@ornexus/neocortex 4.59.1
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/LICENSE +56 -0
- package/LICENSE-COMMERCIAL.md +70 -0
- package/README.md +58 -0
- package/dist/sbom.cdx.json +7067 -0
- package/docs/install/coderabbit-manual-setup.md +86 -0
- package/docs/install/installer-diagnostics.md +107 -0
- package/docs/install/linux-global-install.md +97 -0
- package/install.js +572 -0
- package/install.ps1 +2214 -0
- package/install.sh +2013 -0
- package/package.json +118 -0
- package/packages/client/dist/adapters/adapter-registry.d.ts +61 -0
- package/packages/client/dist/adapters/adapter-registry.js +1 -0
- package/packages/client/dist/adapters/antigravity-adapter.d.ts +18 -0
- package/packages/client/dist/adapters/antigravity-adapter.js +2 -0
- package/packages/client/dist/adapters/claude-code-adapter.d.ts +19 -0
- package/packages/client/dist/adapters/claude-code-adapter.js +3 -0
- package/packages/client/dist/adapters/codex-adapter.d.ts +19 -0
- package/packages/client/dist/adapters/codex-adapter.js +2 -0
- package/packages/client/dist/adapters/cursor-adapter.d.ts +19 -0
- package/packages/client/dist/adapters/cursor-adapter.js +4 -0
- package/packages/client/dist/adapters/gemini-adapter.d.ts +18 -0
- package/packages/client/dist/adapters/gemini-adapter.js +2 -0
- package/packages/client/dist/adapters/index.d.ts +19 -0
- package/packages/client/dist/adapters/index.js +1 -0
- package/packages/client/dist/adapters/platform-detector.d.ts +48 -0
- package/packages/client/dist/adapters/platform-detector.js +1 -0
- package/packages/client/dist/adapters/target-adapter.d.ts +70 -0
- package/packages/client/dist/adapters/target-adapter.js +0 -0
- package/packages/client/dist/adapters/vscode-adapter.d.ts +19 -0
- package/packages/client/dist/adapters/vscode-adapter.js +2 -0
- package/packages/client/dist/agent/refresh-stubs.d.ts +80 -0
- package/packages/client/dist/agent/refresh-stubs.js +2 -0
- package/packages/client/dist/agent/update-agent-yaml.d.ts +26 -0
- package/packages/client/dist/agent/update-agent-yaml.js +1 -0
- package/packages/client/dist/agent/update-description.d.ts +45 -0
- package/packages/client/dist/agent/update-description.js +1 -0
- package/packages/client/dist/cache/crypto-utils.d.ts +30 -0
- package/packages/client/dist/cache/crypto-utils.js +1 -0
- package/packages/client/dist/cache/encrypted-cache.d.ts +30 -0
- package/packages/client/dist/cache/encrypted-cache.js +1 -0
- package/packages/client/dist/cache/in-memory-asset-cache.d.ts +62 -0
- package/packages/client/dist/cache/in-memory-asset-cache.js +1 -0
- package/packages/client/dist/cache/index.d.ts +13 -0
- package/packages/client/dist/cache/index.js +1 -0
- package/packages/client/dist/cache/protected-pi-boundary.d.ts +19 -0
- package/packages/client/dist/cache/protected-pi-boundary.js +1 -0
- package/packages/client/dist/checkpoint/checkpoint-client-reader.d.ts +45 -0
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +2 -0
- package/packages/client/dist/checkpoint/index.d.ts +12 -0
- package/packages/client/dist/checkpoint/index.js +1 -0
- package/packages/client/dist/checkpoint/shared-checkpoint-types.d.ts +85 -0
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +1 -0
- package/packages/client/dist/cli.d.ts +14 -0
- package/packages/client/dist/cli.js +48 -0
- package/packages/client/dist/commands/activate.d.ts +55 -0
- package/packages/client/dist/commands/activate.js +8 -0
- package/packages/client/dist/commands/cache-status.d.ts +39 -0
- package/packages/client/dist/commands/cache-status.js +2 -0
- package/packages/client/dist/commands/invoke.d.ts +229 -0
- package/packages/client/dist/commands/invoke.js +63 -0
- package/packages/client/dist/commands/refresh-memory.d.ts +11 -0
- package/packages/client/dist/commands/refresh-memory.js +1 -0
- package/packages/client/dist/config/resolver-selection.d.ts +40 -0
- package/packages/client/dist/config/resolver-selection.js +1 -0
- package/packages/client/dist/config/secure-config.d.ts +78 -0
- package/packages/client/dist/config/secure-config.js +12 -0
- package/packages/client/dist/constants.d.ts +25 -0
- package/packages/client/dist/constants.js +1 -0
- package/packages/client/dist/context/context-collector.d.ts +28 -0
- package/packages/client/dist/context/context-collector.js +2 -0
- package/packages/client/dist/context/context-sanitizer.d.ts +28 -0
- package/packages/client/dist/context/context-sanitizer.js +1 -0
- package/packages/client/dist/continuity/continuity-client-state-store.d.ts +183 -0
- package/packages/client/dist/continuity/continuity-client-state-store.js +1 -0
- package/packages/client/dist/continuity/invoke-hooks.d.ts +18 -0
- package/packages/client/dist/continuity/invoke-hooks.js +1 -0
- package/packages/client/dist/continuity/migrations/001-initial-schema.d.ts +11 -0
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +263 -0
- package/packages/client/dist/continuity/sqlite-store.d.ts +409 -0
- package/packages/client/dist/continuity/sqlite-store.js +226 -0
- package/packages/client/dist/errors/error-messages.d.ts +40 -0
- package/packages/client/dist/errors/error-messages.js +2 -0
- package/packages/client/dist/graph-retrieval/pre-command-hook.d.ts +31 -0
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +1 -0
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.d.ts +77 -0
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +1 -0
- package/packages/client/dist/i18n/first-run.d.ts +23 -0
- package/packages/client/dist/i18n/first-run.js +2 -0
- package/packages/client/dist/index.d.ts +56 -0
- package/packages/client/dist/index.js +1 -0
- package/packages/client/dist/license/index.d.ts +5 -0
- package/packages/client/dist/license/index.js +1 -0
- package/packages/client/dist/license/license-client.d.ts +79 -0
- package/packages/client/dist/license/license-client.js +1 -0
- package/packages/client/dist/machine/fingerprint.d.ts +34 -0
- package/packages/client/dist/machine/fingerprint.js +2 -0
- package/packages/client/dist/machine/index.d.ts +5 -0
- package/packages/client/dist/machine/index.js +1 -0
- package/packages/client/dist/memory/project-memory-writer.d.ts +74 -0
- package/packages/client/dist/memory/project-memory-writer.js +36 -0
- package/packages/client/dist/memory/shared-project-memory-types.d.ts +370 -0
- package/packages/client/dist/memory/shared-project-memory-types.js +2 -0
- package/packages/client/dist/policy/architecture-policy.d.ts +40 -0
- package/packages/client/dist/policy/architecture-policy.js +2 -0
- package/packages/client/dist/policy/index.d.ts +8 -0
- package/packages/client/dist/policy/index.js +1 -0
- package/packages/client/dist/policy/shared-policy-types.d.ts +89 -0
- package/packages/client/dist/policy/shared-policy-types.js +0 -0
- package/packages/client/dist/resilience/circuit-breaker.d.ts +70 -0
- package/packages/client/dist/resilience/circuit-breaker.js +1 -0
- package/packages/client/dist/resilience/degradation-manager.d.ts +67 -0
- package/packages/client/dist/resilience/degradation-manager.js +1 -0
- package/packages/client/dist/resilience/freshness-indicator.d.ts +59 -0
- package/packages/client/dist/resilience/freshness-indicator.js +1 -0
- package/packages/client/dist/resilience/index.d.ts +8 -0
- package/packages/client/dist/resilience/index.js +1 -0
- package/packages/client/dist/resilience/recovery-detector.d.ts +59 -0
- package/packages/client/dist/resilience/recovery-detector.js +1 -0
- package/packages/client/dist/resolvers/asset-resolver.d.ts +79 -0
- package/packages/client/dist/resolvers/asset-resolver.js +0 -0
- package/packages/client/dist/resolvers/local-resolver.d.ts +26 -0
- package/packages/client/dist/resolvers/local-resolver.js +8 -0
- package/packages/client/dist/resolvers/remote-resolver.d.ts +91 -0
- package/packages/client/dist/resolvers/remote-resolver.js +1 -0
- package/packages/client/dist/runner/cli.d.ts +121 -0
- package/packages/client/dist/runner/cli.js +20 -0
- package/packages/client/dist/runner/scheduler.d.ts +116 -0
- package/packages/client/dist/runner/scheduler.js +6 -0
- package/packages/client/dist/runner-cli.d.ts +9 -0
- package/packages/client/dist/runner-cli.js +3 -0
- package/packages/client/dist/state/project-state-snapshot.d.ts +15 -0
- package/packages/client/dist/state/project-state-snapshot.js +1 -0
- package/packages/client/dist/state/state-json-repair.d.ts +17 -0
- package/packages/client/dist/state/state-json-repair.js +3 -0
- package/packages/client/dist/telemetry/index.d.ts +5 -0
- package/packages/client/dist/telemetry/index.js +1 -0
- package/packages/client/dist/telemetry/offline-queue.d.ts +57 -0
- package/packages/client/dist/telemetry/offline-queue.js +1 -0
- package/packages/client/dist/tier/index.d.ts +5 -0
- package/packages/client/dist/tier/index.js +1 -0
- package/packages/client/dist/tier/tier-aware-client.d.ts +105 -0
- package/packages/client/dist/tier/tier-aware-client.js +1 -0
- package/packages/client/dist/types/index.d.ts +140 -0
- package/packages/client/dist/types/index.js +1 -0
- package/packages/client/dist/yoloop/discovery-hook.d.ts +85 -0
- package/packages/client/dist/yoloop/discovery-hook.js +2 -0
- package/packages/client/dist/yoloop/index.d.ts +10 -0
- package/packages/client/dist/yoloop/index.js +1 -0
- package/packages/client/dist/yoloop/invoke-hooks.d.ts +125 -0
- package/packages/client/dist/yoloop/invoke-hooks.js +5 -0
- package/packages/client/dist/yoloop/shared-discover-epics.d.ts +289 -0
- package/packages/client/dist/yoloop/shared-discover-epics.js +1 -0
- package/packages/client/dist/yoloop/shared-yoloop-types.d.ts +172 -0
- package/packages/client/dist/yoloop/shared-yoloop-types.js +1 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +124 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1 -0
- package/postinstall.js +754 -0
- package/targets-stubs/antigravity/README.md +36 -0
- package/targets-stubs/antigravity/gemini.md +29 -0
- package/targets-stubs/antigravity/install-antigravity.sh +153 -0
- package/targets-stubs/antigravity/mcp-config.json +30 -0
- package/targets-stubs/antigravity/skill/SKILL.md +159 -0
- package/targets-stubs/claude-code/.mcp.json +32 -0
- package/targets-stubs/claude-code/README.md +20 -0
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +42 -0
- package/targets-stubs/claude-code/neocortex-root.md +310 -0
- package/targets-stubs/claude-code/neocortex.agent.yaml +42 -0
- package/targets-stubs/claude-code/neocortex.md +378 -0
- package/targets-stubs/codex/AGENTS.md +244 -0
- package/targets-stubs/codex/README.md +47 -0
- package/targets-stubs/codex/config-mcp.toml +22 -0
- package/targets-stubs/codex/install-codex.sh +63 -0
- package/targets-stubs/codex/neocortex.toml +29 -0
- package/targets-stubs/cursor/README.md +33 -0
- package/targets-stubs/cursor/agent.md +204 -0
- package/targets-stubs/cursor/install-cursor.sh +50 -0
- package/targets-stubs/cursor/mcp.json +30 -0
- package/targets-stubs/gemini-cli/README.md +34 -0
- package/targets-stubs/gemini-cli/agent.md +234 -0
- package/targets-stubs/gemini-cli/agents/neocortex.md +54 -0
- package/targets-stubs/gemini-cli/gemini.md +46 -0
- package/targets-stubs/gemini-cli/install-gemini.sh +70 -0
- package/targets-stubs/gemini-cli/settings-mcp.json +30 -0
- package/targets-stubs/kimi/mcp.json +33 -0
- package/targets-stubs/kimi/neocortex.md +54 -0
- package/targets-stubs/lib/mcp-merge.js +189 -0
- package/targets-stubs/openclaw/README.md +12 -0
- package/targets-stubs/openclaw/SKILL.md +88 -0
- package/targets-stubs/opencode/neocortex-root.md +261 -0
- package/targets-stubs/opencode/neocortex.md +59 -0
- package/targets-stubs/opencode/opencode-mcp.json +35 -0
- package/targets-stubs/vscode/README.md +34 -0
- package/targets-stubs/vscode/copilot-instructions.md +47 -0
- package/targets-stubs/vscode/install-vscode.sh +72 -0
- package/targets-stubs/vscode/mcp.json +36 -0
- package/targets-stubs/vscode/neocortex.agent.md +245 -0
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* P180.04 -- Local SQLite continuity store, migrations and integrity checks.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CONTINUITY_SQLITE_RELATIVE_DIR: ".neocortex/continuity";
|
|
8
|
+
export declare const CONTINUITY_SQLITE_FILENAME: "continuity.sqlite";
|
|
9
|
+
export declare const CONTINUITY_SQLITE_SCHEMA_VERSION: 1;
|
|
10
|
+
export declare const DEFAULT_CONTINUITY_SQLITE_BUSY_TIMEOUT_MS = 5000;
|
|
11
|
+
export declare const SQLITE_ADAPTER_INSTALL_GUIDANCE = "Install the optional Enterprise continuity SQLite adapter with `npm install --workspace packages/client better-sqlite3 --include=optional` or reinstall Neocortex with optional dependencies enabled.";
|
|
12
|
+
export type ContinuitySqliteStoreErrorCode = 'sqlite-adapter-unavailable' | 'sqlite-integrity-failed' | 'sqlite-migration-failed' | 'sqlite-migration-conflict' | 'sqlite-foreign-key-failed' | 'sqlite-public-safety-rejected' | 'sqlite-mutation-blocked';
|
|
13
|
+
export declare class ContinuitySqliteStoreError extends Error {
|
|
14
|
+
readonly code: ContinuitySqliteStoreErrorCode;
|
|
15
|
+
readonly reasonCode: ContinuitySqliteStoreErrorCode;
|
|
16
|
+
readonly guidance?: string;
|
|
17
|
+
readonly mutationBlocked: boolean;
|
|
18
|
+
readonly cause?: unknown;
|
|
19
|
+
constructor(code: ContinuitySqliteStoreErrorCode, message: string, options?: {
|
|
20
|
+
readonly guidance?: string;
|
|
21
|
+
readonly cause?: unknown;
|
|
22
|
+
readonly mutationBlocked?: boolean;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export interface ContinuitySqliteStatementRunResult {
|
|
26
|
+
readonly changes: number;
|
|
27
|
+
readonly lastInsertRowid?: number | bigint;
|
|
28
|
+
}
|
|
29
|
+
export interface ContinuitySqliteStatement {
|
|
30
|
+
run(...params: readonly unknown[]): ContinuitySqliteStatementRunResult;
|
|
31
|
+
get(...params: readonly unknown[]): unknown;
|
|
32
|
+
all(...params: readonly unknown[]): readonly unknown[];
|
|
33
|
+
}
|
|
34
|
+
export interface ContinuitySqliteDatabase {
|
|
35
|
+
pragma(source: string, options?: {
|
|
36
|
+
readonly simple?: boolean;
|
|
37
|
+
}): unknown;
|
|
38
|
+
exec(source: string): void;
|
|
39
|
+
prepare(source: string): ContinuitySqliteStatement;
|
|
40
|
+
transaction<T extends (...args: never[]) => unknown>(fn: T): T;
|
|
41
|
+
close(): void;
|
|
42
|
+
}
|
|
43
|
+
export interface ContinuitySqliteAdapter {
|
|
44
|
+
readonly adapterName: 'better-sqlite3' | 'test-adapter' | string;
|
|
45
|
+
open(filePath: string, options?: {
|
|
46
|
+
readonly fileMustExist?: boolean;
|
|
47
|
+
}): ContinuitySqliteDatabase;
|
|
48
|
+
}
|
|
49
|
+
export type ContinuitySqliteAdapterLoadResult = {
|
|
50
|
+
readonly ok: true;
|
|
51
|
+
readonly adapter: ContinuitySqliteAdapter;
|
|
52
|
+
} | {
|
|
53
|
+
readonly ok: false;
|
|
54
|
+
readonly error: ContinuitySqliteStoreError;
|
|
55
|
+
};
|
|
56
|
+
export type ContinuitySqliteDynamicImporter = (specifier: string) => Promise<unknown>;
|
|
57
|
+
export interface OpenContinuitySqliteStoreOptions {
|
|
58
|
+
readonly projectRoot: string;
|
|
59
|
+
readonly adapter?: ContinuitySqliteAdapter;
|
|
60
|
+
readonly adapterLoader?: () => Promise<ContinuitySqliteAdapterLoadResult>;
|
|
61
|
+
readonly busyTimeoutMs?: number;
|
|
62
|
+
readonly integrityCheck?: boolean;
|
|
63
|
+
readonly now?: () => string;
|
|
64
|
+
}
|
|
65
|
+
export interface ContinuityJobWriteInput {
|
|
66
|
+
readonly jobId: string;
|
|
67
|
+
readonly kind: 'goal' | 'loop' | 'runner' | 'jobs';
|
|
68
|
+
readonly status: string;
|
|
69
|
+
readonly createdAt: string;
|
|
70
|
+
readonly updatedAt: string;
|
|
71
|
+
readonly summary?: string;
|
|
72
|
+
readonly reasonCode?: string;
|
|
73
|
+
readonly nextRunAt?: string;
|
|
74
|
+
readonly goalId?: string;
|
|
75
|
+
readonly loopId?: string;
|
|
76
|
+
readonly campaignId?: string;
|
|
77
|
+
readonly operationId?: string;
|
|
78
|
+
readonly idempotencyKey?: string;
|
|
79
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
80
|
+
}
|
|
81
|
+
export interface ContinuityEventWriteInput {
|
|
82
|
+
readonly eventId: string;
|
|
83
|
+
readonly jobId: string;
|
|
84
|
+
readonly operationId: string;
|
|
85
|
+
readonly idempotencyKey?: string;
|
|
86
|
+
readonly sequence?: number;
|
|
87
|
+
readonly type: string;
|
|
88
|
+
readonly summary: string;
|
|
89
|
+
readonly reasonCode?: string;
|
|
90
|
+
readonly createdAt: string;
|
|
91
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
92
|
+
}
|
|
93
|
+
export interface ContinuityReceiptWriteInput {
|
|
94
|
+
readonly receiptId: string;
|
|
95
|
+
readonly jobId: string;
|
|
96
|
+
readonly operationId?: string;
|
|
97
|
+
readonly idempotencyKey?: string;
|
|
98
|
+
readonly status: 'accepted' | 'applied' | 'ignored' | 'failed' | 'deferred';
|
|
99
|
+
readonly reasonCode?: string;
|
|
100
|
+
readonly appliedOperationIds?: readonly string[];
|
|
101
|
+
readonly ignoredOperationIds?: readonly string[];
|
|
102
|
+
readonly createdAt: string;
|
|
103
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
104
|
+
}
|
|
105
|
+
export interface ContinuitySqliteWriteResult {
|
|
106
|
+
readonly inserted: boolean;
|
|
107
|
+
readonly replay: boolean;
|
|
108
|
+
readonly changes: number;
|
|
109
|
+
}
|
|
110
|
+
export interface ContinuityJobStatusUpdateInput {
|
|
111
|
+
readonly jobId: string;
|
|
112
|
+
readonly status: string;
|
|
113
|
+
readonly updatedAt: string;
|
|
114
|
+
readonly reasonCode?: string;
|
|
115
|
+
readonly nextRunAt?: string | null;
|
|
116
|
+
}
|
|
117
|
+
export interface ContinuityScheduleWriteInput {
|
|
118
|
+
readonly jobId: string;
|
|
119
|
+
readonly scheduledAt: string;
|
|
120
|
+
readonly updatedAt: string;
|
|
121
|
+
readonly reasonCode?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface ContinuityLeaseWriteInput {
|
|
124
|
+
readonly leaseId: string;
|
|
125
|
+
readonly jobId: string;
|
|
126
|
+
readonly runnerId: string;
|
|
127
|
+
readonly acquiredAt: string;
|
|
128
|
+
readonly expiresAt: string;
|
|
129
|
+
readonly operationId?: string;
|
|
130
|
+
readonly idempotencyKey?: string;
|
|
131
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
132
|
+
}
|
|
133
|
+
export interface ContinuityLeaseReleaseInput {
|
|
134
|
+
readonly leaseId: string;
|
|
135
|
+
readonly releasedAt: string;
|
|
136
|
+
readonly reasonCode?: string;
|
|
137
|
+
}
|
|
138
|
+
export interface ContinuityStateSnapshotWriteInput {
|
|
139
|
+
readonly snapshotId: string;
|
|
140
|
+
readonly jobId?: string;
|
|
141
|
+
readonly kind: string;
|
|
142
|
+
readonly relativePath?: string;
|
|
143
|
+
readonly sha256?: string;
|
|
144
|
+
readonly summary?: string;
|
|
145
|
+
readonly capturedAt: string;
|
|
146
|
+
readonly operationId?: string;
|
|
147
|
+
readonly idempotencyKey?: string;
|
|
148
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
149
|
+
}
|
|
150
|
+
export interface ContinuityArtifactWriteInput {
|
|
151
|
+
readonly artifactId: string;
|
|
152
|
+
readonly jobId?: string;
|
|
153
|
+
readonly kind: string;
|
|
154
|
+
readonly relativePath: string;
|
|
155
|
+
readonly sha256?: string;
|
|
156
|
+
readonly summary?: string;
|
|
157
|
+
readonly operationId?: string;
|
|
158
|
+
readonly idempotencyKey?: string;
|
|
159
|
+
readonly createdAt: string;
|
|
160
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
161
|
+
}
|
|
162
|
+
export interface ContinuityOutboxWriteInput {
|
|
163
|
+
readonly outboxId: string;
|
|
164
|
+
readonly jobId?: string;
|
|
165
|
+
readonly operationId: string;
|
|
166
|
+
readonly idempotencyKey?: string;
|
|
167
|
+
readonly type: string;
|
|
168
|
+
readonly status?: 'pending' | 'sent' | 'acked' | 'failed' | 'dead_letter';
|
|
169
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
170
|
+
readonly retryCount?: number;
|
|
171
|
+
readonly nextAttemptAt?: string;
|
|
172
|
+
readonly lastErrorCode?: string;
|
|
173
|
+
readonly createdAt: string;
|
|
174
|
+
readonly updatedAt: string;
|
|
175
|
+
}
|
|
176
|
+
export interface ContinuityGoalCampaignWriteInput {
|
|
177
|
+
readonly campaignId: string;
|
|
178
|
+
readonly jobId: string;
|
|
179
|
+
readonly status: string;
|
|
180
|
+
readonly title?: string;
|
|
181
|
+
readonly publicSummary?: string;
|
|
182
|
+
readonly reasonCode?: string;
|
|
183
|
+
readonly createdAt: string;
|
|
184
|
+
readonly updatedAt: string;
|
|
185
|
+
readonly operationId?: string;
|
|
186
|
+
readonly idempotencyKey?: string;
|
|
187
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
188
|
+
}
|
|
189
|
+
export interface ContinuityGoalLedgerItemWriteInput {
|
|
190
|
+
readonly itemId: string;
|
|
191
|
+
readonly campaignId: string;
|
|
192
|
+
readonly jobId: string;
|
|
193
|
+
readonly itemType: string;
|
|
194
|
+
readonly status: string;
|
|
195
|
+
readonly summary: string;
|
|
196
|
+
readonly reasonCode?: string;
|
|
197
|
+
readonly createdAt: string;
|
|
198
|
+
readonly updatedAt: string;
|
|
199
|
+
readonly operationId?: string;
|
|
200
|
+
readonly idempotencyKey?: string;
|
|
201
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
202
|
+
}
|
|
203
|
+
export interface ContinuityGoalVerifierWriteInput {
|
|
204
|
+
readonly verifierId: string;
|
|
205
|
+
readonly campaignId: string;
|
|
206
|
+
readonly jobId: string;
|
|
207
|
+
readonly kind: string;
|
|
208
|
+
readonly status: string;
|
|
209
|
+
readonly summary?: string;
|
|
210
|
+
readonly reasonCode?: string;
|
|
211
|
+
readonly lastCheckedAt?: string;
|
|
212
|
+
readonly operationId?: string;
|
|
213
|
+
readonly idempotencyKey?: string;
|
|
214
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
215
|
+
}
|
|
216
|
+
export interface ContinuityGoalReviewGateWriteInput {
|
|
217
|
+
readonly gateId: string;
|
|
218
|
+
readonly campaignId: string;
|
|
219
|
+
readonly jobId: string;
|
|
220
|
+
readonly status: string;
|
|
221
|
+
readonly summary?: string;
|
|
222
|
+
readonly required: boolean;
|
|
223
|
+
readonly reasonCode?: string;
|
|
224
|
+
readonly operationId?: string;
|
|
225
|
+
readonly idempotencyKey?: string;
|
|
226
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
227
|
+
}
|
|
228
|
+
export interface ContinuityOperationAuditInput {
|
|
229
|
+
readonly receiptId: string;
|
|
230
|
+
readonly jobId: string;
|
|
231
|
+
readonly operationId: string;
|
|
232
|
+
readonly idempotencyKey?: string;
|
|
233
|
+
readonly status: 'accepted' | 'applied' | 'ignored' | 'failed' | 'deferred';
|
|
234
|
+
readonly reasonCode?: string;
|
|
235
|
+
readonly appliedOperationIds?: readonly string[];
|
|
236
|
+
readonly ignoredOperationIds?: readonly string[];
|
|
237
|
+
readonly createdAt: string;
|
|
238
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
239
|
+
}
|
|
240
|
+
export interface ContinuitySnapshotQueryOptions {
|
|
241
|
+
readonly nowIso: string;
|
|
242
|
+
readonly jobLimit: number;
|
|
243
|
+
readonly staleLeaseLimit: number;
|
|
244
|
+
readonly receiptLimit: number;
|
|
245
|
+
readonly eventLimit: number;
|
|
246
|
+
readonly snapshotLimit: number;
|
|
247
|
+
}
|
|
248
|
+
export interface ContinuitySnapshotJobRow {
|
|
249
|
+
readonly job_id: string;
|
|
250
|
+
readonly kind: string;
|
|
251
|
+
readonly status: string;
|
|
252
|
+
readonly summary: string | null;
|
|
253
|
+
readonly reason_code: string | null;
|
|
254
|
+
readonly created_at: string;
|
|
255
|
+
readonly updated_at: string;
|
|
256
|
+
readonly next_run_at: string | null;
|
|
257
|
+
readonly metadata_json: string | null;
|
|
258
|
+
readonly iteration?: number;
|
|
259
|
+
readonly goal_ledger_item_count?: number;
|
|
260
|
+
readonly blocked_goal_ledger_item_count?: number;
|
|
261
|
+
readonly security_issue_blocked_count?: number;
|
|
262
|
+
readonly goal_verifier_count?: number;
|
|
263
|
+
readonly failed_verifier_count?: number;
|
|
264
|
+
readonly unavailable_verifier_count?: number;
|
|
265
|
+
readonly goal_review_gate_count?: number;
|
|
266
|
+
readonly failed_required_review_gate_count?: number;
|
|
267
|
+
}
|
|
268
|
+
export interface ContinuitySnapshotLeaseRow {
|
|
269
|
+
readonly lease_id: string;
|
|
270
|
+
readonly job_id: string;
|
|
271
|
+
readonly runner_id: string;
|
|
272
|
+
readonly expires_at: string;
|
|
273
|
+
}
|
|
274
|
+
export interface ContinuitySnapshotReceiptRow {
|
|
275
|
+
readonly receipt_id: string;
|
|
276
|
+
readonly job_id: string;
|
|
277
|
+
readonly operation_id: string | null;
|
|
278
|
+
readonly status: string;
|
|
279
|
+
readonly reason_code: string | null;
|
|
280
|
+
readonly created_at: string;
|
|
281
|
+
readonly metadata_json: string | null;
|
|
282
|
+
}
|
|
283
|
+
export interface ContinuitySnapshotEventRow {
|
|
284
|
+
readonly event_id: string;
|
|
285
|
+
readonly job_id: string;
|
|
286
|
+
readonly operation_id: string;
|
|
287
|
+
readonly type: string;
|
|
288
|
+
readonly summary: string;
|
|
289
|
+
readonly reason_code: string | null;
|
|
290
|
+
readonly created_at: string;
|
|
291
|
+
}
|
|
292
|
+
export interface ContinuitySnapshotStateSnapshotRow {
|
|
293
|
+
readonly snapshot_id: string;
|
|
294
|
+
readonly job_id: string | null;
|
|
295
|
+
readonly kind: string;
|
|
296
|
+
readonly relative_path: string | null;
|
|
297
|
+
readonly sha256: string | null;
|
|
298
|
+
readonly summary: string | null;
|
|
299
|
+
readonly captured_at: string;
|
|
300
|
+
readonly operation_id: string | null;
|
|
301
|
+
readonly metadata_json: string | null;
|
|
302
|
+
}
|
|
303
|
+
export interface ContinuitySnapshotQueryResult {
|
|
304
|
+
readonly schemaVersion: number;
|
|
305
|
+
readonly jobs: readonly ContinuitySnapshotJobRow[];
|
|
306
|
+
readonly staleLeases: readonly ContinuitySnapshotLeaseRow[];
|
|
307
|
+
readonly receipts: readonly ContinuitySnapshotReceiptRow[];
|
|
308
|
+
readonly events: readonly ContinuitySnapshotEventRow[];
|
|
309
|
+
readonly stateSnapshots: readonly ContinuitySnapshotStateSnapshotRow[];
|
|
310
|
+
readonly counts: Readonly<Record<string, number>>;
|
|
311
|
+
readonly outboxCounts: Readonly<Record<string, number>>;
|
|
312
|
+
}
|
|
313
|
+
export interface ContinuityDueJobRow {
|
|
314
|
+
readonly job_id: string;
|
|
315
|
+
readonly kind: string;
|
|
316
|
+
readonly status: string;
|
|
317
|
+
readonly summary: string | null;
|
|
318
|
+
readonly reason_code: string | null;
|
|
319
|
+
readonly created_at: string;
|
|
320
|
+
readonly updated_at: string;
|
|
321
|
+
readonly next_run_at: string | null;
|
|
322
|
+
readonly metadata_json: string | null;
|
|
323
|
+
readonly iteration?: number;
|
|
324
|
+
readonly active_lease_count?: number;
|
|
325
|
+
}
|
|
326
|
+
export interface ContinuityDueJobQueryOptions {
|
|
327
|
+
readonly nowIso: string;
|
|
328
|
+
readonly limit: number;
|
|
329
|
+
}
|
|
330
|
+
export interface ContinuityStaleLeaseRecoveryOptions {
|
|
331
|
+
readonly nowIso: string;
|
|
332
|
+
readonly staleAfterMs: number;
|
|
333
|
+
readonly limit: number;
|
|
334
|
+
}
|
|
335
|
+
export interface ContinuityStaleLeaseRecoveryResult {
|
|
336
|
+
readonly recoveredLeaseIds: readonly string[];
|
|
337
|
+
readonly safeExpiredAtOrBefore: string;
|
|
338
|
+
readonly changes: number;
|
|
339
|
+
}
|
|
340
|
+
export interface ContinuityOutboxRetryOptions {
|
|
341
|
+
readonly nowIso: string;
|
|
342
|
+
readonly limit: number;
|
|
343
|
+
readonly statuses?: readonly ('failed' | 'dead_letter')[];
|
|
344
|
+
readonly nextAttemptAt?: string;
|
|
345
|
+
readonly reasonCode?: string;
|
|
346
|
+
}
|
|
347
|
+
export interface ContinuityOutboxRetryResult {
|
|
348
|
+
readonly retriedOutboxIds: readonly string[];
|
|
349
|
+
readonly changes: number;
|
|
350
|
+
readonly reasonCode: string;
|
|
351
|
+
readonly publicSafe: true;
|
|
352
|
+
}
|
|
353
|
+
declare const CONTINUITY_TABLES: readonly ["continuity_migrations", "jobs", "job_leases", "job_events", "job_receipts", "goal_campaigns", "goal_ledger_items", "goal_verifiers", "goal_review_gates", "loop_jobs", "artifacts", "state_snapshots", "runner_config", "outbox"];
|
|
354
|
+
export type ContinuitySqliteTable = (typeof CONTINUITY_TABLES)[number];
|
|
355
|
+
export declare function loadBetterSqlite3Adapter(importer?: ContinuitySqliteDynamicImporter): Promise<ContinuitySqliteAdapterLoadResult>;
|
|
356
|
+
export declare function continuitySqliteStorePath(projectRoot: string): string;
|
|
357
|
+
export declare function openContinuitySqliteStore(options: OpenContinuitySqliteStoreOptions): Promise<ContinuitySqliteStore>;
|
|
358
|
+
export declare class ContinuitySqliteStore {
|
|
359
|
+
readonly filePath: string;
|
|
360
|
+
readonly adapterName: string;
|
|
361
|
+
private readonly db;
|
|
362
|
+
private readonly busyTimeoutMs;
|
|
363
|
+
private readonly integrityCheck;
|
|
364
|
+
private readonly now;
|
|
365
|
+
private mutationBlocked;
|
|
366
|
+
constructor(options: {
|
|
367
|
+
readonly db: ContinuitySqliteDatabase;
|
|
368
|
+
readonly filePath: string;
|
|
369
|
+
readonly adapterName: string;
|
|
370
|
+
readonly busyTimeoutMs: number;
|
|
371
|
+
readonly integrityCheck: boolean;
|
|
372
|
+
readonly now: () => string;
|
|
373
|
+
});
|
|
374
|
+
initialize(): void;
|
|
375
|
+
close(): void;
|
|
376
|
+
pragmaValue(source: string): unknown;
|
|
377
|
+
runIntegrityCheck(): void;
|
|
378
|
+
getSchemaVersion(): number;
|
|
379
|
+
countRows(table: ContinuitySqliteTable): number;
|
|
380
|
+
recordJob(input: ContinuityJobWriteInput): ContinuitySqliteWriteResult;
|
|
381
|
+
appendEvent(input: ContinuityEventWriteInput): ContinuitySqliteWriteResult;
|
|
382
|
+
appendReceipt(input: ContinuityReceiptWriteInput): ContinuitySqliteWriteResult;
|
|
383
|
+
updateJobStatus(input: ContinuityJobStatusUpdateInput): ContinuitySqliteWriteResult;
|
|
384
|
+
scheduleNextTick(input: ContinuityScheduleWriteInput): ContinuitySqliteWriteResult;
|
|
385
|
+
acquireLease(input: ContinuityLeaseWriteInput): ContinuitySqliteWriteResult;
|
|
386
|
+
releaseLease(input: ContinuityLeaseReleaseInput): ContinuitySqliteWriteResult;
|
|
387
|
+
recordStateSnapshot(input: ContinuityStateSnapshotWriteInput): ContinuitySqliteWriteResult;
|
|
388
|
+
recordArtifact(input: ContinuityArtifactWriteInput): ContinuitySqliteWriteResult;
|
|
389
|
+
enqueueOutbox(input: ContinuityOutboxWriteInput): ContinuitySqliteWriteResult;
|
|
390
|
+
retryOutboxEntries(options: ContinuityOutboxRetryOptions): ContinuityOutboxRetryResult;
|
|
391
|
+
upsertGoalCampaign(input: ContinuityGoalCampaignWriteInput): ContinuitySqliteWriteResult;
|
|
392
|
+
upsertGoalLedgerItem(input: ContinuityGoalLedgerItemWriteInput): ContinuitySqliteWriteResult;
|
|
393
|
+
upsertGoalVerifier(input: ContinuityGoalVerifierWriteInput): ContinuitySqliteWriteResult;
|
|
394
|
+
upsertGoalReviewGate(input: ContinuityGoalReviewGateWriteInput): ContinuitySqliteWriteResult;
|
|
395
|
+
recordOperationAudit(input: ContinuityOperationAuditInput): ContinuitySqliteWriteResult;
|
|
396
|
+
hasOperationRef(operationId: string, idempotencyKey?: string): boolean;
|
|
397
|
+
jobExists(jobId: string): boolean;
|
|
398
|
+
runInTransaction<T>(fn: () => T): T;
|
|
399
|
+
collectSnapshotRows(options: ContinuitySnapshotQueryOptions): ContinuitySnapshotQueryResult;
|
|
400
|
+
listDueJobs(options: ContinuityDueJobQueryOptions): readonly ContinuityDueJobRow[];
|
|
401
|
+
recoverStaleLeases(options: ContinuityStaleLeaseRecoveryOptions): ContinuityStaleLeaseRecoveryResult;
|
|
402
|
+
private ensureGoalCampaign;
|
|
403
|
+
private configureConnection;
|
|
404
|
+
private ensureMigrationTable;
|
|
405
|
+
private applyMigrations;
|
|
406
|
+
private assertCanMutate;
|
|
407
|
+
private toWriteResult;
|
|
408
|
+
}
|
|
409
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import{createHash as T}from"node:crypto";import{chmodSync as b,existsSync as C,mkdirSync as N}from"node:fs";import{join as y}from"node:path";import{INITIAL_CONTINUITY_SQLITE_MIGRATION as O}from"./migrations/001-initial-schema.js";const f=".neocortex/continuity",A="continuity.sqlite",K=1,j=5e3,I="Install the optional Enterprise continuity SQLite adapter with `npm install --workspace packages/client better-sqlite3 --include=optional` or reinstall Neocortex with optional dependencies enabled.";class i extends Error{code;reasonCode;guidance;mutationBlocked;cause;constructor(e,t,a={}){super(t),this.name="ContinuitySqliteStoreError",this.code=e,this.reasonCode=e,this.guidance=a.guidance,this.cause=a.cause,this.mutationBlocked=a.mutationBlocked??e==="sqlite-integrity-failed"}}const R=[O],L=Object.freeze(["continuity_migrations","jobs","job_leases","job_events","job_receipts","goal_campaigns","goal_ledger_items","goal_verifiers","goal_review_gates","loop_jobs","artifacts","state_snapshots","runner_config","outbox"]),w=/(raw[_-]?logs?|prompt(?:[_-]?(?:body|text))?|private[_-]?urls?|secret|token|password|protected(?:[_-]?(?:field|body|internals))?|workflow(?:[_-]?body)?|step(?:[_-]?body)?|customer(?:[_-]?(?:pii|data))?|authorization|api[_-]?key|license[_-]?key)/i,S=/(https?:\/\/\S+|ghp_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]+|-----BEGIN [A-Z ]*PRIVATE KEY-----|authorization\s*:|password\s*=|token\s*=|api[_-]?key\s*=|license[_-]?key\s*=|raw[_-]?log|transcript|stack trace|stderr:|stdout:|system prompt|workflow body|step body|PROTECTED_|PRIVATE_INTERNALS|CUSTOMER_PII|VENDOR_CORPUS|P180[_-]?SYNTHETIC[_-]?CONTINUITY)/i,k=/(corrupt|malformed|not a database|file is not a database|database disk image is malformed)/i,x=/(foreign key constraint failed|SQLITE_CONSTRAINT_FOREIGNKEY)/i;function M(r){return new Function("specifier","return import(specifier)")(r)}function v(r){return`sha256:${T("sha256").update(r).digest("hex")}`}function _(r){return typeof r=="object"&&r!==null&&!Array.isArray(r)}function U(r){return r instanceof Error?r.message:String(r)}function q(r){return _(r)&&typeof r.code=="string"?r.code:void 0}function n(r,e){if(r instanceof i)return r;const t=U(r),a=q(r);return a==="SQLITE_CORRUPT"||a==="SQLITE_NOTADB"||k.test(t)?new i("sqlite-integrity-failed","Continuity SQLite integrity check failed; durable mutation is blocked until the store is repaired or rebuilt.",{cause:r,mutationBlocked:!0}):a==="SQLITE_CONSTRAINT_FOREIGNKEY"||x.test(t)?new i("sqlite-foreign-key-failed","Continuity SQLite foreign-key validation failed; mutation was rejected.",{cause:r}):new i(e,t,{cause:r})}function g(r,e){if(typeof r=="string"){if(S.test(r))throw new i("sqlite-public-safety-rejected",`Continuity SQLite metadata rejected unsafe value at ${e}.`);return}if(!(r===null||typeof r=="number"||typeof r=="boolean")){if(Array.isArray(r)){r.forEach((t,a)=>g(t,`${e}[${a}]`));return}if(_(r)){for(const[t,a]of Object.entries(r)){if(w.test(t))throw new i("sqlite-public-safety-rejected",`Continuity SQLite metadata rejected unsafe key at ${e}.${t}.`);g(a,`${e}.${t}`)}return}throw new i("sqlite-public-safety-rejected",`Continuity SQLite metadata rejected unsupported value at ${e}.`)}}function c(r,e){if(r!==void 0&&S.test(r))throw new i("sqlite-public-safety-rejected",`Continuity SQLite text rejected unsafe value at ${e}.`)}function l(r){return r?(g(r,"metadata"),JSON.stringify(r)):null}function p(r){if(Array.isArray(r)){const e=r[0];return _(e)?Object.values(e)[0]:e}return _(r)?Object.values(r)[0]:r}function D(r){return L.includes(r)}function F(r){return Array.from(new Set(r))}function W(r){const e=_(r)&&"default"in r?r.default:r;if(typeof e!="function")throw new i("sqlite-adapter-unavailable","Optional better-sqlite3 adapter did not export a database constructor.",{guidance:I});const t=e;return{adapterName:"better-sqlite3",open(a,s){return new t(a,s)}}}async function P(r=M){try{const e=await r("better-sqlite3");return{ok:!0,adapter:W(e)}}catch(e){return e instanceof i?{ok:!1,error:e}:{ok:!1,error:new i("sqlite-adapter-unavailable","Optional Enterprise continuity SQLite adapter better-sqlite3 is unavailable.",{cause:e,guidance:I})}}}function H(r){return y(r,f,A)}function B(r){const e=y(r,f);N(e,{recursive:!0,mode:448});try{b(e,448)}catch{}return e}async function z(r){const e=r.adapter??await J(r.adapterLoader);B(r.projectRoot);const t=H(r.projectRoot);let a;try{a=e.open(t)}catch(o){throw n(o,"sqlite-integrity-failed")}const s=new Q({db:a,filePath:t,adapterName:e.adapterName,busyTimeoutMs:r.busyTimeoutMs??j,integrityCheck:r.integrityCheck??!0,now:r.now??(()=>new Date().toISOString())});try{if(s.initialize(),C(t))try{b(t,384)}catch{}return s}catch(o){try{a.close()}catch{}throw o}}async function J(r){const e=r?await r():await P();if(!e.ok)throw e.error;return e.adapter}class Q{filePath;adapterName;db;busyTimeoutMs;integrityCheck;now;mutationBlocked=!1;constructor(e){this.db=e.db,this.filePath=e.filePath,this.adapterName=e.adapterName,this.busyTimeoutMs=e.busyTimeoutMs,this.integrityCheck=e.integrityCheck,this.now=e.now}initialize(){try{this.configureConnection(),this.integrityCheck&&this.runIntegrityCheck(),this.ensureMigrationTable(),this.applyMigrations(),this.integrityCheck&&this.runIntegrityCheck()}catch(e){throw n(e,"sqlite-migration-failed")}}close(){this.db.close()}pragmaValue(e){return p(this.db.pragma(e,{simple:!0}))}runIntegrityCheck(){try{if(String(p(this.db.pragma("integrity_check",{simple:!0}))??"").toLowerCase()!=="ok")throw this.mutationBlocked=!0,new i("sqlite-integrity-failed","Continuity SQLite integrity check failed; durable mutation is blocked until the store is repaired or rebuilt.",{mutationBlocked:!0})}catch(e){throw this.mutationBlocked=!0,n(e,"sqlite-integrity-failed")}}getSchemaVersion(){const e=this.db.prepare("SELECT COALESCE(MAX(version), 0) AS version FROM continuity_migrations").get();return _(e)&&typeof e.version=="number"?e.version:0}countRows(e){if(!D(e))throw new i("sqlite-public-safety-rejected","Unknown continuity table name.");const t=this.db.prepare(`SELECT COUNT(*) AS count FROM ${e}`).get();return _(t)&&typeof t.count=="number"?t.count:0}recordJob(e){this.assertCanMutate(),c(e.summary,"jobs.summary");const t=l(e.metadata);try{const a=this.db.prepare(`
|
|
2
|
+
INSERT OR IGNORE INTO jobs (
|
|
3
|
+
job_id, kind, status, summary, reason_code, created_at, updated_at,
|
|
4
|
+
next_run_at, goal_id, loop_id, campaign_id, operation_id,
|
|
5
|
+
idempotency_key, metadata_json
|
|
6
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
7
|
+
`).run(e.jobId,e.kind,e.status,e.summary??null,e.reasonCode??null,e.createdAt,e.updatedAt,e.nextRunAt??null,e.goalId??null,e.loopId??null,e.campaignId??null,e.operationId??null,e.idempotencyKey??null,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}appendEvent(e){this.assertCanMutate(),c(e.summary,"job_events.summary");const t=l(e.metadata);try{const a=this.db.prepare(`
|
|
8
|
+
INSERT OR IGNORE INTO job_events (
|
|
9
|
+
event_id, job_id, operation_id, idempotency_key, event_sequence,
|
|
10
|
+
type, summary, reason_code, created_at, metadata_json
|
|
11
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
12
|
+
`).run(e.eventId,e.jobId,e.operationId,e.idempotencyKey??null,e.sequence??null,e.type,e.summary,e.reasonCode??null,e.createdAt,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}appendReceipt(e){this.assertCanMutate();const t=l(e.metadata);try{const a=this.db.prepare(`
|
|
13
|
+
INSERT OR IGNORE INTO job_receipts (
|
|
14
|
+
receipt_id, job_id, operation_id, idempotency_key, status, reason_code,
|
|
15
|
+
applied_operation_ids_json, ignored_operation_ids_json, created_at, metadata_json
|
|
16
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
17
|
+
`).run(e.receiptId,e.jobId,e.operationId??null,e.idempotencyKey??null,e.status,e.reasonCode??null,e.appliedOperationIds?JSON.stringify(e.appliedOperationIds):null,e.ignoredOperationIds?JSON.stringify(e.ignoredOperationIds):null,e.createdAt,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}updateJobStatus(e){this.assertCanMutate();try{const t=this.db.prepare(`
|
|
18
|
+
UPDATE jobs
|
|
19
|
+
SET status = ?,
|
|
20
|
+
reason_code = COALESCE(?, reason_code),
|
|
21
|
+
updated_at = ?,
|
|
22
|
+
next_run_at = COALESCE(?, next_run_at)
|
|
23
|
+
WHERE job_id = ?
|
|
24
|
+
`).run(e.status,e.reasonCode??null,e.updatedAt,e.nextRunAt??null,e.jobId);if(t.changes===0)throw new i("sqlite-foreign-key-failed",`Continuity SQLite job ${e.jobId} was not found for status update.`);return this.toWriteResult(t)}catch(t){throw n(t,"sqlite-migration-failed")}}scheduleNextTick(e){return this.updateJobStatus({jobId:e.jobId,status:"active",updatedAt:e.updatedAt,reasonCode:e.reasonCode,nextRunAt:e.scheduledAt})}acquireLease(e){this.assertCanMutate();const t=l(e.metadata);try{const a=this.db.prepare(`
|
|
25
|
+
INSERT OR IGNORE INTO job_leases (
|
|
26
|
+
lease_id, job_id, runner_id, status, acquired_at, expires_at,
|
|
27
|
+
operation_id, idempotency_key, metadata_json
|
|
28
|
+
) VALUES (?, ?, ?, 'acquired', ?, ?, ?, ?, ?)
|
|
29
|
+
`).run(e.leaseId,e.jobId,e.runnerId,e.acquiredAt,e.expiresAt,e.operationId??null,e.idempotencyKey??null,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}releaseLease(e){this.assertCanMutate();try{const t=this.db.prepare(`
|
|
30
|
+
UPDATE job_leases
|
|
31
|
+
SET status = 'released', released_at = ?
|
|
32
|
+
WHERE lease_id = ? AND released_at IS NULL
|
|
33
|
+
`).run(e.releasedAt,e.leaseId);if(t.changes===0)throw new i("sqlite-foreign-key-failed",`Continuity SQLite lease ${e.leaseId} was not found for release.`);return this.toWriteResult(t)}catch(t){throw n(t,"sqlite-migration-failed")}}recordStateSnapshot(e){this.assertCanMutate(),c(e.summary,"state_snapshots.summary"),c(e.relativePath,"state_snapshots.relative_path");const t=l(e.metadata);try{const a=this.db.prepare(`
|
|
34
|
+
INSERT OR IGNORE INTO state_snapshots (
|
|
35
|
+
snapshot_id, job_id, kind, relative_path, sha256, summary, captured_at,
|
|
36
|
+
operation_id, idempotency_key, metadata_json
|
|
37
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
38
|
+
`).run(e.snapshotId,e.jobId??null,e.kind,e.relativePath??null,e.sha256??null,e.summary??null,e.capturedAt,e.operationId??null,e.idempotencyKey??null,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}recordArtifact(e){this.assertCanMutate(),c(e.kind,"artifacts.kind"),c(e.relativePath,"artifacts.relative_path"),c(e.summary,"artifacts.summary");const t=l(e.metadata);try{const a=this.db.prepare(`
|
|
39
|
+
INSERT OR IGNORE INTO artifacts (
|
|
40
|
+
artifact_id, job_id, kind, relative_path, sha256, summary,
|
|
41
|
+
operation_id, idempotency_key, created_at, metadata_json
|
|
42
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
43
|
+
`).run(e.artifactId,e.jobId??null,e.kind,e.relativePath,e.sha256??null,e.summary??null,e.operationId??null,e.idempotencyKey??null,e.createdAt,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}enqueueOutbox(e){this.assertCanMutate();const t=l(e.payload);try{const a=this.db.prepare(`
|
|
44
|
+
INSERT OR IGNORE INTO outbox (
|
|
45
|
+
outbox_id, job_id, operation_id, idempotency_key, type, status,
|
|
46
|
+
payload_json, retry_count, next_attempt_at, last_error_code,
|
|
47
|
+
created_at, updated_at
|
|
48
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
49
|
+
`).run(e.outboxId,e.jobId??null,e.operationId,e.idempotencyKey??null,e.type,e.status??"pending",t??"{}",e.retryCount??0,e.nextAttemptAt??null,e.lastErrorCode??null,e.createdAt,e.updatedAt);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}retryOutboxEntries(e){this.assertCanMutate();const t=Math.max(1,Math.min(100,Math.floor(e.limit))),a=F(e.statuses?.length?e.statuses:["failed","dead_letter"]),s=e.reasonCode??"backoff-scheduled";c(s,"outbox.last_error_code"),c(e.nextAttemptAt,"outbox.next_attempt_at");try{return this.runInTransaction(()=>{const o=a.map(()=>"?").join(", "),d=this.db.prepare(`
|
|
50
|
+
SELECT outbox_id
|
|
51
|
+
FROM outbox
|
|
52
|
+
WHERE status IN (${o})
|
|
53
|
+
ORDER BY updated_at ASC, outbox_id ASC
|
|
54
|
+
LIMIT ?
|
|
55
|
+
`).all(...a,t).map(u=>u.outbox_id).filter(u=>typeof u=="string"&&u.length>0);if(d.length===0)return{retriedOutboxIds:[],changes:0,reasonCode:s,publicSafe:!0};const h=d.map(()=>"?").join(", "),E=this.db.prepare(`
|
|
56
|
+
UPDATE outbox
|
|
57
|
+
SET status = 'pending',
|
|
58
|
+
retry_count = retry_count + 1,
|
|
59
|
+
next_attempt_at = ?,
|
|
60
|
+
last_error_code = ?,
|
|
61
|
+
updated_at = ?
|
|
62
|
+
WHERE outbox_id IN (${h})
|
|
63
|
+
`).run(e.nextAttemptAt??e.nowIso,s,e.nowIso,...d);return{retriedOutboxIds:d,changes:E.changes,reasonCode:s,publicSafe:!0}})}catch(o){throw n(o,"sqlite-migration-failed")}}upsertGoalCampaign(e){this.assertCanMutate(),c(e.title,"goal_campaigns.title"),c(e.publicSummary,"goal_campaigns.public_summary");const t=l(e.metadata);try{const a=this.db.prepare(`
|
|
64
|
+
INSERT INTO goal_campaigns (
|
|
65
|
+
campaign_id, job_id, status, title, public_summary, reason_code,
|
|
66
|
+
created_at, updated_at, operation_id, idempotency_key, metadata_json
|
|
67
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
68
|
+
ON CONFLICT(campaign_id) DO UPDATE SET
|
|
69
|
+
status = excluded.status,
|
|
70
|
+
title = COALESCE(excluded.title, goal_campaigns.title),
|
|
71
|
+
public_summary = COALESCE(excluded.public_summary, goal_campaigns.public_summary),
|
|
72
|
+
reason_code = excluded.reason_code,
|
|
73
|
+
updated_at = excluded.updated_at,
|
|
74
|
+
operation_id = excluded.operation_id,
|
|
75
|
+
idempotency_key = excluded.idempotency_key,
|
|
76
|
+
metadata_json = excluded.metadata_json
|
|
77
|
+
`).run(e.campaignId,e.jobId,e.status,e.title??null,e.publicSummary??null,e.reasonCode??null,e.createdAt,e.updatedAt,e.operationId??null,e.idempotencyKey??null,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}upsertGoalLedgerItem(e){this.assertCanMutate(),c(e.summary,"goal_ledger_items.summary");const t=l(e.metadata);try{this.ensureGoalCampaign(e.campaignId,e.jobId,e.createdAt,e.updatedAt);const a=this.db.prepare(`
|
|
78
|
+
INSERT INTO goal_ledger_items (
|
|
79
|
+
item_id, campaign_id, operation_id, idempotency_key, item_type, status,
|
|
80
|
+
summary, reason_code, created_at, updated_at, metadata_json
|
|
81
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
82
|
+
ON CONFLICT(item_id) DO UPDATE SET
|
|
83
|
+
status = excluded.status,
|
|
84
|
+
summary = excluded.summary,
|
|
85
|
+
reason_code = excluded.reason_code,
|
|
86
|
+
updated_at = excluded.updated_at,
|
|
87
|
+
metadata_json = excluded.metadata_json
|
|
88
|
+
`).run(e.itemId,e.campaignId,e.operationId??null,e.idempotencyKey??null,e.itemType,e.status,e.summary,e.reasonCode??null,e.createdAt,e.updatedAt,t);return this.toWriteResult(a)}catch(a){throw n(a,"sqlite-migration-failed")}}upsertGoalVerifier(e){this.assertCanMutate(),c(e.summary,"goal_verifiers.summary");const t=l(e.metadata);try{const a=e.lastCheckedAt??this.now();this.ensureGoalCampaign(e.campaignId,e.jobId,a,a);const s=this.db.prepare(`
|
|
89
|
+
INSERT INTO goal_verifiers (
|
|
90
|
+
verifier_id, campaign_id, kind, status, summary, reason_code,
|
|
91
|
+
last_checked_at, operation_id, idempotency_key, metadata_json
|
|
92
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
93
|
+
ON CONFLICT(verifier_id) DO UPDATE SET
|
|
94
|
+
status = excluded.status,
|
|
95
|
+
summary = excluded.summary,
|
|
96
|
+
reason_code = excluded.reason_code,
|
|
97
|
+
last_checked_at = excluded.last_checked_at,
|
|
98
|
+
metadata_json = excluded.metadata_json
|
|
99
|
+
`).run(e.verifierId,e.campaignId,e.kind,e.status,e.summary??null,e.reasonCode??null,e.lastCheckedAt??null,e.operationId??null,e.idempotencyKey??null,t);return this.toWriteResult(s)}catch(a){throw n(a,"sqlite-migration-failed")}}upsertGoalReviewGate(e){this.assertCanMutate(),c(e.summary,"goal_review_gates.summary");const t=l(e.metadata);try{const a=this.now();this.ensureGoalCampaign(e.campaignId,e.jobId,a,a);const s=this.db.prepare(`
|
|
100
|
+
INSERT INTO goal_review_gates (
|
|
101
|
+
gate_id, campaign_id, status, summary, required, reason_code,
|
|
102
|
+
operation_id, idempotency_key, metadata_json
|
|
103
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
104
|
+
ON CONFLICT(gate_id) DO UPDATE SET
|
|
105
|
+
status = excluded.status,
|
|
106
|
+
summary = excluded.summary,
|
|
107
|
+
required = excluded.required,
|
|
108
|
+
reason_code = excluded.reason_code,
|
|
109
|
+
metadata_json = excluded.metadata_json
|
|
110
|
+
`).run(e.gateId,e.campaignId,e.status,e.summary??null,e.required?1:0,e.reasonCode??null,e.operationId??null,e.idempotencyKey??null,t);return this.toWriteResult(s)}catch(a){throw n(a,"sqlite-migration-failed")}}recordOperationAudit(e){return this.appendReceipt(e)}hasOperationRef(e,t){this.assertCanMutate();const a=["jobs","job_leases","job_events","job_receipts","goal_campaigns","goal_ledger_items","goal_verifiers","goal_review_gates","loop_jobs","artifacts","state_snapshots","runner_config","outbox"],s=a.map(d=>`SELECT 1 AS found FROM ${d} WHERE operation_id = ?${t?" OR idempotency_key = ?":""}`),o=a.flatMap(()=>t?[e,t]:[e]);return!!this.db.prepare(`${s.join(" UNION ALL ")} LIMIT 1`).get(...o)}jobExists(e){return!!this.db.prepare("SELECT 1 AS found FROM jobs WHERE job_id = ? LIMIT 1").get(e)}runInTransaction(e){this.assertCanMutate();const t=this.db.transaction(e);try{return t()}catch(a){throw n(a,"sqlite-migration-failed")}}collectSnapshotRows(e){const t=(o,...m)=>{const d=this.db.prepare(o).get(...m);return _(d)&&typeof d.count=="number"?d.count:0},a=this.db.prepare(`
|
|
111
|
+
SELECT status, COUNT(*) AS count FROM outbox GROUP BY status
|
|
112
|
+
`).all(),s={};for(const o of a)typeof o.status=="string"&&typeof o.count=="number"&&(s[o.status]=o.count);return{schemaVersion:this.getSchemaVersion(),jobs:this.db.prepare(`
|
|
113
|
+
SELECT job_id, kind, status, summary, reason_code, created_at, updated_at,
|
|
114
|
+
next_run_at, metadata_json,
|
|
115
|
+
(SELECT COUNT(*)
|
|
116
|
+
FROM job_receipts r
|
|
117
|
+
WHERE r.job_id = jobs.job_id
|
|
118
|
+
AND (r.operation_id LIKE 'tick-%' OR r.operation_id LIKE 'loop-tick-%')
|
|
119
|
+
AND r.status IN ('accepted', 'applied')) AS iteration,
|
|
120
|
+
(SELECT COUNT(*)
|
|
121
|
+
FROM goal_campaigns c
|
|
122
|
+
JOIN goal_ledger_items i ON i.campaign_id = c.campaign_id
|
|
123
|
+
WHERE c.job_id = jobs.job_id) AS goal_ledger_item_count,
|
|
124
|
+
(SELECT COUNT(*)
|
|
125
|
+
FROM goal_campaigns c
|
|
126
|
+
JOIN goal_ledger_items i ON i.campaign_id = c.campaign_id
|
|
127
|
+
WHERE c.job_id = jobs.job_id
|
|
128
|
+
AND i.status = 'blocked') AS blocked_goal_ledger_item_count,
|
|
129
|
+
(SELECT COUNT(*)
|
|
130
|
+
FROM goal_campaigns c
|
|
131
|
+
JOIN goal_ledger_items i ON i.campaign_id = c.campaign_id
|
|
132
|
+
WHERE c.job_id = jobs.job_id
|
|
133
|
+
AND i.item_type = 'security_issue'
|
|
134
|
+
AND i.status = 'blocked') AS security_issue_blocked_count,
|
|
135
|
+
(SELECT COUNT(*)
|
|
136
|
+
FROM goal_campaigns c
|
|
137
|
+
JOIN goal_verifiers v ON v.campaign_id = c.campaign_id
|
|
138
|
+
WHERE c.job_id = jobs.job_id) AS goal_verifier_count,
|
|
139
|
+
(SELECT COUNT(*)
|
|
140
|
+
FROM goal_campaigns c
|
|
141
|
+
JOIN goal_verifiers v ON v.campaign_id = c.campaign_id
|
|
142
|
+
WHERE c.job_id = jobs.job_id
|
|
143
|
+
AND v.status = 'failed') AS failed_verifier_count,
|
|
144
|
+
(SELECT COUNT(*)
|
|
145
|
+
FROM goal_campaigns c
|
|
146
|
+
JOIN goal_verifiers v ON v.campaign_id = c.campaign_id
|
|
147
|
+
WHERE c.job_id = jobs.job_id
|
|
148
|
+
AND v.status = 'unavailable') AS unavailable_verifier_count,
|
|
149
|
+
(SELECT COUNT(*)
|
|
150
|
+
FROM goal_campaigns c
|
|
151
|
+
JOIN goal_review_gates g ON g.campaign_id = c.campaign_id
|
|
152
|
+
WHERE c.job_id = jobs.job_id) AS goal_review_gate_count,
|
|
153
|
+
(SELECT COUNT(*)
|
|
154
|
+
FROM goal_campaigns c
|
|
155
|
+
JOIN goal_review_gates g ON g.campaign_id = c.campaign_id
|
|
156
|
+
WHERE c.job_id = jobs.job_id
|
|
157
|
+
AND g.required = 1
|
|
158
|
+
AND g.status IN ('failed', 'blocked')) AS failed_required_review_gate_count
|
|
159
|
+
FROM jobs
|
|
160
|
+
ORDER BY updated_at DESC, job_id ASC
|
|
161
|
+
LIMIT ?
|
|
162
|
+
`).all(e.jobLimit),staleLeases:this.db.prepare(`
|
|
163
|
+
SELECT lease_id, job_id, runner_id, expires_at
|
|
164
|
+
FROM job_leases
|
|
165
|
+
WHERE released_at IS NULL AND expires_at <= ?
|
|
166
|
+
ORDER BY expires_at ASC, lease_id ASC
|
|
167
|
+
LIMIT ?
|
|
168
|
+
`).all(e.nowIso,e.staleLeaseLimit),receipts:this.db.prepare(`
|
|
169
|
+
SELECT receipt_id, job_id, operation_id, status, reason_code, created_at, metadata_json
|
|
170
|
+
FROM job_receipts
|
|
171
|
+
ORDER BY created_at DESC, receipt_id ASC
|
|
172
|
+
LIMIT ?
|
|
173
|
+
`).all(e.receiptLimit),events:this.db.prepare(`
|
|
174
|
+
SELECT event_id, job_id, operation_id, type, summary, reason_code, created_at
|
|
175
|
+
FROM job_events
|
|
176
|
+
ORDER BY created_at DESC, event_id ASC
|
|
177
|
+
LIMIT ?
|
|
178
|
+
`).all(e.eventLimit),stateSnapshots:this.db.prepare(`
|
|
179
|
+
SELECT snapshot_id, job_id, kind, relative_path, sha256, summary,
|
|
180
|
+
captured_at, operation_id, metadata_json
|
|
181
|
+
FROM state_snapshots
|
|
182
|
+
WHERE kind = 'context_compaction'
|
|
183
|
+
ORDER BY captured_at DESC, snapshot_id ASC
|
|
184
|
+
LIMIT ?
|
|
185
|
+
`).all(e.snapshotLimit),counts:{jobs:t("SELECT COUNT(*) AS count FROM jobs"),activeJobs:t("SELECT COUNT(*) AS count FROM jobs WHERE status IN ('planned', 'active', 'running', 'waiting_external', 'waiting_human', 'backoff', 'paused', 'blocked')"),activeLeases:t("SELECT COUNT(*) AS count FROM job_leases WHERE released_at IS NULL"),dueJobs:t("SELECT COUNT(*) AS count FROM jobs WHERE next_run_at IS NOT NULL AND next_run_at <= ? AND status NOT IN ('completed', 'aborted', 'cancelled')",e.nowIso),staleLeases:t("SELECT COUNT(*) AS count FROM job_leases WHERE released_at IS NULL AND expires_at <= ?",e.nowIso),receipts:t("SELECT COUNT(*) AS count FROM job_receipts"),events:t("SELECT COUNT(*) AS count FROM job_events"),goalLedgerItems:t("SELECT COUNT(*) AS count FROM goal_ledger_items"),goalVerifiers:t("SELECT COUNT(*) AS count FROM goal_verifiers"),goalReviewGates:t("SELECT COUNT(*) AS count FROM goal_review_gates"),stateSnapshots:t("SELECT COUNT(*) AS count FROM state_snapshots"),outbox:t("SELECT COUNT(*) AS count FROM outbox")},outboxCounts:s}}listDueJobs(e){const t=Math.max(1,Math.min(50,Math.floor(e.limit)));return this.db.prepare(`
|
|
186
|
+
SELECT j.job_id, j.kind, j.status, j.summary, j.reason_code, j.created_at,
|
|
187
|
+
j.updated_at, j.next_run_at, j.metadata_json,
|
|
188
|
+
(SELECT COUNT(*)
|
|
189
|
+
FROM job_receipts r
|
|
190
|
+
WHERE r.job_id = j.job_id
|
|
191
|
+
AND (r.operation_id LIKE 'tick-%' OR r.operation_id LIKE 'loop-tick-%')
|
|
192
|
+
AND r.status IN ('accepted', 'applied')) AS iteration,
|
|
193
|
+
(SELECT COUNT(*)
|
|
194
|
+
FROM job_leases l
|
|
195
|
+
WHERE l.job_id = j.job_id
|
|
196
|
+
AND l.released_at IS NULL) AS active_lease_count
|
|
197
|
+
FROM jobs j
|
|
198
|
+
WHERE j.next_run_at IS NOT NULL
|
|
199
|
+
AND j.next_run_at <= ?
|
|
200
|
+
AND j.status NOT IN ('waiting_external', 'waiting_human', 'paused', 'blocked', 'completed', 'aborted', 'cancelled')
|
|
201
|
+
ORDER BY j.next_run_at ASC, j.job_id ASC
|
|
202
|
+
LIMIT ?
|
|
203
|
+
`).all(e.nowIso,t)}recoverStaleLeases(e){this.assertCanMutate();const t=Date.parse(e.nowIso);if(!Number.isFinite(t))throw new i("sqlite-public-safety-rejected","Continuity SQLite stale lease recovery received an invalid timestamp.");const a=Math.max(0,Math.floor(e.staleAfterMs)),s=Math.max(1,Math.min(100,Math.floor(e.limit))),o=new Date(t-a).toISOString();try{return this.runInTransaction(()=>{const d=this.db.prepare(`
|
|
204
|
+
SELECT lease_id
|
|
205
|
+
FROM job_leases
|
|
206
|
+
WHERE released_at IS NULL
|
|
207
|
+
AND expires_at <= ?
|
|
208
|
+
ORDER BY expires_at ASC, lease_id ASC
|
|
209
|
+
LIMIT ?
|
|
210
|
+
`).all(o,s).map(u=>u.lease_id).filter(u=>typeof u=="string"&&u.length>0);if(d.length===0)return{recoveredLeaseIds:[],safeExpiredAtOrBefore:o,changes:0};const h=d.map(()=>"?").join(", "),E=this.db.prepare(`
|
|
211
|
+
UPDATE job_leases
|
|
212
|
+
SET status = 'expired', released_at = ?
|
|
213
|
+
WHERE released_at IS NULL
|
|
214
|
+
AND lease_id IN (${h})
|
|
215
|
+
`).run(e.nowIso,...d);return{recoveredLeaseIds:d,safeExpiredAtOrBefore:o,changes:E.changes}})}catch(m){throw n(m,"sqlite-migration-failed")}}ensureGoalCampaign(e,t,a,s){this.db.prepare(`
|
|
216
|
+
INSERT OR IGNORE INTO goal_campaigns (
|
|
217
|
+
campaign_id, job_id, status, public_summary, created_at, updated_at
|
|
218
|
+
) VALUES (?, ?, 'active', 'Public goal campaign summary unavailable', ?, ?)
|
|
219
|
+
`).run(e,t,a,s)}configureConnection(){const e=String(p(this.db.pragma("journal_mode = WAL",{simple:!0}))??"").toLowerCase();if(e!=="wal")throw new i("sqlite-migration-failed",`Continuity SQLite journal_mode did not switch to WAL (observed ${e||"unknown"}).`);if(this.db.pragma("foreign_keys = ON"),this.db.pragma(`busy_timeout = ${this.busyTimeoutMs}`),Number(p(this.db.pragma("foreign_keys",{simple:!0}))??0)!==1)throw new i("sqlite-migration-failed","Continuity SQLite foreign_keys pragma is not enabled.")}ensureMigrationTable(){this.db.exec(`
|
|
220
|
+
CREATE TABLE IF NOT EXISTS continuity_migrations (
|
|
221
|
+
version INTEGER PRIMARY KEY,
|
|
222
|
+
name TEXT NOT NULL,
|
|
223
|
+
checksum TEXT NOT NULL,
|
|
224
|
+
applied_at TEXT NOT NULL
|
|
225
|
+
);
|
|
226
|
+
`)}applyMigrations(){this.db.transaction(()=>{for(const t of R){const a=v(t.sql),s=this.db.prepare("SELECT version, name, checksum FROM continuity_migrations WHERE version = ?").get(t.version);if(s){if(s.checksum!==a||s.name!==t.name)throw new i("sqlite-migration-conflict",`Continuity SQLite migration ${t.version} checksum conflict.`);continue}this.db.exec(t.sql),this.db.prepare("INSERT INTO continuity_migrations (version, name, checksum, applied_at) VALUES (?, ?, ?, ?)").run(t.version,t.name,a,this.now()),this.db.pragma(`user_version = ${t.version}`)}})()}assertCanMutate(){if(this.mutationBlocked)throw new i("sqlite-mutation-blocked","Continuity SQLite mutation is blocked after integrity failure.",{mutationBlocked:!0})}toWriteResult(e){const t=e.changes>0;return{inserted:t,replay:!t,changes:e.changes}}}export{A as CONTINUITY_SQLITE_FILENAME,f as CONTINUITY_SQLITE_RELATIVE_DIR,K as CONTINUITY_SQLITE_SCHEMA_VERSION,Q as ContinuitySqliteStore,i as ContinuitySqliteStoreError,j as DEFAULT_CONTINUITY_SQLITE_BUSY_TIMEOUT_MS,I as SQLITE_ADAPTER_INSTALL_GUIDANCE,H as continuitySqliteStorePath,P as loadBetterSqlite3Adapter,z as openContinuitySqliteStore};
|