@koalaauto/agentchannel 3.36.3 → 3.36.5
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/src/args.d.ts +1 -1
- package/dist/src/args.js +1 -1
- package/dist/src/cli.js +16 -4
- package/dist/src/sandboxcheck.d.ts +2 -0
- package/dist/src/sandboxcheck.js +41 -3
- package/dist/src/selfupdate.d.ts +55 -2
- package/dist/src/selfupdate.js +148 -2
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/dist/src/args.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export declare function parseCli(argv: string[]): Parsed;
|
|
|
16
16
|
* runs over the more indented lines under it.
|
|
17
17
|
*/
|
|
18
18
|
export declare function helpFor(words: string[]): string;
|
|
19
|
-
export declare const HELP = "ach - AgentChannel CLI\n\nSetup: npx -y @koalaauto/agentchannel@3 join <ach2.invite> [--name <n>] [--service] [--yes] [--dry-run] (run it in the\n project directory: a line from the panel's \"Connect an agent\" creates the agent there, named\n \"<your name>-<directory>\" (lowercase) unless --name says otherwise; a line from the panel or\n `ach admin invite <agent>`: stores the agent's key and adds the `ach` MCP server to the agent's own tool\n (Claude Code or Codex). In a terminal it shows the hub and every command first and asks once; --yes skips\n that; run by an agent (no terminal) it just does it. --service also installs the background helper\n (notifications only where there is a desktop). --dry-run prints the plan and uses nothing)\n ach login --hub <url> --key <ach_sk_...> | ach me | ach agents\n ach doctor (hub, front door, key; then this machine: which `ach` runs, claude/codex login and MCP entry)\n ach doctor --codex-sandbox-setup (Windows, Codex agents: sets up Codex's elevated sandbox once; asks for administrator approval)\n ach notify --test (shows a test desktop notification: checks the background helper can reach you)\nTasks: ach send --to <agent> --title <t> --priority P0..P3 --purpose <p> --key-question <q> --money <m> --handoff-file <f>\n [--depends <id> ...] (not handed out until those tasks complete) [--base <branch|commit>] [--repo <name>] [--read-repo <name>[@base] ...] [--attach <file> ...]\n [--review] (the task waits for acceptance when its worker is done: ach accept or ach request-changes)\n ach accept <task> [<note>] | ach request-changes <task> \"<what to change>\" (the sender's side judges work sent with --review)\n ach handoff <taskId> --note <change note> [--file <f>] [--priority P0..P3] [--purpose p] [--money m] [--key-question q] [--attach <file> ...]\n [--channel <name>] (default: the channel named like --repo, else #general)\n ach task <id|TASK-128> (lists attachments with download URLs) | ach inbox [--owner]\n Every task argument also takes the TASK-<seq> number shown in the panel (TASK-128; T-128 still works).\n ach download <taskId> [--out <dir>] (fetches every attachment; default ./ach-files-<taskId>)\nRecurring: ach schedule add --to <agent> --title <t> --money <m> --handoff-file <f> --every day|weekday|week|month --at HH:MM\n [--weekday 1..7] [--day 1..28] [--tz +08:00] [--purpose p] [--priority P0..P3] [--channel <name>]\n (a proposal: it runs only after your owner replies \"approve\"; {date} in the title/handoff becomes the run's date;\n a run is skipped while the previous one is still open)\n ach schedule add ... --on task_completed|task_failed|figure|post --match '<json>' (an event rule instead of a time:\n task: {\"to\":\"puller\",\"title\":\"pull\"} (its own tasks only); figure: {\"topic\":\"ads\",\"metric\":\"Meta daily spend\",\"op\":\">\",\"value\":5000};\n post: {\"channel\":\"ci\",\"contains\":\"failed\"}. {ref} {title} {link} {metric} {value} {unit} {text} fill the title/handoff)\n ach schedules | ach schedule pause <id> | ach schedule resume <id> | ach schedule rm <id> (resume: your owner, in the panel or with a person's session)\nMessages: ach ask [--task <id>] [--to <agent>] \"<question>\"\n ach answer [--task <id>] --reply-to <msgId> --evidence \"<files/commands>\" \"<answer>\"\n ach decide [--task <id>] <requestId> \"<reply>\" (interactive sessions only, with your agent key: your owner's reply, marked \"via <agent>\")\n ach decide [--task <id>] <requestId> --grant <id> --option <n> (a runner, within an authorization grant)\nAuthorization: ach grant (--agent <name> | --person <who>) (--task <TASK-n> | --channel <name>) --cap <usd> [--until YYYY-MM-DD]\n [--note \"<guidance>\"] [--requester <agent|person>] (your agent key: you, present, grant it; never a run token)\n ach grants | ach revoke <grantId>\n ach ask-human [--task <id>] [--to both|<person name|email>] \"<one question>\" --option \"A|detail|$450\" --option \"B|detail|$0\" [--recommend 0]\n (2\u20133 options, recommended first, money/impact on each; the person replies by picking one or typing;\n `decide-request` is the older name)\n ach progress [--task <id>] \"<text>\" | ach note [--task <id>] \"<text>\"\n Each takes --attach <file> (repeatable; png, jpg, webp, gif, mp4, webm, mov; text/code up to 2 MB:\n txt md json ts js py go sh diff patch log csv yaml sql; .html reports; inside a spawned\n agent the file must be inside the working directory).\nChannels: ach channels [--all] | ach channel [<#name>] [--since <iso>] [--before <iso>] [--limit n]\n ach post <#name|name|title> \"<text>\" [--attach <file> ...] [--announce] (@agent mentions wake that agent for a read-only reply;\n an @name that matches nobody is warned about, with the closest name;\n --announce: \"shipped\" / \"data published\": an announcement every channel reader is notified of)\n ach reply [<postId>] \"<text>\" [--evidence \"<files/commands>\"] [--escalate [--to owner|asker] | --as-owner] [--attach <file> ...]\n (postId defaults to $ACH_THREAD_ID in a mention run)\n ach thread <postId> | ach search \"<query>\" [--channel <name>] [--author <agent|person>] [--limit n]\n Inside a spawned agent: no new top-level posts; replies only in the task's own thread.\nMemory: ach recall \"<query>\" [--limit 5] (one line + link per hit: what the team already knows)\n ach remember [--channel <name>] [--topic <slug>] --source <link> \"<one fact or lesson>\" (source: hub permalink or GitHub URL)\n ach remember --to-team --source <link> \"<one fact>\" (members of a private channel: make one statement team-visible;\n its source stays private: others see \"source: private channel\")\n ach decide-draft [--by <person>] --source <link> [--task <id>] [--topic <slug>] [--scope task|channel] \"<the decision>\"\n (asks that person; their reply records it. Task-only unless it says \"from now on\"/\"always\"/\"\u4EE5\u540E\u90FD\")\n ach memory search \"<query>\" [--limit n] | ach memory read <slug>\n ach memory pull <dir> [--channel <name>] | ach memory push <dir> --note \"<what changed>\" (maintainers; Markdown + YAML\n front matter; per-page note: in front matter; every problem line is listed with its reason)\n ach memory seed --from-imports (maintainers: one upkeep task per channel over its imported GitHub issues/PRs)\n ach memory hook [--channel <name> | --task <id>] (a bounded Memory summary for a Claude Code SessionStart hook;\n default: --channel, $ACH_TASK_ID, a .ach-channel file in this or a parent directory, else your main channel)\n ach memory lang [en|zh] (admins: the language pages are written in)\nWorking: ach claim <task> (take a task sent to your agent and work it yourself, interactively; no runner starts)\nFinishing: ach complete [--task <id>] [--run-id <r>] [--result-file <f> | \"<text>\"] [--attach <file> ...]\n ach fail [--task <id>] [--run-id <r>] \"<reason>\" | ach cancel <id> [--reason <r>]\n With your agent key and no --run-id: an unclaimed task sent to your agent is claimed interactively\n first (complete), or declined (fail); a task you claimed with `ach claim` uses that claim.\nRunner: ach run --dir <path> [--repo name=path ...] [--runtime claude|codex|kiro] [--interval 3] [--max 2]\n [--perm read|workdir|full] [--model m] [--pass-env NAME ...]\n [--claim-delay <sec> | --interactive-first] (default 0; --interactive-first = 60 s for you to claim first)\n [--no-trace] (keep execution traces on this machine; ACH_NO_TRACE=1 too)\n [--notify | --no-notify] (desktop notifications for your owner's important / needs-you items;\n default on for --install-service where there is a desktop, off otherwise)\n ach run --install-service [same flags] (installs and starts a launchd/systemd user unit; runs at login)\n ach run --gc [--dir <path>] [--days 7]\nMCP: ach mcp (stdio server; your interactive agent can also claim and work tasks)\nPanel: ach open [--print] (opens the panel in your browser, logged in as this agent's owner; 60 s single-use link)\nAdmin: ach admin login --link <login link>\n ach admin users | ach admin create-user --name <n> [--email <e>] [--admin] (prints a 24 h one-time join link)\n ach admin login-link <email|userId> (a new one-time login link for a new device)\n ach admin user <email|userId> [--deactivate [--reassign-to <user>] | --reactivate] [--admin true|false] [--confirm-name <name>] [--name n] [--email e]\n ach admin create-agent --name <slug> [--owner <email|userId>] --runtime claude|codex|kiro|other --description <d>\n [--perm read|workdir|full] [--budget <usd>] [--net-allow a.com,b.com] [--invite] [--cf-token]\n ach admin invite <agent> [--line] [--lang zh|en] [--cf-token] (rotates the key; prints a paragraph to paste into the engineer's\n Claude/Codex: join, background helper + notifications, a test notification, the inbox. --line: only\n the join line npx -y @koalaauto/agentchannel@3 join <blob>. Language: --lang, else the hub's (Memory) language.\n --cf-token: also put the hub's shared front-door (Cloudflare Access) token in the line; off by default)\n ach admin invite <person> [--feishu] (prints a one-time login link; --feishu sends it on Feishu)\nOnboarding: ach admin import github --org <org> [--since 60d] --dry-run [--out plan.json] (reads GitHub with your gh login; writes a plan)\n ach admin import github --org <org> --link <one-time admin link> [--yes] (the line from the panel's Settings -> Import:\n logs in with the 15-minute link for this import only, shows the dry run, then imports on a yes / --yes)\n ach admin import github --org <org> [--plan plan.json] (channels, people, issues/PRs; idempotent, re-run updates)\n Two ranges: posted to channels = open items + items closed/merged in the last N days\n [--post-closed-days N (alias --closed-days), default 7 | --all]; used to seed Memory (links only) = closed\n items of the last M months [--seed-months M, default 6 | --seed-all]. The hub keeps both for sync.\n [--exclude security,secret,... | --no-exclude] (default exclusion:\n security, \u5B89\u5168, \u6F0F\u6D1E, secret, \u5BC6\u94A5 in labels or title: never sent, not even an excerpt)\n Plan: \"visibility\": \"private\" on a channel + people \"channels\" = members-only (the hub otherwise\n widens access: everyone on the hub reads team channels, even repos they cannot see on GitHub).\n ach admin sync github [--org <org>] [same range and --exclude flags] (issues/PRs updated since the last\n import/sync; items that closed since then still update their posts; releases too; cron-friendly)\n [--every 5m [--runs N]] (keep syncing in a loop; or cron: */5 * * * * ach admin sync github)\n ach admin invite --feishu [--people a,b] [--map login=ou_xxx ...] [--yes] (Feishu DMs via lark-cli; preview without --yes)\n ach admin invite --people a,b --yes (prints one-time login links to send yourself)\n ach admin rotate-key <name|id> | ach admin set <agentId> [--active true|false] [--perm p] [--budget usd]\n [--description d] [--accept-from a,b] [--net-allow a.com,b.com]\n ach admin profile [--notify-webhook <url>] [--name <n>] (your own account)\n ach admin decide --task <id> --message <msgId> \"<decision>\" [--attach <file> ...]\n ach admin note --task <id> \"<text>\" [--attach <file> ...] (a human note to the agents on a task)\n ach admin channels [list | create [--name path] [--folder f] [--title t] | archive <#name> | unarchive <#name>]\n ach admin channels move <#old> <#new-path> (a channel is a path like reela/onair, at most 3 levels; the old path keeps working)\n ach admin channels private|team <#name> [--cascade] (private: members and admins only; never wider than the channel above)\n ach admin channels members <#name> [--add a,b] [--remove c] (people by email or GitHub login)\n ach admin embeds [--set host1,host2] (embed allowlist; public suffixes are refused)\n ach admin wiki-lang [en|zh] (= ach memory lang: the language Memory pages are written in; default ACH_DEFAULT_LANG)\n ach admin memory-maintainers [<agent> ...] (who keeps Memory current; no name: show it. Default: the admin agent with no setup problem seen most recently)\n ach admin memory-upkeep [<#channel>] (queue Memory upkeep now; also restarts one paused after repeated failures)\n\n--task defaults to $ACH_TASK_ID. Links use ACH_PUBLIC_URL when set (else the hub URL). Env: ACH_HUB, ACH_KEY, ACH_RUN_TOKEN, ACH_CF_ID, ACH_CF_SECRET, AGENTCHANNEL_HOME,\nACH_KEYSTORE=file (store the agent key in a 0600 file instead of the OS keychain).\nHome: ~/.config/agentchannel ($XDG_CONFIG_HOME/agentchannel; AGENTCHANNEL_HOME overrides).\nInside a spawned agent (ACH_RUN_TOKEN set) login, join, open, admin, run, mcp, send, handoff, cancel, doctor, post and search are refused.\n";
|
|
19
|
+
export declare const HELP = "ach - AgentChannel CLI\n\nSetup: npx -y @koalaauto/agentchannel@3 join <ach2.invite> [--name <n>] [--service] [--yes] [--dry-run] (run it in the\n project directory: a line from the panel's \"Connect an agent\" creates the agent there, named\n \"<your name>-<directory>\" (lowercase) unless --name says otherwise; a line from the panel or\n `ach admin invite <agent>`: stores the agent's key and adds the `ach` MCP server to the agent's own tool\n (Claude Code or Codex). In a terminal it shows the hub and every command first and asks once; --yes skips\n that; run by an agent (no terminal) it just does it. --service also installs the background helper\n (notifications only where there is a desktop). --dry-run prints the plan and uses nothing)\n ach login --hub <url> --key <ach_sk_...> | ach me | ach agents\n ach doctor (hub, front door, key; then this machine: which `ach` runs, claude/codex login and MCP entry)\n ach doctor --codex-sandbox-setup (Windows, Codex agents: sets up Codex's elevated sandbox once; run it in a terminal opened as administrator)\n ach notify --test (shows a test desktop notification: checks the background helper can reach you)\nTasks: ach send --to <agent> --title <t> --priority P0..P3 --purpose <p> --key-question <q> --money <m> --handoff-file <f>\n [--depends <id> ...] (not handed out until those tasks complete) [--base <branch|commit>] [--repo <name>] [--read-repo <name>[@base] ...] [--attach <file> ...]\n [--review] (the task waits for acceptance when its worker is done: ach accept or ach request-changes)\n ach accept <task> [<note>] | ach request-changes <task> \"<what to change>\" (the sender's side judges work sent with --review)\n ach handoff <taskId> --note <change note> [--file <f>] [--priority P0..P3] [--purpose p] [--money m] [--key-question q] [--attach <file> ...]\n [--channel <name>] (default: the channel named like --repo, else #general)\n ach task <id|TASK-128> (lists attachments with download URLs) | ach inbox [--owner]\n Every task argument also takes the TASK-<seq> number shown in the panel (TASK-128; T-128 still works).\n ach download <taskId> [--out <dir>] (fetches every attachment; default ./ach-files-<taskId>)\nRecurring: ach schedule add --to <agent> --title <t> --money <m> --handoff-file <f> --every day|weekday|week|month --at HH:MM\n [--weekday 1..7] [--day 1..28] [--tz +08:00] [--purpose p] [--priority P0..P3] [--channel <name>]\n (a proposal: it runs only after your owner replies \"approve\"; {date} in the title/handoff becomes the run's date;\n a run is skipped while the previous one is still open)\n ach schedule add ... --on task_completed|task_failed|figure|post --match '<json>' (an event rule instead of a time:\n task: {\"to\":\"puller\",\"title\":\"pull\"} (its own tasks only); figure: {\"topic\":\"ads\",\"metric\":\"Meta daily spend\",\"op\":\">\",\"value\":5000};\n post: {\"channel\":\"ci\",\"contains\":\"failed\"}. {ref} {title} {link} {metric} {value} {unit} {text} fill the title/handoff)\n ach schedules | ach schedule pause <id> | ach schedule resume <id> | ach schedule rm <id> (resume: your owner, in the panel or with a person's session)\nMessages: ach ask [--task <id>] [--to <agent>] \"<question>\"\n ach answer [--task <id>] --reply-to <msgId> --evidence \"<files/commands>\" \"<answer>\"\n ach decide [--task <id>] <requestId> \"<reply>\" (interactive sessions only, with your agent key: your owner's reply, marked \"via <agent>\")\n ach decide [--task <id>] <requestId> --grant <id> --option <n> (a runner, within an authorization grant)\nAuthorization: ach grant (--agent <name> | --person <who>) (--task <TASK-n> | --channel <name>) --cap <usd> [--until YYYY-MM-DD]\n [--note \"<guidance>\"] [--requester <agent|person>] (your agent key: you, present, grant it; never a run token)\n ach grants | ach revoke <grantId>\n ach ask-human [--task <id>] [--to both|<person name|email>] \"<one question>\" --option \"A|detail|$450\" --option \"B|detail|$0\" [--recommend 0]\n (2\u20133 options, recommended first, money/impact on each; the person replies by picking one or typing;\n `decide-request` is the older name)\n ach progress [--task <id>] \"<text>\" | ach note [--task <id>] \"<text>\"\n Each takes --attach <file> (repeatable; png, jpg, webp, gif, mp4, webm, mov; text/code up to 2 MB:\n txt md json ts js py go sh diff patch log csv yaml sql; .html reports; inside a spawned\n agent the file must be inside the working directory).\nChannels: ach channels [--all] | ach channel [<#name>] [--since <iso>] [--before <iso>] [--limit n]\n ach post <#name|name|title> \"<text>\" [--attach <file> ...] [--announce] (@agent mentions wake that agent for a read-only reply;\n an @name that matches nobody is warned about, with the closest name;\n --announce: \"shipped\" / \"data published\": an announcement every channel reader is notified of)\n ach reply [<postId>] \"<text>\" [--evidence \"<files/commands>\"] [--escalate [--to owner|asker] | --as-owner] [--attach <file> ...]\n (postId defaults to $ACH_THREAD_ID in a mention run)\n ach thread <postId> | ach search \"<query>\" [--channel <name>] [--author <agent|person>] [--limit n]\n Inside a spawned agent: no new top-level posts; replies only in the task's own thread.\nMemory: ach recall \"<query>\" [--limit 5] (one line + link per hit: what the team already knows)\n ach remember [--channel <name>] [--topic <slug>] --source <link> \"<one fact or lesson>\" (source: hub permalink or GitHub URL)\n ach remember --to-team --source <link> \"<one fact>\" (members of a private channel: make one statement team-visible;\n its source stays private: others see \"source: private channel\")\n ach decide-draft [--by <person>] --source <link> [--task <id>] [--topic <slug>] [--scope task|channel] \"<the decision>\"\n (asks that person; their reply records it. Task-only unless it says \"from now on\"/\"always\"/\"\u4EE5\u540E\u90FD\")\n ach memory search \"<query>\" [--limit n] | ach memory read <slug>\n ach memory pull <dir> [--channel <name>] | ach memory push <dir> --note \"<what changed>\" (maintainers; Markdown + YAML\n front matter; per-page note: in front matter; every problem line is listed with its reason)\n ach memory seed --from-imports (maintainers: one upkeep task per channel over its imported GitHub issues/PRs)\n ach memory hook [--channel <name> | --task <id>] (a bounded Memory summary for a Claude Code SessionStart hook;\n default: --channel, $ACH_TASK_ID, a .ach-channel file in this or a parent directory, else your main channel)\n ach memory lang [en|zh] (admins: the language pages are written in)\nWorking: ach claim <task> (take a task sent to your agent and work it yourself, interactively; no runner starts)\nFinishing: ach complete [--task <id>] [--run-id <r>] [--result-file <f> | \"<text>\"] [--attach <file> ...]\n ach fail [--task <id>] [--run-id <r>] \"<reason>\" | ach cancel <id> [--reason <r>]\n With your agent key and no --run-id: an unclaimed task sent to your agent is claimed interactively\n first (complete), or declined (fail); a task you claimed with `ach claim` uses that claim.\nRunner: ach run --dir <path> [--repo name=path ...] [--runtime claude|codex|kiro] [--interval 3] [--max 2]\n [--perm read|workdir|full] [--model m] [--pass-env NAME ...]\n [--claim-delay <sec> | --interactive-first] (default 0; --interactive-first = 60 s for you to claim first)\n [--no-trace] (keep execution traces on this machine; ACH_NO_TRACE=1 too)\n [--notify | --no-notify] (desktop notifications for your owner's important / needs-you items;\n default on for --install-service where there is a desktop, off otherwise)\n ach run --install-service [same flags] (installs and starts a launchd/systemd user unit; runs at login)\n ach run --gc [--dir <path>] [--days 7]\nMCP: ach mcp (stdio server; your interactive agent can also claim and work tasks)\nPanel: ach open [--print] (opens the panel in your browser, logged in as this agent's owner; 60 s single-use link)\nAdmin: ach admin login --link <login link>\n ach admin users | ach admin create-user --name <n> [--email <e>] [--admin] (prints a 24 h one-time join link)\n ach admin login-link <email|userId> (a new one-time login link for a new device)\n ach admin user <email|userId> [--deactivate [--reassign-to <user>] | --reactivate] [--admin true|false] [--confirm-name <name>] [--name n] [--email e]\n ach admin create-agent --name <slug> [--owner <email|userId>] --runtime claude|codex|kiro|other --description <d>\n [--perm read|workdir|full] [--budget <usd>] [--net-allow a.com,b.com] [--invite] [--cf-token]\n ach admin invite <agent> [--line] [--lang zh|en] [--cf-token] (rotates the key; prints a paragraph to paste into the engineer's\n Claude/Codex: join, background helper + notifications, a test notification, the inbox. --line: only\n the join line npx -y @koalaauto/agentchannel@3 join <blob>. Language: --lang, else the hub's (Memory) language.\n --cf-token: also put the hub's shared front-door (Cloudflare Access) token in the line; off by default)\n ach admin invite <person> [--feishu] (prints a one-time login link; --feishu sends it on Feishu)\nOnboarding: ach admin import github --org <org> [--since 60d] --dry-run [--out plan.json] (reads GitHub with your gh login; writes a plan)\n ach admin import github --org <org> --link <one-time admin link> [--yes] (the line from the panel's Settings -> Import:\n logs in with the 15-minute link for this import only, shows the dry run, then imports on a yes / --yes)\n ach admin import github --org <org> [--plan plan.json] (channels, people, issues/PRs; idempotent, re-run updates)\n Two ranges: posted to channels = open items + items closed/merged in the last N days\n [--post-closed-days N (alias --closed-days), default 7 | --all]; used to seed Memory (links only) = closed\n items of the last M months [--seed-months M, default 6 | --seed-all]. The hub keeps both for sync.\n [--exclude security,secret,... | --no-exclude] (default exclusion:\n security, \u5B89\u5168, \u6F0F\u6D1E, secret, \u5BC6\u94A5 in labels or title: never sent, not even an excerpt)\n Plan: \"visibility\": \"private\" on a channel + people \"channels\" = members-only (the hub otherwise\n widens access: everyone on the hub reads team channels, even repos they cannot see on GitHub).\n ach admin sync github [--org <org>] [same range and --exclude flags] (issues/PRs updated since the last\n import/sync; items that closed since then still update their posts; releases too; cron-friendly)\n [--every 5m [--runs N]] (keep syncing in a loop; or cron: */5 * * * * ach admin sync github)\n ach admin invite --feishu [--people a,b] [--map login=ou_xxx ...] [--yes] (Feishu DMs via lark-cli; preview without --yes)\n ach admin invite --people a,b --yes (prints one-time login links to send yourself)\n ach admin rotate-key <name|id> | ach admin set <agentId> [--active true|false] [--perm p] [--budget usd]\n [--description d] [--accept-from a,b] [--net-allow a.com,b.com]\n ach admin profile [--notify-webhook <url>] [--name <n>] (your own account)\n ach admin decide --task <id> --message <msgId> \"<decision>\" [--attach <file> ...]\n ach admin note --task <id> \"<text>\" [--attach <file> ...] (a human note to the agents on a task)\n ach admin channels [list | create [--name path] [--folder f] [--title t] | archive <#name> | unarchive <#name>]\n ach admin channels move <#old> <#new-path> (a channel is a path like reela/onair, at most 3 levels; the old path keeps working)\n ach admin channels private|team <#name> [--cascade] (private: members and admins only; never wider than the channel above)\n ach admin channels members <#name> [--add a,b] [--remove c] (people by email or GitHub login)\n ach admin embeds [--set host1,host2] (embed allowlist; public suffixes are refused)\n ach admin wiki-lang [en|zh] (= ach memory lang: the language Memory pages are written in; default ACH_DEFAULT_LANG)\n ach admin memory-maintainers [<agent> ...] (who keeps Memory current; no name: show it. Default: the admin agent with no setup problem seen most recently)\n ach admin memory-upkeep [<#channel>] (queue Memory upkeep now; also restarts one paused after repeated failures)\n\n--task defaults to $ACH_TASK_ID. Links use ACH_PUBLIC_URL when set (else the hub URL). Env: ACH_HUB, ACH_KEY, ACH_RUN_TOKEN, ACH_CF_ID, ACH_CF_SECRET, AGENTCHANNEL_HOME,\nACH_KEYSTORE=file (store the agent key in a 0600 file instead of the OS keychain).\nHome: ~/.config/agentchannel ($XDG_CONFIG_HOME/agentchannel; AGENTCHANNEL_HOME overrides).\nInside a spawned agent (ACH_RUN_TOKEN set) login, join, open, admin, run, mcp, send, handoff, cancel, doctor, post and search are refused.\n";
|
|
20
20
|
export {};
|
package/dist/src/args.js
CHANGED
|
@@ -179,7 +179,7 @@ Setup: npx -y @koalaauto/agentchannel@3 join <ach2.invite> [--name <n>] [--
|
|
|
179
179
|
(notifications only where there is a desktop). --dry-run prints the plan and uses nothing)
|
|
180
180
|
ach login --hub <url> --key <ach_sk_...> | ach me | ach agents
|
|
181
181
|
ach doctor (hub, front door, key; then this machine: which \`ach\` runs, claude/codex login and MCP entry)
|
|
182
|
-
ach doctor --codex-sandbox-setup (Windows, Codex agents: sets up Codex's elevated sandbox once;
|
|
182
|
+
ach doctor --codex-sandbox-setup (Windows, Codex agents: sets up Codex's elevated sandbox once; run it in a terminal opened as administrator)
|
|
183
183
|
ach notify --test (shows a test desktop notification: checks the background helper can reach you)
|
|
184
184
|
Tasks: ach send --to <agent> --title <t> --priority P0..P3 --purpose <p> --key-question <q> --money <m> --handoff-file <f>
|
|
185
185
|
[--depends <id> ...] (not handed out until those tasks complete) [--base <branch|commit>] [--repo <name>] [--read-repo <name>[@base] ...] [--attach <file> ...]
|
package/dist/src/cli.js
CHANGED
|
@@ -17,7 +17,7 @@ import { isPerm } from './perm.js';
|
|
|
17
17
|
import { AttachError, humanSize, isLinkRef, resolveAttachments, taskFiles } from './attachments.js';
|
|
18
18
|
export { VERSION } from './version.js';
|
|
19
19
|
import { VERSION } from './version.js';
|
|
20
|
-
import { bootGuard, markHealthy, SelfUpdater, superviseSelf, UPDATE_EXIT_CODE } from './selfupdate.js';
|
|
20
|
+
import { bootGuard, markHealthy, SelfUpdater, superviseSelf, UPDATE_EXIT_CODE, UPDATE_HANDOFF_EXIT_CODE, waitForWindowsUpdate } from './selfupdate.js';
|
|
21
21
|
import { installProxy } from './netproxy.js';
|
|
22
22
|
import { inheritedEnv } from './env.js';
|
|
23
23
|
/** At a terminal, a command that replaces an agent's key says what that cuts off and asks (default no). --yes skips it; scripts are not asked. */
|
|
@@ -1571,6 +1571,11 @@ async function runCommand(p, io) {
|
|
|
1571
1571
|
const env = io.env;
|
|
1572
1572
|
if (env.ACH_RUN_TOKEN)
|
|
1573
1573
|
throw new UsageError('run: refusing to start a runner inside a spawned agent (ACH_RUN_TOKEN is set)');
|
|
1574
|
+
// Windows: a release being installed by the helper of the runner before this one (a Startup script restarted it in between).
|
|
1575
|
+
// Wait before the key is read (that loads a native module, whose file the install replaces), then start the new release.
|
|
1576
|
+
if (process.platform === 'win32' && (await waitForWindowsUpdate(achHome(env), { log: io.err }))) {
|
|
1577
|
+
return env.ACH_SUPERVISED === '1' ? UPDATE_EXIT_CODE : superviseSelf({ log: io.err });
|
|
1578
|
+
}
|
|
1574
1579
|
const cfg = loadConfig(env);
|
|
1575
1580
|
// No key on this machine (deleted, a new machine or directory). It exits like a refused key: a service that exits 2 here
|
|
1576
1581
|
// would be restarted for ever, and `ach login` is no way back for someone who no longer has the key.
|
|
@@ -1744,6 +1749,10 @@ async function runCommand(p, io) {
|
|
|
1744
1749
|
// B7: the hub refused the agent key: rotated, agent disabled or owner deactivated.
|
|
1745
1750
|
if (end === 'unauthorized')
|
|
1746
1751
|
return authExit(io);
|
|
1752
|
+
if (updater.restarting && updater.installed === 'handoff') {
|
|
1753
|
+
io.err(`ach run: exiting for the update; the installer starts the runner again when it is done`);
|
|
1754
|
+
return UPDATE_HANDOFF_EXIT_CODE;
|
|
1755
|
+
}
|
|
1747
1756
|
if (updater.restarting) {
|
|
1748
1757
|
// started by hand (no systemd / launchd behind it) from a global install: nothing would start it again, so it does that itself
|
|
1749
1758
|
if (updater.installed === 'global' && process.env.ACH_SUPERVISED !== '1' && !(await import('./servicefix.js')).startedByService(me.name, process.platform, process.env)) {
|
|
@@ -2019,8 +2028,9 @@ export function inboxSummary(r) {
|
|
|
2019
2028
|
}
|
|
2020
2029
|
/**
|
|
2021
2030
|
* `ach doctor --codex-sandbox-setup` (Windows): Codex's one-time elevated sandbox setup for this user, with the network settings a
|
|
2022
|
-
* work run uses (Codex's proxy for the hub), so the firewall rules it provisions match the runs.
|
|
2023
|
-
*
|
|
2031
|
+
* work run uses (Codex's proxy for the hub), so the firewall rules it provisions match the runs. It needs a terminal opened as
|
|
2032
|
+
* administrator: Codex does not raise the prompt itself (orchestrator_elevation_required). Runs then link the setup into their
|
|
2033
|
+
* own Codex home (codexhome.ts).
|
|
2024
2034
|
*/
|
|
2025
2035
|
async function codexSandboxSetup(env, out) {
|
|
2026
2036
|
const zh = isZh(env);
|
|
@@ -2053,6 +2063,8 @@ async function codexSandboxSetup(env, out) {
|
|
|
2053
2063
|
p.on('exit', (c) => res(c ?? 1));
|
|
2054
2064
|
});
|
|
2055
2065
|
const why = failed ? `${codex[0]}: ${failed}` : zh ? `退出码 ${code}` : `exit ${code}`;
|
|
2056
|
-
|
|
2066
|
+
// Codex does not raise its own administrator prompt from here (orchestrator_elevation_required, echo-duck-pr)
|
|
2067
|
+
const admin = zh ? '要在“以管理员身份运行”打开的终端里执行。' : 'It needs a terminal opened as administrator.';
|
|
2068
|
+
out(code === 0 ? (zh ? '设置完成:重启 runner。' : 'Done: restart the runner.') : zh ? `设置没有完成(${why})。${admin}` : `The setup did not finish (${why}). ${admin}`);
|
|
2057
2069
|
return code === 0 ? 0 : 1;
|
|
2058
2070
|
}
|
|
@@ -81,6 +81,8 @@ export declare function detectHost(env?: NodeJS.ProcessEnv, platform?: NodeJS.Pl
|
|
|
81
81
|
* Node cannot start a .cmd without a shell (spawn EINVAL, echo-duck-pr's startup check).
|
|
82
82
|
*/
|
|
83
83
|
export declare function codexCommand(env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string[] | undefined;
|
|
84
|
+
/** The native Codex the SDK starts (@openai/codex-sdk findCodexPath): @openai/codex from the SDK, its platform package's binary. */
|
|
85
|
+
export declare function sdkCodexBinary(platform?: NodeJS.Platform, arch?: string): string | undefined;
|
|
84
86
|
/** `codex` on PATH; on Windows codex.exe, else an npm `codex.cmd` shim as node and its script (see codexCommand). */
|
|
85
87
|
export declare function codexOnPath(env: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string[] | undefined;
|
|
86
88
|
/** What a failed sandbox start said, as a problem. */
|
package/dist/src/sandboxcheck.js
CHANGED
|
@@ -70,6 +70,10 @@ export function detectHost(env = process.env, platform = process.platform) {
|
|
|
70
70
|
* Node cannot start a .cmd without a shell (spawn EINVAL, echo-duck-pr's startup check).
|
|
71
71
|
*/
|
|
72
72
|
export function codexCommand(env = process.env, platform = process.platform) {
|
|
73
|
+
// first the very binary a run starts (the SDK's own lookup), so the check runs what the runs run
|
|
74
|
+
const native = sdkCodexBinary(platform);
|
|
75
|
+
if (native)
|
|
76
|
+
return [native];
|
|
73
77
|
const from = [() => import.meta.url, () => fileURLToPath(import.meta.resolve('@openai/codex-sdk'))];
|
|
74
78
|
for (const base of from) {
|
|
75
79
|
try {
|
|
@@ -83,6 +87,29 @@ export function codexCommand(env = process.env, platform = process.platform) {
|
|
|
83
87
|
}
|
|
84
88
|
return codexOnPath(env, platform);
|
|
85
89
|
}
|
|
90
|
+
const CODEX_TARGETS = {
|
|
91
|
+
'linux-x64': ['x86_64-unknown-linux-musl', '@openai/codex-linux-x64'],
|
|
92
|
+
'linux-arm64': ['aarch64-unknown-linux-musl', '@openai/codex-linux-arm64'],
|
|
93
|
+
'darwin-x64': ['x86_64-apple-darwin', '@openai/codex-darwin-x64'],
|
|
94
|
+
'darwin-arm64': ['aarch64-apple-darwin', '@openai/codex-darwin-arm64'],
|
|
95
|
+
'win32-x64': ['x86_64-pc-windows-msvc', '@openai/codex-win32-x64'],
|
|
96
|
+
'win32-arm64': ['aarch64-pc-windows-msvc', '@openai/codex-win32-arm64'],
|
|
97
|
+
};
|
|
98
|
+
/** The native Codex the SDK starts (@openai/codex-sdk findCodexPath): @openai/codex from the SDK, its platform package's binary. */
|
|
99
|
+
export function sdkCodexBinary(platform = process.platform, arch = process.arch) {
|
|
100
|
+
const t = CODEX_TARGETS[`${platform}-${arch}`];
|
|
101
|
+
if (!t)
|
|
102
|
+
return undefined;
|
|
103
|
+
try {
|
|
104
|
+
const codexPkg = createRequire(fileURLToPath(import.meta.resolve('@openai/codex-sdk'))).resolve('@openai/codex/package.json');
|
|
105
|
+
const vendor = join(dirname(createRequire(codexPkg).resolve(`${t[1]}/package.json`)), 'vendor');
|
|
106
|
+
const bin = join(vendor, t[0], 'bin', platform === 'win32' ? 'codex.exe' : 'codex');
|
|
107
|
+
return existsSync(bin) ? bin : undefined;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
86
113
|
/** `codex` on PATH; on Windows codex.exe, else an npm `codex.cmd` shim as node and its script (see codexCommand). */
|
|
87
114
|
export function codexOnPath(env, platform = process.platform) {
|
|
88
115
|
if (platform !== 'win32') {
|
|
@@ -116,7 +143,9 @@ const PROBE_NOISE = /^warning\b|proceeding, even though/i;
|
|
|
116
143
|
function firstLine(s) {
|
|
117
144
|
const lines = s.split('\n').map((l) => l.trim()).filter(Boolean);
|
|
118
145
|
const real = lines.filter((l) => !PROBE_NOISE.test(l));
|
|
119
|
-
|
|
146
|
+
// a Node stack trace: the `Error: message` line, not the source line above it (`throw new Error(`)
|
|
147
|
+
const thrown = real.find((l) => /^(\w+)?Error\b[^(]*:\s*\S/.test(l));
|
|
148
|
+
return (thrown ?? real.find((l) => !/\bthrow\b|^at\s/.test(l) && /error|fail|denied|refus|cannot|not (found|permitted|allowed)|requires|missing/i.test(l)) ?? real[0] ?? lines[0] ?? '').slice(0, 300);
|
|
120
149
|
}
|
|
121
150
|
/**
|
|
122
151
|
* The two writes: inside the sandbox's directory (must work) and in the home directory (must be refused). With a third
|
|
@@ -299,12 +328,21 @@ export const BWRAP_APPARMOR = `printf '%s\\n' 'abi <abi/4.0>,' 'include <tunable
|
|
|
299
328
|
/** The fix for a failed probe on this host. */
|
|
300
329
|
export function sandboxFix(st, host) {
|
|
301
330
|
const name = st.tool === 'claude' ? 'Claude Code' : 'Codex';
|
|
331
|
+
// the Codex package came without its platform binary (an optional dependency npm skipped): runs cannot start either
|
|
332
|
+
if (st.tool === 'codex' && /Missing optional dependency @openai\/codex-/i.test(st.detail ?? '')) {
|
|
333
|
+
const cmd = 'npm install -g @koalaauto/agentchannel@latest';
|
|
334
|
+
return {
|
|
335
|
+
en: `Codex's program for this system is missing from the install: run \`${cmd}\`, then restart the runner.`,
|
|
336
|
+
zh: `安装里缺少这个系统的 Codex 程序:执行 \`${cmd}\`,再重启 runner。`,
|
|
337
|
+
commands: [cmd],
|
|
338
|
+
};
|
|
339
|
+
}
|
|
302
340
|
// Windows Codex: the run's read limits need the elevated sandbox, set up once per user with administrator approval
|
|
303
341
|
if (st.tool === 'codex' && /requires the elevated Windows sandbox/i.test(st.detail ?? '')) {
|
|
304
342
|
const cmd = 'ach doctor --codex-sandbox-setup';
|
|
305
343
|
return {
|
|
306
|
-
en: `Codex needs its elevated Windows sandbox, set up once on this machine: run
|
|
307
|
-
zh: `Codex 需要 Windows
|
|
344
|
+
en: `Codex needs its elevated Windows sandbox, set up once on this machine: in a terminal run as administrator (Run as administrator), as the user that runs this agent, run \`${cmd}\`, then restart the runner.`,
|
|
345
|
+
zh: `Codex 需要 Windows 提权沙箱,这台机器要设置一次:用“以管理员身份运行”打开终端(同一个运行这个智能体的用户),执行 \`${cmd}\`,再重启 runner。`,
|
|
308
346
|
commands: [cmd],
|
|
309
347
|
};
|
|
310
348
|
}
|
package/dist/src/selfupdate.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** A restart-worthy exit: not 0 (systemd on-failure and launchd restart only a failure) and not 78 (key refused: do not restart). */
|
|
2
2
|
export declare const UPDATE_EXIT_CODE = 75;
|
|
3
|
+
/** Windows: the runner exited so that a helper can install the release (windowsHandoff); the process tree ends, nothing restarts here. */
|
|
4
|
+
export declare const UPDATE_HANDOFF_EXIT_CODE = 76;
|
|
3
5
|
export interface HubVersions {
|
|
4
6
|
latest_client?: string;
|
|
5
7
|
min_client_proto?: number;
|
|
@@ -96,6 +98,9 @@ export interface Quiescable {
|
|
|
96
98
|
export type CheckResult = 'none' | 'manual' | 'off' | 'backoff' | 'busy' | 'failed' | 'restarting';
|
|
97
99
|
export interface SelfUpdaterOptions {
|
|
98
100
|
fetchVersions: () => Promise<HubVersions | null>;
|
|
101
|
+
platform?: NodeJS.Platform;
|
|
102
|
+
/** Windows: starts the helper that installs after this runner exited (default startWindowsUpdate). */
|
|
103
|
+
handoff?: (target: string, dir: string) => boolean;
|
|
99
104
|
runner: Quiescable;
|
|
100
105
|
home: string;
|
|
101
106
|
env?: NodeJS.ProcessEnv;
|
|
@@ -113,8 +118,8 @@ export declare class SelfUpdater {
|
|
|
113
118
|
private o;
|
|
114
119
|
/** True once the install is done and the runner is stopping: the process should exit UPDATE_EXIT_CODE. */
|
|
115
120
|
restarting: boolean;
|
|
116
|
-
/** How the release that was just installed got here (set with `restarting`). */
|
|
117
|
-
installed?: InstallKind['kind'];
|
|
121
|
+
/** How the release that was just installed got here (set with `restarting`); 'handoff': a helper installs it after this exits. */
|
|
122
|
+
installed?: InstallKind['kind'] | 'handoff';
|
|
118
123
|
private timer?;
|
|
119
124
|
private stopped;
|
|
120
125
|
private lastNudge;
|
|
@@ -139,6 +144,54 @@ export declare class SelfUpdater {
|
|
|
139
144
|
heardLatest(latest: string): Promise<CheckResult> | undefined;
|
|
140
145
|
check(): Promise<CheckResult>;
|
|
141
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* The helper (CommonJS, run by the same node, from the AgentChannel home: never from the package it replaces). It waits for the
|
|
149
|
+
* runner's processes to exit, runs `npm install -g` (up to three tries), reads the version back, removes the update lock, and
|
|
150
|
+
* starts the runner again with the same command line unless something else already did (a Startup script that restarts it
|
|
151
|
+
* holds the runner lock by then). It writes what it did to logs/update.log. The plan holds no secrets: the environment is
|
|
152
|
+
* inherited, not written down.
|
|
153
|
+
*/
|
|
154
|
+
export declare const WINDOWS_UPDATER_SCRIPT = "// written by agentchannel (ach): installs a release once the runner has exited (Windows keeps a running program's files)\n'use strict';\nconst { spawn, spawnSync } = require('child_process');\nconst fs = require('fs');\nconst plan = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));\nconst log = (s) => { try { fs.appendFileSync(plan.log, new Date().toISOString() + ' [ach update] ' + s + '\\n'); } catch (e) {} };\nconst alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };\nconst sleep = (ms) => new Promise((r) => setTimeout(r, ms));\n(async () => {\n for (let i = 0; i < 240 && plan.pids.some(alive); i++) await sleep(500);\n await sleep(plan.settleMs);\n let ok = false;\n for (let attempt = 1; attempt <= 3 && !ok; attempt++) {\n const r = spawnSync(plan.npm.file, plan.npm.pre.concat(plan.args), { shell: plan.npm.shell, windowsHide: true, encoding: 'utf8', timeout: 300000 });\n let got = '';\n try { got = JSON.parse(fs.readFileSync(plan.pkgJson, 'utf8')).version; } catch (e) {}\n ok = r.status === 0 && got === plan.target;\n if (ok) log('installed ' + plan.target);\n else { log('npm install -g failed (try ' + attempt + ', exit ' + r.status + ', installed ' + (got || 'nothing') + '): ' + String(r.stderr || r.stdout || r.error || '').trim().split('\\n').slice(-3).join(' | ')); await sleep(5000); }\n }\n try { fs.unlinkSync(plan.lock); } catch (e) {}\n await sleep(plan.settleMs * 10);\n let held = 0;\n try { held = Number(String(fs.readFileSync(plan.runnerLock, 'utf8')).split('@')[0]); } catch (e) {}\n if (held && alive(held)) { log('the runner is running again (pid ' + held + ')'); return; }\n const out = fs.openSync(plan.log, 'a');\n const c = spawn(plan.relaunch.file, plan.relaunch.args, { cwd: plan.relaunch.cwd, detached: true, stdio: ['ignore', out, out], windowsHide: true });\n c.unref();\n log('started the runner again (pid ' + c.pid + ')');\n})();\n";
|
|
155
|
+
export declare const windowsUpdateFiles: (home: string) => {
|
|
156
|
+
script: string;
|
|
157
|
+
plan: string;
|
|
158
|
+
lock: string;
|
|
159
|
+
log: string;
|
|
160
|
+
runnerLock: string;
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Start the Windows install helper (WINDOWS_UPDATER_SCRIPT), detached, for `target` into the global package at `dir`. It waits for
|
|
164
|
+
* this process (and its supervisor, ACH_SUPERVISED) to exit. The update lock holds its pid from the start, so a runner a Startup
|
|
165
|
+
* script restarts in between waits for it (waitForWindowsUpdate) instead of taking the files again. False when it did not start.
|
|
166
|
+
*/
|
|
167
|
+
export declare function startWindowsUpdate(o: {
|
|
168
|
+
home: string;
|
|
169
|
+
target: string;
|
|
170
|
+
dir: string;
|
|
171
|
+
log?: (s: string) => void;
|
|
172
|
+
pids?: number[];
|
|
173
|
+
relaunch?: {
|
|
174
|
+
file: string;
|
|
175
|
+
args: string[];
|
|
176
|
+
cwd: string;
|
|
177
|
+
};
|
|
178
|
+
npm?: {
|
|
179
|
+
file: string;
|
|
180
|
+
pre: string[];
|
|
181
|
+
shell: boolean;
|
|
182
|
+
};
|
|
183
|
+
settleMs?: number;
|
|
184
|
+
spawnHelper?: (script: string, plan: string) => number | undefined;
|
|
185
|
+
}): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Called first thing by `ach run` on Windows, before anything loads a native module: while an install helper is working, wait
|
|
188
|
+
* for it (at most 15 minutes). True when it waited: this process holds the old release's code, so the caller starts the new one.
|
|
189
|
+
*/
|
|
190
|
+
export declare function waitForWindowsUpdate(home: string, o?: {
|
|
191
|
+
log?: (s: string) => void;
|
|
192
|
+
sleep?: (ms: number) => Promise<void>;
|
|
193
|
+
maxMs?: number;
|
|
194
|
+
}): Promise<boolean>;
|
|
142
195
|
export type SpawnSelf = (file: string, args: string[], env: NodeJS.ProcessEnv) => {
|
|
143
196
|
exit: Promise<number>;
|
|
144
197
|
kill: (sig: NodeJS.Signals) => void;
|
package/dist/src/selfupdate.js
CHANGED
|
@@ -8,16 +8,22 @@
|
|
|
8
8
|
// - an MCP session (`ach mcp`, started by Claude Code or Codex): it cannot be restarted from outside, so startStaleNotice
|
|
9
9
|
// pushes one line into the session saying it is behind.
|
|
10
10
|
//
|
|
11
|
+
// - Windows: a running program's files cannot be replaced (npm EBUSY on the keyring native module, and the install left half
|
|
12
|
+
// done), so the runner starts a helper (WINDOWS_UPDATER_SCRIPT) and exits; the helper installs once the runner's processes
|
|
13
|
+
// are gone and starts the runner again, unless a Startup script already did (that runner waits for the helper first).
|
|
14
|
+
//
|
|
11
15
|
// What it never does: move across a major release by itself (the protocol may have changed: a person decides), move a stable
|
|
12
16
|
// install onto a prerelease, touch a CLI it cannot tell how it was installed, or retry a failed update more than once a day.
|
|
13
17
|
// ACH_AUTO_UPDATE=0 turns the installing off (the log and the session notice remain).
|
|
14
18
|
import { execFile, spawn } from 'node:child_process';
|
|
15
|
-
import { accessSync, constants, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
19
|
+
import { accessSync, constants, existsSync, mkdirSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
16
20
|
import { dirname, join, sep } from 'node:path';
|
|
17
21
|
import { thisCliPath } from './invite.js';
|
|
18
22
|
import { CLIENT_PROTO, newerVersion, PKG_NAME, VERSION } from './version.js';
|
|
19
23
|
/** A restart-worthy exit: not 0 (systemd on-failure and launchd restart only a failure) and not 78 (key refused: do not restart). */
|
|
20
24
|
export const UPDATE_EXIT_CODE = 75;
|
|
25
|
+
/** Windows: the runner exited so that a helper can install the release (windowsHandoff); the process tree ends, nothing restarts here. */
|
|
26
|
+
export const UPDATE_HANDOFF_EXIT_CODE = 76;
|
|
21
27
|
const DAY_MS = 24 * 3600_000;
|
|
22
28
|
const CHECK_EVERY_MS = 6 * 3600_000;
|
|
23
29
|
const isVersion = (v) => typeof v === 'string' && /^\d+\.\d+\.\d+(-[0-9A-Za-z.]+)?$/.test(v);
|
|
@@ -148,7 +154,7 @@ export class SelfUpdater {
|
|
|
148
154
|
o;
|
|
149
155
|
/** True once the install is done and the runner is stopping: the process should exit UPDATE_EXIT_CODE. */
|
|
150
156
|
restarting = false;
|
|
151
|
-
/** How the release that was just installed got here (set with `restarting`). */
|
|
157
|
+
/** How the release that was just installed got here (set with `restarting`); 'handoff': a helper installs it after this exits. */
|
|
152
158
|
installed;
|
|
153
159
|
timer;
|
|
154
160
|
stopped = false;
|
|
@@ -264,6 +270,21 @@ export class SelfUpdater {
|
|
|
264
270
|
this.log(`ach ${v.target} is out (this is ${version}): taking no new work, ${this.o.runner.busy()} run(s) to finish first`);
|
|
265
271
|
await this.o.runner.quiesce();
|
|
266
272
|
saveUpdateState(this.o.home, { target: v.target, at: now, attempts: (last?.attempts ?? 0) + 1, previous: version });
|
|
273
|
+
if ((this.o.platform ?? process.platform) === 'win32' && kind.kind === 'global') {
|
|
274
|
+
// Windows will not replace files a running process holds (its native modules: npm EBUSY, and the install left half
|
|
275
|
+
// done): a helper installs once this runner, and its supervisor, have exited, then starts it again (windowsHandoff)
|
|
276
|
+
const started = (this.o.handoff ?? ((t, d) => startWindowsUpdate({ home: this.o.home, target: t, dir: d, log: (x) => this.log(x) })))(v.target, kind.dir);
|
|
277
|
+
if (!started) {
|
|
278
|
+
this.log(`update to ${v.target}: the installer could not be started; staying on ${version}`);
|
|
279
|
+
this.o.runner.unquiesce();
|
|
280
|
+
return 'failed';
|
|
281
|
+
}
|
|
282
|
+
this.log(`exiting so that ${v.target} can be installed (Windows keeps a running program's files); it starts again after`);
|
|
283
|
+
this.restarting = true;
|
|
284
|
+
this.installed = 'handoff';
|
|
285
|
+
await this.o.runner.stop();
|
|
286
|
+
return 'restarting';
|
|
287
|
+
}
|
|
267
288
|
const r = await installRelease(kind, v.target, this.o.exec);
|
|
268
289
|
if (!r.ok) {
|
|
269
290
|
this.log(`update to ${v.target} failed: ${r.detail}; staying on ${version}`);
|
|
@@ -281,6 +302,131 @@ export class SelfUpdater {
|
|
|
281
302
|
}
|
|
282
303
|
}
|
|
283
304
|
}
|
|
305
|
+
// ---- Windows: install after the runner exited ----------------------------------------------------------------------------------
|
|
306
|
+
/**
|
|
307
|
+
* The helper (CommonJS, run by the same node, from the AgentChannel home: never from the package it replaces). It waits for the
|
|
308
|
+
* runner's processes to exit, runs `npm install -g` (up to three tries), reads the version back, removes the update lock, and
|
|
309
|
+
* starts the runner again with the same command line unless something else already did (a Startup script that restarts it
|
|
310
|
+
* holds the runner lock by then). It writes what it did to logs/update.log. The plan holds no secrets: the environment is
|
|
311
|
+
* inherited, not written down.
|
|
312
|
+
*/
|
|
313
|
+
export const WINDOWS_UPDATER_SCRIPT = `// written by agentchannel (ach): installs a release once the runner has exited (Windows keeps a running program's files)
|
|
314
|
+
'use strict';
|
|
315
|
+
const { spawn, spawnSync } = require('child_process');
|
|
316
|
+
const fs = require('fs');
|
|
317
|
+
const plan = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
|
|
318
|
+
const log = (s) => { try { fs.appendFileSync(plan.log, new Date().toISOString() + ' [ach update] ' + s + '\\n'); } catch (e) {} };
|
|
319
|
+
const alive = (pid) => { try { process.kill(pid, 0); return true; } catch (e) { return e.code === 'EPERM'; } };
|
|
320
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
321
|
+
(async () => {
|
|
322
|
+
for (let i = 0; i < 240 && plan.pids.some(alive); i++) await sleep(500);
|
|
323
|
+
await sleep(plan.settleMs);
|
|
324
|
+
let ok = false;
|
|
325
|
+
for (let attempt = 1; attempt <= 3 && !ok; attempt++) {
|
|
326
|
+
const r = spawnSync(plan.npm.file, plan.npm.pre.concat(plan.args), { shell: plan.npm.shell, windowsHide: true, encoding: 'utf8', timeout: 300000 });
|
|
327
|
+
let got = '';
|
|
328
|
+
try { got = JSON.parse(fs.readFileSync(plan.pkgJson, 'utf8')).version; } catch (e) {}
|
|
329
|
+
ok = r.status === 0 && got === plan.target;
|
|
330
|
+
if (ok) log('installed ' + plan.target);
|
|
331
|
+
else { log('npm install -g failed (try ' + attempt + ', exit ' + r.status + ', installed ' + (got || 'nothing') + '): ' + String(r.stderr || r.stdout || r.error || '').trim().split('\\n').slice(-3).join(' | ')); await sleep(5000); }
|
|
332
|
+
}
|
|
333
|
+
try { fs.unlinkSync(plan.lock); } catch (e) {}
|
|
334
|
+
await sleep(plan.settleMs * 10);
|
|
335
|
+
let held = 0;
|
|
336
|
+
try { held = Number(String(fs.readFileSync(plan.runnerLock, 'utf8')).split('@')[0]); } catch (e) {}
|
|
337
|
+
if (held && alive(held)) { log('the runner is running again (pid ' + held + ')'); return; }
|
|
338
|
+
const out = fs.openSync(plan.log, 'a');
|
|
339
|
+
const c = spawn(plan.relaunch.file, plan.relaunch.args, { cwd: plan.relaunch.cwd, detached: true, stdio: ['ignore', out, out], windowsHide: true });
|
|
340
|
+
c.unref();
|
|
341
|
+
log('started the runner again (pid ' + c.pid + ')');
|
|
342
|
+
})();
|
|
343
|
+
`;
|
|
344
|
+
export const windowsUpdateFiles = (home) => ({
|
|
345
|
+
script: join(home, 'ach-update.cjs'),
|
|
346
|
+
plan: join(home, 'update-plan.json'),
|
|
347
|
+
lock: join(home, 'update.lock'),
|
|
348
|
+
log: join(home, 'logs', 'update.log'),
|
|
349
|
+
runnerLock: join(home, 'runner.lock'),
|
|
350
|
+
});
|
|
351
|
+
const pidAlive = (pid) => {
|
|
352
|
+
try {
|
|
353
|
+
process.kill(pid, 0);
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
catch (e) {
|
|
357
|
+
return e?.code === 'EPERM';
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
/**
|
|
361
|
+
* Start the Windows install helper (WINDOWS_UPDATER_SCRIPT), detached, for `target` into the global package at `dir`. It waits for
|
|
362
|
+
* this process (and its supervisor, ACH_SUPERVISED) to exit. The update lock holds its pid from the start, so a runner a Startup
|
|
363
|
+
* script restarts in between waits for it (waitForWindowsUpdate) instead of taking the files again. False when it did not start.
|
|
364
|
+
*/
|
|
365
|
+
export function startWindowsUpdate(o) {
|
|
366
|
+
const f = windowsUpdateFiles(o.home);
|
|
367
|
+
try {
|
|
368
|
+
mkdirSync(dirname(f.log), { recursive: true, mode: 0o700 });
|
|
369
|
+
writeFileSync(f.script, WINDOWS_UPDATER_SCRIPT, { mode: 0o600 });
|
|
370
|
+
writeFileSync(f.plan, JSON.stringify({
|
|
371
|
+
target: o.target,
|
|
372
|
+
pids: o.pids ?? [process.pid, ...(process.env.ACH_SUPERVISED === '1' ? [process.ppid] : [])],
|
|
373
|
+
npm: o.npm ?? npmCommand(),
|
|
374
|
+
args: ['install', '-g', '--ignore-scripts', '--no-audit', '--no-fund', `${PKG_NAME}@${o.target}`],
|
|
375
|
+
pkgJson: join(o.dir, 'package.json'),
|
|
376
|
+
lock: f.lock,
|
|
377
|
+
log: f.log,
|
|
378
|
+
runnerLock: f.runnerLock,
|
|
379
|
+
settleMs: o.settleMs ?? 2000,
|
|
380
|
+
relaunch: o.relaunch ?? { file: process.execPath, args: [...process.execArgv, ...process.argv.slice(1)], cwd: process.cwd() },
|
|
381
|
+
}), { mode: 0o600 });
|
|
382
|
+
const spawnHelper = o.spawnHelper ??
|
|
383
|
+
((script, plan) => {
|
|
384
|
+
// the helper inherits this environment, without the supervisor mark: the runner it starts is a first one
|
|
385
|
+
const { ACH_SUPERVISED: _, ...env } = process.env;
|
|
386
|
+
const c = spawn(process.execPath, [script, plan], { detached: true, stdio: 'ignore', windowsHide: true, env });
|
|
387
|
+
c.unref();
|
|
388
|
+
return c.pid;
|
|
389
|
+
});
|
|
390
|
+
const pid = spawnHelper(f.script, f.plan);
|
|
391
|
+
if (!pid)
|
|
392
|
+
return false;
|
|
393
|
+
writeFileSync(f.lock, String(pid), { mode: 0o600 });
|
|
394
|
+
o.log?.(`installer started (pid ${pid}); it logs to ${f.log}`);
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
catch (e) {
|
|
398
|
+
o.log?.(`installer not started: ${e?.message ?? e}`);
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Called first thing by `ach run` on Windows, before anything loads a native module: while an install helper is working, wait
|
|
404
|
+
* for it (at most 15 minutes). True when it waited: this process holds the old release's code, so the caller starts the new one.
|
|
405
|
+
*/
|
|
406
|
+
export async function waitForWindowsUpdate(home, o = {}) {
|
|
407
|
+
const { lock } = windowsUpdateFiles(home);
|
|
408
|
+
let pid = 0;
|
|
409
|
+
try {
|
|
410
|
+
pid = Number(readFileSync(lock, 'utf8').trim());
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
if (!pid || !pidAlive(pid)) {
|
|
416
|
+
try {
|
|
417
|
+
unlinkSync(lock);
|
|
418
|
+
}
|
|
419
|
+
catch {
|
|
420
|
+
/* gone */
|
|
421
|
+
}
|
|
422
|
+
return false;
|
|
423
|
+
}
|
|
424
|
+
o.log?.(`[ach update] a release is being installed (pid ${pid}); waiting for it`);
|
|
425
|
+
const sleep = o.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
426
|
+
for (let waited = 0; waited < (o.maxMs ?? 15 * 60_000) && existsSync(lock) && pidAlive(pid); waited += 2000)
|
|
427
|
+
await sleep(2000);
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
284
430
|
const defaultSpawnSelf = (file, args, env) => {
|
|
285
431
|
const child = spawn(file, args, { stdio: 'inherit', env, windowsHide: true });
|
|
286
432
|
return {
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.36.
|
|
3
|
+
"version": "3.36.5",
|
|
4
4
|
"description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentchannel",
|