coding-friend-cli 1.27.2 → 1.29.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.
Files changed (29) hide show
  1. package/README.md +9 -3
  2. package/dist/{chunk-JVYZ72EP.js → chunk-ADCFJSCP.js} +18 -3
  3. package/dist/{chunk-PRIH34UB.js → chunk-DHH6SRXV.js} +5 -1
  4. package/dist/{chunk-75IEE2OE.js → chunk-E7OY4UWW.js} +2 -2
  5. package/dist/chunk-J4N2ODQ5.js +191 -0
  6. package/dist/{chunk-YCWRBOB3.js → chunk-RGQGKOBH.js} +1 -1
  7. package/dist/{chunk-GDZTU2Z4.js → chunk-XQ5KAXKL.js} +1 -1
  8. package/dist/{chunk-BX3DRKTU.js → chunk-XROT7L2F.js} +6 -5
  9. package/dist/{config-N55LTJ76.js → config-GRJ5WKFR.js} +7 -7
  10. package/dist/{dev-BSXR55PZ.js → dev-4OAJCQRQ.js} +29 -5
  11. package/dist/guide-LQ2BHU5Y.js +117 -0
  12. package/dist/{host-JVLWYY5A.js → host-2KBOPER6.js} +2 -2
  13. package/dist/index.js +36 -27
  14. package/dist/{init-FM5D5CD2.js → init-4GHLRTOK.js} +7 -7
  15. package/dist/{install-G4XYNVL3.js → install-XZC6UO54.js} +3 -3
  16. package/dist/{mcp-DABSO5PE.js → mcp-CNZLJ57B.js} +4 -4
  17. package/dist/{memory-7Q5P7LIU.js → memory-KU2MOCPQ.js} +4 -4
  18. package/dist/{permission-K54DWLHN.js → permission-HU36DY4C.js} +1 -1
  19. package/dist/{permissions-O24R7WUU.js → permissions-DDLSTTPS.js} +1 -1
  20. package/dist/{session-VXYTI2C6.js → session-ZGNQKV4M.js} +2 -2
  21. package/dist/{status-K7TBUAXT.js → status-7WFW4JI2.js} +5 -5
  22. package/dist/{statusline-CDGADB3C.js → statusline-RMTO4MQA.js} +2 -2
  23. package/dist/{update-6M3YFHS6.js → update-HS6A2C5V.js} +3 -3
  24. package/lib/cf-memory/README.md +3 -3
  25. package/lib/cf-memory/src/__tests__/tier.test.ts +59 -0
  26. package/lib/cf-memory/src/daemon/process.ts +1 -1
  27. package/lib/cf-memory/src/lib/tier.ts +19 -7
  28. package/package.json +7 -4
  29. 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/) and live in `src/lib/__tests__/`.
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
- Current coverage: `lib/json.ts`, `lib/paths.ts`, `lib/exec.ts`.
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
 
@@ -203,9 +203,23 @@ var STATIC_RULES = [
203
203
  category: "Testing & Build",
204
204
  recommended: true
205
205
  },
206
+ // Narrow npx rules only — the broad "Bash(npx *)" used to live here but
207
+ // grants execution of any package from any registry, which conflicts with
208
+ // the auto-approve hook's threat model (see plugin/hooks/auto-approve.cjs).
209
+ // tsc and prettier are safe because they typecheck/format and do not
210
+ // execute arbitrary code from input files. Tools that execute arbitrary
211
+ // code (eslint plugins, jest test files, vitest, tsx) are intentionally
212
+ // NOT in the static recommended list — users who want them must add them
213
+ // explicitly with awareness of the risk.
214
+ {
215
+ rule: "Bash(npx tsc *)",
216
+ description: "[execute] Run TypeScript compiler \xB7 Used by: cf-verification",
217
+ category: "Testing & Build",
218
+ recommended: true
219
+ },
206
220
  {
207
- rule: "Bash(npx *)",
208
- description: "[execute] Run npx commands (eslint, tsc) \xB7 Used by: cf-verification",
221
+ rule: "Bash(npx prettier *)",
222
+ description: "[execute] Run Prettier formatter \xB7 Used by: cf-verification",
209
223
  category: "Testing & Build",
210
224
  recommended: true
211
225
  },
@@ -305,7 +319,8 @@ var DANGEROUS_RULE_PATTERNS = [
305
319
  reason: "Grants execution of any npm script"
306
320
  },
307
321
  {
308
- pattern: /^Bash\(npx\*?\)$/,
322
+ // Matches Bash(npx), Bash(npx*), and Bash(npx *) — any bare npx wildcard
323
+ pattern: /^Bash\(npx\s*\*?\)$/,
309
324
  reason: "Grants execution of any npx package"
310
325
  },
311
326
  {
@@ -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 & org (from ~/.claude.json)"
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-BX3DRKTU.js";
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-2HQVNQB7.js";
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
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ensureStatusline,
3
3
  getInstalledVersion
4
- } from "./chunk-GDZTU2Z4.js";
4
+ } from "./chunk-XQ5KAXKL.js";
5
5
  import {
6
6
  ensureShellCompletion
7
7
  } from "./chunk-DMJCO6LJ.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ALL_COMPONENT_IDS,
3
3
  STATUSLINE_COMPONENTS
4
- } from "./chunk-PRIH34UB.js";
4
+ } from "./chunk-DHH6SRXV.js";
5
5
  import {
6
6
  claudeSettingsPath,
7
7
  globalConfigPath,
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-RZRT7NGT.js";
4
4
  import {
5
5
  resolveMemoryDir
6
- } from "./chunk-2HQVNQB7.js";
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 ?? 30),
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 < 1) return "Must be a positive number";
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-BX3DRKTU.js";
3
+ } from "./chunk-XROT7L2F.js";
4
4
  import "./chunk-RZRT7NGT.js";
5
- import "./chunk-2HQVNQB7.js";
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-GDZTU2Z4.js";
12
+ } from "./chunk-XQ5KAXKL.js";
13
13
  import {
14
14
  ALL_COMPONENT_IDS,
15
15
  DEFAULT_CONFIG
16
- } from "./chunk-PRIH34UB.js";
16
+ } from "./chunk-DHH6SRXV.js";
17
17
  import {
18
18
  ensureShellCompletion,
19
19
  hasShellCompletion,
@@ -47,7 +47,7 @@ import {
47
47
  import {
48
48
  getAllRules,
49
49
  getExistingRules
50
- } from "./chunk-JVYZ72EP.js";
50
+ } from "./chunk-ADCFJSCP.js";
51
51
  import {
52
52
  mergeJson,
53
53
  readJson
@@ -393,7 +393,7 @@ async function editAutoApprove(globalCfg, localCfg) {
393
393
  if (scope === "back") return;
394
394
  writeToScope(scope, { autoApprove: value });
395
395
  if (value) {
396
- const { runDangerousRulesAudit } = await import("./permissions-O24R7WUU.js");
396
+ const { runDangerousRulesAudit } = await import("./permissions-DDLSTTPS.js");
397
397
  await runDangerousRulesAudit(
398
398
  [
399
399
  claudeProjectSettingsPath(),
@@ -570,7 +570,7 @@ async function editPermissions() {
570
570
  )
571
571
  });
572
572
  if (choice === BACK) return;
573
- const { permissionCommand } = await import("./permission-K54DWLHN.js");
573
+ const { permissionCommand } = await import("./permission-HU36DY4C.js");
574
574
  switch (choice) {
575
575
  case "interactive":
576
576
  await permissionCommand({});
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  ensureStatusline
3
- } from "./chunk-GDZTU2Z4.js";
4
- import "./chunk-PRIH34UB.js";
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
- log.success(
261
- `Synced ${chalk.green(fileCount.n)} files. Restart Claude Code to apply changes.`
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,117 @@
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 chalk from "chalk";
14
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from "fs";
15
+ import { join, resolve } from "path";
16
+ var GUIDE_TEMPLATE = `# Custom Guide for {{SKILL_NAME}}
17
+
18
+ <!-- Sections are optional \u2014 include only the ones you need. -->
19
+ <!-- This file is loaded automatically when the skill runs. -->
20
+
21
+ ## Before
22
+
23
+ <!-- Steps to execute BEFORE the skill's first step. -->
24
+ <!-- Example: run a linter, check prerequisites, set up context. -->
25
+
26
+ ## Rules
27
+
28
+ <!-- Additional rules to apply THROUGHOUT all steps of the skill. -->
29
+ <!-- Example: "always use TypeScript strict mode", "never modify tests in src/__tests__". -->
30
+
31
+ ## After
32
+
33
+ <!-- Steps to execute AFTER the skill's final step. -->
34
+ <!-- Example: run a formatter, update a changelog, notify a channel. -->
35
+ `;
36
+ function findPluginSkillsDir() {
37
+ const devState = readJson(devStatePath());
38
+ if (devState?.localPath) {
39
+ const dir = join(devState.localPath, "plugin", "skills");
40
+ if (existsSync(dir)) return dir;
41
+ }
42
+ const cachePath = pluginCachePath();
43
+ if (existsSync(cachePath)) {
44
+ try {
45
+ 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 }));
46
+ for (const ver of versions) {
47
+ const dir = join(cachePath, ver, "plugin", "skills");
48
+ if (existsSync(dir)) return dir;
49
+ }
50
+ } catch {
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+ function skillExists(skillsDir, skillName) {
56
+ return existsSync(join(skillsDir, skillName, "SKILL.md"));
57
+ }
58
+ function guideCreateCommand(skillName) {
59
+ if (!/^[a-z0-9-]+$/.test(skillName)) {
60
+ log.error(
61
+ `Invalid skill name "${skillName}". Use lowercase letters, numbers, and hyphens only.`
62
+ );
63
+ return;
64
+ }
65
+ const skillsDir = findPluginSkillsDir();
66
+ if (!skillsDir || !skillExists(skillsDir, skillName)) {
67
+ log.error(
68
+ `Skill "${skillName}" not found. Run "cf guide list" to see available skills.`
69
+ );
70
+ return;
71
+ }
72
+ const guideDir = resolve(".coding-friend", "skills", `${skillName}-custom`);
73
+ const guidePath = join(guideDir, "SKILL.md");
74
+ if (existsSync(guidePath)) {
75
+ log.warn(`Custom guide already exists: ${guidePath}`);
76
+ return;
77
+ }
78
+ mkdirSync(guideDir, { recursive: true });
79
+ writeFileSync(
80
+ guidePath,
81
+ GUIDE_TEMPLATE.replace(/\{\{SKILL_NAME\}\}/g, skillName)
82
+ );
83
+ log.success(`Created custom guide: ${guidePath}`);
84
+ log.dim("Edit the file to add your Before/Rules/After sections.");
85
+ }
86
+ function guideListCommand() {
87
+ const customDir = resolve(".coding-friend", "skills");
88
+ if (!existsSync(customDir)) {
89
+ log.dim(
90
+ "No custom guides found. Run `cf guide create <skill-name>` to create one."
91
+ );
92
+ return;
93
+ }
94
+ const entries = readdirSync(customDir, { withFileTypes: true }).filter(
95
+ (e) => e.isDirectory() && e.name.endsWith("-custom") && existsSync(join(customDir, e.name, "SKILL.md"))
96
+ ).map((e) => e.name.replace(/-custom$/, ""));
97
+ if (entries.length === 0) {
98
+ log.dim(
99
+ "No custom guides found. Run `cf guide create <skill-name>` to create one."
100
+ );
101
+ return;
102
+ }
103
+ const skillsDir = findPluginSkillsDir();
104
+ log.info(`Custom guides (${chalk.bold(entries.length)}):`);
105
+ for (const name of entries) {
106
+ const path = join(customDir, `${name}-custom`, "SKILL.md");
107
+ const found = skillsDir != null && skillExists(skillsDir, name);
108
+ const status = found ? chalk.green("\u2714") : chalk.yellow("\u26A0 skill not found");
109
+ log.info(
110
+ ` ${status} ${chalk.cyan(name)} ${chalk.dim("\u2192")} ${chalk.dim(path)}`
111
+ );
112
+ }
113
+ }
114
+ export {
115
+ guideCreateCommand,
116
+ guideListCommand
117
+ };
@@ -3,8 +3,8 @@ import {
3
3
  } from "./chunk-RZRT7NGT.js";
4
4
  import {
5
5
  resolveDocsDir
6
- } from "./chunk-2HQVNQB7.js";
7
- import "./chunk-PRIH34UB.js";
6
+ } from "./chunk-J4N2ODQ5.js";
7
+ import "./chunk-DHH6SRXV.js";
8
8
  import {
9
9
  run,
10
10
  streamExec
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-G4XYNVL3.js");
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,38 +30,38 @@ 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-FM5D5CD2.js");
33
+ const { initCommand } = await import("./init-4GHLRTOK.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-N55LTJ76.js");
37
+ const { configCommand } = await import("./config-GRJ5WKFR.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-JVLWYY5A.js");
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-DABSO5PE.js");
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(
49
49
  "--project",
50
50
  "Save to project-level settings (.claude/settings.local.json)"
51
51
  ).action(async (opts) => {
52
- const { permissionCommand } = await import("./permission-K54DWLHN.js");
52
+ const { permissionCommand } = await import("./permission-HU36DY4C.js");
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-CDGADB3C.js");
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-6M3YFHS6.js");
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-K7TBUAXT.js");
64
+ const { statusCommand } = await import("./status-7WFW4JI2.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-VXYTI2C6.js");
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-VXYTI2C6.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-7Q5P7LIU.js");
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-LQ2BHU5Y.js");
154
+ guideCreateCommand(skillName);
155
+ });
156
+ guide.command("list").description("List existing custom guides").action(async () => {
157
+ const { guideListCommand } = await import("./guide-LQ2BHU5Y.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-BSXR55PZ.js");
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-BSXR55PZ.js");
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-BSXR55PZ.js");
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-BSXR55PZ.js");
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-BSXR55PZ.js");
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-BSXR55PZ.js");
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-75IEE2OE.js";
5
+ } from "./chunk-E7OY4UWW.js";
6
6
  import {
7
7
  memoryConfigMenu
8
- } from "./chunk-BX3DRKTU.js";
8
+ } from "./chunk-XROT7L2F.js";
9
9
  import {
10
10
  getLibPath
11
11
  } from "./chunk-RZRT7NGT.js";
12
- import "./chunk-2HQVNQB7.js";
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-GDZTU2Z4.js";
19
+ } from "./chunk-XQ5KAXKL.js";
20
20
  import {
21
21
  DEFAULT_CONFIG
22
- } from "./chunk-PRIH34UB.js";
22
+ } from "./chunk-DHH6SRXV.js";
23
23
  import {
24
24
  ensureShellCompletion,
25
25
  hasShellCompletion
@@ -59,7 +59,7 @@ import {
59
59
  getExistingRules,
60
60
  getMissingRules,
61
61
  logPluginScriptWarning
62
- } from "./chunk-JVYZ72EP.js";
62
+ } from "./chunk-ADCFJSCP.js";
63
63
  import {
64
64
  mergeJson,
65
65
  readJson,
@@ -827,7 +827,7 @@ async function initMenu(gitAvailable) {
827
827
  log.success(`Saved to ${targetPath}`);
828
828
  }
829
829
  if (autoApproveChoice) {
830
- const { runDangerousRulesAudit } = await import("./permissions-O24R7WUU.js");
830
+ const { runDangerousRulesAudit } = await import("./permissions-DDLSTTPS.js");
831
831
  await runDangerousRulesAudit(
832
832
  [
833
833
  claudeProjectSettingsPath(),
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getLatestVersion,
3
3
  semverCompare
4
- } from "./chunk-YCWRBOB3.js";
4
+ } from "./chunk-RGQGKOBH.js";
5
5
  import {
6
6
  getInstalledVersion
7
- } from "./chunk-GDZTU2Z4.js";
8
- import "./chunk-PRIH34UB.js";
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-75IEE2OE.js";
5
- import "./chunk-BX3DRKTU.js";
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-2HQVNQB7.js";
13
- import "./chunk-PRIH34UB.js";
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-75IEE2OE.js";
17
- import "./chunk-BX3DRKTU.js";
16
+ } from "./chunk-E7OY4UWW.js";
17
+ import "./chunk-XROT7L2F.js";
18
18
  import "./chunk-RZRT7NGT.js";
19
- import "./chunk-2HQVNQB7.js";
20
- import "./chunk-PRIH34UB.js";
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";
@@ -26,7 +26,7 @@ import {
26
26
  groupByCategory,
27
27
  logPluginScriptWarning,
28
28
  runDangerousRulesAudit
29
- } from "./chunk-JVYZ72EP.js";
29
+ } from "./chunk-ADCFJSCP.js";
30
30
  import {
31
31
  mergeJson,
32
32
  readJson
@@ -15,7 +15,7 @@ import {
15
15
  logPluginScriptWarning,
16
16
  runDangerousRulesAudit,
17
17
  stripDangerousRules
18
- } from "./chunk-JVYZ72EP.js";
18
+ } from "./chunk-ADCFJSCP.js";
19
19
  import "./chunk-5UVDWG5L.js";
20
20
  export {
21
21
  DANGEROUS_RULE_PATTERNS,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  loadConfig
3
- } from "./chunk-2HQVNQB7.js";
4
- import "./chunk-PRIH34UB.js";
3
+ } from "./chunk-J4N2ODQ5.js";
4
+ import "./chunk-DHH6SRXV.js";
5
5
  import {
6
6
  claudeSessionDir,
7
7
  encodeProjectPath,
@@ -3,17 +3,17 @@ import {
3
3
  } from "./chunk-RZRT7NGT.js";
4
4
  import {
5
5
  resolveMemoryDir
6
- } from "./chunk-2HQVNQB7.js";
6
+ } from "./chunk-J4N2ODQ5.js";
7
7
  import {
8
8
  getCliVersion,
9
9
  getLatestCliVersion,
10
10
  getLatestVersion,
11
11
  semverCompare
12
- } from "./chunk-YCWRBOB3.js";
12
+ } from "./chunk-RGQGKOBH.js";
13
13
  import {
14
14
  getInstalledVersion
15
- } from "./chunk-GDZTU2Z4.js";
16
- import "./chunk-PRIH34UB.js";
15
+ } from "./chunk-XQ5KAXKL.js";
16
+ import "./chunk-DHH6SRXV.js";
17
17
  import "./chunk-DMJCO6LJ.js";
18
18
  import {
19
19
  detectPluginScope,
@@ -30,7 +30,7 @@ import {
30
30
  import "./chunk-NREZK463.js";
31
31
  import {
32
32
  getExistingRules
33
- } from "./chunk-JVYZ72EP.js";
33
+ } from "./chunk-ADCFJSCP.js";
34
34
  import {
35
35
  readJson
36
36
  } from "./chunk-5UVDWG5L.js";
@@ -4,10 +4,10 @@ import {
4
4
  saveStatuslineConfig,
5
5
  selectStatuslineComponents,
6
6
  writeStatuslineSettings
7
- } from "./chunk-GDZTU2Z4.js";
7
+ } from "./chunk-XQ5KAXKL.js";
8
8
  import {
9
9
  ALL_COMPONENT_IDS
10
- } from "./chunk-PRIH34UB.js";
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-YCWRBOB3.js";
8
- import "./chunk-GDZTU2Z4.js";
9
- import "./chunk-PRIH34UB.js";
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";
@@ -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 1800000 --tier=lite
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., idle timeout expires), the `DaemonClient` automatically respawns it on the next request. This means mid-session daemon restarts are transparent — no manual intervention needed.
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` | `1800000` (30 min) | Daemon idle timeout in ms (`0` = never auto-stop) |
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 = 30 * 60 * 1000; // 30 minutes
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
- /** Build a respawn callback that DaemonClient can call when the daemon is gone. */
54
- function makeRespawn(
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
- const result = await spawnDaemon(docsDir, embeddingConfig, {
61
- idleTimeoutMs,
62
- });
63
- return result !== null;
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 = makeRespawn(
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.27.2",
3
+ "version": "1.29.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",
@@ -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
- };