coding-friend-cli 1.27.1 → 1.27.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/index.js +3 -3
- package/dist/{init-KX6Y3ELD.js → init-FM5D5CD2.js} +1 -1
- package/dist/{session-DMQZXZ7F.js → session-VXYTI2C6.js} +24 -5
- package/lib/cf-memory/README.md +1 -1
- package/lib/cf-memory/src/__tests__/claude-md.test.ts +105 -0
- package/lib/cf-memory/src/lib/claude-md.ts +12 -3
- package/lib/cf-memory/src/tools/delete.ts +3 -3
- package/lib/cf-memory/src/tools/store.ts +14 -2
- package/lib/cf-memory/src/tools/update.ts +21 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ program.command("enable").description("Re-enable the Coding Friend plugin").opti
|
|
|
30
30
|
await enableCommand(opts);
|
|
31
31
|
});
|
|
32
32
|
program.command("init").description("Initialize coding-friend in current project").action(async () => {
|
|
33
|
-
const { initCommand } = await import("./init-
|
|
33
|
+
const { initCommand } = await import("./init-FM5D5CD2.js");
|
|
34
34
|
await initCommand();
|
|
35
35
|
});
|
|
36
36
|
program.command("config").description("Manage Coding Friend configuration").action(async () => {
|
|
@@ -76,11 +76,11 @@ session.command("save").description("Save current Claude Code session to sync fo
|
|
|
76
76
|
"-s, --session-id <id>",
|
|
77
77
|
"session UUID to save (default: auto-detect newest)"
|
|
78
78
|
).option("-l, --label <label>", "label for this session").action(async (opts) => {
|
|
79
|
-
const { sessionSaveCommand } = await import("./session-
|
|
79
|
+
const { sessionSaveCommand } = await import("./session-VXYTI2C6.js");
|
|
80
80
|
await sessionSaveCommand(opts);
|
|
81
81
|
});
|
|
82
82
|
session.command("load").description("Load a saved session from sync folder").action(async () => {
|
|
83
|
-
const { sessionLoadCommand } = await import("./session-
|
|
83
|
+
const { sessionLoadCommand } = await import("./session-VXYTI2C6.js");
|
|
84
84
|
await sessionLoadCommand();
|
|
85
85
|
});
|
|
86
86
|
var memory = program.command("memory").description("AI memory system \u2014 store and search project knowledge");
|
|
@@ -980,7 +980,7 @@ async function initCommand() {
|
|
|
980
980
|
console.log();
|
|
981
981
|
log.congrats("Setup complete!");
|
|
982
982
|
log.dim(
|
|
983
|
-
"Available commands: /cf-ask, /cf-plan, /cf-fix, /cf-commit, /cf-review, /cf-review-out, /cf-review-in, /cf-ship, /cf-optimize, /cf-scan, /cf-remember, /cf-learn, /cf-research, /cf-session, /cf-help"
|
|
983
|
+
"Available commands: /cf-ask, /cf-plan, /cf-fix, /cf-commit, /cf-review, /cf-review-out, /cf-review-in, /cf-ship, /cf-optimize, /cf-scan, /cf-remember, /cf-learn, /cf-teach, /cf-research, /cf-session, /cf-warm, /cf-help"
|
|
984
984
|
);
|
|
985
985
|
}
|
|
986
986
|
export {
|
|
@@ -32,6 +32,10 @@ import {
|
|
|
32
32
|
} from "fs";
|
|
33
33
|
import { join } from "path";
|
|
34
34
|
import { hostname as osHostname } from "os";
|
|
35
|
+
function slugifyLabel(label, maxLen = 100) {
|
|
36
|
+
const slug = label.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, maxLen).replace(/-+$/, "");
|
|
37
|
+
return slug || "session";
|
|
38
|
+
}
|
|
35
39
|
function buildPreviewText(jsonlPath, maxChars = 200) {
|
|
36
40
|
try {
|
|
37
41
|
const content = readFileSync(jsonlPath, "utf-8");
|
|
@@ -65,7 +69,10 @@ function listSyncedSessions(syncDir) {
|
|
|
65
69
|
for (const entry of entries) {
|
|
66
70
|
const metaPath = join(sessionsDir, entry, "meta.json");
|
|
67
71
|
const meta = readJson(metaPath);
|
|
68
|
-
if (meta)
|
|
72
|
+
if (meta) {
|
|
73
|
+
if (!meta.folderName) meta.folderName = entry;
|
|
74
|
+
metas.push(meta);
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
return metas.sort(
|
|
71
78
|
(a, b) => new Date(b.savedAt).getTime() - new Date(a.savedAt).getTime()
|
|
@@ -92,13 +99,17 @@ function remapProjectPath(originalPath, currentHome) {
|
|
|
92
99
|
}
|
|
93
100
|
function saveSession(opts) {
|
|
94
101
|
const { jsonlPath, sessionId, label, projectPath, syncDir, previewText } = opts;
|
|
95
|
-
const
|
|
102
|
+
const sessionsDir = join(syncDir, "sessions");
|
|
103
|
+
const baseSlug = slugifyLabel(label);
|
|
104
|
+
const folderName = uniqueFolderName(sessionsDir, baseSlug);
|
|
105
|
+
const destDir = join(sessionsDir, folderName);
|
|
96
106
|
const destJsonl = join(destDir, "session.jsonl");
|
|
97
107
|
const destMeta = join(destDir, "meta.json");
|
|
98
108
|
mkdirSync(destDir, { recursive: true });
|
|
99
109
|
copyFileSync(jsonlPath, destJsonl);
|
|
100
110
|
const meta = {
|
|
101
111
|
sessionId,
|
|
112
|
+
folderName,
|
|
102
113
|
label,
|
|
103
114
|
projectPath,
|
|
104
115
|
savedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -106,12 +117,20 @@ function saveSession(opts) {
|
|
|
106
117
|
previewText
|
|
107
118
|
};
|
|
108
119
|
writeJson(destMeta, meta);
|
|
120
|
+
return folderName;
|
|
121
|
+
}
|
|
122
|
+
function uniqueFolderName(sessionsDir, base) {
|
|
123
|
+
if (!existsSync(join(sessionsDir, base))) return base;
|
|
124
|
+
let i = 2;
|
|
125
|
+
while (existsSync(join(sessionsDir, `${base}-${i}`))) i++;
|
|
126
|
+
return `${base}-${i}`;
|
|
109
127
|
}
|
|
110
128
|
function loadSession(meta, localProjectPath, syncDir) {
|
|
111
129
|
const encodedPath = encodeProjectPath(localProjectPath);
|
|
112
130
|
const destDir = claudeSessionDir(encodedPath);
|
|
113
131
|
const destPath = join(destDir, `${meta.sessionId}.jsonl`);
|
|
114
|
-
const
|
|
132
|
+
const folder = meta.folderName ?? meta.sessionId;
|
|
133
|
+
const srcPath = join(syncDir, "sessions", folder, "session.jsonl");
|
|
115
134
|
mkdirSync(destDir, { recursive: true });
|
|
116
135
|
copyFileSync(srcPath, destPath);
|
|
117
136
|
}
|
|
@@ -184,7 +203,7 @@ async function sessionSaveCommand(opts = {}) {
|
|
|
184
203
|
default: `session-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}`
|
|
185
204
|
});
|
|
186
205
|
const previewText = buildPreviewText(jsonlPath);
|
|
187
|
-
saveSession({
|
|
206
|
+
const folderName = saveSession({
|
|
188
207
|
jsonlPath,
|
|
189
208
|
sessionId,
|
|
190
209
|
label,
|
|
@@ -193,7 +212,7 @@ async function sessionSaveCommand(opts = {}) {
|
|
|
193
212
|
previewText
|
|
194
213
|
});
|
|
195
214
|
log.success(`Session saved: "${label}"`);
|
|
196
|
-
log.dim(` \u2192 ${join2(docsDir, "sessions",
|
|
215
|
+
log.dim(` \u2192 ${join2(docsDir, "sessions", folderName)}`);
|
|
197
216
|
}
|
|
198
217
|
async function sessionLoadCommand() {
|
|
199
218
|
const docsDir = resolveDocsDir();
|
package/lib/cf-memory/README.md
CHANGED
|
@@ -48,7 +48,7 @@ Detection: Tier 1 → Tier 2 → Tier 3 (first available wins).
|
|
|
48
48
|
|
|
49
49
|
Memories are stored as Markdown files with YAML frontmatter in `docs/memory/<category>/`.
|
|
50
50
|
|
|
51
|
-
Convention memories (`preference` type → `conventions/` folder) are
|
|
51
|
+
Convention memories (`preference` type → `conventions/` folder) are automatically synced to the project's `CLAUDE.md` under a `## CF Memory: Project Rules` section. Other memory types can opt-in to CLAUDE.md sync by setting `sync_to_claude_md: true` when storing or updating — useful for decisions, infrastructure rules, or any project-wide rules that future sessions must follow. Entries are tracked via HTML comments (`<!-- cf:<id> -->`) and are automatically added, updated, or removed when the corresponding memory is stored, updated, or deleted.
|
|
52
52
|
|
|
53
53
|
## Embedding Models
|
|
54
54
|
|
|
@@ -236,3 +236,108 @@ describe("syncToClaudeMd with realistic docsDir", () => {
|
|
|
236
236
|
expect(content).toContain(SECTION_HEADER);
|
|
237
237
|
});
|
|
238
238
|
});
|
|
239
|
+
|
|
240
|
+
describe("migration from old header", () => {
|
|
241
|
+
const OLD_HEADER = "## CF Memory: Conventions";
|
|
242
|
+
|
|
243
|
+
it("reads entries from old header and rewrites with new header on sync", () => {
|
|
244
|
+
writeFileSync(
|
|
245
|
+
claudeMdFile,
|
|
246
|
+
`# My Project\n\n${OLD_HEADER}\n\n- Old rule <!-- cf:conventions/old-rule -->\n`,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
syncToClaudeMd(testDir, "conventions/new-rule", "New rule");
|
|
250
|
+
|
|
251
|
+
const content = readFileSync(claudeMdFile, "utf-8");
|
|
252
|
+
// Should have new header
|
|
253
|
+
expect(content).toContain(SECTION_HEADER);
|
|
254
|
+
// Should NOT have old header (unless they're the same)
|
|
255
|
+
if (SECTION_HEADER !== OLD_HEADER) {
|
|
256
|
+
expect(content).not.toContain(OLD_HEADER);
|
|
257
|
+
}
|
|
258
|
+
// Both entries should be preserved
|
|
259
|
+
expect(content).toContain("Old rule");
|
|
260
|
+
expect(content).toContain("New rule");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("removes entries from old header format", () => {
|
|
264
|
+
writeFileSync(
|
|
265
|
+
claudeMdFile,
|
|
266
|
+
`# My Project\n\n${OLD_HEADER}\n\n- Old rule <!-- cf:conventions/old-rule -->\n- Keep this <!-- cf:conventions/keep -->\n`,
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
removeFromClaudeMd(testDir, "conventions/old-rule");
|
|
270
|
+
|
|
271
|
+
const content = readFileSync(claudeMdFile, "utf-8");
|
|
272
|
+
expect(content).not.toContain("Old rule");
|
|
273
|
+
expect(content).toContain("Keep this");
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe("syncToClaudeMd with non-convention categories", () => {
|
|
278
|
+
it("syncs decisions entries to CLAUDE.md", () => {
|
|
279
|
+
syncToClaudeMd(
|
|
280
|
+
testDir,
|
|
281
|
+
"decisions/api-versioning",
|
|
282
|
+
"Always use URL-based API versioning (v1, v2)",
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const content = readFileSync(claudeMdFile, "utf-8");
|
|
286
|
+
expect(content).toContain(SECTION_HEADER);
|
|
287
|
+
expect(content).toContain("Always use URL-based API versioning");
|
|
288
|
+
expect(content).toContain("<!-- cf:decisions/api-versioning -->");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("syncs infrastructure entries to CLAUDE.md", () => {
|
|
292
|
+
syncToClaudeMd(
|
|
293
|
+
testDir,
|
|
294
|
+
"infrastructure/deploy-checklist",
|
|
295
|
+
"Always run migrations before deploying",
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const content = readFileSync(claudeMdFile, "utf-8");
|
|
299
|
+
expect(content).toContain("Always run migrations before deploying");
|
|
300
|
+
expect(content).toContain("<!-- cf:infrastructure/deploy-checklist -->");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("mixes convention and non-convention entries in same section", () => {
|
|
304
|
+
syncToClaudeMd(testDir, "conventions/naming", "Use camelCase");
|
|
305
|
+
syncToClaudeMd(
|
|
306
|
+
testDir,
|
|
307
|
+
"decisions/db-choice",
|
|
308
|
+
"Use PostgreSQL for all new services",
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const content = readFileSync(claudeMdFile, "utf-8");
|
|
312
|
+
expect(content).toContain("Use camelCase");
|
|
313
|
+
expect(content).toContain("Use PostgreSQL for all new services");
|
|
314
|
+
// Only one section header
|
|
315
|
+
const headerCount = content.split(SECTION_HEADER).length - 1;
|
|
316
|
+
expect(headerCount).toBe(1);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it("removes non-convention entries by ID", () => {
|
|
320
|
+
syncToClaudeMd(testDir, "decisions/api-versioning", "URL-based versioning");
|
|
321
|
+
syncToClaudeMd(testDir, "conventions/naming", "Use camelCase");
|
|
322
|
+
|
|
323
|
+
removeFromClaudeMd(testDir, "decisions/api-versioning");
|
|
324
|
+
|
|
325
|
+
const content = readFileSync(claudeMdFile, "utf-8");
|
|
326
|
+
expect(content).not.toContain("URL-based versioning");
|
|
327
|
+
expect(content).toContain("Use camelCase");
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it("updates non-convention entries", () => {
|
|
331
|
+
syncToClaudeMd(testDir, "infrastructure/ci-rule", "Run lint before tests");
|
|
332
|
+
|
|
333
|
+
updateInClaudeMd(
|
|
334
|
+
testDir,
|
|
335
|
+
"infrastructure/ci-rule",
|
|
336
|
+
"Run lint and type-check before tests",
|
|
337
|
+
);
|
|
338
|
+
|
|
339
|
+
const content = readFileSync(claudeMdFile, "utf-8");
|
|
340
|
+
expect(content).toContain("Run lint and type-check before tests");
|
|
341
|
+
expect(content).not.toContain("Run lint before tests\n");
|
|
342
|
+
});
|
|
343
|
+
});
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
import fs from "node:fs";
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
|
|
17
|
-
export const SECTION_HEADER = "## CF Memory:
|
|
17
|
+
export const SECTION_HEADER = "## CF Memory: Project Rules";
|
|
18
|
+
|
|
19
|
+
/** @deprecated Old header — kept for migration. Removed after reading. */
|
|
20
|
+
const LEGACY_HEADER = "## CF Memory: Conventions";
|
|
18
21
|
|
|
19
22
|
// Tested per-line via .split("\n"), not against the full document,
|
|
20
23
|
// so the $ anchor correctly matches end-of-line without the `m` flag.
|
|
@@ -52,13 +55,19 @@ function parseClaudeMd(content: string): {
|
|
|
52
55
|
after: string;
|
|
53
56
|
untrackedLines: string[];
|
|
54
57
|
} {
|
|
55
|
-
|
|
58
|
+
// Try current header first, then legacy header for migration
|
|
59
|
+
let headerIdx = content.indexOf(SECTION_HEADER);
|
|
60
|
+
let headerLen = SECTION_HEADER.length;
|
|
61
|
+
if (headerIdx === -1) {
|
|
62
|
+
headerIdx = content.indexOf(LEGACY_HEADER);
|
|
63
|
+
headerLen = LEGACY_HEADER.length;
|
|
64
|
+
}
|
|
56
65
|
if (headerIdx === -1) {
|
|
57
66
|
return { before: content, entries: [], after: "", untrackedLines: [] };
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
const before = content.slice(0, headerIdx);
|
|
61
|
-
const rest = content.slice(headerIdx +
|
|
70
|
+
const rest = content.slice(headerIdx + headerLen);
|
|
62
71
|
|
|
63
72
|
// Find the next section header (## ) to determine where our section ends
|
|
64
73
|
const nextSectionMatch = rest.match(/\n(## )/);
|
|
@@ -28,12 +28,12 @@ export function registerDelete(
|
|
|
28
28
|
isError: true,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
// Remove from CLAUDE.md
|
|
32
|
-
if (
|
|
31
|
+
// Remove from CLAUDE.md (any category may have been synced via sync_to_claude_md)
|
|
32
|
+
if (ctx?.docsDir) {
|
|
33
33
|
try {
|
|
34
34
|
removeFromClaudeMd(ctx.docsDir, id);
|
|
35
35
|
} catch {
|
|
36
|
-
// Best-effort
|
|
36
|
+
// Best-effort — removeFromClaudeMd is idempotent
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -40,6 +40,14 @@ export function registerStore(
|
|
|
40
40
|
.describe(
|
|
41
41
|
"When true, skip file creation and return a Memory object for indexing. File must already exist on disk.",
|
|
42
42
|
),
|
|
43
|
+
sync_to_claude_md: z
|
|
44
|
+
.boolean()
|
|
45
|
+
.optional()
|
|
46
|
+
.describe(
|
|
47
|
+
"When true, sync this memory to the project's CLAUDE.md regardless of category. " +
|
|
48
|
+
"Use for memories containing project-wide rules, conventions, or decisions that should be visible in CLAUDE.md. " +
|
|
49
|
+
"Convention memories (type: preference) are always synced automatically.",
|
|
50
|
+
),
|
|
43
51
|
},
|
|
44
52
|
async ({
|
|
45
53
|
title,
|
|
@@ -50,6 +58,7 @@ export function registerStore(
|
|
|
50
58
|
importance,
|
|
51
59
|
source,
|
|
52
60
|
index_only,
|
|
61
|
+
sync_to_claude_md,
|
|
53
62
|
}) => {
|
|
54
63
|
const input = {
|
|
55
64
|
title,
|
|
@@ -73,9 +82,12 @@ export function registerStore(
|
|
|
73
82
|
|
|
74
83
|
const memory = await backend.store(input);
|
|
75
84
|
|
|
76
|
-
// Sync
|
|
85
|
+
// Sync to CLAUDE.md: auto for conventions, opt-in for other categories
|
|
77
86
|
let claudeMdUpdated = false;
|
|
78
|
-
|
|
87
|
+
const shouldSync =
|
|
88
|
+
(memory.category === "conventions" || sync_to_claude_md) &&
|
|
89
|
+
ctx?.docsDir;
|
|
90
|
+
if (shouldSync) {
|
|
79
91
|
try {
|
|
80
92
|
syncToClaudeMd(ctx.docsDir, memory.id, description);
|
|
81
93
|
claudeMdUpdated = true;
|
|
@@ -29,8 +29,23 @@ export function registerUpdate(
|
|
|
29
29
|
.max(5)
|
|
30
30
|
.optional()
|
|
31
31
|
.describe("New importance"),
|
|
32
|
+
sync_to_claude_md: z
|
|
33
|
+
.boolean()
|
|
34
|
+
.optional()
|
|
35
|
+
.describe(
|
|
36
|
+
"When true, sync this memory to the project's CLAUDE.md regardless of category. " +
|
|
37
|
+
"Convention memories (type: preference) are always synced automatically.",
|
|
38
|
+
),
|
|
32
39
|
},
|
|
33
|
-
async ({
|
|
40
|
+
async ({
|
|
41
|
+
id,
|
|
42
|
+
title,
|
|
43
|
+
description,
|
|
44
|
+
tags,
|
|
45
|
+
content,
|
|
46
|
+
importance,
|
|
47
|
+
sync_to_claude_md,
|
|
48
|
+
}) => {
|
|
34
49
|
const memory = await backend.update({
|
|
35
50
|
id,
|
|
36
51
|
title,
|
|
@@ -51,9 +66,12 @@ export function registerUpdate(
|
|
|
51
66
|
};
|
|
52
67
|
}
|
|
53
68
|
|
|
54
|
-
// Sync
|
|
69
|
+
// Sync to CLAUDE.md: auto for conventions, opt-in for other categories
|
|
55
70
|
let claudeMdUpdated = false;
|
|
56
|
-
|
|
71
|
+
const shouldSync =
|
|
72
|
+
(memory.category === "conventions" || sync_to_claude_md) &&
|
|
73
|
+
ctx?.docsDir;
|
|
74
|
+
if (shouldSync) {
|
|
57
75
|
try {
|
|
58
76
|
if (description) {
|
|
59
77
|
// Description changed — update the CLAUDE.md entry
|