opencode-swarm 7.107.3 → 7.107.5

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 (62) hide show
  1. package/.opencode/skills/consult/SKILL.md +10 -0
  2. package/.opencode/skills/council/SKILL.md +10 -0
  3. package/.opencode/skills/engineering-conventions/SKILL.md +20 -0
  4. package/README.md +2 -2
  5. package/dist/agents/agent-output-schema.d.ts +1 -1
  6. package/dist/cli/{config-doctor-cntnpyvj.js → config-doctor-kdq3vae4.js} +3 -2
  7. package/dist/cli/{curator-1nr4qszq.js → curator-k9swkynp.js} +17 -12
  8. package/dist/cli/{curator-llm-factory-x9tk7e6m.js → curator-llm-factory-ed67kywr.js} +17 -12
  9. package/dist/cli/{dispatch-e4ejrsz8.js → dispatch-anmxxhen.js} +56 -13
  10. package/dist/cli/{evidence-summary-service-9r28ds8t.js → evidence-summary-service-6zsgw7x7.js} +3 -3
  11. package/dist/cli/{gate-evidence-ywys9vfs.js → gate-evidence-pgr7d942.js} +2 -2
  12. package/dist/cli/{guardrail-explain-etdrhd4d.js → guardrail-explain-vd6da30t.js} +18 -13
  13. package/dist/cli/{guardrail-log-2rns4g6d.js → guardrail-log-fjypsmek.js} +4 -3
  14. package/dist/cli/{hive-promoter-j4e6rfa6.js → hive-promoter-gh0nva5c.js} +17 -12
  15. package/dist/cli/{index-r8f89sm9.js → index-0kxc7t16.js} +2 -1
  16. package/dist/cli/{index-tgtmbf3r.js → index-4vsgp5a8.js} +1 -1
  17. package/dist/cli/{index-kzfkggjx.js → index-6h82c2h0.js} +28 -11
  18. package/dist/cli/index-bfwt3abw.js +14 -0
  19. package/dist/cli/{index-9wstcavp.js → index-bpgqbwmf.js} +115 -1019
  20. package/dist/cli/index-bq8kd9r9.js +199 -0
  21. package/dist/cli/index-dfdg4ws5.js +741 -0
  22. package/dist/cli/{index-w15984gg.js → index-jrka8jd4.js} +2 -2
  23. package/dist/cli/index-kxm3bdjh.js +631 -0
  24. package/dist/cli/index-n1sptn1w.js +147 -0
  25. package/dist/cli/{index-2560cctg.js → index-pchpahdf.js} +11 -0
  26. package/dist/cli/{index-cyzzdbvw.js → index-vzq4h90s.js} +354 -116
  27. package/dist/cli/{index-502f6np6.js → index-w1tvqh4x.js} +22 -17
  28. package/dist/cli/{index-esg1554h.js → index-wvxhynxq.js} +1 -1
  29. package/dist/cli/{index-8w4d325g.js → index-xg18az81.js} +61 -22
  30. package/dist/cli/{index-f7nma02k.js → index-xmarctsf.js} +137 -175
  31. package/dist/cli/{index-m1xjr58n.js → index-zej8cy0j.js} +1 -1
  32. package/dist/cli/index.js +18 -13
  33. package/dist/cli/knowledge-escalator-3sgwrgy9.js +32 -0
  34. package/dist/cli/knowledge-events-kfc6xmkw.js +62 -0
  35. package/dist/cli/{knowledge-store-tsa8ezka.js → knowledge-store-kyacem71.js} +3 -1
  36. package/dist/cli/knowledge-validator-ez3ws8ef.js +57 -0
  37. package/dist/cli/{pr-subscriptions-0dpn4epk.js → pr-subscriptions-bpvazmsw.js} +2 -2
  38. package/dist/cli/{schema-vw2ffhe9.js → schema-x0ekqzvs.js} +2 -1
  39. package/dist/cli/{skill-generator-y6mmq8n5.js → skill-generator-x83re96d.js} +6 -2
  40. package/dist/commands/knowledge.d.ts +5 -1
  41. package/dist/commands/registry.d.ts +2 -2
  42. package/dist/config/evidence-schema.d.ts +9 -9
  43. package/dist/config/schema.d.ts +42 -12
  44. package/dist/hooks/knowledge-curator.d.ts +27 -0
  45. package/dist/hooks/knowledge-escalator.d.ts +16 -0
  46. package/dist/hooks/knowledge-events.d.ts +11 -0
  47. package/dist/hooks/knowledge-reader.d.ts +0 -17
  48. package/dist/hooks/knowledge-store.d.ts +16 -1
  49. package/dist/hooks/knowledge-types.d.ts +85 -0
  50. package/dist/hooks/knowledge-validator.d.ts +15 -0
  51. package/dist/hooks/skill-usage-log.d.ts +3 -0
  52. package/dist/index.js +312 -310
  53. package/dist/memory/consolidation.d.ts +1 -1
  54. package/dist/memory/schema.d.ts +4 -4
  55. package/dist/sast/rules/rust.d.ts +6 -0
  56. package/dist/tools/knowledge-archive.d.ts +6 -2
  57. package/dist/tools/lint.d.ts +2 -2
  58. package/dist/tools/secretscan.d.ts +16 -0
  59. package/dist/tools/test-runner.d.ts +1 -1
  60. package/package.json +1 -1
  61. package/dist/cli/{index-hkpw4wwa.js → index-4r5z8sgw.js} +3 -3
  62. package/dist/cli/{pending-delegations-ws51m1e1.js → pending-delegations-vfnpm8zt.js} +3 -3
@@ -0,0 +1,199 @@
1
+ // @bun
2
+ import {
3
+ countEntryContradictionsInWindow,
4
+ countEntryViolationsInWindow,
5
+ readKnowledgeEvents,
6
+ recordKnowledgeEvent
7
+ } from "./index-kxm3bdjh.js";
8
+ import {
9
+ jaccardBigram,
10
+ readKnowledge,
11
+ resolveHiveKnowledgePath,
12
+ resolveSwarmKnowledgePath,
13
+ transactKnowledge,
14
+ wordBigrams
15
+ } from "./index-xmarctsf.js";
16
+ import {
17
+ isActiveStatus
18
+ } from "./index-bfwt3abw.js";
19
+ import {
20
+ __require
21
+ } from "./index-a76rekgs.js";
22
+
23
+ // src/hooks/knowledge-escalator.ts
24
+ import { existsSync } from "fs";
25
+ var NEAR_DUPLICATE_THRESHOLD = 0.6;
26
+ var ESCALATION_WINDOW_DAYS = 30;
27
+ var ESCALATION_THRESHOLD = 2;
28
+ function isFullyEscalated(e) {
29
+ return e.directive_priority === "critical" && e.enforcement_mode === "enforce";
30
+ }
31
+ async function maybeEscalateOnViolation(directory, entryId, now = new Date) {
32
+ try {
33
+ let count = await countEntryViolationsInWindow(directory, entryId, ESCALATION_WINDOW_DAYS, now);
34
+ if (count < ESCALATION_THRESHOLD) {
35
+ try {
36
+ const allEntries = [];
37
+ allEntries.push(...await readKnowledge(resolveSwarmKnowledgePath(directory)));
38
+ const hivePath = resolveHiveKnowledgePath();
39
+ if (existsSync(hivePath)) {
40
+ allEntries.push(...await readKnowledge(hivePath));
41
+ }
42
+ const target = allEntries.find((e) => e.id === entryId);
43
+ if (target) {
44
+ const seen = new Set([entryId]);
45
+ const targetBigrams = wordBigrams(target.lesson);
46
+ for (const e of allEntries) {
47
+ if (seen.has(e.id))
48
+ continue;
49
+ seen.add(e.id);
50
+ if (jaccardBigram(targetBigrams, wordBigrams(e.lesson)) >= NEAR_DUPLICATE_THRESHOLD) {
51
+ count += await countEntryViolationsInWindow(directory, e.id, ESCALATION_WINDOW_DAYS, now);
52
+ if (count >= ESCALATION_THRESHOLD)
53
+ break;
54
+ }
55
+ }
56
+ }
57
+ } catch {}
58
+ }
59
+ if (count < ESCALATION_THRESHOLD) {
60
+ return { escalated: false, entryId, violationsInWindow: count };
61
+ }
62
+ const to = "critical";
63
+ const at = now.toISOString();
64
+ const state = {
65
+ outcome: { kind: "not_found" }
66
+ };
67
+ const mutate = (entries) => {
68
+ const entry = entries.find((e) => e.id === entryId);
69
+ if (!entry) {
70
+ state.outcome = { kind: "not_found" };
71
+ return null;
72
+ }
73
+ if (isFullyEscalated(entry)) {
74
+ state.outcome = { kind: "already" };
75
+ return null;
76
+ }
77
+ const from2 = entry.directive_priority ?? "medium";
78
+ const record = {
79
+ from: from2,
80
+ to,
81
+ reason: "repeat_violation",
82
+ at
83
+ };
84
+ entry.directive_priority = to;
85
+ entry.enforcement_mode = "enforce";
86
+ entry.escalation_history = [...entry.escalation_history ?? [], record];
87
+ entry.updated_at = at;
88
+ state.outcome = { kind: "escalated", from: from2 };
89
+ return entries;
90
+ };
91
+ await transactKnowledge(resolveSwarmKnowledgePath(directory), mutate);
92
+ if (state.outcome.kind === "not_found") {
93
+ const hivePath = resolveHiveKnowledgePath();
94
+ if (existsSync(hivePath)) {
95
+ await transactKnowledge(hivePath, mutate);
96
+ }
97
+ }
98
+ if (state.outcome.kind === "already") {
99
+ return {
100
+ escalated: false,
101
+ entryId,
102
+ violationsInWindow: count,
103
+ alreadyEscalated: true
104
+ };
105
+ }
106
+ if (state.outcome.kind === "not_found") {
107
+ return { escalated: false, entryId, violationsInWindow: count };
108
+ }
109
+ const from = state.outcome.from;
110
+ await recordKnowledgeEvent(directory, {
111
+ type: "escalation",
112
+ entry_id: entryId,
113
+ from,
114
+ to,
115
+ reason: "repeat_violation",
116
+ enforcement_mode: "enforce"
117
+ });
118
+ return {
119
+ escalated: true,
120
+ entryId,
121
+ from,
122
+ to,
123
+ violationsInWindow: count
124
+ };
125
+ } catch {
126
+ return { escalated: false, entryId };
127
+ }
128
+ }
129
+ var ESCALATION_DISPLAY_WINDOW_DAYS = 7;
130
+ async function readRecentEscalations(directory, windowDays = ESCALATION_DISPLAY_WINDOW_DAYS, now = new Date) {
131
+ try {
132
+ const cutoff = now.getTime() - windowDays * 24 * 60 * 60 * 1000;
133
+ const events = await readKnowledgeEvents(directory);
134
+ const out = [];
135
+ for (const e of events) {
136
+ if (e.type !== "escalation")
137
+ continue;
138
+ const t = Date.parse(e.timestamp);
139
+ if (Number.isNaN(t) || t < cutoff)
140
+ continue;
141
+ out.push({
142
+ entry_id: e.entry_id,
143
+ from: e.from,
144
+ to: e.to,
145
+ reason: e.reason,
146
+ at: e.timestamp
147
+ });
148
+ }
149
+ out.sort((a, b) => a.at < b.at ? 1 : a.at > b.at ? -1 : 0);
150
+ return out;
151
+ } catch {
152
+ return [];
153
+ }
154
+ }
155
+ function buildEscalationBriefing(escalations, windowDays = ESCALATION_DISPLAY_WINDOW_DAYS) {
156
+ if (escalations.length === 0)
157
+ return null;
158
+ const lines = [`### Recently Escalated (last ${windowDays} days)`];
159
+ for (const e of escalations) {
160
+ lines.push(`- ${e.entry_id} (${e.from}\u2192${e.to}) reason=${e.reason}`);
161
+ }
162
+ return lines.join(`
163
+ `);
164
+ }
165
+ async function escalateViolatedEntries(directory, entryIds, now = new Date) {
166
+ const out = [];
167
+ for (const id of [...new Set(entryIds)]) {
168
+ out.push(await maybeEscalateOnViolation(directory, id, now));
169
+ }
170
+ return out;
171
+ }
172
+ async function maybeQuarantineOnContradiction(directory, entryId, threshold, windowDays, now = new Date) {
173
+ try {
174
+ const count = await countEntryContradictionsInWindow(directory, entryId, windowDays, now);
175
+ if (count < threshold) {
176
+ return { quarantined: false, entryId, contradictionsInWindow: count };
177
+ }
178
+ const entries = await readKnowledge(resolveSwarmKnowledgePath(directory));
179
+ const entry = entries.find((e) => e.id === entryId);
180
+ if (!entry) {
181
+ return { quarantined: false, entryId, contradictionsInWindow: count };
182
+ }
183
+ if (!isActiveStatus(entry.status)) {
184
+ return {
185
+ quarantined: false,
186
+ entryId,
187
+ contradictionsInWindow: count,
188
+ alreadyInactive: true
189
+ };
190
+ }
191
+ const { quarantineEntry } = await import("./knowledge-validator-ez3ws8ef.js");
192
+ await quarantineEntry(directory, entryId, `repeat_contradiction: ${count} contradicted events in ${windowDays}d`, "auto");
193
+ return { quarantined: true, entryId, contradictionsInWindow: count };
194
+ } catch {
195
+ return { quarantined: false, entryId };
196
+ }
197
+ }
198
+
199
+ export { ESCALATION_WINDOW_DAYS, ESCALATION_THRESHOLD, maybeEscalateOnViolation, ESCALATION_DISPLAY_WINDOW_DAYS, readRecentEscalations, buildEscalationBriefing, escalateViolatedEntries, maybeQuarantineOnContradiction };