talentos 1.2.0 → 1.3.0
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 +8 -0
- package/dist/agent/gateway.js +7 -1
- package/dist/agent/native/approvals.js +53 -1
- package/dist/agent/native/codex-owner-probe.js +389 -0
- package/dist/agent/native/codex-owner.js +160 -0
- package/dist/agent/native/context.js +92 -0
- package/dist/agent/native/gate.js +11 -1
- package/dist/agent/native/hook-entry.js +65 -3
- package/dist/agent/native/launch.js +10 -1
- package/dist/agent/native/policy.js +283 -20
- package/dist/agent/native/probe.js +18 -15
- package/dist/agent/native/receipts.js +47 -0
- package/dist/agent/native/touch.js +143 -0
- package/dist/agent/serve.js +47 -2
- package/dist/agent-service.js +14 -1
- package/dist/commands/agent-native.js +2 -2
- package/dist/gateway-install.js +15 -0
- package/package.json +1 -1
package/dist/agent/serve.js
CHANGED
|
@@ -2,7 +2,7 @@ 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";
|
|
@@ -150,6 +150,12 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
150
150
|
dispose = await gateway.subscribe(wake, () => {
|
|
151
151
|
push = false;
|
|
152
152
|
wake();
|
|
153
|
+
},
|
|
154
|
+
// The owner's Stop lands in a second or two; the renewal is the backstop.
|
|
155
|
+
(jobIds) => {
|
|
156
|
+
if (active && jobIds.includes(active.job.jobId)) {
|
|
157
|
+
active.cancel.abort();
|
|
158
|
+
}
|
|
153
159
|
});
|
|
154
160
|
}
|
|
155
161
|
catch (error) {
|
|
@@ -157,7 +163,25 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
157
163
|
failService(error);
|
|
158
164
|
}
|
|
159
165
|
heartbeats = heartbeatLoop();
|
|
166
|
+
let reexecAfter = 0;
|
|
160
167
|
while (!signal.aborted) {
|
|
168
|
+
// A repair or update installed a newer gateway while this process kept
|
|
169
|
+
// running the old one: exit between turns so the service relaunches on it.
|
|
170
|
+
if (Date.now() >= reexecAfter && process.platform !== "win32") {
|
|
171
|
+
reexecAfter = Date.now() + 60_000;
|
|
172
|
+
const newer = await newerInstalledVersion(dirname(dirname(dirname(directory))), version).catch(() => undefined);
|
|
173
|
+
if (newer) {
|
|
174
|
+
// launchd and systemd relaunch an exited service; a hand-run serve
|
|
175
|
+
// just ends.
|
|
176
|
+
const supervised = Boolean(process.env.INVOCATION_ID ||
|
|
177
|
+
(process.env.XPC_SERVICE_NAME &&
|
|
178
|
+
process.env.XPC_SERVICE_NAME !== "0"));
|
|
179
|
+
console.error(supervised
|
|
180
|
+
? `Gateway ${newer} is installed; restarting from ${version}.`
|
|
181
|
+
: `Gateway ${newer} is installed. Stopping ${version}; run talentos agent serve again to use it.`);
|
|
182
|
+
return newer;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
161
185
|
if (needsUpdate(version, minimum) && Date.now() >= updateAfter) {
|
|
162
186
|
if (process.platform === "win32") {
|
|
163
187
|
throw new Error(`Gateway update required; re-run npx talentos@${minimum} agent serve --agent ${config.agentId}. Windows gateways update in the foreground.`);
|
|
@@ -177,7 +201,7 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
177
201
|
let job;
|
|
178
202
|
const claimStartedAt = Date.now();
|
|
179
203
|
try {
|
|
180
|
-
job = await gateway.request("/agent-gateway/claim", { deviceId }, signal);
|
|
204
|
+
job = await gateway.request("/agent-gateway/claim", { cliVersion: version, deviceId }, signal);
|
|
181
205
|
}
|
|
182
206
|
catch (error) {
|
|
183
207
|
failService(error);
|
|
@@ -215,12 +239,24 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
215
239
|
]);
|
|
216
240
|
owner = prepared;
|
|
217
241
|
current.owner = Boolean(owner);
|
|
242
|
+
// In a room with other people the server holds what the job
|
|
243
|
+
// posts unless this computer affirms it started clean: none of
|
|
244
|
+
// the owner's own context loaded, every touch reported. Unknown
|
|
245
|
+
// is reviewed, so a missing or failed word costs one tap.
|
|
246
|
+
if (owner && job.native.sharedRoom && owner.context === false) {
|
|
247
|
+
await gateway
|
|
248
|
+
.request(`/agent-gateway/jobs/${job.jobId}/touch-tracked`, { leaseToken: job.leaseToken }, signal)
|
|
249
|
+
.catch(() => undefined);
|
|
250
|
+
}
|
|
218
251
|
}
|
|
219
252
|
const sessionKey = owner
|
|
220
253
|
? `${job.packet.thread.id}:owner`
|
|
221
254
|
: job.packet.thread.id;
|
|
222
255
|
const bridge = () => new ApprovalBridge({
|
|
223
256
|
gateway: {
|
|
257
|
+
touch: async (flags) => {
|
|
258
|
+
await gateway.request(`/agent-gateway/jobs/${job.jobId}/private-touch`, { leaseToken: job.leaseToken, ...flags }, signal);
|
|
259
|
+
},
|
|
224
260
|
request: async (ask) => (await gateway.request(`/agent-gateway/jobs/${job.jobId}/approval-request`, { leaseToken: job.leaseToken, ...ask }, signal)) ?? { status: "expired" },
|
|
225
261
|
status: async (actionKeys) => (await gateway.request(`/agent-gateway/jobs/${job.jobId}/approval-status`, { actionKeys, leaseToken: job.leaseToken }, signal)) ?? [],
|
|
226
262
|
},
|
|
@@ -245,6 +281,15 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
245
281
|
remember: async (sessionId) => {
|
|
246
282
|
await sessions.remember(sessionKey, sessionId);
|
|
247
283
|
},
|
|
284
|
+
receipts: async (rows) => {
|
|
285
|
+
// The gateway body limit is 32 kB: 50 rows of at most ~250 B.
|
|
286
|
+
for (let at = 0; at < rows.length; at += 50) {
|
|
287
|
+
await gateway.request(`/agent-gateway/jobs/${job.jobId}/receipts`, {
|
|
288
|
+
leaseToken: job.leaseToken,
|
|
289
|
+
rows: rows.slice(at, at + 50),
|
|
290
|
+
}, signal);
|
|
291
|
+
}
|
|
292
|
+
},
|
|
248
293
|
mark: (name) => {
|
|
249
294
|
timings[`${name}Ms`] = Math.round(performance.now() - receivedAt);
|
|
250
295
|
},
|
package/dist/agent-service.js
CHANGED
|
@@ -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
|
-
|
|
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", [
|
|
@@ -39,8 +39,8 @@ export async function runAgentNative(parsed, home = homeDir()) {
|
|
|
39
39
|
if (action === "status") {
|
|
40
40
|
const config = await readNativeConfig(directory);
|
|
41
41
|
emit(config
|
|
42
|
-
? `On. ${agent.name} works in ${shown(config.root, home)} when you ask it in a room
|
|
43
|
-
: `Off. Run talentos agent native enable to let ${agent.name} use your full setup in rooms
|
|
42
|
+
? `On. ${agent.name} works in ${shown(config.root, home)} when you ask it in a room.`
|
|
43
|
+
: `Off. Run talentos agent native enable to let ${agent.name} use your full setup in rooms.`);
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
if (agent.provider !== "claude_code") {
|
package/dist/gateway-install.js
CHANGED
|
@@ -217,6 +217,21 @@ async function installLock(root, signal) {
|
|
|
217
217
|
await rm(pending, { force: true });
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* The installed gateway the launcher would run now, when it is a newer, complete
|
|
222
|
+
* version than the one running. `talentos agent repair` swaps `cli/current` but
|
|
223
|
+
* a service that is already running keeps its old code until it restarts, so a
|
|
224
|
+
* serving process asks this between turns and exits to be relaunched on it.
|
|
225
|
+
*/
|
|
226
|
+
export async function newerInstalledVersion(home, running) {
|
|
227
|
+
const root = join(home, ".talentos/cli");
|
|
228
|
+
const active = await readlink(join(root, "current")).catch(() => "");
|
|
229
|
+
if ((compareGatewayVersions(active, running) ?? 0) > 0 &&
|
|
230
|
+
(await installed(join(root, active, "node_modules/talentos"), active))) {
|
|
231
|
+
return active;
|
|
232
|
+
}
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
220
235
|
export async function installSharedGateway(options = {}) {
|
|
221
236
|
const home = options.home ?? homeDir();
|
|
222
237
|
const source = options.source ?? fileURLToPath(new URL("../", import.meta.url));
|
package/package.json
CHANGED