talentos 1.4.19 → 1.4.21
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/adapters.js +10 -3
- package/dist/agent/codex-image-probe.js +4 -4
- package/dist/agent/native/codex-fence-probe.js +3 -3
- package/dist/agent/native/codex-fence.js +15 -6
- package/dist/agent/native/codex-launch.js +29 -12
- package/dist/agent/native/codex-owner-images.js +392 -0
- package/dist/agent/native/gate.js +10 -8
- package/dist/agent/native/hook-client.js +118 -0
- package/dist/agent/native/hook-denial.js +13 -0
- package/dist/agent/native/hook-entry.js +68 -5
- package/dist/agent/native/launch.js +23 -3
- package/dist/agent/native/owner-pictures.js +66 -0
- package/dist/agent/native/policy.js +16 -0
- package/dist/agent/native/probe.js +6 -2
- package/dist/agent/native/receipts.js +102 -0
- package/dist/agent/native/touch.js +7 -0
- package/dist/agent/native/workspace.js +68 -16
- package/dist/agent/serve.js +38 -19
- package/dist/mcp-proxy.js +9 -1
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { mkdirSync, realpathSync, statSync } from "node:fs";
|
|
4
|
-
import { join } from "node:path";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
|
+
import { isMissing } from "../../agent-config.js";
|
|
6
7
|
import { rootProblem } from "./config.js";
|
|
7
8
|
import { freshBase, SAFE_GIT } from "./fresh.js";
|
|
8
|
-
import { canonical, isInside } from "./paths.js";
|
|
9
|
+
import { canonical, fold, isInside } from "./paths.js";
|
|
9
10
|
const exec = promisify(execFile);
|
|
10
11
|
const safeId = (value, length) => value
|
|
11
12
|
.replace(/[^a-z\d]/giu, "")
|
|
@@ -53,7 +54,13 @@ export async function prepareWorkspace(input) {
|
|
|
53
54
|
if (!(statSync(real).isDirectory() && inside(real))) {
|
|
54
55
|
throw new Error("The workspace left its folder.");
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
const checkout = useWorktree ? await readCheckout(real) : undefined;
|
|
58
|
+
return {
|
|
59
|
+
...(base ? { base } : {}),
|
|
60
|
+
...(checkout ? { checkout } : {}),
|
|
61
|
+
cwd: real,
|
|
62
|
+
writeRoots: [real],
|
|
63
|
+
};
|
|
57
64
|
}
|
|
58
65
|
async function hasCommit(root) {
|
|
59
66
|
try {
|
|
@@ -70,33 +77,78 @@ async function hasCommit(root) {
|
|
|
70
77
|
async function ensureWorktree(root, path, thread, fresh) {
|
|
71
78
|
try {
|
|
72
79
|
if (statSync(path).isDirectory()) {
|
|
80
|
+
await verifyWorktree(root, path);
|
|
73
81
|
return;
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
|
-
catch {
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (!isMissing(error)) {
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
77
88
|
// Missing: create it below.
|
|
78
89
|
}
|
|
79
90
|
mkdirSync(join(path, ".."), { recursive: true, mode: 0o700 });
|
|
80
91
|
const branch = `talentos/${thread}`;
|
|
81
92
|
const options = { cwd: root, timeout: 60_000 };
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
const exists = await exec("git", [...SAFE_GIT, "show-ref", "--verify", "--quiet", `refs/heads/${branch}`], options).then(() => true, () => false);
|
|
94
|
+
if (exists) {
|
|
95
|
+
const { stdout } = await exec("git", [...SAFE_GIT, "worktree", "list", "--porcelain", "-z"], options);
|
|
96
|
+
const records = stdout.split("\0\0").map((record) => record.split("\0"));
|
|
97
|
+
const registered = records.filter((record) => record.includes(`branch refs/heads/${branch}`));
|
|
98
|
+
if (registered.some((record) => record[0] !== `worktree ${path}` ||
|
|
99
|
+
record.some((field) => field.startsWith("locked")))) {
|
|
100
|
+
throw new Error("The thread's branch is in use by another worktree.");
|
|
101
|
+
}
|
|
102
|
+
// Recover only this thread's missing registration; never prune or force a
|
|
103
|
+
// branch checked out elsewhere, and never reset its committed work.
|
|
85
104
|
await exec("git", [
|
|
86
105
|
...SAFE_GIT,
|
|
87
106
|
"worktree",
|
|
88
107
|
"add",
|
|
89
|
-
"--
|
|
90
|
-
"-b",
|
|
91
|
-
branch,
|
|
108
|
+
...(registered.length > 0 ? ["--force"] : []),
|
|
92
109
|
path,
|
|
93
|
-
|
|
110
|
+
branch,
|
|
94
111
|
], options);
|
|
95
|
-
return base;
|
|
96
|
-
}
|
|
97
|
-
catch {
|
|
98
|
-
// The branch survives a deleted folder: reattach it.
|
|
99
|
-
await exec("git", [...SAFE_GIT, "worktree", "add", path, branch], options);
|
|
100
112
|
return;
|
|
101
113
|
}
|
|
114
|
+
const base = await freshBase(root, fresh);
|
|
115
|
+
// No upstream: a bare `git push` from the thread can never target main.
|
|
116
|
+
await exec("git", [
|
|
117
|
+
...SAFE_GIT,
|
|
118
|
+
"worktree",
|
|
119
|
+
"add",
|
|
120
|
+
"--no-track",
|
|
121
|
+
"-b",
|
|
122
|
+
branch,
|
|
123
|
+
path,
|
|
124
|
+
base.start,
|
|
125
|
+
], options);
|
|
126
|
+
return base;
|
|
127
|
+
}
|
|
128
|
+
async function verifyWorktree(root, path) {
|
|
129
|
+
const options = { timeout: 5000 };
|
|
130
|
+
const [project, workspace] = await Promise.all([
|
|
131
|
+
exec("git", [...SAFE_GIT, "rev-parse", "--git-common-dir"], {
|
|
132
|
+
...options,
|
|
133
|
+
cwd: root,
|
|
134
|
+
}),
|
|
135
|
+
exec("git", [...SAFE_GIT, "rev-parse", "--show-toplevel", "--git-common-dir"], { ...options, cwd: path }),
|
|
136
|
+
]);
|
|
137
|
+
const [top, common] = workspace.stdout.trim().split("\n");
|
|
138
|
+
if (!(top && common) ||
|
|
139
|
+
fold(realpathSync.native(top)) !== fold(realpathSync.native(path)) ||
|
|
140
|
+
fold(realpathSync.native(resolve(path, common))) !==
|
|
141
|
+
fold(realpathSync.native(resolve(root, project.stdout.trim())))) {
|
|
142
|
+
throw new Error("The thread's folder is no longer in the chosen repository.");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export async function readCheckout(cwd) {
|
|
146
|
+
const options = { cwd, timeout: 5000 };
|
|
147
|
+
const [head, branch] = await Promise.all([
|
|
148
|
+
exec("git", [...SAFE_GIT, "rev-parse", "--verify", "HEAD"], options),
|
|
149
|
+
exec("git", [...SAFE_GIT, "symbolic-ref", "--quiet", "--short", "HEAD"], options)
|
|
150
|
+
.then(({ stdout }) => stdout.trim())
|
|
151
|
+
.catch(() => "detached HEAD"),
|
|
152
|
+
]);
|
|
153
|
+
return { branch, commit: head.stdout.trim() };
|
|
102
154
|
}
|
package/dist/agent/serve.js
CHANGED
|
@@ -12,8 +12,10 @@ import { holdMs, renewDelayMs } from "./lease-hold.js";
|
|
|
12
12
|
import { ApprovalBridge } from "./native/approvals.js";
|
|
13
13
|
import { NativeGate, PLAIN_FALLBACK_REASONS } from "./native/gate.js";
|
|
14
14
|
import { ROOM_ONLY_STATUS, roomOnlyStatus } from "./native/native-issue.js";
|
|
15
|
+
import { redactSummary } from "./native/policy.js";
|
|
15
16
|
import { ProjectRequests } from "./native/project-requests.js";
|
|
16
17
|
import { mirrorOf } from "./native/projects.js";
|
|
18
|
+
import { RECEIPT_ROWS_MAX } from "./native/receipts.js";
|
|
17
19
|
import { nodeBlocksUpdate } from "./node-floor.js";
|
|
18
20
|
import { failureReasonOf } from "./provider-failure.js";
|
|
19
21
|
import { ProviderLoginWatch, probeProviderLogin } from "./provider-login.js";
|
|
@@ -406,16 +408,6 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
406
408
|
]);
|
|
407
409
|
owner = prepared;
|
|
408
410
|
current.owner = Boolean(owner);
|
|
409
|
-
// The owner asked for their setup and this computer can't give
|
|
410
|
-
// it: say so in the room (neutral, no version), hold that line a
|
|
411
|
-
// moment, then let progress resume. The owner's Access menu has
|
|
412
|
-
// the detail.
|
|
413
|
-
if (!owner && (gate.issue?.() || fellBack)) {
|
|
414
|
-
post(gate.issue?.()
|
|
415
|
-
? ROOM_ONLY_STATUS
|
|
416
|
-
: roomOnlyStatus(config.provider));
|
|
417
|
-
reasonUntil = Date.now() + fallbackHoldMs;
|
|
418
|
-
}
|
|
419
411
|
// In a room with other people this computer affirms it started
|
|
420
412
|
// clean: none of the owner's own context loaded, every touch
|
|
421
413
|
// reported. The server records it; since #11906 nothing waits on
|
|
@@ -426,17 +418,42 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
426
418
|
.catch(() => undefined);
|
|
427
419
|
}
|
|
428
420
|
}
|
|
421
|
+
if (job.native && !owner) {
|
|
422
|
+
// Reduce the server's grant before launching room-only: otherwise
|
|
423
|
+
// shared-room status and tools still describe a native job.
|
|
424
|
+
const downgrade = await gateway.request(`/agent-gateway/jobs/${job.jobId}/status`, {
|
|
425
|
+
leaseToken: job.leaseToken,
|
|
426
|
+
roomOnly: true,
|
|
427
|
+
statusLine: gate.issue?.()
|
|
428
|
+
? ROOM_ONLY_STATUS
|
|
429
|
+
: roomOnlyStatus(config.provider),
|
|
430
|
+
}, signal);
|
|
431
|
+
if (downgrade?.roomOnly !== true) {
|
|
432
|
+
throw new Error("TalentOS couldn't confirm room-only access. This job did not start.");
|
|
433
|
+
}
|
|
434
|
+
lastStatusAt = Date.now();
|
|
435
|
+
current.job = { ...job, native: undefined };
|
|
436
|
+
current.deadline = lastStatusAt + holdFor(false);
|
|
437
|
+
reasonUntil = lastStatusAt + fallbackHoldMs;
|
|
438
|
+
}
|
|
429
439
|
// Which code the work started from, on the owner's record.
|
|
430
|
-
const base = owner?.workspace
|
|
431
|
-
const
|
|
440
|
+
const { base, checkout } = owner?.workspace ?? {};
|
|
441
|
+
const workspaceRows = [
|
|
442
|
+
...(base ? [base.receipt] : []),
|
|
443
|
+
...(checkout
|
|
444
|
+
? [
|
|
445
|
+
`Checkout ${checkout.branch} at ${checkout.commit.slice(0, 12)}`,
|
|
446
|
+
]
|
|
447
|
+
: []),
|
|
448
|
+
].map((target, seq) => ({
|
|
432
449
|
at: Date.now(),
|
|
433
450
|
decision: "allow",
|
|
434
|
-
seq
|
|
451
|
+
seq,
|
|
435
452
|
subagent: false,
|
|
436
|
-
target:
|
|
453
|
+
target: redactSummary(target).slice(0, 120),
|
|
437
454
|
tier: 0,
|
|
438
455
|
tool: "Workspace",
|
|
439
|
-
};
|
|
456
|
+
}));
|
|
440
457
|
const bridge = () => new ApprovalBridge({
|
|
441
458
|
gateway: {
|
|
442
459
|
touch: async (flags) => {
|
|
@@ -472,10 +489,12 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
472
489
|
// Room tools and the current packet carry continuity. Replaying
|
|
473
490
|
// provider history grows forever and carries stale file copies.
|
|
474
491
|
signal: AbortSignal.any([signal, cancel.signal]),
|
|
475
|
-
receipts: async (hookRows) => {
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
492
|
+
receipts: async (hookRows, resultRows = []) => {
|
|
493
|
+
const hooks = hookRows.slice(0, RECEIPT_ROWS_MAX - workspaceRows.length - resultRows.length);
|
|
494
|
+
const rows = [...workspaceRows, ...hooks, ...resultRows].map((row, seq) => ({
|
|
495
|
+
...row,
|
|
496
|
+
seq,
|
|
497
|
+
}));
|
|
479
498
|
// The gateway body limit is 32 kB: 50 rows of at most ~250 B.
|
|
480
499
|
for (let at = 0; at < rows.length; at += 50) {
|
|
481
500
|
await gateway.request(`/agent-gateway/jobs/${job.jobId}/receipts`, {
|
package/dist/mcp-proxy.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
3
|
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
4
4
|
import { handleRunCommand, RUN_COMMAND_TOOL, stopAllRunCommands, wireShutdown, } from "./agent/native/codex-run-command.js";
|
|
5
|
+
import { ownerPictureRoot } from "./agent/native/owner-pictures.js";
|
|
5
6
|
import { UploadRefusal, uploadFile } from "./upload-file.js";
|
|
6
7
|
// The two server steps behind upload_file. The model sees only upload_file.
|
|
7
8
|
const UPLOAD_STEP_TOOLS = new Set(["prepare_upload", "commit_upload"]);
|
|
@@ -132,7 +133,14 @@ scratch = false) {
|
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
135
|
if (name === "upload_file") {
|
|
135
|
-
|
|
136
|
+
// A picture this owner job's own image call made sits in Codex's folder
|
|
137
|
+
// (owner-pictures.ts), read with the scratch rules, as a fenced job's is.
|
|
138
|
+
const picture = ownerJobDir
|
|
139
|
+
? await ownerPictureRoot(ownerJobDir, String(args.path ?? ""))
|
|
140
|
+
: undefined;
|
|
141
|
+
return picture
|
|
142
|
+
? await runUpload(client, args, picture, true)
|
|
143
|
+
: await runUpload(client, args, root, scratch);
|
|
136
144
|
}
|
|
137
145
|
if (UPLOAD_STEP_TOOLS.has(name)) {
|
|
138
146
|
return {
|
package/package.json
CHANGED