@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.
- package/README.md +324 -117
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/agents/design-explorer.md +14 -18
- package/agents/diagnosis-worker.md +14 -14
- package/agents/implementation-worker.md +16 -17
- 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 +92 -20
- package/src/index.ts +21 -1802
- 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/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-context.ts +0 -289
- 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/contracts.ts +0 -2466
- 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 -227
- package/src/durable-workflow.ts +0 -822
- 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-process.ts +0 -206
- package/src/package-candidate.ts +0 -24
- 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 -305
- package/src/packet-runtime.ts +0 -459
- package/src/phase-execution.ts +0 -2163
- 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/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/subagent-process.ts +0 -476
- package/src/task-ledger.ts +0 -1338
- package/src/transport-budget.ts +0 -50
- 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/workflow-engine.ts +0 -28
- package/src/workflow-policy.ts +0 -1670
- package/src/workflow-recovery-policy.ts +0 -97
- package/src/workflow-scheduling.ts +0 -105
- package/src/workflow-state-machine.ts +0 -4341
- 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
|
@@ -1,559 +0,0 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
|
-
import { canonicalJson } from "./canonical.ts";
|
|
3
|
-
|
|
4
|
-
const CHANGE_NAME = /^[a-z0-9](?:[a-z0-9-]{0,126}[a-z0-9])?$/u;
|
|
5
|
-
const TERMINAL_STATES = new Set(["completed", "discarded", "rejected"]);
|
|
6
|
-
const ACTIONABLE_STATES = new Set([
|
|
7
|
-
"not-started",
|
|
8
|
-
"created",
|
|
9
|
-
"validating-delivery",
|
|
10
|
-
"ready",
|
|
11
|
-
"queued",
|
|
12
|
-
"connecting",
|
|
13
|
-
"running",
|
|
14
|
-
"validating",
|
|
15
|
-
"verifying",
|
|
16
|
-
"retryable",
|
|
17
|
-
"paused",
|
|
18
|
-
"approval-needed",
|
|
19
|
-
"change-verifying",
|
|
20
|
-
"ready-to-apply",
|
|
21
|
-
"applying",
|
|
22
|
-
"recovering",
|
|
23
|
-
]);
|
|
24
|
-
const READ_ONLY_AMENDMENT_OPERATIONS = new Set([
|
|
25
|
-
"status",
|
|
26
|
-
"validate-plan-draft",
|
|
27
|
-
]);
|
|
28
|
-
const INVESTIGATION_TOOLS = new Set(["read", "grep", "find", "ls", "bash"]);
|
|
29
|
-
const MAX_INVESTIGATION_CONTINUATIONS = 2;
|
|
30
|
-
|
|
31
|
-
type Activation = {
|
|
32
|
-
id: number;
|
|
33
|
-
cwd: string;
|
|
34
|
-
change: string;
|
|
35
|
-
inputRevision: number;
|
|
36
|
-
progressRevision: number;
|
|
37
|
-
amendmentBatchId?: string;
|
|
38
|
-
runId?: string;
|
|
39
|
-
stopped: boolean;
|
|
40
|
-
seenProgress: Set<string>;
|
|
41
|
-
seenInvestigationEvidence: Set<string>;
|
|
42
|
-
investigationEvidenceRevision: number;
|
|
43
|
-
investigationRoundsUsed: number;
|
|
44
|
-
lastInvestigationEvidenceUsed: number;
|
|
45
|
-
lastWorkflowEvidenceKey?: string;
|
|
46
|
-
sentContinuations: Set<string>;
|
|
47
|
-
reportedStalls: Set<string>;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export interface ImplementSettlementProbe {
|
|
51
|
-
readonly activationId: number;
|
|
52
|
-
readonly cwd: string;
|
|
53
|
-
readonly change: string;
|
|
54
|
-
readonly inputRevision: number;
|
|
55
|
-
readonly progressRevision: number;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export type ImplementSettlementDecision =
|
|
59
|
-
| {
|
|
60
|
-
kind: "continue";
|
|
61
|
-
change: string;
|
|
62
|
-
message: string;
|
|
63
|
-
statusFingerprint: string;
|
|
64
|
-
}
|
|
65
|
-
| {
|
|
66
|
-
kind: "terminal";
|
|
67
|
-
change: string;
|
|
68
|
-
state: string;
|
|
69
|
-
}
|
|
70
|
-
| {
|
|
71
|
-
kind: "stalled";
|
|
72
|
-
change: string;
|
|
73
|
-
message: string;
|
|
74
|
-
statusFingerprint: string;
|
|
75
|
-
code: "implement-continuation-no-progress";
|
|
76
|
-
state: string;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
type ToolResultObservation = {
|
|
80
|
-
toolName?: string;
|
|
81
|
-
input: unknown;
|
|
82
|
-
content?: unknown;
|
|
83
|
-
details: unknown;
|
|
84
|
-
isError: boolean;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
88
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function fingerprint(value: unknown): string {
|
|
92
|
-
return createHash("sha256")
|
|
93
|
-
.update(canonicalJson(value === undefined ? null : value))
|
|
94
|
-
.digest("hex");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const VOLATILE_KEYS = new Set([
|
|
98
|
-
"activityDisplay",
|
|
99
|
-
"durationMs",
|
|
100
|
-
"elapsedMs",
|
|
101
|
-
"finishedAt",
|
|
102
|
-
"observedAt",
|
|
103
|
-
"operationId",
|
|
104
|
-
"sequence",
|
|
105
|
-
"startedAt",
|
|
106
|
-
"timestamp",
|
|
107
|
-
"updatedAt",
|
|
108
|
-
"usage",
|
|
109
|
-
]);
|
|
110
|
-
const COUNT_ONLY_KEYS = new Set(["attempt", "attempts", "remaining", "used"]);
|
|
111
|
-
|
|
112
|
-
function semanticValue(
|
|
113
|
-
value: unknown,
|
|
114
|
-
options: {
|
|
115
|
-
progress?: boolean;
|
|
116
|
-
omitCounts?: boolean;
|
|
117
|
-
workflow?: boolean;
|
|
118
|
-
} = {},
|
|
119
|
-
parentKey?: string,
|
|
120
|
-
): unknown {
|
|
121
|
-
if (Array.isArray(value))
|
|
122
|
-
return value.map((item) => semanticValue(item, options, parentKey));
|
|
123
|
-
if (!isRecord(value)) return value;
|
|
124
|
-
return Object.fromEntries(
|
|
125
|
-
Object.entries(value).flatMap(([key, item]) =>
|
|
126
|
-
item === undefined ||
|
|
127
|
-
VOLATILE_KEYS.has(key) ||
|
|
128
|
-
(options.omitCounts && COUNT_ONLY_KEYS.has(key)) ||
|
|
129
|
-
(options.workflow &&
|
|
130
|
-
(key === "batchId" ||
|
|
131
|
-
(parentKey === "decisionBatch" && key === "id") ||
|
|
132
|
-
(typeof item === "number" &&
|
|
133
|
-
(key === "failures" || key === "failureSequence")))) ||
|
|
134
|
-
(options.progress && (key === "runId" || key === "amendmentRunId"))
|
|
135
|
-
? []
|
|
136
|
-
: [[key, semanticValue(item, options, key)]],
|
|
137
|
-
),
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** Compare work evidence without altering the live authority/grant envelopes.
|
|
142
|
-
* Batch hashes encode retry counts; retain their semantic items, not those hashes.
|
|
143
|
-
*/
|
|
144
|
-
function workflowProgress(value: unknown): unknown {
|
|
145
|
-
return semanticValue(value, {
|
|
146
|
-
progress: true,
|
|
147
|
-
omitCounts: true,
|
|
148
|
-
workflow: true,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function parentAutomaticContinuation(
|
|
153
|
-
status: Record<string, unknown>,
|
|
154
|
-
change: string,
|
|
155
|
-
): boolean {
|
|
156
|
-
const continuation = isRecord(status.continuation)
|
|
157
|
-
? status.continuation
|
|
158
|
-
: undefined;
|
|
159
|
-
return Boolean(
|
|
160
|
-
continuation?.owner === "parent" &&
|
|
161
|
-
continuation.automatic === true &&
|
|
162
|
-
(continuation.change === undefined || continuation.change === change) &&
|
|
163
|
-
(continuation.stage === undefined ||
|
|
164
|
-
continuation.stage === "abel-implement"),
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function currentRecoveryGrant(status: Record<string, unknown>): boolean {
|
|
169
|
-
return Boolean(
|
|
170
|
-
isRecord(status.recovery) &&
|
|
171
|
-
isRecord(status.recovery.additionalAttempt) &&
|
|
172
|
-
typeof status.recovery.additionalAttempt.incidentKey === "string" &&
|
|
173
|
-
Number.isInteger(status.recovery.additionalAttempt.failureSequence),
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function workBudgetExhausted(status: Record<string, unknown>): boolean {
|
|
178
|
-
return Boolean(
|
|
179
|
-
(isRecord(status.resourceBudget) &&
|
|
180
|
-
status.resourceBudget.remaining === 0) ||
|
|
181
|
-
(isRecord(status.recovery) &&
|
|
182
|
-
[
|
|
183
|
-
"change-work-budget-exhausted",
|
|
184
|
-
"change-recovery-budget-exhausted",
|
|
185
|
-
].includes(String(status.recovery.code))),
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function settleApplyRecovery(
|
|
190
|
-
status: Record<string, unknown>,
|
|
191
|
-
change: string,
|
|
192
|
-
legalCommands: readonly unknown[],
|
|
193
|
-
): boolean {
|
|
194
|
-
const continuation = isRecord(status.continuation)
|
|
195
|
-
? status.continuation
|
|
196
|
-
: undefined;
|
|
197
|
-
return Boolean(
|
|
198
|
-
status.state === "recovering" &&
|
|
199
|
-
isRecord(status.pause) &&
|
|
200
|
-
status.pause.code === "operation-interrupted" &&
|
|
201
|
-
legalCommands.includes("resume") &&
|
|
202
|
-
continuation?.owner === "parent" &&
|
|
203
|
-
continuation.automatic === true &&
|
|
204
|
-
continuation.kind === "settle-apply-recovery" &&
|
|
205
|
-
continuation.reason === "operation-interrupted" &&
|
|
206
|
-
continuation.command === "resume" &&
|
|
207
|
-
continuation.stage === "abel-implement" &&
|
|
208
|
-
continuation.change === change,
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function matchingAmendmentAuthority(
|
|
213
|
-
status: Record<string, unknown>,
|
|
214
|
-
change: string,
|
|
215
|
-
batchId: string | undefined,
|
|
216
|
-
): boolean {
|
|
217
|
-
if (!batchId || !isRecord(status.decisionBatch)) return false;
|
|
218
|
-
const continuation = isRecord(status.decisionBatch.continuation)
|
|
219
|
-
? status.decisionBatch.continuation
|
|
220
|
-
: undefined;
|
|
221
|
-
return Boolean(
|
|
222
|
-
status.decisionBatch.id === batchId &&
|
|
223
|
-
continuation?.action === "amend" &&
|
|
224
|
-
continuation.change === change &&
|
|
225
|
-
continuation.batchId === batchId,
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function lastAssistantStopReason(
|
|
230
|
-
messages: readonly unknown[],
|
|
231
|
-
): string | undefined {
|
|
232
|
-
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
233
|
-
const message = messages[index];
|
|
234
|
-
if (isRecord(message) && message.role === "assistant") {
|
|
235
|
-
return typeof message.stopReason === "string"
|
|
236
|
-
? message.stopReason
|
|
237
|
-
: undefined;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return undefined;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/** Resolve the exact argument from the original explicit slash invocation. */
|
|
244
|
-
export function implementChangeFromInvocation(
|
|
245
|
-
text: string,
|
|
246
|
-
): string | undefined {
|
|
247
|
-
const prefix = "/abel-implement";
|
|
248
|
-
if (!text.startsWith(prefix)) return undefined;
|
|
249
|
-
const boundary = text[prefix.length];
|
|
250
|
-
if (boundary !== undefined && !/\s/u.test(boundary)) return undefined;
|
|
251
|
-
const change = text.slice(prefix.length).trim();
|
|
252
|
-
return CHANGE_NAME.test(change) ? change : undefined;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/** Confirm that verified package expansion retained the raw invocation identity. */
|
|
256
|
-
export function implementPromptBindsChange(
|
|
257
|
-
prompt: string,
|
|
258
|
-
expectedChange: string,
|
|
259
|
-
): boolean {
|
|
260
|
-
if (!CHANGE_NAME.test(expectedChange)) return false;
|
|
261
|
-
const close = prompt.lastIndexOf("</abel-request>");
|
|
262
|
-
if (close < 0) return false;
|
|
263
|
-
const open = prompt.lastIndexOf("<abel-request>", close);
|
|
264
|
-
if (open < 0) return false;
|
|
265
|
-
const change = prompt.slice(open + "<abel-request>".length, close).trim();
|
|
266
|
-
return change === expectedChange;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export function isTerminalImplementStatus(status: unknown): boolean {
|
|
270
|
-
if (!isRecord(status)) return false;
|
|
271
|
-
return (
|
|
272
|
-
status.completed === true ||
|
|
273
|
-
TERMINAL_STATES.has(String(status.state)) ||
|
|
274
|
-
TERMINAL_STATES.has(String(status.terminal))
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Session-local liveness guard for one explicitly activated Implement change.
|
|
280
|
-
* It owns no workflow command authority and never persists or executes a resume.
|
|
281
|
-
*/
|
|
282
|
-
export class ImplementContinuationDriver {
|
|
283
|
-
#activation?: Activation;
|
|
284
|
-
#inputRevision = 0;
|
|
285
|
-
#nextActivationId = 1;
|
|
286
|
-
|
|
287
|
-
noteInput(): void {
|
|
288
|
-
this.#inputRevision += 1;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
activate(input: { cwd: string; change: string }): void {
|
|
292
|
-
this.#activation = {
|
|
293
|
-
id: this.#nextActivationId++,
|
|
294
|
-
cwd: input.cwd,
|
|
295
|
-
change: input.change,
|
|
296
|
-
inputRevision: this.#inputRevision,
|
|
297
|
-
progressRevision: 0,
|
|
298
|
-
stopped: false,
|
|
299
|
-
seenProgress: new Set(),
|
|
300
|
-
seenInvestigationEvidence: new Set(),
|
|
301
|
-
investigationEvidenceRevision: 0,
|
|
302
|
-
investigationRoundsUsed: 0,
|
|
303
|
-
lastInvestigationEvidenceUsed: 0,
|
|
304
|
-
sentContinuations: new Set(),
|
|
305
|
-
reportedStalls: new Set(),
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
beginParentTurn(cwd: string): void {
|
|
310
|
-
const active = this.#activation;
|
|
311
|
-
if (!active || active.cwd !== cwd || active.stopped) return;
|
|
312
|
-
active.inputRevision = this.#inputRevision;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
deactivate(): void {
|
|
316
|
-
this.#activation = undefined;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
noteToolResult(observation: ToolResultObservation): void {
|
|
320
|
-
const active = this.#activation;
|
|
321
|
-
if (!active || !isRecord(observation.input)) return;
|
|
322
|
-
const input = observation.input;
|
|
323
|
-
const toolName = observation.toolName ?? "abel_dispatch";
|
|
324
|
-
if (toolName !== "abel_dispatch") {
|
|
325
|
-
if (observation.isError || !INVESTIGATION_TOOLS.has(toolName)) return;
|
|
326
|
-
const evidenceKey = fingerprint({
|
|
327
|
-
kind: "parent-investigation",
|
|
328
|
-
toolName,
|
|
329
|
-
input: semanticValue(input, { progress: true, omitCounts: true }),
|
|
330
|
-
content: semanticValue(observation.content, {
|
|
331
|
-
progress: true,
|
|
332
|
-
omitCounts: true,
|
|
333
|
-
}),
|
|
334
|
-
details: semanticValue(observation.details, {
|
|
335
|
-
progress: true,
|
|
336
|
-
omitCounts: true,
|
|
337
|
-
}),
|
|
338
|
-
});
|
|
339
|
-
if (active.seenInvestigationEvidence.has(evidenceKey)) return;
|
|
340
|
-
active.seenInvestigationEvidence.add(evidenceKey);
|
|
341
|
-
active.investigationEvidenceRevision += 1;
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
if (input.change !== active.change) return;
|
|
345
|
-
|
|
346
|
-
if (
|
|
347
|
-
!observation.isError &&
|
|
348
|
-
(input.command === "cancel" || input.command === "discard")
|
|
349
|
-
) {
|
|
350
|
-
active.stopped = true;
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
if (observation.isError) return;
|
|
354
|
-
|
|
355
|
-
let progressKey: string | undefined;
|
|
356
|
-
if (input.action === "amend") {
|
|
357
|
-
const request = isRecord(input.request) ? input.request : undefined;
|
|
358
|
-
const operation = request?.operation;
|
|
359
|
-
if (
|
|
360
|
-
typeof input.batchId === "string" &&
|
|
361
|
-
typeof operation === "string" &&
|
|
362
|
-
!READ_ONLY_AMENDMENT_OPERATIONS.has(operation)
|
|
363
|
-
) {
|
|
364
|
-
active.amendmentBatchId = input.batchId;
|
|
365
|
-
const semanticRequest = semanticValue(request, { progress: true });
|
|
366
|
-
progressKey = fingerprint({
|
|
367
|
-
kind: "amendment",
|
|
368
|
-
request: semanticRequest,
|
|
369
|
-
result: workflowProgress(observation.details),
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
} else if (
|
|
373
|
-
input.stage === "abel-implement" &&
|
|
374
|
-
["start", "resume", "rebind"].includes(String(input.command))
|
|
375
|
-
) {
|
|
376
|
-
progressKey = fingerprint({
|
|
377
|
-
kind: "control",
|
|
378
|
-
result: workflowProgress(observation.details),
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (!progressKey || active.seenProgress.has(progressKey)) return;
|
|
383
|
-
active.seenProgress.add(progressKey);
|
|
384
|
-
active.progressRevision += 1;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
prepareSettlement(input: {
|
|
388
|
-
cwd: string;
|
|
389
|
-
messages: readonly unknown[];
|
|
390
|
-
}): ImplementSettlementProbe | undefined {
|
|
391
|
-
const active = this.#activation;
|
|
392
|
-
if (
|
|
393
|
-
!active ||
|
|
394
|
-
active.stopped ||
|
|
395
|
-
active.cwd !== input.cwd ||
|
|
396
|
-
active.inputRevision !== this.#inputRevision
|
|
397
|
-
) {
|
|
398
|
-
return undefined;
|
|
399
|
-
}
|
|
400
|
-
const stopReason = lastAssistantStopReason(input.messages);
|
|
401
|
-
if (stopReason === "aborted" || stopReason === "error") return undefined;
|
|
402
|
-
return {
|
|
403
|
-
activationId: active.id,
|
|
404
|
-
cwd: active.cwd,
|
|
405
|
-
change: active.change,
|
|
406
|
-
inputRevision: active.inputRevision,
|
|
407
|
-
progressRevision: active.progressRevision,
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
finishSettlement(
|
|
412
|
-
probe: ImplementSettlementProbe,
|
|
413
|
-
status: unknown,
|
|
414
|
-
): ImplementSettlementDecision | undefined {
|
|
415
|
-
const active = this.#activation;
|
|
416
|
-
if (
|
|
417
|
-
!active ||
|
|
418
|
-
active.stopped ||
|
|
419
|
-
active.id !== probe.activationId ||
|
|
420
|
-
active.cwd !== probe.cwd ||
|
|
421
|
-
active.change !== probe.change ||
|
|
422
|
-
active.inputRevision !== probe.inputRevision ||
|
|
423
|
-
active.inputRevision !== this.#inputRevision ||
|
|
424
|
-
active.progressRevision !== probe.progressRevision ||
|
|
425
|
-
!isRecord(status) ||
|
|
426
|
-
status.stage !== "abel-implement" ||
|
|
427
|
-
status.change !== active.change
|
|
428
|
-
) {
|
|
429
|
-
return undefined;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
if (isTerminalImplementStatus(status)) {
|
|
433
|
-
active.stopped = true;
|
|
434
|
-
return {
|
|
435
|
-
kind: "terminal",
|
|
436
|
-
change: active.change,
|
|
437
|
-
state: String(status.state),
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
if (
|
|
441
|
-
!ACTIONABLE_STATES.has(String(status.state)) ||
|
|
442
|
-
(isRecord(status.pause) && status.pause.code === "operation-cancelled")
|
|
443
|
-
) {
|
|
444
|
-
if (isRecord(status.pause) && status.pause.code === "operation-cancelled")
|
|
445
|
-
active.stopped = true;
|
|
446
|
-
return undefined;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (typeof status.runId === "string") {
|
|
450
|
-
if (active.runId && active.runId !== status.runId) return undefined;
|
|
451
|
-
active.runId = status.runId;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const legalCommands = Array.isArray(status.legalCommands)
|
|
455
|
-
? status.legalCommands
|
|
456
|
-
: [];
|
|
457
|
-
const automatic = parentAutomaticContinuation(status, active.change);
|
|
458
|
-
const continuation = isRecord(status.continuation)
|
|
459
|
-
? status.continuation
|
|
460
|
-
: undefined;
|
|
461
|
-
const amendmentExhausted = Boolean(
|
|
462
|
-
isRecord(status.amendmentBudget) &&
|
|
463
|
-
status.amendmentBudget.exhausted === true,
|
|
464
|
-
);
|
|
465
|
-
const currentAmendment = matchingAmendmentAuthority(
|
|
466
|
-
status,
|
|
467
|
-
active.change,
|
|
468
|
-
active.amendmentBatchId,
|
|
469
|
-
);
|
|
470
|
-
const actionable =
|
|
471
|
-
(status.state === "not-started" && legalCommands.includes("start")) ||
|
|
472
|
-
(automatic &&
|
|
473
|
-
!(continuation?.action === "amend" && amendmentExhausted)) ||
|
|
474
|
-
currentRecoveryGrant(status) ||
|
|
475
|
-
(currentAmendment && !amendmentExhausted);
|
|
476
|
-
if (
|
|
477
|
-
!actionable ||
|
|
478
|
-
(workBudgetExhausted(status) &&
|
|
479
|
-
!settleApplyRecovery(status, active.change, legalCommands))
|
|
480
|
-
)
|
|
481
|
-
return undefined;
|
|
482
|
-
|
|
483
|
-
const evidence = workflowProgress(status);
|
|
484
|
-
// A successful control call returning already observed failure evidence is
|
|
485
|
-
// not progress, even on the first retry after a read-only status observation.
|
|
486
|
-
active.seenProgress.add(fingerprint({ kind: "control", result: evidence }));
|
|
487
|
-
const statusFingerprint = fingerprint(evidence);
|
|
488
|
-
const workflowEvidenceKey = fingerprint({
|
|
489
|
-
progressRevision: active.progressRevision,
|
|
490
|
-
statusFingerprint,
|
|
491
|
-
});
|
|
492
|
-
const baseContinuationKey = fingerprint({
|
|
493
|
-
inputRevision: active.inputRevision,
|
|
494
|
-
workflowEvidenceKey,
|
|
495
|
-
kind: "workflow",
|
|
496
|
-
});
|
|
497
|
-
let continuationKey: string | undefined;
|
|
498
|
-
if (active.lastWorkflowEvidenceKey !== workflowEvidenceKey) {
|
|
499
|
-
active.lastWorkflowEvidenceKey = workflowEvidenceKey;
|
|
500
|
-
active.investigationRoundsUsed = 0;
|
|
501
|
-
active.lastInvestigationEvidenceUsed =
|
|
502
|
-
active.investigationEvidenceRevision;
|
|
503
|
-
continuationKey = baseContinuationKey;
|
|
504
|
-
} else if (!active.sentContinuations.has(baseContinuationKey)) {
|
|
505
|
-
active.lastInvestigationEvidenceUsed =
|
|
506
|
-
active.investigationEvidenceRevision;
|
|
507
|
-
continuationKey = baseContinuationKey;
|
|
508
|
-
} else if (
|
|
509
|
-
active.investigationEvidenceRevision >
|
|
510
|
-
active.lastInvestigationEvidenceUsed &&
|
|
511
|
-
active.investigationRoundsUsed < MAX_INVESTIGATION_CONTINUATIONS
|
|
512
|
-
) {
|
|
513
|
-
active.investigationRoundsUsed += 1;
|
|
514
|
-
active.lastInvestigationEvidenceUsed =
|
|
515
|
-
active.investigationEvidenceRevision;
|
|
516
|
-
continuationKey = fingerprint({
|
|
517
|
-
baseContinuationKey,
|
|
518
|
-
kind: "investigation",
|
|
519
|
-
round: active.investigationRoundsUsed,
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
if (!continuationKey || active.sentContinuations.has(continuationKey)) {
|
|
524
|
-
const stalledKey = fingerprint({
|
|
525
|
-
baseContinuationKey,
|
|
526
|
-
investigationEvidenceRevision: active.lastInvestigationEvidenceUsed,
|
|
527
|
-
investigationRoundsUsed: active.investigationRoundsUsed,
|
|
528
|
-
});
|
|
529
|
-
if (active.reportedStalls.has(stalledKey)) return undefined;
|
|
530
|
-
active.reportedStalls.add(stalledKey);
|
|
531
|
-
return {
|
|
532
|
-
kind: "stalled",
|
|
533
|
-
change: active.change,
|
|
534
|
-
code: "implement-continuation-no-progress",
|
|
535
|
-
state: String(status.state),
|
|
536
|
-
statusFingerprint,
|
|
537
|
-
message:
|
|
538
|
-
active.investigationRoundsUsed >= MAX_INVESTIGATION_CONTINUATIONS
|
|
539
|
-
? `Abel Implement retained ${active.change} in ${String(status.state)} state but stopped automatic continuation because workflow and control evidence did not advance after two bounded investigation rounds. New investigation evidence was observed without durable workflow progress; retained progress is preserved.`
|
|
540
|
-
: `Abel Implement retained ${active.change} in ${String(status.state)} state but stopped automatic continuation because the fresh local status and implementation evidence did not change. Durable progress is preserved.`,
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
active.sentContinuations.add(continuationKey);
|
|
544
|
-
|
|
545
|
-
return {
|
|
546
|
-
kind: "continue",
|
|
547
|
-
change: active.change,
|
|
548
|
-
statusFingerprint,
|
|
549
|
-
message: [
|
|
550
|
-
`[Abel host continuation for ${active.change}]`,
|
|
551
|
-
"The explicitly activated Implement run is still nonterminal after the previous parent response ended.",
|
|
552
|
-
`Fresh local status: ${JSON.stringify(status)}`,
|
|
553
|
-
"Continue the same accepted goal now. Inspect this current evidence, repair or amend within existing authority, and use only a legal closed abel_dispatch request when the evidence supports it.",
|
|
554
|
-
"The status continuation object is guidance metadata, not dispatch arguments. Do not replay an earlier command blindly, do not merely poll status, and do not ask the user to choose routine implementation or recovery steps.",
|
|
555
|
-
"Stop only for verified completion, explicit cancellation, or a concrete external condition that available capabilities and retained budgets cannot resolve.",
|
|
556
|
-
].join("\n"),
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
}
|