opencode-swarm 7.164.11 → 7.164.13

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 (127) hide show
  1. package/.opencode/skills/engineering-conventions/SKILL.md +1 -1
  2. package/.opencode/skills/loop/SKILL.md +1 -1
  3. package/.opencode/skills/{plan → swarm-plan}/SKILL.md +1 -1
  4. package/dist/background/pending-delegations.d.ts +7 -2
  5. package/dist/background/pr-subscriptions.d.ts +3 -3
  6. package/dist/cli/{coder-settlement-0rfk8y11.js → coder-settlement-em2fgg4p.js} +16 -17
  7. package/dist/cli/{config-doctor-j17b7qq2.js → config-doctor-1m4mrybp.js} +4 -4
  8. package/dist/cli/{core-evhjjrtt.js → core-zbzdffha.js} +3 -3
  9. package/dist/cli/{curation-policy-vj6z5hvr.js → curation-policy-bqpmry2n.js} +5 -6
  10. package/dist/cli/{curator-drift-ez81vg2t.js → curator-drift-hbc3w5zj.js} +14 -12
  11. package/dist/cli/curator-llm-factory-j76c96t7.js +70 -0
  12. package/dist/cli/{curator-vqd5yeck.js → curator-tn3x5j02.js} +49 -47
  13. package/dist/cli/{dispatch-dqybvj8v.js → dispatch-c7xjt7js.js} +3 -3
  14. package/dist/cli/{evidence-summary-service-937x7rbg.js → evidence-summary-service-7cn9z4sn.js} +25 -24
  15. package/dist/cli/{gate-evidence-q1cehr4k.js → gate-evidence-deyzt3hz.js} +10 -11
  16. package/dist/cli/guardrail-explain-4k2pqj46.js +71 -0
  17. package/dist/cli/{guardrail-log-3g93f3g2.js → guardrail-log-cnbv6vry.js} +11 -11
  18. package/dist/cli/{guardrail-reset-qe2r5qzq.js → guardrail-reset-xhh61cax.js} +49 -47
  19. package/dist/cli/hive-promoter-1m8zpz4d.js +85 -0
  20. package/dist/cli/{index-rhqdsc1x.js → index-0mwjamha.js} +9 -9
  21. package/dist/cli/{index-y1yqmkv7.js → index-3c0z1jnc.js} +56 -52
  22. package/dist/cli/{index-kch6yenm.js → index-4fhcbe14.js} +8 -8
  23. package/dist/cli/{index-ww6zm5hr.js → index-5ebgzb5a.js} +3 -3
  24. package/dist/cli/{index-4vb6qa73.js → index-5h60rtaa.js} +37 -3
  25. package/dist/cli/{index-w3gtqey0.js → index-6chhqq2n.js} +4 -4
  26. package/dist/cli/index-6m24v15v.js +429 -0
  27. package/dist/cli/{index-vdn32nws.js → index-6rx1rdaq.js} +3 -3
  28. package/dist/cli/{index-x43debgx.js → index-74514zkh.js} +15 -17
  29. package/dist/cli/{index-1ww7wj8d.js → index-7f2r3ysr.js} +41 -17
  30. package/dist/cli/{index-kc2tgcm7.js → index-7z9zqxqt.js} +4 -4
  31. package/dist/cli/{index-n8688d12.js → index-8bdk7124.js} +2 -2
  32. package/dist/cli/{index-3146wmgv.js → index-8d90gzaz.js} +1 -1
  33. package/dist/cli/{index-b2nj04q6.js → index-9ss2m4rs.js} +1 -434
  34. package/dist/cli/{index-50j914b5.js → index-a0d4fp6r.js} +29 -7
  35. package/dist/cli/{index-ggtmsm84.js → index-ajknebrc.js} +1 -1
  36. package/dist/cli/{index-zjg4chy2.js → index-anxs69ad.js} +2 -2
  37. package/dist/cli/{index-aqppaaqx.js → index-asey3tb3.js} +6 -4
  38. package/dist/cli/{index-kv2tdkk5.js → index-bvkd7at6.js} +1 -1
  39. package/dist/cli/{index-r656jh9j.js → index-c98rjgjq.js} +4301 -2877
  40. package/dist/cli/{index-r5q5gd2a.js → index-d224mhr9.js} +3 -3
  41. package/dist/cli/{index-nqsj0g5y.js → index-dh5th4jn.js} +8 -8
  42. package/dist/cli/index-e45htt92.js +361 -0
  43. package/dist/cli/{index-w95vxjde.js → index-f36hy1x4.js} +39 -8
  44. package/dist/cli/{index-hp22pzn5.js → index-f8jdar6q.js} +2 -2
  45. package/dist/cli/{index-47kh2103.js → index-fnyw5rzg.js} +14 -14
  46. package/dist/cli/{index-7m32fjb4.js → index-g11h1qpk.js} +9 -9
  47. package/dist/cli/{index-d9entpn3.js → index-g9weyhq6.js} +4 -4
  48. package/dist/cli/{index-qbw3yw2d.js → index-grn6tkbt.js} +11 -11
  49. package/dist/cli/{index-9gxbjkts.js → index-gy0nyfbw.js} +24 -21
  50. package/dist/cli/{index-5jx22kwc.js → index-hhzzyjm3.js} +544 -15
  51. package/dist/cli/{index-dsg9dw3b.js → index-j2svfhzk.js} +2 -2
  52. package/dist/cli/{index-2bgr671r.js → index-jre6tm3v.js} +20 -2
  53. package/dist/cli/{index-77z98j76.js → index-mpf1tvwf.js} +314 -130
  54. package/dist/cli/{index-e90em0x4.js → index-ndjjvxzz.js} +12 -17
  55. package/dist/cli/{index-r3mvsbtq.js → index-p612v1mv.js} +7 -1
  56. package/dist/cli/{index-zfs3zqeq.js → index-ptsqnxwd.js} +771 -21
  57. package/dist/cli/{index-ggrp3v00.js → index-qtxevgdx.js} +15 -17
  58. package/dist/cli/{index-c5v1w13g.js → index-s3k7xbqd.js} +807 -629
  59. package/dist/cli/{index-pp2nya9v.js → index-tqw8w2n5.js} +2 -4
  60. package/dist/cli/index-w6988bbc.js +675 -0
  61. package/dist/cli/{index-4gqxppcx.js → index-xwbn7c8m.js} +2 -2
  62. package/dist/cli/{index-mmjamc9b.js → index-y5hfk7ya.js} +6 -6
  63. package/dist/cli/{index-5kcvrpkt.js → index-zb6gdym8.js} +2 -2
  64. package/dist/cli/index.js +161 -80
  65. package/dist/cli/{knowledge-escalator-j04g450p.js → knowledge-escalator-3fax9y3s.js} +18 -19
  66. package/dist/cli/{knowledge-events-53z45rs0.js → knowledge-events-9cpdyhmb.js} +16 -17
  67. package/dist/cli/{knowledge-link-a6kfg3qm.js → knowledge-link-dgvbqjqg.js} +4 -5
  68. package/dist/cli/{knowledge-store-whm0gagt.js → knowledge-store-y35rka0p.js} +6 -7
  69. package/dist/cli/{knowledge-validator-h8m7065g.js → knowledge-validator-fd761gpx.js} +8 -9
  70. package/dist/cli/{model-preflight-288nsgpw.js → model-preflight-3s1c0zpc.js} +1 -1
  71. package/dist/cli/{pending-delegations-6hkpe5ze.js → pending-delegations-t3y19j3n.js} +17 -8
  72. package/dist/cli/{pr-subscriptions-11zca1mh.js → pr-subscriptions-00zp69mt.js} +17 -8
  73. package/dist/cli/{pr-workflow-gate-6g29rkg7.js → pr-workflow-gate-2h0j8c92.js} +51 -49
  74. package/dist/cli/{runner-5abw3t35.js → runner-0e3bjeev.js} +6 -7
  75. package/dist/cli/{scan-cursor-mkfx410t.js → scan-cursor-wppe2gxw.js} +9 -10
  76. package/dist/cli/{schema-jbbam3ev.js → schema-sec49ppy.js} +2 -2
  77. package/dist/cli/{scope-persistence-q1ct4k42.js → scope-persistence-59eyqaz4.js} +20 -13
  78. package/dist/cli/{skill-generator-cv8fg96x.js → skill-generator-56rbmpj7.js} +21 -22
  79. package/dist/cli/snapshot-coordination-init-dnkdc7gx.js +84 -0
  80. package/dist/cli/{telemetry-mbqqamsj.js → telemetry-a1yvjerj.js} +1 -1
  81. package/dist/cli/{workspace-snapshot-eh18vgkn.js → workspace-snapshot-6z9rk7xw.js} +3 -3
  82. package/dist/cli/{worktree-collision-ownership-xgnn8dsq.js → worktree-collision-ownership-fj9n4mhk.js} +21 -12
  83. package/dist/cli/{worktree-isolation-k2dgfmeg.js → worktree-isolation-vd1s86ya.js} +49 -47
  84. package/dist/commands/benchmark.d.ts +5 -1
  85. package/dist/commands/close.d.ts +13 -6
  86. package/dist/commands/registry.d.ts +34 -43
  87. package/dist/commands/reset-session.d.ts +4 -0
  88. package/dist/commands/turbo.d.ts +1 -1
  89. package/dist/config/bundled-skills.d.ts +4 -3
  90. package/dist/config/constants.d.ts +13 -0
  91. package/dist/db/coordination-store.d.ts +85 -0
  92. package/dist/db/durability.d.ts +22 -5
  93. package/dist/db/index.d.ts +1 -0
  94. package/dist/db/project-db.d.ts +12 -0
  95. package/dist/hooks/extractors.d.ts +9 -0
  96. package/dist/hooks/non-architect-advisory.d.ts +18 -0
  97. package/dist/hooks/repo-graph-injection.d.ts +16 -0
  98. package/dist/index.js +837 -730
  99. package/dist/memory/schema.d.ts +3 -3
  100. package/dist/pr-review/authorization.d.ts +5 -4
  101. package/dist/pr-review/persistence.d.ts +10 -1
  102. package/dist/scope/scope-binding.d.ts +10 -0
  103. package/dist/scope/scope-persistence.d.ts +10 -0
  104. package/dist/services/decision-drift-analyzer.d.ts +7 -0
  105. package/dist/services/handoff-service.d.ts +12 -0
  106. package/dist/services/status-service.d.ts +31 -0
  107. package/dist/session/snapshot-coordination-init.d.ts +49 -0
  108. package/dist/session/snapshot-reader.d.ts +2 -0
  109. package/dist/session/snapshot-store.d.ts +42 -0
  110. package/dist/session/snapshot-writer.d.ts +4 -1
  111. package/dist/state.d.ts +14 -3
  112. package/dist/tools/repo-graph/builder.d.ts +1 -25
  113. package/dist/tools/repo-graph/cache.d.ts +5 -1
  114. package/dist/tools/repo-graph/fallback-scanner.d.ts +71 -0
  115. package/dist/tools/repo-graph/indexed-storage.d.ts +11 -0
  116. package/dist/tools/repo-graph/storage.d.ts +7 -0
  117. package/dist/turbo/epic/state.d.ts +4 -20
  118. package/dist/utils/bun-compat.d.ts +10 -0
  119. package/dist/utils/context-decisions.d.ts +77 -0
  120. package/dist/utils/external-tool-runner.d.ts +2 -0
  121. package/dist/utils/sanitize-display.d.ts +7 -0
  122. package/package.json +5 -3
  123. package/dist/cli/curator-llm-factory-sxcpmcqq.js +0 -68
  124. package/dist/cli/guardrail-explain-xv9aw1bf.js +0 -69
  125. package/dist/cli/hive-promoter-09yc9mp5.js +0 -83
  126. package/dist/cli/index-xnb3tk7x.js +0 -24
  127. package/dist/cli/{ast-diff-ekd9v10f.js → ast-diff-b0esr2kf.js} +3 -3
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  init_loader,
4
4
  loadPluginConfigWithMeta
5
- } from "./index-rhqdsc1x.js";
5
+ } from "./index-0mwjamha.js";
6
6
  import {
7
7
  init_schema
8
- } from "./index-aqppaaqx.js";
8
+ } from "./index-asey3tb3.js";
9
9
  import {
10
10
  DEFAULT_WORKTREE_ISOLATION_CONFIG,
11
11
  init_constants
12
- } from "./index-50j914b5.js";
12
+ } from "./index-a0d4fp6r.js";
13
13
 
14
14
  // src/config/index.ts
15
15
  init_constants();
@@ -5,7 +5,7 @@ import {
5
5
  batchDurabilityClass,
6
6
  classifyDbWriteError,
7
7
  getProjectDb
8
- } from "./index-b2nj04q6.js";
8
+ } from "./index-w6988bbc.js";
9
9
  import {
10
10
  _internals,
11
11
  canonicalRootKeyFresh
@@ -16,6 +16,13 @@ import {
16
16
  warn
17
17
  } from "./index-zgwm4ryv.js";
18
18
 
19
+ // src/db/canonical-project.ts
20
+ var defaultCanonicalRootRealpath = _internals.realpathSync;
21
+ var defaultCanonicalRootNativeRealpath = _internals.realpathSyncNative;
22
+ function canonicalProjectKey(directory) {
23
+ return canonicalRootKeyFresh(directory);
24
+ }
25
+
19
26
  // src/background/event-bus.ts
20
27
  class AutomationEventBus {
21
28
  listeners = new Map;
@@ -83,13 +90,6 @@ function getGlobalEventBus() {
83
90
  return globalEventBus;
84
91
  }
85
92
 
86
- // src/db/canonical-project.ts
87
- var defaultCanonicalRootRealpath = _internals.realpathSync;
88
- var defaultCanonicalRootNativeRealpath = _internals.realpathSyncNative;
89
- function canonicalProjectKey(directory) {
90
- return canonicalRootKeyFresh(directory);
91
- }
92
-
93
93
  // src/db/group-commit-writer.ts
94
94
  init_logger();
95
95
  function isClosedHandleError(err) {
@@ -0,0 +1,361 @@
1
+ // @bun
2
+ import {
3
+ DURABILITY_CLASSES,
4
+ getProjectDb,
5
+ projectDbExists,
6
+ withImmediateTransaction
7
+ } from "./index-w6988bbc.js";
8
+
9
+ // src/db/coordination-store.ts
10
+ import { createHash } from "crypto";
11
+ var MAX_KEY_CHARS = 512;
12
+ var MAX_STATUS_CHARS = 128;
13
+ var MAX_PAYLOAD_CHARS = 1048576;
14
+ var MAX_EVENTS_PER_STREAM = 2048;
15
+ var MAX_TOTAL_EVENTS = 1e5;
16
+ var MAX_EVENT_FENCES_PER_STREAM = 8192;
17
+ var MAX_TOTAL_EVENT_FENCES = 400000;
18
+ var MAX_COORDINATION_STATE_LIST_ROWS = 25000;
19
+ var COORDINATION_STATE_PAGE_SIZE = 5000;
20
+ var _internals = {
21
+ maxEventsPerStream: MAX_EVENTS_PER_STREAM,
22
+ maxTotalEvents: MAX_TOTAL_EVENTS,
23
+ maxEventFencesPerStream: MAX_EVENT_FENCES_PER_STREAM,
24
+ maxTotalEventFences: MAX_TOTAL_EVENT_FENCES
25
+ };
26
+ function boundedText(value, label, max) {
27
+ if (value.length === 0 || value.length > max) {
28
+ throw new Error(`${label} must contain 1..${max} characters`);
29
+ }
30
+ return value;
31
+ }
32
+ function validatePayload(payload) {
33
+ boundedText(payload, "payload", MAX_PAYLOAD_CHARS);
34
+ JSON.parse(payload);
35
+ return payload;
36
+ }
37
+ function digestPayload(payload) {
38
+ return createHash("sha256").update(payload, "utf8").digest("hex");
39
+ }
40
+ function rowToState(row) {
41
+ if (!row)
42
+ return null;
43
+ validatePayload(row.payload);
44
+ return {
45
+ namespace: row.namespace,
46
+ entityKey: row.entity_key,
47
+ revision: row.revision,
48
+ generation: row.generation,
49
+ status: row.status,
50
+ payload: row.payload,
51
+ updatedAt: row.updated_at
52
+ };
53
+ }
54
+ function readState(db, namespace, entityKey) {
55
+ const row = db.query(`SELECT namespace, entity_key, revision, generation, status, payload, updated_at
56
+ FROM coordination_state WHERE namespace = ? AND entity_key = ?`).get(namespace, entityKey) ?? null;
57
+ return rowToState(row);
58
+ }
59
+ function transactionHooks() {
60
+ return {
61
+ beforeBegin: (db) => _internals.coordinationFaultInjector?.("before_begin", db),
62
+ beforeOuterCommit: (db) => _internals.coordinationFaultInjector?.("before_outer_commit", db)
63
+ };
64
+ }
65
+ function withCoordinationTransaction(directory, fn) {
66
+ return withImmediateTransaction(getProjectDb(directory), DURABILITY_CLASSES.coordination_state, fn, transactionHooks());
67
+ }
68
+ function getCoordinationState(directory, namespace, entityKey) {
69
+ if (!projectDbExists(directory))
70
+ return null;
71
+ return readState(getProjectDb(directory), namespace, entityKey);
72
+ }
73
+ function listCoordinationStates(directory, namespace, limit = 5000) {
74
+ if (!projectDbExists(directory))
75
+ return [];
76
+ const boundedLimit = Number.isFinite(limit) ? Math.max(0, Math.min(MAX_COORDINATION_STATE_LIST_ROWS, Math.trunc(limit))) : 0;
77
+ if (boundedLimit === 0)
78
+ return [];
79
+ const db = getProjectDb(directory);
80
+ const states = [];
81
+ let lastEntityKey;
82
+ while (states.length < boundedLimit) {
83
+ const pageLimit = Math.min(COORDINATION_STATE_PAGE_SIZE, boundedLimit - states.length);
84
+ const rows = lastEntityKey === undefined ? db.query(`SELECT namespace, entity_key, revision, generation, status, payload, updated_at
85
+ FROM coordination_state WHERE namespace = ? ORDER BY entity_key LIMIT ?`).all(namespace, pageLimit) : db.query(`SELECT namespace, entity_key, revision, generation, status, payload, updated_at
86
+ FROM coordination_state
87
+ WHERE namespace = ? AND entity_key > ?
88
+ ORDER BY entity_key LIMIT ?`).all(namespace, lastEntityKey, pageLimit);
89
+ if (rows.length === 0)
90
+ break;
91
+ states.push(...rows.map((row) => rowToState(row)));
92
+ lastEntityKey = rows[rows.length - 1]?.entity_key;
93
+ if (rows.length < pageLimit)
94
+ break;
95
+ }
96
+ return states;
97
+ }
98
+ function countCoordinationStates(directory, namespace) {
99
+ if (!projectDbExists(directory))
100
+ return 0;
101
+ const row = getProjectDb(directory).query("SELECT COUNT(*) AS count FROM coordination_state WHERE namespace = ?").get(namespace);
102
+ return row?.count ?? 0;
103
+ }
104
+ function deleteCoordinationState(directory, namespace, entityKey, expectedRevision) {
105
+ return withCoordinationTransaction(directory, () => {
106
+ const db = getProjectDb(directory);
107
+ const result = expectedRevision === undefined ? db.run("DELETE FROM coordination_state WHERE namespace = ? AND entity_key = ?", [namespace, entityKey]) : db.run(`DELETE FROM coordination_state
108
+ WHERE namespace = ? AND entity_key = ? AND revision = ?`, [namespace, entityKey, expectedRevision]);
109
+ return result.changes === 1;
110
+ });
111
+ }
112
+ function deleteCoordinationStateWithinTransaction(directory, namespace, entityKey, expectedRevision) {
113
+ const db = getProjectDb(directory);
114
+ const result = expectedRevision === undefined ? db.run("DELETE FROM coordination_state WHERE namespace = ? AND entity_key = ?", [namespace, entityKey]) : db.run(`DELETE FROM coordination_state
115
+ WHERE namespace = ? AND entity_key = ? AND revision = ?`, [namespace, entityKey, expectedRevision]);
116
+ return result.changes === 1;
117
+ }
118
+ function validateTransitionInput(input) {
119
+ boundedText(input.namespace, "namespace", MAX_KEY_CHARS);
120
+ boundedText(input.entityKey, "entityKey", MAX_KEY_CHARS);
121
+ boundedText(input.status, "status", MAX_STATUS_CHARS);
122
+ validatePayload(input.payload);
123
+ if (!Number.isSafeInteger(input.generation) || input.generation < 0) {
124
+ throw new Error("generation must be a nonnegative safe integer");
125
+ }
126
+ if (input.event) {
127
+ if (input.expectedRevision === undefined) {
128
+ throw new Error("event-bearing coordination transitions require expectedRevision");
129
+ }
130
+ boundedText(input.event.streamId, "streamId", MAX_KEY_CHARS);
131
+ boundedText(input.event.idempotencyKey, "idempotencyKey", MAX_KEY_CHARS);
132
+ boundedText(input.event.eventType, "eventType", MAX_STATUS_CHARS);
133
+ validatePayload(input.event.payload);
134
+ if (input.event.expectedStreamVersion !== undefined && (!Number.isSafeInteger(input.event.expectedStreamVersion) || input.event.expectedStreamVersion < 0)) {
135
+ throw new Error("expectedStreamVersion must be a nonnegative safe integer");
136
+ }
137
+ }
138
+ }
139
+ function transitionCoordinationStateWithinTransaction(directory, input) {
140
+ validateTransitionInput(input);
141
+ const db = getProjectDb(directory);
142
+ const current = readState(db, input.namespace, input.entityKey);
143
+ if (input.event) {
144
+ const duplicate = db.query(`SELECT event_type, generation, payload_digest FROM coordination_event_fence
145
+ WHERE stream_id = ? AND idempotency_key = ?`).get(input.event.streamId, input.event.idempotencyKey);
146
+ if (duplicate) {
147
+ const exact = duplicate.event_type === input.event.eventType && duplicate.generation === input.generation && duplicate.payload_digest === digestPayload(input.event.payload);
148
+ return {
149
+ outcome: exact ? "duplicate" : "idempotency_conflict",
150
+ state: current
151
+ };
152
+ }
153
+ }
154
+ if (current && input.generation < current.generation) {
155
+ return { outcome: "stale_generation", state: current };
156
+ }
157
+ if (input.expectedRevision === null && current !== null || typeof input.expectedRevision === "number" && current?.revision !== input.expectedRevision) {
158
+ return { outcome: "revision_conflict", state: current };
159
+ }
160
+ const nextRevision = (current?.revision ?? 0) + 1;
161
+ const now = new Date().toISOString();
162
+ if (input.event) {
163
+ const currentStreamVersion = db.query("SELECT MAX(version) AS max FROM coordination_event WHERE stream_id = ?").get(input.event.streamId)?.max ?? 0;
164
+ if (input.event.expectedStreamVersion !== undefined && input.event.expectedStreamVersion !== currentStreamVersion) {
165
+ return { outcome: "stream_version_conflict", state: current };
166
+ }
167
+ const nextVersion = currentStreamVersion + 1;
168
+ const payloadDigest = digestPayload(input.event.payload);
169
+ db.run(`INSERT INTO coordination_event
170
+ (stream_id, version, idempotency_key, event_type, generation, payload, created_at)
171
+ VALUES (?, ?, ?, ?, ?, ?, ?)`, [
172
+ input.event.streamId,
173
+ nextVersion,
174
+ input.event.idempotencyKey,
175
+ input.event.eventType,
176
+ input.generation,
177
+ input.event.payload,
178
+ now
179
+ ]);
180
+ db.run(`INSERT INTO coordination_event_fence
181
+ (stream_id, idempotency_key, event_type, generation, payload_digest, created_at)
182
+ VALUES (?, ?, ?, ?, ?, ?)
183
+ ON CONFLICT(stream_id, idempotency_key) DO UPDATE SET
184
+ event_type = excluded.event_type, generation = excluded.generation,
185
+ payload_digest = excluded.payload_digest, created_at = excluded.created_at`, [
186
+ input.event.streamId,
187
+ input.event.idempotencyKey,
188
+ input.event.eventType,
189
+ input.generation,
190
+ payloadDigest,
191
+ now
192
+ ]);
193
+ const streamFenceOverflow = (db.query("SELECT COUNT(*) AS count FROM coordination_event_fence WHERE stream_id = ?").get(input.event.streamId)?.count ?? 0) - _internals.maxEventFencesPerStream;
194
+ if (streamFenceOverflow > 0) {
195
+ db.run(`DELETE FROM coordination_event_fence WHERE rowid IN (
196
+ SELECT rowid FROM coordination_event_fence
197
+ WHERE stream_id = ? ORDER BY created_at, rowid LIMIT ?
198
+ )`, [input.event.streamId, streamFenceOverflow]);
199
+ }
200
+ const totalFenceCount = db.query("SELECT COUNT(*) AS count FROM coordination_event_fence").get()?.count ?? 0;
201
+ const totalFenceOverflow = totalFenceCount - _internals.maxTotalEventFences;
202
+ if (totalFenceOverflow > 0) {
203
+ db.run(`DELETE FROM coordination_event_fence WHERE rowid IN (
204
+ SELECT rowid FROM coordination_event_fence
205
+ ORDER BY created_at, stream_id, rowid LIMIT ?
206
+ )`, [totalFenceOverflow]);
207
+ }
208
+ const streamFloor = nextVersion - _internals.maxEventsPerStream;
209
+ if (streamFloor > 0) {
210
+ db.run("DELETE FROM coordination_event WHERE stream_id = ? AND version <= ?", [input.event.streamId, streamFloor]);
211
+ }
212
+ const total = db.query("SELECT COUNT(*) AS count FROM coordination_event").get()?.count ?? 0;
213
+ const overflow = total - _internals.maxTotalEvents;
214
+ if (overflow > 0) {
215
+ db.run(`DELETE FROM coordination_event WHERE rowid IN (
216
+ SELECT candidate.rowid FROM coordination_event AS candidate
217
+ WHERE candidate.version < (
218
+ SELECT MAX(head.version) FROM coordination_event AS head
219
+ WHERE head.stream_id = candidate.stream_id
220
+ )
221
+ ORDER BY candidate.created_at, candidate.stream_id, candidate.version LIMIT ?
222
+ )`, [overflow]);
223
+ }
224
+ _internals.coordinationFaultInjector?.("after_event_before_state", db);
225
+ }
226
+ db.run(`INSERT INTO coordination_state
227
+ (namespace, entity_key, revision, generation, status, payload, updated_at)
228
+ VALUES (?, ?, ?, ?, ?, ?, ?)
229
+ ON CONFLICT(namespace, entity_key) DO UPDATE SET
230
+ revision = excluded.revision, generation = excluded.generation,
231
+ status = excluded.status, payload = excluded.payload, updated_at = excluded.updated_at`, [
232
+ input.namespace,
233
+ input.entityKey,
234
+ nextRevision,
235
+ input.generation,
236
+ input.status,
237
+ input.payload,
238
+ now
239
+ ]);
240
+ return {
241
+ outcome: "applied",
242
+ state: readState(db, input.namespace, input.entityKey)
243
+ };
244
+ }
245
+ function transitionCoordinationState(directory, input) {
246
+ validateTransitionInput(input);
247
+ return withCoordinationTransaction(directory, () => transitionCoordinationStateWithinTransaction(directory, input));
248
+ }
249
+ function getCoordinationLease(directory, namespace, entityKey) {
250
+ boundedText(namespace, "namespace", MAX_KEY_CHARS);
251
+ boundedText(entityKey, "entityKey", MAX_KEY_CHARS);
252
+ const row = getProjectDb(directory).query(`SELECT generation, owner_token, lease_expires_at, payload, updated_at
253
+ FROM coordination_lease WHERE namespace = ? AND entity_key = ?`).get(namespace, entityKey);
254
+ return row ? {
255
+ namespace,
256
+ entityKey,
257
+ generation: row.generation,
258
+ ownerToken: row.owner_token,
259
+ leaseExpiresAt: row.lease_expires_at,
260
+ payload: row.payload,
261
+ updatedAt: row.updated_at
262
+ } : null;
263
+ }
264
+ function acquireCoordinationLease(directory, input) {
265
+ boundedText(input.namespace, "namespace", MAX_KEY_CHARS);
266
+ boundedText(input.entityKey, "entityKey", MAX_KEY_CHARS);
267
+ boundedText(input.ownerToken, "ownerToken", MAX_KEY_CHARS);
268
+ validatePayload(input.payload);
269
+ if (!Number.isSafeInteger(input.generation) || input.generation < 0) {
270
+ throw new Error("generation must be a nonnegative safe integer");
271
+ }
272
+ const expiryMs = Date.parse(input.leaseExpiresAt);
273
+ if (!Number.isFinite(expiryMs) || new Date(expiryMs).toISOString() !== input.leaseExpiresAt) {
274
+ throw new Error("leaseExpiresAt must be a canonical ISO timestamp");
275
+ }
276
+ return withCoordinationTransaction(directory, () => {
277
+ const db = getProjectDb(directory);
278
+ const row = db.query(`SELECT generation, owner_token, lease_expires_at FROM coordination_lease
279
+ WHERE namespace = ? AND entity_key = ?`).get(input.namespace, input.entityKey);
280
+ if (row && input.generation < row.generation)
281
+ return { outcome: "stale_generation" };
282
+ if (row && row.lease_expires_at > new Date().toISOString() && row.owner_token !== input.ownerToken) {
283
+ return { outcome: "held" };
284
+ }
285
+ const now = new Date().toISOString();
286
+ db.run(`INSERT INTO coordination_lease
287
+ (namespace, entity_key, generation, owner_token, lease_expires_at, payload, updated_at)
288
+ VALUES (?, ?, ?, ?, ?, ?, ?)
289
+ ON CONFLICT(namespace, entity_key) DO UPDATE SET
290
+ generation = excluded.generation, owner_token = excluded.owner_token,
291
+ lease_expires_at = excluded.lease_expires_at, payload = excluded.payload,
292
+ updated_at = excluded.updated_at`, [
293
+ input.namespace,
294
+ input.entityKey,
295
+ input.generation,
296
+ input.ownerToken,
297
+ input.leaseExpiresAt,
298
+ input.payload,
299
+ now
300
+ ]);
301
+ return { outcome: "acquired" };
302
+ });
303
+ }
304
+ function releaseCoordinationLease(directory, namespace, entityKey, generation, ownerToken) {
305
+ return withCoordinationTransaction(directory, () => {
306
+ const result = getProjectDb(directory).run(`DELETE FROM coordination_lease
307
+ WHERE namespace = ? AND entity_key = ? AND generation = ? AND owner_token = ?`, [namespace, entityKey, generation, ownerToken]);
308
+ return result.changes === 1;
309
+ });
310
+ }
311
+ function importCoordinationOnce(directory, input, importer) {
312
+ boundedText(input.source, "source", MAX_KEY_CHARS);
313
+ boundedText(input.sourceDigest, "sourceDigest", MAX_KEY_CHARS);
314
+ boundedText(input.emptyNamespace, "emptyNamespace", MAX_KEY_CHARS);
315
+ if (!Number.isSafeInteger(input.rowCount) || input.rowCount < 0) {
316
+ throw new Error("rowCount must be a nonnegative safe integer");
317
+ }
318
+ const result = withCoordinationTransaction(directory, () => {
319
+ const db = getProjectDb(directory);
320
+ const prior = db.query("SELECT 1 AS present FROM coordination_import WHERE source = ?").get(input.source);
321
+ if (prior)
322
+ return "already_imported";
323
+ const count = db.query("SELECT COUNT(*) AS count FROM coordination_state WHERE namespace = ?").get(input.emptyNamespace)?.count ?? 0;
324
+ if (count !== 0)
325
+ return "state_exists";
326
+ importer();
327
+ db.run(`INSERT INTO coordination_import
328
+ (source, imported_at, source_digest, row_count) VALUES (?, ?, ?, ?)`, [
329
+ input.source,
330
+ new Date().toISOString(),
331
+ input.sourceDigest,
332
+ input.rowCount
333
+ ]);
334
+ return "imported";
335
+ });
336
+ if (result === "imported") {
337
+ _internals.coordinationFaultInjector?.("after_commit_before_archive", getProjectDb(directory));
338
+ }
339
+ return result;
340
+ }
341
+ function deleteCoordinationImports(directory, sources) {
342
+ const boundedSources = sources.map((source) => boundedText(source, "source", MAX_KEY_CHARS));
343
+ if (boundedSources.length === 0 || !projectDbExists(directory))
344
+ return 0;
345
+ return withCoordinationTransaction(directory, () => {
346
+ const placeholders = boundedSources.map(() => "?").join(", ");
347
+ const result = getProjectDb(directory).run(`DELETE FROM coordination_import WHERE source IN (${placeholders})`, boundedSources);
348
+ return result.changes;
349
+ });
350
+ }
351
+
352
+ // src/plan/utils.ts
353
+ import { createHash as createHash2 } from "crypto";
354
+ function derivePlanId(plan) {
355
+ return `${plan.swarm}-${plan.title}`.replace(/[^a-zA-Z0-9-_]/g, "_");
356
+ }
357
+ function derivePlanIdentityHash(plan) {
358
+ return createHash2("sha256").update(JSON.stringify([plan.swarm, plan.title]), "utf8").digest("hex");
359
+ }
360
+
361
+ export { MAX_COORDINATION_STATE_LIST_ROWS, withCoordinationTransaction, getCoordinationState, listCoordinationStates, countCoordinationStates, deleteCoordinationState, deleteCoordinationStateWithinTransaction, transitionCoordinationStateWithinTransaction, transitionCoordinationState, getCoordinationLease, acquireCoordinationLease, releaseCoordinationLease, importCoordinationOnce, deleteCoordinationImports, derivePlanId, derivePlanIdentityHash };
@@ -9,7 +9,7 @@ import {
9
9
  readEvaluationRun,
10
10
  saveEvaluationRun,
11
11
  saveTaskSetSnapshot
12
- } from "./index-pp2nya9v.js";
12
+ } from "./index-tqw8w2n5.js";
13
13
  import {
14
14
  canonicalHash,
15
15
  computeCandidateInputContentHash,
@@ -20,11 +20,15 @@ import {
20
20
  } from "./index-txdagbh7.js";
21
21
  import {
22
22
  bunSpawn
23
- } from "./index-r3mvsbtq.js";
23
+ } from "./index-p612v1mv.js";
24
24
  import {
25
25
  exports_external,
26
26
  init_zod
27
27
  } from "./index-bpmtbmy9.js";
28
+ import {
29
+ init_logger,
30
+ warn
31
+ } from "./index-zgwm4ryv.js";
28
32
 
29
33
  // src/evaluation/runner.ts
30
34
  import * as fs3 from "fs";
@@ -192,6 +196,20 @@ init_zod();
192
196
  // src/utils/external-tool-runner.ts
193
197
  import * as fs from "fs";
194
198
  import * as path from "path";
199
+ init_logger();
200
+ function decodeCompleteUtf8Prefix(bytes) {
201
+ const fatalDecoder = new TextDecoder("utf-8", { fatal: true });
202
+ try {
203
+ return fatalDecoder.decode(bytes);
204
+ } catch {
205
+ for (let trim = 1;trim <= 3 && trim <= bytes.byteLength; trim += 1) {
206
+ try {
207
+ return fatalDecoder.decode(bytes.subarray(0, bytes.byteLength - trim));
208
+ } catch {}
209
+ }
210
+ return new TextDecoder().decode(bytes).replace(/\uFFFD+$/u, "");
211
+ }
212
+ }
195
213
  var DEFAULT_WINDOWS_EXTENSIONS = [".exe", ".cmd", ".bat"];
196
214
  var TERMINATION_GRACE_MS = 20;
197
215
  var TERMINATION_FORCE_MS = 20;
@@ -325,7 +343,7 @@ function startBoundedStreamRead(stream, maxBytes, onLimitExceeded) {
325
343
  offset += chunk.byteLength;
326
344
  }
327
345
  return {
328
- text: new TextDecoder().decode(out),
346
+ text: decodeCompleteUtf8Prefix(out),
329
347
  truncated
330
348
  };
331
349
  })();
@@ -334,20 +352,32 @@ function startBoundedStreamRead(stream, maxBytes, onLimitExceeded) {
334
352
  function timeoutKillSignal(platform) {
335
353
  return platform === "win32" ? "SIGTERM" : "SIGKILL";
336
354
  }
355
+ function reportKillFailure(error, signal) {
356
+ if (error?.code === "ESRCH")
357
+ return;
358
+ _internals.warn(`external tool process kill failed for ${signal}`, error);
359
+ }
337
360
  function killProcess(proc) {
361
+ const signal = timeoutKillSignal(_internals.platform());
338
362
  try {
339
- proc?.kill(timeoutKillSignal(_internals.platform()));
340
- } catch {}
363
+ proc?.kill(signal);
364
+ } catch (error) {
365
+ reportKillFailure(error, signal);
366
+ }
341
367
  }
342
368
  function requestTermination(proc, signal) {
343
369
  try {
344
370
  if (proc?.killTree) {
345
- return proc.killTree(signal).then(() => true, () => false);
371
+ return proc.killTree(signal).then(() => true, (error) => {
372
+ reportKillFailure(error, signal);
373
+ return false;
374
+ });
346
375
  } else {
347
376
  proc?.kill(signal);
348
377
  return Promise.resolve(proc !== undefined);
349
378
  }
350
- } catch {
379
+ } catch (error) {
380
+ reportKillFailure(error, signal);
351
381
  return Promise.resolve(false);
352
382
  }
353
383
  }
@@ -635,7 +665,8 @@ var _internals = {
635
665
  setTimeout,
636
666
  clearTimeout,
637
667
  clampTimeoutMs,
638
- computeSpawnTimeoutMs
668
+ computeSpawnTimeoutMs,
669
+ warn
639
670
  };
640
671
 
641
672
  // src/evaluation/disposable-worktree.ts
@@ -14,14 +14,14 @@ import {
14
14
  detectWindowsWrites,
15
15
  getSharedClassifierGuardrailBlock,
16
16
  resolveWriteTargets
17
- } from "./index-r656jh9j.js";
17
+ } from "./index-c98rjgjq.js";
18
18
  import {
19
19
  checkFileAuthority,
20
20
  classifyFile,
21
21
  isInDeclaredScope,
22
22
  redactPath,
23
23
  redactShellCommand
24
- } from "./index-kch6yenm.js";
24
+ } from "./index-4fhcbe14.js";
25
25
 
26
26
  // src/services/guardrail-explain-service.ts
27
27
  import path from "path";
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  captureWorkspaceSnapshot,
4
4
  changedFilesSinceSnapshot
5
- } from "./index-w3gtqey0.js";
5
+ } from "./index-6chhqq2n.js";
6
6
  import {
7
7
  removeWorktreeProvisioningOwner
8
- } from "./index-n8688d12.js";
8
+ } from "./index-8bdk7124.js";
9
9
  import {
10
10
  SOURCE_WORKTREE_GONE_STAGE,
11
11
  ensureTaskGateRequirementsReceiptForSettledTransition,
@@ -14,16 +14,22 @@ import {
14
14
  reconcileLandedMerge,
15
15
  withTaskEvidenceTransaction,
16
16
  writeWorkflowWalFile
17
- } from "./index-x43debgx.js";
17
+ } from "./index-74514zkh.js";
18
+ import {
19
+ validateSwarmPath
20
+ } from "./index-anxs69ad.js";
18
21
  import {
19
22
  appendCoreEventSync
20
- } from "./index-4gqxppcx.js";
23
+ } from "./index-xwbn7c8m.js";
21
24
  import {
22
25
  isPathWithinDeclaredScope
23
26
  } from "./index-556ja8an.js";
24
27
  import {
25
- validateSwarmPath
26
- } from "./index-zjg4chy2.js";
28
+ canonicalRootKeyFresh
29
+ } from "./index-7qefgq4j.js";
30
+ import {
31
+ tryAcquireLock
32
+ } from "./index-jre6tm3v.js";
27
33
  import {
28
34
  init_git_executable,
29
35
  resolveGitExecutable
@@ -32,12 +38,6 @@ import {
32
38
  advisoryWarn,
33
39
  init_warning_buffer
34
40
  } from "./index-4rhhvd1a.js";
35
- import {
36
- canonicalRootKeyFresh
37
- } from "./index-7qefgq4j.js";
38
- import {
39
- tryAcquireLock
40
- } from "./index-2bgr671r.js";
41
41
  import {
42
42
  criticalWarn,
43
43
  init_logger
@@ -487,7 +487,7 @@ async function cleanupRecoveredWorktree(directory, descriptor) {
487
487
  awaitingMergeByCallID,
488
488
  cleanupStandardWorktreeForCallId,
489
489
  standardWorktreeByCallID
490
- } = await import("./worktree-isolation-k2dgfmeg.js");
490
+ } = await import("./worktree-isolation-vd1s86ya.js");
491
491
  standardWorktreeByCallID.delete(descriptor.callID);
492
492
  if (hasResidue)
493
493
  awaitingMergeByCallID.set(descriptor.callID, {
@@ -611,7 +611,7 @@ async function recoverCoderSettlement(directory, taskId) {
611
611
  awaitingMergeByCallID,
612
612
  finishStandardWorktreeDispatch,
613
613
  standardWorktreeByCallID
614
- } = await import("./worktree-isolation-k2dgfmeg.js");
614
+ } = await import("./worktree-isolation-vd1s86ya.js");
615
615
  const descriptor = wal.worktree;
616
616
  const reconstructedDispatch = {
617
617
  callID: descriptor.callID,
@@ -1,4 +1,9 @@
1
1
  // @bun
2
+ import {
3
+ queryHistoricalOutcomes,
4
+ readKnowledgeEvents,
5
+ recordKnowledgeEvent
6
+ } from "./index-qtxevgdx.js";
2
7
  import {
3
8
  jaccardBigram,
4
9
  readKnowledge,
@@ -6,12 +11,7 @@ import {
6
11
  resolveSwarmKnowledgePath,
7
12
  transactKnowledge,
8
13
  wordBigrams
9
- } from "./index-qbw3yw2d.js";
10
- import {
11
- queryHistoricalOutcomes,
12
- readKnowledgeEvents,
13
- recordKnowledgeEvent
14
- } from "./index-ggrp3v00.js";
14
+ } from "./index-grn6tkbt.js";
15
15
  import {
16
16
  init_knowledge_types,
17
17
  isActiveStatus
@@ -224,11 +224,11 @@ async function maybeQuarantineOnContradiction(directory, entryId, threshold, win
224
224
  alreadyInactive: true
225
225
  };
226
226
  }
227
- const { quarantineEntry } = await import("./knowledge-validator-h8m7065g.js");
227
+ const { quarantineEntry } = await import("./knowledge-validator-fd761gpx.js");
228
228
  let policyConfig;
229
229
  try {
230
- const { KnowledgeConfigSchema } = await import("./schema-jbbam3ev.js");
231
- const { loadPluginConfigWithMeta } = await import("./index-mmjamc9b.js");
230
+ const { KnowledgeConfigSchema } = await import("./schema-sec49ppy.js");
231
+ const { loadPluginConfigWithMeta } = await import("./index-y5hfk7ya.js");
232
232
  const { config: loadedConfig } = loadPluginConfigWithMeta(directory);
233
233
  policyConfig = KnowledgeConfigSchema.parse(loadedConfig.knowledge ?? {});
234
234
  } catch {
@@ -2,14 +2,14 @@
2
2
  import {
3
3
  readKnowledge,
4
4
  transactKnowledge
5
- } from "./index-qbw3yw2d.js";
5
+ } from "./index-grn6tkbt.js";
6
+ import {
7
+ resolveKnowledgeStoreDir
8
+ } from "./index-6rx1rdaq.js";
6
9
  import {
7
10
  init_git_executable,
8
11
  resolveGitExecutableAsync
9
12
  } from "./index-9e6fdz2h.js";
10
- import {
11
- resolveKnowledgeStoreDir
12
- } from "./index-vdn32nws.js";
13
13
  import {
14
14
  init_knowledge_types,
15
15
  isActiveStatus