@snoai/mem-claude 1.7.1 → 1.7.2

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/README.md CHANGED
@@ -29,7 +29,7 @@ start of every session.
29
29
  2. Install the plugin (Node.js 22.22.3+, 24.15.0+ or 25.9.0+, and `git`):
30
30
 
31
31
  ```bash
32
- sh -c 'sno_installer_body=$(curl -fsSL https://sno.ai/install) && printf "%s\n" "$sno_installer_body" | sh'
32
+ curl -fsSL https://sno.ai/install | sh
33
33
  ```
34
34
 
35
35
  3. Open a new Claude Code session inside a git repository, then try it:
package/dist/worker.d.ts CHANGED
@@ -37,7 +37,7 @@ export interface WorkerDependencies {
37
37
  reason: string;
38
38
  } | {
39
39
  kind: "error";
40
- category: "transport";
40
+ category: "transport" | "auth" | "exhausted";
41
41
  message: string;
42
42
  }>;
43
43
  now?(): number;
@@ -58,9 +58,10 @@ export declare function runClaudeChild(prompt: string, cwd: string, timeoutMs?:
58
58
  reason: string;
59
59
  } | {
60
60
  kind: "error";
61
- category: "transport";
61
+ category: "transport" | "auth" | "exhausted";
62
62
  message: string;
63
63
  }>;
64
+ export declare function claudeChildResult(status: number | null, stdout: string, stderr: string, cwd?: string): Awaited<ReturnType<WorkerDependencies["runChild"]>>;
64
65
  type SpoolEntry = {
65
66
  path: string;
66
67
  record: z.infer<typeof spoolSchema>;
package/dist/worker.js CHANGED
@@ -71,25 +71,35 @@ export async function runClaudeChild(prompt, cwd, timeoutMs = CODING_SKIN_CHILD_
71
71
  });
72
72
  if (result.error && "code" in result.error && result.error.code === "ETIMEDOUT")
73
73
  return { kind: "cancelled", reason: "deadline" };
74
- if (result.status !== 0)
75
- return { kind: "error", category: "transport", message: `claude-exit-${result.status ?? "signal"}` };
74
+ return claudeChildResult(result.status, result.stdout ?? "", result.stderr ?? "", cwd);
75
+ }
76
+ export function claudeChildResult(status, stdout, stderr, cwd) {
76
77
  let output;
77
78
  try {
78
- output = JSON.parse(result.stdout);
79
+ output = JSON.parse(stdout);
79
80
  }
80
81
  catch {
81
- return { kind: "error", category: "transport", message: "invalid-json" };
82
+ output = undefined;
82
83
  }
83
84
  const parsed = z.object({
84
85
  result: z.string().optional(),
85
86
  is_error: z.boolean(),
86
87
  usage: z.object({ cache_creation_input_tokens: z.number().optional(), cache_read_input_tokens: z.number().optional(), input_tokens: z.number().optional(), output_tokens: z.number().optional() }).optional(),
87
88
  }).safeParse(output);
89
+ if (status === 0 && parsed.success && cwd !== undefined)
90
+ console.log(JSON.stringify({ event: "claude-child", cwd, usage: parsed.data.usage, claudeCodeUnset: true }));
91
+ if (status !== 0 || (parsed.success && parsed.data.is_error)) {
92
+ const failure = `${parsed.success ? parsed.data.result ?? "" : stdout}\n${stderr}`;
93
+ if (/\b401\b|unauthori[sz]ed|invalid x-api-key|authentication_error|not logged in|run \/login|authentication required|authentication failed|invalid (?:api key|auth token)|oauth token (?:expired|revoked)|login expired/i.test(failure))
94
+ return { kind: "error", category: "auth", message: "Claude login unavailable" };
95
+ if (/you['’]ve (?:hit|reached) your|usage limit reached|out of (?:extra usage|usage credits)|credit balance.{0,20}too low/i.test(failure))
96
+ return { kind: "error", category: "exhausted", message: "Claude usage limit reached" };
97
+ return { kind: "error", category: "transport", message: status !== 0 ? `claude-exit-${status ?? "signal"}` : "claude-is-error" };
98
+ }
99
+ if (output === undefined)
100
+ return { kind: "error", category: "transport", message: "invalid-json" };
88
101
  if (!parsed.success)
89
102
  return { kind: "error", category: "transport", message: "invalid-result" };
90
- console.log(JSON.stringify({ event: "claude-child", cwd, usage: parsed.data.usage, claudeCodeUnset: true }));
91
- if (parsed.data.is_error)
92
- return { kind: "error", category: "transport", message: "claude-is-error" };
93
103
  const text = parsed.data.result?.trim();
94
104
  if (!text)
95
105
  return { kind: "error", category: "transport", message: "empty-output" };
@@ -298,9 +308,15 @@ export async function runWorker(dependencies = productionDependencies()) {
298
308
  let currentImport = false;
299
309
  let server;
300
310
  let handoff = false;
311
+ let modelUnavailable = false;
301
312
  try {
302
313
  mkdirSync(childCwd, { recursive: true, mode: 0o700 });
303
- const callback = await callbackServer(credential, () => currentCwd ?? childCwd, () => currentImport, () => { lastCallbackAt = now(); }, (prompt, cwd, requesterMs) => dependencies.runChild(prompt, cwd, Math.min(CODING_SKIN_CHILD_DEADLINE_MS, requesterMs ?? Infinity)));
314
+ const callback = await callbackServer(credential, () => currentCwd ?? childCwd, () => currentImport, () => { lastCallbackAt = now(); }, async (prompt, cwd, requesterMs) => {
315
+ const result = await dependencies.runChild(prompt, cwd, Math.min(CODING_SKIN_CHILD_DEADLINE_MS, requesterMs ?? Infinity));
316
+ if (result.kind === "error" && (result.category === "auth" || result.category === "exhausted"))
317
+ modelUnavailable = true;
318
+ return result;
319
+ });
304
320
  server = callback.server;
305
321
  await readSpoolNames();
306
322
  const client = await dependencies.connect();
@@ -337,6 +353,7 @@ export async function runWorker(dependencies = productionDependencies()) {
337
353
  }
338
354
  currentCwd = childCwd;
339
355
  currentImport = record.kind === "import";
356
+ modelUnavailable = false;
340
357
  try {
341
358
  const messages = batch.flatMap(({ record: turn }) => turn.kind === "import"
342
359
  ? [{ role: "user", content: turn.user, at: turn.at }]
@@ -347,6 +364,8 @@ export async function runWorker(dependencies = productionDependencies()) {
347
364
  // A capture in flight is never abandoned for the lifetime: the sidecar would go on extracting it while this
348
365
  // worker's model callback is gone. Its route deadline bounds it, and the lifetime is checked before the next one.
349
366
  const result = await client.capture({ turnId: record.turnId, rewindEpoch: 0, messages }, { principal, project: record.project, session: record.sessionId, host: { sessionId: record.sessionId, workspace: record.project } });
367
+ if (modelUnavailable)
368
+ throw new Error("host model unavailable");
350
369
  if (result.degraded)
351
370
  throw new Error(result.reason);
352
371
  if (!result.committed && !result.accepted && !result.skipped && !result.partial)
@@ -360,6 +379,10 @@ export async function runWorker(dependencies = productionDependencies()) {
360
379
  break;
361
380
  }
362
381
  catch (error) {
382
+ if (modelUnavailable) {
383
+ console.log(JSON.stringify({ event: "capture-deferred", turnId: record.turnId, reason: "host-model-unavailable" }));
384
+ return "failed";
385
+ }
363
386
  for (const entry of batch)
364
387
  await updateImportReceipt(entry.record.importReceipt, "failures");
365
388
  const attempts = record.attempts + 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snoai/mem-claude",
3
- "version": "1.7.1",
3
+ "version": "1.7.2",
4
4
  "license": "Apache-2.0",
5
5
  "publishConfig": { "access": "public" },
6
6
  "repository": {