@monoes/monomindcli 2.16.11 → 2.16.13
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/agents/core/coder.md +1 -1
- package/.claude/agents/engineering/engineering-devops-automator.md +1 -1
- package/.claude/agents/github/repo-architect.md +1 -1
- package/.claude/agents/testing/production-validator.md +1 -1
- package/.claude/agents/testing/testing-tool-evaluator.md +1 -1
- package/.claude/commands/github/pr-manager.md +1 -1
- package/.claude/helpers/pick-rank.cjs +34 -4
- package/.claude/skills/monolean-audit/SKILL.md +1 -1
- package/dist/src/commands/cleanup-data.d.ts +30 -0
- package/dist/src/commands/cleanup-data.d.ts.map +1 -0
- package/dist/src/commands/cleanup-data.js +138 -0
- package/dist/src/commands/cleanup-data.js.map +1 -0
- package/dist/src/commands/cleanup-origin.d.ts +24 -0
- package/dist/src/commands/cleanup-origin.d.ts.map +1 -0
- package/dist/src/commands/cleanup-origin.js +67 -0
- package/dist/src/commands/cleanup-origin.js.map +1 -0
- package/dist/src/commands/cleanup-scratch.d.ts +43 -0
- package/dist/src/commands/cleanup-scratch.d.ts.map +1 -0
- package/dist/src/commands/cleanup-scratch.js +125 -0
- package/dist/src/commands/cleanup-scratch.js.map +1 -0
- package/dist/src/commands/cleanup.d.ts +2 -39
- package/dist/src/commands/cleanup.d.ts.map +1 -1
- package/dist/src/commands/cleanup.js +9 -296
- package/dist/src/commands/cleanup.js.map +1 -1
- package/dist/src/commands/doctor-gitignore-checks.d.ts +10 -0
- package/dist/src/commands/doctor-gitignore-checks.d.ts.map +1 -0
- package/dist/src/commands/doctor-gitignore-checks.js +141 -0
- package/dist/src/commands/doctor-gitignore-checks.js.map +1 -0
- package/dist/src/commands/doctor-helpers-checks.d.ts +10 -0
- package/dist/src/commands/doctor-helpers-checks.d.ts.map +1 -0
- package/dist/src/commands/doctor-helpers-checks.js +292 -0
- package/dist/src/commands/doctor-helpers-checks.js.map +1 -0
- package/dist/src/commands/doctor-memory-checks.d.ts +47 -0
- package/dist/src/commands/doctor-memory-checks.d.ts.map +1 -0
- package/dist/src/commands/doctor-memory-checks.js +298 -0
- package/dist/src/commands/doctor-memory-checks.js.map +1 -0
- package/dist/src/commands/doctor-monograph-checks.d.ts +9 -0
- package/dist/src/commands/doctor-monograph-checks.d.ts.map +1 -0
- package/dist/src/commands/doctor-monograph-checks.js +331 -0
- package/dist/src/commands/doctor-monograph-checks.js.map +1 -0
- package/dist/src/commands/doctor-project-checks.d.ts +7 -66
- package/dist/src/commands/doctor-project-checks.d.ts.map +1 -1
- package/dist/src/commands/doctor-project-checks.js +10 -1331
- package/dist/src/commands/doctor-project-checks.js.map +1 -1
- package/dist/src/commands/doctor-routing-checks.d.ts +10 -0
- package/dist/src/commands/doctor-routing-checks.d.ts.map +1 -0
- package/dist/src/commands/doctor-routing-checks.js +194 -0
- package/dist/src/commands/doctor-routing-checks.js.map +1 -0
- package/dist/src/commands/doctor-worker-checks.d.ts +17 -0
- package/dist/src/commands/doctor-worker-checks.d.ts.map +1 -0
- package/dist/src/commands/doctor-worker-checks.js +122 -0
- package/dist/src/commands/doctor-worker-checks.js.map +1 -0
- package/dist/src/commands/hooks-routing-commands.js +1 -1
- package/dist/src/commands/hooks-routing-commands.js.map +1 -1
- package/dist/src/commands/init.d.ts.map +1 -1
- package/dist/src/commands/init.js +6 -15
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/never-commit.d.ts +3 -3
- package/dist/src/init/types.d.ts +1 -1
- package/dist/src/init/types.js +1 -1
- package/dist/src/knowledge/document-store.js +1 -1
- package/dist/src/knowledge/document-store.js.map +1 -1
- package/dist/src/mcp-tools/hooks-edit-command.d.ts +10 -0
- package/dist/src/mcp-tools/hooks-edit-command.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-edit-command.js +247 -0
- package/dist/src/mcp-tools/hooks-edit-command.js.map +1 -0
- package/dist/src/mcp-tools/hooks-learning.d.ts +9 -0
- package/dist/src/mcp-tools/hooks-learning.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-learning.js +408 -0
- package/dist/src/mcp-tools/hooks-learning.js.map +1 -0
- package/dist/src/mcp-tools/hooks-metrics-list.d.ts +8 -0
- package/dist/src/mcp-tools/hooks-metrics-list.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-metrics-list.js +205 -0
- package/dist/src/mcp-tools/hooks-metrics-list.js.map +1 -0
- package/dist/src/mcp-tools/hooks-route.d.ts +12 -0
- package/dist/src/mcp-tools/hooks-route.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-route.js +251 -0
- package/dist/src/mcp-tools/hooks-route.js.map +1 -0
- package/dist/src/mcp-tools/hooks-routing.d.ts +6 -27
- package/dist/src/mcp-tools/hooks-routing.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-routing.js +6 -1727
- package/dist/src/mcp-tools/hooks-routing.js.map +1 -1
- package/dist/src/mcp-tools/hooks-session.d.ts +9 -0
- package/dist/src/mcp-tools/hooks-session.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-session.js +243 -0
- package/dist/src/mcp-tools/hooks-session.js.map +1 -0
- package/dist/src/mcp-tools/hooks-task.d.ts +17 -0
- package/dist/src/mcp-tools/hooks-task.d.ts.map +1 -0
- package/dist/src/mcp-tools/hooks-task.js +427 -0
- package/dist/src/mcp-tools/hooks-task.js.map +1 -0
- package/dist/src/mcp-tools/hooks-tools.d.ts +2 -1
- package/dist/src/mcp-tools/hooks-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +2 -1
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +1 -1
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/memory/bm25-index.d.ts +2 -2
- package/dist/src/memory/bm25-index.js +2 -2
- package/dist/src/memory/embedding-operations.js +2 -2
- package/dist/src/memory/embedding-operations.js.map +1 -1
- package/dist/src/memory/entity-name-key.d.ts +1 -1
- package/dist/src/memory/entity-name-key.js +1 -1
- package/dist/src/memory/hnsw-operations.d.ts +1 -1
- package/dist/src/memory/hnsw-operations.js +1 -1
- package/dist/src/memory/memory-bridge-backend.d.ts +43 -0
- package/dist/src/memory/memory-bridge-backend.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-backend.js +363 -0
- package/dist/src/memory/memory-bridge-backend.js.map +1 -0
- package/dist/src/memory/memory-bridge-core.d.ts +42 -0
- package/dist/src/memory/memory-bridge-core.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-core.js +126 -0
- package/dist/src/memory/memory-bridge-core.js.map +1 -0
- package/dist/src/memory/memory-bridge-entries.d.ts +131 -0
- package/dist/src/memory/memory-bridge-entries.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-entries.js +227 -0
- package/dist/src/memory/memory-bridge-entries.js.map +1 -0
- package/dist/src/memory/memory-bridge-feedback.d.ts +60 -0
- package/dist/src/memory/memory-bridge-feedback.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-feedback.js +118 -0
- package/dist/src/memory/memory-bridge-feedback.js.map +1 -0
- package/dist/src/memory/memory-bridge-paths.d.ts +123 -0
- package/dist/src/memory/memory-bridge-paths.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-paths.js +335 -0
- package/dist/src/memory/memory-bridge-paths.js.map +1 -0
- package/dist/src/memory/memory-bridge-search.d.ts +48 -0
- package/dist/src/memory/memory-bridge-search.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-search.js +383 -0
- package/dist/src/memory/memory-bridge-search.js.map +1 -0
- package/dist/src/memory/memory-bridge-sessions.d.ts +38 -0
- package/dist/src/memory/memory-bridge-sessions.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-sessions.js +109 -0
- package/dist/src/memory/memory-bridge-sessions.js.map +1 -0
- package/dist/src/memory/memory-bridge-store.d.ts +58 -0
- package/dist/src/memory/memory-bridge-store.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge-store.js +201 -0
- package/dist/src/memory/memory-bridge-store.js.map +1 -0
- package/dist/src/memory/memory-bridge.d.ts +10 -438
- package/dist/src/memory/memory-bridge.d.ts.map +1 -1
- package/dist/src/memory/memory-bridge.js +14 -1787
- package/dist/src/memory/memory-bridge.js.map +1 -1
- package/dist/src/memory/memory-kg-claims.d.ts +52 -0
- package/dist/src/memory/memory-kg-claims.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-claims.js +99 -0
- package/dist/src/memory/memory-kg-claims.js.map +1 -0
- package/dist/src/memory/memory-kg-index.d.ts +86 -0
- package/dist/src/memory/memory-kg-index.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-index.js +256 -0
- package/dist/src/memory/memory-kg-index.js.map +1 -0
- package/dist/src/memory/memory-kg-ingest.d.ts +44 -0
- package/dist/src/memory/memory-kg-ingest.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-ingest.js +361 -0
- package/dist/src/memory/memory-kg-ingest.js.map +1 -0
- package/dist/src/memory/memory-kg-model.d.ts +168 -0
- package/dist/src/memory/memory-kg-model.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-model.js +158 -0
- package/dist/src/memory/memory-kg-model.js.map +1 -0
- package/dist/src/memory/memory-kg-names.d.ts +64 -0
- package/dist/src/memory/memory-kg-names.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-names.js +187 -0
- package/dist/src/memory/memory-kg-names.js.map +1 -0
- package/dist/src/memory/memory-kg-promote.d.ts +79 -0
- package/dist/src/memory/memory-kg-promote.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-promote.js +248 -0
- package/dist/src/memory/memory-kg-promote.js.map +1 -0
- package/dist/src/memory/memory-kg-rebuild.d.ts +77 -0
- package/dist/src/memory/memory-kg-rebuild.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-rebuild.js +299 -0
- package/dist/src/memory/memory-kg-rebuild.js.map +1 -0
- package/dist/src/memory/memory-kg-rollback.d.ts +47 -0
- package/dist/src/memory/memory-kg-rollback.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-rollback.js +193 -0
- package/dist/src/memory/memory-kg-rollback.js.map +1 -0
- package/dist/src/memory/memory-kg-rules.d.ts +64 -0
- package/dist/src/memory/memory-kg-rules.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-rules.js +251 -0
- package/dist/src/memory/memory-kg-rules.js.map +1 -0
- package/dist/src/memory/memory-kg-scan.d.ts +118 -0
- package/dist/src/memory/memory-kg-scan.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-scan.js +209 -0
- package/dist/src/memory/memory-kg-scan.js.map +1 -0
- package/dist/src/memory/memory-kg-search.d.ts +80 -0
- package/dist/src/memory/memory-kg-search.d.ts.map +1 -0
- package/dist/src/memory/memory-kg-search.js +239 -0
- package/dist/src/memory/memory-kg-search.js.map +1 -0
- package/dist/src/memory/memory-kg.d.ts +19 -547
- package/dist/src/memory/memory-kg.d.ts.map +1 -1
- package/dist/src/memory/memory-kg.js +10 -2389
- package/dist/src/memory/memory-kg.js.map +1 -1
- package/dist/src/orgrt/sandbox-stubs.d.ts +4 -0
- package/dist/src/orgrt/sandbox-stubs.d.ts.map +1 -1
- package/dist/src/orgrt/sandbox-stubs.js +12 -2
- package/dist/src/orgrt/sandbox-stubs.js.map +1 -1
- package/dist/src/ui/org-hil.mjs +1 -1
- package/dist/src/ui/routes-org-agents.mjs +318 -0
- package/dist/src/ui/routes-org-approvals.mjs +133 -0
- package/dist/src/ui/routes-org-config.mjs +459 -0
- package/dist/src/ui/routes-org-control.mjs +300 -0
- package/dist/src/ui/routes-org-files.mjs +172 -0
- package/dist/src/ui/routes-org-helpers.mjs +84 -0
- package/dist/src/ui/routes-org-knowledge.mjs +262 -0
- package/dist/src/ui/routes-org-lifecycle.mjs +224 -0
- package/dist/src/ui/routes-org-live.mjs +278 -0
- package/dist/src/ui/routes-org-mastermind.mjs +346 -0
- package/dist/src/ui/routes-org-planning.mjs +398 -0
- package/dist/src/ui/routes-org-runs.mjs +430 -0
- package/dist/src/ui/routes-org-status.mjs +342 -0
- package/dist/src/ui/routes-org-workflows.mjs +212 -0
- package/dist/src/ui/routes-org.mjs +26 -3847
- package/dist/src/ui/server.mjs +1 -1
- package/dist/src/utils/native-error.d.ts +1 -1
- package/dist/src/utils/native-error.js +1 -1
- package/dist/src/utils/paths.d.ts +2 -1
- package/dist/src/utils/paths.d.ts.map +1 -1
- package/dist/src/utils/paths.js +2 -1
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/org-skills/adversarial-reviewer/SKILL.md +1 -1
- package/org-skills/board-deck-builder/SKILL.md +1 -1
- package/org-skills/code-reviewer/SKILL.md +1 -1
- package/org-skills/debugging-wizard/SKILL.md +1 -1
- package/org-skills/scientific-thinking-literature-review/SKILL.md +1 -1
- package/org-skills/scientific-thinking-scholar-evaluation/SKILL.md +1 -1
- package/package.json +8 -8
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hooks MCP Tools — pretrain, transfer and intelligence.
|
|
3
|
+
* Extracted from hooks-routing.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { join, resolve, sep } from 'node:path';
|
|
7
|
+
import { DEFAULT_EMBEDDING_DIMS, DEFAULT_EMBEDDING_MODEL } from '../init/types.js';
|
|
8
|
+
import { validateMcpString } from '../utils/input-guards.js';
|
|
9
|
+
import { mergeRecordsById } from '../utils/json-file.js';
|
|
10
|
+
import { getIntelligenceStatsFromMemory, getSONAOptimizer } from './hooks-embedding.js';
|
|
11
|
+
import { getProjectCwd } from './types.js';
|
|
12
|
+
// Pretrain hook - repository analysis for intelligence bootstrap
|
|
13
|
+
export const hooksPretrain = {
|
|
14
|
+
name: 'hooks_pretrain',
|
|
15
|
+
description: 'Walk the repository counting file extensions and directory patterns to seed the keyword router. This is a filesystem scan writing JSON state — despite the name, no model is trained.',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
path: { type: 'string', description: 'Repository path' },
|
|
20
|
+
depth: { type: 'string', description: 'Analysis depth (shallow, medium, deep)' },
|
|
21
|
+
skipCache: { type: 'boolean', description: 'Skip cached analysis' },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
handler: async (params) => {
|
|
25
|
+
const repoPath = resolve(validateMcpString(params.path, 'path', 4 * 1024) ?? '.');
|
|
26
|
+
const projectRoot = getProjectCwd();
|
|
27
|
+
if (repoPath !== projectRoot && !repoPath.startsWith(projectRoot + sep)) {
|
|
28
|
+
return { error: 'Invalid path: must be within the project directory.' };
|
|
29
|
+
}
|
|
30
|
+
const depth = validateMcpString(params.depth, 'depth', 16) ?? 'medium';
|
|
31
|
+
const allowedDepths = new Set(['shallow', 'medium', 'deep']);
|
|
32
|
+
if (!allowedDepths.has(depth)) {
|
|
33
|
+
return { error: 'Invalid depth: must be shallow, medium, or deep' };
|
|
34
|
+
}
|
|
35
|
+
const startTime = performance.now();
|
|
36
|
+
// Real file scanning — count files by extension, extract patterns
|
|
37
|
+
const { readdirSync, statSync } = await import('node:fs');
|
|
38
|
+
const extCounts = {};
|
|
39
|
+
let filesAnalyzed = 0;
|
|
40
|
+
let totalLines = 0;
|
|
41
|
+
const maxDepth = depth === 'shallow' ? 2 : depth === 'deep' ? 6 : 4;
|
|
42
|
+
const patterns = [];
|
|
43
|
+
const scan = (dir, currentDepth) => {
|
|
44
|
+
if (currentDepth > maxDepth)
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
if (entry.name.startsWith('.') || entry.name === 'node_modules' || entry.name === 'dist')
|
|
50
|
+
continue;
|
|
51
|
+
const full = join(dir, entry.name);
|
|
52
|
+
if (entry.isDirectory()) {
|
|
53
|
+
scan(full, currentDepth + 1);
|
|
54
|
+
}
|
|
55
|
+
else if (entry.isFile()) {
|
|
56
|
+
const ext = entry.name.includes('.')
|
|
57
|
+
? entry.name.slice(entry.name.lastIndexOf('.'))
|
|
58
|
+
: '';
|
|
59
|
+
if (ext)
|
|
60
|
+
extCounts[ext] = (extCounts[ext] || 0) + 1;
|
|
61
|
+
filesAnalyzed++;
|
|
62
|
+
// For code files, count lines and extract imports
|
|
63
|
+
if (['.ts', '.js', '.py', '.go', '.rs', '.java'].includes(ext)) {
|
|
64
|
+
try {
|
|
65
|
+
// Skip very large files (minified bundles, generated code) to prevent OOM.
|
|
66
|
+
// 1 MB is generous for a source file; anything larger is unlikely to have
|
|
67
|
+
// useful import patterns in the first 30 lines anyway.
|
|
68
|
+
const MAX_CODE_FILE_BYTES = 1 * 1024 * 1024;
|
|
69
|
+
if (statSync(full).size > MAX_CODE_FILE_BYTES)
|
|
70
|
+
continue;
|
|
71
|
+
const content = readFileSync(full, 'utf-8');
|
|
72
|
+
const lines = content.split('\n');
|
|
73
|
+
totalLines += lines.length;
|
|
74
|
+
// Extract import patterns (first 50 files max for performance)
|
|
75
|
+
if (filesAnalyzed <= 50) {
|
|
76
|
+
for (const line of lines.slice(0, 30)) {
|
|
77
|
+
if (line.startsWith('import ') ||
|
|
78
|
+
line.startsWith('from ') ||
|
|
79
|
+
(line.startsWith('const ') && line.includes('require('))) {
|
|
80
|
+
const trimmed = line.trim();
|
|
81
|
+
if (trimmed.length < 120 && !patterns.includes(trimmed))
|
|
82
|
+
patterns.push(trimmed);
|
|
83
|
+
if (patterns.length >= 100)
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
/* skip unreadable */
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
/* skip inaccessible dirs */
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
scan(repoPath, 0);
|
|
101
|
+
const elapsed = Math.round(performance.now() - startTime);
|
|
102
|
+
// Store extracted patterns in memory backend
|
|
103
|
+
let patternsStored = 0;
|
|
104
|
+
try {
|
|
105
|
+
const bridge = await import('../memory/memory-bridge.js');
|
|
106
|
+
const stored = await bridge.bridgeStoreEntry({
|
|
107
|
+
key: `pretrain-${Date.now()}`,
|
|
108
|
+
value: JSON.stringify({
|
|
109
|
+
filesAnalyzed,
|
|
110
|
+
totalLines,
|
|
111
|
+
topExtensions: Object.entries(extCounts)
|
|
112
|
+
.sort((a, b) => b[1] - a[1])
|
|
113
|
+
.slice(0, 10),
|
|
114
|
+
importPatterns: patterns.slice(0, 20),
|
|
115
|
+
}),
|
|
116
|
+
namespace: 'pretrain',
|
|
117
|
+
tags: ['pretrain', depth],
|
|
118
|
+
});
|
|
119
|
+
// #293: only count what actually persisted. bridgeStoreEntry returns
|
|
120
|
+
// null (never throws) when the backend cannot be loaded, so this used to
|
|
121
|
+
// report every scanned pattern as stored on a store that did nothing.
|
|
122
|
+
if (stored?.success)
|
|
123
|
+
patternsStored = patterns.length;
|
|
124
|
+
else
|
|
125
|
+
console.warn(`[hooks-pretrain] patterns were NOT stored (${stored?.error ?? 'memory backend unavailable'})`);
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
/* memory backend unavailable */
|
|
129
|
+
if (process.env.DEBUG || process.env.MONOMIND_DEBUG)
|
|
130
|
+
console.error('[hooks-pretrain] pattern store failed:', e);
|
|
131
|
+
}
|
|
132
|
+
// Feed extracted import patterns into the neural training system so
|
|
133
|
+
// pretrain actually trains, not just scans.
|
|
134
|
+
let neuralPatternsLearned = 0;
|
|
135
|
+
if (patterns.length > 0) {
|
|
136
|
+
try {
|
|
137
|
+
const intel = await import('../memory/intelligence.js');
|
|
138
|
+
await intel.initializeIntelligence({
|
|
139
|
+
confidenceLearningRate: 0.002,
|
|
140
|
+
maxTrajectorySize: patterns.length,
|
|
141
|
+
});
|
|
142
|
+
// Record each extracted pattern as an action step
|
|
143
|
+
for (const pat of patterns.slice(0, 50)) {
|
|
144
|
+
await intel.recordStep({
|
|
145
|
+
type: 'action',
|
|
146
|
+
content: pat,
|
|
147
|
+
metadata: { source: 'pretrain', depth },
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// Record the entire scan as a completed trajectory
|
|
151
|
+
const steps = patterns.slice(0, 50).map((p) => ({ type: 'action', content: p }));
|
|
152
|
+
const recorded = await intel.recordTrajectory(steps, 'success');
|
|
153
|
+
intel.flushPatterns();
|
|
154
|
+
if (recorded)
|
|
155
|
+
neuralPatternsLearned = steps.length;
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
/* intelligence not available */
|
|
159
|
+
if (process.env.DEBUG || process.env.MONOMIND_DEBUG)
|
|
160
|
+
console.error('[hooks-pretrain] intelligence training failed:', e);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
success: true,
|
|
165
|
+
_real: true,
|
|
166
|
+
path: repoPath,
|
|
167
|
+
depth,
|
|
168
|
+
durationMs: elapsed,
|
|
169
|
+
stats: {
|
|
170
|
+
filesAnalyzed,
|
|
171
|
+
totalLines,
|
|
172
|
+
patternsExtracted: patterns.length,
|
|
173
|
+
patternsStored,
|
|
174
|
+
neuralPatternsLearned,
|
|
175
|
+
fileTypes: Object.entries(extCounts)
|
|
176
|
+
.sort((a, b) => b[1] - a[1])
|
|
177
|
+
.slice(0, 15)
|
|
178
|
+
.map(([ext, count]) => ({ ext, count })),
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
// Transfer hook - transfer patterns from another project
|
|
184
|
+
export const hooksTransfer = {
|
|
185
|
+
name: 'hooks_transfer',
|
|
186
|
+
description: 'Transfer learned patterns from another project',
|
|
187
|
+
inputSchema: {
|
|
188
|
+
type: 'object',
|
|
189
|
+
properties: {
|
|
190
|
+
sourcePath: { type: 'string', description: 'Source project path' },
|
|
191
|
+
filter: { type: 'string', description: 'Filter patterns by type' },
|
|
192
|
+
minConfidence: { type: 'number', description: 'Minimum confidence threshold' },
|
|
193
|
+
},
|
|
194
|
+
required: ['sourcePath'],
|
|
195
|
+
},
|
|
196
|
+
handler: async (params) => {
|
|
197
|
+
const sourcePath = validateMcpString(params.sourcePath, 'sourcePath', 4 * 1024);
|
|
198
|
+
if (!sourcePath) {
|
|
199
|
+
return { error: 'sourcePath is required (non-empty string, no control chars, max 4KB)' };
|
|
200
|
+
}
|
|
201
|
+
const minConfidence = typeof params.minConfidence === 'number' && Number.isFinite(params.minConfidence)
|
|
202
|
+
? Math.max(0, Math.min(1, params.minConfidence))
|
|
203
|
+
: 0.7;
|
|
204
|
+
const filter = validateMcpString(params.filter, 'filter', 64) ?? undefined;
|
|
205
|
+
// Validate sourcePath is an existing directory before reading from it
|
|
206
|
+
const resolvedSource = resolve(sourcePath);
|
|
207
|
+
const { statSync } = await import('node:fs');
|
|
208
|
+
const { homedir } = await import('node:os');
|
|
209
|
+
const home = homedir();
|
|
210
|
+
if (resolvedSource !== home && !resolvedSource.startsWith(home + sep)) {
|
|
211
|
+
return { error: 'sourcePath must be within the home directory.' };
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const st = statSync(resolvedSource);
|
|
215
|
+
if (!st.isDirectory()) {
|
|
216
|
+
return { error: 'sourcePath must be a directory' };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch {
|
|
220
|
+
return { error: 'sourcePath does not exist' };
|
|
221
|
+
}
|
|
222
|
+
// Load learned patterns from the source project's neural pattern store —
|
|
223
|
+
// the same `.monomind/neural/patterns.json` file `hooks intelligence
|
|
224
|
+
// import` writes to and intelligence.ts reads from (src/memory/intelligence.ts
|
|
225
|
+
// getPatternsPath()).
|
|
226
|
+
const sourcePatternsPath = join(resolvedSource, '.monomind', 'neural', 'patterns.json');
|
|
227
|
+
let sourcePatterns = [];
|
|
228
|
+
const MAX_SOURCE_PATTERNS_BYTES = 50 * 1024 * 1024; // 50 MB — matches other store readers
|
|
229
|
+
try {
|
|
230
|
+
if (existsSync(sourcePatternsPath) &&
|
|
231
|
+
statSync(sourcePatternsPath).size <= MAX_SOURCE_PATTERNS_BYTES) {
|
|
232
|
+
const parsed = JSON.parse(readFileSync(sourcePatternsPath, 'utf-8'));
|
|
233
|
+
if (Array.isArray(parsed))
|
|
234
|
+
sourcePatterns = parsed;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch (e) {
|
|
238
|
+
// Fall back to empty list
|
|
239
|
+
if (process.env.DEBUG || process.env.MONOMIND_DEBUG)
|
|
240
|
+
console.error('[hooks-transfer] source patterns.json read/parse failed:', e);
|
|
241
|
+
}
|
|
242
|
+
if (sourcePatterns.length === 0) {
|
|
243
|
+
return {
|
|
244
|
+
success: false,
|
|
245
|
+
message: 'No patterns found in source project',
|
|
246
|
+
sourcePath,
|
|
247
|
+
transferred: { total: 0, byType: {} },
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
// Qualifying patterns: confidence at/above threshold, and (if given) type
|
|
251
|
+
// matches the filter.
|
|
252
|
+
const qualifying = sourcePatterns.filter((p) => typeof p.id === 'string' &&
|
|
253
|
+
p.id.length > 0 &&
|
|
254
|
+
(typeof p.confidence !== 'number' || p.confidence >= minConfidence) &&
|
|
255
|
+
(!filter || (typeof p.type === 'string' && p.type.includes(filter))));
|
|
256
|
+
if (qualifying.length === 0) {
|
|
257
|
+
return {
|
|
258
|
+
success: false,
|
|
259
|
+
message: 'No patterns in source project meet the filter/confidence threshold',
|
|
260
|
+
sourcePath,
|
|
261
|
+
transferred: { total: 0, byType: {} },
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
// Merge into this project's pattern store, reusing the same by-id dedupe
|
|
265
|
+
// logic as `hooks intelligence import` (neural-registry.ts's importCommand).
|
|
266
|
+
const destDir = join(getProjectCwd(), '.monomind', 'neural');
|
|
267
|
+
const destPatternsPath = join(destDir, 'patterns.json');
|
|
268
|
+
let destPatterns = [];
|
|
269
|
+
try {
|
|
270
|
+
if (existsSync(destPatternsPath) &&
|
|
271
|
+
statSync(destPatternsPath).size <= MAX_SOURCE_PATTERNS_BYTES) {
|
|
272
|
+
const parsed = JSON.parse(readFileSync(destPatternsPath, 'utf-8'));
|
|
273
|
+
if (Array.isArray(parsed))
|
|
274
|
+
destPatterns = parsed;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
catch (e) {
|
|
278
|
+
if (process.env.DEBUG || process.env.MONOMIND_DEBUG)
|
|
279
|
+
console.error('[hooks-transfer] destination patterns.json read/parse failed:', e);
|
|
280
|
+
}
|
|
281
|
+
const { merged, added } = mergeRecordsById(destPatterns, qualifying);
|
|
282
|
+
if (!existsSync(destDir))
|
|
283
|
+
mkdirSync(destDir, { recursive: true });
|
|
284
|
+
const tmpDest = `${destPatternsPath}.${process.pid}.${Date.now()}.tmp`;
|
|
285
|
+
writeFileSync(tmpDest, JSON.stringify(merged, null, 2), 'utf-8');
|
|
286
|
+
renameSync(tmpDest, destPatternsPath);
|
|
287
|
+
// Real counts of what was actually transferred, grouped by each pattern's
|
|
288
|
+
// own `type` field (falling back to 'unknown' when absent).
|
|
289
|
+
const byType = {};
|
|
290
|
+
for (const p of added) {
|
|
291
|
+
const type = typeof p.type === 'string' && p.type.length > 0 ? p.type : 'unknown';
|
|
292
|
+
byType[type] = (byType[type] || 0) + 1;
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
success: true,
|
|
296
|
+
sourcePath,
|
|
297
|
+
transferred: {
|
|
298
|
+
total: added.length,
|
|
299
|
+
byType,
|
|
300
|
+
},
|
|
301
|
+
dataSource: 'source-project',
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
// Intelligence hook - JS pattern/trajectory logging
|
|
306
|
+
export const hooksIntelligence = {
|
|
307
|
+
name: 'hooks_intelligence',
|
|
308
|
+
description: 'Intelligence status: pattern/trajectory logging metrics from the memory store',
|
|
309
|
+
inputSchema: {
|
|
310
|
+
type: 'object',
|
|
311
|
+
properties: {
|
|
312
|
+
enableHnsw: { type: 'boolean', description: 'Enable HNSW search' },
|
|
313
|
+
forceTraining: { type: 'boolean', description: 'Force training cycle' },
|
|
314
|
+
showStatus: { type: 'boolean', description: 'Show status only' },
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
handler: async (params) => {
|
|
318
|
+
const enableHnsw = params.enableHnsw !== false;
|
|
319
|
+
// Get REAL statistics from memory store
|
|
320
|
+
const realStats = getIntelligenceStatsFromMemory();
|
|
321
|
+
// Check actual implementation availability
|
|
322
|
+
const sonaAvailable = (await getSONAOptimizer()) !== null;
|
|
323
|
+
return {
|
|
324
|
+
status: 'active',
|
|
325
|
+
components: {
|
|
326
|
+
sona: {
|
|
327
|
+
enabled: sonaAvailable,
|
|
328
|
+
status: sonaAvailable ? 'active' : 'idle',
|
|
329
|
+
implemented: true,
|
|
330
|
+
trajectoriesRecorded: realStats.trajectories.total,
|
|
331
|
+
trajectoriesSuccessful: realStats.trajectories.successful,
|
|
332
|
+
patternsLearned: realStats.patterns.learned,
|
|
333
|
+
note: 'Trajectory + pattern logging (no neural training in the lean build)',
|
|
334
|
+
},
|
|
335
|
+
moe: {
|
|
336
|
+
enabled: false,
|
|
337
|
+
status: 'removed',
|
|
338
|
+
implemented: false,
|
|
339
|
+
routingDecisions: realStats.routing.decisions,
|
|
340
|
+
note: 'MoE removed in lean build; keyword routing is used instead (see monoes-full-loop)',
|
|
341
|
+
},
|
|
342
|
+
hnsw: {
|
|
343
|
+
enabled: enableHnsw,
|
|
344
|
+
status: enableHnsw ? 'active' : 'disabled',
|
|
345
|
+
implemented: true,
|
|
346
|
+
indexSize: realStats.memory.indexSize,
|
|
347
|
+
memorySizeBytes: realStats.memory.memorySizeBytes,
|
|
348
|
+
note: 'Pure-JS HNSW vector indexing (O(log n) vs O(n))',
|
|
349
|
+
},
|
|
350
|
+
flashAttention: {
|
|
351
|
+
enabled: false,
|
|
352
|
+
status: 'removed',
|
|
353
|
+
implemented: false,
|
|
354
|
+
note: 'Flash Attention removed in lean build; lives on monoes-full-loop branch',
|
|
355
|
+
},
|
|
356
|
+
ewc: {
|
|
357
|
+
enabled: false,
|
|
358
|
+
status: 'removed',
|
|
359
|
+
implemented: false,
|
|
360
|
+
note: 'EWC++ removed in lean build; lives on monoes-full-loop branch',
|
|
361
|
+
},
|
|
362
|
+
lora: {
|
|
363
|
+
enabled: false,
|
|
364
|
+
status: 'removed',
|
|
365
|
+
implemented: false,
|
|
366
|
+
note: 'LoRA removed in lean build; lives on monoes-full-loop branch',
|
|
367
|
+
},
|
|
368
|
+
embeddings: {
|
|
369
|
+
provider: 'transformers',
|
|
370
|
+
model: DEFAULT_EMBEDDING_MODEL,
|
|
371
|
+
dimension: DEFAULT_EMBEDDING_DIMS,
|
|
372
|
+
implemented: true,
|
|
373
|
+
note: `Real ONNX embeddings via ${DEFAULT_EMBEDDING_MODEL}`,
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
realMetrics: {
|
|
377
|
+
trajectories: realStats.trajectories,
|
|
378
|
+
patterns: realStats.patterns,
|
|
379
|
+
memory: realStats.memory,
|
|
380
|
+
routing: realStats.routing,
|
|
381
|
+
},
|
|
382
|
+
implementationStatus: {
|
|
383
|
+
working: [
|
|
384
|
+
'memory-store',
|
|
385
|
+
'embeddings',
|
|
386
|
+
'trajectory-recording',
|
|
387
|
+
'claims',
|
|
388
|
+
'swarm-coordination',
|
|
389
|
+
'hnsw-index',
|
|
390
|
+
'pattern-storage',
|
|
391
|
+
'keyword-routing',
|
|
392
|
+
],
|
|
393
|
+
partial: [],
|
|
394
|
+
notImplemented: [],
|
|
395
|
+
removed: [
|
|
396
|
+
'moe-routing',
|
|
397
|
+
'flash-attention',
|
|
398
|
+
'lora-adapter',
|
|
399
|
+
'native-sona-engine',
|
|
400
|
+
'native-router',
|
|
401
|
+
'native-attention',
|
|
402
|
+
],
|
|
403
|
+
},
|
|
404
|
+
version: '3.0.0-alpha.102',
|
|
405
|
+
};
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
//# sourceMappingURL=hooks-learning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-learning.js","sourceRoot":"","sources":["../../../src/mcp-tools/hooks-learning.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,8BAA8B,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxF,OAAO,EAAE,aAAa,EAAgB,MAAM,YAAY,CAAC;AAazD,iEAAiE;AACjE,MAAM,CAAC,MAAM,aAAa,GAAY;IACpC,IAAI,EAAE,gBAAgB;IACtB,WAAW,EACT,uLAAuL;IACzL,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iBAAiB,EAAE;YACxD,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,wCAAwC,EAAE;YAChF,SAAS,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,sBAAsB,EAAE;SACpE;KACF;IACD,OAAO,EAAE,KAAK,EAAE,MAA+B,EAAE,EAAE;QACjD,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,MAAM,C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MAAM,EAAE,SAAS;oBACjB,WAAW,EAAE,KAAK;oBAClB,IAAI,EAAE,+DAA+D;iBACtE;gBACD,IAAI,EAAE;oBACJ,OAAO,EAAE,KAAK;oBACd,MAAM,EAAE,SAAS;oBACjB,WAAW,EAAE,KAAK;oBAClB,IAAI,EAAE,8DAA8D;iBACrE;gBACD,UAAU,EAAE;oBACV,QAAQ,EAAE,cAAc;oBACxB,KAAK,EAAE,uBAAuB;oBAC9B,SAAS,EAAE,sBAAsB;oBACjC,WAAW,EAAE,IAAI;oBACjB,IAAI,EAAE,4BAA4B,uBAAuB,EAAE;iBAC5D;aACF;YACD,WAAW,EAAE;gBACX,YAAY,EAAE,SAAS,CAAC,YAAY;gBACpC,QAAQ,EAAE,SAAS,CAAC,QAAQ;gBAC5B,MAAM,EAAE,SAAS,CAAC,MAAM;gBACxB,OAAO,EAAE,SAAS,CAAC,OAAO;aAC3B;YACD,oBAAoB,EAAE;gBACpB,OAAO,EAAE;oBACP,cAAc;oBACd,YAAY;oBACZ,sBAAsB;oBACtB,QAAQ;oBACR,oBAAoB;oBACpB,YAAY;oBACZ,iBAAiB;oBACjB,iBAAiB;iBAClB;gBACD,OAAO,EAAE,EAAE;gBACX,cAAc,EAAE,EAAE;gBAClB,OAAO,EAAE;oBACP,aAAa;oBACb,iBAAiB;oBACjB,cAAc;oBACd,oBAAoB;oBACpB,eAAe;oBACf,kBAAkB;iBACnB;aACF;YACD,OAAO,EAAE,iBAAiB;SAC3B,CAAC;IACJ,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hooks MCP Tools — metrics and list.
|
|
3
|
+
* Extracted from hooks-routing.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { type MCPTool } from './types.js';
|
|
6
|
+
export declare const hooksMetrics: MCPTool;
|
|
7
|
+
export declare const hooksList: MCPTool;
|
|
8
|
+
//# sourceMappingURL=hooks-metrics-list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks-metrics-list.d.ts","sourceRoot":"","sources":["../../../src/mcp-tools/hooks-metrics-list.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAEzD,eAAO,MAAM,YAAY,EAAE,OAyD1B,CAAC;AAuGF,eAAO,MAAM,SAAS,EAAE,OA2DvB,CAAC"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hooks MCP Tools — metrics and list.
|
|
3
|
+
* Extracted from hooks-routing.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { validateMcpString } from '../utils/input-guards.js';
|
|
8
|
+
import { loadMemoryStore } from './hooks-embedding.js';
|
|
9
|
+
import { getProjectCwd } from './types.js';
|
|
10
|
+
export const hooksMetrics = {
|
|
11
|
+
name: 'hooks_metrics',
|
|
12
|
+
description: 'View learning metrics dashboard',
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
period: { type: 'string', description: 'Metrics period (1h, 24h, 7d, 30d)' },
|
|
17
|
+
includeV1: { type: 'boolean', description: 'Include v1 performance metrics' },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
handler: async (params) => {
|
|
21
|
+
const period = validateMcpString(params.period, 'period', 32) ?? '24h';
|
|
22
|
+
// Try to read real counts from memory store
|
|
23
|
+
const store = loadMemoryStore();
|
|
24
|
+
const entries = Object.values(store.entries);
|
|
25
|
+
// Count patterns by looking at stored pattern entries
|
|
26
|
+
const patternEntries = entries.filter((e) => e.key.includes('pattern'));
|
|
27
|
+
const routingEntries = entries.filter((e) => e.key.includes('route') || e.key.includes('routing'));
|
|
28
|
+
const taskEntries = entries.filter((e) => e.key.includes('task'));
|
|
29
|
+
if (entries.length === 0) {
|
|
30
|
+
return {
|
|
31
|
+
_real: true,
|
|
32
|
+
_note: 'No metrics data collected yet. Data populates from hooks_post-task, hooks_post-edit, hooks_post-command, and hooks_route calls.',
|
|
33
|
+
period,
|
|
34
|
+
patterns: { total: 0, successful: 0, failed: 0, avgConfidence: null },
|
|
35
|
+
agents: { routingAccuracy: null, totalRoutes: 0, topAgent: null },
|
|
36
|
+
commands: { totalExecuted: 0, successRate: null, avgRiskScore: null },
|
|
37
|
+
lastUpdated: new Date().toISOString(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
period,
|
|
42
|
+
patterns: {
|
|
43
|
+
total: patternEntries.length,
|
|
44
|
+
_note: 'Success/failure breakdown not tracked yet — store outcomes via hooks_post-task to populate.',
|
|
45
|
+
},
|
|
46
|
+
agents: {
|
|
47
|
+
totalRoutes: routingEntries.length,
|
|
48
|
+
_note: 'Routing accuracy not tracked yet — requires route-outcome correlation data.',
|
|
49
|
+
},
|
|
50
|
+
commands: {
|
|
51
|
+
totalExecuted: taskEntries.length,
|
|
52
|
+
_note: 'Success rate not tracked yet — requires command-outcomes.jsonl data.',
|
|
53
|
+
},
|
|
54
|
+
dataSource: 'memory-store',
|
|
55
|
+
entriesFound: entries.length,
|
|
56
|
+
lastUpdated: new Date().toISOString(),
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The only per-hook execution data monomind actually persists: invocation
|
|
62
|
+
* counters written by `.claude/helpers/hook-handler.cjs` into
|
|
63
|
+
* `.monomind/metrics/hook-latency.json` as `{ count, total, max, mean }`.
|
|
64
|
+
*
|
|
65
|
+
* It is keyed by *handler* name (`pre-bash`, `pre-write`, `agent-start`, …) —
|
|
66
|
+
* the wiring `readClaudeCodeHookWiring` reports, not the subcommand registry
|
|
67
|
+
* `hooks_list` returns. The two name spaces overlap on 6 of 24 entries and
|
|
68
|
+
* diverge elsewhere (registry `pre-command` vs. handler `pre-bash`, registry
|
|
69
|
+
* `pre-edit` vs. handler `pre-write`), so joining them would be a guess. These
|
|
70
|
+
* counts are therefore reported alongside the wiring they measure.
|
|
71
|
+
*
|
|
72
|
+
* There is no per-hook timestamp and no per-hook priority anywhere on disk:
|
|
73
|
+
* the file carries one file-global `lastUpdated`, and `HookPriority` lives
|
|
74
|
+
* only in @monoes/hooks' in-memory registry, which this process never fills.
|
|
75
|
+
*/
|
|
76
|
+
function readHookHandlerInvocations() {
|
|
77
|
+
const metricsPath = join(getProjectCwd(), '.monomind', 'metrics', 'hook-latency.json');
|
|
78
|
+
const handlers = [];
|
|
79
|
+
let raw;
|
|
80
|
+
try {
|
|
81
|
+
raw = JSON.parse(readFileSync(metricsPath, 'utf8'));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return { metricsPath, recorded: false, handlers };
|
|
85
|
+
}
|
|
86
|
+
if (typeof raw !== 'object' || raw === null)
|
|
87
|
+
return { metricsPath, recorded: false, handlers };
|
|
88
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
89
|
+
// `lastUpdated` is a file-global epoch, not a handler.
|
|
90
|
+
if (name === 'lastUpdated' || typeof value !== 'object' || value === null)
|
|
91
|
+
continue;
|
|
92
|
+
const entry = value;
|
|
93
|
+
// Report only what the writer actually recorded — never a defaulted zero.
|
|
94
|
+
if (typeof entry.count !== 'number')
|
|
95
|
+
continue;
|
|
96
|
+
handlers.push({
|
|
97
|
+
name,
|
|
98
|
+
count: entry.count,
|
|
99
|
+
meanMs: typeof entry.mean === 'number' ? entry.mean : 0,
|
|
100
|
+
maxMs: typeof entry.max === 'number' ? entry.max : 0,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
handlers.sort((a, b) => b.count - a.count);
|
|
104
|
+
return { metricsPath, recorded: handlers.length > 0, handlers };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Claude Code event wiring, as written into `.claude/settings.json` by
|
|
108
|
+
* `monomind init hooks`. This is a *different* subsystem from the hook
|
|
109
|
+
* subcommand registry below — it is keyed by Claude Code event and handler
|
|
110
|
+
* script, not by these subcommand names — so `hooks list` reports it
|
|
111
|
+
* separately instead of folding it into the registry's own state (#270).
|
|
112
|
+
*/
|
|
113
|
+
function readClaudeCodeHookWiring() {
|
|
114
|
+
const settingsPath = join(getProjectCwd(), '.claude', 'settings.json');
|
|
115
|
+
const invocations = readHookHandlerInvocations();
|
|
116
|
+
const empty = { configured: false, settingsPath, wired: 0, events: [], invocations };
|
|
117
|
+
let hooks;
|
|
118
|
+
try {
|
|
119
|
+
const parsed = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
|
120
|
+
hooks = (parsed?.hooks ?? {});
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return empty;
|
|
124
|
+
}
|
|
125
|
+
const events = [];
|
|
126
|
+
let wired = 0;
|
|
127
|
+
for (const [event, matchers] of Object.entries(hooks)) {
|
|
128
|
+
let eventWired = 0;
|
|
129
|
+
for (const matcher of Array.isArray(matchers) ? matchers : []) {
|
|
130
|
+
for (const entry of Array.isArray(matcher?.hooks) ? matcher.hooks : []) {
|
|
131
|
+
// Only ours: every command monomind generates runs a script out of
|
|
132
|
+
// .claude/helpers. Third-party hooks in the same file are not ours
|
|
133
|
+
// to report on.
|
|
134
|
+
if (typeof entry?.command === 'string' && entry.command.includes('.claude/helpers/')) {
|
|
135
|
+
eventWired++;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (eventWired > 0) {
|
|
140
|
+
events.push(event);
|
|
141
|
+
wired += eventWired;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return { configured: wired > 0, settingsPath, wired, events, invocations };
|
|
145
|
+
}
|
|
146
|
+
export const hooksList = {
|
|
147
|
+
name: 'hooks_list',
|
|
148
|
+
description: 'List all registered hooks',
|
|
149
|
+
inputSchema: {
|
|
150
|
+
type: 'object',
|
|
151
|
+
properties: {},
|
|
152
|
+
},
|
|
153
|
+
handler: async () => {
|
|
154
|
+
// Static registry — not live discovery from handler objects.
|
|
155
|
+
// Update this list when hooks are added or removed.
|
|
156
|
+
const hooks = [
|
|
157
|
+
// Core hooks
|
|
158
|
+
{ name: 'pre-edit', type: 'PreToolUse', status: 'active' },
|
|
159
|
+
{ name: 'post-edit', type: 'PostToolUse', status: 'active' },
|
|
160
|
+
{ name: 'pre-command', type: 'PreToolUse', status: 'active' },
|
|
161
|
+
{ name: 'post-command', type: 'PostToolUse', status: 'active' },
|
|
162
|
+
{ name: 'pre-task', type: 'PreToolUse', status: 'active' },
|
|
163
|
+
{ name: 'post-task', type: 'PostToolUse', status: 'active' },
|
|
164
|
+
// Routing hooks
|
|
165
|
+
{ name: 'route', type: 'intelligence', status: 'active' },
|
|
166
|
+
{ name: 'explain', type: 'intelligence', status: 'active' },
|
|
167
|
+
// Session hooks
|
|
168
|
+
{ name: 'session-start', type: 'SessionStart', status: 'active' },
|
|
169
|
+
{ name: 'session-end', type: 'SessionEnd', status: 'active' },
|
|
170
|
+
{ name: 'session-restore', type: 'SessionStart', status: 'active' },
|
|
171
|
+
// Learning hooks
|
|
172
|
+
{ name: 'pretrain', type: 'intelligence', status: 'active' },
|
|
173
|
+
{ name: 'transfer', type: 'intelligence', status: 'active' },
|
|
174
|
+
{ name: 'metrics', type: 'analytics', status: 'active' },
|
|
175
|
+
// System hooks
|
|
176
|
+
{ name: 'init', type: 'system', status: 'active' },
|
|
177
|
+
{ name: 'notify', type: 'coordination', status: 'active' },
|
|
178
|
+
// Intelligence subcommands
|
|
179
|
+
{ name: 'intelligence', type: 'intelligence', status: 'active' },
|
|
180
|
+
{ name: 'intelligence_trajectory-start', type: 'intelligence', status: 'active' },
|
|
181
|
+
{ name: 'intelligence_trajectory-step', type: 'intelligence', status: 'active' },
|
|
182
|
+
{ name: 'intelligence_trajectory-end', type: 'intelligence', status: 'active' },
|
|
183
|
+
{ name: 'intelligence_pattern-store', type: 'intelligence', status: 'active' },
|
|
184
|
+
{ name: 'intelligence_pattern-search', type: 'intelligence', status: 'active' },
|
|
185
|
+
{ name: 'intelligence_stats', type: 'analytics', status: 'active' },
|
|
186
|
+
{ name: 'intelligence_learn', type: 'intelligence', status: 'active' },
|
|
187
|
+
];
|
|
188
|
+
return {
|
|
189
|
+
_note: 'Two independent things. `hooks` is a static registry of monomind CLI ' +
|
|
190
|
+
'hook subcommands (update it when hooks are added or removed); each is ' +
|
|
191
|
+
'enabled when its status is active. `claudeCode` is the Claude Code ' +
|
|
192
|
+
'event wiring in .claude/settings.json that `monomind init hooks` ' +
|
|
193
|
+
'writes — keyed by event and handler script, not by these names. A hook ' +
|
|
194
|
+
'can be registered here without that wiring being present. Registry ' +
|
|
195
|
+
'entries carry no priority, execution count or last-executed timestamp: ' +
|
|
196
|
+
'nothing persists those. The only recorded execution data is ' +
|
|
197
|
+
'`claudeCode.invocations` — per-handler counters from ' +
|
|
198
|
+
'.monomind/metrics/hook-latency.json, in the wiring name space, not this one.',
|
|
199
|
+
hooks: hooks.map((hook) => ({ ...hook, enabled: hook.status === 'active' })),
|
|
200
|
+
total: hooks.length,
|
|
201
|
+
claudeCode: readClaudeCodeHookWiring(),
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
//# sourceMappingURL=hooks-metrics-list.js.map
|