talentos 1.4.10 → 1.4.11
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 +3 -3
- package/dist/agent/adapters.js +75 -11
- package/dist/agent/codex-policy.js +11 -0
- package/dist/agent/codex-probe.js +9 -5
- package/dist/agent/mcp-entry.js +22 -9
- package/dist/agent/native/approvals.js +15 -11
- package/dist/agent/native/codex-launch.js +1 -0
- package/dist/agent/native/gate.js +35 -1
- package/dist/agent/native/hook-entry.js +31 -8
- package/dist/agent/native/launch.js +1 -0
- package/dist/agent/native/policy.js +62 -14
- package/dist/agent/native/probe.js +13 -1
- package/dist/agent/native/touch.js +15 -1
- package/dist/agent/node-floor.js +140 -0
- package/dist/agent/serve.js +53 -7
- package/dist/agent-http.js +48 -0
- package/dist/agent-session.js +137 -0
- package/dist/args.js +1 -0
- package/dist/client.js +11 -2
- package/dist/commands/agent-session.js +160 -0
- package/dist/commands/agent.js +29 -3
- package/dist/commands/init.js +2 -2
- package/dist/commands/login.js +2 -2
- package/dist/gateway-install.js +50 -11
- package/dist/index.js +13 -4
- package/dist/install.js +39 -14
- package/dist/mcp-proxy.js +30 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# talentos
|
|
2
2
|
|
|
3
|
-
The TalentOS CLI. It connects the
|
|
3
|
+
The TalentOS CLI. It connects the agent on your machine to your team's
|
|
4
4
|
governed brain, for four jobs:
|
|
5
5
|
|
|
6
6
|
1. **Push** a skill your agent wrote into TalentOS, then share it with the company.
|
|
@@ -27,7 +27,7 @@ npx talentos@1 init
|
|
|
27
27
|
`init` is the whole setup in one command. It:
|
|
28
28
|
|
|
29
29
|
1. **Signs you in** — skipped when the key already on this machine still works.
|
|
30
|
-
2. **Detects your
|
|
30
|
+
2. **Detects your agents** — Claude Code (the `claude` command on your
|
|
31
31
|
PATH, or `~/.claude`), Cursor (`~/.cursor` or `./.cursor`), Codex (`~/.codex`).
|
|
32
32
|
`--for claude|cursor|codex|all` overrides detection.
|
|
33
33
|
3. **Writes the MCP config** for each of them, at user level (see the table below).
|
|
@@ -60,7 +60,7 @@ and asks you to approve the device in TalentOS. The raw key is written to
|
|
|
60
60
|
`~/.config/talentos/config.json` (mode 0600) and never leaves the machine.
|
|
61
61
|
|
|
62
62
|
It prints an eight-character code and, when the server returns an approval link,
|
|
63
|
-
opens it. Otherwise open TalentOS yourself, go to **Settings → Agents
|
|
63
|
+
opens it. Otherwise open TalentOS yourself, go to **Settings → Agents**, and
|
|
64
64
|
enter the code there.
|
|
65
65
|
|
|
66
66
|
Already have a key? `npx talentos@1 login --key tos_...` — it is checked for shape
|
package/dist/agent/adapters.js
CHANGED
|
@@ -10,7 +10,7 @@ import { redactAgentOutput, } from "../agent-link.js";
|
|
|
10
10
|
import { gatewayLauncherPath } from "../gateway-install.js";
|
|
11
11
|
import { providerPathEnv, resolveProviderBinary } from "../provider-binary.js";
|
|
12
12
|
import { codexRoomArgs, ROOM_TOOLS } from "./codex-policy.js";
|
|
13
|
-
import { CodexBoundaryError, codexWebProven, probeCodexBoundary, } from "./codex-probe.js";
|
|
13
|
+
import { binaryIdentity, CodexBoundaryError, codexWebProven, probeCodexBoundary, } from "./codex-probe.js";
|
|
14
14
|
import { prepareCodexOwnerLaunch } from "./native/codex-launch.js";
|
|
15
15
|
import { prepareOwnerLaunch } from "./native/launch.js";
|
|
16
16
|
import { readReceipts } from "./native/receipts.js";
|
|
@@ -93,8 +93,30 @@ export async function verifyClaudeCode(configured) {
|
|
|
93
93
|
}
|
|
94
94
|
throw new Error(`Update Claude Code (${version}) to a version that supports --permission-mode dontAsk, --setting-sources and --no-session-persistence.`);
|
|
95
95
|
}
|
|
96
|
+
// What the serve loop already proved about each Codex binary, keyed by the
|
|
97
|
+
// binary's path and valid only while binaryIdentity is unchanged: the loop
|
|
98
|
+
// verifies before every claim, and an unchanged file cannot answer differently.
|
|
99
|
+
// An update in place changes the identity, so the next verify runs in full.
|
|
100
|
+
const verifiedCodex = new Map();
|
|
101
|
+
const webVerifiedCodex = new Map();
|
|
102
|
+
const roomCatalogs = new Map();
|
|
103
|
+
async function identityOrUndefined(binary) {
|
|
104
|
+
try {
|
|
105
|
+
return await binaryIdentity(binary);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
96
111
|
export async function verifyCodex(configured, signal) {
|
|
97
112
|
const binary = resolveProviderBinary("codex", configured);
|
|
113
|
+
// Taken before the checks: a swap while they run leaves a stale identity, and
|
|
114
|
+
// the next verify runs in full.
|
|
115
|
+
const identity = await identityOrUndefined(binary);
|
|
116
|
+
if (identity !== undefined &&
|
|
117
|
+
verifiedCodex.get(binary)?.identity === identity) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
98
120
|
const execute = promisify(execFile);
|
|
99
121
|
const options = {
|
|
100
122
|
env: childEnvironment(process.env, binary),
|
|
@@ -122,6 +144,9 @@ export async function verifyCodex(configured, signal) {
|
|
|
122
144
|
}
|
|
123
145
|
if (version !== "unknown") {
|
|
124
146
|
await probeCodexBoundary(binary, version, await codexRoomCatalog(binary), signal);
|
|
147
|
+
if (identity !== undefined) {
|
|
148
|
+
verifiedCodex.set(binary, { identity, version });
|
|
149
|
+
}
|
|
125
150
|
return;
|
|
126
151
|
}
|
|
127
152
|
}
|
|
@@ -141,22 +166,50 @@ export async function verifyCodex(configured, signal) {
|
|
|
141
166
|
export async function verifyCodexWeb(configured, signal) {
|
|
142
167
|
try {
|
|
143
168
|
const binary = resolveProviderBinary("codex", configured);
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const version =
|
|
169
|
+
const identity = await identityOrUndefined(binary);
|
|
170
|
+
// Only a pass is remembered: a failed or interrupted proof is tried again.
|
|
171
|
+
if (identity !== undefined && webVerifiedCodex.get(binary) === identity) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const known = verifiedCodex.get(binary);
|
|
175
|
+
const version = known && known.identity === identity
|
|
176
|
+
? known.version
|
|
177
|
+
: await codexVersion(binary, signal);
|
|
151
178
|
if (version) {
|
|
152
179
|
await probeCodexBoundary(binary, version, await codexRoomCatalog(binary), signal, { web: true });
|
|
180
|
+
if (identity !== undefined) {
|
|
181
|
+
webVerifiedCodex.set(binary, identity);
|
|
182
|
+
}
|
|
153
183
|
}
|
|
154
184
|
}
|
|
155
185
|
catch {
|
|
156
186
|
// Web stays off for this Codex.
|
|
157
187
|
}
|
|
158
188
|
}
|
|
189
|
+
async function codexVersion(binary, signal) {
|
|
190
|
+
const { stdout } = await promisify(execFile)(binary, ["--version"], {
|
|
191
|
+
env: childEnvironment(process.env, binary),
|
|
192
|
+
timeout: 5000,
|
|
193
|
+
signal,
|
|
194
|
+
maxBuffer: 256_000,
|
|
195
|
+
});
|
|
196
|
+
return CODEX_VERSION.exec(stdout)?.[0];
|
|
197
|
+
}
|
|
198
|
+
// The bundled catalog is the binary's own output, so an unchanged binary gives
|
|
199
|
+
// the same one: it is read once per identity, not on every job.
|
|
159
200
|
async function codexRoomCatalog(binary) {
|
|
201
|
+
const identity = await identityOrUndefined(binary);
|
|
202
|
+
const known = roomCatalogs.get(binary);
|
|
203
|
+
if (identity !== undefined && known?.identity === identity) {
|
|
204
|
+
return known.catalog;
|
|
205
|
+
}
|
|
206
|
+
const catalog = await readCodexRoomCatalog(binary);
|
|
207
|
+
if (identity !== undefined) {
|
|
208
|
+
roomCatalogs.set(binary, { catalog, identity });
|
|
209
|
+
}
|
|
210
|
+
return catalog;
|
|
211
|
+
}
|
|
212
|
+
async function readCodexRoomCatalog(binary) {
|
|
160
213
|
try {
|
|
161
214
|
const { stdout } = await promisify(execFile)(binary, ["debug", "models", "--bundled"], {
|
|
162
215
|
env: childEnvironment(process.env, binary),
|
|
@@ -227,8 +280,13 @@ export function readProviderEvent(provider, value) {
|
|
|
227
280
|
if (event.type === "assistant" &&
|
|
228
281
|
Array.isArray(message?.content) &&
|
|
229
282
|
message.content.some((part) => part.type === "tool_use")) {
|
|
283
|
+
const names = message.content.flatMap((part) => part.type === "tool_use" ? [part.name ?? ""] : []);
|
|
230
284
|
return {
|
|
231
|
-
status: WEB_STATUS[
|
|
285
|
+
status: WEB_STATUS[names[0] ?? ""] ?? "Using room tools…",
|
|
286
|
+
// Any of the turn's calls, not only the first: they run together.
|
|
287
|
+
...(names.some((name) => name in WEB_STATUS)
|
|
288
|
+
? { web: true }
|
|
289
|
+
: {}),
|
|
232
290
|
};
|
|
233
291
|
}
|
|
234
292
|
}
|
|
@@ -255,7 +313,7 @@ export function readProviderEvent(provider, value) {
|
|
|
255
313
|
return { status: "Using room tools…" };
|
|
256
314
|
}
|
|
257
315
|
if (event.type === "item.started" && item?.type === "web_search") {
|
|
258
|
-
return { status: SEARCHING };
|
|
316
|
+
return { status: SEARCHING, web: true };
|
|
259
317
|
}
|
|
260
318
|
}
|
|
261
319
|
return {};
|
|
@@ -282,6 +340,7 @@ export async function runProvider(input) {
|
|
|
282
340
|
instructions,
|
|
283
341
|
jobId: job.jobId,
|
|
284
342
|
prompt,
|
|
343
|
+
roomId: job.packet.room?.id,
|
|
285
344
|
sessionId,
|
|
286
345
|
sharedRoom: job.native?.sharedRoom,
|
|
287
346
|
workspace: input.owner.workspace,
|
|
@@ -303,6 +362,7 @@ export async function runProvider(input) {
|
|
|
303
362
|
instructions,
|
|
304
363
|
jobId: job.jobId,
|
|
305
364
|
prompt,
|
|
365
|
+
roomId: job.packet.room?.id,
|
|
306
366
|
sessionId,
|
|
307
367
|
sharedRoom: job.native?.sharedRoom,
|
|
308
368
|
signal,
|
|
@@ -488,7 +548,7 @@ export async function runProvider(input) {
|
|
|
488
548
|
stop();
|
|
489
549
|
}
|
|
490
550
|
try {
|
|
491
|
-
let text = "", failure, failed = false, sawResult = false;
|
|
551
|
+
let text = "", failure, failed = false, sawResult = false, webReported = false;
|
|
492
552
|
if (!child.stdout) {
|
|
493
553
|
throw new Error("Provider output is unavailable.");
|
|
494
554
|
}
|
|
@@ -509,6 +569,10 @@ export async function runProvider(input) {
|
|
|
509
569
|
if (event.status) {
|
|
510
570
|
mark("firstTool");
|
|
511
571
|
}
|
|
572
|
+
if (event.web && !(webReported || input.owner)) {
|
|
573
|
+
webReported = true;
|
|
574
|
+
await input.webRead?.();
|
|
575
|
+
}
|
|
512
576
|
if (event.failed) {
|
|
513
577
|
failed = true;
|
|
514
578
|
}
|
|
@@ -14,6 +14,15 @@ export const ROOM_TOOLS = [
|
|
|
14
14
|
"read_app_state",
|
|
15
15
|
"write_app_state",
|
|
16
16
|
"get_skill",
|
|
17
|
+
"list_skills",
|
|
18
|
+
"search_memory",
|
|
19
|
+
"list_connections",
|
|
20
|
+
"use_connection",
|
|
21
|
+
"ask_talent",
|
|
22
|
+
"get_thread",
|
|
23
|
+
"list_routines",
|
|
24
|
+
"run_routine",
|
|
25
|
+
"remember",
|
|
17
26
|
"suggest_change",
|
|
18
27
|
"create_file",
|
|
19
28
|
"create_deck",
|
|
@@ -26,6 +35,8 @@ export const ROOM_TOOLS = [
|
|
|
26
35
|
"post_to_thread",
|
|
27
36
|
"start_thread",
|
|
28
37
|
"share_link",
|
|
38
|
+
"room_default_set",
|
|
39
|
+
"room_default_remove",
|
|
29
40
|
"whoami",
|
|
30
41
|
];
|
|
31
42
|
export function codexRoomArgs(input) {
|
|
@@ -185,7 +185,11 @@ async function execute(binary, args, cwd, env, signal) {
|
|
|
185
185
|
function digest(value) {
|
|
186
186
|
return createHash("sha256").update(value).digest("hex");
|
|
187
187
|
}
|
|
188
|
-
|
|
188
|
+
/**
|
|
189
|
+
* What makes a Codex binary the same file: its path, real target, inode, size
|
|
190
|
+
* and times. An update in place changes at least the size or the times.
|
|
191
|
+
*/
|
|
192
|
+
export async function binaryIdentity(binary) {
|
|
189
193
|
const target = await realpath(binary);
|
|
190
194
|
const info = await stat(target);
|
|
191
195
|
return JSON.stringify([
|
|
@@ -234,7 +238,7 @@ const proofCache = (key) => join(homeDir(), ".talentos", "codex-boundary", `${ke
|
|
|
234
238
|
/** Whether this Codex binary passed the proof with live web search on. */
|
|
235
239
|
export async function codexWebProven(binary, catalog) {
|
|
236
240
|
try {
|
|
237
|
-
const key = webProofKey(await
|
|
241
|
+
const key = webProofKey(await binaryIdentity(binary), catalog);
|
|
238
242
|
return ((await readFile(proofCache(key), "utf8")) ===
|
|
239
243
|
JSON.stringify({ key, safe: true }));
|
|
240
244
|
}
|
|
@@ -243,7 +247,7 @@ export async function codexWebProven(binary, catalog) {
|
|
|
243
247
|
}
|
|
244
248
|
}
|
|
245
249
|
async function proveCodexBoundary(binary, version, catalog, stop, web = false) {
|
|
246
|
-
const before = await
|
|
250
|
+
const before = await binaryIdentity(binary);
|
|
247
251
|
const key = web
|
|
248
252
|
? webProofKey(before, catalog)
|
|
249
253
|
: digest(JSON.stringify([
|
|
@@ -297,7 +301,7 @@ async function proveCodexBoundary(binary, version, catalog, stop, web = false) {
|
|
|
297
301
|
import {StdioServerTransport} from ${JSON.stringify(import.meta.resolve("@modelcontextprotocol/sdk/server/stdio.js"))};
|
|
298
302
|
import {ListToolsRequestSchema,CallToolRequestSchema} from ${JSON.stringify(import.meta.resolve("@modelcontextprotocol/sdk/types.js"))};
|
|
299
303
|
const server=new Server({name:'talentos',version:'probe'},{capabilities:{tools:{}}});
|
|
300
|
-
server.setRequestHandler(ListToolsRequestSchema,async()=>{await new Promise(r=>setTimeout(r,Number(process.argv[2])));return {tools:${JSON.stringify([...ROOM_TOOLS, "
|
|
304
|
+
server.setRequestHandler(ListToolsRequestSchema,async()=>{await new Promise(r=>setTimeout(r,Number(process.argv[2])));return {tools:${JSON.stringify([...ROOM_TOOLS, "save_skill", "share_skill"].map((name) => ({ name, description: name, inputSchema: { type: "object", properties: {} }, annotations: { readOnlyHint: true, destructiveHint: false, openWorldHint: false } })))}};});
|
|
301
305
|
server.setRequestHandler(CallToolRequestSchema,async r=>({content:[{type:'text',text:r.params.name==='read_room'?${JSON.stringify(marker)}:'private-tool-refused'}]}));
|
|
302
306
|
await server.connect(new StdioServerTransport());`, { mode: 0o600 });
|
|
303
307
|
server.on("request", async (request, response) => {
|
|
@@ -451,7 +455,7 @@ await server.connect(new StdioServerTransport());`, { mode: 0o600 });
|
|
|
451
455
|
}
|
|
452
456
|
session = thread;
|
|
453
457
|
}
|
|
454
|
-
if ((await
|
|
458
|
+
if ((await binaryIdentity(binary)) !== before) {
|
|
455
459
|
throw new Error("Codex changed during probe");
|
|
456
460
|
}
|
|
457
461
|
signal.throwIfAborted();
|
package/dist/agent/mcp-entry.js
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
import { localAgents } from "../agent-config.js";
|
|
2
|
+
import { readSessionKey, sessionUploadRoot } from "../agent-session.js";
|
|
2
3
|
import { parseArgv } from "../args.js";
|
|
3
4
|
import { AgentClient } from "../client.js";
|
|
5
|
+
import { homeDir } from "../install.js";
|
|
4
6
|
import { startMcpProxy } from "../mcp-proxy.js";
|
|
5
7
|
// A local stdio entry avoids putting the bearer key in Codex's argv or child
|
|
6
8
|
// environment. Only the MCP proxy reads the linked-agent credential file.
|
|
7
9
|
const { options } = parseArgv(process.argv.slice(2));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
if (options.surface === "session") {
|
|
11
|
+
// The member's own terminal acting as the agent (#10527): its own key, from
|
|
12
|
+
// its own private file, and whatever folder the terminal runs in.
|
|
13
|
+
const key = await readSessionKey(options.agent ?? "", homeDir());
|
|
14
|
+
if (!key) {
|
|
15
|
+
throw new Error("This terminal is not connected. Run talentos agent connect-session.");
|
|
16
|
+
}
|
|
17
|
+
await startMcpProxy(new AgentClient(key), await sessionUploadRoot(process.cwd(), homeDir()));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
const config = (await localAgents()).find((agent) => agent.agentId === options.agent);
|
|
21
|
+
if (!config) {
|
|
22
|
+
throw new Error("Linked agent configuration is unavailable.");
|
|
23
|
+
}
|
|
24
|
+
await startMcpProxy(new AgentClient({ apiUrl: config.apiUrl, apiKey: config.apiKey }),
|
|
25
|
+
// The launcher names the job's workspace; a job with none uploads nothing.
|
|
26
|
+
options["upload-root"],
|
|
27
|
+
// Set only for an owner-native Codex job: the folder whose context.json and
|
|
28
|
+
// hook gate run_command (#10987). Absent for every room-only job.
|
|
29
|
+
options["owner-job-dir"]);
|
|
11
30
|
}
|
|
12
|
-
await startMcpProxy(new AgentClient({ apiUrl: config.apiUrl, apiKey: config.apiKey }),
|
|
13
|
-
// The launcher names the job's workspace; a job with none uploads nothing.
|
|
14
|
-
options["upload-root"],
|
|
15
|
-
// Set only for an owner-native Codex job: the folder whose context.json and
|
|
16
|
-
// hook gate run_command (#10987). Absent for every room-only job.
|
|
17
|
-
options["owner-job-dir"]);
|
|
@@ -18,6 +18,12 @@ const MAX_LINE = 4096;
|
|
|
18
18
|
const asAnswer = (status) => status === "approved" || status === "denied" || status === "expired"
|
|
19
19
|
? status
|
|
20
20
|
: undefined;
|
|
21
|
+
const asRefusedBy = (value) => Array.isArray(value) &&
|
|
22
|
+
value.length > 0 &&
|
|
23
|
+
value.length <= 5 &&
|
|
24
|
+
value.every((name) => typeof name === "string")
|
|
25
|
+
? value
|
|
26
|
+
: undefined;
|
|
21
27
|
function parseReport(line) {
|
|
22
28
|
try {
|
|
23
29
|
const value = JSON.parse(line);
|
|
@@ -168,10 +174,10 @@ export class ApprovalBridge {
|
|
|
168
174
|
}
|
|
169
175
|
async forward(ask, socket) {
|
|
170
176
|
try {
|
|
171
|
-
const { status } = await this.gateway.request(ask);
|
|
177
|
+
const { refusedBy, status } = await this.gateway.request(ask);
|
|
172
178
|
const answer = asAnswer(status);
|
|
173
179
|
if (answer) {
|
|
174
|
-
this.reply(socket, answer);
|
|
180
|
+
this.reply(socket, answer, refusedBy);
|
|
175
181
|
return;
|
|
176
182
|
}
|
|
177
183
|
}
|
|
@@ -196,16 +202,13 @@ export class ApprovalBridge {
|
|
|
196
202
|
this.lastPollAt = Date.now();
|
|
197
203
|
try {
|
|
198
204
|
const keys = [...this.waiters.keys()].slice(0, 10);
|
|
199
|
-
const answers = new Map((await this.gateway.status(keys)).map((row) => [
|
|
200
|
-
row.actionKey,
|
|
201
|
-
row.status,
|
|
202
|
-
]));
|
|
205
|
+
const answers = new Map((await this.gateway.status(keys)).map((row) => [row.actionKey, row]));
|
|
203
206
|
for (const key of keys) {
|
|
204
|
-
const
|
|
205
|
-
const answer =
|
|
207
|
+
const row = answers.get(key);
|
|
208
|
+
const answer = row === undefined ? "expired" : asAnswer(row.status);
|
|
206
209
|
if (answer) {
|
|
207
210
|
for (const socket of this.waiters.get(key) ?? []) {
|
|
208
|
-
this.reply(socket, answer);
|
|
211
|
+
this.reply(socket, answer, row?.refusedBy);
|
|
209
212
|
}
|
|
210
213
|
this.waiters.delete(key);
|
|
211
214
|
}
|
|
@@ -227,8 +230,9 @@ export class ApprovalBridge {
|
|
|
227
230
|
this.signal();
|
|
228
231
|
}
|
|
229
232
|
}
|
|
230
|
-
reply(socket, status) {
|
|
231
|
-
|
|
233
|
+
reply(socket, status, refusedBy) {
|
|
234
|
+
const classes = status === "denied" ? asRefusedBy(refusedBy) : undefined;
|
|
235
|
+
socket.end(`${JSON.stringify(classes ? { status, refusedBy: classes } : { status })}\n`);
|
|
232
236
|
}
|
|
233
237
|
signal() {
|
|
234
238
|
const waiting = this.waiters.size > 0;
|
|
@@ -20,6 +20,7 @@ export async function prepareCodexOwnerLaunch(input) {
|
|
|
20
20
|
await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
|
|
21
21
|
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
22
22
|
home: input.home,
|
|
23
|
+
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
23
24
|
writeRoots: input.workspace.writeRoots,
|
|
24
25
|
}));
|
|
25
26
|
const catalogPath = join(jobDir, "catalog.json");
|
|
@@ -12,7 +12,7 @@ import { NATIVE_FALLBACK_FILE, NATIVE_FILE, readNativeConfig, } from "./config.j
|
|
|
12
12
|
import { ownerContextPresent } from "./context.js";
|
|
13
13
|
import { claudeDisqualifier } from "./disqualify.js";
|
|
14
14
|
import { loginShellEnv } from "./env.js";
|
|
15
|
-
import { ensureOwnerNativeProbe } from "./probe.js";
|
|
15
|
+
import { ensureOwnerNativeProbe, ownerNativeProbeCached } from "./probe.js";
|
|
16
16
|
import { readProjects } from "./projects.js";
|
|
17
17
|
import { prepareWorkspace } from "./workspace.js";
|
|
18
18
|
const WHITESPACE = /\s+/u;
|
|
@@ -25,6 +25,7 @@ export const NO_PROJECT = "No project is set up on this computer, so I'm working
|
|
|
25
25
|
export const MISSING_PROJECT = "That project's folder isn't available on this computer, so I'm working room-only.";
|
|
26
26
|
export const NATIVE_OFF = "Full setup is off on this computer. Run talentos agent native enable to turn it on.";
|
|
27
27
|
export const NOT_READY = "The safety check for your setup hasn't passed on this computer yet. Run talentos agent native enable again, and check talentos agent logs.";
|
|
28
|
+
export const CLAUDE_CHANGED = "Claude Code changed on this computer since its safety check, so I'm working room-only until it passes again.";
|
|
28
29
|
export const PREPARE_FAILED = "Something went wrong preparing your setup on this computer.";
|
|
29
30
|
export const LOCAL_BASE = "Couldn't get the latest code, so I started from your local copy.";
|
|
30
31
|
/**
|
|
@@ -44,8 +45,10 @@ export class NativeGate {
|
|
|
44
45
|
env;
|
|
45
46
|
agent;
|
|
46
47
|
directory;
|
|
48
|
+
hookEntry;
|
|
47
49
|
home;
|
|
48
50
|
constructor(input) {
|
|
51
|
+
this.hookEntry = input.hookEntry;
|
|
49
52
|
this.agent = input.agent;
|
|
50
53
|
this.directory = input.directory;
|
|
51
54
|
this.home = input.home;
|
|
@@ -141,6 +144,7 @@ export class NativeGate {
|
|
|
141
144
|
await ensureOwnerNativeProbe({
|
|
142
145
|
binary,
|
|
143
146
|
cachePath: join(this.directory, "native-probe.json"),
|
|
147
|
+
hookEntry: this.hookEntry,
|
|
144
148
|
version: stdout.trim().split(WHITESPACE)[0] ?? "unknown",
|
|
145
149
|
});
|
|
146
150
|
}
|
|
@@ -225,6 +229,13 @@ export class NativeGate {
|
|
|
225
229
|
return;
|
|
226
230
|
}
|
|
227
231
|
const env = await this.loginEnv();
|
|
232
|
+
// Claude: an update in place replaces the binary the probe proved, so it is
|
|
233
|
+
// checked again per job (a stat and a --version, never the probe itself).
|
|
234
|
+
if (this.agent.provider !== "codex" && !(await this.claudeUnchanged(env))) {
|
|
235
|
+
this.probe = "none";
|
|
236
|
+
fell(CLAUDE_CHANGED);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
228
239
|
// Codex: the per-job fence checks come before any workspace is created.
|
|
229
240
|
const codex = this.agent.provider === "codex"
|
|
230
241
|
? await this.codexReady(env, job.codexTested)
|
|
@@ -295,6 +306,29 @@ export class NativeGate {
|
|
|
295
306
|
workspace,
|
|
296
307
|
};
|
|
297
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Per Claude owner job: the binary answering now is the one the cached probe
|
|
311
|
+
* proved (realpath, mtime, version). On a change the job runs room-only and
|
|
312
|
+
* the next heartbeat re-probes.
|
|
313
|
+
*/
|
|
314
|
+
async claudeUnchanged(env) {
|
|
315
|
+
try {
|
|
316
|
+
const binary = resolveProviderBinary(this.agent.provider, this.agent.providerPath);
|
|
317
|
+
const { stdout } = await exec(binary, ["--version"], {
|
|
318
|
+
env: { ...env, PATH: providerPathEnv(binary, this.home) },
|
|
319
|
+
timeout: 5000,
|
|
320
|
+
});
|
|
321
|
+
return await ownerNativeProbeCached({
|
|
322
|
+
binary,
|
|
323
|
+
cachePath: join(this.directory, "native-probe.json"),
|
|
324
|
+
hookEntry: this.hookEntry,
|
|
325
|
+
version: stdout.trim().split(WHITESPACE)[0] ?? "unknown",
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
298
332
|
/** Per Codex owner job: the binary, its catalog and ~/.codex, or undefined. */
|
|
299
333
|
async codexReady(env, tested) {
|
|
300
334
|
// Fail closed: a claim without the server's list (an older server) never
|
|
@@ -22,7 +22,26 @@ export const HOLD_MS = 14 * 60_000;
|
|
|
22
22
|
const TOUCH_MS = 20_000;
|
|
23
23
|
export const HOOK_FAILED = "The room safety check could not run, so this action is blocked. Tell the owner and do not retry.";
|
|
24
24
|
const DECLINED = "The owner declined this. Do not retry or work around it; say in your reply what you were trying to do.";
|
|
25
|
+
// The sheet's labels (agent-permissions-dialog.tsx), by the class names the
|
|
26
|
+
// server sends when an Off setting refused an ask (#13236).
|
|
27
|
+
const OFF_LABELS = {
|
|
28
|
+
edit: "Edit files and local git",
|
|
29
|
+
outside: "Outside tools",
|
|
30
|
+
push: "Push to GitHub",
|
|
31
|
+
terminal: "Other terminal commands",
|
|
32
|
+
tests: "Run tests and builds",
|
|
33
|
+
};
|
|
25
34
|
const NO_ANSWER = "The owner did not answer in time. Do not retry; say in your reply what you wanted to do.";
|
|
35
|
+
/** The refusal for an Off setting, or the plain decline when none is named. */
|
|
36
|
+
function refusal(refusedBy) {
|
|
37
|
+
const labels = (refusedBy ?? []).flatMap((name) => OFF_LABELS[name] ?? []);
|
|
38
|
+
if (labels.length === 0) {
|
|
39
|
+
return DECLINED;
|
|
40
|
+
}
|
|
41
|
+
const last = labels.pop();
|
|
42
|
+
const names = labels.length > 0 ? `${labels.join(", ")} and ${last}` : last;
|
|
43
|
+
return `${names} ${labels.length > 0 ? "are" : "is"} Off for this agent, so this is blocked. Nobody declined it. Do not retry or work around it; tell the owner which setting blocks it, and say in your reply what you were trying to do.`;
|
|
44
|
+
}
|
|
26
45
|
function target(input) {
|
|
27
46
|
const raw = [input.command, input.file_path, input.path].find((value) => typeof value === "string");
|
|
28
47
|
// Arguments may hold secrets: keep the first words only.
|
|
@@ -91,22 +110,22 @@ function holdForOwner(socketPath, ask, holdMs) {
|
|
|
91
110
|
const info = lstatSync(socketPath);
|
|
92
111
|
if (!info.isSocket() ||
|
|
93
112
|
(process.getuid && info.uid !== process.getuid())) {
|
|
94
|
-
resolve("expired");
|
|
113
|
+
resolve({ answer: "expired" });
|
|
95
114
|
return;
|
|
96
115
|
}
|
|
97
116
|
}
|
|
98
117
|
catch {
|
|
99
|
-
resolve("expired");
|
|
118
|
+
resolve({ answer: "expired" });
|
|
100
119
|
return;
|
|
101
120
|
}
|
|
102
121
|
let settled = false;
|
|
103
122
|
let received = "";
|
|
104
|
-
const finish = (answer) => {
|
|
123
|
+
const finish = (answer, refusedBy) => {
|
|
105
124
|
if (!settled) {
|
|
106
125
|
settled = true;
|
|
107
126
|
socket.destroy();
|
|
108
127
|
clearTimeout(timer);
|
|
109
|
-
resolve(answer);
|
|
128
|
+
resolve({ answer, refusedBy });
|
|
110
129
|
}
|
|
111
130
|
};
|
|
112
131
|
const socket = connect(socketPath);
|
|
@@ -124,8 +143,10 @@ function holdForOwner(socketPath, ask, holdMs) {
|
|
|
124
143
|
received += chunk;
|
|
125
144
|
if (received.includes("\n")) {
|
|
126
145
|
try {
|
|
127
|
-
const { status } = JSON.parse(received.split("\n")[0] ?? "");
|
|
128
|
-
finish(status === "approved" || status === "denied" ? status : "expired")
|
|
146
|
+
const { refusedBy, status } = JSON.parse(received.split("\n")[0] ?? "");
|
|
147
|
+
finish(status === "approved" || status === "denied" ? status : "expired", Array.isArray(refusedBy)
|
|
148
|
+
? refusedBy.filter((name) => typeof name === "string")
|
|
149
|
+
: undefined);
|
|
129
150
|
}
|
|
130
151
|
catch {
|
|
131
152
|
finish("expired");
|
|
@@ -161,13 +182,15 @@ export async function runHook(jobDir, raw, holdMs = HOLD_MS) {
|
|
|
161
182
|
const policy = {
|
|
162
183
|
dirty: existsSync(join(jobDir, "dirty")),
|
|
163
184
|
home: context.home,
|
|
185
|
+
roomId: context.roomId,
|
|
164
186
|
writeRoots: context.writeRoots,
|
|
165
187
|
};
|
|
166
188
|
verdict = classifyCall(call, policy);
|
|
167
189
|
const touches = touchesPrivate(call, policy, verdict.allow);
|
|
168
190
|
const taints = taintsJob(call, policy, verdict.allow ? undefined : verdict.ask);
|
|
169
191
|
if (!verdict.allow && verdict.ask && context.askSocket) {
|
|
170
|
-
|
|
192
|
+
const held = await holdForOwner(context.askSocket, verdict.ask, holdMs);
|
|
193
|
+
asked = held.answer;
|
|
171
194
|
if (asked === "approved") {
|
|
172
195
|
// An approved action may change files; later runs ask accordingly (R5).
|
|
173
196
|
verdict = { allow: true, mutates: true };
|
|
@@ -175,7 +198,7 @@ export async function runHook(jobDir, raw, holdMs = HOLD_MS) {
|
|
|
175
198
|
else {
|
|
176
199
|
verdict = {
|
|
177
200
|
allow: false,
|
|
178
|
-
reason: asked === "denied" ?
|
|
201
|
+
reason: asked === "denied" ? refusal(held.refusedBy) : NO_ANSWER,
|
|
179
202
|
tier: verdict.tier,
|
|
180
203
|
};
|
|
181
204
|
}
|
|
@@ -50,6 +50,7 @@ export async function prepareOwnerLaunch(input) {
|
|
|
50
50
|
await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
|
|
51
51
|
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
52
52
|
home: input.home,
|
|
53
|
+
...(input.roomId ? { roomId: input.roomId } : {}),
|
|
53
54
|
writeRoots: input.workspace.writeRoots,
|
|
54
55
|
}));
|
|
55
56
|
await writePrivateFile(join(jobDir, "settings.json"), JSON.stringify({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { existsSync, readdirSync, readFileSync, realpathSync, statSync, } from "node:fs";
|
|
2
|
-
import { basename, dirname, join, sep } from "node:path";
|
|
3
|
+
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
3
4
|
import { ROOM_LOCAL_TOOLS, ROOM_TOOLS } from "../codex-policy.js";
|
|
4
5
|
import { canonical, inGitDir, isInside, protectedPaths, protectedReason, reachesProtected, WRITE_PROTECTED_SEGMENTS, } from "./paths.js";
|
|
5
6
|
import { parseShell } from "./shell.js";
|
|
@@ -888,6 +889,10 @@ function hookSetup(ctx) {
|
|
|
888
889
|
for (const [, value] of configText(config, ctx.home).matchAll(HOOKS_PATH)) {
|
|
889
890
|
if (value) {
|
|
890
891
|
folders.push(canonical(value, top, ctx.home));
|
|
892
|
+
// Husky locates the user script from $0, before following folder links.
|
|
893
|
+
setup.folders.push(value === "~" || value.startsWith("~/")
|
|
894
|
+
? join(ctx.home, value.slice(1))
|
|
895
|
+
: resolve(top, value));
|
|
891
896
|
}
|
|
892
897
|
}
|
|
893
898
|
}
|
|
@@ -937,16 +942,59 @@ function hookConfig(real, ctx, content) {
|
|
|
937
942
|
PACKAGE_HOOK_KEY.test(content) ||
|
|
938
943
|
PACKAGE_HOOK_KEY.test(readText(real))));
|
|
939
944
|
}
|
|
940
|
-
//
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
945
|
+
// Pull includes both paths: config can select rebase without a CLI flag.
|
|
946
|
+
const GIT_HOOKS = {
|
|
947
|
+
commit: [
|
|
948
|
+
"pre-commit",
|
|
949
|
+
"prepare-commit-msg",
|
|
950
|
+
"commit-msg",
|
|
951
|
+
"post-commit",
|
|
952
|
+
"post-rewrite",
|
|
953
|
+
],
|
|
954
|
+
push: ["pre-push"],
|
|
955
|
+
checkout: ["post-checkout"],
|
|
956
|
+
switch: ["post-checkout"],
|
|
957
|
+
restore: ["post-checkout"],
|
|
958
|
+
pull: [
|
|
959
|
+
"post-merge",
|
|
960
|
+
"pre-merge-commit",
|
|
961
|
+
"prepare-commit-msg",
|
|
962
|
+
"commit-msg",
|
|
963
|
+
"pre-rebase",
|
|
964
|
+
"post-rewrite",
|
|
965
|
+
"post-checkout",
|
|
966
|
+
],
|
|
967
|
+
};
|
|
968
|
+
// Husky 9.1.7 exits before loading init code when the user's script is absent.
|
|
969
|
+
// Pin both helper and stub: a replacement may run code without that script.
|
|
970
|
+
const HUSKY_HELPER_SHA256 = "70200b200ca709b0622784f93839a5b2872333a917a09afddefd7dc2d8cdc680";
|
|
971
|
+
const HUSKY_STUB = '#!/usr/bin/env sh\n. "$(dirname "$0")/h"';
|
|
972
|
+
function hookMayExist(path) {
|
|
973
|
+
try {
|
|
974
|
+
statSync(path);
|
|
975
|
+
return true;
|
|
976
|
+
}
|
|
977
|
+
catch (error) {
|
|
978
|
+
return error.code !== "ENOENT";
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
function gitHookRuns(folder, name) {
|
|
982
|
+
const hook = join(folder, name);
|
|
983
|
+
if (!hookMayExist(hook)) {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
return (readText(hook) !== HUSKY_STUB ||
|
|
987
|
+
createHash("sha256")
|
|
988
|
+
.update(readText(join(folder, "h")))
|
|
989
|
+
.digest("hex") !== HUSKY_HELPER_SHA256 ||
|
|
990
|
+
hookMayExist(join(dirname(folder), name)));
|
|
991
|
+
}
|
|
992
|
+
function gitRunsHooks(sub, ctx) {
|
|
993
|
+
const hooks = GIT_HOOKS[sub];
|
|
994
|
+
if (!hooks) {
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
return hookSetup(ctx).folders.some((folder) => hooks.some((name) => gitHookRuns(folder, name)));
|
|
950
998
|
}
|
|
951
999
|
// A clone into a folder that holds a hooks folder or a hook config's target
|
|
952
1000
|
// fills it from the clone (#13118).
|
|
@@ -1019,12 +1067,12 @@ function shellAsk(command, ctx) {
|
|
|
1019
1067
|
holdsHooks(word.text, ctx)))) {
|
|
1020
1068
|
tier = 1;
|
|
1021
1069
|
}
|
|
1022
|
-
// R5 for
|
|
1070
|
+
// R5 for git hooks (#13115, #13440): after an edit, hooks load configs
|
|
1023
1071
|
// and tests the model may have changed, so it also needs the owner's tests
|
|
1024
1072
|
// consent. The server reads `run:hooks` as the tests class.
|
|
1025
1073
|
return {
|
|
1026
|
-
kind:
|
|
1027
|
-
?
|
|
1074
|
+
kind: tier === 2 && ctx.dirty && gitRunsHooks(sub, ctx)
|
|
1075
|
+
? `git:${sub} + run:hooks`
|
|
1028
1076
|
: `git:${sub}`,
|
|
1029
1077
|
tier,
|
|
1030
1078
|
};
|