@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,786 @@
|
|
|
1
|
+
import type { CodingResultKindV1 } from '../../../../packages/contracts/dist/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* C09 durable ledger (B02-A). Sole owner of SQL and transactions.
|
|
4
|
+
* Secrets are never stored: only SHA-256 digests of random high-entropy values.
|
|
5
|
+
* Database file permissions are NOT restricted by this module (no ACL enforcement is claimed).
|
|
6
|
+
*/
|
|
7
|
+
export declare const LEDGER_SCHEMA_VERSION = 13;
|
|
8
|
+
/** Preserve previous immutable snapshots while allowing a separately typed applied delivery. */
|
|
9
|
+
export declare const MIGRATION_V12_SQL = "\nCREATE TABLE coding_results_v12 (\n result_id TEXT PRIMARY KEY CHECK (result_id GLOB 'cres.*'), run_id TEXT NOT NULL,\n principal_id TEXT NOT NULL REFERENCES principals(principal_id), proposal_id TEXT NOT NULL REFERENCES coding_proposals(proposal_id),\n text_sha256 TEXT NOT NULL CHECK(length(text_sha256)=64), text_bytes INTEGER NOT NULL CHECK(text_bytes BETWEEN 1 AND 65536),\n text_content TEXT NOT NULL, created_at TEXT NOT NULL,\n kind TEXT NOT NULL CHECK(kind IN ('VERIFIED_CODING_RESULT','PROPOSAL_ONLY_UNVERIFIED','APPLIED_UNTESTED_RESULT')), UNIQUE(proposal_id,kind));\nINSERT INTO coding_results_v12 SELECT result_id,run_id,principal_id,proposal_id,text_sha256,text_bytes,text_content,created_at,kind FROM coding_results;\nDROP TRIGGER coding_results_immutable;\nDROP TRIGGER coding_results_no_delete;\nDROP TABLE coding_results;\nALTER TABLE coding_results_v12 RENAME TO coding_results;\nCREATE TRIGGER coding_results_immutable BEFORE UPDATE ON coding_results BEGIN SELECT RAISE(ABORT, 'CODING_RESULT_IMMUTABLE'); END;\nCREATE TRIGGER coding_results_no_delete BEFORE DELETE ON coding_results BEGIN SELECT RAISE(ABORT, 'CODING_RESULT_IMMUTABLE'); END;\n";
|
|
10
|
+
export declare const MIGRATION_V13_SQL: string;
|
|
11
|
+
export declare const MIGRATION_V11_SQL = "\nALTER TABLE coding_results ADD COLUMN kind TEXT NOT NULL DEFAULT 'VERIFIED_CODING_RESULT' CHECK (kind IN ('VERIFIED_CODING_RESULT','PROPOSAL_ONLY_UNVERIFIED'));\n";
|
|
12
|
+
export declare const MIGRATION_V10_SQL = "\nCREATE TABLE coding_actions (proposal_id TEXT NOT NULL REFERENCES coding_proposals(proposal_id), action TEXT NOT NULL, digest TEXT NOT NULL, started_at TEXT NOT NULL, result_json TEXT, PRIMARY KEY(proposal_id, action));\nCREATE TRIGGER coding_actions_identity_immutable BEFORE UPDATE OF proposal_id, action, digest, started_at ON coding_actions BEGIN SELECT RAISE(ABORT, 'CODING_ACTION_IMMUTABLE'); END;\nCREATE TRIGGER coding_actions_result_immutable BEFORE UPDATE OF result_json ON coding_actions WHEN OLD.result_json IS NOT NULL BEGIN SELECT RAISE(ABORT, 'CODING_ACTION_IMMUTABLE'); END;\nCREATE TRIGGER coding_actions_no_delete BEFORE DELETE ON coding_actions BEGIN SELECT RAISE(ABORT, 'CODING_ACTION_RETAINED'); END;\n";
|
|
13
|
+
export declare const MAX_PAIRING_FAILED_ATTEMPTS = 5;
|
|
14
|
+
export type LifecycleStateName = 'CREATED' | 'AWAITING_USER_APPROVAL' | 'QUEUED' | 'STARTING' | 'RUNNING' | 'WAITING_AGENT_APPROVAL' | 'CANCEL_REQUESTED' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'UNKNOWN';
|
|
15
|
+
/** Schema version 1 (SW-031). Kept verbatim so v1 databases can be created and migrated in tests. */
|
|
16
|
+
export declare const SCHEMA_V1_SQL: string;
|
|
17
|
+
/** Additive migration 1 -> 2 (SW-032): one-time trusted approval challenges. */
|
|
18
|
+
export declare const MIGRATION_V2_SQL = "\nCREATE TABLE approval_challenges (\n approval_id TEXT PRIMARY KEY CHECK (length(approval_id) >= 16),\n run_id TEXT NOT NULL REFERENCES run_intents(run_id),\n principal_id TEXT NOT NULL REFERENCES principals(principal_id),\n code_sha256 TEXT NOT NULL CHECK (length(code_sha256) = 64),\n request_fingerprint TEXT NOT NULL CHECK (length(request_fingerprint) = 64),\n expires_at TEXT NOT NULL,\n consumed_at TEXT,\n created_at TEXT NOT NULL\n);\nCREATE INDEX approval_challenges_run_idx ON approval_challenges(run_id);\n";
|
|
19
|
+
/**
|
|
20
|
+
* Additive migration 2 -> 3 (SW-051): execution evidence. A run has at most ONE launch record (primary key), committed in the same
|
|
21
|
+
* transaction as QUEUED -> STARTING and before any process can exist, so an uncertain run can never be relaunched. Output events,
|
|
22
|
+
* the outcome and Git observations reference it. Agent text is stored as untrusted data; no secret, bearer or path of the database is
|
|
23
|
+
* ever part of a row written here.
|
|
24
|
+
*/
|
|
25
|
+
export declare const MIGRATION_V3_SQL = "\nCREATE TABLE run_launches (\n run_id TEXT PRIMARY KEY REFERENCES run_intents(run_id),\n authorization_grant_id TEXT NOT NULL CHECK (length(authorization_grant_id) > 0),\n manifest_fingerprint TEXT NOT NULL CHECK (length(manifest_fingerprint) = 64),\n executable_sha256 TEXT NOT NULL CHECK (length(executable_sha256) = 64),\n execution_identity TEXT NOT NULL CHECK (execution_identity IN ('RESTRICTED_LOW_INTEGRITY')),\n security_tier TEXT NOT NULL CHECK (security_tier = 'PATH_CHECKS_ONLY'),\n committed_at TEXT NOT NULL\n);\nCREATE TABLE run_output_events (\n run_id TEXT NOT NULL REFERENCES run_launches(run_id),\n sequence_no INTEGER NOT NULL CHECK (sequence_no >= 1),\n event_id TEXT NOT NULL UNIQUE,\n event_kind TEXT NOT NULL,\n payload_json TEXT NOT NULL CHECK (length(payload_json) <= 65536),\n native_session_id TEXT,\n occurred_at TEXT NOT NULL,\n PRIMARY KEY (run_id, sequence_no)\n);\nCREATE TABLE run_outcomes (\n run_id TEXT PRIMARY KEY REFERENCES run_launches(run_id),\n process_outcome TEXT NOT NULL,\n process_launched INTEGER NOT NULL CHECK (process_launched IN (0,1)),\n exit_code INTEGER,\n tree_terminated INTEGER CHECK (tree_terminated IN (0,1)),\n child_token_verified INTEGER NOT NULL CHECK (child_token_verified IN (0,1)),\n stdout_sha256 TEXT,\n stdout_bytes INTEGER,\n stdout_truncated INTEGER CHECK (stdout_truncated IN (0,1)),\n stderr_bytes INTEGER,\n stderr_truncated INTEGER CHECK (stderr_truncated IN (0,1)),\n duration_ms INTEGER,\n final_message TEXT CHECK (final_message IS NULL OR length(final_message) <= 8192),\n validation_status TEXT NOT NULL CHECK (validation_status IN ('PASS','NEEDS_CORRECTION','BLOCKED','NOT_VERIFIED')),\n cancellation_racing INTEGER NOT NULL CHECK (cancellation_racing IN (0,1)),\n recorded_at TEXT NOT NULL\n);\nCREATE TABLE git_observations (\n run_id TEXT NOT NULL REFERENCES run_intents(run_id),\n phase TEXT NOT NULL CHECK (phase IN ('BEFORE','AFTER')),\n status TEXT NOT NULL CHECK (status IN ('OBSERVED','FAILED')),\n failure_code TEXT,\n branch TEXT,\n head_commit TEXT CHECK (head_commit IS NULL OR length(head_commit) = 40),\n clean INTEGER CHECK (clean IN (0,1)),\n dirty_json TEXT,\n untracked_json TEXT,\n observed_at TEXT NOT NULL,\n PRIMARY KEY (run_id, phase)\n);\n";
|
|
26
|
+
/**
|
|
27
|
+
* Additive migration 3 -> 4 (SW-052): the approved prompt becomes an immutable, digest-bound snapshot. run_intents is deliberately NOT
|
|
28
|
+
* altered. Existing rows are backfilled by the constructor (SQLite has no SHA-256). The triggers make the stored prompt text and its
|
|
29
|
+
* snapshot immutable at the database level, so the digest recorded at acceptance is the digest verified at launch. The launch record
|
|
30
|
+
* gains the prompt digest/length, the input transport actually used and the pinned code-input digest; the outcome gains the stdin status.
|
|
31
|
+
*/
|
|
32
|
+
export declare const MIGRATION_V4_SQL = "\nCREATE TABLE prompt_snapshots (\n run_id TEXT PRIMARY KEY REFERENCES run_intents(run_id),\n prompt_sha256 TEXT NOT NULL CHECK (length(prompt_sha256) = 64),\n prompt_bytes INTEGER NOT NULL CHECK (prompt_bytes > 0),\n created_at TEXT NOT NULL\n);\nCREATE TRIGGER prompt_snapshots_no_update BEFORE UPDATE ON prompt_snapshots BEGIN SELECT RAISE(ABORT, 'PROMPT_SNAPSHOT_IMMUTABLE'); END;\nCREATE TRIGGER prompt_snapshots_no_delete BEFORE DELETE ON prompt_snapshots BEGIN SELECT RAISE(ABORT, 'PROMPT_SNAPSHOT_IMMUTABLE'); END;\nCREATE TRIGGER run_intents_prompt_immutable BEFORE UPDATE OF prompt_text ON run_intents BEGIN SELECT RAISE(ABORT, 'PROMPT_IMMUTABLE'); END;\nALTER TABLE run_launches ADD COLUMN prompt_sha256 TEXT CHECK (prompt_sha256 IS NULL OR length(prompt_sha256) = 64);\nALTER TABLE run_launches ADD COLUMN prompt_bytes INTEGER;\nALTER TABLE run_launches ADD COLUMN input_transport TEXT CHECK (input_transport IS NULL OR input_transport IN ('ARGV','STDIN'));\nALTER TABLE run_launches ADD COLUMN code_inputs_sha256 TEXT CHECK (code_inputs_sha256 IS NULL OR length(code_inputs_sha256) = 64);\nALTER TABLE run_outcomes ADD COLUMN stdin_status TEXT CHECK (stdin_status IS NULL OR stdin_status IN ('NOT_REQUESTED','NOT_ATTEMPTED','DELIVERED_EOF','EARLY_EXIT','ERROR'));\nALTER TABLE run_outcomes ADD COLUMN stdin_bytes_written INTEGER;\n";
|
|
33
|
+
/**
|
|
34
|
+
* Additive migration 4 -> 5 (SW-058, B05): the immutable final-text return snapshot of ONE completed run (UNIQUE run_id). Rows can be inserted once and are
|
|
35
|
+
* then undeletable and unupdatable at the database level; the digest is checked again on every read. Existing tables are not altered.
|
|
36
|
+
*/
|
|
37
|
+
export declare const MIGRATION_V5_SQL = "\nCREATE TABLE return_snapshots (\n return_id TEXT PRIMARY KEY CHECK (return_id GLOB 'ret.????????????????????????????????'),\n run_id TEXT NOT NULL UNIQUE REFERENCES run_intents(run_id),\n principal_id TEXT NOT NULL REFERENCES principals(principal_id),\n project_id TEXT NOT NULL REFERENCES projects(project_id),\n text_sha256 TEXT NOT NULL CHECK (length(text_sha256) = 64),\n text_bytes INTEGER NOT NULL CHECK (text_bytes BETWEEN 1 AND 16384),\n text_content TEXT NOT NULL CHECK (length(text_content) > 0),\n created_at TEXT NOT NULL\n);\nCREATE TRIGGER return_snapshots_no_update BEFORE UPDATE ON return_snapshots BEGIN SELECT RAISE(ABORT, 'RETURN_SNAPSHOT_IMMUTABLE'); END;\nCREATE TRIGGER return_snapshots_no_delete BEFORE DELETE ON return_snapshots BEGIN SELECT RAISE(ABORT, 'RETURN_SNAPSHOT_IMMUTABLE'); END;\n";
|
|
38
|
+
/**
|
|
39
|
+
* Additive migration 5 -> 6 (SW-060): operator-provisioned operations. NON-SECRET configuration only: which reviewed profile, which absolute executable and
|
|
40
|
+
* code inputs, and the digests the operator saw when provisioning. The row is data, not authority: every start and every launch re-verifies the files against it,
|
|
41
|
+
* and a failed re-verification disables the row for good (it is never re-enabled automatically). No prompt, token or credential is ever stored here.
|
|
42
|
+
*/
|
|
43
|
+
export declare const MIGRATION_V6_SQL = "\nCREATE TABLE provisioned_operations (\n plugin_id TEXT NOT NULL CHECK (length(plugin_id) > 0),\n operation_id TEXT NOT NULL CHECK (length(operation_id) > 0),\n profile_id TEXT NOT NULL CHECK (length(profile_id) > 0),\n executable_path TEXT NOT NULL CHECK (length(executable_path) > 0),\n executable_sha256 TEXT NOT NULL CHECK (length(executable_sha256) = 64),\n code_inputs_json TEXT NOT NULL,\n code_inputs_sha256 TEXT CHECK (code_inputs_sha256 IS NULL OR length(code_inputs_sha256) = 64),\n manifest_fingerprint TEXT NOT NULL CHECK (length(manifest_fingerprint) = 64),\n enabled INTEGER NOT NULL CHECK (enabled IN (0,1)),\n disabled_reason TEXT,\n created_at TEXT NOT NULL,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (plugin_id, operation_id)\n);\n";
|
|
44
|
+
/**
|
|
45
|
+
* Additive migration 6 -> 7 (SW-062 integrated automation). Existing tables keep every row and meaning:
|
|
46
|
+
* - installations: ONE revocable per-user trust record per extension identity; the native bootstrap host proves it with a secret whose SHA-256 only is
|
|
47
|
+
* stored here. Its principal is the stable owner of grants and runs; only that principal's short-lived bearer rotates.
|
|
48
|
+
* - grants.consent_mode: LOCAL_CONFIRM (every pre-SW-062 grant: unchanged behaviour) or RUN_CLICK (set ONLY by trusted local setup, ONLY for verified
|
|
49
|
+
* 'read' operations: the user's own Run click is the per-run consent). The CHECK makes RUN_CLICK on any other effect class unrepresentable.
|
|
50
|
+
* - capture_snapshots: the user-gesture selection, ENCRYPTED (AES-256-GCM, key protected by Windows DPAPI CurrentUser); only digests and ids are
|
|
51
|
+
* clear text. TTL-bounded; one capture can feed exactly one run (consumed_run_id UNIQUE).
|
|
52
|
+
* - return_targets / return_receipts: the return state machine (separate from the run lifecycle). Targets are encrypted like captures. Append-only.
|
|
53
|
+
* - workflow_preferences: the user's default approved operation (non-secret).
|
|
54
|
+
*/
|
|
55
|
+
export declare const MIGRATION_V7_SQL = "\nCREATE TABLE installations (\n installation_id TEXT PRIMARY KEY CHECK (installation_id GLOB 'inst.*'),\n principal_id TEXT NOT NULL UNIQUE REFERENCES principals(principal_id),\n extension_origin TEXT NOT NULL CHECK (extension_origin LIKE 'chrome-extension://%'),\n secret_sha256 TEXT NOT NULL CHECK (length(secret_sha256) = 64),\n failed_attempts INTEGER NOT NULL DEFAULT 0 CHECK (failed_attempts >= 0),\n sessions_issued INTEGER NOT NULL DEFAULT 0 CHECK (sessions_issued >= 0),\n created_at TEXT NOT NULL,\n revoked_at TEXT\n);\nALTER TABLE grants ADD COLUMN consent_mode TEXT NOT NULL DEFAULT 'LOCAL_CONFIRM' CHECK (consent_mode IN ('LOCAL_CONFIRM','RUN_CLICK'));\nCREATE TRIGGER grants_run_click_read_only_insert BEFORE INSERT ON grants WHEN NEW.consent_mode = 'RUN_CLICK' AND NEW.max_effect_class <> 'read' BEGIN SELECT RAISE(ABORT, 'RUN_CLICK_READ_ONLY'); END;\nCREATE TRIGGER grants_consent_immutable BEFORE UPDATE OF consent_mode, max_effect_class ON grants BEGIN SELECT RAISE(ABORT, 'GRANT_SCOPE_IMMUTABLE'); END;\nCREATE TABLE capture_snapshots (\n capture_id TEXT PRIMARY KEY CHECK (capture_id GLOB 'cap.????????????????????????????????'),\n principal_id TEXT NOT NULL REFERENCES principals(principal_id),\n text_sha256 TEXT NOT NULL CHECK (length(text_sha256) = 64),\n text_bytes INTEGER NOT NULL CHECK (text_bytes BETWEEN 1 AND 32768),\n sealed BLOB NOT NULL,\n created_at TEXT NOT NULL,\n expires_at TEXT NOT NULL,\n consumed_run_id TEXT UNIQUE REFERENCES run_intents(run_id),\n consent_mode TEXT CHECK (consent_mode IS NULL OR consent_mode IN ('LOCAL_CONFIRM','RUN_CLICK')),\n dismissed_at TEXT\n);\nCREATE INDEX capture_snapshots_principal ON capture_snapshots(principal_id, created_at);\nCREATE TABLE return_targets (\n return_id TEXT NOT NULL REFERENCES return_snapshots(return_id),\n sequence_no INTEGER NOT NULL CHECK (sequence_no >= 1),\n reason TEXT NOT NULL CHECK (reason IN ('ORIGIN','USER_REBIND')),\n sealed BLOB NOT NULL,\n created_at TEXT NOT NULL,\n PRIMARY KEY (return_id, sequence_no)\n);\nCREATE TABLE return_receipts (\n return_id TEXT NOT NULL REFERENCES return_snapshots(return_id),\n sequence_no INTEGER NOT NULL CHECK (sequence_no >= 1),\n state TEXT NOT NULL CHECK (state IN ('RETURN_READY','INSERTED_UNSENT','RETURN_STALE','INSERT_FAILED')),\n code TEXT,\n editor TEXT CHECK (editor IS NULL OR editor IN ('TEXTAREA','CONTENTEDITABLE','PROSEMIRROR')),\n created_at TEXT NOT NULL,\n PRIMARY KEY (return_id, sequence_no)\n);\nCREATE TRIGGER return_receipts_no_update BEFORE UPDATE ON return_receipts BEGIN SELECT RAISE(ABORT, 'RETURN_RECEIPT_APPEND_ONLY'); END;\nCREATE TRIGGER return_targets_no_update BEFORE UPDATE ON return_targets BEGIN SELECT RAISE(ABORT, 'RETURN_TARGET_APPEND_ONLY'); END;\nCREATE TABLE workflow_preferences (\n principal_id TEXT PRIMARY KEY REFERENCES principals(principal_id),\n project_id TEXT NOT NULL,\n plugin_id TEXT NOT NULL,\n operation_id TEXT NOT NULL,\n updated_at TEXT NOT NULL\n);\n";
|
|
56
|
+
/**
|
|
57
|
+
* Additive migration 7 -> 8 (SW-068): EXECUTION EVIDENCE. One header row per launched run is written BEFORE any external process exists (fail closed when it cannot be),
|
|
58
|
+
* and every later lifecycle step, bounded redacted stdout/stderr line and parser problem is appended as its own committed row, so a crash, timeout or daemon restart keeps
|
|
59
|
+
* everything recorded so far. Rows hold REDACTED, bounded text only (see evidenceRedaction.ts); retention is enforced by purgeExecutionEvidence.
|
|
60
|
+
*/
|
|
61
|
+
export declare const MIGRATION_V8_SQL = "\nCREATE TABLE execution_evidence (\n run_id TEXT PRIMARY KEY REFERENCES run_intents(run_id),\n correlation_id TEXT NOT NULL UNIQUE CHECK (correlation_id GLOB 'corr.*'),\n created_at TEXT NOT NULL,\n driver TEXT NOT NULL,\n output_profile TEXT,\n plugin_id TEXT NOT NULL,\n operation_id TEXT NOT NULL,\n executable_sha256 TEXT NOT NULL CHECK (length(executable_sha256) = 64),\n manifest_fingerprint TEXT NOT NULL,\n config_json TEXT NOT NULL CHECK (length(config_json) <= 4096),\n last_stage TEXT NOT NULL,\n classification_json TEXT CHECK (classification_json IS NULL OR length(classification_json) <= 2048),\n finalized_at TEXT\n);\nCREATE TABLE execution_evidence_events (\n run_id TEXT NOT NULL REFERENCES execution_evidence(run_id),\n seq INTEGER NOT NULL CHECK (seq >= 1),\n ts TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('LIFECYCLE','STDOUT','STDERR','PARSER','NOTE')),\n stage TEXT,\n data TEXT NOT NULL CHECK (length(data) <= 1024),\n truncated INTEGER NOT NULL CHECK (truncated IN (0,1)),\n PRIMARY KEY (run_id, seq)\n);\nCREATE TRIGGER execution_evidence_events_no_update BEFORE UPDATE ON execution_evidence_events BEGIN SELECT RAISE(ABORT, 'EVIDENCE_EVENT_APPEND_ONLY'); END;\nCREATE TABLE execution_telemetry_probe (token TEXT PRIMARY KEY, written_at TEXT NOT NULL);\n";
|
|
62
|
+
export interface ExecutionEvidenceHeader {
|
|
63
|
+
runId: string;
|
|
64
|
+
correlationId: string;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
driver: string;
|
|
67
|
+
outputProfile: string | null;
|
|
68
|
+
pluginId: string;
|
|
69
|
+
operationId: string;
|
|
70
|
+
executableSha256: string;
|
|
71
|
+
manifestFingerprint: string;
|
|
72
|
+
configJson: string;
|
|
73
|
+
lastStage: string;
|
|
74
|
+
classificationJson: string | null;
|
|
75
|
+
finalizedAt: string | null;
|
|
76
|
+
}
|
|
77
|
+
export interface ExecutionEvidenceEventRow {
|
|
78
|
+
seq: number;
|
|
79
|
+
ts: string;
|
|
80
|
+
kind: string;
|
|
81
|
+
stage: string | null;
|
|
82
|
+
data: string;
|
|
83
|
+
truncated: boolean;
|
|
84
|
+
}
|
|
85
|
+
export type ConsentModeName = 'LOCAL_CONFIRM' | 'RUN_CLICK';
|
|
86
|
+
export interface InstallationRow {
|
|
87
|
+
installationId: string;
|
|
88
|
+
principalId: string;
|
|
89
|
+
extensionOrigin: string;
|
|
90
|
+
secretSha256: string;
|
|
91
|
+
failedAttempts: number;
|
|
92
|
+
sessionsIssued: number;
|
|
93
|
+
createdAt: string;
|
|
94
|
+
revokedAt: string | null;
|
|
95
|
+
}
|
|
96
|
+
export interface CaptureRow {
|
|
97
|
+
captureId: string;
|
|
98
|
+
principalId: string;
|
|
99
|
+
sha256: string;
|
|
100
|
+
bytes: number;
|
|
101
|
+
sealed: Uint8Array;
|
|
102
|
+
createdAt: string;
|
|
103
|
+
expiresAt: string;
|
|
104
|
+
consumedRunId: string | null;
|
|
105
|
+
consentMode: ConsentModeName | null;
|
|
106
|
+
dismissedAt: string | null;
|
|
107
|
+
}
|
|
108
|
+
export interface ActiveGrantRow {
|
|
109
|
+
grantId: string;
|
|
110
|
+
projectId: string;
|
|
111
|
+
pluginId: string;
|
|
112
|
+
operationId: string;
|
|
113
|
+
maxEffectClass: string;
|
|
114
|
+
expiresAt: string;
|
|
115
|
+
consentMode: ConsentModeName;
|
|
116
|
+
}
|
|
117
|
+
export type ReturnStateName = 'RETURN_READY' | 'INSERTED_UNSENT' | 'RETURN_STALE' | 'INSERT_FAILED';
|
|
118
|
+
export interface ProvisionedOperationRow {
|
|
119
|
+
pluginId: string;
|
|
120
|
+
operationId: string;
|
|
121
|
+
profileId: string;
|
|
122
|
+
executablePath: string;
|
|
123
|
+
executableSha256: string;
|
|
124
|
+
codeInputs: readonly string[];
|
|
125
|
+
/** Digest over the pinned code-bearing inputs as the operator saw them (null when the profile has none). */
|
|
126
|
+
codeInputsSha256: string | null;
|
|
127
|
+
manifestFingerprint: string;
|
|
128
|
+
enabled: boolean;
|
|
129
|
+
disabledReason: string | null;
|
|
130
|
+
createdAt: string;
|
|
131
|
+
}
|
|
132
|
+
export interface ReturnSnapshotRow {
|
|
133
|
+
returnId: string;
|
|
134
|
+
runId: string;
|
|
135
|
+
projectId: string;
|
|
136
|
+
text: string;
|
|
137
|
+
sha256: string;
|
|
138
|
+
bytes: number;
|
|
139
|
+
createdAt: string;
|
|
140
|
+
}
|
|
141
|
+
/** C08 policy answer, computed by the artifacts owner from committed evidence; the ledger only stores and verifies. */
|
|
142
|
+
export type ReturnDecision = {
|
|
143
|
+
kind: 'REFUSE';
|
|
144
|
+
code: string;
|
|
145
|
+
} | {
|
|
146
|
+
kind: 'SNAPSHOT';
|
|
147
|
+
text: string;
|
|
148
|
+
returnId: string;
|
|
149
|
+
};
|
|
150
|
+
export type ReturnPrepareResult = {
|
|
151
|
+
kind: 'NOT_FOUND';
|
|
152
|
+
} | {
|
|
153
|
+
kind: 'REFUSED';
|
|
154
|
+
code: string;
|
|
155
|
+
} | {
|
|
156
|
+
kind: 'CONFLICT';
|
|
157
|
+
code: string;
|
|
158
|
+
} | {
|
|
159
|
+
kind: 'OK';
|
|
160
|
+
snapshot: ReturnSnapshotRow;
|
|
161
|
+
duplicate: boolean;
|
|
162
|
+
};
|
|
163
|
+
export type GitObservationRow = {
|
|
164
|
+
status: 'OBSERVED';
|
|
165
|
+
branch: string;
|
|
166
|
+
headCommit: string;
|
|
167
|
+
clean: boolean;
|
|
168
|
+
dirtyFiles: readonly string[];
|
|
169
|
+
untrackedFiles: readonly string[];
|
|
170
|
+
observedAt: string;
|
|
171
|
+
} | {
|
|
172
|
+
status: 'FAILED';
|
|
173
|
+
failureCode: string;
|
|
174
|
+
observedAt: string;
|
|
175
|
+
};
|
|
176
|
+
export interface LaunchRecordInput {
|
|
177
|
+
authorizationGrantId: string;
|
|
178
|
+
manifestFingerprint: string;
|
|
179
|
+
executableSha256: string;
|
|
180
|
+
executionIdentity: 'RESTRICTED_LOW_INTEGRITY';
|
|
181
|
+
securityTier: 'PATH_CHECKS_ONLY';
|
|
182
|
+
/** SW-052 (all optional so SW-051-shaped callers still work; the executor always supplies them). */
|
|
183
|
+
promptSha256?: string;
|
|
184
|
+
promptBytes?: number;
|
|
185
|
+
inputTransport?: 'ARGV' | 'STDIN';
|
|
186
|
+
codeInputsSha256?: string | null;
|
|
187
|
+
}
|
|
188
|
+
export interface OutputEventRow {
|
|
189
|
+
eventId: string;
|
|
190
|
+
eventKind: string;
|
|
191
|
+
payload: Readonly<Record<string, unknown>>;
|
|
192
|
+
nativeSessionId?: string;
|
|
193
|
+
occurredAt: string;
|
|
194
|
+
}
|
|
195
|
+
export interface RunOutcomeInput {
|
|
196
|
+
processOutcome: string;
|
|
197
|
+
processLaunched: boolean;
|
|
198
|
+
exitCode: number | null;
|
|
199
|
+
treeTerminated: boolean | null;
|
|
200
|
+
childTokenVerified: boolean;
|
|
201
|
+
stdoutSha256: string | null;
|
|
202
|
+
stdoutBytes: number | null;
|
|
203
|
+
stdoutTruncated: boolean | null;
|
|
204
|
+
stderrBytes: number | null;
|
|
205
|
+
stderrTruncated: boolean | null;
|
|
206
|
+
durationMs: number | null;
|
|
207
|
+
finalMessage: string | null;
|
|
208
|
+
validationStatus: 'PASS' | 'NEEDS_CORRECTION' | 'BLOCKED' | 'NOT_VERIFIED';
|
|
209
|
+
cancellationRacing: boolean;
|
|
210
|
+
/** SW-052 */
|
|
211
|
+
stdinStatus?: 'NOT_REQUESTED' | 'NOT_ATTEMPTED' | 'DELIVERED_EOF' | 'EARLY_EXIT' | 'ERROR' | null;
|
|
212
|
+
stdinBytesWritten?: number | null;
|
|
213
|
+
}
|
|
214
|
+
export interface RunExecutionInput {
|
|
215
|
+
run: RunDetail;
|
|
216
|
+
promptText: string;
|
|
217
|
+
/** SW-052: digest recorded at acceptance (immutable snapshot); undefined if the run has none (fail closed at launch). */
|
|
218
|
+
promptSnapshotSha256?: string;
|
|
219
|
+
promptSnapshotBytes?: number;
|
|
220
|
+
idempotencyKey: string;
|
|
221
|
+
projectRoot: string;
|
|
222
|
+
}
|
|
223
|
+
/** Context handed to a launch decision, evaluated INSIDE the BEGIN IMMEDIATE transaction on committed rows. */
|
|
224
|
+
export interface LaunchContext {
|
|
225
|
+
run: RunDetail;
|
|
226
|
+
/** SW-052: SHA-256 of the prompt text as stored NOW, and the digest/length of the immutable acceptance-time snapshot (undefined if none). */
|
|
227
|
+
storedPromptSha256: string;
|
|
228
|
+
promptSnapshot: {
|
|
229
|
+
sha256: string;
|
|
230
|
+
bytes: number;
|
|
231
|
+
} | undefined;
|
|
232
|
+
alreadyLaunched: boolean;
|
|
233
|
+
otherActiveRunsOnProject: number;
|
|
234
|
+
}
|
|
235
|
+
export type LaunchDecision = {
|
|
236
|
+
kind: 'REJECT';
|
|
237
|
+
code: string;
|
|
238
|
+
} | {
|
|
239
|
+
kind: 'FAIL';
|
|
240
|
+
states: ReadonlyArray<{
|
|
241
|
+
state: LifecycleStateName;
|
|
242
|
+
reason: string;
|
|
243
|
+
}>;
|
|
244
|
+
gitBefore?: GitObservationRow;
|
|
245
|
+
} | {
|
|
246
|
+
kind: 'LAUNCH';
|
|
247
|
+
states: ReadonlyArray<{
|
|
248
|
+
state: LifecycleStateName;
|
|
249
|
+
reason: string;
|
|
250
|
+
}>;
|
|
251
|
+
launch: LaunchRecordInput;
|
|
252
|
+
gitBefore: GitObservationRow;
|
|
253
|
+
};
|
|
254
|
+
export type LaunchCommitResult = {
|
|
255
|
+
kind: 'NOT_FOUND';
|
|
256
|
+
} | {
|
|
257
|
+
kind: 'REJECTED';
|
|
258
|
+
code: string;
|
|
259
|
+
} | {
|
|
260
|
+
kind: 'FAILED';
|
|
261
|
+
run: RunRow;
|
|
262
|
+
} | {
|
|
263
|
+
kind: 'LAUNCH_COMMITTED';
|
|
264
|
+
run: RunRow;
|
|
265
|
+
};
|
|
266
|
+
export type OutcomeDecision = {
|
|
267
|
+
kind: 'REJECT';
|
|
268
|
+
code: string;
|
|
269
|
+
} | {
|
|
270
|
+
kind: 'APPLY';
|
|
271
|
+
states: ReadonlyArray<{
|
|
272
|
+
state: LifecycleStateName;
|
|
273
|
+
reason: string;
|
|
274
|
+
}>;
|
|
275
|
+
outcome: RunOutcomeInput;
|
|
276
|
+
events: readonly OutputEventRow[];
|
|
277
|
+
gitAfter?: GitObservationRow;
|
|
278
|
+
};
|
|
279
|
+
export interface RunEvidence {
|
|
280
|
+
lifecycle: Array<{
|
|
281
|
+
sequenceNo: number;
|
|
282
|
+
state: LifecycleStateName;
|
|
283
|
+
reason: string | null;
|
|
284
|
+
occurredAt: string;
|
|
285
|
+
}>;
|
|
286
|
+
launch: (LaunchRecordInput & {
|
|
287
|
+
committedAt: string;
|
|
288
|
+
}) | undefined;
|
|
289
|
+
promptSnapshot: {
|
|
290
|
+
sha256: string;
|
|
291
|
+
bytes: number;
|
|
292
|
+
} | undefined;
|
|
293
|
+
outputEvents: Array<{
|
|
294
|
+
sequenceNo: number;
|
|
295
|
+
eventId: string;
|
|
296
|
+
eventKind: string;
|
|
297
|
+
payload: Record<string, unknown>;
|
|
298
|
+
nativeSessionId: string | null;
|
|
299
|
+
}>;
|
|
300
|
+
outcome: (RunOutcomeInput & {
|
|
301
|
+
recordedAt: string;
|
|
302
|
+
}) | undefined;
|
|
303
|
+
git: {
|
|
304
|
+
before: GitObservationRow | undefined;
|
|
305
|
+
after: GitObservationRow | undefined;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
export interface RunDetail extends RunRow {
|
|
309
|
+
fingerprint: string;
|
|
310
|
+
projectId: string;
|
|
311
|
+
pluginId: string;
|
|
312
|
+
operationId: string;
|
|
313
|
+
}
|
|
314
|
+
export interface ApprovalRow {
|
|
315
|
+
approvalId: string;
|
|
316
|
+
runId: string;
|
|
317
|
+
principalId: string;
|
|
318
|
+
codeSha256: string;
|
|
319
|
+
fingerprint: string;
|
|
320
|
+
expiresAt: string;
|
|
321
|
+
consumedAt: string | null;
|
|
322
|
+
}
|
|
323
|
+
export type DecisionPlan = {
|
|
324
|
+
kind: 'APPLY';
|
|
325
|
+
states: ReadonlyArray<{
|
|
326
|
+
state: LifecycleStateName;
|
|
327
|
+
reason: string;
|
|
328
|
+
}>;
|
|
329
|
+
consumeApproval?: boolean;
|
|
330
|
+
} | {
|
|
331
|
+
kind: 'REPLAY';
|
|
332
|
+
} | {
|
|
333
|
+
kind: 'REJECT';
|
|
334
|
+
code: string;
|
|
335
|
+
};
|
|
336
|
+
export type DecisionResult = {
|
|
337
|
+
kind: 'NOT_FOUND';
|
|
338
|
+
} | {
|
|
339
|
+
kind: 'APPLIED';
|
|
340
|
+
run: RunRow;
|
|
341
|
+
} | {
|
|
342
|
+
kind: 'REPLAY';
|
|
343
|
+
run: RunRow;
|
|
344
|
+
} | {
|
|
345
|
+
kind: 'REJECTED';
|
|
346
|
+
code: string;
|
|
347
|
+
};
|
|
348
|
+
export interface PrincipalRow {
|
|
349
|
+
principalId: string;
|
|
350
|
+
exactOrigin: string;
|
|
351
|
+
tokenExpiresAt: string;
|
|
352
|
+
enabled: boolean;
|
|
353
|
+
}
|
|
354
|
+
export interface GrantRow {
|
|
355
|
+
grantId: string;
|
|
356
|
+
maxEffectClass: string;
|
|
357
|
+
expiresAt: string;
|
|
358
|
+
requiresConfirmation: boolean;
|
|
359
|
+
/** SW-062 (schema 7). */
|
|
360
|
+
consentMode?: ConsentModeName;
|
|
361
|
+
}
|
|
362
|
+
export interface RunRow {
|
|
363
|
+
runId: string;
|
|
364
|
+
principalId: string;
|
|
365
|
+
lifecycleState: LifecycleStateName;
|
|
366
|
+
createdAt: string;
|
|
367
|
+
updatedAt: string;
|
|
368
|
+
}
|
|
369
|
+
export interface ReserveIntentInput {
|
|
370
|
+
runId: string;
|
|
371
|
+
principalId: string;
|
|
372
|
+
requestId: string;
|
|
373
|
+
idempotencyKey: string;
|
|
374
|
+
fingerprint: string;
|
|
375
|
+
projectId: string;
|
|
376
|
+
pluginId: string;
|
|
377
|
+
operationId: string;
|
|
378
|
+
promptText: string;
|
|
379
|
+
/** Ordered states; first is initial (CREATED), last is the resulting current state. */
|
|
380
|
+
states: ReadonlyArray<{
|
|
381
|
+
state: LifecycleStateName;
|
|
382
|
+
reason: string;
|
|
383
|
+
}>;
|
|
384
|
+
nowIso: string;
|
|
385
|
+
}
|
|
386
|
+
export type ReserveIntentResult = {
|
|
387
|
+
kind: 'CREATED';
|
|
388
|
+
run: RunRow;
|
|
389
|
+
} | {
|
|
390
|
+
kind: 'DUPLICATE';
|
|
391
|
+
run: RunRow;
|
|
392
|
+
} | {
|
|
393
|
+
kind: 'CONFLICT';
|
|
394
|
+
};
|
|
395
|
+
export type RedeemResult = 'OK' | 'INVALID' | 'EXPIRED' | 'LOCKED' | 'USED' | 'ORIGIN';
|
|
396
|
+
/**
|
|
397
|
+
* Schema version 9 (SW-080): the coding workflow's durable state. Three tables, all owned here (C09):
|
|
398
|
+
* coding_grants - one row per scoped authority (INSPECT, PROPOSE, APPLY, TEST, GIT_READ, COMMIT). A grant is bound to a principal, a project, ONE run, ONE operation and its matching effect class;
|
|
399
|
+
* it expires, can be revoked, and (for APPLY and COMMIT) is single-use. No operation implies another.
|
|
400
|
+
* coding_proposals- an immutable change proposal (canonical JSON + digest) bound to a run and a project snapshot. Only its status moves, along an explicit lifecycle.
|
|
401
|
+
* coding_events - append-only, hash-chained decision and lifecycle evidence. Rows can be neither updated nor deleted.
|
|
402
|
+
*/
|
|
403
|
+
export declare const MIGRATION_V9_SQL = "\nCREATE TABLE coding_grants (\n grant_id TEXT PRIMARY KEY CHECK (grant_id GLOB 'cgrant.*'),\n principal_id TEXT NOT NULL REFERENCES principals(principal_id),\n project_id TEXT NOT NULL REFERENCES projects(project_id),\n run_id TEXT NOT NULL CHECK (length(run_id) BETWEEN 5 AND 200),\n operation TEXT NOT NULL CHECK (operation IN ('INSPECT','PROPOSE','APPLY','TEST','GIT_READ','COMMIT')),\n effect_class TEXT NOT NULL CHECK (effect_class IN ('read','propose','write_project','execute','git_commit')),\n scope_json TEXT NOT NULL CHECK (length(scope_json) <= 2048),\n single_use INTEGER NOT NULL CHECK (single_use IN (0,1)),\n created_at TEXT NOT NULL,\n expires_at TEXT NOT NULL,\n consumed_at TEXT,\n revoked_at TEXT,\n CHECK ((operation IN ('INSPECT','GIT_READ') AND effect_class = 'read') OR (operation = 'PROPOSE' AND effect_class = 'propose') OR (operation = 'APPLY' AND effect_class = 'write_project')\n OR (operation = 'TEST' AND effect_class = 'execute') OR (operation = 'COMMIT' AND effect_class = 'git_commit')),\n CHECK (operation NOT IN ('APPLY','COMMIT') OR single_use = 1)\n);\nCREATE INDEX coding_grants_lookup ON coding_grants (principal_id, project_id, run_id, operation);\nCREATE TABLE coding_proposals (\n proposal_id TEXT PRIMARY KEY CHECK (proposal_id GLOB 'prop.*'),\n run_id TEXT NOT NULL,\n project_id TEXT NOT NULL REFERENCES projects(project_id),\n principal_id TEXT NOT NULL REFERENCES principals(principal_id),\n digest TEXT NOT NULL CHECK (length(digest) = 64),\n base_head TEXT NOT NULL CHECK (length(base_head) BETWEEN 7 AND 64),\n canonical_json TEXT NOT NULL CHECK (length(canonical_json) <= 524288),\n effect_json TEXT NOT NULL CHECK (length(effect_json) <= 4096),\n status TEXT NOT NULL CHECK (status IN ('SUBMITTED','APPROVED','REJECTED','APPLYING','APPLIED','APPLY_UNCERTAIN','ROLLED_BACK','ROLLBACK_INCOMPLETE','COMMITTED')),\n created_at TEXT NOT NULL,\n status_at TEXT NOT NULL,\n UNIQUE (run_id, digest)\n);\nCREATE TRIGGER coding_proposals_immutable BEFORE UPDATE OF proposal_id, run_id, project_id, principal_id, digest, base_head, canonical_json, effect_json, created_at ON coding_proposals\n BEGIN SELECT RAISE(ABORT, 'PROPOSAL_IMMUTABLE'); END;\nCREATE TRIGGER coding_proposals_no_delete BEFORE DELETE ON coding_proposals BEGIN SELECT RAISE(ABORT, 'PROPOSAL_RETAINED'); END;\nCREATE TABLE coding_events (\n seq INTEGER PRIMARY KEY AUTOINCREMENT,\n at TEXT NOT NULL,\n run_id TEXT NOT NULL,\n subject_kind TEXT NOT NULL CHECK (subject_kind IN ('GRANT','PROPOSAL','APPLY','TEST','GIT','COMMIT')),\n subject_id TEXT NOT NULL,\n event TEXT NOT NULL CHECK (length(event) <= 64),\n decision TEXT CHECK (decision IS NULL OR decision IN ('ALLOWED','DENIED')),\n detail_json TEXT NOT NULL CHECK (length(detail_json) <= 2048),\n prev_sha256 TEXT NOT NULL CHECK (length(prev_sha256) = 64),\n record_sha256 TEXT NOT NULL CHECK (length(record_sha256) = 64)\n);\nCREATE TABLE coding_results (\n result_id TEXT PRIMARY KEY CHECK (result_id GLOB 'cres.*'),\n run_id TEXT NOT NULL,\n principal_id TEXT NOT NULL REFERENCES principals(principal_id),\n proposal_id TEXT NOT NULL UNIQUE REFERENCES coding_proposals(proposal_id),\n text_sha256 TEXT NOT NULL CHECK (length(text_sha256) = 64),\n text_bytes INTEGER NOT NULL CHECK (text_bytes BETWEEN 1 AND 65536),\n text_content TEXT NOT NULL,\n created_at TEXT NOT NULL\n);\nCREATE TRIGGER coding_results_immutable BEFORE UPDATE ON coding_results BEGIN SELECT RAISE(ABORT, 'CODING_RESULT_IMMUTABLE'); END;\nCREATE TRIGGER coding_results_no_delete BEFORE DELETE ON coding_results BEGIN SELECT RAISE(ABORT, 'CODING_RESULT_IMMUTABLE'); END;\nCREATE TRIGGER coding_events_no_update BEFORE UPDATE ON coding_events BEGIN SELECT RAISE(ABORT, 'CODING_EVENT_APPEND_ONLY'); END;\nCREATE TRIGGER coding_events_no_delete BEFORE DELETE ON coding_events BEGIN SELECT RAISE(ABORT, 'CODING_EVENT_APPEND_ONLY'); END;\n";
|
|
404
|
+
export type CodingOperationName = 'INSPECT' | 'PROPOSE' | 'APPLY' | 'TEST' | 'GIT_READ' | 'COMMIT';
|
|
405
|
+
export type CodingEffectClassName = 'read' | 'propose' | 'write_project' | 'execute' | 'git_commit';
|
|
406
|
+
export type CodingProposalStatus = 'SUBMITTED' | 'APPROVED' | 'REJECTED' | 'APPLYING' | 'APPLIED' | 'APPLY_UNCERTAIN' | 'ROLLED_BACK' | 'ROLLBACK_INCOMPLETE' | 'COMMITTED';
|
|
407
|
+
export interface CodingGrantRow {
|
|
408
|
+
grantId: string;
|
|
409
|
+
principalId: string;
|
|
410
|
+
projectId: string;
|
|
411
|
+
runId: string;
|
|
412
|
+
operation: CodingOperationName;
|
|
413
|
+
effectClass: CodingEffectClassName;
|
|
414
|
+
scopeJson: string;
|
|
415
|
+
singleUse: boolean;
|
|
416
|
+
createdAt: string;
|
|
417
|
+
expiresAt: string;
|
|
418
|
+
consumedAt: string | null;
|
|
419
|
+
revokedAt: string | null;
|
|
420
|
+
}
|
|
421
|
+
export interface CodingProposalRow {
|
|
422
|
+
proposalId: string;
|
|
423
|
+
runId: string;
|
|
424
|
+
projectId: string;
|
|
425
|
+
principalId: string;
|
|
426
|
+
digest: string;
|
|
427
|
+
baseHead: string;
|
|
428
|
+
canonicalJson: string;
|
|
429
|
+
effectJson: string;
|
|
430
|
+
status: CodingProposalStatus;
|
|
431
|
+
createdAt: string;
|
|
432
|
+
statusAt: string;
|
|
433
|
+
}
|
|
434
|
+
export interface CodingResultRow {
|
|
435
|
+
resultId: string;
|
|
436
|
+
runId: string;
|
|
437
|
+
principalId: string;
|
|
438
|
+
proposalId: string;
|
|
439
|
+
sha256: string;
|
|
440
|
+
bytes: number;
|
|
441
|
+
text: string;
|
|
442
|
+
createdAt: string;
|
|
443
|
+
kind: CodingResultKindV1;
|
|
444
|
+
}
|
|
445
|
+
export interface CodingEventRow {
|
|
446
|
+
seq: number;
|
|
447
|
+
at: string;
|
|
448
|
+
runId: string;
|
|
449
|
+
subjectKind: string;
|
|
450
|
+
subjectId: string;
|
|
451
|
+
event: string;
|
|
452
|
+
decision: 'ALLOWED' | 'DENIED' | null;
|
|
453
|
+
detailJson: string;
|
|
454
|
+
prevSha256: string;
|
|
455
|
+
recordSha256: string;
|
|
456
|
+
}
|
|
457
|
+
export declare const CODING_CHAIN_GENESIS: string;
|
|
458
|
+
export declare const sha256Hex: (data: string | Buffer) => string;
|
|
459
|
+
export declare class SqliteLedger {
|
|
460
|
+
private readonly db;
|
|
461
|
+
private open;
|
|
462
|
+
constructor(dbPath: string);
|
|
463
|
+
/** Proves the evidence store is writable AND readable right now (a committed write, read back, removed). Throws when it is not. */
|
|
464
|
+
telemetryProbe(nowIso: string): void;
|
|
465
|
+
beginExecutionEvidence(h: Omit<ExecutionEvidenceHeader, 'classificationJson' | 'finalizedAt'>): void;
|
|
466
|
+
/** One committed row per call (WAL): survives a crash of this process right after it returns. Also advances the last confirmed stage when `stage` is given. */
|
|
467
|
+
appendExecutionEvidence(runId: string, ev: {
|
|
468
|
+
ts: string;
|
|
469
|
+
kind: string;
|
|
470
|
+
stage?: string;
|
|
471
|
+
data: string;
|
|
472
|
+
truncated?: boolean;
|
|
473
|
+
}): number;
|
|
474
|
+
finalizeExecutionEvidence(runId: string, classificationJson: string, nowIso: string): void;
|
|
475
|
+
getExecutionEvidence(runId: string): {
|
|
476
|
+
header: ExecutionEvidenceHeader;
|
|
477
|
+
events: ExecutionEvidenceEventRow[];
|
|
478
|
+
} | undefined;
|
|
479
|
+
/** The run id whose evidence carries this correlation id, or (no argument) the most recently started execution. */
|
|
480
|
+
findExecutionEvidenceRun(correlationId?: string): string | undefined;
|
|
481
|
+
/** Retention: deletes evidence (events first) created before the cut-off. Returns the number of executions removed. */
|
|
482
|
+
purgeExecutionEvidence(beforeIso: string): number;
|
|
483
|
+
close(): void;
|
|
484
|
+
private immediate;
|
|
485
|
+
insertProject(projectId: string, canonicalRoot: string, createdAt: string): void;
|
|
486
|
+
getProjectRoot(projectId: string): string | undefined;
|
|
487
|
+
insertChallenge(challengeId: string, origin: string, codeSha256: string, expiresAtIso: string): void;
|
|
488
|
+
/**
|
|
489
|
+
* Atomic single-use redemption. A wrong code persists its failed-attempt increment; an origin
|
|
490
|
+
* mismatch is denied without counting (so a foreign origin cannot lock out the real extension).
|
|
491
|
+
*/
|
|
492
|
+
redeemPairing(input: {
|
|
493
|
+
challengeId: string;
|
|
494
|
+
origin: string;
|
|
495
|
+
codeSha256: string;
|
|
496
|
+
nowMs: number;
|
|
497
|
+
principalId: string;
|
|
498
|
+
tokenSha256: string;
|
|
499
|
+
tokenExpiresAtIso: string;
|
|
500
|
+
}): RedeemResult;
|
|
501
|
+
findPrincipalByTokenSha256(tokenSha256: string): PrincipalRow | undefined;
|
|
502
|
+
/** True if the origin belongs to a stored principal or an unconsumed challenge (used for CORS echo only). */
|
|
503
|
+
isKnownOrigin(origin: string): boolean;
|
|
504
|
+
insertGrant(g: {
|
|
505
|
+
grantId: string;
|
|
506
|
+
principalId: string;
|
|
507
|
+
projectId: string;
|
|
508
|
+
pluginId: string;
|
|
509
|
+
operationId: string;
|
|
510
|
+
maxEffectClass: string;
|
|
511
|
+
expiresAtIso: string;
|
|
512
|
+
requiresConfirmation: boolean;
|
|
513
|
+
consentMode?: ConsentModeName;
|
|
514
|
+
}): void;
|
|
515
|
+
/** Trusted-local revocation: deletes one stored grant. Returns true if a grant was removed. */
|
|
516
|
+
revokeGrant(grantId: string): boolean;
|
|
517
|
+
/** Trusted-local revocation: disables a principal so its bearer no longer authorizes anything. */
|
|
518
|
+
disablePrincipal(principalId: string): boolean;
|
|
519
|
+
principalExists(principalId: string): boolean;
|
|
520
|
+
findGrants(principalId: string, projectId: string, pluginId: string, operationId: string): GrantRow[];
|
|
521
|
+
/** Unexpired grants of one principal (for the workflow's operation list; C03 still decides admission). */
|
|
522
|
+
listActiveGrants(principalId: string, nowIso: string): ActiveGrantRow[];
|
|
523
|
+
/** Creates the installation and its stable principal in ONE transaction. The principal's initial token digest is random and already expired (unusable). */
|
|
524
|
+
createInstallation(i: {
|
|
525
|
+
installationId: string;
|
|
526
|
+
principalId: string;
|
|
527
|
+
extensionOrigin: string;
|
|
528
|
+
secretSha256: string;
|
|
529
|
+
placeholderTokenSha256: string;
|
|
530
|
+
nowIso: string;
|
|
531
|
+
}): void;
|
|
532
|
+
getInstallation(installationId: string): InstallationRow | undefined;
|
|
533
|
+
listInstallations(): InstallationRow[];
|
|
534
|
+
private toInstallation;
|
|
535
|
+
/**
|
|
536
|
+
* Atomic session issue: the installation must be unrevoked, not locked, bound to exactly this origin and present the right secret; then the principal's
|
|
537
|
+
* bearer digest is ROTATED (the previous bearer stops working at once). A wrong secret persists one failed attempt.
|
|
538
|
+
*/
|
|
539
|
+
issueInstallationSession(input: {
|
|
540
|
+
installationId: string;
|
|
541
|
+
origin: string;
|
|
542
|
+
secretSha256: string;
|
|
543
|
+
tokenSha256: string;
|
|
544
|
+
tokenExpiresAtIso: string;
|
|
545
|
+
maxFailedAttempts: number;
|
|
546
|
+
}): {
|
|
547
|
+
kind: 'OK';
|
|
548
|
+
principalId: string;
|
|
549
|
+
} | {
|
|
550
|
+
kind: 'REFUSED';
|
|
551
|
+
reason: 'UNKNOWN' | 'REVOKED' | 'ORIGIN' | 'LOCKED' | 'SECRET' | 'PRINCIPAL_DISABLED';
|
|
552
|
+
};
|
|
553
|
+
recordInstallationFailure(installationId: string): void;
|
|
554
|
+
/** Revocation is one-way: the installation is marked revoked and its principal disabled (every bearer and grant stops authorizing at once). */
|
|
555
|
+
revokeInstallation(installationId: string, nowIso: string): boolean;
|
|
556
|
+
/** Idempotent: the id is derived from principal + content + document identity, so a repeated gesture on the same selection returns the same capture. */
|
|
557
|
+
storeCapture(c: {
|
|
558
|
+
captureId: string;
|
|
559
|
+
principalId: string;
|
|
560
|
+
sha256: string;
|
|
561
|
+
bytes: number;
|
|
562
|
+
sealed: Uint8Array;
|
|
563
|
+
createdAt: string;
|
|
564
|
+
expiresAt: string;
|
|
565
|
+
}): {
|
|
566
|
+
row: CaptureRow;
|
|
567
|
+
duplicate: boolean;
|
|
568
|
+
};
|
|
569
|
+
private getCaptureRow;
|
|
570
|
+
getCapture(principalId: string, captureId: string): CaptureRow | undefined;
|
|
571
|
+
/** The newest capture of this principal that the user did not dismiss (expired ones are reported as expired by the caller). */
|
|
572
|
+
latestCapture(principalId: string): CaptureRow | undefined;
|
|
573
|
+
dismissCapture(principalId: string, captureId: string, nowIso: string): boolean;
|
|
574
|
+
/** Binds a capture to its ONE run (first writer wins). Returns the bound run id (which may be an earlier run on a duplicate request). */
|
|
575
|
+
bindCaptureRun(principalId: string, captureId: string, runId: string, consent: ConsentModeName): string | undefined;
|
|
576
|
+
/** Expired captures that never fed a run are deleted with their ciphertext. Consumed captures stay as the run's origin binding. */
|
|
577
|
+
purgeExpiredCaptures(nowIso: string): number;
|
|
578
|
+
getReturnSnapshot(principalId: string, runId: string): ReturnSnapshotRow | undefined;
|
|
579
|
+
getReturnSnapshotById(principalId: string, returnId: string): ReturnSnapshotRow | undefined;
|
|
580
|
+
getCaptureByRun(principalId: string, runId: string): CaptureRow | undefined;
|
|
581
|
+
appendReturnTarget(returnId: string, reason: 'ORIGIN' | 'USER_REBIND', sealed: Uint8Array, nowIso: string): number;
|
|
582
|
+
latestReturnTarget(returnId: string): {
|
|
583
|
+
sequenceNo: number;
|
|
584
|
+
reason: string;
|
|
585
|
+
sealed: Uint8Array;
|
|
586
|
+
} | undefined;
|
|
587
|
+
latestReturnReceipt(returnId: string): {
|
|
588
|
+
state: ReturnStateName;
|
|
589
|
+
code: string | null;
|
|
590
|
+
sequenceNo: number;
|
|
591
|
+
} | undefined;
|
|
592
|
+
/** Appends one receipt if `allowed(current)` says the transition is legal; all inside one transaction. */
|
|
593
|
+
appendReturnReceipt(returnId: string, next: ReturnStateName, code: string | null, editor: string | null, nowIso: string, allowed: (current: ReturnStateName) => boolean): {
|
|
594
|
+
kind: 'OK';
|
|
595
|
+
state: ReturnStateName;
|
|
596
|
+
} | {
|
|
597
|
+
kind: 'REJECTED';
|
|
598
|
+
current: ReturnStateName;
|
|
599
|
+
};
|
|
600
|
+
countReturnTargets(returnId: string): number;
|
|
601
|
+
setPreference(principalId: string, p: {
|
|
602
|
+
projectId: string;
|
|
603
|
+
pluginId: string;
|
|
604
|
+
operationId: string;
|
|
605
|
+
}, nowIso: string): void;
|
|
606
|
+
getPreference(principalId: string): {
|
|
607
|
+
projectId: string;
|
|
608
|
+
pluginId: string;
|
|
609
|
+
operationId: string;
|
|
610
|
+
} | undefined;
|
|
611
|
+
reserveIntent(input: ReserveIntentInput): ReserveIntentResult;
|
|
612
|
+
private selectRunBy;
|
|
613
|
+
getRunForPrincipal(principalId: string, runId: string): RunRow | undefined;
|
|
614
|
+
/**
|
|
615
|
+
* Restart reconciliation: runs recorded as possibly executing become UNKNOWN exactly once.
|
|
616
|
+
* The caller supplies the shared lifecycle validator, which is invoked for every row; if it throws,
|
|
617
|
+
* the whole reconciliation rolls back. Never produces QUEUED/COMPLETED/FAILED and never launches anything.
|
|
618
|
+
*/
|
|
619
|
+
recoverUncertainRuns(uncertainStates: readonly LifecycleStateName[], validateTransition: (from: LifecycleStateName, to: LifecycleStateName) => void, reason: string, nowIso: string): number;
|
|
620
|
+
/** Appends one gap-free ordered event and updates the run state. Must run inside a transaction. */
|
|
621
|
+
private appendState;
|
|
622
|
+
insertApprovalChallenge(a: {
|
|
623
|
+
approvalId: string;
|
|
624
|
+
runId: string;
|
|
625
|
+
principalId: string;
|
|
626
|
+
codeSha256: string;
|
|
627
|
+
fingerprint: string;
|
|
628
|
+
expiresAtIso: string;
|
|
629
|
+
createdAtIso: string;
|
|
630
|
+
}): void;
|
|
631
|
+
principalIsEnabled(principalId: string): boolean;
|
|
632
|
+
/**
|
|
633
|
+
* Trusted-local lookup of the owning principal of one exact run id, for the attended operator console only.
|
|
634
|
+
* Not exposed over HTTP; there is no listing or search.
|
|
635
|
+
*/
|
|
636
|
+
getRunOwnerPrincipalId(runId: string): string | undefined;
|
|
637
|
+
getRunDetailForPrincipal(principalId: string, runId: string): RunDetail | undefined;
|
|
638
|
+
/**
|
|
639
|
+
* Single atomic decision point (BEGIN IMMEDIATE). `decide` runs inside the transaction on the
|
|
640
|
+
* committed row and returns a plan; policy lives in C03/C05, storage and ordering live here.
|
|
641
|
+
* If `decide` throws, or any write fails (including consuming the approval), everything rolls back.
|
|
642
|
+
*/
|
|
643
|
+
applyDecision(principalId: string, runId: string, approvalId: string | undefined, nowIso: string, decide: (run: RunDetail, approval: ApprovalRow | undefined) => DecisionPlan): DecisionResult;
|
|
644
|
+
/** Trusted in-process read of what a launch needs. Principal-bound; never exposed over HTTP. */
|
|
645
|
+
getRunExecutionInput(principalId: string, runId: string): RunExecutionInput | undefined;
|
|
646
|
+
private insertGit;
|
|
647
|
+
/**
|
|
648
|
+
* The launch commit point. In one BEGIN IMMEDIATE transaction: reads the committed run, whether it was ever launched and how many
|
|
649
|
+
* other runs are active on the same project, asks `decide` (C05 policy, including the C03 recheck) and applies the plan. A LAUNCH
|
|
650
|
+
* plan writes the lifecycle hops, the single launch record and the BEFORE Git observation together; only after this returns
|
|
651
|
+
* LAUNCH_COMMITTED may a process be created. If anything throws, nothing is written.
|
|
652
|
+
*/
|
|
653
|
+
commitLaunch(principalId: string, runId: string, nowIso: string, decide: (ctx: LaunchContext) => LaunchDecision): LaunchCommitResult;
|
|
654
|
+
/**
|
|
655
|
+
* Records the end of a launched run atomically: lifecycle hops, normalized output events, the outcome row and the AFTER Git
|
|
656
|
+
* observation. `decide` sees the committed state (a cancel may have been recorded meanwhile). A second outcome for the same run
|
|
657
|
+
* violates the primary key and rolls back.
|
|
658
|
+
*/
|
|
659
|
+
commitRunOutcome(runId: string, nowIso: string, decide: (run: RunRow) => OutcomeDecision): {
|
|
660
|
+
kind: 'NOT_FOUND';
|
|
661
|
+
} | {
|
|
662
|
+
kind: 'REJECTED';
|
|
663
|
+
code: string;
|
|
664
|
+
} | {
|
|
665
|
+
kind: 'RECORDED';
|
|
666
|
+
run: RunRow;
|
|
667
|
+
};
|
|
668
|
+
/** Trusted local evidence read for one exact run id (operator/report use; not exposed over HTTP). */
|
|
669
|
+
getRunEvidence(runId: string): RunEvidence;
|
|
670
|
+
/**
|
|
671
|
+
* SW-058: creates (once) or re-reads (idempotently) the immutable return snapshot of one run owned by `principalId`. Everything happens in one BEGIN
|
|
672
|
+
* IMMEDIATE transaction on committed rows. `decide` is the C08 policy (completed, clean, bounded, untruncated); a stored snapshot whose digest no longer
|
|
673
|
+
* matches its bytes, or that differs from what the committed evidence now yields, is a CONFLICT and is never overwritten or returned.
|
|
674
|
+
*/
|
|
675
|
+
prepareReturnSnapshot(principalId: string, runId: string, nowIso: string, decide: (run: RunDetail, evidence: RunEvidence) => ReturnDecision): ReturnPrepareResult;
|
|
676
|
+
insertProvisionedOperation(r: Omit<ProvisionedOperationRow, 'enabled' | 'disabledReason'>, nowIso: string): void;
|
|
677
|
+
listProvisionedOperations(): ProvisionedOperationRow[];
|
|
678
|
+
/** Disabling is one-way: there is no SQL path that sets enabled back to 1. */
|
|
679
|
+
disableProvisionedOperation(pluginId: string, operationId: string, reason: string, nowIso: string): boolean;
|
|
680
|
+
countEvents(runId: string): number;
|
|
681
|
+
insertCodingGrant(g: {
|
|
682
|
+
grantId: string;
|
|
683
|
+
principalId: string;
|
|
684
|
+
projectId: string;
|
|
685
|
+
runId: string;
|
|
686
|
+
operation: CodingOperationName;
|
|
687
|
+
effectClass: CodingEffectClassName;
|
|
688
|
+
scopeJson: string;
|
|
689
|
+
singleUse: boolean;
|
|
690
|
+
createdAtIso: string;
|
|
691
|
+
expiresAtIso: string;
|
|
692
|
+
}): void;
|
|
693
|
+
private codingGrantOf;
|
|
694
|
+
getCodingGrant(grantId: string): CodingGrantRow | undefined;
|
|
695
|
+
findCodingGrants(principalId: string, projectId: string, runId: string, operation: CodingOperationName): CodingGrantRow[];
|
|
696
|
+
/** Atomic single-use consumption: exactly one caller can ever win, and only while the grant is unrevoked and unexpired. */
|
|
697
|
+
consumeCodingGrant(grantId: string, nowIso: string): boolean;
|
|
698
|
+
revokeCodingGrant(grantId: string, nowIso: string): boolean;
|
|
699
|
+
revokeCodingGrantsForRun(runId: string, nowIso: string): number;
|
|
700
|
+
/** Returns 'DUPLICATE' (same run and digest already stored: a replay) instead of inserting a second row. */
|
|
701
|
+
insertCodingProposal(p: {
|
|
702
|
+
proposalId: string;
|
|
703
|
+
runId: string;
|
|
704
|
+
projectId: string;
|
|
705
|
+
principalId: string;
|
|
706
|
+
digest: string;
|
|
707
|
+
baseHead: string;
|
|
708
|
+
canonicalJson: string;
|
|
709
|
+
effectJson: string;
|
|
710
|
+
createdAtIso: string;
|
|
711
|
+
}): 'OK' | 'DUPLICATE';
|
|
712
|
+
private codingProposalOf;
|
|
713
|
+
getCodingProposal(proposalId: string): CodingProposalRow | undefined;
|
|
714
|
+
/** A committed reservation precedes every transport mutation. An unfinished reservation is uncertain and is never dispatched again. */
|
|
715
|
+
reserveCodingAction(proposalId: string, action: string, digest: string, at: string): 'NEW' | 'EXISTING' | 'CONFLICT';
|
|
716
|
+
finishCodingAction(proposalId: string, action: string, result: unknown): void;
|
|
717
|
+
readCodingActions(proposalId: string): {
|
|
718
|
+
action: string;
|
|
719
|
+
startedAt: string;
|
|
720
|
+
result: unknown | null;
|
|
721
|
+
}[];
|
|
722
|
+
unresolvedReviewedPatches(): string[];
|
|
723
|
+
unresolvedReviewedCommits(): string[];
|
|
724
|
+
findCodingProposalsByRun(runId: string): CodingProposalRow[];
|
|
725
|
+
findRecoverableCodingProposals(): string[];
|
|
726
|
+
/** Compare-and-set: moves the status only from one of the expected current states. Returns false when the proposal is in any other state (a concurrent or replayed transition). */
|
|
727
|
+
transitionCodingProposal(proposalId: string, from: readonly CodingProposalStatus[], to: CodingProposalStatus, nowIso: string): boolean;
|
|
728
|
+
/** Appends one hash-chained record (the chain head is read and extended inside one immediate transaction). Detail must be content-free and small. */
|
|
729
|
+
appendCodingEvent(e: {
|
|
730
|
+
at: string;
|
|
731
|
+
runId: string;
|
|
732
|
+
subjectKind: 'GRANT' | 'PROPOSAL' | 'APPLY' | 'TEST' | 'GIT' | 'COMMIT';
|
|
733
|
+
subjectId: string;
|
|
734
|
+
event: string;
|
|
735
|
+
decision?: 'ALLOWED' | 'DENIED';
|
|
736
|
+
detail?: Record<string, string | number | boolean | null>;
|
|
737
|
+
}): number;
|
|
738
|
+
/** The raw verified summary of a finished coding workflow, stored once and never changed (Copy Result serves exactly these bytes). */
|
|
739
|
+
insertCodingResult(r: {
|
|
740
|
+
resultId: string;
|
|
741
|
+
runId: string;
|
|
742
|
+
principalId: string;
|
|
743
|
+
proposalId: string;
|
|
744
|
+
text: string;
|
|
745
|
+
createdAtIso: string;
|
|
746
|
+
kind?: CodingResultRow['kind'];
|
|
747
|
+
}): CodingResultRow | 'DUPLICATE';
|
|
748
|
+
hasCodingResult(principalId: string, proposalId: string): boolean;
|
|
749
|
+
getCodingResultForPrincipal(principalId: string, proposalId: string, kind?: CodingResultKindV1): CodingResultRow | undefined;
|
|
750
|
+
/** SW-097 bounded read-only projection from existing tables. No raw output payloads or coding details. */
|
|
751
|
+
activityRows(runId: string): {
|
|
752
|
+
lifecycle: {
|
|
753
|
+
seq: number;
|
|
754
|
+
ts: string;
|
|
755
|
+
state: string;
|
|
756
|
+
}[];
|
|
757
|
+
execution: {
|
|
758
|
+
seq: number;
|
|
759
|
+
ts: string;
|
|
760
|
+
kind: string;
|
|
761
|
+
stage: string | null;
|
|
762
|
+
data: string;
|
|
763
|
+
}[];
|
|
764
|
+
coding: {
|
|
765
|
+
seq: number;
|
|
766
|
+
ts: string;
|
|
767
|
+
event: string;
|
|
768
|
+
decision: string | null;
|
|
769
|
+
}[];
|
|
770
|
+
cursor: string;
|
|
771
|
+
truncated: boolean;
|
|
772
|
+
};
|
|
773
|
+
/** Revision-only read: indexed source heads, without fetching event bodies. */
|
|
774
|
+
activityCursor(runId: string): string;
|
|
775
|
+
readCodingEvents(filter?: {
|
|
776
|
+
runId?: string;
|
|
777
|
+
subjectId?: string;
|
|
778
|
+
}): CodingEventRow[];
|
|
779
|
+
/** Recomputes the whole chain. ok=false names the first sequence number that does not verify. */
|
|
780
|
+
verifyCodingChain(): {
|
|
781
|
+
ok: boolean;
|
|
782
|
+
records: number;
|
|
783
|
+
brokenAtSeq: number | null;
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
//# sourceMappingURL=sqliteLedger.d.ts.map
|