@koalaauto/agentchannel 3.45.2 → 3.45.3
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/codex.js +4 -0
- package/dist/src/args.d.ts +1 -1
- package/dist/src/args.js +7 -60
- package/dist/src/cli-admin.d.ts +3 -0
- package/dist/src/cli-admin.js +307 -0
- package/dist/src/cli-memory.d.ts +3 -0
- package/dist/src/cli-memory.js +138 -0
- package/dist/src/cli-run.d.ts +28 -0
- package/dist/src/cli-run.js +429 -0
- package/dist/src/cli-shared.d.ts +73 -0
- package/dist/src/cli-shared.js +159 -0
- package/dist/src/cli.d.ts +9 -38
- package/dist/src/cli.js +21 -1181
- package/dist/src/client.d.ts +0 -22
- package/dist/src/client.js +0 -29
- package/dist/src/codexdaemon.d.ts +22 -0
- package/dist/src/codexdaemon.js +68 -0
- package/dist/src/invite_people.d.ts +31 -0
- package/dist/src/invite_people.js +238 -0
- package/dist/src/invite_person.d.ts +1 -1
- package/dist/src/invite_person.js +1 -1
- package/dist/src/mcp.d.ts +1 -1
- package/dist/src/mcp.js +7 -47
- package/dist/src/prompts.d.ts +2 -2
- package/dist/src/prompts.js +6 -17
- package/dist/src/runner/home.d.ts +45 -0
- package/dist/src/runner/home.js +150 -0
- package/dist/src/runner/runner.d.ts +3 -76
- package/dist/src/runner/runner.js +24 -326
- package/dist/src/runner/structured.d.ts +20 -0
- package/dist/src/runner/structured.js +64 -0
- package/dist/src/runner/traces.d.ts +29 -0
- package/dist/src/runner/traces.js +119 -0
- package/dist/src/sandboxcheck.d.ts +3 -0
- package/dist/src/sandboxcheck.js +16 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
- package/dist/src/import.d.ts +0 -244
- package/dist/src/import.js +0 -998
|
@@ -3,6 +3,7 @@ import { closeSync, existsSync, openSync, readdirSync, readSync, statSync } from
|
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { readable, systemPaths } from './scope.js';
|
|
5
5
|
import { KILL_GRACE_MS } from './procgroup.js';
|
|
6
|
+
import { ensureCodexDaemonDir } from '../codexdaemon.js';
|
|
6
7
|
import { CAPS_SERVER } from '../caps.js';
|
|
7
8
|
import { modelId } from './types.js';
|
|
8
9
|
export const DEFAULT_CODEX_PRICE = { input: 1.25, cached_input: 0.125, output: 10 };
|
|
@@ -329,6 +330,9 @@ export class CodexAdapter {
|
|
|
329
330
|
denyRead: [...(opts.denyReadPaths ?? []), ...(opts.env.CODEX_HOME ? [opts.env.CODEX_HOME] : [])],
|
|
330
331
|
realHome: opts.realHome,
|
|
331
332
|
});
|
|
333
|
+
// Codex will not start its sandbox over a wrong socket folder: put it right (a problem left shows in Codex's own error)
|
|
334
|
+
if (sandbox.length && process.platform !== 'win32')
|
|
335
|
+
ensureCodexDaemonDir();
|
|
332
336
|
const codex = new Codex(codexClientOptions(opts.env, [...sandbox, ...codexCapsOverrides(opts.caps)]));
|
|
333
337
|
const thread = opts.resume ? codex.resumeThread(opts.resume, to) : codex.startThread(to);
|
|
334
338
|
const price = this.o.price ?? priceFromEnv(opts.env);
|
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 owners [<repo>] (the team's projects and who answers for each: agents, people, an admin's note)\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] [--ask \"<one line to decide>\"] | --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>] [--cause <c> --needs <what>] \"<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.\nCapabilities: ach caps (lists the host capabilities in <agent home>/capabilities.json: commands your runner's agents may run\n outside their sandbox, with no approval, for anyone who sends them a task or mentions them)\n ach caps run <name> [arg=value ...] (runs one here, as a run would: to check a declaration)\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] (desktop notifications for what needs your owner, the same items as their browser\n notifications; off by default; macOS needs terminal-notifier)\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; Linux always uses the file).\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 owners [<repo>] (the team's projects and who answers for each: agents, people, an admin's note)\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>)\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 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] [--ask \"<one line to decide>\"] | --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 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>] [--cause <c> --needs <what>] \"<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.\nCapabilities: ach caps (lists the host capabilities in <agent home>/capabilities.json: commands your runner's agents may run\n outside their sandbox, with no approval, for anyone who sends them a task or mentions them)\n ach caps run <name> [arg=value ...] (runs one here, as a run would: to check a declaration)\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] (desktop notifications for what needs your owner, the same items as their browser\n notifications; off by default; macOS needs terminal-notifier)\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 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 wiki-lang [en|zh] (= ach memory lang: the language Memory pages are written in; default ACH_DEFAULT_LANG)\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; Linux always uses the file).\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
|
@@ -20,14 +20,6 @@ export const COMMANDS = {
|
|
|
20
20
|
'request-changes': { task: s, ...json },
|
|
21
21
|
handoff: { file: s, note: s, priority: s, purpose: s, money: s, 'key-question': s, attach: sm, 'attach-url': sm, ...json },
|
|
22
22
|
task: { ...json },
|
|
23
|
-
'schedule add': {
|
|
24
|
-
channel: s, to: s, title: s, priority: s, purpose: s, money: s, 'handoff-file': s, handoff: s,
|
|
25
|
-
every: s, at: s, weekday: s, day: s, tz: s, on: s, match: s, ...json,
|
|
26
|
-
},
|
|
27
|
-
'schedule list': { ...json },
|
|
28
|
-
'schedule pause': { ...json },
|
|
29
|
-
'schedule resume': { ...json },
|
|
30
|
-
'schedule rm': { ...json },
|
|
31
23
|
download: { out: s, ...json },
|
|
32
24
|
inbox: { owner: b, ...json },
|
|
33
25
|
channels: { all: b, ...json },
|
|
@@ -39,10 +31,7 @@ export const COMMANDS = {
|
|
|
39
31
|
ask: { task: s, to: s, attach: sm, 'attach-url': sm, ...json },
|
|
40
32
|
answer: { task: s, 'reply-to': s, evidence: s, attach: sm, 'attach-url': sm, ...json },
|
|
41
33
|
'ask-human': { task: s, to: s, attach: sm, 'attach-url': sm, option: sm, recommend: s, ...json },
|
|
42
|
-
decide: { task: s,
|
|
43
|
-
grant: { agent: s, person: s, task: s, channel: s, cap: s, until: s, note: s, requester: s, ...json },
|
|
44
|
-
grants: { ...json },
|
|
45
|
-
revoke: { ...json },
|
|
34
|
+
decide: { task: s, ...json },
|
|
46
35
|
'decide-request': { task: s, to: s, attach: sm, 'attach-url': sm, option: sm, recommend: s, ...json },
|
|
47
36
|
progress: { task: s, attach: sm, 'attach-url': sm, ...json },
|
|
48
37
|
note: { task: s, attach: sm, 'attach-url': sm, ...json },
|
|
@@ -64,23 +53,18 @@ export const COMMANDS = {
|
|
|
64
53
|
'admin user': { deactivate: b, reactivate: b, 'reassign-to': s, 'confirm-name': s, admin: s, name: s, email: s, ...json },
|
|
65
54
|
'admin create-agent': { name: s, owner: s, runtime: s, description: s, perm: s, budget: s, 'accept-from': s, 'net-allow': s, invite: b, 'cf-token': b, ...json },
|
|
66
55
|
'admin invite': { 'cf-id': s, 'cf-secret': s, 'cf-token': b, line: b, lang: s, feishu: b, people: s, map: sm, yes: b, ...json },
|
|
67
|
-
'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 },
|
|
68
|
-
'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 },
|
|
69
56
|
'admin profile': { 'notify-webhook': s, name: s, ...json },
|
|
70
57
|
'admin rotate-key': { 'cf-token': b, yes: b, ...json },
|
|
71
58
|
'admin set': { active: s, perm: s, budget: s, description: s, 'accept-from': s, 'net-allow': s, ...json },
|
|
72
59
|
'admin decide': { task: s, message: s, attach: sm, 'attach-url': sm, ...json },
|
|
73
60
|
'admin channels': { name: s, folder: s, title: s, description: s, add: s, remove: s, cascade: b, ...json },
|
|
74
|
-
'admin embeds': { set: s, ...json },
|
|
75
61
|
'admin memory-upkeep': { ...json },
|
|
76
|
-
'admin memory-maintainers': { ...json },
|
|
77
62
|
'admin note': { task: s, attach: sm, 'attach-url': sm, ...json },
|
|
78
63
|
remember: { source: s, channel: s, topic: s, 'to-team': b, ...json },
|
|
79
64
|
'decide-draft': { source: s, by: s, channel: s, topic: s, task: s, scope: s, ...json },
|
|
80
65
|
recall: { limit: s, ...json },
|
|
81
66
|
'memory pull': { channel: s, ...json },
|
|
82
67
|
'memory push': { note: s, ...json },
|
|
83
|
-
'memory seed': { 'from-imports': b, ...json },
|
|
84
68
|
'memory search': { limit: s, ...json },
|
|
85
69
|
'memory read': { ...json },
|
|
86
70
|
'memory lang': { ...json },
|
|
@@ -98,13 +82,13 @@ export function parseCli(argv) {
|
|
|
98
82
|
if (first === '--version' || first === '-v')
|
|
99
83
|
return { cmd: 'version', values: {}, positionals: [] };
|
|
100
84
|
let cmd = first;
|
|
101
|
-
// `ach admin --help`, `ach memory -h
|
|
102
|
-
if (['admin', 'memory', 'wiki'
|
|
85
|
+
// `ach admin --help`, `ach memory -h`: the group's help, before a subcommand is expected
|
|
86
|
+
if (['admin', 'memory', 'wiki'].includes(first) && (rest[0] === '--help' || rest[0] === '-h'))
|
|
103
87
|
return { cmd: 'help', values: {}, positionals: [first === 'wiki' ? 'memory' : first] };
|
|
104
88
|
if (first === 'admin') {
|
|
105
89
|
const sub = rest[0];
|
|
106
90
|
if (!sub)
|
|
107
|
-
throw new UsageError('admin needs a subcommand: login, users, create-user, login-link, user, create-agent, invite,
|
|
91
|
+
throw new UsageError('admin needs a subcommand: login, users, create-user, login-link, user, create-agent, invite, rotate-key, set, profile, decide, note, channels, storage, wiki-lang');
|
|
108
92
|
cmd = `admin ${sub}`;
|
|
109
93
|
rest = rest.slice(1);
|
|
110
94
|
}
|
|
@@ -112,18 +96,10 @@ export function parseCli(argv) {
|
|
|
112
96
|
if (first === 'memory' || first === 'wiki') {
|
|
113
97
|
const sub = rest[0];
|
|
114
98
|
if (!sub)
|
|
115
|
-
throw new UsageError('memory needs a subcommand: pull, push,
|
|
99
|
+
throw new UsageError('memory needs a subcommand: pull, push, search, read, lang, hook');
|
|
116
100
|
cmd = `memory ${sub}`;
|
|
117
101
|
rest = rest.slice(1);
|
|
118
102
|
}
|
|
119
|
-
if (first === 'schedule' || first === 'schedules') {
|
|
120
|
-
const sub = first === 'schedules' ? 'list' : rest[0];
|
|
121
|
-
if (!sub)
|
|
122
|
-
throw new UsageError('schedule needs a subcommand: add, list, pause, resume, rm');
|
|
123
|
-
cmd = `schedule ${sub}`;
|
|
124
|
-
if (first === 'schedule')
|
|
125
|
-
rest = rest.slice(1);
|
|
126
|
-
}
|
|
127
103
|
const options = COMMANDS[cmd];
|
|
128
104
|
if (!options)
|
|
129
105
|
throw new UsageError(`Unknown command "${cmd}". Run \`ach help\`.`);
|
|
@@ -146,7 +122,7 @@ export function parseCli(argv) {
|
|
|
146
122
|
export function helpFor(words) {
|
|
147
123
|
const cmd = words.join(' ');
|
|
148
124
|
const known = Object.keys(COMMANDS).filter((k) => k !== 'help' && k !== 'version');
|
|
149
|
-
const key = known.includes(cmd) ? cmd : known.includes(words.slice(0, 2).join(' ')) ? words.slice(0, 2).join(' ') : words[0]
|
|
125
|
+
const key = known.includes(cmd) ? cmd : known.includes(words.slice(0, 2).join(' ')) ? words.slice(0, 2).join(' ') : words[0] ?? '';
|
|
150
126
|
const lines = HELP.split('\n');
|
|
151
127
|
const entries = [];
|
|
152
128
|
for (const line of lines) {
|
|
@@ -193,21 +169,9 @@ Tasks: ach send --to <agent> --title <t> --priority P0..P3 --purpose <p> --
|
|
|
193
169
|
ach task <id|TASK-128> (lists attachments with download URLs) | ach inbox [--owner]
|
|
194
170
|
Every task argument also takes the TASK-<seq> number shown in the panel (TASK-128; T-128 still works).
|
|
195
171
|
ach download <taskId> [--out <dir>] (fetches every attachment; default ./ach-files-<taskId>)
|
|
196
|
-
Recurring: ach schedule add --to <agent> --title <t> --money <m> --handoff-file <f> --every day|weekday|week|month --at HH:MM
|
|
197
|
-
[--weekday 1..7] [--day 1..28] [--tz +08:00] [--purpose p] [--priority P0..P3] [--channel <name>]
|
|
198
|
-
(a proposal: it runs only after your owner replies "approve"; {date} in the title/handoff becomes the run's date;
|
|
199
|
-
a run is skipped while the previous one is still open)
|
|
200
|
-
ach schedule add ... --on task_completed|task_failed|figure|post --match '<json>' (an event rule instead of a time:
|
|
201
|
-
task: {"to":"puller","title":"pull"} (its own tasks only); figure: {"topic":"ads","metric":"Meta daily spend","op":">","value":5000};
|
|
202
|
-
post: {"channel":"ci","contains":"failed"}. {ref} {title} {link} {metric} {value} {unit} {text} fill the title/handoff)
|
|
203
|
-
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)
|
|
204
172
|
Messages: ach ask [--task <id>] [--to <agent>] "<question>"
|
|
205
173
|
ach answer [--task <id>] --reply-to <msgId> --evidence "<files/commands>" "<answer>"
|
|
206
174
|
ach decide [--task <id>] <requestId> "<reply>" (interactive sessions only, with your agent key: your owner's reply, marked "via <agent>")
|
|
207
|
-
ach decide [--task <id>] <requestId> --grant <id> --option <n> (a runner, within an authorization grant)
|
|
208
|
-
Authorization: ach grant (--agent <name> | --person <who>) (--task <TASK-n> | --channel <name>) --cap <usd> [--until YYYY-MM-DD]
|
|
209
|
-
[--note "<guidance>"] [--requester <agent|person>] (your agent key: you, present, grant it; never a run token)
|
|
210
|
-
ach grants | ach revoke <grantId>
|
|
211
175
|
ach ask-human [--task <id>] [--to both|<person name|email>] "<one question>" --option "A|detail|$450" --option "B|detail|$0" [--recommend 0]
|
|
212
176
|
(2–3 options, recommended first, money/impact on each; the person replies by picking one or typing;
|
|
213
177
|
\`decide-request\` is the older name)
|
|
@@ -232,7 +196,6 @@ Memory: ach recall "<query>" [--limit 5] (one line + link per hit: what th
|
|
|
232
196
|
ach memory search "<query>" [--limit n] | ach memory read <slug>
|
|
233
197
|
ach memory pull <dir> [--channel <name>] | ach memory push <dir> --note "<what changed>" (maintainers; Markdown + YAML
|
|
234
198
|
front matter; per-page note: in front matter; every problem line is listed with its reason)
|
|
235
|
-
ach memory seed --from-imports (maintainers: one upkeep task per channel over its imported GitHub issues/PRs)
|
|
236
199
|
ach memory hook [--channel <name> | --task <id>] (a bounded Memory summary for a Claude Code SessionStart hook;
|
|
237
200
|
default: --channel, $ACH_TASK_ID, a .ach-channel file in this or a parent directory, else your main channel)
|
|
238
201
|
ach memory lang [en|zh] (admins: the language pages are written in)
|
|
@@ -265,21 +228,7 @@ Admin: ach admin login --link <login link>
|
|
|
265
228
|
the join line npx -y @koalaauto/agentchannel@3 join <blob>. Language: --lang, else the hub's (Memory) language.
|
|
266
229
|
--cf-token: also put the hub's shared front-door (Cloudflare Access) token in the line; off by default)
|
|
267
230
|
ach admin invite <person> [--feishu] (prints a one-time login link; --feishu sends it on Feishu)
|
|
268
|
-
Onboarding: ach admin
|
|
269
|
-
ach admin import github --org <org> --link <one-time admin link> [--yes] (the line from the panel's Settings -> Import:
|
|
270
|
-
logs in with the 15-minute link for this import only, shows the dry run, then imports on a yes / --yes)
|
|
271
|
-
ach admin import github --org <org> [--plan plan.json] (channels, people, issues/PRs; idempotent, re-run updates)
|
|
272
|
-
Two ranges: posted to channels = open items + items closed/merged in the last N days
|
|
273
|
-
[--post-closed-days N (alias --closed-days), default 7 | --all]; used to seed Memory (links only) = closed
|
|
274
|
-
items of the last M months [--seed-months M, default 6 | --seed-all]. The hub keeps both for sync.
|
|
275
|
-
[--exclude security,secret,... | --no-exclude] (default exclusion:
|
|
276
|
-
security, 安全, 漏洞, secret, 密钥 in labels or title: never sent, not even an excerpt)
|
|
277
|
-
Plan: "visibility": "private" on a channel + people "channels" = members-only (the hub otherwise
|
|
278
|
-
widens access: everyone on the hub reads team channels, even repos they cannot see on GitHub).
|
|
279
|
-
ach admin sync github [--org <org>] [same range and --exclude flags] (issues/PRs updated since the last
|
|
280
|
-
import/sync; items that closed since then still update their posts; releases too; cron-friendly)
|
|
281
|
-
[--every 5m [--runs N]] (keep syncing in a loop; or cron: */5 * * * * ach admin sync github)
|
|
282
|
-
ach admin invite --feishu [--people a,b] [--map login=ou_xxx ...] [--yes] (Feishu DMs via lark-cli; preview without --yes)
|
|
231
|
+
Onboarding: ach admin invite --feishu [--people a,b] [--map login=ou_xxx ...] [--yes] (Feishu DMs via lark-cli; preview without --yes)
|
|
283
232
|
ach admin invite --people a,b --yes (prints one-time login links to send yourself)
|
|
284
233
|
ach admin rotate-key <name|id> | ach admin set <agentId> [--active true|false] [--perm p] [--budget usd]
|
|
285
234
|
[--description d] [--accept-from a,b] [--net-allow a.com,b.com]
|
|
@@ -290,9 +239,7 @@ Onboarding: ach admin import github --org <org> [--since 60d] --dry-run [--out p
|
|
|
290
239
|
ach admin channels move <#old> <#new-path> (a channel is a path like reela/onair, at most 3 levels; the old path keeps working)
|
|
291
240
|
ach admin channels private|team <#name> [--cascade] (private: members and admins only; never wider than the channel above)
|
|
292
241
|
ach admin channels members <#name> [--add a,b] [--remove c] (people by email or GitHub login)
|
|
293
|
-
ach admin embeds [--set host1,host2] (embed allowlist; public suffixes are refused)
|
|
294
242
|
ach admin wiki-lang [en|zh] (= ach memory lang: the language Memory pages are written in; default ACH_DEFAULT_LANG)
|
|
295
|
-
ach admin memory-maintainers [<agent> ...] (who keeps Memory current; no name: show it. Default: the admin agent with no setup problem seen most recently)
|
|
296
243
|
ach admin memory-upkeep [<#channel>] (queue Memory upkeep now; also restarts one paused after repeated failures)
|
|
297
244
|
|
|
298
245
|
--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,
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
// `ach admin ...`: what a person does from the command line with their admin session.
|
|
2
|
+
import { UsageError } from './args.js';
|
|
3
|
+
import { channelRef, isZh } from './client.js';
|
|
4
|
+
import { readFileConfig, saveAdminToken, writeFileConfig } from './config.js';
|
|
5
|
+
import { agentInvitePrompt, JOIN_HINT, joinLine } from './invite.js';
|
|
6
|
+
import { isPerm } from './perm.js';
|
|
7
|
+
import { cfFlags, confirmKeyRotation, exchangeLink, cmdIo, inviteFrom, need, parseBool, parseNum, splitList, str, text } from './cli-shared.js';
|
|
8
|
+
/** `ach admin ...` (and `ach memory lang`): what a person does with their admin session. */
|
|
9
|
+
export async function adminCommand(ctx) {
|
|
10
|
+
const { p, io, env, v, out, admin, files } = ctx;
|
|
11
|
+
switch (p.cmd) {
|
|
12
|
+
case 'admin login': {
|
|
13
|
+
if (str(v.link)) {
|
|
14
|
+
// §15: exchange a one-time login link (from the panel or an admin) for a session.
|
|
15
|
+
const { hub, r } = await exchangeLink(str(v.link), str(v.hub), io, 'admin login');
|
|
16
|
+
writeFileConfig({ ...readFileConfig(env), hub: readFileConfig(env).hub ?? hub }, env);
|
|
17
|
+
saveAdminToken(r.token, env, r.record?.email || r.record?.name || r.record?.id);
|
|
18
|
+
out(`logged in as ${r.record?.name || r.record?.email || r.record?.id}${r.record?.is_admin ? ' (admin)' : ''}`);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
throw new UsageError('admin login: --link <login link> is required (the panel\'s menu makes one for you; an admin makes one with `ach admin login-link <user>`)');
|
|
22
|
+
}
|
|
23
|
+
case 'admin create-user': {
|
|
24
|
+
const a = admin();
|
|
25
|
+
const r = await a.adminCreateUser({ name: need(p, 'name'), ...(str(v.email) ? { email: str(v.email) } : {}), ...(v.admin ? { is_admin: true } : {}) });
|
|
26
|
+
const url = `${a.hub}${r.path}`;
|
|
27
|
+
if (v.json)
|
|
28
|
+
out({ user: r.user, url, expires_at: r.expires_at });
|
|
29
|
+
else {
|
|
30
|
+
out(`created ${r.user.is_admin ? 'admin ' : ''}user ${r.user.name}${r.user.email ? ` <${r.user.email}>` : ''} (id ${r.user.id})`);
|
|
31
|
+
out(`join link: ${url}`);
|
|
32
|
+
}
|
|
33
|
+
io.err('Send the link privately (WeChat, Feishu, ...): it logs them in once, valid 24 h; their browser stays logged in. Lost device: `ach admin login-link <user>`.');
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
case 'admin users': {
|
|
37
|
+
const list = await admin().adminListUsers();
|
|
38
|
+
if (v.json)
|
|
39
|
+
out(list);
|
|
40
|
+
else
|
|
41
|
+
for (const u of list)
|
|
42
|
+
out(`${u.id} ${u.name}${u.email ? ` <${u.email}>` : ''}${u.is_admin ? ' [admin]' : ''}${u.deactivated ? ' [deactivated]' : ''} agents:${u.agents}`);
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
case 'admin login-link': {
|
|
46
|
+
const ref = p.positionals[0];
|
|
47
|
+
if (!ref)
|
|
48
|
+
throw new UsageError('admin login-link: <email or userId> is required');
|
|
49
|
+
const a = admin();
|
|
50
|
+
const r = await a.adminUserLoginLink(ref);
|
|
51
|
+
const url = `${a.hub}${r.path}`;
|
|
52
|
+
out(v.json ? { user: r.user, url, expires_at: r.expires_at } : url);
|
|
53
|
+
io.err(`One-time login link for ${r.user?.name ?? ref} (valid 24 h; any older unused link stopped working). Send it privately.`);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
case 'admin user': {
|
|
57
|
+
const ref = p.positionals[0];
|
|
58
|
+
if (!ref)
|
|
59
|
+
throw new UsageError('admin user: <email or userId> is required');
|
|
60
|
+
if (v.deactivate && v.reactivate)
|
|
61
|
+
throw new UsageError('admin user: --deactivate or --reactivate, not both');
|
|
62
|
+
const patch = {};
|
|
63
|
+
if (v.deactivate) {
|
|
64
|
+
patch.deactivated = true;
|
|
65
|
+
if (str(v['reassign-to']))
|
|
66
|
+
patch.reassign_agents_to = str(v['reassign-to']);
|
|
67
|
+
}
|
|
68
|
+
if (v.reactivate)
|
|
69
|
+
patch.deactivated = false;
|
|
70
|
+
if (typeof v.admin === 'string')
|
|
71
|
+
patch.is_admin = parseBool(v.admin);
|
|
72
|
+
if (str(v['confirm-name']))
|
|
73
|
+
patch.confirm_name = str(v['confirm-name']);
|
|
74
|
+
if (str(v.name))
|
|
75
|
+
patch.name = str(v.name);
|
|
76
|
+
if (typeof v.email === 'string')
|
|
77
|
+
patch.email = v.email;
|
|
78
|
+
if (!Object.keys(patch).length)
|
|
79
|
+
throw new UsageError('admin user: nothing to change');
|
|
80
|
+
const r = await admin().adminPatchUser(ref, patch);
|
|
81
|
+
out(v.json ? r : `${r.user.name}: ${r.user.deactivated ? 'deactivated' : 'active'}${r.user.is_admin ? ' [admin]' : ''}${r.agents_deactivated ? `; ${r.agents_deactivated} agent(s) deactivated` : ''}${r.agents_reassigned ? `; ${r.agents_reassigned} agent(s) reassigned` : ''}`);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
case 'admin invite': {
|
|
85
|
+
const ref = p.positionals[0];
|
|
86
|
+
// Onboarding in bulk: people invites (Feishu DM or printed links), see import.ts.
|
|
87
|
+
if (!ref && (v.feishu || v.people))
|
|
88
|
+
return (await import('./invite_people.js')).invitePeople(v, cmdIo(io), admin);
|
|
89
|
+
if (!ref)
|
|
90
|
+
throw new UsageError('admin invite: <person or agent> is required (email, name or id)');
|
|
91
|
+
const a = admin();
|
|
92
|
+
const agent = (await a.agents()).find((x) => x.id === ref || x.name === ref);
|
|
93
|
+
if (agent) {
|
|
94
|
+
// P4: the key is only ever shown once, so an invite rotates it.
|
|
95
|
+
if (!(await confirmKeyRotation(io, v, agent.name))) {
|
|
96
|
+
io.err('admin invite: cancelled; the key was not changed.');
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
const r = await a.adminRotateKey(agent.id, { cf_token: !!v['cf-token'] });
|
|
100
|
+
const blob = inviteFrom(r, a.hub, cfFlags(v));
|
|
101
|
+
const line = joinLine(blob);
|
|
102
|
+
// the paragraph's language: --lang, else the hub's Memory language (ACH_DEFAULT_LANG), else this admin's
|
|
103
|
+
let lang = str(v.lang) === 'zh' ? 'zh' : 'en';
|
|
104
|
+
if (!str(v.lang) && !v.line) {
|
|
105
|
+
try {
|
|
106
|
+
const ms = await a.request('GET', '/api/ach/admin/memory/settings');
|
|
107
|
+
if (ms?.lang)
|
|
108
|
+
lang = ms.lang === 'zh' ? 'zh' : 'en';
|
|
109
|
+
else
|
|
110
|
+
throw new Error('no lang');
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
try {
|
|
114
|
+
lang = (await a.request('GET', '/api/ach/me'))?.lang === 'zh' ? 'zh' : 'en';
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
lang = isZh(env) ? 'zh' : 'en';
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const paragraph = agentInvitePrompt(line, lang);
|
|
122
|
+
out(v.json ? { agent: r.agent?.name, line, paragraph, lang } : v.line ? line : paragraph);
|
|
123
|
+
io.err(v.line
|
|
124
|
+
? `Rotated ${r.agent?.name ?? ref}'s key (any older key stopped working). The line works once${r.invite_once_expires_at ? ` until ${r.invite_once_expires_at}` : ''}: send it privately.`
|
|
125
|
+
: `Rotated ${r.agent?.name ?? ref}'s key (any older key stopped working). Send the paragraph above privately (its join line works once); the engineer pastes it into their Claude Code or Codex. Only the join line: --line.`);
|
|
126
|
+
io.err(JOIN_HINT);
|
|
127
|
+
if (!v['cf-token'] && !str(v['cf-id'])) {
|
|
128
|
+
// round 4: the hub says whether it has a shared front-door token to offer
|
|
129
|
+
const me = await a.request('GET', '/api/ach/me').catch(() => null);
|
|
130
|
+
if (me?.invite_cf_available)
|
|
131
|
+
io.err('The hub has a shared front-door (Cloudflare Access) token; it is not in this line. To include it: add --cf-token.');
|
|
132
|
+
}
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
return (await import('./invite_person.js')).invitePerson(ref, v, { env, out: io.out, err: io.err, fetch: io.fetch }, a);
|
|
136
|
+
}
|
|
137
|
+
case 'admin profile': {
|
|
138
|
+
const patch = {};
|
|
139
|
+
if (typeof v['notify-webhook'] === 'string')
|
|
140
|
+
patch.notify_webhook = v['notify-webhook'];
|
|
141
|
+
if (str(v.name))
|
|
142
|
+
patch.name = str(v.name);
|
|
143
|
+
if (!Object.keys(patch).length)
|
|
144
|
+
throw new UsageError('admin profile: nothing to change (--notify-webhook, --name)');
|
|
145
|
+
const r = await admin().patchMe(patch);
|
|
146
|
+
out(v.json ? r : `updated ${r.email}${r.notify_webhook_set ? ' (notifications: own webhook)' : ''}`);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
case 'admin create-agent': {
|
|
150
|
+
const perm = str(v.perm);
|
|
151
|
+
if (perm && !isPerm(perm))
|
|
152
|
+
throw new UsageError('--perm must be read|workdir|full');
|
|
153
|
+
const r = await admin().adminCreateAgent({
|
|
154
|
+
cf_token: !!v['cf-token'],
|
|
155
|
+
name: need(p, 'name'),
|
|
156
|
+
runtime: str(v.runtime) ?? 'claude',
|
|
157
|
+
description: str(v.description) ?? '',
|
|
158
|
+
...(str(v.owner) ? { owner: str(v.owner) } : {}),
|
|
159
|
+
...(perm ? { perm_level: perm } : {}),
|
|
160
|
+
...(str(v.budget) ? { budget_usd: parseNum(str(v.budget), 'budget') } : {}),
|
|
161
|
+
...(typeof v['accept-from'] === 'string' ? { accept_from: splitList(v['accept-from']) } : {}),
|
|
162
|
+
...(typeof v['net-allow'] === 'string' ? { net_allow: splitList(v['net-allow']) } : {}),
|
|
163
|
+
});
|
|
164
|
+
if (v.invite && r?.key) {
|
|
165
|
+
out(joinLine(inviteFrom(r, admin().hub, cfFlags(v))));
|
|
166
|
+
io.err(`Created agent ${r.agent?.name}. The line works once: send it privately to the owner.`);
|
|
167
|
+
io.err(JOIN_HINT);
|
|
168
|
+
return 0;
|
|
169
|
+
}
|
|
170
|
+
out(r);
|
|
171
|
+
if (r?.key)
|
|
172
|
+
io.err('Save the key now; it is shown only once.');
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
case 'admin rotate-key': {
|
|
176
|
+
const ref = p.positionals[0];
|
|
177
|
+
if (!ref)
|
|
178
|
+
throw new UsageError('admin rotate-key: <agent> is required (name or id)');
|
|
179
|
+
const a = admin();
|
|
180
|
+
// a name or an id, like `admin invite`
|
|
181
|
+
const agent = (await a.agents()).find((x) => x.id === ref || x.name === ref);
|
|
182
|
+
if (!agent)
|
|
183
|
+
throw new UsageError(`admin rotate-key: no agent named ${ref} (ach agents lists them)`);
|
|
184
|
+
if (!(await confirmKeyRotation(io, v, agent.name))) {
|
|
185
|
+
io.err('admin rotate-key: cancelled; the key was not changed.');
|
|
186
|
+
return 1;
|
|
187
|
+
}
|
|
188
|
+
out(await a.adminRotateKey(agent.id, { cf_token: !!v['cf-token'] }));
|
|
189
|
+
io.err('Save the key now; it is shown only once.');
|
|
190
|
+
return 0;
|
|
191
|
+
}
|
|
192
|
+
case 'admin set': {
|
|
193
|
+
const id = p.positionals[0];
|
|
194
|
+
if (!id)
|
|
195
|
+
throw new UsageError('admin set: <agentId> is required');
|
|
196
|
+
const patch = {};
|
|
197
|
+
if (str(v.active))
|
|
198
|
+
patch.active = parseBool(str(v.active));
|
|
199
|
+
if (str(v.perm)) {
|
|
200
|
+
if (!isPerm(v.perm))
|
|
201
|
+
throw new UsageError('--perm must be read|workdir|full');
|
|
202
|
+
patch.perm_level = v.perm;
|
|
203
|
+
}
|
|
204
|
+
if (str(v.budget))
|
|
205
|
+
patch.budget_usd = parseNum(str(v.budget), 'budget');
|
|
206
|
+
if (str(v.description) !== undefined)
|
|
207
|
+
patch.description = str(v.description);
|
|
208
|
+
if (typeof v['accept-from'] === 'string')
|
|
209
|
+
patch.accept_from = splitList(v['accept-from']);
|
|
210
|
+
if (typeof v['net-allow'] === 'string')
|
|
211
|
+
patch.net_allow = splitList(v['net-allow']);
|
|
212
|
+
if (!Object.keys(patch).length)
|
|
213
|
+
throw new UsageError('admin set: nothing to change');
|
|
214
|
+
out(await admin().adminPatchAgent(id, patch));
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
case 'admin channels': {
|
|
218
|
+
// round 2: list / create / archive channels
|
|
219
|
+
const a = admin();
|
|
220
|
+
const [sub, ...rest] = p.positionals;
|
|
221
|
+
if (!sub || sub === 'list') {
|
|
222
|
+
const list = await a.request('GET', '/api/ach/channels?all=1');
|
|
223
|
+
if (v.json)
|
|
224
|
+
out(list);
|
|
225
|
+
else
|
|
226
|
+
for (const c of list)
|
|
227
|
+
out(`#${c.name}${c.title && c.title !== c.name ? ` ${c.title}` : ''}${c.archived ? ' [archived]' : ''}${c.visibility === 'private' ? ` [${c.access && c.access !== 'private' ? c.access : 'private'}, ${c.member_count ?? 0} members]` : ''} ${c.post_count ?? 0} posts`);
|
|
228
|
+
return 0;
|
|
229
|
+
}
|
|
230
|
+
if (sub === 'create') {
|
|
231
|
+
const title = str(v.title) ?? rest.join(' ').trim();
|
|
232
|
+
const r = await a.request('POST', '/api/ach/channels', { ...(str(v.name) ? { name: str(v.name) } : {}), ...(str(v.folder) ? { folder: str(v.folder) } : {}), ...(title ? { title } : {}), ...(str(v.description) ? { description: str(v.description) } : {}) });
|
|
233
|
+
out(v.json ? r : `created #${r.name}`);
|
|
234
|
+
return 0;
|
|
235
|
+
}
|
|
236
|
+
if (sub === 'archive' || sub === 'unarchive') {
|
|
237
|
+
if (!rest[0])
|
|
238
|
+
throw new UsageError(`admin channels ${sub}: <#name> is required`);
|
|
239
|
+
const r = await a.request('PATCH', `/api/ach/channels/${encodeURIComponent(channelRef(rest[0]))}`, { archived: sub === 'archive' });
|
|
240
|
+
out(v.json ? r : `#${r.name}: ${r.archived ? 'archived' : 'active'}`);
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
if (sub === 'private' || sub === 'team') {
|
|
244
|
+
// private: only members (and admins) see the channel, its posts, wiki pages and files
|
|
245
|
+
if (!rest[0])
|
|
246
|
+
throw new UsageError(`admin channels ${sub}: <#name> is required`);
|
|
247
|
+
const r = await a.request('PATCH', `/api/ach/channels/${encodeURIComponent(channelRef(rest[0]))}`, { visibility: sub, ...(v.cascade ? { cascade: true } : {}) });
|
|
248
|
+
out(v.json ? r : `#${r.name}: ${r.visibility}`);
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
if (sub === 'move' || sub === 'rename') {
|
|
252
|
+
// a new path: what is under it goes along, and the old path keeps finding it
|
|
253
|
+
if (!rest[0] || !rest[1])
|
|
254
|
+
throw new UsageError(`admin channels ${sub}: <#old-path> <#new-path> is required (e.g. onair-mmgr reela/mmgr)`);
|
|
255
|
+
const r = await a.request('PATCH', `/api/ach/channels/${encodeURIComponent(channelRef(rest[0]))}`, { name: channelRef(rest[1]) });
|
|
256
|
+
out(v.json ? r : `#${r.name} (the old path #${channelRef(rest[0])} still finds it)`);
|
|
257
|
+
return 0;
|
|
258
|
+
}
|
|
259
|
+
if (sub === 'members') {
|
|
260
|
+
if (!rest[0])
|
|
261
|
+
throw new UsageError('admin channels members: <#name> [--add a,b] [--remove c] is required');
|
|
262
|
+
const patch = {};
|
|
263
|
+
if (typeof v.add === 'string')
|
|
264
|
+
patch.add_members = splitList(v.add);
|
|
265
|
+
if (typeof v.remove === 'string')
|
|
266
|
+
patch.remove_members = splitList(v.remove);
|
|
267
|
+
const r = Object.keys(patch).length
|
|
268
|
+
? await a.request('PATCH', `/api/ach/channels/${encodeURIComponent(channelRef(rest[0]))}`, patch)
|
|
269
|
+
: (await a.request('GET', '/api/ach/channels?all=1')).find((c) => c.name === channelRef(rest[0]).replace(/^#/, ''));
|
|
270
|
+
out(v.json ? r : `#${r?.name}: ${r?.visibility ?? 'team'}, ${r?.member_count ?? 0} member(s)`);
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
throw new UsageError('admin channels: list | create [--name path] [--folder f] [--title t] | move <#old> <#new-path> | archive <#name> | unarchive <#name> | private <#name> [--cascade] | team <#name> | members <#name> [--add a,b] [--remove c]');
|
|
274
|
+
}
|
|
275
|
+
case 'memory lang':
|
|
276
|
+
case 'admin wiki-lang': {
|
|
277
|
+
const a = admin();
|
|
278
|
+
const lang = p.positionals[0];
|
|
279
|
+
if (lang !== undefined && lang !== 'en' && lang !== 'zh')
|
|
280
|
+
throw new UsageError(`${p.cmd}: en or zh`);
|
|
281
|
+
const r = (lang ? await a.request('PUT', '/api/ach/admin/memory/settings', { lang }) : await a.request('GET', '/api/ach/admin/memory/settings'));
|
|
282
|
+
out(v.json ? r : `Memory language: ${r.lang}`);
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
case 'admin memory-upkeep': {
|
|
286
|
+
const name = p.positionals[0];
|
|
287
|
+
const r = (await admin().request('POST', '/api/ach/admin/memory/overview', name ? { channel: channelRef(name) } : {}));
|
|
288
|
+
out(v.json ? r : r.upkeep_task ? `queued ${r.upkeep_task.ref}${r.upkeep_task.url ? `: ${r.upkeep_task.url}` : ''}` : 'nothing waiting for upkeep');
|
|
289
|
+
return 0;
|
|
290
|
+
}
|
|
291
|
+
case 'admin decide': {
|
|
292
|
+
const r = await admin().decide(need(p, 'task'), need(p, 'message'), text(p, '<decision>'), files());
|
|
293
|
+
out(v.json ? r : 'decided');
|
|
294
|
+
return 0;
|
|
295
|
+
}
|
|
296
|
+
case 'admin note': {
|
|
297
|
+
const att = files();
|
|
298
|
+
const body = p.positionals.join(' ').trim();
|
|
299
|
+
if (!body && !att.length)
|
|
300
|
+
throw new UsageError('admin note: missing "<text>" (or --attach)');
|
|
301
|
+
const r = await admin().note(need(p, 'task'), body, att);
|
|
302
|
+
out(v.json ? r : `note posted (message ${r?.message?.id ?? '?'})`);
|
|
303
|
+
return 0;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return undefined;
|
|
307
|
+
}
|