coding-friend-cli 1.27.2 → 1.28.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/README.md +9 -3
- package/dist/{chunk-PRIH34UB.js → chunk-DHH6SRXV.js} +5 -1
- package/dist/{chunk-75IEE2OE.js → chunk-E7OY4UWW.js} +2 -2
- package/dist/chunk-J4N2ODQ5.js +191 -0
- package/dist/{chunk-YCWRBOB3.js → chunk-RGQGKOBH.js} +1 -1
- package/dist/{chunk-GDZTU2Z4.js → chunk-XQ5KAXKL.js} +1 -1
- package/dist/{chunk-BX3DRKTU.js → chunk-XROT7L2F.js} +6 -5
- package/dist/{config-N55LTJ76.js → config-U2WEZXF6.js} +4 -4
- package/dist/{dev-BSXR55PZ.js → dev-4OAJCQRQ.js} +29 -5
- package/dist/guide-F2FLCDYO.js +113 -0
- package/dist/{host-JVLWYY5A.js → host-2KBOPER6.js} +2 -2
- package/dist/index.js +35 -26
- package/dist/{init-FM5D5CD2.js → init-R5L2GAFV.js} +5 -5
- package/dist/{install-G4XYNVL3.js → install-XZC6UO54.js} +3 -3
- package/dist/{mcp-DABSO5PE.js → mcp-CNZLJ57B.js} +4 -4
- package/dist/{memory-7Q5P7LIU.js → memory-KU2MOCPQ.js} +4 -4
- package/dist/{session-VXYTI2C6.js → session-ZGNQKV4M.js} +2 -2
- package/dist/{status-K7TBUAXT.js → status-JXUXVHRH.js} +4 -4
- package/dist/{statusline-CDGADB3C.js → statusline-RMTO4MQA.js} +2 -2
- package/dist/{update-6M3YFHS6.js → update-HS6A2C5V.js} +3 -3
- package/lib/cf-memory/README.md +3 -3
- package/lib/cf-memory/src/__tests__/tier.test.ts +59 -0
- package/lib/cf-memory/src/daemon/process.ts +1 -1
- package/lib/cf-memory/src/lib/tier.ts +19 -7
- package/package.json +7 -4
- package/dist/chunk-2HQVNQB7.js +0 -71
package/README.md
CHANGED
|
@@ -147,19 +147,25 @@ npm ls -g coding-friend-cli
|
|
|
147
147
|
|
|
148
148
|
### Running tests
|
|
149
149
|
|
|
150
|
-
Tests are written with [Vitest](https://vitest.dev/)
|
|
150
|
+
Tests are written with [Vitest](https://vitest.dev/).
|
|
151
151
|
|
|
152
152
|
```bash
|
|
153
153
|
cd cli
|
|
154
154
|
|
|
155
|
-
# Run all tests once
|
|
155
|
+
# Run all unit tests once
|
|
156
156
|
npm test
|
|
157
157
|
|
|
158
158
|
# Watch mode (re-runs on file changes)
|
|
159
159
|
npm run test:watch
|
|
160
|
+
|
|
161
|
+
# Run E2E tests (real CLI commands against temp directories)
|
|
162
|
+
npm run test:e2e
|
|
163
|
+
|
|
164
|
+
# Run E2E tests in Docker (isolated, no host pollution)
|
|
165
|
+
cd e2e && docker compose up --build --abort-on-container-exit
|
|
160
166
|
```
|
|
161
167
|
|
|
162
|
-
|
|
168
|
+
Unit tests live in `src/**/__tests__/` and use mocks. E2E tests live in `e2e/` and run actual CLI commands — see [`e2e/README.md`](e2e/README.md) for details.
|
|
163
169
|
|
|
164
170
|
## Publish CLI to npm
|
|
165
171
|
|
|
@@ -6,12 +6,16 @@ var STATUSLINE_COMPONENTS = [
|
|
|
6
6
|
{ id: "branch", label: "Git branch (\u2387 main)" },
|
|
7
7
|
{
|
|
8
8
|
id: "account",
|
|
9
|
-
label: "Account info \u2014 name, email
|
|
9
|
+
label: "Account info \u2014 name, email (from ~/.claude.json)"
|
|
10
10
|
},
|
|
11
11
|
{ id: "context", label: "Context window usage (ctx 42%)" },
|
|
12
12
|
{
|
|
13
13
|
id: "rate_limit",
|
|
14
14
|
label: "Rate limit \u2014 current & weekly usage (requires curl & jq)"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
id: "task_agent",
|
|
18
|
+
label: "Task progress & active agent (Tasks: 2/5 | Agent: cf-reviewer)"
|
|
15
19
|
}
|
|
16
20
|
];
|
|
17
21
|
var ALL_COMPONENT_IDS = STATUSLINE_COMPONENTS.map((c) => c.id);
|
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
getMemoryMcpStatus,
|
|
8
8
|
memoryConfigMenu,
|
|
9
9
|
writeMemoryMcpEntry
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-XROT7L2F.js";
|
|
11
11
|
import {
|
|
12
12
|
getLibPath
|
|
13
13
|
} from "./chunk-RZRT7NGT.js";
|
|
14
14
|
import {
|
|
15
15
|
loadConfig,
|
|
16
16
|
resolveMemoryDir
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-J4N2ODQ5.js";
|
|
18
18
|
import {
|
|
19
19
|
showConfigHint
|
|
20
20
|
} from "./chunk-HPNRQYLM.js";
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_CONFIG
|
|
3
|
+
} from "./chunk-DHH6SRXV.js";
|
|
4
|
+
import {
|
|
5
|
+
globalConfigPath,
|
|
6
|
+
localConfigPath,
|
|
7
|
+
resolvePath
|
|
8
|
+
} from "./chunk-TWKNGPBO.js";
|
|
9
|
+
import {
|
|
10
|
+
log
|
|
11
|
+
} from "./chunk-NREZK463.js";
|
|
12
|
+
import {
|
|
13
|
+
readJson
|
|
14
|
+
} from "./chunk-5UVDWG5L.js";
|
|
15
|
+
|
|
16
|
+
// src/lib/config.ts
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
function deepMerge(base, override) {
|
|
19
|
+
const result = { ...base };
|
|
20
|
+
for (const key of Object.keys(override)) {
|
|
21
|
+
const baseVal = result[key];
|
|
22
|
+
const overVal = override[key];
|
|
23
|
+
if (baseVal && overVal && typeof baseVal === "object" && typeof overVal === "object" && !Array.isArray(baseVal) && !Array.isArray(overVal)) {
|
|
24
|
+
result[key] = deepMerge(
|
|
25
|
+
baseVal,
|
|
26
|
+
overVal
|
|
27
|
+
);
|
|
28
|
+
} else {
|
|
29
|
+
result[key] = overVal;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
var LearnCategorySchema = z.object({
|
|
35
|
+
name: z.string(),
|
|
36
|
+
description: z.string()
|
|
37
|
+
});
|
|
38
|
+
var LearnConfigSchema = z.object({
|
|
39
|
+
language: z.string().optional(),
|
|
40
|
+
outputDir: z.string().optional(),
|
|
41
|
+
categories: z.array(LearnCategorySchema).optional(),
|
|
42
|
+
autoCommit: z.boolean().optional(),
|
|
43
|
+
readmeIndex: z.union([z.boolean(), z.literal("per-category")]).optional()
|
|
44
|
+
});
|
|
45
|
+
var StatuslineComponentSchema = z.enum([
|
|
46
|
+
"version",
|
|
47
|
+
"folder",
|
|
48
|
+
"model",
|
|
49
|
+
"branch",
|
|
50
|
+
"account",
|
|
51
|
+
"context",
|
|
52
|
+
"rate_limit",
|
|
53
|
+
"task_agent"
|
|
54
|
+
]);
|
|
55
|
+
var StatuslineConfigSchema = z.object({
|
|
56
|
+
components: z.array(StatuslineComponentSchema).optional()
|
|
57
|
+
});
|
|
58
|
+
var MemoryConfigSchema = z.object({
|
|
59
|
+
tier: z.enum(["auto", "full", "lite", "markdown"]).optional(),
|
|
60
|
+
daemon: z.object({
|
|
61
|
+
idleTimeout: z.number().optional()
|
|
62
|
+
}).optional(),
|
|
63
|
+
embedding: z.object({
|
|
64
|
+
provider: z.enum(["transformers", "ollama"]).optional(),
|
|
65
|
+
model: z.string().optional(),
|
|
66
|
+
ollamaUrl: z.string().optional()
|
|
67
|
+
}).optional(),
|
|
68
|
+
autoCapture: z.boolean().optional(),
|
|
69
|
+
autoStart: z.boolean().optional()
|
|
70
|
+
});
|
|
71
|
+
var ConfigSchema = z.strictObject({
|
|
72
|
+
language: z.string().optional(),
|
|
73
|
+
docsDir: z.string().optional(),
|
|
74
|
+
learn: LearnConfigSchema.optional(),
|
|
75
|
+
statusline: StatuslineConfigSchema.optional(),
|
|
76
|
+
memory: MemoryConfigSchema.optional(),
|
|
77
|
+
autoApprove: z.boolean().optional()
|
|
78
|
+
});
|
|
79
|
+
var KNOWN_KEYS = [
|
|
80
|
+
"language",
|
|
81
|
+
"docsDir",
|
|
82
|
+
"learn",
|
|
83
|
+
"statusline",
|
|
84
|
+
"memory",
|
|
85
|
+
"autoApprove"
|
|
86
|
+
];
|
|
87
|
+
function suggestKey(unknown) {
|
|
88
|
+
let best = null;
|
|
89
|
+
let bestDist = Infinity;
|
|
90
|
+
for (const known of KNOWN_KEYS) {
|
|
91
|
+
const dist = levenshtein(unknown.toLowerCase(), known.toLowerCase());
|
|
92
|
+
if (dist < bestDist && dist <= 3) {
|
|
93
|
+
bestDist = dist;
|
|
94
|
+
best = known;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return best;
|
|
98
|
+
}
|
|
99
|
+
function levenshtein(a, b) {
|
|
100
|
+
const m = a.length;
|
|
101
|
+
const n = b.length;
|
|
102
|
+
const dp = Array.from(
|
|
103
|
+
{ length: m + 1 },
|
|
104
|
+
() => Array(n + 1).fill(0)
|
|
105
|
+
);
|
|
106
|
+
for (let i = 0; i <= m; i++) dp[i][0] = i;
|
|
107
|
+
for (let j = 0; j <= n; j++) dp[0][j] = j;
|
|
108
|
+
for (let i = 1; i <= m; i++) {
|
|
109
|
+
for (let j = 1; j <= n; j++) {
|
|
110
|
+
dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return dp[m][n];
|
|
114
|
+
}
|
|
115
|
+
function validateConfig(merged) {
|
|
116
|
+
const result = ConfigSchema.safeParse(merged);
|
|
117
|
+
if (result.success) return result.data;
|
|
118
|
+
const sanitized = { ...merged };
|
|
119
|
+
for (const issue of result.error.issues) {
|
|
120
|
+
const pathStr = issue.path.join(".");
|
|
121
|
+
if (issue.code === "unrecognized_keys") {
|
|
122
|
+
const keys = issue.keys ?? [];
|
|
123
|
+
for (const key of keys) {
|
|
124
|
+
const suggestion = suggestKey(key);
|
|
125
|
+
const hint = suggestion ? ` Did you mean '${suggestion}'?` : "";
|
|
126
|
+
log.warn(`Unknown config key '${key}'.${hint}`);
|
|
127
|
+
delete sanitized[key];
|
|
128
|
+
}
|
|
129
|
+
} else {
|
|
130
|
+
log.warn(`Config: ${pathStr} \u2014 ${issue.message}. Using default.`);
|
|
131
|
+
stripPath(sanitized, issue.path);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return deepMerge(
|
|
135
|
+
DEFAULT_CONFIG,
|
|
136
|
+
sanitized
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function stripPath(obj, path) {
|
|
140
|
+
if (path.length === 0) return;
|
|
141
|
+
let current = obj;
|
|
142
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
143
|
+
const key = String(path[i]);
|
|
144
|
+
if (current[key] && typeof current[key] === "object") {
|
|
145
|
+
current = current[key];
|
|
146
|
+
} else {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
delete current[String(path[path.length - 1])];
|
|
151
|
+
}
|
|
152
|
+
function loadConfig() {
|
|
153
|
+
const global = readJson(globalConfigPath());
|
|
154
|
+
const local = readJson(localConfigPath());
|
|
155
|
+
const base = deepMerge(
|
|
156
|
+
DEFAULT_CONFIG,
|
|
157
|
+
global ?? {}
|
|
158
|
+
);
|
|
159
|
+
const merged = deepMerge(base, local ?? {});
|
|
160
|
+
return validateConfig(merged);
|
|
161
|
+
}
|
|
162
|
+
function resolveDocsDir(explicitPath) {
|
|
163
|
+
if (explicitPath) {
|
|
164
|
+
return resolvePath(explicitPath);
|
|
165
|
+
}
|
|
166
|
+
const local = readJson(localConfigPath());
|
|
167
|
+
if (local?.learn?.outputDir) {
|
|
168
|
+
return resolvePath(local.learn.outputDir);
|
|
169
|
+
}
|
|
170
|
+
const global = readJson(globalConfigPath());
|
|
171
|
+
if (global?.learn?.outputDir) {
|
|
172
|
+
return resolvePath(global.learn.outputDir);
|
|
173
|
+
}
|
|
174
|
+
return resolvePath("docs/learn");
|
|
175
|
+
}
|
|
176
|
+
function resolveMemoryDir(explicitPath) {
|
|
177
|
+
if (explicitPath) {
|
|
178
|
+
return resolvePath(explicitPath);
|
|
179
|
+
}
|
|
180
|
+
const config = loadConfig();
|
|
181
|
+
if (config.docsDir) {
|
|
182
|
+
return resolvePath(`${config.docsDir}/memory`);
|
|
183
|
+
}
|
|
184
|
+
return resolvePath("docs/memory");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export {
|
|
188
|
+
loadConfig,
|
|
189
|
+
resolveDocsDir,
|
|
190
|
+
resolveMemoryDir
|
|
191
|
+
};
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-RZRT7NGT.js";
|
|
4
4
|
import {
|
|
5
5
|
resolveMemoryDir
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-J4N2ODQ5.js";
|
|
7
7
|
import {
|
|
8
8
|
BACK,
|
|
9
9
|
askScope,
|
|
@@ -222,16 +222,17 @@ async function editMemoryEmbedding(globalCfg, localCfg) {
|
|
|
222
222
|
async function editMemoryDaemonTimeout(globalCfg, localCfg) {
|
|
223
223
|
const currentDaemon = getMergedMemoryValue("daemon", globalCfg, localCfg);
|
|
224
224
|
const currentMs = currentDaemon?.idleTimeout;
|
|
225
|
-
const currentMin = currentMs ? currentMs / 6e4 : void 0;
|
|
225
|
+
const currentMin = currentMs !== void 0 ? currentMs / 6e4 : void 0;
|
|
226
226
|
if (currentMin !== void 0) {
|
|
227
227
|
log.dim(`Current: ${currentMin} minutes`);
|
|
228
228
|
}
|
|
229
229
|
const value = await input({
|
|
230
|
-
message: "Daemon idle timeout (minutes):",
|
|
231
|
-
default: String(currentMin ??
|
|
230
|
+
message: "Daemon idle timeout (minutes, 0 = no timeout):",
|
|
231
|
+
default: String(currentMin ?? 0),
|
|
232
232
|
validate: (val) => {
|
|
233
233
|
const n = Number(val);
|
|
234
|
-
if (isNaN(n) || n <
|
|
234
|
+
if (isNaN(n) || n < 0)
|
|
235
|
+
return "Must be 0 (no timeout) or a positive number";
|
|
235
236
|
return true;
|
|
236
237
|
}
|
|
237
238
|
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
memoryConfigMenu
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-XROT7L2F.js";
|
|
4
4
|
import "./chunk-RZRT7NGT.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-J4N2ODQ5.js";
|
|
6
6
|
import {
|
|
7
7
|
findStatuslineHookPath,
|
|
8
8
|
isStatuslineConfigured,
|
|
9
9
|
saveStatuslineConfig,
|
|
10
10
|
selectStatuslineComponents,
|
|
11
11
|
writeStatuslineSettings
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-XQ5KAXKL.js";
|
|
13
13
|
import {
|
|
14
14
|
ALL_COMPONENT_IDS,
|
|
15
15
|
DEFAULT_CONFIG
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-DHH6SRXV.js";
|
|
17
17
|
import {
|
|
18
18
|
ensureShellCompletion,
|
|
19
19
|
hasShellCompletion,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ensureStatusline
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-XQ5KAXKL.js";
|
|
4
|
+
import "./chunk-DHH6SRXV.js";
|
|
5
5
|
import {
|
|
6
6
|
ensureShellCompletion
|
|
7
7
|
} from "./chunk-DMJCO6LJ.js";
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
existsSync,
|
|
33
33
|
unlinkSync,
|
|
34
34
|
readdirSync,
|
|
35
|
+
readFileSync,
|
|
35
36
|
statSync,
|
|
36
37
|
mkdirSync,
|
|
37
38
|
copyFileSync
|
|
@@ -255,11 +256,29 @@ async function devSyncCommand() {
|
|
|
255
256
|
}
|
|
256
257
|
const shortDest = cacheVersionDir.replace(homedir(), "~");
|
|
257
258
|
log.step(`Syncing ${chalk.cyan(pluginSrcDir)} \u2192 ${chalk.dim(shortDest)}`);
|
|
259
|
+
const cachedHooksPath = join(cacheVersionDir, "hooks", "hooks.json");
|
|
260
|
+
const sourceHooksPath = join(pluginSrcDir, "hooks", "hooks.json");
|
|
261
|
+
let hooksEventsChanged = false;
|
|
262
|
+
try {
|
|
263
|
+
const cachedHooks = JSON.parse(readFileSync(cachedHooksPath, "utf-8"));
|
|
264
|
+
const sourceHooks = JSON.parse(readFileSync(sourceHooksPath, "utf-8"));
|
|
265
|
+
const cachedEvents = Object.keys(cachedHooks.hooks || {}).sort();
|
|
266
|
+
const sourceEvents = Object.keys(sourceHooks.hooks || {}).sort();
|
|
267
|
+
hooksEventsChanged = JSON.stringify(cachedEvents) !== JSON.stringify(sourceEvents);
|
|
268
|
+
} catch {
|
|
269
|
+
}
|
|
258
270
|
const fileCount = { n: 0 };
|
|
259
271
|
copyDirRecursive(pluginSrcDir, cacheVersionDir, fileCount);
|
|
260
|
-
|
|
261
|
-
`Synced ${chalk.green(fileCount.n)} files
|
|
262
|
-
|
|
272
|
+
if (hooksEventsChanged) {
|
|
273
|
+
log.success(`Synced ${chalk.green(fileCount.n)} files.`);
|
|
274
|
+
log.warn(
|
|
275
|
+
`hooks.json event types changed. Run ${chalk.bold("cf dev restart")} for Claude Code to register the new hook events.`
|
|
276
|
+
);
|
|
277
|
+
} else {
|
|
278
|
+
log.success(
|
|
279
|
+
`Synced ${chalk.green(fileCount.n)} files. Restart Claude Code to apply changes.`
|
|
280
|
+
);
|
|
281
|
+
}
|
|
263
282
|
}
|
|
264
283
|
async function devReinstall(path, label) {
|
|
265
284
|
const state = getDevState();
|
|
@@ -288,6 +307,11 @@ async function devStatusCommand() {
|
|
|
288
307
|
if (state) {
|
|
289
308
|
log.info(`Dev mode: ${chalk.green("ON")}`);
|
|
290
309
|
log.info(`Local path: ${chalk.cyan(state.localPath)}`);
|
|
310
|
+
if (!existsSync(state.localPath)) {
|
|
311
|
+
log.warn(
|
|
312
|
+
`Dev mode path no longer exists: ${state.localPath}. Run 'cf host <new-path>' to update.`
|
|
313
|
+
);
|
|
314
|
+
}
|
|
291
315
|
log.dim(`Since: ${state.savedAt}`);
|
|
292
316
|
} else {
|
|
293
317
|
log.info(`Dev mode: ${chalk.yellow("OFF")}`);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {
|
|
2
|
+
devStatePath,
|
|
3
|
+
pluginCachePath
|
|
4
|
+
} from "./chunk-TWKNGPBO.js";
|
|
5
|
+
import {
|
|
6
|
+
log
|
|
7
|
+
} from "./chunk-NREZK463.js";
|
|
8
|
+
import {
|
|
9
|
+
readJson
|
|
10
|
+
} from "./chunk-5UVDWG5L.js";
|
|
11
|
+
|
|
12
|
+
// src/commands/guide.ts
|
|
13
|
+
import { existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
|
|
14
|
+
import { join, resolve } from "path";
|
|
15
|
+
var GUIDE_TEMPLATE = `# Custom Guide for {{SKILL_NAME}}
|
|
16
|
+
|
|
17
|
+
<!-- Sections are optional \u2014 include only the ones you need. -->
|
|
18
|
+
<!-- This file is loaded automatically when the skill runs. -->
|
|
19
|
+
|
|
20
|
+
## Before
|
|
21
|
+
|
|
22
|
+
<!-- Steps to execute BEFORE the skill's first step. -->
|
|
23
|
+
<!-- Example: run a linter, check prerequisites, set up context. -->
|
|
24
|
+
|
|
25
|
+
## Rules
|
|
26
|
+
|
|
27
|
+
<!-- Additional rules to apply THROUGHOUT all steps of the skill. -->
|
|
28
|
+
<!-- Example: "always use TypeScript strict mode", "never modify tests in src/__tests__". -->
|
|
29
|
+
|
|
30
|
+
## After
|
|
31
|
+
|
|
32
|
+
<!-- Steps to execute AFTER the skill's final step. -->
|
|
33
|
+
<!-- Example: run a formatter, update a changelog, notify a channel. -->
|
|
34
|
+
`;
|
|
35
|
+
function findPluginSkillsDir() {
|
|
36
|
+
const devState = readJson(devStatePath());
|
|
37
|
+
if (devState?.localPath) {
|
|
38
|
+
const dir = join(devState.localPath, "plugin", "skills");
|
|
39
|
+
if (existsSync(dir)) return dir;
|
|
40
|
+
}
|
|
41
|
+
const cachePath = pluginCachePath();
|
|
42
|
+
if (existsSync(cachePath)) {
|
|
43
|
+
try {
|
|
44
|
+
const versions = readdirSync(cachePath, { withFileTypes: true }).filter((e) => e.isDirectory() && /^\d/.test(e.name)).map((e) => e.name).sort((a, b) => b.localeCompare(a, void 0, { numeric: true }));
|
|
45
|
+
for (const ver of versions) {
|
|
46
|
+
const dir = join(cachePath, ver, "plugin", "skills");
|
|
47
|
+
if (existsSync(dir)) return dir;
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function skillExists(skillsDir, skillName) {
|
|
55
|
+
return existsSync(join(skillsDir, skillName, "SKILL.md"));
|
|
56
|
+
}
|
|
57
|
+
function guideCreateCommand(skillName) {
|
|
58
|
+
if (!/^[a-z0-9-]+$/.test(skillName)) {
|
|
59
|
+
log.error(
|
|
60
|
+
`Invalid skill name "${skillName}". Use lowercase letters, numbers, and hyphens only.`
|
|
61
|
+
);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const skillsDir = findPluginSkillsDir();
|
|
65
|
+
if (!skillsDir || !skillExists(skillsDir, skillName)) {
|
|
66
|
+
log.error(
|
|
67
|
+
`Skill "${skillName}" not found. Run "cf guide list" to see available skills.`
|
|
68
|
+
);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const guideDir = resolve(".coding-friend", "skills", `${skillName}-custom`);
|
|
72
|
+
const guidePath = join(guideDir, "SKILL.md");
|
|
73
|
+
if (existsSync(guidePath)) {
|
|
74
|
+
log.warn(`Custom guide already exists: ${guidePath}`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
mkdirSync(guideDir, { recursive: true });
|
|
78
|
+
writeFileSync(
|
|
79
|
+
guidePath,
|
|
80
|
+
GUIDE_TEMPLATE.replace(/\{\{SKILL_NAME\}\}/g, skillName)
|
|
81
|
+
);
|
|
82
|
+
log.success(`Created custom guide: ${guidePath}`);
|
|
83
|
+
log.dim("Edit the file to add your Before/Rules/After sections.");
|
|
84
|
+
}
|
|
85
|
+
function guideListCommand() {
|
|
86
|
+
const customDir = resolve(".coding-friend", "skills");
|
|
87
|
+
if (!existsSync(customDir)) {
|
|
88
|
+
log.dim(
|
|
89
|
+
"No custom guides found. Run `cf guide create <skill-name>` to create one."
|
|
90
|
+
);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const entries = readdirSync(customDir, { withFileTypes: true }).filter(
|
|
94
|
+
(e) => e.isDirectory() && e.name.endsWith("-custom") && existsSync(join(customDir, e.name, "SKILL.md"))
|
|
95
|
+
).map((e) => e.name.replace(/-custom$/, ""));
|
|
96
|
+
if (entries.length === 0) {
|
|
97
|
+
log.dim(
|
|
98
|
+
"No custom guides found. Run `cf guide create <skill-name>` to create one."
|
|
99
|
+
);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const skillsDir = findPluginSkillsDir();
|
|
103
|
+
log.info(`Custom guides (${entries.length}):`);
|
|
104
|
+
for (const name of entries) {
|
|
105
|
+
const path = join(customDir, `${name}-custom`, "SKILL.md");
|
|
106
|
+
const exists = skillsDir != null && skillExists(skillsDir, name) ? "\u2714" : "\u26A0 skill not found";
|
|
107
|
+
log.info(` ${name} \u2192 ${path} (${exists})`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
guideCreateCommand,
|
|
112
|
+
guideListCommand
|
|
113
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ program.name("cf").description(
|
|
|
14
14
|
"coding-friend CLI \u2014 host learning docs, setup MCP, init projects"
|
|
15
15
|
).version(pkg.version, "-v, --version");
|
|
16
16
|
program.command("install").description("Install the Coding Friend plugin into Claude Code").option("--user", "Install at user scope (all projects)").option("--global", "Install at user scope (all projects)").option("--project", "Install at project scope (shared via git)").option("--local", "Install at local scope (this machine only)").action(async (opts) => {
|
|
17
|
-
const { installCommand } = await import("./install-
|
|
17
|
+
const { installCommand } = await import("./install-XZC6UO54.js");
|
|
18
18
|
await installCommand(opts);
|
|
19
19
|
});
|
|
20
20
|
program.command("uninstall").description("Uninstall the Coding Friend plugin from Claude Code").option("--user", "Uninstall from user scope (all projects)").option("--global", "Uninstall from user scope (all projects)").option("--project", "Uninstall from project scope").option("--local", "Uninstall from local scope").action(async (opts) => {
|
|
@@ -30,19 +30,19 @@ 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-R5L2GAFV.js");
|
|
34
34
|
await initCommand();
|
|
35
35
|
});
|
|
36
36
|
program.command("config").description("Manage Coding Friend configuration").action(async () => {
|
|
37
|
-
const { configCommand } = await import("./config-
|
|
37
|
+
const { configCommand } = await import("./config-U2WEZXF6.js");
|
|
38
38
|
await configCommand();
|
|
39
39
|
});
|
|
40
40
|
program.command("host").description("Build and serve learning docs as a static website").argument("[path]", "path to docs folder").option("-p, --port <port>", "port number", "3333").action(async (path, opts) => {
|
|
41
|
-
const { hostCommand } = await import("./host-
|
|
41
|
+
const { hostCommand } = await import("./host-2KBOPER6.js");
|
|
42
42
|
await hostCommand(path, opts);
|
|
43
43
|
});
|
|
44
44
|
program.command("mcp").description("Setup MCP server for learning docs").argument("[path]", "path to docs folder").action(async (path) => {
|
|
45
|
-
const { mcpCommand } = await import("./mcp-
|
|
45
|
+
const { mcpCommand } = await import("./mcp-CNZLJ57B.js");
|
|
46
46
|
await mcpCommand(path);
|
|
47
47
|
});
|
|
48
48
|
program.command("permission").description("Manage Claude Code permission rules for Coding Friend").option("--all", "Apply all recommended permissions without prompts").option("--user", "Save to user-level settings (~/.claude/settings.json)").option(
|
|
@@ -53,15 +53,15 @@ program.command("permission").description("Manage Claude Code permission rules f
|
|
|
53
53
|
await permissionCommand(opts);
|
|
54
54
|
});
|
|
55
55
|
program.command("statusline").description("Setup coding-friend statusline in Claude Code").action(async () => {
|
|
56
|
-
const { statuslineCommand } = await import("./statusline-
|
|
56
|
+
const { statuslineCommand } = await import("./statusline-RMTO4MQA.js");
|
|
57
57
|
await statuslineCommand();
|
|
58
58
|
});
|
|
59
59
|
program.command("update").description("Update coding-friend plugin, CLI, and statusline").option("--cli", "Update only the CLI (npm package)").option("--plugin", "Update only the Claude Code plugin").option("--statusline", "Update only the statusline").option("--user", "Update plugin at user scope (all projects)").option("--global", "Update plugin at user scope (all projects)").option("--project", "Update plugin at project scope").option("--local", "Update plugin at local scope").action(async (opts) => {
|
|
60
|
-
const { updateCommand } = await import("./update-
|
|
60
|
+
const { updateCommand } = await import("./update-HS6A2C5V.js");
|
|
61
61
|
await updateCommand(opts);
|
|
62
62
|
});
|
|
63
63
|
program.command("status").description("Show comprehensive Coding Friend status").action(async () => {
|
|
64
|
-
const { statusCommand } = await import("./status-
|
|
64
|
+
const { statusCommand } = await import("./status-JXUXVHRH.js");
|
|
65
65
|
await statusCommand();
|
|
66
66
|
});
|
|
67
67
|
var session = program.command("session").description("Save and load Claude Code sessions across machines");
|
|
@@ -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-ZGNQKV4M.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-ZGNQKV4M.js");
|
|
84
84
|
await sessionLoadCommand();
|
|
85
85
|
});
|
|
86
86
|
var memory = program.command("memory").description("AI memory system \u2014 store and search project knowledge");
|
|
@@ -100,43 +100,43 @@ Memory subcommands:
|
|
|
100
100
|
memory mcp Show MCP server setup instructions`
|
|
101
101
|
);
|
|
102
102
|
memory.command("status").description("Show memory system status").action(async () => {
|
|
103
|
-
const { memoryStatusCommand } = await import("./memory-
|
|
103
|
+
const { memoryStatusCommand } = await import("./memory-KU2MOCPQ.js");
|
|
104
104
|
await memoryStatusCommand();
|
|
105
105
|
});
|
|
106
106
|
memory.command("search").description("Search memories by query").argument("<query>", "search query").action(async (query) => {
|
|
107
|
-
const { memorySearchCommand } = await import("./memory-
|
|
107
|
+
const { memorySearchCommand } = await import("./memory-KU2MOCPQ.js");
|
|
108
108
|
await memorySearchCommand(query);
|
|
109
109
|
});
|
|
110
110
|
memory.command("list").description(
|
|
111
111
|
"List memories in current project, or all projects with --projects"
|
|
112
112
|
).option("--projects", "List all project databases with size and metadata").action(async (opts) => {
|
|
113
|
-
const { memoryListCommand } = await import("./memory-
|
|
113
|
+
const { memoryListCommand } = await import("./memory-KU2MOCPQ.js");
|
|
114
114
|
await memoryListCommand(opts);
|
|
115
115
|
});
|
|
116
116
|
memory.command("init").description(
|
|
117
117
|
"Initialize memory system \u2014 interactive wizard (first time) or config menu"
|
|
118
118
|
).action(async () => {
|
|
119
|
-
const { memoryInitCommand } = await import("./memory-
|
|
119
|
+
const { memoryInitCommand } = await import("./memory-KU2MOCPQ.js");
|
|
120
120
|
await memoryInitCommand();
|
|
121
121
|
});
|
|
122
122
|
memory.command("config").description("Configure memory system settings").action(async () => {
|
|
123
|
-
const { memoryConfigCommand } = await import("./memory-
|
|
123
|
+
const { memoryConfigCommand } = await import("./memory-KU2MOCPQ.js");
|
|
124
124
|
await memoryConfigCommand();
|
|
125
125
|
});
|
|
126
126
|
memory.command("start-daemon").description("Start the memory daemon (Tier 2 \u2014 MiniSearch)").action(async () => {
|
|
127
|
-
const { memoryStartDaemonCommand } = await import("./memory-
|
|
127
|
+
const { memoryStartDaemonCommand } = await import("./memory-KU2MOCPQ.js");
|
|
128
128
|
await memoryStartDaemonCommand();
|
|
129
129
|
});
|
|
130
130
|
memory.command("stop-daemon").description("Stop the memory daemon").action(async () => {
|
|
131
|
-
const { memoryStopDaemonCommand } = await import("./memory-
|
|
131
|
+
const { memoryStopDaemonCommand } = await import("./memory-KU2MOCPQ.js");
|
|
132
132
|
await memoryStopDaemonCommand();
|
|
133
133
|
});
|
|
134
134
|
memory.command("rebuild").description("Rebuild the daemon search index").action(async () => {
|
|
135
|
-
const { memoryRebuildCommand } = await import("./memory-
|
|
135
|
+
const { memoryRebuildCommand } = await import("./memory-KU2MOCPQ.js");
|
|
136
136
|
await memoryRebuildCommand();
|
|
137
137
|
});
|
|
138
138
|
memory.command("mcp").description("Show MCP server setup instructions").action(async () => {
|
|
139
|
-
const { memoryMcpCommand } = await import("./memory-
|
|
139
|
+
const { memoryMcpCommand } = await import("./memory-KU2MOCPQ.js");
|
|
140
140
|
await memoryMcpCommand();
|
|
141
141
|
});
|
|
142
142
|
memory.command("rm").description("Remove a project database").option("--project-id <id>", "Project ID to remove").option("--all", "Remove all project databases").option(
|
|
@@ -144,10 +144,19 @@ memory.command("rm").description("Remove a project database").option("--project-
|
|
|
144
144
|
"Remove orphaned projects (source dir missing or 0 memories)"
|
|
145
145
|
).action(
|
|
146
146
|
async (opts) => {
|
|
147
|
-
const { memoryRmCommand } = await import("./memory-
|
|
147
|
+
const { memoryRmCommand } = await import("./memory-KU2MOCPQ.js");
|
|
148
148
|
await memoryRmCommand(opts);
|
|
149
149
|
}
|
|
150
150
|
);
|
|
151
|
+
var guide = program.command("guide").description("Manage custom skill guides");
|
|
152
|
+
guide.command("create").description("Create a custom guide for a skill").argument("<skill-name>", "skill to create guide for (e.g. cf-commit)").action(async (skillName) => {
|
|
153
|
+
const { guideCreateCommand } = await import("./guide-F2FLCDYO.js");
|
|
154
|
+
guideCreateCommand(skillName);
|
|
155
|
+
});
|
|
156
|
+
guide.command("list").description("List existing custom guides").action(async () => {
|
|
157
|
+
const { guideListCommand } = await import("./guide-F2FLCDYO.js");
|
|
158
|
+
guideListCommand();
|
|
159
|
+
});
|
|
151
160
|
var dev = program.command("dev").description("Development mode commands");
|
|
152
161
|
program.addHelpText(
|
|
153
162
|
"after",
|
|
@@ -161,35 +170,35 @@ Dev subcommands:
|
|
|
161
170
|
dev update [path] Update local dev plugin to latest version`
|
|
162
171
|
);
|
|
163
172
|
dev.command("on").description("Switch to local plugin source").argument("[path]", "path to local coding-friend repo (default: cwd)").action(async (path) => {
|
|
164
|
-
const { devOnCommand } = await import("./dev-
|
|
173
|
+
const { devOnCommand } = await import("./dev-4OAJCQRQ.js");
|
|
165
174
|
await devOnCommand(path);
|
|
166
175
|
});
|
|
167
176
|
dev.command("off").description("Switch back to remote marketplace").action(async () => {
|
|
168
|
-
const { devOffCommand } = await import("./dev-
|
|
177
|
+
const { devOffCommand } = await import("./dev-4OAJCQRQ.js");
|
|
169
178
|
await devOffCommand();
|
|
170
179
|
});
|
|
171
180
|
dev.command("status").description("Show current dev mode").action(async () => {
|
|
172
|
-
const { devStatusCommand } = await import("./dev-
|
|
181
|
+
const { devStatusCommand } = await import("./dev-4OAJCQRQ.js");
|
|
173
182
|
await devStatusCommand();
|
|
174
183
|
});
|
|
175
184
|
dev.command("sync").description(
|
|
176
185
|
"Copy local source files to plugin cache (no version bump needed)"
|
|
177
186
|
).action(async () => {
|
|
178
|
-
const { devSyncCommand } = await import("./dev-
|
|
187
|
+
const { devSyncCommand } = await import("./dev-4OAJCQRQ.js");
|
|
179
188
|
await devSyncCommand();
|
|
180
189
|
});
|
|
181
190
|
dev.command("restart").description("Reinstall local dev plugin (off + on)").argument(
|
|
182
191
|
"[path]",
|
|
183
192
|
"path to local coding-friend repo (default: saved path or cwd)"
|
|
184
193
|
).action(async (path) => {
|
|
185
|
-
const { devRestartCommand } = await import("./dev-
|
|
194
|
+
const { devRestartCommand } = await import("./dev-4OAJCQRQ.js");
|
|
186
195
|
await devRestartCommand(path);
|
|
187
196
|
});
|
|
188
197
|
dev.command("update").description("Update local dev plugin to latest version (off + on)").argument(
|
|
189
198
|
"[path]",
|
|
190
199
|
"path to local coding-friend repo (default: saved path or cwd)"
|
|
191
200
|
).action(async (path) => {
|
|
192
|
-
const { devUpdateCommand } = await import("./dev-
|
|
201
|
+
const { devUpdateCommand } = await import("./dev-4OAJCQRQ.js");
|
|
193
202
|
await devUpdateCommand(path);
|
|
194
203
|
});
|
|
195
204
|
program.hook("postAction", async () => {
|
|
@@ -2,24 +2,24 @@ import {
|
|
|
2
2
|
ensureMemoryBuilt,
|
|
3
3
|
isMemoryInitialized,
|
|
4
4
|
memoryInitWizard
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-E7OY4UWW.js";
|
|
6
6
|
import {
|
|
7
7
|
memoryConfigMenu
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-XROT7L2F.js";
|
|
9
9
|
import {
|
|
10
10
|
getLibPath
|
|
11
11
|
} from "./chunk-RZRT7NGT.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-J4N2ODQ5.js";
|
|
13
13
|
import {
|
|
14
14
|
findStatuslineHookPath,
|
|
15
15
|
isStatuslineConfigured,
|
|
16
16
|
saveStatuslineConfig,
|
|
17
17
|
selectStatuslineComponents,
|
|
18
18
|
writeStatuslineSettings
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-XQ5KAXKL.js";
|
|
20
20
|
import {
|
|
21
21
|
DEFAULT_CONFIG
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-DHH6SRXV.js";
|
|
23
23
|
import {
|
|
24
24
|
ensureShellCompletion,
|
|
25
25
|
hasShellCompletion
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getLatestVersion,
|
|
3
3
|
semverCompare
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RGQGKOBH.js";
|
|
5
5
|
import {
|
|
6
6
|
getInstalledVersion
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-XQ5KAXKL.js";
|
|
8
|
+
import "./chunk-DHH6SRXV.js";
|
|
9
9
|
import {
|
|
10
10
|
ensureShellCompletion
|
|
11
11
|
} from "./chunk-DMJCO6LJ.js";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ensureMemoryBuilt,
|
|
3
3
|
printMemoryMcpConfig
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-E7OY4UWW.js";
|
|
5
|
+
import "./chunk-XROT7L2F.js";
|
|
6
6
|
import {
|
|
7
7
|
getLibPath
|
|
8
8
|
} from "./chunk-RZRT7NGT.js";
|
|
9
9
|
import {
|
|
10
10
|
resolveDocsDir,
|
|
11
11
|
resolveMemoryDir
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-J4N2ODQ5.js";
|
|
13
|
+
import "./chunk-DHH6SRXV.js";
|
|
14
14
|
import "./chunk-HPNRQYLM.js";
|
|
15
15
|
import {
|
|
16
16
|
run
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
memoryStatusCommand,
|
|
14
14
|
memoryStopDaemonCommand,
|
|
15
15
|
printMemoryMcpConfig
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-E7OY4UWW.js";
|
|
17
|
+
import "./chunk-XROT7L2F.js";
|
|
18
18
|
import "./chunk-RZRT7NGT.js";
|
|
19
|
-
import "./chunk-
|
|
20
|
-
import "./chunk-
|
|
19
|
+
import "./chunk-J4N2ODQ5.js";
|
|
20
|
+
import "./chunk-DHH6SRXV.js";
|
|
21
21
|
import "./chunk-HPNRQYLM.js";
|
|
22
22
|
import "./chunk-EVGXUDX4.js";
|
|
23
23
|
import "./chunk-TWKNGPBO.js";
|
|
@@ -3,17 +3,17 @@ import {
|
|
|
3
3
|
} from "./chunk-RZRT7NGT.js";
|
|
4
4
|
import {
|
|
5
5
|
resolveMemoryDir
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-J4N2ODQ5.js";
|
|
7
7
|
import {
|
|
8
8
|
getCliVersion,
|
|
9
9
|
getLatestCliVersion,
|
|
10
10
|
getLatestVersion,
|
|
11
11
|
semverCompare
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-RGQGKOBH.js";
|
|
13
13
|
import {
|
|
14
14
|
getInstalledVersion
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-XQ5KAXKL.js";
|
|
16
|
+
import "./chunk-DHH6SRXV.js";
|
|
17
17
|
import "./chunk-DMJCO6LJ.js";
|
|
18
18
|
import {
|
|
19
19
|
detectPluginScope,
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
saveStatuslineConfig,
|
|
5
5
|
selectStatuslineComponents,
|
|
6
6
|
writeStatuslineSettings
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-XQ5KAXKL.js";
|
|
8
8
|
import {
|
|
9
9
|
ALL_COMPONENT_IDS
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-DHH6SRXV.js";
|
|
11
11
|
import {
|
|
12
12
|
commandExists
|
|
13
13
|
} from "./chunk-EVGXUDX4.js";
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
getLatestVersion,
|
|
5
5
|
semverCompare,
|
|
6
6
|
updateCommand
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-RGQGKOBH.js";
|
|
8
|
+
import "./chunk-XQ5KAXKL.js";
|
|
9
|
+
import "./chunk-DHH6SRXV.js";
|
|
10
10
|
import "./chunk-DMJCO6LJ.js";
|
|
11
11
|
import "./chunk-HPNRQYLM.js";
|
|
12
12
|
import "./chunk-EVGXUDX4.js";
|
package/lib/cf-memory/README.md
CHANGED
|
@@ -226,12 +226,12 @@ npm run test:watch # Watch mode
|
|
|
226
226
|
node dist/daemon/entry.js ./docs/memory
|
|
227
227
|
|
|
228
228
|
# With idle timeout (ms) and tier
|
|
229
|
-
node dist/daemon/entry.js ./docs/memory
|
|
229
|
+
node dist/daemon/entry.js ./docs/memory 0 --tier=lite
|
|
230
230
|
```
|
|
231
231
|
|
|
232
232
|
The daemon runs a Hono HTTP server on a Unix Domain Socket at `~/.coding-friend/memory/daemon.sock`, with PID tracking at `~/.coding-friend/memory/daemon.pid`.
|
|
233
233
|
|
|
234
|
-
**Auto-reconnect:** If the daemon dies (e.g.,
|
|
234
|
+
**Auto-reconnect with retry:** If the daemon dies (e.g., crash or explicit stop), the `DaemonClient` automatically respawns it on the next request with up to 3 retry attempts (1-second delay between retries). If all retries fail, it falls back to Tier 3 (markdown grep). This means mid-session daemon restarts are transparent — no manual intervention needed.
|
|
235
235
|
|
|
236
236
|
### Lazy dependencies (Tier 1)
|
|
237
237
|
|
|
@@ -306,7 +306,7 @@ If these are missing, `cf memory init` will fail at the "Installing SQLite depen
|
|
|
306
306
|
| ----------------------------- | ------------------------ | ------------------------------------------------- |
|
|
307
307
|
| `MEMORY_DOCS_DIR` | `./docs/memory` | Path to memory storage directory |
|
|
308
308
|
| `MEMORY_TIER` | `auto` | Force a tier: `auto`, `full`, `lite`, `markdown` |
|
|
309
|
-
| `MEMORY_DAEMON_IDLE_TIMEOUT` | `
|
|
309
|
+
| `MEMORY_DAEMON_IDLE_TIMEOUT` | `0` (no timeout) | Daemon idle timeout in ms (`0` = never auto-stop) |
|
|
310
310
|
| `MEMORY_EMBEDDING_PROVIDER` | `transformers` | Embedding provider: `transformers` or `ollama` |
|
|
311
311
|
| `MEMORY_EMBEDDING_MODEL` | (provider default) | Embedding model name (e.g., `nomic-embed-text`) |
|
|
312
312
|
| `MEMORY_EMBEDDING_OLLAMA_URL` | `http://localhost:11434` | Ollama server URL |
|
|
@@ -289,6 +289,65 @@ describe("createBackendForTier() with embeddingConfig", () => {
|
|
|
289
289
|
});
|
|
290
290
|
});
|
|
291
291
|
|
|
292
|
+
describe("makeRespawn retry logic", () => {
|
|
293
|
+
it("retries up to 3 times before giving up", async () => {
|
|
294
|
+
const daemonProcess = await import("../daemon/process.js");
|
|
295
|
+
|
|
296
|
+
let attempts = 0;
|
|
297
|
+
const spawnSpy = vi
|
|
298
|
+
.spyOn(daemonProcess, "spawnDaemon")
|
|
299
|
+
.mockImplementation(async () => {
|
|
300
|
+
attempts++;
|
|
301
|
+
return null; // always fail
|
|
302
|
+
});
|
|
303
|
+
// Isolate from real daemon state on the host machine
|
|
304
|
+
const runningSpy = vi
|
|
305
|
+
.spyOn(daemonProcess, "isDaemonRunning")
|
|
306
|
+
.mockResolvedValue(false);
|
|
307
|
+
|
|
308
|
+
// Use createBackendForTier with "lite" to trigger respawn path
|
|
309
|
+
// The respawn callback wraps makeRespawn which calls spawnDaemon
|
|
310
|
+
// We need to get the respawn function indirectly
|
|
311
|
+
// Instead, test via the exported createRespawnWithRetry
|
|
312
|
+
const { createRespawnWithRetry } = await import("../lib/tier.js");
|
|
313
|
+
const respawn = createRespawnWithRetry(".", undefined, undefined);
|
|
314
|
+
const result = await respawn();
|
|
315
|
+
|
|
316
|
+
expect(result).toBe(false);
|
|
317
|
+
expect(attempts).toBe(3);
|
|
318
|
+
|
|
319
|
+
spawnSpy.mockRestore();
|
|
320
|
+
runningSpy.mockRestore();
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("succeeds on second attempt", async () => {
|
|
324
|
+
const daemonProcess = await import("../daemon/process.js");
|
|
325
|
+
|
|
326
|
+
let attempts = 0;
|
|
327
|
+
const spawnSpy = vi
|
|
328
|
+
.spyOn(daemonProcess, "spawnDaemon")
|
|
329
|
+
.mockImplementation(async () => {
|
|
330
|
+
attempts++;
|
|
331
|
+
if (attempts === 2) return { pid: 1234 };
|
|
332
|
+
return null;
|
|
333
|
+
});
|
|
334
|
+
// Isolate from real daemon state on the host machine
|
|
335
|
+
const runningSpy = vi
|
|
336
|
+
.spyOn(daemonProcess, "isDaemonRunning")
|
|
337
|
+
.mockResolvedValue(false);
|
|
338
|
+
|
|
339
|
+
const { createRespawnWithRetry } = await import("../lib/tier.js");
|
|
340
|
+
const respawn = createRespawnWithRetry(".", undefined, undefined);
|
|
341
|
+
const result = await respawn();
|
|
342
|
+
|
|
343
|
+
expect(result).toBe(true);
|
|
344
|
+
expect(attempts).toBe(2);
|
|
345
|
+
|
|
346
|
+
spawnSpy.mockRestore();
|
|
347
|
+
runningSpy.mockRestore();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
292
351
|
describe("TIERS constant", () => {
|
|
293
352
|
it("has all 3 tier definitions", () => {
|
|
294
353
|
expect(Object.keys(TIERS)).toHaveLength(3);
|
|
@@ -6,7 +6,7 @@ import { getRequestListener } from "@hono/node-server";
|
|
|
6
6
|
import { createDaemonApp } from "./server.js";
|
|
7
7
|
import type { MemoryBackend } from "../lib/backend.js";
|
|
8
8
|
|
|
9
|
-
const DEFAULT_IDLE_TIMEOUT_MS =
|
|
9
|
+
const DEFAULT_IDLE_TIMEOUT_MS = 0; // 0 = no timeout, run until explicitly stopped
|
|
10
10
|
|
|
11
11
|
export interface DaemonPaths {
|
|
12
12
|
socketPath: string;
|
|
@@ -50,17 +50,29 @@ export async function detectTier(configTier?: TierConfig): Promise<TierInfo> {
|
|
|
50
50
|
return TIERS.markdown;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const RESPAWN_MAX_RETRIES = 3;
|
|
54
|
+
const RESPAWN_RETRY_DELAY_MS = 1000;
|
|
55
|
+
|
|
56
|
+
/** Build a respawn callback with retry logic (up to 3 attempts). */
|
|
57
|
+
export function createRespawnWithRetry(
|
|
55
58
|
docsDir: string,
|
|
56
59
|
embeddingConfig?: Partial<EmbeddingConfig>,
|
|
57
60
|
idleTimeoutMs?: number,
|
|
58
61
|
): () => Promise<boolean> {
|
|
59
62
|
return async () => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
for (let attempt = 1; attempt <= RESPAWN_MAX_RETRIES; attempt++) {
|
|
64
|
+
// spawnDaemon returns null both when "already running" and "truly failed"
|
|
65
|
+
// Check isDaemonRunning after null to distinguish the two cases
|
|
66
|
+
const result = await spawnDaemon(docsDir, embeddingConfig, {
|
|
67
|
+
idleTimeoutMs,
|
|
68
|
+
});
|
|
69
|
+
if (result !== null) return true;
|
|
70
|
+
if (await isDaemonRunning()) return true;
|
|
71
|
+
if (attempt < RESPAWN_MAX_RETRIES) {
|
|
72
|
+
await new Promise((r) => setTimeout(r, RESPAWN_RETRY_DELAY_MS));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
64
76
|
};
|
|
65
77
|
}
|
|
66
78
|
|
|
@@ -75,7 +87,7 @@ export async function createBackendForTier(
|
|
|
75
87
|
daemonOptions?: { idleTimeoutMs?: number },
|
|
76
88
|
): Promise<{ backend: MemoryBackend; tier: TierInfo }> {
|
|
77
89
|
const tier = await detectTier(configTier);
|
|
78
|
-
const respawn =
|
|
90
|
+
const respawn = createRespawnWithRetry(
|
|
79
91
|
docsDir,
|
|
80
92
|
embeddingConfig,
|
|
81
93
|
daemonOptions?.idleTimeoutMs,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coding-friend-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.28.0",
|
|
4
4
|
"description": "CLI for coding-friend — host learning docs, setup MCP server, initialize projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"dev": "tsx src/index.ts",
|
|
14
14
|
"watch": "tsup src/index.ts src/postinstall.ts --format esm --dts --watch",
|
|
15
|
-
"test": "vitest run",
|
|
16
|
-
"test:watch": "vitest"
|
|
15
|
+
"test": "vitest run && vitest run --config vitest.hooks.config.ts",
|
|
16
|
+
"test:watch": "vitest",
|
|
17
|
+
"test:hooks": "vitest run --config vitest.hooks.config.ts",
|
|
18
|
+
"test:e2e": "vitest run --config vitest.e2e.config.ts"
|
|
17
19
|
},
|
|
18
20
|
"files": [
|
|
19
21
|
"dist",
|
|
@@ -43,7 +45,8 @@
|
|
|
43
45
|
"dependencies": {
|
|
44
46
|
"@inquirer/prompts": "^7.0.0",
|
|
45
47
|
"chalk": "^5.0.0",
|
|
46
|
-
"commander": "^13.0.0"
|
|
48
|
+
"commander": "^13.0.0",
|
|
49
|
+
"zod": "^4.3.6"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
52
|
"@types/node": "^22.0.0",
|
package/dist/chunk-2HQVNQB7.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_CONFIG
|
|
3
|
-
} from "./chunk-PRIH34UB.js";
|
|
4
|
-
import {
|
|
5
|
-
globalConfigPath,
|
|
6
|
-
localConfigPath,
|
|
7
|
-
resolvePath
|
|
8
|
-
} from "./chunk-TWKNGPBO.js";
|
|
9
|
-
import {
|
|
10
|
-
readJson
|
|
11
|
-
} from "./chunk-5UVDWG5L.js";
|
|
12
|
-
|
|
13
|
-
// src/lib/config.ts
|
|
14
|
-
function deepMerge(base, override) {
|
|
15
|
-
const result = { ...base };
|
|
16
|
-
for (const key of Object.keys(override)) {
|
|
17
|
-
const baseVal = result[key];
|
|
18
|
-
const overVal = override[key];
|
|
19
|
-
if (baseVal && overVal && typeof baseVal === "object" && typeof overVal === "object" && !Array.isArray(baseVal) && !Array.isArray(overVal)) {
|
|
20
|
-
result[key] = deepMerge(
|
|
21
|
-
baseVal,
|
|
22
|
-
overVal
|
|
23
|
-
);
|
|
24
|
-
} else {
|
|
25
|
-
result[key] = overVal;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
function loadConfig() {
|
|
31
|
-
const global = readJson(globalConfigPath());
|
|
32
|
-
const local = readJson(localConfigPath());
|
|
33
|
-
const base = deepMerge(
|
|
34
|
-
DEFAULT_CONFIG,
|
|
35
|
-
global ?? {}
|
|
36
|
-
);
|
|
37
|
-
return deepMerge(
|
|
38
|
-
base,
|
|
39
|
-
local ?? {}
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
function resolveDocsDir(explicitPath) {
|
|
43
|
-
if (explicitPath) {
|
|
44
|
-
return resolvePath(explicitPath);
|
|
45
|
-
}
|
|
46
|
-
const local = readJson(localConfigPath());
|
|
47
|
-
if (local?.learn?.outputDir) {
|
|
48
|
-
return resolvePath(local.learn.outputDir);
|
|
49
|
-
}
|
|
50
|
-
const global = readJson(globalConfigPath());
|
|
51
|
-
if (global?.learn?.outputDir) {
|
|
52
|
-
return resolvePath(global.learn.outputDir);
|
|
53
|
-
}
|
|
54
|
-
return resolvePath("docs/learn");
|
|
55
|
-
}
|
|
56
|
-
function resolveMemoryDir(explicitPath) {
|
|
57
|
-
if (explicitPath) {
|
|
58
|
-
return resolvePath(explicitPath);
|
|
59
|
-
}
|
|
60
|
-
const config = loadConfig();
|
|
61
|
-
if (config.docsDir) {
|
|
62
|
-
return resolvePath(`${config.docsDir}/memory`);
|
|
63
|
-
}
|
|
64
|
-
return resolvePath("docs/memory");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export {
|
|
68
|
-
loadConfig,
|
|
69
|
-
resolveDocsDir,
|
|
70
|
-
resolveMemoryDir
|
|
71
|
-
};
|