docspec 0.1.0 → 0.3.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 (84) hide show
  1. package/README.md +69 -51
  2. package/dist/__tests__/changed.test.d.ts +2 -0
  3. package/dist/__tests__/changed.test.d.ts.map +1 -0
  4. package/dist/__tests__/changed.test.js +98 -0
  5. package/dist/__tests__/changed.test.js.map +1 -0
  6. package/dist/__tests__/cli.test.js +38 -158
  7. package/dist/__tests__/cli.test.js.map +1 -1
  8. package/dist/__tests__/constants.test.js +8 -18
  9. package/dist/__tests__/constants.test.js.map +1 -1
  10. package/dist/__tests__/create.test.d.ts +2 -0
  11. package/dist/__tests__/create.test.d.ts.map +1 -0
  12. package/dist/__tests__/create.test.js +122 -0
  13. package/dist/__tests__/create.test.js.map +1 -0
  14. package/dist/__tests__/generate.test.d.ts +2 -0
  15. package/dist/__tests__/generate.test.d.ts.map +1 -0
  16. package/dist/__tests__/generate.test.js +113 -0
  17. package/dist/__tests__/generate.test.js.map +1 -0
  18. package/dist/__tests__/generator.test.js +36 -32
  19. package/dist/__tests__/generator.test.js.map +1 -1
  20. package/dist/__tests__/path-utils.test.d.ts +2 -0
  21. package/dist/__tests__/path-utils.test.d.ts.map +1 -0
  22. package/dist/__tests__/path-utils.test.js +49 -0
  23. package/dist/__tests__/path-utils.test.js.map +1 -0
  24. package/dist/__tests__/template.test.d.ts +2 -0
  25. package/dist/__tests__/template.test.d.ts.map +1 -0
  26. package/dist/__tests__/template.test.js +95 -0
  27. package/dist/__tests__/template.test.js.map +1 -0
  28. package/dist/__tests__/validator.test.js +50 -94
  29. package/dist/__tests__/validator.test.js.map +1 -1
  30. package/dist/changed.d.ts +25 -0
  31. package/dist/changed.d.ts.map +1 -0
  32. package/dist/changed.js +210 -0
  33. package/dist/changed.js.map +1 -0
  34. package/dist/cli.js +89 -73
  35. package/dist/cli.js.map +1 -1
  36. package/dist/constants.d.ts +5 -2
  37. package/dist/constants.d.ts.map +1 -1
  38. package/dist/constants.js +155 -40
  39. package/dist/constants.js.map +1 -1
  40. package/dist/create.d.ts +12 -0
  41. package/dist/create.d.ts.map +1 -0
  42. package/dist/create.js +93 -0
  43. package/dist/create.js.map +1 -0
  44. package/dist/docspec-changed.d.ts +25 -0
  45. package/dist/docspec-changed.d.ts.map +1 -0
  46. package/dist/docspec-changed.js +210 -0
  47. package/dist/docspec-changed.js.map +1 -0
  48. package/dist/docspec-generate.d.ts +22 -0
  49. package/dist/docspec-generate.d.ts.map +1 -0
  50. package/dist/docspec-generate.js +171 -0
  51. package/dist/docspec-generate.js.map +1 -0
  52. package/dist/format-parser.d.ts +24 -0
  53. package/dist/format-parser.d.ts.map +1 -0
  54. package/dist/format-parser.js +205 -0
  55. package/dist/format-parser.js.map +1 -0
  56. package/dist/generate.d.ts +26 -0
  57. package/dist/generate.d.ts.map +1 -0
  58. package/dist/generate.js +175 -0
  59. package/dist/generate.js.map +1 -0
  60. package/dist/generator.d.ts +6 -6
  61. package/dist/generator.d.ts.map +1 -1
  62. package/dist/generator.js +38 -26
  63. package/dist/generator.js.map +1 -1
  64. package/dist/index.d.ts +8 -4
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/index.js +16 -7
  67. package/dist/index.js.map +1 -1
  68. package/dist/logger.d.ts +40 -0
  69. package/dist/logger.d.ts.map +1 -0
  70. package/dist/logger.js +74 -0
  71. package/dist/logger.js.map +1 -0
  72. package/dist/path-utils.d.ts +17 -0
  73. package/dist/path-utils.d.ts.map +1 -0
  74. package/dist/path-utils.js +76 -0
  75. package/dist/path-utils.js.map +1 -0
  76. package/dist/template.d.ts +20 -0
  77. package/dist/template.d.ts.map +1 -0
  78. package/dist/template.js +151 -0
  79. package/dist/template.js.map +1 -0
  80. package/dist/validator.d.ts.map +1 -1
  81. package/dist/validator.js +39 -1
  82. package/dist/validator.js.map +1 -1
  83. package/docspec-format.md +45 -0
  84. package/package.json +4 -3
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.buildDocspecChangedPrompt = buildDocspecChangedPrompt;
37
+ const fs = __importStar(require("fs/promises"));
38
+ const fsSync = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const child_process_1 = require("child_process");
41
+ const path_utils_1 = require("./path-utils");
42
+ const DEFAULT_MAX_DOCSPECS = 10;
43
+ const DEFAULT_MAX_DIFF_CHARS = 120000;
44
+ /**
45
+ * List changed files via git diff --name-only base...merge
46
+ */
47
+ function listChangedFiles(base, merge, repoRoot) {
48
+ const out = (0, child_process_1.execSync)(`git diff --name-only ${base}...${merge}`, {
49
+ encoding: "utf-8",
50
+ cwd: repoRoot,
51
+ }).trim();
52
+ return out ? out.split("\n").map((line) => line.trim()).filter(Boolean) : [];
53
+ }
54
+ /**
55
+ * Get diff text via git diff base...merge, truncated if needed.
56
+ */
57
+ function getDiffText(base, merge, repoRoot, maxChars) {
58
+ let diff;
59
+ try {
60
+ diff = (0, child_process_1.execSync)(`git diff ${base}...${merge}`, { encoding: "utf-8", cwd: repoRoot });
61
+ }
62
+ catch {
63
+ return "";
64
+ }
65
+ if (diff.length > maxChars) {
66
+ diff = diff.slice(0, maxChars) + "\n\n[DIFF TRUNCATED]\n";
67
+ }
68
+ return diff;
69
+ }
70
+ /**
71
+ * Find all docspec paths under .docspec/ in the repo.
72
+ */
73
+ async function findAllDocspecPaths(docspecDir) {
74
+ const files = [];
75
+ try {
76
+ const entries = await fs.readdir(docspecDir, { withFileTypes: true });
77
+ for (const entry of entries) {
78
+ const full = path.join(docspecDir, entry.name);
79
+ if (entry.isDirectory()) {
80
+ files.push(...(await findAllDocspecPaths(full)));
81
+ }
82
+ else if (entry.isFile() && entry.name.endsWith(".docspec.md")) {
83
+ files.push(full);
84
+ }
85
+ }
86
+ }
87
+ catch (e) {
88
+ if (e.code !== "ENOENT")
89
+ throw e;
90
+ }
91
+ return files;
92
+ }
93
+ /**
94
+ * Find candidate docspec files to process given changed files.
95
+ * Strategy:
96
+ * 1) Changed files that are under .docspec/ and end with .docspec.md are included.
97
+ * 2) For each other changed file, walk up from its directory to repo root; at each level,
98
+ * include docspecs whose target markdown lives in that directory.
99
+ */
100
+ function findCandidateDocspecs(repoRoot, docspecPaths, changedFiles, maxDocspecs) {
101
+ const normalizedRoot = path.normalize(repoRoot).replace(/\\/g, "/");
102
+ const candidates = [];
103
+ const seen = new Set();
104
+ const add = (p) => {
105
+ const norm = path.normalize(p).replace(/\\/g, "/");
106
+ if (!seen.has(norm)) {
107
+ seen.add(norm);
108
+ candidates.push(p);
109
+ }
110
+ };
111
+ // 1) Directly changed docspecs (under .docspec/)
112
+ for (const f of changedFiles) {
113
+ const normalized = path.normalize(f).replace(/\\/g, "/");
114
+ if ((0, path_utils_1.isDocspecPath)(normalized) || (normalized.startsWith(".docspec/") && normalized.endsWith(".docspec.md"))) {
115
+ const full = path.join(repoRoot, f);
116
+ add(full);
117
+ }
118
+ }
119
+ // 2) For each changed file, walk up directory and include docspecs whose target markdown is in that directory
120
+ for (const f of changedFiles) {
121
+ const normalized = path.normalize(f).replace(/\\/g, "/");
122
+ if (normalized.startsWith(".docspec/"))
123
+ continue; // already handled
124
+ const fullPath = path.join(repoRoot, f);
125
+ let dir = path.dirname(fullPath);
126
+ while (true) {
127
+ const relDir = path.relative(repoRoot, dir).replace(/\\/g, "/") || ".";
128
+ for (const { docspecPath, targetMdPath } of docspecPaths) {
129
+ const targetDir = path.dirname(targetMdPath).replace(/\\/g, "/") || ".";
130
+ if (targetDir === relDir) {
131
+ add(docspecPath);
132
+ }
133
+ }
134
+ const parent = path.dirname(dir);
135
+ if (parent === dir || path.relative(repoRoot, parent).startsWith(".."))
136
+ break;
137
+ dir = parent;
138
+ }
139
+ // Include if the changed file is the target markdown
140
+ for (const { docspecPath, targetMdPath } of docspecPaths) {
141
+ if (path.normalize(f).replace(/\\/g, "/") === path.normalize(targetMdPath).replace(/\\/g, "/")) {
142
+ add(docspecPath);
143
+ }
144
+ }
145
+ }
146
+ return candidates.slice(0, maxDocspecs);
147
+ }
148
+ /**
149
+ * Build the docspec-changed prompt and return it as a string.
150
+ * If options.outputPath is set, writes the prompt to that file.
151
+ */
152
+ async function buildDocspecChangedPrompt(options) {
153
+ const repoRoot = path.resolve(options.repoRoot ?? process.cwd());
154
+ const docspecDir = path.join(repoRoot, ".docspec");
155
+ let changedFiles = options.changedFiles ?? [];
156
+ let diffText = "";
157
+ if (changedFiles.length === 0 && options.base && options.merge) {
158
+ changedFiles = listChangedFiles(options.base, options.merge, repoRoot);
159
+ diffText = getDiffText(options.base, options.merge, repoRoot, options.maxDiffChars ?? DEFAULT_MAX_DIFF_CHARS);
160
+ }
161
+ else if (options.changedFiles && options.changedFiles.length > 0 && options.base && options.merge) {
162
+ diffText = getDiffText(options.base, options.merge, repoRoot, options.maxDiffChars ?? DEFAULT_MAX_DIFF_CHARS);
163
+ }
164
+ const allDocspecPaths = await findAllDocspecPaths(docspecDir);
165
+ const docspecWithTargets = allDocspecPaths
166
+ .map((p) => {
167
+ const rel = path.relative(repoRoot, p).replace(/\\/g, "/");
168
+ const targetMd = (0, path_utils_1.docspecToMarkdownPath)(rel);
169
+ return { docspecPath: p, targetMdPath: targetMd };
170
+ })
171
+ .filter(({ docspecPath }) => fsSync.existsSync(docspecPath));
172
+ const candidates = findCandidateDocspecs(repoRoot, docspecWithTargets, changedFiles, options.maxDocspecs ?? DEFAULT_MAX_DOCSPECS);
173
+ const parts = [
174
+ "Merged PR diff (context):",
175
+ "<diff>",
176
+ diffText || "(no diff available)",
177
+ "</diff>",
178
+ "",
179
+ "The following docspec files were discovered based on the PR changes. For each docspec, check if its target markdown file needs to be updated based on the code changes:",
180
+ "",
181
+ ];
182
+ let added = 0;
183
+ for (const docspecPath of candidates) {
184
+ const relDocspec = path.relative(repoRoot, docspecPath).replace(/\\/g, "/");
185
+ const targetMdPath = (0, path_utils_1.docspecToMarkdownPath)(relDocspec);
186
+ const targetFull = path.join(repoRoot, targetMdPath);
187
+ try {
188
+ await fs.access(targetFull);
189
+ }
190
+ catch {
191
+ continue;
192
+ }
193
+ const docspecContent = await fs.readFile(docspecPath, "utf-8");
194
+ const mdContent = await fs.readFile(targetFull, "utf-8");
195
+ parts.push(`## Docspec: ${relDocspec}`, `Target markdown: ${targetMdPath}`, "", "<docspec>", docspecContent, "</docspec>", "", "<markdown>", mdContent, "</markdown>", "");
196
+ added++;
197
+ }
198
+ if (added === 0) {
199
+ return { prompt: "", outputPath: null };
200
+ }
201
+ parts.push("Task:", "1. Explore the repository using your available tools to understand the codebase context", "2. Understand how the code changes in the diff relate to each docspec's requirements", "3. For each markdown file listed above, check if it already satisfies its docspec given the code changes", "4. Only update markdown files if changes are actually necessary to satisfy their docspecs - avoid making unnecessary changes", "5. Use the Edit tool to modify markdown files directly if changes are needed", "6. Do not provide any text output - files are modified directly using tools");
202
+ const prompt = parts.join("\n");
203
+ const outPath = options.outputPath ? path.resolve(repoRoot, options.outputPath) : null;
204
+ if (outPath && prompt) {
205
+ await fs.mkdir(path.dirname(outPath), { recursive: true });
206
+ await fs.writeFile(outPath, prompt, "utf-8");
207
+ }
208
+ return { prompt, outputPath: outPath };
209
+ }
210
+ //# sourceMappingURL=docspec-changed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docspec-changed.js","sourceRoot":"","sources":["../src/docspec-changed.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2IA,8DAqGC;AAhPD,gDAAkC;AAClC,2CAA6B;AAC7B,2CAA6B;AAC7B,iDAAyC;AACzC,6CAAoE;AAEpE,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAiBtC;;GAEG;AACH,SAAS,gBAAgB,CAAC,IAAY,EAAE,KAAa,EAAE,QAAgB;IACrE,MAAM,GAAG,GAAG,IAAA,wBAAQ,EAAC,wBAAwB,IAAI,MAAM,KAAK,EAAE,EAAE;QAC9D,QAAQ,EAAE,OAAO;QACjB,GAAG,EAAE,QAAQ;KACd,CAAC,CAAC,IAAI,EAAE,CAAC;IACV,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/E,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,IAAY,EAAE,KAAa,EAAE,QAAgB,EAAE,QAAgB;IAClF,IAAI,IAAY,CAAC;IACjB,IAAI,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markdownPath: string;
4
+ /** If true, overwrite existing docspec. If false and docspec exists, throws. */
5
+ overwrite?: boolean;
6
+ /** Repo root (default process.cwd()). */
7
+ repoRoot?: string;
8
+ }
9
+ /**
10
+ * Generate the docspec file (if missing or overwrite), then build plan and implementation prompts.
11
+ * Returns combined prompt (implementation prompt with {{PLAN}} placeholder) and optional paths to write.
12
+ */
13
+ export declare function buildDocspecGeneratePrompts(options: DocspecGenerateOptions & {
14
+ outputPromptPath?: string;
15
+ outputPlanPath?: string;
16
+ }): Promise<{
17
+ planPrompt: string;
18
+ implPrompt: string;
19
+ outputPromptPath?: string;
20
+ outputPlanPath?: string;
21
+ }>;
22
+ //# sourceMappingURL=docspec-generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docspec-generate.d.ts","sourceRoot":"","sources":["../src/docspec-generate.ts"],"names":[],"mappings":"AAqFA,MAAM,WAAW,sBAAsB;IACrC,mFAAmF;IACnF,YAAY,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,sBAAsB,GAAG;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GACA,OAAO,CAAC;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA0DzG"}
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.buildDocspecGeneratePrompts = buildDocspecGeneratePrompts;
37
+ const fs = __importStar(require("fs/promises"));
38
+ const path = __importStar(require("path"));
39
+ const generator_1 = require("./generator");
40
+ const path_utils_1 = require("./path-utils");
41
+ const PLAN_TEMPLATE = `You are analyzing a markdown file and its docspec to discover missing or irrelevant information. Do not ask questions - create the plan directly.
42
+
43
+ <markdown path="{{md_path}}">
44
+ {{md_text}}
45
+ </markdown>
46
+
47
+ <docspec path="{{docspec_path}}">
48
+ {{docspec_text}}
49
+ </docspec>
50
+
51
+ Task: Focus on INFORMATION DISCOVERY. Use all of your available tools to explore the repository and understand what actually exists, then analyze both files and create a plan that identifies:
52
+
53
+ 1. **Missing information in the docspec**: What important details about the markdown file are not captured in sections 1-5?
54
+ - What does the markdown actually contain that isn't mentioned in the docspec?
55
+ - What should trigger updates that isn't currently listed?
56
+ - What structure/guidelines are missing?
57
+
58
+ 2. **Irrelevant or incorrect information in the docspec**: What's in the docspec that doesn't match reality?
59
+ - Does the docspec describe things that aren't actually in the markdown?
60
+ - Are there update triggers that don't make sense?
61
+ - Are there structure requirements that don't match the actual document?
62
+
63
+ 3. **Missing information in the markdown**: What should be documented but isn't?
64
+ - Are there important details missing?
65
+ - Are there sections that should exist but don't?
66
+
67
+ IMPORTANT: The docspec structure must be preserved:
68
+ - Keep the header format: \`# DOCSPEC: [filename]\`
69
+ - Keep the one-line description
70
+ - Keep the \`## AGENT INSTRUCTIONS\` section exactly as-is
71
+ - Keep section headers: \`## 1. Document Purpose\`, \`## 2. Update Triggers\`, etc.
72
+ - ONLY update the CONTENT within sections 1-5, not the headers or structure
73
+
74
+ Output your plan in a clear, structured format focusing on information gaps and corrections.
75
+ `;
76
+ const IMPL_TEMPLATE = `Based on this information discovery plan:
77
+ <plan>
78
+ {{PLAN}}
79
+ </plan>
80
+
81
+ You need to update two files:
82
+ 1. {{md_path}} - the markdown file
83
+ 2. {{docspec_path}} - the docspec file
84
+
85
+ CRITICAL CONSTRAINTS FOR DOCSPEC FILE - YOU MUST PRESERVE THE EXACT STRUCTURE:
86
+
87
+ 1. Read the existing {{docspec_path}} file FIRST using the Read tool
88
+ 2. PRESERVE EXACTLY:
89
+ - The exact header format (e.g. \`# DOCSPEC: Readme\` or \`# DOCSPEC: [README.md](/README.md)\`) - keep it EXACTLY as written
90
+ - The exact one-line description format (e.g. \`> A specification that ...\`) - keep it EXACTLY as written
91
+ - The \`## AGENT INSTRUCTIONS\` section if it exists - keep it EXACTLY as-is, do not modify
92
+ - The EXACT section header names and numbers (e.g. \`## 1. Document Purpose\` or \`## 2. Update Triggers\`) - keep them EXACTLY as written
93
+ - The order of sections - do not reorder them
94
+
95
+ 3. ONLY update the CONTENT within sections 1-5 (the text below each section header)
96
+ - Do NOT change section header text, numbers, or names
97
+ - Do NOT change the format of headers
98
+ - Do NOT modify title, description, or AGENT INSTRUCTIONS
99
+
100
+ Task:
101
+ 1. Read {{docspec_path}} and note its EXACT structure
102
+ 2. Read {{md_path}}
103
+ 3. Explore the repository and discover information about:
104
+ - What the codebase actually contains
105
+ - What files exist that relate to the markdown
106
+ - What the actual structure and content of the markdown is
107
+ 4. For {{docspec_path}}: Update ONLY the content text within sections 1-5. Preserve ALL structure, headers, format, and separators exactly as they were.
108
+ 5. For {{md_path}}: Add any missing information identified in the plan
109
+ 6. Make changes directly to the files
110
+ `;
111
+ function substitute(template, vars) {
112
+ let out = template;
113
+ for (const [key, value] of Object.entries(vars)) {
114
+ out = out.replace(new RegExp(`\\{\\{${key}\\}\\}`, "g"), value);
115
+ }
116
+ return out;
117
+ }
118
+ /**
119
+ * Generate the docspec file (if missing or overwrite), then build plan and implementation prompts.
120
+ * Returns combined prompt (implementation prompt with {{PLAN}} placeholder) and optional paths to write.
121
+ */
122
+ async function buildDocspecGeneratePrompts(options) {
123
+ const repoRoot = path.resolve(options.repoRoot ?? process.cwd());
124
+ const mdPath = path.normalize(options.markdownPath).replace(/\\/g, "/");
125
+ const mdFull = path.join(repoRoot, mdPath);
126
+ const docspecPath = (0, path_utils_1.markdownToDocspecPath)(mdPath);
127
+ const docspecFull = path.join(repoRoot, docspecPath);
128
+ try {
129
+ await fs.access(mdFull);
130
+ }
131
+ catch {
132
+ throw new Error(`Markdown file not found: ${mdFull}`);
133
+ }
134
+ const docspecExists = await fs.access(docspecFull).then(() => true).catch(() => false);
135
+ if (docspecExists && !options.overwrite) {
136
+ throw new Error(`Docspec file already exists: ${docspecPath}. To overwrite, set overwrite to true.`);
137
+ }
138
+ await (0, generator_1.generateDocspec)(mdPath);
139
+ const mdText = await fs.readFile(mdFull, "utf-8");
140
+ const docspecText = await fs.readFile(docspecFull, "utf-8");
141
+ const vars = {
142
+ md_path: mdPath,
143
+ md_text: mdText,
144
+ docspec_path: docspecPath,
145
+ docspec_text: docspecText,
146
+ "{{PLAN}}": "{{PLAN}}",
147
+ };
148
+ const planPrompt = substitute(PLAN_TEMPLATE, vars);
149
+ const implPrompt = substitute(IMPL_TEMPLATE, vars);
150
+ const outPrompt = options.outputPromptPath
151
+ ? path.resolve(repoRoot, options.outputPromptPath)
152
+ : undefined;
153
+ const outPlan = options.outputPlanPath
154
+ ? path.resolve(repoRoot, options.outputPlanPath)
155
+ : undefined;
156
+ if (outPrompt) {
157
+ await fs.mkdir(path.dirname(outPrompt), { recursive: true });
158
+ await fs.writeFile(outPrompt, implPrompt, "utf-8");
159
+ }
160
+ if (outPlan) {
161
+ await fs.mkdir(path.dirname(outPlan), { recursive: true });
162
+ await fs.writeFile(outPlan, planPrompt, "utf-8");
163
+ }
164
+ return {
165
+ planPrompt,
166
+ implPrompt,
167
+ outputPromptPath: outPrompt,
168
+ outputPlanPath: outPlan,
169
+ };
170
+ }
171
+ //# sourceMappingURL=docspec-generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docspec-generate.js","sourceRoot":"","sources":["../src/docspec-generate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,kEA+DC;AAjKD,gDAAkC;AAClC,2CAA6B;AAC7B,2CAA8C;AAC9C,6CAAqD;AAErD,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCrB,CAAC;AAEF,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCrB,CAAC;AAEF,SAAS,UAAU,CAAC,QAAgB,EAAE,IAA4B;IAChE,IAAI,GAAG,GAAG,QAAQ,CAAC;IACnB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,SAAS,GAAG,QAAQ,EAAE,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,G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+ boilerplate: string;
4
+ number: number;
5
+ }
6
+ export interface ParsedFormat {
7
+ sections: ParsedSection[];
8
+ template: string;
9
+ agentInstructions?: string;
10
+ }
11
+ /**
12
+ * Parse the docspec format file
13
+ */
14
+ export declare function parseFormatFile(formatFilePath: string): ParsedFormat;
15
+ /**
16
+ * Parse format content from a string
17
+ */
18
+ export declare function parseFormatContent(content: string): ParsedFormat;
19
+ /**
20
+ * Get the path to the format file. Uses .docspec/docspec.md in cwd.
21
+ * If it doesn't exist, seeds it from the bundled docspec-format.md and returns the new path.
22
+ */
23
+ export declare function getFormatFilePath(): string;
24
+ //# sourceMappingURL=format-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-parser.d.ts","sourceRoot":"","sources":["../src/format-parser.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,cAAc,EAAE,MAAM,GAAG,YAAY,CAKpE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,YAAY,CAyIhE;AAyBD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAS1C"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.parseFormatFile = parseFormatFile;
37
+ exports.parseFormatContent = parseFormatContent;
38
+ exports.getFormatFilePath = getFormatFilePath;
39
+ const fs = __importStar(require("fs"));
40
+ const path = __importStar(require("path"));
41
+ const logger_1 = require("./logger");
42
+ /**
43
+ * Parse the docspec format file
44
+ */
45
+ function parseFormatFile(formatFilePath) {
46
+ logger_1.logger.debug(`Reading format file: ${formatFilePath}`);
47
+ const content = fs.readFileSync(formatFilePath, "utf-8");
48
+ logger_1.logger.debug(`Format file read: ${content.length} characters`);
49
+ return parseFormatContent(content);
50
+ }
51
+ /**
52
+ * Parse format content from a string
53
+ */
54
+ function parseFormatContent(content) {
55
+ const lines = content.split("\n");
56
+ logger_1.logger.debug(`Parsing format content: ${lines.length} lines`);
57
+ // Look for AGENT INSTRUCTIONS section first
58
+ let agentInstructions;
59
+ let agentInstructionsStart = -1;
60
+ let agentInstructionsEnd = -1;
61
+ for (let i = 0; i < lines.length; i++) {
62
+ if (lines[i].trim() === "## AGENT INSTRUCTIONS") {
63
+ agentInstructionsStart = i;
64
+ logger_1.logger.debug(`Found AGENT INSTRUCTIONS section at line ${i + 1}`);
65
+ break;
66
+ }
67
+ }
68
+ // If AGENT INSTRUCTIONS section found, extract it
69
+ if (agentInstructionsStart >= 0) {
70
+ // Find the end of the AGENT INSTRUCTIONS section
71
+ // It ends at the next section header (##) or end of file
72
+ for (let i = agentInstructionsStart + 1; i < lines.length; i++) {
73
+ const trimmedLine = lines[i].trim();
74
+ // Check if this is a section header (starts with ##)
75
+ if (trimmedLine.match(/^##\s+/)) {
76
+ agentInstructionsEnd = i;
77
+ break;
78
+ }
79
+ }
80
+ if (agentInstructionsEnd < 0) {
81
+ agentInstructionsEnd = lines.length;
82
+ }
83
+ // Extract content between header and next section
84
+ const agentLines = lines.slice(agentInstructionsStart + 1, agentInstructionsEnd);
85
+ let agentContent = agentLines.join("\n");
86
+ // Remove separator lines (---) from the content
87
+ agentContent = agentContent
88
+ .split("\n")
89
+ .filter(line => line.trim() !== "---")
90
+ .join("\n")
91
+ .trim();
92
+ if (agentContent) {
93
+ agentInstructions = agentContent;
94
+ logger_1.logger.debug(`Extracted agent instructions: ${agentContent.length} characters`);
95
+ }
96
+ }
97
+ else {
98
+ logger_1.logger.debug("No AGENT INSTRUCTIONS section found");
99
+ }
100
+ // Find all section headers: ## N. Section Name
101
+ const sectionHeaderRegex = /^##\s+(\d+)\.\s+(.+)$/;
102
+ const sectionHeaders = [];
103
+ for (let i = 0; i < lines.length; i++) {
104
+ // Skip the AGENT INSTRUCTIONS header if it exists
105
+ if (lines[i].trim() === "## AGENT INSTRUCTIONS") {
106
+ continue;
107
+ }
108
+ const match = lines[i].match(sectionHeaderRegex);
109
+ if (match) {
110
+ sectionHeaders.push({
111
+ lineIndex: i,
112
+ number: parseInt(match[1], 10),
113
+ name: match[2].trim(),
114
+ });
115
+ logger_1.logger.debug(`Found section header: ${match[1]}. ${match[2].trim()} at line ${i + 1}`);
116
+ }
117
+ }
118
+ if (sectionHeaders.length === 0) {
119
+ logger_1.logger.debug("No section headers found in format file");
120
+ throw new Error("No section headers found in format file. Expected format: ## N. Section Name");
121
+ }
122
+ logger_1.logger.debug(`Found ${sectionHeaders.length} section header(s)`);
123
+ // Extract template: everything before the first numbered section header
124
+ // But exclude the AGENT INSTRUCTIONS section if it exists
125
+ const firstSectionLine = sectionHeaders[0].lineIndex;
126
+ let templateBeforeSections;
127
+ if (agentInstructionsStart >= 0 && agentInstructionsStart < firstSectionLine) {
128
+ // AGENT INSTRUCTIONS is between title and first section
129
+ // Template is everything before AGENT INSTRUCTIONS
130
+ templateBeforeSections = lines.slice(0, agentInstructionsStart).join("\n").trim();
131
+ logger_1.logger.debug("Template extracted before AGENT INSTRUCTIONS section");
132
+ }
133
+ else {
134
+ // No AGENT INSTRUCTIONS, use everything before first section
135
+ templateBeforeSections = lines.slice(0, firstSectionLine).join("\n").trim();
136
+ logger_1.logger.debug("Template extracted before first section");
137
+ }
138
+ const template = templateBeforeSections + "\n\n{{AGENT_INSTRUCTIONS}}\n\n{{SECTIONS}}\n";
139
+ logger_1.logger.debug(`Template length: ${template.length} characters`);
140
+ // Extract sections
141
+ const sections = [];
142
+ for (let i = 0; i < sectionHeaders.length; i++) {
143
+ const header = sectionHeaders[i];
144
+ const nextHeaderLine = i < sectionHeaders.length - 1
145
+ ? sectionHeaders[i + 1].lineIndex
146
+ : lines.length;
147
+ // Extract content between this header and the next header
148
+ const sectionLines = lines.slice(header.lineIndex + 1, nextHeaderLine);
149
+ let sectionContent = sectionLines.join("\n");
150
+ // Remove separator lines (---) from the content
151
+ sectionContent = sectionContent
152
+ .split("\n")
153
+ .filter(line => line.trim() !== "---")
154
+ .join("\n")
155
+ .trim();
156
+ logger_1.logger.debug(`Extracted section "${header.name}": ${sectionContent.length} characters`);
157
+ sections.push({
158
+ name: header.name,
159
+ boilerplate: sectionContent,
160
+ number: header.number,
161
+ });
162
+ }
163
+ // Sort sections by number to ensure correct order
164
+ sections.sort((a, b) => a.number - b.number);
165
+ logger_1.logger.debug(`Parsed ${sections.length} section(s) from format file`);
166
+ return {
167
+ sections,
168
+ template,
169
+ agentInstructions,
170
+ };
171
+ }
172
+ const USER_TEMPLATE = ".docspec/docspec.md";
173
+ /**
174
+ * Seed .docspec/docspec.md from the bundled docspec-format.md if it doesn't exist.
175
+ * Returns the path to .docspec/docspec.md (in cwd).
176
+ */
177
+ function seedDefaultFormatFile() {
178
+ const cwd = process.cwd();
179
+ const userPath = path.join(cwd, ".docspec", "docspec.md");
180
+ const defaultPath = path.join(__dirname, "..", "docspec-format.md");
181
+ logger_1.logger.debug(`Seeding ${userPath} from ${defaultPath}`);
182
+ if (!fs.existsSync(defaultPath)) {
183
+ throw new Error(`Default template not found at ${defaultPath}. ` +
184
+ `Create .docspec/docspec.md in your project or ensure the docspec package is installed correctly.`);
185
+ }
186
+ fs.mkdirSync(path.join(cwd, ".docspec"), { recursive: true });
187
+ fs.copyFileSync(defaultPath, userPath);
188
+ logger_1.logger.debug(`Seeded ${userPath}`);
189
+ return userPath;
190
+ }
191
+ /**
192
+ * Get the path to the format file. Uses .docspec/docspec.md in cwd.
193
+ * If it doesn't exist, seeds it from the bundled docspec-format.md and returns the new path.
194
+ */
195
+ function getFormatFilePath() {
196
+ const cwd = process.cwd();
197
+ const userPath = path.join(cwd, ".docspec", "docspec.md");
198
+ if (fs.existsSync(userPath)) {
199
+ logger_1.logger.debug(`Format file found: ${userPath}`);
200
+ return userPath;
201
+ }
202
+ logger_1.logger.debug(`Format file not found at ${userPath}, seeding from default`);
203
+ return seedDefaultFormatFile();
204
+ }
205
+ //# sourceMappingURL=format-parser.js.map