Preview

From hanamizuki/solopreneur · View interactive version

Preview is an AI agent skill from the GitHub repository hanamizuki/solopreneur. Create an interactive HTML preview of any proposal, plan, idea, doc, brief, or spec and land it in the browsable local Preview Library by default (opens under file:// with a catalog sidebar and in-page comments); an explicitly temporary ask produces one self-contained HTML on the Desktop instead, an

How to use this skill

Skill file

preview

Delivery mode gate

This is the first action. Decide the delivery mode before reading Preview

Library config, running Vercel preflight/setup, creating files, using the

network, or making any other state change:

online deployment, cross-device access, or external sharing.

"看完就丟", "just drop it on my Desktop" — or when the user names the

output path themselves.

such as "give me a link" still means a clickable local file:// link.

Misrouting is asymmetric — a real deliverable sent to a throwaway file is

lost after the look, while a throwaway in the Library is one extra catalog

row — so ambiguity always lands in the Library.

Run the side-effect-free resolver from this skill directory with no argument

for library, or with exactly one flag for the explicit intents above:

node scripts/resolve-delivery.mjs [--ephemeral | --vercel]

Follow only the workflow it prints. On a Codex host (CODEX_THREAD_ID set),

--vercel fails closed before any network or state change. Stop immediately,

repeat the resolver's Codex Phase 1 local-only limitation, and do not substitute

a local artifact for the explicitly requested deployment. Claude Code may

continue through the existing Vercel workflow. library and ephemeral are

pure local file operations, available on Claude Code and Codex alike.

Turn any proposal / plan / idea into interactive HTML and hand the user a link

they can open. Library delivery writes into the content root and returns a

file:// link into the freshly rebuilt local library. Explicit remote delivery

publishes the existing private Library; an external one-off link uses Share

(same Vercel project, Preview environment only — never promotes Library

production).

Outcome the user is looking for

A link they can open and try. Not a markdown wall and not a screenshot.

Library delivery returns an absolute file:// Markdown link to the item's

built page (catalog sidebar included). Ephemeral delivery returns an

absolute-path link to one standalone file. Explicit Vercel delivery returns

the existing Library or Share URL.

Library workflow (default)

This workflow is available on Claude Code and Codex and is the default.

Deep reference (schema, setup, deploy internals): ../../shared/config.md, relative to this skill inside an installed package (canonical source: src/solopreneur/shared/config.md).

1. Resolve Library config

Config is path-scoped, not git-remote-scoped. From the content path (or cwd when creating new work), walk up for the nearest .solopreneur.json that contains a preview block. Full resolution order and rules: config-resolve.mjs / shared/config.md.

# Inspect what the tools will use (anchor at the content path or cwd)
node scripts/config-resolve.mjs --from "$CONTENT_OR_CWD"   # see script --help for flags

No v2 config resolves (mode none or legacy): library mode is

unavailable here — say so in one line and deliver through the Ephemeral

workflow instead. Creating a new content root stays an explicit setup action

(setup.mjs, Vercel-oriented — do not invent projects or silently create

roots). Legacy solopreneur.json cascades still work for the escape hatch;

prefer migrating with config-migrate.mjs when the user is ready, and never

silently rewrite their legacy file.

2. Decide content + create / update item

Self-assess ambiguity before writing: only ask which deliverable if ≥2 separable topics, bare "preview" after a wide discussion, or multiple candidate artifacts. Otherwise state what you are previewing in one line and proceed.

Layout (v2)
<root>/                    # preview.root from resolved config
├── active/<id>/
│   ├── index.html
│   ├── preview.json
│   └── …assets (relative only)
├── archive/<id>/
│   └── …
└── library/               # generated local library (gitignored, never edited)
Update routing / duplicate guard

Prefer, in order: preview id from URL / Share or archive request → caller-given id → sourceRef in metadata. Title similarity alone never auto-merges. Same id or same sourceRef → treat as update candidate. Fork only when the user says so.

`preview.json` (required fields)

Write a sidecar in the Library source tree only — never deploy raw preview.json; the builder projects an allowlist into directory.json:

{
  "schemaVersion": 1,
  "id": "2026-07-25-short-slug",
  "title": "Human title",
  "createdAt": "2026-07-25T10:00:00+08:00",
  "updatedAt": "2026-07-25T12:00:00+08:00",
  "revision": 1,
  "entry": "index.html",
  "provenance": {
    "createdBy": { "agent": "Builder Claude", "platform": "claude", "sessionTitle": "optional" },
    "lastUpdatedBy": { "agent": "Builder Claude", "platform": "claude", "sessionTitle": "optional" }
  }
}

3. Write HTML

Start from assets/template.html (placeholders {{TITLE}} / {{DATE}} / {{LEAD_PARAGRAPH}} / {{AUTHOR_OR_CONTEXT}}).

The builds inject shared comment-overlay.js and preview-shell.js — the local library build and the Vercel publish alike. You may still reference ./comment-overlay.js in the template for raw-source review; the builder rewrites it to the shared asset. Prefer not treating per-item overlay copies as the durable happy path.

Contract (v1 static): single index.html, relative assets only. No root-relative /assets/..., no SPA history fallback, no entry outside the item dir. Read references/libs.md before Alpine / Chart.js / Mermaid.

Form follows content (calculator, doc, charts, etc.) — same guidance as before.

Full-bleed slides: wrap in <main class="doc">, set body.cmt-full-bleed when needed (see template comments).

4. Build the local library

After content is ready (and preferably committed when the content root is git-backed):

node scripts/build-library.mjs --local --from "$PATH_UNDER_ROOT"
# machine-readable:
node scripts/build-library.mjs --local --json --from "$PATH_UNDER_ROOT"

<root>/library/ — generated output, never edited, never committed. A

failed build leaves the previous library untouched, and re-running is the

recovery. Concurrent builds of one root are serialized by a lock; if a

build was hard-killed, the next one refuses to start and names the stale

lock file to delete.

.gitignore and reports it — commit those lines with the content. The glob

covers the build's swap siblings (library.tmp, library.bak,

library.lock); untracked build output would otherwise dirty the root and

trip the deploy fetch-guard.

sidebar, provenance footer, comment overlay. Comments persist per item in

that browser's localStorage (this machine only — export markdown if they

matter elsewhere).

[Open preview](file:///…/<root>/library/p/<id>/index.html) — and mention

the library home <root>/library/index.html when useful. Run open only

when the user explicitly asks.

stale), mention once that the user can open the sidebar Manage mode,

multi-select, and copy archive instructions — never block the build.

5. Archive / restore (from Manage mode)

Sidebar Manage mode copies a structured block (agent contract):

## library archive request
library: <label>
exported: <ISO timestamp>

archive(active → archive):
- <id> — <title>
restore(archive → active):
- <id> — <title>

(給 agent:對每個 id 做 mv <root>/<from>/<id> <root>/<to>/<id>,全部完成後重新發布 library。)

When the user pastes this:

  1. For each archive id: mv <root>/active/<id> <root>/archive/<id> (keep id).
  2. For each restore id: reverse.
  3. One rebuild after all moves: build-library.mjs --local, plus one

deploy-library.mjs republish when the Library is also published on Vercel.

  1. Do not delete unless the user confirms item-by-item (delete is out of the Manage UI).

6. Feedback loop (comments + visible diffs)

Keep the existing comment + revision workflow:

  1. User highlights, comments, exports markdown (## comments on: …).
  2. On each revision round: flatten prior <del> / <ins>, apply new changes as visible diff, refresh a top revision-log callout, rebuild the local library (same id, revision +1 when content changed); republish Vercel only when that is where the user reviews.
  3. Comments are per-preview-id (preview_comments_v3:<id>) in the browser that made them. The local library and a Vercel deployment are different origins — comments do not travel between them, or across Share origins. Export if they matter.

See "The comment overlay" below for UX detail.

Vercel workflow (Claude Code)

This is the existing Library v2 publish path. Enter it only after the delivery

resolver prints vercel. Content rules are the Library workflow's steps 1–3 —

the same content root, items, and HTML feed both renderings. Legacy

three-bucket / deploy.sh is an escape hatch only (see below).

1. Preflight FIRST

Always run bash scripts/preflight.sh before drafting HTML. It checks Vercel CLI + auth.

No v2 config found: run first-run setup — do not invent projects.

node scripts/setup.mjs
# optional: --project my-private-previews --team <teamId>

Setup proposes one private target, creates dirs only after confirm, and fail-closes if protection cannot be verified. It never auto-creates three Hana buckets.

2. Publish the Library

node scripts/deploy-library.mjs --from "$PATH_UNDER_ROOT"
# machine-readable:
node scripts/deploy-library.mjs --json --from "$PATH_UNDER_ROOT"

3. Share (external, optional)

The page Share… control only builds a copyable JSON request (no token, no deploy). Example:

{
  "schemaVersion": 1,
  "kind": "preview-share-request",
  "previewId": "<id>",
  "revision": 4,
  "contentHash": "sha256:<hash>",
  "url": "<current library item URL>",
  "access": "project-members"
}

access: project-members (default) or anyone-with-link.

When the user pastes a request (or asks to share an id):

# request on stdin, or --request <file>
node scripts/deploy-share.mjs --from "$PATH_UNDER_ROOT" --request - <<'EOF'
{ ...share request JSON... }
EOF

Ephemeral workflow

Enter only when the resolver prints ephemeral — explicitly temporary work or

a user-named output path — or as the stated fallback when no v2 config

resolves in library mode. The artifact joins no catalog and carries no shell

or overlay chrome.

  1. Choose one output file. A user-specified path wins. For temporary work

with no path, use ~/Desktop/<safe-slug>.html, where the slug is lowercase

ASCII [a-z0-9-], repeated hyphens are collapsed, and an empty result falls

back to preview. Resolve the final path to an absolute path.

  1. Refuse silent overwrite. Unless the user explicitly asked to update or

replace that exact file, atomically reserve the target after the delivery

mode is decided:

```bash

node scripts/reserve-local-output.mjs "$ABSOLUTE_TARGET"

```

Use only the absolute path it prints. An existing target is preserved and

receives a collision-free sibling such as <safe-slug>-2.html.

  1. Write exactly one self-contained HTML file. Write into the reserved file

(or the explicitly approved replacement). Put all CSS in <style> and

all necessary JavaScript in inline <script> blocks. Use inline SVG or data

URIs for required images. The file must render directly under file://

without a server, build step, external stylesheet/script/module, CDN,

runtime fetch, or relative asset. Omit JavaScript when HTML/CSS is enough.

assets/template.html is a Library-oriented visual reference only: its CDN

and comment-overlay.js references must not appear in an ephemeral artifact.

  1. Keep ephemeral delivery isolated. Create no preview.json, write no

.solopreneur.json / solopreneur.json, run no setup.mjs,

preflight.sh, or deploy script, create no .vercel, and make no

Vercel/network calls. Config reading is not part of this workflow either —

the no-config Library fallback has already done its one read by the time it

lands here. The output HTML is the only delivery artifact.

  1. Verify and hand off. Confirm the file exists, contains its required

inline CSS/JS, and has no runtime asset dependency. Return a clickable

absolute-path Markdown link such as [Open preview](/absolute/path/file.html).

Run open only when the user explicitly asks to open it.

Wanting to keep an ephemeral page later is not a feature — move it into

active/<id>/, add a preview.json, rebuild the library. Ordinary file

operations, on request.


Legacy / escape hatch

Use only when there is no v2 Library config, or for living-spec / slides / explicit migration rollback.

`deploy.sh` (arbitrary directory)

scripts/deploy.sh <path-to-dir>
# optional: PREVIEW_PROJECT=... or --bucket default|keep|public

Prints one URL to stdout. Buckets (default / keep / public) live in legacy solopreneur.json. Not the default for new /preview work when a Library config resolves.

Path probing + solopreneur.json helpers for legacy flat docs/preview/<date>-<slug>/ dirs remain valid for this escape hatch only. Prefer active/<id>/ whenever v2 applies.


The Library comment overlay (what the user sees)

Margin-style annotations (Google Docs / Medium-like), identical in the local

library and on Vercel:

Agent revision rules:

  1. Flatten previous round (delete old <del>, unwrap old <ins>).
  2. Apply this round as <del> / <ins> only — never silent replace.
  3. Rewrite the top revision-log callout for this round only.
  4. Rebuild the local library; redeploy Vercel only if still reviewing there (or legacy deploy only if still on escape hatch).

What not to do

cross-device / external-share intent; "give me a link" remains local.

a user-named path only.

or use the network in ephemeral mode.

items + preview.json (+ the .gitignore line when first added) instead.

explicit request.


Files in this skill

| Path | Role |

|------|------|

| scripts/resolve-delivery.mjs | Side-effect-free library / ephemeral / Vercel gate |

| scripts/reserve-local-output.mjs | Atomic no-overwrite ephemeral path reservation |

| scripts/preflight.sh | Vercel CLI + auth |

| scripts/config-resolve.mjs | Path-scoped v2 + legacy resolve |

| scripts/config-migrate.mjs | Legacy → v2 proposal + write |

| scripts/setup.mjs | First-run private target |

| scripts/build-library.mjs | Scan collections → staging; --local swaps <root>/library/ |

| scripts/deploy-library.mjs | Staged Library publish |

| scripts/deploy-share.mjs | Single-item Share Preview |

| scripts/deploy.sh | Legacy arbitrary-dir deploy |

| scripts/preview-schema.json | preview.json schema |

| scripts/resolve-provenance.mjs | Provenance display shape |

| assets/template.html | HTML starter |

| assets/comment-overlay.js | Comments + diff toggle |

| assets/preview-shell.js | Sidebar, Manage, Share, footer |

| assets/library-index.html | Library home template |

| references/libs.md | Alpine / Chart.js / Mermaid recipes |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.