@agentchatme/agent-core 0.3.1 → 0.4.1

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.
@@ -0,0 +1,289 @@
1
+ import { TextsRuntime } from 'agentchatme';
2
+ import { a as RunProfile, b as RunRunner, f as RunPreflight, g as RunRequest, c as RunOutcome } from './runner-B-ZZDAAm.js';
3
+
4
+ /** What a preset needs to build a runner acting as one agent. */
5
+ interface PresetContext {
6
+ /** The identity home of the agent the runs act as. Runs' file tools are kept off it where the runtime allows. */
7
+ readonly home: string;
8
+ /** The run's working directory. */
9
+ readonly workdir: string;
10
+ readonly profile: RunProfile;
11
+ /** The agent's key and API base, for the hosted tool server the runs reach. Never put on argv. */
12
+ readonly apiKey: string;
13
+ readonly apiBase: string;
14
+ /** The environment runs inherit (defaults to `process.env`). */
15
+ readonly env?: NodeJS.ProcessEnv;
16
+ /** Test seam: the runtime's binary. */
17
+ readonly command?: string;
18
+ /**
19
+ * The version the runs name in `X-AgentChat-Client-Version`: the front door
20
+ * that placed them (the `agentchat` listener passes its own). Defaults to
21
+ * this engine's version. The client name is the runtime's (`claude-code`,
22
+ * `codex`): a run the listener wakes needs no wake-webhook tools, and the
23
+ * hosted tools spell their names per runtime by it.
24
+ */
25
+ readonly clientVersion?: string;
26
+ }
27
+ interface PresetInspection {
28
+ readonly ok: boolean;
29
+ readonly detail: string;
30
+ }
31
+ interface Preset {
32
+ /** The name a user types (`--preset <name>`). */
33
+ readonly name: string;
34
+ /** Human name for output. */
35
+ readonly label: string;
36
+ /** How the served texts spell the hosted tools for this runtime (`GET /v1/texts?runtime=`). */
37
+ readonly runtime: TextsRuntime;
38
+ /** Is the runtime installed, new enough and signed in? For `doctor` and `status`. */
39
+ inspect(env?: NodeJS.ProcessEnv, command?: string): PresetInspection;
40
+ /**
41
+ * A runner whose runs act as the agent in `ctx`: the hosted tool server is
42
+ * given to each run with that agent's key (a file or an environment
43
+ * variable, never an argument), whatever the runtime's own configuration
44
+ * registers. May write owner-only files into `ctx.home`.
45
+ */
46
+ runner(ctx: PresetContext): RunRunner;
47
+ /**
48
+ * The hosted-tool configuration a listener's run of this preset sees, as
49
+ * lines for `doctor` (keys never printed): what the run is given, and what
50
+ * of the user's own configuration still applies.
51
+ */
52
+ describeMcp(ctx: {
53
+ readonly home: string;
54
+ readonly apiBase: string;
55
+ readonly env?: NodeJS.ProcessEnv;
56
+ }): string[];
57
+ /** Variables a service must capture for this runtime (where it keeps its config, when relocated). */
58
+ readonly serviceEnv: readonly string[];
59
+ /** Whether the run can read files under the identity home (decides how the manual is pointed to). */
60
+ readonly readsIdentityHome: boolean;
61
+ }
62
+
63
+ /** `actual` (any text containing `x.y.z`) is at least `minimum`. False when either has no version in it. */
64
+ declare function semverAtLeast(actual: string, minimum: string): boolean;
65
+
66
+ declare const CLAUDE_CODE_PRESET = "claude-code";
67
+ /**
68
+ * Two flags set the floor:
69
+ * * `--permission-prompts none` — Claude Code v2.1.259.
70
+ * * `CLAUDE_CODE_MCP_STARTUP_WAIT_MS` — bounds how long the first
71
+ * non-interactive turn waits for the MCP servers `--allowedTools` names to
72
+ * connect. Added in v2.1.274. Without it a run could start before the
73
+ * hosted inbox tool is there.
74
+ */
75
+ declare const MIN_CLAUDE_CODE_VERSION = "2.1.274";
76
+ /** The MCP server name the runs see; every hosted tool is `mcp__agentchat__<tool>`, as the served texts spell them. */
77
+ declare const CLAUDE_MCP_SERVER_NAME = "agentchat";
78
+ declare const AGENTCHAT_TOOL_ALLOW = "mcp__agentchat__*";
79
+ /** Built-in tools an `answer` run keeps: read-only files plus the web. */
80
+ declare const ANSWER_TOOLS: readonly ["Read", "Glob", "Grep", "WebSearch", "WebFetch"];
81
+ /** Built-in tools a `work` run additionally pre-approves. */
82
+ declare const WORK_TOOLS: readonly ["Bash", "Edit", "Write", "MultiEdit", "NotebookEdit"];
83
+ /** Env a parent Claude Code session leaks that would make the child think it is nested. */
84
+ declare const PARENT_ENV_KEYS: string[];
85
+ /** Claude Code's supported relocation knob. Unset is NOT the same as `~/.claude`. */
86
+ declare function claudeConfigDirFrom(env?: NodeJS.ProcessEnv): string | undefined;
87
+ /** `~/.claude`, or the relocated config dir. */
88
+ declare function claudeHomeFor(configDirOverride: string | undefined): string;
89
+ /**
90
+ * Where Claude Code keeps user-scoped MCP servers (and so any key registered
91
+ * there): `~/.claude.json`, or `$CLAUDE_CONFIG_DIR/.claude.json`.
92
+ */
93
+ declare function claudeUserStatePathFor(configDirOverride: string | undefined): string;
94
+ declare function buildClaudeEnv(configDirOverride: string | undefined, source?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
95
+ /**
96
+ * Is Claude Code signed in? `claude auth status` prints JSON with a boolean
97
+ * `loggedIn` and exits 0 if logged in, 1 if not. When that JSON is there it is
98
+ * the answer. The file/keychain probes are a fallback for builds without the
99
+ * subcommand; the keychain probe is existence-only and never prompts — a
100
+ * resident listener must never trigger a keychain prompt.
101
+ */
102
+ declare function claudeIsLoggedIn(configDirOverride?: string, command?: string): boolean;
103
+ declare function inspectClaudeRuntime(configDirOverride?: string, command?: string): PresetInspection;
104
+ /**
105
+ * The entry of `denied` that is `dir` or contains it, or null. Whole path
106
+ * segments only: `~/.claude/agentchat` does not contain `~/.claude/agentchat-workdir`.
107
+ */
108
+ declare function deniedAncestorOf(dir: string, denied: readonly string[]): string | null;
109
+ declare function claudeProfileArgs(profile: RunProfile): string[];
110
+ interface ClaudeRunArgOptions {
111
+ /** `AGENTCHAT_RUN_MAX_BUDGET_USD`: stop the run once estimated spend reaches this (print mode only). */
112
+ readonly maxBudgetUsd?: string | undefined;
113
+ /**
114
+ * Absolute paths the run's file tools may not read (a directory covers its
115
+ * tree). Rendered as `Read(//<path>)` / `Read(//<dir>/**)` deny rules. A
116
+ * prompt-injected run could otherwise read the key and send it; the wake
117
+ * text should not be the only guard. POSIX paths only — on Windows the
118
+ * rule syntax for drive paths is undocumented, so nothing is rendered.
119
+ */
120
+ readonly denyReadPaths?: readonly string[] | undefined;
121
+ /**
122
+ * A `--mcp-config` file holding the hosted server with the agent's key;
123
+ * with it, `--strict-mcp-config` makes it the run's only MCP server. Absent:
124
+ * the run uses the user-scope server the integration registered.
125
+ */
126
+ readonly mcpConfigPath?: string | undefined;
127
+ }
128
+ /**
129
+ * The deny paths no rule can carry: on Windows all of them (the rule syntax
130
+ * for drive paths is undocumented), elsewhere a relative path or one with a
131
+ * comma or whitespace. A run would be able to read these.
132
+ */
133
+ declare function inexpressibleDenyPaths(paths: readonly string[]): string[];
134
+ /** `/Users/x/.claude/agentchat` → `Read(//Users/x/.claude/agentchat/**)` and `Read(//Users/x/.claude/agentchat)`. Paths no rule can carry are left out (`inexpressibleDenyPaths`). */
135
+ declare function readDenyRules(paths: readonly string[]): string[];
136
+ /**
137
+ * The full argument list for one headless run. The prompt goes on STDIN, not
138
+ * as a positional: the variadic `--allowedTools` (and `--mcp-config`) would
139
+ * otherwise swallow a trailing positional (verified on 2.1.220; `cat file |
140
+ * claude -p` is the documented piped form).
141
+ */
142
+ declare function claudeRunArgs(profile: RunProfile, options?: ClaudeRunArgOptions): string[];
143
+ /** The `--mcp-config` document: the hosted server, by HTTP, with the agent's key. Owner-only on disk. */
144
+ /**
145
+ * The `--mcp-config` file a listener's run is given: the hosted tool server
146
+ * with this agent's key, and the client headers that name the runtime to it
147
+ * (`X-AgentChat-Client: claude-code`, `-Version`: the front door that placed
148
+ * the run). The hosted tool server names a client only from these headers:
149
+ * without them a run is an unknown client and is shown the wake-webhook
150
+ * tools, a second way of being woken that the listener makes unnecessary.
151
+ */
152
+ declare function claudeMcpConfig(apiBase: string, apiKey: string, clientVersion?: string): string;
153
+ interface ClaudeRunnerOptions {
154
+ readonly configDir: string | undefined;
155
+ /**
156
+ * The run's working directory; the `work` profile edits and runs shell here.
157
+ * Must lie outside `denyReadPaths`, or the run cannot read its own cwd —
158
+ * preflight says so once and still runs.
159
+ */
160
+ readonly workdir: string;
161
+ readonly profile: RunProfile;
162
+ /** Paths every run's file tools are denied: the key store (identity home, the user-scope MCP state). */
163
+ readonly denyReadPaths: readonly string[];
164
+ /** See `ClaudeRunArgOptions.mcpConfigPath`. */
165
+ readonly mcpConfigPath?: string;
166
+ /** The one-line fix printed when the workdir sits inside a denied path. */
167
+ readonly workdirAdvice?: string;
168
+ /**
169
+ * A deny path no rule can carry (a comma or whitespace in it; every path on
170
+ * Windows): `warn` (default) logs it once and runs — the run can then read
171
+ * that path; `refuse` fails preflight with the reason, so no run starts.
172
+ */
173
+ readonly inexpressibleDeny?: 'warn' | 'refuse';
174
+ /** Test seam: the binary to run. */
175
+ readonly command?: string;
176
+ readonly env?: NodeJS.ProcessEnv;
177
+ }
178
+ declare class ClaudeRunner implements RunRunner {
179
+ private readonly options;
180
+ readonly name = "claude";
181
+ private readonly command;
182
+ /** The workdir warning is one line per process, not one per preflight (preflight repeats every few minutes). */
183
+ private warnedWorkdir;
184
+ private warnedDeny;
185
+ constructor(options: ClaudeRunnerOptions);
186
+ /** The denied path the configured workdir sits in, or null when the run can read its own cwd. */
187
+ workdirDeniedBy(): string | null;
188
+ preflight(): Promise<RunPreflight>;
189
+ /** The exact argv one run uses — exported for tests to pin per profile. */
190
+ args(): string[];
191
+ start(request: RunRequest): Promise<RunOutcome>;
192
+ }
193
+ /** Where a listener keeps the `--mcp-config` file for this preset, inside its identity home. */
194
+ declare function claudeMcpConfigPath(home: string): string;
195
+ declare const claudeCodePreset: Preset;
196
+
197
+ declare const CODEX_PRESET = "codex";
198
+ /** `--ephemeral`, `--sandbox`, `-C`, `--json` all exist on this version; older builds were not checked. */
199
+ declare const MIN_CODEX_VERSION = "0.154.0";
200
+ /** The `[mcp_servers.<name>]` table the runs use; tools are `mcp__agentchat__<tool>`, as the served texts spell them. */
201
+ declare const CODEX_MCP_SERVER_NAME = "agentchat";
202
+ /**
203
+ * The variable a listener's runs read the bearer token from. Deliberately not
204
+ * `AGENTCHAT_API_KEY`: Codex loads `$CODEX_HOME/.env` at startup, where an
205
+ * installed integration keeps ITS agent's key under that name.
206
+ */
207
+ declare const LISTENER_KEY_ENV = "AGENTCHAT_LISTENER_API_KEY";
208
+ /**
209
+ * The final positional argument: `-` tells `codex exec` to read its
210
+ * instructions from stdin ("If not provided as an argument (or if `-` is
211
+ * used), instructions are read from stdin").
212
+ */
213
+ declare const CODEX_PROMPT_FROM_STDIN = "-";
214
+ /** Codex's config root. Honouring CODEX_HOME matters: users relocate it. */
215
+ declare function codexHomeFrom(env?: NodeJS.ProcessEnv): string;
216
+ declare function inspectCodexRuntime(codexHome: string, command?: string): PresetInspection;
217
+ /** `codex login status` exits 0 when signed in. */
218
+ declare function codexIsLoggedIn(codexHome: string, command?: string): PresetInspection;
219
+ declare function codexProfileArgs(profile: RunProfile): string[];
220
+ /** Where a run's hosted tool server points, and which variable carries its bearer token. */
221
+ interface CodexMcpOverride {
222
+ readonly url: string;
223
+ readonly keyEnv: string;
224
+ /** The version named in `X-AgentChat-Client-Version` (the front door that placed the run). Defaults to this engine's. */
225
+ readonly clientVersion?: string;
226
+ }
227
+ /**
228
+ * `{"X-AgentChat-Client" = "codex", "X-AgentChat-Client-Version" = "<version>"}`:
229
+ * the client headers that name the runtime to the hosted tool server, as a
230
+ * TOML inline table for `-c …http_headers=`. Codex parses a `-c` value as
231
+ * TOML (inline tables included) since before 0.154.0, and sends
232
+ * `http_headers` on every request to a streamable-HTTP server. Without them
233
+ * a run is an unknown client and is shown the wake-webhook tools.
234
+ */
235
+ declare function codexClientHeadersToml(clientVersion?: string): string;
236
+ /** The `-c` overrides that make `[mcp_servers.agentchat]` this agent's, for one run. TOML values, no key in them. */
237
+ declare function codexMcpOverrideArgs(override: CodexMcpOverride): string[];
238
+ /**
239
+ * The full argument list for one headless run. The prompt is NOT an argument:
240
+ * the runner writes it to stdin and closes it. An argument cannot carry it on
241
+ * Windows — npm installs codex as a `.cmd` shim, cross-spawn runs that through
242
+ * cmd.exe, and cmd.exe ends the command at the first line break, so every line
243
+ * after the first was silently dropped (caught by CI on windows-latest).
244
+ */
245
+ declare function codexRunArgs(profile: RunProfile, options: {
246
+ workdir: string;
247
+ mcp?: CodexMcpOverride;
248
+ }): string[];
249
+ interface CodexRunnerOptions {
250
+ readonly codexHome: string;
251
+ /** The run's working root (`-C`); the `work` profile may write here. */
252
+ readonly workdir: string;
253
+ readonly profile: RunProfile;
254
+ /** The agent's key, read per run (a credential change between runs is followed). Null: none is set. */
255
+ readonly apiKey: () => string | null;
256
+ /** The variable the key is set under in the run's environment. */
257
+ readonly keyEnv: string;
258
+ /** Point the hosted server at this agent for each run (`-c` overrides); absent, config.toml decides. */
259
+ readonly mcp?: CodexMcpOverride;
260
+ /** Test seam: the binary to run. */
261
+ readonly command?: string;
262
+ readonly env?: NodeJS.ProcessEnv;
263
+ }
264
+ declare class CodexRunner implements RunRunner {
265
+ private readonly options;
266
+ readonly name = "codex";
267
+ private readonly command;
268
+ constructor(options: CodexRunnerOptions);
269
+ preflight(): Promise<RunPreflight>;
270
+ /** The exact argv one run uses — exported for tests to pin per profile. */
271
+ args(): string[];
272
+ /** The child environment: Codex's home and the key the hosted server needs, under the configured name. */
273
+ env(): NodeJS.ProcessEnv;
274
+ start(request: RunRequest): Promise<RunOutcome>;
275
+ }
276
+ /**
277
+ * The keys of `[mcp_servers.agentchat]` in a config.toml, or null when the
278
+ * table is absent. Keys only — a value can be a secret. A line scan, not a
279
+ * TOML parser: enough to say what a run's `-c` overrides merge over.
280
+ */
281
+ declare function agentchatTableKeys(configToml: string): string[] | null;
282
+ declare const codexPreset: Preset;
283
+
284
+ /** Every preset, by the name a user types. */
285
+ declare const PRESETS: Readonly<Record<string, Preset>>;
286
+ declare function presetNamed(name: string): Preset | null;
287
+ declare function presetNames(): string[];
288
+
289
+ export { AGENTCHAT_TOOL_ALLOW, ANSWER_TOOLS, CLAUDE_CODE_PRESET, CLAUDE_MCP_SERVER_NAME, CODEX_MCP_SERVER_NAME, CODEX_PRESET, CODEX_PROMPT_FROM_STDIN, type ClaudeRunArgOptions, ClaudeRunner, type ClaudeRunnerOptions, type CodexMcpOverride, CodexRunner, type CodexRunnerOptions, LISTENER_KEY_ENV, MIN_CLAUDE_CODE_VERSION, MIN_CODEX_VERSION, PARENT_ENV_KEYS, PRESETS, type Preset, type PresetContext, type PresetInspection, WORK_TOOLS, agentchatTableKeys, buildClaudeEnv, claudeCodePreset, claudeConfigDirFrom, claudeHomeFor, claudeIsLoggedIn, claudeMcpConfig, claudeMcpConfigPath, claudeProfileArgs, claudeRunArgs, claudeUserStatePathFor, codexClientHeadersToml, codexHomeFrom, codexIsLoggedIn, codexMcpOverrideArgs, codexPreset, codexProfileArgs, codexRunArgs, deniedAncestorOf, inexpressibleDenyPaths, inspectClaudeRuntime, inspectCodexRuntime, presetNamed, presetNames, readDenyRules, semverAtLeast };