@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,293 @@
|
|
|
1
|
+
import { OperationIdSchema, PluginIdSchema, RunIdSchema } from '../../../../packages/contracts/dist/index.js';
|
|
2
|
+
export const MAX_LINE_BYTES = 256;
|
|
3
|
+
export const MAX_QUEUED_LINES = 5;
|
|
4
|
+
const ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
5
|
+
const EXTENSION_ID = /^[a-p]{32}$/;
|
|
6
|
+
const LINE = /^[\x21-\x7e]+( [\x21-\x7e]+)*$/; // printable ASCII, single spaces, no control or escape characters
|
|
7
|
+
const SAFE_FIELD = /^[A-Za-z0-9._:+-]{1,200}$/;
|
|
8
|
+
const ARITY = { help: [0, 0], pair: [1, 1], grant: [3, 3], 'grant-run-click': [3, 3], revoke: [3, 3], approve: [1, 1], quit: [0, 0], provision: [4, 5], provisioned: [0, 0], disable: [2, 2], diag: [0, 2] };
|
|
9
|
+
/** An absolute Windows path with no spaces or quotes (the console line language is single-spaced printable ASCII). */
|
|
10
|
+
const PATH_FIELD = /^[A-Za-z]:\\[A-Za-z0-9._\\+@~#$%&()=,;-]{1,230}$/;
|
|
11
|
+
const PROFILE_ID = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
12
|
+
const idOk = (v) => ID.test(v);
|
|
13
|
+
export function createOperatorConsole(options) {
|
|
14
|
+
const { input, output, actions } = options;
|
|
15
|
+
let running = false;
|
|
16
|
+
let closed = false;
|
|
17
|
+
let finish;
|
|
18
|
+
let detach;
|
|
19
|
+
const write = (text) => {
|
|
20
|
+
try {
|
|
21
|
+
output.write(`${text}\n`);
|
|
22
|
+
}
|
|
23
|
+
catch { /* a closed terminal must not crash the daemon */ }
|
|
24
|
+
};
|
|
25
|
+
const fieldsOk = (...v) => v.every((x) => typeof x === 'string' && SAFE_FIELD.test(x));
|
|
26
|
+
function codeOf(err) {
|
|
27
|
+
const msg = err instanceof Error ? err.message : '';
|
|
28
|
+
const m = /^[A-Z][A-Z0-9_]{2,60}/.exec(msg);
|
|
29
|
+
return m ? m[0] : 'ACTION_FAILED';
|
|
30
|
+
}
|
|
31
|
+
function handle(line) {
|
|
32
|
+
const tokens = line.split(' ');
|
|
33
|
+
const cmd = tokens[0];
|
|
34
|
+
if (!Object.prototype.hasOwnProperty.call(ARITY, cmd)) {
|
|
35
|
+
write('ERR UNKNOWN_COMMAND');
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const [minArgs, maxArgs] = ARITY[cmd];
|
|
39
|
+
if (tokens.length - 1 < minArgs || tokens.length - 1 > maxArgs) {
|
|
40
|
+
write('ERR BAD_ARITY');
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const [, a, b, c, d, e] = tokens;
|
|
44
|
+
try {
|
|
45
|
+
switch (cmd) {
|
|
46
|
+
case 'help':
|
|
47
|
+
write('COMMANDS help | pair <extension-id> | grant <principal-id> <plugin-id> <operation-id> | grant-run-click <principal-id> <plugin-id> <operation-id> | revoke <principal-id> <plugin-id> <operation-id> | approve <run-id> | provision <plugin-id> <operation-id> <profile-id> <exe-path> [<code-path>] | provisioned | disable <plugin-id> <operation-id> | diag [count] [correlation-id] | quit');
|
|
48
|
+
return undefined;
|
|
49
|
+
case 'provision': {
|
|
50
|
+
if (!actions.provisionOperation) {
|
|
51
|
+
write('ERR NOT_AVAILABLE');
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
// a path may contain spaces only as the exact three-character sequence %20 (the line language is single-spaced); any other % is refused
|
|
55
|
+
const decode = (s) => (/%(?!20)/.test(s) ? undefined : s.split('%20').join(' '));
|
|
56
|
+
const exe = decode(d);
|
|
57
|
+
const code = e === undefined ? undefined : decode(e);
|
|
58
|
+
if (!idOk(a) || !idOk(b) || !PluginIdSchema.safeParse(a).success || !OperationIdSchema.safeParse(b).success || !PROFILE_ID.test(c) || !PATH_FIELD.test(d) || (e !== undefined && !PATH_FIELD.test(e))
|
|
59
|
+
|| exe === undefined || (e !== undefined && code === undefined) || exe.includes('..') || (code ?? '').includes('..')) {
|
|
60
|
+
write('ERR BAD_ARGUMENT');
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
actions.provisionOperation({ pluginId: a, operationId: b, profileId: c, executablePath: exe, ...(code !== undefined ? { codeInputPath: code } : {}) }).then((r) => write(`PROVISION OK exe-sha256=${r.executableSha256} manifest=${r.manifestFingerprint.slice(0, 16)} (enabled; grants and per-run approval are still required)`), (err) => write(`PROVISION ERR ${codeOf(err)}`));
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
case 'provisioned': {
|
|
67
|
+
if (!actions.listProvisioned) {
|
|
68
|
+
write('ERR NOT_AVAILABLE');
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const list = actions.listProvisioned();
|
|
72
|
+
for (const r of list)
|
|
73
|
+
write(`PROVISIONED ${r.pluginId} ${r.operationId} profile=${r.profileId} enabled=${r.enabled ? 1 : 0} exe-sha256=${r.executableSha256.slice(0, 16)}${r.disabledReason ? ` reason=${r.disabledReason}` : ''}`);
|
|
74
|
+
write(`PROVISIONED COUNT=${list.length}`);
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
case 'disable': {
|
|
78
|
+
if (!actions.disableProvisioned) {
|
|
79
|
+
write('ERR NOT_AVAILABLE');
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
if (!idOk(a) || !idOk(b)) {
|
|
83
|
+
write('ERR BAD_ARGUMENT');
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
write(actions.disableProvisioned(a, b) ? 'DISABLE OK (one-way: provision again under a new plugin id after restart)' : 'ERR NOT_FOUND');
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
case 'diag': {
|
|
90
|
+
if (!actions.recentDiagnostics) {
|
|
91
|
+
write('ERR NOT_AVAILABLE');
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const n = a === undefined ? 20 : /^[0-9]{1,3}$/.test(a) ? Number(a) : -1;
|
|
95
|
+
if (n < 1 || n > 200 || (b !== undefined && !/^corr\.[A-Za-z0-9_-]{8,40}$/.test(b))) {
|
|
96
|
+
write('ERR BAD_ARGUMENT');
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const lines = actions.recentDiagnostics(n, b);
|
|
100
|
+
for (const l of lines)
|
|
101
|
+
write(`DIAG ${l}`);
|
|
102
|
+
write(`DIAG COUNT=${lines.length}`);
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
case 'quit':
|
|
106
|
+
write('BYE');
|
|
107
|
+
return 'QUIT';
|
|
108
|
+
case 'pair': {
|
|
109
|
+
if (!EXTENSION_ID.test(a)) {
|
|
110
|
+
write('ERR BAD_ARGUMENT');
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
const r = actions.issuePairingCodeForExtension(a);
|
|
114
|
+
if (!fieldsOk(r.challengeId, r.code, r.expiresAt)) {
|
|
115
|
+
write('ERR ACTION_FAILED');
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
write(`PAIR challenge-id=${r.challengeId} code=${r.code} expires=${r.expiresAt} (shown once)`);
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
case 'grant-run-click': {
|
|
122
|
+
if (!actions.grantRunClickOperation) {
|
|
123
|
+
write('ERR NOT_AVAILABLE');
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
if (![a, b, c].every(idOk) || !PluginIdSchema.safeParse(b).success || !OperationIdSchema.safeParse(c).success) {
|
|
127
|
+
write('ERR BAD_ARGUMENT');
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
const r = actions.grantRunClickOperation(a, b, c);
|
|
131
|
+
if (!fieldsOk(r.expiresAt)) {
|
|
132
|
+
write('ERR ACTION_FAILED');
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
write(`GRANT OK consent=RUN_CLICK expires=${r.expiresAt}`);
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
case 'grant':
|
|
139
|
+
case 'revoke': {
|
|
140
|
+
if (![a, b, c].every(idOk) || !PluginIdSchema.safeParse(b).success || !OperationIdSchema.safeParse(c).success) {
|
|
141
|
+
write('ERR BAD_ARGUMENT');
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
if (cmd === 'grant') {
|
|
145
|
+
const r = actions.grantVerifiedOperation(a, b, c);
|
|
146
|
+
if (!fieldsOk(r.expiresAt)) {
|
|
147
|
+
write('ERR ACTION_FAILED');
|
|
148
|
+
return undefined;
|
|
149
|
+
}
|
|
150
|
+
write(`GRANT OK expires=${r.expiresAt}`);
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
const r = actions.revokeOperationGrant(a, b, c);
|
|
154
|
+
if (!Number.isInteger(r.revoked) || r.revoked < 0 || r.revoked > 1000) {
|
|
155
|
+
write('ERR ACTION_FAILED');
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
write(`REVOKE OK count=${r.revoked}`);
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
case 'approve': {
|
|
163
|
+
if (!idOk(a) || !RunIdSchema.safeParse(a).success) {
|
|
164
|
+
write('ERR BAD_ARGUMENT');
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
const r = actions.issuePendingRunApproval(a);
|
|
168
|
+
if (!fieldsOk(r.approvalId, r.approvalCode, r.expiresAt)) {
|
|
169
|
+
write('ERR ACTION_FAILED');
|
|
170
|
+
return undefined;
|
|
171
|
+
}
|
|
172
|
+
write(`APPROVE approval-id=${r.approvalId} code=${r.approvalCode} expires=${r.expiresAt} (shown once)`);
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
default:
|
|
176
|
+
write('ERR UNKNOWN_COMMAND');
|
|
177
|
+
return undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
write(`ERR ${codeOf(err)}`);
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function run() {
|
|
186
|
+
if (closed || running)
|
|
187
|
+
return Promise.resolve('CLOSED');
|
|
188
|
+
const attended = input?.isTTY === true && output?.isTTY === true;
|
|
189
|
+
if (!attended && options.allowInjectedTestStreams !== true)
|
|
190
|
+
return Promise.resolve('DENIED_NOT_ATTENDED');
|
|
191
|
+
running = true;
|
|
192
|
+
return new Promise((resolve) => {
|
|
193
|
+
let buf = Buffer.alloc(0);
|
|
194
|
+
let discarding = false;
|
|
195
|
+
let ended = false;
|
|
196
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
197
|
+
const done = (r) => {
|
|
198
|
+
if (ended)
|
|
199
|
+
return;
|
|
200
|
+
ended = true;
|
|
201
|
+
detach?.();
|
|
202
|
+
running = false;
|
|
203
|
+
resolve(r);
|
|
204
|
+
};
|
|
205
|
+
finish = done;
|
|
206
|
+
const onData = (chunk) => {
|
|
207
|
+
if (ended)
|
|
208
|
+
return;
|
|
209
|
+
buf = Buffer.concat([buf, typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk]);
|
|
210
|
+
const pending = [];
|
|
211
|
+
let overflowReported = false;
|
|
212
|
+
for (;;) {
|
|
213
|
+
const nl = buf.indexOf(0x0a);
|
|
214
|
+
if (nl < 0) {
|
|
215
|
+
if (buf.length > MAX_LINE_BYTES) { // an over-long line without a terminator: drop it, keep memory bounded
|
|
216
|
+
buf = Buffer.alloc(0);
|
|
217
|
+
if (!discarding)
|
|
218
|
+
write('ERR LINE_TOO_LONG');
|
|
219
|
+
discarding = true;
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
const lineBytes = buf.subarray(0, nl);
|
|
224
|
+
buf = buf.subarray(nl + 1);
|
|
225
|
+
if (discarding) {
|
|
226
|
+
discarding = false;
|
|
227
|
+
continue;
|
|
228
|
+
} // tail of an over-long line
|
|
229
|
+
if (lineBytes.length > MAX_LINE_BYTES) {
|
|
230
|
+
write('ERR LINE_TOO_LONG');
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (pending.length >= MAX_QUEUED_LINES) {
|
|
234
|
+
if (!overflowReported) {
|
|
235
|
+
write('ERR INPUT_OVERFLOW');
|
|
236
|
+
overflowReported = true;
|
|
237
|
+
}
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
pending.push(Buffer.from(lineBytes));
|
|
241
|
+
}
|
|
242
|
+
for (const raw of pending) {
|
|
243
|
+
let text;
|
|
244
|
+
try {
|
|
245
|
+
text = decoder.decode(raw);
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
write('ERR INVALID_INPUT');
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (text.endsWith('\r'))
|
|
252
|
+
text = text.slice(0, -1);
|
|
253
|
+
if (text.length === 0)
|
|
254
|
+
continue;
|
|
255
|
+
if (!LINE.test(text)) {
|
|
256
|
+
write('ERR INVALID_INPUT');
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (handle(text) === 'QUIT') {
|
|
260
|
+
done('QUIT');
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const onEnd = () => done('EOF');
|
|
266
|
+
const onError = () => done('CLOSED');
|
|
267
|
+
input.on('data', onData);
|
|
268
|
+
input.on('end', onEnd);
|
|
269
|
+
input.on('error', onError);
|
|
270
|
+
detach = () => {
|
|
271
|
+
input.removeListener('data', onData);
|
|
272
|
+
input.removeListener('end', onEnd);
|
|
273
|
+
input.removeListener('error', onError);
|
|
274
|
+
};
|
|
275
|
+
write(attended ? 'OPERATOR_CONSOLE ready (attended terminal). Type help.' : 'OPERATOR_CONSOLE TEST_OPERATOR_INPUT (injected streams; not a human gesture).');
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
run,
|
|
280
|
+
close() {
|
|
281
|
+
closed = true;
|
|
282
|
+
finish?.('CLOSED');
|
|
283
|
+
detach?.();
|
|
284
|
+
},
|
|
285
|
+
notify(line) {
|
|
286
|
+
if (!running)
|
|
287
|
+
return;
|
|
288
|
+
const safe = typeof line === 'string' && LINE.test(line) && line.length <= 200 ? line : 'NOTICE';
|
|
289
|
+
write(safe);
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=operatorConsole.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows private data root for the production SQLite ledger (B02-E).
|
|
3
|
+
*
|
|
4
|
+
* Contract: the data root must be a canonical, non-reparse-point subdirectory of <projectRoot>\.switchyard-data.
|
|
5
|
+
* A directory THIS call creates is hardened (protected DACL, only the current user's SID and LOCAL SYSTEM,
|
|
6
|
+
* full control, inherited by new children). An already existing directory is only VERIFIED, never rewritten.
|
|
7
|
+
* If the exact DACL cannot be established or read back, startup fails closed with
|
|
8
|
+
* PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED.
|
|
9
|
+
*
|
|
10
|
+
* What this proves: the DACL contains exactly {current user SID, S-1-5-18} and is not inherited from a parent.
|
|
11
|
+
* What it does NOT prove: isolation from a process running under the same user SID, from an elevated or
|
|
12
|
+
* backup-privileged administrator, or effective access for the CodexSandboxUsers token (no such token was
|
|
13
|
+
* exercised). Those remain NOT_VERIFIED. Windows-native tooling is invoked with shell:false and windowsHide:true;
|
|
14
|
+
* paths reach PowerShell through environment variables, never through command text.
|
|
15
|
+
*/
|
|
16
|
+
export type PrivateDataRootErrorCode = 'DATA_ROOT_INVALID' | 'PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED';
|
|
17
|
+
/** Sanitized: only a fixed code, never a path, SID or ACL text. */
|
|
18
|
+
export declare class PrivateDataRootError extends Error {
|
|
19
|
+
readonly code: PrivateDataRootErrorCode;
|
|
20
|
+
constructor(code: PrivateDataRootErrorCode);
|
|
21
|
+
}
|
|
22
|
+
export interface PrivateDataRootResult {
|
|
23
|
+
verified: true;
|
|
24
|
+
canonicalDataRoot: string;
|
|
25
|
+
verification: {
|
|
26
|
+
created: boolean;
|
|
27
|
+
method: 'DACL_EXACT_SET_USER_AND_SYSTEM';
|
|
28
|
+
/** Always NOT_VERIFIED: no restricted or sandbox-group token was exercised. */
|
|
29
|
+
effectiveTokenIsolation: 'NOT_VERIFIED';
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare function assertOrInitializePrivateDataRoot(input: {
|
|
33
|
+
projectRoot: string;
|
|
34
|
+
dataRoot: string;
|
|
35
|
+
}): PrivateDataRootResult;
|
|
36
|
+
/** Verifies the directory and every file in it (database, WAL, SHM) after SQLite has created them. */
|
|
37
|
+
export declare function verifyPrivateDataFiles(canonicalDataRoot: string): void;
|
|
38
|
+
//# sourceMappingURL=privateDataRoot.d.ts.map
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readdirSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { isAbsolute, join, normalize, sep } from 'node:path';
|
|
4
|
+
/** Sanitized: only a fixed code, never a path, SID or ACL text. */
|
|
5
|
+
export class PrivateDataRootError extends Error {
|
|
6
|
+
code;
|
|
7
|
+
constructor(code) {
|
|
8
|
+
super(code);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.name = 'PrivateDataRootError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const SYSTEM_SID = 'S-1-5-18';
|
|
14
|
+
const same = (a, b) => (process.platform === 'win32' ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
15
|
+
const trimSep = (p) => p.replace(new RegExp(`\\${sep}+$`), '');
|
|
16
|
+
function fail(code) {
|
|
17
|
+
throw new PrivateDataRootError(code);
|
|
18
|
+
}
|
|
19
|
+
/** Existing, real (non-link, non-junction, no short-name alias) directory; returns its canonical path. */
|
|
20
|
+
function realDir(p) {
|
|
21
|
+
try {
|
|
22
|
+
const st = lstatSync(p);
|
|
23
|
+
if (st.isSymbolicLink() || !st.isDirectory())
|
|
24
|
+
fail('DATA_ROOT_INVALID');
|
|
25
|
+
const real = trimSep(realpathSync.native(p));
|
|
26
|
+
if (!same(real, trimSep(normalize(p))))
|
|
27
|
+
fail('DATA_ROOT_INVALID');
|
|
28
|
+
return real;
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
if (e instanceof PrivateDataRootError)
|
|
32
|
+
throw e;
|
|
33
|
+
return fail('DATA_ROOT_INVALID');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const POWERSHELL = () => {
|
|
37
|
+
const sys = process.env.SystemRoot ?? 'C:\\Windows';
|
|
38
|
+
const abs = join(sys, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
|
|
39
|
+
return existsSync(abs) ? abs : 'powershell.exe';
|
|
40
|
+
};
|
|
41
|
+
const PS_SCRIPT = `
|
|
42
|
+
$ErrorActionPreference = 'Stop'
|
|
43
|
+
$user = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
|
|
44
|
+
if ($env:MC_OP -eq 'init') {
|
|
45
|
+
$p = $env:MC_PATH
|
|
46
|
+
$acl = Get-Acl -LiteralPath $p
|
|
47
|
+
$acl.SetAccessRuleProtection($true, $false)
|
|
48
|
+
foreach ($r in @($acl.Access)) { [void]$acl.RemoveAccessRule($r) }
|
|
49
|
+
$inh = [System.Security.AccessControl.InheritanceFlags]'ContainerInherit,ObjectInherit'
|
|
50
|
+
$prop = [System.Security.AccessControl.PropagationFlags]::None
|
|
51
|
+
foreach ($sidText in @($user, 'S-1-5-18')) {
|
|
52
|
+
$sid = New-Object System.Security.Principal.SecurityIdentifier($sidText)
|
|
53
|
+
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($sid, 'FullControl', $inh, $prop, 'Allow')
|
|
54
|
+
$acl.AddAccessRule($rule)
|
|
55
|
+
}
|
|
56
|
+
Set-Acl -LiteralPath $p -AclObject $acl
|
|
57
|
+
}
|
|
58
|
+
$items = @()
|
|
59
|
+
foreach ($p in ($env:MC_PATHS -split '\\|')) {
|
|
60
|
+
if ($p.Length -gt 0) {
|
|
61
|
+
$acl = Get-Acl -LiteralPath $p
|
|
62
|
+
$raw = New-Object System.Security.AccessControl.RawSecurityDescriptor($acl.GetSecurityDescriptorBinaryForm(), 0)
|
|
63
|
+
$index = 0
|
|
64
|
+
# SDDL can abbreviate the local administrator as LA. Preserve each native
|
|
65
|
+
# ACE's flags/rights/type, but compare its actual SID, never an alias allowlist.
|
|
66
|
+
$sddl = [regex]::Replace($acl.Sddl, '\\(([^()]*)\\)', {
|
|
67
|
+
param($match)
|
|
68
|
+
$fields = $match.Groups[1].Value.Split(';')
|
|
69
|
+
if ($fields.Length -ne 6 -or $index -ge $raw.DiscretionaryAcl.Count) { throw 'ACL_FORMAT' }
|
|
70
|
+
$fields[5] = $raw.DiscretionaryAcl[$index].SecurityIdentifier.Value
|
|
71
|
+
$script:index++
|
|
72
|
+
'(' + ($fields -join ';') + ')'
|
|
73
|
+
})
|
|
74
|
+
if ($index -ne $raw.DiscretionaryAcl.Count) { throw 'ACL_FORMAT' }
|
|
75
|
+
$items += [pscustomobject]@{ path = $p; sddl = $sddl }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
[pscustomobject]@{ user = $user; items = $items } | ConvertTo-Json -Compress -Depth 4
|
|
79
|
+
`;
|
|
80
|
+
function powershell(op, paths) {
|
|
81
|
+
if (process.platform !== 'win32')
|
|
82
|
+
fail('PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED');
|
|
83
|
+
let out;
|
|
84
|
+
try {
|
|
85
|
+
out = execFileSync(POWERSHELL(), ['-NoProfile', '-NonInteractive', '-Command', PS_SCRIPT], {
|
|
86
|
+
// Windows PowerShell 5.1 must load its own in-box modules, even when the
|
|
87
|
+
// parent is PowerShell 7. Do not search inherited/user module locations.
|
|
88
|
+
env: { ...process.env, PSModulePath: join(process.env.SystemRoot ?? 'C:\\Windows', 'System32', 'WindowsPowerShell', 'v1.0', 'Modules'), MC_OP: op, MC_PATH: paths[0], MC_PATHS: paths.join('|') },
|
|
89
|
+
windowsHide: true,
|
|
90
|
+
shell: false,
|
|
91
|
+
timeout: 30_000,
|
|
92
|
+
maxBuffer: 64 * 1024,
|
|
93
|
+
encoding: 'utf8',
|
|
94
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
95
|
+
});
|
|
96
|
+
const parsed = JSON.parse(out.trim());
|
|
97
|
+
if (typeof parsed.user !== 'string' || !/^S-1-5-21(-\d+)+$/.test(parsed.user))
|
|
98
|
+
fail('PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED');
|
|
99
|
+
const items = Array.isArray(parsed.items) ? parsed.items : [parsed.items];
|
|
100
|
+
return { user: parsed.user, items };
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
if (e instanceof PrivateDataRootError)
|
|
104
|
+
throw e;
|
|
105
|
+
return fail('PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/** Parses the DACL section of an SDDL string. Returns undefined for anything it does not fully understand. */
|
|
109
|
+
function parseDacl(sddl) {
|
|
110
|
+
const m = /D:([A-Z]*)((?:\([^)]*\))*)/.exec(sddl);
|
|
111
|
+
if (!m)
|
|
112
|
+
return undefined;
|
|
113
|
+
const aces = [];
|
|
114
|
+
for (const a of m[2].matchAll(/\(([^)]*)\)/g)) {
|
|
115
|
+
const f = a[1].split(';');
|
|
116
|
+
if (f.length !== 6)
|
|
117
|
+
return undefined;
|
|
118
|
+
aces.push({ type: f[0], flags: f[1], rights: f[2], sid: f[5] === 'SY' ? SYSTEM_SID : f[5] });
|
|
119
|
+
}
|
|
120
|
+
return { protectedDacl: m[1].includes('P'), aces };
|
|
121
|
+
}
|
|
122
|
+
const FULL_CONTROL = new Set(['FA', '0x1f01ff']);
|
|
123
|
+
/** Directory rule: protected (nothing inherited) and exactly {user, SYSTEM} with full control. */
|
|
124
|
+
function directoryIsPrivate(sddl, user) {
|
|
125
|
+
const d = parseDacl(sddl);
|
|
126
|
+
if (!d || !d.protectedDacl || d.aces.length === 0)
|
|
127
|
+
return false;
|
|
128
|
+
const seen = new Set();
|
|
129
|
+
for (const ace of d.aces) {
|
|
130
|
+
if (ace.type !== 'A' || ace.flags.includes('ID'))
|
|
131
|
+
return false;
|
|
132
|
+
if (ace.sid !== user && ace.sid !== SYSTEM_SID)
|
|
133
|
+
return false;
|
|
134
|
+
if (!FULL_CONTROL.has(ace.rights))
|
|
135
|
+
return false;
|
|
136
|
+
seen.add(ace.sid);
|
|
137
|
+
}
|
|
138
|
+
return seen.has(user) && seen.has(SYSTEM_SID);
|
|
139
|
+
}
|
|
140
|
+
/** File rule: only allow ACEs for {user, SYSTEM}; inheritance from the private directory is expected. */
|
|
141
|
+
function fileIsPrivate(sddl, user) {
|
|
142
|
+
const d = parseDacl(sddl);
|
|
143
|
+
if (!d || d.aces.length === 0)
|
|
144
|
+
return false;
|
|
145
|
+
return d.aces.every((ace) => ace.type === 'A' && (ace.sid === user || ace.sid === SYSTEM_SID));
|
|
146
|
+
}
|
|
147
|
+
export function assertOrInitializePrivateDataRoot(input) {
|
|
148
|
+
const { projectRoot, dataRoot } = input ?? {};
|
|
149
|
+
if (typeof projectRoot !== 'string' || !isAbsolute(projectRoot) || typeof dataRoot !== 'string' || !isAbsolute(dataRoot))
|
|
150
|
+
fail('DATA_ROOT_INVALID');
|
|
151
|
+
if (projectRoot.split(/[\\/]+/).includes('..') || dataRoot.split(/[\\/]+/).includes('..'))
|
|
152
|
+
fail('DATA_ROOT_INVALID');
|
|
153
|
+
const root = realDir(projectRoot);
|
|
154
|
+
const dataParent = join(root, '.switchyard-data');
|
|
155
|
+
const target = trimSep(normalize(dataRoot));
|
|
156
|
+
// Strictly a child of <root>\.switchyard-data; the runtime-data tree itself is never the private root.
|
|
157
|
+
if (target.length <= dataParent.length + 1 || !same(target.slice(0, dataParent.length + 1), dataParent + sep))
|
|
158
|
+
fail('DATA_ROOT_INVALID');
|
|
159
|
+
if (!existsSync(dataParent))
|
|
160
|
+
mkdirSync(dataParent); // the runtime-data tree only; its ACL is left as inherited
|
|
161
|
+
realDir(dataParent);
|
|
162
|
+
const rel = target.slice(dataParent.length + 1).split(sep);
|
|
163
|
+
let cur = dataParent;
|
|
164
|
+
for (let i = 0; i < rel.length - 1; i += 1) {
|
|
165
|
+
cur = join(cur, rel[i]);
|
|
166
|
+
realDir(cur); // intermediate directories must already exist and be real; they are never created or changed
|
|
167
|
+
}
|
|
168
|
+
let created = false;
|
|
169
|
+
if (!existsSync(target)) {
|
|
170
|
+
try {
|
|
171
|
+
mkdirSync(target);
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
fail('DATA_ROOT_INVALID');
|
|
175
|
+
}
|
|
176
|
+
created = true;
|
|
177
|
+
}
|
|
178
|
+
const canonical = realDir(target);
|
|
179
|
+
if (created)
|
|
180
|
+
powershell('init', [canonical]);
|
|
181
|
+
const snap = powershell('read', [canonical]);
|
|
182
|
+
const dirSddl = snap.items[0]?.sddl;
|
|
183
|
+
if (typeof dirSddl !== 'string' || !directoryIsPrivate(dirSddl, snap.user))
|
|
184
|
+
fail('PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED');
|
|
185
|
+
return {
|
|
186
|
+
verified: true,
|
|
187
|
+
canonicalDataRoot: canonical,
|
|
188
|
+
verification: { created, method: 'DACL_EXACT_SET_USER_AND_SYSTEM', effectiveTokenIsolation: 'NOT_VERIFIED' },
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/** Verifies the directory and every file in it (database, WAL, SHM) after SQLite has created them. */
|
|
192
|
+
export function verifyPrivateDataFiles(canonicalDataRoot) {
|
|
193
|
+
const files = readdirSync(canonicalDataRoot, { withFileTypes: true }).filter((e) => e.isFile()).map((e) => join(canonicalDataRoot, e.name));
|
|
194
|
+
const snap = powershell('read', [canonicalDataRoot, ...files]);
|
|
195
|
+
if (snap.items.length !== files.length + 1)
|
|
196
|
+
fail('PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED');
|
|
197
|
+
if (!directoryIsPrivate(snap.items[0].sddl, snap.user))
|
|
198
|
+
fail('PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED');
|
|
199
|
+
for (const item of snap.items.slice(1)) {
|
|
200
|
+
if (!fileIsPrivate(item.sddl, snap.user))
|
|
201
|
+
fail('PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=privateDataRoot.js.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { WorkflowService } from '../runs/workflowService.js';
|
|
2
|
+
import { type Dpapi } from '../storage/protectedSecrets.js';
|
|
3
|
+
import type { FastifyInstance } from 'fastify';
|
|
4
|
+
import { type OperatorConsole, type OperatorStream } from './operatorConsole.js';
|
|
5
|
+
import { type OperationCatalog } from '../plugins/registry/operationCatalog.js';
|
|
6
|
+
import { type ProvisionedExecution } from '../runtime/provisionedExecution.js';
|
|
7
|
+
import { PairedAuthority } from '../projects/pairedAuthority.js';
|
|
8
|
+
import { DurableIntentCoordinator } from '../runs/durableIntentCoordinator.js';
|
|
9
|
+
import { SqliteLedger } from '../storage/sqliteLedger.js';
|
|
10
|
+
import { DiagnosticLog } from '../storage/diagnosticLog.js';
|
|
11
|
+
import type { DiagLevel } from '../../../../packages/contracts/dist/index.js';
|
|
12
|
+
import type { QueuedRunLauncher } from '../transports/http/secureRoutes.js';
|
|
13
|
+
/**
|
|
14
|
+
* Nonexecuting secure startup (B02-C/B02-E). Composes the existing C03/C05/C09 owners through the single
|
|
15
|
+
* createDaemonApp factory in 'secure' mode. No driver, subprocess host, fixture token or
|
|
16
|
+
* environment-derived credential is involved, and nothing here can launch a process.
|
|
17
|
+
*
|
|
18
|
+
* Data roots: there is exactly ONE policy for every invocation (compiled main.js, tests, any local caller). The data
|
|
19
|
+
* root must be a strict canonical child of <projectRoot>\.switchyard-data that passes the private data root check
|
|
20
|
+
* (Windows DACL exactly {current user, SYSTEM}) before SQLite is opened, and the database files are verified again
|
|
21
|
+
* afterwards. There is no scratch, test or skip mode: the SW-034 scratch location is not a secure data root. The
|
|
22
|
+
* attended operator console is created only when the caller passes operatorConsole.
|
|
23
|
+
*/
|
|
24
|
+
export declare const SECURE_DB_FILE_NAME = "secure-ledger.db";
|
|
25
|
+
/** Default production data root, relative to the project root. A NEW directory so existing data is never rewritten. */
|
|
26
|
+
export declare const DEFAULT_PRIVATE_DATA_RELATIVE: string;
|
|
27
|
+
/** Operator grants are short-lived read grants that always require user confirmation. */
|
|
28
|
+
export declare const OPERATOR_GRANT_TTL_MS: number;
|
|
29
|
+
export type SecureStartupErrorCode = 'PROJECT_ROOT_INVALID' | 'DATA_ROOT_INVALID' | 'PRODUCTION_DB_CONFIDENTIALITY_NOT_VERIFIED' | 'APPROVED_PROJECT_INVALID' | 'OPERATOR_CONSOLE_INVALID' | 'OPERATOR_TTY_REQUIRED' | 'PORT_INVALID' | 'CATALOG_INVALID' | 'LEDGER_OPEN_FAILED' | 'ALREADY_RUNNING' | 'LISTEN_FAILED';
|
|
30
|
+
/** SW-062: the daemon's single-instance lock and runtime record live in <private data root>\run\ (never on a browser-reachable route). */
|
|
31
|
+
export declare const RUNTIME_DIR_NAME = "run";
|
|
32
|
+
export declare const RUNTIME_RECORD_FILE = "daemon.json";
|
|
33
|
+
export declare const RUNTIME_LOCK_FILE = "daemon.lock";
|
|
34
|
+
/** Sanitized: carries only a fixed code, never paths, tokens or driver messages. */
|
|
35
|
+
export declare class SecureStartupError extends Error {
|
|
36
|
+
readonly code: SecureStartupErrorCode;
|
|
37
|
+
constructor(code: SecureStartupErrorCode);
|
|
38
|
+
}
|
|
39
|
+
export interface SecureDaemonOptions {
|
|
40
|
+
/** Absolute canonical root of the my-centcom checkout. */
|
|
41
|
+
projectRoot: string;
|
|
42
|
+
/** Optional; defaults to <projectRoot>\.switchyard-data\private. Otherwise a strict child of <projectRoot>\.switchyard-data; always verified private. */
|
|
43
|
+
dataRoot?: string;
|
|
44
|
+
/** SW-062: per-file size cap of the rotated diagnostic log (default 1 MiB, minimum 1 KiB) and the minimum level recorded (default INFO). */
|
|
45
|
+
diagnosticLogMaxBytes?: number;
|
|
46
|
+
diagnosticMinLevel?: DiagLevel;
|
|
47
|
+
/** Trusted local catalog; defaults to EMPTY (admits nothing). */
|
|
48
|
+
operationCatalog?: OperationCatalog;
|
|
49
|
+
/** The one Git project operator grants may name. Validated and registered through C03; omitted means grants are refused. */
|
|
50
|
+
approvedProject?: {
|
|
51
|
+
projectId: string;
|
|
52
|
+
root: string;
|
|
53
|
+
};
|
|
54
|
+
/** Creates the attended operator console in this process. Never reachable over HTTP; never created implicitly. */
|
|
55
|
+
operatorConsole?: {
|
|
56
|
+
input: NodeJS.ReadableStream & OperatorStream;
|
|
57
|
+
output: NodeJS.WritableStream & OperatorStream;
|
|
58
|
+
allowInjectedTestStreams?: boolean;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* TRUSTED construction-time seam (SW-055), in-process only: builds the opaque port that runs approved work from THIS daemon's own
|
|
62
|
+
* already-created owners, so the launcher shares the single ledger writer instead of opening a second one. Not reachable over HTTP,
|
|
63
|
+
* not derived from an environment variable, flag or message, and not set by the ordinary entry point. Omitted = this daemon launches nothing.
|
|
64
|
+
*/
|
|
65
|
+
createRunLauncher?: (owners: {
|
|
66
|
+
ledger: SqliteLedger;
|
|
67
|
+
authority: PairedAuthority;
|
|
68
|
+
coordinator: DurableIntentCoordinator;
|
|
69
|
+
now: () => number;
|
|
70
|
+
}) => QueuedRunLauncher;
|
|
71
|
+
/** TRUSTED (SW-053): per-operation prompt ceiling in UTF-8 bytes (default 16384; above that only for stdin-transport operations). */
|
|
72
|
+
promptCapBytes?: (pluginId: string, operationId: string) => number;
|
|
73
|
+
/** SW-061 TRUSTED startup flag: also offer the benign DEV_SMOKE_PROFILES to the operator console. Default false. */
|
|
74
|
+
devSmokeProfiles?: boolean;
|
|
75
|
+
/** Trusted offline acceptance endpoint; honored only with devSmokeProfiles. Never accepted from HTTP or model arguments. */
|
|
76
|
+
devMockResponsesPort?: number;
|
|
77
|
+
/** Exact source binding for trusted, non-sensitive offline fixture acceptance. */
|
|
78
|
+
syntheticTestAcceptance?: {
|
|
79
|
+
sourceRoot: string;
|
|
80
|
+
sourceSha256: string;
|
|
81
|
+
};
|
|
82
|
+
/** 0 (ephemeral) .. 65535; loopback only. */
|
|
83
|
+
port?: number;
|
|
84
|
+
now?: () => number;
|
|
85
|
+
/**
|
|
86
|
+
* SW-062 TRUSTED startup flag: take the single-instance lock and publish <dataRoot>\run\daemon.json {port,pid,instanceId} for the native bootstrap host.
|
|
87
|
+
* Set by the ordinary entry point when it is started by the host (MY_CENTCOM_PUBLISH_RUNTIME=1) and by the setup self-test. Default false.
|
|
88
|
+
*/
|
|
89
|
+
publishRuntime?: boolean;
|
|
90
|
+
/** SW-062: DPAPI implementation for the capture data key (tests on non-Windows may inject one). Production: Windows DPAPI CurrentUser. */
|
|
91
|
+
dpapi?: Dpapi;
|
|
92
|
+
}
|
|
93
|
+
export interface SecureDaemon {
|
|
94
|
+
port: number;
|
|
95
|
+
url: string;
|
|
96
|
+
app: FastifyInstance;
|
|
97
|
+
/** Trusted in-process administration handle (pairing challenges, grants, revocation). Never reachable over HTTP. */
|
|
98
|
+
authority: PairedAuthority;
|
|
99
|
+
/** SW-062: the daemon diagnostic log (in-process handle for tests and the operator console). */
|
|
100
|
+
diag: DiagnosticLog;
|
|
101
|
+
/** The attended operator console, present only when requested through options.operatorConsole. */
|
|
102
|
+
operator?: OperatorConsole;
|
|
103
|
+
/** Number of uncertain runs moved to UNKNOWN before listening. */
|
|
104
|
+
recovered: number;
|
|
105
|
+
/** SW-060: provisioned operations re-verified and enabled at startup, and the ones whose re-verification failed (disabled for good). Absent when a test seam supplied the launcher. */
|
|
106
|
+
provisioned?: {
|
|
107
|
+
enabled: number;
|
|
108
|
+
invalidated: readonly string[];
|
|
109
|
+
};
|
|
110
|
+
/** SW-062 trusted in-process handles (never reachable over HTTP): the workflow owner, the ledger for setup, and provisioning for setup/self-test. */
|
|
111
|
+
workflow: WorkflowService;
|
|
112
|
+
ledger: SqliteLedger;
|
|
113
|
+
provisionedActions?: Pick<ProvisionedExecution, 'provisionOperation' | 'listProvisioned' | 'disableProvisioned'>;
|
|
114
|
+
instanceId: string;
|
|
115
|
+
close: () => Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
export declare function startSecureDaemon(options: SecureDaemonOptions): Promise<SecureDaemon>;
|
|
118
|
+
//# sourceMappingURL=secureMain.d.ts.map
|