@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,273 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { existsSync, lstatSync, realpathSync, statSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join, normalize, sep } from 'node:path';
|
|
4
|
+
import { EXTENSION_ORIGIN_PATTERN } from '../../../../packages/contracts/dist/index.js';
|
|
5
|
+
import { sha256Hex } from '../storage/sqliteLedger.js';
|
|
6
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
7
|
+
/**
|
|
8
|
+
* C03 secure authority (B02-A): canonical project roots, local-admin pairing issue, bearer
|
|
9
|
+
* principals and exact operation grants. Application-level authorization only; this is NOT
|
|
10
|
+
* OS-level filesystem containment.
|
|
11
|
+
*/
|
|
12
|
+
export const PAIRING_CHALLENGE_TTL_MS = 120_000;
|
|
13
|
+
export const BEARER_TOKEN_TTL_MS = 24 * 60 * 60 * 1000;
|
|
14
|
+
export const APPROVAL_CHALLENGE_TTL_MS = 60_000;
|
|
15
|
+
/** SW-062: a native-bootstrap session bearer is short-lived; the worker silently re-establishes it through the registered native host. */
|
|
16
|
+
export const INSTALLATION_SESSION_TTL_MS = 8 * 60 * 60 * 1000;
|
|
17
|
+
export const INSTALLATION_MAX_FAILED_ATTEMPTS = 10;
|
|
18
|
+
export class ProjectRootRejectedError extends Error {
|
|
19
|
+
constructor(reason) {
|
|
20
|
+
super(`PROJECT_ROOT_REJECTED: ${reason}`);
|
|
21
|
+
this.name = 'ProjectRootRejectedError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const digestsEqual = (a, b) => {
|
|
25
|
+
const x = Buffer.from(a, 'hex');
|
|
26
|
+
const y = Buffer.from(b, 'hex');
|
|
27
|
+
return x.length === y.length && x.length > 0 && timingSafeEqual(x, y);
|
|
28
|
+
};
|
|
29
|
+
const b64url = (n) => randomBytes(n).toString('base64url');
|
|
30
|
+
const sameCanonical = (a, b) => process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b;
|
|
31
|
+
export class PairedAuthority {
|
|
32
|
+
ledger;
|
|
33
|
+
now;
|
|
34
|
+
resolver;
|
|
35
|
+
onPairingCompleted;
|
|
36
|
+
constructor(opts) {
|
|
37
|
+
if (typeof opts.resolveVerifiedOperationEffect !== 'function') {
|
|
38
|
+
throw new Error('RESOLVER_REQUIRED: a trusted operation-effect resolver must be injected');
|
|
39
|
+
}
|
|
40
|
+
this.ledger = opts.ledger;
|
|
41
|
+
this.resolver = opts.resolveVerifiedOperationEffect;
|
|
42
|
+
this.now = opts.now ?? Date.now;
|
|
43
|
+
this.onPairingCompleted = opts.onPairingCompleted;
|
|
44
|
+
}
|
|
45
|
+
static isValidExtensionOrigin(origin) {
|
|
46
|
+
return typeof origin === 'string' && EXTENSION_ORIGIN_PATTERN.test(origin);
|
|
47
|
+
}
|
|
48
|
+
// ---- trusted local administration (not exposed over HTTP) ----------------
|
|
49
|
+
registerApprovedProject(projectId, absoluteRoot) {
|
|
50
|
+
if (typeof projectId !== 'string' || projectId.length === 0)
|
|
51
|
+
throw new ProjectRootRejectedError('empty project id');
|
|
52
|
+
if (typeof absoluteRoot !== 'string' || !isAbsolute(absoluteRoot))
|
|
53
|
+
throw new ProjectRootRejectedError('root must be absolute');
|
|
54
|
+
if (absoluteRoot.split(/[\\/]+/).includes('..'))
|
|
55
|
+
throw new ProjectRootRejectedError('traversal segments are not allowed');
|
|
56
|
+
if (!existsSync(absoluteRoot))
|
|
57
|
+
throw new ProjectRootRejectedError('root does not exist');
|
|
58
|
+
if (lstatSync(absoluteRoot).isSymbolicLink())
|
|
59
|
+
throw new ProjectRootRejectedError('root is a symbolic link');
|
|
60
|
+
if (!statSync(absoluteRoot).isDirectory())
|
|
61
|
+
throw new ProjectRootRejectedError('root is not a directory');
|
|
62
|
+
const canonical = realpathSync.native(absoluteRoot);
|
|
63
|
+
const requested = normalize(absoluteRoot).replace(new RegExp(`\\${sep}+$`), '');
|
|
64
|
+
if (!sameCanonical(canonical.replace(new RegExp(`\\${sep}+$`), ''), requested)) {
|
|
65
|
+
throw new ProjectRootRejectedError('root is an alias (junction, symlink or short-name) of a different canonical path');
|
|
66
|
+
}
|
|
67
|
+
if (!existsSync(join(canonical, '.git')))
|
|
68
|
+
throw new ProjectRootRejectedError('root is not a Git working tree root');
|
|
69
|
+
this.ledger.insertProject(projectId, canonical, new Date(this.now()).toISOString());
|
|
70
|
+
return canonical;
|
|
71
|
+
}
|
|
72
|
+
issuePairingChallenge(exactExtensionOrigin) {
|
|
73
|
+
if (!PairedAuthority.isValidExtensionOrigin(exactExtensionOrigin)) {
|
|
74
|
+
throw new Error('INVALID_EXTENSION_ORIGIN');
|
|
75
|
+
}
|
|
76
|
+
const challengeId = `chal.${b64url(24)}`;
|
|
77
|
+
const code = b64url(12); // 16 ASCII characters
|
|
78
|
+
const expiresAt = new Date(this.now() + PAIRING_CHALLENGE_TTL_MS).toISOString();
|
|
79
|
+
this.ledger.insertChallenge(challengeId, exactExtensionOrigin, sha256Hex(code), expiresAt);
|
|
80
|
+
return { challengeId, code, origin: exactExtensionOrigin, expiresAt };
|
|
81
|
+
}
|
|
82
|
+
grantOperation(principalId, projectId, pluginId, operationId, maxEffectClass, expiresAt, requiresConfirmation = true, consentMode = 'LOCAL_CONFIRM') {
|
|
83
|
+
if (!['read', 'write_project', 'external_network', 'destructive'].includes(maxEffectClass))
|
|
84
|
+
throw new Error('INVALID_EFFECT_CLASS');
|
|
85
|
+
if (consentMode !== 'LOCAL_CONFIRM' && consentMode !== 'RUN_CLICK')
|
|
86
|
+
throw new Error('INVALID_CONSENT_MODE');
|
|
87
|
+
if (consentMode === 'RUN_CLICK') {
|
|
88
|
+
// SW-062: the Run click may be the per-run consent ONLY for an operation the trusted resolver defines as verified read. Never widened by a request.
|
|
89
|
+
const def = this.resolver({ pluginId, operationId });
|
|
90
|
+
if (maxEffectClass !== 'read' || !def || def.verified !== true || def.effectClass !== 'read' || requiresConfirmation !== true)
|
|
91
|
+
throw new Error('RUN_CLICK_REQUIRES_VERIFIED_READ');
|
|
92
|
+
}
|
|
93
|
+
if (!this.ledger.principalExists(principalId))
|
|
94
|
+
throw new Error('UNKNOWN_PRINCIPAL');
|
|
95
|
+
const grantId = `grant.${b64url(18)}`;
|
|
96
|
+
this.ledger.insertGrant({
|
|
97
|
+
grantId, principalId, projectId, pluginId, operationId, maxEffectClass,
|
|
98
|
+
expiresAtIso: expiresAt.toISOString(), requiresConfirmation, consentMode,
|
|
99
|
+
});
|
|
100
|
+
return grantId;
|
|
101
|
+
}
|
|
102
|
+
// ---- SW-062 installation trust (trusted local setup + native bootstrap) ------------------------------------------------------------------
|
|
103
|
+
/** Trusted local installer only (never HTTP). Creates a revocable installation bound to ONE exact extension origin, with a stable principal. */
|
|
104
|
+
createInstallation(exactExtensionOrigin) {
|
|
105
|
+
if (!PairedAuthority.isValidExtensionOrigin(exactExtensionOrigin))
|
|
106
|
+
throw new Error('INVALID_EXTENSION_ORIGIN');
|
|
107
|
+
const installationId = `inst.${b64url(18)}`;
|
|
108
|
+
const principalId = `prin.${b64url(18)}`;
|
|
109
|
+
const secret = b64url(32);
|
|
110
|
+
this.ledger.createInstallation({
|
|
111
|
+
installationId, principalId, extensionOrigin: exactExtensionOrigin, secretSha256: sha256Hex(secret),
|
|
112
|
+
placeholderTokenSha256: sha256Hex(b64url(32)), nowIso: new Date(this.now()).toISOString(),
|
|
113
|
+
});
|
|
114
|
+
return { installationId, principalId, secret, extensionOrigin: exactExtensionOrigin };
|
|
115
|
+
}
|
|
116
|
+
/** Issues a fresh short-lived bearer for the installation's stable principal (rotating out the previous one). */
|
|
117
|
+
issueInstallationSession(installationId, secret, origin) {
|
|
118
|
+
if (!PairedAuthority.isValidExtensionOrigin(origin))
|
|
119
|
+
return { ok: false, reason: 'BAD_ORIGIN' };
|
|
120
|
+
const bearerToken = b64url(32);
|
|
121
|
+
const expiresAt = new Date(this.now() + INSTALLATION_SESSION_TTL_MS).toISOString();
|
|
122
|
+
const r = this.ledger.issueInstallationSession({
|
|
123
|
+
installationId, origin, secretSha256: sha256Hex(secret), tokenSha256: sha256Hex(bearerToken), tokenExpiresAtIso: expiresAt, maxFailedAttempts: INSTALLATION_MAX_FAILED_ATTEMPTS,
|
|
124
|
+
});
|
|
125
|
+
if (r.kind !== 'OK')
|
|
126
|
+
return { ok: false, reason: r.reason };
|
|
127
|
+
return { ok: true, principalId: r.principalId, bearerToken, expiresAt };
|
|
128
|
+
}
|
|
129
|
+
/** Local admin channel (setup CLI): proves the installation secret WITHOUT rotating the extension's bearer. A wrong secret counts as a failed attempt. */
|
|
130
|
+
verifyInstallationSecret(installationId, secret) {
|
|
131
|
+
const inst = this.ledger.getInstallation(installationId);
|
|
132
|
+
if (!inst || inst.revokedAt !== null || inst.failedAttempts >= INSTALLATION_MAX_FAILED_ATTEMPTS)
|
|
133
|
+
return undefined;
|
|
134
|
+
if (!digestsEqual(inst.secretSha256, sha256Hex(secret))) {
|
|
135
|
+
this.ledger.recordInstallationFailure(installationId);
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
return this.ledger.principalIsEnabled(inst.principalId) ? inst.principalId : undefined;
|
|
139
|
+
}
|
|
140
|
+
revokeInstallation(installationId) {
|
|
141
|
+
return this.ledger.revokeInstallation(installationId, new Date(this.now()).toISOString());
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* 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;
|
|
145
|
+
* anything else (including no grant) is LOCAL_CONFIRM, i.e. the separate trusted confirmation. A request can never choose this.
|
|
146
|
+
*/
|
|
147
|
+
consentModeFor(principalId, projectId, pluginId, operationId) {
|
|
148
|
+
if (!this.authorize(principalId, projectId, pluginId, operationId))
|
|
149
|
+
return 'LOCAL_CONFIRM';
|
|
150
|
+
const def = this.resolver({ pluginId, operationId });
|
|
151
|
+
if (!def || def.verified !== true || def.effectClass !== 'read')
|
|
152
|
+
return 'LOCAL_CONFIRM';
|
|
153
|
+
const nowMs = this.now();
|
|
154
|
+
const ok = this.ledger.findGrants(principalId, projectId, pluginId, operationId).some((g) => Date.parse(g.expiresAt) > nowMs && g.maxEffectClass === 'read' && g.requiresConfirmation === true && g.consentMode === 'RUN_CLICK');
|
|
155
|
+
return ok ? 'RUN_CLICK' : 'LOCAL_CONFIRM';
|
|
156
|
+
}
|
|
157
|
+
/** The verified effect class of an operation (undefined = unknown: fail closed). */
|
|
158
|
+
effectClassOf(pluginId, operationId) {
|
|
159
|
+
const def = this.resolver({ pluginId, operationId });
|
|
160
|
+
return def && def.verified === true ? def.effectClass : undefined;
|
|
161
|
+
}
|
|
162
|
+
/** Trusted local revocation (not exposed over HTTP). */
|
|
163
|
+
revokeGrant(grantId) {
|
|
164
|
+
return this.ledger.revokeGrant(grantId);
|
|
165
|
+
}
|
|
166
|
+
revokePrincipal(principalId) {
|
|
167
|
+
return this.ledger.disablePrincipal(principalId);
|
|
168
|
+
}
|
|
169
|
+
// ---- request-time decisions ----------------------------------------------
|
|
170
|
+
completePairing(challengeId, code, origin) {
|
|
171
|
+
if (!PairedAuthority.isValidExtensionOrigin(origin))
|
|
172
|
+
return { ok: false, reason: 'BAD_ORIGIN' };
|
|
173
|
+
const principalId = `prin.${b64url(18)}`;
|
|
174
|
+
const bearerToken = b64url(32);
|
|
175
|
+
const nowMs = this.now();
|
|
176
|
+
const expiresAt = new Date(nowMs + BEARER_TOKEN_TTL_MS).toISOString();
|
|
177
|
+
const res = this.ledger.redeemPairing({
|
|
178
|
+
challengeId, origin, codeSha256: sha256Hex(code), nowMs, principalId,
|
|
179
|
+
tokenSha256: sha256Hex(bearerToken), tokenExpiresAtIso: expiresAt,
|
|
180
|
+
});
|
|
181
|
+
if (res !== 'OK')
|
|
182
|
+
return { ok: false, reason: res };
|
|
183
|
+
try {
|
|
184
|
+
this.onPairingCompleted?.({ principalId, origin });
|
|
185
|
+
}
|
|
186
|
+
catch { /* an observer can never affect pairing */ }
|
|
187
|
+
return { ok: true, principalId, bearerToken, pairedOrigin: origin, expiresAt };
|
|
188
|
+
}
|
|
189
|
+
/** A valid bearer never overrides the origin: the exact stored origin is required on every call. */
|
|
190
|
+
authenticate(bearer, origin) {
|
|
191
|
+
if (!bearer)
|
|
192
|
+
return { ok: false, reason: 'UNAUTHENTICATED' };
|
|
193
|
+
const p = this.ledger.findPrincipalByTokenSha256(sha256Hex(bearer));
|
|
194
|
+
if (!p || !p.enabled || Date.parse(p.tokenExpiresAt) <= this.now())
|
|
195
|
+
return { ok: false, reason: 'UNAUTHENTICATED' };
|
|
196
|
+
if (!PairedAuthority.isValidExtensionOrigin(origin) || origin !== p.exactOrigin) {
|
|
197
|
+
return { ok: false, reason: 'ORIGIN_DENIED' };
|
|
198
|
+
}
|
|
199
|
+
return { ok: true, principal: { principalId: p.principalId, origin: p.exactOrigin } };
|
|
200
|
+
}
|
|
201
|
+
isKnownOrigin(origin) {
|
|
202
|
+
return PairedAuthority.isValidExtensionOrigin(origin) && this.ledger.isKnownOrigin(origin);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Provisional nonexecuting admission policy (SW-032): the operation must be defined by the trusted resolver
|
|
206
|
+
* as verified `read`, and a stored, unexpired grant must name exactly this principal, project, plugin and
|
|
207
|
+
* operation at effect class `read` with requires_confirmation=true. No effect-class ranking is applied:
|
|
208
|
+
* every other class is denied. The request's own approval flag is never consulted here.
|
|
209
|
+
*/
|
|
210
|
+
authorize(principalId, projectId, pluginId, operationId) {
|
|
211
|
+
return this.authorizeLaunch(principalId, projectId, pluginId, operationId) !== undefined;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* SW-051: the same admission rules as authorize(), evaluated again at launch time, returning the id of one stored grant that
|
|
215
|
+
* satisfies them (for the AuthorizedInvocation) or undefined. A revoked grant, disabled principal, unknown or non-read operation,
|
|
216
|
+
* or a project root that is no longer its own canonical path all deny. This decides nothing about processes or containment.
|
|
217
|
+
*/
|
|
218
|
+
authorizeLaunch(principalId, projectId, pluginId, operationId) {
|
|
219
|
+
const def = this.resolver({ pluginId, operationId });
|
|
220
|
+
if (!def || def.verified !== true || def.effectClass !== 'read')
|
|
221
|
+
return undefined;
|
|
222
|
+
if (!this.ledger.principalIsEnabled(principalId))
|
|
223
|
+
return undefined;
|
|
224
|
+
const root = this.ledger.getProjectRoot(projectId);
|
|
225
|
+
if (!root)
|
|
226
|
+
return undefined;
|
|
227
|
+
try {
|
|
228
|
+
if (!existsSync(root) || !sameCanonical(realpathSync.native(root), root))
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
const nowMs = this.now();
|
|
235
|
+
const hit = this.ledger.findGrants(principalId, projectId, pluginId, operationId).find((g) => Date.parse(g.expiresAt) > nowMs && g.maxEffectClass === 'read' && g.requiresConfirmation === true);
|
|
236
|
+
return hit ? { grantId: hit.grantId } : undefined;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Trusted, in-process-only issuance of a one-time approval proof for a pending run. This is NOT
|
|
240
|
+
* exposed over HTTP and is not evidence of a real user gesture; a future UI channel must call it
|
|
241
|
+
* only after a verified user action.
|
|
242
|
+
*/
|
|
243
|
+
issueLocalApprovalChallenge(input) {
|
|
244
|
+
const run = this.ledger.getRunDetailForPrincipal(input.principalId, input.runId);
|
|
245
|
+
if (!run)
|
|
246
|
+
throw new Error('APPROVAL_RUN_NOT_FOUND');
|
|
247
|
+
if (run.lifecycleState !== 'AWAITING_USER_APPROVAL')
|
|
248
|
+
throw new Error('APPROVAL_RUN_NOT_PENDING');
|
|
249
|
+
if (!this.authorize(run.principalId, run.projectId, run.pluginId, run.operationId)) {
|
|
250
|
+
throw new Error('APPROVAL_NOT_AUTHORIZED');
|
|
251
|
+
}
|
|
252
|
+
const approvalId = `appr.${b64url(24)}`;
|
|
253
|
+
const approvalCode = b64url(32);
|
|
254
|
+
const nowMs = this.now();
|
|
255
|
+
const expiresAt = new Date(nowMs + APPROVAL_CHALLENGE_TTL_MS).toISOString();
|
|
256
|
+
this.ledger.insertApprovalChallenge({
|
|
257
|
+
approvalId, runId: run.runId, principalId: run.principalId, codeSha256: sha256Hex(approvalCode),
|
|
258
|
+
fingerprint: run.fingerprint, expiresAtIso: expiresAt, createdAtIso: new Date(nowMs).toISOString(),
|
|
259
|
+
});
|
|
260
|
+
return { approvalId, approvalCode, expiresAt };
|
|
261
|
+
}
|
|
262
|
+
/** True iff the stored challenge is bound to this run/principal/fingerprint, unexpired, and the code matches. */
|
|
263
|
+
verifyApprovalProof(run, approval, presentedCode, requireUnconsumed) {
|
|
264
|
+
if (approval.runId !== run.runId || approval.principalId !== run.principalId)
|
|
265
|
+
return false;
|
|
266
|
+
if (approval.fingerprint !== run.fingerprint)
|
|
267
|
+
return false;
|
|
268
|
+
if (requireUnconsumed && (approval.consumedAt !== null || Date.parse(approval.expiresAt) <= this.now()))
|
|
269
|
+
return false;
|
|
270
|
+
return digestsEqual(approval.codeSha256, sha256Hex(presentedCode));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=pairedAuthority.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SqliteLedger } from '../storage/sqliteLedger.js';
|
|
2
|
+
export declare const TRUSTED_MODE: "TRUSTED_LOCAL_CLI_PROPOSAL_ONLY";
|
|
3
|
+
export type TrustedCliTarget = {
|
|
4
|
+
principalId: string;
|
|
5
|
+
origin: string;
|
|
6
|
+
projectId: string;
|
|
7
|
+
pluginId: string;
|
|
8
|
+
operationId: string;
|
|
9
|
+
};
|
|
10
|
+
/** C03 consent is projected from the existing immutable C09 event chain. It is
|
|
11
|
+
* not a substitute for operation grants or STRICT_ISOLATED readiness. Restart
|
|
12
|
+
* deliberately expires execution consent; stored proposals remain retrievable. */
|
|
13
|
+
export declare class TrustedCliConsent {
|
|
14
|
+
private readonly ledger;
|
|
15
|
+
private readonly now;
|
|
16
|
+
private readonly epoch;
|
|
17
|
+
constructor(ledger: SqliteLedger, now?: () => number);
|
|
18
|
+
private scope;
|
|
19
|
+
status(t: TrustedCliTarget): {
|
|
20
|
+
mode: "TRUSTED_LOCAL_CLI_PROPOSAL_ONLY";
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
scopeKey: string;
|
|
23
|
+
challenge: string;
|
|
24
|
+
consentId: number | null;
|
|
25
|
+
warning: string;
|
|
26
|
+
warningVersion: string;
|
|
27
|
+
cliSha256: string;
|
|
28
|
+
profile: string;
|
|
29
|
+
expiresAt: number | null;
|
|
30
|
+
};
|
|
31
|
+
decide(t: TrustedCliTarget, action: 'accept' | 'revoke', challenge?: string, warningVersion?: string): {
|
|
32
|
+
mode: "TRUSTED_LOCAL_CLI_PROPOSAL_ONLY";
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
scopeKey: string;
|
|
35
|
+
challenge: string;
|
|
36
|
+
consentId: number | null;
|
|
37
|
+
warning: string;
|
|
38
|
+
warningVersion: string;
|
|
39
|
+
cliSha256: string;
|
|
40
|
+
profile: string;
|
|
41
|
+
expiresAt: number | null;
|
|
42
|
+
};
|
|
43
|
+
bind(t: TrustedCliTarget, runId: string): void;
|
|
44
|
+
authorize(runId: string): boolean;
|
|
45
|
+
}
|
|
46
|
+
export declare function isTrustedProposalRun(ledger: SqliteLedger, runId: string): boolean;
|
|
47
|
+
//# sourceMappingURL=trustedCliConsent.d.ts.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { TRUSTED_CLI_WARNING, TRUSTED_CLI_WARNING_VERSION } from '../../../../packages/contracts/dist/index.js';
|
|
3
|
+
import { CodingAuthority } from './codingAuthority.js';
|
|
4
|
+
export const TRUSTED_MODE = 'TRUSTED_LOCAL_CLI_PROPOSAL_ONLY';
|
|
5
|
+
/** C03 consent is projected from the existing immutable C09 event chain. It is
|
|
6
|
+
* not a substitute for operation grants or STRICT_ISOLATED readiness. Restart
|
|
7
|
+
* deliberately expires execution consent; stored proposals remain retrievable. */
|
|
8
|
+
export class TrustedCliConsent {
|
|
9
|
+
ledger;
|
|
10
|
+
now;
|
|
11
|
+
epoch = randomUUID();
|
|
12
|
+
constructor(ledger, now = Date.now) {
|
|
13
|
+
this.ledger = ledger;
|
|
14
|
+
this.now = now;
|
|
15
|
+
}
|
|
16
|
+
scope(t) {
|
|
17
|
+
const p = this.ledger.listProvisionedOperations().find(p => p.pluginId === t.pluginId && p.operationId === t.operationId && p.enabled);
|
|
18
|
+
const root = this.ledger.getProjectRoot(t.projectId);
|
|
19
|
+
if (!p || !root || !this.ledger.principalIsEnabled(t.principalId) || !p.profileId.startsWith('codex-'))
|
|
20
|
+
throw new Error('TRUSTED_CLI_TARGET_INVALID');
|
|
21
|
+
const identity = { principalId: t.principalId, origin: t.origin, projectId: t.projectId, pluginId: t.pluginId, operationId: t.operationId, root, cli: p.executableSha256, manifest: p.manifestFingerprint, profile: p.profileId, epoch: this.epoch, warningVersion: TRUSTED_CLI_WARNING_VERSION };
|
|
22
|
+
return { identity, key: createHash('sha256').update(JSON.stringify(identity)).digest('hex') };
|
|
23
|
+
}
|
|
24
|
+
status(t) {
|
|
25
|
+
if (!this.ledger.verifyCodingChain().ok)
|
|
26
|
+
throw new Error('AUDIT_UNAVAILABLE');
|
|
27
|
+
const s = this.scope(t), last = this.ledger.readCodingEvents({ subjectId: 'trust.' + s.key }).pop();
|
|
28
|
+
const d = last ? JSON.parse(last.detailJson) : undefined;
|
|
29
|
+
const challenge = createHash('sha256').update(s.key + ':' + (last?.recordSha256 ?? 'INITIAL') + ':' + Math.floor(this.now() / 120_000)).digest('hex');
|
|
30
|
+
return { mode: TRUSTED_MODE, enabled: last?.event === 'TRUSTED_CLI_CONSENT_ACCEPTED' && Number(d?.expiresAt) > this.now(), scopeKey: s.key, challenge,
|
|
31
|
+
consentId: last?.seq ?? null, warning: TRUSTED_CLI_WARNING, warningVersion: TRUSTED_CLI_WARNING_VERSION, cliSha256: s.identity.cli, profile: s.identity.profile, expiresAt: d?.expiresAt ?? null };
|
|
32
|
+
}
|
|
33
|
+
decide(t, action, challenge, warningVersion) {
|
|
34
|
+
const s = this.status(t);
|
|
35
|
+
if (challenge !== s.challenge || warningVersion !== TRUSTED_CLI_WARNING_VERSION)
|
|
36
|
+
throw new Error('TRUSTED_CLI_CONSENT_MISMATCH');
|
|
37
|
+
if (action === 'accept' && s.enabled)
|
|
38
|
+
return s;
|
|
39
|
+
this.ledger.appendCodingEvent({ at: new Date(this.now()).toISOString(), runId: 'consent.' + s.scopeKey, subjectKind: 'GRANT', subjectId: 'trust.' + s.scopeKey,
|
|
40
|
+
event: action === 'accept' ? 'TRUSTED_CLI_CONSENT_ACCEPTED' : 'TRUSTED_CLI_CONSENT_REVOKED', decision: action === 'accept' ? 'ALLOWED' : 'DENIED',
|
|
41
|
+
detail: { mode: TRUSTED_MODE, expiresAt: action === 'accept' ? this.now() + 600_000 : this.now(), cli: s.cliSha256, warningVersion: TRUSTED_CLI_WARNING_VERSION } });
|
|
42
|
+
if (action === 'revoke')
|
|
43
|
+
for (const e of this.ledger.readCodingEvents()) {
|
|
44
|
+
if (e.event === 'MODEL_MODE_BOUND' && JSON.parse(e.detailJson).scopeKey === s.scopeKey)
|
|
45
|
+
new CodingAuthority({ ledger: this.ledger, now: this.now }).revokeRun(e.runId);
|
|
46
|
+
}
|
|
47
|
+
return this.status(t);
|
|
48
|
+
}
|
|
49
|
+
bind(t, runId) {
|
|
50
|
+
const s = this.status(t);
|
|
51
|
+
if (!s.enabled)
|
|
52
|
+
throw new Error('TRUSTED_CLI_CONSENT_REQUIRED');
|
|
53
|
+
const run = this.ledger.getRunDetailForPrincipal(t.principalId, runId);
|
|
54
|
+
if (!run || run.projectId !== t.projectId || run.pluginId !== t.pluginId || run.operationId !== t.operationId)
|
|
55
|
+
throw new Error('TRUSTED_CLI_TARGET_INVALID');
|
|
56
|
+
const previous = this.ledger.readCodingEvents({ runId }).find(e => e.event === 'MODEL_MODE_BOUND');
|
|
57
|
+
if (previous) {
|
|
58
|
+
if (JSON.parse(previous.detailJson).consentId !== s.consentId || JSON.parse(previous.detailJson).scopeKey !== s.scopeKey)
|
|
59
|
+
throw new Error('TRUSTED_CLI_CONSENT_MISMATCH');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
this.ledger.appendCodingEvent({ at: new Date(this.now()).toISOString(), runId, subjectKind: 'GRANT', subjectId: runId, event: 'MODEL_MODE_BOUND', decision: 'ALLOWED',
|
|
63
|
+
detail: { mode: TRUSTED_MODE, scopeKey: s.scopeKey, consentId: s.consentId, principalId: t.principalId, origin: t.origin, projectId: t.projectId, pluginId: t.pluginId, operationId: t.operationId, cli: s.cliSha256 } });
|
|
64
|
+
}
|
|
65
|
+
authorize(runId) {
|
|
66
|
+
try {
|
|
67
|
+
if (!this.ledger.verifyCodingChain().ok)
|
|
68
|
+
return false;
|
|
69
|
+
const e = this.ledger.readCodingEvents({ runId }).find(e => e.event === 'MODEL_MODE_BOUND');
|
|
70
|
+
if (!e)
|
|
71
|
+
return false;
|
|
72
|
+
const d = JSON.parse(e.detailJson);
|
|
73
|
+
const s = this.status(d);
|
|
74
|
+
return d.mode === TRUSTED_MODE && s.enabled && s.scopeKey === d.scopeKey && s.consentId === d.consentId;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
export function isTrustedProposalRun(ledger, runId) {
|
|
82
|
+
return ledger.readCodingEvents({ runId }).some(e => e.event === 'MODEL_MODE_BOUND' && JSON.parse(e.detailJson).mode === TRUSTED_MODE);
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=trustedCliConsent.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { CpProposal } from '../context/changeProposal.js';
|
|
2
|
+
export type JournalState = 'PREPARED' | 'APPLYING' | 'APPLIED' | 'ROLLED_BACK' | 'ROLLBACK_INCOMPLETE';
|
|
3
|
+
export type ApplyResult = {
|
|
4
|
+
readonly ok: true;
|
|
5
|
+
readonly state: 'APPLIED';
|
|
6
|
+
readonly changed: readonly {
|
|
7
|
+
path: string;
|
|
8
|
+
sha256: string | null;
|
|
9
|
+
}[];
|
|
10
|
+
} | {
|
|
11
|
+
readonly ok: false;
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly state: 'ROLLED_BACK' | 'ROLLBACK_INCOMPLETE' | 'NOT_STARTED';
|
|
14
|
+
readonly detail: string;
|
|
15
|
+
readonly unrestored: readonly string[];
|
|
16
|
+
readonly ioFailure?: AtomicFailure;
|
|
17
|
+
readonly rollbackIoFailure?: AtomicFailure;
|
|
18
|
+
};
|
|
19
|
+
interface AtomicFailure {
|
|
20
|
+
stage: 'OPEN' | 'WRITE' | 'FLUSH' | 'CLOSE' | 'REPLACE';
|
|
21
|
+
code: string;
|
|
22
|
+
syscall: string;
|
|
23
|
+
errno?: number;
|
|
24
|
+
targetSha256: string;
|
|
25
|
+
}
|
|
26
|
+
export declare function persistenceFailure(e: unknown): AtomicFailure | undefined;
|
|
27
|
+
/** Thrown by fault injection to emulate a process death: the applier deliberately does NOT clean up after it, exactly like a killed process. */
|
|
28
|
+
export declare class SimulatedCrash extends Error {
|
|
29
|
+
readonly at: string;
|
|
30
|
+
constructor(at: string);
|
|
31
|
+
}
|
|
32
|
+
export interface ApplyFaults {
|
|
33
|
+
before?: (stage: string, index: number, atomic?: {
|
|
34
|
+
targetFile: string;
|
|
35
|
+
tempFile: string;
|
|
36
|
+
}) => void;
|
|
37
|
+
failWith?: (stage: string, index: number) => string | undefined;
|
|
38
|
+
}
|
|
39
|
+
export declare function applyProposal(i: {
|
|
40
|
+
workspaceRoot: string;
|
|
41
|
+
journalDir: string;
|
|
42
|
+
proposalId: string;
|
|
43
|
+
proposalDigest: string;
|
|
44
|
+
proposal: CpProposal;
|
|
45
|
+
faults?: ApplyFaults;
|
|
46
|
+
}): ApplyResult;
|
|
47
|
+
/** After a daemon crash: an unfinished journal is rolled back (never re-applied) and the outcome is reported. A finished journal is reported as it is. */
|
|
48
|
+
export declare function recoverJournal(i: {
|
|
49
|
+
workspaceRoot: string;
|
|
50
|
+
journalDir: string;
|
|
51
|
+
}): {
|
|
52
|
+
found: boolean;
|
|
53
|
+
priorState?: JournalState;
|
|
54
|
+
state?: JournalState;
|
|
55
|
+
unrestored?: readonly string[];
|
|
56
|
+
};
|
|
57
|
+
export declare const __journalFileForTests: (dir: string) => string;
|
|
58
|
+
export {};
|
|
59
|
+
//# sourceMappingURL=changeApplier.d.ts.map
|