@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,244 @@
|
|
|
1
|
+
import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
3
|
+
/**
|
|
4
|
+
* C03 CODING-WORKFLOW AUTHORITY (SW-080). Six DISTINCT operation authorities, none of which implies another:
|
|
5
|
+
*
|
|
6
|
+
* INSPECT read inspect the repository through the read-only MCP surface
|
|
7
|
+
* PROPOSE propose submit an immutable change proposal (never modifies the project)
|
|
8
|
+
* APPLY write_project apply ONE approved proposal (single use, bound to the proposal digest)
|
|
9
|
+
* TEST execute run ONE reviewed test profile against the applied bytes (bound to a proposal and a profile id)
|
|
10
|
+
* GIT_READ read read Git status and diffs
|
|
11
|
+
* COMMIT git_commit create a Git commit of ONE verified proposal (single use, bound to the proposal digest)
|
|
12
|
+
*
|
|
13
|
+
* 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
|
|
14
|
+
* 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).
|
|
15
|
+
* 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
|
|
16
|
+
* operations and no way for a request, a prompt or a model to choose its own scope.
|
|
17
|
+
*/
|
|
18
|
+
export const CODING_OPERATIONS = Object.freeze(['INSPECT', 'PROPOSE', 'APPLY', 'TEST', 'GIT_READ', 'COMMIT']);
|
|
19
|
+
export const CODING_EFFECT = Object.freeze({
|
|
20
|
+
INSPECT: 'read', PROPOSE: 'propose', APPLY: 'write_project', TEST: 'execute', GIT_READ: 'read', COMMIT: 'git_commit',
|
|
21
|
+
});
|
|
22
|
+
const MIN = 60_000;
|
|
23
|
+
export const CODING_MAX_LIFETIME_MS = Object.freeze({ INSPECT: 15 * MIN, PROPOSE: 15 * MIN, APPLY: 10 * MIN, TEST: 15 * MIN, GIT_READ: 15 * MIN, COMMIT: 10 * MIN });
|
|
24
|
+
const SINGLE_USE_REQUIRED = new Set(['APPLY', 'COMMIT']);
|
|
25
|
+
/** Scope keys each operation must (and may only) carry. */
|
|
26
|
+
const SCOPE_KEYS = Object.freeze({
|
|
27
|
+
INSPECT: [], PROPOSE: [], GIT_READ: [], APPLY: ['proposalId', 'digest'], TEST: ['proposalId', 'profileId'], COMMIT: ['proposalId', 'digest'],
|
|
28
|
+
});
|
|
29
|
+
const PROPOSAL_ID = /^prop\.[A-Za-z0-9_-]{16,64}$/;
|
|
30
|
+
const DIGEST = /^[a-f0-9]{64}$/;
|
|
31
|
+
const PROFILE_ID = /^[a-z0-9][a-z0-9.-]{2,62}$/;
|
|
32
|
+
const SCOPE_VALUE = Object.freeze({ proposalId: PROPOSAL_ID, digest: DIGEST, profileId: PROFILE_ID });
|
|
33
|
+
const b64 = (n) => randomBytes(n).toString('base64url');
|
|
34
|
+
const sameCanon = (a, b) => (process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
35
|
+
function scopeValid(op, scope) {
|
|
36
|
+
if ((op === 'APPLY' || op === 'GIT_READ' || op === 'COMMIT') && Object.keys(scope).length === 3 && PROPOSAL_ID.test(scope.proposalId ?? '') && DIGEST.test(scope.digest ?? '') && DIGEST.test(scope.reviewKey ?? ''))
|
|
37
|
+
return true;
|
|
38
|
+
const want = SCOPE_KEYS[op];
|
|
39
|
+
const have = Object.keys(scope);
|
|
40
|
+
if (have.length !== want.length || !want.every((k) => have.includes(k)))
|
|
41
|
+
return false;
|
|
42
|
+
return want.every((k) => typeof scope[k] === 'string' && SCOPE_VALUE[k].test(scope[k]));
|
|
43
|
+
}
|
|
44
|
+
export class CodingAuthority {
|
|
45
|
+
reviewSecret = randomBytes(32);
|
|
46
|
+
reviewReceipts = new Map();
|
|
47
|
+
ledger;
|
|
48
|
+
now;
|
|
49
|
+
constructor(o) {
|
|
50
|
+
this.ledger = o.ledger;
|
|
51
|
+
this.now = o.now ?? Date.now;
|
|
52
|
+
}
|
|
53
|
+
iso() { return new Date(this.now()).toISOString(); }
|
|
54
|
+
receipt(binding) {
|
|
55
|
+
const now = this.now();
|
|
56
|
+
for (const [key, value] of this.reviewReceipts)
|
|
57
|
+
if (value.expiresAt <= now)
|
|
58
|
+
this.reviewReceipts.delete(key);
|
|
59
|
+
const existing = this.reviewReceipts.get(binding);
|
|
60
|
+
if (existing)
|
|
61
|
+
return existing;
|
|
62
|
+
if (this.reviewReceipts.size >= 1024)
|
|
63
|
+
throw Error('REVIEW_CAPACITY');
|
|
64
|
+
const expiresAt = now + 300000, reviewKey = createHash('sha256').update(binding + ':' + expiresAt).digest('hex');
|
|
65
|
+
const value = { expiresAt, reviewKey, challenge: createHmac('sha256', this.reviewSecret).update(reviewKey).digest('hex') };
|
|
66
|
+
this.reviewReceipts.set(binding, value);
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
commitChallenge(binding) { return this.receipt('COMMIT:' + binding).challenge; }
|
|
70
|
+
/** A short-lived, daemon-incarnation-bound review receipt, not an execution grant. */
|
|
71
|
+
reviewedPatch(i) {
|
|
72
|
+
const p = this.ledger.getCodingProposal(i.proposalId), root = this.ledger.getProjectRoot(i.projectId);
|
|
73
|
+
if (!p || p.principalId !== i.principalId || p.projectId !== i.projectId || p.digest !== i.digest || p.baseHead !== i.baseHead || !root || !this.ledger.principalIsEnabled(i.principalId)
|
|
74
|
+
|| this.ledger.getRunDetailForPrincipal(i.principalId, p.runId)?.projectId !== i.projectId || !this.ledger.verifyCodingChain().ok)
|
|
75
|
+
throw Error('REVIEW_SCOPE_INVALID');
|
|
76
|
+
const { expiresAt, reviewKey, challenge } = this.receipt('APPLY:' + JSON.stringify({ ...i, root }));
|
|
77
|
+
return { projectId: i.projectId, target: root, baseHead: p.baseHead, digest: p.digest, reviewKey, challenge, expiresAt, authorities: ['APPLY', 'GIT_READ'] };
|
|
78
|
+
}
|
|
79
|
+
approveReviewedPatch(i) {
|
|
80
|
+
let review;
|
|
81
|
+
try {
|
|
82
|
+
review = this.reviewedPatch({ principalId: i.principalId, origin: i.origin, projectId: i.projectId, proposalId: i.proposalId, digest: i.digest, baseHead: i.baseHead });
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return { ok: false, code: 'SCOPE_MISMATCH' };
|
|
86
|
+
}
|
|
87
|
+
const a = Buffer.from(i.challenge, 'hex'), b = Buffer.from(review.challenge, 'hex');
|
|
88
|
+
if (a.length !== b.length || !timingSafeEqual(a, b))
|
|
89
|
+
return { ok: false, code: 'SCOPE_MISMATCH' };
|
|
90
|
+
const p = this.ledger.getCodingProposal(i.proposalId);
|
|
91
|
+
const common = { principalId: i.principalId, projectId: p.projectId, runId: p.runId, scope: { proposalId: p.proposalId, digest: p.digest, reviewKey: review.reviewKey }, lifetimeMs: Math.min(60_000, review.expiresAt - this.now()) };
|
|
92
|
+
const apply = this.grant({ ...common, operation: 'APPLY' });
|
|
93
|
+
if (!apply.ok)
|
|
94
|
+
return apply;
|
|
95
|
+
const git = this.grant({ ...common, operation: 'GIT_READ' });
|
|
96
|
+
if (!git.ok) {
|
|
97
|
+
this.revoke(apply.grantId);
|
|
98
|
+
return git;
|
|
99
|
+
}
|
|
100
|
+
if (!this.record(p.runId, p.proposalId, 'REVIEWED_PATCH_APPROVED', 'ALLOWED', { origin: i.origin, projectId: p.projectId, reviewKey: review.reviewKey, applyGrant: apply.grantId, gitGrant: git.grantId })) {
|
|
101
|
+
this.revoke(apply.grantId);
|
|
102
|
+
this.revoke(git.grantId);
|
|
103
|
+
return { ok: false, code: 'AUDIT_UNAVAILABLE' };
|
|
104
|
+
}
|
|
105
|
+
return { ...apply, gitGrantId: git.grantId, reviewKey: review.reviewKey };
|
|
106
|
+
}
|
|
107
|
+
/** Writes decision evidence; false = the evidence store is unavailable and the caller must deny. */
|
|
108
|
+
record(runId, subjectId, event, decision, detail, kind = 'GRANT') {
|
|
109
|
+
try {
|
|
110
|
+
this.ledger.appendCodingEvent({ at: this.iso(), runId, subjectKind: kind, subjectId, event, decision, detail });
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/** Trusted local administration (never reachable from the model or HTTP): issues one scoped grant. */
|
|
118
|
+
grant(i) {
|
|
119
|
+
const deny = (code) => { this.record(String(i.runId).slice(0, 200), 'cgrant.none', 'GRANT_REFUSED', 'DENIED', { code, operation: String(i.operation).slice(0, 16) }); return { ok: false, code }; };
|
|
120
|
+
if (!CODING_OPERATIONS.includes(i.operation))
|
|
121
|
+
return { ok: false, code: 'OPERATION_INVALID' };
|
|
122
|
+
const scope = i.scope ?? {};
|
|
123
|
+
if (!scopeValid(i.operation, scope))
|
|
124
|
+
return deny('SCOPE_INVALID');
|
|
125
|
+
if (!Number.isInteger(i.lifetimeMs) || i.lifetimeMs < 1000 || i.lifetimeMs > CODING_MAX_LIFETIME_MS[i.operation])
|
|
126
|
+
return deny('LIFETIME_INVALID');
|
|
127
|
+
if (typeof i.runId !== 'string' || i.runId.length < 5 || i.runId.length > 200)
|
|
128
|
+
return deny('RUN_UNKNOWN');
|
|
129
|
+
const owner = this.ledger.getRunOwnerPrincipalId(i.runId);
|
|
130
|
+
if (!owner)
|
|
131
|
+
return deny('RUN_UNKNOWN');
|
|
132
|
+
if (owner !== i.principalId)
|
|
133
|
+
return deny('RUN_NOT_OWNED');
|
|
134
|
+
if (!this.ledger.principalIsEnabled(i.principalId))
|
|
135
|
+
return deny('PRINCIPAL_DISABLED');
|
|
136
|
+
if (!this.ledger.getProjectRoot(i.projectId))
|
|
137
|
+
return deny('PROJECT_UNKNOWN');
|
|
138
|
+
const grantId = `cgrant.${b64(18)}`;
|
|
139
|
+
const createdAt = this.iso();
|
|
140
|
+
const expiresAt = new Date(this.now() + i.lifetimeMs).toISOString();
|
|
141
|
+
// evidence BEFORE the grant exists: a grant is never usable without its issue record
|
|
142
|
+
if (!this.record(i.runId, grantId, 'GRANT_ISSUED', 'ALLOWED', { operation: i.operation, effect: CODING_EFFECT[i.operation], singleUse: SINGLE_USE_REQUIRED.has(i.operation), expiresAt }))
|
|
143
|
+
return { ok: false, code: 'AUDIT_UNAVAILABLE' };
|
|
144
|
+
this.ledger.insertCodingGrant({ grantId, principalId: i.principalId, projectId: i.projectId, runId: i.runId, operation: i.operation, effectClass: CODING_EFFECT[i.operation], scopeJson: JSON.stringify(scope),
|
|
145
|
+
singleUse: SINGLE_USE_REQUIRED.has(i.operation), createdAtIso: createdAt, expiresAtIso: expiresAt });
|
|
146
|
+
return { ok: true, grantId, expiresAt };
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 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.
|
|
150
|
+
* 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).
|
|
151
|
+
*/
|
|
152
|
+
authorize(r) {
|
|
153
|
+
const subject = `req.${r.operation}`;
|
|
154
|
+
const refuse = (code, grantId) => {
|
|
155
|
+
this.record(String(r.runId).slice(0, 200), grantId ?? subject, 'AUTHORIZE', 'DENIED', { code, operation: String(r.operation).slice(0, 16) });
|
|
156
|
+
return { ok: false, code };
|
|
157
|
+
};
|
|
158
|
+
if (!CODING_OPERATIONS.includes(r.operation))
|
|
159
|
+
return { ok: false, code: 'OPERATION_INVALID' };
|
|
160
|
+
const requested = r.scope ?? {};
|
|
161
|
+
if (!scopeValid(r.operation, requested))
|
|
162
|
+
return refuse('SCOPE_INVALID');
|
|
163
|
+
if (!this.ledger.principalIsEnabled(r.principalId))
|
|
164
|
+
return refuse('PRINCIPAL_DISABLED');
|
|
165
|
+
const owner = this.ledger.getRunOwnerPrincipalId(r.runId);
|
|
166
|
+
if (!owner)
|
|
167
|
+
return refuse('RUN_UNKNOWN');
|
|
168
|
+
if (owner !== r.principalId)
|
|
169
|
+
return refuse('RUN_NOT_OWNED');
|
|
170
|
+
const root = this.ledger.getProjectRoot(r.projectId);
|
|
171
|
+
if (!root)
|
|
172
|
+
return refuse('PROJECT_UNKNOWN');
|
|
173
|
+
try {
|
|
174
|
+
if (!existsSync(root) || !sameCanon(realpathSync.native(root), root))
|
|
175
|
+
return refuse('PROJECT_ROOT_INVALID');
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return refuse('PROJECT_ROOT_INVALID');
|
|
179
|
+
}
|
|
180
|
+
const nowMs = this.now();
|
|
181
|
+
const all = this.ledger.findCodingGrants(r.principalId, r.projectId, r.runId, r.operation);
|
|
182
|
+
if (all.length === 0)
|
|
183
|
+
return refuse('NO_GRANT');
|
|
184
|
+
// choose the first grant that fully admits; otherwise report the most specific reason among the candidates
|
|
185
|
+
let reason = 'SCOPE_MISMATCH';
|
|
186
|
+
let spent;
|
|
187
|
+
for (const g of all) {
|
|
188
|
+
if (g.revokedAt !== null) {
|
|
189
|
+
reason = 'GRANT_REVOKED';
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (Date.parse(g.expiresAt) <= nowMs) {
|
|
193
|
+
reason = 'GRANT_EXPIRED';
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (g.consumedAt !== null) {
|
|
197
|
+
reason = 'GRANT_CONSUMED';
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
let gs;
|
|
201
|
+
try {
|
|
202
|
+
gs = JSON.parse(g.scopeJson);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (g.effectClass !== CODING_EFFECT[r.operation] || Object.keys(gs).length !== Object.keys(requested).length || !Object.keys(requested).every((k) => gs[k] === requested[k])) {
|
|
208
|
+
reason = 'SCOPE_MISMATCH';
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
spent = g;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
if (!spent)
|
|
215
|
+
return refuse(reason, all[all.length - 1].grantId);
|
|
216
|
+
let consumed = false;
|
|
217
|
+
if (r.consume === true || spent.singleUse) {
|
|
218
|
+
// single-use grants are ALWAYS spent by the decision that uses them
|
|
219
|
+
if (!this.ledger.consumeCodingGrant(spent.grantId, this.iso()))
|
|
220
|
+
return refuse('GRANT_CONSUMED', spent.grantId);
|
|
221
|
+
consumed = true;
|
|
222
|
+
}
|
|
223
|
+
if (!this.record(r.runId, spent.grantId, 'AUTHORIZE', 'ALLOWED', { operation: r.operation, consumed }))
|
|
224
|
+
return { ok: false, code: 'AUDIT_UNAVAILABLE' };
|
|
225
|
+
return { ok: true, grantId: spent.grantId, consumed };
|
|
226
|
+
}
|
|
227
|
+
revoke(grantId) {
|
|
228
|
+
const g = this.ledger.getCodingGrant(grantId);
|
|
229
|
+
if (!g)
|
|
230
|
+
return false;
|
|
231
|
+
const ok = this.ledger.revokeCodingGrant(grantId, this.iso());
|
|
232
|
+
if (ok)
|
|
233
|
+
this.record(g.runId, grantId, 'GRANT_REVOKED', 'ALLOWED', { operation: g.operation });
|
|
234
|
+
return ok;
|
|
235
|
+
}
|
|
236
|
+
/** Revokes every unrevoked coding grant of a run (run cancelled, daemon shutdown, project removed). */
|
|
237
|
+
revokeRun(runId) {
|
|
238
|
+
const n = this.ledger.revokeCodingGrantsForRun(runId, this.iso());
|
|
239
|
+
if (n > 0)
|
|
240
|
+
this.record(runId, `run.${runId}`.slice(0, 200), 'RUN_GRANTS_REVOKED', 'ALLOWED', { count: n });
|
|
241
|
+
return n;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=codingAuthority.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { LoopbackHttpRequestV1, AuthorizedInvocation, BoundedFileRequestV1 } from '../../../../packages/contracts/dist/index.js';
|
|
2
|
+
export declare const FIXTURE_PROJECT_ID = "project.m03-fixture";
|
|
3
|
+
export declare const FIXTURE_PLUGIN_ID = "plugin.m03-fake";
|
|
4
|
+
export declare const FIXTURE_OPERATION_ID = "run-sentinel";
|
|
5
|
+
export declare function isFixtureIssuedInvocation(value: unknown): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Fixture authorization check for M03 walking skeleton.
|
|
8
|
+
* Invariant: Authorization is not inferred from structure; it requires explicit fixture matching.
|
|
9
|
+
*/
|
|
10
|
+
export declare function authorizeM03Fixture(request: LoopbackHttpRequestV1, expectedToken: string): AuthorizedInvocation;
|
|
11
|
+
/** Capability name for the read-only fixture branch. Deliberately independent of mutating dispatch. */
|
|
12
|
+
export declare const READ_ONLY_FIXTURE_CAPABILITY: "READ_ONLY_FIXTURE_EVIDENCE";
|
|
13
|
+
/** Only these exact relative paths may ever be requested. Anything else fails closed. */
|
|
14
|
+
export declare const FIXTURE_ALLOWED_EVIDENCE_PATHS: ReadonlySet<string>;
|
|
15
|
+
/** Upper bound for fixture reads, independent of the contract's 10 MiB ceiling. */
|
|
16
|
+
export declare const FIXTURE_MAX_READ_BYTES: number;
|
|
17
|
+
/**
|
|
18
|
+
* In-memory evidence declared by a deterministic test fixture. This is NOT a project context
|
|
19
|
+
* service (C07), artifact service (C08) or durable store (C09). It is supplied through an
|
|
20
|
+
* explicit dependency; production code never imports a fixture path.
|
|
21
|
+
*/
|
|
22
|
+
export interface FixtureEvidenceFile {
|
|
23
|
+
/** Truthful identity of the in-memory record (not a real filesystem path). */
|
|
24
|
+
canonicalPath: string;
|
|
25
|
+
content: string;
|
|
26
|
+
}
|
|
27
|
+
export interface FixtureReturnCandidates {
|
|
28
|
+
runId: string;
|
|
29
|
+
conversationId: string;
|
|
30
|
+
/** Every artifact the fixture declares, including ones that are NOT selected. Untrusted until parsed. */
|
|
31
|
+
artifacts: unknown[];
|
|
32
|
+
/** Artifact ids the fixture declares as selected for return. */
|
|
33
|
+
selectedArtifactIds: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface FixtureEvidenceSource {
|
|
36
|
+
readonly kind: 'FIXTURE_IN_MEMORY';
|
|
37
|
+
/** Must return undefined for any record the fixture does not explicitly declare. */
|
|
38
|
+
readFile(projectId: string, relativePath: string): FixtureEvidenceFile | undefined;
|
|
39
|
+
getReturnCandidates(projectId: string): FixtureReturnCandidates | undefined;
|
|
40
|
+
}
|
|
41
|
+
export interface ReadOnlyEvidenceGrant {
|
|
42
|
+
readonly capability: typeof READ_ONLY_FIXTURE_CAPABILITY;
|
|
43
|
+
readonly projectId: string;
|
|
44
|
+
readonly fileRequest: BoundedFileRequestV1;
|
|
45
|
+
}
|
|
46
|
+
export declare function isIssuedReadOnlyGrant(value: unknown): boolean;
|
|
47
|
+
export type ReadOnlyAuthorizer = typeof authorizeFixtureReadOnly;
|
|
48
|
+
/**
|
|
49
|
+
* Authorizes one read-only GET_CONTEXT request. Order: credential, action, project, absence of any
|
|
50
|
+
* driver-selection fields, strict payload keys, contract bounds, exact path allowlist.
|
|
51
|
+
* Invariant: a successful schema parse is not authorization; only an allowlisted path is.
|
|
52
|
+
*/
|
|
53
|
+
export declare function authorizeFixtureReadOnly(request: LoopbackHttpRequestV1, expectedToken: string): ReadOnlyEvidenceGrant;
|
|
54
|
+
//# sourceMappingURL=fixtureAuthorization.d.ts.map
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { createHash, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { AuthorizedInvocationSchema, ContractError, BoundedFileRequestV1Schema, createRunId, createAuthorizationGrantId, } from '../../../../packages/contracts/dist/index.js';
|
|
3
|
+
export const FIXTURE_PROJECT_ID = 'project.m03-fixture';
|
|
4
|
+
export const FIXTURE_PLUGIN_ID = 'plugin.m03-fake';
|
|
5
|
+
export const FIXTURE_OPERATION_ID = 'run-sentinel';
|
|
6
|
+
/**
|
|
7
|
+
* Registry of invocations minted by authorizeM03Fixture.
|
|
8
|
+
* Invariant: a structurally valid AuthorizedInvocation is NOT proof of authorization;
|
|
9
|
+
* only objects issued by this module are recognized by the coordinator.
|
|
10
|
+
*/
|
|
11
|
+
const issuedInvocations = new WeakSet();
|
|
12
|
+
export function isFixtureIssuedInvocation(value) {
|
|
13
|
+
return typeof value === 'object' && value !== null && issuedInvocations.has(value);
|
|
14
|
+
}
|
|
15
|
+
function tokensMatch(provided, expected) {
|
|
16
|
+
const a = createHash('sha256').update(provided, 'utf8').digest();
|
|
17
|
+
const b = createHash('sha256').update(expected, 'utf8').digest();
|
|
18
|
+
return timingSafeEqual(a, b);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Fixture authorization check for M03 walking skeleton.
|
|
22
|
+
* Invariant: Authorization is not inferred from structure; it requires explicit fixture matching.
|
|
23
|
+
*/
|
|
24
|
+
export function authorizeM03Fixture(request, expectedToken) {
|
|
25
|
+
if (!request.authToken || !expectedToken || !tokensMatch(request.authToken, expectedToken)) {
|
|
26
|
+
throw new ContractError({
|
|
27
|
+
errorCode: 'MISSING_OR_INVALID_AUTHORIZATION',
|
|
28
|
+
message: 'Invalid or missing fixture authorization token',
|
|
29
|
+
correlationId: request.requestId,
|
|
30
|
+
projectId: request.projectId,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
if (request.action !== 'DISPATCH_PROMPT') {
|
|
34
|
+
throw new ContractError({
|
|
35
|
+
errorCode: 'UNAUTHORIZED_PROJECT_OR_OPERATION',
|
|
36
|
+
message: `Unauthorized action for M03 fixture: ${request.action}`,
|
|
37
|
+
correlationId: request.requestId,
|
|
38
|
+
projectId: request.projectId,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (request.projectId !== FIXTURE_PROJECT_ID) {
|
|
42
|
+
throw new ContractError({
|
|
43
|
+
errorCode: 'UNAUTHORIZED_PROJECT_OR_OPERATION',
|
|
44
|
+
message: `Unauthorized project ID: ${request.projectId}`,
|
|
45
|
+
correlationId: request.requestId,
|
|
46
|
+
projectId: request.projectId,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (request.pluginId !== FIXTURE_PLUGIN_ID) {
|
|
50
|
+
throw new ContractError({
|
|
51
|
+
errorCode: 'UNAUTHORIZED_PROJECT_OR_OPERATION',
|
|
52
|
+
message: `Unauthorized plugin ID: ${request.pluginId}`,
|
|
53
|
+
correlationId: request.requestId,
|
|
54
|
+
projectId: request.projectId,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (request.operationId !== FIXTURE_OPERATION_ID) {
|
|
58
|
+
throw new ContractError({
|
|
59
|
+
errorCode: 'UNAUTHORIZED_PROJECT_OR_OPERATION',
|
|
60
|
+
message: `Unauthorized operation ID: ${request.operationId}`,
|
|
61
|
+
correlationId: request.requestId,
|
|
62
|
+
projectId: request.projectId,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (!request.idempotencyKey) {
|
|
66
|
+
throw new ContractError({
|
|
67
|
+
errorCode: 'INVALID_PAYLOAD',
|
|
68
|
+
message: 'Missing required idempotencyKey for DISPATCH_PROMPT',
|
|
69
|
+
correlationId: request.requestId,
|
|
70
|
+
projectId: request.projectId,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
const prompt = request.payload.prompt;
|
|
74
|
+
if (typeof prompt !== 'string' || prompt.trim().length === 0) {
|
|
75
|
+
throw new ContractError({
|
|
76
|
+
errorCode: 'INVALID_PAYLOAD',
|
|
77
|
+
message: 'Payload prompt must be a non-empty string',
|
|
78
|
+
correlationId: request.requestId,
|
|
79
|
+
projectId: request.projectId,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const runId = createRunId(`run.m03-${randomUUID()}`);
|
|
83
|
+
const authorizationGrantId = createAuthorizationGrantId(`grant.m03-${randomUUID()}`);
|
|
84
|
+
const invocation = AuthorizedInvocationSchema.parse({
|
|
85
|
+
schemaVersion: 1,
|
|
86
|
+
runId,
|
|
87
|
+
projectId: request.projectId,
|
|
88
|
+
pluginId: request.pluginId,
|
|
89
|
+
operationId: request.operationId,
|
|
90
|
+
authorizationGrantId,
|
|
91
|
+
idempotencyKey: request.idempotencyKey,
|
|
92
|
+
params: request.payload,
|
|
93
|
+
workingDirectory: process.cwd(),
|
|
94
|
+
securityTier: 'PATH_CHECKS_ONLY',
|
|
95
|
+
timeoutMs: 30000,
|
|
96
|
+
createdAt: new Date().toISOString(),
|
|
97
|
+
});
|
|
98
|
+
Object.freeze(invocation);
|
|
99
|
+
issuedInvocations.add(invocation);
|
|
100
|
+
return invocation;
|
|
101
|
+
}
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
// Read-only fixture evidence authorization (M04, K03/K05 read-only branch)
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
/** Capability name for the read-only fixture branch. Deliberately independent of mutating dispatch. */
|
|
106
|
+
export const READ_ONLY_FIXTURE_CAPABILITY = 'READ_ONLY_FIXTURE_EVIDENCE';
|
|
107
|
+
/** Only these exact relative paths may ever be requested. Anything else fails closed. */
|
|
108
|
+
export const FIXTURE_ALLOWED_EVIDENCE_PATHS = new Set(['reports/m04-evidence.txt']);
|
|
109
|
+
/** Upper bound for fixture reads, independent of the contract's 10 MiB ceiling. */
|
|
110
|
+
export const FIXTURE_MAX_READ_BYTES = 64 * 1024;
|
|
111
|
+
const READ_PAYLOAD_KEYS = new Set(['relativePath', 'maxBytes', 'maxLines']);
|
|
112
|
+
const issuedReadOnlyGrants = new WeakSet();
|
|
113
|
+
export function isIssuedReadOnlyGrant(value) {
|
|
114
|
+
return typeof value === 'object' && value !== null && issuedReadOnlyGrants.has(value);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Authorizes one read-only GET_CONTEXT request. Order: credential, action, project, absence of any
|
|
118
|
+
* driver-selection fields, strict payload keys, contract bounds, exact path allowlist.
|
|
119
|
+
* Invariant: a successful schema parse is not authorization; only an allowlisted path is.
|
|
120
|
+
*/
|
|
121
|
+
export function authorizeFixtureReadOnly(request, expectedToken) {
|
|
122
|
+
const fail = (errorCode, message, details) => new ContractError({
|
|
123
|
+
errorCode,
|
|
124
|
+
message,
|
|
125
|
+
correlationId: request.requestId,
|
|
126
|
+
projectId: request.projectId,
|
|
127
|
+
...(details ? { details } : {}),
|
|
128
|
+
});
|
|
129
|
+
if (!request.authToken || !expectedToken || !tokensMatch(request.authToken, expectedToken)) {
|
|
130
|
+
throw fail('MISSING_OR_INVALID_AUTHORIZATION', 'Invalid or missing fixture authorization token');
|
|
131
|
+
}
|
|
132
|
+
if (request.action !== 'GET_CONTEXT') {
|
|
133
|
+
throw fail('UNAUTHORIZED_PROJECT_OR_OPERATION', `Not a read-only evidence action: ${request.action}`);
|
|
134
|
+
}
|
|
135
|
+
if (request.projectId !== FIXTURE_PROJECT_ID) {
|
|
136
|
+
throw fail('UNAUTHORIZED_PROJECT_OR_OPERATION', `Unauthorized project ID: ${request.projectId}`);
|
|
137
|
+
}
|
|
138
|
+
if (request.pluginId !== undefined ||
|
|
139
|
+
request.operationId !== undefined ||
|
|
140
|
+
request.idempotencyKey !== undefined) {
|
|
141
|
+
throw fail('INVALID_PAYLOAD', 'Read-only evidence requests must not select a plugin, operation or idempotency key');
|
|
142
|
+
}
|
|
143
|
+
const payload = request.payload;
|
|
144
|
+
const unknownKeys = Object.keys(payload).filter((key) => !READ_PAYLOAD_KEYS.has(key));
|
|
145
|
+
if (unknownKeys.length > 0) {
|
|
146
|
+
throw fail('INVALID_PAYLOAD', 'Unexpected read-only payload fields', { unknownKeys });
|
|
147
|
+
}
|
|
148
|
+
// The project identity comes from the authenticated envelope, never from the payload.
|
|
149
|
+
const parsed = BoundedFileRequestV1Schema.safeParse({
|
|
150
|
+
schemaVersion: 1,
|
|
151
|
+
projectId: request.projectId,
|
|
152
|
+
relativePath: payload.relativePath,
|
|
153
|
+
maxBytes: payload.maxBytes,
|
|
154
|
+
...(payload.maxLines !== undefined ? { maxLines: payload.maxLines } : {}),
|
|
155
|
+
});
|
|
156
|
+
if (!parsed.success || parsed.data.maxBytes > FIXTURE_MAX_READ_BYTES) {
|
|
157
|
+
throw fail('INVALID_PAYLOAD', 'Invalid byte/line bounds or relative path', {
|
|
158
|
+
issues: parsed.success ? [{ path: 'maxBytes', code: 'too_big' }] : parsed.error.issues.map((i) => ({ path: i.path.join('.'), code: i.code })),
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (!FIXTURE_ALLOWED_EVIDENCE_PATHS.has(parsed.data.relativePath)) {
|
|
162
|
+
throw fail('CONTENT_BOUNDS_OR_PATH_DENIAL', 'Requested path is not an allowlisted fixture record');
|
|
163
|
+
}
|
|
164
|
+
const grant = Object.freeze({
|
|
165
|
+
capability: READ_ONLY_FIXTURE_CAPABILITY,
|
|
166
|
+
projectId: request.projectId,
|
|
167
|
+
fileRequest: Object.freeze(parsed.data),
|
|
168
|
+
});
|
|
169
|
+
issuedReadOnlyGrants.add(grant);
|
|
170
|
+
return grant;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=fixtureAuthorization.js.map
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { ApprovalRow, RunDetail, SqliteLedger } from '../storage/sqliteLedger.js';
|
|
2
|
+
/**
|
|
3
|
+
* C03 secure authority (B02-A): canonical project roots, local-admin pairing issue, bearer
|
|
4
|
+
* principals and exact operation grants. Application-level authorization only; this is NOT
|
|
5
|
+
* OS-level filesystem containment.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PAIRING_CHALLENGE_TTL_MS = 120000;
|
|
8
|
+
export declare const BEARER_TOKEN_TTL_MS: number;
|
|
9
|
+
export type EffectClassName = 'read' | 'write_project' | 'external_network' | 'destructive';
|
|
10
|
+
export type VerifiedOperationEffect = {
|
|
11
|
+
effectClass: EffectClassName;
|
|
12
|
+
verified: true;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Trusted operation-definition lookup injected by the composition root (a future C04 provides the
|
|
16
|
+
* production implementation). Returning undefined means the operation is unknown: authorization fails closed.
|
|
17
|
+
* There is deliberately no default resolver and no default effect class.
|
|
18
|
+
*/
|
|
19
|
+
export type OperationEffectResolver = (op: {
|
|
20
|
+
pluginId: string;
|
|
21
|
+
operationId: string;
|
|
22
|
+
}) => VerifiedOperationEffect | undefined;
|
|
23
|
+
export declare const APPROVAL_CHALLENGE_TTL_MS = 60000;
|
|
24
|
+
/** SW-062: a native-bootstrap session bearer is short-lived; the worker silently re-establishes it through the registered native host. */
|
|
25
|
+
export declare const INSTALLATION_SESSION_TTL_MS: number;
|
|
26
|
+
export declare const INSTALLATION_MAX_FAILED_ATTEMPTS = 10;
|
|
27
|
+
export type ConsentMode = 'LOCAL_CONFIRM' | 'RUN_CLICK';
|
|
28
|
+
export interface CreatedInstallation {
|
|
29
|
+
installationId: string;
|
|
30
|
+
principalId: string;
|
|
31
|
+
/** Returned ONCE to the trusted local installer, which protects it with DPAPI. Only its SHA-256 is stored in the ledger. */
|
|
32
|
+
secret: string;
|
|
33
|
+
extensionOrigin: string;
|
|
34
|
+
}
|
|
35
|
+
export type InstallationSessionResult = {
|
|
36
|
+
ok: true;
|
|
37
|
+
principalId: string;
|
|
38
|
+
bearerToken: string;
|
|
39
|
+
expiresAt: string;
|
|
40
|
+
}
|
|
41
|
+
/** `reason` is for the PRIVATE log only; the wire answer is identical for every refusal. */
|
|
42
|
+
| {
|
|
43
|
+
ok: false;
|
|
44
|
+
reason: 'BAD_ORIGIN' | 'UNKNOWN' | 'REVOKED' | 'ORIGIN' | 'LOCKED' | 'SECRET' | 'PRINCIPAL_DISABLED';
|
|
45
|
+
};
|
|
46
|
+
export interface PairedAuthorityOptions {
|
|
47
|
+
ledger: SqliteLedger;
|
|
48
|
+
resolveVerifiedOperationEffect: OperationEffectResolver;
|
|
49
|
+
/** Injectable clock for expiry tests; defaults to Date.now. */
|
|
50
|
+
now?: () => number;
|
|
51
|
+
/**
|
|
52
|
+
* Trusted in-process observer, called once after a pairing is committed. It receives only the same
|
|
53
|
+
* non-secret receipt fields the pairing response already carries (never the bearer). Used by the
|
|
54
|
+
* attended local operator console so a human can learn the new principal id. Errors are swallowed.
|
|
55
|
+
*/
|
|
56
|
+
onPairingCompleted?: (receipt: {
|
|
57
|
+
principalId: string;
|
|
58
|
+
origin: string;
|
|
59
|
+
}) => void;
|
|
60
|
+
}
|
|
61
|
+
export interface IssuedApproval {
|
|
62
|
+
approvalId: string;
|
|
63
|
+
/** One-time secret returned once to the trusted in-process caller; only its SHA-256 is stored. */
|
|
64
|
+
approvalCode: string;
|
|
65
|
+
expiresAt: string;
|
|
66
|
+
}
|
|
67
|
+
export interface IssuedChallenge {
|
|
68
|
+
challengeId: string;
|
|
69
|
+
/** One-time code; returned once to the trusted local administrator and never stored or logged. */
|
|
70
|
+
code: string;
|
|
71
|
+
origin: string;
|
|
72
|
+
expiresAt: string;
|
|
73
|
+
}
|
|
74
|
+
export interface AuthenticatedPrincipal {
|
|
75
|
+
principalId: string;
|
|
76
|
+
origin: string;
|
|
77
|
+
}
|
|
78
|
+
export type AuthenticateResult = {
|
|
79
|
+
ok: true;
|
|
80
|
+
principal: AuthenticatedPrincipal;
|
|
81
|
+
} | {
|
|
82
|
+
ok: false;
|
|
83
|
+
reason: 'UNAUTHENTICATED' | 'ORIGIN_DENIED';
|
|
84
|
+
};
|
|
85
|
+
export type PairResult = {
|
|
86
|
+
ok: true;
|
|
87
|
+
principalId: string;
|
|
88
|
+
bearerToken: string;
|
|
89
|
+
pairedOrigin: string;
|
|
90
|
+
expiresAt: string;
|
|
91
|
+
}
|
|
92
|
+
/** `reason` is for the daemon's PRIVATE diagnostic log only. It is never put on the wire: the HTTP answer is identical for every refusal. */
|
|
93
|
+
| {
|
|
94
|
+
ok: false;
|
|
95
|
+
reason: 'BAD_ORIGIN' | 'INVALID' | 'ORIGIN' | 'USED' | 'EXPIRED' | 'LOCKED';
|
|
96
|
+
};
|
|
97
|
+
export declare class ProjectRootRejectedError extends Error {
|
|
98
|
+
constructor(reason: string);
|
|
99
|
+
}
|
|
100
|
+
export declare class PairedAuthority {
|
|
101
|
+
private readonly ledger;
|
|
102
|
+
private readonly now;
|
|
103
|
+
private readonly resolver;
|
|
104
|
+
private readonly onPairingCompleted?;
|
|
105
|
+
constructor(opts: PairedAuthorityOptions);
|
|
106
|
+
static isValidExtensionOrigin(origin: unknown): origin is string;
|
|
107
|
+
registerApprovedProject(projectId: string, absoluteRoot: string): string;
|
|
108
|
+
issuePairingChallenge(exactExtensionOrigin: string): IssuedChallenge;
|
|
109
|
+
grantOperation(principalId: string, projectId: string, pluginId: string, operationId: string, maxEffectClass: EffectClassName, expiresAt: Date, requiresConfirmation?: boolean, consentMode?: ConsentMode): string;
|
|
110
|
+
/** Trusted local installer only (never HTTP). Creates a revocable installation bound to ONE exact extension origin, with a stable principal. */
|
|
111
|
+
createInstallation(exactExtensionOrigin: string): CreatedInstallation;
|
|
112
|
+
/** Issues a fresh short-lived bearer for the installation's stable principal (rotating out the previous one). */
|
|
113
|
+
issueInstallationSession(installationId: string, secret: string, origin: string): InstallationSessionResult;
|
|
114
|
+
/** Local admin channel (setup CLI): proves the installation secret WITHOUT rotating the extension's bearer. A wrong secret counts as a failed attempt. */
|
|
115
|
+
verifyInstallationSecret(installationId: string, secret: string): string | undefined;
|
|
116
|
+
revokeInstallation(installationId: string): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* The consent a run of this operation needs, evaluated with the SAME admission rules as authorize(). RUN_CLICK only when an admitting grant says so;
|
|
119
|
+
* anything else (including no grant) is LOCAL_CONFIRM, i.e. the separate trusted confirmation. A request can never choose this.
|
|
120
|
+
*/
|
|
121
|
+
consentModeFor(principalId: string, projectId: string, pluginId: string, operationId: string): ConsentMode;
|
|
122
|
+
/** The verified effect class of an operation (undefined = unknown: fail closed). */
|
|
123
|
+
effectClassOf(pluginId: string, operationId: string): EffectClassName | undefined;
|
|
124
|
+
/** Trusted local revocation (not exposed over HTTP). */
|
|
125
|
+
revokeGrant(grantId: string): boolean;
|
|
126
|
+
revokePrincipal(principalId: string): boolean;
|
|
127
|
+
completePairing(challengeId: string, code: string, origin: string): PairResult;
|
|
128
|
+
/** A valid bearer never overrides the origin: the exact stored origin is required on every call. */
|
|
129
|
+
authenticate(bearer: string | undefined, origin: string | undefined): AuthenticateResult;
|
|
130
|
+
isKnownOrigin(origin: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Provisional nonexecuting admission policy (SW-032): the operation must be defined by the trusted resolver
|
|
133
|
+
* as verified `read`, and a stored, unexpired grant must name exactly this principal, project, plugin and
|
|
134
|
+
* operation at effect class `read` with requires_confirmation=true. No effect-class ranking is applied:
|
|
135
|
+
* every other class is denied. The request's own approval flag is never consulted here.
|
|
136
|
+
*/
|
|
137
|
+
authorize(principalId: string, projectId: string, pluginId: string, operationId: string): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* SW-051: the same admission rules as authorize(), evaluated again at launch time, returning the id of one stored grant that
|
|
140
|
+
* satisfies them (for the AuthorizedInvocation) or undefined. A revoked grant, disabled principal, unknown or non-read operation,
|
|
141
|
+
* or a project root that is no longer its own canonical path all deny. This decides nothing about processes or containment.
|
|
142
|
+
*/
|
|
143
|
+
authorizeLaunch(principalId: string, projectId: string, pluginId: string, operationId: string): {
|
|
144
|
+
grantId: string;
|
|
145
|
+
} | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Trusted, in-process-only issuance of a one-time approval proof for a pending run. This is NOT
|
|
148
|
+
* exposed over HTTP and is not evidence of a real user gesture; a future UI channel must call it
|
|
149
|
+
* only after a verified user action.
|
|
150
|
+
*/
|
|
151
|
+
issueLocalApprovalChallenge(input: {
|
|
152
|
+
principalId: string;
|
|
153
|
+
runId: string;
|
|
154
|
+
}): IssuedApproval;
|
|
155
|
+
/** True iff the stored challenge is bound to this run/principal/fingerprint, unexpired, and the code matches. */
|
|
156
|
+
verifyApprovalProof(run: RunDetail, approval: ApprovalRow, presentedCode: string, requireUnconsumed: boolean): boolean;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=pairedAuthority.d.ts.map
|