claude-code-session-manager 0.136.2 → 0.137.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/dist/assets/{AgentLibrary-CbvVbzm2.js → AgentLibrary-DV0DTZDC.js} +1 -1
- package/dist/assets/{AppSettings-Blks3xh_.js → AppSettings-l7NTc0yu.js} +1 -1
- package/dist/assets/{Button-hPwe-y_4.js → Button-Cmfkgjfa.js} +1 -1
- package/dist/assets/{DocumentEditorPane-C_fgkNoa.js → DocumentEditorPane-MTljV-Uw.js} +1 -1
- package/dist/assets/{Extensions-CcDjNq7W.js → Extensions-Cc1Q_8id.js} +2 -2
- package/dist/assets/{History-D4s5ykcm.js → History-CFo-1DHo.js} +1 -1
- package/dist/assets/{Library-BtJ7gnDM.js → Library-C_ibFiOx.js} +1 -1
- package/dist/assets/{ListDetail-Bbwwd-HR.js → ListDetail-ByULG209.js} +1 -1
- package/dist/assets/{Panel-8xYPYH7R.js → Panel-BuInRmA0.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-yqqVtHY7.js +25 -0
- package/dist/assets/{ProvenanceBadge-COnyY49b.js → ProvenanceBadge-CJvnQReI.js} +1 -1
- package/dist/assets/{Scheduler-CpmSitKx.js → Scheduler-B7sn2mUw.js} +1 -1
- package/dist/assets/{Settings-Blfjp8Bp.js → Settings-DRRSJksU.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-pYSyx841.js → SkillReferenceGraph-DwV0Ueyc.js} +1 -1
- package/dist/assets/{Skills-C4fV80-T.js → Skills-DVYHA9gV.js} +1 -1
- package/dist/assets/{SourceChip-Bx9marLv.js → SourceChip-DfJ5_5rV.js} +1 -1
- package/dist/assets/{SystemPrompt-CBvedERn.js → SystemPrompt-f11wGllK.js} +1 -1
- package/dist/assets/{TiptapBody-BV7WhKYF.js → TiptapBody-Bl8hDhhS.js} +1 -1
- package/dist/assets/{Toggle-BUPbeHTj.js → Toggle-DaxeFDFp.js} +1 -1
- package/dist/assets/{ViewTabs-oXSVRUrm.js → ViewTabs-DRtgFKRw.js} +1 -1
- package/dist/assets/{VoiceButton-Ca6X_WNA.js → VoiceButton-DJx-jY4r.js} +1 -1
- package/dist/assets/{historyTotals-BcJ7QH96.js → historyTotals-Cgjm5q24.js} +1 -1
- package/dist/assets/{index-h8BmSc_8.js → index-iQ6pdyuS.js} +3 -3
- package/dist/index.html +1 -1
- package/dist-web/app.js +334 -334
- package/package.json +1 -1
- package/plugins/CLAUDE.md +1 -0
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +1 -0
- package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +2 -0
- package/scripts/scheduler-mcp-server.cjs +46 -2
- package/src/main/build-info.json +4 -4
- package/src/main/lib/CLAUDE.md +2 -0
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +58 -12
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +14 -1
- package/src/main/lib/memoryRefResolve.cjs +64 -2
- package/src/main/lib/memoryStale.cjs +111 -18
- package/src/main/memoryAssist.cjs +23 -7
- package/src/main/memoryTool.cjs +58 -5
- package/src/main/promptSessionsIpc.cjs +1 -1
- package/src/main/templates/PRD_AUTHORING.md +3 -1
- package/src/preload/api.d.ts +2 -0
- package/dist/assets/ProjectClaudeConfig-B9PlbaSV.js +0 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-code-session-manager",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.137.0",
|
|
4
4
|
"description": "Local cockpit for the Claude Code CLI — multi-tab terminal, full config surface, scheduler, voice dictation, and live observability.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/main/index.cjs",
|
package/plugins/CLAUDE.md
CHANGED
|
@@ -15,6 +15,7 @@ Two manifests: root [`.claude-plugin/marketplace.json`](../.claude-plugin/market
|
|
|
15
15
|
declares the one plugin (`source: "./plugins/session-manager-dev"`); the plugin's own
|
|
16
16
|
[`session-manager-dev/.claude-plugin/plugin.json`](session-manager-dev/.claude-plugin/plugin.json)
|
|
17
17
|
carries the `description` shown in the marketplace UI — list only shipped skills.
|
|
18
|
+
Bumping a plugin's `plugin.json` version requires bumping its entry in `.claude-plugin/marketplace.json` in the same PRD (PRD 3140 was refuted for missing it).
|
|
18
19
|
|
|
19
20
|
`src/main/seedDevPlugin.cjs` is the first-boot offline installer — installs this plugin from its
|
|
20
21
|
bundled marketplace (no GitHub/registry call) as a default on a fresh machine, then marks
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "session-manager-dev",
|
|
3
3
|
"description": "The default end-to-end development skillset for the Claude Code Session Manager: decompose work into scheduler PRDs and track them to a validated finish (/develop), publish releases to npm (/builder), hand a finding to another project on this machine (/send-feedback), and review or drift-check a project's CLAUDE.md/markdown network (/maintaining-md-network). Together with the session-manager scheduler these form a develop → queue → validate → release loop.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.3",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Bilko Bibitkov",
|
|
7
7
|
"email": "BilkoBibitkov2000@gmail.com",
|
|
@@ -90,6 +90,7 @@ have no `release.yml`) always use steps 5-11:
|
|
|
90
90
|
paths as fixtures and fail there.
|
|
91
91
|
6. In the worktree: `npm ci`, then the gates again (step 3), then the project's build. Check
|
|
92
92
|
every `files` entry in `package.json` exists before publishing; stop on any failure.
|
|
93
|
+
A cold `test:unit` in a fresh publish worktree can time out under load; rerun the failed files, then the full suite, before calling the gate red — never publish on the partial rerun.
|
|
93
94
|
7. `npm publish` from inside the worktree, so `prepublishOnly` builds there too.
|
|
94
95
|
A 403 saying two-factor authentication or a bypass-2FA granular token is required is not a
|
|
95
96
|
login problem (`npm whoami` can succeed). Don't retry `npm login` or `npm publish`: run
|
|
@@ -42,6 +42,8 @@ round-trip, not a wrong write.
|
|
|
42
42
|
Routing a finding is the **default action, not a question**: a proposal starts
|
|
43
43
|
nothing until a human there approves it. Send it, then report what you delivered.
|
|
44
44
|
|
|
45
|
+
`scheduler_create_prd` resolves its Epic against the CALLING project (a foreign `cwd` only narrows the search), so cross-project work always goes through `feedback_open_session`, never `create_prd`.
|
|
46
|
+
|
|
45
47
|
## Steps
|
|
46
48
|
|
|
47
49
|
### 1. Confirm it's really theirs
|
|
@@ -168,6 +168,37 @@ function resolveCwdArg(args) {
|
|
|
168
168
|
return process.env.SM_PROJECT_ROOT || process.cwd();
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
// This server is registered from a checkout that can be newer than the
|
|
172
|
+
// running app; its version goes into the version-skew message below.
|
|
173
|
+
const MCP_SERVER_VERSION = (() => {
|
|
174
|
+
try { return require('../package.json').version; } catch { return 'unknown'; }
|
|
175
|
+
})();
|
|
176
|
+
|
|
177
|
+
// The transport's own unknown-route 404 (localAdminHttp handleRequest). Apps
|
|
178
|
+
// up to v0.136.2 send exactly { ok:false, error:'not found' }; newer ones add
|
|
179
|
+
// unknownRoute. Route handlers' own 'not found' replies use HTTP 200
|
|
180
|
+
// (reset-job) or other error text (GET /admin/scheduler/prd), so they never match.
|
|
181
|
+
function isUnknownRouteReply(status, body) {
|
|
182
|
+
if (status !== 404 || !body || typeof body !== 'object' || Array.isArray(body)) return false;
|
|
183
|
+
if (body.ok !== false) return false;
|
|
184
|
+
if (typeof body.unknownRoute === 'string') return true;
|
|
185
|
+
return Object.keys(body).length === 2 && body.error === 'not found';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function unknownRouteError(method, urlPath, body) {
|
|
189
|
+
const pathname = String(urlPath).split('?')[0];
|
|
190
|
+
const appVersion = body && typeof body.appVersion === 'string' && body.appVersion
|
|
191
|
+
? ` (running app: v${body.appVersion})` : '';
|
|
192
|
+
const err = new Error(
|
|
193
|
+
`the running Session Manager app has no route ${method} ${pathname}: the app${appVersion} is older than `
|
|
194
|
+
+ `this MCP server (v${MCP_SERVER_VERSION}). Restart Session Manager (Command Palette: 'Reboot app (drain first)') `
|
|
195
|
+
+ 'and call again.',
|
|
196
|
+
);
|
|
197
|
+
// Tagged so callers can add a tool-specific hint (feedback_reply does).
|
|
198
|
+
err.code = 'SM_UNKNOWN_ROUTE';
|
|
199
|
+
return err;
|
|
200
|
+
}
|
|
201
|
+
|
|
171
202
|
async function readAdminConfig() {
|
|
172
203
|
const raw = await fsp.readFile(adminTokenPath(), 'utf8');
|
|
173
204
|
const parsed = JSON.parse(raw);
|
|
@@ -198,11 +229,14 @@ async function adminRequest(method, urlPath, body) {
|
|
|
198
229
|
if (err?.cause?.code === 'ECONNREFUSED') throw new Error(NOT_RUNNING_ERROR);
|
|
199
230
|
throw new Error(busyError(err?.cause?.code || err?.name || 'unknown'));
|
|
200
231
|
}
|
|
232
|
+
let json;
|
|
201
233
|
try {
|
|
202
|
-
|
|
234
|
+
json = await res.json();
|
|
203
235
|
} catch {
|
|
204
236
|
throw new Error(`admin API answered HTTP ${res.status} with a non-JSON body`);
|
|
205
237
|
}
|
|
238
|
+
if (isUnknownRouteReply(res.status, json)) throw unknownRouteError(method, urlPath, json);
|
|
239
|
+
return json;
|
|
206
240
|
}
|
|
207
241
|
|
|
208
242
|
// session_manager_help's live half. The catalog/recipes below are static and
|
|
@@ -1089,7 +1123,17 @@ async function handleCallTool(request) {
|
|
|
1089
1123
|
payload.originProjectRoot = process.env.SM_PROJECT_ROOT;
|
|
1090
1124
|
}
|
|
1091
1125
|
payload.fromCwd = process.cwd();
|
|
1092
|
-
|
|
1126
|
+
let result;
|
|
1127
|
+
try {
|
|
1128
|
+
result = await adminRequest('POST', '/admin/feedback/reply', payload);
|
|
1129
|
+
} catch (err) {
|
|
1130
|
+
if (err && err.code === 'SM_UNKNOWN_ROUTE') {
|
|
1131
|
+
return errorResult(`${err.message} feedback_reply needs Session Manager v0.136.0 or later. `
|
|
1132
|
+
+ 'Until the app is restarted, send your answer with feedback_open_session to the asking project; '
|
|
1133
|
+
+ 'it opens there as a new proposed session.');
|
|
1134
|
+
}
|
|
1135
|
+
throw err;
|
|
1136
|
+
}
|
|
1093
1137
|
// Say only where the reply landed — never that the other project acted.
|
|
1094
1138
|
let note = '';
|
|
1095
1139
|
if (result?.ok !== false) {
|
package/src/main/build-info.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
3
|
-
"gitSha": "
|
|
4
|
-
"gitShortSha": "
|
|
2
|
+
"version": "0.137.0",
|
|
3
|
+
"gitSha": "2ec9176d21aa5c815cbf59feeb935924dcb3342e",
|
|
4
|
+
"gitShortSha": "2ec9176d",
|
|
5
5
|
"gitBranch": "HEAD",
|
|
6
|
-
"builtAt": "2026-11-
|
|
6
|
+
"builtAt": "2026-11-19T18:18:31.246Z",
|
|
7
7
|
"dirty": false
|
|
8
8
|
}
|
package/src/main/lib/CLAUDE.md
CHANGED
|
@@ -50,3 +50,5 @@ Pin `--model` on every `claude -p` spawn.
|
|
|
50
50
|
|
|
51
51
|
- Never `path.join` an agent cwd to build an ops path — use `opsPath`.
|
|
52
52
|
- No private process caps, no hand-rolled tmp+rename, no new `JSON.parse(readFileSync)` fallbacks.
|
|
53
|
+
- Never call `activeSessions.cjs` `allProjectCwds`/`activeProjectCwds` on an IPC, boot or timer hot path: they scan `~/.claude/projects` synchronously (7k+ dirs, 0.3-4 s; the 2026-10-25 OOM crashes).
|
|
54
|
+
- `ipcSchemas.cjs` `validated()` passes the zod-parsed payload, which strips unknown keys: an IPC key rename the schema misses silently drops the key (2026-11-07 persona wipe). Rename keys and schema in one PRD; prefer `.strict()`.
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
* never for scheduler jobs) — never from an agent-supplied Epic id;
|
|
18
18
|
* - Y must be a cross-project-feedback Epic carrying a complete replyTo;
|
|
19
19
|
* anything else is a NEW request, which is feedback_open_session's job;
|
|
20
|
+
* - LEGACY: a request Epic minted before reply threads (no replyTo, no
|
|
21
|
+
* replyOf) threads to source.fromEpicId in source.fromCwd, without the
|
|
22
|
+
* Claude-session check;
|
|
20
23
|
* - the target is replyTo.epicId and nothing else (toEpicId may only
|
|
21
24
|
* restate it);
|
|
22
25
|
* - at most MAX_REPLIES_PER_THREAD replies per Y, serialized per Y in
|
|
@@ -212,16 +215,11 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
212
215
|
if (!y) return bad(403, 'no Epic in the calling project owns this chat session — cannot reply');
|
|
213
216
|
|
|
214
217
|
// 3. Thread.
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
&& typeof rt.claudeSessionId === 'string' && rt.claudeSessionId;
|
|
221
|
-
if (!threadComplete) {
|
|
222
|
-
return bad(400, 'this session is not answering a cross-project request with a reply thread — '
|
|
223
|
-
+ 'a new request to another project goes through feedback_open_session');
|
|
224
|
-
}
|
|
218
|
+
const resolved = resolveThread(y.source || {});
|
|
219
|
+
if (!resolved.ok) return bad(400, resolved.error);
|
|
220
|
+
const rt = resolved.thread;
|
|
221
|
+
const legacy = resolved.legacy;
|
|
222
|
+
const threadField = legacy ? { thread: 'legacy' } : {};
|
|
225
223
|
if (input.toEpicId !== undefined && input.toEpicId !== null && input.toEpicId !== rt.epicId) {
|
|
226
224
|
return bad(403, `this session may only reply to Epic ${rt.epicId}, the one that asked`);
|
|
227
225
|
}
|
|
@@ -229,7 +227,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
229
227
|
try {
|
|
230
228
|
targetCwd = config.validatePath(path.resolve(rt.cwd));
|
|
231
229
|
} catch (e) {
|
|
232
|
-
return bad(400,
|
|
230
|
+
return bad(400, `${legacy ? 'source.fromCwd' : 'replyTo.cwd'} rejected: ${e.message}`);
|
|
233
231
|
}
|
|
234
232
|
if (!feedbackConduit().isSessionManagerProject(targetCwd)) {
|
|
235
233
|
return bad(400, `${targetCwd} is not a Session Manager project`);
|
|
@@ -296,6 +294,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
296
294
|
toEpicId: rt.epicId,
|
|
297
295
|
fallbackEpicId: opened.epicId,
|
|
298
296
|
receiptOnAskingEpic,
|
|
297
|
+
...threadField,
|
|
299
298
|
...receiptFields(receipt),
|
|
300
299
|
repliesUsed: sent + 1,
|
|
301
300
|
repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
|
|
@@ -306,7 +305,10 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
306
305
|
const x = readActiveIndex(targetCwd).sessions[rt.epicId];
|
|
307
306
|
if (!x) return fallback('missing');
|
|
308
307
|
if (x.status !== 'active') return fallback('not-active');
|
|
309
|
-
|
|
308
|
+
// Legacy threads carry no session pin; X's own (1:1, life-long) session is the one that asked.
|
|
309
|
+
if (legacy ? !(typeof x.claudeSessionId === 'string' && x.claudeSessionId) : x.claudeSessionId !== rt.claudeSessionId) {
|
|
310
|
+
return fallback('session-mismatch');
|
|
311
|
+
}
|
|
310
312
|
|
|
311
313
|
const prompt = composeReplyPrompt({
|
|
312
314
|
fromCwd: replierCwd,
|
|
@@ -349,6 +351,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
349
351
|
fromEpicId: yId,
|
|
350
352
|
outcome,
|
|
351
353
|
delivery,
|
|
354
|
+
...threadField,
|
|
352
355
|
});
|
|
353
356
|
|
|
354
357
|
return {
|
|
@@ -356,6 +359,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
356
359
|
delivery,
|
|
357
360
|
toCwd: targetCwd,
|
|
358
361
|
toEpicId: x.id,
|
|
362
|
+
...threadField,
|
|
359
363
|
...receiptFields(receipt),
|
|
360
364
|
repliesUsed: sent + 1,
|
|
361
365
|
repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
|
|
@@ -364,6 +368,48 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
364
368
|
});
|
|
365
369
|
}
|
|
366
370
|
|
|
371
|
+
const nonEmpty = (v) => typeof v === 'string' && v.length > 0;
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* resolveThread(src) — pure. The thread a replying Epic's `source` names:
|
|
375
|
+
* { ok: true, thread: { cwd, epicId, claudeSessionId }, legacy } or { ok: false, error }.
|
|
376
|
+
* A complete replyTo → legacy false. A pre-reply-thread request Epic (no
|
|
377
|
+
* replyTo key, no replyOf, fromCwd + fromEpicId set) → legacy true, no
|
|
378
|
+
* session pin. Every refusal says why and points at feedback_open_session.
|
|
379
|
+
*/
|
|
380
|
+
function resolveThread(src) {
|
|
381
|
+
const s = src && typeof src === 'object' ? src : {};
|
|
382
|
+
const isRequest = s.producer === 'cross-project-feedback';
|
|
383
|
+
const rt = s.replyTo;
|
|
384
|
+
if (isRequest && rt && typeof rt === 'object'
|
|
385
|
+
&& nonEmpty(rt.cwd) && nonEmpty(rt.epicId) && nonEmpty(rt.claudeSessionId)) {
|
|
386
|
+
return { ok: true, thread: { cwd: rt.cwd, epicId: rt.epicId, claudeSessionId: rt.claudeSessionId }, legacy: false };
|
|
387
|
+
}
|
|
388
|
+
if (s.replyOf) {
|
|
389
|
+
return {
|
|
390
|
+
ok: false,
|
|
391
|
+
error: 'this session is itself a reply that could not be delivered, so it has no thread to answer — '
|
|
392
|
+
+ 'a new request to another project goes through feedback_open_session',
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const hasReplyTo = Object.prototype.hasOwnProperty.call(s, 'replyTo');
|
|
396
|
+
if (isRequest && !hasReplyTo && nonEmpty(s.fromCwd)) {
|
|
397
|
+
if (nonEmpty(s.fromEpicId)) {
|
|
398
|
+
return { ok: true, thread: { cwd: s.fromCwd, epicId: s.fromEpicId, claudeSessionId: null }, legacy: true };
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
ok: false,
|
|
402
|
+
error: 'the sending session was not identified when this request was opened, so there is no thread to answer — '
|
|
403
|
+
+ `send a new request to ${s.fromCwd} with feedback_open_session`,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
return {
|
|
407
|
+
ok: false,
|
|
408
|
+
error: 'this session is not answering a cross-project request with a reply thread — '
|
|
409
|
+
+ 'a new request to another project goes through feedback_open_session',
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
367
413
|
/** Registers POST /admin/feedback/reply on the loopback admin transport —
|
|
368
414
|
* mirrors crossProjectFeedback.registerAdminRoute; auth is the transport's. */
|
|
369
415
|
function registerAdminRoute(adminHttp, deps) {
|
|
@@ -38,6 +38,11 @@ const fsp = require('node:fs/promises');
|
|
|
38
38
|
const config = require('../../config.cjs');
|
|
39
39
|
const schedulerPaths = require('../scheduler/schedulerPaths.cjs');
|
|
40
40
|
|
|
41
|
+
// Reported on unknown-route 404s so a newer scheduler-mcp-server.cjs can tell
|
|
42
|
+
// the agent which app version lacks the route. Read once; omitted if unreadable.
|
|
43
|
+
let APP_VERSION = null;
|
|
44
|
+
try { APP_VERSION = require('../../../../package.json').version || null; } catch { APP_VERSION = null; }
|
|
45
|
+
|
|
41
46
|
/**
|
|
42
47
|
* Mode-aware token file path, resolved fresh on every call (never cached at
|
|
43
48
|
* module load) so a dev/e2e launch never collides with a production
|
|
@@ -145,7 +150,15 @@ function createAdminHttp() {
|
|
|
145
150
|
try {
|
|
146
151
|
const handler = routes.get(`${req.method} ${urlObj.pathname}`);
|
|
147
152
|
if (!handler) {
|
|
148
|
-
|
|
153
|
+
// Keep error 'not found' so older MCP servers still see the same key;
|
|
154
|
+
// unknownRoute marks this as transport-level (version skew), not a
|
|
155
|
+
// route handler's own 'not found'.
|
|
156
|
+
sendJson(res, 404, {
|
|
157
|
+
ok: false,
|
|
158
|
+
error: 'not found',
|
|
159
|
+
unknownRoute: `${req.method} ${urlObj.pathname}`,
|
|
160
|
+
...(APP_VERSION ? { appVersion: APP_VERSION } : {}),
|
|
161
|
+
});
|
|
149
162
|
return;
|
|
150
163
|
}
|
|
151
164
|
await handler(req, res, urlObj.searchParams);
|
|
@@ -23,7 +23,12 @@ function underHome(abs, home) {
|
|
|
23
23
|
return r === '' || (!r.startsWith('..') && !path.isAbsolute(r));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function makeRefResolver({ cwd, trackedFiles = [], exists = fs.existsSync, home = os.homedir() }) {
|
|
26
|
+
function makeRefResolver({ cwd, trackedFiles = [], exists = fs.existsSync, home = os.homedir(), extraBases = [] }) {
|
|
27
|
+
// Extra absolute bases (e.g. the ops root) a repo-relative ref may resolve under; home-confined.
|
|
28
|
+
const bases = extraBases
|
|
29
|
+
.filter((b) => typeof b === 'string' && path.isAbsolute(b))
|
|
30
|
+
.map((b) => path.normalize(b))
|
|
31
|
+
.filter((b) => underHome(b, home));
|
|
27
32
|
const exact = new Set(trackedFiles);
|
|
28
33
|
const byBase = new Map();
|
|
29
34
|
for (const p of trackedFiles) {
|
|
@@ -45,6 +50,9 @@ function makeRefResolver({ cwd, trackedFiles = [], exists = fs.existsSync, home
|
|
|
45
50
|
if (exact.has(rel)) return true;
|
|
46
51
|
const candidates = byBase.get(path.posix.basename(rel));
|
|
47
52
|
if (candidates && candidates.some((p) => p === rel || p.endsWith('/' + rel))) return true;
|
|
53
|
+
for (const base of bases) {
|
|
54
|
+
if (exists(path.join(base, rel))) return true;
|
|
55
|
+
}
|
|
48
56
|
for (const root of roots) {
|
|
49
57
|
const abs = expandRoot(root);
|
|
50
58
|
if (abs && underHome(abs, home) && exists(path.join(abs, rel))) return true;
|
|
@@ -61,4 +69,58 @@ function listTrackedFiles(cwd) {
|
|
|
61
69
|
});
|
|
62
70
|
}
|
|
63
71
|
|
|
64
|
-
|
|
72
|
+
const MAX_RENAME_HOPS = 10;
|
|
73
|
+
const RENAME_LINE_RE = /^R\d*\t([^\t]+)\t([^\t]+)$/;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Map<oldPath, finalPath> from the repo's rename history, one git call.
|
|
77
|
+
* git log prints newest first, so the first time an old path is seen wins.
|
|
78
|
+
* Chains old -> mid -> new are followed up to MAX_RENAME_HOPS, only through
|
|
79
|
+
* renames newer than the previous hop; a cycle stops at the last unvisited
|
|
80
|
+
* path, and a chain that returns to its start is dropped (the path lives
|
|
81
|
+
* where it began). `exec` is injectable for tests.
|
|
82
|
+
* Complexity: O(lines + renames * MAX_RENAME_HOPS).
|
|
83
|
+
*/
|
|
84
|
+
function listRenames(cwd, exec = execFile) {
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
exec(
|
|
87
|
+
'git',
|
|
88
|
+
['-C', cwd, 'log', '--diff-filter=R', '--name-status', '--format=', '-M', 'HEAD'],
|
|
89
|
+
{ timeout: 10_000, maxBuffer: 32 * 1024 * 1024 },
|
|
90
|
+
(err, stdout) => {
|
|
91
|
+
if (err) return resolve(new Map());
|
|
92
|
+
// direct: old -> { to, order }, order 0 = newest rename.
|
|
93
|
+
const direct = new Map();
|
|
94
|
+
let order = 0;
|
|
95
|
+
for (const line of String(stdout).split('\n')) {
|
|
96
|
+
const m = RENAME_LINE_RE.exec(line.replace(/\r$/, ''));
|
|
97
|
+
if (!m) continue;
|
|
98
|
+
if (!direct.has(m[1])) direct.set(m[1], { to: m[2], order });
|
|
99
|
+
order++;
|
|
100
|
+
}
|
|
101
|
+
const out = new Map();
|
|
102
|
+
for (const [from, first] of direct) {
|
|
103
|
+
const visited = new Set([from]);
|
|
104
|
+
let cur = first.to;
|
|
105
|
+
let curOrder = first.order;
|
|
106
|
+
let returned = false;
|
|
107
|
+
visited.add(cur);
|
|
108
|
+
for (let hop = 1; hop < MAX_RENAME_HOPS; hop++) {
|
|
109
|
+
const next = direct.get(cur);
|
|
110
|
+
// Only a LATER rename of the new path continues the chain.
|
|
111
|
+
if (next === undefined || next.order >= curOrder) break;
|
|
112
|
+
if (next.to === from) { returned = true; break; }
|
|
113
|
+
if (visited.has(next.to)) break;
|
|
114
|
+
visited.add(next.to);
|
|
115
|
+
cur = next.to;
|
|
116
|
+
curOrder = next.order;
|
|
117
|
+
}
|
|
118
|
+
if (!returned && cur !== from) out.set(from, cur);
|
|
119
|
+
}
|
|
120
|
+
resolve(out);
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
module.exports = { makeRefResolver, listTrackedFiles, listRenames };
|
|
@@ -38,6 +38,59 @@ function parseMeta(body) {
|
|
|
38
38
|
return { description, type: pick('type'), originSessionId: pick('originSessionId') };
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Top-level (unindented) frontmatter `name:` value, surrounding quotes
|
|
43
|
+
* stripped. A sibling of parseMeta so the result's `name` (the filename) is
|
|
44
|
+
* never clobbered by the meta spread.
|
|
45
|
+
*/
|
|
46
|
+
function parseFrontmatterName(body) {
|
|
47
|
+
const fm = /^---\r?\n([\s\S]*?)\r?\n---/.exec(body);
|
|
48
|
+
if (!fm) return null;
|
|
49
|
+
const m = /^name:[ \t]*(.+?)[ \t]*$/m.exec(fm[1]);
|
|
50
|
+
if (!m) return null;
|
|
51
|
+
const v = m[1].replace(/^"(.*)"$/, '$1').replace(/^'(.*)'$/, '$1').trim();
|
|
52
|
+
return v || null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Lowercase; collapse runs of '-', '_' and whitespace to a single '-'. */
|
|
56
|
+
function normalizeLinkKey(s) {
|
|
57
|
+
return String(s).trim().toLowerCase().replace(/[-_\s]+/g, '-');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* makeLinkResolver(entries) => (target) => canonical filename stem | null
|
|
62
|
+
*
|
|
63
|
+
* entries: Array<{ name, body }>. A wikilink target matches an entry when its
|
|
64
|
+
* normalized form equals the normalized filename stem OR the normalized
|
|
65
|
+
* frontmatter `name:` (Claude Code links memories by the kebab frontmatter
|
|
66
|
+
* name while files are snake_case). Collisions: an exact stem match wins;
|
|
67
|
+
* otherwise filename stems claim keys before frontmatter names, and within
|
|
68
|
+
* each pass the entry whose filename sorts first wins — independent of input
|
|
69
|
+
* order. Complexity: O(entries log entries) build, O(target length) lookup.
|
|
70
|
+
*/
|
|
71
|
+
function makeLinkResolver(entries) {
|
|
72
|
+
const sorted = [...entries].sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
73
|
+
const exactStems = new Set();
|
|
74
|
+
const byKey = new Map();
|
|
75
|
+
for (const e of sorted) {
|
|
76
|
+
const stem = stripName(e.name);
|
|
77
|
+
exactStems.add(stem);
|
|
78
|
+
const key = normalizeLinkKey(stem);
|
|
79
|
+
if (!byKey.has(key)) byKey.set(key, stem);
|
|
80
|
+
}
|
|
81
|
+
for (const e of sorted) {
|
|
82
|
+
const fmName = parseFrontmatterName(e.body || '');
|
|
83
|
+
if (fmName === null) continue;
|
|
84
|
+
const key = normalizeLinkKey(fmName);
|
|
85
|
+
if (!byKey.has(key)) byKey.set(key, stripName(e.name));
|
|
86
|
+
}
|
|
87
|
+
return (target) => {
|
|
88
|
+
const t = String(target).trim();
|
|
89
|
+
if (exactStems.has(t)) return t;
|
|
90
|
+
return byKey.get(normalizeLinkKey(t)) ?? null;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
41
94
|
/**
|
|
42
95
|
* Extract dead-ref candidate paths from a memory body.
|
|
43
96
|
* Complexity: O(body length) — one regex pass, then O(candidates) filtering.
|
|
@@ -78,41 +131,69 @@ function extractRoots(body) {
|
|
|
78
131
|
return out;
|
|
79
132
|
}
|
|
80
133
|
|
|
134
|
+
function escapeRegExp(s) {
|
|
135
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Compile projectRoots ({name, root}[]) into whole-word, case-insensitive
|
|
140
|
+
* matchers. A word boundary is any non-[A-Za-z0-9_] char, so 'Bilko' matches
|
|
141
|
+
* 'bilko-run' but not 'notbilkos'.
|
|
142
|
+
*/
|
|
143
|
+
function compileProjectRoots(projectRoots) {
|
|
144
|
+
return projectRoots
|
|
145
|
+
.filter((p) => p && typeof p.name === 'string' && p.name !== '' && typeof p.root === 'string' && p.root !== '')
|
|
146
|
+
.map((p) => ({ root: p.root, re: new RegExp(`(?<![A-Za-z0-9_])${escapeRegExp(p.name)}(?![A-Za-z0-9_])`, 'i') }));
|
|
147
|
+
}
|
|
148
|
+
|
|
81
149
|
/**
|
|
82
|
-
* scoreMemories({ entries, now, existsPath })
|
|
150
|
+
* scoreMemories({ entries, now, existsPath, projectRoots, renamedTo })
|
|
83
151
|
*
|
|
84
152
|
* entries: Array<{ name, mtimeMs, body }>
|
|
85
153
|
* now: ms epoch
|
|
86
154
|
* existsPath: (relPath: string, roots?: string[]) => boolean
|
|
155
|
+
* projectRoots: Array<{ name, root }> — a root joins a memory's roots when its
|
|
156
|
+
* name appears in the body as a whole word (case-insensitive)
|
|
157
|
+
* renamedTo: (relPath) => string | null — git rename target; a dead candidate
|
|
158
|
+
* whose target exists is reported in movedRefs, not deadRefs, and is not stale
|
|
87
159
|
*
|
|
88
160
|
* Complexity: O(total body bytes) — a single pass per entry to extract
|
|
89
161
|
* wikilink targets and dead-ref candidates; the inbound-link fold is
|
|
90
162
|
* O(entries + total links), NOT O(n^2) substring scans.
|
|
91
163
|
*/
|
|
92
|
-
function scoreMemories({ entries, now, existsPath }) {
|
|
93
|
-
|
|
94
|
-
//
|
|
95
|
-
//
|
|
164
|
+
function scoreMemories({ entries, now, existsPath, projectRoots = [], renamedTo = () => null }) {
|
|
165
|
+
const projectMatchers = compileProjectRoots(projectRoots);
|
|
166
|
+
// Signal 2 (pass 1): per-entry set of wikilink targets, each resolved to its
|
|
167
|
+
// canonical filename stem (raw text when unresolved), deduped so repeated
|
|
168
|
+
// links to the same memory within one body count once toward its inbound
|
|
169
|
+
// count. Self-links (by stem or frontmatter name) are dropped here.
|
|
170
|
+
const resolve = makeLinkResolver(entries);
|
|
96
171
|
const perEntryTargets = entries.map((e) => {
|
|
172
|
+
const selfSlug = stripName(e.name);
|
|
97
173
|
const targets = new Set();
|
|
174
|
+
const dangling = new Set();
|
|
98
175
|
let m;
|
|
99
176
|
WIKILINK_RE.lastIndex = 0;
|
|
100
177
|
while ((m = WIKILINK_RE.exec(e.body)) !== null) {
|
|
101
|
-
|
|
178
|
+
const raw = m[1].trim();
|
|
179
|
+
const canonical = resolve(raw);
|
|
180
|
+
if (canonical === null) {
|
|
181
|
+
targets.add(raw);
|
|
182
|
+
dangling.add(raw);
|
|
183
|
+
} else if (canonical !== selfSlug) {
|
|
184
|
+
targets.add(canonical);
|
|
185
|
+
}
|
|
102
186
|
}
|
|
103
|
-
return targets;
|
|
187
|
+
return { targets, dangling };
|
|
104
188
|
});
|
|
105
189
|
|
|
106
190
|
const inboundCounts = new Map();
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
if (target === selfSlug) continue; // a memory linking itself isn't an inbound reference
|
|
191
|
+
for (const { targets, dangling } of perEntryTargets) {
|
|
192
|
+
for (const target of targets) {
|
|
193
|
+
if (dangling.has(target)) continue;
|
|
111
194
|
inboundCounts.set(target, (inboundCounts.get(target) || 0) + 1);
|
|
112
195
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const knownSlugs = new Set(entries.map((e) => stripName(e.name)));
|
|
196
|
+
}
|
|
116
197
|
|
|
117
198
|
return entries.map((e, i) => {
|
|
118
199
|
const ageDays = Math.floor((now - e.mtimeMs) / DAY_MS);
|
|
@@ -121,7 +202,17 @@ function scoreMemories({ entries, now, existsPath }) {
|
|
|
121
202
|
|
|
122
203
|
const candidates = extractCandidates(e.body);
|
|
123
204
|
const roots = extractRoots(e.body);
|
|
124
|
-
const
|
|
205
|
+
for (const { root, re } of projectMatchers) {
|
|
206
|
+
if (!roots.includes(root) && re.test(e.body)) roots.push(root);
|
|
207
|
+
}
|
|
208
|
+
const deadRefs = [];
|
|
209
|
+
const movedRefs = [];
|
|
210
|
+
for (const c of candidates) {
|
|
211
|
+
if (existsPath(c, roots)) continue;
|
|
212
|
+
const to = renamedTo(c);
|
|
213
|
+
if (typeof to === 'string' && to !== '' && to !== c && existsPath(to, roots)) movedRefs.push({ from: c, to });
|
|
214
|
+
else deadRefs.push(c);
|
|
215
|
+
}
|
|
125
216
|
|
|
126
217
|
const reasons = [];
|
|
127
218
|
if (deadRefs.length > 0) {
|
|
@@ -136,20 +227,22 @@ function scoreMemories({ entries, now, existsPath }) {
|
|
|
136
227
|
reasons.push('90+ days old with no inbound links');
|
|
137
228
|
}
|
|
138
229
|
|
|
139
|
-
const
|
|
230
|
+
const { targets, dangling } = perEntryTargets[i];
|
|
231
|
+
const outLinks = [...targets];
|
|
140
232
|
|
|
141
233
|
return {
|
|
142
234
|
name: e.name,
|
|
143
235
|
...parseMeta(e.body),
|
|
144
236
|
outLinks,
|
|
145
|
-
danglingLinks:
|
|
237
|
+
danglingLinks: [...dangling],
|
|
146
238
|
ageDays,
|
|
147
239
|
inboundLinks,
|
|
148
240
|
deadRefs,
|
|
241
|
+
movedRefs,
|
|
149
242
|
stale: deadRefs.length > 0 || oldAndUnlinked,
|
|
150
243
|
reasons,
|
|
151
244
|
};
|
|
152
245
|
});
|
|
153
246
|
}
|
|
154
247
|
|
|
155
|
-
module.exports = { scoreMemories, extractRoots };
|
|
248
|
+
module.exports = { scoreMemories, extractRoots, makeLinkResolver };
|
|
@@ -13,8 +13,8 @@ const path = require('node:path');
|
|
|
13
13
|
const { extractJson } = require('./lib/util/extractJson.cjs');
|
|
14
14
|
const { runClaudeP: realRunClaudeP } = require('./lib/claude/runClaudeP.cjs');
|
|
15
15
|
const realSessionSlots = require('./lib/scheduler/sessionSlots.cjs');
|
|
16
|
-
const { scoreMemories } = require('./lib/memoryStale.cjs');
|
|
17
|
-
const { makeRefResolver, listTrackedFiles } = require('./lib/memoryRefResolve.cjs');
|
|
16
|
+
const { scoreMemories, makeLinkResolver } = require('./lib/memoryStale.cjs');
|
|
17
|
+
const { makeRefResolver, listTrackedFiles, listRenames } = require('./lib/memoryRefResolve.cjs');
|
|
18
18
|
const { collectMdNetwork } = require('./lib/memoryMdNetwork.cjs');
|
|
19
19
|
|
|
20
20
|
const MODEL = 'sonnet';
|
|
@@ -51,10 +51,16 @@ function selectAskFiles(files, contextName) {
|
|
|
51
51
|
const ctxName = withMd(contextName);
|
|
52
52
|
const ctx = pool.find((f) => f.name === ctxName);
|
|
53
53
|
if (ctx) {
|
|
54
|
+
// Follow [[links]] by filename stem or frontmatter name, as scoreMemories does.
|
|
55
|
+
const resolveLink = makeLinkResolver(pool);
|
|
54
56
|
const linked = new Set([ctxName]);
|
|
55
57
|
let m;
|
|
56
58
|
WIKILINK_RE.lastIndex = 0;
|
|
57
|
-
while ((m = WIKILINK_RE.exec(ctx.body)) !== null)
|
|
59
|
+
while ((m = WIKILINK_RE.exec(ctx.body)) !== null) {
|
|
60
|
+
const target = m[1].trim();
|
|
61
|
+
const stem = resolveLink(target);
|
|
62
|
+
linked.add(withMd(stem === null ? target : stem));
|
|
63
|
+
}
|
|
58
64
|
pool = pool.filter((f) => linked.has(f.name));
|
|
59
65
|
}
|
|
60
66
|
}
|
|
@@ -143,7 +149,12 @@ const ACTIONS = new Set(['update', 'delete', 'fold', 'keep']);
|
|
|
143
149
|
const FOLD_MAX_LINES = 3;
|
|
144
150
|
const FOLD_MAX_CHARS = 600;
|
|
145
151
|
|
|
146
|
-
|
|
152
|
+
/**
|
|
153
|
+
* extraBases / projectRoots / renames are the resolution inputs memoryTool
|
|
154
|
+
* derives for the project (ops root, registered roots, git rename map); a
|
|
155
|
+
* missing `renames` is read from git here, once.
|
|
156
|
+
*/
|
|
157
|
+
async function proposeFix({ name, dir, cwd, extraBases = [], projectRoots = [], renames } = {}, deps = {}) {
|
|
147
158
|
const fail = (error) => ({ ok: false, action: 'keep', summary: '', reason: '', content: '', fold: null, error });
|
|
148
159
|
if (typeof name !== 'string' || !name || name !== path.basename(name) || !name.endsWith('.md')) return fail('invalid memory name');
|
|
149
160
|
const files = await (deps.readDir || defaultReadDir)(dir);
|
|
@@ -152,12 +163,17 @@ async function proposeFix({ name, dir, cwd } = {}, deps = {}) {
|
|
|
152
163
|
|
|
153
164
|
const tracked = Array.isArray(deps.trackedFiles) ? deps.trackedFiles : await listTrackedFiles(cwd);
|
|
154
165
|
const readFile = deps.readFile || ((p) => fs.readFileSync(p, 'utf8'));
|
|
155
|
-
const resolver = makeRefResolver({ cwd, trackedFiles: tracked, ...(deps.exists ? { exists: deps.exists } : {}) });
|
|
156
|
-
const
|
|
166
|
+
const resolver = makeRefResolver({ cwd, trackedFiles: tracked, extraBases, ...(deps.exists ? { exists: deps.exists } : {}) });
|
|
167
|
+
const renameMap = renames instanceof Map ? renames : await (deps.listRenames || listRenames)(cwd);
|
|
168
|
+
const renamedTo = (rel) => renameMap.get(rel) || null;
|
|
169
|
+
// Moved refs land in scored.movedRefs, never deadRefs, so they are not reported as unresolved.
|
|
170
|
+
const [scored] = scoreMemories({ entries: [entry], now: Date.now(), existsPath: resolver, projectRoots, renamedTo });
|
|
157
171
|
const unresolved = {};
|
|
158
172
|
for (const dead of scored.deadRefs) {
|
|
159
173
|
const base = path.posix.basename(dead);
|
|
160
|
-
|
|
174
|
+
const target = renamedTo(dead);
|
|
175
|
+
const byBase = tracked.filter((p) => path.posix.basename(p) === base && p !== target);
|
|
176
|
+
unresolved[dead] = (target ? [target, ...byBase] : byBase).slice(0, MAX_SUGGESTIONS);
|
|
161
177
|
}
|
|
162
178
|
const network = collectMdNetwork({ cwd, memoryBody: entry.body, trackedFiles: tracked, readFile });
|
|
163
179
|
|