@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
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// packages/cdd-engine/src-next/__tests__/smoke.integration.test.ts
|
|
2
|
+
// The engine smoke integration test — the consumer release gate migrated from
|
|
3
|
+
// scripts/smoke-cdd.ts (P5 T7): boots the source bin (`node src-next/bin.ts`) over a
|
|
4
|
+
// fresh fixture git repo and asserts the `--help` commander face plus the read-only
|
|
5
|
+
// `--dry-run` preview (the five-row next-step forecast at zero repo writes). The engine
|
|
6
|
+
// carries no version assertion — `--expect-version` was withdrawn as a no-op (user
|
|
7
|
+
// adjudication 2026-10-12); the `smoke` script (`pnpm -C packages/cdd-engine run smoke`)
|
|
8
|
+
// is the release.yml gate's shared anchor.
|
|
9
|
+
//
|
|
10
|
+
// Zero module-level bare functions — the helpers are `const` (the P5
|
|
11
|
+
// zero-`function`-declaration discipline).
|
|
12
|
+
|
|
13
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
14
|
+
import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import { describe, it } from "vitest";
|
|
19
|
+
|
|
20
|
+
/** The source bin under test — the engine's own entry (spawned, never imported). */
|
|
21
|
+
const BIN = fileURLToPath(new URL("../bin.ts", import.meta.url));
|
|
22
|
+
|
|
23
|
+
/** The fixture plan text — the canonical data-shaped task record (the front-matter
|
|
24
|
+
* head the plan parser reads; the workspace slug derives `fixture` from the
|
|
25
|
+
* basename). */
|
|
26
|
+
const fixturePlan = (): string =>
|
|
27
|
+
[
|
|
28
|
+
"---",
|
|
29
|
+
"title: Fixture Plan",
|
|
30
|
+
"doc-type: plan",
|
|
31
|
+
"version: v1.0",
|
|
32
|
+
"date: 2026-10-09",
|
|
33
|
+
"spec: fixture-design.md",
|
|
34
|
+
"parent-program: fixture-overall.md",
|
|
35
|
+
"parent-version: v1.0",
|
|
36
|
+
"---",
|
|
37
|
+
"",
|
|
38
|
+
"## Constraints",
|
|
39
|
+
"",
|
|
40
|
+
"- Smoke fixture constraints materialized into the temp repo.",
|
|
41
|
+
"",
|
|
42
|
+
"### Task 1: fixture task",
|
|
43
|
+
"",
|
|
44
|
+
"- **Objective**: exercise the installed cdd engine under the read-only preview",
|
|
45
|
+
"- **Files**: fixture-plan.md",
|
|
46
|
+
"- **Steps**:",
|
|
47
|
+
" 1. run the new-tree engine under `--dry-run` — checkable: the preview block completes",
|
|
48
|
+
"- **Acceptance**:",
|
|
49
|
+
" - the preview forecasts the next step with zero repo writes",
|
|
50
|
+
"- **DependsOn**: none",
|
|
51
|
+
"",
|
|
52
|
+
].join("\n");
|
|
53
|
+
|
|
54
|
+
/** The fixture design spec — the plan's `spec:` link target (existence only). */
|
|
55
|
+
const fixtureSpec = (): string =>
|
|
56
|
+
[
|
|
57
|
+
"---",
|
|
58
|
+
"title: Fixture Design",
|
|
59
|
+
"doc-type: phase-spec",
|
|
60
|
+
"version: v1.0",
|
|
61
|
+
"date: 2026-10-09",
|
|
62
|
+
"status: Draft",
|
|
63
|
+
"---",
|
|
64
|
+
"",
|
|
65
|
+
"## Design",
|
|
66
|
+
"",
|
|
67
|
+
"### Acceptance criteria",
|
|
68
|
+
"",
|
|
69
|
+
"- the smoke chain audits clean",
|
|
70
|
+
"",
|
|
71
|
+
].join("\n");
|
|
72
|
+
|
|
73
|
+
/** The fixture overall — the plan's `parent-program:` link target (existence only). */
|
|
74
|
+
const fixtureOverall = (): string =>
|
|
75
|
+
[
|
|
76
|
+
"---",
|
|
77
|
+
"title: Fixture Overall",
|
|
78
|
+
"doc-type: overall-spec",
|
|
79
|
+
"version: v1.0",
|
|
80
|
+
"date: 2026-10-09",
|
|
81
|
+
"status: Draft",
|
|
82
|
+
"---",
|
|
83
|
+
"",
|
|
84
|
+
"## Phase inventory",
|
|
85
|
+
"",
|
|
86
|
+
"| # | Phase | Status | []",
|
|
87
|
+
"|---|-------|--------|-----|",
|
|
88
|
+
"",
|
|
89
|
+
"",
|
|
90
|
+
]
|
|
91
|
+
.join("\n")
|
|
92
|
+
.trimEnd();
|
|
93
|
+
|
|
94
|
+
/** The smoke assertion surface — one failed assert = the smoke fails loud. */
|
|
95
|
+
const assertOk = (cond: boolean, msg: string): void => {
|
|
96
|
+
if (!cond) throw new Error(`smoke: ${msg}`);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/** Run the source bin in a cwd (host env injected — the harness detection sees claude). */
|
|
100
|
+
const runNode = (args: string[], cwd: string): { code: number; stdout: string; stderr: string } => {
|
|
101
|
+
const res = spawnSync(process.execPath, args, {
|
|
102
|
+
cwd,
|
|
103
|
+
encoding: "utf8",
|
|
104
|
+
env: { ...process.env, CLAUDE_CODE_SESSION_ID: "1" },
|
|
105
|
+
timeout: 120_000,
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
code: res.status ?? 1,
|
|
109
|
+
stdout: (res.stdout ?? "") as string,
|
|
110
|
+
stderr: (res.stderr ?? "") as string,
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Run git in the fixture repo (the temp repo's commit identity is injected inline). */
|
|
115
|
+
const git = (repo: string, ...args: string[]): void => {
|
|
116
|
+
execFileSync("git", ["-C", repo, ...args], { encoding: "utf8", stdio: "ignore" });
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
describe("the engine smoke — the source bin over a fixture repo", () => {
|
|
120
|
+
it("boots the bin, asserts the `--help` face + the read-only `--dry-run` preview (zero writes)", () => {
|
|
121
|
+
const repoRoot = mkdtempSync(path.join(tmpdir(), "cdd-smoke-"));
|
|
122
|
+
try {
|
|
123
|
+
writeFileSync(path.join(repoRoot, ".gitignore"), ".kairos\n");
|
|
124
|
+
writeFileSync(path.join(repoRoot, "fixture-plan.md"), fixturePlan(), "utf8");
|
|
125
|
+
writeFileSync(path.join(repoRoot, "fixture-design.md"), fixtureSpec(), "utf8");
|
|
126
|
+
writeFileSync(path.join(repoRoot, "fixture-overall.md"), fixtureOverall(), "utf8");
|
|
127
|
+
git(repoRoot, "init", "-q");
|
|
128
|
+
git(
|
|
129
|
+
repoRoot,
|
|
130
|
+
"-c",
|
|
131
|
+
"user.name=cdd-smoke",
|
|
132
|
+
"-c",
|
|
133
|
+
"user.email=cdd-smoke@oscaner.dev",
|
|
134
|
+
"add",
|
|
135
|
+
"-A",
|
|
136
|
+
);
|
|
137
|
+
git(
|
|
138
|
+
repoRoot,
|
|
139
|
+
"-c",
|
|
140
|
+
"user.name=cdd-smoke",
|
|
141
|
+
"-c",
|
|
142
|
+
"user.email=cdd-smoke@oscaner.dev",
|
|
143
|
+
"commit",
|
|
144
|
+
"-qm",
|
|
145
|
+
"fixture",
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
// The help face — the commander-native program face (the T4 stable anchor): the
|
|
149
|
+
// native Usage first line + the command-table rows (the new-tree CLI's --help is
|
|
150
|
+
// the commander program face — `Usage: cdd [options] [command]` + the
|
|
151
|
+
// `implement [options]` / `review [options]` / `fix [options]` rows).
|
|
152
|
+
const helpOut = runNode([BIN, "--help"], repoRoot);
|
|
153
|
+
assertOk(
|
|
154
|
+
helpOut.stdout.includes("Usage: cdd [options] [command]") &&
|
|
155
|
+
["implement", "review", "fix"].every((name) =>
|
|
156
|
+
helpOut.stdout.includes(`${name} [options]`),
|
|
157
|
+
),
|
|
158
|
+
`--help missing the commander-native face (code ${helpOut.code}) stdout=${JSON.stringify(helpOut.stdout.slice(0, 120))} stderr=${JSON.stringify(helpOut.stderr.slice(0, 120))}`,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
// The `--dry-run` read-only preview — the release gate's zero-write face: the
|
|
162
|
+
// next dispatch step is forecast in five rows and nothing is written. The
|
|
163
|
+
// retired synthetic bookkeeping (a booked round + a fabricated capsule) is
|
|
164
|
+
// gone: a preview states the step, never a conclusion.
|
|
165
|
+
const preview = runNode(
|
|
166
|
+
[BIN, "--dry-run", "implement", "--tasks", "1", "--plan", "fixture-plan.md"],
|
|
167
|
+
repoRoot,
|
|
168
|
+
);
|
|
169
|
+
assertOk(preview.code === 0, `--dry-run implement exited ${preview.code}: ${preview.stderr}`);
|
|
170
|
+
assertOk(
|
|
171
|
+
preview.stdout.startsWith("cdd implement: preview (no repo changes)\n"),
|
|
172
|
+
`preview header missing: ${JSON.stringify(preview.stdout)}`,
|
|
173
|
+
);
|
|
174
|
+
for (const label of ["step:", "reads:", "would write:", "would record:", "child:"])
|
|
175
|
+
assertOk(preview.stdout.includes(` ${label} `), `preview row ${label} missing`);
|
|
176
|
+
// a preview fabricates no conclusion and no next hop
|
|
177
|
+
assertOk(!preview.stdout.includes("status:"), "preview must not print a status: line");
|
|
178
|
+
assertOk(!/^next:/m.test(preview.stdout), "preview must not print a next: line");
|
|
179
|
+
// zero repo writes — the engine workspace (and its slug) never appear
|
|
180
|
+
assertOk(!existsSync(path.join(repoRoot, ".kairos")), ".kairos/ must stay absent");
|
|
181
|
+
} finally {
|
|
182
|
+
rmSync(repoRoot, { recursive: true, force: true });
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// packages/cdd-engine/src-next/__tests__/support/strip-comments.ts
|
|
2
|
+
// The shared length-preserving comment/string stripper for the src-next source
|
|
3
|
+
// guards (P9 branch-review-1 F4 — one stripper, one home). Two guards read the
|
|
4
|
+
// engine's own source text and must ignore prose comments while still counting a
|
|
5
|
+
// token that lives inside a string literal (a `process.cwd()` quoted in code is a
|
|
6
|
+
// real occurrence; the same text in a `//` comment is not) — the structural pin
|
|
7
|
+
// (face/__tests__/repo-root.guard.test.ts) and the retired-plane guard
|
|
8
|
+
// (__tests__/zero-dep.test.ts) both ride this ONE implementation, so their
|
|
9
|
+
// hand-written heuristic boundary can never drift apart.
|
|
10
|
+
//
|
|
11
|
+
// The stripper preserves length and line count (a stripped comment collapses to
|
|
12
|
+
// blank chars, its line terminator survives) so a reported `line:col` hit stays
|
|
13
|
+
// true after stripping. It tracks string and template-literal interiors (never
|
|
14
|
+
// blanked — a token inside a string is a real occurrence) and regex-literal
|
|
15
|
+
// bodies (so a backtick inside `/`+…`/` never desyncs the string tracker).
|
|
16
|
+
//
|
|
17
|
+
// Documented heuristic boundary: a template literal's `${ … }` nesting is not
|
|
18
|
+
// tracked, so a backtick inside an interpolation closes the outer template early.
|
|
19
|
+
//
|
|
20
|
+
// Zero module-level bare functions — the strip/regex-may-start pair are `const`
|
|
21
|
+
// arrows (the plan's zero-`function`-declaration discipline).
|
|
22
|
+
|
|
23
|
+
/** Whether a `/` at `previous` (the last non-space code char, "" at file start)
|
|
24
|
+
* may open a regex literal rather than being a division operator. */
|
|
25
|
+
const regexMayStart = (previous: string): boolean =>
|
|
26
|
+
previous === "" || !/[A-Za-z0-9_$)\]]/.test(previous);
|
|
27
|
+
|
|
28
|
+
/** Strip line + block comments, preserving length and line count. The scan tracks
|
|
29
|
+
* string / template-literal interiors (kept verbatim — a symbol inside a string
|
|
30
|
+
* is a real occurrence, not prose) and regex-literal bodies (so a backtick inside
|
|
31
|
+
* `/`+…`/` never desyncs the string tracker); a `//` inside a string or template
|
|
32
|
+
* therefore never truncates the line. See the module header for the documented
|
|
33
|
+
* interpolation-nesting boundary. */
|
|
34
|
+
export const stripComments = (source: string): string => {
|
|
35
|
+
const out = source.split("");
|
|
36
|
+
let index = 0;
|
|
37
|
+
let previous = "";
|
|
38
|
+
while (index < source.length) {
|
|
39
|
+
const char = source[index]!;
|
|
40
|
+
const next = source[index + 1];
|
|
41
|
+
if (char === "/" && next === "/") {
|
|
42
|
+
while (index < source.length && source[index] !== "\n") {
|
|
43
|
+
out[index] = "";
|
|
44
|
+
index += 1;
|
|
45
|
+
}
|
|
46
|
+
} else if (char === "/" && next === "*") {
|
|
47
|
+
out[index] = "";
|
|
48
|
+
out[index + 1] = "";
|
|
49
|
+
index += 2;
|
|
50
|
+
while (index < source.length && !(source[index] === "*" && source[index + 1] === "/")) {
|
|
51
|
+
if (source[index] !== "\n") out[index] = "";
|
|
52
|
+
index += 1;
|
|
53
|
+
}
|
|
54
|
+
if (index < source.length) {
|
|
55
|
+
out[index] = "";
|
|
56
|
+
out[index + 1] = "";
|
|
57
|
+
index += 2;
|
|
58
|
+
}
|
|
59
|
+
} else if (char === "'" || char === '"' || char === "`") {
|
|
60
|
+
const quote = char;
|
|
61
|
+
index += 1;
|
|
62
|
+
while (index < source.length && source[index] !== quote) {
|
|
63
|
+
if (source[index] === "\\") index += 1;
|
|
64
|
+
index += 1;
|
|
65
|
+
}
|
|
66
|
+
index += 1;
|
|
67
|
+
} else if (char === "/" && regexMayStart(previous)) {
|
|
68
|
+
index += 1;
|
|
69
|
+
let inClass = false;
|
|
70
|
+
while (index < source.length) {
|
|
71
|
+
const inner = source[index]!;
|
|
72
|
+
if (inner === "\\") {
|
|
73
|
+
index += 2;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (inner === "[") {
|
|
77
|
+
inClass = true;
|
|
78
|
+
index += 1;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (inner === "]") {
|
|
82
|
+
inClass = false;
|
|
83
|
+
index += 1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (inner === "/" && !inClass) {
|
|
87
|
+
index += 1;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (inner === "\n") break;
|
|
91
|
+
index += 1;
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
if (char.trim() !== "") previous = char;
|
|
95
|
+
index += 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return out.join("");
|
|
99
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// packages/cdd-engine/src-next/__tests__/zero-dep.test.ts
|
|
2
|
+
// P3.2 zero-dependency guard (T1 → cutover): during the two-tree coexistence window the
|
|
3
|
+
// old tree (src) and the new tree (src-next) had to stay mutually import-free. The
|
|
4
|
+
// cutover (T15) deleted the old tree — the guard now pins the post-cutover terminal
|
|
5
|
+
// state: the retired planes of this package (the src and config planes) are absent from
|
|
6
|
+
// disk, and no src-next module specifier may address them (a dangling reference into a
|
|
7
|
+
// deleted plane is a hard violation of the plan's zero-residue constraint). The two-way
|
|
8
|
+
// scan becomes one-way: src-next is the only live plane left.
|
|
9
|
+
|
|
10
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
11
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { expect, it } from "vitest";
|
|
14
|
+
import { stripComments } from "./support/strip-comments.ts";
|
|
15
|
+
|
|
16
|
+
const SRC_NEXT = fileURLToPath(new URL("../", import.meta.url));
|
|
17
|
+
const PKG_ROOT = fileURLToPath(new URL("../../", import.meta.url)); // packages/cdd-engine/
|
|
18
|
+
|
|
19
|
+
// The retired-plane discriminant: which deleted plane a module specifier addresses.
|
|
20
|
+
// The bare dirnames (no trailing slash — a slash-prefixed form would itself trip the
|
|
21
|
+
// cutover's zero-residue grep) are the only retired-plane tokens the guard names.
|
|
22
|
+
type RetiredPlane = "src" | "config";
|
|
23
|
+
const RETIRED_PLANES: readonly RetiredPlane[] = ["src", "config"];
|
|
24
|
+
|
|
25
|
+
/** Which retired plane a first path segment names, or null. */
|
|
26
|
+
const retiredBySegment = (head: string | undefined): RetiredPlane | null =>
|
|
27
|
+
head === "src" || head === "config" ? head : null;
|
|
28
|
+
|
|
29
|
+
/** The retired plane a resolved path falls into (by the package-root-relative first
|
|
30
|
+
* segment), or null when the path lives in a live plane or outside the package. */
|
|
31
|
+
const retiredByResolved = (resolved: string): RetiredPlane | null => {
|
|
32
|
+
return retiredBySegment(relative(PKG_ROOT, resolved).split(sep)[0]);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Module specifier patterns: `from "..."` (static import + re-export), dynamic
|
|
36
|
+
// `import("...")`, and side-effect `import "..."`.
|
|
37
|
+
const SPECIFIER_PATTERN = /(?:from\s+|import\s*\(\s*)(['"])([^'"]+)\1/g;
|
|
38
|
+
const SIDE_EFFECT_PATTERN = /^\s*import\s+(['"])([^'"]+)\1/gm;
|
|
39
|
+
|
|
40
|
+
// Comment elision (line + block) with string literals kept verbatim — the shared
|
|
41
|
+
// length-preserving stripper (P9 branch-review-1 F4: one stripper for both source
|
|
42
|
+
// guards, `./support/strip-comments.ts`), so prose that quotes a `from "../src/x"`
|
|
43
|
+
// idiom never trips the guard and its heuristic boundary can never drift apart from
|
|
44
|
+
// the structural pin's copy.
|
|
45
|
+
|
|
46
|
+
const listTsFiles = (dir: string, files: string[]): string[] => {
|
|
47
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
48
|
+
const full = join(dir, entry.name);
|
|
49
|
+
if (entry.isDirectory()) listTsFiles(full, files);
|
|
50
|
+
else if (entry.name.endsWith(".ts") || entry.name.endsWith(".tsx")) files.push(full);
|
|
51
|
+
}
|
|
52
|
+
return files;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const extractSpecifiers = (text: string): string[] => {
|
|
56
|
+
const specifiers = new Set<string>();
|
|
57
|
+
const cleaned = stripComments(text);
|
|
58
|
+
for (const match of cleaned.matchAll(SPECIFIER_PATTERN)) specifiers.add(match[2]);
|
|
59
|
+
for (const match of cleaned.matchAll(SIDE_EFFECT_PATTERN)) specifiers.add(match[2]);
|
|
60
|
+
return [...specifiers];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Result: the retired plane a module specifier addresses, or null when it addresses
|
|
64
|
+
// neither (a live plane, a bare package, a node: builtin, or an external module).
|
|
65
|
+
const addressedRetiredPlane = (specifier: string, importer: string): RetiredPlane | null => {
|
|
66
|
+
if (!specifier.startsWith("./") && !specifier.startsWith("../") && !specifier.startsWith("/")) {
|
|
67
|
+
return retiredBySegment(specifier.split("/")[0]);
|
|
68
|
+
}
|
|
69
|
+
const resolved = specifier.startsWith("/") ? specifier : resolve(dirname(importer), specifier);
|
|
70
|
+
return retiredByResolved(resolved);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
it("the retired src and config planes are deleted from the package (the cutover terminal pin)", () => {
|
|
74
|
+
const entries = readdirSync(PKG_ROOT);
|
|
75
|
+
for (const name of RETIRED_PLANES) {
|
|
76
|
+
expect(entries, `deleted plane ${name} must be absent from the package root`).not.toContain(
|
|
77
|
+
name,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("src-next carries zero module specifiers addressing the retired src or config planes", () => {
|
|
83
|
+
const files = listTsFiles(SRC_NEXT, []);
|
|
84
|
+
const violations: string[] = [];
|
|
85
|
+
for (const file of files) {
|
|
86
|
+
for (const specifier of extractSpecifiers(readFileSync(file, "utf8"))) {
|
|
87
|
+
const target = addressedRetiredPlane(specifier, file);
|
|
88
|
+
if (target !== null) violations.push(`${file} imports "${specifier}"`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const message =
|
|
92
|
+
violations.length > 0 ? violations.join("\n") : "src-next has no retired-plane references";
|
|
93
|
+
expect(violations, message).toEqual([]);
|
|
94
|
+
});
|
package/src-next/bin.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// src-next/bin.ts — the P3.2 new-tree CLI entry. The whole command tree, the parse
|
|
3
|
+
// face and the run bodies live in face/cli.ts (T11 — the composition root); this
|
|
4
|
+
// file only boots it: pass the raw argv to the composed `Cli` (the static factory —
|
|
5
|
+
// the class face is the entry, the module carries zero bare functions), exit by its
|
|
6
|
+
// code. The dev face runs this source directly under Node >=22.18 (native type
|
|
7
|
+
// stripping); the published artifact runs the tsc-emitted dist/bin.js. Unconditional
|
|
8
|
+
// boot — this artifact is only ever executed as the CLI entry, never imported.
|
|
9
|
+
import process from "node:process";
|
|
10
|
+
|
|
11
|
+
// The environment pre-flight — the engine's `engines` floor (package.json#engines
|
|
12
|
+
// ">=22.18.0"). It is the first thing this module body runs and covers every
|
|
13
|
+
// configuration where the entry's JS actually loads — the published artifact (the
|
|
14
|
+
// tsc-emitted dist/bin.js, plain JS) on any below-floor Node, and dev-face setups
|
|
15
|
+
// that load the `.ts` entry behind the type-stripping flag while still below 22.18.
|
|
16
|
+
// On those surfaces it exits with a self-explaining message + exit 1 before the
|
|
17
|
+
// cli face loads — the Cli face is `await import`ed only after the check, so that
|
|
18
|
+
// ordering is real where reachable. It cannot cover the plain `node src-next/bin.ts`
|
|
19
|
+
// dev face on a below-22.18 Node: there the loader itself rejects the `.ts` entry
|
|
20
|
+
// (native type stripping), so no engine JS — including this guard — ever runs; that
|
|
21
|
+
// crash is inherent to a `.ts` entry on old Node. On the published artifact the
|
|
22
|
+
// guard is a no-op — floor-consistent, never over-strict.
|
|
23
|
+
const NODE_FLOOR = { major: 22, minor: 18 } as const;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* NodeEnvGuard — the entry's environment pre-flight, a static-judgement class (the
|
|
27
|
+
* module carries zero bare functions). problem() returns the below-floor message or
|
|
28
|
+
* null; the gate semantics and the exit message bytes are the boot guard's pinned
|
|
29
|
+
* face — the version floor and the wording never drift from this run.
|
|
30
|
+
*/
|
|
31
|
+
// biome-ignore lint/complexity/noStaticOnlyClass: the plan-mandated static guard surface — the zero-bare-function discipline admits no standalone predicate functions.
|
|
32
|
+
class NodeEnvGuard {
|
|
33
|
+
static problem(): string | null {
|
|
34
|
+
const [major, minor] = process.versions.node
|
|
35
|
+
.split(".")
|
|
36
|
+
.map((part) => Number.parseInt(part, 10));
|
|
37
|
+
if (major < NODE_FLOOR.major || (major === NODE_FLOOR.major && minor < NODE_FLOOR.minor)) {
|
|
38
|
+
return `cdd requires Node >= ${NODE_FLOOR.major}.${NODE_FLOOR.minor} (native type stripping) — installed: ${process.versions.node}`;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const environmentProblem = NodeEnvGuard.problem();
|
|
45
|
+
if (environmentProblem !== null) {
|
|
46
|
+
process.stderr.write(`${environmentProblem}\n`);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// The CLI face — runArgv owns the usage-error normalization (exit code 0 / 1 / 2,
|
|
51
|
+
// the steady exit-code table); the boot wrapper only maps an unexpected
|
|
52
|
+
// composition-root load/crash to the message + exit 1, never an unhandled
|
|
53
|
+
// rejection. `await import` keeps the environment pre-flight ahead of the load.
|
|
54
|
+
try {
|
|
55
|
+
const { Cli } = await import("./face/cli.ts");
|
|
56
|
+
const exitCode = await Cli.create().runArgv(process.argv.slice(2));
|
|
57
|
+
process.exit(exitCode);
|
|
58
|
+
} catch (raw) {
|
|
59
|
+
process.stderr.write(`cdd: ${raw instanceof Error ? raw.message : String(raw)}\n`);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|