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
@@ -1,4 +1,10 @@
1
1
  // @bun
2
+ import {
3
+ resolveKnowledgeStoreDir
4
+ } from "./index-n1sptn1w.js";
5
+ import {
6
+ isActiveStatus
7
+ } from "./index-bfwt3abw.js";
2
8
  import {
3
9
  atomicWriteFile
4
10
  } from "./index-9b7qp18e.js";
@@ -9,199 +15,57 @@ import {
9
15
  require_proper_lockfile
10
16
  } from "./index-3naa2ajc.js";
11
17
  import {
18
+ __require,
12
19
  __toESM
13
20
  } from "./index-a76rekgs.js";
14
21
 
15
22
  // src/hooks/knowledge-store.ts
16
23
  var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
17
- import { existsSync as existsSync2 } from "fs";
24
+ import { existsSync } from "fs";
18
25
  import { appendFile, mkdir, readFile } from "fs/promises";
19
- import * as os2 from "os";
20
- import * as path2 from "path";
21
-
22
- // src/hooks/knowledge-link.ts
23
- import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
24
26
  import * as os from "os";
25
27
  import * as path from "path";
26
- var LINK_POINTER_FILENAME = "link.json";
27
- var MAX_LINK_ID_LENGTH = 64;
28
- var WINDOWS_RESERVED_NAMES = new Set([
29
- "con",
30
- "prn",
31
- "aux",
32
- "nul",
33
- "com0",
34
- "com1",
35
- "com2",
36
- "com3",
37
- "com4",
38
- "com5",
39
- "com6",
40
- "com7",
41
- "com8",
42
- "com9",
43
- "lpt0",
44
- "lpt1",
45
- "lpt2",
46
- "lpt3",
47
- "lpt4",
48
- "lpt5",
49
- "lpt6",
50
- "lpt7",
51
- "lpt8",
52
- "lpt9"
53
- ]);
54
- var CACHE_TTL_MS = 2000;
55
- var MAX_CACHE_ENTRIES = 500;
56
- function resolveDataDir() {
57
- const platform = process.platform;
58
- const home = process.env.HOME || os.homedir();
59
- if (platform === "win32") {
60
- return path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "opencode-swarm", "Data");
61
- } else if (platform === "darwin") {
62
- return path.join(home, "Library", "Application Support", "opencode-swarm");
63
- }
64
- return path.join(process.env.XDG_DATA_HOME || path.join(home, ".local", "share"), "opencode-swarm");
65
- }
66
- function resolveLinkBaseDir() {
67
- return path.join(resolveDataDir(), "links");
68
- }
69
- function resolveLinkDir(linkId) {
70
- return path.join(resolveLinkBaseDir(), linkId);
71
- }
72
- function sanitizeLinkId(name) {
73
- if (typeof name !== "string")
74
- return null;
75
- const cleaned = name.trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/-+/g, "-").replace(/^[-.]+|[-.]+$/g, "").slice(0, MAX_LINK_ID_LENGTH).replace(/[-.]+$/g, "");
76
- if (cleaned.length === 0)
77
- return null;
78
- const base = cleaned.split(".")[0];
79
- if (WINDOWS_RESERVED_NAMES.has(base))
80
- return null;
81
- return cleaned;
82
- }
83
- function resolveLinkPointerPath(directory) {
84
- return path.join(directory, ".swarm", LINK_POINTER_FILENAME);
85
- }
86
- function readLinkPointer(directory) {
87
- const pointerPath = resolveLinkPointerPath(directory);
88
- if (!existsSync(pointerPath))
89
- return null;
90
- try {
91
- const raw = JSON.parse(readFileSync(pointerPath, "utf-8"));
92
- if (!raw || typeof raw !== "object")
93
- return null;
94
- const obj = raw;
95
- const linkId = obj.linkId;
96
- if (typeof linkId !== "string" || linkId.length === 0)
97
- return null;
98
- const safeId = sanitizeLinkId(linkId);
99
- if (!safeId)
100
- return null;
101
- return {
102
- version: 1,
103
- linkId: safeId,
104
- name: typeof obj.name === "string" ? obj.name : undefined,
105
- createdAt: typeof obj.createdAt === "string" ? obj.createdAt : new Date(0).toISOString(),
106
- source: obj.source === "auto" ? "auto" : "manual"
107
- };
108
- } catch {
109
- return null;
110
- }
111
- }
112
- async function writeLinkPointer(directory, pointer) {
113
- const swarmDir = path.join(directory, ".swarm");
114
- mkdirSync(swarmDir, { recursive: true });
115
- const pointerPath = resolveLinkPointerPath(directory);
116
- await atomicWriteFile(pointerPath, JSON.stringify(pointer, null, 2));
117
- invalidateKnowledgeStoreDirCache(directory);
118
- }
119
- async function removeLinkPointer(directory) {
120
- const pointerPath = resolveLinkPointerPath(directory);
121
- try {
122
- rmSync(pointerPath, { force: true });
123
- } finally {
124
- invalidateKnowledgeStoreDirCache(directory);
125
- }
126
- }
127
- var _resolutionCache = new Map;
128
- function resolveKnowledgeStoreDir(directory) {
129
- const localSwarm = path.join(directory, ".swarm");
130
- const now = Date.now();
131
- const cached = _resolutionCache.get(directory);
132
- if (cached && now < cached.expires) {
133
- return cached.linkDir ?? localSwarm;
134
- }
135
- let linkDir = null;
136
- try {
137
- const pointer = readLinkPointer(directory);
138
- if (pointer) {
139
- linkDir = path.resolve(resolveLinkDir(pointer.linkId));
140
- }
141
- } catch {
142
- linkDir = null;
143
- }
144
- if (!_resolutionCache.has(directory) && _resolutionCache.size >= MAX_CACHE_ENTRIES) {
145
- const oldest = _resolutionCache.keys().next().value;
146
- if (oldest !== undefined)
147
- _resolutionCache.delete(oldest);
148
- }
149
- _resolutionCache.set(directory, { linkDir, expires: now + CACHE_TTL_MS });
150
- return linkDir ?? localSwarm;
151
- }
152
- function invalidateKnowledgeStoreDirCache(directory) {
153
- if (directory === undefined) {
154
- _resolutionCache.clear();
155
- return;
156
- }
157
- _resolutionCache.delete(directory);
158
- }
159
- function isLinked(directory) {
160
- return readLinkPointer(directory) !== null;
161
- }
162
-
163
- // src/hooks/knowledge-store.ts
164
28
  var KNOWLEDGE_JSONL_CACHE_NAMESPACE = "knowledge-jsonl:normalized:v1";
165
29
  function getPlatformConfigDir() {
166
30
  const platform = process.platform;
167
- const home = process.env.HOME || os2.homedir();
31
+ const home = process.env.HOME || os.homedir();
168
32
  if (platform === "win32") {
169
- return path2.join(process.env.LOCALAPPDATA || path2.join(home, "AppData", "Local"), "opencode-swarm", "config");
33
+ return path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "opencode-swarm", "config");
170
34
  } else if (platform === "darwin") {
171
- return path2.join(home, "Library", "Application Support", "opencode-swarm");
35
+ return path.join(home, "Library", "Application Support", "opencode-swarm");
172
36
  } else {
173
- return path2.join(process.env.XDG_CONFIG_HOME || path2.join(home, ".config"), "opencode-swarm");
37
+ return path.join(process.env.XDG_CONFIG_HOME || path.join(home, ".config"), "opencode-swarm");
174
38
  }
175
39
  }
176
40
  function resolveSwarmKnowledgePath(directory) {
177
- return path2.join(resolveKnowledgeStoreDir(directory), "knowledge.jsonl");
41
+ return path.join(resolveKnowledgeStoreDir(directory), "knowledge.jsonl");
178
42
  }
179
43
  function resolveSwarmRejectedPath(directory) {
180
- return path2.join(resolveKnowledgeStoreDir(directory), "knowledge-rejected.jsonl");
44
+ return path.join(resolveKnowledgeStoreDir(directory), "knowledge-rejected.jsonl");
181
45
  }
182
46
  function resolveSwarmRetractionsPath(directory) {
183
- return path2.join(resolveKnowledgeStoreDir(directory), "knowledge-retractions.jsonl");
47
+ return path.join(resolveKnowledgeStoreDir(directory), "knowledge-retractions.jsonl");
184
48
  }
185
49
  function resolveHiveKnowledgePath() {
186
50
  const platform = process.platform;
187
- const home = process.env.HOME || os2.homedir();
51
+ const home = process.env.HOME || os.homedir();
188
52
  let dataDir;
189
53
  if (platform === "win32") {
190
- dataDir = path2.join(process.env.LOCALAPPDATA || path2.join(home, "AppData", "Local"), "opencode-swarm", "Data");
54
+ dataDir = path.join(process.env.LOCALAPPDATA || path.join(home, "AppData", "Local"), "opencode-swarm", "Data");
191
55
  } else if (platform === "darwin") {
192
- dataDir = path2.join(home, "Library", "Application Support", "opencode-swarm");
56
+ dataDir = path.join(home, "Library", "Application Support", "opencode-swarm");
193
57
  } else {
194
- dataDir = path2.join(process.env.XDG_DATA_HOME || path2.join(home, ".local", "share"), "opencode-swarm");
58
+ dataDir = path.join(process.env.XDG_DATA_HOME || path.join(home, ".local", "share"), "opencode-swarm");
195
59
  }
196
- return path2.join(dataDir, "shared-learnings.jsonl");
60
+ return path.join(dataDir, "shared-learnings.jsonl");
197
61
  }
198
62
  function resolveHiveRejectedPath() {
199
63
  const hivePath = resolveHiveKnowledgePath();
200
- return path2.join(path2.dirname(hivePath), "shared-learnings-rejected.jsonl");
64
+ return path.join(path.dirname(hivePath), "shared-learnings-rejected.jsonl");
201
65
  }
202
66
  function resolveHiveEventsPath() {
203
67
  const hivePath = resolveHiveKnowledgePath();
204
- return path2.join(path2.dirname(hivePath), "shared-knowledge-events.jsonl");
68
+ return path.join(path.dirname(hivePath), "shared-knowledge-events.jsonl");
205
69
  }
206
70
  function parseKnowledgeContent(content, max) {
207
71
  const results = [];
@@ -221,16 +85,16 @@ function parseKnowledgeContent(content, max) {
221
85
  return results;
222
86
  }
223
87
  async function readKnowledge(filePath, maxEntries) {
224
- const resolvedPath = path2.resolve(filePath);
88
+ const resolvedPath = path.resolve(filePath);
225
89
  const cap = maxEntries !== undefined && maxEntries > 0 ? maxEntries : undefined;
226
90
  if (cap !== undefined) {
227
- if (!existsSync2(resolvedPath))
91
+ if (!existsSync(resolvedPath))
228
92
  return [];
229
93
  const content = await readFile(resolvedPath, "utf-8");
230
94
  return parseKnowledgeContent(content, cap);
231
95
  }
232
96
  const entries = await readCachedParsedFile(resolvedPath, KNOWLEDGE_JSONL_CACHE_NAMESPACE, async () => {
233
- if (!existsSync2(resolvedPath))
97
+ if (!existsSync(resolvedPath))
234
98
  return null;
235
99
  return await readFile(resolvedPath, "utf-8");
236
100
  }, (content) => parseKnowledgeContent(content, Infinity));
@@ -281,6 +145,9 @@ function normalizeEntry(raw) {
281
145
  });
282
146
  } catch {}
283
147
  }
148
+ if (typeof obj.recent_negative_phase_count !== "number") {
149
+ obj.recent_negative_phase_count = 0;
150
+ }
284
151
  const arrayFields = [
285
152
  "triggers",
286
153
  "required_actions",
@@ -312,7 +179,7 @@ async function appendRetractionRecord(directory, record) {
312
179
  await appendKnowledge(resolveSwarmRetractionsPath(directory), record);
313
180
  }
314
181
  async function appendKnowledge(filePath, entry) {
315
- const dir = path2.dirname(filePath);
182
+ const dir = path.dirname(filePath);
316
183
  await mkdir(dir, { recursive: true });
317
184
  let release = null;
318
185
  try {
@@ -331,7 +198,7 @@ async function appendKnowledge(filePath, entry) {
331
198
  }
332
199
  }
333
200
  async function rewriteKnowledge(filePath, entries) {
334
- const dir = path2.dirname(filePath);
201
+ const dir = path.dirname(filePath);
335
202
  await mkdir(dir, { recursive: true });
336
203
  let release = null;
337
204
  try {
@@ -352,7 +219,7 @@ async function rewriteKnowledge(filePath, entries) {
352
219
  }
353
220
  }
354
221
  async function transactFile(filePath, read, write, mutate) {
355
- const dir = path2.dirname(filePath);
222
+ const dir = path.dirname(filePath);
356
223
  try {
357
224
  await mkdir(dir, { recursive: true });
358
225
  } catch {
@@ -396,7 +263,7 @@ async function getArchivedKnowledgeIds(directory) {
396
263
  for (const line of lines) {
397
264
  try {
398
265
  const entry = JSON.parse(line);
399
- if (entry.status === "archived" || entry.status === "quarantined" || entry.status === "quarantined_unactionable") {
266
+ if (!isActiveStatus(entry.status)) {
400
267
  archived.add(entry.id);
401
268
  }
402
269
  } catch {}
@@ -410,7 +277,7 @@ async function getArchivedKnowledgeIds(directory) {
410
277
  for (const line of lines) {
411
278
  try {
412
279
  const entry = JSON.parse(line);
413
- if (entry.status === "archived" || entry.status === "quarantined" || entry.status === "quarantined_unactionable") {
280
+ if (!isActiveStatus(entry.status)) {
414
281
  archived.add(entry.id);
415
282
  }
416
283
  } catch {}
@@ -466,7 +333,7 @@ function selectKnowledgeCapSurvivors(entries, maxEntries) {
466
333
  return candidates.filter((c) => !drop.has(c.index)).map((c) => c.entry);
467
334
  }
468
335
  function getKnowledgeCapStatusPriority(status) {
469
- if (status === "archived" || status === "quarantined" || status === "quarantined_unactionable") {
336
+ if (!isActiveStatus(status)) {
470
337
  return 0;
471
338
  }
472
339
  return 1;
@@ -497,6 +364,8 @@ async function sweepAgedEntries(filePath, defaultMaxPhases) {
497
364
  mutated = true;
498
365
  const ttl = entry.max_phases ?? defaultMaxPhases;
499
366
  if (entry.phases_alive > ttl) {
367
+ entry.archived_from = entry.status;
368
+ entry.archived_at = now;
500
369
  entry.status = "archived";
501
370
  entry.updated_at = now;
502
371
  result.archived++;
@@ -624,32 +493,123 @@ function inferTags(lesson) {
624
493
  }
625
494
  var CONFIDENCE_FLOOR = 0.1;
626
495
  var CONFIDENCE_CEILING = 1;
627
- async function bumpKnowledgeConfidenceBatch(directory, deltas) {
496
+ async function bumpKnowledgeConfidenceBatch(directory, deltas, options) {
628
497
  if (deltas.length === 0)
629
498
  return;
630
499
  const swarmPath = resolveSwarmKnowledgePath(directory);
631
500
  const hivePath = resolveHiveKnowledgePath();
501
+ const touchedSwarm = [];
502
+ const touchedHive = [];
632
503
  try {
633
- await applyConfidenceDeltas(swarmPath, deltas);
634
- const swarmEntries = await readKnowledge(swarmPath);
635
- const swarmIds = new Set(swarmEntries.map((e) => e.id));
504
+ touchedSwarm.push(...await applyConfidenceDeltas(swarmPath, deltas));
505
+ const swarmIds = new Set(touchedSwarm.map((e) => e.id));
636
506
  const hiveOnly = deltas.filter((d) => !swarmIds.has(d.id));
637
507
  if (hiveOnly.length > 0) {
638
- await applyConfidenceDeltas(hivePath, hiveOnly);
508
+ touchedHive.push(...await applyConfidenceDeltas(hivePath, hiveOnly));
639
509
  }
510
+ await applyConfidenceFloorAction(directory, [...touchedSwarm, ...touchedHive], options).catch((err) => {
511
+ console.warn("[knowledge-store] confidence-floor action sweep failed (best-effort):", err instanceof Error ? err.message : String(err));
512
+ });
640
513
  } catch (err) {
641
514
  console.warn("[knowledge-store] bumpKnowledgeConfidenceBatch failed (fail-open):", err instanceof Error ? err.message : String(err));
642
515
  }
643
516
  }
517
+ async function applyConfidenceFloorAction(directory, touched, options) {
518
+ const action = options?.floorAction ?? "demote";
519
+ if (action === "none" || touched.length === 0)
520
+ return;
521
+ const minOutcomes = options?.floorMinOutcomes ?? 3;
522
+ const signalThreshold = options?.floorSignalThreshold ?? 0;
523
+ const FLOOR_EPSILON = 0.000000001;
524
+ const atFloor = touched.filter((e) => e.confidence <= CONFIDENCE_FLOOR + FLOOR_EPSILON);
525
+ const recovered = touched.filter((e) => e.confidence > CONFIDENCE_FLOOR + FLOOR_EPSILON && e.confidence_floor_demoted);
526
+ if (atFloor.length === 0 && recovered.length === 0)
527
+ return;
528
+ const { readKnowledgeCounterRollups, effectiveRetrievalOutcomes } = await import("./knowledge-events-kfc6xmkw.js");
529
+ const rollups = await readKnowledgeCounterRollups(directory);
530
+ const flagIds = new Set;
531
+ for (const e of atFloor) {
532
+ const outcomes = effectiveRetrievalOutcomes(e.retrieval_outcomes, rollups?.get(e.id));
533
+ const signal = computeOutcomeSignal(outcomes);
534
+ const totalEvidence = (outcomes.applied_explicit_count ?? 0) + (outcomes.succeeded_after_shown_count ?? 0) + (outcomes.ignored_count ?? 0) + (outcomes.violated_count ?? 0) + (outcomes.contradicted_count ?? 0) + (outcomes.failed_after_shown_count ?? 0);
535
+ if (signal < signalThreshold && totalEvidence >= minOutcomes) {
536
+ flagIds.add(e.id);
537
+ }
538
+ }
539
+ for (const e of recovered)
540
+ flagIds.add(e.id);
541
+ if (flagIds.size === 0)
542
+ return;
543
+ const swarmPath = resolveSwarmKnowledgePath(directory);
544
+ const hivePath = resolveHiveKnowledgePath();
545
+ const toQuarantine = [];
546
+ await transactKnowledge(swarmPath, (swarmEntries) => {
547
+ const now = new Date().toISOString();
548
+ for (const entry of swarmEntries) {
549
+ if (!flagIds.has(entry.id))
550
+ continue;
551
+ const atFloorEntry = atFloor.find((e) => e.id === entry.id);
552
+ if (atFloorEntry) {
553
+ entry.confidence_floor_demoted = true;
554
+ if (action === "quarantine") {
555
+ toQuarantine.push({ id: entry.id, tier: "swarm" });
556
+ }
557
+ } else {
558
+ entry.confidence_floor_demoted = false;
559
+ }
560
+ entry.updated_at = now;
561
+ }
562
+ return swarmEntries;
563
+ }).catch((err) => {
564
+ console.warn("[knowledge-store] confidence-floor swarm flag transaction failed (best-effort):", err instanceof Error ? err.message : String(err));
565
+ });
566
+ const hiveFlagIds = new Set;
567
+ for (const e of atFloor) {
568
+ if (e.tier === "hive" && flagIds.has(e.id))
569
+ hiveFlagIds.add(e.id);
570
+ }
571
+ for (const e of recovered) {
572
+ if (e.tier === "hive" && flagIds.has(e.id))
573
+ hiveFlagIds.add(e.id);
574
+ }
575
+ if (hiveFlagIds.size > 0) {
576
+ await transactKnowledge(hivePath, (hiveEntries) => {
577
+ const now = new Date().toISOString();
578
+ for (const entry of hiveEntries) {
579
+ if (!hiveFlagIds.has(entry.id))
580
+ continue;
581
+ const atFloorEntry = atFloor.find((e) => e.id === entry.id);
582
+ if (atFloorEntry) {
583
+ entry.confidence_floor_demoted = true;
584
+ } else {
585
+ entry.confidence_floor_demoted = false;
586
+ }
587
+ entry.updated_at = now;
588
+ }
589
+ return hiveEntries;
590
+ }).catch((err) => {
591
+ console.warn("[knowledge-store] confidence-floor hive flag transaction failed (best-effort):", err instanceof Error ? err.message : String(err));
592
+ });
593
+ }
594
+ if (action === "quarantine" && toQuarantine.length > 0) {
595
+ const { quarantineEntry } = await import("./knowledge-validator-ez3ws8ef.js");
596
+ for (const { id } of toQuarantine) {
597
+ await quarantineEntry(directory, id, "confidence_floor_negative_outcome", "auto").catch((err) => {
598
+ console.warn("[knowledge-store] confidence-floor quarantine failed (best-effort):", err instanceof Error ? err.message : String(err));
599
+ });
600
+ }
601
+ }
602
+ }
644
603
  async function applyConfidenceDeltas(filePath, deltas) {
645
604
  const idDeltaMap = new Map;
646
605
  for (const d of deltas) {
647
606
  const existing = idDeltaMap.get(d.id);
648
607
  idDeltaMap.set(d.id, existing !== undefined ? existing + d.delta : d.delta);
649
608
  }
609
+ const touched = [];
650
610
  let release = null;
651
611
  try {
652
- const dir = path2.dirname(filePath);
612
+ const dir = path.dirname(filePath);
653
613
  await mkdir(dir, { recursive: true });
654
614
  release = await import_proper_lockfile.default.lock(dir, {
655
615
  retries: { retries: 5, minTimeout: 100, maxTimeout: 500 },
@@ -657,7 +617,7 @@ async function applyConfidenceDeltas(filePath, deltas) {
657
617
  });
658
618
  const entries = await readKnowledge(filePath);
659
619
  if (entries.length === 0)
660
- return;
620
+ return [];
661
621
  const now = new Date().toISOString();
662
622
  let mutated = false;
663
623
  for (const entry of entries) {
@@ -667,6 +627,7 @@ async function applyConfidenceDeltas(filePath, deltas) {
667
627
  entry.confidence = Math.max(CONFIDENCE_FLOOR, Math.min(CONFIDENCE_CEILING, entry.confidence + delta));
668
628
  entry.updated_at = now;
669
629
  mutated = true;
630
+ touched.push(entry);
670
631
  }
671
632
  if (mutated) {
672
633
  const content = entries.map((e) => JSON.stringify(e)).join(`
@@ -683,6 +644,7 @@ async function applyConfidenceDeltas(filePath, deltas) {
683
644
  } catch {}
684
645
  }
685
646
  }
647
+ return touched;
686
648
  }
687
649
  var _internals = {
688
650
  getPlatformConfigDir,
@@ -713,4 +675,4 @@ var _internals = {
713
675
  getArchivedKnowledgeIds
714
676
  };
715
677
 
716
- export { resolveLinkDir, sanitizeLinkId, readLinkPointer, writeLinkPointer, removeLinkPointer, resolveKnowledgeStoreDir, isLinked, getPlatformConfigDir, resolveSwarmKnowledgePath, resolveSwarmRejectedPath, resolveSwarmRetractionsPath, resolveHiveKnowledgePath, resolveHiveRejectedPath, resolveHiveEventsPath, readKnowledge, normalizeEntry, readRejectedLessons, readRetractionRecords, appendRetractionRecord, appendKnowledge, rewriteKnowledge, transactFile, transactKnowledge, getArchivedKnowledgeIds, appendKnowledgeWithCapEnforcement, enforceKnowledgeCap, sweepAgedEntries, sweepStaleTodos, appendRejectedLesson, normalize, wordBigrams, jaccardBigram, findNearDuplicate, computeConfidence, OUTCOME_SIGNAL_SMOOTHING, computeOutcomeSignal, inferTags, bumpKnowledgeConfidenceBatch, _internals };
678
+ export { getPlatformConfigDir, resolveSwarmKnowledgePath, resolveSwarmRejectedPath, resolveSwarmRetractionsPath, resolveHiveKnowledgePath, resolveHiveRejectedPath, resolveHiveEventsPath, readKnowledge, normalizeEntry, readRejectedLessons, readRetractionRecords, appendRetractionRecord, appendKnowledge, rewriteKnowledge, transactFile, transactKnowledge, getArchivedKnowledgeIds, appendKnowledgeWithCapEnforcement, enforceKnowledgeCap, sweepAgedEntries, sweepStaleTodos, appendRejectedLesson, normalize, wordBigrams, jaccardBigram, findNearDuplicate, computeConfidence, OUTCOME_SIGNAL_SMOOTHING, computeOutcomeSignal, inferTags, bumpKnowledgeConfidenceBatch, _internals };
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  redactPath,
4
4
  redactShellCommand
5
- } from "./index-tgtmbf3r.js";
5
+ } from "./index-4vsgp5a8.js";
6
6
 
7
7
  // src/services/guardrail-log-service.ts
8
8
  import * as fs from "fs/promises";
package/dist/cli/index.js CHANGED
@@ -7,30 +7,35 @@ import {
7
7
  getPluginLockFilePaths,
8
8
  package_default,
9
9
  resolveCommand
10
- } from "./index-cyzzdbvw.js";
11
- import"./index-esg1554h.js";
12
- import"./index-kzfkggjx.js";
13
- import"./index-8w4d325g.js";
14
- import"./index-tgtmbf3r.js";
10
+ } from "./index-vzq4h90s.js";
11
+ import"./index-4vsgp5a8.js";
12
+ import"./index-c8s9a3zh.js";
13
+ import"./index-wvxhynxq.js";
14
+ import"./index-6h82c2h0.js";
15
+ import"./index-91j1sqzm.js";
16
+ import"./index-xg18az81.js";
15
17
  import"./index-09xpycan.js";
16
18
  import {
17
19
  DEFAULT_AGENT_CONFIGS
18
- } from "./index-2560cctg.js";
19
- import"./index-9wstcavp.js";
20
- import"./index-f7nma02k.js";
21
- import"./index-c8s9a3zh.js";
22
- import"./index-91j1sqzm.js";
20
+ } from "./index-pchpahdf.js";
21
+ import"./index-bpgqbwmf.js";
22
+ import"./index-dfdg4ws5.js";
23
+ import"./index-bq8kd9r9.js";
24
+ import"./index-kxm3bdjh.js";
25
+ import"./index-xmarctsf.js";
26
+ import"./index-n1sptn1w.js";
27
+ import"./index-bfwt3abw.js";
23
28
  import"./index-v4fcn4tr.js";
24
- import"./index-r8f89sm9.js";
29
+ import"./index-0kxc7t16.js";
25
30
  import"./index-9b7qp18e.js";
26
- import"./index-hkpw4wwa.js";
31
+ import"./index-4r5z8sgw.js";
27
32
  import"./index-57ymmh7h.js";
28
33
  import"./index-5e4e2hvv.js";
29
34
  import"./index-p0arc26j.js";
30
35
  import"./index-jtqkh8jf.js";
31
36
  import"./index-zgwm4ryv.js";
32
- import"./index-3naa2ajc.js";
33
37
  import"./index-293f68mj.js";
38
+ import"./index-3naa2ajc.js";
34
39
  import"./index-b9v501fr.js";
35
40
  import"./index-vn263hqt.js";
36
41
  import"./index-a76rekgs.js";
@@ -0,0 +1,32 @@
1
+ // @bun
2
+ import {
3
+ ESCALATION_DISPLAY_WINDOW_DAYS,
4
+ ESCALATION_THRESHOLD,
5
+ ESCALATION_WINDOW_DAYS,
6
+ buildEscalationBriefing,
7
+ escalateViolatedEntries,
8
+ maybeEscalateOnViolation,
9
+ maybeQuarantineOnContradiction,
10
+ readRecentEscalations
11
+ } from "./index-bq8kd9r9.js";
12
+ import"./index-kxm3bdjh.js";
13
+ import"./index-xmarctsf.js";
14
+ import"./index-n1sptn1w.js";
15
+ import"./index-bfwt3abw.js";
16
+ import"./index-9b7qp18e.js";
17
+ import"./index-jtqkh8jf.js";
18
+ import"./index-zgwm4ryv.js";
19
+ import"./index-3naa2ajc.js";
20
+ import"./index-b9v501fr.js";
21
+ import"./index-vn263hqt.js";
22
+ import"./index-a76rekgs.js";
23
+ export {
24
+ readRecentEscalations,
25
+ maybeQuarantineOnContradiction,
26
+ maybeEscalateOnViolation,
27
+ escalateViolatedEntries,
28
+ buildEscalationBriefing,
29
+ ESCALATION_WINDOW_DAYS,
30
+ ESCALATION_THRESHOLD,
31
+ ESCALATION_DISPLAY_WINDOW_DAYS
32
+ };
@@ -0,0 +1,62 @@
1
+ // @bun
2
+ import {
3
+ KNOWLEDGE_EVENT_SCHEMA_VERSION,
4
+ MAX_EVENT_LOG_ENTRIES,
5
+ MAX_VIOLATION_TIMESTAMPS,
6
+ RECEIPT_EVENT_TYPES,
7
+ _internals,
8
+ appendHiveKnowledgeEvent,
9
+ appendKnowledgeEvent,
10
+ applyKnowledgeVerdictFeedback,
11
+ countEntryContradictionsInWindow,
12
+ countEntryViolationsInWindow,
13
+ countViolationsInWindow,
14
+ effectiveRetrievalOutcomes,
15
+ newEventId,
16
+ newTraceId,
17
+ readHiveKnowledgeEvents,
18
+ readKnowledgeCounterRollups,
19
+ readKnowledgeEvents,
20
+ readLegacyApplicationRecords,
21
+ recomputeCounters,
22
+ recordHiveKnowledgeEvent,
23
+ recordKnowledgeEvent,
24
+ resolveHiveEventsPath,
25
+ resolveKnowledgeCounterBaselinePath,
26
+ resolveKnowledgeEventsPath,
27
+ resolveLegacyApplicationLogPath
28
+ } from "./index-kxm3bdjh.js";
29
+ import"./index-n1sptn1w.js";
30
+ import"./index-9b7qp18e.js";
31
+ import"./index-zgwm4ryv.js";
32
+ import"./index-3naa2ajc.js";
33
+ import"./index-b9v501fr.js";
34
+ import"./index-vn263hqt.js";
35
+ import"./index-a76rekgs.js";
36
+ export {
37
+ resolveLegacyApplicationLogPath,
38
+ resolveKnowledgeEventsPath,
39
+ resolveKnowledgeCounterBaselinePath,
40
+ resolveHiveEventsPath,
41
+ recordKnowledgeEvent,
42
+ recordHiveKnowledgeEvent,
43
+ recomputeCounters,
44
+ readLegacyApplicationRecords,
45
+ readKnowledgeEvents,
46
+ readKnowledgeCounterRollups,
47
+ readHiveKnowledgeEvents,
48
+ newTraceId,
49
+ newEventId,
50
+ effectiveRetrievalOutcomes,
51
+ countViolationsInWindow,
52
+ countEntryViolationsInWindow,
53
+ countEntryContradictionsInWindow,
54
+ applyKnowledgeVerdictFeedback,
55
+ appendKnowledgeEvent,
56
+ appendHiveKnowledgeEvent,
57
+ _internals,
58
+ RECEIPT_EVENT_TYPES,
59
+ MAX_VIOLATION_TIMESTAMPS,
60
+ MAX_EVENT_LOG_ENTRIES,
61
+ KNOWLEDGE_EVENT_SCHEMA_VERSION
62
+ };
@@ -32,7 +32,9 @@ import {
32
32
  transactFile,
33
33
  transactKnowledge,
34
34
  wordBigrams
35
- } from "./index-f7nma02k.js";
35
+ } from "./index-xmarctsf.js";
36
+ import"./index-n1sptn1w.js";
37
+ import"./index-bfwt3abw.js";
36
38
  import"./index-9b7qp18e.js";
37
39
  import"./index-jtqkh8jf.js";
38
40
  import"./index-3naa2ajc.js";