claude-db 0.10.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.3
4
+
5
+ ### Fixed
6
+
7
+ - **Picks and facts can now find Claude when `claude` is not on `PATH`.** Both call
8
+ Claude through its binary. Claude Code does not pass that path to its hooks, so
9
+ on a machine where `claude` is not on `PATH`, for example when Claude Code runs
10
+ inside an editor, every call failed with `claude was not found`, and the feature
11
+ paused. Each hook now looks up the Claude process that started it and saves
12
+ its path in `~/.claude-memory/claude-binary`. Background jobs and commands run
13
+ in a terminal use that path when `CLAUDE_CODE_EXECPATH` is not set. A saved path
14
+ that no longer exists, for example after an editor update, is replaced by the
15
+ next hook run. Linux and macOS only.
16
+
3
17
  ## 0.10.2
4
18
 
5
19
  ### Changed
@@ -1,3 +1,4 @@
1
+ import { rememberClaudeBinary } from '../util/claude-binary.js';
1
2
  export function capturingDisabled(scripted) {
2
3
  if (process.env['CLAUDE_DB_CAPTURE'] === 'off')
3
4
  return true;
@@ -19,6 +20,7 @@ export async function readPayload() {
19
20
  }
20
21
  export async function runHook(fn) {
21
22
  try {
23
+ rememberClaudeBinary();
22
24
  await fn();
23
25
  }
24
26
  catch (error) {
@@ -0,0 +1,9 @@
1
+ export interface ProcessInfo {
2
+ parent: number;
3
+ exe: string;
4
+ }
5
+ export type InspectProcess = (pid: number) => ProcessInfo | null;
6
+ export declare function findClaudeAncestor(start?: number, inspect?: InspectProcess): string | null;
7
+ export declare function rememberedBinary(file?: string): string | null;
8
+ export declare function rememberClaudeBinary(env?: NodeJS.ProcessEnv, file?: string, find?: () => string | null): void;
9
+ export declare function claudeBinary(env?: NodeJS.ProcessEnv, remembered?: () => string | null): string;
@@ -0,0 +1,74 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import { mkdirSync, readFileSync, readlinkSync, statSync, writeFileSync } from 'node:fs';
3
+ import { basename, join } from 'node:path';
4
+ import { CONFIG_DIR } from '../config/dir.js';
5
+ const REMEMBERED_FILE = join(CONFIG_DIR, 'claude-binary');
6
+ const MAX_ANCESTORS = 8;
7
+ function inspectOnLinux(pid) {
8
+ try {
9
+ const exe = readlinkSync(`/proc/${pid}/exe`);
10
+ const stat = readFileSync(`/proc/${pid}/stat`, 'utf8');
11
+ const parent = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]);
12
+ return Number.isInteger(parent) ? { parent, exe } : null;
13
+ }
14
+ catch {
15
+ return null;
16
+ }
17
+ }
18
+ function inspectWithPs(pid) {
19
+ try {
20
+ const line = execFileSync('ps', ['-o', 'ppid=,comm=', '-p', String(pid)], {
21
+ encoding: 'utf8',
22
+ stdio: ['ignore', 'pipe', 'ignore'],
23
+ timeout: 1000,
24
+ }).trim();
25
+ const match = /^(\d+)\s+(.+)$/.exec(line);
26
+ return match?.[1] && match[2] ? { parent: Number(match[1]), exe: match[2] } : null;
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ }
32
+ function inspectProcess(pid) {
33
+ if (process.platform === 'win32')
34
+ return null;
35
+ return process.platform === 'linux' ? inspectOnLinux(pid) : inspectWithPs(pid);
36
+ }
37
+ function isClaude(exe) {
38
+ return basename(exe) === 'claude';
39
+ }
40
+ export function findClaudeAncestor(start = process.ppid, inspect = inspectProcess) {
41
+ let pid = start;
42
+ for (let depth = 0; depth < MAX_ANCESTORS && pid > 1; depth++) {
43
+ const info = inspect(pid);
44
+ if (!info)
45
+ return null;
46
+ if (isClaude(info.exe))
47
+ return info.exe;
48
+ pid = info.parent;
49
+ }
50
+ return null;
51
+ }
52
+ export function rememberedBinary(file = REMEMBERED_FILE) {
53
+ try {
54
+ const path = readFileSync(file, 'utf8').trim();
55
+ return path !== '' && statSync(path, { throwIfNoEntry: false })?.isFile() ? path : null;
56
+ }
57
+ catch {
58
+ return null;
59
+ }
60
+ }
61
+ export function rememberClaudeBinary(env = process.env, file = REMEMBERED_FILE, find = findClaudeAncestor) {
62
+ const known = rememberedBinary(file);
63
+ const path = env['CLAUDE_CODE_EXECPATH'] || (known === null ? find() : null);
64
+ if (!path || path === known)
65
+ return;
66
+ try {
67
+ mkdirSync(CONFIG_DIR, { recursive: true });
68
+ writeFileSync(file, `${path}\n`, 'utf8');
69
+ }
70
+ catch { }
71
+ }
72
+ export function claudeBinary(env = process.env, remembered = rememberedBinary) {
73
+ return env['CLAUDE_CODE_EXECPATH'] || remembered() || 'claude';
74
+ }
@@ -9,7 +9,6 @@ export type HeadlessResult = {
9
9
  ok: false;
10
10
  reason: string;
11
11
  };
12
- export declare function claudeBinary(env?: NodeJS.ProcessEnv): string;
13
12
  export declare function runHeadlessResult(prompt: string, model: string, timeoutMs: number, options?: HeadlessOptions): Promise<HeadlessResult>;
14
13
  export declare function runHeadless(prompt: string, model: string, timeoutMs: number, options?: HeadlessOptions): Promise<string | null>;
15
14
  export declare function describeFailure(error: unknown, stderr: string, timeoutMs: number): string;
@@ -1,4 +1,5 @@
1
1
  import { execFile } from 'node:child_process';
2
+ import { claudeBinary } from './claude-binary.js';
2
3
  const MAX_BUFFER = 1024 * 1024;
3
4
  const REASON_CHARS = 120;
4
5
  const OPTIONAL_FLAGS = [
@@ -6,9 +7,6 @@ const OPTIONAL_FLAGS = [
6
7
  ['--no-session-persistence'],
7
8
  ];
8
9
  const UNKNOWN_OPTION = /unknown option '(--[\w-]+)'/i;
9
- export function claudeBinary(env = process.env) {
10
- return env['CLAUDE_CODE_EXECPATH'] || 'claude';
11
- }
12
10
  export async function runHeadlessResult(prompt, model, timeoutMs, options = {}) {
13
11
  let optional = [...OPTIONAL_FLAGS, ...(options.flags ?? [])];
14
12
  for (;;) {
@@ -29,7 +27,7 @@ export async function runHeadless(prompt, model, timeoutMs, options = {}) {
29
27
  export function describeFailure(error, stderr, timeoutMs) {
30
28
  const failure = typeof error === 'object' && error !== null ? error : {};
31
29
  if (failure.code === 'ENOENT') {
32
- return 'claude was not found: set CLAUDE_CODE_EXECPATH or put it on PATH';
30
+ return 'claude was not found: put it on PATH, or set CLAUDE_CODE_EXECPATH';
33
31
  }
34
32
  if (failure.code === 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER') {
35
33
  return 'the reply was larger than the 1 MB buffer';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-db",
3
- "version": "0.10.2",
3
+ "version": "0.10.3",
4
4
  "description": "Persistent memory for Claude Code. Captures why decisions were made, not just which files changed. Bring your own database: SQLite, MongoDB or Postgres. No cloud, no subscription.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",