fushiguro-mcp 0.1.0
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/LICENSE +21 -0
- package/README.md +278 -0
- package/catalog/agents/backend-api.md +71 -0
- package/catalog/agents/content-editor.md +59 -0
- package/catalog/agents/customer-support.md +60 -0
- package/catalog/agents/data-analyst.md +66 -0
- package/catalog/agents/database.md +65 -0
- package/catalog/agents/docs.md +52 -0
- package/catalog/agents/process-automation.md +61 -0
- package/catalog/agents/research-analyst.md +57 -0
- package/catalog/agents/security.md +68 -0
- package/catalog/agents/testing.md +63 -0
- package/catalog/agents/ux-ui-specialist.md +87 -0
- package/catalog/connectors/crm.md +24 -0
- package/catalog/connectors/data-warehouse.md +26 -0
- package/catalog/connectors/document-store.md +23 -0
- package/catalog/connectors/helpdesk.md +24 -0
- package/catalog/knowledge/platform/using-this-catalog.md +50 -0
- package/catalog/runbooks/_TEMPLATE.md +52 -0
- package/catalog/runbooks/ai-use-case-intake.md +89 -0
- package/catalog/runbooks/change-release.md +54 -0
- package/catalog/runbooks/customer-escalation.md +67 -0
- package/catalog/skills/cite-sources.md +18 -0
- package/catalog/skills/clarify-scope.md +18 -0
- package/catalog/skills/data-quality-check.md +22 -0
- package/catalog/skills/risk-and-compliance-check.md +21 -0
- package/catalog/skills/stakeholder-summary.md +21 -0
- package/catalog/tools/knowledge-search.md +14 -0
- package/catalog/tools/shell.md +15 -0
- package/catalog/tools/web-fetch.md +15 -0
- package/catalog/tools/web-search.md +15 -0
- package/catalog/topics/ai-adoption.md +25 -0
- package/catalog/topics/customer-operations.md +21 -0
- package/catalog/topics/data-and-reporting.md +20 -0
- package/catalog/topics/marketing-content.md +19 -0
- package/catalog/topics/product-engineering.md +20 -0
- package/dist/catalog.d.ts +34 -0
- package/dist/catalog.js +412 -0
- package/dist/catalog.js.map +1 -0
- package/dist/config.d.ts +17 -0
- package/dist/config.js +48 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +5 -0
- package/dist/init.js +159 -0
- package/dist/init.js.map +1 -0
- package/dist/knowledge.d.ts +31 -0
- package/dist/knowledge.js +126 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +22 -0
- package/dist/main.js.map +1 -0
- package/dist/memory.d.ts +85 -0
- package/dist/memory.js +374 -0
- package/dist/memory.js.map +1 -0
- package/dist/quiet.d.ts +1 -0
- package/dist/quiet.js +21 -0
- package/dist/quiet.js.map +1 -0
- package/dist/registry.d.ts +15 -0
- package/dist/registry.js +128 -0
- package/dist/registry.js.map +1 -0
- package/dist/router.d.ts +55 -0
- package/dist/router.js +358 -0
- package/dist/router.js.map +1 -0
- package/dist/server.d.ts +6 -0
- package/dist/server.js +529 -0
- package/dist/server.js.map +1 -0
- package/dist/text.d.ts +20 -0
- package/dist/text.js +72 -0
- package/dist/text.js.map +1 -0
- package/dist/types.d.ts +195 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
package/dist/memory.js
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { mkdirSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
import { DatabaseSync } from "node:sqlite";
|
|
4
|
+
import { containment, ftsQuery, jaccard, sharedTokens, tokenize } from "./text.js";
|
|
5
|
+
/**
|
|
6
|
+
* Hard rules must outrank soft tastes during recall, so each kind carries a
|
|
7
|
+
* multiplier applied on top of the text-relevance score.
|
|
8
|
+
*/
|
|
9
|
+
const KIND_WEIGHT = {
|
|
10
|
+
constraint: 1.6,
|
|
11
|
+
correction: 1.5,
|
|
12
|
+
preference: 1.0,
|
|
13
|
+
style: 0.9,
|
|
14
|
+
fact: 0.8,
|
|
15
|
+
};
|
|
16
|
+
/** Ranking used to decide whether a new memory supersedes an older one. */
|
|
17
|
+
const KIND_RANK = {
|
|
18
|
+
fact: 0,
|
|
19
|
+
style: 1,
|
|
20
|
+
preference: 2,
|
|
21
|
+
correction: 3,
|
|
22
|
+
constraint: 4,
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Whether two memories are restatements of one preference. Jaccard alone misses
|
|
26
|
+
* a preference restated at greater length, so containment of the smaller set
|
|
27
|
+
* counts too — but only above a floor of shared distinct tokens, since two short
|
|
28
|
+
* preferences about different objects ("8pt grid for spacing" / "8pt grid for
|
|
29
|
+
* icons") otherwise look identical to a purely lexical measure.
|
|
30
|
+
*/
|
|
31
|
+
function saysTheSameThing(a, b) {
|
|
32
|
+
if (sharedTokens(a, b) < 3)
|
|
33
|
+
return false;
|
|
34
|
+
return Math.max(jaccard(a, b), containment(a, b)) >= 0.6;
|
|
35
|
+
}
|
|
36
|
+
function toMemory(row) {
|
|
37
|
+
return {
|
|
38
|
+
id: row.id,
|
|
39
|
+
scope: row.scope,
|
|
40
|
+
agent: row.agent,
|
|
41
|
+
kind: row.kind,
|
|
42
|
+
text: row.text,
|
|
43
|
+
why: row.why,
|
|
44
|
+
confidence: row.confidence,
|
|
45
|
+
source: row.source,
|
|
46
|
+
createdAt: row.created_at,
|
|
47
|
+
updatedAt: row.updated_at,
|
|
48
|
+
hits: row.hits,
|
|
49
|
+
supersededBy: row.superseded_by,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export class MemoryStore {
|
|
53
|
+
#db;
|
|
54
|
+
constructor(dbPath) {
|
|
55
|
+
if (dbPath !== ":memory:")
|
|
56
|
+
mkdirSync(dirname(dbPath), { recursive: true });
|
|
57
|
+
this.#db = new DatabaseSync(dbPath);
|
|
58
|
+
this.#db.exec("PRAGMA journal_mode = WAL");
|
|
59
|
+
this.#db.exec("PRAGMA foreign_keys = ON");
|
|
60
|
+
this.#migrate();
|
|
61
|
+
}
|
|
62
|
+
#migrate() {
|
|
63
|
+
this.#db.exec(`
|
|
64
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
65
|
+
id INTEGER PRIMARY KEY,
|
|
66
|
+
scope TEXT NOT NULL DEFAULT 'global',
|
|
67
|
+
agent TEXT,
|
|
68
|
+
kind TEXT NOT NULL DEFAULT 'preference',
|
|
69
|
+
text TEXT NOT NULL,
|
|
70
|
+
why TEXT,
|
|
71
|
+
confidence REAL NOT NULL DEFAULT 0.6,
|
|
72
|
+
source TEXT,
|
|
73
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
74
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
75
|
+
hits INTEGER NOT NULL DEFAULT 0,
|
|
76
|
+
superseded_by INTEGER REFERENCES memories(id) ON DELETE SET NULL
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
CREATE INDEX IF NOT EXISTS idx_memories_lookup
|
|
80
|
+
ON memories(scope, agent, superseded_by);
|
|
81
|
+
|
|
82
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts
|
|
83
|
+
USING fts5(text, why, tokenize = 'porter unicode61');
|
|
84
|
+
|
|
85
|
+
CREATE TABLE IF NOT EXISTS decisions (
|
|
86
|
+
id INTEGER PRIMARY KEY,
|
|
87
|
+
task TEXT NOT NULL,
|
|
88
|
+
agent TEXT NOT NULL,
|
|
89
|
+
outcome TEXT NOT NULL,
|
|
90
|
+
notes TEXT,
|
|
91
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
-- Learned routing signal: how often a term led to a good outcome for an agent.
|
|
95
|
+
CREATE TABLE IF NOT EXISTS affinity (
|
|
96
|
+
agent TEXT NOT NULL,
|
|
97
|
+
term TEXT NOT NULL,
|
|
98
|
+
weight REAL NOT NULL DEFAULT 0,
|
|
99
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
100
|
+
PRIMARY KEY (agent, term)
|
|
101
|
+
);
|
|
102
|
+
`);
|
|
103
|
+
}
|
|
104
|
+
close() {
|
|
105
|
+
this.#db.close();
|
|
106
|
+
}
|
|
107
|
+
#row(id) {
|
|
108
|
+
const row = this.#db
|
|
109
|
+
.prepare("SELECT * FROM memories WHERE id = ?")
|
|
110
|
+
.get(id);
|
|
111
|
+
if (!row)
|
|
112
|
+
throw new Error(`memory ${id} not found`);
|
|
113
|
+
return toMemory(row);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Writes a preference, folding it into an existing one when it says the same
|
|
117
|
+
* thing. Restating a preference reinforces it; a constraint or correction that
|
|
118
|
+
* restates a softer memory retires that memory instead of duplicating it.
|
|
119
|
+
*/
|
|
120
|
+
remember(input) {
|
|
121
|
+
const text = input.text.trim();
|
|
122
|
+
if (!text)
|
|
123
|
+
throw new Error("memory text is empty");
|
|
124
|
+
const confidence = Math.min(1, Math.max(0, input.confidence ?? 0.6));
|
|
125
|
+
const tokens = tokenize(text);
|
|
126
|
+
for (const candidate of this.#similarCandidates(input, tokens)) {
|
|
127
|
+
if (!saysTheSameThing(tokens, tokenize(candidate.text)))
|
|
128
|
+
continue;
|
|
129
|
+
const sameOrLowerKind = KIND_RANK[input.kind] <= KIND_RANK[candidate.kind];
|
|
130
|
+
if (sameOrLowerKind) {
|
|
131
|
+
// A restatement: keep the newer wording and raise confidence.
|
|
132
|
+
const bumped = Math.min(1, Math.max(candidate.confidence, confidence) + 0.15);
|
|
133
|
+
this.#db
|
|
134
|
+
.prepare(`UPDATE memories
|
|
135
|
+
SET text = ?, why = COALESCE(?, why), confidence = ?,
|
|
136
|
+
kind = ?, updated_at = datetime('now')
|
|
137
|
+
WHERE id = ?`)
|
|
138
|
+
.run(text, input.why ?? null, bumped, input.kind, candidate.id);
|
|
139
|
+
this.#reindex(candidate.id, text, input.why ?? candidate.why);
|
|
140
|
+
return { id: candidate.id, action: "reinforced", memory: this.#row(candidate.id) };
|
|
141
|
+
}
|
|
142
|
+
// A stronger statement of the same thing: retire the old, keep the trail.
|
|
143
|
+
const created = this.#insert({ ...input, text, confidence });
|
|
144
|
+
this.#db
|
|
145
|
+
.prepare("UPDATE memories SET superseded_by = ?, updated_at = datetime('now') WHERE id = ?")
|
|
146
|
+
.run(created, candidate.id);
|
|
147
|
+
return {
|
|
148
|
+
id: created,
|
|
149
|
+
action: "superseded",
|
|
150
|
+
supersededId: candidate.id,
|
|
151
|
+
memory: this.#row(created),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
const id = this.#insert({ ...input, text, confidence });
|
|
155
|
+
return { id, action: "created", memory: this.#row(id) };
|
|
156
|
+
}
|
|
157
|
+
/** Live memories in the same scope/agent lane that share vocabulary with `tokens`. */
|
|
158
|
+
#similarCandidates(input, tokens) {
|
|
159
|
+
const match = ftsQuery(tokens.join(" "));
|
|
160
|
+
if (!match)
|
|
161
|
+
return [];
|
|
162
|
+
const rows = this.#db
|
|
163
|
+
.prepare(`SELECT m.* FROM memories_fts f
|
|
164
|
+
JOIN memories m ON m.id = f.rowid
|
|
165
|
+
WHERE memories_fts MATCH ?
|
|
166
|
+
AND m.superseded_by IS NULL
|
|
167
|
+
AND m.scope = ?
|
|
168
|
+
AND ((m.agent IS NULL AND ? IS NULL) OR m.agent = ?)
|
|
169
|
+
ORDER BY bm25(memories_fts)
|
|
170
|
+
LIMIT 10`)
|
|
171
|
+
.all(match, input.scope, input.agent, input.agent);
|
|
172
|
+
return rows.map(toMemory);
|
|
173
|
+
}
|
|
174
|
+
#insert(input) {
|
|
175
|
+
const result = this.#db
|
|
176
|
+
.prepare(`INSERT INTO memories (scope, agent, kind, text, why, confidence, source)
|
|
177
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
178
|
+
.run(input.scope, input.agent, input.kind, input.text, input.why ?? null, input.confidence, input.source ?? null);
|
|
179
|
+
const id = Number(result.lastInsertRowid);
|
|
180
|
+
this.#db
|
|
181
|
+
.prepare("INSERT INTO memories_fts (rowid, text, why) VALUES (?, ?, ?)")
|
|
182
|
+
.run(id, input.text, input.why ?? "");
|
|
183
|
+
return id;
|
|
184
|
+
}
|
|
185
|
+
#reindex(id, text, why) {
|
|
186
|
+
this.#db.prepare("DELETE FROM memories_fts WHERE rowid = ?").run(id);
|
|
187
|
+
this.#db
|
|
188
|
+
.prepare("INSERT INTO memories_fts (rowid, text, why) VALUES (?, ?, ?)")
|
|
189
|
+
.run(id, text, why ?? "");
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Ranked recall. Relevance comes from BM25 when there is a query, then gets
|
|
193
|
+
* scaled by kind weight and confidence so a hard constraint beats a passing
|
|
194
|
+
* remark even when the remark matches the words better.
|
|
195
|
+
*
|
|
196
|
+
* Constraints and corrections are also pulled in unconditionally, whether or
|
|
197
|
+
* not they match the query. A rule like "never use purple" that only surfaces
|
|
198
|
+
* when the user happens to say "purple" is not a rule — it has to be in front
|
|
199
|
+
* of the agent on the task where it would otherwise be broken.
|
|
200
|
+
*/
|
|
201
|
+
recall(options = {}) {
|
|
202
|
+
const limit = Math.min(100, Math.max(1, options.limit ?? 12));
|
|
203
|
+
const scopes = options.scopes?.length ? options.scopes : ["global"];
|
|
204
|
+
const scopePlaceholders = scopes.map(() => "?").join(", ");
|
|
205
|
+
const agent = options.agent ?? null;
|
|
206
|
+
const match = options.query ? ftsQuery(options.query) : null;
|
|
207
|
+
let rows;
|
|
208
|
+
if (match) {
|
|
209
|
+
rows = this.#db
|
|
210
|
+
.prepare(`SELECT m.*, -bm25(memories_fts) AS relevance
|
|
211
|
+
FROM memories_fts f
|
|
212
|
+
JOIN memories m ON m.id = f.rowid
|
|
213
|
+
WHERE memories_fts MATCH ?
|
|
214
|
+
AND m.superseded_by IS NULL
|
|
215
|
+
AND m.scope IN (${scopePlaceholders})
|
|
216
|
+
AND (m.agent IS NULL OR m.agent = ?)
|
|
217
|
+
ORDER BY relevance DESC
|
|
218
|
+
LIMIT ?`)
|
|
219
|
+
.all(match, ...scopes, agent, limit * 4);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
rows = this.#db
|
|
223
|
+
.prepare(`SELECT m.* FROM memories m
|
|
224
|
+
WHERE m.superseded_by IS NULL
|
|
225
|
+
AND m.scope IN (${scopePlaceholders})
|
|
226
|
+
AND (m.agent IS NULL OR m.agent = ?)
|
|
227
|
+
ORDER BY m.updated_at DESC
|
|
228
|
+
LIMIT ?`)
|
|
229
|
+
.all(...scopes, agent, limit * 4);
|
|
230
|
+
}
|
|
231
|
+
// BM25 magnitudes vary wildly with document length, so normalise relevance
|
|
232
|
+
// within this result set before weighting. Otherwise a short, soft memory
|
|
233
|
+
// that matched slightly better buries a hard constraint that also matched.
|
|
234
|
+
const maxRelevance = match
|
|
235
|
+
? Math.max(...rows.map((r) => r.relevance ?? 0), Number.EPSILON)
|
|
236
|
+
: 1;
|
|
237
|
+
// Hard rules are always in scope, matched or not.
|
|
238
|
+
const bindingRows = this.#db
|
|
239
|
+
.prepare(`SELECT * FROM memories
|
|
240
|
+
WHERE superseded_by IS NULL
|
|
241
|
+
AND kind IN ('constraint', 'correction')
|
|
242
|
+
AND scope IN (${scopePlaceholders})
|
|
243
|
+
AND (agent IS NULL OR agent = ?)
|
|
244
|
+
ORDER BY confidence DESC, updated_at DESC
|
|
245
|
+
LIMIT ?`)
|
|
246
|
+
.all(...scopes, agent, limit);
|
|
247
|
+
const seen = new Set(rows.map((r) => r.id));
|
|
248
|
+
for (const row of bindingRows) {
|
|
249
|
+
if (!seen.has(row.id))
|
|
250
|
+
rows.push(row);
|
|
251
|
+
}
|
|
252
|
+
const scored = rows.map((row) => {
|
|
253
|
+
const memory = toMemory(row);
|
|
254
|
+
const binding = memory.kind === "constraint" || memory.kind === "correction";
|
|
255
|
+
const normalised = !match || binding
|
|
256
|
+
? 1
|
|
257
|
+
: Math.max(0, row.relevance ?? 0) / maxRelevance;
|
|
258
|
+
// Floor at 0.4 so relevance ranks within a kind without overpowering kind.
|
|
259
|
+
const relevance = 0.4 + 0.6 * normalised;
|
|
260
|
+
return { memory, score: relevance * KIND_WEIGHT[memory.kind] * memory.confidence };
|
|
261
|
+
});
|
|
262
|
+
scored.sort((a, b) => b.score - a.score);
|
|
263
|
+
return scored.slice(0, limit).map((s) => s.memory);
|
|
264
|
+
}
|
|
265
|
+
/** Marks memories as used, so `memory_stats` can show what actually earns its keep. */
|
|
266
|
+
markUsed(ids) {
|
|
267
|
+
if (ids.length === 0)
|
|
268
|
+
return;
|
|
269
|
+
const stmt = this.#db.prepare("UPDATE memories SET hits = hits + 1 WHERE id = ?");
|
|
270
|
+
for (const id of ids)
|
|
271
|
+
stmt.run(id);
|
|
272
|
+
}
|
|
273
|
+
get(id) {
|
|
274
|
+
const row = this.#db.prepare("SELECT * FROM memories WHERE id = ?").get(id);
|
|
275
|
+
return row ? toMemory(row) : null;
|
|
276
|
+
}
|
|
277
|
+
forget(id) {
|
|
278
|
+
const changes = this.#db.prepare("DELETE FROM memories WHERE id = ?").run(id).changes;
|
|
279
|
+
this.#db.prepare("DELETE FROM memories_fts WHERE rowid = ?").run(id);
|
|
280
|
+
return Number(changes) > 0;
|
|
281
|
+
}
|
|
282
|
+
list(options = {}) {
|
|
283
|
+
const clauses = ["superseded_by IS NULL"];
|
|
284
|
+
const params = [];
|
|
285
|
+
if (options.agent !== undefined) {
|
|
286
|
+
clauses.push("agent IS ?");
|
|
287
|
+
params.push(options.agent);
|
|
288
|
+
}
|
|
289
|
+
if (options.scope) {
|
|
290
|
+
clauses.push("scope = ?");
|
|
291
|
+
params.push(options.scope);
|
|
292
|
+
}
|
|
293
|
+
params.push(Math.min(200, Math.max(1, options.limit ?? 50)));
|
|
294
|
+
const rows = this.#db
|
|
295
|
+
.prepare(`SELECT * FROM memories WHERE ${clauses.join(" AND ")}
|
|
296
|
+
ORDER BY updated_at DESC LIMIT ?`)
|
|
297
|
+
.all(...params);
|
|
298
|
+
return rows.map(toMemory);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Records how a routing decision landed and nudges the term→agent affinity
|
|
302
|
+
* that the router consults next time. This is the loop that makes routing
|
|
303
|
+
* improve with use rather than staying frozen at whatever the keywords say.
|
|
304
|
+
*/
|
|
305
|
+
recordOutcome(input) {
|
|
306
|
+
const result = this.#db
|
|
307
|
+
.prepare("INSERT INTO decisions (task, agent, outcome, notes) VALUES (?, ?, ?, ?)")
|
|
308
|
+
.run(input.task, input.agent, input.outcome, input.notes ?? null);
|
|
309
|
+
const delta = input.outcome === "accepted" ? 1 : input.outcome === "revised" ? 0.25 : -1;
|
|
310
|
+
const terms = [...new Set(tokenize(input.task))].slice(0, 24);
|
|
311
|
+
let adjusted = 0;
|
|
312
|
+
for (const term of terms) {
|
|
313
|
+
this.#bumpAffinity(input.agent, term, delta);
|
|
314
|
+
adjusted += 1;
|
|
315
|
+
// "wrong agent, should have been X" teaches both sides in one call.
|
|
316
|
+
if (input.correctAgent && input.correctAgent !== input.agent) {
|
|
317
|
+
this.#bumpAffinity(input.correctAgent, term, 1);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return { decisionId: Number(result.lastInsertRowid), adjusted };
|
|
321
|
+
}
|
|
322
|
+
#bumpAffinity(agent, term, delta) {
|
|
323
|
+
this.#db
|
|
324
|
+
.prepare(`INSERT INTO affinity (agent, term, weight) VALUES (?, ?, ?)
|
|
325
|
+
ON CONFLICT(agent, term) DO UPDATE
|
|
326
|
+
SET weight = max(-5, min(5, affinity.weight + excluded.weight)),
|
|
327
|
+
updated_at = datetime('now')`)
|
|
328
|
+
.run(agent, term, delta);
|
|
329
|
+
}
|
|
330
|
+
/** Learned per-agent weight for the given terms, summed. */
|
|
331
|
+
affinity(terms) {
|
|
332
|
+
const unique = [...new Set(terms)];
|
|
333
|
+
const out = new Map();
|
|
334
|
+
if (unique.length === 0)
|
|
335
|
+
return out;
|
|
336
|
+
const placeholders = unique.map(() => "?").join(", ");
|
|
337
|
+
const rows = this.#db
|
|
338
|
+
.prepare(`SELECT agent, SUM(weight) AS total FROM affinity
|
|
339
|
+
WHERE term IN (${placeholders}) GROUP BY agent`)
|
|
340
|
+
.all(...unique);
|
|
341
|
+
for (const row of rows)
|
|
342
|
+
out.set(row.agent, row.total);
|
|
343
|
+
return out;
|
|
344
|
+
}
|
|
345
|
+
stats() {
|
|
346
|
+
const count = (sql, ...params) => Number(this.#db.prepare(sql).get(...params).n);
|
|
347
|
+
const byKind = {};
|
|
348
|
+
for (const row of this.#db
|
|
349
|
+
.prepare("SELECT kind, COUNT(*) AS n FROM memories WHERE superseded_by IS NULL GROUP BY kind")
|
|
350
|
+
.all()) {
|
|
351
|
+
byKind[row.kind] = Number(row.n);
|
|
352
|
+
}
|
|
353
|
+
const byAgent = {};
|
|
354
|
+
for (const row of this.#db
|
|
355
|
+
.prepare(`SELECT COALESCE(agent, '(all agents)') AS agent, COUNT(*) AS n
|
|
356
|
+
FROM memories WHERE superseded_by IS NULL GROUP BY agent`)
|
|
357
|
+
.all()) {
|
|
358
|
+
byAgent[row.agent] = Number(row.n);
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
total: count("SELECT COUNT(*) AS n FROM memories WHERE superseded_by IS NULL"),
|
|
362
|
+
byKind,
|
|
363
|
+
byAgent,
|
|
364
|
+
superseded: count("SELECT COUNT(*) AS n FROM memories WHERE superseded_by IS NOT NULL"),
|
|
365
|
+
decisions: count("SELECT COUNT(*) AS n FROM decisions"),
|
|
366
|
+
topUsed: this.#db
|
|
367
|
+
.prepare(`SELECT id, text, hits FROM memories
|
|
368
|
+
WHERE superseded_by IS NULL AND hits > 0
|
|
369
|
+
ORDER BY hits DESC LIMIT 5`)
|
|
370
|
+
.all(),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,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AG;aACvB,OAAO,CACN;oEAC4D,CAC7D;aACA,GAAG,EAA+C,EAAE,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QACrC,CAAC;QAED,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,gEAAgE,CAAC;YAC9E,MAAM;YACN,OAAO;YACP,UAAU,EAAE,KAAK,CAAC,oEAAoE,CAAC;YACvF,SAAS,EAAE,KAAK,CAAC,qCAAqC,CAAC;YACvD,OAAO,EAAE,IAAI,CAAC,GAAG;iBACd,OAAO,CACN;;uCAE6B,CAC9B;iBACA,GAAG,EAA6D;SACpE,CAAC;IACJ,CAAC;CACF"}
|
package/dist/quiet.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/quiet.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Silences the `node:sqlite` experimental warning, which would otherwise land in
|
|
3
|
+
* the host's error log on every start. Nothing else is silenced.
|
|
4
|
+
*
|
|
5
|
+
* The warning fires while `node:sqlite` is being linked, which happens before any
|
|
6
|
+
* module body in a static graph runs — so this module has no imports of its own
|
|
7
|
+
* and `index.ts` reaches the rest of the server through a dynamic import.
|
|
8
|
+
*/
|
|
9
|
+
const originalEmit = process.emit.bind(process);
|
|
10
|
+
process.emit = (name, ...args) => {
|
|
11
|
+
const data = args[0];
|
|
12
|
+
if (name === "warning" &&
|
|
13
|
+
data instanceof Error &&
|
|
14
|
+
data.name === "ExperimentalWarning" &&
|
|
15
|
+
data.message.includes("SQLite")) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return originalEmit(name, ...args);
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=quiet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quiet.js","sourceRoot":"","sources":["../src/quiet.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC/C,OAA8E,CAAC,IAAI,GAAG,CACrF,IAAY,EACZ,GAAG,IAAe,EAClB,EAAE;IACF,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACrB,IACE,IAAI,KAAK,SAAS;QAClB,IAAI,YAAY,KAAK;QACrB,IAAI,CAAC,IAAI,KAAK,qBAAqB;QACnC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAC/B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAQ,YAA6C,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;AACvE,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Specialist } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Loads the specialist roster from disk and reloads it when a file changes,
|
|
4
|
+
* so editing an `agents/*.md` takes effect without restarting the server.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Registry {
|
|
7
|
+
#private;
|
|
8
|
+
private readonly dir;
|
|
9
|
+
constructor(dir: string);
|
|
10
|
+
refresh(): void;
|
|
11
|
+
all(): Specialist[];
|
|
12
|
+
get(name: string): Specialist | undefined;
|
|
13
|
+
/** Parse failures from the last load, surfaced so bad files aren't silent. */
|
|
14
|
+
errors(): string[];
|
|
15
|
+
}
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
|
|
5
|
+
function asStringArray(value) {
|
|
6
|
+
if (Array.isArray(value))
|
|
7
|
+
return value.map((v) => String(v).trim()).filter(Boolean);
|
|
8
|
+
if (typeof value === "string") {
|
|
9
|
+
return value
|
|
10
|
+
.split(",")
|
|
11
|
+
.map((v) => v.trim())
|
|
12
|
+
.filter(Boolean);
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
function parseSpecialist(file, raw) {
|
|
17
|
+
const match = FRONTMATTER.exec(raw);
|
|
18
|
+
if (!match) {
|
|
19
|
+
throw new Error(`${file}: missing YAML frontmatter (a --- delimited block at the top)`);
|
|
20
|
+
}
|
|
21
|
+
const meta = (parseYaml(match[1]) ?? {});
|
|
22
|
+
const systemPrompt = raw.slice(match[0].length).trim();
|
|
23
|
+
const name = String(meta.name ?? "").trim();
|
|
24
|
+
if (!name)
|
|
25
|
+
throw new Error(`${file}: frontmatter needs a 'name'`);
|
|
26
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {
|
|
27
|
+
throw new Error(`${file}: 'name' must be lowercase kebab-case, got '${name}'`);
|
|
28
|
+
}
|
|
29
|
+
if (!systemPrompt)
|
|
30
|
+
throw new Error(`${file}: no system prompt below the frontmatter`);
|
|
31
|
+
const patterns = [];
|
|
32
|
+
for (const src of asStringArray(meta.patterns)) {
|
|
33
|
+
try {
|
|
34
|
+
patterns.push(new RegExp(src, "i"));
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
throw new Error(`${file}: invalid regex in 'patterns': ${src} (${err.message})`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
name,
|
|
42
|
+
title: String(meta.title ?? name),
|
|
43
|
+
description: String(meta.description ?? ""),
|
|
44
|
+
model: meta.model ? String(meta.model) : undefined,
|
|
45
|
+
keywords: asStringArray(meta.keywords).map((k) => k.toLowerCase()),
|
|
46
|
+
triggers: asStringArray(meta.triggers),
|
|
47
|
+
patterns,
|
|
48
|
+
tools: asStringArray(meta.tools),
|
|
49
|
+
systemPrompt,
|
|
50
|
+
file,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Loads the specialist roster from disk and reloads it when a file changes,
|
|
55
|
+
* so editing an `agents/*.md` takes effect without restarting the server.
|
|
56
|
+
*/
|
|
57
|
+
export class Registry {
|
|
58
|
+
dir;
|
|
59
|
+
#specialists = new Map();
|
|
60
|
+
#signature = "";
|
|
61
|
+
#errors = [];
|
|
62
|
+
constructor(dir) {
|
|
63
|
+
this.dir = dir;
|
|
64
|
+
this.refresh();
|
|
65
|
+
}
|
|
66
|
+
/** Cheap mtime+size fingerprint of the directory; changes trigger a reload. */
|
|
67
|
+
#fingerprint() {
|
|
68
|
+
let files;
|
|
69
|
+
try {
|
|
70
|
+
files = readdirSync(this.dir).filter((f) => f.endsWith(".md")).sort();
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return "missing";
|
|
74
|
+
}
|
|
75
|
+
return files
|
|
76
|
+
.map((f) => {
|
|
77
|
+
const s = statSync(join(this.dir, f));
|
|
78
|
+
return `${f}:${s.mtimeMs}:${s.size}`;
|
|
79
|
+
})
|
|
80
|
+
.join("|");
|
|
81
|
+
}
|
|
82
|
+
refresh() {
|
|
83
|
+
const signature = this.#fingerprint();
|
|
84
|
+
if (signature === this.#signature && this.#specialists.size > 0)
|
|
85
|
+
return;
|
|
86
|
+
this.#signature = signature;
|
|
87
|
+
const next = new Map();
|
|
88
|
+
const errors = [];
|
|
89
|
+
let files = [];
|
|
90
|
+
try {
|
|
91
|
+
files = readdirSync(this.dir).filter((f) => f.endsWith(".md")).sort();
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
errors.push(`agents directory not readable: ${this.dir}`);
|
|
95
|
+
}
|
|
96
|
+
for (const file of files) {
|
|
97
|
+
const path = join(this.dir, file);
|
|
98
|
+
try {
|
|
99
|
+
const spec = parseSpecialist(path, readFileSync(path, "utf8"));
|
|
100
|
+
if (next.has(spec.name)) {
|
|
101
|
+
errors.push(`duplicate specialist name '${spec.name}' in ${file}; keeping the first`);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
next.set(spec.name, spec);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
// One malformed file must not take the whole roster down.
|
|
108
|
+
errors.push(err.message);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
this.#specialists = next;
|
|
112
|
+
this.#errors = errors;
|
|
113
|
+
}
|
|
114
|
+
all() {
|
|
115
|
+
this.refresh();
|
|
116
|
+
return [...this.#specialists.values()];
|
|
117
|
+
}
|
|
118
|
+
get(name) {
|
|
119
|
+
this.refresh();
|
|
120
|
+
return this.#specialists.get(name);
|
|
121
|
+
}
|
|
122
|
+
/** Parse failures from the last load, surfaced so bad files aren't silent. */
|
|
123
|
+
errors() {
|
|
124
|
+
this.refresh();
|
|
125
|
+
return this.#errors;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AAG1C,MAAM,WAAW,GAAG,mCAAmC,CAAC;AAExD,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK;aACT,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC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IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,MAAM,CAAC,IAAI,CAAC,8BAA8B,IAAI,CAAC,IAAI,QAAQ,IAAI,qBAAqB,CAAC,CAAC;oBACtF,SAAS;gBACX,CAAC;gBACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,0DAA0D;gBAC1D,MAAM,CAAC,IAAI,CAAE,GAAa,CAAC,OAAO,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,GAAG;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;IACzC,CAAC;IAED,GAAG,CAAC,IAAY;QACd,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAED,8EAA8E;IAC9E,MAAM;QACJ,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Catalog } from "./catalog.js";
|
|
2
|
+
import type { KnowledgeIndex } from "./knowledge.js";
|
|
3
|
+
import type { MemoryStore } from "./memory.js";
|
|
4
|
+
import type { Agent, Briefing, Connector, Memory, RouteResult, Runbook, Skill, ToolDef, Topic } from "./types.js";
|
|
5
|
+
export interface BriefOptions {
|
|
6
|
+
/** Memory scopes to draw preferences from. */
|
|
7
|
+
scopes: string[];
|
|
8
|
+
memoryLimit: number;
|
|
9
|
+
knowledgeLimit: number;
|
|
10
|
+
/** Force a specific agent, bypassing the router. */
|
|
11
|
+
agentName?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class Router {
|
|
14
|
+
private readonly catalog;
|
|
15
|
+
private readonly memory;
|
|
16
|
+
private readonly knowledge;
|
|
17
|
+
private readonly options;
|
|
18
|
+
constructor(catalog: Catalog, memory: MemoryStore, knowledge: KnowledgeIndex, options: {
|
|
19
|
+
minScore: number;
|
|
20
|
+
ambiguityRatio: number;
|
|
21
|
+
});
|
|
22
|
+
/** Picks the best agent for a task, without assembling the rest of the briefing. */
|
|
23
|
+
routeAgent(task: string, context?: string): RouteResult;
|
|
24
|
+
private matchTopics;
|
|
25
|
+
/**
|
|
26
|
+
* Assembles everything the host needs to run one task: the agent, the skills
|
|
27
|
+
* and runbooks that apply, retrieved knowledge, the tools and connectors it may
|
|
28
|
+
* use, and the user's standing preferences — composed into one system prompt.
|
|
29
|
+
*/
|
|
30
|
+
brief(task: string, context: string, options: BriefOptions): Briefing | {
|
|
31
|
+
route: RouteResult;
|
|
32
|
+
};
|
|
33
|
+
private selectSkills;
|
|
34
|
+
private selectRunbooks;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Builds the system prompt handed to the subagent. Order matters: the agent's own
|
|
38
|
+
* instructions first, then the procedures it must follow, then reference material,
|
|
39
|
+
* then the user's standing preferences last so they are freshest in context.
|
|
40
|
+
*/
|
|
41
|
+
export declare function composePrompt(parts: {
|
|
42
|
+
agent: Agent;
|
|
43
|
+
skills: Skill[];
|
|
44
|
+
runbooks: Runbook[];
|
|
45
|
+
knowledge: {
|
|
46
|
+
id: string;
|
|
47
|
+
docName: string;
|
|
48
|
+
heading: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}[];
|
|
51
|
+
tools: ToolDef[];
|
|
52
|
+
connectors: Connector[];
|
|
53
|
+
memories: Memory[];
|
|
54
|
+
topics: Topic[];
|
|
55
|
+
}): string;
|