@popoverai/dotrequirements 0.25.0 → 0.26.1
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.
- package/dist/cli.js +8 -1
- package/dist/codebase-to-spec/area-name.d.ts +13 -0
- package/dist/codebase-to-spec/area-name.js +18 -0
- package/dist/codebase-to-spec/cache.d.ts +31 -0
- package/dist/codebase-to-spec/cache.js +29 -1
- package/dist/codebase-to-spec/compose.d.ts +7 -4
- package/dist/codebase-to-spec/compose.js +10 -21
- package/dist/codebase-to-spec/dispatch.js +1 -1
- package/dist/codebase-to-spec/present.d.ts +9 -0
- package/dist/codebase-to-spec/present.js +30 -4
- package/dist/codebase-to-spec/prompts/planner-initial.d.ts +3 -2
- package/dist/codebase-to-spec/prompts/planner-initial.js +3 -2
- package/dist/codebase-to-spec/renumber.d.ts +52 -0
- package/dist/codebase-to-spec/renumber.js +105 -0
- package/dist/codebase-to-spec/schemas.d.ts +35 -240
- package/dist/codebase-to-spec/schemas.js +5 -173
- package/dist/codebase-to-spec/skill-install.d.ts +16 -6
- package/dist/codebase-to-spec/skill-install.js +109 -47
- package/dist/codebase-to-spec/version-check.d.ts +31 -0
- package/dist/codebase-to-spec/version-check.js +56 -0
- package/dist/commands/ai-setup.d.ts +12 -1
- package/dist/commands/ai-setup.js +65 -33
- package/dist/commands/codebase-to-spec/dispatch-editor.js +1 -1
- package/dist/commands/codebase-to-spec/dispatch-spec.js +1 -1
- package/dist/commands/codebase-to-spec/index.js +7 -103
- package/dist/commands/codebase-to-spec/pack.d.ts +4 -0
- package/dist/commands/codebase-to-spec/pack.js +25 -1
- package/dist/commands/codebase-to-spec/present-orchestrator.d.ts +3 -1
- package/dist/commands/codebase-to-spec/present-orchestrator.js +11 -4
- package/dist/commands/init.js +6 -1
- package/dist/commands/link-resolution.d.ts +79 -0
- package/dist/commands/link-resolution.js +141 -0
- package/dist/commands/link.d.ts +14 -4
- package/dist/commands/link.js +369 -16
- package/dist/commands/pull.js +19 -2
- package/dist/commands/push.js +36 -2
- package/dist/convex.d.ts +5 -3
- package/dist/convex.js +5 -3
- package/dist/harness/cache.d.ts +0 -14
- package/dist/harness/cache.js +1 -41
- package/dist/harness/finalize.js +2 -2
- package/dist/harness/prepare.js +1 -3
- package/dist/harness/requirementsLoader.d.ts +3 -3
- package/dist/harness/requirementsLoader.js +13 -8
- package/dist/mcp/handlers/authoring.d.ts +5 -5
- package/dist/mcp/handlers/authoring.js +9 -9
- package/dist/mcp/handlers/push.d.ts +2 -2
- package/dist/mcp/handlers/push.js +36 -3
- package/dist/mcp/handlers/review.d.ts +4 -4
- package/dist/mcp/handlers/review.js +4 -4
- package/dist/mcp/handlers/search.d.ts +1 -1
- package/dist/mcp/handlers/search.js +1 -1
- package/dist/mcp/index.js +29 -0
- package/dist/push/core.d.ts +18 -0
- package/dist/push/core.js +70 -3
- package/dist/push/index.d.ts +1 -1
- package/dist/push/index.js +1 -1
- package/dist/schema/parser-core.js +5 -1
- package/dist/schema/parser.js +5 -1
- package/dist/schema/run-marker.d.ts +38 -0
- package/dist/schema/run-marker.js +138 -0
- package/dist/schema/schemas.d.ts +12 -0
- package/dist/schema/schemas.js +1 -0
- package/dist/templates/agents/cts-worker.md +1 -1
- package/dist/templates/skills/codebase-to-spec/SKILL.md +39 -11
- package/dist/templates/workflows/specify-codebase.js +4 -2
- package/dist/utils/own-package.d.ts +10 -0
- package/dist/utils/own-package.js +13 -0
- package/dist/utils/project-selector.d.ts +5 -0
- package/dist/utils/project-selector.js +4 -0
- package/package.json +2 -2
- package/dist/codebase-to-spec/edit-loop.d.ts +0 -54
- package/dist/codebase-to-spec/edit-loop.js +0 -195
- package/dist/codebase-to-spec/editor.d.ts +0 -54
- package/dist/codebase-to-spec/editor.js +0 -74
- package/dist/codebase-to-spec/fan-out.d.ts +0 -63
- package/dist/codebase-to-spec/fan-out.js +0 -215
- package/dist/codebase-to-spec/outline-review-loop.d.ts +0 -51
- package/dist/codebase-to-spec/outline-review-loop.js +0 -187
- package/dist/codebase-to-spec/planner.d.ts +0 -41
- package/dist/codebase-to-spec/planner.js +0 -76
- package/dist/codebase-to-spec/prompts/outline-reviewer.d.ts +0 -12
- package/dist/codebase-to-spec/prompts/outline-reviewer.js +0 -89
- package/dist/codebase-to-spec/slice.d.ts +0 -49
- package/dist/codebase-to-spec/slice.js +0 -111
- package/dist/codebase-to-spec/specifier.d.ts +0 -60
- package/dist/codebase-to-spec/specifier.js +0 -85
- package/dist/codebase-to-spec/summary.d.ts +0 -51
- package/dist/codebase-to-spec/summary.js +0 -183
- package/dist/commands/codebase-to-spec/compose.d.ts +0 -14
- package/dist/commands/codebase-to-spec/compose.js +0 -57
- package/dist/commands/codebase-to-spec/edit-loop.d.ts +0 -16
- package/dist/commands/codebase-to-spec/edit-loop.js +0 -83
- package/dist/commands/codebase-to-spec/fan-out.d.ts +0 -19
- package/dist/commands/codebase-to-spec/fan-out.js +0 -77
- package/dist/commands/codebase-to-spec/plan-loop.d.ts +0 -26
- package/dist/commands/codebase-to-spec/plan-loop.js +0 -105
- package/dist/commands/codebase-to-spec/present.d.ts +0 -26
- package/dist/commands/codebase-to-spec/present.js +0 -97
- package/dist/commands/codebase-to-spec/run.d.ts +0 -20
- package/dist/commands/codebase-to-spec/run.js +0 -86
- package/dist/commands/codebase-to-spec/specify-area.d.ts +0 -18
- package/dist/commands/codebase-to-spec/specify-area.js +0 -82
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Spec review + editor loop.
|
|
3
|
-
*
|
|
4
|
-
* Same structure as the outline review loop, scaled up for document-level
|
|
5
|
-
* revision: stateful spec reviewer + stateless editor. The reviewer
|
|
6
|
-
* persists across turns so it can compare prior spec versions to the latest.
|
|
7
|
-
*
|
|
8
|
-
* Requirements covered:
|
|
9
|
-
* - CTS-EDIT-1: stateful spec reviewer
|
|
10
|
-
* - CTS-EDIT-2: approved → proceed
|
|
11
|
-
* - CTS-EDIT-3: approved-with-revisions → one mechanical edit pass
|
|
12
|
-
* - CTS-EDIT-4: requires-another-review → revise & resubmit
|
|
13
|
-
* - CTS-EDIT-5: editor operates on cohesive document
|
|
14
|
-
* - CTS-EDIT-6: max-turns + convergence nudge
|
|
15
|
-
*/
|
|
16
|
-
import { randomUUID } from "node:crypto";
|
|
17
|
-
import { copyFileSync } from "node:fs";
|
|
18
|
-
import { runClaude } from "./claude.js";
|
|
19
|
-
import { runEditor } from "./editor.js";
|
|
20
|
-
import { SPEC_REVIEWER_PROMPT } from "./prompts/spec-reviewer.js";
|
|
21
|
-
import { parseSpecReview, SPEC_REVIEW_JSON_SCHEMA, } from "./schemas.js";
|
|
22
|
-
export const DEFAULT_EDIT_LOOP_MAX_TURNS = 6;
|
|
23
|
-
function reviewerUserMessageInitial(specPath, packPath) {
|
|
24
|
-
return [
|
|
25
|
-
`Initial spec review.`,
|
|
26
|
-
``,
|
|
27
|
-
`Composed spec: ${specPath}`,
|
|
28
|
-
`Codebase pack: ${packPath}`,
|
|
29
|
-
``,
|
|
30
|
-
`Read both via the Read tool, then produce your critique JSON.`,
|
|
31
|
-
].join("\n");
|
|
32
|
-
}
|
|
33
|
-
function reviewerUserMessageRevised(turn, specPath, packPath, nudge) {
|
|
34
|
-
const lines = [
|
|
35
|
-
`Review turn ${turn}. The editor has revised the spec based on your prior feedback.`,
|
|
36
|
-
``,
|
|
37
|
-
];
|
|
38
|
-
if (nudge) {
|
|
39
|
-
lines.push(nudge, ``);
|
|
40
|
-
}
|
|
41
|
-
lines.push(`Revised spec: ${specPath}`, `Codebase pack at ${packPath} is unchanged.`, ``, `Read the revised spec, compare to the prior version, and produce your critique JSON.`);
|
|
42
|
-
return lines.join("\n");
|
|
43
|
-
}
|
|
44
|
-
function convergenceNudge(turn, maxTurns) {
|
|
45
|
-
return `CONVERGENCE NUDGE: This is review turn ${turn} of ${maxTurns} maximum. Please prioritize convergence. Your job is still to only approve a genuinely-ready spec, but if it is close, lean toward \`approved-with-revisions\` over \`requires-another-review\`. Reserve \`requires-another-review\` for genuine issues that the editor has not addressed despite prior feedback.`;
|
|
46
|
-
}
|
|
47
|
-
async function callReviewer(args) {
|
|
48
|
-
const result = await args.runner({
|
|
49
|
-
systemPrompt: SPEC_REVIEWER_PROMPT,
|
|
50
|
-
userMessage: args.userMessage,
|
|
51
|
-
model: args.model,
|
|
52
|
-
tools: ["Read", "Grep", "Glob"],
|
|
53
|
-
addDirs: args.addDirs,
|
|
54
|
-
jsonSchema: SPEC_REVIEW_JSON_SCHEMA,
|
|
55
|
-
session: {
|
|
56
|
-
kind: args.isFirstTurn ? "fresh" : "resume",
|
|
57
|
-
sessionId: args.sessionId,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
if (result.exitCode !== 0) {
|
|
61
|
-
throw new Error(`Spec reviewer failed (exit ${result.exitCode}): ${result.stderr || result.stdout}`);
|
|
62
|
-
}
|
|
63
|
-
// Retry-once on parse failure (CTS-EDIT-1 convention, same as outline loop).
|
|
64
|
-
try {
|
|
65
|
-
return parseSpecReview(result.stdout);
|
|
66
|
-
}
|
|
67
|
-
catch (err) {
|
|
68
|
-
const retry = await args.runner({
|
|
69
|
-
systemPrompt: SPEC_REVIEWER_PROMPT,
|
|
70
|
-
userMessage: `${args.userMessage}\n\n(Your prior output failed schema validation: ${err instanceof Error ? err.message : String(err)}. Please try again, emitting JSON only.)`,
|
|
71
|
-
model: args.model,
|
|
72
|
-
tools: ["Read", "Grep", "Glob"],
|
|
73
|
-
addDirs: args.addDirs,
|
|
74
|
-
jsonSchema: SPEC_REVIEW_JSON_SCHEMA,
|
|
75
|
-
session: { kind: "resume", sessionId: args.sessionId },
|
|
76
|
-
});
|
|
77
|
-
if (retry.exitCode !== 0) {
|
|
78
|
-
throw new Error(`Spec reviewer retry failed (exit ${retry.exitCode}): ${retry.stderr || retry.stdout}`);
|
|
79
|
-
}
|
|
80
|
-
return parseSpecReview(retry.stdout);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
export async function runEditLoop(options) {
|
|
84
|
-
const { composedSpecPath, specVersionFor, fullPackPath, addDirs, maxTurns = DEFAULT_EDIT_LOOP_MAX_TURNS, runner = runClaude, model, progress, sessionId = randomUUID(), } = options;
|
|
85
|
-
// Turn 1: copy the composed spec to spec-v1 and review it.
|
|
86
|
-
const specV1 = specVersionFor(1);
|
|
87
|
-
copyFileSync(composedSpecPath, specV1);
|
|
88
|
-
progress?.emit({
|
|
89
|
-
stage: "spec-review",
|
|
90
|
-
step: "turn-1",
|
|
91
|
-
message: `Reviewing composed spec (${specV1})`,
|
|
92
|
-
});
|
|
93
|
-
let review = await callReviewer({
|
|
94
|
-
runner,
|
|
95
|
-
sessionId,
|
|
96
|
-
isFirstTurn: true,
|
|
97
|
-
userMessage: reviewerUserMessageInitial(specV1, fullPackPath),
|
|
98
|
-
addDirs,
|
|
99
|
-
model,
|
|
100
|
-
});
|
|
101
|
-
const specPathsByTurn = [specV1];
|
|
102
|
-
const reviewsByTurn = [review];
|
|
103
|
-
let currentSpecPath = specV1;
|
|
104
|
-
progress?.emit({
|
|
105
|
-
stage: "spec-review",
|
|
106
|
-
step: "turn-1",
|
|
107
|
-
message: `Verdict: ${review.verdict}`,
|
|
108
|
-
data: { verdict: review.verdict },
|
|
109
|
-
});
|
|
110
|
-
let turn = 1;
|
|
111
|
-
while (review.verdict === "requires-another-review" && turn < maxTurns) {
|
|
112
|
-
turn++;
|
|
113
|
-
const nextSpec = specVersionFor(turn);
|
|
114
|
-
progress?.emit({
|
|
115
|
-
stage: "spec-review",
|
|
116
|
-
step: `edit-turn-${turn}`,
|
|
117
|
-
message: `Editor revising spec (turn ${turn}/${maxTurns})`,
|
|
118
|
-
});
|
|
119
|
-
const editResult = await runEditor({
|
|
120
|
-
inputSpecPath: currentSpecPath,
|
|
121
|
-
outputSpecPath: nextSpec,
|
|
122
|
-
fullPackPath,
|
|
123
|
-
addDirs,
|
|
124
|
-
critique: review,
|
|
125
|
-
mode: "revise",
|
|
126
|
-
runner,
|
|
127
|
-
model,
|
|
128
|
-
});
|
|
129
|
-
if (!editResult.wroteSpec) {
|
|
130
|
-
throw new Error(`Editor produced no output spec at ${nextSpec} (exit ${editResult.exitCode}): ${editResult.stderr}`);
|
|
131
|
-
}
|
|
132
|
-
currentSpecPath = nextSpec;
|
|
133
|
-
specPathsByTurn.push(currentSpecPath);
|
|
134
|
-
const nudge = turn >= maxTurns - 1 && turn !== maxTurns
|
|
135
|
-
? convergenceNudge(turn, maxTurns)
|
|
136
|
-
: undefined;
|
|
137
|
-
progress?.emit({
|
|
138
|
-
stage: "spec-review",
|
|
139
|
-
step: `turn-${turn}`,
|
|
140
|
-
message: `Reviewing revised spec (turn ${turn}/${maxTurns})`,
|
|
141
|
-
data: { turn, maxTurns, nudge: !!nudge },
|
|
142
|
-
});
|
|
143
|
-
review = await callReviewer({
|
|
144
|
-
runner,
|
|
145
|
-
sessionId,
|
|
146
|
-
isFirstTurn: false,
|
|
147
|
-
userMessage: reviewerUserMessageRevised(turn, currentSpecPath, fullPackPath, nudge),
|
|
148
|
-
addDirs,
|
|
149
|
-
model,
|
|
150
|
-
});
|
|
151
|
-
reviewsByTurn.push(review);
|
|
152
|
-
progress?.emit({
|
|
153
|
-
stage: "spec-review",
|
|
154
|
-
step: `turn-${turn}`,
|
|
155
|
-
message: `Verdict: ${review.verdict}`,
|
|
156
|
-
data: { verdict: review.verdict },
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
const hitMaxTurns = review.verdict === "requires-another-review" && turn >= maxTurns;
|
|
160
|
-
// approved-with-revisions → apply mechanical revisions to a final version.
|
|
161
|
-
if (review.verdict === "approved-with-revisions" &&
|
|
162
|
-
review.revisions.length > 0) {
|
|
163
|
-
const finalTurn = turn + 1;
|
|
164
|
-
const finalPath = specVersionFor(finalTurn);
|
|
165
|
-
progress?.emit({
|
|
166
|
-
stage: "spec-review",
|
|
167
|
-
step: "apply-revisions",
|
|
168
|
-
message: `Applying ${review.revisions.length} mechanical revision(s)`,
|
|
169
|
-
});
|
|
170
|
-
const applyResult = await runEditor({
|
|
171
|
-
inputSpecPath: currentSpecPath,
|
|
172
|
-
outputSpecPath: finalPath,
|
|
173
|
-
fullPackPath,
|
|
174
|
-
addDirs,
|
|
175
|
-
critique: review,
|
|
176
|
-
mode: "apply",
|
|
177
|
-
runner,
|
|
178
|
-
model,
|
|
179
|
-
});
|
|
180
|
-
if (!applyResult.wroteSpec) {
|
|
181
|
-
throw new Error(`Apply-mode editor produced no output spec at ${finalPath} (exit ${applyResult.exitCode}): ${applyResult.stderr}`);
|
|
182
|
-
}
|
|
183
|
-
currentSpecPath = finalPath;
|
|
184
|
-
specPathsByTurn.push(currentSpecPath);
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
finalSpecPath: currentSpecPath,
|
|
188
|
-
specPathsByTurn,
|
|
189
|
-
reviewsByTurn,
|
|
190
|
-
finalVerdict: review.verdict,
|
|
191
|
-
turnsUsed: turn,
|
|
192
|
-
hitMaxTurns,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
//# sourceMappingURL=edit-loop.js.map
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Editor worker: revise the composed spec in place based on a reviewer's
|
|
3
|
-
* critique.
|
|
4
|
-
*
|
|
5
|
-
* Two modes:
|
|
6
|
-
* - apply: apply mechanical revisions verbatim (when verdict is `approved-with-revisions`)
|
|
7
|
-
* - revise: address the critique using the editor's own judgment (when verdict is `requires-another-review`)
|
|
8
|
-
*
|
|
9
|
-
* Requirements covered:
|
|
10
|
-
* - CTS-EDIT-3: approved-with-revisions triggers apply mode
|
|
11
|
-
* - CTS-EDIT-4: requires-another-review triggers revise mode
|
|
12
|
-
* - CTS-EDIT-5: editor operates on the cohesive document, reads codebase only on demand
|
|
13
|
-
*/
|
|
14
|
-
import { type ClaudeRunner } from "./claude.js";
|
|
15
|
-
import type { SpecReview } from "./schemas.js";
|
|
16
|
-
export type EditorMode = "apply" | "revise";
|
|
17
|
-
export interface EditorContext {
|
|
18
|
-
/**
|
|
19
|
-
* Input spec path. The editor reads from here.
|
|
20
|
-
* If `outputSpecPath` differs, the input is copied to the output path first
|
|
21
|
-
* (so the editor's in-place edits land on the output).
|
|
22
|
-
*/
|
|
23
|
-
inputSpecPath: string;
|
|
24
|
-
/** Output spec path (may equal inputSpecPath for true in-place editing). */
|
|
25
|
-
outputSpecPath: string;
|
|
26
|
-
/** Path to the codebase pack the editor may consult on demand. */
|
|
27
|
-
fullPackPath: string;
|
|
28
|
-
/** Directories to grant filesystem access to. */
|
|
29
|
-
addDirs: string[];
|
|
30
|
-
/** Reviewer's critique. */
|
|
31
|
-
critique: SpecReview;
|
|
32
|
-
/** Apply or revise. */
|
|
33
|
-
mode: EditorMode;
|
|
34
|
-
runner?: ClaudeRunner;
|
|
35
|
-
model?: string;
|
|
36
|
-
}
|
|
37
|
-
export interface EditorResult {
|
|
38
|
-
/** True if the output file exists and is non-empty after the editor ran. */
|
|
39
|
-
wroteSpec: boolean;
|
|
40
|
-
/** Size of the output in bytes (0 if missing). */
|
|
41
|
-
outputBytes: number;
|
|
42
|
-
/** Process exit code. */
|
|
43
|
-
exitCode: number;
|
|
44
|
-
/** Captured stdout (one-line confirmation). */
|
|
45
|
-
stdout: string;
|
|
46
|
-
/** Captured stderr. */
|
|
47
|
-
stderr: string;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Run the editor. If outputSpecPath differs from inputSpecPath, copy first
|
|
51
|
-
* so the in-place edits land on the output.
|
|
52
|
-
*/
|
|
53
|
-
export declare function runEditor(ctx: EditorContext): Promise<EditorResult>;
|
|
54
|
-
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Editor worker: revise the composed spec in place based on a reviewer's
|
|
3
|
-
* critique.
|
|
4
|
-
*
|
|
5
|
-
* Two modes:
|
|
6
|
-
* - apply: apply mechanical revisions verbatim (when verdict is `approved-with-revisions`)
|
|
7
|
-
* - revise: address the critique using the editor's own judgment (when verdict is `requires-another-review`)
|
|
8
|
-
*
|
|
9
|
-
* Requirements covered:
|
|
10
|
-
* - CTS-EDIT-3: approved-with-revisions triggers apply mode
|
|
11
|
-
* - CTS-EDIT-4: requires-another-review triggers revise mode
|
|
12
|
-
* - CTS-EDIT-5: editor operates on the cohesive document, reads codebase only on demand
|
|
13
|
-
*/
|
|
14
|
-
import { copyFileSync, existsSync, statSync } from "node:fs";
|
|
15
|
-
import { runClaude } from "./claude.js";
|
|
16
|
-
import { EDITOR_PROMPT } from "./prompts/editor.js";
|
|
17
|
-
function userMessage(ctx) {
|
|
18
|
-
const mode = ctx.mode === "apply" ? "APPLY" : "REVISE";
|
|
19
|
-
const lines = [
|
|
20
|
-
`Mode: ${mode}`,
|
|
21
|
-
``,
|
|
22
|
-
`Spec to edit (in place via Edit tool): ${ctx.outputSpecPath}`,
|
|
23
|
-
`Codebase pack (consult only on demand): ${ctx.fullPackPath}`,
|
|
24
|
-
``,
|
|
25
|
-
`## Reviewer critique`,
|
|
26
|
-
`\`\`\`json`,
|
|
27
|
-
JSON.stringify(ctx.critique, null, 2),
|
|
28
|
-
`\`\`\``,
|
|
29
|
-
``,
|
|
30
|
-
];
|
|
31
|
-
if (ctx.mode === "apply") {
|
|
32
|
-
lines.push(`You are in APPLY mode. The reviewer's verdict is \`approved-with-revisions\`. Apply each revision in the \`revisions\` array verbatim. Do not restructure. When done, output a one-line confirmation.`);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
lines.push(`You are in REVISE mode. The reviewer's verdict is \`requires-another-review\`. Address each finding using your judgment. Use the Edit tool for targeted changes. Consult the codebase only to verify specific findings before adding requirements.`);
|
|
36
|
-
}
|
|
37
|
-
return lines.join("\n");
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Run the editor. If outputSpecPath differs from inputSpecPath, copy first
|
|
41
|
-
* so the in-place edits land on the output.
|
|
42
|
-
*/
|
|
43
|
-
export async function runEditor(ctx) {
|
|
44
|
-
if (ctx.inputSpecPath !== ctx.outputSpecPath) {
|
|
45
|
-
copyFileSync(ctx.inputSpecPath, ctx.outputSpecPath);
|
|
46
|
-
}
|
|
47
|
-
const runner = ctx.runner ?? runClaude;
|
|
48
|
-
const result = await runner({
|
|
49
|
-
systemPrompt: EDITOR_PROMPT,
|
|
50
|
-
userMessage: userMessage(ctx),
|
|
51
|
-
model: ctx.model,
|
|
52
|
-
tools: ["Read", "Edit", "Grep", "Glob"],
|
|
53
|
-
addDirs: ctx.addDirs,
|
|
54
|
-
});
|
|
55
|
-
let wroteSpec = false;
|
|
56
|
-
let outputBytes = 0;
|
|
57
|
-
if (existsSync(ctx.outputSpecPath)) {
|
|
58
|
-
try {
|
|
59
|
-
outputBytes = statSync(ctx.outputSpecPath).size;
|
|
60
|
-
wroteSpec = outputBytes > 0;
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
// Treat as not written.
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return {
|
|
67
|
-
wroteSpec,
|
|
68
|
-
outputBytes,
|
|
69
|
-
exitCode: result.exitCode,
|
|
70
|
-
stdout: result.stdout,
|
|
71
|
-
stderr: result.stderr,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=editor.js.map
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Specifier fan-out orchestrator.
|
|
3
|
-
*
|
|
4
|
-
* For each area in the outline, extract a slice, spawn a specifier worker,
|
|
5
|
-
* and write the resulting partial to the cache. Workers run in parallel up
|
|
6
|
-
* to a bounded concurrency limit. On per-area failure (no partial written,
|
|
7
|
-
* empty partial), the worker is retried once; on second failure, the area
|
|
8
|
-
* is recorded as failed for surfacing to the user.
|
|
9
|
-
*
|
|
10
|
-
* Requirements covered:
|
|
11
|
-
* - CTS-SPEC-1.2: bounded concurrent execution
|
|
12
|
-
* - CTS-SPEC-5: failed/empty specifier output is detected and retried
|
|
13
|
-
* - CTS-OBSERVE-2.0: failure details are logged with area name + cause
|
|
14
|
-
* - CTS-RESUME-1.2: existing non-empty partial means the specifier is skipped
|
|
15
|
-
*/
|
|
16
|
-
import type { ClaudeRunner } from "./claude.js";
|
|
17
|
-
import type { ProgressEmitter } from "./progress.js";
|
|
18
|
-
import type { Area, Outline } from "./schemas.js";
|
|
19
|
-
export declare const DEFAULT_FAN_OUT_CONCURRENCY = 8;
|
|
20
|
-
export interface FanOutOptions {
|
|
21
|
-
outline: Outline;
|
|
22
|
-
/** Path to the uncompressed pack (slices come from here). */
|
|
23
|
-
fullPackPath: string;
|
|
24
|
-
/** Path resolver: given a sanitized area name, return the partial path. */
|
|
25
|
-
partialPathFor: (sanitizedAreaName: string) => string;
|
|
26
|
-
/** Path resolver: given a sanitized area name, return the slice path. */
|
|
27
|
-
slicePathFor: (sanitizedAreaName: string) => string;
|
|
28
|
-
/** Command (path + args) the specifier should run to invoke schema validation. Run before style-check. */
|
|
29
|
-
validateCommand: string;
|
|
30
|
-
/** Command (path + args) the specifier should run to invoke style-check. */
|
|
31
|
-
styleCheckCommand: string;
|
|
32
|
-
/** Directories the specifier needs filesystem access to. */
|
|
33
|
-
addDirs: string[];
|
|
34
|
-
concurrency?: number;
|
|
35
|
-
runner?: ClaudeRunner;
|
|
36
|
-
model?: string;
|
|
37
|
-
progress?: ProgressEmitter;
|
|
38
|
-
}
|
|
39
|
-
export interface AreaOutcome {
|
|
40
|
-
area: Area;
|
|
41
|
-
status: "completed" | "skipped-resume" | "failed";
|
|
42
|
-
/** Number of attempts made (1 = first attempt succeeded; 2 = retry succeeded; 2 with failed = retried and still failed). */
|
|
43
|
-
attempts: number;
|
|
44
|
-
/** Reason the area failed, if applicable. */
|
|
45
|
-
failureCause?: string;
|
|
46
|
-
/** Path to the partial (whether or not it was written successfully). */
|
|
47
|
-
partialPath: string;
|
|
48
|
-
}
|
|
49
|
-
export interface FanOutResult {
|
|
50
|
-
outcomes: AreaOutcome[];
|
|
51
|
-
/** True if every area produced a non-empty partial (either now or from cache). */
|
|
52
|
-
allSucceeded: boolean;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Convert an area name to a stable filesystem-safe identifier.
|
|
56
|
-
* E.g., "Reading & Editing Files" → "reading-editing-files"
|
|
57
|
-
*/
|
|
58
|
-
export declare function sanitizeAreaName(name: string): string;
|
|
59
|
-
/**
|
|
60
|
-
* Run the fan-out: extract slices, invoke specifiers, retry on failure.
|
|
61
|
-
*/
|
|
62
|
-
export declare function runFanOut(options: FanOutOptions): Promise<FanOutResult>;
|
|
63
|
-
//# sourceMappingURL=fan-out.d.ts.map
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Specifier fan-out orchestrator.
|
|
3
|
-
*
|
|
4
|
-
* For each area in the outline, extract a slice, spawn a specifier worker,
|
|
5
|
-
* and write the resulting partial to the cache. Workers run in parallel up
|
|
6
|
-
* to a bounded concurrency limit. On per-area failure (no partial written,
|
|
7
|
-
* empty partial), the worker is retried once; on second failure, the area
|
|
8
|
-
* is recorded as failed for surfacing to the user.
|
|
9
|
-
*
|
|
10
|
-
* Requirements covered:
|
|
11
|
-
* - CTS-SPEC-1.2: bounded concurrent execution
|
|
12
|
-
* - CTS-SPEC-5: failed/empty specifier output is detected and retried
|
|
13
|
-
* - CTS-OBSERVE-2.0: failure details are logged with area name + cause
|
|
14
|
-
* - CTS-RESUME-1.2: existing non-empty partial means the specifier is skipped
|
|
15
|
-
*/
|
|
16
|
-
import { existsSync, mkdirSync, statSync, writeFileSync } from "node:fs";
|
|
17
|
-
import { dirname } from "node:path";
|
|
18
|
-
import { extractSlice } from "./slice.js";
|
|
19
|
-
import { runSpecifier } from "./specifier.js";
|
|
20
|
-
export const DEFAULT_FAN_OUT_CONCURRENCY = 8;
|
|
21
|
-
/**
|
|
22
|
-
* Convert an area name to a stable filesystem-safe identifier.
|
|
23
|
-
* E.g., "Reading & Editing Files" → "reading-editing-files"
|
|
24
|
-
*/
|
|
25
|
-
export function sanitizeAreaName(name) {
|
|
26
|
-
return (name
|
|
27
|
-
.replace(/[^A-Za-z0-9]+/g, "-")
|
|
28
|
-
.replace(/^-+|-+$/g, "")
|
|
29
|
-
.toLowerCase() || "area");
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Run a bounded-concurrency loop over items. Workers pull items off a shared
|
|
33
|
-
* counter; at most `limit` workers run at a time.
|
|
34
|
-
*/
|
|
35
|
-
async function withLimit(items, limit, fn) {
|
|
36
|
-
let next = 0;
|
|
37
|
-
async function worker() {
|
|
38
|
-
while (true) {
|
|
39
|
-
const i = next++;
|
|
40
|
-
if (i >= items.length)
|
|
41
|
-
return;
|
|
42
|
-
await fn(items[i], i);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const workerCount = Math.min(Math.max(1, limit), items.length);
|
|
46
|
-
const workers = Array.from({ length: workerCount }, () => worker());
|
|
47
|
-
await Promise.all(workers);
|
|
48
|
-
}
|
|
49
|
-
function partialIsUsable(path) {
|
|
50
|
-
if (!existsSync(path))
|
|
51
|
-
return false;
|
|
52
|
-
try {
|
|
53
|
-
return statSync(path).size > 0;
|
|
54
|
-
}
|
|
55
|
-
catch {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Run the fan-out: extract slices, invoke specifiers, retry on failure.
|
|
61
|
-
*/
|
|
62
|
-
export async function runFanOut(options) {
|
|
63
|
-
const { outline, fullPackPath, partialPathFor, slicePathFor, validateCommand, styleCheckCommand, addDirs, concurrency = DEFAULT_FAN_OUT_CONCURRENCY, runner, model, progress, } = options;
|
|
64
|
-
if (!existsSync(fullPackPath)) {
|
|
65
|
-
throw new Error(`Missing full pack at ${fullPackPath}`);
|
|
66
|
-
}
|
|
67
|
-
// Sanitization is lossy ("Read & Write" and "read/write" both become
|
|
68
|
-
// "read-write"). If two areas collide, they'd share a partial file path and
|
|
69
|
-
// silently overwrite each other downstream. Catch this up front.
|
|
70
|
-
const sanitizedNames = new Map();
|
|
71
|
-
for (const area of outline.areas) {
|
|
72
|
-
const key = sanitizeAreaName(area.name);
|
|
73
|
-
const bucket = sanitizedNames.get(key) ?? [];
|
|
74
|
-
bucket.push(area.name);
|
|
75
|
-
sanitizedNames.set(key, bucket);
|
|
76
|
-
}
|
|
77
|
-
const collisions = [...sanitizedNames.entries()].filter(([, names]) => names.length > 1);
|
|
78
|
-
if (collisions.length > 0) {
|
|
79
|
-
const detail = collisions
|
|
80
|
-
.map(([key, names]) => ` "${key}" ← ${names.map((n) => `"${n}"`).join(", ")}`)
|
|
81
|
-
.join("\n");
|
|
82
|
-
throw new Error(`Outline contains area names that collide after sanitization. Rename them so each produces a unique partial file path:\n${detail}`);
|
|
83
|
-
}
|
|
84
|
-
const outcomes = outline.areas.map((area) => ({
|
|
85
|
-
area,
|
|
86
|
-
status: "failed",
|
|
87
|
-
attempts: 0,
|
|
88
|
-
partialPath: partialPathFor(sanitizeAreaName(area.name)),
|
|
89
|
-
}));
|
|
90
|
-
// Ensure partials directory exists for each area.
|
|
91
|
-
for (const outcome of outcomes) {
|
|
92
|
-
mkdirSync(dirname(outcome.partialPath), { recursive: true });
|
|
93
|
-
}
|
|
94
|
-
await withLimit(outcomes, concurrency, async (outcome) => {
|
|
95
|
-
const sanitized = sanitizeAreaName(outcome.area.name);
|
|
96
|
-
const slicePath = slicePathFor(sanitized);
|
|
97
|
-
// CTS-RESUME-1.2: skip if a non-empty partial exists from a prior run.
|
|
98
|
-
if (partialIsUsable(outcome.partialPath)) {
|
|
99
|
-
outcome.status = "skipped-resume";
|
|
100
|
-
outcome.attempts = 0;
|
|
101
|
-
progress?.emit({
|
|
102
|
-
stage: "specify",
|
|
103
|
-
step: outcome.area.prefix,
|
|
104
|
-
message: `(resume) skipping ${outcome.area.name} — partial exists`,
|
|
105
|
-
});
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
// Extract this area's slice from the full pack.
|
|
109
|
-
if (outcome.area.files.length === 0) {
|
|
110
|
-
// No files assigned — write a stub partial so compose has something.
|
|
111
|
-
writeFileSync(outcome.partialPath, "_(no files assigned to this area)_\n", "utf-8");
|
|
112
|
-
outcome.status = "failed";
|
|
113
|
-
outcome.attempts = 0;
|
|
114
|
-
outcome.failureCause = "no files assigned in outline";
|
|
115
|
-
progress?.emit({
|
|
116
|
-
stage: "specify",
|
|
117
|
-
step: outcome.area.prefix,
|
|
118
|
-
message: `!! ${outcome.area.name} has no files; marking as failed`,
|
|
119
|
-
});
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
let sliceMatched = 0;
|
|
123
|
-
try {
|
|
124
|
-
const sliceResult = extractSlice(fullPackPath, slicePath, outcome.area.files);
|
|
125
|
-
sliceMatched = sliceResult.matched;
|
|
126
|
-
}
|
|
127
|
-
catch (err) {
|
|
128
|
-
outcome.failureCause = `slice extraction failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
129
|
-
progress?.emit({
|
|
130
|
-
stage: "specify",
|
|
131
|
-
step: outcome.area.prefix,
|
|
132
|
-
message: `!! ${outcome.failureCause}`,
|
|
133
|
-
});
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
if (sliceMatched === 0) {
|
|
137
|
-
progress?.emit({
|
|
138
|
-
stage: "specify",
|
|
139
|
-
step: outcome.area.prefix,
|
|
140
|
-
message: `(warning) slice for ${outcome.area.name} matched 0 files; specifier will need to fall back to full-pack reads`,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
// Attempt 1
|
|
144
|
-
progress?.emit({
|
|
145
|
-
stage: "specify",
|
|
146
|
-
step: outcome.area.prefix,
|
|
147
|
-
message: `Running specifier for ${outcome.area.name} (attempt 1/2)`,
|
|
148
|
-
});
|
|
149
|
-
outcome.attempts = 1;
|
|
150
|
-
const r1 = await runSpecifier({
|
|
151
|
-
outline,
|
|
152
|
-
area: outcome.area,
|
|
153
|
-
slicePath,
|
|
154
|
-
fullPackPath,
|
|
155
|
-
partialPath: outcome.partialPath,
|
|
156
|
-
validateCommand,
|
|
157
|
-
styleCheckCommand,
|
|
158
|
-
addDirs,
|
|
159
|
-
runner,
|
|
160
|
-
model,
|
|
161
|
-
});
|
|
162
|
-
if (r1.wrotePartial) {
|
|
163
|
-
outcome.status = "completed";
|
|
164
|
-
progress?.emit({
|
|
165
|
-
stage: "specify",
|
|
166
|
-
step: outcome.area.prefix,
|
|
167
|
-
message: `${outcome.area.name} done (${r1.partialBytes} bytes)`,
|
|
168
|
-
});
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
// Attempt 2 (retry once on no/empty partial)
|
|
172
|
-
progress?.emit({
|
|
173
|
-
stage: "specify",
|
|
174
|
-
step: outcome.area.prefix,
|
|
175
|
-
message: `!! ${outcome.area.name} produced no partial; retrying (attempt 2/2)`,
|
|
176
|
-
});
|
|
177
|
-
outcome.attempts = 2;
|
|
178
|
-
const r2 = await runSpecifier({
|
|
179
|
-
outline,
|
|
180
|
-
area: outcome.area,
|
|
181
|
-
slicePath,
|
|
182
|
-
fullPackPath,
|
|
183
|
-
partialPath: outcome.partialPath,
|
|
184
|
-
validateCommand,
|
|
185
|
-
styleCheckCommand,
|
|
186
|
-
addDirs,
|
|
187
|
-
runner,
|
|
188
|
-
model,
|
|
189
|
-
});
|
|
190
|
-
if (r2.wrotePartial) {
|
|
191
|
-
outcome.status = "completed";
|
|
192
|
-
progress?.emit({
|
|
193
|
-
stage: "specify",
|
|
194
|
-
step: outcome.area.prefix,
|
|
195
|
-
message: `${outcome.area.name} done on retry (${r2.partialBytes} bytes)`,
|
|
196
|
-
});
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
// Two failures — record and continue. CTS-SPEC-5 says other areas still proceed.
|
|
200
|
-
outcome.status = "failed";
|
|
201
|
-
outcome.failureCause =
|
|
202
|
-
r2.exitCode !== 0
|
|
203
|
-
? `specifier exited with code ${r2.exitCode}: ${r2.stderr.slice(0, 200)}`
|
|
204
|
-
: "specifier wrote no partial (or empty partial) on both attempts";
|
|
205
|
-
writeFileSync(outcome.partialPath, `_(missing partial — specifier failed after retry: ${outcome.failureCause})_\n`, "utf-8");
|
|
206
|
-
progress?.emit({
|
|
207
|
-
stage: "specify",
|
|
208
|
-
step: outcome.area.prefix,
|
|
209
|
-
message: `!! ${outcome.area.name} failed: ${outcome.failureCause}`,
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
const allSucceeded = outcomes.every((o) => o.status === "completed" || o.status === "skipped-resume");
|
|
213
|
-
return { outcomes, allSucceeded };
|
|
214
|
-
}
|
|
215
|
-
//# sourceMappingURL=fan-out.js.map
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Outline review loop: planner → reviewer → revise → reviewer → ... → approved.
|
|
3
|
-
*
|
|
4
|
-
* The reviewer runs in a SINGLE stateful claude session across turns (so it
|
|
5
|
-
* can compare prior outlines to the latest one). The planner is stateless —
|
|
6
|
-
* each invocation is fresh.
|
|
7
|
-
*
|
|
8
|
-
* Requirements covered:
|
|
9
|
-
* - CTS-PLAN-2: stateful reviewer session
|
|
10
|
-
* - CTS-PLAN-3: approved → proceed
|
|
11
|
-
* - CTS-PLAN-4: approved-with-revisions → one revision pass, then proceed
|
|
12
|
-
* - CTS-PLAN-5: requires-another-review → revision loop
|
|
13
|
-
* - CTS-PLAN-6: max-turns + convergence nudge
|
|
14
|
-
*/
|
|
15
|
-
import { type ClaudeRunner } from "./claude.js";
|
|
16
|
-
import type { ProgressEmitter } from "./progress.js";
|
|
17
|
-
import { type Outline, type OutlineReview } from "./schemas.js";
|
|
18
|
-
export declare const DEFAULT_OUTLINE_LOOP_MAX_TURNS = 3;
|
|
19
|
-
export interface OutlineReviewLoopOptions {
|
|
20
|
-
overviewPath: string;
|
|
21
|
-
addDirs: string[];
|
|
22
|
-
maxTurns?: number;
|
|
23
|
-
runner?: ClaudeRunner;
|
|
24
|
-
model?: string;
|
|
25
|
-
progress?: ProgressEmitter;
|
|
26
|
-
/** Override session id (for tests and reproducibility). Otherwise random. */
|
|
27
|
-
sessionId?: string;
|
|
28
|
-
}
|
|
29
|
-
export interface OutlineReviewLoopResult {
|
|
30
|
-
/** The final outline after the loop converges (or hits max-turns). */
|
|
31
|
-
outline: Outline;
|
|
32
|
-
/** Per-turn outline snapshots (turn 1 is the initial, then each revision). */
|
|
33
|
-
outlinesByTurn: Outline[];
|
|
34
|
-
/** Per-turn reviewer results. */
|
|
35
|
-
reviewsByTurn: OutlineReview[];
|
|
36
|
-
/** The final reviewer verdict. */
|
|
37
|
-
finalVerdict: OutlineReview["verdict"];
|
|
38
|
-
/** Number of review turns used (= length of reviewsByTurn). */
|
|
39
|
-
turnsUsed: number;
|
|
40
|
-
/** True if the loop hit max-turns without converging. */
|
|
41
|
-
hitMaxTurns: boolean;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Run the outline review loop end-to-end.
|
|
45
|
-
*
|
|
46
|
-
* Returns the final outline (after applying mechanical revisions if the
|
|
47
|
-
* verdict was `approved-with-revisions`), the per-turn trace, and the final
|
|
48
|
-
* verdict.
|
|
49
|
-
*/
|
|
50
|
-
export declare function runOutlineReviewLoop(options: OutlineReviewLoopOptions): Promise<OutlineReviewLoopResult>;
|
|
51
|
-
//# sourceMappingURL=outline-review-loop.d.ts.map
|