@snoai/mem-claude 2.0.2 → 2.1.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.
- package/dist/cli.js +2 -2
- package/dist/doctor.js +19 -1
- package/dist/explicit.d.ts +1 -0
- package/dist/explicit.js +5 -0
- package/dist/hooks.js +8 -4
- package/dist/session-state.d.ts +1 -0
- package/dist/session-state.js +1 -0
- package/dist/worker.js +23 -18
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import { isAbsolute, join } from "node:path";
|
|
4
4
|
import { composeContinuityContext, observeAgentEvent, refreshContinuityBrief, renderAgentStatusLine } from "@snoai/memory/coding-skin";
|
|
5
5
|
import { doctor } from "./doctor.js";
|
|
6
|
-
import { correctCommand, getCommand, recallCommand, rememberCommand } from "./explicit.js";
|
|
6
|
+
import { correctCommand, getCommand, recallCommand, rememberCommand, undoCommand } from "./explicit.js";
|
|
7
7
|
import { postToolUse, preToolUse, sessionEnd, sessionStart, stop, userPromptSubmit } from "./hooks.js";
|
|
8
8
|
import { installClaude, uninstallClaude } from "./install.js";
|
|
9
9
|
import { importRepository } from "./import.js";
|
|
@@ -135,7 +135,7 @@ async function main() {
|
|
|
135
135
|
return result.ok ? 0 : 1;
|
|
136
136
|
}
|
|
137
137
|
if (command === "correct") {
|
|
138
|
-
const result = await correctCommand(args[0] ?? "", args.slice(1).join(" "));
|
|
138
|
+
const result = args[0] === "--undo" ? await undoCommand(args[1] ?? "") : await correctCommand(args[0] ?? "", args.slice(1).join(" "));
|
|
139
139
|
process.stdout.write(`${result.text}\n`);
|
|
140
140
|
return result.ok ? 0 : 1;
|
|
141
141
|
}
|
package/dist/doctor.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { connectMemory, isDegradedConnection } from "./memory-client.js";
|
|
2
|
+
import { manualScope, workspaceRoot } from "./scope.js";
|
|
1
3
|
import { readFile, readdir } from "node:fs/promises";
|
|
2
4
|
import { join } from "node:path";
|
|
3
5
|
import { CODING_SKIN_HOOKS } from "@snoai/memory/coding-skin";
|
|
@@ -56,10 +58,26 @@ export async function doctor(configDir) {
|
|
|
56
58
|
let permission = "unparsable";
|
|
57
59
|
if (settings)
|
|
58
60
|
permission = settings.permissions?.allow?.some(isOwnedPermissionRule) ? "present" : "absent";
|
|
59
|
-
|
|
61
|
+
const lines = [
|
|
60
62
|
`sidecar: ${await sidecarStatus()}`,
|
|
61
63
|
`hooks: ${hooks}`,
|
|
62
64
|
`permission rule: ${permission}`,
|
|
63
65
|
`import receipts: ${await importSummary()}`,
|
|
64
66
|
];
|
|
67
|
+
try {
|
|
68
|
+
const client = await connectMemory();
|
|
69
|
+
if (isDegradedConnection(client))
|
|
70
|
+
lines.push(`precision: ${client.error ?? client.reason}`);
|
|
71
|
+
else {
|
|
72
|
+
const inspected = await client.inspect({ op: "precision" }, manualScope(await workspaceRoot(process.cwd())));
|
|
73
|
+
if (inspected.degraded)
|
|
74
|
+
lines.push(`precision: ${inspected.error ?? inspected.reason}`);
|
|
75
|
+
else if (inspected.result.op === "precision")
|
|
76
|
+
lines.push(...inspected.result.lines);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
lines.push(`precision: ${String(error)}`);
|
|
81
|
+
}
|
|
82
|
+
return lines;
|
|
65
83
|
}
|
package/dist/explicit.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export declare function recallCommand(query: string): Promise<CommandResult>;
|
|
|
6
6
|
export declare function getCommand(id: string): Promise<CommandResult>;
|
|
7
7
|
export declare function rememberCommand(content: string): Promise<CommandResult>;
|
|
8
8
|
export declare function correctCommand(id: string, content: string): Promise<CommandResult>;
|
|
9
|
+
export declare function undoCommand(id: string): Promise<CommandResult>;
|
package/dist/explicit.js
CHANGED
|
@@ -85,3 +85,8 @@ export async function correctCommand(id, content) {
|
|
|
85
85
|
return { ok: false, text: "invalid-input" };
|
|
86
86
|
return mutateCommand({ op: "correct", id, content });
|
|
87
87
|
}
|
|
88
|
+
export async function undoCommand(id) {
|
|
89
|
+
if (!id.trim())
|
|
90
|
+
return { ok: false, text: "invalid-input" };
|
|
91
|
+
return mutateCommand({ op: "undo", id });
|
|
92
|
+
}
|
package/dist/hooks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { performance } from "node:perf_hooks";
|
|
2
2
|
import { getSnoProfileDir } from "@snoai/observability";
|
|
3
|
-
import { appendObserveLedgerRows, CODING_SKIN_SESSION_QUERY, } from "@snoai/memory/coding-skin";
|
|
3
|
+
import { appendObserveLedgerRows, CODING_SKIN_SESSION_QUERY, loadedFilesAtStart, } from "@snoai/memory/coding-skin";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { readCaptureSettings, readRecallSettings } from "./settings.js";
|
|
6
6
|
import { ContractError } from "@snoai/memory/client";
|
|
@@ -114,7 +114,7 @@ export async function sessionStart(raw) {
|
|
|
114
114
|
if (!recall.auto)
|
|
115
115
|
return emptyEnvelope("SessionStart");
|
|
116
116
|
recordLookup(state, "SessionStart");
|
|
117
|
-
const recalled = await withinDeadline(client.getRecall(CODING_SKIN_SESSION_QUERY, hookScope(project, input.session_id), { source: "auto", injectionPhase: "session-start", limit: recall.sessionStart.limit, maxChars: recall.sessionStart.maxChars }), Math.max(1, recall.sessionStart.timeoutMs - (performance.now() - started)));
|
|
117
|
+
const recalled = await withinDeadline(client.getRecall(CODING_SKIN_SESSION_QUERY, hookScope(project, input.session_id), { source: "auto", injectionPhase: "session-start", loadedFiles: loadedFilesAtStart("claude-code", input.cwd, project), limit: recall.sessionStart.limit, maxChars: recall.sessionStart.maxChars }), Math.max(1, recall.sessionStart.timeoutMs - (performance.now() - started)));
|
|
118
118
|
if (recalled.degraded)
|
|
119
119
|
recordDegraded(state, "SessionStart", recalled.error ?? recalled.reason);
|
|
120
120
|
else if (recalled.unavailable)
|
|
@@ -154,6 +154,7 @@ export async function userPromptSubmit(raw) {
|
|
|
154
154
|
}
|
|
155
155
|
const project = await workspaceRoot(input.cwd);
|
|
156
156
|
const state = await readSession(input.session_id);
|
|
157
|
+
state.oneshot ??= input.prompt.startsWith("[sno-oneshot]");
|
|
157
158
|
state.prompts[input.prompt_id] = { prompt: input.prompt, at: Date.now() };
|
|
158
159
|
await writeSession(state);
|
|
159
160
|
const client = await withinDeadline(connectMemory(), Math.max(1, recall.prompt.timeoutMs - (performance.now() - started)));
|
|
@@ -167,7 +168,7 @@ export async function userPromptSubmit(raw) {
|
|
|
167
168
|
if (!recall.auto)
|
|
168
169
|
return emptyEnvelope("UserPromptSubmit");
|
|
169
170
|
recordLookup(state, "UserPromptSubmit");
|
|
170
|
-
const recalled = await withinDeadline(client.getRecall(input.prompt, hookScope(project, input.session_id), { source: "auto", injectionPhase: "prompt", limit: recall.prompt.limit, minScore: recall.prompt.minScore, maxChars: recall.prompt.maxChars }), Math.max(1, recall.prompt.timeoutMs - (performance.now() - started)));
|
|
171
|
+
const recalled = await withinDeadline(client.getRecall(input.prompt, hookScope(project, input.session_id), { source: "auto", injectionPhase: "prompt", loadedFiles: loadedFilesAtStart("claude-code", input.cwd, project), limit: recall.prompt.limit, minScore: recall.prompt.minScore, maxChars: recall.prompt.maxChars }), Math.max(1, recall.prompt.timeoutMs - (performance.now() - started)));
|
|
171
172
|
if (recalled.degraded)
|
|
172
173
|
recordDegraded(state, "UserPromptSubmit", recalled.error ?? recalled.reason);
|
|
173
174
|
else if (recalled.unavailable)
|
|
@@ -229,7 +230,10 @@ export async function stop(raw) {
|
|
|
229
230
|
const state = await readSession(input.session_id);
|
|
230
231
|
const prompt = state.prompts[input.prompt_id]?.prompt.trim() ?? "";
|
|
231
232
|
const assistant = input.last_assistant_message.trim();
|
|
232
|
-
if (
|
|
233
|
+
if (state.oneshot) {
|
|
234
|
+
recordSkip(state, "Stop", "[sno-oneshot]");
|
|
235
|
+
}
|
|
236
|
+
else if (!prompt || !assistant) {
|
|
233
237
|
recordSkip(state, "Stop", "empty-turn");
|
|
234
238
|
}
|
|
235
239
|
else {
|
package/dist/session-state.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare function readLastSession(project: string): Promise<z.infer<typeof
|
|
|
7
7
|
export declare function writeLastSession(project: string, sessionId: string, transcriptPath: string): Promise<void>;
|
|
8
8
|
declare const sessionStateSchema: z.ZodObject<{
|
|
9
9
|
sessionId: z.ZodString;
|
|
10
|
+
oneshot: z.ZodOptional<z.ZodBoolean>;
|
|
10
11
|
skillRunsReported: z.ZodDefault<z.ZodNumber>;
|
|
11
12
|
activity: z.ZodOptional<z.ZodType<import("@snoai/memory/coding-skin").ActivityCursor, unknown, z.core.$ZodTypeInternals<import("@snoai/memory/coding-skin").ActivityCursor, unknown>>>;
|
|
12
13
|
prompts: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
package/dist/session-state.js
CHANGED
|
@@ -35,6 +35,7 @@ const receiptEventSchema = z.object({
|
|
|
35
35
|
});
|
|
36
36
|
const sessionStateSchema = z.object({
|
|
37
37
|
sessionId: z.string().min(1),
|
|
38
|
+
oneshot: z.boolean().optional(),
|
|
38
39
|
skillRunsReported: z.number().int().nonnegative().default(0),
|
|
39
40
|
/** Where the previous session.activity send stopped in the transcript. */
|
|
40
41
|
activity: activityCursorSchema.optional(),
|
package/dist/worker.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { execFile, spawn } from "node:child_process";
|
|
3
3
|
import { closeSync, mkdirSync, openSync } from "node:fs";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
import { userInfo } from "node:os";
|
|
6
6
|
import { readFile, readdir, rm } from "node:fs/promises";
|
|
7
7
|
import { basename, join } from "node:path";
|
|
8
|
-
import { CODING_SKIN_CAPTURE_MAX_INPUT_TOKENS, CODING_SKIN_CAPTURE_QUIET_MS, CODING_SKIN_CHILD_DEADLINE_MS, CODING_SKIN_CHILD_MAX_BUFFER_BYTES, CODING_SKIN_IMPORT_INTERVAL_MS, CODING_SKIN_MAX_ATTEMPTS, CODING_SKIN_MAX_PENDING_CAPTURES, CODING_SKIN_RETRY_DELAYS_MS, CODING_SKIN_WORKER_LIFETIME_MS, HOST_MODEL_CALLBACK_HOST, HOST_MODEL_CALLBACK_PATH, HOST_MODEL_DEADLINE_HEADER, } from "@snoai/memory/coding-skin";
|
|
8
|
+
import { CODING_SKIN_CAPTURE_MAX_INPUT_TOKENS, CODING_SKIN_CAPTURE_QUIET_MS, CODING_SKIN_CHILD_DEADLINE_MS, CODING_SKIN_CHILD_MAX_BUFFER_BYTES, CODING_SKIN_IMPORT_INTERVAL_MS, CODING_SKIN_MAX_ATTEMPTS, CODING_SKIN_MAX_PENDING_CAPTURES, CODING_SKIN_RETRY_DELAYS_MS, CODING_SKIN_WORKER_LIFETIME_MS, HOST_MODEL_CONCURRENCY, HOST_MODEL_CALLBACK_HOST, HOST_MODEL_CALLBACK_PATH, HOST_MODEL_DEADLINE_HEADER, writeHostWorkerRecord, } from "@snoai/memory/coding-skin";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { MODEL_ID, SKIN_ID } from "./constants.js";
|
|
11
11
|
import { acquirePidFileLock, writeJsonAtomic } from "./files.js";
|
|
@@ -60,18 +60,22 @@ export async function runClaudeChild(prompt, cwd, timeoutMs = CODING_SKIN_CHILD_
|
|
|
60
60
|
const env = { ...process.env };
|
|
61
61
|
env["GIT_CEILING_DIRECTORIES"] = appStateRoot();
|
|
62
62
|
delete env["CLAUDECODE"];
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
63
|
+
return new Promise(resolve => {
|
|
64
|
+
const child = execFile("claude", ["-p", "--output-format", "json", "--max-turns", "1", "--setting-sources", "", "--settings", '{"disableAllHooks":true}', "--no-session-persistence", "--permission-mode", "dontAsk", "--tools", ""], {
|
|
65
|
+
cwd, env, encoding: "utf8", timeout: timeoutMs, killSignal: "SIGKILL", maxBuffer: CODING_SKIN_CHILD_MAX_BUFFER_BYTES,
|
|
66
|
+
}, (error, stdout, stderr) => {
|
|
67
|
+
if (error?.killed && error.code !== "ERR_CHILD_PROCESS_STDIO_MAXBUFFER") {
|
|
68
|
+
resolve({ kind: "cancelled", reason: "deadline" });
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
let status = 0;
|
|
72
|
+
if (error)
|
|
73
|
+
status = typeof error.code === "number" ? error.code : null;
|
|
74
|
+
resolve(claudeChildResult(status, stdout, stderr, cwd));
|
|
75
|
+
});
|
|
76
|
+
child.stdin?.on("error", () => { });
|
|
77
|
+
child.stdin?.end(prompt);
|
|
71
78
|
});
|
|
72
|
-
if (result.error && "code" in result.error && result.error.code === "ETIMEDOUT")
|
|
73
|
-
return { kind: "cancelled", reason: "deadline" };
|
|
74
|
-
return claudeChildResult(result.status, result.stdout ?? "", result.stderr ?? "", cwd);
|
|
75
79
|
}
|
|
76
80
|
export function claudeChildResult(status, stdout, stderr, cwd) {
|
|
77
81
|
let output;
|
|
@@ -116,10 +120,12 @@ function promptFromMessages(value) {
|
|
|
116
120
|
return { model: parsed.data.model, prompt: parsed.data.messages.map(message => `${message.role}: ${message.content}`).join("\n\n") };
|
|
117
121
|
}
|
|
118
122
|
async function callbackServer(credential, activeCwd, isImport, onCall, runChild) {
|
|
119
|
-
|
|
123
|
+
const lanes = Array.from({ length: HOST_MODEL_CONCURRENCY }, () => Promise.resolve());
|
|
124
|
+
let nextLane = 0;
|
|
120
125
|
let lastImportChildAt = 0;
|
|
121
126
|
const server = createServer((request, response) => {
|
|
122
|
-
|
|
127
|
+
const lane = isImport() ? 0 : nextLane++ % lanes.length;
|
|
128
|
+
lanes[lane] = (lanes[lane] ?? Promise.resolve()).then(async () => {
|
|
123
129
|
if (request.method !== "POST" || request.url !== HOST_MODEL_CALLBACK_PATH) {
|
|
124
130
|
response.writeHead(404).end();
|
|
125
131
|
return;
|
|
@@ -146,8 +152,7 @@ async function callbackServer(credential, activeCwd, isImport, onCall, runChild)
|
|
|
146
152
|
return;
|
|
147
153
|
}
|
|
148
154
|
onCall();
|
|
149
|
-
//
|
|
150
|
-
// this call's turn: skip it instead of spending a model run on an answer nobody reads.
|
|
155
|
+
// A requester may have stopped waiting while all child slots were occupied.
|
|
151
156
|
const deadline = Number(request.headers[HOST_MODEL_DEADLINE_HEADER]);
|
|
152
157
|
if (Number.isFinite(deadline) && deadline <= Date.now()) {
|
|
153
158
|
console.log(JSON.stringify({ event: "model-callback-expired", model: requestBody.model }));
|
|
@@ -324,6 +329,7 @@ export async function runWorker(dependencies = productionDependencies()) {
|
|
|
324
329
|
await client.init({ principal, project: "global", session: "claude-worker", host: { sessionId: "claude-worker" } }, {
|
|
325
330
|
skinId: SKIN_ID, model: { baseUrl: callback.baseUrl, credential, model: MODEL_ID },
|
|
326
331
|
});
|
|
332
|
+
await writeHostWorkerRecord(profileRoot());
|
|
327
333
|
console.log(JSON.stringify({ event: "worker-registered" }));
|
|
328
334
|
while (true) {
|
|
329
335
|
const entries = await readSpoolEntries();
|
|
@@ -435,7 +441,6 @@ export async function runWorker(dependencies = productionDependencies()) {
|
|
|
435
441
|
}
|
|
436
442
|
finally {
|
|
437
443
|
if (server) {
|
|
438
|
-
server.closeAllConnections();
|
|
439
444
|
await new Promise(resolve => server?.close(() => resolve()));
|
|
440
445
|
}
|
|
441
446
|
if (handoff)
|