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.
@@ -11,7 +11,9 @@ 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
13
  import { CodexBoundaryError, probeCodexBoundary } from "./codex-probe.js";
14
+ import { prepareCodexOwnerLaunch } from "./native/codex-launch.js";
14
15
  import { prepareOwnerLaunch } from "./native/launch.js";
16
+ import { readReceipts } from "./native/receipts.js";
15
17
  const CHILD_ENV = [
16
18
  "HOME",
17
19
  "PATH",
@@ -205,6 +207,29 @@ export async function runProvider(input) {
205
207
  jobId: job.jobId,
206
208
  prompt,
207
209
  sessionId,
210
+ sharedRoom: job.native?.sharedRoom,
211
+ workspace: input.owner.workspace,
212
+ });
213
+ command = binary;
214
+ args = ownerLaunch.args;
215
+ }
216
+ else if (input.owner && config.provider === "codex" && input.owner.codex) {
217
+ const watching = await input.owner.watch?.();
218
+ stopWatching = watching?.stop;
219
+ ownerLaunch = await prepareCodexOwnerLaunch({
220
+ agentId: config.agentId,
221
+ askSocket: watching?.socketPath,
222
+ binary: input.owner.codex.binary,
223
+ bundledCatalog: input.owner.codex.bundledCatalog,
224
+ directory: dirname(workDir),
225
+ env: input.owner.env,
226
+ home: input.owner.home,
227
+ instructions,
228
+ jobId: job.jobId,
229
+ prompt,
230
+ sessionId,
231
+ sharedRoom: job.native?.sharedRoom,
232
+ signal,
208
233
  workspace: input.owner.workspace,
209
234
  });
210
235
  command = binary;
@@ -375,6 +400,12 @@ export async function runProvider(input) {
375
400
  await rm(mcpPath, { force: true });
376
401
  await rm(catalogPath, { force: true });
377
402
  stopWatching?.();
403
+ if (ownerLaunch && input.receipts) {
404
+ // Best effort: a lost record never changes how the job ended.
405
+ await readReceipts(ownerLaunch.jobDir)
406
+ .then((rows) => (rows.length > 0 ? input.receipts?.(rows) : undefined))
407
+ .catch(() => undefined);
408
+ }
378
409
  await ownerLaunch?.cleanup();
379
410
  }
380
411
  }
@@ -1,3 +1,6 @@
1
+ // Served by our LOCAL stdio proxy in an owner-native Codex job, not by the
2
+ // server: the shell fence (#10987). The proxy classifies the command.
3
+ export const ROOM_LOCAL_TOOLS = ["run_command"];
1
4
  export const ROOM_TOOLS = [
2
5
  "list_rooms",
3
6
  "read_room",
@@ -36,7 +36,11 @@ export class AgentGateway {
36
36
  }
37
37
  return response.status === 204 ? null : (await response.json());
38
38
  }
39
- async subscribe(wake, fallback) {
39
+ async subscribe(wake, fallback,
40
+ // Jobs of this agent that were cancelled (the owner's Stop): end them now.
41
+ stopped,
42
+ // The owner opened "Add project" or removed one: serve it from this computer.
43
+ projectRequests) {
40
44
  const initial = await this.request("/agent-gateway/token");
41
45
  if (!(initial && isSecureUrl(new URL(initial.convexUrl)))) {
42
46
  throw new Error("Agent push is unavailable.");
@@ -62,8 +66,20 @@ export class AgentGateway {
62
66
  wake();
63
67
  }
64
68
  }, () => fallback());
69
+ const unsubscribeStops = stopped
70
+ ? client.onUpdate(makeFunctionReference("externalAgents/jobs:jobControl"), {}, (jobIds) => stopped(jobIds), () => undefined)
71
+ : undefined;
72
+ const unsubscribeProjects = projectRequests
73
+ ? client.onUpdate(makeFunctionReference("externalAgents/projects:requestsForAgent"), {}, (count) => {
74
+ if (count > 0) {
75
+ projectRequests();
76
+ }
77
+ }, () => undefined)
78
+ : undefined;
65
79
  return async () => {
66
80
  unsubscribe();
81
+ unsubscribeStops?.();
82
+ unsubscribeProjects?.();
67
83
  await client.close();
68
84
  };
69
85
  }
@@ -11,4 +11,7 @@ if (!config) {
11
11
  }
12
12
  await startMcpProxy(new AgentClient({ apiUrl: config.apiUrl, apiKey: config.apiKey }),
13
13
  // The launcher names the job's workspace; a job with none uploads nothing.
14
- options["upload-root"]);
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,18 @@ const MAX_LINE = 4096;
18
18
  const asAnswer = (status) => status === "approved" || status === "denied" || status === "expired"
19
19
  ? status
20
20
  : undefined;
21
+ function parseReport(line) {
22
+ try {
23
+ const value = JSON.parse(line);
24
+ if (value.touch === true || value.taint === true) {
25
+ return { taint: value.taint === true, touch: value.touch === true };
26
+ }
27
+ }
28
+ catch {
29
+ // Not a report.
30
+ }
31
+ return;
32
+ }
21
33
  function parseAsk(line) {
22
34
  try {
23
35
  const value = JSON.parse(line);
@@ -46,6 +58,10 @@ export class ApprovalBridge {
46
58
  onWaiting;
47
59
  statusEveryMs;
48
60
  waiters = new Map();
61
+ reported = {
62
+ taint: undefined,
63
+ touch: undefined,
64
+ };
49
65
  waiting = false;
50
66
  polling = false;
51
67
  lastPollAt = 0;
@@ -96,8 +112,14 @@ export class ApprovalBridge {
96
112
  if (end < 0) {
97
113
  return;
98
114
  }
99
- const ask = parseAsk(buffer.slice(0, end));
115
+ const line = buffer.slice(0, end);
100
116
  buffer = "";
117
+ const report = parseReport(line);
118
+ if (report) {
119
+ this.report(report, socket);
120
+ return;
121
+ }
122
+ const ask = parseAsk(line);
101
123
  if (!ask) {
102
124
  socket.destroy();
103
125
  return;
@@ -114,6 +136,36 @@ export class ApprovalBridge {
114
136
  this.signal();
115
137
  });
116
138
  }
139
+ // Each flag is reported once per job; every later hook gets the cached
140
+ // answer. A failed report is retried by the next call, and the hook that
141
+ // asked is refused until one lands.
142
+ report(flags, socket) {
143
+ const need = {
144
+ taint: flags.taint && !this.reported.taint,
145
+ touch: flags.touch && !this.reported.touch,
146
+ };
147
+ if (need.taint || need.touch) {
148
+ const request = this.gateway.touch(need).catch((error) => {
149
+ for (const key of ["taint", "touch"]) {
150
+ if (need[key]) {
151
+ this.reported[key] = undefined;
152
+ }
153
+ }
154
+ throw error;
155
+ });
156
+ for (const key of ["taint", "touch"]) {
157
+ if (need[key]) {
158
+ this.reported[key] = request;
159
+ }
160
+ }
161
+ }
162
+ const pending = ["taint", "touch"].flatMap((key) => flags[key] && this.reported[key]
163
+ ? [this.reported[key]]
164
+ : []);
165
+ Promise.all(pending)
166
+ .then(() => socket.end(`${JSON.stringify({ touched: true })}\n`))
167
+ .catch(() => socket.destroy());
168
+ }
117
169
  async forward(ask, socket) {
118
170
  try {
119
171
  const { status } = await this.gateway.request(ask);