@koalaauto/agentchannel 3.45.1 → 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/README.md +9 -6
- package/dist/src/adapters/claude.d.ts +1 -1
- package/dist/src/adapters/claude.js +1 -1
- package/dist/src/adapters/codex.d.ts +1 -1
- package/dist/src/adapters/codex.js +5 -1
- package/dist/src/adapters/types.d.ts +1 -1
- package/dist/src/args.d.ts +1 -1
- package/dist/src/args.js +9 -62
- package/dist/src/caps.d.ts +1 -1
- package/dist/src/caps.js +1 -1
- 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 +23 -1184
- package/dist/src/client.d.ts +1 -23
- package/dist/src/client.js +1 -30
- package/dist/src/codexdaemon.d.ts +22 -0
- package/dist/src/codexdaemon.js +68 -0
- package/dist/src/desknotify.js +11 -7
- package/dist/src/doctor.js +1 -1
- package/dist/src/envcheck.js +1 -1
- 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/onboard.d.ts +3 -6
- package/dist/src/onboard.js +6 -14
- 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 +9 -82
- package/dist/src/runner/runner.js +31 -333
- 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 +4 -1
- package/dist/src/sandboxcheck.js +16 -1
- package/dist/src/service.d.ts +1 -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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// `ach remember`, `ach recall`, `ach decide-draft` and `ach memory ...`: the team Memory from the command line.
|
|
2
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
3
|
+
import { UsageError } from './args.js';
|
|
4
|
+
import { HubError } from './client.js';
|
|
5
|
+
import { loadConfig } from './config.js';
|
|
6
|
+
import { untrustedBlock as wrapUntrusted } from './prompts.js';
|
|
7
|
+
import { MEMORY_NOTE, absUrl, channelFile, noAgentHint, str, text } from './cli-shared.js';
|
|
8
|
+
/** `ach remember`, `ach recall`, `ach decide-draft`, `ach memory ...`: the team Memory. */
|
|
9
|
+
export async function memoryCommand(ctx) {
|
|
10
|
+
const { p, io, env, v, out, client, admin } = ctx;
|
|
11
|
+
switch (p.cmd) {
|
|
12
|
+
case 'remember': {
|
|
13
|
+
const source = str(v.source);
|
|
14
|
+
if (!source)
|
|
15
|
+
throw new UsageError('remember: --source <link> is required (a hub permalink like #/t/TASK-12 or a GitHub URL)');
|
|
16
|
+
const r = await client().remember(text(p, '"<fact or lesson>"'), source, { channel: str(v.channel), topic: str(v.topic), toTeam: !!v['to-team'] });
|
|
17
|
+
if (v.json)
|
|
18
|
+
out(r);
|
|
19
|
+
else if (r?.held)
|
|
20
|
+
out(`held for review: ${r.conflicts?.[0]?.reason ?? 'it contradicts Memory'} (an admin or the decider accepts or discards it in the Inbox)`);
|
|
21
|
+
else if (v['to-team'])
|
|
22
|
+
out(`promoted to the team overview ${r?.id ?? ''}${r?.source_private ? ' (source stays private: others see "source: private channel")' : ''}`);
|
|
23
|
+
else
|
|
24
|
+
out(`remembered ${r?.id ?? ''} (the Memory maintainer folds it into a page)`);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
case 'decide-draft': {
|
|
28
|
+
const source = str(v.source);
|
|
29
|
+
if (!source)
|
|
30
|
+
throw new UsageError('decide-draft: --source <link> is required');
|
|
31
|
+
const task = str(v.task) ?? str(env.ACH_TASK_ID);
|
|
32
|
+
const r = await client().decideDraft({ text: text(p, '"<who decided what>"'), source, by: str(v.by), channel: str(v.channel), topic: str(v.topic), task, ...(str(v.scope) ? { scope: str(v.scope) } : {}) });
|
|
33
|
+
if (v.json)
|
|
34
|
+
out(r);
|
|
35
|
+
else
|
|
36
|
+
out(`asked ${r?.decider_name ?? 'the decider'} ${r?.request_url ?? ''} (decision ${r?.id ?? ''}, ${r?.scope === 'task' ? 'for this task only, not a channel rule' : 'a standing channel rule'}${r?.money ? ' [money]' : ''}): their reply records it; nothing counts until they reply`);
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
case 'recall':
|
|
40
|
+
case 'memory search': {
|
|
41
|
+
const limit = str(v.limit) ? Number(str(v.limit)) : p.cmd === 'recall' ? 5 : undefined;
|
|
42
|
+
if (limit !== undefined && !(Number.isInteger(limit) && limit >= 1 && limit <= 30))
|
|
43
|
+
throw new UsageError(`${p.cmd}: --limit must be 1-30`);
|
|
44
|
+
const r = await client().wikiSearch(text(p, '"<query>"'), limit);
|
|
45
|
+
if (v.json)
|
|
46
|
+
out(r);
|
|
47
|
+
else if (p.cmd === 'recall') {
|
|
48
|
+
// one line + link per hit (never bloats the context)
|
|
49
|
+
// marks: superseded (with the current value), stale ("may be outdated, verify"), unconfirmed ("verify first")
|
|
50
|
+
const mark = (m) => (m === 'stale' ? '[stale: may be outdated, verify]' : m === 'unconfirmed' ? '[unconfirmed: not a confirmed decision, verify first]' : `[${m}]`);
|
|
51
|
+
const lines = r.results.slice(0, limit).map((x) => `- ${Array.isArray(x.marks) && x.marks.length ? `${x.marks.map(String).map(mark).join(' ')} ` : ''}${String(x.line ?? x.title).replace(/\s+/g, ' ').slice(0, 240)} — ${x.title} ${absUrl(env, x.url)}`);
|
|
52
|
+
out(lines.length ? [MEMORY_NOTE, ...lines].join('\n') : `nothing in Memory for "${r.query}" (try ach search for posts and tasks: background only)`);
|
|
53
|
+
}
|
|
54
|
+
else
|
|
55
|
+
out(wrapUntrusted(r.results.map((x) => ({ slug: x.slug, title: x.title, channel: x.channel_name, line: x.line, ...(x.marks?.length ? { marks: x.marks } : {}), url: absUrl(env, x.url) }))));
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
case 'memory read': {
|
|
59
|
+
const slug = p.positionals[0];
|
|
60
|
+
if (!slug)
|
|
61
|
+
throw new UsageError('memory read: <slug> is required');
|
|
62
|
+
const r = await client().wikiPage(slug);
|
|
63
|
+
out(v.json ? r : wrapUntrusted(r));
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
case 'memory hook': {
|
|
67
|
+
// Claude Code SessionStart hook: print a bounded Memory summary (stdout is added to the session context).
|
|
68
|
+
// It never fails the session: on any error it prints nothing and exits 0.
|
|
69
|
+
try {
|
|
70
|
+
const cfg = loadConfig(env);
|
|
71
|
+
if (!cfg.hub || !(cfg.key || cfg.runToken))
|
|
72
|
+
return 0;
|
|
73
|
+
const task = str(v.task) ?? str(env.ACH_TASK_ID);
|
|
74
|
+
const channel = str(v.channel) ?? str(env.ACH_CHANNEL) ?? channelFile(io.cwd ?? process.cwd());
|
|
75
|
+
const r = await client().memoryBrief(task ? { task } : channel ? { channel } : {});
|
|
76
|
+
out(v.json ? r : `${MEMORY_NOTE}\n${r.text}`);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
/* the session starts without Memory */
|
|
80
|
+
}
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
case 'memory pull': {
|
|
84
|
+
const dir = p.positionals[0];
|
|
85
|
+
if (!dir)
|
|
86
|
+
throw new UsageError('memory pull: <dir> is required');
|
|
87
|
+
const cfg = loadConfig(env);
|
|
88
|
+
if (!cfg.key && !cfg.runToken) {
|
|
89
|
+
io.err(await noAgentHint(cfg.adminToken ? admin() : undefined, 'memory pull <dir>'));
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
const base = io.cwd ?? process.cwd();
|
|
93
|
+
const files = await (await import('./wiki.js')).wikiPull(client(), isAbsolute(dir) ? dir : resolve(base, dir), str(v.channel));
|
|
94
|
+
out(v.json ? { files } : `pulled ${files.length} page(s) into ${dir} (edit, then: ach memory push ${dir} --note "<what changed>")`);
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
case 'memory push': {
|
|
98
|
+
const dir = p.positionals[0];
|
|
99
|
+
if (!dir)
|
|
100
|
+
throw new UsageError('memory push: <dir> is required');
|
|
101
|
+
const note = str(v.note);
|
|
102
|
+
if (!note)
|
|
103
|
+
throw new UsageError('memory push: --note "<what changed>" is required');
|
|
104
|
+
const base = io.cwd ?? process.cwd();
|
|
105
|
+
let r;
|
|
106
|
+
try {
|
|
107
|
+
r = await (await import('./wiki.js')).wikiPush(client(), isAbsolute(dir) ? dir : resolve(base, dir), note);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
// lint: list every problem line with its reason, then fail
|
|
111
|
+
const body = e instanceof HubError ? e.body : undefined;
|
|
112
|
+
if (e instanceof HubError && e.code === 'lint' && Array.isArray(body?.problems)) {
|
|
113
|
+
io.err(`not pushed: ${body.problems.length} problem(s). Fix each line and push again:`);
|
|
114
|
+
for (const x of body.problems)
|
|
115
|
+
io.err(` ${x.slug}.md${x.line ? ` line ${x.line}` : ''}: ${x.problem}${x.text ? `\n ${x.text}` : ''}`);
|
|
116
|
+
return 1;
|
|
117
|
+
}
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
120
|
+
if (v.json) {
|
|
121
|
+
out(r);
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
if (r.held) {
|
|
125
|
+
out(`held for review, nothing written: ${r.message ?? ''}`);
|
|
126
|
+
for (const c of r.conflicts ?? [])
|
|
127
|
+
io.err(` ${c.reason}`);
|
|
128
|
+
return 0;
|
|
129
|
+
}
|
|
130
|
+
out(`pushed: ${r.pages.length ? r.pages.map((x) => `${x.slug} v${x.version}${x.note && x.note !== note ? ` (${x.note})` : ''}`).join(', ') : 'no page changes'}; ${r.figures.length} new figure(s)`);
|
|
131
|
+
// warnings do not block the push: fix them in the next one
|
|
132
|
+
for (const w of r.warnings ?? [])
|
|
133
|
+
io.err(`warning: ${w.slug}.md line ${w.line}: ${w.problem}: ${w.text}`);
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type Parsed } from './args.js';
|
|
2
|
+
import { type Io } from './cli-shared.js';
|
|
3
|
+
/** A shell line with this terminal's stdin/stdout/stderr (sudo asks for its password there); its exit code. */
|
|
4
|
+
export declare function runInTerminal(line: string, env: NodeJS.ProcessEnv): Promise<number>;
|
|
5
|
+
/**
|
|
6
|
+
* Write <home>/bin/ach, a shim that runs this exact CLI with this node, so spawned
|
|
7
|
+
* agents always find a matching `ach` on PATH (even when the runner was started
|
|
8
|
+
* with npx or `node dist/src/cli.js`). Returns the dir to prepend to PATH.
|
|
9
|
+
*/
|
|
10
|
+
export declare function writeAchShim(home: string): string | undefined;
|
|
11
|
+
export declare function runCommand(p: Parsed, io: Io): Promise<number>;
|
|
12
|
+
/**
|
|
13
|
+
* `ach run` where the agent's key is not stored: the key lives only on its own machine and the hub keeps a hash of it, so it
|
|
14
|
+
* cannot be read back. The way back is a new key (the panel: the agent's page, Settings or the stopped-runner card) and its join line.
|
|
15
|
+
*/
|
|
16
|
+
export declare const NO_KEY_MESSAGE: {
|
|
17
|
+
readonly en: "ach run: there is no key for this agent on this machine (deleted, or a new machine or directory).\nA key cannot be recovered: in the panel open the agent and rotate its key (an admin or its owner can), then run the new `join` line here, in the agent's project directory.";
|
|
18
|
+
readonly zh: "ach run:这台机器上没有这个智能体的密钥(被删除了,或是新机器、新目录)。\n密钥找不回,只能换新:在面板里打开这个智能体,点「换新密钥」(管理员或负责人可以),再到它的项目目录里运行新生成的 `join` 命令。";
|
|
19
|
+
};
|
|
20
|
+
/** B7: `ach run` exit code when the hub answers 401 (systemd: RestartPreventExitStatus=78). */
|
|
21
|
+
export declare const AUTH_EXIT_CODE = 78;
|
|
22
|
+
export declare const AUTH_EXIT_MESSAGE = "ach run: key rotated or agent deactivated \u2014 run ach join";
|
|
23
|
+
/**
|
|
24
|
+
* The agent whose key this home already holds for `hub`, when it is another agent than `meId` and its key still works (a key the
|
|
25
|
+
* hub refuses belongs to nobody: replacing it loses nothing). Unknown (hub unreachable) counts as another agent: keeping a key
|
|
26
|
+
* costs a folder, losing one costs a runner.
|
|
27
|
+
*/
|
|
28
|
+
export declare function otherAgentHere(env: NodeJS.ProcessEnv, hub: string, newKey: string, meId: string, cfId: string | undefined, cfSecret: string | undefined, fetch: Io['fetch']): Promise<string | undefined>;
|