@melite/estate-queue 0.0.0-stage → 0.1.5-pre-alpha
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/LICENSE +557 -0
- package/README.md +54 -2
- package/lib/bakeParams.d.ts +17 -0
- package/lib/bakeParams.js +182 -0
- package/lib/bench.d.ts +32 -0
- package/lib/bench.js +111 -0
- package/lib/cardsArmError.d.ts +61 -0
- package/lib/cardsArmError.js +57 -0
- package/lib/cardsCompose.d.ts +53 -0
- package/lib/cardsCompose.js +295 -0
- package/lib/cardsDangling.d.ts +16 -0
- package/lib/cardsDangling.js +213 -0
- package/lib/cardsFacts.d.ts +87 -0
- package/lib/cardsFacts.js +78 -0
- package/lib/cardsLanes.d.ts +43 -0
- package/lib/cardsLanes.js +178 -0
- package/lib/cardsRegistry.d.ts +404 -0
- package/lib/cardsRegistry.js +1543 -0
- package/lib/cardsVariant.d.ts +37 -0
- package/lib/cardsVariant.js +243 -0
- package/lib/discloseRegistry.d.ts +95 -0
- package/lib/discloseRegistry.js +156 -0
- package/lib/filmLead.d.ts +4 -0
- package/lib/filmLead.js +17 -0
- package/lib/filmMemoryWarn.d.ts +27 -0
- package/lib/filmMemoryWarn.js +99 -0
- package/lib/flowsData.d.ts +234 -0
- package/lib/flowsData.js +673 -0
- package/lib/flowsFamilyCompose.d.ts +45 -0
- package/lib/flowsFamilyCompose.js +191 -0
- package/lib/flowsParamsOverlay.d.ts +55 -0
- package/lib/flowsParamsOverlay.js +197 -0
- package/lib/flowsRegistryRows.d.ts +12 -0
- package/lib/flowsRegistryRows.js +520 -0
- package/lib/index.d.ts +47 -0
- package/lib/index.js +75 -0
- package/lib/ledgerTail.d.ts +20 -0
- package/lib/ledgerTail.js +123 -0
- package/lib/lifecycleLatch.d.ts +16 -0
- package/lib/lifecycleLatch.js +42 -0
- package/lib/loadPlane.d.ts +94 -0
- package/lib/loadPlane.js +570 -0
- package/lib/loadRegistry.d.ts +22 -0
- package/lib/loadRegistry.js +55 -0
- package/lib/manageOps.d.ts +27 -0
- package/lib/manageOps.js +162 -0
- package/lib/managePlane.d.ts +151 -0
- package/lib/managePlane.js +1790 -0
- package/lib/manageProbe.d.ts +48 -0
- package/lib/manageProbe.js +165 -0
- package/lib/manageRegistry.d.ts +66 -0
- package/lib/manageRegistry.js +113 -0
- package/lib/managerRail.d.ts +33 -0
- package/lib/managerRail.js +91 -0
- package/lib/mediaKinds.d.ts +3 -0
- package/lib/mediaKinds.js +2 -0
- package/lib/queue.d.ts +9 -0
- package/lib/queue.js +80 -0
- package/lib/queueCore.d.ts +72 -0
- package/lib/queueCore.js +128 -0
- package/lib/queueLifecycle.d.ts +2 -0
- package/lib/queueLifecycle.js +11 -0
- package/lib/queueLock.d.ts +60 -0
- package/lib/queueLock.js +198 -0
- package/lib/queueResurrect.d.ts +59 -0
- package/lib/queueResurrect.js +249 -0
- package/lib/queueRetry.d.ts +36 -0
- package/lib/queueRetry.js +24 -0
- package/lib/queueSidecar.d.ts +149 -0
- package/lib/queueSidecar.js +183 -0
- package/lib/queueSubmit.d.ts +82 -0
- package/lib/queueSubmit.js +191 -0
- package/lib/queueSweep.d.ts +30 -0
- package/lib/queueSweep.js +132 -0
- package/lib/resurrect.d.ts +6 -0
- package/lib/resurrect.js +18 -0
- package/lib/rootsManifest.d.ts +11 -0
- package/lib/rootsManifest.js +11 -0
- package/lib/runsChange.d.ts +61 -0
- package/lib/runsChange.js +79 -0
- package/lib/runsErrorCodes.d.ts +2 -0
- package/lib/runsErrorCodes.js +48 -0
- package/lib/runsExecute.d.ts +52 -0
- package/lib/runsExecute.js +494 -0
- package/lib/runsGates.d.ts +161 -0
- package/lib/runsGates.js +307 -0
- package/lib/runsList.d.ts +78 -0
- package/lib/runsList.js +574 -0
- package/lib/runsRefusalVoices.d.ts +9 -0
- package/lib/runsRefusalVoices.js +96 -0
- package/lib/runsRegistry.d.ts +351 -0
- package/lib/runsRegistry.js +2394 -0
- package/lib/runsSourceEcho.d.ts +81 -0
- package/lib/runsSourceEcho.js +341 -0
- package/lib/runsStart.d.ts +163 -0
- package/lib/runsStart.js +667 -0
- package/lib/runsTypes.d.ts +218 -0
- package/lib/runsTypes.js +289 -0
- package/lib/runsValidate.d.ts +5 -0
- package/lib/runsValidate.js +31 -0
- package/lib/runsValidateArms.d.ts +7 -0
- package/lib/runsValidateArms.js +339 -0
- package/lib/runsValidateInline.d.ts +6 -0
- package/lib/runsValidateInline.js +82 -0
- package/lib/runsValidateRefusals.d.ts +7 -0
- package/lib/runsValidateRefusals.js +18 -0
- package/lib/runsValidateServe.d.ts +15 -0
- package/lib/runsValidateServe.js +276 -0
- package/lib/runsValidateShared.d.ts +84 -0
- package/lib/runsValidateShared.js +88 -0
- package/lib/runsValidateStages.d.ts +32 -0
- package/lib/runsValidateStages.js +511 -0
- package/lib/runsValidateSweeps.d.ts +6 -0
- package/lib/runsValidateSweeps.js +143 -0
- package/lib/service.d.ts +63 -0
- package/lib/service.js +89 -0
- package/lib/skillFrontmatter.d.ts +11 -0
- package/lib/skillFrontmatter.js +46 -0
- package/lib/skillFs.d.ts +24 -0
- package/lib/skillFs.js +78 -0
- package/lib/skillPlane.d.ts +99 -0
- package/lib/skillPlane.js +269 -0
- package/lib/skillRegistry.d.ts +23 -0
- package/lib/skillRegistry.js +55 -0
- package/lib/skillRows.d.ts +127 -0
- package/lib/skillRows.js +468 -0
- package/lib/toolProjection.d.ts +30 -0
- package/lib/toolProjection.js +142 -0
- package/lib/vocab.d.ts +6 -0
- package/lib/vocab.js +18 -0
- package/package.json +48 -4
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export interface QueueRefusal {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly payload: Record<string, unknown>;
|
|
4
|
+
}
|
|
5
|
+
export declare function refusal(status: number, error: string, code: string, loc?: string, expected?: string, got?: string): QueueRefusal;
|
|
6
|
+
/** The envelope refusal texts (door-verbatim, the ONE voice — both
|
|
7
|
+
* the submit envelope validator below and the registry's envelope
|
|
8
|
+
* walk delegate here; one copy, no drift). Kept as a table — one
|
|
9
|
+
* voice each, like the admission gate's static tables. */
|
|
10
|
+
export declare function envelopeRefusal(kind: "not-object" | "bad-test" | "missing-draft" | "malformed-draft", doc: unknown, detail?: {
|
|
11
|
+
testFlag?: unknown;
|
|
12
|
+
draftId?: string;
|
|
13
|
+
}): QueueRefusal;
|
|
14
|
+
/** The unknown-draft refusal (door-verbatim; the probe rides the
|
|
15
|
+
* caller's drafts domain — the remote hops the ctx seat). */
|
|
16
|
+
export declare function unknownDraftRefusal(draftId: string): QueueRefusal;
|
|
17
|
+
/** Draft id rule (draftIdOk in @melite/estate-drafts, re-exported below): <=96 chars of [A-Za-z0-9_-]. */
|
|
18
|
+
/** This core re-checks nothing: it BUILDS the refusal for a caller-computed verdict (the check is one regex, owned by the drafts package so envelope validation is whole). */
|
|
19
|
+
/** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see walkSubmitEnvelope. */
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export { draftIdOk } from "@melite/estate-drafts";
|
|
27
|
+
export { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS, } from "./vocab.js";
|
|
28
|
+
/** The strict-body gate (_strict_body 248-276). */
|
|
29
|
+
export declare function strictBodyCheck(body: Record<string, unknown>): QueueRefusal | null;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
export declare function submitEnvelopeStructuralRefusal(doc: unknown): QueueRefusal | null;
|
|
44
|
+
/** Door-selection order (resolve_request 302: flow/flow_inline/
|
|
45
|
+
* model fixed order — ambiguity lists in DOOR order, not sorted). */
|
|
46
|
+
export declare const SUBMIT_DOORS: readonly string[];
|
|
47
|
+
/** The walker's chain in order: non-object body (bad_envelope/body)
|
|
48
|
+
* -> non-bool test (bad_envelope/test) -> draft required
|
|
49
|
+
* (draft_required) -> malformed (draft_malformed) -> unknown doc
|
|
50
|
+
* (draft_unknown). The probe is the caller's seat (existence is
|
|
51
|
+
* I/O — the walker owns the TEXT, the seat owns the fs). Strict
|
|
52
|
+
* knobs and door selection judge past the walk, at startReserved. */
|
|
53
|
+
/** The door-selection helpers, ONE HOME (the envelope-twin cure's
|
|
54
|
+
* doors half): the shared door set and the runs seat's
|
|
55
|
+
* selectSubmitDoor derive the door set and both
|
|
56
|
+
* refusal texts from HERE — the wire contract cannot drift
|
|
57
|
+
* between the two seats. hasOwnProperty (never `in`): a door is a
|
|
58
|
+
* body-own key, not a prototype inheritance. */
|
|
59
|
+
export declare function submitDoorsOf(body: Record<string, unknown>): string[];
|
|
60
|
+
/** The too-many-doors refusal (text is the wire contract). */
|
|
61
|
+
export declare function ambiguousDoorsRefusal(doors: string[]): QueueRefusal;
|
|
62
|
+
/** The no-door refusal (text is the wire contract). */
|
|
63
|
+
export declare function noDoorRefusal(): QueueRefusal;
|
|
64
|
+
/** THE ONE ENVELOPE WALKER (the S3 twin cure): the structural
|
|
65
|
+
* faces, the draft probe ordering and the ok face live HERE and
|
|
66
|
+
* the runs registration delegates — there is no second sync face
|
|
67
|
+
* to drift against. draftExists is the caller's probe (the runs
|
|
68
|
+
* seat hops to the drafts service and awaits; a sync caller passes
|
|
69
|
+
* a sync probe — one signature carries both). Returns the ok face
|
|
70
|
+
* when the envelope may proceed to door selection, which the live
|
|
71
|
+
* face owns at startReserved (strict then doors, after the
|
|
72
|
+
* replay/reservation verdict). */
|
|
73
|
+
export declare function walkSubmitEnvelope(doc: unknown, draftExists: (draftId: string) => boolean | Promise<boolean>): Promise<{
|
|
74
|
+
kind: "ok";
|
|
75
|
+
body: Record<string, unknown>;
|
|
76
|
+
testFlag: boolean;
|
|
77
|
+
draftId: string;
|
|
78
|
+
} | {
|
|
79
|
+
kind: "refusal";
|
|
80
|
+
refusal: QueueRefusal;
|
|
81
|
+
}>;
|
|
82
|
+
//# sourceMappingURL=queueSubmit.d.ts.map
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
// pure move, zero logic changes — the queue.ts barrel re-exports
|
|
3
|
+
// every symbol, so the public surface is byte-identical).
|
|
4
|
+
//
|
|
5
|
+
// Erasable-syntax TS only (node --experimental-strip-types): no
|
|
6
|
+
// enums, import type for types, .ts specifiers for relative imports.
|
|
7
|
+
export function refusal(status, error, code, loc, expected, got) {
|
|
8
|
+
const payload = { error, code };
|
|
9
|
+
if (loc !== undefined)
|
|
10
|
+
payload["loc"] = loc;
|
|
11
|
+
if (expected !== undefined)
|
|
12
|
+
payload["expected"] = expected;
|
|
13
|
+
if (got !== undefined)
|
|
14
|
+
payload["got"] = got;
|
|
15
|
+
return { status, payload };
|
|
16
|
+
}
|
|
17
|
+
/** The envelope refusal texts (door-verbatim, the ONE voice — both
|
|
18
|
+
* the submit envelope validator below and the registry's envelope
|
|
19
|
+
* walk delegate here; one copy, no drift). Kept as a table — one
|
|
20
|
+
* voice each, like the admission gate's static tables. */
|
|
21
|
+
export function envelopeRefusal(kind, doc, detail) {
|
|
22
|
+
switch (kind) {
|
|
23
|
+
case "not-object":
|
|
24
|
+
return refusal(400, "request body must be a JSON object", "bad_envelope", "body", "object", Array.isArray(doc) ? "array" : typeof doc);
|
|
25
|
+
case "bad-test":
|
|
26
|
+
return refusal(400, "test flag must be a boolean (got " +
|
|
27
|
+
(typeof detail?.testFlag) +
|
|
28
|
+
" " +
|
|
29
|
+
JSON.stringify(detail?.testFlag) +
|
|
30
|
+
")", "bad_envelope", "test", "boolean", (typeof detail?.testFlag));
|
|
31
|
+
case "missing-draft":
|
|
32
|
+
return refusal(400, "draft_id is required — every run is born from an " +
|
|
33
|
+
"action card (CARD BIRTH LAW); compose the card first: " +
|
|
34
|
+
"POST /v1/flows/drafts, then start with its draft_id", "draft_required", "draft_id", "doc-backed draft id", "absent");
|
|
35
|
+
case "malformed-draft":
|
|
36
|
+
return refusal(400, "draft_id malformed (96 char cap, [A-Za-z0-9_-] only): " +
|
|
37
|
+
JSON.stringify(detail?.draftId ?? ""), "draft_malformed", "draft_id", "[A-Za-z0-9_-]{1,96}", (detail?.draftId ?? "").slice(0, 60));
|
|
38
|
+
default:
|
|
39
|
+
// Closed union: a new refusal kind fails loud at compile, not
|
|
40
|
+
// silently undefined at the door. assertNever from
|
|
41
|
+
// @deepseek-ai/dsh-util-values (maintained helper, not a handroll).
|
|
42
|
+
return assertNever(kind, "queueSubmit.envelopeRefusal");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** The unknown-draft refusal (door-verbatim; the probe rides the
|
|
46
|
+
* caller's drafts domain — the remote hops the ctx seat). */
|
|
47
|
+
export function unknownDraftRefusal(draftId) {
|
|
48
|
+
return refusal(400, "unknown draft_id " +
|
|
49
|
+
JSON.stringify(draftId) +
|
|
50
|
+
" — no card doc at drafts/" +
|
|
51
|
+
draftId +
|
|
52
|
+
".json; compose the card first: POST /v1/flows/drafts", "draft_unknown", "draft_id", "existing card doc", draftId.slice(0, 60));
|
|
53
|
+
}
|
|
54
|
+
/** Draft id rule (draftIdOk in @melite/estate-drafts, re-exported below): <=96 chars of [A-Za-z0-9_-]. */
|
|
55
|
+
/** This core re-checks nothing: it BUILDS the refusal for a caller-computed verdict (the check is one regex, owned by the drafts package so envelope validation is whole). */
|
|
56
|
+
/** Callers pass the raw draft_id; the malformed/unknown split needs the existence probe too — see walkSubmitEnvelope. */
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
export { draftIdOk } from "@melite/estate-drafts";
|
|
64
|
+
// ── the submit pre-registration chain ────────────────
|
|
65
|
+
|
|
66
|
+
// carry-key / door-key sets live ONCE in ./vocab.ts;
|
|
67
|
+
// these re-exports keep the @melite/gateway-queue barrel stable.
|
|
68
|
+
export { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS, } from "./vocab.js";
|
|
69
|
+
import { RETIRED_RUNNER_KNOBS, RETIRED_CARRY_KEYS, DOOR_KEYS, } from "./vocab.js";
|
|
70
|
+
import { assertNever } from "@deepseek-ai/dsh-util-values";
|
|
71
|
+
import { draftIdOk } from "@melite/estate-drafts";
|
|
72
|
+
/** The strict-body gate (_strict_body 248-276). */
|
|
73
|
+
export function strictBodyCheck(body) {
|
|
74
|
+
const bad = Object.keys(body)
|
|
75
|
+
.filter((k) => RETIRED_RUNNER_KNOBS.includes(k) ||
|
|
76
|
+
(k.startsWith("_") && !DOOR_KEYS.includes(k)))
|
|
77
|
+
.sort();
|
|
78
|
+
if (bad.length > 0) {
|
|
79
|
+
return refusal(400, "request body carries retired runner knob(s) " +
|
|
80
|
+
JSON.stringify(bad) +
|
|
81
|
+
" — the runner never reads these (silent-drop class); remove them", "invalid_request");
|
|
82
|
+
}
|
|
83
|
+
const carry = Object.keys(body)
|
|
84
|
+
.filter((k) => RETIRED_CARRY_KEYS.includes(k))
|
|
85
|
+
.sort();
|
|
86
|
+
if (carry.length > 0) {
|
|
87
|
+
return refusal(400, "request body carries retired pipe-carry key(s) " +
|
|
88
|
+
JSON.stringify(carry) +
|
|
89
|
+
" — the 2026-08-10 stowaway wire: no gateway ever " +
|
|
90
|
+
"stashed it (flow_doc was never emitted). The revive " +
|
|
91
|
+
"rail is the draft (draft_id) + the run registry; card " +
|
|
92
|
+
"bodies carry params only", "invalid_request");
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
export function submitEnvelopeStructuralRefusal(doc) {
|
|
110
|
+
if (typeof doc !== "object" || doc === null || Array.isArray(doc)) {
|
|
111
|
+
return envelopeRefusal("not-object", doc);
|
|
112
|
+
}
|
|
113
|
+
const body = doc;
|
|
114
|
+
const testFlag = body["test"] ?? false;
|
|
115
|
+
if (typeof testFlag !== "boolean") {
|
|
116
|
+
return envelopeRefusal("bad-test", doc, { testFlag });
|
|
117
|
+
}
|
|
118
|
+
const draftId = body["draft_id"];
|
|
119
|
+
if (typeof draftId !== "string" || draftId === "") {
|
|
120
|
+
return envelopeRefusal("missing-draft", doc);
|
|
121
|
+
}
|
|
122
|
+
if (!draftIdOk(draftId)) {
|
|
123
|
+
return envelopeRefusal("malformed-draft", doc, { draftId });
|
|
124
|
+
}
|
|
125
|
+
// THE PRESS KEY (audit N-E1): an OPTIONAL client-minted id naming
|
|
126
|
+
// THE PRESS — a transport retry or a double-fire of one press
|
|
127
|
+
// replays the same key, and the registry answers the FIRST run
|
|
128
|
+
// instead of minting a second one. Absent = the legacy behavior
|
|
129
|
+
// (every call is a new press). Opaque: bounded length, safe
|
|
130
|
+
// charset, never interpreted.
|
|
131
|
+
const pressKey = body["press_key"];
|
|
132
|
+
if (pressKey !== undefined) {
|
|
133
|
+
if (typeof pressKey !== "string" || !/^[-A-Za-z0-9_.]{8,128}$/.test(pressKey)) {
|
|
134
|
+
return refusal(400, "press_key must be 8-128 chars of [-A-Za-z0-9_.] — it names ONE press across retries", "invalid_request", "press_key");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
/** Door-selection order (resolve_request 302: flow/flow_inline/
|
|
140
|
+
* model fixed order — ambiguity lists in DOOR order, not sorted). */
|
|
141
|
+
export const SUBMIT_DOORS = [
|
|
142
|
+
"flow",
|
|
143
|
+
"flow_inline",
|
|
144
|
+
"model",
|
|
145
|
+
];
|
|
146
|
+
/** The walker's chain in order: non-object body (bad_envelope/body)
|
|
147
|
+
* -> non-bool test (bad_envelope/test) -> draft required
|
|
148
|
+
* (draft_required) -> malformed (draft_malformed) -> unknown doc
|
|
149
|
+
* (draft_unknown). The probe is the caller's seat (existence is
|
|
150
|
+
* I/O — the walker owns the TEXT, the seat owns the fs). Strict
|
|
151
|
+
* knobs and door selection judge past the walk, at startReserved. */
|
|
152
|
+
/** The door-selection helpers, ONE HOME (the envelope-twin cure's
|
|
153
|
+
* doors half): the shared door set and the runs seat's
|
|
154
|
+
* selectSubmitDoor derive the door set and both
|
|
155
|
+
* refusal texts from HERE — the wire contract cannot drift
|
|
156
|
+
* between the two seats. hasOwnProperty (never `in`): a door is a
|
|
157
|
+
* body-own key, not a prototype inheritance. */
|
|
158
|
+
export function submitDoorsOf(body) {
|
|
159
|
+
return SUBMIT_DOORS.filter((k) => Object.prototype.hasOwnProperty.call(body, k));
|
|
160
|
+
}
|
|
161
|
+
/** The too-many-doors refusal (text is the wire contract). */
|
|
162
|
+
export function ambiguousDoorsRefusal(doors) {
|
|
163
|
+
return refusal(400, "ambiguous request: names " +
|
|
164
|
+
JSON.stringify(doors) +
|
|
165
|
+
" — provide exactly one of flow, flow_inline, model", "invalid_request");
|
|
166
|
+
}
|
|
167
|
+
/** The no-door refusal (text is the wire contract). */
|
|
168
|
+
export function noDoorRefusal() {
|
|
169
|
+
return refusal(400, "no flow selected: provide flow, flow_inline or model", "invalid_request");
|
|
170
|
+
}
|
|
171
|
+
/** THE ONE ENVELOPE WALKER (the S3 twin cure): the structural
|
|
172
|
+
* faces, the draft probe ordering and the ok face live HERE and
|
|
173
|
+
* the runs registration delegates — there is no second sync face
|
|
174
|
+
* to drift against. draftExists is the caller's probe (the runs
|
|
175
|
+
* seat hops to the drafts service and awaits; a sync caller passes
|
|
176
|
+
* a sync probe — one signature carries both). Returns the ok face
|
|
177
|
+
* when the envelope may proceed to door selection, which the live
|
|
178
|
+
* face owns at startReserved (strict then doors, after the
|
|
179
|
+
* replay/reservation verdict). */
|
|
180
|
+
export async function walkSubmitEnvelope(doc, draftExists) {
|
|
181
|
+
const structural = submitEnvelopeStructuralRefusal(doc);
|
|
182
|
+
if (structural !== null)
|
|
183
|
+
return { kind: "refusal", refusal: structural };
|
|
184
|
+
const body = doc;
|
|
185
|
+
const draftId = body["draft_id"];
|
|
186
|
+
if (!(await draftExists(draftId))) {
|
|
187
|
+
return { kind: "refusal", refusal: unknownDraftRefusal(draftId) };
|
|
188
|
+
}
|
|
189
|
+
return { kind: "ok", body, testFlag: body["test"] === true, draftId };
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=queueSubmit.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface SweepResult {
|
|
2
|
+
readonly touched: boolean;
|
|
3
|
+
readonly wasQueued: boolean;
|
|
4
|
+
readonly doc: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
/** Patch a stale sidecar (pure half of sweep_sidecar): every
|
|
7
|
+
* running/queued status — top-level AND per-stage (any depth) —
|
|
8
|
+
* becomes failed. Idempotent (an already-swept file has no active
|
|
9
|
+
* statuses left → touched false, no write). A run still QUEUED
|
|
10
|
+
* never executed: its sweep note + error say so (queuedWhy)
|
|
11
|
+
* instead of implying a crash mid-run. */
|
|
12
|
+
export declare function sweepSidecar(doc: Record<string, unknown>, why: string, queuedWhy?: string): SweepResult;
|
|
13
|
+
/** Boot-sweep notes (boot_sweep 2402-2409). */
|
|
14
|
+
export declare const BOOT_SWEEP_WHY: string;
|
|
15
|
+
export declare const BOOT_SWEEP_QUEUED_WHY: string;
|
|
16
|
+
/** Read-time sweep notes + response errors (sidecar_status
|
|
17
|
+
* 2428-2451): the ledger state is ALWAYS "failed" (even for a
|
|
18
|
+
* queued zombie — the error TEXT carries the never-executed
|
|
19
|
+
* honesty), error "zombie swept at read time" mid-run. */
|
|
20
|
+
export declare const READ_SWEEP_WHY: string;
|
|
21
|
+
export declare const READ_SWEEP_QUEUED_WHY: string;
|
|
22
|
+
export declare const READ_SWEEP_RUNNING_ERROR: string;
|
|
23
|
+
/** Boot-time zombie sweep (boot_sweep 2378-2410, fs half): every
|
|
24
|
+
* sidecar still claiming running/queued belongs to a DEAD process
|
|
25
|
+
* — EXCEPT liveRunIds (boot_resurrect just re-queued those; their
|
|
26
|
+
* queued sidecar is resurrected work, not a zombie). Swept BEFORE
|
|
27
|
+
* traffic, so the ledger never shows phantom actives. Returns the
|
|
28
|
+
* swept run ids in sorted order. */
|
|
29
|
+
export declare function bootSweep(stateRoot: string, liveRunIds?: readonly string[], nowS?: number): Promise<string[]>;
|
|
30
|
+
//# sourceMappingURL=queueSweep.d.ts.map
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
|
|
2
|
+
// pure move, zero logic changes — the queue.ts barrel re-exports
|
|
3
|
+
// every symbol, so the public surface is byte-identical).
|
|
4
|
+
//
|
|
5
|
+
// Erasable-syntax TS only (node --experimental-strip-types): no
|
|
6
|
+
// enums, import type for types, .ts specifiers for relative imports.
|
|
7
|
+
import { readdirSync, readFileSync, rmSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { appendLedger, writeJsonAtomic } from "./queueLock.js";
|
|
10
|
+
/** Patch a stale sidecar (pure half of sweep_sidecar): every
|
|
11
|
+
* running/queued status — top-level AND per-stage (any depth) —
|
|
12
|
+
* becomes failed. Idempotent (an already-swept file has no active
|
|
13
|
+
* statuses left → touched false, no write). A run still QUEUED
|
|
14
|
+
* never executed: its sweep note + error say so (queuedWhy)
|
|
15
|
+
* instead of implying a crash mid-run. */
|
|
16
|
+
export function sweepSidecar(doc, why, queuedWhy = "") {
|
|
17
|
+
const wasQueued = doc["status"] === "queued";
|
|
18
|
+
let touched = false;
|
|
19
|
+
const patch = (o) => {
|
|
20
|
+
if (Array.isArray(o)) {
|
|
21
|
+
for (const v of o)
|
|
22
|
+
patch(v);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (typeof o === "object" && o !== null) {
|
|
26
|
+
const rec = o;
|
|
27
|
+
if (rec["status"] === "running" || rec["status"] === "queued") {
|
|
28
|
+
rec["status"] = "failed";
|
|
29
|
+
touched = true;
|
|
30
|
+
}
|
|
31
|
+
else if (rec["status"] === "stopping") {
|
|
32
|
+
// a stopping run at sweep time: the stop was requested and
|
|
33
|
+
// the dead host IS the stop landing — 'stopped' is the
|
|
34
|
+
// honest terminal, never 'failed' (the caller asked for
|
|
35
|
+
|
|
36
|
+
rec["status"] = "stopped";
|
|
37
|
+
touched = true;
|
|
38
|
+
}
|
|
39
|
+
for (const v of Object.values(rec))
|
|
40
|
+
patch(v);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
patch(doc);
|
|
44
|
+
if (!touched)
|
|
45
|
+
return { touched: false, wasQueued, doc };
|
|
46
|
+
const note = wasQueued && queuedWhy !== "" ? queuedWhy : why;
|
|
47
|
+
doc["sweep"] = note;
|
|
48
|
+
if (wasQueued && queuedWhy !== "")
|
|
49
|
+
doc["error"] = queuedWhy;
|
|
50
|
+
return { touched: true, wasQueued, doc };
|
|
51
|
+
}
|
|
52
|
+
/** Boot-sweep notes (boot_sweep 2402-2409). */
|
|
53
|
+
export const BOOT_SWEEP_WHY = "host restarted (boot sweep): stale active sidecar from a dead process";
|
|
54
|
+
export const BOOT_SWEEP_QUEUED_WHY = "host restarted before the run started (never executed) — resubmit";
|
|
55
|
+
/** Read-time sweep notes + response errors (sidecar_status
|
|
56
|
+
* 2428-2451): the ledger state is ALWAYS "failed" (even for a
|
|
57
|
+
* queued zombie — the error TEXT carries the never-executed
|
|
58
|
+
* honesty), error "zombie swept at read time" mid-run. */
|
|
59
|
+
export const READ_SWEEP_WHY = "read-time sweep: stale running sidecar, no live registry entry";
|
|
60
|
+
export const READ_SWEEP_QUEUED_WHY = "run was still queued when the gateway vanished (never executed) — resubmit";
|
|
61
|
+
export const READ_SWEEP_RUNNING_ERROR = "zombie swept at read time";
|
|
62
|
+
/** Boot-time zombie sweep (boot_sweep 2378-2410, fs half): every
|
|
63
|
+
* sidecar still claiming running/queued belongs to a DEAD process
|
|
64
|
+
* — EXCEPT liveRunIds (boot_resurrect just re-queued those; their
|
|
65
|
+
* queued sidecar is resurrected work, not a zombie). Swept BEFORE
|
|
66
|
+
* traffic, so the ledger never shows phantom actives. Returns the
|
|
67
|
+
* swept run ids in sorted order. */
|
|
68
|
+
export async function bootSweep(stateRoot, liveRunIds = [], nowS = Math.floor(Date.now() / 1000)) {
|
|
69
|
+
const swept = [];
|
|
70
|
+
const live = new Set(liveRunIds);
|
|
71
|
+
const outRoot = join(stateRoot, "output");
|
|
72
|
+
let names;
|
|
73
|
+
try {
|
|
74
|
+
names = readdirSync(outRoot);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return swept;
|
|
78
|
+
}
|
|
79
|
+
for (const name of names.sort()) {
|
|
80
|
+
if (!name.startsWith("run-"))
|
|
81
|
+
continue;
|
|
82
|
+
if (live.has(name))
|
|
83
|
+
continue;
|
|
84
|
+
let pre = {};
|
|
85
|
+
try {
|
|
86
|
+
pre = JSON.parse(readFileSync(join(outRoot, name, "_flow.json"), "utf8"));
|
|
87
|
+
if (typeof pre !== "object" || pre === null || Array.isArray(pre)) {
|
|
88
|
+
pre = {};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
pre = {};
|
|
93
|
+
}
|
|
94
|
+
const wasQueued = pre["status"] === "queued";
|
|
95
|
+
const path = join(outRoot, name, "_flow.json");
|
|
96
|
+
let current = null;
|
|
97
|
+
try {
|
|
98
|
+
current = JSON.parse(readFileSync(path, "utf8"));
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
|
|
102
|
+
// not vanish from the sweep silently — the QUEUE LANE LAW
|
|
103
|
+
// wants every boot disposition ledgered so the operator can
|
|
104
|
+
// reconcile (the old bare continue left an unaudited row).
|
|
105
|
+
// THE CRASH-ORPHAN (lifecycle audit Q5): an ABSENT sidecar is
|
|
106
|
+
// the press that died between its two writes — the run was
|
|
107
|
+
// never enqueued, so the id is observed once here and the dir
|
|
108
|
+
// is reclaimed instead of sitting as orphan bytes. A
|
|
109
|
+
// PRESENT-but-unparsable sidecar keeps the ledger-only
|
|
110
|
+
// disposition (operator reconcile owns the genuinely corrupt).
|
|
111
|
+
const orphaned = e instanceof Error && e.code === "ENOENT";
|
|
112
|
+
if (orphaned)
|
|
113
|
+
rmSync(join(outRoot, name), { recursive: true, force: true });
|
|
114
|
+
appendLedger(stateRoot, "run.swept", { run_id: name, state: "unreadable", error: orphaned
|
|
115
|
+
? "boot sweep: _flow.json absent — crash-orphaned dir dropped"
|
|
116
|
+
: `boot sweep: _flow.json parse failed: ${e instanceof Error ? e.message : String(e)}` }, nowS);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (typeof current !== "object" || current === null || Array.isArray(current)) {
|
|
120
|
+
appendLedger(stateRoot, "run.swept", { run_id: name, state: "unreadable", error: "boot sweep: _flow.json is not an object" }, nowS);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const res = sweepSidecar(current, BOOT_SWEEP_WHY, wasQueued ? BOOT_SWEEP_QUEUED_WHY : "");
|
|
124
|
+
if (!res.touched)
|
|
125
|
+
continue;
|
|
126
|
+
await writeJsonAtomic(path, res.doc);
|
|
127
|
+
appendLedger(stateRoot, "run.swept", { run_id: name, state: wasQueued ? "queued_lost" : "failed", error: "boot sweep" }, nowS);
|
|
128
|
+
swept.push(name);
|
|
129
|
+
}
|
|
130
|
+
return swept;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=queueSweep.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { QueueRoots } from "./queue.js";
|
|
2
|
+
export type { QueueRoots };
|
|
3
|
+
/** Sweep half: stale running/queued sidecars settle failed (+ boot
|
|
4
|
+
* notes), live ids exempt. Returns swept ids in sorted order. */
|
|
5
|
+
export declare function bootSweep(roots: QueueRoots, live: readonly string[]): Promise<string[]>;
|
|
6
|
+
//# sourceMappingURL=resurrect.d.ts.map
|
package/lib/resurrect.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// resurrect.ts — thin compat seam over queue.ts (the single P5 core).
|
|
2
|
+
//
|
|
3
|
+
// STROKE 83: the hollow bootResurrect wrapper is RETIRED — the
|
|
4
|
+
// service's bootReconcile (runsRegistry.ts) replays _request.json
|
|
5
|
+
// through the start door, so revived rows carry REAL params. What
|
|
6
|
+
// stays here is the sweep ADAPTER (the QueueRoots signature) —
|
|
7
|
+
// all discipline lives in queue.ts, this file only adapts the
|
|
8
|
+
// signature, never reimplements (no second sweeper).
|
|
9
|
+
//
|
|
10
|
+
// Erasable-syntax TS only (node --experimental-strip-types): no
|
|
11
|
+
// enums, import type for types, .ts specifiers for relative imports.
|
|
12
|
+
import { bootSweep as coreSweep } from "./queue.js";
|
|
13
|
+
/** Sweep half: stale running/queued sidecars settle failed (+ boot
|
|
14
|
+
* notes), live ids exempt. Returns swept ids in sorted order. */
|
|
15
|
+
export async function bootSweep(roots, live) {
|
|
16
|
+
return coreSweep(roots.stateRoot, live);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=resurrect.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
2
|
+
type RunChangeListener = (runId: string) => void;
|
|
3
|
+
/** The event seam this pure-domain spine reaches the bus through
|
|
4
|
+
* (the bench seam's law, verbatim: the writers own no Context, the
|
|
5
|
+
* owning service installs the pair once). */
|
|
6
|
+
export interface RunsChangeSeam {
|
|
7
|
+
emit: (runId: string) => void;
|
|
8
|
+
on: (fn: RunChangeListener) => () => void;
|
|
9
|
+
}
|
|
10
|
+
declare module "@deepseek-ai/cordis" {
|
|
11
|
+
interface Events {
|
|
12
|
+
/**
|
|
13
|
+
* A run row moved — a claim (queued→running), a settle
|
|
14
|
+
* (terminal), an artifacts harvest, or a stop press (→stopping).
|
|
15
|
+
* Emitted after the write landed.
|
|
16
|
+
* @mode emit
|
|
17
|
+
* @param runId - the run whose row moved.
|
|
18
|
+
*/
|
|
19
|
+
"runs.changed": (runId: string) => void;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Install the seam (the registry service does this with its
|
|
23
|
+
* Context; tests with their own). Pass null to detach. ONE seam at
|
|
24
|
+
* a time — module state, LAST install wins (the bench seam's
|
|
25
|
+
* measured law, drafts remote.ts installBenchChangeSeam: the estate
|
|
26
|
+
* is single-tenant here, and the failure mode is loud — onRunChange
|
|
27
|
+
* refuses rather than subscribing to nothing). */
|
|
28
|
+
export declare function setRunsChangeSeam(seam: RunsChangeSeam | null): void;
|
|
29
|
+
/** Detach the seam ONLY if `seam` is still the installed one — the
|
|
30
|
+
* ownership stamp that keeps dispose honest: a fiber that installed
|
|
31
|
+
* EARLIER (a newer install displaced it) detaches nothing, so the
|
|
32
|
+
* live seam survives the older fiber's unwind.
|
|
33
|
+
* @param seam - the seam instance the caller installed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function clearRunsChangeSeam(seam: RunsChangeSeam): void;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
export declare function onRunChange(fn: RunChangeListener): () => void;
|
|
45
|
+
/** Fire the row-moved event — the write spine calls this after every
|
|
46
|
+
* landed write that moves a run (the claim, the settle, the
|
|
47
|
+
* artifacts harvest, the stop press). A wake resolves the
|
|
48
|
+
* subscriber's park in a microtask, by which time the writer's
|
|
49
|
+
* synchronous mutation has landed — the re-read serves the moved
|
|
50
|
+
* row, never the pre-write one. */
|
|
51
|
+
export declare function notifyRunChanged(runId: string): void;
|
|
52
|
+
/** Install the typed runs event seam on a Context (the registry
|
|
53
|
+
* service's constructor — the bench installer's law, drafts
|
|
54
|
+
* remote.ts installBenchChangeSeam): fiber-scoped through
|
|
55
|
+
* ctx.effect, so the seam detaches when the fiber is disposed.
|
|
56
|
+
* @param ctx - the Context whose bus carries `runs.changed`.
|
|
57
|
+
* @returns the effect disposer (the effect owns it; returned for
|
|
58
|
+
* direct callers that need an early detach). */
|
|
59
|
+
export declare function installRunsChangeSeam(ctx: Context): () => void;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=runsChange.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
let runsChangeSeam = null;
|
|
2
|
+
/** Install the seam (the registry service does this with its
|
|
3
|
+
* Context; tests with their own). Pass null to detach. ONE seam at
|
|
4
|
+
* a time — module state, LAST install wins (the bench seam's
|
|
5
|
+
* measured law, drafts remote.ts installBenchChangeSeam: the estate
|
|
6
|
+
* is single-tenant here, and the failure mode is loud — onRunChange
|
|
7
|
+
* refuses rather than subscribing to nothing). */
|
|
8
|
+
export function setRunsChangeSeam(seam) {
|
|
9
|
+
runsChangeSeam = seam;
|
|
10
|
+
}
|
|
11
|
+
/** Detach the seam ONLY if `seam` is still the installed one — the
|
|
12
|
+
* ownership stamp that keeps dispose honest: a fiber that installed
|
|
13
|
+
* EARLIER (a newer install displaced it) detaches nothing, so the
|
|
14
|
+
* live seam survives the older fiber's unwind.
|
|
15
|
+
* @param seam - the seam instance the caller installed.
|
|
16
|
+
*/
|
|
17
|
+
export function clearRunsChangeSeam(seam) {
|
|
18
|
+
if (runsChangeSeam === seam)
|
|
19
|
+
runsChangeSeam = null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export function onRunChange(fn) {
|
|
30
|
+
if (runsChangeSeam === null) {
|
|
31
|
+
throw new Error("estate-queue: no runs change seam installed — RunsRuntimeService installs it in its constructor, tests call setRunsChangeSeam()");
|
|
32
|
+
}
|
|
33
|
+
return runsChangeSeam.on((runId) => {
|
|
34
|
+
try {
|
|
35
|
+
fn(runId);
|
|
36
|
+
}
|
|
37
|
+
catch (fault) {
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
console.error("runs.changed listener fault:", fault);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** Fire the row-moved event — the write spine calls this after every
|
|
46
|
+
* landed write that moves a run (the claim, the settle, the
|
|
47
|
+
* artifacts harvest, the stop press). A wake resolves the
|
|
48
|
+
* subscriber's park in a microtask, by which time the writer's
|
|
49
|
+
* synchronous mutation has landed — the re-read serves the moved
|
|
50
|
+
* row, never the pre-write one. */
|
|
51
|
+
export function notifyRunChanged(runId) {
|
|
52
|
+
runsChangeSeam?.emit(runId);
|
|
53
|
+
}
|
|
54
|
+
/** Install the typed runs event seam on a Context (the registry
|
|
55
|
+
* service's constructor — the bench installer's law, drafts
|
|
56
|
+
* remote.ts installBenchChangeSeam): fiber-scoped through
|
|
57
|
+
* ctx.effect, so the seam detaches when the fiber is disposed.
|
|
58
|
+
* @param ctx - the Context whose bus carries `runs.changed`.
|
|
59
|
+
* @returns the effect disposer (the effect owns it; returned for
|
|
60
|
+
* direct callers that need an early detach). */
|
|
61
|
+
export function installRunsChangeSeam(ctx) {
|
|
62
|
+
let detach = null;
|
|
63
|
+
ctx.effect(() => {
|
|
64
|
+
const mine = {
|
|
65
|
+
emit: (runId) => { ctx.emit("runs.changed", runId); },
|
|
66
|
+
on: (fn) => {
|
|
67
|
+
const stop = ctx.on("runs.changed", fn);
|
|
68
|
+
return () => { stop(); };
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
setRunsChangeSeam(mine);
|
|
72
|
+
// the ownership stamp: an older fiber's unwind clears only its own
|
|
73
|
+
// install — a displaced seam detaches nothing (clearRunsChangeSeam)
|
|
74
|
+
detach = () => { clearRunsChangeSeam(mine); };
|
|
75
|
+
return detach;
|
|
76
|
+
});
|
|
77
|
+
return () => { detach?.(); };
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=runsChange.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const RUNS_ERROR_CODES: Readonly<Record<string, "runs/bad-envelope" | "runs/draft-required" | "runs/draft-malformed" | "runs/draft-unknown" | "runs/invalid-request" | "runs/preview-scope" | "runs/flow-compile" | "runs/workflow-pin" | "runs/card-compose" | "runs/card-compose-incomplete" | "runs/lane-input-missing" | "runs/lifecycle-inflight">>;
|
|
2
|
+
//# sourceMappingURL=runsErrorCodes.d.ts.map
|