@the-librarian/cli 1.0.0-rc.5 → 1.0.0-rc.50

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 (78) hide show
  1. package/README.md +53 -7
  2. package/dist/archive.d.ts +15 -0
  3. package/dist/archive.d.ts.map +1 -0
  4. package/dist/archive.js +58 -0
  5. package/dist/archive.js.map +1 -0
  6. package/dist/harnesses/codex.d.ts +13 -0
  7. package/dist/harnesses/codex.d.ts.map +1 -1
  8. package/dist/harnesses/codex.js +210 -26
  9. package/dist/harnesses/codex.js.map +1 -1
  10. package/dist/harnesses/hermes.d.ts +1 -1
  11. package/dist/harnesses/hermes.d.ts.map +1 -1
  12. package/dist/harnesses/hermes.js +42 -23
  13. package/dist/harnesses/hermes.js.map +1 -1
  14. package/dist/harnesses/opencode.d.ts +12 -0
  15. package/dist/harnesses/opencode.d.ts.map +1 -1
  16. package/dist/harnesses/opencode.js +122 -5
  17. package/dist/harnesses/opencode.js.map +1 -1
  18. package/dist/paths.d.ts +16 -0
  19. package/dist/paths.d.ts.map +1 -1
  20. package/dist/paths.js +22 -0
  21. package/dist/paths.js.map +1 -1
  22. package/dist/runtime.d.ts +14 -0
  23. package/dist/runtime.d.ts.map +1 -1
  24. package/dist/runtime.js +230 -1
  25. package/dist/runtime.js.map +1 -1
  26. package/dist/server/admin.d.ts +31 -0
  27. package/dist/server/admin.d.ts.map +1 -0
  28. package/dist/server/admin.js +131 -0
  29. package/dist/server/admin.js.map +1 -0
  30. package/dist/server/autoupdate.d.ts +184 -0
  31. package/dist/server/autoupdate.d.ts.map +1 -0
  32. package/dist/server/autoupdate.js +794 -0
  33. package/dist/server/autoupdate.js.map +1 -0
  34. package/dist/server/boot.d.ts +51 -0
  35. package/dist/server/boot.d.ts.map +1 -0
  36. package/dist/server/boot.js +233 -0
  37. package/dist/server/boot.js.map +1 -0
  38. package/dist/server/deploy-state.d.ts +40 -0
  39. package/dist/server/deploy-state.d.ts.map +1 -0
  40. package/dist/server/deploy-state.js +89 -0
  41. package/dist/server/deploy-state.js.map +1 -0
  42. package/dist/server/docker.d.ts +53 -0
  43. package/dist/server/docker.d.ts.map +1 -0
  44. package/dist/server/docker.js +166 -0
  45. package/dist/server/docker.js.map +1 -0
  46. package/dist/server/down.d.ts +19 -0
  47. package/dist/server/down.d.ts.map +1 -0
  48. package/dist/server/down.js +62 -0
  49. package/dist/server/down.js.map +1 -0
  50. package/dist/server/index.d.ts +8 -0
  51. package/dist/server/index.d.ts.map +1 -0
  52. package/dist/server/index.js +50 -0
  53. package/dist/server/index.js.map +1 -0
  54. package/dist/server/logs.d.ts +50 -0
  55. package/dist/server/logs.d.ts.map +1 -0
  56. package/dist/server/logs.js +162 -0
  57. package/dist/server/logs.js.map +1 -0
  58. package/dist/server/preflight.d.ts +24 -0
  59. package/dist/server/preflight.d.ts.map +1 -0
  60. package/dist/server/preflight.js +58 -0
  61. package/dist/server/preflight.js.map +1 -0
  62. package/dist/server/redact.d.ts +2 -0
  63. package/dist/server/redact.d.ts.map +1 -0
  64. package/dist/server/redact.js +26 -0
  65. package/dist/server/redact.js.map +1 -0
  66. package/dist/server/status.d.ts +20 -0
  67. package/dist/server/status.d.ts.map +1 -0
  68. package/dist/server/status.js +103 -0
  69. package/dist/server/status.js.map +1 -0
  70. package/dist/server/up.d.ts +244 -0
  71. package/dist/server/up.d.ts.map +1 -0
  72. package/dist/server/up.js +758 -0
  73. package/dist/server/up.js.map +1 -0
  74. package/dist/server/update.d.ts +35 -0
  75. package/dist/server/update.d.ts.map +1 -0
  76. package/dist/server/update.js +313 -0
  77. package/dist/server/update.js.map +1 -0
  78. package/package.json +2 -2
package/README.md CHANGED
@@ -1,16 +1,26 @@
1
1
  # `@the-librarian/cli` — the `librarian` installer
2
2
 
3
- A small cross-harness CLI that installs, updates, and tracks
4
- [The Librarian](https://github.com/JimJafar/the-librarian)'s integrations across
5
- all your harnesses and machines. Think of it as the package manager for your
6
- Librarian setup: one tool you keep, driving each harness's **native** install
7
- path rather than hand-editing five config formats.
3
+ A small CLI that does two jobs for
4
+ [The Librarian](https://github.com/JimJafar/the-librarian): it **wires it into
5
+ your AI agents** (installs/updates the integration for each harness, across all
6
+ your machines) and **self-hosts the server** they talk to (`server up` /
7
+ `update`). Think of it as the package manager for your Librarian setup: one tool
8
+ you keep, driving each harness's **native** install path rather than hand-editing
9
+ five config formats.
8
10
 
9
- Harnesses it manages: **Claude Code, Codex, OpenCode, Hermes, Pi.**
11
+ Harnesses it manages: **Claude Code, Codex, OpenCode, Hermes, Pi.** For the
12
+ server side, see [Self-host the server](#self-host-the-server).
10
13
 
11
14
  ## Install
12
15
 
13
- Install the CLI globally, then run the interactive setup:
16
+ Run it straight from npm with `npx` — no global install needed:
17
+
18
+ ```sh
19
+ npx @the-librarian/cli install
20
+ ```
21
+
22
+ Prefer a persistent command? Install it globally once and call `librarian`
23
+ directly:
14
24
 
15
25
  ```sh
16
26
  npm i -g @the-librarian/cli
@@ -36,6 +46,12 @@ librarian config Show or set MCP URL, token, server URL
36
46
  librarian self-update Update the CLI itself (coming in a later release)
37
47
  librarian report Push this machine's state to the server
38
48
  (coming in a later release)
49
+
50
+ librarian server up Self-host the server with Docker; prints the
51
+ MCP URL + agent token to paste into `install`
52
+ librarian server update Upgrade the server to the latest release
53
+ (your data is preserved)
54
+ librarian server down|status|logs Stop / inspect / tail the running server
39
55
  ```
40
56
 
41
57
  Useful flags: `--mcp-url <url>`, `--token <token>` (never printed),
@@ -44,6 +60,36 @@ Useful flags: `--mcp-url <url>`, `--token <token>` (never printed),
44
60
  harness whose CLI isn't installed is reported `not-detected` and skipped — not
45
61
  an error.
46
62
 
63
+ ## Self-host the server
64
+
65
+ The Librarian needs a server to talk to. `server up` stands one up with Docker —
66
+ it builds the all-in-one image, mints your secrets, waits for health, and prints
67
+ the MCP URL + agent token to paste into `librarian install`:
68
+
69
+ ```sh
70
+ npx @the-librarian/cli server up
71
+ ```
72
+
73
+ By default the vault lives in a Docker-managed named volume (`librarian_data`).
74
+ To keep your data at a path **you** choose — so you can back it up, put it on a
75
+ specific disk, or move it between hosts — pass `--data-dir`:
76
+
77
+ ```sh
78
+ npx @the-librarian/cli server up --data-dir /srv/librarian
79
+ ```
80
+
81
+ With `--data-dir`, the server bind-mounts that directory at `/data` and runs the
82
+ container **as the directory's owner**, so the vault stays owned by — and
83
+ writable by — you, not a container user. The directory is created if it doesn't
84
+ exist, and `server update` reuses it automatically. (`--data-dir` and
85
+ `--data-volume` are mutually exclusive.)
86
+
87
+ Other server commands: `server update` (upgrade to the latest release, preserving
88
+ your data), `server down` / `status` / `logs`, and `server enable-boot` (Linux
89
+ systemd) to start it on boot. Run it on a private network / behind a VPN, or
90
+ expose it with auth — see the
91
+ [deployment guide](https://github.com/JimJafar/the-librarian/blob/main/DEPLOYMENT.md).
92
+
47
93
  ## What it writes to your environment
48
94
 
49
95
  The CLI keeps everything under `~/.librarian/`:
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Extract `subPath` (a POSIX path *inside* the repo root, e.g.
3
+ * `integrations/codex`) out of a codeload `.tar.gz` and return the absolute
4
+ * path to it. The returned directory's CONTENTS are the subtree's contents —
5
+ * matching the old `--strip-components` semantics, so callers copy from the
6
+ * returned path unchanged.
7
+ *
8
+ * @param tarball path to the downloaded `.tar.gz`
9
+ * @param work scratch dir to extract into (caller owns its lifecycle)
10
+ * @param subPath POSIX subtree path inside the repo root, e.g. `integrations/codex`
11
+ * @throws if tar exits non-zero, the tarball layout is unexpected, or the
12
+ * requested subtree is absent — with a message safe to show the user.
13
+ */
14
+ export declare function extractAdapterSubtree(tarball: string, work: string, subPath: string): Promise<string>;
15
+ //# sourceMappingURL=archive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../src/archive.ts"],"names":[],"mappings":"AAwBA;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,CAAC,CAwBjB"}
@@ -0,0 +1,58 @@
1
+ // Portable extraction of a single integration subtree out of a GitHub
2
+ // codeload tarball.
3
+ //
4
+ // The harness capture adapters (Codex / OpenCode / Hermes) don't ship inside
5
+ // their plugin packages — the installer downloads the pinned release tarball
6
+ // from codeload and copies one `integrations/<harness>/…` subtree out of it.
7
+ //
8
+ // History: the original approach selected members directly with
9
+ // tar -xzf t -C out --strip-components=N --wildcards '*/integrations/<h>/*'
10
+ // That is GNU-tar-only. BSD/libarchive tar (the `/usr/bin/tar` on macOS)
11
+ // rejects the flag outright — `tar: Option --wildcards is not supported` —
12
+ // and busybox tar lacks it too, so the Codex/OpenCode/Hermes steps failed on
13
+ // every non-GNU box. (GNU tar needs `--wildcards` to glob member names on
14
+ // extract; BSD tar globs by default and has no such flag — there is no single
15
+ // flag set that means "glob members" on both.)
16
+ //
17
+ // Fix: extract the whole archive using only the universally-supported
18
+ // `-xzf`/`-C` flags, then locate the wanted subtree with the filesystem. No
19
+ // `--wildcards`, no `--strip-components`, no tar-flavour detection.
20
+ import fs from "node:fs";
21
+ import path from "node:path";
22
+ import { run } from "./exec.js";
23
+ /**
24
+ * Extract `subPath` (a POSIX path *inside* the repo root, e.g.
25
+ * `integrations/codex`) out of a codeload `.tar.gz` and return the absolute
26
+ * path to it. The returned directory's CONTENTS are the subtree's contents —
27
+ * matching the old `--strip-components` semantics, so callers copy from the
28
+ * returned path unchanged.
29
+ *
30
+ * @param tarball path to the downloaded `.tar.gz`
31
+ * @param work scratch dir to extract into (caller owns its lifecycle)
32
+ * @param subPath POSIX subtree path inside the repo root, e.g. `integrations/codex`
33
+ * @throws if tar exits non-zero, the tarball layout is unexpected, or the
34
+ * requested subtree is absent — with a message safe to show the user.
35
+ */
36
+ export async function extractAdapterSubtree(tarball, work, subPath) {
37
+ const raw = path.join(work, "raw");
38
+ fs.mkdirSync(raw, { recursive: true });
39
+ // Only `-xzf`/`-C` — supported by GNU tar, BSD/libarchive tar, and busybox.
40
+ const extract = await run("tar", ["-xzf", tarball, "-C", raw]);
41
+ if (extract.code !== 0) {
42
+ throw new Error((extract.stderr || "").trim() || `tar exited with code ${extract.code}`);
43
+ }
44
+ // codeload wraps everything in a single top-level dir whose name depends on
45
+ // the ref (GitHub strips a leading `v` from tags: `v1.2.3` → `…-1.2.3`), so
46
+ // discover it rather than hardcode it.
47
+ const tops = fs.readdirSync(raw).filter((e) => !e.startsWith("."));
48
+ const top = tops.length === 1 ? tops[0] : tops.find((e) => e.startsWith("the-librarian-"));
49
+ if (!top) {
50
+ throw new Error(`unexpected tarball layout (top-level entries: ${tops.join(", ") || "none"})`);
51
+ }
52
+ const dir = path.join(raw, top, ...subPath.split("/"));
53
+ if (!fs.existsSync(dir)) {
54
+ throw new Error(`adapter path '${subPath}' not found under '${top}' in tarball`);
55
+ }
56
+ return dir;
57
+ }
58
+ //# sourceMappingURL=archive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive.js","sourceRoot":"","sources":["../src/archive.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,oBAAoB;AACpB,EAAE;AACF,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,EAAE;AACF,gEAAgE;AAChE,8EAA8E;AAC9E,yEAAyE;AACzE,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,8EAA8E;AAC9E,+CAA+C;AAC/C,EAAE;AACF,sEAAsE;AACtE,4EAA4E;AAC5E,oEAAoE;AAEpE,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEhC;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,OAAe,EACf,IAAY,EACZ,OAAe;IAEf,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE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IAAI,KAAK,CAAC,iBAAiB,OAAO,sBAAsB,GAAG,cAAc,CAAC,CAAC;IACnF,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1,3 +1,16 @@
1
1
  import type { HarnessModule } from "./types.js";
2
+ export declare const CODEX_CAPTURE_PINNED_REF: string;
3
+ /**
4
+ * Fetches the Codex capture integration for a pinned ref and returns the absolute
5
+ * path to a directory whose contents ARE the integration (the equivalent of
6
+ * `integrations/codex/`, i.e. holding `scripts/**` and `hooks/codex-hooks.json`).
7
+ * The caller copies from there. Injectable so tests substitute a local fixture
8
+ * instead of the network.
9
+ */
10
+ export type CaptureFetcher = (ref: string) => Promise<string>;
11
+ /** Override the capture-adapter fetcher (tests inject a local-fixture fetcher). */
12
+ export declare function setCodexCaptureFetcher(next: CaptureFetcher): void;
13
+ /** Restore the default (network) capture-adapter fetcher (tests). */
14
+ export declare function resetCodexCaptureFetcher(): void;
2
15
  export declare const codex: HarnessModule;
3
16
  //# sourceMappingURL=codex.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/harnesses/codex.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AA6F/D,eAAO,MAAM,KAAK,EAAE,aAuDnB,CAAC"}
1
+ {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/harnesses/codex.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AA0C/D,eAAO,MAAM,wBAAwB,QAAqB,CAAC;AAsF3D;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AA0B9D,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAEjE;AAED,qEAAqE;AACrE,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AA4HD,eAAO,MAAM,KAAK,EAAE,aAiDnB,CAAC"}
@@ -16,9 +16,12 @@
16
16
  // it resolves the value at request time. We pass `cfg.mcpUrl` (not the
17
17
  // token) on the CLI, so nothing secret is ever logged.
18
18
  import fs from "node:fs";
19
+ import os from "node:os";
19
20
  import path from "node:path";
21
+ import { extractAdapterSubtree } from "../archive.js";
20
22
  import { run, which } from "../exec.js";
21
- import { codexConfigPath } from "../paths.js";
23
+ import { codexCaptureDir, codexConfigPath, codexHooksPath } from "../paths.js";
24
+ import { cliVersion } from "../version.js";
22
25
  const CLI = "codex";
23
26
  const SERVER_ID = "librarian";
24
27
  const TOKEN_ENV_VAR = "LIBRARIAN_AGENT_TOKEN";
@@ -27,6 +30,37 @@ const TABLE_HEADER = "[mcp_servers.librarian]";
27
30
  // though TOML carries no native version for an MCP entry.
28
31
  const CONFIG_VERSION = "1";
29
32
  const VERSION_MARKER = "# librarian-config-version =";
33
+ // ── Auto-capture hooks wiring (spec 2026-06-16-harness-auto-capture, Phase 2A) ─
34
+ //
35
+ // Codex fires the same command-hook events as Claude (UserPromptSubmit / Stop /
36
+ // SessionEnd). Codex discovers lifecycle hooks ONLY at ~/.codex/hooks.json (no
37
+ // plugin host auto-wires them), so — mirroring mem0's install_codex_hooks.py — we
38
+ // MERGE our entries into that file (creating it if absent) and surface the
39
+ // `codex_hooks = true` feature-flag requirement. The merge is idempotent: entries
40
+ // we own are identified by an owner marker in the command string and stripped
41
+ // before fresh ones are added, so re-install/upgrade leaves no duplicates.
42
+ //
43
+ // The capture-adapter scripts (integrations/codex/scripts/**) do NOT ship with
44
+ // the published installer (it ships only dist/), so — exactly like the Hermes
45
+ // adapter — we FETCH them from the pinned release tarball and copy them under
46
+ // ~/.librarian/codex-capture; the merged hook commands point their
47
+ // ${LIBRARIAN_CODEX_ROOT} placeholder at that dir.
48
+ //
49
+ // ASSUMPTION (the one genuine unknown): the assumed hook events + payload shape
50
+ // are derived from mem0's proven Codex wiring + the Claude payload (documented in
51
+ // integrations/codex/scripts/lib/transcript.mjs). SC1 (true e2e against a running
52
+ // Codex) is DEFERRED — there is no codex CLI on the build machine to confirm.
53
+ // The placeholder in hooks/codex-hooks.json, rewritten to the absolute scripts
54
+ // install dir at merge time. Matches the env var the entry shell reads.
55
+ const ROOT_PLACEHOLDER = "${LIBRARIAN_CODEX_ROOT}";
56
+ // Substring that identifies entries THIS installer owns (stable across install
57
+ // paths), so the merge can strip + re-add idempotently. Mirrors mem0's
58
+ // OWNER_MARKER = "mem0-plugin".
59
+ const HOOKS_OWNER_MARKER = "the-librarian-codex";
60
+ // The pinned monorepo release we fetch the adapter from: the tag matching this
61
+ // CLI's own version. DERIVED (not hardcoded) so it can't drift — same rationale
62
+ // as the Hermes adapter's PINNED_REF.
63
+ export const CODEX_CAPTURE_PINNED_REF = `v${cliVersion()}`;
30
64
  /** Read config.toml, or "" if it doesn't exist yet. */
31
65
  function readConfig() {
32
66
  try {
@@ -106,6 +140,133 @@ function writeConfig(content) {
106
140
  fs.mkdirSync(path.dirname(file), { recursive: true });
107
141
  fs.writeFileSync(file, content, "utf8");
108
142
  }
143
+ /** The default fetcher: codeload tarball → `tar` extract → integration dir. */
144
+ const defaultCaptureFetcher = async (ref) => {
145
+ const url = `https://codeload.github.com/JimJafar/the-librarian/tar.gz/refs/tags/${ref}`;
146
+ const work = fs.mkdtempSync(path.join(os.tmpdir(), "librarian-codex-fetch-"));
147
+ const tarball = path.join(work, "src.tar.gz");
148
+ const res = await fetch(url, { redirect: "error" });
149
+ if (!res.ok) {
150
+ throw new Error(`Failed to fetch Codex capture adapter (${ref}): HTTP ${res.status}`);
151
+ }
152
+ const buf = Buffer.from(await res.arrayBuffer());
153
+ fs.writeFileSync(tarball, buf);
154
+ // codeload nests the integration at `the-librarian-<ref>/integrations/codex/**`;
155
+ // the returned dir holds its contents (`scripts/` + `hooks/`), which is what
156
+ // the caller copies into ~/.librarian/.
157
+ try {
158
+ return await extractAdapterSubtree(tarball, work, "integrations/codex");
159
+ }
160
+ catch (err) {
161
+ const msg = err instanceof Error ? err.message : String(err);
162
+ throw new Error(`Failed to extract Codex capture adapter: ${msg}`);
163
+ }
164
+ };
165
+ let captureFetcher = defaultCaptureFetcher;
166
+ /** Override the capture-adapter fetcher (tests inject a local-fixture fetcher). */
167
+ export function setCodexCaptureFetcher(next) {
168
+ captureFetcher = next;
169
+ }
170
+ /** Restore the default (network) capture-adapter fetcher (tests). */
171
+ export function resetCodexCaptureFetcher() {
172
+ captureFetcher = defaultCaptureFetcher;
173
+ }
174
+ /** Recursively copy a directory tree, overwriting any prior copy (idempotent). */
175
+ function copyDir(from, to) {
176
+ fs.rmSync(to, { recursive: true, force: true });
177
+ fs.mkdirSync(path.dirname(to), { recursive: true });
178
+ fs.cpSync(from, to, { recursive: true });
179
+ }
180
+ /** Read ~/.codex/hooks.json, or an empty shape if absent/unparseable. */
181
+ function readHooksFile() {
182
+ try {
183
+ const raw = fs.readFileSync(codexHooksPath(), "utf8");
184
+ const parsed = JSON.parse(raw);
185
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
186
+ return parsed;
187
+ }
188
+ }
189
+ catch {
190
+ // absent / unreadable / malformed — start from an empty shape
191
+ }
192
+ return { hooks: {} };
193
+ }
194
+ function writeHooksFile(config) {
195
+ const file = codexHooksPath();
196
+ fs.mkdirSync(path.dirname(file), { recursive: true });
197
+ fs.writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`, "utf8");
198
+ }
199
+ /** Does this entry belong to us (owner marker in any command string)? */
200
+ function isOwnedEntry(entry) {
201
+ return (entry.hooks ?? []).some((h) => typeof h.command === "string" && h.command.includes(HOOKS_OWNER_MARKER));
202
+ }
203
+ /** Remove every entry we own from a hooks file (so a re-merge can't duplicate). */
204
+ function stripOwnedEntries(config) {
205
+ const hooks = config.hooks ?? {};
206
+ for (const event of Object.keys(hooks)) {
207
+ hooks[event] = (hooks[event] ?? []).filter((e) => !isOwnedEntry(e));
208
+ if (hooks[event].length === 0)
209
+ delete hooks[event];
210
+ }
211
+ config.hooks = hooks;
212
+ return config;
213
+ }
214
+ /**
215
+ * Load our hooks template, rewrite the ${LIBRARIAN_CODEX_ROOT} placeholder to the
216
+ * absolute scripts dir, and return the parsed shape. The template lives in the
217
+ * fetched integration dir alongside the scripts it points at.
218
+ */
219
+ function loadTemplate(integrationDir, scriptsRoot) {
220
+ const raw = fs.readFileSync(path.join(integrationDir, "hooks", "codex-hooks.json"), "utf8");
221
+ // JSON-string-escape the path so a backslash (Windows) can't break the JSON.
222
+ const safe = JSON.stringify(scriptsRoot).slice(1, -1);
223
+ const rewritten = raw.split(ROOT_PLACEHOLDER).join(safe);
224
+ return JSON.parse(rewritten);
225
+ }
226
+ /** Merge template entries onto a (stripped) config, appending per event. */
227
+ function mergeTemplate(config, template) {
228
+ const hooks = (config.hooks ??= {});
229
+ for (const [event, entries] of Object.entries(template.hooks ?? {})) {
230
+ // Only `template.hooks` is iterated, so the template's top-level "//" doc key
231
+ // (a sibling of `hooks`, not inside it) is never carried over — excluded
232
+ // structurally, no filtering needed here.
233
+ (hooks[event] ??= []).push(...entries);
234
+ }
235
+ return config;
236
+ }
237
+ /** True iff `codex_hooks = true` is set under [features] in config.toml. */
238
+ function captureFeatureFlagEnabled(config) {
239
+ for (const line of config.split("\n")) {
240
+ // Strip an inline comment, then collapse whitespace, so `codex_hooks = true`
241
+ // (any spacing) matches but a `# codex_hooks = true` comment does not.
242
+ const stripped = (line.split("#", 1)[0] ?? "").trim().replace(/\s+/g, "");
243
+ if (stripped === "codex_hooks=true")
244
+ return true;
245
+ }
246
+ return false;
247
+ }
248
+ /**
249
+ * Wire (or re-wire) the per-turn capture hooks: fetch + copy the adapter scripts,
250
+ * then idempotently merge our entries into ~/.codex/hooks.json. Returns whether
251
+ * the user still needs to enable the `codex_hooks` feature flag (so the caller can
252
+ * surface the hint, mirroring mem0's print_feature_flag_hint).
253
+ */
254
+ async function installCaptureHooks() {
255
+ const integrationDir = await captureFetcher(CODEX_CAPTURE_PINNED_REF);
256
+ const scriptsRoot = codexCaptureDir();
257
+ copyDir(integrationDir, scriptsRoot);
258
+ const template = loadTemplate(integrationDir, scriptsRoot);
259
+ const config = stripOwnedEntries(readHooksFile());
260
+ writeHooksFile(mergeTemplate(config, template));
261
+ return { featureFlagNeeded: !captureFeatureFlagEnabled(readConfig()) };
262
+ }
263
+ /** Remove our capture wiring: strip owned hook entries + delete the scripts dir. */
264
+ function uninstallCaptureHooks() {
265
+ if (fs.existsSync(codexHooksPath())) {
266
+ writeHooksFile(stripOwnedEntries(readHooksFile()));
267
+ }
268
+ fs.rmSync(codexCaptureDir(), { recursive: true, force: true });
269
+ }
109
270
  export const codex = {
110
271
  id: "codex",
111
272
  displayName: "Codex",
@@ -117,32 +278,20 @@ export const codex = {
117
278
  return { installed: true, version };
118
279
  },
119
280
  async install(cfg) {
120
- if (await which(CLI)) {
121
- // Idempotent: if our table is already present, do nothing.
122
- if (hasTable(readConfig()))
123
- return;
124
- const result = await run(CLI, [
125
- "mcp",
126
- "add",
127
- SERVER_ID,
128
- "--url",
129
- cfg.mcpUrl,
130
- "--bearer-token-env-var",
131
- TOKEN_ENV_VAR,
132
- ]);
133
- if (result.code !== 0) {
134
- throw new Error(`codex mcp add failed: ${oneLine(result.stderr || result.stdout)}`);
135
- }
136
- // Stamp our config-shape version alongside the CLI-written table so
137
- // detect can report it (the CLI doesn't write the marker comment).
138
- stampVersionIfMissing();
139
- return;
281
+ // Two independently-idempotent halves: (1) the MCP server table (the tools +
282
+ // primer surface) and (2) the per-turn auto-capture hooks. Both run on every
283
+ // install so a second install repairs either half if only one is present.
284
+ await installMcpTable(cfg);
285
+ const { featureFlagNeeded } = await installCaptureHooks();
286
+ // Codex won't FIRE lifecycle hooks until `codex_hooks = true` is set under
287
+ // [features] in config.toml (mirrors mem0's print_feature_flag_hint). We can't
288
+ // edit a TOML table the user owns safely from here, so we SURFACE the one-time
289
+ // requirement on stderr. Fail-soft: this is a hint, never a hard failure.
290
+ if (featureFlagNeeded) {
291
+ process.stderr.write(`\nCodex auto-capture is wired, but Codex won't run the hooks until you enable the\n` +
292
+ `feature flag. Add this to ${codexConfigPath()}:\n\n` +
293
+ ` [features]\n codex_hooks = true\n\nThen restart Codex.\n`);
140
294
  }
141
- // Fallback: no `codex` on PATH. We can still write the config file.
142
- const config = readConfig();
143
- if (hasTable(config))
144
- return; // idempotent
145
- writeConfig(withTable(config, cfg));
146
295
  },
147
296
  async uninstall() {
148
297
  if (await which(CLI)) {
@@ -155,12 +304,47 @@ export const codex = {
155
304
  if (hasTable(config) || parseConfigVersion(config) !== undefined) {
156
305
  writeConfig(withoutTable(config));
157
306
  }
307
+ // Remove the auto-capture wiring (owned hook entries + the scripts dir).
308
+ uninstallCaptureHooks();
158
309
  },
159
310
  async update(cfg) {
160
311
  // Re-applying is idempotent; install short-circuits when present.
161
312
  await this.install(cfg);
162
313
  },
163
314
  };
315
+ /**
316
+ * Install/repair just the MCP server table — the original Codex wiring. Prefers
317
+ * the native `codex` CLI; falls back to editing config.toml directly when the CLI
318
+ * isn't on PATH. Idempotent (a present table is a no-op).
319
+ */
320
+ async function installMcpTable(cfg) {
321
+ if (await which(CLI)) {
322
+ // Idempotent: if our table is already present, do nothing.
323
+ if (hasTable(readConfig()))
324
+ return;
325
+ const result = await run(CLI, [
326
+ "mcp",
327
+ "add",
328
+ SERVER_ID,
329
+ "--url",
330
+ cfg.mcpUrl,
331
+ "--bearer-token-env-var",
332
+ TOKEN_ENV_VAR,
333
+ ]);
334
+ if (result.code !== 0) {
335
+ throw new Error(`codex mcp add failed: ${oneLine(result.stderr || result.stdout)}`);
336
+ }
337
+ // Stamp our config-shape version alongside the CLI-written table so
338
+ // detect can report it (the CLI doesn't write the marker comment).
339
+ stampVersionIfMissing();
340
+ return;
341
+ }
342
+ // Fallback: no `codex` on PATH. We can still write the config file.
343
+ const config = readConfig();
344
+ if (hasTable(config))
345
+ return; // idempotent
346
+ writeConfig(withTable(config, cfg));
347
+ }
164
348
  /** If the table exists but our version marker doesn't, add the marker. */
165
349
  function stampVersionIfMissing() {
166
350
  const config = readConfig();
@@ -1 +1 @@
1
- {"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/harnesses/codex.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,EAAE;AACF,wEAAwE;AACxE,mEAAmE;AACnE,6DAA6D;AAC7D,EAAE;AACF,2EAA2E;AAC3E,iDAAiD;AACjD,gEAAgE;AAChE,2DAA2D;AAC3D,uEAAuE;AACvE,0CAA0C;AAC1C,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,uEAAuE;AACvE,uDAAuD;AAEvD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAG9C,MAAM,GAAG,GAAG,OAAO,CAAC;AACpB,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAC9C,MAAM,YAAY,GAAG,yBAAyB,CAAC;AAC/C,yEAAyE;AACzE,0DAA0D;AAC1D,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAEtD,uDAAuD;AACvD,SAAS,UAAU;IACjB,IAAI,CAAC;QACH,OAAO,EAAE,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,MAAM,CAAC,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,sEAAsE;AACtE,SAAS,QAAQ,CAAC,MAAc;IAC9B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,YAAY,CAAC,CAAC;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
- export declare const PINNED_REF = "v1.0.0-rc.5";
2
+ export declare const PINNED_REF: string;
3
3
  /**
4
4
  * Fetches the Hermes adapter for a pinned ref and returns the absolute
5
5
  * path to a directory whose contents ARE the adapter (the equivalent of
@@ -1 +1 @@
1
- {"version":3,"file":"hermes.d.ts","sourceRoot":"","sources":["../../src/harnesses/hermes.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AAK/D,eAAO,MAAM,UAAU,gBAAgB,CAAC;AAExC;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAqC9D,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAE5D;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAoDD,eAAO,MAAM,MAAM,EAAE,aA+CpB,CAAC"}
1
+ {"version":3,"file":"hermes.d.ts","sourceRoot":"","sources":["../../src/harnesses/hermes.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AAQ/D,eAAO,MAAM,UAAU,QAAqB,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AA2B9D,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAE5D;AAED,6DAA6D;AAC7D,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAsED,eAAO,MAAM,MAAM,EAAE,aAkDpB,CAAC"}
@@ -5,9 +5,11 @@
5
5
  // - set `memory.provider = librarian` in `~/.hermes/config.json`.
6
6
  //
7
7
  // detect plugin dir present AND provider set to "librarian"
8
- // version comes from the adapter's `plugin.yaml`
8
+ // version is read from the installed `plugin.yaml`, which install
9
+ // stamps with the CLI version (the fetched tag's value is a static
10
+ // placeholder) so status/update can compare installed-vs-latest
9
11
  // uninstall remove the plugin dir + unset the provider key
10
- // update re-fetch + re-copy the adapter (idempotent)
12
+ // update re-fetch + re-copy the adapter, re-stamping the version (idempotent)
11
13
  //
12
14
  // ARTIFACT SOURCING. On a user's machine the adapter does NOT live in the
13
15
  // repo — the CLI must fetch it from a pinned release. We download a tarball
@@ -20,12 +22,16 @@
20
22
  import fs from "node:fs";
21
23
  import os from "node:os";
22
24
  import path from "node:path";
23
- import { run } from "../exec.js";
25
+ import { extractAdapterSubtree } from "../archive.js";
24
26
  import { hermesConfigPath, hermesHomeDir, hermesPluginDir } from "../paths.js";
27
+ import { cliVersion } from "../version.js";
25
28
  const PROVIDER_ID = "librarian";
26
- // The pinned monorepo release we fetch the adapter from. Default to the
27
- // repo's current release tag; the phase gate owns version bumps.
28
- export const PINNED_REF = "v1.0.0-rc.5";
29
+ // The pinned monorepo release we fetch the adapter from: the tag matching this
30
+ // CLI's own version. DERIVED (not hardcoded) so it can't drift — the published
31
+ // package's version is stamped from the root at publish (scripts/stamp-version.mjs),
32
+ // and the matching `vX.Y.Z` tag exists before the package is published. A
33
+ // hardcoded literal here silently froze at rc.5 once before.
34
+ export const PINNED_REF = `v${cliVersion()}`;
29
35
  /** The default fetcher: codeload tarball → `tar` extract → adapter dir. */
30
36
  const defaultFetcher = async (ref) => {
31
37
  const url = `https://codeload.github.com/JimJafar/the-librarian/tar.gz/refs/tags/${ref}`;
@@ -39,24 +45,15 @@ const defaultFetcher = async (ref) => {
39
45
  fs.writeFileSync(tarball, buf);
40
46
  // codeload nests the adapter at
41
47
  // the-librarian-<ref>/integrations/hermes/librarian/**
42
- // — four leading path components. Strip all four so the adapter's own
43
- // files (plugin.yaml, …) land at the extraction root, which is what the
44
- // caller copies into `~/.hermes/plugins/librarian/`.
45
- const out = path.join(work, "adapter");
46
- fs.mkdirSync(out, { recursive: true });
47
- const extract = await run("tar", [
48
- "-xzf",
49
- tarball,
50
- "-C",
51
- out,
52
- "--strip-components=4",
53
- "--wildcards",
54
- "*/integrations/hermes/librarian/*",
55
- ]);
56
- if (extract.code !== 0) {
57
- throw new Error(`Failed to extract Hermes adapter: ${(extract.stderr || "").trim()}`);
48
+ // the returned dir holds its contents (the adapter's own files: plugin.yaml,
49
+ // …), which is what the caller copies into `~/.hermes/plugins/librarian/`.
50
+ try {
51
+ return await extractAdapterSubtree(tarball, work, "integrations/hermes/librarian");
52
+ }
53
+ catch (err) {
54
+ const msg = err instanceof Error ? err.message : String(err);
55
+ throw new Error(`Failed to extract Hermes adapter: ${msg}`);
58
56
  }
59
- return out;
60
57
  };
61
58
  let fetcher = defaultFetcher;
62
59
  /** Override the adapter fetcher (tests inject a local-fixture fetcher). */
@@ -110,6 +107,25 @@ function copyDir(from, to) {
110
107
  fs.mkdirSync(path.dirname(to), { recursive: true });
111
108
  fs.cpSync(from, to, { recursive: true });
112
109
  }
110
+ /**
111
+ * Overwrite the copied plugin.yaml's `version:` with the CLI version, so the
112
+ * INSTALLED adapter reports the version that installed it. The fetched tag's
113
+ * source `version` is a static placeholder; `librarian status`/`update` need the
114
+ * real version to compare installed-vs-latest honestly. Fail-soft: a missing or
115
+ * odd plugin.yaml is left as-is (detect just reports no version).
116
+ */
117
+ function stampAdapterVersion(pluginDir, version) {
118
+ const file = path.join(pluginDir, "plugin.yaml");
119
+ try {
120
+ const raw = fs.readFileSync(file, "utf8");
121
+ const next = raw.replace(/^(\s*version\s*:).*$/m, `$1 ${version}`);
122
+ if (next !== raw)
123
+ fs.writeFileSync(file, next, "utf8");
124
+ }
125
+ catch {
126
+ // no plugin.yaml / unreadable — nothing to stamp.
127
+ }
128
+ }
113
129
  export const hermes = {
114
130
  id: "hermes",
115
131
  displayName: "Hermes",
@@ -126,6 +142,9 @@ export const hermes = {
126
142
  // so re-running is idempotent.
127
143
  const adapterDir = await fetcher(PINNED_REF);
128
144
  copyDir(adapterDir, hermesPluginDir());
145
+ // Stamp the installed plugin.yaml with the CLI version (the fetched tag's
146
+ // source value is a static placeholder) so detect() reports it honestly.
147
+ stampAdapterVersion(hermesPluginDir(), cliVersion());
129
148
  // Set memory.provider = librarian, preserving any other config keys.
130
149
  const config = readHermesConfig() ?? {};
131
150
  const memory = (config.memory && typeof config.memory === "object" ? config.memory : {});