talentos 1.2.0 → 1.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,168 @@
1
+ import { ROOM_LOCAL_TOOLS, ROOM_TOOLS } from "../codex-policy.js";
2
+ // The owner-native Codex fence (#10987 slice 1): the launch that turns a Codex
3
+ // whose shell is NOT hookable (write_stdin into an open exec_command session
4
+ // runs with no hook call, on every version through 0.164.0-alpha.3 — see
5
+ // codex-owner-probe.ts) into one that is safe to run the owner's real setup.
6
+ //
7
+ // The fence has three parts, proven by codex-fence-probe.ts before any version
8
+ // is allowed to run owner-native:
9
+ // 1. A per-run model catalog sets every model's shell_type="disabled", which
10
+ // drops exec_command AND write_stdin together (no knob keeps write_stdin
11
+ // without exec_command). apply_patch and view_image stay, both hooked.
12
+ // 2. run_command, served by our LOCAL stdio proxy, is the only way to run a
13
+ // command; the proxy classifies it through the same hook as Claude's Bash.
14
+ // 3. Everything the hook cannot see is turned off (web search, image
15
+ // generation, goals, tool search, request_user_input, multi-agent), so the
16
+ // session's whole tool list is exactly the allowlist below.
17
+ export const ROOM_SERVER = "talentos_room";
18
+ // R2 (#10987): a version pin both ways. Owner-native Codex runs only on a
19
+ // version at or above the minimum AND in the exact tested set; an untested newer
20
+ // Codex falls back to room-only until probeCodexFence re-runs on it and this set
21
+ // grows. The minimum is npm `latest` at the time of the gate. These are the
22
+ // EXACT npm version strings probed (`codex --version`'s numeric form parses the
23
+ // alpha to 0.164.0). 0.162.1 also passes the fence but stays below the pin.
24
+ // Enforced by the claim/gate (slice 2).
25
+ export const CODEX_FENCE_MIN_VERSION = "0.163.0";
26
+ export const CODEX_FENCE_TESTED = ["0.163.0", "0.164.0-alpha.3"];
27
+ // The FULL version including any prerelease: `codex --version` prints
28
+ // "codex-cli 0.164.0-alpha.3", and dropping "-alpha.3" would both fail to match
29
+ // a tested alpha and wrongly admit an untested stable 0.164.0. The gate
30
+ // exact-matches this against the tested set, so a version we have not probed —
31
+ // including a newer stable — stays room-only until probeCodexFence re-runs.
32
+ const CODEX_VERSION_FULL = /(\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?)/u;
33
+ export function codexFenceVersion(versionOutput) {
34
+ return CODEX_VERSION_FULL.exec(versionOutput)?.[1];
35
+ }
36
+ /** What `talentos agent native enable` tells the owner about an untested Codex. */
37
+ export function codexUnsupportedMessage(versionOutput) {
38
+ const version = codexFenceVersion(versionOutput) ?? "unknown version";
39
+ return `Your Codex (${version}) isn't verified for full setup yet, so it works room-only. Works with: ${CODEX_FENCE_TESTED.join(", ")}. Install one of those, then run talentos agent native enable again.`;
40
+ }
41
+ /** Whether this exact Codex version has passed the fence gate (R2). */
42
+ export function codexFenceEligible(versionOutput) {
43
+ const version = codexFenceVersion(versionOutput);
44
+ return (version !== undefined &&
45
+ CODEX_FENCE_TESTED.includes(version));
46
+ }
47
+ /**
48
+ * The session's complete tool surface in an owner-native Codex job. The gate
49
+ * probe fails closed unless the live tool list equals this exactly (an
50
+ * allowlist, never a denylist: a future shell variant that the catalog did not
51
+ * remove is a new name here, so it fails). The three list/read MCP-resource
52
+ * tools are Codex builtins present whenever any MCP server is configured; they
53
+ * are inert because our room server exposes no resources, and the hook holds
54
+ * read_mcp_resource like any unknown tool.
55
+ */
56
+ export function ownerToolAllowlist(roomTools = [...ROOM_TOOLS, ...ROOM_LOCAL_TOOLS]) {
57
+ return new Set([
58
+ "apply_patch",
59
+ "view_image",
60
+ "list_mcp_resources",
61
+ "list_mcp_resource_templates",
62
+ "read_mcp_resource",
63
+ ...roomTools.map((tool) => `mcp__${ROOM_SERVER}__${tool}`),
64
+ ]);
65
+ }
66
+ /**
67
+ * The owner-native catalog: the bundled catalog with every model's shell
68
+ * removed (shell_type="disabled", node_repl off) and the hosted web-search tool
69
+ * off, keeping apply_patch and the model's own tool mode (code or direct) so the
70
+ * fence holds in both. A model missing from the bundled catalog cannot appear,
71
+ * so a model with no entry has no shell to fall back to. Throws on a catalog
72
+ * shape it does not recognise, so the launch fails closed rather than guessing.
73
+ */
74
+ export function ownerCatalog(bundled) {
75
+ const catalog = JSON.parse(bundled);
76
+ if (!Array.isArray(catalog.models) || catalog.models.length === 0) {
77
+ throw new Error("Unsupported model catalog");
78
+ }
79
+ const models = catalog.models.map((model) => {
80
+ if (!model ||
81
+ typeof model !== "object" ||
82
+ !("slug" in model) ||
83
+ !("shell_type" in model)) {
84
+ throw new Error("Unsupported model catalog entry");
85
+ }
86
+ return {
87
+ ...model,
88
+ // Drops exec_command and write_stdin together; nothing else does.
89
+ shell_type: "disabled",
90
+ node_repl_disabled: true,
91
+ node_repl_auto_review_required: true,
92
+ // The hook cannot see the hosted web-search or the clock tool.
93
+ supports_search_tool: false,
94
+ experimental_supported_tools: [],
95
+ };
96
+ });
97
+ return JSON.stringify({ ...catalog, models });
98
+ }
99
+ // Everything the hook cannot see, turned off so the tool list is the allowlist.
100
+ // Kept ON: apply_patch (freeform, hooked every path), view_image (hooked), the
101
+ // room MCP server (room tools + run_command). Multi-agent is off in slice 1, so
102
+ // no subagent can reach a tool the parent cannot; it is a stated v1 gap.
103
+ const OWNER_FEATURE_ARGS = [
104
+ 'web_search="disabled"',
105
+ "features.view_image=true",
106
+ "features.image_generation=false",
107
+ "features.apps=false",
108
+ "features.plugins=false",
109
+ "features.tool_search=false",
110
+ "features.goals=false",
111
+ "features.multi_agent=false",
112
+ "agents.enabled=false",
113
+ "tools.experimental_request_user_input.enabled=false",
114
+ "memories.generate_memories=false",
115
+ ];
116
+ /**
117
+ * The owner-native launch arguments, minus the hook-trust argument (built
118
+ * asynchronously from the app server by the caller) and the inline hook
119
+ * argument (codexHookArgs). approval_policy is "never" because our hook, not
120
+ * Codex's own prompt, decides; the OS sandbox (workspace-write, network off) is
121
+ * a backstop layer, never the gate, and run_command runs one-shot in the proxy
122
+ * outside it.
123
+ */
124
+ export function codexOwnerArgs(input) {
125
+ const args = [
126
+ "-c",
127
+ 'sandbox_mode="workspace-write"',
128
+ "-c",
129
+ `sandbox_workspace_write.writable_roots=${JSON.stringify([input.writableRoot])}`,
130
+ "-c",
131
+ "sandbox_workspace_write.network_access=false",
132
+ "-c",
133
+ 'approval_policy="never"',
134
+ ...OWNER_FEATURE_ARGS.flatMap((flag) => ["-c", flag]),
135
+ "-c",
136
+ `model_catalog_json=${JSON.stringify(input.catalogPath)}`,
137
+ "-c",
138
+ `mcp_servers.${ROOM_SERVER}.enabled_tools=${JSON.stringify([
139
+ ...ROOM_TOOLS,
140
+ ...ROOM_LOCAL_TOOLS,
141
+ ])}`,
142
+ // Our PreToolUse hook is the gate, so Codex must not add its own approval
143
+ // prompt in front of the room server (under workspace-write an MCP call
144
+ // would otherwise be refused as "requires approval, but policy is never").
145
+ "-c",
146
+ `mcp_servers.${ROOM_SERVER}.default_tools_approval_mode="approve"`,
147
+ // run_command holds for the owner's approval then runs, so the room server's
148
+ // per-tool-call timeout must cover the hold (up to ~900 s) plus the 600 s
149
+ // command cap. This PER-SERVER key is the one that governs an MCP tool call
150
+ // (measured: mcp_servers.<s>.tool_timeout_sec=10 cuts a 40 s call; the global
151
+ // tool_timeout_sec does not, and the ~300 s default would otherwise cut a
152
+ // long approval hold short — "owner taps Allow and nothing happens").
153
+ "-c",
154
+ `mcp_servers.${ROOM_SERVER}.tool_timeout_sec=1800`,
155
+ "-c",
156
+ `mcp_servers.${ROOM_SERVER}.command=${JSON.stringify(input.mcpCommand)}`,
157
+ "-c",
158
+ `mcp_servers.${ROOM_SERVER}.args=${JSON.stringify(input.mcpArgs)}`,
159
+ "exec",
160
+ ];
161
+ if (input.sessionId) {
162
+ args.push("resume", input.sessionId);
163
+ }
164
+ // --ignore-user-config is NOT passed: owner-native loads the owner's ~/.codex
165
+ // setup. What that implies for the shared-room review gate is slice 2.
166
+ args.push("--json", "--skip-git-repo-check", input.prompt);
167
+ return args;
168
+ }
@@ -0,0 +1,86 @@
1
+ import { mkdir, rm } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { writePrivateFile } from "../../agent-config.js";
5
+ import { gatewayLauncherPath } from "../../gateway-install.js";
6
+ import { codexOwnerArgs, ownerCatalog } from "./codex-fence.js";
7
+ import { codexHookArgs, trustHookArgs } from "./codex-owner.js";
8
+ import { HOOK_ENTRY, ownerRules } from "./launch.js";
9
+ /** The room MCP proxy command for a Codex owner job: adds the owner job dir. */
10
+ export function codexRoomMcpEntry(input) {
11
+ const launcher = gatewayLauncherPath(input.home);
12
+ const useLauncher = process.platform !== "win32";
13
+ return {
14
+ command: useLauncher ? launcher : process.execPath,
15
+ args: [
16
+ ...(useLauncher
17
+ ? []
18
+ : [fileURLToPath(new URL("../../index.js", import.meta.url))]),
19
+ "agent",
20
+ "mcp",
21
+ "--agent",
22
+ input.agentId,
23
+ ...(input.uploadRoot ? ["--upload-root", input.uploadRoot] : []),
24
+ // Turns on run_command, served and gated by the proxy for this job only.
25
+ "--owner-job-dir",
26
+ input.jobDir,
27
+ ],
28
+ };
29
+ }
30
+ export async function prepareCodexOwnerLaunch(input) {
31
+ const jobDir = join(input.directory, "jobs", input.jobId.replace(/[^\w-]/gu, ""));
32
+ await mkdir(jobDir, { recursive: true, mode: 0o700 });
33
+ await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
34
+ ...(input.askSocket ? { askSocket: input.askSocket } : {}),
35
+ home: input.home,
36
+ writeRoots: input.workspace.writeRoots,
37
+ }));
38
+ const catalogPath = join(jobDir, "catalog.json");
39
+ await writePrivateFile(catalogPath, ownerCatalog(input.bundledCatalog));
40
+ // A tiny per-job wrapper so the hook is a single executable path (as Codex's
41
+ // hook runner expects) that carries this job's folder, like Claude's hook.
42
+ const hookPath = join(jobDir, "hook.sh");
43
+ await writePrivateFile(hookPath, `#!/bin/sh\nexec ${shellQuote(process.execPath)} ${shellQuote(HOOK_ENTRY)} ${shellQuote(jobDir)}\n`, 0o700);
44
+ const trust = input.trust ?? trustHookArgs;
45
+ const trustArgs = await trust({
46
+ binary: input.binary,
47
+ command: hookPath,
48
+ cwd: input.workspace.cwd,
49
+ env: input.env,
50
+ signal: input.signal,
51
+ });
52
+ const mcp = codexRoomMcpEntry({
53
+ agentId: input.agentId,
54
+ home: input.home,
55
+ jobDir,
56
+ uploadRoot: input.workspace.writeRoots[0],
57
+ });
58
+ const args = [
59
+ // The owner's own setup reaches the model as data (room is untrusted); the
60
+ // fence's own refusal is expected. Same rules as Claude owner-native.
61
+ "-c",
62
+ `developer_instructions=${toml(`${input.instructions}\n\n${ownerRules(input.sharedRoom)}`)}`,
63
+ ...codexHookArgs(hookPath),
64
+ ...trustArgs,
65
+ ...codexOwnerArgs({
66
+ catalogPath,
67
+ mcpArgs: mcp.args,
68
+ mcpCommand: mcp.command,
69
+ prompt: input.prompt,
70
+ sessionId: input.sessionId,
71
+ writableRoot: input.workspace.writeRoots[0] ?? input.workspace.cwd,
72
+ }),
73
+ ];
74
+ return {
75
+ args,
76
+ cleanup: () => rm(jobDir, { force: true, recursive: true }),
77
+ jobDir,
78
+ };
79
+ }
80
+ /** A TOML basic string for a `-c key=value` override (value is model-visible text). */
81
+ function toml(value) {
82
+ return JSON.stringify(value);
83
+ }
84
+ function shellQuote(value) {
85
+ return `'${value.replaceAll("'", "'\\''")}'`;
86
+ }