@oscaner-skills/cdd-engine 1.0.0 → 3.0.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.
- package/README.md +11 -10
- package/README.zh-CN.md +11 -10
- package/package.json +16 -22
- package/src-next/__tests__/bin.test.ts +128 -0
- package/src-next/__tests__/dead-decl.guard.test.ts +39 -0
- package/src-next/__tests__/floor.guard.test.ts +69 -0
- package/src-next/__tests__/issue-body.guard.test.ts +66 -0
- package/src-next/__tests__/phase-suffix.guard.test.ts +72 -0
- package/src-next/__tests__/smoke.integration.test.ts +185 -0
- package/src-next/__tests__/support/strip-comments.ts +99 -0
- package/src-next/__tests__/zero-dep.test.ts +94 -0
- package/src-next/bin.ts +61 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.overall-spec.snap +256 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.phase-spec.snap +165 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.plan.snap +190 -0
- package/src-next/contract/__tests__/__snapshots__/project.schema.single-spec.snap +106 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.overall-spec.snap +240 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.phase-spec.snap +165 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.plan.snap +190 -0
- package/src-next/contract/__tests__/__snapshots__/project.shape.single-spec.snap +100 -0
- package/src-next/contract/__tests__/declare.test.ts +481 -0
- package/src-next/contract/__tests__/doc.test.ts +527 -0
- package/src-next/contract/__tests__/dockey.guard.test.ts +58 -0
- package/src-next/contract/__tests__/edge-conditions.guard.test.ts +81 -0
- package/src-next/contract/__tests__/frontmatter.test.ts +164 -0
- package/src-next/contract/__tests__/judge.test.ts +1111 -0
- package/src-next/contract/__tests__/lint.test.ts +324 -0
- package/src-next/contract/__tests__/project.test.ts +460 -0
- package/src-next/contract/__tests__/structure-pin.test.ts +186 -0
- package/src-next/contract/__tests__/translate.test.ts +96 -0
- package/src-next/contract/declare.ts +1071 -0
- package/src-next/contract/doc.ts +816 -0
- package/src-next/contract/frontmatter.ts +233 -0
- package/src-next/contract/home-extractors.ts +397 -0
- package/src-next/contract/invariants.ts +1413 -0
- package/src-next/contract/judge.ts +151 -0
- package/src-next/contract/lint.ts +239 -0
- package/src-next/contract/project.ts +656 -0
- package/src-next/contract/skill-anatomy.ts +301 -0
- package/src-next/contract/translate.ts +113 -0
- package/src-next/face/__tests__/board-view.test.ts +1151 -0
- package/src-next/face/__tests__/capsule.test.ts +300 -0
- package/src-next/face/__tests__/channel-closure.guard.test.ts +129 -0
- package/src-next/face/__tests__/cli.test.ts +4897 -0
- package/src-next/face/__tests__/face.test.ts +289 -0
- package/src-next/face/__tests__/graph-view.test.ts +61 -0
- package/src-next/face/__tests__/host.test.ts +24 -0
- package/src-next/face/__tests__/install-rows.guard.test.ts +58 -0
- package/src-next/face/__tests__/negation.ts +6 -0
- package/src-next/face/__tests__/preview.test.ts +374 -0
- package/src-next/face/__tests__/projection.test.ts +303 -0
- package/src-next/face/__tests__/repo-root.guard.test.ts +120 -0
- package/src-next/face/__tests__/termination.test.ts +650 -0
- package/src-next/face/__tests__/words.guard.test.ts +93 -0
- package/src-next/face/artifacts.ts +248 -0
- package/src-next/face/board-view.ts +652 -0
- package/src-next/face/capsule.ts +163 -0
- package/src-next/face/cli.ts +1028 -0
- package/src-next/face/declare.ts +323 -0
- package/src-next/face/gate.ts +171 -0
- package/src-next/face/graph-view.ts +74 -0
- package/src-next/face/host.ts +302 -0
- package/src-next/face/lifecycle.ts +725 -0
- package/src-next/face/preview.ts +151 -0
- package/src-next/face/projection.ts +285 -0
- package/src-next/face/route-render.ts +185 -0
- package/src-next/face/termination.ts +573 -0
- package/src-next/face/words.ts +314 -0
- package/src-next/infra/__tests__/infra.test.ts +333 -0
- package/src-next/infra/__tests__/root.test.ts +56 -0
- package/src-next/infra/config.ts +42 -0
- package/src-next/infra/doc-roots.ts +29 -0
- package/src-next/infra/git.ts +39 -0
- package/src-next/infra/process.ts +34 -0
- package/src-next/infra/root.ts +73 -0
- package/src-next/infra/runtime.ts +132 -0
- package/src-next/infra/workspace.ts +322 -0
- package/src-next/render/__tests__/render.test.ts +550 -0
- package/src-next/render/__tests__/skeleton.test.ts +684 -0
- package/src-next/render/brief.ts +121 -0
- package/src-next/render/issue-body.ts +162 -0
- package/src-next/render/skeleton.ts +502 -0
- package/src-next/render/templates.ts +645 -0
- package/src-next/session/__tests__/graph.test.ts +277 -0
- package/src-next/session/__tests__/handoff-plane.guard.test.ts +48 -0
- package/src-next/session/__tests__/handoff-schema.test.ts +310 -0
- package/src-next/session/__tests__/ledger.test.ts +745 -0
- package/src-next/session/__tests__/next.test.ts +460 -0
- package/src-next/session/__tests__/preflight.test.ts +545 -0
- package/src-next/session/__tests__/round-naming.test.ts +142 -0
- package/src-next/session/__tests__/run.test.ts +1026 -0
- package/src-next/session/__tests__/wave-line-phase.guard.test.ts +49 -0
- package/src-next/session/__tests__/wave.test.ts +476 -0
- package/src-next/session/faces.ts +110 -0
- package/src-next/session/graph.ts +411 -0
- package/src-next/session/handoff-schema.ts +373 -0
- package/src-next/session/ledger.ts +1076 -0
- package/src-next/session/next.ts +293 -0
- package/src-next/session/preflight.ts +271 -0
- package/src-next/session/round-naming.ts +84 -0
- package/src-next/session/run.ts +610 -0
- package/src-next/session/state.ts +30 -0
- package/src-next/session/wave.ts +139 -0
- package/templates/report/issue-body.json +17 -65
- package/dist/chunks/branch.mjs +0 -480
- package/dist/chunks/docs.mjs +0 -253
- package/dist/chunks/task.mjs +0 -913
- package/dist/cli.mjs +0 -5457
- package/dist/documents/schema/add-phase-protocol.json +0 -126
- package/dist/documents/schema/overall.json +0 -361
- package/dist/documents/schema/phase-spec.json +0 -145
- package/dist/documents/schema/plan.json +0 -191
- package/dist/documents/schema/skill-anatomy.json +0 -233
- package/dist/resources/harness-registry.json +0 -49
- package/dist/shared/cdd-engine.liioziig.mjs +0 -184
- package/templates/engine-config.json +0 -302
- package/templates/schema/cache-profile-schema.json +0 -23
- package/templates/schema/docs-handoff-schema.json +0 -129
- package/templates/schema/task-handoff-schema.json +0 -332
- package/templates/template-contract.json +0 -231
package/dist/chunks/docs.mjs
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { b as DispatchLifecycle, B as getRoot, i as invariant, G as GitClient, T as TemplateLoader, k as writeBlockedCarrier, l as FAILURE_CATEGORIES, H as HandoffSchemaValidator, m as recoverHandoff, a as writeOwnHandoff, f as finalizeHandoff, z as hashFile, p as persistFinalized, C as CommitChecker, U as UNCOMMITTED_RETURN_MARKER, r as readJson, N as withLifecycle, q as DispatchBlocked, s as exitWithCode } from '../cli.mjs';
|
|
4
|
-
import { R as Registry, a as REG_PATH, E as EngineInvoker } from '../shared/cdd-engine.liioziig.mjs';
|
|
5
|
-
import 'node:process';
|
|
6
|
-
import 'citty';
|
|
7
|
-
import 'node:url';
|
|
8
|
-
import 'tinyglobby';
|
|
9
|
-
import 'node:child_process';
|
|
10
|
-
import 'ajv';
|
|
11
|
-
import 'execa';
|
|
12
|
-
import 'simple-git';
|
|
13
|
-
import 'node:crypto';
|
|
14
|
-
import 'hookable';
|
|
15
|
-
import 'handlebars';
|
|
16
|
-
|
|
17
|
-
const git = new GitClient();
|
|
18
|
-
const registry = new Registry();
|
|
19
|
-
const invoker = new EngineInvoker();
|
|
20
|
-
const templates = new TemplateLoader();
|
|
21
|
-
const commit = new CommitChecker();
|
|
22
|
-
const schema = new HandoffSchemaValidator();
|
|
23
|
-
class DocsLifecycle extends DispatchLifecycle {
|
|
24
|
-
#opts;
|
|
25
|
-
#agentRc = 0;
|
|
26
|
-
#handoff = null;
|
|
27
|
-
#exitCode = 0;
|
|
28
|
-
#finished = false;
|
|
29
|
-
constructor(options) {
|
|
30
|
-
const { ctx, ...opts } = options;
|
|
31
|
-
super({ ctx });
|
|
32
|
-
this.#opts = { ...opts };
|
|
33
|
-
}
|
|
34
|
-
/** runDocsTask compat result surface — { exitCode, handoff } read after run(). */
|
|
35
|
-
get result() {
|
|
36
|
-
return { exitCode: this.#exitCode, handoff: this.#handoff };
|
|
37
|
-
}
|
|
38
|
-
#done(result) {
|
|
39
|
-
this.#exitCode = result.exitCode;
|
|
40
|
-
this.#handoff = result.handoff;
|
|
41
|
-
this.#finished = true;
|
|
42
|
-
}
|
|
43
|
-
/** Lane-declared doc-audit target (Task 3 ④「lane 声明审计对象」): the docs channel audits the
|
|
44
|
-
* reviewed doc itself — the base default docContractValidate walks the doc's chain by doc-type
|
|
45
|
-
* (plan / spec / overall), gating the review/fix on the parent-overall four tables when the
|
|
46
|
-
* lineage resolves. null (no doc) → the gate is waived. */
|
|
47
|
-
docAuditTarget() {
|
|
48
|
-
return this.#opts.doc ?? null;
|
|
49
|
-
}
|
|
50
|
-
// ---- pre-flight ----
|
|
51
|
-
/** Step 2/4 family: root (injected vs engine singleton) + canonical handoffPath guard; on the
|
|
52
|
-
* dry-run path this is the finish line — no spawn / handoff happens here, and the inherited
|
|
53
|
-
* entry gate already ran in pre-flight (E2②: dirty tree downgraded to a stderr CDD_WARN on the
|
|
54
|
-
* dry-run path; legacy: runDocsTask returned the APPROVED stub before withLifecycle). */
|
|
55
|
-
async resolveContext(_hookCtx) {
|
|
56
|
-
if (this.#opts.dryRun) {
|
|
57
|
-
this.#done({
|
|
58
|
-
exitCode: 0,
|
|
59
|
-
handoff: {
|
|
60
|
-
phase: this.#opts.mode,
|
|
61
|
-
status: "APPROVED",
|
|
62
|
-
findings: [],
|
|
63
|
-
artifacts: {},
|
|
64
|
-
doc_path: this.#opts.doc
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (!this.ctx.repoRoot) {
|
|
70
|
-
this.ctx = { ...this.ctx, repoRoot: getRoot() };
|
|
71
|
-
}
|
|
72
|
-
if (!this.#opts.handoffPath)
|
|
73
|
-
invariant(
|
|
74
|
-
false,
|
|
75
|
-
"docs-runner: handoffPath required (canonical naming; no template fallback)"
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
// ---- dispatch ----
|
|
79
|
-
/** Steps 7+8: render the prompt (single composition pass: shared shell embeds the schema block;
|
|
80
|
-
* ## Return + ## Round context render on top — the round-context slots carry the per-dispatch
|
|
81
|
-
* real values incl. the HANDOFF_WRITE_GATE), then spawn the docs agent CLI (cwd = repo root —
|
|
82
|
-
* Bug L fix; env = host env so invokeCli's cleanEnv strips credentials). */
|
|
83
|
-
async dispatch(_hookCtx) {
|
|
84
|
-
if (this.#finished) return;
|
|
85
|
-
const { mode, type, doc, template, params = {}, handoffPath, harness } = this.#opts;
|
|
86
|
-
const docFixedPoint = await git.revParseHead(this.ctx.repoRoot ?? "") ?? "";
|
|
87
|
-
const prompt = templates.renderTemplate(
|
|
88
|
-
template,
|
|
89
|
-
{
|
|
90
|
-
MODE: mode,
|
|
91
|
-
DOC: doc,
|
|
92
|
-
FINDINGS: this.#opts.findingsPath ?? "",
|
|
93
|
-
HANDOFF_TARGET: handoffPath ?? "",
|
|
94
|
-
...params,
|
|
95
|
-
// Computed dispatch facts win over caller params (last-wins) — FIXED_POINT included:
|
|
96
|
-
// the entry base is an engine fact, never a caller injectable.
|
|
97
|
-
FIXED_POINT: docFixedPoint,
|
|
98
|
-
// The was-gate prose is byte constant; the gate VALUE (real handoff path) rides the
|
|
99
|
-
// `### HANDOFF_WRITE_GATE` round-context slot (Task 20 ⑥ facade de-pathing). The review family
|
|
100
|
-
// gate dispatches by return semantics (retrieve a fixed 'json-return' write gate — the
|
|
101
|
-
// return is a JSON object on stdout); the fix family = the docs write gate (fix's return is
|
|
102
|
-
// the file itself; stdout has no JSON return — reviewHardGate's "before outputting the
|
|
103
|
-
// JSON return" self-contradicts for a fix agent — reviewHardGate must not be reused).
|
|
104
|
-
RETURN_FORMAT: mode === "fix" ? "DOCS_FIX" : "RETURN_JSON",
|
|
105
|
-
HANDOFF_WRITE_GATE: mode === "fix" ? templates.docsFixHardGate(handoffPath ?? "") : templates.reviewHardGate("RETURN_JSON", handoffPath ?? "")
|
|
106
|
-
},
|
|
107
|
-
"docs-runner"
|
|
108
|
-
);
|
|
109
|
-
const reg = registry.load(REG_PATH);
|
|
110
|
-
const entry = registry.checkHarness(reg, harness);
|
|
111
|
-
const res = await invoker.invokeCli(
|
|
112
|
-
entry,
|
|
113
|
-
prompt,
|
|
114
|
-
{ op: mode, type },
|
|
115
|
-
process.env,
|
|
116
|
-
this.ctx.repoRoot,
|
|
117
|
-
invoker.resolveTerminationConfig("review")
|
|
118
|
-
);
|
|
119
|
-
this.#agentRc = res.code;
|
|
120
|
-
}
|
|
121
|
-
// ---- post-flight ----
|
|
122
|
-
/** Step 8.8: read the agent-written handoff from disk; unparseable / schema-invalid →
|
|
123
|
-
* writeBlockedCarrier (the unified BLOCKED terminal incl. the doc_hash content token). */
|
|
124
|
-
async schemaValidate(_hookCtx) {
|
|
125
|
-
if (this.#finished) return;
|
|
126
|
-
const handoffPath = this.#opts.handoffPath;
|
|
127
|
-
if (!existsSync(handoffPath)) {
|
|
128
|
-
this.#done(
|
|
129
|
-
writeBlockedCarrier(handoffPath, {
|
|
130
|
-
phase: this.#opts.mode,
|
|
131
|
-
doc: this.#opts.doc,
|
|
132
|
-
recovery: {
|
|
133
|
-
cause: FAILURE_CATEGORIES.EXECUTION_FAILURE.id,
|
|
134
|
-
...this.#agentRc !== 0 ? { exit_code: this.#agentRc } : {}
|
|
135
|
-
},
|
|
136
|
-
blocker: `${path.basename(handoffPath)} not written after exit \u2192 worktree residue is preserved as a stash (\`git stash list\` \u2192 \`git stash apply <ref>\` \u2192 review \u2192 commit to salvage or \`git stash drop\` to discard) \u2192 re-run ${this.#opts.mode} and ensure handoff is written to ${handoffPath} before exit`
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
let handoff;
|
|
142
|
-
try {
|
|
143
|
-
handoff = JSON.parse(readFileSync(handoffPath, "utf8"));
|
|
144
|
-
} catch (e) {
|
|
145
|
-
this.#done(
|
|
146
|
-
writeBlockedCarrier(handoffPath, {
|
|
147
|
-
phase: this.#opts.mode,
|
|
148
|
-
doc: this.#opts.doc,
|
|
149
|
-
blocker: `handoff JSON unparseable: ${e.message} \u2192 fix the handoff at ${handoffPath} or re-run ${this.#opts.mode}`
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const sv = schema.validateHandoffSchema(handoff, "docs");
|
|
155
|
-
if (!sv.valid) {
|
|
156
|
-
const rec = recoverHandoff(handoff, "docs");
|
|
157
|
-
if (!rec.valid) {
|
|
158
|
-
this.#done(
|
|
159
|
-
writeBlockedCarrier(handoffPath, {
|
|
160
|
-
phase: this.#opts.mode,
|
|
161
|
-
doc: this.#opts.doc,
|
|
162
|
-
findings: rec.preservedFindings,
|
|
163
|
-
blocker: `docs handoff schema invalid${rec.reason} \u2192 fix the handoff JSON at ${handoffPath} and re-run ${this.#opts.mode}`,
|
|
164
|
-
fullReplace: true
|
|
165
|
-
// normalized-object full-replace (offending keys never stay on disk)
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
writeOwnHandoff(handoffPath, rec.handoff);
|
|
171
|
-
handoff = rec.handoff;
|
|
172
|
-
}
|
|
173
|
-
this.#handoff = handoff;
|
|
174
|
-
}
|
|
175
|
-
/** Steps 12/13: result normalization — review/fix finalization (status single-authority;
|
|
176
|
-
* review re-injects the doc_hash content token, fix keeps the agent-declared status) and the
|
|
177
|
-
* final { exitCode, handoff } result. */
|
|
178
|
-
async normalizeResult(_hookCtx) {
|
|
179
|
-
if (this.#finished) return;
|
|
180
|
-
const { mode, handoffPath } = this.#opts;
|
|
181
|
-
const handoff = this.#handoff ?? {};
|
|
182
|
-
if (mode === "review" || mode === "fix") {
|
|
183
|
-
const finalized = await finalizeHandoff({ mode, agentHandoff: handoff });
|
|
184
|
-
if (mode === "review") {
|
|
185
|
-
const merged = {
|
|
186
|
-
...finalized.handoff ?? handoff,
|
|
187
|
-
doc_hash: hashFile(this.#opts.doc)
|
|
188
|
-
};
|
|
189
|
-
writeOwnHandoff(handoffPath, merged);
|
|
190
|
-
handoff.status = merged.status;
|
|
191
|
-
handoff.doc_hash = merged.doc_hash;
|
|
192
|
-
this.#handoff = merged;
|
|
193
|
-
} else {
|
|
194
|
-
persistFinalized(handoffPath, handoff, finalized);
|
|
195
|
-
this.#handoff = finalized.handoff ?? handoff;
|
|
196
|
-
}
|
|
197
|
-
this.#exitCode = this.#agentRc !== 0 ? this.#agentRc : finalized.exitCode;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
/** Exit gate (出口门) override — docs review/fix dispatch consumes the post-commit gate like the
|
|
201
|
-
* task face (P5 落点 2/3 + spec-review-2 [2]; AC10). validateCommitContract(mode, root,
|
|
202
|
-
* { handoffPath }): dirty → BLOCKED handoff rewrite (by the rules layer) + exit code 1; the
|
|
203
|
-
* in-memory handoff re-reads from disk so the returned payload reflects the rewrite. Skipped on
|
|
204
|
-
* finished rounds (unparseable/schema-invalid dry paths) — matches the task face's skip. */
|
|
205
|
-
async commitPostCheck(_hookCtx) {
|
|
206
|
-
if (this.#finished) return;
|
|
207
|
-
const cv = await commit.validateCommitContract(this.#opts.mode, this.ctx.repoRoot, {
|
|
208
|
-
handoffPath: this.#opts.handoffPath
|
|
209
|
-
});
|
|
210
|
-
if (!cv.ok) {
|
|
211
|
-
const diagnosis = cv.blocker.includes(UNCOMMITTED_RETURN_MARKER) ? `${cv.blocker} \u2014 commit before returning` : cv.blocker;
|
|
212
|
-
process.stdout.write(`CDD_BLOCKED: ${diagnosis}
|
|
213
|
-
`);
|
|
214
|
-
this.#done({ exitCode: 1, handoff: readJson(this.#opts.handoffPath ?? "") });
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/** run — legacy surface kept ({ exitCode, handoff }) as the class's STATIC entry (Task 6/7
|
|
218
|
-
* export-surface reshuffle: `runDocsTask` → `DocsLifecycle.run` — the class public face, no bare forwarding
|
|
219
|
-
* shell): builds the injected ctx, runs the lifecycle, converts an entry-gate DispatchBlocked
|
|
220
|
-
* into a CDD_BLOCKED stderr + ExitRequested(1) (the CLI needs the process exit — it discards the
|
|
221
|
-
* return value). Root resolves eagerly for a real dispatch (entry gate must see it); dry-run
|
|
222
|
-
* defers root entirely (legacy: dry-run returned before getRoot()). */
|
|
223
|
-
static run(options) {
|
|
224
|
-
const { dryRun = false, ...rest } = options;
|
|
225
|
-
return withLifecycle(async () => {
|
|
226
|
-
const lc = new DocsLifecycle({
|
|
227
|
-
...rest,
|
|
228
|
-
dryRun,
|
|
229
|
-
ctx: {
|
|
230
|
-
mode: rest.mode,
|
|
231
|
-
repoRoot: rest.repoRoot ?? (dryRun ? null : getRoot()),
|
|
232
|
-
handoffPath: rest.handoffPath,
|
|
233
|
-
// E2②: the entry gate (inherited default hook) downgrades a dirty tree to a stderr CDD_WARN
|
|
234
|
-
// on the dry-run path — the base gate reads it from ctx; real dispatch keeps the hard BLOCKED.
|
|
235
|
-
dryRun
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
try {
|
|
239
|
-
await lc.run();
|
|
240
|
-
} catch (e) {
|
|
241
|
-
if (e instanceof DispatchBlocked && e.gate === "entry") {
|
|
242
|
-
process.stderr.write(`CDD_BLOCKED: ${e.message}
|
|
243
|
-
`);
|
|
244
|
-
exitWithCode(1);
|
|
245
|
-
}
|
|
246
|
-
throw e;
|
|
247
|
-
}
|
|
248
|
-
return lc.result;
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export { DocsLifecycle };
|