@abelxiaoxing/cadence 1.8.4 → 2.0.1

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.
Files changed (202) hide show
  1. package/README.md +324 -117
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/agents/design-explorer.md +14 -18
  4. package/agents/diagnosis-worker.md +14 -14
  5. package/agents/implementation-worker.md +16 -17
  6. package/config/workflow-task.example.json +7 -0
  7. package/docs/remote-access.md +60 -0
  8. package/docs/reuse-and-distribution.md +44 -0
  9. package/docs/service-management.md +108 -0
  10. package/licenses/bundled-web.txt +6245 -0
  11. package/licenses/pi-web-ui-MIT.txt +21 -0
  12. package/licenses/pi-web-ui-reuse.md +22 -0
  13. package/package.json +92 -20
  14. package/src/index.ts +21 -1802
  15. package/src/native-build.ts +6 -0
  16. package/src/native-client.ts +103 -0
  17. package/src/native-export.ts +58 -0
  18. package/src/native-history.ts +359 -0
  19. package/src/operator-cli.mjs +453 -1937
  20. package/src/plan-proposal.ts +87 -0
  21. package/src/sdk-worker.mjs +549 -0
  22. package/src/service/contracts/active.ts +82 -0
  23. package/src/service/contracts/budget.ts +148 -0
  24. package/src/service/contracts/build.ts +67 -0
  25. package/src/service/contracts/capture.ts +48 -0
  26. package/src/service/contracts/core.ts +33 -0
  27. package/src/service/contracts/current.ts +261 -0
  28. package/src/service/contracts/domain.ts +68 -0
  29. package/src/service/contracts/history.ts +2245 -0
  30. package/src/service/contracts/models.ts +139 -0
  31. package/src/service/coordination.ts +862 -0
  32. package/src/service/private-files.ts +204 -0
  33. package/src/service-cli.mjs +5592 -0
  34. package/src/service-client.ts +747 -0
  35. package/src/service-contract.ts +245 -0
  36. package/src/service-host.mjs +22382 -0
  37. package/src/service-http-client.ts +425 -0
  38. package/src/service-wire.ts +372 -0
  39. package/src/task-shell.ts +1045 -0
  40. package/src/task-store.ts +479 -0
  41. package/src/task-types.ts +184 -0
  42. package/src/verification-diagnostics.ts +29 -72
  43. package/src/worker-capture.mjs +1197 -0
  44. package/src/worker-public.mjs +1753 -0
  45. package/src/worker-redaction.mjs +608 -0
  46. package/src/worker-tools.mjs +202 -0
  47. package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
  48. package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
  49. package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
  50. package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
  51. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
  52. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
  53. package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
  54. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
  55. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
  56. package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
  57. package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
  58. package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
  59. package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
  60. package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
  61. package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
  62. package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
  63. package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
  64. package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
  65. package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
  66. package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
  67. package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
  68. package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
  69. package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
  70. package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
  71. package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
  72. package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
  73. package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
  74. package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
  75. package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
  76. package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
  77. package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
  78. package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
  79. package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
  80. package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
  81. package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
  82. package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
  83. package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
  84. package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
  85. package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
  86. package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
  87. package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
  88. package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
  89. package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
  90. package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
  91. package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
  92. package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
  93. package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
  94. package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
  95. package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
  96. package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
  97. package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
  98. package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
  99. package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
  100. package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
  101. package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
  102. package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
  103. package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
  104. package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
  105. package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
  106. package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
  107. package/web/dist/assets/cadence.css +2 -0
  108. package/web/dist/assets/cadence.js +7 -0
  109. package/web/dist/assets/markdown.js +296 -0
  110. package/web/dist/assets/react.js +9 -0
  111. package/web/dist/assets/rolldown-runtime.js +1 -0
  112. package/web/dist/assets/timeline-client.js +41 -0
  113. package/web/dist/assets/vis-timeline.css +1274 -0
  114. package/web/dist/assets/vis-timeline.js +32 -0
  115. package/web/dist/index.html +18 -0
  116. package/web/dist/manifest.json +505 -0
  117. package/config/plan-draft.example.json +0 -125
  118. package/config/plan-draft.multiple-tasks.example.json +0 -375
  119. package/config/plan-draft.quick.example.json +0 -78
  120. package/prompts/abel-design.md +0 -382
  121. package/prompts/abel-diagnose.md +0 -71
  122. package/prompts/abel-implement.md +0 -284
  123. package/prompts/abel-init.md +0 -52
  124. package/src/activation.ts +0 -44
  125. package/src/activity-contracts.ts +0 -82
  126. package/src/agent-registry.ts +0 -53
  127. package/src/apply-transaction.ts +0 -1437
  128. package/src/artifact-store.ts +0 -213
  129. package/src/build-windows-job.mjs +0 -95
  130. package/src/candidate-artifact.ts +0 -143
  131. package/src/candidate-context.ts +0 -289
  132. package/src/candidate-patch.ts +0 -271
  133. package/src/candidate-workspace.ts +0 -80
  134. package/src/canonical.ts +0 -16
  135. package/src/change-contract-schema.ts +0 -191
  136. package/src/change-contract.ts +0 -324
  137. package/src/change-verification.ts +0 -1617
  138. package/src/contracts.ts +0 -2466
  139. package/src/control-contracts.ts +0 -382
  140. package/src/delivery-compiler.ts +0 -1805
  141. package/src/delivery-revision.ts +0 -42
  142. package/src/design-control.ts +0 -1299
  143. package/src/design-diagnostics.ts +0 -181
  144. package/src/design-journal.ts +0 -1773
  145. package/src/directory-sync.ts +0 -36
  146. package/src/durable-contracts.ts +0 -227
  147. package/src/durable-workflow.ts +0 -822
  148. package/src/evidence-draft.ts +0 -122
  149. package/src/execution-profile.ts +0 -64
  150. package/src/execution-retention.ts +0 -77
  151. package/src/file-snapshot.ts +0 -163
  152. package/src/implement-continuation.ts +0 -559
  153. package/src/implement-graph.ts +0 -690
  154. package/src/implement-plan.ts +0 -72
  155. package/src/install-config.d.mts +0 -6
  156. package/src/isolation-backend.ts +0 -353
  157. package/src/model-source.ts +0 -22
  158. package/src/openspec-cli.ts +0 -494
  159. package/src/operator-cli-entry.mjs +0 -24
  160. package/src/operator-tools.ts +0 -309
  161. package/src/package-candidate-process.ts +0 -206
  162. package/src/package-candidate.ts +0 -24
  163. package/src/package-delivery.ts +0 -486
  164. package/src/package-state.ts +0 -320
  165. package/src/package-verification.ts +0 -635
  166. package/src/package-workflow.ts +0 -305
  167. package/src/packet-runtime.ts +0 -459
  168. package/src/phase-execution.ts +0 -2163
  169. package/src/pi-adapter.ts +0 -19
  170. package/src/plan-draft-summary.ts +0 -527
  171. package/src/plan-draft.ts +0 -502
  172. package/src/remove-path.ts +0 -32
  173. package/src/run-state.ts +0 -420
  174. package/src/run-store.ts +0 -1179
  175. package/src/safe-path.ts +0 -77
  176. package/src/scoped-grep-worker.mjs +0 -23
  177. package/src/scoped-tools.ts +0 -775
  178. package/src/single-task-draft.ts +0 -142
  179. package/src/sqlite-schema.ts +0 -171
  180. package/src/state-root.ts +0 -215
  181. package/src/storage-schema.ts +0 -360
  182. package/src/subagent-activity.ts +0 -1417
  183. package/src/subagent-process.ts +0 -476
  184. package/src/task-ledger.ts +0 -1338
  185. package/src/transport-budget.ts +0 -50
  186. package/src/verification-capability.ts +0 -1191
  187. package/src/verification-environment-io.ts +0 -389
  188. package/src/verification-environment.ts +0 -162
  189. package/src/verification-identity.ts +0 -77
  190. package/src/verification-scan.ts +0 -64
  191. package/src/windows-job-backend.ts +0 -419
  192. package/src/windows-job.c +0 -149
  193. package/src/workflow-engine.ts +0 -28
  194. package/src/workflow-policy.ts +0 -1670
  195. package/src/workflow-recovery-policy.ts +0 -97
  196. package/src/workflow-scheduling.ts +0 -105
  197. package/src/workflow-state-machine.ts +0 -4341
  198. package/src/workflow-status.ts +0 -576
  199. package/src/workspace-io-entry.mjs +0 -76
  200. package/src/workspace-io-worker.mjs +0 -1312
  201. package/src/workspace-io.ts +0 -89
  202. package/src/workspace-store.ts +0 -634
@@ -0,0 +1,82 @@
1
+ /** Bounded current original-work roster, separate from historical run reduction. */
2
+ import {
3
+ canonicalJson,
4
+ closed,
5
+ decodeId,
6
+ decodePublicError,
7
+ invalid,
8
+ LIMITS,
9
+ list,
10
+ literal,
11
+ oneOf,
12
+ type PublicError,
13
+ } from "./core.ts";
14
+ export interface ActiveRunRef {
15
+ taskId: string;
16
+ runId: string;
17
+ operationId: string;
18
+ epoch: string;
19
+ kind: "start" | "generate-plan" | "check";
20
+ stage: "accepted-unallocated" | "active" | "draining";
21
+ }
22
+ export type ActiveRuns = {
23
+ storeId: string;
24
+ workspaceId: string;
25
+ epoch: string;
26
+ } & (
27
+ | { status: "complete"; runs: ActiveRunRef[] }
28
+ | { status: "unavailable"; error: PublicError }
29
+ );
30
+ export function decodeActiveRuns(v: unknown): ActiveRuns {
31
+ canonicalJson({ kind: "ok", value: v }, LIMITS.pageBytes);
32
+ const complete =
33
+ Object.getOwnPropertyDescriptor(v ?? {}, "status")?.value === "complete";
34
+ const o = closed(v, [
35
+ "storeId",
36
+ "workspaceId",
37
+ "epoch",
38
+ "status",
39
+ complete ? "runs" : "error",
40
+ ]);
41
+ const base = {
42
+ storeId: decodeId(o.storeId),
43
+ workspaceId: decodeId(o.workspaceId),
44
+ epoch: decodeId(o.epoch),
45
+ };
46
+ if (!complete) {
47
+ literal(o.status, "unavailable");
48
+ return { ...base, status: "unavailable", error: noEffect(o.error) };
49
+ }
50
+ const runs = list(o.runs, LIMITS.episodes, (v): ActiveRunRef => {
51
+ const r = closed(v, [
52
+ "taskId",
53
+ "runId",
54
+ "operationId",
55
+ "epoch",
56
+ "kind",
57
+ "stage",
58
+ ]);
59
+ return {
60
+ taskId: decodeId(r.taskId),
61
+ runId: decodeId(r.runId),
62
+ operationId: decodeId(r.operationId),
63
+ epoch: decodeId(r.epoch),
64
+ kind: oneOf(r.kind, ["start", "generate-plan", "check"]),
65
+ stage: oneOf(r.stage, ["accepted-unallocated", "active", "draining"]),
66
+ };
67
+ });
68
+ if (
69
+ runs.some((r) => r.epoch !== base.epoch) ||
70
+ new Set(runs.map((r) => r.runId)).size !== runs.length ||
71
+ new Set(runs.map((r) => r.taskId)).size !== runs.length ||
72
+ new Set(runs.map((r) => r.operationId)).size !== runs.length
73
+ )
74
+ invalid();
75
+ return { ...base, status: "complete", runs };
76
+ }
77
+
78
+ function noEffect(v: unknown): PublicError {
79
+ const error = decodePublicError(v);
80
+ literal(error.effect, "none");
81
+ return error;
82
+ }
@@ -0,0 +1,148 @@
1
+ import {
2
+ type CaptureBudget,
3
+ decodeCaptureBudget,
4
+ decodeRecordingInput,
5
+ type PublicRecordingInput,
6
+ } from "./capture.ts";
7
+ import { ContractError, canonicalJson, LIMITS, utf8Bytes } from "./core.ts";
8
+ import {
9
+ decodeOwnerRecordingInput,
10
+ type OwnerRecordingInput,
11
+ } from "./history.ts";
12
+
13
+ /** Resource accounting only: no persistence, accepting sink, scheduler or timer.
14
+ * One instance per W3 child/owner ingress. The caller must reserve BEFORE copying
15
+ * source values. Bytes mean encoded-data/retention budgets, not total JS heap.
16
+ */
17
+ export class CaptureBudgetPool {
18
+ private leases = new Set<CaptureBudgetLease>();
19
+ reserve(input: CaptureBudget): CaptureBudgetLease {
20
+ const budget = decodeCaptureBudget(input);
21
+ const lease = new CaptureBudgetLease(
22
+ (next) => this.check(lease, next),
23
+ () => {
24
+ this.leases.delete(lease);
25
+ },
26
+ budget,
27
+ );
28
+ this.check(lease, budget);
29
+ this.leases.add(lease);
30
+ return lease;
31
+ }
32
+ get accounting(): {
33
+ leases: number;
34
+ bytes: number;
35
+ sourceFrames: number;
36
+ outputChunks: number;
37
+ } {
38
+ const values = [...this.leases].map((l) => l.budget);
39
+ return {
40
+ leases: values.length,
41
+ bytes: values.reduce((n, b) => n + b.retainedBytes + b.outputBytes, 0),
42
+ sourceFrames: values.reduce((n, b) => n + b.sourceFrames, 0),
43
+ outputChunks: values.reduce((n, b) => n + b.outputChunks, 0),
44
+ };
45
+ }
46
+ /** Internal lease update: replacement is checked before any accounting mutation. */
47
+ private check(lease: CaptureBudgetLease, budget: CaptureBudget): void {
48
+ const values = [...this.leases]
49
+ .filter((l) => l !== lease)
50
+ .map((l) => l.budget)
51
+ .concat(budget);
52
+ const fits = (items: CaptureBudget[], bytes: number, frames: number) =>
53
+ items.reduce((n, b) => n + b.retainedBytes + b.outputBytes, 0) <= bytes &&
54
+ // Source and transformed events share the SAME frame ceiling while both
55
+ // are retained. A prefix-only/empty lease still occupies one slot.
56
+ items.reduce(
57
+ (n, b) => n + Math.max(1, b.sourceFrames + b.outputChunks),
58
+ 0,
59
+ ) <= frames;
60
+ if (
61
+ !fits(values, LIMITS.ownerQueueBytes, LIMITS.ownerQueueFrames) ||
62
+ !fits(
63
+ values.filter((b) => b.lane === "data"),
64
+ LIMITS.ownerQueueBytes - LIMITS.ownerControlBytes,
65
+ LIMITS.ownerQueueFrames - LIMITS.ownerControlFrames,
66
+ )
67
+ )
68
+ throw new ContractError("capacity");
69
+ }
70
+ }
71
+ class CaptureBudgetLease {
72
+ private state: "reserved" | "in-flight" | "released" = "reserved";
73
+ constructor(
74
+ private readonly resize: (budget: CaptureBudget) => void,
75
+ private readonly forget: () => void,
76
+ private value: CaptureBudget,
77
+ ) {}
78
+ get budget(): CaptureBudget {
79
+ return { ...this.value };
80
+ }
81
+ grow(input: CaptureBudget): void {
82
+ if (this.state !== "reserved") throw new ContractError("conflict");
83
+ const extra = decodeCaptureBudget(input);
84
+ if (extra.lane !== this.value.lane) throw new ContractError("invalid");
85
+ const next = decodeCaptureBudget({
86
+ lane: extra.lane,
87
+ sourceFrames: extra.sourceFrames + this.value.sourceFrames,
88
+ retainedBytes: extra.retainedBytes + this.value.retainedBytes,
89
+ outputBytes: extra.outputBytes + this.value.outputBytes,
90
+ outputChunks: extra.outputChunks + this.value.outputChunks,
91
+ });
92
+ this.resize(next);
93
+ this.value = next;
94
+ }
95
+ beginWorker(input: PublicRecordingInput): PublicRecordingInput {
96
+ if (this.state !== "reserved") throw new ContractError("conflict");
97
+ this.size(input);
98
+ const value = decodeRecordingInput(input);
99
+ this.chunks(value.events.length);
100
+ if (
101
+ this.value.lane === "control" &&
102
+ value.events.some(
103
+ (e) =>
104
+ !["ready", "capture-status", "worker-failure", "final"].includes(
105
+ e.event.kind,
106
+ ),
107
+ )
108
+ )
109
+ throw new ContractError("invalid");
110
+ this.state = "in-flight";
111
+ return value;
112
+ }
113
+ beginOwner(input: OwnerRecordingInput): OwnerRecordingInput {
114
+ if (this.state !== "reserved") throw new ContractError("conflict");
115
+ this.size(input);
116
+ const value = decodeOwnerRecordingInput(input);
117
+ this.chunks(value.events.length);
118
+ if (
119
+ this.value.sourceFrames !== 0 ||
120
+ (this.value.lane === "control" &&
121
+ value.events.some((e) => e.kind !== "fact"))
122
+ )
123
+ throw new ContractError("invalid");
124
+ this.state = "in-flight";
125
+ return value;
126
+ }
127
+ private size(input: unknown): void {
128
+ // No unreserved decoded copy is retained: check encoded output ceiling first.
129
+ if (
130
+ utf8Bytes(canonicalJson(input, this.value.outputBytes)) >
131
+ this.value.outputBytes
132
+ )
133
+ throw new ContractError("capacity");
134
+ }
135
+ private chunks(count: number): void {
136
+ if (count > this.value.outputChunks) throw new ContractError("capacity");
137
+ }
138
+ release(): void {
139
+ if (this.state !== "reserved") throw new ContractError("conflict");
140
+ this.state = "released";
141
+ this.forget();
142
+ }
143
+ settled(): void {
144
+ if (this.state !== "in-flight") throw new ContractError("conflict");
145
+ this.state = "released";
146
+ this.forget();
147
+ }
148
+ }
@@ -0,0 +1,67 @@
1
+ /** Compatibility is independent of authentication and of task confirmation. */
2
+ import { closed, decodeHash, oneOf } from "./core.ts";
3
+ export interface BrowserBuild {
4
+ sourceHash: string;
5
+ contractHash: string;
6
+ buildId: string;
7
+ }
8
+ export type ClientBuild =
9
+ | { kind: "native"; contractHash: string }
10
+ | ({ kind: "browser" } & BrowserBuild);
11
+ export interface ServiceBuild {
12
+ contractHash: string;
13
+ assets: BrowserBuild;
14
+ }
15
+ export function decodeBrowserBuild(value: unknown): BrowserBuild {
16
+ const o = closed(value, ["sourceHash", "contractHash", "buildId"]);
17
+ return {
18
+ sourceHash: decodeHash(o.sourceHash),
19
+ contractHash: decodeHash(o.contractHash),
20
+ buildId: decodeHash(o.buildId),
21
+ };
22
+ }
23
+ export function decodeClientBuild(value: unknown): ClientBuild {
24
+ const kind = oneOf(
25
+ Object.getOwnPropertyDescriptor(value ?? {}, "kind")?.value,
26
+ ["native", "browser"],
27
+ );
28
+ const o = closed(
29
+ value,
30
+ kind === "native"
31
+ ? ["kind", "contractHash"]
32
+ : ["kind", "contractHash", "sourceHash", "buildId"],
33
+ );
34
+ return kind === "native"
35
+ ? { kind, contractHash: decodeHash(o.contractHash) }
36
+ : {
37
+ kind,
38
+ ...decodeBrowserBuild({
39
+ contractHash: o.contractHash,
40
+ sourceHash: o.sourceHash,
41
+ buildId: o.buildId,
42
+ }),
43
+ };
44
+ }
45
+ export function decodeServiceBuild(value: unknown): ServiceBuild {
46
+ const o = closed(value, ["contractHash", "assets"]);
47
+ return {
48
+ contractHash: decodeHash(o.contractHash),
49
+ assets: decodeBrowserBuild(o.assets),
50
+ };
51
+ }
52
+ export function compatibleBuild(
53
+ server: ServiceBuild | undefined,
54
+ client: ClientBuild | null,
55
+ safety = false,
56
+ ): boolean {
57
+ return (
58
+ !!server &&
59
+ !!client &&
60
+ client.contractHash === server.contractHash &&
61
+ (safety ||
62
+ (server.assets.contractHash === server.contractHash &&
63
+ (client.kind === "native" ||
64
+ (client.buildId === server.assets.buildId &&
65
+ client.sourceHash === server.assets.sourceHash))))
66
+ );
67
+ }
@@ -0,0 +1,48 @@
1
+ /** Compatibility import path only; worker-public.mjs owns the executable codec and declarations. */
2
+ export {
3
+ advanceCapture,
4
+ type CallDeclarationLink,
5
+ type CaptureBudget,
6
+ type CaptureEvent,
7
+ type CaptureFrame,
8
+ type CapturePosition,
9
+ type CheckNativeSettlement,
10
+ type CommittedBatch,
11
+ type ContentOwner,
12
+ callLink,
13
+ childSatisfied,
14
+ type DetailCommit,
15
+ type DetailDescriptor,
16
+ decodeCaptureBudget,
17
+ decodeCaptureEvent,
18
+ decodeCaptureFrame,
19
+ decodeCheckNativeSettlement,
20
+ decodeCommittedBatch,
21
+ decodeContentOwner,
22
+ decodeDetailCommit,
23
+ decodeDetailDescriptor,
24
+ decodeFinalRecording,
25
+ decodeFinalSelection,
26
+ decodeOmittedBlock,
27
+ decodeRecordingEvent,
28
+ decodeRecordingInput,
29
+ decodeRecordingLink,
30
+ decodeRunSettlement,
31
+ decodeSourceIdentity,
32
+ decodeSourceRange,
33
+ decodeWorkerCompletion,
34
+ type FinalRecording,
35
+ type FinalSelection,
36
+ type OmittedBlock,
37
+ type OwnerDetailCommit,
38
+ type PublicRecordingInput,
39
+ type RecordingEvent,
40
+ type RecordingLink,
41
+ type RequiredChildSettlement,
42
+ type RunSettlement,
43
+ type SanitizedCaptureEvent,
44
+ type SourceIdentity,
45
+ type SourceRange,
46
+ settlementOutcome,
47
+ type WorkerCompletion,
48
+ } from "../../worker-public.mjs";
@@ -0,0 +1,33 @@
1
+ /** Compatibility import path only; worker-public.mjs owns the executable codec and declarations. */
2
+ export {
3
+ assignmentId,
4
+ bool,
5
+ ContractError,
6
+ canonicalJson,
7
+ closed,
8
+ compareSequence,
9
+ decodeHash,
10
+ decodeId,
11
+ decodePublicError,
12
+ decodeSequence,
13
+ ERROR_CODES,
14
+ type ErrorCode,
15
+ EXPORT_SCHEMA,
16
+ errorStatus,
17
+ GRAPH_SCHEMA,
18
+ HISTORY_SCHEMA,
19
+ integer,
20
+ invalid,
21
+ LIMITS,
22
+ list,
23
+ literal,
24
+ nullable,
25
+ oneOf,
26
+ type PublicError,
27
+ parseWireJson,
28
+ publicError,
29
+ SERVICE_PROTOCOL,
30
+ text,
31
+ utf8Bytes,
32
+ WORKER_PROTOCOL,
33
+ } from "../../worker-public.mjs";
@@ -0,0 +1,261 @@
1
+ /** Current owner observations, never retained-content or execution authority by inference. */
2
+
3
+ import { role } from "../../worker-public.mjs";
4
+ import {
5
+ bool,
6
+ canonicalJson,
7
+ closed,
8
+ decodeHash,
9
+ decodeId,
10
+ decodePublicError,
11
+ decodeSequence,
12
+ integer,
13
+ invalid,
14
+ LIMITS,
15
+ list,
16
+ literal,
17
+ nullable,
18
+ oneOf,
19
+ type PublicError,
20
+ text,
21
+ } from "./core.ts";
22
+ import {
23
+ type CaptureCoverage,
24
+ decodeCoverage,
25
+ type RoleSelection,
26
+ type TaskKind,
27
+ } from "./domain.ts";
28
+ import {
29
+ type ControlContext,
30
+ controlTask,
31
+ controlWorkspace,
32
+ decodeControlContext,
33
+ decodeGraphReadRequest,
34
+ type GraphReadRequest,
35
+ type ObservationFact,
36
+ } from "./history.ts";
37
+
38
+ export interface CurrentRequest {
39
+ storeId: string;
40
+ taskId: string | null;
41
+ }
42
+ export interface CurrentTask {
43
+ id: string;
44
+ kind: TaskKind;
45
+ revision: number;
46
+ identity: string;
47
+ }
48
+ export type SavedGraphSelection =
49
+ | { status: "none" }
50
+ | { status: "saved"; request: GraphReadRequest; planRevision: number }
51
+ | { status: "unavailable"; error: PublicError };
52
+ export interface CurrentView {
53
+ request: CurrentRequest;
54
+ workspaceId: string;
55
+ epoch: string;
56
+ committedSeq: string;
57
+ context: ControlContext;
58
+ task: CurrentTask | null;
59
+ roles: RoleSelection[];
60
+ readablePlan: null | {
61
+ source: "current-v1";
62
+ text: string;
63
+ editable: boolean;
64
+ coverage: CaptureCoverage;
65
+ };
66
+ savedGraph: SavedGraphSelection;
67
+ }
68
+ export interface CurrentChanges {
69
+ request: CurrentRequest;
70
+ workspaceId: string;
71
+ epoch: string;
72
+ committedSeq: string;
73
+ context: ControlContext;
74
+ task: CurrentTask;
75
+ observation: ObservationFact;
76
+ text: string;
77
+ git: boolean;
78
+ coverage: CaptureCoverage;
79
+ }
80
+ const noEffect = (v: unknown) => {
81
+ const error = decodePublicError(v);
82
+ literal(error.effect, "none");
83
+ return error;
84
+ };
85
+ export function decodeCurrentRequest(v: unknown): CurrentRequest {
86
+ const o = closed(v, ["storeId", "taskId"]);
87
+ return { storeId: decodeId(o.storeId), taskId: nullable(o.taskId, decodeId) };
88
+ }
89
+ export function decodeCurrentChangesRequest(v: unknown): CurrentRequest {
90
+ const request = decodeCurrentRequest(v);
91
+ if (request.taskId === null) invalid();
92
+ return request;
93
+ }
94
+ function currentTask(v: unknown): CurrentTask {
95
+ const o = closed(v, ["id", "kind", "revision", "identity"]);
96
+ return {
97
+ id: decodeId(o.id),
98
+ kind: oneOf(o.kind, ["code", "research", "diagnosis"]),
99
+ revision: integer(o.revision, 1),
100
+ identity: decodeHash(o.identity),
101
+ };
102
+ }
103
+ export function decodeCurrentRoles(v: unknown): RoleSelection[] {
104
+ const roles = list(v, 3, role);
105
+ if (roles.length !== 3 || new Set(roles.map((r) => r.role)).size !== 3)
106
+ invalid();
107
+ return roles;
108
+ }
109
+ function savedGraph(v: unknown): SavedGraphSelection {
110
+ const status = Object.getOwnPropertyDescriptor(v ?? {}, "status")?.value;
111
+ if (status === "none") {
112
+ closed(v, ["status"]);
113
+ return { status };
114
+ }
115
+ if (status === "saved") {
116
+ const o = closed(v, ["status", "request", "planRevision"]);
117
+ return {
118
+ status,
119
+ request: decodeGraphReadRequest(o.request),
120
+ planRevision: integer(o.planRevision, 1),
121
+ };
122
+ }
123
+ const o = closed(v, ["status", "error"]);
124
+ literal(o.status, "unavailable");
125
+ return { status: "unavailable", error: noEffect(o.error) };
126
+ }
127
+ function correlate(v: {
128
+ request: CurrentRequest;
129
+ workspaceId: string;
130
+ epoch: string;
131
+ context: ControlContext;
132
+ task: CurrentTask | null;
133
+ }) {
134
+ if (
135
+ v.request.taskId !== (v.task?.id ?? null) ||
136
+ controlWorkspace(v.context) !== v.workspaceId ||
137
+ controlTask(v.context) !== v.request.taskId
138
+ )
139
+ invalid();
140
+ if (v.context.status === "available") {
141
+ const c = v.context.version;
142
+ if (
143
+ c.epoch !== v.epoch ||
144
+ !!c.task !== !!v.task ||
145
+ (v.task &&
146
+ (c.task?.revision !== v.task.revision ||
147
+ c.task.identity !== v.task.identity ||
148
+ c.task.kind !== v.task.kind))
149
+ )
150
+ invalid();
151
+ }
152
+ }
153
+ export function decodeCurrentView(v: unknown): CurrentView {
154
+ canonicalJson({ kind: "ok", value: v }, LIMITS.pageBytes);
155
+ const o = closed(v, [
156
+ "request",
157
+ "workspaceId",
158
+ "epoch",
159
+ "committedSeq",
160
+ "context",
161
+ "task",
162
+ "roles",
163
+ "readablePlan",
164
+ "savedGraph",
165
+ ]);
166
+ const result: CurrentView = {
167
+ request: decodeCurrentRequest(o.request),
168
+ workspaceId: decodeId(o.workspaceId),
169
+ epoch: decodeId(o.epoch),
170
+ committedSeq: decodeSequence(o.committedSeq),
171
+ context: decodeControlContext(o.context),
172
+ task: nullable(o.task, currentTask),
173
+ roles: decodeCurrentRoles(o.roles),
174
+ savedGraph: savedGraph(o.savedGraph),
175
+ readablePlan: nullable(o.readablePlan, (v) => {
176
+ const p = closed(v, ["source", "text", "editable", "coverage"]);
177
+ const coverage = decodeCoverage(p.coverage),
178
+ editable = bool(p.editable);
179
+ if (
180
+ editable &&
181
+ (coverage.redacted ||
182
+ coverage.observed !== "complete" ||
183
+ coverage.source !== "complete" ||
184
+ coverage.omissions.length)
185
+ )
186
+ invalid();
187
+ return {
188
+ source: literal(p.source, "current-v1"),
189
+ text: text(p.text, 32768),
190
+ editable,
191
+ coverage,
192
+ };
193
+ }),
194
+ };
195
+ correlate(result);
196
+ if (!!result.task !== !!result.readablePlan) invalid();
197
+ const saved = result.savedGraph;
198
+ if (
199
+ saved.status === "saved" &&
200
+ (saved.request.storeId !== result.request.storeId ||
201
+ saved.request.scope.kind !== "task" ||
202
+ saved.request.scope.id !== result.task?.id ||
203
+ saved.request.snapshotSeq !== result.committedSeq ||
204
+ (result.context.status === "available" &&
205
+ (saved.request.graph.sha256 !==
206
+ result.context.version.task?.graphIdentity ||
207
+ saved.request.graph.revision !==
208
+ result.context.version.task?.graphRevision)))
209
+ )
210
+ invalid();
211
+ if (saved.status === "unavailable" && result.context.status === "available")
212
+ invalid();
213
+ return result;
214
+ }
215
+ export function decodeCurrentChanges(v: unknown): CurrentChanges {
216
+ canonicalJson({ kind: "ok", value: v }, LIMITS.pageBytes);
217
+ const o = closed(v, [
218
+ "request",
219
+ "workspaceId",
220
+ "epoch",
221
+ "committedSeq",
222
+ "context",
223
+ "task",
224
+ "observation",
225
+ "text",
226
+ "git",
227
+ "coverage",
228
+ ]);
229
+ const f = closed(o.observation, [
230
+ "identity",
231
+ "complete",
232
+ "checkoutGeneration",
233
+ ]);
234
+ const result: CurrentChanges = {
235
+ request: decodeCurrentChangesRequest(o.request),
236
+ workspaceId: decodeId(o.workspaceId),
237
+ epoch: decodeId(o.epoch),
238
+ committedSeq: decodeSequence(o.committedSeq),
239
+ context: decodeControlContext(o.context),
240
+ task: currentTask(o.task),
241
+ observation: {
242
+ identity: decodeHash(f.identity),
243
+ complete: bool(f.complete),
244
+ checkoutGeneration: integer(f.checkoutGeneration, 0),
245
+ },
246
+ text: text(o.text, 128 * 1024),
247
+ git: bool(o.git),
248
+ coverage: decodeCoverage(o.coverage),
249
+ };
250
+ correlate(result);
251
+ if (result.context.status === "available") {
252
+ const c = result.context.version;
253
+ if (
254
+ c.observation.identity !== result.observation.identity ||
255
+ c.observation.complete !== result.observation.complete ||
256
+ c.checkoutGeneration !== result.observation.checkoutGeneration
257
+ )
258
+ invalid();
259
+ }
260
+ return result;
261
+ }
@@ -0,0 +1,68 @@
1
+ /** Compatibility import path only; worker-public.mjs owns the executable codec and declarations. */
2
+ export {
3
+ type Action,
4
+ type ActionPreview,
5
+ type Assignment,
6
+ assertWorkerEnvelopeSize,
7
+ type ByteRange,
8
+ type CancelCommand,
9
+ type CaptureCoverage,
10
+ type CheckSelection,
11
+ type Closure,
12
+ type Command,
13
+ type CommandIdentity,
14
+ type ContentRef,
15
+ type ContextVersion,
16
+ checkSelection,
17
+ closures,
18
+ type Dependency,
19
+ type DependencyHandoff,
20
+ type DependencySource,
21
+ decodeAction,
22
+ decodeCancel,
23
+ decodeCommand,
24
+ decodeCommandIdentity,
25
+ decodeContentRef,
26
+ decodeContext,
27
+ decodeCoverage,
28
+ decodeCursor,
29
+ decodeGraph,
30
+ decodeHandoff,
31
+ decodeModelSelection,
32
+ decodeModelSelector,
33
+ decodeNativeSettlement,
34
+ decodeNavigation,
35
+ decodePreflight,
36
+ decodePreflightRequest,
37
+ decodePreview,
38
+ decodeScope,
39
+ decodeWorkerPublicRequest,
40
+ dependency,
41
+ type ExecutionOutcome,
42
+ type Field,
43
+ fields,
44
+ type Graph,
45
+ type HandoffInput,
46
+ type Issue,
47
+ type ModelSelection,
48
+ type ModelSelector,
49
+ modelApis,
50
+ type NativeSettlement,
51
+ outcomes,
52
+ type Preflight,
53
+ type PreflightRequest,
54
+ type Publication,
55
+ type Purpose,
56
+ type ReadCursor,
57
+ type RoleSelection,
58
+ range,
59
+ role,
60
+ roleForPurpose,
61
+ type Scope,
62
+ type TaskKind,
63
+ type TaskVersion,
64
+ tag,
65
+ taskVersion,
66
+ thinkingLevels,
67
+ type WorkerPublicRequest,
68
+ } from "../../worker-public.mjs";