@abelxiaoxing/cadence 1.8.3 → 2.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 +324 -111
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/agents/design-explorer.md +14 -26
- package/agents/diagnosis-worker.md +14 -25
- package/agents/implementation-worker.md +16 -35
- package/config/.env.example +2 -5
- package/config/workflow-task.example.json +7 -0
- package/docs/remote-access.md +60 -0
- package/docs/reuse-and-distribution.md +44 -0
- package/docs/service-management.md +108 -0
- package/licenses/bundled-web.txt +6245 -0
- package/licenses/pi-web-ui-MIT.txt +21 -0
- package/licenses/pi-web-ui-reuse.md +22 -0
- package/package.json +94 -21
- package/src/index.ts +22 -1807
- package/src/native-build.ts +6 -0
- package/src/native-client.ts +103 -0
- package/src/native-export.ts +58 -0
- package/src/native-history.ts +359 -0
- package/src/operator-cli.mjs +453 -1937
- package/src/plan-proposal.ts +87 -0
- package/src/sdk-worker.mjs +549 -0
- package/src/service/contracts/active.ts +82 -0
- package/src/service/contracts/budget.ts +148 -0
- package/src/service/contracts/build.ts +67 -0
- package/src/service/contracts/capture.ts +48 -0
- package/src/service/contracts/core.ts +33 -0
- package/src/service/contracts/current.ts +261 -0
- package/src/service/contracts/domain.ts +68 -0
- package/src/service/contracts/history.ts +2245 -0
- package/src/service/contracts/models.ts +139 -0
- package/src/service/coordination.ts +862 -0
- package/src/service/private-files.ts +204 -0
- package/src/service-cli.mjs +5592 -0
- package/src/service-client.ts +747 -0
- package/src/service-contract.ts +245 -0
- package/src/service-host.mjs +22382 -0
- package/src/service-http-client.ts +425 -0
- package/src/service-wire.ts +372 -0
- package/src/task-shell.ts +1045 -0
- package/src/task-store.ts +479 -0
- package/src/task-types.ts +184 -0
- package/src/verification-diagnostics.ts +29 -72
- package/src/worker-capture.mjs +1197 -0
- package/src/worker-public.mjs +1753 -0
- package/src/worker-redaction.mjs +608 -0
- package/src/worker-tools.mjs +202 -0
- package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/web/dist/assets/cadence.css +2 -0
- package/web/dist/assets/cadence.js +7 -0
- package/web/dist/assets/markdown.js +296 -0
- package/web/dist/assets/react.js +9 -0
- package/web/dist/assets/rolldown-runtime.js +1 -0
- package/web/dist/assets/timeline-client.js +41 -0
- package/web/dist/assets/vis-timeline.css +1274 -0
- package/web/dist/assets/vis-timeline.js +32 -0
- package/web/dist/index.html +18 -0
- package/web/dist/manifest.json +505 -0
- package/config/plan-draft.example.json +0 -125
- package/config/plan-draft.multiple-tasks.example.json +0 -375
- package/config/plan-draft.quick.example.json +0 -78
- package/config/routes.example.json +0 -39
- package/prompts/abel-design.md +0 -382
- package/prompts/abel-diagnose.md +0 -71
- package/prompts/abel-implement.md +0 -284
- package/prompts/abel-init.md +0 -52
- package/src/activation.ts +0 -44
- package/src/activity-contracts.ts +0 -82
- package/src/agent-registry.ts +0 -53
- package/src/apply-transaction.ts +0 -1437
- package/src/artifact-store.ts +0 -213
- package/src/build-windows-job.mjs +0 -95
- package/src/candidate-artifact.ts +0 -143
- package/src/candidate-patch.ts +0 -271
- package/src/candidate-workspace.ts +0 -80
- package/src/canonical.ts +0 -16
- package/src/change-contract-schema.ts +0 -191
- package/src/change-contract.ts +0 -324
- package/src/change-verification.ts +0 -1617
- package/src/child-budget.ts +0 -58
- package/src/child-model.ts +0 -142
- package/src/child-session.ts +0 -640
- package/src/contracts.ts +0 -2476
- package/src/control-contracts.ts +0 -382
- package/src/delivery-compiler.ts +0 -1805
- package/src/delivery-revision.ts +0 -42
- package/src/design-control.ts +0 -1299
- package/src/design-diagnostics.ts +0 -181
- package/src/design-journal.ts +0 -1773
- package/src/directory-sync.ts +0 -36
- package/src/durable-contracts.ts +0 -231
- package/src/durable-workflow.ts +0 -978
- package/src/evidence-draft.ts +0 -122
- package/src/execution-profile.ts +0 -64
- package/src/execution-retention.ts +0 -77
- package/src/file-snapshot.ts +0 -163
- package/src/implement-continuation.ts +0 -559
- package/src/implement-graph.ts +0 -690
- package/src/implement-plan.ts +0 -72
- package/src/install-config.d.mts +0 -6
- package/src/isolation-backend.ts +0 -353
- package/src/model-source.ts +0 -22
- package/src/openspec-cli.ts +0 -494
- package/src/operator-cli-entry.mjs +0 -24
- package/src/operator-tools.ts +0 -309
- package/src/package-candidate.ts +0 -227
- package/src/package-delivery.ts +0 -486
- package/src/package-state.ts +0 -320
- package/src/package-verification.ts +0 -635
- package/src/package-workflow.ts +0 -342
- package/src/packet-runtime.ts +0 -570
- package/src/parent-provider.ts +0 -375
- package/src/phase-execution.ts +0 -2259
- package/src/pi-adapter.ts +0 -19
- package/src/plan-draft-summary.ts +0 -527
- package/src/plan-draft.ts +0 -502
- package/src/remove-path.ts +0 -32
- package/src/route-policy.ts +0 -545
- package/src/run-state.ts +0 -420
- package/src/run-store.ts +0 -1179
- package/src/safe-path.ts +0 -77
- package/src/scoped-grep-worker.mjs +0 -23
- package/src/scoped-tools.ts +0 -775
- package/src/single-task-draft.ts +0 -142
- package/src/sqlite-schema.ts +0 -171
- package/src/state-root.ts +0 -215
- package/src/storage-schema.ts +0 -360
- package/src/subagent-activity.ts +0 -1417
- package/src/submit-tool.ts +0 -950
- package/src/task-ledger.ts +0 -1338
- package/src/transport-budget.ts +0 -52
- package/src/verification-capability.ts +0 -1191
- package/src/verification-environment-io.ts +0 -389
- package/src/verification-environment.ts +0 -162
- package/src/verification-identity.ts +0 -77
- package/src/verification-scan.ts +0 -64
- package/src/windows-job-backend.ts +0 -419
- package/src/windows-job.c +0 -149
- package/src/worker-broker.ts +0 -806
- package/src/workflow-engine.ts +0 -28
- package/src/workflow-policy.ts +0 -1679
- package/src/workflow-recovery-policy.ts +0 -97
- package/src/workflow-scheduling.ts +0 -105
- package/src/workflow-state-machine.ts +0 -4355
- package/src/workflow-status.ts +0 -576
- package/src/workspace-io-entry.mjs +0 -76
- package/src/workspace-io-worker.mjs +0 -1312
- package/src/workspace-io.ts +0 -89
- package/src/workspace-store.ts +0 -634
package/src/control-contracts.ts
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
// Caller-facing commands for the private Abel workflow control plane.
|
|
2
|
-
// Mechanical graph, snapshot, task, and apply identities are intentionally not
|
|
3
|
-
// part of this surface: the control plane derives them from approved delivery.
|
|
4
|
-
|
|
5
|
-
export const CONTROL_COMMANDS = [
|
|
6
|
-
"start",
|
|
7
|
-
"status",
|
|
8
|
-
"resume",
|
|
9
|
-
"rebind",
|
|
10
|
-
"cancel",
|
|
11
|
-
"discard",
|
|
12
|
-
] as const;
|
|
13
|
-
|
|
14
|
-
export const CONTROL_STAGES = ["abel-implement"] as const;
|
|
15
|
-
|
|
16
|
-
export interface RecoveryRequest {
|
|
17
|
-
incidentKey: string;
|
|
18
|
-
failureSequence: number;
|
|
19
|
-
reason: "parent-directed-retry" | "route-changed" | "context-extended";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const CONTROL_SCHEMA_PROPERTIES = {
|
|
23
|
-
command: {
|
|
24
|
-
type: "string",
|
|
25
|
-
enum: ["start", "status", "resume", "rebind", "cancel", "discard"],
|
|
26
|
-
},
|
|
27
|
-
stage: { type: "string", enum: ["abel-implement"] },
|
|
28
|
-
change: { type: "string" },
|
|
29
|
-
operationId: { type: "string" },
|
|
30
|
-
deliveryRevision: { type: "integer", minimum: 1 },
|
|
31
|
-
receiptHash: { type: "string" },
|
|
32
|
-
routeId: { type: "string" },
|
|
33
|
-
recovery: {
|
|
34
|
-
type: "object",
|
|
35
|
-
additionalProperties: false,
|
|
36
|
-
properties: {
|
|
37
|
-
incidentKey: { type: "string", pattern: "^[a-f0-9]{64}$" },
|
|
38
|
-
failureSequence: { type: "integer", minimum: 1 },
|
|
39
|
-
reason: {
|
|
40
|
-
type: "string",
|
|
41
|
-
enum: ["parent-directed-retry", "route-changed", "context-extended"],
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
required: ["incidentKey", "failureSequence", "reason"],
|
|
45
|
-
},
|
|
46
|
-
} as const;
|
|
47
|
-
|
|
48
|
-
type ControlSchemaField = Exclude<
|
|
49
|
-
keyof typeof CONTROL_SCHEMA_PROPERTIES,
|
|
50
|
-
"command"
|
|
51
|
-
>;
|
|
52
|
-
|
|
53
|
-
const commandSchema = (
|
|
54
|
-
command: ControlCommandName,
|
|
55
|
-
fields: readonly ControlSchemaField[],
|
|
56
|
-
) => ({
|
|
57
|
-
type: "object" as const,
|
|
58
|
-
properties: {
|
|
59
|
-
command: { type: "string" as const, enum: [command] },
|
|
60
|
-
...Object.fromEntries(
|
|
61
|
-
fields.map((field) => [field, CONTROL_SCHEMA_PROPERTIES[field]]),
|
|
62
|
-
),
|
|
63
|
-
},
|
|
64
|
-
required: ["command", ...fields],
|
|
65
|
-
additionalProperties: false,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Provider-facing schema for the closed Implement command union.
|
|
70
|
-
*
|
|
71
|
-
* The anyOf branches express command-specific required fields, including the
|
|
72
|
-
* paired optional receipt arguments on resume. Exact keys and provider-added
|
|
73
|
-
* nullable padding remain enforced by the canonicalizer and validator below.
|
|
74
|
-
*/
|
|
75
|
-
export const CONTROL_COMMAND_PARAMETERS = {
|
|
76
|
-
type: "object",
|
|
77
|
-
properties: CONTROL_SCHEMA_PROPERTIES,
|
|
78
|
-
required: ["command", "stage", "change"],
|
|
79
|
-
anyOf: [
|
|
80
|
-
commandSchema("start", ["stage", "change", "operationId"]),
|
|
81
|
-
commandSchema("status", ["stage", "change"]),
|
|
82
|
-
commandSchema("resume", ["stage", "change", "operationId"]),
|
|
83
|
-
commandSchema("resume", ["stage", "change", "operationId", "recovery"]),
|
|
84
|
-
commandSchema("resume", [
|
|
85
|
-
"stage",
|
|
86
|
-
"change",
|
|
87
|
-
"operationId",
|
|
88
|
-
"deliveryRevision",
|
|
89
|
-
"receiptHash",
|
|
90
|
-
"recovery",
|
|
91
|
-
]),
|
|
92
|
-
commandSchema("resume", [
|
|
93
|
-
"stage",
|
|
94
|
-
"change",
|
|
95
|
-
"operationId",
|
|
96
|
-
"deliveryRevision",
|
|
97
|
-
"receiptHash",
|
|
98
|
-
]),
|
|
99
|
-
commandSchema("rebind", ["stage", "change", "operationId", "routeId"]),
|
|
100
|
-
commandSchema("cancel", ["stage", "change", "operationId"]),
|
|
101
|
-
commandSchema("discard", ["stage", "change", "operationId"]),
|
|
102
|
-
],
|
|
103
|
-
additionalProperties: false,
|
|
104
|
-
} as const;
|
|
105
|
-
|
|
106
|
-
export type ControlCommandName = (typeof CONTROL_COMMANDS)[number];
|
|
107
|
-
export type ControlStage = (typeof CONTROL_STAGES)[number];
|
|
108
|
-
|
|
109
|
-
const IDENTIFIER = /^[a-z0-9](?:[a-z0-9._:-]{0,126}[a-z0-9])?$/iu;
|
|
110
|
-
const CHANGE_NAME = /^[a-z0-9](?:[a-z0-9-]{0,126}[a-z0-9])?$/u;
|
|
111
|
-
const SHA256 = /^[a-f0-9]{64}$/u;
|
|
112
|
-
|
|
113
|
-
interface ControlBase {
|
|
114
|
-
command: ControlCommandName;
|
|
115
|
-
stage: ControlStage;
|
|
116
|
-
change: string;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export interface StartControlCommand extends ControlBase {
|
|
120
|
-
command: "start";
|
|
121
|
-
operationId: string;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface StatusControlCommand extends ControlBase {
|
|
125
|
-
command: "status";
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface ResumeControlCommand extends ControlBase {
|
|
129
|
-
command: "resume";
|
|
130
|
-
operationId: string;
|
|
131
|
-
deliveryRevision?: number;
|
|
132
|
-
receiptHash?: string;
|
|
133
|
-
recovery?: RecoveryRequest;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface RebindControlCommand extends ControlBase {
|
|
137
|
-
command: "rebind";
|
|
138
|
-
operationId: string;
|
|
139
|
-
routeId: string;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface CancelControlCommand extends ControlBase {
|
|
143
|
-
command: "cancel";
|
|
144
|
-
operationId: string;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface DiscardControlCommand extends ControlBase {
|
|
148
|
-
command: "discard";
|
|
149
|
-
operationId: string;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export type ControlCommand =
|
|
153
|
-
| StartControlCommand
|
|
154
|
-
| StatusControlCommand
|
|
155
|
-
| ResumeControlCommand
|
|
156
|
-
| RebindControlCommand
|
|
157
|
-
| CancelControlCommand
|
|
158
|
-
| DiscardControlCommand;
|
|
159
|
-
|
|
160
|
-
export type ControlCommandValidation =
|
|
161
|
-
| { ok: true; value: ControlCommand }
|
|
162
|
-
| { ok: false; code: "invalid-control-command" };
|
|
163
|
-
|
|
164
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
165
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const CONTROL_TOOL_FIELDS = new Set([
|
|
169
|
-
"command",
|
|
170
|
-
"stage",
|
|
171
|
-
"change",
|
|
172
|
-
"operationId",
|
|
173
|
-
"deliveryRevision",
|
|
174
|
-
"receiptHash",
|
|
175
|
-
"routeId",
|
|
176
|
-
"recovery",
|
|
177
|
-
]);
|
|
178
|
-
|
|
179
|
-
const COMMAND_FIELDS: Readonly<
|
|
180
|
-
Record<ControlCommandName, ReadonlySet<string>>
|
|
181
|
-
> = Object.freeze({
|
|
182
|
-
start: new Set(["command", "stage", "change", "operationId"]),
|
|
183
|
-
status: new Set(["command", "stage", "change"]),
|
|
184
|
-
resume: new Set([
|
|
185
|
-
"command",
|
|
186
|
-
"stage",
|
|
187
|
-
"change",
|
|
188
|
-
"operationId",
|
|
189
|
-
"deliveryRevision",
|
|
190
|
-
"receiptHash",
|
|
191
|
-
"recovery",
|
|
192
|
-
]),
|
|
193
|
-
rebind: new Set(["command", "stage", "change", "operationId", "routeId"]),
|
|
194
|
-
cancel: new Set(["command", "stage", "change", "operationId"]),
|
|
195
|
-
discard: new Set(["command", "stage", "change", "operationId"]),
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Adapts Pi/provider strict-schema padding to the closed command union.
|
|
200
|
-
* Known fields belonging to a different command are projected away, while
|
|
201
|
-
* unknown fields and fields owned by the selected command remain available to
|
|
202
|
-
* the strict validator and therefore cannot bypass its exact-key/type checks.
|
|
203
|
-
*/
|
|
204
|
-
export function canonicalizeControlCommandToolInput(value: unknown): unknown {
|
|
205
|
-
if (
|
|
206
|
-
!isRecord(value) ||
|
|
207
|
-
!(CONTROL_COMMANDS as readonly unknown[]).includes(value.command)
|
|
208
|
-
) {
|
|
209
|
-
return value;
|
|
210
|
-
}
|
|
211
|
-
const command = value.command as ControlCommandName;
|
|
212
|
-
const allowed = COMMAND_FIELDS[command];
|
|
213
|
-
const canonical = Object.create(null) as Record<string, unknown>;
|
|
214
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
215
|
-
if (CONTROL_TOOL_FIELDS.has(key) && !allowed.has(key)) continue;
|
|
216
|
-
if (
|
|
217
|
-
command === "resume" &&
|
|
218
|
-
(key === "deliveryRevision" || key === "receiptHash") &&
|
|
219
|
-
(entry === null || entry === undefined)
|
|
220
|
-
) {
|
|
221
|
-
continue;
|
|
222
|
-
}
|
|
223
|
-
canonical[key] = entry;
|
|
224
|
-
}
|
|
225
|
-
return canonical;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function hasExactKeys(
|
|
229
|
-
value: Record<string, unknown>,
|
|
230
|
-
required: readonly string[],
|
|
231
|
-
optional: readonly string[] = [],
|
|
232
|
-
): boolean {
|
|
233
|
-
const keys = Object.keys(value);
|
|
234
|
-
const allowed = new Set([...required, ...optional]);
|
|
235
|
-
return (
|
|
236
|
-
required.every((key) => Object.hasOwn(value, key)) &&
|
|
237
|
-
keys.every((key) => allowed.has(key))
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function validCommon(value: Record<string, unknown>): boolean {
|
|
242
|
-
return (
|
|
243
|
-
(CONTROL_COMMANDS as readonly unknown[]).includes(value.command) &&
|
|
244
|
-
(CONTROL_STAGES as readonly unknown[]).includes(value.stage)
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function validChange(value: unknown): value is string {
|
|
249
|
-
return typeof value === "string" && CHANGE_NAME.test(value);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function validOperationId(value: unknown): value is string {
|
|
253
|
-
return typeof value === "string" && IDENTIFIER.test(value);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export function validateControlCommand(
|
|
257
|
-
value: unknown,
|
|
258
|
-
): ControlCommandValidation {
|
|
259
|
-
if (!isRecord(value)) return { ok: false, code: "invalid-control-command" };
|
|
260
|
-
if (!validCommon(value)) {
|
|
261
|
-
return { ok: false, code: "invalid-control-command" };
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const common = ["command", "stage", "change"] as const;
|
|
265
|
-
switch (value.command) {
|
|
266
|
-
case "status":
|
|
267
|
-
if (!hasExactKeys(value, common) || !validChange(value.change)) break;
|
|
268
|
-
return {
|
|
269
|
-
ok: true,
|
|
270
|
-
value: structuredClone(value) as unknown as StatusControlCommand,
|
|
271
|
-
};
|
|
272
|
-
case "cancel":
|
|
273
|
-
case "discard":
|
|
274
|
-
if (
|
|
275
|
-
hasExactKeys(value, [...common, "operationId"]) &&
|
|
276
|
-
validChange(value.change) &&
|
|
277
|
-
validOperationId(value.operationId)
|
|
278
|
-
) {
|
|
279
|
-
return {
|
|
280
|
-
ok: true,
|
|
281
|
-
value: structuredClone(value) as unknown as ControlCommand,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
break;
|
|
285
|
-
case "start":
|
|
286
|
-
if (
|
|
287
|
-
hasExactKeys(value, [...common, "operationId"]) &&
|
|
288
|
-
validChange(value.change) &&
|
|
289
|
-
validOperationId(value.operationId)
|
|
290
|
-
) {
|
|
291
|
-
return {
|
|
292
|
-
ok: true,
|
|
293
|
-
value: structuredClone(value) as unknown as StartControlCommand,
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
break;
|
|
297
|
-
case "rebind":
|
|
298
|
-
if (
|
|
299
|
-
hasExactKeys(value, [...common, "operationId", "routeId"]) &&
|
|
300
|
-
validChange(value.change) &&
|
|
301
|
-
validOperationId(value.operationId) &&
|
|
302
|
-
typeof value.routeId === "string" &&
|
|
303
|
-
IDENTIFIER.test(value.routeId)
|
|
304
|
-
) {
|
|
305
|
-
return {
|
|
306
|
-
ok: true,
|
|
307
|
-
value: structuredClone(value) as unknown as RebindControlCommand,
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
break;
|
|
311
|
-
case "resume": {
|
|
312
|
-
if (
|
|
313
|
-
!hasExactKeys(
|
|
314
|
-
value,
|
|
315
|
-
[...common, "operationId"],
|
|
316
|
-
["deliveryRevision", "receiptHash", "recovery"],
|
|
317
|
-
) ||
|
|
318
|
-
!validChange(value.change) ||
|
|
319
|
-
!validOperationId(value.operationId)
|
|
320
|
-
) {
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
323
|
-
if (
|
|
324
|
-
value.recovery !== undefined &&
|
|
325
|
-
(!isRecord(value.recovery) ||
|
|
326
|
-
!hasExactKeys(value.recovery, [
|
|
327
|
-
"incidentKey",
|
|
328
|
-
"failureSequence",
|
|
329
|
-
"reason",
|
|
330
|
-
]) ||
|
|
331
|
-
typeof value.recovery.incidentKey !== "string" ||
|
|
332
|
-
!SHA256.test(value.recovery.incidentKey) ||
|
|
333
|
-
!Number.isSafeInteger(value.recovery.failureSequence) ||
|
|
334
|
-
(value.recovery.failureSequence as number) < 1 ||
|
|
335
|
-
![
|
|
336
|
-
"parent-directed-retry",
|
|
337
|
-
"route-changed",
|
|
338
|
-
"context-extended",
|
|
339
|
-
].includes(String(value.recovery.reason)))
|
|
340
|
-
)
|
|
341
|
-
break;
|
|
342
|
-
const hasRevision = value.deliveryRevision !== undefined;
|
|
343
|
-
const hasReceipt = value.receiptHash !== undefined;
|
|
344
|
-
if (hasRevision !== hasReceipt) break;
|
|
345
|
-
if (
|
|
346
|
-
hasRevision &&
|
|
347
|
-
(!Number.isSafeInteger(value.deliveryRevision) ||
|
|
348
|
-
(value.deliveryRevision as number) < 1 ||
|
|
349
|
-
typeof value.receiptHash !== "string" ||
|
|
350
|
-
!SHA256.test(value.receiptHash))
|
|
351
|
-
) {
|
|
352
|
-
break;
|
|
353
|
-
}
|
|
354
|
-
return {
|
|
355
|
-
ok: true,
|
|
356
|
-
value: structuredClone(value) as unknown as ResumeControlCommand,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
return { ok: false, code: "invalid-control-command" };
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export function assertControlCommand(value: unknown): ControlCommand {
|
|
364
|
-
const validation = validateControlCommand(value);
|
|
365
|
-
if (!validation.ok) {
|
|
366
|
-
const error = new Error(validation.code);
|
|
367
|
-
error.name = "ControlCommandError";
|
|
368
|
-
throw error;
|
|
369
|
-
}
|
|
370
|
-
return validation.value;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export function controlRunKey(
|
|
374
|
-
canonicalRootHash: string,
|
|
375
|
-
stage: ControlStage,
|
|
376
|
-
change: string,
|
|
377
|
-
): string {
|
|
378
|
-
if (!SHA256.test(canonicalRootHash) || !CHANGE_NAME.test(change)) {
|
|
379
|
-
throw new Error("invalid-control-run-key");
|
|
380
|
-
}
|
|
381
|
-
return `${canonicalRootHash}:${stage}:${change}`;
|
|
382
|
-
}
|