@vellumai/assistant 0.10.7-dev.202607100313.fffdfea → 0.10.7-dev.202607100720.fba456e

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.
Files changed (99) hide show
  1. package/openapi.yaml +846 -27
  2. package/package.json +1 -1
  3. package/src/__tests__/config-watcher-skill-reseed.test.ts +1 -0
  4. package/src/__tests__/config-watcher.test.ts +22 -4
  5. package/src/__tests__/credential-security-invariants.test.ts +1 -1
  6. package/src/__tests__/plugin-import-boundary-guard.test.ts +6 -9
  7. package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +0 -2
  8. package/src/cli/commands/__tests__/inference-models.test.ts +86 -0
  9. package/src/cli/commands/__tests__/inference-profiles.test.ts +254 -0
  10. package/src/cli/commands/__tests__/inference-providers.test.ts +171 -0
  11. package/src/cli/commands/__tests__/schedules.test.ts +133 -1
  12. package/src/cli/commands/__tests__/usage.test.ts +131 -0
  13. package/src/cli/commands/inference-callsites.ts +158 -0
  14. package/src/cli/commands/inference-models.ts +84 -0
  15. package/src/cli/commands/inference-profiles.ts +371 -0
  16. package/src/cli/commands/inference-providers-default.ts +89 -0
  17. package/src/cli/commands/inference-providers.ts +87 -16
  18. package/src/cli/commands/inference.ts +6 -0
  19. package/src/cli/commands/memory/nodes.ts +90 -50
  20. package/src/cli/commands/schedules.ts +17 -2
  21. package/src/cli/commands/usage.ts +59 -21
  22. package/src/cli/lib/__tests__/cli-output.test.ts +20 -0
  23. package/src/cli/lib/cli-output.ts +55 -0
  24. package/src/config/__tests__/loader-last-known-good.test.ts +229 -0
  25. package/src/config/__tests__/loader-sparse-array-cleanup.test.ts +166 -0
  26. package/src/config/default-profile-catalog.ts +28 -0
  27. package/src/config/loader.ts +276 -46
  28. package/src/daemon/config-watcher.ts +65 -20
  29. package/src/daemon/message-types/sync.ts +1 -0
  30. package/src/oauth/byo-connection.test.ts +1 -1
  31. package/src/oauth/connection-resolver.test.ts +140 -0
  32. package/src/oauth/connection-resolver.ts +48 -12
  33. package/src/plugins/defaults/memory/anisotropy.ts +1 -1
  34. package/src/plugins/defaults/memory/config.ts +1 -1
  35. package/src/plugins/defaults/memory/context-search/agent-protocol.ts +1 -1
  36. package/src/plugins/defaults/memory/context-search/search.ts +1 -1
  37. package/src/plugins/defaults/memory/graph/bootstrap.ts +1 -1
  38. package/src/plugins/defaults/memory/graph/consolidation.ts +1 -1
  39. package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +11 -1
  40. package/src/plugins/defaults/memory/graph/extraction.ts +1 -1
  41. package/src/plugins/defaults/memory/graph/narrative.ts +1 -1
  42. package/src/plugins/defaults/memory/graph/pattern-scan.ts +1 -1
  43. package/src/plugins/defaults/memory/graph/tool-handlers.ts +1 -1
  44. package/src/plugins/defaults/memory/graph/tools.ts +1 -1
  45. package/src/plugins/defaults/memory/graph-topology/build-memory-graph.ts +43 -16
  46. package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +1 -1
  47. package/src/plugins/defaults/memory/host-utils.ts +80 -0
  48. package/src/plugins/defaults/memory/identity-context.ts +1 -1
  49. package/src/plugins/defaults/memory/injectors.ts +1 -1
  50. package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +2 -2
  51. package/src/plugins/defaults/memory/jobs-worker.ts +2 -9
  52. package/src/plugins/defaults/memory/memory-retrospective-state.ts +1 -1
  53. package/src/plugins/defaults/memory/paths.ts +48 -0
  54. package/src/plugins/defaults/memory/pkb/autoinject.ts +1 -1
  55. package/src/plugins/defaults/memory/pkb/context.ts +2 -2
  56. package/src/plugins/defaults/memory/pkb/types.ts +1 -1
  57. package/src/plugins/defaults/memory/pkb-schedule.ts +2 -2
  58. package/src/plugins/defaults/memory/rerank-local.ts +2 -3
  59. package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +1 -1
  60. package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +149 -1
  61. package/src/plugins/defaults/memory/routes/memory-item-routes.ts +144 -1
  62. package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +1 -1
  63. package/src/plugins/defaults/memory/startup.ts +1 -1
  64. package/src/plugins/defaults/memory/v2/backfill-jobs.ts +1 -1
  65. package/src/plugins/defaults/memory/v2/consolidation-job.ts +2 -2
  66. package/src/plugins/defaults/memory/v2/injection.ts +1 -1
  67. package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +1 -1
  68. package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +1 -1
  69. package/src/plugins/defaults/memory/v2/qdrant.ts +1 -1
  70. package/src/plugins/defaults/memory/v2/reranker.ts +1 -1
  71. package/src/plugins/defaults/memory/v2/static-context.ts +1 -1
  72. package/src/plugins/defaults/memory/v2/sweep-job.ts +1 -1
  73. package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
  74. package/src/plugins/defaults/memory/v3/maintain-job.ts +1 -1
  75. package/src/plugins/defaults/memory/v3/page-content.ts +1 -1
  76. package/src/plugins/defaults/memory/v3/pool-select.ts +1 -2
  77. package/src/plugins/defaults/memory/v3/selection-log-store.ts +1 -1
  78. package/src/plugins/defaults/memory/v3/shadow-plugin.ts +2 -5
  79. package/src/plugins/defaults/memory/worker.ts +1 -1
  80. package/src/plugins/defaults/workspace/injectors.ts +17 -15
  81. package/src/plugins/types.ts +9 -14
  82. package/src/providers/inference/connection-availability.ts +193 -0
  83. package/src/runtime/routes/__tests__/inference-callsites-routes.test.ts +54 -0
  84. package/src/runtime/routes/__tests__/inference-models-routes.test.ts +54 -0
  85. package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +405 -0
  86. package/src/runtime/routes/__tests__/inference-routes-registration.test.ts +42 -0
  87. package/src/runtime/routes/__tests__/theme-routes.test.ts +66 -0
  88. package/src/runtime/routes/conversation-query-routes.ts +5 -3
  89. package/src/runtime/routes/default-provider-routes.ts +5 -152
  90. package/src/runtime/routes/index.ts +8 -0
  91. package/src/runtime/routes/inference-callsites-routes.ts +211 -0
  92. package/src/runtime/routes/inference-models-routes.ts +104 -0
  93. package/src/runtime/routes/inference-profiles-routes.ts +717 -0
  94. package/src/runtime/routes/theme-routes.ts +36 -0
  95. package/src/runtime/sync/resource-sync-events.ts +4 -0
  96. package/src/theme/workspace-theme.test.ts +269 -0
  97. package/src/theme/workspace-theme.ts +304 -0
  98. package/src/watcher/__tests__/engine-auth-notify.test.ts +316 -0
  99. package/src/watcher/engine.ts +87 -2
@@ -1,14 +1,12 @@
1
1
  /**
2
2
  * `assistant memory nodes` CLI subgroup.
3
3
  *
4
- * Content-based CRUD over the memory v2 graph nodes. Handlers are invoked
5
- * directly in-process (no IPC, no daemon dependency) — exactly the same
6
- * functions the daemon would call, but run here without routing through the
7
- * main thread:
4
+ * Content-based CRUD over the memory v2 graph nodes, routed through the
5
+ * daemon's memory-nodes routes via IPC:
8
6
  *
9
- * - `list` → handleListMemory
10
- * - `delete` → handleDeleteMemory
11
- * - `update` → handleUpdateMemory
7
+ * - `list` → `listMemoryNodes`
8
+ * - `delete` → `deleteMemoryNode`
9
+ * - `update` → `updateMemoryNode`
12
10
  *
13
11
  * Unlike `memory items`, which addresses nodes by UUID, these commands address
14
12
  * nodes by content text — matching the way an operator or agent naturally
@@ -17,20 +15,36 @@
17
15
 
18
16
  import type { Command } from "commander";
19
17
 
20
- import { getConfig } from "../../../config/loader.js";
21
- import {
22
- handleDeleteMemory,
23
- handleListMemory,
24
- handleUpdateMemory,
25
- } from "../../../plugins/defaults/memory/graph/tool-handlers.js";
18
+ import { cliIpcCall, exitFromIpcResult } from "../../../ipc/cli-client.js";
26
19
  import { registerCommand } from "../../lib/register-command.js";
27
20
  import { log } from "../../logger.js";
28
21
  import { writeOutput } from "../../output.js";
29
22
 
23
+ /** Wire shapes of the daemon's memory-nodes route responses. */
24
+ interface MemoryNodeEntry {
25
+ id: string;
26
+ content: string;
27
+ type: string;
28
+ fidelity: string;
29
+ created: number;
30
+ }
31
+
32
+ interface ListMemoryNodesResult {
33
+ success: boolean;
34
+ message: string;
35
+ nodes: MemoryNodeEntry[];
36
+ total: number;
37
+ }
38
+
39
+ interface MemoryNodeMutationResult {
40
+ success: boolean;
41
+ message: string;
42
+ }
43
+
30
44
  export function registerMemoryNodesCommand(memory: Command): void {
31
45
  registerCommand(memory, {
32
46
  name: "nodes",
33
- transport: "local",
47
+ transport: "ipc",
34
48
  description: "Content-based list, delete, and update of memory graph nodes",
35
49
  build: (nodes) => {
36
50
  nodes.addHelpText(
@@ -41,7 +55,7 @@ memory v2 subsystem. Unlike 'memory items', which addresses nodes by UUID, these
41
55
  commands address nodes by content text — matching the way an operator refers to
42
56
  a remembered fact without first looking up its ID.
43
57
 
44
- All subcommands require memory v2 to be enabled on the assistant.
58
+ All subcommands require memory v2 to be enabled and the assistant to be running.
45
59
 
46
60
  Examples:
47
61
  $ assistant memory nodes list
@@ -77,17 +91,25 @@ Examples:
77
91
  $ assistant memory nodes list --json`,
78
92
  )
79
93
  .action(
80
- (
94
+ async (
81
95
  opts: { search?: string; limit?: string; json?: boolean },
82
96
  cmd: Command,
83
97
  ) => {
84
- const result = handleListMemory(
85
- {
86
- search: opts.search,
87
- limit: opts.limit ? parseInt(opts.limit, 10) : undefined,
88
- },
89
- getConfig(),
98
+ const queryParams: Record<string, string> = {};
99
+ if (opts.search) {
100
+ queryParams.search = opts.search;
101
+ }
102
+ if (opts.limit) {
103
+ queryParams.limit = opts.limit;
104
+ }
105
+ const r = await cliIpcCall<ListMemoryNodesResult>(
106
+ "listMemoryNodes",
107
+ { queryParams },
90
108
  );
109
+ if (!r.ok) {
110
+ exitFromIpcResult(r, cmd);
111
+ }
112
+ const result = r.result!;
91
113
 
92
114
  if (!result.success) {
93
115
  log.error(result.message);
@@ -125,7 +147,9 @@ Examples:
125
147
  );
126
148
 
127
149
  console.log(
128
- `${"CONTENT".padEnd(CONTENT_WIDTH)} ${"TYPE".padEnd(typeWidth)} ${"FIDELITY".padEnd(fidelityWidth)} CREATED`,
150
+ `${"CONTENT".padEnd(CONTENT_WIDTH)} ${"TYPE".padEnd(
151
+ typeWidth,
152
+ )} ${"FIDELITY".padEnd(fidelityWidth)} CREATED`,
129
153
  );
130
154
 
131
155
  for (const n of result.nodes) {
@@ -136,12 +160,16 @@ Examples:
136
160
  minute: "2-digit",
137
161
  });
138
162
  console.log(
139
- `${truncate(n.content).padEnd(CONTENT_WIDTH)} ${n.type.padEnd(typeWidth)} ${n.fidelity.padEnd(fidelityWidth)} ${created}`,
163
+ `${truncate(n.content).padEnd(CONTENT_WIDTH)} ${n.type.padEnd(
164
+ typeWidth,
165
+ )} ${n.fidelity.padEnd(fidelityWidth)} ${created}`,
140
166
  );
141
167
  }
142
168
 
143
169
  console.log(
144
- `\n${result.total} node${result.total === 1 ? "" : "s"}${opts.search ? ` matching "${opts.search}"` : ""}`,
170
+ `\n${result.total} node${result.total === 1 ? "" : "s"}${
171
+ opts.search ? ` matching "${opts.search}"` : ""
172
+ }`,
145
173
  );
146
174
  },
147
175
  );
@@ -171,30 +199,39 @@ Examples:
171
199
  $ assistant memory nodes delete "User prefers TypeScript"
172
200
  $ assistant memory nodes delete "User prefers TypeScript" --json`,
173
201
  )
174
- .action((content: string, opts: { json?: boolean }, cmd: Command) => {
175
- if (!content.trim()) {
176
- log.error(
177
- "content is required. Run 'assistant memory nodes list' to find the exact text.",
178
- );
179
- process.exitCode = 1;
180
- return;
181
- }
202
+ .action(
203
+ async (content: string, opts: { json?: boolean }, cmd: Command) => {
204
+ if (!content.trim()) {
205
+ log.error(
206
+ "content is required. Run 'assistant memory nodes list' to find the exact text.",
207
+ );
208
+ process.exitCode = 1;
209
+ return;
210
+ }
182
211
 
183
- const result = handleDeleteMemory({ content }, getConfig());
212
+ const r = await cliIpcCall<MemoryNodeMutationResult>(
213
+ "deleteMemoryNode",
214
+ { body: { content } },
215
+ );
216
+ if (!r.ok) {
217
+ exitFromIpcResult(r, cmd);
218
+ }
219
+ const result = r.result!;
184
220
 
185
- if (!result.success) {
186
- log.error(result.message);
187
- process.exitCode = 1;
188
- return;
189
- }
221
+ if (!result.success) {
222
+ log.error(result.message);
223
+ process.exitCode = 1;
224
+ return;
225
+ }
190
226
 
191
- if (opts.json) {
192
- writeOutput(cmd, result);
193
- return;
194
- }
227
+ if (opts.json) {
228
+ writeOutput(cmd, result);
229
+ return;
230
+ }
195
231
 
196
- log.info(result.message);
197
- });
232
+ log.info(result.message);
233
+ },
234
+ );
198
235
 
199
236
  // ── update ────────────────────────────────────────────────────────────
200
237
 
@@ -222,7 +259,7 @@ Examples:
222
259
  $ assistant memory nodes update "old fact" "corrected fact" --json`,
223
260
  )
224
261
  .action(
225
- (
262
+ async (
226
263
  oldContent: string,
227
264
  newContent: string,
228
265
  opts: { json?: boolean },
@@ -236,11 +273,14 @@ Examples:
236
273
  return;
237
274
  }
238
275
 
239
- const result = handleUpdateMemory(
240
- { old_content: oldContent, new_content: newContent },
241
- "cli",
242
- getConfig(),
276
+ const r = await cliIpcCall<MemoryNodeMutationResult>(
277
+ "updateMemoryNode",
278
+ { body: { oldContent, newContent } },
243
279
  );
280
+ if (!r.ok) {
281
+ exitFromIpcResult(r, cmd);
282
+ }
283
+ const result = r.result!;
244
284
 
245
285
  if (!result.success) {
246
286
  log.error(result.message);
@@ -1,6 +1,7 @@
1
1
  import type { Command } from "commander";
2
2
 
3
3
  import { cliIpcCall, exitFromIpcResult } from "../../ipc/cli-client.js";
4
+ import { formatCostUsd } from "../lib/cli-output.js";
4
5
  import { confirmPrompt } from "../lib/confirm-prompt.js";
5
6
  import { registerCommand } from "../lib/register-command.js";
6
7
  import { log } from "../logger.js";
@@ -54,6 +55,7 @@ interface ScheduleRunRecord {
54
55
  output: string | null;
55
56
  error: string | null;
56
57
  conversationId: string | null;
58
+ estimatedCostUsd: number;
57
59
  createdAt: number;
58
60
  }
59
61
 
@@ -360,6 +362,7 @@ Examples:
360
362
  startedAt: formatTimestamp(run.startedAt),
361
363
  finishedAt: formatNullableTimestamp(run.finishedAt),
362
364
  duration: formatDuration(run.durationMs),
365
+ cost: formatRunCost(run.estimatedCostUsd),
363
366
  conversation: run.conversationId ?? "—",
364
367
  error: run.error ?? "—",
365
368
  }));
@@ -370,6 +373,7 @@ Examples:
370
373
  "STARTED",
371
374
  "FINISHED",
372
375
  "DURATION",
376
+ "COST",
373
377
  "CONVERSATION",
374
378
  "ERROR",
375
379
  ];
@@ -381,6 +385,7 @@ Examples:
381
385
  headers[4].length,
382
386
  headers[5].length,
383
387
  headers[6].length,
388
+ headers[7].length,
384
389
  ];
385
390
 
386
391
  for (const row of rows) {
@@ -389,8 +394,9 @@ Examples:
389
394
  widths[2] = Math.max(widths[2], row.startedAt.length);
390
395
  widths[3] = Math.max(widths[3], row.finishedAt.length);
391
396
  widths[4] = Math.max(widths[4], row.duration.length);
392
- widths[5] = Math.max(widths[5], row.conversation.length);
393
- widths[6] = Math.max(widths[6], row.error.length);
397
+ widths[5] = Math.max(widths[5], row.cost.length);
398
+ widths[6] = Math.max(widths[6], row.conversation.length);
399
+ widths[7] = Math.max(widths[7], row.error.length);
394
400
  }
395
401
 
396
402
  const pad = (value: string, width: number) => value.padEnd(width);
@@ -408,6 +414,7 @@ Examples:
408
414
  row.startedAt,
409
415
  row.finishedAt,
410
416
  row.duration,
417
+ row.cost,
411
418
  row.conversation,
412
419
  row.error,
413
420
  ]
@@ -1169,6 +1176,14 @@ function formatNullableTimestamp(value: number | null): string {
1169
1176
  return value == null ? "—" : formatTimestamp(value);
1170
1177
  }
1171
1178
 
1179
+ /** Run costs render "—" when absent or zero; positive values use the shared USD formatter. */
1180
+ function formatRunCost(value: number | null | undefined): string {
1181
+ if (value == null || !Number.isFinite(value) || value <= 0) {
1182
+ return "—";
1183
+ }
1184
+ return formatCostUsd(value);
1185
+ }
1186
+
1172
1187
  function formatDuration(value: number | null): string {
1173
1188
  if (value == null || !Number.isFinite(value) || value < 0) {
1174
1189
  return "—";
@@ -1,20 +1,19 @@
1
1
  import type { Command } from "commander";
2
2
 
3
3
  import { cliIpcCall, exitFromIpcResult } from "../../ipc/cli-client.js";
4
+ import { formatCostUsd } from "../lib/cli-output.js";
4
5
  import { registerCommand } from "../lib/register-command.js";
5
6
  import { log } from "../logger.js";
6
7
 
7
8
  // ── Formatting helpers ───────────────────────────────────────────
8
9
 
9
- function formatCost(usd: number): string {
10
- if (usd === 0) return "$0.00";
11
- if (usd < 0.01) return `$${usd.toFixed(6)}`;
12
- return `$${usd.toFixed(2)}`;
13
- }
14
-
15
10
  function formatTokens(count: number): string {
16
- if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1)}M`;
17
- if (count >= 1_000) return `${(count / 1_000).toFixed(1)}k`;
11
+ if (count >= 1_000_000) {
12
+ return `${(count / 1_000_000).toFixed(1)}M`;
13
+ }
14
+ if (count >= 1_000) {
15
+ return `${(count / 1_000).toFixed(1)}k`;
16
+ }
18
17
  return String(count);
19
18
  }
20
19
 
@@ -84,7 +83,9 @@ function printTotalsTable(totals: UsageTotals): void {
84
83
  log.info("");
85
84
  log.info(" Usage Totals");
86
85
  log.info(" ────────────────────────────────────");
87
- log.info(` Estimated Cost ${formatCost(totals.totalEstimatedCostUsd)}`);
86
+ log.info(
87
+ ` Estimated Cost ${formatCostUsd(totals.totalEstimatedCostUsd)}`,
88
+ );
88
89
  log.info(` LLM Calls ${totals.eventCount}`);
89
90
  log.info(` Input Tokens ${formatTokens(totals.totalInputTokens)}`);
90
91
  log.info(` Output Tokens ${formatTokens(totals.totalOutputTokens)}`);
@@ -115,7 +116,7 @@ function printDailyTable(buckets: UsageDayBucket[]): void {
115
116
  );
116
117
  const costW = Math.max(
117
118
  "COST".length,
118
- ...buckets.map((b) => formatCost(b.totalEstimatedCostUsd).length),
119
+ ...buckets.map((b) => formatCostUsd(b.totalEstimatedCostUsd).length),
119
120
  );
120
121
  const callsW = Math.max(
121
122
  "CALLS".length,
@@ -132,7 +133,7 @@ function printDailyTable(buckets: UsageDayBucket[]): void {
132
133
 
133
134
  for (const b of buckets) {
134
135
  log.info(
135
- ` ${pad(b.date, dateW)} ${pad(formatTokens(b.totalInputTokens), inputW, "right")} ${pad(formatTokens(b.totalOutputTokens), outputW, "right")} ${pad(formatCost(b.totalEstimatedCostUsd), costW, "right")} ${pad(String(b.eventCount), callsW, "right")}`,
136
+ ` ${pad(b.date, dateW)} ${pad(formatTokens(b.totalInputTokens), inputW, "right")} ${pad(formatTokens(b.totalOutputTokens), outputW, "right")} ${pad(formatCostUsd(b.totalEstimatedCostUsd), costW, "right")} ${pad(String(b.eventCount), callsW, "right")}`,
136
137
  );
137
138
  }
138
139
  log.info("");
@@ -167,7 +168,7 @@ function printBreakdownTable(
167
168
  );
168
169
  const costW = Math.max(
169
170
  "COST".length,
170
- ...entries.map((e) => formatCost(e.totalEstimatedCostUsd).length),
171
+ ...entries.map((e) => formatCostUsd(e.totalEstimatedCostUsd).length),
171
172
  );
172
173
  const callsW = Math.max(
173
174
  "CALLS".length,
@@ -184,7 +185,7 @@ function printBreakdownTable(
184
185
 
185
186
  for (const e of entries) {
186
187
  log.info(
187
- ` ${pad(e.group, groupW)} ${pad(formatTokens(e.totalInputTokens), inputW, "right")} ${pad(formatTokens(e.totalOutputTokens), outputW, "right")} ${pad(formatCost(e.totalEstimatedCostUsd), costW, "right")} ${pad(String(e.eventCount), callsW, "right")}`,
188
+ ` ${pad(e.group, groupW)} ${pad(formatTokens(e.totalInputTokens), inputW, "right")} ${pad(formatTokens(e.totalOutputTokens), outputW, "right")} ${pad(formatCostUsd(e.totalEstimatedCostUsd), costW, "right")} ${pad(String(e.eventCount), callsW, "right")}`,
188
189
  );
189
190
  }
190
191
  log.info("");
@@ -232,11 +233,12 @@ Examples:
232
233
  "--from <epoch_ms>",
233
234
  "Start of range (epoch ms)",
234
235
  ] as const;
235
- const toOption = [
236
- "--to <epoch_ms>",
237
- "End of range (epoch ms)",
238
- ] as const;
236
+ const toOption = ["--to <epoch_ms>", "End of range (epoch ms)"] as const;
239
237
  const jsonOption = ["--json", "Output raw JSON"] as const;
238
+ const scheduleOption = [
239
+ "--schedule <id>",
240
+ "Filter to a schedule id — run 'assistant schedules list' to find it; attributes usage by that schedule's cron run windows",
241
+ ] as const;
240
242
 
241
243
  usage
242
244
  .command("totals", { isDefault: true })
@@ -244,6 +246,7 @@ Examples:
244
246
  .option(...rangeOption)
245
247
  .option(...fromOption)
246
248
  .option(...toOption)
249
+ .option(...scheduleOption)
247
250
  .option(...jsonOption)
248
251
  .addHelpText(
249
252
  "after",
@@ -254,9 +257,13 @@ within the time range.
254
257
  Columns: estimated cost, LLM call count, input/output tokens, cache
255
258
  creation/read tokens, unpriced event count (if any).
256
259
 
260
+ Pass --schedule <id> to restrict totals to a single schedule's cron run
261
+ windows. Find schedule ids with 'assistant schedules list'.
262
+
257
263
  Examples:
258
264
  $ assistant usage totals
259
265
  $ assistant usage totals --range all
266
+ $ assistant usage totals --schedule sched-abc123
260
267
  $ assistant usage totals --from 1709856000000 --to 1709942400000`,
261
268
  )
262
269
  .action(
@@ -264,11 +271,12 @@ Examples:
264
271
  range: string;
265
272
  from?: string;
266
273
  to?: string;
274
+ schedule?: string;
267
275
  json?: boolean;
268
276
  }) => {
269
277
  const { from, to } = resolveRange(opts);
270
278
  const response = await cliIpcCall<UsageTotals>("usage_totals", {
271
- queryParams: { from: String(from), to: String(to) },
279
+ queryParams: buildUsageQueryParams(from, to, opts.schedule),
272
280
  });
273
281
  if (!response.ok) {
274
282
  return exitFromIpcResult(response);
@@ -288,6 +296,7 @@ Examples:
288
296
  .option(...rangeOption)
289
297
  .option(...fromOption)
290
298
  .option(...toOption)
299
+ .option(...scheduleOption)
291
300
  .option(...jsonOption)
292
301
  .addHelpText(
293
302
  "after",
@@ -295,9 +304,13 @@ Examples:
295
304
  Shows one row per day (UTC) with input tokens, output tokens, estimated
296
305
  cost, and LLM call count.
297
306
 
307
+ Pass --schedule <id> to restrict the breakdown to a single schedule's cron
308
+ run windows. Find schedule ids with 'assistant schedules list'.
309
+
298
310
  Examples:
299
311
  $ assistant usage daily
300
312
  $ assistant usage daily --range week
313
+ $ assistant usage daily --schedule sched-abc123
301
314
  $ assistant usage daily --range month --json`,
302
315
  )
303
316
  .action(
@@ -305,12 +318,13 @@ Examples:
305
318
  range: string;
306
319
  from?: string;
307
320
  to?: string;
321
+ schedule?: string;
308
322
  json?: boolean;
309
323
  }) => {
310
324
  const { from, to } = resolveRange(opts);
311
325
  const response = await cliIpcCall<{ buckets: UsageDayBucket[] }>(
312
326
  "usage_daily",
313
- { queryParams: { from: String(from), to: String(to) } },
327
+ { queryParams: buildUsageQueryParams(from, to, opts.schedule) },
314
328
  );
315
329
  if (!response.ok) {
316
330
  return exitFromIpcResult(response);
@@ -332,6 +346,7 @@ Examples:
332
346
  .option(...rangeOption)
333
347
  .option(...fromOption)
334
348
  .option(...toOption)
349
+ .option(...scheduleOption)
335
350
  .option(...jsonOption)
336
351
  .option(
337
352
  "-g, --group-by <dimension>",
@@ -354,11 +369,15 @@ Grouping dimensions:
354
369
  Shows one row per group with input/output tokens, estimated cost, and
355
370
  call count. Rows are sorted by cost descending.
356
371
 
372
+ Pass --schedule <id> to restrict the breakdown to a single schedule's cron
373
+ run windows. Find schedule ids with 'assistant schedules list'.
374
+
357
375
  Examples:
358
376
  $ assistant usage breakdown
359
377
  $ assistant usage breakdown --group-by call_site
360
378
  $ assistant usage breakdown --group-by inference_profile
361
379
  $ assistant usage breakdown --group-by provider
380
+ $ assistant usage breakdown --schedule sched-abc123
362
381
  $ assistant usage breakdown --group-by actor --range week`,
363
382
  )
364
383
  .action(
@@ -366,6 +385,7 @@ Examples:
366
385
  range: string;
367
386
  from?: string;
368
387
  to?: string;
388
+ schedule?: string;
369
389
  json?: boolean;
370
390
  groupBy: string;
371
391
  }) => {
@@ -381,8 +401,7 @@ Examples:
381
401
  breakdown: UsageGroupBreakdown[];
382
402
  }>("usage_breakdown", {
383
403
  queryParams: {
384
- from: String(from),
385
- to: String(to),
404
+ ...buildUsageQueryParams(from, to, opts.schedule),
386
405
  groupBy: opts.groupBy,
387
406
  },
388
407
  });
@@ -401,6 +420,25 @@ Examples:
401
420
  });
402
421
  }
403
422
 
423
+ /**
424
+ * Build the shared usage query params, including scheduleId only when a
425
+ * schedule filter is provided.
426
+ */
427
+ function buildUsageQueryParams(
428
+ from: number,
429
+ to: number,
430
+ schedule?: string,
431
+ ): Record<string, string> {
432
+ const queryParams: Record<string, string> = {
433
+ from: String(from),
434
+ to: String(to),
435
+ };
436
+ if (schedule !== undefined) {
437
+ queryParams.scheduleId = schedule;
438
+ }
439
+ return queryParams;
440
+ }
441
+
404
442
  /** Resolve the time range from commander options. */
405
443
  function resolveRange(opts: { range: string; from?: string; to?: string }): {
406
444
  from: number;
@@ -0,0 +1,20 @@
1
+ import { describe, expect, test } from "bun:test";
2
+
3
+ import { formatCostUsd } from "../cli-output.js";
4
+
5
+ describe("formatCostUsd", () => {
6
+ test("renders zero as $0.00", () => {
7
+ expect(formatCostUsd(0)).toBe("$0.00");
8
+ });
9
+
10
+ test("renders sub-cent amounts with six decimal places", () => {
11
+ expect(formatCostUsd(0.0042)).toBe("$0.004200");
12
+ expect(formatCostUsd(0.000001)).toBe("$0.000001");
13
+ });
14
+
15
+ test("renders a cent or more with two decimal places", () => {
16
+ expect(formatCostUsd(0.0123)).toBe("$0.01");
17
+ expect(formatCostUsd(1.5)).toBe("$1.50");
18
+ expect(formatCostUsd(12.345)).toBe("$12.35");
19
+ });
20
+ });
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Shared stdout/error helpers for CLI subcommands that support a `--json`
3
+ * mode: plain line output, a JSON-aware error writer that sets the exit
4
+ * code, and a fixed-width table renderer for human-readable lists.
5
+ */
6
+
7
+ import { log } from "../logger.js";
8
+
9
+ export function writeLine(msg: string): void {
10
+ process.stdout.write(msg + "\n");
11
+ }
12
+
13
+ /**
14
+ * Format a USD cost with variable precision: "$0.00" for zero, six decimal
15
+ * places for sub-cent amounts, two decimal places otherwise.
16
+ */
17
+ export function formatCostUsd(usd: number): string {
18
+ if (usd === 0) {
19
+ return "$0.00";
20
+ }
21
+ if (usd < 0.01) {
22
+ return `$${usd.toFixed(6)}`;
23
+ }
24
+ return `$${usd.toFixed(2)}`;
25
+ }
26
+
27
+ /**
28
+ * Report a CLI failure and set `process.exitCode = 1`. In `--json` mode the
29
+ * error is emitted to stdout as `{ ok: false, error }` so machine callers
30
+ * always get a parseable body; otherwise it goes through the CLI logger.
31
+ */
32
+ export function writeCliError(message: string, json?: boolean): void {
33
+ if (json) {
34
+ process.stdout.write(JSON.stringify({ ok: false, error: message }) + "\n");
35
+ } else {
36
+ log.error(message);
37
+ }
38
+ process.exitCode = 1;
39
+ }
40
+
41
+ /** Render rows as a left-aligned fixed-width table with a header row. */
42
+ export function renderTable(headers: string[], rows: string[][]): void {
43
+ const widths = headers.map((h, i) =>
44
+ Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)),
45
+ );
46
+ const fmt = (cells: string[]) =>
47
+ cells
48
+ .map((c, i) => (c ?? "").padEnd(widths[i]!))
49
+ .join(" ")
50
+ .trimEnd();
51
+ writeLine(fmt(headers));
52
+ for (const row of rows) {
53
+ writeLine(fmt(row));
54
+ }
55
+ }