@a-company/paradigm 3.44.0 → 5.3.3
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/dist/{accept-orchestration-ZUWQUHSK.js → accept-orchestration-GX2YRWM4.js} +5 -5
- package/dist/{add-VSPZ6FM4.js → add-FZRKEGH4.js} +1 -1
- package/dist/agent-HYKC2LAK.js +387 -0
- package/dist/agent-loader-SJPJJS33.js +36 -0
- package/dist/{agents-suggest-65SER5IS.js → agents-suggest-DNSYJ6IA.js} +1 -1
- package/dist/{aggregate-SV3VGEIL.js → aggregate-H57K7PNV.js} +1 -1
- package/dist/{assess-UHBDYIK7.js → assess-4WVXZLZQ.js} +2 -2
- package/dist/{auto-24ICVUH4.js → auto-QFS5NHQU.js} +1 -1
- package/dist/{beacon-3SJV4DAP.js → beacon-KXZXYQHX.js} +1 -1
- package/dist/{calibration-WWHK73WU.js → calibration-V46G7JTY.js} +2 -2
- package/dist/{check-OLI6AUS6.js → check-OWAIWV23.js} +1 -1
- package/dist/{chunk-RP6TZYGE.js → chunk-2IO7JAG2.js} +1 -1
- package/dist/chunk-2T6BTYBN.js +712 -0
- package/dist/{chunk-CDMAMDSG.js → chunk-5VKJBNJL.js} +13 -5
- package/dist/{chunk-KB4XJWE3.js → chunk-6N3JTACN.js} +98 -437
- package/dist/chunk-7N7GSU6K.js +34 -0
- package/dist/chunk-A2L4TSLZ.js +526 -0
- package/dist/{chunk-P7XSBJE3.js → chunk-ABVQGRF7.js} +1 -1
- package/dist/{chunk-HIKKOCXY.js → chunk-EI32ZBE6.js} +1 -1
- package/dist/{chunk-QIOCFXDQ.js → chunk-EKGMAM62.js} +1 -1
- package/dist/chunk-EZ3GOCYC.js +132 -0
- package/dist/chunk-GGMI6C2L.js +1075 -0
- package/dist/{chunk-DS5QY37M.js → chunk-GTR2TBIJ.js} +247 -15
- package/dist/{chunk-QDXI2DHR.js → chunk-J2JEQRT3.js} +1 -1
- package/dist/{chunk-AKIMFN6I.js → chunk-JASGXLK3.js} +2 -2
- package/dist/chunk-KVDYJLTC.js +121 -0
- package/dist/{chunk-J4E6K5MG.js → chunk-LSRABQIY.js} +25 -1
- package/dist/chunk-MCMOGQMU.js +145 -0
- package/dist/{chunk-ZXMDA7VB.js → chunk-PDX44BCA.js} +1 -6
- package/dist/{chunk-SOBTKFSP.js → chunk-S2HO5MLR.js} +5 -0
- package/dist/{chunk-2SKXFXIT.js → chunk-S3ORKP3V.js} +10 -15
- package/dist/{chunk-ZMQA6SCO.js → chunk-S6MZ2IEX.js} +628 -228
- package/dist/chunk-TAIJOFOE.js +124 -0
- package/dist/{chunk-FS3WTUHY.js → chunk-TXESEO7Y.js} +6 -6
- package/dist/{chunk-7COU5S2Z.js → chunk-VL67H5IC.js} +1 -1
- package/dist/{chunk-QWA26UNO.js → chunk-WQITYKHM.js} +7 -7
- package/dist/{chunk-MW5DMGBB.js → chunk-YMDLDELF.js} +114 -55
- package/dist/{claude-63ISJAZK.js → claude-FRRWJSTJ.js} +1 -1
- package/dist/{claude-cli-ABML5RHX.js → claude-cli-XJLK2X4L.js} +1 -1
- package/dist/{claude-code-JRLMRPTO.js → claude-code-HTBA4XRB.js} +1 -1
- package/dist/{claude-code-teams-CAJBEFIZ.js → claude-code-teams-T4SP24MD.js} +1 -1
- package/dist/{conductor-HLWYWUVH.js → conductor-PGPDVIVE.js} +1 -1
- package/dist/{config-schema-3YNIFJCJ.js → config-schema-EA4XALGG.js} +4 -2
- package/dist/{constellation-FAGT45TU.js → constellation-A26CCGQS.js} +1 -1
- package/dist/{context-audit-557EO6PK.js → context-audit-RLO3ETRP.js} +8 -5
- package/dist/{cost-XEBADYFT.js → cost-BGM32XJU.js} +1 -1
- package/dist/{cost-UD3WPEKZ.js → cost-VI46A4XL.js} +1 -1
- package/dist/{cursor-cli-QUOOF2N4.js → cursor-cli-JVEZGHWQ.js} +1 -1
- package/dist/{cursorrules-3TKZ4E4R.js → cursorrules-HLIKJJZT.js} +1 -1
- package/dist/decision-loader-WWCLIQPJ.js +20 -0
- package/dist/{delete-RRK4RL6Y.js → delete-KBRPQLPC.js} +2 -2
- package/dist/{diff-IP5CIARP.js → diff-RQLLNAFI.js} +5 -5
- package/dist/{discipline-5F5OVTXB.js → discipline-FA4OZXIS.js} +1 -1
- package/dist/{dist-UXWV4OKX.js → dist-34NA5RS5.js} +1 -1
- package/dist/{dist-5QE2BB2B-X6DYVSUL.js → dist-5QE2BB2B-5S3T6Y3T.js} +1 -1
- package/dist/{dist-CM3MVWWW.js → dist-77JDTVAY.js} +1 -0
- package/dist/{dist-POMVY6WP.js → dist-QK4SQAK7.js} +1 -1
- package/dist/{dist-3RVKEJRT.js → dist-TA6LSC2Q.js} +1 -1
- package/dist/docs-LVLRPBAW.js +155 -0
- package/dist/docs-PBZB7LYP.js +89 -0
- package/dist/{doctor-GKZJU7QG.js → doctor-ULBOHEIC.js} +3 -3
- package/dist/{drift-YGT4LJ7Q.js → drift-R5NRKFHI.js} +1 -1
- package/dist/{echo-A6HD5UP7.js → echo-O2LY7CC2.js} +1 -1
- package/dist/{edit-4CLNN5JG.js → edit-R2HNLMOG.js} +2 -2
- package/dist/event-25OJKDCE.js +31 -0
- package/dist/{export-T7CMMJIB.js → export-IWVL7XLF.js} +1 -1
- package/dist/{flow-UFMPVOEM.js → flow-CRRVV3O3.js} +2 -2
- package/dist/{global-HHUJSBG5.js → global-3NG5JXUB.js} +1 -1
- package/dist/graduate-USAWGBJM.js +160 -0
- package/dist/{graph-YYUXI3F7.js → graph-VHUMAAS6.js} +2 -2
- package/dist/{graph-server-ZPXRSGCW.js → graph-server-YL22VBBN.js} +1 -1
- package/dist/{habits-RG5SVKXP.js → habits-OL5NGPXO.js} +3 -3
- package/dist/{history-CETCSUCP.js → history-WOWC573W.js} +1 -1
- package/dist/{hooks-TCUHQMPF.js → hooks-HFWSCGPV.js} +2 -2
- package/dist/index.js +307 -184
- package/dist/{integrity-MK2OP5TA.js → integrity-IHO4FZTS.js} +1 -1
- package/dist/{integrity-checker-J7YXRTBT.js → integrity-checker-PSKJA5SB.js} +1 -0
- package/dist/journal-loader-5EYSBFFY.js +18 -0
- package/dist/{lint-HYWGS3JJ.js → lint-K6CJGGPH.js} +1 -1
- package/dist/{list-IUCYPGMK.js → list-4YK7QKFF.js} +1 -1
- package/dist/{list-BTLFHSRC.js → list-ENR7Q4CR.js} +2 -2
- package/dist/{lore-loader-VTEEZDX3.js → lore-loader-7NO6N6FT.js} +4 -1
- package/dist/{lore-server-NOOAHKJX.js → lore-server-UNJY5KC3.js} +1 -1
- package/dist/{manual-AFJ2J2V3.js → manual-G6FISID5.js} +1 -1
- package/dist/mcp.js +3954 -479
- package/dist/{migrate-FQVGQNXZ.js → migrate-LS45DNEV.js} +2 -2
- package/dist/{migrate-assessments-JP6Q5KME.js → migrate-assessments-RGH4O6IX.js} +2 -2
- package/dist/nomination-engine-Q4XSXFKT.js +40 -0
- package/dist/notebook-YWIYGEHV.js +155 -0
- package/dist/{orchestrate-A226N6FC.js → orchestrate-XZA33TJC.js} +5 -5
- package/dist/peers-DEOUIZM6.js +82 -0
- package/dist/persona-UHAHIVST.js +390 -0
- package/dist/{pipeline-3G2FRAKM.js → pipeline-L4HCSBGN.js} +1 -1
- package/dist/{platform-server-KHL6ZPPN.js → platform-server-PMD57BEG.js} +264 -18
- package/dist/{plugin-update-checker-HMRPGY5Z.js → plugin-update-checker-ELOEEQYS.js} +1 -0
- package/dist/{portal-check-FF5EKZE5.js → portal-check-NPYGII2D.js} +2 -2
- package/dist/{portal-compliance-VU4NIFEN.js → portal-compliance-J7DGAPFX.js} +2 -2
- package/dist/{probe-7JK7IDNI.js → probe-MHL5HQZ2.js} +3 -3
- package/dist/{promote-XO63XMAN.js → promote-F6ZYZZAL.js} +2 -2
- package/dist/{providers-YNFSL6HK.js → providers-GK7PB2OL.js} +2 -2
- package/dist/{quiz-I75NU2QQ.js → quiz-M66SC7F7.js} +1 -1
- package/dist/{record-46CLR4OG.js → record-RA4WR2BO.js} +2 -2
- package/dist/{reindex-WIJMCJ4A.js → reindex-HRA2AUS6.js} +3 -2
- package/dist/{remember-4EUZKIIB.js → remember-HBWJ655S.js} +1 -1
- package/dist/{retag-KC4JVRLE.js → retag-3OLCVDEQ.js} +2 -2
- package/dist/{review-Q7M4CRB5.js → review-27ATYTD2.js} +2 -2
- package/dist/review-57QMURZV.js +334 -0
- package/dist/{ripple-RI3LOT6R.js → ripple-JPBXP5I3.js} +1 -1
- package/dist/{sentinel-UOIGJWHH.js → sentinel-4XIG4STA.js} +2 -2
- package/dist/{sentinel-bridge-APDXYAZS.js → sentinel-bridge-MDUXTQRL.js} +2 -2
- package/dist/{serve-JVXSRSUB.js → serve-FLTFTM3P.js} +2 -2
- package/dist/{serve-22A4XOIG.js → serve-INL7SNBK.js} +2 -2
- package/dist/{serve-2YJ6D2Y6.js → serve-KBSE36PL.js} +4 -4
- package/dist/{server-JV6UFGWZ.js → server-54SKYFFY.js} +2 -2
- package/dist/{server-RDLQ3DK7.js → server-XUOIO7E6.js} +1 -1
- package/dist/{setup-YNZJQLW7.js → setup-EDS27WUR.js} +1 -1
- package/dist/{setup-M2ZKLKNN.js → setup-KO5AFC4K.js} +2 -2
- package/dist/{shift-LNMKFYLR.js → shift-VFG23DLA.js} +16 -16
- package/dist/{show-P7GYO43X.js → show-5PV5KFJE.js} +2 -2
- package/dist/{show-PKZMYKRN.js → show-NQKYX6WQ.js} +1 -1
- package/dist/{snapshot-Y3COXK4T.js → snapshot-BK4RBPCG.js} +1 -1
- package/dist/{spawn-SSXZX45U.js → spawn-AW6GDECS.js} +3 -3
- package/dist/{status-KLHALGW4.js → status-WGIAQODY.js} +1 -1
- package/dist/{summary-5NQNOD3F.js → summary-NIRABMF5.js} +2 -2
- package/dist/{sweep-EZU3GU6S.js → sweep-QMHNSIY5.js} +2 -2
- package/dist/{switch-WYUMVNA5.js → switch-6EJPZDIA.js} +1 -1
- package/dist/{symphony-EYRGGVNE.js → symphony-4OCY36AI.js} +350 -29
- package/dist/{symphony-QWOEKZMC.js → symphony-B75X2MME.js} +20 -2
- package/dist/symphony-peers-2ZQYLRNI.js +34 -0
- package/dist/symphony-peers-OL7F6M5S.js +121 -0
- package/dist/symphony-relay-UJYUXN65.js +710 -0
- package/dist/{sync-ZM4Q3R4U.js → sync-VEHUH4OA.js} +3 -3
- package/dist/{sync-llms-JIPP3XX4.js → sync-llms-YHCFIE6X.js} +2 -2
- package/dist/{task-loader-7M2FCBX6.js → task-loader-LDYWQSLM.js} +1 -0
- package/dist/{team-HGLJXWQG.js → team-7HG7XK5C.js} +6 -6
- package/dist/{test-WTR5Q33E.js → test-566CP5KC.js} +1 -1
- package/dist/{thread-3WM7KKID.js → thread-N754I4D5.js} +1 -1
- package/dist/{timeline-ANC7LVDL.js → timeline-M3CICQFE.js} +2 -2
- package/dist/{triage-IZ4MDYNB.js → triage-HHYGT3HY.js} +1 -1
- package/dist/{tutorial-GC6QL4US.js → tutorial-KD22SUNO.js} +1 -1
- package/dist/university-content/courses/.purpose +66 -0
- package/dist/university-content/courses/para-401.json +146 -0
- package/dist/university-content/courses/para-501.json +151 -0
- package/dist/university-content/courses/para-601.json +608 -0
- package/dist/university-content/plsat/.purpose +6 -0
- package/dist/university-content/plsat/v2.0.json +2 -2
- package/dist/university-content/plsat/v3.0.json +563 -3
- package/dist/university-content/reference.json +91 -0
- package/dist/{upgrade-ANX3LVSA.js → upgrade-H5PF32BW.js} +2 -2
- package/dist/{validate-GD5XWILV.js → validate-CNKEKO6A.js} +1 -1
- package/dist/{validate-ITC5D6QG.js → validate-MB5ULIHS.js} +1 -1
- package/dist/{validate-ZVPNN4FL.js → validate-QH3LADM6.js} +1 -1
- package/dist/{watch-X64UK7K4.js → watch-2TKP5PVL.js} +3 -3
- package/dist/{watch-ERBEJUJW.js → watch-ZF4ML6CD.js} +2 -2
- package/dist/{wisdom-L2WC7J62.js → wisdom-AATMGNFA.js} +1 -1
- package/dist/work-log-loader-5L45XNYZ.js +14 -0
- package/dist/{workspace-UIUTHZTD.js → workspace-6E6OSRNU.js} +4 -4
- package/package.json +1 -1
- package/platform-ui/dist/assets/DocsSection-ByAgPzWV.js +1 -0
- package/platform-ui/dist/assets/DocsSection-CjdO6R-u.css +1 -0
- package/platform-ui/dist/assets/{GitSection-BD3Ze06e.js → GitSection-BLovj9yT.js} +1 -1
- package/platform-ui/dist/assets/{GraphSection-SglITfSs.js → GraphSection-C5PCPUFl.js} +1 -1
- package/platform-ui/dist/assets/{LoreSection-bR5Km4Fd.js → LoreSection-BftejTla.js} +1 -1
- package/platform-ui/dist/assets/{SentinelSection-QSpAZArG.js → SentinelSection-CnYcasN7.js} +1 -1
- package/platform-ui/dist/assets/{SymphonySection-CobYJgvg.js → SymphonySection-BpmqCHeK.js} +1 -1
- package/platform-ui/dist/assets/{index-DbxeSMkV.js → index-G9JnWEs_.js} +10 -10
- package/platform-ui/dist/index.html +1 -1
- package/dist/dist-PSF5CP4I.js +0 -7294
|
@@ -0,0 +1,1075 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
init_agent_loader,
|
|
4
|
+
loadAgentProfile,
|
|
5
|
+
loadAllAgentProfiles,
|
|
6
|
+
saveAgentProfile
|
|
7
|
+
} from "./chunk-A2L4TSLZ.js";
|
|
8
|
+
import {
|
|
9
|
+
init_journal_loader,
|
|
10
|
+
journal_loader_exports
|
|
11
|
+
} from "./chunk-MCMOGQMU.js";
|
|
12
|
+
import {
|
|
13
|
+
__esm,
|
|
14
|
+
__export,
|
|
15
|
+
__require,
|
|
16
|
+
__toCommonJS
|
|
17
|
+
} from "./chunk-7N7GSU6K.js";
|
|
18
|
+
|
|
19
|
+
// ../paradigm-mcp/src/utils/event-stream.ts
|
|
20
|
+
import * as fs from "fs";
|
|
21
|
+
import * as path from "path";
|
|
22
|
+
function getStreamPath(rootDir) {
|
|
23
|
+
return path.join(rootDir, EVENTS_DIR, STREAM_FILE);
|
|
24
|
+
}
|
|
25
|
+
function generateEventId() {
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
const rand = Math.floor(Math.random() * 9999).toString().padStart(4, "0");
|
|
28
|
+
return `ev-${now}-${rand}`;
|
|
29
|
+
}
|
|
30
|
+
function emitEvent(rootDir, event) {
|
|
31
|
+
const full = {
|
|
32
|
+
id: generateEventId(),
|
|
33
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
34
|
+
...event
|
|
35
|
+
};
|
|
36
|
+
memoryStream.push(full);
|
|
37
|
+
if (memoryStream.length > DEFAULT_MAX_EVENTS) {
|
|
38
|
+
memoryStream = memoryStream.slice(-DEFAULT_MAX_EVENTS);
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const dir = path.join(rootDir, EVENTS_DIR);
|
|
42
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
43
|
+
const streamPath = getStreamPath(rootDir);
|
|
44
|
+
fs.appendFileSync(streamPath, JSON.stringify(full) + "\n", "utf8");
|
|
45
|
+
pruneIfNeeded(streamPath);
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
return full;
|
|
49
|
+
}
|
|
50
|
+
function pruneIfNeeded(streamPath) {
|
|
51
|
+
try {
|
|
52
|
+
const stat = fs.statSync(streamPath);
|
|
53
|
+
if (stat.size > 512 * 1024) {
|
|
54
|
+
const content = fs.readFileSync(streamPath, "utf8");
|
|
55
|
+
const lines = content.trim().split("\n");
|
|
56
|
+
if (lines.length > DEFAULT_MAX_EVENTS) {
|
|
57
|
+
const kept = lines.slice(-DEFAULT_MAX_EVENTS);
|
|
58
|
+
fs.writeFileSync(streamPath, kept.join("\n") + "\n", "utf8");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function queryEvents(rootDir, opts) {
|
|
65
|
+
let events = loadEventsFromDisk(rootDir);
|
|
66
|
+
if (opts?.type) events = events.filter((e) => e.type === opts.type);
|
|
67
|
+
if (opts?.source) events = events.filter((e) => e.source === opts.source);
|
|
68
|
+
if (opts?.symbol) events = events.filter((e) => e.symbols?.includes(opts.symbol));
|
|
69
|
+
if (opts?.agent) events = events.filter((e) => e.agent === opts.agent);
|
|
70
|
+
if (opts?.since) events = events.filter((e) => e.timestamp >= opts.since);
|
|
71
|
+
events.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
|
|
72
|
+
if (opts?.limit) events = events.slice(0, opts.limit);
|
|
73
|
+
return events;
|
|
74
|
+
}
|
|
75
|
+
function loadEventsFromDisk(rootDir) {
|
|
76
|
+
const streamPath = getStreamPath(rootDir);
|
|
77
|
+
if (!fs.existsSync(streamPath)) return [...memoryStream];
|
|
78
|
+
try {
|
|
79
|
+
const content = fs.readFileSync(streamPath, "utf8");
|
|
80
|
+
const events = content.trim().split("\n").filter((line) => line.trim()).map((line) => {
|
|
81
|
+
try {
|
|
82
|
+
return JSON.parse(line);
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}).filter((e) => e !== null);
|
|
87
|
+
return events;
|
|
88
|
+
} catch {
|
|
89
|
+
return [...memoryStream];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function scoreEventForAgent(event, agentId, attention) {
|
|
93
|
+
let symbolMatch = 0;
|
|
94
|
+
let pathMatch = 0;
|
|
95
|
+
let conceptMatch = 0;
|
|
96
|
+
let signalMatch = 0;
|
|
97
|
+
if (attention.symbols?.length && event.symbols?.length) {
|
|
98
|
+
for (const pattern of attention.symbols) {
|
|
99
|
+
for (const symbol of event.symbols) {
|
|
100
|
+
if (matchGlob(pattern, symbol)) {
|
|
101
|
+
symbolMatch = Math.max(symbolMatch, 1);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (attention.paths?.length && event.path) {
|
|
107
|
+
for (const pattern of attention.paths) {
|
|
108
|
+
if (matchGlob(pattern, event.path)) {
|
|
109
|
+
pathMatch = 1;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (attention.concepts?.length) {
|
|
115
|
+
const eventText = [
|
|
116
|
+
event.context || "",
|
|
117
|
+
...event.keywords || [],
|
|
118
|
+
event.type
|
|
119
|
+
].join(" ").toLowerCase();
|
|
120
|
+
let matched = 0;
|
|
121
|
+
for (const concept of attention.concepts) {
|
|
122
|
+
if (eventText.includes(concept.toLowerCase())) {
|
|
123
|
+
matched++;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (attention.concepts.length > 0) {
|
|
127
|
+
conceptMatch = matched / attention.concepts.length;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (attention.signals?.length) {
|
|
131
|
+
for (const signal of attention.signals) {
|
|
132
|
+
if (signal.type === event.type) {
|
|
133
|
+
signalMatch = 1;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const dimensions = [symbolMatch, pathMatch, conceptMatch, signalMatch].sort((a, b) => b - a);
|
|
139
|
+
const score = dimensions[0] * 0.5 + dimensions[1] * 0.2 + dimensions[2] * 0.15 + dimensions[3] * 0.15;
|
|
140
|
+
const threshold = attention.threshold ?? 0.6;
|
|
141
|
+
return {
|
|
142
|
+
agentId,
|
|
143
|
+
score,
|
|
144
|
+
breakdown: { symbolMatch, pathMatch, conceptMatch, signalMatch },
|
|
145
|
+
shouldNominate: score >= threshold,
|
|
146
|
+
quietReason: score < threshold ? "below-threshold" : void 0
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function matchGlob(pattern, value) {
|
|
150
|
+
if (pattern === value) return true;
|
|
151
|
+
const regex = pattern.replace(/\*\*/g, "\xA7\xA7").replace(/\*/g, "[^/]*").replace(/§§/g, ".*");
|
|
152
|
+
try {
|
|
153
|
+
return new RegExp(`^${regex}$`).test(value);
|
|
154
|
+
} catch {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
var EVENTS_DIR, STREAM_FILE, DEFAULT_MAX_EVENTS, memoryStream;
|
|
159
|
+
var init_event_stream = __esm({
|
|
160
|
+
"../paradigm-mcp/src/utils/event-stream.ts"() {
|
|
161
|
+
"use strict";
|
|
162
|
+
EVENTS_DIR = ".paradigm/events";
|
|
163
|
+
STREAM_FILE = "stream.jsonl";
|
|
164
|
+
DEFAULT_MAX_EVENTS = 1e3;
|
|
165
|
+
memoryStream = [];
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// ../paradigm-mcp/src/types/data-policy.ts
|
|
170
|
+
var DEFAULT_DATA_POLICY;
|
|
171
|
+
var init_data_policy = __esm({
|
|
172
|
+
"../paradigm-mcp/src/types/data-policy.ts"() {
|
|
173
|
+
"use strict";
|
|
174
|
+
DEFAULT_DATA_POLICY = {
|
|
175
|
+
version: "1.0",
|
|
176
|
+
default_ring: "project-locked",
|
|
177
|
+
observation: {
|
|
178
|
+
allow: ["src/**", ".paradigm/**", "portal.yaml"],
|
|
179
|
+
deny: [".env*", "**/*.key", "**/*.pem", "**/secrets/**"]
|
|
180
|
+
},
|
|
181
|
+
streams: {
|
|
182
|
+
work_log: {
|
|
183
|
+
ring: "project-locked",
|
|
184
|
+
allow_content: ["file_paths", "symbol_names", "outcome"],
|
|
185
|
+
deny_content: ["code_snippets", "file_contents", "diff_content"]
|
|
186
|
+
},
|
|
187
|
+
learning_journal: {
|
|
188
|
+
ring: "user-scoped",
|
|
189
|
+
allow_content: ["pattern_descriptions", "confidence_adjustments", "approach_descriptions"],
|
|
190
|
+
deny_content: ["code_snippets", "file_contents", "symbol_names_with_context"],
|
|
191
|
+
redaction: [
|
|
192
|
+
{ pattern: "\\b[A-Z_]{2,}_KEY\\b" },
|
|
193
|
+
{ pattern: "password|secret|token" }
|
|
194
|
+
]
|
|
195
|
+
},
|
|
196
|
+
team_decisions: {
|
|
197
|
+
ring: "project-locked",
|
|
198
|
+
allow_content: ["rationale", "alternatives", "symbol_references"],
|
|
199
|
+
deny_content: ["implementation_details"]
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
upstream: {
|
|
203
|
+
ring: "creator-upstream",
|
|
204
|
+
allowed: ["task_type", "outcome", "helpfulness", "duration_bucket", "error_category"],
|
|
205
|
+
denied: ["code_of_any_kind", "file_paths", "symbol_names", "conversation_content", "user_identity"]
|
|
206
|
+
},
|
|
207
|
+
network: {
|
|
208
|
+
ring: "network-public",
|
|
209
|
+
opt_in: false,
|
|
210
|
+
if_opted_in: ["aggregated_task_success_rates", "anonymized_pattern_frequency"]
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// ../paradigm-mcp/src/utils/data-policy-loader.ts
|
|
217
|
+
import * as fs2 from "fs";
|
|
218
|
+
import * as path2 from "path";
|
|
219
|
+
import * as yaml from "js-yaml";
|
|
220
|
+
function loadDataPolicy(rootDir) {
|
|
221
|
+
const filePath = path2.join(rootDir, POLICY_FILE);
|
|
222
|
+
if (!fs2.existsSync(filePath)) {
|
|
223
|
+
return { ...DEFAULT_DATA_POLICY };
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const content = fs2.readFileSync(filePath, "utf8");
|
|
227
|
+
const userPolicy = yaml.load(content);
|
|
228
|
+
return mergePolicy(DEFAULT_DATA_POLICY, userPolicy);
|
|
229
|
+
} catch {
|
|
230
|
+
return { ...DEFAULT_DATA_POLICY };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function mergePolicy(base, override) {
|
|
234
|
+
const merged = { ...base };
|
|
235
|
+
if (override.version) merged.version = override.version;
|
|
236
|
+
if (override.default_ring) merged.default_ring = override.default_ring;
|
|
237
|
+
if (override.observation) {
|
|
238
|
+
merged.observation = {
|
|
239
|
+
allow: override.observation.allow || base.observation?.allow,
|
|
240
|
+
deny: [
|
|
241
|
+
...base.observation?.deny || [],
|
|
242
|
+
...override.observation.deny || []
|
|
243
|
+
].filter((v, i, a) => a.indexOf(v) === i)
|
|
244
|
+
// deduplicate
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
if (override.streams) {
|
|
248
|
+
merged.streams = { ...base.streams };
|
|
249
|
+
for (const key of ["work_log", "learning_journal", "team_decisions"]) {
|
|
250
|
+
if (override.streams[key]) {
|
|
251
|
+
merged.streams[key] = {
|
|
252
|
+
...base.streams?.[key],
|
|
253
|
+
...override.streams[key],
|
|
254
|
+
deny_content: [
|
|
255
|
+
...base.streams?.[key]?.deny_content || [],
|
|
256
|
+
...override.streams[key]?.deny_content || []
|
|
257
|
+
].filter((v, i, a) => a.indexOf(v) === i)
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (override.upstream) merged.upstream = { ...base.upstream, ...override.upstream };
|
|
263
|
+
if (override.network) merged.network = { ...base.network, ...override.network };
|
|
264
|
+
if (override.agent_overrides) merged.agent_overrides = { ...base.agent_overrides, ...override.agent_overrides };
|
|
265
|
+
if (override.deployment) merged.deployment = { ...base.deployment, ...override.deployment };
|
|
266
|
+
return merged;
|
|
267
|
+
}
|
|
268
|
+
function canObservePath(policy, filePath, agentId) {
|
|
269
|
+
if (agentId && policy.agent_overrides?.[agentId]?.observation) {
|
|
270
|
+
const agentObs = policy.agent_overrides[agentId].observation;
|
|
271
|
+
if (agentObs.deny?.some((p) => matchGlob2(p, filePath))) return false;
|
|
272
|
+
}
|
|
273
|
+
if (policy.observation?.deny?.some((p) => matchGlob2(p, filePath))) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
if (policy.observation?.allow?.length) {
|
|
277
|
+
return policy.observation.allow.some((p) => matchGlob2(p, filePath));
|
|
278
|
+
}
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
function filterContent(content, policy, stream) {
|
|
282
|
+
const streamRules = policy.streams?.[stream];
|
|
283
|
+
if (!streamRules) return { filtered: content, redacted: [] };
|
|
284
|
+
const redacted = [];
|
|
285
|
+
let result = content;
|
|
286
|
+
if (streamRules.redaction) {
|
|
287
|
+
for (const pattern of streamRules.redaction) {
|
|
288
|
+
try {
|
|
289
|
+
const regex = new RegExp(pattern.pattern, "gi");
|
|
290
|
+
const matches = result.match(regex);
|
|
291
|
+
if (matches) {
|
|
292
|
+
redacted.push(...matches);
|
|
293
|
+
result = result.replace(regex, pattern.replacement || "[REDACTED]");
|
|
294
|
+
}
|
|
295
|
+
} catch {
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return { filtered: result, redacted };
|
|
300
|
+
}
|
|
301
|
+
function matchGlob2(pattern, value) {
|
|
302
|
+
if (pattern === value) return true;
|
|
303
|
+
const regex = pattern.replace(/\*\*/g, "\xA7\xA7").replace(/\*/g, "[^/]*").replace(/§§/g, ".*");
|
|
304
|
+
try {
|
|
305
|
+
return new RegExp(`^${regex}$`).test(value);
|
|
306
|
+
} catch {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
var POLICY_FILE;
|
|
311
|
+
var init_data_policy_loader = __esm({
|
|
312
|
+
"../paradigm-mcp/src/utils/data-policy-loader.ts"() {
|
|
313
|
+
"use strict";
|
|
314
|
+
init_data_policy();
|
|
315
|
+
POLICY_FILE = ".paradigm/data-policy.yaml";
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// ../paradigm-mcp/src/utils/notebook-loader.ts
|
|
320
|
+
var notebook_loader_exports = {};
|
|
321
|
+
__export(notebook_loader_exports, {
|
|
322
|
+
addNotebookEntry: () => addNotebookEntry,
|
|
323
|
+
incrementApplied: () => incrementApplied,
|
|
324
|
+
loadNotebookEntries: () => loadNotebookEntries,
|
|
325
|
+
promoteFromLore: () => promoteFromLore,
|
|
326
|
+
searchNotebooks: () => searchNotebooks
|
|
327
|
+
});
|
|
328
|
+
import * as fs3 from "fs";
|
|
329
|
+
import * as path3 from "path";
|
|
330
|
+
import * as os from "os";
|
|
331
|
+
import * as yaml2 from "js-yaml";
|
|
332
|
+
function loadNotebookEntries(agentId, rootDir, filter) {
|
|
333
|
+
const entries = /* @__PURE__ */ new Map();
|
|
334
|
+
const globalDir = path3.join(GLOBAL_NOTEBOOKS_DIR, agentId);
|
|
335
|
+
loadEntriesFromDir(globalDir, entries);
|
|
336
|
+
const projectDir = path3.join(rootDir, PROJECT_NOTEBOOKS_DIR, agentId);
|
|
337
|
+
loadEntriesFromDir(projectDir, entries);
|
|
338
|
+
let result = Array.from(entries.values());
|
|
339
|
+
if (filter?.concepts && filter.concepts.length > 0) {
|
|
340
|
+
const conceptSet = new Set(filter.concepts.map((c) => c.toLowerCase()));
|
|
341
|
+
result = result.filter(
|
|
342
|
+
(e) => e.concepts.some((c) => conceptSet.has(c.toLowerCase()))
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
if (filter?.tags && filter.tags.length > 0) {
|
|
346
|
+
const tagSet = new Set(filter.tags.map((t) => t.toLowerCase()));
|
|
347
|
+
result = result.filter(
|
|
348
|
+
(e) => e.tags.some((t) => tagSet.has(t.toLowerCase()))
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
return result.sort((a, b) => b.appliedCount - a.appliedCount);
|
|
352
|
+
}
|
|
353
|
+
function loadEntriesFromDir(dir, entries) {
|
|
354
|
+
if (!fs3.existsSync(dir)) return;
|
|
355
|
+
try {
|
|
356
|
+
const files = fs3.readdirSync(dir).filter(
|
|
357
|
+
(f) => f.startsWith(NOTEBOOK_PREFIX) && f.endsWith(NOTEBOOK_EXT)
|
|
358
|
+
);
|
|
359
|
+
for (const file of files) {
|
|
360
|
+
try {
|
|
361
|
+
const content = fs3.readFileSync(path3.join(dir, file), "utf-8");
|
|
362
|
+
const entry = yaml2.load(content);
|
|
363
|
+
if (entry?.id) {
|
|
364
|
+
entries.set(entry.id, entry);
|
|
365
|
+
}
|
|
366
|
+
} catch {
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
} catch {
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function searchNotebooks(agentId, query, rootDir) {
|
|
373
|
+
const all = loadNotebookEntries(agentId, rootDir);
|
|
374
|
+
const q = query.toLowerCase();
|
|
375
|
+
return all.filter(
|
|
376
|
+
(e) => e.context.toLowerCase().includes(q) || e.snippet.toLowerCase().includes(q) || e.concepts.some((c) => c.toLowerCase().includes(q)) || e.tags.some((t) => t.toLowerCase().includes(q))
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
function addNotebookEntry(agentId, entry, scope, rootDir) {
|
|
380
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
381
|
+
const conceptSlug = (entry.concepts[0] || "entry").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
|
|
382
|
+
const timestamp = Date.now().toString(36);
|
|
383
|
+
const id = `nb-${conceptSlug}-${timestamp}`;
|
|
384
|
+
const fullEntry = {
|
|
385
|
+
...entry,
|
|
386
|
+
id,
|
|
387
|
+
appliedCount: 0,
|
|
388
|
+
created: now,
|
|
389
|
+
updated: now
|
|
390
|
+
};
|
|
391
|
+
const dir = scope === "global" ? path3.join(GLOBAL_NOTEBOOKS_DIR, agentId) : path3.join(rootDir || process.cwd(), PROJECT_NOTEBOOKS_DIR, agentId);
|
|
392
|
+
if (!fs3.existsSync(dir)) {
|
|
393
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
394
|
+
}
|
|
395
|
+
const fileName = `${id}${NOTEBOOK_EXT}`;
|
|
396
|
+
const filePath = path3.join(dir, fileName);
|
|
397
|
+
const content = yaml2.dump(fullEntry, {
|
|
398
|
+
lineWidth: 120,
|
|
399
|
+
noRefs: true,
|
|
400
|
+
sortKeys: false
|
|
401
|
+
});
|
|
402
|
+
fs3.writeFileSync(filePath, content, "utf-8");
|
|
403
|
+
return { entry: fullEntry, filePath };
|
|
404
|
+
}
|
|
405
|
+
async function promoteFromLore(agentId, loreEntryId, rootDir, scope = "global") {
|
|
406
|
+
const { loadLoreEntry } = await import("./lore-loader-7NO6N6FT.js");
|
|
407
|
+
const loreEntry = await loadLoreEntry(rootDir, loreEntryId);
|
|
408
|
+
if (!loreEntry) return null;
|
|
409
|
+
const concepts = [];
|
|
410
|
+
if (loreEntry.symbols_touched) {
|
|
411
|
+
for (const sym of loreEntry.symbols_touched) {
|
|
412
|
+
const clean = sym.replace(/^[#$^!~]/, "").toLowerCase();
|
|
413
|
+
concepts.push(clean);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
let snippet = loreEntry.summary || "";
|
|
417
|
+
if (loreEntry.body) {
|
|
418
|
+
snippet += "\n\n" + loreEntry.body;
|
|
419
|
+
}
|
|
420
|
+
const provenance = {
|
|
421
|
+
source: "lore",
|
|
422
|
+
loreEntryId,
|
|
423
|
+
originProject: path3.basename(rootDir),
|
|
424
|
+
createdBy: agentId
|
|
425
|
+
};
|
|
426
|
+
return addNotebookEntry(
|
|
427
|
+
agentId,
|
|
428
|
+
{
|
|
429
|
+
context: loreEntry.title || `Promoted from ${loreEntryId}`,
|
|
430
|
+
snippet,
|
|
431
|
+
provenance,
|
|
432
|
+
confidence: loreEntry.confidence ?? 0.7,
|
|
433
|
+
concepts,
|
|
434
|
+
tags: loreEntry.tags || []
|
|
435
|
+
},
|
|
436
|
+
scope,
|
|
437
|
+
rootDir
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
function incrementApplied(agentId, entryId, rootDir) {
|
|
441
|
+
const projectDir = path3.join(rootDir, PROJECT_NOTEBOOKS_DIR, agentId);
|
|
442
|
+
const globalDir = path3.join(GLOBAL_NOTEBOOKS_DIR, agentId);
|
|
443
|
+
for (const dir of [projectDir, globalDir]) {
|
|
444
|
+
const filePath = path3.join(dir, `${entryId}${NOTEBOOK_EXT}`);
|
|
445
|
+
if (fs3.existsSync(filePath)) {
|
|
446
|
+
try {
|
|
447
|
+
const content = fs3.readFileSync(filePath, "utf-8");
|
|
448
|
+
const entry = yaml2.load(content);
|
|
449
|
+
if (entry) {
|
|
450
|
+
entry.appliedCount = (entry.appliedCount || 0) + 1;
|
|
451
|
+
entry.updated = (/* @__PURE__ */ new Date()).toISOString();
|
|
452
|
+
fs3.writeFileSync(filePath, yaml2.dump(entry, {
|
|
453
|
+
lineWidth: 120,
|
|
454
|
+
noRefs: true,
|
|
455
|
+
sortKeys: false
|
|
456
|
+
}), "utf-8");
|
|
457
|
+
return true;
|
|
458
|
+
}
|
|
459
|
+
} catch {
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
var GLOBAL_NOTEBOOKS_DIR, PROJECT_NOTEBOOKS_DIR, NOTEBOOK_PREFIX, NOTEBOOK_EXT;
|
|
466
|
+
var init_notebook_loader = __esm({
|
|
467
|
+
"../paradigm-mcp/src/utils/notebook-loader.ts"() {
|
|
468
|
+
"use strict";
|
|
469
|
+
GLOBAL_NOTEBOOKS_DIR = path3.join(os.homedir(), ".paradigm", "notebooks");
|
|
470
|
+
PROJECT_NOTEBOOKS_DIR = ".paradigm/notebooks";
|
|
471
|
+
NOTEBOOK_PREFIX = "nb-";
|
|
472
|
+
NOTEBOOK_EXT = ".yaml";
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// ../paradigm-mcp/src/utils/nomination-engine.ts
|
|
477
|
+
import * as fs4 from "fs";
|
|
478
|
+
import * as os2 from "os";
|
|
479
|
+
import * as path4 from "path";
|
|
480
|
+
function generateNominationId() {
|
|
481
|
+
const now = Date.now();
|
|
482
|
+
const rand = Math.floor(Math.random() * 9999).toString().padStart(4, "0");
|
|
483
|
+
return `nom-${now}-${rand}`;
|
|
484
|
+
}
|
|
485
|
+
function generateDebateId() {
|
|
486
|
+
const now = Date.now();
|
|
487
|
+
const rand = Math.floor(Math.random() * 9999).toString().padStart(4, "0");
|
|
488
|
+
return `dbt-${now}-${rand}`;
|
|
489
|
+
}
|
|
490
|
+
function processEvent(rootDir, event) {
|
|
491
|
+
const profiles = loadAllAgentProfiles(rootDir);
|
|
492
|
+
const policy = loadDataPolicy(rootDir);
|
|
493
|
+
const scores = [];
|
|
494
|
+
for (const profile of profiles) {
|
|
495
|
+
if (!profile.attention) continue;
|
|
496
|
+
if (event.path && !canObservePath(policy, event.path, profile.id)) {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
const score = scoreEventForAgent(event, profile.id, profile.attention);
|
|
500
|
+
if (score.shouldNominate) {
|
|
501
|
+
scores.push({ profile, score });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (scores.length === 0) {
|
|
505
|
+
return { nominations: [], debates: [] };
|
|
506
|
+
}
|
|
507
|
+
const recentNominations = loadNominations(rootDir, { since: new Date(Date.now() - 3e4).toISOString() });
|
|
508
|
+
const deduped = scores.filter(({ profile }) => {
|
|
509
|
+
const recent = recentNominations.find(
|
|
510
|
+
(n) => n.agent === profile.id && n.brief === generateBrief(profile, event, { ...scores.find((s) => s.profile.id === profile.id).score })
|
|
511
|
+
);
|
|
512
|
+
return !recent;
|
|
513
|
+
});
|
|
514
|
+
if (deduped.length === 0) {
|
|
515
|
+
return { nominations: [], debates: [] };
|
|
516
|
+
}
|
|
517
|
+
const nominations = deduped.map(({ profile, score }) => {
|
|
518
|
+
const urgency = deriveUrgency(event, score);
|
|
519
|
+
const type = deriveNominationType(profile, event);
|
|
520
|
+
return {
|
|
521
|
+
id: generateNominationId(),
|
|
522
|
+
agent: profile.id,
|
|
523
|
+
relevance: score.score,
|
|
524
|
+
urgency,
|
|
525
|
+
type,
|
|
526
|
+
brief: generateBrief(profile, event, score),
|
|
527
|
+
triggered_by: [event.id],
|
|
528
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
529
|
+
surfaced: false
|
|
530
|
+
};
|
|
531
|
+
});
|
|
532
|
+
persistNominations(rootDir, nominations);
|
|
533
|
+
const debates = detectDebates(rootDir, nominations);
|
|
534
|
+
if (debates.length > 0) {
|
|
535
|
+
persistDebates(rootDir, debates);
|
|
536
|
+
}
|
|
537
|
+
return { nominations, debates };
|
|
538
|
+
}
|
|
539
|
+
function deriveUrgency(event, score) {
|
|
540
|
+
if (event.severity === "critical") return "critical";
|
|
541
|
+
if (event.severity === "error") return "high";
|
|
542
|
+
if (event.type === "compliance-violation") return "high";
|
|
543
|
+
if (event.type === "error-encountered") return "high";
|
|
544
|
+
if (event.type === "gate-added" || event.type === "route-created") return "medium";
|
|
545
|
+
if (score.score >= 0.9) return "medium";
|
|
546
|
+
return "low";
|
|
547
|
+
}
|
|
548
|
+
function deriveNominationType(profile, event) {
|
|
549
|
+
const stance = profile.collaboration?.stance;
|
|
550
|
+
if (event.type === "compliance-violation" || event.type === "error-encountered") return "warning";
|
|
551
|
+
if (event.type === "gate-added" || event.type === "route-created") return "observation";
|
|
552
|
+
if (stance === "advisory") return "suggestion";
|
|
553
|
+
if (stance === "lead") return "suggestion";
|
|
554
|
+
if (stance === "observer") return "observation";
|
|
555
|
+
return "observation";
|
|
556
|
+
}
|
|
557
|
+
function generateBrief(profile, event, score) {
|
|
558
|
+
const role = profile.role || profile.id;
|
|
559
|
+
switch (event.type) {
|
|
560
|
+
case "gate-checked":
|
|
561
|
+
return `${role}: Gate check on ${event.symbols?.join(", ") || "route"} \u2014 verify gate coverage is complete`;
|
|
562
|
+
case "file-modified":
|
|
563
|
+
return `${role}: ${event.path || "File"} modified \u2014 review for ${profile.id === "security" ? "security implications" : profile.id === "tester" ? "test coverage" : profile.id === "reviewer" ? "code quality" : "consistency"}`;
|
|
564
|
+
case "compliance-violation":
|
|
565
|
+
return `${role}: Compliance violation detected \u2014 ${event.context || "check .purpose and portal.yaml coverage"}`;
|
|
566
|
+
case "route-created":
|
|
567
|
+
return `${role}: New route ${event.symbols?.join(", ") || ""} \u2014 ${profile.id === "security" ? "needs gate assignment in portal.yaml" : "review route structure"}`;
|
|
568
|
+
case "gate-added":
|
|
569
|
+
return `${role}: Gate ${event.symbols?.join(", ") || ""} added \u2014 ${profile.id === "security" ? "verify enforcement points" : "check downstream impact"}`;
|
|
570
|
+
case "decision-made":
|
|
571
|
+
return `${role}: Decision recorded \u2014 ${event.context?.slice(0, 80) || "review for alignment with project patterns"}`;
|
|
572
|
+
case "work-completed":
|
|
573
|
+
return `${role}: Work completed on ${event.symbols?.join(", ") || event.context?.slice(0, 40) || "task"} \u2014 review outcome`;
|
|
574
|
+
case "error-encountered":
|
|
575
|
+
return `${role}: Error detected \u2014 ${event.context?.slice(0, 80) || "investigate root cause"}`;
|
|
576
|
+
default: {
|
|
577
|
+
const matchDetail = score.breakdown.symbolMatch > 0 ? `symbol match on ${event.symbols?.join(", ") || "unknown"}` : score.breakdown.pathMatch > 0 ? `path ${event.path || "unknown"}` : event.context?.slice(0, 60) || event.type;
|
|
578
|
+
return `${role}: ${matchDetail}`;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
function detectDebates(rootDir, newNominations) {
|
|
583
|
+
if (newNominations.length < 2) return [];
|
|
584
|
+
const debates = [];
|
|
585
|
+
const byEvent = /* @__PURE__ */ new Map();
|
|
586
|
+
for (const nom of newNominations) {
|
|
587
|
+
for (const eventId of nom.triggered_by) {
|
|
588
|
+
const group = byEvent.get(eventId) || [];
|
|
589
|
+
group.push(nom);
|
|
590
|
+
byEvent.set(eventId, group);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
for (const [eventId, group] of byEvent) {
|
|
594
|
+
if (group.length < 2) continue;
|
|
595
|
+
const agents = new Set(group.map((n) => n.agent));
|
|
596
|
+
if (agents.size < 2) continue;
|
|
597
|
+
const types = new Set(group.map((n) => n.type));
|
|
598
|
+
const isConflicting = types.size > 1 && types.has("warning") && types.has("suggestion");
|
|
599
|
+
debates.push({
|
|
600
|
+
id: generateDebateId(),
|
|
601
|
+
topic: `Multiple agents responded to event ${eventId}`,
|
|
602
|
+
nominations: group.map((n) => n.id),
|
|
603
|
+
type: isConflicting ? "conflicting" : "complementary",
|
|
604
|
+
overlap_events: [eventId]
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
return debates;
|
|
608
|
+
}
|
|
609
|
+
function getNominationsPath(rootDir) {
|
|
610
|
+
return path4.join(rootDir, EVENTS_DIR2, NOMINATIONS_FILE);
|
|
611
|
+
}
|
|
612
|
+
function getDebatesPath(rootDir) {
|
|
613
|
+
return path4.join(rootDir, EVENTS_DIR2, DEBATES_FILE);
|
|
614
|
+
}
|
|
615
|
+
function persistNominations(rootDir, nominations) {
|
|
616
|
+
try {
|
|
617
|
+
const dir = path4.join(rootDir, EVENTS_DIR2);
|
|
618
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
619
|
+
const filePath = getNominationsPath(rootDir);
|
|
620
|
+
const lines = nominations.map((n) => JSON.stringify(n)).join("\n") + "\n";
|
|
621
|
+
fs4.appendFileSync(filePath, lines, "utf8");
|
|
622
|
+
pruneFile(filePath, MAX_NOMINATIONS);
|
|
623
|
+
} catch {
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function persistDebates(rootDir, debates) {
|
|
627
|
+
try {
|
|
628
|
+
const dir = path4.join(rootDir, EVENTS_DIR2);
|
|
629
|
+
fs4.mkdirSync(dir, { recursive: true });
|
|
630
|
+
const filePath = getDebatesPath(rootDir);
|
|
631
|
+
const lines = debates.map((d) => JSON.stringify(d)).join("\n") + "\n";
|
|
632
|
+
fs4.appendFileSync(filePath, lines, "utf8");
|
|
633
|
+
pruneFile(filePath, MAX_DEBATES);
|
|
634
|
+
} catch {
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
function pruneFile(filePath, maxLines) {
|
|
638
|
+
try {
|
|
639
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
640
|
+
const lines = content.trim().split("\n").filter((l) => l.trim());
|
|
641
|
+
if (lines.length > maxLines) {
|
|
642
|
+
const kept = lines.slice(-maxLines);
|
|
643
|
+
fs4.writeFileSync(filePath, kept.join("\n") + "\n", "utf8");
|
|
644
|
+
}
|
|
645
|
+
} catch {
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function loadNominations(rootDir, filter) {
|
|
649
|
+
const filePath = getNominationsPath(rootDir);
|
|
650
|
+
if (!fs4.existsSync(filePath)) return [];
|
|
651
|
+
try {
|
|
652
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
653
|
+
let nominations = content.trim().split("\n").filter((line) => line.trim()).map((line) => {
|
|
654
|
+
try {
|
|
655
|
+
return JSON.parse(line);
|
|
656
|
+
} catch {
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
}).filter((n) => n !== null);
|
|
660
|
+
if (filter?.agent) nominations = nominations.filter((n) => n.agent === filter.agent);
|
|
661
|
+
if (filter?.urgency) nominations = nominations.filter((n) => n.urgency === filter.urgency);
|
|
662
|
+
if (filter?.surfaced !== void 0) nominations = nominations.filter((n) => n.surfaced === filter.surfaced);
|
|
663
|
+
if (filter?.pending_only) nominations = nominations.filter((n) => !n.engaged);
|
|
664
|
+
if (filter?.since) nominations = nominations.filter((n) => n.timestamp >= filter.since);
|
|
665
|
+
nominations.sort((a, b) => b.timestamp.localeCompare(a.timestamp));
|
|
666
|
+
if (filter?.limit) nominations = nominations.slice(0, filter.limit);
|
|
667
|
+
return nominations;
|
|
668
|
+
} catch {
|
|
669
|
+
return [];
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
function loadDebates(rootDir) {
|
|
673
|
+
const filePath = getDebatesPath(rootDir);
|
|
674
|
+
if (!fs4.existsSync(filePath)) return [];
|
|
675
|
+
try {
|
|
676
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
677
|
+
return content.trim().split("\n").filter((line) => line.trim()).map((line) => {
|
|
678
|
+
try {
|
|
679
|
+
return JSON.parse(line);
|
|
680
|
+
} catch {
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
}).filter((d) => d !== null);
|
|
684
|
+
} catch {
|
|
685
|
+
return [];
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
function engageNomination(rootDir, nominationId, response) {
|
|
689
|
+
const filePath = getNominationsPath(rootDir);
|
|
690
|
+
if (!fs4.existsSync(filePath)) return false;
|
|
691
|
+
try {
|
|
692
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
693
|
+
const lines = content.trim().split("\n");
|
|
694
|
+
let found = false;
|
|
695
|
+
const updated = lines.map((line) => {
|
|
696
|
+
try {
|
|
697
|
+
const nom = JSON.parse(line);
|
|
698
|
+
if (nom.id === nominationId) {
|
|
699
|
+
nom.engaged = true;
|
|
700
|
+
nom.response = response;
|
|
701
|
+
found = true;
|
|
702
|
+
return JSON.stringify(nom);
|
|
703
|
+
}
|
|
704
|
+
return line;
|
|
705
|
+
} catch {
|
|
706
|
+
return line;
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
if (found) {
|
|
710
|
+
fs4.writeFileSync(filePath, updated.join("\n") + "\n", "utf8");
|
|
711
|
+
if (response === "accepted" || response === "dismissed") {
|
|
712
|
+
const nom = JSON.parse(lines.find((l) => {
|
|
713
|
+
try {
|
|
714
|
+
return JSON.parse(l).id === nominationId;
|
|
715
|
+
} catch {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
}));
|
|
719
|
+
const profile = loadAllAgentProfiles(rootDir).find((p) => p.id === nom.agent);
|
|
720
|
+
if (profile?.learning?.intrinsic?.feedback?.after_recommendation) {
|
|
721
|
+
emitEvent(rootDir, {
|
|
722
|
+
type: "work-completed",
|
|
723
|
+
source: "agent-action",
|
|
724
|
+
agent: nom.agent,
|
|
725
|
+
context: `Nomination ${nominationId} ${response} \u2014 feedback for learning`,
|
|
726
|
+
data: { nomination_id: nominationId, response }
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return found;
|
|
732
|
+
} catch {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function resolveDebate(rootDir, debateId, chosenNominationId, reason) {
|
|
737
|
+
const filePath = getDebatesPath(rootDir);
|
|
738
|
+
if (!fs4.existsSync(filePath)) return false;
|
|
739
|
+
try {
|
|
740
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
741
|
+
const lines = content.trim().split("\n");
|
|
742
|
+
let found = false;
|
|
743
|
+
const updated = lines.map((line) => {
|
|
744
|
+
try {
|
|
745
|
+
const debate = JSON.parse(line);
|
|
746
|
+
if (debate.id === debateId) {
|
|
747
|
+
debate.resolution = {
|
|
748
|
+
chosen: chosenNominationId,
|
|
749
|
+
reason,
|
|
750
|
+
resolved_by: "human",
|
|
751
|
+
resolved_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
752
|
+
};
|
|
753
|
+
found = true;
|
|
754
|
+
const nonChosen = debate.nominations.filter((id) => id !== chosenNominationId);
|
|
755
|
+
for (const loserId of nonChosen) {
|
|
756
|
+
const loserNom = loadNominations(rootDir).find((n) => n.id === loserId);
|
|
757
|
+
if (loserNom) {
|
|
758
|
+
emitEvent(rootDir, {
|
|
759
|
+
type: "work-completed",
|
|
760
|
+
source: "agent-action",
|
|
761
|
+
agent: loserNom.agent,
|
|
762
|
+
context: `Debate ${debateId} resolved \u2014 nomination ${loserId} not chosen`,
|
|
763
|
+
data: { debate_id: debateId, chosen: chosenNominationId, reason }
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
return JSON.stringify(debate);
|
|
768
|
+
}
|
|
769
|
+
return line;
|
|
770
|
+
} catch {
|
|
771
|
+
return line;
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
if (found) {
|
|
775
|
+
fs4.writeFileSync(filePath, updated.join("\n") + "\n", "utf8");
|
|
776
|
+
}
|
|
777
|
+
return found;
|
|
778
|
+
} catch {
|
|
779
|
+
return false;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function processPendingEvents(rootDir) {
|
|
783
|
+
const lastProcessedPath = path4.join(rootDir, EVENTS_DIR2, ".last-processed");
|
|
784
|
+
let lastProcessedId = "";
|
|
785
|
+
try {
|
|
786
|
+
if (fs4.existsSync(lastProcessedPath)) {
|
|
787
|
+
lastProcessedId = fs4.readFileSync(lastProcessedPath, "utf8").trim();
|
|
788
|
+
}
|
|
789
|
+
} catch {
|
|
790
|
+
}
|
|
791
|
+
const streamPath = path4.join(rootDir, EVENTS_DIR2, "stream.jsonl");
|
|
792
|
+
if (!fs4.existsSync(streamPath)) return { processed: 0, nominations: [] };
|
|
793
|
+
let events = [];
|
|
794
|
+
try {
|
|
795
|
+
const content = fs4.readFileSync(streamPath, "utf8");
|
|
796
|
+
events = content.trim().split("\n").filter((line) => line.trim()).map((line) => {
|
|
797
|
+
try {
|
|
798
|
+
return JSON.parse(line);
|
|
799
|
+
} catch {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
}).filter((e) => e !== null);
|
|
803
|
+
} catch {
|
|
804
|
+
return { processed: 0, nominations: [] };
|
|
805
|
+
}
|
|
806
|
+
let startIdx = 0;
|
|
807
|
+
if (lastProcessedId) {
|
|
808
|
+
const idx = events.findIndex((e) => e.id === lastProcessedId);
|
|
809
|
+
if (idx >= 0) startIdx = idx + 1;
|
|
810
|
+
}
|
|
811
|
+
const pending = events.slice(startIdx);
|
|
812
|
+
if (pending.length === 0) return { processed: 0, nominations: [] };
|
|
813
|
+
const allNominations = [];
|
|
814
|
+
const toProcess = pending.slice(0, 50);
|
|
815
|
+
for (const event of toProcess) {
|
|
816
|
+
const { nominations } = processEvent(rootDir, event);
|
|
817
|
+
allNominations.push(...nominations);
|
|
818
|
+
}
|
|
819
|
+
const lastEvent = toProcess[toProcess.length - 1];
|
|
820
|
+
try {
|
|
821
|
+
fs4.mkdirSync(path4.join(rootDir, EVENTS_DIR2), { recursive: true });
|
|
822
|
+
fs4.writeFileSync(lastProcessedPath, lastEvent.id, "utf8");
|
|
823
|
+
} catch {
|
|
824
|
+
}
|
|
825
|
+
return { processed: toProcess.length, nominations: allNominations };
|
|
826
|
+
}
|
|
827
|
+
function emitAndProcess(rootDir, event, opts) {
|
|
828
|
+
const policy = loadDataPolicy(rootDir);
|
|
829
|
+
if (event.path && !canObservePath(policy, event.path)) {
|
|
830
|
+
const emitted2 = emitEvent(rootDir, event);
|
|
831
|
+
return { event: emitted2, nominations: [], debates: [] };
|
|
832
|
+
}
|
|
833
|
+
const emitted = emitEvent(rootDir, event);
|
|
834
|
+
if (opts?.skipNominations) {
|
|
835
|
+
return { event: emitted, nominations: [], debates: [] };
|
|
836
|
+
}
|
|
837
|
+
const { nominations, debates } = processEvent(rootDir, emitted);
|
|
838
|
+
if (nominations.length > 0) {
|
|
839
|
+
forwardNominationsToRelay(rootDir, nominations);
|
|
840
|
+
}
|
|
841
|
+
return { event: emitted, nominations, debates };
|
|
842
|
+
}
|
|
843
|
+
function adjustAttentionFromFeedback(rootDir, agentId) {
|
|
844
|
+
const profile = loadAgentProfile(rootDir, agentId);
|
|
845
|
+
if (!profile?.attention) {
|
|
846
|
+
return { adjusted: false, oldThreshold: 0.6, newThreshold: 0.6, reason: "No attention config" };
|
|
847
|
+
}
|
|
848
|
+
const oldThreshold = profile.attention.threshold ?? 0.6;
|
|
849
|
+
const nominations = loadNominations(rootDir, { agent: agentId });
|
|
850
|
+
const engaged = nominations.filter((n) => n.engaged);
|
|
851
|
+
if (engaged.length < 5) {
|
|
852
|
+
return { adjusted: false, oldThreshold, newThreshold: oldThreshold, reason: `Insufficient data (${engaged.length}/5 engaged nominations)` };
|
|
853
|
+
}
|
|
854
|
+
const accepted = engaged.filter((n) => n.response === "accepted").length;
|
|
855
|
+
const dismissed = engaged.filter((n) => n.response === "dismissed").length;
|
|
856
|
+
const acceptRate = accepted / engaged.length;
|
|
857
|
+
const dismissRate = dismissed / engaged.length;
|
|
858
|
+
let newThreshold = oldThreshold;
|
|
859
|
+
let reason = "No adjustment needed";
|
|
860
|
+
if (dismissRate > 0.6) {
|
|
861
|
+
newThreshold = Math.min(0.95, oldThreshold + 0.05);
|
|
862
|
+
reason = `High dismiss rate (${(dismissRate * 100).toFixed(0)}%) \u2014 raising threshold to reduce noise`;
|
|
863
|
+
} else if (acceptRate > 0.8) {
|
|
864
|
+
newThreshold = Math.max(0.2, oldThreshold - 0.05);
|
|
865
|
+
reason = `High accept rate (${(acceptRate * 100).toFixed(0)}%) \u2014 lowering threshold to contribute more`;
|
|
866
|
+
}
|
|
867
|
+
if (newThreshold === oldThreshold) {
|
|
868
|
+
return { adjusted: false, oldThreshold, newThreshold, reason };
|
|
869
|
+
}
|
|
870
|
+
profile.attention.threshold = newThreshold;
|
|
871
|
+
const projectPath = path4.join(rootDir, ".paradigm/agents", `${agentId}.agent`);
|
|
872
|
+
const scope = fs4.existsSync(projectPath) ? "project" : "global";
|
|
873
|
+
saveAgentProfile(agentId, profile, scope, rootDir);
|
|
874
|
+
emitEvent(rootDir, {
|
|
875
|
+
type: "work-completed",
|
|
876
|
+
source: "agent-action",
|
|
877
|
+
agent: agentId,
|
|
878
|
+
context: `Attention threshold adjusted: ${oldThreshold.toFixed(2)} \u2192 ${newThreshold.toFixed(2)} (${reason})`,
|
|
879
|
+
data: { old_threshold: oldThreshold, new_threshold: newThreshold, accept_rate: acceptRate, dismiss_rate: dismissRate }
|
|
880
|
+
});
|
|
881
|
+
return { adjusted: true, oldThreshold, newThreshold, reason };
|
|
882
|
+
}
|
|
883
|
+
function getNominationStats(rootDir, agentId) {
|
|
884
|
+
const nominations = loadNominations(rootDir, { agent: agentId });
|
|
885
|
+
const accepted = nominations.filter((n) => n.response === "accepted").length;
|
|
886
|
+
const dismissed = nominations.filter((n) => n.response === "dismissed").length;
|
|
887
|
+
const deferred = nominations.filter((n) => n.response === "deferred").length;
|
|
888
|
+
const pending = nominations.filter((n) => !n.engaged).length;
|
|
889
|
+
const engaged = accepted + dismissed + deferred;
|
|
890
|
+
return {
|
|
891
|
+
total: nominations.length,
|
|
892
|
+
accepted,
|
|
893
|
+
dismissed,
|
|
894
|
+
deferred,
|
|
895
|
+
pending,
|
|
896
|
+
acceptRate: engaged > 0 ? accepted / engaged : 0
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
function forwardNominationsToRelay(rootDir, nominations) {
|
|
900
|
+
if (nominations.length === 0) return;
|
|
901
|
+
const outboxDir = path4.join(os2.homedir(), ".paradigm", "score", "outbox");
|
|
902
|
+
if (!fs4.existsSync(outboxDir)) return;
|
|
903
|
+
try {
|
|
904
|
+
const outboxFile = path4.join(outboxDir, `nom-${Date.now()}.json`);
|
|
905
|
+
const message = {
|
|
906
|
+
type: "nomination_forward",
|
|
907
|
+
nominations: nominations.map((n) => ({ ...n })),
|
|
908
|
+
origin: detectLocalProject(rootDir),
|
|
909
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
910
|
+
};
|
|
911
|
+
fs4.writeFileSync(outboxFile, JSON.stringify(message), "utf8");
|
|
912
|
+
} catch {
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
function detectLocalProject(rootDir) {
|
|
916
|
+
try {
|
|
917
|
+
const configPath = path4.join(rootDir, ".paradigm", "config.yaml");
|
|
918
|
+
if (fs4.existsSync(configPath)) {
|
|
919
|
+
const content = fs4.readFileSync(configPath, "utf8");
|
|
920
|
+
const match = content.match(/project:\s*(.+)/);
|
|
921
|
+
if (match) return match[1].trim();
|
|
922
|
+
}
|
|
923
|
+
} catch {
|
|
924
|
+
}
|
|
925
|
+
return path4.basename(rootDir);
|
|
926
|
+
}
|
|
927
|
+
function autoPromoteJournalEntries(rootDir, agentId) {
|
|
928
|
+
let loadJournalEntries;
|
|
929
|
+
let addNotebookEntry2;
|
|
930
|
+
try {
|
|
931
|
+
const journalMod = (init_journal_loader(), __toCommonJS(journal_loader_exports));
|
|
932
|
+
const notebookMod = (init_notebook_loader(), __toCommonJS(notebook_loader_exports));
|
|
933
|
+
loadJournalEntries = journalMod.loadJournalEntries;
|
|
934
|
+
addNotebookEntry2 = notebookMod.addNotebookEntry;
|
|
935
|
+
} catch {
|
|
936
|
+
return { promoted: 0, entries: [] };
|
|
937
|
+
}
|
|
938
|
+
const journal = loadJournalEntries(agentId, {
|
|
939
|
+
trigger: "pattern_discovered",
|
|
940
|
+
limit: 100
|
|
941
|
+
});
|
|
942
|
+
const promoted = [];
|
|
943
|
+
for (const entry of journal) {
|
|
944
|
+
if (entry.promoted_to_notebook) continue;
|
|
945
|
+
if ((entry.confidence_after ?? 0) < 0.8) continue;
|
|
946
|
+
try {
|
|
947
|
+
const { entry: nbEntry } = addNotebookEntry2(
|
|
948
|
+
agentId,
|
|
949
|
+
{
|
|
950
|
+
context: entry.pattern?.applies_when || entry.insight.slice(0, 80),
|
|
951
|
+
snippet: entry.pattern?.correct_approach || entry.insight,
|
|
952
|
+
concepts: entry.tags || [entry.pattern?.id || "learned-pattern"],
|
|
953
|
+
provenance: {
|
|
954
|
+
source: "journal-auto-promote",
|
|
955
|
+
sourceId: entry.id,
|
|
956
|
+
createdBy: agentId
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
"global",
|
|
960
|
+
rootDir
|
|
961
|
+
);
|
|
962
|
+
promoted.push({ journalId: entry.id, notebookId: nbEntry.id });
|
|
963
|
+
try {
|
|
964
|
+
const journalDir = path4.join(os2.homedir(), ".paradigm", "agents", agentId, "journal");
|
|
965
|
+
if (fs4.existsSync(journalDir)) {
|
|
966
|
+
const files = fs4.readdirSync(journalDir).filter((f) => f.endsWith(".yaml"));
|
|
967
|
+
for (const file of files) {
|
|
968
|
+
const filePath = path4.join(journalDir, file);
|
|
969
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
970
|
+
if (content.includes(entry.id)) {
|
|
971
|
+
const updated = content.replace(
|
|
972
|
+
/promoted_to_notebook:.*$/m,
|
|
973
|
+
`promoted_to_notebook: "${nbEntry.id}"`
|
|
974
|
+
);
|
|
975
|
+
if (updated === content) {
|
|
976
|
+
const lines = content.trimEnd().split("\n");
|
|
977
|
+
lines.push(`promoted_to_notebook: "${nbEntry.id}"`);
|
|
978
|
+
fs4.writeFileSync(filePath, lines.join("\n") + "\n", "utf8");
|
|
979
|
+
} else {
|
|
980
|
+
fs4.writeFileSync(filePath, updated, "utf8");
|
|
981
|
+
}
|
|
982
|
+
break;
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
} catch {
|
|
987
|
+
}
|
|
988
|
+
} catch {
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return { promoted: promoted.length, entries: promoted };
|
|
992
|
+
}
|
|
993
|
+
function loadSurfacingConfig(rootDir) {
|
|
994
|
+
const filePath = path4.join(rootDir, SURFACING_FILE);
|
|
995
|
+
const defaults = {
|
|
996
|
+
default_min_urgency: "low",
|
|
997
|
+
enable_debates: true
|
|
998
|
+
};
|
|
999
|
+
if (!fs4.existsSync(filePath)) return defaults;
|
|
1000
|
+
try {
|
|
1001
|
+
const yaml3 = __require("js-yaml");
|
|
1002
|
+
const content = fs4.readFileSync(filePath, "utf8");
|
|
1003
|
+
const parsed = yaml3.load(content);
|
|
1004
|
+
return { ...defaults, ...parsed };
|
|
1005
|
+
} catch {
|
|
1006
|
+
return defaults;
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
function applySurfacingRules(nominations, config) {
|
|
1010
|
+
const urgencyOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
1011
|
+
const minUrgency = urgencyOrder[config.default_min_urgency || "low"] ?? 3;
|
|
1012
|
+
return nominations.filter((n) => {
|
|
1013
|
+
const nomUrgency = urgencyOrder[n.urgency] ?? 3;
|
|
1014
|
+
if (config.preferences) {
|
|
1015
|
+
const agentPref = config.preferences.find((p) => p.agent === n.agent);
|
|
1016
|
+
if (agentPref) {
|
|
1017
|
+
if (agentPref.always_show) return true;
|
|
1018
|
+
if (agentPref.mute_unless?.length) {
|
|
1019
|
+
const matchesMute = agentPref.mute_unless.some(
|
|
1020
|
+
(condition) => n.urgency === condition || n.type === condition
|
|
1021
|
+
);
|
|
1022
|
+
if (!matchesMute) return false;
|
|
1023
|
+
}
|
|
1024
|
+
if (agentPref.min_urgency) {
|
|
1025
|
+
const agentMin = urgencyOrder[agentPref.min_urgency] ?? 3;
|
|
1026
|
+
return nomUrgency <= agentMin;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
return nomUrgency <= minUrgency;
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
var EVENTS_DIR2, NOMINATIONS_FILE, DEBATES_FILE, MAX_NOMINATIONS, MAX_DEBATES, SURFACING_FILE;
|
|
1034
|
+
var init_nomination_engine = __esm({
|
|
1035
|
+
"../paradigm-mcp/src/utils/nomination-engine.ts"() {
|
|
1036
|
+
init_event_stream();
|
|
1037
|
+
init_data_policy_loader();
|
|
1038
|
+
init_agent_loader();
|
|
1039
|
+
EVENTS_DIR2 = ".paradigm/events";
|
|
1040
|
+
NOMINATIONS_FILE = "nominations.jsonl";
|
|
1041
|
+
DEBATES_FILE = "debates.jsonl";
|
|
1042
|
+
MAX_NOMINATIONS = 500;
|
|
1043
|
+
MAX_DEBATES = 200;
|
|
1044
|
+
SURFACING_FILE = ".paradigm/surfacing.yaml";
|
|
1045
|
+
}
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
export {
|
|
1049
|
+
queryEvents,
|
|
1050
|
+
init_event_stream,
|
|
1051
|
+
loadDataPolicy,
|
|
1052
|
+
filterContent,
|
|
1053
|
+
init_data_policy_loader,
|
|
1054
|
+
loadNotebookEntries,
|
|
1055
|
+
searchNotebooks,
|
|
1056
|
+
addNotebookEntry,
|
|
1057
|
+
promoteFromLore,
|
|
1058
|
+
init_notebook_loader,
|
|
1059
|
+
processEvent,
|
|
1060
|
+
detectDebates,
|
|
1061
|
+
persistNominations,
|
|
1062
|
+
loadNominations,
|
|
1063
|
+
loadDebates,
|
|
1064
|
+
engageNomination,
|
|
1065
|
+
resolveDebate,
|
|
1066
|
+
processPendingEvents,
|
|
1067
|
+
emitAndProcess,
|
|
1068
|
+
adjustAttentionFromFeedback,
|
|
1069
|
+
getNominationStats,
|
|
1070
|
+
forwardNominationsToRelay,
|
|
1071
|
+
autoPromoteJournalEntries,
|
|
1072
|
+
loadSurfacingConfig,
|
|
1073
|
+
applySurfacingRules,
|
|
1074
|
+
init_nomination_engine
|
|
1075
|
+
};
|