@vellumai/assistant 0.8.12-dev.202606152340.7efde97 → 0.8.12-dev.202606160320.367ef7c

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 (52) hide show
  1. package/docs/workflows.md +56 -20
  2. package/package.json +1 -1
  3. package/src/__tests__/conversation-history-web-search.test.ts +7 -0
  4. package/src/__tests__/conversation-surfaces-task-progress.test.ts +67 -0
  5. package/src/__tests__/db-schedule-syntax-migration.test.ts +1 -0
  6. package/src/__tests__/dynamic-page-surface.test.ts +75 -0
  7. package/src/__tests__/require-fresh-approval.test.ts +199 -1
  8. package/src/__tests__/schedule-routes-workflow-validation.test.ts +46 -0
  9. package/src/__tests__/schedule-store.test.ts +60 -0
  10. package/src/__tests__/schedule-tools.test.ts +136 -1
  11. package/src/__tests__/skill-execute-input.test.ts +85 -0
  12. package/src/__tests__/task-progress-nudge-hook.test.ts +372 -0
  13. package/src/__tests__/task-scheduler.test.ts +54 -0
  14. package/src/config/bundled-skills/schedule/SKILL.md +1 -1
  15. package/src/config/bundled-skills/schedule/TOOLS.json +20 -0
  16. package/src/config/bundled-skills/workflows/SKILL.md +208 -0
  17. package/src/config/bundled-skills/workflows/TOOLS.json +77 -0
  18. package/src/config/bundled-skills/workflows/tools/manage-workflows.ts +12 -0
  19. package/src/config/bundled-skills/workflows/tools/run-workflow.ts +12 -0
  20. package/src/config/bundled-tool-registry.ts +7 -0
  21. package/src/daemon/conversation-surfaces.ts +75 -0
  22. package/src/daemon/conversation-tool-setup.ts +2 -4
  23. package/src/ipc/gateway-flag-listener.ts +10 -8
  24. package/src/memory/db-init.ts +2 -0
  25. package/src/memory/migrations/290-schedule-capabilities.test.ts +77 -0
  26. package/src/memory/migrations/290-schedule-capabilities.ts +25 -0
  27. package/src/memory/migrations/index.ts +1 -0
  28. package/src/memory/schema/infrastructure.ts +1 -0
  29. package/src/permissions/threshold.ts +11 -0
  30. package/src/plugins/defaults/index.ts +22 -0
  31. package/src/plugins/defaults/task-progress-nudge/hooks/post-tool-use.ts +204 -0
  32. package/src/plugins/defaults/task-progress-nudge/package.json +15 -0
  33. package/src/prompts/__tests__/task-progress-hint-section.test.ts +5 -7
  34. package/src/prompts/templates/BOOTSTRAP-ACTIVATION-RAIL.md +3 -1
  35. package/src/prompts/templates/system-sections.ts +7 -2
  36. package/src/runtime/routes/schedule-routes.ts +5 -5
  37. package/src/runtime/routes/workflow-routes.test.ts +54 -20
  38. package/src/runtime/routes/workflow-routes.ts +20 -8
  39. package/src/schedule/schedule-store.ts +14 -0
  40. package/src/schedule/scheduler.ts +5 -5
  41. package/src/tools/executor.ts +17 -0
  42. package/src/tools/flag-gated-tools.test.ts +8 -21
  43. package/src/tools/permission-checker.ts +8 -1
  44. package/src/tools/registry.ts +4 -14
  45. package/src/tools/schedule/create.ts +29 -0
  46. package/src/tools/skills/execute.ts +56 -0
  47. package/src/tools/tool-manifest.ts +0 -31
  48. package/src/tools/ui-surface/definitions.ts +31 -2
  49. package/src/tools/workflows/manage-workflows.ts +25 -46
  50. package/src/tools/workflows/run-workflow.test.ts +78 -46
  51. package/src/tools/workflows/run-workflow.ts +13 -134
  52. package/src/workflows/capabilities.ts +4 -4
package/docs/workflows.md CHANGED
@@ -8,12 +8,14 @@ from each of a hundred documents, draft-then-verify a batch — and you want the
8
8
  results orchestrated deterministically and reported back when the whole run
9
9
  finishes.
10
10
 
11
- Workflows are gated behind the `workflows` feature flag (default **off**). When it
12
- is off, the `run_workflow` / `manage_workflows` tools are absent, the management
13
- routes 404, and the scheduler rejects `workflow`-mode jobs.
11
+ Workflows are gated behind the `workflows` feature flag (default **off**). The
12
+ `run_workflow` / `manage_workflows` tools are served by the flag-gated `workflows`
13
+ bundled skill rather than as always-on tools — load it with `skill_load` and invoke
14
+ its tools via `skill_execute`. When the flag is off, the skill is absent, the
15
+ management routes 404, and the scheduler rejects `workflow`-mode jobs.
14
16
 
15
17
  - Engine code: `assistant/src/workflows/`
16
- - Launching tools: `assistant/src/tools/workflows/`
18
+ - Skill (tool surface): `assistant/src/config/bundled-skills/workflows/`
17
19
  - Architecture overview: [`ARCHITECTURE.md` § Workflow Orchestration Engine](../../ARCHITECTURE.md#workflow-orchestration-engine)
18
20
  - Manual e2e runbook: [`workflows-testing.md`](./workflows-testing.md)
19
21
 
@@ -222,7 +224,7 @@ minus a forbidden set.
222
224
  launch approval, so it carries only read-only tools. `web_fetch` is **not**
223
225
  here — it is classified as a side-effect tool (its URL can exfiltrate read data
224
226
  or trigger external actions), so a run that needs it must declare it (which
225
- forces the launch approval gate).
227
+ arms the threshold-aware launch approval gate).
226
228
  - **Declared tools** must exist in the tool registry — an unknown name is a hard
227
229
  authoring error, not a silent drop.
228
230
  - **Forbidden tools** can never be granted, even if declared (declaring one is a
@@ -240,6 +242,28 @@ Side-effecting tools (`file_write`, sends, shell, …) and `persona` are **not**
240
242
  the baseline; a run must declare them. Once declared, every leaf may use them with
241
243
  no further prompting.
242
244
 
245
+ ### Launch and resume approval are threshold-aware
246
+
247
+ Declaring any side-effecting tool or host function arms a **launch approval**: the
248
+ single point at which the user consents to the whole run. It is threshold-aware —
249
+ at the full-access posture (auto-approve threshold `high`) it does **not** prompt;
250
+ in normal posture it prompts once. A read-only run (no declared side effects)
251
+ never prompts.
252
+
253
+ The same posture gates **resume** of a run whose stored manifest granted side
254
+ effects, since resuming restarts the unfinished side-effecting leaves:
255
+
256
+ - **Conversationally** (`manage_workflows` action `resume`): full access bypasses;
257
+ normal posture re-prompts for fresh approval.
258
+ - **Over HTTP** (`POST /v1/workflows/runs/:id/resume`, and the
259
+ `vellum workflows resume` CLI on top of it): full access proceeds; normal
260
+ posture is **refused** (403) and the caller is directed to resume through the
261
+ assistant, since the route has no prompt channel.
262
+
263
+ A read-only run resumes freely regardless of posture. The check is
264
+ `isFullAccessThreshold` in `assistant/src/permissions/threshold.ts`, applied in
265
+ `permission-checker.ts` and `workflow-routes.ts`.
266
+
243
267
  ---
244
268
 
245
269
  ## Worked examples
@@ -385,32 +409,43 @@ call `workflow()` — nesting deeper than one level throws.
385
409
  ### Scheduler `workflow` mode
386
410
 
387
411
  A scheduled job can trigger a saved workflow by name (e.g. "triage the inbox every
388
- morning"). In v1 the scheduler runs the workflow with **only the read-only
389
- baseline** — a scheduled run cannot be granted side-effecting tools. The trigger
390
- records success once the run starts; completion/failure is surfaced out-of-band
391
- via workflow events and the completion wake.
412
+ morning"). Each `workflow`-mode schedule carries a **persisted capability manifest**
413
+ (`capabilities_json` on `cron_jobs`), consented to **once at schedule creation**:
414
+ `schedule_create` accepts a `capabilities` manifest, validates it against the same
415
+ forbidden/unknown checks `run_workflow` applies, and — if it grants side effects —
416
+ arms the threshold-aware approval at creation time. Both firing paths (the
417
+ scheduler's auto-fire and the run-now `POST /v1/schedules/:id/run` route) execute
418
+ the run under that stored manifest. Legacy or null-manifest schedules fall back to
419
+ the read-only baseline. The trigger records success once the run starts;
420
+ completion/failure is surfaced out-of-band via workflow events and the completion
421
+ wake.
392
422
 
393
423
  ---
394
424
 
395
425
  ## Tools, routes, and CLI
396
426
 
397
- ### Tools (flag-gated)
427
+ ### Tools (served by the `workflows` skill)
428
+
429
+ Reached via the skill (`skill_load` then `skill_execute`), not as always-on tools.
398
430
 
399
431
  - **`run_workflow`** — `{ script?, name?, args?, capabilities?, label? }` (exactly
400
432
  one of `script`/`name`). Returns `{ runId }` immediately; the run is
401
433
  asynchronous and you are notified in the conversation when it completes. **Do
402
434
  not poll.**
403
- - **`manage_workflows`** — `{ action: "status" | "abort" | "list_runs", run_id? }`.
404
- `status`/`abort` require `run_id`.
435
+ - **`manage_workflows`** — `{ action: "status" | "abort" | "resume" | "list_runs"
436
+ | "list_profiles", run_id? }`. `status`/`abort`/`resume` require `run_id`.
437
+ `list_profiles` returns `{ profiles, activeProfile }` — the defined LLM profile
438
+ names plus the workspace active profile, used to pick a valid leaf `profile`.
405
439
 
406
- ### Routes (read/abort, all 404 when the flag is off)
440
+ ### Routes (read/abort/resume, all 404 when the flag is off)
407
441
 
408
- | Method | Path | Purpose |
409
- | ------ | ------------------------------ | ----------------------------------------------------- |
410
- | `GET` | `/v1/workflows` | List saved (named) workflows. |
411
- | `GET` | `/v1/workflows/runs` | List recent runs (newest first); `?limit`, `?status`. |
412
- | `GET` | `/v1/workflows/runs/:id` | Get one run. |
413
- | `POST` | `/v1/workflows/runs/:id/abort` | Signal an in-flight run to abort. |
442
+ | Method | Path | Purpose |
443
+ | ------ | ------------------------------- | ---------------------------------------------------------------------------------------------------- |
444
+ | `GET` | `/v1/workflows` | List saved (named) workflows. |
445
+ | `GET` | `/v1/workflows/runs` | List recent runs (newest first); `?limit`, `?status`. |
446
+ | `GET` | `/v1/workflows/runs/:id` | Get one run. |
447
+ | `POST` | `/v1/workflows/runs/:id/abort` | Signal an in-flight run to abort. |
448
+ | `POST` | `/v1/workflows/runs/:id/resume` | Resume an interrupted run (refuses a side-effecting run in normal posture; proceeds at full access). |
414
449
 
415
450
  ### CLI
416
451
 
@@ -419,6 +454,7 @@ vellum workflows list # saved (named) workflows
419
454
  vellum workflows runs # recent runs (--limit, --status)
420
455
  vellum workflows show <run-id> # one run's status + counts
421
456
  vellum workflows abort <run-id> # abort an in-flight run
457
+ vellum workflows resume <run-id> # resume an interrupted run
422
458
  ```
423
459
 
424
460
  All subcommands accept `--assistant <name>` to target a specific instance.
@@ -440,7 +476,7 @@ Engine caps live under `workflows.*` in assistant config:
440
476
 
441
477
  ## Persistence and resume
442
478
 
443
- Run state lives in two tables (migration 282):
479
+ Run state lives in two tables (migration 284):
444
480
 
445
481
  - **`workflow_runs`** — one row per run: status (`running` / `completed` /
446
482
  `failed` / `aborted` / `cap_exceeded` / `interrupted`), agent/token counts,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.8.12-dev.202606152340.7efde97",
3
+ "version": "0.8.12-dev.202606160320.367ef7c",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -796,6 +796,13 @@ describe("web_search_tool_result structural guard", () => {
796
796
  // conservative direction (fewer nudges). Same reasoning as agent/loop.ts.
797
797
  "plugins/defaults/exploration-drift/hooks/post-tool-use.ts",
798
798
 
799
+ // Detects turn boundaries by checking whether a user message carries any
800
+ // tool_result block (internal continuation) vs. none (genuine user prompt).
801
+ // A web_search_tool_result-only message is also internal, but treating one
802
+ // as a boundary only bounds the round count early — the conservative
803
+ // direction (fewer nudges). Same reasoning as exploration-drift above.
804
+ "plugins/defaults/task-progress-nudge/hooks/post-tool-use.ts",
805
+
799
806
  // Reconciles synthesized cancellation tool_results for locally-executed
800
807
  // tools only. Same reasoning as agent/loop.ts above.
801
808
  "daemon/conversation-agent-loop.ts",
@@ -208,6 +208,73 @@ describe("task_progress surface compatibility", () => {
208
208
  );
209
209
  });
210
210
 
211
+ test("ui_show fills well-formed templateData for a stepless task_progress card", async () => {
212
+ const sent: ServerMessage[] = [];
213
+ const ctx = makeContext(sent);
214
+
215
+ const result = await surfaceProxyResolver(ctx, "ui_show", {
216
+ surface_type: "card",
217
+ title: "Researching",
218
+ template: "task_progress",
219
+ data: {},
220
+ });
221
+
222
+ expect(result.isError).toBe(false);
223
+
224
+ const showMessage = sent.find(
225
+ (msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
226
+ );
227
+ expect(showMessage).toBeDefined();
228
+ if (!showMessage || showMessage.surfaceType !== "card") return;
229
+
230
+ const card = showMessage.data as CardSurfaceData;
231
+ expect(card.template).toBe("task_progress");
232
+ const templateData = card.templateData as Record<string, unknown>;
233
+ expect(templateData.status).toBe("in_progress");
234
+ expect(templateData.title).toBe("Researching");
235
+ expect(templateData.steps).toEqual([]);
236
+ });
237
+
238
+ test("ui_show coerces invalid status and malformed steps on a task_progress card", async () => {
239
+ const sent: ServerMessage[] = [];
240
+ const ctx = makeContext(sent);
241
+
242
+ const result = await surfaceProxyResolver(ctx, "ui_show", {
243
+ surface_type: "card",
244
+ title: "Building",
245
+ template: "task_progress",
246
+ templateData: {
247
+ status: "working",
248
+ steps: [
249
+ { label: "Valid step" },
250
+ { title: "Aliased label", status: "completed" },
251
+ { status: "in_progress" },
252
+ "not an object",
253
+ ],
254
+ },
255
+ });
256
+
257
+ expect(result.isError).toBe(false);
258
+
259
+ const showMessage = sent.find(
260
+ (msg): msg is UiSurfaceShow => msg.type === "ui_surface_show",
261
+ );
262
+ expect(showMessage).toBeDefined();
263
+ if (!showMessage || showMessage.surfaceType !== "card") return;
264
+
265
+ const templateData = (showMessage.data as CardSurfaceData)
266
+ .templateData as Record<string, unknown>;
267
+ expect(templateData.status).toBe("in_progress");
268
+ const steps = templateData.steps as Array<Record<string, unknown>>;
269
+ expect(steps).toHaveLength(2);
270
+ expect(steps[0]).toEqual({ label: "Valid step", status: "pending" });
271
+ expect(steps[1]).toEqual({
272
+ title: "Aliased label",
273
+ label: "Aliased label",
274
+ status: "completed",
275
+ });
276
+ });
277
+
211
278
  test("ui_show normalizes top-level dynamic_page fields into data", async () => {
212
279
  const sent: ServerMessage[] = [];
213
280
  const ctx = makeContext(sent);
@@ -54,6 +54,7 @@ describe("schedule_syntax column migration", () => {
54
54
  workflow_args_json TEXT,
55
55
  timeout_ms INTEGER,
56
56
  inference_profile TEXT,
57
+ capabilities_json TEXT,
57
58
  description TEXT NOT NULL DEFAULT '',
58
59
  created_at INTEGER NOT NULL,
59
60
  updated_at INTEGER NOT NULL
@@ -206,6 +206,81 @@ describe("ui_show dynamic_page app substitute guard", () => {
206
206
  });
207
207
  });
208
208
 
209
+ // ---------------------------------------------------------------------------
210
+ // task_progress ui_show appends the update hint to its return value
211
+ // ---------------------------------------------------------------------------
212
+
213
+ describe("ui_show task_progress update hint", () => {
214
+ const ctx = {
215
+ conversationId: "conversation-123",
216
+ workingDir: "/tmp",
217
+ trustClass: "guardian" as const,
218
+ proxyToolResolver: async () => ({
219
+ content: "Surface displayed (surface_id: surf-1).",
220
+ isError: false,
221
+ }),
222
+ };
223
+
224
+ test("appends the ui_update hint after a task_progress card is shown", async () => {
225
+ const result = await uiShowTool.execute(
226
+ {
227
+ surface_type: "card",
228
+ template: "task_progress",
229
+ templateData: { status: "in_progress", steps: [] },
230
+ },
231
+ ctx,
232
+ );
233
+
234
+ expect(result.isError).toBe(false);
235
+ expect(result.content).toContain("Surface displayed (surface_id: surf-1).");
236
+ expect(result.content).toContain("call ui_update with this surface_id");
237
+ });
238
+
239
+ test("recognizes task_progress nested under data", async () => {
240
+ const result = await uiShowTool.execute(
241
+ {
242
+ surface_type: "card",
243
+ data: {
244
+ template: "task_progress",
245
+ templateData: { status: "in_progress" },
246
+ },
247
+ },
248
+ ctx,
249
+ );
250
+
251
+ expect(result.content).toContain("call ui_update with this surface_id");
252
+ });
253
+
254
+ test("does not append the hint for a non-task_progress card", async () => {
255
+ const result = await uiShowTool.execute(
256
+ { surface_type: "card", data: { title: "Plain", body: "hi" } },
257
+ ctx,
258
+ );
259
+
260
+ expect(result.content).toBe("Surface displayed (surface_id: surf-1).");
261
+ });
262
+
263
+ test("does not append the hint when the surface call errors", async () => {
264
+ const result = await uiShowTool.execute(
265
+ {
266
+ surface_type: "card",
267
+ template: "task_progress",
268
+ templateData: { status: "in_progress" },
269
+ },
270
+ {
271
+ ...ctx,
272
+ proxyToolResolver: async () => ({
273
+ content: "blocked on this channel",
274
+ isError: true,
275
+ }),
276
+ },
277
+ );
278
+
279
+ expect(result.isError).toBe(true);
280
+ expect(result.content).toBe("blocked on this channel");
281
+ });
282
+ });
283
+
209
284
  // ---------------------------------------------------------------------------
210
285
  // UiSurfaceShowDynamicPage structure
211
286
  // ---------------------------------------------------------------------------
@@ -68,6 +68,13 @@ let riskOverride: string = "high";
68
68
  /** Scope options override — controls whether persistent decisions are offered. */
69
69
  let scopeOptionsOverride: ScopeOption[] | undefined;
70
70
 
71
+ /**
72
+ * Auto-approve threshold returned to the permission checker. "high" is the
73
+ * full-access posture under which the requireFreshApproval promotion is
74
+ * skipped; every lower value still promotes allow → prompt.
75
+ */
76
+ let thresholdOverride: "none" | "low" | "medium" | "high" = "medium";
77
+
71
78
  mock.module("../config/loader.js", () => ({
72
79
  getConfig: () => mockConfig,
73
80
  loadConfig: () => mockConfig,
@@ -124,7 +131,7 @@ mock.module("../tools/registry.js", () => ({
124
131
  }));
125
132
 
126
133
  mock.module("../permissions/gateway-threshold-reader.js", () => ({
127
- getAutoApproveThreshold: async () => "medium",
134
+ getAutoApproveThreshold: async () => thresholdOverride,
128
135
  // Refresh failure ("null") keeps the original decision — these tests
129
136
  // exercise the cached-threshold paths only.
130
137
  refreshAutoApproveThreshold: async () => null,
@@ -186,6 +193,7 @@ describe("requireFreshApproval: non-interactive guardian denial", () => {
186
193
  checkResultOverride = undefined;
187
194
  scopeOptionsOverride = undefined;
188
195
  riskOverride = "high";
196
+ thresholdOverride = "medium";
189
197
  });
190
198
 
191
199
  afterEach(() => {});
@@ -335,6 +343,7 @@ describe("requireFreshApproval: persistent decisions disabled", () => {
335
343
  checkResultOverride = undefined;
336
344
  scopeOptionsOverride = undefined;
337
345
  riskOverride = "high";
346
+ thresholdOverride = "medium";
338
347
  });
339
348
 
340
349
  afterEach(() => {});
@@ -398,6 +407,7 @@ describe("requireFreshApproval: grant-consumed does not skip permission check",
398
407
  checkResultOverride = undefined;
399
408
  scopeOptionsOverride = undefined;
400
409
  riskOverride = "high";
410
+ thresholdOverride = "medium";
401
411
  });
402
412
 
403
413
  afterEach(() => {});
@@ -450,6 +460,7 @@ describe("requireFreshApproval: context flag propagation", () => {
450
460
  checkResultOverride = undefined;
451
461
  scopeOptionsOverride = undefined;
452
462
  riskOverride = "high";
463
+ thresholdOverride = "medium";
453
464
  });
454
465
 
455
466
  afterEach(() => {});
@@ -503,6 +514,7 @@ describe("requireFreshApproval: workflow capability grants", () => {
503
514
  checkResultOverride = undefined;
504
515
  scopeOptionsOverride = undefined;
505
516
  riskOverride = "low";
517
+ thresholdOverride = "medium";
506
518
  fakeWorkflowRun = null;
507
519
  });
508
520
 
@@ -539,6 +551,104 @@ describe("requireFreshApproval: workflow capability grants", () => {
539
551
  expect(result.isError).toBe(false);
540
552
  });
541
553
 
554
+ test.each(["none", "low", "medium"] as const)(
555
+ "run_workflow side-effecting launch prompts at the %s threshold (non-full-access posture)",
556
+ async (threshold) => {
557
+ checkResultOverride = { decision: "allow", reason: "allowed" };
558
+ thresholdOverride = threshold;
559
+ const state = { prompted: false };
560
+ const executor = new ToolExecutor(trackingPrompter(state));
561
+ const ctx = makeContext();
562
+
563
+ const result = await executor.execute(
564
+ "run_workflow",
565
+ { script: "export const meta={};", capabilities: { tools: ["bash"] } },
566
+ ctx,
567
+ );
568
+
569
+ expect(ctx.requireFreshApproval).toBe(true);
570
+ expect(state.prompted).toBe(true);
571
+ expect(result.isError).toBe(false);
572
+ },
573
+ );
574
+
575
+ test("run_workflow side-effecting launch does NOT prompt at full access (high)", async () => {
576
+ // Full-access posture auto-approves even high-risk tools, so the
577
+ // requireFreshApproval promotion is skipped — the grant auto-allows.
578
+ checkResultOverride = { decision: "allow", reason: "allowed" };
579
+ thresholdOverride = "high";
580
+ const state = { prompted: false };
581
+ const executor = new ToolExecutor(trackingPrompter(state));
582
+ const ctx = makeContext();
583
+
584
+ const result = await executor.execute(
585
+ "run_workflow",
586
+ { script: "export const meta={};", capabilities: { tools: ["bash"] } },
587
+ ctx,
588
+ );
589
+
590
+ // requireFreshApproval is still SET on the context (launch is
591
+ // side-effecting); only the allow → prompt promotion is suppressed.
592
+ expect(ctx.requireFreshApproval).toBe(true);
593
+ expect(state.prompted).toBe(false);
594
+ expect(result.isError).toBe(false);
595
+ });
596
+
597
+ test("a deny rule still blocks a side-effecting launch at full access (high)", async () => {
598
+ // Full access skips the fresh-approval promotion but never overrides an
599
+ // explicit deny — deny rules win regardless of posture.
600
+ checkResultOverride = { decision: "deny", reason: "blocked by rule" };
601
+ thresholdOverride = "high";
602
+ const state = { prompted: false };
603
+ const executor = new ToolExecutor(trackingPrompter(state));
604
+ const ctx = makeContext();
605
+
606
+ const result = await executor.execute(
607
+ "run_workflow",
608
+ { script: "export const meta={};", capabilities: { tools: ["bash"] } },
609
+ ctx,
610
+ );
611
+
612
+ expect(state.prompted).toBe(false);
613
+ expect(result.isError).toBe(true);
614
+ });
615
+
616
+ test("a deny rule still blocks a side-effecting launch at a normal threshold", async () => {
617
+ checkResultOverride = { decision: "deny", reason: "blocked by rule" };
618
+ thresholdOverride = "medium";
619
+ const state = { prompted: false };
620
+ const executor = new ToolExecutor(trackingPrompter(state));
621
+ const ctx = makeContext();
622
+
623
+ const result = await executor.execute(
624
+ "run_workflow",
625
+ { script: "export const meta={};", capabilities: { tools: ["bash"] } },
626
+ ctx,
627
+ );
628
+
629
+ expect(state.prompted).toBe(false);
630
+ expect(result.isError).toBe(true);
631
+ });
632
+
633
+ test("a read-only launch (no requireFreshApproval) is unaffected by a normal threshold", async () => {
634
+ // No requireFreshApproval means the allow stands untouched at any posture.
635
+ checkResultOverride = { decision: "allow", reason: "allowed" };
636
+ thresholdOverride = "medium";
637
+ const state = { prompted: false };
638
+ const executor = new ToolExecutor(trackingPrompter(state));
639
+ const ctx = makeContext();
640
+
641
+ const result = await executor.execute(
642
+ "run_workflow",
643
+ { script: "export const meta={};", capabilities: {} },
644
+ ctx,
645
+ );
646
+
647
+ expect(ctx.requireFreshApproval).toBeUndefined();
648
+ expect(state.prompted).toBe(false);
649
+ expect(result.isError).toBe(false);
650
+ });
651
+
542
652
  test("run_workflow granting host functions prompts at launch", async () => {
543
653
  checkResultOverride = { decision: "allow", reason: "allowed" };
544
654
  const state = { prompted: false };
@@ -575,6 +685,94 @@ describe("requireFreshApproval: workflow capability grants", () => {
575
685
  expect(result.isError).toBe(false);
576
686
  });
577
687
 
688
+ test("workflow-mode schedule_create granting side-effecting tools prompts at creation", async () => {
689
+ checkResultOverride = { decision: "allow", reason: "allowed" };
690
+ const state = { prompted: false };
691
+ const executor = new ToolExecutor(trackingPrompter(state));
692
+ const ctx = makeContext();
693
+
694
+ const result = await executor.execute(
695
+ "schedule_create",
696
+ {
697
+ name: "Nightly writeback",
698
+ mode: "workflow",
699
+ workflow_name: "nightly-report",
700
+ capabilities: { tools: ["bash"] },
701
+ },
702
+ ctx,
703
+ );
704
+
705
+ expect(ctx.requireFreshApproval).toBe(true);
706
+ expect(state.prompted).toBe(true);
707
+ expect(result.isError).toBe(false);
708
+ });
709
+
710
+ test("workflow-mode schedule_create granting host functions prompts at creation", async () => {
711
+ checkResultOverride = { decision: "allow", reason: "allowed" };
712
+ const state = { prompted: false };
713
+ const executor = new ToolExecutor(trackingPrompter(state));
714
+ const ctx = makeContext();
715
+
716
+ await executor.execute(
717
+ "schedule_create",
718
+ {
719
+ name: "Nightly notify",
720
+ mode: "workflow",
721
+ workflow_name: "nightly-report",
722
+ capabilities: { hostFunctions: ["notify"] },
723
+ },
724
+ ctx,
725
+ );
726
+
727
+ expect(ctx.requireFreshApproval).toBe(true);
728
+ expect(state.prompted).toBe(true);
729
+ });
730
+
731
+ test("workflow-mode schedule_create with a read-only manifest stays silent", async () => {
732
+ checkResultOverride = { decision: "allow", reason: "allowed" };
733
+ const state = { prompted: false };
734
+ const executor = new ToolExecutor(trackingPrompter(state));
735
+ const ctx = makeContext();
736
+
737
+ const result = await executor.execute(
738
+ "schedule_create",
739
+ {
740
+ name: "Read-only schedule",
741
+ mode: "workflow",
742
+ workflow_name: "nightly-report",
743
+ capabilities: {},
744
+ },
745
+ ctx,
746
+ );
747
+
748
+ expect(ctx.requireFreshApproval).toBeUndefined();
749
+ expect(state.prompted).toBe(false);
750
+ expect(result.isError).toBe(false);
751
+ });
752
+
753
+ test("non-workflow schedule_create never gates even with a side-effecting capabilities blob", async () => {
754
+ // The capabilities field is workflow-mode only; an execute-mode schedule
755
+ // must not be promoted to a fresh approval by a stray capabilities object.
756
+ checkResultOverride = { decision: "allow", reason: "allowed" };
757
+ const state = { prompted: false };
758
+ const executor = new ToolExecutor(trackingPrompter(state));
759
+ const ctx = makeContext();
760
+
761
+ await executor.execute(
762
+ "schedule_create",
763
+ {
764
+ name: "Execute schedule",
765
+ mode: "execute",
766
+ message: "do the thing",
767
+ capabilities: { tools: ["bash"] },
768
+ },
769
+ ctx,
770
+ );
771
+
772
+ expect(ctx.requireFreshApproval).toBeUndefined();
773
+ expect(state.prompted).toBe(false);
774
+ });
775
+
578
776
  test("manage_workflows resume of a side-effecting run requires fresh approval", async () => {
579
777
  // The target run's STORED manifest granted tools, so resuming it (which
580
778
  // restarts unfinished side-effecting leaves) must re-prompt.
@@ -319,6 +319,52 @@ describe("POST /schedules/:id/run — workflow mode triggers the workflow", () =
319
319
  expect(Array.isArray(result.schedules)).toBe(true);
320
320
  });
321
321
 
322
+ test("fires with the schedule's stored side-effecting manifest", async () => {
323
+ const schedule = createSchedule({
324
+ name: "Side-effecting workflow",
325
+ cronExpression: "0 9 * * *",
326
+ message: "",
327
+ syntax: "cron",
328
+ mode: "workflow",
329
+ workflowName: "send-report",
330
+ capabilities: {
331
+ tools: ["file_write"],
332
+ hostFunctions: ["notify"],
333
+ persona: true,
334
+ },
335
+ });
336
+
337
+ await runNowRoute().handler({ pathParams: { id: schedule.id } });
338
+
339
+ expect(workflowStartCalls).toHaveLength(1);
340
+ expect(workflowStartCalls[0]!.manifest).toEqual({
341
+ tools: ["file_write"],
342
+ hostFunctions: ["notify"],
343
+ persona: true,
344
+ });
345
+ });
346
+
347
+ test("a legacy schedule (null capabilities) fires with the read-only baseline", async () => {
348
+ const schedule = createSchedule({
349
+ name: "Legacy workflow",
350
+ cronExpression: "0 9 * * *",
351
+ message: "",
352
+ syntax: "cron",
353
+ mode: "workflow",
354
+ workflowName: "triage-inbox",
355
+ capabilities: null,
356
+ });
357
+
358
+ await runNowRoute().handler({ pathParams: { id: schedule.id } });
359
+
360
+ expect(workflowStartCalls).toHaveLength(1);
361
+ expect(workflowStartCalls[0]!.manifest).toEqual({
362
+ tools: [],
363
+ hostFunctions: [],
364
+ persona: false,
365
+ });
366
+ });
367
+
322
368
  test("rejects a workflow schedule with no workflowName", async () => {
323
369
  // Defensive guard mirroring the scheduler's automatic firing path; a
324
370
  // nameless workflow schedule cannot be created via the routes, but the store