talentos 1.4.5 → 1.4.6
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 +10 -4
- package/dist/agent/adapters.js +59 -11
- package/dist/agent/codex-policy.js +13 -2
- package/dist/agent/room-profile.js +130 -0
- package/dist/agent/serve.js +6 -11
- package/package.json +1 -1
- package/dist/agent/sessions.js +0 -36
package/README.md
CHANGED
|
@@ -83,11 +83,17 @@ before it is sent, and stored only once TalentOS accepts it.
|
|
|
83
83
|
### Agents in Rooms
|
|
84
84
|
|
|
85
85
|
`talentos agent serve --agent <id>` runs the linked provider in its private
|
|
86
|
-
work folder. It keeps one turn active
|
|
87
|
-
|
|
86
|
+
work folder. It keeps one turn active and starts a fresh Claude Code or Codex
|
|
87
|
+
session for every job, including retries and service restarts. Follow-ups use
|
|
88
|
+
the current room packet and room tools; native project files stay in the
|
|
89
|
+
thread's workspace. Old `~/.talentos/agents/<id>/sessions.json` files are ignored
|
|
90
|
+
and left untouched. A room-only job (a teammate's ask, a not-ready owner job,
|
|
91
|
+
every Codex job) runs in its own empty folder and does not load your CLAUDE.md,
|
|
92
|
+
rules, hooks, memory or Codex AGENTS.md and skills (not even their names); only
|
|
93
|
+
your provider login is used. Final text posts automatically.
|
|
88
94
|
The service heartbeats every 20 seconds and stops the child if its lease is
|
|
89
95
|
lost. A required CLI update installs under the agent directory between turns.
|
|
90
|
-
Signing-key provisioning
|
|
96
|
+
Signing-key provisioning and real staging latency proofs are
|
|
91
97
|
tracked in [Agent access](../../docs/features/agent-access/README.md).
|
|
92
98
|
|
|
93
99
|
Use the setup prompt from TalentOS to link Claude Code or Codex. The fragment
|
|
@@ -96,7 +102,7 @@ required even when its desktop app is signed in. Approve the user service
|
|
|
96
102
|
installation interactively or pass `--yes` after approval.
|
|
97
103
|
|
|
98
104
|
Linking waits for a recent gateway heartbeat before reporting Connected. Real
|
|
99
|
-
provider connection
|
|
105
|
+
provider connection and latency proofs remain staged after publication.
|
|
100
106
|
If the service cannot start, use the printed foreground
|
|
101
107
|
`talentos agent serve --agent <id>` command.
|
|
102
108
|
|
package/dist/agent/adapters.js
CHANGED
|
@@ -15,6 +15,7 @@ import { prepareCodexOwnerLaunch } from "./native/codex-launch.js";
|
|
|
15
15
|
import { prepareOwnerLaunch } from "./native/launch.js";
|
|
16
16
|
import { readReceipts } from "./native/receipts.js";
|
|
17
17
|
import { classifyProviderFailure, matchFailureText, ProviderFailureError, } from "./provider-failure.js";
|
|
18
|
+
import { prepareRoomProfile, ROOM_CATALOG_FILE, ROOM_MCP_FILE, } from "./room-profile.js";
|
|
18
19
|
const CHILD_ENV = [
|
|
19
20
|
"HOME",
|
|
20
21
|
"PATH",
|
|
@@ -34,6 +35,11 @@ const CHILD_ENV = [
|
|
|
34
35
|
const CLAUDE_VERSION = /^\d+\.\d+\.\d+/u;
|
|
35
36
|
const CODEX_VERSION = /\b\d+\.\d+\.\d+\b/u;
|
|
36
37
|
const DONT_ASK = /\bdontAsk\b/u;
|
|
38
|
+
// A room-only job needs both to keep the owner's profile and transcripts out.
|
|
39
|
+
const CLAUDE_ISOLATION_FLAGS = [
|
|
40
|
+
"--setting-sources",
|
|
41
|
+
"--no-session-persistence",
|
|
42
|
+
];
|
|
37
43
|
// What Codex prints when the required room server never listed its tools.
|
|
38
44
|
const ROOM_SERVER_FAILED = /required MCP servers failed to initialize/u;
|
|
39
45
|
const CLAUDE_TOOLS = ROOM_TOOLS.map((tool) => `mcp__talentos__${tool}`).join(",");
|
|
@@ -59,14 +65,16 @@ export async function verifyClaudeCode(configured) {
|
|
|
59
65
|
const detected = await execute(binary, ["--version"], options);
|
|
60
66
|
version = CLAUDE_VERSION.exec(detected.stdout.trim())?.[0] ?? "unknown";
|
|
61
67
|
const help = await execute(binary, ["--help"], options);
|
|
62
|
-
if (version !== "unknown" &&
|
|
68
|
+
if (version !== "unknown" &&
|
|
69
|
+
DONT_ASK.test(help.stdout) &&
|
|
70
|
+
CLAUDE_ISOLATION_FLAGS.every((flag) => help.stdout.includes(flag))) {
|
|
63
71
|
return;
|
|
64
72
|
}
|
|
65
73
|
}
|
|
66
74
|
catch {
|
|
67
75
|
// Never include provider stderr, which may contain login details.
|
|
68
76
|
}
|
|
69
|
-
throw new Error(`Update Claude Code (${version}) to a version that supports --permission-mode dontAsk.`);
|
|
77
|
+
throw new Error(`Update Claude Code (${version}) to a version that supports --permission-mode dontAsk, --setting-sources and --no-session-persistence.`);
|
|
70
78
|
}
|
|
71
79
|
export async function verifyCodex(configured, signal) {
|
|
72
80
|
const binary = resolveProviderBinary("codex", configured);
|
|
@@ -210,12 +218,14 @@ export function readProviderEvent(provider, value) {
|
|
|
210
218
|
export async function runProvider(input) {
|
|
211
219
|
const { config, job, workDir, sessionId, signal } = input;
|
|
212
220
|
const { instructions, ...context } = job.packet;
|
|
213
|
-
const prompt = JSON.stringify(config.provider === "claude_code" ? context : job.packet), mcpPath = join(dirname(workDir),
|
|
214
|
-
const catalogPath = join(dirname(workDir),
|
|
221
|
+
const prompt = JSON.stringify(config.provider === "claude_code" ? context : job.packet), mcpPath = join(dirname(workDir), ROOM_MCP_FILE);
|
|
222
|
+
const catalogPath = join(dirname(workDir), ROOM_CATALOG_FILE);
|
|
215
223
|
const binary = resolveProviderBinary(config.provider, config.providerPath);
|
|
216
224
|
let command, args;
|
|
217
225
|
let ownerLaunch;
|
|
218
226
|
let stopWatching;
|
|
227
|
+
// Only a room-only job: an owner job runs in the owner's own setup on purpose.
|
|
228
|
+
let roomProfile;
|
|
219
229
|
if (input.owner && config.provider === "claude_code") {
|
|
220
230
|
const watching = await input.owner.watch?.();
|
|
221
231
|
stopWatching = watching?.stop;
|
|
@@ -266,6 +276,13 @@ export async function runProvider(input) {
|
|
|
266
276
|
},
|
|
267
277
|
},
|
|
268
278
|
}));
|
|
279
|
+
// Last step that can fail: nothing after it leaves the job's files behind.
|
|
280
|
+
roomProfile = await prepareRoomProfile({
|
|
281
|
+
directory: dirname(workDir),
|
|
282
|
+
env: process.env,
|
|
283
|
+
jobId: job.jobId,
|
|
284
|
+
provider: config.provider,
|
|
285
|
+
});
|
|
269
286
|
command = binary;
|
|
270
287
|
args = [
|
|
271
288
|
"-p",
|
|
@@ -286,16 +303,35 @@ export async function runProvider(input) {
|
|
|
286
303
|
"Bash,Agent,Task",
|
|
287
304
|
"--permission-mode",
|
|
288
305
|
"dontAsk",
|
|
306
|
+
// None of the owner's CLAUDE.md, rules, hooks or output style. The login
|
|
307
|
+
// keys they need ride in the job's own settings file.
|
|
308
|
+
"--setting-sources",
|
|
309
|
+
"",
|
|
310
|
+
...(roomProfile.settingsPath
|
|
311
|
+
? ["--settings", roomProfile.settingsPath]
|
|
312
|
+
: []),
|
|
289
313
|
];
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
314
|
+
// A room-only job never resumes: the transcript would live in the owner's
|
|
315
|
+
// profile, and the job must not leave one there.
|
|
316
|
+
args.push("--no-session-persistence");
|
|
293
317
|
}
|
|
294
318
|
else {
|
|
319
|
+
if (input.owner) {
|
|
320
|
+
// A Codex owner job needs its own launch inputs; it must never run with
|
|
321
|
+
// the room-only profile's environment.
|
|
322
|
+
throw new Error("A Codex owner job is missing its launch inputs.");
|
|
323
|
+
}
|
|
295
324
|
command = binary;
|
|
296
325
|
const launcher = gatewayLauncherPath();
|
|
297
326
|
const useLauncher = process.platform !== "win32" && existsSync(launcher);
|
|
298
327
|
await writePrivateFile(catalogPath, await codexRoomCatalog(binary));
|
|
328
|
+
// Last step that can fail: nothing after it leaves the job's files behind.
|
|
329
|
+
roomProfile = await prepareRoomProfile({
|
|
330
|
+
directory: dirname(workDir),
|
|
331
|
+
env: process.env,
|
|
332
|
+
jobId: job.jobId,
|
|
333
|
+
provider: config.provider,
|
|
334
|
+
});
|
|
299
335
|
// Resume has a different flag surface. Root overrides are inherited by
|
|
300
336
|
// both exec paths; shell_tool=false enforces ADR 0093's default no-Bash.
|
|
301
337
|
args = codexRoomArgs({
|
|
@@ -311,11 +347,11 @@ export async function runProvider(input) {
|
|
|
311
347
|
config.agentId,
|
|
312
348
|
],
|
|
313
349
|
prompt,
|
|
314
|
-
|
|
350
|
+
isolated: true,
|
|
315
351
|
});
|
|
316
352
|
}
|
|
317
353
|
const child = spawn(command, args, {
|
|
318
|
-
cwd: input.owner?.workspace.cwd ?? workDir,
|
|
354
|
+
cwd: input.owner?.workspace.cwd ?? roomProfile?.cwd ?? workDir,
|
|
319
355
|
env: input.owner
|
|
320
356
|
? {
|
|
321
357
|
...input.owner.env,
|
|
@@ -323,7 +359,18 @@ export async function runProvider(input) {
|
|
|
323
359
|
.filter(Boolean)
|
|
324
360
|
.join(delimiter),
|
|
325
361
|
}
|
|
326
|
-
:
|
|
362
|
+
: {
|
|
363
|
+
...childEnvironment(process.env, binary),
|
|
364
|
+
// Login variables from the owner's settings; never written to a file.
|
|
365
|
+
...roomProfile?.env,
|
|
366
|
+
// The owner's memory stays out; the job's own directory is fresh.
|
|
367
|
+
...(config.provider === "claude_code"
|
|
368
|
+
? { CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1" }
|
|
369
|
+
: {}),
|
|
370
|
+
...(roomProfile?.codexHome
|
|
371
|
+
? { CODEX_HOME: roomProfile.codexHome }
|
|
372
|
+
: {}),
|
|
373
|
+
},
|
|
327
374
|
// stderr is matched to name a failure, never forwarded: it can hold login
|
|
328
375
|
// details.
|
|
329
376
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -406,7 +453,7 @@ export async function runProvider(input) {
|
|
|
406
453
|
failure = event.failure;
|
|
407
454
|
}
|
|
408
455
|
if (event.sessionId) {
|
|
409
|
-
await input.remember(event.sessionId);
|
|
456
|
+
await input.remember?.(event.sessionId);
|
|
410
457
|
}
|
|
411
458
|
if (event.status) {
|
|
412
459
|
// Room-visible status never names the owner's private tools.
|
|
@@ -447,6 +494,7 @@ export async function runProvider(input) {
|
|
|
447
494
|
}
|
|
448
495
|
await rm(mcpPath, { force: true });
|
|
449
496
|
await rm(catalogPath, { force: true });
|
|
497
|
+
await roomProfile?.cleanup();
|
|
450
498
|
stopWatching?.();
|
|
451
499
|
if (ownerLaunch && input.receipts) {
|
|
452
500
|
// Best effort: a lost record never changes how the job ended.
|
|
@@ -21,7 +21,7 @@ export const ROOM_TOOLS = [
|
|
|
21
21
|
"whoami",
|
|
22
22
|
];
|
|
23
23
|
export function codexRoomArgs(input) {
|
|
24
|
-
const { catalogPath, mcpCommand, mcpArgs, prompt, sessionId } = input;
|
|
24
|
+
const { catalogPath, mcpCommand, mcpArgs, prompt, sessionId, isolated } = input;
|
|
25
25
|
const args = [
|
|
26
26
|
"-c",
|
|
27
27
|
'sandbox_mode="read-only"',
|
|
@@ -72,11 +72,22 @@ export function codexRoomArgs(input) {
|
|
|
72
72
|
`mcp_servers.talentos.command=${JSON.stringify(mcpCommand)}`,
|
|
73
73
|
"-c",
|
|
74
74
|
`mcp_servers.talentos.args=${JSON.stringify(mcpArgs)}`,
|
|
75
|
+
// An empty directory has no AGENTS.md, but a repo above it could. The
|
|
76
|
+
// owner's skills (~/.agents/skills, and ~/.codex/skills in a repo home) are
|
|
77
|
+
// listed to the model by name and description unless told not to.
|
|
78
|
+
...(isolated
|
|
79
|
+
? [
|
|
80
|
+
"-c",
|
|
81
|
+
"project_doc_max_bytes=0",
|
|
82
|
+
"-c",
|
|
83
|
+
"skills.include_instructions=false",
|
|
84
|
+
]
|
|
85
|
+
: []),
|
|
75
86
|
"exec",
|
|
76
87
|
];
|
|
77
88
|
if (sessionId) {
|
|
78
89
|
args.push("resume", sessionId);
|
|
79
90
|
}
|
|
80
|
-
args.push("--json", "--skip-git-repo-check", "--ignore-user-config", "--ignore-rules", prompt);
|
|
91
|
+
args.push("--json", "--skip-git-repo-check", "--ignore-user-config", "--ignore-rules", ...(isolated ? ["--ephemeral"] : []), prompt);
|
|
81
92
|
return args;
|
|
82
93
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { access, mkdir, readFile, rm, rmdir, symlink } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { writePrivateFile } from "../agent-config.js";
|
|
5
|
+
import { homeDir } from "../install.js";
|
|
6
|
+
import { ProviderFailureError } from "./provider-failure.js";
|
|
7
|
+
// The room-only profile (#12712): a job for a teammate, a not-ready owner job
|
|
8
|
+
// and every Codex room job sees what TalentOS hands it (the packet and the room
|
|
9
|
+
// tools) and nothing from the owner's own setup. Each job gets an empty working
|
|
10
|
+
// directory and, for Codex, a CODEX_HOME that holds only the login. Owner jobs
|
|
11
|
+
// never come through here (docs/features/agent-access/README.md).
|
|
12
|
+
export const ROOM_MCP_FILE = ".talentos-mcp.json";
|
|
13
|
+
export const ROOM_CATALOG_FILE = ".talentos-codex-models.json";
|
|
14
|
+
const ROOM_JOBS = "room-jobs";
|
|
15
|
+
// Claude Code reads its login helpers and provider routing from user settings,
|
|
16
|
+
// and `--setting-sources ""` skips that file. These keys alone carry across so
|
|
17
|
+
// a login that works today keeps working; hooks, permissions, plugins and
|
|
18
|
+
// output style never do. The `env` entries can hold credentials themselves, so
|
|
19
|
+
// they go to the child's environment and never to a file.
|
|
20
|
+
const CLAUDE_LOGIN_KEYS = [
|
|
21
|
+
"apiKeyHelper",
|
|
22
|
+
"awsAuthRefresh",
|
|
23
|
+
"awsCredentialExport",
|
|
24
|
+
"forceLoginMethod",
|
|
25
|
+
"forceLoginOrgUUID",
|
|
26
|
+
"gcpAuthRefresh",
|
|
27
|
+
"model",
|
|
28
|
+
];
|
|
29
|
+
const CLAUDE_LOGIN_ENV = /^(?:ANTHROPIC_|CLAUDE_CODE_USE_|CLAUDE_CODE_SKIP_|AWS_|GOOGLE_|CLOUD_ML_|VERTEX_|(?:HTTPS?|NO)_PROXY$|NODE_EXTRA_CA_CERTS$)/iu;
|
|
30
|
+
function isPlainObject(value) {
|
|
31
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
async function claudeLoginSettings(env) {
|
|
34
|
+
const directory = env.CLAUDE_CONFIG_DIR || join(homeDir(env), ".claude");
|
|
35
|
+
let settings;
|
|
36
|
+
try {
|
|
37
|
+
settings = JSON.parse(await readFile(join(directory, "settings.json"), "utf8"));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Missing or unreadable settings carry no login; never echo what failed.
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
if (!isPlainObject(settings)) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
const forwarded = {};
|
|
47
|
+
for (const key of CLAUDE_LOGIN_KEYS) {
|
|
48
|
+
if (typeof settings[key] === "string") {
|
|
49
|
+
forwarded[key] = settings[key];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const login = isPlainObject(settings.env)
|
|
53
|
+
? Object.fromEntries(Object.entries(settings.env).filter((entry) => CLAUDE_LOGIN_ENV.test(entry[0]) && typeof entry[1] === "string"))
|
|
54
|
+
: {};
|
|
55
|
+
return {
|
|
56
|
+
...(Object.keys(login).length > 0 ? { env: login } : {}),
|
|
57
|
+
...(Object.keys(forwarded).length > 0
|
|
58
|
+
? { file: JSON.stringify(forwarded) }
|
|
59
|
+
: {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Codex could not be kept apart from the owner's setup, so no job runs. */
|
|
63
|
+
export class RoomIsolationError extends ProviderFailureError {
|
|
64
|
+
constructor() {
|
|
65
|
+
super("unknown", "Codex could not be isolated from your setup on this computer.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export async function prepareRoomProfile(input) {
|
|
69
|
+
const jobDir = join(input.directory, ROOM_JOBS, input.jobId.replace(/[^\w-]/gu, ""));
|
|
70
|
+
const cwd = join(jobDir, "cwd");
|
|
71
|
+
const profile = {
|
|
72
|
+
cleanup: async () => {
|
|
73
|
+
await rm(jobDir, { force: true, recursive: true });
|
|
74
|
+
// Claude Code logs under a cache directory named for the cwd: one small
|
|
75
|
+
// directory per job would pile up. Linux and macOS locations only.
|
|
76
|
+
if (input.provider === "claude_code") {
|
|
77
|
+
const home = homeDir(input.env);
|
|
78
|
+
const key = cwd.replace(/[^a-zA-Z0-9]/gu, "-");
|
|
79
|
+
await Promise.all([
|
|
80
|
+
join(input.env.XDG_CACHE_HOME || join(home, ".cache")),
|
|
81
|
+
join(home, "Library", "Caches"),
|
|
82
|
+
].map((cache) => rm(join(cache, "claude-cli-nodejs", key), {
|
|
83
|
+
force: true,
|
|
84
|
+
recursive: true,
|
|
85
|
+
})));
|
|
86
|
+
}
|
|
87
|
+
// Leave no empty room-jobs/ behind; a job still running keeps it.
|
|
88
|
+
await rmdir(join(input.directory, ROOM_JOBS)).catch(() => undefined);
|
|
89
|
+
},
|
|
90
|
+
cwd,
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
// A retry of the same job starts from nothing, whatever an earlier attempt left.
|
|
94
|
+
await profile.cleanup();
|
|
95
|
+
await mkdir(cwd, { recursive: true, mode: 0o700 });
|
|
96
|
+
if (input.provider === "claude_code") {
|
|
97
|
+
const login = await claudeLoginSettings(input.env);
|
|
98
|
+
profile.env = login.env;
|
|
99
|
+
if (login.file) {
|
|
100
|
+
profile.settingsPath = join(jobDir, "settings.json");
|
|
101
|
+
await writePrivateFile(profile.settingsPath, login.file);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
profile.codexHome = join(jobDir, "codex-home");
|
|
106
|
+
await mkdir(profile.codexHome, { mode: 0o700 });
|
|
107
|
+
const login = join(input.env.CODEX_HOME || join(homeDir(input.env), ".codex"), "auth.json");
|
|
108
|
+
// A link, never a copy: Codex rotates the refresh token in place, and a
|
|
109
|
+
// copy would leave the owner's own file holding the one it retired.
|
|
110
|
+
if (await access(login, constants.F_OK).then(() => true, () => false)) {
|
|
111
|
+
await symlink(login, join(profile.codexHome, "auth.json")).catch(() => {
|
|
112
|
+
throw new RoomIsolationError();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
await profile.cleanup();
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
return profile;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Anything left from a job the daemon never finished: the per-agent lock means
|
|
125
|
+
* no job of this agent is running when it starts, and a job's profile can hold
|
|
126
|
+
* a login key. The agent key's config files go with it.
|
|
127
|
+
*/
|
|
128
|
+
export async function sweepRoomJobs(directory) {
|
|
129
|
+
await Promise.all([ROOM_JOBS, ROOM_MCP_FILE, ROOM_CATALOG_FILE].map((name) => rm(join(directory, name), { force: true, recursive: true })));
|
|
130
|
+
}
|
package/dist/agent/serve.js
CHANGED
|
@@ -14,7 +14,7 @@ import { ROOM_ONLY_STATUS } from "./native/native-issue.js";
|
|
|
14
14
|
import { ProjectRequests } from "./native/project-requests.js";
|
|
15
15
|
import { mirrorOf } from "./native/projects.js";
|
|
16
16
|
import { failureReasonOf } from "./provider-failure.js";
|
|
17
|
-
import {
|
|
17
|
+
import { sweepRoomJobs } from "./room-profile.js";
|
|
18
18
|
const HEARTBEAT_MS = 20_000;
|
|
19
19
|
// A native job holds a 30 s server lease and is re-derived on every renewal.
|
|
20
20
|
const NATIVE_RENEW_MS = 10_000;
|
|
@@ -71,7 +71,9 @@ export async function installGatewayUpdate(directory, minimum, signal) {
|
|
|
71
71
|
export async function serveAgent(config, directory, version, stop, verify, options = {}) {
|
|
72
72
|
const release = await acquireLock(directory);
|
|
73
73
|
try {
|
|
74
|
-
|
|
74
|
+
// This agent has no job running: whatever a crashed job left is stale.
|
|
75
|
+
await sweepRoomJobs(directory);
|
|
76
|
+
const workDir = join(directory, "work"), gateway = new AgentGateway(config);
|
|
75
77
|
await mkdir(workDir, { recursive: true, mode: 0o700 });
|
|
76
78
|
const deviceId = randomUUID();
|
|
77
79
|
const gate = options.gate ??
|
|
@@ -352,11 +354,6 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
352
354
|
.catch(() => undefined);
|
|
353
355
|
}
|
|
354
356
|
}
|
|
355
|
-
// A project's sessions are its own; the root from before projects
|
|
356
|
-
// keeps its key so those threads still resume.
|
|
357
|
-
const sessionKey = owner
|
|
358
|
-
? `${job.packet.thread.id}:owner${owner.project.legacy ? "" : `:${owner.project.id}`}`
|
|
359
|
-
: job.packet.thread.id;
|
|
360
357
|
// Which code the work started from, on the owner's record.
|
|
361
358
|
const base = owner?.workspace.base;
|
|
362
359
|
const baseRow = base && {
|
|
@@ -392,11 +389,9 @@ export async function serveAgent(config, directory, version, stop, verify, optio
|
|
|
392
389
|
job,
|
|
393
390
|
workDir,
|
|
394
391
|
owner: owner && { ...owner, watch: bridge },
|
|
395
|
-
|
|
392
|
+
// Room tools and the current packet carry continuity. Replaying
|
|
393
|
+
// provider history grows forever and carries stale file copies.
|
|
396
394
|
signal: AbortSignal.any([signal, cancel.signal]),
|
|
397
|
-
remember: async (sessionId) => {
|
|
398
|
-
await sessions.remember(sessionKey, sessionId);
|
|
399
|
-
},
|
|
400
395
|
receipts: async (hookRows) => {
|
|
401
396
|
const rows = baseRow
|
|
402
397
|
? [baseRow, ...hookRows].map((row, seq) => ({ ...row, seq }))
|
package/package.json
CHANGED
package/dist/agent/sessions.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { isMissing, writePrivateFile } from "../agent-config.js";
|
|
4
|
-
// One file per agent already supplies the agentId half of the session key.
|
|
5
|
-
export class SessionMap {
|
|
6
|
-
path;
|
|
7
|
-
constructor(directory) {
|
|
8
|
-
this.path = join(directory, "sessions.json");
|
|
9
|
-
}
|
|
10
|
-
async get(threadId) {
|
|
11
|
-
return (await this.read())[threadId];
|
|
12
|
-
}
|
|
13
|
-
async remember(threadId, sessionId) {
|
|
14
|
-
const sessions = await this.read();
|
|
15
|
-
sessions[threadId] = sessionId;
|
|
16
|
-
await writePrivateFile(this.path, `${JSON.stringify(sessions)}\n`);
|
|
17
|
-
}
|
|
18
|
-
async read() {
|
|
19
|
-
try {
|
|
20
|
-
const value = JSON.parse(await readFile(this.path, "utf8"));
|
|
21
|
-
if (!value ||
|
|
22
|
-
typeof value !== "object" ||
|
|
23
|
-
Array.isArray(value) ||
|
|
24
|
-
Object.values(value).some((session) => typeof session !== "string")) {
|
|
25
|
-
throw new Error("Agent sessions are invalid. Restore sessions.json before serving.");
|
|
26
|
-
}
|
|
27
|
-
return value;
|
|
28
|
-
}
|
|
29
|
-
catch (error) {
|
|
30
|
-
if (isMissing(error)) {
|
|
31
|
-
return {};
|
|
32
|
-
}
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|