@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,505 @@
|
|
|
1
|
+
import { AuthorizedInvocationSchema, CancelReceiptSchema, CapabilityReportSchema, NormalizedEventV1Schema, NormalizedResultSchema, RunReceiptSchema, } from '../../../../../packages/contracts/dist/index.js';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { basename } from 'node:path';
|
|
4
|
+
import { createBoundedProcessHost, DEFAULT_PROCESS_HOST_LIMITS, MAX_PROCESS_HOST_TIMEOUT_MS, ProcessHostError } from '../../runtime/boundedProcessHost.js';
|
|
5
|
+
/**
|
|
6
|
+
* C06 generic finite-CLI driver (SW-051): the single selected driver, conforming to PluginDriver (probe, invoke, observe, cancel,
|
|
7
|
+
* collect). It runs ONE operation of ONE pinned plugin through the shared bounded process host and the Windows Job supervisor.
|
|
8
|
+
*
|
|
9
|
+
* Fixed security posture (not configurable by any invocation):
|
|
10
|
+
* - There is no plain-spawn path. The trusted constructor must pass a supervisor whose fixed identity is RESTRICTED_LOW_INTEGRITY;
|
|
11
|
+
* anything else is refused at construction, so a failed or absent restricted identity can never fall back to the caller token.
|
|
12
|
+
* - The executable, its SHA-256 and the argument vector come ONLY from the C04 pinned record, re-inspected at invoke time and
|
|
13
|
+
* required to equal the fingerprint and digest the coordinator durably recorded at prepare time. The host re-hashes the file
|
|
14
|
+
* immediately before creation. A template containing a known permission-bypass flag is refused.
|
|
15
|
+
* - The prompt is substituted into exactly one whole template element equal to PROMPT_PLACEHOLDER. A prompt the host cannot carry
|
|
16
|
+
* as one argument (control characters such as newlines, oversize) or that could be parsed as an option is refused before any
|
|
17
|
+
* process exists (PROMPT_UNREPRESENTABLE). This is a recorded limitation, not a silent rewrite.
|
|
18
|
+
* - SW-052 stdin transport: an operation whose PINNED manifest declares inputTransport {kind:'stdin_utf8'} (and only when this driver was
|
|
19
|
+
* constructed with enableStdinTransport=true) receives the approved prompt as UTF-8 bytes on a private pipe, written once and closed. Its
|
|
20
|
+
* argv template must NOT contain the prompt placeholder, so the prompt can never also reach argv. The prompt's SHA-256 must equal the digest
|
|
21
|
+
* the coordinator took from the immutable acceptance-time snapshot. Operations without the field are exactly the SW-051 argv operations.
|
|
22
|
+
* - SW-052 script identity: an interpreter (node, python, powershell, cmd, ...) executes code the interpreter's own digest does not describe.
|
|
23
|
+
* Such an operation is DISABLED (SCRIPT_UNPINNED) unless trusted composition pinned every code-bearing file, and every pinned file must be
|
|
24
|
+
* an exact element of the argv template. Pinning is by content digest, size and file id (revalidated at prepare and at invoke); the OS
|
|
25
|
+
* does not give an atomic launch identity, so a residual race between the check and the interpreter opening the file stays NOT_VERIFIED.
|
|
26
|
+
* - SW-052 timeout: the pinned operation's timeoutMs is honoured up to MAX_PROCESS_HOST_TIMEOUT_MS (120 s); above that the operation is
|
|
27
|
+
* refused (TIMEOUT_EXCEEDS_LIMIT), never silently clamped. A request cannot supply a timeout.
|
|
28
|
+
* - securityTier must be PATH_CHECKS_ONLY. This driver never claims OS enforcement or filesystem confinement.
|
|
29
|
+
*
|
|
30
|
+
* Output: stdout is buffered by the host and parsed after exit (supportsStreaming=false). The provider-specific parser lives here
|
|
31
|
+
* only: 'codex-exec-jsonl-v1' maps the frame shapes recorded by SW-024/SW-025 (thread.started, turn.started, item.started /
|
|
32
|
+
* item.completed with agent_message or command_execution, turn.completed). Any other line is kept as a bounded stdout_chunk.
|
|
33
|
+
* Agent prose is untrusted data; a final message is reported, never treated as validation.
|
|
34
|
+
*/
|
|
35
|
+
export const PROMPT_PLACEHOLDER = '{{prompt}}';
|
|
36
|
+
export class DriverError extends Error {
|
|
37
|
+
code;
|
|
38
|
+
constructor(code) {
|
|
39
|
+
super(code);
|
|
40
|
+
this.code = code;
|
|
41
|
+
this.name = 'DriverError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const INTERPRETERS = new Set(['node', 'nodejs', 'python', 'python3', 'pythonw', 'py', 'powershell', 'pwsh', 'cmd', 'wscript', 'cscript', 'mshta', 'bash', 'sh', 'deno', 'bun', 'ruby', 'perl', 'java', 'javaw', 'php', 'lua']);
|
|
45
|
+
const FORBIDDEN_TEMPLATE = /dangerous|yolo|full-auto|danger-full-access|bypass|skip-permissions|--add-dir|allow-all/i;
|
|
46
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
47
|
+
const MAX_EVENTS = 1000;
|
|
48
|
+
const MAX_TEXT = 8192;
|
|
49
|
+
const MAX_SUMMARY = 8192;
|
|
50
|
+
const bounded = (s, max = MAX_TEXT) => s.length > max ? { text: s.slice(0, max), truncated: true } : { text: s, truncated: false };
|
|
51
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
52
|
+
const num = (v) => (typeof v === 'number' && Number.isSafeInteger(v) && v >= 0 ? v : undefined);
|
|
53
|
+
export function createFiniteCliDriver(config) {
|
|
54
|
+
if (config === null || typeof config !== 'object')
|
|
55
|
+
throw new DriverError('DRIVER_CONFIG_INVALID');
|
|
56
|
+
const { pluginId, registry, supervisor, childTempDirectory, trustedEnvironment, outputProfile } = config;
|
|
57
|
+
const stdinEnabled = config.enableStdinTransport === true;
|
|
58
|
+
const fixedNoPrompt = new Set(Array.isArray(config.fixedNoPromptOperations) ? config.fixedNoPromptOperations.filter((s) => typeof s === 'string' && s.length > 0) : []);
|
|
59
|
+
const now = config.now ?? Date.now;
|
|
60
|
+
if (typeof pluginId !== 'string' || pluginId.length === 0)
|
|
61
|
+
throw new DriverError('DRIVER_CONFIG_INVALID');
|
|
62
|
+
if (!registry || typeof registry.inspectOperation !== 'function')
|
|
63
|
+
throw new DriverError('DRIVER_CONFIG_INVALID');
|
|
64
|
+
// No fallback: only the verified restricted identity is acceptable for this driver.
|
|
65
|
+
if (!supervisor || supervisor.kind !== 'WINDOWS_JOB_SUPERVISOR' || supervisor.executionIdentity !== 'RESTRICTED_LOW_INTEGRITY') {
|
|
66
|
+
throw new DriverError('DRIVER_CONFIG_INVALID');
|
|
67
|
+
}
|
|
68
|
+
if (typeof childTempDirectory !== 'string' || childTempDirectory.length === 0)
|
|
69
|
+
throw new DriverError('DRIVER_CONFIG_INVALID');
|
|
70
|
+
if (outputProfile !== 'codex-exec-jsonl-v1')
|
|
71
|
+
throw new DriverError('DRIVER_CONFIG_INVALID');
|
|
72
|
+
const systemRoot = process.env.SystemRoot;
|
|
73
|
+
if (typeof systemRoot !== 'string')
|
|
74
|
+
throw new DriverError('DRIVER_CONFIG_INVALID');
|
|
75
|
+
const runs = new Map();
|
|
76
|
+
function templateIsSafe(template, mode) {
|
|
77
|
+
// argv transport: the prompt is exactly one whole element. stdin transport / fixed prompt-less command: the prompt can NEVER be in argv, so no placeholder at all.
|
|
78
|
+
if (template.filter((a) => a === PROMPT_PLACEHOLDER).length !== (mode === 'ARGV' ? 1 : 0))
|
|
79
|
+
return false;
|
|
80
|
+
return !template.some((a) => FORBIDDEN_TEMPLATE.test(a) || (a !== PROMPT_PLACEHOLDER && a.includes('{{')));
|
|
81
|
+
}
|
|
82
|
+
async function prepare(runId, operationId) {
|
|
83
|
+
if (typeof runId !== 'string' || runId.length === 0 || typeof operationId !== 'string')
|
|
84
|
+
return { ok: false, code: 'OPERATION_UNKNOWN' };
|
|
85
|
+
// A plan may be refreshed until the run is invoked (e.g. a launch refused for a busy worktree); never after.
|
|
86
|
+
if (runs.get(runId)?.invoked)
|
|
87
|
+
return { ok: false, code: 'DUPLICATE_RUN' };
|
|
88
|
+
const ins = await registry.inspectOperation(pluginId, operationId);
|
|
89
|
+
if (!ins.ok)
|
|
90
|
+
return { ok: false, code: ins.reason === 'UNKNOWN_OPERATION' || ins.reason === 'UNKNOWN_PLUGIN' ? 'OPERATION_UNKNOWN' : 'EXECUTABLE_CHANGED' };
|
|
91
|
+
const transport = ins.operation.inputTransport;
|
|
92
|
+
if (transport !== null && !stdinEnabled)
|
|
93
|
+
return { ok: false, code: 'TRANSPORT_NOT_ENABLED' };
|
|
94
|
+
const mode = transport !== null ? 'STDIN' : fixedNoPrompt.has(operationId) ? 'NONE' : 'ARGV';
|
|
95
|
+
if (!templateIsSafe(ins.operation.argvTemplate, mode))
|
|
96
|
+
return { ok: false, code: 'TEMPLATE_UNSAFE' };
|
|
97
|
+
if (ins.operation.timeoutMs > MAX_PROCESS_HOST_TIMEOUT_MS)
|
|
98
|
+
return { ok: false, code: 'TIMEOUT_EXCEEDS_LIMIT' };
|
|
99
|
+
const interp = basename(ins.record.executable.canonicalPath).toLowerCase().replace(/\.exe$/, '');
|
|
100
|
+
if (INTERPRETERS.has(interp) && ins.record.codeInputs.length === 0)
|
|
101
|
+
return { ok: false, code: 'SCRIPT_UNPINNED' };
|
|
102
|
+
const lowerTemplate = ins.operation.argvTemplate.map((a) => a.toLowerCase());
|
|
103
|
+
for (const ci of ins.record.codeInputs)
|
|
104
|
+
if (!lowerTemplate.includes(ci.canonicalPath.toLowerCase()))
|
|
105
|
+
return { ok: false, code: 'CODE_INPUT_NOT_IN_TEMPLATE' };
|
|
106
|
+
const plan = Object.freeze({
|
|
107
|
+
runId,
|
|
108
|
+
pluginId,
|
|
109
|
+
operationId,
|
|
110
|
+
manifestFingerprint: ins.record.manifestFingerprint,
|
|
111
|
+
executableSha256: ins.record.executable.sha256,
|
|
112
|
+
effectClass: ins.operation.effectClass,
|
|
113
|
+
timeoutMs: ins.operation.timeoutMs,
|
|
114
|
+
maxOutputBytes: Math.min(ins.operation.maxOutputBytes, DEFAULT_PROCESS_HOST_LIMITS.maxStdoutBytes),
|
|
115
|
+
executionIdentity: supervisor.executionIdentity,
|
|
116
|
+
inputTransport: mode,
|
|
117
|
+
argvTemplate: Object.freeze([...ins.operation.argvTemplate]),
|
|
118
|
+
stdinMaxBytes: transport === null ? null : transport.maxBytes,
|
|
119
|
+
codeInputsSha256: ins.record.codeInputsSha256,
|
|
120
|
+
});
|
|
121
|
+
if (runs.get(runId)?.invoked)
|
|
122
|
+
return { ok: false, code: 'DUPLICATE_RUN' }; // re-checked after the await
|
|
123
|
+
runs.set(runId, { plan, invoked: false, cancelRequested: false });
|
|
124
|
+
return { ok: true, plan };
|
|
125
|
+
}
|
|
126
|
+
function buildArgs(template, prompt, maxArgvBytes) {
|
|
127
|
+
if (prompt.length === 0 || CONTROL.test(prompt))
|
|
128
|
+
throw new DriverError('PROMPT_UNREPRESENTABLE');
|
|
129
|
+
const at = template.indexOf(PROMPT_PLACEHOLDER);
|
|
130
|
+
if (prompt.startsWith('-') && template[at - 1] !== '--')
|
|
131
|
+
throw new DriverError('PROMPT_UNREPRESENTABLE'); // could be read as an option
|
|
132
|
+
const args = template.map((a) => (a === PROMPT_PLACEHOLDER ? prompt : a));
|
|
133
|
+
const bytes = args.reduce((n, a) => n + Buffer.byteLength(a, 'utf8') + 1, 0);
|
|
134
|
+
if (bytes > maxArgvBytes)
|
|
135
|
+
throw new DriverError('PROMPT_UNREPRESENTABLE');
|
|
136
|
+
return args;
|
|
137
|
+
}
|
|
138
|
+
function invoke(request) {
|
|
139
|
+
return (async () => {
|
|
140
|
+
const parsed = AuthorizedInvocationSchema.safeParse(request);
|
|
141
|
+
if (!parsed.success)
|
|
142
|
+
throw new DriverError('INVOCATION_INVALID');
|
|
143
|
+
const inv = parsed.data;
|
|
144
|
+
if (inv.pluginId !== pluginId)
|
|
145
|
+
throw new DriverError('PLUGIN_MISMATCH');
|
|
146
|
+
if (inv.securityTier !== 'PATH_CHECKS_ONLY')
|
|
147
|
+
throw new DriverError('SECURITY_TIER_UNSUPPORTED');
|
|
148
|
+
const entry = runs.get(inv.runId);
|
|
149
|
+
if (!entry)
|
|
150
|
+
throw new DriverError('NOT_PREPARED');
|
|
151
|
+
if (entry.invoked)
|
|
152
|
+
throw new DriverError('DUPLICATE_RUN');
|
|
153
|
+
if (entry.plan.operationId !== inv.operationId)
|
|
154
|
+
throw new DriverError('INVOCATION_INVALID');
|
|
155
|
+
entry.invoked = true; // spent before any await: a run id is invoked at most once
|
|
156
|
+
entry.projectId = inv.projectId;
|
|
157
|
+
const settle = (o) => {
|
|
158
|
+
if (o.kind === 'NOT_LAUNCHED') {
|
|
159
|
+
try {
|
|
160
|
+
entry.observer?.lifecycle('FAILED_NOT_LAUNCHED', { code: o.code });
|
|
161
|
+
}
|
|
162
|
+
catch { /* evidence is best-effort */ }
|
|
163
|
+
}
|
|
164
|
+
return Promise.resolve(Object.freeze(o));
|
|
165
|
+
};
|
|
166
|
+
if (entry.cancelRequested) {
|
|
167
|
+
entry.settled = settle({ kind: 'NOT_LAUNCHED', code: 'CANCELLED_BEFORE_LAUNCH' });
|
|
168
|
+
return receipt(inv);
|
|
169
|
+
}
|
|
170
|
+
// Re-inspect: the pinned identity must still be exactly what was durably recorded at prepare time.
|
|
171
|
+
const ins = await registry.inspectOperation(pluginId, inv.operationId);
|
|
172
|
+
if (!ins.ok || ins.record.manifestFingerprint !== entry.plan.manifestFingerprint || ins.record.executable.sha256 !== entry.plan.executableSha256 || ins.record.codeInputsSha256 !== entry.plan.codeInputsSha256) {
|
|
173
|
+
entry.settled = settle({ kind: 'NOT_LAUNCHED', code: 'EXECUTABLE_CHANGED' });
|
|
174
|
+
return receipt(inv);
|
|
175
|
+
}
|
|
176
|
+
let runTrusted = trustedEnvironment;
|
|
177
|
+
let runEnvRelease;
|
|
178
|
+
let runCwd = inv.workingDirectory;
|
|
179
|
+
if (config.runEnvironment) {
|
|
180
|
+
const extra = (() => { try {
|
|
181
|
+
return config.runEnvironment.resolve(inv);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return undefined;
|
|
185
|
+
} })();
|
|
186
|
+
if (!extra || !trustedEnvironment) {
|
|
187
|
+
entry.settled = settle({ kind: 'NOT_LAUNCHED', code: 'PROJECT_READ_UNAVAILABLE' });
|
|
188
|
+
return receipt(inv);
|
|
189
|
+
}
|
|
190
|
+
if (typeof extra.workingDirectory === 'string' && extra.workingDirectory.length > 0)
|
|
191
|
+
runCwd = extra.workingDirectory;
|
|
192
|
+
const release = config.runEnvironment.release;
|
|
193
|
+
runEnvRelease = () => { try {
|
|
194
|
+
release(inv.runId);
|
|
195
|
+
}
|
|
196
|
+
catch { /* best-effort: the capability also expires */ } };
|
|
197
|
+
runTrusted = {
|
|
198
|
+
containmentRoot: trustedEnvironment.containmentRoot,
|
|
199
|
+
entries: { ...trustedEnvironment.entries, ...(extra.entries ?? {}) },
|
|
200
|
+
files: { ...(trustedEnvironment.files ?? {}), ...(extra.files ?? {}) },
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const prompt = inv.params.prompt;
|
|
204
|
+
const stdinMode = entry.plan.inputTransport === 'STDIN';
|
|
205
|
+
let args;
|
|
206
|
+
try {
|
|
207
|
+
if (typeof prompt !== 'string')
|
|
208
|
+
throw new DriverError(stdinMode ? 'INPUT_INVALID' : 'PROMPT_UNREPRESENTABLE');
|
|
209
|
+
// The prompt must be exactly the one the coordinator took from the immutable acceptance-time snapshot.
|
|
210
|
+
const digest = inv.params.promptSha256;
|
|
211
|
+
if (stdinMode || digest !== undefined) {
|
|
212
|
+
if (typeof digest !== 'string' || digest !== createHash('sha256').update(prompt, 'utf8').digest('hex'))
|
|
213
|
+
throw new DriverError('PROMPT_DIGEST_MISMATCH');
|
|
214
|
+
}
|
|
215
|
+
if (entry.plan.inputTransport === 'NONE') {
|
|
216
|
+
args = [...ins.operation.argvTemplate]; // fixed command: nothing derived from the prompt reaches argv, stdin or the environment
|
|
217
|
+
}
|
|
218
|
+
else if (stdinMode) {
|
|
219
|
+
if (prompt.length === 0 || /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(prompt) || prompt.includes('\u0000'))
|
|
220
|
+
throw new DriverError('INPUT_INVALID');
|
|
221
|
+
if (Buffer.byteLength(prompt, 'utf8') > entry.plan.stdinMaxBytes)
|
|
222
|
+
throw new DriverError('INPUT_INVALID');
|
|
223
|
+
args = [...ins.operation.argvTemplate]; // fixed template: the prompt is never part of argv
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
args = buildArgs(ins.operation.argvTemplate, prompt, DEFAULT_PROCESS_HOST_LIMITS.maxArgvBytes);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (e) {
|
|
230
|
+
runEnvRelease?.();
|
|
231
|
+
entry.settled = settle({ kind: 'NOT_LAUNCHED', code: e instanceof DriverError ? e.code : 'PROMPT_UNREPRESENTABLE' });
|
|
232
|
+
return receipt(inv);
|
|
233
|
+
}
|
|
234
|
+
let host;
|
|
235
|
+
try {
|
|
236
|
+
host = createBoundedProcessHost({
|
|
237
|
+
approvedProjectRoot: runCwd,
|
|
238
|
+
approvedExecutablePath: ins.record.executable.canonicalPath,
|
|
239
|
+
approvedExecutableSha256: entry.plan.executableSha256,
|
|
240
|
+
supervisor,
|
|
241
|
+
limits: {
|
|
242
|
+
timeoutMs: Math.min(inv.timeoutMs, entry.plan.timeoutMs),
|
|
243
|
+
maxStdoutBytes: entry.plan.maxOutputBytes,
|
|
244
|
+
maxStderrBytes: entry.plan.maxOutputBytes,
|
|
245
|
+
},
|
|
246
|
+
...(runTrusted ? { trustedEnvironment: runTrusted } : {}),
|
|
247
|
+
...(stdinMode ? { stdin: { maxBytes: entry.plan.stdinMaxBytes } } : {}),
|
|
248
|
+
...(entry.observer ? { observer: entry.observer } : {}),
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
runEnvRelease?.();
|
|
253
|
+
entry.settled = settle({ kind: 'NOT_LAUNCHED', code: e instanceof ProcessHostError ? e.code : 'HOST_UNAVAILABLE' });
|
|
254
|
+
return receipt(inv);
|
|
255
|
+
}
|
|
256
|
+
if (entry.cancelRequested) { // a cancel that arrived during the awaits above; nothing between here and run() yields
|
|
257
|
+
runEnvRelease?.();
|
|
258
|
+
entry.settled = settle({ kind: 'NOT_LAUNCHED', code: 'CANCELLED_BEFORE_LAUNCH' });
|
|
259
|
+
return receipt(inv);
|
|
260
|
+
}
|
|
261
|
+
const running = host.run({
|
|
262
|
+
runId: inv.runId,
|
|
263
|
+
executablePath: ins.record.executable.canonicalPath,
|
|
264
|
+
args,
|
|
265
|
+
cwd: runCwd,
|
|
266
|
+
environment: { SystemRoot: systemRoot, TEMP: childTempDirectory, TMP: childTempDirectory },
|
|
267
|
+
...(stdinMode ? { stdinUtf8: prompt } : {}),
|
|
268
|
+
});
|
|
269
|
+
entry.cancel = () => host.cancel(inv.runId);
|
|
270
|
+
entry.settled = running.then((r) => Object.freeze(toOutcome(inv, r)), (e) => { const code = e instanceof ProcessHostError ? e.code : 'HOST_FAILED'; try {
|
|
271
|
+
entry.observer?.lifecycle('FAILED_NOT_LAUNCHED', { code });
|
|
272
|
+
}
|
|
273
|
+
catch { /* best-effort */ } return Object.freeze({ kind: 'NOT_LAUNCHED', code }); }).finally(() => { void host.close(); runEnvRelease?.(); });
|
|
274
|
+
return receipt(inv);
|
|
275
|
+
})();
|
|
276
|
+
}
|
|
277
|
+
function receipt(inv) {
|
|
278
|
+
return RunReceiptSchema.parse({ runId: inv.runId, pluginId: inv.pluginId, operationId: inv.operationId, startedAt: new Date(now()).toISOString() });
|
|
279
|
+
}
|
|
280
|
+
function toOutcome(inv, r) {
|
|
281
|
+
const sev = r.supervision;
|
|
282
|
+
const parsed = parseCodexExecJsonl(inv, r, now);
|
|
283
|
+
return {
|
|
284
|
+
kind: 'FINISHED',
|
|
285
|
+
processOutcome: r.outcome,
|
|
286
|
+
processLaunched: sev ? sev.processLaunched : false,
|
|
287
|
+
exitCode: r.exitCode,
|
|
288
|
+
treeTerminated: r.processTreeTerminated,
|
|
289
|
+
executionIdentity: sev ? sev.executionIdentity : null,
|
|
290
|
+
childTokenVerified: sev ? sev.childTokenVerified : false,
|
|
291
|
+
jobAssignedBeforeResume: sev ? sev.jobAssignedBeforeResume : false,
|
|
292
|
+
supervisionProtocol: sev ? sev.protocol : null,
|
|
293
|
+
stdoutSha256: createHash('sha256').update(r.stdoutUtf8, 'utf8').digest('hex'),
|
|
294
|
+
stdoutBytes: Buffer.byteLength(r.stdoutUtf8, 'utf8'),
|
|
295
|
+
stdoutTruncated: r.stdoutTruncated,
|
|
296
|
+
stderrBytes: Buffer.byteLength(r.stderrUtf8, 'utf8'),
|
|
297
|
+
stderrTruncated: r.stderrTruncated,
|
|
298
|
+
stdinStatus: sev ? sev.stdinStatus : 'NOT_REQUESTED',
|
|
299
|
+
stdinBytesWritten: sev ? sev.stdinBytesWritten : null,
|
|
300
|
+
stdinBytesExpected: sev ? sev.stdinBytesExpected : null,
|
|
301
|
+
durationMs: r.durationMs,
|
|
302
|
+
finalMessage: parsed.finalMessage,
|
|
303
|
+
unparsedLines: parsed.unparsedLines,
|
|
304
|
+
events: Object.freeze(parsed.events),
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
async function outcome(runId) {
|
|
308
|
+
const entry = runs.get(runId);
|
|
309
|
+
if (!entry || !entry.settled)
|
|
310
|
+
throw new DriverError('UNKNOWN_RUN');
|
|
311
|
+
return entry.settled;
|
|
312
|
+
}
|
|
313
|
+
async function* observe(runId) {
|
|
314
|
+
const o = await outcome(runId);
|
|
315
|
+
if (o.kind === 'FINISHED')
|
|
316
|
+
for (const e of o.events)
|
|
317
|
+
yield e;
|
|
318
|
+
}
|
|
319
|
+
async function cancel(runId, reason) {
|
|
320
|
+
const entry = runs.get(runId);
|
|
321
|
+
const at = () => new Date(now()).toISOString();
|
|
322
|
+
if (!entry)
|
|
323
|
+
return CancelReceiptSchema.parse({ runId, cancelledAt: at(), acknowledged: false, processTerminated: false, reason });
|
|
324
|
+
entry.cancelRequested = true;
|
|
325
|
+
if (!entry.settled)
|
|
326
|
+
return CancelReceiptSchema.parse({ runId, cancelledAt: at(), acknowledged: true, processTerminated: false, reason }); // never launched
|
|
327
|
+
if (entry.cancel)
|
|
328
|
+
await entry.cancel();
|
|
329
|
+
const o = await entry.settled;
|
|
330
|
+
const terminated = o.kind === 'FINISHED' && o.processOutcome === 'CANCELLED' && (o.treeTerminated === true || !o.processLaunched);
|
|
331
|
+
return CancelReceiptSchema.parse({ runId, cancelledAt: at(), acknowledged: true, processTerminated: terminated, reason });
|
|
332
|
+
}
|
|
333
|
+
async function collect(runId) {
|
|
334
|
+
const o = await outcome(runId);
|
|
335
|
+
if (o.kind !== 'FINISHED' || !o.processLaunched)
|
|
336
|
+
throw new DriverError('UNKNOWN_RUN'); // never manufacture a result for a run that did not execute
|
|
337
|
+
return NormalizedResultSchema.parse({
|
|
338
|
+
runId,
|
|
339
|
+
exitCode: o.exitCode ?? -1,
|
|
340
|
+
durationMs: Math.max(0, Math.round(o.durationMs)),
|
|
341
|
+
outputSummary: bounded(o.finalMessage ?? '', MAX_SUMMARY).text,
|
|
342
|
+
completedAt: new Date(now()).toISOString(),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
async function probe() {
|
|
346
|
+
const rec = registry.get(pluginId);
|
|
347
|
+
const live = rec ? await registry.revalidate(pluginId) : undefined;
|
|
348
|
+
return CapabilityReportSchema.parse({
|
|
349
|
+
pluginId,
|
|
350
|
+
installed: live?.ok === true,
|
|
351
|
+
...(rec ? { installedVersion: rec.version } : {}),
|
|
352
|
+
capabilities: { supportsSession: false, supportsApproval: false, supportsResume: false, supportsStreaming: false },
|
|
353
|
+
details: {
|
|
354
|
+
driverType: 'FINITE_CLI',
|
|
355
|
+
outputProfile,
|
|
356
|
+
versionSource: 'MANIFEST_DECLARED',
|
|
357
|
+
behavioralProbe: 'NOT_PERFORMED',
|
|
358
|
+
executionIdentity: supervisor.executionIdentity,
|
|
359
|
+
securityTier: 'PATH_CHECKS_ONLY',
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
return Object.freeze({
|
|
364
|
+
pluginId,
|
|
365
|
+
executionIdentity: supervisor.executionIdentity,
|
|
366
|
+
outputProfile,
|
|
367
|
+
attachObserver(runId, observer) {
|
|
368
|
+
const e = runs.get(runId);
|
|
369
|
+
if (e && !e.invoked)
|
|
370
|
+
e.observer = observer; // only before the run is invoked: evidence is attached to exactly one launch
|
|
371
|
+
},
|
|
372
|
+
prepare,
|
|
373
|
+
outcome,
|
|
374
|
+
probe,
|
|
375
|
+
invoke,
|
|
376
|
+
observe,
|
|
377
|
+
cancel,
|
|
378
|
+
collect,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* SW-066: the assistant text of one completed item, EXACTLY as the CLI wrote it (no trimming, joining separators or normalization). Two shapes were observed from
|
|
383
|
+
* real Codex runs across versions and both are accepted, so a CLI update that switches shape does not silently turn every run into NO_FINAL_TEXT:
|
|
384
|
+
* {type:'agent_message', text} (SW-024/025)
|
|
385
|
+
* {type:'message', role:'assistant', content:[{type:'text'|'output_text', text}, ...]} (SW-003; the parts are concatenated in order, nothing between them)
|
|
386
|
+
* Anything else (a user message, a reasoning item, a part of another kind) yields undefined and is kept only as a bounded event, never as the final message.
|
|
387
|
+
*/
|
|
388
|
+
function assistantText(item) {
|
|
389
|
+
if (!item)
|
|
390
|
+
return undefined;
|
|
391
|
+
if (item.type === 'agent_message')
|
|
392
|
+
return typeof item.text === 'string' ? item.text : undefined;
|
|
393
|
+
if (item.type === 'message' && item.role === 'assistant' && Array.isArray(item.content) && item.content.length > 0) {
|
|
394
|
+
let out = '';
|
|
395
|
+
for (const part of item.content) {
|
|
396
|
+
if (!isObj(part) || (part.type !== 'text' && part.type !== 'output_text') || typeof part.text !== 'string')
|
|
397
|
+
return undefined; // a part this parser does not understand: not guessed
|
|
398
|
+
out += part.text;
|
|
399
|
+
}
|
|
400
|
+
return out;
|
|
401
|
+
}
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* SW-067: a failed Codex run (exit 1 after its reconnect loop) used to leave only frame TYPE names behind, so the cause could not be diagnosed afterwards. For the
|
|
406
|
+
* frames that report a problem, a short plain-text message is kept (control characters removed, 300 characters). Bearer-style secrets and long opaque tokens are
|
|
407
|
+
* masked. This is the CLI's own diagnostic prose; it is never treated as a result and never reaches the final message.
|
|
408
|
+
*/
|
|
409
|
+
const DIAGNOSTIC_FRAMES = new Set(['error', 'turn.failed', 'thread.error', 'stream_error']);
|
|
410
|
+
function maskDiag(raw, max) {
|
|
411
|
+
const cleaned = Array.from(raw).map((ch) => (ch.charCodeAt(0) < 32 || ch.charCodeAt(0) === 127 ? ' ' : ch)).join('');
|
|
412
|
+
return cleaned.replace(/Bearer\s+[A-Za-z0-9._~+/=-]+/gi, 'Bearer [MASKED]').replace(/[A-Za-z0-9_-]{40,}/g, '[MASKED]').replace(/\s+/g, ' ').trim().slice(0, max);
|
|
413
|
+
}
|
|
414
|
+
function frameDiagnostic(frame, item) {
|
|
415
|
+
const err = isObj(frame.error) ? frame.error : undefined;
|
|
416
|
+
const msg = typeof frame.message === 'string' ? frame.message : typeof err?.message === 'string' ? err.message
|
|
417
|
+
: item && item.type === 'error' && typeof item.message === 'string' ? item.message : undefined;
|
|
418
|
+
return msg === undefined ? undefined : maskDiag(msg, 300);
|
|
419
|
+
}
|
|
420
|
+
/** Provider-specific parser (codex-exec-jsonl-v1). Bounded; every unrecognized line is kept as data, never executed or trusted. Exported for the pure fidelity tests. */
|
|
421
|
+
export function parseCodexExecJsonl(inv, r, now) {
|
|
422
|
+
const events = [];
|
|
423
|
+
let session;
|
|
424
|
+
let finalMessage = null;
|
|
425
|
+
let unparsedLines = 0;
|
|
426
|
+
let dropped = 0;
|
|
427
|
+
const ts = new Date(now()).toISOString();
|
|
428
|
+
const push = (eventKind, payload) => {
|
|
429
|
+
if (events.length >= MAX_EVENTS - 1) {
|
|
430
|
+
dropped += 1;
|
|
431
|
+
return;
|
|
432
|
+
} // keep room for the terminal event
|
|
433
|
+
events.push(NormalizedEventV1Schema.parse({
|
|
434
|
+
schemaVersion: 1, eventId: `evt.${inv.runId}.${events.length + 1}`, runId: inv.runId, projectId: inv.projectId, pluginId: inv.pluginId,
|
|
435
|
+
timestamp: ts, eventKind, payload: { sequence: events.length + 1, ...payload }, ...(session ? { nativeSessionId: session } : {}),
|
|
436
|
+
}));
|
|
437
|
+
};
|
|
438
|
+
push('run_started', { operationId: inv.operationId, observation: 'RECONSTRUCTED_AFTER_EXIT' });
|
|
439
|
+
for (const raw of r.stdoutUtf8.split('\n')) {
|
|
440
|
+
const line = raw.endsWith('\r') ? raw.slice(0, -1) : raw;
|
|
441
|
+
if (line.trim().length === 0)
|
|
442
|
+
continue;
|
|
443
|
+
let frame;
|
|
444
|
+
try {
|
|
445
|
+
frame = JSON.parse(line);
|
|
446
|
+
}
|
|
447
|
+
catch {
|
|
448
|
+
frame = undefined;
|
|
449
|
+
}
|
|
450
|
+
if (!isObj(frame) || typeof frame.type !== 'string') {
|
|
451
|
+
unparsedLines += 1;
|
|
452
|
+
const b = bounded(line);
|
|
453
|
+
push('stdout_chunk', { text: b.text, truncated: b.truncated });
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
const item = isObj(frame.item) ? frame.item : undefined;
|
|
457
|
+
switch (frame.type) {
|
|
458
|
+
case 'thread.started':
|
|
459
|
+
if (typeof frame.thread_id === 'string' && frame.thread_id.length > 0 && frame.thread_id.length <= 128 && !CONTROL.test(frame.thread_id))
|
|
460
|
+
session = frame.thread_id;
|
|
461
|
+
break;
|
|
462
|
+
case 'turn.started':
|
|
463
|
+
push('agent_turn_started', {});
|
|
464
|
+
break;
|
|
465
|
+
case 'turn.completed': {
|
|
466
|
+
const u = isObj(frame.usage) ? frame.usage : {};
|
|
467
|
+
push('agent_turn_completed', { usage: { inputTokens: num(u.input_tokens), cachedInputTokens: num(u.cached_input_tokens), outputTokens: num(u.output_tokens) } });
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
case 'item.started':
|
|
471
|
+
case 'item.completed':
|
|
472
|
+
if (frame.type === 'item.completed' && assistantText(item) !== undefined) {
|
|
473
|
+
const b = bounded(assistantText(item));
|
|
474
|
+
finalMessage = b.text;
|
|
475
|
+
push('agent_message', { text: b.text, truncated: b.truncated });
|
|
476
|
+
}
|
|
477
|
+
else if (item?.type === 'command_execution') {
|
|
478
|
+
const cmd = bounded(typeof item.command === 'string' ? item.command : '', 2048);
|
|
479
|
+
push('tool_call', {
|
|
480
|
+
phase: frame.type === 'item.started' ? 'started' : 'completed',
|
|
481
|
+
command: cmd.text, commandTruncated: cmd.truncated,
|
|
482
|
+
status: typeof item.status === 'string' ? item.status.slice(0, 32) : null,
|
|
483
|
+
exitCode: typeof item.exit_code === 'number' && Number.isSafeInteger(item.exit_code) ? item.exit_code : null,
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
else {
|
|
487
|
+
const dg = frameDiagnostic(frame, item);
|
|
488
|
+
push('stdout_chunk', { frameType: frame.type, itemType: typeof item?.type === 'string' ? item.type.slice(0, 64) : null, ...(dg !== undefined ? { detail: dg } : {}) });
|
|
489
|
+
}
|
|
490
|
+
break;
|
|
491
|
+
default:
|
|
492
|
+
const dg = DIAGNOSTIC_FRAMES.has(frame.type) ? frameDiagnostic(frame, undefined) : undefined;
|
|
493
|
+
push('stdout_chunk', { frameType: frame.type.slice(0, 64), ...(dg !== undefined ? { detail: dg } : {}) });
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const terminal = r.outcome === 'EXITED' && r.exitCode === 0 ? 'run_completed' : r.outcome === 'CANCELLED' ? 'run_cancelled' : 'run_failed';
|
|
497
|
+
events.push(NormalizedEventV1Schema.parse({
|
|
498
|
+
schemaVersion: 1, eventId: `evt.${inv.runId}.${events.length + 1}`, runId: inv.runId, projectId: inv.projectId, pluginId: inv.pluginId,
|
|
499
|
+
timestamp: ts, eventKind: terminal,
|
|
500
|
+
payload: { sequence: events.length + 1, processOutcome: r.outcome, exitCode: r.exitCode, eventsDropped: dropped, unparsedLines, ...(terminal === 'run_failed' && r.stderrUtf8.length > 0 ? { stderrTail: maskDiag(r.stderrUtf8.slice(-1200), 500) } : {}) },
|
|
501
|
+
...(session ? { nativeSessionId: session } : {}),
|
|
502
|
+
}));
|
|
503
|
+
return { events, finalMessage, unparsedLines };
|
|
504
|
+
}
|
|
505
|
+
//# sourceMappingURL=finiteCliDriver.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { EffectClassName, OperationEffectResolver } from '../../projects/pairedAuthority.js';
|
|
2
|
+
/**
|
|
3
|
+
* C04 (minimal, provider-neutral): the single immutable catalog of locally verified operations.
|
|
4
|
+
* Only trusted composition code constructs it; HTTP input can never add, edit or assert a definition.
|
|
5
|
+
* No driver, executable or process configuration lives here.
|
|
6
|
+
*/
|
|
7
|
+
export interface OperationDefinition {
|
|
8
|
+
readonly pluginId: string;
|
|
9
|
+
readonly operationId: string;
|
|
10
|
+
readonly effectClass: EffectClassName;
|
|
11
|
+
readonly verified: true;
|
|
12
|
+
}
|
|
13
|
+
export interface OperationCatalog {
|
|
14
|
+
readonly size: number;
|
|
15
|
+
/** Compatible with PairedAuthority's required resolveVerifiedOperationEffect dependency. */
|
|
16
|
+
readonly resolve: OperationEffectResolver;
|
|
17
|
+
}
|
|
18
|
+
export declare class OperationCatalogError extends Error {
|
|
19
|
+
constructor(reason: string);
|
|
20
|
+
}
|
|
21
|
+
/** The default catalog is empty, so a freshly started secure daemon admits nothing. */
|
|
22
|
+
export declare function createOperationCatalog(definitions?: readonly OperationDefinition[]): OperationCatalog;
|
|
23
|
+
//# sourceMappingURL=operationCatalog.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const EFFECT_CLASSES = ['read', 'write_project', 'external_network', 'destructive'];
|
|
2
|
+
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
3
|
+
export class OperationCatalogError extends Error {
|
|
4
|
+
constructor(reason) {
|
|
5
|
+
super(`OPERATION_CATALOG_REJECTED: ${reason}`);
|
|
6
|
+
this.name = 'OperationCatalogError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const keyOf = (pluginId, operationId) => JSON.stringify([pluginId, operationId]);
|
|
10
|
+
/** The default catalog is empty, so a freshly started secure daemon admits nothing. */
|
|
11
|
+
export function createOperationCatalog(definitions = []) {
|
|
12
|
+
if (!Array.isArray(definitions))
|
|
13
|
+
throw new OperationCatalogError('definitions must be an array');
|
|
14
|
+
const entries = new Map();
|
|
15
|
+
for (const d of definitions) {
|
|
16
|
+
if (typeof d !== 'object' || d === null)
|
|
17
|
+
throw new OperationCatalogError('definition must be an object');
|
|
18
|
+
// Copy the primitive fields once; later mutation of the caller's object cannot reach the catalog.
|
|
19
|
+
const { pluginId, operationId, effectClass, verified } = d;
|
|
20
|
+
if (typeof pluginId !== 'string' || !ID_PATTERN.test(pluginId))
|
|
21
|
+
throw new OperationCatalogError('malformed pluginId');
|
|
22
|
+
if (typeof operationId !== 'string' || !ID_PATTERN.test(operationId))
|
|
23
|
+
throw new OperationCatalogError('malformed operationId');
|
|
24
|
+
if (typeof effectClass !== 'string' || !EFFECT_CLASSES.includes(effectClass))
|
|
25
|
+
throw new OperationCatalogError('unknown effect class');
|
|
26
|
+
if (verified !== true)
|
|
27
|
+
throw new OperationCatalogError('definition is not verified');
|
|
28
|
+
const key = keyOf(pluginId, operationId);
|
|
29
|
+
if (entries.has(key))
|
|
30
|
+
throw new OperationCatalogError('duplicate operation identity');
|
|
31
|
+
entries.set(key, Object.freeze({ effectClass: effectClass, verified: true }));
|
|
32
|
+
}
|
|
33
|
+
const resolve = (op) => {
|
|
34
|
+
if (typeof op !== 'object' || op === null || typeof op.pluginId !== 'string' || typeof op.operationId !== 'string')
|
|
35
|
+
return undefined;
|
|
36
|
+
const hit = entries.get(keyOf(op.pluginId, op.operationId));
|
|
37
|
+
return hit ? { effectClass: hit.effectClass, verified: true } : undefined;
|
|
38
|
+
};
|
|
39
|
+
return Object.freeze({ size: entries.size, resolve });
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=operationCatalog.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type OperationCatalog } from './operationCatalog.js';
|
|
2
|
+
import type { VerifiedCapabilityRegistry } from './verifiedCapabilityRegistry.js';
|
|
3
|
+
/**
|
|
4
|
+
* C04 bridge (SW-051): builds the existing immutable OperationCatalog (the C03 operation-effect resolver) from operations that
|
|
5
|
+
* trusted local composition explicitly selects out of the pinned registry. For each selection the registry re-reads and re-hashes
|
|
6
|
+
* the pinned executable; the effect class comes ONLY from the pinned manifest, never from the caller. Anything unknown, changed or
|
|
7
|
+
* missing refuses the whole catalog. The result means "this exact pinned operation was selected by trusted composition"; it is not a
|
|
8
|
+
* behavioral capability probe, an enablement for any principal, or a grant. Nothing here starts a process.
|
|
9
|
+
*/
|
|
10
|
+
export declare function createOperationCatalogFromRegistry(registry: VerifiedCapabilityRegistry, selections: ReadonlyArray<Readonly<{
|
|
11
|
+
pluginId: string;
|
|
12
|
+
operationId: string;
|
|
13
|
+
}>>): Promise<OperationCatalog>;
|
|
14
|
+
//# sourceMappingURL=registryOperationCatalog.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createOperationCatalog, OperationCatalogError } from './operationCatalog.js';
|
|
2
|
+
/**
|
|
3
|
+
* C04 bridge (SW-051): builds the existing immutable OperationCatalog (the C03 operation-effect resolver) from operations that
|
|
4
|
+
* trusted local composition explicitly selects out of the pinned registry. For each selection the registry re-reads and re-hashes
|
|
5
|
+
* the pinned executable; the effect class comes ONLY from the pinned manifest, never from the caller. Anything unknown, changed or
|
|
6
|
+
* missing refuses the whole catalog. The result means "this exact pinned operation was selected by trusted composition"; it is not a
|
|
7
|
+
* behavioral capability probe, an enablement for any principal, or a grant. Nothing here starts a process.
|
|
8
|
+
*/
|
|
9
|
+
export async function createOperationCatalogFromRegistry(registry, selections) {
|
|
10
|
+
if (!Array.isArray(selections) || selections.length === 0)
|
|
11
|
+
throw new OperationCatalogError('selections must be a non-empty array');
|
|
12
|
+
const definitions = [];
|
|
13
|
+
for (const s of selections) {
|
|
14
|
+
if (typeof s !== 'object' || s === null || typeof s.pluginId !== 'string' || typeof s.operationId !== 'string') {
|
|
15
|
+
throw new OperationCatalogError('malformed selection');
|
|
16
|
+
}
|
|
17
|
+
const inspected = await registry.inspectOperation(s.pluginId, s.operationId);
|
|
18
|
+
if (!inspected.ok)
|
|
19
|
+
throw new OperationCatalogError(`selection not pinned: ${inspected.reason}`);
|
|
20
|
+
definitions.push({
|
|
21
|
+
pluginId: inspected.record.pluginId,
|
|
22
|
+
operationId: inspected.operation.operationId,
|
|
23
|
+
effectClass: inspected.operation.effectClass,
|
|
24
|
+
verified: true,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return createOperationCatalog(definitions);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=registryOperationCatalog.js.map
|