@koalaauto/agentchannel 0.0.0-stage → 3.0.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/LICENSE +202 -0
- package/README.md +154 -2
- package/dist/src/adapters/claude.d.ts +65 -0
- package/dist/src/adapters/claude.js +243 -0
- package/dist/src/adapters/codex.d.ts +74 -0
- package/dist/src/adapters/codex.js +237 -0
- package/dist/src/adapters/fake.d.ts +65 -0
- package/dist/src/adapters/fake.js +105 -0
- package/dist/src/adapters/index.d.ts +11 -0
- package/dist/src/adapters/index.js +26 -0
- package/dist/src/adapters/paths.d.ts +35 -0
- package/dist/src/adapters/paths.js +113 -0
- package/dist/src/adapters/procgroup.d.ts +14 -0
- package/dist/src/adapters/procgroup.js +49 -0
- package/dist/src/adapters/types.d.ts +57 -0
- package/dist/src/adapters/types.js +1 -0
- package/dist/src/args.d.ts +14 -0
- package/dist/src/args.js +257 -0
- package/dist/src/attachments.d.ts +63 -0
- package/dist/src/attachments.js +227 -0
- package/dist/src/attention.d.ts +85 -0
- package/dist/src/attention.js +262 -0
- package/dist/src/avatars.d.ts +40 -0
- package/dist/src/avatars.js +90 -0
- package/dist/src/cli.d.ts +45 -0
- package/dist/src/cli.js +1822 -0
- package/dist/src/client.d.ts +520 -0
- package/dist/src/client.js +449 -0
- package/dist/src/config.d.ts +62 -0
- package/dist/src/config.js +121 -0
- package/dist/src/desknotify.d.ts +154 -0
- package/dist/src/desknotify.js +426 -0
- package/dist/src/doctor.d.ts +75 -0
- package/dist/src/doctor.js +375 -0
- package/dist/src/env.d.ts +31 -0
- package/dist/src/env.js +52 -0
- package/dist/src/import.d.ts +245 -0
- package/dist/src/import.js +1008 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.js +13 -0
- package/dist/src/invite.d.ts +103 -0
- package/dist/src/invite.js +229 -0
- package/dist/src/invite_person.d.ts +16 -0
- package/dist/src/invite_person.js +75 -0
- package/dist/src/keystore.d.ts +55 -0
- package/dist/src/keystore.js +108 -0
- package/dist/src/mcp.d.ts +62 -0
- package/dist/src/mcp.js +503 -0
- package/dist/src/names.d.ts +30 -0
- package/dist/src/names.js +108 -0
- package/dist/src/netproxy.d.ts +20 -0
- package/dist/src/netproxy.js +36 -0
- package/dist/src/onboard.d.ts +105 -0
- package/dist/src/onboard.js +270 -0
- package/dist/src/perm.d.ts +12 -0
- package/dist/src/perm.js +20 -0
- package/dist/src/prompts.d.ts +166 -0
- package/dist/src/prompts.js +409 -0
- package/dist/src/runner/runner.d.ts +212 -0
- package/dist/src/runner/runner.js +1148 -0
- package/dist/src/runner/state.d.ts +68 -0
- package/dist/src/runner/state.js +80 -0
- package/dist/src/runner/workspace.d.ts +70 -0
- package/dist/src/runner/workspace.js +265 -0
- package/dist/src/service.d.ts +29 -0
- package/dist/src/service.js +101 -0
- package/dist/src/version.d.ts +3 -0
- package/dist/src/version.js +3 -0
- package/dist/src/wiki.d.ts +74 -0
- package/dist/src/wiki.js +222 -0
- package/package.json +48 -4
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import type { RuntimeAdapter } from '../adapters/types.js';
|
|
2
|
+
import { type Agent, type Client, type MentionItem, type Message } from '../client.js';
|
|
3
|
+
import { type Perm } from '../perm.js';
|
|
4
|
+
import { RunnerState } from './state.js';
|
|
5
|
+
import type { Workspace } from './workspace.js';
|
|
6
|
+
export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize'>>;
|
|
7
|
+
export interface RunnerOptions {
|
|
8
|
+
client: RunnerClient;
|
|
9
|
+
adapter: RuntimeAdapter;
|
|
10
|
+
workspace: Workspace;
|
|
11
|
+
home: string;
|
|
12
|
+
hub: string;
|
|
13
|
+
/** --dir: cwd for answer runs on tasks without a worktree. */
|
|
14
|
+
dir: string;
|
|
15
|
+
max?: number;
|
|
16
|
+
perm?: Perm;
|
|
17
|
+
intervalMs?: number;
|
|
18
|
+
heartbeatMs?: number;
|
|
19
|
+
idleMs?: number;
|
|
20
|
+
cfId?: string;
|
|
21
|
+
cfSecret?: string;
|
|
22
|
+
/** Extra env var names passed to spawned agents (`--pass-env`). */
|
|
23
|
+
passEnv?: string[];
|
|
24
|
+
baseEnv?: NodeJS.ProcessEnv;
|
|
25
|
+
log?: (s: string) => void;
|
|
26
|
+
newRunId?: () => string;
|
|
27
|
+
/**
|
|
28
|
+
* P1: leave new tasks alone for this long after they were sent, so the
|
|
29
|
+
* owner can claim them interactively first (default 0: claim at once).
|
|
30
|
+
*/
|
|
31
|
+
claimDelayMs?: number;
|
|
32
|
+
/** Client acting with a run token (posts structured answers for codex). Default: a hub Client. */
|
|
33
|
+
tokenClient?: (token: string) => Pick<Client, 'postMessage' | 'reply'>;
|
|
34
|
+
/** §19: base URL for links in prompts (ACH_PUBLIC_URL); default the hub URL. */
|
|
35
|
+
publicUrl?: string;
|
|
36
|
+
/** B1: where per-task scratch HOMEs for spawned agents live (default <tmpdir>/ach-homes). */
|
|
37
|
+
agentHomesDir?: string;
|
|
38
|
+
/** §16: how many recent channel posts work prompts carry (default 15; 0 = none). */
|
|
39
|
+
channelContext?: number;
|
|
40
|
+
}
|
|
41
|
+
export type Job = {
|
|
42
|
+
kind: 'work';
|
|
43
|
+
taskId: string;
|
|
44
|
+
}
|
|
45
|
+
/** nudge: the agent stopped without finishing; ask it once to complete, fail or ask. */
|
|
46
|
+
| {
|
|
47
|
+
kind: 'resume';
|
|
48
|
+
taskId: string;
|
|
49
|
+
replies: Message[];
|
|
50
|
+
nudge?: boolean;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'answer';
|
|
53
|
+
taskId: string;
|
|
54
|
+
question: Message;
|
|
55
|
+
} | {
|
|
56
|
+
kind: 'mention';
|
|
57
|
+
item: MentionItem;
|
|
58
|
+
};
|
|
59
|
+
export declare function jobKey(j: Job): string;
|
|
60
|
+
interface Active {
|
|
61
|
+
job: Job;
|
|
62
|
+
controller: AbortController;
|
|
63
|
+
/** lost: the hub says this run no longer owns the task (heartbeat 409, C3). */
|
|
64
|
+
reason?: 'cancel' | 'idle' | 'stop' | 'lost' | 'auth';
|
|
65
|
+
done: Promise<void>;
|
|
66
|
+
/** Job to start right after this one frees its slot (e.g. resume on replies that arrived mid-run). */
|
|
67
|
+
followUp?: Job;
|
|
68
|
+
}
|
|
69
|
+
/** A gate decision that lets the run go ahead (S1). Anything else rejects. */
|
|
70
|
+
export declare function approves(decision: string): boolean;
|
|
71
|
+
export declare function newRunId(): string;
|
|
72
|
+
/**
|
|
73
|
+
* What the worker is still waiting on: its own open questions, blocking decision
|
|
74
|
+
* requests, and (non-blocking) decision requests that replace one of its questions.
|
|
75
|
+
*/
|
|
76
|
+
export declare function openRequests(messages: Message[], myId: string): Message[];
|
|
77
|
+
/** A human note addressed to me (panel composer / `ach admin note`): wakes a parked run. */
|
|
78
|
+
export declare function isHumanNoteTo(m: Message, myId: string): boolean;
|
|
79
|
+
/** Answers / decisions replying to something I asked, and human notes to me, that the worker has not been shown yet. */
|
|
80
|
+
export declare function unseenReplies(messages: Message[], myId: string, seen: string[]): Message[];
|
|
81
|
+
/**
|
|
82
|
+
* Runner files a spawned agent must never read: the agent key (config.json), other
|
|
83
|
+
* runs' tokens (runs.json), session ids and logs. Not the whole home: the per-task
|
|
84
|
+
* worktrees live in <home>/work and must stay readable.
|
|
85
|
+
*/
|
|
86
|
+
export declare function secretPaths(home: string): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Runtime config a spawned agent's CLI needs from the real home: linked into the
|
|
89
|
+
* scratch home. Claude only: its user settings, hooks and MCP servers are not
|
|
90
|
+
* loaded anyway (settingSources [], strictMcpConfig). Codex is NOT linked: it
|
|
91
|
+
* gets its own CODEX_HOME (see prepareCodexHome).
|
|
92
|
+
*/
|
|
93
|
+
export declare const RUNTIME_HOME_LINKS: string[];
|
|
94
|
+
/**
|
|
95
|
+
* macOS (live test): Claude Code keeps its login in the login keychain, which
|
|
96
|
+
* `security` finds through $HOME/Library/Keychains. Without this link a worker
|
|
97
|
+
* with a scratch HOME reports "Not logged in". Only the folder is linked; the
|
|
98
|
+
* sandbox still denies the worker's tools every path under the real home.
|
|
99
|
+
*/
|
|
100
|
+
export declare function runtimeHomeLinks(platform?: NodeJS.Platform): string[];
|
|
101
|
+
/** The config.toml of a worker's own CODEX_HOME: nothing from the user's global config (no mcp_servers, profiles, notify hooks). */
|
|
102
|
+
export declare const CODEX_WORKER_CONFIG: string;
|
|
103
|
+
/**
|
|
104
|
+
* Codex isolation (live test): a worker run must not load the user's global
|
|
105
|
+
* Codex config (~/.codex/config.toml: MCP servers with their own credentials,
|
|
106
|
+
* profiles, notify hooks, AGENTS.md). The run gets its own CODEX_HOME holding
|
|
107
|
+
* only a generated config.toml and a symlink to the login file (auth.json) of
|
|
108
|
+
* the user's Codex home. The login file is placed by path only: it is never
|
|
109
|
+
* opened or copied here. Codex rewrites it in place through the link, so a
|
|
110
|
+
* refreshed login stays the user's. Sessions of the run stay in this home, so
|
|
111
|
+
* a resumed run of the same task finds its thread.
|
|
112
|
+
*/
|
|
113
|
+
export declare function prepareCodexHome(home: string, realCodexHome?: string): string;
|
|
114
|
+
/**
|
|
115
|
+
* B1: a per-task scratch HOME for spawned agents, so `~/.config/agentchannel`
|
|
116
|
+
* (agent key file, admin session, runner state) is not reachable through
|
|
117
|
+
* $HOME. Runtime config (.claude, .codex) is linked, the git identity
|
|
118
|
+
* (.gitconfig) copied; npm keeps the real cache via npm_config_cache.
|
|
119
|
+
*/
|
|
120
|
+
export declare function prepareAgentHome(root: string, agentName: string, key: string, realHome?: string, realCodexHome?: string): {
|
|
121
|
+
home: string;
|
|
122
|
+
env: Record<string, string>;
|
|
123
|
+
};
|
|
124
|
+
export declare function budgetBlocked(me: Agent): boolean;
|
|
125
|
+
export declare class Runner {
|
|
126
|
+
readonly state: RunnerState;
|
|
127
|
+
readonly queue: Job[];
|
|
128
|
+
readonly active: Map<string, Active>;
|
|
129
|
+
me?: Agent;
|
|
130
|
+
private o;
|
|
131
|
+
private stopped;
|
|
132
|
+
private waiters;
|
|
133
|
+
private lastPrune;
|
|
134
|
+
/** Last heartbeat sent for each parked run. */
|
|
135
|
+
private parkedHb;
|
|
136
|
+
/** B7: set when the hub answered 401 (key rotated, agent or owner deactivated): the runner stops. */
|
|
137
|
+
fatal?: 'unauthorized';
|
|
138
|
+
private wake?;
|
|
139
|
+
constructor(opts: RunnerOptions);
|
|
140
|
+
private log;
|
|
141
|
+
private taskLog;
|
|
142
|
+
private isQueuedOrActive;
|
|
143
|
+
enqueue(job: Job, front?: boolean): boolean;
|
|
144
|
+
/** Re-claim runs that were active when the runner died (§14.10). */
|
|
145
|
+
recover(): void;
|
|
146
|
+
/**
|
|
147
|
+
* B7: a 401 from inbox, heartbeat or claim means the key no longer works.
|
|
148
|
+
* Abort every job without posting anything (no fail, no usage) and stop.
|
|
149
|
+
*/
|
|
150
|
+
authFailed(where: string): void;
|
|
151
|
+
/** One poll cycle. */
|
|
152
|
+
tick(): Promise<void>;
|
|
153
|
+
private notifyBudget;
|
|
154
|
+
/**
|
|
155
|
+
* Cancel running jobs whose task went terminal; forget parked runs of
|
|
156
|
+
* terminal tasks; keep parked leases alive; and (C1) resume a parked run
|
|
157
|
+
* whose task is back to `working` with nothing left to wait for.
|
|
158
|
+
*/
|
|
159
|
+
checkActive(): Promise<void>;
|
|
160
|
+
/** Heartbeat a run; adopt a refreshed run token (C5). Throws HubError 409 when the run lost the task. */
|
|
161
|
+
private heartbeat;
|
|
162
|
+
/** C8: drop runs.json bookkeeping for terminal (or vanished) tasks, every 10 minutes. */
|
|
163
|
+
prune(force?: boolean): Promise<void>;
|
|
164
|
+
pump(): void;
|
|
165
|
+
/** Resolves when nothing is queued or running (tests). */
|
|
166
|
+
drain(): Promise<void>;
|
|
167
|
+
private runJob;
|
|
168
|
+
private ensureMe;
|
|
169
|
+
private runWork;
|
|
170
|
+
private runResume;
|
|
171
|
+
/** S10: the agent cannot write .git, so the runner commits its changes after every work run. */
|
|
172
|
+
private commitWork;
|
|
173
|
+
private afterWork;
|
|
174
|
+
/** Base URL for links shown to agents (§19). */
|
|
175
|
+
private base;
|
|
176
|
+
/** The task's absolute permalink: the hub's (ACH_PUBLIC_URL on the hub), else built here. */
|
|
177
|
+
private linkOf;
|
|
178
|
+
/** Memory trial metrics: the total size of a full work prompt (best effort, never blocks the run). */
|
|
179
|
+
private reportPromptSize;
|
|
180
|
+
/** §16: the latest posts of the task's channel (best effort). */
|
|
181
|
+
private channelContext;
|
|
182
|
+
/**
|
|
183
|
+
* §16 mention run: read-only, in --dir, with a run token that may only read
|
|
184
|
+
* the channel and reply in this thread. The hub hands each mention out once.
|
|
185
|
+
*/
|
|
186
|
+
private runMention;
|
|
187
|
+
/** Codex mention runs: the runner posts the reply the agent returned. */
|
|
188
|
+
private postStructuredReply;
|
|
189
|
+
private markHandled;
|
|
190
|
+
private runAnswer;
|
|
191
|
+
/** Codex answer runs (S4): read-only and offline; the runner posts what the agent returned. */
|
|
192
|
+
private postStructuredAnswer;
|
|
193
|
+
/** Readable roots for the spawned agent besides its cwd (S4). */
|
|
194
|
+
private readRoots;
|
|
195
|
+
/** Where a task's attachments are downloaded for its agents (readable, outside the worktree). */
|
|
196
|
+
filesDir(taskId: string): string;
|
|
197
|
+
/** The task's attachments, downloaded into filesDir (best effort: a failed download is listed without a path). */
|
|
198
|
+
private fetchFiles;
|
|
199
|
+
/** Run the adapter with heartbeat, idle watchdog, session persistence and usage posting. */
|
|
200
|
+
private execute;
|
|
201
|
+
/** Polls until stop() or a 401 (B7: resolves 'unauthorized' after aborting every job). */
|
|
202
|
+
start(): Promise<'stopped' | 'unauthorized'>;
|
|
203
|
+
/** Stop polling; abort running jobs without failing their tasks (they resume on restart). */
|
|
204
|
+
stop(): Promise<void>;
|
|
205
|
+
}
|
|
206
|
+
/** `ach run --gc`: remove work dirs of tasks terminal for more than `days` (branches are kept). */
|
|
207
|
+
export declare function gcWorktrees(client: Pick<Client, 'getTask'>, ws: Workspace, o?: {
|
|
208
|
+
days?: number;
|
|
209
|
+
now?: number;
|
|
210
|
+
log?: (s: string) => void;
|
|
211
|
+
}): Promise<string[]>;
|
|
212
|
+
export {};
|