@koalaauto/agentchannel 3.24.0 → 3.26.0
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/adapters/claude.js +7 -1
- package/dist/src/adapters/paths.d.ts +2 -0
- package/dist/src/adapters/paths.js +3 -0
- package/dist/src/adapters/types.d.ts +4 -0
- package/dist/src/args.d.ts +7 -1
- package/dist/src/args.js +44 -15
- package/dist/src/cli.d.ts +6 -0
- package/dist/src/cli.js +114 -72
- package/dist/src/client.d.ts +3 -0
- package/dist/src/client.js +24 -5
- package/dist/src/envcheck.d.ts +7 -0
- package/dist/src/envcheck.js +11 -0
- package/dist/src/invite.js +1 -1
- package/dist/src/mcp.d.ts +7 -0
- package/dist/src/mcp.js +45 -7
- package/dist/src/redact.js +3 -0
- package/dist/src/runner/lock.d.ts +4 -0
- package/dist/src/runner/lock.js +69 -0
- package/dist/src/runner/runner.d.ts +19 -0
- package/dist/src/runner/runner.js +100 -11
- package/dist/src/runner/state.d.ts +2 -0
- package/dist/src/runner/state.js +4 -2
- package/dist/src/runner/workspace.js +8 -2
- package/dist/src/selfupdate.d.ts +23 -1
- package/dist/src/selfupdate.js +71 -5
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -22,6 +22,10 @@ export const WORK_ACH_TOOLS = [
|
|
|
22
22
|
'Bash(ach channel:*)',
|
|
23
23
|
'Bash(ach thread:*)',
|
|
24
24
|
'Bash(ach reply:*)',
|
|
25
|
+
// the work prompt tells the agent to check and add to the team Memory (the hub decides who may write what)
|
|
26
|
+
'Bash(ach recall:*)',
|
|
27
|
+
'Bash(ach remember:*)',
|
|
28
|
+
'Bash(ach memory:*)',
|
|
25
29
|
];
|
|
26
30
|
export const ANSWER_ACH_TOOLS = ['Bash(ach answer:*)', 'Bash(ach decide-request:*)', 'Bash(ach ask-human:*)', 'Bash(ach task:*)'];
|
|
27
31
|
/** §16 mention runs: read the thread and channel, reply in the thread (with evidence, or --escalate). */
|
|
@@ -108,6 +112,7 @@ export function claudePermOptions(perm, o) {
|
|
|
108
112
|
readRoots: o.readRoots ?? [],
|
|
109
113
|
writeRoots: perm === 'workdir' ? [o.cwd] : [],
|
|
110
114
|
deny: denyRead,
|
|
115
|
+
secretFiles: o.mode === 'mention' || o.mode === 'answer',
|
|
111
116
|
};
|
|
112
117
|
const hubHost = hostOf(o.hub);
|
|
113
118
|
const sandbox = {
|
|
@@ -209,6 +214,7 @@ export class ClaudeAdapter {
|
|
|
209
214
|
abortController,
|
|
210
215
|
...(opts.resume ? { resume: opts.resume } : {}),
|
|
211
216
|
...(this.o.model ? { model: this.o.model } : {}),
|
|
217
|
+
...(opts.maxBudgetUsd && opts.maxBudgetUsd > 0 ? { maxBudgetUsd: opts.maxBudgetUsd } : {}),
|
|
212
218
|
...(withThinking ? thinkingFor(this.o.model, opts.env) : {}),
|
|
213
219
|
...claudePermOptions(opts.perm, {
|
|
214
220
|
cwd: opts.cwd,
|
|
@@ -289,6 +295,6 @@ export class ClaudeAdapter {
|
|
|
289
295
|
}
|
|
290
296
|
if (!finalText)
|
|
291
297
|
finalText = lastText.join('\n');
|
|
292
|
-
return { finalText, sessionId, costUsd, ok, error };
|
|
298
|
+
return { finalText, sessionId, costUsd, costCumulative: true, ok, error };
|
|
293
299
|
}
|
|
294
300
|
}
|
|
@@ -30,6 +30,8 @@ export interface PathPolicy {
|
|
|
30
30
|
writeRoots: string[];
|
|
31
31
|
/** Never readable or writable, even inside an allowed root. */
|
|
32
32
|
deny: string[];
|
|
33
|
+
/** Refuse files that hold secrets by convention (.env, keys, .npmrc): set for the short read-only runs a mention or a question starts in the real working copy. */
|
|
34
|
+
secretFiles?: boolean;
|
|
33
35
|
}
|
|
34
36
|
/** Undefined = allowed, else the reason for denying a read of p. */
|
|
35
37
|
export declare function readDenied(pol: PathPolicy, p: string): string | undefined;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isSecretFile } from '../redact.js';
|
|
1
2
|
import { existsSync, lstatSync, readlinkSync, realpathSync } from 'node:fs';
|
|
2
3
|
import { homedir } from 'node:os';
|
|
3
4
|
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
@@ -86,6 +87,8 @@ export function readDenied(pol, p) {
|
|
|
86
87
|
const abs = resolve(pol.cwd, p);
|
|
87
88
|
if (pol.deny.some((d) => isInside(d, abs)))
|
|
88
89
|
return `${p} is a protected AgentChannel file`;
|
|
90
|
+
if (pol.secretFiles && isSecretFile(abs))
|
|
91
|
+
return `${p} holds secrets by convention: a read-only reply does not read it`;
|
|
89
92
|
if (!isInside(pol.home, abs))
|
|
90
93
|
return undefined;
|
|
91
94
|
if ([pol.cwd, ...pol.readRoots].some((r) => isInside(r, abs)))
|
|
@@ -38,6 +38,8 @@ export interface AdapterRunOptions {
|
|
|
38
38
|
* The hub host is always added. Undefined = hub host + api.anthropic.com only.
|
|
39
39
|
*/
|
|
40
40
|
netAllow?: string[];
|
|
41
|
+
/** The most this one run may spend, in USD (the agent's budget minus what it has spent); the run stops there. Claude only. */
|
|
42
|
+
maxBudgetUsd?: number;
|
|
41
43
|
/** JSON schema the final message must follow (codex answer runs). */
|
|
42
44
|
outputSchema?: unknown;
|
|
43
45
|
}
|
|
@@ -45,6 +47,8 @@ export interface AdapterResult {
|
|
|
45
47
|
finalText: string;
|
|
46
48
|
sessionId?: string;
|
|
47
49
|
costUsd?: number;
|
|
50
|
+
/** costUsd is a running total for the whole session (a resumed Claude session reports what its earlier runs cost too), not this run's own. */
|
|
51
|
+
costCumulative?: boolean;
|
|
48
52
|
/** True when cost is estimated from tokens (codex). */
|
|
49
53
|
estimated?: boolean;
|
|
50
54
|
ok: boolean;
|
package/dist/src/args.d.ts
CHANGED
|
@@ -10,5 +10,11 @@ export interface Parsed {
|
|
|
10
10
|
export declare class UsageError extends Error {
|
|
11
11
|
}
|
|
12
12
|
export declare function parseCli(argv: string[]): Parsed;
|
|
13
|
-
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 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>] [--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 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). Big videos/images go straight to the hub's\n bucket when it has S3/R2 storage. --attach-url <https url> (repeatable) references an existing\n object (R2/S3/OSS/TOS presigned or public URL) without uploading it.\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 [--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 storage (attachment and database size; per channel with direct uploads and retention)\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 ach admin retention <#name> [<days>] (delete attachments of finished tasks older than <days>; 0 = keep everything)\n ach admin link-hosts [--set h1,h2] [--only yes|no] (hosts whose linked images/videos the panel previews; --only rejects other links)\n ach keep <taskId> [--file <name>] [--off] (flag a task's attachments as deliverables: retention never deletes them)\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";
|
|
13
|
+
/**
|
|
14
|
+
* Help for one command (`ach help send`, `ach send --help`, `ach admin users --help`): the entries of the full help that mention it,
|
|
15
|
+
* and the options it takes. An entry starts at a line whose text (after a section label like "Tasks:") begins with "ach ", and
|
|
16
|
+
* runs over the more indented lines under it.
|
|
17
|
+
*/
|
|
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 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";
|
|
14
20
|
export {};
|
package/dist/src/args.js
CHANGED
|
@@ -51,7 +51,7 @@ export const COMMANDS = {
|
|
|
51
51
|
cancel: { reason: s, ...json },
|
|
52
52
|
run: {
|
|
53
53
|
dir: s, runtime: s, interval: s, max: s, perm: s, model: s, gc: b, days: s, 'pass-env': sm,
|
|
54
|
-
repo: sm, 'claim-delay': s, 'interactive-first': b, 'install-service': b, notify: b, 'no-notify': b, ...json,
|
|
54
|
+
repo: sm, 'claim-delay': s, 'interactive-first': b, 'install-service': b, notify: b, 'no-notify': b, 'no-trace': b, ...json,
|
|
55
55
|
},
|
|
56
56
|
mcp: { ...json },
|
|
57
57
|
open: { print: b, ...json },
|
|
@@ -65,17 +65,13 @@ export const COMMANDS = {
|
|
|
65
65
|
'admin import': { link: s, hub: s, yes: b, org: s, since: s, plan: s, out: s, 'dry-run': b, 'closed-days': s, 'post-closed-days': s, all: b, 'seed-months': s, 'seed-all': b, exclude: s, 'no-exclude': b, ...json },
|
|
66
66
|
'admin sync': { org: s, every: s, runs: s, since: s, 'closed-days': s, 'post-closed-days': s, all: b, 'seed-months': s, 'seed-all': b, exclude: s, 'no-exclude': b, ...json },
|
|
67
67
|
'admin profile': { 'notify-webhook': s, name: s, ...json },
|
|
68
|
-
'admin rotate-key': { 'cf-token': b, ...json },
|
|
68
|
+
'admin rotate-key': { 'cf-token': b, yes: b, ...json },
|
|
69
69
|
'admin set': { active: s, perm: s, budget: s, description: s, 'accept-from': s, 'net-allow': s, ...json },
|
|
70
70
|
'admin decide': { task: s, message: s, attach: sm, 'attach-url': sm, ...json },
|
|
71
71
|
'admin channels': { name: s, folder: s, title: s, description: s, add: s, remove: s, cascade: b, ...json },
|
|
72
72
|
'admin embeds': { set: s, ...json },
|
|
73
|
-
'admin storage': { ...json },
|
|
74
|
-
'admin retention': { ...json },
|
|
75
73
|
'admin memory-upkeep': { ...json },
|
|
76
74
|
'admin memory-maintainers': { ...json },
|
|
77
|
-
'admin link-hosts': { set: s, only: s, ...json },
|
|
78
|
-
keep: { file: s, off: b, ...json },
|
|
79
75
|
'admin note': { task: s, attach: sm, 'attach-url': sm, ...json },
|
|
80
76
|
remember: { source: s, channel: s, topic: s, 'to-team': b, ...json },
|
|
81
77
|
'decide-draft': { source: s, by: s, channel: s, topic: s, task: s, scope: s, ...json },
|
|
@@ -100,6 +96,9 @@ export function parseCli(argv) {
|
|
|
100
96
|
if (first === '--version' || first === '-v')
|
|
101
97
|
return { cmd: 'version', values: {}, positionals: [] };
|
|
102
98
|
let cmd = first;
|
|
99
|
+
// `ach admin --help`, `ach memory -h`, `ach schedule --help`: the group's help, before a subcommand is expected
|
|
100
|
+
if (['admin', 'memory', 'wiki', 'schedule'].includes(first) && (rest[0] === '--help' || rest[0] === '-h'))
|
|
101
|
+
return { cmd: 'help', values: {}, positionals: [first === 'wiki' ? 'memory' : first] };
|
|
103
102
|
if (first === 'admin') {
|
|
104
103
|
const sub = rest[0];
|
|
105
104
|
if (!sub)
|
|
@@ -128,12 +127,47 @@ export function parseCli(argv) {
|
|
|
128
127
|
throw new UsageError(`Unknown command "${cmd}". Run \`ach help\`.`);
|
|
129
128
|
try {
|
|
130
129
|
const { values, positionals } = parseArgs({ args: rest, options, allowPositionals: true, strict: true });
|
|
130
|
+
// `ach <command> --help` shows that command's help and does nothing else (it used to be parsed and then ignored: `ach run --help` started a runner)
|
|
131
|
+
if (values.help)
|
|
132
|
+
return { cmd: 'help', values: {}, positionals: cmd.split(' ') };
|
|
131
133
|
return { cmd, values: values, positionals };
|
|
132
134
|
}
|
|
133
135
|
catch (e) {
|
|
134
136
|
throw new UsageError(`${cmd}: ${e?.message ?? e}`);
|
|
135
137
|
}
|
|
136
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Help for one command (`ach help send`, `ach send --help`, `ach admin users --help`): the entries of the full help that mention it,
|
|
141
|
+
* and the options it takes. An entry starts at a line whose text (after a section label like "Tasks:") begins with "ach ", and
|
|
142
|
+
* runs over the more indented lines under it.
|
|
143
|
+
*/
|
|
144
|
+
export function helpFor(words) {
|
|
145
|
+
const cmd = words.join(' ');
|
|
146
|
+
const known = Object.keys(COMMANDS).filter((k) => k !== 'help' && k !== 'version');
|
|
147
|
+
const key = known.includes(cmd) ? cmd : known.includes(words.slice(0, 2).join(' ')) ? words.slice(0, 2).join(' ') : words[0] === 'schedules' ? 'schedule list' : words[0] ?? '';
|
|
148
|
+
const lines = HELP.split('\n');
|
|
149
|
+
const entries = [];
|
|
150
|
+
for (const line of lines) {
|
|
151
|
+
const starts = /^(?:[A-Za-z][A-Za-z ]*:\s+)?ach /.test(line.replace(/^ {1,12}/, '')) && !/^ {13,}/.test(line);
|
|
152
|
+
if (starts || /^[A-Za-z][A-Za-z ]*:\s+npx /.test(line))
|
|
153
|
+
entries.push([line]);
|
|
154
|
+
else if (entries.length && /^\s+\S/.test(line))
|
|
155
|
+
entries[entries.length - 1].push(line);
|
|
156
|
+
}
|
|
157
|
+
const base = key.split(' ')[0];
|
|
158
|
+
const sub = key.split(' ').slice(1).join(' ');
|
|
159
|
+
const word = (w) => new RegExp(`(?:ach|npx -y @koalaauto/agentchannel@3|\\|)\\s+${w.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')}(?![\\w-])`);
|
|
160
|
+
// match on an entry's first line only (its continuation lines mention other commands in passing)
|
|
161
|
+
let hits = entries.filter((e) => (sub ? word(`${base} ${sub}`).test(e[0]) : word(base).test(e[0])));
|
|
162
|
+
if (!hits.length && sub)
|
|
163
|
+
hits = entries.filter((e) => word(base).test(e[0]));
|
|
164
|
+
const opts = COMMANDS[key];
|
|
165
|
+
const flags = opts ? Object.keys(opts).filter((o) => o !== 'help' && o !== 'json').map((o) => `--${o}`) : [];
|
|
166
|
+
if (!hits.length && !opts)
|
|
167
|
+
return `ach: no command "${cmd}". Run \`ach help\` for all of them.`;
|
|
168
|
+
const body = hits.length ? hits.map((e) => e.join('\n')).join('\n') : `ach ${key}`;
|
|
169
|
+
return `${body}\n\n${flags.length ? `Options of "ach ${key}": ${flags.join(' ')} --json --help` : `"ach ${key}" takes only --json and --help.`}\nAll commands: ach help`;
|
|
170
|
+
}
|
|
137
171
|
export const HELP = `ach - AgentChannel CLI
|
|
138
172
|
|
|
139
173
|
Setup: npx -y @koalaauto/agentchannel@3 join <ach2.invite> [--name <n>] [--service] [--yes] [--dry-run] (run it in the
|
|
@@ -147,7 +181,7 @@ Setup: npx -y @koalaauto/agentchannel@3 join <ach2.invite> [--name <n>] [--
|
|
|
147
181
|
ach doctor (hub, front door, key; then this machine: which \`ach\` runs, claude/codex login and MCP entry)
|
|
148
182
|
ach notify --test (shows a test desktop notification: checks the background helper can reach you)
|
|
149
183
|
Tasks: ach send --to <agent> --title <t> --priority P0..P3 --purpose <p> --key-question <q> --money <m> --handoff-file <f>
|
|
150
|
-
[--depends <id>] [--base <branch|commit>] [--repo <name>] [--read-repo <name>[@base] ...] [--attach <file> ...]
|
|
184
|
+
[--depends <id> ...] (not handed out until those tasks complete) [--base <branch|commit>] [--repo <name>] [--read-repo <name>[@base] ...] [--attach <file> ...]
|
|
151
185
|
[--review] (the task waits for acceptance when its worker is done: ach accept or ach request-changes)
|
|
152
186
|
ach accept <task> [<note>] | ach request-changes <task> "<what to change>" (the sender's side judges work sent with --review)
|
|
153
187
|
ach handoff <taskId> --note <change note> [--file <f>] [--priority P0..P3] [--purpose p] [--money m] [--key-question q] [--attach <file> ...]
|
|
@@ -162,7 +196,7 @@ Recurring: ach schedule add --to <agent> --title <t> --money <m> --handoff-file
|
|
|
162
196
|
ach schedule add ... --on task_completed|task_failed|figure|post --match '<json>' (an event rule instead of a time:
|
|
163
197
|
task: {"to":"puller","title":"pull"} (its own tasks only); figure: {"topic":"ads","metric":"Meta daily spend","op":">","value":5000};
|
|
164
198
|
post: {"channel":"ci","contains":"failed"}. {ref} {title} {link} {metric} {value} {unit} {text} fill the title/handoff)
|
|
165
|
-
ach schedules | ach schedule pause <id> | ach schedule rm <id> (resume: your owner, in the panel or with a person's session)
|
|
199
|
+
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)
|
|
166
200
|
Messages: ach ask [--task <id>] [--to <agent>] "<question>"
|
|
167
201
|
ach answer [--task <id>] --reply-to <msgId> --evidence "<files/commands>" "<answer>"
|
|
168
202
|
ach decide [--task <id>] <requestId> "<reply>" (interactive sessions only, with your agent key: your owner's reply, marked "via <agent>")
|
|
@@ -176,9 +210,7 @@ Authorization: ach grant (--agent <name> | --person <who>) (--task <TASK-n> | --
|
|
|
176
210
|
ach progress [--task <id>] "<text>" | ach note [--task <id>] "<text>"
|
|
177
211
|
Each takes --attach <file> (repeatable; png, jpg, webp, gif, mp4, webm, mov; text/code up to 2 MB:
|
|
178
212
|
txt md json ts js py go sh diff patch log csv yaml sql; .html reports; inside a spawned
|
|
179
|
-
agent the file must be inside the working directory).
|
|
180
|
-
bucket when it has S3/R2 storage. --attach-url <https url> (repeatable) references an existing
|
|
181
|
-
object (R2/S3/OSS/TOS presigned or public URL) without uploading it.
|
|
213
|
+
agent the file must be inside the working directory).
|
|
182
214
|
Channels: ach channels [--all] | ach channel [<#name>] [--since <iso>] [--before <iso>] [--limit n]
|
|
183
215
|
ach post <#name|name|title> "<text>" [--attach <file> ...] [--announce] (@agent mentions wake that agent for a read-only reply;
|
|
184
216
|
an @name that matches nobody is warned about, with the closest name;
|
|
@@ -208,6 +240,7 @@ Finishing: ach complete [--task <id>] [--run-id <r>] [--result-file <f> | "<tex
|
|
|
208
240
|
Runner: ach run --dir <path> [--repo name=path ...] [--runtime claude|codex|kiro] [--interval 3] [--max 2]
|
|
209
241
|
[--perm read|workdir|full] [--model m] [--pass-env NAME ...]
|
|
210
242
|
[--claim-delay <sec> | --interactive-first] (default 0; --interactive-first = 60 s for you to claim first)
|
|
243
|
+
[--no-trace] (keep execution traces on this machine; ACH_NO_TRACE=1 too)
|
|
211
244
|
[--notify | --no-notify] (desktop notifications for your owner's important / needs-you items;
|
|
212
245
|
default on for --install-service where there is a desktop, off otherwise)
|
|
213
246
|
ach run --install-service [same flags] (installs and starts a launchd/systemd user unit; runs at login)
|
|
@@ -252,12 +285,8 @@ Onboarding: ach admin import github --org <org> [--since 60d] --dry-run [--out p
|
|
|
252
285
|
ach admin channels members <#name> [--add a,b] [--remove c] (people by email or GitHub login)
|
|
253
286
|
ach admin embeds [--set host1,host2] (embed allowlist; public suffixes are refused)
|
|
254
287
|
ach admin wiki-lang [en|zh] (= ach memory lang: the language Memory pages are written in; default ACH_DEFAULT_LANG)
|
|
255
|
-
ach admin storage (attachment and database size; per channel with direct uploads and retention)
|
|
256
288
|
ach admin memory-maintainers [<agent> ...] (who keeps Memory current; no name: show it. Default: the admin agent with no setup problem seen most recently)
|
|
257
289
|
ach admin memory-upkeep [<#channel>] (queue Memory upkeep now; also restarts one paused after repeated failures)
|
|
258
|
-
ach admin retention <#name> [<days>] (delete attachments of finished tasks older than <days>; 0 = keep everything)
|
|
259
|
-
ach admin link-hosts [--set h1,h2] [--only yes|no] (hosts whose linked images/videos the panel previews; --only rejects other links)
|
|
260
|
-
ach keep <taskId> [--file <name>] [--off] (flag a task's attachments as deliverables: retention never deletes them)
|
|
261
290
|
|
|
262
291
|
--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,
|
|
263
292
|
ACH_KEYSTORE=file (store the agent key in a 0600 file instead of the OS keychain).
|
package/dist/src/cli.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export interface Io {
|
|
|
7
7
|
cwd?: string;
|
|
8
8
|
out: (s: string) => void;
|
|
9
9
|
err: (s: string) => void;
|
|
10
|
+
/** stdout is a terminal (a person reading): reads print a summary instead of raw JSON. Agents and scripts get JSON as before. */
|
|
11
|
+
tty?: boolean;
|
|
10
12
|
fetch?: FetchLike;
|
|
11
13
|
/** `ach open`: opens a URL in the browser (tests inject a fake). */
|
|
12
14
|
openUrl?: (url: string) => Promise<void>;
|
|
@@ -42,3 +44,7 @@ export declare function writeAchShim(home: string): string | undefined;
|
|
|
42
44
|
/** B7: `ach run` exit code when the hub answers 401 (systemd: RestartPreventExitStatus=78). */
|
|
43
45
|
export declare const AUTH_EXIT_CODE = 78;
|
|
44
46
|
export declare const AUTH_EXIT_MESSAGE = "ach run: key rotated or agent deactivated \u2014 run ach join";
|
|
47
|
+
/** A task as a person reads it: the header, the brief, the last few things said, the files. */
|
|
48
|
+
export declare function taskSummary(b: any, files?: any[]): string;
|
|
49
|
+
/** An inbox as a person reads it: each kind of thing with its count and one line per item. */
|
|
50
|
+
export declare function inboxSummary(r: any): string;
|
package/dist/src/cli.js
CHANGED
|
@@ -4,8 +4,9 @@ import { randomBytes } from 'node:crypto';
|
|
|
4
4
|
import { chmodSync, existsSync, mkdirSync, readFileSync, realpathSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { acquireRunnerLock, RunnerLockedError } from './runner/lock.js';
|
|
8
|
+
import { helpFor, HELP, parseCli, UsageError } from './args.js';
|
|
9
|
+
import { channelRef, Client, clientFromConfig, HubError, isZh, NetworkError, parseLinkRepo } from './client.js';
|
|
9
10
|
import { channelTails, closest, decisionTo, explainToUser, matchChannel, mentionNames, unknownMentions } from './names.js';
|
|
10
11
|
import { refOf, untrustedBlock as wrapUntrusted } from './prompts.js';
|
|
11
12
|
import { achHome, agentHome, homeForDir, loadConfig, readFileConfig, resolveClaimDelay, saveAdminToken, saveAgentKey, saveCfSecret, writeFileConfig } from './config.js';
|
|
@@ -14,8 +15,15 @@ import { isPerm } from './perm.js';
|
|
|
14
15
|
import { AttachError, humanSize, isLinkRef, resolveAttachments, taskFiles } from './attachments.js';
|
|
15
16
|
export { VERSION } from './version.js';
|
|
16
17
|
import { VERSION } from './version.js';
|
|
17
|
-
import { SelfUpdater, UPDATE_EXIT_CODE } from './selfupdate.js';
|
|
18
|
+
import { bootGuard, markHealthy, SelfUpdater, UPDATE_EXIT_CODE } from './selfupdate.js';
|
|
18
19
|
import { installProxy } from './netproxy.js';
|
|
20
|
+
/** 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. */
|
|
21
|
+
async function confirmKeyRotation(io, v, agentName) {
|
|
22
|
+
if (!io.ask || v.yes || v.json)
|
|
23
|
+
return true;
|
|
24
|
+
const a = (await io.ask(`This replaces the key of ${agentName}: its runner and its MCP entry stop working until it joins again with the new line. Continue? [y/N] `)).trim().toLowerCase();
|
|
25
|
+
return /^(y|yes)$/.test(a);
|
|
26
|
+
}
|
|
19
27
|
async function askTty(question) {
|
|
20
28
|
const { createInterface } = await import('node:readline/promises');
|
|
21
29
|
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
@@ -30,6 +38,7 @@ const defaultIo = () => ({
|
|
|
30
38
|
env: process.env,
|
|
31
39
|
out: (s) => process.stdout.write(s + '\n'),
|
|
32
40
|
err: (s) => process.stderr.write(s + '\n'),
|
|
41
|
+
tty: !!process.stdout.isTTY,
|
|
33
42
|
...(process.stdin.isTTY && process.stderr.isTTY ? { ask: askTty } : {}),
|
|
34
43
|
});
|
|
35
44
|
function str(v) {
|
|
@@ -248,6 +257,10 @@ export async function main(argv, io = defaultIo()) {
|
|
|
248
257
|
io.err(e.message);
|
|
249
258
|
return 2;
|
|
250
259
|
}
|
|
260
|
+
if (e instanceof NetworkError) {
|
|
261
|
+
io.err(`error: ${e.message}`);
|
|
262
|
+
return 3;
|
|
263
|
+
}
|
|
251
264
|
if (e instanceof HubError) {
|
|
252
265
|
io.err(`hub error ${e.status}: ${e.message}${hubHint(e, io.env)}`);
|
|
253
266
|
return 1;
|
|
@@ -270,10 +283,10 @@ async function dispatch(p, io) {
|
|
|
270
283
|
const files = () => {
|
|
271
284
|
try {
|
|
272
285
|
const urls = Array.isArray(v['attach-url']) ? v['attach-url'] : [];
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return resolveAttachments(
|
|
286
|
+
const list = [...(Array.isArray(v.attach) ? v.attach : []), ...urls];
|
|
287
|
+
if (list.some(isLinkRef))
|
|
288
|
+
throw new AttachError('this hub does not take linked attachments (--attach-url, or --attach with a URL): upload the file with --attach <file>, or put the link in the text');
|
|
289
|
+
return resolveAttachments(list, io);
|
|
277
290
|
}
|
|
278
291
|
catch (e) {
|
|
279
292
|
if (e instanceof AttachError)
|
|
@@ -292,7 +305,7 @@ async function dispatch(p, io) {
|
|
|
292
305
|
}
|
|
293
306
|
switch (p.cmd) {
|
|
294
307
|
case 'help':
|
|
295
|
-
io.out(HELP);
|
|
308
|
+
io.out(p.positionals.length ? helpFor(p.positionals) : HELP);
|
|
296
309
|
return 0;
|
|
297
310
|
case 'version':
|
|
298
311
|
io.out(VERSION);
|
|
@@ -626,6 +639,8 @@ async function dispatch(p, io) {
|
|
|
626
639
|
const list = taskFiles(b).map((f) => ({ ...f, download_url: f.ref === 'link' ? f.url : `${c.hub}${f.url}` }));
|
|
627
640
|
if (v.json)
|
|
628
641
|
out({ ...b, files: list });
|
|
642
|
+
else if (io.tty)
|
|
643
|
+
out(taskSummary(b, list));
|
|
629
644
|
else {
|
|
630
645
|
if (b.task.url)
|
|
631
646
|
out(`${b.task.ref ?? b.task.id}: ${b.task.url}`);
|
|
@@ -669,9 +684,11 @@ async function dispatch(p, io) {
|
|
|
669
684
|
out(`${f.path} (${f.original}, ${f.type}, ${humanSize(f.size)}, from ${f.from})`);
|
|
670
685
|
return 0;
|
|
671
686
|
}
|
|
672
|
-
case 'inbox':
|
|
673
|
-
|
|
687
|
+
case 'inbox': {
|
|
688
|
+
const r = v.owner ? await client().ownerInbox() : await client().inbox();
|
|
689
|
+
out(io.tty && !v.json ? inboxSummary(r) : r);
|
|
674
690
|
return 0;
|
|
691
|
+
}
|
|
675
692
|
case 'channels': {
|
|
676
693
|
const list = await client().channels(!!v.all);
|
|
677
694
|
if (v.json)
|
|
@@ -1218,6 +1235,10 @@ async function dispatch(p, io) {
|
|
|
1218
1235
|
const agent = (await a.agents()).find((x) => x.id === ref || x.name === ref);
|
|
1219
1236
|
if (agent) {
|
|
1220
1237
|
// P4: the key is only ever shown once, so an invite rotates it.
|
|
1238
|
+
if (!(await confirmKeyRotation(io, v, agent.name))) {
|
|
1239
|
+
io.err('admin invite: cancelled; the key was not changed.');
|
|
1240
|
+
return 1;
|
|
1241
|
+
}
|
|
1221
1242
|
const r = await a.adminRotateKey(agent.id, { cf_token: !!v['cf-token'] });
|
|
1222
1243
|
const blob = inviteFrom(r, a.hub, cfFlags(v));
|
|
1223
1244
|
const line = joinLine(blob);
|
|
@@ -1341,6 +1362,10 @@ async function dispatch(p, io) {
|
|
|
1341
1362
|
const agent = (await a.agents()).find((x) => x.id === ref || x.name === ref);
|
|
1342
1363
|
if (!agent)
|
|
1343
1364
|
throw new UsageError(`admin rotate-key: no agent named ${ref} (ach agents lists them)`);
|
|
1365
|
+
if (!(await confirmKeyRotation(io, v, agent.name))) {
|
|
1366
|
+
io.err('admin rotate-key: cancelled; the key was not changed.');
|
|
1367
|
+
return 1;
|
|
1368
|
+
}
|
|
1344
1369
|
out(await a.adminRotateKey(agent.id, { cf_token: !!v['cf-token'] }));
|
|
1345
1370
|
io.err('Save the key now; it is shown only once.');
|
|
1346
1371
|
return 0;
|
|
@@ -1449,24 +1474,6 @@ async function dispatch(p, io) {
|
|
|
1449
1474
|
out(v.json ? r : `Memory language: ${r.lang}`);
|
|
1450
1475
|
return 0;
|
|
1451
1476
|
}
|
|
1452
|
-
case 'admin storage': {
|
|
1453
|
-
const a = admin();
|
|
1454
|
-
const r = (await a.request('GET', '/api/ach/admin/storage'));
|
|
1455
|
-
// §20 v1.1: per channel, direct uploads, links and retention (older hubs: basic numbers only)
|
|
1456
|
-
const d = (await a.request('GET', '/api/ach/admin/storage/detail').catch(() => null));
|
|
1457
|
-
if (v.json) {
|
|
1458
|
-
out(d ? { ...r, detail: d } : r);
|
|
1459
|
-
return 0;
|
|
1460
|
-
}
|
|
1461
|
-
out(`attachments: ${r.attachments_files} files, ${humanSize(r.attachments_bytes)} (${r.storage}); database ${humanSize(r.db_bytes)}`);
|
|
1462
|
-
if (d) {
|
|
1463
|
-
out(`direct uploads: ${d.direct_uploads.files} files, ${humanSize(d.direct_uploads.bytes)} (${d.direct_upload ? `on, over ${d.direct_threshold_mb} MB, max ${d.direct_max_mb} MB` : 'off: no S3 storage'}); link references: ${d.link_refs}`);
|
|
1464
|
-
for (const c of d.channels || []) {
|
|
1465
|
-
out(` #${c.name}: ${c.files} files ${humanSize(c.bytes)}, ${c.direct_files} uploads ${humanSize(c.direct_bytes)}, retention ${c.retention_days ? `${c.retention_days} days` : 'keep all'}`);
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
return 0;
|
|
1469
|
-
}
|
|
1470
1477
|
case 'admin memory-maintainers': {
|
|
1471
1478
|
const a = admin();
|
|
1472
1479
|
const names = p.positionals.flatMap(splitList);
|
|
@@ -1481,49 +1488,6 @@ async function dispatch(p, io) {
|
|
|
1481
1488
|
out(v.json ? r : r.upkeep_task ? `queued ${r.upkeep_task.ref}${r.upkeep_task.url ? `: ${r.upkeep_task.url}` : ''}` : 'nothing waiting for upkeep');
|
|
1482
1489
|
return 0;
|
|
1483
1490
|
}
|
|
1484
|
-
case 'admin retention': {
|
|
1485
|
-
const name = p.positionals[0];
|
|
1486
|
-
if (!name)
|
|
1487
|
-
throw new UsageError('admin retention: <#channel> is required');
|
|
1488
|
-
const path = `/api/ach/channels/${encodeURIComponent(name.replace(/^#/, ''))}/retention`;
|
|
1489
|
-
const days = p.positionals[1];
|
|
1490
|
-
if (days !== undefined && !/^\d+$/.test(days))
|
|
1491
|
-
throw new UsageError('admin retention: <days> must be a whole number (0 = keep everything)');
|
|
1492
|
-
const r = (days === undefined ? await admin().request('GET', path) : await admin().request('PUT', path, { days: Number(days) }));
|
|
1493
|
-
out(v.json ? r : `#${r.channel}: ${r.retention_days ? `attachments of finished tasks are deleted after ${r.retention_days} days (except kept ones)` : 'keeps every attachment'}`);
|
|
1494
|
-
return 0;
|
|
1495
|
-
}
|
|
1496
|
-
case 'admin link-hosts': {
|
|
1497
|
-
const body = {};
|
|
1498
|
-
if (v.set !== undefined)
|
|
1499
|
-
body.link_hosts = String(v.set).split(',').map((x) => x.trim()).filter(Boolean);
|
|
1500
|
-
if (v.only !== undefined)
|
|
1501
|
-
body.link_hosts_only = /^(yes|true|1|on)$/i.test(String(v.only));
|
|
1502
|
-
const r = (Object.keys(body).length ? await admin().request('PUT', '/api/ach/admin/storage/settings', body) : await admin().request('GET', '/api/ach/admin/storage/settings'));
|
|
1503
|
-
out(v.json ? r : `link preview hosts: ${(r.link_hosts || []).join(', ') || '(none)'}${r.link_hosts_only ? ' (other links refused)' : ''}`);
|
|
1504
|
-
return 0;
|
|
1505
|
-
}
|
|
1506
|
-
case 'keep': {
|
|
1507
|
-
const id = p.positionals[0] ?? str(env.ACH_TASK_ID);
|
|
1508
|
-
if (!id)
|
|
1509
|
-
throw new UsageError('keep: <taskId> is required');
|
|
1510
|
-
const c = client();
|
|
1511
|
-
const body = { task: id, keep: !v.off };
|
|
1512
|
-
if (v.file) {
|
|
1513
|
-
const f = taskFiles(await c.getTask(id)).find((x) => x.name === v.file || x.original === v.file);
|
|
1514
|
-
if (!f)
|
|
1515
|
-
throw new UsageError(`keep: no attachment named ${v.file} on ${id}`);
|
|
1516
|
-
if (f.ref === 'upload')
|
|
1517
|
-
body.upload = f.upload;
|
|
1518
|
-
else if (f.ref === 'link')
|
|
1519
|
-
body.url = f.url;
|
|
1520
|
-
else
|
|
1521
|
-
body.name = f.name;
|
|
1522
|
-
}
|
|
1523
|
-
const r = (await c.request('POST', '/api/ach/attachments/keep', body));
|
|
1524
|
-
out(v.json ? r : v.off ? `unflagged ${r.unkept} attachment(s)` : `kept ${r.kept} attachment(s): retention will not delete them`);
|
|
1525
|
-
return 0;
|
|
1526
|
-
}
|
|
1527
1491
|
case 'admin decide': {
|
|
1528
1492
|
const r = await admin().decide(need(p, 'task'), need(p, 'message'), text(p, '<decision>'), files());
|
|
1529
1493
|
out(v.json ? r : 'decided');
|
|
@@ -1649,6 +1613,11 @@ async function runCommand(p, io) {
|
|
|
1649
1613
|
if (moved)
|
|
1650
1614
|
return UPDATE_EXIT_CODE;
|
|
1651
1615
|
const runtime = str(v.runtime) ?? (me.runtime === 'codex' || me.runtime === 'kiro' ? me.runtime : 'claude');
|
|
1616
|
+
// what the permission and the network list do not cover, said where the person starting the runner will read it
|
|
1617
|
+
if (perm === 'full')
|
|
1618
|
+
io.err('warning: --perm full runs commands with no sandbox (bypassPermissions): anything in a task that reaches the agent can run anything with your rights.');
|
|
1619
|
+
if (runtime === 'codex')
|
|
1620
|
+
io.err('warning: Codex work runs are not sandboxed like Claude runs: they can read the whole disk and reach any host, whatever --perm and net_allow say. On a shared machine run this under a dedicated OS user.');
|
|
1652
1621
|
const { makeAdapter } = await import('./adapters/index.js');
|
|
1653
1622
|
let adapter;
|
|
1654
1623
|
try {
|
|
@@ -1669,6 +1638,7 @@ async function runCommand(p, io) {
|
|
|
1669
1638
|
perm,
|
|
1670
1639
|
intervalMs: (str(v.interval) ? parseNum(str(v.interval), 'interval') : 3) * 1000,
|
|
1671
1640
|
claimDelayMs: claimDelay * 1000,
|
|
1641
|
+
noTrace: !!v['no-trace'] || env.ACH_NO_TRACE === '1',
|
|
1672
1642
|
cfId: cfg.cfId,
|
|
1673
1643
|
cfSecret: cfg.cfSecret,
|
|
1674
1644
|
secrets: [cfg.key ?? ''].filter(Boolean),
|
|
@@ -1716,7 +1686,32 @@ async function runCommand(p, io) {
|
|
|
1716
1686
|
};
|
|
1717
1687
|
process.once('SIGINT', shutdown);
|
|
1718
1688
|
process.once('SIGTERM', shutdown);
|
|
1719
|
-
|
|
1689
|
+
// one runner per home: a second one would overwrite the first's state
|
|
1690
|
+
let release = () => { };
|
|
1691
|
+
try {
|
|
1692
|
+
release = acquireRunnerLock(home);
|
|
1693
|
+
}
|
|
1694
|
+
catch (e) {
|
|
1695
|
+
if (e instanceof RunnerLockedError)
|
|
1696
|
+
throw new UsageError(`run: ${e.message}`);
|
|
1697
|
+
throw e;
|
|
1698
|
+
}
|
|
1699
|
+
process.once('exit', () => release()); // the shutdown path ends with process.exit, which skips the finally below
|
|
1700
|
+
// the brake (counted only for the runner that holds the lock, not for a second `ach run` the lock turns away): a release this
|
|
1701
|
+
// runner updated itself to that keeps failing to start goes back to the one before
|
|
1702
|
+
if ((await bootGuard(home, { log: io.err })) === 'rolledback') {
|
|
1703
|
+
release();
|
|
1704
|
+
return UPDATE_EXIT_CODE;
|
|
1705
|
+
}
|
|
1706
|
+
// five minutes of running is a working release (the guard stops counting its starts)
|
|
1707
|
+
setTimeout(() => markHealthy(home), 5 * 60_000).unref?.();
|
|
1708
|
+
let end;
|
|
1709
|
+
try {
|
|
1710
|
+
end = await runner.start();
|
|
1711
|
+
}
|
|
1712
|
+
finally {
|
|
1713
|
+
release();
|
|
1714
|
+
}
|
|
1720
1715
|
updater.stop();
|
|
1721
1716
|
desk?.stop();
|
|
1722
1717
|
// B7: the hub refused the agent key: rotated, agent disabled or owner deactivated.
|
|
@@ -1935,3 +1930,50 @@ if (isEntry()) {
|
|
|
1935
1930
|
installProxy();
|
|
1936
1931
|
main(process.argv.slice(2)).then((code) => process.exit(code));
|
|
1937
1932
|
}
|
|
1933
|
+
// ---- what a person reads in a terminal (agents and scripts keep the JSON) ---------------------------------------------------
|
|
1934
|
+
const line1 = (s, n = 110) => String(s ?? '').replace(/[#*_`>]/g, '').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
1935
|
+
/** A task as a person reads it: the header, the brief, the last few things said, the files. */
|
|
1936
|
+
export function taskSummary(b, files = []) {
|
|
1937
|
+
const t = b.task ?? {};
|
|
1938
|
+
const out = [];
|
|
1939
|
+
out.push(`${t.ref ?? t.id} ${t.title ?? ''}`);
|
|
1940
|
+
out.push(`${t.status}${t.waiting_on ? ` (waiting on ${t.waiting_on})` : ''} · ${t.priority ?? ''} · ${t.from_agent_name ?? '?'} -> ${t.to_agent_name ?? '?'}${t.channel_name ? ` · #${t.channel_name}` : ''}`);
|
|
1941
|
+
if (t.url)
|
|
1942
|
+
out.push(String(t.url));
|
|
1943
|
+
const brief = String(b.handoff?.body ?? '').split('\n');
|
|
1944
|
+
if (brief.join('').trim())
|
|
1945
|
+
out.push('', `brief (v${b.handoff?.version ?? t.handoff_version ?? 1}):`, ...brief.slice(0, 25).map((l) => ` ${l}`), ...(brief.length > 25 ? [` … ${brief.length - 25} more lines (ach task ${t.ref ?? t.id} --json)`] : []));
|
|
1946
|
+
const msgs = Array.isArray(b.messages) ? b.messages.filter((m) => m.author_type !== 'system' || m.kind === 'note') : [];
|
|
1947
|
+
if (msgs.length) {
|
|
1948
|
+
out.push('', `latest (${Math.min(8, msgs.length)} of ${msgs.length}):`);
|
|
1949
|
+
for (const m of msgs.slice(-8))
|
|
1950
|
+
out.push(` ${String(m.created ?? '').slice(5, 16)} ${m.author_name ?? m.author_type} [${m.kind}${m.resolved === false && /question|decision_request/.test(m.kind) ? ', open' : ''}] ${line1(m.choices?.question || m.body)}`);
|
|
1951
|
+
}
|
|
1952
|
+
if (t.result)
|
|
1953
|
+
out.push('', `${t.status === 'failed' ? 'reason' : 'result'}: ${line1(String(t.result).replace(/^failed:\s*/i, ''), 400)}`);
|
|
1954
|
+
if (files.length)
|
|
1955
|
+
out.push('', `attachments (${files.length}): ach download ${t.ref ?? t.id}`);
|
|
1956
|
+
return out.join('\n');
|
|
1957
|
+
}
|
|
1958
|
+
/** An inbox as a person reads it: each kind of thing with its count and one line per item. */
|
|
1959
|
+
export function inboxSummary(r) {
|
|
1960
|
+
if (!r || typeof r !== 'object')
|
|
1961
|
+
return String(r);
|
|
1962
|
+
const out = [];
|
|
1963
|
+
const item = (x) => {
|
|
1964
|
+
const task = x.task ?? x;
|
|
1965
|
+
const ref = task.ref ?? x.task_ref ?? '';
|
|
1966
|
+
const text = x.choices?.question ?? x.text ?? x.body ?? x.post?.body ?? task.title ?? '';
|
|
1967
|
+
return ` ${ref ? `${ref} ` : ''}${line1(text)}`;
|
|
1968
|
+
};
|
|
1969
|
+
for (const [k, v] of Object.entries(r)) {
|
|
1970
|
+
if (!Array.isArray(v) || !v.length)
|
|
1971
|
+
continue;
|
|
1972
|
+
out.push(`${k.replace(/_/g, ' ')} (${v.length})`);
|
|
1973
|
+
for (const x of v.slice(0, 10))
|
|
1974
|
+
out.push(item(x));
|
|
1975
|
+
if (v.length > 10)
|
|
1976
|
+
out.push(` … ${v.length - 10} more (--json for all)`);
|
|
1977
|
+
}
|
|
1978
|
+
return out.length ? out.join('\n') : 'nothing waiting';
|
|
1979
|
+
}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -281,6 +281,9 @@ export interface DecisionOption {
|
|
|
281
281
|
}
|
|
282
282
|
/** Who is calling, on every request: the hub records the release per agent and may refuse a protocol below its floor (426 client_too_old). */
|
|
283
283
|
export declare const CLIENT_HEADERS: Record<string, string>;
|
|
284
|
+
/** The hub could not be reached at all (no answer, a refused connection, a DNS failure, or no answer within the time limit). */
|
|
285
|
+
export declare class NetworkError extends Error {
|
|
286
|
+
}
|
|
284
287
|
export declare class HubError extends Error {
|
|
285
288
|
status: number;
|
|
286
289
|
code?: string | undefined;
|