certal 0.0.0-stage → 0.1.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/.claude-plugin/plugin.json +11 -0
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +277 -2
- package/SECURITY.md +36 -0
- package/bin/certal.mjs +12 -0
- package/certal.schema.json +156 -0
- package/dist/adapters/approval-channel.d.ts +44 -0
- package/dist/adapters/approval-channel.js +74 -0
- package/dist/adapters/commands.d.ts +73 -0
- package/dist/adapters/commands.js +185 -0
- package/dist/adapters/contracts.d.ts +59 -0
- package/dist/adapters/contracts.js +1 -0
- package/dist/adapters/file-watcher.d.ts +53 -0
- package/dist/adapters/file-watcher.js +142 -0
- package/dist/adapters/in-memory.d.ts +53 -0
- package/dist/adapters/in-memory.js +165 -0
- package/dist/adapters/index.d.ts +8 -0
- package/dist/adapters/index.js +8 -0
- package/dist/adapters/manifest.d.ts +105 -0
- package/dist/adapters/manifest.js +438 -0
- package/dist/adapters/operator-auth.d.ts +47 -0
- package/dist/adapters/operator-auth.js +72 -0
- package/dist/adapters/tool-sdk.d.ts +150 -0
- package/dist/adapters/tool-sdk.js +336 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +1 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +386 -0
- package/dist/kernel/common.d.ts +46 -0
- package/dist/kernel/common.js +238 -0
- package/dist/kernel/crypto.d.ts +35 -0
- package/dist/kernel/crypto.js +54 -0
- package/dist/kernel/effects.d.ts +4 -0
- package/dist/kernel/effects.js +178 -0
- package/dist/kernel/index.d.ts +9 -0
- package/dist/kernel/index.js +9 -0
- package/dist/kernel/jcs.d.ts +24 -0
- package/dist/kernel/jcs.js +93 -0
- package/dist/kernel/leases.d.ts +11 -0
- package/dist/kernel/leases.js +86 -0
- package/dist/kernel/step.d.ts +10 -0
- package/dist/kernel/step.js +967 -0
- package/dist/kernel/types.d.ts +538 -0
- package/dist/kernel/types.js +1 -0
- package/dist/kernel/undo.d.ts +4 -0
- package/dist/kernel/undo.js +180 -0
- package/dist/kernel/validation.d.ts +13 -0
- package/dist/kernel/validation.js +307 -0
- package/dist/kernel/witness.d.ts +34 -0
- package/dist/kernel/witness.js +279 -0
- package/dist/mcp/host.d.ts +141 -0
- package/dist/mcp/host.js +517 -0
- package/dist/mcp/index.d.ts +2 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/server.d.ts +70 -0
- package/dist/mcp/server.js +508 -0
- package/dist/runtime/dp1.d.ts +48 -0
- package/dist/runtime/dp1.js +229 -0
- package/dist/runtime/engine.d.ts +86 -0
- package/dist/runtime/engine.js +320 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/outbox.d.ts +69 -0
- package/dist/runtime/outbox.js +238 -0
- package/dist/runtime/store.d.ts +204 -0
- package/dist/runtime/store.js +746 -0
- package/package.json +91 -4
- package/presets/exchange-firewall.json +40 -0
- package/presets/sdk.json +32 -0
- package/presets/solver.json +22 -0
- package/presets/vibeops.json +34 -0
- package/skills/certal/SKILL.md +49 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import type { SignatureAlgorithm, SignatureVerifier } from './crypto.ts';
|
|
2
|
+
import type { HashAlgorithm } from './jcs.ts';
|
|
3
|
+
export type Grade = 'exact' | 'partial' | 'unknown';
|
|
4
|
+
export type Reversibility = 'REVERSIBLE' | 'COMPENSABLE' | 'IRREVERSIBLE';
|
|
5
|
+
export type PinKind = 'H' | 'T' | 'N';
|
|
6
|
+
export type WitnessStage = 'L0' | 'L1' | 'L2' | 'L3';
|
|
7
|
+
export type WitnessVerdictCode = 'PASS' | 'FAIL' | 'UNKNOWN';
|
|
8
|
+
export type AttemptStatus = 'OPEN' | 'VERIFYING' | 'VERIFIED' | 'FINALIZED' | 'ABORTED' | 'HALTED';
|
|
9
|
+
export type AutonomyTier = 'SHADOW' | 'APPROVAL' | 'AUTO';
|
|
10
|
+
export type EffectStatus = 'INTENT' | 'IN_FLIGHT' | 'APPLIED' | 'UNKNOWN' | 'RECONCILE_EXHAUSTED' | 'DELIVERY_FAILED' | 'ABORTED_EXPIRED' | 'COMP_INTENT' | 'COMP_IN_FLIGHT' | 'COMPENSATED' | 'COMP_UNKNOWN' | 'COMP_FAILED' | 'MANUAL_COMPENSATION_REQUIRED';
|
|
11
|
+
export type Origin = {
|
|
12
|
+
readonly kind: 'Human';
|
|
13
|
+
readonly actorId: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'Agent';
|
|
16
|
+
readonly actorId: string;
|
|
17
|
+
readonly taskId: string;
|
|
18
|
+
readonly attemptId: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'Sensor';
|
|
21
|
+
readonly actorId: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'System';
|
|
24
|
+
readonly actorId: string;
|
|
25
|
+
};
|
|
26
|
+
export interface AuthContext {
|
|
27
|
+
readonly origin: Origin;
|
|
28
|
+
readonly roles: readonly string[];
|
|
29
|
+
readonly authMethod: string;
|
|
30
|
+
}
|
|
31
|
+
export interface Binding {
|
|
32
|
+
readonly diffHash: string;
|
|
33
|
+
readonly scopeHash: string;
|
|
34
|
+
readonly inputSnapshotHash: string;
|
|
35
|
+
}
|
|
36
|
+
export interface InputSnapshot {
|
|
37
|
+
readonly schemaVersion: number;
|
|
38
|
+
readonly dataRef: string;
|
|
39
|
+
readonly hash: string;
|
|
40
|
+
readonly capturedAtMs: number;
|
|
41
|
+
readonly confidence: Grade;
|
|
42
|
+
readonly missingFields?: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
export interface PinPolicy {
|
|
45
|
+
readonly pinId: string;
|
|
46
|
+
readonly kind: PinKind;
|
|
47
|
+
readonly scopeId: string;
|
|
48
|
+
readonly classId: string;
|
|
49
|
+
readonly ruleId: string;
|
|
50
|
+
readonly ownerId: string;
|
|
51
|
+
readonly expiresAtMs?: number;
|
|
52
|
+
readonly contractVersion?: number;
|
|
53
|
+
readonly costPenaltyMicroUnits?: number;
|
|
54
|
+
}
|
|
55
|
+
export interface ApprovalToken {
|
|
56
|
+
readonly approvalId: string;
|
|
57
|
+
readonly humanId: string;
|
|
58
|
+
readonly attemptId: string;
|
|
59
|
+
readonly binding: Binding;
|
|
60
|
+
readonly expiresAtMs: number;
|
|
61
|
+
readonly singleUse: true;
|
|
62
|
+
readonly signature?: {
|
|
63
|
+
readonly algorithm: SignatureAlgorithm;
|
|
64
|
+
readonly keyId: string;
|
|
65
|
+
readonly value: string;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export interface ResourceUnits {
|
|
69
|
+
readonly inferenceSlots: number;
|
|
70
|
+
readonly witnessSlots: number;
|
|
71
|
+
readonly mutationSlots: number;
|
|
72
|
+
}
|
|
73
|
+
export interface Lease2D {
|
|
74
|
+
readonly leaseId: string;
|
|
75
|
+
readonly scopeId: string;
|
|
76
|
+
readonly classId: string;
|
|
77
|
+
readonly ownerId: string;
|
|
78
|
+
readonly attemptId: string;
|
|
79
|
+
readonly leaseEpoch: number;
|
|
80
|
+
readonly expiresAtMs: number;
|
|
81
|
+
readonly units: ResourceUnits;
|
|
82
|
+
}
|
|
83
|
+
export interface StateOp {
|
|
84
|
+
readonly opIndex: number;
|
|
85
|
+
readonly objectId: string;
|
|
86
|
+
readonly classId: string;
|
|
87
|
+
readonly field: string;
|
|
88
|
+
readonly expectedBeforeRev: number;
|
|
89
|
+
readonly beforeValue: unknown;
|
|
90
|
+
readonly afterValue: unknown;
|
|
91
|
+
readonly reversibility: Reversibility;
|
|
92
|
+
readonly parentObjectId?: string;
|
|
93
|
+
readonly externalEffect?: {
|
|
94
|
+
readonly effectKey: string;
|
|
95
|
+
readonly recipientId: string;
|
|
96
|
+
readonly supportsCas: boolean;
|
|
97
|
+
readonly actionPayload: unknown;
|
|
98
|
+
readonly inversePayload?: unknown;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export interface StateSlotValue {
|
|
102
|
+
readonly objectId: string;
|
|
103
|
+
readonly classId: string;
|
|
104
|
+
readonly field: string;
|
|
105
|
+
readonly rev: number;
|
|
106
|
+
readonly value: unknown;
|
|
107
|
+
readonly owner: Origin;
|
|
108
|
+
readonly batchId: string | null;
|
|
109
|
+
readonly parentObjectId?: string;
|
|
110
|
+
}
|
|
111
|
+
export interface OptimizationVector {
|
|
112
|
+
readonly hardViolations: readonly string[];
|
|
113
|
+
readonly pinViolations: readonly string[];
|
|
114
|
+
readonly baselineViolations: readonly string[];
|
|
115
|
+
readonly afterViolations: readonly string[];
|
|
116
|
+
readonly costDeltaMicroUnits: number;
|
|
117
|
+
}
|
|
118
|
+
export interface PolicyConfig {
|
|
119
|
+
readonly schemaVersion: number;
|
|
120
|
+
readonly maxAttempts: number;
|
|
121
|
+
readonly maxFailStreak: number;
|
|
122
|
+
readonly maxConflictStreak: number;
|
|
123
|
+
readonly maxCpuMs: number;
|
|
124
|
+
readonly maxCostMicroUnits: number;
|
|
125
|
+
readonly maxReconcileAttempts: number;
|
|
126
|
+
readonly undoWindowTtlMs: number;
|
|
127
|
+
readonly defaultLeaseTtlMs: number;
|
|
128
|
+
readonly maxConcurrentPerScope: number;
|
|
129
|
+
readonly resourcePoolCapacity: ResourceUnits;
|
|
130
|
+
readonly minImprovementMicroUnits: number;
|
|
131
|
+
readonly escalatePartialToC2: boolean;
|
|
132
|
+
readonly denyPartial: boolean;
|
|
133
|
+
readonly escalateSoftPinToC2: boolean;
|
|
134
|
+
readonly enforceApprovalSignature: boolean;
|
|
135
|
+
readonly enforceAutonomyLadder: boolean;
|
|
136
|
+
readonly maxEventBytes: number;
|
|
137
|
+
readonly requiredWitnessStages: readonly WitnessStage[];
|
|
138
|
+
}
|
|
139
|
+
export interface WitnessStageRecord {
|
|
140
|
+
readonly verifyId: string;
|
|
141
|
+
readonly stage: WitnessStage;
|
|
142
|
+
readonly verdict: WitnessVerdictCode;
|
|
143
|
+
readonly cpuMs: number;
|
|
144
|
+
readonly nearMissPassed: boolean;
|
|
145
|
+
readonly optimization?: OptimizationVector;
|
|
146
|
+
}
|
|
147
|
+
export interface PendingVerify {
|
|
148
|
+
readonly verifyId: string;
|
|
149
|
+
readonly stage: WitnessStage;
|
|
150
|
+
readonly attemptId: string;
|
|
151
|
+
readonly epoch: number;
|
|
152
|
+
readonly scopeHash: string;
|
|
153
|
+
readonly inputSnapshotHash: string;
|
|
154
|
+
readonly budgetCpuMs: number;
|
|
155
|
+
readonly requireNearMiss: boolean;
|
|
156
|
+
}
|
|
157
|
+
export interface AttemptState {
|
|
158
|
+
readonly attemptId: string;
|
|
159
|
+
readonly taskId: string;
|
|
160
|
+
readonly toolId: string;
|
|
161
|
+
readonly clusterId: string;
|
|
162
|
+
readonly executorId: string;
|
|
163
|
+
readonly scopeId: string;
|
|
164
|
+
readonly classId: string;
|
|
165
|
+
readonly status: AttemptStatus;
|
|
166
|
+
readonly openedAtEpoch: number;
|
|
167
|
+
readonly openedScopeHash: string;
|
|
168
|
+
readonly diffHash: string | null;
|
|
169
|
+
readonly binding: Binding | null;
|
|
170
|
+
readonly ops: readonly StateOp[];
|
|
171
|
+
readonly snapshot: InputSnapshot | null;
|
|
172
|
+
readonly needsApproval: boolean;
|
|
173
|
+
readonly approvalReason: string | null;
|
|
174
|
+
readonly approval: ApprovalToken | null;
|
|
175
|
+
readonly pendingVerify: PendingVerify | null;
|
|
176
|
+
readonly stages: readonly WitnessStageRecord[];
|
|
177
|
+
readonly optimizationEnabled: boolean;
|
|
178
|
+
readonly lastOptimization: OptimizationVector | null;
|
|
179
|
+
readonly isRiskReducing: boolean;
|
|
180
|
+
}
|
|
181
|
+
export interface CommittedBatchRecord {
|
|
182
|
+
readonly batchId: string;
|
|
183
|
+
readonly attemptId: string;
|
|
184
|
+
readonly taskId: string;
|
|
185
|
+
readonly committedAtMs: number;
|
|
186
|
+
readonly committedAtSeq: number;
|
|
187
|
+
readonly scopeId: string;
|
|
188
|
+
readonly reversibility: Reversibility;
|
|
189
|
+
readonly ops: readonly StateOp[];
|
|
190
|
+
readonly effectIds: readonly string[];
|
|
191
|
+
readonly undone: boolean;
|
|
192
|
+
}
|
|
193
|
+
export interface EffectRecord {
|
|
194
|
+
readonly effectId: string;
|
|
195
|
+
readonly batchId: string;
|
|
196
|
+
readonly attemptId: string;
|
|
197
|
+
readonly scopeId: string;
|
|
198
|
+
readonly classId: string;
|
|
199
|
+
readonly effectKey: string;
|
|
200
|
+
readonly recipientId: string;
|
|
201
|
+
readonly supportsCas: boolean;
|
|
202
|
+
readonly actionPayload: unknown;
|
|
203
|
+
readonly inversePayload: unknown;
|
|
204
|
+
readonly binding: Binding;
|
|
205
|
+
readonly approvalId: string | null;
|
|
206
|
+
readonly approvalExpiresAtMs: number | null;
|
|
207
|
+
readonly status: EffectStatus;
|
|
208
|
+
readonly reconcileCount: number;
|
|
209
|
+
readonly orderIndex: number;
|
|
210
|
+
readonly compensating: boolean;
|
|
211
|
+
readonly originalEffectId: string | null;
|
|
212
|
+
}
|
|
213
|
+
export interface ClusterRecord {
|
|
214
|
+
readonly toolId: string;
|
|
215
|
+
readonly clusterId: string;
|
|
216
|
+
readonly outcome: 'CLEAN' | 'VIOLATION';
|
|
217
|
+
readonly firstSeq: number;
|
|
218
|
+
}
|
|
219
|
+
export interface ToolClusterStats {
|
|
220
|
+
readonly cleanCount: number;
|
|
221
|
+
readonly violationCount: number;
|
|
222
|
+
}
|
|
223
|
+
export interface ToolAutonomyStatus {
|
|
224
|
+
readonly toolId: string;
|
|
225
|
+
readonly cleanClusterCount: number;
|
|
226
|
+
readonly violationCount: number;
|
|
227
|
+
readonly tier: AutonomyTier;
|
|
228
|
+
readonly downgraded: boolean;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Policy for an undo that meets a field conflict (a later overwrite or a human-owned dependency).
|
|
232
|
+
* - ABORT_ON_CONFLICT: change nothing and reject.
|
|
233
|
+
* - COMPENSATE_ONLY_IF_ALL_REVERTED: if the batch has applied external effects, change nothing and pause for the operator.
|
|
234
|
+
* - FORCE_COMPENSATE: restore what can be restored and compensate the external effects anyway.
|
|
235
|
+
*/
|
|
236
|
+
export type CompensationPolicy = 'ABORT_ON_CONFLICT' | 'COMPENSATE_ONLY_IF_ALL_REVERTED' | 'FORCE_COMPENSATE';
|
|
237
|
+
export type UndoConflictReason = 'HUMAN_OVERWRITE' | 'AGENT_OVERWRITE' | 'SKIPPED_DEPENDENT_REF';
|
|
238
|
+
export interface UndoConflict {
|
|
239
|
+
readonly objectId: string;
|
|
240
|
+
readonly field: string;
|
|
241
|
+
readonly reason: UndoConflictReason;
|
|
242
|
+
readonly detail: string;
|
|
243
|
+
}
|
|
244
|
+
export interface UndoReport {
|
|
245
|
+
readonly batchId: string;
|
|
246
|
+
readonly appliedFields: readonly {
|
|
247
|
+
readonly objectId: string;
|
|
248
|
+
readonly field: string;
|
|
249
|
+
}[];
|
|
250
|
+
readonly skippedConflicts: readonly UndoConflict[];
|
|
251
|
+
readonly compensationMode: 'NONE' | 'QUEUED' | 'MANUAL_REQUIRED';
|
|
252
|
+
}
|
|
253
|
+
export type Intent = {
|
|
254
|
+
readonly kind: 'Verify';
|
|
255
|
+
readonly verifyId: string;
|
|
256
|
+
readonly attemptId: string;
|
|
257
|
+
readonly stage: WitnessStage;
|
|
258
|
+
readonly budgetCpuMs: number;
|
|
259
|
+
readonly requireNearMiss: boolean;
|
|
260
|
+
readonly binding: Binding;
|
|
261
|
+
} | {
|
|
262
|
+
readonly kind: 'Deliver';
|
|
263
|
+
readonly effectId: string;
|
|
264
|
+
readonly batchId: string;
|
|
265
|
+
readonly scopeId: string;
|
|
266
|
+
readonly classId: string;
|
|
267
|
+
readonly recipientId: string;
|
|
268
|
+
readonly supportsCas: boolean;
|
|
269
|
+
readonly binding: Binding;
|
|
270
|
+
readonly postCommitScopeHash: string;
|
|
271
|
+
readonly approvalExpiresAtMs: number | null;
|
|
272
|
+
readonly payload: unknown;
|
|
273
|
+
} | {
|
|
274
|
+
readonly kind: 'Reconcile';
|
|
275
|
+
readonly effectId: string;
|
|
276
|
+
readonly recipientId: string;
|
|
277
|
+
readonly attemptNumber: number;
|
|
278
|
+
} | {
|
|
279
|
+
readonly kind: 'Compensate';
|
|
280
|
+
readonly compensationId: string;
|
|
281
|
+
readonly originalEffectId: string;
|
|
282
|
+
readonly recipientId: string;
|
|
283
|
+
readonly supportsCas: boolean;
|
|
284
|
+
readonly inversePayload: unknown;
|
|
285
|
+
};
|
|
286
|
+
export type Decision = {
|
|
287
|
+
readonly code: 'ALLOW';
|
|
288
|
+
readonly reason: string;
|
|
289
|
+
} | {
|
|
290
|
+
readonly code: 'REJECT';
|
|
291
|
+
readonly reason: string;
|
|
292
|
+
} | {
|
|
293
|
+
readonly code: 'PAUSE';
|
|
294
|
+
readonly reason: string;
|
|
295
|
+
} | {
|
|
296
|
+
readonly code: 'HALT';
|
|
297
|
+
readonly reason: string;
|
|
298
|
+
};
|
|
299
|
+
export interface BudgetCounters {
|
|
300
|
+
readonly attempts: number;
|
|
301
|
+
readonly failStreak: number;
|
|
302
|
+
readonly conflictStreak: number;
|
|
303
|
+
readonly cpuMs: number;
|
|
304
|
+
readonly costMicroUnits: number;
|
|
305
|
+
}
|
|
306
|
+
export interface KernelMetrics {
|
|
307
|
+
readonly idempotentReplays: number;
|
|
308
|
+
readonly redactedSecretsTotal: number;
|
|
309
|
+
readonly rejectedCount: number;
|
|
310
|
+
readonly orphanVerdicts: number;
|
|
311
|
+
}
|
|
312
|
+
export type TaskStatus = 'ACTIVE' | 'PAUSED' | 'HALTED';
|
|
313
|
+
export interface LogEntry {
|
|
314
|
+
readonly schemaVersion: number;
|
|
315
|
+
readonly hashAlg: HashAlgorithm;
|
|
316
|
+
readonly serverSeq: number;
|
|
317
|
+
readonly opId: string;
|
|
318
|
+
readonly payloadHash: string;
|
|
319
|
+
readonly timestampMs: number;
|
|
320
|
+
readonly origin: Origin;
|
|
321
|
+
readonly scopeId: string;
|
|
322
|
+
readonly classId: string;
|
|
323
|
+
readonly epoch: number;
|
|
324
|
+
readonly scopeHash: string;
|
|
325
|
+
readonly inputSnapshotHash: string;
|
|
326
|
+
readonly diffHash: string | null;
|
|
327
|
+
readonly kind: KernelEvent['kind'];
|
|
328
|
+
readonly applied: boolean;
|
|
329
|
+
readonly decision: Decision;
|
|
330
|
+
readonly prevEntryHash: string;
|
|
331
|
+
readonly entryHash: string;
|
|
332
|
+
readonly undoReport?: UndoReport;
|
|
333
|
+
}
|
|
334
|
+
export interface OpIndexRecord {
|
|
335
|
+
readonly opId: string;
|
|
336
|
+
readonly payloadHash: string;
|
|
337
|
+
readonly decision: Decision;
|
|
338
|
+
readonly applied: boolean;
|
|
339
|
+
readonly serverSeq: number;
|
|
340
|
+
readonly undoReport?: UndoReport;
|
|
341
|
+
}
|
|
342
|
+
export interface KernelState {
|
|
343
|
+
readonly schemaVersion: number;
|
|
344
|
+
readonly serverSeq: number;
|
|
345
|
+
/** Global epoch. It grows on every human action, orders the log and governs scope `*`. */
|
|
346
|
+
readonly epoch: number;
|
|
347
|
+
/** Per-scope epochs. Key `*` counts human actions that affect every scope. */
|
|
348
|
+
readonly scopeEpochs: Readonly<Record<string, number>>;
|
|
349
|
+
readonly lastNowMs: number;
|
|
350
|
+
readonly taskStatus: TaskStatus;
|
|
351
|
+
readonly haltReason: string | null;
|
|
352
|
+
readonly pauseReason: string | null;
|
|
353
|
+
readonly policy: PolicyConfig;
|
|
354
|
+
readonly policyHash: string;
|
|
355
|
+
readonly slots: Readonly<Record<string, StateSlotValue>>;
|
|
356
|
+
readonly pins: readonly PinPolicy[];
|
|
357
|
+
readonly leases: readonly Lease2D[];
|
|
358
|
+
readonly nextLeaseEpoch: number;
|
|
359
|
+
readonly activeAttempts: readonly AttemptState[];
|
|
360
|
+
readonly recentArchivedAttempts: readonly AttemptState[];
|
|
361
|
+
readonly batches: readonly CommittedBatchRecord[];
|
|
362
|
+
readonly effects: readonly EffectRecord[];
|
|
363
|
+
readonly spentApprovals: readonly string[];
|
|
364
|
+
readonly budgets: BudgetCounters;
|
|
365
|
+
readonly undoExpiredScopes: readonly string[];
|
|
366
|
+
readonly toolClusterStats: Readonly<Record<string, ToolClusterStats>>;
|
|
367
|
+
readonly clusters: readonly ClusterRecord[];
|
|
368
|
+
readonly recentOps: readonly OpIndexRecord[];
|
|
369
|
+
readonly lastEntryHash: string;
|
|
370
|
+
readonly metrics: KernelMetrics;
|
|
371
|
+
}
|
|
372
|
+
export type KernelEvent = {
|
|
373
|
+
readonly kind: 'PolicyUpdated';
|
|
374
|
+
readonly policy: Partial<PolicyConfig>;
|
|
375
|
+
readonly scopeId?: string;
|
|
376
|
+
} | {
|
|
377
|
+
readonly kind: 'HumanEdit';
|
|
378
|
+
readonly scopeId: string;
|
|
379
|
+
readonly classId: string;
|
|
380
|
+
readonly objectId: string;
|
|
381
|
+
readonly field: string;
|
|
382
|
+
readonly value: unknown;
|
|
383
|
+
readonly parentObjectId?: string;
|
|
384
|
+
readonly autoPinTtlMs?: number;
|
|
385
|
+
} | {
|
|
386
|
+
readonly kind: 'SetPin';
|
|
387
|
+
readonly pin: PinPolicy;
|
|
388
|
+
} | {
|
|
389
|
+
readonly kind: 'RemovePin';
|
|
390
|
+
readonly pinId: string;
|
|
391
|
+
readonly scopeId: string;
|
|
392
|
+
readonly reason: string;
|
|
393
|
+
} | {
|
|
394
|
+
readonly kind: 'HumanHalt';
|
|
395
|
+
readonly scopeId: string;
|
|
396
|
+
readonly reason: string;
|
|
397
|
+
} | {
|
|
398
|
+
readonly kind: 'HumanResume';
|
|
399
|
+
readonly scopeId: string;
|
|
400
|
+
readonly extraAttempts?: number;
|
|
401
|
+
readonly extraCpuMs?: number;
|
|
402
|
+
readonly extraCostMicroUnits?: number;
|
|
403
|
+
} | {
|
|
404
|
+
readonly kind: 'HumanReset';
|
|
405
|
+
readonly scopeId: string;
|
|
406
|
+
readonly reason: string;
|
|
407
|
+
} | {
|
|
408
|
+
readonly kind: 'AcquireLease';
|
|
409
|
+
readonly leaseId: string;
|
|
410
|
+
readonly scopeId: string;
|
|
411
|
+
readonly classId: string;
|
|
412
|
+
readonly attemptId: string;
|
|
413
|
+
readonly ttlMs?: number;
|
|
414
|
+
readonly units: ResourceUnits;
|
|
415
|
+
} | {
|
|
416
|
+
readonly kind: 'RenewLease';
|
|
417
|
+
readonly leaseId: string;
|
|
418
|
+
readonly leaseEpoch: number;
|
|
419
|
+
readonly ttlMs?: number;
|
|
420
|
+
} | {
|
|
421
|
+
readonly kind: 'ReleaseLease';
|
|
422
|
+
readonly leaseId: string;
|
|
423
|
+
readonly leaseEpoch: number;
|
|
424
|
+
} | {
|
|
425
|
+
readonly kind: 'OpenAttempt';
|
|
426
|
+
readonly attemptId: string;
|
|
427
|
+
readonly taskId: string;
|
|
428
|
+
readonly toolId: string;
|
|
429
|
+
readonly clusterId: string;
|
|
430
|
+
readonly executorId: string;
|
|
431
|
+
readonly scopeId: string;
|
|
432
|
+
readonly classId: string;
|
|
433
|
+
readonly expectedScopeHash: string;
|
|
434
|
+
readonly isRiskReducing?: boolean;
|
|
435
|
+
} | {
|
|
436
|
+
readonly kind: 'SubmitBatch';
|
|
437
|
+
readonly attemptId: string;
|
|
438
|
+
readonly executorId: string;
|
|
439
|
+
readonly leaseId: string;
|
|
440
|
+
readonly leaseEpoch: number;
|
|
441
|
+
readonly expectedScopeHash: string;
|
|
442
|
+
readonly ops: readonly StateOp[];
|
|
443
|
+
readonly snapshot: InputSnapshot;
|
|
444
|
+
readonly optimizationEnabled?: boolean;
|
|
445
|
+
readonly budgetCpuMs?: number;
|
|
446
|
+
readonly requireNearMiss?: boolean;
|
|
447
|
+
readonly costEstimateMicroUnits?: number;
|
|
448
|
+
readonly blobRef?: {
|
|
449
|
+
readonly blobHash: string;
|
|
450
|
+
readonly byteSize: number;
|
|
451
|
+
};
|
|
452
|
+
} | {
|
|
453
|
+
readonly kind: 'WitnessVerdict';
|
|
454
|
+
readonly attemptId: string;
|
|
455
|
+
readonly verifyId: string;
|
|
456
|
+
readonly stage: WitnessStage;
|
|
457
|
+
readonly epoch: number;
|
|
458
|
+
readonly scopeHash: string;
|
|
459
|
+
readonly inputSnapshotHash: string;
|
|
460
|
+
readonly verdict: WitnessVerdictCode;
|
|
461
|
+
readonly cpuMs: number;
|
|
462
|
+
readonly nearMissPassed: boolean;
|
|
463
|
+
readonly optimization?: OptimizationVector;
|
|
464
|
+
} | {
|
|
465
|
+
readonly kind: 'GrantApproval';
|
|
466
|
+
readonly approval: ApprovalToken;
|
|
467
|
+
} | {
|
|
468
|
+
readonly kind: 'FinalizeBatch';
|
|
469
|
+
readonly attemptId: string;
|
|
470
|
+
readonly approvalId?: string;
|
|
471
|
+
} | {
|
|
472
|
+
readonly kind: 'CancelAttempt';
|
|
473
|
+
readonly attemptId: string;
|
|
474
|
+
readonly reason: string;
|
|
475
|
+
} | {
|
|
476
|
+
readonly kind: 'EffectTransition';
|
|
477
|
+
readonly effectId: string;
|
|
478
|
+
readonly outcome: 'IN_FLIGHT' | 'APPLIED' | 'UNKNOWN' | 'REFUSED' | 'EXPIRED_BEFORE_SEND';
|
|
479
|
+
readonly recoveredFromCrash?: boolean;
|
|
480
|
+
readonly reason?: string;
|
|
481
|
+
} | {
|
|
482
|
+
readonly kind: 'OriginUndo';
|
|
483
|
+
readonly batchId: string;
|
|
484
|
+
readonly scopeId: string;
|
|
485
|
+
readonly reason: string;
|
|
486
|
+
/** What to do when some fields cannot be restored. Default: COMPENSATE_ONLY_IF_ALL_REVERTED. */
|
|
487
|
+
readonly compensationPolicy?: CompensationPolicy;
|
|
488
|
+
} | {
|
|
489
|
+
readonly kind: 'ExpireUndoWindow';
|
|
490
|
+
readonly scopeId: string;
|
|
491
|
+
} | {
|
|
492
|
+
readonly kind: 'RuntimeBudgetReported';
|
|
493
|
+
readonly scopeId: string;
|
|
494
|
+
readonly cpuMs: number;
|
|
495
|
+
readonly costMicroUnits: number;
|
|
496
|
+
};
|
|
497
|
+
export interface EventEnvelope {
|
|
498
|
+
readonly opId: string;
|
|
499
|
+
readonly nowMs: number;
|
|
500
|
+
readonly auth: AuthContext;
|
|
501
|
+
readonly event: KernelEvent;
|
|
502
|
+
readonly dp1Meta?: {
|
|
503
|
+
readonly redactedCount: number;
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
export interface UndoDependencyPatch {
|
|
507
|
+
readonly batchId: string;
|
|
508
|
+
readonly objectId: string;
|
|
509
|
+
readonly field: string;
|
|
510
|
+
readonly restoreValue: unknown;
|
|
511
|
+
}
|
|
512
|
+
export interface DeterministicHooks {
|
|
513
|
+
readonly signatureVerifier?: SignatureVerifier;
|
|
514
|
+
readonly lookupOpId?: (opId: string) => OpIndexRecord | null;
|
|
515
|
+
readonly isApprovalSpent?: (approvalId: string) => boolean;
|
|
516
|
+
readonly lookupClusterOutcome?: (toolId: string, clusterId: string) => 'CLEAN' | 'VIOLATION' | null;
|
|
517
|
+
readonly checkUndoDependencies?: (state: KernelState, patch: UndoDependencyPatch) => {
|
|
518
|
+
readonly blocked: boolean;
|
|
519
|
+
readonly reason?: string;
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
export interface StepResult {
|
|
523
|
+
readonly state: KernelState;
|
|
524
|
+
readonly decision: Decision;
|
|
525
|
+
readonly intents: readonly Intent[];
|
|
526
|
+
readonly logEntry: LogEntry | null;
|
|
527
|
+
readonly idempotentReplay: boolean;
|
|
528
|
+
readonly schemaRejected: boolean;
|
|
529
|
+
readonly undoReport?: UndoReport;
|
|
530
|
+
}
|
|
531
|
+
export interface CheckpointSnapshot {
|
|
532
|
+
readonly schemaVersion: number;
|
|
533
|
+
readonly hashAlg: HashAlgorithm;
|
|
534
|
+
readonly serverSeq: number;
|
|
535
|
+
readonly stateHash: string;
|
|
536
|
+
readonly state: KernelState;
|
|
537
|
+
readonly createdAtMs: number;
|
|
538
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DeterministicHooks, EventEnvelope, KernelEvent, KernelState, StepResult } from './types.ts';
|
|
2
|
+
export declare function handleOriginUndo(prevState: KernelState, stateAfterRedact: KernelState, cleanEnvelope: EventEnvelope, payloadHash: string, ev: Extract<KernelEvent, {
|
|
3
|
+
kind: 'OriginUndo';
|
|
4
|
+
}>, hooks?: DeterministicHooks): StepResult;
|