@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
|
@@ -344,7 +344,7 @@ var init_acceptance_gate_schema = __esm({
|
|
|
344
344
|
message: "Result cannot precede input capture"
|
|
345
345
|
});
|
|
346
346
|
const executable = ["test", "command", "lint"].includes(result.kind);
|
|
347
|
-
if (executable && !binding.invocation)
|
|
347
|
+
if (executable && !binding.invocation && result.result !== "error")
|
|
348
348
|
context.addIssue({
|
|
349
349
|
code: "custom",
|
|
350
350
|
path: ["binding", "invocation"],
|
|
@@ -3110,12 +3110,21 @@ var init_operations_registry = __esm({
|
|
|
3110
3110
|
gateway: "query",
|
|
3111
3111
|
domain: "tasks",
|
|
3112
3112
|
operation: "history",
|
|
3113
|
-
description: "Show task work history
|
|
3113
|
+
description: "Show task work history; with taskId, the task audit trail; with ranking, who changed its priority/severity/kind/depends and why (T12693)",
|
|
3114
3114
|
tier: 1,
|
|
3115
3115
|
idempotent: true,
|
|
3116
3116
|
sessionRequired: false,
|
|
3117
3117
|
requiredParams: [],
|
|
3118
|
-
params: [
|
|
3118
|
+
params: [
|
|
3119
|
+
{ name: "taskId", type: "string", required: false, description: "Task to show history for" },
|
|
3120
|
+
{ name: "limit", type: "number", required: false, description: "Maximum entries" },
|
|
3121
|
+
{
|
|
3122
|
+
name: "ranking",
|
|
3123
|
+
type: "boolean",
|
|
3124
|
+
required: false,
|
|
3125
|
+
description: "Only ranking-input changes (actor, session, reason, before/after)"
|
|
3126
|
+
}
|
|
3127
|
+
]
|
|
3119
3128
|
},
|
|
3120
3129
|
{
|
|
3121
3130
|
gateway: "query",
|
|
@@ -5610,6 +5619,32 @@ var init_operations_registry = __esm({
|
|
|
5610
5619
|
],
|
|
5611
5620
|
outputSchema: OUTPUT_CONTRACTS["tasks.assignee"]
|
|
5612
5621
|
},
|
|
5622
|
+
{
|
|
5623
|
+
gateway: "mutate",
|
|
5624
|
+
domain: "tasks",
|
|
5625
|
+
operation: "ranking.revert",
|
|
5626
|
+
description: "tasks.ranking.revert (mutate) \u2014 undo one recorded ranking change (priority/severity/kind/depends) as a new audited change (T12693, D11161)",
|
|
5627
|
+
tier: 1,
|
|
5628
|
+
idempotent: false,
|
|
5629
|
+
sessionRequired: false,
|
|
5630
|
+
requiredParams: ["entryId"],
|
|
5631
|
+
params: [
|
|
5632
|
+
{
|
|
5633
|
+
name: "entryId",
|
|
5634
|
+
type: "string",
|
|
5635
|
+
required: true,
|
|
5636
|
+
description: "ranking_changed audit row id (cleo history ranking <taskId>)",
|
|
5637
|
+
cli: { positional: true }
|
|
5638
|
+
},
|
|
5639
|
+
{ name: "reason", type: "string", required: false, description: "Why it is reverted" },
|
|
5640
|
+
{
|
|
5641
|
+
name: "force",
|
|
5642
|
+
type: "boolean",
|
|
5643
|
+
required: false,
|
|
5644
|
+
description: "Revert even though a field changed again since"
|
|
5645
|
+
}
|
|
5646
|
+
]
|
|
5647
|
+
},
|
|
5613
5648
|
{
|
|
5614
5649
|
gateway: "mutate",
|
|
5615
5650
|
domain: "tasks",
|
|
@@ -13077,7 +13112,10 @@ var init_evidence_atom_schema = __esm({
|
|
|
13077
13112
|
["commit", "note"],
|
|
13078
13113
|
["decision", "files"],
|
|
13079
13114
|
["decision", "note"],
|
|
13080
|
-
["pr", "files"]
|
|
13115
|
+
["pr", "files"],
|
|
13116
|
+
// T12689: a deletion-only PR (no bytes to hash). Contextual validation
|
|
13117
|
+
// accepts this only when every change the PR made is a deletion.
|
|
13118
|
+
["pr", "note"]
|
|
13081
13119
|
]
|
|
13082
13120
|
},
|
|
13083
13121
|
testsPassed: { oneOf: [["test-run"], ["tool"], ["ci"]] },
|
|
@@ -17052,7 +17090,7 @@ var init_collection_keys = __esm({
|
|
|
17052
17090
|
|
|
17053
17091
|
// packages/contracts/src/decide.ts
|
|
17054
17092
|
import { z as z24 } from "zod";
|
|
17055
|
-
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;
|
|
17093
|
+
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;
|
|
17056
17094
|
var init_decide = __esm({
|
|
17057
17095
|
"packages/contracts/src/decide.ts"() {
|
|
17058
17096
|
"use strict";
|
|
@@ -17076,6 +17114,7 @@ var init_decide = __esm({
|
|
|
17076
17114
|
/** Maximum number of levels on a `score` question's scale. */
|
|
17077
17115
|
maxScoreLevels: 10
|
|
17078
17116
|
};
|
|
17117
|
+
DECISION_PROVIDER_KINDS = ["layahost", "jev"];
|
|
17079
17118
|
decisionQuestionTypeSchema = z24.enum(DECISION_QUESTION_TYPES);
|
|
17080
17119
|
decisionOutcomeSourceSchema = z24.enum(DECISION_OUTCOME_SOURCES);
|
|
17081
17120
|
decisionInstructionsSchema = z24.union([z24.string(), z24.record(z24.string(), z24.json())]);
|
|
@@ -17113,6 +17152,8 @@ var init_decide = __esm({
|
|
|
17113
17152
|
]);
|
|
17114
17153
|
decisionRequestSchema = z24.object({
|
|
17115
17154
|
model: z24.string().min(1).optional(),
|
|
17155
|
+
lang: z24.string().regex(/^[a-z]{2,3}(-[A-Za-z0-9]{2,8})?$/).optional(),
|
|
17156
|
+
cache: z24.boolean().optional(),
|
|
17116
17157
|
state: decisionStateSchema,
|
|
17117
17158
|
questions: z24.record(z24.string().min(1), decisionQuestionSchema).refine(
|
|
17118
17159
|
(questions) => {
|
|
@@ -17153,14 +17194,26 @@ var init_decide = __esm({
|
|
|
17153
17194
|
requestId: z24.string().min(1).optional(),
|
|
17154
17195
|
latencyMs: z24.number().nonnegative(),
|
|
17155
17196
|
costUsd: z24.number().nonnegative().optional(),
|
|
17197
|
+
costMicros: z24.number().int().nonnegative().optional(),
|
|
17198
|
+
balanceMicros: z24.number().int().optional(),
|
|
17199
|
+
checkpoint: z24.string().min(1).optional(),
|
|
17156
17200
|
inputTokens: z24.number().int().nonnegative().optional()
|
|
17157
17201
|
});
|
|
17202
|
+
decisionProviderKindSchema = z24.enum(DECISION_PROVIDER_KINDS);
|
|
17158
17203
|
decisionProviderConfigSchema = z24.object({
|
|
17159
|
-
baseUrl: z24.url()
|
|
17204
|
+
baseUrl: z24.url(),
|
|
17205
|
+
provider: decisionProviderKindSchema.optional()
|
|
17160
17206
|
});
|
|
17161
17207
|
}
|
|
17162
17208
|
});
|
|
17163
17209
|
|
|
17210
|
+
// packages/contracts/src/decide-sites.ts
|
|
17211
|
+
var init_decide_sites = __esm({
|
|
17212
|
+
"packages/contracts/src/decide-sites.ts"() {
|
|
17213
|
+
"use strict";
|
|
17214
|
+
}
|
|
17215
|
+
});
|
|
17216
|
+
|
|
17164
17217
|
// packages/contracts/src/task-id.ts
|
|
17165
17218
|
var init_task_id = __esm({
|
|
17166
17219
|
"packages/contracts/src/task-id.ts"() {
|
|
@@ -17242,6 +17295,7 @@ var init_src = __esm({
|
|
|
17242
17295
|
init_caamp_markers();
|
|
17243
17296
|
init_collection_keys();
|
|
17244
17297
|
init_decide();
|
|
17298
|
+
init_decide_sites();
|
|
17245
17299
|
init_task_id();
|
|
17246
17300
|
}
|
|
17247
17301
|
});
|
|
@@ -18763,7 +18817,10 @@ function linkedWorktreeMainRoot(dir) {
|
|
|
18763
18817
|
}
|
|
18764
18818
|
function describeWorktreeOwner(dir) {
|
|
18765
18819
|
const mainRoot = linkedWorktreeMainRoot(dir);
|
|
18766
|
-
if (mainRoot === null)
|
|
18820
|
+
if (mainRoot === null) {
|
|
18821
|
+
const bare = bareRepositoryOfWorktree(dir);
|
|
18822
|
+
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`;
|
|
18823
|
+
}
|
|
18767
18824
|
let projectId = null;
|
|
18768
18825
|
try {
|
|
18769
18826
|
const parsed = JSON.parse(
|
|
@@ -18777,6 +18834,18 @@ function describeWorktreeOwner(dir) {
|
|
|
18777
18834
|
}
|
|
18778
18835
|
return projectId === null ? `owning repository ${mainRoot} (not an initialised CLEO project)` : `owning project ${mainRoot} (projectId ${projectId})`;
|
|
18779
18836
|
}
|
|
18837
|
+
function bareRepositoryOfWorktree(dir) {
|
|
18838
|
+
const gitdir = readGitlinkTarget(dir);
|
|
18839
|
+
if (!gitdir || basename2(dirname2(gitdir)) !== "worktrees") return null;
|
|
18840
|
+
const commonDir = dirname2(dirname2(gitdir));
|
|
18841
|
+
try {
|
|
18842
|
+
const config2 = readFileSync2(join3(commonDir, "config"), "utf-8");
|
|
18843
|
+
const core = /^\[core\][^[]*/m.exec(config2)?.[0] ?? "";
|
|
18844
|
+
return /^\s*bare\s*=\s*true\s*$/im.test(core) ? commonDir : null;
|
|
18845
|
+
} catch {
|
|
18846
|
+
return null;
|
|
18847
|
+
}
|
|
18848
|
+
}
|
|
18780
18849
|
function readCoreWorktree(gitDir) {
|
|
18781
18850
|
try {
|
|
18782
18851
|
const config2 = readFileSync2(join3(gitDir, "config"), "utf-8");
|
|
@@ -19226,13 +19295,13 @@ function captureWriteFence(input) {
|
|
|
19226
19295
|
return writeFence;
|
|
19227
19296
|
}
|
|
19228
19297
|
function observeOperation(context, work) {
|
|
19229
|
-
return new Promise((
|
|
19298
|
+
return new Promise((resolve17) => {
|
|
19230
19299
|
let observed = false;
|
|
19231
19300
|
const finish = (result) => {
|
|
19232
19301
|
if (observed) return;
|
|
19233
19302
|
observed = true;
|
|
19234
19303
|
context.signal.removeEventListener("abort", abort);
|
|
19235
|
-
|
|
19304
|
+
resolve17(result);
|
|
19236
19305
|
};
|
|
19237
19306
|
const abort = () => {
|
|
19238
19307
|
const reason = context.signal.reason;
|
|
@@ -19866,7 +19935,7 @@ var init_sql = __esm({
|
|
|
19866
19935
|
return new SQL([new StringChunk(str)]);
|
|
19867
19936
|
}
|
|
19868
19937
|
_sql.raw = raw;
|
|
19869
|
-
function
|
|
19938
|
+
function join50(chunks, separator) {
|
|
19870
19939
|
const result = [];
|
|
19871
19940
|
for (const [i, chunk] of chunks.entries()) {
|
|
19872
19941
|
if (i > 0 && separator !== void 0) result.push(separator);
|
|
@@ -19874,7 +19943,7 @@ var init_sql = __esm({
|
|
|
19874
19943
|
}
|
|
19875
19944
|
return new SQL(result);
|
|
19876
19945
|
}
|
|
19877
|
-
_sql.join =
|
|
19946
|
+
_sql.join = join50;
|
|
19878
19947
|
function identifier2(value) {
|
|
19879
19948
|
return new Name(value);
|
|
19880
19949
|
}
|
|
@@ -21889,7 +21958,7 @@ var init_select = __esm({
|
|
|
21889
21958
|
const baseTableName = this.tableName;
|
|
21890
21959
|
const tableName = getTableLikeName(table);
|
|
21891
21960
|
for (const item of extractUsedTable(table)) this.usedTables.add(item);
|
|
21892
|
-
if (typeof tableName === "string" && this.config.joins?.some((
|
|
21961
|
+
if (typeof tableName === "string" && this.config.joins?.some((join50) => join50.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
21893
21962
|
if (!this.isPartialSelect) {
|
|
21894
21963
|
if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") this.config.fields = { [baseTableName]: this.config.fields };
|
|
21895
21964
|
if (typeof tableName === "string" && !is(table, SQL)) {
|
|
@@ -23486,7 +23555,7 @@ var init_dialect = __esm({
|
|
|
23486
23555
|
if (!joins2) return;
|
|
23487
23556
|
const withEntries = Object.entries(joins2).filter(([_, v]) => v);
|
|
23488
23557
|
if (!withEntries.length) return;
|
|
23489
|
-
return sql.join(withEntries.map(([k,
|
|
23558
|
+
return sql.join(withEntries.map(([k, join50]) => {
|
|
23490
23559
|
const relation = tableConfig.relations[k];
|
|
23491
23560
|
const isSingle2 = is(relation, One);
|
|
23492
23561
|
const targetTable = aliasedTable(relation.targetTable, `d${currentDepth + 1}`);
|
|
@@ -23497,7 +23566,7 @@ var init_dialect = __esm({
|
|
|
23497
23566
|
table: targetTable,
|
|
23498
23567
|
mode: isSingle2 ? "first" : "many",
|
|
23499
23568
|
schema,
|
|
23500
|
-
queryConfig:
|
|
23569
|
+
queryConfig: join50,
|
|
23501
23570
|
tableConfig: schema[relation.targetTableName],
|
|
23502
23571
|
relationWhere: filter2,
|
|
23503
23572
|
isNested: true,
|
|
@@ -23511,7 +23580,7 @@ var init_dialect = __esm({
|
|
|
23511
23580
|
key: k,
|
|
23512
23581
|
selection: innerQuery.selection,
|
|
23513
23582
|
isArray: !isSingle2,
|
|
23514
|
-
isOptional: (relation.optional ?? false) ||
|
|
23583
|
+
isOptional: (relation.optional ?? false) || join50 !== true && !!join50.where
|
|
23515
23584
|
});
|
|
23516
23585
|
const jsonColumns = sql.join(innerQuery.selection.map((s) => {
|
|
23517
23586
|
return sql`${sql.raw(this.escapeString(s.key))}, ${s.selection ? sql`${jsonb2}(${sql.identifier(s.key)})` : sql.identifier(s.key)}`;
|
|
@@ -23933,7 +24002,7 @@ var init_update = __esm({
|
|
|
23933
24002
|
createJoin(joinType) {
|
|
23934
24003
|
return ((table, on) => {
|
|
23935
24004
|
const tableName = getTableLikeName(table);
|
|
23936
|
-
if (typeof tableName === "string" && this.config.joins.some((
|
|
24005
|
+
if (typeof tableName === "string" && this.config.joins.some((join50) => join50.alias === tableName)) throw new Error(`Alias "${tableName}" is already used in this query`);
|
|
23937
24006
|
if (typeof on === "function") {
|
|
23938
24007
|
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;
|
|
23939
24008
|
on = on(new Proxy(this.config.table[Table.Symbol.Columns], new SelectionProxyHandler({
|
|
@@ -25081,7 +25150,7 @@ async function withWriteRetry(fn, opts = {}) {
|
|
|
25081
25150
|
throw contentionErr;
|
|
25082
25151
|
}
|
|
25083
25152
|
function sleep(ms) {
|
|
25084
|
-
return new Promise((
|
|
25153
|
+
return new Promise((resolve17) => setTimeout(resolve17, ms));
|
|
25085
25154
|
}
|
|
25086
25155
|
var DEFAULT_MAX_ATTEMPTS, DEFAULT_BASE_DELAY_MS, DEFAULT_JITTER_MS;
|
|
25087
25156
|
var init_with_retry = __esm({
|
|
@@ -25093,9 +25162,250 @@ var init_with_retry = __esm({
|
|
|
25093
25162
|
}
|
|
25094
25163
|
});
|
|
25095
25164
|
|
|
25165
|
+
// packages/core/src/store/worktree-build-guard.ts
|
|
25166
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3, realpathSync as realpathSync3 } from "node:fs";
|
|
25167
|
+
import { createRequire } from "node:module";
|
|
25168
|
+
import { dirname as dirname3, isAbsolute as isAbsolute3, join as join5, relative as relative2, resolve as resolve2, sep as sep2 } from "node:path";
|
|
25169
|
+
import { fileURLToPath } from "node:url";
|
|
25170
|
+
function realOrResolved(path) {
|
|
25171
|
+
try {
|
|
25172
|
+
return realpathSync3(path);
|
|
25173
|
+
} catch {
|
|
25174
|
+
return resolve2(path);
|
|
25175
|
+
}
|
|
25176
|
+
}
|
|
25177
|
+
function isWithin(root, path) {
|
|
25178
|
+
const local = relative2(root, path);
|
|
25179
|
+
return local === "" || !isAbsolute3(local) && local !== ".." && !local.startsWith(`..${sep2}`);
|
|
25180
|
+
}
|
|
25181
|
+
function insideGitCheckout(dir) {
|
|
25182
|
+
let current = dir;
|
|
25183
|
+
for (; ; ) {
|
|
25184
|
+
if (existsSync4(join5(current, ".git"))) return true;
|
|
25185
|
+
const parent = dirname3(current);
|
|
25186
|
+
if (parent === current) return false;
|
|
25187
|
+
current = parent;
|
|
25188
|
+
}
|
|
25189
|
+
}
|
|
25190
|
+
function insideTestSandbox(path) {
|
|
25191
|
+
let dir = dirname3(path);
|
|
25192
|
+
for (; ; ) {
|
|
25193
|
+
if (existsSync4(join5(dir, TEST_SANDBOX_MARKER))) return !insideGitCheckout(dir);
|
|
25194
|
+
const parent = dirname3(dir);
|
|
25195
|
+
if (parent === dir) return false;
|
|
25196
|
+
dir = parent;
|
|
25197
|
+
}
|
|
25198
|
+
}
|
|
25199
|
+
function linkedWorktreeRootOf(path) {
|
|
25200
|
+
let dir = realOrResolved(path);
|
|
25201
|
+
for (; ; ) {
|
|
25202
|
+
if (isGitLinkedCheckout(dir)) return dir;
|
|
25203
|
+
if (existsSync4(join5(dir, ".git"))) return null;
|
|
25204
|
+
const parent = dirname3(dir);
|
|
25205
|
+
if (parent === dir) return null;
|
|
25206
|
+
dir = parent;
|
|
25207
|
+
}
|
|
25208
|
+
}
|
|
25209
|
+
function readBuildProvenance(codePath) {
|
|
25210
|
+
let dir = dirname3(codePath);
|
|
25211
|
+
for (; ; ) {
|
|
25212
|
+
const stamp = join5(dir, "build-provenance.json");
|
|
25213
|
+
if (existsSync4(stamp)) {
|
|
25214
|
+
try {
|
|
25215
|
+
const parsed = JSON.parse(readFileSync3(stamp, "utf8"));
|
|
25216
|
+
if (typeof parsed === "object" && parsed !== null && "linkedWorktree" in parsed) {
|
|
25217
|
+
const value = parsed.linkedWorktree;
|
|
25218
|
+
if (value === null || typeof value === "string") return { linkedWorktree: value };
|
|
25219
|
+
}
|
|
25220
|
+
} catch {
|
|
25221
|
+
}
|
|
25222
|
+
return null;
|
|
25223
|
+
}
|
|
25224
|
+
if (existsSync4(join5(dir, "package.json"))) return null;
|
|
25225
|
+
const parent = dirname3(dir);
|
|
25226
|
+
if (parent === dir) return null;
|
|
25227
|
+
dir = parent;
|
|
25228
|
+
}
|
|
25229
|
+
}
|
|
25230
|
+
function devBuildWorktree(options = {}) {
|
|
25231
|
+
const codePath = options.codePath ?? overrides?.codePath ?? fileURLToPath(import.meta.url);
|
|
25232
|
+
const provenance = options.provenance !== void 0 ? options.provenance : overrides?.provenance !== void 0 ? overrides.provenance : readBuildProvenance(codePath);
|
|
25233
|
+
if (provenance) return provenance.linkedWorktree;
|
|
25234
|
+
if (codePath.split(/[\\/]/).includes("node_modules")) return null;
|
|
25235
|
+
return linkedWorktreeRootOf(codePath);
|
|
25236
|
+
}
|
|
25237
|
+
function schemaWriteRefusal(dbPath, options = {}) {
|
|
25238
|
+
const env = options.env ?? overrides?.env ?? process.env;
|
|
25239
|
+
const buildWorktree = devBuildWorktree(options);
|
|
25240
|
+
if (buildWorktree === null) return null;
|
|
25241
|
+
const store = realOrResolved(dbPath);
|
|
25242
|
+
if (isWithin(realOrResolved(buildWorktree), store)) return null;
|
|
25243
|
+
if (env["VITEST"]) return null;
|
|
25244
|
+
const honourTestSandbox = options.honourTestSandbox ?? overrides?.honourTestSandbox ?? true;
|
|
25245
|
+
if (honourTestSandbox && insideTestSandbox(store)) return null;
|
|
25246
|
+
if (env[ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV] === "1") return null;
|
|
25247
|
+
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).`;
|
|
25248
|
+
}
|
|
25249
|
+
function decisionFor(dbPath) {
|
|
25250
|
+
const key = realOrResolved(dbPath);
|
|
25251
|
+
if (!decisions.has(key)) decisions.set(key, schemaWriteRefusal(key));
|
|
25252
|
+
return decisions.get(key) ?? null;
|
|
25253
|
+
}
|
|
25254
|
+
function isWorktreeBuildSchemaError(error48) {
|
|
25255
|
+
return error48 instanceof Error && error48.message.includes(E_WORKTREE_BUILD_SCHEMA);
|
|
25256
|
+
}
|
|
25257
|
+
function codes() {
|
|
25258
|
+
if (authorizerCodes) return authorizerCodes;
|
|
25259
|
+
const sqlite = createRequire(import.meta.url)("node:sqlite").constants;
|
|
25260
|
+
authorizerCodes = {
|
|
25261
|
+
sqlite,
|
|
25262
|
+
creates: /* @__PURE__ */ new Map([
|
|
25263
|
+
[sqlite.SQLITE_CREATE_TABLE, "table"],
|
|
25264
|
+
[sqlite.SQLITE_CREATE_VTABLE, "table"],
|
|
25265
|
+
[sqlite.SQLITE_CREATE_INDEX, "index"],
|
|
25266
|
+
[sqlite.SQLITE_CREATE_TRIGGER, "trigger"],
|
|
25267
|
+
[sqlite.SQLITE_CREATE_VIEW, "view"]
|
|
25268
|
+
]),
|
|
25269
|
+
changes: /* @__PURE__ */ new Set([
|
|
25270
|
+
sqlite.SQLITE_ALTER_TABLE,
|
|
25271
|
+
sqlite.SQLITE_DROP_TABLE,
|
|
25272
|
+
sqlite.SQLITE_DROP_INDEX,
|
|
25273
|
+
sqlite.SQLITE_DROP_TRIGGER,
|
|
25274
|
+
sqlite.SQLITE_DROP_VIEW,
|
|
25275
|
+
sqlite.SQLITE_DROP_VTABLE
|
|
25276
|
+
])
|
|
25277
|
+
};
|
|
25278
|
+
return authorizerCodes;
|
|
25279
|
+
}
|
|
25280
|
+
function attachRefusal(name15) {
|
|
25281
|
+
if (name15 === "" || name15 === ":memory:") return null;
|
|
25282
|
+
if (typeof name15 !== "string" || /^file:/i.test(name15) || name15.includes("?")) {
|
|
25283
|
+
return UNKNOWN_ATTACH_REFUSAL;
|
|
25284
|
+
}
|
|
25285
|
+
return decisionFor(name15);
|
|
25286
|
+
}
|
|
25287
|
+
function readSchemas(nativeDb) {
|
|
25288
|
+
const schemas = /* @__PURE__ */ new Map();
|
|
25289
|
+
const list = nativeDb.prepare("PRAGMA database_list").all();
|
|
25290
|
+
for (const { name: name15, file: file2 } of list) {
|
|
25291
|
+
if (name15 === "temp") continue;
|
|
25292
|
+
const rows = nativeDb.prepare(`SELECT type, name FROM "${name15.replaceAll('"', '""')}".sqlite_master`).all();
|
|
25293
|
+
schemas.set(name15.toLowerCase(), {
|
|
25294
|
+
refusal: file2 ? decisionFor(file2) : null,
|
|
25295
|
+
// '' = in-memory
|
|
25296
|
+
objects: new Set(rows.map((r) => `${r.type}:${r.name}`))
|
|
25297
|
+
});
|
|
25298
|
+
}
|
|
25299
|
+
return schemas;
|
|
25300
|
+
}
|
|
25301
|
+
function guardActive() {
|
|
25302
|
+
const env = overrides?.env ?? process.env;
|
|
25303
|
+
if (env["VITEST"]) return false;
|
|
25304
|
+
if (overrides) return devBuildWorktree() !== null;
|
|
25305
|
+
if (processBuildWorktree === void 0) processBuildWorktree = devBuildWorktree();
|
|
25306
|
+
return processBuildWorktree !== null;
|
|
25307
|
+
}
|
|
25308
|
+
function installSchemaWriteGuard(nativeDb) {
|
|
25309
|
+
if (!guardActive()) return false;
|
|
25310
|
+
const location = nativeDb.location();
|
|
25311
|
+
const mainRefusal = location ? decisionFor(location) : null;
|
|
25312
|
+
if (typeof nativeDb.setAuthorizer !== "function") {
|
|
25313
|
+
if (mainRefusal) throw new WorktreeBuildSchemaError(mainRefusal);
|
|
25314
|
+
return false;
|
|
25315
|
+
}
|
|
25316
|
+
const state = {
|
|
25317
|
+
schemas: readSchemas(nativeDb),
|
|
25318
|
+
unmappedAttachRefusal: null,
|
|
25319
|
+
stale: false,
|
|
25320
|
+
lastDenied: null
|
|
25321
|
+
};
|
|
25322
|
+
guards.set(nativeDb, state);
|
|
25323
|
+
const { sqlite, creates, changes } = codes();
|
|
25324
|
+
nativeDb.setAuthorizer((action, arg1, arg2, dbName) => {
|
|
25325
|
+
if (action === sqlite.SQLITE_ATTACH) {
|
|
25326
|
+
const refusal2 = attachRefusal(arg1);
|
|
25327
|
+
if (refusal2 && !state.unmappedAttachRefusal) state.unmappedAttachRefusal = refusal2;
|
|
25328
|
+
return sqlite.SQLITE_OK;
|
|
25329
|
+
}
|
|
25330
|
+
if (action === sqlite.SQLITE_DETACH) {
|
|
25331
|
+
state.stale = true;
|
|
25332
|
+
return sqlite.SQLITE_OK;
|
|
25333
|
+
}
|
|
25334
|
+
const createType = creates.get(action);
|
|
25335
|
+
if (createType === void 0 && !changes.has(action)) return sqlite.SQLITE_OK;
|
|
25336
|
+
const schema = ((action === sqlite.SQLITE_ALTER_TABLE ? arg1 : dbName) ?? "main").toLowerCase();
|
|
25337
|
+
if (schema === "temp") return sqlite.SQLITE_OK;
|
|
25338
|
+
const mapped = state.schemas.get(schema);
|
|
25339
|
+
const policy = state.stale ? void 0 : mapped;
|
|
25340
|
+
const refusal = policy ? policy.refusal : (mapped?.refusal ?? null) || state.unmappedAttachRefusal;
|
|
25341
|
+
if (refusal === null) return sqlite.SQLITE_OK;
|
|
25342
|
+
if (createType !== void 0 && policy?.objects.has(`${createType}:${arg1}`)) {
|
|
25343
|
+
return sqlite.SQLITE_OK;
|
|
25344
|
+
}
|
|
25345
|
+
state.lastDenied = {
|
|
25346
|
+
what: createType !== void 0 ? `CREATE ${createType} ${schema}.${arg1}` : `schema change on ${schema}.${(action === sqlite.SQLITE_ALTER_TABLE ? arg2 : arg1) ?? ""}`,
|
|
25347
|
+
refusal
|
|
25348
|
+
};
|
|
25349
|
+
return sqlite.SQLITE_DENY;
|
|
25350
|
+
});
|
|
25351
|
+
return mainRefusal !== null;
|
|
25352
|
+
}
|
|
25353
|
+
function refreshSchemaWriteGuard(nativeDb) {
|
|
25354
|
+
const state = guards.get(nativeDb);
|
|
25355
|
+
if (!state) return;
|
|
25356
|
+
state.schemas = readSchemas(nativeDb);
|
|
25357
|
+
state.unmappedAttachRefusal = null;
|
|
25358
|
+
state.stale = false;
|
|
25359
|
+
}
|
|
25360
|
+
function explainSchemaWriteDenial(nativeDb, error48) {
|
|
25361
|
+
if (!(error48 instanceof Error) || !/not authorized/i.test(error48.message)) return error48;
|
|
25362
|
+
const denied = guards.get(nativeDb)?.lastDenied;
|
|
25363
|
+
if (!denied) return error48;
|
|
25364
|
+
return new WorktreeBuildSchemaError(`${denied.refusal} Denied: ${denied.what}.`);
|
|
25365
|
+
}
|
|
25366
|
+
function pendingMigrations(nativeDb, migrations) {
|
|
25367
|
+
const hasJournal = nativeDb.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = '__drizzle_migrations'").get();
|
|
25368
|
+
const applied = hasJournal ? new Set(
|
|
25369
|
+
nativeDb.prepare('SELECT hash FROM main."__drizzle_migrations"').all().map((row) => row.hash)
|
|
25370
|
+
) : /* @__PURE__ */ new Set();
|
|
25371
|
+
return migrations.filter((m) => !applied.has(m.hash)).map((m) => m.name ?? m.hash);
|
|
25372
|
+
}
|
|
25373
|
+
function assertNoPendingMigrationsForWorktreeBuild(nativeDb, migrations) {
|
|
25374
|
+
const dbPath = nativeDb.location();
|
|
25375
|
+
if (!dbPath) return;
|
|
25376
|
+
const refusal = decisionFor(dbPath);
|
|
25377
|
+
if (refusal === null) return;
|
|
25378
|
+
const pending = pendingMigrations(nativeDb, migrations);
|
|
25379
|
+
if (pending.length === 0) return;
|
|
25380
|
+
throw new WorktreeBuildSchemaError(`${refusal} Pending migrations: ${pending.join(", ")}.`);
|
|
25381
|
+
}
|
|
25382
|
+
var ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV, TEST_SANDBOX_MARKER, E_WORKTREE_BUILD_SCHEMA, overrides, decisions, WorktreeBuildSchemaError, authorizerCodes, guards, UNKNOWN_ATTACH_REFUSAL, processBuildWorktree;
|
|
25383
|
+
var init_worktree_build_guard = __esm({
|
|
25384
|
+
"packages/core/src/store/worktree-build-guard.ts"() {
|
|
25385
|
+
"use strict";
|
|
25386
|
+
init_src();
|
|
25387
|
+
init_errors2();
|
|
25388
|
+
init_project_scope();
|
|
25389
|
+
ALLOW_WORKTREE_BUILD_MIGRATIONS_ENV = "CLEO_ALLOW_WORKTREE_BUILD_MIGRATIONS";
|
|
25390
|
+
TEST_SANDBOX_MARKER = ".cleo-test-sandbox";
|
|
25391
|
+
E_WORKTREE_BUILD_SCHEMA = "E_WORKTREE_BUILD_SCHEMA";
|
|
25392
|
+
overrides = null;
|
|
25393
|
+
decisions = /* @__PURE__ */ new Map();
|
|
25394
|
+
WorktreeBuildSchemaError = class extends CleoError {
|
|
25395
|
+
constructor(message) {
|
|
25396
|
+
super(8 /* CONFIG_ERROR */, `${E_WORKTREE_BUILD_SCHEMA}: ${message}`, {
|
|
25397
|
+
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.`
|
|
25398
|
+
});
|
|
25399
|
+
}
|
|
25400
|
+
};
|
|
25401
|
+
guards = /* @__PURE__ */ new WeakMap();
|
|
25402
|
+
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";
|
|
25403
|
+
}
|
|
25404
|
+
});
|
|
25405
|
+
|
|
25096
25406
|
// packages/core/src/store/migration-manager.ts
|
|
25097
|
-
import { copyFileSync, existsSync as
|
|
25098
|
-
import { dirname as
|
|
25407
|
+
import { copyFileSync, existsSync as existsSync5 } from "node:fs";
|
|
25408
|
+
import { dirname as dirname4, join as join6 } from "node:path";
|
|
25099
25409
|
function stripSqlComments(sql29) {
|
|
25100
25410
|
return sql29.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
25101
25411
|
}
|
|
@@ -25134,10 +25444,10 @@ function computeEliminatedTables(migrations) {
|
|
|
25134
25444
|
return eliminated;
|
|
25135
25445
|
}
|
|
25136
25446
|
function resolveConsolidationCutoverPrefix(migrationsFolder) {
|
|
25137
|
-
const parent =
|
|
25447
|
+
const parent = dirname4(migrationsFolder);
|
|
25138
25448
|
for (const setName of ["drizzle-cleo-project", "drizzle-cleo-global"]) {
|
|
25139
|
-
const folder =
|
|
25140
|
-
if (!
|
|
25449
|
+
const folder = join6(parent, setName);
|
|
25450
|
+
if (!existsSync5(folder)) continue;
|
|
25141
25451
|
try {
|
|
25142
25452
|
const consolidation = readMigrationFiles({ migrationsFolder: folder }).find(
|
|
25143
25453
|
(m) => /-consolidation-cleo-/.test(m.name ?? "")
|
|
@@ -25161,7 +25471,7 @@ function tableExists(nativeDb, tableName) {
|
|
|
25161
25471
|
}
|
|
25162
25472
|
function createSafetyBackup(dbPath) {
|
|
25163
25473
|
const backupPath = dbPath.replace(/\.db$/, "-pre-cleo.db.bak");
|
|
25164
|
-
if (!
|
|
25474
|
+
if (!existsSync5(backupPath)) {
|
|
25165
25475
|
try {
|
|
25166
25476
|
copyFileSync(dbPath, backupPath);
|
|
25167
25477
|
} catch {
|
|
@@ -25279,6 +25589,16 @@ function readSiblingMigrationHashes(siblingFolder) {
|
|
|
25279
25589
|
return /* @__PURE__ */ new Set();
|
|
25280
25590
|
}
|
|
25281
25591
|
}
|
|
25592
|
+
function readSiblingNewestMillis(siblingFolder) {
|
|
25593
|
+
try {
|
|
25594
|
+
return Math.max(
|
|
25595
|
+
0,
|
|
25596
|
+
...readMigrationFiles({ migrationsFolder: siblingFolder }).map((m) => m.folderMillis)
|
|
25597
|
+
);
|
|
25598
|
+
} catch {
|
|
25599
|
+
return 0;
|
|
25600
|
+
}
|
|
25601
|
+
}
|
|
25282
25602
|
function ensureJournalHashUnique(nativeDb) {
|
|
25283
25603
|
if (!tableExists(nativeDb, "__drizzle_migrations")) return;
|
|
25284
25604
|
try {
|
|
@@ -25327,6 +25647,7 @@ function upgradeSharedJournalFormat(nativeDb, lineageFolders) {
|
|
|
25327
25647
|
return { named, unnamed: rows.length - named };
|
|
25328
25648
|
}
|
|
25329
25649
|
function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsystem, siblingMigrationsFolders = []) {
|
|
25650
|
+
assertNoPendingMigrationsForWorktreeBuild(nativeDb, readMigrationFiles({ migrationsFolder }));
|
|
25330
25651
|
const eliminatedTables = computeEliminatedTables(readMigrationFiles({ migrationsFolder }));
|
|
25331
25652
|
const cutoverPrefix = resolveConsolidationCutoverPrefix(migrationsFolder);
|
|
25332
25653
|
if (siblingMigrationsFolders.length > 0)
|
|
@@ -25358,8 +25679,15 @@ function reconcileJournal(nativeDb, migrationsFolder, existenceTable2, logSubsys
|
|
|
25358
25679
|
knownHashes.add(m);
|
|
25359
25680
|
}
|
|
25360
25681
|
}
|
|
25361
|
-
const
|
|
25362
|
-
|
|
25682
|
+
const newestKnownMillis = Math.max(
|
|
25683
|
+
0,
|
|
25684
|
+
...localMigrations.map((m) => m.folderMillis),
|
|
25685
|
+
...siblingMigrationsFolders.filter((folder) => folder !== migrationsFolder).map(readSiblingNewestMillis)
|
|
25686
|
+
);
|
|
25687
|
+
const dbEntries = nativeDb.prepare('SELECT id, hash, created_at FROM "__drizzle_migrations"').all();
|
|
25688
|
+
const orphanedEntries = dbEntries.filter(
|
|
25689
|
+
(e) => !knownHashes.has(e.hash) && !(Number(e.created_at) > newestKnownMillis)
|
|
25690
|
+
);
|
|
25363
25691
|
const hasOrphanedEntries = orphanedEntries.length > 0;
|
|
25364
25692
|
if (hasOrphanedEntries) {
|
|
25365
25693
|
const dbHashes = new Set(dbEntries.map((e) => e.hash));
|
|
@@ -25601,6 +25929,8 @@ function sanitizeMigrationStatements(migrations) {
|
|
|
25601
25929
|
}
|
|
25602
25930
|
function migrateSanitized(db, config2) {
|
|
25603
25931
|
const raw = readMigrationFiles(config2);
|
|
25932
|
+
const client = db.$client;
|
|
25933
|
+
if (client) assertNoPendingMigrationsForWorktreeBuild(client, raw);
|
|
25604
25934
|
const sanitized = sanitizeMigrationStatements(raw);
|
|
25605
25935
|
migrateSync(sanitized, db._.session, config2);
|
|
25606
25936
|
}
|
|
@@ -25664,6 +25994,7 @@ var init_migration_manager = __esm({
|
|
|
25664
25994
|
init_sqlite_core();
|
|
25665
25995
|
init_logger2();
|
|
25666
25996
|
init_with_retry();
|
|
25997
|
+
init_worktree_build_guard();
|
|
25667
25998
|
MAX_MIGRATION_RETRIES = 5;
|
|
25668
25999
|
MIGRATION_RETRY_BASE_DELAY_MS = 100;
|
|
25669
26000
|
MIGRATION_RETRY_MAX_DELAY_MS = 2e3;
|
|
@@ -25673,13 +26004,13 @@ var init_migration_manager = __esm({
|
|
|
25673
26004
|
});
|
|
25674
26005
|
|
|
25675
26006
|
// packages/core/src/store/relocated-store-guard.ts
|
|
25676
|
-
import { existsSync as
|
|
25677
|
-
import { createRequire } from "node:module";
|
|
25678
|
-
import { basename as basename3, dirname as
|
|
26007
|
+
import { existsSync as existsSync6, realpathSync as realpathSync4 } from "node:fs";
|
|
26008
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
26009
|
+
import { basename as basename3, dirname as dirname5 } from "node:path";
|
|
25679
26010
|
import { readDeclaredProjectIdentity as readDeclaredProjectIdentity2, readPortableProjectId } from "@cleocode/paths";
|
|
25680
26011
|
function real2(p) {
|
|
25681
26012
|
try {
|
|
25682
|
-
return
|
|
26013
|
+
return realpathSync4(p);
|
|
25683
26014
|
} catch {
|
|
25684
26015
|
return p;
|
|
25685
26016
|
}
|
|
@@ -25696,7 +26027,7 @@ function liveElsewhere(globalDbPath, projectId, root) {
|
|
|
25696
26027
|
"SELECT project_path AS projectPath FROM nexus_project_registry WHERE project_id = ?"
|
|
25697
26028
|
).get(projectId);
|
|
25698
26029
|
const live = row?.projectPath;
|
|
25699
|
-
if (!live || paths.has(live) || !
|
|
26030
|
+
if (!live || paths.has(live) || !existsSync6(live)) return null;
|
|
25700
26031
|
if (!isStrictlyInsideDir(root, live)) return null;
|
|
25701
26032
|
return readDeclaredProjectIdentity2(live)?.projectId === projectId ? live : null;
|
|
25702
26033
|
} catch {
|
|
@@ -25710,14 +26041,14 @@ function detectRelocatedRoot(root, globalDbPath) {
|
|
|
25710
26041
|
if (tombstone)
|
|
25711
26042
|
return { projectId: tombstone.projectId, movedTo: tombstone.movedTo, via: "tombstone" };
|
|
25712
26043
|
const declared = readPortableProjectId(root);
|
|
25713
|
-
if (declared.status !== "valid" || !
|
|
26044
|
+
if (declared.status !== "valid" || !existsSync6(globalDbPath)) return null;
|
|
25714
26045
|
const movedTo = liveElsewhere(globalDbPath, declared.projectId, root);
|
|
25715
26046
|
return movedTo ? { projectId: declared.projectId, movedTo, via: "registry" } : null;
|
|
25716
26047
|
}
|
|
25717
26048
|
function assertStoreNotRelocated(dbPath, globalDbPath) {
|
|
25718
|
-
if (basename3(dbPath) !== "cleo.db" || basename3(
|
|
25719
|
-
if (
|
|
25720
|
-
const root =
|
|
26049
|
+
if (basename3(dbPath) !== "cleo.db" || basename3(dirname5(dbPath)) !== ".cleo") return;
|
|
26050
|
+
if (existsSync6(dbPath) || globalDbPath === dbPath) return;
|
|
26051
|
+
const root = dirname5(dirname5(dbPath));
|
|
25721
26052
|
if (_adopted.has(root)) return;
|
|
25722
26053
|
const moved = detectRelocatedRoot(root, globalDbPath);
|
|
25723
26054
|
if (moved) throw projectMovedError(root, moved, void 0, moved.via);
|
|
@@ -25727,17 +26058,17 @@ var init_relocated_store_guard = __esm({
|
|
|
25727
26058
|
"packages/core/src/store/relocated-store-guard.ts"() {
|
|
25728
26059
|
"use strict";
|
|
25729
26060
|
init_project_tombstone();
|
|
25730
|
-
_require =
|
|
26061
|
+
_require = createRequire2(import.meta.url);
|
|
25731
26062
|
_adopted = /* @__PURE__ */ new Set();
|
|
25732
26063
|
}
|
|
25733
26064
|
});
|
|
25734
26065
|
|
|
25735
26066
|
// packages/core/src/store/resolve-migrations-folder.ts
|
|
25736
|
-
import { createRequire as
|
|
25737
|
-
import { dirname as
|
|
25738
|
-
import { fileURLToPath } from "node:url";
|
|
26067
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
26068
|
+
import { dirname as dirname6, join as join7 } from "node:path";
|
|
26069
|
+
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
25739
26070
|
function coreRootFromEntry(entryPath) {
|
|
25740
|
-
return
|
|
26071
|
+
return dirname6(dirname6(entryPath));
|
|
25741
26072
|
}
|
|
25742
26073
|
function resolveConsolidatedJournalSiblings(ownSetName) {
|
|
25743
26074
|
return CONSOLIDATED_JOURNAL_LINEAGES.filter((name15) => name15 !== ownSetName).map(
|
|
@@ -25747,14 +26078,14 @@ function resolveConsolidatedJournalSiblings(ownSetName) {
|
|
|
25747
26078
|
function resolveCorePackageMigrationsFolder(setName) {
|
|
25748
26079
|
try {
|
|
25749
26080
|
const resolved = import.meta.resolve("@cleocode/core", import.meta.url);
|
|
25750
|
-
const entryPath =
|
|
25751
|
-
return
|
|
26081
|
+
const entryPath = fileURLToPath2(resolved);
|
|
26082
|
+
return join7(coreRootFromEntry(entryPath), "migrations", setName);
|
|
25752
26083
|
} catch {
|
|
25753
26084
|
}
|
|
25754
|
-
const _require7 =
|
|
26085
|
+
const _require7 = createRequire3(import.meta.url);
|
|
25755
26086
|
try {
|
|
25756
26087
|
const entryPath = _require7.resolve("@cleocode/core");
|
|
25757
|
-
return
|
|
26088
|
+
return join7(coreRootFromEntry(entryPath), "migrations", setName);
|
|
25758
26089
|
} catch (err) {
|
|
25759
26090
|
throw new Error(
|
|
25760
26091
|
`resolveCorePackageMigrationsFolder("${setName}"): cannot locate @cleocode/core from "${import.meta.url}". Ensure @cleocode/core is installed (workspace or npm). Original error: ${err.message}`
|
|
@@ -25850,11 +26181,11 @@ var init_sqlite_pragmas = __esm({
|
|
|
25850
26181
|
});
|
|
25851
26182
|
|
|
25852
26183
|
// packages/core/src/store/worktree-isolation-guard.ts
|
|
25853
|
-
import { basename as basename4, dirname as
|
|
26184
|
+
import { basename as basename4, dirname as dirname7, join as join8, resolve as resolve3 } from "node:path";
|
|
25854
26185
|
function assertStorePathIsNotWorktreeResident(role, dbPath) {
|
|
25855
|
-
const cleoDir =
|
|
26186
|
+
const cleoDir = dirname7(dbPath);
|
|
25856
26187
|
if (basename4(cleoDir) !== ".cleo") return;
|
|
25857
|
-
const projectRoot =
|
|
26188
|
+
const projectRoot = dirname7(cleoDir);
|
|
25858
26189
|
if (!isGitLinkedCheckout(projectRoot)) return;
|
|
25859
26190
|
if (process.env["CLEO_ALLOW_WORKTREE_DB_CREATE"] === "1") {
|
|
25860
26191
|
process.stderr.write(
|
|
@@ -25879,7 +26210,7 @@ function assertDbPathIsNotWorktreeResident(role, cwd) {
|
|
|
25879
26210
|
} catch {
|
|
25880
26211
|
return;
|
|
25881
26212
|
}
|
|
25882
|
-
assertStorePathIsNotWorktreeResident(role,
|
|
26213
|
+
assertStorePathIsNotWorktreeResident(role, join8(cleoDir, PROJECT_STORE_FILENAME2));
|
|
25883
26214
|
}
|
|
25884
26215
|
var PROJECT_STORE_FILENAME2;
|
|
25885
26216
|
var init_worktree_isolation_guard = __esm({
|
|
@@ -25899,10 +26230,10 @@ __export(sqlite_native_exports, {
|
|
|
25899
26230
|
getDbSyncConstructor: () => getDbSyncConstructor,
|
|
25900
26231
|
openNativeDatabase: () => openNativeDatabase
|
|
25901
26232
|
});
|
|
25902
|
-
import { realpathSync as
|
|
25903
|
-
import { createRequire as
|
|
26233
|
+
import { realpathSync as realpathSync5 } from "node:fs";
|
|
26234
|
+
import { createRequire as createRequire4 } from "node:module";
|
|
25904
26235
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
25905
|
-
import { delimiter, dirname as
|
|
26236
|
+
import { delimiter, dirname as dirname8, isAbsolute as isAbsolute4, join as join9, resolve as resolve4, sep as sep3 } from "node:path";
|
|
25906
26237
|
function getDbSyncConstructor() {
|
|
25907
26238
|
if (_ctor === null) {
|
|
25908
26239
|
const mod = _require2("node:sqlite");
|
|
@@ -25911,19 +26242,19 @@ function getDbSyncConstructor() {
|
|
|
25911
26242
|
return _ctor;
|
|
25912
26243
|
}
|
|
25913
26244
|
function resolveAbsoluteSafe(p) {
|
|
25914
|
-
const abs =
|
|
26245
|
+
const abs = isAbsolute4(p) ? p : resolve4(p);
|
|
25915
26246
|
try {
|
|
25916
|
-
return
|
|
26247
|
+
return realpathSync5(abs);
|
|
25917
26248
|
} catch {
|
|
25918
26249
|
const missingParts = [];
|
|
25919
26250
|
let cursor = abs;
|
|
25920
26251
|
while (true) {
|
|
25921
|
-
const parent =
|
|
26252
|
+
const parent = dirname8(cursor);
|
|
25922
26253
|
if (parent === cursor) return abs;
|
|
25923
|
-
missingParts.unshift(cursor.slice(parent.length + (parent.endsWith(
|
|
26254
|
+
missingParts.unshift(cursor.slice(parent.length + (parent.endsWith(sep3) ? 0 : 1)));
|
|
25924
26255
|
cursor = parent;
|
|
25925
26256
|
try {
|
|
25926
|
-
return
|
|
26257
|
+
return join9(realpathSync5(cursor), ...missingParts);
|
|
25927
26258
|
} catch {
|
|
25928
26259
|
}
|
|
25929
26260
|
}
|
|
@@ -25931,7 +26262,7 @@ function resolveAbsoluteSafe(p) {
|
|
|
25931
26262
|
}
|
|
25932
26263
|
function isPathUnder(child, parent) {
|
|
25933
26264
|
if (child === parent) return true;
|
|
25934
|
-
const withSep = parent.endsWith(
|
|
26265
|
+
const withSep = parent.endsWith(sep3) ? parent : parent + sep3;
|
|
25935
26266
|
return child.startsWith(withSep);
|
|
25936
26267
|
}
|
|
25937
26268
|
function assertVitestSafePath(path) {
|
|
@@ -25954,6 +26285,7 @@ function openNativeDatabase(path, options) {
|
|
|
25954
26285
|
assertVitestSafePath(path);
|
|
25955
26286
|
const DatabaseSyncCtor = getDbSyncConstructor();
|
|
25956
26287
|
const db = new DatabaseSyncCtor(path, {
|
|
26288
|
+
// schema-guard-exempt: the native chokepoint; every writable caller installs the guard
|
|
25957
26289
|
enableForeignKeyConstraints: true,
|
|
25958
26290
|
readOnly: options?.readonly ?? false,
|
|
25959
26291
|
// Default handle-open lock timeout mirrors the SSoT busy_timeout
|
|
@@ -26005,7 +26337,7 @@ var init_sqlite_native = __esm({
|
|
|
26005
26337
|
"packages/core/src/store/sqlite-native.ts"() {
|
|
26006
26338
|
"use strict";
|
|
26007
26339
|
init_sqlite_pragmas();
|
|
26008
|
-
_require2 =
|
|
26340
|
+
_require2 = createRequire4(import.meta.url);
|
|
26009
26341
|
_ctor = null;
|
|
26010
26342
|
}
|
|
26011
26343
|
});
|
|
@@ -26079,7 +26411,7 @@ var init_writer_lease_schema = __esm({
|
|
|
26079
26411
|
// packages/core/src/store/writer-lease.ts
|
|
26080
26412
|
import { AsyncLocalStorage as AsyncLocalStorage3 } from "node:async_hooks";
|
|
26081
26413
|
import { randomUUID } from "node:crypto";
|
|
26082
|
-
import { realpathSync as
|
|
26414
|
+
import { realpathSync as realpathSync6, statSync as statSync2 } from "node:fs";
|
|
26083
26415
|
import { resolve as resolvePath } from "node:path";
|
|
26084
26416
|
function log() {
|
|
26085
26417
|
if (_log === null) _log = getLogger("writer-lease");
|
|
@@ -26169,7 +26501,7 @@ function resolveDbIdentity(db) {
|
|
|
26169
26501
|
return identity;
|
|
26170
26502
|
}
|
|
26171
26503
|
function sleepAsync(ms) {
|
|
26172
|
-
return new Promise((
|
|
26504
|
+
return new Promise((resolve17) => setTimeout(resolve17, Math.max(0, Math.round(ms))));
|
|
26173
26505
|
}
|
|
26174
26506
|
function isPidAlive(pid) {
|
|
26175
26507
|
try {
|
|
@@ -26508,7 +26840,7 @@ function assertColdOpenFile(frame) {
|
|
|
26508
26840
|
async function withRequiredColdOpenLease(scope, nativeDb, fn, opts) {
|
|
26509
26841
|
opts.execution?.assertActive();
|
|
26510
26842
|
const captured = opts.requiredIdentity;
|
|
26511
|
-
const path =
|
|
26843
|
+
const path = realpathSync6(captured.dbPath);
|
|
26512
26844
|
const identity = statSync2(path, { bigint: true });
|
|
26513
26845
|
if (captured.scope !== scope || captured.fileDevice !== String(identity.dev) || captured.fileInode !== String(identity.ino)) {
|
|
26514
26846
|
throw new LeaseUnavailableError(
|
|
@@ -26541,6 +26873,7 @@ async function withRequiredColdOpenLease(scope, nativeDb, fn, opts) {
|
|
|
26541
26873
|
}
|
|
26542
26874
|
const remaining = opts.execution ? Math.max(1, opts.execution.deadlineAt - Date.now()) : ACQUIRE_DEADLINE_MS;
|
|
26543
26875
|
const owned = openNativeDatabase(path, { timeout: Math.min(ACQUIRE_DEADLINE_MS, remaining) });
|
|
26876
|
+
installSchemaWriteGuard(owned);
|
|
26544
26877
|
try {
|
|
26545
26878
|
opts.execution?.assertActive();
|
|
26546
26879
|
const afterOpen = statSync2(path, { bigint: true });
|
|
@@ -26734,6 +27067,7 @@ var init_writer_lease = __esm({
|
|
|
26734
27067
|
init_background_ops();
|
|
26735
27068
|
init_dual_scope_db();
|
|
26736
27069
|
init_sqlite_native();
|
|
27070
|
+
init_worktree_build_guard();
|
|
26737
27071
|
init_writer_lease_schema();
|
|
26738
27072
|
DEFAULT_TTL_MS = 3e4;
|
|
26739
27073
|
DEFAULT_PRIORITY = 100;
|
|
@@ -27276,10 +27610,10 @@ var init_monitor = __esm({
|
|
|
27276
27610
|
|
|
27277
27611
|
// packages/core/src/resources/supervisor-admit.ts
|
|
27278
27612
|
import { connect } from "node:net";
|
|
27279
|
-
import { join as
|
|
27613
|
+
import { join as join10 } from "node:path";
|
|
27280
27614
|
import { getCleoHome as getCleoHome2 } from "@cleocode/paths";
|
|
27281
27615
|
function resolveSupervisorSocketPath() {
|
|
27282
|
-
return process.env.CLEO_SUPERVISOR_SOCKET ??
|
|
27616
|
+
return process.env.CLEO_SUPERVISOR_SOCKET ?? join10(getCleoHome2(), SUPERVISOR_SOCKET_NAME);
|
|
27283
27617
|
}
|
|
27284
27618
|
async function sendResourceAdmit(socketPath, cls, holderId, budget) {
|
|
27285
27619
|
const result = await sendLeaseRequest(
|
|
@@ -27302,7 +27636,7 @@ async function sendResourceRelease(socketPath, cls, holderId) {
|
|
|
27302
27636
|
return { unavailable: true, reason: `unexpected response kind: ${result.kind}` };
|
|
27303
27637
|
}
|
|
27304
27638
|
function sendLeaseRequest(socketPath, request, expectedKind) {
|
|
27305
|
-
return new Promise((
|
|
27639
|
+
return new Promise((resolve17) => {
|
|
27306
27640
|
const id = `ra-${process.pid}-${request.kind}`;
|
|
27307
27641
|
const envelope = LeaseIpcRequestEnvelopeSchema.parse({
|
|
27308
27642
|
protocol_version: LEASE_IPC_PROTOCOL_VERSION,
|
|
@@ -27320,7 +27654,7 @@ function sendLeaseRequest(socketPath, request, expectedKind) {
|
|
|
27320
27654
|
settled = true;
|
|
27321
27655
|
socket.removeAllListeners();
|
|
27322
27656
|
socket.destroy();
|
|
27323
|
-
|
|
27657
|
+
resolve17(value);
|
|
27324
27658
|
};
|
|
27325
27659
|
const degrade = (reason) => done({ unavailable: true, reason });
|
|
27326
27660
|
socket.setTimeout(REQUEST_TIMEOUT_MS);
|
|
@@ -27391,9 +27725,9 @@ __export(governor_exports, {
|
|
|
27391
27725
|
resolveGovernorMode: () => resolveGovernorMode,
|
|
27392
27726
|
slotFileCount: () => slotFileCount
|
|
27393
27727
|
});
|
|
27394
|
-
import { existsSync as
|
|
27728
|
+
import { existsSync as existsSync7, mkdirSync, readdirSync as readdirSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
27395
27729
|
import { availableParallelism, totalmem } from "node:os";
|
|
27396
|
-
import { join as
|
|
27730
|
+
import { join as join11 } from "node:path";
|
|
27397
27731
|
import lockfile from "proper-lockfile";
|
|
27398
27732
|
function log2() {
|
|
27399
27733
|
if (_log2 === null) _log2 = getLogger("resource-governor");
|
|
@@ -27462,14 +27796,14 @@ function clamp(lo, v, hi) {
|
|
|
27462
27796
|
return Math.max(lo, Math.min(v, hi));
|
|
27463
27797
|
}
|
|
27464
27798
|
function governorSlotDir(cls) {
|
|
27465
|
-
return
|
|
27799
|
+
return join11(getCleoHome(), "locks", `resource-${cls}`);
|
|
27466
27800
|
}
|
|
27467
27801
|
function ensureSlotFiles(dir, count) {
|
|
27468
|
-
if (!
|
|
27802
|
+
if (!existsSync7(dir)) mkdirSync(dir, { recursive: true });
|
|
27469
27803
|
const paths = [];
|
|
27470
27804
|
for (let i = 0; i < count; i++) {
|
|
27471
|
-
const p =
|
|
27472
|
-
if (!
|
|
27805
|
+
const p = join11(dir, `slot-${i}.lock`);
|
|
27806
|
+
if (!existsSync7(p)) writeFileSync3(p, "", { flag: "a" });
|
|
27473
27807
|
paths.push(p);
|
|
27474
27808
|
}
|
|
27475
27809
|
return paths;
|
|
@@ -27509,7 +27843,7 @@ function shuffledIndices(n) {
|
|
|
27509
27843
|
}
|
|
27510
27844
|
async function countHeldSlots(cls, budget) {
|
|
27511
27845
|
const dir = governorSlotDir(cls);
|
|
27512
|
-
if (!
|
|
27846
|
+
if (!existsSync7(dir)) return 0;
|
|
27513
27847
|
const slots = ensureSlotFiles(dir, budget);
|
|
27514
27848
|
let held = 0;
|
|
27515
27849
|
for (const path of slots) {
|
|
@@ -27524,7 +27858,7 @@ async function countHeldSlots(cls, budget) {
|
|
|
27524
27858
|
}
|
|
27525
27859
|
function slotFileCount(cls) {
|
|
27526
27860
|
const dir = governorSlotDir(cls);
|
|
27527
|
-
if (!
|
|
27861
|
+
if (!existsSync7(dir)) return 0;
|
|
27528
27862
|
return readdirSync2(dir).filter((f) => f.startsWith("slot-") && f.endsWith(".lock")).length;
|
|
27529
27863
|
}
|
|
27530
27864
|
var _log2, _cachedMode2, _supervisorDegradeLogged, MB, STALE_MS, _supervisorHolderSeq, ResourceGovernor, governor;
|
|
@@ -27724,11 +28058,11 @@ var init_lock = __esm({
|
|
|
27724
28058
|
|
|
27725
28059
|
// packages/core/src/store/atomic.ts
|
|
27726
28060
|
import { mkdir, readFile as readFile2, rename, unlink } from "node:fs/promises";
|
|
27727
|
-
import { dirname as
|
|
28061
|
+
import { dirname as dirname9 } from "node:path";
|
|
27728
28062
|
import writeFileAtomic from "write-file-atomic";
|
|
27729
28063
|
async function atomicWrite(filePath, data, options) {
|
|
27730
28064
|
try {
|
|
27731
|
-
await mkdir(
|
|
28065
|
+
await mkdir(dirname9(filePath), { recursive: true });
|
|
27732
28066
|
await writeFileAtomic(filePath, data, {
|
|
27733
28067
|
encoding: options?.encoding ?? "utf8",
|
|
27734
28068
|
mode: options?.mode
|
|
@@ -27761,7 +28095,7 @@ var init_atomic = __esm({
|
|
|
27761
28095
|
|
|
27762
28096
|
// packages/core/src/store/backup.ts
|
|
27763
28097
|
import { copyFile, rename as fsRename, mkdir as mkdir2, readdir, stat as stat2, unlink as unlink2 } from "node:fs/promises";
|
|
27764
|
-
import { basename as basename5, join as
|
|
28098
|
+
import { basename as basename5, dirname as dirname10, join as join12 } from "node:path";
|
|
27765
28099
|
async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUPS) {
|
|
27766
28100
|
try {
|
|
27767
28101
|
await mkdir2(backupDir, { recursive: true });
|
|
@@ -27772,14 +28106,14 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
27772
28106
|
throw new CleoError(3 /* FILE_ERROR */, `Cannot backup: source file not found: ${filePath}`);
|
|
27773
28107
|
}
|
|
27774
28108
|
for (let i = maxBackups; i >= 1; i--) {
|
|
27775
|
-
const current =
|
|
28109
|
+
const current = join12(backupDir, `${fileName}.${i}`);
|
|
27776
28110
|
if (i === maxBackups) {
|
|
27777
28111
|
try {
|
|
27778
28112
|
await unlink2(current);
|
|
27779
28113
|
} catch {
|
|
27780
28114
|
}
|
|
27781
28115
|
} else {
|
|
27782
|
-
const next =
|
|
28116
|
+
const next = join12(backupDir, `${fileName}.${i + 1}`);
|
|
27783
28117
|
try {
|
|
27784
28118
|
await stat2(current);
|
|
27785
28119
|
await fsRename(current, next);
|
|
@@ -27787,7 +28121,7 @@ async function createBackup(filePath, backupDir, maxBackups = DEFAULT_MAX_BACKUP
|
|
|
27787
28121
|
}
|
|
27788
28122
|
}
|
|
27789
28123
|
}
|
|
27790
|
-
const backupPath =
|
|
28124
|
+
const backupPath = join12(backupDir, `${fileName}.1`);
|
|
27791
28125
|
await copyFile(filePath, backupPath);
|
|
27792
28126
|
return backupPath;
|
|
27793
28127
|
} catch (err) {
|
|
@@ -27801,6 +28135,7 @@ var init_backup = __esm({
|
|
|
27801
28135
|
"use strict";
|
|
27802
28136
|
init_src();
|
|
27803
28137
|
init_errors2();
|
|
28138
|
+
init_worktree_isolation_guard();
|
|
27804
28139
|
DEFAULT_MAX_BACKUPS = 5;
|
|
27805
28140
|
}
|
|
27806
28141
|
});
|
|
@@ -28085,7 +28420,7 @@ __export(identity_exports, {
|
|
|
28085
28420
|
import { execFile } from "node:child_process";
|
|
28086
28421
|
import { createHash as createHash2 } from "node:crypto";
|
|
28087
28422
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
28088
|
-
import { join as
|
|
28423
|
+
import { join as join13, resolve as resolve5 } from "node:path";
|
|
28089
28424
|
import { promisify } from "node:util";
|
|
28090
28425
|
import { legacyProjectId } from "@cleocode/paths";
|
|
28091
28426
|
import { legacyProjectId as legacyProjectId2 } from "@cleocode/paths";
|
|
@@ -28093,14 +28428,14 @@ async function findGitRoot(fromPath, execution) {
|
|
|
28093
28428
|
execution?.assertActive();
|
|
28094
28429
|
try {
|
|
28095
28430
|
const { stdout } = await execFileAsync("git", ["rev-parse", "--show-toplevel"], {
|
|
28096
|
-
cwd:
|
|
28431
|
+
cwd: resolve5(fromPath),
|
|
28097
28432
|
signal: execution?.signal,
|
|
28098
28433
|
timeout: execution ? Math.max(1, execution.remainingMs()) : void 0,
|
|
28099
28434
|
killSignal: "SIGKILL",
|
|
28100
28435
|
maxBuffer: 64 * 1024
|
|
28101
28436
|
});
|
|
28102
28437
|
execution?.assertActive();
|
|
28103
|
-
return
|
|
28438
|
+
return resolve5(stdout.trim());
|
|
28104
28439
|
} catch {
|
|
28105
28440
|
execution?.assertActive();
|
|
28106
28441
|
return null;
|
|
@@ -28110,7 +28445,7 @@ async function findGitRemoteUrl(fromPath, execution) {
|
|
|
28110
28445
|
execution?.assertActive();
|
|
28111
28446
|
try {
|
|
28112
28447
|
const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
|
|
28113
|
-
cwd:
|
|
28448
|
+
cwd: resolve5(fromPath),
|
|
28114
28449
|
signal: execution?.signal,
|
|
28115
28450
|
timeout: execution ? Math.max(1, execution.remainingMs()) : void 0,
|
|
28116
28451
|
killSignal: "SIGKILL",
|
|
@@ -28140,7 +28475,7 @@ async function collectCheckoutEvidence(fromPath, execution) {
|
|
|
28140
28475
|
try {
|
|
28141
28476
|
const args = ["--no-replace-objects", "rev-list", "--max-parents=0", "HEAD"];
|
|
28142
28477
|
const { stdout } = await execFileAsync("git", args, {
|
|
28143
|
-
cwd:
|
|
28478
|
+
cwd: resolve5(fromPath),
|
|
28144
28479
|
signal: execution?.signal,
|
|
28145
28480
|
timeout: execution ? Math.max(1, execution.remainingMs()) : void 0,
|
|
28146
28481
|
killSignal: "SIGKILL",
|
|
@@ -28163,7 +28498,7 @@ async function collectCheckoutEvidence(fromPath, execution) {
|
|
|
28163
28498
|
async function readProjectInfoName(repoRoot, execution) {
|
|
28164
28499
|
execution?.assertActive();
|
|
28165
28500
|
try {
|
|
28166
|
-
const raw = await readFile3(
|
|
28501
|
+
const raw = await readFile3(join13(repoRoot, ".cleo", "project-info.json"), {
|
|
28167
28502
|
encoding: "utf8",
|
|
28168
28503
|
signal: execution?.signal
|
|
28169
28504
|
});
|
|
@@ -28178,7 +28513,7 @@ async function readProjectInfoName(repoRoot, execution) {
|
|
|
28178
28513
|
}
|
|
28179
28514
|
async function projectPathFingerprint(repoPath, execution) {
|
|
28180
28515
|
execution?.assertActive();
|
|
28181
|
-
const realRepoPath =
|
|
28516
|
+
const realRepoPath = resolve5(repoPath);
|
|
28182
28517
|
const results = await Promise.allSettled([
|
|
28183
28518
|
findGitRoot(realRepoPath, execution),
|
|
28184
28519
|
findGitRemoteUrl(realRepoPath, execution)
|
|
@@ -28202,9 +28537,9 @@ async function projectPathFingerprint(repoPath, execution) {
|
|
|
28202
28537
|
}
|
|
28203
28538
|
function computeLegacyAliases(repoPath, additionalPaths) {
|
|
28204
28539
|
const aliases = /* @__PURE__ */ new Set();
|
|
28205
|
-
aliases.add(legacyProjectId(
|
|
28540
|
+
aliases.add(legacyProjectId(resolve5(repoPath)));
|
|
28206
28541
|
for (const p of additionalPaths ?? []) {
|
|
28207
|
-
aliases.add(legacyProjectId(
|
|
28542
|
+
aliases.add(legacyProjectId(resolve5(p)));
|
|
28208
28543
|
}
|
|
28209
28544
|
return [...aliases];
|
|
28210
28545
|
}
|
|
@@ -28238,17 +28573,17 @@ var init_project_identity = __esm({
|
|
|
28238
28573
|
});
|
|
28239
28574
|
|
|
28240
28575
|
// packages/core/src/scaffold/ensure-config.ts
|
|
28241
|
-
import { existsSync as
|
|
28242
|
-
import { basename as basename6, dirname as
|
|
28243
|
-
import { fileURLToPath as
|
|
28576
|
+
import { existsSync as existsSync8, readFileSync as readFileSync4 } from "node:fs";
|
|
28577
|
+
import { basename as basename6, dirname as dirname11, join as join14, resolve as resolve6 } from "node:path";
|
|
28578
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
28244
28579
|
function getPackageRoot() {
|
|
28245
|
-
const thisFile =
|
|
28246
|
-
return
|
|
28580
|
+
const thisFile = fileURLToPath3(import.meta.url);
|
|
28581
|
+
return resolve6(dirname11(thisFile), "..", "..");
|
|
28247
28582
|
}
|
|
28248
28583
|
function getCleoVersion() {
|
|
28249
28584
|
try {
|
|
28250
|
-
const pkgPath =
|
|
28251
|
-
const pkg = JSON.parse(
|
|
28585
|
+
const pkgPath = join14(getPackageRoot(), "package.json");
|
|
28586
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf-8"));
|
|
28252
28587
|
return pkg.version ?? "0.0.0";
|
|
28253
28588
|
} catch {
|
|
28254
28589
|
return "0.0.0";
|
|
@@ -28607,25 +28942,25 @@ var init_recovery = __esm({
|
|
|
28607
28942
|
// packages/core/src/store/exodus/archive.ts
|
|
28608
28943
|
import {
|
|
28609
28944
|
copyFileSync as copyFileSync2,
|
|
28610
|
-
existsSync as
|
|
28945
|
+
existsSync as existsSync9,
|
|
28611
28946
|
mkdirSync as mkdirSync2,
|
|
28612
|
-
readFileSync as
|
|
28947
|
+
readFileSync as readFileSync5,
|
|
28613
28948
|
renameSync as renameSync3,
|
|
28614
28949
|
unlinkSync,
|
|
28615
28950
|
writeFileSync as writeFileSync4
|
|
28616
28951
|
} from "node:fs";
|
|
28617
|
-
import { basename as basename7, dirname as
|
|
28952
|
+
import { basename as basename7, dirname as dirname12, join as join15, resolve as resolve7 } from "node:path";
|
|
28618
28953
|
import { z as z26 } from "zod";
|
|
28619
28954
|
function scopeBaseDir(scope, cwd, targetDbPath) {
|
|
28620
|
-
if (targetDbPath !== void 0) return
|
|
28955
|
+
if (targetDbPath !== void 0) return dirname12(targetDbPath);
|
|
28621
28956
|
return scope === "project" ? resolveCleoDir(cwd) : getCleoHome();
|
|
28622
28957
|
}
|
|
28623
28958
|
function exodusArchiveDir(scope, cwd, targetDbPath) {
|
|
28624
|
-
return
|
|
28959
|
+
return join15(scopeBaseDir(scope, cwd, targetDbPath), ARCHIVE_DIR_NAME);
|
|
28625
28960
|
}
|
|
28626
28961
|
function exodusMarkerPath(scope, cwd, targetDbPath) {
|
|
28627
28962
|
const marker16 = targetDbPath !== void 0 && basename7(targetDbPath) !== "cleo.db" ? `${basename7(targetDbPath)}.${MARKER_FILENAME_BY_SCOPE[scope]}` : MARKER_FILENAME_BY_SCOPE[scope];
|
|
28628
|
-
return
|
|
28963
|
+
return join15(scopeBaseDir(scope, cwd, targetDbPath), marker16);
|
|
28629
28964
|
}
|
|
28630
28965
|
function hasExodusCompleteMarker(scope, cwd, targetDbPath, nativeDb) {
|
|
28631
28966
|
let markerPath;
|
|
@@ -28635,13 +28970,13 @@ function hasExodusCompleteMarker(scope, cwd, targetDbPath, nativeDb) {
|
|
|
28635
28970
|
if (targetDbPath) throw error48;
|
|
28636
28971
|
return false;
|
|
28637
28972
|
}
|
|
28638
|
-
if (!
|
|
28639
|
-
const marker16 = markerIdentity.parse(JSON.parse(
|
|
28973
|
+
if (!existsSync9(markerPath)) return false;
|
|
28974
|
+
const marker16 = markerIdentity.parse(JSON.parse(readFileSync5(markerPath, "utf8")));
|
|
28640
28975
|
if (nativeDb && (!marker16.databaseIdentity || !hasExodusDatabaseIdentity(nativeDb, marker16.databaseIdentity)))
|
|
28641
28976
|
throw new Error(
|
|
28642
28977
|
"Exodus completion marker does not certify this database generation; assessment required"
|
|
28643
28978
|
);
|
|
28644
|
-
return marker16.scope === scope && (!targetDbPath || !marker16.targetDbPath ||
|
|
28979
|
+
return marker16.scope === scope && (!targetDbPath || !marker16.targetDbPath || resolve7(marker16.targetDbPath) === resolve7(targetDbPath));
|
|
28645
28980
|
}
|
|
28646
28981
|
function writeExodusCompleteMarker(scope, archivedSources, cwd, targetDbPath, databaseIdentity) {
|
|
28647
28982
|
const markerPath = exodusMarkerPath(scope, cwd, targetDbPath);
|
|
@@ -28653,7 +28988,7 @@ function writeExodusCompleteMarker(scope, archivedSources, cwd, targetDbPath, da
|
|
|
28653
28988
|
cleoVersion: getCleoVersion(),
|
|
28654
28989
|
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
28655
28990
|
archivedSources: [...archivedSources],
|
|
28656
|
-
targetDbPath:
|
|
28991
|
+
targetDbPath: resolve7(targetDbPath ?? join15(baseDir, "cleo.db")),
|
|
28657
28992
|
...databaseIdentity ? { databaseIdentity } : {}
|
|
28658
28993
|
};
|
|
28659
28994
|
const tmpPath = `${markerPath}.tmp`;
|
|
@@ -28664,10 +28999,10 @@ function writeExodusCompleteMarker(scope, archivedSources, cwd, targetDbPath, da
|
|
|
28664
28999
|
}
|
|
28665
29000
|
function moveFileInto(srcPath, destDir) {
|
|
28666
29001
|
mkdirSync2(destDir, { recursive: true });
|
|
28667
|
-
let dest =
|
|
28668
|
-
if (
|
|
29002
|
+
let dest = join15(destDir, basename7(srcPath));
|
|
29003
|
+
if (existsSync9(dest)) {
|
|
28669
29004
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "").replace(/Z$/, "Z");
|
|
28670
|
-
dest =
|
|
29005
|
+
dest = join15(destDir, `${basename7(srcPath)}.${stamp}`);
|
|
28671
29006
|
}
|
|
28672
29007
|
try {
|
|
28673
29008
|
renameSync3(srcPath, dest);
|
|
@@ -28678,14 +29013,14 @@ function moveFileInto(srcPath, destDir) {
|
|
|
28678
29013
|
return dest;
|
|
28679
29014
|
}
|
|
28680
29015
|
function archiveSourceDb(source, cwd, targetDbPath) {
|
|
28681
|
-
if (!
|
|
29016
|
+
if (!existsSync9(source.path)) {
|
|
28682
29017
|
return { name: source.name, sourcePath: source.path, archivedTo: null, action: "absent" };
|
|
28683
29018
|
}
|
|
28684
29019
|
const destDir = exodusArchiveDir(source.targetScope, cwd, targetDbPath);
|
|
28685
29020
|
const archivedTo = moveFileInto(source.path, destDir);
|
|
28686
29021
|
for (const suffix of SIDECAR_SUFFIXES) {
|
|
28687
29022
|
const sidecar = `${source.path}${suffix}`;
|
|
28688
|
-
if (
|
|
29023
|
+
if (existsSync9(sidecar)) {
|
|
28689
29024
|
try {
|
|
28690
29025
|
moveFileInto(sidecar, destDir);
|
|
28691
29026
|
} catch (err) {
|
|
@@ -28733,7 +29068,7 @@ function detectStrandedResidue(sources, cwd) {
|
|
|
28733
29068
|
const stranded = [];
|
|
28734
29069
|
for (const source of sources) {
|
|
28735
29070
|
if (!markedScopes.has(source.targetScope)) continue;
|
|
28736
|
-
if (
|
|
29071
|
+
if (existsSync9(source.path)) {
|
|
28737
29072
|
stranded.push({ name: source.name, path: source.path, scope: source.targetScope });
|
|
28738
29073
|
}
|
|
28739
29074
|
}
|
|
@@ -28798,7 +29133,7 @@ __export(open_cleo_db_exports, {
|
|
|
28798
29133
|
openCleoDbSnapshot: () => openCleoDbSnapshot,
|
|
28799
29134
|
validateProjectIdConsistency: () => validateProjectIdConsistency
|
|
28800
29135
|
});
|
|
28801
|
-
import { createRequire as
|
|
29136
|
+
import { createRequire as createRequire5 } from "node:module";
|
|
28802
29137
|
function unwrapNativeSqliteDb(db) {
|
|
28803
29138
|
if (db && typeof db === "object" && "$client" in db) {
|
|
28804
29139
|
return db.$client ?? db;
|
|
@@ -28862,9 +29197,10 @@ async function openCleoDb(role, cwd) {
|
|
|
28862
29197
|
}
|
|
28863
29198
|
function openCleoDbSnapshot(path, options = {}) {
|
|
28864
29199
|
const { readOnly = true, applyPragmas = true } = options;
|
|
28865
|
-
const _require7 =
|
|
29200
|
+
const _require7 = createRequire5(import.meta.url);
|
|
28866
29201
|
const { DatabaseSync: DatabaseSyncCtor } = _require7("node:sqlite");
|
|
28867
29202
|
const db = new DatabaseSyncCtor(path, { readOnly });
|
|
29203
|
+
if (!readOnly) installSchemaWriteGuard(db);
|
|
28868
29204
|
if (applyPragmas) {
|
|
28869
29205
|
applyPerfPragmas(db, { enableWal: !readOnly });
|
|
28870
29206
|
}
|
|
@@ -28892,6 +29228,7 @@ var init_open_cleo_db = __esm({
|
|
|
28892
29228
|
init_project_info();
|
|
28893
29229
|
init_dual_scope_db();
|
|
28894
29230
|
init_sqlite_pragmas();
|
|
29231
|
+
init_worktree_build_guard();
|
|
28895
29232
|
init_worktree_isolation_guard();
|
|
28896
29233
|
PROJECT_ID_TRACKING_ROLES = /* @__PURE__ */ new Set(["global"]);
|
|
28897
29234
|
}
|
|
@@ -29231,7 +29568,7 @@ var init_table_name_map = __esm({
|
|
|
29231
29568
|
});
|
|
29232
29569
|
|
|
29233
29570
|
// packages/core/src/store/exodus/count-parity.ts
|
|
29234
|
-
import { existsSync as
|
|
29571
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
29235
29572
|
function listTables(db) {
|
|
29236
29573
|
return db.prepare(
|
|
29237
29574
|
"SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name NOT LIKE '__drizzle_%' ORDER BY name"
|
|
@@ -29252,14 +29589,14 @@ function rowCount(db, tableName) {
|
|
|
29252
29589
|
function computeCountParity(sources, projectDbPath, globalDbPath) {
|
|
29253
29590
|
const entries = [];
|
|
29254
29591
|
let skipped = 0;
|
|
29255
|
-
if (!
|
|
29592
|
+
if (!existsSync10(projectDbPath) || !existsSync10(globalDbPath)) {
|
|
29256
29593
|
return { ok: false, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
29257
29594
|
}
|
|
29258
29595
|
const projectSnap = openCleoDbSnapshot(projectDbPath, { readOnly: true });
|
|
29259
29596
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
29260
29597
|
try {
|
|
29261
29598
|
for (const src of sources) {
|
|
29262
|
-
if (!
|
|
29599
|
+
if (!existsSync10(src.path)) continue;
|
|
29263
29600
|
const srcSnap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
29264
29601
|
try {
|
|
29265
29602
|
for (const legacyTable of listTables(srcSnap.db)) {
|
|
@@ -29317,8 +29654,8 @@ var init_count_parity = __esm({
|
|
|
29317
29654
|
});
|
|
29318
29655
|
|
|
29319
29656
|
// packages/core/src/store/exodus/plan.ts
|
|
29320
|
-
import { existsSync as
|
|
29321
|
-
import { join as
|
|
29657
|
+
import { existsSync as existsSync11, readdirSync as readdirSync3, statfsSync, statSync as statSync3 } from "node:fs";
|
|
29658
|
+
import { join as join16 } from "node:path";
|
|
29322
29659
|
function computeRequiredBytes(totalSourceBytes, largestSourceBytes) {
|
|
29323
29660
|
return Math.ceil(STAGING_HEADROOM_FACTOR * largestSourceBytes) + totalSourceBytes;
|
|
29324
29661
|
}
|
|
@@ -29329,33 +29666,33 @@ function buildSourceDescriptors(cwd) {
|
|
|
29329
29666
|
// Project-tier — go into consolidated project-scope cleo.db
|
|
29330
29667
|
{
|
|
29331
29668
|
name: "tasks",
|
|
29332
|
-
path:
|
|
29669
|
+
path: join16(cleoDir, "tasks.db"),
|
|
29333
29670
|
targetScope: "project"
|
|
29334
29671
|
},
|
|
29335
29672
|
{
|
|
29336
29673
|
name: "brain (project)",
|
|
29337
|
-
path:
|
|
29674
|
+
path: join16(cleoDir, "brain.db"),
|
|
29338
29675
|
targetScope: "project"
|
|
29339
29676
|
},
|
|
29340
29677
|
{
|
|
29341
29678
|
name: "conduit",
|
|
29342
|
-
path:
|
|
29679
|
+
path: join16(cleoDir, "conduit.db"),
|
|
29343
29680
|
targetScope: "project"
|
|
29344
29681
|
},
|
|
29345
29682
|
// Global-tier — go into consolidated global-scope cleo.db
|
|
29346
29683
|
{
|
|
29347
29684
|
name: "nexus",
|
|
29348
|
-
path:
|
|
29685
|
+
path: join16(cleoHome, "nexus.db"),
|
|
29349
29686
|
targetScope: "global"
|
|
29350
29687
|
},
|
|
29351
29688
|
{
|
|
29352
29689
|
name: "signaldock",
|
|
29353
|
-
path:
|
|
29690
|
+
path: join16(cleoHome, "signaldock.db"),
|
|
29354
29691
|
targetScope: "global"
|
|
29355
29692
|
},
|
|
29356
29693
|
{
|
|
29357
29694
|
name: "skills",
|
|
29358
|
-
path:
|
|
29695
|
+
path: join16(cleoHome, "skills.db"),
|
|
29359
29696
|
targetScope: "global"
|
|
29360
29697
|
}
|
|
29361
29698
|
];
|
|
@@ -29384,7 +29721,7 @@ function findExistingStaging(cleoDir) {
|
|
|
29384
29721
|
const entries = readdirSync3(cleoDir, { withFileTypes: true });
|
|
29385
29722
|
const stagingDirs = entries.filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => e.name).sort().reverse();
|
|
29386
29723
|
if (stagingDirs.length > 0) {
|
|
29387
|
-
return
|
|
29724
|
+
return join16(cleoDir, stagingDirs[0]);
|
|
29388
29725
|
}
|
|
29389
29726
|
} catch {
|
|
29390
29727
|
}
|
|
@@ -29400,7 +29737,7 @@ function buildExodusPlan(cwd) {
|
|
|
29400
29737
|
const availableBytes = getAvailableBytes(cleoDir);
|
|
29401
29738
|
const diskPreflight = totalSourceBytes === 0 || availableBytes >= requiredBytes;
|
|
29402
29739
|
const existingStaging = findExistingStaging(cleoDir);
|
|
29403
|
-
const stagingDir = existingStaging ??
|
|
29740
|
+
const stagingDir = existingStaging ?? join16(cleoDir, deriveStagingDirName());
|
|
29404
29741
|
const resumeFromStaging = existingStaging !== null;
|
|
29405
29742
|
const projectDbPath = resolveDualScopeDbPath("project", cwd);
|
|
29406
29743
|
const globalDbPath = resolveDualScopeDbPath("global");
|
|
@@ -29419,7 +29756,7 @@ function buildExodusPlan(cwd) {
|
|
|
29419
29756
|
};
|
|
29420
29757
|
}
|
|
29421
29758
|
function sourcesPresent(sources) {
|
|
29422
|
-
return sources.some((s) =>
|
|
29759
|
+
return sources.some((s) => existsSync11(s.path));
|
|
29423
29760
|
}
|
|
29424
29761
|
var STAGING_HEADROOM_FACTOR, STAGING_COPY_SKIP_THRESHOLD_BYTES;
|
|
29425
29762
|
var init_plan2 = __esm({
|
|
@@ -29433,18 +29770,18 @@ var init_plan2 = __esm({
|
|
|
29433
29770
|
});
|
|
29434
29771
|
|
|
29435
29772
|
// packages/core/src/store/exodus/health.ts
|
|
29436
|
-
import { existsSync as
|
|
29773
|
+
import { existsSync as existsSync12, statSync as statSync4 } from "node:fs";
|
|
29437
29774
|
function buildExodusHealth(cwd) {
|
|
29438
29775
|
const plan = buildExodusPlan(cwd);
|
|
29439
|
-
const anyLegacyPresent = plan.sources.some((s) =>
|
|
29776
|
+
const anyLegacyPresent = plan.sources.some((s) => existsSync12(s.path));
|
|
29440
29777
|
const parity = anyLegacyPresent ? computeCountParity(plan.sources, plan.projectDbPath, plan.globalDbPath) : { ok: true, entries: [], deficits: [], checked: 0, skipped: 0 };
|
|
29441
29778
|
const consolidatedExistsByScope = {
|
|
29442
|
-
project:
|
|
29443
|
-
global:
|
|
29779
|
+
project: existsSync12(plan.projectDbPath),
|
|
29780
|
+
global: existsSync12(plan.globalDbPath)
|
|
29444
29781
|
};
|
|
29445
29782
|
const buildScope = (scope) => {
|
|
29446
29783
|
const sources = plan.sources.filter((s) => s.targetScope === scope).map((s) => {
|
|
29447
|
-
const present =
|
|
29784
|
+
const present = existsSync12(s.path);
|
|
29448
29785
|
let bytes = 0;
|
|
29449
29786
|
if (present) {
|
|
29450
29787
|
try {
|
|
@@ -29796,8 +30133,8 @@ var init_types = __esm({
|
|
|
29796
30133
|
});
|
|
29797
30134
|
|
|
29798
30135
|
// packages/core/src/store/backup-sidecar.ts
|
|
29799
|
-
import { existsSync as
|
|
29800
|
-
import { join as
|
|
30136
|
+
import { existsSync as existsSync13, readdirSync as readdirSync4, renameSync as renameSync4, statSync as statSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
30137
|
+
import { join as join17 } from "node:path";
|
|
29801
30138
|
function formatBackupTimestamp(d) {
|
|
29802
30139
|
const pad = (n, len = 2) => String(n).padStart(len, "0");
|
|
29803
30140
|
return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}${pad(d.getSeconds())}`;
|
|
@@ -29808,8 +30145,8 @@ function rotateBackupDir(backupDir, maxSnapshots, backupType) {
|
|
|
29808
30145
|
const ownedPattern = new RegExp(`\\.${escapedType}-`);
|
|
29809
30146
|
const files = readdirSync4(backupDir).filter((f) => !f.endsWith(".meta.json") && !f.endsWith(".tmp") && ownedPattern.test(f)).map((f) => ({
|
|
29810
30147
|
name: f,
|
|
29811
|
-
path:
|
|
29812
|
-
mtimeMs: statSync5(
|
|
30148
|
+
path: join17(backupDir, f),
|
|
30149
|
+
mtimeMs: statSync5(join17(backupDir, f)).mtimeMs
|
|
29813
30150
|
})).sort((a, b) => a.mtimeMs - b.mtimeMs);
|
|
29814
30151
|
while (files.length > maxSnapshots) {
|
|
29815
30152
|
const oldest = files.shift();
|
|
@@ -29817,7 +30154,7 @@ function rotateBackupDir(backupDir, maxSnapshots, backupType) {
|
|
|
29817
30154
|
try {
|
|
29818
30155
|
unlinkSync2(oldest.path);
|
|
29819
30156
|
const metaPath = `${oldest.path}.meta.json`;
|
|
29820
|
-
if (
|
|
30157
|
+
if (existsSync13(metaPath)) unlinkSync2(metaPath);
|
|
29821
30158
|
} catch {
|
|
29822
30159
|
}
|
|
29823
30160
|
}
|
|
@@ -29825,7 +30162,7 @@ function rotateBackupDir(backupDir, maxSnapshots, backupType) {
|
|
|
29825
30162
|
}
|
|
29826
30163
|
}
|
|
29827
30164
|
function writeBackupSidecar(backupDir, sidecar) {
|
|
29828
|
-
const dest =
|
|
30165
|
+
const dest = join17(backupDir, `${sidecar.backupId}.meta.json`);
|
|
29829
30166
|
const tmp = `${dest}.${process.pid}.${Date.now()}.tmp`;
|
|
29830
30167
|
writeFileSync5(tmp, JSON.stringify(sidecar, null, 2));
|
|
29831
30168
|
renameSync4(tmp, dest);
|
|
@@ -29837,23 +30174,23 @@ var init_backup_sidecar = __esm({
|
|
|
29837
30174
|
});
|
|
29838
30175
|
|
|
29839
30176
|
// packages/core/src/store/pre-repair-snapshot.ts
|
|
29840
|
-
import { existsSync as
|
|
29841
|
-
import { dirname as
|
|
30177
|
+
import { existsSync as existsSync14, mkdirSync as mkdirSync3, statfsSync as statfsSync2 } from "node:fs";
|
|
30178
|
+
import { dirname as dirname13, join as join18 } from "node:path";
|
|
29842
30179
|
function writePreRepairSnapshot(nativeDb, dbPath, label) {
|
|
29843
30180
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
29844
|
-
const backupDir =
|
|
30181
|
+
const backupDir = join18(dirname13(dbPath), "backups");
|
|
29845
30182
|
mkdirSync3(backupDir, { recursive: true });
|
|
29846
|
-
const snapshotPath =
|
|
30183
|
+
const snapshotPath = join18(backupDir, `cleo-pre-${label}-${stamp}.db`);
|
|
29847
30184
|
nativeDb.exec(`VACUUM INTO '${snapshotPath.replace(/'/g, "''")}'`);
|
|
29848
30185
|
return snapshotPath;
|
|
29849
30186
|
}
|
|
29850
30187
|
function existingAncestor(path) {
|
|
29851
30188
|
let p = path;
|
|
29852
|
-
while (!
|
|
30189
|
+
while (!existsSync14(p) && dirname13(p) !== p) p = dirname13(p);
|
|
29853
30190
|
return p;
|
|
29854
30191
|
}
|
|
29855
30192
|
function planMigrationSnapshot(nativeDb, dbPath) {
|
|
29856
|
-
const backupDir =
|
|
30193
|
+
const backupDir = join18(dirname13(dbPath), "backups", "sqlite");
|
|
29857
30194
|
const pragma = (name15) => Number(nativeDb.prepare(`PRAGMA main.${name15}`).get()[name15] ?? 0);
|
|
29858
30195
|
const liveBytes = (pragma("page_count") - pragma("freelist_count")) * pragma("page_size");
|
|
29859
30196
|
let availableBytes = null;
|
|
@@ -29865,13 +30202,13 @@ function planMigrationSnapshot(nativeDb, dbPath) {
|
|
|
29865
30202
|
}
|
|
29866
30203
|
const base = `migration-${formatBackupTimestamp(/* @__PURE__ */ new Date())}`;
|
|
29867
30204
|
let backupId = base;
|
|
29868
|
-
for (let n = 2;
|
|
30205
|
+
for (let n = 2; existsSync14(join18(backupDir, `${backupId}.meta.json`)); n++) {
|
|
29869
30206
|
backupId = `${base}-${n}`;
|
|
29870
30207
|
}
|
|
29871
30208
|
return {
|
|
29872
30209
|
backupDir,
|
|
29873
30210
|
backupId,
|
|
29874
|
-
snapshotPath:
|
|
30211
|
+
snapshotPath: join18(backupDir, `cleo.db.${backupId}`),
|
|
29875
30212
|
requiredBytes: liveBytes + SNAPSHOT_HEADROOM_BYTES,
|
|
29876
30213
|
availableBytes
|
|
29877
30214
|
};
|
|
@@ -30111,7 +30448,7 @@ var init_legacy_tasks_lineage = __esm({
|
|
|
30111
30448
|
|
|
30112
30449
|
// packages/core/src/store/ports/domain-binding.ts
|
|
30113
30450
|
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
30114
|
-
import { resolve as
|
|
30451
|
+
import { resolve as resolve8 } from "node:path";
|
|
30115
30452
|
function getCleoRuntime() {
|
|
30116
30453
|
if (!_runtime) {
|
|
30117
30454
|
_runtime = createCleoRuntime();
|
|
@@ -30179,6 +30516,8 @@ async function bindAgainst(key, store, establish) {
|
|
|
30179
30516
|
() => establish(native, store)
|
|
30180
30517
|
);
|
|
30181
30518
|
return { store, native, db };
|
|
30519
|
+
} catch (error48) {
|
|
30520
|
+
throw explainSchemaWriteDenial(native, error48);
|
|
30182
30521
|
} finally {
|
|
30183
30522
|
membership.active = false;
|
|
30184
30523
|
}
|
|
@@ -30228,7 +30567,7 @@ async function bindLive(scope, key, dbPath, openStore, establish) {
|
|
|
30228
30567
|
);
|
|
30229
30568
|
}
|
|
30230
30569
|
async function bindProjectDomain(domain2, cwd, establish) {
|
|
30231
|
-
const dbPath =
|
|
30570
|
+
const dbPath = resolve8(resolveDualScopeDbPath("project", cwd));
|
|
30232
30571
|
const row = await bindLive(
|
|
30233
30572
|
"project",
|
|
30234
30573
|
bindingKey("project", dbPath, domain2),
|
|
@@ -30239,7 +30578,7 @@ async function bindProjectDomain(domain2, cwd, establish) {
|
|
|
30239
30578
|
return row;
|
|
30240
30579
|
}
|
|
30241
30580
|
async function bindGlobalDomain(domain2, establish, cwd) {
|
|
30242
|
-
const dbPath =
|
|
30581
|
+
const dbPath = resolve8(resolveDualScopeDbPath("global"));
|
|
30243
30582
|
const row = await bindLive(
|
|
30244
30583
|
"global",
|
|
30245
30584
|
bindingKey("global", dbPath, domain2),
|
|
@@ -30250,7 +30589,7 @@ async function bindGlobalDomain(domain2, establish, cwd) {
|
|
|
30250
30589
|
return row;
|
|
30251
30590
|
}
|
|
30252
30591
|
async function bindGlobalDomainAtPath(domain2, dbPath, establish) {
|
|
30253
|
-
const normalized =
|
|
30592
|
+
const normalized = resolve8(dbPath);
|
|
30254
30593
|
const row = await bindLive(
|
|
30255
30594
|
"global",
|
|
30256
30595
|
bindingKey("global", normalized, domain2),
|
|
@@ -30261,7 +30600,7 @@ async function bindGlobalDomainAtPath(domain2, dbPath, establish) {
|
|
|
30261
30600
|
return row;
|
|
30262
30601
|
}
|
|
30263
30602
|
function peekDomainAtPath(scope, dbPath, domain2) {
|
|
30264
|
-
const row = _bindings.get(bindingKey(scope,
|
|
30603
|
+
const row = _bindings.get(bindingKey(scope, resolve8(dbPath), domain2));
|
|
30265
30604
|
if (!row?.native.isOpen) return null;
|
|
30266
30605
|
return row;
|
|
30267
30606
|
}
|
|
@@ -30270,12 +30609,12 @@ function releaseDomainBindings(filter2) {
|
|
|
30270
30609
|
_bindings.clear();
|
|
30271
30610
|
return;
|
|
30272
30611
|
}
|
|
30273
|
-
const wantPath = filter2.dbPath === void 0 ? void 0 :
|
|
30612
|
+
const wantPath = filter2.dbPath === void 0 ? void 0 : resolve8(filter2.dbPath);
|
|
30274
30613
|
for (const key of [..._bindings.keys()]) {
|
|
30275
|
-
const
|
|
30614
|
+
const sep6 = key.indexOf("::");
|
|
30276
30615
|
const lastSep = key.lastIndexOf("::");
|
|
30277
|
-
const scope = key.slice(0,
|
|
30278
|
-
const dbPath = key.slice(
|
|
30616
|
+
const scope = key.slice(0, sep6);
|
|
30617
|
+
const dbPath = key.slice(sep6 + 2, lastSep);
|
|
30279
30618
|
const domain2 = key.slice(lastSep + 2);
|
|
30280
30619
|
if (filter2.scope !== void 0 && scope !== filter2.scope) continue;
|
|
30281
30620
|
if (wantPath !== void 0 && dbPath !== wantPath) continue;
|
|
@@ -30290,7 +30629,7 @@ function boundProjectNative(domain2, cwd) {
|
|
|
30290
30629
|
return peekProjectDomain(domain2, cwd)?.native ?? null;
|
|
30291
30630
|
}
|
|
30292
30631
|
function peekProjectDomain(domain2, cwd) {
|
|
30293
|
-
const dbPath =
|
|
30632
|
+
const dbPath = resolve8(resolveDualScopeDbPath("project", cwd));
|
|
30294
30633
|
const row = _bindings.get(bindingKey("project", dbPath, domain2));
|
|
30295
30634
|
if (row?.native.isOpen) return row;
|
|
30296
30635
|
if (cwd !== void 0) return null;
|
|
@@ -30305,7 +30644,7 @@ function peekProjectDomain(domain2, cwd) {
|
|
|
30305
30644
|
return sole ?? null;
|
|
30306
30645
|
}
|
|
30307
30646
|
function peekGlobalDomain(domain2) {
|
|
30308
|
-
const dbPath =
|
|
30647
|
+
const dbPath = resolve8(resolveDualScopeDbPath("global"));
|
|
30309
30648
|
const row = _bindings.get(bindingKey("global", dbPath, domain2));
|
|
30310
30649
|
if (!row || !row.native.isOpen) return null;
|
|
30311
30650
|
return row;
|
|
@@ -30316,6 +30655,7 @@ var init_domain_binding = __esm({
|
|
|
30316
30655
|
"use strict";
|
|
30317
30656
|
init_project_scope();
|
|
30318
30657
|
init_dual_scope_db();
|
|
30658
|
+
init_worktree_build_guard();
|
|
30319
30659
|
_runtime = null;
|
|
30320
30660
|
_bindings = /* @__PURE__ */ new Map();
|
|
30321
30661
|
_inflight = /* @__PURE__ */ new Map();
|
|
@@ -30326,9 +30666,9 @@ var init_domain_binding = __esm({
|
|
|
30326
30666
|
|
|
30327
30667
|
// packages/core/src/telemetry/sqlite.ts
|
|
30328
30668
|
import { mkdirSync as mkdirSync4 } from "node:fs";
|
|
30329
|
-
import { dirname as
|
|
30669
|
+
import { dirname as dirname14, join as join19 } from "node:path";
|
|
30330
30670
|
function getTelemetryDbPath() {
|
|
30331
|
-
return
|
|
30671
|
+
return join19(getCleoHome(), DB_FILENAME);
|
|
30332
30672
|
}
|
|
30333
30673
|
function resolveTelemetryMigrationsFolder() {
|
|
30334
30674
|
return resolveCorePackageMigrationsFolder("drizzle-telemetry");
|
|
@@ -30376,8 +30716,9 @@ async function getTelemetryDb() {
|
|
|
30376
30716
|
_initPromise = (async () => {
|
|
30377
30717
|
const dbPath = requestedPath;
|
|
30378
30718
|
_dbPath = dbPath;
|
|
30379
|
-
mkdirSync4(
|
|
30719
|
+
mkdirSync4(dirname14(dbPath), { recursive: true });
|
|
30380
30720
|
const nativeDb = openNativeDatabase(dbPath);
|
|
30721
|
+
installSchemaWriteGuard(nativeDb);
|
|
30381
30722
|
_nativeDb = nativeDb;
|
|
30382
30723
|
const db = drizzle({ client: nativeDb });
|
|
30383
30724
|
runTelemetryMigrations(nativeDb, db);
|
|
@@ -30398,6 +30739,7 @@ var init_sqlite2 = __esm({
|
|
|
30398
30739
|
init_migration_manager();
|
|
30399
30740
|
init_resolve_migrations_folder();
|
|
30400
30741
|
init_sqlite3();
|
|
30742
|
+
init_worktree_build_guard();
|
|
30401
30743
|
DB_FILENAME = "telemetry.db";
|
|
30402
30744
|
TELEMETRY_SCHEMA_VERSION = "1.0.0";
|
|
30403
30745
|
_db = null;
|
|
@@ -30408,11 +30750,11 @@ var init_sqlite2 = __esm({
|
|
|
30408
30750
|
});
|
|
30409
30751
|
|
|
30410
30752
|
// packages/core/src/store/agent-registry-store.ts
|
|
30411
|
-
import { existsSync as
|
|
30412
|
-
import { join as
|
|
30753
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
30754
|
+
import { join as join20 } from "node:path";
|
|
30413
30755
|
function getGlobalAgentRegistryDbPath() {
|
|
30414
30756
|
const cleoHome = getCleoHome();
|
|
30415
|
-
const dbPath =
|
|
30757
|
+
const dbPath = join20(cleoHome, "cleo.db");
|
|
30416
30758
|
if (!dbPath.startsWith(cleoHome)) {
|
|
30417
30759
|
throw new Error(
|
|
30418
30760
|
`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.`
|
|
@@ -30479,7 +30821,7 @@ function establishAgentRegistrySchema(native) {
|
|
|
30479
30821
|
}
|
|
30480
30822
|
async function ensureGlobalAgentRegistryDb() {
|
|
30481
30823
|
const dbPath = getGlobalAgentRegistryDbPath();
|
|
30482
|
-
const alreadyExists =
|
|
30824
|
+
const alreadyExists = existsSync15(dbPath);
|
|
30483
30825
|
let created = false;
|
|
30484
30826
|
const { native: nativeDb } = await bindGlobalDomainAtPath(
|
|
30485
30827
|
AGENT_REGISTRY_DOMAIN,
|
|
@@ -30524,8 +30866,8 @@ var init_agent_registry_store = __esm({
|
|
|
30524
30866
|
});
|
|
30525
30867
|
|
|
30526
30868
|
// packages/core/src/store/conduit-sqlite.ts
|
|
30527
|
-
import { existsSync as
|
|
30528
|
-
import { createRequire as
|
|
30869
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
30870
|
+
import { createRequire as createRequire6 } from "node:module";
|
|
30529
30871
|
function _getDrizzle() {
|
|
30530
30872
|
if (_drizzle === null) {
|
|
30531
30873
|
const mod = _require3("drizzle-orm/node-sqlite");
|
|
@@ -30553,7 +30895,7 @@ function runConduitMigrations(nativeDb) {
|
|
|
30553
30895
|
}
|
|
30554
30896
|
async function ensureConduitDb(projectRoot) {
|
|
30555
30897
|
const dbPath = getConduitDbPath(projectRoot);
|
|
30556
|
-
const alreadyExists = peekProjectDomain("conduit", projectRoot) !== null ||
|
|
30898
|
+
const alreadyExists = peekProjectDomain("conduit", projectRoot) !== null || existsSync16(dbPath);
|
|
30557
30899
|
await bindConduitDomain(projectRoot);
|
|
30558
30900
|
return { action: alreadyExists ? "exists" : "created", path: dbPath };
|
|
30559
30901
|
}
|
|
@@ -30579,7 +30921,8 @@ var init_conduit_sqlite = __esm({
|
|
|
30579
30921
|
init_domain_binding();
|
|
30580
30922
|
init_resolve_migrations_folder();
|
|
30581
30923
|
init_sqlite_pragmas();
|
|
30582
|
-
|
|
30924
|
+
init_worktree_build_guard();
|
|
30925
|
+
_require3 = createRequire6(import.meta.url);
|
|
30583
30926
|
({ DatabaseSync: DatabaseSync2 } = _require3("node:sqlite"));
|
|
30584
30927
|
_drizzle = null;
|
|
30585
30928
|
CONDUIT_SCHEMA_VERSION = "2026.4.23";
|
|
@@ -33051,7 +33394,7 @@ __export(config_exports, {
|
|
|
33051
33394
|
parseConfigValue: () => parseConfigValue,
|
|
33052
33395
|
setConfigValue: () => setConfigValue
|
|
33053
33396
|
});
|
|
33054
|
-
import { existsSync as
|
|
33397
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
33055
33398
|
function getNestedValue(obj, path) {
|
|
33056
33399
|
const parts = path.split(".");
|
|
33057
33400
|
let current = obj;
|
|
@@ -33173,7 +33516,7 @@ function parseConfigValue(value) {
|
|
|
33173
33516
|
}
|
|
33174
33517
|
async function setConfigValue(key, value, cwd, opts) {
|
|
33175
33518
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
33176
|
-
if (!
|
|
33519
|
+
if (!existsSync17(configPath)) {
|
|
33177
33520
|
await atomicWriteJson(configPath, {});
|
|
33178
33521
|
}
|
|
33179
33522
|
const config2 = await readJson(configPath) ?? {};
|
|
@@ -33185,7 +33528,7 @@ async function setConfigValue(key, value, cwd, opts) {
|
|
|
33185
33528
|
async function applyStrictnessPreset(preset, cwd, opts) {
|
|
33186
33529
|
const definition = STRICTNESS_PRESETS[preset];
|
|
33187
33530
|
const configPath = opts?.global ? getGlobalConfigPath() : getConfigPath(cwd);
|
|
33188
|
-
if (!
|
|
33531
|
+
if (!existsSync17(configPath)) {
|
|
33189
33532
|
await atomicWriteJson(configPath, {});
|
|
33190
33533
|
}
|
|
33191
33534
|
const config2 = await readJson(configPath) ?? {};
|
|
@@ -33762,6 +34105,7 @@ var init_cross_db_cleanup = __esm({
|
|
|
33762
34105
|
"use strict";
|
|
33763
34106
|
init_memory_sqlite();
|
|
33764
34107
|
init_memory_schema();
|
|
34108
|
+
init_worktree_build_guard();
|
|
33765
34109
|
}
|
|
33766
34110
|
});
|
|
33767
34111
|
|
|
@@ -38454,7 +38798,7 @@ __export(sqlite_data_accessor_exports, {
|
|
|
38454
38798
|
setMetaValue: () => setMetaValue
|
|
38455
38799
|
});
|
|
38456
38800
|
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
38457
|
-
import { resolve as
|
|
38801
|
+
import { resolve as resolve9 } from "node:path";
|
|
38458
38802
|
import {
|
|
38459
38803
|
and as and5,
|
|
38460
38804
|
eq as eq6,
|
|
@@ -38563,7 +38907,7 @@ function bindTaskAccessorScope(accessor, scope) {
|
|
|
38563
38907
|
}
|
|
38564
38908
|
async function createSqliteDataAccessor(cwd) {
|
|
38565
38909
|
const scope = captureProjectScope(
|
|
38566
|
-
|
|
38910
|
+
resolve9(cwd ?? getProjectRoot()),
|
|
38567
38911
|
worktreeScope.getStore()
|
|
38568
38912
|
);
|
|
38569
38913
|
return worktreeScope.run(
|
|
@@ -38678,7 +39022,9 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38678
39022
|
actor: entry.actor ?? "system",
|
|
38679
39023
|
detailsJson: entry.details ? JSON.stringify(entry.details) : "{}",
|
|
38680
39024
|
beforeJson: entry.before ? JSON.stringify(entry.before) : null,
|
|
38681
|
-
afterJson: entry.after ? JSON.stringify(entry.after) : null
|
|
39025
|
+
afterJson: entry.after ? JSON.stringify(entry.after) : null,
|
|
39026
|
+
// T12693: the session a ranking change ran in.
|
|
39027
|
+
sessionId: typeof entry.sessionId === "string" ? entry.sessionId : null
|
|
38682
39028
|
}).run()
|
|
38683
39029
|
);
|
|
38684
39030
|
});
|
|
@@ -38686,6 +39032,9 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38686
39032
|
async queryAuditLog(query) {
|
|
38687
39033
|
const db = await getDb(cwd);
|
|
38688
39034
|
const conditions = [];
|
|
39035
|
+
if (query.ids && query.ids.length > 0) {
|
|
39036
|
+
conditions.push(inArray4(tasksAuditLog.id, [...query.ids]));
|
|
39037
|
+
}
|
|
38689
39038
|
if (query.taskIds && query.taskIds.length > 0) {
|
|
38690
39039
|
conditions.push(inArray4(tasksAuditLog.taskId, [...query.taskIds]));
|
|
38691
39040
|
}
|
|
@@ -38704,7 +39053,8 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38704
39053
|
actor: tasksAuditLog.actor,
|
|
38705
39054
|
detailsJson: tasksAuditLog.detailsJson,
|
|
38706
39055
|
beforeJson: tasksAuditLog.beforeJson,
|
|
38707
|
-
afterJson: tasksAuditLog.afterJson
|
|
39056
|
+
afterJson: tasksAuditLog.afterJson,
|
|
39057
|
+
sessionId: tasksAuditLog.sessionId
|
|
38708
39058
|
}).from(tasksAuditLog).where(conditions.length > 0 ? and5(...conditions) : void 0).orderBy(sql26`${tasksAuditLog.timestamp} DESC`).limit(limit).all();
|
|
38709
39059
|
return rows.map((row) => ({
|
|
38710
39060
|
id: row.id,
|
|
@@ -38714,7 +39064,8 @@ async function createOwnedSqliteDataAccessor(cwd, accessorScope) {
|
|
|
38714
39064
|
actor: row.actor,
|
|
38715
39065
|
detailsJson: row.detailsJson ?? null,
|
|
38716
39066
|
beforeJson: row.beforeJson ?? null,
|
|
38717
|
-
afterJson: row.afterJson ?? null
|
|
39067
|
+
afterJson: row.afterJson ?? null,
|
|
39068
|
+
sessionId: row.sessionId ?? null
|
|
38718
39069
|
}));
|
|
38719
39070
|
},
|
|
38720
39071
|
// ---- Fine-grained task operations (T5034) ----
|
|
@@ -39552,13 +39903,13 @@ var init_sqlite_data_accessor = __esm({
|
|
|
39552
39903
|
});
|
|
39553
39904
|
|
|
39554
39905
|
// packages/core/src/sequence/index.ts
|
|
39555
|
-
import { existsSync as
|
|
39556
|
-
import { join as
|
|
39906
|
+
import { existsSync as existsSync18, readFileSync as readFileSync6, renameSync as renameSync5 } from "node:fs";
|
|
39907
|
+
import { join as join21 } from "node:path";
|
|
39557
39908
|
function getLegacySequenceJsonPath(cwd) {
|
|
39558
|
-
return
|
|
39909
|
+
return join21(resolveOrCwd(cwd), ".cleo", ".sequence.json");
|
|
39559
39910
|
}
|
|
39560
39911
|
function getLegacySequencePath(cwd) {
|
|
39561
|
-
return
|
|
39912
|
+
return join21(resolveOrCwd(cwd), ".cleo", ".sequence");
|
|
39562
39913
|
}
|
|
39563
39914
|
function isValidSequenceState(value) {
|
|
39564
39915
|
if (!value || typeof value !== "object") return false;
|
|
@@ -39569,19 +39920,19 @@ function isSeedSequence(value) {
|
|
|
39569
39920
|
return value.counter === 0 && value.lastId === "T000" && value.checksum === "seed";
|
|
39570
39921
|
}
|
|
39571
39922
|
function readLegacySequenceFile(path) {
|
|
39572
|
-
if (!
|
|
39923
|
+
if (!existsSync18(path)) return null;
|
|
39573
39924
|
try {
|
|
39574
|
-
const parsed = JSON.parse(
|
|
39925
|
+
const parsed = JSON.parse(readFileSync6(path, "utf-8"));
|
|
39575
39926
|
return isValidSequenceState(parsed) ? parsed : null;
|
|
39576
39927
|
} catch {
|
|
39577
39928
|
return null;
|
|
39578
39929
|
}
|
|
39579
39930
|
}
|
|
39580
39931
|
function renameLegacyFile(path) {
|
|
39581
|
-
if (!
|
|
39932
|
+
if (!existsSync18(path)) return;
|
|
39582
39933
|
const migratedPath = `${path}.migrated`;
|
|
39583
39934
|
try {
|
|
39584
|
-
if (!
|
|
39935
|
+
if (!existsSync18(migratedPath)) {
|
|
39585
39936
|
renameSync5(path, migratedPath);
|
|
39586
39937
|
return;
|
|
39587
39938
|
}
|
|
@@ -39733,9 +40084,9 @@ var init_sequence = __esm({
|
|
|
39733
40084
|
});
|
|
39734
40085
|
|
|
39735
40086
|
// packages/core/src/store/checkpoint-git-dir.ts
|
|
39736
|
-
import { join as
|
|
40087
|
+
import { join as join22 } from "node:path";
|
|
39737
40088
|
function checkpointGitDir(cleoDir) {
|
|
39738
|
-
return
|
|
40089
|
+
return join22(cleoDir, CHECKPOINT_GIT_DIRNAME);
|
|
39739
40090
|
}
|
|
39740
40091
|
var CHECKPOINT_GIT_DIRNAME;
|
|
39741
40092
|
var init_checkpoint_git_dir = __esm({
|
|
@@ -39747,12 +40098,12 @@ var init_checkpoint_git_dir = __esm({
|
|
|
39747
40098
|
|
|
39748
40099
|
// packages/core/src/store/git-checkpoint.ts
|
|
39749
40100
|
import { execFile as execFile2 } from "node:child_process";
|
|
39750
|
-
import { existsSync as
|
|
40101
|
+
import { existsSync as existsSync19 } from "node:fs";
|
|
39751
40102
|
import { readFile as readFile4, writeFile } from "node:fs/promises";
|
|
39752
|
-
import { join as
|
|
40103
|
+
import { join as join23, resolve as resolve10 } from "node:path";
|
|
39753
40104
|
import { promisify as promisify2 } from "node:util";
|
|
39754
40105
|
function makeCleoGitEnv(cleoDir) {
|
|
39755
|
-
const abs =
|
|
40106
|
+
const abs = resolve10(cleoDir);
|
|
39756
40107
|
return {
|
|
39757
40108
|
...process.env,
|
|
39758
40109
|
GIT_DIR: checkpointGitDir(abs),
|
|
@@ -39762,7 +40113,7 @@ function makeCleoGitEnv(cleoDir) {
|
|
|
39762
40113
|
async function cleoGitCommand(args, cleoDir) {
|
|
39763
40114
|
try {
|
|
39764
40115
|
const result = await execFileAsync2("git", args, {
|
|
39765
|
-
cwd:
|
|
40116
|
+
cwd: resolve10(cleoDir),
|
|
39766
40117
|
// absolute cwd so relative paths in args resolve correctly
|
|
39767
40118
|
env: makeCleoGitEnv(cleoDir),
|
|
39768
40119
|
timeout: 1e4
|
|
@@ -39773,7 +40124,7 @@ async function cleoGitCommand(args, cleoDir) {
|
|
|
39773
40124
|
}
|
|
39774
40125
|
}
|
|
39775
40126
|
function isCleoGitInitialized(cleoDir) {
|
|
39776
|
-
return
|
|
40127
|
+
return existsSync19(join23(checkpointGitDir(cleoDir), "HEAD"));
|
|
39777
40128
|
}
|
|
39778
40129
|
async function loadStateFileAllowlist(cwd) {
|
|
39779
40130
|
try {
|
|
@@ -39817,25 +40168,25 @@ async function isCleoGitRepo(cleoDir) {
|
|
|
39817
40168
|
return result.success && (result.stdout === "true" || isCleoGitInitialized(cleoDir));
|
|
39818
40169
|
}
|
|
39819
40170
|
function isMergeInProgress(cleoDir) {
|
|
39820
|
-
return
|
|
40171
|
+
return existsSync19(join23(checkpointGitDir(cleoDir), "MERGE_HEAD"));
|
|
39821
40172
|
}
|
|
39822
40173
|
async function isDetachedHead(cleoDir) {
|
|
39823
40174
|
const result = await cleoGitCommand(["symbolic-ref", "HEAD"], cleoDir);
|
|
39824
40175
|
return !result.success;
|
|
39825
40176
|
}
|
|
39826
40177
|
function isRebaseInProgress(cleoDir) {
|
|
39827
|
-
return
|
|
40178
|
+
return existsSync19(join23(checkpointGitDir(cleoDir), "rebase-merge")) || existsSync19(join23(checkpointGitDir(cleoDir), "rebase-apply"));
|
|
39828
40179
|
}
|
|
39829
40180
|
async function recordCheckpointTime(cleoDir) {
|
|
39830
40181
|
try {
|
|
39831
|
-
const stateFile =
|
|
40182
|
+
const stateFile = join23(cleoDir, CHECKPOINT_STATE_FILE);
|
|
39832
40183
|
await writeFile(stateFile, String(Math.floor(Date.now() / 1e3)));
|
|
39833
40184
|
} catch {
|
|
39834
40185
|
}
|
|
39835
40186
|
}
|
|
39836
40187
|
async function getLastCheckpointTime(cleoDir) {
|
|
39837
40188
|
try {
|
|
39838
|
-
const stateFile =
|
|
40189
|
+
const stateFile = join23(cleoDir, CHECKPOINT_STATE_FILE);
|
|
39839
40190
|
const content = await readFile4(stateFile, "utf-8");
|
|
39840
40191
|
const epoch = parseInt(content.trim(), 10);
|
|
39841
40192
|
return Number.isNaN(epoch) ? 0 : epoch;
|
|
@@ -39847,8 +40198,8 @@ async function getChangedStateFiles(cleoDir, cwd) {
|
|
|
39847
40198
|
const changed = [];
|
|
39848
40199
|
const allStateFiles = await getAllStateFiles(cwd);
|
|
39849
40200
|
for (const stateFile of allStateFiles) {
|
|
39850
|
-
const fullPath =
|
|
39851
|
-
if (!
|
|
40201
|
+
const fullPath = join23(cleoDir, stateFile);
|
|
40202
|
+
if (!existsSync19(fullPath)) continue;
|
|
39852
40203
|
const diffResult = await cleoGitCommand(["diff", "--quiet", "--", stateFile], cleoDir);
|
|
39853
40204
|
const cachedResult = await cleoGitCommand(
|
|
39854
40205
|
["diff", "--cached", "--quiet", "--", stateFile],
|
|
@@ -39875,7 +40226,7 @@ async function shouldCheckpoint(options) {
|
|
|
39875
40226
|
const config2 = await loadCheckpointConfig(cwd);
|
|
39876
40227
|
if (!config2.enabled) return false;
|
|
39877
40228
|
const cleoDir = getCleoDir(cwd);
|
|
39878
|
-
if (!
|
|
40229
|
+
if (!existsSync19(cleoDir)) return false;
|
|
39879
40230
|
if (!isCleoGitInitialized(cleoDir)) return false;
|
|
39880
40231
|
if (!await isCleoGitRepo(cleoDir)) return false;
|
|
39881
40232
|
if (isMergeInProgress(cleoDir)) return false;
|
|
@@ -39949,7 +40300,7 @@ var init_git_checkpoint = __esm({
|
|
|
39949
40300
|
});
|
|
39950
40301
|
|
|
39951
40302
|
// packages/core/src/store/snapshot-gate.ts
|
|
39952
|
-
import { join as
|
|
40303
|
+
import { join as join24 } from "node:path";
|
|
39953
40304
|
function readGateState(db) {
|
|
39954
40305
|
const row = db.prepare("SELECT value FROM tasks_schema_meta WHERE key = ?").get(SNAPSHOT_GATE_META_KEY);
|
|
39955
40306
|
const state = { generation: 0, prefixes: {} };
|
|
@@ -40014,7 +40365,7 @@ async function runGatedSnapshot(opts, snapshot) {
|
|
|
40014
40365
|
return none("debounced");
|
|
40015
40366
|
}
|
|
40016
40367
|
}
|
|
40017
|
-
const lockPath2 =
|
|
40368
|
+
const lockPath2 = join24(opts.backupDir, GATE_LOCK_BASENAME);
|
|
40018
40369
|
let release;
|
|
40019
40370
|
try {
|
|
40020
40371
|
release = await acquireLock(lockPath2, {
|
|
@@ -40570,7 +40921,7 @@ __export(data_accessor_exports, {
|
|
|
40570
40921
|
getAccessorDb: () => getAccessorDb,
|
|
40571
40922
|
getTaskAccessor: () => getTaskAccessor
|
|
40572
40923
|
});
|
|
40573
|
-
import { resolve as
|
|
40924
|
+
import { resolve as resolve11 } from "node:path";
|
|
40574
40925
|
function assertTestEnv(dbPath) {
|
|
40575
40926
|
const testMode = process.env["CLEO_TEST_MODE"];
|
|
40576
40927
|
if (testMode !== "1") return;
|
|
@@ -40591,7 +40942,7 @@ function assertTestEnv(dbPath) {
|
|
|
40591
40942
|
}
|
|
40592
40943
|
}
|
|
40593
40944
|
async function createDataAccessor(cwd) {
|
|
40594
|
-
const root =
|
|
40945
|
+
const root = resolve11(cwd ?? getProjectRoot());
|
|
40595
40946
|
const inherited = worktreeScope.getStore();
|
|
40596
40947
|
const captured = inherited ? { ...inherited } : void 0;
|
|
40597
40948
|
captured?.execution?.assertActive();
|
|
@@ -40635,7 +40986,7 @@ __export(memory_sqlite_exports, {
|
|
|
40635
40986
|
resetBrainDbState: () => resetBrainDbState,
|
|
40636
40987
|
resolveBrainMigrationsFolder: () => resolveBrainMigrationsFolder
|
|
40637
40988
|
});
|
|
40638
|
-
import { createRequire as
|
|
40989
|
+
import { createRequire as createRequire7 } from "node:module";
|
|
40639
40990
|
function _getDrizzle2() {
|
|
40640
40991
|
if (_drizzle2 === null) {
|
|
40641
40992
|
const mod = _require4("drizzle-orm/node-sqlite");
|
|
@@ -40772,7 +41123,7 @@ var init_memory_sqlite = __esm({
|
|
|
40772
41123
|
init_resolve_migrations_folder();
|
|
40773
41124
|
init_memory_schema();
|
|
40774
41125
|
init_twin_collapse();
|
|
40775
|
-
_require4 =
|
|
41126
|
+
_require4 = createRequire7(import.meta.url);
|
|
40776
41127
|
_drizzle2 = null;
|
|
40777
41128
|
BRAIN_SCHEMA_VERSION = "1.0.0";
|
|
40778
41129
|
CONSOLIDATED_BRAIN_TABLES = [
|
|
@@ -40960,11 +41311,11 @@ var init_skills_schema = __esm({
|
|
|
40960
41311
|
});
|
|
40961
41312
|
|
|
40962
41313
|
// packages/core/src/store/skills-db.ts
|
|
40963
|
-
import { join as
|
|
41314
|
+
import { join as join25 } from "node:path";
|
|
40964
41315
|
import { and as and6, eq as eq8 } from "drizzle-orm";
|
|
40965
41316
|
function getDefaultSkillsDbPath() {
|
|
40966
41317
|
const cleoHome = getCleoHome();
|
|
40967
|
-
const dbPath =
|
|
41318
|
+
const dbPath = join25(cleoHome, "cleo.db");
|
|
40968
41319
|
if (!dbPath.startsWith(cleoHome)) {
|
|
40969
41320
|
throw new Error(
|
|
40970
41321
|
`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.`
|
|
@@ -41012,19 +41363,19 @@ import {
|
|
|
41012
41363
|
chmodSync,
|
|
41013
41364
|
closeSync,
|
|
41014
41365
|
copyFileSync as copyFileSync3,
|
|
41015
|
-
existsSync as
|
|
41366
|
+
existsSync as existsSync20,
|
|
41016
41367
|
fsyncSync,
|
|
41017
41368
|
linkSync,
|
|
41018
41369
|
mkdirSync as mkdirSync5,
|
|
41019
41370
|
openSync,
|
|
41020
41371
|
readdirSync as readdirSync5,
|
|
41021
|
-
realpathSync as
|
|
41372
|
+
realpathSync as realpathSync7,
|
|
41022
41373
|
renameSync as renameSync6,
|
|
41023
41374
|
rmSync,
|
|
41024
41375
|
statSync as statSync6,
|
|
41025
41376
|
unlinkSync as unlinkSync3
|
|
41026
41377
|
} from "node:fs";
|
|
41027
|
-
import { dirname as
|
|
41378
|
+
import { dirname as dirname15, join as join26, sep as sep4 } from "node:path";
|
|
41028
41379
|
function resolveInventoryPath(entry, cwd) {
|
|
41029
41380
|
try {
|
|
41030
41381
|
if (entry.tier === "global") {
|
|
@@ -41060,8 +41411,8 @@ async function openAgentRegistryDbForSnapshot() {
|
|
|
41060
41411
|
}
|
|
41061
41412
|
async function openTelemetryDbForSnapshot() {
|
|
41062
41413
|
try {
|
|
41063
|
-
const path =
|
|
41064
|
-
if (!
|
|
41414
|
+
const path = join26(getCleoHome(), "telemetry.db");
|
|
41415
|
+
if (!existsSync20(path)) return null;
|
|
41065
41416
|
} catch {
|
|
41066
41417
|
return null;
|
|
41067
41418
|
}
|
|
@@ -41173,7 +41524,7 @@ function rotateSnapshots(backupDir, prefix, justWritten) {
|
|
|
41173
41524
|
for (const name15 of names) {
|
|
41174
41525
|
if (keep.has(name15)) continue;
|
|
41175
41526
|
try {
|
|
41176
|
-
unlinkSync3(
|
|
41527
|
+
unlinkSync3(join26(backupDir, name15));
|
|
41177
41528
|
} catch {
|
|
41178
41529
|
}
|
|
41179
41530
|
}
|
|
@@ -41195,7 +41546,7 @@ async function snapshotProjectTargetsGated(targets, opts) {
|
|
|
41195
41546
|
let backupDir;
|
|
41196
41547
|
try {
|
|
41197
41548
|
const cleoDir = getCleoDir(cwd);
|
|
41198
|
-
backupDir =
|
|
41549
|
+
backupDir = join26(cleoDir, "backups", "sqlite");
|
|
41199
41550
|
mkdirSync5(backupDir, { recursive: true });
|
|
41200
41551
|
} catch {
|
|
41201
41552
|
return null;
|
|
@@ -41227,7 +41578,7 @@ function sourceFileOf(db) {
|
|
|
41227
41578
|
const location = db.location();
|
|
41228
41579
|
if (!location) return null;
|
|
41229
41580
|
try {
|
|
41230
|
-
return
|
|
41581
|
+
return realpathSync7(location);
|
|
41231
41582
|
} catch {
|
|
41232
41583
|
return location;
|
|
41233
41584
|
}
|
|
@@ -41238,10 +41589,10 @@ function hasLocation(db) {
|
|
|
41238
41589
|
function assertOwnedByProject(source, prefix, cwd) {
|
|
41239
41590
|
let cleoDir = getCleoDir(cwd);
|
|
41240
41591
|
try {
|
|
41241
|
-
cleoDir =
|
|
41592
|
+
cleoDir = realpathSync7(cleoDir);
|
|
41242
41593
|
} catch {
|
|
41243
41594
|
}
|
|
41244
|
-
if (!source.startsWith(cleoDir +
|
|
41595
|
+
if (!source.startsWith(cleoDir + sep4)) {
|
|
41245
41596
|
throw new Error(
|
|
41246
41597
|
`refusing to snapshot ${prefix}: its database ${source} is not inside ${cleoDir}`
|
|
41247
41598
|
);
|
|
@@ -41270,7 +41621,7 @@ function commitSnapshotFile(tmp, dest) {
|
|
|
41270
41621
|
}
|
|
41271
41622
|
renameSync6(tmp, dest);
|
|
41272
41623
|
try {
|
|
41273
|
-
const dirFd = openSync(
|
|
41624
|
+
const dirFd = openSync(dirname15(dest), "r");
|
|
41274
41625
|
try {
|
|
41275
41626
|
fsyncSync(dirFd);
|
|
41276
41627
|
} finally {
|
|
@@ -41293,7 +41644,7 @@ function removeDeadTempSnapshots(backupDir) {
|
|
|
41293
41644
|
const m = TEMP_SNAPSHOT_RE.exec(name15);
|
|
41294
41645
|
if (!m) continue;
|
|
41295
41646
|
const pid = Number(m[1]);
|
|
41296
|
-
const path =
|
|
41647
|
+
const path = join26(backupDir, name15);
|
|
41297
41648
|
const stale = pid !== process.pid && (!isPidAlive2(pid) || Date.now() - statSync6(path).mtimeMs > TEMP_SNAPSHOT_MAX_AGE_MS);
|
|
41298
41649
|
if (stale) rmSync(path, { force: true });
|
|
41299
41650
|
}
|
|
@@ -41303,7 +41654,7 @@ function removeDeadTempSnapshots(backupDir) {
|
|
|
41303
41654
|
async function freeSnapshotName(backupDir, prefix) {
|
|
41304
41655
|
for (let attempt = 0; attempt < SNAPSHOT_NAME_ATTEMPTS; attempt++) {
|
|
41305
41656
|
const name15 = `${prefix}-${formatTimestamp(/* @__PURE__ */ new Date())}.db`;
|
|
41306
|
-
if (!
|
|
41657
|
+
if (!existsSync20(join26(backupDir, name15))) return name15;
|
|
41307
41658
|
await new Promise((r) => setTimeout(r, 1e3 - Date.now() % 1e3 + 5));
|
|
41308
41659
|
}
|
|
41309
41660
|
throw new Error(`no free snapshot filename for ${prefix} in ${backupDir}`);
|
|
@@ -41331,7 +41682,7 @@ async function snapshotOne(target, backupDir, writtenBySource, cwd) {
|
|
|
41331
41682
|
if (opened && target.closeDb) target.closeDb(opened);
|
|
41332
41683
|
throw err;
|
|
41333
41684
|
}
|
|
41334
|
-
const dest =
|
|
41685
|
+
const dest = join26(backupDir, destName);
|
|
41335
41686
|
removeDeadTempSnapshots(backupDir);
|
|
41336
41687
|
const existing = source !== null ? writtenBySource.get(source) : void 0;
|
|
41337
41688
|
if (existing !== void 0) {
|
|
@@ -41385,13 +41736,13 @@ async function vacuumIntoBackup(opts = {}) {
|
|
|
41385
41736
|
function listSqliteBackupsForPrefix(prefix, cwd) {
|
|
41386
41737
|
try {
|
|
41387
41738
|
const cleoDir = getCleoDir(cwd);
|
|
41388
|
-
const backupDir =
|
|
41389
|
-
if (!
|
|
41739
|
+
const backupDir = join26(cleoDir, "backups", "sqlite");
|
|
41740
|
+
if (!existsSync20(backupDir)) return [];
|
|
41390
41741
|
const pattern = snapshotPattern(prefix);
|
|
41391
41742
|
return readdirSync5(backupDir).filter((f) => pattern.test(f)).map((f) => ({
|
|
41392
41743
|
name: f,
|
|
41393
|
-
path:
|
|
41394
|
-
mtimeMs: statSync6(
|
|
41744
|
+
path: join26(backupDir, f),
|
|
41745
|
+
mtimeMs: statSync6(join26(backupDir, f)).mtimeMs
|
|
41395
41746
|
})).sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
41396
41747
|
} catch {
|
|
41397
41748
|
return [];
|
|
@@ -41464,13 +41815,13 @@ __export(sqlite_exports, {
|
|
|
41464
41815
|
seedTasksMeta: () => seedTasksMeta,
|
|
41465
41816
|
worktreeRecoveryRefusal: () => worktreeRecoveryRefusal
|
|
41466
41817
|
});
|
|
41467
|
-
import { copyFileSync as copyFileSync4, existsSync as
|
|
41468
|
-
import { createRequire as
|
|
41469
|
-
import { basename as basename8, dirname as
|
|
41818
|
+
import { copyFileSync as copyFileSync4, existsSync as existsSync21, realpathSync as realpathSync8, renameSync as renameSync7, unlinkSync as unlinkSync4 } from "node:fs";
|
|
41819
|
+
import { createRequire as createRequire8 } from "node:module";
|
|
41820
|
+
import { basename as basename8, dirname as dirname16, resolve as resolve12 } from "node:path";
|
|
41470
41821
|
import { eq as eq9 } from "drizzle-orm";
|
|
41471
41822
|
function _getDrizzle3() {
|
|
41472
41823
|
if (_drizzle3 === null) {
|
|
41473
|
-
const _require7 =
|
|
41824
|
+
const _require7 = createRequire8(import.meta.url);
|
|
41474
41825
|
const mod = _require7("drizzle-orm/node-sqlite");
|
|
41475
41826
|
_drizzle3 = mod.drizzle;
|
|
41476
41827
|
}
|
|
@@ -41506,16 +41857,16 @@ function countBackupTasks(backupDb) {
|
|
|
41506
41857
|
return 0;
|
|
41507
41858
|
}
|
|
41508
41859
|
function isSameDirectory(a, b) {
|
|
41509
|
-
if (
|
|
41860
|
+
if (resolve12(a) === resolve12(b)) return true;
|
|
41510
41861
|
try {
|
|
41511
|
-
return
|
|
41862
|
+
return realpathSync8(a) === realpathSync8(b);
|
|
41512
41863
|
} catch {
|
|
41513
41864
|
return false;
|
|
41514
41865
|
}
|
|
41515
41866
|
}
|
|
41516
41867
|
function worktreeRecoveryRefusal(dbPath) {
|
|
41517
|
-
const storeCleoDir =
|
|
41518
|
-
const root =
|
|
41868
|
+
const storeCleoDir = dirname16(dbPath);
|
|
41869
|
+
const root = dirname16(storeCleoDir);
|
|
41519
41870
|
if (basename8(storeCleoDir) !== ".cleo" || !isGitLinkedCheckout(root)) return null;
|
|
41520
41871
|
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).`;
|
|
41521
41872
|
}
|
|
@@ -41527,7 +41878,7 @@ async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
|
|
|
41527
41878
|
const countResult = nativeDb.prepare("SELECT COUNT(*) as cnt FROM tasks_tasks").get();
|
|
41528
41879
|
const taskCount = countResult?.cnt ?? 0;
|
|
41529
41880
|
if (taskCount > 0) return false;
|
|
41530
|
-
const storeCleoDir =
|
|
41881
|
+
const storeCleoDir = dirname16(dbPath);
|
|
41531
41882
|
const worktreeRefusal = worktreeRecoveryRefusal(dbPath);
|
|
41532
41883
|
if (worktreeRefusal !== null) {
|
|
41533
41884
|
log15.warn({ dbPath }, worktreeRefusal);
|
|
@@ -41538,7 +41889,7 @@ async function autoRecoverFromBackup(nativeDb, dbPath, cwd) {
|
|
|
41538
41889
|
return false;
|
|
41539
41890
|
}
|
|
41540
41891
|
const newestBackup = backups[0];
|
|
41541
|
-
const backupCleoDir =
|
|
41892
|
+
const backupCleoDir = dirname16(dirname16(dirname16(newestBackup.path)));
|
|
41542
41893
|
if (!isSameDirectory(backupCleoDir, storeCleoDir)) {
|
|
41543
41894
|
log15.warn(
|
|
41544
41895
|
{ dbPath, backupPath: newestBackup.path },
|
|
@@ -41660,6 +42011,7 @@ function runMigrations(nativeDb, db, dbPath) {
|
|
|
41660
42011
|
try {
|
|
41661
42012
|
migrateWithRetry(db, migrationsFolder, nativeDb, "tasks", "sqlite");
|
|
41662
42013
|
} catch (error48) {
|
|
42014
|
+
if (isWorktreeBuildSchemaError(error48)) throw error48;
|
|
41663
42015
|
if (isSqliteBusy(error48) || !tableExists(nativeDb, "tasks_tasks")) throw error48;
|
|
41664
42016
|
try {
|
|
41665
42017
|
rebuildLegacyTasksLineage(
|
|
@@ -41701,7 +42053,7 @@ async function getSchemaVersion(cwd) {
|
|
|
41701
42053
|
return result[0]?.value ?? null;
|
|
41702
42054
|
}
|
|
41703
42055
|
function dbExists(cwd) {
|
|
41704
|
-
return
|
|
42056
|
+
return existsSync21(resolveDualScopeDbPath("project", cwd));
|
|
41705
42057
|
}
|
|
41706
42058
|
function getNativeDb(cwd) {
|
|
41707
42059
|
return boundProjectNative("tasks", cwd);
|
|
@@ -41737,6 +42089,7 @@ var init_sqlite3 = __esm({
|
|
|
41737
42089
|
init_resolve_migrations_folder();
|
|
41738
42090
|
init_sqlite_backup();
|
|
41739
42091
|
init_twin_collapse();
|
|
42092
|
+
init_worktree_build_guard();
|
|
41740
42093
|
init_worktree_isolation_guard();
|
|
41741
42094
|
init_sqlite_native();
|
|
41742
42095
|
init_tasks_schema();
|
|
@@ -41765,15 +42118,15 @@ var init_sqlite3 = __esm({
|
|
|
41765
42118
|
// packages/core/src/store/exodus/migrate.ts
|
|
41766
42119
|
import {
|
|
41767
42120
|
copyFileSync as copyFileSync5,
|
|
41768
|
-
existsSync as
|
|
42121
|
+
existsSync as existsSync22,
|
|
41769
42122
|
mkdirSync as mkdirSync6,
|
|
41770
|
-
readFileSync as
|
|
42123
|
+
readFileSync as readFileSync7,
|
|
41771
42124
|
renameSync as renameSync8,
|
|
41772
42125
|
statSync as statSync7,
|
|
41773
42126
|
unlinkSync as unlinkSync5,
|
|
41774
42127
|
writeFileSync as writeFileSync6
|
|
41775
42128
|
} from "node:fs";
|
|
41776
|
-
import { join as
|
|
42129
|
+
import { join as join27 } from "node:path";
|
|
41777
42130
|
function getSqliteVersion(db) {
|
|
41778
42131
|
try {
|
|
41779
42132
|
const row = db.prepare("SELECT sqlite_version() AS v").get();
|
|
@@ -41804,24 +42157,24 @@ function restoreGrandfatheredGuards(db, suspended) {
|
|
|
41804
42157
|
}
|
|
41805
42158
|
}
|
|
41806
42159
|
function writeJournal(stagingDir, journal) {
|
|
41807
|
-
const journalPath =
|
|
42160
|
+
const journalPath = join27(stagingDir, JOURNAL_FILENAME);
|
|
41808
42161
|
const tmpPath = `${journalPath}.tmp`;
|
|
41809
42162
|
writeFileSync6(tmpPath, JSON.stringify(journal, null, 2) + "\n", "utf8");
|
|
41810
42163
|
renameSync8(tmpPath, journalPath);
|
|
41811
42164
|
}
|
|
41812
42165
|
function readJournal(stagingDir) {
|
|
41813
|
-
const journalPath =
|
|
41814
|
-
if (!
|
|
42166
|
+
const journalPath = join27(stagingDir, JOURNAL_FILENAME);
|
|
42167
|
+
if (!existsSync22(journalPath)) return null;
|
|
41815
42168
|
try {
|
|
41816
|
-
return JSON.parse(
|
|
42169
|
+
return JSON.parse(readFileSync7(journalPath, "utf8"));
|
|
41817
42170
|
} catch {
|
|
41818
42171
|
return null;
|
|
41819
42172
|
}
|
|
41820
42173
|
}
|
|
41821
42174
|
function clearExodusJournal(stagingDir) {
|
|
41822
|
-
const journalPath =
|
|
42175
|
+
const journalPath = join27(stagingDir, JOURNAL_FILENAME);
|
|
41823
42176
|
try {
|
|
41824
|
-
if (!
|
|
42177
|
+
if (!existsSync22(journalPath)) return false;
|
|
41825
42178
|
unlinkSync5(journalPath);
|
|
41826
42179
|
log10.info(
|
|
41827
42180
|
{ stagingDir },
|
|
@@ -42117,7 +42470,7 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress, opt
|
|
|
42117
42470
|
mkdirSync6(stagingDir, { recursive: true });
|
|
42118
42471
|
let sqliteVersion = "unknown";
|
|
42119
42472
|
for (const src of sources) {
|
|
42120
|
-
if (
|
|
42473
|
+
if (existsSync22(src.path)) {
|
|
42121
42474
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
42122
42475
|
sqliteVersion = getSqliteVersion(snap.db);
|
|
42123
42476
|
snap.close();
|
|
@@ -42147,15 +42500,15 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress, opt
|
|
|
42147
42500
|
let reseedProject = null;
|
|
42148
42501
|
try {
|
|
42149
42502
|
for (const src of sources) {
|
|
42150
|
-
if (!
|
|
42151
|
-
const backupDest =
|
|
42503
|
+
if (!existsSync22(src.path)) continue;
|
|
42504
|
+
const backupDest = join27(stagingDir, `${src.name.replace(/[^a-z0-9-]/g, "_")}-backup.db`);
|
|
42152
42505
|
const srcBytes = safeStatBytes(src.path);
|
|
42153
42506
|
const skipStagingCopy = srcBytes > plan.stagingCopyThresholdBytes;
|
|
42154
42507
|
if (skipStagingCopy) {
|
|
42155
42508
|
onProgress?.(
|
|
42156
42509
|
`Skipping full staging copy of ${src.name} (${srcBytes} bytes > ${plan.stagingCopyThresholdBytes} threshold) \u2014 source is archived, not deleted, on success.`
|
|
42157
42510
|
);
|
|
42158
|
-
} else if (!
|
|
42511
|
+
} else if (!existsSync22(backupDest)) {
|
|
42159
42512
|
onProgress?.(`Backing up ${src.name} \u2192 staging dir\u2026`);
|
|
42160
42513
|
copyFileSync5(src.path, backupDest);
|
|
42161
42514
|
backupPaths.push(backupDest);
|
|
@@ -42188,8 +42541,8 @@ async function runExodusMigrate(plan, forceCrossVersion = false, onProgress, opt
|
|
|
42188
42541
|
}
|
|
42189
42542
|
prepareExodusRecovery(projectNative, stagingDir);
|
|
42190
42543
|
if (globalNative !== null) prepareExodusRecovery(globalNative, stagingDir);
|
|
42191
|
-
const projectSources = sources.filter((s) => s.targetScope === "project" &&
|
|
42192
|
-
const globalSources = sources.filter((s) => s.targetScope === "global" &&
|
|
42544
|
+
const projectSources = sources.filter((s) => s.targetScope === "project" && existsSync22(s.path));
|
|
42545
|
+
const globalSources = sources.filter((s) => s.targetScope === "global" && existsSync22(s.path));
|
|
42193
42546
|
if (globalNative === null && globalSources.length > 0)
|
|
42194
42547
|
throw new Error("A projectOnly exodus run was given global-scope sources");
|
|
42195
42548
|
await migrateScope(
|
|
@@ -42497,9 +42850,9 @@ __export(reconcile_exports, {
|
|
|
42497
42850
|
reconcileSupersededStores: () => reconcileSupersededStores,
|
|
42498
42851
|
unmigratedBareSources: () => unmigratedBareSources
|
|
42499
42852
|
});
|
|
42500
|
-
import { copyFileSync as copyFileSync6, existsSync as
|
|
42853
|
+
import { copyFileSync as copyFileSync6, existsSync as existsSync23, mkdirSync as mkdirSync7, mkdtempSync, rmSync as rmSync2, writeFileSync as writeFileSync7 } from "node:fs";
|
|
42501
42854
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
42502
|
-
import { basename as basename9, join as
|
|
42855
|
+
import { basename as basename9, join as join28 } from "node:path";
|
|
42503
42856
|
function ident2(name15) {
|
|
42504
42857
|
return `"${name15.replace(/"/g, '""')}"`;
|
|
42505
42858
|
}
|
|
@@ -42568,7 +42921,7 @@ function assessSupersededProjectStores(liveStorePath, sources, resolveTarget = r
|
|
|
42568
42921
|
}
|
|
42569
42922
|
function legacySourcesHoldRows(sources) {
|
|
42570
42923
|
for (const src of sources) {
|
|
42571
|
-
if (!
|
|
42924
|
+
if (!existsSync23(src.path)) continue;
|
|
42572
42925
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
42573
42926
|
try {
|
|
42574
42927
|
for (const table of orderTablesForCopy(snap.db)) {
|
|
@@ -42599,8 +42952,8 @@ async function bareTaskCoreSource(liveStorePath, resolveTarget, outDir) {
|
|
|
42599
42952
|
live.close();
|
|
42600
42953
|
}
|
|
42601
42954
|
if (tables.length === 0) return null;
|
|
42602
|
-
const seedPath = await buildFreshProjectStore(
|
|
42603
|
-
const path =
|
|
42955
|
+
const seedPath = await buildFreshProjectStore(join28(outDir, "fresh-project-seed.db"));
|
|
42956
|
+
const path = join28(outDir, "cleo-bare-task-core.db");
|
|
42604
42957
|
const snap = openCleoDbSnapshot(path, { readOnly: false });
|
|
42605
42958
|
let kept = 0;
|
|
42606
42959
|
try {
|
|
@@ -42648,7 +43001,7 @@ async function buildFreshProjectStore(path) {
|
|
|
42648
43001
|
}
|
|
42649
43002
|
function snapshotFresherBareRows(barePath, legacyTasksPath, stagingDir) {
|
|
42650
43003
|
if (legacyTasksPath === void 0) return null;
|
|
42651
|
-
const path =
|
|
43004
|
+
const path = join28(stagingDir, "cleo-bare-task-core-fresher.db");
|
|
42652
43005
|
const snap = openCleoDbSnapshot(barePath, { readOnly: true });
|
|
42653
43006
|
try {
|
|
42654
43007
|
snap.db.exec(`VACUUM INTO '${path.replace(/'/g, "''")}'`);
|
|
@@ -42799,7 +43152,7 @@ async function reconcileSuppressed(projectRoot, options, liveStorePath) {
|
|
|
42799
43152
|
const additive = options.additive === true;
|
|
42800
43153
|
const plan = buildExodusPlan(projectRoot);
|
|
42801
43154
|
const resolveTarget = await buildRuntimeTargetResolver();
|
|
42802
|
-
const scratch = mkdtempSync(
|
|
43155
|
+
const scratch = mkdtempSync(join28(tmpdir3(), "cleo-reconcile-"));
|
|
42803
43156
|
try {
|
|
42804
43157
|
return await reconcileWithScratch(
|
|
42805
43158
|
projectRoot,
|
|
@@ -42815,8 +43168,8 @@ async function reconcileSuppressed(projectRoot, options, liveStorePath) {
|
|
|
42815
43168
|
}
|
|
42816
43169
|
}
|
|
42817
43170
|
async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath, plan, resolveTarget, scratch) {
|
|
42818
|
-
const fileSources = plan.sources.filter((s) => s.targetScope === "project" &&
|
|
42819
|
-
const bare = !additive &&
|
|
43171
|
+
const fileSources = plan.sources.filter((s) => s.targetScope === "project" && existsSync23(s.path));
|
|
43172
|
+
const bare = !additive && existsSync23(liveStorePath) ? await bareTaskCoreSource(liveStorePath, resolveTarget, scratch) : null;
|
|
42820
43173
|
const copyResolver = additive ? (sourceName, legacyTable) => {
|
|
42821
43174
|
const r = resolveTarget(sourceName, legacyTable);
|
|
42822
43175
|
return r.kind !== "skip" && isLiveAuthoritative(sourceName, legacyTable, r.targetName) ? { kind: "skip", reason: "additive: live-authoritative task graph" } : r;
|
|
@@ -42835,7 +43188,7 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
42835
43188
|
stagingDir: null,
|
|
42836
43189
|
receiptPath: null
|
|
42837
43190
|
};
|
|
42838
|
-
if (sources.length === 0 || !
|
|
43191
|
+
if (sources.length === 0 || !existsSync23(liveStorePath)) {
|
|
42839
43192
|
return {
|
|
42840
43193
|
...base,
|
|
42841
43194
|
outcome: "nothing-to-reconcile",
|
|
@@ -42875,11 +43228,11 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
42875
43228
|
};
|
|
42876
43229
|
}
|
|
42877
43230
|
const iso = (/* @__PURE__ */ new Date()).toISOString().replace(/[:]/g, "").replace(/\..+Z$/, "Z");
|
|
42878
|
-
const stagingDir =
|
|
43231
|
+
const stagingDir = join28(resolveCleoDir(projectRoot), `${RECONCILE_DIR_PREFIX}${iso}`);
|
|
42879
43232
|
mkdirSync7(stagingDir, { recursive: true });
|
|
42880
43233
|
const copySources = sources.map((s) => {
|
|
42881
43234
|
if (s !== bare) return s;
|
|
42882
|
-
const kept =
|
|
43235
|
+
const kept = join28(stagingDir, basename9(s.path));
|
|
42883
43236
|
copyFileSync6(s.path, kept);
|
|
42884
43237
|
return { ...s, path: kept };
|
|
42885
43238
|
});
|
|
@@ -42899,7 +43252,7 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
42899
43252
|
const result = await withLock(
|
|
42900
43253
|
`${liveStorePath}.exodus-on-open.lock`,
|
|
42901
43254
|
async () => {
|
|
42902
|
-
const liveBefore =
|
|
43255
|
+
const liveBefore = join28(scratch, "live-before.db");
|
|
42903
43256
|
snapshotLive(liveStorePath, liveBefore);
|
|
42904
43257
|
const migrated = await runExodusMigrate(reconcilePlan, false, (msg) => log11.debug(msg), {
|
|
42905
43258
|
projectOnly: true,
|
|
@@ -42949,7 +43302,7 @@ async function reconcileWithScratch(projectRoot, dryRun, additive, liveStorePath
|
|
|
42949
43302
|
},
|
|
42950
43303
|
{ stale: 6e5, retries: 30 }
|
|
42951
43304
|
);
|
|
42952
|
-
const receiptPath =
|
|
43305
|
+
const receiptPath = join28(stagingDir, RECEIPT_FILENAME);
|
|
42953
43306
|
const receipt2 = { ...result, receiptPath };
|
|
42954
43307
|
writeFileSync7(receiptPath, `${JSON.stringify(receipt2, null, 2)}
|
|
42955
43308
|
`, "utf8");
|
|
@@ -43026,20 +43379,20 @@ var init_seal = __esm({
|
|
|
43026
43379
|
});
|
|
43027
43380
|
|
|
43028
43381
|
// packages/core/src/store/exodus/status.ts
|
|
43029
|
-
import { existsSync as
|
|
43030
|
-
import { join as
|
|
43382
|
+
import { existsSync as existsSync24, readdirSync as readdirSync6, readFileSync as readFileSync8, statSync as statSync8 } from "node:fs";
|
|
43383
|
+
import { join as join29 } from "node:path";
|
|
43031
43384
|
function readJournal2(stagingDir) {
|
|
43032
|
-
const p =
|
|
43033
|
-
if (!
|
|
43385
|
+
const p = join29(stagingDir, JOURNAL_FILENAME2);
|
|
43386
|
+
if (!existsSync24(p)) return null;
|
|
43034
43387
|
try {
|
|
43035
|
-
return JSON.parse(
|
|
43388
|
+
return JSON.parse(readFileSync8(p, "utf8"));
|
|
43036
43389
|
} catch {
|
|
43037
43390
|
return null;
|
|
43038
43391
|
}
|
|
43039
43392
|
}
|
|
43040
43393
|
function findStagingDirs(cleoDir) {
|
|
43041
43394
|
try {
|
|
43042
|
-
return readdirSync6(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) =>
|
|
43395
|
+
return readdirSync6(cleoDir, { withFileTypes: true }).filter((e) => e.isDirectory() && e.name.startsWith("exodus-staging-")).map((e) => join29(cleoDir, e.name)).sort().reverse();
|
|
43043
43396
|
} catch {
|
|
43044
43397
|
return [];
|
|
43045
43398
|
}
|
|
@@ -43062,15 +43415,15 @@ function runExodusStatus(cwd) {
|
|
|
43062
43415
|
const sourcesInfo = plan.sources.map((s) => ({
|
|
43063
43416
|
name: s.name,
|
|
43064
43417
|
path: s.path,
|
|
43065
|
-
exists:
|
|
43418
|
+
exists: existsSync24(s.path),
|
|
43066
43419
|
bytes: safeBytes(s.path)
|
|
43067
43420
|
}));
|
|
43068
43421
|
return {
|
|
43069
43422
|
hasStaging: latestStaging !== null,
|
|
43070
43423
|
stagingDir: latestStaging,
|
|
43071
43424
|
journal,
|
|
43072
|
-
projectDbExists:
|
|
43073
|
-
globalDbExists:
|
|
43425
|
+
projectDbExists: existsSync24(projectDbPath),
|
|
43426
|
+
globalDbExists: existsSync24(globalDbPath),
|
|
43074
43427
|
sourcesPresent: sourcesInfo.some((s) => s.exists),
|
|
43075
43428
|
sources: sourcesInfo
|
|
43076
43429
|
};
|
|
@@ -43087,8 +43440,8 @@ var init_status = __esm({
|
|
|
43087
43440
|
});
|
|
43088
43441
|
|
|
43089
43442
|
// packages/core/src/store/exodus/verify-migration.ts
|
|
43090
|
-
import { existsSync as
|
|
43091
|
-
import { createRequire as
|
|
43443
|
+
import { existsSync as existsSync25 } from "node:fs";
|
|
43444
|
+
import { createRequire as createRequire9 } from "node:module";
|
|
43092
43445
|
function orderByClause(db, tableName) {
|
|
43093
43446
|
try {
|
|
43094
43447
|
const pragma = db.prepare(`PRAGMA table_info("${tableName}")`).all();
|
|
@@ -43352,7 +43705,7 @@ function orphanAlreadyInSource(targetDb, fk, sources, resolveTarget = resolveCon
|
|
|
43352
43705
|
const anyFeeder = (targetTable, probe) => {
|
|
43353
43706
|
for (const feeder of feedersOf(targetTable)) {
|
|
43354
43707
|
const src = sources.find((s) => s.name === feeder.sourceName);
|
|
43355
|
-
if (src === void 0 || !
|
|
43708
|
+
if (src === void 0 || !existsSync25(src.path)) continue;
|
|
43356
43709
|
const snap = openCleoDbSnapshot(src.path, { readOnly: true });
|
|
43357
43710
|
try {
|
|
43358
43711
|
if (!tableExists3(snap.db, feeder.legacyTable)) continue;
|
|
@@ -43407,7 +43760,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress, resol
|
|
|
43407
43760
|
const preExistingForeignKeyViolations = [];
|
|
43408
43761
|
const failureLines = [];
|
|
43409
43762
|
const sourceOrphanSigs = /* @__PURE__ */ new Set();
|
|
43410
|
-
if (!
|
|
43763
|
+
if (!existsSync25(projectDbPath)) {
|
|
43411
43764
|
return {
|
|
43412
43765
|
ok: false,
|
|
43413
43766
|
tables: [],
|
|
@@ -43418,7 +43771,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress, resol
|
|
|
43418
43771
|
error: `Consolidated project cleo.db not found at ${projectDbPath}. Run 'cleo exodus migrate' first.`
|
|
43419
43772
|
};
|
|
43420
43773
|
}
|
|
43421
|
-
if (!
|
|
43774
|
+
if (!existsSync25(globalDbPath)) {
|
|
43422
43775
|
return {
|
|
43423
43776
|
ok: false,
|
|
43424
43777
|
tables: [],
|
|
@@ -43433,7 +43786,7 @@ function verifyMigration(sources, projectDbPath, globalDbPath, onProgress, resol
|
|
|
43433
43786
|
const globalSnap = openCleoDbSnapshot(globalDbPath, { readOnly: true });
|
|
43434
43787
|
try {
|
|
43435
43788
|
for (const src of sources) {
|
|
43436
|
-
if (!
|
|
43789
|
+
if (!existsSync25(src.path)) {
|
|
43437
43790
|
onProgress?.(`Skipping ${src.name} (not present)`);
|
|
43438
43791
|
continue;
|
|
43439
43792
|
}
|
|
@@ -43628,7 +43981,7 @@ var init_verify_migration = __esm({
|
|
|
43628
43981
|
init_column_transforms();
|
|
43629
43982
|
init_table_name_map();
|
|
43630
43983
|
log13 = getLogger("verify-migration");
|
|
43631
|
-
_require5 =
|
|
43984
|
+
_require5 = createRequire9(import.meta.url);
|
|
43632
43985
|
CHECK_ENUM_REGEX = /CHECK\s*\(\s*"([^"]+)"\s+(?:IS\s+NULL\s+OR\s+"[^"]+"\s+)?IN\s*\(([^)]*)\)\s*\)/gi;
|
|
43633
43986
|
}
|
|
43634
43987
|
});
|
|
@@ -43724,11 +44077,11 @@ __export(on_open_exports, {
|
|
|
43724
44077
|
maybeRunExodusOnOpen: () => maybeRunExodusOnOpen,
|
|
43725
44078
|
withExodusOnOpenSuppressed: () => withExodusOnOpenSuppressed
|
|
43726
44079
|
});
|
|
43727
|
-
import { existsSync as
|
|
44080
|
+
import { existsSync as existsSync26, mkdtempSync as mkdtempSync2, rmSync as rmSync3 } from "node:fs";
|
|
43728
44081
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
43729
|
-
import { join as
|
|
44082
|
+
import { join as join30, resolve as resolve13 } from "node:path";
|
|
43730
44083
|
async function withExodusOnOpenSuppressed(dbPath, fn) {
|
|
43731
|
-
const key =
|
|
44084
|
+
const key = resolve13(dbPath);
|
|
43732
44085
|
_reconcileInProgress.set(key, (_reconcileInProgress.get(key) ?? 0) + 1);
|
|
43733
44086
|
try {
|
|
43734
44087
|
return await fn();
|
|
@@ -43766,7 +44119,7 @@ function remedyFor(scope) {
|
|
|
43766
44119
|
}
|
|
43767
44120
|
async function strandedLegacySources(scope, cwd) {
|
|
43768
44121
|
const { buildExodusPlan: buildExodusPlan2, legacySourcesHoldRows: legacySourcesHoldRows2 } = await Promise.resolve().then(() => (init_exodus(), exodus_exports));
|
|
43769
|
-
return buildExodusPlan2(cwd).sources.filter((s) => s.targetScope === scope &&
|
|
44122
|
+
return buildExodusPlan2(cwd).sources.filter((s) => s.targetScope === scope && existsSync26(s.path)).filter((s) => legacySourcesHoldRows2([s])).map((s) => s.name);
|
|
43770
44123
|
}
|
|
43771
44124
|
async function rollbackBothScopes(plan) {
|
|
43772
44125
|
const { getDualScopeNativeDb: getDualScopeNativeDb2, openDualScopeDbAtPath: openDualScopeDbAtPath2 } = await Promise.resolve().then(() => (init_dual_scope_db(), dual_scope_db_exports));
|
|
@@ -43844,7 +44197,7 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
43844
44197
|
if (_exodusInProgress) {
|
|
43845
44198
|
return { outcome: "skipped", reason: "re-entrant open during active migration" };
|
|
43846
44199
|
}
|
|
43847
|
-
if (_reconcileInProgress.has(
|
|
44200
|
+
if (_reconcileInProgress.has(resolve13(dbPath))) {
|
|
43848
44201
|
return {
|
|
43849
44202
|
outcome: "skipped",
|
|
43850
44203
|
reason: "an explicit superseded-store reconcile of this store is in progress"
|
|
@@ -43877,14 +44230,14 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
43877
44230
|
const { buildExodusPlan: buildExodusPlan2, runExodusMigrate: runExodusMigrate2, verifyMigration: verifyMigration2, clearExodusJournal: clearExodusJournal2 } = await Promise.resolve().then(() => (init_exodus(), exodus_exports));
|
|
43878
44231
|
const plan = buildExodusPlan2(cwd);
|
|
43879
44232
|
const plannedTarget = scope === "project" ? plan.projectDbPath : plan.globalDbPath;
|
|
43880
|
-
if (
|
|
44233
|
+
if (resolve13(plannedTarget) !== resolve13(dbPath)) {
|
|
43881
44234
|
return {
|
|
43882
44235
|
outcome: "aborted",
|
|
43883
44236
|
reason: `migration plan target ${plannedTarget} does not match opened database ${dbPath}; no migration applied`
|
|
43884
44237
|
};
|
|
43885
44238
|
}
|
|
43886
44239
|
const scopeSources = plan.sources.filter((s) => s.targetScope === scope);
|
|
43887
|
-
if (!scopeSources.some((s) =>
|
|
44240
|
+
if (!scopeSources.some((s) => existsSync26(s.path))) {
|
|
43888
44241
|
return {
|
|
43889
44242
|
outcome: "skipped",
|
|
43890
44243
|
reason: `no legacy ${scope}-scope source DBs present (fresh install or cross-scope-only)`
|
|
@@ -43901,12 +44254,12 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
43901
44254
|
{
|
|
43902
44255
|
scope,
|
|
43903
44256
|
dbPath,
|
|
43904
|
-
sources: plan.sources.filter((s) =>
|
|
44257
|
+
sources: plan.sources.filter((s) => existsSync26(s.path)).map((s) => s.name)
|
|
43905
44258
|
},
|
|
43906
44259
|
"exodus-on-open: consolidated cleo.db is empty and legacy data present \u2014 auto-migrating"
|
|
43907
44260
|
);
|
|
43908
44261
|
_exodusInProgress = true;
|
|
43909
|
-
const bareScratch = mkdtempSync2(
|
|
44262
|
+
const bareScratch = mkdtempSync2(join30(tmpdir4(), "cleo-exodus-bare-"));
|
|
43910
44263
|
try {
|
|
43911
44264
|
const { buildRuntimeTargetResolver: buildRuntimeTargetResolver2 } = await Promise.resolve().then(() => (init_runtime_targets(), runtime_targets_exports));
|
|
43912
44265
|
const resolveTarget = await buildRuntimeTargetResolver2();
|
|
@@ -43914,7 +44267,7 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
43914
44267
|
const bare = scope === "project" ? await unmigratedBareSources2(
|
|
43915
44268
|
dbPath,
|
|
43916
44269
|
resolveTarget,
|
|
43917
|
-
plan.sources.find((s) => s.name === "tasks" &&
|
|
44270
|
+
plan.sources.find((s) => s.name === "tasks" && existsSync26(s.path))?.path,
|
|
43918
44271
|
bareScratch
|
|
43919
44272
|
) : { first: [], last: [] };
|
|
43920
44273
|
const migratePlan = { ...plan, sources: [...bare.first, ...plan.sources, ...bare.last] };
|
|
@@ -43978,7 +44331,7 @@ async function runExodusOnOpen(scope, dbPath, nativeDb, cwd) {
|
|
|
43978
44331
|
"exodus-on-open: parity verified \u2014 legacy data migrated into consolidated cleo.db"
|
|
43979
44332
|
);
|
|
43980
44333
|
try {
|
|
43981
|
-
const consumed = plan.sources.filter((s) =>
|
|
44334
|
+
const consumed = plan.sources.filter((s) => existsSync26(s.path));
|
|
43982
44335
|
const identities = await sealTargets(plan, consumed);
|
|
43983
44336
|
const archiveResult = archiveMigratedSources(consumed, cwd, plan, identities);
|
|
43984
44337
|
log14.info(
|
|
@@ -44053,9 +44406,9 @@ __export(dual_scope_db_exports, {
|
|
|
44053
44406
|
upsertIdempotent: () => upsertIdempotent,
|
|
44054
44407
|
withStoreSchemaOwnership: () => withStoreSchemaOwnership
|
|
44055
44408
|
});
|
|
44056
|
-
import { existsSync as
|
|
44057
|
-
import { createRequire as
|
|
44058
|
-
import { dirname as
|
|
44409
|
+
import { existsSync as existsSync27, mkdirSync as mkdirSync8 } from "node:fs";
|
|
44410
|
+
import { createRequire as createRequire10 } from "node:module";
|
|
44411
|
+
import { dirname as dirname17, join as join31, resolve as resolve14 } from "node:path";
|
|
44059
44412
|
function getDualScopeNativeDb(handle) {
|
|
44060
44413
|
const db = handle.db;
|
|
44061
44414
|
if ("$client" in db && db.$client instanceof getDatabaseSyncCtor()) return db.$client;
|
|
@@ -44077,9 +44430,9 @@ function cacheKey(scope, dbPath) {
|
|
|
44077
44430
|
}
|
|
44078
44431
|
function resolveDualScopeDbPath(scope, cwd, capturedGlobalHome) {
|
|
44079
44432
|
if (scope === "project") {
|
|
44080
|
-
return
|
|
44433
|
+
return join31(resolveCleoDir(cwd), "cleo.db");
|
|
44081
44434
|
}
|
|
44082
|
-
return
|
|
44435
|
+
return join31(capturedGlobalHome ?? getCleoHome(), "cleo.db");
|
|
44083
44436
|
}
|
|
44084
44437
|
function migrationsSetName(scope) {
|
|
44085
44438
|
return scope === "project" ? "drizzle-cleo-project" : "drizzle-cleo-global";
|
|
@@ -44129,8 +44482,8 @@ async function openDualScopeDb(scope, cwd, options) {
|
|
|
44129
44482
|
async function openDedicatedDualScopeDb(scope, dbPath, log15, execution) {
|
|
44130
44483
|
execution?.assertActive();
|
|
44131
44484
|
log15.debug({ scope, dbPath }, "opening DEDICATED (non-cached) dual-scope cleo.db (T11782 FIX D)");
|
|
44132
|
-
const dir =
|
|
44133
|
-
if (!
|
|
44485
|
+
const dir = dirname17(dbPath);
|
|
44486
|
+
if (!existsSync27(dir)) {
|
|
44134
44487
|
mkdirSync8(dir, { recursive: true });
|
|
44135
44488
|
}
|
|
44136
44489
|
execution?.assertActive();
|
|
@@ -44138,6 +44491,7 @@ async function openDedicatedDualScopeDb(scope, dbPath, log15, execution) {
|
|
|
44138
44491
|
const nativeDb = new DatabaseSyncCtor(dbPath, { allowExtension: true });
|
|
44139
44492
|
try {
|
|
44140
44493
|
applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
|
|
44494
|
+
installSchemaWriteGuard(nativeDb);
|
|
44141
44495
|
const drizzle2 = getDrizzle();
|
|
44142
44496
|
const db = drizzle2({ client: nativeDb });
|
|
44143
44497
|
const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
|
|
@@ -44186,11 +44540,12 @@ async function openDedicatedDualScopeDb(scope, dbPath, log15, execution) {
|
|
|
44186
44540
|
execution?.assertActive();
|
|
44187
44541
|
return handle;
|
|
44188
44542
|
} catch (err) {
|
|
44543
|
+
const explained = explainSchemaWriteDenial(nativeDb, err);
|
|
44189
44544
|
try {
|
|
44190
44545
|
nativeDb.close();
|
|
44191
44546
|
} catch {
|
|
44192
44547
|
}
|
|
44193
|
-
throw
|
|
44548
|
+
throw explained;
|
|
44194
44549
|
}
|
|
44195
44550
|
}
|
|
44196
44551
|
async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
@@ -44211,7 +44566,7 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44211
44566
|
);
|
|
44212
44567
|
}
|
|
44213
44568
|
const dedicated = options?.dedicated === true;
|
|
44214
|
-
const normalizedPath =
|
|
44569
|
+
const normalizedPath = resolve14(dbPath);
|
|
44215
44570
|
const key = cacheKey(scope, normalizedPath);
|
|
44216
44571
|
if (!dedicated) {
|
|
44217
44572
|
const existing = _cache.get(key);
|
|
@@ -44248,8 +44603,8 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44248
44603
|
}
|
|
44249
44604
|
let initResolve = null;
|
|
44250
44605
|
let initReject = null;
|
|
44251
|
-
const initPromise = new Promise((
|
|
44252
|
-
initResolve =
|
|
44606
|
+
const initPromise = new Promise((resolve17, reject) => {
|
|
44607
|
+
initResolve = resolve17;
|
|
44253
44608
|
initReject = reject;
|
|
44254
44609
|
});
|
|
44255
44610
|
_cache.set(key, {
|
|
@@ -44270,8 +44625,8 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44270
44625
|
try {
|
|
44271
44626
|
execution?.assertActive();
|
|
44272
44627
|
log15.debug({ scope, dbPath: normalizedPath }, "opening dual-scope cleo.db");
|
|
44273
|
-
const dir =
|
|
44274
|
-
if (!
|
|
44628
|
+
const dir = dirname17(normalizedPath);
|
|
44629
|
+
if (!existsSync27(dir)) {
|
|
44275
44630
|
mkdirSync8(dir, { recursive: true });
|
|
44276
44631
|
}
|
|
44277
44632
|
execution?.assertActive();
|
|
@@ -44279,6 +44634,7 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44279
44634
|
const nativeDb = new DatabaseSyncCtor(normalizedPath, { allowExtension: true });
|
|
44280
44635
|
openingNative = nativeDb;
|
|
44281
44636
|
applyPerfPragmas(nativeDb, memoryBoundedPragmaOverrides());
|
|
44637
|
+
installSchemaWriteGuard(nativeDb);
|
|
44282
44638
|
const drizzle2 = getDrizzle();
|
|
44283
44639
|
const db = drizzle2({ client: nativeDb });
|
|
44284
44640
|
const migrationsFolder = resolveCorePackageMigrationsFolder(migrationsSetName(scope));
|
|
@@ -44409,12 +44765,13 @@ async function openDualScopeDbAtPath(scope, dbPath, exodusCwd, options) {
|
|
|
44409
44765
|
execution?.assertActive();
|
|
44410
44766
|
initResolve(finalHandle);
|
|
44411
44767
|
} catch (err) {
|
|
44768
|
+
const explained = openingNative ? explainSchemaWriteDenial(openingNative, err) : err;
|
|
44412
44769
|
try {
|
|
44413
44770
|
if (!published && openingNative?.isOpen) openingNative.close();
|
|
44414
44771
|
} catch (closeError) {
|
|
44415
44772
|
log15.warn({ closeError }, "failed to close unpublished database initializer");
|
|
44416
44773
|
}
|
|
44417
|
-
initReject(
|
|
44774
|
+
initReject(explained);
|
|
44418
44775
|
}
|
|
44419
44776
|
})();
|
|
44420
44777
|
return initPromise;
|
|
@@ -44487,6 +44844,7 @@ var init_dual_scope_db = __esm({
|
|
|
44487
44844
|
init_relocated_store_guard();
|
|
44488
44845
|
init_resolve_migrations_folder();
|
|
44489
44846
|
init_sqlite_pragmas();
|
|
44847
|
+
init_worktree_build_guard();
|
|
44490
44848
|
init_worktree_isolation_guard();
|
|
44491
44849
|
init_writer_lease();
|
|
44492
44850
|
ExodusAbortWriteUnsafeError = class extends Error {
|
|
@@ -44509,7 +44867,7 @@ var init_dual_scope_db = __esm({
|
|
|
44509
44867
|
}
|
|
44510
44868
|
};
|
|
44511
44869
|
_cache = /* @__PURE__ */ new Map();
|
|
44512
|
-
_require6 =
|
|
44870
|
+
_require6 = createRequire10(import.meta.url);
|
|
44513
44871
|
_drizzle4 = null;
|
|
44514
44872
|
_DatabaseSyncCtor = null;
|
|
44515
44873
|
EntryCancelledError = class extends Error {
|
|
@@ -44540,7 +44898,7 @@ var init_dual_scope_db = __esm({
|
|
|
44540
44898
|
}
|
|
44541
44899
|
/** @inheritdoc */
|
|
44542
44900
|
async openProject(dbPath, options) {
|
|
44543
|
-
const normalized =
|
|
44901
|
+
const normalized = resolve14(dbPath);
|
|
44544
44902
|
if (options?.dedicated) {
|
|
44545
44903
|
const handle = await openDualScopeDbAtPath("project", normalized, options?.exodusCwd, {
|
|
44546
44904
|
dedicated: true
|
|
@@ -44552,7 +44910,7 @@ var init_dual_scope_db = __esm({
|
|
|
44552
44910
|
/** @inheritdoc */
|
|
44553
44911
|
async openGlobal(options) {
|
|
44554
44912
|
const dbPath = resolveDualScopeDbPath("global");
|
|
44555
|
-
const normalized =
|
|
44913
|
+
const normalized = resolve14(dbPath);
|
|
44556
44914
|
if (options?.dedicated) {
|
|
44557
44915
|
const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
|
|
44558
44916
|
dedicated: true
|
|
@@ -44563,7 +44921,7 @@ var init_dual_scope_db = __esm({
|
|
|
44563
44921
|
}
|
|
44564
44922
|
/** @inheritdoc */
|
|
44565
44923
|
async openGlobalAt(dbPath, options) {
|
|
44566
|
-
const normalized =
|
|
44924
|
+
const normalized = resolve14(dbPath);
|
|
44567
44925
|
if (options?.dedicated) {
|
|
44568
44926
|
const handle = await openDualScopeDbAtPath("global", normalized, options?.exodusCwd, {
|
|
44569
44927
|
dedicated: true
|
|
@@ -44574,7 +44932,7 @@ var init_dual_scope_db = __esm({
|
|
|
44574
44932
|
}
|
|
44575
44933
|
/** @inheritdoc */
|
|
44576
44934
|
closeProject(dbPath) {
|
|
44577
|
-
const normalized =
|
|
44935
|
+
const normalized = resolve14(dbPath);
|
|
44578
44936
|
this.closeEntry("project", normalized);
|
|
44579
44937
|
}
|
|
44580
44938
|
/** @inheritdoc */
|
|
@@ -44611,8 +44969,8 @@ var init_dual_scope_db = __esm({
|
|
|
44611
44969
|
const entryId = ++this._nextId;
|
|
44612
44970
|
let initResolve;
|
|
44613
44971
|
let initReject;
|
|
44614
|
-
const initPromise = new Promise((
|
|
44615
|
-
initResolve =
|
|
44972
|
+
const initPromise = new Promise((resolve17, reject) => {
|
|
44973
|
+
initResolve = resolve17;
|
|
44616
44974
|
initReject = reject;
|
|
44617
44975
|
});
|
|
44618
44976
|
this._registry.set(key, { id: entryId, store: null, initPromise });
|
|
@@ -45405,8 +45763,8 @@ __export(nexus_sqlite_exports, {
|
|
|
45405
45763
|
resetNexusDbState: () => resetNexusDbState,
|
|
45406
45764
|
resolveNexusMigrationsFolder: () => resolveNexusMigrationsFolder
|
|
45407
45765
|
});
|
|
45408
|
-
import { copyFileSync as copyFileSync7, existsSync as
|
|
45409
|
-
import { join as
|
|
45766
|
+
import { copyFileSync as copyFileSync7, existsSync as existsSync28 } from "node:fs";
|
|
45767
|
+
import { join as join32 } from "node:path";
|
|
45410
45768
|
function getNexusDbPath(cwd) {
|
|
45411
45769
|
return resolveDualScopeDbPath("project", cwd);
|
|
45412
45770
|
}
|
|
@@ -45442,12 +45800,13 @@ function ensureGlobalRegistryAttached(nativeDb) {
|
|
|
45442
45800
|
}
|
|
45443
45801
|
}
|
|
45444
45802
|
nativeDb.exec(`ATTACH DATABASE '${escaped}' AS ${NEXUS_GLOBAL_ATTACH_ALIAS}`);
|
|
45803
|
+
refreshSchemaWriteGuard(nativeDb);
|
|
45445
45804
|
}
|
|
45446
45805
|
function resolveNexusMigrationsFolder() {
|
|
45447
45806
|
return resolveCorePackageMigrationsFolder("drizzle-nexus");
|
|
45448
45807
|
}
|
|
45449
45808
|
function getNestedNexusSentinelPath() {
|
|
45450
|
-
return
|
|
45809
|
+
return join32(getCleoHome(), "nexus", NESTED_NEXUS_SENTINEL);
|
|
45451
45810
|
}
|
|
45452
45811
|
function detectAndWarnOnNestedNexus() {
|
|
45453
45812
|
let nestedPath;
|
|
@@ -45456,7 +45815,7 @@ function detectAndWarnOnNestedNexus() {
|
|
|
45456
45815
|
} catch {
|
|
45457
45816
|
return false;
|
|
45458
45817
|
}
|
|
45459
|
-
if (!
|
|
45818
|
+
if (!existsSync28(nestedPath)) return false;
|
|
45460
45819
|
if (_warnedNestedPaths.has(nestedPath)) return false;
|
|
45461
45820
|
_warnedNestedPaths.add(nestedPath);
|
|
45462
45821
|
const canonicalPath = getNexusDbPath();
|
|
@@ -45615,7 +45974,7 @@ function runNexusMigrations(nativeDb, db, dbPath) {
|
|
|
45615
45974
|
const migrationsFolder = resolveNexusMigrationsFolder();
|
|
45616
45975
|
if (tableExists4(nativeDb, "nexus_nodes")) {
|
|
45617
45976
|
const backupPath = dbPath.replace(/\.db$/, "-pre-cleo.db.bak");
|
|
45618
|
-
if (!
|
|
45977
|
+
if (!existsSync28(backupPath)) {
|
|
45619
45978
|
try {
|
|
45620
45979
|
copyFileSync7(dbPath, backupPath);
|
|
45621
45980
|
} catch {
|
|
@@ -45710,6 +46069,7 @@ var init_nexus_sqlite = __esm({
|
|
|
45710
46069
|
init_resolve_migrations_folder();
|
|
45711
46070
|
init_nexus_schema();
|
|
45712
46071
|
init_with_retry();
|
|
46072
|
+
init_worktree_build_guard();
|
|
45713
46073
|
NEXUS_SCHEMA_VERSION = "1.0.0";
|
|
45714
46074
|
NEXUS_GLOBAL_ATTACH_ALIAS = "nexus_global";
|
|
45715
46075
|
NESTED_NEXUS_SENTINEL = "nexus.db";
|
|
@@ -45744,15 +46104,15 @@ var init_legacy_alias = __esm({
|
|
|
45744
46104
|
|
|
45745
46105
|
// packages/core/src/llm/stable-device-id.ts
|
|
45746
46106
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
45747
|
-
import { existsSync as
|
|
45748
|
-
import { dirname as
|
|
46107
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync9, readFileSync as readFileSync9, renameSync as renameSync9, writeFileSync as writeFileSync8 } from "node:fs";
|
|
46108
|
+
import { dirname as dirname18 } from "node:path";
|
|
45749
46109
|
import { resolveStableDeviceIdPath } from "@cleocode/paths";
|
|
45750
46110
|
function getStableDeviceId() {
|
|
45751
46111
|
if (_cachedDeviceId !== null) return _cachedDeviceId;
|
|
45752
46112
|
const path = resolveStableDeviceIdPath();
|
|
45753
|
-
if (
|
|
46113
|
+
if (existsSync29(path)) {
|
|
45754
46114
|
try {
|
|
45755
|
-
const raw =
|
|
46115
|
+
const raw = readFileSync9(path, "utf-8").trim();
|
|
45756
46116
|
if (raw.length > 0) {
|
|
45757
46117
|
_cachedDeviceId = raw;
|
|
45758
46118
|
return raw;
|
|
@@ -45762,8 +46122,8 @@ function getStableDeviceId() {
|
|
|
45762
46122
|
}
|
|
45763
46123
|
const fresh = randomUUID3();
|
|
45764
46124
|
try {
|
|
45765
|
-
const dir =
|
|
45766
|
-
if (!
|
|
46125
|
+
const dir = dirname18(path);
|
|
46126
|
+
if (!existsSync29(dir)) {
|
|
45767
46127
|
mkdirSync9(dir, { recursive: true });
|
|
45768
46128
|
}
|
|
45769
46129
|
const tmpPath = `${path}.tmp.${process.pid}`;
|
|
@@ -45800,8 +46160,8 @@ var init_registry_roots = __esm({
|
|
|
45800
46160
|
// packages/core/src/nexus/projects-scan.ts
|
|
45801
46161
|
async function withinBudget(promise2, ms) {
|
|
45802
46162
|
let timer;
|
|
45803
|
-
const expiry = new Promise((
|
|
45804
|
-
timer = setTimeout(() =>
|
|
46163
|
+
const expiry = new Promise((resolve17) => {
|
|
46164
|
+
timer = setTimeout(() => resolve17("timeout"), ms);
|
|
45805
46165
|
timer.unref();
|
|
45806
46166
|
});
|
|
45807
46167
|
try {
|
|
@@ -45839,9 +46199,9 @@ __export(path_map_exports, {
|
|
|
45839
46199
|
supersededRegistryPath: () => supersededRegistryPath,
|
|
45840
46200
|
touchProjectLocation: () => touchProjectLocation
|
|
45841
46201
|
});
|
|
45842
|
-
import { existsSync as
|
|
46202
|
+
import { existsSync as existsSync30, lstatSync, readdirSync as readdirSync7 } from "node:fs";
|
|
45843
46203
|
import { lstat, readdir as readdir2 } from "node:fs/promises";
|
|
45844
|
-
import { isAbsolute as
|
|
46204
|
+
import { isAbsolute as isAbsolute5, join as join33, relative as relative3, sep as sep5 } from "node:path";
|
|
45845
46205
|
import { canonicalizePath as canonicalizePath3, readDeclaredProjectIdentity as readDeclaredProjectIdentity3 } from "@cleocode/paths";
|
|
45846
46206
|
import { and as and7, desc as desc3, eq as eq11, inArray as inArray5, ne as ne3 } from "drizzle-orm";
|
|
45847
46207
|
function holdingKey(projectId, path) {
|
|
@@ -45857,7 +46217,7 @@ function isSupersededRegistryPath(projectPath) {
|
|
|
45857
46217
|
return projectPath.startsWith(SUPERSEDED_PATH_PREFIX);
|
|
45858
46218
|
}
|
|
45859
46219
|
function projectHolding(path, projectId) {
|
|
45860
|
-
const cleoDir =
|
|
46220
|
+
const cleoDir = join33(path, ".cleo");
|
|
45861
46221
|
try {
|
|
45862
46222
|
lstatSync(cleoDir);
|
|
45863
46223
|
readdirSync7(cleoDir);
|
|
@@ -45869,7 +46229,7 @@ function projectHolding(path, projectId) {
|
|
|
45869
46229
|
return declared === null || declared.projectId === projectId ? "yes" : "no";
|
|
45870
46230
|
}
|
|
45871
46231
|
async function probeProjectHolding(path, projectId, timeoutMs) {
|
|
45872
|
-
const cleoDir =
|
|
46232
|
+
const cleoDir = join33(path, ".cleo");
|
|
45873
46233
|
const probe = async () => {
|
|
45874
46234
|
try {
|
|
45875
46235
|
await lstat(cleoDir);
|
|
@@ -45887,8 +46247,8 @@ async function probeProjectHolding(path, projectId, timeoutMs) {
|
|
|
45887
46247
|
return declared === null || declared.projectId === projectId ? "yes" : "no";
|
|
45888
46248
|
}
|
|
45889
46249
|
function isStrictlyInside(outer, inner) {
|
|
45890
|
-
const rel =
|
|
45891
|
-
return rel.length > 0 && rel !== ".." && !rel.startsWith(`..${
|
|
46250
|
+
const rel = relative3(canonicalizePath3(outer), canonicalizePath3(inner));
|
|
46251
|
+
return rel.length > 0 && rel !== ".." && !rel.startsWith(`..${sep5}`) && !isAbsolute5(rel);
|
|
45892
46252
|
}
|
|
45893
46253
|
function locationKey(projectId, deviceId, path) {
|
|
45894
46254
|
return and7(
|
|
@@ -46050,7 +46410,7 @@ function hasOtherLiveLocation(db, record2, deviceId) {
|
|
|
46050
46410
|
ne3(projectLocations.path, record2.projectPath)
|
|
46051
46411
|
)
|
|
46052
46412
|
).all().some(
|
|
46053
|
-
(location) => isStrictlyInside(record2.projectPath, location.path) &&
|
|
46413
|
+
(location) => isStrictlyInside(record2.projectPath, location.path) && existsSync30(location.path) && readDeclaredProjectIdentity3(location.path)?.projectId === record2.projectId
|
|
46054
46414
|
);
|
|
46055
46415
|
}
|
|
46056
46416
|
function demoteProjectLocation(db, record2, state) {
|
|
@@ -46101,7 +46461,7 @@ function rehomeDisplacedRows(db, projectId, projectPath, deviceId, probed) {
|
|
|
46101
46461
|
).orderBy(desc3(projectLocations.lastSeen)).all();
|
|
46102
46462
|
const present = (path) => {
|
|
46103
46463
|
const holding = probed?.get(holdingKey(row.projectId, path));
|
|
46104
|
-
return holding === void 0 ?
|
|
46464
|
+
return holding === void 0 ? existsSync30(path) : holding === "yes";
|
|
46105
46465
|
};
|
|
46106
46466
|
const home = candidates.find(
|
|
46107
46467
|
(c) => present(c.path) && db.select({ projectId: projectRegistry.projectId }).from(projectRegistry).where(eq11(projectRegistry.projectPath, c.path)).all().length === 0
|
|
@@ -46130,7 +46490,7 @@ async function listProjectCheckouts(projectId, opts = {}) {
|
|
|
46130
46490
|
projectHash: generateProjectHash(row.path),
|
|
46131
46491
|
firstSeen: row.firstSeen,
|
|
46132
46492
|
lastSeen: row.lastSeen,
|
|
46133
|
-
exists: local &&
|
|
46493
|
+
exists: local && existsSync30(row.path),
|
|
46134
46494
|
deviceId: local ? deviceId : row.deviceId,
|
|
46135
46495
|
state: row.state
|
|
46136
46496
|
});
|
|
@@ -46159,13 +46519,13 @@ __export(checkout_nonce_exports, {
|
|
|
46159
46519
|
readCheckoutNonce: () => readCheckoutNonce
|
|
46160
46520
|
});
|
|
46161
46521
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
46162
|
-
import { existsSync as
|
|
46163
|
-
import { join as
|
|
46522
|
+
import { existsSync as existsSync31, readFileSync as readFileSync10, renameSync as renameSync10, writeFileSync as writeFileSync9 } from "node:fs";
|
|
46523
|
+
import { join as join34 } from "node:path";
|
|
46164
46524
|
function readInfo(projectRoot) {
|
|
46165
|
-
const path =
|
|
46166
|
-
if (!
|
|
46525
|
+
const path = join34(projectRoot, ".cleo", "project-info.json");
|
|
46526
|
+
if (!existsSync31(path)) return null;
|
|
46167
46527
|
try {
|
|
46168
|
-
const parsed = JSON.parse(
|
|
46528
|
+
const parsed = JSON.parse(readFileSync10(path, "utf-8"));
|
|
46169
46529
|
return parsed !== null && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
46170
46530
|
} catch {
|
|
46171
46531
|
return null;
|
|
@@ -46181,7 +46541,7 @@ function ensureCheckoutNonce(projectRoot) {
|
|
|
46181
46541
|
const info = readInfo(projectRoot);
|
|
46182
46542
|
if (!info) return null;
|
|
46183
46543
|
const nonce = randomBytes2(16).toString("hex");
|
|
46184
|
-
const path =
|
|
46544
|
+
const path = join34(projectRoot, ".cleo", "project-info.json");
|
|
46185
46545
|
const temp = `${path}.${randomBytes2(6).toString("hex")}.tmp`;
|
|
46186
46546
|
writeFileSync9(temp, `${JSON.stringify({ ...info, [CHECKOUT_NONCE_FIELD]: nonce }, null, 2)}
|
|
46187
46547
|
`);
|
|
@@ -46256,10 +46616,10 @@ __export(paths_exports, {
|
|
|
46256
46616
|
validateProjectRoot: () => validateProjectRoot,
|
|
46257
46617
|
worktreeScope: () => worktreeScope
|
|
46258
46618
|
});
|
|
46259
|
-
import { existsSync as
|
|
46260
|
-
import { createRequire as
|
|
46619
|
+
import { existsSync as existsSync32, readFileSync as readFileSync11, statSync as statSync9 } from "node:fs";
|
|
46620
|
+
import { createRequire as createRequire11 } from "node:module";
|
|
46261
46621
|
import { homedir as homedir2 } from "node:os";
|
|
46262
|
-
import { basename as basename10, dirname as
|
|
46622
|
+
import { basename as basename10, dirname as dirname19, join as join35, resolve as resolve15 } from "node:path";
|
|
46263
46623
|
import {
|
|
46264
46624
|
getCanonicalTemplatesTildePath as _getCanonicalTemplatesTildePath,
|
|
46265
46625
|
getCleoTemplatesTildePath as _getCleoTemplatesTildePath,
|
|
@@ -46269,7 +46629,7 @@ import {
|
|
|
46269
46629
|
resolveCanonicalCleoDir as _resolveCanonicalCleoDir
|
|
46270
46630
|
} from "@cleocode/paths";
|
|
46271
46631
|
function _getDatabaseSyncCtor() {
|
|
46272
|
-
const _require7 =
|
|
46632
|
+
const _require7 = createRequire11(import.meta.url);
|
|
46273
46633
|
const mod = _require7("node:sqlite");
|
|
46274
46634
|
return mod.DatabaseSync;
|
|
46275
46635
|
}
|
|
@@ -46281,20 +46641,20 @@ function runWithWorktreeScopeFromEnv(fn) {
|
|
|
46281
46641
|
}
|
|
46282
46642
|
function isProjectInitialized(projectRoot) {
|
|
46283
46643
|
const root = projectRoot ?? getProjectRoot();
|
|
46284
|
-
const cleoDir =
|
|
46285
|
-
return
|
|
46644
|
+
const cleoDir = join35(root, ".cleo");
|
|
46645
|
+
return existsSync32(cleoDir) && existsSync32(join35(cleoDir, "tasks.db"));
|
|
46286
46646
|
}
|
|
46287
46647
|
function getCleoHome() {
|
|
46288
46648
|
return getPlatformPaths().data;
|
|
46289
46649
|
}
|
|
46290
46650
|
function getCleoTemplatesDir() {
|
|
46291
|
-
return
|
|
46651
|
+
return join35(getCleoHome(), "templates");
|
|
46292
46652
|
}
|
|
46293
46653
|
function getCleoSchemasDir() {
|
|
46294
|
-
return
|
|
46654
|
+
return join35(getCleoHome(), "schemas");
|
|
46295
46655
|
}
|
|
46296
46656
|
function getCleoDocsDir() {
|
|
46297
|
-
return
|
|
46657
|
+
return join35(getCleoHome(), "docs");
|
|
46298
46658
|
}
|
|
46299
46659
|
function getCleoDir(cwd) {
|
|
46300
46660
|
if (cwd) {
|
|
@@ -46343,24 +46703,24 @@ function getCleoDirAbsolute(cwd, opts) {
|
|
|
46343
46703
|
try {
|
|
46344
46704
|
const projectRoot = getProjectRoot(cwd);
|
|
46345
46705
|
const canonical = _resolveCanonicalCleoDir(project.projectId);
|
|
46346
|
-
if (canonical !== null && canonical ===
|
|
46706
|
+
if (canonical !== null && canonical === resolve15(projectRoot, cleoDir)) {
|
|
46347
46707
|
return canonical;
|
|
46348
46708
|
}
|
|
46349
|
-
return
|
|
46709
|
+
return resolve15(projectRoot, cleoDir);
|
|
46350
46710
|
} catch {
|
|
46351
|
-
return
|
|
46711
|
+
return resolve15(project.projectRoot, cleoDir);
|
|
46352
46712
|
}
|
|
46353
46713
|
}
|
|
46354
46714
|
try {
|
|
46355
|
-
return
|
|
46715
|
+
return resolve15(getProjectRoot(cwd), cleoDir);
|
|
46356
46716
|
} catch (err) {
|
|
46357
46717
|
if (opts?.bootstrap) {
|
|
46358
|
-
return
|
|
46718
|
+
return resolve15(cwd ?? process.cwd(), cleoDir);
|
|
46359
46719
|
}
|
|
46360
46720
|
if (_cwdHasGitAncestor(cwd)) {
|
|
46361
46721
|
throw err;
|
|
46362
46722
|
}
|
|
46363
|
-
return
|
|
46723
|
+
return resolve15(cwd ?? process.cwd(), cleoDir);
|
|
46364
46724
|
}
|
|
46365
46725
|
}
|
|
46366
46726
|
function resolveCanonicalCleoDir(projectId) {
|
|
@@ -46387,9 +46747,9 @@ function resolveCanonicalCleoDir(projectId) {
|
|
|
46387
46747
|
function _resolveProjectByCwdFromNexus(cwd) {
|
|
46388
46748
|
try {
|
|
46389
46749
|
const cleoHome = getCleoHome();
|
|
46390
|
-
const globalDbPath =
|
|
46391
|
-
if (!
|
|
46392
|
-
const start =
|
|
46750
|
+
const globalDbPath = join35(cleoHome, "cleo.db");
|
|
46751
|
+
if (!existsSync32(globalDbPath)) return null;
|
|
46752
|
+
const start = resolve15(cwd ?? process.cwd());
|
|
46393
46753
|
let current = start;
|
|
46394
46754
|
const DatabaseSync3 = _getDatabaseSyncCtor();
|
|
46395
46755
|
const db = new DatabaseSync3(globalDbPath, { readOnly: true });
|
|
@@ -46402,7 +46762,7 @@ function _resolveProjectByCwdFromNexus(cwd) {
|
|
|
46402
46762
|
if (row && typeof row.project_id === "string" && row.project_id.length > 0) {
|
|
46403
46763
|
return row.project_id;
|
|
46404
46764
|
}
|
|
46405
|
-
const parent =
|
|
46765
|
+
const parent = dirname19(current);
|
|
46406
46766
|
if (parent === current) break;
|
|
46407
46767
|
current = parent;
|
|
46408
46768
|
}
|
|
@@ -46422,18 +46782,18 @@ function _cleoDirEnvOverride() {
|
|
|
46422
46782
|
}
|
|
46423
46783
|
function _findCleoDirRoot(cwd) {
|
|
46424
46784
|
const homeRoot = homedir2();
|
|
46425
|
-
let current =
|
|
46785
|
+
let current = resolve15(cwd ?? process.cwd());
|
|
46426
46786
|
while (true) {
|
|
46427
46787
|
const isDangerousRoot = current === homeRoot || current === "/" || current === "";
|
|
46428
46788
|
if (!isDangerousRoot) {
|
|
46429
46789
|
try {
|
|
46430
|
-
if (statSync9(
|
|
46790
|
+
if (statSync9(join35(current, ".cleo")).isDirectory()) {
|
|
46431
46791
|
return current;
|
|
46432
46792
|
}
|
|
46433
46793
|
} catch {
|
|
46434
46794
|
}
|
|
46435
46795
|
}
|
|
46436
|
-
const parent =
|
|
46796
|
+
const parent = dirname19(current);
|
|
46437
46797
|
if (parent === current) break;
|
|
46438
46798
|
current = parent;
|
|
46439
46799
|
}
|
|
@@ -46452,7 +46812,7 @@ function resolveProjectByCwd(cwd) {
|
|
|
46452
46812
|
if (pathsResult !== null) {
|
|
46453
46813
|
return pathsResult.projectId;
|
|
46454
46814
|
}
|
|
46455
|
-
const start =
|
|
46815
|
+
const start = resolve15(from ?? process.cwd());
|
|
46456
46816
|
let current = start;
|
|
46457
46817
|
while (true) {
|
|
46458
46818
|
const mainRepo = _resolveMainRepoFromGitlink(current);
|
|
@@ -46463,7 +46823,7 @@ function resolveProjectByCwd(cwd) {
|
|
|
46463
46823
|
}
|
|
46464
46824
|
break;
|
|
46465
46825
|
}
|
|
46466
|
-
const parent =
|
|
46826
|
+
const parent = dirname19(current);
|
|
46467
46827
|
if (parent === current) break;
|
|
46468
46828
|
current = parent;
|
|
46469
46829
|
}
|
|
@@ -46482,7 +46842,7 @@ function resolveProjectByCwd(cwd) {
|
|
|
46482
46842
|
function resolveCleoDir(cwd) {
|
|
46483
46843
|
const scope = worktreeScope.getStore();
|
|
46484
46844
|
if (scope !== void 0) {
|
|
46485
|
-
return
|
|
46845
|
+
return join35(resolveStoreOwnerRoot(scope.worktreeRoot), ".cleo");
|
|
46486
46846
|
}
|
|
46487
46847
|
const override = _cleoDirEnvOverride();
|
|
46488
46848
|
if (override !== null) {
|
|
@@ -46490,16 +46850,16 @@ function resolveCleoDir(cwd) {
|
|
|
46490
46850
|
}
|
|
46491
46851
|
const root = _findCleoDirRoot(cwd);
|
|
46492
46852
|
if (root !== null) {
|
|
46493
|
-
return
|
|
46853
|
+
return join35(resolveStoreOwnerRoot(root), ".cleo");
|
|
46494
46854
|
}
|
|
46495
|
-
const start =
|
|
46855
|
+
const start = resolve15(cwd ?? process.cwd());
|
|
46496
46856
|
let current = start;
|
|
46497
46857
|
while (true) {
|
|
46498
46858
|
const mainRepo = _resolveMainRepoFromGitlink(current);
|
|
46499
46859
|
if (mainRepo !== null) {
|
|
46500
|
-
return
|
|
46860
|
+
return join35(mainRepo, ".cleo");
|
|
46501
46861
|
}
|
|
46502
|
-
const parent =
|
|
46862
|
+
const parent = dirname19(current);
|
|
46503
46863
|
if (parent === current) {
|
|
46504
46864
|
break;
|
|
46505
46865
|
}
|
|
@@ -46538,25 +46898,25 @@ function _resolveCleoDir(cwd) {
|
|
|
46538
46898
|
const project = _pathsResolveProjectByCwd(cwd);
|
|
46539
46899
|
if (project !== null) {
|
|
46540
46900
|
try {
|
|
46541
|
-
return
|
|
46901
|
+
return resolve15(getProjectRoot(cwd), cleoDir);
|
|
46542
46902
|
} catch {
|
|
46543
|
-
return
|
|
46903
|
+
return resolve15(project.projectRoot, cleoDir);
|
|
46544
46904
|
}
|
|
46545
46905
|
}
|
|
46546
46906
|
return getCleoDirAbsolute(cwd);
|
|
46547
46907
|
}
|
|
46548
46908
|
function _cwdHasGitAncestor(cwd) {
|
|
46549
|
-
const start =
|
|
46909
|
+
const start = resolve15(cwd ?? process.cwd());
|
|
46550
46910
|
let current = start;
|
|
46551
46911
|
while (true) {
|
|
46552
|
-
const gitMarker =
|
|
46912
|
+
const gitMarker = join35(current, ".git");
|
|
46553
46913
|
try {
|
|
46554
|
-
if (
|
|
46914
|
+
if (existsSync32(gitMarker)) {
|
|
46555
46915
|
return true;
|
|
46556
46916
|
}
|
|
46557
46917
|
} catch {
|
|
46558
46918
|
}
|
|
46559
|
-
const parent =
|
|
46919
|
+
const parent = dirname19(current);
|
|
46560
46920
|
if (parent === current) return false;
|
|
46561
46921
|
current = parent;
|
|
46562
46922
|
}
|
|
@@ -46583,55 +46943,55 @@ function resolveProjectPath(relativePath, cwd) {
|
|
|
46583
46943
|
return relativePath;
|
|
46584
46944
|
}
|
|
46585
46945
|
if (relativePath.startsWith("~/") || relativePath.startsWith("~\\") || relativePath === "~") {
|
|
46586
|
-
return
|
|
46946
|
+
return resolve15(homedir2(), relativePath.slice(2));
|
|
46587
46947
|
}
|
|
46588
|
-
return
|
|
46948
|
+
return resolve15(getProjectRoot(cwd), relativePath);
|
|
46589
46949
|
}
|
|
46590
46950
|
function getTaskPath(cwd) {
|
|
46591
|
-
return
|
|
46951
|
+
return join35(_resolveCleoDir(cwd), "tasks.db");
|
|
46592
46952
|
}
|
|
46593
46953
|
function getConfigPath(cwd) {
|
|
46594
|
-
return
|
|
46954
|
+
return join35(_resolveCleoDir(cwd), "config.json");
|
|
46595
46955
|
}
|
|
46596
46956
|
function getSessionsPath(cwd) {
|
|
46597
|
-
return
|
|
46957
|
+
return join35(_resolveCleoDir(cwd), "sessions.json");
|
|
46598
46958
|
}
|
|
46599
46959
|
function getArchivePath(cwd) {
|
|
46600
|
-
return
|
|
46960
|
+
return join35(_resolveCleoDir(cwd), "tasks-archive.json");
|
|
46601
46961
|
}
|
|
46602
46962
|
function getLogPath(cwd) {
|
|
46603
|
-
return
|
|
46963
|
+
return join35(_resolveCleoDir(cwd), "logs", "cleo.log");
|
|
46604
46964
|
}
|
|
46605
46965
|
function getBackupDir(cwd) {
|
|
46606
|
-
return
|
|
46966
|
+
return join35(_resolveCleoDir(cwd), "backups", "operational");
|
|
46607
46967
|
}
|
|
46608
46968
|
function getGlobalConfigPath() {
|
|
46609
|
-
return
|
|
46969
|
+
return join35(getCleoHome(), "config.json");
|
|
46610
46970
|
}
|
|
46611
46971
|
function getCleoGlobalRecipesDir() {
|
|
46612
|
-
return
|
|
46972
|
+
return join35(getCleoHome(), "global-recipes");
|
|
46613
46973
|
}
|
|
46614
46974
|
function getCleoGlobalJustfilePath() {
|
|
46615
|
-
return
|
|
46975
|
+
return join35(getCleoGlobalRecipesDir(), "justfile");
|
|
46616
46976
|
}
|
|
46617
46977
|
function getCleoPiExtensionsDir() {
|
|
46618
|
-
return
|
|
46978
|
+
return join35(getCleoHome(), "pi-extensions");
|
|
46619
46979
|
}
|
|
46620
46980
|
function getCleoCantWorkflowsDir() {
|
|
46621
|
-
return
|
|
46981
|
+
return join35(getCleoHome(), "cant-workflows");
|
|
46622
46982
|
}
|
|
46623
46983
|
function getCleoGlobalAgentsDir() {
|
|
46624
|
-
return
|
|
46984
|
+
return join35(getCleoHome(), "agents");
|
|
46625
46985
|
}
|
|
46626
46986
|
function getCleoGlobalCantAgentsDir() {
|
|
46627
|
-
return
|
|
46987
|
+
return join35(getCleoHome(), "cant", "agents");
|
|
46628
46988
|
}
|
|
46629
46989
|
function getAgentOutputsDir(cwd) {
|
|
46630
46990
|
const projectRoot = getProjectRoot(cwd);
|
|
46631
|
-
const configPath =
|
|
46632
|
-
if (
|
|
46991
|
+
const configPath = join35(projectRoot, ".cleo", "config.json");
|
|
46992
|
+
if (existsSync32(configPath)) {
|
|
46633
46993
|
try {
|
|
46634
|
-
const config2 = JSON.parse(
|
|
46994
|
+
const config2 = JSON.parse(readFileSync11(configPath, "utf-8"));
|
|
46635
46995
|
if (typeof config2.agentOutputs === "object" && config2.agentOutputs?.directory) {
|
|
46636
46996
|
return config2.agentOutputs.directory;
|
|
46637
46997
|
}
|
|
@@ -46654,17 +47014,17 @@ function getAgentOutputsAbsolute(cwd) {
|
|
|
46654
47014
|
if (isAbsolutePath2(dir)) {
|
|
46655
47015
|
return dir;
|
|
46656
47016
|
}
|
|
46657
|
-
return
|
|
47017
|
+
return resolve15(getProjectRoot(cwd), dir);
|
|
46658
47018
|
}
|
|
46659
47019
|
function getManifestPath(cwd) {
|
|
46660
47020
|
const outputDir = getAgentOutputsDir(cwd);
|
|
46661
47021
|
const projectRoot = getProjectRoot(cwd);
|
|
46662
|
-
const configPath =
|
|
47022
|
+
const configPath = join35(projectRoot, ".cleo", "config.json");
|
|
46663
47023
|
const legacyFileName = ["MANIFEST", "jsonl"].join(".");
|
|
46664
47024
|
let manifestFile = legacyFileName;
|
|
46665
|
-
if (
|
|
47025
|
+
if (existsSync32(configPath)) {
|
|
46666
47026
|
try {
|
|
46667
|
-
const config2 = JSON.parse(
|
|
47027
|
+
const config2 = JSON.parse(readFileSync11(configPath, "utf-8"));
|
|
46668
47028
|
const customFile = config2.agentOutputs?.manifestFile ?? config2.research?.manifestFile;
|
|
46669
47029
|
if (customFile) {
|
|
46670
47030
|
manifestFile = customFile;
|
|
@@ -46672,12 +47032,12 @@ function getManifestPath(cwd) {
|
|
|
46672
47032
|
} catch {
|
|
46673
47033
|
}
|
|
46674
47034
|
}
|
|
46675
|
-
return
|
|
47035
|
+
return resolve15(projectRoot, outputDir, manifestFile);
|
|
46676
47036
|
}
|
|
46677
47037
|
function getManifestArchivePath(cwd) {
|
|
46678
47038
|
const outputDir = getAgentOutputsDir(cwd);
|
|
46679
47039
|
const projectRoot = getProjectRoot(cwd);
|
|
46680
|
-
return
|
|
47040
|
+
return resolve15(projectRoot, outputDir, "MANIFEST.archive.jsonl");
|
|
46681
47041
|
}
|
|
46682
47042
|
function isAbsolutePath2(path) {
|
|
46683
47043
|
return _isAbsolutePath(path);
|
|
@@ -46701,24 +47061,24 @@ function getCanonicalTemplatesTildePath() {
|
|
|
46701
47061
|
return _getCanonicalTemplatesTildePath();
|
|
46702
47062
|
}
|
|
46703
47063
|
function getAgentsHome() {
|
|
46704
|
-
return process.env["AGENTS_HOME"] ??
|
|
47064
|
+
return process.env["AGENTS_HOME"] ?? join35(homedir2(), ".agents");
|
|
46705
47065
|
}
|
|
46706
47066
|
function getClaudeAgentsDir() {
|
|
46707
|
-
const claudeDir = process.env["CLAUDE_HOME"] ??
|
|
46708
|
-
return
|
|
47067
|
+
const claudeDir = process.env["CLAUDE_HOME"] ?? join35(homedir2(), ".claude");
|
|
47068
|
+
return join35(claudeDir, "agents");
|
|
46709
47069
|
}
|
|
46710
47070
|
function getClaudeMemDbPath() {
|
|
46711
|
-
return process.env["CLAUDE_MEM_DB"] ??
|
|
47071
|
+
return process.env["CLAUDE_MEM_DB"] ?? join35(homedir2(), ".claude-mem", "claude-mem.db");
|
|
46712
47072
|
}
|
|
46713
47073
|
function resolveWorktreeRouting(cwdOverride) {
|
|
46714
|
-
const cwd =
|
|
47074
|
+
const cwd = resolve15(cwdOverride ?? process.cwd());
|
|
46715
47075
|
const home = homedir2();
|
|
46716
47076
|
let worktreePath;
|
|
46717
47077
|
let current = cwd;
|
|
46718
47078
|
while (current !== home && current !== "/" && current !== "") {
|
|
46719
|
-
const gitPath =
|
|
47079
|
+
const gitPath = join35(current, ".git");
|
|
46720
47080
|
try {
|
|
46721
|
-
if (
|
|
47081
|
+
if (existsSync32(gitPath)) {
|
|
46722
47082
|
const stat3 = statSync9(gitPath);
|
|
46723
47083
|
if (stat3.isFile()) {
|
|
46724
47084
|
worktreePath = current;
|
|
@@ -46730,7 +47090,7 @@ function resolveWorktreeRouting(cwdOverride) {
|
|
|
46730
47090
|
}
|
|
46731
47091
|
} catch {
|
|
46732
47092
|
}
|
|
46733
|
-
const parent =
|
|
47093
|
+
const parent = dirname19(current);
|
|
46734
47094
|
if (parent === current) break;
|
|
46735
47095
|
current = parent;
|
|
46736
47096
|
}
|
|
@@ -46747,17 +47107,17 @@ function resolveWorktreeRouting(cwdOverride) {
|
|
|
46747
47107
|
}
|
|
46748
47108
|
function resolveWorktreeFilePath(filePath, routing) {
|
|
46749
47109
|
if (!routing.isWorktree || routing.worktreePath === void 0) {
|
|
46750
|
-
return
|
|
47110
|
+
return resolve15(filePath);
|
|
46751
47111
|
}
|
|
46752
|
-
return
|
|
47112
|
+
return resolve15(routing.cwd, filePath);
|
|
46753
47113
|
}
|
|
46754
47114
|
function detectStrayCleoDb(routing) {
|
|
46755
47115
|
if (!routing.isWorktree || routing.worktreePath === void 0) {
|
|
46756
47116
|
return void 0;
|
|
46757
47117
|
}
|
|
46758
|
-
const tasksDbPath =
|
|
47118
|
+
const tasksDbPath = join35(routing.worktreePath, ".cleo", "tasks.db");
|
|
46759
47119
|
try {
|
|
46760
|
-
if (
|
|
47120
|
+
if (existsSync32(tasksDbPath) && statSync9(tasksDbPath).isFile()) {
|
|
46761
47121
|
return tasksDbPath;
|
|
46762
47122
|
}
|
|
46763
47123
|
} catch {
|
|
@@ -46767,7 +47127,7 @@ function detectStrayCleoDb(routing) {
|
|
|
46767
47127
|
async function resolveProjectById(projectId) {
|
|
46768
47128
|
try {
|
|
46769
47129
|
const { getNexusDb: getNexusDb2, getNexusRegistryDbPath: getNexusRegistryDbPath2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
|
|
46770
|
-
if (!
|
|
47130
|
+
if (!existsSync32(getNexusRegistryDbPath2())) return null;
|
|
46771
47131
|
const { eq: eq12 } = await import("drizzle-orm");
|
|
46772
47132
|
const { projectRegistry: projectRegistry2 } = await Promise.resolve().then(() => (init_nexus_schema(), nexus_schema_exports));
|
|
46773
47133
|
const db = await getNexusDb2();
|
|
@@ -46802,9 +47162,9 @@ function _rowToRegistryEntry(row) {
|
|
|
46802
47162
|
};
|
|
46803
47163
|
}
|
|
46804
47164
|
function _readProjectNameFromInfo(projectRoot) {
|
|
46805
|
-
const infoPath =
|
|
46806
|
-
if (!
|
|
46807
|
-
const raw =
|
|
47165
|
+
const infoPath = join35(projectRoot, ".cleo", "project-info.json");
|
|
47166
|
+
if (!existsSync32(infoPath)) return void 0;
|
|
47167
|
+
const raw = readFileSync11(infoPath, "utf-8");
|
|
46808
47168
|
const data = JSON.parse(raw);
|
|
46809
47169
|
return typeof data.name === "string" && data.name.length > 0 ? data.name : void 0;
|
|
46810
47170
|
}
|
|
@@ -46855,7 +47215,7 @@ async function recordProjectEncounter(cwd) {
|
|
|
46855
47215
|
if (!shouldAutoRegisterProject(project.projectRoot, cleoHome)) return "ephemeral";
|
|
46856
47216
|
const checkout = captureProjectScope(project.projectRoot, worktreeScope.getStore()).worktreeRoot;
|
|
46857
47217
|
const { getNexusRegistryDb: getNexusRegistryDb2, getNexusRegistryDbPath: getNexusRegistryDbPath2 } = await Promise.resolve().then(() => (init_nexus_sqlite(), nexus_sqlite_exports));
|
|
46858
|
-
if (
|
|
47218
|
+
if (existsSync32(getNexusRegistryDbPath2(cleoHome))) {
|
|
46859
47219
|
const { and: and8, eq: eq12 } = await import("drizzle-orm");
|
|
46860
47220
|
const { projectLocations: projectLocations2, projectRegistry: projectRegistry2 } = await Promise.resolve().then(() => (init_nexus_schema(), nexus_schema_exports));
|
|
46861
47221
|
const { currentDeviceId: currentDeviceId2 } = await Promise.resolve().then(() => (init_path_map(), path_map_exports));
|
|
@@ -47032,42 +47392,42 @@ var init_paths = __esm({
|
|
|
47032
47392
|
// packages/core/src/store/file-utils.ts
|
|
47033
47393
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
47034
47394
|
import {
|
|
47035
|
-
existsSync as
|
|
47395
|
+
existsSync as existsSync33,
|
|
47036
47396
|
mkdirSync as mkdirSync10,
|
|
47037
47397
|
readdirSync as readdirSync8,
|
|
47038
|
-
readFileSync as
|
|
47398
|
+
readFileSync as readFileSync12,
|
|
47039
47399
|
renameSync as renameSync11,
|
|
47040
47400
|
unlinkSync as unlinkSync6,
|
|
47041
47401
|
writeFileSync as writeFileSync10
|
|
47042
47402
|
} from "node:fs";
|
|
47043
|
-
import { basename as basename11, dirname as
|
|
47403
|
+
import { basename as basename11, dirname as dirname20, join as join36 } from "node:path";
|
|
47044
47404
|
import * as lockfile3 from "proper-lockfile";
|
|
47045
47405
|
function rotateBackup(filePath, mode) {
|
|
47046
|
-
const dir =
|
|
47406
|
+
const dir = dirname20(filePath);
|
|
47047
47407
|
const name15 = basename11(filePath);
|
|
47048
|
-
const backupDir =
|
|
47408
|
+
const backupDir = join36(dir, ".backups");
|
|
47049
47409
|
const dirMode = typeof mode === "number" ? modeToDirMode(mode) : void 0;
|
|
47050
|
-
if (!
|
|
47410
|
+
if (!existsSync33(backupDir)) {
|
|
47051
47411
|
mkdirSync10(backupDir, { recursive: true, mode: dirMode });
|
|
47052
47412
|
}
|
|
47053
47413
|
for (let i = MAX_BACKUPS; i >= 1; i--) {
|
|
47054
|
-
const current =
|
|
47414
|
+
const current = join36(backupDir, `${name15}.${i}`);
|
|
47055
47415
|
if (i === MAX_BACKUPS) {
|
|
47056
47416
|
try {
|
|
47057
47417
|
unlinkSync6(current);
|
|
47058
47418
|
} catch {
|
|
47059
47419
|
}
|
|
47060
47420
|
} else {
|
|
47061
|
-
const next =
|
|
47421
|
+
const next = join36(backupDir, `${name15}.${i + 1}`);
|
|
47062
47422
|
try {
|
|
47063
|
-
if (
|
|
47423
|
+
if (existsSync33(current)) renameSync11(current, next);
|
|
47064
47424
|
} catch {
|
|
47065
47425
|
}
|
|
47066
47426
|
}
|
|
47067
47427
|
}
|
|
47068
47428
|
try {
|
|
47069
|
-
const content =
|
|
47070
|
-
const backupPath =
|
|
47429
|
+
const content = readFileSync12(filePath, "utf-8");
|
|
47430
|
+
const backupPath = join36(backupDir, `${name15}.1`);
|
|
47071
47431
|
if (typeof mode === "number") {
|
|
47072
47432
|
writeFileSync10(backupPath, content, { encoding: "utf-8", mode });
|
|
47073
47433
|
} else {
|
|
@@ -47087,8 +47447,8 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
47087
47447
|
const opts = typeof optsOrIndent === "number" ? { indent: optsOrIndent } : optsOrIndent;
|
|
47088
47448
|
const indent = opts.indent ?? 2;
|
|
47089
47449
|
const mode = opts.mode;
|
|
47090
|
-
const dir =
|
|
47091
|
-
const tempPath =
|
|
47450
|
+
const dir = dirname20(filePath);
|
|
47451
|
+
const tempPath = join36(dir, `.${basename11(filePath)}.${randomBytes3(6).toString("hex")}.tmp`);
|
|
47092
47452
|
const content = JSON.stringify(data, null, indent) + "\n";
|
|
47093
47453
|
if (typeof mode === "number") {
|
|
47094
47454
|
writeFileSync10(tempPath, content, { encoding: "utf-8", mode });
|
|
@@ -47096,7 +47456,7 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
47096
47456
|
writeFileSync10(tempPath, content, "utf-8");
|
|
47097
47457
|
}
|
|
47098
47458
|
try {
|
|
47099
|
-
if (
|
|
47459
|
+
if (existsSync33(filePath)) {
|
|
47100
47460
|
rotateBackup(filePath, mode);
|
|
47101
47461
|
}
|
|
47102
47462
|
renameSync11(tempPath, filePath);
|
|
@@ -47110,7 +47470,7 @@ function writeJsonFileAtomic(filePath, data, optsOrIndent = 2) {
|
|
|
47110
47470
|
}
|
|
47111
47471
|
function readJsonFile(filePath) {
|
|
47112
47472
|
try {
|
|
47113
|
-
const content =
|
|
47473
|
+
const content = readFileSync12(filePath, "utf-8");
|
|
47114
47474
|
return JSON.parse(content);
|
|
47115
47475
|
} catch (error48) {
|
|
47116
47476
|
if (error48.code === "ENOENT") {
|
|
@@ -47120,12 +47480,12 @@ function readJsonFile(filePath) {
|
|
|
47120
47480
|
}
|
|
47121
47481
|
}
|
|
47122
47482
|
async function withLock2(filePath, transform2, opts = {}) {
|
|
47123
|
-
const dir =
|
|
47483
|
+
const dir = dirname20(filePath);
|
|
47124
47484
|
const dirMode = typeof opts.mode === "number" ? modeToDirMode(opts.mode) : void 0;
|
|
47125
|
-
if (!
|
|
47485
|
+
if (!existsSync33(dir)) {
|
|
47126
47486
|
mkdirSync10(dir, { recursive: true, mode: dirMode });
|
|
47127
47487
|
}
|
|
47128
|
-
if (!
|
|
47488
|
+
if (!existsSync33(filePath)) {
|
|
47129
47489
|
if (typeof opts.mode === "number") {
|
|
47130
47490
|
writeFileSync10(filePath, "", { encoding: "utf-8", mode: opts.mode });
|
|
47131
47491
|
} else {
|
|
@@ -47146,11 +47506,11 @@ async function withLock2(filePath, transform2, opts = {}) {
|
|
|
47146
47506
|
}
|
|
47147
47507
|
}
|
|
47148
47508
|
async function withFileLock(filePath, operation) {
|
|
47149
|
-
const dir =
|
|
47150
|
-
if (!
|
|
47509
|
+
const dir = dirname20(filePath);
|
|
47510
|
+
if (!existsSync33(dir)) {
|
|
47151
47511
|
mkdirSync10(dir, { recursive: true });
|
|
47152
47512
|
}
|
|
47153
|
-
if (!
|
|
47513
|
+
if (!existsSync33(filePath)) {
|
|
47154
47514
|
writeFileSync10(filePath, "", "utf-8");
|
|
47155
47515
|
}
|
|
47156
47516
|
let release;
|
|
@@ -47184,10 +47544,10 @@ var init_file_utils = __esm({
|
|
|
47184
47544
|
|
|
47185
47545
|
// packages/core/src/llm/credential-removal.ts
|
|
47186
47546
|
import { unlinkSync as unlinkSync7 } from "node:fs";
|
|
47187
|
-
import { join as
|
|
47547
|
+
import { join as join37 } from "node:path";
|
|
47188
47548
|
import { getCleoHome as getCleoHome4 } from "@cleocode/paths";
|
|
47189
47549
|
function suppressionStatePath() {
|
|
47190
|
-
return
|
|
47550
|
+
return join37(getCleoHome4(), SUPPRESSION_FILENAME);
|
|
47191
47551
|
}
|
|
47192
47552
|
function readSuppressionFile() {
|
|
47193
47553
|
const data = readJsonFile(suppressionStatePath());
|
|
@@ -47291,7 +47651,7 @@ var init_credential_removal = __esm({
|
|
|
47291
47651
|
sourceId: "cleo-pkce",
|
|
47292
47652
|
description: "Delete CLEO-issued PKCE token at <CLEO_HOME>/anthropic-oauth.json",
|
|
47293
47653
|
async remove() {
|
|
47294
|
-
const path =
|
|
47654
|
+
const path = join37(getCleoHome4(), "anthropic-oauth.json");
|
|
47295
47655
|
const cleaned = [];
|
|
47296
47656
|
try {
|
|
47297
47657
|
unlinkSync7(path);
|
|
@@ -47349,12 +47709,12 @@ var init_credential_removal = __esm({
|
|
|
47349
47709
|
});
|
|
47350
47710
|
|
|
47351
47711
|
// packages/core/src/llm/credential-seeders/claude-code-seeder.ts
|
|
47352
|
-
import { readFileSync as
|
|
47712
|
+
import { readFileSync as readFileSync13 } from "node:fs";
|
|
47353
47713
|
import { homedir as homedir3 } from "node:os";
|
|
47354
|
-
import { join as
|
|
47714
|
+
import { join as join38 } from "node:path";
|
|
47355
47715
|
function defaultReadCredentialFile() {
|
|
47356
47716
|
try {
|
|
47357
|
-
return
|
|
47717
|
+
return readFileSync13(join38(homedir3(), ".claude", ".credentials.json"), "utf-8");
|
|
47358
47718
|
} catch {
|
|
47359
47719
|
return null;
|
|
47360
47720
|
}
|
|
@@ -47448,14 +47808,14 @@ var init_claude_code_seeder = __esm({
|
|
|
47448
47808
|
});
|
|
47449
47809
|
|
|
47450
47810
|
// packages/core/src/llm/credential-seeders/cleo-pkce-seeder.ts
|
|
47451
|
-
import { readFileSync as
|
|
47452
|
-
import { join as
|
|
47811
|
+
import { readFileSync as readFileSync14 } from "node:fs";
|
|
47812
|
+
import { join as join39 } from "node:path";
|
|
47453
47813
|
function defaultCleoPkcePath() {
|
|
47454
|
-
return
|
|
47814
|
+
return join39(getCleoHome(), "anthropic-oauth.json");
|
|
47455
47815
|
}
|
|
47456
47816
|
function defaultReadCredentialFile2() {
|
|
47457
47817
|
try {
|
|
47458
|
-
return
|
|
47818
|
+
return readFileSync14(defaultCleoPkcePath(), "utf-8");
|
|
47459
47819
|
} catch {
|
|
47460
47820
|
return null;
|
|
47461
47821
|
}
|
|
@@ -47522,13 +47882,13 @@ var init_cleo_pkce_seeder = __esm({
|
|
|
47522
47882
|
});
|
|
47523
47883
|
|
|
47524
47884
|
// packages/core/src/llm/credential-seeders/codex-cli-seeder.ts
|
|
47525
|
-
import { existsSync as
|
|
47885
|
+
import { existsSync as existsSync34, readFileSync as readFileSync15 } from "node:fs";
|
|
47526
47886
|
import { homedir as homedir4 } from "node:os";
|
|
47527
|
-
import { join as
|
|
47887
|
+
import { join as join40 } from "node:path";
|
|
47528
47888
|
function getCodexAuthPath() {
|
|
47529
47889
|
const codexHome = (process.env["CODEX_HOME"] ?? "").trim();
|
|
47530
|
-
const root = codexHome ||
|
|
47531
|
-
return
|
|
47890
|
+
const root = codexHome || join40(homedir4(), ".codex");
|
|
47891
|
+
return join40(root, "auth.json");
|
|
47532
47892
|
}
|
|
47533
47893
|
var CodexCliSeeder, codexCliSeeder;
|
|
47534
47894
|
var init_codex_cli_seeder = __esm({
|
|
@@ -47547,12 +47907,12 @@ var init_codex_cli_seeder = __esm({
|
|
|
47547
47907
|
*/
|
|
47548
47908
|
async seed() {
|
|
47549
47909
|
const authPath = getCodexAuthPath();
|
|
47550
|
-
if (!
|
|
47910
|
+
if (!existsSync34(authPath)) {
|
|
47551
47911
|
return { entries: [] };
|
|
47552
47912
|
}
|
|
47553
47913
|
let raw;
|
|
47554
47914
|
try {
|
|
47555
|
-
raw =
|
|
47915
|
+
raw = readFileSync15(authPath, "utf-8");
|
|
47556
47916
|
} catch (err) {
|
|
47557
47917
|
return {
|
|
47558
47918
|
entries: [],
|
|
@@ -47742,11 +48102,11 @@ var init_google_pkce = __esm({
|
|
|
47742
48102
|
});
|
|
47743
48103
|
|
|
47744
48104
|
// packages/core/src/llm/credential-seeders/gemini-cli-seeder.ts
|
|
47745
|
-
import { existsSync as
|
|
47746
|
-
import { join as
|
|
48105
|
+
import { existsSync as existsSync35, readFileSync as readFileSync16 } from "node:fs";
|
|
48106
|
+
import { join as join41 } from "node:path";
|
|
47747
48107
|
import { getCleoHome as getCleoHome5 } from "@cleocode/paths";
|
|
47748
48108
|
function getGoogleOauthPath() {
|
|
47749
|
-
return
|
|
48109
|
+
return join41(getCleoHome5(), "google_oauth.json");
|
|
47750
48110
|
}
|
|
47751
48111
|
function parseGoogleOauthFile(raw) {
|
|
47752
48112
|
let json2;
|
|
@@ -47791,12 +48151,12 @@ var init_gemini_cli_seeder = __esm({
|
|
|
47791
48151
|
*/
|
|
47792
48152
|
async seed() {
|
|
47793
48153
|
const path = getGoogleOauthPath();
|
|
47794
|
-
if (!
|
|
48154
|
+
if (!existsSync35(path)) {
|
|
47795
48155
|
return { entries: [] };
|
|
47796
48156
|
}
|
|
47797
48157
|
let raw;
|
|
47798
48158
|
try {
|
|
47799
|
-
raw =
|
|
48159
|
+
raw = readFileSync16(path, "utf-8");
|
|
47800
48160
|
} catch (err) {
|
|
47801
48161
|
return {
|
|
47802
48162
|
entries: [],
|
|
@@ -48016,23 +48376,23 @@ var init_credential_seeders = __esm({
|
|
|
48016
48376
|
|
|
48017
48377
|
// packages/core/src/llm/global-config-migration.ts
|
|
48018
48378
|
import {
|
|
48019
|
-
existsSync as
|
|
48379
|
+
existsSync as existsSync36,
|
|
48020
48380
|
mkdirSync as mkdirSync11,
|
|
48021
|
-
readFileSync as
|
|
48381
|
+
readFileSync as readFileSync17,
|
|
48022
48382
|
renameSync as renameSync12,
|
|
48023
48383
|
unlinkSync as unlinkSync8,
|
|
48024
48384
|
writeFileSync as writeFileSync11
|
|
48025
48385
|
} from "node:fs";
|
|
48026
|
-
import { join as
|
|
48386
|
+
import { join as join42 } from "node:path";
|
|
48027
48387
|
import { getCleoHome as getCleoHome6, getCleoPlatformPaths as getCleoPlatformPaths2 } from "@cleocode/paths";
|
|
48028
48388
|
function configDirGlobalConfigPath() {
|
|
48029
|
-
return
|
|
48389
|
+
return join42(getCleoPlatformPaths2().config, GLOBAL_CONFIG_FILENAME);
|
|
48030
48390
|
}
|
|
48031
48391
|
function legacyGlobalConfigPath() {
|
|
48032
|
-
return
|
|
48392
|
+
return join42(getCleoHome6(), GLOBAL_CONFIG_FILENAME);
|
|
48033
48393
|
}
|
|
48034
48394
|
function migrationMarkerPath() {
|
|
48035
|
-
return
|
|
48395
|
+
return join42(getCleoHome6(), MIGRATIONS_SUBDIR, MIGRATION_MARKER);
|
|
48036
48396
|
}
|
|
48037
48397
|
function tempTargetPath() {
|
|
48038
48398
|
return `${configDirGlobalConfigPath()}.tmp`;
|
|
@@ -48042,17 +48402,17 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
48042
48402
|
const source = legacyGlobalConfigPath();
|
|
48043
48403
|
const target = configDirGlobalConfigPath();
|
|
48044
48404
|
const marker16 = migrationMarkerPath();
|
|
48045
|
-
if (
|
|
48046
|
-
if (!
|
|
48405
|
+
if (existsSync36(marker16)) return false;
|
|
48406
|
+
if (!existsSync36(source)) {
|
|
48047
48407
|
stampMarker(marker16);
|
|
48048
48408
|
return false;
|
|
48049
48409
|
}
|
|
48050
|
-
if (
|
|
48410
|
+
if (existsSync36(target)) {
|
|
48051
48411
|
backupSourceQuiet(source);
|
|
48052
48412
|
stampMarker(marker16);
|
|
48053
48413
|
return false;
|
|
48054
48414
|
}
|
|
48055
|
-
const raw =
|
|
48415
|
+
const raw = readFileSync17(source, "utf-8");
|
|
48056
48416
|
try {
|
|
48057
48417
|
JSON.parse(raw);
|
|
48058
48418
|
} catch (err) {
|
|
@@ -48080,7 +48440,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
48080
48440
|
} catch (err) {
|
|
48081
48441
|
try {
|
|
48082
48442
|
const temp = tempTargetPath();
|
|
48083
|
-
if (
|
|
48443
|
+
if (existsSync36(temp)) unlinkSync8(temp);
|
|
48084
48444
|
} catch {
|
|
48085
48445
|
}
|
|
48086
48446
|
console.error(
|
|
@@ -48091,7 +48451,7 @@ function migrateGlobalConfigToConfigDir() {
|
|
|
48091
48451
|
}
|
|
48092
48452
|
function stampMarker(markerPath) {
|
|
48093
48453
|
try {
|
|
48094
|
-
mkdirSync11(
|
|
48454
|
+
mkdirSync11(join42(getCleoHome6(), MIGRATIONS_SUBDIR), { recursive: true });
|
|
48095
48455
|
writeFileSync11(markerPath, `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
48096
48456
|
`, { mode: 420 });
|
|
48097
48457
|
} catch {
|
|
@@ -48100,7 +48460,7 @@ function stampMarker(markerPath) {
|
|
|
48100
48460
|
function backupSourceQuiet(source) {
|
|
48101
48461
|
try {
|
|
48102
48462
|
const backup = `${source}${BACKUP_SUFFIX}`;
|
|
48103
|
-
if (
|
|
48463
|
+
if (existsSync36(backup)) return;
|
|
48104
48464
|
renameSync12(source, backup);
|
|
48105
48465
|
} catch {
|
|
48106
48466
|
}
|
|
@@ -48123,15 +48483,15 @@ var init_global_config_migration = __esm({
|
|
|
48123
48483
|
});
|
|
48124
48484
|
|
|
48125
48485
|
// packages/core/src/llm/legacy-flat-key-import.ts
|
|
48126
|
-
import { existsSync as
|
|
48127
|
-
import { join as
|
|
48486
|
+
import { existsSync as existsSync37, readFileSync as readFileSync18, renameSync as renameSync13, writeFileSync as writeFileSync12 } from "node:fs";
|
|
48487
|
+
import { join as join43 } from "node:path";
|
|
48128
48488
|
import { getCleoHome as getCleoHome7 } from "@cleocode/paths";
|
|
48129
48489
|
function migrationPaths() {
|
|
48130
48490
|
const home = getCleoHome7();
|
|
48131
48491
|
return {
|
|
48132
|
-
flatPath:
|
|
48133
|
-
bakPath:
|
|
48134
|
-
markerPath:
|
|
48492
|
+
flatPath: join43(home, "anthropic-key"),
|
|
48493
|
+
bakPath: join43(home, `anthropic-key${LEGACY_FLAT_KEY_BAK_SUFFIX}`),
|
|
48494
|
+
markerPath: join43(home, LEGACY_FLAT_KEY_MARKER)
|
|
48135
48495
|
};
|
|
48136
48496
|
}
|
|
48137
48497
|
function writeMarker(markerPath) {
|
|
@@ -48152,8 +48512,8 @@ function writeMarker(markerPath) {
|
|
|
48152
48512
|
}
|
|
48153
48513
|
function readFlatKey(flatPath) {
|
|
48154
48514
|
try {
|
|
48155
|
-
if (!
|
|
48156
|
-
const raw =
|
|
48515
|
+
if (!existsSync37(flatPath)) return null;
|
|
48516
|
+
const raw = readFileSync18(flatPath, "utf-8").trim();
|
|
48157
48517
|
return raw || null;
|
|
48158
48518
|
} catch (err) {
|
|
48159
48519
|
logger.warn(
|
|
@@ -48165,7 +48525,7 @@ function readFlatKey(flatPath) {
|
|
|
48165
48525
|
}
|
|
48166
48526
|
async function importLegacyFlatAnthropicKey() {
|
|
48167
48527
|
const { flatPath, bakPath, markerPath } = migrationPaths();
|
|
48168
|
-
if (
|
|
48528
|
+
if (existsSync37(markerPath)) {
|
|
48169
48529
|
return { status: "marker-present", flatPath, bakPath: null, markerPath };
|
|
48170
48530
|
}
|
|
48171
48531
|
let existing = null;
|
|
@@ -48182,7 +48542,7 @@ async function importLegacyFlatAnthropicKey() {
|
|
|
48182
48542
|
writeMarker(markerPath);
|
|
48183
48543
|
return { status: "already-imported", flatPath, bakPath: null, markerPath };
|
|
48184
48544
|
}
|
|
48185
|
-
if (!
|
|
48545
|
+
if (!existsSync37(flatPath)) {
|
|
48186
48546
|
writeMarker(markerPath);
|
|
48187
48547
|
return { status: "no-flat-file", flatPath, bakPath: null, markerPath };
|
|
48188
48548
|
}
|
|
@@ -48259,15 +48619,15 @@ __export(credentials_exports, {
|
|
|
48259
48619
|
resolveProviderStatus: () => resolveProviderStatus,
|
|
48260
48620
|
storeAnthropicApiKey: () => storeAnthropicApiKey
|
|
48261
48621
|
});
|
|
48262
|
-
import { existsSync as
|
|
48263
|
-
import { join as
|
|
48622
|
+
import { existsSync as existsSync38, mkdirSync as mkdirSync12, readFileSync as readFileSync19, writeFileSync as writeFileSync13 } from "node:fs";
|
|
48623
|
+
import { join as join44 } from "node:path";
|
|
48264
48624
|
import { getCleoHome as getCleoHome8 } from "@cleocode/paths";
|
|
48265
48625
|
function globalConfigPath() {
|
|
48266
48626
|
return configDirGlobalConfigPath();
|
|
48267
48627
|
}
|
|
48268
48628
|
function projectConfigPath(projectRoot) {
|
|
48269
48629
|
const cleoDir = process.env["CLEO_DIR"] ?? ".cleo";
|
|
48270
|
-
return
|
|
48630
|
+
return join44(projectRoot, cleoDir, "config.json");
|
|
48271
48631
|
}
|
|
48272
48632
|
function readGlobalProviderKey(provider) {
|
|
48273
48633
|
ensureGlobalConfigMigrated();
|
|
@@ -48277,9 +48637,9 @@ function readGlobalProviderKey(provider) {
|
|
|
48277
48637
|
}
|
|
48278
48638
|
function readFlatAnthropicKey() {
|
|
48279
48639
|
try {
|
|
48280
|
-
const keyFile =
|
|
48281
|
-
if (!
|
|
48282
|
-
const stored =
|
|
48640
|
+
const keyFile = join44(getCleoHome8(), "anthropic-key");
|
|
48641
|
+
if (!existsSync38(keyFile)) return null;
|
|
48642
|
+
const stored = readFileSync19(keyFile, "utf-8").trim();
|
|
48283
48643
|
return stored || null;
|
|
48284
48644
|
} catch {
|
|
48285
48645
|
return null;
|
|
@@ -48287,8 +48647,8 @@ function readFlatAnthropicKey() {
|
|
|
48287
48647
|
}
|
|
48288
48648
|
function readProviderKeyFromConfig(configFile, provider) {
|
|
48289
48649
|
try {
|
|
48290
|
-
if (!
|
|
48291
|
-
const raw =
|
|
48650
|
+
if (!existsSync38(configFile)) return null;
|
|
48651
|
+
const raw = readFileSync19(configFile, "utf-8");
|
|
48292
48652
|
const config2 = JSON.parse(raw);
|
|
48293
48653
|
const llm = config2["llm"];
|
|
48294
48654
|
if (!llm || typeof llm !== "object") return null;
|
|
@@ -48460,10 +48820,10 @@ function resolveProviderStatus(provider) {
|
|
|
48460
48820
|
}
|
|
48461
48821
|
function storeAnthropicApiKey(apiKey) {
|
|
48462
48822
|
const dir = getCleoHome8();
|
|
48463
|
-
if (!
|
|
48823
|
+
if (!existsSync38(dir)) {
|
|
48464
48824
|
mkdirSync12(dir, { recursive: true });
|
|
48465
48825
|
}
|
|
48466
|
-
const keyFile =
|
|
48826
|
+
const keyFile = join44(dir, "anthropic-key");
|
|
48467
48827
|
writeFileSync13(keyFile, apiKey.trim(), { mode: 384 });
|
|
48468
48828
|
}
|
|
48469
48829
|
function clearAnthropicKeyCache() {
|
|
@@ -48528,16 +48888,16 @@ __export(credentials_store_exports, {
|
|
|
48528
48888
|
pickCredentialForProviderSync: () => pickCredentialForProviderSync,
|
|
48529
48889
|
removeCredential: () => removeCredential
|
|
48530
48890
|
});
|
|
48531
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
48532
|
-
import { dirname as
|
|
48891
|
+
import { chmodSync as chmodSync2, existsSync as existsSync39, mkdirSync as mkdirSync13, readFileSync as readFileSync20, statSync as statSync10, writeFileSync as writeFileSync14 } from "node:fs";
|
|
48892
|
+
import { dirname as dirname21, join as join45 } from "node:path";
|
|
48533
48893
|
import { getCleoHome as getCleoHome9 } from "@cleocode/paths";
|
|
48534
48894
|
function credentialsStorePath() {
|
|
48535
|
-
return
|
|
48895
|
+
return join45(getCleoHome9(), "llm-credentials.json");
|
|
48536
48896
|
}
|
|
48537
48897
|
function ensureFileInitialized(path) {
|
|
48538
|
-
if (
|
|
48539
|
-
const dir =
|
|
48540
|
-
if (!
|
|
48898
|
+
if (existsSync39(path)) return;
|
|
48899
|
+
const dir = dirname21(path);
|
|
48900
|
+
if (!existsSync39(dir)) {
|
|
48541
48901
|
mkdirSync13(dir, { recursive: true, mode: 448 });
|
|
48542
48902
|
} else {
|
|
48543
48903
|
try {
|
|
@@ -48581,7 +48941,7 @@ function readStoreSync() {
|
|
|
48581
48941
|
const path = credentialsStorePath();
|
|
48582
48942
|
let raw;
|
|
48583
48943
|
try {
|
|
48584
|
-
raw =
|
|
48944
|
+
raw = readFileSync20(path, "utf-8");
|
|
48585
48945
|
} catch {
|
|
48586
48946
|
return emptyStore();
|
|
48587
48947
|
}
|
|
@@ -49170,13 +49530,13 @@ var init_xai = __esm({
|
|
|
49170
49530
|
|
|
49171
49531
|
// packages/core/src/llm/provider-registry/loader.ts
|
|
49172
49532
|
import { readdirSync as readdirSync9, statSync as statSync11 } from "node:fs";
|
|
49173
|
-
import { join as
|
|
49533
|
+
import { join as join46 } from "node:path";
|
|
49174
49534
|
import { pathToFileURL } from "node:url";
|
|
49175
49535
|
function isPluginFile(filename) {
|
|
49176
49536
|
return PLUGIN_EXTENSIONS.some((ext) => filename.endsWith(ext));
|
|
49177
49537
|
}
|
|
49178
49538
|
function getPluginDir() {
|
|
49179
|
-
return
|
|
49539
|
+
return join46(getCleoHome(), "plugins", "model-providers");
|
|
49180
49540
|
}
|
|
49181
49541
|
async function loadOnePlugin(absPath, api) {
|
|
49182
49542
|
let mod;
|
|
@@ -49224,13 +49584,13 @@ async function scanAndLoadPlugins(pluginDir, api) {
|
|
|
49224
49584
|
}
|
|
49225
49585
|
const pluginFiles = entries.filter((name15) => !name15.startsWith(".") && isPluginFile(name15)).filter((name15) => {
|
|
49226
49586
|
try {
|
|
49227
|
-
return statSync11(
|
|
49587
|
+
return statSync11(join46(pluginDir, name15)).isFile();
|
|
49228
49588
|
} catch {
|
|
49229
49589
|
return false;
|
|
49230
49590
|
}
|
|
49231
49591
|
}).sort();
|
|
49232
49592
|
for (const filename of pluginFiles) {
|
|
49233
|
-
await loadOnePlugin(
|
|
49593
|
+
await loadOnePlugin(join46(pluginDir, filename), api);
|
|
49234
49594
|
}
|
|
49235
49595
|
}
|
|
49236
49596
|
async function runDiscovery(registerProvider2, builtins) {
|
|
@@ -49333,15 +49693,15 @@ var init_provider_registry = __esm({
|
|
|
49333
49693
|
});
|
|
49334
49694
|
|
|
49335
49695
|
// packages/core/src/llm/rate-limit-guard.ts
|
|
49336
|
-
import { existsSync as
|
|
49337
|
-
import { join as
|
|
49696
|
+
import { existsSync as existsSync40, mkdirSync as mkdirSync14, unlinkSync as unlinkSync9 } from "node:fs";
|
|
49697
|
+
import { join as join47 } from "node:path";
|
|
49338
49698
|
import { getCleoHome as getCleoHome10 } from "@cleocode/paths";
|
|
49339
49699
|
function sanitize(value) {
|
|
49340
49700
|
return value.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
49341
49701
|
}
|
|
49342
49702
|
function rateLimitStatePath(provider, label) {
|
|
49343
|
-
const dir =
|
|
49344
|
-
return
|
|
49703
|
+
const dir = join47(getCleoHome10(), "rate-limit-state");
|
|
49704
|
+
return join47(dir, `${sanitize(provider)}-${sanitize(label)}.json`);
|
|
49345
49705
|
}
|
|
49346
49706
|
function parseResetFromHeaders(headers) {
|
|
49347
49707
|
const get = (k) => {
|
|
@@ -49388,8 +49748,8 @@ async function recordRateLimit(provider, label, opts) {
|
|
|
49388
49748
|
source = "default";
|
|
49389
49749
|
}
|
|
49390
49750
|
const filePath = rateLimitStatePath(provider, label);
|
|
49391
|
-
const dir =
|
|
49392
|
-
if (!
|
|
49751
|
+
const dir = join47(getCleoHome10(), "rate-limit-state");
|
|
49752
|
+
if (!existsSync40(dir)) {
|
|
49393
49753
|
mkdirSync14(dir, { recursive: true });
|
|
49394
49754
|
}
|
|
49395
49755
|
const state = { resetAt, recordedAt: now, source };
|
|
@@ -50290,31 +50650,31 @@ var init_error_classifier = __esm({
|
|
|
50290
50650
|
|
|
50291
50651
|
// packages/core/src/llm/catalog-cache.ts
|
|
50292
50652
|
import {
|
|
50293
|
-
existsSync as
|
|
50653
|
+
existsSync as existsSync41,
|
|
50294
50654
|
mkdirSync as mkdirSync15,
|
|
50295
50655
|
readdirSync as readdirSync10,
|
|
50296
|
-
readFileSync as
|
|
50656
|
+
readFileSync as readFileSync21,
|
|
50297
50657
|
statSync as statSync12,
|
|
50298
50658
|
symlinkSync,
|
|
50299
50659
|
unlinkSync as unlinkSync10,
|
|
50300
50660
|
writeFileSync as writeFileSync15
|
|
50301
50661
|
} from "node:fs";
|
|
50302
|
-
import { join as
|
|
50662
|
+
import { join as join48 } from "node:path";
|
|
50303
50663
|
import { getCleoHome as getCleoHome11 } from "@cleocode/paths";
|
|
50304
50664
|
function getCatalogDir() {
|
|
50305
50665
|
if (process.env["CLEO_DATA_DIR"]) {
|
|
50306
|
-
return
|
|
50666
|
+
return join48(process.env["CLEO_DATA_DIR"], "llm-catalog");
|
|
50307
50667
|
}
|
|
50308
|
-
return
|
|
50668
|
+
return join48(getCleoHome11(), "llm-catalog");
|
|
50309
50669
|
}
|
|
50310
50670
|
function findLatestCacheFile(dir) {
|
|
50311
|
-
if (!
|
|
50312
|
-
const files = readdirSync10(dir).filter((f) => f.endsWith("-models.json")).map((f) => ({ name: f, mtime: statSync12(
|
|
50313
|
-
return files.length > 0 ?
|
|
50671
|
+
if (!existsSync41(dir)) return null;
|
|
50672
|
+
const files = readdirSync10(dir).filter((f) => f.endsWith("-models.json")).map((f) => ({ name: f, mtime: statSync12(join48(dir, f)).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
|
|
50673
|
+
return files.length > 0 ? join48(dir, files[0].name) : null;
|
|
50314
50674
|
}
|
|
50315
50675
|
function readCacheFile(filePath) {
|
|
50316
50676
|
try {
|
|
50317
|
-
const raw =
|
|
50677
|
+
const raw = readFileSync21(filePath, "utf-8");
|
|
50318
50678
|
return JSON.parse(raw);
|
|
50319
50679
|
} catch {
|
|
50320
50680
|
return null;
|
|
@@ -50327,16 +50687,16 @@ var init_catalog_cache = __esm({
|
|
|
50327
50687
|
});
|
|
50328
50688
|
|
|
50329
50689
|
// packages/core/src/llm/model-metadata.ts
|
|
50330
|
-
import { readFileSync as
|
|
50331
|
-
import { dirname as
|
|
50332
|
-
import { fileURLToPath as
|
|
50690
|
+
import { readFileSync as readFileSync22 } from "node:fs";
|
|
50691
|
+
import { dirname as dirname22, join as join49 } from "node:path";
|
|
50692
|
+
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
50333
50693
|
function getCuratedTable() {
|
|
50334
50694
|
if (_curated !== void 0) {
|
|
50335
50695
|
return _curated;
|
|
50336
50696
|
}
|
|
50337
|
-
const thisDir =
|
|
50338
|
-
const jsonPath =
|
|
50339
|
-
const raw = JSON.parse(
|
|
50697
|
+
const thisDir = dirname22(fileURLToPath4(import.meta.url));
|
|
50698
|
+
const jsonPath = join49(thisDir, "curated-models.json");
|
|
50699
|
+
const raw = JSON.parse(readFileSync22(jsonPath, "utf-8"));
|
|
50340
50700
|
_curated = raw.models;
|
|
50341
50701
|
return _curated;
|
|
50342
50702
|
}
|
|
@@ -50421,7 +50781,7 @@ function storedToResolved(stored) {
|
|
|
50421
50781
|
};
|
|
50422
50782
|
}
|
|
50423
50783
|
function sleep3(ms) {
|
|
50424
|
-
return new Promise((
|
|
50784
|
+
return new Promise((resolve17) => setTimeout(resolve17, ms));
|
|
50425
50785
|
}
|
|
50426
50786
|
function backoffMs(policy, attempt) {
|
|
50427
50787
|
const base = policy.baseDelayMs * 2 ** attempt;
|
|
@@ -54363,7 +54723,7 @@ function normalizeOllamaToolCall(tc) {
|
|
|
54363
54723
|
};
|
|
54364
54724
|
}
|
|
54365
54725
|
function sleep4(ms) {
|
|
54366
|
-
return new Promise((
|
|
54726
|
+
return new Promise((resolve17) => setTimeout(resolve17, ms));
|
|
54367
54727
|
}
|
|
54368
54728
|
var OLLAMA_DEFAULT_BASE_URL, MAX_RETRIES, INITIAL_BACKOFF_MS, RETRYABLE_STATUS_CODES, OllamaTransport;
|
|
54369
54729
|
var init_ollama2 = __esm({
|
|
@@ -74877,7 +75237,7 @@ function createProviderToolFactoryWithOutputSchema({
|
|
|
74877
75237
|
supportsDeferredResults
|
|
74878
75238
|
});
|
|
74879
75239
|
}
|
|
74880
|
-
async function
|
|
75240
|
+
async function resolve16(value) {
|
|
74881
75241
|
if (typeof value === "function") {
|
|
74882
75242
|
value = value();
|
|
74883
75243
|
}
|
|
@@ -78911,14 +79271,14 @@ var init_dist4 = __esm({
|
|
|
78911
79271
|
headers
|
|
78912
79272
|
}) {
|
|
78913
79273
|
return combineHeaders(
|
|
78914
|
-
await
|
|
79274
|
+
await resolve16(this.config.headers),
|
|
78915
79275
|
headers,
|
|
78916
79276
|
betas.size > 0 ? { "anthropic-beta": Array.from(betas).join(",") } : {}
|
|
78917
79277
|
);
|
|
78918
79278
|
}
|
|
78919
79279
|
async getBetasFromHeaders(requestHeaders) {
|
|
78920
79280
|
var _a17, _b16;
|
|
78921
|
-
const configHeaders = await
|
|
79281
|
+
const configHeaders = await resolve16(this.config.headers);
|
|
78922
79282
|
const configBetaHeader = (_a17 = configHeaders["anthropic-beta"]) != null ? _a17 : "";
|
|
78923
79283
|
const requestBetaHeader = (_b16 = requestHeaders == null ? void 0 : requestHeaders["anthropic-beta"]) != null ? _b16 : "";
|
|
78924
79284
|
return new Set(
|