claude-mem 13.4.0 → 13.4.1

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.
@@ -66,7 +66,15 @@ function isPluginDisabledInClaudeSettings() {
66
66
  const settingsPath = join(configDir, 'settings.json');
67
67
  if (!existsSync(settingsPath)) return false;
68
68
  const settings = JSON.parse(readFileSync(settingsPath, 'utf-8'));
69
- return settings?.enabledPlugins?.['claude-mem@thedotmack'] === false;
69
+ // No optional chaining (?.) here: this launcher must parse on the oldest
70
+ // Node that any host might invoke it with. Some Claude Code installs run
71
+ // hooks under a bundled pre-ES2020 Node whose ESM loader throws
72
+ // "SyntaxError: Unexpected token '.'" on `?.` (issue #2791).
73
+ return Boolean(
74
+ settings &&
75
+ settings.enabledPlugins &&
76
+ settings.enabledPlugins['claude-mem@thedotmack'] === false
77
+ );
70
78
  } catch {
71
79
  return false;
72
80
  }
@@ -142,60 +150,74 @@ if (child.stdin) {
142
150
  child.stdin.write(stdinData);
143
151
  child.stdin.end();
144
152
  } else {
145
- // Issue #2188: empty/missing stdin previously masked by `|| '{}'` fallback,
146
- // which silently hid WSL bash failures (e.g. hooks invoked under a broken
147
- // shell that never piped a payload). Surface the failure mode instead.
148
- const dataDir = process.env.CLAUDE_MEM_DATA_DIR || join(homedir(), '.claude-mem');
149
- const payloadType = stdinData === null
150
- ? 'null (no data event or stream error)'
151
- : stdinData === undefined
152
- ? 'undefined'
153
- : Buffer.isBuffer(stdinData) && stdinData.length === 0
154
- ? 'empty Buffer (zero bytes received)'
155
- : `unexpected (${typeof stdinData})`;
156
- const payloadByteLength = (stdinData && typeof stdinData.length === 'number')
157
- ? stdinData.length
158
- : 0;
159
- const diagnostic = [
160
- `[bun-runner] empty stdin payload received — issue #2188`,
161
- ` script: ${args[0]}`,
162
- ` payload byte length: ${payloadByteLength}`,
163
- ` payload type: ${payloadType}`,
164
- ` platform: ${process.platform}`,
165
- ` shell: ${process.env.SHELL || 'n/a'}`,
166
- ` stdin TTY: ${process.stdin.isTTY === true ? 'true' : process.stdin.isTTY === false ? 'false' : 'undefined'}`,
167
- ` timestamp: ${new Date().toISOString()}`,
168
- ` CLAUDE_PLUGIN_ROOT: ${RESOLVED_PLUGIN_ROOT}`,
169
- ].join('\n');
170
-
171
- // IO discipline (see src/shared/hook-io.ts intent vocabulary):
172
- // - this stderr write is a USER_HINT (Claude Code surfaces it inline).
173
- // - the CAPTURE_BROKEN marker file below is a DIAGNOSTIC durable signal for
174
- // the next session-start hint.
175
- // - exit 0 below is the EXIT_SIGNAL per CLAUDE.md (Windows Terminal tab
176
- // management); the marker file, not the exit code, is the durable failure
177
- // signal. bun-runner runs in its own node process BEFORE hookCommand's
178
- // stderr buffer is installed, so this write is never swallowed.
179
- console.error(diagnostic);
180
-
181
- // Persist diagnostic to the runner-errors log and drop a CAPTURE_BROKEN marker
182
- // file so the next session-start hint can surface the failure. We exit 0 to
183
- // honor the project's exit-code strategy (worker/hook errors exit 0 to
184
- // prevent Windows Terminal tab pileup) the marker file is the durable
185
- // signal that something is wrong, not the exit code.
186
- try {
187
- const logsDir = join(dataDir, 'logs');
188
- mkdirSync(logsDir, { recursive: true });
189
- appendFileSync(join(logsDir, 'runner-errors.log'), diagnostic + '\n\n');
190
- mkdirSync(dataDir, { recursive: true });
191
- writeFileSync(join(dataDir, 'CAPTURE_BROKEN'), diagnostic + '\n');
192
- } catch (writeErr) {
193
- console.error(`[bun-runner] failed to persist diagnostic: ${writeErr && writeErr.message ? writeErr.message : writeErr}`);
194
- }
153
+ // Lifecycle subcommands (start, stop, restart, status) never consume stdin
154
+ // they manage the worker daemon, not hook payloads. Killing the child here
155
+ // prevents the daemon from starting/stopping on platforms where Claude Code
156
+ // doesn't pipe a payload for SessionStart (e.g. Windows CC ≤ 2.1.145).
157
+ const lifecycleCommands = ['start', 'stop', 'restart', 'status'];
158
+ const isLifecycle = lifecycleCommands.some(cmd => args.includes(cmd));
159
+
160
+ if (isLifecycle) {
161
+ // Lifecycle commands don't need stdin — close pipe and let child run.
162
+ try { child.stdin.end(); } catch {}
163
+ } else {
164
+ // Issue #2188: empty/missing stdin previously masked by `|| '{}'` fallback,
165
+ // which silently hid WSL bash failures (e.g. hooks invoked under a broken
166
+ // shell that never piped a payload). Surface the failure mode instead.
167
+ const dataDir = process.env.CLAUDE_MEM_DATA_DIR || join(homedir(), '.claude-mem');
168
+ const payloadType = stdinData === null
169
+ ? 'null (no data event or stream error)'
170
+ : stdinData === undefined
171
+ ? 'undefined'
172
+ : Buffer.isBuffer(stdinData) && stdinData.length === 0
173
+ ? 'empty Buffer (zero bytes received)'
174
+ : `unexpected (${typeof stdinData})`;
175
+ const payloadByteLength = (stdinData && typeof stdinData.length === 'number')
176
+ ? stdinData.length
177
+ : 0;
178
+ const diagnostic = [
179
+ `[bun-runner] empty stdin payload received issue #2188`,
180
+ ` script: ${args[0]}`,
181
+ ` payload byte length: ${payloadByteLength}`,
182
+ ` payload type: ${payloadType}`,
183
+ ` platform: ${process.platform}`,
184
+ ` shell: ${process.env.SHELL || 'n/a'}`,
185
+ ` stdin TTY: ${process.stdin.isTTY === true ? 'true' : process.stdin.isTTY === false ? 'false' : 'undefined'}`,
186
+ ` timestamp: ${new Date().toISOString()}`,
187
+ ` CLAUDE_PLUGIN_ROOT: ${RESOLVED_PLUGIN_ROOT}`,
188
+ ].join('\n');
189
+
190
+ // IO discipline (see src/shared/hook-io.ts intent vocabulary):
191
+ // - this stderr write is a USER_HINT (Claude Code surfaces it inline).
192
+ // - the CAPTURE_BROKEN marker file below is a DIAGNOSTIC durable signal for
193
+ // the next session-start hint.
194
+ // - exit 0 below is the EXIT_SIGNAL per CLAUDE.md (Windows Terminal tab
195
+ // management); the marker file, not the exit code, is the durable failure
196
+ // signal. bun-runner runs in its own node process BEFORE hookCommand's
197
+ // stderr buffer is installed, so this write is never swallowed.
198
+
199
+ // Write to stderr so Claude Code surfaces the diagnostic.
200
+ console.error(diagnostic);
201
+
202
+ // Persist diagnostic to the runner-errors log and drop a CAPTURE_BROKEN marker
203
+ // file so the next session-start hint can surface the failure. We exit 0 to
204
+ // honor the project's exit-code strategy (worker/hook errors exit 0 to
205
+ // prevent Windows Terminal tab pileup) — the marker file is the durable
206
+ // signal that something is wrong, not the exit code.
207
+ try {
208
+ const logsDir = join(dataDir, 'logs');
209
+ mkdirSync(logsDir, { recursive: true });
210
+ appendFileSync(join(logsDir, 'runner-errors.log'), diagnostic + '\n\n');
211
+ mkdirSync(dataDir, { recursive: true });
212
+ writeFileSync(join(dataDir, 'CAPTURE_BROKEN'), diagnostic + '\n');
213
+ } catch (writeErr) {
214
+ console.error(`[bun-runner] failed to persist diagnostic: ${writeErr && writeErr.message ? writeErr.message : writeErr}`);
215
+ }
195
216
 
196
- try { child.stdin.end(); } catch {}
197
- try { child.kill(); } catch {}
198
- process.exit(0);
217
+ try { child.stdin.end(); } catch {}
218
+ try { child.kill(); } catch {}
219
+ process.exit(0);
220
+ }
199
221
  }
200
222
  }
201
223