@agentchatme/agent-core 0.6.0 → 0.7.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/README.md +48 -6
- package/dist/{chunk-AVLI55C5.js → chunk-C2ARQLZ7.js} +26 -4
- package/dist/chunk-C2ARQLZ7.js.map +1 -0
- package/dist/{chunk-EDB33Z22.js → chunk-NYSMAN4N.js} +201 -48
- package/dist/chunk-NYSMAN4N.js.map +1 -0
- package/dist/{chunk-QUANHUVW.js → chunk-PTKQIKCI.js} +3 -3
- package/dist/{chunk-QUANHUVW.js.map → chunk-PTKQIKCI.js.map} +1 -1
- package/dist/daemon-entry.d.ts +55 -5
- package/dist/daemon-entry.js +148 -12
- package/dist/daemon-entry.js.map +1 -1
- package/dist/index.d.ts +45 -5
- package/dist/index.js +65 -3
- package/dist/index.js.map +1 -1
- package/dist/presets.d.ts +99 -2
- package/dist/presets.js +184 -18
- package/dist/presets.js.map +1 -1
- package/dist/{runner-C9kZD3KH.d.ts → runner-BjCgl4bV.d.ts} +34 -2
- package/dist/{served-manual-CawJYdzJ.d.ts → served-manual-RAIaRcr2.d.ts} +88 -2
- package/package.json +2 -2
- package/dist/chunk-AVLI55C5.js.map +0 -1
- package/dist/chunk-EDB33Z22.js.map +0 -1
package/dist/presets.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TextsRuntime } from 'agentchatme';
|
|
2
|
-
import { a as RunProfile, b as RunRunner,
|
|
2
|
+
import { a as RunProfile, b as RunRunner, f as RunPreflight, q as RunPreflightOptions, g as RunRequest, c as RunOutcome } from './runner-BjCgl4bV.js';
|
|
3
3
|
|
|
4
4
|
/** What a preset needs to build a runner acting as one agent. */
|
|
5
5
|
interface PresetContext {
|
|
@@ -115,6 +115,48 @@ declare function withoutParentSession(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv
|
|
|
115
115
|
/** `actual` (any text containing `x.y.z`) is at least `minimum`. False when either has no version in it. */
|
|
116
116
|
declare function semverAtLeast(actual: string, minimum: string): boolean;
|
|
117
117
|
|
|
118
|
+
/** The fixed prompt: nothing from any peer, nothing to act on. */
|
|
119
|
+
declare const RUNTIME_CHECK_PROMPT = "Reply with the single word OK.";
|
|
120
|
+
/**
|
|
121
|
+
* The check's own budget. Past it the probe is SIGTERMed, SIGKILLed 5 s later
|
|
122
|
+
* and given up 5 s after that: 55 s at most, inside the engine's
|
|
123
|
+
* `RUNTIME_CHECK_DEADLINE_MS` (60 s).
|
|
124
|
+
*/
|
|
125
|
+
declare const RUNTIME_CHECK_BUDGET_MS = 45000;
|
|
126
|
+
/** The most of a check's stdout kept for its `judge` (a result line is a few kB); more is not read. */
|
|
127
|
+
declare const RUNTIME_CHECK_OUTPUT_BYTES: number;
|
|
128
|
+
/** The name of the empty folder a runtime check runs in, beside the runtime's own config. */
|
|
129
|
+
declare const RUNTIME_CHECK_DIR = "agentchat-runtime-check";
|
|
130
|
+
/**
|
|
131
|
+
* The variables an AgentChat key travels in (the daemon's own, the listener's
|
|
132
|
+
* Codex bearer variable): never in a runtime check's environment, whatever
|
|
133
|
+
* the runs carry. The check needs no key.
|
|
134
|
+
*/
|
|
135
|
+
declare const RUNTIME_CHECK_KEY_ENV: readonly string[];
|
|
136
|
+
interface RuntimeCheckSpec {
|
|
137
|
+
/** The runtime's name, for the diagnostic. */
|
|
138
|
+
readonly label: string;
|
|
139
|
+
readonly command: string;
|
|
140
|
+
readonly args: readonly string[];
|
|
141
|
+
/** An empty folder of the check's own (created owner-only). */
|
|
142
|
+
readonly cwd: string;
|
|
143
|
+
/** The runs' environment; the key variables are taken out (`RUNTIME_CHECK_KEY_ENV`, `keyEnv`). */
|
|
144
|
+
readonly env: NodeJS.ProcessEnv;
|
|
145
|
+
/** Another variable this runtime's runs carry a key in (a Codex runner's `keyEnv`). */
|
|
146
|
+
readonly keyEnv?: string;
|
|
147
|
+
readonly signal?: AbortSignal;
|
|
148
|
+
/**
|
|
149
|
+
* Reads the runtime's answer (its stdout, bounded) after an exit 0: null
|
|
150
|
+
* when it is a good answer, else why not (ids and flags only, never the
|
|
151
|
+
* text). Absent: exit 0 with something on stdout is ok.
|
|
152
|
+
*/
|
|
153
|
+
readonly judge?: (stdout: string) => string | null;
|
|
154
|
+
/** Test seam: `RUNTIME_CHECK_BUDGET_MS`. */
|
|
155
|
+
readonly budgetMs?: number;
|
|
156
|
+
}
|
|
157
|
+
/** Run the check once: ok when the runtime exited 0 having printed an answer. Never throws. */
|
|
158
|
+
declare function runRuntimeCheck(spec: RuntimeCheckSpec): Promise<RunPreflight>;
|
|
159
|
+
|
|
118
160
|
declare const CLAUDE_CODE_PRESET = "claude-code";
|
|
119
161
|
/**
|
|
120
162
|
* Two flags set the floor:
|
|
@@ -260,6 +302,30 @@ interface ClaudeRunArgOptions {
|
|
|
260
302
|
*/
|
|
261
303
|
readonly appendSystemPromptFile?: string | undefined;
|
|
262
304
|
}
|
|
305
|
+
/**
|
|
306
|
+
* The `--settings` a runtime check is given: no hook of the user's (or a
|
|
307
|
+
* workdir repository's) fires on a health check, and the two `ANSWER_ENV`
|
|
308
|
+
* switches again (a settings file's `env` overrides the process environment;
|
|
309
|
+
* `--settings` outranks user, project and local settings). A constant
|
|
310
|
+
* (`claude --help`: a settings value that fails validation is silently ignored
|
|
311
|
+
* in print mode). Every key exists at the 2.1.274 floor.
|
|
312
|
+
*/
|
|
313
|
+
declare const RUNTIME_CHECK_SETTINGS: string;
|
|
314
|
+
/**
|
|
315
|
+
* Whether a runtime check's stdout (`--output-format json`) is a good answer:
|
|
316
|
+
* null when it is one result object with `type: "result"`, `subtype:
|
|
317
|
+
* "success"` and `is_error: false`; otherwise why not, in ids and flags only
|
|
318
|
+
* (`is_error`, `api_error_status`, `terminal_reason`), never the result text.
|
|
319
|
+
*/
|
|
320
|
+
declare function claudeRuntimeCheckJudge(stdout: string): string | null;
|
|
321
|
+
/**
|
|
322
|
+
* The argv of a runtime check: one `claude -p` with no tool of any kind (no
|
|
323
|
+
* MCP server, no built-in tool), no hooks, never waiting on a prompt; the
|
|
324
|
+
* prompt on stdin, as for a run. `denyReadPaths` are the runs' own deny rules.
|
|
325
|
+
*/
|
|
326
|
+
declare function claudeRuntimeCheckArgs(denyReadPaths?: readonly string[]): string[];
|
|
327
|
+
/** The empty folder a runtime check runs in: beside Claude Code's config, outside every denied path. */
|
|
328
|
+
declare function claudeRuntimeCheckWorkdir(configDirOverride: string | undefined): string;
|
|
263
329
|
/**
|
|
264
330
|
* The deny paths no rule can carry: on Windows all of them (the rule syntax
|
|
265
331
|
* for drive paths is undocumented), elsewhere a relative path or one with a
|
|
@@ -429,6 +495,15 @@ declare class ClaudeRunner implements RunRunner {
|
|
|
429
495
|
* hosted tools through its MCP entry, never through that variable.
|
|
430
496
|
*/
|
|
431
497
|
runEnv(): NodeJS.ProcessEnv;
|
|
498
|
+
/**
|
|
499
|
+
* Does the model answer right now, through this runner's binary, sign-in
|
|
500
|
+
* and environment? One `claude -p` with a fixed prompt and no tool at all
|
|
501
|
+
* (`claudeRuntimeCheckArgs`), in its own empty folder, with no key in its
|
|
502
|
+
* environment and no instruction file or memory in its context; ok only
|
|
503
|
+
* when its JSON result says success with no error (`claudeRuntimeCheckJudge`).
|
|
504
|
+
* Its output is read for that alone and never logged. Never throws.
|
|
505
|
+
*/
|
|
506
|
+
checkRuntime(options?: RunPreflightOptions): Promise<RunPreflight>;
|
|
432
507
|
start(request: RunRequest): Promise<RunOutcome>;
|
|
433
508
|
}
|
|
434
509
|
/** Where a listener keeps the `--mcp-config` file for this preset, inside its identity home. */
|
|
@@ -470,6 +545,20 @@ declare const CODEX_ANSWER_FILESYSTEM = "{ \":workspace_roots\" = \"read\" }";
|
|
|
470
545
|
*/
|
|
471
546
|
declare const CODEX_ANSWER_DISABLED_FEATURES: readonly ["shell_tool", "view_image", "image_generation", "plugins", "apps", "memories", "browser_use", "browser_use_external", "computer_use", "in_app_browser"];
|
|
472
547
|
declare function codexProfileArgs(profile: RunProfile): string[];
|
|
548
|
+
/** The features a runtime check turns off, as an `answer` run does (names at the 0.154.0 floor). */
|
|
549
|
+
declare const CODEX_RUNTIME_CHECK_DISABLED_FEATURES: readonly ["memories", "plugins", "apps"];
|
|
550
|
+
/**
|
|
551
|
+
* The argv of a runtime check: `codex exec` in `dir` (an empty folder), the
|
|
552
|
+
* read-only sandbox, no session files, low reasoning effort, no web search,
|
|
553
|
+
* memories, plugins or connectors, and the hosted AgentChat server switched
|
|
554
|
+
* off for it; the prompt on stdin, as for a run. `agentchatUrl` is the URL the
|
|
555
|
+
* runs pin (with it, the `agentchat` table stays valid whether or not a config
|
|
556
|
+
* layer defines one); without it a config layer must define the table, as the
|
|
557
|
+
* runs need.
|
|
558
|
+
*/
|
|
559
|
+
declare function codexRuntimeCheckArgs(dir: string, agentchatUrl?: string): string[];
|
|
560
|
+
/** The empty folder a runtime check runs in, under CODEX_HOME. */
|
|
561
|
+
declare function codexRuntimeCheckWorkdir(codexHome: string): string;
|
|
473
562
|
/** Where a run's hosted tool server points, and which variable carries its bearer token. */
|
|
474
563
|
interface CodexMcpOverride {
|
|
475
564
|
readonly url: string;
|
|
@@ -679,6 +768,14 @@ declare class CodexRunner implements RunRunner {
|
|
|
679
768
|
private listingFlags;
|
|
680
769
|
/** `codex mcp list --json <flags>` from the run's workdir, with the run's environment: its output, or why there is none. Killed with its whole tree past its time. */
|
|
681
770
|
private listMcpServers;
|
|
771
|
+
/**
|
|
772
|
+
* Does the model answer right now, through this runner's binary, sign-in,
|
|
773
|
+
* CODEX_HOME and environment? One `codex exec` with a fixed prompt in its
|
|
774
|
+
* own empty folder, read-only, with the hosted AgentChat server switched off
|
|
775
|
+
* (`codexRuntimeCheckArgs`) and no key in its environment. Its output is
|
|
776
|
+
* discarded. Never throws.
|
|
777
|
+
*/
|
|
778
|
+
checkRuntime(options?: RunPreflightOptions): Promise<RunPreflight>;
|
|
682
779
|
start(request: RunRequest): Promise<RunOutcome>;
|
|
683
780
|
}
|
|
684
781
|
/** Where a listener's `own` runs' headers helper lives: `<home>/presets/codex.mcp-headers.mjs` (owner-only; it holds no key). */
|
|
@@ -711,4 +808,4 @@ declare const PRESETS: Readonly<Record<string, Preset>>;
|
|
|
711
808
|
declare function presetNamed(name: string): Preset | null;
|
|
712
809
|
declare function presetNames(): string[];
|
|
713
810
|
|
|
714
|
-
export { AGENTCHAT_TOOL_ALLOW, ANSWER_DENIED_TOOLS, ANSWER_ENV, ANSWER_SETTINGS, ANSWER_TOOLS, CLAUDE_CODE_ENV_KEPT, CLAUDE_CODE_PRESET, CLAUDE_MCP_SERVER_NAME, CLAUDE_SESSION_ENV, CODEX_ANSWER_DISABLED_FEATURES, CODEX_ANSWER_FILESYSTEM, CODEX_ANSWER_PERMISSIONS, CODEX_LISTENER_HEADERS_HELPER_SOURCE, CODEX_MANAGED_PROXY_ENV, CODEX_MCP_LIST_MAX_AGE_MS, CODEX_MCP_LIST_TIMEOUT_MS, CODEX_MCP_SERVER_NAME, CODEX_PRESET, CODEX_PROBE_TIMEOUT_MS, CODEX_PROMPT_FROM_STDIN, CODEX_SESSION_ENV, type ClaudeAnswerMcp, type ClaudeRunArgOptions, ClaudeRunner, type ClaudeRunnerOptions, type ClaudeSignIn, type CodexMcpOverride, CodexRunner, type CodexRunnerOptions, LISTENER_KEY_ENV, MIN_CLAUDE_CODE_VERSION, MIN_CODEX_VERSION, PARENT_ENV_KEYS, PRESETS, PROBE_TIMEOUT_MS, type Preset, type PresetContext, type PresetInspection, WEB_TOOLS, WORK_TOOLS, agentchatTableKeys, buildClaudeEnv, claudeAnswerFallbackWorkdir, claudeCodePreset, claudeConfigDirFrom, claudeExtraDirectoriesGrant, claudeHomeFor, claudeIsLoggedIn, claudeManagedSettingsDir, claudeMcpConfig, claudeMcpConfigPath, claudeProfileArgs, claudeProjectsDirFor, claudeRunArgs, claudeSettingsFilesGrantingDirectories, claudeSignIn, claudeUserStatePathFor, codexAgentchatExplicitAuth, codexAnswerFallbackWorkdir, codexClientHeadersToml, codexConfigLayerFiles, codexDotEnvKeyNames, codexHeadersHelperCommand, codexHomeFrom, codexIsLoggedIn, codexListenerHeadersHelperPath, codexMcpDisableArgs, codexMcpOverrideArgs, codexPinnedUrlArgs, codexPreset, codexProfileArgs, codexRunArgs, codexServerNameAddressable, deniedAncestorOf, inexpressibleDenyPaths, inspectClaudeRuntime, inspectCodexRuntime, isParentSessionEnv, parseCodexMcpList, presetNamed, presetNames, readDenyRules, semverAtLeast, withoutParentSession, workdirPaths, workdirReadRules };
|
|
811
|
+
export { AGENTCHAT_TOOL_ALLOW, ANSWER_DENIED_TOOLS, ANSWER_ENV, ANSWER_SETTINGS, ANSWER_TOOLS, CLAUDE_CODE_ENV_KEPT, CLAUDE_CODE_PRESET, CLAUDE_MCP_SERVER_NAME, CLAUDE_SESSION_ENV, CODEX_ANSWER_DISABLED_FEATURES, CODEX_ANSWER_FILESYSTEM, CODEX_ANSWER_PERMISSIONS, CODEX_LISTENER_HEADERS_HELPER_SOURCE, CODEX_MANAGED_PROXY_ENV, CODEX_MCP_LIST_MAX_AGE_MS, CODEX_MCP_LIST_TIMEOUT_MS, CODEX_MCP_SERVER_NAME, CODEX_PRESET, CODEX_PROBE_TIMEOUT_MS, CODEX_PROMPT_FROM_STDIN, CODEX_RUNTIME_CHECK_DISABLED_FEATURES, CODEX_SESSION_ENV, type ClaudeAnswerMcp, type ClaudeRunArgOptions, ClaudeRunner, type ClaudeRunnerOptions, type ClaudeSignIn, type CodexMcpOverride, CodexRunner, type CodexRunnerOptions, LISTENER_KEY_ENV, MIN_CLAUDE_CODE_VERSION, MIN_CODEX_VERSION, PARENT_ENV_KEYS, PRESETS, PROBE_TIMEOUT_MS, type Preset, type PresetContext, type PresetInspection, RUNTIME_CHECK_BUDGET_MS, RUNTIME_CHECK_DIR, RUNTIME_CHECK_KEY_ENV, RUNTIME_CHECK_OUTPUT_BYTES, RUNTIME_CHECK_PROMPT, RUNTIME_CHECK_SETTINGS, type RuntimeCheckSpec, WEB_TOOLS, WORK_TOOLS, agentchatTableKeys, buildClaudeEnv, claudeAnswerFallbackWorkdir, claudeCodePreset, claudeConfigDirFrom, claudeExtraDirectoriesGrant, claudeHomeFor, claudeIsLoggedIn, claudeManagedSettingsDir, claudeMcpConfig, claudeMcpConfigPath, claudeProfileArgs, claudeProjectsDirFor, claudeRunArgs, claudeRuntimeCheckArgs, claudeRuntimeCheckJudge, claudeRuntimeCheckWorkdir, claudeSettingsFilesGrantingDirectories, claudeSignIn, claudeUserStatePathFor, codexAgentchatExplicitAuth, codexAnswerFallbackWorkdir, codexClientHeadersToml, codexConfigLayerFiles, codexDotEnvKeyNames, codexHeadersHelperCommand, codexHomeFrom, codexIsLoggedIn, codexListenerHeadersHelperPath, codexMcpDisableArgs, codexMcpOverrideArgs, codexPinnedUrlArgs, codexPreset, codexProfileArgs, codexRunArgs, codexRuntimeCheckArgs, codexRuntimeCheckWorkdir, codexServerNameAddressable, deniedAncestorOf, inexpressibleDenyPaths, inspectClaudeRuntime, inspectCodexRuntime, isParentSessionEnv, parseCodexMcpList, presetNamed, presetNames, readDenyRules, runRuntimeCheck, semverAtLeast, withoutParentSession, workdirPaths, workdirReadRules };
|
package/dist/presets.js
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
VERSION,
|
|
3
3
|
hostedMcpUrl,
|
|
4
4
|
runProbe
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-PTKQIKCI.js";
|
|
6
6
|
import {
|
|
7
7
|
atomicWriteFile,
|
|
8
8
|
clientHeadersOf,
|
|
@@ -11,11 +11,12 @@ import {
|
|
|
11
11
|
redactDiagnostic,
|
|
12
12
|
spawnCommand,
|
|
13
13
|
spawnRun,
|
|
14
|
+
spawnRunCapturing,
|
|
14
15
|
workdirExposesHome
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-C2ARQLZ7.js";
|
|
16
17
|
|
|
17
18
|
// src/presets/claude-code.ts
|
|
18
|
-
import * as
|
|
19
|
+
import * as fs2 from "fs";
|
|
19
20
|
import * as os from "os";
|
|
20
21
|
import * as path from "path";
|
|
21
22
|
|
|
@@ -34,6 +35,41 @@ function semverAtLeast(actual, minimum) {
|
|
|
34
35
|
return true;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
// src/presets/runtime-check.ts
|
|
39
|
+
import * as fs from "fs";
|
|
40
|
+
var RUNTIME_CHECK_PROMPT = "Reply with the single word OK.";
|
|
41
|
+
var RUNTIME_CHECK_BUDGET_MS = 45e3;
|
|
42
|
+
var RUNTIME_CHECK_OUTPUT_BYTES = 128 * 1024;
|
|
43
|
+
var RUNTIME_CHECK_DIR = "agentchat-runtime-check";
|
|
44
|
+
var RUNTIME_CHECK_KEY_ENV = ["AGENTCHAT_API_KEY", "AGENTCHAT_LISTENER_API_KEY"];
|
|
45
|
+
function withoutKeys(env, also) {
|
|
46
|
+
const names = new Set([...RUNTIME_CHECK_KEY_ENV, ...also].map((name) => name.toUpperCase()));
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const [key, value] of Object.entries(env)) if (!names.has(key.toUpperCase())) out[key] = value;
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
async function runRuntimeCheck(spec) {
|
|
52
|
+
if (spec.signal?.aborted === true) return { ok: false, detail: `${spec.label} runtime check: stopped before it started` };
|
|
53
|
+
try {
|
|
54
|
+
fs.mkdirSync(spec.cwd, { recursive: true, mode: 448 });
|
|
55
|
+
} catch (err) {
|
|
56
|
+
return { ok: false, detail: `${spec.label} runtime check: could not create its folder ${spec.cwd}: ${err instanceof Error ? err.message : String(err)}` };
|
|
57
|
+
}
|
|
58
|
+
const { outcome, stdout } = await spawnRunCapturing({
|
|
59
|
+
command: spec.command,
|
|
60
|
+
args: spec.args,
|
|
61
|
+
cwd: spec.cwd,
|
|
62
|
+
env: withoutKeys(spec.env, spec.keyEnv !== void 0 ? [spec.keyEnv] : []),
|
|
63
|
+
stdin: RUNTIME_CHECK_PROMPT,
|
|
64
|
+
budgetMs: spec.budgetMs ?? RUNTIME_CHECK_BUDGET_MS,
|
|
65
|
+
requireStdout: true,
|
|
66
|
+
...spec.signal !== void 0 ? { signal: spec.signal } : {}
|
|
67
|
+
}, spec.judge !== void 0 ? RUNTIME_CHECK_OUTPUT_BYTES : 0);
|
|
68
|
+
if (outcome.state !== "ok") return { ok: false, detail: `${spec.label} runtime check ${outcome.state.replace("_", " ")}${outcome.detail ? `: ${outcome.detail}` : ""}` };
|
|
69
|
+
const verdict = spec.judge === void 0 ? null : spec.judge(stdout);
|
|
70
|
+
return verdict === null ? { ok: true } : { ok: false, detail: `${spec.label} runtime check failed: exit 0, but ${verdict}` };
|
|
71
|
+
}
|
|
72
|
+
|
|
37
73
|
// src/presets/types.ts
|
|
38
74
|
var CLAUDE_CODE_ENV_KEPT = [
|
|
39
75
|
// Sign-in and provider
|
|
@@ -249,7 +285,7 @@ async function claudeSignIn(configDirOverride, command = "claude", timeoutMs = P
|
|
|
249
285
|
if (status.status === 0) return { signedIn: true, unanswered: null };
|
|
250
286
|
}
|
|
251
287
|
const configDir = claudeHomeFor(configDirOverride);
|
|
252
|
-
if (
|
|
288
|
+
if (fs2.existsSync(path.join(configDir, ".credentials.json"))) return { signedIn: true, unanswered: null };
|
|
253
289
|
if (process.platform !== "darwin") return { signedIn: false, unanswered: null };
|
|
254
290
|
const keychain = await runProbe("security", ["find-generic-password", "-s", "Claude Code-credentials"], { timeoutMs: Math.min(timeoutMs, 5e3), ...signal !== void 0 ? { signal } : {} });
|
|
255
291
|
return { signedIn: !keychain.error && keychain.status === 0, unanswered: null };
|
|
@@ -284,7 +320,7 @@ function workdirPaths(workdir) {
|
|
|
284
320
|
const given = path.resolve(workdir);
|
|
285
321
|
let real = given;
|
|
286
322
|
try {
|
|
287
|
-
real =
|
|
323
|
+
real = fs2.realpathSync(given);
|
|
288
324
|
} catch {
|
|
289
325
|
}
|
|
290
326
|
return real === given ? [given] : [given, real];
|
|
@@ -333,6 +369,55 @@ function claudeProfileArgs(profile, workdir) {
|
|
|
333
369
|
return ["--dangerously-skip-permissions", "--permission-prompts", "none", "--allowedTools", AGENTCHAT_TOOL_ALLOW];
|
|
334
370
|
}
|
|
335
371
|
}
|
|
372
|
+
var RUNTIME_CHECK_SETTINGS = JSON.stringify({
|
|
373
|
+
env: { CLAUDE_CODE_DISABLE_CLAUDE_MDS: "1", CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" },
|
|
374
|
+
disableAllHooks: true
|
|
375
|
+
});
|
|
376
|
+
function claudeRuntimeCheckJudge(stdout) {
|
|
377
|
+
const text = stdout.trim();
|
|
378
|
+
let parsed = null;
|
|
379
|
+
for (const candidate of [text, text.split(/\r?\n/).filter((line) => line.trim().length > 0).at(-1) ?? ""]) {
|
|
380
|
+
try {
|
|
381
|
+
parsed = JSON.parse(candidate);
|
|
382
|
+
break;
|
|
383
|
+
} catch {
|
|
384
|
+
parsed = null;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return "its answer is not a JSON result";
|
|
388
|
+
const r = parsed;
|
|
389
|
+
if (r["type"] === "result" && r["subtype"] === "success" && r["is_error"] === false) return null;
|
|
390
|
+
const facts = [
|
|
391
|
+
`type ${typeof r["type"] === "string" ? r["type"] : "?"}`,
|
|
392
|
+
`subtype ${typeof r["subtype"] === "string" ? r["subtype"] : "?"}`,
|
|
393
|
+
`is_error ${typeof r["is_error"] === "boolean" ? String(r["is_error"]) : "?"}`,
|
|
394
|
+
...typeof r["api_error_status"] === "number" ? [`api_error_status ${r["api_error_status"]}`] : [],
|
|
395
|
+
...typeof r["terminal_reason"] === "string" && /^[a-z_]{1,40}$/.test(r["terminal_reason"]) ? [`terminal_reason ${r["terminal_reason"]}`] : []
|
|
396
|
+
];
|
|
397
|
+
return `the result is not a success (${facts.join(", ")})`;
|
|
398
|
+
}
|
|
399
|
+
function claudeRuntimeCheckArgs(denyReadPaths = []) {
|
|
400
|
+
const deny = readDenyRules(denyReadPaths);
|
|
401
|
+
return [
|
|
402
|
+
"-p",
|
|
403
|
+
"--output-format",
|
|
404
|
+
"json",
|
|
405
|
+
"--no-session-persistence",
|
|
406
|
+
// No --mcp-config: with this flag, no MCP server loads at all.
|
|
407
|
+
"--strict-mcp-config",
|
|
408
|
+
// Variadic; "" is none (`claude --help`). Closed by the option after it.
|
|
409
|
+
"--tools",
|
|
410
|
+
"",
|
|
411
|
+
"--permission-prompts",
|
|
412
|
+
"none",
|
|
413
|
+
"--settings",
|
|
414
|
+
RUNTIME_CHECK_SETTINGS,
|
|
415
|
+
...deny.length > 0 ? ["--disallowedTools", deny.join(",")] : []
|
|
416
|
+
];
|
|
417
|
+
}
|
|
418
|
+
function claudeRuntimeCheckWorkdir(configDirOverride) {
|
|
419
|
+
return path.join(claudeHomeFor(configDirOverride), RUNTIME_CHECK_DIR);
|
|
420
|
+
}
|
|
336
421
|
function expressible(raw) {
|
|
337
422
|
return raw.startsWith("/") && !/[,\s]/.test(raw);
|
|
338
423
|
}
|
|
@@ -387,7 +472,7 @@ function claudeManagedSettingsDir(platform = process.platform) {
|
|
|
387
472
|
function gitRootOf(dir) {
|
|
388
473
|
let current = path.resolve(dir);
|
|
389
474
|
for (; ; ) {
|
|
390
|
-
if (
|
|
475
|
+
if (fs2.existsSync(path.join(current, ".git"))) return current;
|
|
391
476
|
const parent = path.dirname(current);
|
|
392
477
|
if (parent === current) return null;
|
|
393
478
|
current = parent;
|
|
@@ -397,7 +482,7 @@ function claudeSettingsFilesGrantingDirectories(configDirOverride, workdir) {
|
|
|
397
482
|
const managed = claudeManagedSettingsDir();
|
|
398
483
|
const dropIns = (() => {
|
|
399
484
|
try {
|
|
400
|
-
return
|
|
485
|
+
return fs2.readdirSync(path.join(managed, "managed-settings.d")).filter((name) => name.endsWith(".json") && !name.startsWith(".")).sort().map((name) => path.join(managed, "managed-settings.d", name));
|
|
401
486
|
} catch {
|
|
402
487
|
return [];
|
|
403
488
|
}
|
|
@@ -416,7 +501,7 @@ function claudeExtraDirectoriesGrant(configDirOverride, workdir) {
|
|
|
416
501
|
for (const file of claudeSettingsFilesGrantingDirectories(configDirOverride, workdir)) {
|
|
417
502
|
let text;
|
|
418
503
|
try {
|
|
419
|
-
text =
|
|
504
|
+
text = fs2.readFileSync(file, "utf-8");
|
|
420
505
|
} catch {
|
|
421
506
|
continue;
|
|
422
507
|
}
|
|
@@ -506,10 +591,10 @@ var ClaudeRunner = class _ClaudeRunner {
|
|
|
506
591
|
log.warn(`${why}: runs can read those paths.`);
|
|
507
592
|
}
|
|
508
593
|
}
|
|
509
|
-
if (this.options.mcpConfigPath !== void 0 && !
|
|
594
|
+
if (this.options.mcpConfigPath !== void 0 && !fs2.existsSync(this.options.mcpConfigPath)) {
|
|
510
595
|
return { ok: false, detail: `the hosted tool config ${this.options.mcpConfigPath} is missing` };
|
|
511
596
|
}
|
|
512
|
-
|
|
597
|
+
fs2.mkdirSync(this.workdir(), { recursive: true, mode: 448 });
|
|
513
598
|
return { ok: true };
|
|
514
599
|
}
|
|
515
600
|
/** `<dir>/<stem>.<run id><ext>`: a file of this run's own beside `file` (the run id reduced to letters, digits and `-`). */
|
|
@@ -577,6 +662,27 @@ var ClaudeRunner = class _ClaudeRunner {
|
|
|
577
662
|
const env = buildClaudeEnv(this.options.configDir, this.options.profile === "own" ? withoutInheritedKey(source) : source);
|
|
578
663
|
return this.options.profile === "answer" ? { ...env, ...ANSWER_ENV } : env;
|
|
579
664
|
}
|
|
665
|
+
/**
|
|
666
|
+
* Does the model answer right now, through this runner's binary, sign-in
|
|
667
|
+
* and environment? One `claude -p` with a fixed prompt and no tool at all
|
|
668
|
+
* (`claudeRuntimeCheckArgs`), in its own empty folder, with no key in its
|
|
669
|
+
* environment and no instruction file or memory in its context; ok only
|
|
670
|
+
* when its JSON result says success with no error (`claudeRuntimeCheckJudge`).
|
|
671
|
+
* Its output is read for that alone and never logged. Never throws.
|
|
672
|
+
*/
|
|
673
|
+
async checkRuntime(options = {}) {
|
|
674
|
+
return runRuntimeCheck({
|
|
675
|
+
label: "claude",
|
|
676
|
+
command: this.command,
|
|
677
|
+
args: claudeRuntimeCheckArgs(this.readDenyPaths()),
|
|
678
|
+
cwd: claudeRuntimeCheckWorkdir(this.options.configDir),
|
|
679
|
+
// No key (runRuntimeCheck takes every key variable out); no instruction file or memory.
|
|
680
|
+
env: { ...this.runEnv(), ...ANSWER_ENV },
|
|
681
|
+
// Exit 0 is not enough: the JSON result must say success with no error.
|
|
682
|
+
judge: claudeRuntimeCheckJudge,
|
|
683
|
+
...options.signal !== void 0 ? { signal: options.signal } : {}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
580
686
|
async start(request) {
|
|
581
687
|
const startedAt = Date.now();
|
|
582
688
|
const notStarted = (detail) => ({ state: "not_started", exitCode: null, durationMs: Date.now() - startedAt, detail });
|
|
@@ -593,7 +699,7 @@ var ClaudeRunner = class _ClaudeRunner {
|
|
|
593
699
|
const identityFile = request.identityLine !== void 0 ? files.identityFile : void 0;
|
|
594
700
|
const written = [];
|
|
595
701
|
const cleanup = () => {
|
|
596
|
-
for (const file of written)
|
|
702
|
+
for (const file of written) fs2.rmSync(file, { force: true });
|
|
597
703
|
};
|
|
598
704
|
if (answerMcp !== void 0 && files.mcpConfigPath !== void 0) {
|
|
599
705
|
const key = answerMcp.apiKey();
|
|
@@ -618,7 +724,7 @@ var ClaudeRunner = class _ClaudeRunner {
|
|
|
618
724
|
}
|
|
619
725
|
try {
|
|
620
726
|
const args = this.argsFor(files.mcpConfigPath ?? this.options.mcpConfigPath, identityFile);
|
|
621
|
-
log.debug(`claude ${args.join(" ")} (prompt on stdin, ${request.kind} run ${request.runId})`);
|
|
727
|
+
log.debug(`claude ${args.join(" ")} (prompt on stdin, ${request.kind} run ${request.runId}${request.conversationId !== void 0 ? ` for ${request.conversationId}` : ""})`);
|
|
622
728
|
return await spawnRun({
|
|
623
729
|
command: this.command,
|
|
624
730
|
args,
|
|
@@ -685,7 +791,7 @@ var claudeCodePreset = {
|
|
|
685
791
|
};
|
|
686
792
|
|
|
687
793
|
// src/presets/codex.ts
|
|
688
|
-
import * as
|
|
794
|
+
import * as fs3 from "fs";
|
|
689
795
|
import * as os2 from "os";
|
|
690
796
|
import * as path2 from "path";
|
|
691
797
|
var CODEX_PRESET = "codex";
|
|
@@ -758,6 +864,32 @@ function codexProfileArgs(profile) {
|
|
|
758
864
|
return ["--dangerously-bypass-approvals-and-sandbox"];
|
|
759
865
|
}
|
|
760
866
|
}
|
|
867
|
+
var CODEX_RUNTIME_CHECK_DISABLED_FEATURES = ["memories", "plugins", "apps"];
|
|
868
|
+
function codexRuntimeCheckArgs(dir, agentchatUrl) {
|
|
869
|
+
const table = `mcp_servers.${CODEX_MCP_SERVER_NAME}`;
|
|
870
|
+
return [
|
|
871
|
+
"exec",
|
|
872
|
+
"--json",
|
|
873
|
+
"--skip-git-repo-check",
|
|
874
|
+
"--ephemeral",
|
|
875
|
+
"-C",
|
|
876
|
+
dir,
|
|
877
|
+
"--sandbox",
|
|
878
|
+
"read-only",
|
|
879
|
+
"-c",
|
|
880
|
+
'model_reasoning_effort="low"',
|
|
881
|
+
"-c",
|
|
882
|
+
'web_search="disabled"',
|
|
883
|
+
...CODEX_RUNTIME_CHECK_DISABLED_FEATURES.flatMap((feature) => ["--disable", feature]),
|
|
884
|
+
...agentchatUrl !== void 0 ? ["-c", `${table}.url=${JSON.stringify(agentchatUrl)}`] : [],
|
|
885
|
+
"-c",
|
|
886
|
+
`${table}.enabled=false`,
|
|
887
|
+
CODEX_PROMPT_FROM_STDIN
|
|
888
|
+
];
|
|
889
|
+
}
|
|
890
|
+
function codexRuntimeCheckWorkdir(codexHome) {
|
|
891
|
+
return path2.join(codexHome, RUNTIME_CHECK_DIR);
|
|
892
|
+
}
|
|
761
893
|
function codexClientHeadersToml(clientVersion = VERSION) {
|
|
762
894
|
const pairs = Object.entries(clientHeadersOf({ runtime: "codex", version: clientVersion })).map(([name, value]) => `${JSON.stringify(name)} = ${JSON.stringify(value)}`);
|
|
763
895
|
return `{ ${pairs.join(", ")} }`;
|
|
@@ -883,7 +1015,7 @@ function codexConfigLayerFiles(codexHome, workdir, platform = process.platform,
|
|
|
883
1015
|
function codexListingKey(files, parts) {
|
|
884
1016
|
const stats = files.map((file) => {
|
|
885
1017
|
try {
|
|
886
|
-
const st =
|
|
1018
|
+
const st = fs3.statSync(file);
|
|
887
1019
|
return `${file}\0${st.size}\0${st.mtimeMs}`;
|
|
888
1020
|
} catch {
|
|
889
1021
|
return `${file}\0-`;
|
|
@@ -924,7 +1056,7 @@ var CodexRunner = class {
|
|
|
924
1056
|
this.warnedHome = true;
|
|
925
1057
|
log.warn(`the run workdir ${this.options.workdir} is your home folder or contains it: ${this.options.profile} runs work in ${this.workdir()} instead, so a peer-started run reaches none of your files there. Point the workdir at a folder of its own to choose another.`);
|
|
926
1058
|
}
|
|
927
|
-
|
|
1059
|
+
fs3.mkdirSync(this.workdir(), { recursive: true });
|
|
928
1060
|
if (this.options.profile === "answer") {
|
|
929
1061
|
const disables = await this.answerMcpDisables();
|
|
930
1062
|
if (!disables.ok) return { ok: false, detail: codexAnswerListingRefusal(disables.detail) };
|
|
@@ -994,7 +1126,7 @@ var CodexRunner = class {
|
|
|
994
1126
|
const dotenv = path2.join(this.options.codexHome, ".env");
|
|
995
1127
|
let names = [];
|
|
996
1128
|
try {
|
|
997
|
-
names = codexDotEnvKeyNames(
|
|
1129
|
+
names = codexDotEnvKeyNames(fs3.readFileSync(dotenv, "utf-8"));
|
|
998
1130
|
} catch {
|
|
999
1131
|
names = [];
|
|
1000
1132
|
}
|
|
@@ -1080,6 +1212,27 @@ var CodexRunner = class {
|
|
|
1080
1212
|
});
|
|
1081
1213
|
});
|
|
1082
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Does the model answer right now, through this runner's binary, sign-in,
|
|
1217
|
+
* CODEX_HOME and environment? One `codex exec` with a fixed prompt in its
|
|
1218
|
+
* own empty folder, read-only, with the hosted AgentChat server switched off
|
|
1219
|
+
* (`codexRuntimeCheckArgs`) and no key in its environment. Its output is
|
|
1220
|
+
* discarded. Never throws.
|
|
1221
|
+
*/
|
|
1222
|
+
async checkRuntime(options = {}) {
|
|
1223
|
+
if (this.options.refuse !== void 0) return { ok: false, detail: this.options.refuse };
|
|
1224
|
+
const dir = codexRuntimeCheckWorkdir(this.options.codexHome);
|
|
1225
|
+
return runRuntimeCheck({
|
|
1226
|
+
label: "codex",
|
|
1227
|
+
command: this.command,
|
|
1228
|
+
args: codexRuntimeCheckArgs(dir, this.options.mcp?.url ?? this.options.pinMcpUrl),
|
|
1229
|
+
cwd: dir,
|
|
1230
|
+
// The runs' environment; runRuntimeCheck takes every key variable out, this runner's own included.
|
|
1231
|
+
env: this.env(),
|
|
1232
|
+
keyEnv: this.options.keyEnv,
|
|
1233
|
+
...options.signal !== void 0 ? { signal: options.signal } : {}
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1083
1236
|
async start(request) {
|
|
1084
1237
|
const startedAt = Date.now();
|
|
1085
1238
|
if (this.options.refuse !== void 0) return { state: "not_started", exitCode: null, durationMs: 0, detail: this.options.refuse };
|
|
@@ -1091,7 +1244,7 @@ var CodexRunner = class {
|
|
|
1091
1244
|
}
|
|
1092
1245
|
const ownProblem = await this.ownAuthProblem();
|
|
1093
1246
|
if (ownProblem !== null) return { state: "not_started", exitCode: null, durationMs: Date.now() - startedAt, detail: ownProblem };
|
|
1094
|
-
log.debug(`codex ${args.join(" ")} (prompt on stdin, ${request.kind} run ${request.runId})`);
|
|
1247
|
+
log.debug(`codex ${args.join(" ")} (prompt on stdin, ${request.kind} run ${request.runId}${request.conversationId !== void 0 ? ` for ${request.conversationId}` : ""})`);
|
|
1095
1248
|
return spawnRun({
|
|
1096
1249
|
command: this.command,
|
|
1097
1250
|
args,
|
|
@@ -1150,7 +1303,7 @@ var codexPreset = {
|
|
|
1150
1303
|
const file = path2.join(codexHomeFrom(env), "config.toml");
|
|
1151
1304
|
let own = null;
|
|
1152
1305
|
try {
|
|
1153
|
-
own = agentchatTableKeys(
|
|
1306
|
+
own = agentchatTableKeys(fs3.readFileSync(file, "utf-8"));
|
|
1154
1307
|
} catch {
|
|
1155
1308
|
own = null;
|
|
1156
1309
|
}
|
|
@@ -1235,6 +1388,7 @@ export {
|
|
|
1235
1388
|
CODEX_PRESET,
|
|
1236
1389
|
CODEX_PROBE_TIMEOUT_MS,
|
|
1237
1390
|
CODEX_PROMPT_FROM_STDIN,
|
|
1391
|
+
CODEX_RUNTIME_CHECK_DISABLED_FEATURES,
|
|
1238
1392
|
CODEX_SESSION_ENV,
|
|
1239
1393
|
ClaudeRunner,
|
|
1240
1394
|
CodexRunner,
|
|
@@ -1244,6 +1398,12 @@ export {
|
|
|
1244
1398
|
PARENT_ENV_KEYS,
|
|
1245
1399
|
PRESETS,
|
|
1246
1400
|
PROBE_TIMEOUT_MS,
|
|
1401
|
+
RUNTIME_CHECK_BUDGET_MS,
|
|
1402
|
+
RUNTIME_CHECK_DIR,
|
|
1403
|
+
RUNTIME_CHECK_KEY_ENV,
|
|
1404
|
+
RUNTIME_CHECK_OUTPUT_BYTES,
|
|
1405
|
+
RUNTIME_CHECK_PROMPT,
|
|
1406
|
+
RUNTIME_CHECK_SETTINGS,
|
|
1247
1407
|
WEB_TOOLS,
|
|
1248
1408
|
WORK_TOOLS,
|
|
1249
1409
|
agentchatTableKeys,
|
|
@@ -1260,6 +1420,9 @@ export {
|
|
|
1260
1420
|
claudeProfileArgs,
|
|
1261
1421
|
claudeProjectsDirFor,
|
|
1262
1422
|
claudeRunArgs,
|
|
1423
|
+
claudeRuntimeCheckArgs,
|
|
1424
|
+
claudeRuntimeCheckJudge,
|
|
1425
|
+
claudeRuntimeCheckWorkdir,
|
|
1263
1426
|
claudeSettingsFilesGrantingDirectories,
|
|
1264
1427
|
claudeSignIn,
|
|
1265
1428
|
claudeUserStatePathFor,
|
|
@@ -1278,6 +1441,8 @@ export {
|
|
|
1278
1441
|
codexPreset,
|
|
1279
1442
|
codexProfileArgs,
|
|
1280
1443
|
codexRunArgs,
|
|
1444
|
+
codexRuntimeCheckArgs,
|
|
1445
|
+
codexRuntimeCheckWorkdir,
|
|
1281
1446
|
codexServerNameAddressable,
|
|
1282
1447
|
deniedAncestorOf,
|
|
1283
1448
|
inexpressibleDenyPaths,
|
|
@@ -1288,6 +1453,7 @@ export {
|
|
|
1288
1453
|
presetNamed,
|
|
1289
1454
|
presetNames,
|
|
1290
1455
|
readDenyRules,
|
|
1456
|
+
runRuntimeCheck,
|
|
1291
1457
|
semverAtLeast,
|
|
1292
1458
|
withoutParentSession,
|
|
1293
1459
|
workdirPaths,
|