@cleocode/core 2026.9.22 → 2026.9.23
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/dist/build-provenance.json +6 -0
- package/dist/decide/audit.d.ts +7 -1
- package/dist/decide/audit.d.ts.map +1 -1
- package/dist/decide/audit.js.map +1 -1
- package/dist/decide/client.d.ts +46 -4
- package/dist/decide/client.d.ts.map +1 -1
- package/dist/decide/client.js +328 -33
- package/dist/decide/client.js.map +1 -1
- package/dist/decide/credentials.d.ts +28 -4
- package/dist/decide/credentials.d.ts.map +1 -1
- package/dist/decide/credentials.js +50 -12
- package/dist/decide/credentials.js.map +1 -1
- package/dist/decide/index.d.ts +10 -4
- package/dist/decide/index.d.ts.map +1 -1
- package/dist/decide/index.js +10 -4
- package/dist/decide/index.js.map +1 -1
- package/dist/decide/jev-wire.d.ts +100 -8
- package/dist/decide/jev-wire.d.ts.map +1 -1
- package/dist/decide/jev-wire.js +402 -55
- package/dist/decide/jev-wire.js.map +1 -1
- package/dist/decide/operations.d.ts +97 -20
- package/dist/decide/operations.d.ts.map +1 -1
- package/dist/decide/operations.js +180 -28
- package/dist/decide/operations.js.map +1 -1
- package/dist/decide/provider-state.d.ts +89 -0
- package/dist/decide/provider-state.d.ts.map +1 -0
- package/dist/decide/provider-state.js +134 -0
- package/dist/decide/provider-state.js.map +1 -0
- package/dist/decide/provider.d.ts +26 -5
- package/dist/decide/provider.d.ts.map +1 -1
- package/dist/decide/provider.js.map +1 -1
- package/dist/decide/providers.d.ts +58 -0
- package/dist/decide/providers.d.ts.map +1 -0
- package/dist/decide/providers.js +69 -0
- package/dist/decide/providers.js.map +1 -0
- package/dist/decide/site.d.ts +2 -2
- package/dist/decide/site.d.ts.map +1 -1
- package/dist/decide/site.js +2 -0
- package/dist/decide/site.js.map +1 -1
- package/dist/decide/sites/list.d.ts +46 -0
- package/dist/decide/sites/list.d.ts.map +1 -0
- package/dist/decide/sites/list.js +206 -0
- package/dist/decide/sites/list.js.map +1 -0
- package/dist/decide/sites/registry.d.ts +130 -0
- package/dist/decide/sites/registry.d.ts.map +1 -0
- package/dist/decide/sites/registry.js +375 -0
- package/dist/decide/sites/registry.js.map +1 -0
- package/dist/decide/spend.d.ts +196 -0
- package/dist/decide/spend.d.ts.map +1 -0
- package/dist/decide/spend.js +387 -0
- package/dist/decide/spend.js.map +1 -0
- package/dist/decide/wizard.d.ts +53 -0
- package/dist/decide/wizard.d.ts.map +1 -0
- package/dist/decide/wizard.js +144 -0
- package/dist/decide/wizard.js.map +1 -0
- package/dist/docs/docs-audit.d.ts.map +1 -1
- package/dist/docs/docs-audit.js +1 -2
- package/dist/docs/docs-audit.js.map +1 -1
- package/dist/docs/export-document.js +775 -415
- package/dist/docs/export-document.js.map +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init/scaffold-workflows.d.ts.map +1 -1
- package/dist/init/scaffold-workflows.js +6 -3
- package/dist/init/scaffold-workflows.js.map +1 -1
- package/dist/init/upgrade-workflows.d.ts.map +1 -1
- package/dist/init/upgrade-workflows.js +6 -3
- package/dist/init/upgrade-workflows.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/llm/plugin-facade.js +886 -526
- package/dist/llm/plugin-facade.js.map +3 -3
- package/dist/memory/decision-contradiction.d.ts +3 -3
- package/dist/memory/decision-contradiction.d.ts.map +1 -1
- package/dist/memory/decision-contradiction.js +4 -3
- package/dist/memory/decision-contradiction.js.map +1 -1
- package/dist/memory/graph-memory-bridge.d.ts.map +1 -1
- package/dist/memory/graph-memory-bridge.js +2 -0
- package/dist/memory/graph-memory-bridge.js.map +1 -1
- package/dist/memory/observation-type-decision.d.ts +2 -2
- package/dist/memory/observation-type-decision.d.ts.map +1 -1
- package/dist/memory/observation-type-decision.js +3 -2
- package/dist/memory/observation-type-decision.js.map +1 -1
- package/dist/memory/pipeline-manifest-sqlite.d.ts +111 -0
- package/dist/memory/pipeline-manifest-sqlite.d.ts.map +1 -1
- package/dist/memory/pipeline-manifest-sqlite.js +230 -2
- package/dist/memory/pipeline-manifest-sqlite.js.map +1 -1
- package/dist/nexus/migrations/M-split-graph.d.ts.map +1 -1
- package/dist/nexus/migrations/M-split-graph.js +4 -0
- package/dist/nexus/migrations/M-split-graph.js.map +1 -1
- package/dist/nexus/store.d.ts.map +1 -1
- package/dist/nexus/store.js +2 -0
- package/dist/nexus/store.js.map +1 -1
- package/dist/orchestrate/pivot.d.ts.map +1 -1
- package/dist/orchestrate/pivot.js +13 -8
- package/dist/orchestrate/pivot.js.map +1 -1
- package/dist/orchestrate/plan.d.ts.map +1 -1
- package/dist/orchestrate/plan.js +3 -0
- package/dist/orchestrate/plan.js.map +1 -1
- package/dist/orchestration/lead-rollup.js +14 -2
- package/dist/orchestration/lead-rollup.js.map +1 -1
- package/dist/orchestration/owner-decision-readiness.d.ts +2 -2
- package/dist/orchestration/owner-decision-readiness.d.ts.map +1 -1
- package/dist/orchestration/owner-decision-readiness.js +3 -2
- package/dist/orchestration/owner-decision-readiness.js.map +1 -1
- package/dist/orchestration/validate-spawn.d.ts.map +1 -1
- package/dist/orchestration/validate-spawn.js +2 -0
- package/dist/orchestration/validate-spawn.js.map +1 -1
- package/dist/project-scope.d.ts +16 -0
- package/dist/project-scope.d.ts.map +1 -1
- package/dist/project-scope.js +38 -2
- package/dist/project-scope.js.map +1 -1
- package/dist/release/github-pr.d.ts.map +1 -1
- package/dist/release/github-pr.js +2 -1
- package/dist/release/github-pr.js.map +1 -1
- package/dist/routing/capability-matrix.d.ts.map +1 -1
- package/dist/routing/capability-matrix.js +7 -0
- package/dist/routing/capability-matrix.js.map +1 -1
- package/dist/selfimprove/fix-gen.js +895 -535
- package/dist/selfimprove/fix-gen.js.map +3 -3
- package/dist/sessions/briefing.d.ts.map +1 -1
- package/dist/sessions/briefing.js +23 -62
- package/dist/sessions/briefing.js.map +1 -1
- package/dist/sessions/focus-state-store.d.ts +6 -1
- package/dist/sessions/focus-state-store.d.ts.map +1 -1
- package/dist/sessions/focus-state-store.js +5 -2
- package/dist/sessions/focus-state-store.js.map +1 -1
- package/dist/setup/config-json-merge.d.ts +28 -0
- package/dist/setup/config-json-merge.d.ts.map +1 -1
- package/dist/setup/config-json-merge.js +51 -0
- package/dist/setup/config-json-merge.js.map +1 -1
- package/dist/setup/index.d.ts +13 -10
- package/dist/setup/index.d.ts.map +1 -1
- package/dist/setup/index.js +15 -10
- package/dist/setup/index.js.map +1 -1
- package/dist/setup/sections/llm.js +1 -1
- package/dist/setup/sections/llm.js.map +1 -1
- package/dist/setup/sections/system-one.d.ts +28 -0
- package/dist/setup/sections/system-one.d.ts.map +1 -0
- package/dist/setup/sections/system-one.js +53 -0
- package/dist/setup/sections/system-one.js.map +1 -0
- package/dist/setup/wizard.d.ts +15 -1
- package/dist/setup/wizard.d.ts.map +1 -1
- package/dist/setup/wizard.js +15 -0
- package/dist/setup/wizard.js.map +1 -1
- package/dist/skills/prune-bundled.d.ts +40 -1
- package/dist/skills/prune-bundled.d.ts.map +1 -1
- package/dist/skills/prune-bundled.js +117 -1
- package/dist/skills/prune-bundled.js.map +1 -1
- package/dist/store/agent-registry-accessor.d.ts.map +1 -1
- package/dist/store/agent-registry-accessor.js +2 -0
- package/dist/store/agent-registry-accessor.js.map +1 -1
- package/dist/store/backup-pack.js +1 -1
- package/dist/store/backup-pack.js.map +1 -1
- package/dist/store/backup.d.ts +15 -1
- package/dist/store/backup.d.ts.map +1 -1
- package/dist/store/backup.js +18 -2
- package/dist/store/backup.js.map +1 -1
- package/dist/store/conduit-sqlite.d.ts.map +1 -1
- package/dist/store/conduit-sqlite.js +3 -0
- package/dist/store/conduit-sqlite.js.map +1 -1
- package/dist/store/credential-transfer.d.ts.map +1 -1
- package/dist/store/credential-transfer.js +2 -0
- package/dist/store/credential-transfer.js.map +1 -1
- package/dist/store/cross-db-cleanup.d.ts.map +1 -1
- package/dist/store/cross-db-cleanup.js +2 -0
- package/dist/store/cross-db-cleanup.js.map +1 -1
- package/dist/store/dual-scope-db.d.ts.map +1 -1
- package/dist/store/dual-scope-db.js +13 -2
- package/dist/store/dual-scope-db.js.map +1 -1
- package/dist/store/migrate-signaldock-to-conduit.d.ts.map +1 -1
- package/dist/store/migrate-signaldock-to-conduit.js +3 -0
- package/dist/store/migrate-signaldock-to-conduit.js.map +1 -1
- package/dist/store/migration-manager.d.ts.map +1 -1
- package/dist/store/migration-manager.js +37 -3
- package/dist/store/migration-manager.js.map +1 -1
- package/dist/store/migration-sqlite.d.ts.map +1 -1
- package/dist/store/migration-sqlite.js +2 -0
- package/dist/store/migration-sqlite.js.map +1 -1
- package/dist/store/nexus-sqlite.d.ts.map +1 -1
- package/dist/store/nexus-sqlite.js +3 -0
- package/dist/store/nexus-sqlite.js.map +1 -1
- package/dist/store/open-cleo-db.d.ts.map +1 -1
- package/dist/store/open-cleo-db.js +3 -0
- package/dist/store/open-cleo-db.js.map +1 -1
- package/dist/store/portable-bundle-import.d.ts.map +1 -1
- package/dist/store/portable-bundle-import.js +2 -0
- package/dist/store/portable-bundle-import.js.map +1 -1
- package/dist/store/portable-bundle-relocate.d.ts.map +1 -1
- package/dist/store/portable-bundle-relocate.js +2 -0
- package/dist/store/portable-bundle-relocate.js.map +1 -1
- package/dist/store/portable-bundle-scan.js +1 -1
- package/dist/store/portable-bundle-scan.js.map +1 -1
- package/dist/store/ports/domain-binding.d.ts.map +1 -1
- package/dist/store/ports/domain-binding.js +5 -0
- package/dist/store/ports/domain-binding.js.map +1 -1
- package/dist/store/split-brain-import.d.ts.map +1 -1
- package/dist/store/split-brain-import.js +2 -0
- package/dist/store/split-brain-import.js.map +1 -1
- package/dist/store/sqlite-data-accessor.js +7 -0
- package/dist/store/sqlite-data-accessor.js.map +1 -1
- package/dist/store/sqlite-native.d.ts.map +1 -1
- package/dist/store/sqlite-native.js +1 -0
- package/dist/store/sqlite-native.js.map +1 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +5 -0
- package/dist/store/sqlite.js.map +1 -1
- package/dist/store/worktree-build-guard.d.ts +191 -0
- package/dist/store/worktree-build-guard.d.ts.map +1 -0
- package/dist/store/worktree-build-guard.js +486 -0
- package/dist/store/worktree-build-guard.js.map +1 -0
- package/dist/store/worktree-isolation-guard.d.ts +27 -0
- package/dist/store/worktree-isolation-guard.d.ts.map +1 -1
- package/dist/store/worktree-isolation-guard.js +67 -1
- package/dist/store/worktree-isolation-guard.js.map +1 -1
- package/dist/store/writer-lease.d.ts.map +1 -1
- package/dist/store/writer-lease.js +2 -0
- package/dist/store/writer-lease.js.map +1 -1
- package/dist/system/backup.d.ts +6 -2
- package/dist/system/backup.d.ts.map +1 -1
- package/dist/system/backup.js +6 -3
- package/dist/system/backup.js.map +1 -1
- package/dist/task-tools/index.d.ts +4 -2
- package/dist/task-tools/index.d.ts.map +1 -1
- package/dist/task-tools/index.js +3 -2
- package/dist/task-tools/index.js.map +1 -1
- package/dist/task-tools/score-task-priority.d.ts +93 -18
- package/dist/task-tools/score-task-priority.d.ts.map +1 -1
- package/dist/task-tools/score-task-priority.js +193 -81
- package/dist/task-tools/score-task-priority.js.map +1 -1
- package/dist/tasks/affected-packages.d.ts +5 -1
- package/dist/tasks/affected-packages.d.ts.map +1 -1
- package/dist/tasks/affected-packages.js +21 -3
- package/dist/tasks/affected-packages.js.map +1 -1
- package/dist/tasks/analyze.d.ts +29 -1
- package/dist/tasks/analyze.d.ts.map +1 -1
- package/dist/tasks/analyze.js +45 -34
- package/dist/tasks/analyze.js.map +1 -1
- package/dist/tasks/backfill-child-projections.d.ts.map +1 -1
- package/dist/tasks/backfill-child-projections.js +4 -1
- package/dist/tasks/backfill-child-projections.js.map +1 -1
- package/dist/tasks/change-set.d.ts.map +1 -1
- package/dist/tasks/change-set.js +16 -3
- package/dist/tasks/change-set.js.map +1 -1
- package/dist/tasks/command-line.d.ts +54 -0
- package/dist/tasks/command-line.d.ts.map +1 -0
- package/dist/tasks/command-line.js +151 -0
- package/dist/tasks/command-line.js.map +1 -0
- package/dist/tasks/component-pr.d.ts.map +1 -1
- package/dist/tasks/component-pr.js +97 -12
- package/dist/tasks/component-pr.js.map +1 -1
- package/dist/tasks/delete.d.ts.map +1 -1
- package/dist/tasks/delete.js +20 -0
- package/dist/tasks/delete.js.map +1 -1
- package/dist/tasks/duplicate-detector.d.ts +3 -3
- package/dist/tasks/duplicate-detector.d.ts.map +1 -1
- package/dist/tasks/duplicate-detector.js +4 -3
- package/dist/tasks/duplicate-detector.js.map +1 -1
- package/dist/tasks/engine-wrap-ops.d.ts +29 -0
- package/dist/tasks/engine-wrap-ops.d.ts.map +1 -1
- package/dist/tasks/engine-wrap-ops.js +40 -0
- package/dist/tasks/engine-wrap-ops.js.map +1 -1
- package/dist/tasks/engine-wrap.d.ts +1 -1
- package/dist/tasks/engine-wrap.d.ts.map +1 -1
- package/dist/tasks/engine-wrap.js +1 -1
- package/dist/tasks/engine-wrap.js.map +1 -1
- package/dist/tasks/evidence.d.ts +2 -0
- package/dist/tasks/evidence.d.ts.map +1 -1
- package/dist/tasks/evidence.js +30 -4
- package/dist/tasks/evidence.js.map +1 -1
- package/dist/tasks/gate-runner.d.ts.map +1 -1
- package/dist/tasks/gate-runner.js +48 -12
- package/dist/tasks/gate-runner.js.map +1 -1
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.d.ts.map +1 -1
- package/dist/tasks/index.js +1 -1
- package/dist/tasks/index.js.map +1 -1
- package/dist/tasks/ops.d.ts +1 -0
- package/dist/tasks/ops.d.ts.map +1 -1
- package/dist/tasks/ranking-audit.d.ts +122 -0
- package/dist/tasks/ranking-audit.d.ts.map +1 -0
- package/dist/tasks/ranking-audit.js +193 -0
- package/dist/tasks/ranking-audit.js.map +1 -0
- package/dist/tasks/task-analyze.d.ts.map +1 -1
- package/dist/tasks/task-analyze.js +19 -32
- package/dist/tasks/task-analyze.js.map +1 -1
- package/dist/tasks/task-next.d.ts +44 -2
- package/dist/tasks/task-next.d.ts.map +1 -1
- package/dist/tasks/task-next.js +80 -102
- package/dist/tasks/task-next.js.map +1 -1
- package/dist/tasks/task-ops.d.ts +1 -1
- package/dist/tasks/task-ops.d.ts.map +1 -1
- package/dist/tasks/task-ops.js +1 -1
- package/dist/tasks/task-ops.js.map +1 -1
- package/dist/tasks/tool-resolver.d.ts +7 -1
- package/dist/tasks/tool-resolver.d.ts.map +1 -1
- package/dist/tasks/tool-resolver.js +24 -10
- package/dist/tasks/tool-resolver.js.map +1 -1
- package/dist/tasks/update.d.ts +8 -2
- package/dist/tasks/update.d.ts.map +1 -1
- package/dist/tasks/update.js +28 -1
- package/dist/tasks/update.js.map +1 -1
- package/dist/telemetry/sqlite.d.ts.map +1 -1
- package/dist/telemetry/sqlite.js +2 -0
- package/dist/telemetry/sqlite.js.map +1 -1
- package/dist/validation/doctor/checks.d.ts.map +1 -1
- package/dist/validation/doctor/checks.js +2 -2
- package/dist/validation/doctor/checks.js.map +1 -1
- package/package.json +14 -14
- package/schemas/config.schema.json +13 -0
- package/templates/CLEO-INJECTION.md +1 -1
- package/templates/CLEO-REFERENCE.md +5 -1
|
@@ -102,9 +102,9 @@ function getLogDir() {
|
|
|
102
102
|
return currentLogDir;
|
|
103
103
|
}
|
|
104
104
|
function closeLogger() {
|
|
105
|
-
return new Promise((
|
|
105
|
+
return new Promise((resolve17) => {
|
|
106
106
|
if (!rootLogger) {
|
|
107
|
-
|
|
107
|
+
resolve17();
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
110
|
const logger8 = rootLogger;
|
|
@@ -116,7 +116,7 @@ function closeLogger() {
|
|
|
116
116
|
rootLogger = null;
|
|
117
117
|
currentLogDir = null;
|
|
118
118
|
currentTransport = null;
|
|
119
|
-
|
|
119
|
+
resolve17();
|
|
120
120
|
};
|
|
121
121
|
logger8.flush(() => {
|
|
122
122
|
if (transport && typeof transport.end === "function") {
|
|
@@ -479,7 +479,7 @@ var init_acceptance_gate_schema = __esm({
|
|
|
479
479
|
message: "Result cannot precede input capture"
|
|
480
480
|
});
|
|
481
481
|
const executable = ["test", "command", "lint"].includes(result.kind);
|
|
482
|
-
if (executable && !binding.invocation)
|
|
482
|
+
if (executable && !binding.invocation && result.result !== "error")
|
|
483
483
|
context.addIssue({
|
|
484
484
|
code: "custom",
|
|
485
485
|
path: ["binding", "invocation"],
|
|
@@ -3245,12 +3245,21 @@ var init_operations_registry = __esm({
|
|
|
3245
3245
|
gateway: "query",
|
|
3246
3246
|
domain: "tasks",
|
|
3247
3247
|
operation: "history",
|
|
3248
|
-
description: "Show task work history
|
|
3248
|
+
description: "Show task work history; with taskId, the task audit trail; with ranking, who changed its priority/severity/kind/depends and why (T12693)",
|
|
3249
3249
|
tier: 1,
|
|
3250
3250
|
idempotent: true,
|
|
3251
3251
|
sessionRequired: false,
|
|
3252
3252
|
requiredParams: [],
|
|
3253
|
-
params: [
|
|
3253
|
+
params: [
|
|
3254
|
+
{ name: "taskId", type: "string", required: false, description: "Task to show history for" },
|
|
3255
|
+
{ name: "limit", type: "number", required: false, description: "Maximum entries" },
|
|
3256
|
+
{
|
|
3257
|
+
name: "ranking",
|
|
3258
|
+
type: "boolean",
|
|
3259
|
+
required: false,
|
|
3260
|
+
description: "Only ranking-input changes (actor, session, reason, before/after)"
|
|
3261
|
+
}
|
|
3262
|
+
]
|
|
3254
3263
|
},
|
|
3255
3264
|
{
|
|
3256
3265
|
gateway: "query",
|
|
@@ -5745,6 +5754,32 @@ var init_operations_registry = __esm({
|
|
|
5745
5754
|
],
|
|
5746
5755
|
outputSchema: OUTPUT_CONTRACTS["tasks.assignee"]
|
|
5747
5756
|
},
|
|
5757
|
+
{
|
|
5758
|
+
gateway: "mutate",
|
|
5759
|
+
domain: "tasks",
|
|
5760
|
+
operation: "ranking.revert",
|
|
5761
|
+
description: "tasks.ranking.revert (mutate) \u2014 undo one recorded ranking change (priority/severity/kind/depends) as a new audited change (T12693, D11161)",
|
|
5762
|
+
tier: 1,
|
|
5763
|
+
idempotent: false,
|
|
5764
|
+
sessionRequired: false,
|
|
5765
|
+
requiredParams: ["entryId"],
|
|
5766
|
+
params: [
|
|
5767
|
+
{
|
|
5768
|
+
name: "entryId",
|
|
5769
|
+
type: "string",
|
|
5770
|
+
required: true,
|
|
5771
|
+
description: "ranking_changed audit row id (cleo history ranking <taskId>)",
|
|
5772
|
+
cli: { positional: true }
|
|
5773
|
+
},
|
|
5774
|
+
{ name: "reason", type: "string", required: false, description: "Why it is reverted" },
|
|
5775
|
+
{
|
|
5776
|
+
name: "force",
|
|
5777
|
+
type: "boolean",
|
|
5778
|
+
required: false,
|
|
5779
|
+
description: "Revert even though a field changed again since"
|
|
5780
|
+
}
|
|
5781
|
+
]
|
|
5782
|
+
},
|
|
5748
5783
|
{
|
|
5749
5784
|
gateway: "mutate",
|
|
5750
5785
|
domain: "tasks",
|
|
@@ -13212,7 +13247,10 @@ var init_evidence_atom_schema = __esm({
|
|
|
13212
13247
|
["commit", "note"],
|
|
13213
13248
|
["decision", "files"],
|
|
13214
13249
|
["decision", "note"],
|
|
13215
|
-
["pr", "files"]
|
|
13250
|
+
["pr", "files"],
|
|
13251
|
+
// T12689: a deletion-only PR (no bytes to hash). Contextual validation
|
|
13252
|
+
// accepts this only when every change the PR made is a deletion.
|
|
13253
|
+
["pr", "note"]
|
|
13216
13254
|
]
|
|
13217
13255
|
},
|
|
13218
13256
|
testsPassed: { oneOf: [["test-run"], ["tool"], ["ci"]] },
|
|
@@ -17126,7 +17164,7 @@ var init_collection_keys = __esm({
|
|
|
17126
17164
|
|
|
17127
17165
|
// packages/contracts/src/decide.ts
|
|
17128
17166
|
import { z as z24 } from "zod";
|
|
17129
|
-
var DECISION_QUESTION_TYPES, DECISION_OUTCOME_SOURCES, DECISION_REQUEST_LIMITS, decisionQuestionTypeSchema, decisionOutcomeSourceSchema, decisionInstructionsSchema, unitIntervalSchema, decisionStateSchema, noulDecisionQuestionSchema, choiceDecisionQuestionSchema, scoreDecisionQuestionSchema, decisionQuestionSchema, decisionRequestSchema, noulDecisionAnswerSchema, choiceDecisionAnswerSchema, scoreDecisionAnswerSchema, decisionAnswerSchema, decisionOutcomeSchema, decisionProviderConfigSchema;
|
|
17167
|
+
var DECISION_QUESTION_TYPES, DECISION_OUTCOME_SOURCES, DECISION_REQUEST_LIMITS, DECISION_PROVIDER_KINDS, decisionQuestionTypeSchema, decisionOutcomeSourceSchema, decisionInstructionsSchema, unitIntervalSchema, decisionStateSchema, noulDecisionQuestionSchema, choiceDecisionQuestionSchema, scoreDecisionQuestionSchema, decisionQuestionSchema, decisionRequestSchema, noulDecisionAnswerSchema, choiceDecisionAnswerSchema, scoreDecisionAnswerSchema, decisionAnswerSchema, decisionOutcomeSchema, decisionProviderKindSchema, decisionProviderConfigSchema;
|
|
17130
17168
|
var init_decide = __esm({
|
|
17131
17169
|
"packages/contracts/src/decide.ts"() {
|
|
17132
17170
|
"use strict";
|
|
@@ -17150,6 +17188,7 @@ var init_decide = __esm({
|
|
|
17150
17188
|
/** Maximum number of levels on a `score` question's scale. */
|
|
17151
17189
|
maxScoreLevels: 10
|
|
17152
17190
|
};
|
|
17191
|
+
DECISION_PROVIDER_KINDS = ["layahost", "jev"];
|
|
17153
17192
|
decisionQuestionTypeSchema = z24.enum(DECISION_QUESTION_TYPES);
|
|
17154
17193
|
decisionOutcomeSourceSchema = z24.enum(DECISION_OUTCOME_SOURCES);
|
|
17155
17194
|
decisionInstructionsSchema = z24.union([z24.string(), z24.record(z24.string(), z24.json())]);
|
|
@@ -17187,6 +17226,8 @@ var init_decide = __esm({
|
|
|
17187
17226
|
]);
|
|
17188
17227
|
decisionRequestSchema = z24.object({
|
|
17189
17228
|
model: z24.string().min(1).optional(),
|
|
17229
|
+
lang: z24.string().regex(/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})?$/).optional(),
|
|
17230
|
+
cache: z24.boolean().optional(),
|
|
17190
17231
|
state: decisionStateSchema,
|
|
17191
17232
|
questions: z24.record(z24.string().min(1), decisionQuestionSchema).refine(
|
|
17192
17233
|
(questions) => {
|
|
@@ -17227,14 +17268,26 @@ var init_decide = __esm({
|
|
|
17227
17268
|
requestId: z24.string().min(1).optional(),
|
|
17228
17269
|
latencyMs: z24.number().nonnegative(),
|
|
17229
17270
|
costUsd: z24.number().nonnegative().optional(),
|
|
17271
|
+
costMicros: z24.number().int().nonnegative().optional(),
|
|
17272
|
+
balanceMicros: z24.number().int().optional(),
|
|
17273
|
+
checkpoint: z24.string().min(1).optional(),
|
|
17230
17274
|
inputTokens: z24.number().int().nonnegative().optional()
|
|
17231
17275
|
});
|
|
17276
|
+
decisionProviderKindSchema = z24.enum(DECISION_PROVIDER_KINDS);
|
|
17232
17277
|
decisionProviderConfigSchema = z24.object({
|
|
17233
|
-
baseUrl: z24.url()
|
|
17278
|
+
baseUrl: z24.url(),
|
|
17279
|
+
provider: decisionProviderKindSchema.optional()
|
|
17234
17280
|
});
|
|
17235
17281
|
}
|
|
17236
17282
|
});
|
|
17237
17283
|
|
|
17284
|
+
// packages/contracts/src/decide-sites.ts
|
|
17285
|
+
var init_decide_sites = __esm({
|
|
17286
|
+
"packages/contracts/src/decide-sites.ts"() {
|
|
17287
|
+
"use strict";
|
|
17288
|
+
}
|
|
17289
|
+
});
|
|
17290
|
+
|
|
17238
17291
|
// packages/contracts/src/task-id.ts
|
|
17239
17292
|
var init_task_id = __esm({
|
|
17240
17293
|
"packages/contracts/src/task-id.ts"() {
|
|
@@ -17316,6 +17369,7 @@ var init_src = __esm({
|
|
|
17316
17369
|
init_caamp_markers();
|
|
17317
17370
|
init_collection_keys();
|
|
17318
17371
|
init_decide();
|
|
17372
|
+
init_decide_sites();
|
|
17319
17373
|
init_task_id();
|
|
17320
17374
|
}
|
|
17321
17375
|
});
|
|
@@ -18932,7 +18986,10 @@ function linkedWorktreeMainRoot(dir) {
|
|
|
18932
18986
|
}
|
|
18933
18987
|
function describeWorktreeOwner(dir) {
|
|
18934
18988
|
const mainRoot = linkedWorktreeMainRoot(dir);
|
|
18935
|
-
if (mainRoot === null)
|
|
18989
|
+
if (mainRoot === null) {
|
|
18990
|
+
const bare = bareRepositoryOfWorktree(dir);
|
|
18991
|
+
return bare === null ? "owning repository unknown (unreadable gitlink)" : `owning repository ${bare} is a bare git repository with no main checkout to hold a CLEO store; clone it to a regular checkout, run \`cleo init\` there, and create worktrees from that checkout`;
|
|
18992
|
+
}
|
|
18936
18993
|
let projectId = null;
|
|
18937
18994
|
try {
|
|
18938
18995
|
const parsed = JSON.parse(
|
|
@@ -18946,6 +19003,18 @@ function describeWorktreeOwner(dir) {
|
|
|
18946
19003
|
}
|
|
18947
19004
|
return projectId === null ? `owning repository ${mainRoot} (not an initialised CLEO project)` : `owning project ${mainRoot} (projectId ${projectId})`;
|
|
18948
19005
|
}
|
|
19006
|
+
function bareRepositoryOfWorktree(dir) {
|
|
19007
|
+
const gitdir = readGitlinkTarget(dir);
|
|
19008
|
+
if (!gitdir || basename2(dirname3(gitdir)) !== "worktrees") return null;
|
|
19009
|
+
const commonDir = dirname3(dirname3(gitdir));
|
|
19010
|
+
try {
|
|
19011
|
+
const config2 = readFileSync3(join5(commonDir, "config"), "utf-8");
|
|
19012
|
+
const core = /^\[core\][^[]*/m.exec(config2)?.[0] ?? "";
|
|
19013
|
+
return /^\s*bare\s*=\s*true\s*$/im.test(core) ? commonDir : null;
|
|
19014
|
+
} catch {
|
|
19015
|
+
return null;
|
|
19016
|
+
}
|
|
19017
|
+
}
|
|
18949
19018
|
function readCoreWorktree(gitDir) {
|
|
18950
19019
|
try {
|
|
18951
19020
|
const config2 = readFileSync3(join5(gitDir, "config"), "utf-8");
|
|
@@ -19395,13 +19464,13 @@ function captureWriteFence(input) {
|
|
|
19395
19464
|
return writeFence;
|
|
19396
19465
|
}
|
|
19397
19466
|
function observeOperation(context, work) {
|
|
19398
|
-
return new Promise((
|
|
19467
|
+
return new Promise((resolve17) => {
|
|
19399
19468
|
let observed = false;
|
|
19400
19469
|
const finish = (result) => {
|
|
19401
19470
|
if (observed) return;
|
|
19402
19471
|
observed = true;
|
|
19403
19472
|
context.signal.removeEventListener("abort", abort);
|
|
19404
|
-
|
|
19473
|
+
resolve17(result);
|
|
19405
19474
|
};
|
|
19406
19475
|
const abort = () => {
|
|
19407
19476
|
const reason = context.signal.reason;
|
|
@@ -20035,7 +20104,7 @@ var init_sql = __esm({
|
|
|
20035
20104
|
return new SQL([new StringChunk(str)]);
|
|
20036
20105
|
}
|
|
20037
20106
|
_sql.raw = raw;
|
|
20038
|
-
function
|
|
20107
|
+
function join54(chunks, separator) {
|
|
20039
20108
|
const result = [];
|
|
20040
20109
|
for (const [i, chunk] of chunks.entries()) {
|
|
20041
20110
|
if (i > 0 && separator !== void 0) result.push(separator);
|
|
@@ -20043,7 +20112,7 @@ var init_sql = __esm({
|
|
|
20043
20112
|
}
|
|
20044
20113
|
return new SQL(result);
|
|
20045
20114
|
}
|
|
20046
|
-
_sql.join =
|
|
20115
|
+
_sql.join = join54;
|
|
20047
20116
|
function identifier2(value) {
|
|
20048
20117
|
return new Name(value);
|
|
20049
20118
|
}
|
|
@@ -22058,7 +22127,7 @@ var init_select = __esm({
|
|
|
22058
22127
|
const baseTableName = this.tableName;
|
|
22059
22128
|
const tableName = getTableLikeName(table);
|
|
22060
22129
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
22061
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
22130
|
+
if (typeof tableName === "string" && this.config.joins?.some((join54) => join54.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
22062
22131
|
if (!this.isPartialSelect) {
|
|
22063
22132
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
22064
22133
|
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
@@ -23655,7 +23724,7 @@ var init_dialect = __esm({
|
|
|
23655
23724
|
if (!joins2) return;
|
|
23656
23725
|
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
23657
23726
|
if (!withEntries.length) return;
|
|
23658
|
-
return sql.join(withEntries.map(([k,
|
|
23727
|
+
return sql.join(withEntries.map(([k, join54]) => {
|
|
23659
23728
|
const relation = tableConfig.relations[k];
|
|
23660
23729
|
const isSingle2 = is(relation, One);
|
|
23661
23730
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
@@ -23666,7 +23735,7 @@ var init_dialect = __esm({
|
|
|
23666
23735
|
table: targetTable,
|
|
23667
23736
|
mode: isSingle2 ? "first" : "many",
|
|
23668
23737
|
schema,
|
|
23669
|
-
queryConfig:
|
|
23738
|
+
queryConfig: join54,
|
|
23670
23739
|
tableConfig: schema[relation.targetTableName],
|
|
23671
23740
|
relationWhere: filter2,
|
|
23672
23741
|
isNested: true,
|
|
@@ -23680,7 +23749,7 @@ var init_dialect = __esm({
|
|
|
23680
23749
|
key: k,
|
|
23681
23750
|
selection: innerQuery.selection,
|
|
23682
23751
|
isArray: !isSingle2,
|
|
23683
|
-
isOptional: (relation.optional ?? false) ||
|
|
23752
|
+
isOptional: (relation.optional ?? false) || join54 !== true && !!join54.where
|
|
23684
23753
|
});
|
|
23685
23754
|
const jsonColumns = sql.join(innerQuery.selection.map((s) => {
|
|
23686
23755
|
return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb2}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
|
|
@@ -24102,7 +24171,7 @@ var init_update = __esm({
|
|
|
24102
24171
|
createJoin(joinType) {
|
|
24103
24172
|
return ((table, on) => {
|
|
24104
24173
|
const tableName = getTableLikeName(table);
|
|
24105
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
24174
|
+
if (typeof tableName === "string" && this.config.joins.some((join54) => join54.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
24106
24175
|
if (typeof on === "function") {
|
|
24107
24176
|
const from = this.config.from ? is(table, SQLiteTable) ? table[Table.Symbol.Columns] : is(table, Subquery) ? table._.selectedFields : is(table, SQLiteViewBase) ? table[ViewBaseConfig].selectedFields : void 0 : void 0;
|
|
24108
24177
|
on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
@@ -25227,7 +25296,7 @@ async function withWriteRetry(fn, opts = {}) {
|
|
|
25227
25296
|
throw contentionErr;
|
|
25228
25297
|
}
|
|
25229
25298
|
function sleep(ms) {
|
|
25230
|
-
return new Promise((
|
|
25299
|
+
return new Promise((resolve17) => setTimeout(resolve17, ms));
|
|
25231
25300
|
}
|
|
25232
25301
|
var DEFAULT_MAX_ATTEMPTS, DEFAULT_BASE_DELAY_MS, DEFAULT_JITTER_MS;
|
|
25233
25302
|
var init_with_retry = __esm({
|
|
@@ -25239,9 +25308,250 @@ var init_with_retry = __esm({
|
|
|
25239
25308
|
}
|
|
25240
25309
|
});
|
|
25241
25310
|
|
|
25311
|
+
// packages/core/src/store/worktree-build-guard.ts
|
|
25312
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
25313
|
+
import { createRequire } from "node:module";
|
|
25314
|
+
import { dirname as dirname4, isAbsolute as isAbsolute3, join as join7, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
25315
|
+
import { fileURLToPath } from "node:url";
|
|
25316
|
+
function realOrResolved(path) {
|
|
25317
|
+
try {
|
|
25318
|
+
return realpathSync3(path);
|
|
25319
|
+
} catch {
|
|
25320
|
+
return resolve2(path);
|
|
25321
|
+
}
|
|
25322
|
+
}
|
|
25323
|
+
function isWithin(root, path) {
|
|
25324
|
+
const local = relative2(root, path);
|
|
25325
|
+
return local === "" || !isAbsolute3(local) && local !== ".." && !local.startsWith(`..${sep2}`);
|
|
25326
|
+
}
|
|
25327
|
+
function insideGitCheckout(dir) {
|
|
25328
|
+
let current = dir;
|
|
25329
|
+
for (; ; ) {
|
|
25330
|
+
if (existsSync5(join7(current, ".git"))) return true;
|
|
25331
|
+
const parent = dirname4(current);
|
|
25332
|
+
if (parent === current) return false;
|
|
25333
|
+
current = parent;
|
|
25334
|
+
}
|
|
25335
|
+
}
|
|
25336
|
+
function insideTestSandbox(path) {
|
|
25337
|
+
let dir = dirname4(path);
|
|
25338
|
+
for (; ; ) {
|
|
25339
|
+
if (existsSync5(join7(dir, TEST_SANDBOX_MARKER))) return !insideGitCheckout(dir);
|
|
25340
|
+
const parent = dirname4(dir);
|
|
25341
|
+
if (parent === dir) return false;
|
|
25342
|
+
dir = parent;
|
|
25343
|
+
}
|
|
25344
|
+
}
|
|
25345
|
+
function linkedWorktreeRootOf(path) {
|
|
25346
|
+
let dir = realOrResolved(path);
|
|
25347
|
+
for (; ; ) {
|
|
25348
|
+
if (isGitLinkedCheckout(dir)) return dir;
|
|
25349
|
+
if (existsSync5(join7(dir, ".git"))) return null;
|
|
25350
|
+
const parent = dirname4(dir);
|
|
25351
|
+
if (parent === dir) return null;
|
|
25352
|
+
dir = parent;
|
|
25353
|
+
}
|
|
25354
|
+
}
|
|
25355
|
+
function readBuildProvenance(codePath) {
|
|
25356
|
+
let dir = dirname4(codePath);
|
|
25357
|
+
for (; ; ) {
|
|
25358
|
+
const stamp = join7(dir, "build-provenance.json");
|
|
25359
|
+
if (existsSync5(stamp)) {
|
|
25360
|
+
try {
|
|
25361
|
+
const parsed = JSON.parse(readFileSync4(stamp, "utf8"));
|
|
25362
|
+
if (typeof parsed === "object" && parsed !== null && "linkedWorktree" in parsed) {
|
|
25363
|
+
const value = parsed.linkedWorktree;
|
|
25364
|
+
if (value === null || typeof value === "string") return { linkedWorktree: value };
|
|
25365
|
+
}
|
|
25366
|
+
} catch {
|
|
25367
|
+
}
|
|
25368
|
+
return null;
|
|
25369
|
+
}
|
|
25370
|
+
if (existsSync5(join7(dir, "package.json"))) return null;
|
|
25371
|
+
const parent = dirname4(dir);
|
|
25372
|
+
if (parent === dir) return null;
|
|
25373
|
+
dir = parent;
|
|
25374
|
+
}
|
|
25375
|
+
}
|
|
25376
|
+
function devBuildWorktree(options = {}) {
|
|
25377
|
+
const codePath = options.codePath ?? overrides?.codePath ?? fileURLToPath(import.meta.url);
|
|
25378
|
+
const provenance = options.provenance !== void 0 ? options.provenance : overrides?.provenance !== void 0 ? overrides.provenance : readBuildProvenance(codePath);
|
|
25379
|
+
if (provenance) return provenance.linkedWorktree;
|
|
25380
|
+
if (codePath.split(/[\\/]/).includes("node_modules")) return null;
|
|
25381
|
+
return linkedWorktreeRootOf(codePath);
|
|
25382
|
+
}
|
|
25383
|
+
function schemaWriteRefusal(dbPath, options = {}) {
|
|
25384
|
+
const env = options.env ?? overrides?.env ?? process.env;
|
|
25385
|
+
const buildWorktree = devBuildWorktree(options);
|
|
25386
|
+
if (buildWorktree === null) return null;
|
|
25387
|
+
const store = realOrResolved(dbPath);
|
|
25388
|
+
if (isWithin(realOrResolved(buildWorktree), store)) return null;
|
|
25389
|
+
if (env["VITEST"]) return null;
|
|
25390
|
+
const honourTestSandbox = options.honourTestSandbox ?? overrides?.honourTestSandbox ?? true;
|
|
25391
|
+
if (honourTestSandbox && insideTestSandbox(store)) return null;
|
|
25392
|
+
if (env[ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV] === "1") return null;
|
|
25393
|
+
return `Refusing to change the schema of ${store}: this CLI was built inside the git worktree ${buildWorktree}, and its schema may be unreleased. Run the released \`cleo\` against this store, or opt in with ${ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV}=1 (T12687).`;
|
|
25394
|
+
}
|
|
25395
|
+
function decisionFor(dbPath) {
|
|
25396
|
+
const key = realOrResolved(dbPath);
|
|
25397
|
+
if (!decisions.has(key)) decisions.set(key, schemaWriteRefusal(key));
|
|
25398
|
+
return decisions.get(key) ?? null;
|
|
25399
|
+
}
|
|
25400
|
+
function isWorktreeBuildSchemaError(error48) {
|
|
25401
|
+
return error48 instanceof Error && error48.message.includes(E_WORKTREE_BUILD_SCHEMA);
|
|
25402
|
+
}
|
|
25403
|
+
function codes() {
|
|
25404
|
+
if (authorizerCodes) return authorizerCodes;
|
|
25405
|
+
const sqlite = createRequire(import.meta.url)("node:sqlite").constants;
|
|
25406
|
+
authorizerCodes = {
|
|
25407
|
+
sqlite,
|
|
25408
|
+
creates: /* @__PURE__ */ new Map([
|
|
25409
|
+
[sqlite.SQLITE_CREATE_TABLE, "table"],
|
|
25410
|
+
[sqlite.SQLITE_CREATE_VTABLE, "table"],
|
|
25411
|
+
[sqlite.SQLITE_CREATE_INDEX, "index"],
|
|
25412
|
+
[sqlite.SQLITE_CREATE_TRIGGER, "trigger"],
|
|
25413
|
+
[sqlite.SQLITE_CREATE_VIEW, "view"]
|
|
25414
|
+
]),
|
|
25415
|
+
changes: /* @__PURE__ */ new Set([
|
|
25416
|
+
sqlite.SQLITE_ALTER_TABLE,
|
|
25417
|
+
sqlite.SQLITE_DROP_TABLE,
|
|
25418
|
+
sqlite.SQLITE_DROP_INDEX,
|
|
25419
|
+
sqlite.SQLITE_DROP_TRIGGER,
|
|
25420
|
+
sqlite.SQLITE_DROP_VIEW,
|
|
25421
|
+
sqlite.SQLITE_DROP_VTABLE
|
|
25422
|
+
])
|
|
25423
|
+
};
|
|
25424
|
+
return authorizerCodes;
|
|
25425
|
+
}
|
|
25426
|
+
function attachRefusal(name15) {
|
|
25427
|
+
if (name15 === "" || name15 === ":memory:") return null;
|
|
25428
|
+
if (typeof name15 !== "string" || /^file:/i.test(name15) || name15.includes("?")) {
|
|
25429
|
+
return UNKNOWN_ATTACH_REFUSAL;
|
|
25430
|
+
}
|
|
25431
|
+
return decisionFor(name15);
|
|
25432
|
+
}
|
|
25433
|
+
function readSchemas(nativeDb) {
|
|
25434
|
+
const schemas = /* @__PURE__ */ new Map();
|
|
25435
|
+
const list = nativeDb.prepare("PRAGMA database_list").all();
|
|
25436
|
+
for (const { name: name15, file: file2 } of list) {
|
|
25437
|
+
if (name15 === "temp") continue;
|
|
25438
|
+
const rows = nativeDb.prepare(`SELECT type, name FROM "${name15.replaceAll('"', '""')}".sqlite_master`).all();
|
|
25439
|
+
schemas.set(name15.toLowerCase(), {
|
|
25440
|
+
refusal: file2 ? decisionFor(file2) : null,
|
|
25441
|
+
// '' = in-memory
|
|
25442
|
+
objects: new Set(rows.map((r) => `${r.type}:${r.name}`))
|
|
25443
|
+
});
|
|
25444
|
+
}
|
|
25445
|
+
return schemas;
|
|
25446
|
+
}
|
|
25447
|
+
function guardActive() {
|
|
25448
|
+
const env = overrides?.env ?? process.env;
|
|
25449
|
+
if (env["VITEST"]) return false;
|
|
25450
|
+
if (overrides) return devBuildWorktree() !== null;
|
|
25451
|
+
if (processBuildWorktree === void 0) processBuildWorktree = devBuildWorktree();
|
|
25452
|
+
return processBuildWorktree !== null;
|
|
25453
|
+
}
|
|
25454
|
+
function installSchemaWriteGuard(nativeDb) {
|
|
25455
|
+
if (!guardActive()) return false;
|
|
25456
|
+
const location = nativeDb.location();
|
|
25457
|
+
const mainRefusal = location ? decisionFor(location) : null;
|
|
25458
|
+
if (typeof nativeDb.setAuthorizer !== "function") {
|
|
25459
|
+
if (mainRefusal) throw new WorktreeBuildSchemaError(mainRefusal);
|
|
25460
|
+
return false;
|
|
25461
|
+
}
|
|
25462
|
+
const state = {
|
|
25463
|
+
schemas: readSchemas(nativeDb),
|
|
25464
|
+
unmappedAttachRefusal: null,
|
|
25465
|
+
stale: false,
|
|
25466
|
+
lastDenied: null
|
|
25467
|
+
};
|
|
25468
|
+
guards.set(nativeDb, state);
|
|
25469
|
+
const { sqlite, creates, changes } = codes();
|
|
25470
|
+
nativeDb.setAuthorizer((action, arg1, arg2, dbName) => {
|
|
25471
|
+
if (action === sqlite.SQLITE_ATTACH) {
|
|
25472
|
+
const refusal2 = attachRefusal(arg1);
|
|
25473
|
+
if (refusal2 && !state.unmappedAttachRefusal) state.unmappedAttachRefusal = refusal2;
|
|
25474
|
+
return sqlite.SQLITE_OK;
|
|
25475
|
+
}
|
|
25476
|
+
if (action === sqlite.SQLITE_DETACH) {
|
|
25477
|
+
state.stale = true;
|
|
25478
|
+
return sqlite.SQLITE_OK;
|
|
25479
|
+
}
|
|
25480
|
+
const createType = creates.get(action);
|
|
25481
|
+
if (createType === void 0 && !changes.has(action)) return sqlite.SQLITE_OK;
|
|
25482
|
+
const schema = ((action === sqlite.SQLITE_ALTER_TABLE ? arg1 : dbName) ?? "main").toLowerCase();
|
|
25483
|
+
if (schema === "temp") return sqlite.SQLITE_OK;
|
|
25484
|
+
const mapped = state.schemas.get(schema);
|
|
25485
|
+
const policy = state.stale ? void 0 : mapped;
|
|
25486
|
+
const refusal = policy ? policy.refusal : (mapped?.refusal ?? null) || state.unmappedAttachRefusal;
|
|
25487
|
+
if (refusal === null) return sqlite.SQLITE_OK;
|
|
25488
|
+
if (createType !== void 0 && policy?.objects.has(`${createType}:${arg1}`)) {
|
|
25489
|
+
return sqlite.SQLITE_OK;
|
|
25490
|
+
}
|
|
25491
|
+
state.lastDenied = {
|
|
25492
|
+
what: createType !== void 0 ? `CREATE ${createType} ${schema}.${arg1}` : `schema change on ${schema}.${(action === sqlite.SQLITE_ALTER_TABLE ? arg2 : arg1) ?? ""}`,
|
|
25493
|
+
refusal
|
|
25494
|
+
};
|
|
25495
|
+
return sqlite.SQLITE_DENY;
|
|
25496
|
+
});
|
|
25497
|
+
return mainRefusal !== null;
|
|
25498
|
+
}
|
|
25499
|
+
function refreshSchemaWriteGuard(nativeDb) {
|
|
25500
|
+
const state = guards.get(nativeDb);
|
|
25501
|
+
if (!state) return;
|
|
25502
|
+
state.schemas = readSchemas(nativeDb);
|
|
25503
|
+
state.unmappedAttachRefusal = null;
|
|
25504
|
+
state.stale = false;
|
|
25505
|
+
}
|
|
25506
|
+
function explainSchemaWriteDenial(nativeDb, error48) {
|
|
25507
|
+
if (!(error48 instanceof Error) || !/not authorized/i.test(error48.message)) return error48;
|
|
25508
|
+
const denied = guards.get(nativeDb)?.lastDenied;
|
|
25509
|
+
if (!denied) return error48;
|
|
25510
|
+
return new WorktreeBuildSchemaError(`${denied.refusal} Denied: ${denied.what}.`);
|
|
25511
|
+
}
|
|
25512
|
+
function pendingMigrations(nativeDb, migrations) {
|
|
25513
|
+
const hasJournal = nativeDb.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = '__drizzle_migrations'").get();
|
|
25514
|
+
const applied = hasJournal ? new Set(
|
|
25515
|
+
nativeDb.prepare('SELECT hash FROM main."__drizzle_migrations"').all().map((row) => row.hash)
|
|
25516
|
+
) : /* @__PURE__ */ new Set();
|
|
25517
|
+
return migrations.filter((m) => !applied.has(m.hash)).map((m) => m.name ?? m.hash);
|
|
25518
|
+
}
|
|
25519
|
+
function assertNoPendingMigrationsForWorktreeBuild(nativeDb, migrations) {
|
|
25520
|
+
const dbPath = nativeDb.location();
|
|
25521
|
+
if (!dbPath) return;
|
|
25522
|
+
const refusal = decisionFor(dbPath);
|
|
25523
|
+
if (refusal === null) return;
|
|
25524
|
+
const pending = pendingMigrations(nativeDb, migrations);
|
|
25525
|
+
if (pending.length === 0) return;
|
|
25526
|
+
throw new WorktreeBuildSchemaError(`${refusal} Pending migrations: ${pending.join(", ")}.`);
|
|
25527
|
+
}
|
|
25528
|
+
var ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV, TEST_SANDBOX_MARKER, E_WORKTREE_BUILD_SCHEMA, overrides, decisions, WorktreeBuildSchemaError, authorizerCodes, guards, UNKNOWN_ATTACH_REFUSAL, processBuildWorktree;
|
|
25529
|
+
var init_worktree_build_guard = __esm({
|
|
25530
|
+
"packages/core/src/store/worktree-build-guard.ts"() {
|
|
25531
|
+
"use strict";
|
|
25532
|
+
init_src();
|
|
25533
|
+
init_errors2();
|
|
25534
|
+
init_project_scope();
|
|
25535
|
+
ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV = "CLEO_ALLOW_WORKTREE_BUILD_MIGRATIONS";
|
|
25536
|
+
TEST_SANDBOX_MARKER = ".cleo-test-sandbox";
|
|
25537
|
+
E_WORKTREE_BUILD_SCHEMA = "E_WORKTREE_BUILD_SCHEMA";
|
|
25538
|
+
overrides = null;
|
|
25539
|
+
decisions = /* @__PURE__ */ new Map();
|
|
25540
|
+
WorktreeBuildSchemaError = class extends CleoError {
|
|
25541
|
+
constructor(message) {
|
|
25542
|
+
super(8 /* CONFIG_ERROR */, `${E_WORKTREE_BUILD_SCHEMA}: ${message}`, {
|
|
25543
|
+
fix: `Use the released \`cleo\` for this store, run the build against a store inside its own worktree, or set ${ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV}=1 to accept the schema change.`
|
|
25544
|
+
});
|
|
25545
|
+
}
|
|
25546
|
+
};
|
|
25547
|
+
guards = /* @__PURE__ */ new WeakMap();
|
|
25548
|
+
UNKNOWN_ATTACH_REFUSAL = "a store was ATTACHed by a bound, computed or URI filename, so this build cannot tell whose store it is; schema changes on unmapped schemas are refused until the guard is refreshed";
|
|
25549
|
+
}
|
|
25550
|
+
});
|
|
25551
|
+
|
|
25242
25552
|
// packages/core/src/store/migration-manager.ts
|
|
25243
|
-
import { copyFileSync, existsSync as
|
|
25244
|
-
import { dirname as
|
|
25553
|
+
import { copyFileSync, existsSync as existsSync6 } from "node:fs";
|
|
25554
|
+
import { dirname as dirname5, join as join8 } from "node:path";
|
|
25245
25555
|
function stripSqlComments(sql30) {
|
|
25246
25556
|
return sql30.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
25247
25557
|
}
|
|
@@ -25280,10 +25590,10 @@ function computeEliminatedTables(migrations) {
|
|
|
25280
25590
|
return eliminated;
|
|
25281
25591
|
}
|
|
25282
25592
|
function resolveConsolidationCutoverPrefix(migrationsFolder) {
|
|
25283
|
-
const parent =
|
|
25593
|
+
const parent = dirname5(migrationsFolder);
|
|
25284
25594
|
for (const setName of ["drizzle-cleo-project", "drizzle-cleo-global"]) {
|
|
25285
|
-
const folder =
|
|
25286
|
-
if (!
|
|
25595
|
+
const folder = join8(parent, setName);
|
|
25596
|
+
if (!existsSync6(folder)) continue;
|
|
25287
25597
|
try {
|
|
25288
25598
|
const consolidation = readMigrationFiles({ migrationsFolder: folder }).find(
|
|
25289
25599
|
(m) => /-consolidation-cleo-/.test(m.name ?? "")
|
|
@@ -25307,7 +25617,7 @@ function tableExists(nativeDb, tableName) {
|
|
|
25307
25617
|
}
|
|
25308
25618
|
function createSafetyBackup(dbPath) {
|
|
25309
25619
|
const backupPath = dbPath.replace(/\.db$/, "-pre-cleo.db.bak");
|
|
25310
|
-
if (!
|
|
25620
|
+
if (!existsSync6(backupPath)) {
|
|
25311
25621
|
try {
|
|
25312
25622
|
copyFileSync(dbPath, backupPath);
|
|
25313
25623
|
} catch {
|
|
@@ -25425,6 +25735,16 @@ function readSiblingMigrationHashes(siblingFolder) {
|
|
|
25425
25735
|
return /* @__PURE__ */ new Set();
|
|
25426
25736
|
}
|
|
25427
25737
|
}
|
|
25738
|
+
function readSiblingNewestMillis(siblingFolder) {
|
|
25739
|
+
try {
|
|
25740
|
+
return Math.max(
|
|
25741
|
+
0,
|
|
25742
|
+
...readMigrationFiles({ migrationsFolder: siblingFolder }).map((m) => m.folderMillis)
|
|
25743
|
+
);
|
|
25744
|
+
} catch {
|
|
25745
|
+
return 0;
|
|
25746
|
+
}
|
|
25747
|
+
}
|
|
25428
25748
|
function ensureJournalHashUnique(nativeDb) {
|
|
25429
25749
|
if (!tableExists(nativeDb, "__drizzle_migrations")) return;
|
|
25430
25750
|
try {
|
|
@@ -25473,6 +25793,7 @@ function upgradeSharedJournalFormat(nativeDb, lineageFolders) {
|
|
|
25473
25793
|
return { named, unnamed: rows.length - named };
|
|
25474
25794
|
}
|
|
25475
25795
|
function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsystem, siblingMigrationsFolders = []) {
|
|
25796
|
+
assertNoPendingMigrationsForWorktreeBuild(nativeDb, readMigrationFiles({ migrationsFolder }));
|
|
25476
25797
|
const eliminatedTables = computeEliminatedTables(readMigrationFiles({ migrationsFolder }));
|
|
25477
25798
|
const cutoverPrefix = resolveConsolidationCutoverPrefix(migrationsFolder);
|
|
25478
25799
|
if (siblingMigrationsFolders.length > 0)
|
|
@@ -25504,8 +25825,15 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
25504
25825
|
knownHashes.add(m);
|
|
25505
25826
|
}
|
|
25506
25827
|
}
|
|
25507
|
-
const
|
|
25508
|
-
|
|
25828
|
+
const newestKnownMillis = Math.max(
|
|
25829
|
+
0,
|
|
25830
|
+
...localMigrations.map((m) => m.folderMillis),
|
|
25831
|
+
...siblingMigrationsFolders.filter((folder) => folder !== migrationsFolder).map(readSiblingNewestMillis)
|
|
25832
|
+
);
|
|
25833
|
+
const dbEntries = nativeDb.prepare('SELECT id, hash, created_at FROM "__drizzle_migrations"').all();
|
|
25834
|
+
const orphanedEntries = dbEntries.filter(
|
|
25835
|
+
(e) => !knownHashes.has(e.hash) && !(Number(e.created_at) > newestKnownMillis)
|
|
25836
|
+
);
|
|
25509
25837
|
const hasOrphanedEntries = orphanedEntries.length > 0;
|
|
25510
25838
|
if (hasOrphanedEntries) {
|
|
25511
25839
|
const dbHashes = new Set(dbEntries.map((e) => e.hash));
|
|
@@ -25747,6 +26075,8 @@ function sanitizeMigrationStatements(migrations) {
|
|
|
25747
26075
|
}
|
|
25748
26076
|
function migrateSanitized(db, config2) {
|
|
25749
26077
|
const raw = readMigrationFiles(config2);
|
|
26078
|
+
const client = db.$client;
|
|
26079
|
+
if (client) assertNoPendingMigrationsForWorktreeBuild(client, raw);
|
|
25750
26080
|
const sanitized = sanitizeMigrationStatements(raw);
|
|
25751
26081
|
migrateSync(sanitized, db._.session, config2);
|
|
25752
26082
|
}
|
|
@@ -25810,6 +26140,7 @@ var init_migration_manager = __esm({
|
|
|
25810
26140
|
init_sqlite_core();
|
|
25811
26141
|
init_logger();
|
|
25812
26142
|
init_with_retry();
|
|
26143
|
+
init_worktree_build_guard();
|
|
25813
26144
|
MAX_MIGRATION_RETRIES = 5;
|
|
25814
26145
|
MIGRATION_RETRY_BASE_DELAY_MS = 100;
|
|
25815
26146
|
MIGRATION_RETRY_MAX_DELAY_MS = 2e3;
|
|
@@ -25819,13 +26150,13 @@ var init_migration_manager = __esm({
|
|
|
25819
26150
|
});
|
|
25820
26151
|
|
|
25821
26152
|
// packages/core/src/store/relocated-store-guard.ts
|
|
25822
|
-
import { existsSync as
|
|
25823
|
-
import { createRequire } from "node:module";
|
|
25824
|
-
import { basename as basename3, dirname as
|
|
26153
|
+
import { existsSync as existsSync7, realpathSync as realpathSync4 } from "node:fs";
|
|
26154
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
26155
|
+
import { basename as basename3, dirname as dirname6 } from "node:path";
|
|
25825
26156
|
import { readDeclaredProjectIdentity as readDeclaredProjectIdentity2, readPortableProjectId } from "@cleocode/paths";
|
|
25826
26157
|
function real2(p) {
|
|
25827
26158
|
try {
|
|
25828
|
-
return
|
|
26159
|
+
return realpathSync4(p);
|
|
25829
26160
|
} catch {
|
|
25830
26161
|
return p;
|
|
25831
26162
|
}
|
|
@@ -25842,7 +26173,7 @@ function liveElsewhere(globalDbPath, projectId, root) {
|
|
|
25842
26173
|
"SELECT project_path AS projectPath FROM nexus_project_registry WHERE project_id = ?"
|
|
25843
26174
|
).get(projectId);
|
|
25844
26175
|
const live = row?.projectPath;
|
|
25845
|
-
if (!live || paths.has(live) || !
|
|
26176
|
+
if (!live || paths.has(live) || !existsSync7(live)) return null;
|
|
25846
26177
|
if (!isStrictlyInsideDir(root, live)) return null;
|
|
25847
26178
|
return readDeclaredProjectIdentity2(live)?.projectId === projectId ? live : null;
|
|
25848
26179
|
} catch {
|
|
@@ -25856,14 +26187,14 @@ function detectRelocatedRoot(root, globalDbPath) {
|
|
|
25856
26187
|
if (tombstone)
|
|
25857
26188
|
return { projectId: tombstone.projectId, movedTo: tombstone.movedTo, via: "tombstone" };
|
|
25858
26189
|
const declared = readPortableProjectId(root);
|
|
25859
|
-
if (declared.status !== "valid" || !
|
|
26190
|
+
if (declared.status !== "valid" || !existsSync7(globalDbPath)) return null;
|
|
25860
26191
|
const movedTo = liveElsewhere(globalDbPath, declared.projectId, root);
|
|
25861
26192
|
return movedTo ? { projectId: declared.projectId, movedTo, via: "registry" } : null;
|
|
25862
26193
|
}
|
|
25863
26194
|
function assertStoreNotRelocated(dbPath, globalDbPath) {
|
|
25864
|
-
if (basename3(dbPath) !== "cleo.db" || basename3(
|
|
25865
|
-
if (
|
|
25866
|
-
const root =
|
|
26195
|
+
if (basename3(dbPath) !== "cleo.db" || basename3(dirname6(dbPath)) !== ".cleo") return;
|
|
26196
|
+
if (existsSync7(dbPath) || globalDbPath === dbPath) return;
|
|
26197
|
+
const root = dirname6(dirname6(dbPath));
|
|
25867
26198
|
if (_adopted.has(root)) return;
|
|
25868
26199
|
const moved = detectRelocatedRoot(root, globalDbPath);
|
|
25869
26200
|
if (moved) throw projectMovedError(root, moved, void 0, moved.via);
|
|
@@ -25873,17 +26204,17 @@ var init_relocated_store_guard = __esm({
|
|
|
25873
26204
|
"packages/core/src/store/relocated-store-guard.ts"() {
|
|
25874
26205
|
"use strict";
|
|
25875
26206
|
init_project_tombstone();
|
|
25876
|
-
_require =
|
|
26207
|
+
_require = createRequire2(import.meta.url);
|
|
25877
26208
|
_adopted = /* @__PURE__ */ new Set();
|
|
25878
26209
|
}
|
|
25879
26210
|
});
|
|
25880
26211
|
|
|
25881
26212
|
// packages/core/src/store/resolve-migrations-folder.ts
|
|
25882
|
-
import { createRequire as
|
|
25883
|
-
import { dirname as
|
|
25884
|
-
import { fileURLToPath } from "node:url";
|
|
26213
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
26214
|
+
import { dirname as dirname7, join as join9 } from "node:path";
|
|
26215
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
25885
26216
|
function coreRootFromEntry(entryPath) {
|
|
25886
|
-
return
|
|
26217
|
+
return dirname7(dirname7(entryPath));
|
|
25887
26218
|
}
|
|
25888
26219
|
function resolveConsolidatedJournalSiblings(ownSetName) {
|
|
25889
26220
|
return CONSOLIDATED_JOURNAL_LINEAGES.filter((name15) => name15 !== ownSetName).map(
|
|
@@ -25893,14 +26224,14 @@ function resolveConsolidatedJournalSiblings(ownSetName) {
|
|
|
25893
26224
|
function resolveCorePackageMigrationsFolder(setName) {
|
|
25894
26225
|
try {
|
|
25895
26226
|
const resolved = import.meta.resolve("@cleocode/core", import.meta.url);
|
|
25896
|
-
const entryPath =
|
|
25897
|
-
return
|
|
26227
|
+
const entryPath = fileURLToPath2(resolved);
|
|
26228
|
+
return join9(coreRootFromEntry(entryPath), "migrations", setName);
|
|
25898
26229
|
} catch {
|
|
25899
26230
|
}
|
|
25900
|
-
const _require7 =
|
|
26231
|
+
const _require7 = createRequire3(import.meta.url);
|
|
25901
26232
|
try {
|
|
25902
26233
|
const entryPath = _require7.resolve("@cleocode/core");
|
|
25903
|
-
return
|
|
26234
|
+
return join9(coreRootFromEntry(entryPath), "migrations", setName);
|
|
25904
26235
|
} catch (err) {
|
|
25905
26236
|
throw new Error(
|
|
25906
26237
|
`resolveCorePackageMigrationsFolder("${setName}"): cannot locate @cleocode/core from "${import.meta.url}". Ensure @cleocode/core is installed (workspace or npm). Original error: ${err.message}`
|
|
@@ -25996,11 +26327,11 @@ var init_sqlite_pragmas = __esm({
|
|
|
25996
26327
|
});
|
|
25997
26328
|
|
|
25998
26329
|
// packages/core/src/store/worktree-isolation-guard.ts
|
|
25999
|
-
import { basename as basename4, dirname as
|
|
26330
|
+
import { basename as basename4, dirname as dirname8, join as join10, resolve as resolve3 } from "node:path";
|
|
26000
26331
|
function assertStorePathIsNotWorktreeResident(role, dbPath) {
|
|
26001
|
-
const cleoDir =
|
|
26332
|
+
const cleoDir = dirname8(dbPath);
|
|
26002
26333
|
if (basename4(cleoDir) !== ".cleo") return;
|
|
26003
|
-
const projectRoot =
|
|
26334
|
+
const projectRoot = dirname8(cleoDir);
|
|
26004
26335
|
if (!isGitLinkedCheckout(projectRoot)) return;
|
|
26005
26336
|
if (process.env["CLEO_ALLOW_WORKTREE_DB_CREATE"] === "1") {
|
|
26006
26337
|
process.stderr.write(
|
|
@@ -26025,7 +26356,7 @@ function assertDbPathIsNotWorktreeResident(role, cwd) {
|
|
|
26025
26356
|
} catch {
|
|
26026
26357
|
return;
|
|
26027
26358
|
}
|
|
26028
|
-
assertStorePathIsNotWorktreeResident(role,
|
|
26359
|
+
assertStorePathIsNotWorktreeResident(role, join10(cleoDir, PROJECT_STORE_FILENAME2));
|
|
26029
26360
|
}
|
|
26030
26361
|
var PROJECT_STORE_FILENAME2;
|
|
26031
26362
|
var init_worktree_isolation_guard = __esm({
|
|
@@ -26045,10 +26376,10 @@ __export(sqlite_native_exports, {
|
|
|
26045
26376
|
getDbSyncConstructor: () => getDbSyncConstructor,
|
|
26046
26377
|
openNativeDatabase: () => openNativeDatabase
|
|
26047
26378
|
});
|
|
26048
|
-
import { realpathSync as
|
|
26049
|
-
import { createRequire as
|
|
26379
|
+
import { realpathSync as realpathSync5 } from "node:fs";
|
|
26380
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
26050
26381
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
26051
|
-
import { delimiter, dirname as
|
|
26382
|
+
import { delimiter, dirname as dirname9, isAbsolute as isAbsolute4, join as join11, resolve as resolve4, sep as sep3 } from "node:path";
|
|
26052
26383
|
function getDbSyncConstructor() {
|
|
26053
26384
|
if (_ctor === null) {
|
|
26054
26385
|
const mod = _require2("node:sqlite");
|
|
@@ -26057,19 +26388,19 @@ function getDbSyncConstructor() {
|
|
|
26057
26388
|
return _ctor;
|
|
26058
26389
|
}
|
|
26059
26390
|
function resolveAbsoluteSafe(p) {
|
|
26060
|
-
const abs =
|
|
26391
|
+
const abs = isAbsolute4(p) ? p : resolve4(p);
|
|
26061
26392
|
try {
|
|
26062
|
-
return
|
|
26393
|
+
return realpathSync5(abs);
|
|
26063
26394
|
} catch {
|
|
26064
26395
|
const missingParts = [];
|
|
26065
26396
|
let cursor = abs;
|
|
26066
26397
|
while (true) {
|
|
26067
|
-
const parent =
|
|
26398
|
+
const parent = dirname9(cursor);
|
|
26068
26399
|
if (parent === cursor) return abs;
|
|
26069
|
-
missingParts.unshift(cursor.slice(parent.length + (parent.endsWith(
|
|
26400
|
+
missingParts.unshift(cursor.slice(parent.length + (parent.endsWith(sep3) ? 0 : 1)));
|
|
26070
26401
|
cursor = parent;
|
|
26071
26402
|
try {
|
|
26072
|
-
return
|
|
26403
|
+
return join11(realpathSync5(cursor), ...missingParts);
|
|
26073
26404
|
} catch {
|
|
26074
26405
|
}
|
|
26075
26406
|
}
|
|
@@ -26077,7 +26408,7 @@ function resolveAbsoluteSafe(p) {
|
|
|
26077
26408
|
}
|
|
26078
26409
|
function isPathUnder(child, parent) {
|
|
26079
26410
|
if (child === parent) return true;
|
|
26080
|
-
const withSep = parent.endsWith(
|
|
26411
|
+
const withSep = parent.endsWith(sep3) ? parent : parent + sep3;
|
|
26081
26412
|
return child.startsWith(withSep);
|
|
26082
26413
|
}
|
|
26083
26414
|
function assertVitestSafePath(path) {
|
|
@@ -26100,6 +26431,7 @@ function openNativeDatabase(path, options) {
|
|
|
26100
26431
|
assertVitestSafePath(path);
|
|
26101
26432
|
const DatabaseSyncCtor = getDbSyncConstructor();
|
|
26102
26433
|
const db = new DatabaseSyncCtor(path, {
|
|
26434
|
+
// schema-guard-exempt: the native chokepoint; every writable caller installs the guard
|
|
26103
26435
|
enableForeignKeyConstraints: true,
|
|
26104
26436
|
readOnly: options?.readonly ?? false,
|
|
26105
26437
|
// Default handle-open lock timeout mirrors the SSoT busy_timeout
|
|
@@ -26151,7 +26483,7 @@ var init_sqlite_native = __esm({
|
|
|
26151
26483
|
"packages/core/src/store/sqlite-native.ts"() {
|
|
26152
26484
|
"use strict";
|
|
26153
26485
|
init_sqlite_pragmas();
|
|
26154
|
-
_require2 =
|
|
26486
|
+
_require2 = createRequire4(import.meta.url);
|
|
26155
26487
|
_ctor = null;
|
|
26156
26488
|
}
|
|
26157
26489
|
});
|
|
@@ -26225,7 +26557,7 @@ var init_writer_lease_schema = __esm({
|
|
|
26225
26557
|
// packages/core/src/store/writer-lease.ts
|
|
26226
26558
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
26227
26559
|
import { randomUUID } from "node:crypto";
|
|
26228
|
-
import { realpathSync as
|
|
26560
|
+
import { realpathSync as realpathSync6, statSync as statSync2 } from "node:fs";
|
|
26229
26561
|
import { resolve as resolvePath } from "node:path";
|
|
26230
26562
|
function log() {
|
|
26231
26563
|
if (_log === null) _log = getLogger("writer-lease");
|
|
@@ -26315,7 +26647,7 @@ function resolveDbIdentity(db) {
|
|
|
26315
26647
|
return identity;
|
|
26316
26648
|
}
|
|
26317
26649
|
function sleepAsync(ms) {
|
|
26318
|
-
return new Promise((
|
|
26650
|
+
return new Promise((resolve17) => setTimeout(resolve17, Math.max(0, Math.round(ms))));
|
|
26319
26651
|
}
|
|
26320
26652
|
function isPidAlive(pid) {
|
|
26321
26653
|
try {
|
|
@@ -26654,7 +26986,7 @@ function assertColdOpenFile(frame) {
|
|
|
26654
26986
|
async function withRequiredColdOpenLease(scope, nativeDb, fn, opts) {
|
|
26655
26987
|
opts.execution?.assertActive();
|
|
26656
26988
|
const captured = opts.requiredIdentity;
|
|
26657
|
-
const path =
|
|
26989
|
+
const path = realpathSync6(captured.dbPath);
|
|
26658
26990
|
const identity = statSync2(path, { bigint: true });
|
|
26659
26991
|
if (captured.scope !== scope || captured.fileDevice !== String(identity.dev) || captured.fileInode !== String(identity.ino)) {
|
|
26660
26992
|
throw new LeaseUnavailableError(
|
|
@@ -26687,6 +27019,7 @@ async function withRequiredColdOpenLease(scope, nativeDb, fn, opts) {
|
|
|
26687
27019
|
}
|
|
26688
27020
|
const remaining = opts.execution ? Math.max(1, opts.execution.deadlineAt - Date.now()) : ACQUIRE_DEADLINE_MS;
|
|
26689
27021
|
const owned = openNativeDatabase(path, { timeout: Math.min(ACQUIRE_DEADLINE_MS, remaining) });
|
|
27022
|
+
installSchemaWriteGuard(owned);
|
|
26690
27023
|
try {
|
|
26691
27024
|
opts.execution?.assertActive();
|
|
26692
27025
|
const afterOpen = statSync2(path, { bigint: true });
|
|
@@ -26880,6 +27213,7 @@ var init_writer_lease = __esm({
|
|
|
26880
27213
|
init_background_ops();
|
|
26881
27214
|
init_dual_scope_db();
|
|
26882
27215
|
init_sqlite_native();
|
|
27216
|
+
init_worktree_build_guard();
|
|
26883
27217
|
init_writer_lease_schema();
|
|
26884
27218
|
DEFAULT_TTL_MS = 3e4;
|
|
26885
27219
|
DEFAULT_PRIORITY = 100;
|
|
@@ -27422,10 +27756,10 @@ var init_monitor = __esm({
|
|
|
27422
27756
|
|
|
27423
27757
|
// packages/core/src/resources/supervisor-admit.ts
|
|
27424
27758
|
import { connect } from "node:net";
|
|
27425
|
-
import { join as
|
|
27759
|
+
import { join as join12 } from "node:path";
|
|
27426
27760
|
import { getCleoHome as getCleoHome2 } from "@cleocode/paths";
|
|
27427
27761
|
function resolveSupervisorSocketPath() {
|
|
27428
|
-
return process.env.CLEO_SUPERVISOR_SOCKET ??
|
|
27762
|
+
return process.env.CLEO_SUPERVISOR_SOCKET ?? join12(getCleoHome2(), SUPERVISOR_SOCKET_NAME);
|
|
27429
27763
|
}
|
|
27430
27764
|
async function sendResourceAdmit(socketPath, cls, holderId, budget) {
|
|
27431
27765
|
const result = await sendLeaseRequest(
|
|
@@ -27448,7 +27782,7 @@ async function sendResourceRelease(socketPath, cls, holderId) {
|
|
|
27448
27782
|
return { unavailable: true, reason: `unexpected response kind: ${result.kind}` };
|
|
27449
27783
|
}
|
|
27450
27784
|
function sendLeaseRequest(socketPath, request, expectedKind) {
|
|
27451
|
-
return new Promise((
|
|
27785
|
+
return new Promise((resolve17) => {
|
|
27452
27786
|
const id = `ra-${process.pid}-${request.kind}`;
|
|
27453
27787
|
const envelope = LeaseIpcRequestEnvelopeSchema.parse({
|
|
27454
27788
|
protocol_version: LEASE_IPC_PROTOCOL_VERSION,
|
|
@@ -27466,7 +27800,7 @@ function sendLeaseRequest(socketPath, request, expectedKind) {
|
|
|
27466
27800
|
settled = true;
|
|
27467
27801
|
socket.removeAllListeners();
|
|
27468
27802
|
socket.destroy();
|
|
27469
|
-
|
|
27803
|
+
resolve17(value);
|
|
27470
27804
|
};
|
|
27471
27805
|
const degrade = (reason) => done({ unavailable: true, reason });
|
|
27472
27806
|
socket.setTimeout(REQUEST_TIMEOUT_MS);
|
|
@@ -27537,9 +27871,9 @@ __export(governor_exports, {
|
|
|
27537
27871
|
resolveGovernorMode: () => resolveGovernorMode,
|
|
27538
27872
|
slotFileCount: () => slotFileCount
|
|
27539
27873
|
});
|
|
27540
|
-
import { existsSync as
|
|
27874
|
+
import { existsSync as existsSync8, mkdirSync, readdirSync as readdirSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27541
27875
|
import { availableParallelism, totalmem } from "node:os";
|
|
27542
|
-
import { join as
|
|
27876
|
+
import { join as join13 } from "node:path";
|
|
27543
27877
|
import lockfile from "proper-lockfile";
|
|
27544
27878
|
function log2() {
|
|
27545
27879
|
if (_log2 === null) _log2 = getLogger("resource-governor");
|
|
@@ -27608,14 +27942,14 @@ function clamp2(lo, v, hi) {
|
|
|
27608
27942
|
return Math.max(lo, Math.min(v, hi));
|
|
27609
27943
|
}
|
|
27610
27944
|
function governorSlotDir(cls) {
|
|
27611
|
-
return
|
|
27945
|
+
return join13(getCleoHome(), "locks", `resource-${cls}`);
|
|
27612
27946
|
}
|
|
27613
27947
|
function ensureSlotFiles(dir, count) {
|
|
27614
|
-
if (!
|
|
27948
|
+
if (!existsSync8(dir)) mkdirSync(dir, { recursive: true });
|
|
27615
27949
|
const paths = [];
|
|
27616
27950
|
for (let i = 0; i < count; i++) {
|
|
27617
|
-
const p =
|
|
27618
|
-
if (!
|
|
27951
|
+
const p = join13(dir, `slot-${i}.lock`);
|
|
27952
|
+
if (!existsSync8(p)) writeFileSync3(p, "", { flag: "a" });
|
|
27619
27953
|
paths.push(p);
|
|
27620
27954
|
}
|
|
27621
27955
|
return paths;
|
|
@@ -27655,7 +27989,7 @@ function shuffledIndices(n) {
|
|
|
27655
27989
|
}
|
|
27656
27990
|
async function countHeldSlots(cls, budget) {
|
|
27657
27991
|
const dir = governorSlotDir(cls);
|
|
27658
|
-
if (!
|
|
27992
|
+
if (!existsSync8(dir)) return 0;
|
|
27659
27993
|
const slots = ensureSlotFiles(dir, budget);
|
|
27660
27994
|
let held = 0;
|
|
27661
27995
|
for (const path of slots) {
|
|
@@ -27670,7 +28004,7 @@ async function countHeldSlots(cls, budget) {
|
|
|
27670
28004
|
}
|
|
27671
28005
|
function slotFileCount(cls) {
|
|
27672
28006
|
const dir = governorSlotDir(cls);
|
|
27673
|
-
if (!
|
|
28007
|
+
if (!existsSync8(dir)) return 0;
|
|
27674
28008
|
return readdirSync2(dir).filter((f) => f.startsWith("slot-") && f.endsWith(".lock")).length;
|
|
27675
28009
|
}
|
|
27676
28010
|
var _log2, _cachedMode2, _supervisorDegradeLogged, MB, STALE_MS, _supervisorHolderSeq, ResourceGovernor, governor;
|
|
@@ -27870,11 +28204,11 @@ var init_lock = __esm({
|
|
|
27870
28204
|
|
|
27871
28205
|
// packages/core/src/store/atomic.ts
|
|
27872
28206
|
import { mkdir, readFile as readFile2, rename, unlink } from "node:fs/promises";
|
|
27873
|
-
import { dirname as
|
|
28207
|
+
import { dirname as dirname10 } from "node:path";
|
|
27874
28208
|
import writeFileAtomic from "write-file-atomic";
|
|
27875
28209
|
async function atomicWrite(filePath, data, options) {
|
|
27876
28210
|
try {
|
|
27877
|
-
await mkdir(
|
|
28211
|
+
await mkdir(dirname10(filePath), { recursive: true });
|
|
27878
28212
|
await writeFileAtomic(filePath, data, {
|
|
27879
28213
|
encoding: options?.encoding ?? "utf8",
|
|
27880
28214
|
mode: options?.mode
|
|
@@ -27907,7 +28241,7 @@ var init_atomic = __esm({
|
|
|
27907
28241
|
|
|
27908
28242
|
// packages/core/src/store/backup.ts
|
|
27909
28243
|
import { copyFile, rename as fsRename, mkdir as mkdir2, readdir, stat as stat2, unlink as unlink2 } from "node:fs/promises";
|
|
27910
|
-
import { basename as basename5, join as
|
|
28244
|
+
import { basename as basename5, dirname as dirname11, join as join14 } from "node:path";
|
|
27911
28245
|
async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUPS) {
|
|
27912
28246
|
try {
|
|
27913
28247
|
await mkdir2(backupDir, { recursive: true });
|
|
@@ -27918,14 +28252,14 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
27918
28252
|
throw new CleoError(3 /* FILE_ERROR */, `Cannot backup: source file not found: ${filePath}`);
|
|
27919
28253
|
}
|
|
27920
28254
|
for (let i = maxBackups; i >= 1; i--) {
|
|
27921
|
-
const current =
|
|
28255
|
+
const current = join14(backupDir, `${fileName}.${i}`);
|
|
27922
28256
|
if (i === maxBackups) {
|
|
27923
28257
|
try {
|
|
27924
28258
|
await unlink2(current);
|
|
27925
28259
|
} catch {
|
|
27926
28260
|
}
|
|
27927
28261
|
} else {
|
|
27928
|
-
const next =
|
|
28262
|
+
const next = join14(backupDir, `${fileName}.${i + 1}`);
|
|
27929
28263
|
try {
|
|
27930
28264
|
await stat2(current);
|
|
27931
28265
|
await fsRename(current, next);
|
|
@@ -27933,7 +28267,7 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
27933
28267
|
}
|
|
27934
28268
|
}
|
|
27935
28269
|
}
|
|
27936
|
-
const backupPath =
|
|
28270
|
+
const backupPath = join14(backupDir, `${fileName}.1`);
|
|
27937
28271
|
await copyFile(filePath, backupPath);
|
|
27938
28272
|
return backupPath;
|
|
27939
28273
|
} catch (err) {
|
|
@@ -27947,6 +28281,7 @@ var init_backup = __esm({
|
|
|
27947
28281
|
"use strict";
|
|
27948
28282
|
init_src();
|
|
27949
28283
|
init_errors2();
|
|
28284
|
+
init_worktree_isolation_guard();
|
|
27950
28285
|
DEFAULT_MAX_BACKUPS = 5;
|
|
27951
28286
|
}
|
|
27952
28287
|
});
|
|
@@ -28231,7 +28566,7 @@ __export(identity_exports, {
|
|
|
28231
28566
|
import { execFile } from "node:child_process";
|
|
28232
28567
|
import { createHash as createHash2 } from "node:crypto";
|
|
28233
28568
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
28234
|
-
import { join as
|
|
28569
|
+
import { join as join15, resolve as resolve5 } from "node:path";
|
|
28235
28570
|
import { promisify } from "node:util";
|
|
28236
28571
|
import { legacyProjectId } from "@cleocode/paths";
|
|
28237
28572
|
import { legacyProjectId as legacyProjectId2 } from "@cleocode/paths";
|
|
@@ -28239,14 +28574,14 @@ async function findGitRoot(fromPath, execution) {
|
|
|
28239
28574
|
execution?.assertActive();
|
|
28240
28575
|
try {
|
|
28241
28576
|
const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], {
|
|
28242
|
-
cwd:
|
|
28577
|
+
cwd: resolve5(fromPath),
|
|
28243
28578
|
signal: execution?.signal,
|
|
28244
28579
|
timeout: execution ? Math.max(1, execution.remainingMs()) : void 0,
|
|
28245
28580
|
killSignal: "SIGKILL",
|
|
28246
28581
|
maxBuffer: 64 * 1024
|
|
28247
28582
|
});
|
|
28248
28583
|
execution?.assertActive();
|
|
28249
|
-
return
|
|
28584
|
+
return resolve5(stdout.trim());
|
|
28250
28585
|
} catch {
|
|
28251
28586
|
execution?.assertActive();
|
|
28252
28587
|
return null;
|
|
@@ -28256,7 +28591,7 @@ async function findGitRemoteUrl(fromPath, execution) {
|
|
|
28256
28591
|
execution?.assertActive();
|
|
28257
28592
|
try {
|
|
28258
28593
|
const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
|
|
28259
|
-
cwd:
|
|
28594
|
+
cwd: resolve5(fromPath),
|
|
28260
28595
|
signal: execution?.signal,
|
|
28261
28596
|
timeout: execution ? Math.max(1, execution.remainingMs()) : void 0,
|
|
28262
28597
|
killSignal: "SIGKILL",
|
|
@@ -28286,7 +28621,7 @@ async function collectCheckoutEvidence(fromPath, execution) {
|
|
|
28286
28621
|
try {
|
|
28287
28622
|
const args = ["--no-replace-objects", "rev-list", "--max-parents=0", "HEAD"];
|
|
28288
28623
|
const { stdout } = await execFileAsync("git", args, {
|
|
28289
|
-
cwd:
|
|
28624
|
+
cwd: resolve5(fromPath),
|
|
28290
28625
|
signal: execution?.signal,
|
|
28291
28626
|
timeout: execution ? Math.max(1, execution.remainingMs()) : void 0,
|
|
28292
28627
|
killSignal: "SIGKILL",
|
|
@@ -28309,7 +28644,7 @@ async function collectCheckoutEvidence(fromPath, execution) {
|
|
|
28309
28644
|
async function readProjectInfoName(repoRoot, execution) {
|
|
28310
28645
|
execution?.assertActive();
|
|
28311
28646
|
try {
|
|
28312
|
-
const raw = await readFile3(
|
|
28647
|
+
const raw = await readFile3(join15(repoRoot, ".cleo", "project-info.json"), {
|
|
28313
28648
|
encoding: "utf8",
|
|
28314
28649
|
signal: execution?.signal
|
|
28315
28650
|
});
|
|
@@ -28324,7 +28659,7 @@ async function readProjectInfoName(repoRoot, execution) {
|
|
|
28324
28659
|
}
|
|
28325
28660
|
async function projectPathFingerprint(repoPath, execution) {
|
|
28326
28661
|
execution?.assertActive();
|
|
28327
|
-
const realRepoPath =
|
|
28662
|
+
const realRepoPath = resolve5(repoPath);
|
|
28328
28663
|
const results = await Promise.allSettled([
|
|
28329
28664
|
findGitRoot(realRepoPath, execution),
|
|
28330
28665
|
findGitRemoteUrl(realRepoPath, execution)
|
|
@@ -28348,9 +28683,9 @@ async function projectPathFingerprint(repoPath, execution) {
|
|
|
28348
28683
|
}
|
|
28349
28684
|
function computeLegacyAliases(repoPath, additionalPaths) {
|
|
28350
28685
|
const aliases = /* @__PURE__ */ new Set();
|
|
28351
|
-
aliases.add(legacyProjectId(
|
|
28686
|
+
aliases.add(legacyProjectId(resolve5(repoPath)));
|
|
28352
28687
|
for (const p of additionalPaths ?? []) {
|
|
28353
|
-
aliases.add(legacyProjectId(
|
|
28688
|
+
aliases.add(legacyProjectId(resolve5(p)));
|
|
28354
28689
|
}
|
|
28355
28690
|
return [...aliases];
|
|
28356
28691
|
}
|
|
@@ -28384,17 +28719,17 @@ var init_project_identity = __esm({
|
|
|
28384
28719
|
});
|
|
28385
28720
|
|
|
28386
28721
|
// packages/core/src/scaffold/ensure-config.ts
|
|
28387
|
-
import { existsSync as
|
|
28388
|
-
import { basename as basename6, dirname as
|
|
28389
|
-
import { fileURLToPath as
|
|
28722
|
+
import { existsSync as existsSync9, readFileSync as readFileSync5 } from "node:fs";
|
|
28723
|
+
import { basename as basename6, dirname as dirname12, join as join16, resolve as resolve6 } from "node:path";
|
|
28724
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
28390
28725
|
function getPackageRoot() {
|
|
28391
|
-
const thisFile =
|
|
28392
|
-
return
|
|
28726
|
+
const thisFile = fileURLToPath3(import.meta.url);
|
|
28727
|
+
return resolve6(dirname12(thisFile), "..", "..");
|
|
28393
28728
|
}
|
|
28394
28729
|
function getCleoVersion() {
|
|
28395
28730
|
try {
|
|
28396
|
-
const pkgPath =
|
|
28397
|
-
const pkg = JSON.parse(
|
|
28731
|
+
const pkgPath = join16(getPackageRoot(), "package.json");
|
|
28732
|
+
const pkg = JSON.parse(readFileSync5(pkgPath, "utf-8"));
|
|
28398
28733
|
return pkg.version ?? "0.0.0";
|
|
28399
28734
|
} catch {
|
|
28400
28735
|
return "0.0.0";
|
|
@@ -28753,25 +29088,25 @@ var init_recovery = __esm({
|
|
|
28753
29088
|
// packages/core/src/store/exodus/archive.ts
|
|
28754
29089
|
import {
|
|
28755
29090
|
copyFileSync as copyFileSync2,
|
|
28756
|
-
existsSync as
|
|
29091
|
+
existsSync as existsSync10,
|
|
28757
29092
|
mkdirSync as mkdirSync2,
|
|
28758
|
-
readFileSync as
|
|
29093
|
+
readFileSync as readFileSync6,
|
|
28759
29094
|
renameSync as renameSync3,
|
|
28760
29095
|
unlinkSync,
|
|
28761
29096
|
writeFileSync as writeFileSync4
|
|
28762
29097
|
} from "node:fs";
|
|
28763
|
-
import { basename as basename7, dirname as
|
|
29098
|
+
import { basename as basename7, dirname as dirname13, join as join17, resolve as resolve7 } from "node:path";
|
|
28764
29099
|
import { z as z26 } from "zod";
|
|
28765
29100
|
function scopeBaseDir(scope, cwd, targetDbPath) {
|
|
28766
|
-
if (targetDbPath !== void 0) return
|
|
29101
|
+
if (targetDbPath !== void 0) return dirname13(targetDbPath);
|
|
28767
29102
|
return scope === "project" ? resolveCleoDir(cwd) : getCleoHome();
|
|
28768
29103
|
}
|
|
28769
29104
|
function exodusArchiveDir(scope, cwd, targetDbPath) {
|
|
28770
|
-
return
|
|
29105
|
+
return join17(scopeBaseDir(scope, cwd, targetDbPath), ARCHIVE_DIR_NAME);
|
|
28771
29106
|
}
|
|
28772
29107
|
function exodusMarkerPath(scope, cwd, targetDbPath) {
|
|
28773
29108
|
const marker16 = targetDbPath !== void 0 && basename7(targetDbPath) !== "cleo.db" ? `${basename7(targetDbPath)}.${MARKER_FILENAME_BY_SCOPE[scope]}` : MARKER_FILENAME_BY_SCOPE[scope];
|
|
28774
|
-
return
|
|
29109
|
+
return join17(scopeBaseDir(scope, cwd, targetDbPath), marker16);
|
|
28775
29110
|
}
|
|
28776
29111
|
function hasExodusCompleteMarker(scope, cwd, targetDbPath, nativeDb) {
|
|
28777
29112
|
let markerPath;
|
|
@@ -28781,13 +29116,13 @@ function hasExodusCompleteMarker(scope, cwd, targetDbPath, nativeDb) {
|
|
|
28781
29116
|
if (targetDbPath) throw error48;
|
|
28782
29117
|
return false;
|
|
28783
29118
|
}
|
|
28784
|
-
if (!
|
|
28785
|
-
const marker16 = markerIdentity.parse(JSON.parse(
|
|
29119
|
+
if (!existsSync10(markerPath)) return false;
|
|
29120
|
+
const marker16 = markerIdentity.parse(JSON.parse(readFileSync6(markerPath, "utf8")));
|
|
28786
29121
|
if (nativeDb && (!marker16.databaseIdentity || !hasExodusDatabaseIdentity(nativeDb, marker16.databaseIdentity)))
|
|
28787
29122
|
throw new Error(
|
|
28788
29123
|
"Exodus completion marker does not certify this database generation; assessment required"
|
|
28789
29124
|
);
|
|
28790
|
-
return marker16.scope === scope && (!targetDbPath || !marker16.targetDbPath ||
|
|
29125
|
+
return marker16.scope === scope && (!targetDbPath || !marker16.targetDbPath || resolve7(marker16.targetDbPath) === resolve7(targetDbPath));
|
|
28791
29126
|
}
|
|
28792
29127
|
function writeExodusCompleteMarker(scope, archivedSources, cwd, targetDbPath, databaseIdentity) {
|
|
28793
29128
|
const markerPath = exodusMarkerPath(scope, cwd, targetDbPath);
|
|
@@ -28799,7 +29134,7 @@ function writeExodusCompleteMarker(scope, archivedSources, cwd, targetDbPath, da
|
|
|
28799
29134
|
cleoVersion: getCleoVersion(),
|
|
28800
29135
|
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
28801
29136
|
archivedSources: [...archivedSources],
|
|
28802
|
-
targetDbPath:
|
|
29137
|
+
targetDbPath: resolve7(targetDbPath ?? join17(baseDir, "cleo.db")),
|
|
28803
29138
|
...databaseIdentity ? { databaseIdentity } : {}
|
|
28804
29139
|
};
|
|
28805
29140
|
const tmpPath = `${markerPath}.tmp`;
|
|
@@ -28810,10 +29145,10 @@ function writeExodusCompleteMarker(scope, archivedSources, cwd, targetDbPath, da
|
|
|
28810
29145
|
}
|
|
28811
29146
|
function moveFileInto(srcPath, destDir) {
|
|
28812
29147
|
mkdirSync2(destDir, { recursive: true });
|
|
28813
|
-
let dest =
|
|
28814
|
-
if (
|
|
29148
|
+
let dest = join17(destDir, basename7(srcPath));
|
|
29149
|
+
if (existsSync10(dest)) {
|
|
28815
29150
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace(/Z$/, "Z");
|
|
28816
|
-
dest =
|
|
29151
|
+
dest = join17(destDir, `${basename7(srcPath)}.${stamp}`);
|
|
28817
29152
|
}
|
|
28818
29153
|
try {
|
|
28819
29154
|
renameSync3(srcPath, dest);
|
|
@@ -28824,14 +29159,14 @@ function moveFileInto(srcPath, destDir) {
|
|
|
28824
29159
|
return dest;
|
|
28825
29160
|
}
|
|
28826
29161
|
function archiveSourceDb(source, cwd, targetDbPath) {
|
|
28827
|
-
if (!
|
|
29162
|
+
if (!existsSync10(source.path)) {
|
|
28828
29163
|
return { name: source.name, sourcePath: source.path, archivedTo: null, action: "absent" };
|
|
28829
29164
|
}
|
|
28830
29165
|
const destDir = exodusArchiveDir(source.targetScope, cwd, targetDbPath);
|
|
28831
29166
|
const archivedTo = moveFileInto(source.path, destDir);
|
|
28832
29167
|
for (const suffix of SIDECAR_SUFFIXES) {
|
|
28833
29168
|
const sidecar = `${source.path}${suffix}`;
|
|
28834
|
-
if (
|
|
29169
|
+
if (existsSync10(sidecar)) {
|
|
28835
29170
|
try {
|
|
28836
29171
|
moveFileInto(sidecar, destDir);
|
|
28837
29172
|
} catch (err) {
|
|
@@ -28879,7 +29214,7 @@ function detectStrandedResidue(sources, cwd) {
|
|
|
28879
29214
|
const stranded = [];
|
|
28880
29215
|
for (const source of sources) {
|
|
28881
29216
|
if (!markedScopes.has(source.targetScope)) continue;
|
|
28882
|
-
if (
|
|
29217
|
+
if (existsSync10(source.path)) {
|
|
28883
29218
|
stranded.push({ name: source.name, path: source.path, scope: source.targetScope });
|
|
28884
29219
|
}
|
|
28885
29220
|
}
|
|
@@ -28944,7 +29279,7 @@ __export(open_cleo_db_exports, {
|
|
|
28944
29279
|
openCleoDbSnapshot: () => openCleoDbSnapshot,
|
|
28945
29280
|
validateProjectIdConsistency: () => validateProjectIdConsistency
|
|
28946
29281
|
});
|
|
28947
|
-
import { createRequire as
|
|
29282
|
+
import { createRequire as createRequire5 } from "node:module";
|
|
28948
29283
|
function unwrapNativeSqliteDb(db) {
|
|
28949
29284
|
if (db && typeof db === "object" && "$client" in db) {
|
|
28950
29285
|
return db.$client ?? db;
|
|
@@ -29008,9 +29343,10 @@ async function openCleoDb(role, cwd) {
|
|
|
29008
29343
|
}
|
|
29009
29344
|
function openCleoDbSnapshot(path, options = {}) {
|
|
29010
29345
|
const { readOnly = true, applyPragmas = true } = options;
|
|
29011
|
-
const _require7 =
|
|
29346
|
+
const _require7 = createRequire5(import.meta.url);
|
|
29012
29347
|
const { DatabaseSync: DatabaseSyncCtor } = _require7("node:sqlite");
|
|
29013
29348
|
const db = new DatabaseSyncCtor(path, { readOnly });
|
|
29349
|
+
if (!readOnly) installSchemaWriteGuard(db);
|
|
29014
29350
|
if (applyPragmas) {
|
|
29015
29351
|
applyPerfPragmas(db, { enableWal: !readOnly });
|
|
29016
29352
|
}
|
|
@@ -29038,6 +29374,7 @@ var init_open_cleo_db = __esm({
|
|
|
29038
29374
|
init_project_info();
|
|
29039
29375
|
init_dual_scope_db();
|
|
29040
29376
|
init_sqlite_pragmas();
|
|
29377
|
+
init_worktree_build_guard();
|
|
29041
29378
|
init_worktree_isolation_guard();
|
|
29042
29379
|
PROJECT_ID_TRACKING_ROLES = /* @__PURE__ */ new Set(["global"]);
|
|
29043
29380
|
}
|
|
@@ -29377,7 +29714,7 @@ var init_table_name_map = __esm({
|
|
|
29377
29714
|
});
|
|
29378
29715
|
|
|
29379
29716
|
// packages/core/src/store/exodus/count-parity.ts
|
|
29380
|
-
import { existsSync as
|
|
29717
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
29381
29718
|
function listTables(db) {
|
|
29382
29719
|
return db.prepare(
|
|
29383
29720
|
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '__drizzle_%' ORDER BY name"
|
|
@@ -29398,14 +29735,14 @@ function rowCount(db, tableName) {
|
|
|
29398
29735
|
function computeCountParity(sources, projectDbPath, globalDbPath) {
|
|
29399
29736
|
const entries = [];
|
|
29400
29737
|
let skipped = 0;
|
|
29401
|
-
if (!
|
|
29738
|
+
if (!existsSync11(projectDbPath) || !existsSync11(globalDbPath)) {
|
|
29402
29739
|
return { ok: false, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
29403
29740
|
}
|
|
29404
29741
|
const projectSnap = openCleoDbSnapshot(projectDbPath, { readOnly: true });
|
|
29405
29742
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
29406
29743
|
try {
|
|
29407
29744
|
for (const src of sources) {
|
|
29408
|
-
if (!
|
|
29745
|
+
if (!existsSync11(src.path)) continue;
|
|
29409
29746
|
const srcSnap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
29410
29747
|
try {
|
|
29411
29748
|
for (const legacyTable of listTables(srcSnap.db)) {
|
|
@@ -29463,8 +29800,8 @@ var init_count_parity = __esm({
|
|
|
29463
29800
|
});
|
|
29464
29801
|
|
|
29465
29802
|
// packages/core/src/store/exodus/plan.ts
|
|
29466
|
-
import { existsSync as
|
|
29467
|
-
import { join as
|
|
29803
|
+
import { existsSync as existsSync12, readdirSync as readdirSync3, statfsSync, statSync as statSync3 } from "node:fs";
|
|
29804
|
+
import { join as join18 } from "node:path";
|
|
29468
29805
|
function computeRequiredBytes(totalSourceBytes, largestSourceBytes) {
|
|
29469
29806
|
return Math.ceil(STAGING_HEADROOM_FACTOR * largestSourceBytes) + totalSourceBytes;
|
|
29470
29807
|
}
|
|
@@ -29475,33 +29812,33 @@ function buildSourceDescriptors(cwd) {
|
|
|
29475
29812
|
// Project-tier — go into consolidated project-scope cleo.db
|
|
29476
29813
|
{
|
|
29477
29814
|
name: "tasks",
|
|
29478
|
-
path:
|
|
29815
|
+
path: join18(cleoDir, "tasks.db"),
|
|
29479
29816
|
targetScope: "project"
|
|
29480
29817
|
},
|
|
29481
29818
|
{
|
|
29482
29819
|
name: "brain (project)",
|
|
29483
|
-
path:
|
|
29820
|
+
path: join18(cleoDir, "brain.db"),
|
|
29484
29821
|
targetScope: "project"
|
|
29485
29822
|
},
|
|
29486
29823
|
{
|
|
29487
29824
|
name: "conduit",
|
|
29488
|
-
path:
|
|
29825
|
+
path: join18(cleoDir, "conduit.db"),
|
|
29489
29826
|
targetScope: "project"
|
|
29490
29827
|
},
|
|
29491
29828
|
// Global-tier — go into consolidated global-scope cleo.db
|
|
29492
29829
|
{
|
|
29493
29830
|
name: "nexus",
|
|
29494
|
-
path:
|
|
29831
|
+
path: join18(cleoHome, "nexus.db"),
|
|
29495
29832
|
targetScope: "global"
|
|
29496
29833
|
},
|
|
29497
29834
|
{
|
|
29498
29835
|
name: "signaldock",
|
|
29499
|
-
path:
|
|
29836
|
+
path: join18(cleoHome, "signaldock.db"),
|
|
29500
29837
|
targetScope: "global"
|
|
29501
29838
|
},
|
|
29502
29839
|
{
|
|
29503
29840
|
name: "skills",
|
|
29504
|
-
path:
|
|
29841
|
+
path: join18(cleoHome, "skills.db"),
|
|
29505
29842
|
targetScope: "global"
|
|
29506
29843
|
}
|
|
29507
29844
|
];
|
|
@@ -29530,7 +29867,7 @@ function findExistingStaging(cleoDir) {
|
|
|
29530
29867
|
const entries = readdirSync3(cleoDir, { withFileTypes: true });
|
|
29531
29868
|
const stagingDirs = entries.filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => e.name).sort().reverse();
|
|
29532
29869
|
if (stagingDirs.length > 0) {
|
|
29533
|
-
return
|
|
29870
|
+
return join18(cleoDir, stagingDirs[0]);
|
|
29534
29871
|
}
|
|
29535
29872
|
} catch {
|
|
29536
29873
|
}
|
|
@@ -29546,7 +29883,7 @@ function buildExodusPlan(cwd) {
|
|
|
29546
29883
|
const availableBytes = getAvailableBytes(cleoDir);
|
|
29547
29884
|
const diskPreflight = totalSourceBytes === 0 || availableBytes >= requiredBytes;
|
|
29548
29885
|
const existingStaging = findExistingStaging(cleoDir);
|
|
29549
|
-
const stagingDir = existingStaging ??
|
|
29886
|
+
const stagingDir = existingStaging ?? join18(cleoDir, deriveStagingDirName());
|
|
29550
29887
|
const resumeFromStaging = existingStaging !== null;
|
|
29551
29888
|
const projectDbPath = resolveDualScopeDbPath("project", cwd);
|
|
29552
29889
|
const globalDbPath = resolveDualScopeDbPath("global");
|
|
@@ -29565,7 +29902,7 @@ function buildExodusPlan(cwd) {
|
|
|
29565
29902
|
};
|
|
29566
29903
|
}
|
|
29567
29904
|
function sourcesPresent(sources) {
|
|
29568
|
-
return sources.some((s) =>
|
|
29905
|
+
return sources.some((s) => existsSync12(s.path));
|
|
29569
29906
|
}
|
|
29570
29907
|
var STAGING_HEADROOM_FACTOR, STAGING_COPY_SKIP_THRESHOLD_BYTES;
|
|
29571
29908
|
var init_plan2 = __esm({
|
|
@@ -29579,18 +29916,18 @@ var init_plan2 = __esm({
|
|
|
29579
29916
|
});
|
|
29580
29917
|
|
|
29581
29918
|
// packages/core/src/store/exodus/health.ts
|
|
29582
|
-
import { existsSync as
|
|
29919
|
+
import { existsSync as existsSync13, statSync as statSync4 } from "node:fs";
|
|
29583
29920
|
function buildExodusHealth(cwd) {
|
|
29584
29921
|
const plan = buildExodusPlan(cwd);
|
|
29585
|
-
const anyLegacyPresent = plan.sources.some((s) =>
|
|
29922
|
+
const anyLegacyPresent = plan.sources.some((s) => existsSync13(s.path));
|
|
29586
29923
|
const parity = anyLegacyPresent ? computeCountParity(plan.sources, plan.projectDbPath, plan.globalDbPath) : { ok: true, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
29587
29924
|
const consolidatedExistsByScope = {
|
|
29588
|
-
project:
|
|
29589
|
-
global:
|
|
29925
|
+
project: existsSync13(plan.projectDbPath),
|
|
29926
|
+
global: existsSync13(plan.globalDbPath)
|
|
29590
29927
|
};
|
|
29591
29928
|
const buildScope = (scope) => {
|
|
29592
29929
|
const sources = plan.sources.filter((s) => s.targetScope === scope).map((s) => {
|
|
29593
|
-
const present =
|
|
29930
|
+
const present = existsSync13(s.path);
|
|
29594
29931
|
let bytes = 0;
|
|
29595
29932
|
if (present) {
|
|
29596
29933
|
try {
|
|
@@ -29942,8 +30279,8 @@ var init_types = __esm({
|
|
|
29942
30279
|
});
|
|
29943
30280
|
|
|
29944
30281
|
// packages/core/src/store/backup-sidecar.ts
|
|
29945
|
-
import { existsSync as
|
|
29946
|
-
import { join as
|
|
30282
|
+
import { existsSync as existsSync14, readdirSync as readdirSync4, renameSync as renameSync4, statSync as statSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30283
|
+
import { join as join19 } from "node:path";
|
|
29947
30284
|
function formatBackupTimestamp(d) {
|
|
29948
30285
|
const pad = (n, len = 2) => String(n).padStart(len, "0");
|
|
29949
30286
|
return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
|
|
@@ -29954,8 +30291,8 @@ function rotateBackupDir(backupDir, maxSnapshots, backupType) {
|
|
|
29954
30291
|
const ownedPattern = new RegExp(`\\.${escapedType}-`);
|
|
29955
30292
|
const files = readdirSync4(backupDir).filter((f) => !f.endsWith(".meta.json") && !f.endsWith(".tmp") && ownedPattern.test(f)).map((f) => ({
|
|
29956
30293
|
name: f,
|
|
29957
|
-
path:
|
|
29958
|
-
mtimeMs: statSync5(
|
|
30294
|
+
path: join19(backupDir, f),
|
|
30295
|
+
mtimeMs: statSync5(join19(backupDir, f)).mtimeMs
|
|
29959
30296
|
})).sort((a, b) => a.mtimeMs - b.mtimeMs);
|
|
29960
30297
|
while (files.length > maxSnapshots) {
|
|
29961
30298
|
const oldest = files.shift();
|
|
@@ -29963,7 +30300,7 @@ function rotateBackupDir(backupDir, maxSnapshots, backupType) {
|
|
|
29963
30300
|
try {
|
|
29964
30301
|
unlinkSync2(oldest.path);
|
|
29965
30302
|
const metaPath = `${oldest.path}.meta.json`;
|
|
29966
|
-
if (
|
|
30303
|
+
if (existsSync14(metaPath)) unlinkSync2(metaPath);
|
|
29967
30304
|
} catch {
|
|
29968
30305
|
}
|
|
29969
30306
|
}
|
|
@@ -29971,7 +30308,7 @@ function rotateBackupDir(backupDir, maxSnapshots, backupType) {
|
|
|
29971
30308
|
}
|
|
29972
30309
|
}
|
|
29973
30310
|
function writeBackupSidecar(backupDir, sidecar) {
|
|
29974
|
-
const dest =
|
|
30311
|
+
const dest = join19(backupDir, `${sidecar.backupId}.meta.json`);
|
|
29975
30312
|
const tmp = `${dest}.${process.pid}.${Date.now()}.tmp`;
|
|
29976
30313
|
writeFileSync5(tmp, JSON.stringify(sidecar, null, 2));
|
|
29977
30314
|
renameSync4(tmp, dest);
|
|
@@ -29983,23 +30320,23 @@ var init_backup_sidecar = __esm({
|
|
|
29983
30320
|
});
|
|
29984
30321
|
|
|
29985
30322
|
// packages/core/src/store/pre-repair-snapshot.ts
|
|
29986
|
-
import { existsSync as
|
|
29987
|
-
import { dirname as
|
|
30323
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync3, statfsSync as statfsSync2 } from "node:fs";
|
|
30324
|
+
import { dirname as dirname14, join as join20 } from "node:path";
|
|
29988
30325
|
function writePreRepairSnapshot(nativeDb, dbPath, label) {
|
|
29989
30326
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
29990
|
-
const backupDir =
|
|
30327
|
+
const backupDir = join20(dirname14(dbPath), "backups");
|
|
29991
30328
|
mkdirSync3(backupDir, { recursive: true });
|
|
29992
|
-
const snapshotPath =
|
|
30329
|
+
const snapshotPath = join20(backupDir, `cleo-pre-${label}-${stamp}.db`);
|
|
29993
30330
|
nativeDb.exec(`VACUUM INTO '${snapshotPath.replace(/'/g, "''")}'`);
|
|
29994
30331
|
return snapshotPath;
|
|
29995
30332
|
}
|
|
29996
30333
|
function existingAncestor(path) {
|
|
29997
30334
|
let p = path;
|
|
29998
|
-
while (!
|
|
30335
|
+
while (!existsSync15(p) && dirname14(p) !== p) p = dirname14(p);
|
|
29999
30336
|
return p;
|
|
30000
30337
|
}
|
|
30001
30338
|
function planMigrationSnapshot(nativeDb, dbPath) {
|
|
30002
|
-
const backupDir =
|
|
30339
|
+
const backupDir = join20(dirname14(dbPath), "backups", "sqlite");
|
|
30003
30340
|
const pragma = (name15) => Number(nativeDb.prepare(`PRAGMA main.${name15}`).get()[name15] ?? 0);
|
|
30004
30341
|
const liveBytes = (pragma("page_count") - pragma("freelist_count")) * pragma("page_size");
|
|
30005
30342
|
let availableBytes = null;
|
|
@@ -30011,13 +30348,13 @@ function planMigrationSnapshot(nativeDb, dbPath) {
|
|
|
30011
30348
|
}
|
|
30012
30349
|
const base = `migration-${formatBackupTimestamp(/* @__PURE__ */ new Date())}`;
|
|
30013
30350
|
let backupId = base;
|
|
30014
|
-
for (let n = 2;
|
|
30351
|
+
for (let n = 2; existsSync15(join20(backupDir, `${backupId}.meta.json`)); n++) {
|
|
30015
30352
|
backupId = `${base}-${n}`;
|
|
30016
30353
|
}
|
|
30017
30354
|
return {
|
|
30018
30355
|
backupDir,
|
|
30019
30356
|
backupId,
|
|
30020
|
-
snapshotPath:
|
|
30357
|
+
snapshotPath: join20(backupDir, `cleo.db.${backupId}`),
|
|
30021
30358
|
requiredBytes: liveBytes + SNAPSHOT_HEADROOM_BYTES,
|
|
30022
30359
|
availableBytes
|
|
30023
30360
|
};
|
|
@@ -30257,7 +30594,7 @@ var init_legacy_tasks_lineage = __esm({
|
|
|
30257
30594
|
|
|
30258
30595
|
// packages/core/src/store/ports/domain-binding.ts
|
|
30259
30596
|
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
30260
|
-
import { resolve as
|
|
30597
|
+
import { resolve as resolve8 } from "node:path";
|
|
30261
30598
|
function getCleoRuntime() {
|
|
30262
30599
|
if (!_runtime) {
|
|
30263
30600
|
_runtime = createCleoRuntime();
|
|
@@ -30325,6 +30662,8 @@ async function bindAgainst(key, store, establish) {
|
|
|
30325
30662
|
() => establish(native, store)
|
|
30326
30663
|
);
|
|
30327
30664
|
return { store, native, db };
|
|
30665
|
+
} catch (error48) {
|
|
30666
|
+
throw explainSchemaWriteDenial(native, error48);
|
|
30328
30667
|
} finally {
|
|
30329
30668
|
membership.active = false;
|
|
30330
30669
|
}
|
|
@@ -30374,7 +30713,7 @@ async function bindLive(scope, key, dbPath, openStore, establish) {
|
|
|
30374
30713
|
);
|
|
30375
30714
|
}
|
|
30376
30715
|
async function bindProjectDomain(domain2, cwd, establish) {
|
|
30377
|
-
const dbPath =
|
|
30716
|
+
const dbPath = resolve8(resolveDualScopeDbPath("project", cwd));
|
|
30378
30717
|
const row = await bindLive(
|
|
30379
30718
|
"project",
|
|
30380
30719
|
bindingKey("project", dbPath, domain2),
|
|
@@ -30385,7 +30724,7 @@ async function bindProjectDomain(domain2, cwd, establish) {
|
|
|
30385
30724
|
return row;
|
|
30386
30725
|
}
|
|
30387
30726
|
async function bindGlobalDomain(domain2, establish, cwd) {
|
|
30388
|
-
const dbPath =
|
|
30727
|
+
const dbPath = resolve8(resolveDualScopeDbPath("global"));
|
|
30389
30728
|
const row = await bindLive(
|
|
30390
30729
|
"global",
|
|
30391
30730
|
bindingKey("global", dbPath, domain2),
|
|
@@ -30396,7 +30735,7 @@ async function bindGlobalDomain(domain2, establish, cwd) {
|
|
|
30396
30735
|
return row;
|
|
30397
30736
|
}
|
|
30398
30737
|
async function bindGlobalDomainAtPath(domain2, dbPath, establish) {
|
|
30399
|
-
const normalized =
|
|
30738
|
+
const normalized = resolve8(dbPath);
|
|
30400
30739
|
const row = await bindLive(
|
|
30401
30740
|
"global",
|
|
30402
30741
|
bindingKey("global", normalized, domain2),
|
|
@@ -30407,7 +30746,7 @@ async function bindGlobalDomainAtPath(domain2, dbPath, establish) {
|
|
|
30407
30746
|
return row;
|
|
30408
30747
|
}
|
|
30409
30748
|
function peekDomainAtPath(scope, dbPath, domain2) {
|
|
30410
|
-
const row = _bindings.get(bindingKey(scope,
|
|
30749
|
+
const row = _bindings.get(bindingKey(scope, resolve8(dbPath), domain2));
|
|
30411
30750
|
if (!row?.native.isOpen) return null;
|
|
30412
30751
|
return row;
|
|
30413
30752
|
}
|
|
@@ -30416,12 +30755,12 @@ function releaseDomainBindings(filter2) {
|
|
|
30416
30755
|
_bindings.clear();
|
|
30417
30756
|
return;
|
|
30418
30757
|
}
|
|
30419
|
-
const wantPath = filter2.dbPath === void 0 ? void 0 :
|
|
30758
|
+
const wantPath = filter2.dbPath === void 0 ? void 0 : resolve8(filter2.dbPath);
|
|
30420
30759
|
for (const key of [..._bindings.keys()]) {
|
|
30421
|
-
const
|
|
30760
|
+
const sep6 = key.indexOf("::");
|
|
30422
30761
|
const lastSep = key.lastIndexOf("::");
|
|
30423
|
-
const scope = key.slice(0,
|
|
30424
|
-
const dbPath = key.slice(
|
|
30762
|
+
const scope = key.slice(0, sep6);
|
|
30763
|
+
const dbPath = key.slice(sep6 + 2, lastSep);
|
|
30425
30764
|
const domain2 = key.slice(lastSep + 2);
|
|
30426
30765
|
if (filter2.scope !== void 0 && scope !== filter2.scope) continue;
|
|
30427
30766
|
if (wantPath !== void 0 && dbPath !== wantPath) continue;
|
|
@@ -30436,7 +30775,7 @@ function boundProjectNative(domain2, cwd) {
|
|
|
30436
30775
|
return peekProjectDomain(domain2, cwd)?.native ?? null;
|
|
30437
30776
|
}
|
|
30438
30777
|
function peekProjectDomain(domain2, cwd) {
|
|
30439
|
-
const dbPath =
|
|
30778
|
+
const dbPath = resolve8(resolveDualScopeDbPath("project", cwd));
|
|
30440
30779
|
const row = _bindings.get(bindingKey("project", dbPath, domain2));
|
|
30441
30780
|
if (row?.native.isOpen) return row;
|
|
30442
30781
|
if (cwd !== void 0) return null;
|
|
@@ -30451,7 +30790,7 @@ function peekProjectDomain(domain2, cwd) {
|
|
|
30451
30790
|
return sole ?? null;
|
|
30452
30791
|
}
|
|
30453
30792
|
function peekGlobalDomain(domain2) {
|
|
30454
|
-
const dbPath =
|
|
30793
|
+
const dbPath = resolve8(resolveDualScopeDbPath("global"));
|
|
30455
30794
|
const row = _bindings.get(bindingKey("global", dbPath, domain2));
|
|
30456
30795
|
if (!row || !row.native.isOpen) return null;
|
|
30457
30796
|
return row;
|
|
@@ -30462,6 +30801,7 @@ var init_domain_binding = __esm({
|
|
|
30462
30801
|
"use strict";
|
|
30463
30802
|
init_project_scope();
|
|
30464
30803
|
init_dual_scope_db();
|
|
30804
|
+
init_worktree_build_guard();
|
|
30465
30805
|
_runtime = null;
|
|
30466
30806
|
_bindings = /* @__PURE__ */ new Map();
|
|
30467
30807
|
_inflight = /* @__PURE__ */ new Map();
|
|
@@ -30472,9 +30812,9 @@ var init_domain_binding = __esm({
|
|
|
30472
30812
|
|
|
30473
30813
|
// packages/core/src/telemetry/sqlite.ts
|
|
30474
30814
|
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
30475
|
-
import { dirname as
|
|
30815
|
+
import { dirname as dirname15, join as join21 } from "node:path";
|
|
30476
30816
|
function getTelemetryDbPath() {
|
|
30477
|
-
return
|
|
30817
|
+
return join21(getCleoHome(), DB_FILENAME);
|
|
30478
30818
|
}
|
|
30479
30819
|
function resolveTelemetryMigrationsFolder() {
|
|
30480
30820
|
return resolveCorePackageMigrationsFolder("drizzle-telemetry");
|
|
@@ -30522,8 +30862,9 @@ async function getTelemetryDb() {
|
|
|
30522
30862
|
_initPromise = (async () => {
|
|
30523
30863
|
const dbPath = requestedPath;
|
|
30524
30864
|
_dbPath = dbPath;
|
|
30525
|
-
mkdirSync4(
|
|
30865
|
+
mkdirSync4(dirname15(dbPath), { recursive: true });
|
|
30526
30866
|
const nativeDb = openNativeDatabase(dbPath);
|
|
30867
|
+
installSchemaWriteGuard(nativeDb);
|
|
30527
30868
|
_nativeDb = nativeDb;
|
|
30528
30869
|
const db = drizzle({ client: nativeDb });
|
|
30529
30870
|
runTelemetryMigrations(nativeDb, db);
|
|
@@ -30544,6 +30885,7 @@ var init_sqlite2 = __esm({
|
|
|
30544
30885
|
init_migration_manager();
|
|
30545
30886
|
init_resolve_migrations_folder();
|
|
30546
30887
|
init_sqlite3();
|
|
30888
|
+
init_worktree_build_guard();
|
|
30547
30889
|
DB_FILENAME = "telemetry.db";
|
|
30548
30890
|
TELEMETRY_SCHEMA_VERSION = "1.0.0";
|
|
30549
30891
|
_db = null;
|
|
@@ -30554,11 +30896,11 @@ var init_sqlite2 = __esm({
|
|
|
30554
30896
|
});
|
|
30555
30897
|
|
|
30556
30898
|
// packages/core/src/store/agent-registry-store.ts
|
|
30557
|
-
import { existsSync as
|
|
30558
|
-
import { join as
|
|
30899
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
30900
|
+
import { join as join22 } from "node:path";
|
|
30559
30901
|
function getGlobalAgentRegistryDbPath() {
|
|
30560
30902
|
const cleoHome = getCleoHome();
|
|
30561
|
-
const dbPath =
|
|
30903
|
+
const dbPath = join22(cleoHome, "cleo.db");
|
|
30562
30904
|
if (!dbPath.startsWith(cleoHome)) {
|
|
30563
30905
|
throw new Error(
|
|
30564
30906
|
`BUG: getGlobalAgentRegistryDbPath() resolved to "${dbPath}" which is NOT under getCleoHome() ("${cleoHome}"). The Agent Registry is global-only per ADR-037. This indicates a code path that bypasses path resolution \u2014 fix the caller, do not suppress this error.`
|
|
@@ -30625,7 +30967,7 @@ function establishAgentRegistrySchema(native) {
|
|
|
30625
30967
|
}
|
|
30626
30968
|
async function ensureGlobalAgentRegistryDb() {
|
|
30627
30969
|
const dbPath = getGlobalAgentRegistryDbPath();
|
|
30628
|
-
const alreadyExists =
|
|
30970
|
+
const alreadyExists = existsSync16(dbPath);
|
|
30629
30971
|
let created = false;
|
|
30630
30972
|
const { native: nativeDb } = await bindGlobalDomainAtPath(
|
|
30631
30973
|
AGENT_REGISTRY_DOMAIN,
|
|
@@ -30670,8 +31012,8 @@ var init_agent_registry_store = __esm({
|
|
|
30670
31012
|
});
|
|
30671
31013
|
|
|
30672
31014
|
// packages/core/src/store/conduit-sqlite.ts
|
|
30673
|
-
import { existsSync as
|
|
30674
|
-
import { createRequire as
|
|
31015
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
31016
|
+
import { createRequire as createRequire6 } from "node:module";
|
|
30675
31017
|
function _getDrizzle() {
|
|
30676
31018
|
if (_drizzle === null) {
|
|
30677
31019
|
const mod = _require3("drizzle-orm/node-sqlite");
|
|
@@ -30699,7 +31041,7 @@ function runConduitMigrations(nativeDb) {
|
|
|
30699
31041
|
}
|
|
30700
31042
|
async function ensureConduitDb(projectRoot) {
|
|
30701
31043
|
const dbPath = getConduitDbPath(projectRoot);
|
|
30702
|
-
const alreadyExists = peekProjectDomain("conduit", projectRoot) !== null ||
|
|
31044
|
+
const alreadyExists = peekProjectDomain("conduit", projectRoot) !== null || existsSync17(dbPath);
|
|
30703
31045
|
await bindConduitDomain(projectRoot);
|
|
30704
31046
|
return { action: alreadyExists ? "exists" : "created", path: dbPath };
|
|
30705
31047
|
}
|
|
@@ -30725,7 +31067,8 @@ var init_conduit_sqlite = __esm({
|
|
|
30725
31067
|
init_domain_binding();
|
|
30726
31068
|
init_resolve_migrations_folder();
|
|
30727
31069
|
init_sqlite_pragmas();
|
|
30728
|
-
|
|
31070
|
+
init_worktree_build_guard();
|
|
31071
|
+
_require3 = createRequire6(import.meta.url);
|
|
30729
31072
|
({ DatabaseSync: DatabaseSync2 } = _require3("node:sqlite"));
|
|
30730
31073
|
_drizzle = null;
|
|
30731
31074
|
CONDUIT_SCHEMA_VERSION = "2026.4.23";
|
|
@@ -33197,7 +33540,7 @@ __export(config_exports, {
|
|
|
33197
33540
|
parseConfigValue: () => parseConfigValue,
|
|
33198
33541
|
setConfigValue: () => setConfigValue
|
|
33199
33542
|
});
|
|
33200
|
-
import { existsSync as
|
|
33543
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
33201
33544
|
function getNestedValue(obj, path) {
|
|
33202
33545
|
const parts = path.split(".");
|
|
33203
33546
|
let current = obj;
|
|
@@ -33319,7 +33662,7 @@ function parseConfigValue(value) {
|
|
|
33319
33662
|
}
|
|
33320
33663
|
async function setConfigValue(key, value, cwd, opts) {
|
|
33321
33664
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
33322
|
-
if (!
|
|
33665
|
+
if (!existsSync18(configPath)) {
|
|
33323
33666
|
await atomicWriteJson(configPath, {});
|
|
33324
33667
|
}
|
|
33325
33668
|
const config2 = await readJson(configPath) ?? {};
|
|
@@ -33331,7 +33674,7 @@ async function setConfigValue(key, value, cwd, opts) {
|
|
|
33331
33674
|
async function applyStrictnessPreset(preset, cwd, opts) {
|
|
33332
33675
|
const definition = STRICTNESS_PRESETS[preset];
|
|
33333
33676
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
33334
|
-
if (!
|
|
33677
|
+
if (!existsSync18(configPath)) {
|
|
33335
33678
|
await atomicWriteJson(configPath, {});
|
|
33336
33679
|
}
|
|
33337
33680
|
const config2 = await readJson(configPath) ?? {};
|
|
@@ -33908,6 +34251,7 @@ var init_cross_db_cleanup = __esm({
|
|
|
33908
34251
|
"use strict";
|
|
33909
34252
|
init_memory_sqlite();
|
|
33910
34253
|
init_memory_schema();
|
|
34254
|
+
init_worktree_build_guard();
|
|
33911
34255
|
}
|
|
33912
34256
|
});
|
|
33913
34257
|
|
|
@@ -38600,7 +38944,7 @@ __export(sqlite_data_accessor_exports, {
|
|
|
38600
38944
|
setMetaValue: () => setMetaValue
|
|
38601
38945
|
});
|
|
38602
38946
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
38603
|
-
import { resolve as
|
|
38947
|
+
import { resolve as resolve9 } from "node:path";
|
|
38604
38948
|
import {
|
|
38605
38949
|
and as and5,
|
|
38606
38950
|
eq as eq6,
|
|
@@ -38709,7 +39053,7 @@ function bindTaskAccessorScope(accessor, scope) {
|
|
|
38709
39053
|
}
|
|
38710
39054
|
async function createSqliteDataAccessor(cwd) {
|
|
38711
39055
|
const scope = captureProjectScope(
|
|
38712
|
-
|
|
39056
|
+
resolve9(cwd ?? getProjectRoot()),
|
|
38713
39057
|
worktreeScope.getStore()
|
|
38714
39058
|
);
|
|
38715
39059
|
return worktreeScope.run(
|
|
@@ -38824,7 +39168,9 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38824
39168
|
actor: entry.actor ?? "system",
|
|
38825
39169
|
detailsJson: entry.details ? JSON.stringify(entry.details) : "{}",
|
|
38826
39170
|
beforeJson: entry.before ? JSON.stringify(entry.before) : null,
|
|
38827
|
-
afterJson: entry.after ? JSON.stringify(entry.after) : null
|
|
39171
|
+
afterJson: entry.after ? JSON.stringify(entry.after) : null,
|
|
39172
|
+
// T12693: the session a ranking change ran in.
|
|
39173
|
+
sessionId: typeof entry.sessionId === "string" ? entry.sessionId : null
|
|
38828
39174
|
}).run()
|
|
38829
39175
|
);
|
|
38830
39176
|
});
|
|
@@ -38832,6 +39178,9 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38832
39178
|
async queryAuditLog(query) {
|
|
38833
39179
|
const db = await getDb(cwd);
|
|
38834
39180
|
const conditions = [];
|
|
39181
|
+
if (query.ids && query.ids.length > 0) {
|
|
39182
|
+
conditions.push(inArray4(tasksAuditLog.id, [...query.ids]));
|
|
39183
|
+
}
|
|
38835
39184
|
if (query.taskIds && query.taskIds.length > 0) {
|
|
38836
39185
|
conditions.push(inArray4(tasksAuditLog.taskId, [...query.taskIds]));
|
|
38837
39186
|
}
|
|
@@ -38850,7 +39199,8 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38850
39199
|
actor: tasksAuditLog.actor,
|
|
38851
39200
|
detailsJson: tasksAuditLog.detailsJson,
|
|
38852
39201
|
beforeJson: tasksAuditLog.beforeJson,
|
|
38853
|
-
afterJson: tasksAuditLog.afterJson
|
|
39202
|
+
afterJson: tasksAuditLog.afterJson,
|
|
39203
|
+
sessionId: tasksAuditLog.sessionId
|
|
38854
39204
|
}).from(tasksAuditLog).where(conditions.length > 0 ? and5(...conditions) : void 0).orderBy(sql26`${tasksAuditLog.timestamp} DESC`).limit(limit).all();
|
|
38855
39205
|
return rows.map((row) => ({
|
|
38856
39206
|
id: row.id,
|
|
@@ -38860,7 +39210,8 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38860
39210
|
actor: row.actor,
|
|
38861
39211
|
detailsJson: row.detailsJson ?? null,
|
|
38862
39212
|
beforeJson: row.beforeJson ?? null,
|
|
38863
|
-
afterJson: row.afterJson ?? null
|
|
39213
|
+
afterJson: row.afterJson ?? null,
|
|
39214
|
+
sessionId: row.sessionId ?? null
|
|
38864
39215
|
}));
|
|
38865
39216
|
},
|
|
38866
39217
|
// ---- Fine-grained task operations (T5034) ----
|
|
@@ -39698,13 +40049,13 @@ var init_sqlite_data_accessor = __esm({
|
|
|
39698
40049
|
});
|
|
39699
40050
|
|
|
39700
40051
|
// packages/core/src/sequence/index.ts
|
|
39701
|
-
import { existsSync as
|
|
39702
|
-
import { join as
|
|
40052
|
+
import { existsSync as existsSync19, readFileSync as readFileSync7, renameSync as renameSync5 } from "node:fs";
|
|
40053
|
+
import { join as join23 } from "node:path";
|
|
39703
40054
|
function getLegacySequenceJsonPath(cwd) {
|
|
39704
|
-
return
|
|
40055
|
+
return join23(resolveOrCwd(cwd), ".cleo", ".sequence.json");
|
|
39705
40056
|
}
|
|
39706
40057
|
function getLegacySequencePath(cwd) {
|
|
39707
|
-
return
|
|
40058
|
+
return join23(resolveOrCwd(cwd), ".cleo", ".sequence");
|
|
39708
40059
|
}
|
|
39709
40060
|
function isValidSequenceState(value) {
|
|
39710
40061
|
if (!value || typeof value !== "object") return false;
|
|
@@ -39715,19 +40066,19 @@ function isSeedSequence(value) {
|
|
|
39715
40066
|
return value.counter === 0 && value.lastId === "T000" && value.checksum === "seed";
|
|
39716
40067
|
}
|
|
39717
40068
|
function readLegacySequenceFile(path) {
|
|
39718
|
-
if (!
|
|
40069
|
+
if (!existsSync19(path)) return null;
|
|
39719
40070
|
try {
|
|
39720
|
-
const parsed = JSON.parse(
|
|
40071
|
+
const parsed = JSON.parse(readFileSync7(path, "utf-8"));
|
|
39721
40072
|
return isValidSequenceState(parsed) ? parsed : null;
|
|
39722
40073
|
} catch {
|
|
39723
40074
|
return null;
|
|
39724
40075
|
}
|
|
39725
40076
|
}
|
|
39726
40077
|
function renameLegacyFile(path) {
|
|
39727
|
-
if (!
|
|
40078
|
+
if (!existsSync19(path)) return;
|
|
39728
40079
|
const migratedPath = `${path}.migrated`;
|
|
39729
40080
|
try {
|
|
39730
|
-
if (!
|
|
40081
|
+
if (!existsSync19(migratedPath)) {
|
|
39731
40082
|
renameSync5(path, migratedPath);
|
|
39732
40083
|
return;
|
|
39733
40084
|
}
|
|
@@ -39879,9 +40230,9 @@ var init_sequence = __esm({
|
|
|
39879
40230
|
});
|
|
39880
40231
|
|
|
39881
40232
|
// packages/core/src/store/checkpoint-git-dir.ts
|
|
39882
|
-
import { join as
|
|
40233
|
+
import { join as join24 } from "node:path";
|
|
39883
40234
|
function checkpointGitDir(cleoDir) {
|
|
39884
|
-
return
|
|
40235
|
+
return join24(cleoDir, CHECKPOINT_GIT_DIRNAME);
|
|
39885
40236
|
}
|
|
39886
40237
|
var CHECKPOINT_GIT_DIRNAME;
|
|
39887
40238
|
var init_checkpoint_git_dir = __esm({
|
|
@@ -39893,12 +40244,12 @@ var init_checkpoint_git_dir = __esm({
|
|
|
39893
40244
|
|
|
39894
40245
|
// packages/core/src/store/git-checkpoint.ts
|
|
39895
40246
|
import { execFile as execFile2 } from "node:child_process";
|
|
39896
|
-
import { existsSync as
|
|
40247
|
+
import { existsSync as existsSync20 } from "node:fs";
|
|
39897
40248
|
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
39898
|
-
import { join as
|
|
40249
|
+
import { join as join25, resolve as resolve10 } from "node:path";
|
|
39899
40250
|
import { promisify as promisify2 } from "node:util";
|
|
39900
40251
|
function makeCleoGitEnv(cleoDir) {
|
|
39901
|
-
const abs =
|
|
40252
|
+
const abs = resolve10(cleoDir);
|
|
39902
40253
|
return {
|
|
39903
40254
|
...process.env,
|
|
39904
40255
|
GIT_DIR: checkpointGitDir(abs),
|
|
@@ -39908,7 +40259,7 @@ function makeCleoGitEnv(cleoDir) {
|
|
|
39908
40259
|
async function cleoGitCommand(args, cleoDir) {
|
|
39909
40260
|
try {
|
|
39910
40261
|
const result = await execFileAsync2("git", args, {
|
|
39911
|
-
cwd:
|
|
40262
|
+
cwd: resolve10(cleoDir),
|
|
39912
40263
|
// absolute cwd so relative paths in args resolve correctly
|
|
39913
40264
|
env: makeCleoGitEnv(cleoDir),
|
|
39914
40265
|
timeout: 1e4
|
|
@@ -39919,7 +40270,7 @@ async function cleoGitCommand(args, cleoDir) {
|
|
|
39919
40270
|
}
|
|
39920
40271
|
}
|
|
39921
40272
|
function isCleoGitInitialized(cleoDir) {
|
|
39922
|
-
return
|
|
40273
|
+
return existsSync20(join25(checkpointGitDir(cleoDir), "HEAD"));
|
|
39923
40274
|
}
|
|
39924
40275
|
async function loadStateFileAllowlist(cwd) {
|
|
39925
40276
|
try {
|
|
@@ -39963,25 +40314,25 @@ async function isCleoGitRepo(cleoDir) {
|
|
|
39963
40314
|
return result.success && (result.stdout === "true" || isCleoGitInitialized(cleoDir));
|
|
39964
40315
|
}
|
|
39965
40316
|
function isMergeInProgress(cleoDir) {
|
|
39966
|
-
return
|
|
40317
|
+
return existsSync20(join25(checkpointGitDir(cleoDir), "MERGE_HEAD"));
|
|
39967
40318
|
}
|
|
39968
40319
|
async function isDetachedHead(cleoDir) {
|
|
39969
40320
|
const result = await cleoGitCommand(["symbolic-ref", "HEAD"], cleoDir);
|
|
39970
40321
|
return !result.success;
|
|
39971
40322
|
}
|
|
39972
40323
|
function isRebaseInProgress(cleoDir) {
|
|
39973
|
-
return
|
|
40324
|
+
return existsSync20(join25(checkpointGitDir(cleoDir), "rebase-merge")) || existsSync20(join25(checkpointGitDir(cleoDir), "rebase-apply"));
|
|
39974
40325
|
}
|
|
39975
40326
|
async function recordCheckpointTime(cleoDir) {
|
|
39976
40327
|
try {
|
|
39977
|
-
const stateFile =
|
|
40328
|
+
const stateFile = join25(cleoDir, CHECKPOINT_STATE_FILE);
|
|
39978
40329
|
await writeFile(stateFile, String(Math.floor(Date.now() / 1e3)));
|
|
39979
40330
|
} catch {
|
|
39980
40331
|
}
|
|
39981
40332
|
}
|
|
39982
40333
|
async function getLastCheckpointTime(cleoDir) {
|
|
39983
40334
|
try {
|
|
39984
|
-
const stateFile =
|
|
40335
|
+
const stateFile = join25(cleoDir, CHECKPOINT_STATE_FILE);
|
|
39985
40336
|
const content = await readFile4(stateFile, "utf-8");
|
|
39986
40337
|
const epoch = parseInt(content.trim(), 10);
|
|
39987
40338
|
return Number.isNaN(epoch) ? 0 : epoch;
|
|
@@ -39993,8 +40344,8 @@ async function getChangedStateFiles(cleoDir, cwd) {
|
|
|
39993
40344
|
const changed = [];
|
|
39994
40345
|
const allStateFiles = await getAllStateFiles(cwd);
|
|
39995
40346
|
for (const stateFile of allStateFiles) {
|
|
39996
|
-
const fullPath =
|
|
39997
|
-
if (!
|
|
40347
|
+
const fullPath = join25(cleoDir, stateFile);
|
|
40348
|
+
if (!existsSync20(fullPath)) continue;
|
|
39998
40349
|
const diffResult = await cleoGitCommand(["diff", "--quiet", "--", stateFile], cleoDir);
|
|
39999
40350
|
const cachedResult = await cleoGitCommand(
|
|
40000
40351
|
["diff", "--cached", "--quiet", "--", stateFile],
|
|
@@ -40021,7 +40372,7 @@ async function shouldCheckpoint(options) {
|
|
|
40021
40372
|
const config2 = await loadCheckpointConfig(cwd);
|
|
40022
40373
|
if (!config2.enabled) return false;
|
|
40023
40374
|
const cleoDir = getCleoDir(cwd);
|
|
40024
|
-
if (!
|
|
40375
|
+
if (!existsSync20(cleoDir)) return false;
|
|
40025
40376
|
if (!isCleoGitInitialized(cleoDir)) return false;
|
|
40026
40377
|
if (!await isCleoGitRepo(cleoDir)) return false;
|
|
40027
40378
|
if (isMergeInProgress(cleoDir)) return false;
|
|
@@ -40095,7 +40446,7 @@ var init_git_checkpoint = __esm({
|
|
|
40095
40446
|
});
|
|
40096
40447
|
|
|
40097
40448
|
// packages/core/src/store/snapshot-gate.ts
|
|
40098
|
-
import { join as
|
|
40449
|
+
import { join as join26 } from "node:path";
|
|
40099
40450
|
function readGateState(db) {
|
|
40100
40451
|
const row = db.prepare("SELECT value FROM tasks_schema_meta WHERE key = ?").get(SNAPSHOT_GATE_META_KEY);
|
|
40101
40452
|
const state = { generation: 0, prefixes: {} };
|
|
@@ -40160,7 +40511,7 @@ async function runGatedSnapshot(opts, snapshot) {
|
|
|
40160
40511
|
return none("debounced");
|
|
40161
40512
|
}
|
|
40162
40513
|
}
|
|
40163
|
-
const lockPath2 =
|
|
40514
|
+
const lockPath2 = join26(opts.backupDir, GATE_LOCK_BASENAME);
|
|
40164
40515
|
let release;
|
|
40165
40516
|
try {
|
|
40166
40517
|
release = await acquireLock(lockPath2, {
|
|
@@ -40716,7 +41067,7 @@ __export(data_accessor_exports, {
|
|
|
40716
41067
|
getAccessorDb: () => getAccessorDb,
|
|
40717
41068
|
getTaskAccessor: () => getTaskAccessor
|
|
40718
41069
|
});
|
|
40719
|
-
import { resolve as
|
|
41070
|
+
import { resolve as resolve11 } from "node:path";
|
|
40720
41071
|
function assertTestEnv(dbPath) {
|
|
40721
41072
|
const testMode = process.env["CLEO_TEST_MODE"];
|
|
40722
41073
|
if (testMode !== "1") return;
|
|
@@ -40737,7 +41088,7 @@ function assertTestEnv(dbPath) {
|
|
|
40737
41088
|
}
|
|
40738
41089
|
}
|
|
40739
41090
|
async function createDataAccessor(cwd) {
|
|
40740
|
-
const root =
|
|
41091
|
+
const root = resolve11(cwd ?? getProjectRoot());
|
|
40741
41092
|
const inherited = worktreeScope.getStore();
|
|
40742
41093
|
const captured = inherited ? { ...inherited } : void 0;
|
|
40743
41094
|
captured?.execution?.assertActive();
|
|
@@ -40781,7 +41132,7 @@ __export(memory_sqlite_exports, {
|
|
|
40781
41132
|
resetBrainDbState: () => resetBrainDbState,
|
|
40782
41133
|
resolveBrainMigrationsFolder: () => resolveBrainMigrationsFolder
|
|
40783
41134
|
});
|
|
40784
|
-
import { createRequire as
|
|
41135
|
+
import { createRequire as createRequire7 } from "node:module";
|
|
40785
41136
|
function _getDrizzle2() {
|
|
40786
41137
|
if (_drizzle2 === null) {
|
|
40787
41138
|
const mod = _require4("drizzle-orm/node-sqlite");
|
|
@@ -40918,7 +41269,7 @@ var init_memory_sqlite = __esm({
|
|
|
40918
41269
|
init_resolve_migrations_folder();
|
|
40919
41270
|
init_memory_schema();
|
|
40920
41271
|
init_twin_collapse();
|
|
40921
|
-
_require4 =
|
|
41272
|
+
_require4 = createRequire7(import.meta.url);
|
|
40922
41273
|
_drizzle2 = null;
|
|
40923
41274
|
BRAIN_SCHEMA_VERSION = "1.0.0";
|
|
40924
41275
|
CONSOLIDATED_BRAIN_TABLES = [
|
|
@@ -41106,11 +41457,11 @@ var init_skills_schema = __esm({
|
|
|
41106
41457
|
});
|
|
41107
41458
|
|
|
41108
41459
|
// packages/core/src/store/skills-db.ts
|
|
41109
|
-
import { join as
|
|
41460
|
+
import { join as join27 } from "node:path";
|
|
41110
41461
|
import { and as and6, eq as eq8 } from "drizzle-orm";
|
|
41111
41462
|
function getDefaultSkillsDbPath() {
|
|
41112
41463
|
const cleoHome = getCleoHome();
|
|
41113
|
-
const dbPath =
|
|
41464
|
+
const dbPath = join27(cleoHome, "cleo.db");
|
|
41114
41465
|
if (!dbPath.startsWith(cleoHome)) {
|
|
41115
41466
|
throw new Error(
|
|
41116
41467
|
`BUG: getDefaultSkillsDbPath() resolved to "${dbPath}" which is NOT under getCleoHome() ("${cleoHome}"). The skills registry is global-only per SG-CLEO-SKILLS-architecture-v3.md \xA74. Fix the caller, do not suppress.`
|
|
@@ -41158,19 +41509,19 @@ import {
|
|
|
41158
41509
|
chmodSync,
|
|
41159
41510
|
closeSync,
|
|
41160
41511
|
copyFileSync as copyFileSync3,
|
|
41161
|
-
existsSync as
|
|
41512
|
+
existsSync as existsSync21,
|
|
41162
41513
|
fsyncSync,
|
|
41163
41514
|
linkSync,
|
|
41164
41515
|
mkdirSync as mkdirSync5,
|
|
41165
41516
|
openSync,
|
|
41166
41517
|
readdirSync as readdirSync5,
|
|
41167
|
-
realpathSync as
|
|
41518
|
+
realpathSync as realpathSync7,
|
|
41168
41519
|
renameSync as renameSync6,
|
|
41169
41520
|
rmSync,
|
|
41170
41521
|
statSync as statSync6,
|
|
41171
41522
|
unlinkSync as unlinkSync3
|
|
41172
41523
|
} from "node:fs";
|
|
41173
|
-
import { dirname as
|
|
41524
|
+
import { dirname as dirname16, join as join28, sep as sep4 } from "node:path";
|
|
41174
41525
|
function resolveInventoryPath(entry, cwd) {
|
|
41175
41526
|
try {
|
|
41176
41527
|
if (entry.tier === "global") {
|
|
@@ -41206,8 +41557,8 @@ async function openAgentRegistryDbForSnapshot() {
|
|
|
41206
41557
|
}
|
|
41207
41558
|
async function openTelemetryDbForSnapshot() {
|
|
41208
41559
|
try {
|
|
41209
|
-
const path =
|
|
41210
|
-
if (!
|
|
41560
|
+
const path = join28(getCleoHome(), "telemetry.db");
|
|
41561
|
+
if (!existsSync21(path)) return null;
|
|
41211
41562
|
} catch {
|
|
41212
41563
|
return null;
|
|
41213
41564
|
}
|
|
@@ -41319,7 +41670,7 @@ function rotateSnapshots(backupDir, prefix, justWritten) {
|
|
|
41319
41670
|
for (const name15 of names) {
|
|
41320
41671
|
if (keep.has(name15)) continue;
|
|
41321
41672
|
try {
|
|
41322
|
-
unlinkSync3(
|
|
41673
|
+
unlinkSync3(join28(backupDir, name15));
|
|
41323
41674
|
} catch {
|
|
41324
41675
|
}
|
|
41325
41676
|
}
|
|
@@ -41341,7 +41692,7 @@ async function snapshotProjectTargetsGated(targets, opts) {
|
|
|
41341
41692
|
let backupDir;
|
|
41342
41693
|
try {
|
|
41343
41694
|
const cleoDir = getCleoDir(cwd);
|
|
41344
|
-
backupDir =
|
|
41695
|
+
backupDir = join28(cleoDir, "backups", "sqlite");
|
|
41345
41696
|
mkdirSync5(backupDir, { recursive: true });
|
|
41346
41697
|
} catch {
|
|
41347
41698
|
return null;
|
|
@@ -41373,7 +41724,7 @@ function sourceFileOf(db) {
|
|
|
41373
41724
|
const location = db.location();
|
|
41374
41725
|
if (!location) return null;
|
|
41375
41726
|
try {
|
|
41376
|
-
return
|
|
41727
|
+
return realpathSync7(location);
|
|
41377
41728
|
} catch {
|
|
41378
41729
|
return location;
|
|
41379
41730
|
}
|
|
@@ -41384,10 +41735,10 @@ function hasLocation(db) {
|
|
|
41384
41735
|
function assertOwnedByProject(source, prefix, cwd) {
|
|
41385
41736
|
let cleoDir = getCleoDir(cwd);
|
|
41386
41737
|
try {
|
|
41387
|
-
cleoDir =
|
|
41738
|
+
cleoDir = realpathSync7(cleoDir);
|
|
41388
41739
|
} catch {
|
|
41389
41740
|
}
|
|
41390
|
-
if (!source.startsWith(cleoDir +
|
|
41741
|
+
if (!source.startsWith(cleoDir + sep4)) {
|
|
41391
41742
|
throw new Error(
|
|
41392
41743
|
`refusing to snapshot ${prefix}: its database ${source} is not inside ${cleoDir}`
|
|
41393
41744
|
);
|
|
@@ -41416,7 +41767,7 @@ function commitSnapshotFile(tmp, dest) {
|
|
|
41416
41767
|
}
|
|
41417
41768
|
renameSync6(tmp, dest);
|
|
41418
41769
|
try {
|
|
41419
|
-
const dirFd = openSync(
|
|
41770
|
+
const dirFd = openSync(dirname16(dest), "r");
|
|
41420
41771
|
try {
|
|
41421
41772
|
fsyncSync(dirFd);
|
|
41422
41773
|
} finally {
|
|
@@ -41439,7 +41790,7 @@ function removeDeadTempSnapshots(backupDir) {
|
|
|
41439
41790
|
const m = TEMP_SNAPSHOT_RE.exec(name15);
|
|
41440
41791
|
if (!m) continue;
|
|
41441
41792
|
const pid = Number(m[1]);
|
|
41442
|
-
const path =
|
|
41793
|
+
const path = join28(backupDir, name15);
|
|
41443
41794
|
const stale = pid !== process.pid && (!isPidAlive2(pid) || Date.now() - statSync6(path).mtimeMs > TEMP_SNAPSHOT_MAX_AGE_MS);
|
|
41444
41795
|
if (stale) rmSync(path, { force: true });
|
|
41445
41796
|
}
|
|
@@ -41449,7 +41800,7 @@ function removeDeadTempSnapshots(backupDir) {
|
|
|
41449
41800
|
async function freeSnapshotName(backupDir, prefix) {
|
|
41450
41801
|
for (let attempt = 0; attempt < SNAPSHOT_NAME_ATTEMPTS; attempt++) {
|
|
41451
41802
|
const name15 = `${prefix}-${formatTimestamp(/* @__PURE__ */ new Date())}.db`;
|
|
41452
|
-
if (!
|
|
41803
|
+
if (!existsSync21(join28(backupDir, name15))) return name15;
|
|
41453
41804
|
await new Promise((r) => setTimeout(r, 1e3 - Date.now() % 1e3 + 5));
|
|
41454
41805
|
}
|
|
41455
41806
|
throw new Error(`no free snapshot filename for ${prefix} in ${backupDir}`);
|
|
@@ -41477,7 +41828,7 @@ async function snapshotOne(target, backupDir, writtenBySource, cwd) {
|
|
|
41477
41828
|
if (opened && target.closeDb) target.closeDb(opened);
|
|
41478
41829
|
throw err;
|
|
41479
41830
|
}
|
|
41480
|
-
const dest =
|
|
41831
|
+
const dest = join28(backupDir, destName);
|
|
41481
41832
|
removeDeadTempSnapshots(backupDir);
|
|
41482
41833
|
const existing = source !== null ? writtenBySource.get(source) : void 0;
|
|
41483
41834
|
if (existing !== void 0) {
|
|
@@ -41531,13 +41882,13 @@ async function vacuumIntoBackup(opts = {}) {
|
|
|
41531
41882
|
function listSqliteBackupsForPrefix(prefix, cwd) {
|
|
41532
41883
|
try {
|
|
41533
41884
|
const cleoDir = getCleoDir(cwd);
|
|
41534
|
-
const backupDir =
|
|
41535
|
-
if (!
|
|
41885
|
+
const backupDir = join28(cleoDir, "backups", "sqlite");
|
|
41886
|
+
if (!existsSync21(backupDir)) return [];
|
|
41536
41887
|
const pattern = snapshotPattern(prefix);
|
|
41537
41888
|
return readdirSync5(backupDir).filter((f) => pattern.test(f)).map((f) => ({
|
|
41538
41889
|
name: f,
|
|
41539
|
-
path:
|
|
41540
|
-
mtimeMs: statSync6(
|
|
41890
|
+
path: join28(backupDir, f),
|
|
41891
|
+
mtimeMs: statSync6(join28(backupDir, f)).mtimeMs
|
|
41541
41892
|
})).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
41542
41893
|
} catch {
|
|
41543
41894
|
return [];
|
|
@@ -41610,13 +41961,13 @@ __export(sqlite_exports, {
|
|
|
41610
41961
|
seedTasksMeta: () => seedTasksMeta,
|
|
41611
41962
|
worktreeRecoveryRefusal: () => worktreeRecoveryRefusal
|
|
41612
41963
|
});
|
|
41613
|
-
import { copyFileSync as copyFileSync4, existsSync as
|
|
41614
|
-
import { createRequire as
|
|
41615
|
-
import { basename as basename8, dirname as
|
|
41964
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync22, realpathSync as realpathSync8, renameSync as renameSync7, unlinkSync as unlinkSync4 } from "node:fs";
|
|
41965
|
+
import { createRequire as createRequire8 } from "node:module";
|
|
41966
|
+
import { basename as basename8, dirname as dirname17, resolve as resolve12 } from "node:path";
|
|
41616
41967
|
import { eq as eq9 } from "drizzle-orm";
|
|
41617
41968
|
function _getDrizzle3() {
|
|
41618
41969
|
if (_drizzle3 === null) {
|
|
41619
|
-
const _require7 =
|
|
41970
|
+
const _require7 = createRequire8(import.meta.url);
|
|
41620
41971
|
const mod = _require7("drizzle-orm/node-sqlite");
|
|
41621
41972
|
_drizzle3 = mod.drizzle;
|
|
41622
41973
|
}
|
|
@@ -41652,16 +42003,16 @@ function countBackupTasks(backupDb) {
|
|
|
41652
42003
|
return 0;
|
|
41653
42004
|
}
|
|
41654
42005
|
function isSameDirectory(a, b) {
|
|
41655
|
-
if (
|
|
42006
|
+
if (resolve12(a) === resolve12(b)) return true;
|
|
41656
42007
|
try {
|
|
41657
|
-
return
|
|
42008
|
+
return realpathSync8(a) === realpathSync8(b);
|
|
41658
42009
|
} catch {
|
|
41659
42010
|
return false;
|
|
41660
42011
|
}
|
|
41661
42012
|
}
|
|
41662
42013
|
function worktreeRecoveryRefusal(dbPath) {
|
|
41663
|
-
const storeCleoDir =
|
|
41664
|
-
const root =
|
|
42014
|
+
const storeCleoDir = dirname17(dbPath);
|
|
42015
|
+
const root = dirname17(storeCleoDir);
|
|
41665
42016
|
if (basename8(storeCleoDir) !== ".cleo" || !isGitLinkedCheckout(root)) return null;
|
|
41666
42017
|
return `Auto-recovery refused: ${dbPath} lives inside the git worktree ${root}; ${describeWorktreeOwner(root)}. A worktree uses its owning project's store and never receives a restored copy (T12460, T12677).`;
|
|
41667
42018
|
}
|
|
@@ -41673,7 +42024,7 @@ async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
|
|
|
41673
42024
|
const countResult = nativeDb.prepare("SELECT COUNT(*) as cnt FROM tasks_tasks").get();
|
|
41674
42025
|
const taskCount = countResult?.cnt ?? 0;
|
|
41675
42026
|
if (taskCount > 0) return false;
|
|
41676
|
-
const storeCleoDir =
|
|
42027
|
+
const storeCleoDir = dirname17(dbPath);
|
|
41677
42028
|
const worktreeRefusal = worktreeRecoveryRefusal(dbPath);
|
|
41678
42029
|
if (worktreeRefusal !== null) {
|
|
41679
42030
|
log15.warn({ dbPath }, worktreeRefusal);
|
|
@@ -41684,7 +42035,7 @@ async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
|
|
|
41684
42035
|
return false;
|
|
41685
42036
|
}
|
|
41686
42037
|
const newestBackup = backups[0];
|
|
41687
|
-
const backupCleoDir =
|
|
42038
|
+
const backupCleoDir = dirname17(dirname17(dirname17(newestBackup.path)));
|
|
41688
42039
|
if (!isSameDirectory(backupCleoDir, storeCleoDir)) {
|
|
41689
42040
|
log15.warn(
|
|
41690
42041
|
{ dbPath, backupPath: newestBackup.path },
|
|
@@ -41806,6 +42157,7 @@ function runMigrations(nativeDb, db, dbPath) {
|
|
|
41806
42157
|
try {
|
|
41807
42158
|
migrateWithRetry(db, migrationsFolder, nativeDb, "tasks", "sqlite");
|
|
41808
42159
|
} catch (error48) {
|
|
42160
|
+
if (isWorktreeBuildSchemaError(error48)) throw error48;
|
|
41809
42161
|
if (isSqliteBusy(error48) || !tableExists(nativeDb, "tasks_tasks")) throw error48;
|
|
41810
42162
|
try {
|
|
41811
42163
|
rebuildLegacyTasksLineage(
|
|
@@ -41847,7 +42199,7 @@ async function getSchemaVersion(cwd) {
|
|
|
41847
42199
|
return result[0]?.value ?? null;
|
|
41848
42200
|
}
|
|
41849
42201
|
function dbExists(cwd) {
|
|
41850
|
-
return
|
|
42202
|
+
return existsSync22(resolveDualScopeDbPath("project", cwd));
|
|
41851
42203
|
}
|
|
41852
42204
|
function getNativeDb(cwd) {
|
|
41853
42205
|
return boundProjectNative("tasks", cwd);
|
|
@@ -41883,6 +42235,7 @@ var init_sqlite3 = __esm({
|
|
|
41883
42235
|
init_resolve_migrations_folder();
|
|
41884
42236
|
init_sqlite_backup();
|
|
41885
42237
|
init_twin_collapse();
|
|
42238
|
+
init_worktree_build_guard();
|
|
41886
42239
|
init_worktree_isolation_guard();
|
|
41887
42240
|
init_sqlite_native();
|
|
41888
42241
|
init_tasks_schema();
|
|
@@ -41911,15 +42264,15 @@ var init_sqlite3 = __esm({
|
|
|
41911
42264
|
// packages/core/src/store/exodus/migrate.ts
|
|
41912
42265
|
import {
|
|
41913
42266
|
copyFileSync as copyFileSync5,
|
|
41914
|
-
existsSync as
|
|
42267
|
+
existsSync as existsSync23,
|
|
41915
42268
|
mkdirSync as mkdirSync6,
|
|
41916
|
-
readFileSync as
|
|
42269
|
+
readFileSync as readFileSync8,
|
|
41917
42270
|
renameSync as renameSync8,
|
|
41918
42271
|
statSync as statSync7,
|
|
41919
42272
|
unlinkSync as unlinkSync5,
|
|
41920
42273
|
writeFileSync as writeFileSync6
|
|
41921
42274
|
} from "node:fs";
|
|
41922
|
-
import { join as
|
|
42275
|
+
import { join as join29 } from "node:path";
|
|
41923
42276
|
function getSqliteVersion(db) {
|
|
41924
42277
|
try {
|
|
41925
42278
|
const row = db.prepare("SELECT sqlite_version() AS v").get();
|
|
@@ -41950,24 +42303,24 @@ function restoreGrandfatheredGuards(db, suspended) {
|
|
|
41950
42303
|
}
|
|
41951
42304
|
}
|
|
41952
42305
|
function writeJournal(stagingDir, journal) {
|
|
41953
|
-
const journalPath =
|
|
42306
|
+
const journalPath = join29(stagingDir, JOURNAL_FILENAME);
|
|
41954
42307
|
const tmpPath = `${journalPath}.tmp`;
|
|
41955
42308
|
writeFileSync6(tmpPath, JSON.stringify(journal, null, 2) + "\n", "utf8");
|
|
41956
42309
|
renameSync8(tmpPath, journalPath);
|
|
41957
42310
|
}
|
|
41958
42311
|
function readJournal(stagingDir) {
|
|
41959
|
-
const journalPath =
|
|
41960
|
-
if (!
|
|
42312
|
+
const journalPath = join29(stagingDir, JOURNAL_FILENAME);
|
|
42313
|
+
if (!existsSync23(journalPath)) return null;
|
|
41961
42314
|
try {
|
|
41962
|
-
return JSON.parse(
|
|
42315
|
+
return JSON.parse(readFileSync8(journalPath, "utf8"));
|
|
41963
42316
|
} catch {
|
|
41964
42317
|
return null;
|
|
41965
42318
|
}
|
|
41966
42319
|
}
|
|
41967
42320
|
function clearExodusJournal(stagingDir) {
|
|
41968
|
-
const journalPath =
|
|
42321
|
+
const journalPath = join29(stagingDir, JOURNAL_FILENAME);
|
|
41969
42322
|
try {
|
|
41970
|
-
if (!
|
|
42323
|
+
if (!existsSync23(journalPath)) return false;
|
|
41971
42324
|
unlinkSync5(journalPath);
|
|
41972
42325
|
log10.info(
|
|
41973
42326
|
{ stagingDir },
|
|
@@ -42263,7 +42616,7 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress, opt
|
|
|
42263
42616
|
mkdirSync6(stagingDir, { recursive: true });
|
|
42264
42617
|
let sqliteVersion = "unknown";
|
|
42265
42618
|
for (const src of sources) {
|
|
42266
|
-
if (
|
|
42619
|
+
if (existsSync23(src.path)) {
|
|
42267
42620
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
42268
42621
|
sqliteVersion = getSqliteVersion(snap.db);
|
|
42269
42622
|
snap.close();
|
|
@@ -42293,15 +42646,15 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress, opt
|
|
|
42293
42646
|
let reseedProject = null;
|
|
42294
42647
|
try {
|
|
42295
42648
|
for (const src of sources) {
|
|
42296
|
-
if (!
|
|
42297
|
-
const backupDest =
|
|
42649
|
+
if (!existsSync23(src.path)) continue;
|
|
42650
|
+
const backupDest = join29(stagingDir, `${src.name.replace(/[^a-z0-9-]/g, "_")}-backup.db`);
|
|
42298
42651
|
const srcBytes = safeStatBytes(src.path);
|
|
42299
42652
|
const skipStagingCopy = srcBytes > plan.stagingCopyThresholdBytes;
|
|
42300
42653
|
if (skipStagingCopy) {
|
|
42301
42654
|
onProgress?.(
|
|
42302
42655
|
`Skipping full staging copy of ${src.name} (${srcBytes} bytes > ${plan.stagingCopyThresholdBytes} threshold) \u2014 source is archived, not deleted, on success.`
|
|
42303
42656
|
);
|
|
42304
|
-
} else if (!
|
|
42657
|
+
} else if (!existsSync23(backupDest)) {
|
|
42305
42658
|
onProgress?.(`Backing up ${src.name} \u2192 staging dir\u2026`);
|
|
42306
42659
|
copyFileSync5(src.path, backupDest);
|
|
42307
42660
|
backupPaths.push(backupDest);
|
|
@@ -42334,8 +42687,8 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress, opt
|
|
|
42334
42687
|
}
|
|
42335
42688
|
prepareExodusRecovery(projectNative, stagingDir);
|
|
42336
42689
|
if (globalNative !== null) prepareExodusRecovery(globalNative, stagingDir);
|
|
42337
|
-
const projectSources = sources.filter((s) => s.targetScope === "project" &&
|
|
42338
|
-
const globalSources = sources.filter((s) => s.targetScope === "global" &&
|
|
42690
|
+
const projectSources = sources.filter((s) => s.targetScope === "project" && existsSync23(s.path));
|
|
42691
|
+
const globalSources = sources.filter((s) => s.targetScope === "global" && existsSync23(s.path));
|
|
42339
42692
|
if (globalNative === null && globalSources.length > 0)
|
|
42340
42693
|
throw new Error("A projectOnly exodus run was given global-scope sources");
|
|
42341
42694
|
await migrateScope(
|
|
@@ -42643,9 +42996,9 @@ __export(reconcile_exports, {
|
|
|
42643
42996
|
reconcileSupersededStores: () => reconcileSupersededStores,
|
|
42644
42997
|
unmigratedBareSources: () => unmigratedBareSources
|
|
42645
42998
|
});
|
|
42646
|
-
import { copyFileSync as copyFileSync6, existsSync as
|
|
42999
|
+
import { copyFileSync as copyFileSync6, existsSync as existsSync24, mkdirSync as mkdirSync7, mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSync7 } from "node:fs";
|
|
42647
43000
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
42648
|
-
import { basename as basename9, join as
|
|
43001
|
+
import { basename as basename9, join as join30 } from "node:path";
|
|
42649
43002
|
function ident2(name15) {
|
|
42650
43003
|
return `"${name15.replace(/"/g, '""')}"`;
|
|
42651
43004
|
}
|
|
@@ -42714,7 +43067,7 @@ function assessSupersededProjectStores(liveStorePath, sources, resolveTarget = r
|
|
|
42714
43067
|
}
|
|
42715
43068
|
function legacySourcesHoldRows(sources) {
|
|
42716
43069
|
for (const src of sources) {
|
|
42717
|
-
if (!
|
|
43070
|
+
if (!existsSync24(src.path)) continue;
|
|
42718
43071
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
42719
43072
|
try {
|
|
42720
43073
|
for (const table of orderTablesForCopy(snap.db)) {
|
|
@@ -42745,8 +43098,8 @@ async function bareTaskCoreSource(liveStorePath, resolveTarget, outDir) {
|
|
|
42745
43098
|
live.close();
|
|
42746
43099
|
}
|
|
42747
43100
|
if (tables.length === 0) return null;
|
|
42748
|
-
const seedPath = await buildFreshProjectStore(
|
|
42749
|
-
const path =
|
|
43101
|
+
const seedPath = await buildFreshProjectStore(join30(outDir, "fresh-project-seed.db"));
|
|
43102
|
+
const path = join30(outDir, "cleo-bare-task-core.db");
|
|
42750
43103
|
const snap = openCleoDbSnapshot(path, { readOnly: false });
|
|
42751
43104
|
let kept = 0;
|
|
42752
43105
|
try {
|
|
@@ -42794,7 +43147,7 @@ async function buildFreshProjectStore(path) {
|
|
|
42794
43147
|
}
|
|
42795
43148
|
function snapshotFresherBareRows(barePath, legacyTasksPath, stagingDir) {
|
|
42796
43149
|
if (legacyTasksPath === void 0) return null;
|
|
42797
|
-
const path =
|
|
43150
|
+
const path = join30(stagingDir, "cleo-bare-task-core-fresher.db");
|
|
42798
43151
|
const snap = openCleoDbSnapshot(barePath, { readOnly: true });
|
|
42799
43152
|
try {
|
|
42800
43153
|
snap.db.exec(`VACUUM INTO '${path.replace(/'/g, "''")}'`);
|
|
@@ -42945,7 +43298,7 @@ async function reconcileSuppressed(projectRoot, options, liveStorePath) {
|
|
|
42945
43298
|
const additive = options.additive === true;
|
|
42946
43299
|
const plan = buildExodusPlan(projectRoot);
|
|
42947
43300
|
const resolveTarget = await buildRuntimeTargetResolver();
|
|
42948
|
-
const scratch = mkdtempSync(
|
|
43301
|
+
const scratch = mkdtempSync(join30(tmpdir3(), "cleo-reconcile-"));
|
|
42949
43302
|
try {
|
|
42950
43303
|
return await reconcileWithScratch(
|
|
42951
43304
|
projectRoot,
|
|
@@ -42961,8 +43314,8 @@ async function reconcileSuppressed(projectRoot, options, liveStorePath) {
|
|
|
42961
43314
|
}
|
|
42962
43315
|
}
|
|
42963
43316
|
async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath, plan, resolveTarget, scratch) {
|
|
42964
|
-
const fileSources = plan.sources.filter((s) => s.targetScope === "project" &&
|
|
42965
|
-
const bare = !additive &&
|
|
43317
|
+
const fileSources = plan.sources.filter((s) => s.targetScope === "project" && existsSync24(s.path));
|
|
43318
|
+
const bare = !additive && existsSync24(liveStorePath) ? await bareTaskCoreSource(liveStorePath, resolveTarget, scratch) : null;
|
|
42966
43319
|
const copyResolver = additive ? (sourceName, legacyTable) => {
|
|
42967
43320
|
const r = resolveTarget(sourceName, legacyTable);
|
|
42968
43321
|
return r.kind !== "skip" && isLiveAuthoritative(sourceName, legacyTable, r.targetName) ? { kind: "skip", reason: "additive: live-authoritative task graph" } : r;
|
|
@@ -42981,7 +43334,7 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
42981
43334
|
stagingDir: null,
|
|
42982
43335
|
receiptPath: null
|
|
42983
43336
|
};
|
|
42984
|
-
if (sources.length === 0 || !
|
|
43337
|
+
if (sources.length === 0 || !existsSync24(liveStorePath)) {
|
|
42985
43338
|
return {
|
|
42986
43339
|
...base,
|
|
42987
43340
|
outcome: "nothing-to-reconcile",
|
|
@@ -43021,11 +43374,11 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
43021
43374
|
};
|
|
43022
43375
|
}
|
|
43023
43376
|
const iso = (/* @__PURE__ */ new Date()).toISOString().replace(/[:]/g, "").replace(/\..+Z$/, "Z");
|
|
43024
|
-
const stagingDir =
|
|
43377
|
+
const stagingDir = join30(resolveCleoDir(projectRoot), `${RECONCILE_DIR_PREFIX}${iso}`);
|
|
43025
43378
|
mkdirSync7(stagingDir, { recursive: true });
|
|
43026
43379
|
const copySources = sources.map((s) => {
|
|
43027
43380
|
if (s !== bare) return s;
|
|
43028
|
-
const kept =
|
|
43381
|
+
const kept = join30(stagingDir, basename9(s.path));
|
|
43029
43382
|
copyFileSync6(s.path, kept);
|
|
43030
43383
|
return { ...s, path: kept };
|
|
43031
43384
|
});
|
|
@@ -43045,7 +43398,7 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
43045
43398
|
const result = await withLock(
|
|
43046
43399
|
`${liveStorePath}.exodus-on-open.lock`,
|
|
43047
43400
|
async () => {
|
|
43048
|
-
const liveBefore =
|
|
43401
|
+
const liveBefore = join30(scratch, "live-before.db");
|
|
43049
43402
|
snapshotLive(liveStorePath, liveBefore);
|
|
43050
43403
|
const migrated = await runExodusMigrate(reconcilePlan, false, (msg) => log11.debug(msg), {
|
|
43051
43404
|
projectOnly: true,
|
|
@@ -43095,7 +43448,7 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
43095
43448
|
},
|
|
43096
43449
|
{ stale: 6e5, retries: 30 }
|
|
43097
43450
|
);
|
|
43098
|
-
const receiptPath =
|
|
43451
|
+
const receiptPath = join30(stagingDir, RECEIPT_FILENAME);
|
|
43099
43452
|
const receipt2 = { ...result, receiptPath };
|
|
43100
43453
|
writeFileSync7(receiptPath, `${JSON.stringify(receipt2, null, 2)}
|
|
43101
43454
|
`, "utf8");
|
|
@@ -43172,20 +43525,20 @@ var init_seal = __esm({
|
|
|
43172
43525
|
});
|
|
43173
43526
|
|
|
43174
43527
|
// packages/core/src/store/exodus/status.ts
|
|
43175
|
-
import { existsSync as
|
|
43176
|
-
import { join as
|
|
43528
|
+
import { existsSync as existsSync25, readdirSync as readdirSync6, readFileSync as readFileSync9, statSync as statSync8 } from "node:fs";
|
|
43529
|
+
import { join as join31 } from "node:path";
|
|
43177
43530
|
function readJournal2(stagingDir) {
|
|
43178
|
-
const p =
|
|
43179
|
-
if (!
|
|
43531
|
+
const p = join31(stagingDir, JOURNAL_FILENAME2);
|
|
43532
|
+
if (!existsSync25(p)) return null;
|
|
43180
43533
|
try {
|
|
43181
|
-
return JSON.parse(
|
|
43534
|
+
return JSON.parse(readFileSync9(p, "utf8"));
|
|
43182
43535
|
} catch {
|
|
43183
43536
|
return null;
|
|
43184
43537
|
}
|
|
43185
43538
|
}
|
|
43186
43539
|
function findStagingDirs(cleoDir) {
|
|
43187
43540
|
try {
|
|
43188
|
-
return readdirSync6(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) =>
|
|
43541
|
+
return readdirSync6(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => join31(cleoDir, e.name)).sort().reverse();
|
|
43189
43542
|
} catch {
|
|
43190
43543
|
return [];
|
|
43191
43544
|
}
|
|
@@ -43208,15 +43561,15 @@ function runExodusStatus(cwd) {
|
|
|
43208
43561
|
const sourcesInfo = plan.sources.map((s) => ({
|
|
43209
43562
|
name: s.name,
|
|
43210
43563
|
path: s.path,
|
|
43211
|
-
exists:
|
|
43564
|
+
exists: existsSync25(s.path),
|
|
43212
43565
|
bytes: safeBytes(s.path)
|
|
43213
43566
|
}));
|
|
43214
43567
|
return {
|
|
43215
43568
|
hasStaging: latestStaging !== null,
|
|
43216
43569
|
stagingDir: latestStaging,
|
|
43217
43570
|
journal,
|
|
43218
|
-
projectDbExists:
|
|
43219
|
-
globalDbExists:
|
|
43571
|
+
projectDbExists: existsSync25(projectDbPath),
|
|
43572
|
+
globalDbExists: existsSync25(globalDbPath),
|
|
43220
43573
|
sourcesPresent: sourcesInfo.some((s) => s.exists),
|
|
43221
43574
|
sources: sourcesInfo
|
|
43222
43575
|
};
|
|
@@ -43233,8 +43586,8 @@ var init_status = __esm({
|
|
|
43233
43586
|
});
|
|
43234
43587
|
|
|
43235
43588
|
// packages/core/src/store/exodus/verify-migration.ts
|
|
43236
|
-
import { existsSync as
|
|
43237
|
-
import { createRequire as
|
|
43589
|
+
import { existsSync as existsSync26 } from "node:fs";
|
|
43590
|
+
import { createRequire as createRequire9 } from "node:module";
|
|
43238
43591
|
function orderByClause(db, tableName) {
|
|
43239
43592
|
try {
|
|
43240
43593
|
const pragma = db.prepare(`PRAGMA table_info("${tableName}")`).all();
|
|
@@ -43498,7 +43851,7 @@ function orphanAlreadyInSource(targetDb, fk, sources, resolveTarget = resolveCon
|
|
|
43498
43851
|
const anyFeeder = (targetTable, probe) => {
|
|
43499
43852
|
for (const feeder of feedersOf(targetTable)) {
|
|
43500
43853
|
const src = sources.find((s) => s.name === feeder.sourceName);
|
|
43501
|
-
if (src === void 0 || !
|
|
43854
|
+
if (src === void 0 || !existsSync26(src.path)) continue;
|
|
43502
43855
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
43503
43856
|
try {
|
|
43504
43857
|
if (!tableExists3(snap.db, feeder.legacyTable)) continue;
|
|
@@ -43553,7 +43906,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress, resol
|
|
|
43553
43906
|
const preExistingForeignKeyViolations = [];
|
|
43554
43907
|
const failureLines = [];
|
|
43555
43908
|
const sourceOrphanSigs = /* @__PURE__ */ new Set();
|
|
43556
|
-
if (!
|
|
43909
|
+
if (!existsSync26(projectDbPath)) {
|
|
43557
43910
|
return {
|
|
43558
43911
|
ok: false,
|
|
43559
43912
|
tables: [],
|
|
@@ -43564,7 +43917,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress, resol
|
|
|
43564
43917
|
error: `Consolidated project cleo.db not found at ${projectDbPath}. Run 'cleo exodus migrate' first.`
|
|
43565
43918
|
};
|
|
43566
43919
|
}
|
|
43567
|
-
if (!
|
|
43920
|
+
if (!existsSync26(globalDbPath)) {
|
|
43568
43921
|
return {
|
|
43569
43922
|
ok: false,
|
|
43570
43923
|
tables: [],
|
|
@@ -43579,7 +43932,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress, resol
|
|
|
43579
43932
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
43580
43933
|
try {
|
|
43581
43934
|
for (const src of sources) {
|
|
43582
|
-
if (!
|
|
43935
|
+
if (!existsSync26(src.path)) {
|
|
43583
43936
|
onProgress?.(`Skipping ${src.name} (not present)`);
|
|
43584
43937
|
continue;
|
|
43585
43938
|
}
|
|
@@ -43774,7 +44127,7 @@ var init_verify_migration = __esm({
|
|
|
43774
44127
|
init_column_transforms();
|
|
43775
44128
|
init_table_name_map();
|
|
43776
44129
|
log13 = getLogger("verify-migration");
|
|
43777
|
-
_require5 =
|
|
44130
|
+
_require5 = createRequire9(import.meta.url);
|
|
43778
44131
|
CHECK_ENUM_REGEX = /CHECK\s*\(\s*"([^"]+)"\s+(?:IS\s+NULL\s+OR\s+"[^"]+"\s+)?IN\s*\(([^)]*)\)\s*\)/gi;
|
|
43779
44132
|
}
|
|
43780
44133
|
});
|
|
@@ -43870,11 +44223,11 @@ __export(on_open_exports, {
|
|
|
43870
44223
|
maybeRunExodusOnOpen: () => maybeRunExodusOnOpen,
|
|
43871
44224
|
withExodusOnOpenSuppressed: () => withExodusOnOpenSuppressed
|
|
43872
44225
|
});
|
|
43873
|
-
import { existsSync as
|
|
44226
|
+
import { existsSync as existsSync27, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
43874
44227
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
43875
|
-
import { join as
|
|
44228
|
+
import { join as join32, resolve as resolve13 } from "node:path";
|
|
43876
44229
|
async function withExodusOnOpenSuppressed(dbPath, fn) {
|
|
43877
|
-
const key =
|
|
44230
|
+
const key = resolve13(dbPath);
|
|
43878
44231
|
_reconcileInProgress.set(key, (_reconcileInProgress.get(key) ?? 0) + 1);
|
|
43879
44232
|
try {
|
|
43880
44233
|
return await fn();
|
|
@@ -43912,7 +44265,7 @@ function remedyFor(scope) {
|
|
|
43912
44265
|
}
|
|
43913
44266
|
async function strandedLegacySources(scope, cwd) {
|
|
43914
44267
|
const { buildExodusPlan: buildExodusPlan2, legacySourcesHoldRows: legacySourcesHoldRows2 } = await Promise.resolve().then(() => (init_exodus(), exodus_exports));
|
|
43915
|
-
return buildExodusPlan2(cwd).sources.filter((s) => s.targetScope === scope &&
|
|
44268
|
+
return buildExodusPlan2(cwd).sources.filter((s) => s.targetScope === scope && existsSync27(s.path)).filter((s) => legacySourcesHoldRows2([s])).map((s) => s.name);
|
|
43916
44269
|
}
|
|
43917
44270
|
async function rollbackBothScopes(plan) {
|
|
43918
44271
|
const { getDualScopeNativeDb: getDualScopeNativeDb2, openDualScopeDbAtPath: openDualScopeDbAtPath2 } = await Promise.resolve().then(() => (init_dual_scope_db(), dual_scope_db_exports));
|
|
@@ -43990,7 +44343,7 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
43990
44343
|
if (_exodusInProgress) {
|
|
43991
44344
|
return { outcome: "skipped", reason: "re-entrant open during active migration" };
|
|
43992
44345
|
}
|
|
43993
|
-
if (_reconcileInProgress.has(
|
|
44346
|
+
if (_reconcileInProgress.has(resolve13(dbPath))) {
|
|
43994
44347
|
return {
|
|
43995
44348
|
outcome: "skipped",
|
|
43996
44349
|
reason: "an explicit superseded-store reconcile of this store is in progress"
|
|
@@ -44023,14 +44376,14 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
44023
44376
|
const { buildExodusPlan: buildExodusPlan2, runExodusMigrate: runExodusMigrate2, verifyMigration: verifyMigration2, clearExodusJournal: clearExodusJournal2 } = await Promise.resolve().then(() => (init_exodus(), exodus_exports));
|
|
44024
44377
|
const plan = buildExodusPlan2(cwd);
|
|
44025
44378
|
const plannedTarget = scope === "project" ? plan.projectDbPath : plan.globalDbPath;
|
|
44026
|
-
if (
|
|
44379
|
+
if (resolve13(plannedTarget) !== resolve13(dbPath)) {
|
|
44027
44380
|
return {
|
|
44028
44381
|
outcome: "aborted",
|
|
44029
44382
|
reason: `migration plan target ${plannedTarget} does not match opened database ${dbPath}; no migration applied`
|
|
44030
44383
|
};
|
|
44031
44384
|
}
|
|
44032
44385
|
const scopeSources = plan.sources.filter((s) => s.targetScope === scope);
|
|
44033
|
-
if (!scopeSources.some((s) =>
|
|
44386
|
+
if (!scopeSources.some((s) => existsSync27(s.path))) {
|
|
44034
44387
|
return {
|
|
44035
44388
|
outcome: "skipped",
|
|
44036
44389
|
reason: `no legacy ${scope}-scope source DBs present (fresh install or cross-scope-only)`
|
|
@@ -44047,12 +44400,12 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
44047
44400
|
{
|
|
44048
44401
|
scope,
|
|
44049
44402
|
dbPath,
|
|
44050
|
-
sources: plan.sources.filter((s) =>
|
|
44403
|
+
sources: plan.sources.filter((s) => existsSync27(s.path)).map((s) => s.name)
|
|
44051
44404
|
},
|
|
44052
44405
|
"exodus-on-open: consolidated cleo.db is empty and legacy data present \u2014 auto-migrating"
|
|
44053
44406
|
);
|
|
44054
44407
|
_exodusInProgress = true;
|
|
44055
|
-
const bareScratch = mkdtempSync2(
|
|
44408
|
+
const bareScratch = mkdtempSync2(join32(tmpdir4(), "cleo-exodus-bare-"));
|
|
44056
44409
|
try {
|
|
44057
44410
|
const { buildRuntimeTargetResolver: buildRuntimeTargetResolver2 } = await Promise.resolve().then(() => (init_runtime_targets(), runtime_targets_exports));
|
|
44058
44411
|
const resolveTarget = await buildRuntimeTargetResolver2();
|
|
@@ -44060,7 +44413,7 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
44060
44413
|
const bare = scope === "project" ? await unmigratedBareSources2(
|
|
44061
44414
|
dbPath,
|
|
44062
44415
|
resolveTarget,
|
|
44063
|
-
plan.sources.find((s) => s.name === "tasks" &&
|
|
44416
|
+
plan.sources.find((s) => s.name === "tasks" && existsSync27(s.path))?.path,
|
|
44064
44417
|
bareScratch
|
|
44065
44418
|
) : { first: [], last: [] };
|
|
44066
44419
|
const migratePlan = { ...plan, sources: [...bare.first, ...plan.sources, ...bare.last] };
|
|
@@ -44124,7 +44477,7 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
44124
44477
|
"exodus-on-open: parity verified \u2014 legacy data migrated into consolidated cleo.db"
|
|
44125
44478
|
);
|
|
44126
44479
|
try {
|
|
44127
|
-
const consumed = plan.sources.filter((s) =>
|
|
44480
|
+
const consumed = plan.sources.filter((s) => existsSync27(s.path));
|
|
44128
44481
|
const identities = await sealTargets(plan, consumed);
|
|
44129
44482
|
const archiveResult = archiveMigratedSources(consumed, cwd, plan, identities);
|
|
44130
44483
|
log14.info(
|
|
@@ -44199,9 +44552,9 @@ __export(dual_scope_db_exports, {
|
|
|
44199
44552
|
upsertIdempotent: () => upsertIdempotent,
|
|
44200
44553
|
withStoreSchemaOwnership: () => withStoreSchemaOwnership
|
|
44201
44554
|
});
|
|
44202
|
-
import { existsSync as
|
|
44203
|
-
import { createRequire as
|
|
44204
|
-
import { dirname as
|
|
44555
|
+
import { existsSync as existsSync28, mkdirSync as mkdirSync8 } from "node:fs";
|
|
44556
|
+
import { createRequire as createRequire10 } from "node:module";
|
|
44557
|
+
import { dirname as dirname18, join as join33, resolve as resolve14 } from "node:path";
|
|
44205
44558
|
function getDualScopeNativeDb(handle) {
|
|
44206
44559
|
const db = handle.db;
|
|
44207
44560
|
if ("$client" in db && db.$client instanceof getDatabaseSyncCtor()) return db.$client;
|
|
@@ -44223,9 +44576,9 @@ function cacheKey(scope, dbPath) {
|
|
|
44223
44576
|
}
|
|
44224
44577
|
function resolveDualScopeDbPath(scope, cwd, capturedGlobalHome) {
|
|
44225
44578
|
if (scope === "project") {
|
|
44226
|
-
return
|
|
44579
|
+
return join33(resolveCleoDir(cwd), "cleo.db");
|
|
44227
44580
|
}
|
|
44228
|
-
return
|
|
44581
|
+
return join33(capturedGlobalHome ?? getCleoHome(), "cleo.db");
|
|
44229
44582
|
}
|
|
44230
44583
|
function migrationsSetName(scope) {
|
|
44231
44584
|
return scope === "project" ? "drizzle-cleo-project" : "drizzle-cleo-global";
|
|
@@ -44275,8 +44628,8 @@ async function openDualScopeDb(scope, cwd, options) {
|
|
|
44275
44628
|
async function openDedicatedDualScopeDb(scope, dbPath, log15, execution) {
|
|
44276
44629
|
execution?.assertActive();
|
|
44277
44630
|
log15.debug({ scope, dbPath }, "opening DEDICATED (non-cached) dual-scope cleo.db (T11782 FIX D)");
|
|
44278
|
-
const dir =
|
|
44279
|
-
if (!
|
|
44631
|
+
const dir = dirname18(dbPath);
|
|
44632
|
+
if (!existsSync28(dir)) {
|
|
44280
44633
|
mkdirSync8(dir, { recursive: true });
|
|
44281
44634
|
}
|
|
44282
44635
|
execution?.assertActive();
|
|
@@ -44284,6 +44637,7 @@ async function openDedicatedDualScopeDb(scope, dbPath, log15, execution) {
|
|
|
44284
44637
|
const nativeDb = new DatabaseSyncCtor(dbPath, { allowExtension: true });
|
|
44285
44638
|
try {
|
|
44286
44639
|
applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
|
|
44640
|
+
installSchemaWriteGuard(nativeDb);
|
|
44287
44641
|
const drizzle2 = getDrizzle();
|
|
44288
44642
|
const db = drizzle2({ client: nativeDb });
|
|
44289
44643
|
const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
|
|
@@ -44332,11 +44686,12 @@ async function openDedicatedDualScopeDb(scope, dbPath, log15, execution) {
|
|
|
44332
44686
|
execution?.assertActive();
|
|
44333
44687
|
return handle;
|
|
44334
44688
|
} catch (err) {
|
|
44689
|
+
const explained = explainSchemaWriteDenial(nativeDb, err);
|
|
44335
44690
|
try {
|
|
44336
44691
|
nativeDb.close();
|
|
44337
44692
|
} catch {
|
|
44338
44693
|
}
|
|
44339
|
-
throw
|
|
44694
|
+
throw explained;
|
|
44340
44695
|
}
|
|
44341
44696
|
}
|
|
44342
44697
|
async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
@@ -44357,7 +44712,7 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44357
44712
|
);
|
|
44358
44713
|
}
|
|
44359
44714
|
const dedicated = options?.dedicated === true;
|
|
44360
|
-
const normalizedPath =
|
|
44715
|
+
const normalizedPath = resolve14(dbPath);
|
|
44361
44716
|
const key = cacheKey(scope, normalizedPath);
|
|
44362
44717
|
if (!dedicated) {
|
|
44363
44718
|
const existing = _cache.get(key);
|
|
@@ -44394,8 +44749,8 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44394
44749
|
}
|
|
44395
44750
|
let initResolve = null;
|
|
44396
44751
|
let initReject = null;
|
|
44397
|
-
const initPromise = new Promise((
|
|
44398
|
-
initResolve =
|
|
44752
|
+
const initPromise = new Promise((resolve17, reject) => {
|
|
44753
|
+
initResolve = resolve17;
|
|
44399
44754
|
initReject = reject;
|
|
44400
44755
|
});
|
|
44401
44756
|
_cache.set(key, {
|
|
@@ -44416,8 +44771,8 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44416
44771
|
try {
|
|
44417
44772
|
execution?.assertActive();
|
|
44418
44773
|
log15.debug({ scope, dbPath: normalizedPath }, "opening dual-scope cleo.db");
|
|
44419
|
-
const dir =
|
|
44420
|
-
if (!
|
|
44774
|
+
const dir = dirname18(normalizedPath);
|
|
44775
|
+
if (!existsSync28(dir)) {
|
|
44421
44776
|
mkdirSync8(dir, { recursive: true });
|
|
44422
44777
|
}
|
|
44423
44778
|
execution?.assertActive();
|
|
@@ -44425,6 +44780,7 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44425
44780
|
const nativeDb = new DatabaseSyncCtor(normalizedPath, { allowExtension: true });
|
|
44426
44781
|
openingNative = nativeDb;
|
|
44427
44782
|
applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
|
|
44783
|
+
installSchemaWriteGuard(nativeDb);
|
|
44428
44784
|
const drizzle2 = getDrizzle();
|
|
44429
44785
|
const db = drizzle2({ client: nativeDb });
|
|
44430
44786
|
const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
|
|
@@ -44555,12 +44911,13 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44555
44911
|
execution?.assertActive();
|
|
44556
44912
|
initResolve(finalHandle);
|
|
44557
44913
|
} catch (err) {
|
|
44914
|
+
const explained = openingNative ? explainSchemaWriteDenial(openingNative, err) : err;
|
|
44558
44915
|
try {
|
|
44559
44916
|
if (!published && openingNative?.isOpen) openingNative.close();
|
|
44560
44917
|
} catch (closeError) {
|
|
44561
44918
|
log15.warn({ closeError }, "failed to close unpublished database initializer");
|
|
44562
44919
|
}
|
|
44563
|
-
initReject(
|
|
44920
|
+
initReject(explained);
|
|
44564
44921
|
}
|
|
44565
44922
|
})();
|
|
44566
44923
|
return initPromise;
|
|
@@ -44633,6 +44990,7 @@ var init_dual_scope_db = __esm({
|
|
|
44633
44990
|
init_relocated_store_guard();
|
|
44634
44991
|
init_resolve_migrations_folder();
|
|
44635
44992
|
init_sqlite_pragmas();
|
|
44993
|
+
init_worktree_build_guard();
|
|
44636
44994
|
init_worktree_isolation_guard();
|
|
44637
44995
|
init_writer_lease();
|
|
44638
44996
|
ExodusAbortWriteUnsafeError = class extends Error {
|
|
@@ -44655,7 +45013,7 @@ var init_dual_scope_db = __esm({
|
|
|
44655
45013
|
}
|
|
44656
45014
|
};
|
|
44657
45015
|
_cache = /* @__PURE__ */ new Map();
|
|
44658
|
-
_require6 =
|
|
45016
|
+
_require6 = createRequire10(import.meta.url);
|
|
44659
45017
|
_drizzle4 = null;
|
|
44660
45018
|
_DatabaseSyncCtor = null;
|
|
44661
45019
|
EntryCancelledError = class extends Error {
|
|
@@ -44686,7 +45044,7 @@ var init_dual_scope_db = __esm({
|
|
|
44686
45044
|
}
|
|
44687
45045
|
/** @inheritdoc */
|
|
44688
45046
|
async openProject(dbPath, options) {
|
|
44689
|
-
const normalized =
|
|
45047
|
+
const normalized = resolve14(dbPath);
|
|
44690
45048
|
if (options?.dedicated) {
|
|
44691
45049
|
const handle = await openDualScopeDbAtPath("project", normalized, options?.exodusCwd, {
|
|
44692
45050
|
dedicated: true
|
|
@@ -44698,7 +45056,7 @@ var init_dual_scope_db = __esm({
|
|
|
44698
45056
|
/** @inheritdoc */
|
|
44699
45057
|
async openGlobal(options) {
|
|
44700
45058
|
const dbPath = resolveDualScopeDbPath("global");
|
|
44701
|
-
const normalized =
|
|
45059
|
+
const normalized = resolve14(dbPath);
|
|
44702
45060
|
if (options?.dedicated) {
|
|
44703
45061
|
const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
|
|
44704
45062
|
dedicated: true
|
|
@@ -44709,7 +45067,7 @@ var init_dual_scope_db = __esm({
|
|
|
44709
45067
|
}
|
|
44710
45068
|
/** @inheritdoc */
|
|
44711
45069
|
async openGlobalAt(dbPath, options) {
|
|
44712
|
-
const normalized =
|
|
45070
|
+
const normalized = resolve14(dbPath);
|
|
44713
45071
|
if (options?.dedicated) {
|
|
44714
45072
|
const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
|
|
44715
45073
|
dedicated: true
|
|
@@ -44720,7 +45078,7 @@ var init_dual_scope_db = __esm({
|
|
|
44720
45078
|
}
|
|
44721
45079
|
/** @inheritdoc */
|
|
44722
45080
|
closeProject(dbPath) {
|
|
44723
|
-
const normalized =
|
|
45081
|
+
const normalized = resolve14(dbPath);
|
|
44724
45082
|
this.closeEntry("project", normalized);
|
|
44725
45083
|
}
|
|
44726
45084
|
/** @inheritdoc */
|
|
@@ -44757,8 +45115,8 @@ var init_dual_scope_db = __esm({
|
|
|
44757
45115
|
const entryId = ++this._nextId;
|
|
44758
45116
|
let initResolve;
|
|
44759
45117
|
let initReject;
|
|
44760
|
-
const initPromise = new Promise((
|
|
44761
|
-
initResolve =
|
|
45118
|
+
const initPromise = new Promise((resolve17, reject) => {
|
|
45119
|
+
initResolve = resolve17;
|
|
44762
45120
|
initReject = reject;
|
|
44763
45121
|
});
|
|
44764
45122
|
this._registry.set(key, { id: entryId, store: null, initPromise });
|
|
@@ -45551,8 +45909,8 @@ __export(nexus_sqlite_exports, {
|
|
|
45551
45909
|
resetNexusDbState: () => resetNexusDbState,
|
|
45552
45910
|
resolveNexusMigrationsFolder: () => resolveNexusMigrationsFolder
|
|
45553
45911
|
});
|
|
45554
|
-
import { copyFileSync as copyFileSync7, existsSync as
|
|
45555
|
-
import { join as
|
|
45912
|
+
import { copyFileSync as copyFileSync7, existsSync as existsSync29 } from "node:fs";
|
|
45913
|
+
import { join as join34 } from "node:path";
|
|
45556
45914
|
function getNexusDbPath(cwd) {
|
|
45557
45915
|
return resolveDualScopeDbPath("project", cwd);
|
|
45558
45916
|
}
|
|
@@ -45588,12 +45946,13 @@ function ensureGlobalRegistryAttached(nativeDb) {
|
|
|
45588
45946
|
}
|
|
45589
45947
|
}
|
|
45590
45948
|
nativeDb.exec(`ATTACH DATABASE '${escaped}' AS ${NEXUS_GLOBAL_ATTACH_ALIAS}`);
|
|
45949
|
+
refreshSchemaWriteGuard(nativeDb);
|
|
45591
45950
|
}
|
|
45592
45951
|
function resolveNexusMigrationsFolder() {
|
|
45593
45952
|
return resolveCorePackageMigrationsFolder("drizzle-nexus");
|
|
45594
45953
|
}
|
|
45595
45954
|
function getNestedNexusSentinelPath() {
|
|
45596
|
-
return
|
|
45955
|
+
return join34(getCleoHome(), "nexus", NESTED_NEXUS_SENTINEL);
|
|
45597
45956
|
}
|
|
45598
45957
|
function detectAndWarnOnNestedNexus() {
|
|
45599
45958
|
let nestedPath;
|
|
@@ -45602,7 +45961,7 @@ function detectAndWarnOnNestedNexus() {
|
|
|
45602
45961
|
} catch {
|
|
45603
45962
|
return false;
|
|
45604
45963
|
}
|
|
45605
|
-
if (!
|
|
45964
|
+
if (!existsSync29(nestedPath)) return false;
|
|
45606
45965
|
if (_warnedNestedPaths.has(nestedPath)) return false;
|
|
45607
45966
|
_warnedNestedPaths.add(nestedPath);
|
|
45608
45967
|
const canonicalPath = getNexusDbPath();
|
|
@@ -45761,7 +46120,7 @@ function runNexusMigrations(nativeDb, db, dbPath) {
|
|
|
45761
46120
|
const migrationsFolder = resolveNexusMigrationsFolder();
|
|
45762
46121
|
if (tableExists4(nativeDb, "nexus_nodes")) {
|
|
45763
46122
|
const backupPath = dbPath.replace(/\.db$/, "-pre-cleo.db.bak");
|
|
45764
|
-
if (!
|
|
46123
|
+
if (!existsSync29(backupPath)) {
|
|
45765
46124
|
try {
|
|
45766
46125
|
copyFileSync7(dbPath, backupPath);
|
|
45767
46126
|
} catch {
|
|
@@ -45856,6 +46215,7 @@ var init_nexus_sqlite = __esm({
|
|
|
45856
46215
|
init_resolve_migrations_folder();
|
|
45857
46216
|
init_nexus_schema();
|
|
45858
46217
|
init_with_retry();
|
|
46218
|
+
init_worktree_build_guard();
|
|
45859
46219
|
NEXUS_SCHEMA_VERSION = "1.0.0";
|
|
45860
46220
|
NEXUS_GLOBAL_ATTACH_ALIAS = "nexus_global";
|
|
45861
46221
|
NESTED_NEXUS_SENTINEL = "nexus.db";
|
|
@@ -45890,15 +46250,15 @@ var init_legacy_alias = __esm({
|
|
|
45890
46250
|
|
|
45891
46251
|
// packages/core/src/llm/stable-device-id.ts
|
|
45892
46252
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
45893
|
-
import { existsSync as
|
|
45894
|
-
import { dirname as
|
|
46253
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync9, readFileSync as readFileSync10, renameSync as renameSync9, writeFileSync as writeFileSync8 } from "node:fs";
|
|
46254
|
+
import { dirname as dirname19 } from "node:path";
|
|
45895
46255
|
import { resolveStableDeviceIdPath } from "@cleocode/paths";
|
|
45896
46256
|
function getStableDeviceId() {
|
|
45897
46257
|
if (_cachedDeviceId !== null) return _cachedDeviceId;
|
|
45898
46258
|
const path = resolveStableDeviceIdPath();
|
|
45899
|
-
if (
|
|
46259
|
+
if (existsSync30(path)) {
|
|
45900
46260
|
try {
|
|
45901
|
-
const raw =
|
|
46261
|
+
const raw = readFileSync10(path, "utf-8").trim();
|
|
45902
46262
|
if (raw.length > 0) {
|
|
45903
46263
|
_cachedDeviceId = raw;
|
|
45904
46264
|
return raw;
|
|
@@ -45908,8 +46268,8 @@ function getStableDeviceId() {
|
|
|
45908
46268
|
}
|
|
45909
46269
|
const fresh = randomUUID3();
|
|
45910
46270
|
try {
|
|
45911
|
-
const dir =
|
|
45912
|
-
if (!
|
|
46271
|
+
const dir = dirname19(path);
|
|
46272
|
+
if (!existsSync30(dir)) {
|
|
45913
46273
|
mkdirSync9(dir, { recursive: true });
|
|
45914
46274
|
}
|
|
45915
46275
|
const tmpPath = `${path}.tmp.${process.pid}`;
|
|
@@ -45946,8 +46306,8 @@ var init_registry_roots = __esm({
|
|
|
45946
46306
|
// packages/core/src/nexus/projects-scan.ts
|
|
45947
46307
|
async function withinBudget(promise2, ms) {
|
|
45948
46308
|
let timer;
|
|
45949
|
-
const expiry = new Promise((
|
|
45950
|
-
timer = setTimeout(() =>
|
|
46309
|
+
const expiry = new Promise((resolve17) => {
|
|
46310
|
+
timer = setTimeout(() => resolve17("timeout"), ms);
|
|
45951
46311
|
timer.unref();
|
|
45952
46312
|
});
|
|
45953
46313
|
try {
|
|
@@ -45985,9 +46345,9 @@ __export(path_map_exports, {
|
|
|
45985
46345
|
supersededRegistryPath: () => supersededRegistryPath,
|
|
45986
46346
|
touchProjectLocation: () => touchProjectLocation
|
|
45987
46347
|
});
|
|
45988
|
-
import { existsSync as
|
|
46348
|
+
import { existsSync as existsSync31, lstatSync, readdirSync as readdirSync7 } from "node:fs";
|
|
45989
46349
|
import { lstat, readdir as readdir2 } from "node:fs/promises";
|
|
45990
|
-
import { isAbsolute as
|
|
46350
|
+
import { isAbsolute as isAbsolute5, join as join35, relative as relative3, sep as sep5 } from "node:path";
|
|
45991
46351
|
import { canonicalizePath as canonicalizePath3, readDeclaredProjectIdentity as readDeclaredProjectIdentity3 } from "@cleocode/paths";
|
|
45992
46352
|
import { and as and7, desc as desc3, eq as eq11, inArray as inArray5, ne as ne3 } from "drizzle-orm";
|
|
45993
46353
|
function holdingKey(projectId, path) {
|
|
@@ -46003,7 +46363,7 @@ function isSupersededRegistryPath(projectPath) {
|
|
|
46003
46363
|
return projectPath.startsWith(SUPERSEDED_PATH_PREFIX);
|
|
46004
46364
|
}
|
|
46005
46365
|
function projectHolding(path, projectId) {
|
|
46006
|
-
const cleoDir =
|
|
46366
|
+
const cleoDir = join35(path, ".cleo");
|
|
46007
46367
|
try {
|
|
46008
46368
|
lstatSync(cleoDir);
|
|
46009
46369
|
readdirSync7(cleoDir);
|
|
@@ -46015,7 +46375,7 @@ function projectHolding(path, projectId) {
|
|
|
46015
46375
|
return declared === null || declared.projectId === projectId ? "yes" : "no";
|
|
46016
46376
|
}
|
|
46017
46377
|
async function probeProjectHolding(path, projectId, timeoutMs) {
|
|
46018
|
-
const cleoDir =
|
|
46378
|
+
const cleoDir = join35(path, ".cleo");
|
|
46019
46379
|
const probe = async () => {
|
|
46020
46380
|
try {
|
|
46021
46381
|
await lstat(cleoDir);
|
|
@@ -46033,8 +46393,8 @@ async function probeProjectHolding(path, projectId, timeoutMs) {
|
|
|
46033
46393
|
return declared === null || declared.projectId === projectId ? "yes" : "no";
|
|
46034
46394
|
}
|
|
46035
46395
|
function isStrictlyInside(outer, inner) {
|
|
46036
|
-
const rel =
|
|
46037
|
-
return rel.length > 0 && rel !== ".." && !rel.startsWith(`..${
|
|
46396
|
+
const rel = relative3(canonicalizePath3(outer), canonicalizePath3(inner));
|
|
46397
|
+
return rel.length > 0 && rel !== ".." && !rel.startsWith(`..${sep5}`) && !isAbsolute5(rel);
|
|
46038
46398
|
}
|
|
46039
46399
|
function locationKey(projectId, deviceId, path) {
|
|
46040
46400
|
return and7(
|
|
@@ -46196,7 +46556,7 @@ function hasOtherLiveLocation(db, record2, deviceId) {
|
|
|
46196
46556
|
ne3(projectLocations.path, record2.projectPath)
|
|
46197
46557
|
)
|
|
46198
46558
|
).all().some(
|
|
46199
|
-
(location) => isStrictlyInside(record2.projectPath, location.path) &&
|
|
46559
|
+
(location) => isStrictlyInside(record2.projectPath, location.path) && existsSync31(location.path) && readDeclaredProjectIdentity3(location.path)?.projectId === record2.projectId
|
|
46200
46560
|
);
|
|
46201
46561
|
}
|
|
46202
46562
|
function demoteProjectLocation(db, record2, state) {
|
|
@@ -46247,7 +46607,7 @@ function rehomeDisplacedRows(db, projectId, projectPath, deviceId, probed) {
|
|
|
46247
46607
|
).orderBy(desc3(projectLocations.lastSeen)).all();
|
|
46248
46608
|
const present = (path) => {
|
|
46249
46609
|
const holding = probed?.get(holdingKey(row.projectId, path));
|
|
46250
|
-
return holding === void 0 ?
|
|
46610
|
+
return holding === void 0 ? existsSync31(path) : holding === "yes";
|
|
46251
46611
|
};
|
|
46252
46612
|
const home = candidates.find(
|
|
46253
46613
|
(c) => present(c.path) && db.select({ projectId: projectRegistry.projectId }).from(projectRegistry).where(eq11(projectRegistry.projectPath, c.path)).all().length === 0
|
|
@@ -46276,7 +46636,7 @@ async function listProjectCheckouts(projectId, opts = {}) {
|
|
|
46276
46636
|
projectHash: generateProjectHash(row.path),
|
|
46277
46637
|
firstSeen: row.firstSeen,
|
|
46278
46638
|
lastSeen: row.lastSeen,
|
|
46279
|
-
exists: local &&
|
|
46639
|
+
exists: local && existsSync31(row.path),
|
|
46280
46640
|
deviceId: local ? deviceId : row.deviceId,
|
|
46281
46641
|
state: row.state
|
|
46282
46642
|
});
|
|
@@ -46305,13 +46665,13 @@ __export(checkout_nonce_exports, {
|
|
|
46305
46665
|
readCheckoutNonce: () => readCheckoutNonce
|
|
46306
46666
|
});
|
|
46307
46667
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
46308
|
-
import { existsSync as
|
|
46309
|
-
import { join as
|
|
46668
|
+
import { existsSync as existsSync32, readFileSync as readFileSync11, renameSync as renameSync10, writeFileSync as writeFileSync9 } from "node:fs";
|
|
46669
|
+
import { join as join36 } from "node:path";
|
|
46310
46670
|
function readInfo(projectRoot) {
|
|
46311
|
-
const path =
|
|
46312
|
-
if (!
|
|
46671
|
+
const path = join36(projectRoot, ".cleo", "project-info.json");
|
|
46672
|
+
if (!existsSync32(path)) return null;
|
|
46313
46673
|
try {
|
|
46314
|
-
const parsed = JSON.parse(
|
|
46674
|
+
const parsed = JSON.parse(readFileSync11(path, "utf-8"));
|
|
46315
46675
|
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
46316
46676
|
} catch {
|
|
46317
46677
|
return null;
|
|
@@ -46327,7 +46687,7 @@ function ensureCheckoutNonce(projectRoot) {
|
|
|
46327
46687
|
const info = readInfo(projectRoot);
|
|
46328
46688
|
if (!info) return null;
|
|
46329
46689
|
const nonce = randomBytes2(16).toString("hex");
|
|
46330
|
-
const path =
|
|
46690
|
+
const path = join36(projectRoot, ".cleo", "project-info.json");
|
|
46331
46691
|
const temp = `${path}.${randomBytes2(6).toString("hex")}.tmp`;
|
|
46332
46692
|
writeFileSync9(temp, `${JSON.stringify({ ...info, [CHECKOUT_NONCE_FIELD]: nonce }, null, 2)}
|
|
46333
46693
|
`);
|
|
@@ -46402,10 +46762,10 @@ __export(paths_exports, {
|
|
|
46402
46762
|
validateProjectRoot: () => validateProjectRoot,
|
|
46403
46763
|
worktreeScope: () => worktreeScope
|
|
46404
46764
|
});
|
|
46405
|
-
import { existsSync as
|
|
46406
|
-
import { createRequire as
|
|
46765
|
+
import { existsSync as existsSync33, readFileSync as readFileSync12, statSync as statSync9 } from "node:fs";
|
|
46766
|
+
import { createRequire as createRequire11 } from "node:module";
|
|
46407
46767
|
import { homedir as homedir2 } from "node:os";
|
|
46408
|
-
import { basename as basename10, dirname as
|
|
46768
|
+
import { basename as basename10, dirname as dirname20, join as join37, resolve as resolve15 } from "node:path";
|
|
46409
46769
|
import {
|
|
46410
46770
|
getCanonicalTemplatesTildePath as _getCanonicalTemplatesTildePath,
|
|
46411
46771
|
getCleoTemplatesTildePath as _getCleoTemplatesTildePath,
|
|
@@ -46415,7 +46775,7 @@ import {
|
|
|
46415
46775
|
resolveCanonicalCleoDir as _resolveCanonicalCleoDir
|
|
46416
46776
|
} from "@cleocode/paths";
|
|
46417
46777
|
function _getDatabaseSyncCtor() {
|
|
46418
|
-
const _require7 =
|
|
46778
|
+
const _require7 = createRequire11(import.meta.url);
|
|
46419
46779
|
const mod = _require7("node:sqlite");
|
|
46420
46780
|
return mod.DatabaseSync;
|
|
46421
46781
|
}
|
|
@@ -46427,20 +46787,20 @@ function runWithWorktreeScopeFromEnv(fn) {
|
|
|
46427
46787
|
}
|
|
46428
46788
|
function isProjectInitialized(projectRoot) {
|
|
46429
46789
|
const root = projectRoot ?? getProjectRoot();
|
|
46430
|
-
const cleoDir =
|
|
46431
|
-
return
|
|
46790
|
+
const cleoDir = join37(root, ".cleo");
|
|
46791
|
+
return existsSync33(cleoDir) && existsSync33(join37(cleoDir, "tasks.db"));
|
|
46432
46792
|
}
|
|
46433
46793
|
function getCleoHome() {
|
|
46434
46794
|
return getPlatformPaths().data;
|
|
46435
46795
|
}
|
|
46436
46796
|
function getCleoTemplatesDir() {
|
|
46437
|
-
return
|
|
46797
|
+
return join37(getCleoHome(), "templates");
|
|
46438
46798
|
}
|
|
46439
46799
|
function getCleoSchemasDir() {
|
|
46440
|
-
return
|
|
46800
|
+
return join37(getCleoHome(), "schemas");
|
|
46441
46801
|
}
|
|
46442
46802
|
function getCleoDocsDir() {
|
|
46443
|
-
return
|
|
46803
|
+
return join37(getCleoHome(), "docs");
|
|
46444
46804
|
}
|
|
46445
46805
|
function getCleoDir(cwd) {
|
|
46446
46806
|
if (cwd) {
|
|
@@ -46489,24 +46849,24 @@ function getCleoDirAbsolute(cwd, opts) {
|
|
|
46489
46849
|
try {
|
|
46490
46850
|
const projectRoot = getProjectRoot(cwd);
|
|
46491
46851
|
const canonical = _resolveCanonicalCleoDir(project.projectId);
|
|
46492
|
-
if (canonical !== null && canonical ===
|
|
46852
|
+
if (canonical !== null && canonical === resolve15(projectRoot, cleoDir)) {
|
|
46493
46853
|
return canonical;
|
|
46494
46854
|
}
|
|
46495
|
-
return
|
|
46855
|
+
return resolve15(projectRoot, cleoDir);
|
|
46496
46856
|
} catch {
|
|
46497
|
-
return
|
|
46857
|
+
return resolve15(project.projectRoot, cleoDir);
|
|
46498
46858
|
}
|
|
46499
46859
|
}
|
|
46500
46860
|
try {
|
|
46501
|
-
return
|
|
46861
|
+
return resolve15(getProjectRoot(cwd), cleoDir);
|
|
46502
46862
|
} catch (err) {
|
|
46503
46863
|
if (opts?.bootstrap) {
|
|
46504
|
-
return
|
|
46864
|
+
return resolve15(cwd ?? process.cwd(), cleoDir);
|
|
46505
46865
|
}
|
|
46506
46866
|
if (_cwdHasGitAncestor(cwd)) {
|
|
46507
46867
|
throw err;
|
|
46508
46868
|
}
|
|
46509
|
-
return
|
|
46869
|
+
return resolve15(cwd ?? process.cwd(), cleoDir);
|
|
46510
46870
|
}
|
|
46511
46871
|
}
|
|
46512
46872
|
function resolveCanonicalCleoDir(projectId) {
|
|
@@ -46533,9 +46893,9 @@ function resolveCanonicalCleoDir(projectId) {
|
|
|
46533
46893
|
function _resolveProjectByCwdFromNexus(cwd) {
|
|
46534
46894
|
try {
|
|
46535
46895
|
const cleoHome = getCleoHome();
|
|
46536
|
-
const globalDbPath =
|
|
46537
|
-
if (!
|
|
46538
|
-
const start =
|
|
46896
|
+
const globalDbPath = join37(cleoHome, "cleo.db");
|
|
46897
|
+
if (!existsSync33(globalDbPath)) return null;
|
|
46898
|
+
const start = resolve15(cwd ?? process.cwd());
|
|
46539
46899
|
let current = start;
|
|
46540
46900
|
const DatabaseSync3 = _getDatabaseSyncCtor();
|
|
46541
46901
|
const db = new DatabaseSync3(globalDbPath, { readOnly: true });
|
|
@@ -46548,7 +46908,7 @@ function _resolveProjectByCwdFromNexus(cwd) {
|
|
|
46548
46908
|
if (row && typeof row.project_id === "string" && row.project_id.length > 0) {
|
|
46549
46909
|
return row.project_id;
|
|
46550
46910
|
}
|
|
46551
|
-
const parent =
|
|
46911
|
+
const parent = dirname20(current);
|
|
46552
46912
|
if (parent === current) break;
|
|
46553
46913
|
current = parent;
|
|
46554
46914
|
}
|
|
@@ -46568,18 +46928,18 @@ function _cleoDirEnvOverride() {
|
|
|
46568
46928
|
}
|
|
46569
46929
|
function _findCleoDirRoot(cwd) {
|
|
46570
46930
|
const homeRoot = homedir2();
|
|
46571
|
-
let current =
|
|
46931
|
+
let current = resolve15(cwd ?? process.cwd());
|
|
46572
46932
|
while (true) {
|
|
46573
46933
|
const isDangerousRoot = current === homeRoot || current === "/" || current === "";
|
|
46574
46934
|
if (!isDangerousRoot) {
|
|
46575
46935
|
try {
|
|
46576
|
-
if (statSync9(
|
|
46936
|
+
if (statSync9(join37(current, ".cleo")).isDirectory()) {
|
|
46577
46937
|
return current;
|
|
46578
46938
|
}
|
|
46579
46939
|
} catch {
|
|
46580
46940
|
}
|
|
46581
46941
|
}
|
|
46582
|
-
const parent =
|
|
46942
|
+
const parent = dirname20(current);
|
|
46583
46943
|
if (parent === current) break;
|
|
46584
46944
|
current = parent;
|
|
46585
46945
|
}
|
|
@@ -46598,7 +46958,7 @@ function resolveProjectByCwd(cwd) {
|
|
|
46598
46958
|
if (pathsResult !== null) {
|
|
46599
46959
|
return pathsResult.projectId;
|
|
46600
46960
|
}
|
|
46601
|
-
const start =
|
|
46961
|
+
const start = resolve15(from ?? process.cwd());
|
|
46602
46962
|
let current = start;
|
|
46603
46963
|
while (true) {
|
|
46604
46964
|
const mainRepo = _resolveMainRepoFromGitlink(current);
|
|
@@ -46609,7 +46969,7 @@ function resolveProjectByCwd(cwd) {
|
|
|
46609
46969
|
}
|
|
46610
46970
|
break;
|
|
46611
46971
|
}
|
|
46612
|
-
const parent =
|
|
46972
|
+
const parent = dirname20(current);
|
|
46613
46973
|
if (parent === current) break;
|
|
46614
46974
|
current = parent;
|
|
46615
46975
|
}
|
|
@@ -46628,7 +46988,7 @@ function resolveProjectByCwd(cwd) {
|
|
|
46628
46988
|
function resolveCleoDir(cwd) {
|
|
46629
46989
|
const scope = worktreeScope.getStore();
|
|
46630
46990
|
if (scope !== void 0) {
|
|
46631
|
-
return
|
|
46991
|
+
return join37(resolveStoreOwnerRoot(scope.worktreeRoot), ".cleo");
|
|
46632
46992
|
}
|
|
46633
46993
|
const override = _cleoDirEnvOverride();
|
|
46634
46994
|
if (override !== null) {
|
|
@@ -46636,16 +46996,16 @@ function resolveCleoDir(cwd) {
|
|
|
46636
46996
|
}
|
|
46637
46997
|
const root = _findCleoDirRoot(cwd);
|
|
46638
46998
|
if (root !== null) {
|
|
46639
|
-
return
|
|
46999
|
+
return join37(resolveStoreOwnerRoot(root), ".cleo");
|
|
46640
47000
|
}
|
|
46641
|
-
const start =
|
|
47001
|
+
const start = resolve15(cwd ?? process.cwd());
|
|
46642
47002
|
let current = start;
|
|
46643
47003
|
while (true) {
|
|
46644
47004
|
const mainRepo = _resolveMainRepoFromGitlink(current);
|
|
46645
47005
|
if (mainRepo !== null) {
|
|
46646
|
-
return
|
|
47006
|
+
return join37(mainRepo, ".cleo");
|
|
46647
47007
|
}
|
|
46648
|
-
const parent =
|
|
47008
|
+
const parent = dirname20(current);
|
|
46649
47009
|
if (parent === current) {
|
|
46650
47010
|
break;
|
|
46651
47011
|
}
|
|
@@ -46684,25 +47044,25 @@ function _resolveCleoDir(cwd) {
|
|
|
46684
47044
|
const project = _pathsResolveProjectByCwd(cwd);
|
|
46685
47045
|
if (project !== null) {
|
|
46686
47046
|
try {
|
|
46687
|
-
return
|
|
47047
|
+
return resolve15(getProjectRoot(cwd), cleoDir);
|
|
46688
47048
|
} catch {
|
|
46689
|
-
return
|
|
47049
|
+
return resolve15(project.projectRoot, cleoDir);
|
|
46690
47050
|
}
|
|
46691
47051
|
}
|
|
46692
47052
|
return getCleoDirAbsolute(cwd);
|
|
46693
47053
|
}
|
|
46694
47054
|
function _cwdHasGitAncestor(cwd) {
|
|
46695
|
-
const start =
|
|
47055
|
+
const start = resolve15(cwd ?? process.cwd());
|
|
46696
47056
|
let current = start;
|
|
46697
47057
|
while (true) {
|
|
46698
|
-
const gitMarker =
|
|
47058
|
+
const gitMarker = join37(current, ".git");
|
|
46699
47059
|
try {
|
|
46700
|
-
if (
|
|
47060
|
+
if (existsSync33(gitMarker)) {
|
|
46701
47061
|
return true;
|
|
46702
47062
|
}
|
|
46703
47063
|
} catch {
|
|
46704
47064
|
}
|
|
46705
|
-
const parent =
|
|
47065
|
+
const parent = dirname20(current);
|
|
46706
47066
|
if (parent === current) return false;
|
|
46707
47067
|
current = parent;
|
|
46708
47068
|
}
|
|
@@ -46729,55 +47089,55 @@ function resolveProjectPath(relativePath, cwd) {
|
|
|
46729
47089
|
return relativePath;
|
|
46730
47090
|
}
|
|
46731
47091
|
if (relativePath.startsWith("~/") || relativePath.startsWith("~\\") || relativePath === "~") {
|
|
46732
|
-
return
|
|
47092
|
+
return resolve15(homedir2(), relativePath.slice(2));
|
|
46733
47093
|
}
|
|
46734
|
-
return
|
|
47094
|
+
return resolve15(getProjectRoot(cwd), relativePath);
|
|
46735
47095
|
}
|
|
46736
47096
|
function getTaskPath(cwd) {
|
|
46737
|
-
return
|
|
47097
|
+
return join37(_resolveCleoDir(cwd), "tasks.db");
|
|
46738
47098
|
}
|
|
46739
47099
|
function getConfigPath(cwd) {
|
|
46740
|
-
return
|
|
47100
|
+
return join37(_resolveCleoDir(cwd), "config.json");
|
|
46741
47101
|
}
|
|
46742
47102
|
function getSessionsPath(cwd) {
|
|
46743
|
-
return
|
|
47103
|
+
return join37(_resolveCleoDir(cwd), "sessions.json");
|
|
46744
47104
|
}
|
|
46745
47105
|
function getArchivePath(cwd) {
|
|
46746
|
-
return
|
|
47106
|
+
return join37(_resolveCleoDir(cwd), "tasks-archive.json");
|
|
46747
47107
|
}
|
|
46748
47108
|
function getLogPath(cwd) {
|
|
46749
|
-
return
|
|
47109
|
+
return join37(_resolveCleoDir(cwd), "logs", "cleo.log");
|
|
46750
47110
|
}
|
|
46751
47111
|
function getBackupDir(cwd) {
|
|
46752
|
-
return
|
|
47112
|
+
return join37(_resolveCleoDir(cwd), "backups", "operational");
|
|
46753
47113
|
}
|
|
46754
47114
|
function getGlobalConfigPath() {
|
|
46755
|
-
return
|
|
47115
|
+
return join37(getCleoHome(), "config.json");
|
|
46756
47116
|
}
|
|
46757
47117
|
function getCleoGlobalRecipesDir() {
|
|
46758
|
-
return
|
|
47118
|
+
return join37(getCleoHome(), "global-recipes");
|
|
46759
47119
|
}
|
|
46760
47120
|
function getCleoGlobalJustfilePath() {
|
|
46761
|
-
return
|
|
47121
|
+
return join37(getCleoGlobalRecipesDir(), "justfile");
|
|
46762
47122
|
}
|
|
46763
47123
|
function getCleoPiExtensionsDir() {
|
|
46764
|
-
return
|
|
47124
|
+
return join37(getCleoHome(), "pi-extensions");
|
|
46765
47125
|
}
|
|
46766
47126
|
function getCleoCantWorkflowsDir() {
|
|
46767
|
-
return
|
|
47127
|
+
return join37(getCleoHome(), "cant-workflows");
|
|
46768
47128
|
}
|
|
46769
47129
|
function getCleoGlobalAgentsDir() {
|
|
46770
|
-
return
|
|
47130
|
+
return join37(getCleoHome(), "agents");
|
|
46771
47131
|
}
|
|
46772
47132
|
function getCleoGlobalCantAgentsDir() {
|
|
46773
|
-
return
|
|
47133
|
+
return join37(getCleoHome(), "cant", "agents");
|
|
46774
47134
|
}
|
|
46775
47135
|
function getAgentOutputsDir(cwd) {
|
|
46776
47136
|
const projectRoot = getProjectRoot(cwd);
|
|
46777
|
-
const configPath =
|
|
46778
|
-
if (
|
|
47137
|
+
const configPath = join37(projectRoot, ".cleo", "config.json");
|
|
47138
|
+
if (existsSync33(configPath)) {
|
|
46779
47139
|
try {
|
|
46780
|
-
const config2 = JSON.parse(
|
|
47140
|
+
const config2 = JSON.parse(readFileSync12(configPath, "utf-8"));
|
|
46781
47141
|
if (typeof config2.agentOutputs === "object" && config2.agentOutputs?.directory) {
|
|
46782
47142
|
return config2.agentOutputs.directory;
|
|
46783
47143
|
}
|
|
@@ -46800,17 +47160,17 @@ function getAgentOutputsAbsolute(cwd) {
|
|
|
46800
47160
|
if (isAbsolutePath2(dir)) {
|
|
46801
47161
|
return dir;
|
|
46802
47162
|
}
|
|
46803
|
-
return
|
|
47163
|
+
return resolve15(getProjectRoot(cwd), dir);
|
|
46804
47164
|
}
|
|
46805
47165
|
function getManifestPath(cwd) {
|
|
46806
47166
|
const outputDir = getAgentOutputsDir(cwd);
|
|
46807
47167
|
const projectRoot = getProjectRoot(cwd);
|
|
46808
|
-
const configPath =
|
|
47168
|
+
const configPath = join37(projectRoot, ".cleo", "config.json");
|
|
46809
47169
|
const legacyFileName = ["MANIFEST", "jsonl"].join(".");
|
|
46810
47170
|
let manifestFile = legacyFileName;
|
|
46811
|
-
if (
|
|
47171
|
+
if (existsSync33(configPath)) {
|
|
46812
47172
|
try {
|
|
46813
|
-
const config2 = JSON.parse(
|
|
47173
|
+
const config2 = JSON.parse(readFileSync12(configPath, "utf-8"));
|
|
46814
47174
|
const customFile = config2.agentOutputs?.manifestFile ?? config2.research?.manifestFile;
|
|
46815
47175
|
if (customFile) {
|
|
46816
47176
|
manifestFile = customFile;
|
|
@@ -46818,12 +47178,12 @@ function getManifestPath(cwd) {
|
|
|
46818
47178
|
} catch {
|
|
46819
47179
|
}
|
|
46820
47180
|
}
|
|
46821
|
-
return
|
|
47181
|
+
return resolve15(projectRoot, outputDir, manifestFile);
|
|
46822
47182
|
}
|
|
46823
47183
|
function getManifestArchivePath(cwd) {
|
|
46824
47184
|
const outputDir = getAgentOutputsDir(cwd);
|
|
46825
47185
|
const projectRoot = getProjectRoot(cwd);
|
|
46826
|
-
return
|
|
47186
|
+
return resolve15(projectRoot, outputDir, "MANIFEST.archive.jsonl");
|
|
46827
47187
|
}
|
|
46828
47188
|
function isAbsolutePath2(path) {
|
|
46829
47189
|
return _isAbsolutePath(path);
|
|
@@ -46847,24 +47207,24 @@ function getCanonicalTemplatesTildePath() {
|
|
|
46847
47207
|
return _getCanonicalTemplatesTildePath();
|
|
46848
47208
|
}
|
|
46849
47209
|
function getAgentsHome() {
|
|
46850
|
-
return process.env["AGENTS_HOME"] ??
|
|
47210
|
+
return process.env["AGENTS_HOME"] ?? join37(homedir2(), ".agents");
|
|
46851
47211
|
}
|
|
46852
47212
|
function getClaudeAgentsDir() {
|
|
46853
|
-
const claudeDir = process.env["CLAUDE_HOME"] ??
|
|
46854
|
-
return
|
|
47213
|
+
const claudeDir = process.env["CLAUDE_HOME"] ?? join37(homedir2(), ".claude");
|
|
47214
|
+
return join37(claudeDir, "agents");
|
|
46855
47215
|
}
|
|
46856
47216
|
function getClaudeMemDbPath() {
|
|
46857
|
-
return process.env["CLAUDE_MEM_DB"] ??
|
|
47217
|
+
return process.env["CLAUDE_MEM_DB"] ?? join37(homedir2(), ".claude-mem", "claude-mem.db");
|
|
46858
47218
|
}
|
|
46859
47219
|
function resolveWorktreeRouting(cwdOverride) {
|
|
46860
|
-
const cwd =
|
|
47220
|
+
const cwd = resolve15(cwdOverride ?? process.cwd());
|
|
46861
47221
|
const home = homedir2();
|
|
46862
47222
|
let worktreePath;
|
|
46863
47223
|
let current = cwd;
|
|
46864
47224
|
while (current !== home && current !== "/" && current !== "") {
|
|
46865
|
-
const gitPath =
|
|
47225
|
+
const gitPath = join37(current, ".git");
|
|
46866
47226
|
try {
|
|
46867
|
-
if (
|
|
47227
|
+
if (existsSync33(gitPath)) {
|
|
46868
47228
|
const stat3 = statSync9(gitPath);
|
|
46869
47229
|
if (stat3.isFile()) {
|
|
46870
47230
|
worktreePath = current;
|
|
@@ -46876,7 +47236,7 @@ function resolveWorktreeRouting(cwdOverride) {
|
|
|
46876
47236
|
}
|
|
46877
47237
|
} catch {
|
|
46878
47238
|
}
|
|
46879
|
-
const parent =
|
|
47239
|
+
const parent = dirname20(current);
|
|
46880
47240
|
if (parent === current) break;
|
|
46881
47241
|
current = parent;
|
|
46882
47242
|
}
|
|
@@ -46893,17 +47253,17 @@ function resolveWorktreeRouting(cwdOverride) {
|
|
|
46893
47253
|
}
|
|
46894
47254
|
function resolveWorktreeFilePath(filePath, routing) {
|
|
46895
47255
|
if (!routing.isWorktree || routing.worktreePath === void 0) {
|
|
46896
|
-
return
|
|
47256
|
+
return resolve15(filePath);
|
|
46897
47257
|
}
|
|
46898
|
-
return
|
|
47258
|
+
return resolve15(routing.cwd, filePath);
|
|
46899
47259
|
}
|
|
46900
47260
|
function detectStrayCleoDb(routing) {
|
|
46901
47261
|
if (!routing.isWorktree || routing.worktreePath === void 0) {
|
|
46902
47262
|
return void 0;
|
|
46903
47263
|
}
|
|
46904
|
-
const tasksDbPath =
|
|
47264
|
+
const tasksDbPath = join37(routing.worktreePath, ".cleo", "tasks.db");
|
|
46905
47265
|
try {
|
|
46906
|
-
if (
|
|
47266
|
+
if (existsSync33(tasksDbPath) && statSync9(tasksDbPath).isFile()) {
|
|
46907
47267
|
return tasksDbPath;
|
|
46908
47268
|
}
|
|
46909
47269
|
} catch {
|
|
@@ -46913,7 +47273,7 @@ function detectStrayCleoDb(routing) {
|
|
|
46913
47273
|
async function resolveProjectById(projectId) {
|
|
46914
47274
|
try {
|
|
46915
47275
|
const { getNexusDb: getNexusDb2, getNexusRegistryDbPath: getNexusRegistryDbPath2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
|
|
46916
|
-
if (!
|
|
47276
|
+
if (!existsSync33(getNexusRegistryDbPath2())) return null;
|
|
46917
47277
|
const { eq: eq12 } = await import("drizzle-orm");
|
|
46918
47278
|
const { projectRegistry: projectRegistry2 } = await Promise.resolve().then(() => (init_nexus_schema(), nexus_schema_exports));
|
|
46919
47279
|
const db = await getNexusDb2();
|
|
@@ -46948,9 +47308,9 @@ function _rowToRegistryEntry(row) {
|
|
|
46948
47308
|
};
|
|
46949
47309
|
}
|
|
46950
47310
|
function _readProjectNameFromInfo(projectRoot) {
|
|
46951
|
-
const infoPath =
|
|
46952
|
-
if (!
|
|
46953
|
-
const raw =
|
|
47311
|
+
const infoPath = join37(projectRoot, ".cleo", "project-info.json");
|
|
47312
|
+
if (!existsSync33(infoPath)) return void 0;
|
|
47313
|
+
const raw = readFileSync12(infoPath, "utf-8");
|
|
46954
47314
|
const data = JSON.parse(raw);
|
|
46955
47315
|
return typeof data.name === "string" && data.name.length > 0 ? data.name : void 0;
|
|
46956
47316
|
}
|
|
@@ -47001,7 +47361,7 @@ async function recordProjectEncounter(cwd) {
|
|
|
47001
47361
|
if (!shouldAutoRegisterProject(project.projectRoot, cleoHome)) return "ephemeral";
|
|
47002
47362
|
const checkout = captureProjectScope(project.projectRoot, worktreeScope.getStore()).worktreeRoot;
|
|
47003
47363
|
const { getNexusRegistryDb: getNexusRegistryDb2, getNexusRegistryDbPath: getNexusRegistryDbPath2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
|
|
47004
|
-
if (
|
|
47364
|
+
if (existsSync33(getNexusRegistryDbPath2(cleoHome))) {
|
|
47005
47365
|
const { and: and8, eq: eq12 } = await import("drizzle-orm");
|
|
47006
47366
|
const { projectLocations: projectLocations2, projectRegistry: projectRegistry2 } = await Promise.resolve().then(() => (init_nexus_schema(), nexus_schema_exports));
|
|
47007
47367
|
const { currentDeviceId: currentDeviceId2 } = await Promise.resolve().then(() => (init_path_map(), path_map_exports));
|
|
@@ -47259,42 +47619,42 @@ var init_api_mode = __esm({
|
|
|
47259
47619
|
// packages/core/src/store/file-utils.ts
|
|
47260
47620
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
47261
47621
|
import {
|
|
47262
|
-
existsSync as
|
|
47622
|
+
existsSync as existsSync34,
|
|
47263
47623
|
mkdirSync as mkdirSync10,
|
|
47264
47624
|
readdirSync as readdirSync8,
|
|
47265
|
-
readFileSync as
|
|
47625
|
+
readFileSync as readFileSync13,
|
|
47266
47626
|
renameSync as renameSync11,
|
|
47267
47627
|
unlinkSync as unlinkSync6,
|
|
47268
47628
|
writeFileSync as writeFileSync10
|
|
47269
47629
|
} from "node:fs";
|
|
47270
|
-
import { basename as basename11, dirname as
|
|
47630
|
+
import { basename as basename11, dirname as dirname21, join as join38 } from "node:path";
|
|
47271
47631
|
import * as lockfile3 from "proper-lockfile";
|
|
47272
47632
|
function rotateBackup(filePath, mode) {
|
|
47273
|
-
const dir =
|
|
47633
|
+
const dir = dirname21(filePath);
|
|
47274
47634
|
const name15 = basename11(filePath);
|
|
47275
|
-
const backupDir =
|
|
47635
|
+
const backupDir = join38(dir, ".backups");
|
|
47276
47636
|
const dirMode = typeof mode === "number" ? modeToDirMode(mode) : void 0;
|
|
47277
|
-
if (!
|
|
47637
|
+
if (!existsSync34(backupDir)) {
|
|
47278
47638
|
mkdirSync10(backupDir, { recursive: true, mode: dirMode });
|
|
47279
47639
|
}
|
|
47280
47640
|
for (let i = MAX_BACKUPS; i >= 1; i--) {
|
|
47281
|
-
const current =
|
|
47641
|
+
const current = join38(backupDir, `${name15}.${i}`);
|
|
47282
47642
|
if (i === MAX_BACKUPS) {
|
|
47283
47643
|
try {
|
|
47284
47644
|
unlinkSync6(current);
|
|
47285
47645
|
} catch {
|
|
47286
47646
|
}
|
|
47287
47647
|
} else {
|
|
47288
|
-
const next =
|
|
47648
|
+
const next = join38(backupDir, `${name15}.${i + 1}`);
|
|
47289
47649
|
try {
|
|
47290
|
-
if (
|
|
47650
|
+
if (existsSync34(current)) renameSync11(current, next);
|
|
47291
47651
|
} catch {
|
|
47292
47652
|
}
|
|
47293
47653
|
}
|
|
47294
47654
|
}
|
|
47295
47655
|
try {
|
|
47296
|
-
const content =
|
|
47297
|
-
const backupPath =
|
|
47656
|
+
const content = readFileSync13(filePath, "utf-8");
|
|
47657
|
+
const backupPath = join38(backupDir, `${name15}.1`);
|
|
47298
47658
|
if (typeof mode === "number") {
|
|
47299
47659
|
writeFileSync10(backupPath, content, { encoding: "utf-8", mode });
|
|
47300
47660
|
} else {
|
|
@@ -47314,8 +47674,8 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
47314
47674
|
const opts = typeof optsOrIndent === "number" ? { indent: optsOrIndent } : optsOrIndent;
|
|
47315
47675
|
const indent = opts.indent ?? 2;
|
|
47316
47676
|
const mode = opts.mode;
|
|
47317
|
-
const dir =
|
|
47318
|
-
const tempPath =
|
|
47677
|
+
const dir = dirname21(filePath);
|
|
47678
|
+
const tempPath = join38(dir, `.${basename11(filePath)}.${randomBytes3(6).toString("hex")}.tmp`);
|
|
47319
47679
|
const content = JSON.stringify(data, null, indent) + "\n";
|
|
47320
47680
|
if (typeof mode === "number") {
|
|
47321
47681
|
writeFileSync10(tempPath, content, { encoding: "utf-8", mode });
|
|
@@ -47323,7 +47683,7 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
47323
47683
|
writeFileSync10(tempPath, content, "utf-8");
|
|
47324
47684
|
}
|
|
47325
47685
|
try {
|
|
47326
|
-
if (
|
|
47686
|
+
if (existsSync34(filePath)) {
|
|
47327
47687
|
rotateBackup(filePath, mode);
|
|
47328
47688
|
}
|
|
47329
47689
|
renameSync11(tempPath, filePath);
|
|
@@ -47337,7 +47697,7 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
47337
47697
|
}
|
|
47338
47698
|
function readJsonFile(filePath) {
|
|
47339
47699
|
try {
|
|
47340
|
-
const content =
|
|
47700
|
+
const content = readFileSync13(filePath, "utf-8");
|
|
47341
47701
|
return JSON.parse(content);
|
|
47342
47702
|
} catch (error48) {
|
|
47343
47703
|
if (error48.code === "ENOENT") {
|
|
@@ -47347,12 +47707,12 @@ function readJsonFile(filePath) {
|
|
|
47347
47707
|
}
|
|
47348
47708
|
}
|
|
47349
47709
|
async function withLock2(filePath, transform2, opts = {}) {
|
|
47350
|
-
const dir =
|
|
47710
|
+
const dir = dirname21(filePath);
|
|
47351
47711
|
const dirMode = typeof opts.mode === "number" ? modeToDirMode(opts.mode) : void 0;
|
|
47352
|
-
if (!
|
|
47712
|
+
if (!existsSync34(dir)) {
|
|
47353
47713
|
mkdirSync10(dir, { recursive: true, mode: dirMode });
|
|
47354
47714
|
}
|
|
47355
|
-
if (!
|
|
47715
|
+
if (!existsSync34(filePath)) {
|
|
47356
47716
|
if (typeof opts.mode === "number") {
|
|
47357
47717
|
writeFileSync10(filePath, "", { encoding: "utf-8", mode: opts.mode });
|
|
47358
47718
|
} else {
|
|
@@ -47373,11 +47733,11 @@ async function withLock2(filePath, transform2, opts = {}) {
|
|
|
47373
47733
|
}
|
|
47374
47734
|
}
|
|
47375
47735
|
async function withFileLock(filePath, operation) {
|
|
47376
|
-
const dir =
|
|
47377
|
-
if (!
|
|
47736
|
+
const dir = dirname21(filePath);
|
|
47737
|
+
if (!existsSync34(dir)) {
|
|
47378
47738
|
mkdirSync10(dir, { recursive: true });
|
|
47379
47739
|
}
|
|
47380
|
-
if (!
|
|
47740
|
+
if (!existsSync34(filePath)) {
|
|
47381
47741
|
writeFileSync10(filePath, "", "utf-8");
|
|
47382
47742
|
}
|
|
47383
47743
|
let release;
|
|
@@ -47411,7 +47771,7 @@ var init_file_utils = __esm({
|
|
|
47411
47771
|
|
|
47412
47772
|
// packages/core/src/llm/credential-removal.ts
|
|
47413
47773
|
import { unlinkSync as unlinkSync7 } from "node:fs";
|
|
47414
|
-
import { join as
|
|
47774
|
+
import { join as join39 } from "node:path";
|
|
47415
47775
|
import { getCleoHome as getCleoHome4 } from "@cleocode/paths";
|
|
47416
47776
|
function buildBuiltinRemovalRegistry() {
|
|
47417
47777
|
const registry2 = new RemovalRegistry();
|
|
@@ -47503,7 +47863,7 @@ var init_credential_removal = __esm({
|
|
|
47503
47863
|
sourceId: "cleo-pkce",
|
|
47504
47864
|
description: "Delete CLEO-issued PKCE token at <CLEO_HOME>/anthropic-oauth.json",
|
|
47505
47865
|
async remove() {
|
|
47506
|
-
const path =
|
|
47866
|
+
const path = join39(getCleoHome4(), "anthropic-oauth.json");
|
|
47507
47867
|
const cleaned = [];
|
|
47508
47868
|
try {
|
|
47509
47869
|
unlinkSync7(path);
|
|
@@ -47561,12 +47921,12 @@ var init_credential_removal = __esm({
|
|
|
47561
47921
|
});
|
|
47562
47922
|
|
|
47563
47923
|
// packages/core/src/llm/credential-seeders/claude-code-seeder.ts
|
|
47564
|
-
import { readFileSync as
|
|
47924
|
+
import { readFileSync as readFileSync14 } from "node:fs";
|
|
47565
47925
|
import { homedir as homedir3 } from "node:os";
|
|
47566
|
-
import { join as
|
|
47926
|
+
import { join as join40 } from "node:path";
|
|
47567
47927
|
function defaultReadCredentialFile() {
|
|
47568
47928
|
try {
|
|
47569
|
-
return
|
|
47929
|
+
return readFileSync14(join40(homedir3(), ".claude", ".credentials.json"), "utf-8");
|
|
47570
47930
|
} catch {
|
|
47571
47931
|
return null;
|
|
47572
47932
|
}
|
|
@@ -47660,14 +48020,14 @@ var init_claude_code_seeder = __esm({
|
|
|
47660
48020
|
});
|
|
47661
48021
|
|
|
47662
48022
|
// packages/core/src/llm/credential-seeders/cleo-pkce-seeder.ts
|
|
47663
|
-
import { readFileSync as
|
|
47664
|
-
import { join as
|
|
48023
|
+
import { readFileSync as readFileSync15 } from "node:fs";
|
|
48024
|
+
import { join as join41 } from "node:path";
|
|
47665
48025
|
function defaultCleoPkcePath() {
|
|
47666
|
-
return
|
|
48026
|
+
return join41(getCleoHome(), "anthropic-oauth.json");
|
|
47667
48027
|
}
|
|
47668
48028
|
function defaultReadCredentialFile2() {
|
|
47669
48029
|
try {
|
|
47670
|
-
return
|
|
48030
|
+
return readFileSync15(defaultCleoPkcePath(), "utf-8");
|
|
47671
48031
|
} catch {
|
|
47672
48032
|
return null;
|
|
47673
48033
|
}
|
|
@@ -47734,13 +48094,13 @@ var init_cleo_pkce_seeder = __esm({
|
|
|
47734
48094
|
});
|
|
47735
48095
|
|
|
47736
48096
|
// packages/core/src/llm/credential-seeders/codex-cli-seeder.ts
|
|
47737
|
-
import { existsSync as
|
|
48097
|
+
import { existsSync as existsSync35, readFileSync as readFileSync16 } from "node:fs";
|
|
47738
48098
|
import { homedir as homedir4 } from "node:os";
|
|
47739
|
-
import { join as
|
|
48099
|
+
import { join as join42 } from "node:path";
|
|
47740
48100
|
function getCodexAuthPath() {
|
|
47741
48101
|
const codexHome = (process.env["CODEX_HOME"] ?? "").trim();
|
|
47742
|
-
const root = codexHome ||
|
|
47743
|
-
return
|
|
48102
|
+
const root = codexHome || join42(homedir4(), ".codex");
|
|
48103
|
+
return join42(root, "auth.json");
|
|
47744
48104
|
}
|
|
47745
48105
|
var CodexCliSeeder, codexCliSeeder;
|
|
47746
48106
|
var init_codex_cli_seeder = __esm({
|
|
@@ -47759,12 +48119,12 @@ var init_codex_cli_seeder = __esm({
|
|
|
47759
48119
|
*/
|
|
47760
48120
|
async seed() {
|
|
47761
48121
|
const authPath = getCodexAuthPath();
|
|
47762
|
-
if (!
|
|
48122
|
+
if (!existsSync35(authPath)) {
|
|
47763
48123
|
return { entries: [] };
|
|
47764
48124
|
}
|
|
47765
48125
|
let raw;
|
|
47766
48126
|
try {
|
|
47767
|
-
raw =
|
|
48127
|
+
raw = readFileSync16(authPath, "utf-8");
|
|
47768
48128
|
} catch (err) {
|
|
47769
48129
|
return {
|
|
47770
48130
|
entries: [],
|
|
@@ -47954,11 +48314,11 @@ var init_google_pkce = __esm({
|
|
|
47954
48314
|
});
|
|
47955
48315
|
|
|
47956
48316
|
// packages/core/src/llm/credential-seeders/gemini-cli-seeder.ts
|
|
47957
|
-
import { existsSync as
|
|
47958
|
-
import { join as
|
|
48317
|
+
import { existsSync as existsSync36, readFileSync as readFileSync17 } from "node:fs";
|
|
48318
|
+
import { join as join43 } from "node:path";
|
|
47959
48319
|
import { getCleoHome as getCleoHome5 } from "@cleocode/paths";
|
|
47960
48320
|
function getGoogleOauthPath() {
|
|
47961
|
-
return
|
|
48321
|
+
return join43(getCleoHome5(), "google_oauth.json");
|
|
47962
48322
|
}
|
|
47963
48323
|
function parseGoogleOauthFile(raw) {
|
|
47964
48324
|
let json2;
|
|
@@ -48003,12 +48363,12 @@ var init_gemini_cli_seeder = __esm({
|
|
|
48003
48363
|
*/
|
|
48004
48364
|
async seed() {
|
|
48005
48365
|
const path = getGoogleOauthPath();
|
|
48006
|
-
if (!
|
|
48366
|
+
if (!existsSync36(path)) {
|
|
48007
48367
|
return { entries: [] };
|
|
48008
48368
|
}
|
|
48009
48369
|
let raw;
|
|
48010
48370
|
try {
|
|
48011
|
-
raw =
|
|
48371
|
+
raw = readFileSync17(path, "utf-8");
|
|
48012
48372
|
} catch (err) {
|
|
48013
48373
|
return {
|
|
48014
48374
|
entries: [],
|
|
@@ -48228,23 +48588,23 @@ var init_credential_seeders = __esm({
|
|
|
48228
48588
|
|
|
48229
48589
|
// packages/core/src/llm/global-config-migration.ts
|
|
48230
48590
|
import {
|
|
48231
|
-
existsSync as
|
|
48591
|
+
existsSync as existsSync37,
|
|
48232
48592
|
mkdirSync as mkdirSync11,
|
|
48233
|
-
readFileSync as
|
|
48593
|
+
readFileSync as readFileSync18,
|
|
48234
48594
|
renameSync as renameSync12,
|
|
48235
48595
|
unlinkSync as unlinkSync8,
|
|
48236
48596
|
writeFileSync as writeFileSync11
|
|
48237
48597
|
} from "node:fs";
|
|
48238
|
-
import { join as
|
|
48598
|
+
import { join as join44 } from "node:path";
|
|
48239
48599
|
import { getCleoHome as getCleoHome6, getCleoPlatformPaths as getCleoPlatformPaths2 } from "@cleocode/paths";
|
|
48240
48600
|
function configDirGlobalConfigPath() {
|
|
48241
|
-
return
|
|
48601
|
+
return join44(getCleoPlatformPaths2().config, GLOBAL_CONFIG_FILENAME);
|
|
48242
48602
|
}
|
|
48243
48603
|
function legacyGlobalConfigPath() {
|
|
48244
|
-
return
|
|
48604
|
+
return join44(getCleoHome6(), GLOBAL_CONFIG_FILENAME);
|
|
48245
48605
|
}
|
|
48246
48606
|
function migrationMarkerPath() {
|
|
48247
|
-
return
|
|
48607
|
+
return join44(getCleoHome6(), MIGRATIONS_SUBDIR, MIGRATION_MARKER);
|
|
48248
48608
|
}
|
|
48249
48609
|
function tempTargetPath() {
|
|
48250
48610
|
return `${configDirGlobalConfigPath()}.tmp`;
|
|
@@ -48254,17 +48614,17 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
48254
48614
|
const source = legacyGlobalConfigPath();
|
|
48255
48615
|
const target = configDirGlobalConfigPath();
|
|
48256
48616
|
const marker16 = migrationMarkerPath();
|
|
48257
|
-
if (
|
|
48258
|
-
if (!
|
|
48617
|
+
if (existsSync37(marker16)) return false;
|
|
48618
|
+
if (!existsSync37(source)) {
|
|
48259
48619
|
stampMarker(marker16);
|
|
48260
48620
|
return false;
|
|
48261
48621
|
}
|
|
48262
|
-
if (
|
|
48622
|
+
if (existsSync37(target)) {
|
|
48263
48623
|
backupSourceQuiet(source);
|
|
48264
48624
|
stampMarker(marker16);
|
|
48265
48625
|
return false;
|
|
48266
48626
|
}
|
|
48267
|
-
const raw =
|
|
48627
|
+
const raw = readFileSync18(source, "utf-8");
|
|
48268
48628
|
try {
|
|
48269
48629
|
JSON.parse(raw);
|
|
48270
48630
|
} catch (err) {
|
|
@@ -48292,7 +48652,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
48292
48652
|
} catch (err) {
|
|
48293
48653
|
try {
|
|
48294
48654
|
const temp = tempTargetPath();
|
|
48295
|
-
if (
|
|
48655
|
+
if (existsSync37(temp)) unlinkSync8(temp);
|
|
48296
48656
|
} catch {
|
|
48297
48657
|
}
|
|
48298
48658
|
console.error(
|
|
@@ -48303,7 +48663,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
48303
48663
|
}
|
|
48304
48664
|
function stampMarker(markerPath) {
|
|
48305
48665
|
try {
|
|
48306
|
-
mkdirSync11(
|
|
48666
|
+
mkdirSync11(join44(getCleoHome6(), MIGRATIONS_SUBDIR), { recursive: true });
|
|
48307
48667
|
writeFileSync11(markerPath, `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
48308
48668
|
`, { mode: 420 });
|
|
48309
48669
|
} catch {
|
|
@@ -48312,7 +48672,7 @@ function stampMarker(markerPath) {
|
|
|
48312
48672
|
function backupSourceQuiet(source) {
|
|
48313
48673
|
try {
|
|
48314
48674
|
const backup = `${source}${BACKUP_SUFFIX}`;
|
|
48315
|
-
if (
|
|
48675
|
+
if (existsSync37(backup)) return;
|
|
48316
48676
|
renameSync12(source, backup);
|
|
48317
48677
|
} catch {
|
|
48318
48678
|
}
|
|
@@ -48335,15 +48695,15 @@ var init_global_config_migration = __esm({
|
|
|
48335
48695
|
});
|
|
48336
48696
|
|
|
48337
48697
|
// packages/core/src/llm/legacy-flat-key-import.ts
|
|
48338
|
-
import { existsSync as
|
|
48339
|
-
import { join as
|
|
48698
|
+
import { existsSync as existsSync38, readFileSync as readFileSync19, renameSync as renameSync13, writeFileSync as writeFileSync12 } from "node:fs";
|
|
48699
|
+
import { join as join45 } from "node:path";
|
|
48340
48700
|
import { getCleoHome as getCleoHome7 } from "@cleocode/paths";
|
|
48341
48701
|
function migrationPaths() {
|
|
48342
48702
|
const home = getCleoHome7();
|
|
48343
48703
|
return {
|
|
48344
|
-
flatPath:
|
|
48345
|
-
bakPath:
|
|
48346
|
-
markerPath:
|
|
48704
|
+
flatPath: join45(home, "anthropic-key"),
|
|
48705
|
+
bakPath: join45(home, `anthropic-key${LEGACY_FLAT_KEY_BAK_SUFFIX}`),
|
|
48706
|
+
markerPath: join45(home, LEGACY_FLAT_KEY_MARKER)
|
|
48347
48707
|
};
|
|
48348
48708
|
}
|
|
48349
48709
|
function writeMarker(markerPath) {
|
|
@@ -48364,8 +48724,8 @@ function writeMarker(markerPath) {
|
|
|
48364
48724
|
}
|
|
48365
48725
|
function readFlatKey(flatPath) {
|
|
48366
48726
|
try {
|
|
48367
|
-
if (!
|
|
48368
|
-
const raw =
|
|
48727
|
+
if (!existsSync38(flatPath)) return null;
|
|
48728
|
+
const raw = readFileSync19(flatPath, "utf-8").trim();
|
|
48369
48729
|
return raw || null;
|
|
48370
48730
|
} catch (err) {
|
|
48371
48731
|
logger.warn(
|
|
@@ -48377,7 +48737,7 @@ function readFlatKey(flatPath) {
|
|
|
48377
48737
|
}
|
|
48378
48738
|
async function importLegacyFlatAnthropicKey() {
|
|
48379
48739
|
const { flatPath, bakPath, markerPath } = migrationPaths();
|
|
48380
|
-
if (
|
|
48740
|
+
if (existsSync38(markerPath)) {
|
|
48381
48741
|
return { status: "marker-present", flatPath, bakPath: null, markerPath };
|
|
48382
48742
|
}
|
|
48383
48743
|
let existing = null;
|
|
@@ -48394,7 +48754,7 @@ async function importLegacyFlatAnthropicKey() {
|
|
|
48394
48754
|
writeMarker(markerPath);
|
|
48395
48755
|
return { status: "already-imported", flatPath, bakPath: null, markerPath };
|
|
48396
48756
|
}
|
|
48397
|
-
if (!
|
|
48757
|
+
if (!existsSync38(flatPath)) {
|
|
48398
48758
|
writeMarker(markerPath);
|
|
48399
48759
|
return { status: "no-flat-file", flatPath, bakPath: null, markerPath };
|
|
48400
48760
|
}
|
|
@@ -48456,15 +48816,15 @@ var init_legacy_flat_key_import = __esm({
|
|
|
48456
48816
|
});
|
|
48457
48817
|
|
|
48458
48818
|
// packages/core/src/llm/credentials.ts
|
|
48459
|
-
import { existsSync as
|
|
48460
|
-
import { join as
|
|
48819
|
+
import { existsSync as existsSync39, mkdirSync as mkdirSync12, readFileSync as readFileSync20, writeFileSync as writeFileSync13 } from "node:fs";
|
|
48820
|
+
import { join as join46 } from "node:path";
|
|
48461
48821
|
import { getCleoHome as getCleoHome8 } from "@cleocode/paths";
|
|
48462
48822
|
function globalConfigPath() {
|
|
48463
48823
|
return configDirGlobalConfigPath();
|
|
48464
48824
|
}
|
|
48465
48825
|
function projectConfigPath(projectRoot) {
|
|
48466
48826
|
const cleoDir = process.env["CLEO_DIR"] ?? ".cleo";
|
|
48467
|
-
return
|
|
48827
|
+
return join46(projectRoot, cleoDir, "config.json");
|
|
48468
48828
|
}
|
|
48469
48829
|
function readGlobalProviderKey(provider) {
|
|
48470
48830
|
ensureGlobalConfigMigrated();
|
|
@@ -48474,9 +48834,9 @@ function readGlobalProviderKey(provider) {
|
|
|
48474
48834
|
}
|
|
48475
48835
|
function readFlatAnthropicKey() {
|
|
48476
48836
|
try {
|
|
48477
|
-
const keyFile =
|
|
48478
|
-
if (!
|
|
48479
|
-
const stored =
|
|
48837
|
+
const keyFile = join46(getCleoHome8(), "anthropic-key");
|
|
48838
|
+
if (!existsSync39(keyFile)) return null;
|
|
48839
|
+
const stored = readFileSync20(keyFile, "utf-8").trim();
|
|
48480
48840
|
return stored || null;
|
|
48481
48841
|
} catch {
|
|
48482
48842
|
return null;
|
|
@@ -48484,8 +48844,8 @@ function readFlatAnthropicKey() {
|
|
|
48484
48844
|
}
|
|
48485
48845
|
function readProviderKeyFromConfig(configFile, provider) {
|
|
48486
48846
|
try {
|
|
48487
|
-
if (!
|
|
48488
|
-
const raw =
|
|
48847
|
+
if (!existsSync39(configFile)) return null;
|
|
48848
|
+
const raw = readFileSync20(configFile, "utf-8");
|
|
48489
48849
|
const config2 = JSON.parse(raw);
|
|
48490
48850
|
const llm = config2["llm"];
|
|
48491
48851
|
if (!llm || typeof llm !== "object") return null;
|
|
@@ -48624,16 +48984,16 @@ __export(credentials_store_exports, {
|
|
|
48624
48984
|
pickCredentialForProviderSync: () => pickCredentialForProviderSync,
|
|
48625
48985
|
removeCredential: () => removeCredential
|
|
48626
48986
|
});
|
|
48627
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
48628
|
-
import { dirname as
|
|
48987
|
+
import { chmodSync as chmodSync2, existsSync as existsSync40, mkdirSync as mkdirSync13, readFileSync as readFileSync21, statSync as statSync10, writeFileSync as writeFileSync14 } from "node:fs";
|
|
48988
|
+
import { dirname as dirname22, join as join47 } from "node:path";
|
|
48629
48989
|
import { getCleoHome as getCleoHome9 } from "@cleocode/paths";
|
|
48630
48990
|
function credentialsStorePath() {
|
|
48631
|
-
return
|
|
48991
|
+
return join47(getCleoHome9(), "llm-credentials.json");
|
|
48632
48992
|
}
|
|
48633
48993
|
function ensureFileInitialized(path) {
|
|
48634
|
-
if (
|
|
48635
|
-
const dir =
|
|
48636
|
-
if (!
|
|
48994
|
+
if (existsSync40(path)) return;
|
|
48995
|
+
const dir = dirname22(path);
|
|
48996
|
+
if (!existsSync40(dir)) {
|
|
48637
48997
|
mkdirSync13(dir, { recursive: true, mode: 448 });
|
|
48638
48998
|
} else {
|
|
48639
48999
|
try {
|
|
@@ -48677,7 +49037,7 @@ function readStoreSync() {
|
|
|
48677
49037
|
const path = credentialsStorePath();
|
|
48678
49038
|
let raw;
|
|
48679
49039
|
try {
|
|
48680
|
-
raw =
|
|
49040
|
+
raw = readFileSync21(path, "utf-8");
|
|
48681
49041
|
} catch {
|
|
48682
49042
|
return emptyStore();
|
|
48683
49043
|
}
|
|
@@ -49266,13 +49626,13 @@ var init_xai = __esm({
|
|
|
49266
49626
|
|
|
49267
49627
|
// packages/core/src/llm/provider-registry/loader.ts
|
|
49268
49628
|
import { readdirSync as readdirSync9, statSync as statSync11 } from "node:fs";
|
|
49269
|
-
import { join as
|
|
49629
|
+
import { join as join48 } from "node:path";
|
|
49270
49630
|
import { pathToFileURL } from "node:url";
|
|
49271
49631
|
function isPluginFile(filename) {
|
|
49272
49632
|
return PLUGIN_EXTENSIONS.some((ext) => filename.endsWith(ext));
|
|
49273
49633
|
}
|
|
49274
49634
|
function getPluginDir() {
|
|
49275
|
-
return
|
|
49635
|
+
return join48(getCleoHome(), "plugins", "model-providers");
|
|
49276
49636
|
}
|
|
49277
49637
|
async function loadOnePlugin(absPath, api) {
|
|
49278
49638
|
let mod;
|
|
@@ -49320,13 +49680,13 @@ async function scanAndLoadPlugins(pluginDir, api) {
|
|
|
49320
49680
|
}
|
|
49321
49681
|
const pluginFiles = entries.filter((name15) => !name15.startsWith(".") && isPluginFile(name15)).filter((name15) => {
|
|
49322
49682
|
try {
|
|
49323
|
-
return statSync11(
|
|
49683
|
+
return statSync11(join48(pluginDir, name15)).isFile();
|
|
49324
49684
|
} catch {
|
|
49325
49685
|
return false;
|
|
49326
49686
|
}
|
|
49327
49687
|
}).sort();
|
|
49328
49688
|
for (const filename of pluginFiles) {
|
|
49329
|
-
await loadOnePlugin(
|
|
49689
|
+
await loadOnePlugin(join48(pluginDir, filename), api);
|
|
49330
49690
|
}
|
|
49331
49691
|
}
|
|
49332
49692
|
async function runDiscovery(registerProvider2, builtins) {
|
|
@@ -49429,15 +49789,15 @@ var init_provider_registry = __esm({
|
|
|
49429
49789
|
});
|
|
49430
49790
|
|
|
49431
49791
|
// packages/core/src/llm/rate-limit-guard.ts
|
|
49432
|
-
import { existsSync as
|
|
49433
|
-
import { join as
|
|
49792
|
+
import { existsSync as existsSync41, mkdirSync as mkdirSync14, unlinkSync as unlinkSync9 } from "node:fs";
|
|
49793
|
+
import { join as join49 } from "node:path";
|
|
49434
49794
|
import { getCleoHome as getCleoHome10 } from "@cleocode/paths";
|
|
49435
49795
|
function sanitize(value) {
|
|
49436
49796
|
return value.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
49437
49797
|
}
|
|
49438
49798
|
function rateLimitStatePath(provider, label) {
|
|
49439
|
-
const dir =
|
|
49440
|
-
return
|
|
49799
|
+
const dir = join49(getCleoHome10(), "rate-limit-state");
|
|
49800
|
+
return join49(dir, `${sanitize(provider)}-${sanitize(label)}.json`);
|
|
49441
49801
|
}
|
|
49442
49802
|
function parseResetFromHeaders(headers) {
|
|
49443
49803
|
const get = (k) => {
|
|
@@ -49484,8 +49844,8 @@ async function recordRateLimit(provider, label, opts) {
|
|
|
49484
49844
|
source = "default";
|
|
49485
49845
|
}
|
|
49486
49846
|
const filePath = rateLimitStatePath(provider, label);
|
|
49487
|
-
const dir =
|
|
49488
|
-
if (!
|
|
49847
|
+
const dir = join49(getCleoHome10(), "rate-limit-state");
|
|
49848
|
+
if (!existsSync41(dir)) {
|
|
49489
49849
|
mkdirSync14(dir, { recursive: true });
|
|
49490
49850
|
}
|
|
49491
49851
|
const state = { resetAt, recordedAt: now, source };
|
|
@@ -50070,31 +50430,31 @@ var init_local_inference_probe = __esm({
|
|
|
50070
50430
|
|
|
50071
50431
|
// packages/core/src/llm/catalog-cache.ts
|
|
50072
50432
|
import {
|
|
50073
|
-
existsSync as
|
|
50433
|
+
existsSync as existsSync42,
|
|
50074
50434
|
mkdirSync as mkdirSync15,
|
|
50075
50435
|
readdirSync as readdirSync10,
|
|
50076
|
-
readFileSync as
|
|
50436
|
+
readFileSync as readFileSync22,
|
|
50077
50437
|
statSync as statSync12,
|
|
50078
50438
|
symlinkSync,
|
|
50079
50439
|
unlinkSync as unlinkSync10,
|
|
50080
50440
|
writeFileSync as writeFileSync15
|
|
50081
50441
|
} from "node:fs";
|
|
50082
|
-
import { join as
|
|
50442
|
+
import { join as join50 } from "node:path";
|
|
50083
50443
|
import { getCleoHome as getCleoHome11 } from "@cleocode/paths";
|
|
50084
50444
|
function getCatalogDir() {
|
|
50085
50445
|
if (process.env["CLEO_DATA_DIR"]) {
|
|
50086
|
-
return
|
|
50446
|
+
return join50(process.env["CLEO_DATA_DIR"], "llm-catalog");
|
|
50087
50447
|
}
|
|
50088
|
-
return
|
|
50448
|
+
return join50(getCleoHome11(), "llm-catalog");
|
|
50089
50449
|
}
|
|
50090
50450
|
function findLatestCacheFile(dir) {
|
|
50091
|
-
if (!
|
|
50092
|
-
const files = readdirSync10(dir).filter((f) => f.endsWith("-models.json")).map((f) => ({ name: f, mtime: statSync12(
|
|
50093
|
-
return files.length > 0 ?
|
|
50451
|
+
if (!existsSync42(dir)) return null;
|
|
50452
|
+
const files = readdirSync10(dir).filter((f) => f.endsWith("-models.json")).map((f) => ({ name: f, mtime: statSync12(join50(dir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
|
|
50453
|
+
return files.length > 0 ? join50(dir, files[0].name) : null;
|
|
50094
50454
|
}
|
|
50095
50455
|
function readCacheFile(filePath) {
|
|
50096
50456
|
try {
|
|
50097
|
-
const raw =
|
|
50457
|
+
const raw = readFileSync22(filePath, "utf-8");
|
|
50098
50458
|
return JSON.parse(raw);
|
|
50099
50459
|
} catch {
|
|
50100
50460
|
return null;
|
|
@@ -50873,9 +51233,9 @@ __export(catalog_resolver_exports, {
|
|
|
50873
51233
|
openCatalogAtPath: () => openCatalogAtPath,
|
|
50874
51234
|
resolveCatalogEntry: () => resolveCatalogEntry
|
|
50875
51235
|
});
|
|
50876
|
-
import { readFileSync as
|
|
50877
|
-
import { dirname as
|
|
50878
|
-
import { fileURLToPath as
|
|
51236
|
+
import { readFileSync as readFileSync23 } from "node:fs";
|
|
51237
|
+
import { dirname as dirname23, join as join51 } from "node:path";
|
|
51238
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
50879
51239
|
async function openCatalogAtPath(dbPath) {
|
|
50880
51240
|
const handle = await openDualScopeDbAtPath("global", dbPath);
|
|
50881
51241
|
return handle.db;
|
|
@@ -50883,9 +51243,9 @@ async function openCatalogAtPath(dbPath) {
|
|
|
50883
51243
|
function loadShippedSeed() {
|
|
50884
51244
|
if (_seed !== void 0) return _seed;
|
|
50885
51245
|
try {
|
|
50886
|
-
const thisDir =
|
|
50887
|
-
const jsonPath =
|
|
50888
|
-
_seed = JSON.parse(
|
|
51246
|
+
const thisDir = dirname23(fileURLToPath4(import.meta.url));
|
|
51247
|
+
const jsonPath = join51(thisDir, "curated-catalog.json");
|
|
51248
|
+
_seed = JSON.parse(readFileSync23(jsonPath, "utf-8"));
|
|
50889
51249
|
} catch (err) {
|
|
50890
51250
|
logger5.warn(
|
|
50891
51251
|
{ err: err instanceof Error ? err.message : String(err) },
|
|
@@ -51308,16 +51668,16 @@ var init_message_utils = __esm({
|
|
|
51308
51668
|
});
|
|
51309
51669
|
|
|
51310
51670
|
// packages/core/src/llm/model-metadata.ts
|
|
51311
|
-
import { readFileSync as
|
|
51312
|
-
import { dirname as
|
|
51313
|
-
import { fileURLToPath as
|
|
51671
|
+
import { readFileSync as readFileSync24 } from "node:fs";
|
|
51672
|
+
import { dirname as dirname24, join as join52 } from "node:path";
|
|
51673
|
+
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
51314
51674
|
function getCuratedTable() {
|
|
51315
51675
|
if (_curated !== void 0) {
|
|
51316
51676
|
return _curated;
|
|
51317
51677
|
}
|
|
51318
|
-
const thisDir =
|
|
51319
|
-
const jsonPath =
|
|
51320
|
-
const raw = JSON.parse(
|
|
51678
|
+
const thisDir = dirname24(fileURLToPath5(import.meta.url));
|
|
51679
|
+
const jsonPath = join52(thisDir, "curated-models.json");
|
|
51680
|
+
const raw = JSON.parse(readFileSync24(jsonPath, "utf-8"));
|
|
51321
51681
|
_curated = raw.models;
|
|
51322
51682
|
return _curated;
|
|
51323
51683
|
}
|
|
@@ -51396,7 +51756,7 @@ function storedToResolved(stored) {
|
|
|
51396
51756
|
};
|
|
51397
51757
|
}
|
|
51398
51758
|
function sleep3(ms) {
|
|
51399
|
-
return new Promise((
|
|
51759
|
+
return new Promise((resolve17) => setTimeout(resolve17, ms));
|
|
51400
51760
|
}
|
|
51401
51761
|
function backoffMs(policy, attempt) {
|
|
51402
51762
|
const base = policy.baseDelayMs * 2 ** attempt;
|
|
@@ -55218,7 +55578,7 @@ function normalizeOllamaToolCall(tc) {
|
|
|
55218
55578
|
};
|
|
55219
55579
|
}
|
|
55220
55580
|
function sleep4(ms) {
|
|
55221
|
-
return new Promise((
|
|
55581
|
+
return new Promise((resolve17) => setTimeout(resolve17, ms));
|
|
55222
55582
|
}
|
|
55223
55583
|
var OLLAMA_DEFAULT_BASE_URL, MAX_RETRIES, INITIAL_BACKOFF_MS, RETRYABLE_STATUS_CODES, OllamaTransport;
|
|
55224
55584
|
var init_ollama2 = __esm({
|
|
@@ -75732,7 +76092,7 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
75732
76092
|
supportsDeferredResults
|
|
75733
76093
|
});
|
|
75734
76094
|
}
|
|
75735
|
-
async function
|
|
76095
|
+
async function resolve16(value) {
|
|
75736
76096
|
if (typeof value === "function") {
|
|
75737
76097
|
value = value();
|
|
75738
76098
|
}
|
|
@@ -79766,14 +80126,14 @@ var init_dist4 = __esm({
|
|
|
79766
80126
|
headers
|
|
79767
80127
|
}) {
|
|
79768
80128
|
return combineHeaders(
|
|
79769
|
-
await
|
|
80129
|
+
await resolve16(this.config.headers),
|
|
79770
80130
|
headers,
|
|
79771
80131
|
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}
|
|
79772
80132
|
);
|
|
79773
80133
|
}
|
|
79774
80134
|
async getBetasFromHeaders(requestHeaders) {
|
|
79775
80135
|
var _a17, _b16;
|
|
79776
|
-
const configHeaders = await
|
|
80136
|
+
const configHeaders = await resolve16(this.config.headers);
|
|
79777
80137
|
const configBetaHeader = (_a17 = configHeaders["anthropic-beta"]) != null ? _a17 : "";
|
|
79778
80138
|
const requestBetaHeader = (_b16 = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b16 : "";
|
|
79779
80139
|
return new Set(
|
|
@@ -83361,7 +83721,7 @@ var init_model_runner = __esm({
|
|
|
83361
83721
|
|
|
83362
83722
|
// packages/core/src/selfimprove/fix-gen.ts
|
|
83363
83723
|
import { mkdirSync as mkdirSync16, writeFileSync as writeFileSync16 } from "node:fs";
|
|
83364
|
-
import { dirname as
|
|
83724
|
+
import { dirname as dirname25, join as join53, resolve as resolvePath2 } from "node:path";
|
|
83365
83725
|
import { cwd as processCwd } from "node:process";
|
|
83366
83726
|
|
|
83367
83727
|
// packages/utils/src/redact.ts
|
|
@@ -83625,7 +83985,7 @@ var FIXGEN_SYSTEM = "task-executor";
|
|
|
83625
83985
|
var UNIFIED_DIFF_MARKERS = ["diff --git ", "--- ", "+++ ", "@@ "];
|
|
83626
83986
|
function fixPatchPath(scenario, cwd) {
|
|
83627
83987
|
const safeScenario = scenario.replace(/[^a-z0-9-]/gi, "-");
|
|
83628
|
-
return resolvePath2(cwd ?? processCwd(),
|
|
83988
|
+
return resolvePath2(cwd ?? processCwd(), join53(".cleo", "selfimprove", `${safeScenario}.patch`));
|
|
83629
83989
|
}
|
|
83630
83990
|
function looksLikeUnifiedDiff(text2) {
|
|
83631
83991
|
if (text2.trim().length === 0) return false;
|
|
@@ -83710,7 +84070,7 @@ async function generateFixPatch(opts) {
|
|
|
83710
84070
|
}
|
|
83711
84071
|
const diff = output.diff.endsWith("\n") ? output.diff : `${output.diff}
|
|
83712
84072
|
`;
|
|
83713
|
-
mkdirSync16(
|
|
84073
|
+
mkdirSync16(dirname25(patchPath), { recursive: true });
|
|
83714
84074
|
writeFileSync16(patchPath, diff, "utf8");
|
|
83715
84075
|
const bytes = Buffer.byteLength(diff, "utf8");
|
|
83716
84076
|
logger8.info(
|