@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,158 @@
|
|
|
1
|
+
import { randomBytes, createHash } from 'node:crypto';
|
|
2
|
+
import { chmodSync, lstatSync, mkdirSync, readdirSync, realpathSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { PROJECT_READ_LIMITS, PROJECT_READ_TOOLS, PROJECT_PROPOSE_TOOLS, ProjectReadCapabilitySchema } from '../../../../packages/contracts/dist/index.js';
|
|
5
|
+
import { CodingAuthority } from '../projects/codingAuthority.js';
|
|
6
|
+
import { materializeProjectView, purgeProjectViews, removeProjectView, verifyProjectView } from './projectViewService.js';
|
|
7
|
+
const ACTIVE_STATES = new Set(['STARTING', 'RUNNING', 'WAITING_AGENT_APPROVAL', 'QUEUED']);
|
|
8
|
+
/** The production sweep period (the composition root's timer uses this constant). Worst-case latency from a ledger revocation to descriptor removal is this period plus one sweep. */
|
|
9
|
+
export const PROJECT_READ_SWEEP_INTERVAL_MS = 1000;
|
|
10
|
+
export function createProjectReadIssuer(o) {
|
|
11
|
+
const now = o.now ?? Date.now;
|
|
12
|
+
mkdirSync(o.grantsDir, { recursive: true });
|
|
13
|
+
const dir = realpathSync.native(o.grantsDir);
|
|
14
|
+
const active = new Map(); // capabilityId -> state
|
|
15
|
+
// SW-075 DAEMON RESTART: the in-memory `active` map does not survive the daemon. Every descriptor left in the grants directory by a previous daemon incarnation belongs to a run that cannot
|
|
16
|
+
// be resumed (its process tree died with, or was reconciled by, the daemon), so it is removed at start instead of staying valid until its own expiry (<= 15 minutes).
|
|
17
|
+
let orphansPurged = 0;
|
|
18
|
+
try {
|
|
19
|
+
for (const f of readdirSync(dir))
|
|
20
|
+
if (/^cap.[A-Za-z0-9_-]+.json(.tmp)?$/.test(f)) {
|
|
21
|
+
try {
|
|
22
|
+
unlinkSync(join(dir, f));
|
|
23
|
+
orphansPurged += 1;
|
|
24
|
+
}
|
|
25
|
+
catch { /* in use or already gone */ }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch { /* an unreadable directory has nothing to purge */ }
|
|
29
|
+
const viewsRoot = o.viewsRoot;
|
|
30
|
+
const viewMeta = new Map(); // viewId -> manifest sha256
|
|
31
|
+
let viewsPurged = 0;
|
|
32
|
+
if (viewsRoot) {
|
|
33
|
+
mkdirSync(viewsRoot, { recursive: true });
|
|
34
|
+
viewsPurged = purgeProjectViews(viewsRoot);
|
|
35
|
+
}
|
|
36
|
+
const remove = (a) => { try {
|
|
37
|
+
unlinkSync(a.path);
|
|
38
|
+
}
|
|
39
|
+
catch { /* already gone */ } if (viewsRoot && a.viewId) {
|
|
40
|
+
removeProjectView(viewsRoot, a.viewId);
|
|
41
|
+
viewMeta.delete(a.viewId);
|
|
42
|
+
} };
|
|
43
|
+
function canonicalRootOf(projectId) {
|
|
44
|
+
const root = o.ledger.getProjectRoot(projectId);
|
|
45
|
+
if (!root)
|
|
46
|
+
return undefined;
|
|
47
|
+
try {
|
|
48
|
+
const st = lstatSync(root);
|
|
49
|
+
if (!st.isDirectory() || st.isSymbolicLink())
|
|
50
|
+
return undefined;
|
|
51
|
+
const real = realpathSync.native(root);
|
|
52
|
+
return (process.platform === 'win32' ? real.toLowerCase() === root.toLowerCase() : real === root) ? real : undefined;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
issue(inv, opts) {
|
|
60
|
+
const principalId = o.ledger.getRunOwnerPrincipalId(inv.runId);
|
|
61
|
+
if (!principalId)
|
|
62
|
+
return { ok: false, code: 'RUN_UNKNOWN' };
|
|
63
|
+
const run = o.ledger.getRunDetailForPrincipal(principalId, inv.runId);
|
|
64
|
+
if (!run)
|
|
65
|
+
return { ok: false, code: 'RUN_UNKNOWN' };
|
|
66
|
+
if (run.projectId !== inv.projectId || run.pluginId !== inv.pluginId || run.operationId !== inv.operationId)
|
|
67
|
+
return { ok: false, code: 'RUN_MISMATCH' };
|
|
68
|
+
const auth = o.authority.authorizeLaunch(principalId, run.projectId, run.pluginId, run.operationId);
|
|
69
|
+
if (!auth)
|
|
70
|
+
return { ok: false, code: 'NOT_AUTHORIZED' };
|
|
71
|
+
if (opts?.proposeTool) {
|
|
72
|
+
const coding = new CodingAuthority({ ledger: o.ledger, now });
|
|
73
|
+
if (!['INSPECT', 'PROPOSE'].every((operation) => coding.authorize({ principalId, projectId: run.projectId, runId: run.runId, operation }).ok))
|
|
74
|
+
return { ok: false, code: 'NOT_AUTHORIZED' };
|
|
75
|
+
}
|
|
76
|
+
const root = canonicalRootOf(run.projectId);
|
|
77
|
+
if (!root)
|
|
78
|
+
return { ok: false, code: 'PROJECT_ROOT_INVALID' };
|
|
79
|
+
const lifetime = Math.max(1000, Math.min(opts?.lifetimeMs ?? 10 * 60 * 1000, PROJECT_READ_LIMITS.maxLifetimeMs));
|
|
80
|
+
const issuedMs = now();
|
|
81
|
+
// SW-077: the reader serves a private COPY of the policy-allowed material; the capability root is the view, never the original project.
|
|
82
|
+
let view;
|
|
83
|
+
if (viewsRoot) {
|
|
84
|
+
const v = materializeProjectView({ sourceRoot: root, viewsRoot, projectId: run.projectId, runId: run.runId, grantId: auth.grantId, expiresAt: new Date(issuedMs + lifetime).toISOString(), now });
|
|
85
|
+
if (!v.ok)
|
|
86
|
+
return { ok: false, code: 'VIEW_UNAVAILABLE' };
|
|
87
|
+
view = v;
|
|
88
|
+
viewMeta.set(v.viewId, v.manifestSha256);
|
|
89
|
+
}
|
|
90
|
+
const capabilityId = `cap.${randomBytes(18).toString('base64url')}`;
|
|
91
|
+
const cap = ProjectReadCapabilitySchema.parse({
|
|
92
|
+
protocol: 'my-centcom.project-read/1', capabilityId, projectId: run.projectId, runId: run.runId, grantId: auth.grantId, canonicalRoot: view ? view.root : root,
|
|
93
|
+
issuedAt: new Date(issuedMs).toISOString(), expiresAt: new Date(issuedMs + lifetime).toISOString(), tools: opts?.proposeTool === true ? [...PROJECT_READ_TOOLS, ...PROJECT_PROPOSE_TOOLS] : [...PROJECT_READ_TOOLS], auditRequired: true,
|
|
94
|
+
limits: { maxFileBytes: PROJECT_READ_LIMITS.maxFileBytes, maxReadBytes: PROJECT_READ_LIMITS.maxReadBytes, maxListEntries: PROJECT_READ_LIMITS.maxListEntries, maxRequests: PROJECT_READ_LIMITS.maxRequests, maxTotalResponseBytes: PROJECT_READ_LIMITS.maxTotalResponseBytes },
|
|
95
|
+
});
|
|
96
|
+
const text = JSON.stringify(cap);
|
|
97
|
+
const path = join(dir, `${capabilityId}.json`);
|
|
98
|
+
try {
|
|
99
|
+
const tmp = `${path}.tmp`;
|
|
100
|
+
writeFileSync(tmp, text, { encoding: 'utf8', flag: 'wx' });
|
|
101
|
+
renameSync(tmp, path);
|
|
102
|
+
try {
|
|
103
|
+
chmodSync(path, 0o444);
|
|
104
|
+
}
|
|
105
|
+
catch { /* ACLs, not mode bits, protect the file on Windows */ }
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
if (view && viewsRoot)
|
|
109
|
+
removeProjectView(viewsRoot, view.viewId);
|
|
110
|
+
return { ok: false, code: 'WRITE_FAILED' };
|
|
111
|
+
}
|
|
112
|
+
active.set(capabilityId, { coding: opts?.proposeTool === true, ...(view ? { viewId: view.viewId } : {}), runId: run.runId, principalId, projectId: run.projectId, pluginId: run.pluginId, operationId: run.operationId, path, expiresAtMs: issuedMs + lifetime });
|
|
113
|
+
return { ok: true, capabilityId, descriptorPath: path, descriptorSha256: createHash('sha256').update(text).digest('hex'), expiresAt: cap.expiresAt, canonicalRoot: view ? view.root : root, ...(view ? { view } : {}) };
|
|
114
|
+
},
|
|
115
|
+
revoke(runId) {
|
|
116
|
+
let any = false;
|
|
117
|
+
for (const [id, a] of [...active])
|
|
118
|
+
if (a.runId === runId) {
|
|
119
|
+
remove(a);
|
|
120
|
+
active.delete(id);
|
|
121
|
+
any = true;
|
|
122
|
+
}
|
|
123
|
+
return any;
|
|
124
|
+
},
|
|
125
|
+
sweep() {
|
|
126
|
+
const revoked = [];
|
|
127
|
+
for (const [id, a] of [...active]) {
|
|
128
|
+
let keep = now() < a.expiresAtMs && o.authority.authorizeLaunch(a.principalId, a.projectId, a.pluginId, a.operationId) !== undefined && canonicalRootOf(a.projectId) !== undefined;
|
|
129
|
+
if (keep && a.coding) {
|
|
130
|
+
const coding = new CodingAuthority({ ledger: o.ledger, now });
|
|
131
|
+
keep = ['INSPECT', 'PROPOSE'].every((operation) => coding.authorize({ principalId: a.principalId, projectId: a.projectId, runId: a.runId, operation }).ok);
|
|
132
|
+
}
|
|
133
|
+
if (keep) {
|
|
134
|
+
const run = o.ledger.getRunDetailForPrincipal(a.principalId, a.runId);
|
|
135
|
+
keep = run !== undefined && ACTIVE_STATES.has(run.lifecycleState);
|
|
136
|
+
}
|
|
137
|
+
if (!keep) {
|
|
138
|
+
remove(a);
|
|
139
|
+
active.delete(id);
|
|
140
|
+
revoked.push(id);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return revoked;
|
|
144
|
+
},
|
|
145
|
+
activeCount: () => active.size,
|
|
146
|
+
orphansPurged,
|
|
147
|
+
viewsPurged,
|
|
148
|
+
verifyView(runId) {
|
|
149
|
+
for (const a of active.values())
|
|
150
|
+
if (a.runId === runId && a.viewId && viewsRoot) {
|
|
151
|
+
const m = viewMeta.get(a.viewId) ?? '';
|
|
152
|
+
return { ...verifyProjectView({ viewsRoot, viewId: a.viewId, expectedManifestSha256: m }), viewId: a.viewId, manifestSha256: m };
|
|
153
|
+
}
|
|
154
|
+
return undefined;
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=projectReadIssuer.js.map
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C07 BOUNDED PROJECT READ SERVICE (SW-074). Provider-neutral. Node built-ins only (the MCP adapter that serves it must stay a small, auditable closure).
|
|
3
|
+
*
|
|
4
|
+
* Authority model. The agent-visible surface is three READ-ONLY operations bound to one run-scoped capability. The capability descriptor is written by the daemon only after
|
|
5
|
+
* C03 authorization and is read-only for the agent identity; THIS module re-reads and re-verifies it on EVERY request (digest pinned at start, expiry, run/project binding,
|
|
6
|
+
* canonical root), so a revoked, replaced, deleted or expired capability stops working at the next call even though the server process is long-lived. Tool arguments are
|
|
7
|
+
* untrusted: there is no root, project or run argument at all; a relative path is validated lexically, then walked component by component with lstat (no link, no alias),
|
|
8
|
+
* then compared with the physical path, then opened and re-verified by handle identity before AND after the read. Nothing is written to the project. All filesystem work uses
|
|
9
|
+
* real filesystem APIs; no shell, no command is ever built from agent input.
|
|
10
|
+
*
|
|
11
|
+
* Known limit (reported in SW-074): Node cannot open relative to a directory handle, so a directory swapped for a junction between the walk and the open is detected by the
|
|
12
|
+
* post-read identity/realpath re-check, which DISCARDS the content (nothing is returned); it is not prevented at the OS level. Hard-linked files are refused wholesale.
|
|
13
|
+
*/
|
|
14
|
+
export declare const PR_PROTOCOL = "my-centcom.project-read/1";
|
|
15
|
+
export declare const PR_LIMITS: Readonly<{
|
|
16
|
+
maxPathChars: 260;
|
|
17
|
+
maxSegments: 32;
|
|
18
|
+
maxSegmentChars: 120;
|
|
19
|
+
maxFileBytes: 1048576;
|
|
20
|
+
maxReadBytes: 32768;
|
|
21
|
+
defaultReadBytes: 16384;
|
|
22
|
+
maxListEntries: 200;
|
|
23
|
+
defaultListEntries: 100;
|
|
24
|
+
maxRequests: 200;
|
|
25
|
+
maxTotalResponseBytes: 524288;
|
|
26
|
+
maxLifetimeMs: number;
|
|
27
|
+
listScanCap: 2000;
|
|
28
|
+
maxDescriptorBytes: 8192;
|
|
29
|
+
}>;
|
|
30
|
+
export declare const PR_TOOLS: readonly ["list_project_entries", "read_project_text", "get_project_file_metadata"];
|
|
31
|
+
export type PrTool = (typeof PR_TOOLS)[number];
|
|
32
|
+
/** SW-080: the proposal tool is separate from the read tools and only exists in a capability that lists it. */
|
|
33
|
+
export declare const PR_PROPOSE_TOOL: "propose_change";
|
|
34
|
+
export declare const PR_CAPABILITY_TOOLS: readonly string[];
|
|
35
|
+
export declare const PR_MAX_PROPOSALS_PER_CAPABILITY = 3;
|
|
36
|
+
export type PrDenial = {
|
|
37
|
+
readonly ok: false;
|
|
38
|
+
readonly code: string;
|
|
39
|
+
readonly message: string;
|
|
40
|
+
};
|
|
41
|
+
export type PrResult<T> = {
|
|
42
|
+
readonly ok: true;
|
|
43
|
+
readonly value: T;
|
|
44
|
+
} | PrDenial;
|
|
45
|
+
/** Lexical validation of an agent-supplied relative path. Returns its segments (empty = the project root itself). */
|
|
46
|
+
export declare function validateRelativePath(p: unknown, opts: {
|
|
47
|
+
allowRoot: boolean;
|
|
48
|
+
}): PrResult<readonly string[]>;
|
|
49
|
+
export interface PrCapability {
|
|
50
|
+
readonly protocol: string;
|
|
51
|
+
readonly capabilityId: string;
|
|
52
|
+
readonly projectId: string;
|
|
53
|
+
readonly runId: string;
|
|
54
|
+
readonly grantId: string;
|
|
55
|
+
readonly canonicalRoot: string;
|
|
56
|
+
readonly issuedAt: string;
|
|
57
|
+
readonly expiresAt: string;
|
|
58
|
+
readonly tools: readonly (PrTool | typeof PR_PROPOSE_TOOL)[];
|
|
59
|
+
readonly auditRequired: boolean;
|
|
60
|
+
readonly limits: {
|
|
61
|
+
readonly maxFileBytes: number;
|
|
62
|
+
readonly maxReadBytes: number;
|
|
63
|
+
readonly maxListEntries: number;
|
|
64
|
+
readonly maxRequests: number;
|
|
65
|
+
readonly maxTotalResponseBytes: number;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export declare function parseCapability(bytes: Uint8Array): PrCapability | undefined;
|
|
69
|
+
export interface PrAuditRecordInput {
|
|
70
|
+
event: 'SERVER_START' | 'TOOL_CALL' | 'SERVER_STOP';
|
|
71
|
+
tool?: string;
|
|
72
|
+
decision?: 'ALLOWED' | 'DENIED';
|
|
73
|
+
code?: string;
|
|
74
|
+
pathSha256?: string;
|
|
75
|
+
pathDisplay?: string;
|
|
76
|
+
fileSha256?: string;
|
|
77
|
+
returnedSha256?: string;
|
|
78
|
+
returnedBytes?: number;
|
|
79
|
+
offset?: number;
|
|
80
|
+
}
|
|
81
|
+
export interface PrServiceConfig {
|
|
82
|
+
capabilityPath: string;
|
|
83
|
+
/** JSONL audit file (appended, hash-chained). Omit only in tests that do not need evidence. */
|
|
84
|
+
auditPath?: string;
|
|
85
|
+
now?: () => number;
|
|
86
|
+
/** Expected binding supplied by the trusted launcher (never by the agent): when set, the descriptor must match. */
|
|
87
|
+
expect?: {
|
|
88
|
+
runId?: string;
|
|
89
|
+
projectId?: string;
|
|
90
|
+
};
|
|
91
|
+
/** SW-080: where propose_change records a validated proposal (an exclusive-create file the daemon later ingests and re-validates) and the validator that checks it against the capability root. Without it the tool does not exist. */
|
|
92
|
+
propose?: {
|
|
93
|
+
record: (fileName: string, text: string) => 'OK' | 'EXISTS' | 'FAILED';
|
|
94
|
+
validate: (input: unknown, root: string) => {
|
|
95
|
+
ok: true;
|
|
96
|
+
canonicalJson: string;
|
|
97
|
+
digest: string;
|
|
98
|
+
effect: unknown;
|
|
99
|
+
} | {
|
|
100
|
+
ok: false;
|
|
101
|
+
code: string;
|
|
102
|
+
message: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export interface PrService {
|
|
107
|
+
readonly capabilityId: string;
|
|
108
|
+
/** The tools this capability actually carries (the adapter lists exactly these). */
|
|
109
|
+
readonly tools: readonly string[];
|
|
110
|
+
call(tool: string, args: unknown): PrResult<Record<string, unknown>>;
|
|
111
|
+
stop(): void;
|
|
112
|
+
}
|
|
113
|
+
type Node = {
|
|
114
|
+
kind: 'file' | 'directory';
|
|
115
|
+
path: string;
|
|
116
|
+
ino: string;
|
|
117
|
+
};
|
|
118
|
+
/** Walks root + segments with lstat per component. No link, no alias, no nested repository, then compares with the physical path. */
|
|
119
|
+
export declare function walkProjectPath(root: string, segs: readonly string[], want: 'file' | 'directory'): PrResult<Node>;
|
|
120
|
+
export declare function readProjectFileWhole(node: Node, root: string, segs: readonly string[], maxBytes: number): PrResult<{
|
|
121
|
+
bytes: Buffer;
|
|
122
|
+
ino: string;
|
|
123
|
+
mtimeMs: number;
|
|
124
|
+
}>;
|
|
125
|
+
export declare function createProjectReadService(cfg: PrServiceConfig): PrResult<PrService>;
|
|
126
|
+
/**
|
|
127
|
+
* Independent verification of an audit log (daemon or test side). Chain integrity is recomputed from the text; allowed reads are matched to ground truth computed WITHOUT the
|
|
128
|
+
* model; "the token came from a tool result" is proven only when an ALLOWED read of the expected path returned a slice whose digest equals the digest of that range of the
|
|
129
|
+
* independently known file bytes and the token lies inside that range, and the token was never in the prompt. The answer text alone proves nothing.
|
|
130
|
+
*/
|
|
131
|
+
export declare function assessProjectReadAudit(i: {
|
|
132
|
+
auditText: string;
|
|
133
|
+
capabilityId: string;
|
|
134
|
+
groundTruth?: {
|
|
135
|
+
relativePath: string;
|
|
136
|
+
fileBytes: Uint8Array;
|
|
137
|
+
token: string;
|
|
138
|
+
};
|
|
139
|
+
promptText?: string;
|
|
140
|
+
answerText?: string;
|
|
141
|
+
}): {
|
|
142
|
+
chainIntact: boolean;
|
|
143
|
+
records: number;
|
|
144
|
+
allowedReads: number;
|
|
145
|
+
refusals: number;
|
|
146
|
+
refusalCodes: string[];
|
|
147
|
+
verifiedRead: boolean;
|
|
148
|
+
tokenInToolResult: boolean;
|
|
149
|
+
tokenInPrompt: boolean;
|
|
150
|
+
verdict: 'TOOL_PROVEN' | 'NOT_PROVEN_NO_TOOL_READ' | 'NOT_PROVEN_AUDIT_UNTRUSTED' | 'NOT_PROVEN_TOKEN_IN_PROMPT' | 'NOT_PROVEN_DIGEST_MISMATCH';
|
|
151
|
+
};
|
|
152
|
+
export {};
|
|
153
|
+
//# sourceMappingURL=projectReadService.d.ts.map
|