@wular/coder 0.3.14 → 0.3.16
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 +42 -42
- package/dist/flow/index.js +1 -1
- package/dist/runtime-SneScSWY.js +25 -0
- package/dist/sdk.js +1 -1
- package/dist/upgrade-Cjbeytvs.js +37 -0
- package/docs/sdk.md +4 -2
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/cursor/.cursor-plugin/plugin.json +1 -1
- package/dist/runtime-9CD0_h4s.js +0 -19
- package/dist/upgrade-pCzfMZc6.js +0 -36
package/dist/cli.js
CHANGED
|
@@ -1,83 +1,83 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{B as e,E as t,H as n,I as r,L as i,M as a,N as o,O as s,R as c,V as l,_ as u,b as d,c as f,d as p,f as m,j as h,l as g,m as _,o as v,s as y,u as b}from"./app-server-bHl6RBZ2.js";import{$ as ee,$t as x,A as S,At as C,B as te,Ct as w,D as
|
|
2
|
+
import{B as e,E as t,H as n,I as r,L as i,M as a,N as o,O as s,R as c,V as l,_ as u,b as d,c as f,d as p,f as m,j as h,l as g,m as _,o as v,s as y,u as b}from"./app-server-bHl6RBZ2.js";import{$ as ee,$t as x,A as S,At as C,B as te,Ct as w,D as ne,Dt as re,Et as T,F as ie,Ft as ae,Gt as oe,I as se,It as ce,Jt as le,Kt as E,L as ue,M as D,Mt as de,N as fe,O as pe,Ot as me,Qt as he,R as ge,Rt as _e,S as ve,St as ye,T as be,Tt as xe,Ut as O,Vt as Se,Wt as k,Xt as Ce,Y as we,Yt as Te,_ as Ee,a as De,an as A,b as Oe,ct as j,d as ke,dn as Ae,dt as je,en as M,ft as Me,g as N,h as Ne,in as Pe,j as Fe,jt as Ie,l as Le,ln as Re,n as ze,nn as Be,on as Ve,p as He,pt as Ue,qt as P,r as We,rn as F,rt as I,s as Ge,sn as Ke,st as qe,t as Je,tn as L,u as Ye,un as Xe,v as R,w as Ze,wt as Qe,x as $e,xt as et,y as tt,yt as nt,zt as rt}from"./runtime-SneScSWY.js";import{C as it,E as z,O as at,a as ot,h as st,k as ct,p as lt,r as ut,t as dt,v as ft,w as pt,x as mt}from"./upgrade-Cjbeytvs.js";import B from"node:process";import V from"node:fs";import H from"node:path";import{spawn as ht,spawnSync as gt}from"node:child_process";import _t from"node:os";import*as U from"zod/mini";import vt from"node:readline";import{randomUUID as yt}from"node:crypto";const bt=[[`--wait`,`run in the foreground and block until the answer is ready`],[`--agent <codex|claude|custom>`,`engine to use; custom runs your configured custom models (default: first in the chain)`],[`--model <alias|slug>`,`spark/luna/terra/sol (codex) · haiku/sonnet/opus/fable (claude) · a custom model (coder model list)`],[`--effort <low|medium|high>`,`reasoning effort`],[`--permissions <mode>`,`read-only · workspace-write · auto (default: auto)`],[`--resume <task-id>`,`continue that task's thread instead of a fresh run`],[`--json`,`machine-readable JSON output`]],W=[`--cwd <dir>`,`workspace directory (default: current)`],G=[`--json`,`JSON output`],xt=[{sub:`run`,usage:`run "<text>"`,blurb:`run a task (background; --wait blocks)`,alias:`run`},{sub:`list`,usage:`list`,blurb:`list recent tasks (running + just stopped)`,alias:`list`},{sub:`result`,usage:`result [task-id]`,blurb:`status + final answer (--wait blocks)`,alias:`result`},{sub:`watch`,usage:`watch [task-id]`,blurb:`watch a task live (progress log)`,alias:`watch`},{sub:`steer`,usage:`steer <task-id> "<follow-up>"`,blurb:`continue a task's thread`},{sub:`ask`,usage:`ask <task-id> "<question>"`,blurb:`ask about a task without interrupting it`},{sub:`stop`,usage:`stop <task-id>`,blurb:`interrupt a running task`},{sub:`archive`,usage:`archive <task-id>`,blurb:`archive a session (or --all-stopped)`},{sub:`delete`,usage:`delete <task-id>`,blurb:`delete a session (or --all-archived)`},{sub:`approvals`,usage:`approvals [task-id]`,blurb:`pending approvals (all tasks, or one)`},{sub:`approve`,usage:`approve <id>`,blurb:`answer an escalated permission`}],K={"task run":{list:[`task run "<text>"`,`run a coding task (background; --wait blocks)`],usage:`coder task run "<task text>"`,summary:`Dispatch a coding task to the configured engine. Backgrounds by default and
|
|
3
3
|
prints a task id; --wait runs in the foreground and prints the answer.
|
|
4
|
-
Shortcut: \`coder run "<text>"\`.`,flags:[[`--name <name>`,`label the task (shown in list/result)`],[`--system <text>`,`standing instructions prepended to the task (kept out of prompt previews)`],...
|
|
4
|
+
Shortcut: \`coder run "<text>"\`.`,flags:[[`--name <name>`,`label the task (shown in list/result)`],[`--system <text>`,`standing instructions prepended to the task (kept out of prompt previews)`],...bt,W],examples:[[`coder run "add a /health endpoint"`,`dispatch in the background, print a task id`],[`coder result <task-id> --wait`,`then block until it finishes and print the answer`],[`coder run --wait "fix the failing test"`,`or block on the run itself`],[`coder task run --model spark --system "tests live in test/, don't touch anything outside of it" "rename foo to bar"`,`pick an engine via its model alias; --system adds standing instructions`]],seeAlso:`task result · task steer · task stop · task watch`},"task list":{list:[`task list [--running|--stopped|--archived]`,`list recent tasks (running + just stopped)`],usage:`coder task list [--running] [--stopped] [--archived [--limit N]]`,summary:`List recent tasks across all workspaces, most recent first: running tasks plus
|
|
5
5
|
ones stopped within the last 10 minutes. Older stopped tasks auto-archive and
|
|
6
|
-
move to --archived. Shortcut: \`coder list\`.`,flags:[[`--running`,`show only running tasks`],[`--stopped`,`show only recently stopped tasks (not yet archived)`],[`--archived`,`show only archived tasks (auto-archived or via task archive)`],[`--limit <n|all>`,`show at most n tasks (default all)`],[`--dir <dir>`,`only tasks launched in that workspace`],
|
|
6
|
+
move to --archived. Shortcut: \`coder list\`.`,flags:[[`--running`,`show only running tasks`],[`--stopped`,`show only recently stopped tasks (not yet archived)`],[`--archived`,`show only archived tasks (auto-archived or via task archive)`],[`--limit <n|all>`,`show at most n tasks (default all)`],[`--dir <dir>`,`only tasks launched in that workspace`],G],seeAlso:`task result · task archive · task delete`},"task result":{list:[`task result [task-id]`,`status + final answer of a task`],usage:`coder task result [task-id]`,summary:`Show a task's status and its final answer (result pending while it runs), plus
|
|
7
7
|
any pending approvals. --wait blocks until it finishes, then prints. --tail <n>
|
|
8
8
|
includes the last n progress-log steps (--tail all for the whole transcript).
|
|
9
|
-
Defaults to the most recent task. Shortcut: \`coder result\`.`,flags:[[`--wait`,`block until the task finishes, then print`],[`--turns`,`every turn's answer (a steered task accretes turns)`],[`--tail <n|all>`,`include the last n progress-log steps (default: 0, final result only)`],
|
|
9
|
+
Defaults to the most recent task. Shortcut: \`coder result\`.`,flags:[[`--wait`,`block until the task finishes, then print`],[`--turns`,`every turn's answer (a steered task accretes turns)`],[`--tail <n|all>`,`include the last n progress-log steps (default: 0, final result only)`],G,W],examples:[[`coder result <task-id> --wait`,`block until the task finishes, print the answer`],[`coder result <task-id> --turns`,`every turn's answer for a steered task`]],seeAlso:`task list · task steer · task watch`},"task watch":{list:[`task watch [task-id]`,`watch a task live (progress log)`],usage:`coder task watch [task-id]`,summary:`Watch a running task's progress log live (for you/debugging), then print its
|
|
10
10
|
final answer. Replays the last line first so the current step is visible;
|
|
11
11
|
--tail <n> replays the last n lines (--tail all for the whole transcript).
|
|
12
12
|
Blocks until it finishes; exits 0 on success, 1 otherwise. For the answer
|
|
13
|
-
alone, prefer \`coder result\`. Alias: stream.`,flags:[[`--tail <n|all>`,`replay the last n log lines first (default: 1)`],[`--trim <n|none>`,`
|
|
13
|
+
alone, prefer \`coder result\`. Alias: stream.`,flags:[[`--tail <n|all>`,`replay the last n log lines first (default: 1)`],[`--trim <n|none>`,`budget for tool output and thinking (default: 1200 chars, 12 lines)`],[`--json`,`emit each log entry as a JSON line, then the result`],W],examples:[[`coder watch`,`follow the most recent task to completion`]],seeAlso:`task result · task run`},"task ask":{list:[`task ask <task-id> "<question>"`,`ask about a task without interrupting it`],usage:`coder task ask <task-id> "<question>"`,summary:`Answer a question ABOUT a task without touching it: a read-only sidecar reads
|
|
14
14
|
the task's progress log, result, and workspace and answers; the task never
|
|
15
15
|
sees the question and its thread is not steered. Works whether the task is
|
|
16
|
-
running or stopped. To change what the task does, use \`coder task steer\`.`,flags:[[`--model <alias|slug>`,`sidecar model (default: the task's own)`],[`--effort <low|medium|high>`,`sidecar reasoning effort`],
|
|
16
|
+
running or stopped. To change what the task does, use \`coder task steer\`.`,flags:[[`--model <alias|slug>`,`sidecar model (default: the task's own)`],[`--effort <low|medium|high>`,`sidecar reasoning effort`],G,W],examples:[[`coder task ask task-abc "what approach did you take and why?"`,`probe a decision without derailing the task`]],seeAlso:`task steer · task result · task watch`},"task steer":{list:[`task steer <task-id> "<follow-up>"`,`continue a task's thread`],usage:`coder task steer <task-id> "<follow-up instructions>" [--wait]`,summary:`Continue a task's thread with new instructions: injected into a live Codex or
|
|
17
17
|
Claude turn at its next tool boundary, queued across a startup/completion race,
|
|
18
18
|
or — for a stopped task — resumed on the same task id. Reuses the task's engine,
|
|
19
|
-
model, and permissions unless overridden.`,flags:[[`--wait`,`run in the foreground and block until the answer is ready`],[`--model <alias|slug>`,`override the task's model for this follow-up`],[`--effort <low|medium|high>`,`override the task's reasoning effort`],[`--permissions <mode>`,`read-only · workspace-write · auto`],
|
|
19
|
+
model, and permissions unless overridden.`,flags:[[`--wait`,`run in the foreground and block until the answer is ready`],[`--model <alias|slug>`,`override the task's model for this follow-up`],[`--effort <low|medium|high>`,`override the task's reasoning effort`],[`--permissions <mode>`,`read-only · workspace-write · auto`],W],examples:[[`coder task steer task-abc "now add tests"`,`continue that task with a follow-up`]],seeAlso:`task run · task stop`},"task stop":{list:[`task stop <task-id>`,`interrupt a running task`],usage:`coder task stop <task-id>`,summary:`Interrupt a running task and mark it cancelled.`,flags:[G,W],seeAlso:`task result · task steer`},"task archive":{list:[`task archive <task-id> | --all-stopped`,`hide a task (or all stopped) from the list`],usage:`coder task archive <task-id> | coder task archive --all-stopped`,summary:`Archive a task session so it drops out of the default list (see it again with
|
|
20
20
|
\`coder task list --archived [--limit N]\`). Pass --all-stopped to archive every
|
|
21
|
-
finished task.`,flags:[[`--all-stopped`,`archive every stopped (finished) task`],
|
|
22
|
-
delete every archived task at once. A running task must be stopped first.`,flags:[[`--all-archived`,`delete every archived task`],
|
|
21
|
+
finished task.`,flags:[[`--all-stopped`,`archive every stopped (finished) task`],G,W],seeAlso:`task list · task delete`},"task delete":{list:[`task delete <task-id> | --all-archived`,`delete a task session (or all archived)`],usage:`coder task delete <task-id> | coder task delete --all-archived`,summary:`Delete a task's session from disk. This is permanent. Pass --all-archived to
|
|
22
|
+
delete every archived task at once. A running task must be stopped first.`,flags:[[`--all-archived`,`delete every archived task`],G,W],seeAlso:`task archive · task stop`},"task approvals":{list:[`task approvals [task-id]`,`pending approvals (all tasks, or one)`],usage:`coder task approvals [task-id]`,summary:"Without a task id: pending approvals across all tasks. With one: that task's\npermission escalations and how each was answered. Shortcut: `coder approvals`.",flags:[G,W],seeAlso:`task approve`},"task approve":{list:[`task approve <id> [--deny]`,`answer an escalated permission`],usage:`coder task approve [task-id] <approval-id> [--deny]`,summary:"Answer an escalated permission request. Accepts by default; --deny rejects it.\nApproval ids are unique, so the task id is optional. Shortcut: `coder approve`.",flags:[[`--deny`,`reject the request instead of accepting`],G,W],seeAlso:`task approvals · task result`},"flow run":{list:[`flow run <name|path> [--args | key=value...]`,`run a flow (orchestrate a wave of tasks)`],usage:`coder flow run <name|path> [--args '<json>' | key=value...] [--wait] [--concurrency N] [--max-tasks N] [--json] [--dry-run]`,summary:`Run a flow: a TypeScript file that orchestrates many coder tasks with gates,
|
|
23
23
|
journaling, and resume. Prints the run id and orchestrates in the background;
|
|
24
24
|
--wait follows the run in the foreground with live progress (Ctrl-C detaches;
|
|
25
25
|
it keeps running), and \`coder flow watch\` shows the same lines any time.
|
|
26
|
-
Stop a run with \`coder flow stop\`.`,flags:[[`--wait`,`follow the run in the foreground (Ctrl-C detaches; it keeps running)`],[`--args <json>`,`the flow's input as a JSON value (or pass bare key=value pairs)`],[`--concurrency <n>`,`tasks running at once (default: CPU count)`],[`--max-tasks <n>`,`total tasks the run may dispatch (default: CPU count x 10)`],[`--dry-run`,`print every resolved prompt and gate command without dispatching`],
|
|
27
|
-
within the last 10 minutes. Older runs auto-archive and move to --archived.`,flags:[[`--archived`,`show archived runs (auto-archived or via flow archive)`],[`--limit <n|all>`,`show at most n runs (default all)`],
|
|
28
|
-
.coder/flows/ (walking up to the repo root) and global flows in ~/.coder/flows/.`,flags:[
|
|
26
|
+
Stop a run with \`coder flow stop\`.`,flags:[[`--wait`,`follow the run in the foreground (Ctrl-C detaches; it keeps running)`],[`--args <json>`,`the flow's input as a JSON value (or pass bare key=value pairs)`],[`--concurrency <n>`,`tasks running at once (default: CPU count)`],[`--max-tasks <n>`,`total tasks the run may dispatch (default: CPU count x 10)`],[`--dry-run`,`print every resolved prompt and gate command without dispatching`],G,W],examples:[[`coder flow run audit-routes --wait`,`run a discovered flow`],[`coder flow run ./scratch/one-off.ts --wait`,`run a flow by path`],[`coder flow run verify --args '{"clusters":["a","b"]}' --wait`,`pass structured input`]],seeAlso:`flow list · flow discover · flow result · flow resume`},"flow list":{list:[`flow list`,`recent flow runs (running + just stopped)`],usage:`coder flow list [--archived] [--limit N] [--json]`,summary:`List recent flow runs, most recent first: running runs plus ones that ended
|
|
27
|
+
within the last 10 minutes. Older runs auto-archive and move to --archived.`,flags:[[`--archived`,`show archived runs (auto-archived or via flow archive)`],[`--limit <n|all>`,`show at most n runs (default all)`],G,W],seeAlso:`flow run · flow result · flow resume`},"flow discover":{list:[`flow discover`,`list flows runnable here (workspace + global)`],usage:`coder flow discover [--json]`,summary:`List every flow discoverable from the current directory: workspace flows in
|
|
28
|
+
.coder/flows/ (walking up to the repo root) and global flows in ~/.coder/flows/.`,flags:[G,W],seeAlso:`flow run · flow result`},"flow result":{list:[`flow result [run-id]`,`progress and result of a flow run`],usage:`coder flow result [run-id] [--tail <n|all>] [--json]`,summary:`Show a flow run's status and result, with its tasks, gates, and token ledger.
|
|
29
29
|
--tail <n> caps the step rows (0 for the result alone). Defaults to the most
|
|
30
|
-
recent run. To watch a run live, prefer \`coder flow watch\`.`,flags:[[`--tail <n|all>`,`show the last n step rows (default: all; 0 hides them)`],
|
|
30
|
+
recent run. To watch a run live, prefer \`coder flow watch\`.`,flags:[[`--tail <n|all>`,`show the last n step rows (default: all; 0 hides them)`],G,W],examples:[[`coder flow result --tail 0`,`the most recent run's result, no step rows`]],seeAlso:`flow run · flow watch · flow resume`},"flow watch":{list:[`flow watch [run-id]`,`watch a flow run live (replay + follow)`],usage:`coder flow watch [run-id] [--tail <n|all>] [--json]`,summary:`Watch a flow run live: replay its progress lines from the start, then keep
|
|
31
31
|
following while it runs (Ctrl-C detaches; it keeps running). Blocks until it
|
|
32
32
|
finishes; exits 0 on success, 1 otherwise. Defaults to the most recent run.
|
|
33
|
-
For the result alone, prefer \`coder flow result\`. Alias: stream.`,flags:[[`--tail <n|all>`,`replay only the last n events first (default: all)`],[`--json`,`emit each event as a JSON line, then the result`],
|
|
33
|
+
For the result alone, prefer \`coder flow result\`. Alias: stream.`,flags:[[`--tail <n|all>`,`replay only the last n events first (default: all)`],[`--json`,`emit each event as a JSON line, then the result`],W],examples:[[`coder flow watch`,`follow the most recent run to completion`]],seeAlso:`flow result · flow run`},"flow stop":{list:[`flow stop [run-id]`,`stop a run and its still-running tasks`],usage:`coder flow stop [run-id] [--keep-tasks] [--json]`,summary:`Stop a running flow: signal the orchestrator so it stops dispatching, stamp the
|
|
34
34
|
run stopped, and stop its still-running tasks. Defaults to the most recent run;
|
|
35
35
|
the journal stays ready for \`coder flow resume\`.`,flags:[[`--keep-tasks`,`leave the run's still-running tasks running`],[`--json`,`print { runId, status, stoppedTasks, keptTasks }`]],seeAlso:`flow resume · flow result`},"flow resume":{list:[`flow resume [run-id]`,`continue a stopped or edited run`],usage:`coder flow resume [run-id] [--wait] [--json] [--dry-run]`,summary:`Re-run a flow from its journal: finished steps replay instantly, the first
|
|
36
36
|
changed or new step onward runs live. Defaults to the most recent run.
|
|
37
|
-
Accepts the same flags as flow run.`,flags:[[`--wait`,`follow the run in the foreground (Ctrl-C detaches; it keeps running)`],[`--concurrency <n>`,`tasks running at once`],[`--max-tasks <n>`,`total tasks the run may dispatch`],
|
|
37
|
+
Accepts the same flags as flow run.`,flags:[[`--wait`,`follow the run in the foreground (Ctrl-C detaches; it keeps running)`],[`--concurrency <n>`,`tasks running at once`],[`--max-tasks <n>`,`total tasks the run may dispatch`],G,W],examples:[[`coder flow resume`,`continue the most recent run`]],seeAlso:`flow run · flow result`},"flow archive":{list:[`flow archive <run-id> | --all-stopped`,`hide a run (or all stopped) from the list`],usage:`coder flow archive <run-id> | coder flow archive --all-stopped`,summary:`Archive a flow run so it drops out of the default list (see it again with
|
|
38
38
|
\`coder flow list --archived [--limit N]\`). Pass --all-stopped to archive every
|
|
39
|
-
finished run. A running run must be stopped first.`,flags:[[`--all-stopped`,`archive every stopped (finished) run`],
|
|
39
|
+
finished run. A running run must be stopped first.`,flags:[[`--all-stopped`,`archive every stopped (finished) run`],G],seeAlso:`flow list · flow delete`},"flow delete":{list:[`flow delete <run-id> | --all-archived`,`delete a run's record (or all archived)`],usage:`coder flow delete <run-id> | coder flow delete --all-archived`,summary:`Delete a flow run's record from disk (its journal, events, and logs). This is
|
|
40
40
|
permanent; the run's tasks are ordinary tasks and are not touched. Pass
|
|
41
41
|
--all-archived to delete every archived run at once. A running run must be
|
|
42
|
-
stopped first.`,flags:[[`--all-archived`,`delete every archived run`],
|
|
43
|
-
target a dotted key (e.g. agents.codex.model). Writes go to ~/.coder/config.json.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],
|
|
42
|
+
stopped first.`,flags:[[`--all-archived`,`delete every archived run`],G],seeAlso:`flow archive · flow stop`},config:{list:[`config [get|set|unset] <key> [value]`,`read or write config`],usage:`coder config [get|set|unset] <key> [value] [--workspace]`,summary:`Read or write configuration. No args prints the effective config; get/set/unset
|
|
43
|
+
target a dotted key (e.g. agents.codex.model). Writes go to ~/.coder/config.json.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],G,W],examples:[[`coder config`,`print the effective config`],[`coder config set chain codex,claude`,`set the engine fallback chain`],[`coder config get agents.codex.model`,`read one value`]]},"setup-host":{list:[`setup-host [claude|codex|agents]`,`set up the host: check engines, write config, install plugin`],usage:`coder setup-host [claude] [codex] [agents] [--json]`,summary:`Set up coder in your host: check engines and auth, seed the config, and
|
|
44
44
|
install the host plugin/skill for the named host(s). Claude Code gets its
|
|
45
45
|
marketplace plugin; "agents" installs a skill into ~/.agents/skills for
|
|
46
46
|
every host that reads the Agent Skills standard dir (Codex, Pi, OpenCode,
|
|
47
|
-
...). "codex" is an alias for agents. With no host, checks and seeds.`,flags:[[`--json`,`machine-readable output`]],examples:[[`coder setup-host claude`,`install the Claude Code plugin`],[`coder setup-host agents`,`install the skill into ~/.agents/skills (Codex, Pi, OpenCode, ...)`]]},"model list":{list:[`model list`,`list built-ins, custom models, and aliases`],usage:`coder model list [--json]`,summary:"List built-in aliases, configured custom models, and user aliases. Only custom\nmodels are probed. Also the default when `coder model` is run bare.",flags:[
|
|
47
|
+
...). "codex" is an alias for agents. With no host, checks and seeds.`,flags:[[`--json`,`machine-readable output`]],examples:[[`coder setup-host claude`,`install the Claude Code plugin`],[`coder setup-host agents`,`install the skill into ~/.agents/skills (Codex, Pi, OpenCode, ...)`]]},"model list":{list:[`model list`,`list built-ins, custom models, and aliases`],usage:`coder model list [--json]`,summary:"List built-in aliases, configured custom models, and user aliases. Only custom\nmodels are probed. Also the default when `coder model` is run bare.",flags:[G,W],seeAlso:`model add · model remove`},"model add":{list:[`model add <name> --base-url <url> --model <id>`,`connect a local or third-party model (OpenAI-compatible)`],usage:`coder model add <name> --base-url <url> --model <id> [--env-key VAR]`,summary:`Connect a custom model behind an OpenAI-compatible endpoint (Ollama, LM Studio,
|
|
48
48
|
vLLM, OpenRouter, ...). It currently runs on the codex engine pointed at your
|
|
49
49
|
URL and is usable anywhere a model is: --model <name>, --agent custom, or as an
|
|
50
|
-
agent default in config. Alias: \`coder model setup\`.`,flags:[[`--base-url <url>`,`OpenAI-compatible API base (e.g. http://localhost:11434/v1)`],[`--model <id>`,`the provider's model id (e.g. qwen2.5-coder:32b)`],[`--env-key <VAR>`,`env var holding the API key (omit for keyless local endpoints)`],[`--workspace`,`write to <repo>/coder.config.json instead of the user file`],
|
|
51
|
-
is re-probed and the wire protocol re-detected.`,flags:[[`--base-url <url>`,`new API base`],[`--model <id>`,`new provider model id`],[`--env-key <VAR>`,`new API-key env var`],[`--workspace`,`write to <repo>/coder.config.json instead of the user file`],
|
|
52
|
-
built-in name to override it.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],
|
|
50
|
+
agent default in config. Alias: \`coder model setup\`.`,flags:[[`--base-url <url>`,`OpenAI-compatible API base (e.g. http://localhost:11434/v1)`],[`--model <id>`,`the provider's model id (e.g. qwen2.5-coder:32b)`],[`--env-key <VAR>`,`env var holding the API key (omit for keyless local endpoints)`],[`--workspace`,`write to <repo>/coder.config.json instead of the user file`],G],examples:[[`coder model add qwen --base-url http://localhost:11434/v1 --model qwen2.5-coder:32b`,`local Ollama model, no key`],[`coder model add kimi --base-url https://openrouter.ai/api/v1 --model moonshotai/kimi-k2 --env-key OPENROUTER_API_KEY`,`third-party provider via OpenRouter`],[`coder run --model qwen "explain this repo"`,`dispatch a task on it`]],seeAlso:`model list · model update · setup-host · config`},"model update":{list:[`model update <name> [--base-url|--model|--env-key]`,`change a custom model in place`],usage:`coder model update <name> [--base-url <url>] [--model <id>] [--env-key VAR]`,summary:`Update a configured custom model. Only the flags you pass change; the endpoint
|
|
51
|
+
is re-probed and the wire protocol re-detected.`,flags:[[`--base-url <url>`,`new API base`],[`--model <id>`,`new provider model id`],[`--env-key <VAR>`,`new API-key env var`],[`--workspace`,`write to <repo>/coder.config.json instead of the user file`],G],seeAlso:`model list · model remove`},"model remove":{list:[`model remove <name>`,`delete a custom model`],usage:`coder model remove <name>`,summary:`Remove a configured custom model.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],G],seeAlso:`model list · model add`},"model disable":{list:[`model disable <name>`,`turn off a model (built-in, custom, or alias)`],usage:`coder model disable <name> [--workspace]`,summary:`Disable a model - built-in, custom, or alias. Requests for it fail until re-enabled.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],G],seeAlso:`model enable · model list`},"model enable":{list:[`model enable <name>`,`re-enable a disabled model`],usage:`coder model enable <name> [--workspace]`,summary:`Re-enable a disabled model.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],G],seeAlso:`model disable · model list`},"model alias":{list:[`model alias <name> <spec>`,`add or replace a user alias`],usage:`coder model alias <name> <spec> [--workspace]`,summary:`Save an alias for an agent spec, e.g. fast -> codex:spark. An alias may reuse a
|
|
52
|
+
built-in name to override it.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],G],seeAlso:`model unalias · model list`},"model unalias":{list:[`model unalias <name>`,`remove a user alias`],usage:`coder model unalias <name> [--workspace]`,summary:`Remove a user-defined alias.`,flags:[[`--workspace`,`target <repo>/coder.config.json instead of the user file`],G],seeAlso:`model alias · model list`},docs:{list:[`docs [topic]`,`print bundled documentation (for agents to read)`],usage:`coder docs [topic] [--json]`,summary:`Print bundled documentation. With no topic, list the available topics; with a
|
|
53
53
|
topic, print that doc's raw markdown to stdout (unstyled, for an agent to
|
|
54
54
|
consume). \`coder docs skill\` prints the host skill so an agent can load it
|
|
55
55
|
once per session (--claude for the Claude Code flavor).`,flags:[[`--claude`,`with the skill topic: print the Claude Code flavor`],[`--json`,`list topics as JSON (bare listing only)`]],examples:[[`coder docs`,`list the available topics`],[`coder docs flows`,`print the Flows doc`]]},upgrade:{list:[`upgrade [--cli-only|--plugins-only]`,`update the CLI and host plugins (alias: update)`],usage:`coder upgrade [--cli-only] [--plugins-only] [--codex] [--claude] [--pm <mgr>]`,summary:`Update the coder CLI through whichever package manager installed it, then refresh
|
|
56
|
-
the host plugins to match. Alias: update.`,flags:[[`--cli-only`,`update just the CLI`],[`--plugins-only`,`refresh just the host plugins`],[`--codex`,`limit the refresh to the Agent Skills copy (Codex, Pi, ...)`],[`--claude`,`limit the refresh to the Claude Code plugin`],[`--pm <npm|pnpm|yarn|bun>`,`force a package manager instead of auto-detecting`]]}},
|
|
57
|
-
`)}\n`}function
|
|
58
|
-
`)}\n`}function
|
|
59
|
-
`)}\n`}function
|
|
60
|
-
`)}\n`}function
|
|
61
|
-
`)}\n`}function
|
|
62
|
-
`).filter(Boolean).flatMap(e=>{try{return[JSON.parse(e)]}catch{return[]}}):[]}function
|
|
63
|
-
`))this.final(e.depth??0,t.light(n),!0);return;case`flow-start`:this.final(e.depth-1,t.bold(`flow ${e.name}`));return;case`replay`:this.final(0,t.dim(`replayed ${e.count} steps from journal`),!0)}}done(){this.spin(!1),this.flush(0),this.tty&&this.repaint(),this.region.done()}flush(e){this.pending&&=(this.region.commit(`${
|
|
64
|
-
[flow] dry-run ended early: a downstream step depends on real task output (stub it or run for real).`:``;
|
|
56
|
+
the host plugins to match. Alias: update.`,flags:[[`--cli-only`,`update just the CLI`],[`--plugins-only`,`refresh just the host plugins`],[`--codex`,`limit the refresh to the Agent Skills copy (Codex, Pi, ...)`],[`--claude`,`limit the refresh to the Claude Code plugin`],[`--pm <npm|pnpm|yarn|bun>`,`force a package manager instead of auto-detecting`]]}},St={run:`task run`,list:`task list`,watch:`task watch`,stream:`task watch`,result:`task result`,steer:`task steer`,ask:`task ask`,stop:`task stop`,archive:`task archive`,delete:`task delete`,approvals:`task approvals`,approve:`task approve`,setup:`setup-host`,"host-setup":`setup-host`,update:`upgrade`},Ct=[{usage:`list`,blurb:`list built-ins, custom models, and aliases`},{usage:`add <name> --base-url <url> --model <id> [--env-key VAR]`,blurb:`connect a model (alias: setup)`},{usage:`update <name> [--base-url|--model|--env-key]`,blurb:`change a model in place`},{usage:`remove <name>`,blurb:`delete a custom model`},{usage:`disable <name>`,blurb:`turn off a model (built-in, custom, or alias)`},{usage:`enable <name>`,blurb:`re-enable a disabled model`},{usage:`alias <name> <spec>`,blurb:`name a spec, e.g. fast codex:spark`},{usage:`unalias <name>`,blurb:`remove an alias`}],wt=[{usage:`run <name|path> [--wait] [--args ...]`,blurb:`run a flow in the background (--wait to follow it live)`},{usage:`list`,blurb:`recent flow runs (running + just stopped)`},{usage:`discover`,blurb:`list flows runnable here (workspace + global)`},{usage:`result [run-id]`,blurb:`progress and result of a run`},{usage:`watch [run-id]`,blurb:`watch a run live (replay + follow)`},{usage:`stop [run-id]`,blurb:`stop a run and its still-running tasks`},{usage:`resume [run-id]`,blurb:`continue a stopped or edited run`},{usage:`archive <run-id> | --all-stopped`,blurb:`hide a run (or all stopped) from the list`},{usage:`delete <run-id> | --all-archived`,blurb:`delete a run's record (or all archived)`}];function q(){let e=x,t=wt.map(t=>` ${e.cyan(t.usage.padEnd(44))}${e.dim(t.blurb)}`);return`${[e.bold(`Usage:`),` coder flow <subcommand>`,``,`Orchestrate many coder tasks with a plain TypeScript file: dispatch, gates,`,`concurrency, journaling, and resume. Flows live in .coder/flows/ (workspace)`,"or ~/.coder/flows/ (global). See `coder docs flows`.",``,e.bold(`Subcommands:`),...t,``,e.dim(`Run 'coder flow <subcommand> --help' for details on any subcommand.`)].join(`
|
|
57
|
+
`)}\n`}function Tt(){let e=x,t=Ct.map(t=>` ${e.cyan(t.usage.padEnd(60))}${e.dim(t.blurb)}`);return`${[e.bold(`Usage:`),` coder model <subcommand>`,``,"Manage the models coder can dispatch to. `add` connects any OpenAI-compatible",`endpoint (Ollama, vLLM, OpenRouter, ...) as the custom agent, alongside the`,"built-in codex/claude models. Name your own shortcuts with `alias`",`(e.g. fast -> codex:spark); disable/enable turns any model off and on.`,``,e.bold(`Subcommands:`),...t,``,e.dim(`Run 'coder model <subcommand> --help' for details on any subcommand.`)].join(`
|
|
58
|
+
`)}\n`}function Et(e,t){return e.map(([e,n])=>` ${t.cyan(e.padEnd(30))}${t.dim(n)}`)}function J(e){let t=K[e];if(!t)return null;let n=x,r=[n.bold(`Usage:`),` ${t.usage}`];if(t.summary&&r.push(``,t.summary),t.flags?.length&&r.push(``,n.bold(`Flags:`),...Et(t.flags,n)),t.examples?.length){r.push(``,n.bold(`Examples:`));for(let[e,i]of t.examples)r.push(` ${n.cyan(e)}`,` ${n.dim(i)}`)}return t.seeAlso&&r.push(``,n.dim(`Related: ${t.seeAlso}`)),`${r.join(`
|
|
59
|
+
`)}\n`}function Y(){let e=x,t=xt.map(t=>{let n=t.alias?e.dim(` (coder ${t.alias})`):``;return` ${e.cyan(t.usage.padEnd(30))}${e.dim(t.blurb)}${n}`});return`${[e.bold(`Usage:`),` coder task <subcommand>`,``,e.bold(`Subcommands:`),...t,``,e.dim(`Run 'coder task <subcommand> --help' for details on any subcommand.`)].join(`
|
|
60
|
+
`)}\n`}function Dt(){let e=x,t=([t,n])=>` ${e.cyan(t.padEnd(41))}${e.dim(n)}`,n=xt.filter(e=>e.alias).map(e=>t([e.usage.replace(/^\S+/,e.alias),e.blurb]));return`${[`${e.bold(`Coder`)} ${e.dim(`v${_()}`)}`,`Delegate a coding task to the best available engine and steer it while it runs.`,``,e.bold(`Get started:`),` ${e.cyan(`coder setup-host claude`)} ${e.dim(`# or agents (Codex, Pi, ...); installs the host plugin/skill`)}`,` ${e.cyan(`coder run "explain this repo's layout"`)}`,``,e.dim("Agents: load the skill once with `coder docs skill [--claude]`."),``,e.bold(`Usage:`),` coder <command>`,``,e.bold(`Commands:`),...n,` ${e.cyan(`task <cmd>`.padEnd(41))}${e.dim(`more task commands (steer, stop, approve, ...): `)}${e.light(`coder task --help`)}`,` ${e.cyan(`flow <cmd>`.padEnd(41))}${e.dim(`orchestrate a wave of tasks: `)}${e.light(`coder flow --help`)}`,t(K.config.list),t([`model <list|add|alias|disable>`,`manage models: built-ins, aliases, custom endpoints`]),t(K.docs.list),t(K.upgrade.list),``,e.bold(`Global:`),t([`-h, --help`,`show help (top-level, or for a command)`]),t([`-v, --version`,`print the coder version`]),t([`--json`,`JSON output instead of human-readable text`]),t(W)].join(`
|
|
61
|
+
`)}\n`}function X(e){let t=e.indexOf(`--`),n=t===-1?e:e.slice(0,t);return n.includes(`-h`)||n.includes(`--help`)}const Ot=`CODER_FLOW_ATTACH`;function kt(e){let t={};for(let n of e){let e=n.indexOf(`=`);e===-1&&k(`Invalid argument "${n}": expected key=value.`,{hint:`Help: coder flow run --help`});let r=n.slice(0,e),i=n.slice(e+1);try{t[r]=JSON.parse(i)}catch{t[r]=i}}return t}function At(e,t){if(e!==void 0)try{return JSON.parse(e)}catch(e){k(`Invalid --args JSON: ${e instanceof Error?e.message:String(e)}`)}return t.length?kt(t):{}}function jt(){try{return gt(`bun`,[`--version`],{stdio:`ignore`}).status===0}catch{return!1}}function Mt(e){if(!e.endsWith(`.ts`)||B.versions.bun||B.features.typescript)return;jt()||k(`This flow is a TypeScript file (${e}) and this Node cannot run TypeScript.`,{hint:[`Upgrade to Node 23.6+ or install bun: https://bun.sh`,`Or write the flow as .mjs / .js`]});let t=gt(`bun`,[m,...B.argv.slice(2)],{stdio:`inherit`});B.exit(t.status??1)}function Nt(e){B.once(`SIGINT`,()=>{(async()=>{let{runId:t}=e,n=V.existsSync(H.join(R(t),Je));if(B.stderr.write(`\n[flow] stopping run ${t} — no new tasks will dispatch.\n`),n){let t=e.runningIds();t.length&&B.stderr.write(`[flow] left running: ${t.join(`, `)}\n`)}else{let n=await Oe(t,e.runningIds());n.length&&B.stderr.write(`[flow] stopped tasks: ${n.join(`, `)}\n`)}B.stderr.write(`[flow] resume with: coder flow resume ${t}\n`),e.requestStop(),B.exit(130)})()})}const Pt=[`⣾`,`⣽`,`⣻`,`⢿`,`⡿`,`⣟`,`⣯`,`⣷`];function Z(e,t=!1){let n=x;return t?O(`[${It(e)}]`,10):e===`completed`?n.bold(n.green(`✔`)):e===`failed`||e===`cancelled`||e===`stopped`?n.bold(n.red(`✘`)):e===`running`?n.bold(n.cyan(`●`)):n.dim(`○`)}function Ft(){return O(`[start]`,10)}function It(e){return e===`completed`?`done`:e===`cancelled`?`failed`:e}function Lt(e,t){return e??t.replace(/\s+/g,` `).trim().slice(0,60)}function Q(e,t,n,r,i,a){let o=x,s=O(t??n,32);return[`${e} ${a?o.bold(s):s}`,o.dim(O(n,24)),o.light(O(i??``,20)),r?o.light(`${Te(r.total)} tok`):``].join(` `).trimEnd()}function Rt(e){let t=H.join(R(e),`events.jsonl`);return V.existsSync(t)?V.readFileSync(t,`utf8`).split(`
|
|
62
|
+
`).filter(Boolean).flatMap(e=>{try{return[JSON.parse(e)]}catch{return[]}}):[]}function zt(e,t=!1){let n=x;return`${Z(e.ok?`completed`:`failed`,t)} ${n.dim(`gate`)} ${n.light(e.cmd)}${e.ok?``:n.dim(` · exit ${e.code}`)}`}function Bt(e,t,n){let r=x,i=n!==void 0&&n>=1e3?r.dim(` · ${E(n)}`):``;return`${t} ${r.dim(`gate`)} ${r.light(e)}${i}`}function Vt(e,t=!1){return x.dim(`${`│ `.repeat(e)}${t?`└─`:`├─`}`)}function Ht(e){return x.dim(`${`│ `.repeat(e)}│ `)}function Ut(e){return`${` `.repeat(e.depth)}${e.log?`${O(`[log]`,10)} `:``}${e.body}`}function Wt(e,t,n=!1){return n?Ut(e):`${e.log?Ht(e.depth):Vt(e.depth,t)} ${e.body}`}function Gt(e){return x.dim(`${`│ `.repeat(Math.max(0,e))}│`)}function Kt(e,t=!1){let n=x;if(t)return e.map(Ut);let r=(t,n)=>{for(let r=t+1;r<e.length;r+=1){let t=e[r].depth;if(t<n)return!1;if(t===n)return!0}return!1};return e.map((e,t)=>{let i=``;for(let n=0;n<e.depth;n+=1)i+=r(t,n)?`│ `:` `;return i+=e.log?`│ `:r(t,e.depth)?`├─`:`└─`,`${n.dim(i)} ${e.body}`})}var qt=class{stream;names=new Map;active=new Map;activeGates=new Map;pending;previews=new Map;frame=0;hasCommitted=!1;timer;tty;region;constructor(e=B.stdout){this.stream=e,this.tty=!!e.isTTY,this.region=new _e(e)}emit(e){let t=x;switch(e.kind){case`task-start`:{let t={name:Lt(e.name,e.prompt),agent:e.agent,depth:e.depth??0};if(this.names.set(e.taskId,t),!this.tty){this.final(t.depth,Q(Ft(),t.name,e.taskId,null,t.agent));return}this.active.set(e.taskId,t),this.spin(!0),this.repaint();return}case`task-end`:{this.active.delete(e.taskId),this.previews.delete(e.taskId),this.idle();let t=this.names.get(e.taskId);this.final(t?.depth??0,Q(Z(e.status,!this.tty),t?.name??null,e.taskId,e.tokens,t?.agent));return}case`gate-start`:{let t={cmd:e.cmd,depth:e.depth??0,startedAt:Date.now()};if(!this.tty){this.final(t.depth,Bt(t.cmd,Ft()));return}this.activeGates.set(e.gateId,t),this.spin(!0),this.repaint();return}case`gate`:e.gateId&&this.activeGates.delete(e.gateId),this.idle(),this.final(e.depth??0,zt(e,!this.tty));return;case`log`:for(let n of e.message.split(`
|
|
63
|
+
`))this.final(e.depth??0,t.light(n),!0);return;case`flow-start`:this.final(e.depth-1,t.bold(`flow ${e.name}`));return;case`replay`:this.final(0,t.dim(`replayed ${e.count} steps from journal`),!0)}}done(){this.spin(!1),this.flush(0),this.tty&&this.repaint(),this.region.done()}flush(e){this.pending&&=(this.region.commit(`${Wt(this.pending,e<this.pending.depth,!this.tty)}\n`),this.hasCommitted=!0,void 0)}final(e,t,n=!1){if(!this.tty){this.region.commit(`${Ut({depth:e,body:t,log:n})}\n`),this.hasCommitted=!0;return}this.flush(e),this.pending={depth:e,body:t,log:n},this.tty&&this.repaint()}repaint(){let e=[],t=[];if(this.pending){let n=Wt(this.pending,!1);e.push(n),t.push(n)}let n=this.timer?x.bold(x.cyan(Pt[this.frame%Pt.length])):Z(`running`);for(let[r,i]of this.active){let a=`${Vt(i.depth??0)} ${Q(n,i.name,r,null,i.agent,!0)}`;(e.length||this.hasCommitted)&&e.push(Gt(i.depth??0)),e.push(a),t.push(a);let o=this.previews.get(r);o&&e.push(`${Ht(i.depth??0)} ${x.dim(o)}`)}for(let r of this.activeGates.values()){let i=`${Vt(r.depth)} ${Bt(r.cmd,n,Date.now()-r.startedAt)}`;(e.length||this.hasCommitted)&&e.push(Gt(r.depth)),e.push(i),t.push(i)}let r=(Xe(this.stream)??1/0)-1,i=e.length<=r?e:t;if(i.length>r){let e=Math.max(0,r-1);i=[x.dim(`… +${i.length-e} more running`),...i.slice(-e)]}this.region.set(i)}refreshPreviews(){for(let e of this.active.keys())try{let t=a(B.cwd(),e,1)[0]?.message?.replace(/\s+/g,` `).trim();if(!t)continue;let n=(Re(this.stream)??120)-8;this.previews.set(e,t.length>n?`${t.slice(0,n-1)}…`:t)}catch{}}idle(){!this.active.size&&!this.activeGates.size&&this.spin(!1)}spin(e){e&&!this.timer?this.timer=setInterval(()=>{this.frame++,this.frame%4==0&&this.refreshPreviews(),this.repaint()},120).unref():!e&&this.timer&&(clearInterval(this.timer),this.timer=void 0)}};function Jt(e){if(e.json)return{};let t=new qt,n=e=>t.emit(e);return{onTaskStart:e=>n({kind:`task-start`,...e}),onTaskEnd:e=>n({kind:`task-end`,...e}),onGateStart:e=>n({kind:`gate-start`,...e}),onGate:e=>n({kind:`gate`,...e}),onLog:(e,t)=>n({kind:`log`,message:e,depth:t}),onFlowStart:e=>n({kind:`flow-start`,...e}),onReplay:e=>n({kind:`replay`,count:e})}}function Yt(e){let t=H.join(R(e),`events.jsonl`),n=e=>{try{V.appendFileSync(t,`${JSON.stringify(e)}\n`,`utf8`)}catch{}};return{onStart:e=>Nt(e),onTaskStart:e=>n({kind:`task-start`,...e}),onTaskEnd:e=>n({kind:`task-end`,...e}),onGateStart:e=>n({kind:`gate-start`,...e}),onGate:e=>n({kind:`gate`,...e}),onLog:(e,t)=>n({kind:`log`,message:e,depth:t}),onFlowStart:e=>n({kind:`flow-start`,...e}),onReplay:e=>n({kind:`replay`,count:e})}}async function Xt(e,t){try{await Ee(e,t,Yt(e)),B.exit(0)}catch(t){He(e,t instanceof Error?t.message:String(t)),B.exit(1)}}function Zt(e,t){let n=R(e.runId);V.writeFileSync(H.join(n,`events.jsonl`),``,`utf8`);let r=V.openSync(H.join(n,`flow.log`),`a`),i=ht(B.execPath,[m,...B.argv.slice(2)],{detached:!0,stdio:[`ignore`,r,r],env:{...B.env,[Ot]:e.runId}});return i.unref(),V.closeSync(r),t.wait?i.pid:t.json?(L({runId:e.runId,status:`running`}),i.pid):(B.stdout.write(`${x.dim(`[flow]`)} run ${x.cyan(e.runId)} started in the background (running).\n`),B.stdout.write(`\n${P([`Result: coder flow result ${e.runId}`,`Runs: coder flow list`],x)}\n`),i.pid)}async function Qt(e,t,n){let r=!!(t.stream&&t.json);!t.json&&(N(e)?.status??`running`)===`running`&&B.stderr.write(`${x.dim(`[flow]`)} run ${x.cyan(e)} started (running); waiting for it to finish — Ctrl-C to detach (it keeps running).\n\n`);let i=t.json?()=>{}:he(),a=()=>{i(),r||(B.stderr.write(`\n${x.dim(`[flow] detached — run still going.`)}\n`),B.stderr.write(`\n${P([`Result: coder flow result ${e}`,`Stop it: coder flow stop ${e}`],x)}\n`)),B.exit(130)};B.on(`SIGINT`,a);let o=new qt;for await(let i of ve(e,n,{tail:t.tail}))r?B.stdout.write(`${JSON.stringify(i)}\n`):t.json||o.emit(i);o.done(),i(),B.off(`SIGINT`,a);let s=N(e);s||k(`[flow] run ${e} vanished while following.`,{hint:`Recent runs: coder flow list`}),r&&(B.stdout.write(`${JSON.stringify(cn(s))}\n`),B.exit(s.status===`completed`?0:1)),s.status===`completed`&&(tn({runId:e,name:s.name,status:`completed`,result:s.result,tokens:s.ledger,taskCount:s.taskCount},t.json),B.exit(0)),s.status===`stopped`&&(t.json?L({runId:e,name:s.name,status:`stopped`,taskCount:s.taskCount}):B.stdout.write(`\n${x.dim(`[flow] run ${e} stopped — resume: coder flow resume ${e}`)}\n`),B.exit(1)),B.stdout.write(`\n${x.red(`error:`)} ${s.error??`unknown error`}\n`),B.stdout.write(`\n${P([`Resume: coder flow resume ${e}`],x)}\n`),B.exit(1)}const $t={cwd:b,json:y,args:b,wait:y,concurrency:b,"max-tasks":b,"dry-run":y},$=e=>e?Number(e):void 0;async function en(e,t,n){let r=B.env[Ot];if(r&&(delete B.env[Ot],await Xt(r,t)),e[`dry-run`])return!1;let i=n(),a=Zt(i,e);return e.wait&&await Qt(i.runId,e,a),!0}function tn(e,t){if(t){L(e);return}let n=!B.stdout.isTTY,r=n?``:`${x.dim(`└─`)} `;B.stdout.write(`${r}${Z(`completed`,n)} run ${x.cyan(e.runId)} completed ${x.dim(`(${e.taskCount} tasks)`)}\n`),B.stdout.write(`\n${le(e.result)}\n`),an(e.tokens)}function nn(e,t,n){if(e instanceof D&&e.code===`flow-failed`){let r=n?`
|
|
64
|
+
[flow] dry-run ended early: a downstream step depends on real task output (stub it or run for real).`:``;k(`[flow] ${t} ${e.runId} failed: ${e.message}${r}`,{hint:`Resume${t===`resume`?` again`:``}: coder flow resume ${e.runId}`})}throw e}async function rn(e){let{options:t,positionals:n}=g(e,U.object($t)),[r,...i]=n;r||k(`Missing flow name or path.`,{hint:[`Usage: coder flow run <name|path>`,`List: coder flow discover`]});let a=A(t);Mt(Fe(r,a).path);let o={args:At(t.args,i),cwd:a,dryRun:t[`dry-run`],concurrency:$(t.concurrency),maxTasks:$(t[`max-tasks`])};if(!await en(t,o,()=>Ne(r,o)))try{tn(await tt(r,o,Jt(t)),t.json)}catch(e){nn(e,`run`,o.dryRun)}}function an(e){let t=Object.keys(e);if(t.length){B.stdout.write(`\n${x.bold(`Tokens:`)}\n`);for(let n of t)B.stdout.write(` ${x.dim(Ce(e[n],n))}\n`)}}async function on(e){let{options:t,positionals:n}=g(e,U.object({cwd:b,json:y,archived:y,limit:f}));F(n,0,`flow list`);let r=t.limit===`all`?void 0:t.limit,{runs:i,clipped:a}=We({archived:t.archived,limit:r});if(t.json){L(i);return}if(!i.length){B.stdout.write(t.archived?`No archived flow runs.
|
|
65
65
|
`:`No recent flow runs.
|
|
66
|
-
`),
|
|
67
|
-
`),
|
|
68
|
-
`))l.push({depth:e.depth??0,body:i.light(t),log:!0});else e.kind===`flow-start`&&l.push({depth:e.depth-1,body:i.bold(`flow ${e.name}`)});for(let[e,t]of s)l.push({depth:t.depth??0,body
|
|
69
|
-
`)}\n`)}e.endedAt&&e.result!==void 0&&
|
|
70
|
-
`),
|
|
66
|
+
`),B.stdout.write(`\n${P([`Run one: coder flow run <name>`,`Runnable flows: coder flow discover`],x)}\n`);return}let o=x,s=(e,t,n)=>Math.min(t,Math.max(e,...n.map(e=>e.length))),c={id:s(6,28,i.map(e=>e.runId)),name:s(4,30,i.map(e=>e.name))};B.stdout.write(o.bold(o.light(`${`run-id`.padEnd(c.id)} ${`name`.padEnd(c.name)} ${`status`.padEnd(10)} ${`tasks`.padEnd(9)} ${`tokens`.padEnd(10)} age\n`)));for(let e of i){let t=Object.values(e.ledger).reduce((e,t)=>e+t.total,0);B.stdout.write(`${o.cyan(O(e.runId,c.id))} ${O(e.name,c.name)} ${M(e.status,10)} ${o.light(O(`${e.taskCount} tasks`,9))} ${o.light(O(t?`${Te(t)} tok`:`-`,10))} ${o.light(E(Se(e.startedAt)))}\n`)}a&&B.stdout.write(o.dim(`\n... ${a} more not shown (--limit ${r})\n`)),B.stdout.write(`\n${P([`Result: coder flow result <run-id>`,`Tasks: coder list`,`Runnable flows: coder flow discover`],o)}\n`)}async function sn(e){let{options:t,positionals:n}=g(e,U.object({cwd:b,json:y}));F(n,0,`flow discover`);let r=A(t),i=S(r);if(t.json){L(i);return}if(!i.length){B.stdout.write(`No flows found in .coder/flows/ (workspace) or ~/.coder/flows/ (global).
|
|
67
|
+
`),B.stdout.write(`\n${P([`Authoring guide: coder docs flows`],x)}\n`);return}let a=x;B.stdout.write(a.bold(a.light(`${`name`.padEnd(24)} ${`scope`.padEnd(10)} path\n`)));for(let e of i){let t=e.scope===`workspace`?H.relative(r,e.path)||e.path:e.path.replace(_t.homedir(),`~`);B.stdout.write(`${a.cyan(e.name.padEnd(24))} ${a.light(e.scope.padEnd(10))} ${a.light(t)}\n`)}B.stdout.write(`\n${P([`Run one: coder flow run <name>`,`Recent runs: coder flow list`],a)}\n`)}function cn(e){let t=Ze(`${R(e.runId)}/journal.jsonl`);return{...e,journal:t.map(e=>({kind:e.kind,taskId:e.taskId,tokens:e.tokens}))}}function ln(e,t,r=`all`){if(t){L(cn(e));return}let i=x,a=!B.stdout.isTTY;B.stdout.write(`${i.bold(`Flow`)} ${i.cyan(e.name)} ${i.dim(`(${e.runId})`)} — ${i.bold(M(e.status))}\n`);let o=Ge(e.runId),s=o.filter(e=>n.includes(e.status)).length,c=e.status===`running`?`${s}/${o.length} tasks`:`${e.taskCount} tasks`;if(B.stdout.write(`${i.dim(`started ${e.startedAt}${e.endedAt?` · ended ${e.endedAt}`:``} · ${c}`)}\n`),r!==0){let t=Rt(e.runId),n=new Map,s=new Map,c=new Map,l=[];for(let e of t)if(e.kind===`task-start`){let t={name:Lt(e.name,e.prompt),agent:e.agent,depth:e.depth??0};n.set(e.taskId,t),s.set(e.taskId,t)}else if(e.kind===`task-end`){s.delete(e.taskId);let t=n.get(e.taskId);l.push({depth:t?.depth??0,body:Q(Z(e.status,a),t?.name??null,e.taskId,e.tokens,t?.agent)})}else if(e.kind===`gate-start`)c.set(e.gateId,{cmd:e.cmd,depth:e.depth??0});else if(e.kind===`gate`)e.gateId&&c.delete(e.gateId),l.push({depth:e.depth??0,body:zt(e,a)});else if(e.kind===`log`)for(let t of e.message.split(`
|
|
68
|
+
`))l.push({depth:e.depth??0,body:i.light(t),log:!0});else e.kind===`flow-start`&&l.push({depth:e.depth-1,body:i.bold(`flow ${e.name}`)});for(let[e,t]of s)l.push({depth:t.depth??0,body:Q(Z(`running`,a),t.name,e,null,t.agent)+(a?``:` ${i.light(`running`)}`)});for(let e of c.values())l.push({depth:e.depth,body:Bt(e.cmd,Z(`running`,a))+(a?``:` ${i.light(`running`)}`)});if(!l.length)for(let t of r===`all`?o:Ge(e.runId,r))l.push({depth:0,body:Q(Z(t.status,a),t.name,t.taskId??`-`,t.tokens)});let u=Kt(l,a),d=r===`all`?u:u.slice(-r);d.length&&B.stdout.write(`\n${d.join(`
|
|
69
|
+
`)}\n`)}e.endedAt&&e.result!==void 0&&B.stdout.write(`\n${i.bold(`Result:`)}\n${le(e.result)}\n`),e.error&&B.stdout.write(`\n${i.red(`error:`)} ${e.error}\n`),an(e.ledger);let l=e.status===`running`?[`Follow live: coder flow watch ${e.runId}`,`Stop it: coder flow stop ${e.runId}`]:e.status===`stopped`||e.status===`failed`?[`Resume: coder flow resume ${e.runId}`]:[];l.length&&B.stdout.write(`\n${P(l,i)}\n`)}async function un(e){let{options:t,positionals:n}=g(e,U.object({cwd:b,json:y,tail:p})),r=n[0]?N(n[0]):Le();if(!r){if(t.json){L(null);return}k(n[0]?`No flow run "${n[0]}".`:`No flow runs yet.`,{hint:`Run one: coder flow run <name>`})}ln(r,!!t.json,t.tail)}async function dn(e){let{options:t,positionals:n}=g(e,U.object({cwd:b,json:y,tail:p})),r=n[0]?N(n[0]):Le();r||k(n[0]?`No flow run "${n[0]}".`:`No flow runs yet.`,{hint:`Run one: coder flow run <name>`}),await Qt(r.runId,{json:t.json,stream:!0,tail:t.tail})}async function fn(e){let{options:t,positionals:n}=g(e,U.object({cwd:b,json:y,"keep-tasks":y}));F(n,1,`flow stop`);try{let e=await $e(n[0],{keepTasks:t[`keep-tasks`]});if(t.json){L(e);return}let r=x;e.status===`failed`?B.stdout.write(`${r.dim(`[flow]`)} run ${r.cyan(e.runId)} orchestrator died — marked ${M(`failed`)}.\n`):B.stdout.write(`${r.dim(`[flow]`)} run ${r.cyan(e.runId)} ${M(e.status)}.\n`),e.stoppedTasks.length&&B.stdout.write(`${r.dim(`[flow]`)} stopped tasks: ${e.stoppedTasks.join(`, `)}\n`),e.keptTasks.length&&B.stdout.write(`${r.dim(`[flow]`)} left running: ${e.keptTasks.join(`, `)}\n`),B.stdout.write(`\n${P([`Resume: coder flow resume ${e.runId}`],r)}\n`)}catch(e){throw e instanceof D&&e.code===`flow-failed`&&k(e.message,e.hint?{hint:e.hint}:{}),e}}async function pn(e){let{options:t,positionals:n}=g(e,U.object($t)),r=n[0]?N(n[0]):Le();r||k(n[0]?`No flow run "${n[0]}".`:`No flow runs to resume.`,{hint:`Run one: coder flow run <name>`}),Mt(r.script);let i={cwd:A(t),dryRun:t[`dry-run`],concurrency:$(t.concurrency),maxTasks:$(t[`max-tasks`]),...t.args===void 0?{}:{args:At(t.args,[])}};if(!await en(t,i,()=>Ne(``,i,r.runId)))try{tn(await Ee(r.runId,i,Jt(t)),t.json)}catch(e){nn(e,`resume`,i.dryRun)}}function mn(e){let t=N(e);return t||k(`No flow run "${e}".`,{hint:`Recent runs: coder flow list`}),(t.status===`running`||t.status===`queued`)&&k(`Run ${t.runId} is still running.`,{hint:`Stop it first: coder flow stop ${t.runId}`}),t}async function hn(e){let{options:t,positionals:n}=g(e,U.object({cwd:b,json:y,"all-stopped":y}));if(F(n,1,`flow archive`),t[`all-stopped`]){let e=ke().filter(e=>e.status!==`running`&&e.status!==`queued`);for(let t of e)ze(t);let n=e.map(e=>e.runId);if(t.json){L({archived:n,count:n.length});return}B.stdout.write(n.length?`Archived ${n.length} stopped run${n.length===1?``:`s`}.\n`:`${x.dim(`No stopped runs to archive.`)}\n`);return}let r=n[0];r||k(`Missing run id.`,{hint:[`Archive one: coder flow archive <run-id>`,`Archive all stopped: coder flow archive --all-stopped`]});let i=mn(r);if(ze(i),t.json){L({runId:i.runId,archived:!0});return}B.stdout.write(`Archived run ${x.cyan(i.runId)}.\n`)}async function gn(e){let{options:t,positionals:n}=g(e,U.object({cwd:b,json:y,"all-archived":y}));if(F(n,1,`flow delete`),t[`all-archived`]){let e=Ye().filter(e=>De(e.runId)).map(e=>e.runId);if(t.json){L({deleted:e,count:e.length});return}B.stdout.write(e.length?`Deleted ${e.length} archived run${e.length===1?``:`s`}.\n`:`${x.dim(`No archived runs to delete.`)}\n`);return}let r=n[0];r||k(`Missing run id.`,{hint:[`Delete one: coder flow delete <run-id>`,`Delete all archived: coder flow delete --all-archived`]});let i=mn(r);if(De(i.runId),t.json){L({runId:i.runId,deleted:!0});return}B.stdout.write(`Deleted run ${x.cyan(i.runId)}.\n`)}const _n={run:rn,list:on,discover:sn,result:un,watch:dn,stream:dn,stop:fn,resume:pn,archive:hn,delete:gn};async function vn(e){let[t,...n]=e;if(t===void 0||t===`help`||t===`-h`||t===`--help`){B.stdout.write(q());return}let r=_n[t];if(r||(B.stdout.write(q()),B.stdout.write(`
|
|
70
|
+
`),k(`Unknown flow subcommand "${t}".`,{hint:`Run a flow: coder flow run <name>`})),X(n)){let e=t===`stream`?`watch`:t;B.stdout.write(J(`flow ${e}`)??q());return}await r(n)}function yn(e){return e.resumeThreadId?e.currentPrompt??e.prompt??``:`<system>
|
|
71
71
|
You are running inside a coder task: do the work yourself, directly.
|
|
72
72
|
Do not load the coder skill (recursive), and never dispatch through the \`coder\` CLI - nested dispatch is disabled.
|
|
73
73
|
When finished, provide a concise implementation result summary.
|
|
74
74
|
Your turn is one-shot: background processes will not re-invoke you after it ends, so verify synchronously before finishing.${e.system?`\n-------\n${e.system}`:``}
|
|
75
75
|
</system>
|
|
76
76
|
|
|
77
|
-
${e.prompt??``}`}function
|
|
78
|
-
`);t.json||(
|
|
79
|
-
`);if(t.json){
|
|
80
|
-
`)}\n`),
|
|
77
|
+
${e.prompt??``}`}function bn(e,t){let n=0;return()=>{Date.now()-n>=1e4&&(n=Date.now(),c(e,t))}}function xn(e,t,{echo:n}){return r=>{let i=typeof r==`string`?{message:r}:r;u(e,t,i),n&&i.message&&B.stderr.write(`[coder] ${i.message}\n`)}}async function Sn(t,n,{echo:a}){let o=i(t),s=r(t,n.id),c=j(t),l=xn(t,n.id,{echo:a}),d=I[n.permissions??`auto`]??I.auto,f=d.approvalPolicy===`never`?void 0:w({workspaceRoot:o,jobDir:s,mode:d.approvalMode,escalationTimeoutMs:c.approvals.escalationTimeoutMs,allowedNetworkHosts:c.approvals.allowedNetworkHosts,onEvent:e=>{u(t,n.id,e),a&&e.message&&B.stderr.write(`[coder] ${e.message}\n`)}}),p=n.model?c.models?.[n.model]:void 0,m=p&&qe(p)?p:void 0;if(m&&!m.wireApi&&n.model){let e=await at(m);e&&(m={...m,...e},c.models[n.model]=m,je(t,n.model,e),u(t,n.id,{kind:`info`,message:`detected wire api for ${n.model}: ${e.wireApi} @ ${m.baseUrl}`}))}if(m?.envKey&&!B.env[m.envKey])throw Error(`Missing environment variable: \`${m.envKey}\`.`);let h=m?await ct(m,m.wireApi??`chat`):null,g=Ue(c,n.model,h??void 0);try{let r=await nt(t,{prompt:yn(n),model:g?.model??Me(n.model),modelProvider:g?.modelProvider??null,configOverrides:g?.configOverrides??null,effort:n.effort,sandbox:d.sandbox,approvalPolicy:d.approvalPolicy,approvalsReviewer:d.approvalMode===`auto`?`auto_review`:null,onApprovalRequest:f,onHeartbeat:bn(t,n.id),resumeThreadId:n.resumeThreadId??null,onControlReady:(r,i,a)=>{e(t,n.id,{status:`running`,steerEndpoint:r,threadId:i,turnId:a})},onProgress:r=>{l(r);let i=typeof r==`object`?r.threadId:null,a=typeof r==`object`?r.turnId:null;(i||a)&&e(t,n.id,{status:`running`,...i?{threadId:i}:{},...a?{turnId:a}:{}})}});return e(t,n.id,{status:r.status===0?`completed`:`failed`,threadId:r.threadId,turnId:r.turnId,steerEndpoint:null,completedAt:new Date().toISOString()}),wn(t,n,s,r),r}finally{e(t,n.id,{steerEndpoint:null}),await h?.close()}}async function Cn(t,n,{echo:i}){let a=r(t,n.id),o=j(t),s=xn(t,n.id,{echo:i}),c=I[n.permissions??`auto`]??I.auto;try{let r=await we(t,{prompt:yn(n),model:n.model,effort:n.effort,permissions:n.permissions,approvalJobId:c.approvalMode===`auto`?n.id:null,allowedNetworkHosts:o.approvals.allowedNetworkHosts,resumeSessionId:n.resumeThreadId??null,onHeartbeat:bn(t,n.id),onSteerReady:r=>{e(t,n.id,{status:`running`,steerEndpoint:r})},onProgress:r=>{s(r),r.threadId&&e(t,n.id,{status:`running`,threadId:r.threadId})}});return e(t,n.id,{status:r.status===0?`completed`:`failed`,threadId:r.threadId,steerEndpoint:null,completedAt:new Date().toISOString()}),wn(t,n,a,r),r}finally{e(t,n.id,{steerEndpoint:null})}}function wn(e,t,n,r){de(H.join(n,`result.json`),r);let i={at:new Date().toISOString(),prompt:t.currentPrompt??t.prompt??null,...r};V.appendFileSync(H.join(n,`results.jsonl`),`${JSON.stringify(i)}\n`,`utf8`)}function Tn(e){return e.engine===`claude`?Cn:Sn}async function En(t,n){for(let r=0;r<2;){let i=h(t,n);if(!i||i.status===`failed`||i.status===`cancelled`)return;let a=d(t,n);if(a.length===0){r+=1,await new Promise(e=>setTimeout(e,300));continue}r=0;for(let r of a){let a=e(t,n,{status:`running`,currentPrompt:r,resumeThreadId:i.threadId??null});u(t,n,{message:`Running steered follow-up.`});try{await Tn(a)(t,a,{echo:!1})}catch(r){let i=r instanceof Error?r.message:String(r);e(t,n,{status:`failed`,error:i}),u(t,n,{kind:`error`,message:i});return}}}}function Dn(e,t){if(e instanceof D)switch(e.code){case`chain-exhausted`:L(e.payload),B.exit(3);case`read-only-unavailable`:On(e.message,t);break;case`startup-failed`:t.json&&(L({taskId:e.taskId,status:`failed`,detail:e.message}),B.exit(1)),k(`Task ${e.taskId} failed to start.${e.message?`\n${e.message}`:``}`,{hint:`See: coder task result ${e.taskId}`});break;default:k(e.message,e.hint?{hint:e.hint}:{})}throw e}function On(e,t){let n=`read-only unavailable on this host: the OS sandbox failed to start (Linux/WSL2 needs bubblewrap + socat). Re-dispatch with --permissions auto (or workspace-write) if writes are acceptable, or install the sandbox deps.`;t.json?L({error:n,code:`read-only-unavailable`,detail:e}):B.stderr.write(`[coder] ${n}\n`),B.exit(1)}async function kn(e){B.env.CODER_WORKER&&k(`Nested dispatch refused: this shell is already inside a coder task. Do the work yourself, directly in this session - ignore any skill or instruction telling you to orchestrate via the coder CLI.`);let{options:t,positionals:n}=g(e,U.object({...v,agent:b,model:b,effort:b,permissions:b,resume:b,host:b,name:b,system:b,background:y,wait:y,"simulate-approval":y})),r=A(t),i=n.join(` `).trim();i||k(`Missing task text.`,{hint:[`Usage: coder run "<task text>"`,`Help: coder task run --help`]});let a={prompt:i,cwd:r,agent:t.agent,model:t.model,effort:t.effort,permissions:t.permissions,name:t.name,system:t.system,resume:t.resume,wait:t.wait,simulateApproval:t[`simulate-approval`],onFallback:({agent:e,detail:t,next:n})=>B.stderr.write(`[coder] ${e} failed to start (${t}); falling back to ${n}.\n`),onInstallNote:e=>B.stderr.write(`[coder] ${e}\n`)},o;try{o=await se(a)}catch(e){Dn(e,t)}if(t.wait)for(;;){let e=o.taskId,n=o.job,s=[` result: coder task result ${e}`,` steer: coder task steer ${e} "<follow-up>"`].join(`
|
|
78
|
+
`);t.json||(B.stderr.write(`${x.dim(`[coder]`)} task ${x.cyan(e)} started (${n.status}); waiting for it to finish — Ctrl-C to detach (it keeps running).\n`),B.stderr.write(`${x.dim(s)}\n`));let c=()=>{B.stderr.write(`\n${x.dim(`[coder] detached — task still running: coder task result ${e}`)}\n`),B.exit(130)};B.on(`SIGINT`,c);let l;try{l=await te(r,e)}catch(n){throw B.off(`SIGINT`,c),n instanceof D&&n.code===`approval-pending`&&Ve(e,n.approval,t.json),n}B.off(`SIGINT`,c);let u=l.job,d=l.result,f=d?.error?.message??``;if(u.status===`failed`&&ue(u.permissions??`auto`,f)&&On(f,t),u.status===`failed`&&fe.test(f)){let e=j(r).chain,n=e[e.indexOf(o.agent)+1];n||(L(ie(o.agent,f,u.permissions??`auto`,t.system,i)),B.exit(3)),B.stderr.write(`[coder] ${o.agent} failed to start (${f}); falling back to ${n}.\n`);try{o=await se({...a,agent:n,model:void 0,effort:void 0,name:void 0,resume:void 0,simulateApproval:void 0})}catch(e){Dn(e,t)}continue}if(t.json)L({taskId:e,status:u.status,finalMessage:d?.finalMessage,...f?{error:f}:{},tokens:d?.tokens??null,model:d?.model??u.model??null});else{B.stdout.write(`\n${d?.finalMessage||(f?`${x.red(`error:`)} ${f}`:`(no final message)`)}\n\n`);let t=d?.tokens?` tokens=${Ce(d.tokens,d.model??u.model)}`:``;B.stderr.write(`${x.dim(`[coder] task=${e} status=${u.status}${t}`)}\n`)}B.exit(u.status===`completed`?0:1)}let s=o.taskId,c=o.job,l=[` result: coder task result ${s}`,` steer: coder task steer ${s} "<follow-up>"`].join(`
|
|
79
|
+
`);if(t.json){L({taskId:s,status:c.status,startupCheck:o.startupCheck,commands:{result:`coder task result ${s}`,steer:`coder task steer ${s} "<follow-up>"`,stop:`coder task stop ${s}`,watch:`coder task watch ${s}`}});return}B.stdout.write(`${x.dim(`[coder]`)} task ${x.cyan(s)} started in the background (${c.status}).\n`),B.stdout.write(`${x.dim(l)}\n`)}async function An(t){let{options:n,positionals:i}=g(t,U.object({cwd:b})),a=A(n),o=i[0],s=h(a,o);s||k(`Worker: task ${o} not found.`),e(a,o,{status:`running`,pid:B.pid});try{if(s.simulateApproval){let t=await me(r(a,o),{onEvent:e=>u(a,o,e)});if(u(a,o,{message:`simulated approval: ${t}`}),t===`decline`){e(a,o,{status:`cancelled`,completedAt:new Date().toISOString(),error:`simulated approval denied`});return}}await Tn(s)(a,s,{echo:!1}),await En(a,o)}catch(t){let n=t instanceof Error?t.message:String(t);e(a,o,{status:`failed`,error:n}),u(a,o,{kind:`error`,message:n}),B.exit(1)}}async function jn(e){let{options:n,positionals:i}=g(e,U.object({...v,tail:p,wait:y,turns:y}));F(i,1,`task result`);let s=A(n),c=Pe(s,i[0]);if(n.wait){l.includes(c.status)&&B.stderr.write(`${x.dim(`[coder] waiting for task ${c.id} to finish...`)}\n`);let e=await et(s,c);c=e.job,e.reason===`approval`&&Ve(c.id,e.approval,n.json)}let{steps:u,result:d}=ge(s,c.id,{tail:n.tail}),f=o(s,c.id),m=re(r(s,c.id)).filter(e=>!e.response),h=l.includes(c.status),_=h&&m.length?`waiting-approval`:c.status,b=h?a(s,c.id,1)[0]:void 0,ee=h?t(s,c):c.updatedAt,S=Se(ee),C=h&&m.length===0&&S>6e5,te=()=>{n.wait&&B.exit(c.status===`completed`?0:1)};if(n.json)return L({taskId:c.id,name:c.name??null,prompt:c.prompt??null,system:c.system??null,status:_,agent:c.agent,model:c.model??null,effort:c.effort??null,permissions:c.permissions??null,cwd:c.cwd??null,createdAt:c.createdAt??null,completedAt:c.completedAt??null,...h?{idleMs:S,lastActivityAt:ee??null,stalled:C}:{},pendingApprovals:m.map(e=>({id:e.id,summary:e.summary})),...u.length?{steps:u}:{},turnCount:f.length,...n.turns?{turns:f}:{},result:d}),te();let w=x,ne=h?a(s,c.id,200).reverse().find(e=>e.kind===`usage`)?.tokens??null:null,T=Ke(c,{status:_,tokens:d?.tokens??ne,tokenModel:d?.model,files:d?.touchedFiles?.map(e=>Ie(c.cwd??s,e)),live:!d?.tokens&&!!ne,style:w});if(c.prompt&&T.push(...Be(c.prompt,w)),m.length){T.push(``,w.dim(`pending approvals:`));for(let e of m)T.push(` ${w.cyan(e.id)} ${e.summary}`),T.push(` ${w.bold(`coder approve ${c.id} ${e.id}`)} ${w.dim(`(--deny to reject)`)}`)}if(u.length){T.push(``,w.dim(`steps:`));let e=new rt({cwd:c.cwd??s,startedAt:Date.parse(c.createdAt??``)||void 0,width:Re(),style:w}),t=d?.finalMessage&&String(u.at(-1)?.message??``).trim()===String(d.finalMessage).trim()?u.slice(0,-1):u;for(let n of t)T.push(...e.render(n))}if(T.push(``),n.turns&&f.length?f.forEach((e,t)=>{t&&T.push(``),T.push(w.dim(`— turn ${t+1} of ${f.length}: ${Ae(String(e.prompt??``))}`)),T.push(String(e.finalMessage||w.dim(`(no final message)`)))}):d?(T.push(oe({...d,error:d.error??void 0},c.error,`(no final message)`,w)),f.length>1&&T.push(w.dim(`(turn ${f.length} of ${f.length} — all answers: coder task result ${c.id} --turns)`))):h?T.push(w.dim(C?`Result pending, but no progress for ${E(S)} — the task may be stalled.${b?` Last: ${Ae(b.message??b.kind??``)}`:``}`:`Result pending — task is still running.`)):T.push(w.dim(`(no result)`)),h&&!n.wait){let e=[`Wait for it: coder task result ${c.id} --wait`,`Follow live: coder task watch ${c.id}`];C&&e.push(`Check the transcript: coder task result ${c.id} --tail all`),T.push(``,P(e,w))}return B.stdout.write(`${T.join(`
|
|
80
|
+
`)}\n`),te()}function Mn(e){return s(e).filter(e=>l.includes(e.status)).flatMap(t=>re(r(e,t.id)).filter(e=>!e.response).map(e=>({taskId:t.id,id:e.id,summary:String(e.summary??``),createdAt:e.createdAt?String(e.createdAt):void 0})))}async function Nn(e){let{options:t,positionals:n}=g(e,U.object(v));F(n,1,`task approvals`);let i=A(t),a=x;if(n[0]){let e=Pe(i,n[0]),o=re(r(i,e.id)).map(e=>({id:e.id,summary:e.summary,createdAt:e.createdAt,answered:e.response?.decision??null}));if(t.json){L(o);return}if(!o.length){B.stdout.write(`${a.dim(`No approvals for task ${e.id}.`)}\n`);return}for(let e of o){let t=e.answered??`pending`;B.stdout.write(`${a.cyan(e.id)} ${t.padEnd(8)} ${a.dim(String(e.summary??``))}\n`)}let s=o.filter(e=>!e.answered);if(s.length){let e=s.length===1?s[0].id:`<approval-id>`;B.stdout.write(`\n${P([`Answer: coder approve ${e} [--deny]`],a)}\n`)}return}let o=Mn(i);if(t.json){L(o);return}if(!o.length){B.stdout.write(`${a.dim(`No pending approvals.`)}\n`);return}let s={id:Math.max(11,...o.map(e=>e.id.length)),task:Math.max(7,...o.map(e=>e.taskId.length))};B.stdout.write(a.bold(a.light(`${`approval-id`.padEnd(s.id)} ${`task-id`.padEnd(s.task)} age summary\n`)));for(let e of o){let t=e.createdAt?E(Se(e.createdAt)):`-`;B.stdout.write(`${a.cyan(e.id.padEnd(s.id))} ${a.cyan(e.taskId.padEnd(s.task))} ${t.padEnd(5)} ${a.light(e.summary)}\n`)}let c=o.length===1?o[0].id:`<approval-id>`;B.stdout.write(`\n${P([`Answer: coder approve ${c} [--deny]`],a)}\n`)}async function Pn(e){let{options:t,positionals:n}=g(e,U.object({...v,deny:y}));F(n,2,`task approve`);let i=A(t),[a,o]=n;a&&!o&&a.startsWith(`apr-`)&&(o=a,a=Mn(i).find(e=>e.id===o)?.taskId,a||k(`No pending approval "${o}".`,{hint:`List them: coder approvals`})),(!a||!o)&&k(`Missing approval id.`,{hint:[`List them: coder approvals`,`Usage: coder approve [task-id] <approval-id> [--deny]`]});let s=Pe(i,a),c=t.deny?`decline`:`accept`;if(ye(r(i,s.id),o,c),t.json){L({taskId:s.id,approvalId:o,decision:c});return}B.stdout.write(`${t.deny?`Denied`:`Approved`} ${x.cyan(o)} on task ${x.cyan(s.id)}.\n`)}function Fn(e){return H.join(e,`sidecar.json`)}function In(e){return C(Fn(e))??{sessionId:null,declineStreak:0}}async function Ln(e){let t=H.join(e,`sidecar.lock`),n=Date.now()+12e4;for(;;)try{return V.mkdirSync(t),()=>{try{V.rmdirSync(t)}catch{}}}catch{try{if(Date.now()-V.statSync(t).mtimeMs>9e4){V.rmdirSync(t);continue}}catch{continue}if(Date.now()>n)throw Error(`sidecar lock wait timed out`);await new Promise(e=>setTimeout(e,250))}}function Rn(e,t,n,r){return[`-p`,r,`--output-format`,`json`,`--model`,`sonnet`,`--effort`,`low`,n?`--resume`:`--session-id`,t,...ee,`--add-dir`,e]}function zn(e,t,n,r,i){let a=Rn(t,n,r,i);return new Promise((t,n)=>{let r=ht(`claude`,a,{cwd:e,stdio:[`ignore`,`pipe`,`pipe`]}),i=``,o=``,s=setTimeout(()=>{r.kill(`SIGKILL`),n(Error(`sidecar call timed out`))},12e4);r.stdout.on(`data`,e=>i+=e),r.stderr.on(`data`,e=>o+=e),r.on(`error`,e=>{clearTimeout(s),n(e)}),r.on(`close`,e=>{if(clearTimeout(s),e!==0){n(Error(`sidecar claude exited ${e}: ${o.trim().slice(0,200)}`));return}try{let e=JSON.parse(i);if(e.is_error){n(Error(`sidecar turn errored: ${String(e.result??``).slice(0,200)}`));return}t(String(e.result??``))}catch{n(Error(`sidecar returned unparseable output`))}})})}function Bn(e){let t=e.match(/\{[^{}]*"decision"[^{}]*\}/);if(!t)return null;try{let e=JSON.parse(t[0]);if(e.decision===`accept`||e.decision===`decline`||e.decision===`escalate`)return{decision:e.decision,reason:String(e.reason??``)}}catch{}return null}async function Vn(e,t,n){let r=null;try{r=await Ln(t);let i=In(t);if(i.declineStreak>=3)return{decision:`escalate`,reason:`sidecar decline streak; needs human review`};if(!i.sessionId){let r=yt();await zn(e,t,r,!1,`You are the approval reviewer for a "coder" background coding task. The task runs inside an OS sandbox; you review only actions that escape it.
|
|
81
81
|
|
|
82
82
|
Rules:
|
|
83
83
|
- git stays read-only: decline any git write (commit/push/checkout/reset/...).
|
|
@@ -88,5 +88,5 @@ Rules:
|
|
|
88
88
|
|
|
89
89
|
You may Read/Grep files to inform a decision: the workspace (your cwd) to judge whether an action fits the code, and the task's progress log noted below to see what the task has been doing. Do this only when the action line alone is not enough — most decisions should not need it.
|
|
90
90
|
|
|
91
|
-
Reply with ONLY one line of JSON: {"decision":"accept"|"decline"|"escalate","reason":"<short>"}. Acknowledge now with {"decision":"escalate","reason":"ready"}.${n.taskGoal?`\n\nTask goal: ${n.taskGoal.replace(/\s+/g,` `).slice(0,500)}`:``}${`\nTask progress log: ${
|
|
92
|
-
`),
|
|
91
|
+
Reply with ONLY one line of JSON: {"decision":"accept"|"decline"|"escalate","reason":"<short>"}. Acknowledge now with {"decision":"escalate","reason":"ready"}.${n.taskGoal?`\n\nTask goal: ${n.taskGoal.replace(/\s+/g,` `).slice(0,500)}`:``}${`\nTask progress log: ${H.join(t,`log.jsonl`)}`}`),i.sessionId=r,de(Fn(t),i)}let a=Bn(await zn(e,t,i.sessionId,!0,`action: ${n.summary.slice(0,500)}`));return a?.decision===`decline`?i.declineStreak+=1:a?.decision===`accept`&&(i.declineStreak=0),de(Fn(t),i),a??{decision:`escalate`,reason:`sidecar verdict unparseable`}}catch(e){return{decision:`escalate`,reason:`sidecar unavailable: ${e instanceof Error?e.message:String(e)}`}}finally{r?.()}}const Hn=new Set([`Write`,`Edit`,`MultiEdit`,`NotebookEdit`]);async function Un(e,t,n){let a=String(n.tool_name??``),o=n.input??n.tool_input??{},s=i(e),c=r(e,t),l=j(e),d=n=>u(e,t,n),f,p;if(a===`Bash`){let e=String(o.command??``);p=`run command: ${e||`(unknown command)`}`,f=Qe(e,{allowedNetworkHosts:l.approvals.allowedNetworkHosts})}else if(Hn.has(a)){let e=String(o.file_path??o.notebook_path??``);p=`${a}: ${e||`(unknown path)`}`,f=xe(e?[e]:[],s)}else p=`${a||`(unknown tool)`}: ${JSON.stringify(o).slice(0,200)}`,f={decision:`escalate`,reason:`tool needs approval: ${a}`};d({kind:`approval-decision`,method:a,decision:f.decision,reason:f.reason,summary:p});let m=f.decision,g=f.reason;if(m===`escalate`){let n=await Vn(e,c,{taskGoal:h(e,t)?.prompt??null,summary:p});d({kind:`sidecar-decision`,decision:n.decision,reason:n.reason,summary:p}),n.decision===`escalate`?(m=await T(c,{method:`claude/${a}`,summary:p,params:{tool_name:a,input:o}},{timeoutMs:l.approvals.escalationTimeoutMs,onEvent:d}),g=`escalated for human review`):(m=n.decision,g=n.reason)}return m===`accept`?{behavior:`allow`,updatedInput:o}:{behavior:`deny`,message:`Denied by coder policy: ${g}`}}const Wn={approval_prompt:{description:`Coder approval policy for claude permission prompts.`,inputSchema:{type:`object`,additionalProperties:!0},handler:Un}};async function Gn(e){let{options:t,positionals:n}=g(e,U.object({cwd:b})),r=A(t),i=n[0],a=e=>B.stdout.write(`${JSON.stringify(e)}\n`),o=vt.createInterface({input:B.stdin,terminal:!1});for await(let e of o){if(!e.trim())continue;let t;try{t=JSON.parse(e)}catch{continue}let{id:n,method:o,params:s}=t;if(o===`initialize`)a({jsonrpc:`2.0`,id:n,result:{protocolVersion:s?.protocolVersion??`2024-11-05`,capabilities:{tools:{}},serverInfo:{name:`coder`,version:_()}}});else if(o===`tools/list`)a({jsonrpc:`2.0`,id:n,result:{tools:Object.entries(Wn).map(([e,t])=>({name:e,description:t.description,inputSchema:t.inputSchema}))}});else if(o===`tools/call`){let e=Wn[String(s?.name??``)],t;try{if(!e)throw Error(`unknown tool: ${s?.name}`);t=await e.handler(r,i,s?.arguments??{})}catch(e){t={behavior:`deny`,message:`coder mcp tool failed: ${e instanceof Error?e.message:String(e)}`}}a({jsonrpc:`2.0`,id:n,result:{content:[{type:`text`,text:JSON.stringify(t)}]}})}else n!==void 0&&a({jsonrpc:`2.0`,id:n,result:{}})}}B.stdout.on(`error`,e=>{throw e.code===`EPIPE`&&B.exit(0),e});const Kn={run:kn,list:mt,watch:z,stream:z,result:jn,steer:pt,ask:it,stop:be,archive:ne,delete:ft,approvals:Nn,approve:Pn};async function qn(e){let[t,...n]=e;if(t===void 0||t===`help`||t===`-h`||t===`--help`){B.stdout.write(Y());return}let r=Kn[t];if(r||(B.stdout.write(Y()),k(`Unknown task subcommand "${t}".`,{hint:`Run a task: coder run "<text>"`})),X(n)){let e=t===`stream`?`watch`:t;B.stdout.write(J(`task ${e}`)??Y());return}await r(n)}const Jn={task:qn,flow:vn,run:kn,list:mt,watch:z,result:jn,stream:z,steer:pt,ask:it,stop:be,archive:ne,delete:ft,approvals:Nn,approve:Pn,config:st,"setup-host":lt,"host-setup":lt,setup:lt,model:ot,docs:ut,upgrade:dt,update:dt,_worker:An,_mcp:Gn,_refreshUpdate:async()=>ce(_()),_archiveSweep:pe};async function Yn(){let[e,...t]=B.argv.slice(2);if(e===`--version`||e===`-v`){B.stdout.write(`${_()}\n`);return}if(e===void 0||e===`help`||e===`--help`||e===`-h`){if(t[0]===`task`&&t[1]===void 0){B.stdout.write(Y());return}if(t[0]===`model`&&t[1]===void 0){B.stdout.write(Tt());return}if(t[0]===`flow`&&t[1]===void 0){B.stdout.write(q());return}let e=t.map(e=>(e===`task`||e===`model`||e===`flow`)&&t[1]?`${e} ${t[1]}`:St[e]??e).find(e=>K[e]);B.stdout.write(e&&J(e)||Dt());return}e!==`_worker`&&e!==`_mcp`&&e!==`_refreshUpdate`&&e!==`_archiveSweep`&&ae(_(),m);let n=Jn[e];if(n||(B.stdout.write(Dt()),B.stdout.write(`
|
|
92
|
+
`),k(`Unknown command "${e}".`,{hint:`See all commands: coder --help`})),e===`model`&&X(t)){let e=t.find(e=>!e.startsWith(`-`));B.stdout.write(e&&J(`model ${e}`)||Tt());return}if(e!==`task`&&e!==`flow`&&X(t)){let t=St[e]??e;B.stdout.write(J(t)??Dt());return}try{await n(t)}catch(t){let n=t instanceof Error?t.message:String(t);if(/^(Unknown option|Missing value)/.test(n)){let t=St[e]??e;K[t]&&k(n,{hint:`Help: coder ${e} --help`})}throw t}}Yn().catch(e=>{B.stderr.write(`${e instanceof Error?e.message:String(e)}\n`),B.exit(1)});export{};
|
package/dist/flow/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e,C as t,M as n,S as r,_ as i,a,c as o,d as s,f as c,g as l,i as u,m as d,n as f,o as p,r as m,s as h,x as g,y as _}from"../runtime-
|
|
1
|
+
import{A as e,C as t,M as n,S as r,_ as i,a,c as o,d as s,f as c,g as l,i as u,m as d,n as f,o as p,r as m,s as h,x as g,y as _}from"../runtime-SneScSWY.js";const v=new Proxy({},{get(e,t){return u()?.[t]},has(e,t){let n=u();return n!=null&&t in Object(n)},ownKeys(){let e=u();return e?Reflect.ownKeys(Object(e)):[]},getOwnPropertyDescriptor(e,t){let n=u();if(n!=null&&t in Object(n))return{enumerable:!0,configurable:!0,value:n[t]}}});function y(e){let t=l(e);if(!t)throw new n(`flow-failed`,`No flow run "${e}".`,{hint:`Recent runs: coder flow list`});if(t.status===`running`||t.status===`queued`)throw new n(`flow-failed`,`Run ${t.runId} is still running.`,{runId:t.runId,hint:`Stop it first: coder flow stop ${t.runId}`});return t}const b={run(e,t={}){return _(e,t)},list(e={}){return m(e).runs},discover(t){return e(t??process.cwd())},result(e,t={}){let n=e?l(e):s()[0]??null;return n?{...n,steps:h(n.runId,t.tail)}:null},stream(e,t={}){let n=e??s()[0]?.runId;if(!n)throw Error(`No flow runs to stream.`);return r(n,void 0,{tail:t.tail})},stop(e,t={}){return g(e,t)},resume(e,t={}){let n=e??s()[0]?.runId;if(!n)throw Error(`No flow runs to resume.`);return i(n,t)},archive(e){return f(y(e)),{runId:e,archived:!0}},delete(e){return y(e),{runId:e,deleted:a(e)}}};export{n as CoderError,v as args,b as default,b as flowSdk,p as flow,o as gate,c as log,d as pipeline,t as task};
|