@dailephd/my-centcom 0.2.0 → 0.3.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/README.md +10 -5
- package/apps/daemon/dist/artifacts/returnSnapshots.d.ts +12 -0
- package/apps/daemon/dist/artifacts/returnSnapshots.js +41 -0
- package/apps/daemon/dist/bootstrap/app.d.ts +21 -0
- package/apps/daemon/dist/bootstrap/app.js +27 -0
- package/apps/daemon/dist/bootstrap/installLayout.d.ts +81 -0
- package/apps/daemon/dist/bootstrap/installLayout.js +164 -0
- package/apps/daemon/dist/bootstrap/main.d.ts +14 -0
- package/apps/daemon/dist/bootstrap/main.js +141 -0
- package/apps/daemon/dist/bootstrap/operatorConsole.d.ts +75 -0
- package/apps/daemon/dist/bootstrap/operatorConsole.js +293 -0
- package/apps/daemon/dist/bootstrap/privateDataRoot.d.ts +38 -0
- package/apps/daemon/dist/bootstrap/privateDataRoot.js +204 -0
- package/apps/daemon/dist/bootstrap/secureMain.d.ts +118 -0
- package/apps/daemon/dist/bootstrap/secureMain.js +403 -0
- package/apps/daemon/dist/bootstrap/setup.d.ts +93 -0
- package/apps/daemon/dist/bootstrap/setup.js +738 -0
- package/apps/daemon/dist/context/changeProposal.d.ts +97 -0
- package/apps/daemon/dist/context/changeProposal.js +259 -0
- package/apps/daemon/dist/context/gitEvidence.d.ts +88 -0
- package/apps/daemon/dist/context/gitEvidence.js +332 -0
- package/apps/daemon/dist/context/gitObservation.d.ts +30 -0
- package/apps/daemon/dist/context/gitObservation.js +113 -0
- package/apps/daemon/dist/context/projectReadIssuer.d.ts +68 -0
- package/apps/daemon/dist/context/projectReadIssuer.js +158 -0
- package/apps/daemon/dist/context/projectReadService.d.ts +153 -0
- package/apps/daemon/dist/context/projectReadService.js +652 -0
- package/apps/daemon/dist/context/projectViewService.d.ts +85 -0
- package/apps/daemon/dist/context/projectViewService.js +332 -0
- package/apps/daemon/dist/context/proposalRecorder.d.ts +11 -0
- package/apps/daemon/dist/context/proposalRecorder.js +19 -0
- package/apps/daemon/dist/plugins/drivers/codexMcpConfig.d.ts +40 -0
- package/apps/daemon/dist/plugins/drivers/codexMcpConfig.js +73 -0
- package/apps/daemon/dist/plugins/drivers/codexModelCompatibility.d.ts +49 -0
- package/apps/daemon/dist/plugins/drivers/codexModelCompatibility.js +70 -0
- package/apps/daemon/dist/plugins/drivers/fakePluginDriver.d.ts +16 -0
- package/apps/daemon/dist/plugins/drivers/fakePluginDriver.js +115 -0
- package/apps/daemon/dist/plugins/drivers/finiteCliDriver.d.ts +153 -0
- package/apps/daemon/dist/plugins/drivers/finiteCliDriver.js +505 -0
- package/apps/daemon/dist/plugins/registry/operationCatalog.d.ts +23 -0
- package/apps/daemon/dist/plugins/registry/operationCatalog.js +41 -0
- package/apps/daemon/dist/plugins/registry/registryOperationCatalog.d.ts +14 -0
- package/apps/daemon/dist/plugins/registry/registryOperationCatalog.js +29 -0
- package/apps/daemon/dist/plugins/registry/verifiedCapabilityRegistry.d.ts +151 -0
- package/apps/daemon/dist/plugins/registry/verifiedCapabilityRegistry.js +579 -0
- package/apps/daemon/dist/projects/codingAuthority.d.ts +102 -0
- package/apps/daemon/dist/projects/codingAuthority.js +244 -0
- package/apps/daemon/dist/projects/fixtureAuthorization.d.ts +54 -0
- package/apps/daemon/dist/projects/fixtureAuthorization.js +172 -0
- package/apps/daemon/dist/projects/pairedAuthority.d.ts +158 -0
- package/apps/daemon/dist/projects/pairedAuthority.js +273 -0
- package/apps/daemon/dist/projects/trustedCliConsent.d.ts +47 -0
- package/apps/daemon/dist/projects/trustedCliConsent.js +84 -0
- package/apps/daemon/dist/runs/changeApplier.d.ts +59 -0
- package/apps/daemon/dist/runs/changeApplier.js +319 -0
- package/apps/daemon/dist/runs/codingWorkflowService.d.ts +283 -0
- package/apps/daemon/dist/runs/codingWorkflowService.js +785 -0
- package/apps/daemon/dist/runs/durableIntentCoordinator.d.ts +72 -0
- package/apps/daemon/dist/runs/durableIntentCoordinator.js +160 -0
- package/apps/daemon/dist/runs/inMemoryCoordinator.d.ts +55 -0
- package/apps/daemon/dist/runs/inMemoryCoordinator.js +375 -0
- package/apps/daemon/dist/runs/runExecutor.d.ts +154 -0
- package/apps/daemon/dist/runs/runExecutor.js +295 -0
- package/apps/daemon/dist/runs/workflowService.d.ts +185 -0
- package/apps/daemon/dist/runs/workflowService.js +300 -0
- package/apps/daemon/dist/runtime/boundedProcessHost.d.ts +111 -0
- package/apps/daemon/dist/runtime/boundedProcessHost.js +752 -0
- package/apps/daemon/dist/runtime/evidenceRedaction.d.ts +30 -0
- package/apps/daemon/dist/runtime/evidenceRedaction.js +79 -0
- package/apps/daemon/dist/runtime/executionDiagnostics.d.ts +134 -0
- package/apps/daemon/dist/runtime/executionDiagnostics.js +213 -0
- package/apps/daemon/dist/runtime/modelExecutionPolicy.d.ts +22 -0
- package/apps/daemon/dist/runtime/modelExecutionPolicy.js +19 -0
- package/apps/daemon/dist/runtime/mxcExecution.d.ts +12 -0
- package/apps/daemon/dist/runtime/mxcExecution.js +163 -0
- package/apps/daemon/dist/runtime/mxcIntegrity.d.ts +24 -0
- package/apps/daemon/dist/runtime/mxcIntegrity.js +81 -0
- package/apps/daemon/dist/runtime/mxcWorker.d.ts +2 -0
- package/apps/daemon/dist/runtime/mxcWorker.js +45 -0
- package/apps/daemon/dist/runtime/provisionedExecution.d.ts +150 -0
- package/apps/daemon/dist/runtime/provisionedExecution.js +653 -0
- package/apps/daemon/dist/runtime/testExecution.d.ts +76 -0
- package/apps/daemon/dist/runtime/testExecution.js +106 -0
- package/apps/daemon/dist/runtime/testProfiles.d.ts +10 -0
- package/apps/daemon/dist/runtime/testProfiles.js +4 -0
- package/apps/daemon/dist/runtime/trustedAgentStaging.d.ts +89 -0
- package/apps/daemon/dist/runtime/trustedAgentStaging.js +262 -0
- package/apps/daemon/dist/runtime/trustedCaBundle.d.ts +77 -0
- package/apps/daemon/dist/runtime/trustedCaBundle.js +125 -0
- package/apps/daemon/dist/runtime/windows/windowsJobSupervisor.d.ts +166 -0
- package/apps/daemon/dist/runtime/windows/windowsJobSupervisor.js +521 -0
- package/apps/daemon/dist/storage/diagnosticLog.d.ts +63 -0
- package/apps/daemon/dist/storage/diagnosticLog.js +136 -0
- package/apps/daemon/dist/storage/executionTelemetry.d.ts +63 -0
- package/apps/daemon/dist/storage/executionTelemetry.js +247 -0
- package/apps/daemon/dist/storage/protectedSecrets.d.ts +39 -0
- package/apps/daemon/dist/storage/protectedSecrets.js +106 -0
- package/apps/daemon/dist/storage/sqliteLedger.d.ts +786 -0
- package/apps/daemon/dist/storage/sqliteLedger.js +1303 -0
- package/apps/daemon/dist/transports/http/dispatch.d.ts +43 -0
- package/apps/daemon/dist/transports/http/dispatch.js +405 -0
- package/apps/daemon/dist/transports/http/secureRoutes.d.ts +40 -0
- package/apps/daemon/dist/transports/http/secureRoutes.js +332 -0
- package/apps/daemon/dist/transports/http/workflowRoutes.d.ts +41 -0
- package/apps/daemon/dist/transports/http/workflowRoutes.js +473 -0
- package/apps/daemon/dist/transports/mcp/localProjectReadServer.d.ts +182 -0
- package/apps/daemon/dist/transports/mcp/localProjectReadServer.js +221 -0
- package/apps/daemon/dist/transports/native/nativeHost.d.ts +24 -0
- package/apps/daemon/dist/transports/native/nativeHost.js +344 -0
- package/apps/daemon/package.json +24 -0
- package/apps/daemon/src/runtime/benign/referenceEcho.mjs +27 -0
- package/apps/daemon/src/runtime/windows/buildSupervisor.mjs +87 -0
- package/apps/daemon/src/runtime/windows/supervisorMain.cs +676 -0
- package/apps/extension/manifest.secure.json +25 -0
- package/apps/extension/scripts/build.mjs +173 -0
- package/apps/extension/src/background/secureWorker.ts +1595 -0
- package/apps/extension/src/background/serviceWorker.ts +892 -0
- package/apps/extension/src/content/captureSelection.ts +64 -0
- package/apps/extension/src/content/secureInsert.ts +207 -0
- package/apps/extension/src/probe/index.html +41 -0
- package/apps/extension/src/probe/main.ts +201 -0
- package/apps/extension/src/sidepanel/index.html +203 -0
- package/apps/extension/src/sidepanel/main.ts +903 -0
- package/package.json +19 -3
- package/packages/contracts/dist/artifacts.d.ts +66 -0
- package/packages/contracts/dist/artifacts.js +64 -0
- package/packages/contracts/dist/automation.d.ts +540 -0
- package/packages/contracts/dist/automation.js +191 -0
- package/packages/contracts/dist/browser.d.ts +251 -0
- package/packages/contracts/dist/browser.js +131 -0
- package/packages/contracts/dist/context.d.ts +71 -0
- package/packages/contracts/dist/context.js +73 -0
- package/packages/contracts/dist/diagnostics.d.ts +99 -0
- package/packages/contracts/dist/diagnostics.js +284 -0
- package/packages/contracts/dist/effects.d.ts +42 -0
- package/packages/contracts/dist/effects.js +42 -0
- package/packages/contracts/dist/errors.d.ts +75 -0
- package/packages/contracts/dist/errors.js +70 -0
- package/packages/contracts/dist/events.d.ts +50 -0
- package/packages/contracts/dist/events.js +34 -0
- package/packages/contracts/dist/executionDiagnostics.d.ts +212 -0
- package/packages/contracts/dist/executionDiagnostics.js +101 -0
- package/packages/contracts/dist/identity.d.ts +54 -0
- package/packages/contracts/dist/identity.js +40 -0
- package/packages/contracts/dist/index.d.ts +20 -0
- package/packages/contracts/dist/index.js +20 -0
- package/packages/contracts/dist/invocation.d.ts +90 -0
- package/packages/contracts/dist/invocation.js +77 -0
- package/packages/contracts/dist/lifecycle.d.ts +130 -0
- package/packages/contracts/dist/lifecycle.js +135 -0
- package/packages/contracts/dist/plugin.d.ts +214 -0
- package/packages/contracts/dist/plugin.js +117 -0
- package/packages/contracts/dist/projectRead.d.ts +205 -0
- package/packages/contracts/dist/projectRead.js +162 -0
- package/packages/contracts/dist/secure.d.ts +128 -0
- package/packages/contracts/dist/secure.js +99 -0
- package/packages/contracts/package.json +32 -0
- package/packages/contracts/src/artifacts.ts +83 -0
- package/packages/contracts/src/automation.ts +238 -0
- package/packages/contracts/src/browser.ts +164 -0
- package/packages/contracts/src/context.ts +91 -0
- package/packages/contracts/src/diagnostics.ts +318 -0
- package/packages/contracts/src/effects.ts +49 -0
- package/packages/contracts/src/errors.ts +83 -0
- package/packages/contracts/src/events.ts +46 -0
- package/packages/contracts/src/executionDiagnostics.ts +116 -0
- package/packages/contracts/src/identity.ts +68 -0
- package/packages/contracts/src/index.ts +20 -0
- package/packages/contracts/src/invocation.ts +96 -0
- package/packages/contracts/src/lifecycle.ts +169 -0
- package/packages/contracts/src/plugin.ts +174 -0
- package/packages/contracts/src/projectRead.ts +179 -0
- package/packages/contracts/src/secure.ts +136 -0
- package/provenance.json +179 -9
- package/source.zip +0 -0
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { basename } from 'node:path';
|
|
3
|
+
import { CAPTURE_TTL_MS, CaptureFidelitySchema, SCHEMA_VERSION_V1, TabBindingV1Schema } from '../../../../packages/contracts/dist/index.js';
|
|
4
|
+
import { redactText } from '../runtime/evidenceRedaction.js';
|
|
5
|
+
import { IdempotencyConflictError } from './durableIntentCoordinator.js';
|
|
6
|
+
export class WorkflowRefusal extends Error {
|
|
7
|
+
code;
|
|
8
|
+
constructor(code) {
|
|
9
|
+
super(code);
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.name = 'WorkflowRefusal';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const sha = (s) => createHash('sha256').update(s, 'utf8').digest('hex');
|
|
15
|
+
const TERMINAL = new Set(['COMPLETED', 'FAILED', 'CANCELLED', 'UNKNOWN']);
|
|
16
|
+
export class WorkflowService {
|
|
17
|
+
ledger;
|
|
18
|
+
authority;
|
|
19
|
+
coordinator;
|
|
20
|
+
sealer;
|
|
21
|
+
now;
|
|
22
|
+
telemetry;
|
|
23
|
+
presentation;
|
|
24
|
+
constructor(ledger, authority, coordinator, sealer, now = Date.now,
|
|
25
|
+
/** SW-068: lets the workflow show a failed execution's category and correlation id directly. */
|
|
26
|
+
telemetry, presentation) {
|
|
27
|
+
this.ledger = ledger;
|
|
28
|
+
this.authority = authority;
|
|
29
|
+
this.coordinator = coordinator;
|
|
30
|
+
this.sealer = sealer;
|
|
31
|
+
this.now = now;
|
|
32
|
+
this.telemetry = telemetry;
|
|
33
|
+
this.presentation = presentation;
|
|
34
|
+
}
|
|
35
|
+
iso() { return new Date(this.now()).toISOString(); }
|
|
36
|
+
openCapture(c) {
|
|
37
|
+
let v;
|
|
38
|
+
try {
|
|
39
|
+
v = this.sealer().open(c.sealed);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new WorkflowRefusal('SEAL_FAILED');
|
|
43
|
+
}
|
|
44
|
+
const o = v;
|
|
45
|
+
const b = TabBindingV1Schema.safeParse(o?.binding);
|
|
46
|
+
const f = o?.fidelity === undefined ? { success: true, data: 'CAPTURED_RENDERED_TEXT' } : CaptureFidelitySchema.safeParse(o.fidelity);
|
|
47
|
+
if (!o || typeof o.text !== 'string' || !b.success || !f.success || sha(o.text) !== c.sha256)
|
|
48
|
+
throw new WorkflowRefusal('SEAL_FAILED');
|
|
49
|
+
// SW-066: a capture sealed before this field existed had no normalization recorded (a rendered selection never had any; an older paste is reported as 0 = not recorded).
|
|
50
|
+
const n = typeof o.lineEndingsNormalized === 'number' && Number.isSafeInteger(o.lineEndingsNormalized) && o.lineEndingsNormalized >= 0 ? o.lineEndingsNormalized : 0;
|
|
51
|
+
return { text: o.text, binding: b.data, fidelity: f.data, lineEndingsNormalized: n };
|
|
52
|
+
}
|
|
53
|
+
storeCapture(principalId, input) {
|
|
54
|
+
// The worker's digest is re-verified here: the daemon never stores text under a digest it did not compute itself.
|
|
55
|
+
if (sha(input.text) !== input.sha256 || Buffer.byteLength(input.text, 'utf8') !== input.bytes || input.text.trim().length === 0)
|
|
56
|
+
throw new WorkflowRefusal('CAPTURE_INVALID');
|
|
57
|
+
// A pasted capture is normalized to LF by the panel; a CR here means a producer skipped that step (never stored, never guessed).
|
|
58
|
+
if (input.fidelity === 'PASTED_PLAIN_TEXT' && input.text.includes('\r'))
|
|
59
|
+
throw new WorkflowRefusal('CAPTURE_INVALID');
|
|
60
|
+
// SW-066: only a pasted capture can have had line endings normalized; a rendered selection is never rewritten, so a non-zero count there is a producer bug.
|
|
61
|
+
const normalized = input.lineEndingsNormalized ?? 0;
|
|
62
|
+
if (normalized > 0 && input.fidelity !== 'PASTED_PLAIN_TEXT')
|
|
63
|
+
throw new WorkflowRefusal('CAPTURE_INVALID');
|
|
64
|
+
if (input.fidelity === 'EDITED_TASK_TEXT') {
|
|
65
|
+
const parent = input.editOf ? this.ledger.getCapture(principalId, input.editOf) : undefined;
|
|
66
|
+
if (!parent || parent.consumedRunId || parent.dismissedAt || Date.parse(parent.expiresAt) <= this.now() || this.ledger.latestCapture(principalId)?.captureId !== parent.captureId)
|
|
67
|
+
throw new WorkflowRefusal('CAPTURE_CONFLICT');
|
|
68
|
+
if (JSON.stringify(this.openCapture(parent).binding) !== JSON.stringify(TabBindingV1Schema.parse(input.binding)))
|
|
69
|
+
throw new WorkflowRefusal('CAPTURE_CONFLICT');
|
|
70
|
+
}
|
|
71
|
+
else if (input.editOf)
|
|
72
|
+
throw new WorkflowRefusal('CAPTURE_INVALID');
|
|
73
|
+
this.ledger.purgeExpiredCaptures(this.iso());
|
|
74
|
+
const b = input.binding;
|
|
75
|
+
// The id of a rendered-selection capture is unchanged from SW-062; a pasted capture of the same bytes in the same document is a DIFFERENT capture.
|
|
76
|
+
const idParts = [principalId, input.sha256, b.tabId, b.windowId, b.documentId, b.nonce, b.sourceUrl];
|
|
77
|
+
if (input.fidelity !== 'CAPTURED_RENDERED_TEXT')
|
|
78
|
+
idParts.push(input.fidelity);
|
|
79
|
+
if (input.editOf)
|
|
80
|
+
idParts.push(input.editOf);
|
|
81
|
+
const captureId = `cap.${sha(JSON.stringify(idParts)).slice(0, 32)}`;
|
|
82
|
+
let sealed;
|
|
83
|
+
try {
|
|
84
|
+
sealed = this.sealer().seal({ text: input.text, binding: b, fidelity: input.fidelity, lineEndingsNormalized: normalized });
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new WorkflowRefusal('SEAL_FAILED');
|
|
88
|
+
}
|
|
89
|
+
const nowMs = this.now();
|
|
90
|
+
const { row, duplicate } = this.ledger.storeCapture({ captureId, principalId, sha256: input.sha256, bytes: input.bytes, sealed, createdAt: new Date(nowMs).toISOString(), expiresAt: new Date(nowMs + CAPTURE_TTL_MS).toISOString() });
|
|
91
|
+
return { captureId: row.captureId, createdAt: row.createdAt, expiresAt: row.expiresAt, duplicate, sha256: row.sha256, bytes: row.bytes };
|
|
92
|
+
}
|
|
93
|
+
/** Idempotent capture -> run. `launch` is true ONLY for the single call whose approval committed QUEUED. */
|
|
94
|
+
runCapture(principalId, captureId, op) {
|
|
95
|
+
const c = this.ledger.getCapture(principalId, captureId);
|
|
96
|
+
if (!c || c.dismissedAt !== null)
|
|
97
|
+
throw new WorkflowRefusal('CAPTURE_NOT_FOUND');
|
|
98
|
+
if (c.consumedRunId === null && Date.parse(c.expiresAt) <= this.now())
|
|
99
|
+
throw new WorkflowRefusal('CAPTURE_EXPIRED');
|
|
100
|
+
if (!this.authority.authorize(principalId, op.projectId, op.pluginId, op.operationId))
|
|
101
|
+
throw new WorkflowRefusal('GRANT_DENIED');
|
|
102
|
+
const effectClass = this.authority.effectClassOf(op.pluginId, op.operationId) ?? 'read';
|
|
103
|
+
const consent = this.authority.consentModeFor(principalId, op.projectId, op.pluginId, op.operationId);
|
|
104
|
+
const { text } = this.openCapture(c);
|
|
105
|
+
let out;
|
|
106
|
+
try {
|
|
107
|
+
out = this.coordinator.prepareIntent(principalId, {
|
|
108
|
+
schemaVersion: SCHEMA_VERSION_V1, requestId: `req.${captureId}`, idempotencyKey: `idem.${captureId}`, projectId: op.projectId, pluginId: op.pluginId, operationId: op.operationId,
|
|
109
|
+
params: { prompt: text }, requestedAt: this.iso(), requiresUserApproval: true,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
if (e instanceof IdempotencyConflictError)
|
|
114
|
+
throw new WorkflowRefusal('CAPTURE_CONFLICT'); // the same capture was already used for a different operation
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
const bound = this.ledger.bindCaptureRun(principalId, captureId, out.runId, consent);
|
|
118
|
+
if (bound !== out.runId)
|
|
119
|
+
throw new WorkflowRefusal('CAPTURE_CONFLICT');
|
|
120
|
+
let launch = false;
|
|
121
|
+
let state = this.coordinator.getStatus(principalId, out.runId)?.lifecycleState ?? 'UNKNOWN';
|
|
122
|
+
if (consent === 'RUN_CLICK' && state === 'AWAITING_USER_APPROVAL') {
|
|
123
|
+
// The user's own Run click is the consent for this verified read operation. The proof is single-use, fingerprint-bound, and never leaves the process.
|
|
124
|
+
const a = this.authority.issueLocalApprovalChallenge({ principalId, runId: out.runId });
|
|
125
|
+
const d = this.coordinator.approveRun(principalId, out.runId, a.approvalId, a.approvalCode, 'USER_RUN_CLICK');
|
|
126
|
+
if (d.kind === 'OK' && d.lifecycleState === 'QUEUED' && !d.duplicate)
|
|
127
|
+
launch = true;
|
|
128
|
+
state = this.coordinator.getStatus(principalId, out.runId)?.lifecycleState ?? state;
|
|
129
|
+
}
|
|
130
|
+
return { runId: out.runId, lifecycleState: state, duplicate: out.duplicate, consent, effectClass, launch };
|
|
131
|
+
}
|
|
132
|
+
/** Trusted LOCAL confirmation of a pending (non-run-click) run. Reachable only from the local admin channel, never from the browser. */
|
|
133
|
+
confirmLocally(principalId, runId) {
|
|
134
|
+
const run = this.ledger.getRunDetailForPrincipal(principalId, runId);
|
|
135
|
+
if (!run)
|
|
136
|
+
throw new WorkflowRefusal('NOT_FOUND');
|
|
137
|
+
if (run.lifecycleState !== 'AWAITING_USER_APPROVAL')
|
|
138
|
+
throw new WorkflowRefusal('RUN_NOT_RUNNABLE');
|
|
139
|
+
let a;
|
|
140
|
+
try {
|
|
141
|
+
a = this.authority.issueLocalApprovalChallenge({ principalId, runId });
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
throw new WorkflowRefusal('GRANT_DENIED');
|
|
145
|
+
}
|
|
146
|
+
const d = this.coordinator.approveRun(principalId, runId, a.approvalId, a.approvalCode, 'LOCAL_RISK_CONFIRMATION');
|
|
147
|
+
if (d.kind !== 'OK')
|
|
148
|
+
throw new WorkflowRefusal(d.kind === 'DENIED' ? 'GRANT_DENIED' : 'STATE_CONFLICT');
|
|
149
|
+
return { lifecycleState: d.lifecycleState, launch: !d.duplicate };
|
|
150
|
+
}
|
|
151
|
+
pendingConfirmations(principalId) {
|
|
152
|
+
const c = this.ledger.latestCapture(principalId); // the one current workflow item; older pending runs are visible to the operator console
|
|
153
|
+
const out = [];
|
|
154
|
+
if (c?.consumedRunId) {
|
|
155
|
+
const r = this.ledger.getRunDetailForPrincipal(principalId, c.consumedRunId);
|
|
156
|
+
if (r && r.lifecycleState === 'AWAITING_USER_APPROVAL')
|
|
157
|
+
out.push({ runId: r.runId, projectId: r.projectId, pluginId: r.pluginId, operationId: r.operationId, effectClass: this.authority.effectClassOf(r.pluginId, r.operationId) ?? 'UNKNOWN', createdAt: r.createdAt, promptBytes: c.bytes });
|
|
158
|
+
}
|
|
159
|
+
return out;
|
|
160
|
+
}
|
|
161
|
+
/** Called after the immutable return snapshot exists: its first target is the tab/document the run departed from (if it came from a capture). */
|
|
162
|
+
ensureOriginTarget(principalId, snapshot) {
|
|
163
|
+
if (this.ledger.latestReturnTarget(snapshot.returnId))
|
|
164
|
+
return;
|
|
165
|
+
const cap = this.captureOfRun(principalId, snapshot.runId);
|
|
166
|
+
if (!cap)
|
|
167
|
+
return;
|
|
168
|
+
const { binding } = this.openCapture(cap);
|
|
169
|
+
this.ledger.appendReturnTarget(snapshot.returnId, 'ORIGIN', this.sealer().seal(binding), this.iso());
|
|
170
|
+
}
|
|
171
|
+
captureOfRun(principalId, runId) {
|
|
172
|
+
return this.ledger.getCaptureByRun(principalId, runId);
|
|
173
|
+
}
|
|
174
|
+
targetOf(returnId) {
|
|
175
|
+
const t = this.ledger.latestReturnTarget(returnId);
|
|
176
|
+
if (!t)
|
|
177
|
+
return undefined;
|
|
178
|
+
let v;
|
|
179
|
+
try {
|
|
180
|
+
v = this.sealer().open(t.sealed);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
const b = TabBindingV1Schema.safeParse(v);
|
|
186
|
+
return b.success ? { binding: b.data, sequenceNo: t.sequenceNo } : undefined;
|
|
187
|
+
}
|
|
188
|
+
snapshotFor(principalId, returnId) {
|
|
189
|
+
const snap = this.ledger.getReturnSnapshotById(principalId, returnId);
|
|
190
|
+
if (!snap)
|
|
191
|
+
throw new WorkflowRefusal('RETURN_NOT_AVAILABLE');
|
|
192
|
+
return snap;
|
|
193
|
+
}
|
|
194
|
+
/** Records what the worker observed. INSERTED_UNSENT is terminal: a return is never inserted twice, even after any restart. */
|
|
195
|
+
recordReceipt(principalId, returnId, r) {
|
|
196
|
+
const snap = this.snapshotFor(principalId, returnId);
|
|
197
|
+
if (snap.sha256 !== r.sha256)
|
|
198
|
+
throw new WorkflowRefusal('RETURN_CHANGED');
|
|
199
|
+
const res = this.ledger.appendReturnReceipt(returnId, r.state, r.code ?? null, r.editor ?? null, this.iso(), (cur) => cur !== 'INSERTED_UNSENT');
|
|
200
|
+
if (res.kind === 'REJECTED')
|
|
201
|
+
throw new WorkflowRefusal('ALREADY_INSERTED');
|
|
202
|
+
return res.state;
|
|
203
|
+
}
|
|
204
|
+
/** The user's explicit choice of a NEW target for the SAME immutable result. The CLI is not re-run; validation of the tab happens in the worker first. */
|
|
205
|
+
rebind(principalId, returnId, sha256, binding) {
|
|
206
|
+
const snap = this.snapshotFor(principalId, returnId);
|
|
207
|
+
if (snap.sha256 !== sha256)
|
|
208
|
+
throw new WorkflowRefusal('RETURN_CHANGED');
|
|
209
|
+
const cur = this.ledger.latestReturnReceipt(returnId)?.state ?? 'RETURN_READY';
|
|
210
|
+
if (cur === 'INSERTED_UNSENT')
|
|
211
|
+
throw new WorkflowRefusal('ALREADY_INSERTED');
|
|
212
|
+
const seq = this.ledger.appendReturnTarget(returnId, 'USER_REBIND', this.sealer().seal(binding), this.iso());
|
|
213
|
+
this.ledger.appendReturnReceipt(returnId, 'RETURN_READY', 'USER_REBIND', null, this.iso(), (c) => c !== 'INSERTED_UNSENT');
|
|
214
|
+
return seq;
|
|
215
|
+
}
|
|
216
|
+
setPreference(principalId, p) {
|
|
217
|
+
if (!this.authority.authorize(principalId, p.projectId, p.pluginId, p.operationId))
|
|
218
|
+
return false;
|
|
219
|
+
this.ledger.setPreference(principalId, p, this.iso());
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
dismiss(principalId, captureId) {
|
|
223
|
+
return this.ledger.dismissCapture(principalId, captureId, this.iso());
|
|
224
|
+
}
|
|
225
|
+
current(principalId) {
|
|
226
|
+
const seen = new Set();
|
|
227
|
+
const operations = [];
|
|
228
|
+
for (const g of this.ledger.listActiveGrants(principalId, this.iso())) {
|
|
229
|
+
const k = JSON.stringify([g.projectId, g.pluginId, g.operationId]);
|
|
230
|
+
if (seen.has(k) || !this.authority.authorize(principalId, g.projectId, g.pluginId, g.operationId))
|
|
231
|
+
continue;
|
|
232
|
+
seen.add(k);
|
|
233
|
+
operations.push({ projectId: g.projectId, pluginId: g.pluginId, operationId: g.operationId, effectClass: (this.authority.effectClassOf(g.pluginId, g.operationId) ?? 'read'), consent: this.authority.consentModeFor(principalId, g.projectId, g.pluginId, g.operationId), expiresAt: g.expiresAt });
|
|
234
|
+
const option = operations[operations.length - 1];
|
|
235
|
+
option.projectLabel = basename(this.ledger.getProjectRoot(g.projectId) ?? 'Registered project').slice(0, 120);
|
|
236
|
+
Object.assign(option, this.presentation?.(g.pluginId, g.operationId));
|
|
237
|
+
}
|
|
238
|
+
const pref = this.ledger.getPreference(principalId);
|
|
239
|
+
const preferred = pref && operations.some((o) => o.projectId === pref.projectId && o.pluginId === pref.pluginId && o.operationId === pref.operationId)
|
|
240
|
+
? pref : operations[0] ? { projectId: operations[0].projectId, pluginId: operations[0].pluginId, operationId: operations[0].operationId } : null;
|
|
241
|
+
let capture = null;
|
|
242
|
+
let run = null;
|
|
243
|
+
let ret = null;
|
|
244
|
+
const c = this.ledger.latestCapture(principalId);
|
|
245
|
+
if (c) {
|
|
246
|
+
const expired = c.consumedRunId === null && Date.parse(c.expiresAt) <= this.now();
|
|
247
|
+
let opened;
|
|
248
|
+
try {
|
|
249
|
+
opened = this.openCapture(c);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
opened = undefined;
|
|
253
|
+
}
|
|
254
|
+
if (opened) {
|
|
255
|
+
capture = { captureId: c.captureId, text: expired ? '' : opened.text, sha256: c.sha256, bytes: c.bytes, createdAt: c.createdAt, expiresAt: c.expiresAt, state: c.consumedRunId ? 'DISPATCHED' : expired ? 'EXPIRED' : 'CAPTURED', binding: opened.binding, fidelity: opened.fidelity, lineEndingsNormalized: opened.lineEndingsNormalized };
|
|
256
|
+
}
|
|
257
|
+
if (c.consumedRunId) {
|
|
258
|
+
const r = this.ledger.getRunForPrincipal(principalId, c.consumedRunId);
|
|
259
|
+
if (r)
|
|
260
|
+
run = { runId: r.runId, lifecycleState: r.lifecycleState, updatedAt: r.updatedAt, consent: c.consentMode ?? 'LOCAL_CONFIRM', failure: (r.lifecycleState === 'FAILED' || r.lifecycleState === 'UNKNOWN' || r.lifecycleState === 'COMPLETED' || r.lifecycleState === 'CANCELLED') ? (this.telemetry?.describeFailure(r.runId, r.lifecycleState) ?? null) : null };
|
|
261
|
+
const snap = r && r.lifecycleState === 'COMPLETED' ? this.ledger.getReturnSnapshot(principalId, r.runId) : undefined;
|
|
262
|
+
const target = snap ? this.targetOf(snap.returnId) : undefined;
|
|
263
|
+
if (snap && target) {
|
|
264
|
+
const rc = this.ledger.latestReturnReceipt(snap.returnId);
|
|
265
|
+
ret = { returnId: snap.returnId, sha256: snap.sha256, bytes: snap.bytes, text: snap.text, state: rc?.state ?? 'RETURN_READY', code: rc?.code ?? null, binding: target.binding, rebinds: this.ledger.countReturnTargets(snap.returnId) - 1 };
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return { schemaVersion: SCHEMA_VERSION_V1, operations, preferred, capture, run, ret };
|
|
270
|
+
}
|
|
271
|
+
/** Meaningful durable-state revision. Observation time is deliberately absent: quiet health does not manufacture activity. */
|
|
272
|
+
revision(principalId, snapshot = this.current(principalId)) {
|
|
273
|
+
return sha(JSON.stringify([snapshot, snapshot.run ? this.ledger.activityCursor(snapshot.run.runId) : null]));
|
|
274
|
+
}
|
|
275
|
+
/** Authenticated, principal-scoped projection of durable lifecycle, process and coding evidence.
|
|
276
|
+
* Only fixed vocabulary is exposed from coding records; never detailJson, paths, patches or model text.
|
|
277
|
+
* Process text has already been redacted before persistence; redact again and remove terminal markup.
|
|
278
|
+
*/
|
|
279
|
+
activity(principalId, runId, cursor) {
|
|
280
|
+
const run = this.ledger.getRunForPrincipal(principalId, runId);
|
|
281
|
+
if (!run)
|
|
282
|
+
throw new WorkflowRefusal('NOT_FOUND');
|
|
283
|
+
const rows = this.ledger.activityRows(runId);
|
|
284
|
+
const safe = (s) => redactText(s.replace(/(?:[A-Za-z]:[\\/]|\/home\/|\/Users\/)[^\s"']+/g, '[PRIVATE_PATH]').replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '').replace(/<[^>]*>/g, '[MARKUP]'), { max: 240 }).text;
|
|
285
|
+
const vocabulary = (s) => /^[A-Z][A-Z0-9_.:-]{0,63}$/.test(s) ? s : 'RECORD_REDACTED';
|
|
286
|
+
const all = [
|
|
287
|
+
...rows.lifecycle.map(r => ({ id: `L:${r.seq}`, ts: r.ts, component: 'C05', severity: (['FAILED', 'UNKNOWN'].includes(r.state) ? 'ERROR' : 'INFO'), status: 'OBSERVED', kind: vocabulary(r.state), summary: vocabulary(r.state), runId })),
|
|
288
|
+
...rows.execution.map(r => ({ id: `E:${r.seq}`, ts: r.ts, component: 'C06', severity: (r.kind === 'STDERR' ? 'WARN' : 'INFO'), status: 'OBSERVED', kind: vocabulary(r.kind), summary: safe(`${r.stage ?? ''} ${r.data}`), runId })),
|
|
289
|
+
...rows.coding.map(r => ({ id: `C:${r.seq}`, ts: r.ts, component: 'C07', severity: (r.decision === 'DENIED' ? 'WARN' : 'INFO'), status: 'OBSERVED', kind: vocabulary(r.event), summary: `${vocabulary(r.event)} ${r.decision === 'DENIED' ? 'DENIED' : r.decision === 'ALLOWED' ? 'ALLOWED' : ''}`, runId })),
|
|
290
|
+
];
|
|
291
|
+
const since = cursor.split(':').map(Number);
|
|
292
|
+
const index = (id) => id[0] === 'L' ? 0 : id[0] === 'E' ? 1 : 2;
|
|
293
|
+
const fresh = all.filter(e => Number(e.id.slice(2)) > (since[index(e.id)] ?? 0));
|
|
294
|
+
fresh.sort((a, b) => a.ts.localeCompare(b.ts) || a.id[0].localeCompare(b.id[0]) || Number(a.id.slice(2)) - Number(b.id.slice(2)));
|
|
295
|
+
return { schemaVersion: 1, runId, cursor: rows.cursor, collectedAt: this.iso(), daemonVersion: '0.3.0',
|
|
296
|
+
phase: run.lifecycleState, startedAt: run.createdAt, truncated: fresh.length > 80 || rows.truncated, events: fresh.slice(-80) };
|
|
297
|
+
}
|
|
298
|
+
isTerminal(state) { return TERMINAL.has(state); }
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=workflowService.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { type SupervisionEvidence, type WindowsJobSupervisor } from './windows/windowsJobSupervisor.js';
|
|
2
|
+
/**
|
|
3
|
+
* C06 bounded subprocess host (B03-A). A provider-neutral, process-local MECHANISM.
|
|
4
|
+
*
|
|
5
|
+
* What it does: validates one request, spawns exactly one pinned executable with an argv array (shell:false,
|
|
6
|
+
* windowsHide:true, detached:false), a brand-new explicit environment, bounded stdout/stderr, a timeout and
|
|
7
|
+
* cancellation, and reports a truthful outcome.
|
|
8
|
+
*
|
|
9
|
+
* Executable identity (SW-044): the host is constructed with a TRUSTED expected SHA-256 of the pinned executable's
|
|
10
|
+
* bytes. Every run streams the file through SHA-256 on one handle immediately before the spawn and refuses to spawn
|
|
11
|
+
* on any mismatch, change of file identity or length, or change observed while reading. This is DEFENSE IN DEPTH
|
|
12
|
+
* only: Node's spawn takes a path, so the interval between the last check and CreateProcess is NOT closed
|
|
13
|
+
* (TOCTOU_NOT_VERIFIED), and a hash proves nothing about behavior, safety or authorization.
|
|
14
|
+
*
|
|
15
|
+
* What it is NOT: a sandbox. cwd, shell:false, windowsHide and the environment allowlist do NOT stop the child
|
|
16
|
+
* from reading or writing anywhere the current user can. There is deliberately no "sandboxVerified" notion here.
|
|
17
|
+
* Descendant processes are not tracked: processTreeTerminated is never reported true in this batch (see
|
|
18
|
+
* ProcessHostResult). Output is untrusted data and is never logged by this module. This module has no durable
|
|
19
|
+
* state, no HTTP, no authorization decision and no knowledge of any agent; its only legitimate future caller is a
|
|
20
|
+
* trusted coordinator that already holds an independently verified executable and capability.
|
|
21
|
+
*
|
|
22
|
+
* Optional Windows Job supervision (SW-046): a trusted constructor may pass a WindowsJobSupervisor. The host then keeps all
|
|
23
|
+
* of its own controls (validation, digest precheck, limits, timeout, cancel, single flight) and only delegates process
|
|
24
|
+
* CREATION and tree cleanup to that supervisor. With it, ProcessHostResult.supervision carries separate observed
|
|
25
|
+
* dimensions and processTreeTerminated may be true ONLY when the supervisor positively verified every tracked Job
|
|
26
|
+
* member. Atomic image identity, filesystem confinement and private-database isolation stay NOT_VERIFIED.
|
|
27
|
+
*/
|
|
28
|
+
export type ProcessHostLimits = Readonly<{
|
|
29
|
+
timeoutMs: number;
|
|
30
|
+
maxStdoutBytes: number;
|
|
31
|
+
maxStderrBytes: number;
|
|
32
|
+
maxArgvBytes: number;
|
|
33
|
+
maxArguments: number;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* SW-068: TRUSTED, in-process evidence sink (never part of a run request). The host reports each lifecycle fact and every output chunk AS IT HAPPENS, so evidence
|
|
37
|
+
* survives a crash, timeout or kill. Calls are best-effort: an observer failure is swallowed and can never change the execution. A stage name beginning with FAILED_
|
|
38
|
+
* records a problem without advancing the "last confirmed stage".
|
|
39
|
+
*/
|
|
40
|
+
export interface ProcessObserver {
|
|
41
|
+
lifecycle(stage: string, data?: Record<string, string | number | boolean | null>): void;
|
|
42
|
+
chunk(stream: 'stdout' | 'stderr', bytes: Uint8Array): void;
|
|
43
|
+
}
|
|
44
|
+
export type ProcessHostRequest = Readonly<{
|
|
45
|
+
runId: string;
|
|
46
|
+
executablePath: string;
|
|
47
|
+
args: readonly string[];
|
|
48
|
+
cwd: string;
|
|
49
|
+
environment: Readonly<Record<string, string>>;
|
|
50
|
+
/**
|
|
51
|
+
* SW-052: approved UTF-8 text delivered once on a private stdin pipe, then EOF. Honoured only when the host was constructed with
|
|
52
|
+
* stdin enabled; the bytes are exactly the UTF-8 encoding of this string (no newline conversion, no truncation).
|
|
53
|
+
*/
|
|
54
|
+
stdinUtf8?: string;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* processTreeTerminated: this host observes only its direct child. It is `null` when no termination was needed or
|
|
58
|
+
* when the direct child was reaped but descendants were not observed (the only truthful positive in B03-A), and
|
|
59
|
+
* `false` when the direct child could not be confirmed terminated. It is never `true`.
|
|
60
|
+
*/
|
|
61
|
+
export type ProcessHostResult = Readonly<{
|
|
62
|
+
runId: string;
|
|
63
|
+
outcome: 'EXITED' | 'TIMEOUT' | 'CANCELLED' | 'SPAWN_FAILED' | 'OUTPUT_LIMIT_EXCEEDED' | 'SUPERVISION_FAILED';
|
|
64
|
+
exitCode: number | null;
|
|
65
|
+
signal: string | null;
|
|
66
|
+
stdoutUtf8: string;
|
|
67
|
+
stderrUtf8: string;
|
|
68
|
+
stdoutTruncated: boolean;
|
|
69
|
+
stderrTruncated: boolean;
|
|
70
|
+
processTreeTerminated: boolean | null;
|
|
71
|
+
durationMs: number;
|
|
72
|
+
/** Present only for runs created through a WindowsJobSupervisor. */
|
|
73
|
+
supervision?: SupervisionEvidence;
|
|
74
|
+
}>;
|
|
75
|
+
export type ProcessHostErrorCode = 'CONFIG_INVALID' | 'LIMITS_INVALID' | 'REQUEST_INVALID' | 'RUN_ID_INVALID' | 'EXECUTABLE_MISMATCH' | 'EXECUTABLE_DIGEST_MISMATCH' | 'EXECUTABLE_UNSTABLE' | 'CWD_NOT_APPROVED_ROOT' | 'ROOT_CHANGED' | 'ARGV_INVALID' | 'ENV_INVALID' | 'HOST_BUSY' | 'DUPLICATE_RUN_ID' | 'RUN_HISTORY_FULL' | 'STDIN_NOT_ENABLED' | 'STDIN_INVALID' | 'HOST_CLOSED' | 'SUPERVISOR_UNAVAILABLE' | 'UNSUPPORTED_PLATFORM';
|
|
76
|
+
/** Sanitized: only a fixed code, never a path, argument, environment value or output. */
|
|
77
|
+
export declare class ProcessHostError extends Error {
|
|
78
|
+
readonly code: ProcessHostErrorCode;
|
|
79
|
+
constructor(code: ProcessHostErrorCode);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* SW-052: the largest per-run timeout a trusted constructor may configure. The DEFAULT stays 30 s; only the trusted owner (never a
|
|
83
|
+
* request) can raise it, and never above this ceiling.
|
|
84
|
+
*/
|
|
85
|
+
export declare const MAX_PROCESS_HOST_TIMEOUT_MS = 120000;
|
|
86
|
+
export declare const DEFAULT_PROCESS_HOST_LIMITS: ProcessHostLimits;
|
|
87
|
+
export declare function createBoundedProcessHost(config: {
|
|
88
|
+
approvedProjectRoot: string;
|
|
89
|
+
approvedExecutablePath: string;
|
|
90
|
+
/** TRUSTED expected SHA-256 (64 hex digits) of the pinned executable's bytes. Never taken from a run request. */
|
|
91
|
+
approvedExecutableSha256: string;
|
|
92
|
+
limits?: Partial<ProcessHostLimits>;
|
|
93
|
+
/** TRUSTED, in-process only; never derived from a run request. Absent = the original plain spawn behavior. */
|
|
94
|
+
supervisor?: WindowsJobSupervisor;
|
|
95
|
+
/** TRUSTED, in-process only (SW-048): fixed extra environment entries; see validateTrustedEnvironment. Absent = unchanged behavior. */
|
|
96
|
+
trustedEnvironment?: {
|
|
97
|
+
containmentRoot: string;
|
|
98
|
+
entries: Readonly<Record<string, string>>;
|
|
99
|
+
};
|
|
100
|
+
/** TRUSTED, in-process only (SW-052): enables bounded stdin delivery; requires a supervisor. Absent = a request carrying stdin is refused. */
|
|
101
|
+
stdin?: {
|
|
102
|
+
maxBytes: number;
|
|
103
|
+
};
|
|
104
|
+
/** TRUSTED (SW-068): incremental evidence sink; see ProcessObserver. */
|
|
105
|
+
observer?: ProcessObserver;
|
|
106
|
+
}): {
|
|
107
|
+
run(request: ProcessHostRequest): Promise<ProcessHostResult>;
|
|
108
|
+
cancel(runId: string): Promise<boolean>;
|
|
109
|
+
close(): Promise<void>;
|
|
110
|
+
};
|
|
111
|
+
//# sourceMappingURL=boundedProcessHost.d.ts.map
|