zelari-code 2.37.2 → 2.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cli/asyncLimit.js +53 -0
  2. package/dist/cli/asyncLimit.js.map +1 -0
  3. package/dist/cli/budget/restoreRuntime.js +10 -5
  4. package/dist/cli/budget/restoreRuntime.js.map +1 -1
  5. package/dist/cli/crossProviderFailover.js +32 -0
  6. package/dist/cli/crossProviderFailover.js.map +1 -1
  7. package/dist/cli/harnessState.js +7 -3
  8. package/dist/cli/harnessState.js.map +1 -1
  9. package/dist/cli/headless/liveTurnAbort.js +1 -1
  10. package/dist/cli/headless/liveTurnAbort.js.map +1 -1
  11. package/dist/cli/headless/runOneTurn.js +15 -5
  12. package/dist/cli/headless/runOneTurn.js.map +1 -1
  13. package/dist/cli/headlessSpine.js +7 -3
  14. package/dist/cli/headlessSpine.js.map +1 -1
  15. package/dist/cli/kraken/cachedShell.js +162 -0
  16. package/dist/cli/kraken/cachedShell.js.map +1 -0
  17. package/dist/cli/kraken/contractCompiler.js +6 -1
  18. package/dist/cli/kraken/contractCompiler.js.map +1 -1
  19. package/dist/cli/kraken/executor.js +27 -17
  20. package/dist/cli/kraken/executor.js.map +1 -1
  21. package/dist/cli/kraken/nativeVerification.js +9 -1
  22. package/dist/cli/kraken/nativeVerification.js.map +1 -1
  23. package/dist/cli/kraken/worktreeCleanupBatch.js +110 -0
  24. package/dist/cli/kraken/worktreeCleanupBatch.js.map +1 -0
  25. package/dist/cli/main.bundled.js +1323 -510
  26. package/dist/cli/main.bundled.js.map +4 -4
  27. package/dist/cli/memory/legacyImport.js +66 -14
  28. package/dist/cli/memory/legacyImport.js.map +1 -1
  29. package/dist/cli/memory/sqliteBackend.js +19 -5
  30. package/dist/cli/memory/sqliteBackend.js.map +1 -1
  31. package/dist/cli/providerFailover.js +21 -2
  32. package/dist/cli/providerFailover.js.map +1 -1
  33. package/dist/cli/runHeadless.js +32 -1
  34. package/dist/cli/runHeadless.js.map +1 -1
  35. package/dist/cli/serve/harnessServer.js +6 -2
  36. package/dist/cli/serve/harnessServer.js.map +1 -1
  37. package/dist/cli/serve/sessionControl.js.map +1 -1
  38. package/dist/cli/sessionSpine.js +26 -10
  39. package/dist/cli/sessionSpine.js.map +1 -1
  40. package/dist/cli/toolRegistry.js +23 -4
  41. package/dist/cli/toolRegistry.js.map +1 -1
  42. package/dist/cli/tools/krakenModel.js +72 -9
  43. package/dist/cli/tools/krakenModel.js.map +1 -1
  44. package/dist/cli/tools/krakenRadio.js +60 -3
  45. package/dist/cli/tools/krakenRadio.js.map +1 -1
  46. package/dist/cli/tools/krakenWorktree.js +105 -4
  47. package/dist/cli/tools/krakenWorktree.js.map +1 -1
  48. package/dist/cli/tools/taskTool.js +64 -40
  49. package/dist/cli/tools/taskTool.js.map +1 -1
  50. package/dist/cli/tools/tentacleHeartbeat.js +47 -0
  51. package/dist/cli/tools/tentacleHeartbeat.js.map +1 -0
  52. package/package.json +3 -2
@@ -0,0 +1,110 @@
1
+ /**
2
+ * worktreeCleanupBatch — Int3c (plan v2 §7.3) cleanup policy + queue.
3
+ *
4
+ * The per-worktree git calls live in `tools/krakenWorktree.ts`; this module
5
+ * owns only the POLICY (`batch` vs `eager`) and the in-process QUEUE of
6
+ * repo-level cleanup that a run defers. Split out because krakenWorktree.ts is
7
+ * already at its size budget and the state here is unrelated to worktree
8
+ * creation/merging.
9
+ *
10
+ * Why defer anything: removing a worktree used to cost three git processes —
11
+ * `worktree remove --force` (must stay eager: the directory has to be free
12
+ * before the next writer, and a merge node may run right after), then
13
+ * `worktree prune`, then `branch -D <branch>`. Prune and branch deletion are
14
+ * idempotent, order-independent and invisible to the run, so inside a run
15
+ * scope they are coalesced into ONE `prune` + ONE `branch -D <list>` at the
16
+ * end of the run.
17
+ *
18
+ * Scope, not "always": `cleanupKrakenWorktree` only defers while a scope is
19
+ * open (`beginKrakenWorktreeCleanupBatch`). Outside one, nothing would ever
20
+ * drain the queue — a standalone `task` call would silently keep its branches
21
+ * — so cleanup stays eager there. The flag's default is still `batch`: every
22
+ * run that opens a scope defers, `ZELARI_KRAKEN_WORKTREE_CLEANUP=eager` opts
23
+ * out for all callers.
24
+ *
25
+ * Pure state + policy: no fs, no git, no clock. The caller does the spawning.
26
+ *
27
+ * @since v2.38.0 (Int3c)
28
+ */
29
+ /**
30
+ * `ZELARI_KRAKEN_WORKTREE_CLEANUP`, default `batch` (plan v2 §13):
31
+ *
32
+ * `batch` — inside a run scope, coalesce `worktree prune` + `branch -D` into
33
+ * ONE pair at the end of the run.
34
+ * `eager` — kill-switch: per-worktree `prune` + `branch -D`, exactly as
35
+ * before Int3c.
36
+ *
37
+ * An unrecognized value falls back to the default rather than to `eager`: a
38
+ * typo must not silently re-enable the extra subprocesses the slice removed.
39
+ */
40
+ export function resolveWorktreeCleanupMode(env = process.env) {
41
+ const v = (env.ZELARI_KRAKEN_WORKTREE_CLEANUP ?? '').trim().toLowerCase();
42
+ if (v === 'eager')
43
+ return 'eager';
44
+ return 'batch';
45
+ }
46
+ /** repoRoot → the `worktree prune` it still owes (one per removed worktree). */
47
+ const pendingPruneRoots = new Set();
48
+ /** repoRoot → branches whose worktree is gone but whose branch is not. */
49
+ const pendingBranches = new Map();
50
+ /**
51
+ * Open run scopes. A counter (not a boolean) so two concurrent scopes — an
52
+ * executor run and, say, a nested one — cannot close each other's batch: each
53
+ * `begin` is matched by one `take`, and a take already drains the whole queue
54
+ * (deleting a queued branch earlier than "end of run" is only ever *more*
55
+ * eager, never wrong).
56
+ */
57
+ let batchScopes = 0;
58
+ /** True when `cleanupKrakenWorktree` should defer instead of cleaning eagerly. */
59
+ export function isKrakenWorktreeCleanupBatched(env = process.env) {
60
+ return batchScopes > 0 && resolveWorktreeCleanupMode(env) === 'batch';
61
+ }
62
+ /**
63
+ * Open the cleanup batch for a run. Returns whether deferral is active: false
64
+ * in `eager` mode (nothing is queued, so the caller has no flush to make).
65
+ */
66
+ export function beginKrakenWorktreeCleanupBatch(env = process.env) {
67
+ if (resolveWorktreeCleanupMode(env) !== 'batch')
68
+ return false;
69
+ batchScopes += 1;
70
+ return true;
71
+ }
72
+ /**
73
+ * Queue the repo-level half of one cleanup. Duplicates collapse: N worktrees
74
+ * of the same repo cost one prune, and a branch name is unique per worktree
75
+ * anyway (it embeds a timestamp + random id).
76
+ */
77
+ export function queueWorktreeCleanup(repoRoot, branch) {
78
+ pendingPruneRoots.add(repoRoot);
79
+ if (!branch)
80
+ return;
81
+ const queued = pendingBranches.get(repoRoot) ?? new Set();
82
+ queued.add(branch);
83
+ pendingBranches.set(repoRoot, queued);
84
+ }
85
+ /**
86
+ * Close one scope and drain the queue. Draining clears the state, so a second
87
+ * drain in the same process returns empty work — the caller can issue no git
88
+ * command for it (an idle flush costs zero spawns).
89
+ */
90
+ export function takeQueuedWorktreeCleanup() {
91
+ if (batchScopes > 0)
92
+ batchScopes -= 1;
93
+ const repoRoots = new Set([...pendingPruneRoots, ...pendingBranches.keys()]);
94
+ const branchesByRoot = new Map();
95
+ for (const repoRoot of repoRoots) {
96
+ const queued = pendingBranches.get(repoRoot);
97
+ if (queued && queued.size > 0)
98
+ branchesByRoot.set(repoRoot, [...queued]);
99
+ pendingPruneRoots.delete(repoRoot);
100
+ pendingBranches.delete(repoRoot);
101
+ }
102
+ return { repoRoots: [...repoRoots], branchesByRoot };
103
+ }
104
+ /** Test-only: drop the queue and any open scope. */
105
+ export function __resetKrakenWorktreeCleanupQueueForTests() {
106
+ pendingPruneRoots.clear();
107
+ pendingBranches.clear();
108
+ batchScopes = 0;
109
+ }
110
+ //# sourceMappingURL=worktreeCleanupBatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktreeCleanupBatch.js","sourceRoot":"","sources":["../../../src/cli/kraken/worktreeCleanupBatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAKH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA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