claude-flow 3.74.0 → 3.75.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/.claude/helpers/auto-memory-hook.mjs +262 -81
- package/node_modules/@claude-flow/codex/README.md +38 -0
- package/node_modules/@claude-flow/codex/dist/generators/agents-md.d.ts +1 -0
- package/node_modules/@claude-flow/codex/dist/generators/agents-md.d.ts.map +1 -1
- package/node_modules/@claude-flow/codex/dist/generators/agents-md.js +4 -4
- package/node_modules/@claude-flow/codex/dist/generators/agents-md.js.map +1 -1
- package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.d.ts +20 -0
- package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.d.ts.map +1 -0
- package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.js +104 -0
- package/node_modules/@claude-flow/codex/dist/generators/dual-instructions.js.map +1 -0
- package/node_modules/@claude-flow/codex/dist/generators/index.d.ts +2 -0
- package/node_modules/@claude-flow/codex/dist/generators/index.d.ts.map +1 -1
- package/node_modules/@claude-flow/codex/dist/generators/index.js +2 -0
- package/node_modules/@claude-flow/codex/dist/generators/index.js.map +1 -1
- package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.d.ts +46 -0
- package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.d.ts.map +1 -0
- package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.js +162 -0
- package/node_modules/@claude-flow/codex/dist/generators/shared-instructions.js.map +1 -0
- package/node_modules/@claude-flow/codex/dist/index.d.ts +3 -3
- package/node_modules/@claude-flow/codex/dist/index.js +1 -1
- package/node_modules/@claude-flow/codex/dist/initializer.d.ts.map +1 -1
- package/node_modules/@claude-flow/codex/dist/initializer.js +16 -93
- package/node_modules/@claude-flow/codex/dist/initializer.js.map +1 -1
- package/node_modules/@claude-flow/codex/package.json +8 -6
- package/node_modules/@claude-flow/mcp/README.md +44 -0
- package/node_modules/@claude-flow/mcp/package.json +16 -4
- package/package.json +4 -4
- package/v3/@claude-flow/cli/catalog-manifest.json +3 -3
- package/v3/@claude-flow/cli/dist/src/autopilot-state.js +17 -8
- package/v3/@claude-flow/cli/dist/src/commands/agent.js +2 -1
- package/v3/@claude-flow/cli/dist/src/commands/init.js +28 -6
- package/v3/@claude-flow/cli/dist/src/commands/memory-backup.js +2 -1
- package/v3/@claude-flow/cli/dist/src/commands/memory-distill.js +2 -1
- package/v3/@claude-flow/cli/dist/src/commands/memory.js +47 -3
- package/v3/@claude-flow/cli/dist/src/commands/neural.js +6 -5
- package/v3/@claude-flow/cli/dist/src/commands/plugins-host.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/commands/plugins-host.js +161 -0
- package/v3/@claude-flow/cli/dist/src/commands/plugins.js +3 -1
- package/v3/@claude-flow/cli/dist/src/commands/start-all.d.ts +28 -0
- package/v3/@claude-flow/cli/dist/src/commands/start-all.js +99 -0
- package/v3/@claude-flow/cli/dist/src/commands/start.d.ts +5 -1
- package/v3/@claude-flow/cli/dist/src/commands/start.js +17 -10
- package/v3/@claude-flow/cli/dist/src/commands/swarm.js +2 -1
- package/v3/@claude-flow/cli/dist/src/fs-secure.js +9 -2
- package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.d.ts +15 -0
- package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.js +64 -114
- package/v3/@claude-flow/cli/dist/src/init/dual-instructions.d.ts +29 -0
- package/v3/@claude-flow/cli/dist/src/init/dual-instructions.js +87 -0
- package/v3/@claude-flow/cli/dist/src/init/executor.js +96 -13
- package/v3/@claude-flow/cli/dist/src/init/index.d.ts +3 -1
- package/v3/@claude-flow/cli/dist/src/init/index.js +5 -1
- package/v3/@claude-flow/cli/dist/src/init/plugin-dedup.d.ts +61 -0
- package/v3/@claude-flow/cli/dist/src/init/plugin-dedup.js +130 -0
- package/v3/@claude-flow/cli/dist/src/init/shared-instructions.d.ts +46 -0
- package/v3/@claude-flow/cli/dist/src/init/shared-instructions.js +162 -0
- package/v3/@claude-flow/cli/dist/src/init/types.d.ts +33 -0
- package/v3/@claude-flow/cli/dist/src/init/types.js +3 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.d.ts +14 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +48 -5
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-hierarchical-inventory-tools.d.ts +15 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-hierarchical-inventory-tools.js +115 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-inventory-tools.d.ts +21 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-inventory-tools.js +152 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +56 -7
- package/v3/@claude-flow/cli/dist/src/mcp-tools/aidefence-known-misses.d.ts +6 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/aidefence-known-misses.js +23 -5
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +21 -3
- package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.d.ts +29 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +239 -19
- package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +53 -5
- package/v3/@claude-flow/cli/dist/src/memory/embedding-config.d.ts +79 -0
- package/v3/@claude-flow/cli/dist/src/memory/embedding-config.js +250 -0
- package/v3/@claude-flow/cli/dist/src/memory/ewc-consolidation.js +2 -1
- package/v3/@claude-flow/cli/dist/src/memory/intelligence.d.ts +28 -2
- package/v3/@claude-flow/cli/dist/src/memory/intelligence.js +37 -7
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +42 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +267 -28
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +1 -1
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +47 -22
- package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.js +3 -2
- package/v3/@claude-flow/cli/dist/src/ruvector/task-embedder.d.ts +2 -1
- package/v3/@claude-flow/cli/dist/src/ruvector/task-embedder.js +7 -3
- package/v3/@claude-flow/cli/dist/src/services/daemon-autostart.d.ts +4 -6
- package/v3/@claude-flow/cli/dist/src/services/daemon-autostart.js +6 -46
- package/v3/@claude-flow/cli/dist/src/services/host-executable.d.ts +68 -0
- package/v3/@claude-flow/cli/dist/src/services/host-executable.js +175 -0
- package/v3/@claude-flow/cli/dist/src/services/host-plugin-manager.d.ts +137 -0
- package/v3/@claude-flow/cli/dist/src/services/host-plugin-manager.js +374 -0
- package/v3/@claude-flow/cli/dist/src/services/project-root.d.ts +37 -0
- package/v3/@claude-flow/cli/dist/src/services/project-root.js +122 -0
- package/v3/@claude-flow/cli/package.json +7 -7
- package/.claude/.proven-config-version +0 -1
- package/.claude/proven-config.json +0 -42
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* agentdb_pattern-list / agentdb_skill-list / agentdb_skill-get /
|
|
3
|
+
* agentdb_hierarchical-stats (#4707).
|
|
4
|
+
*
|
|
5
|
+
* Read-only bindings over inventory APIs AgentDB already ships
|
|
6
|
+
* (ReasoningBank.listPatterns, SkillLibrary.listSkills/getSkill, agentdb >= 3.3.0)
|
|
7
|
+
* and the tiered store's counts (TieredMemoryStore.getTierStats/countPersisted).
|
|
8
|
+
* They go through the existing memory-bridge registry, so they read the same
|
|
9
|
+
* stores the write tools use. A controller or method the installed agentdb
|
|
10
|
+
* does not have comes back as `success: false, code: 'unsupported'`, never as
|
|
11
|
+
* an empty list.
|
|
12
|
+
*
|
|
13
|
+
* @module v3/cli/mcp-tools/agentdb-inventory-tools
|
|
14
|
+
*/
|
|
15
|
+
/** agentdb's MAX_LIST_LIMIT; a larger limit is rejected natively. */
|
|
16
|
+
const MAX_LIMIT = 500;
|
|
17
|
+
const DEFAULT_LIMIT = 50;
|
|
18
|
+
const MAX_OFFSET = 1_000_000_000;
|
|
19
|
+
const TASK_TYPE_MAX_LENGTH = 200;
|
|
20
|
+
let bridgeModule = null;
|
|
21
|
+
async function getBridge() {
|
|
22
|
+
bridgeModule ??= await import('../memory/memory-bridge.js');
|
|
23
|
+
return bridgeModule;
|
|
24
|
+
}
|
|
25
|
+
const unavailable = { success: false, error: 'AgentDB bridge not available. Use memory_list/memory_retrieve instead.' };
|
|
26
|
+
function fail(error) {
|
|
27
|
+
return { success: false, code: 'invalid-argument', error };
|
|
28
|
+
}
|
|
29
|
+
function errorMessage(error) {
|
|
30
|
+
return error instanceof Error ? error.message.replace(/\/[^\s:]+\//g, '<path>/').slice(0, 500) : 'Internal error';
|
|
31
|
+
}
|
|
32
|
+
/** Validate limit/offset; returns an error message or the clamped page. */
|
|
33
|
+
function readPage(params) {
|
|
34
|
+
const { limit, offset } = params;
|
|
35
|
+
if (limit !== undefined && (typeof limit !== 'number' || !Number.isFinite(limit)))
|
|
36
|
+
return 'limit must be a number';
|
|
37
|
+
if (offset !== undefined && (typeof offset !== 'number' || !Number.isFinite(offset) || offset < 0)) {
|
|
38
|
+
return 'offset must be a non-negative number';
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
limit: limit === undefined ? DEFAULT_LIMIT : Math.min(MAX_LIMIT, Math.max(1, Math.floor(limit))),
|
|
42
|
+
offset: offset === undefined ? 0 : Math.min(MAX_OFFSET, Math.floor(offset)),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const pageProperties = {
|
|
46
|
+
limit: { type: 'number', minimum: 1, maximum: MAX_LIMIT, default: DEFAULT_LIMIT, description: `Page size, clamped to 1..${MAX_LIMIT} (agentdb's own maximum).` },
|
|
47
|
+
offset: { type: 'number', minimum: 0, maximum: MAX_OFFSET, default: 0, description: 'Number of records to skip. For the next page pass offset + limit; stop when offset >= total.' },
|
|
48
|
+
};
|
|
49
|
+
export const agentdbPatternList = {
|
|
50
|
+
name: 'agentdb_pattern-list',
|
|
51
|
+
description: 'Page through every ReasoningBank pattern (the store agentdb_pattern-store writes), newest first, optionally filtered by exact taskType. Use when you need a complete inventory or audit of stored patterns: agentdb_pattern-search is wrong for that because it returns only the top-k most similar to a query. Returns the native page {items, total, limit, offset}; total counts every matching pattern, so page with offset until offset >= total. Pages are live reads, not a snapshot. Read-only. code=unsupported means the active ReasoningBank has no listPatterns (agentdb < 3.3.0 or the local fallback bank), which is not the same as an empty store.',
|
|
52
|
+
inputSchema: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
taskType: { type: 'string', minLength: 1, maxLength: TASK_TYPE_MAX_LENGTH, description: 'Only patterns with exactly this task type. Omit for all.' },
|
|
56
|
+
...pageProperties,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
handler: async (params) => {
|
|
60
|
+
try {
|
|
61
|
+
const taskType = params.taskType;
|
|
62
|
+
if (taskType !== undefined && (typeof taskType !== 'string' || taskType.length === 0 || taskType.length > TASK_TYPE_MAX_LENGTH)) {
|
|
63
|
+
return fail(`taskType must be a non-empty string of at most ${TASK_TYPE_MAX_LENGTH} characters`);
|
|
64
|
+
}
|
|
65
|
+
const page = readPage(params);
|
|
66
|
+
if (typeof page === 'string')
|
|
67
|
+
return fail(page);
|
|
68
|
+
const bridge = await getBridge();
|
|
69
|
+
const result = await bridge.bridgeListPatterns({ taskType: taskType, ...page });
|
|
70
|
+
return result ?? unavailable;
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
return { success: false, error: errorMessage(error) };
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
export const agentdbSkillList = {
|
|
78
|
+
name: 'agentdb_skill-list',
|
|
79
|
+
description: 'Page through every skill in the AgentDB SkillLibrary, newest first, optionally only those with successRate >= minSuccessRate. Use when you need the full set of learned skills or their ids for agentdb_skill-get; semantic retrieval is wrong for an inventory because it returns only the closest matches. Returns the native page {items, total, limit, offset}; total counts every matching skill, so page with offset until offset >= total. Pages are live reads, not a snapshot. Read-only. code=unsupported means no SkillLibrary or no listSkills (agentdb < 3.3.0); a graph-backed library refuses with its own error.',
|
|
80
|
+
inputSchema: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
properties: {
|
|
83
|
+
minSuccessRate: { type: 'number', minimum: 0, maximum: 1, description: 'Only skills whose successRate is at least this value (0..1). Omit for all.' },
|
|
84
|
+
...pageProperties,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
handler: async (params) => {
|
|
88
|
+
try {
|
|
89
|
+
const min = params.minSuccessRate;
|
|
90
|
+
if (min !== undefined && (typeof min !== 'number' || !Number.isFinite(min) || min < 0 || min > 1)) {
|
|
91
|
+
return fail('minSuccessRate must be a number between 0 and 1');
|
|
92
|
+
}
|
|
93
|
+
const page = readPage(params);
|
|
94
|
+
if (typeof page === 'string')
|
|
95
|
+
return fail(page);
|
|
96
|
+
const bridge = await getBridge();
|
|
97
|
+
const result = await bridge.bridgeListSkills({ minSuccessRate: min, ...page });
|
|
98
|
+
return result ?? unavailable;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return { success: false, error: errorMessage(error) };
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
export const agentdbSkillGet = {
|
|
106
|
+
name: 'agentdb_skill-get',
|
|
107
|
+
description: 'Read one AgentDB SkillLibrary skill by its numeric id (as listed by agentdb_skill-list). Use when you hold a skill id and need that exact record; a similarity search is wrong for this because it can return a different skill. found=false with skill=null means no skill has that id. Names are not accepted: AgentDB has no exact lookup by name, so list and pick the id. Read-only. code=unsupported means no SkillLibrary or no getSkill (agentdb < 3.3.0).',
|
|
108
|
+
inputSchema: {
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: {
|
|
111
|
+
id: { type: 'integer', minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: 'Positive integer skill id.' },
|
|
112
|
+
},
|
|
113
|
+
required: ['id'],
|
|
114
|
+
},
|
|
115
|
+
handler: async (params) => {
|
|
116
|
+
try {
|
|
117
|
+
const raw = params.id;
|
|
118
|
+
const id = typeof raw === 'string' && /^\d+$/.test(raw.trim()) ? Number(raw.trim()) : raw;
|
|
119
|
+
if (typeof id !== 'number' || !Number.isSafeInteger(id) || id < 1) {
|
|
120
|
+
return fail('id must be a positive integer skill id (names are not accepted)');
|
|
121
|
+
}
|
|
122
|
+
const bridge = await getBridge();
|
|
123
|
+
const result = await bridge.bridgeGetSkill({ id });
|
|
124
|
+
return result ?? unavailable;
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
return { success: false, error: errorMessage(error) };
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
export const agentdbHierarchicalStats = {
|
|
132
|
+
name: 'agentdb_hierarchical-stats',
|
|
133
|
+
description: 'Count-only view of the hierarchical memory store behind agentdb_hierarchical-store: tiers = in-memory entry counts per tier plus superseded (getTierStats), persistedRows = rows in the tiered_memory table (countPersisted, null on a volatile store). The two measure different things and need not agree. Use when you need to know how much hierarchical memory exists or whether writes are persisted; agentdb_hierarchical-recall is wrong for that because it ranks by relevance and returns no totals. Also reports controller, durable and persistence. It does not list entries. Read-only. code=unsupported means the active store has no such counts.',
|
|
134
|
+
inputSchema: { type: 'object', properties: {} },
|
|
135
|
+
handler: async () => {
|
|
136
|
+
try {
|
|
137
|
+
const bridge = await getBridge();
|
|
138
|
+
const result = await bridge.bridgeHierarchicalStats();
|
|
139
|
+
return result ?? unavailable;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return { success: false, error: errorMessage(error) };
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
export const agentdbInventoryTools = [
|
|
147
|
+
agentdbPatternList,
|
|
148
|
+
agentdbSkillList,
|
|
149
|
+
agentdbSkillGet,
|
|
150
|
+
agentdbHierarchicalStats,
|
|
151
|
+
];
|
|
152
|
+
//# sourceMappingURL=agentdb-inventory-tools.js.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { feedbackPatternsSchema, validateFeedbackPatterns } from '../memory/feedback-patterns.js';
|
|
2
|
+
import { agentdbInventoryTools } from './agentdb-inventory-tools.js';
|
|
2
3
|
import { validateIdentifier, validateText } from './validate-input.js';
|
|
3
4
|
import { agentdbEpisodeCrudTools } from './agentdb-episode-tools.js';
|
|
5
|
+
import { agentdbHierarchicalInventoryTools } from './agentdb-hierarchical-inventory-tools.js';
|
|
4
6
|
// ===== Shared validation helpers =====
|
|
5
7
|
const MAX_STRING_LENGTH = 100_000; // 100KB max for any string input
|
|
6
8
|
const MAX_BATCH_SIZE = 500; // Max entries per batch operation
|
|
@@ -297,6 +299,12 @@ export const agentdbPatternSearch = {
|
|
|
297
299
|
note: `ReasoningBank controller unavailable (controller=${result.controller}); results returned via the fallback path. Run \`agentdb_health\` to inspect controller registration.`,
|
|
298
300
|
};
|
|
299
301
|
}
|
|
302
|
+
// #4714 — an empty result is only a healthy zero-match when the
|
|
303
|
+
// ReasoningBank controller itself ran and reported no error. `null`
|
|
304
|
+
// (no registry) and `bridge-fallback` (controller not used) do not
|
|
305
|
+
// qualify, and neither does an empty list that carries a read error.
|
|
306
|
+
const reasoningBankError = typeof result?.error === 'string' ? result.error : undefined;
|
|
307
|
+
const reasoningBankRanClean = !!result && result.controller === 'reasoningBank' && !reasoningBankError;
|
|
300
308
|
// #1889 — symmetric fallback. pattern-store writes to the `pattern`
|
|
301
309
|
// namespace via memory_store when ReasoningBank is unavailable; the
|
|
302
310
|
// search path used to return an empty list with `controller: 'unavailable'`
|
|
@@ -357,12 +365,20 @@ export const agentdbPatternSearch = {
|
|
|
357
365
|
// getEntry (which DOES return content) before parsing/matching. This is the path
|
|
358
366
|
// that actually runs when the ReasoningBank controller is unavailable (the common
|
|
359
367
|
// real-world state), so a stored pattern is now findable by search.
|
|
368
|
+
// #4714 — a failed list or hydrate read must not pass as an empty scan.
|
|
369
|
+
let listError;
|
|
370
|
+
let scanLimited = false;
|
|
360
371
|
if (results.length === 0) {
|
|
361
372
|
tier = 'substring';
|
|
362
373
|
const all = await listEntries({ namespace: 'pattern', limit: 200 });
|
|
374
|
+
if (all && all.success === false)
|
|
375
|
+
listError = all.error ?? 'listEntries returned success:false';
|
|
376
|
+
const listed = all?.entries ?? [];
|
|
377
|
+
if (typeof all?.total === 'number' && all.total > listed.length)
|
|
378
|
+
scanLimited = true;
|
|
363
379
|
const qLower = query.toLowerCase();
|
|
364
380
|
const matched = [];
|
|
365
|
-
for (const e of
|
|
381
|
+
for (const e of listed) {
|
|
366
382
|
const meta = e;
|
|
367
383
|
let entry = meta;
|
|
368
384
|
// If the listing lacks content, hydrate it from the keyed store.
|
|
@@ -371,6 +387,8 @@ export const agentdbPatternSearch = {
|
|
|
371
387
|
if (!key)
|
|
372
388
|
continue;
|
|
373
389
|
const got = await getEntry({ key, namespace: 'pattern' });
|
|
390
|
+
if (got && got.success === false)
|
|
391
|
+
listError ??= got.error ?? `getEntry(${key}) returned success:false`;
|
|
374
392
|
if (!got?.found || !got.entry)
|
|
375
393
|
continue;
|
|
376
394
|
entry = got.entry;
|
|
@@ -393,20 +411,44 @@ export const agentdbPatternSearch = {
|
|
|
393
411
|
// #3288: degraded:true is the structural signal a caller can check
|
|
394
412
|
// without already knowing to distrust an apparently-successful
|
|
395
413
|
// response — matches agentbbs-tools.ts's degradedResult() convention.
|
|
414
|
+
//
|
|
415
|
+
// #4714 — except when nothing was found and nothing failed: the
|
|
416
|
+
// ReasoningBank controller ran cleanly and so did every legacy read.
|
|
417
|
+
// That is an honest "no match", not a degraded controller.
|
|
418
|
+
if (results.length === 0 && reasoningBankRanClean && !semanticError && !listError) {
|
|
419
|
+
return {
|
|
420
|
+
results: [],
|
|
421
|
+
noMatch: true,
|
|
422
|
+
degraded: false,
|
|
423
|
+
controller: 'reasoningBank',
|
|
424
|
+
searched: ['reasoningBank', 'pattern-namespace'],
|
|
425
|
+
// The legacy substring scan reads at most 200 entries; say so
|
|
426
|
+
// when the namespace holds more than that.
|
|
427
|
+
...(scanLimited ? { scanLimited: true } : {}),
|
|
428
|
+
note: 'No patterns matched the query in ReasoningBank or the legacy pattern namespace.',
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
const safeReasoningBankError = reasoningBankError ? sanitizeError(new Error(reasoningBankError)) : undefined;
|
|
396
432
|
return {
|
|
397
433
|
results,
|
|
398
434
|
degraded: true,
|
|
399
|
-
reason:
|
|
435
|
+
reason: safeReasoningBankError
|
|
436
|
+
? `reasoningBank-error:${safeReasoningBankError}`
|
|
437
|
+
: result ? `reasoningBank-empty:${result.controller ?? 'unknown'}` : 'reasoningBank-unavailable:registry-null',
|
|
400
438
|
controller: 'memory-store-fallback',
|
|
401
439
|
tier,
|
|
440
|
+
...(safeReasoningBankError ? { reasoningBankError: safeReasoningBankError } : {}),
|
|
402
441
|
// #3325: when tier=substring because tier 1 hit a real error (thrown,
|
|
403
442
|
// or {success:false, error}) rather than a genuine zero-match,
|
|
404
443
|
// surface why — otherwise a hard failure and an honest "not found"
|
|
405
444
|
// are indistinguishable from the response alone.
|
|
406
445
|
...(tier === 'substring' && semanticError ? { semanticError } : {}),
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
446
|
+
...(listError ? { listError } : {}),
|
|
447
|
+
note: safeReasoningBankError
|
|
448
|
+
? `ReasoningBank search failed; tier=${tier} from pattern namespace.`
|
|
449
|
+
: result
|
|
450
|
+
? `ReasoningBank returned 0 results; tier=${tier} from pattern namespace.`
|
|
451
|
+
: `ReasoningBank controller unavailable; tier=${tier} from pattern namespace.`,
|
|
410
452
|
};
|
|
411
453
|
}
|
|
412
454
|
catch (fallbackErr) {
|
|
@@ -770,7 +812,12 @@ export const agentdbHierarchicalStore = {
|
|
|
770
812
|
type: 'object',
|
|
771
813
|
properties: {
|
|
772
814
|
key: { type: 'string', description: 'Memory entry key' },
|
|
773
|
-
value: {
|
|
815
|
+
value: {
|
|
816
|
+
type: 'string',
|
|
817
|
+
minLength: 1,
|
|
818
|
+
maxLength: 10000,
|
|
819
|
+
description: 'Memory entry value. Non-empty, max 10000 UTF-16 code units (JavaScript string length); longer values are refused. JSON Schema maxLength counts code points, so text with astral characters (emoji, some CJK) can pass this schema and still exceed the limit — each such character counts as 2.',
|
|
820
|
+
},
|
|
774
821
|
tier: {
|
|
775
822
|
type: 'string',
|
|
776
823
|
description: 'Memory tier (working, episodic, semantic)',
|
|
@@ -810,7 +857,7 @@ export const agentdbHierarchicalStore = {
|
|
|
810
857
|
if (!key)
|
|
811
858
|
return { success: false, error: 'key is required (non-empty string, max 1KB)' };
|
|
812
859
|
if (!value)
|
|
813
|
-
return { success: false, error: 'value is required (non-empty string, max
|
|
860
|
+
return { success: false, error: 'value is required (non-empty string, max 10000 characters)' };
|
|
814
861
|
const tier = validateString(params.tier, 'tier', 20) ?? 'working';
|
|
815
862
|
if (!['working', 'episodic', 'semantic'].includes(tier)) {
|
|
816
863
|
return { success: false, error: `Invalid tier: ${tier}. Must be working, episodic, or semantic` };
|
|
@@ -1646,5 +1693,7 @@ export const agentdbTools = [
|
|
|
1646
1693
|
agentdbSemanticRoute,
|
|
1647
1694
|
agentdbGraphQuery, // ADR-130 Phase 2
|
|
1648
1695
|
agentdbGraphPathfinder, // ADR-130 Phase 5
|
|
1696
|
+
...agentdbHierarchicalInventoryTools, // #4712
|
|
1697
|
+
...agentdbInventoryTools, // #4707
|
|
1649
1698
|
];
|
|
1650
1699
|
//# sourceMappingURL=agentdb-tools.js.map
|
|
@@ -18,5 +18,11 @@ export interface KnownMiss {
|
|
|
18
18
|
export declare function hashInput(input: string): string;
|
|
19
19
|
/** Returns true when the miss was newly recorded, false when it was already known. */
|
|
20
20
|
export declare function recordKnownMiss(input: string, threatType: string, cwd?: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Removes exactly the entry whose hash AND threatType match (#4862), leaving
|
|
23
|
+
* every other entry in place. Returns true when an entry was removed. When
|
|
24
|
+
* nothing matches the store is not rewritten, so a no-op leaves it untouched.
|
|
25
|
+
*/
|
|
26
|
+
export declare function retractKnownMiss(input: string, threatType: string, cwd?: string): boolean;
|
|
21
27
|
export declare function findKnownMiss(input: string, cwd?: string): KnownMiss | undefined;
|
|
22
28
|
//# sourceMappingURL=aidefence-known-misses.d.ts.map
|
|
@@ -33,6 +33,14 @@ function load(cwd) {
|
|
|
33
33
|
return [];
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
+
/** Atomic write: temp file in the same directory, then rename over the store. */
|
|
37
|
+
function save(cwd, entries) {
|
|
38
|
+
const dir = join(cwd, '.claude-flow');
|
|
39
|
+
mkdirSync(dir, { recursive: true });
|
|
40
|
+
const tmp = `${storePath(cwd)}.${process.pid}.tmp`;
|
|
41
|
+
writeFileSync(tmp, JSON.stringify(entries.slice(-MAX_ENTRIES), null, 2), { mode: 0o600 });
|
|
42
|
+
renameSync(tmp, storePath(cwd));
|
|
43
|
+
}
|
|
36
44
|
/** Returns true when the miss was newly recorded, false when it was already known. */
|
|
37
45
|
export function recordKnownMiss(input, threatType, cwd = process.cwd()) {
|
|
38
46
|
const hash = hashInput(input);
|
|
@@ -40,11 +48,21 @@ export function recordKnownMiss(input, threatType, cwd = process.cwd()) {
|
|
|
40
48
|
if (entries.some((e) => e.hash === hash))
|
|
41
49
|
return false;
|
|
42
50
|
entries.push({ hash, threatType, reportedAt: new Date().toISOString() });
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
save(cwd, entries);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Removes exactly the entry whose hash AND threatType match (#4862), leaving
|
|
56
|
+
* every other entry in place. Returns true when an entry was removed. When
|
|
57
|
+
* nothing matches the store is not rewritten, so a no-op leaves it untouched.
|
|
58
|
+
*/
|
|
59
|
+
export function retractKnownMiss(input, threatType, cwd = process.cwd()) {
|
|
60
|
+
const hash = hashInput(input);
|
|
61
|
+
const entries = load(cwd);
|
|
62
|
+
const kept = entries.filter((e) => !(e.hash === hash && e.threatType === threatType));
|
|
63
|
+
if (kept.length === entries.length)
|
|
64
|
+
return false;
|
|
65
|
+
save(cwd, kept);
|
|
48
66
|
return true;
|
|
49
67
|
}
|
|
50
68
|
export function findKnownMiss(input, cwd = process.cwd()) {
|
|
@@ -1643,16 +1643,34 @@ export const hooksPreTask = {
|
|
|
1643
1643
|
};
|
|
1644
1644
|
},
|
|
1645
1645
|
};
|
|
1646
|
+
// #4887 — advertise the grammar validateIdentifier() (cli-core) plus the CLI
|
|
1647
|
+
// reserved-name wrapper enforce, so callers learn it from the schema instead of
|
|
1648
|
+
// from a refusal. NATIVE_ID_PATTERN is IDENTIFIER_RE (with '-' moved last so no
|
|
1649
|
+
// escape is needed); the shell-meta and path-traversal checks can never fire on a
|
|
1650
|
+
// string it accepts. ASCII-only, so maxLength (code points) and the 128 .length
|
|
1651
|
+
// cap agree. The HTTP transport enforces pattern/minLength at runtime, so a
|
|
1652
|
+
// field the handler treats as omitted when empty (agent) must accept ''.
|
|
1653
|
+
const NATIVE_ID_BODY = '[a-zA-Z0-9_][a-zA-Z0-9_.:-]{0,127}';
|
|
1654
|
+
const NATIVE_ID_RESERVED = ['__proto__', 'constructor', 'prototype'];
|
|
1655
|
+
const NATIVE_ID_RULES = '1-128 chars of A-Z a-z 0-9 _ - . : (first char alphanumeric or _); not __proto__, constructor or prototype. Must be a registered native ID, not a host path such as /root/x.';
|
|
1656
|
+
const nativeIdSchema = (description, opts = {}) => ({
|
|
1657
|
+
type: 'string',
|
|
1658
|
+
...(opts.emptyMeansOmitted ? {} : { minLength: 1 }),
|
|
1659
|
+
maxLength: 128,
|
|
1660
|
+
pattern: opts.emptyMeansOmitted ? `^(?:${NATIVE_ID_BODY})?$` : `^${NATIVE_ID_BODY}$`,
|
|
1661
|
+
not: { enum: NATIVE_ID_RESERVED },
|
|
1662
|
+
description: `${description} ${NATIVE_ID_RULES}`,
|
|
1663
|
+
});
|
|
1646
1664
|
export const hooksPostTask = {
|
|
1647
1665
|
name: 'hooks_post-task',
|
|
1648
1666
|
description: 'Record task completion for learning Use when native Bash hooks (via Claude Code\'s settings.json) are wrong because you need Ruflo-side state — pattern persistence, neural training signals, model-routing learning, cost tracking, audit chain. For one-off shell commands, plain Bash hooks are fine.',
|
|
1649
1667
|
inputSchema: {
|
|
1650
1668
|
type: 'object',
|
|
1651
1669
|
properties: {
|
|
1652
|
-
taskId:
|
|
1670
|
+
taskId: nativeIdSchema('Task identifier.'),
|
|
1653
1671
|
patterns: feedbackPatternsSchema,
|
|
1654
1672
|
success: { type: 'boolean', description: 'Whether task was successful' },
|
|
1655
|
-
agent:
|
|
1673
|
+
agent: nativeIdSchema('Agent that completed the task. An empty string is treated as omitted.', { emptyMeansOmitted: true }),
|
|
1656
1674
|
quality: { type: 'number', minimum: 0, maximum: 1, description: 'Quality score (0-1)' },
|
|
1657
1675
|
task: { type: 'string', description: 'Task description text (used for learning keyword extraction)' },
|
|
1658
1676
|
duration: { type: 'number', description: 'Observed task duration in milliseconds (used by pheromone-adaptive topology)' },
|
|
@@ -1661,7 +1679,7 @@ export const hooksPostTask = {
|
|
|
1661
1679
|
agentRole: { type: 'string', description: 'Role for role-local pheromone normalization (default agent)' },
|
|
1662
1680
|
storeDecisions: { type: 'boolean', description: 'Also store routing decision in memory DB' },
|
|
1663
1681
|
// ADR-147 P2: nested-subagent spawn-tree capture
|
|
1664
|
-
parentAgentId:
|
|
1682
|
+
parentAgentId: nativeIdSchema('ID of the parent agent (from Claude Code\'s parent_agent_id OTel span tag / x-claude-code-parent-agent-id header). Omit for top-level work.'),
|
|
1665
1683
|
depth: { type: 'number', description: 'Chain depth from root lead session (0 = lead, 1+ = subagent). Used by ADR-147 P3 depth-aware guardrail.' },
|
|
1666
1684
|
},
|
|
1667
1685
|
required: ['taskId'],
|
|
@@ -17,5 +17,34 @@ export declare const DANGEROUS_KEY_PATTERN: RegExp;
|
|
|
17
17
|
* do not. Returns the error message, or null when the key is acceptable.
|
|
18
18
|
*/
|
|
19
19
|
export declare function memoryKeyError(key: string): string | null;
|
|
20
|
+
export declare const MEMORY_SCOPES: readonly ["project", "local", "user"];
|
|
21
|
+
export type MemoryScope = typeof MEMORY_SCOPES[number];
|
|
22
|
+
export declare const SCOPED_NAMESPACE_PREFIX = "agent-memory";
|
|
23
|
+
export type ScopedNamespace = {
|
|
24
|
+
ok: true;
|
|
25
|
+
namespace: string;
|
|
26
|
+
scope?: MemoryScope;
|
|
27
|
+
agentId?: string;
|
|
28
|
+
} | {
|
|
29
|
+
ok: false;
|
|
30
|
+
error: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the namespace a memory operation actually reads or writes.
|
|
34
|
+
* `scope`/`agentId` absent → `namespace` unchanged. Otherwise both are
|
|
35
|
+
* validated and the result is the prefixed form, itself run through the
|
|
36
|
+
* namespace validator so the stored namespace stays exportable and purgeable.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveScopedNamespace(opts: {
|
|
39
|
+
scope?: unknown;
|
|
40
|
+
agentId?: unknown;
|
|
41
|
+
namespace: string;
|
|
42
|
+
}): ScopedNamespace;
|
|
43
|
+
/** Inverse of resolveScopedNamespace; null for an unscoped namespace. */
|
|
44
|
+
export declare function parseScopedNamespace(stored: string): {
|
|
45
|
+
scope: MemoryScope;
|
|
46
|
+
agentId: string;
|
|
47
|
+
namespace: string;
|
|
48
|
+
} | null;
|
|
20
49
|
export declare const memoryTools: MCPTool[];
|
|
21
50
|
//# sourceMappingURL=memory-tools.d.ts.map
|