@vellumai/assistant 0.10.3-dev.202606262135.fc770c1 → 0.10.3-dev.202606262332.2a738b0
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/package.json +1 -1
- package/src/__tests__/config-loader-backfill.test.ts +1 -0
- package/src/__tests__/plugin-disabled-state.test.ts +32 -0
- package/src/api/events/acp-session-completed.ts +2 -3
- package/src/api/events/acp-session-error.ts +2 -3
- package/src/api/events/acp-session-spawned.ts +2 -3
- package/src/api/events/acp-session-update.ts +2 -3
- package/src/api/events/acp-session-usage.ts +2 -3
- package/src/cli/commands/__tests__/ps.test.ts +205 -0
- package/src/cli/commands/memory/__tests__/worker.test.ts +6 -3
- package/src/cli/commands/memory/worker.ts +4 -1
- package/src/cli/commands/ps.ts +89 -0
- package/src/cli/program.ts +2 -0
- package/src/memory/__tests__/worker-control.test.ts +216 -0
- package/src/memory/jobs-worker.ts +4 -1
- package/src/memory/schema/acp.ts +2 -2
- package/src/memory/worker-control.ts +111 -13
- package/src/messaging/providers/slack/render.test.ts +13 -12
- package/src/messaging/providers/slack/render.ts +34 -122
- package/src/messaging/providers/slack/send.test.ts +39 -0
- package/src/messaging/providers/slack/send.ts +35 -15
- package/src/providers/__tests__/retry-callsite.test.ts +30 -2
- package/src/providers/retry.ts +16 -0
- package/src/tools/registry.ts +11 -1
package/package.json
CHANGED
|
@@ -854,6 +854,7 @@ describe("loadConfig startup behavior", () => {
|
|
|
854
854
|
expect(raw.llm.profiles.balanced.model).toBe(
|
|
855
855
|
"accounts/fireworks/models/glm-5p2",
|
|
856
856
|
);
|
|
857
|
+
expect(raw.llm.profiles.balanced.effort).toBe("high");
|
|
857
858
|
expect(raw.llm.profiles.balanced.source).toBe("managed");
|
|
858
859
|
// Quality serves Anthropic Opus, the most capable managed profile.
|
|
859
860
|
expect(raw.llm.profiles["quality-optimized"].provider).toBe("anthropic");
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from "../plugins/registry.js";
|
|
24
24
|
import { type HookFunction, type Plugin } from "../plugins/types.js";
|
|
25
25
|
import {
|
|
26
|
+
getAllToolDefinitions,
|
|
26
27
|
getPluginToolDefinitions,
|
|
27
28
|
registerPluginTools,
|
|
28
29
|
} from "../tools/registry.js";
|
|
@@ -148,6 +149,37 @@ describe("per-surface disabled-state filtering", () => {
|
|
|
148
149
|
expect(defs.some((d) => d.name === "test_tool")).toBe(true);
|
|
149
150
|
});
|
|
150
151
|
|
|
152
|
+
test("getAllToolDefinitions excludes tools from a disabled plugin", async () => {
|
|
153
|
+
// getAllToolDefinitions is the base tool snapshot the conversation tool
|
|
154
|
+
// resolver captures at creation. A plugin disabled BEFORE a new
|
|
155
|
+
// conversation starts must not leak its tools here — otherwise the
|
|
156
|
+
// resolver's core/plugin split (which reads the filtered
|
|
157
|
+
// getPluginToolDefinitions) misclassifies them as core and keeps them on
|
|
158
|
+
// the wire to the LLM, executable despite being hidden from the catalog.
|
|
159
|
+
const plugin: Plugin = {
|
|
160
|
+
manifest: { name: "default-test-base-snapshot", version: "1.0.0" },
|
|
161
|
+
tools: [makeFakeTool("base_snapshot_tool")],
|
|
162
|
+
};
|
|
163
|
+
registerPlugin(plugin);
|
|
164
|
+
registerPluginTools("default-test-base-snapshot", plugin.tools!);
|
|
165
|
+
|
|
166
|
+
// Before disabling: tool is part of the base snapshot.
|
|
167
|
+
let defs = getAllToolDefinitions();
|
|
168
|
+
expect(defs.some((d) => d.name === "base_snapshot_tool")).toBe(true);
|
|
169
|
+
|
|
170
|
+
// Disable via sentinel.
|
|
171
|
+
await createSentinel("default-test-base-snapshot");
|
|
172
|
+
|
|
173
|
+
// After disabling: tool drops from the base snapshot at read time.
|
|
174
|
+
defs = getAllToolDefinitions();
|
|
175
|
+
expect(defs.some((d) => d.name === "base_snapshot_tool")).toBe(false);
|
|
176
|
+
|
|
177
|
+
// Re-enable.
|
|
178
|
+
await removeSentinel("default-test-base-snapshot");
|
|
179
|
+
defs = getAllToolDefinitions();
|
|
180
|
+
expect(defs.some((d) => d.name === "base_snapshot_tool")).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
151
183
|
test("disabling one plugin does not affect others", async () => {
|
|
152
184
|
const pluginA = buildPlugin("default-test-alpha", {
|
|
153
185
|
"user-prompt-submit": () => Promise.resolve(),
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* Server → client notification that an ACP session has finished its
|
|
5
5
|
* turn. `stopReason` mirrors the ACP `StopReason` set.
|
|
6
6
|
*
|
|
7
|
-
* Canonical wire-contract source.
|
|
8
|
-
*
|
|
9
|
-
* `@vellumai/assistant-api`.
|
|
7
|
+
* Canonical wire-contract source. Re-exported to external consumers via
|
|
8
|
+
* `@vellumai/assistant-api` (the `api/index.ts` barrel).
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
11
|
import { z } from "zod";
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
* Server → client notification that an ACP session has errored.
|
|
5
5
|
* Carries the session identity and a human-readable `error` message.
|
|
6
6
|
*
|
|
7
|
-
* Canonical wire-contract source.
|
|
8
|
-
*
|
|
9
|
-
* `@vellumai/assistant-api`.
|
|
7
|
+
* Canonical wire-contract source. Re-exported to external consumers via
|
|
8
|
+
* `@vellumai/assistant-api` (the `api/index.ts` barrel).
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
11
|
import { z } from "zod";
|
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
* anchors the inline card to the `acp_spawn` tool-use block, and `task`
|
|
9
9
|
* carries the objective text.
|
|
10
10
|
*
|
|
11
|
-
* Canonical wire-contract source.
|
|
12
|
-
*
|
|
13
|
-
* `@vellumai/assistant-api`.
|
|
11
|
+
* Canonical wire-contract source. Re-exported to external consumers via
|
|
12
|
+
* `@vellumai/assistant-api` (the `api/index.ts` barrel).
|
|
14
13
|
*/
|
|
15
14
|
|
|
16
15
|
import { z } from "zod";
|
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
* since they apply only to the relevant `updateType`s. `messageId` and
|
|
8
8
|
* `seq` let clients correlate and order chunks within a session.
|
|
9
9
|
*
|
|
10
|
-
* Canonical wire-contract source.
|
|
11
|
-
*
|
|
12
|
-
* `@vellumai/assistant-api`.
|
|
10
|
+
* Canonical wire-contract source. Re-exported to external consumers via
|
|
11
|
+
* `@vellumai/assistant-api` (the `api/index.ts` barrel).
|
|
13
12
|
*/
|
|
14
13
|
|
|
15
14
|
import { z } from "zod";
|
|
@@ -9,9 +9,8 @@
|
|
|
9
9
|
* agent's cumulative cost. A side gauge, not part of the ordered update
|
|
10
10
|
* timeline — carries no `seq`.
|
|
11
11
|
*
|
|
12
|
-
* Canonical wire-contract source.
|
|
13
|
-
*
|
|
14
|
-
* `@vellumai/assistant-api`.
|
|
12
|
+
* Canonical wire-contract source. Re-exported to external consumers via
|
|
13
|
+
* `@vellumai/assistant-api` (the `api/index.ts` barrel).
|
|
15
14
|
*/
|
|
16
15
|
|
|
17
16
|
import { z } from "zod";
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the `assistant ps` CLI command.
|
|
3
|
+
*
|
|
4
|
+
* Validates:
|
|
5
|
+
* - Calls the `ps` IPC method exactly once
|
|
6
|
+
* - Renders the daemon process tree (parent + indented children + status)
|
|
7
|
+
* - `--json` emits the raw route payload instead of the tree
|
|
8
|
+
* - IPC failures surface via exitFromIpcResult (non-zero exit)
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
12
|
+
|
|
13
|
+
import { Command } from "commander";
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Mock state
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
let ipcCalls: Array<{ method: string }> = [];
|
|
20
|
+
let mockResponse: {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
result?: unknown;
|
|
23
|
+
error?: string;
|
|
24
|
+
statusCode?: number;
|
|
25
|
+
} = { ok: true, result: { processes: [] } };
|
|
26
|
+
|
|
27
|
+
let logLines: string[] = [];
|
|
28
|
+
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
// Mocks
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
mock.module("../../../ipc/cli-client.js", () => ({
|
|
34
|
+
cliIpcCall: async (method: string) => {
|
|
35
|
+
ipcCalls.push({ method });
|
|
36
|
+
return mockResponse;
|
|
37
|
+
},
|
|
38
|
+
exitFromIpcResult: (r: { error?: string }) => {
|
|
39
|
+
process.stderr.write((r.error ?? "error") + "\n");
|
|
40
|
+
process.exit(1);
|
|
41
|
+
},
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
mock.module("../../../util/logger.js", () => ({
|
|
45
|
+
getLogger: () => ({
|
|
46
|
+
info: () => {},
|
|
47
|
+
warn: () => {},
|
|
48
|
+
error: () => {},
|
|
49
|
+
debug: () => {},
|
|
50
|
+
}),
|
|
51
|
+
getCliLogger: () => ({
|
|
52
|
+
info: (msg: string) => logLines.push(msg),
|
|
53
|
+
warn: () => {},
|
|
54
|
+
error: () => {},
|
|
55
|
+
debug: () => {},
|
|
56
|
+
}),
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
// Import module under test (after mocks)
|
|
61
|
+
// ---------------------------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
const { registerPsCommand } = await import("../ps.js");
|
|
64
|
+
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Test helper
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
async function runPsCommand(
|
|
70
|
+
args: string[] = [],
|
|
71
|
+
): Promise<{ stdout: string; exitCode: number }> {
|
|
72
|
+
const stdoutChunks: string[] = [];
|
|
73
|
+
let capturedExitCode = 0;
|
|
74
|
+
let exitCalled = false;
|
|
75
|
+
|
|
76
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
77
|
+
const originalExit = process.exit.bind(process);
|
|
78
|
+
|
|
79
|
+
process.stdout.write = ((chunk: unknown) => {
|
|
80
|
+
stdoutChunks.push(typeof chunk === "string" ? chunk : String(chunk));
|
|
81
|
+
return true;
|
|
82
|
+
}) as typeof process.stdout.write;
|
|
83
|
+
|
|
84
|
+
(process as { exit: (code?: number) => never }).exit = ((code?: number) => {
|
|
85
|
+
capturedExitCode = code ?? 0;
|
|
86
|
+
exitCalled = true;
|
|
87
|
+
throw new Error(`process.exit(${code})`);
|
|
88
|
+
}) as typeof process.exit;
|
|
89
|
+
|
|
90
|
+
process.exitCode = 0;
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const program = new Command();
|
|
94
|
+
program.exitOverride();
|
|
95
|
+
program.configureOutput({ writeErr: () => {}, writeOut: () => {} });
|
|
96
|
+
registerPsCommand(program);
|
|
97
|
+
await program.parseAsync(["node", "assistant", "ps", ...args]);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
if (err instanceof Error && !err.message.startsWith("process.exit(")) {
|
|
100
|
+
// Commander parse errors; ignore
|
|
101
|
+
}
|
|
102
|
+
} finally {
|
|
103
|
+
process.stdout.write = originalStdoutWrite;
|
|
104
|
+
(process as { exit: (code?: number) => never }).exit = originalExit;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const exitCode = exitCalled ? capturedExitCode : (process.exitCode ?? 0);
|
|
108
|
+
process.exitCode = 0;
|
|
109
|
+
|
|
110
|
+
return { exitCode, stdout: stdoutChunks.join("") };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
// Setup
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
ipcCalls = [];
|
|
119
|
+
logLines = [];
|
|
120
|
+
mockResponse = { ok: true, result: { processes: [] } };
|
|
121
|
+
process.exitCode = 0;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// Tests
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
describe("ps command — IPC wiring", () => {
|
|
129
|
+
test("calls the `ps` IPC method exactly once", async () => {
|
|
130
|
+
await runPsCommand();
|
|
131
|
+
expect(ipcCalls).toEqual([{ method: "ps" }]);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("ps command — tree rendering", () => {
|
|
136
|
+
test("renders parent, indented children, and status labels", async () => {
|
|
137
|
+
mockResponse = {
|
|
138
|
+
ok: true,
|
|
139
|
+
result: {
|
|
140
|
+
processes: [
|
|
141
|
+
{
|
|
142
|
+
name: "assistant",
|
|
143
|
+
status: "running",
|
|
144
|
+
children: [
|
|
145
|
+
{ name: "qdrant", status: "running" },
|
|
146
|
+
{ name: "embed-worker", status: "not_running" },
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
await runPsCommand();
|
|
154
|
+
const out = logLines.join("\n");
|
|
155
|
+
|
|
156
|
+
expect(out).toContain("assistant [running]");
|
|
157
|
+
expect(out).toContain(" qdrant [running]");
|
|
158
|
+
expect(out).toContain(" embed-worker [not running]");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
test("appends info text when present", async () => {
|
|
162
|
+
mockResponse = {
|
|
163
|
+
ok: true,
|
|
164
|
+
result: {
|
|
165
|
+
processes: [
|
|
166
|
+
{ name: "qdrant", status: "unreachable", info: "probe timed out" },
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
await runPsCommand();
|
|
172
|
+
expect(logLines.join("\n")).toContain(
|
|
173
|
+
"qdrant [unreachable] — probe timed out",
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("prints a placeholder when no processes are reported", async () => {
|
|
178
|
+
mockResponse = { ok: true, result: { processes: [] } };
|
|
179
|
+
await runPsCommand();
|
|
180
|
+
expect(logLines.join("\n")).toContain("No processes reported.");
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("ps command — JSON output", () => {
|
|
185
|
+
test("--json emits the raw route payload, not the tree", async () => {
|
|
186
|
+
const result = {
|
|
187
|
+
processes: [{ name: "assistant", status: "running" }],
|
|
188
|
+
};
|
|
189
|
+
mockResponse = { ok: true, result };
|
|
190
|
+
|
|
191
|
+
const { stdout } = await runPsCommand(["--json"]);
|
|
192
|
+
|
|
193
|
+
expect(JSON.parse(stdout)).toEqual(result);
|
|
194
|
+
// Tree renderer should not have run.
|
|
195
|
+
expect(logLines.join("\n")).not.toContain("[running]");
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe("ps command — failures", () => {
|
|
200
|
+
test("exits non-zero when the IPC call fails", async () => {
|
|
201
|
+
mockResponse = { ok: false, error: "boom", statusCode: 500 };
|
|
202
|
+
const { exitCode } = await runPsCommand();
|
|
203
|
+
expect(exitCode).toBe(1);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -408,11 +408,14 @@ describe("memory worker start", () => {
|
|
|
408
408
|
test("leaves the config flag untouched when the spawn fails", async () => {
|
|
409
409
|
const restore = stubProcessKill(new Set());
|
|
410
410
|
const originalSpawn = Bun.spawn;
|
|
411
|
-
// Spawn returns
|
|
412
|
-
//
|
|
411
|
+
// Spawn returns a child that exits during startup without writing a PID file
|
|
412
|
+
// → spawnMemoryWorkerProcess detects the early exit and throws, so the flag
|
|
413
|
+
// must stay disabled.
|
|
413
414
|
(Bun as { spawn: typeof Bun.spawn }).spawn = (() => ({
|
|
414
415
|
unref: () => {},
|
|
415
|
-
|
|
416
|
+
kill: () => {},
|
|
417
|
+
exited: Promise.resolve(1),
|
|
418
|
+
pid: 123,
|
|
416
419
|
})) as unknown as typeof Bun.spawn;
|
|
417
420
|
try {
|
|
418
421
|
const { exitCode, stdout } = await runCommand([
|
|
@@ -60,7 +60,10 @@ async function startWorker(
|
|
|
60
60
|
): Promise<void> {
|
|
61
61
|
let result: { pid: number; alreadyRunning: boolean };
|
|
62
62
|
try {
|
|
63
|
-
|
|
63
|
+
// Terminate the child if it times out: this path leaves
|
|
64
|
+
// `memory.worker.enabled` off on failure, so a worker that came up late
|
|
65
|
+
// would drain the queue alongside the daemon's synchronous runner.
|
|
66
|
+
result = await spawnMemoryWorkerProcess({ terminateOnTimeout: true });
|
|
64
67
|
} catch (err) {
|
|
65
68
|
// Spawn failed — leave `memory.worker.enabled` untouched so the daemon's
|
|
66
69
|
// synchronous runner keeps draining the queue rather than standing down
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI command: `assistant ps`
|
|
3
|
+
*
|
|
4
|
+
* Thin IPC wrapper over the daemon's `ps` route. Renders the daemon's own
|
|
5
|
+
* process tree (the assistant runtime and its supervised subsystems —
|
|
6
|
+
* qdrant, embed-worker) to the console. The route owns the live probing;
|
|
7
|
+
* the CLI just forwards the request and formats the response.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { Command } from "commander";
|
|
11
|
+
|
|
12
|
+
import { cliIpcCall, exitFromIpcResult } from "../../ipc/cli-client.js";
|
|
13
|
+
import { registerCommand } from "../lib/register-command.js";
|
|
14
|
+
import { log } from "../logger.js";
|
|
15
|
+
import { shouldOutputJson, writeOutput } from "../output.js";
|
|
16
|
+
|
|
17
|
+
interface ProcessEntry {
|
|
18
|
+
name: string;
|
|
19
|
+
status: "running" | "not_running" | "unreachable";
|
|
20
|
+
children?: ProcessEntry[];
|
|
21
|
+
info?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface PsResponse {
|
|
25
|
+
processes: ProcessEntry[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const STATUS_LABEL: Record<ProcessEntry["status"], string> = {
|
|
29
|
+
running: "running",
|
|
30
|
+
not_running: "not running",
|
|
31
|
+
unreachable: "unreachable",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Render one entry plus its children, indented to reflect tree depth. */
|
|
35
|
+
function renderEntry(entry: ProcessEntry, depth: number): void {
|
|
36
|
+
const indent = " ".repeat(depth);
|
|
37
|
+
const status = STATUS_LABEL[entry.status] ?? entry.status;
|
|
38
|
+
const info = entry.info ? ` — ${entry.info}` : "";
|
|
39
|
+
log.info(`${indent}${entry.name} [${status}]${info}`);
|
|
40
|
+
for (const child of entry.children ?? []) {
|
|
41
|
+
renderEntry(child, depth + 1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function registerPsCommand(program: Command): void {
|
|
46
|
+
registerCommand(program, {
|
|
47
|
+
name: "ps",
|
|
48
|
+
transport: "ipc",
|
|
49
|
+
description:
|
|
50
|
+
"Show the assistant daemon's process tree and subsystem health",
|
|
51
|
+
build: (ps) => {
|
|
52
|
+
ps.option("--json", "Machine-readable JSON output").addHelpText(
|
|
53
|
+
"after",
|
|
54
|
+
`
|
|
55
|
+
Reports the daemon's own process tree: the assistant runtime plus its
|
|
56
|
+
supervised subsystems (qdrant vector store, embed-worker). Each subsystem
|
|
57
|
+
status is probed live — qdrant via its readiness endpoint, embed-worker via
|
|
58
|
+
PID-file liveness — so a status of "unreachable" means the probe itself
|
|
59
|
+
failed rather than the process being confirmed down.
|
|
60
|
+
|
|
61
|
+
Examples:
|
|
62
|
+
$ assistant ps
|
|
63
|
+
$ assistant ps --json`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
ps.action(async (_opts, cmd: Command) => {
|
|
67
|
+
const r = await cliIpcCall<PsResponse>("ps");
|
|
68
|
+
if (!r.ok) return exitFromIpcResult(r);
|
|
69
|
+
|
|
70
|
+
if (shouldOutputJson(cmd)) {
|
|
71
|
+
writeOutput(cmd, r.result);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const processes = r.result?.processes ?? [];
|
|
76
|
+
if (processes.length === 0) {
|
|
77
|
+
log.info("No processes reported.");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
log.info("");
|
|
82
|
+
for (const entry of processes) {
|
|
83
|
+
renderEntry(entry, 0);
|
|
84
|
+
}
|
|
85
|
+
log.info("");
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
package/src/cli/program.ts
CHANGED
|
@@ -40,6 +40,7 @@ import { registerOAuthCommand } from "./commands/oauth/index.js";
|
|
|
40
40
|
import { registerPendingCommand } from "./commands/pending.js";
|
|
41
41
|
import { registerPlatformCommand } from "./commands/platform/index.js";
|
|
42
42
|
import { registerPluginsCommand } from "./commands/plugins.js";
|
|
43
|
+
import { registerPsCommand } from "./commands/ps.js";
|
|
43
44
|
import { registerRoutesCommand } from "./commands/routes.js";
|
|
44
45
|
import { registerSchedulesCommand } from "./commands/schedules.js";
|
|
45
46
|
import { registerSequenceCommand } from "./commands/sequence.js";
|
|
@@ -137,6 +138,7 @@ Examples:
|
|
|
137
138
|
if (isExternalPluginsEnabled(getConfigReadOnly())) {
|
|
138
139
|
registerPluginsCommand(program);
|
|
139
140
|
}
|
|
141
|
+
registerPsCommand(program);
|
|
140
142
|
registerRoutesCommand(program);
|
|
141
143
|
registerSchedulesCommand(program);
|
|
142
144
|
registerSequenceCommand(program);
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for `spawnMemoryWorkerProcess` — the detached worker-process spawner.
|
|
3
|
+
*
|
|
4
|
+
* Focuses on the readiness wait, which gates whether `assistant memory worker
|
|
5
|
+
* start` reports success and flips `memory.worker.enabled`:
|
|
6
|
+
* - succeeds when the worker writes its PID file (immediately or a little
|
|
7
|
+
* late — a cold `bun run` start takes seconds),
|
|
8
|
+
* - fails fast when the child exits during startup,
|
|
9
|
+
* - on timeout, terminates a still-alive child only when asked, so the CLI
|
|
10
|
+
* (which leaves the flag off on failure) cannot orphan a worker that would
|
|
11
|
+
* then drain the queue alongside the daemon's synchronous runner.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
18
|
+
import { mock } from "bun:test";
|
|
19
|
+
|
|
20
|
+
let tmpDir: string;
|
|
21
|
+
let pidPath: string;
|
|
22
|
+
let markerPath: string;
|
|
23
|
+
|
|
24
|
+
mock.module("../../util/platform.js", () => ({
|
|
25
|
+
getMemoryWorkerPidPath: () => pidPath,
|
|
26
|
+
getMemorySyncRunnerMarkerPath: () => markerPath,
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const noopLogger = {
|
|
30
|
+
info: () => {},
|
|
31
|
+
warn: () => {},
|
|
32
|
+
error: () => {},
|
|
33
|
+
debug: () => {},
|
|
34
|
+
};
|
|
35
|
+
mock.module("../../util/logger.js", () => ({
|
|
36
|
+
getLogger: () => noopLogger,
|
|
37
|
+
getCliLogger: () => noopLogger,
|
|
38
|
+
getCurrentLogFilePath: () => join(tmpDir, "worker-control-test.log"),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
const { spawnMemoryWorkerProcess, MemoryWorkerSpawnError } =
|
|
42
|
+
await import("../worker-control.js");
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Install a stub `Bun.spawn`. The `onSpawn` callback receives the resolved PID
|
|
46
|
+
* path so a test can simulate the worker writing its PID file (now or later),
|
|
47
|
+
* and returns the fake child handle.
|
|
48
|
+
*/
|
|
49
|
+
function stubBunSpawn(
|
|
50
|
+
makeChild: () => {
|
|
51
|
+
unref: () => void;
|
|
52
|
+
kill: () => void;
|
|
53
|
+
pid: number;
|
|
54
|
+
exited?: Promise<unknown>;
|
|
55
|
+
},
|
|
56
|
+
): () => void {
|
|
57
|
+
const original = Bun.spawn;
|
|
58
|
+
(Bun as { spawn: typeof Bun.spawn }).spawn = (() =>
|
|
59
|
+
makeChild()) as unknown as typeof Bun.spawn;
|
|
60
|
+
return () => {
|
|
61
|
+
(Bun as { spawn: typeof Bun.spawn }).spawn = original;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** A promise that never resolves — stands in for a still-alive child. */
|
|
66
|
+
function neverExits(): Promise<unknown> {
|
|
67
|
+
return new Promise(() => {});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
tmpDir = mkdtempSync(join(tmpdir(), "worker-control-test-"));
|
|
72
|
+
pidPath = join(tmpDir, "memory-worker.pid");
|
|
73
|
+
markerPath = join(tmpDir, "memory-sync-runner.pid");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
rmSync(tmpDir, { recursive: true, force: true });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("spawnMemoryWorkerProcess", () => {
|
|
81
|
+
test("returns the PID when the worker writes its file immediately", async () => {
|
|
82
|
+
const restore = stubBunSpawn(() => {
|
|
83
|
+
writeFileSync(pidPath, "4242");
|
|
84
|
+
return {
|
|
85
|
+
unref: () => {},
|
|
86
|
+
kill: () => {},
|
|
87
|
+
pid: 4242,
|
|
88
|
+
exited: neverExits(),
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
try {
|
|
92
|
+
const result = await spawnMemoryWorkerProcess({
|
|
93
|
+
pidWaitTimeoutMs: 1_000,
|
|
94
|
+
pidPollIntervalMs: 10,
|
|
95
|
+
});
|
|
96
|
+
expect(result).toEqual({ pid: 4242, alreadyRunning: false });
|
|
97
|
+
} finally {
|
|
98
|
+
restore();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("succeeds when the worker writes its PID file slightly late", async () => {
|
|
103
|
+
const restore = stubBunSpawn(() => {
|
|
104
|
+
// Worker takes ~120ms to come up — would have failed under the old 1s/10x
|
|
105
|
+
// loop's tight window only if shorter; here we prove the wait spans it.
|
|
106
|
+
setTimeout(() => writeFileSync(pidPath, "777"), 120);
|
|
107
|
+
return {
|
|
108
|
+
unref: () => {},
|
|
109
|
+
kill: () => {},
|
|
110
|
+
pid: 777,
|
|
111
|
+
exited: neverExits(),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
try {
|
|
115
|
+
const result = await spawnMemoryWorkerProcess({
|
|
116
|
+
pidWaitTimeoutMs: 2_000,
|
|
117
|
+
pidPollIntervalMs: 20,
|
|
118
|
+
});
|
|
119
|
+
expect(result).toEqual({ pid: 777, alreadyRunning: false });
|
|
120
|
+
} finally {
|
|
121
|
+
restore();
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("fails fast when the child exits during startup", async () => {
|
|
126
|
+
let killed = false;
|
|
127
|
+
const restore = stubBunSpawn(() => ({
|
|
128
|
+
unref: () => {},
|
|
129
|
+
kill: () => {
|
|
130
|
+
killed = true;
|
|
131
|
+
},
|
|
132
|
+
pid: 99,
|
|
133
|
+
// Never writes a PID file; exits immediately.
|
|
134
|
+
exited: Promise.resolve(1),
|
|
135
|
+
}));
|
|
136
|
+
try {
|
|
137
|
+
await expect(
|
|
138
|
+
spawnMemoryWorkerProcess({
|
|
139
|
+
// Long timeout so the test only passes if early-exit short-circuits it.
|
|
140
|
+
pidWaitTimeoutMs: 10_000,
|
|
141
|
+
pidPollIntervalMs: 10,
|
|
142
|
+
terminateOnTimeout: true,
|
|
143
|
+
}),
|
|
144
|
+
).rejects.toBeInstanceOf(MemoryWorkerSpawnError);
|
|
145
|
+
// It exited on its own — nothing to terminate.
|
|
146
|
+
expect(killed).toBe(false);
|
|
147
|
+
} finally {
|
|
148
|
+
restore();
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("terminates a still-alive child on timeout when terminateOnTimeout is set", async () => {
|
|
153
|
+
let killed = false;
|
|
154
|
+
const restore = stubBunSpawn(() => ({
|
|
155
|
+
unref: () => {},
|
|
156
|
+
kill: () => {
|
|
157
|
+
killed = true;
|
|
158
|
+
},
|
|
159
|
+
pid: 55,
|
|
160
|
+
exited: neverExits(),
|
|
161
|
+
}));
|
|
162
|
+
try {
|
|
163
|
+
await expect(
|
|
164
|
+
spawnMemoryWorkerProcess({
|
|
165
|
+
pidWaitTimeoutMs: 150,
|
|
166
|
+
pidPollIntervalMs: 20,
|
|
167
|
+
terminateOnTimeout: true,
|
|
168
|
+
}),
|
|
169
|
+
).rejects.toBeInstanceOf(MemoryWorkerSpawnError);
|
|
170
|
+
expect(killed).toBe(true);
|
|
171
|
+
} finally {
|
|
172
|
+
restore();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("does not terminate the child on timeout when terminateOnTimeout is false", async () => {
|
|
177
|
+
let killed = false;
|
|
178
|
+
const restore = stubBunSpawn(() => ({
|
|
179
|
+
unref: () => {},
|
|
180
|
+
kill: () => {
|
|
181
|
+
killed = true;
|
|
182
|
+
},
|
|
183
|
+
pid: 55,
|
|
184
|
+
exited: neverExits(),
|
|
185
|
+
}));
|
|
186
|
+
try {
|
|
187
|
+
await expect(
|
|
188
|
+
spawnMemoryWorkerProcess({
|
|
189
|
+
pidWaitTimeoutMs: 150,
|
|
190
|
+
pidPollIntervalMs: 20,
|
|
191
|
+
terminateOnTimeout: false,
|
|
192
|
+
}),
|
|
193
|
+
).rejects.toBeInstanceOf(MemoryWorkerSpawnError);
|
|
194
|
+
expect(killed).toBe(false);
|
|
195
|
+
} finally {
|
|
196
|
+
restore();
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("reuses an already-running worker without spawning", async () => {
|
|
201
|
+
// A live PID file (this test process) makes the probe report running.
|
|
202
|
+
writeFileSync(pidPath, String(process.pid));
|
|
203
|
+
let spawned = false;
|
|
204
|
+
const restore = stubBunSpawn(() => {
|
|
205
|
+
spawned = true;
|
|
206
|
+
return { unref: () => {}, kill: () => {}, pid: 1, exited: neverExits() };
|
|
207
|
+
});
|
|
208
|
+
try {
|
|
209
|
+
const result = await spawnMemoryWorkerProcess({ pidWaitTimeoutMs: 100 });
|
|
210
|
+
expect(result).toEqual({ pid: process.pid, alreadyRunning: true });
|
|
211
|
+
expect(spawned).toBe(false);
|
|
212
|
+
} finally {
|
|
213
|
+
restore();
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
});
|