agent-working-memory 0.7.16 → 0.8.5
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/README.md +156 -15
- package/dist/adapters/claude-code.d.ts.map +1 -1
- package/dist/adapters/claude-code.js +2 -16
- package/dist/adapters/claude-code.js.map +1 -1
- package/dist/adapters/codex.d.ts.map +1 -1
- package/dist/adapters/codex.js +2 -11
- package/dist/adapters/codex.js.map +1 -1
- package/dist/adapters/common.d.ts +18 -0
- package/dist/adapters/common.d.ts.map +1 -1
- package/dist/adapters/common.js +254 -141
- package/dist/adapters/common.js.map +1 -1
- package/dist/adapters/cursor.d.ts.map +1 -1
- package/dist/adapters/cursor.js +2 -15
- package/dist/adapters/cursor.js.map +1 -1
- package/dist/adapters/http.d.ts.map +1 -1
- package/dist/adapters/http.js +28 -34
- package/dist/adapters/http.js.map +1 -1
- package/dist/api/routes.d.ts +1 -1
- package/dist/api/routes.d.ts.map +1 -1
- package/dist/api/routes.js +280 -113
- package/dist/api/routes.js.map +1 -1
- package/dist/cli/migrate.d.ts +42 -0
- package/dist/cli/migrate.d.ts.map +1 -0
- package/dist/cli/migrate.js +268 -0
- package/dist/cli/migrate.js.map +1 -0
- package/dist/cli.js +45 -1
- package/dist/cli.js.map +1 -1
- package/dist/coordination/circuit-breaker.d.ts +24 -0
- package/dist/coordination/circuit-breaker.d.ts.map +1 -0
- package/dist/coordination/circuit-breaker.js +70 -0
- package/dist/coordination/circuit-breaker.js.map +1 -0
- package/dist/coordination/failure-modes.d.ts +21 -0
- package/dist/coordination/failure-modes.d.ts.map +1 -0
- package/dist/coordination/failure-modes.js +49 -0
- package/dist/coordination/failure-modes.js.map +1 -0
- package/dist/coordination/peer-decisions.js +7 -7
- package/dist/coordination/routes.d.ts.map +1 -1
- package/dist/coordination/routes.js +44 -1
- package/dist/coordination/routes.js.map +1 -1
- package/dist/coordination/schema.d.ts.map +1 -1
- package/dist/coordination/schema.js +18 -0
- package/dist/coordination/schema.js.map +1 -1
- package/dist/coordination/schemas.d.ts +9 -9
- package/dist/coordination/stale.d.ts +9 -1
- package/dist/coordination/stale.d.ts.map +1 -1
- package/dist/coordination/stale.js +53 -9
- package/dist/coordination/stale.js.map +1 -1
- package/dist/core/embeddings.d.ts +16 -10
- package/dist/core/embeddings.d.ts.map +1 -1
- package/dist/core/embeddings.js +54 -38
- package/dist/core/embeddings.js.map +1 -1
- package/dist/core/ml-worker-entry.d.ts +17 -0
- package/dist/core/ml-worker-entry.d.ts.map +1 -0
- package/dist/core/ml-worker-entry.js +193 -0
- package/dist/core/ml-worker-entry.js.map +1 -0
- package/dist/core/ml-worker.d.ts +59 -0
- package/dist/core/ml-worker.d.ts.map +1 -0
- package/dist/core/ml-worker.js +253 -0
- package/dist/core/ml-worker.js.map +1 -0
- package/dist/core/query-expander.d.ts +13 -15
- package/dist/core/query-expander.d.ts.map +1 -1
- package/dist/core/query-expander.js +48 -54
- package/dist/core/query-expander.js.map +1 -1
- package/dist/core/reranker.d.ts +9 -19
- package/dist/core/reranker.d.ts.map +1 -1
- package/dist/core/reranker.js +33 -35
- package/dist/core/reranker.js.map +1 -1
- package/dist/core/salience.d.ts +32 -5
- package/dist/core/salience.d.ts.map +1 -1
- package/dist/core/salience.js +201 -28
- package/dist/core/salience.js.map +1 -1
- package/dist/core/write-pipeline.d.ts +128 -0
- package/dist/core/write-pipeline.d.ts.map +1 -0
- package/dist/core/write-pipeline.js +405 -0
- package/dist/core/write-pipeline.js.map +1 -0
- package/dist/engine/activation.d.ts +2 -2
- package/dist/engine/activation.d.ts.map +1 -1
- package/dist/engine/activation.js +238 -115
- package/dist/engine/activation.js.map +1 -1
- package/dist/engine/confidence.d.ts +62 -0
- package/dist/engine/confidence.d.ts.map +1 -0
- package/dist/engine/confidence.js +100 -0
- package/dist/engine/confidence.js.map +1 -0
- package/dist/engine/connections.d.ts +47 -8
- package/dist/engine/connections.d.ts.map +1 -1
- package/dist/engine/connections.js +83 -22
- package/dist/engine/connections.js.map +1 -1
- package/dist/engine/consolidation-scheduler.d.ts +46 -10
- package/dist/engine/consolidation-scheduler.d.ts.map +1 -1
- package/dist/engine/consolidation-scheduler.js +170 -50
- package/dist/engine/consolidation-scheduler.js.map +1 -1
- package/dist/engine/consolidation.d.ts +16 -2
- package/dist/engine/consolidation.d.ts.map +1 -1
- package/dist/engine/consolidation.js +143 -44
- package/dist/engine/consolidation.js.map +1 -1
- package/dist/engine/eval.d.ts +2 -2
- package/dist/engine/eval.d.ts.map +1 -1
- package/dist/engine/eval.js +9 -9
- package/dist/engine/eval.js.map +1 -1
- package/dist/engine/eviction.d.ts +4 -4
- package/dist/engine/eviction.d.ts.map +1 -1
- package/dist/engine/eviction.js +15 -15
- package/dist/engine/eviction.js.map +1 -1
- package/dist/engine/retraction.d.ts +93 -5
- package/dist/engine/retraction.d.ts.map +1 -1
- package/dist/engine/retraction.js +238 -19
- package/dist/engine/retraction.js.map +1 -1
- package/dist/engine/staging.d.ts +1 -1
- package/dist/engine/staging.d.ts.map +1 -1
- package/dist/engine/staging.js +3 -3
- package/dist/engine/staging.js.map +1 -1
- package/dist/hooks/sidecar.d.ts +1 -1
- package/dist/hooks/sidecar.d.ts.map +1 -1
- package/dist/hooks/sidecar.js +4 -4
- package/dist/hooks/sidecar.js.map +1 -1
- package/dist/index.js +48 -31
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +110 -155
- package/dist/mcp.js.map +1 -1
- package/dist/storage/factory.d.ts +55 -0
- package/dist/storage/factory.d.ts.map +1 -0
- package/dist/storage/factory.js +135 -0
- package/dist/storage/factory.js.map +1 -0
- package/dist/storage/pglite-schema.d.ts +20 -0
- package/dist/storage/pglite-schema.d.ts.map +1 -0
- package/dist/storage/pglite-schema.js +165 -0
- package/dist/storage/pglite-schema.js.map +1 -0
- package/dist/storage/pglite.d.ts +187 -0
- package/dist/storage/pglite.d.ts.map +1 -0
- package/dist/storage/pglite.js +1114 -0
- package/dist/storage/pglite.js.map +1 -0
- package/dist/storage/sqlite.d.ts +117 -0
- package/dist/storage/sqlite.d.ts.map +1 -1
- package/dist/storage/sqlite.js +357 -8
- package/dist/storage/sqlite.js.map +1 -1
- package/dist/storage/store.d.ts +63 -0
- package/dist/storage/store.d.ts.map +1 -0
- package/dist/storage/store.js +27 -0
- package/dist/storage/store.js.map +1 -0
- package/dist/types/engram.d.ts +92 -2
- package/dist/types/engram.d.ts.map +1 -1
- package/dist/types/engram.js.map +1 -1
- package/package.json +3 -1
- package/src/adapters/claude-code.ts +218 -234
- package/src/adapters/codex.ts +252 -262
- package/src/adapters/common.ts +411 -284
- package/src/adapters/cursor.ts +135 -150
- package/src/adapters/http.ts +93 -100
- package/src/adapters/index.ts +31 -31
- package/src/adapters/types.ts +75 -75
- package/src/api/index.ts +3 -3
- package/src/api/routes.ts +367 -120
- package/src/cli/migrate.ts +307 -0
- package/src/cli.ts +37 -1
- package/src/coordination/circuit-breaker.ts +83 -0
- package/src/coordination/events.ts +90 -90
- package/src/coordination/failure-modes.ts +50 -0
- package/src/coordination/peer-decisions.ts +105 -105
- package/src/coordination/plugin-loader.ts +60 -60
- package/src/coordination/plugin.ts +44 -44
- package/src/coordination/routes.ts +56 -1
- package/src/coordination/schema.ts +13 -0
- package/src/coordination/stale.ts +80 -11
- package/src/coordination/types.ts +311 -311
- package/src/coordination/write-mutex.ts +69 -69
- package/src/core/auto-tagger.ts +168 -168
- package/src/core/decay.ts +63 -63
- package/src/core/embeddings.ts +110 -93
- package/src/core/index.ts +5 -5
- package/src/core/logger.ts +36 -36
- package/src/core/ml-worker-entry.ts +194 -0
- package/src/core/ml-worker.ts +281 -0
- package/src/core/query-expander.ts +122 -128
- package/src/core/reranker.ts +119 -125
- package/src/core/salience.ts +200 -33
- package/src/core/write-pipeline.ts +521 -0
- package/src/engine/activation.ts +235 -109
- package/src/engine/confidence.ts +120 -0
- package/src/engine/connections.ts +162 -103
- package/src/engine/consolidation-scheduler.ts +242 -125
- package/src/engine/consolidation.ts +138 -45
- package/src/engine/eval.ts +102 -102
- package/src/engine/eviction.ts +101 -101
- package/src/engine/index.ts +8 -8
- package/src/engine/retraction.ts +366 -116
- package/src/engine/staging.ts +74 -74
- package/src/hooks/sidecar.ts +5 -5
- package/src/index.ts +42 -28
- package/src/mcp.ts +105 -152
- package/src/storage/factory.ts +147 -0
- package/src/storage/index.ts +3 -3
- package/src/storage/pglite-schema.ts +166 -0
- package/src/storage/pglite.ts +1363 -0
- package/src/storage/sqlite.ts +402 -7
- package/src/storage/store.ts +80 -0
- package/src/types/agent.ts +67 -67
- package/src/types/checkpoint.ts +46 -46
- package/src/types/engram.ts +101 -3
- package/src/types/eval.ts +100 -100
- package/src/types/index.ts +6 -6
|
@@ -1,234 +1,218 @@
|
|
|
1
|
-
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Claude Code adapter — writes .mcp.json, CLAUDE.md, and hooks.
|
|
6
|
-
*
|
|
7
|
-
* This is a direct extraction of the original setup() behavior.
|
|
8
|
-
* Zero behavioral change from the monolithic version.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
12
|
-
import { join, dirname, basename } from 'node:path';
|
|
13
|
-
import type { CLIAdapter, SetupContext, DiagnosticResult } from './types.js';
|
|
14
|
-
import { resolveMcpCommand, homedir, AWM_INSTRUCTION_CONTENT } from './common.js';
|
|
15
|
-
|
|
16
|
-
const adapter: CLIAdapter = {
|
|
17
|
-
id: 'claude-code',
|
|
18
|
-
name: 'Claude Code',
|
|
19
|
-
supportsProjectScope: true,
|
|
20
|
-
supportsGlobalScope: true,
|
|
21
|
-
|
|
22
|
-
writeMcpConfig(ctx: SetupContext): string {
|
|
23
|
-
const mcpCmd = resolveMcpCommand(ctx);
|
|
24
|
-
const mcpConfig = { ...mcpCmd, env: ctx.envVars };
|
|
25
|
-
|
|
26
|
-
// Global: ~/.mcp.json (standard MCP location, all projects)
|
|
27
|
-
// Project: .claude/mcp.json (Claude Code's native project scope)
|
|
28
|
-
const mcpJsonPath = ctx.isGlobal
|
|
29
|
-
? join(homedir(), '.mcp.json')
|
|
30
|
-
: join(ctx.cwd, '.claude', 'mcp.json');
|
|
31
|
-
|
|
32
|
-
const mcpDir = dirname(mcpJsonPath);
|
|
33
|
-
if (!existsSync(mcpDir)) {
|
|
34
|
-
mkdirSync(mcpDir, { recursive: true });
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let existing: any = {};
|
|
38
|
-
if (existsSync(mcpJsonPath)) {
|
|
39
|
-
try {
|
|
40
|
-
existing = JSON.parse(readFileSync(mcpJsonPath, 'utf-8'));
|
|
41
|
-
} catch {
|
|
42
|
-
existing = {};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (!existing.mcpServers) existing.mcpServers = {};
|
|
46
|
-
|
|
47
|
-
existing.mcpServers['agent-working-memory'] = mcpConfig;
|
|
48
|
-
writeFileSync(mcpJsonPath, JSON.stringify(existing, null, 2) + '\n');
|
|
49
|
-
return `MCP config: ${mcpJsonPath}`;
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
writeInstructions(ctx: SetupContext, skip: boolean): string {
|
|
53
|
-
const claudeMdPath = ctx.isGlobal
|
|
54
|
-
? join(homedir(), '.claude', 'CLAUDE.md')
|
|
55
|
-
: join(ctx.cwd, 'CLAUDE.md');
|
|
56
|
-
|
|
57
|
-
if (skip) return 'CLAUDE.md: skipped (--no-instructions)';
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
status: '
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
results.push({ check: 'Hooks', status: 'ok', message: 'PreCompact + SessionEnd configured' });
|
|
220
|
-
} else {
|
|
221
|
-
results.push({ check: 'Hooks', status: 'warn', message: 'Hooks partially configured' });
|
|
222
|
-
}
|
|
223
|
-
} catch {
|
|
224
|
-
results.push({ check: 'Hooks', status: 'warn', message: 'settings.json is not valid JSON' });
|
|
225
|
-
}
|
|
226
|
-
} else {
|
|
227
|
-
results.push({ check: 'Hooks', status: 'warn', message: 'No hooks configured (auto-checkpoint disabled)' });
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return results;
|
|
231
|
-
},
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
export default adapter;
|
|
1
|
+
// Copyright 2026 Robert Winter / Complete Ideas
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Claude Code adapter — writes .mcp.json, CLAUDE.md, and hooks.
|
|
6
|
+
*
|
|
7
|
+
* This is a direct extraction of the original setup() behavior.
|
|
8
|
+
* Zero behavioral change from the monolithic version.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
12
|
+
import { join, dirname, basename } from 'node:path';
|
|
13
|
+
import type { CLIAdapter, SetupContext, DiagnosticResult } from './types.js';
|
|
14
|
+
import { resolveMcpCommand, homedir, AWM_INSTRUCTION_CONTENT, upsertAwmSection } from './common.js';
|
|
15
|
+
|
|
16
|
+
const adapter: CLIAdapter = {
|
|
17
|
+
id: 'claude-code',
|
|
18
|
+
name: 'Claude Code',
|
|
19
|
+
supportsProjectScope: true,
|
|
20
|
+
supportsGlobalScope: true,
|
|
21
|
+
|
|
22
|
+
writeMcpConfig(ctx: SetupContext): string {
|
|
23
|
+
const mcpCmd = resolveMcpCommand(ctx);
|
|
24
|
+
const mcpConfig = { ...mcpCmd, env: ctx.envVars };
|
|
25
|
+
|
|
26
|
+
// Global: ~/.mcp.json (standard MCP location, all projects)
|
|
27
|
+
// Project: .claude/mcp.json (Claude Code's native project scope)
|
|
28
|
+
const mcpJsonPath = ctx.isGlobal
|
|
29
|
+
? join(homedir(), '.mcp.json')
|
|
30
|
+
: join(ctx.cwd, '.claude', 'mcp.json');
|
|
31
|
+
|
|
32
|
+
const mcpDir = dirname(mcpJsonPath);
|
|
33
|
+
if (!existsSync(mcpDir)) {
|
|
34
|
+
mkdirSync(mcpDir, { recursive: true });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let existing: any = {};
|
|
38
|
+
if (existsSync(mcpJsonPath)) {
|
|
39
|
+
try {
|
|
40
|
+
existing = JSON.parse(readFileSync(mcpJsonPath, 'utf-8'));
|
|
41
|
+
} catch {
|
|
42
|
+
existing = {};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!existing.mcpServers) existing.mcpServers = {};
|
|
46
|
+
|
|
47
|
+
existing.mcpServers['agent-working-memory'] = mcpConfig;
|
|
48
|
+
writeFileSync(mcpJsonPath, JSON.stringify(existing, null, 2) + '\n');
|
|
49
|
+
return `MCP config: ${mcpJsonPath}`;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
writeInstructions(ctx: SetupContext, skip: boolean): string {
|
|
53
|
+
const claudeMdPath = ctx.isGlobal
|
|
54
|
+
? join(homedir(), '.claude', 'CLAUDE.md')
|
|
55
|
+
: join(ctx.cwd, 'CLAUDE.md');
|
|
56
|
+
|
|
57
|
+
if (skip) return 'CLAUDE.md: skipped (--no-instructions)';
|
|
58
|
+
|
|
59
|
+
const title = ctx.isGlobal ? '# Global Instructions' : `# ${basename(ctx.cwd)}`;
|
|
60
|
+
return upsertAwmSection(claudeMdPath, AWM_INSTRUCTION_CONTENT, { titleIfNew: title });
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
writeHooks(ctx: SetupContext, skip: boolean): string {
|
|
64
|
+
if (skip) return 'Hooks: skipped (--no-hooks)';
|
|
65
|
+
|
|
66
|
+
const settingsPath = join(homedir(), '.claude', 'settings.json');
|
|
67
|
+
let settings: any = {};
|
|
68
|
+
if (existsSync(settingsPath)) {
|
|
69
|
+
try {
|
|
70
|
+
settings = JSON.parse(readFileSync(settingsPath, 'utf-8'));
|
|
71
|
+
} catch {
|
|
72
|
+
settings = {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!settings.hooks) settings.hooks = {};
|
|
76
|
+
|
|
77
|
+
const hookUrl = `http://127.0.0.1:${ctx.hookPort}/hooks/checkpoint`;
|
|
78
|
+
|
|
79
|
+
// Stop — remind Claude to write/recall/switch tasks
|
|
80
|
+
settings.hooks.Stop = [{
|
|
81
|
+
matcher: '',
|
|
82
|
+
hooks: [{
|
|
83
|
+
type: 'command',
|
|
84
|
+
command: 'echo "MEMORY: (1) Did you learn anything new? Call memory_write. (2) Are you about to work on a topic you might have prior knowledge about? Call memory_recall. (3) Switching tasks? Call memory_task_begin."',
|
|
85
|
+
timeout: 5,
|
|
86
|
+
async: true,
|
|
87
|
+
}],
|
|
88
|
+
}];
|
|
89
|
+
|
|
90
|
+
// Multi-port fallback for separate memory pools
|
|
91
|
+
const altPort = ctx.hookPort === '8401' ? '8402' : '8401';
|
|
92
|
+
const hookUrlAlt = `http://127.0.0.1:${altPort}/hooks/checkpoint`;
|
|
93
|
+
const buildHookCmd = (event: string, maxTime: number) => {
|
|
94
|
+
const primary = `curl -sf -X POST ${hookUrl} -H "Content-Type: application/json" -H "Authorization: Bearer ${ctx.hookSecret}" -d "{\\"hook_event_name\\":\\"${event}\\"}" --max-time ${maxTime}`;
|
|
95
|
+
const fallback = `curl -sf -X POST ${hookUrlAlt} -H "Content-Type: application/json" -H "Authorization: Bearer ${ctx.hookSecret}" -d "{\\"hook_event_name\\":\\"${event}\\"}" --max-time ${maxTime}`;
|
|
96
|
+
return `${primary} || ${fallback}`;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// PreCompact — auto-checkpoint before context compaction
|
|
100
|
+
settings.hooks.PreCompact = [{
|
|
101
|
+
matcher: '',
|
|
102
|
+
hooks: [{
|
|
103
|
+
type: 'command',
|
|
104
|
+
command: buildHookCmd('PreCompact', 5),
|
|
105
|
+
timeout: 10,
|
|
106
|
+
}],
|
|
107
|
+
}];
|
|
108
|
+
|
|
109
|
+
// SessionEnd — auto-checkpoint on session close
|
|
110
|
+
settings.hooks.SessionEnd = [{
|
|
111
|
+
matcher: '',
|
|
112
|
+
hooks: [{
|
|
113
|
+
type: 'command',
|
|
114
|
+
command: buildHookCmd('SessionEnd', 2),
|
|
115
|
+
timeout: 5,
|
|
116
|
+
}],
|
|
117
|
+
}];
|
|
118
|
+
|
|
119
|
+
const settingsDir = dirname(settingsPath);
|
|
120
|
+
if (!existsSync(settingsDir)) {
|
|
121
|
+
mkdirSync(settingsDir, { recursive: true });
|
|
122
|
+
}
|
|
123
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
|
124
|
+
|
|
125
|
+
return `Hooks: Stop + PreCompact + SessionEnd (port ${ctx.hookPort})`;
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
diagnose(ctx: SetupContext): DiagnosticResult[] {
|
|
129
|
+
const results: DiagnosticResult[] = [];
|
|
130
|
+
|
|
131
|
+
// Check MCP config — Claude Code reads from both locations, check all
|
|
132
|
+
const globalPath = join(homedir(), '.mcp.json');
|
|
133
|
+
const projectPath = join(ctx.cwd, '.claude', 'mcp.json');
|
|
134
|
+
const candidates = [projectPath, globalPath];
|
|
135
|
+
|
|
136
|
+
let foundConfig = false;
|
|
137
|
+
for (const mcpJsonPath of candidates) {
|
|
138
|
+
if (!existsSync(mcpJsonPath)) continue;
|
|
139
|
+
try {
|
|
140
|
+
const config = JSON.parse(readFileSync(mcpJsonPath, 'utf-8'));
|
|
141
|
+
if (config.mcpServers?.['agent-working-memory']) {
|
|
142
|
+
results.push({ check: 'MCP config', status: 'ok', message: `AWM registered in ${mcpJsonPath}` });
|
|
143
|
+
foundConfig = true;
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
} catch { /* not valid JSON, skip */ }
|
|
147
|
+
}
|
|
148
|
+
if (!foundConfig) {
|
|
149
|
+
results.push({
|
|
150
|
+
check: 'MCP config',
|
|
151
|
+
status: 'fail',
|
|
152
|
+
message: 'No AWM MCP config found',
|
|
153
|
+
fix: `Run: awm setup claude-code${ctx.isGlobal ? ' --global' : ''}`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Check MCP entrypoint
|
|
158
|
+
if (ctx.hasDist) {
|
|
159
|
+
results.push({ check: 'MCP entrypoint', status: 'ok', message: `dist/mcp.js exists` });
|
|
160
|
+
} else {
|
|
161
|
+
results.push({
|
|
162
|
+
check: 'MCP entrypoint',
|
|
163
|
+
status: 'warn',
|
|
164
|
+
message: 'dist/mcp.js not found — using dev mode (npx tsx)',
|
|
165
|
+
fix: 'Run: npm run build',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Check database
|
|
170
|
+
if (existsSync(ctx.dbPath)) {
|
|
171
|
+
results.push({ check: 'Database', status: 'ok', message: ctx.dbPath });
|
|
172
|
+
} else {
|
|
173
|
+
results.push({ check: 'Database', status: 'warn', message: `${ctx.dbPath} not found (will be created on first use)` });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Check CLAUDE.md
|
|
177
|
+
const claudeMdPath = ctx.isGlobal
|
|
178
|
+
? join(homedir(), '.claude', 'CLAUDE.md')
|
|
179
|
+
: join(ctx.cwd, 'CLAUDE.md');
|
|
180
|
+
if (existsSync(claudeMdPath)) {
|
|
181
|
+
const content = readFileSync(claudeMdPath, 'utf-8');
|
|
182
|
+
if (content.includes('## Memory (AWM)')) {
|
|
183
|
+
results.push({ check: 'Instructions', status: 'ok', message: `CLAUDE.md has AWM section` });
|
|
184
|
+
} else {
|
|
185
|
+
results.push({
|
|
186
|
+
check: 'Instructions',
|
|
187
|
+
status: 'warn',
|
|
188
|
+
message: `CLAUDE.md exists but missing AWM section`,
|
|
189
|
+
fix: `Run: awm setup claude-code${ctx.isGlobal ? ' --global' : ''}`,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
results.push({ check: 'Instructions', status: 'warn', message: `CLAUDE.md not found` });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Check hooks
|
|
197
|
+
const settingsPath = join(homedir(), '.claude', 'settings.json');
|
|
198
|
+
if (existsSync(settingsPath)) {
|
|
199
|
+
try {
|
|
200
|
+
const settings = JSON.parse(readFileSync(settingsPath, 'utf-8'));
|
|
201
|
+
const hasHooks = settings.hooks?.PreCompact && settings.hooks?.SessionEnd;
|
|
202
|
+
if (hasHooks) {
|
|
203
|
+
results.push({ check: 'Hooks', status: 'ok', message: 'PreCompact + SessionEnd configured' });
|
|
204
|
+
} else {
|
|
205
|
+
results.push({ check: 'Hooks', status: 'warn', message: 'Hooks partially configured' });
|
|
206
|
+
}
|
|
207
|
+
} catch {
|
|
208
|
+
results.push({ check: 'Hooks', status: 'warn', message: 'settings.json is not valid JSON' });
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
results.push({ check: 'Hooks', status: 'warn', message: 'No hooks configured (auto-checkpoint disabled)' });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return results;
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export default adapter;
|