@mp-lb/berth 0.1.5 → 0.1.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.
Files changed (2) hide show
  1. package/dist/berth.js +37 -13
  2. package/package.json +1 -1
package/dist/berth.js CHANGED
@@ -5995,7 +5995,7 @@ var require_lib = __commonJS({
5995
5995
  });
5996
5996
 
5997
5997
  // package.json
5998
- var version = "0.1.5";
5998
+ var version = "0.1.6";
5999
5999
 
6000
6000
  // src/runAuthCommand.ts
6001
6001
  import { spawn } from "node:child_process";
@@ -24222,6 +24222,8 @@ var startTmuxSession = (name, directory, command, sessionId, machineId) => {
24222
24222
  "-c",
24223
24223
  directory,
24224
24224
  "env",
24225
+ "-u",
24226
+ "CODEX_THREAD_ID",
24225
24227
  `BERTH_SESSION_ID=${sessionId}`,
24226
24228
  `BERTH_MACHINE_ID=${machineId}`,
24227
24229
  `PATH=${process.env.PATH ?? ""}`,
@@ -24304,6 +24306,38 @@ var recoverTerminalSession = async (session, worker, prompts) => {
24304
24306
  return { id: session.id, recovered: true };
24305
24307
  };
24306
24308
 
24309
+ // src/registerTerminalSession.ts
24310
+ var registerTerminalSession = async (value) => {
24311
+ const id = external_exports.uuid().parse(value);
24312
+ if (process.env.BERTH_SESSION_ID !== id || !process.env.TMUX)
24313
+ throw new Error(
24314
+ "Registration must run inside the matching Berth terminal session."
24315
+ );
24316
+ const client = createWorkClient();
24317
+ let session = await client.terminalSession.read.query(id);
24318
+ const machine = resolveSessionMachine(await client.config.read.query());
24319
+ if (session.machineId !== machine.id || !tmuxSessionExists(session.terminalSessionId) || currentTmuxSessionName() !== session.terminalSessionId)
24320
+ throw new Error("Registration must run in this exact terminal session.");
24321
+ if (session.workerTypeId === "codex" && !session.workerSessionId && !process.env.CODEX_THREAD_ID)
24322
+ throw new Error(
24323
+ "Codex conversation ID is unavailable. Run registration from a shell command inside the Codex conversation."
24324
+ );
24325
+ if (session.workerTypeId === "codex" && process.env.CODEX_THREAD_ID) {
24326
+ const workerSessionId = external_exports.uuid().parse(process.env.CODEX_THREAD_ID);
24327
+ if (session.workerSessionId && session.workerSessionId !== workerSessionId)
24328
+ throw new Error(
24329
+ "Worker is already linked to a different Codex conversation."
24330
+ );
24331
+ if (!session.workerSessionId)
24332
+ session = await client.terminalSession.update.mutate({
24333
+ id,
24334
+ startedAt: session.startedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
24335
+ workerSessionId
24336
+ });
24337
+ }
24338
+ return session.taskId ? client.terminalSession.register.mutate(id) : session;
24339
+ };
24340
+
24307
24341
  // ../../packages/core/src/work/data/resolveDefaultWorkerTypeId.ts
24308
24342
  var resolveDefaultWorkerTypeId = (types, current) => types.some((type) => type.id === current) ? current : types[0]?.id ?? null;
24309
24343
 
@@ -24399,18 +24433,8 @@ var runSessionCommand = async (args2) => {
24399
24433
  attachTmuxSession(session.terminalSessionId);
24400
24434
  return { id: session.id, detached: true };
24401
24435
  }
24402
- if (action === "register" && value && !agentValue) {
24403
- const id = external_exports.uuid().parse(value);
24404
- if (process.env.BERTH_SESSION_ID !== id || !process.env.TMUX)
24405
- throw new Error(
24406
- "Registration must run inside the matching Berth terminal session."
24407
- );
24408
- const session = await client.terminalSession.read.query(id);
24409
- const machine = resolveSessionMachine(await client.config.read.query());
24410
- if (session.machineId !== machine.id || !tmuxSessionExists(session.terminalSessionId) || currentTmuxSessionName() !== session.terminalSessionId)
24411
- throw new Error("Registration must run in this exact terminal session.");
24412
- return client.terminalSession.register.mutate(id);
24413
- }
24436
+ if (action === "register" && value && !agentValue)
24437
+ return registerTerminalSession(value);
24414
24438
  if (action === "start" && value && !instanceSlug) {
24415
24439
  const taskId = external_exports.uuid().parse(value);
24416
24440
  const workerTypeId = await prepareTaskWorkerInstance(taskId, agentValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mp-lb/berth",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {