opencode-swarm 7.107.2 → 7.107.4
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/consult/SKILL.md +10 -0
- package/.opencode/skills/council/SKILL.md +10 -0
- package/.opencode/skills/engineering-conventions/SKILL.md +20 -0
- package/README.md +2 -2
- package/dist/agents/agent-output-schema.d.ts +1 -1
- package/dist/cli/{config-doctor-cntnpyvj.js → config-doctor-kdq3vae4.js} +3 -2
- package/dist/cli/{curator-drift-6ad8mxxb.js → curator-drift-ed7p5mfy.js} +2 -2
- package/dist/cli/{curator-llm-factory-r3m5e7n8.js → curator-llm-factory-abw56kg0.js} +18 -13
- package/dist/cli/{curator-6zvpn7fs.js → curator-rb05fjjk.js} +18 -13
- package/dist/cli/{dispatch-e4ejrsz8.js → dispatch-anmxxhen.js} +56 -13
- package/dist/cli/{evidence-summary-service-7nwhd8s4.js → evidence-summary-service-nwdfnbz1.js} +4 -4
- package/dist/cli/gate-evidence-ywys9vfs.js +1 -1
- package/dist/cli/guardrail-explain-dayy7zw4.js +37 -0
- package/dist/cli/{guardrail-log-fsc85hwa.js → guardrail-log-fjypsmek.js} +4 -3
- package/dist/cli/{hive-promoter-nwcsha2j.js → hive-promoter-34bdmw1w.js} +18 -13
- package/dist/cli/{index-r87xhtmx.js → index-19vxtwa6.js} +22 -17
- package/dist/cli/{index-t4hbye3v.js → index-4r5z8sgw.js} +4 -4
- package/dist/cli/{index-fxtrk7y8.js → index-4vsgp5a8.js} +2 -2
- package/dist/cli/{index-mpe0yk9s.js → index-57ymmh7h.js} +5 -3
- package/dist/cli/{index-357p0baj.js → index-91j1sqzm.js} +14 -2
- package/dist/cli/{index-f12bmedv.js → index-9b7a6agd.js} +91 -34
- package/dist/cli/index-bfwt3abw.js +14 -0
- package/dist/cli/{index-9wstcavp.js → index-bpgqbwmf.js} +115 -1019
- package/dist/cli/index-bq8kd9r9.js +199 -0
- package/dist/cli/index-dfdg4ws5.js +741 -0
- package/dist/cli/{index-jr54w7pb.js → index-f45hbd5x.js} +2 -2
- package/dist/cli/{index-168p3bfr.js → index-gyzxeza3.js} +910 -608
- package/dist/cli/index-kxm3bdjh.js +631 -0
- package/dist/cli/index-n1sptn1w.js +147 -0
- package/dist/cli/{index-2560cctg.js → index-pchpahdf.js} +11 -0
- package/dist/cli/{index-esg1554h.js → index-wvxhynxq.js} +1 -1
- package/dist/cli/{index-8w4d325g.js → index-xg18az81.js} +61 -22
- package/dist/cli/{index-f7nma02k.js → index-xmarctsf.js} +137 -175
- package/dist/cli/{index-w8dzxnx4.js → index-zej8cy0j.js} +1 -1
- package/dist/cli/index.js +18 -13
- package/dist/cli/knowledge-escalator-3sgwrgy9.js +32 -0
- package/dist/cli/knowledge-events-kfc6xmkw.js +62 -0
- package/dist/cli/{knowledge-store-tsa8ezka.js → knowledge-store-kyacem71.js} +3 -1
- package/dist/cli/knowledge-validator-ez3ws8ef.js +57 -0
- package/dist/cli/{pending-delegations-46xf2n2e.js → pending-delegations-vfnpm8zt.js} +4 -4
- package/dist/cli/{pr-subscriptions-3c34rnm1.js → pr-subscriptions-bpvazmsw.js} +3 -3
- package/dist/cli/{schema-vw2ffhe9.js → schema-x0ekqzvs.js} +2 -1
- package/dist/cli/{skill-generator-y6mmq8n5.js → skill-generator-x83re96d.js} +6 -2
- package/dist/commands/knowledge.d.ts +5 -1
- package/dist/commands/registry.d.ts +2 -2
- package/dist/config/evidence-schema.d.ts +9 -9
- package/dist/config/schema.d.ts +42 -12
- package/dist/hooks/guardrails/file-authority.d.ts +1 -1
- package/dist/hooks/knowledge-curator.d.ts +27 -0
- package/dist/hooks/knowledge-escalator.d.ts +16 -0
- package/dist/hooks/knowledge-events.d.ts +11 -0
- package/dist/hooks/knowledge-injector.d.ts +3 -0
- package/dist/hooks/knowledge-store.d.ts +16 -1
- package/dist/hooks/knowledge-types.d.ts +85 -0
- package/dist/hooks/knowledge-validator.d.ts +15 -0
- package/dist/hooks/semantic-diff-injection.d.ts +19 -0
- package/dist/hooks/skill-usage-log.d.ts +3 -0
- package/dist/index.js +354 -353
- package/dist/memory/consolidation.d.ts +1 -1
- package/dist/memory/schema.d.ts +4 -4
- package/dist/sast/rules/rust.d.ts +6 -0
- package/dist/services/directive-predicate-runner.d.ts +1 -1
- package/dist/tools/knowledge-archive.d.ts +6 -2
- package/dist/tools/knowledge-remove.d.ts +11 -0
- package/dist/tools/lint.d.ts +2 -2
- package/dist/tools/secretscan.d.ts +16 -0
- package/dist/tools/test-runner.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cli/guardrail-explain-zajegz3a.js +0 -32
|
@@ -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 };
|