@sweny-ai/core 0.1.141 → 0.1.143
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/agent-env.d.ts +24 -0
- package/dist/agent-env.js +40 -7
- package/dist/cli/config-file.d.ts +1 -1
- package/dist/cli/config-file.js +1 -1
- package/dist/cli/config.d.ts +2 -0
- package/dist/cli/config.js +15 -7
- package/dist/cli/main.js +45 -15
- package/dist/cli/output.d.ts +2 -0
- package/dist/cli/output.js +11 -0
- package/dist/cli/run-history.d.ts +2 -0
- package/dist/cli/run-history.js +2 -0
- package/dist/cli/run-output.d.ts +13 -2
- package/dist/cli/run-output.js +23 -2
- package/dist/executor.js +30 -25
- package/dist/harness/abort.d.ts +17 -0
- package/dist/harness/abort.js +53 -0
- package/dist/harness/agents.d.ts +11 -0
- package/dist/harness/agents.js +15 -0
- package/dist/harness/capabilities.d.ts +23 -0
- package/dist/harness/capabilities.js +35 -0
- package/dist/harness/claude-code.d.ts +9 -40
- package/dist/harness/claude-code.js +21 -308
- package/dist/harness/codex.d.ts +175 -0
- package/dist/harness/codex.js +917 -0
- package/dist/harness/index.d.ts +11 -3
- package/dist/harness/index.js +8 -8
- package/dist/harness/parse.d.ts +49 -0
- package/dist/harness/parse.js +253 -0
- package/dist/harness/policy.d.ts +23 -1
- package/dist/harness/policy.js +73 -15
- package/dist/harness/prompts.d.ts +7 -1
- package/dist/harness/prompts.js +16 -0
- package/dist/harness/types.d.ts +13 -2
- package/dist/harness/types.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/schema.d.ts +12 -11
- package/dist/schema.js +7 -3
- package/dist/types.d.ts +8 -1
- package/package.json +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex harness (#331): runs a node on OpenAI Codex through `codex exec --json`.
|
|
3
|
+
*
|
|
4
|
+
* Interfaces used, all read from openai/codex at rust-v0.159.2:
|
|
5
|
+
* - `codex-rs/exec/src/cli.rs`: `exec --json`, `--output-schema <file>`,
|
|
6
|
+
* `--ignore-user-config`, `--ignore-rules`, `--ephemeral`,
|
|
7
|
+
* `--skip-git-repo-check`, `--sandbox`, `--cd`, `--model`, `-c key=value`,
|
|
8
|
+
* prompt on stdin with `-`.
|
|
9
|
+
* - `codex-rs/exec/src/exec_events.rs`: the JSONL events (`thread.started`,
|
|
10
|
+
* `turn.started|completed|failed`, `item.started|updated|completed`,
|
|
11
|
+
* `error`) and item kinds.
|
|
12
|
+
* - `sdk/typescript/src/exec.ts`: how the official SDK spawns the same CLI
|
|
13
|
+
* (config overrides as TOML values, stdin prompt, exit handling).
|
|
14
|
+
* - `codex-rs/core/config.schema.json`: `features.*`, `web_search`,
|
|
15
|
+
* `agents.enabled`, `sandbox_workspace_write.network_access`,
|
|
16
|
+
* `mcp_servers.<id>.{command,args,env,env_vars,url,http_headers,...}`.
|
|
17
|
+
* - `codex-rs/rmcp-client/src/utils.rs`: an MCP stdio server gets only a
|
|
18
|
+
* small default env plus the names listed in `env_vars`, so the tool
|
|
19
|
+
* bridge token travels by name, never in argv.
|
|
20
|
+
*
|
|
21
|
+
* Every sweny opinion in the Codex column of the enforcement matrix is
|
|
22
|
+
* enforced natively here, kept by sweny (watchdog, fencing, env scoping,
|
|
23
|
+
* output validation), reported in `degraded`, or refused under strict policy
|
|
24
|
+
* by `policyGate`. Nothing is dropped silently.
|
|
25
|
+
*/
|
|
26
|
+
import type { Logger, McpServerConfig, ToolContext } from "../types.js";
|
|
27
|
+
import { type SandboxMode } from "../agent-env.js";
|
|
28
|
+
import type { AgentHarness, HarnessCapabilities, HarnessCompleteRequest, HarnessInfo, HarnessRunRequest, HarnessRunResult, ToolClass } from "./types.js";
|
|
29
|
+
import { CODEX_CAPABILITIES } from "./capabilities.js";
|
|
30
|
+
import { type HarnessPolicyMode } from "./policy.js";
|
|
31
|
+
import { type SandboxWrapper } from "./sandbox-wrapper.js";
|
|
32
|
+
export { CODEX_CAPABILITIES };
|
|
33
|
+
/** Oldest Codex CLI whose flags this adapter uses (`--ignore-user-config`, `--ignore-rules`). */
|
|
34
|
+
export declare const MIN_CODEX_VERSION = "0.159.0";
|
|
35
|
+
/**
|
|
36
|
+
* Codex features sweny always turns off, so a node sees only the tools sweny
|
|
37
|
+
* gave it: ChatGPT apps and plugins (their own MCP servers), tool suggestions,
|
|
38
|
+
* browser and computer use, lifecycle hooks, and image generation. Keys from
|
|
39
|
+
* `codex-rs/features/src/lib.rs` at rust-v0.159.2.
|
|
40
|
+
*/
|
|
41
|
+
export declare const CODEX_ISOLATION_FEATURES_OFF: readonly ["apps", "plugins", "tool_suggest", "browser_use", "computer_use", "hooks", "image_generation"];
|
|
42
|
+
/**
|
|
43
|
+
* Hosts Codex itself needs (its model API and ChatGPT sign-in), always allowed
|
|
44
|
+
* through the sandbox wrapper, plus the host of `OPENAI_BASE_URL` when set.
|
|
45
|
+
*/
|
|
46
|
+
export declare function codexBackendHosts(env?: Record<string, string | undefined>): string[];
|
|
47
|
+
export interface CodexHarnessOptions {
|
|
48
|
+
/** Model override (`--model`). Free text; sweny has no model opinion. */
|
|
49
|
+
model?: string;
|
|
50
|
+
/** Tool-call budget the watchdog enforces when a node sets no `max_turns` (default: 20). */
|
|
51
|
+
maxTurns?: number;
|
|
52
|
+
/** Working directory (default: process.cwd()). */
|
|
53
|
+
cwd?: string;
|
|
54
|
+
logger?: Logger;
|
|
55
|
+
/** Default tool context for standalone usage (not via the executor). */
|
|
56
|
+
defaultContext?: ToolContext;
|
|
57
|
+
/** Catalog defaults, overridden by per-run skill servers and explicit mcpServers. */
|
|
58
|
+
defaultMcpServers?: Record<string, McpServerConfig>;
|
|
59
|
+
/** Explicit external MCP servers, overriding defaults and per-run skill servers. */
|
|
60
|
+
mcpServers?: Record<string, McpServerConfig>;
|
|
61
|
+
/** Extra env var names passed through (see agent-env.ts). Default: `SWENY_ENV_PASSTHROUGH`. */
|
|
62
|
+
envPassthrough?: string[];
|
|
63
|
+
/** Scope the Codex env to the allowlist. Default: `SWENY_ENV_SCOPE`, else on in CI. */
|
|
64
|
+
envScope?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Codex sandbox for commands: `strict` = `workspace-write` or fail, `auto` =
|
|
67
|
+
* `workspace-write` when the host can sandbox, `off` = `danger-full-access`.
|
|
68
|
+
* Default: `SWENY_SANDBOX`, else `auto` in CI and `off` locally.
|
|
69
|
+
*/
|
|
70
|
+
sandbox?: SandboxMode;
|
|
71
|
+
/** Sandbox preflight probe (test seam). Returns a reason when the host cannot sandbox. */
|
|
72
|
+
sandboxProbe?: () => string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The host's process sandbox wrapper (#360 step 2). `undefined` = detect
|
|
75
|
+
* srt once per process; `null` = none (test seam).
|
|
76
|
+
*/
|
|
77
|
+
sandboxWrapper?: SandboxWrapper | null;
|
|
78
|
+
/** `strict` refuses a node with unenforceable opinions. Default: {@link resolveHarnessPolicy}. */
|
|
79
|
+
policy?: HarnessPolicyMode;
|
|
80
|
+
/** The Codex CLI. Default: `SWENY_CODEX_PATH`, else `codex` on PATH. Test seam for the fake. */
|
|
81
|
+
codexCommand?: {
|
|
82
|
+
command: string;
|
|
83
|
+
args: string[];
|
|
84
|
+
};
|
|
85
|
+
/** Shim command override for the tool bridge (test seam). */
|
|
86
|
+
toolBridgeShim?: {
|
|
87
|
+
command: string;
|
|
88
|
+
args: string[];
|
|
89
|
+
};
|
|
90
|
+
/** Grace period between SIGTERM and SIGKILL when stopping Codex (default: 2000 ms). */
|
|
91
|
+
killGraceMs?: number;
|
|
92
|
+
}
|
|
93
|
+
/** A TOML value for `-c key=value`, as the official SDK writes it (sdk/typescript/src/exec.ts). */
|
|
94
|
+
export declare function toTomlValue(value: unknown): string;
|
|
95
|
+
/**
|
|
96
|
+
* Split `disallowed_tools` names into portable classes Codex can act on and
|
|
97
|
+
* the names it has no tool for.
|
|
98
|
+
*/
|
|
99
|
+
export declare function translateDenyNames(names?: readonly string[]): {
|
|
100
|
+
classes: ToolClass[];
|
|
101
|
+
unknown: string[];
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Is this JSON schema accepted by OpenAI strict structured outputs? Codex
|
|
105
|
+
* sends `--output-schema` with `strict: true` (core/src/session/turn.rs), which
|
|
106
|
+
* requires `additionalProperties: false` and every property listed in
|
|
107
|
+
* `required` on every object. Not a full check; it catches the common misses.
|
|
108
|
+
*/
|
|
109
|
+
export declare function isStrictCompatibleSchema(schema: unknown): boolean;
|
|
110
|
+
export declare class CodexHarness implements AgentHarness {
|
|
111
|
+
readonly id: "codex";
|
|
112
|
+
readonly capabilities: HarnessCapabilities;
|
|
113
|
+
/**
|
|
114
|
+
* Empty on purpose: judges use Codex's own default model. Leaving this
|
|
115
|
+
* undefined would fall back to the Claude judge model, which Codex cannot run.
|
|
116
|
+
*/
|
|
117
|
+
readonly defaultJudgeModel = "";
|
|
118
|
+
readonly logger: Logger;
|
|
119
|
+
private model;
|
|
120
|
+
private maxTurns;
|
|
121
|
+
private cwd;
|
|
122
|
+
private defaultContext;
|
|
123
|
+
private mcpServers;
|
|
124
|
+
private defaultMcpServers;
|
|
125
|
+
private envPassthrough;
|
|
126
|
+
private envScope;
|
|
127
|
+
private sandboxMode;
|
|
128
|
+
private sandboxProbe;
|
|
129
|
+
private sandboxWarned;
|
|
130
|
+
private sandboxWrapper;
|
|
131
|
+
private loginWarned;
|
|
132
|
+
private policyMode;
|
|
133
|
+
private codexCommand;
|
|
134
|
+
private toolBridgeShim;
|
|
135
|
+
private killGraceMs;
|
|
136
|
+
private preflightResult;
|
|
137
|
+
private version;
|
|
138
|
+
constructor(opts?: CodexHarnessOptions);
|
|
139
|
+
info(): HarnessInfo;
|
|
140
|
+
/** `codex --version`, checked against {@link MIN_CODEX_VERSION}. Cached per instance. */
|
|
141
|
+
preflight(): Promise<{
|
|
142
|
+
ok: true;
|
|
143
|
+
version: string;
|
|
144
|
+
} | {
|
|
145
|
+
ok: false;
|
|
146
|
+
reason: string;
|
|
147
|
+
}>;
|
|
148
|
+
/** Env for the Codex process: scoped like Claude Code's, with Codex's auth vars instead of Anthropic's. */
|
|
149
|
+
private buildEnv;
|
|
150
|
+
/** The node policy after `disallowed_tools` names are translated into Codex classes. */
|
|
151
|
+
private compilePolicy;
|
|
152
|
+
/** Resolve the Codex `--sandbox` value for a normal (not read-only) run. */
|
|
153
|
+
private resolveSandbox;
|
|
154
|
+
/** argv shared by run() and complete(). */
|
|
155
|
+
private baseArgs;
|
|
156
|
+
/** `-c mcp_servers.<id>.*` for each server. Returns the args and anything Codex cannot load. */
|
|
157
|
+
private mcpArgs;
|
|
158
|
+
/** Spawn codex exec, feed the prompt on stdin, and read JSONL until it exits. */
|
|
159
|
+
private exec;
|
|
160
|
+
/**
|
|
161
|
+
* Run a node. The gate runs first: in strict mode a node whose opinions
|
|
162
|
+
* Codex cannot honor is refused before Codex starts. With a sandbox mode
|
|
163
|
+
* other than off, the whole Codex process runs inside the host's process
|
|
164
|
+
* sandbox wrapper (#360 step 2) when there is one, which also keeps the
|
|
165
|
+
* node's per-host egress allowlist that Codex cannot keep itself.
|
|
166
|
+
*/
|
|
167
|
+
run(req: HarnessRunRequest): Promise<HarnessRunResult>;
|
|
168
|
+
/** Map one exec outcome onto a NodeResult with Claude Code's semantics. */
|
|
169
|
+
private toResult;
|
|
170
|
+
/**
|
|
171
|
+
* One completion: read-only sandbox, no shell, no web search, no subagents,
|
|
172
|
+
* no MCP. null when it failed (callers fail closed).
|
|
173
|
+
*/
|
|
174
|
+
complete(req: HarnessCompleteRequest): Promise<string | null>;
|
|
175
|
+
}
|