claude-memory-store 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atlas/vector.d.ts +6 -0
- package/dist/atlas/vector.d.ts.map +1 -1
- package/dist/atlas/vector.js +44 -0
- package/dist/atlas/vector.js.map +1 -1
- package/dist/bin/claude-memory.js +135 -80
- package/dist/bin/claude-memory.js.map +1 -1
- package/dist/bin/mcp-server.js +48 -8
- package/dist/bin/mcp-server.js.map +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +43 -2
- package/dist/config.js.map +1 -1
- package/dist/hooks/hook-input.d.ts +34 -0
- package/dist/hooks/hook-input.d.ts.map +1 -0
- package/dist/hooks/hook-input.js +68 -0
- package/dist/hooks/hook-input.js.map +1 -0
- package/dist/hooks/post-tool-use.d.ts +8 -2
- package/dist/hooks/post-tool-use.d.ts.map +1 -1
- package/dist/hooks/post-tool-use.js +203 -3
- package/dist/hooks/post-tool-use.js.map +1 -1
- package/dist/hooks/pre-compact.d.ts +3 -0
- package/dist/hooks/pre-compact.d.ts.map +1 -0
- package/dist/hooks/pre-compact.js +36 -0
- package/dist/hooks/pre-compact.js.map +1 -0
- package/dist/hooks/pre-tool-use.d.ts +15 -0
- package/dist/hooks/pre-tool-use.d.ts.map +1 -1
- package/dist/hooks/pre-tool-use.js +166 -8
- package/dist/hooks/pre-tool-use.js.map +1 -1
- package/dist/hooks/stop.js +6 -99
- package/dist/hooks/stop.js.map +1 -1
- package/dist/hooks/transcript-utils.d.ts +18 -0
- package/dist/hooks/transcript-utils.d.ts.map +1 -0
- package/dist/hooks/transcript-utils.js +110 -0
- package/dist/hooks/transcript-utils.js.map +1 -0
- package/dist/memory/commands.d.ts.map +1 -1
- package/dist/memory/commands.js +7 -1
- package/dist/memory/commands.js.map +1 -1
- package/dist/memory/developer.d.ts +16 -0
- package/dist/memory/developer.d.ts.map +1 -1
- package/dist/memory/developer.js +28 -0
- package/dist/memory/developer.js.map +1 -1
- package/dist/memory/project.d.ts +26 -0
- package/dist/memory/project.d.ts.map +1 -1
- package/dist/memory/project.js +79 -0
- package/dist/memory/project.js.map +1 -1
- package/dist/memory/working.d.ts.map +1 -1
- package/dist/memory/working.js +2 -1
- package/dist/memory/working.js.map +1 -1
- package/dist/modes/code.d.ts +7 -0
- package/dist/modes/code.d.ts.map +1 -0
- package/dist/modes/code.js +15 -0
- package/dist/modes/code.js.map +1 -0
- package/dist/modes/index.d.ts +16 -0
- package/dist/modes/index.d.ts.map +1 -0
- package/dist/modes/index.js +29 -0
- package/dist/modes/index.js.map +1 -0
- package/dist/modes/research.d.ts +7 -0
- package/dist/modes/research.d.ts.map +1 -0
- package/dist/modes/research.js +15 -0
- package/dist/modes/research.js.map +1 -0
- package/dist/natural-language/router.js +1 -3
- package/dist/natural-language/router.js.map +1 -1
- package/dist/startup/injector.d.ts.map +1 -1
- package/dist/startup/injector.js +64 -38
- package/dist/startup/injector.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +10 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +33 -0
- package/dist/utils.js.map +1 -1
- package/dist/watch/event-log.d.ts.map +1 -1
- package/dist/watch/event-log.js +23 -0
- package/dist/watch/event-log.js.map +1 -1
- package/package.json +1 -1
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAoBrD,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,wBAAgB,eAAe,IAAI,IAAI,CAItC;AAED,wBAAgB,UAAU,IAAI,kBAAkB,CAW/C;AAED,wBAAgB,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAG3D;AAED,wBAAgB,WAAW,IAAI,MAAM,CAOpC;AAED,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED,wBAAgB,gBAAgB,IAAI,MAAM,CAGzC;AAID,eAAO,MAAM,0BAA0B,OAAO,CAAC;AAK/C,eAAO,MAAM,8BAA8B,OAAO,CAAC;AAGnD,eAAO,MAAM,mBAAmB,OAAO,CAAC;AAExC,wBAAgB,gBAAgB,IAAI,SAAS,GAAG,MAAM,CAGrD;AAED,wBAAgB,oBAAoB,IAAI,MAAM,CAG7C;AAED,wBAAgB,2BAA2B,IAAI,MAAM,CAGpD;AAED,wBAAgB,0BAA0B,IAAI,OAAO,CAGpD;AAED,wBAAgB,qBAAqB,IAAI,SAAS,GAAG,UAAU,GAAG,SAAS,CAG1E;AAED,wBAAgB,OAAO,IAAI,MAAM,CAGhC;AAED,wBAAgB,cAAc,IAAI,OAAO,CAGxC;AAED,wBAAgB,oBAAoB,IAAI,MAAM,CAG7C;AAED,wBAAgB,sBAAsB,IAAI,MAAM,CAG/C"}
|
package/dist/config.js
CHANGED
|
@@ -42,6 +42,13 @@ exports.saveConfig = saveConfig;
|
|
|
42
42
|
exports.getAtlasUri = getAtlasUri;
|
|
43
43
|
exports.isConfigured = isConfigured;
|
|
44
44
|
exports.getMemoryTtlDays = getMemoryTtlDays;
|
|
45
|
+
exports.getContextDetail = getContextDetail;
|
|
46
|
+
exports.getContextMaxResults = getContextMaxResults;
|
|
47
|
+
exports.getContextMaxInjectionChars = getContextMaxInjectionChars;
|
|
48
|
+
exports.getContextShowTokenSavings = getContextShowTokenSavings;
|
|
49
|
+
exports.getContextStartupMode = getContextStartupMode;
|
|
50
|
+
exports.getMode = getMode;
|
|
51
|
+
exports.getAutoCapture = getAutoCapture;
|
|
45
52
|
exports.getDecayHalfLifeDays = getDecayHalfLifeDays;
|
|
46
53
|
exports.getDecayDeathThreshold = getDecayDeathThreshold;
|
|
47
54
|
const fs = __importStar(require("node:fs"));
|
|
@@ -55,6 +62,13 @@ const DEFAULT_CONFIG = {
|
|
|
55
62
|
memory_ttl_days: 30,
|
|
56
63
|
decay_half_life_days: 7,
|
|
57
64
|
decay_death_threshold: 0.05,
|
|
65
|
+
context_detail: 'compact',
|
|
66
|
+
context_max_results: 5,
|
|
67
|
+
context_max_injection_chars: 2000,
|
|
68
|
+
context_show_token_savings: false,
|
|
69
|
+
context_startup_mode: 'standard',
|
|
70
|
+
mode: 'code',
|
|
71
|
+
auto_capture: true,
|
|
58
72
|
};
|
|
59
73
|
function getConfigDir() {
|
|
60
74
|
return CONFIG_DIR;
|
|
@@ -106,9 +120,36 @@ exports.VECTOR_RELEVANCE_THRESHOLD = 0.55;
|
|
|
106
120
|
// If a new memory scores >= this against an existing one, treat as duplicate.
|
|
107
121
|
// Higher = stricter dedup. Lower = more aggressive merging.
|
|
108
122
|
exports.DUPLICATE_SIMILARITY_THRESHOLD = 0.92;
|
|
109
|
-
// Maximum characters injected from memory per prompt.
|
|
110
|
-
// Prevents memory from accidentally consuming the context window.
|
|
123
|
+
// Maximum characters injected from memory per prompt (default, overridable via config).
|
|
111
124
|
exports.MAX_INJECTION_CHARS = 2000;
|
|
125
|
+
function getContextDetail() {
|
|
126
|
+
const config = loadConfig();
|
|
127
|
+
return config.context_detail ?? 'compact';
|
|
128
|
+
}
|
|
129
|
+
function getContextMaxResults() {
|
|
130
|
+
const config = loadConfig();
|
|
131
|
+
return config.context_max_results ?? 5;
|
|
132
|
+
}
|
|
133
|
+
function getContextMaxInjectionChars() {
|
|
134
|
+
const config = loadConfig();
|
|
135
|
+
return config.context_max_injection_chars ?? exports.MAX_INJECTION_CHARS;
|
|
136
|
+
}
|
|
137
|
+
function getContextShowTokenSavings() {
|
|
138
|
+
const config = loadConfig();
|
|
139
|
+
return config.context_show_token_savings ?? false;
|
|
140
|
+
}
|
|
141
|
+
function getContextStartupMode() {
|
|
142
|
+
const config = loadConfig();
|
|
143
|
+
return config.context_startup_mode ?? 'standard';
|
|
144
|
+
}
|
|
145
|
+
function getMode() {
|
|
146
|
+
const config = loadConfig();
|
|
147
|
+
return config.mode ?? 'code';
|
|
148
|
+
}
|
|
149
|
+
function getAutoCapture() {
|
|
150
|
+
const config = loadConfig();
|
|
151
|
+
return config.auto_capture ?? true;
|
|
152
|
+
}
|
|
112
153
|
function getDecayHalfLifeDays() {
|
|
113
154
|
const config = loadConfig();
|
|
114
155
|
return config.decay_half_life_days ?? 7;
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,oCAEC;AAED,sCAEC;AAED,0CAIC;AAED,gCAWC;AAED,gCAGC;AAED,kCAOC;AAED,oCAEC;AAED,4CAGC;AAcD,4CAGC;AAED,oDAGC;AAED,kEAGC;AAED,gEAGC;AAED,sDAGC;AAED,0BAGC;AAED,wCAGC;AAED,oDAGC;AAED,wDAGC;AAhID,4CAA8B;AAC9B,gDAAkC;AAClC,4CAA8B;AAG9B,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,gBAAgB,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAEzD,MAAM,cAAc,GAAuB;IACzC,SAAS,EAAE,EAAE;IACb,WAAW,EAAE,KAAK;IAClB,eAAe,EAAE,EAAE;IACnB,oBAAoB,EAAE,CAAC;I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;IACrB,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC;AAC/B,CAAC;AAED,SAAgB,cAAc;IAC5B,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,YAAY,IAAI,IAAI,CAAC;AACrC,CAAC;AAED,SAAgB,oBAAoB;IAClC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,oBAAoB,IAAI,CAAC,CAAC;AAC1C,CAAC;AAED,SAAgB,sBAAsB;IACpC,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,qBAAqB,IAAI,IAAI,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses the structured JSON that Claude Code sends to hooks via stdin.
|
|
3
|
+
*
|
|
4
|
+
* Claude Code passes tool metadata (tool_name, tool_input, tool_result)
|
|
5
|
+
* as JSON. Previously we treated stdin as raw text, losing this data.
|
|
6
|
+
*/
|
|
7
|
+
export interface HookInput {
|
|
8
|
+
session_id?: string;
|
|
9
|
+
hook_event_name?: string;
|
|
10
|
+
tool_name?: string;
|
|
11
|
+
tool_input?: Record<string, unknown>;
|
|
12
|
+
tool_result?: string;
|
|
13
|
+
transcript_path?: string;
|
|
14
|
+
cwd?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Try to parse raw stdin as Claude Code hook JSON.
|
|
18
|
+
* Returns null if the input is not valid JSON (legacy plain-text invocation).
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseHookInput(raw: string): HookInput | null;
|
|
21
|
+
/**
|
|
22
|
+
* Extract the file path from Edit, Write, or Read tool_input.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getFilePath(input: HookInput): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Extract the bash command string from Bash tool_input.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getBashCommand(input: HookInput): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Extract a meaningful search query from the hook input.
|
|
31
|
+
* Falls back to stringifying tool_input keys for unknown tools.
|
|
32
|
+
*/
|
|
33
|
+
export declare function extractSearchQuery(input: HookInput): string | null;
|
|
34
|
+
//# sourceMappingURL=hook-input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-input.d.ts","sourceRoot":"","sources":["../../src/hooks/hook-input.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,SAAS;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAU5D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAE3D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAE9D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAwBlE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parses the structured JSON that Claude Code sends to hooks via stdin.
|
|
4
|
+
*
|
|
5
|
+
* Claude Code passes tool metadata (tool_name, tool_input, tool_result)
|
|
6
|
+
* as JSON. Previously we treated stdin as raw text, losing this data.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.parseHookInput = parseHookInput;
|
|
10
|
+
exports.getFilePath = getFilePath;
|
|
11
|
+
exports.getBashCommand = getBashCommand;
|
|
12
|
+
exports.extractSearchQuery = extractSearchQuery;
|
|
13
|
+
/**
|
|
14
|
+
* Try to parse raw stdin as Claude Code hook JSON.
|
|
15
|
+
* Returns null if the input is not valid JSON (legacy plain-text invocation).
|
|
16
|
+
*/
|
|
17
|
+
function parseHookInput(raw) {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(raw);
|
|
20
|
+
if (typeof parsed === 'object' && parsed !== null) {
|
|
21
|
+
return parsed;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract the file path from Edit, Write, or Read tool_input.
|
|
31
|
+
*/
|
|
32
|
+
function getFilePath(input) {
|
|
33
|
+
return input.tool_input?.file_path ?? null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extract the bash command string from Bash tool_input.
|
|
37
|
+
*/
|
|
38
|
+
function getBashCommand(input) {
|
|
39
|
+
return input.tool_input?.command ?? null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Extract a meaningful search query from the hook input.
|
|
43
|
+
* Falls back to stringifying tool_input keys for unknown tools.
|
|
44
|
+
*/
|
|
45
|
+
function extractSearchQuery(input) {
|
|
46
|
+
const toolName = input.tool_name || '';
|
|
47
|
+
switch (toolName) {
|
|
48
|
+
case 'Edit':
|
|
49
|
+
case 'Write':
|
|
50
|
+
return getFilePath(input);
|
|
51
|
+
case 'Bash':
|
|
52
|
+
return getBashCommand(input);
|
|
53
|
+
case 'Read':
|
|
54
|
+
case 'Glob':
|
|
55
|
+
case 'Grep':
|
|
56
|
+
// Read-only tools — no injection needed
|
|
57
|
+
return null;
|
|
58
|
+
default: {
|
|
59
|
+
// For MCP tools, Agent, etc. — try to extract something useful
|
|
60
|
+
const toolInput = input.tool_input;
|
|
61
|
+
if (!toolInput)
|
|
62
|
+
return null;
|
|
63
|
+
const values = Object.values(toolInput).filter((v) => typeof v === 'string' && v.length > 5 && v.length < 500);
|
|
64
|
+
return values.length > 0 ? values.join(' ') : null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=hook-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-input.js","sourceRoot":"","sources":["../../src/hooks/hook-input.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAgBH,wCAUC;AAKD,kCAEC;AAKD,wCAEC;AAMD,gDAwBC;AA1DD;;;GAGG;AACH,SAAgB,cAAc,CAAC,GAAW;IACxC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;YAClD,OAAO,MAAmB,CAAC;QAC7B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,KAAgB;IAC1C,OAAQ,KAAK,CAAC,UAAU,EAAE,SAAoB,IAAI,IAAI,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAgB;IAC7C,OAAQ,KAAK,CAAC,UAAU,EAAE,OAAkB,IAAI,IAAI,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,KAAgB;IACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC;IAEvC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;QAC5B,KAAK,MAAM;YACT,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;QAC/B,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM,CAAC;QACZ,KAAK,MAAM;YACT,wCAAwC;YACxC,OAAO,IAAI,CAAC;QACd,OAAO,CAAC,CAAC,CAAC;YACR,+DAA+D;YAC/D,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC;YACnC,IAAI,CAAC,SAAS;gBAAE,OAAO,IAAI,CAAC;YAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAC5C,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,GAAG,CAC/D,CAAC;YACF,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import type { HookInput } from './hook-input.js';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
3
|
+
* New entry point: dispatches to tool-specific handlers based on
|
|
4
|
+
* the structured JSON from Claude Code stdin.
|
|
5
|
+
*/
|
|
6
|
+
export declare function postToolUseDispatch(input: HookInput): Promise<string | null>;
|
|
7
|
+
/**
|
|
8
|
+
* Original PostToolUse entry point.
|
|
9
|
+
* Kept for backward compatibility when stdin is not JSON.
|
|
4
10
|
*/
|
|
5
11
|
export declare function postToolUse(toolName: string, toolInput: string, toolOutput: string): Promise<string | null>;
|
|
6
12
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-tool-use.d.ts","sourceRoot":"","sources":["../../src/hooks/post-tool-use.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"post-tool-use.d.ts","sourceRoot":"","sources":["../../src/hooks/post-tool-use.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA0DjD;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYlF;AAqJD;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAKxB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkBjF"}
|
|
@@ -1,15 +1,215 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postToolUseDispatch = postToolUseDispatch;
|
|
3
4
|
exports.postToolUse = postToolUse;
|
|
4
5
|
exports.processMemoryCommand = processMemoryCommand;
|
|
5
6
|
const router_js_1 = require("../natural-language/router.js");
|
|
6
7
|
const intent_js_1 = require("../natural-language/intent.js");
|
|
8
|
+
const project_js_1 = require("../memory/project.js");
|
|
9
|
+
const parser_js_1 = require("../natural-language/parser.js");
|
|
10
|
+
const config_js_1 = require("../config.js");
|
|
11
|
+
const hook_input_js_1 = require("./hook-input.js");
|
|
12
|
+
// ─── Auto-Capture Helper ───────────────────────────────────────────────────
|
|
7
13
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
14
|
+
* Fire-and-forget: stores a summary string as context.
|
|
15
|
+
* Config-gated, secret-safe, never blocks the hook.
|
|
16
|
+
*/
|
|
17
|
+
function autoCapture(content) {
|
|
18
|
+
if (!(0, config_js_1.getAutoCapture)())
|
|
19
|
+
return;
|
|
20
|
+
if (!content || content.length < 10)
|
|
21
|
+
return;
|
|
22
|
+
if ((0, parser_js_1.containsSecret)(content))
|
|
23
|
+
return;
|
|
24
|
+
(async () => {
|
|
25
|
+
try {
|
|
26
|
+
await (0, project_js_1.ensureProjectMeta)();
|
|
27
|
+
await (0, project_js_1.addContext)(content);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Silent — never block the hook
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
33
|
+
}
|
|
34
|
+
// Config files that warrant a memory suggestion when changed
|
|
35
|
+
const SIGNIFICANT_FILES = [
|
|
36
|
+
'package.json',
|
|
37
|
+
'tsconfig.json',
|
|
38
|
+
'tsconfig.build.json',
|
|
39
|
+
'Dockerfile',
|
|
40
|
+
'docker-compose.yml',
|
|
41
|
+
'docker-compose.yaml',
|
|
42
|
+
'.env.example',
|
|
43
|
+
'.gitignore',
|
|
44
|
+
'.dockerignore',
|
|
45
|
+
'jest.config',
|
|
46
|
+
'vitest.config',
|
|
47
|
+
'webpack.config',
|
|
48
|
+
'vite.config',
|
|
49
|
+
'next.config',
|
|
50
|
+
'tailwind.config',
|
|
51
|
+
'eslint.config',
|
|
52
|
+
'.eslintrc',
|
|
53
|
+
'.prettierrc',
|
|
54
|
+
'CLAUDE.md',
|
|
55
|
+
];
|
|
56
|
+
// Patterns in code that indicate structural/architectural changes
|
|
57
|
+
const STRUCTURAL_PATTERNS = [
|
|
58
|
+
/^export\s+(default\s+)?(class|interface|type|enum|const|function)\s/m,
|
|
59
|
+
/^(class|interface|type|enum)\s+\w+/m,
|
|
60
|
+
/module\.exports/m,
|
|
61
|
+
/createRouter|createApp|express\(\)/m,
|
|
62
|
+
/new\s+(MongoClient|Pool|Redis|Server)/m,
|
|
63
|
+
];
|
|
64
|
+
// ─── Tool-Specific Dispatch ─────────────────────────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* New entry point: dispatches to tool-specific handlers based on
|
|
67
|
+
* the structured JSON from Claude Code stdin.
|
|
68
|
+
*/
|
|
69
|
+
async function postToolUseDispatch(input) {
|
|
70
|
+
const toolName = input.tool_name || '';
|
|
71
|
+
switch (toolName) {
|
|
72
|
+
case 'Edit':
|
|
73
|
+
case 'Write':
|
|
74
|
+
return postToolUseFileChange(input);
|
|
75
|
+
case 'Bash':
|
|
76
|
+
return postToolUseBash(input);
|
|
77
|
+
default:
|
|
78
|
+
return postToolUseGeneric(input);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* After Edit/Write: detect significant code changes worth remembering.
|
|
83
|
+
* Uses heuristics, not AI — fast and free.
|
|
84
|
+
*/
|
|
85
|
+
async function postToolUseFileChange(input) {
|
|
86
|
+
const filePath = (0, hook_input_js_1.getFilePath)(input);
|
|
87
|
+
if (!filePath)
|
|
88
|
+
return null;
|
|
89
|
+
const fileName = filePath.split('/').pop() || '';
|
|
90
|
+
const reasons = [];
|
|
91
|
+
// Check 1: Is this a significant config file?
|
|
92
|
+
if (SIGNIFICANT_FILES.some((sf) => fileName.includes(sf) || filePath.endsWith(sf))) {
|
|
93
|
+
reasons.push('config file changed');
|
|
94
|
+
}
|
|
95
|
+
// Check 2: Does the change contain structural patterns?
|
|
96
|
+
// For Edit: check new_string. For Write: check content (full file).
|
|
97
|
+
const newContent = input.tool_input?.new_string || input.tool_input?.content || '';
|
|
98
|
+
const oldContent = input.tool_input?.old_string || '';
|
|
99
|
+
const combinedContent = newContent + ' ' + oldContent;
|
|
100
|
+
if (combinedContent.trim() && STRUCTURAL_PATTERNS.some((p) => p.test(combinedContent))) {
|
|
101
|
+
reasons.push('structural code change');
|
|
102
|
+
}
|
|
103
|
+
// Check 3: First-time file touch — not mentioned in any memory
|
|
104
|
+
if (reasons.length === 0) {
|
|
105
|
+
try {
|
|
106
|
+
const existing = await (0, project_js_1.searchByFilePath)(filePath);
|
|
107
|
+
if (existing.length === 0) {
|
|
108
|
+
reasons.push('first-time file touch');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Skip first-touch check on DB error
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (reasons.length === 0)
|
|
116
|
+
return null;
|
|
117
|
+
const shortPath = filePath.split('/').slice(-2).join('/');
|
|
118
|
+
// Auto-capture: store a summary of what changed
|
|
119
|
+
if (reasons.includes('config file changed')) {
|
|
120
|
+
autoCapture(`Config changed: ${shortPath}`);
|
|
121
|
+
}
|
|
122
|
+
if (reasons.includes('structural code change')) {
|
|
123
|
+
autoCapture(`Code structure change in ${shortPath} (new export/class/interface/type)`);
|
|
124
|
+
}
|
|
125
|
+
if (reasons.includes('first-time file touch')) {
|
|
126
|
+
autoCapture(`New file touched: ${filePath.split('/').slice(-3).join('/')}`);
|
|
127
|
+
}
|
|
128
|
+
return `[MEMORY] Notable change in ${shortPath} (${reasons.join(', ')}). Use the \`remember\` MCP tool if this is an architecture decision worth preserving.`;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* After Bash: flag notable command outcomes (errors, test results, deploys).
|
|
132
|
+
*/
|
|
133
|
+
async function postToolUseBash(input) {
|
|
134
|
+
const command = (0, hook_input_js_1.getBashCommand)(input);
|
|
135
|
+
const result = input.tool_result || '';
|
|
136
|
+
if (!command || !result)
|
|
137
|
+
return null;
|
|
138
|
+
// Only check meaningful output
|
|
139
|
+
if (result.length < 20)
|
|
140
|
+
return null;
|
|
141
|
+
const resultLower = result.toLowerCase();
|
|
142
|
+
const commandLower = command.toLowerCase();
|
|
143
|
+
// Test results
|
|
144
|
+
const isTestCommand = commandLower.includes('npm test') ||
|
|
145
|
+
commandLower.includes('vitest') ||
|
|
146
|
+
commandLower.includes('jest') ||
|
|
147
|
+
commandLower.includes('pytest') ||
|
|
148
|
+
commandLower.includes('npm run test');
|
|
149
|
+
if (isTestCommand) {
|
|
150
|
+
const hasFail = resultLower.includes('fail') || resultLower.includes('error');
|
|
151
|
+
if (hasFail) {
|
|
152
|
+
// Extract first meaningful error line for the auto-capture summary
|
|
153
|
+
const errorLine = extractFirstErrorLine(result);
|
|
154
|
+
const shortCmd = command.length > 60 ? command.slice(0, 60) + '...' : command;
|
|
155
|
+
autoCapture(`Test failure: ${shortCmd} — ${errorLine}`);
|
|
156
|
+
return `[MEMORY] Test failures detected. If this reveals a pattern or known issue, consider storing it with the \`remember\` MCP tool.`;
|
|
157
|
+
}
|
|
158
|
+
// Don't nag on passing tests
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
// Deploy/publish commands
|
|
162
|
+
const isDeployCommand = commandLower.includes('npm publish') ||
|
|
163
|
+
commandLower.includes('docker push') ||
|
|
164
|
+
commandLower.includes('git push');
|
|
165
|
+
if (isDeployCommand) {
|
|
166
|
+
const shortCmd = command.length > 80 ? command.slice(0, 80) + '...' : command;
|
|
167
|
+
autoCapture(`Deploy completed: ${shortCmd}`);
|
|
168
|
+
return `[MEMORY] Deploy/publish command completed. Consider storing the version or outcome with the \`remember\` MCP tool.`;
|
|
169
|
+
}
|
|
170
|
+
// Significant errors (silent capture — no suggestion string)
|
|
171
|
+
const errorPatterns = /\b(error:|fatal:|enoent|permission denied|command not found|segmentation fault|killed|oom)\b/i;
|
|
172
|
+
if (errorPatterns.test(result)) {
|
|
173
|
+
const errorLine = extractFirstErrorLine(result);
|
|
174
|
+
const shortCmd = command.length > 60 ? command.slice(0, 60) + '...' : command;
|
|
175
|
+
autoCapture(`Command error: ${shortCmd} — ${errorLine}`);
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Extract the first meaningful error/failure line from command output.
|
|
181
|
+
* Skips blank lines and common noise. Truncates to 150 chars.
|
|
182
|
+
*/
|
|
183
|
+
function extractFirstErrorLine(output) {
|
|
184
|
+
const lines = output.split('\n');
|
|
185
|
+
const errorLine = lines.find((line) => {
|
|
186
|
+
const trimmed = line.trim();
|
|
187
|
+
if (!trimmed || trimmed.length < 5)
|
|
188
|
+
return false;
|
|
189
|
+
return /\b(error|fail|fatal|exception|panic|enoent|denied|not found)\b/i.test(trimmed);
|
|
190
|
+
});
|
|
191
|
+
const raw = errorLine?.trim() || lines.find((l) => l.trim().length > 10)?.trim() || 'unknown error';
|
|
192
|
+
return raw.length > 150 ? raw.slice(0, 150) + '...' : raw;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Generic fallback: natural language intent detection for memory commands.
|
|
196
|
+
* Handles "remember X", "store this", "recall Y" etc.
|
|
197
|
+
*/
|
|
198
|
+
async function postToolUseGeneric(input) {
|
|
199
|
+
// Extract conversational text from tool input
|
|
200
|
+
const text = input.tool_input?.prompt ||
|
|
201
|
+
input.tool_input?.content ||
|
|
202
|
+
'';
|
|
203
|
+
if (!text)
|
|
204
|
+
return null;
|
|
205
|
+
return processMemoryCommand(text);
|
|
206
|
+
}
|
|
207
|
+
// ─── Legacy Entry Points (backward compat) ──────────────────────────────────
|
|
208
|
+
/**
|
|
209
|
+
* Original PostToolUse entry point.
|
|
210
|
+
* Kept for backward compatibility when stdin is not JSON.
|
|
10
211
|
*/
|
|
11
212
|
async function postToolUse(toolName, toolInput, toolOutput) {
|
|
12
|
-
// Check tool input for explicit memory commands from the developer
|
|
13
213
|
if (toolInput) {
|
|
14
214
|
return processMemoryCommand(toolInput);
|
|
15
215
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-tool-use.js","sourceRoot":"","sources":["../../src/hooks/post-tool-use.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"post-tool-use.js","sourceRoot":"","sources":["../../src/hooks/post-tool-use.ts"],"names":[],"mappings":";;AAmEA,kDAYC;AAyJD,kCASC;AAMD,oDAkBC;AAzQD,6DAA4D;AAC5D,6DAA6D;AAC7D,qDAAuF;AACvF,6DAA+D;AAC/D,4CAA8C;AAE9C,mDAA8D;AAE9D,8EAA8E;AAE9E;;;GAGG;AACH,S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Root":"","sources":["../../src/hooks/pre-compact.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,wBAAsB,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwBzE"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preCompact = preCompact;
|
|
4
|
+
/**
|
|
5
|
+
* PreCompact hook — fires before /compact or auto-compression.
|
|
6
|
+
* Reads the transcript and stores substantive content before it's lost.
|
|
7
|
+
*/
|
|
8
|
+
const client_js_1 = require("../atlas/client.js");
|
|
9
|
+
const config_js_1 = require("../config.js");
|
|
10
|
+
const project_js_1 = require("../memory/project.js");
|
|
11
|
+
const transcript_utils_js_1 = require("./transcript-utils.js");
|
|
12
|
+
async function preCompact(input) {
|
|
13
|
+
if (!(0, config_js_1.isConfigured)())
|
|
14
|
+
return null;
|
|
15
|
+
const transcriptPath = input.transcript_path;
|
|
16
|
+
if (!transcriptPath)
|
|
17
|
+
return null;
|
|
18
|
+
try {
|
|
19
|
+
await (0, client_js_1.connect)();
|
|
20
|
+
const messages = (0, transcript_utils_js_1.extractSubstantiveContent)(transcriptPath);
|
|
21
|
+
if (messages.length === 0)
|
|
22
|
+
return null;
|
|
23
|
+
let stored = 0;
|
|
24
|
+
for (const msg of messages) {
|
|
25
|
+
await (0, project_js_1.addContext)(msg);
|
|
26
|
+
stored++;
|
|
27
|
+
}
|
|
28
|
+
return stored > 0
|
|
29
|
+
? `[MEMORY] Checkpoint: ${stored} items captured before compact.`
|
|
30
|
+
: null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=pre-compact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pre-compact.js","sourceRoot":"","sources":["../../src/hooks/pre-compact.ts"],"names":[],"mappings":";;AAUA,gCAwBC;AAlCD;;;GAGG;AACH,kDAA6C;AAC7C,4CAA4C;AAC5C,qDAAkD;AAClD,+DAAkE;AAG3D,KAAK,UAAU,UAAU,CAAC,KAAgB;IAC/C,IAAI,CAAC,IAAA,wBAAY,GAAE;QAAE,OAAO,IAAI,CAAC;IAEjC,MAAM,cAAc,GAAG,KAAK,CAAC,eAAe,CAAC;IAC7C,IAAI,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC;IAEjC,IAAI,CAAC;QACH,MAAM,IAAA,mBAAO,GAAE,CAAC;QAEhB,MAAM,QAAQ,GAAG,IAAA,+CAAyB,EAAC,cAAc,CAAC,CAAC;QAC3D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QAEvC,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC;YACtB,MAAM,EAAE,CAAC;QACX,CAAC;QAED,OAAO,MAAM,GAAG,CAAC;YACf,CAAC,CAAC,wBAAwB,MAAM,iCAAiC;YACjE,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
import { CommandCache } from '../cache/command-cache.js';
|
|
2
|
+
import type { HookInput } from './hook-input.js';
|
|
2
3
|
export declare function initCommandCache(): Promise<void>;
|
|
4
|
+
/**
|
|
5
|
+
* Reload the command cache from the database.
|
|
6
|
+
* Call after command mutations (store/delete) to keep the cache fresh.
|
|
7
|
+
*/
|
|
8
|
+
export declare function reloadCommandCache(): Promise<void>;
|
|
3
9
|
export declare function getCommandCache(): CommandCache | null;
|
|
10
|
+
/**
|
|
11
|
+
* New entry point: dispatches to tool-specific handlers based on the
|
|
12
|
+
* structured JSON that Claude Code sends via stdin.
|
|
13
|
+
*/
|
|
14
|
+
export declare function preToolUseDispatch(input: HookInput): Promise<string | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Original entry point: semantic search on a raw text prompt.
|
|
17
|
+
* Kept for backward compatibility when stdin is not JSON.
|
|
18
|
+
*/
|
|
4
19
|
export declare function preToolUse(prompt: string): Promise<string | null>;
|
|
5
20
|
//# sourceMappingURL=pre-tool-use.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pre-tool-use.d.ts","sourceRoot":"","sources":["../../src/hooks/pre-tool-use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"pre-tool-use.d.ts","sourceRoot":"","sources":["../../src/hooks/pre-tool-use.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AASzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAOjD,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAKtD;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWxD;AAED,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAErD;AAID;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiBjF;AAgHD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA8DvE"}
|