@oscaner-skills/cdd-engine 4.4.0 → 4.5.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/dist/contract/doc-body.js +77 -0
- package/dist/contract/invariants.js +58 -1
- package/dist/contract/rules.js +8 -2
- package/dist/face/board-view.js +9 -9
- package/dist/face/cli.js +136 -99
- package/dist/face/gate.js +61 -149
- package/dist/session/dispatch-authority.js +282 -0
- package/dist/session/ledger.js +12 -6
- package/dist/session/line-identity.js +2 -1
- package/dist/session/next.js +55 -16
- package/dist/session/pipeline.js +13 -0
- package/dist/session/preflight.js +10 -26
- package/dist/session/run.js +8 -7
- package/dist/session/wave.js +6 -6
- package/package.json +1 -1
package/dist/face/gate.js
CHANGED
|
@@ -1,43 +1,54 @@
|
|
|
1
1
|
// packages/cdd-engine/src-next/face/gate.ts
|
|
2
2
|
// T8 — the split contract's gate face (§6.2: face/gate.ts — the target/line gate
|
|
3
|
-
// family). The work commands' readiness
|
|
4
|
-
// derivation (lineGate/#
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// family). The work commands' readiness gate facts — the single-target line's phase
|
|
4
|
+
// derivation (lineGate/#lineKey, reading the ONE walk
|
|
5
|
+
// `DispatchAuthority#linePhaseFacts`), the line identity facts the dispatch request
|
|
6
|
+
// assembles from (lineIdentity), the refusal-prose renderers the CLI still prints
|
|
7
|
+
// (`lineHopMessage` for the lifecycle's peeked hop, `hopCommand` for the dispatch
|
|
8
|
+
// verdict's `next:` value, P22 §5.2) and the group helpers (#tasksOf/#renderBrief).
|
|
9
|
+
// The dispatch VERDICT itself is not this face's: `session/dispatch-authority.ts`
|
|
10
|
+
// owns it, and the CLI refusal renders the authority's hop
|
|
11
|
+
// (`PipelineFrontier#hopOf`) on the ONE `reason · next:` line (P27 §2.4) — the
|
|
12
|
+
// pre-P27 doc BLOCK and pending-fix prose rows retired with that collapse, so this
|
|
13
|
+
// face renders no literal of its own for a refusal. The method bodies are the
|
|
8
14
|
// pre-split Cli members moved verbatim — behavior bytes identical; the root Cli
|
|
9
15
|
// holds the gate instance and composes through it via its .action thin shells (zero
|
|
10
16
|
// bare functions).
|
|
11
|
-
import { readFileSync } from "node:fs";
|
|
12
17
|
import process from "node:process";
|
|
13
|
-
import { FrontMatterExtractor } from "../contract/frontmatter.js";
|
|
14
18
|
import { BriefRenderer } from "../render/brief.js";
|
|
19
|
+
import { DispatchAuthority } from "../session/dispatch-authority.js";
|
|
15
20
|
import { RoundNaming } from "../session/round-naming.js";
|
|
16
|
-
import { BoardView } from "./board-view.js";
|
|
17
21
|
import { ARGV_CHANNEL } from "./declare.js";
|
|
18
22
|
import { HostDetect } from "./host.js";
|
|
19
23
|
import { RouteRenderer } from "./route-render.js";
|
|
20
24
|
/**
|
|
21
25
|
* CliGate — the target/line gate family (the split contract's gate face): the
|
|
22
|
-
* readiness
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* readiness FACTS the work commands render around a dispatch. The instance's methods
|
|
27
|
+
* take the per-invocation scene; the gate holds only the stable collaborators it
|
|
28
|
+
* needs — the brief renderer and the dispatch authority whose ONE line-phase walk it
|
|
29
|
+
* reads (P27 §2.7; the verdict itself is never this face's to judge). The
|
|
30
|
+
* verdict-bearing methods return their ruling + message — the root renders, never
|
|
31
|
+
* re-judges.
|
|
26
32
|
*/
|
|
27
33
|
export class CliGate {
|
|
28
34
|
#brief;
|
|
35
|
+
#authority;
|
|
29
36
|
constructor(opts = {}) {
|
|
30
37
|
this.#brief = opts.brief ?? new BriefRenderer();
|
|
38
|
+
this.#authority = opts.authority ?? new DispatchAuthority();
|
|
31
39
|
}
|
|
32
40
|
/** The single-target line's current open phase plus the doc-line verdict the gate
|
|
33
|
-
* judged —
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
+
* judged — a FACE-LEVEL FACT READ (P27 §2.7): the walk itself lives ONCE, on the
|
|
42
|
+
* session plane (`DispatchAuthority#linePhaseFacts`), so the dispatch VERDICT and
|
|
43
|
+
* this face read one derivation and can never disagree on the line's phase. The
|
|
44
|
+
* gate renders the value; it never judges a dispatch.
|
|
45
|
+
*
|
|
46
|
+
* The {phase, verdict} pair IS the gate's ruling: the verdict is the one the
|
|
47
|
+
* authority's walk returned, never a recomputed one. The task face holds no
|
|
48
|
+
* separate gate here: the wave rows are the authority's line leg — the ONE phase
|
|
49
|
+
* authority. A doc line's gate is the reviewGate method family (T8 · §3.5), shared
|
|
50
|
+
* by the lifecycle's frame phase so an opened gate dispatches: a moved doc reopens
|
|
51
|
+
* the review lead on a line whose C5 hop is on the EXIT side (a closed line, `null`,
|
|
41
52
|
* or a face-to-face station — the ONE `Ledger#docReopens` judgment), while a
|
|
42
53
|
* still-pending fix keeps its hop (drift never outranks it, §5.5 ②) so the gate
|
|
43
54
|
* never refuses the round the ONE derivation names. An unchanged doc yields the
|
|
@@ -46,9 +57,8 @@ export class CliGate {
|
|
|
46
57
|
* falls back to the legacy rounds/routes judgment: a completed-fix line reopens
|
|
47
58
|
* the review lead through its fix round's C5-1 route (the lifecycle's own
|
|
48
59
|
* fall-through — an open gate and a dispatchable frame agree), a truly closed line
|
|
49
|
-
* keeps the revision-aware
|
|
50
|
-
* unreadable doc) keeps the legacy round/route judgment
|
|
51
|
-
* message (only present facts land).
|
|
60
|
+
* keeps the revision-aware "same" verdict. An unbound line (no identity on
|
|
61
|
+
* record / an unreadable doc) keeps the legacy round/route judgment.
|
|
52
62
|
*
|
|
53
63
|
* The branch line rides the SAME drift leg (its identity document is the PLAN,
|
|
54
64
|
* P21 §3/§4.1 — the very document a branch re-review judges): a plan revision
|
|
@@ -56,86 +66,13 @@ export class CliGate {
|
|
|
56
66
|
* lead, so the `next:` a closure hands the user is never a command this gate
|
|
57
67
|
* refuses. An unchanged plan falls through to the SAME derived faces the doc lines
|
|
58
68
|
* reach: a branch review that left findings yields the derived `fix` face
|
|
59
|
-
* (`pending-fix`
|
|
60
|
-
* renders through the ONE line hop), while only a fully closed, drift-free branch
|
|
69
|
+
* (`pending-fix`), while only a fully closed, drift-free branch
|
|
61
70
|
* line keeps the generic `face-closed` row. */
|
|
62
71
|
lineGate(scene) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const verdict = key !== null && doc !== null ? scene.ledger.reviewGate(key, doc, scene.face.type) : null;
|
|
66
|
-
// The drift leg reads the ONE reopen judgment (exit-side routes only): a moved doc
|
|
67
|
-
// reopens the review lead on a line whose C5 hop is gone, while a still-pending
|
|
68
|
-
// fix keeps its own hop — drift never outranks it (§5.1 · §5.5 ②), so this gate
|
|
69
|
-
// always accepts the round the ONE derivation names.
|
|
70
|
-
if (key !== null &&
|
|
71
|
-
verdict !== null &&
|
|
72
|
-
scene.ledger.docReopens(key, scene.face.type, verdict)) {
|
|
73
|
-
return { phase: scene.face.product.reviewLead, verdict: null, reviewed: null };
|
|
74
|
-
}
|
|
75
|
-
if (verdict !== null && verdict.kind === "same") {
|
|
76
|
-
if (verdict.pending) {
|
|
77
|
-
return { phase: "fix", verdict: "pending-fix", reviewed: verdict.reviewed };
|
|
78
|
-
}
|
|
79
|
-
// same + no pending fix — the legacy rounds/routes judgment (the lifecycle's
|
|
80
|
-
// own fall-through): a completed-fix line reopens the review lead through its
|
|
81
|
-
// fix round's C5-1 route; a truly closed line keeps the revision-aware BLOCK.
|
|
82
|
-
const open = this.#linePhase(scene);
|
|
83
|
-
return open !== null
|
|
84
|
-
? { phase: open, verdict: null, reviewed: null }
|
|
85
|
-
: { phase: null, verdict: "same", reviewed: verdict.reviewed };
|
|
86
|
-
}
|
|
87
|
-
const open = this.#linePhase(scene);
|
|
88
|
-
return { phase: open, verdict: null, reviewed: null };
|
|
89
|
-
}
|
|
90
|
-
/** The doc line's revision-aware BLOCK message (T7/T8) — the unchanged-approved
|
|
91
|
-
* face: "{plan|spec} already reviewed at vX.Y (doc-hash …) — target revision
|
|
92
|
-
* unchanged; amend body/version to open a new review". Renders ONLY on the
|
|
93
|
-
* gate's "same" verdict — the approved identity the gate judged, whose reviewed
|
|
94
|
-
* ref the message names: the block consumes the verdict's identity, never a
|
|
95
|
-
* second ledger lookup (the face's judgment read points converge to the
|
|
96
|
-
* method family). Null off that face or with no identity ("target revision
|
|
97
|
-
* unchanged" is a present fact only there). */
|
|
98
|
-
docLineBlock(scene, reviewed) {
|
|
99
|
-
if (reviewed === null || (scene.target?.kind !== "plan" && scene.target?.kind !== "spec"))
|
|
100
|
-
return null;
|
|
101
|
-
const version = this.#docVersionOf(this.#docContent(scene.target.doc));
|
|
102
|
-
return `${scene.type} already reviewed at ${version ?? "the current version"} (doc-hash ${reviewed.doc_hash.slice(0, 12)}…) — target revision unchanged; amend body/version to open a new review`;
|
|
103
|
-
}
|
|
104
|
-
/** The doc line's derived pending-fix note (T8) — the unchanged + non-APPROVED
|
|
105
|
-
* face: "the pending fix applies to the unchanged doc (doc-hash …) — run cdd
|
|
106
|
-
* fix first". Renders ONLY for the gate's "pending-fix" verdict — the derived
|
|
107
|
-
* fix-awaited face (a same-doc re-review stays refused until its fix lands,
|
|
108
|
-
* Review Convergence anti-spin); the message names the reviewed identity the
|
|
109
|
-
* gate judged. */
|
|
110
|
-
pendingFixBlock(scene, reviewed) {
|
|
111
|
-
if (reviewed === null || (scene.target?.kind !== "plan" && scene.target?.kind !== "spec"))
|
|
112
|
-
return null;
|
|
113
|
-
return `the pending fix applies to the unchanged doc (doc-hash ${reviewed.doc_hash.slice(0, 12)}…) — run cdd fix first`;
|
|
114
|
-
}
|
|
115
|
-
/** lineHop(scene) — this LINE's next-hop object (§5.2), the LINE FRONTIER's
|
|
116
|
-
* assembly: built from this line's facts through `Ledger#nextHopOf` (the ONE
|
|
117
|
-
* derivation entry: the drift gate + the declaration read). The capsule and the
|
|
118
|
-
* board render the PIPELINE frontier's assembly (`PipelineFrontier#hopOf`) instead,
|
|
119
|
-
* a different reader over a different input; this one serves the CLI rejection
|
|
120
|
-
* message, which renders THIS object's `reason` + hop/station
|
|
121
|
-
* — never a second judgment, never a second shape. The doc-class
|
|
122
|
-
* discrimination is ROOTED in the workspace's own repo basis (the same basis the
|
|
123
|
-
* lifecycle injects), so an engine invoked from a subdirectory reads the
|
|
124
|
-
* same declared `doc-type:` the board does. Null when the scene holds no
|
|
125
|
-
* registered line (no fixed target → there is no line to name). */
|
|
126
|
-
lineHop(scene) {
|
|
127
|
-
const key = this.#lineKey(scene);
|
|
128
|
-
const target = this.#routeTargetOf(scene);
|
|
129
|
-
if (key === null || target === null)
|
|
130
|
-
return null;
|
|
131
|
-
const basis = scene.workspace.root.basis;
|
|
132
|
-
return scene.ledger.nextHopOf({
|
|
133
|
-
type: scene.face.type,
|
|
134
|
-
key,
|
|
135
|
-
route: scene.ledger.lineRoute(key, scene.face.type),
|
|
136
|
-
target,
|
|
72
|
+
return this.#authority.linePhaseFacts(scene.ledger, {
|
|
73
|
+
key: this.#lineKey(scene),
|
|
137
74
|
doc: this.#docOf(scene),
|
|
138
|
-
|
|
75
|
+
type: scene.face.type,
|
|
139
76
|
});
|
|
140
77
|
}
|
|
141
78
|
/** lineHopMessage(scene, hop, words) — the CLI rejection prose of one `NextHop`
|
|
@@ -145,9 +82,30 @@ export class CliGate {
|
|
|
145
82
|
lineHopMessage(scene, hop, words) {
|
|
146
83
|
if (hop === null)
|
|
147
84
|
return "the line holds no open round";
|
|
148
|
-
const renderer =
|
|
85
|
+
const renderer = this.#renderer(scene, words);
|
|
149
86
|
return scene.router.message(hop, (entry) => renderer.render({ kind: "handoff", entry }, hop.target));
|
|
150
87
|
}
|
|
88
|
+
/** hopCommand(scene, hop, words) — the `next:` VALUE of one hop through the SAME
|
|
89
|
+
* route renderer the capsule and the board read, so a dispatch refusal's `next:`
|
|
90
|
+
* and the board's `next:` row are byte-identical by construction. Empty string
|
|
91
|
+
* when the hop renders no command (the bare terminal rows). */
|
|
92
|
+
hopCommand(scene, hop, words) {
|
|
93
|
+
return this.#renderer(scene, words).renderHop(hop) ?? "";
|
|
94
|
+
}
|
|
95
|
+
/** lineIdentity(scene) — this line's stable identity facts: the ledger KEY (the
|
|
96
|
+
* branch line's constant, a doc line's declared word) and the judged document (a
|
|
97
|
+
* doc line's own path, the branch line's plan, P21 §4.1). A FACT read, never a
|
|
98
|
+
* judgment: the dispatch verdict belongs to `session/dispatch-authority.ts`, so
|
|
99
|
+
* this accessor only spares its request assembly a second key/doc derivation. */
|
|
100
|
+
lineIdentity(scene) {
|
|
101
|
+
return { key: this.#lineKey(scene), doc: this.#docOf(scene) };
|
|
102
|
+
}
|
|
103
|
+
/** The ONE route renderer of this face — the argv channel, the host spelling and
|
|
104
|
+
* the scene's repo basis (the same instance shape the capsule and the board
|
|
105
|
+
* build), so every `next:` literal this file prints speaks one rendering. */
|
|
106
|
+
#renderer(scene, words) {
|
|
107
|
+
return new RouteRenderer(words, ARGV_CHANNEL, HostDetect.detect(process.env), scene.workspace.root.basis);
|
|
108
|
+
}
|
|
151
109
|
/** The line's judged document — the doc line's own path, the branch line's plan
|
|
152
110
|
* (its identity document, P21 §4.1); null off the doc faces. */
|
|
153
111
|
#docOf(scene) {
|
|
@@ -157,19 +115,6 @@ export class CliGate {
|
|
|
157
115
|
return scene.planPath;
|
|
158
116
|
return null;
|
|
159
117
|
}
|
|
160
|
-
/** The dispatch frame's own render target (§5.2's `target` cell) — the fixed
|
|
161
|
-
* line's type + stable key (+ the plan fact the branch literal needs). A doc shape
|
|
162
|
-
* (the `--spec` channel: phase-spec / overall / single-spec) renders its OWN
|
|
163
|
-
* target-type word, never a folded `spec` spelling. */
|
|
164
|
-
#routeTargetOf(scene) {
|
|
165
|
-
if (scene.target?.kind === "branch")
|
|
166
|
-
return { type: "branch", id: "branch", plan: scene.planPath ?? undefined };
|
|
167
|
-
if (scene.target?.kind === "spec")
|
|
168
|
-
return { type: scene.face.type, id: scene.target.doc };
|
|
169
|
-
if (scene.target?.kind === "plan")
|
|
170
|
-
return { type: "plan", id: scene.target.doc };
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
118
|
/** The requested group ints — the normalized tasks value split. */
|
|
174
119
|
tasksOf(parsed) {
|
|
175
120
|
return (parsed.args.tasks ?? "").split(",").map((part) => Number(part));
|
|
@@ -187,22 +132,13 @@ export class CliGate {
|
|
|
187
132
|
const name = new RoundNaming(scene.workspace).briefName(parsed.args.tasks ?? "");
|
|
188
133
|
return scene.workspace.writeText(name, content);
|
|
189
134
|
}
|
|
190
|
-
/** The single-target line's current open phase — fix-awaits / re-review / closure
|
|
191
|
-
* read from the ledger's SINGLE line-phase judge (`Ledger#linePhase`, D40 — the
|
|
192
|
-
* retired gate twin): the gate and the lifecycle's frame frontier now read ONE
|
|
193
|
-
* source, never a second walk. */
|
|
194
|
-
#linePhase(scene) {
|
|
195
|
-
const key = this.#lineKey(scene);
|
|
196
|
-
if (key === null)
|
|
197
|
-
return null;
|
|
198
|
-
return scene.ledger.linePhase(key, scene.face.type);
|
|
199
|
-
}
|
|
200
135
|
/** The line key of a fixed-target face — the line's STABLE key (find #9 · spec
|
|
201
136
|
* §6.5/§3.7 — `"branch"` per workspace for the branch line; a doc line keys by
|
|
202
137
|
* its target-type word (`"phase-spec"` / `"overall"` / `"plan"` / `"single-spec"`)
|
|
203
138
|
* — never the argv path: a moved argv
|
|
204
139
|
* string must not fork the same line into two ledger rows, resetting its round),
|
|
205
|
-
* the lifecycle's own key derivation (run.ts #lineKey).
|
|
140
|
+
* the lifecycle's own key derivation (run.ts #lineKey). Read here as a line
|
|
141
|
+
* IDENTITY fact; the phase judgment is the authority's. */
|
|
206
142
|
#lineKey(scene) {
|
|
207
143
|
if (scene.target?.kind === "branch")
|
|
208
144
|
return "branch";
|
|
@@ -210,28 +146,4 @@ export class CliGate {
|
|
|
210
146
|
return scene.face.type;
|
|
211
147
|
return null;
|
|
212
148
|
}
|
|
213
|
-
/** The doc's live content — readable doc else null. This helper backs the face's
|
|
214
|
-
* one remaining doc read site, the revision-aware BLOCK's version token — a read
|
|
215
|
-
* fired only when the BLOCK message actually renders (the version is raw doc
|
|
216
|
-
* grammar — zero parse dependence: the revision hash is a raw-content digest).
|
|
217
|
-
* The gate's own doc read lives in the ledger (Ledger#docLineVerdict — one read
|
|
218
|
-
* per reviewGate, the shared comparison). A BLOCK render is a run-failure prose
|
|
219
|
-
* channel — never a usage face — so the read is guarded here (null on unreadable),
|
|
220
|
-
* not routed through the artifacts readText's usage error. */
|
|
221
|
-
#docContent(doc) {
|
|
222
|
-
try {
|
|
223
|
-
return readFileSync(doc, "utf8");
|
|
224
|
-
}
|
|
225
|
-
catch {
|
|
226
|
-
return null;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/** The doc's `v<major>.<minor>` version token — the front-matter `version:`
|
|
230
|
-
* scalar (the T6 read point: the header version facts ride the typed head
|
|
231
|
-
* record — the fence split + `yaml` engine, never a line scan). */
|
|
232
|
-
#docVersionOf(content) {
|
|
233
|
-
if (content === null)
|
|
234
|
-
return null;
|
|
235
|
-
return FrontMatterExtractor.split(content).head.version;
|
|
236
|
-
}
|
|
237
149
|
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// packages/cdd-engine/src-next/session/dispatch-authority.ts
|
|
2
|
+
// P27 §2 — the dispatch authority: ONE verdict over the three legs, in ONE priority
|
|
3
|
+
// order (structure → upstream → line, short-circuiting on the first refusal).
|
|
4
|
+
//
|
|
5
|
+
// Before this object the dispatch question was answered at two call sites by two
|
|
6
|
+
// independent authorities: the wave face's phase by `WaveGate.vet` (from
|
|
7
|
+
// session/preflight.ts) and the doc/branch face's by `CliGate#lineGate` (from
|
|
8
|
+
// face/cli.ts). The order between them was implicit in the two call sites, the two
|
|
9
|
+
// refusal vocabularies never met, and the station object (`NextHop`) had no dispatch
|
|
10
|
+
// reader at all — so a `next:` could name a round the dispatch face then refused.
|
|
11
|
+
//
|
|
12
|
+
// The legs:
|
|
13
|
+
// · structure — the pre-flight seam's verdict (tree-clean · in-flight · graph ·
|
|
14
|
+
// plan-ledger · doc-contract), handed in already judged: its inputs (the git
|
|
15
|
+
// tree, the in-flight lock) are the seam's to read, and the seam's report face
|
|
16
|
+
// (the ordered gate rows + the named findings) renders beside the refusal. The
|
|
17
|
+
// leg names no hop — a dirty tree has no `next:` round.
|
|
18
|
+
// · upstream — the station's reviewed-identity + closure pair over the faces that
|
|
19
|
+
// precede the request's face (P27 §2.3): the faces are read off `PIPELINE_FACES`
|
|
20
|
+
// (the ONE order), each judged by ① whether its reviewed identity moved (a doc
|
|
21
|
+
// line's `reviewGate` · a wave line's `briefDrifted`) and ② whether it has closed
|
|
22
|
+
// for the request (a doc line's `lineStateAt` · the wave face's exhaustion over
|
|
23
|
+
// `closedWaves()`). A face the pipeline never entered holds no station — its
|
|
24
|
+
// line carries no round to hold the request — so the request face is the
|
|
25
|
+
// pipeline's own first entry. `waveLineRoute !== null` is never a closure judge:
|
|
26
|
+
// a never-entered face's `active` is null, and a closed-but-drifted wave is ①'s
|
|
27
|
+
// catch, because exhaustion only answers "every task is done".
|
|
28
|
+
// · line — this line's own phase: the wave face's five rows (the `WaveGate` stays
|
|
29
|
+
// the leg's judge) and the doc/branch face's rows (pending-fix · unchanged ·
|
|
30
|
+
// face-closed, plus the drift reopen, which ADMITS the review round).
|
|
31
|
+
//
|
|
32
|
+
// The verdict's `next` is the pipeline frontier's own hop (`PipelineFrontier#hopOf`)
|
|
33
|
+
// — the object the capsule and the board already render, never a second shape and
|
|
34
|
+
// never a second derivation. The refusal line is correspondingly ONE line
|
|
35
|
+
// (§2.6): `reason · next: <command>` on the line leg, `reason · <wording>` on the
|
|
36
|
+
// structure leg (no hop to name). The command renderer itself stays on the face
|
|
37
|
+
// plane (the argv channel / host / repo-basis facts are the face's to hold).
|
|
38
|
+
//
|
|
39
|
+
// Module-level exports are types / the class — zero behavior-carrying bare functions.
|
|
40
|
+
var _a;
|
|
41
|
+
import { TargetFaceTable, targetFaces, } from "./faces.js";
|
|
42
|
+
import { DISPATCH_REASON, PIPELINE_FACES, } from "./next.js";
|
|
43
|
+
import { PipelineFrontier } from "./pipeline.js";
|
|
44
|
+
import { WaveGate } from "./wave.js";
|
|
45
|
+
/**
|
|
46
|
+
* DispatchAuthority — the ONE dispatch verdict (§2.1/§2.2). One `verdict` call walks
|
|
47
|
+
* the three legs in priority order and returns the single verdict the CLI renders,
|
|
48
|
+
* the capsule's `next:` and the board's `next:` all read the same hop through it.
|
|
49
|
+
*
|
|
50
|
+
* Rule zero on the ≤200-line class cap (broke by design, not by accident): the three
|
|
51
|
+
* legs are one short-circuit chain over one `next:` assembly — extracted, the chain's
|
|
52
|
+
* order moves to a caller and a refusal can name a round another leg contradicts.
|
|
53
|
+
*/
|
|
54
|
+
export class DispatchAuthority {
|
|
55
|
+
/** The wave face's five rows — this leg's wave judge (the judgment body stays in
|
|
56
|
+
* `WaveGate`, whose verdict rows are the reason table's `leg: "line"` rows). */
|
|
57
|
+
#waveGate;
|
|
58
|
+
constructor(opts = {}) {
|
|
59
|
+
this.#waveGate = opts.waveGate ?? new WaveGate();
|
|
60
|
+
}
|
|
61
|
+
/** verdict(request) — the priority chain: structure, then upstream, then the line.
|
|
62
|
+
* The first leg that refuses owns the verdict (§2.2: report the most upstream
|
|
63
|
+
* cause — the actionable one). */
|
|
64
|
+
verdict(request) {
|
|
65
|
+
const structure = this.structureRefusal(request.structure);
|
|
66
|
+
if (structure !== null)
|
|
67
|
+
return structure;
|
|
68
|
+
const upstream = this.#upstreamLeg(request);
|
|
69
|
+
if (upstream !== null)
|
|
70
|
+
return upstream;
|
|
71
|
+
return this.#lineLeg(request);
|
|
72
|
+
}
|
|
73
|
+
/** message(verdict, render) — the ONE refusal line (§2.6): `reason · next: ` plus
|
|
74
|
+
* the command the hop renders, or `reason · <wording>` on the structure leg. */
|
|
75
|
+
message(verdict, render) {
|
|
76
|
+
if (verdict.next === null) {
|
|
77
|
+
return render.detail === undefined || render.detail === ""
|
|
78
|
+
? verdict.reason
|
|
79
|
+
: `${verdict.reason} · ${render.detail}`;
|
|
80
|
+
}
|
|
81
|
+
const command = render.command === undefined ? "" : render.command(verdict.next);
|
|
82
|
+
return `${verdict.reason} · next: ${command}`;
|
|
83
|
+
}
|
|
84
|
+
/** The structure leg's verdict — the seam's refusal re-expressed as this chain's
|
|
85
|
+
* first row. Its token is the refusing gate's own id (the table's structure rows:
|
|
86
|
+
* `tree-clean` · `in-flight` · `graph` · `plan-ledger` · `doc-contract`), never a
|
|
87
|
+
* new spelling. Public because the lifecycle re-states a seam refusal (the
|
|
88
|
+
* structurally unreachable dispatch-entry path) through the same shape. */
|
|
89
|
+
structureRefusal(preflight) {
|
|
90
|
+
if (preflight.ok)
|
|
91
|
+
return null;
|
|
92
|
+
const gate = preflight.gate;
|
|
93
|
+
// A refused pre-flight always names its gate; a gate-less refusal is no
|
|
94
|
+
// structure verdict at all (the seam keeps its own report face).
|
|
95
|
+
if (gate === undefined)
|
|
96
|
+
return null;
|
|
97
|
+
return { allowed: false, leg: "structure", reason: gate, next: null };
|
|
98
|
+
}
|
|
99
|
+
/** The upstream leg (§2.3) — the faces that PRECEDE the request's face, in the ONE
|
|
100
|
+
* `PIPELINE_FACES` order: the request face's index cuts the order, and the first
|
|
101
|
+
* upstream face that reports owns the verdict. Its `next` is the pipeline
|
|
102
|
+
* frontier's own hop — the object the capsule and the board render — so a refusal
|
|
103
|
+
* never names a round another face contradicts. */
|
|
104
|
+
#upstreamLeg(request) {
|
|
105
|
+
const index = _a.#faceIndexOf(request.type);
|
|
106
|
+
if (index <= 0)
|
|
107
|
+
return null;
|
|
108
|
+
for (const face of PIPELINE_FACES.slice(0, index)) {
|
|
109
|
+
const station = this.#stationOf(face, request.line);
|
|
110
|
+
if (station === null)
|
|
111
|
+
continue;
|
|
112
|
+
const next = this.#hopOf(request.line);
|
|
113
|
+
const reason = station === "drift" ? DISPATCH_REASON.docDrift.token : next.reason;
|
|
114
|
+
return { allowed: false, leg: "upstream", reason, next };
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
/** One upstream face's station sign — ① first (a moved reviewed identity refuses as
|
|
119
|
+
* `doc-drift` whatever the closure cell says), then ② (the face has not closed for
|
|
120
|
+
* the request, so the frontier's own hop reason rules). */
|
|
121
|
+
#stationOf(face, facts) {
|
|
122
|
+
if (face === "wave")
|
|
123
|
+
return this.#waveStation(facts);
|
|
124
|
+
const line = _a.#docFaceOf(face, facts.pipeline);
|
|
125
|
+
if (line === null)
|
|
126
|
+
return null;
|
|
127
|
+
const ledger = facts.ledger;
|
|
128
|
+
// A line with no recorded round was never entered: no station, nothing to hold.
|
|
129
|
+
if (!_a.#docEntered(ledger, line))
|
|
130
|
+
return null;
|
|
131
|
+
if (ledger.reviewGate(line.key, line.doc, line.type).kind === "open")
|
|
132
|
+
return "drift";
|
|
133
|
+
return ledger.lineStateAt(line.key, line.type, line.doc) === "closed" ? null : "open";
|
|
134
|
+
}
|
|
135
|
+
/** The wave face's station — read off the SAME two judges the frontier runs, never a
|
|
136
|
+
* local walk: entered over the three dispatch modes, drifted over the derived
|
|
137
|
+
* batches' reviewed briefs, exhausted over `closedWaves()`. */
|
|
138
|
+
#waveStation(facts) {
|
|
139
|
+
const graph = facts.pipeline.planGraph;
|
|
140
|
+
if (graph === null)
|
|
141
|
+
return null;
|
|
142
|
+
const frontier = this.#frontierOf(facts);
|
|
143
|
+
if (!frontier.wavesEntered(graph))
|
|
144
|
+
return null;
|
|
145
|
+
const drifted = graph.batches().some((batch) => facts.ledger.briefDrifted(batch.join(",")));
|
|
146
|
+
if (drifted)
|
|
147
|
+
return "drift";
|
|
148
|
+
return frontier.wavesExhausted(graph) ? null : "open";
|
|
149
|
+
}
|
|
150
|
+
/** The line leg — this line's phase against the requested one, with the refusal's
|
|
151
|
+
* `next` read from the pipeline frontier only when the line actually refuses. */
|
|
152
|
+
#lineLeg(request) {
|
|
153
|
+
const ruling = request.type === "wave" ? this.#waveRuling(request) : this.#docRuling(request);
|
|
154
|
+
if (ruling.kind === "allowed")
|
|
155
|
+
return { allowed: true };
|
|
156
|
+
const next = this.#hopOf(request.line);
|
|
157
|
+
const reason = ruling.kind === "row" ? ruling.reason : next.reason;
|
|
158
|
+
return { allowed: false, leg: "line", reason, next };
|
|
159
|
+
}
|
|
160
|
+
/** The wave face's rows — the three-verb gate judged whole (its order IS the
|
|
161
|
+
* judgment: a shape matching an earlier row keeps that earlier row's cause). */
|
|
162
|
+
#waveRuling(request) {
|
|
163
|
+
const facts = request.line;
|
|
164
|
+
if (facts.graph === null || facts.tasks === null)
|
|
165
|
+
return { kind: "allowed" };
|
|
166
|
+
const verdict = this.#waveGate.vet(facts.tasks, request.verb, facts.graph, facts.ledger, facts.words);
|
|
167
|
+
if (verdict.ok || verdict.reason === undefined)
|
|
168
|
+
return { kind: "allowed" };
|
|
169
|
+
return { kind: "row", reason: verdict.reason };
|
|
170
|
+
}
|
|
171
|
+
/** linePhaseFacts(ledger, input) — this line's phase, read ONCE (§2.7): the drift
|
|
172
|
+
* reopen (which ADMITS the review lead), the derived pending fix, then the
|
|
173
|
+
* rounds/routes judge. The face gate renders this value; this object's line leg
|
|
174
|
+
* judges it — one derivation, two readers, no second walk to drift from. */
|
|
175
|
+
linePhaseFacts(ledger, input) {
|
|
176
|
+
const gate = input.key !== null && input.doc !== null
|
|
177
|
+
? ledger.reviewGate(input.key, input.doc, input.type)
|
|
178
|
+
: null;
|
|
179
|
+
if (input.key !== null && gate !== null && ledger.docReopens(input.key, input.type, gate)) {
|
|
180
|
+
return { phase: targetFaces[input.type].product.reviewLead, verdict: null, reviewed: null };
|
|
181
|
+
}
|
|
182
|
+
if (gate !== null && gate.kind === "same") {
|
|
183
|
+
return gate.pending
|
|
184
|
+
? { phase: "fix", verdict: "pending-fix", reviewed: gate.reviewed }
|
|
185
|
+
: this.#sameDocFallback(ledger, input, gate.reviewed);
|
|
186
|
+
}
|
|
187
|
+
return { phase: this.#lineRoutePhase(ledger, input), verdict: null, reviewed: null };
|
|
188
|
+
}
|
|
189
|
+
/** An unchanged doc holding no pending fix — the legacy rounds/routes fall-through:
|
|
190
|
+
* a completed-fix line reopens the review lead through its fix round's route, while
|
|
191
|
+
* a truly closed line keeps the "same" verdict (the revision-aware BLOCK's face). */
|
|
192
|
+
#sameDocFallback(ledger, input, reviewed) {
|
|
193
|
+
const open = this.#lineRoutePhase(ledger, input);
|
|
194
|
+
return open !== null
|
|
195
|
+
? { phase: open, verdict: null, reviewed: null }
|
|
196
|
+
: { phase: null, verdict: "same", reviewed };
|
|
197
|
+
}
|
|
198
|
+
/** The rounds/routes phase — the ledger's SINGLE line-phase judge (D40). */
|
|
199
|
+
#lineRoutePhase(ledger, input) {
|
|
200
|
+
return input.key === null ? null : ledger.linePhase(input.key, input.type);
|
|
201
|
+
}
|
|
202
|
+
/** The doc/branch face's rows, in order: the line's phase (the drift reopen is a ROW
|
|
203
|
+
* that admits the review lead), then the named refusals, then the hop's own fact
|
|
204
|
+
* when the line sits at another open round. */
|
|
205
|
+
#docRuling(request) {
|
|
206
|
+
const facts = request.line;
|
|
207
|
+
const phase = this.linePhaseFacts(facts.ledger, {
|
|
208
|
+
key: facts.lineKey,
|
|
209
|
+
doc: facts.doc,
|
|
210
|
+
type: request.type,
|
|
211
|
+
});
|
|
212
|
+
if (phase.phase === this.#expectedPhase(request.type, request.verb)) {
|
|
213
|
+
return { kind: "allowed" };
|
|
214
|
+
}
|
|
215
|
+
// A pending fix is the line's own row: the fix it awaits is a present fact, and
|
|
216
|
+
// the refusal names it whatever the requested verb was.
|
|
217
|
+
if (phase.phase === "fix")
|
|
218
|
+
return { kind: "row", reason: DISPATCH_REASON.pendingFix.token };
|
|
219
|
+
if (phase.phase !== null)
|
|
220
|
+
return { kind: "hop" };
|
|
221
|
+
// The closed line: the doc shapes name their unchanged reviewed identity (the
|
|
222
|
+
// anti-spin row); every other line keeps the generic closed face.
|
|
223
|
+
const unchanged = TargetFaceTable.isDocShape(request.type) && phase.verdict === "same";
|
|
224
|
+
return {
|
|
225
|
+
kind: "row",
|
|
226
|
+
reason: unchanged ? DISPATCH_REASON.unchanged.token : DISPATCH_REASON.faceClosed.token,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/** The phase the requested verb dispatches on this face — the review verb asks for
|
|
230
|
+
* the face's OWN review lead (the branch line's `branch-review`). */
|
|
231
|
+
#expectedPhase(type, verb) {
|
|
232
|
+
if (verb === "implement")
|
|
233
|
+
return "implement";
|
|
234
|
+
if (verb === "fix")
|
|
235
|
+
return "fix";
|
|
236
|
+
return targetFaces[type].product.reviewLead;
|
|
237
|
+
}
|
|
238
|
+
/** The refusal's `next` — the pipeline frontier's ONE assembly (§2.1), the object
|
|
239
|
+
* the capsule and the board render. */
|
|
240
|
+
#hopOf(facts) {
|
|
241
|
+
return this.#frontierOf(facts).hopOf(facts.pipeline, {
|
|
242
|
+
docClassOf: facts.docClassOf,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/** The pipeline frontier over this line's ledger — ONE construction per read. */
|
|
246
|
+
#frontierOf(facts) {
|
|
247
|
+
return new PipelineFrontier(facts.ledger);
|
|
248
|
+
}
|
|
249
|
+
/** The pipeline face a target type occupies — the identity slot's declared words
|
|
250
|
+
* (`phase-spec` / `single-spec`) share face 0, every node face is its own key, and
|
|
251
|
+
* the charter (`overall`) occupies no pipeline face at all (-1). Read off
|
|
252
|
+
* `PIPELINE_FACES` (the ONE order declaration), never a second order table. */
|
|
253
|
+
static #faceIndexOf(type) {
|
|
254
|
+
const face = type === "single-spec" ? "phase-spec" : type;
|
|
255
|
+
return _a.#isPipelineFace(face) ? PIPELINE_FACES.indexOf(face) : -1;
|
|
256
|
+
}
|
|
257
|
+
static #isPipelineFace(key) {
|
|
258
|
+
return PIPELINE_FACES.includes(key);
|
|
259
|
+
}
|
|
260
|
+
/** One upstream doc face's line identity — a node face's own key/document, the
|
|
261
|
+
* identity slot's DECLARED word (`specType`, the `single-spec` / `phase-spec`
|
|
262
|
+
* spelling the document carries). A face with no document was never entered; the
|
|
263
|
+
* charter is no pipeline face at all, so it is never an upstream station. */
|
|
264
|
+
static #docFaceOf(face, pipeline) {
|
|
265
|
+
if (face === "plan" || face === "branch") {
|
|
266
|
+
return pipeline.planPath === null ? null : { type: face, key: face, doc: pipeline.planPath };
|
|
267
|
+
}
|
|
268
|
+
if (pipeline.specType === "overall")
|
|
269
|
+
return null;
|
|
270
|
+
const type = pipeline.specType ?? "phase-spec";
|
|
271
|
+
return pipeline.specPath === null ? null : { type, key: type, doc: pipeline.specPath };
|
|
272
|
+
}
|
|
273
|
+
/** Whether an upstream doc face was ever WORKED — its line carries at least one
|
|
274
|
+
* recorded round (the review lead or a fix). A face the pipeline never entered
|
|
275
|
+
* holds no station: the request face is the pipeline's own first entry. */
|
|
276
|
+
static #docEntered(ledger, line) {
|
|
277
|
+
const lead = targetFaces[line.type].product.reviewLead;
|
|
278
|
+
return (ledger.roundCount(line.key, lead, line.type) > 0 ||
|
|
279
|
+
ledger.roundCount(line.key, "fix", line.type) > 0);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
_a = DispatchAuthority;
|
package/dist/session/ledger.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
var _a;
|
|
24
24
|
import { createHash } from "node:crypto";
|
|
25
25
|
import { readdirSync, readFileSync } from "node:fs";
|
|
26
|
+
import { DocBodyProjection } from "../contract/doc-body.js";
|
|
26
27
|
import { BriefRenderer } from "../render/brief.js";
|
|
27
28
|
import { targetFaces } from "./faces.js";
|
|
28
29
|
import { HandoffSchema } from "./handoff-schema.js";
|
|
@@ -142,10 +143,15 @@ const RETIRED_SPEC_LINE_KEYS = new Set([
|
|
|
142
143
|
* derivation point — typed data, zero prose.
|
|
143
144
|
*/
|
|
144
145
|
export class ReviewRefs {
|
|
145
|
-
/** The doc-revision two-layer binding — the doc path + the content-hash
|
|
146
|
-
* (sha1 of the reviewed
|
|
146
|
+
/** The doc-revision two-layer binding — the doc path + the BODY's content-hash
|
|
147
|
+
* revision (sha1 of the reviewed body — the second layer of the doc ref). The
|
|
148
|
+
* bookkeeping faces (front matter, `## Change history`) are projected away by the
|
|
149
|
+
* `contract/` projection first (P26 T1): a closed-out registration write never
|
|
150
|
+
* reopens a reviewed line, while a substantive body edit still drifts. */
|
|
147
151
|
docRevision(doc, content) {
|
|
148
|
-
|
|
152
|
+
const body = typeof content === "string" ? content : content.toString("utf8");
|
|
153
|
+
const projected = new DocBodyProjection().project(body);
|
|
154
|
+
return { kind: "doc-revision", doc, doc_hash: this.#hash(projected) };
|
|
149
155
|
}
|
|
150
156
|
/** The brief-revision two-layer binding (D30) — the plan path the brief renders
|
|
151
157
|
* from + the RENDERED brief content's hash (the wave line's reviewed identity). */
|
|
@@ -167,7 +173,7 @@ export class ReviewRefs {
|
|
|
167
173
|
#hash(content) {
|
|
168
174
|
// The revision hash is a content digest (a fingerprint of the reviewed bytes),
|
|
169
175
|
// never a commit ref — the full sha1 hex stays unsliced so the bind basis covers
|
|
170
|
-
// the whole
|
|
176
|
+
// the whole input, not a truncated prefix.
|
|
171
177
|
return createHash("sha1").update(content).digest("hex");
|
|
172
178
|
}
|
|
173
179
|
}
|
|
@@ -783,8 +789,8 @@ export class Ledger {
|
|
|
783
789
|
return route?.kind === "review" ? route : null;
|
|
784
790
|
}
|
|
785
791
|
/** The single-target line's open phase — the rounds/routes walk the lifecycle's
|
|
786
|
-
* frame frontier (run.ts #nextLinePhase) and the
|
|
787
|
-
*
|
|
792
|
+
* frame frontier (run.ts #nextLinePhase) and the authority's line-phase read both
|
|
793
|
+
* consume (one judge, one source — the retired twin copies), mapped from
|
|
788
794
|
* `lineRoute`'s active C5 hop: the review-lead hop reads the face's own review-lead
|
|
789
795
|
* mode word (branch→branch-review, the others→review), the fix hop `"fix"`, a closed
|
|
790
796
|
* line null. */
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// Today's session carried two parallel comparisons (the doc line's doc-revision and
|
|
4
4
|
// the wave line's brief-revision); the branch line had none at all. This class is the
|
|
5
5
|
// single identity face all three read:
|
|
6
|
-
// · spec / plan — the document's `doc-revision` (a hash of the
|
|
6
|
+
// · spec / plan — the document's `doc-revision` (a hash of the BODY: front matter
|
|
7
|
+
// and `## Change history` are projected away, P26 T1);
|
|
7
8
|
// · wave — the RENDERED brief's `brief-revision` (its task sections plus the
|
|
8
9
|
// plan's `## Constraints` — a plan edit elsewhere is not a drift);
|
|
9
10
|
// · branch — its plan document's `doc-revision` (the SAME kind, no new ref
|