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.
Files changed (73) hide show
  1. package/.claude-plugin/plugin.json +11 -0
  2. package/CHANGELOG.md +32 -0
  3. package/LICENSE +21 -0
  4. package/README.md +277 -2
  5. package/SECURITY.md +36 -0
  6. package/bin/certal.mjs +12 -0
  7. package/certal.schema.json +156 -0
  8. package/dist/adapters/approval-channel.d.ts +44 -0
  9. package/dist/adapters/approval-channel.js +74 -0
  10. package/dist/adapters/commands.d.ts +73 -0
  11. package/dist/adapters/commands.js +185 -0
  12. package/dist/adapters/contracts.d.ts +59 -0
  13. package/dist/adapters/contracts.js +1 -0
  14. package/dist/adapters/file-watcher.d.ts +53 -0
  15. package/dist/adapters/file-watcher.js +142 -0
  16. package/dist/adapters/in-memory.d.ts +53 -0
  17. package/dist/adapters/in-memory.js +165 -0
  18. package/dist/adapters/index.d.ts +8 -0
  19. package/dist/adapters/index.js +8 -0
  20. package/dist/adapters/manifest.d.ts +105 -0
  21. package/dist/adapters/manifest.js +438 -0
  22. package/dist/adapters/operator-auth.d.ts +47 -0
  23. package/dist/adapters/operator-auth.js +72 -0
  24. package/dist/adapters/tool-sdk.d.ts +150 -0
  25. package/dist/adapters/tool-sdk.js +336 -0
  26. package/dist/cli/index.d.ts +1 -0
  27. package/dist/cli/index.js +1 -0
  28. package/dist/cli/main.d.ts +1 -0
  29. package/dist/cli/main.js +386 -0
  30. package/dist/kernel/common.d.ts +46 -0
  31. package/dist/kernel/common.js +238 -0
  32. package/dist/kernel/crypto.d.ts +35 -0
  33. package/dist/kernel/crypto.js +54 -0
  34. package/dist/kernel/effects.d.ts +4 -0
  35. package/dist/kernel/effects.js +178 -0
  36. package/dist/kernel/index.d.ts +9 -0
  37. package/dist/kernel/index.js +9 -0
  38. package/dist/kernel/jcs.d.ts +24 -0
  39. package/dist/kernel/jcs.js +93 -0
  40. package/dist/kernel/leases.d.ts +11 -0
  41. package/dist/kernel/leases.js +86 -0
  42. package/dist/kernel/step.d.ts +10 -0
  43. package/dist/kernel/step.js +967 -0
  44. package/dist/kernel/types.d.ts +538 -0
  45. package/dist/kernel/types.js +1 -0
  46. package/dist/kernel/undo.d.ts +4 -0
  47. package/dist/kernel/undo.js +180 -0
  48. package/dist/kernel/validation.d.ts +13 -0
  49. package/dist/kernel/validation.js +307 -0
  50. package/dist/kernel/witness.d.ts +34 -0
  51. package/dist/kernel/witness.js +279 -0
  52. package/dist/mcp/host.d.ts +141 -0
  53. package/dist/mcp/host.js +517 -0
  54. package/dist/mcp/index.d.ts +2 -0
  55. package/dist/mcp/index.js +2 -0
  56. package/dist/mcp/server.d.ts +70 -0
  57. package/dist/mcp/server.js +508 -0
  58. package/dist/runtime/dp1.d.ts +48 -0
  59. package/dist/runtime/dp1.js +229 -0
  60. package/dist/runtime/engine.d.ts +86 -0
  61. package/dist/runtime/engine.js +320 -0
  62. package/dist/runtime/index.d.ts +4 -0
  63. package/dist/runtime/index.js +4 -0
  64. package/dist/runtime/outbox.d.ts +69 -0
  65. package/dist/runtime/outbox.js +238 -0
  66. package/dist/runtime/store.d.ts +204 -0
  67. package/dist/runtime/store.js +746 -0
  68. package/package.json +91 -4
  69. package/presets/exchange-firewall.json +40 -0
  70. package/presets/sdk.json +32 -0
  71. package/presets/solver.json +22 -0
  72. package/presets/vibeops.json +34 -0
  73. package/skills/certal/SKILL.md +49 -0
@@ -0,0 +1,279 @@
1
+ import { RECENT_CLUSTERS_LIMIT, activeLeasesAt, archiveAttempt, commitEntry, computeScopeHash, recordFailStreak, replaceAttempt, scopeEpochOf, } from './common.js';
2
+ import { hashCanonical } from './jcs.js';
3
+ /**
4
+ * Epoch that the witness echoes in `WitnessVerdict.epoch`: the scope epoch stored in the pending verification.
5
+ * Returns null when the attempt is not waiting for a verdict.
6
+ */
7
+ export function pendingVerifyEpoch(state, attemptId) {
8
+ return state.activeAttempts.find((a) => a.attemptId === attemptId)?.pendingVerify?.epoch ?? null;
9
+ }
10
+ export function computeVerifyId(attemptId, epoch, scopeHash, stage) {
11
+ return hashCanonical('verify', 1, { attemptId, epoch, scopeHash, stage });
12
+ }
13
+ export function checkOptimizationDominance(opt, minImprovement) {
14
+ if (opt.pinViolations.length > 0 || opt.hardViolations.length > 0) {
15
+ return { ok: false, reason: 'WITNESS_HARD_OR_PIN_VIOLATION' };
16
+ }
17
+ const baseSet = new Set(opt.baselineViolations);
18
+ for (const v of opt.afterViolations) {
19
+ if (!baseSet.has(v)) {
20
+ return { ok: false, reason: 'DOMINANCE_NEW_VIOLATION' };
21
+ }
22
+ }
23
+ if (opt.afterViolations.length < opt.baselineViolations.length) {
24
+ return {
25
+ ok: true,
26
+ escalateCost: opt.costDeltaMicroUnits > 0,
27
+ };
28
+ }
29
+ if (opt.costDeltaMicroUnits > 0) {
30
+ return { ok: false, reason: 'DOMINANCE_NO_PROGRESS_COST_UP' };
31
+ }
32
+ if (opt.costDeltaMicroUnits > -minImprovement) {
33
+ return { ok: false, reason: 'INSUFFICIENT_IMPROVEMENT' };
34
+ }
35
+ return { ok: true, escalateCost: false };
36
+ }
37
+ /**
38
+ * Records a cluster outcome in the bounded window of recent clusters and in the per-tool counters.
39
+ * When a cluster changes its outcome, the changed record always moves to the end of the returned array.
40
+ */
41
+ export function recordClusterOutcome(state, toolId, clusterId, outcome, seq, hooks) {
42
+ const localExisting = state.clusters.find((c) => c.toolId === toolId && c.clusterId === clusterId);
43
+ const prevOutcome = hooks?.lookupClusterOutcome?.(toolId, clusterId) ?? localExisting?.outcome ?? null;
44
+ const prevStats = state.toolClusterStats[toolId] ?? { cleanCount: 0, violationCount: 0 };
45
+ if (outcome === 'CLEAN') {
46
+ if (prevOutcome !== null) {
47
+ return { clusters: state.clusters, toolClusterStats: state.toolClusterStats };
48
+ }
49
+ const appended = { toolId, clusterId, outcome: 'CLEAN', firstSeq: seq };
50
+ const nextList = [...state.clusters, appended];
51
+ const nextClusters = nextList.length > RECENT_CLUSTERS_LIMIT
52
+ ? nextList.slice(nextList.length - RECENT_CLUSTERS_LIMIT)
53
+ : nextList;
54
+ return {
55
+ clusters: nextClusters,
56
+ toolClusterStats: {
57
+ ...state.toolClusterStats,
58
+ [toolId]: {
59
+ cleanCount: prevStats.cleanCount + 1,
60
+ violationCount: prevStats.violationCount,
61
+ },
62
+ },
63
+ };
64
+ }
65
+ if (prevOutcome === 'VIOLATION') {
66
+ return { clusters: state.clusters, toolClusterStats: state.toolClusterStats };
67
+ }
68
+ const nextClean = prevOutcome === 'CLEAN' ? Math.max(0, prevStats.cleanCount - 1) : prevStats.cleanCount;
69
+ const filtered = state.clusters.filter((c) => !(c.toolId === toolId && c.clusterId === clusterId));
70
+ const updatedRec = {
71
+ toolId,
72
+ clusterId,
73
+ outcome: 'VIOLATION',
74
+ firstSeq: localExisting?.firstSeq ?? seq,
75
+ };
76
+ const nextList = [...filtered, updatedRec];
77
+ const nextClusters = nextList.length > RECENT_CLUSTERS_LIMIT
78
+ ? nextList.slice(nextList.length - RECENT_CLUSTERS_LIMIT)
79
+ : nextList;
80
+ return {
81
+ clusters: nextClusters,
82
+ toolClusterStats: {
83
+ ...state.toolClusterStats,
84
+ [toolId]: {
85
+ cleanCount: nextClean,
86
+ violationCount: prevStats.violationCount + 1,
87
+ },
88
+ },
89
+ };
90
+ }
91
+ /**
92
+ * Marks a cluster as poisoned on a KernelState. Helper for callers outside the kernel.
93
+ */
94
+ export function markClusterViolation(state, toolId, clusterId, hooks) {
95
+ const patch = recordClusterOutcome(state, toolId, clusterId, 'VIOLATION', state.serverSeq, hooks);
96
+ return patch.clusters === state.clusters ? state : { ...state, ...patch };
97
+ }
98
+ /**
99
+ * Computes the autonomy tier of a tool: Shadow -> n=59 Approval -> n=299 Auto
100
+ * with an immediate downgrade to SHADOW when a violation is found.
101
+ */
102
+ export function computeToolAutonomy(state, toolId) {
103
+ const stats = state.toolClusterStats[toolId];
104
+ const cleanClusterCount = stats?.cleanCount ?? 0;
105
+ const violationCount = stats?.violationCount ?? 0;
106
+ if (violationCount > 0) {
107
+ return { toolId, cleanClusterCount, violationCount, tier: 'SHADOW', downgraded: true };
108
+ }
109
+ let tier = 'SHADOW';
110
+ if (cleanClusterCount >= 299) {
111
+ tier = 'AUTO';
112
+ }
113
+ else if (cleanClusterCount >= 59) {
114
+ tier = 'APPROVAL';
115
+ }
116
+ return { toolId, cleanClusterCount, violationCount, tier, downgraded: false };
117
+ }
118
+ export function handleWitnessVerdict(prevState, stateAfterRedact, cleanEnvelope, payloadHash, ev, hooks) {
119
+ if (cleanEnvelope.auth.origin.kind !== 'System') {
120
+ const { nextState, decision } = recordFailStreak(stateAfterRedact, 'FORBIDDEN_ORIGIN');
121
+ return commitEntry(prevState, nextState, cleanEnvelope, payloadHash, false, decision, [], '*', '*', null, ev.inputSnapshotHash);
122
+ }
123
+ const attempt = prevState.activeAttempts.find((a) => a.attemptId === ev.attemptId);
124
+ const pv = attempt?.pendingVerify;
125
+ if (!attempt ||
126
+ attempt.status !== 'VERIFYING' ||
127
+ !pv ||
128
+ pv.verifyId !== ev.verifyId ||
129
+ pv.stage !== ev.stage ||
130
+ pv.epoch !== ev.epoch ||
131
+ pv.epoch !== scopeEpochOf(prevState, attempt.scopeId) ||
132
+ pv.scopeHash !== ev.scopeHash ||
133
+ pv.scopeHash !== computeScopeHash(prevState, attempt.scopeId, attempt.classId, cleanEnvelope.nowMs) ||
134
+ pv.inputSnapshotHash !== ev.inputSnapshotHash) {
135
+ const orphanState = {
136
+ ...stateAfterRedact,
137
+ metrics: {
138
+ ...stateAfterRedact.metrics,
139
+ orphanVerdicts: stateAfterRedact.metrics.orphanVerdicts + 1,
140
+ },
141
+ };
142
+ return commitEntry(prevState, orphanState, cleanEnvelope, payloadHash, false, { code: 'REJECT', reason: 'ORPHAN_VERDICT' }, [], attempt?.scopeId ?? '*', attempt?.classId ?? '*', attempt?.diffHash ?? null, ev.inputSnapshotHash);
143
+ }
144
+ const nextCpu = prevState.budgets.cpuMs + ev.cpuMs;
145
+ const remainingLeases = activeLeasesAt(prevState.leases, cleanEnvelope.nowMs).filter((l) => l.attemptId !== attempt.attemptId);
146
+ if (ev.cpuMs > pv.budgetCpuMs || nextCpu > prevState.policy.maxCpuMs) {
147
+ const abortedAttempt = { ...attempt, status: 'ABORTED', pendingVerify: null };
148
+ const archived = archiveAttempt(prevState, abortedAttempt);
149
+ const pausedState = {
150
+ ...stateAfterRedact,
151
+ taskStatus: 'PAUSED',
152
+ pauseReason: 'BUDGET_EXHAUSTED',
153
+ leases: remainingLeases,
154
+ budgets: { ...prevState.budgets, cpuMs: nextCpu },
155
+ ...archived,
156
+ };
157
+ return commitEntry(prevState, pausedState, cleanEnvelope, payloadHash, false, { code: 'PAUSE', reason: 'BUDGET_EXHAUSTED' }, [], attempt.scopeId, attempt.classId, attempt.diffHash, ev.inputSnapshotHash);
158
+ }
159
+ if (ev.verdict !== 'PASS' || (pv.requireNearMiss && !ev.nearMissPassed)) {
160
+ const reason = ev.verdict !== 'PASS' ? `WITNESS_${ev.verdict}` : 'NEAR_MISS_FAILED';
161
+ const abortedAttempt = { ...attempt, status: 'ABORTED', pendingVerify: null };
162
+ const archived = archiveAttempt(prevState, abortedAttempt);
163
+ const clusterPatch = recordClusterOutcome(prevState, attempt.toolId, attempt.clusterId, 'VIOLATION', prevState.serverSeq + 1, hooks);
164
+ const { nextState, decision } = recordFailStreak({
165
+ ...stateAfterRedact,
166
+ leases: remainingLeases,
167
+ ...clusterPatch,
168
+ budgets: { ...prevState.budgets, cpuMs: nextCpu },
169
+ ...archived,
170
+ }, reason);
171
+ return commitEntry(prevState, nextState, cleanEnvelope, payloadHash, false, decision, [], attempt.scopeId, attempt.classId, attempt.diffHash, ev.inputSnapshotHash);
172
+ }
173
+ let escalateCost = false;
174
+ if (attempt.optimizationEnabled) {
175
+ if (!ev.optimization) {
176
+ const abortedAttempt = { ...attempt, status: 'ABORTED', pendingVerify: null };
177
+ const archived = archiveAttempt(prevState, abortedAttempt);
178
+ const clusterPatch = recordClusterOutcome(prevState, attempt.toolId, attempt.clusterId, 'VIOLATION', prevState.serverSeq + 1, hooks);
179
+ const { nextState, decision } = recordFailStreak({
180
+ ...stateAfterRedact,
181
+ leases: remainingLeases,
182
+ ...clusterPatch,
183
+ budgets: { ...prevState.budgets, cpuMs: nextCpu },
184
+ ...archived,
185
+ }, 'OPTIMIZATION_VECTOR_MISSING');
186
+ return commitEntry(prevState, nextState, cleanEnvelope, payloadHash, false, decision, [], attempt.scopeId, attempt.classId, attempt.diffHash, ev.inputSnapshotHash);
187
+ }
188
+ const dom = checkOptimizationDominance(ev.optimization, prevState.policy.minImprovementMicroUnits);
189
+ if (!dom.ok) {
190
+ const abortedAttempt = { ...attempt, status: 'ABORTED', pendingVerify: null };
191
+ const archived = archiveAttempt(prevState, abortedAttempt);
192
+ const clusterPatch = recordClusterOutcome(prevState, attempt.toolId, attempt.clusterId, 'VIOLATION', prevState.serverSeq + 1, hooks);
193
+ const { nextState, decision } = recordFailStreak({
194
+ ...stateAfterRedact,
195
+ leases: remainingLeases,
196
+ ...clusterPatch,
197
+ budgets: { ...prevState.budgets, cpuMs: nextCpu },
198
+ ...archived,
199
+ }, dom.reason);
200
+ return commitEntry(prevState, nextState, cleanEnvelope, payloadHash, false, decision, [], attempt.scopeId, attempt.classId, attempt.diffHash, ev.inputSnapshotHash);
201
+ }
202
+ escalateCost = dom.escalateCost;
203
+ }
204
+ const stageRec = {
205
+ verifyId: ev.verifyId,
206
+ stage: ev.stage,
207
+ verdict: ev.verdict,
208
+ cpuMs: ev.cpuMs,
209
+ nearMissPassed: ev.nearMissPassed,
210
+ ...(ev.optimization !== undefined ? { optimization: ev.optimization } : {}),
211
+ };
212
+ const nextStages = [...attempt.stages, stageRec];
213
+ const stageList = prevState.policy.requiredWitnessStages;
214
+ const idx = stageList.indexOf(ev.stage);
215
+ const hasNextStage = idx >= 0 && idx + 1 < stageList.length;
216
+ if (hasNextStage) {
217
+ const nextStage = stageList[idx + 1];
218
+ const nextVerifyId = computeVerifyId(attempt.attemptId, scopeEpochOf(prevState, attempt.scopeId), pv.scopeHash, nextStage);
219
+ const remainingCpu = Math.max(0, prevState.policy.maxCpuMs - nextCpu);
220
+ const nextRequireNearMiss = nextStage === 'L2';
221
+ const updatedAttempt = {
222
+ ...attempt,
223
+ stages: nextStages,
224
+ needsApproval: attempt.needsApproval || escalateCost,
225
+ approvalReason: escalateCost ? 'COST_REGRESSION_APPROVAL' : attempt.approvalReason,
226
+ lastOptimization: ev.optimization ?? attempt.lastOptimization,
227
+ pendingVerify: {
228
+ verifyId: nextVerifyId,
229
+ stage: nextStage,
230
+ attemptId: attempt.attemptId,
231
+ epoch: scopeEpochOf(prevState, attempt.scopeId),
232
+ scopeHash: pv.scopeHash,
233
+ inputSnapshotHash: pv.inputSnapshotHash,
234
+ budgetCpuMs: remainingCpu,
235
+ requireNearMiss: nextRequireNearMiss,
236
+ },
237
+ };
238
+ const nextIntent = {
239
+ kind: 'Verify',
240
+ verifyId: nextVerifyId,
241
+ attemptId: attempt.attemptId,
242
+ stage: nextStage,
243
+ budgetCpuMs: remainingCpu,
244
+ requireNearMiss: nextRequireNearMiss,
245
+ binding: attempt.binding,
246
+ };
247
+ const nextState = {
248
+ ...stateAfterRedact,
249
+ budgets: { ...prevState.budgets, cpuMs: nextCpu },
250
+ activeAttempts: replaceAttempt(prevState.activeAttempts, updatedAttempt),
251
+ };
252
+ return commitEntry(prevState, nextState, cleanEnvelope, payloadHash, true, { code: 'ALLOW', reason: 'STAGE_PASSED_NEXT_VERIFY' }, [nextIntent], attempt.scopeId, attempt.classId, attempt.diffHash, ev.inputSnapshotHash);
253
+ }
254
+ const finalNeedsApproval = attempt.needsApproval || escalateCost;
255
+ const finalApprovalReason = escalateCost
256
+ ? 'COST_REGRESSION_APPROVAL'
257
+ : attempt.approvalReason ?? (finalNeedsApproval ? 'APPROVAL_REQUIRED' : null);
258
+ const verifiedAttempt = {
259
+ ...attempt,
260
+ status: 'VERIFIED',
261
+ stages: nextStages,
262
+ pendingVerify: null,
263
+ needsApproval: finalNeedsApproval,
264
+ approvalReason: finalApprovalReason,
265
+ lastOptimization: ev.optimization ?? attempt.lastOptimization,
266
+ };
267
+ const needsPauseForC2 = finalNeedsApproval && verifiedAttempt.approval === null;
268
+ const nextState = {
269
+ ...stateAfterRedact,
270
+ budgets: { ...prevState.budgets, cpuMs: nextCpu },
271
+ taskStatus: needsPauseForC2 ? 'PAUSED' : prevState.taskStatus,
272
+ pauseReason: needsPauseForC2 ? (finalApprovalReason ?? 'APPROVAL_REQUIRED') : prevState.pauseReason,
273
+ activeAttempts: replaceAttempt(prevState.activeAttempts, verifiedAttempt),
274
+ };
275
+ const decision = needsPauseForC2
276
+ ? { code: 'PAUSE', reason: finalApprovalReason ?? 'APPROVAL_REQUIRED' }
277
+ : { code: 'ALLOW', reason: 'WITNESS_VERIFIED' };
278
+ return commitEntry(prevState, nextState, cleanEnvelope, payloadHash, true, decision, [], attempt.scopeId, attempt.classId, attempt.diffHash, ev.inputSnapshotHash);
279
+ }
@@ -0,0 +1,141 @@
1
+ import type { ApprovalToken, KernelState, StepResult } from '../kernel/index.ts';
2
+ import { CertalRuntime } from '../runtime/index.ts';
3
+ import type { RuntimePort } from '../runtime/index.ts';
4
+ import { CommandWitness } from '../adapters/commands.ts';
5
+ import type { ResolvedManifest } from '../adapters/manifest.ts';
6
+ /**
7
+ * One Certal host per state directory: the manifest, the SQLite log, the runtime with its single
8
+ * writer, the outbox worker and the operator endpoint. Agents reach it through the MCP server.
9
+ * The operator reaches it through the CLI, which signs every command with the Ed25519 key.
10
+ */
11
+ export declare const DB_FILE = "certal.db";
12
+ export declare const RUNTIME_FILE = "runtime.json";
13
+ export interface RuntimeInfo {
14
+ readonly pid: number;
15
+ readonly operatorPort: number;
16
+ readonly startedAtMs: number;
17
+ }
18
+ export interface PendingApproval {
19
+ readonly attemptId: string;
20
+ readonly scopeId: string;
21
+ readonly toolId: string;
22
+ readonly executorId: string;
23
+ readonly reason: string | null;
24
+ readonly binding: {
25
+ readonly diffHash: string;
26
+ readonly scopeHash: string;
27
+ readonly inputSnapshotHash: string;
28
+ };
29
+ readonly bindingHash: string;
30
+ readonly diffSummary: readonly string[];
31
+ }
32
+ export interface HostStatus {
33
+ readonly taskStatus: KernelState['taskStatus'];
34
+ readonly pauseReason: string | null;
35
+ readonly haltReason: string | null;
36
+ readonly serverSeq: number;
37
+ readonly lastEntryHash: string;
38
+ readonly scopeEpochs: Readonly<Record<string, number>>;
39
+ readonly leases: readonly {
40
+ readonly leaseId: string;
41
+ readonly scopeId: string;
42
+ readonly classId: string;
43
+ readonly ownerId: string;
44
+ readonly attemptId: string;
45
+ readonly leaseEpoch: number;
46
+ readonly expiresInMs: number;
47
+ }[];
48
+ readonly autonomy: readonly {
49
+ readonly toolId: string;
50
+ readonly tier: string;
51
+ readonly toApproval: string;
52
+ readonly toAuto: string;
53
+ readonly violations: number;
54
+ }[];
55
+ readonly pendingApprovals: readonly PendingApproval[];
56
+ }
57
+ export interface OperatorReply {
58
+ readonly ok: boolean;
59
+ readonly decision?: string;
60
+ readonly reason?: string;
61
+ readonly data?: unknown;
62
+ }
63
+ export declare class HostBusyError extends Error {
64
+ readonly info: RuntimeInfo;
65
+ constructor(info: RuntimeInfo);
66
+ }
67
+ /** The process that owns the state directory right now, or null. A stale file is removed. */
68
+ export declare function readRuntimeInfo(stateDir: string): RuntimeInfo | null;
69
+ /** Operator public keys that the database carries, so an audit needs no other file. */
70
+ export declare function readStoredOperatorKeys(dbPath: string): Record<string, string>;
71
+ export declare function describeOps(ops: readonly {
72
+ readonly objectId: string;
73
+ readonly field: string;
74
+ readonly reversibility: string;
75
+ readonly externalEffect?: unknown;
76
+ }[]): string[];
77
+ export declare function pendingApprovalsOf(state: KernelState): PendingApproval[];
78
+ export declare function buildStatus(state: KernelState, nowMs: number, toolIds: readonly string[]): HostStatus;
79
+ /** Reads the state from the log without taking ownership of the state directory. */
80
+ export declare function readStatus(cwd: string): {
81
+ readonly status: HostStatus;
82
+ readonly manifest: ResolvedManifest;
83
+ readonly live: boolean;
84
+ };
85
+ export interface HostOptions {
86
+ readonly cwd: string;
87
+ readonly watch?: boolean;
88
+ /** Start the signed operator endpoint and take ownership of the state directory. Default: true. */
89
+ readonly serveOperator?: boolean;
90
+ }
91
+ export declare class CertalHost {
92
+ readonly manifest: ResolvedManifest;
93
+ readonly runtime: CertalRuntime;
94
+ readonly witness: CommandWitness;
95
+ readonly agentPort: RuntimePort;
96
+ readonly systemPort: RuntimePort;
97
+ private readonly humanPort;
98
+ private readonly outbox;
99
+ private readonly channel;
100
+ private readonly notified;
101
+ private readonly seenNonces;
102
+ private watcher;
103
+ private operatorServer;
104
+ private ownsDirectory;
105
+ private closed;
106
+ private checkpointSeq;
107
+ private humanOpCounter;
108
+ private shutdownRequested;
109
+ /** Declared pins that the kernel refused while the task was halted. They are set after a reset. */
110
+ private deferredPins;
111
+ /** Called after the operator asks the host to stop. */
112
+ onShutdown: (() => void) | null;
113
+ private constructor();
114
+ static open(options: HostOptions): Promise<CertalHost>;
115
+ get humanId(): string;
116
+ private humanAuth;
117
+ /** A manifest that became stricter since the log started is applied. A looser one is refused. */
118
+ private applyPolicyDrift;
119
+ /**
120
+ * Sets every declared pin that the state does not hold yet. Pins are never removed from here.
121
+ * A halted task takes no pin, so such pins are kept aside and set right after the reset.
122
+ * Any other refusal stops the start: the host does not run without a declared pin.
123
+ */
124
+ private applyPins;
125
+ drainOutbox(): Promise<void>;
126
+ private checkpoint;
127
+ status(): HostStatus;
128
+ /** Announces a pending approval once per attempt. A token that the channel returns is granted at once. */
129
+ announceApproval(attemptId: string): Promise<void>;
130
+ grant(token: ApprovalToken): Promise<StepResult>;
131
+ private humanOp;
132
+ /** Runs one operator command. The caller has already established that a human issued it. */
133
+ operatorCommand(command: string, args: Record<string, unknown>): Promise<OperatorReply>;
134
+ private startWatcher;
135
+ /** Resolves when the file watcher has handled every change seen so far. */
136
+ watcherSettled(): Promise<void>;
137
+ private acceptSigned;
138
+ private startOperatorEndpoint;
139
+ scopeEpoch(scopeId: string): number;
140
+ close(): void;
141
+ }