@dailephd/my-centcom 0.1.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,579 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { open } from 'node:fs/promises';
|
|
3
|
+
import { lstatSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { basename, isAbsolute, normalize, sep } from 'node:path';
|
|
5
|
+
import { PluginManifestV1Schema } from '../../../../../packages/contracts/dist/index.js';
|
|
6
|
+
/** Sanitized: a fixed code only, never a path, manifest text, digest or file content. */
|
|
7
|
+
export class CapabilityRegistryError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code) {
|
|
10
|
+
super(code);
|
|
11
|
+
this.code = code;
|
|
12
|
+
this.name = 'CapabilityRegistryError';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export const MAX_MANIFEST_BYTES = 262144;
|
|
16
|
+
export const MAX_EXECUTABLE_BYTES = 1024 * 1024 * 1024;
|
|
17
|
+
const MAX_PLUGINS = 256;
|
|
18
|
+
const MAX_OPERATIONS = 64;
|
|
19
|
+
const MAX_JSON_DEPTH = 12;
|
|
20
|
+
const MAX_JSON_NODES = 8000;
|
|
21
|
+
const MAX_PATH_CHARS = 1024;
|
|
22
|
+
const MAX_TIMEOUT_MS = 86_400_000;
|
|
23
|
+
const ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
24
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/;
|
|
25
|
+
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
26
|
+
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
27
|
+
const WIN = process.platform === 'win32';
|
|
28
|
+
const fail = (code) => {
|
|
29
|
+
throw new CapabilityRegistryError(code);
|
|
30
|
+
};
|
|
31
|
+
const sameFs = (a, b) => (WIN ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
32
|
+
const trimSep = (p) => (p.length > 3 ? p.replace(new RegExp(`\\${sep}+$`), '') : p);
|
|
33
|
+
const STATUS = Object.freeze({
|
|
34
|
+
state: 'registered',
|
|
35
|
+
identityPinned: true,
|
|
36
|
+
capabilitiesDeclared: false,
|
|
37
|
+
capabilitiesVerified: false,
|
|
38
|
+
capabilityProbe: 'NOT_PERFORMED',
|
|
39
|
+
selection: 'DISABLED',
|
|
40
|
+
authorization: 'UNAUTHORIZED',
|
|
41
|
+
execution: 'NOT_AVAILABLE_IN_C04',
|
|
42
|
+
spawnRace: 'TOCTOU_NOT_VERIFIED',
|
|
43
|
+
osContainment: 'NOT_VERIFIED',
|
|
44
|
+
});
|
|
45
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
46
|
+
// Strict JSON: rejects duplicate keys, prototype-pollution keys, controls, lone surrogates, excess depth and size.
|
|
47
|
+
function parseStrictJson(text) {
|
|
48
|
+
let i = 0;
|
|
49
|
+
let nodes = 0;
|
|
50
|
+
const bad = () => fail('MANIFEST_INVALID');
|
|
51
|
+
const ws = () => { while (i < text.length && (text[i] === ' ' || text[i] === '\t' || text[i] === '\n' || text[i] === '\r'))
|
|
52
|
+
i += 1; };
|
|
53
|
+
const str = () => {
|
|
54
|
+
if (text[i] !== '"')
|
|
55
|
+
return bad();
|
|
56
|
+
i += 1;
|
|
57
|
+
let out = '';
|
|
58
|
+
for (;;) {
|
|
59
|
+
if (i >= text.length)
|
|
60
|
+
return bad();
|
|
61
|
+
const c = text[i];
|
|
62
|
+
if (c === '"') {
|
|
63
|
+
i += 1;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
if (c < ' ')
|
|
67
|
+
return bad(); // raw control characters are not valid JSON
|
|
68
|
+
if (c === '\\') {
|
|
69
|
+
const e = text[i + 1];
|
|
70
|
+
i += 2;
|
|
71
|
+
if (e === '"' || e === '\\' || e === '/')
|
|
72
|
+
out += e;
|
|
73
|
+
else if (e === 'b')
|
|
74
|
+
out += '\b';
|
|
75
|
+
else if (e === 'f')
|
|
76
|
+
out += '\f';
|
|
77
|
+
else if (e === 'n')
|
|
78
|
+
out += '\n';
|
|
79
|
+
else if (e === 'r')
|
|
80
|
+
out += '\r';
|
|
81
|
+
else if (e === 't')
|
|
82
|
+
out += '\t';
|
|
83
|
+
else if (e === 'u') {
|
|
84
|
+
const hex = text.slice(i, i + 4);
|
|
85
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex))
|
|
86
|
+
return bad();
|
|
87
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
88
|
+
i += 4;
|
|
89
|
+
}
|
|
90
|
+
else
|
|
91
|
+
return bad();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
out += c;
|
|
95
|
+
i += 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (LONE_SURROGATE.test(out))
|
|
99
|
+
return bad();
|
|
100
|
+
return out;
|
|
101
|
+
};
|
|
102
|
+
const value = (depth) => {
|
|
103
|
+
nodes += 1;
|
|
104
|
+
if (depth > MAX_JSON_DEPTH || nodes > MAX_JSON_NODES)
|
|
105
|
+
return bad();
|
|
106
|
+
ws();
|
|
107
|
+
const c = text[i];
|
|
108
|
+
if (c === '{') {
|
|
109
|
+
i += 1;
|
|
110
|
+
const obj = {};
|
|
111
|
+
const seen = new Set();
|
|
112
|
+
ws();
|
|
113
|
+
if (text[i] === '}') {
|
|
114
|
+
i += 1;
|
|
115
|
+
return obj;
|
|
116
|
+
}
|
|
117
|
+
for (;;) {
|
|
118
|
+
ws();
|
|
119
|
+
const key = str();
|
|
120
|
+
if (FORBIDDEN_KEYS.has(key))
|
|
121
|
+
return fail('MANIFEST_UNKNOWN_FIELD');
|
|
122
|
+
if (seen.has(key))
|
|
123
|
+
return fail('MANIFEST_DUPLICATE_OPERATION');
|
|
124
|
+
seen.add(key);
|
|
125
|
+
ws();
|
|
126
|
+
if (text[i] !== ':')
|
|
127
|
+
return bad();
|
|
128
|
+
i += 1;
|
|
129
|
+
obj[key] = value(depth + 1);
|
|
130
|
+
ws();
|
|
131
|
+
if (text[i] === ',') {
|
|
132
|
+
i += 1;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (text[i] === '}') {
|
|
136
|
+
i += 1;
|
|
137
|
+
return obj;
|
|
138
|
+
}
|
|
139
|
+
return bad();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (c === '[') {
|
|
143
|
+
i += 1;
|
|
144
|
+
const arr = [];
|
|
145
|
+
ws();
|
|
146
|
+
if (text[i] === ']') {
|
|
147
|
+
i += 1;
|
|
148
|
+
return arr;
|
|
149
|
+
}
|
|
150
|
+
for (;;) {
|
|
151
|
+
arr.push(value(depth + 1));
|
|
152
|
+
ws();
|
|
153
|
+
if (text[i] === ',') {
|
|
154
|
+
i += 1;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if (text[i] === ']') {
|
|
158
|
+
i += 1;
|
|
159
|
+
return arr;
|
|
160
|
+
}
|
|
161
|
+
return bad();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (c === '"')
|
|
165
|
+
return str();
|
|
166
|
+
if (text.startsWith('true', i)) {
|
|
167
|
+
i += 4;
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
if (text.startsWith('false', i)) {
|
|
171
|
+
i += 5;
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (text.startsWith('null', i)) {
|
|
175
|
+
i += 4;
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const m = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/.exec(text.slice(i, i + 64));
|
|
179
|
+
if (!m)
|
|
180
|
+
return bad();
|
|
181
|
+
i += m[0].length;
|
|
182
|
+
const n = Number(m[0]);
|
|
183
|
+
if (!Number.isFinite(n))
|
|
184
|
+
return bad();
|
|
185
|
+
return n;
|
|
186
|
+
};
|
|
187
|
+
const result = value(0);
|
|
188
|
+
ws();
|
|
189
|
+
if (i !== text.length)
|
|
190
|
+
return bad();
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
193
|
+
function manifestText(input, max) {
|
|
194
|
+
let bytes;
|
|
195
|
+
if (typeof input === 'string') {
|
|
196
|
+
if (LONE_SURROGATE.test(input))
|
|
197
|
+
return fail('MANIFEST_INVALID');
|
|
198
|
+
bytes = Buffer.from(input, 'utf8');
|
|
199
|
+
}
|
|
200
|
+
else if (input instanceof Uint8Array) {
|
|
201
|
+
bytes = Buffer.from(input); // copy: later mutation of the caller's buffer cannot reach the catalog
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
return fail('REGISTER_INPUT_INVALID');
|
|
205
|
+
if (bytes.length > max)
|
|
206
|
+
return fail('MANIFEST_TOO_LARGE');
|
|
207
|
+
if (bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf)
|
|
208
|
+
return fail('MANIFEST_INVALID');
|
|
209
|
+
try {
|
|
210
|
+
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
return fail('MANIFEST_INVALID');
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const isObj = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
217
|
+
function assertKeys(o, allowed) {
|
|
218
|
+
for (const k of Object.keys(o))
|
|
219
|
+
if (!allowed.includes(k))
|
|
220
|
+
fail('MANIFEST_UNKNOWN_FIELD');
|
|
221
|
+
}
|
|
222
|
+
const TOP = ['schemaVersion', 'id', 'kind', 'name', 'version', 'description', 'state', 'operations', 'capabilities'];
|
|
223
|
+
const OP = ['id', 'name', 'description', 'effectClass', 'inputSchema', 'executablePolicy', 'timeoutMs', 'outputBounds', 'projectCwdRequired', 'inputTransport'];
|
|
224
|
+
const INPUT_TRANSPORT = ['kind', 'maxBytes'];
|
|
225
|
+
const POLICY = ['executable', 'args', 'allowShell', 'windowsHide', 'stdio'];
|
|
226
|
+
const BOUNDS = ['maxOutputBytes', 'maxLineCount'];
|
|
227
|
+
const CAPS = ['supportsSession', 'supportsApproval', 'supportsResume', 'supportsStreaming'];
|
|
228
|
+
/** Local strictness the shared (non-strict, key-stripping) schema does not give: unknown fields, trust promotion, unsafe policy. */
|
|
229
|
+
function strictPrecheck(raw) {
|
|
230
|
+
if (!isObj(raw))
|
|
231
|
+
return fail('MANIFEST_INVALID');
|
|
232
|
+
assertKeys(raw, TOP);
|
|
233
|
+
if (raw.state !== 'registered') {
|
|
234
|
+
if (raw.state === 'verified' || raw.state === 'enabled' || raw.state === 'authorized')
|
|
235
|
+
return fail('MANIFEST_TRUST_PROMOTION');
|
|
236
|
+
return fail('MANIFEST_INVALID');
|
|
237
|
+
}
|
|
238
|
+
if (isObj(raw.capabilities))
|
|
239
|
+
assertKeys(raw.capabilities, CAPS);
|
|
240
|
+
if (!isObj(raw.operations))
|
|
241
|
+
return fail('MANIFEST_INVALID');
|
|
242
|
+
const keys = Object.keys(raw.operations);
|
|
243
|
+
if (keys.length === 0 || keys.length > MAX_OPERATIONS)
|
|
244
|
+
return fail('MANIFEST_INVALID');
|
|
245
|
+
for (const k of keys) {
|
|
246
|
+
const op = raw.operations[k];
|
|
247
|
+
if (!isObj(op))
|
|
248
|
+
return fail('MANIFEST_INVALID');
|
|
249
|
+
assertKeys(op, OP);
|
|
250
|
+
if (op.id !== k)
|
|
251
|
+
return fail('MANIFEST_DUPLICATE_OPERATION'); // key and declared id must be the one identity
|
|
252
|
+
if (isObj(op.outputBounds))
|
|
253
|
+
assertKeys(op.outputBounds, BOUNDS);
|
|
254
|
+
if (op.inputTransport !== undefined) {
|
|
255
|
+
if (!isObj(op.inputTransport))
|
|
256
|
+
return fail('MANIFEST_INVALID');
|
|
257
|
+
assertKeys(op.inputTransport, INPUT_TRANSPORT);
|
|
258
|
+
}
|
|
259
|
+
if (isObj(op.executablePolicy)) {
|
|
260
|
+
assertKeys(op.executablePolicy, POLICY);
|
|
261
|
+
if (op.executablePolicy.allowShell !== false || op.executablePolicy.windowsHide !== true)
|
|
262
|
+
return fail('MANIFEST_UNSAFE_POLICY');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function canonicalJson(v) {
|
|
267
|
+
if (v === null || typeof v === 'boolean' || typeof v === 'string')
|
|
268
|
+
return JSON.stringify(v);
|
|
269
|
+
if (typeof v === 'number')
|
|
270
|
+
return JSON.stringify(v);
|
|
271
|
+
if (Array.isArray(v))
|
|
272
|
+
return '[' + v.map(canonicalJson).join(',') + ']';
|
|
273
|
+
const o = v;
|
|
274
|
+
return '{' + Object.keys(o).sort().map((k) => JSON.stringify(k) + ':' + canonicalJson(o[k])).join(',') + '}';
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Manifest fingerprint = SHA-256 (hex) of the UTF-8 bytes of
|
|
278
|
+
* "my-centcom/c04/manifest-fingerprint/v1\n" + canonicalJson(parsedManifest)
|
|
279
|
+
* where canonicalJson writes object keys in code-unit sorted order with no whitespace. The input is the strictly
|
|
280
|
+
* parsed manifest (duplicate keys, prototype keys and unknown fields already refused), so JSON key order and
|
|
281
|
+
* whitespace in the source text do not change the fingerprint, and every semantic field does.
|
|
282
|
+
*/
|
|
283
|
+
export function fingerprintManifest(parsed) {
|
|
284
|
+
return createHash('sha256').update('my-centcom/c04/manifest-fingerprint/v1\n' + canonicalJson(parsed), 'utf8').digest('hex');
|
|
285
|
+
}
|
|
286
|
+
function deepFreeze(v) {
|
|
287
|
+
if (typeof v === 'object' && v !== null && !Object.isFrozen(v)) {
|
|
288
|
+
Object.freeze(v);
|
|
289
|
+
for (const k of Object.keys(v))
|
|
290
|
+
deepFreeze(v[k]);
|
|
291
|
+
}
|
|
292
|
+
return v;
|
|
293
|
+
}
|
|
294
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
295
|
+
// Executable identity.
|
|
296
|
+
function cleanPath(p) {
|
|
297
|
+
if (typeof p !== 'string' || p.length === 0 || p.length > MAX_PATH_CHARS || CONTROL.test(p) || LONE_SURROGATE.test(p))
|
|
298
|
+
return fail('EXECUTABLE_PATH_INVALID');
|
|
299
|
+
if (!isAbsolute(p))
|
|
300
|
+
return fail('EXECUTABLE_PATH_INVALID');
|
|
301
|
+
if (WIN && !/^[A-Za-z]:[\\/]/.test(p))
|
|
302
|
+
return fail('EXECUTABLE_PATH_INVALID'); // no UNC, device or drive-relative forms
|
|
303
|
+
const parts = p.split(/[\\/]+/);
|
|
304
|
+
if (parts.includes('..') || parts.includes('.'))
|
|
305
|
+
return fail('EXECUTABLE_PATH_INVALID');
|
|
306
|
+
return p;
|
|
307
|
+
}
|
|
308
|
+
/** Existing regular file, not a link, junction or alias: realpath equals the normalized input. Returns the canonical path. */
|
|
309
|
+
function canonicalFile(p) {
|
|
310
|
+
const s = cleanPath(p);
|
|
311
|
+
try {
|
|
312
|
+
const st = lstatSync(s);
|
|
313
|
+
if (st.isSymbolicLink() || !st.isFile())
|
|
314
|
+
return fail('EXECUTABLE_PATH_INVALID');
|
|
315
|
+
const real = trimSep(realpathSync.native(s));
|
|
316
|
+
if (!sameFs(real, trimSep(normalize(s))))
|
|
317
|
+
return fail('EXECUTABLE_PATH_INVALID');
|
|
318
|
+
return real;
|
|
319
|
+
}
|
|
320
|
+
catch (e) {
|
|
321
|
+
if (e instanceof CapabilityRegistryError)
|
|
322
|
+
throw e;
|
|
323
|
+
return fail('EXECUTABLE_PATH_INVALID');
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/** Streams the bytes through SHA-256 on one file handle and checks the file did not change or get swapped while reading. */
|
|
327
|
+
async function hashExecutable(canonical, maxBytes) {
|
|
328
|
+
const fh = await open(canonical, 'r');
|
|
329
|
+
try {
|
|
330
|
+
const before = await fh.stat({ bigint: true });
|
|
331
|
+
if (!before.isFile())
|
|
332
|
+
return fail('EXECUTABLE_PATH_INVALID');
|
|
333
|
+
if (before.size > BigInt(maxBytes))
|
|
334
|
+
return fail('EXECUTABLE_TOO_LARGE');
|
|
335
|
+
const hash = createHash('sha256');
|
|
336
|
+
const buf = Buffer.allocUnsafe(1 << 20);
|
|
337
|
+
let total = 0n;
|
|
338
|
+
for (;;) {
|
|
339
|
+
const { bytesRead } = await fh.read(buf, 0, buf.length, null);
|
|
340
|
+
if (bytesRead === 0)
|
|
341
|
+
break;
|
|
342
|
+
total += BigInt(bytesRead);
|
|
343
|
+
if (total > BigInt(maxBytes))
|
|
344
|
+
return fail('EXECUTABLE_TOO_LARGE');
|
|
345
|
+
hash.update(buf.subarray(0, bytesRead));
|
|
346
|
+
}
|
|
347
|
+
const after = await fh.stat({ bigint: true });
|
|
348
|
+
if (total !== before.size || after.size !== before.size || after.ino !== before.ino || after.dev !== before.dev || after.mtimeNs !== before.mtimeNs)
|
|
349
|
+
return fail('EXECUTABLE_UNSTABLE');
|
|
350
|
+
const atPath = lstatSync(canonical, { bigint: true });
|
|
351
|
+
if (atPath.ino !== before.ino || atPath.dev !== before.dev)
|
|
352
|
+
return fail('EXECUTABLE_UNSTABLE'); // the path now names a different file
|
|
353
|
+
return { sha256: hash.digest('hex'), size: before.size, fileId: `${before.dev}:${before.ino}` };
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
await fh.close();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const MAX_CODE_INPUTS = 8;
|
|
360
|
+
/** Canonical encoding hashed into codeInputsSha256: sorted by path, one line per input. Never includes content. */
|
|
361
|
+
function codeInputsDigest(list) {
|
|
362
|
+
if (list.length === 0)
|
|
363
|
+
return null;
|
|
364
|
+
const body = list.map((c) => c.canonicalPath.toLowerCase() + '\t' + c.sha256 + '\t' + c.sizeBytes + '\t' + c.fileId + '\n').join('');
|
|
365
|
+
return createHash('sha256').update('my-centcom/c04/code-inputs/v1\n' + body, 'utf8').digest('hex');
|
|
366
|
+
}
|
|
367
|
+
/** A per-operation declared executable must name THIS file: its exact canonical path, or its bare file name. Never searched on PATH. */
|
|
368
|
+
function reconcileDeclaredExecutable(declared, canonical) {
|
|
369
|
+
if (CONTROL.test(declared) || LONE_SURROGATE.test(declared))
|
|
370
|
+
return fail('EXECUTABLE_POLICY_MISMATCH');
|
|
371
|
+
if (/[\\/]/.test(declared) || /^[A-Za-z]:/.test(declared)) {
|
|
372
|
+
let p;
|
|
373
|
+
try {
|
|
374
|
+
p = cleanPath(declared);
|
|
375
|
+
}
|
|
376
|
+
catch {
|
|
377
|
+
return fail('EXECUTABLE_POLICY_MISMATCH');
|
|
378
|
+
}
|
|
379
|
+
if (!sameFs(trimSep(normalize(p)), canonical))
|
|
380
|
+
return fail('EXECUTABLE_POLICY_MISMATCH');
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (!sameFs(declared, basename(canonical)))
|
|
384
|
+
return fail('EXECUTABLE_POLICY_MISMATCH');
|
|
385
|
+
}
|
|
386
|
+
function parseManifest(input, maxBytes) {
|
|
387
|
+
const text = manifestText(input, maxBytes);
|
|
388
|
+
const raw = parseStrictJson(text);
|
|
389
|
+
strictPrecheck(raw);
|
|
390
|
+
const parsed = PluginManifestV1Schema.safeParse(raw);
|
|
391
|
+
if (!parsed.success)
|
|
392
|
+
return fail('MANIFEST_INVALID');
|
|
393
|
+
const m = parsed.data;
|
|
394
|
+
if (!ID_PATTERN.test(m.id))
|
|
395
|
+
return fail('MANIFEST_INVALID');
|
|
396
|
+
for (const [key, op] of Object.entries(m.operations)) {
|
|
397
|
+
if (!ID_PATTERN.test(key) || op.timeoutMs > MAX_TIMEOUT_MS)
|
|
398
|
+
return fail('MANIFEST_INVALID');
|
|
399
|
+
for (const a of op.executablePolicy.args)
|
|
400
|
+
if (CONTROL.test(a) || LONE_SURROGATE.test(a))
|
|
401
|
+
return fail('MANIFEST_UNSAFE_POLICY');
|
|
402
|
+
}
|
|
403
|
+
if (m.kind === 'command' && m.capabilities !== undefined)
|
|
404
|
+
return fail('MANIFEST_INVALID'); // driver capabilities are an agent concept
|
|
405
|
+
return { manifest: m, fingerprint: fingerprintManifest(raw) };
|
|
406
|
+
}
|
|
407
|
+
function summarize(m) {
|
|
408
|
+
return Object.entries(m.operations).map(([key, op]) => ({
|
|
409
|
+
operationId: key,
|
|
410
|
+
name: op.name,
|
|
411
|
+
effectClass: op.effectClass,
|
|
412
|
+
timeoutMs: op.timeoutMs,
|
|
413
|
+
maxOutputBytes: op.outputBounds.maxOutputBytes,
|
|
414
|
+
projectCwdRequired: op.projectCwdRequired,
|
|
415
|
+
declaredExecutable: op.executablePolicy.executable,
|
|
416
|
+
argumentCount: op.executablePolicy.args.length,
|
|
417
|
+
argvTemplate: [...op.executablePolicy.args],
|
|
418
|
+
inputTransport: op.inputTransport ? { kind: op.inputTransport.kind, maxBytes: op.inputTransport.maxBytes } : null,
|
|
419
|
+
declared: true,
|
|
420
|
+
verified: false,
|
|
421
|
+
}));
|
|
422
|
+
}
|
|
423
|
+
export function createVerifiedCapabilityRegistry(options = {}) {
|
|
424
|
+
if (options === null || typeof options !== 'object')
|
|
425
|
+
fail('OPTIONS_INVALID');
|
|
426
|
+
const smaller = (v, cap) => {
|
|
427
|
+
if (v === undefined)
|
|
428
|
+
return cap;
|
|
429
|
+
if (typeof v !== 'number' || !Number.isSafeInteger(v) || v < 1 || v > cap)
|
|
430
|
+
return fail('OPTIONS_INVALID');
|
|
431
|
+
return v;
|
|
432
|
+
};
|
|
433
|
+
const maxManifest = smaller(options.maxManifestBytes, MAX_MANIFEST_BYTES);
|
|
434
|
+
const maxExe = smaller(options.maxExecutableBytes, MAX_EXECUTABLE_BYTES);
|
|
435
|
+
const now = options.now ?? Date.now;
|
|
436
|
+
const records = new Map();
|
|
437
|
+
let chain = Promise.resolve();
|
|
438
|
+
const serialized = (fn) => {
|
|
439
|
+
const next = chain.then(fn, fn);
|
|
440
|
+
chain = next.catch(() => undefined);
|
|
441
|
+
return next;
|
|
442
|
+
};
|
|
443
|
+
async function registerNow(input) {
|
|
444
|
+
if (!isObj(input))
|
|
445
|
+
return fail('REGISTER_INPUT_INVALID');
|
|
446
|
+
// Exactly two inputs. A caller-supplied verified/enabled/authorized/state flag is refused, never ignored silently.
|
|
447
|
+
for (const k of Object.keys(input))
|
|
448
|
+
if (k !== 'manifestJson' && k !== 'executablePath' && k !== 'codeInputPaths')
|
|
449
|
+
return fail('REGISTER_INPUT_INVALID');
|
|
450
|
+
const rawCode = input.codeInputPaths;
|
|
451
|
+
if (rawCode !== undefined && (!Array.isArray(rawCode) || rawCode.length > MAX_CODE_INPUTS))
|
|
452
|
+
return fail('REGISTER_INPUT_INVALID');
|
|
453
|
+
const { manifest, fingerprint } = parseManifest(input.manifestJson, maxManifest);
|
|
454
|
+
const canonical = canonicalFile(input.executablePath);
|
|
455
|
+
for (const op of Object.values(manifest.operations))
|
|
456
|
+
reconcileDeclaredExecutable(op.executablePolicy.executable, canonical);
|
|
457
|
+
const existing = records.get(manifest.id);
|
|
458
|
+
if (!existing && records.size >= MAX_PLUGINS)
|
|
459
|
+
return fail('REGISTRY_FULL');
|
|
460
|
+
const facts = await hashExecutable(canonical, maxExe);
|
|
461
|
+
const codeInputs = [];
|
|
462
|
+
for (const raw of (rawCode ?? [])) {
|
|
463
|
+
const cp = canonicalFile(raw); // existing regular file, not a link or junction alias, drive-letter path
|
|
464
|
+
if (codeInputs.some((c) => sameFs(c.canonicalPath, cp)))
|
|
465
|
+
return fail('REGISTER_INPUT_INVALID');
|
|
466
|
+
const f = await hashExecutable(cp, maxExe);
|
|
467
|
+
codeInputs.push({ canonicalPath: cp, sha256: f.sha256, sizeBytes: Number(f.size), fileId: f.fileId });
|
|
468
|
+
}
|
|
469
|
+
codeInputs.sort((a, b) => (a.canonicalPath.toLowerCase() < b.canonicalPath.toLowerCase() ? -1 : 1));
|
|
470
|
+
const codeDigest = codeInputsDigest(codeInputs);
|
|
471
|
+
if (existing) {
|
|
472
|
+
if (existing.manifestFingerprint !== fingerprint)
|
|
473
|
+
return fail('PLUGIN_CONFLICT');
|
|
474
|
+
if (!sameFs(existing.executable.canonicalPath, canonical) || existing.executable.sha256 !== facts.sha256)
|
|
475
|
+
return fail('EXECUTABLE_CONFLICT');
|
|
476
|
+
if (existing.codeInputsSha256 !== codeDigest)
|
|
477
|
+
return fail('EXECUTABLE_CONFLICT');
|
|
478
|
+
return existing; // idempotent
|
|
479
|
+
}
|
|
480
|
+
const declaredCaps = manifest.capabilities ? { ...manifest.capabilities } : null;
|
|
481
|
+
const record = deepFreeze({
|
|
482
|
+
pluginId: manifest.id,
|
|
483
|
+
kind: manifest.kind,
|
|
484
|
+
name: manifest.name,
|
|
485
|
+
version: manifest.version,
|
|
486
|
+
description: manifest.description,
|
|
487
|
+
manifestFingerprint: fingerprint,
|
|
488
|
+
executable: {
|
|
489
|
+
canonicalPath: canonical,
|
|
490
|
+
sha256: facts.sha256,
|
|
491
|
+
sizeBytes: Number(facts.size),
|
|
492
|
+
fileId: facts.fileId,
|
|
493
|
+
pinnedAt: new Date(now()).toISOString(),
|
|
494
|
+
},
|
|
495
|
+
codeInputs,
|
|
496
|
+
codeInputsSha256: codeDigest,
|
|
497
|
+
operations: summarize(manifest),
|
|
498
|
+
declaredDriverCapabilities: declaredCaps,
|
|
499
|
+
status: { ...STATUS, capabilitiesDeclared: true }, // operations are always declared (at least one is required)
|
|
500
|
+
});
|
|
501
|
+
records.set(manifest.id, record);
|
|
502
|
+
return record;
|
|
503
|
+
}
|
|
504
|
+
async function revalidateNow(pluginId, opts) {
|
|
505
|
+
if (typeof pluginId !== 'string')
|
|
506
|
+
return { ok: false, reason: 'INPUT_INVALID' };
|
|
507
|
+
const record = records.get(pluginId);
|
|
508
|
+
if (!record)
|
|
509
|
+
return { ok: false, reason: 'UNKNOWN_PLUGIN' };
|
|
510
|
+
if (opts?.currentManifestJson !== undefined) {
|
|
511
|
+
try {
|
|
512
|
+
if (parseManifest(opts.currentManifestJson, maxManifest).fingerprint !== record.manifestFingerprint)
|
|
513
|
+
return { ok: false, reason: 'MANIFEST_CHANGED' };
|
|
514
|
+
}
|
|
515
|
+
catch {
|
|
516
|
+
return { ok: false, reason: 'MANIFEST_CHANGED' };
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
let canonical;
|
|
520
|
+
try {
|
|
521
|
+
canonical = canonicalFile(record.executable.canonicalPath);
|
|
522
|
+
}
|
|
523
|
+
catch {
|
|
524
|
+
return { ok: false, reason: 'EXECUTABLE_MISSING' };
|
|
525
|
+
}
|
|
526
|
+
if (!sameFs(canonical, record.executable.canonicalPath))
|
|
527
|
+
return { ok: false, reason: 'EXECUTABLE_CHANGED' };
|
|
528
|
+
let facts;
|
|
529
|
+
try {
|
|
530
|
+
facts = await hashExecutable(canonical, maxExe);
|
|
531
|
+
}
|
|
532
|
+
catch (e) {
|
|
533
|
+
return { ok: false, reason: e instanceof CapabilityRegistryError && e.code === 'EXECUTABLE_PATH_INVALID' ? 'EXECUTABLE_MISSING' : 'EXECUTABLE_CHANGED' };
|
|
534
|
+
}
|
|
535
|
+
// Hash first, identity second: replaced-with-identical-bytes is reported too (fail closed), because the file is not the one that was pinned.
|
|
536
|
+
if (facts.sha256 !== record.executable.sha256 || Number(facts.size) !== record.executable.sizeBytes || facts.fileId !== record.executable.fileId) {
|
|
537
|
+
return { ok: false, reason: 'EXECUTABLE_CHANGED' };
|
|
538
|
+
}
|
|
539
|
+
for (const ci of record.codeInputs) {
|
|
540
|
+
let cp;
|
|
541
|
+
try {
|
|
542
|
+
cp = canonicalFile(ci.canonicalPath);
|
|
543
|
+
}
|
|
544
|
+
catch {
|
|
545
|
+
return { ok: false, reason: 'CODE_INPUT_MISSING' };
|
|
546
|
+
}
|
|
547
|
+
if (!sameFs(cp, ci.canonicalPath))
|
|
548
|
+
return { ok: false, reason: 'CODE_INPUT_CHANGED' };
|
|
549
|
+
let f;
|
|
550
|
+
try {
|
|
551
|
+
f = await hashExecutable(cp, maxExe);
|
|
552
|
+
}
|
|
553
|
+
catch (e) {
|
|
554
|
+
return { ok: false, reason: e instanceof CapabilityRegistryError && e.code === 'EXECUTABLE_PATH_INVALID' ? 'CODE_INPUT_MISSING' : 'CODE_INPUT_CHANGED' };
|
|
555
|
+
}
|
|
556
|
+
if (f.sha256 !== ci.sha256 || Number(f.size) !== ci.sizeBytes || f.fileId !== ci.fileId)
|
|
557
|
+
return { ok: false, reason: 'CODE_INPUT_CHANGED' };
|
|
558
|
+
}
|
|
559
|
+
return { ok: true, record };
|
|
560
|
+
}
|
|
561
|
+
return Object.freeze({
|
|
562
|
+
register: (input) => serialized(() => registerNow(input)),
|
|
563
|
+
list: () => Object.freeze([...records.values()]),
|
|
564
|
+
get: (pluginId) => (typeof pluginId === 'string' ? records.get(pluginId) : undefined),
|
|
565
|
+
revalidate: (pluginId, opts) => serialized(() => revalidateNow(pluginId, opts)),
|
|
566
|
+
inspectOperation: (pluginId, operationId, opts) => serialized(async () => {
|
|
567
|
+
if (typeof operationId !== 'string')
|
|
568
|
+
return { ok: false, reason: 'INPUT_INVALID' };
|
|
569
|
+
const r = await revalidateNow(pluginId, opts);
|
|
570
|
+
if (!r.ok)
|
|
571
|
+
return r;
|
|
572
|
+
const operation = r.record.operations.find((o) => o.operationId === operationId);
|
|
573
|
+
if (!operation)
|
|
574
|
+
return { ok: false, reason: 'UNKNOWN_OPERATION' };
|
|
575
|
+
return { ok: true, record: r.record, operation };
|
|
576
|
+
}),
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
//# sourceMappingURL=verifiedCapabilityRegistry.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { CodingEffectClassName, CodingOperationName, SqliteLedger } from '../storage/sqliteLedger.js';
|
|
2
|
+
/**
|
|
3
|
+
* C03 CODING-WORKFLOW AUTHORITY (SW-080). Six DISTINCT operation authorities, none of which implies another:
|
|
4
|
+
*
|
|
5
|
+
* INSPECT read inspect the repository through the read-only MCP surface
|
|
6
|
+
* PROPOSE propose submit an immutable change proposal (never modifies the project)
|
|
7
|
+
* APPLY write_project apply ONE approved proposal (single use, bound to the proposal digest)
|
|
8
|
+
* TEST execute run ONE reviewed test profile against the applied bytes (bound to a proposal and a profile id)
|
|
9
|
+
* GIT_READ read read Git status and diffs
|
|
10
|
+
* COMMIT git_commit create a Git commit of ONE verified proposal (single use, bound to the proposal digest)
|
|
11
|
+
*
|
|
12
|
+
* Every grant is scoped to a principal, a project, ONE run, ONE operation and the matching effect class, has a bounded lifetime, can be revoked and leaves durable, hash-chained
|
|
13
|
+
* evidence (the ledger's coding_events) for every issue, decision, consumption and revocation. A decision whose evidence cannot be written is a denial (fail closed).
|
|
14
|
+
* Application-level authorization only: this is NOT operating-system containment (that is the restricted execution identity's job). There is no default grant, no ranking of
|
|
15
|
+
* operations and no way for a request, a prompt or a model to choose its own scope.
|
|
16
|
+
*/
|
|
17
|
+
export declare const CODING_OPERATIONS: readonly CodingOperationName[];
|
|
18
|
+
export declare const CODING_EFFECT: Readonly<Record<CodingOperationName, CodingEffectClassName>>;
|
|
19
|
+
export declare const CODING_MAX_LIFETIME_MS: Readonly<Record<CodingOperationName, number>>;
|
|
20
|
+
export type CodingScope = Readonly<Record<string, string>>;
|
|
21
|
+
export type CodingDenied = 'OPERATION_INVALID' | 'SCOPE_INVALID' | 'LIFETIME_INVALID' | 'PRINCIPAL_DISABLED' | 'RUN_UNKNOWN' | 'RUN_NOT_OWNED' | 'PROJECT_UNKNOWN' | 'PROJECT_ROOT_INVALID' | 'NO_GRANT' | 'GRANT_EXPIRED' | 'GRANT_REVOKED' | 'GRANT_CONSUMED' | 'SCOPE_MISMATCH' | 'AUDIT_UNAVAILABLE';
|
|
22
|
+
export type GrantResult = {
|
|
23
|
+
readonly ok: true;
|
|
24
|
+
readonly grantId: string;
|
|
25
|
+
readonly expiresAt: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly ok: false;
|
|
28
|
+
readonly code: CodingDenied;
|
|
29
|
+
};
|
|
30
|
+
export type AuthorizeResult = {
|
|
31
|
+
readonly ok: true;
|
|
32
|
+
readonly grantId: string;
|
|
33
|
+
readonly consumed: boolean;
|
|
34
|
+
} | {
|
|
35
|
+
readonly ok: false;
|
|
36
|
+
readonly code: CodingDenied;
|
|
37
|
+
};
|
|
38
|
+
export interface CodingAuthorityOptions {
|
|
39
|
+
ledger: SqliteLedger;
|
|
40
|
+
now?: () => number;
|
|
41
|
+
}
|
|
42
|
+
export declare class CodingAuthority {
|
|
43
|
+
private readonly reviewSecret;
|
|
44
|
+
private readonly reviewReceipts;
|
|
45
|
+
private readonly ledger;
|
|
46
|
+
private readonly now;
|
|
47
|
+
constructor(o: CodingAuthorityOptions);
|
|
48
|
+
private iso;
|
|
49
|
+
private receipt;
|
|
50
|
+
commitChallenge(binding: string): string;
|
|
51
|
+
/** A short-lived, daemon-incarnation-bound review receipt, not an execution grant. */
|
|
52
|
+
reviewedPatch(i: {
|
|
53
|
+
principalId: string;
|
|
54
|
+
origin: string;
|
|
55
|
+
projectId: string;
|
|
56
|
+
proposalId: string;
|
|
57
|
+
digest: string;
|
|
58
|
+
baseHead: string;
|
|
59
|
+
}): {
|
|
60
|
+
projectId: string;
|
|
61
|
+
target: string;
|
|
62
|
+
baseHead: string;
|
|
63
|
+
digest: string;
|
|
64
|
+
reviewKey: string;
|
|
65
|
+
challenge: string;
|
|
66
|
+
expiresAt: number;
|
|
67
|
+
authorities: readonly ["APPLY", "GIT_READ"];
|
|
68
|
+
};
|
|
69
|
+
approveReviewedPatch(i: Parameters<CodingAuthority['reviewedPatch']>[0] & {
|
|
70
|
+
challenge: string;
|
|
71
|
+
}): GrantResult & {
|
|
72
|
+
gitGrantId?: string;
|
|
73
|
+
reviewKey?: string;
|
|
74
|
+
};
|
|
75
|
+
/** Writes decision evidence; false = the evidence store is unavailable and the caller must deny. */
|
|
76
|
+
private record;
|
|
77
|
+
/** Trusted local administration (never reachable from the model or HTTP): issues one scoped grant. */
|
|
78
|
+
grant(i: {
|
|
79
|
+
principalId: string;
|
|
80
|
+
projectId: string;
|
|
81
|
+
runId: string;
|
|
82
|
+
operation: CodingOperationName;
|
|
83
|
+
scope?: CodingScope;
|
|
84
|
+
lifetimeMs: number;
|
|
85
|
+
}): GrantResult;
|
|
86
|
+
/**
|
|
87
|
+
* Decides ONE request of ONE operation. `scope` is what the trusted caller is about to act on (proposal id and digest, profile id); it must equal what the grant names.
|
|
88
|
+
* With `consume`, a single-use grant is spent atomically as part of the decision (a replay or a race yields GRANT_CONSUMED for every loser).
|
|
89
|
+
*/
|
|
90
|
+
authorize(r: {
|
|
91
|
+
principalId: string;
|
|
92
|
+
projectId: string;
|
|
93
|
+
runId: string;
|
|
94
|
+
operation: CodingOperationName;
|
|
95
|
+
scope?: CodingScope;
|
|
96
|
+
consume?: boolean;
|
|
97
|
+
}): AuthorizeResult;
|
|
98
|
+
revoke(grantId: string): boolean;
|
|
99
|
+
/** Revokes every unrevoked coding grant of a run (run cancelled, daemon shutdown, project removed). */
|
|
100
|
+
revokeRun(runId: string): number;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=codingAuthority.d.ts.map
|