@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
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Action,
|
|
3
|
+
type ActiveRuns,
|
|
4
|
+
type CancelCommand,
|
|
5
|
+
type CheckObligations,
|
|
6
|
+
type ChooseModelRequest,
|
|
7
|
+
type Command,
|
|
8
|
+
type ContextVersion,
|
|
9
|
+
ContractError,
|
|
10
|
+
type CurrentChanges,
|
|
11
|
+
type CurrentRequest,
|
|
12
|
+
type CurrentView,
|
|
13
|
+
canonicalJson,
|
|
14
|
+
compareSequence,
|
|
15
|
+
controlTask,
|
|
16
|
+
controlWorkspace,
|
|
17
|
+
type DetailReadResult,
|
|
18
|
+
decodeActiveRuns,
|
|
19
|
+
decodeCancel,
|
|
20
|
+
decodeCheckObligations,
|
|
21
|
+
decodeChooseModelRequest,
|
|
22
|
+
decodeCommand,
|
|
23
|
+
decodeCurrentChanges,
|
|
24
|
+
decodeCurrentChangesRequest,
|
|
25
|
+
decodeCurrentRequest,
|
|
26
|
+
decodeCurrentView,
|
|
27
|
+
decodeCursor,
|
|
28
|
+
decodeDetailReadResult,
|
|
29
|
+
decodeEntityReadRequest,
|
|
30
|
+
decodeEntityReadResult,
|
|
31
|
+
decodeExportRequest,
|
|
32
|
+
decodeGraphReadRequest,
|
|
33
|
+
decodeGraphReadResult,
|
|
34
|
+
decodeHistoryReadResult,
|
|
35
|
+
decodeId,
|
|
36
|
+
decodeListRequest,
|
|
37
|
+
decodeLiveEvent,
|
|
38
|
+
decodeModelCatalog,
|
|
39
|
+
decodeModelChoiceState,
|
|
40
|
+
decodePreflight,
|
|
41
|
+
decodePreflightRequest,
|
|
42
|
+
decodeReceipt,
|
|
43
|
+
decodeReceiptLookup,
|
|
44
|
+
decodeReply,
|
|
45
|
+
decodeScope,
|
|
46
|
+
decodeSearchPage,
|
|
47
|
+
decodeSessionBootstrap,
|
|
48
|
+
decodeSnapshot,
|
|
49
|
+
decodeStoredCommand,
|
|
50
|
+
decodeWorkspaceBootstrap,
|
|
51
|
+
type EntityReadRequest,
|
|
52
|
+
type EntityReadResult,
|
|
53
|
+
type ExportFrame,
|
|
54
|
+
type ExportRequest,
|
|
55
|
+
ExportTracker,
|
|
56
|
+
type GraphReadRequest,
|
|
57
|
+
type GraphReadResult,
|
|
58
|
+
type HistoryReadResult,
|
|
59
|
+
historyReplyMatches,
|
|
60
|
+
LIMITS,
|
|
61
|
+
type ListRequest,
|
|
62
|
+
type LiveEvent,
|
|
63
|
+
type ModelCatalog,
|
|
64
|
+
type ModelChoiceState,
|
|
65
|
+
type Preflight,
|
|
66
|
+
type PreflightRequest,
|
|
67
|
+
publicError,
|
|
68
|
+
type ReadCursor,
|
|
69
|
+
type ReaderKind,
|
|
70
|
+
type Receipt,
|
|
71
|
+
type ReceiptLookup,
|
|
72
|
+
type Reply,
|
|
73
|
+
type Scope,
|
|
74
|
+
type SearchPage,
|
|
75
|
+
type SessionBootstrap,
|
|
76
|
+
type Snapshot,
|
|
77
|
+
type WorkspaceBootstrap,
|
|
78
|
+
} from "./service-contract.ts";
|
|
79
|
+
|
|
80
|
+
/** Transport supplies authentication separately. No URL, auth value, generic send,
|
|
81
|
+
* SDK instance or execution ownership is exposed by the client API.
|
|
82
|
+
* Text transports use parseWireJson BEFORE handing unknown values to this client.
|
|
83
|
+
*/
|
|
84
|
+
export interface ServiceTransport {
|
|
85
|
+
current?(request: CurrentRequest, signal?: AbortSignal): Promise<unknown>;
|
|
86
|
+
currentChanges?(
|
|
87
|
+
request: CurrentRequest,
|
|
88
|
+
signal?: AbortSignal,
|
|
89
|
+
): Promise<unknown>;
|
|
90
|
+
activeRuns?(signal?: AbortSignal): Promise<unknown>;
|
|
91
|
+
models?(signal?: AbortSignal): Promise<unknown>;
|
|
92
|
+
chooseModel?(request: ChooseModelRequest): Promise<unknown>;
|
|
93
|
+
checkObligations(taskId: string, signal?: AbortSignal): Promise<unknown>;
|
|
94
|
+
entity(request: EntityReadRequest, signal?: AbortSignal): Promise<unknown>;
|
|
95
|
+
session(signal?: AbortSignal): Promise<unknown>;
|
|
96
|
+
workspace(signal?: AbortSignal): Promise<unknown>;
|
|
97
|
+
tasks(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
98
|
+
runs(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
99
|
+
messages(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
100
|
+
tools(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
101
|
+
contents(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
102
|
+
events(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
103
|
+
checks(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
104
|
+
changes(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
105
|
+
reviews(request: ListRequest, signal?: AbortSignal): Promise<unknown>;
|
|
106
|
+
graph(request: GraphReadRequest, signal?: AbortSignal): Promise<unknown>;
|
|
107
|
+
export(request: ExportRequest, signal: AbortSignal): AsyncIterable<unknown>;
|
|
108
|
+
preflight(request: PreflightRequest): Promise<unknown>;
|
|
109
|
+
command(command: Command): Promise<unknown>;
|
|
110
|
+
cancel(command: CancelCommand): Promise<unknown>;
|
|
111
|
+
receipt(commandId: string, signal?: AbortSignal): Promise<unknown>;
|
|
112
|
+
snapshot(scope: Scope, signal?: AbortSignal): Promise<unknown>;
|
|
113
|
+
detail(cursor: ReadCursor, signal?: AbortSignal): Promise<unknown>;
|
|
114
|
+
search(cursor: ReadCursor, signal?: AbortSignal): Promise<unknown>;
|
|
115
|
+
}
|
|
116
|
+
type NamedCommand<K extends Action["kind"]> = Omit<Command, "action"> & {
|
|
117
|
+
action: Extract<Action, { kind: K }>;
|
|
118
|
+
};
|
|
119
|
+
const unavailable = <T>(mutation: boolean): Reply<T> => ({
|
|
120
|
+
kind: "error",
|
|
121
|
+
error: publicError("unavailable", mutation ? "uncertain" : "none"),
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export class ServiceClient {
|
|
125
|
+
constructor(private readonly transport: ServiceTransport) {}
|
|
126
|
+
async current(
|
|
127
|
+
input: CurrentRequest,
|
|
128
|
+
signal?: AbortSignal,
|
|
129
|
+
): Promise<Reply<CurrentView>> {
|
|
130
|
+
const request = decodeCurrentRequest(input);
|
|
131
|
+
try {
|
|
132
|
+
if (!this.transport.current) return unavailable(false);
|
|
133
|
+
const reply = decodeReply(
|
|
134
|
+
await this.transport.current(request, signal),
|
|
135
|
+
decodeCurrentView,
|
|
136
|
+
);
|
|
137
|
+
return reply.kind === "ok" &&
|
|
138
|
+
canonicalJson(reply.value.request) !== canonicalJson(request)
|
|
139
|
+
? unavailable(false)
|
|
140
|
+
: reply;
|
|
141
|
+
} catch {
|
|
142
|
+
return unavailable(false);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async currentChanges(
|
|
146
|
+
input: CurrentRequest,
|
|
147
|
+
signal?: AbortSignal,
|
|
148
|
+
): Promise<Reply<CurrentChanges>> {
|
|
149
|
+
const request = decodeCurrentChangesRequest(input);
|
|
150
|
+
try {
|
|
151
|
+
if (!this.transport.currentChanges) return unavailable(false);
|
|
152
|
+
const reply = decodeReply(
|
|
153
|
+
await this.transport.currentChanges(request, signal),
|
|
154
|
+
decodeCurrentChanges,
|
|
155
|
+
);
|
|
156
|
+
return reply.kind === "ok" &&
|
|
157
|
+
canonicalJson(reply.value.request) !== canonicalJson(request)
|
|
158
|
+
? unavailable(false)
|
|
159
|
+
: reply;
|
|
160
|
+
} catch {
|
|
161
|
+
return unavailable(false);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async activeRuns(signal?: AbortSignal): Promise<Reply<ActiveRuns>> {
|
|
165
|
+
try {
|
|
166
|
+
if (!this.transport.activeRuns) return unavailable(false);
|
|
167
|
+
return decodeReply(
|
|
168
|
+
await this.transport.activeRuns(signal),
|
|
169
|
+
decodeActiveRuns,
|
|
170
|
+
);
|
|
171
|
+
} catch {
|
|
172
|
+
return unavailable(false);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
async models(signal?: AbortSignal): Promise<Reply<ModelCatalog>> {
|
|
176
|
+
try {
|
|
177
|
+
if (!this.transport.models) return unavailable(false);
|
|
178
|
+
return decodeReply(
|
|
179
|
+
await this.transport.models(signal),
|
|
180
|
+
decodeModelCatalog,
|
|
181
|
+
);
|
|
182
|
+
} catch {
|
|
183
|
+
return unavailable(false);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
async chooseModel(
|
|
187
|
+
input: ChooseModelRequest,
|
|
188
|
+
): Promise<Reply<ModelChoiceState>> {
|
|
189
|
+
const request = decodeChooseModelRequest(input);
|
|
190
|
+
try {
|
|
191
|
+
if (!this.transport.chooseModel) return unavailable(false);
|
|
192
|
+
const reply = decodeReply(
|
|
193
|
+
await this.transport.chooseModel(request),
|
|
194
|
+
decodeModelChoiceState,
|
|
195
|
+
);
|
|
196
|
+
if (reply.kind === "ok") {
|
|
197
|
+
const { sourceSelectionId: _id, ...selector } =
|
|
198
|
+
reply.value.selected ?? {};
|
|
199
|
+
if (
|
|
200
|
+
canonicalJson(selector) !== canonicalJson(request.choice) ||
|
|
201
|
+
reply.value.version.epoch !== request.expected.epoch ||
|
|
202
|
+
reply.value.version.accessGeneration !==
|
|
203
|
+
request.expected.accessGeneration ||
|
|
204
|
+
![
|
|
205
|
+
request.expected.configRev,
|
|
206
|
+
request.expected.configRev + 1,
|
|
207
|
+
].includes(reply.value.version.configRev) ||
|
|
208
|
+
(reply.value.version.configRev === request.expected.configRev) !==
|
|
209
|
+
(reply.value.version.catalogId === request.expected.catalogId)
|
|
210
|
+
)
|
|
211
|
+
return unavailable(true);
|
|
212
|
+
}
|
|
213
|
+
return reply;
|
|
214
|
+
} catch {
|
|
215
|
+
return unavailable(true);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async checkObligations(
|
|
219
|
+
taskId: string,
|
|
220
|
+
signal?: AbortSignal,
|
|
221
|
+
): Promise<Reply<CheckObligations>> {
|
|
222
|
+
decodeId(taskId);
|
|
223
|
+
try {
|
|
224
|
+
const reply = decodeReply(
|
|
225
|
+
await this.transport.checkObligations(taskId, signal),
|
|
226
|
+
decodeCheckObligations,
|
|
227
|
+
);
|
|
228
|
+
return reply.kind === "ok" && reply.value.taskId !== taskId
|
|
229
|
+
? unavailable(false)
|
|
230
|
+
: reply;
|
|
231
|
+
} catch {
|
|
232
|
+
return unavailable(false);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
task(
|
|
236
|
+
input: Omit<EntityReadRequest, "kind">,
|
|
237
|
+
signal?: AbortSignal,
|
|
238
|
+
): Promise<Reply<EntityReadResult>> {
|
|
239
|
+
return this.entity("task", input, signal);
|
|
240
|
+
}
|
|
241
|
+
message(
|
|
242
|
+
input: Omit<EntityReadRequest, "kind">,
|
|
243
|
+
signal?: AbortSignal,
|
|
244
|
+
): Promise<Reply<EntityReadResult>> {
|
|
245
|
+
return this.entity("message", input, signal);
|
|
246
|
+
}
|
|
247
|
+
tool(
|
|
248
|
+
input: Omit<EntityReadRequest, "kind">,
|
|
249
|
+
signal?: AbortSignal,
|
|
250
|
+
): Promise<Reply<EntityReadResult>> {
|
|
251
|
+
return this.entity("tool", input, signal);
|
|
252
|
+
}
|
|
253
|
+
private async entity(
|
|
254
|
+
kind: EntityReadRequest["kind"],
|
|
255
|
+
input: Omit<EntityReadRequest, "kind">,
|
|
256
|
+
signal?: AbortSignal,
|
|
257
|
+
): Promise<Reply<EntityReadResult>> {
|
|
258
|
+
const request = decodeEntityReadRequest({ ...input, kind });
|
|
259
|
+
try {
|
|
260
|
+
const reply = decodeReply(
|
|
261
|
+
await this.transport.entity(request, signal),
|
|
262
|
+
decodeEntityReadResult,
|
|
263
|
+
);
|
|
264
|
+
return reply.kind === "ok" &&
|
|
265
|
+
canonicalJson(reply.value.request) !== canonicalJson(request)
|
|
266
|
+
? unavailable(false)
|
|
267
|
+
: reply;
|
|
268
|
+
} catch {
|
|
269
|
+
return unavailable(false);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async session(signal?: AbortSignal): Promise<Reply<SessionBootstrap>> {
|
|
273
|
+
try {
|
|
274
|
+
return decodeReply(
|
|
275
|
+
await this.transport.session(signal),
|
|
276
|
+
decodeSessionBootstrap,
|
|
277
|
+
);
|
|
278
|
+
} catch {
|
|
279
|
+
return unavailable(false);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async workspace(signal?: AbortSignal): Promise<Reply<WorkspaceBootstrap>> {
|
|
283
|
+
try {
|
|
284
|
+
return decodeReply(
|
|
285
|
+
await this.transport.workspace(signal),
|
|
286
|
+
decodeWorkspaceBootstrap,
|
|
287
|
+
);
|
|
288
|
+
} catch {
|
|
289
|
+
return unavailable(false);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
tasks(
|
|
293
|
+
request: Omit<ListRequest, "reader">,
|
|
294
|
+
signal?: AbortSignal,
|
|
295
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
296
|
+
return this.page("tasks", request, signal);
|
|
297
|
+
}
|
|
298
|
+
runs(
|
|
299
|
+
request: Omit<ListRequest, "reader">,
|
|
300
|
+
signal?: AbortSignal,
|
|
301
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
302
|
+
return this.page("runs", request, signal);
|
|
303
|
+
}
|
|
304
|
+
messages(
|
|
305
|
+
request: Omit<ListRequest, "reader">,
|
|
306
|
+
signal?: AbortSignal,
|
|
307
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
308
|
+
return this.page("messages", request, signal);
|
|
309
|
+
}
|
|
310
|
+
tools(
|
|
311
|
+
request: Omit<ListRequest, "reader">,
|
|
312
|
+
signal?: AbortSignal,
|
|
313
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
314
|
+
return this.page("tools", request, signal);
|
|
315
|
+
}
|
|
316
|
+
contents(
|
|
317
|
+
request: Omit<ListRequest, "reader">,
|
|
318
|
+
signal?: AbortSignal,
|
|
319
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
320
|
+
return this.page("contents", request, signal);
|
|
321
|
+
}
|
|
322
|
+
events(
|
|
323
|
+
request: Omit<ListRequest, "reader">,
|
|
324
|
+
signal?: AbortSignal,
|
|
325
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
326
|
+
return this.page("events", request, signal);
|
|
327
|
+
}
|
|
328
|
+
checks(
|
|
329
|
+
request: Omit<ListRequest, "reader">,
|
|
330
|
+
signal?: AbortSignal,
|
|
331
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
332
|
+
return this.page("checks", request, signal);
|
|
333
|
+
}
|
|
334
|
+
changes(
|
|
335
|
+
request: Omit<ListRequest, "reader">,
|
|
336
|
+
signal?: AbortSignal,
|
|
337
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
338
|
+
return this.page("changes", request, signal);
|
|
339
|
+
}
|
|
340
|
+
reviews(
|
|
341
|
+
request: Omit<ListRequest, "reader">,
|
|
342
|
+
signal?: AbortSignal,
|
|
343
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
344
|
+
return this.page("reviews", request, signal);
|
|
345
|
+
}
|
|
346
|
+
private async page(
|
|
347
|
+
reader: ReaderKind,
|
|
348
|
+
input: Omit<ListRequest, "reader">,
|
|
349
|
+
signal?: AbortSignal,
|
|
350
|
+
): Promise<Reply<HistoryReadResult>> {
|
|
351
|
+
const request = decodeListRequest({ ...input, reader });
|
|
352
|
+
try {
|
|
353
|
+
const reply = decodeReply(
|
|
354
|
+
await this.transport[reader](request, signal),
|
|
355
|
+
decodeHistoryReadResult,
|
|
356
|
+
);
|
|
357
|
+
if (reply.kind === "ok" && !historyReplyMatches(request, reply.value))
|
|
358
|
+
return unavailable(false);
|
|
359
|
+
return reply;
|
|
360
|
+
} catch {
|
|
361
|
+
return unavailable(false);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
async graph(
|
|
365
|
+
input: GraphReadRequest,
|
|
366
|
+
signal?: AbortSignal,
|
|
367
|
+
): Promise<Reply<GraphReadResult>> {
|
|
368
|
+
const request = decodeGraphReadRequest(input);
|
|
369
|
+
try {
|
|
370
|
+
const reply = decodeReply(
|
|
371
|
+
await this.transport.graph(request, signal),
|
|
372
|
+
decodeGraphReadResult,
|
|
373
|
+
);
|
|
374
|
+
return reply.kind === "ok" &&
|
|
375
|
+
canonicalJson(reply.value.request) !== canonicalJson(request)
|
|
376
|
+
? unavailable(false)
|
|
377
|
+
: reply;
|
|
378
|
+
} catch {
|
|
379
|
+
return unavailable(false);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
async *export(
|
|
383
|
+
input: ExportRequest,
|
|
384
|
+
signal: AbortSignal,
|
|
385
|
+
): AsyncGenerator<ExportFrame> {
|
|
386
|
+
const request = decodeExportRequest(input),
|
|
387
|
+
tracker = new ExportTracker(request);
|
|
388
|
+
let trailer: ExportFrame | undefined;
|
|
389
|
+
try {
|
|
390
|
+
if (signal.aborted) throw new ContractError("unavailable");
|
|
391
|
+
for await (const value of this.transport.export(request, signal)) {
|
|
392
|
+
if (signal.aborted) throw new ContractError("unavailable");
|
|
393
|
+
const frame = tracker.receive(value);
|
|
394
|
+
if (frame.event.kind === "trailer") trailer = frame;
|
|
395
|
+
else yield frame;
|
|
396
|
+
}
|
|
397
|
+
if (signal.aborted || !trailer) throw new ContractError("unavailable");
|
|
398
|
+
yield trailer; // only after original EOF, never synthesize a trailer
|
|
399
|
+
} catch {
|
|
400
|
+
throw new ContractError("unavailable");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
async preflight(
|
|
404
|
+
expected: ContextVersion,
|
|
405
|
+
action: Action,
|
|
406
|
+
): Promise<Reply<Preflight>> {
|
|
407
|
+
const request = decodePreflightRequest({ expected, action });
|
|
408
|
+
try {
|
|
409
|
+
const reply = decodeReply(
|
|
410
|
+
await this.transport.preflight(request),
|
|
411
|
+
decodePreflight,
|
|
412
|
+
);
|
|
413
|
+
if (
|
|
414
|
+
reply.kind === "ok" &&
|
|
415
|
+
(canonicalJson(reply.value.preview.version) !==
|
|
416
|
+
canonicalJson(request.expected) ||
|
|
417
|
+
canonicalJson(reply.value.preview.action) !==
|
|
418
|
+
canonicalJson(request.action))
|
|
419
|
+
)
|
|
420
|
+
return unavailable(false);
|
|
421
|
+
return reply;
|
|
422
|
+
} catch {
|
|
423
|
+
return unavailable(false);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
// Explicitly named methods. IDs and confirmations come from the caller; uncertainty
|
|
427
|
+
// NEVER mints a new ID, retries a command, refreshes auth or repeats preflight.
|
|
428
|
+
create(command: NamedCommand<"create">): Promise<Reply<Receipt>> {
|
|
429
|
+
return this.execute("create", command);
|
|
430
|
+
}
|
|
431
|
+
savePlan(command: NamedCommand<"save-plan">): Promise<Reply<Receipt>> {
|
|
432
|
+
return this.execute("save-plan", command);
|
|
433
|
+
}
|
|
434
|
+
generatePlan(
|
|
435
|
+
command: NamedCommand<"generate-plan">,
|
|
436
|
+
): Promise<Reply<Receipt>> {
|
|
437
|
+
return this.execute("generate-plan", command);
|
|
438
|
+
}
|
|
439
|
+
start(command: NamedCommand<"start">): Promise<Reply<Receipt>> {
|
|
440
|
+
return this.execute("start", command);
|
|
441
|
+
}
|
|
442
|
+
check(command: NamedCommand<"check">): Promise<Reply<Receipt>> {
|
|
443
|
+
return this.execute("check", command);
|
|
444
|
+
}
|
|
445
|
+
review(command: NamedCommand<"review">): Promise<Reply<Receipt>> {
|
|
446
|
+
return this.execute("review", command);
|
|
447
|
+
}
|
|
448
|
+
private async execute(
|
|
449
|
+
kind: Action["kind"],
|
|
450
|
+
input: Command,
|
|
451
|
+
): Promise<Reply<Receipt>> {
|
|
452
|
+
const command = decodeCommand(input);
|
|
453
|
+
if (command.action.kind !== kind)
|
|
454
|
+
return { kind: "error", error: publicError("invalid") };
|
|
455
|
+
try {
|
|
456
|
+
const reply = decodeReply(
|
|
457
|
+
await this.transport.command(command),
|
|
458
|
+
decodeReceipt,
|
|
459
|
+
);
|
|
460
|
+
if (reply.kind === "ok") {
|
|
461
|
+
if (reply.value.commandId !== command.commandId)
|
|
462
|
+
return unavailable(true);
|
|
463
|
+
// Reuse the admission/history correlation rules: matching commandId alone
|
|
464
|
+
// does not make a missing created task or wrong operation settlement valid.
|
|
465
|
+
decodeStoredCommand({
|
|
466
|
+
identity: {
|
|
467
|
+
kind: "action",
|
|
468
|
+
expected: command.expected,
|
|
469
|
+
action: command.action,
|
|
470
|
+
},
|
|
471
|
+
receipt: reply.value,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
return reply;
|
|
475
|
+
} catch {
|
|
476
|
+
return unavailable(true);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
async cancel(input: CancelCommand): Promise<Reply<Receipt>> {
|
|
480
|
+
const command = decodeCancel(input);
|
|
481
|
+
try {
|
|
482
|
+
const reply = decodeReply(
|
|
483
|
+
await this.transport.cancel(command),
|
|
484
|
+
decodeReceipt,
|
|
485
|
+
);
|
|
486
|
+
if (reply.kind === "ok") {
|
|
487
|
+
if (reply.value.commandId !== command.commandId)
|
|
488
|
+
return unavailable(true);
|
|
489
|
+
decodeStoredCommand({
|
|
490
|
+
identity: {
|
|
491
|
+
kind: "cancel",
|
|
492
|
+
epoch: command.epoch,
|
|
493
|
+
runId: command.runId,
|
|
494
|
+
},
|
|
495
|
+
receipt: reply.value,
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
return reply;
|
|
499
|
+
} catch {
|
|
500
|
+
return unavailable(true);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
async receipt(
|
|
504
|
+
commandId: string,
|
|
505
|
+
signal?: AbortSignal,
|
|
506
|
+
): Promise<ReceiptLookup> {
|
|
507
|
+
decodeId(commandId);
|
|
508
|
+
try {
|
|
509
|
+
const result = decodeReceiptLookup(
|
|
510
|
+
await this.transport.receipt(commandId, signal),
|
|
511
|
+
);
|
|
512
|
+
if (result.status === "found" && result.receipt.commandId !== commandId)
|
|
513
|
+
throw new Error("invalid");
|
|
514
|
+
return result;
|
|
515
|
+
} catch {
|
|
516
|
+
return {
|
|
517
|
+
status: "inconclusive",
|
|
518
|
+
error: publicError("receipt-inconclusive", "uncertain"),
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async snapshot(input: Scope, signal?: AbortSignal): Promise<Reply<Snapshot>> {
|
|
523
|
+
const scope = decodeScope(input);
|
|
524
|
+
try {
|
|
525
|
+
const reply = decodeReply(
|
|
526
|
+
await this.transport.snapshot(scope, signal),
|
|
527
|
+
decodeSnapshot,
|
|
528
|
+
);
|
|
529
|
+
if (
|
|
530
|
+
reply.kind === "ok" &&
|
|
531
|
+
canonicalJson(reply.value.scope) !== canonicalJson(scope)
|
|
532
|
+
)
|
|
533
|
+
return unavailable(false);
|
|
534
|
+
return reply;
|
|
535
|
+
} catch {
|
|
536
|
+
return unavailable(false);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
async detail(
|
|
540
|
+
input: ReadCursor,
|
|
541
|
+
signal?: AbortSignal,
|
|
542
|
+
): Promise<Reply<DetailReadResult>> {
|
|
543
|
+
const cursor = decodeCursor(input);
|
|
544
|
+
try {
|
|
545
|
+
const reply = decodeReply(
|
|
546
|
+
await this.transport.detail(cursor, signal),
|
|
547
|
+
decodeDetailReadResult,
|
|
548
|
+
);
|
|
549
|
+
if (
|
|
550
|
+
reply.kind === "ok" &&
|
|
551
|
+
canonicalJson(reply.value.cursor) !== canonicalJson(cursor)
|
|
552
|
+
)
|
|
553
|
+
return unavailable(false);
|
|
554
|
+
return reply;
|
|
555
|
+
} catch {
|
|
556
|
+
return unavailable(false);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
async search(
|
|
560
|
+
input: ReadCursor,
|
|
561
|
+
signal?: AbortSignal,
|
|
562
|
+
): Promise<Reply<SearchPage>> {
|
|
563
|
+
const cursor = decodeCursor(input);
|
|
564
|
+
try {
|
|
565
|
+
const reply = decodeReply(
|
|
566
|
+
await this.transport.search(cursor, signal),
|
|
567
|
+
decodeSearchPage,
|
|
568
|
+
);
|
|
569
|
+
if (
|
|
570
|
+
reply.kind === "ok" &&
|
|
571
|
+
canonicalJson(reply.value.cursor) !== canonicalJson(cursor)
|
|
572
|
+
)
|
|
573
|
+
return unavailable(false);
|
|
574
|
+
return reply;
|
|
575
|
+
} catch {
|
|
576
|
+
return unavailable(false);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export interface ObservationState {
|
|
582
|
+
snapshot: Snapshot;
|
|
583
|
+
connection: "current" | "stale" | "resync";
|
|
584
|
+
lastObservedMs: number;
|
|
585
|
+
}
|
|
586
|
+
/** Read-only correlation/revision reducer; never a scheduler. A new snapshot begins
|
|
587
|
+
* a new subscription generation; old socket callbacks cannot mutate the new view.
|
|
588
|
+
* Polling adapters call needsPoll every 30s even after the socket's last update.
|
|
589
|
+
*/
|
|
590
|
+
export class ProjectionTracker {
|
|
591
|
+
private generation = 0;
|
|
592
|
+
private snapshotRequest = 0;
|
|
593
|
+
private observation: ObservationState | undefined;
|
|
594
|
+
private lastSnapshotMs = 0;
|
|
595
|
+
/** Capture before the read await; pass the ticket to install. */
|
|
596
|
+
beginSnapshot(): number {
|
|
597
|
+
return ++this.snapshotRequest;
|
|
598
|
+
}
|
|
599
|
+
install(input: unknown, now: number, request: number): number | undefined {
|
|
600
|
+
if (request !== this.snapshotRequest) return undefined;
|
|
601
|
+
const snapshot = decodeSnapshot(input);
|
|
602
|
+
const previous = this.observation?.snapshot;
|
|
603
|
+
if (
|
|
604
|
+
previous &&
|
|
605
|
+
previous.storeId === snapshot.storeId &&
|
|
606
|
+
canonicalJson(previous.scope) === canonicalJson(snapshot.scope) &&
|
|
607
|
+
compareSequence(snapshot.committedSeq, previous.committedSeq) < 0
|
|
608
|
+
) {
|
|
609
|
+
this.resync();
|
|
610
|
+
return undefined;
|
|
611
|
+
}
|
|
612
|
+
this.observation = {
|
|
613
|
+
snapshot,
|
|
614
|
+
connection: "current",
|
|
615
|
+
lastObservedMs: now,
|
|
616
|
+
};
|
|
617
|
+
this.lastSnapshotMs = now;
|
|
618
|
+
return ++this.generation;
|
|
619
|
+
}
|
|
620
|
+
private resync(): "resync" {
|
|
621
|
+
if (this.observation) this.observation.connection = "resync";
|
|
622
|
+
// A response started before the gap/epoch fault cannot repair that fault,
|
|
623
|
+
// even if it happens to carry the same committed watermark.
|
|
624
|
+
this.snapshotRequest++;
|
|
625
|
+
return "resync";
|
|
626
|
+
}
|
|
627
|
+
get state(): ObservationState | undefined {
|
|
628
|
+
return this.observation && structuredClone(this.observation);
|
|
629
|
+
}
|
|
630
|
+
needsPoll(now: number): boolean {
|
|
631
|
+
return (
|
|
632
|
+
!this.observation ||
|
|
633
|
+
this.observation.connection === "resync" ||
|
|
634
|
+
now < this.lastSnapshotMs ||
|
|
635
|
+
now - this.lastSnapshotMs >= LIMITS.reconcileMs
|
|
636
|
+
);
|
|
637
|
+
}
|
|
638
|
+
tick(now: number): void {
|
|
639
|
+
const state = this.observation;
|
|
640
|
+
if (
|
|
641
|
+
state &&
|
|
642
|
+
state.connection !== "resync" &&
|
|
643
|
+
(now < state.lastObservedMs ||
|
|
644
|
+
now - state.lastObservedMs >= LIMITS.staleMs)
|
|
645
|
+
)
|
|
646
|
+
state.connection = "stale";
|
|
647
|
+
}
|
|
648
|
+
receive(
|
|
649
|
+
input: unknown,
|
|
650
|
+
generation: number,
|
|
651
|
+
now: number,
|
|
652
|
+
): "applied" | "duplicate" | "ignored" | "resync" {
|
|
653
|
+
const state = this.observation;
|
|
654
|
+
if (!state || generation !== this.generation) return "ignored";
|
|
655
|
+
if (state.connection === "resync") return "resync";
|
|
656
|
+
let event: LiveEvent;
|
|
657
|
+
try {
|
|
658
|
+
event = decodeLiveEvent(input);
|
|
659
|
+
} catch {
|
|
660
|
+
return this.resync();
|
|
661
|
+
}
|
|
662
|
+
const snapshot = state.snapshot;
|
|
663
|
+
if (
|
|
664
|
+
event.storeId !== snapshot.storeId ||
|
|
665
|
+
event.epoch !== snapshot.epoch ||
|
|
666
|
+
canonicalJson(event.scope) !== canonicalJson(snapshot.scope)
|
|
667
|
+
) {
|
|
668
|
+
return this.resync();
|
|
669
|
+
}
|
|
670
|
+
const comparison = compareSequence(
|
|
671
|
+
event.committedSeq,
|
|
672
|
+
snapshot.committedSeq,
|
|
673
|
+
);
|
|
674
|
+
if (comparison < 0) return "duplicate";
|
|
675
|
+
if (event.kind === "heartbeat") {
|
|
676
|
+
if (comparison > 0) {
|
|
677
|
+
return this.resync();
|
|
678
|
+
}
|
|
679
|
+
state.lastObservedMs = now;
|
|
680
|
+
state.connection = "current";
|
|
681
|
+
return "applied";
|
|
682
|
+
}
|
|
683
|
+
if (comparison === 0) return "duplicate";
|
|
684
|
+
if (event.previousSeq !== snapshot.committedSeq) {
|
|
685
|
+
return this.resync();
|
|
686
|
+
}
|
|
687
|
+
if (
|
|
688
|
+
controlWorkspace(event.context) !== controlWorkspace(snapshot.context) ||
|
|
689
|
+
controlTask(event.context) !== controlTask(snapshot.context) ||
|
|
690
|
+
(event.context.status === "available" &&
|
|
691
|
+
snapshot.context.status === "available" &&
|
|
692
|
+
event.context.version.controlRev < snapshot.context.version.controlRev)
|
|
693
|
+
)
|
|
694
|
+
return this.resync();
|
|
695
|
+
// One update contains ALL row changes at its committed watermark. Validate
|
|
696
|
+
// on a copy: a bad sibling cannot leave a partly applied batch behind.
|
|
697
|
+
const rows = [...snapshot.runs];
|
|
698
|
+
for (const key of event.removed) {
|
|
699
|
+
const index = rows.findIndex((r) => (r.childRunId ?? r.runId) === key);
|
|
700
|
+
if (index === -1 || rows[index].lifecycle !== "settled")
|
|
701
|
+
return this.resync();
|
|
702
|
+
rows.splice(index, 1);
|
|
703
|
+
}
|
|
704
|
+
for (const run of event.runs) {
|
|
705
|
+
const key = run.childRunId ?? run.runId;
|
|
706
|
+
const index = rows.findIndex((r) => (r.childRunId ?? r.runId) === key);
|
|
707
|
+
if (index === -1) rows.push(run);
|
|
708
|
+
else {
|
|
709
|
+
const previous = rows[index];
|
|
710
|
+
if (
|
|
711
|
+
previous.runId !== run.runId ||
|
|
712
|
+
previous.childRunId !== run.childRunId ||
|
|
713
|
+
previous.assignmentId !== run.assignmentId ||
|
|
714
|
+
canonicalJson(previous.admission) !== canonicalJson(run.admission)
|
|
715
|
+
)
|
|
716
|
+
return this.resync();
|
|
717
|
+
rows[index] = run;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (rows.length > LIMITS.maxPageEntries) return this.resync();
|
|
721
|
+
const candidate = {
|
|
722
|
+
...snapshot,
|
|
723
|
+
runs: rows,
|
|
724
|
+
context: event.context,
|
|
725
|
+
committedSeq: event.committedSeq,
|
|
726
|
+
horizon: {
|
|
727
|
+
...snapshot.horizon,
|
|
728
|
+
historicalRuns: {
|
|
729
|
+
...snapshot.horizon.historicalRuns,
|
|
730
|
+
snapshotSeq: event.committedSeq,
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
};
|
|
734
|
+
try {
|
|
735
|
+
decodeSnapshot(candidate);
|
|
736
|
+
} catch {
|
|
737
|
+
return this.resync();
|
|
738
|
+
}
|
|
739
|
+
snapshot.runs = rows;
|
|
740
|
+
snapshot.horizon = candidate.horizon;
|
|
741
|
+
snapshot.context = event.context;
|
|
742
|
+
snapshot.committedSeq = event.committedSeq;
|
|
743
|
+
state.lastObservedMs = now;
|
|
744
|
+
state.connection = "current";
|
|
745
|
+
return "applied";
|
|
746
|
+
}
|
|
747
|
+
}
|