@koalaauto/agentchannel 3.47.0 → 3.49.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.d.ts +8 -0
- package/dist/src/adapters/claude.js +26 -3
- package/dist/src/adapters/codex.d.ts +7 -9
- package/dist/src/adapters/codex.js +14 -3
- package/dist/src/adapters/fake.d.ts +7 -0
- package/dist/src/adapters/fake.js +7 -0
- package/dist/src/adapters/kiro.d.ts +8 -0
- package/dist/src/adapters/kiro.js +18 -2
- package/dist/src/adapters/models.d.ts +35 -0
- package/dist/src/adapters/models.js +129 -0
- package/dist/src/adapters/types.d.ts +13 -0
- package/dist/src/args.d.ts +1 -1
- package/dist/src/args.js +3 -3
- package/dist/src/cli-admin.js +3 -0
- package/dist/src/cli-run.js +1 -1
- package/dist/src/client.d.ts +8 -0
- package/dist/src/client.js +4 -0
- package/dist/src/envcheck.d.ts +8 -0
- package/dist/src/envcheck.js +16 -0
- package/dist/src/mcp.js +2 -2
- package/dist/src/runner/runner.d.ts +17 -2
- package/dist/src/runner/runner.js +84 -3
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,7 @@ import type { CanUseTool, HookCallbackMatcher, Options } from '@anthropic-ai/cla
|
|
|
2
2
|
import type { Perm } from '../perm.js';
|
|
3
3
|
import { type CapsServerSpec } from '../caps.js';
|
|
4
4
|
import { type PathPolicy } from './paths.js';
|
|
5
|
+
import { type RuntimeModels } from './models.js';
|
|
5
6
|
import { type AdapterResult, type AdapterRunOptions, type RuntimeAdapter } from './types.js';
|
|
6
7
|
/** Best-effort Bash deny list for `workdir` (the SDK sandbox is the real boundary). */
|
|
7
8
|
export declare const BASH_DENY: RegExp[];
|
|
@@ -123,6 +124,8 @@ export declare function thinkingFor(model: string | undefined, env?: Record<stri
|
|
|
123
124
|
display: 'summarized';
|
|
124
125
|
};
|
|
125
126
|
};
|
|
127
|
+
/** A level Claude Code takes (Codex's minimal and ultra are not). */
|
|
128
|
+
export declare const isClaudeEffort: (e: string | undefined) => e is "low" | "medium" | "high" | "xhigh" | "max";
|
|
126
129
|
/**
|
|
127
130
|
* The model a Claude run used: the one the CLI names in its init message, else the only one its result lists usage for. A run
|
|
128
131
|
* lists more than one when Claude Code does side work on a small model (titles, searches), which says nothing about the one
|
|
@@ -143,6 +146,11 @@ export declare class ClaudeAdapter implements RuntimeAdapter {
|
|
|
143
146
|
* one that takes no adaptive thinking): if the run dies at the start with an error about the thinking option, before the agent did
|
|
144
147
|
* anything, it is run once more without it, and this process stops asking.
|
|
145
148
|
*/
|
|
149
|
+
/** supportedModels() of a session that never gets a prompt: the CLI starts, answers from its own catalog and the login, and stops. */
|
|
150
|
+
listModels(o: {
|
|
151
|
+
env: Record<string, string>;
|
|
152
|
+
cwd: string;
|
|
153
|
+
}): Promise<RuntimeModels>;
|
|
146
154
|
run(opts: AdapterRunOptions): Promise<AdapterResult>;
|
|
147
155
|
private runOnce;
|
|
148
156
|
}
|
|
@@ -5,6 +5,7 @@ import { CAPS_SERVER } from '../caps.js';
|
|
|
5
5
|
import { isSessionToolResult, READ_TOOLS, toolDenied, toolPaths } from './paths.js';
|
|
6
6
|
import { macTempPatterns, readable, systemPaths } from './scope.js';
|
|
7
7
|
import { spawnGroup } from './procgroup.js';
|
|
8
|
+
import { claudeModels } from './models.js';
|
|
8
9
|
import { modelId } from './types.js';
|
|
9
10
|
/** Best-effort Bash deny list for `workdir` (the SDK sandbox is the real boundary). */
|
|
10
11
|
export const BASH_DENY = [
|
|
@@ -342,6 +343,8 @@ export function thinkingFor(model, env = {}) {
|
|
|
342
343
|
return { thinking: { type: 'adaptive', display: 'summarized' } };
|
|
343
344
|
}
|
|
344
345
|
const EFFORT_LEVELS = ['low', 'medium', 'high', 'xhigh', 'max'];
|
|
346
|
+
/** A level Claude Code takes (Codex's minimal and ultra are not). */
|
|
347
|
+
export const isClaudeEffort = (e) => !!e && EFFORT_LEVELS.includes(e);
|
|
345
348
|
/**
|
|
346
349
|
* The model a Claude run used: the one the CLI names in its init message, else the only one its result lists usage for. A run
|
|
347
350
|
* lists more than one when Claude Code does side work on a small model (titles, searches), which says nothing about the one
|
|
@@ -370,11 +373,30 @@ export class ClaudeAdapter {
|
|
|
370
373
|
* one that takes no adaptive thinking): if the run dies at the start with an error about the thinking option, before the agent did
|
|
371
374
|
* anything, it is run once more without it, and this process stops asking.
|
|
372
375
|
*/
|
|
376
|
+
/** supportedModels() of a session that never gets a prompt: the CLI starts, answers from its own catalog and the login, and stops. */
|
|
377
|
+
async listModels(o) {
|
|
378
|
+
const { query } = await import('@anthropic-ai/claude-agent-sdk');
|
|
379
|
+
const abortController = new AbortController();
|
|
380
|
+
const idle = async function* () {
|
|
381
|
+
await new Promise((r) => abortController.signal.addEventListener('abort', () => r(), { once: true }));
|
|
382
|
+
};
|
|
383
|
+
const q = query({ prompt: idle(), options: { cwd: o.cwd, env: o.env, settingSources: [], abortController } });
|
|
384
|
+
let timer;
|
|
385
|
+
try {
|
|
386
|
+
const raw = await Promise.race([q.supportedModels(), new Promise((_, rej) => (timer = setTimeout(() => rej(new Error('claude: no model list within 30 s')), 30_000)))]);
|
|
387
|
+
return claudeModels(raw);
|
|
388
|
+
}
|
|
389
|
+
finally {
|
|
390
|
+
if (timer)
|
|
391
|
+
clearTimeout(timer);
|
|
392
|
+
abortController.abort();
|
|
393
|
+
}
|
|
394
|
+
}
|
|
373
395
|
async run(opts) {
|
|
374
396
|
let progressed = false;
|
|
375
397
|
const first = await this.runOnce({ ...opts, onEvent: (e) => { if (e.type === 'text' || e.type === 'tool_start')
|
|
376
398
|
progressed = true; opts.onEvent(e); } }, true);
|
|
377
|
-
if (!first.ok && !progressed && !opts.signal.aborted && Object.keys(thinkingFor(this.o.model, opts.env)).length && /thinking|adaptive/i.test(first.error ?? '')) {
|
|
399
|
+
if (!first.ok && !progressed && !opts.signal.aborted && Object.keys(thinkingFor((opts.model ?? this.o.model), opts.env)).length && /thinking|adaptive/i.test(first.error ?? '')) {
|
|
378
400
|
thinkingRejected = true;
|
|
379
401
|
opts.onEvent({ type: 'error', data: 'the model does not take the thinking option; running without it' });
|
|
380
402
|
return this.runOnce(opts, false);
|
|
@@ -419,9 +441,10 @@ export class ClaudeAdapter {
|
|
|
419
441
|
env: claudeTmp ? { ...opts.env, CLAUDE_CODE_TMPDIR: claudeTmp } : opts.env,
|
|
420
442
|
abortController,
|
|
421
443
|
...(opts.resume ? { resume: opts.resume } : {}),
|
|
422
|
-
...(this.o.model ? { model: this.o.model } : {}),
|
|
444
|
+
...((opts.model ?? this.o.model) ? { model: (opts.model ?? this.o.model) } : {}),
|
|
445
|
+
...(isClaudeEffort(opts.effort) ? { effort: opts.effort } : {}),
|
|
423
446
|
...(opts.maxBudgetUsd && opts.maxBudgetUsd > 0 ? { maxBudgetUsd: opts.maxBudgetUsd } : {}),
|
|
424
|
-
...(withThinking ? thinkingFor(this.o.model, opts.env) : {}),
|
|
447
|
+
...(withThinking ? thinkingFor((opts.model ?? this.o.model), opts.env) : {}),
|
|
425
448
|
...permOptions,
|
|
426
449
|
...(caps.mcpServers ? { mcpServers: caps.mcpServers } : {}),
|
|
427
450
|
...(permOptions.allowedTools && caps.allowedTools.length ? { allowedTools: [...permOptions.allowedTools, ...caps.allowedTools] } : {}),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { SandboxMode, ThreadOptions, Usage } from '@openai/codex-sdk';
|
|
2
2
|
import type { Perm } from '../perm.js';
|
|
3
3
|
import { type CapsServerSpec } from '../caps.js';
|
|
4
|
+
import { type RuntimeModels } from './models.js';
|
|
4
5
|
import { type AdapterResult, type AdapterRunOptions, type RuntimeAdapter } from './types.js';
|
|
5
6
|
/** USD per 1M tokens. Configurable via ACH_CODEX_PRICE='{"input":..,"cached_input":..,"output":..}'. */
|
|
6
7
|
export interface PriceTable {
|
|
@@ -13,15 +14,7 @@ export declare function priceFromEnv(env?: Record<string, string | undefined>):
|
|
|
13
14
|
export declare function estimateCost(u: Partial<Usage>, p: PriceTable): number;
|
|
14
15
|
/** Only `perm=full` (hub and runner flag both say full) runs Codex without its sandbox. */
|
|
15
16
|
export declare function codexSandbox(perm: Perm): SandboxMode | undefined;
|
|
16
|
-
|
|
17
|
-
* Thread options (§14.3 as amended by round 1). Pure, unit-tested.
|
|
18
|
-
* - Sandboxed runs (every run but a `perm=full` work run) set no sandboxMode:
|
|
19
|
-
* `--sandbox` makes Codex ignore permission profiles, and the sandbox is the
|
|
20
|
-
* runner's profile (codexSandboxOverrides).
|
|
21
|
-
* - No additionalDirectories: the main repo's .git is never writable (S10);
|
|
22
|
-
* the runner commits after the run.
|
|
23
|
-
*/
|
|
24
|
-
export declare function codexThreadOptions(perm: Perm, cwd: string, model?: string, mode?: 'work' | 'answer' | 'mention' | 'prepare'): ThreadOptions;
|
|
17
|
+
export declare function codexThreadOptions(perm: Perm, cwd: string, model?: string, mode?: 'work' | 'answer' | 'mention' | 'prepare', effort?: string): ThreadOptions;
|
|
25
18
|
/** Codex `--config` overrides set by the runner (key names checked against the bundled codex 0.165 binary). */
|
|
26
19
|
export type CodexRunnerConfig = {
|
|
27
20
|
allow_login_shell: boolean;
|
|
@@ -130,5 +123,10 @@ export declare class CodexAdapter implements RuntimeAdapter {
|
|
|
130
123
|
model?: string;
|
|
131
124
|
price?: PriceTable;
|
|
132
125
|
});
|
|
126
|
+
/** model/list of the app-server of the Codex the SDK runs (the call Codex's IDE clients use): isDefault names the default. */
|
|
127
|
+
listModels(o: {
|
|
128
|
+
env: Record<string, string>;
|
|
129
|
+
cwd: string;
|
|
130
|
+
}): Promise<RuntimeModels>;
|
|
133
131
|
run(opts: AdapterRunOptions): Promise<AdapterResult>;
|
|
134
132
|
}
|
|
@@ -5,6 +5,8 @@ import { readable, systemPaths } from './scope.js';
|
|
|
5
5
|
import { KILL_GRACE_MS } from './procgroup.js';
|
|
6
6
|
import { ensureCodexDaemonDir } from '../codexdaemon.js';
|
|
7
7
|
import { CAPS_SERVER } from '../caps.js';
|
|
8
|
+
import { ask, CODEX_MODEL_LIST_INPUT, codexModelListReply } from './models.js';
|
|
9
|
+
import { sdkCodexBinary } from '../sandboxcheck.js';
|
|
8
10
|
import { modelId } from './types.js';
|
|
9
11
|
export const DEFAULT_CODEX_PRICE = { input: 1.25, cached_input: 0.125, output: 10 };
|
|
10
12
|
export function priceFromEnv(env = process.env) {
|
|
@@ -35,7 +37,8 @@ export function codexSandbox(perm) {
|
|
|
35
37
|
* - No additionalDirectories: the main repo's .git is never writable (S10);
|
|
36
38
|
* the runner commits after the run.
|
|
37
39
|
*/
|
|
38
|
-
|
|
40
|
+
const CODEX_EFFORTS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra'];
|
|
41
|
+
export function codexThreadOptions(perm, cwd, model, mode = 'work', effort) {
|
|
39
42
|
const full = mode === 'work' ? codexSandbox(perm) : undefined;
|
|
40
43
|
return {
|
|
41
44
|
workingDirectory: cwd,
|
|
@@ -43,6 +46,7 @@ export function codexThreadOptions(perm, cwd, model, mode = 'work') {
|
|
|
43
46
|
approvalPolicy: 'never',
|
|
44
47
|
skipGitRepoCheck: true,
|
|
45
48
|
...(model ? { model } : {}),
|
|
49
|
+
...(effort && CODEX_EFFORTS.includes(effort) ? { modelReasoningEffort: effort } : {}),
|
|
46
50
|
};
|
|
47
51
|
}
|
|
48
52
|
/** The permission profile the runner defines for its runs (a name the user's own config does not use). */
|
|
@@ -313,9 +317,16 @@ export class CodexAdapter {
|
|
|
313
317
|
constructor(o = {}) {
|
|
314
318
|
this.o = o;
|
|
315
319
|
}
|
|
320
|
+
/** model/list of the app-server of the Codex the SDK runs (the call Codex's IDE clients use): isDefault names the default. */
|
|
321
|
+
async listModels(o) {
|
|
322
|
+
const bin = sdkCodexBinary();
|
|
323
|
+
if (!bin)
|
|
324
|
+
throw new Error('codex: the bundled Codex binary is not there');
|
|
325
|
+
return ask(bin, ['app-server'], o.env, { cwd: o.cwd, input: CODEX_MODEL_LIST_INPUT, timeoutMs: 30_000, done: codexModelListReply });
|
|
326
|
+
}
|
|
316
327
|
async run(opts) {
|
|
317
328
|
const { Codex } = await import('@openai/codex-sdk');
|
|
318
|
-
const to = codexThreadOptions(opts.perm, opts.cwd, this.o.model, opts.mode);
|
|
329
|
+
const to = codexThreadOptions(opts.perm, opts.cwd, (opts.model ?? this.o.model), opts.mode, opts.effort);
|
|
319
330
|
const sandbox = to.sandboxMode
|
|
320
331
|
? []
|
|
321
332
|
: codexSandboxOverrides({
|
|
@@ -421,7 +432,7 @@ export class CodexAdapter {
|
|
|
421
432
|
error,
|
|
422
433
|
// the SDK does not say which model ran: the one pinned with --model, else what Codex wrote in the thread's session file
|
|
423
434
|
...(() => {
|
|
424
|
-
const model = modelId(this.o.model) ?? codexSessionModel(opts.env.CODEX_HOME, sessionId);
|
|
435
|
+
const model = modelId((opts.model ?? this.o.model)) ?? codexSessionModel(opts.env.CODEX_HOME, sessionId);
|
|
425
436
|
return model ? { model } : {};
|
|
426
437
|
})(),
|
|
427
438
|
};
|
|
@@ -48,6 +48,9 @@ export interface FakeRunInfo {
|
|
|
48
48
|
resume?: string;
|
|
49
49
|
cwd: string;
|
|
50
50
|
perm: string;
|
|
51
|
+
/** The model the runner asked for (undefined: the adapter's own default). */
|
|
52
|
+
model?: string;
|
|
53
|
+
effort?: string;
|
|
51
54
|
mode?: 'work' | 'answer' | 'mention' | 'prepare';
|
|
52
55
|
env: Record<string, string>;
|
|
53
56
|
denyReadPaths?: string[];
|
|
@@ -62,6 +65,8 @@ export interface FakeAdapterOptions {
|
|
|
62
65
|
ach?: AchCall;
|
|
63
66
|
/** Behave like codex: answer runs return JSON and the runner posts it. */
|
|
64
67
|
structuredAnswers?: boolean;
|
|
68
|
+
/** The runtime's model list (listModels); absent: the adapter cannot list. */
|
|
69
|
+
models?: import('./models.js').RuntimeModels;
|
|
65
70
|
/** Behave like kiro: no `ach` in the run; the runner reports the final text (implies structuredAnswers). */
|
|
66
71
|
remote?: boolean;
|
|
67
72
|
}
|
|
@@ -80,5 +85,7 @@ export declare class FakeAdapter implements RuntimeAdapter {
|
|
|
80
85
|
result: AchCallResult;
|
|
81
86
|
}[];
|
|
82
87
|
constructor(o: FakeAdapterOptions);
|
|
88
|
+
modelListings: number;
|
|
89
|
+
get listModels(): RuntimeAdapter['listModels'];
|
|
83
90
|
run(opts: AdapterRunOptions): Promise<AdapterResult>;
|
|
84
91
|
}
|
|
@@ -38,6 +38,11 @@ export class FakeAdapter {
|
|
|
38
38
|
this.structuredAnswers = !!o.structuredAnswers || !!o.remote;
|
|
39
39
|
this.remote = !!o.remote;
|
|
40
40
|
}
|
|
41
|
+
modelListings = 0;
|
|
42
|
+
get listModels() {
|
|
43
|
+
const m = this.o.models;
|
|
44
|
+
return m ? async () => (this.modelListings++, m) : undefined;
|
|
45
|
+
}
|
|
41
46
|
async run(opts) {
|
|
42
47
|
const info = {
|
|
43
48
|
index: this.runs.length,
|
|
@@ -45,6 +50,8 @@ export class FakeAdapter {
|
|
|
45
50
|
resume: opts.resume,
|
|
46
51
|
cwd: opts.cwd,
|
|
47
52
|
perm: opts.perm,
|
|
53
|
+
model: opts.model,
|
|
54
|
+
effort: opts.effort,
|
|
48
55
|
mode: opts.mode,
|
|
49
56
|
env: opts.env,
|
|
50
57
|
denyReadPaths: opts.denyReadPaths,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RuntimeModels } from './models.js';
|
|
1
2
|
import { type AdapterEvent, type AdapterResult, type AdapterRunOptions, type RuntimeAdapter } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Kiro runtime: each run is a Kiro cloud session started headlessly with
|
|
@@ -23,6 +24,7 @@ export declare function kiroArgs(o: {
|
|
|
23
24
|
repo: string;
|
|
24
25
|
prompt: string;
|
|
25
26
|
model?: string;
|
|
27
|
+
effort?: string;
|
|
26
28
|
resume?: string;
|
|
27
29
|
format: 'stream-json' | 'text';
|
|
28
30
|
}): string[];
|
|
@@ -83,5 +85,11 @@ export declare class KiroAdapter implements RuntimeAdapter {
|
|
|
83
85
|
readonly remote = true;
|
|
84
86
|
constructor(o?: KiroAdapterOptions);
|
|
85
87
|
run(opts: AdapterRunOptions): Promise<AdapterResult>;
|
|
88
|
+
/** `kiro-cli chat --list-models --format json`: the models this key may use, their credit rate, and default_model. */
|
|
89
|
+
listModels(o: {
|
|
90
|
+
env: Record<string, string>;
|
|
91
|
+
cwd: string;
|
|
92
|
+
realHome?: string;
|
|
93
|
+
}): Promise<RuntimeModels>;
|
|
86
94
|
private runOnce;
|
|
87
95
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
2
|
import { spawnGroup } from './procgroup.js';
|
|
3
|
+
import { ask, kiroModels } from './models.js';
|
|
3
4
|
import { modelId } from './types.js';
|
|
4
5
|
/**
|
|
5
6
|
* Kiro runtime: each run is a Kiro cloud session started headlessly with
|
|
@@ -55,6 +56,7 @@ export function kiroArgs(o) {
|
|
|
55
56
|
...(o.resume ? ['--resume-id', o.resume] : ['--cloud', '--repo', o.repo]),
|
|
56
57
|
...(o.format === 'stream-json' ? ['--output-format', 'stream-json'] : []),
|
|
57
58
|
...(o.model ? ['--model', o.model] : []),
|
|
59
|
+
...(o.effort && /^[a-z]{2,12}$/.test(o.effort) ? ['--effort', o.effort] : []),
|
|
58
60
|
o.prompt,
|
|
59
61
|
];
|
|
60
62
|
}
|
|
@@ -271,6 +273,20 @@ export class KiroAdapter {
|
|
|
271
273
|
}
|
|
272
274
|
return first.result;
|
|
273
275
|
}
|
|
276
|
+
/** `kiro-cli chat --list-models --format json`: the models this key may use, their credit rate, and default_model. */
|
|
277
|
+
async listModels(o) {
|
|
278
|
+
const env = this.o.env ?? process.env;
|
|
279
|
+
const bin = this.o.bin ?? env.ACH_KIRO_BIN ?? 'kiro-cli';
|
|
280
|
+
const done = (out) => {
|
|
281
|
+
try {
|
|
282
|
+
return kiroModels(JSON.parse(out));
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
return undefined; // not all of it yet
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
return ask(bin, ['chat', '--list-models', '--format', 'json'], kiroEnv(o.env, { realHome: o.realHome, apiKey: this.o.apiKey ?? env.KIRO_API_KEY }), { cwd: o.cwd, timeoutMs: 30_000, done });
|
|
289
|
+
}
|
|
274
290
|
runOnce(opts, repo, format) {
|
|
275
291
|
const env = this.o.env ?? process.env;
|
|
276
292
|
const bin = this.o.bin ?? env.ACH_KIRO_BIN ?? 'kiro-cli';
|
|
@@ -285,7 +301,7 @@ export class KiroAdapter {
|
|
|
285
301
|
return new Promise((resolve) => {
|
|
286
302
|
let child;
|
|
287
303
|
try {
|
|
288
|
-
child = spawnGroup(bin, kiroArgs({ repo, prompt: opts.prompt, model: this.o.model, resume: opts.resume, format }), {
|
|
304
|
+
child = spawnGroup(bin, kiroArgs({ repo, prompt: opts.prompt, model: (opts.model ?? this.o.model), effort: opts.effort, resume: opts.resume, format }), {
|
|
289
305
|
cwd: opts.cwd,
|
|
290
306
|
env: kiroEnv(opts.env, { realHome: opts.realHome, apiKey }),
|
|
291
307
|
signal: opts.signal,
|
|
@@ -312,7 +328,7 @@ export class KiroAdapter {
|
|
|
312
328
|
const ok = !err && code === 0 && !opts.signal.aborted;
|
|
313
329
|
const error = ok ? undefined : opts.signal.aborted ? 'aborted' : err ?? (stripAnsi(stderr).trim().split('\n').slice(-3).join(' ') || `kiro-cli exited ${code}`);
|
|
314
330
|
// Kiro bills credits, not dollars, and the CLI does not print them (2.37.1): the cost stays unknown, never guessed.
|
|
315
|
-
resolve({ result: { finalText, sessionId: out.sessionId, ok, error, estimated: true, ...(modelId(this.o.model) ? { model: this.o.model } : {}) }, progressed });
|
|
331
|
+
resolve({ result: { finalText, sessionId: out.sessionId, ok, error, estimated: true, ...(modelId((opts.model ?? this.o.model)) ? { model: (opts.model ?? this.o.model) } : {}) }, progressed });
|
|
316
332
|
};
|
|
317
333
|
child.on('error', (e) => finish(null, e?.code === 'ENOENT' ? `kiro-cli not found (${bin}): install it (curl -fsSL https://cli.kiro.dev/install | bash) or set ACH_KIRO_BIN` : String(e?.message ?? e)));
|
|
318
334
|
child.on('close', (code) => finish(code));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface RuntimeModel {
|
|
2
|
+
/** what the runner hands the tool (an alias like "sonnet", or a full id) */
|
|
3
|
+
id: string;
|
|
4
|
+
/** the tool's own name for it ("Sonnet 5.5") */
|
|
5
|
+
label?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
/** the effort levels it takes, lowest first */
|
|
8
|
+
efforts?: string[];
|
|
9
|
+
/** Kiro: credits per request relative to the base rate (Haiku 0.06, Opus 2.0) */
|
|
10
|
+
rate?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface RuntimeModels {
|
|
13
|
+
/** the model a run uses when none is picked, as the tool resolves it ("claude-opus-5-5", "gpt-6.1-terra", "auto") */
|
|
14
|
+
default?: string;
|
|
15
|
+
models: RuntimeModel[];
|
|
16
|
+
}
|
|
17
|
+
/** At most this many: a long list is the tool's catalog of old ones, and the hub keeps it on the agent. */
|
|
18
|
+
export declare const MAX_MODELS = 60;
|
|
19
|
+
/** Claude's supportedModels(): the "default" entry names the model it resolves to; the rest are pickable. Pure. */
|
|
20
|
+
export declare function claudeModels(raw: unknown): RuntimeModels;
|
|
21
|
+
/** Codex app-server model/list result: hidden ones left out, isDefault names the default. Pure. */
|
|
22
|
+
export declare function codexModels(raw: unknown): RuntimeModels;
|
|
23
|
+
/** `kiro-cli chat --list-models --format json`: {models: [{model_id, description, rate_multiplier}], default_model}. Pure. */
|
|
24
|
+
export declare function kiroModels(raw: unknown): RuntimeModels;
|
|
25
|
+
/** Run `cmd args`, feed it `input`, and resolve with what `done` makes of its stdout so far (or reject on timeout / exit). */
|
|
26
|
+
export declare function ask<T>(cmd: string, args: string[], env: Record<string, string>, o: {
|
|
27
|
+
input?: string;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
done: (out: string) => T | undefined;
|
|
30
|
+
cwd?: string;
|
|
31
|
+
}): Promise<T>;
|
|
32
|
+
/** The JSON-RPC lines that ask a Codex app-server for its models. */
|
|
33
|
+
export declare const CODEX_MODEL_LIST_INPUT: string;
|
|
34
|
+
/** The model/list answer among an app-server's output lines, once it is there. Pure. */
|
|
35
|
+
export declare function codexModelListReply(out: string): RuntimeModels | undefined;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// The models a runtime offers on this machine, with the one it uses when none is picked: what the agent's settings page lists.
|
|
2
|
+
// Each runtime is asked its own way, without a model call (nothing is spent): Claude through the SDK (supportedModels), Codex
|
|
3
|
+
// through its app-server (model/list, the call its IDE clients use), Kiro through `kiro-cli chat --list-models`. The list
|
|
4
|
+
// depends on the login (an account may not reach every model), so it is asked with the environment a run gets.
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { modelId } from './types.js';
|
|
7
|
+
/** At most this many: a long list is the tool's catalog of old ones, and the hub keeps it on the agent. */
|
|
8
|
+
export const MAX_MODELS = 60;
|
|
9
|
+
const text = (v, n) => (typeof v === 'string' && v.trim() ? v.trim().slice(0, n) : undefined);
|
|
10
|
+
const efforts = (v) => {
|
|
11
|
+
const out = Array.isArray(v) ? v.map((x) => (typeof x === 'string' ? x : typeof x?.reasoningEffort === 'string' ? x.reasoningEffort : '')).filter((x) => /^[a-z]{2,12}$/.test(x)) : [];
|
|
12
|
+
return out.length ? [...new Set(out)].slice(0, 8) : undefined;
|
|
13
|
+
};
|
|
14
|
+
function entry(id, o) {
|
|
15
|
+
const m = modelId(id);
|
|
16
|
+
if (!m)
|
|
17
|
+
return undefined;
|
|
18
|
+
const e = efforts(o.efforts);
|
|
19
|
+
const rate = typeof o.rate === 'number' && Number.isFinite(o.rate) && o.rate >= 0 ? o.rate : undefined;
|
|
20
|
+
return { id: m, ...(text(o.label, 60) ? { label: text(o.label, 60) } : {}), ...(text(o.description, 160) ? { description: text(o.description, 160) } : {}), ...(e ? { efforts: e } : {}), ...(rate !== undefined ? { rate } : {}) };
|
|
21
|
+
}
|
|
22
|
+
const list = (xs) => {
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
return xs.filter((x) => !!x && !seen.has(x.id) && !!seen.add(x.id)).slice(0, MAX_MODELS);
|
|
25
|
+
};
|
|
26
|
+
/** Claude's supportedModels(): the "default" entry names the model it resolves to; the rest are pickable. Pure. */
|
|
27
|
+
export function claudeModels(raw) {
|
|
28
|
+
const xs = Array.isArray(raw) ? raw : [];
|
|
29
|
+
const def = xs.find((x) => x?.value === 'default');
|
|
30
|
+
return {
|
|
31
|
+
...(modelId(def?.resolvedModel) ? { default: def.resolvedModel } : {}),
|
|
32
|
+
models: list(xs.filter((x) => x?.value !== 'default').map((x) => entry(x?.value, { label: x?.displayName, description: x?.description, efforts: x?.supportedEffortLevels }))),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Codex app-server model/list result: hidden ones left out, isDefault names the default. Pure. */
|
|
36
|
+
export function codexModels(raw) {
|
|
37
|
+
const r = raw;
|
|
38
|
+
const xs = Array.isArray(r?.data) ? r.data : [];
|
|
39
|
+
const def = xs.find((x) => x?.isDefault);
|
|
40
|
+
return {
|
|
41
|
+
...(modelId(def?.model ?? def?.id) ? { default: def.model ?? def.id } : {}),
|
|
42
|
+
models: list(xs.filter((x) => !x?.hidden).map((x) => entry(x?.model ?? x?.id, { label: x?.displayName, description: x?.description, efforts: x?.supportedReasoningEfforts }))),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** `kiro-cli chat --list-models --format json`: {models: [{model_id, description, rate_multiplier}], default_model}. Pure. */
|
|
46
|
+
export function kiroModels(raw) {
|
|
47
|
+
const r = raw;
|
|
48
|
+
const xs = Array.isArray(r?.models) ? r.models : [];
|
|
49
|
+
return {
|
|
50
|
+
...(modelId(r?.default_model) ? { default: r.default_model } : {}),
|
|
51
|
+
models: list(xs.map((x) => entry(x?.model_id, { label: x?.model_name !== x?.model_id ? x?.model_name : undefined, description: x?.description, rate: x?.rate_multiplier }))),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** Run `cmd args`, feed it `input`, and resolve with what `done` makes of its stdout so far (or reject on timeout / exit). */
|
|
55
|
+
export function ask(cmd, args, env, o) {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
let out = '';
|
|
58
|
+
let err = '';
|
|
59
|
+
let settled = false;
|
|
60
|
+
const child = spawn(cmd, args, { env, cwd: o.cwd, stdio: ['pipe', 'pipe', 'pipe'] });
|
|
61
|
+
const finish = (fn) => {
|
|
62
|
+
if (settled)
|
|
63
|
+
return;
|
|
64
|
+
settled = true;
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
try {
|
|
67
|
+
child.kill('SIGKILL');
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
/* gone */
|
|
71
|
+
}
|
|
72
|
+
fn();
|
|
73
|
+
};
|
|
74
|
+
const timer = setTimeout(() => finish(() => reject(new Error(`${cmd}: no model list within ${o.timeoutMs ?? 20_000} ms`))), o.timeoutMs ?? 20_000);
|
|
75
|
+
child.on('error', (e) => finish(() => reject(e)));
|
|
76
|
+
const check = () => {
|
|
77
|
+
try {
|
|
78
|
+
return o.done(out);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
return e instanceof Error ? e : new Error(String(e));
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
child.stdout.on('data', (d) => {
|
|
85
|
+
out += d;
|
|
86
|
+
const v = check();
|
|
87
|
+
if (v instanceof Error)
|
|
88
|
+
finish(() => reject(v));
|
|
89
|
+
else if (v !== undefined)
|
|
90
|
+
finish(() => resolve(v));
|
|
91
|
+
});
|
|
92
|
+
child.stderr.on('data', (d) => (err = (err + d).slice(-2000)));
|
|
93
|
+
child.on('close', (code) => {
|
|
94
|
+
const v = check();
|
|
95
|
+
if (v instanceof Error)
|
|
96
|
+
return finish(() => reject(v));
|
|
97
|
+
finish(() => (v !== undefined ? resolve(v) : reject(new Error(`${cmd} exited ${code}: ${err.trim().split('\n').slice(-2).join(' ')}`))));
|
|
98
|
+
});
|
|
99
|
+
// stdin stays open while the app-server answers (it stops when its input ends)
|
|
100
|
+
if (o.input !== undefined)
|
|
101
|
+
child.stdin.write(o.input);
|
|
102
|
+
else
|
|
103
|
+
child.stdin.end();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/** The JSON-RPC lines that ask a Codex app-server for its models. */
|
|
107
|
+
export const CODEX_MODEL_LIST_INPUT = [
|
|
108
|
+
{ jsonrpc: '2.0', id: 1, method: 'initialize', params: { clientInfo: { name: 'agentchannel', version: '0' } } },
|
|
109
|
+
{ jsonrpc: '2.0', method: 'initialized' },
|
|
110
|
+
{ jsonrpc: '2.0', id: 2, method: 'model/list', params: {} },
|
|
111
|
+
].map((x) => JSON.stringify(x)).join('\n') + '\n';
|
|
112
|
+
/** The model/list answer among an app-server's output lines, once it is there. Pure. */
|
|
113
|
+
export function codexModelListReply(out) {
|
|
114
|
+
for (const line of out.split('\n')) {
|
|
115
|
+
let d;
|
|
116
|
+
try {
|
|
117
|
+
d = JSON.parse(line);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (d?.id !== 2)
|
|
123
|
+
continue;
|
|
124
|
+
if (d.error)
|
|
125
|
+
throw new Error(`codex model/list: ${String(d.error.message ?? '').slice(0, 200)}`);
|
|
126
|
+
return codexModels(d.result);
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
@@ -18,6 +18,10 @@ export interface AdapterRunOptions {
|
|
|
18
18
|
cwd: string;
|
|
19
19
|
resume?: string;
|
|
20
20
|
perm: Perm;
|
|
21
|
+
/** The model for this run (the agent's hub setting); undefined: the runner's --model, else the runtime's default. */
|
|
22
|
+
model?: string;
|
|
23
|
+
/** How hard the run thinks (low ... max; Codex also minimal, ultra); undefined: the model's default. */
|
|
24
|
+
effort?: string;
|
|
21
25
|
/** work: the task's worker run; answer: a short read-only run answering one question; mention: a read-only run replying in a channel thread (§16). */
|
|
22
26
|
mode?: RunMode;
|
|
23
27
|
env: Record<string, string>;
|
|
@@ -76,4 +80,13 @@ export interface RuntimeAdapter {
|
|
|
76
80
|
*/
|
|
77
81
|
readonly remote?: boolean;
|
|
78
82
|
run(opts: AdapterRunOptions): Promise<AdapterResult>;
|
|
83
|
+
/**
|
|
84
|
+
* The models it offers with the environment a run gets (its login decides which), and the one a run uses when none is picked.
|
|
85
|
+
* No model call. Absent: the runtime cannot say (the panel then offers only the default and a typed id).
|
|
86
|
+
*/
|
|
87
|
+
listModels?(o: {
|
|
88
|
+
env: Record<string, string>;
|
|
89
|
+
cwd: string;
|
|
90
|
+
realHome?: string;
|
|
91
|
+
}): Promise<import('./models.js').RuntimeModels>;
|
|
79
92
|
}
|
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>)\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 ask-human [--task <id>] \"<one question>\" --action <capability> [--arg k=v ...] [--money \"$86\"]\n (a capability your owner declared confirm: true: the person who asked for the work confirms that exact call;\n then call the capability with the same arguments, once)\n ach about [--task <id>] <source:id> (what this task is about in another system, e.g. batch:20261118_003; set once)\n ach related <source:id> (the tasks and outside events about it)\n ach progress [--task <id>] \"<text>\" | ach note [--task <id>] \"<text>\"\n Each takes --attach <file> (repeatable; png, jpg, webp, gif, mp4, webm, mov, pdf, zip; 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 post <#name> --card '<json>' | --card @card.json (a card instead of text, e.g. a #product-log entry:\n {\"type\":\"change\",\"tag\":\"feature|fix|change\",\"title\",\"summary\",\"audience\",\"env\",\"refs\":[links]})\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";
|
|
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 ask-human [--task <id>] \"<one question>\" --action <capability> [--arg k=v ...] [--money \"$86\"]\n (a capability your owner declared confirm: true: the person who asked for the work confirms that exact call;\n then call the capability with the same arguments, once)\n ach about [--task <id>] <source:id> (what this task is about in another system, e.g. batch:20261118_003; set once)\n ach related <source:id> (the tasks and outside events about it)\n ach progress [--task <id>] \"<text>\" | ach note [--task <id>] \"<text>\"\n Each takes --attach <file> (repeatable; png, jpg, webp, gif, mp4, webm, mov, pdf, zip; 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 post <#name> --card '<json>' | --card @card.json (a card instead of text, e.g. a #product-log entry:\n {\"type\":\"change\",\"tag\":\"feature|fix|change\",\"title\",\"date\",\"summary\",\"by\":[logins],\"refs\":[links]})\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 [--model m|default] [--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
|
@@ -57,7 +57,7 @@ export const COMMANDS = {
|
|
|
57
57
|
'admin invite': { 'cf-id': s, 'cf-secret': s, 'cf-token': b, line: b, lang: s, feishu: b, people: s, map: sm, yes: b, ...json },
|
|
58
58
|
'admin profile': { 'notify-webhook': s, name: s, ...json },
|
|
59
59
|
'admin rotate-key': { 'cf-token': b, yes: b, ...json },
|
|
60
|
-
'admin set': { active: s, perm: s, budget: s, description: s, 'accept-from': s, 'net-allow': s, ...json },
|
|
60
|
+
'admin set': { active: s, perm: s, budget: s, model: s, description: s, 'accept-from': s, 'net-allow': s, ...json },
|
|
61
61
|
'admin decide': { task: s, message: s, attach: sm, 'attach-url': sm, ...json },
|
|
62
62
|
'admin channels': { name: s, folder: s, title: s, description: s, add: s, remove: s, cascade: b, ...json },
|
|
63
63
|
'admin memory-upkeep': { ...json },
|
|
@@ -191,7 +191,7 @@ Channels: ach channels [--all] | ach channel [<#name>] [--since <iso>] [--be
|
|
|
191
191
|
an @name that matches nobody is warned about, with the closest name;
|
|
192
192
|
--announce: "shipped" / "data published": an announcement every channel reader is notified of)
|
|
193
193
|
ach post <#name> --card '<json>' | --card @card.json (a card instead of text, e.g. a #product-log entry:
|
|
194
|
-
{"type":"change","tag":"feature|fix|change","title","
|
|
194
|
+
{"type":"change","tag":"feature|fix|change","title","date","summary","by":[logins],"refs":[links]})
|
|
195
195
|
ach reply [<postId>] "<text>" [--evidence "<files/commands>"] [--escalate [--to owner|asker] [--ask "<one line to decide>"] | --as-owner] [--attach <file> ...]
|
|
196
196
|
(postId defaults to $ACH_THREAD_ID in a mention run)
|
|
197
197
|
ach thread <postId> | ach search "<query>" [--channel <name>] [--author <agent|person>] [--limit n]
|
|
@@ -240,7 +240,7 @@ Admin: ach admin login --link <login link>
|
|
|
240
240
|
Onboarding: ach admin invite --feishu [--people a,b] [--map login=ou_xxx ...] [--yes] (Feishu DMs via lark-cli; preview without --yes)
|
|
241
241
|
ach admin invite --people a,b --yes (prints one-time login links to send yourself)
|
|
242
242
|
ach admin rotate-key <name|id> | ach admin set <agentId> [--active true|false] [--perm p] [--budget usd]
|
|
243
|
-
[--description d] [--accept-from a,b] [--net-allow a.com,b.com]
|
|
243
|
+
[--model m|default] [--description d] [--accept-from a,b] [--net-allow a.com,b.com]
|
|
244
244
|
ach admin profile [--notify-webhook <url>] [--name <n>] (your own account)
|
|
245
245
|
ach admin decide --task <id> --message <msgId> "<decision>" [--attach <file> ...]
|
|
246
246
|
ach admin note --task <id> "<text>" [--attach <file> ...] (a human note to the agents on a task)
|
package/dist/src/cli-admin.js
CHANGED
|
@@ -201,6 +201,9 @@ export async function adminCommand(ctx) {
|
|
|
201
201
|
throw new UsageError('--perm must be read|workdir|full');
|
|
202
202
|
patch.perm_level = v.perm;
|
|
203
203
|
}
|
|
204
|
+
// the model its runs use; "default" (or an empty value) clears it
|
|
205
|
+
if (typeof v.model === 'string')
|
|
206
|
+
patch.model = ['default', ''].includes(v.model.trim()) ? '' : v.model.trim();
|
|
204
207
|
if (str(v.budget))
|
|
205
208
|
patch.budget_usd = parseNum(str(v.budget), 'budget');
|
|
206
209
|
if (str(v.description) !== undefined)
|
package/dist/src/cli-run.js
CHANGED
|
@@ -178,7 +178,7 @@ export async function runCommand(p, io) {
|
|
|
178
178
|
return probeEnvironment(runtime === 'codex' ? 'codex' : 'claude', { env, hub: cfg.hub, runEnv: { ...inheritedEnv(baseEnv, passEnv), ...homeEnv } });
|
|
179
179
|
},
|
|
180
180
|
});
|
|
181
|
-
io.err(`ach run: agent ${me.name}, runtime ${runtime}, perm min(${me.perm_level}, ${perm}), dir ${dir}` +
|
|
181
|
+
io.err(`ach run: agent ${me.name}, runtime ${runtime}, perm min(${me.perm_level}, ${perm}), model ${me.model || str(v.model) || 'default'}, dir ${dir}` +
|
|
182
182
|
(Object.keys(repos).length ? `, repos ${Object.entries(repos).map(([k, x]) => `${k}=${x}`).join(' ')}` : '') +
|
|
183
183
|
`, claim delay ${claimDelay}s`);
|
|
184
184
|
// desktop notifications for the owner (deduped by event id, also across restarts)
|
package/dist/src/client.d.ts
CHANGED
|
@@ -37,6 +37,10 @@ export interface Agent {
|
|
|
37
37
|
runtime?: string;
|
|
38
38
|
description?: string;
|
|
39
39
|
perm_level?: string;
|
|
40
|
+
/** The model its runs use (opus, sonnet, haiku or a full id); empty: the runtime's default (or the runner's --model). */
|
|
41
|
+
model?: string;
|
|
42
|
+
/** How hard its runs think (low ... max; Codex also minimal, ultra); empty: the model's default. */
|
|
43
|
+
effort?: string;
|
|
40
44
|
budget_usd?: number;
|
|
41
45
|
spent_usd?: number;
|
|
42
46
|
active?: boolean;
|
|
@@ -556,6 +560,10 @@ export declare class Client {
|
|
|
556
560
|
reportRepos(repos: string[], remotes?: Record<string, string>): Promise<any>;
|
|
557
561
|
/** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values); and how
|
|
558
562
|
* it was started (directory, home, --repo paths, its supervisor), which the owner's page turns into the line that restarts it. */
|
|
563
|
+
/** The models the runtime offers on the runner's machine and the one a run uses when none is picked (the agent's settings list them). */
|
|
564
|
+
reportModels(r: {
|
|
565
|
+
runtime: string;
|
|
566
|
+
} & import('./adapters/models.js').RuntimeModels): Promise<any>;
|
|
559
567
|
reportRunner(r: {
|
|
560
568
|
perm: string;
|
|
561
569
|
runtime: string;
|
package/dist/src/client.js
CHANGED
|
@@ -398,6 +398,10 @@ export class Client {
|
|
|
398
398
|
}
|
|
399
399
|
/** How this runner runs tasks: its --perm, the tool, and the NAMES of the variables it hands its agents (never values); and how
|
|
400
400
|
* it was started (directory, home, --repo paths, its supervisor), which the owner's page turns into the line that restarts it. */
|
|
401
|
+
/** The models the runtime offers on the runner's machine and the one a run uses when none is picked (the agent's settings list them). */
|
|
402
|
+
async reportModels(r) {
|
|
403
|
+
return this.ach('PUT', '/me/models', r);
|
|
404
|
+
}
|
|
401
405
|
async reportRunner(r) {
|
|
402
406
|
return this.ach('PUT', '/me/runner', r);
|
|
403
407
|
}
|
package/dist/src/envcheck.d.ts
CHANGED
|
@@ -26,4 +26,12 @@ export declare function summarizeRuntimeError(raw: string): string;
|
|
|
26
26
|
export declare function quotaProblem(s: string): {
|
|
27
27
|
pauseMs: number;
|
|
28
28
|
} | null;
|
|
29
|
+
/**
|
|
30
|
+
* The runtime refused the model it was asked for (a typo, one the account cannot use): Claude Code's "issue with the selected
|
|
31
|
+
* model (x). It may not exist or you may not have access to it", the API's not_found_error on a model, Codex's "model `x` does
|
|
32
|
+
* not exist", Kiro's "invalid model".
|
|
33
|
+
*/
|
|
34
|
+
/** The runtime refused the effort level it was asked for (one the model does not take). */
|
|
35
|
+
export declare function effortRejected(s: string | undefined): boolean;
|
|
36
|
+
export declare function modelRejected(s: string | undefined): boolean;
|
|
29
37
|
export declare function looksLikeLoginError(s: string): boolean;
|
package/dist/src/envcheck.js
CHANGED
|
@@ -104,6 +104,22 @@ export function quotaProblem(s) {
|
|
|
104
104
|
return { pauseMs: 5 * 60_000 };
|
|
105
105
|
return null;
|
|
106
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* The runtime refused the model it was asked for (a typo, one the account cannot use): Claude Code's "issue with the selected
|
|
109
|
+
* model (x). It may not exist or you may not have access to it", the API's not_found_error on a model, Codex's "model `x` does
|
|
110
|
+
* not exist", Kiro's "invalid model".
|
|
111
|
+
*/
|
|
112
|
+
/** The runtime refused the effort level it was asked for (one the model does not take). */
|
|
113
|
+
export function effortRejected(s) {
|
|
114
|
+
if (!s)
|
|
115
|
+
return false;
|
|
116
|
+
return /\b(reasoning[ _.]?)?effort\b[^\n]{0,80}\b(invalid|not supported|unsupported|unknown|must be one of|is not (a )?valid|not allowed)|\b(invalid|unsupported|unknown) (value for )?(reasoning[ _.]?)?effort/i.test(s);
|
|
117
|
+
}
|
|
118
|
+
export function modelRejected(s) {
|
|
119
|
+
if (!s)
|
|
120
|
+
return false;
|
|
121
|
+
return /issue with the selected model|\bmodel\b[^\n]{0,80}\b(does not exist|not found|not available|not supported|is not (a )?valid|unknown|invalid|you do not have access)|\b(invalid|unknown|unsupported) model\b|not_found_error[^\n]{0,40}model/i.test(s);
|
|
122
|
+
}
|
|
107
123
|
export function looksLikeLoginError(s) {
|
|
108
124
|
return /\b401\b|unauthori[sz]ed|not logged in|please (run|log)[^.\n]*login|invalid (api )?key|authentication (failed|required|error)|credentials? (expired|missing|invalid)/i.test(s);
|
|
109
125
|
}
|
package/dist/src/mcp.js
CHANGED
|
@@ -416,9 +416,9 @@ export function buildMcpServer(client, o = {}) {
|
|
|
416
416
|
type: z.literal('change'),
|
|
417
417
|
tag: z.enum(['feature', 'fix', 'change']),
|
|
418
418
|
title: z.string().describe('What changed, one line'),
|
|
419
|
+
date: z.string().optional().describe('YYYY-MM-DD it shipped, when not today'),
|
|
419
420
|
summary: z.string().optional().describe('One sentence on what it does; omit when the title says it all'),
|
|
420
|
-
|
|
421
|
-
env: z.string().optional().describe('Where it is live, with versions; omit when not verified'),
|
|
421
|
+
by: z.array(z.string()).optional().describe("Who made it: the commits' authors (GitHub logins)"),
|
|
422
422
|
refs: z.array(z.string()).optional().describe('Commit, PR, issue or task links'),
|
|
423
423
|
})
|
|
424
424
|
.optional()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AdapterResult, type RuntimeAdapter } from '../adapters/types.js';
|
|
2
2
|
import { type Agent, type Client, type MentionItem, type MentionOutcome, type Message } from '../client.js';
|
|
3
3
|
import { type Perm } from '../perm.js';
|
|
4
4
|
import { RunnerState } from './state.js';
|
|
@@ -7,7 +7,7 @@ import { TraceRecorder } from '../trace.js';
|
|
|
7
7
|
import { type SandboxStatus } from '../sandboxcheck.js';
|
|
8
8
|
export * from './home.js';
|
|
9
9
|
export * from './structured.js';
|
|
10
|
-
export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'githubToken' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'reportSetup' | 'reportRepos' | 'reportRunner' | 'release' | 'putTrace' | 'pushToken' | 'taskPr' | 'prepareRun' | 'prepared'>>;
|
|
10
|
+
export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'githubToken' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'reportSetup' | 'reportRepos' | 'reportRunner' | 'reportModels' | 'release' | 'putTrace' | 'pushToken' | 'taskPr' | 'prepareRun' | 'prepared'>>;
|
|
11
11
|
export interface RunnerOptions {
|
|
12
12
|
client: RunnerClient;
|
|
13
13
|
adapter: RuntimeAdapter;
|
|
@@ -130,6 +130,8 @@ export declare function isHumanNoteTo(m: Message, myId: string): boolean;
|
|
|
130
130
|
/** Answers / decisions replying to something I asked, and human notes to me, that the worker has not been shown yet. */
|
|
131
131
|
export declare function unseenReplies(messages: Message[], myId: string, seen: string[]): Message[];
|
|
132
132
|
export declare function budgetBlocked(me: Agent): boolean;
|
|
133
|
+
/** How often the runner lists the runtime's models again (besides at start and after a rejected model). */
|
|
134
|
+
export declare const MODELS_EVERY_MS: number;
|
|
133
135
|
export declare class Runner {
|
|
134
136
|
readonly state: RunnerState;
|
|
135
137
|
readonly queue: Job[];
|
|
@@ -197,6 +199,19 @@ export declare class Runner {
|
|
|
197
199
|
/** the capabilities last told to the hub (decisions §34): an edit of the file is reported again on the next poll */
|
|
198
200
|
private capsReported;
|
|
199
201
|
private reportRunner;
|
|
202
|
+
/**
|
|
203
|
+
* Tell the hub which models the runtime offers here and which one a run uses when none is picked (the agent's settings
|
|
204
|
+
* page lists them): when the runner starts, again a day later (a login or the tool's catalog changes), and at once after
|
|
205
|
+
* a run's model was rejected. Asked with the environment a run gets, so the list is what this agent's login can use.
|
|
206
|
+
*/
|
|
207
|
+
private modelsAt;
|
|
208
|
+
private modelsBusy;
|
|
209
|
+
/** set when a run's model was rejected: the list on the hub is out of date */
|
|
210
|
+
private modelsStale;
|
|
211
|
+
/** an older hub without /me/models, or a runtime that cannot list: asked no more */
|
|
212
|
+
private modelsOff;
|
|
213
|
+
private modelsLogged;
|
|
214
|
+
private reportModels;
|
|
200
215
|
private notifyBudget;
|
|
201
216
|
/**
|
|
202
217
|
* Cancel running jobs whose task went terminal; forget parked runs of
|
|
@@ -9,15 +9,16 @@ import { capsPath, capsPromptText, capsServeArgs, loadCaps } from '../caps.js';
|
|
|
9
9
|
import { autorunPath, loadAutorun, ruleName, smallRule } from '../autorun.js';
|
|
10
10
|
import { toolchainReadRoots } from '../adapters/paths.js';
|
|
11
11
|
import { developerDir } from '../adapters/scope.js';
|
|
12
|
+
import { modelId } from '../adapters/types.js';
|
|
12
13
|
import { Client as HubClient, HubError, isTerminal } from '../client.js';
|
|
13
14
|
import { taskFiles } from '../attachments.js';
|
|
14
|
-
import { buildAgentEnv } from '../env.js';
|
|
15
|
+
import { buildAgentEnv, inheritedEnv } from '../env.js';
|
|
15
16
|
import { unlinkWindowsSandbox } from '../codexhome.js';
|
|
16
17
|
import { effectivePerm } from '../perm.js';
|
|
17
18
|
import { ANSWER_SCHEMA, buildAnswerPrompt, buildMentionPrompt, buildPreparePrompt, buildResumePrompt, buildTaskPrompt, postUrl, refOf, REMOTE_FAILED_PREFIX, taskUrl } from '../prompts.js';
|
|
18
19
|
import { RunnerState } from './state.js';
|
|
19
20
|
import { isGitRepo } from './workspace.js';
|
|
20
|
-
import { looksLikeLoginError, quotaProblem, summarizeRuntimeError } from '../envcheck.js';
|
|
21
|
+
import { effortRejected, looksLikeLoginError, modelRejected, quotaProblem, summarizeRuntimeError } from '../envcheck.js';
|
|
21
22
|
import { redact } from '../redact.js';
|
|
22
23
|
import { TraceRecorder } from '../trace.js';
|
|
23
24
|
import { looksLikeSandboxError } from '../sandboxcheck.js';
|
|
@@ -109,6 +110,8 @@ export function budgetBlocked(me) {
|
|
|
109
110
|
const budget = Number(me.budget_usd ?? 0);
|
|
110
111
|
return budget > 0 && Number(me.spent_usd ?? 0) >= budget;
|
|
111
112
|
}
|
|
113
|
+
/** How often the runner lists the runtime's models again (besides at start and after a rejected model). */
|
|
114
|
+
export const MODELS_EVERY_MS = 24 * 60 * 60_000;
|
|
112
115
|
export class Runner {
|
|
113
116
|
state;
|
|
114
117
|
queue = [];
|
|
@@ -395,6 +398,50 @@ export class Runner {
|
|
|
395
398
|
}
|
|
396
399
|
}
|
|
397
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Tell the hub which models the runtime offers here and which one a run uses when none is picked (the agent's settings
|
|
403
|
+
* page lists them): when the runner starts, again a day later (a login or the tool's catalog changes), and at once after
|
|
404
|
+
* a run's model was rejected. Asked with the environment a run gets, so the list is what this agent's login can use.
|
|
405
|
+
*/
|
|
406
|
+
modelsAt = 0;
|
|
407
|
+
modelsBusy = false;
|
|
408
|
+
/** set when a run's model was rejected: the list on the hub is out of date */
|
|
409
|
+
modelsStale = false;
|
|
410
|
+
/** an older hub without /me/models, or a runtime that cannot list: asked no more */
|
|
411
|
+
modelsOff = false;
|
|
412
|
+
modelsLogged = '';
|
|
413
|
+
async reportModels() {
|
|
414
|
+
const adapter = this.o.adapter;
|
|
415
|
+
if (this.modelsOff || this.modelsBusy || !adapter.listModels || !this.o.client.reportModels)
|
|
416
|
+
return;
|
|
417
|
+
if (this.modelsAt && !this.modelsStale && Date.now() - this.modelsAt < MODELS_EVERY_MS)
|
|
418
|
+
return;
|
|
419
|
+
this.modelsBusy = true;
|
|
420
|
+
this.modelsAt = Date.now();
|
|
421
|
+
this.modelsStale = false;
|
|
422
|
+
try {
|
|
423
|
+
const me = await this.ensureMe();
|
|
424
|
+
const baseEnv = this.o.baseEnv ?? process.env;
|
|
425
|
+
const realHome = realHomeOf(baseEnv);
|
|
426
|
+
const { home, env } = prepareAgentHome(this.o.agentHomesDir ?? join(tmpdir(), 'ach-homes'), me.name, 'model-list', realHome, baseEnv.CODEX_HOME || undefined);
|
|
427
|
+
const list = await adapter.listModels({ env: { ...inheritedEnv(baseEnv, this.o.passEnv), ...env }, cwd: home, ...(realHome ? { realHome } : {}) });
|
|
428
|
+
await this.o.client.reportModels({ runtime: adapter.name, ...list });
|
|
429
|
+
this.modelsLogged = '';
|
|
430
|
+
}
|
|
431
|
+
catch (e) {
|
|
432
|
+
if (e instanceof HubError && e.status === 404)
|
|
433
|
+
this.modelsOff = true;
|
|
434
|
+
const msg = String(e?.message ?? e).slice(0, 300);
|
|
435
|
+
// a list that cannot be had is not worth a line every day: said once until it changes
|
|
436
|
+
if (!this.modelsOff && msg !== this.modelsLogged) {
|
|
437
|
+
this.modelsLogged = msg;
|
|
438
|
+
this.log(`model list: ${msg} (trying again in a day)`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
finally {
|
|
442
|
+
this.modelsBusy = false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
398
445
|
async notifyBudget(t, me) {
|
|
399
446
|
if (this.state.runs.budgetNotified[t.id])
|
|
400
447
|
return;
|
|
@@ -1480,8 +1527,15 @@ export class Runner {
|
|
|
1480
1527
|
const caps = this.capsFor(taskId, rec.runId, realHome, env.TMPDIR);
|
|
1481
1528
|
this.taskLog(taskId, `${mode} run start perm=${perm} resume=${resume ?? '-'} cwd=${rec.workdir}${caps ? ` caps=${caps.tools.map((t) => t.name).join(',')}` : ''}`);
|
|
1482
1529
|
let result;
|
|
1530
|
+
// the model the agent's owner or an admin picked for its runs (the hub's setting, read for every run); none: the runner's
|
|
1531
|
+
// --model, else the runtime's default
|
|
1532
|
+
const model = modelId(me.model);
|
|
1533
|
+
const effort = typeof me.effort === 'string' && /^[a-z]{2,12}$/.test(me.effort) ? me.effort : undefined;
|
|
1534
|
+
let toolsRan = 0;
|
|
1483
1535
|
try {
|
|
1484
|
-
|
|
1536
|
+
const go = (m, e) => this.o.adapter.run({
|
|
1537
|
+
...(m ? { model: m } : {}),
|
|
1538
|
+
...(e ? { effort: e } : {}),
|
|
1485
1539
|
prompt: caps ? `${prompt}\n\n${capsPromptText(caps.tools)}` : prompt,
|
|
1486
1540
|
...(caps ? { caps } : {}),
|
|
1487
1541
|
cwd: rec.workdir,
|
|
@@ -1504,6 +1558,8 @@ export class Runner {
|
|
|
1504
1558
|
onEvent: (e) => {
|
|
1505
1559
|
lastEvent = Date.now();
|
|
1506
1560
|
const id = e.data && typeof e.data === 'object' ? String(e.data.id ?? '') : '';
|
|
1561
|
+
if (e.type === 'tool_start')
|
|
1562
|
+
toolsRan++;
|
|
1507
1563
|
if (e.type === 'tool_start' && id)
|
|
1508
1564
|
inflight.add(id);
|
|
1509
1565
|
if (e.type === 'tool_end' && id)
|
|
@@ -1516,6 +1572,29 @@ export class Runner {
|
|
|
1516
1572
|
this.taskLog(taskId, `${e.type} ${typeof e.data === 'string' ? e.data.slice(0, 500) : JSON.stringify(e.data, (k, v) => (k === 'output' ? undefined : v))?.slice(0, 500)}`);
|
|
1517
1573
|
},
|
|
1518
1574
|
});
|
|
1575
|
+
let m = model;
|
|
1576
|
+
let ef = effort;
|
|
1577
|
+
result = await go(m, ef);
|
|
1578
|
+
// a model or an effort level the runtime does not take (a typo, one the account cannot use, a level the model lacks) must
|
|
1579
|
+
// not stop the agent: run again on the default, and say so in the trace (the run's chip then shows what really answered)
|
|
1580
|
+
for (let i = 0; i < 2 && !result.ok && !toolsRan && !entry.controller.signal.aborted; i++) {
|
|
1581
|
+
const why = summarizeRuntimeError(result.error ?? '').slice(0, 160);
|
|
1582
|
+
let note;
|
|
1583
|
+
if (ef && effortRejected(result.error)) {
|
|
1584
|
+
note = `the effort "${ef}" set for this agent was not accepted (${why}); running at the model's default effort`;
|
|
1585
|
+
ef = undefined;
|
|
1586
|
+
}
|
|
1587
|
+
else if (m && modelRejected(result.error)) {
|
|
1588
|
+
note = `the model "${m}" set for this agent was not accepted (${why}); running on the default model`;
|
|
1589
|
+
m = undefined;
|
|
1590
|
+
}
|
|
1591
|
+
else
|
|
1592
|
+
break;
|
|
1593
|
+
recorder.event({ type: 'error', data: note });
|
|
1594
|
+
this.taskLog(taskId, note);
|
|
1595
|
+
this.modelsStale = true;
|
|
1596
|
+
result = await go(m, ef);
|
|
1597
|
+
}
|
|
1519
1598
|
}
|
|
1520
1599
|
catch (e) {
|
|
1521
1600
|
result = { finalText: '', ok: false, error: String(e?.message ?? e) };
|
|
@@ -1574,6 +1653,8 @@ export class Runner {
|
|
|
1574
1653
|
try {
|
|
1575
1654
|
await this.reportRepos();
|
|
1576
1655
|
await this.reportRunner();
|
|
1656
|
+
// not awaited: listing starts the tool (up to a few seconds), and claiming work must not wait for it
|
|
1657
|
+
void this.reportModels();
|
|
1577
1658
|
await this.tick();
|
|
1578
1659
|
}
|
|
1579
1660
|
catch (e) {
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.49.0",
|
|
4
4
|
"description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentchannel",
|