@open-document/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +50 -0
  3. package/README.zh-TW.md +50 -0
  4. package/bin.js +2 -0
  5. package/dist/build-BWZJ1gvL.js +18 -0
  6. package/dist/cli/bin.d.ts +1 -0
  7. package/dist/cli/bin.js +86 -0
  8. package/dist/config-DBp4mOOf.js +1121 -0
  9. package/dist/config-EBFfKtWH.d.ts +17 -0
  10. package/dist/design-BJLvOcCO.js +53 -0
  11. package/dist/dev-CZtw1oqs.js +24 -0
  12. package/dist/edit-ops-DSdUroVO.js +1225 -0
  13. package/dist/index.d.ts +206 -0
  14. package/dist/index.js +240 -0
  15. package/dist/ops/index.d.ts +160 -0
  16. package/dist/ops/index.js +202 -0
  17. package/dist/preview-DUfQl7Ij.js +23 -0
  18. package/dist/sync-6GTPAt2t.js +86 -0
  19. package/dist/sync-C6CsPmyK.js +3 -0
  20. package/dist/vite/index.d.ts +22 -0
  21. package/dist/vite/index.js +5 -0
  22. package/env.d.ts +51 -0
  23. package/package.json +91 -0
  24. package/skills/apply-comments/SKILL.md +74 -0
  25. package/skills/create-doc/SKILL.md +102 -0
  26. package/skills/create-theme/SKILL.md +184 -0
  27. package/skills/doc-authoring/SKILL.md +354 -0
  28. package/skills/doc-authoring/references/assets.md +47 -0
  29. package/skills/doc-authoring/references/design-system.md +81 -0
  30. package/skills/doc-authoring/references/pagination.md +117 -0
  31. package/skills/doc-authoring/references/tables-and-charts.md +161 -0
  32. package/src/app/app.tsx +42 -0
  33. package/src/app/components/design-panel/design-panel.tsx +318 -0
  34. package/src/app/components/design-panel/design-provider.tsx +121 -0
  35. package/src/app/components/design-panel/use-design.ts +85 -0
  36. package/src/app/components/doc-assets.tsx +129 -0
  37. package/src/app/components/doc-sidebar.tsx +162 -0
  38. package/src/app/components/flow-page.tsx +50 -0
  39. package/src/app/components/image-placeholder.tsx +50 -0
  40. package/src/app/components/inspector/inspector.tsx +426 -0
  41. package/src/app/components/page-frame.tsx +70 -0
  42. package/src/app/components/sidebar/folder-item.tsx +212 -0
  43. package/src/app/components/sidebar/icon-picker.tsx +99 -0
  44. package/src/app/components/sidebar/sidebar.tsx +252 -0
  45. package/src/app/components/table-of-contents.tsx +81 -0
  46. package/src/app/components/theme-toggle.tsx +50 -0
  47. package/src/app/components/themes/markdown.tsx +249 -0
  48. package/src/app/components/themes/theme-preview.tsx +74 -0
  49. package/src/app/components/ui/menu.tsx +139 -0
  50. package/src/app/index.html +12 -0
  51. package/src/app/lib/assets.ts +151 -0
  52. package/src/app/lib/design-presets.ts +109 -0
  53. package/src/app/lib/design.ts +88 -0
  54. package/src/app/lib/doc-preview.tsx +29 -0
  55. package/src/app/lib/docs.ts +26 -0
  56. package/src/app/lib/export-html.ts +309 -0
  57. package/src/app/lib/export-pdf.ts +166 -0
  58. package/src/app/lib/flow-measure.ts +109 -0
  59. package/src/app/lib/flow.test.ts +64 -0
  60. package/src/app/lib/flow.ts +111 -0
  61. package/src/app/lib/folders.ts +192 -0
  62. package/src/app/lib/inspector/fiber.ts +99 -0
  63. package/src/app/lib/outline.ts +109 -0
  64. package/src/app/lib/page-context.tsx +38 -0
  65. package/src/app/lib/print-ready.ts +69 -0
  66. package/src/app/lib/sdk.test.ts +24 -0
  67. package/src/app/lib/sdk.ts +86 -0
  68. package/src/app/lib/themes.ts +31 -0
  69. package/src/app/lib/use-doc-module.ts +53 -0
  70. package/src/app/lib/use-doc-pages.ts +99 -0
  71. package/src/app/lib/utils.ts +6 -0
  72. package/src/app/main.tsx +14 -0
  73. package/src/app/routes/assets.tsx +257 -0
  74. package/src/app/routes/doc.tsx +480 -0
  75. package/src/app/routes/home-shell.tsx +203 -0
  76. package/src/app/routes/home.tsx +269 -0
  77. package/src/app/routes/themes.tsx +121 -0
  78. package/src/app/styles.css +72 -0
  79. package/src/app/virtual.d.ts +30 -0
@@ -0,0 +1,202 @@
1
+ import { OpsError, assetImportPath, countAssetUsages, createDocument, deleteDocument, docDir, duplicateDocument, insertMarker, listDocIds, listDocuments, makeContext, newFolderId, parseFrontmatter, readDocument, readManifest, renameDocument, replaceTextAt, resolveEntry, resolveScopedAssetFile, resolveScopedAssetsDir, resolveTextTarget, validateAssetName, validateIcon, validateName, writeDocument, writeManifest } from "../edit-ops-DSdUroVO.js";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { existsSync } from "node:fs";
5
+ import fg from "fast-glob";
6
+
7
+ //#region src/ops/library.ts
8
+ function themesRoot(ctx, themesDir = "themes") {
9
+ return path.resolve(ctx.userCwd, themesDir);
10
+ }
11
+ async function themeFiles(root) {
12
+ if (!existsSync(root)) return [];
13
+ return (await fg("*.md", {
14
+ cwd: root,
15
+ absolute: true,
16
+ onlyFiles: true
17
+ })).sort();
18
+ }
19
+ function demoFor(root, id) {
20
+ for (const cand of [
21
+ `${id}.demo.tsx`,
22
+ `${id}.demo.jsx`,
23
+ `${id}.demo.ts`,
24
+ `${id}.demo.js`
25
+ ]) {
26
+ const p = path.join(root, cand);
27
+ if (existsSync(p)) return p;
28
+ }
29
+ return null;
30
+ }
31
+ async function listThemes(ctx, themesDir) {
32
+ const root = themesRoot(ctx, themesDir);
33
+ const out = [];
34
+ for (const file of await themeFiles(root)) {
35
+ const id = path.basename(file, ".md");
36
+ const { fm } = parseFrontmatter(await fs.readFile(file, "utf8"), id);
37
+ out.push({
38
+ id,
39
+ name: fm.name,
40
+ description: fm.description,
41
+ pageSize: fm.pageSize,
42
+ mode: fm.mode,
43
+ hasDemo: demoFor(root, id) !== null
44
+ });
45
+ }
46
+ return out;
47
+ }
48
+ /**
49
+ * The full theme document. This is what an agent reads before writing a doc —
50
+ * the palette, type scale, and paste-ready components live in the body.
51
+ */
52
+ async function readTheme(ctx, themeId, themesDir) {
53
+ const root = themesRoot(ctx, themesDir);
54
+ const file = path.join(root, `${themeId}.md`);
55
+ if (!file.startsWith(root + path.sep) || !existsSync(file)) throw new OpsError(404, `theme not found: ${themeId}`);
56
+ const { fm, body } = parseFrontmatter(await fs.readFile(file, "utf8"), themeId);
57
+ const demoAbs = demoFor(root, themeId);
58
+ return {
59
+ id: themeId,
60
+ frontmatter: fm,
61
+ body,
62
+ demo: demoAbs ? await fs.readFile(demoAbs, "utf8") : void 0
63
+ };
64
+ }
65
+ /** `scope` is a document id, or `global` for the shared assets directory. */
66
+ async function listAssets(ctx, scope) {
67
+ const dir = resolveScopedAssetsDir(ctx.docsRoot, ctx.globalAssetsRoot, scope);
68
+ if (!dir) throw new OpsError(400, `invalid scope: ${scope}`);
69
+ if (!existsSync(dir)) return [];
70
+ const names = await fs.readdir(dir);
71
+ const out = [];
72
+ for (const filename of names.sort()) {
73
+ const stat = await fs.stat(path.join(dir, filename)).catch(() => null);
74
+ if (!stat?.isFile()) continue;
75
+ out.push({
76
+ scope,
77
+ filename,
78
+ bytes: stat.size,
79
+ importPath: assetImportPath(scope, filename)
80
+ });
81
+ }
82
+ return out;
83
+ }
84
+ async function writeAsset(ctx, scope, filename, data) {
85
+ const name = validateAssetName(filename);
86
+ if (!name) throw new OpsError(400, "invalid filename");
87
+ const dir = resolveScopedAssetsDir(ctx.docsRoot, ctx.globalAssetsRoot, scope);
88
+ if (!dir) throw new OpsError(400, `invalid scope: ${scope}`);
89
+ await fs.mkdir(dir, { recursive: true });
90
+ const file = resolveScopedAssetFile(ctx.docsRoot, ctx.globalAssetsRoot, scope, name);
91
+ if (!file) throw new OpsError(400, "invalid filename");
92
+ await fs.writeFile(file, data);
93
+ return {
94
+ scope,
95
+ filename: name,
96
+ bytes: data.byteLength,
97
+ importPath: assetImportPath(scope, name)
98
+ };
99
+ }
100
+ async function deleteAsset(ctx, scope, filename) {
101
+ const file = resolveScopedAssetFile(ctx.docsRoot, ctx.globalAssetsRoot, scope, filename);
102
+ if (!file) throw new OpsError(400, "invalid filename");
103
+ if (!existsSync(file)) throw new OpsError(404, `asset not found: ${scope}/${filename}`);
104
+ await fs.rm(file);
105
+ }
106
+ /** Which documents import this asset — check before deleting one. */
107
+ async function findAssetUsages(ctx, scope, filename) {
108
+ const importPath = assetImportPath(scope, filename);
109
+ const out = [];
110
+ for (const id of await listDocIds(ctx)) {
111
+ const entry = resolveEntry(ctx, id);
112
+ if (!entry) continue;
113
+ const count = countAssetUsages(await fs.readFile(entry, "utf8"), importPath);
114
+ if (count > 0) out.push({
115
+ docId: id,
116
+ count
117
+ });
118
+ }
119
+ return out;
120
+ }
121
+ async function listFolders(ctx) {
122
+ const manifest = await readManifest(ctx.manifestPath);
123
+ return {
124
+ folders: manifest.folders,
125
+ assignments: manifest.assignments
126
+ };
127
+ }
128
+ /** Folders always carry an icon; agents rarely care, so this is the fallback. */
129
+ const DEFAULT_FOLDER_ICON = {
130
+ type: "color",
131
+ value: "#6b7280"
132
+ };
133
+ async function createFolder(ctx, rawName, rawIcon) {
134
+ const name = validateName(rawName);
135
+ if (!name) throw new OpsError(400, "invalid folder name");
136
+ const icon = validateIcon(rawIcon ?? DEFAULT_FOLDER_ICON);
137
+ if (!icon) throw new OpsError(400, "invalid icon");
138
+ const manifest = await readManifest(ctx.manifestPath);
139
+ const folder = {
140
+ id: newFolderId(),
141
+ name,
142
+ icon
143
+ };
144
+ manifest.folders.push(folder);
145
+ await writeManifest(ctx.manifestPath, manifest);
146
+ return folder;
147
+ }
148
+ /** Filing only edits assignments — a document id never moves on disk. */
149
+ async function fileDocument(ctx, docId, folderId) {
150
+ const manifest = await readManifest(ctx.manifestPath);
151
+ if (folderId !== null && !manifest.folders.some((f) => f.id === folderId)) throw new OpsError(404, `folder not found: ${folderId}`);
152
+ if (folderId === null) delete manifest.assignments[docId];
153
+ else manifest.assignments[docId] = folderId;
154
+ await writeManifest(ctx.manifestPath, manifest);
155
+ }
156
+
157
+ //#endregion
158
+ //#region src/ops/text.ts
159
+ async function sourceOf(ctx, docId) {
160
+ const entry = resolveEntry(ctx, docId);
161
+ if (!entry) throw new OpsError(404, `document not found: ${docId}`);
162
+ return {
163
+ entry,
164
+ source: await fs.readFile(entry, "utf8")
165
+ };
166
+ }
167
+ /**
168
+ * Resolves a `line:column` (or several candidates) to the editable text runs at
169
+ * that spot. `shown` is the rendered text — when a clicked element belongs to a
170
+ * local helper component, it is what decides which candidate was really meant.
171
+ */
172
+ async function readText(ctx, docId, locs, shown) {
173
+ if (locs.length === 0) throw new OpsError(400, "at least one loc is required");
174
+ const { source } = await sourceOf(ctx, docId);
175
+ const resolved = resolveTextTarget(source, locs, shown);
176
+ if (!resolved) throw new OpsError(404, "no editable text at that location");
177
+ return resolved;
178
+ }
179
+ /**
180
+ * `expected` is the text the caller believes is there; when it no longer
181
+ * matches the write is refused rather than silently overwriting someone else's
182
+ * edit. `index` picks a run when the element mixes text and markup.
183
+ */
184
+ async function writeText(ctx, docId, loc, text, opts = {}) {
185
+ const { entry, source } = await sourceOf(ctx, docId);
186
+ const result = replaceTextAt(source, loc, text, opts);
187
+ if (!result.ok) throw new OpsError(result.status, result.error);
188
+ if (result.source !== source) await fs.writeFile(entry, result.source, "utf8");
189
+ return { ok: true };
190
+ }
191
+ /** Leaves a `@doc-comment` marker in the source for a later agent pass to act on. */
192
+ async function addComment(ctx, docId, loc, note, hint) {
193
+ if (note.trim() === "") throw new OpsError(400, "note is empty");
194
+ const { entry, source } = await sourceOf(ctx, docId);
195
+ const inserted = insertMarker(source, loc, note.trim(), hint);
196
+ if (!inserted) throw new OpsError(422, "cannot anchor a comment here — pick the surrounding element");
197
+ await fs.writeFile(entry, inserted.source, "utf8");
198
+ return { id: inserted.id };
199
+ }
200
+
201
+ //#endregion
202
+ export { OpsError, addComment, createDocument, createFolder, deleteAsset, deleteDocument, docDir, duplicateDocument, fileDocument, findAssetUsages, listAssets, listDocIds, listDocuments, listFolders, listThemes, makeContext, readDocument, readText, readTheme, renameDocument, resolveEntry, writeAsset, writeDocument, writeText };
@@ -0,0 +1,23 @@
1
+ import "./design-BJLvOcCO.js";
2
+ import "./edit-ops-DSdUroVO.js";
3
+ import { createViteConfig } from "./config-DBp4mOOf.js";
4
+ import { mergeConfig, preview as preview$1 } from "vite";
5
+
6
+ //#region src/cli/preview.ts
7
+ async function preview(opts = {}) {
8
+ const base = await createViteConfig({
9
+ userCwd: process.cwd(),
10
+ mode: "build"
11
+ });
12
+ const config = mergeConfig(base, { preview: {
13
+ ...opts.port !== void 0 ? { port: opts.port } : {},
14
+ ...opts.host !== void 0 ? { host: opts.host } : {},
15
+ ...opts.open !== void 0 ? { open: opts.open } : {}
16
+ } });
17
+ const server = await preview$1(config);
18
+ server.printUrls();
19
+ server.bindCLIShortcuts({ print: true });
20
+ }
21
+
22
+ //#endregion
23
+ export { preview };
@@ -0,0 +1,86 @@
1
+ import chalk from "chalk";
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { existsSync } from "node:fs";
5
+
6
+ //#region src/cli/sync.ts
7
+ const SKILL_TARGET_DIRS = [".agents/skills", ".claude/skills"];
8
+ async function listFiles(dir) {
9
+ const out = [];
10
+ const walk = async (current) => {
11
+ const entries = await fs.readdir(current, { withFileTypes: true });
12
+ for (const entry of entries) {
13
+ const abs = path.join(current, entry.name);
14
+ if (entry.isDirectory()) await walk(abs);
15
+ else out.push(path.relative(dir, abs));
16
+ }
17
+ };
18
+ await walk(dir);
19
+ return out.sort();
20
+ }
21
+ async function sameTree(src, dst) {
22
+ if (!existsSync(dst)) return false;
23
+ const [srcFiles, dstFiles] = await Promise.all([listFiles(src), listFiles(dst)]);
24
+ if (srcFiles.length !== dstFiles.length) return false;
25
+ if (srcFiles.some((f, i) => f !== dstFiles[i])) return false;
26
+ for (const rel of srcFiles) {
27
+ const [a, b] = await Promise.all([fs.readFile(path.join(src, rel), "utf8"), fs.readFile(path.join(dst, rel), "utf8")]);
28
+ if (a !== b) return false;
29
+ }
30
+ return true;
31
+ }
32
+ async function skillNames(builtinDir) {
33
+ if (!existsSync(builtinDir)) return [];
34
+ const entries = await fs.readdir(builtinDir, { withFileTypes: true });
35
+ return entries.filter((e) => e.isDirectory()).map((e) => e.name).sort();
36
+ }
37
+ async function detectSkillsDrift(builtinDir, userCwd = process.cwd()) {
38
+ const names = await skillNames(builtinDir);
39
+ const primaryTarget = path.join(userCwd, SKILL_TARGET_DIRS[0]);
40
+ const drift = [];
41
+ for (const name of names) {
42
+ const src = path.join(builtinDir, name);
43
+ const dst = path.join(primaryTarget, name);
44
+ if (!existsSync(dst)) drift.push({
45
+ name,
46
+ status: "added"
47
+ });
48
+ else if (!await sameTree(src, dst)) drift.push({
49
+ name,
50
+ status: "updated"
51
+ });
52
+ else drift.push({
53
+ name,
54
+ status: "unchanged"
55
+ });
56
+ }
57
+ return drift;
58
+ }
59
+ async function syncSkills(builtinDir, opts = {}, userCwd = process.cwd()) {
60
+ const drift = await detectSkillsDrift(builtinDir, userCwd);
61
+ const stale = drift.filter((d) => d.status !== "unchanged");
62
+ if (stale.length === 0) {
63
+ process.stdout.write(`${chalk.green("✔")} Skills already up to date.\n`);
64
+ return;
65
+ }
66
+ for (const { name, status } of stale) {
67
+ if (opts.dryRun) {
68
+ process.stdout.write(`${chalk.yellow("~")} ${name} ${chalk.dim(`(${status})`)}\n`);
69
+ continue;
70
+ }
71
+ for (const targetDir of SKILL_TARGET_DIRS) {
72
+ const dst = path.join(userCwd, targetDir, name);
73
+ await fs.rm(dst, {
74
+ recursive: true,
75
+ force: true
76
+ });
77
+ await fs.mkdir(path.dirname(dst), { recursive: true });
78
+ await fs.cp(path.join(builtinDir, name), dst, { recursive: true });
79
+ }
80
+ process.stdout.write(`${chalk.green("✔")} ${name} ${chalk.dim(`(${status})`)}\n`);
81
+ }
82
+ if (opts.dryRun) process.stdout.write(chalk.dim("\nDry run — nothing written.\n"));
83
+ }
84
+
85
+ //#endregion
86
+ export { detectSkillsDrift, syncSkills };
@@ -0,0 +1,3 @@
1
+ import { detectSkillsDrift, syncSkills } from "./sync-6GTPAt2t.js";
2
+
3
+ export { syncSkills };
@@ -0,0 +1,22 @@
1
+ import { OpenDocConfig } from "../config-EBFfKtWH.js";
2
+ import { InlineConfig, Plugin } from "vite";
3
+
4
+ //#region src/vite/open-doc-plugin.d.ts
5
+ type OpenDocPluginOptions = {
6
+ userCwd: string;
7
+ config: OpenDocConfig;
8
+ coreVersion: string;
9
+ };
10
+ declare function openDocPlugin(opts: OpenDocPluginOptions): Plugin; //#endregion
11
+ //#region src/vite/config.d.ts
12
+ type CreateViteConfigOptions = {
13
+ userCwd: string;
14
+ /** Mount the MCP endpoint (requires `@open-document/mcp`). */
15
+ mcp?: boolean;
16
+ config?: OpenDocConfig;
17
+ mode?: 'serve' | 'build';
18
+ };
19
+ declare function createViteConfig(opts: CreateViteConfigOptions): Promise<InlineConfig>;
20
+
21
+ //#endregion
22
+ export { createViteConfig, openDocPlugin };
@@ -0,0 +1,5 @@
1
+ import "../design-BJLvOcCO.js";
2
+ import { openDocPlugin } from "../edit-ops-DSdUroVO.js";
3
+ import { createViteConfig } from "../config-DBp4mOOf.js";
4
+
5
+ export { createViteConfig, openDocPlugin };
package/env.d.ts ADDED
@@ -0,0 +1,51 @@
1
+ // Ambient module declarations for assets imported from `docs/<id>/assets/`.
2
+ // Mirrors Vite's default asset handling (default export = resolved URL).
3
+ //
4
+ // Consumers opt in via tsconfig:
5
+ //
6
+ // { "compilerOptions": { "types": ["@open-document/core/env"] } }
7
+
8
+ declare module '*.svg' {
9
+ const src: string;
10
+ export default src;
11
+ }
12
+ declare module '*.png' {
13
+ const src: string;
14
+ export default src;
15
+ }
16
+ declare module '*.jpg' {
17
+ const src: string;
18
+ export default src;
19
+ }
20
+ declare module '*.jpeg' {
21
+ const src: string;
22
+ export default src;
23
+ }
24
+ declare module '*.webp' {
25
+ const src: string;
26
+ export default src;
27
+ }
28
+ declare module '*.gif' {
29
+ const src: string;
30
+ export default src;
31
+ }
32
+ declare module '*.avif' {
33
+ const src: string;
34
+ export default src;
35
+ }
36
+ declare module '*.woff' {
37
+ const src: string;
38
+ export default src;
39
+ }
40
+ declare module '*.woff2' {
41
+ const src: string;
42
+ export default src;
43
+ }
44
+ declare module '*.ttf' {
45
+ const src: string;
46
+ export default src;
47
+ }
48
+ declare module '*.otf' {
49
+ const src: string;
50
+ export default src;
51
+ }
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@open-document/core",
3
+ "version": "0.1.0",
4
+ "description": "Runtime and CLI for open-doc — write documents in docs/, we handle the pages, print layout, and export.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ },
11
+ "./ops": {
12
+ "types": "./dist/ops/index.d.ts",
13
+ "import": "./dist/ops/index.js"
14
+ },
15
+ "./vite": {
16
+ "types": "./dist/vite/index.d.ts",
17
+ "import": "./dist/vite/index.js"
18
+ },
19
+ "./env": {
20
+ "types": "./env.d.ts"
21
+ }
22
+ },
23
+ "bin": {
24
+ "open-doc": "./bin.js"
25
+ },
26
+ "files": [
27
+ "bin.js",
28
+ "dist",
29
+ "env.d.ts",
30
+ "src/app",
31
+ "skills",
32
+ "README.md",
33
+ "README.zh-TW.md"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "keywords": [
39
+ "document",
40
+ "report",
41
+ "pdf",
42
+ "react",
43
+ "vite"
44
+ ],
45
+ "license": "MIT",
46
+ "author": {
47
+ "name": "Simon Liu",
48
+ "url": "https://github.com/LiuYuWei"
49
+ },
50
+ "homepage": "https://github.com/simonliu-ai-product/open-doc",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/simonliu-ai-product/open-doc.git",
54
+ "directory": "packages/core"
55
+ },
56
+ "bugs": {
57
+ "url": "https://github.com/simonliu-ai-product/open-doc/issues"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "dependencies": {
63
+ "@babel/parser": "^7.29.2",
64
+ "@tailwindcss/vite": "^4.3.3",
65
+ "@vitejs/plugin-react": "^4.3.3",
66
+ "chalk": "^6.0.0",
67
+ "clsx": "^2.1.1",
68
+ "commander": "^15.0.0",
69
+ "fast-glob": "^3.3.2",
70
+ "fflate": "^0.8.3",
71
+ "lucide-react": "^1.25.0",
72
+ "next-themes": "^0.4.6",
73
+ "react": "^18.3.1",
74
+ "react-dom": "^18.3.1",
75
+ "react-router-dom": "^7.18.1",
76
+ "tailwind-merge": "^3.5.0",
77
+ "tailwindcss": "^4.2.2",
78
+ "vite": "^5.4.10"
79
+ },
80
+ "devDependencies": {
81
+ "@types/node": "^22.19.17",
82
+ "@types/react": "^18.3.12",
83
+ "@types/react-dom": "^18.3.1",
84
+ "tsdown": "^0.9.9",
85
+ "typescript": "^5.9.3"
86
+ },
87
+ "scripts": {
88
+ "build": "tsdown",
89
+ "typecheck": "tsc --noEmit"
90
+ }
91
+ }
@@ -0,0 +1,74 @@
1
+ ---
2
+ name: apply-comments
3
+ description: Use this skill when the user asks to apply, process, or clear the comments they left in the open-doc inspector — phrases like "apply the comments", "apply my edits", "I left notes on the document", "process the markers", "/apply-comments". It finds every `@doc-comment` marker under `docs/`, makes the edit each one asks for, then removes the marker. Do NOT use for authoring new documents — that is `create-doc`.
4
+ ---
5
+
6
+ # Apply inspector comments
7
+
8
+ The dev UI's **Inspect** mode lets the user click any element on a page and leave a note. Each note is written into the document source as a marker:
9
+
10
+ ```tsx
11
+ <p style={p}>
12
+ {/* @doc-comment id="c-4591fd61" ts="2026-08-15T15:40:52.644Z" text="<base64url>" */}
13
+ 從 FastMCP 開發、容器化…
14
+ </p>
15
+ ```
16
+
17
+ The marker is always the **first child of the element the note is about** — that is your anchor. `text` is base64url-encoded JSON: `{"note": "...", "hint": "p"}`.
18
+
19
+ ## Step 1 — Find the pending comments
20
+
21
+ ```bash
22
+ grep -rn "@doc-comment" docs/
23
+ ```
24
+
25
+ If the dev server is running you can read them decoded instead, which is easier:
26
+
27
+ ```bash
28
+ curl -s "http://localhost:5273/__comments?docId=<id>"
29
+ ```
30
+
31
+ That returns `{ comments: [{ id, line, ts, note, hint }] }`. If neither turns anything up, tell the user there are no pending comments and stop.
32
+
33
+ ## Step 2 — Read each one in context
34
+
35
+ For every marker, read the surrounding element — not just the marked line. A note like *"make this shorter"* is meaningless without the paragraph it sits in. Open the file with `Read` around the marker's line (±40 lines is usually enough) so you can see the element, its styles, and its neighbours.
36
+
37
+ Group comments by document, and handle them **oldest `ts` first** — later notes may refine earlier ones.
38
+
39
+ ## Step 3 — Make the edit
40
+
41
+ Apply what the note asks for, following the **`doc-authoring`** skill: it owns the type scale, the flow/vertical-budget rules, and the design tokens. In particular:
42
+
43
+ - Edit the element the marker is anchored to. Never reformat the whole file.
44
+ - A note about wording changes the text; a note about weight, color, or size changes the inline style — prefer `var(--od-*)` tokens over new hard-coded values.
45
+ - If the change makes a fixed page overflow, split the page or move the content into the `flow()` section (`references/pagination.md`).
46
+ - If a note is ambiguous ("fix this"), do the smallest reasonable interpretation and say what you assumed at hand-off. Don't guess at a large rewrite.
47
+ - If a note asks for something the framework can't do (per-page orientation, a splitting table), say so in the hand-off and leave the marker in place.
48
+
49
+ ## Step 4 — Remove the marker
50
+
51
+ Delete the marker line for every comment you actually applied. Leave markers you deliberately skipped, and say which ones and why.
52
+
53
+ ```bash
54
+ # with the dev server running
55
+ curl -s -X DELETE "http://localhost:5273/__comments?docId=<id>&id=<comment-id>"
56
+ ```
57
+
58
+ Or delete the `{/* @doc-comment … */}` line directly with `Edit`. Removing it by hand is fine — the marker is a plain JSX comment.
59
+
60
+ ## Step 5 — Verify
61
+
62
+ - No `@doc-comment` marker remains for an applied note: `grep -rn "@doc-comment" docs/`.
63
+ - The document still compiles: it hot-reloads in the browser; check the terminal for a Vite error.
64
+ - Run the "Self-review before finishing" checklist in `doc-authoring` for any page you touched.
65
+
66
+ ## Step 6 — Hand off
67
+
68
+ Tell the user, in one short list:
69
+
70
+ - What you changed, one line per comment.
71
+ - Anything you skipped and why.
72
+ - Any assumption you made on an ambiguous note.
73
+
74
+ Do not restate the whole document.
@@ -0,0 +1,102 @@
1
+ ---
2
+ name: create-doc
3
+ description: Use this skill when the user wants to create, draft, author, or generate a new document, report, whitepaper, proposal, memo, or spec in this open-doc repo. Triggers on phrases like "write a report about X", "draft a proposal", "make a whitepaper", "create a document", "write up the Q3 results", or when the user asks to add content under `docs/`. Do NOT use for editing the framework itself — only for authoring content inside `docs/<id>/`.
4
+ ---
5
+
6
+ # Create a document in open-doc
7
+
8
+ This skill owns the **workflow** for drafting a new document. The technical reference — file contract, page canvas, print type scale, vertical budget, tables, TOC — lives in the **`doc-authoring`** skill. Read it before writing code; don't duplicate its rules here.
9
+
10
+ You only write files under `docs/<id>/`. Never modify `package.json`, `open-doc.config.ts`, or existing documents.
11
+
12
+ ## Step 0 — Pick a theme
13
+
14
+ List files under `themes/`. If any theme markdown exists (anything other than `README.md`), call `AskUserQuestion` with each theme id as an option plus a final **"no theme — design from scratch"** option. (`AskUserQuestion` holds at most 4 options — with 4+ themes, offer the 3 most relevant plus "no theme"; the auto-added "Other" lets the user name an omitted one.)
15
+
16
+ - If the user picks a theme: read `themes/<id>.md` end-to-end. Its palette, typography, page setup, and paste-ready components are now authoritative — copy them into the document, and set `meta.theme: '<id>'` in `index.tsx`. Skip the **visual direction** question in Step 2 (the theme already commits to one) and restate the theme name so the user can correct course. Page size comes from the theme's frontmatter unless the user overrides it.
17
+ - If the user picks "no theme", or `themes/` has no theme files: continue unchanged.
18
+
19
+ ## Step 1 — Gather the substance first
20
+
21
+ A document is judged on content, not layout. Before anything else, establish:
22
+
23
+ - **Topic and purpose** — what decision or action should this document produce?
24
+ - **Audience** — executives (lead with the recommendation), engineers (lead with the mechanism), clients (lead with the outcome and the price).
25
+ - **Source material** — does the user have data, a draft, notes, a repo, an existing doc? Ask for it. **Never fabricate figures, quotes, citations, or customer names.**
26
+
27
+ If the request is thin ("write me a report"), make a **separate** `AskUserQuestion` call for topic, audience, and source material before the style questions below. If the topic is already clear, restate your reading of it in the next call so the user can correct course.
28
+
29
+ ## Step 2 — Clarify the shape (MUST ask before writing code)
30
+
31
+ Ask these in a single `AskUserQuestion` call (multi-question form). Skip a question only when the user's message already answers it unambiguously — and restate the assumption if you skip.
32
+
33
+ 1. **Document type** — propose 3 concrete types that fit *this* topic, each with what it implies structurally. Not bare labels:
34
+ - *"our Q3 infrastructure numbers"* → **internal review** (summary, metrics, incidents, actions) · **exec brief** (2 pages, recommendation-first) · **post-incident deep dive** (timeline, root cause, remediation)
35
+ - *"our new product for enterprise buyers"* → **whitepaper** (problem, approach, evidence, references) · **sales proposal** (scope, deliverables, timeline, price) · **one-pager** (positioning + proof + CTA)
36
+ Mark the best fit "(Recommended)".
37
+ 2. **Length** — offer brackets: 2–4 pages (brief), 5–10 (standard report), 11–25 (deep dive). The auto-added "Other" covers custom counts.
38
+ 3. **Page size** — A4 (default, metric/international) · Letter (US) · A4 landscape (data-heavy, wide tables). Skip if the user already said.
39
+ 4. **Visual direction** — 3 options tailored to the audience, each naming a palette + typographic cue: e.g. **corporate neutral** (near-white, single blue accent, sans throughout) · **editorial serif** (serif headings, generous leading, hairline rules) · **technical mono-accent** (mono labels, dense tables, monochrome + one signal color).
40
+
41
+ Ask about brand colors, a logo, or required sections only if still unclear afterwards.
42
+
43
+ ## Step 3 — Pick a doc id
44
+
45
+ **kebab-case**, short, descriptive: `q3-infra-review`, `acme-proposal-2026`, `auth-migration-rfc`. Check `docs/` for collisions.
46
+
47
+ ## Step 4 — Outline before code
48
+
49
+ Write the page plan first — one line per page, with its role. Typical structures:
50
+
51
+ | Type | Page plan |
52
+ | --- | --- |
53
+ | Report | Cover · Contents · Executive summary · Method · Findings (n pages) · Risks · Recommendations · Appendix |
54
+ | Whitepaper | Cover · Abstract · Problem · Approach · Evidence · Comparison · Conclusion · References |
55
+ | Proposal | Cover · Summary · Scope · Deliverables · Timeline · Pricing · Terms · Next steps |
56
+ | RFC / spec | Summary · Motivation · Design · Alternatives · Migration · Open questions |
57
+ | Memo | Header block · Context · Recommendation · Rationale · Next steps |
58
+
59
+ Rules for the plan:
60
+
61
+ - **Page 1 is the cover**; if the doc is over ~6 pages, **page 2 is `<TableOfContents />`**. Both are fixed pages; everything after them belongs in one `flow()` section so the framework paginates the body.
62
+ - The executive summary must stand alone — a reader who reads only that page should know the conclusion and the ask.
63
+ - One section per page unless a section is genuinely two paragraphs long.
64
+ - Plan the body as a **sequence of sections**, not as a page count — `flow()` decides how many pages that becomes. Only estimate the vertical budget for the fixed pages (cover, contents, dividers); see `doc-authoring` → `references/pagination.md`.
65
+
66
+ Show the user the page plan and the estimated page count before writing the file if the document is over ~8 pages — restructuring a 20-page doc after the fact is expensive.
67
+
68
+ ## Step 5 — Commit to a visual direction
69
+
70
+ Declare a top-level `export const design: DesignSystem` and consume `var(--od-*)` everywhere. Print constraints (white background, ≥13px body, one accent) are in `references/design-system.md` — read it before choosing the palette. If a theme was picked in Step 0, copy its `design` const verbatim instead of inventing one.
71
+
72
+ Keep the const a plain object literal: the dev UI's **Design panel** parses and rewrites it, and a spread or a value read from another constant makes the document untweakable (see "Writing for the Design panel" in `doc-authoring`).
73
+
74
+ Define the shared page shell, heading styles, and the running footer **once** as local constants/components at the top of `index.tsx`, then reuse them on every page. Copy-pasted page styling is how documents drift.
75
+
76
+ ## Step 6 — Write `docs/<id>/index.tsx`
77
+
78
+ Read **`doc-authoring`** first — file contract, canvas, type scale, headings/outline, TOC, page numbers, and a starter template are all there.
79
+
80
+ While writing:
81
+
82
+ - Real `<h1>/<h2>/<h3>` for every section title, so the outline and TOC populate.
83
+ - `<TableOfContents />` for the contents page. Never hand-write one.
84
+ - `useDocPageNumber()` / `useDocPageCount()` for the footer. Never hardcode.
85
+ - Put body content in one `flow(<>…</>, { footer: Footer })` section; mark captions `data-od-keep-with-previous`. Only run budget math for fixed pages.
86
+ - Where the user must supply data, leave `<ImagePlaceholder hint="…">` or an explicit `TODO:` in the copy — never invent numbers.
87
+
88
+ ## Step 7 — Self-review
89
+
90
+ Run the checklist in `doc-authoring` ("Self-review before finishing"). Then re-read the prose once as a reader: does the summary state the conclusion? Does every claim have a source? Is any page over budget?
91
+
92
+ ## Step 8 — Hand off
93
+
94
+ Tell the user:
95
+
96
+ - The doc id and file path.
97
+ - That the dev server hot-reloads — open `http://localhost:5273/d/<id>` (or refresh the home page).
98
+ - **Every placeholder and `TODO:` you left**, and what data each one needs.
99
+ - That "Export PDF" in the toolbar prints at the true page size, and "HTML" downloads a self-contained copy.
100
+ - That the **Design** button live-tweaks the palette and type scale and writes the result back to the source, and that images they want to drop in go through the **Assets** page.
101
+
102
+ Don't run the dev server yourself unless asked.