opencode-swarm 7.200.8 → 7.200.10

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 (113) hide show
  1. package/.opencode/skills/ci-fix-monitor/SKILL.md +49 -0
  2. package/.opencode/skills/swarm-pr-review/references/lane-output-recoverability.md +11 -2
  3. package/binaries/win32-arm64/swarm-sandbox-runner.exe +0 -0
  4. package/binaries/win32-x64/swarm-sandbox-runner.exe +0 -0
  5. package/dist/background/completion-observer.d.ts +2 -1
  6. package/dist/background/pending-delegations.d.ts +9 -1
  7. package/dist/background/pr-review-contract.d.ts +8 -0
  8. package/dist/cli/{attest-task-dxrfae0t.js → attest-task-yx2t832n.js} +78 -76
  9. package/dist/cli/{auto-checkpoint-6sacb90s.js → auto-checkpoint-15mvj9zm.js} +12 -12
  10. package/dist/cli/{capability-probe-dwqn2609.js → capability-probe-qjndmx6z.js} +1 -1
  11. package/dist/cli/{checkpoint-nwp1j6zv.js → checkpoint-65whgvwa.js} +23 -23
  12. package/dist/cli/{coder-settlement-gw7yz6j8.js → coder-settlement-sdg1he8p.js} +14 -13
  13. package/dist/cli/{config-doctor-9azv1kqx.js → config-doctor-4af2p2y4.js} +19 -19
  14. package/dist/cli/{core-0qgp0a8j.js → core-8swqc6kw.js} +6 -3
  15. package/dist/cli/{curation-policy-gy868ec3.js → curation-policy-1a23ftnv.js} +6 -6
  16. package/dist/cli/{curator-ekthxye6.js → curator-6ze04fz3.js} +53 -52
  17. package/dist/cli/{curator-drift-45snz8a6.js → curator-drift-ktf137da.js} +10 -10
  18. package/dist/cli/curator-llm-factory-7vq4rgg7.js +83 -0
  19. package/dist/cli/{doctor-knowledge-receipt-phase-id-fggff61y.js → doctor-knowledge-receipt-phase-id-0smwq3ar.js} +10 -10
  20. package/dist/cli/{evidence-summary-service-zc2fc8h1.js → evidence-summary-service-3bhq2gef.js} +26 -25
  21. package/dist/cli/{gate-evidence-r57ahtp0.js → gate-evidence-gcv0xgfc.js} +10 -9
  22. package/dist/cli/guardrail-explain-9t3mvm92.js +84 -0
  23. package/dist/cli/{guardrail-log-hskq7q1w.js → guardrail-log-ehgpan5n.js} +8 -8
  24. package/dist/cli/{guardrail-reset-ywcnk88z.js → guardrail-reset-q7m265wy.js} +53 -52
  25. package/dist/cli/{hive-promoter-k66hgffk.js → hive-promoter-857ranjf.js} +53 -52
  26. package/dist/cli/{index-4krkevgc.js → index-001tkp0j.js} +1 -1
  27. package/dist/cli/{index-k5h4mmwd.js → index-06sj5bjh.js} +5 -5
  28. package/dist/cli/{index-sg2sd66b.js → index-2dey2mtg.js} +6 -6
  29. package/dist/cli/{index-6w1x38yd.js → index-3h5ztpn5.js} +2 -2
  30. package/dist/cli/{index-kzyw3315.js → index-43zgg04r.js} +5 -5
  31. package/dist/cli/{index-wfd267ma.js → index-4dvqvn4k.js} +12905 -12414
  32. package/dist/cli/{index-q7z2yws5.js → index-60m7qnds.js} +8 -8
  33. package/dist/cli/{index-m6632p7f.js → index-66b4f2qd.js} +18 -13
  34. package/dist/cli/{index-c2k7q723.js → index-6cppzd9c.js} +1 -1
  35. package/dist/cli/{index-zjjxe0q5.js → index-6e7jxxys.js} +15 -15
  36. package/dist/cli/{index-jrpfzv5r.js → index-6ehx0pj4.js} +15 -15
  37. package/dist/cli/{index-yyrnkc3a.js → index-6m551cng.js} +2 -2
  38. package/dist/cli/{index-wgwg2b4d.js → index-8c6zshfj.js} +1 -1
  39. package/dist/cli/{index-8srvdpw6.js → index-8xtdxy91.js} +2 -2
  40. package/dist/cli/{index-mn75z39t.js → index-9qy3tzt5.js} +1 -1
  41. package/dist/cli/{index-057y0sbg.js → index-bt3pxs7r.js} +6 -6
  42. package/dist/cli/{index-0tvkfdwp.js → index-c34tgnwm.js} +7 -7
  43. package/dist/cli/{index-y7c4hqcj.js → index-ck7jpn0y.js} +1 -1
  44. package/dist/cli/{index-p2dst45x.js → index-ckq78kq1.js} +1 -1
  45. package/dist/cli/{index-8mrentmw.js → index-dp6hy23p.js} +58 -53
  46. package/dist/cli/{index-4fkxdnc7.js → index-erp7fk72.js} +1 -1
  47. package/dist/cli/{index-16n2s0zf.js → index-ev46f132.js} +8 -8
  48. package/dist/cli/{index-h7t7hvq3.js → index-fbn2mv67.js} +6 -6
  49. package/dist/cli/{index-vpxdf79m.js → index-ffm3d4cn.js} +17 -17
  50. package/dist/cli/{index-kekvdqj6.js → index-gsnj3a0h.js} +4 -4
  51. package/dist/cli/{index-zvvavx1h.js → index-h9qhy8r6.js} +6 -6
  52. package/dist/cli/{index-tecp3a77.js → index-kd1n3ne2.js} +9 -9
  53. package/dist/cli/{index-2wryy5a7.js → index-kxxy7zq4.js} +18 -20
  54. package/dist/cli/{index-ez0smmcc.js → index-mamw83wm.js} +53 -52
  55. package/dist/cli/{index-4a3ey5g6.js → index-mx34b7bm.js} +58 -57
  56. package/dist/cli/{index-wkbdfy1g.js → index-nv8tx9v4.js} +4 -4
  57. package/dist/cli/{index-q8vfw61p.js → index-pjrx4jkq.js} +1 -1
  58. package/dist/cli/{index-mhd6kdzr.js → index-qyj4383m.js} +1 -1
  59. package/dist/cli/{index-x8cac18k.js → index-r3wyt8za.js} +611 -1376
  60. package/dist/cli/{index-2x015vjy.js → index-rck7v4r4.js} +1 -1
  61. package/dist/cli/{index-vtpt8yns.js → index-rjsqf4hv.js} +2 -2
  62. package/dist/cli/{index-z72545mf.js → index-rnm6c33a.js} +5 -5
  63. package/dist/cli/{index-bk8r4m9j.js → index-rpvp88js.js} +2 -2
  64. package/dist/cli/{index-v839c9mv.js → index-tggyracy.js} +1 -1
  65. package/dist/cli/{index-5z4c9acx.js → index-tm6nwe43.js} +29 -29
  66. package/dist/cli/{index-c5wk61ak.js → index-vajbtn3v.js} +11 -11
  67. package/dist/cli/{index-4y90ecpz.js → index-vm3j8fvn.js} +201 -33
  68. package/dist/cli/{index-z1e9b5qk.js → index-vqknke9n.js} +121 -40
  69. package/dist/cli/{index-4ph7ad0b.js → index-vx1j2t5p.js} +2 -2
  70. package/dist/cli/{index-7h22y3ew.js → index-w0afnznk.js} +2 -2
  71. package/dist/cli/{index-76xnddca.js → index-ww5ne0g6.js} +7 -7
  72. package/dist/cli/index-xkavxqf2.js +1330 -0
  73. package/dist/cli/{index-tfaf8zy8.js → index-ywwazz81.js} +8 -8
  74. package/dist/cli/{index-21nbxx1t.js → index-zmp1k0mb.js} +2 -2
  75. package/dist/cli/index.js +57 -56
  76. package/dist/cli/{knowledge-escalator-9tz25k7f.js → knowledge-escalator-6p7m6gkc.js} +18 -18
  77. package/dist/cli/{knowledge-events-dcmpbb23.js → knowledge-events-w3ep12sq.js} +15 -15
  78. package/dist/cli/{knowledge-link-13t3nfrz.js → knowledge-link-r7e2t5c1.js} +5 -5
  79. package/dist/cli/{knowledge-store-dxwsme9q.js → knowledge-store-g4cpw0hz.js} +7 -7
  80. package/dist/cli/{knowledge-validator-7q1w62s7.js → knowledge-validator-zhy6mgxv.js} +9 -9
  81. package/dist/cli/{mcp-k38cfqtg.js → mcp-j1dy60mx.js} +1 -1
  82. package/dist/cli/{model-preflight-1tkjtc9z.js → model-preflight-962y2z1d.js} +56 -55
  83. package/dist/cli/{pending-delegations-q1fksmee.js → pending-delegations-erjwa1y6.js} +14 -14
  84. package/dist/cli/{pr-subscriptions-pf6mwhwr.js → pr-subscriptions-7fcawjg9.js} +13 -13
  85. package/dist/cli/{pr-workflow-gate-thazeaa1.js → pr-workflow-gate-j8ee9c6g.js} +53 -52
  86. package/dist/cli/{runner-q1g9atrv.js → runner-s4422dq4.js} +6 -6
  87. package/dist/cli/{scan-cursor-8k8rkrcj.js → scan-cursor-msz8j44s.js} +8 -8
  88. package/dist/cli/{schema-ff9v839b.js → schema-kep9t01t.js} +2 -2
  89. package/dist/cli/{scope-persistence-mzyqtkwv.js → scope-persistence-tx71g0ac.js} +18 -18
  90. package/dist/cli/{server-ss4jqd5y.js → server-6enk6sfw.js} +70 -69
  91. package/dist/cli/{skill-generator-fgk15dd5.js → skill-generator-p9fkx1g3.js} +20 -20
  92. package/dist/cli/{snapshot-coordination-init-e9gvsaj7.js → snapshot-coordination-init-kgftbdmq.js} +53 -52
  93. package/dist/cli/{speckit-checkoff-ec4g0hhc.js → speckit-checkoff-jfdwsy5n.js} +5 -5
  94. package/dist/cli/{telemetry-cr8q16wk.js → telemetry-j7zr1dht.js} +1 -1
  95. package/dist/cli/workflow-wal-file-xvvwcxr1.js +32 -0
  96. package/dist/cli/{workspace-snapshot-7hws89e9.js → workspace-snapshot-ksdspd74.js} +3 -3
  97. package/dist/cli/{worktree-collision-ownership-egc9b97v.js → worktree-collision-ownership-hac3t2xv.js} +15 -15
  98. package/dist/cli/{worktree-isolation-9evd232c.js → worktree-isolation-tjvxcsr9.js} +53 -52
  99. package/dist/hooks/delegation-gate/worktree-isolation.d.ts +3 -0
  100. package/dist/hooks/shell-write-detect.d.ts +10 -0
  101. package/dist/index.js +686 -684
  102. package/dist/memory/redaction.d.ts +13 -3
  103. package/dist/pr-review/legacy-transcript-adapter.d.ts +15 -4
  104. package/dist/sandbox/macos/sandbox-exec-executor.d.ts +24 -0
  105. package/dist/workflow/coder-settlement.d.ts +5 -0
  106. package/dist/worktree/core.d.ts +3 -0
  107. package/dist/worktree/merge.d.ts +15 -1
  108. package/dist/worktree/ownership.d.ts +3 -0
  109. package/dist/worktree/settlement-artifact-lifecycle.d.ts +32 -0
  110. package/dist/worktree/settlement-source-recovery.d.ts +12 -0
  111. package/package.json +1 -1
  112. package/dist/cli/curator-llm-factory-ds4y7k0b.js +0 -82
  113. package/dist/cli/guardrail-explain-bc8garre.js +0 -83
@@ -4,7 +4,7 @@ import {
4
4
  getProjectDb,
5
5
  projectDbExists,
6
6
  withImmediateTransaction
7
- } from "./index-y7c4hqcj.js";
7
+ } from "./index-ck7jpn0y.js";
8
8
 
9
9
  // src/db/coordination-store.ts
10
10
  import { createHash } from "crypto";
@@ -1,10 +1,10 @@
1
1
  // @bun
2
2
  import {
3
3
  observeStoreHealth
4
- } from "./index-8srvdpw6.js";
4
+ } from "./index-8xtdxy91.js";
5
5
  import {
6
6
  telemetry
7
- } from "./index-c2k7q723.js";
7
+ } from "./index-6cppzd9c.js";
8
8
  import {
9
9
  init_logger,
10
10
  warn
@@ -1,10 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  readEffectiveSpecSync
4
- } from "./index-sg2sd66b.js";
5
- import {
6
- readSwarmFileAsync
7
- } from "./index-4krkevgc.js";
4
+ } from "./index-2dey2mtg.js";
8
5
  import {
9
6
  DURABILITY_CLASSES,
10
7
  DbWriteError,
@@ -13,7 +10,10 @@ import {
13
10
  classifyDbWriteError,
14
11
  getProjectDb,
15
12
  projectDbExists
16
- } from "./index-y7c4hqcj.js";
13
+ } from "./index-ck7jpn0y.js";
14
+ import {
15
+ readSwarmFileAsync
16
+ } from "./index-001tkp0j.js";
17
17
  import {
18
18
  _internals,
19
19
  canonicalRootKeyFresh
@@ -1,14 +1,14 @@
1
1
  // @bun
2
2
  import {
3
3
  validateSwarmPath
4
- } from "./index-4krkevgc.js";
4
+ } from "./index-001tkp0j.js";
5
5
  import {
6
6
  canonicalRootKey,
7
7
  sameProjectRoot
8
8
  } from "./index-te9hq2f4.js";
9
9
  import {
10
10
  atomicWriteSwarmFile
11
- } from "./index-mn75z39t.js";
11
+ } from "./index-9qy3tzt5.js";
12
12
  import {
13
13
  init_git_executable,
14
14
  resolveGitExecutable
@@ -4,7 +4,7 @@ import {
4
4
  getProjectDb,
5
5
  projectDbExists,
6
6
  withImmediateTransaction
7
- } from "./index-y7c4hqcj.js";
7
+ } from "./index-ck7jpn0y.js";
8
8
  import {
9
9
  derivePlanId,
10
10
  derivePlanIdentityHash
@@ -4,7 +4,7 @@ import {
4
4
  } from "./index-6b295cas.js";
5
5
  import {
6
6
  readEffectiveSpecSync
7
- } from "./index-sg2sd66b.js";
7
+ } from "./index-2dey2mtg.js";
8
8
  import {
9
9
  _internals,
10
10
  clearWorktreeMergeStatus,
@@ -12,15 +12,6 @@ import {
12
12
  initDurableStatusPath,
13
13
  scanWorktreeMergeFailuresForRecovery
14
14
  } from "./index-697mg68b.js";
15
- import {
16
- sanitizeContextText
17
- } from "./index-m9zzj4ee.js";
18
- import {
19
- estimateCharsForTokens,
20
- estimateTokens,
21
- readSwarmFileAsync,
22
- validateSwarmPath
23
- } from "./index-4krkevgc.js";
24
15
  import {
25
16
  LedgerStaleWriterError,
26
17
  appendLedgerEvent,
@@ -39,7 +30,7 @@ import {
39
30
  replayFromLedgerWithStatus,
40
31
  takeSnapshotEvent,
41
32
  takeSnapshotWithRetry
42
- } from "./index-zjjxe0q5.js";
33
+ } from "./index-6e7jxxys.js";
43
34
  import {
44
35
  deleteCoordinationStateWithinTransaction,
45
36
  getCoordinationStateRaw,
@@ -48,26 +39,46 @@ import {
48
39
  transitionCoordinationState,
49
40
  transitionCoordinationStateWithinTransaction,
50
41
  withCoordinationTransaction
51
- } from "./index-2x015vjy.js";
42
+ } from "./index-rck7v4r4.js";
52
43
  import {
53
44
  DURABILITY_CLASSES,
54
45
  getProjectDb,
55
46
  projectDbExists,
56
47
  withDurabilityClass
57
- } from "./index-y7c4hqcj.js";
48
+ } from "./index-ck7jpn0y.js";
58
49
  import {
59
50
  appendCoreEventSync
60
- } from "./index-vtpt8yns.js";
51
+ } from "./index-rjsqf4hv.js";
61
52
  import {
62
53
  derivePlanId,
63
54
  derivePlanIdentityHash
64
55
  } from "./index-7pmbnjvj.js";
56
+ import {
57
+ sanitizeContextText
58
+ } from "./index-m9zzj4ee.js";
59
+ import {
60
+ PlanSchema,
61
+ normalizeCurrentPhaseInPlace,
62
+ resolveActivePhaseId
63
+ } from "./index-3t46mez1.js";
64
+ import {
65
+ init_config,
66
+ init_loader,
67
+ isEpicModeConfigEnabled,
68
+ loadPluginConfigWithMeta
69
+ } from "./index-ww5ne0g6.js";
70
+ import {
71
+ estimateCharsForTokens,
72
+ estimateTokens,
73
+ readSwarmFileAsync,
74
+ validateSwarmPath
75
+ } from "./index-001tkp0j.js";
65
76
  import {
66
77
  assertProjectRoot
67
78
  } from "./index-t7hmqgjy.js";
68
79
  import {
69
80
  emit
70
- } from "./index-c2k7q723.js";
81
+ } from "./index-6cppzd9c.js";
71
82
  import {
72
83
  canonicalRootKeyFresh
73
84
  } from "./index-te9hq2f4.js";
@@ -78,18 +89,7 @@ import {
78
89
  atomicWriteSwarmFileSync,
79
90
  invalidateCachedArtifact,
80
91
  readCachedParsedFile
81
- } from "./index-mn75z39t.js";
82
- import {
83
- PlanSchema,
84
- normalizeCurrentPhaseInPlace,
85
- resolveActivePhaseId
86
- } from "./index-3t46mez1.js";
87
- import {
88
- init_config,
89
- init_loader,
90
- isEpicModeConfigEnabled,
91
- loadPluginConfigWithMeta
92
- } from "./index-76xnddca.js";
92
+ } from "./index-9qy3tzt5.js";
93
93
  import {
94
94
  bunHash,
95
95
  bunWrite,
@@ -2670,7 +2670,7 @@ ${markdown}`;
2670
2670
  }
2671
2671
  }
2672
2672
  async function defaultMaybeSaveAutoCheckpoint(directory, plan) {
2673
- const { maybeSaveAutoCheckpoint } = await import("./auto-checkpoint-6sacb90s.js");
2673
+ const { maybeSaveAutoCheckpoint } = await import("./auto-checkpoint-15mvj9zm.js");
2674
2674
  return maybeSaveAutoCheckpoint(directory, plan);
2675
2675
  }
2676
2676
  async function updateTaskStatus(directory, taskId, status, options) {
@@ -2746,7 +2746,7 @@ async function updateTaskStatus(directory, taskId, status, options) {
2746
2746
  if (status === "completed") {
2747
2747
  try {
2748
2748
  const completedTask = updatedPlan.phases.flatMap((phase) => phase.tasks).find((candidate) => candidate.id === taskId);
2749
- const { maybePropagateSpeckitCheckoff } = await import("./speckit-checkoff-ec4g0hhc.js");
2749
+ const { maybePropagateSpeckitCheckoff } = await import("./speckit-checkoff-jfdwsy5n.js");
2750
2750
  await maybePropagateSpeckitCheckoff(directory, {
2751
2751
  taskId,
2752
2752
  frRefs: completedTask?.fr_refs ?? [],
@@ -11,24 +11,24 @@ import {
11
11
  } from "./index-ae75rja9.js";
12
12
  import {
13
13
  resolveKnowledgeStoreDir
14
- } from "./index-4fkxdnc7.js";
14
+ } from "./index-erp7fk72.js";
15
+ import {
16
+ init_knowledge_types,
17
+ isActiveStatus
18
+ } from "./index-bk5tah7q.js";
15
19
  import {
16
20
  atomicWriteFile
17
- } from "./index-yyrnkc3a.js";
21
+ } from "./index-6m551cng.js";
18
22
  import {
19
23
  require_proper_lockfile
20
24
  } from "./index-7g4c7s5r.js";
21
25
  import {
22
26
  readCachedParsedFile
23
- } from "./index-mn75z39t.js";
27
+ } from "./index-9qy3tzt5.js";
24
28
  import {
25
29
  init_logger,
26
30
  log
27
31
  } from "./index-zgwm4ryv.js";
28
- import {
29
- init_knowledge_types,
30
- isActiveStatus
31
- } from "./index-bk5tah7q.js";
32
32
  import {
33
33
  __require,
34
34
  __toESM
@@ -739,7 +739,7 @@ async function applyConfidenceFloorAction(directory, touched, options) {
739
739
  const {
740
740
  readAuthoritativeKnowledgeCounterRollups,
741
741
  effectiveRetrievalOutcomes
742
- } = await import("./knowledge-events-dcmpbb23.js");
742
+ } = await import("./knowledge-events-w3ep12sq.js");
743
743
  const rollups = await readAuthoritativeKnowledgeCounterRollups(directory);
744
744
  const flagIds = new Set;
745
745
  for (const e of atFloor) {
@@ -806,11 +806,11 @@ async function applyConfidenceFloorAction(directory, touched, options) {
806
806
  });
807
807
  }
808
808
  if (action === "quarantine" && toQuarantine.length > 0) {
809
- const { quarantineEntry } = await import("./knowledge-validator-7q1w62s7.js");
810
- const { KnowledgeConfigSchema } = await import("./schema-ff9v839b.js");
809
+ const { quarantineEntry } = await import("./knowledge-validator-zhy6mgxv.js");
810
+ const { KnowledgeConfigSchema } = await import("./schema-kep9t01t.js");
811
811
  let config;
812
812
  try {
813
- const { loadPluginConfigWithMeta } = await import("./index-0tvkfdwp.js");
813
+ const { loadPluginConfigWithMeta } = await import("./index-c34tgnwm.js");
814
814
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
815
815
  config = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
816
816
  } catch {
@@ -1,13 +1,19 @@
1
1
  // @bun
2
2
  import {
3
3
  validateSwarmPath
4
- } from "./index-4krkevgc.js";
4
+ } from "./index-001tkp0j.js";
5
+ import {
6
+ assertProjectRoot
7
+ } from "./index-t7hmqgjy.js";
5
8
  import {
6
9
  canonicalRootKeyFresh
7
10
  } from "./index-te9hq2f4.js";
11
+ import {
12
+ tryAcquireLock
13
+ } from "./index-ejhxgyvm.js";
8
14
  import {
9
15
  atomicWriteSwarmFileSync
10
- } from "./index-mn75z39t.js";
16
+ } from "./index-9qy3tzt5.js";
11
17
  import {
12
18
  advisoryWarn,
13
19
  init_git_executable,
@@ -35,7 +41,7 @@ init_constants();
35
41
  import * as fs2 from "fs";
36
42
  import * as fsPromises from "fs/promises";
37
43
  import * as os from "os";
38
- import * as path from "path";
44
+ import * as path2 from "path";
39
45
 
40
46
  // src/config/swarm-branch.ts
41
47
  init_constants();
@@ -222,12 +228,160 @@ function listLiveLaneOwners(directory) {
222
228
  init_warning_buffer();
223
229
  init_bun_compat();
224
230
  init_git_executable();
231
+
232
+ // src/worktree/settlement-artifact-lifecycle.ts
233
+ import { lstat, opendir, realpath } from "fs/promises";
234
+ import * as path from "path";
235
+ init_warning_buffer();
236
+ var MAX_INVENTORY_ENTRIES = 200;
237
+ var LIFECYCLE_TARGET = "locks/coder-settlement-artifacts";
238
+
239
+ class SettlementArtifactLifecycleError extends Error {
240
+ code;
241
+ constructor(code, detail) {
242
+ super(`${code}: ${detail}`);
243
+ this.code = code;
244
+ this.name = "SettlementArtifactLifecycleError";
245
+ }
246
+ }
247
+ function isSettlementArtifactLifecycleError(error) {
248
+ return error instanceof SettlementArtifactLifecycleError;
249
+ }
250
+ async function readWal(filePath, taskId) {
251
+ const { readWorkflowWalFile } = await import("./workflow-wal-file-xvvwcxr1.js");
252
+ return readWorkflowWalFile("coder-settlement", filePath, taskId);
253
+ }
254
+ async function canonicalizeArtifact(filePath) {
255
+ if (!path.isAbsolute(filePath))
256
+ throw uncertain("artifact path is not absolute");
257
+ let candidate = path.resolve(filePath);
258
+ const missing = [];
259
+ for (let depth = 0;depth < 256; depth++) {
260
+ try {
261
+ const physical = await _internals2.realpath(candidate);
262
+ const resolved = path.join(physical, ...missing.reverse());
263
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
264
+ } catch (error) {
265
+ if (error.code !== "ENOENT" && error.code !== "ENOTDIR")
266
+ throw error;
267
+ const parent = path.dirname(candidate);
268
+ if (parent === candidate)
269
+ throw error;
270
+ missing.push(path.basename(candidate));
271
+ candidate = parent;
272
+ }
273
+ }
274
+ throw uncertain("artifact ancestry exceeds the identity bound");
275
+ }
225
276
  var _internals2 = {
277
+ tryAcquireLock,
278
+ opendir,
279
+ lstat,
280
+ realpath,
281
+ readWal,
282
+ canonicalize: canonicalizeArtifact,
283
+ assertProjectRoot
284
+ };
285
+ function uncertain(detail) {
286
+ return new SettlementArtifactLifecycleError("CODER_SETTLEMENT_ARTIFACT_UNCERTAIN", detail);
287
+ }
288
+ async function withSettlementArtifactLifecycle(directory, operation) {
289
+ let root;
290
+ let admission;
291
+ try {
292
+ _internals2.assertProjectRoot(directory);
293
+ root = await _internals2.realpath(directory);
294
+ validateSwarmPath(root, LIFECYCLE_TARGET);
295
+ admission = await _internals2.tryAcquireLock(root, LIFECYCLE_TARGET, "coder-settlement-artifact-lifecycle", "coder-settlement-artifact-lifecycle");
296
+ } catch (error) {
297
+ throw uncertain(`cannot acquire lifecycle admission (${error instanceof Error ? error.message : String(error)})`);
298
+ }
299
+ if (!admission.acquired)
300
+ throw uncertain("lifecycle admission is busy: a concurrent removal or dispatch holds the lifecycle lock; retry once it completes");
301
+ try {
302
+ return await operation();
303
+ } finally {
304
+ try {
305
+ await admission.lock._release?.();
306
+ } catch (error) {
307
+ advisoryWarn(`[worktree] settlement artifact lifecycle lock release failed (${error instanceof Error ? error.message : String(error)})`);
308
+ }
309
+ }
310
+ }
311
+ async function matchesPendingWal(wal, target, targetPath) {
312
+ if (wal.state !== "DISPATCHED" && wal.state !== "PREPARED")
313
+ return false;
314
+ if (target.branch && (wal.worktree?.branchName === target.branch || wal.mergeProvenance?.branchName === target.branch))
315
+ return true;
316
+ return Boolean(targetPath && wal.worktree && await _internals2.canonicalize(wal.worktree.worktreePath) === targetPath);
317
+ }
318
+ async function assertSettlementArtifactsRemovable(directory, target) {
319
+ if (!target.path && !target.branch)
320
+ throw uncertain("missing artifact identity");
321
+ let handle;
322
+ let failure;
323
+ try {
324
+ const inventoryPath = validateSwarmPath(directory, "coder-settlements");
325
+ try {
326
+ const stat = await _internals2.lstat(inventoryPath);
327
+ if (stat.isSymbolicLink() || !stat.isDirectory())
328
+ throw uncertain("settlement inventory is not a direct directory");
329
+ } catch (error) {
330
+ if (error.code === "ENOENT")
331
+ return;
332
+ throw error;
333
+ }
334
+ const targetPath = target.path ? await _internals2.canonicalize(target.path) : undefined;
335
+ handle = await _internals2.opendir(inventoryPath);
336
+ let count = 0;
337
+ while (true) {
338
+ const entry = await handle.read();
339
+ if (!entry)
340
+ break;
341
+ if (entry.isSymbolicLink())
342
+ throw uncertain("settlement inventory contains a symbolic entry");
343
+ if (!entry.name.endsWith(".json"))
344
+ continue;
345
+ if (++count > MAX_INVENTORY_ENTRIES)
346
+ throw uncertain(`settlement inventory exceeds ${MAX_INVENTORY_ENTRIES} records; run \`/swarm close\` to archive settled coder settlements`);
347
+ const filePath = path.join(inventoryPath, entry.name);
348
+ const stat = await _internals2.lstat(filePath);
349
+ if (!stat.isFile() || stat.isSymbolicLink())
350
+ throw uncertain("settlement record is not a direct regular file");
351
+ const wal = await _internals2.readWal(filePath, entry.name.slice(0, -5));
352
+ if (!wal)
353
+ throw uncertain("settlement record disappeared during inventory");
354
+ const after = await _internals2.lstat(filePath);
355
+ if (after.dev !== stat.dev || after.ino !== stat.ino || after.size !== stat.size || after.mtimeMs !== stat.mtimeMs)
356
+ throw uncertain("settlement record changed during inspection");
357
+ if (await matchesPendingWal(wal, target, targetPath)) {
358
+ throw new SettlementArtifactLifecycleError("CODER_SETTLEMENT_ARTIFACT_PROTECTED", `task ${wal.taskId} has a ${wal.state} settlement; preserve its lane artifacts`);
359
+ }
360
+ }
361
+ } catch (error) {
362
+ failure = isSettlementArtifactLifecycleError(error) ? error : uncertain(`cannot verify settlement inventory (${error instanceof Error ? error.message : String(error)})`);
363
+ } finally {
364
+ if (handle) {
365
+ try {
366
+ await handle.close();
367
+ } catch {
368
+ failure ??= uncertain("cannot close settlement inventory");
369
+ }
370
+ }
371
+ }
372
+ if (failure)
373
+ throw failure;
374
+ }
375
+
376
+ // src/worktree/core.ts
377
+ var _internals3 = {
378
+ withSettlementArtifactLifecycle,
379
+ assertSettlementArtifactsRemovable,
226
380
  clearLiveLaneOwner,
227
381
  bunSpawn,
228
382
  resolveGitExecutable,
229
383
  platform: process.platform,
230
- sleep: (ms) => new Promise((resolve2) => setTimeout(resolve2, ms)),
384
+ sleep: (ms) => new Promise((resolve3) => setTimeout(resolve3, ms)),
231
385
  osTmpdir: () => os.tmpdir(),
232
386
  getCoreLongPaths: async (directory) => {
233
387
  const result = await runGit(["config", "core.longpaths"], directory);
@@ -244,7 +398,7 @@ var _internals2 = {
244
398
  symlinkSync: fs2.symlinkSync
245
399
  },
246
400
  writeScopeToDisk: async (directory, taskId, files) => {
247
- const { writeScopeToDisk: realWrite } = await import("./scope-persistence-mzyqtkwv.js");
401
+ const { writeScopeToDisk: realWrite } = await import("./scope-persistence-tx71g0ac.js");
248
402
  return realWrite(directory, taskId, files);
249
403
  },
250
404
  writeLaneProfileToDisk: async (_worktreePath, _laneIndex, _envOverrides) => {
@@ -273,15 +427,15 @@ async function writeLaneProfileToDiskReal(worktreePath, laneIndex, envOverrides)
273
427
  }
274
428
  if (lines.length === 0)
275
429
  return;
276
- const lanesDir = path.join(worktreePath, ".swarm", "lanes");
430
+ const lanesDir = path2.join(worktreePath, ".swarm", "lanes");
277
431
  await fs2.promises.mkdir(lanesDir, { recursive: true });
278
- const envPath = path.join(lanesDir, `${laneIndex}.env`);
432
+ const envPath = path2.join(lanesDir, `${laneIndex}.env`);
279
433
  await fs2.promises.writeFile(envPath, `${lines.join(`
280
434
  `)}
281
435
  `, "utf-8");
282
436
  }
283
437
  async function removeLaneProfileFromDiskReal(worktreePath, laneIndex) {
284
- const envPath = path.join(worktreePath, ".swarm", "lanes", `${laneIndex}.env`);
438
+ const envPath = path2.join(worktreePath, ".swarm", "lanes", `${laneIndex}.env`);
285
439
  try {
286
440
  await fs2.promises.unlink(envPath);
287
441
  } catch (err) {
@@ -297,7 +451,7 @@ var GIT_SPAWN_FAILURE_EXIT_CODE = 1;
297
451
  async function runGit(args, cwd, timeoutMs = WORKTREE_TIMEOUT_MS) {
298
452
  let proc;
299
453
  try {
300
- proc = _internals2.bunSpawn([_internals2.resolveGitExecutable(), ...args], {
454
+ proc = _internals3.bunSpawn([_internals3.resolveGitExecutable(), ...args], {
301
455
  cwd,
302
456
  timeout: timeoutMs,
303
457
  stdin: "ignore",
@@ -330,19 +484,19 @@ async function runGit(args, cwd, timeoutMs = WORKTREE_TIMEOUT_MS) {
330
484
  }
331
485
  }
332
486
  async function checkPathBudget(worktreeRoot, directory) {
333
- if (_internals2.platform !== "win32") {
487
+ if (_internals3.platform !== "win32") {
334
488
  return { ok: true };
335
489
  }
336
490
  let longPaths;
337
491
  try {
338
- longPaths = await _internals2.getCoreLongPaths(directory);
492
+ longPaths = await _internals3.getCoreLongPaths(directory);
339
493
  } catch {}
340
494
  if (longPaths === "true") {
341
495
  return { ok: true };
342
496
  }
343
497
  let proc;
344
498
  try {
345
- proc = _internals2.bunSpawn([_internals2.resolveGitExecutable(), "ls-files"], {
499
+ proc = _internals3.bunSpawn([_internals3.resolveGitExecutable(), "ls-files"], {
346
500
  cwd: directory,
347
501
  timeout: WORKTREE_TIMEOUT_MS,
348
502
  stdin: "ignore",
@@ -384,23 +538,23 @@ async function checkPathBudget(worktreeRoot, directory) {
384
538
  }
385
539
  }
386
540
  function shortenWorktreePath(_directory, sessionId, laneId) {
387
- let tmp = _internals2.osTmpdir();
541
+ let tmp = _internals3.osTmpdir();
388
542
  try {
389
543
  tmp = fs2.realpathSync(tmp);
390
544
  } catch {}
391
- return path.join(tmp, "swwt", sessionId, laneId);
545
+ return path2.join(tmp, "swwt", sessionId, laneId);
392
546
  }
393
547
  function makeWorktreeBranchName(sessionId, id, options) {
394
548
  return buildSwarmBranchName(sessionId, id, options.purpose, options.branchStyle === "legacy-lane" && options.purpose === "lane");
395
549
  }
396
550
  function resolveWorktreeBaseDir(directory, worktreeDir) {
397
- return worktreeDir ? path.resolve(directory, worktreeDir) : path.resolve(directory, SWARM_WORKTREE_DIR_NAME);
551
+ return worktreeDir ? path2.resolve(directory, worktreeDir) : path2.resolve(directory, SWARM_WORKTREE_DIR_NAME);
398
552
  }
399
553
  function isPathUnderSwarmWorktreeBase(targetPath, directory, worktreeDirOverrides = []) {
400
554
  const caseInsensitive = process.platform === "win32";
401
555
  let realTarget;
402
556
  try {
403
- realTarget = fs2.realpathSync(path.resolve(directory, targetPath));
557
+ realTarget = fs2.realpathSync(path2.resolve(directory, targetPath));
404
558
  } catch {
405
559
  return false;
406
560
  }
@@ -414,13 +568,13 @@ function isPathUnderSwarmWorktreeBase(targetPath, directory, worktreeDirOverride
414
568
  try {
415
569
  realBase = fs2.realpathSync(base);
416
570
  } catch {
417
- realBase = path.resolve(base);
571
+ realBase = path2.resolve(base);
418
572
  }
419
573
  const cmpBase = caseInsensitive ? realBase.toLowerCase() : realBase;
420
574
  if (cmpTarget === cmpBase)
421
575
  return true;
422
- const rel = path.relative(cmpBase, cmpTarget);
423
- return rel.length > 0 && !rel.startsWith("..") && !path.isAbsolute(rel);
576
+ const rel = path2.relative(cmpBase, cmpTarget);
577
+ return rel.length > 0 && !rel.startsWith("..") && !path2.isAbsolute(rel);
424
578
  });
425
579
  }
426
580
  async function provisionWorktree(directory, id, sessionId, options) {
@@ -430,7 +584,7 @@ async function provisionWorktree(directory, id, sessionId, options) {
430
584
  error: `Refusing to provision worktree: branch "${branchName}" does not match the swarm lane grammar, so lane permission scoping could not recognise it and the lane would hang on the first external-directory prompt. This is almost always an invalid sessionId ("${sessionId}"); it must look like "ses_" followed by letters/digits, and the execution-unit id ("${id}") must be a single path segment.`
431
585
  };
432
586
  }
433
- let worktreePath = path.resolve(resolveWorktreeBaseDir(directory, options.worktreeDir), sessionId, id);
587
+ let worktreePath = path2.resolve(resolveWorktreeBaseDir(directory, options.worktreeDir), sessionId, id);
434
588
  const budgetResult = await checkPathBudget(worktreePath, directory);
435
589
  if (budgetResult.ok === false) {
436
590
  if (options.worktreeDir) {
@@ -575,18 +729,18 @@ async function provisionWorktree(directory, id, sessionId, options) {
575
729
  }
576
730
  const strategy = options.depsStrategy ?? "skip";
577
731
  if (strategy !== "skip") {
578
- const hostDepDir = path.join(directory, "node_modules");
579
- const laneDepDir = path.join(worktreePath, "node_modules");
580
- if (_internals2.fs.existsSync(hostDepDir)) {
732
+ const hostDepDir = path2.join(directory, "node_modules");
733
+ const laneDepDir = path2.join(worktreePath, "node_modules");
734
+ if (_internals3.fs.existsSync(hostDepDir)) {
581
735
  try {
582
736
  if (strategy === "copy") {
583
- await _internals2.fs.cp(hostDepDir, laneDepDir, {
737
+ await _internals3.fs.cp(hostDepDir, laneDepDir, {
584
738
  recursive: true,
585
739
  force: true
586
740
  });
587
741
  } else if (strategy === "link") {
588
- const isWindows = _internals2.platform === "win32";
589
- _internals2.fs.symlinkSync(hostDepDir, laneDepDir, isWindows ? "junction" : "dir");
742
+ const isWindows = _internals3.platform === "win32";
743
+ _internals3.fs.symlinkSync(hostDepDir, laneDepDir, isWindows ? "junction" : "dir");
590
744
  }
591
745
  } catch (e) {
592
746
  log(`[swarm] deps_strategy '${strategy}' preparation failed for ${id}: ${e instanceof Error ? e.message : String(e)}`);
@@ -599,12 +753,12 @@ async function provisionWorktree(directory, id, sessionId, options) {
599
753
  }
600
754
  if (options.scope?.taskId && Array.isArray(options.scope.files)) {
601
755
  try {
602
- await _internals2.writeScopeToDisk(worktreePath, options.scope.taskId, options.scope.files);
756
+ await _internals3.writeScopeToDisk(worktreePath, options.scope.taskId, options.scope.files);
603
757
  } catch {}
604
758
  }
605
759
  if (options.laneProfile) {
606
760
  try {
607
- await _internals2.writeLaneProfileToDisk(worktreePath, options.laneProfile.laneIndex, options.laneProfile.envOverrides);
761
+ await _internals3.writeLaneProfileToDisk(worktreePath, options.laneProfile.laneIndex, options.laneProfile.envOverrides);
608
762
  } catch {}
609
763
  }
610
764
  return {
@@ -616,14 +770,28 @@ async function provisionWorktree(directory, id, sessionId, options) {
616
770
  };
617
771
  }
618
772
  async function removeWorktree(worktreePath, projectRoot, options) {
619
- const isWindows = _internals2.platform === "win32";
773
+ try {
774
+ return await _internals3.withSettlementArtifactLifecycle(projectRoot, async () => {
775
+ await _internals3.assertSettlementArtifactsRemovable(projectRoot, {
776
+ path: worktreePath
777
+ });
778
+ return removeWorktreeUnderLifecycleLock(worktreePath, projectRoot, options);
779
+ });
780
+ } catch (error) {
781
+ return {
782
+ error: `CODER_SETTLEMENT_ARTIFACT_REMOVAL_REFUSED: ${error instanceof Error ? error.message : String(error)}`
783
+ };
784
+ }
785
+ }
786
+ async function removeWorktreeUnderLifecycleLock(worktreePath, projectRoot, options) {
787
+ const isWindows = _internals3.platform === "win32";
620
788
  const MAX_RETRIES = 4;
621
789
  const RETRY_DELAY_MS = 2000;
622
790
  let lastError = "";
623
791
  for (let attempt = 0;attempt < MAX_RETRIES; attempt++) {
624
792
  const result = await runGit(["worktree", "remove", worktreePath], projectRoot);
625
793
  if (result.exitCode === 0) {
626
- _internals2.clearLiveLaneOwner(projectRoot, worktreePath);
794
+ _internals3.clearLiveLaneOwner(projectRoot, worktreePath);
627
795
  if (fs2.existsSync(worktreePath)) {
628
796
  const trusted = isPathUnderSwarmWorktreeBase(worktreePath, projectRoot, options?.worktreeDir ? [options.worktreeDir] : []);
629
797
  if (!trusted) {
@@ -648,13 +816,13 @@ async function removeWorktree(worktreePath, projectRoot, options) {
648
816
  }
649
817
  lastError = result.stderr.trim() || result.stdout.trim();
650
818
  if (isWindows && (lastError.includes("EBUSY") || lastError.includes("EPERM")) && attempt < MAX_RETRIES - 1) {
651
- await _internals2.sleep(RETRY_DELAY_MS);
819
+ await _internals3.sleep(RETRY_DELAY_MS);
652
820
  continue;
653
821
  }
654
822
  if (options?.force && isPathUnderSwarmWorktreeBase(worktreePath, projectRoot, options.worktreeDir ? [options.worktreeDir] : [])) {
655
823
  const forced = await runGit(["worktree", "remove", "--force", worktreePath], projectRoot);
656
824
  if (forced.exitCode === 0) {
657
- _internals2.clearLiveLaneOwner(projectRoot, worktreePath);
825
+ _internals3.clearLiveLaneOwner(projectRoot, worktreePath);
658
826
  if (fs2.existsSync(worktreePath)) {
659
827
  try {
660
828
  fs2.rmSync(worktreePath, { recursive: true, force: true });
@@ -788,4 +956,4 @@ async function assertCleanWorkingTree(directory) {
788
956
  return { clean: true };
789
957
  }
790
958
 
791
- export { recordLiveLaneOwner, listLiveLaneOwners, _internals2 as _internals, writeLaneProfileToDiskReal, removeLaneProfileFromDiskReal, checkPathBudget, shortenWorktreePath, makeWorktreeBranchName, resolveWorktreeBaseDir, isPathUnderSwarmWorktreeBase, provisionWorktree, removeWorktree, isCleanWorktree, autoCommitDirty, cleanUntrackedFiles, assertCleanWorkingTree };
959
+ export { recordLiveLaneOwner, listLiveLaneOwners, withSettlementArtifactLifecycle, assertSettlementArtifactsRemovable, _internals3 as _internals, writeLaneProfileToDiskReal, removeLaneProfileFromDiskReal, checkPathBudget, shortenWorktreePath, makeWorktreeBranchName, resolveWorktreeBaseDir, isPathUnderSwarmWorktreeBase, provisionWorktree, removeWorktree, isCleanWorktree, autoCommitDirty, cleanUntrackedFiles, assertCleanWorkingTree };