opencode-swarm 7.164.11 → 7.164.12
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/.opencode/skills/engineering-conventions/SKILL.md +1 -1
- package/dist/background/pending-delegations.d.ts +7 -2
- package/dist/background/pr-subscriptions.d.ts +3 -3
- package/dist/cli/{coder-settlement-0rfk8y11.js → coder-settlement-yh1q5fr3.js} +15 -16
- package/dist/cli/{config-doctor-j17b7qq2.js → config-doctor-bd4yzmh7.js} +3 -3
- package/dist/cli/{core-evhjjrtt.js → core-y0s1vmyc.js} +2 -2
- package/dist/cli/{curation-policy-vj6z5hvr.js → curation-policy-gs1qakn7.js} +5 -6
- package/dist/cli/{curator-vqd5yeck.js → curator-brqack0j.js} +48 -46
- package/dist/cli/{curator-drift-ez81vg2t.js → curator-drift-1sg9yk2m.js} +14 -12
- package/dist/cli/curator-llm-factory-dtsjc3zf.js +70 -0
- package/dist/cli/{dispatch-dqybvj8v.js → dispatch-c7xjt7js.js} +3 -3
- package/dist/cli/{evidence-summary-service-937x7rbg.js → evidence-summary-service-nqbcvp30.js} +24 -23
- package/dist/cli/{gate-evidence-q1cehr4k.js → gate-evidence-9stdtpej.js} +9 -10
- package/dist/cli/guardrail-explain-3ff1z3fm.js +71 -0
- package/dist/cli/{guardrail-log-3g93f3g2.js → guardrail-log-sf39x00b.js} +10 -10
- package/dist/cli/{guardrail-reset-qe2r5qzq.js → guardrail-reset-9wr6a60s.js} +48 -46
- package/dist/cli/hive-promoter-bqtj8261.js +85 -0
- package/dist/cli/{index-kv2tdkk5.js → index-03enxdaq.js} +1 -1
- package/dist/cli/{index-ggrp3v00.js → index-0byep4pe.js} +15 -17
- package/dist/cli/{index-2bgr671r.js → index-2bhz5k91.js} +20 -2
- package/dist/cli/{index-mmjamc9b.js → index-3fnym6ac.js} +5 -5
- package/dist/cli/{index-d9entpn3.js → index-40twgsyh.js} +4 -4
- package/dist/cli/{index-ggtmsm84.js → index-4mjmnysc.js} +1 -1
- package/dist/cli/{index-e90em0x4.js → index-4vb56w2k.js} +12 -17
- package/dist/cli/{index-r656jh9j.js → index-5wc5pbzc.js} +3700 -2609
- package/dist/cli/{index-w3gtqey0.js → index-6chhqq2n.js} +4 -4
- package/dist/cli/{index-qbw3yw2d.js → index-888pq4xx.js} +11 -11
- package/dist/cli/{index-3146wmgv.js → index-8d90gzaz.js} +1 -1
- package/dist/cli/{index-5jx22kwc.js → index-8vw2pjgr.js} +544 -15
- package/dist/cli/{index-b2nj04q6.js → index-9ss2m4rs.js} +1 -434
- package/dist/cli/{index-x43debgx.js → index-ad9064j9.js} +15 -17
- package/dist/cli/{index-5kcvrpkt.js → index-b25t91a3.js} +1 -1
- package/dist/cli/index-c45662wc.js +361 -0
- package/dist/cli/{index-aqppaaqx.js → index-cgewrpw5.js} +3 -2
- package/dist/cli/{index-zfs3zqeq.js → index-d3mpxsmy.js} +771 -21
- package/dist/cli/{index-y1yqmkv7.js → index-d7j3n5ra.js} +52 -50
- package/dist/cli/{index-4vb6qa73.js → index-ebce775n.js} +36 -2
- package/dist/cli/{index-dsg9dw3b.js → index-eed0gkv6.js} +2 -2
- package/dist/cli/index-es64amqt.js +675 -0
- package/dist/cli/{index-9gxbjkts.js → index-ewv8qa8q.js} +22 -19
- package/dist/cli/{index-1ww7wj8d.js → index-hb7bh4r2.js} +15 -15
- package/dist/cli/{index-kc2tgcm7.js → index-hg09xemc.js} +4 -4
- package/dist/cli/{index-w95vxjde.js → index-hvz4ad2t.js} +39 -8
- package/dist/cli/{index-77z98j76.js → index-k0s8n6m5.js} +314 -130
- package/dist/cli/{index-7m32fjb4.js → index-kxv193aq.js} +9 -9
- package/dist/cli/{index-hp22pzn5.js → index-m8xrbdmn.js} +2 -2
- package/dist/cli/{index-4gqxppcx.js → index-mee9maf5.js} +2 -2
- package/dist/cli/{index-r3mvsbtq.js → index-p612v1mv.js} +7 -1
- package/dist/cli/{index-r5q5gd2a.js → index-qgajv9rd.js} +2 -2
- package/dist/cli/{index-zjg4chy2.js → index-qqq04n70.js} +2 -2
- package/dist/cli/{index-ww6zm5hr.js → index-r2p0pgst.js} +3 -3
- package/dist/cli/{index-47kh2103.js → index-r69gzes2.js} +14 -14
- package/dist/cli/{index-vdn32nws.js → index-sphahrmq.js} +3 -3
- package/dist/cli/{index-rhqdsc1x.js → index-vw66q1rw.js} +9 -9
- package/dist/cli/{index-kch6yenm.js → index-wasdrhev.js} +7 -7
- package/dist/cli/{index-c5v1w13g.js → index-wknpkfm8.js} +807 -629
- package/dist/cli/{index-pp2nya9v.js → index-x39hjdf1.js} +2 -4
- package/dist/cli/{index-n8688d12.js → index-xxfk62zd.js} +2 -2
- package/dist/cli/index-yvqg6kn5.js +429 -0
- package/dist/cli/{index-nqsj0g5y.js → index-ztm0q26v.js} +8 -8
- package/dist/cli/index.js +50 -48
- package/dist/cli/{knowledge-escalator-j04g450p.js → knowledge-escalator-01vva51d.js} +17 -18
- package/dist/cli/{knowledge-events-53z45rs0.js → knowledge-events-dpfwh1hs.js} +15 -16
- package/dist/cli/{knowledge-link-a6kfg3qm.js → knowledge-link-2rvp966j.js} +4 -5
- package/dist/cli/{knowledge-store-whm0gagt.js → knowledge-store-aw58ae7b.js} +6 -7
- package/dist/cli/{knowledge-validator-h8m7065g.js → knowledge-validator-yhd31ryf.js} +8 -9
- package/dist/cli/{pending-delegations-6hkpe5ze.js → pending-delegations-fjetcz8e.js} +17 -8
- package/dist/cli/{pr-subscriptions-11zca1mh.js → pr-subscriptions-cwwtfs8w.js} +17 -8
- package/dist/cli/{pr-workflow-gate-6g29rkg7.js → pr-workflow-gate-5xwtg1k2.js} +50 -48
- package/dist/cli/{runner-5abw3t35.js → runner-mb51twxt.js} +6 -7
- package/dist/cli/{scan-cursor-mkfx410t.js → scan-cursor-j11qwf0v.js} +9 -10
- package/dist/cli/{schema-jbbam3ev.js → schema-0xp3bde3.js} +1 -1
- package/dist/cli/{scope-persistence-q1ct4k42.js → scope-persistence-brrk806y.js} +19 -12
- package/dist/cli/{skill-generator-cv8fg96x.js → skill-generator-j8qzmet9.js} +20 -21
- package/dist/cli/snapshot-coordination-init-h0xmtftq.js +84 -0
- package/dist/cli/{telemetry-mbqqamsj.js → telemetry-m84ap0pp.js} +1 -1
- package/dist/cli/{workspace-snapshot-eh18vgkn.js → workspace-snapshot-6z9rk7xw.js} +3 -3
- package/dist/cli/{worktree-collision-ownership-xgnn8dsq.js → worktree-collision-ownership-j9zykj18.js} +21 -12
- package/dist/cli/{worktree-isolation-k2dgfmeg.js → worktree-isolation-jd39xz6h.js} +48 -46
- package/dist/commands/close.d.ts +13 -6
- package/dist/commands/reset-session.d.ts +4 -0
- package/dist/db/coordination-store.d.ts +85 -0
- package/dist/db/durability.d.ts +22 -5
- package/dist/db/index.d.ts +1 -0
- package/dist/db/project-db.d.ts +12 -0
- package/dist/index.js +810 -705
- package/dist/memory/schema.d.ts +3 -3
- package/dist/pr-review/authorization.d.ts +5 -4
- package/dist/pr-review/persistence.d.ts +10 -1
- package/dist/scope/scope-binding.d.ts +10 -0
- package/dist/scope/scope-persistence.d.ts +10 -0
- package/dist/services/handoff-service.d.ts +2 -0
- package/dist/services/status-service.d.ts +4 -0
- package/dist/session/snapshot-coordination-init.d.ts +49 -0
- package/dist/session/snapshot-reader.d.ts +2 -0
- package/dist/session/snapshot-store.d.ts +42 -0
- package/dist/session/snapshot-writer.d.ts +4 -1
- package/dist/state.d.ts +6 -3
- package/dist/turbo/epic/state.d.ts +4 -20
- package/dist/utils/bun-compat.d.ts +10 -0
- package/dist/utils/external-tool-runner.d.ts +2 -0
- package/package.json +3 -2
- package/dist/cli/curator-llm-factory-sxcpmcqq.js +0 -68
- package/dist/cli/guardrail-explain-xv9aw1bf.js +0 -69
- package/dist/cli/hive-promoter-09yc9mp5.js +0 -83
- package/dist/cli/index-xnb3tk7x.js +0 -24
- package/dist/cli/{ast-diff-ekd9v10f.js → ast-diff-b0esr2kf.js} +3 -3
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
DURABILITY_CLASSES,
|
|
4
|
+
getProjectDb,
|
|
5
|
+
projectDbExists,
|
|
6
|
+
withImmediateTransaction
|
|
7
|
+
} from "./index-es64amqt.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 };
|
|
@@ -21,7 +21,7 @@ var package_default;
|
|
|
21
21
|
var init_package = __esm(() => {
|
|
22
22
|
package_default = {
|
|
23
23
|
name: "opencode-swarm",
|
|
24
|
-
version: "7.164.
|
|
24
|
+
version: "7.164.12",
|
|
25
25
|
description: "Architect-centric agentic swarm plugin for OpenCode - hub-and-spoke orchestration with SME consultation, code generation, and QA review",
|
|
26
26
|
main: "dist/index.js",
|
|
27
27
|
types: "dist/index.d.ts",
|
|
@@ -119,6 +119,7 @@ var init_package = __esm(() => {
|
|
|
119
119
|
"lint:ci": "biome ci .",
|
|
120
120
|
"test:unit:ci": "bun scripts/ci/run-unit-tests-local.ts",
|
|
121
121
|
"drift:check": "bun run scripts/drift-check.ts",
|
|
122
|
+
"check:pre-push": "bun run scripts/drift-check.ts --enforce --no-report && bun run check:registry-citations",
|
|
122
123
|
"schema:generate": "bun run scripts/generate-config-schema.ts",
|
|
123
124
|
"check:runtime-src-refs": "bun run scripts/check-runtime-src-refs.ts",
|
|
124
125
|
"drift:fix": "bun run scripts/drift-check.ts --fix --confirm",
|
|
@@ -162,7 +163,7 @@ var init_package = __esm(() => {
|
|
|
162
163
|
"proper-lockfile": "^4.1.2",
|
|
163
164
|
"quick-lru": "^7.3.0",
|
|
164
165
|
"web-tree-sitter": "^0.25.0",
|
|
165
|
-
zod: "
|
|
166
|
+
zod: "4.3.6"
|
|
166
167
|
},
|
|
167
168
|
devDependencies: {
|
|
168
169
|
"@biomejs/biome": "2.3.14",
|