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,111 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { realpathSync, statSync } from "node:fs";
3
+ import { readFile } from "node:fs/promises";
4
+ import { basename, join } from "node:path";
5
+ import { isMissing, writePrivateFile } from "../../agent-config.js";
6
+ import { readNativeConfig, repoRoot, rootProblem, } from "./config.js";
7
+ export const PROJECTS_FILE = "projects.json";
8
+ export const PROJECTS_MAX = 20;
9
+ const PROJECT_ID = /^[a-f\d]{32}$/u;
10
+ /** 128 random bits; never derived from the path. */
11
+ export const newProjectId = () => randomBytes(16).toString("hex");
12
+ export const isProjectId = (value) => typeof value === "string" && PROJECT_ID.test(value);
13
+ function valid(value) {
14
+ return (isProjectId(value.id) &&
15
+ typeof value.name === "string" &&
16
+ typeof value.root === "string" &&
17
+ (value.kind === "repo" || value.kind === "managed") &&
18
+ typeof value.dev === "number" &&
19
+ typeof value.ino === "number");
20
+ }
21
+ async function writeProjects(directory, projects) {
22
+ await writePrivateFile(join(directory, PROJECTS_FILE), `${JSON.stringify({ projects })}\n`);
23
+ }
24
+ /**
25
+ * The registry. With none yet, the root `native enable` chose becomes project
26
+ * #1, so a setup from before projects keeps working unchanged.
27
+ */
28
+ export async function readProjects(directory) {
29
+ try {
30
+ const value = JSON.parse(await readFile(join(directory, PROJECTS_FILE), "utf8"));
31
+ return (Array.isArray(value.projects) ? value.projects : [])
32
+ .filter(valid)
33
+ .slice(0, PROJECTS_MAX);
34
+ }
35
+ catch (error) {
36
+ if (!(isMissing(error) || error instanceof SyntaxError)) {
37
+ throw error;
38
+ }
39
+ }
40
+ const config = await readNativeConfig(directory);
41
+ if (!config) {
42
+ return [];
43
+ }
44
+ const projects = [
45
+ { ...rootOf(config), id: newProjectId(), legacy: true },
46
+ ];
47
+ await writeProjects(directory, projects);
48
+ return projects;
49
+ }
50
+ function rootOf(config) {
51
+ return {
52
+ dev: config.dev,
53
+ ino: config.ino,
54
+ kind: config.kind,
55
+ name: config.kind === "repo" ? basename(config.root) : "TalentOS folder",
56
+ root: config.root,
57
+ };
58
+ }
59
+ /** Adds a checked root once; the same folder again returns the project it has. */
60
+ export async function registerRoot(directory, config, name) {
61
+ const projects = await readProjects(directory);
62
+ const known = projects.find((project) => project.root === config.root);
63
+ if (known) {
64
+ return known;
65
+ }
66
+ if (projects.length >= PROJECTS_MAX) {
67
+ throw new Error(`An agent can have ${PROJECTS_MAX} projects. Remove one first.`);
68
+ }
69
+ const project = {
70
+ ...rootOf(config),
71
+ ...(name ? { name } : {}),
72
+ id: newProjectId(),
73
+ };
74
+ await writeProjects(directory, [...projects, project]);
75
+ return project;
76
+ }
77
+ /**
78
+ * The repo that contains `folder`, checked like `native enable` checks its
79
+ * root: a git top level, the same folder by device and inode, yours, and
80
+ * neither home, `/` nor anything holding credentials. Throws a plain reason.
81
+ */
82
+ export async function checkRepo(folder, home) {
83
+ const top = await repoRoot(folder);
84
+ if (!top) {
85
+ throw new Error("That folder isn't in a git repository.");
86
+ }
87
+ const root = realpathSync.native(top);
88
+ const stats = statSync(root);
89
+ const config = {
90
+ dev: stats.dev,
91
+ ino: stats.ino,
92
+ kind: "repo",
93
+ root,
94
+ };
95
+ const problem = rootProblem(config, home);
96
+ if (problem) {
97
+ throw new Error(problem);
98
+ }
99
+ return config;
100
+ }
101
+ export async function removeProject(directory, id) {
102
+ const projects = await readProjects(directory);
103
+ const kept = projects.filter((project) => project.id !== id);
104
+ if (kept.length === projects.length) {
105
+ return false;
106
+ }
107
+ await writeProjects(directory, kept);
108
+ return true;
109
+ }
110
+ /** What the server may know: ids and names, never a path. */
111
+ export const mirrorOf = (projects) => projects.map(({ id, name }) => ({ id, name }));
@@ -0,0 +1,47 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { redactSummary } from "./policy.js";
4
+ export const RECEIPT_ROWS_MAX = 500;
5
+ const TARGET_MAX = 120;
6
+ const TOOL_MAX = 80;
7
+ const ASKED = new Set(["approved", "denied", "expired"]);
8
+ export async function readReceipts(jobDir) {
9
+ let raw;
10
+ try {
11
+ raw = await readFile(join(jobDir, "calls.jsonl"), "utf8");
12
+ }
13
+ catch {
14
+ return [];
15
+ }
16
+ const rows = [];
17
+ for (const line of raw.split("\n")) {
18
+ if (rows.length >= RECEIPT_ROWS_MAX) {
19
+ break;
20
+ }
21
+ try {
22
+ const value = JSON.parse(line);
23
+ const decision = value.decision;
24
+ if (typeof value.tool === "string" &&
25
+ typeof value.at === "number" &&
26
+ typeof value.tier === "number" &&
27
+ (decision === "allow" || decision === "deny")) {
28
+ rows.push({
29
+ ...(typeof value.asked === "string" && ASKED.has(value.asked)
30
+ ? { asked: value.asked }
31
+ : {}),
32
+ at: value.at,
33
+ decision,
34
+ seq: rows.length,
35
+ subagent: value.subagent === true,
36
+ target: redactSummary(typeof value.target === "string" ? value.target : "").slice(0, TARGET_MAX),
37
+ tier: value.tier,
38
+ tool: value.tool.slice(0, TOOL_MAX),
39
+ });
40
+ }
41
+ }
42
+ catch {
43
+ // A torn last line from a killed hook is not a receipt.
44
+ }
45
+ }
46
+ return rows;
47
+ }
@@ -0,0 +1,153 @@
1
+ import { canonical, isInside } from "./paths.js";
2
+ import { applyPatchPaths, } from "./policy.js";
3
+ import { parseShell } from "./shell.js";
4
+ // "Private-touched" (#10987 PR 2b, R12 R1): did this call reach into the owner's
5
+ // own setup, so that what it returns may be private? The server holds back what
6
+ // such a job writes into a room with other people until the owner reviews it.
7
+ //
8
+ // Allowlist-shaped like the policy: a call is NOT private only when it is
9
+ // recognised as staying inside the job's workspace or using the room's own
10
+ // tools. Anything else (any other MCP tool, a web fetch, a read outside the
11
+ // workspace, a command the policy had to ask about, a tool we do not know)
12
+ // counts as touched. A false "touched" costs the owner one tap; a false
13
+ // "untouched" would post private data, so every doubt resolves to touched.
14
+ const ROOM_SERVER_PREFIX = "mcp__talentos_room__";
15
+ // Tools that read files by path; the path decides.
16
+ const PATH_TOOLS = new Set(["Glob", "Grep", "LS", "NotebookRead", "Read"]);
17
+ const EDIT_TOOLS = new Set(["Edit", "MultiEdit", "NotebookEdit", "Write"]);
18
+ // Tools that touch nothing of the owner's: bookkeeping and public web search.
19
+ // Skill and Agent are NOT here: a skill or subagent is owner-level context the
20
+ // hook cannot see into, so calling one counts as touched (R13 P2-d).
21
+ const NEUTRAL_TOOLS = new Set([
22
+ "AskUserQuestion",
23
+ "BashOutput",
24
+ "ExitPlanMode",
25
+ "KillShell",
26
+ "TaskCreate",
27
+ "TaskGet",
28
+ "TaskList",
29
+ "TaskStop",
30
+ "TaskUpdate",
31
+ "TodoWrite",
32
+ "ToolSearch",
33
+ "WebSearch",
34
+ ]);
35
+ const GLOB_CHARS = /[*?[{]/u;
36
+ const PATH_START = /[/~]/u;
37
+ function text(value) {
38
+ return typeof value === "string" && value.length > 0 ? value : undefined;
39
+ }
40
+ export function touchesPrivate(call, context, allowedByPolicy) {
41
+ // The policy had to ask the owner: it is outward, irreversible or unknown, and
42
+ // once approved it may read anything.
43
+ if (!allowedByPolicy) {
44
+ return true;
45
+ }
46
+ const { tool, toolInput: input } = call;
47
+ const inside = (path, base = call.cwd) => {
48
+ if (path.startsWith("~") && path !== "~" && !path.startsWith("~/")) {
49
+ return false;
50
+ }
51
+ const real = canonical(path, base, context.home);
52
+ return context.writeRoots.some((root) => isInside(real, root));
53
+ };
54
+ if (tool.startsWith("mcp__")) {
55
+ return !tool.startsWith(ROOM_SERVER_PREFIX);
56
+ }
57
+ if (NEUTRAL_TOOLS.has(tool)) {
58
+ return false;
59
+ }
60
+ // Codex's apply_patch touches private setup only if a path leaves the
61
+ // workspace; view_image is a read, touched when the image is outside it.
62
+ if (tool === "apply_patch") {
63
+ return applyPatchPaths(text(input.command)).some((path) => !inside(path));
64
+ }
65
+ if (tool === "view_image") {
66
+ const path = text(input.path) ?? text(input.file_path);
67
+ return path === undefined ? true : !inside(path);
68
+ }
69
+ if (PATH_TOOLS.has(tool) || EDIT_TOOLS.has(tool)) {
70
+ const paths = [
71
+ text(input.file_path),
72
+ text(input.notebook_path),
73
+ text(input.path),
74
+ // A glob pattern is judged by its literal directory prefix.
75
+ tool === "Glob"
76
+ ? (text(input.pattern)?.split(GLOB_CHARS)[0] ?? undefined)
77
+ : undefined,
78
+ ].filter((path) => path !== undefined);
79
+ if (paths.length === 0) {
80
+ return !inside(".");
81
+ }
82
+ return paths.some((path) => !inside(path));
83
+ }
84
+ if (tool === "Bash") {
85
+ return shellTouchesPrivate(text(input.command), inside, call.cwd, context.home);
86
+ }
87
+ // WebFetch and every tool this list does not know.
88
+ return true;
89
+ }
90
+ const isRun = (part) => part.startsWith("run:");
91
+ /**
92
+ * Did this call pull untrusted input into the job (Auto mode, R13)? Anything
93
+ * the owner's private setup touch covers, plus web search and any serious
94
+ * (tier 1) action the owner approved. After the first, tests and builds ask
95
+ * again for the rest of the job and the thread.
96
+ */
97
+ export function taintsJob(call, context, asked) {
98
+ return (call.tool === "WebSearch" ||
99
+ // A test or build the owner (or Auto mode) allowed brings in nothing; any
100
+ // other serious action does.
101
+ (asked?.tier === 1 && !asked.kind.split(" + ").every(isRun)) ||
102
+ touchesPrivate(call, context, true));
103
+ }
104
+ function shellTouchesPrivate(source, inside, cwd, home) {
105
+ const parsed = source ? parseShell(source) : undefined;
106
+ if (!(parsed?.ok && inside("."))) {
107
+ return true;
108
+ }
109
+ // `cd dir && ...`: later paths resolve from where the command moved to.
110
+ let base = cwd;
111
+ for (const command of parsed.commands) {
112
+ const words = command.argv.slice(1);
113
+ if (command.argv[0]?.text === "cd") {
114
+ const target = words[0];
115
+ if (!target ||
116
+ words.length > 1 ||
117
+ target.glob ||
118
+ !inside(target.text, base)) {
119
+ return true;
120
+ }
121
+ base = canonical(target.text, base, home);
122
+ continue;
123
+ }
124
+ for (const word of words) {
125
+ if (word.text.startsWith("-")) {
126
+ // `--git-dir=/x` and `-C/x` carry a path inside the flag.
127
+ const start = word.text.search(PATH_START);
128
+ if (start > 0 && !inside(word.text.slice(start), base)) {
129
+ return true;
130
+ }
131
+ continue;
132
+ }
133
+ if (word.glob) {
134
+ // A relative glob stays in the working directory; anything else cannot
135
+ // be judged from its literal prefix.
136
+ if (PATH_START.test(word.text.charAt(0)) || word.text.includes("..")) {
137
+ return true;
138
+ }
139
+ continue;
140
+ }
141
+ if (!inside(word.text, base)) {
142
+ return true;
143
+ }
144
+ }
145
+ for (const redirect of command.redirects) {
146
+ if (redirect.target.text !== "/dev/null" &&
147
+ !inside(redirect.target.text, base)) {
148
+ return true;
149
+ }
150
+ }
151
+ }
152
+ return false;
153
+ }
@@ -4,6 +4,7 @@ import { mkdirSync, realpathSync, statSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { promisify } from "node:util";
6
6
  import { rootProblem } from "./config.js";
7
+ import { freshBase, SAFE_GIT } from "./fresh.js";
7
8
  import { canonical, isInside } from "./paths.js";
8
9
  const exec = promisify(execFile);
9
10
  const safeId = (value, length) => value
@@ -41,8 +42,9 @@ export async function prepareWorkspace(input) {
41
42
  if (!inside(cwd)) {
42
43
  throw new Error("The workspace left its folder.");
43
44
  }
45
+ let base;
44
46
  if (useWorktree) {
45
- await ensureWorktree(config.root, cwd, thread);
47
+ base = await ensureWorktree(config.root, cwd, thread, input);
46
48
  }
47
49
  else {
48
50
  mkdirSync(cwd, { recursive: true, mode: 0o700 });
@@ -51,7 +53,7 @@ export async function prepareWorkspace(input) {
51
53
  if (!(statSync(real).isDirectory() && inside(real))) {
52
54
  throw new Error("The workspace left its folder.");
53
55
  }
54
- return { cwd: real, writeRoots: [real] };
56
+ return { cwd: real, writeRoots: [real], ...(base ? { base } : {}) };
55
57
  }
56
58
  async function hasCommit(root) {
57
59
  try {
@@ -65,7 +67,7 @@ async function hasCommit(root) {
65
67
  return false;
66
68
  }
67
69
  }
68
- async function ensureWorktree(root, path, thread) {
70
+ async function ensureWorktree(root, path, thread, fresh) {
69
71
  try {
70
72
  if (statSync(path).isDirectory()) {
71
73
  return;
@@ -77,11 +79,24 @@ async function ensureWorktree(root, path, thread) {
77
79
  mkdirSync(join(path, ".."), { recursive: true, mode: 0o700 });
78
80
  const branch = `talentos/${thread}`;
79
81
  const options = { cwd: root, timeout: 60_000 };
82
+ const base = await freshBase(root, fresh);
80
83
  try {
81
- await exec("git", ["worktree", "add", "-b", branch, path, "HEAD"], options);
84
+ // No upstream: a bare `git push` from the thread can never target main.
85
+ await exec("git", [
86
+ ...SAFE_GIT,
87
+ "worktree",
88
+ "add",
89
+ "--no-track",
90
+ "-b",
91
+ branch,
92
+ path,
93
+ base.start,
94
+ ], options);
95
+ return base;
82
96
  }
83
97
  catch {
84
98
  // The branch survives a deleted folder: reattach it.
85
- await exec("git", ["worktree", "add", path, branch], options);
99
+ await exec("git", [...SAFE_GIT, "worktree", "add", path, branch], options);
100
+ return;
86
101
  }
87
102
  }
@@ -2,13 +2,15 @@ import { randomUUID } from "node:crypto";
2
2
  import { mkdir, open, readFile, rm } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { setTimeout as delay } from "node:timers/promises";
5
- import { installSharedGateway } from "../gateway-install.js";
5
+ import { installSharedGateway, newerInstalledVersion, } from "../gateway-install.js";
6
6
  import { compareGatewayVersions } from "../gateway-version.js";
7
7
  import { homeDir } from "../install.js";
8
8
  import { runProvider } from "./adapters.js";
9
9
  import { AgentGateway, GatewayError } from "./gateway.js";
10
10
  import { ApprovalBridge } from "./native/approvals.js";
11
11
  import { NativeGate } from "./native/gate.js";
12
+ import { ProjectRequests } from "./native/project-requests.js";
13
+ import { mirrorOf } from "./native/projects.js";
12
14
  import { SessionMap } from "./sessions.js";
13
15
  const HEARTBEAT_MS = 20_000;
14
16
  const LEASE_SAFETY_MS = 55_000;
@@ -88,16 +90,40 @@ export async function serveAgent(config, directory, version, stop, verify, optio
88
90
  wake();
89
91
  }
90
92
  };
93
+ let requests;
91
94
  const heartbeat = async () => {
92
95
  gate.refresh();
93
- const response = await gateway.request("/agent-gateway/heartbeat", { cliVersion: version, nativeOptIn: gate.reportable() }, signal);
96
+ // Ids and names only; a registry that cannot be read is not sent.
97
+ const mirror = gate.projects
98
+ ? await gate
99
+ .projects()
100
+ .then(mirrorOf)
101
+ .catch(() => undefined)
102
+ : undefined;
103
+ const response = await gateway.request("/agent-gateway/heartbeat", {
104
+ cliVersion: version,
105
+ nativeOptIn: gate.reportable(),
106
+ ...(mirror ? { projects: mirror } : {}),
107
+ }, signal);
94
108
  if (response) {
95
109
  minimum = response.cliMinVersion;
96
110
  if (response.pendingJobs > 0 || needsUpdate(version, minimum)) {
97
111
  wake();
98
112
  }
113
+ if ((response.projectRequests ?? 0) > 0) {
114
+ requests?.poke().catch(() => undefined);
115
+ }
99
116
  }
100
117
  };
118
+ requests = gate.projects
119
+ ? new ProjectRequests({
120
+ directory,
121
+ env: () => gate.loginEnv?.() ?? Promise.resolve(process.env),
122
+ home: homeDir(),
123
+ mirror: () => heartbeat(),
124
+ post: (path, body) => gateway.request(path, body, signal),
125
+ })
126
+ : undefined;
101
127
  const heartbeatLoop = async () => {
102
128
  while (!signal.aborted) {
103
129
  const started = Date.now();
@@ -150,14 +176,42 @@ export async function serveAgent(config, directory, version, stop, verify, optio
150
176
  dispose = await gateway.subscribe(wake, () => {
151
177
  push = false;
152
178
  wake();
153
- });
179
+ },
180
+ // The owner's Stop lands in a second or two; the renewal is the backstop.
181
+ (jobIds) => {
182
+ if (active && jobIds.includes(active.job.jobId)) {
183
+ active.cancel.abort();
184
+ }
185
+ }, requests
186
+ ? () => {
187
+ requests?.poke().catch(() => undefined);
188
+ }
189
+ : undefined);
154
190
  }
155
191
  catch (error) {
156
192
  push = false;
157
193
  failService(error);
158
194
  }
159
195
  heartbeats = heartbeatLoop();
196
+ let reexecAfter = 0;
160
197
  while (!signal.aborted) {
198
+ // A repair or update installed a newer gateway while this process kept
199
+ // running the old one: exit between turns so the service relaunches on it.
200
+ if (Date.now() >= reexecAfter && process.platform !== "win32") {
201
+ reexecAfter = Date.now() + 60_000;
202
+ const newer = await newerInstalledVersion(dirname(dirname(dirname(directory))), version).catch(() => undefined);
203
+ if (newer) {
204
+ // launchd and systemd relaunch an exited service; a hand-run serve
205
+ // just ends.
206
+ const supervised = Boolean(process.env.INVOCATION_ID ||
207
+ (process.env.XPC_SERVICE_NAME &&
208
+ process.env.XPC_SERVICE_NAME !== "0"));
209
+ console.error(supervised
210
+ ? `Gateway ${newer} is installed; restarting from ${version}.`
211
+ : `Gateway ${newer} is installed. Stopping ${version}; run talentos agent serve again to use it.`);
212
+ return newer;
213
+ }
214
+ }
161
215
  if (needsUpdate(version, minimum) && Date.now() >= updateAfter) {
162
216
  if (process.platform === "win32") {
163
217
  throw new Error(`Gateway update required; re-run npx talentos@${minimum} agent serve --agent ${config.agentId}. Windows gateways update in the foreground.`);
@@ -177,7 +231,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
177
231
  let job;
178
232
  const claimStartedAt = Date.now();
179
233
  try {
180
- job = await gateway.request("/agent-gateway/claim", { deviceId }, signal);
234
+ job = await gateway.request("/agent-gateway/claim", { cliVersion: version, deviceId }, signal);
181
235
  }
182
236
  catch (error) {
183
237
  failService(error);
@@ -211,16 +265,49 @@ export async function serveAgent(config, directory, version, stop, verify, optio
211
265
  lastStatusAt = Date.now();
212
266
  const [, prepared] = await Promise.all([
213
267
  gateway.request(`/agent-gateway/jobs/${job.jobId}/native-confirm`, { leaseToken: job.leaseToken }, signal),
214
- gate.prepare(job.packet.thread.id).catch(() => undefined),
268
+ gate
269
+ .prepare(job.packet.thread.id, {
270
+ projectId: job.native.projectId,
271
+ status: (line) => {
272
+ lastStatusAt = Date.now();
273
+ post(line);
274
+ },
275
+ })
276
+ .catch(() => undefined),
215
277
  ]);
216
278
  owner = prepared;
217
279
  current.owner = Boolean(owner);
280
+ // In a room with other people the server holds what the job
281
+ // posts unless this computer affirms it started clean: none of
282
+ // the owner's own context loaded, every touch reported. Unknown
283
+ // is reviewed, so a missing or failed word costs one tap.
284
+ if (owner && job.native.sharedRoom && owner.context === false) {
285
+ await gateway
286
+ .request(`/agent-gateway/jobs/${job.jobId}/touch-tracked`, { leaseToken: job.leaseToken }, signal)
287
+ .catch(() => undefined);
288
+ }
218
289
  }
290
+ // A project's sessions are its own; the root from before projects
291
+ // keeps its key so those threads still resume.
219
292
  const sessionKey = owner
220
- ? `${job.packet.thread.id}:owner`
293
+ ? `${job.packet.thread.id}:owner${owner.project.legacy ? "" : `:${owner.project.id}`}`
221
294
  : job.packet.thread.id;
295
+ // Which code the work started from, on the owner's record.
296
+ const base = owner?.workspace.base;
297
+ const baseRow = base && {
298
+ at: Date.now(),
299
+ decision: "allow",
300
+ seq: 0,
301
+ subagent: false,
302
+ target: base.receipt,
303
+ tier: 0,
304
+ tool: "Workspace",
305
+ };
222
306
  const bridge = () => new ApprovalBridge({
223
307
  gateway: {
308
+ touch: async (flags) => {
309
+ await gateway.request(`/agent-gateway/jobs/${job.jobId}/private-touch`, { leaseToken: job.leaseToken, ...flags }, signal);
310
+ },
224
311
  request: async (ask) => (await gateway.request(`/agent-gateway/jobs/${job.jobId}/approval-request`, { leaseToken: job.leaseToken, ...ask }, signal)) ?? { status: "expired" },
225
312
  status: async (actionKeys) => (await gateway.request(`/agent-gateway/jobs/${job.jobId}/approval-status`, { actionKeys, leaseToken: job.leaseToken }, signal)) ?? [],
226
313
  },
@@ -245,6 +332,18 @@ export async function serveAgent(config, directory, version, stop, verify, optio
245
332
  remember: async (sessionId) => {
246
333
  await sessions.remember(sessionKey, sessionId);
247
334
  },
335
+ receipts: async (hookRows) => {
336
+ const rows = baseRow
337
+ ? [baseRow, ...hookRows].map((row, seq) => ({ ...row, seq }))
338
+ : hookRows;
339
+ // The gateway body limit is 32 kB: 50 rows of at most ~250 B.
340
+ for (let at = 0; at < rows.length; at += 50) {
341
+ await gateway.request(`/agent-gateway/jobs/${job.jobId}/receipts`, {
342
+ leaseToken: job.leaseToken,
343
+ rows: rows.slice(at, at + 50),
344
+ }, signal);
345
+ }
346
+ },
248
347
  mark: (name) => {
249
348
  timings[`${name}Ms`] = Math.round(performance.now() - receivedAt);
250
349
  },
@@ -48,7 +48,13 @@ export async function installAgentService(agent, options = {}) {
48
48
  const domain = `gui/${options.uid ?? process.getuid?.() ?? 0}`;
49
49
  const loaded = run("launchctl", ["print", `${domain}/${name}`]) === 0;
50
50
  if (loaded && !changed) {
51
- return { path, started: true };
51
+ // The plist is unchanged but the CLI it launches may not be: a running
52
+ // service keeps its old code until it restarts. Kickstart bypasses launchd's
53
+ // throttle and relaunches through the launcher onto cli/current.
54
+ return {
55
+ path,
56
+ started: run("launchctl", ["kickstart", "-k", `${domain}/${name}`]) === 0,
57
+ };
52
58
  }
53
59
  if (loaded) {
54
60
  run("launchctl", ["bootout", domain, path]);
@@ -61,6 +67,13 @@ export async function installAgentService(agent, options = {}) {
61
67
  if (changed && run("systemctl", ["--user", "daemon-reload"]) !== 0) {
62
68
  return { path, started: false };
63
69
  }
70
+ // Restart a running service onto the freshly installed CLI; a stopped one is
71
+ // left for `enable --now` to start.
72
+ run("systemctl", [
73
+ "--user",
74
+ "try-restart",
75
+ `talentos-agent@${agent.agentId}.service`,
76
+ ]);
64
77
  return {
65
78
  path,
66
79
  started: run("systemctl", [
package/dist/args.js CHANGED
@@ -23,6 +23,7 @@ const CLI_OPTIONS = {
23
23
  yes: { type: "boolean" },
24
24
  agent: { type: "string" },
25
25
  "upload-root": { type: "string" },
26
+ "owner-job-dir": { type: "string" },
26
27
  };
27
28
  /** Groups whose first positional is a sub-command rather than an argument. */
28
29
  const ACTION_GROUPS = new Set(["agent", "mcp", "skills", "memory", "routines"]);