@ngockhoale/ckit 0.0.0-stage → 0.1.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/.env.example +21 -0
- package/README.md +70 -2
- package/dist/src/adapters/agent/claude/errors.d.ts +13 -0
- package/dist/src/adapters/agent/claude/errors.js +16 -0
- package/dist/src/adapters/agent/claude/normalize.d.ts +11 -0
- package/dist/src/adapters/agent/claude/normalize.js +83 -0
- package/dist/src/adapters/agent/errors.d.ts +13 -0
- package/dist/src/adapters/agent/errors.js +19 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.d.ts +70 -0
- package/dist/src/adapters/agent/fixtures/claude-transcript.js +15 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.d.ts +60 -0
- package/dist/src/adapters/agent/fixtures/omp-transcript.js +14 -0
- package/dist/src/adapters/agent/normalize.d.ts +18 -0
- package/dist/src/adapters/agent/normalize.js +77 -0
- package/dist/src/adapters/agent/transport.d.ts +35 -0
- package/dist/src/adapters/agent/transport.js +39 -0
- package/dist/src/adapters/agent/worker-service.d.ts +49 -0
- package/dist/src/adapters/agent/worker-service.js +77 -0
- package/dist/src/adapters/fake/fake-advisor.d.ts +15 -0
- package/dist/src/adapters/fake/fake-advisor.js +29 -0
- package/dist/src/adapters/fake/fake-agent.d.ts +12 -0
- package/dist/src/adapters/fake/fake-agent.js +21 -0
- package/dist/src/adapters/fake/fake-store.d.ts +13 -0
- package/dist/src/adapters/fake/fake-store.js +23 -0
- package/dist/src/adapters/fake/fake-web.d.ts +12 -0
- package/dist/src/adapters/fake/fake-web.js +21 -0
- package/dist/src/adapters/fake/fault-injector.d.ts +18 -0
- package/dist/src/adapters/fake/fault-injector.js +64 -0
- package/dist/src/adapters/fake/virtual-clock.d.ts +12 -0
- package/dist/src/adapters/fake/virtual-clock.js +35 -0
- package/dist/src/adapters/launch/discover.d.ts +18 -0
- package/dist/src/adapters/launch/discover.js +55 -0
- package/dist/src/adapters/launch/executor.d.ts +117 -0
- package/dist/src/adapters/launch/executor.js +383 -0
- package/dist/src/adapters/launch/profile.d.ts +35 -0
- package/dist/src/adapters/launch/profile.js +73 -0
- package/dist/src/adapters/launch/spawn.d.ts +29 -0
- package/dist/src/adapters/launch/spawn.js +18 -0
- package/dist/src/adapters/openai/openai-advisor.d.ts +56 -0
- package/dist/src/adapters/openai/openai-advisor.js +146 -0
- package/dist/src/cli/ckit.d.ts +5 -0
- package/dist/src/cli/ckit.js +384 -0
- package/dist/src/cli/demo.d.ts +1 -0
- package/dist/src/cli/demo.js +30 -0
- package/dist/src/cli/lifecycle.d.ts +19 -0
- package/dist/src/cli/lifecycle.js +90 -0
- package/dist/src/cli/sessions.d.ts +10 -0
- package/dist/src/cli/sessions.js +381 -0
- package/dist/src/cli/setup.d.ts +11 -0
- package/dist/src/cli/setup.js +115 -0
- package/dist/src/committee/decision.d.ts +84 -0
- package/dist/src/committee/decision.js +167 -0
- package/dist/src/committee/handover.d.ts +115 -0
- package/dist/src/committee/handover.js +191 -0
- package/dist/src/committee/no-progress.d.ts +44 -0
- package/dist/src/committee/no-progress.js +64 -0
- package/dist/src/committee/primary-registry.d.ts +15 -0
- package/dist/src/committee/primary-registry.js +60 -0
- package/dist/src/committee/reply-parser.d.ts +28 -0
- package/dist/src/committee/reply-parser.js +53 -0
- package/dist/src/committee/reviewer-scheduler.d.ts +101 -0
- package/dist/src/committee/reviewer-scheduler.js +163 -0
- package/dist/src/committee/role-epoch.d.ts +91 -0
- package/dist/src/committee/role-epoch.js +154 -0
- package/dist/src/core/control.d.ts +18 -0
- package/dist/src/core/control.js +29 -0
- package/dist/src/core/entities.d.ts +166 -0
- package/dist/src/core/entities.js +119 -0
- package/dist/src/core/errors.d.ts +9 -0
- package/dist/src/core/errors.js +17 -0
- package/dist/src/core/events.d.ts +72 -0
- package/dist/src/core/events.js +125 -0
- package/dist/src/core/ids.d.ts +47 -0
- package/dist/src/core/ids.js +32 -0
- package/dist/src/core/machine.d.ts +55 -0
- package/dist/src/core/machine.js +110 -0
- package/dist/src/core/policy.d.ts +34 -0
- package/dist/src/core/policy.js +59 -0
- package/dist/src/core/provenance.d.ts +20 -0
- package/dist/src/core/provenance.js +21 -0
- package/dist/src/core/record.d.ts +35 -0
- package/dist/src/core/record.js +67 -0
- package/dist/src/core/replay.d.ts +10 -0
- package/dist/src/core/replay.js +36 -0
- package/dist/src/core/run-task.d.ts +20 -0
- package/dist/src/core/run-task.js +48 -0
- package/dist/src/diagnostics/doctor.d.ts +78 -0
- package/dist/src/diagnostics/doctor.js +365 -0
- package/dist/src/diagnostics/journal-lock.d.ts +38 -0
- package/dist/src/diagnostics/journal-lock.js +181 -0
- package/dist/src/evidence/linker.d.ts +44 -0
- package/dist/src/evidence/linker.js +75 -0
- package/dist/src/evidence/report-parser.d.ts +27 -0
- package/dist/src/evidence/report-parser.js +17 -0
- package/dist/src/evidence/store.d.ts +36 -0
- package/dist/src/evidence/store.js +57 -0
- package/dist/src/gui/server.d.ts +27 -0
- package/dist/src/gui/server.js +497 -0
- package/dist/src/host/checkpoint.d.ts +22 -0
- package/dist/src/host/checkpoint.js +74 -0
- package/dist/src/host/export.d.ts +52 -0
- package/dist/src/host/export.js +45 -0
- package/dist/src/host/ipc.d.ts +57 -0
- package/dist/src/host/ipc.js +124 -0
- package/dist/src/host/leases.d.ts +27 -0
- package/dist/src/host/leases.js +40 -0
- package/dist/src/host/retention.d.ts +47 -0
- package/dist/src/host/retention.js +130 -0
- package/dist/src/host/supervisor.d.ts +59 -0
- package/dist/src/host/supervisor.js +64 -0
- package/dist/src/intake/owner-intake.d.ts +31 -0
- package/dist/src/intake/owner-intake.js +97 -0
- package/dist/src/intake/types.d.ts +46 -0
- package/dist/src/intake/types.js +2 -0
- package/dist/src/intent/context-packet.d.ts +68 -0
- package/dist/src/intent/context-packet.js +76 -0
- package/dist/src/intent/idea-ledger.d.ts +50 -0
- package/dist/src/intent/idea-ledger.js +136 -0
- package/dist/src/intent/ledger.d.ts +35 -0
- package/dist/src/intent/ledger.js +40 -0
- package/dist/src/intent/registry.d.ts +51 -0
- package/dist/src/intent/registry.js +44 -0
- package/dist/src/intent/revision.d.ts +37 -0
- package/dist/src/intent/revision.js +48 -0
- package/dist/src/orchestration/dispatcher.d.ts +32 -0
- package/dist/src/orchestration/dispatcher.js +136 -0
- package/dist/src/orchestration/milestone-loop.d.ts +149 -0
- package/dist/src/orchestration/milestone-loop.js +132 -0
- package/dist/src/orchestration/recovery-coordinator.d.ts +74 -0
- package/dist/src/orchestration/recovery-coordinator.js +180 -0
- package/dist/src/orchestration/work-order-contract.d.ts +44 -0
- package/dist/src/orchestration/work-order-contract.js +85 -0
- package/dist/src/orchestration/work-queue.d.ts +56 -0
- package/dist/src/orchestration/work-queue.js +95 -0
- package/dist/src/ports/advisor.d.ts +33 -0
- package/dist/src/ports/advisor.js +2 -0
- package/dist/src/ports/agent.d.ts +31 -0
- package/dist/src/ports/agent.js +2 -0
- package/dist/src/ports/capabilities.d.ts +3 -0
- package/dist/src/ports/capabilities.js +5 -0
- package/dist/src/ports/clock.d.ts +5 -0
- package/dist/src/ports/clock.js +5 -0
- package/dist/src/ports/store.d.ts +13 -0
- package/dist/src/ports/store.js +2 -0
- package/dist/src/ports/web.d.ts +29 -0
- package/dist/src/ports/web.js +2 -0
- package/dist/src/run/api-run.d.ts +49 -0
- package/dist/src/run/api-run.js +173 -0
- package/dist/src/run/plan-run.d.ts +22 -0
- package/dist/src/run/plan-run.js +233 -0
- package/dist/src/run/plan.d.ts +36 -0
- package/dist/src/run/plan.js +119 -0
- package/dist/src/run/verify.d.ts +25 -0
- package/dist/src/run/verify.js +81 -0
- package/dist/src/security/redact.d.ts +7 -0
- package/dist/src/security/redact.js +21 -0
- package/dist/src/settings/env-config.d.ts +64 -0
- package/dist/src/settings/env-config.js +232 -0
- package/dist/src/storage/artifacts.d.ts +30 -0
- package/dist/src/storage/artifacts.js +105 -0
- package/dist/src/storage/audit.d.ts +6 -0
- package/dist/src/storage/audit.js +6 -0
- package/dist/src/storage/db.d.ts +9 -0
- package/dist/src/storage/db.js +43 -0
- package/dist/src/storage/events.d.ts +20 -0
- package/dist/src/storage/events.js +69 -0
- package/dist/src/storage/migrations.d.ts +8 -0
- package/dist/src/storage/migrations.js +48 -0
- package/dist/src/storage/outbox.d.ts +25 -0
- package/dist/src/storage/outbox.js +40 -0
- package/dist/src/storage/projections.d.ts +18 -0
- package/dist/src/storage/projections.js +40 -0
- package/dist/src/storage/reconcile.d.ts +14 -0
- package/dist/src/storage/reconcile.js +93 -0
- package/dist/src/storage/reservations.d.ts +12 -0
- package/dist/src/storage/reservations.js +80 -0
- package/dist/src/storage/store.d.ts +34 -0
- package/dist/src/storage/store.js +105 -0
- package/dist/src/team/attachments.d.ts +22 -0
- package/dist/src/team/attachments.js +211 -0
- package/dist/src/team/cli-models.d.ts +24 -0
- package/dist/src/team/cli-models.js +72 -0
- package/dist/src/team/config.d.ts +20 -0
- package/dist/src/team/config.js +113 -0
- package/dist/src/team/engine.d.ts +28 -0
- package/dist/src/team/engine.js +443 -0
- package/dist/src/team/journal.d.ts +30 -0
- package/dist/src/team/journal.js +70 -0
- package/dist/src/team/runners.d.ts +79 -0
- package/dist/src/team/runners.js +436 -0
- package/dist/src/team/secrets.d.ts +10 -0
- package/dist/src/team/secrets.js +68 -0
- package/dist/src/team/types.d.ts +157 -0
- package/dist/src/team/types.js +5 -0
- package/dist/src/tui/app.d.ts +29 -0
- package/dist/src/tui/app.js +96 -0
- package/dist/src/tui/control-model.d.ts +101 -0
- package/dist/src/tui/control-model.js +109 -0
- package/dist/src/tui/control-screens.d.ts +27 -0
- package/dist/src/tui/control-screens.js +85 -0
- package/dist/src/tui/graph-model.d.ts +34 -0
- package/dist/src/tui/graph-model.js +29 -0
- package/dist/src/tui/graph-screens.d.ts +13 -0
- package/dist/src/tui/graph-screens.js +4 -0
- package/dist/src/tui/inspector-model.d.ts +150 -0
- package/dist/src/tui/inspector-model.js +15 -0
- package/dist/src/tui/inspector-screens.d.ts +14 -0
- package/dist/src/tui/inspector-screens.js +61 -0
- package/dist/src/tui/live.d.ts +16 -0
- package/dist/src/tui/live.js +39 -0
- package/dist/src/tui/mission-action-screens.d.ts +15 -0
- package/dist/src/tui/mission-action-screens.js +105 -0
- package/dist/src/tui/mission-actions.d.ts +46 -0
- package/dist/src/tui/mission-actions.js +53 -0
- package/dist/src/tui/mission-model.d.ts +120 -0
- package/dist/src/tui/mission-model.js +164 -0
- package/dist/src/tui/mission-nav.d.ts +82 -0
- package/dist/src/tui/mission-nav.js +131 -0
- package/dist/src/tui/mission-plan-screens.d.ts +11 -0
- package/dist/src/tui/mission-plan-screens.js +40 -0
- package/dist/src/tui/mission-plan.d.ts +45 -0
- package/dist/src/tui/mission-plan.js +166 -0
- package/dist/src/tui/mission-screens.d.ts +7 -0
- package/dist/src/tui/mission-screens.js +263 -0
- package/dist/src/tui/provenance-label.d.ts +11 -0
- package/dist/src/tui/provenance-label.js +16 -0
- package/dist/src/tui/screens.d.ts +10 -0
- package/dist/src/tui/screens.js +34 -0
- package/dist/src/tui/session-outcome.d.ts +14 -0
- package/dist/src/tui/session-outcome.js +57 -0
- package/dist/src/tui/setup-model.d.ts +159 -0
- package/dist/src/tui/setup-model.js +234 -0
- package/dist/src/tui/setup-screens.d.ts +66 -0
- package/dist/src/tui/setup-screens.js +72 -0
- package/dist/src/tui/team/app.d.ts +24 -0
- package/dist/src/tui/team/app.js +228 -0
- package/dist/src/tui/team/demo-handle.d.ts +22 -0
- package/dist/src/tui/team/demo-handle.js +42 -0
- package/dist/src/tui/team/model.d.ts +81 -0
- package/dist/src/tui/team/model.js +133 -0
- package/gui/app.css +177 -0
- package/gui/app.js +677 -0
- package/gui/index.html +51 -0
- package/gui/network.js +413 -0
- package/package.json +44 -4
- package/src/storage/schema.sql +42 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { validateEnvelope } from '../core/events.js';
|
|
2
|
+
import { FencedLeaseError, LeaseManager } from '../host/leases.js';
|
|
3
|
+
import { RetentionManager } from '../host/retention.js';
|
|
4
|
+
import { EventJournal, StorageBackpressureError } from '../storage/events.js';
|
|
5
|
+
import { DurableReconciliation } from '../storage/reconcile.js';
|
|
6
|
+
const MAX_REPLAY_EVENTS = 5000;
|
|
7
|
+
export class RecoveryCoordinator {
|
|
8
|
+
db;
|
|
9
|
+
options;
|
|
10
|
+
leases;
|
|
11
|
+
reconciliation;
|
|
12
|
+
journal;
|
|
13
|
+
clock;
|
|
14
|
+
batchSize;
|
|
15
|
+
lease = null;
|
|
16
|
+
paused = false;
|
|
17
|
+
lastReplayBatches = 0;
|
|
18
|
+
constructor(db, options) {
|
|
19
|
+
this.db = db;
|
|
20
|
+
this.options = options;
|
|
21
|
+
if (!options.sessionId || !options.ownerId || !options.sessionIdentity)
|
|
22
|
+
throw new TypeError('recovery identity required');
|
|
23
|
+
if (!Number.isSafeInteger(options.leaseTtlMs) || options.leaseTtlMs <= 0)
|
|
24
|
+
throw new TypeError('invalid lease TTL');
|
|
25
|
+
this.batchSize = options.replayBatchSize ?? 200;
|
|
26
|
+
if (!Number.isSafeInteger(this.batchSize) || this.batchSize <= 0)
|
|
27
|
+
throw new TypeError('replayBatchSize must be a positive safe integer');
|
|
28
|
+
this.clock = options.now ?? Date.now;
|
|
29
|
+
this.leases = new LeaseManager(db);
|
|
30
|
+
this.reconciliation = new DurableReconciliation(db);
|
|
31
|
+
this.journal = new EventJournal(db);
|
|
32
|
+
}
|
|
33
|
+
start() {
|
|
34
|
+
const lease = this.leases.acquire(`session:${this.options.sessionId}`, this.options.ownerId, this.options.leaseTtlMs, this.clock());
|
|
35
|
+
this.lease = lease;
|
|
36
|
+
return Object.freeze({ role: lease ? 'controller' : 'follower', fence: lease?.fence ?? null });
|
|
37
|
+
}
|
|
38
|
+
async reconcileOnStartup() {
|
|
39
|
+
const lease = this.lease;
|
|
40
|
+
if (!lease || !this.leases.isCurrent(lease, this.clock()))
|
|
41
|
+
throw new FencedLeaseError();
|
|
42
|
+
this.mutate(lease, () => { });
|
|
43
|
+
let checkpoint = null;
|
|
44
|
+
let recoveryError = null;
|
|
45
|
+
if (this.options.checkpoint) {
|
|
46
|
+
try {
|
|
47
|
+
checkpoint = this.options.checkpoint.restore({ sessionId: this.options.sessionId, sessionIdentity: this.options.sessionIdentity });
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
recoveryError = { reason: error instanceof Error ? error.message : String(error) };
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
this.mutate(lease, () => { });
|
|
54
|
+
if (recoveryError) {
|
|
55
|
+
const partialArtifacts = this.options.retention ? await this.options.retention.listRawPartials() : [];
|
|
56
|
+
return this.report(lease, [], [], [], null, 0, 0, 0, partialArtifacts, recoveryError);
|
|
57
|
+
}
|
|
58
|
+
if (this.options.retention?.isDispatchPaused())
|
|
59
|
+
this.paused = true;
|
|
60
|
+
const rows = this.db.raw.prepare('SELECT request_id,status FROM outbox ORDER BY rowid').all();
|
|
61
|
+
const decisions = [], surfacedUnknown = [], redeliverable = [];
|
|
62
|
+
for (const row of rows) {
|
|
63
|
+
this.mutate(lease, () => { });
|
|
64
|
+
const requestId = String(row['request_id']), status = String(row['status']);
|
|
65
|
+
let resolvedBy = null;
|
|
66
|
+
let verdict;
|
|
67
|
+
if (status === 'sent')
|
|
68
|
+
verdict = 'sent';
|
|
69
|
+
else if (status === 'possibly-sent' || status === 'UNKNOWN_DELIVERY') {
|
|
70
|
+
const base = { requestId, outboxStatus: status, deliveryState: this.reconciliation.state(requestId), boundaryAudit: this.journal.audit(this.options.sessionId, requestId), verdict: 'unresolved', resolvedBy: null };
|
|
71
|
+
resolvedBy = await this.options.resolve(base);
|
|
72
|
+
if (!['confirmed', 'not-applied', 'unknown'].includes(resolvedBy))
|
|
73
|
+
throw new TypeError('invalid inflight verdict');
|
|
74
|
+
this.mutate(lease, () => this.applyResolution(requestId, resolvedBy));
|
|
75
|
+
this.mutate(lease, () => { });
|
|
76
|
+
if (resolvedBy === 'confirmed')
|
|
77
|
+
verdict = 'sent';
|
|
78
|
+
else if (resolvedBy === 'not-applied') {
|
|
79
|
+
this.mutate(lease, () => {
|
|
80
|
+
const current = this.db.raw.prepare('SELECT status FROM outbox WHERE request_id=?').get(requestId);
|
|
81
|
+
if (!current || String(current['status']) !== 'not-applied')
|
|
82
|
+
throw new TypeError('request was not marked not-applied during reconciliation');
|
|
83
|
+
});
|
|
84
|
+
verdict = 'redeliverable';
|
|
85
|
+
redeliverable.push(requestId);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
verdict = 'unknown-surfaced';
|
|
89
|
+
surfacedUnknown.push(requestId);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
verdict = 'unresolved';
|
|
94
|
+
decisions.push(Object.freeze({ requestId, outboxStatus: status, deliveryState: this.reconciliation.state(requestId), boundaryAudit: this.journal.audit(this.options.sessionId, requestId), verdict, resolvedBy }));
|
|
95
|
+
}
|
|
96
|
+
const cursor = checkpoint?.lastSequence ?? 0;
|
|
97
|
+
let replayedCount = 0;
|
|
98
|
+
for (const _event of this.replayEvents(cursor))
|
|
99
|
+
replayedCount++;
|
|
100
|
+
const replayBatches = this.lastReplayBatches;
|
|
101
|
+
const partialArtifacts = this.options.retention ? await this.options.retention.listRawPartials() : [];
|
|
102
|
+
return this.report(lease, decisions, surfacedUnknown, redeliverable, checkpoint, cursor + 1, replayedCount, replayBatches, partialArtifacts, null);
|
|
103
|
+
}
|
|
104
|
+
authorizeDispatch(dispatch) {
|
|
105
|
+
if (this.isDispatchPaused())
|
|
106
|
+
throw new Error('STORAGE_BACKPRESSURE: dispatch paused');
|
|
107
|
+
try {
|
|
108
|
+
return this.options.retention ? this.options.retention.authorizeDispatch(dispatch) : dispatch();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (isBackpressure(error))
|
|
112
|
+
this.paused = true;
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
isDispatchPaused() { return this.paused || Boolean(this.options.retention?.isDispatchPaused()); }
|
|
117
|
+
recordEvent(input) {
|
|
118
|
+
try {
|
|
119
|
+
this.journal.append(input);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (error instanceof StorageBackpressureError) {
|
|
123
|
+
this.paused = true;
|
|
124
|
+
if (this.options.retention) {
|
|
125
|
+
const id = isRecord(input) && typeof input['eventId'] === 'string' ? input['eventId'] : `recovery-event-${this.clock()}`;
|
|
126
|
+
try {
|
|
127
|
+
this.options.retention.retainEvidence(id, Buffer.from(JSON.stringify(input) ?? 'null'));
|
|
128
|
+
}
|
|
129
|
+
catch { }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
*replayEvents(afterSequence) {
|
|
136
|
+
if (!Number.isSafeInteger(afterSequence) || afterSequence < 0)
|
|
137
|
+
throw new TypeError('invalid event cursor');
|
|
138
|
+
this.lastReplayBatches = 0;
|
|
139
|
+
let cursor = afterSequence, total = 0;
|
|
140
|
+
while (true) {
|
|
141
|
+
const rows = this.db.raw.prepare('SELECT event_json FROM events WHERE session_id=? AND session_sequence>? ORDER BY session_sequence LIMIT ?').all(this.options.sessionId, cursor, this.batchSize);
|
|
142
|
+
if (rows.length === 0)
|
|
143
|
+
return;
|
|
144
|
+
this.lastReplayBatches++;
|
|
145
|
+
for (const row of rows) {
|
|
146
|
+
if (total === MAX_REPLAY_EVENTS)
|
|
147
|
+
throw new RangeError(`event replay exceeds ${MAX_REPLAY_EVENTS} event safety bound`);
|
|
148
|
+
const envelope = validateEnvelope(JSON.parse(String(row['event_json'])));
|
|
149
|
+
cursor = envelope.sessionSequence;
|
|
150
|
+
total++;
|
|
151
|
+
yield envelope;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
applyResolution(requestId, verdict) {
|
|
156
|
+
const current = this.db.raw.prepare('SELECT status FROM outbox WHERE request_id=?').get(requestId);
|
|
157
|
+
if (!current)
|
|
158
|
+
throw new Error(`unknown request: ${requestId}`);
|
|
159
|
+
const currentStatus = String(current['status']);
|
|
160
|
+
if (currentStatus !== 'possibly-sent' && currentStatus !== 'UNKNOWN_DELIVERY')
|
|
161
|
+
throw new TypeError('request does not need reconciliation');
|
|
162
|
+
const last = this.journal.audit(this.options.sessionId, requestId).at(-1);
|
|
163
|
+
const finalStatus = verdict === 'confirmed' ? 'sent' : verdict === 'not-applied' ? 'not-applied' : 'UNKNOWN_DELIVERY';
|
|
164
|
+
this.db.raw.prepare('UPDATE outbox SET status=? WHERE request_id=?').run(finalStatus, requestId);
|
|
165
|
+
const nextState = verdict === 'unknown' ? 'UNKNOWN_DELIVERY' : verdict === 'confirmed' ? 'sent' : null;
|
|
166
|
+
if (nextState && last?.state !== nextState) {
|
|
167
|
+
let sequence = Number(this.db.raw.prepare('SELECT COALESCE(MAX(boundary_sequence),0)+1 AS n FROM delivery_boundaries WHERE session_id=? AND request_id=?').get(this.options.sessionId, requestId)?.['n'] ?? 1);
|
|
168
|
+
if (!last)
|
|
169
|
+
this.db.raw.prepare('INSERT INTO delivery_boundaries(session_id,request_id,boundary_sequence,state,recorded_at) VALUES(?,?,?,?,?)').run(this.options.sessionId, requestId, sequence++, 'prepared', new Date(this.clock()).toISOString());
|
|
170
|
+
this.db.raw.prepare('INSERT INTO delivery_boundaries(session_id,request_id,boundary_sequence,state,recorded_at) VALUES(?,?,?,?,?)').run(this.options.sessionId, requestId, sequence, nextState, new Date(this.clock()).toISOString());
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
mutate(lease, write) { return this.leases.mutate(lease, write, this.clock()); }
|
|
174
|
+
report(lease, decisions, surfacedUnknown, redeliverable, checkpoint, replayedFrom, replayedCount, replayBatches, partialArtifacts, recoveryError) {
|
|
175
|
+
return Object.freeze({ lease: Object.freeze({ role: 'controller', fence: lease.fence }), decisions: Object.freeze(decisions), surfacedUnknown: Object.freeze(surfacedUnknown), redeliverable: Object.freeze(redeliverable), checkpoint, replayedFrom, replayedCount, replayBatches, partialArtifacts: Object.freeze([...partialArtifacts]), dispatchPaused: this.isDispatchPaused(), recoveryError: recoveryError && Object.freeze(recoveryError) });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function isBackpressure(error) { return error instanceof StorageBackpressureError || (typeof error === 'object' && error !== null && 'code' in error && error.code === 'STORAGE_BACKPRESSURE') || (error instanceof Error && /STORAGE_BACKPRESSURE/.test(error.message)); }
|
|
179
|
+
function isRecord(value) { return typeof value === 'object' && value !== null && !Array.isArray(value); }
|
|
180
|
+
//# sourceMappingURL=recovery-coordinator.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface WorkOrderContractInput {
|
|
2
|
+
readonly goal?: unknown;
|
|
3
|
+
readonly scope?: unknown;
|
|
4
|
+
readonly constraints?: unknown;
|
|
5
|
+
readonly acceptanceCriteria?: unknown;
|
|
6
|
+
readonly verification?: unknown;
|
|
7
|
+
readonly stopCondition?: unknown;
|
|
8
|
+
readonly controlBlock?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export type WorkOrderContractResult = {
|
|
11
|
+
readonly ok: true;
|
|
12
|
+
} | {
|
|
13
|
+
readonly ok: false;
|
|
14
|
+
readonly reasonId: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function validateWorkOrderContract(input: unknown): WorkOrderContractResult;
|
|
17
|
+
export interface CompletionCriterion {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly kind: string;
|
|
20
|
+
readonly required?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface CompletionEvidence {
|
|
23
|
+
readonly criterionId: string;
|
|
24
|
+
readonly kind: string;
|
|
25
|
+
readonly status: string;
|
|
26
|
+
readonly content?: unknown;
|
|
27
|
+
readonly claim?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface CompletionInput {
|
|
30
|
+
readonly taskType: 'read-only' | 'code-change' | 'release';
|
|
31
|
+
readonly criteria: readonly CompletionCriterion[];
|
|
32
|
+
readonly evidence: readonly CompletionEvidence[];
|
|
33
|
+
readonly summary: {
|
|
34
|
+
readonly done: boolean;
|
|
35
|
+
};
|
|
36
|
+
readonly pendingIntents: readonly {
|
|
37
|
+
readonly kind: string;
|
|
38
|
+
}[];
|
|
39
|
+
}
|
|
40
|
+
export interface CompletionResult {
|
|
41
|
+
readonly complete: boolean;
|
|
42
|
+
readonly reasonIds: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
export declare function evaluateCompletion(input: CompletionInput): CompletionResult;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
2
|
+
const nonEmptyText = (value) => typeof value === 'string' && value.trim().length > 0;
|
|
3
|
+
const nonEmptyTextList = (value) => Array.isArray(value) && value.length > 0 && value.every(nonEmptyText);
|
|
4
|
+
const contractReason = (key) => ({ ok: false, reasonId: `WORK_ORDER_CONTRACT_${key}_REQUIRED` });
|
|
5
|
+
export function validateWorkOrderContract(input) {
|
|
6
|
+
if (!isRecord(input))
|
|
7
|
+
return { ok: false, reasonId: 'WORK_ORDER_CONTRACT_INVALID' };
|
|
8
|
+
if (!nonEmptyText(input['goal']))
|
|
9
|
+
return contractReason('GOAL');
|
|
10
|
+
if (!nonEmptyTextList(input['scope']))
|
|
11
|
+
return contractReason('SCOPE');
|
|
12
|
+
if (!nonEmptyTextList(input['constraints']))
|
|
13
|
+
return contractReason('CONSTRAINTS');
|
|
14
|
+
if (!nonEmptyTextList(input['acceptanceCriteria']))
|
|
15
|
+
return contractReason('ACCEPTANCE_CRITERIA');
|
|
16
|
+
if (!nonEmptyTextList(input['verification']))
|
|
17
|
+
return contractReason('VERIFICATION');
|
|
18
|
+
if (!nonEmptyText(input['stopCondition']))
|
|
19
|
+
return contractReason('STOP_CONDITION');
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(input, 'controlBlock')) {
|
|
21
|
+
const control = input['controlBlock'];
|
|
22
|
+
if (!isRecord(control) || !nonEmptyText(control['goal']) || !nonEmptyTextList(control['scope']) ||
|
|
23
|
+
!nonEmptyTextList(control['constraints']) || !nonEmptyTextList(control['acceptanceCriteria']) ||
|
|
24
|
+
!nonEmptyTextList(control['verification']) || !nonEmptyText(control['stopCondition'])) {
|
|
25
|
+
return { ok: false, reasonId: 'WORK_ORDER_CONTROL_BLOCK_INVALID' };
|
|
26
|
+
}
|
|
27
|
+
const fields = ['goal', 'scope', 'constraints', 'acceptanceCriteria', 'verification', 'stopCondition'];
|
|
28
|
+
if (fields.some((field) => JSON.stringify(input[field]) !== JSON.stringify(control[field]))) {
|
|
29
|
+
return { ok: false, reasonId: 'WORK_ORDER_CONTROL_BLOCK_MISMATCH' };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { ok: true };
|
|
33
|
+
}
|
|
34
|
+
export function evaluateCompletion(input) {
|
|
35
|
+
const invalid = () => ({ complete: false, reasonIds: ['COMPLETION_INPUT_INVALID'] });
|
|
36
|
+
if (!input || typeof input !== 'object' || !Array.isArray(input.criteria) || !Array.isArray(input.evidence) || !Array.isArray(input.pendingIntents) ||
|
|
37
|
+
!['read-only', 'code-change', 'release'].includes(input.taskType) ||
|
|
38
|
+
!input.criteria.every((item) => isRecord(item) && typeof item['id'] === 'string' && typeof item['kind'] === 'string' &&
|
|
39
|
+
(item['required'] === undefined || typeof item['required'] === 'boolean')) ||
|
|
40
|
+
!input.evidence.every((item) => isRecord(item) && typeof item['criterionId'] === 'string' && typeof item['kind'] === 'string' && typeof item['status'] === 'string') ||
|
|
41
|
+
!input.pendingIntents.every((item) => isRecord(item) && typeof item['kind'] === 'string')) {
|
|
42
|
+
return invalid();
|
|
43
|
+
}
|
|
44
|
+
const reasons = [];
|
|
45
|
+
if (input.pendingIntents.length > 0)
|
|
46
|
+
reasons.push('PENDING_INTENTS_UNRECONCILED');
|
|
47
|
+
const criteria = [...input.criteria];
|
|
48
|
+
if (criteria.length === 0) {
|
|
49
|
+
if (input.taskType !== 'read-only')
|
|
50
|
+
return { complete: false, reasonIds: ['ACCEPTANCE_CRITERIA_MISSING'] };
|
|
51
|
+
const verifiedReport = input.evidence.some((item) => item.kind === 'report' && item.status === 'verified');
|
|
52
|
+
if (!verifiedReport)
|
|
53
|
+
return { complete: false, reasonIds: ['ACCEPTANCE_CRITERIA_MISSING'] };
|
|
54
|
+
}
|
|
55
|
+
if (input.taskType === 'read-only' && !criteria.some((item) => item.required !== false)) {
|
|
56
|
+
const verifiedReport = input.evidence.some((item) => item.kind === 'report' && item.status === 'verified');
|
|
57
|
+
if (!verifiedReport)
|
|
58
|
+
reasons.push('ACCEPTANCE_CRITERIA_MISSING');
|
|
59
|
+
}
|
|
60
|
+
if (input.taskType === 'code-change') {
|
|
61
|
+
const hasRequiredCodeChangeCriterion = criteria.some((item) => ['code-write', 'write', 'commit'].includes(item.kind) && item.required !== false);
|
|
62
|
+
const hasRequiredTestCriterion = criteria.some((item) => item.kind === 'test' && item.required !== false);
|
|
63
|
+
if (!hasRequiredCodeChangeCriterion || !hasRequiredTestCriterion)
|
|
64
|
+
reasons.push('ACCEPTANCE_CRITERIA_MISSING');
|
|
65
|
+
}
|
|
66
|
+
if (input.taskType === 'release') {
|
|
67
|
+
for (const kind of ['publish', 'install']) {
|
|
68
|
+
if (!criteria.some((item) => item.kind === kind)) {
|
|
69
|
+
criteria.push({ id: `release-${kind}`, kind, required: true });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
for (const item of criteria) {
|
|
74
|
+
if (item.required === false && !(input.taskType === 'release' && ['publish', 'install'].includes(item.kind)))
|
|
75
|
+
continue;
|
|
76
|
+
const satisfied = input.evidence.some((evidence) => evidence.criterionId === item.id && evidence.kind === item.kind && evidence.status === 'verified');
|
|
77
|
+
if (!satisfied)
|
|
78
|
+
reasons.push('ACCEPTANCE_CRITERIA_UNMET');
|
|
79
|
+
}
|
|
80
|
+
if (input.summary?.done !== true)
|
|
81
|
+
reasons.push('COMPLETION_NOT_CLAIMED');
|
|
82
|
+
const reasonIds = [...new Set(reasons)];
|
|
83
|
+
return { complete: reasonIds.length === 0, reasonIds };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=work-order-contract.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { AuthorizationScope } from '../intent/registry.js';
|
|
2
|
+
export interface WorkOrderInput {
|
|
3
|
+
readonly commandId: string;
|
|
4
|
+
readonly requestId: string;
|
|
5
|
+
readonly workOrderId: string;
|
|
6
|
+
readonly taskId: string;
|
|
7
|
+
readonly currentTaskId: string;
|
|
8
|
+
readonly intentRevision: number;
|
|
9
|
+
readonly currentRevision: number;
|
|
10
|
+
readonly epoch: number;
|
|
11
|
+
readonly currentEpoch: number;
|
|
12
|
+
readonly authorizationRef: string;
|
|
13
|
+
readonly scope: AuthorizationScope;
|
|
14
|
+
readonly requestedScope: AuthorizationScope;
|
|
15
|
+
readonly permissionGranted: boolean;
|
|
16
|
+
readonly priority: number;
|
|
17
|
+
readonly payload: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface QueuedWorkOrder extends WorkOrderInput {
|
|
20
|
+
readonly status: 'enqueued' | 'accepted' | 'running' | 'cancelled' | 'rejected' | 'failed' | 'unknown_delivery';
|
|
21
|
+
}
|
|
22
|
+
export interface QueueEvent {
|
|
23
|
+
readonly type: 'enqueued' | 'duplicate' | 'rejected' | 'cancelled' | 'cancel_refused' | 'accepted' | 'running' | 'failed' | 'unknown_delivery';
|
|
24
|
+
readonly requestId: string;
|
|
25
|
+
readonly workOrderId: string;
|
|
26
|
+
readonly reasonId?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface EnqueueResult {
|
|
29
|
+
readonly accepted: boolean;
|
|
30
|
+
readonly duplicate?: boolean;
|
|
31
|
+
readonly order?: QueuedWorkOrder;
|
|
32
|
+
readonly reasonId?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface WorkQueueOptions {
|
|
35
|
+
readonly reserve?: (requestId: string, order: WorkOrderInput) => void;
|
|
36
|
+
readonly audit?: (requestId: string, order: WorkOrderInput) => void;
|
|
37
|
+
readonly authorize: (authorizationRef: string, requested: AuthorizationScope, order: WorkOrderInput) => boolean;
|
|
38
|
+
}
|
|
39
|
+
/** In-memory priority queue with adapter seams for inbox/outbox reservation and duplicate auditing. */
|
|
40
|
+
export declare class WorkQueue {
|
|
41
|
+
private readonly options;
|
|
42
|
+
private readonly orders;
|
|
43
|
+
private readonly commands;
|
|
44
|
+
private readonly requests;
|
|
45
|
+
private readonly log;
|
|
46
|
+
constructor(options: WorkQueueOptions);
|
|
47
|
+
get size(): number;
|
|
48
|
+
events(): readonly QueueEvent[];
|
|
49
|
+
enqueue(input: WorkOrderInput): EnqueueResult;
|
|
50
|
+
next(): QueuedWorkOrder | null;
|
|
51
|
+
get(workOrderId: string): QueuedWorkOrder | null;
|
|
52
|
+
mark(workOrderId: string, status: QueuedWorkOrder['status'], reasonId?: string): QueuedWorkOrder;
|
|
53
|
+
record(event: QueueEvent): void;
|
|
54
|
+
cancel(workOrderId: string): boolean;
|
|
55
|
+
private reject;
|
|
56
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const validScope = (scope) => !!scope && typeof scope === 'object' && (scope.kind === 'read' || scope.kind === 'write' || (scope.kind === 'session' && typeof scope.sessionId === 'string' && !!scope.sessionId));
|
|
2
|
+
const allows = (granted, requested) => granted.kind === 'write' || (granted.kind === 'read' && requested.kind === 'read') || (granted.kind === 'session' && requested.kind === 'session' && granted.sessionId === requested.sessionId);
|
|
3
|
+
const snapshotPayload = (payload) => {
|
|
4
|
+
if (Array.isArray(payload))
|
|
5
|
+
return Object.freeze(payload.map(snapshotPayload));
|
|
6
|
+
if (payload && typeof payload === 'object')
|
|
7
|
+
return Object.freeze(Object.fromEntries(Object.entries(payload).map(([key, value]) => [key, snapshotPayload(value)])));
|
|
8
|
+
return payload;
|
|
9
|
+
};
|
|
10
|
+
const freezeOrder = (input, status = 'enqueued') => Object.freeze({ ...input, scope: Object.freeze({ ...input.scope }), requestedScope: Object.freeze({ ...input.requestedScope }), payload: snapshotPayload(input.payload), status });
|
|
11
|
+
/** In-memory priority queue with adapter seams for inbox/outbox reservation and duplicate auditing. */
|
|
12
|
+
export class WorkQueue {
|
|
13
|
+
options;
|
|
14
|
+
orders = new Map();
|
|
15
|
+
commands = new Map();
|
|
16
|
+
requests = new Map();
|
|
17
|
+
log = [];
|
|
18
|
+
constructor(options) {
|
|
19
|
+
this.options = options;
|
|
20
|
+
}
|
|
21
|
+
get size() { return [...this.orders.values()].filter(o => o.status === 'enqueued').length; }
|
|
22
|
+
events() { return Object.freeze([...this.log]); }
|
|
23
|
+
enqueue(input) {
|
|
24
|
+
// Fail closed in the required order: authorization → revision → epoch → permission.
|
|
25
|
+
if (!input || typeof input.authorizationRef !== 'string' || !input.authorizationRef.trim() || !validScope(input.scope) || !validScope(input.requestedScope) || !allows(input.scope, input.requestedScope) || !this.options.authorize(input.authorizationRef, input.requestedScope, input))
|
|
26
|
+
return this.reject(input, 'WORK_ORDER_AUTHORIZATION_REQUIRED');
|
|
27
|
+
if (input.taskId !== input.currentTaskId)
|
|
28
|
+
return this.reject(input, 'WORK_ORDER_TASK_MISMATCH');
|
|
29
|
+
if (!Number.isSafeInteger(input.intentRevision) || input.intentRevision < 1 || input.intentRevision !== input.currentRevision)
|
|
30
|
+
return this.reject(input, 'WORK_ORDER_REVISION_MISMATCH');
|
|
31
|
+
if (!Number.isSafeInteger(input.epoch) || input.epoch < 1 || input.epoch !== input.currentEpoch)
|
|
32
|
+
return this.reject(input, 'WORK_ORDER_EPOCH_STALE');
|
|
33
|
+
if (input.permissionGranted !== true)
|
|
34
|
+
return this.reject(input, 'WORK_ORDER_PERMISSION_DENIED');
|
|
35
|
+
if (!input.commandId?.trim() || !input.requestId?.trim() || !input.workOrderId?.trim() || !input.taskId?.trim() || !Number.isFinite(input.priority))
|
|
36
|
+
return this.reject(input, 'WORK_ORDER_INVALID');
|
|
37
|
+
if (!input.payload || typeof input.payload !== 'object' || typeof input.payload['instruction'] !== 'string' || !input.payload['instruction'])
|
|
38
|
+
return this.reject(input, 'WORK_ORDER_INVALID_PAYLOAD');
|
|
39
|
+
const byCommand = this.commands.get(input.commandId), byRequest = this.requests.get(input.requestId);
|
|
40
|
+
if (byCommand !== undefined || byRequest !== undefined) {
|
|
41
|
+
const existingId = byCommand ?? byRequest;
|
|
42
|
+
const prior = this.orders.get(existingId);
|
|
43
|
+
if (!prior || prior.requestId !== input.requestId || prior.commandId !== input.commandId || prior.workOrderId !== input.workOrderId)
|
|
44
|
+
return this.reject(input, 'WORK_ORDER_ID_CONFLICT');
|
|
45
|
+
try {
|
|
46
|
+
this.options.audit?.(input.requestId, input);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return this.reject(input, 'WORK_ORDER_AUDIT_FAILED');
|
|
50
|
+
}
|
|
51
|
+
this.log.push(Object.freeze({ type: 'duplicate', requestId: input.requestId, workOrderId: prior.workOrderId }));
|
|
52
|
+
return Object.freeze({ accepted: true, duplicate: true, order: prior });
|
|
53
|
+
}
|
|
54
|
+
if (this.orders.has(input.workOrderId))
|
|
55
|
+
return this.reject(input, 'WORK_ORDER_ID_CONFLICT');
|
|
56
|
+
try {
|
|
57
|
+
this.options.reserve?.(input.requestId, input);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return this.reject(input, 'WORK_ORDER_RESERVATION_FAILED');
|
|
61
|
+
}
|
|
62
|
+
const queued = freezeOrder(input);
|
|
63
|
+
this.orders.set(queued.workOrderId, queued);
|
|
64
|
+
this.commands.set(queued.commandId, queued.workOrderId);
|
|
65
|
+
this.requests.set(queued.requestId, queued.workOrderId);
|
|
66
|
+
this.log.push(Object.freeze({ type: 'enqueued', requestId: queued.requestId, workOrderId: queued.workOrderId }));
|
|
67
|
+
return Object.freeze({ accepted: true, order: queued });
|
|
68
|
+
}
|
|
69
|
+
next() { return [...this.orders.values()].filter(o => o.status === 'enqueued').sort((a, b) => b.priority - a.priority || a.requestId.localeCompare(b.requestId))[0] ?? null; }
|
|
70
|
+
get(workOrderId) { return this.orders.get(workOrderId) ?? null; }
|
|
71
|
+
mark(workOrderId, status, reasonId) {
|
|
72
|
+
const prior = this.orders.get(workOrderId);
|
|
73
|
+
if (!prior)
|
|
74
|
+
throw new TypeError('unknown work order');
|
|
75
|
+
const allowed = { enqueued: ['accepted', 'cancelled', 'rejected', 'failed', 'unknown_delivery'], accepted: ['running', 'failed', 'unknown_delivery'], running: ['failed', 'unknown_delivery'], cancelled: [], rejected: [], failed: [], unknown_delivery: [] };
|
|
76
|
+
if (!allowed[prior.status].includes(status))
|
|
77
|
+
throw new TypeError(`invalid work-order transition ${prior.status} -> ${status}`);
|
|
78
|
+
const updated = freezeOrder(prior, status);
|
|
79
|
+
this.orders.set(workOrderId, updated);
|
|
80
|
+
const event = Object.freeze({ type: status, requestId: prior.requestId, workOrderId, ...(['rejected', 'failed'].includes(status) ? { reasonId: reasonId ?? (status === 'failed' ? 'WORK_ORDER_FAILED' : 'WORK_ORDER_REJECTED') } : {}) });
|
|
81
|
+
this.log.push(event);
|
|
82
|
+
try {
|
|
83
|
+
this.options.audit?.(prior.requestId, prior);
|
|
84
|
+
}
|
|
85
|
+
catch { /* audit adapters must not break queue state transitions */ }
|
|
86
|
+
return updated;
|
|
87
|
+
}
|
|
88
|
+
record(event) { this.log.push(Object.freeze({ ...event })); }
|
|
89
|
+
cancel(workOrderId) { const order = this.orders.get(workOrderId); if (!order || order.status !== 'enqueued') {
|
|
90
|
+
this.record({ type: 'cancel_refused', requestId: order?.requestId ?? 'unknown', workOrderId, reasonId: 'WORK_ORDER_CANCEL_NOT_ENQUEUED' });
|
|
91
|
+
return false;
|
|
92
|
+
} this.mark(workOrderId, 'cancelled'); return true; }
|
|
93
|
+
reject(input, reasonId) { this.log.push(Object.freeze({ type: 'rejected', requestId: input?.requestId ?? 'unknown', workOrderId: input?.workOrderId ?? 'unknown', reasonId })); return Object.freeze({ accepted: false, reasonId }); }
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=work-queue.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SessionId, TaskId } from '../core/ids.js';
|
|
2
|
+
export interface DispatchRequest {
|
|
3
|
+
readonly sessionId: SessionId;
|
|
4
|
+
readonly taskId: TaskId;
|
|
5
|
+
/** Opaque reference to the prepared prompt content (never inline secrets). */
|
|
6
|
+
readonly promptRef: string;
|
|
7
|
+
}
|
|
8
|
+
/** Adapter stream messages — transport truth only; the core decides state. */
|
|
9
|
+
export type AdvisorMessage = {
|
|
10
|
+
readonly kind: 'ack';
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'completed';
|
|
13
|
+
readonly resultRef: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'unknown';
|
|
16
|
+
readonly reason: 'ack-lost' | 'timeout' | 'adapter-fault';
|
|
17
|
+
readonly note: string;
|
|
18
|
+
}
|
|
19
|
+
/** Definite rejection. `never-sent`: the request provably never reached the server (budget refundable). `refused`: the server answered with a non-5xx 4xx (the turn was delivered, budget consumed). */
|
|
20
|
+
| {
|
|
21
|
+
readonly kind: 'rejected';
|
|
22
|
+
readonly reason: 'auth' | 'not-found' | 'client-error' | 'rate-limited' | 'connect';
|
|
23
|
+
readonly delivery: 'never-sent' | 'refused';
|
|
24
|
+
readonly status: number | null;
|
|
25
|
+
readonly note: string;
|
|
26
|
+
};
|
|
27
|
+
export interface AdvisorPort {
|
|
28
|
+
/** Declared adapter identity including its simulated/live marker (ADR-015 capability honesty). */
|
|
29
|
+
readonly name: string;
|
|
30
|
+
/** True only for fixtures; live adapters must report false. */
|
|
31
|
+
readonly isSimulated: boolean;
|
|
32
|
+
dispatch(req: DispatchRequest): AsyncIterable<AdvisorMessage>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Capability } from './capabilities.js';
|
|
2
|
+
import type { AdapterFault } from './web.js';
|
|
3
|
+
export interface AgentRequest {
|
|
4
|
+
readonly workOrderId: string;
|
|
5
|
+
readonly cwd: string;
|
|
6
|
+
readonly instruction: string;
|
|
7
|
+
}
|
|
8
|
+
export type AgentObservation = {
|
|
9
|
+
readonly kind: 'accepted';
|
|
10
|
+
readonly runId: string;
|
|
11
|
+
} | {
|
|
12
|
+
readonly kind: 'state';
|
|
13
|
+
readonly state: 'running' | 'waiting-input' | 'completed' | 'failed';
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'output';
|
|
16
|
+
readonly text: string;
|
|
17
|
+
} | {
|
|
18
|
+
readonly kind: 'permission-required';
|
|
19
|
+
readonly requestId: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: 'unknown-outcome';
|
|
22
|
+
readonly runId: string;
|
|
23
|
+
};
|
|
24
|
+
export interface AgentPort {
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly isSimulated: boolean;
|
|
27
|
+
readonly capabilities: Readonly<Record<string, Capability>>;
|
|
28
|
+
dispatch(request: AgentRequest): AsyncIterable<AgentObservation>;
|
|
29
|
+
reconcile(runId: string): Promise<'confirmed' | 'not-applied' | 'unknown'>;
|
|
30
|
+
}
|
|
31
|
+
export type AgentFault = AdapterFault;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface StoreSnapshot {
|
|
2
|
+
readonly bindingRequired: boolean;
|
|
3
|
+
readonly pendingOrderIds: readonly string[];
|
|
4
|
+
}
|
|
5
|
+
export interface StorePort {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly isSimulated: boolean;
|
|
8
|
+
exportSnapshot(): Promise<StoreSnapshot>;
|
|
9
|
+
importSnapshot(snapshot: StoreSnapshot): Promise<void>;
|
|
10
|
+
isBound(): Promise<boolean>;
|
|
11
|
+
markBound(): Promise<void>;
|
|
12
|
+
pendingOrders(): Promise<readonly string[]>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Capability } from './capabilities.js';
|
|
2
|
+
export type AdapterFault = 'latency' | 'failure' | 'quota' | 'partial' | 'permission' | 'unknown-delivery';
|
|
3
|
+
export type DeliveryCertainty = 'confirmed' | 'unknown';
|
|
4
|
+
export interface WebRequest {
|
|
5
|
+
readonly requestId: string;
|
|
6
|
+
readonly conversationId: string;
|
|
7
|
+
readonly content: string;
|
|
8
|
+
}
|
|
9
|
+
export type WebObservation = {
|
|
10
|
+
readonly kind: 'accepted';
|
|
11
|
+
readonly requestId: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: 'chunk';
|
|
14
|
+
readonly text: string;
|
|
15
|
+
readonly complete: boolean;
|
|
16
|
+
} | {
|
|
17
|
+
readonly kind: 'blocked';
|
|
18
|
+
readonly reason: 'quota' | 'permission' | 'failure';
|
|
19
|
+
} | {
|
|
20
|
+
readonly kind: 'unknown-delivery';
|
|
21
|
+
readonly requestId: string;
|
|
22
|
+
};
|
|
23
|
+
export interface WebPort {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly isSimulated: boolean;
|
|
26
|
+
readonly capabilities: Readonly<Record<string, Capability>>;
|
|
27
|
+
send(request: WebRequest): AsyncIterable<WebObservation>;
|
|
28
|
+
reconcile(requestId: string): Promise<DeliveryCertainty>;
|
|
29
|
+
}
|