codealmanac 0.2.5 → 0.2.6

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 (53) hide show
  1. package/COMMERCIAL.md +9 -0
  2. package/LICENSE +133 -21
  3. package/README.md +11 -11
  4. package/dist/{agents-RVTQYE6A.js → agents-HYRWRHRX.js} +4 -4
  5. package/dist/{chunk-TT6ZP4GS.js → chunk-2BNDNGUR.js} +8 -4
  6. package/dist/{chunk-TT6ZP4GS.js.map → chunk-2BNDNGUR.js.map} +1 -1
  7. package/dist/{chunk-P5WGG4FJ.js → chunk-3E7JNMTZ.js} +28 -3
  8. package/dist/chunk-3E7JNMTZ.js.map +1 -0
  9. package/dist/{chunk-SMIK2YLU.js → chunk-DW32TL5W.js} +117 -83
  10. package/dist/chunk-DW32TL5W.js.map +1 -0
  11. package/dist/{chunk-6BJUYZ43.js → chunk-GPFVEF6V.js} +28 -18
  12. package/dist/chunk-GPFVEF6V.js.map +1 -0
  13. package/dist/{chunk-TILAKDN6.js → chunk-HJ3WREGP.js} +2 -2
  14. package/dist/{chunk-BGUID5BS.js → chunk-J7DNV2DH.js} +219 -26
  15. package/dist/chunk-J7DNV2DH.js.map +1 -0
  16. package/dist/{chunk-DL5BXZCX.js → chunk-K2JBCB7R.js} +40 -54
  17. package/dist/chunk-K2JBCB7R.js.map +1 -0
  18. package/dist/{chunk-MRRX4UQB.js → chunk-ODJAAJGZ.js} +2 -2
  19. package/dist/{chunk-447U3GQJ.js → chunk-PDFS5VFE.js} +17 -5
  20. package/dist/chunk-PDFS5VFE.js.map +1 -0
  21. package/dist/{chunk-GFUB57IT.js → chunk-VXDPUOQ5.js} +384 -207
  22. package/dist/chunk-VXDPUOQ5.js.map +1 -0
  23. package/dist/{cli-CL4ID7EO.js → cli-MKXCNEMW.js} +14 -14
  24. package/dist/codealmanac.js +1 -1
  25. package/dist/{config-ML2RCR7J.js → config-F7FKEQ7F.js} +3 -3
  26. package/dist/doctor-37UH3HT5.js +17 -0
  27. package/dist/{hook-2NP3UE7U.js → hook-4SVX446M.js} +4 -2
  28. package/dist/{register-commands-FBJ6XQ3L.js → register-commands-2F6SXLDI.js} +30 -21
  29. package/dist/register-commands-2F6SXLDI.js.map +1 -0
  30. package/dist/uninstall-C62ZOK32.js +17 -0
  31. package/dist/{update-P2IPG7RO.js → update-2UGOFN5C.js} +3 -3
  32. package/guides/mini.md +3 -3
  33. package/guides/reference.md +7 -7
  34. package/package.json +4 -3
  35. package/dist/chunk-447U3GQJ.js.map +0 -1
  36. package/dist/chunk-6BJUYZ43.js.map +0 -1
  37. package/dist/chunk-BGUID5BS.js.map +0 -1
  38. package/dist/chunk-DL5BXZCX.js.map +0 -1
  39. package/dist/chunk-GFUB57IT.js.map +0 -1
  40. package/dist/chunk-P5WGG4FJ.js.map +0 -1
  41. package/dist/chunk-SMIK2YLU.js.map +0 -1
  42. package/dist/doctor-DOLJRGS4.js +0 -17
  43. package/dist/register-commands-FBJ6XQ3L.js.map +0 -1
  44. package/dist/uninstall-DX6LFKMX.js +0 -15
  45. /package/dist/{agents-RVTQYE6A.js.map → agents-HYRWRHRX.js.map} +0 -0
  46. /package/dist/{chunk-TILAKDN6.js.map → chunk-HJ3WREGP.js.map} +0 -0
  47. /package/dist/{chunk-MRRX4UQB.js.map → chunk-ODJAAJGZ.js.map} +0 -0
  48. /package/dist/{cli-CL4ID7EO.js.map → cli-MKXCNEMW.js.map} +0 -0
  49. /package/dist/{config-ML2RCR7J.js.map → config-F7FKEQ7F.js.map} +0 -0
  50. /package/dist/{doctor-DOLJRGS4.js.map → doctor-37UH3HT5.js.map} +0 -0
  51. /package/dist/{hook-2NP3UE7U.js.map → hook-4SVX446M.js.map} +0 -0
  52. /package/dist/{uninstall-DX6LFKMX.js.map → uninstall-C62ZOK32.js.map} +0 -0
  53. /package/dist/{update-P2IPG7RO.js.map → update-2UGOFN5C.js.map} +0 -0
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ removeImportLine,
4
+ removeManagedBlock,
5
+ runUninstall
6
+ } from "./chunk-K2JBCB7R.js";
7
+ import "./chunk-VXDPUOQ5.js";
8
+ import "./chunk-PDFS5VFE.js";
9
+ import "./chunk-J7DNV2DH.js";
10
+ import "./chunk-3E7JNMTZ.js";
11
+ import "./chunk-7JUX4ADQ.js";
12
+ export {
13
+ removeImportLine,
14
+ removeManagedBlock,
15
+ runUninstall
16
+ };
17
+ //# sourceMappingURL=uninstall-C62ZOK32.js.map
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  runUpdate
4
- } from "./chunk-MRRX4UQB.js";
4
+ } from "./chunk-ODJAAJGZ.js";
5
5
  import "./chunk-F53U6JQG.js";
6
- import "./chunk-P5WGG4FJ.js";
6
+ import "./chunk-3E7JNMTZ.js";
7
7
  import "./chunk-7JUX4ADQ.js";
8
8
  export {
9
9
  runUpdate
10
10
  };
11
- //# sourceMappingURL=update-P2IPG7RO.js.map
11
+ //# sourceMappingURL=update-2UGOFN5C.js.map
package/guides/mini.md CHANGED
@@ -45,7 +45,7 @@ The output is page slugs. Pick 1-3 that look relevant, `almanac show <slug>`, fo
45
45
 
46
46
  ## The commands you'll use
47
47
 
48
- Other commands exist (`list`, `tag`, `untag`, `hook`, `uninstall`, `doctor`, etc.) — most are administrative. See `almanac --help` or the installed `codealmanac-reference.md` for the full surface. In normal sessions you'll live in the four commands below.
48
+ Other commands exist (`list`, `tag`, `untag`, `hook`, `uninstall`, `doctor`, etc.) — most are administrative. See `almanac --help` or `@~/.claude/codealmanac-reference.md` for the full surface. In normal sessions you'll live in the four commands below.
49
49
 
50
50
  ### 1. `almanac search` — the starting point
51
51
 
@@ -193,7 +193,7 @@ The reviewer subagent (run by capture at session end) enforces these. Stricter w
193
193
  ## Troubleshooting
194
194
 
195
195
  ### `almanac doctor` is the catchall
196
- When anything feels off and you don't know where to start, run `almanac doctor`. It reports the install (binary, native SQLite binding, provider readiness, hooks, guides, guide imports/rules) and the current wiki (registered, page/topic counts, index freshness, last capture age, health problems). Every ✗ comes with a one-line `run: …` fix. Add `--json` for scripting.
196
+ When anything feels off and you don't know where to start, run `almanac doctor`. It reports the install (binary, native SQLite binding, Claude auth, hook, guides, CLAUDE.md import) and the current wiki (registered, page/topic counts, index freshness, last capture age, health problems). Every ✗ comes with a one-line `run: …` fix. Add `--json` for scripting.
197
197
 
198
198
  ### "better-sqlite3 bindings failed"
199
199
  Node version or arch mismatch with the prebuilt native binding. `almanac doctor` reports this under `install.sqlite` with the raw error. Fix by rebuilding the native binding:
@@ -245,5 +245,5 @@ install) is the design. See `almanac update --help` for the full flag set.
245
245
  ## When in doubt
246
246
 
247
247
  - `.almanac/README.md` — repo-specific conventions + notability bar
248
- - the installed `codealmanac-reference.md` — full command reference with every flag
248
+ - `@~/.claude/codealmanac-reference.md` — full command reference with every flag
249
249
  - `almanac --help`, `almanac <command> --help` — built-in
@@ -1,6 +1,6 @@
1
1
  # codealmanac — full reference
2
2
 
3
- Long-form manual for the `almanac` / `codealmanac` CLI. The mini guide installed for your selected provider covers *when* to reach for each command; this covers *every flag, every return shape, every edge case*. Read the installed `codealmanac-reference.md` on demand.
3
+ Long-form manual for the `almanac` / `codealmanac` CLI. The mini guide at `~/.claude/codealmanac.md` covers *when* to reach for each command; this covers *every flag, every return shape, every edge case*. Import with `@~/.claude/codealmanac-reference.md` on demand.
4
4
 
5
5
  Groupings match `almanac --help`:
6
6
 
@@ -151,15 +151,15 @@ Flag: `--wiki <name>`.
151
151
 
152
152
  #### `almanac setup` (alias: bare `codealmanac`)
153
153
 
154
- Choose the default provider/model, install auto-capture hooks, and install the provider-specific codealmanac guide. Claude uses `~/.claude/CLAUDE.md`, Codex uses `~/.codex/AGENTS.md`, and Cursor uses `.cursor/rules/codealmanac.mdc`. Idempotent.
154
+ Install the SessionEnd hook + the two CLAUDE.md guides (`codealmanac.md`, `codealmanac-reference.md`) + the `@~/.claude/codealmanac.md` import line. Idempotent.
155
155
 
156
156
  | Flag | Semantics |
157
157
  |---|---|
158
158
  | `-y, --yes` | Skip prompts; install everything. |
159
159
  | `--agent <agent>` | Set the default provider. Accepts `claude`, `codex`, `cursor`, or optional shorthand like `claude/opus`. |
160
160
  | `--model <model>` | Set the provider-local model during setup. Non-interactive equivalent of the model picker. |
161
- | `--skip-hook` | Opt out of auto-capture hooks. |
162
- | `--skip-guides` | Opt out of provider guide install. |
161
+ | `--skip-hook` | Opt out of the SessionEnd hook. |
162
+ | `--skip-guides` | Opt out of the CLAUDE.md guides. |
163
163
 
164
164
  Both `almanac setup` and bare `codealmanac` route here. Interactive setup chooses provider first, then provider-local model. `codealmanac --yes`, `codealmanac --agent codex --model gpt-5.3-codex`, `codealmanac --skip-hook`, and `codealmanac --skip-guides` are the typical first-run invocations. Passing `--skip-hook --skip-guides` together short-circuits with a terse line — nothing was installed, no banner drawn.
165
165
 
@@ -170,8 +170,8 @@ Remove the hook + guides + import line.
170
170
  | Flag | Semantics |
171
171
  |---|---|
172
172
  | `-y, --yes` | Skip confirmations; remove everything. |
173
- | `--keep-hook` | Don't remove auto-capture hooks (guides still prompted unless `--yes`). |
174
- | `--keep-guides` | Don't remove guides or provider imports/rules (hook still prompted unless `--yes`). |
173
+ | `--keep-hook` | Don't remove the SessionEnd hook (guides still prompted unless `--yes`). |
174
+ | `--keep-guides` | Don't remove the guides or CLAUDE.md import (hook still prompted unless `--yes`). |
175
175
 
176
176
  #### `almanac doctor`
177
177
 
@@ -706,7 +706,7 @@ one, usually the webhook, leaving orders silently stuck in pending.
706
706
 
707
707
  ### Catch-all: `almanac doctor`
708
708
 
709
- When something feels off and you don't know where to start, run `almanac doctor`. It reports install state (binary, native binding, provider readiness, hooks, guides, imports/rules) and current-wiki state (registered, page/topic counts, index freshness, last capture age, health problems). Every ✗ comes with a one-line `run: …` fix. `--json` for scripting.
709
+ When something feels off and you don't know where to start, run `almanac doctor`. It reports install state (binary, native binding, Claude auth, hook, guides, import line) and current-wiki state (registered, page/topic counts, index freshness, last capture age, health problems). Every ✗ comes with a one-line `run: …` fix. `--json` for scripting.
710
710
 
711
711
  ### "better-sqlite3 bindings missing"
712
712
  Node version / arch mismatch with the prebuilt binary. `almanac doctor` reports it as `install.sqlite: problem` with the underlying error's first line. Fix:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codealmanac",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "A living wiki for codebases, maintained by AI agents. Documents what the code can't say: decisions, flows, invariants, incidents, gotchas.",
5
5
  "keywords": [
6
6
  "wiki",
@@ -10,7 +10,7 @@
10
10
  "codebase",
11
11
  "knowledge-base"
12
12
  ],
13
- "license": "MIT",
13
+ "license": "PolyForm-Noncommercial-1.0.0",
14
14
  "author": "Rohan Sheth",
15
15
  "repository": {
16
16
  "type": "git",
@@ -32,7 +32,8 @@
32
32
  "hooks",
33
33
  "guides",
34
34
  "README.md",
35
- "LICENSE"
35
+ "LICENSE",
36
+ "COMMERCIAL.md"
36
37
  ],
37
38
  "engines": {
38
39
  "node": "20.x || 22.x || 23.x || 24.x || 25.x"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/hook.ts","../src/commands/hook/script.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, readFile, rename, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport path from \"node:path\";\n\nimport {\n copyToStableHooksDir,\n resolveHookScriptPath,\n resolveSettingsPath,\n type ScriptResolution,\n} from \"./hook/script.js\";\n\n/**\n * `almanac hook install|uninstall|status` — wires the bundled\n * `hooks/almanac-capture.sh` into `~/.claude/settings.json` as a\n * `SessionEnd` hook.\n *\n * Design notes:\n *\n * - **Schema.** Claude Code validates `settings.json` against a strict\n * schema: each entry in an event array (like `SessionEnd`) is a\n * `{matcher, hooks: [...]}` container, and the actual command objects\n * live in the nested `hooks` array. v0.1.0–v0.1.4 wrote command objects\n * directly at the event-array level; newer Claude Code versions now\n * reject that shape. We produce the wrapped form on install, and when\n * encountering a legacy unwrapped entry that we recognize as ours (by\n * `command` ending in `almanac-capture.sh`) we migrate it on next\n * install. `SessionEnd` never uses the `matcher` field to discriminate\n * anything — we always emit an empty `matcher: \"\"` (matches\n * everything, which is what session-end lifecycle hooks want).\n *\n * - **Idempotent.** `install` twice leaves one entry, not two. We match by\n * `command` string equality on the inner `hooks[]` entries. If the user\n * replaces our absolute path with a symlink pointing at the same\n * script, we'll treat it as foreign. That's acceptable; the `status`\n * output shows the path we'd use, so the user can reconcile manually.\n *\n * - **Refuse foreign entries.** If `SessionEnd` is already populated with\n * a command we don't recognize, we print the existing value and exit\n * non-zero. Claude Code lets users wire their own hooks (notifications,\n * git autocommit scripts, etc.) and silently replacing them would be\n * rude. Foreign wrapped containers that don't reference our script are\n * preserved byte-for-byte.\n *\n * - **Atomic write.** `settings.json` is small but heavily touched by\n * Claude Code. Writing via tmp-file + rename avoids corrupting the file\n * if we crash mid-write.\n *\n * - **Non-interactive.** No prompts, no confirmations. The caller is\n * already making an intentional choice by running `almanac hook\n * install`.\n */\n\nexport interface HookCommandOptions {\n /** Which agent app to install hooks for. Default keeps legacy Claude behavior. */\n source?: \"claude\" | \"codex\" | \"cursor\" | \"all\";\n /**\n * Override the hook script path. Production code leaves this undefined\n * and we resolve the bundled `hooks/almanac-capture.sh`. Tests pass a\n * fixture path to avoid depending on the runtime-install layout.\n */\n hookScriptPath?: string;\n /**\n * Override `~/.claude/settings.json`. Tests sandbox this to a tmpdir;\n * production code leaves it undefined.\n */\n settingsPath?: string;\n /**\n * Override the stable hooks directory where we copy the script.\n * Defaults to `~/.claude/hooks/`. Tests sandbox this to a tmpdir.\n *\n * Bug #1 fix: we always copy the bundled script to this stable path\n * before writing it into settings.json. This way the settings entry\n * points at a user-owned location that survives npm version bumps,\n * npx cache evictions, and nvm version switches — instead of an\n * ephemeral path inside ~/.npm/_npx/<sha>/... or the nvm-versioned\n * node_modules/.\n */\n stableHooksDir?: string;\n}\n\nexport interface HookCommandResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\nconst HOOK_TIMEOUT_SECONDS = 10;\n\n/** A single command invocation inside a wrapper's `hooks[]` array. */\ninterface HookCommand {\n type: \"command\";\n command: string;\n timeout?: number;\n}\n\n/** A wrapped SessionEnd entry per Claude Code's schema. */\ninterface WrappedEntry {\n matcher: string;\n hooks: HookCommand[];\n}\n\n/**\n * What we read from `settings.hooks.SessionEnd`. During a read we may\n * encounter the legacy unwrapped shape (`HookCommand` directly) written\n * by v0.1.0–v0.1.4 — we recognize and migrate it. Unknown entries we\n * can't classify are preserved as-is via `unknown`.\n */\ntype RawEntry = WrappedEntry | HookCommand | unknown;\n\n/**\n * Claude Code's `settings.json` is a free-form JSON object; we only care\n * about the `hooks.SessionEnd` array. Preserve everything else verbatim\n * so we don't drop user settings when we write the file back.\n */\ntype SettingsJson = Record<string, unknown> & {\n hooks?: Record<string, RawEntry[] | undefined>;\n};\n\n/**\n * Heuristic: does this command path look like one we installed?\n *\n * We match on the filename `almanac-capture.sh` regardless of the parent\n * directory. This covers:\n * - the stable path: `~/.claude/hooks/almanac-capture.sh`\n * - legacy paths from v0.1.0–v0.1.5: inside the nvm node_modules or\n * npx cache\n * The stable path is what new installs produce; legacy paths are what\n * we migrate when the user runs `almanac hook install` again.\n */\nfunction isOurCommandPath(command: string): boolean {\n return command.endsWith(\"almanac-capture.sh\");\n}\n\n/**\n * Classify a raw SessionEnd entry. Wrapped entries are the canonical\n * shape; unwrapped-command entries are legacy output from v0.1.0–v0.1.4.\n * Anything else (random user JSON) is `unknown` and we leave it alone.\n */\ntype Classified =\n | { kind: \"wrapped\"; entry: WrappedEntry }\n | { kind: \"legacy\"; entry: HookCommand }\n | { kind: \"unknown\"; entry: unknown };\n\nfunction classifyEntry(raw: RawEntry): Classified {\n if (raw === null || typeof raw !== \"object\") {\n return { kind: \"unknown\", entry: raw };\n }\n const obj = raw as Record<string, unknown>;\n if (Array.isArray(obj.hooks)) {\n // Wrapped shape. `matcher` may be absent in hand-edited files; treat\n // absent as \"\" so we don't throw on slightly malformed input.\n const matcher = typeof obj.matcher === \"string\" ? obj.matcher : \"\";\n const hooks: HookCommand[] = [];\n for (const h of obj.hooks as unknown[]) {\n if (h !== null && typeof h === \"object\") {\n const ho = h as Record<string, unknown>;\n if (ho.type === \"command\" && typeof ho.command === \"string\") {\n const cmd: HookCommand = {\n type: \"command\",\n command: ho.command,\n };\n if (typeof ho.timeout === \"number\") cmd.timeout = ho.timeout;\n hooks.push(cmd);\n }\n }\n }\n return { kind: \"wrapped\", entry: { matcher, hooks } };\n }\n if (obj.type === \"command\" && typeof obj.command === \"string\") {\n // Legacy unwrapped shape — v0.1.0–v0.1.4 wrote this form.\n const cmd: HookCommand = {\n type: \"command\",\n command: obj.command as string,\n };\n if (typeof obj.timeout === \"number\") cmd.timeout = obj.timeout;\n return { kind: \"legacy\", entry: cmd };\n }\n return { kind: \"unknown\", entry: raw };\n}\n\n/** True when the entry references our script and is safely ours to manage. */\nfunction isOurWrapped(entry: WrappedEntry): boolean {\n return entry.hooks.some((h) => isOurCommandPath(h.command));\n}\n\nexport async function runHookInstall(\n options: HookCommandOptions = {},\n): Promise<HookCommandResult> {\n const bundled = resolveHookScriptPath(options);\n if (!bundled.ok) {\n return { stdout: \"\", stderr: `almanac: ${bundled.error}\\n`, exitCode: 1 };\n }\n\n // Copy the bundled hook script to a stable user-owned location before\n // writing that path into settings.json. This is the Bug #1 fix:\n //\n // OLD behavior: settings.json pointed at the bundled path (inside\n // ~/.nvm/versions/node/<ver>/lib/node_modules/codealmanac/hooks/... or\n // ~/.npm/_npx/<sha>/node_modules/codealmanac/hooks/...). When the user\n // switches Node versions or the npx cache is evicted, the path breaks\n // silently and captures stop firing.\n //\n // NEW behavior: we copy almanac-capture.sh to ~/.claude/hooks/ (same\n // directory Claude Code uses for its own built-in hooks, always present)\n // and point settings.json there. The stable path is independent of\n // Node version and npm cache state. When the user upgrades codealmanac,\n // `almanac hook install` copies a fresh script and updates settings.json\n // if the path changed.\n //\n // When `hookScriptPath` is explicitly provided (test injection), the\n // caller has already specified the destination path — skip the copy and\n // use that path directly. The stable-copy concern only applies to the\n // production flow where we resolved from the bundled package layout.\n const script: ScriptResolution = options.hookScriptPath !== undefined\n ? bundled // already the caller-provided path, no copy needed\n : await copyToStableHooksDir(bundled.path, options);\n if (!script.ok) {\n return { stdout: \"\", stderr: `almanac: ${script.error}\\n`, exitCode: 1 };\n }\n\n const source = options.source ?? \"claude\";\n if (source === \"all\") {\n const results = [\n await installClaudeHook(options, script.path),\n await installGenericHook({\n label: \"Codex Stop\",\n settingsPath: path.join(homedir(), \".codex\", \"hooks.json\"),\n eventName: \"Stop\",\n shape: \"wrapped\",\n scriptPath: script.path,\n }),\n await installGenericHook({\n label: \"Cursor sessionEnd\",\n settingsPath: path.join(homedir(), \".cursor\", \"hooks.json\"),\n eventName: \"sessionEnd\",\n shape: \"flat\",\n scriptPath: script.path,\n }),\n ];\n const failed = results.find((r) => r.exitCode !== 0);\n if (failed !== undefined) return failed;\n return {\n stdout: results.map((r) => r.stdout.trimEnd()).join(\"\\n\") + \"\\n\",\n stderr: \"\",\n exitCode: 0,\n };\n }\n if (source === \"codex\") {\n return await installGenericHook({\n label: \"Codex Stop\",\n settingsPath: path.join(homedir(), \".codex\", \"hooks.json\"),\n eventName: \"Stop\",\n shape: \"wrapped\",\n scriptPath: script.path,\n });\n }\n if (source === \"cursor\") {\n return await installGenericHook({\n label: \"Cursor sessionEnd\",\n settingsPath: path.join(homedir(), \".cursor\", \"hooks.json\"),\n eventName: \"sessionEnd\",\n shape: \"flat\",\n scriptPath: script.path,\n });\n }\n\n return await installClaudeHook(options, script.path);\n}\n\nasync function installClaudeHook(\n options: HookCommandOptions,\n scriptPath: string,\n): Promise<HookCommandResult> {\n\n const settingsPath = resolveSettingsPath(options);\n const settings = await readSettings(settingsPath);\n const existing = (settings.hooks?.SessionEnd ?? []).slice();\n\n // Walk existing entries and split them into buckets:\n // - `preserved` — foreign wrapped/unknown entries we leave alone.\n // - `oursAlready` — a wrapped entry that already points at OUR exact\n // script path (makes install a no-op).\n // - `oursStale` — a wrapped or legacy entry that references our\n // capture script but at a different absolute path\n // (old install, `npm i` moved us) or in the legacy\n // unwrapped shape. We'll collapse these into a\n // single fresh entry at the new path.\n const preserved: RawEntry[] = [];\n let oursAlready: WrappedEntry | null = null;\n const staleCount = { n: 0 };\n\n for (const raw of existing) {\n const c = classifyEntry(raw);\n if (c.kind === \"wrapped\") {\n if (!isOurWrapped(c.entry)) {\n preserved.push(raw);\n continue;\n }\n // Entry belongs to us. Does it already point at the exact script\n // path? If every command in its `hooks[]` that looks like ours is\n // already at `script.path`, it's up to date.\n const exactMatch = c.entry.hooks.some(\n (h) => h.command === scriptPath,\n );\n if (exactMatch && oursAlready === null) {\n oursAlready = c.entry;\n } else {\n staleCount.n += 1;\n }\n } else if (c.kind === \"legacy\") {\n if (isOurCommandPath(c.entry.command)) {\n // Legacy unwrapped entry of ours — always migrate to wrapped.\n staleCount.n += 1;\n } else {\n // Foreign legacy entry (user had their own script before\n // settings.json required wrapping). Leave it alone.\n preserved.push(raw);\n }\n } else {\n // Unknown shape — we can't classify it. Preserve verbatim.\n preserved.push(raw);\n }\n }\n\n // If every non-ours entry is a foreign unwrapped command (not a\n // wrapped one) we refuse to touch the file — Claude Code's newer\n // schema will already reject such files, but surfacing it here lets\n // the user clean up before we stack our entry on top. Wrapped foreign\n // entries are fine to leave alongside ours.\n const foreignLegacy = preserved.filter((raw) => {\n const c = classifyEntry(raw);\n return c.kind === \"legacy\";\n });\n if (foreignLegacy.length > 0) {\n const lines = foreignLegacy\n .map((raw) => {\n const c = classifyEntry(raw);\n if (c.kind === \"legacy\") return ` - ${c.entry.command}`;\n return \" - <unrecognized>\";\n })\n .join(\"\\n\");\n return {\n stdout: \"\",\n stderr:\n `almanac: SessionEnd has a foreign legacy entry:\\n${lines}\\n` +\n `Remove or rewrap it manually in ${settingsPath} before installing.\\n`,\n exitCode: 1,\n };\n }\n\n if (oursAlready !== null && staleCount.n === 0) {\n return {\n stdout: `almanac: SessionEnd hook already installed at ${scriptPath}\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n }\n\n // Build the fresh wrapped entry and append to preserved foreign\n // entries. Stale entries of ours are dropped (we only ever want a\n // single active entry; multiple copies of the capture hook would\n // double-fire on session end).\n const fresh: WrappedEntry = {\n matcher: \"\",\n hooks: [\n {\n type: \"command\",\n command: scriptPath,\n timeout: HOOK_TIMEOUT_SECONDS,\n },\n ],\n };\n\n const newEntries: RawEntry[] = [...preserved, fresh];\n\n settings.hooks = { ...(settings.hooks ?? {}), SessionEnd: newEntries };\n await writeSettings(settingsPath, settings);\n\n return {\n stdout:\n `almanac: SessionEnd hook installed\\n` +\n ` script: ${scriptPath}\\n` +\n ` settings: ${settingsPath}\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n}\n\nasync function installGenericHook(args: {\n label: string;\n settingsPath: string;\n eventName: string;\n shape: \"flat\" | \"wrapped\";\n scriptPath: string;\n}): Promise<HookCommandResult> {\n const settings = await readSettings(args.settingsPath);\n const hooksObj =\n settings.hooks !== undefined &&\n settings.hooks !== null &&\n typeof settings.hooks === \"object\"\n ? settings.hooks\n : {};\n const existing = Array.isArray(hooksObj[args.eventName])\n ? (hooksObj[args.eventName] as RawEntry[])\n : [];\n const kept = existing.filter((entry) => !entryHasOurCommand(entry));\n const already = existing.some((entry) =>\n entryHasExactCommand(entry, args.scriptPath),\n );\n if (already && kept.length === existing.length - 1) {\n return {\n stdout: `almanac: ${args.label} hook already installed at ${args.scriptPath}\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n }\n const fresh =\n args.shape === \"wrapped\"\n ? {\n hooks: [\n {\n type: \"command\",\n command: args.scriptPath,\n timeout: HOOK_TIMEOUT_SECONDS,\n },\n ],\n }\n : {\n command: args.scriptPath,\n timeout: HOOK_TIMEOUT_SECONDS,\n };\n hooksObj[args.eventName] = [\n ...kept,\n fresh,\n ];\n settings.hooks = hooksObj;\n await writeSettings(args.settingsPath, settings);\n if (args.label.startsWith(\"Codex \")) {\n await ensureCodexHooksFeature(path.join(homedir(), \".codex\", \"config.toml\"));\n }\n return {\n stdout:\n `almanac: ${args.label} hook installed\\n` +\n ` script: ${args.scriptPath}\\n` +\n ` settings: ${args.settingsPath}\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n}\n\nfunction entryHasOurCommand(entry: unknown): boolean {\n return collectHookCommands(entry).some(isOurCommandPath);\n}\n\nfunction entryHasExactCommand(entry: unknown, command: string): boolean {\n return collectHookCommands(entry).some((candidate) => candidate === command);\n}\n\nfunction collectHookCommands(entry: unknown): string[] {\n if (entry === null || typeof entry !== \"object\") return [];\n const obj = entry as Record<string, unknown>;\n const direct = typeof obj.command === \"string\" ? [obj.command] : [];\n const nested = Array.isArray(obj.hooks)\n ? obj.hooks.flatMap((hook) => collectHookCommands(hook))\n : [];\n return [...direct, ...nested];\n}\n\nasync function ensureCodexHooksFeature(configPath: string): Promise<void> {\n let body = \"\";\n if (existsSync(configPath)) {\n body = await readFile(configPath, \"utf8\");\n }\n if (/^\\s*codex_hooks\\s*=\\s*true\\s*$/m.test(body)) return;\n\n const next = setTomlFeatureFlag(body, \"codex_hooks\", true);\n await mkdir(path.dirname(configPath), { recursive: true });\n const tmp = `${configPath}.almanac-tmp-${process.pid}`;\n await writeFile(tmp, next.endsWith(\"\\n\") ? next : `${next}\\n`, \"utf8\");\n await rename(tmp, configPath);\n}\n\nfunction setTomlFeatureFlag(\n body: string,\n key: string,\n value: boolean,\n): string {\n const desired = `${key} = ${value ? \"true\" : \"false\"}`;\n const lines = body.split(/\\r?\\n/);\n let featuresStart = -1;\n let featuresEnd = lines.length;\n\n for (let i = 0; i < lines.length; i++) {\n if (/^\\s*\\[features\\]\\s*$/.test(lines[i] ?? \"\")) {\n featuresStart = i;\n continue;\n }\n if (featuresStart !== -1 && i > featuresStart && /^\\s*\\[.*\\]\\s*$/.test(lines[i] ?? \"\")) {\n featuresEnd = i;\n break;\n }\n }\n\n if (featuresStart === -1) {\n const prefix = body.trim().length === 0 ? \"\" : `${body.trimEnd()}\\n\\n`;\n return `${prefix}[features]\\n${desired}\\n`;\n }\n\n const keyPattern = new RegExp(`^\\\\s*${escapeRegex(key)}\\\\s*=`);\n for (let i = featuresStart + 1; i < featuresEnd; i++) {\n if (keyPattern.test(lines[i] ?? \"\")) {\n lines[i] = desired;\n return lines.join(\"\\n\");\n }\n }\n\n lines.splice(featuresStart + 1, 0, desired);\n return lines.join(\"\\n\");\n}\n\nfunction escapeRegex(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\nexport async function runHookUninstall(\n options: HookCommandOptions = {},\n): Promise<HookCommandResult> {\n const settingsPath = resolveSettingsPath(options);\n\n if (!existsSync(settingsPath)) {\n return {\n stdout: `almanac: SessionEnd hook not installed (no settings file)\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n }\n\n const settings = await readSettings(settingsPath);\n const existing = (settings.hooks?.SessionEnd ?? []).slice();\n\n const kept: RawEntry[] = [];\n let removed = 0;\n\n for (const raw of existing) {\n const c = classifyEntry(raw);\n if (c.kind === \"wrapped\") {\n // Filter out our command(s) from the inner hooks array. Keep\n // anything else in the array intact — a foreign wrapper that\n // happened to include our script alongside its own commands\n // (unusual, but survivable) loses our entry and keeps theirs.\n const innerKept = c.entry.hooks.filter(\n (h) => !isOurCommandPath(h.command),\n );\n const innerRemoved = c.entry.hooks.length - innerKept.length;\n removed += innerRemoved;\n if (innerKept.length === 0) {\n // Only drop the outer wrapper when it was entirely ours. A\n // foreign wrapper that never contained our script stays verbatim\n // below (handled by `innerRemoved === 0`, which leaves\n // `innerKept.length === c.entry.hooks.length`, hence we fall\n // through to the else-branch).\n if (innerRemoved === 0) kept.push(raw);\n // else: fully owned by us, drop the container.\n } else if (innerRemoved === 0) {\n // Untouched foreign wrapper — preserve the raw object to keep\n // any fields (like matcher) byte-for-byte.\n kept.push(raw);\n } else {\n // Partial: rebuild with just the kept inner entries, preserving\n // the original matcher string.\n kept.push({ matcher: c.entry.matcher, hooks: innerKept });\n }\n } else if (c.kind === \"legacy\") {\n if (isOurCommandPath(c.entry.command)) {\n removed += 1;\n } else {\n kept.push(raw);\n }\n } else {\n kept.push(raw);\n }\n }\n\n if (removed === 0) {\n return {\n stdout: `almanac: SessionEnd hook not installed\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n }\n\n if (settings.hooks !== undefined) {\n if (kept.length === 0) {\n // Empty SessionEnd array confuses some linters; drop the key when\n // nothing's left.\n const { SessionEnd: _dropped, ...rest } = settings.hooks;\n void _dropped;\n settings.hooks = rest;\n } else {\n settings.hooks = { ...settings.hooks, SessionEnd: kept };\n }\n\n // If `hooks` itself is now empty (user had only our SessionEnd entry\n // and no other hook categories), drop the `hooks` key entirely so\n // uninstall leaves the settings file in the same shape it would be\n // in had we never run install. An empty `\"hooks\": {}` is an obvious\n // breadcrumb in commit diffs.\n if (Object.keys(settings.hooks).length === 0) {\n delete settings.hooks;\n }\n }\n\n await writeSettings(settingsPath, settings);\n\n return {\n stdout: `almanac: SessionEnd hook removed\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n}\n\nexport async function runHookStatus(\n options: HookCommandOptions = {},\n): Promise<HookCommandResult> {\n const script = resolveHookScriptPath(options);\n const settingsPath = resolveSettingsPath(options);\n\n if (!existsSync(settingsPath)) {\n return {\n stdout:\n `SessionEnd hook: not installed\\n` +\n `settings: ${settingsPath} (does not exist)\\n` +\n (script.ok ? `script would be: ${script.path}\\n` : \"\"),\n stderr: \"\",\n exitCode: 0,\n };\n }\n\n const settings = await readSettings(settingsPath);\n const existing = settings.hooks?.SessionEnd ?? [];\n\n // Walk the array looking for any entry (wrapped or legacy) that\n // references our capture script. Gathering foreign entries separately\n // lets us show them to the user if nothing of ours was found.\n let ourCommand: string | null = null;\n const foreignSummary: string[] = [];\n for (const raw of existing) {\n const c = classifyEntry(raw);\n if (c.kind === \"wrapped\") {\n for (const h of c.entry.hooks) {\n if (isOurCommandPath(h.command)) {\n ourCommand ??= h.command;\n } else {\n foreignSummary.push(h.command);\n }\n }\n } else if (c.kind === \"legacy\") {\n if (isOurCommandPath(c.entry.command)) {\n ourCommand ??= c.entry.command;\n } else {\n foreignSummary.push(c.entry.command);\n }\n }\n }\n\n if (ourCommand === null) {\n const foreignLines = foreignSummary\n .map((c) => ` - ${c}`)\n .join(\"\\n\");\n return {\n stdout:\n `SessionEnd hook: not installed\\n` +\n `settings: ${settingsPath}\\n` +\n (foreignSummary.length > 0\n ? `(${foreignSummary.length} foreign entr${foreignSummary.length === 1 ? \"y\" : \"ies\"} present:\\n${foreignLines})\\n`\n : \"\") +\n (script.ok ? `script would be: ${script.path}\\n` : \"\"),\n stderr: \"\",\n exitCode: 0,\n };\n }\n\n return {\n stdout:\n `SessionEnd hook: installed\\n` +\n `script: ${ourCommand}\\n` +\n `settings: ${settingsPath}\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n}\n\n// ─── Settings JSON helpers ───────────────────────────────────────────\n\nasync function readSettings(settingsPath: string): Promise<SettingsJson> {\n if (!existsSync(settingsPath)) return {};\n try {\n const raw = await readFile(settingsPath, \"utf8\");\n if (raw.trim().length === 0) return {};\n const parsed = JSON.parse(raw) as unknown;\n if (parsed === null || typeof parsed !== \"object\") return {};\n return parsed as SettingsJson;\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n throw new Error(`failed to read ${settingsPath}: ${msg}`);\n }\n}\n\nasync function writeSettings(\n settingsPath: string,\n settings: SettingsJson,\n): Promise<void> {\n const dir = path.dirname(settingsPath);\n await mkdir(dir, { recursive: true });\n\n // Atomic write: JSON.stringify → tmp file → rename. `rename` within the\n // same filesystem is atomic on POSIX; Claude Code never sees a partial\n // file. Formatted with 2-space indent to match the existing settings.\n const tmp = `${settingsPath}.almanac-tmp-${process.pid}`;\n const body = `${JSON.stringify(settings, null, 2)}\\n`;\n await writeFile(tmp, body, \"utf8\");\n await rename(tmp, settingsPath);\n}\n","import { existsSync } from \"node:fs\";\nimport { copyFile, mkdir, readFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nexport interface HookPathOptions {\n hookScriptPath?: string;\n settingsPath?: string;\n stableHooksDir?: string;\n}\n\nexport type ScriptResolution =\n | { ok: true; path: string }\n | { ok: false; error: string };\n\nexport function resolveSettingsPath(options: HookPathOptions): string {\n if (options.settingsPath !== undefined) return options.settingsPath;\n return path.join(homedir(), \".claude\", \"settings.json\");\n}\n\n/**\n * Copy the bundled hook script to `~/.claude/hooks/almanac-capture.sh`.\n *\n * This stable, user-owned destination survives Node version switches and\n * npm/npx cache evictions. The copy is idempotent: if bytes already match\n * we skip writing so repeated setup runs do not bump mtimes.\n */\nexport async function copyToStableHooksDir(\n bundledPath: string,\n options: HookPathOptions,\n): Promise<ScriptResolution> {\n const stableHooksDir =\n options.stableHooksDir ?? path.join(homedir(), \".claude\", \"hooks\");\n const dest = path.join(stableHooksDir, \"almanac-capture.sh\");\n\n try {\n await mkdir(stableHooksDir, { recursive: true });\n const srcBytes = await readFile(bundledPath);\n let needsCopy = true;\n if (existsSync(dest)) {\n try {\n const destBytes = await readFile(dest);\n if (srcBytes.equals(destBytes)) needsCopy = false;\n } catch {\n // Can't read dest — overwrite.\n }\n }\n if (needsCopy) {\n await copyFile(bundledPath, dest);\n }\n return { ok: true, path: dest };\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n return {\n ok: false,\n error: `could not copy hook script to ${dest}: ${msg}`,\n };\n }\n}\n\n/**\n * Locate the bundled `hooks/almanac-capture.sh`. Mirrors\n * `resolvePromptsDir` from `src/agent/prompts.ts`: two plausible layouts\n * (installed dist vs. source dev), probe each.\n */\nexport function resolveHookScriptPath(\n options: HookPathOptions,\n): ScriptResolution {\n if (options.hookScriptPath !== undefined) {\n return { ok: true, path: options.hookScriptPath };\n }\n\n const here = path.dirname(fileURLToPath(import.meta.url));\n\n const candidates = [\n // Bundled: `.../codealmanac/dist/codealmanac.js` → `../hooks/…`\n path.resolve(here, \"..\", \"hooks\", \"almanac-capture.sh\"),\n // Source after ts-node-style module layout or nested dist helpers.\n path.resolve(here, \"..\", \"..\", \"hooks\", \"almanac-capture.sh\"),\n // Source: `.../codealmanac/src/commands/hook/script.ts` → `../../../hooks/…`\n path.resolve(here, \"..\", \"..\", \"..\", \"hooks\", \"almanac-capture.sh\"),\n // Defensive nested fallback.\n path.resolve(here, \"..\", \"..\", \"..\", \"..\", \"hooks\", \"almanac-capture.sh\"),\n ];\n\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return { ok: true, path: candidate };\n }\n }\n\n return {\n ok: false,\n error:\n `could not locate hooks/almanac-capture.sh. Tried:\\n` +\n candidates.map((c) => ` - ${c}`).join(\"\\n\"),\n };\n}\n"],"mappings":";;;AAAA,SAAS,cAAAA,mBAAkB;AAC3B,SAAS,SAAAC,QAAO,YAAAC,WAAU,QAAQ,iBAAiB;AACnD,SAAS,WAAAC,gBAAe;AACxB,OAAOC,WAAU;;;ACHjB,SAAS,kBAAkB;AAC3B,SAAS,UAAU,OAAO,gBAAgB;AAC1C,SAAS,eAAe;AACxB,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAYvB,SAAS,oBAAoB,SAAkC;AACpE,MAAI,QAAQ,iBAAiB,OAAW,QAAO,QAAQ;AACvD,SAAO,KAAK,KAAK,QAAQ,GAAG,WAAW,eAAe;AACxD;AASA,eAAsB,qBACpB,aACA,SAC2B;AAC3B,QAAM,iBACJ,QAAQ,kBAAkB,KAAK,KAAK,QAAQ,GAAG,WAAW,OAAO;AACnE,QAAM,OAAO,KAAK,KAAK,gBAAgB,oBAAoB;AAE3D,MAAI;AACF,UAAM,MAAM,gBAAgB,EAAE,WAAW,KAAK,CAAC;AAC/C,UAAM,WAAW,MAAM,SAAS,WAAW;AAC3C,QAAI,YAAY;AAChB,QAAI,WAAW,IAAI,GAAG;AACpB,UAAI;AACF,c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e,cACb,cACA,UACe;AACf,QAAM,MAAMH,MAAK,QAAQ,YAAY;AACrC,QAAMI,OAAM,KAAK,EAAE,WAAW,KAAK,CAAC;AAKpC,QAAM,MAAM,GAAG,YAAY,gBAAgB,QAAQ,GAAG;AACtD,QAAM,OAAO,GAAG,KAAK,UAAU,UAAU,MAAM,CAAC,CAAC;AAAA;AACjD,QAAM,UAAU,KAAK,MAAM,MAAM;AACjC,QAAM,OAAO,KAAK,YAAY;AAChC;","names":["existsSync","mkdir","readFile","homedir","path","path","homedir","existsSync","readFile","mkdir"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/agents.ts"],"sourcesContent":["import {\n buildProviderSetupView,\n parseAgentSelection,\n type ProviderReadiness,\n} from \"../agent/provider-view.js\";\nimport {\n isAgentProviderId,\n readConfig,\n writeConfig,\n type AgentProviderId,\n} from \"../update/config.js\";\n\nexport interface AgentsResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\nexport async function runAgentsList(): Promise<AgentsResult> {\n const view = await buildProviderSetupView();\n const active = view.choices.find((choice) => choice.selected);\n const activeModel = active?.effectiveModel ?? \"provider default\";\n const lines = [\n \"codealmanac agents\",\n `current: ${view.defaultProvider} (model: ${activeModel})`,\n \"\",\n ];\n for (const choice of view.choices) {\n const selected = choice.selected ? \"*\" : \" \";\n const recommended = choice.recommended ? \"recommended\" : \"\";\n const model = choice.effectiveModel ?? \"provider default\";\n const detail = choice.account ?? choice.fixCommand ?? choice.detail;\n lines.push(\n [\n selected,\n choice.label.padEnd(6),\n readinessLabel(choice.readiness).padEnd(15),\n recommended.padEnd(11),\n `model: ${model}`.padEnd(31),\n detail,\n ].join(\" \").trimEnd(),\n );\n }\n lines.push(\n \"\",\n \"Change provider: almanac agents use <claude|codex|cursor>\",\n \"Set model: almanac agents model <provider> <model>\",\n \"Reset model: almanac agents model <provider> --default\",\n );\n return { stdout: `${lines.join(\"\\n\")}\\n`, stderr: \"\", exitCode: 0 };\n}\n\nexport async function runAgentsDoctor(): Promise<AgentsResult> {\n const view = await buildProviderSetupView();\n const lines = [\"codealmanac agent doctor\\n\"];\n for (const choice of view.choices) {\n lines.push(`${choice.ready ? \"✓\" : \"✗\"} ${choice.label}`);\n lines.push(` status: ${readinessLabel(choice.readiness)}`);\n lines.push(` model: ${choice.effectiveModel ?? \"provider default\"}`);\n if (choice.account !== null) {\n lines.push(` account: ${choice.account}`);\n } else if (choice.detail.length > 0) {\n lines.push(` detail: ${choice.detail}`);\n }\n if (choice.fixCommand !== null) lines.push(` fix: ${choice.fixCommand}`);\n lines.push(\"\");\n }\n return { stdout: `${lines.join(\"\\n\").trimEnd()}\\n`, stderr: \"\", exitCode: 0 };\n}\n\nexport interface SetDefaultAgentOptions {\n provider: string;\n}\n\nexport async function runSetDefaultAgent(\n opts: SetDefaultAgentOptions,\n): Promise<AgentsResult> {\n return setDefaultAgent(opts);\n}\n\nexport async function runDeprecatedSetDefaultAgent(\n opts: SetDefaultAgentOptions,\n): Promise<AgentsResult> {\n return withDeprecation(\n await setDefaultAgent(opts),\n \"almanac set default-agent <provider>\",\n \"almanac agents use <provider>\",\n );\n}\n\nexport async function runAgentsUse(opts: SetDefaultAgentOptions): Promise<AgentsResult> {\n return setDefaultAgent(opts);\n}\n\nasync function setDefaultAgent(\n opts: SetDefaultAgentOptions,\n): Promise<AgentsResult> {\n const parsed = parseAgentSelection(opts.provider);\n if (parsed.provider === null) {\n return {\n stdout: \"\",\n stderr:\n `almanac: unknown agent '${opts.provider}'. ` +\n \"Expected one of: claude, codex, cursor.\\n\",\n exitCode: 1,\n };\n }\n const provider = parsed.provider;\n const config = await readConfig();\n const next = {\n ...config,\n agent: {\n ...config.agent,\n default: provider,\n models:\n parsed.model === undefined\n ? config.agent.models\n : {\n ...config.agent.models,\n [provider]: parsed.model,\n },\n },\n };\n await writeConfig(next);\n return {\n stdout:\n parsed.model === undefined\n ? `codealmanac: default provider set to ${provider}.\\n`\n : `codealmanac: default provider set to ${provider}; ${provider} model set to ${parsed.model}.\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n}\n\nexport async function runSetAgentModel(opts: {\n provider: string;\n model?: string;\n defaultModel?: boolean;\n}): Promise<AgentsResult> {\n return setProviderModel(opts);\n}\n\nexport async function runDeprecatedSetAgentModel(opts: {\n provider: string;\n model?: string;\n defaultModel?: boolean;\n}): Promise<AgentsResult> {\n return withDeprecation(\n await setProviderModel(opts),\n \"almanac set model <provider> <model>\",\n \"almanac agents model <provider> <model>\",\n );\n}\n\nexport async function runAgentsModel(opts: {\n provider: string;\n model?: string;\n defaultModel?: boolean;\n}): Promise<AgentsResult> {\n return setProviderModel(opts);\n}\n\nasync function setProviderModel(opts: {\n provider: string;\n model?: string;\n defaultModel?: boolean;\n}): Promise<AgentsResult> {\n if (!isAgentProviderId(opts.provider)) {\n return {\n stdout: \"\",\n stderr:\n `almanac: unknown agent '${opts.provider}'. ` +\n \"Expected one of: claude, codex, cursor.\\n\",\n exitCode: 1,\n };\n }\n if (\n opts.defaultModel !== true &&\n (opts.model === undefined || opts.model.length === 0)\n ) {\n return {\n stdout: \"\",\n stderr:\n `almanac: missing model for ${opts.provider}. ` +\n \"Pass a model id or --default.\\n\",\n exitCode: 1,\n };\n }\n const provider = opts.provider as AgentProviderId;\n const config = await readConfig();\n const model = normalizeRequestedModel(opts);\n await writeConfig({\n ...config,\n agent: {\n ...config.agent,\n models: {\n ...config.agent.models,\n [provider]: model,\n },\n },\n });\n return {\n stdout:\n model === null\n ? `codealmanac: ${provider} model reset to provider default.\\n`\n : `codealmanac: ${provider} model set to ${model}.\\n`,\n stderr: \"\",\n exitCode: 0,\n };\n}\n\nfunction normalizeRequestedModel(opts: {\n provider: string;\n model?: string;\n defaultModel?: boolean;\n}): string | null {\n if (opts.defaultModel === true) return null;\n if (opts.model === undefined || opts.model.length === 0) return null;\n if (opts.model === \"default\" || opts.model === \"null\") return null;\n return opts.model;\n}\n\nfunction readinessLabel(readiness: ProviderReadiness): string {\n switch (readiness) {\n case \"ready\":\n return \"ready\";\n case \"missing\":\n return \"missing\";\n case \"not-authenticated\":\n return \"not ready\";\n }\n}\n\nfunction withDeprecation(\n result: AgentsResult,\n oldUsage: string,\n newUsage: string,\n): AgentsResult {\n return {\n ...result,\n stderr:\n `almanac: warning: \\`${oldUsage}\\` is deprecated; use \\`${newUsage}\\`.\\n` +\n result.stderr,\n };\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,eAAsB,gBAAuC;AAC3D,QAAM,OAAO,MAAM,uBAAuB;AAC1C,QAAM,SAAS,KAAK,QAAQ,KAAK,CAAC,WAAW,OAAO,QAAQ;AAC5D,QAAM,cAAc,QAAQ,kBAAkB;AAC9C,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA,YAAY,KAAK,eAAe,YAAY,WAAW;AAAA,IACvD;AAAA,EACF;AACA,aAAW,UAAU,KAAK,SAAS;AACjC,UAAM,WAAW,OAAO,WAAW,MAAM;AACzC,UAAM,cAAc,OAAO,cAAc,gBAAgB;AACzD,UAAM,QAAQ,OAAO,kBAAkB;AACvC,UAAM,SAAS,OAAO,WAAW,OAAO,cAAc,OAAO;AAC7D,UAAM;AAAA,MACJ;AAAA,QACE;AAAA,QACA,OAAO,MAAM,OAAO,CAAC;AAAA,QACrB,eAAe,OAAO,SAAS,EAAE,OAAO,EAAE;AAAA,QAC1C,YAAY,OAAO,EAAE;AAAA,QACrB,UAAU,KAAK,GAAG,OAAO,EAAE;AAAA,QAC3B;AAAA,MACF,EAAE,KAAK,GAAG,EAAE,QAAQ;AAAA,IACtB;AAAA,EACF;AACA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO,EAAE,QAAQ,GAAG,MAAM,KAAK,IAAI,CAAC;AAAA,GAAM,QAAQ,IAAI,UAAU,EAAE;AACpE;AAEA,eAAsB,kBAAyC;AAC7D,QAAM,OAAO,MAAM,uBAAuB;AAC1C,QAAM,QAAQ,CAAC,4BAA4B;AAC3C,aAAW,UAAU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B,gBAAgB,QAAQ,iBAAiB,KAAK;AAAA;AAAA,IACpD,QAAQ;AAAA,IACR,UAAU;AAAA,EACZ;AACF;AAEA,SAAS,wBAAwB,MAIf;AAChB,MAAI,KAAK,iBAAiB,KAAM,QAAO;AACvC,MAAI,KAAK,UAAU,UAAa,KAAK,MAAM,WAAW,EAAG,QAAO;AAChE,MAAI,KAAK,UAAU,aAAa,KAAK,UAAU,OAAQ,QAAO;AAC9D,SAAO,KAAK;AACd;AAEA,SAAS,eAAe,WAAsC;AAC5D,UAAQ,WAAW;AAAA,IACjB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,EACX;AACF;AAEA,SAAS,gBACP,QACA,UACA,UACc;AACd,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QACE,uBAAuB,QAAQ,2BAA2B,QAAQ;AAAA,IAClE,OAAO;AAAA,EACX;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/agent/providers/claude/index.ts","../src/agent/providers/claude/auth.ts","../src/agent/providers/cli-status.ts","../src/agent/providers/jsonl-cli.ts","../src/agent/providers/prompt.ts","../src/agent/providers/codex-cli.ts","../src/agent/providers/cursor-cli.ts","../src/agent/providers/status.ts","../src/agent/providers/index.ts","../src/agent/provider-view.ts"],"sourcesContent":["import { query } from \"@anthropic-ai/claude-agent-sdk\";\n\nimport type {\n AgentProvider,\n AgentProviderMetadata,\n AgentResult,\n ProviderStatus,\n RunAgentOptions,\n SpawnCliFn,\n} from \"../../types.js\";\nimport {\n assertClaudeAuth,\n checkClaudeAuth,\n resolveClaudeExecutable,\n UNAUTHENTICATED_MESSAGE,\n type ClaudeAuthStatus,\n} from \"./auth.js\";\n\nexport const DEFAULT_AGENT_MODEL = \"claude-sonnet-4-6\";\n\nconst metadata: AgentProviderMetadata = {\n id: \"claude\",\n displayName: \"Claude\",\n defaultModel: DEFAULT_AGENT_MODEL,\n executable: \"claude\",\n capabilities: {\n transport: \"sdk\",\n writesFiles: true,\n supportsModelOverride: true,\n supportsStreaming: true,\n supportsSessionId: true,\n supportsUsage: false,\n supportsCost: true,\n supportsProviderReportedTurns: true,\n supportsProgrammaticSubagents: true,\n supportsStrictToolAllowlist: false,\n },\n};\n\nexport const claudeProvider: AgentProvider = {\n metadata,\n checkStatus,\n assertReady,\n run,\n};\n\nasync function run(opts: RunAgentOptions): Promise<AgentResult> {\n const claudeExecutable = resolveClaudeExecutable();\n\n const q = query({\n prompt: opts.prompt,\n options: {\n systemPrompt: opts.systemPrompt,\n allowedTools: opts.allowedTools,\n agents: opts.agents ?? {},\n cwd: opts.cwd,\n model: opts.model ?? metadata.defaultModel ?? undefined,\n maxTurns: opts.maxTurns ?? 100,\n ...(claudeExecutable !== undefined\n ? { pathToClaudeCodeExecutable: claudeExecutable }\n : {}),\n env: {\n ...process.env,\n CODEALMANAC_INTERNAL_SESSION: \"1\",\n },\n includePartialMessages: true,\n },\n });\n\n let cost = 0;\n let turns = 0;\n let result = \"\";\n let sessionId: string | undefined;\n let success = false;\n let errorMsg: string | undefined;\n\n try {\n for await (const msg of q) {\n opts.onMessage?.(msg);\n\n if (\n sessionId === undefined &&\n typeof (msg as { session_id?: unknown }).session_id === \"string\"\n ) {\n sessionId = (msg as { session_id: string }).session_id;\n }\n\n if (msg.type === \"result\") {\n cost = msg.total_cost_usd;\n turns = msg.num_turns;\n if (msg.subtype === \"success\") {\n success = true;\n result = msg.result;\n } else {\n success = false;\n errorMsg =\n (msg.errors?.join(\"; \") ?? \"\") || `agent error: ${msg.subtype}`;\n }\n }\n }\n } catch (err: unknown) {\n errorMsg = err instanceof Error ? err.message : String(err);\n success = false;\n }\n\n return { success, cost, turns, result, sessionId, error: errorMsg };\n}\n\nasync function checkStatus(spawnCli?: SpawnCliFn): Promise<ProviderStatus> {\n let auth: ClaudeAuthStatus = { loggedIn: false };\n try {\n auth = await checkClaudeAuth(spawnCli);\n } catch {\n auth = { loggedIn: false };\n }\n const hasApiKey =\n process.env.ANTHROPIC_API_KEY !== undefined &&\n process.env.ANTHROPIC_API_KEY.length > 0;\n const installed = resolveClaudeExecutable() !== undefined;\n const authenticated = auth.loggedIn || hasApiKey;\n const detail = authenticated\n ? auth.email ?? (hasApiKey ? \"ANTHROPIC_API_KEY set\" : \"logged in\")\n : installed\n ? \"not logged in\"\n : `${metadata.executable} not found on PATH`;\n return { id: metadata.id, installed, authenticated, detail };\n}\n\nasync function assertReady(spawnCli?: SpawnCliFn): Promise<void> {\n await assertClaudeAuth(spawnCli);\n}\n\nexport { assertClaudeAuth, checkClaudeAuth, UNAUTHENTICATED_MESSAGE };\nexport type { ClaudeAuthStatus } from \"./auth.js\";\nexport type { SpawnCliFn, SpawnedProcess } from \"../../types.js\";\n","import { spawn, spawnSync, type ChildProcess } from \"node:child_process\";\nimport { createRequire } from \"node:module\";\nimport { dirname, join } from \"node:path\";\n\nimport type { SpawnCliFn, SpawnedProcess } from \"../../types.js\";\n\n/**\n * Claude auth gate — accepts either an active Claude subscription login\n * OR an `ANTHROPIC_API_KEY` environment variable.\n *\n * Claude Code owns subscription OAuth credentials. Users who are logged in\n * via `claude auth login --claudeai` should be able to run bootstrap/capture\n * without exporting an API key. Conversely, users on pay-per-token API keys\n * shouldn't be required to go through the OAuth flow.\n *\n * Current Claude Agent SDK packages no longer ship the old private\n * `cli.js` entrypoint, so the primary probe is the public Claude Code CLI:\n * `claude auth status --json`. We keep the SDK `cli.js` probe as a legacy\n * fallback for older SDK layouts.\n */\n\nexport interface ClaudeAuthStatus {\n loggedIn: boolean;\n email?: string;\n subscriptionType?: string;\n authMethod?: string;\n}\n\nconst AUTH_TIMEOUT_MS = 10_000;\n\n/**\n * Resolve the installed Claude Code executable from PATH. The Agent SDK can\n * accept this path via `pathToClaudeCodeExecutable`, and the auth probe uses\n * the same binary so CodeAlmanac agrees with `claude auth status`.\n */\nexport function resolveClaudeExecutable(): string | undefined {\n const result = spawnSync(\"sh\", [\"-lc\", \"command -v claude\"], {\n encoding: \"utf8\",\n });\n if (result.status !== 0) return undefined;\n const found = result.stdout.trim().split(\"\\n\")[0]?.trim();\n return found !== undefined && found.length > 0 ? found : undefined;\n}\n\n/**\n * Resolve legacy `cli.js` from older `@anthropic-ai/claude-agent-sdk`\n * installs. SDK 0.2.129+ no longer ships this file; callers must treat\n * failure as expected and fall back to the public `claude` binary.\n */\nfunction resolveCliJsPath(): string {\n const require = createRequire(import.meta.url);\n const entry = require.resolve(\"@anthropic-ai/claude-agent-sdk\");\n return join(dirname(entry), \"cli.js\");\n}\n\n/**\n * Default subprocess spawner for production use — invokes the installed\n * Claude Code CLI.\n */\nexport const defaultSpawnCli: SpawnCliFn = (args: string[]) => {\n const command = resolveClaudeExecutable() ?? \"claude\";\n const child = spawn(command, args, {\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n return child as unknown as SpawnedProcess;\n};\n\nexport const legacySdkSpawnCli: SpawnCliFn = (args: string[]) => {\n const cliPath = resolveCliJsPath();\n const child = spawn(process.execPath, [cliPath, ...args], {\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n return child as unknown as SpawnedProcess;\n};\n\n/**\n * Check whether the user is authenticated via Claude subscription OAuth.\n *\n * Spawns `claude auth status --json`, falling back to the legacy SDK CLI\n * layout when available. On any failure (spawn error, non-JSON stdout,\n * non-zero exit, timeout) we return `{ loggedIn: false }` rather than\n * propagating the error — the caller will fall back to the\n * `ANTHROPIC_API_KEY` path and, if that's also missing, produce a clean\n * two-option error message.\n *\n * The 10s timeout guards against the CLI hanging on a broken network or\n * keychain prompt. In practice `auth status` is a cheap local read.\n */\nexport async function checkClaudeAuth(\n spawnCli: SpawnCliFn = defaultSpawnCli,\n): Promise<ClaudeAuthStatus> {\n if (spawnCli === defaultSpawnCli) {\n const status = await checkClaudeAuthWith(defaultSpawnCli);\n if (status.loggedIn) return status;\n return await checkClaudeAuthWith(legacySdkSpawnCli);\n }\n return await checkClaudeAuthWith(spawnCli);\n}\n\nasync function checkClaudeAuthWith(\n spawnCli: SpawnCliFn,\n): Promise<ClaudeAuthStatus> {\n let child: SpawnedProcess;\n try {\n child = spawnCli([\"auth\", \"status\", \"--json\"]);\n } catch {\n return { loggedIn: false };\n }\n\n return new Promise<ClaudeAuthStatus>((resolve) => {\n let stdout = \"\";\n let stderr = \"\";\n let settled = false;\n\n const settle = (value: ClaudeAuthStatus): void => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n resolve(value);\n };\n\n const timer = setTimeout(() => {\n try {\n child.kill(\"SIGTERM\");\n } catch {\n // Kill can fail if the process already exited; nothing we can do.\n }\n settle({ loggedIn: false });\n }, AUTH_TIMEOUT_MS);\n\n child.stdout.on(\"data\", (data) => {\n stdout += data.toString();\n });\n child.stderr.on(\"data\", (data) => {\n stderr += data.toString();\n });\n\n child.on(\"error\", () => {\n settle({ loggedIn: false });\n });\n\n child.on(\"close\", (code) => {\n // The SDK writes `{\"loggedIn\": false, ...}` to stdout with a zero\n // exit code when the user isn't signed in, so we only reject on\n // non-zero + empty stdout. An empty stdout with zero exit (shouldn't\n // happen in practice) also fails safely to `loggedIn: false`.\n if (code !== 0 && stdout.trim().length === 0) {\n // `stderr` isn't surfaced to the user here — the caller's error\n // message covers both auth paths — but it would be captured by\n // `stderr` if we ever wanted to log it for debugging.\n void stderr;\n settle({ loggedIn: false });\n return;\n }\n try {\n settle(parseClaudeAuthStatus(stdout.trim()));\n } catch {\n settle({ loggedIn: false });\n }\n });\n });\n}\n\nfunction parseClaudeAuthStatus(raw: string): ClaudeAuthStatus {\n const parsed = JSON.parse(raw) as Record<string, unknown>;\n const loggedIn = parsed.loggedIn === true;\n const out: ClaudeAuthStatus = { loggedIn };\n if (typeof parsed.email === \"string\") out.email = parsed.email;\n if (typeof parsed.subscriptionType === \"string\") {\n out.subscriptionType = parsed.subscriptionType;\n }\n if (typeof parsed.authMethod === \"string\") {\n out.authMethod = parsed.authMethod;\n }\n return out;\n}\n\n/**\n * Human-readable error when neither auth path is available. The text is\n * deliberately verbose — users hitting this wall for the first time\n * deserve both options in front of them, not a terse hint.\n */\nexport const UNAUTHENTICATED_MESSAGE =\n \"not authenticated to Claude.\\n\\n\" +\n \"Option 1 — use your Claude subscription (Pro/Max):\\n\" +\n \" claude auth login --claudeai\\n\\n\" +\n \"Option 2 — use a pay-per-token API key:\\n\" +\n \" Get one at https://console.anthropic.com\\n\" +\n \" export ANTHROPIC_API_KEY=sk-ant-...\\n\\n\" +\n \"Verify with: claude auth status\";\n\n/**\n * Assert that at least one auth path is satisfied. Prefers subscription\n * auth (fewer surprises for Claude Pro/Max users) but accepts\n * `ANTHROPIC_API_KEY` as a fallback. On failure throws with\n * `code = \"CLAUDE_AUTH_MISSING\"` so callers can distinguish this from\n * other errors if they ever want to.\n *\n * Returns the resolved auth status so callers that want to display the\n * logged-in email in a preamble can do so without a second subprocess.\n */\nexport async function assertClaudeAuth(\n spawnCli: SpawnCliFn = defaultSpawnCli,\n): Promise<ClaudeAuthStatus> {\n const status = await checkClaudeAuth(spawnCli);\n if (status.loggedIn) {\n return status;\n }\n const apiKey = process.env.ANTHROPIC_API_KEY;\n if (apiKey !== undefined && apiKey.length > 0) {\n // Signal to callers that we're on the API-key path. Not \"loggedIn\"\n // in the OAuth sense, but the SDK will pick up the env var and\n // succeed — so we return a status that tells bootstrap/capture the\n // gate is open.\n return { loggedIn: true, authMethod: \"apiKey\" };\n }\n const err = new Error(UNAUTHENTICATED_MESSAGE);\n (err as { code?: string }).code = \"CLAUDE_AUTH_MISSING\";\n throw err;\n}\n\n// Internal re-export — helps keep the public type surface minimal while\n// still letting tests import the `ChildProcess` shape when needed.\nexport type { ChildProcess };\nexport type { SpawnCliFn, SpawnedProcess };\n","import { spawn, spawnSync, type ChildProcess } from \"node:child_process\";\n\nconst STATUS_TIMEOUT_MS = 3_000;\n\nexport function commandExists(command: string): boolean {\n const result = spawnSync(\"sh\", [\"-lc\", `command -v ${command}`], {\n encoding: \"utf8\",\n });\n return result.status === 0 && result.stdout.trim().length > 0;\n}\n\nexport function runStatusCommand(\n command: string,\n args: string[],\n): Promise<{ ok: boolean; detail: string }> {\n return new Promise((resolve) => {\n let stdout = \"\";\n let stderr = \"\";\n let child: ChildProcess;\n let settled = false;\n const settle = (value: { ok: boolean; detail: string }): void => {\n if (settled) return;\n settled = true;\n clearTimeout(timer);\n resolve(value);\n };\n try {\n child = spawn(command, args, { stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n resolve({ ok: false, detail: msg });\n return;\n }\n const timer = setTimeout(() => {\n try {\n child.kill(\"SIGTERM\");\n setTimeout(() => {\n if (child.exitCode === null && child.signalCode === null) {\n try {\n child.kill(\"SIGKILL\");\n } catch {\n // already exited\n }\n }\n }, 500).unref();\n } catch {\n // already exited\n }\n settle({ ok: false, detail: `${command} status timed out` });\n }, STATUS_TIMEOUT_MS);\n child.stdout?.on(\"data\", (chunk) => {\n stdout += chunk.toString(\"utf8\");\n });\n child.stderr?.on(\"data\", (chunk) => {\n stderr += chunk.toString(\"utf8\");\n });\n child.on(\"error\", (err) => {\n settle({ ok: false, detail: err.message });\n });\n child.on(\"close\", (code) => {\n const text = `${stdout}\\n${stderr}`.trim();\n settle({\n ok: code === 0,\n detail:\n text\n .split(\"\\n\")\n .find((line) => line.trim().length > 0)\n ?.trim() ?? (code === 0 ? \"ready\" : `${command} exited ${code ?? 1}`),\n });\n });\n });\n}\n","import { spawn } from \"node:child_process\";\n\nimport type {\n AgentResult,\n AgentStreamMessage,\n AgentUsage,\n} from \"../types.js\";\n\nexport interface JsonlCliOptions {\n command: string;\n args: string[];\n cwd: string;\n env: NodeJS.ProcessEnv;\n onMessage?: (msg: AgentStreamMessage) => void;\n parseFinal: (msg: Record<string, unknown>) => Partial<AgentResult> | null;\n}\n\nexport function runJsonlCli(opts: JsonlCliOptions): Promise<AgentResult> {\n return new Promise((resolve) => {\n const child = spawn(opts.command, opts.args, {\n cwd: opts.cwd,\n env: opts.env,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n let stdoutBuf = \"\";\n let stderr = \"\";\n let cost = 0;\n let turns = 0;\n let result = \"\";\n let sessionId: string | undefined;\n let usage: AgentUsage | undefined;\n let success = false;\n let finalSeen = false;\n let error: string | undefined;\n\n const observe = (msg: Record<string, unknown>): void => {\n opts.onMessage?.(msg);\n if (\n sessionId === undefined &&\n typeof msg.session_id === \"string\" &&\n msg.session_id.length > 0\n ) {\n sessionId = msg.session_id;\n }\n if (\n sessionId === undefined &&\n typeof msg.thread_id === \"string\" &&\n msg.thread_id.length > 0\n ) {\n sessionId = msg.thread_id;\n }\n const final = opts.parseFinal(msg);\n if (final === null) return;\n finalSeen = true;\n if (final.cost !== undefined) cost = final.cost;\n if (final.turns !== undefined) turns = final.turns;\n if (final.result !== undefined) result = final.result;\n if (final.sessionId !== undefined) sessionId = final.sessionId;\n if (final.usage !== undefined) usage = final.usage;\n if (final.success !== undefined) success = final.success;\n if (final.error !== undefined) error = final.error;\n };\n\n const flushLines = (): void => {\n let idx = stdoutBuf.indexOf(\"\\n\");\n while (idx !== -1) {\n const rawLine = stdoutBuf.slice(0, idx);\n stdoutBuf = stdoutBuf.slice(idx + 1);\n const line = rawLine.trim();\n if (line.length > 0) {\n try {\n observe(JSON.parse(line) as Record<string, unknown>);\n } catch {\n // Ignore non-JSON chatter; stderr is captured for failures.\n }\n }\n idx = stdoutBuf.indexOf(\"\\n\");\n }\n };\n\n child.stdout.on(\"data\", (chunk) => {\n stdoutBuf += chunk.toString(\"utf8\");\n flushLines();\n });\n child.stderr.on(\"data\", (chunk) => {\n stderr += chunk.toString(\"utf8\");\n });\n child.on(\"error\", (err: NodeJS.ErrnoException) => {\n resolve({\n success: false,\n cost,\n turns,\n result,\n sessionId,\n usage,\n error:\n err.code === \"ENOENT\"\n ? `${opts.command} not found on PATH`\n : err.message,\n });\n });\n child.on(\"close\", (code) => {\n flushLines();\n if (stdoutBuf.trim().length > 0) {\n try {\n observe(JSON.parse(stdoutBuf.trim()) as Record<string, unknown>);\n } catch {\n // Ignore trailing non-JSON.\n }\n }\n\n if (code === 0 && finalSeen && success) {\n resolve({ success, cost, turns, result, sessionId, usage });\n return;\n }\n\n const firstStderr = stderr.trim().split(\"\\n\")[0];\n resolve({\n success: false,\n cost,\n turns,\n result,\n sessionId,\n usage,\n error:\n error ??\n (firstStderr !== undefined && firstStderr.length > 0\n ? firstStderr\n : `${opts.command} exited ${code ?? 1}`),\n });\n });\n });\n}\n\nexport function parseUsage(value: unknown): AgentUsage | undefined {\n if (value === null || typeof value !== \"object\") return undefined;\n const obj = value as Record<string, unknown>;\n return {\n inputTokens: numberField(obj, \"input_tokens\") ?? numberField(obj, \"inputTokens\"),\n cachedInputTokens:\n numberField(obj, \"cached_input_tokens\") ??\n numberField(obj, \"cachedInputTokens\") ??\n numberField(obj, \"cacheReadTokens\"),\n outputTokens:\n numberField(obj, \"output_tokens\") ?? numberField(obj, \"outputTokens\"),\n reasoningOutputTokens:\n numberField(obj, \"reasoning_output_tokens\") ??\n numberField(obj, \"reasoningOutputTokens\"),\n };\n}\n\nfunction numberField(\n input: Record<string, unknown>,\n key: string,\n): number | undefined {\n const value = input[key];\n return typeof value === \"number\" ? value : undefined;\n}\n","import type { AgentProviderMetadata, RunAgentOptions } from \"../types.js\";\n\nexport function combinedPrompt(\n opts: RunAgentOptions,\n metadata: AgentProviderMetadata,\n): string {\n const reviewerFallback = buildReviewerFallback(opts, metadata);\n return `${opts.systemPrompt}${reviewerFallback}\\n\\n---\\n\\n${opts.prompt}`;\n}\n\nfunction buildReviewerFallback(\n opts: RunAgentOptions,\n metadata: AgentProviderMetadata,\n): string {\n if (metadata.capabilities.supportsProgrammaticSubagents) return \"\";\n\n const reviewer = opts.agents?.reviewer;\n if (reviewer === undefined) return \"\";\n return (\n \"\\n\\nNon-Claude provider note: this runtime does not receive Claude's \" +\n \"nested Agent tool contract. When the writer prompt asks you to invoke \" +\n \"the reviewer subagent, perform that review pass yourself before final \" +\n \"wiki edits. Treat this reviewer prompt as read-only review guidance:\\n\\n\" +\n reviewer.prompt\n );\n}\n","import type {\n AgentProvider,\n AgentProviderMetadata,\n AgentResult,\n ProviderStatus,\n RunAgentOptions,\n} from \"../types.js\";\nimport { commandExists, runStatusCommand } from \"./cli-status.js\";\nimport { parseUsage, runJsonlCli } from \"./jsonl-cli.js\";\nimport { combinedPrompt } from \"./prompt.js\";\n\nconst metadata: AgentProviderMetadata = {\n id: \"codex\",\n displayName: \"Codex\",\n defaultModel: null,\n executable: \"codex\",\n capabilities: {\n transport: \"cli-jsonl\",\n writesFiles: true,\n supportsModelOverride: true,\n supportsStreaming: true,\n supportsSessionId: false,\n supportsUsage: true,\n supportsCost: false,\n supportsProviderReportedTurns: false,\n supportsProgrammaticSubagents: false,\n supportsStrictToolAllowlist: false,\n },\n};\n\nexport const codexProvider: AgentProvider = {\n metadata,\n checkStatus,\n assertReady,\n run,\n};\n\nasync function run(opts: RunAgentOptions): Promise<AgentResult> {\n const args = [\n \"exec\",\n \"--json\",\n \"--sandbox\",\n \"workspace-write\",\n \"--skip-git-repo-check\",\n \"-C\",\n opts.cwd,\n ];\n if (opts.model !== undefined && opts.model.length > 0) {\n args.push(\"--model\", opts.model);\n }\n args.push(combinedPrompt({ ...opts, provider: \"codex\" }, metadata));\n\n return await runJsonlCli({\n command: metadata.executable,\n args,\n cwd: opts.cwd,\n env: { ...process.env, CODEALMANAC_INTERNAL_SESSION: \"1\" },\n onMessage: opts.onMessage,\n parseFinal: parseCodexFinal,\n });\n}\n\nasync function checkStatus(): Promise<ProviderStatus> {\n if (!commandExists(metadata.executable)) {\n return {\n id: metadata.id,\n installed: false,\n authenticated: false,\n detail: `${metadata.executable} not found on PATH`,\n };\n }\n\n const auth = await runStatusCommand(metadata.executable, [\"login\", \"status\"]);\n return {\n id: metadata.id,\n installed: true,\n authenticated: auth.ok,\n detail: auth.detail,\n };\n}\n\nasync function assertReady(): Promise<void> {\n const status = await checkStatus();\n if (!status.installed || !status.authenticated) {\n const err = new Error(`${status.id} not ready: ${status.detail}`);\n (err as { code?: string }).code = \"AGENT_AUTH_MISSING\";\n throw err;\n }\n}\n\nfunction parseCodexFinal(\n msg: Record<string, unknown>,\n): Partial<AgentResult> | null {\n if (msg.type === \"item.completed\") {\n const item = msg.item;\n if (item !== null && typeof item === \"object\") {\n const obj = item as Record<string, unknown>;\n if (obj.type === \"agent_message\" && typeof obj.text === \"string\") {\n return { result: obj.text };\n }\n }\n return null;\n }\n if (msg.type === \"turn.completed\") {\n return { success: true, turns: 1, usage: parseUsage(msg.usage) };\n }\n if (msg.type === \"turn.failed\" || msg.type === \"error\") {\n return {\n success: false,\n error:\n typeof msg.message === \"string\"\n ? msg.message\n : typeof msg.error === \"string\"\n ? msg.error\n : \"codex turn failed\",\n };\n }\n return null;\n}\n","import type {\n AgentProvider,\n AgentProviderMetadata,\n AgentResult,\n ProviderStatus,\n RunAgentOptions,\n} from \"../types.js\";\nimport { commandExists, runStatusCommand } from \"./cli-status.js\";\nimport { parseUsage, runJsonlCli } from \"./jsonl-cli.js\";\nimport { combinedPrompt } from \"./prompt.js\";\n\nconst metadata: AgentProviderMetadata = {\n id: \"cursor\",\n displayName: \"Cursor\",\n defaultModel: null,\n executable: \"cursor-agent\",\n capabilities: {\n transport: \"cli-jsonl\",\n writesFiles: true,\n supportsModelOverride: true,\n supportsStreaming: true,\n supportsSessionId: true,\n supportsUsage: true,\n supportsCost: false,\n supportsProviderReportedTurns: false,\n supportsProgrammaticSubagents: false,\n supportsStrictToolAllowlist: false,\n },\n};\n\nexport const cursorProvider: AgentProvider = {\n metadata,\n checkStatus,\n assertReady,\n run,\n};\n\nasync function run(opts: RunAgentOptions): Promise<AgentResult> {\n const args = [\n \"--print\",\n \"--output-format\",\n \"stream-json\",\n \"--stream-partial-output\",\n \"--trust\",\n \"--workspace\",\n opts.cwd,\n ];\n if (opts.model !== undefined && opts.model.length > 0) {\n args.push(\"--model\", opts.model);\n }\n args.push(combinedPrompt({ ...opts, provider: \"cursor\" }, metadata));\n\n return await runJsonlCli({\n command: metadata.executable,\n args,\n cwd: opts.cwd,\n env: { ...process.env, CODEALMANAC_INTERNAL_SESSION: \"1\" },\n onMessage: opts.onMessage,\n parseFinal: parseCursorFinal,\n });\n}\n\nasync function checkStatus(): Promise<ProviderStatus> {\n if (!commandExists(metadata.executable)) {\n return {\n id: metadata.id,\n installed: false,\n authenticated: false,\n detail: `${metadata.executable} not found on PATH`,\n };\n }\n\n const auth = await runStatusCommand(metadata.executable, [\"status\"]);\n return {\n id: metadata.id,\n installed: true,\n authenticated: auth.ok,\n detail: auth.detail,\n };\n}\n\nasync function assertReady(): Promise<void> {\n const status = await checkStatus();\n if (!status.installed || !status.authenticated) {\n const err = new Error(`${status.id} not ready: ${status.detail}`);\n (err as { code?: string }).code = \"AGENT_AUTH_MISSING\";\n throw err;\n }\n}\n\nfunction parseCursorFinal(\n msg: Record<string, unknown>,\n): Partial<AgentResult> | null {\n if (msg.type !== \"result\") return null;\n const isError = msg.is_error === true || msg.subtype !== \"success\";\n return {\n success: !isError,\n turns: 1,\n result: typeof msg.result === \"string\" ? msg.result : \"\",\n sessionId:\n typeof msg.session_id === \"string\" ? msg.session_id : undefined,\n usage: parseUsage(msg.usage),\n error: isError\n ? typeof msg.result === \"string\"\n ? msg.result\n : `cursor result: ${String(msg.subtype ?? \"error\")}`\n : undefined,\n };\n}\n","import {\n AGENT_PROVIDER_IDS,\n type AgentProviderId,\n} from \"../../update/config.js\";\nimport type { ProviderStatus, SpawnCliFn } from \"../types.js\";\nimport { getAgentProvider } from \"./index.js\";\n\nexport async function assertAgentAuth(args: {\n provider: AgentProviderId;\n spawnCli?: SpawnCliFn;\n}): Promise<void> {\n await getAgentProvider(args.provider).assertReady(args.spawnCli);\n}\n\nexport async function listProviderStatuses(\n spawnCli?: SpawnCliFn,\n): Promise<ProviderStatus[]> {\n const out: ProviderStatus[] = [];\n for (const id of AGENT_PROVIDER_IDS) {\n out.push(await getAgentProvider(id).checkStatus(spawnCli));\n }\n return out;\n}\n","import type { AgentProvider } from \"../types.js\";\nimport { claudeProvider, DEFAULT_AGENT_MODEL } from \"./claude/index.js\";\nimport { codexProvider } from \"./codex-cli.js\";\nimport { cursorProvider } from \"./cursor-cli.js\";\n\nconst AGENT_PROVIDERS = {\n claude: claudeProvider,\n codex: codexProvider,\n cursor: cursorProvider,\n} satisfies Record<string, AgentProvider>;\n\nexport function getAgentProvider(id: keyof typeof AGENT_PROVIDERS): AgentProvider {\n return AGENT_PROVIDERS[id];\n}\n\nexport const AGENT_PROVIDER_METADATA = {\n claude: claudeProvider.metadata,\n codex: codexProvider.metadata,\n cursor: cursorProvider.metadata,\n};\nexport { DEFAULT_AGENT_MODEL };\nexport { assertAgentAuth, listProviderStatuses } from \"./status.js\";\n","import {\n AGENT_PROVIDER_METADATA,\n listProviderStatuses,\n} from \"./providers.js\";\nimport type { ProviderStatus, SpawnCliFn } from \"./types.js\";\nimport {\n AGENT_PROVIDER_IDS,\n isAgentProviderId,\n readConfig,\n type AgentProviderId,\n type GlobalConfig,\n} from \"../update/config.js\";\n\nexport type ProviderReadiness = \"ready\" | \"not-authenticated\" | \"missing\";\n\nexport interface ProviderSetupChoice {\n id: AgentProviderId;\n label: string;\n selected: boolean;\n recommended: boolean;\n readiness: ProviderReadiness;\n ready: boolean;\n installed: boolean;\n authenticated: boolean;\n effectiveModel: string | null;\n providerDefaultModel: string | null;\n configuredModel: string | null;\n account: string | null;\n detail: string;\n fixCommand: string | null;\n modelChoices: ProviderModelChoice[];\n}\n\nexport interface ProviderModelChoice {\n value: string | null;\n label: string;\n recommended: boolean;\n source: \"configured\" | \"provider-default\" | \"custom\";\n}\n\nexport interface ProviderSetupView {\n defaultProvider: AgentProviderId;\n recommendedProvider: AgentProviderId;\n choices: ProviderSetupChoice[];\n}\n\nexport interface ProviderViewOptions {\n config?: GlobalConfig;\n statuses?: ProviderStatus[];\n spawnCli?: SpawnCliFn;\n}\n\nconst LOGIN_FIXES: Record<AgentProviderId, string> = {\n claude: \"run: claude auth login --claudeai\",\n codex: \"run: codex login\",\n cursor: \"run: cursor-agent login\",\n};\n\nconst INSTALL_FIXES: Record<AgentProviderId, string> = {\n claude: \"install Claude Code, then run: claude auth login --claudeai\",\n codex: \"install Codex CLI, then run: codex login\",\n cursor: \"install cursor-agent, then run: cursor-agent login\",\n};\n\nexport function getProviderLabel(id: AgentProviderId): string {\n return AGENT_PROVIDER_METADATA[id].displayName;\n}\n\nexport function getProviderDefaultModel(id: AgentProviderId): string | null {\n return AGENT_PROVIDER_METADATA[id].defaultModel;\n}\n\nexport async function buildProviderSetupView(\n opts: ProviderViewOptions = {},\n): Promise<ProviderSetupView> {\n const config = opts.config ?? await readConfig();\n const statuses = opts.statuses ?? await listProviderStatuses(opts.spawnCli);\n const statusById = new Map(statuses.map((status) => [status.id, status]));\n const recommendedProvider = chooseRecommendedProvider(statuses);\n const choices = AGENT_PROVIDER_IDS.map((id) => {\n const status = statusById.get(id) ?? missingStatus(id);\n const readiness = getReadiness(status);\n const configuredModel = normalizeModel(config.agent.models[id]);\n const providerDefaultModel = getProviderDefaultModel(id);\n const effectiveModel = configuredModel ?? providerDefaultModel;\n return {\n id,\n label: getProviderLabel(id),\n selected: id === config.agent.default,\n recommended: id === recommendedProvider,\n readiness,\n ready: readiness === \"ready\",\n installed: status.installed,\n authenticated: status.authenticated,\n effectiveModel,\n providerDefaultModel,\n configuredModel,\n account: status.authenticated ? accountFromDetail(status.detail) : null,\n detail: status.detail,\n fixCommand: fixFor(id, readiness),\n modelChoices: buildProviderModelChoices(id, configuredModel),\n };\n });\n return {\n defaultProvider: config.agent.default,\n recommendedProvider,\n choices,\n };\n}\n\nexport function buildProviderModelChoices(\n id: AgentProviderId,\n configuredModel: string | null = null,\n): ProviderModelChoice[] {\n const choices: ProviderModelChoice[] = [];\n if (configuredModel !== null) {\n choices.push({\n value: configuredModel,\n label: configuredModel,\n recommended: false,\n source: \"configured\",\n });\n }\n\n const providerDefault = getProviderDefaultModel(id);\n if (providerDefault !== null) {\n if (!choices.some((choice) => choice.value === providerDefault)) {\n choices.push({\n value: providerDefault,\n label: providerDefault,\n recommended: true,\n source: \"provider-default\",\n });\n } else {\n choices[0] = { ...choices[0]!, recommended: true };\n }\n } else {\n choices.push({\n value: null,\n label: \"provider default\",\n recommended: true,\n source: \"provider-default\",\n });\n }\n\n choices.push({\n value: \"__custom__\",\n label: \"custom model id\",\n recommended: false,\n source: \"custom\",\n });\n return choices;\n}\n\nexport function chooseRecommendedProvider(\n statuses: ProviderStatus[],\n): AgentProviderId {\n const ready = statuses\n .filter((status) => status.installed && status.authenticated)\n .map((status) => status.id);\n if (ready.includes(\"claude\")) return \"claude\";\n for (const id of AGENT_PROVIDER_IDS) {\n if (ready.includes(id)) return id;\n }\n return \"claude\";\n}\n\nexport function parseAgentSelection(value: string): {\n provider: AgentProviderId | null;\n model?: string;\n} {\n const [rawProvider, ...modelParts] = value.split(\"/\");\n if (rawProvider === undefined || !isAgentProviderId(rawProvider)) {\n return { provider: null };\n }\n const model = modelParts.join(\"/\");\n return {\n provider: rawProvider,\n model: model.length > 0 ? model : undefined,\n };\n}\n\nfunction getReadiness(status: ProviderStatus): ProviderReadiness {\n if (!status.installed) return \"missing\";\n if (!status.authenticated) return \"not-authenticated\";\n return \"ready\";\n}\n\nfunction fixFor(\n id: AgentProviderId,\n readiness: ProviderReadiness,\n): string | null {\n if (readiness === \"ready\") return null;\n if (readiness === \"missing\") return INSTALL_FIXES[id];\n return LOGIN_FIXES[id];\n}\n\nfunction accountFromDetail(detail: string): string | null {\n const clean = detail.trim();\n if (\n clean.length === 0 ||\n clean === \"ready\" ||\n clean === \"logged in\" ||\n clean === \"ANTHROPIC_API_KEY set\"\n ) {\n return null;\n }\n return clean;\n}\n\nfunction normalizeModel(value: string | null | undefined): string | null {\n return typeof value === \"string\" && value.length > 0 ? value : null;\n}\n\nfunction missingStatus(id: AgentProviderId): ProviderStatus {\n return {\n id,\n installed: false,\n authenticated: false,\n detail: \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,UAAa,CAAC,kBAAkB,WAAW,GAAG;AAChE,WAAO,EAAE,UAAU,KAAK;AAAA,EAC1B;AACA,QAAM,QAAQ,WAAW,KAAK,GAAG;AACjC,SAAO;AAAA,IACL,UAAU;AAAA,IACV,OAAO,MAAM,SAAS,IAAI,QAAQ;AAAA,EACpC;AACF;AAEA,SAAS,aAAa,QAA2C;AAC/D,MAAI,CAAC,OAAO,UAAW,QAAO;AAC9B,MAAI,CAAC,OAAO,cAAe,QAAO;AAClC,SAAO;AACT;AAEA,SAAS,OACP,IACA,WACe;AACf,MAAI,cAAc,QAAS,QAAO;AAClC,MAAI,cAAc,UAAW,QAAO,cAAc,EAAE;AACpD,SAAO,YAAY,EAAE;AACvB;AAEA,SAAS,kBAAkB,QAA+B;AACxD,QAAM,QAAQ,OAAO,KAAK;AAC1B,MACE,MAAM,WAAW,KACjB,UAAU,WACV,UAAU,eACV,UAAU,yBACV;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,SAAS,eAAe,OAAiD;AACvE,SAAO,OAAO,UAAU,YAAY,MAAM,SAAS,IAAI,QAAQ;AACjE;AAEA,SAAS,cAAc,IAAqC;AAC1D,SAAO;AAAA,IACL;AAAA,IACA,WAAW;AAAA,IACX,eAAe;AAAA,IACf,QAAQ;AAAA,EACV;AACF;","names":["require","spawn","spawnSync","spawn","metadata","metadata","checkStatus","assertReady","run","metadata","checkStatus","assertReady","run"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/uninstall.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { readFile, rm, writeFile } from \"node:fs/promises\";\nimport { homedir } from \"node:os\";\nimport path from \"node:path\";\n\nimport { runHookUninstall } from \"./hook.js\";\nimport { IMPORT_LINE } from \"./setup.js\";\n\n/**\n * `almanac uninstall` — the reverse of `setup`.\n *\n * Idempotent and order-insensitive: each step is a no-op if that\n * artifact was never installed. We remove exactly the things setup added,\n * nothing else:\n *\n * 1. The `@~/.claude/codealmanac.md` line from `~/.claude/CLAUDE.md`.\n * Other content stays untouched. If removing our line leaves the\n * file empty, we delete the file so our fingerprint doesn't persist\n * as zero bytes.\n * 2. The guide files `~/.claude/codealmanac.md` and\n * `~/.claude/codealmanac-reference.md`.\n * 3. The SessionEnd hook entry (delegated to `runHookUninstall`, which\n * already knows how to leave foreign entries alone).\n *\n * Flags:\n * --yes skip confirmations; remove everything\n * --keep-hook leave the hook alone\n * --keep-guides leave guides and provider imports/rules alone\n *\n * Non-interactive (no TTY) → behaves as if `--yes` was passed. Same\n * contract as `setup`.\n */\n\nexport interface UninstallOptions {\n yes?: boolean;\n keepHook?: boolean;\n keepGuides?: boolean;\n\n // ─── Injection points ────────────────────────────────────────────\n settingsPath?: string;\n hookScriptPath?: string;\n claudeDir?: string;\n isTTY?: boolean;\n stdout?: NodeJS.WritableStream;\n}\n\nexport interface UninstallResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\nconst BLUE = \"\\x1b[38;5;75m\";\nconst DIM = \"\\x1b[2m\";\nconst RST = \"\\x1b[0m\";\n\nexport async function runUninstall(\n options: UninstallOptions = {},\n): Promise<UninstallResult> {\n const out = options.stdout ?? process.stdout;\n const isTTY =\n options.isTTY ?? (process.stdin.isTTY === true);\n const interactive = isTTY && options.yes !== true;\n const claudeDir = options.claudeDir ?? path.join(homedir(), \".claude\");\n\n out.write(\"\\n\");\n\n // Hook removal.\n let removeHook = true;\n if (options.keepHook === true) {\n removeHook = false;\n } else if (interactive) {\n removeHook = await confirm(\n out,\n \"Remove the SessionEnd hook from ~/.claude/settings.json?\",\n true,\n );\n }\n if (removeHook) {\n const res = await runHookUninstall({\n settingsPath: options.settingsPath,\n hookScriptPath: options.hookScriptPath,\n });\n if (res.exitCode !== 0) {\n return { stdout: \"\", stderr: res.stderr, exitCode: res.exitCode };\n }\n out.write(` ${BLUE}\\u25c7${RST} ${res.stdout.trim()}\\n`);\n } else {\n out.write(` ${DIM}\\u25cb Hook kept${RST}\\n`);\n }\n\n // Guide + import removal.\n let removeGuides = true;\n if (options.keepGuides === true) {\n removeGuides = false;\n } else if (interactive) {\n removeGuides = await confirm(\n out,\n \"Remove guides and provider imports/rules?\",\n true,\n );\n }\n if (removeGuides) {\n const summary = await removeGuideFiles(claudeDir);\n if (summary.anyChanges) {\n out.write(\n ` ${BLUE}\\u25c7${RST} Guides removed (${summary.filesTouched.join(\", \")})\\n`,\n );\n } else {\n out.write(` ${DIM}\\u25cb Guides not installed${RST}\\n`);\n }\n } else {\n out.write(` ${DIM}\\u25cb Guides kept${RST}\\n`);\n }\n\n out.write(`\\n ${BLUE}\\u25c7${RST} ${BLUE}Uninstall complete${RST}\\n\\n`);\n\n return { stdout: \"\", stderr: \"\", exitCode: 0 };\n}\n\ninterface RemoveGuidesResult {\n anyChanges: boolean;\n filesTouched: string[];\n}\n\nasync function removeGuideFiles(\n claudeDir: string,\n): Promise<RemoveGuidesResult> {\n const touched: string[] = [];\n\n const mini = path.join(claudeDir, \"codealmanac.md\");\n const ref = path.join(claudeDir, \"codealmanac-reference.md\");\n const claudeMd = path.join(claudeDir, \"CLAUDE.md\");\n\n if (existsSync(mini)) {\n await rm(mini, { force: true });\n touched.push(\"codealmanac.md\");\n }\n if (existsSync(ref)) {\n await rm(ref, { force: true });\n touched.push(\"codealmanac-reference.md\");\n }\n\n if (existsSync(claudeMd)) {\n const existing = await readFile(claudeMd, \"utf8\");\n const { changed, body } = removeImportLine(existing);\n if (changed) {\n // If the file is now content-free, delete it outright so our\n // installation leaves no trace. A user who was using CLAUDE.md\n // before we touched it still has their content; only the case\n // where CLAUDE.md contained nothing but our line gets cleaned up.\n if (body.trim().length === 0) {\n await rm(claudeMd, { force: true });\n touched.push(\"CLAUDE.md (deleted)\");\n } else {\n await writeFile(claudeMd, body, \"utf8\");\n touched.push(\"CLAUDE.md\");\n }\n }\n }\n\n touched.push(...await removeCodexGuides());\n touched.push(...await removeCursorGuides(process.cwd()));\n\n return { anyChanges: touched.length > 0, filesTouched: touched };\n}\n\nasync function removeCodexGuides(): Promise<string[]> {\n const touched: string[] = [];\n const codexDir = path.join(homedir(), \".codex\");\n const mini = path.join(codexDir, \"codealmanac.md\");\n const ref = path.join(codexDir, \"codealmanac-reference.md\");\n const agents = path.join(codexDir, \"AGENTS.md\");\n if (existsSync(mini)) {\n await rm(mini, { force: true });\n touched.push(\"~/.codex/codealmanac.md\");\n }\n if (existsSync(ref)) {\n await rm(ref, { force: true });\n touched.push(\"~/.codex/codealmanac-reference.md\");\n }\n if (existsSync(agents)) {\n const existing = await readFile(agents, \"utf8\");\n const body = removeManagedBlock(\n existing,\n \"<!-- codealmanac:start -->\",\n \"<!-- codealmanac:end -->\",\n );\n if (body !== existing) {\n if (body.trim().length === 0) {\n await rm(agents, { force: true });\n touched.push(\"~/.codex/AGENTS.md (deleted)\");\n } else {\n await writeFile(agents, body, \"utf8\");\n touched.push(\"~/.codex/AGENTS.md\");\n }\n }\n }\n return touched;\n}\n\nasync function removeCursorGuides(cwd: string): Promise<string[]> {\n const rule = path.join(cwd, \".cursor\", \"rules\", \"codealmanac.mdc\");\n if (!existsSync(rule)) return [];\n await rm(rule, { force: true });\n return [\".cursor/rules/codealmanac.mdc\"];\n}\n\nfunction removeManagedBlock(\n contents: string,\n start: string,\n end: string,\n): string {\n const pattern = new RegExp(\n `\\\\n?${escapeRegex(start)}[\\\\s\\\\S]*?${escapeRegex(end)}\\\\n?`,\n );\n return contents.replace(pattern, \"\\n\").replace(/\\n\\n\\n+/g, \"\\n\\n\");\n}\n\nfunction escapeRegex(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/**\n * Remove the import line from a CLAUDE.md body. Match is line-anchored\n * (trimmed equality) so we don't munge a line that happens to include\n * the token as part of a longer string. Returns the unchanged body (and\n * `changed: false`) if the line isn't present — this is what makes the\n * command safe to run repeatedly.\n */\nexport function removeImportLine(contents: string): {\n changed: boolean;\n body: string;\n} {\n const eol = contents.includes(\"\\r\\n\") ? \"\\r\\n\" : \"\\n\";\n const lines = contents.split(/\\r?\\n/);\n\n const indices: number[] = [];\n for (let i = 0; i < lines.length; i++) {\n if (lines[i]!.trim() === IMPORT_LINE) indices.push(i);\n }\n if (indices.length === 0) return { changed: false, body: contents };\n\n // Remove the line(s). Iterate from the end so earlier indices stay\n // valid as we splice.\n for (let i = indices.length - 1; i >= 0; i--) {\n lines.splice(indices[i]!, 1);\n }\n\n let body = lines.join(eol);\n\n // Cleanup: collapse any double-blank that our removal created at the\n // spot the line used to live. A best-effort tidy — we don't try to\n // normalize the whole file.\n body = body.replace(/\\n\\n\\n+/g, \"\\n\\n\");\n\n return { changed: true, body };\n}\n\nfunction confirm(\n out: NodeJS.WritableStream,\n question: string,\n defaultYes: boolean,\n): Promise<boolean> {\n return new Promise((resolve) => {\n const hint = defaultYes ? \"[Y/n]\" : \"[y/N]\";\n out.write(` ${BLUE}\\u25c6${RST} ${question} ${DIM}${hint}${RST} `);\n\n let buf = \"\";\n const onData = (chunk: Buffer): void => {\n buf += chunk.toString(\"utf8\");\n const nl = buf.indexOf(\"\\n\");\n if (nl === -1) return;\n process.stdin.removeListener(\"data\", onData);\n process.stdin.pause();\n\n const answer = buf.slice(0, nl).trim().toLowerCase();\n const accepted =\n answer.length === 0\n ? defaultYes\n : answer === \"y\" || answer === \"yes\";\n resolve(accepted);\n };\n\n process.stdin.resume();\n process.stdin.on(\"data\", onData);\n });\n}\n"],"mappings":";;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,UAAU,IAAI,iBAAiB;AACxC,SAAS,eAAe;AACxB,OAAO,UAAU;AAiDjB,IAAM,OAAO;AACb,IAAM,MAAM;AACZ,IAAM,MAAM;AAEZ,eAAsB,aACpB,UAA4B,CAAC,GACH;AAC1B,QAAM,MAAM,QAAQ,UAAU,QAAQ;AACtC,QAAM,QACJ,QAAQ,SAAU,QAAQ,MAAM,UAAU;AAC5C,QAAM,cAAc,SAAS,QAAQ,QAAQ;AAC7C,QAAM,YAAY,QAAQ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install-path.ts","../src/commands/setup/next-steps.ts"],"sourcesContent":["import { existsSync } from \"node:fs\";\nimport { spawn } from \"node:child_process\";\nimport {\n copyFile,\n mkdir,\n readFile,\n writeFile,\n} from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport { homedir } from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { SpawnCliFn } from \"../agent/providers/claude/index.js\";\nimport {\n buildProviderModelChoices,\n buildProviderSetupView,\n getProviderLabel,\n parseAgentSelection,\n} from \"../agent/provider-view.js\";\nimport type {\n ProviderModelChoice,\n ProviderSetupView,\n} from \"../agent/provider-view.js\";\nimport {\n isAgentProviderId,\n readConfig,\n writeConfig,\n type AgentProviderId,\n} from \"../update/config.js\";\nimport { runHookInstall } from \"./hook.js\";\nimport {\n detectCurrentInstallPath,\n detectEphemeral,\n spawnGlobalInstall,\n} from \"./setup/install-path.js\";\nimport {\n countExistingPages,\n printNextSteps,\n} from \"./setup/next-steps.js\";\n\n/**\n * `codealmanac setup` — the MCP-style branded TUI that runs when a user\n * invokes the bare `codealmanac` binary (or `almanac setup` / `codealmanac\n * setup` explicitly).\n *\n * Model: `mcp-ts/src/setup.ts` from openalmanac. Same ASCII banner + badge\n * + step-indicator style, same interactive + `--yes` + non-interactive\n * modes.\n *\n * Three things get installed:\n *\n * 1. The `SessionEnd` hook in `~/.claude/settings.json` (delegated to\n * `runHookInstall` from `./hook.ts`).\n * 2. Provider-specific agent guidance for the chosen default provider.\n * Claude uses `~/.claude/CLAUDE.md`; Codex uses `~/.codex/AGENTS.md`;\n * Cursor uses a project rule in `.cursor/rules/`.\n *\n * Everything is idempotent — running setup again is safe. `--skip-hook`\n * and `--skip-guides` opt out of the individual installs. `--yes` or a\n * non-TTY stdin skips all prompts and installs everything.\n */\n\nexport interface SetupOptions {\n /** Install everything without prompting. */\n yes?: boolean;\n /** Don't install auto-capture hooks. */\n skipHook?: boolean;\n /** Don't install provider-specific guides. */\n skipGuides?: boolean;\n /** Set the default provider during setup. */\n agent?: string;\n /** Set the default model for the selected provider during setup. */\n model?: string;\n\n // ─── Injection points (tests only) ────────────────────────────────\n /** Override the subprocess spawner for `claude auth status`. */\n spawnCli?: SpawnCliFn;\n /** Override `~/.claude/settings.json` path. */\n settingsPath?: string;\n /** Override the bundled hook script path. */\n hookScriptPath?: string;\n /** Override the stable hooks directory for the hook script copy. */\n stableHooksDir?: string;\n /** Override `~/.claude/` dir for guide install. */\n claudeDir?: string;\n /** Override the directory containing `mini.md` / `reference.md`. */\n guidesDir?: string;\n /** Override interactivity; defaults to `process.stdin.isTTY`. */\n isTTY?: boolean;\n /** Stdout sink; defaults to `process.stdout`. */\n stdout?: NodeJS.WritableStream;\n /**\n * Override the install-path probe result. When `null` the probe is\n * bypassed (tests that don't care about the ephemeral-path step).\n * When a string it's treated as the detected install path.\n */\n installPath?: string | null;\n /**\n * Override the npm global install spawner (tests inject a no-op to\n * avoid actually spawning npm during CI).\n */\n spawnGlobalInstall?: () => Promise<void>;\n}\n\nexport interface SetupResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\n// ─── ANSI helpers ────────────────────────────────────────────────────\n\nconst RST = \"\\x1b[0m\";\nconst DIM = \"\\x1b[2m\";\nconst WHITE_BOLD = \"\\x1b[1;37m\";\nconst BLUE = \"\\x1b[38;5;75m\";\nconst ACCENT_BG = \"\\x1b[48;5;252m\\x1b[38;5;16m\";\n\nconst GRADIENT = [\n \"\\x1b[38;5;255m\",\n \"\\x1b[38;5;253m\",\n \"\\x1b[38;5;251m\",\n \"\\x1b[38;5;249m\",\n \"\\x1b[38;5;246m\",\n \"\\x1b[38;5;243m\",\n];\n\n// `codealmanac` 11-letter ASCII banner. Chosen for tasteful rendering —\n// same banner used in the MCP setup wizard design, retooled letters for\n// the word \"codealmanac\". Each glyph is 6 lines tall.\n//\n// If you tweak this, keep it to ≤80 visual columns wide so it fits in\n// narrow terminals (80 cols is the classic default).\nconst LOGO_LINES = [\n \" ___ ___ ___ ___ _ _ __ __ _ _ _ _ ___ \",\n \" / __/ _ \\\\| \\\\| __| /_\\\\ | | | \\\\/ | /_\\\\ | \\\\| | /_\\\\ / __|\",\n \"| (_| (_) | |) | _| / _ \\\\| |__| |\\\\/| |/ _ \\\\| .` |/ _ \\\\ (__ \",\n \" \\\\___\\\\___/|___/|___/_/ \\\\_\\\\____|_| |_/_/ \\\\_\\\\_|\\\\_/_/ \\\\_\\\\___|\",\n \" \",\n \" a living wiki for codebases, for your agent \",\n];\n\nconst BAR = ` ${DIM}\\u2502${RST}`;\n\nfunction printBanner(out: NodeJS.WritableStream): void {\n out.write(\"\\n\");\n for (let i = 0; i < LOGO_LINES.length; i++) {\n const color = GRADIENT[Math.min(i, GRADIENT.length - 1)] ?? \"\";\n out.write(`${color}${LOGO_LINES[i]}${RST}\\n`);\n }\n out.write(`\\n${WHITE_BOLD} Install provider integrations${RST}\\n`);\n}\n\nfunction printBadge(out: NodeJS.WritableStream): void {\n out.write(`\\n ${ACCENT_BG} codealmanac ${RST}\\n\\n`);\n}\n\nfunction stepDone(out: NodeJS.WritableStream, msg: string): void {\n out.write(` ${BLUE}\\u25c7${RST} ${msg}\\n`);\n}\n\nfunction stepActive(out: NodeJS.WritableStream, msg: string): void {\n out.write(` ${BLUE}\\u25c6${RST} ${msg}\\n`);\n}\n\nfunction stepSkipped(out: NodeJS.WritableStream, msg: string): void {\n out.write(` ${DIM}\\u25cb ${msg}${RST}\\n`);\n}\n\n// ─── Entry point ─────────────────────────────────────────────────────\n\nexport async function runSetup(\n options: SetupOptions = {},\n): Promise<SetupResult> {\n const out = options.stdout ?? process.stdout;\n const isTTY =\n options.isTTY ?? (process.stdin.isTTY === true);\n const interactive = isTTY && options.yes !== true;\n\n // No-op fast path. When the caller explicitly skipped every install\n // step, rendering the full banner + step markers + \"Setup complete\"\n // box is actively misleading — nothing was actually set up. Emit a\n // single terse line and exit so the user gets honest feedback and\n // piped callers (CI, scripts) don't parse through nine lines of ANSI\n // to conclude nothing happened.\n if (options.skipHook === true && options.skipGuides === true) {\n out.write(\n \"codealmanac: nothing to install — use --help to see what setup does\\n\",\n );\n return { stdout: \"\", stderr: \"\", exitCode: 0 };\n }\n\n printBanner(out);\n printBadge(out);\n\n const agentChoice = await chooseDefaultAgent({\n out,\n interactive,\n requested: options.agent,\n requestedModel: options.model,\n spawnCli: options.spawnCli,\n });\n if (!agentChoice.ok) {\n return {\n stdout: \"\",\n stderr: `almanac: ${agentChoice.error}\\n`,\n exitCode: 1,\n };\n }\n stepDone(\n out,\n `Default provider: ${WHITE_BOLD}${agentChoice.provider}${RST}` +\n ` (${agentChoice.model ?? \"provider default\"})`,\n );\n out.write(BAR + \"\\n\");\n\n // Step 1b: ephemeral install detection. When codealmanac was invoked via\n // `npx codealmanac` (no prior `npm i -g`), the binary lives inside an\n // npx cache directory or pnpm store that can be evicted at any time.\n // `almanac` is also not on PATH, so the user can't use it after setup.\n //\n // When we detect an ephemeral location, we offer (or, on --yes, perform)\n // a `npm install -g codealmanac` to make the install permanent.\n //\n // This is Bug #2 from codealmanac-known-bugs.md.\n const ephem = options.installPath !== undefined\n ? (options.installPath !== null\n ? detectEphemeral(options.installPath)\n : false)\n : detectEphemeral(detectCurrentInstallPath());\n if (ephem) {\n let globalAction: InstallDecision = \"install\";\n if (interactive) {\n globalAction = await confirm(\n out,\n `Running from an ephemeral npx location. Install globally so 'almanac' stays on PATH?`,\n true,\n );\n }\n if (globalAction === \"install\") {\n stepActive(out, \"Installing codealmanac globally…\");\n try {\n await (options.spawnGlobalInstall ?? spawnGlobalInstall)();\n stepDone(out, \"codealmanac installed globally (almanac now on PATH)\");\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n stepActive(out, `Global install failed: ${msg}`);\n out.write(\n ` ${DIM}You can retry manually: npm install -g codealmanac${RST}\\n`,\n );\n }\n } else {\n stepSkipped(\n out,\n `Global install ${DIM}skipped — almanac will not be on PATH after this session${RST}`,\n );\n }\n out.write(BAR + \"\\n\");\n }\n\n // Step 2: install the hook (default yes).\n let hookAction: InstallDecision = \"install\";\n if (options.skipHook === true) {\n hookAction = \"skip\";\n } else if (interactive) {\n hookAction = await confirm(\n out,\n \"Install auto-capture hooks for supported agents?\",\n true,\n );\n }\n\n let hookResultLine = \"\";\n if (hookAction === \"install\") {\n const res = await runHookInstall({\n source: \"all\",\n settingsPath: options.settingsPath,\n hookScriptPath: options.hookScriptPath,\n stableHooksDir: options.stableHooksDir,\n });\n if (res.exitCode !== 0) {\n stepActive(out, `Auto-capture hook: ${res.stderr.trim()}`);\n return {\n stdout: \"\",\n stderr: res.stderr,\n exitCode: res.exitCode,\n };\n }\n hookResultLine = res.stdout.includes(\"already installed\")\n ? `Auto-capture hooks ${DIM}already installed${RST}`\n : `Auto-capture hooks installed`;\n stepDone(out, hookResultLine);\n } else {\n stepSkipped(out, `Auto-capture hooks ${DIM}skipped${RST}`);\n }\n out.write(BAR + \"\\n\");\n\n // Step 3: install the provider-specific guide.\n let guidesAction: InstallDecision = \"install\";\n const providerLabel = getProviderLabel(agentChoice.provider);\n if (options.skipGuides === true) {\n guidesAction = \"skip\";\n } else if (interactive) {\n guidesAction = await confirm(\n out,\n `Install the codealmanac guide for ${providerLabel}?`,\n true,\n );\n }\n\n let guidesSummary: string;\n if (guidesAction === \"install\") {\n try {\n const summary = await installGuides({\n provider: agentChoice.provider,\n claudeDir: options.claudeDir ?? path.join(homedir(), \".claude\"),\n guidesDir: options.guidesDir ?? resolveGuidesDir(),\n cwd: process.cwd(),\n });\n guidesSummary = summary.anyChanges\n ? `Guide installed for ${summary.providerLabel} (${summary.filesWritten.join(\", \")})`\n : `Guide for ${summary.providerLabel} ${DIM}already installed${RST}`;\n stepDone(out, guidesSummary);\n } catch (err: unknown) {\n const msg = err instanceof Error ? err.message : String(err);\n return {\n stdout: \"\",\n stderr: `almanac: guide install failed: ${msg}\\n`,\n exitCode: 1,\n };\n }\n } else {\n stepSkipped(out, `Guides ${DIM}skipped${RST}`);\n }\n out.write(BAR + \"\\n\");\n\n stepDone(out, `${BLUE}Setup complete${RST}`);\n out.write(\"\\n\");\n\n // Detect whether the current working directory is inside a repo that\n // already has a wiki with pages. This fixes Bug #6 from\n // codealmanac-known-bugs.md: Engineer B clones a repo that already has\n // `.almanac/pages/` (committed by Engineer A) and gets told to run\n // `almanac bootstrap`, which is wrong — the wiki already exists.\n const existingPageCount = countExistingPages(process.cwd());\n printNextSteps(out, existingPageCount);\n printProviderNextSteps(out);\n\n return { stdout: \"\", stderr: \"\", exitCode: 0 };\n}\n\ntype AgentChoice =\n | { ok: true; provider: AgentProviderId; model: string | null }\n | { ok: false; error: string };\n\nasync function chooseDefaultAgent(args: {\n out: NodeJS.WritableStream;\n interactive: boolean;\n requested?: string;\n requestedModel?: string;\n spawnCli?: SpawnCliFn;\n}): Promise<AgentChoice> {\n const config = await readConfig();\n let view: ProviderSetupView | null = null;\n let selected = args.requested ?? config.agent.default;\n if (args.interactive || args.requested !== undefined) {\n view = await buildProviderSetupView({ config, spawnCli: args.spawnCli });\n }\n if (args.interactive && args.requested === undefined && view !== null) {\n args.out.write(\" Choose default provider for bootstrap/capture:\\n\");\n view.choices.forEach((choice, index) => {\n const tag = choice.recommended ? \" recommended\" : \"\";\n const status = choice.ready ? \"ready\" : \"not ready\";\n const detail = choice.account ?? choice.fixCommand ?? choice.detail;\n args.out.write(\n ` ${index + 1}. ${choice.label.padEnd(6)} ${status.padEnd(9)}${tag} ${detail}\\n`,\n );\n });\n selected = (await promptText(\n args.out,\n \"Default provider\",\n view.recommendedProvider,\n )).toLowerCase();\n const number = Number.parseInt(selected, 10);\n if (\n Number.isInteger(number) &&\n number >= 1 &&\n number <= view.choices.length\n ) {\n selected = view.choices[number - 1]?.id ?? selected;\n }\n }\n const parsed = parseAgentSelection(selected);\n if (parsed.provider === null || !isAgentProviderId(parsed.provider)) {\n return {\n ok: false,\n error:\n `unknown agent '${selected}'. Expected one of: claude, codex, cursor.`,\n };\n }\n const provider = parsed.provider;\n let selectedChoice = view?.choices.find((choice) => choice.id === provider);\n if (\n args.interactive &&\n selectedChoice !== undefined &&\n !selectedChoice.ready &&\n selectedChoice.fixCommand?.startsWith(\"run: \") === true\n ) {\n const command = selectedChoice.fixCommand.slice(\"run: \".length);\n const runLogin = await confirm(\n args.out,\n `${selectedChoice.label} is not ready. Run '${command}' now?`,\n true,\n );\n if (runLogin === \"install\") {\n const login = await runLoginCommand(command);\n if (login.ok) {\n view = await buildProviderSetupView({ config, spawnCli: args.spawnCli });\n selectedChoice = view.choices.find((choice) => choice.id === provider);\n } else {\n stepActive(args.out, `${selectedChoice.label} login failed: ${login.error}`);\n }\n }\n }\n const requestedModel = args.requestedModel ?? parsed.model;\n const model = requestedModel ?? await chooseProviderModel({\n out: args.out,\n interactive: args.interactive,\n provider,\n choice: selectedChoice,\n configuredModel: config.agent.models[provider] ?? null,\n });\n await writeConfig({\n ...config,\n agent: {\n ...config.agent,\n default: provider,\n models: {\n ...config.agent.models,\n [provider]: model,\n },\n },\n });\n if (!args.interactive || args.requested !== undefined) {\n const detail = selectedChoice?.ready === true\n ? \"ready\"\n : selectedChoice?.fixCommand ?? selectedChoice?.detail ?? \"status unknown\";\n stepDone(args.out, `Agent readiness: ${detail}`);\n }\n return { ok: true, provider, model };\n}\n\nasync function chooseProviderModel(args: {\n out: NodeJS.WritableStream;\n interactive: boolean;\n provider: AgentProviderId;\n choice?: ProviderSetupView[\"choices\"][number];\n configuredModel: string | null;\n}): Promise<string | null> {\n const choices =\n args.choice?.modelChoices ??\n buildProviderModelChoices(args.provider, args.configuredModel);\n const recommended =\n choices.find((choice) => choice.recommended) ??\n choices.find((choice) => choice.source === \"provider-default\");\n if (!args.interactive) {\n return args.configuredModel ?? recommended?.value ?? null;\n }\n\n args.out.write(` Choose model for ${getProviderLabel(args.provider)}:\\n`);\n choices.forEach((choice, index) => {\n const marker = choice.recommended ? \" recommended\" : \"\";\n const current = choice.value === args.configuredModel ? \" current\" : \"\";\n args.out.write(\n ` ${index + 1}. ${choice.label}${marker}${current}\\n`,\n );\n });\n const currentIndex = choices.findIndex((choice) =>\n choice.value === args.configuredModel\n );\n const recommendedIndex = choices.findIndex((choice) => choice.recommended);\n const defaultIndex =\n currentIndex >= 0\n ? currentIndex + 1\n : recommendedIndex >= 0\n ? recommendedIndex + 1\n : 1;\n const selected = await promptText(args.out, \"Model\", String(defaultIndex));\n const number = Number.parseInt(selected, 10);\n let modelChoice: ProviderModelChoice | undefined;\n if (\n Number.isInteger(number) &&\n number >= 1 &&\n number <= choices.length\n ) {\n modelChoice = choices[number - 1];\n } else {\n modelChoice = choices.find((choice) => choice.value === selected);\n }\n if (modelChoice?.source === \"custom\") {\n const custom = await promptText(args.out, \"Custom model id\", \"\");\n return custom.length > 0 ? custom : recommended?.value ?? null;\n }\n return modelChoice?.value ?? recommended?.value ?? null;\n}\n\nasync function runLoginCommand(command: string): Promise<\n | { ok: true }\n | { ok: false; error: string }\n> {\n return new Promise((resolve) => {\n const child = spawn(command, {\n shell: true,\n stdio: \"inherit\",\n });\n child.on(\"error\", (err) => {\n resolve({ ok: false, error: err.message });\n });\n child.on(\"close\", (code) => {\n if (code === 0) {\n resolve({ ok: true });\n return;\n }\n resolve({ ok: false, error: `exited ${code ?? 1}` });\n });\n });\n}\n\n// ─── Guide installation ──────────────────────────────────────────────\n\ninterface InstallGuidesOptions {\n provider: AgentProviderId;\n claudeDir: string;\n guidesDir: string;\n cwd: string;\n}\n\ninterface InstallGuidesResult {\n providerLabel: string;\n anyChanges: boolean;\n filesWritten: string[];\n}\n\nconst CODEX_BLOCK_START = \"<!-- codealmanac:start -->\";\nconst CODEX_BLOCK_END = \"<!-- codealmanac:end -->\";\n\n/**\n * Install provider-specific usage guidance. Each provider gets the same\n * core instructions, but in the place that provider actually reads.\n *\n * Returns a summary the caller uses to decide whether to say \"installed\"\n * or \"already installed\" in the TUI.\n */\nasync function installGuides(\n options: InstallGuidesOptions,\n): Promise<InstallGuidesResult> {\n const srcMini = path.join(options.guidesDir, \"mini.md\");\n const srcRef = path.join(options.guidesDir, \"reference.md\");\n if (!existsSync(srcMini)) {\n throw new Error(`missing bundled guide: ${srcMini}`);\n }\n if (!existsSync(srcRef)) {\n throw new Error(`missing bundled guide: ${srcRef}`);\n }\n\n switch (options.provider) {\n case \"claude\":\n return await installClaudeGuides(options, srcMini, srcRef);\n case \"codex\":\n return await installCodexGuides(srcMini, srcRef);\n case \"cursor\":\n return await installCursorGuides(options.cwd, srcMini);\n }\n}\n\nasync function installClaudeGuides(\n options: InstallGuidesOptions,\n srcMini: string,\n srcRef: string,\n): Promise<InstallGuidesResult> {\n await mkdir(options.claudeDir, { recursive: true });\n\n const destMini = path.join(options.claudeDir, \"codealmanac.md\");\n const destRef = path.join(options.claudeDir, \"codealmanac-reference.md\");\n\n const miniChanged = await copyIfChanged(srcMini, destMini);\n const refChanged = await copyIfChanged(srcRef, destRef);\n\n const claudeMd = path.join(options.claudeDir, \"CLAUDE.md\");\n const importChanged = await ensureImport(claudeMd);\n\n const filesWritten: string[] = [];\n if (miniChanged) filesWritten.push(\"codealmanac.md\");\n if (refChanged) filesWritten.push(\"codealmanac-reference.md\");\n if (importChanged) filesWritten.push(\"CLAUDE.md\");\n\n return {\n providerLabel: \"Claude\",\n anyChanges: filesWritten.length > 0,\n filesWritten,\n };\n}\n\nasync function installCodexGuides(\n srcMini: string,\n srcRef: string,\n): Promise<InstallGuidesResult> {\n const codexDir = path.join(homedir(), \".codex\");\n await mkdir(codexDir, { recursive: true });\n const destMini = path.join(codexDir, \"codealmanac.md\");\n const destRef = path.join(codexDir, \"codealmanac-reference.md\");\n const miniChanged = await copyIfChanged(srcMini, destMini);\n const refChanged = await copyIfChanged(srcRef, destRef);\n const agentsChanged = await ensureManagedBlock(\n path.join(codexDir, \"AGENTS.md\"),\n codexGuideBlock(),\n );\n\n const filesWritten: string[] = [];\n if (miniChanged) filesWritten.push(\"codealmanac.md\");\n if (refChanged) filesWritten.push(\"codealmanac-reference.md\");\n if (agentsChanged) filesWritten.push(\"AGENTS.md\");\n\n return {\n providerLabel: \"Codex\",\n anyChanges: filesWritten.length > 0,\n filesWritten,\n };\n}\n\nasync function installCursorGuides(\n cwd: string,\n srcMini: string,\n): Promise<InstallGuidesResult> {\n const rulesDir = path.join(cwd, \".cursor\", \"rules\");\n await mkdir(rulesDir, { recursive: true });\n const mini = await readFile(srcMini, \"utf8\");\n const dest = path.join(rulesDir, \"codealmanac.mdc\");\n const body =\n \"---\\n\" +\n \"description: Use codealmanac wiki context during coding work\\n\" +\n \"alwaysApply: true\\n\" +\n \"---\\n\\n\" +\n mini;\n const changed = await writeIfChanged(dest, body);\n\n return {\n providerLabel: \"Cursor\",\n anyChanges: changed,\n filesWritten: changed ? [\".cursor/rules/codealmanac.mdc\"] : [],\n };\n}\n\nasync function copyIfChanged(src: string, dest: string): Promise<boolean> {\n const srcBytes = await readFile(src);\n if (existsSync(dest)) {\n try {\n const destBytes = await readFile(dest);\n if (srcBytes.equals(destBytes)) return false;\n } catch {\n // Fall through to write.\n }\n }\n await copyFile(src, dest);\n return true;\n}\n\nasync function writeIfChanged(dest: string, body: string): Promise<boolean> {\n if (existsSync(dest)) {\n try {\n if (await readFile(dest, \"utf8\") === body) return false;\n } catch {\n // Fall through to write.\n }\n }\n await writeFile(dest, body, \"utf8\");\n return true;\n}\n\nasync function ensureManagedBlock(\n file: string,\n block: string,\n): Promise<boolean> {\n let existing = \"\";\n if (existsSync(file)) existing = await readFile(file, \"utf8\");\n const pattern = new RegExp(\n `${escapeRegex(CODEX_BLOCK_START)}[\\\\s\\\\S]*?${escapeRegex(CODEX_BLOCK_END)}`,\n );\n const next = pattern.test(existing)\n ? existing.replace(pattern, block.trimEnd())\n : `${existing.trimEnd()}${existing.trim().length > 0 ? \"\\n\\n\" : \"\"}${block.trimEnd()}\\n`;\n const normalized = next.endsWith(\"\\n\") ? next : `${next}\\n`;\n if (normalized === existing) return false;\n await writeFile(file, normalized, \"utf8\");\n return true;\n}\n\nfunction codexGuideBlock(): string {\n return [\n CODEX_BLOCK_START,\n \"# codealmanac\",\n \"\",\n \"This machine has codealmanac installed: a local wiki for codebases.\",\n \"Before codealmanac/wiki-related work, read `~/.codex/codealmanac.md`.\",\n \"For the full command reference, read `~/.codex/codealmanac-reference.md` on demand.\",\n CODEX_BLOCK_END,\n \"\",\n ].join(\"\\n\");\n}\n\nfunction escapeRegex(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\n}\n\n/** The exact import line we manage. Changing this requires updating\n * uninstall too. */\nexport const IMPORT_LINE = \"@~/.claude/codealmanac.md\";\n\n/**\n * Append the import line to `~/.claude/CLAUDE.md` if it isn't already\n * present. Creates the file if absent. Returns true when we wrote, false\n * when the line was already there.\n *\n * We match on `@~/.claude/codealmanac.md` appearing on any non-empty\n * line (trimmed). This catches both the bare line we write and any\n * user-edited variant (comments, trailing whitespace). We deliberately\n * do NOT try to repair a user who deleted the newline — that's their\n * file to shape.\n */\nasync function ensureImport(claudeMdPath: string): Promise<boolean> {\n let existing = \"\";\n if (existsSync(claudeMdPath)) {\n existing = await readFile(claudeMdPath, \"utf8\");\n }\n if (hasImportLine(existing)) return false;\n\n const sep =\n existing.length === 0 ? \"\" : existing.endsWith(\"\\n\") ? \"\\n\" : \"\\n\\n\";\n const body = `${existing}${sep}${IMPORT_LINE}\\n`;\n await writeFile(claudeMdPath, body, \"utf8\");\n return true;\n}\n\nexport function hasImportLine(contents: string): boolean {\n // Match line-starts-with-token rather than exact-line equality so a\n // user who annotated the import line (`@~/.claude/codealmanac.md #\n // codealmanac`) doesn't cause us to re-append a duplicate below.\n // The trailing-character check rules out accidental matches on a\n // longer line like `@~/.claude/codealmanac.md-extra`.\n const lines = contents.split(/\\r?\\n/).map((l) => l.trim());\n return lines.some((line) => {\n if (line === IMPORT_LINE) return true;\n if (!line.startsWith(IMPORT_LINE)) return false;\n const next = line[IMPORT_LINE.length];\n return next === \" \" || next === \"\\t\";\n });\n}\n\n// ─── Interactive prompt ──────────────────────────────────────────────\n\ntype InstallDecision = \"install\" | \"skip\";\n\n/**\n * Minimal `[Y/n]` prompt. No raw mode, no cursor — just readline. The\n * MCP setup uses a fancy arrow-key TUI for multi-choice; we only have\n * binary decisions here, so a line-reader prompt is clearer and doesn't\n * fight with the step-indicator rendering above it.\n */\nfunction confirm(\n out: NodeJS.WritableStream,\n question: string,\n defaultYes: boolean,\n): Promise<InstallDecision> {\n return new Promise((resolve) => {\n const hint = defaultYes ? \"[Y/n]\" : \"[y/N]\";\n out.write(` ${BLUE}\\u25c6${RST} ${question} ${DIM}${hint}${RST} `);\n\n let buf = \"\";\n const onData = (chunk: Buffer): void => {\n buf += chunk.toString(\"utf8\");\n const nl = buf.indexOf(\"\\n\");\n if (nl === -1) return;\n process.stdin.removeListener(\"data\", onData);\n process.stdin.pause();\n\n const answer = buf.slice(0, nl).trim().toLowerCase();\n const accepted =\n answer.length === 0\n ? defaultYes\n : answer === \"y\" || answer === \"yes\";\n resolve(accepted ? \"install\" : \"skip\");\n };\n\n process.stdin.resume();\n process.stdin.on(\"data\", onData);\n });\n}\n\nfunction promptText(\n out: NodeJS.WritableStream,\n question: string,\n defaultValue: string,\n): Promise<string> {\n return new Promise((resolve) => {\n out.write(\n ` ${BLUE}\\u25c6${RST} ${question} ${DIM}[${defaultValue}]${RST} `,\n );\n\n let buf = \"\";\n const onData = (chunk: Buffer): void => {\n buf += chunk.toString(\"utf8\");\n const nl = buf.indexOf(\"\\n\");\n if (nl === -1) return;\n process.stdin.removeListener(\"data\", onData);\n process.stdin.pause();\n\n const answer = buf.slice(0, nl).trim();\n resolve(answer.length === 0 ? defaultValue : answer);\n };\n\n process.stdin.resume();\n process.stdin.on(\"data\", onData);\n });\n}\n\n// ─── Guides path resolution ──────────────────────────────────────────\n\n/**\n * Locate `guides/` relative to the installed package. Mirrors\n * `resolvePromptsDir` from `src/agent/prompts.ts`.\n *\n * Two runtime layouts to handle:\n *\n * 1. **Bundled dist.** `dist/codealmanac.js` → walk one level up →\n * `guides/`.\n * 2. **Source (tests / tsx).** `src/commands/setup.ts` → walk two\n * levels up → `guides/`.\n *\n * We also try `createRequire` to resolve the package root from the\n * `codealmanac/package.json` manifest, as a belt-and-suspenders fallback\n * for unusual install layouts (monorepo hoisting, etc.). That path is\n * only exercised when the direct walk-up fails.\n */\nexport function resolveGuidesDir(): string {\n const here = path.dirname(fileURLToPath(import.meta.url));\n const candidates = [\n path.resolve(here, \"..\", \"guides\"), // dist layout\n path.resolve(here, \"..\", \"..\", \"guides\"), // src layout\n path.resolve(here, \"..\", \"..\", \"..\", \"guides\"),\n ];\n for (const dir of candidates) {\n if (looksLikeGuidesDir(dir)) return dir;\n }\n // Fallback: resolve via the package.json of the currently-running\n // codealmanac. createRequire lets us ask Node's resolver rather than\n // guessing at directory layouts.\n try {\n const require = createRequire(import.meta.url);\n const pkgJson = require.resolve(\"codealmanac/package.json\");\n const guides = path.join(path.dirname(pkgJson), \"guides\");\n if (looksLikeGuidesDir(guides)) return guides;\n } catch {\n // Ignore — we'll throw with the candidate list below.\n }\n throw new Error(\n \"could not locate bundled guides/ directory. Tried:\\n\" +\n candidates.map((c) => ` - ${c}`).join(\"\\n\"),\n );\n}\n\nfunction looksLikeGuidesDir(dir: string): boolean {\n return existsSync(path.join(dir, \"mini.md\"));\n}\n\nfunction printProviderNextSteps(out: NodeJS.WritableStream): void {\n out.write(` ${DIM}Change provider/model later:${RST}\\n`);\n out.write(` ${DIM} almanac agents list${RST}\\n`);\n out.write(` ${DIM} almanac agents use <claude|codex|cursor>${RST}\\n`);\n out.write(\n ` ${DIM} almanac agents model <provider> <model|--default>${RST}\\n\\n`,\n );\n}\n","import { execFile } from \"node:child_process\";\nimport { createRequire } from \"node:module\";\nimport { homedir } from \"node:os\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Return the directory of the currently-running codealmanac install by\n * walking up from this module's file to the nearest `package.json` whose\n * `name` is `codealmanac`. Returns the empty string when the walk fails.\n */\nexport function detectCurrentInstallPath(): string {\n try {\n const req = createRequire(import.meta.url);\n const here = fileURLToPath(import.meta.url);\n let dir = path.dirname(here);\n for (let i = 0; i < 6; i++) {\n const pkgPath = path.join(dir, \"package.json\");\n try {\n const raw = req(\"fs\").readFileSync(pkgPath, \"utf-8\") as string;\n const pkg = JSON.parse(raw) as { name?: unknown };\n if (pkg.name === \"codealmanac\") return dir;\n } catch {\n // keep walking\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n } catch {\n // import.meta.url unavailable — not ephemeral for our purposes.\n }\n return \"\";\n}\n\n/**\n * Return true when the given install path looks ephemeral.\n *\n * Ephemeral locations we recognize:\n * - `~/.npm/_npx/` — npm's npx cache (GC'd on version bumps or\n * `npm cache clean`)\n * - `~/.local/share/pnpm/dlx/` — pnpm's dlx (like npx) cache\n * - `/tmp/` or `/var/folders/` — common CI / temp paths\n *\n * A global install (`~/.nvm/.../lib/node_modules/`, `/usr/local/lib/...`,\n * `~/.local/lib/node_modules/`) is NOT ephemeral.\n */\nexport function detectEphemeral(installPath: string): boolean {\n if (installPath.length === 0) return false;\n const home = homedir();\n if (installPath.startsWith(path.join(home, \".npm\", \"_npx\"))) return true;\n if (\n installPath.startsWith(path.join(home, \".local\", \"share\", \"pnpm\", \"dlx\"))\n ) return true;\n if (installPath.startsWith(\"/tmp/\")) return true;\n if (installPath.startsWith(\"/var/folders/\")) return true;\n return false;\n}\n\n/**\n * Spawn `npm install -g codealmanac@latest` in a child process and wait\n * for it to finish. Rejects on non-zero exit or spawn error.\n */\nexport function spawnGlobalInstall(): Promise<void> {\n return new Promise((resolve, reject) => {\n execFile(\n \"npm\",\n [\"install\", \"-g\", \"codealmanac@latest\"],\n { shell: false },\n (err, _stdout, stderr) => {\n if (err !== null) {\n reject(\n new Error(\n stderr.length > 0\n ? stderr.trim().split(\"\\n\")[0] ?? err.message\n : err.message,\n ),\n );\n } else {\n resolve();\n }\n },\n );\n });\n}\n","import { existsSync, readdirSync } from \"node:fs\";\nimport path from \"node:path\";\n\nconst RST = \"\\x1b[0m\";\nconst BOLD = \"\\x1b[1m\";\nconst DIM = \"\\x1b[2m\";\nconst WHITE_BOLD = \"\\x1b[1;37m\";\nconst BLUE = \"\\x1b[38;5;75m\";\nconst BLUE_DIM = \"\\x1b[38;5;69m\";\n\n/**\n * Print the \"Next steps\" box. When `existingPageCount` is greater than 0,\n * the current working directory already has a wiki with committed pages.\n * In that case we skip the `almanac bootstrap` step and tell the user to\n * start querying.\n */\nexport function printNextSteps(\n out: NodeJS.WritableStream,\n existingPageCount: number,\n): void {\n const innerW = 62;\n const vis = (s: string): number =>\n s.replace(/\\x1b\\[[0-9;]*m/g, \"\").length;\n const row = (content: string): string => {\n const padding = Math.max(0, innerW - vis(content));\n return ` ${BLUE_DIM}\\u2502${RST}${content}${\" \".repeat(padding)}${BLUE_DIM}\\u2502${RST}\\n`;\n };\n const empty = row(\"\");\n\n out.write(` ${BLUE_DIM}\\u256d${\"─\".repeat(innerW)}\\u256e${RST}\\n`);\n out.write(empty);\n out.write(row(` ${WHITE_BOLD}Next steps${RST}`));\n out.write(empty);\n\n if (existingPageCount > 0) {\n out.write(\n row(\n ` ${BLUE}\\u25c7${RST} This repo already has a wiki ${DIM}(${existingPageCount} page${existingPageCount === 1 ? \"\" : \"s\"})${RST}`,\n ),\n );\n out.write(empty);\n out.write(row(` ${BLUE}1.${RST} Start querying your wiki:`));\n out.write(row(` ${BOLD}almanac search --mentions <file>${RST}`));\n out.write(\n row(` ${BLUE}2.${RST} Work normally — capture runs on session end`),\n );\n } else {\n out.write(\n row(` ${BLUE}1.${RST} ${BOLD}cd${RST} into a repo you want to document`),\n );\n out.write(\n row(\n ` ${BLUE}2.${RST} ${BOLD}almanac bootstrap${RST} ${DIM}# scaffold the wiki${RST}`,\n ),\n );\n out.write(\n row(` ${BLUE}3.${RST} Work normally — capture runs on session end`),\n );\n }\n\n out.write(empty);\n out.write(` ${BLUE_DIM}\\u2570${\"─\".repeat(innerW)}\\u256f${RST}\\n\\n`);\n}\n\n/**\n * Count `.md` files in `.almanac/pages/` under the current working\n * directory or any parent. Returns 0 when no wiki is found or the pages\n * directory is empty.\n */\nexport function countExistingPages(cwd: string): number {\n try {\n let dir = cwd;\n for (let i = 0; i < 10; i++) {\n const pagesDir = path.join(dir, \".almanac\", \"pages\");\n if (existsSync(pagesDir)) {\n try {\n const entries = readdirSync(pagesDir);\n return entries.filter((e) => e.endsWith(\".md\")).length;\n } catch {\n return 0;\n }\n }\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n } catch {\n // Swallow — never crash setup because of this.\n }\n return 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,SAAS,cAAAA,mBAAkB;AAC3B,SAAS,aAAa;AACtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAAC,sBAAqB;AAC9B,SAAS,WAAAC,gBAAe;AACxB,OAAOC,WAAU;AACjB,SAAS,iBAAAC,sBAAqB;;;ACX9B,SAAS,gBAAgB;AACzB,SAAS,qBAAqB;AAC9B,SAAS,eAAe;AACxB,OAAO,UAAU;AACjB,SAAS,qBAAqB;AAOvB,SAAS,2BAAmC;AACjD,MAAI;AACF,UAAM,MAAM,cAAc,YAAY,GAAG;AACzC,UAAM,OAAO,cAAc,YAAY,GAAG;AAC1C,QAAI,MAAM,KAAK,QAAQ,IAAI;AAC3B,aAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,YAAM,UAAU,KAAK,KAAK,KAAK,cAAc;AAC7C,UAAI;AACF,cAAM,MAAM,IAAI,IAAI,EAAE,aAAa,SAAS,OAAO;AACnD,cAAM,MAAM,KAAK,MAAM,GAAG;AAC1B,YAAI,IAAI,SAAS,cAAe,QAAO;AAAA,MACzC,QAAQ;AAAA,MAER;AACA,YAAM,SAAS,KAAK,QAAQ,GAAG;AAC/B,UAAI,WAAW,IAAK;AACpB,YAAM;AAAA,IACR;AAAA,EACF,QAAQ;AA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AM,MAAM,QAAQ;AAAA;AAAA,IACvCA,MAAK,QAAQ,MAAM,MAAM,MAAM,MAAM,QAAQ;AAAA,EAC/C;AACA,aAAW,OAAO,YAAY;AAC5B,QAAI,mBAAmB,GAAG,EAAG,QAAO;AAAA,EACtC;AAIA,MAAI;AACF,UAAMI,WAAUC,eAAc,YAAY,GAAG;AAC7C,UAAM,UAAUD,SAAQ,QAAQ,0BAA0B;AAC1D,UAAM,SAASJ,MAAK,KAAKA,MAAK,QAAQ,OAAO,GAAG,QAAQ;AACxD,QAAI,mBAAmB,MAAM,EAAG,QAAO;AAAA,EACzC,QAAQ;AAAA,EAER;AACA,QAAM,IAAI;AAAA,IACR,yDACE,WAAW,IAAI,CAAC,MAAM,OAAO,CAAC,EAAE,EAAE,KAAK,IAAI;AAAA,EAC/C;AACF;AAEA,SAAS,mBAAmB,KAAsB;AAChD,SAAOE,YAAWF,MAAK,KAAK,KAAK,SAAS,CAAC;AAC7C;AAEA,SAAS,uBAAuB,KAAkC;AAChE,MAAI,MAAM,KAAKH,IAAG,+BAA+BD,IAAG;AAAA,CAAI;AACxD,MAAI,MAAM,KAAKC,IAAG,wBAAwBD,IAAG;AAAA,CAAI;AACjD,MAAI,MAAM,KAAKC,IAAG,6CAA6CD,IAAG;AAAA,CAAI;AACtE,MAAI;AAAA,IACF,KAAKC,IAAG,sDAAsDD,IAAG;AAAA;AAAA;AAAA,EACnE;AACF;","names":["existsSync","createRequire","homedir","path","fileURLToPath","path","RST","DIM","WHITE_BOLD","BLUE","path","homedir","existsSync","fileURLToPath","require","createRequire"]}