@mp-lb/berth 0.1.4 → 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.
- package/dist/berth.js +50 -27
- 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.
|
|
5998
|
+
var version = "0.1.6";
|
|
5999
5999
|
|
|
6000
6000
|
// src/runAuthCommand.ts
|
|
6001
6001
|
import { spawn } from "node:child_process";
|
|
@@ -24103,13 +24103,6 @@ var runPromptCommand = async (args2) => {
|
|
|
24103
24103
|
);
|
|
24104
24104
|
};
|
|
24105
24105
|
|
|
24106
|
-
// ../../packages/core/src/work/data/getSessionRecoveryProblem.ts
|
|
24107
|
-
var getSessionRecoveryProblem = (session) => {
|
|
24108
|
-
if (session.endedAt) return "Worker was intentionally ended.";
|
|
24109
|
-
if (!session.startedAt) return "Worker startup was never confirmed.";
|
|
24110
|
-
return null;
|
|
24111
|
-
};
|
|
24112
|
-
|
|
24113
24106
|
// ../../packages/core/src/work/data/renderAgentPrompt.ts
|
|
24114
24107
|
var import_handlebars = __toESM(require_lib(), 1);
|
|
24115
24108
|
|
|
@@ -24162,7 +24155,7 @@ var terminalSessionCreateSchema = terminalSessionSchema.pick({
|
|
|
24162
24155
|
var terminalSessionUpdateSchema = external_exports.strictObject({
|
|
24163
24156
|
id: external_exports.uuid(),
|
|
24164
24157
|
startedAt: external_exports.iso.datetime().optional(),
|
|
24165
|
-
endedAt: external_exports.iso.datetime().optional(),
|
|
24158
|
+
endedAt: external_exports.iso.datetime().nullable().optional(),
|
|
24166
24159
|
error: external_exports.string().max(2e3).nullable().optional(),
|
|
24167
24160
|
workerSessionId: external_exports.string().max(200).nullable().optional()
|
|
24168
24161
|
}).refine(
|
|
@@ -24170,7 +24163,9 @@ var terminalSessionUpdateSchema = external_exports.strictObject({
|
|
|
24170
24163
|
{
|
|
24171
24164
|
message: "Set startedAt or endedAt."
|
|
24172
24165
|
}
|
|
24173
|
-
)
|
|
24166
|
+
).refine((input) => input.endedAt !== null || input.startedAt !== void 0, {
|
|
24167
|
+
message: "Confirm startedAt when relaunching an ended worker."
|
|
24168
|
+
});
|
|
24174
24169
|
|
|
24175
24170
|
// src/renderWorkerCommand.ts
|
|
24176
24171
|
var renderWorkerCommand = (template, values) => {
|
|
@@ -24227,6 +24222,8 @@ var startTmuxSession = (name, directory, command, sessionId, machineId) => {
|
|
|
24227
24222
|
"-c",
|
|
24228
24223
|
directory,
|
|
24229
24224
|
"env",
|
|
24225
|
+
"-u",
|
|
24226
|
+
"CODEX_THREAD_ID",
|
|
24230
24227
|
`BERTH_SESSION_ID=${sessionId}`,
|
|
24231
24228
|
`BERTH_MACHINE_ID=${machineId}`,
|
|
24232
24229
|
`PATH=${process.env.PATH ?? ""}`,
|
|
@@ -24274,8 +24271,6 @@ var attachTmuxSession = (name) => {
|
|
|
24274
24271
|
|
|
24275
24272
|
// src/recoverTerminalSession.ts
|
|
24276
24273
|
var recoverTerminalSession = async (session, worker, prompts) => {
|
|
24277
|
-
if (session.endedAt || !session.startedAt)
|
|
24278
|
-
throw new Error("Session is not an unexpectedly exited session.");
|
|
24279
24274
|
if (tmuxSessionExists(session.terminalSessionId))
|
|
24280
24275
|
throw new Error("Session is already running.");
|
|
24281
24276
|
if (session.workerTypeId !== "shell" && (!worker?.resumeCommand || !session.workerSessionId))
|
|
@@ -24311,6 +24306,38 @@ var recoverTerminalSession = async (session, worker, prompts) => {
|
|
|
24311
24306
|
return { id: session.id, recovered: true };
|
|
24312
24307
|
};
|
|
24313
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
|
+
|
|
24314
24341
|
// ../../packages/core/src/work/data/resolveDefaultWorkerTypeId.ts
|
|
24315
24342
|
var resolveDefaultWorkerTypeId = (types, current) => types.some((type) => type.id === current) ? current : types[0]?.id ?? null;
|
|
24316
24343
|
|
|
@@ -24380,13 +24407,19 @@ var runSessionCommand = async (args2) => {
|
|
|
24380
24407
|
const machine = resolveSessionMachine(config2);
|
|
24381
24408
|
if (session.machineId !== machine.id)
|
|
24382
24409
|
throw new Error("Session belongs to another work machine.");
|
|
24383
|
-
const
|
|
24384
|
-
if (problem) throw new Error(problem);
|
|
24385
|
-
return recoverTerminalSession(
|
|
24410
|
+
const result = await recoverTerminalSession(
|
|
24386
24411
|
session,
|
|
24387
24412
|
session.workerTypeId === "shell" ? null : findWorkerType(config2.workerTypes ?? [], session.workerTypeId),
|
|
24388
24413
|
config2.agentPrompts
|
|
24389
24414
|
);
|
|
24415
|
+
if (session.endedAt || !session.startedAt || session.error)
|
|
24416
|
+
await client.terminalSession.update.mutate({
|
|
24417
|
+
id: session.id,
|
|
24418
|
+
startedAt: session.startedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
24419
|
+
endedAt: null,
|
|
24420
|
+
error: null
|
|
24421
|
+
});
|
|
24422
|
+
return result;
|
|
24390
24423
|
}
|
|
24391
24424
|
if (action === "attach" && value && !agentValue) {
|
|
24392
24425
|
const session = await client.terminalSession.read.query(
|
|
@@ -24400,18 +24433,8 @@ var runSessionCommand = async (args2) => {
|
|
|
24400
24433
|
attachTmuxSession(session.terminalSessionId);
|
|
24401
24434
|
return { id: session.id, detached: true };
|
|
24402
24435
|
}
|
|
24403
|
-
if (action === "register" && value && !agentValue)
|
|
24404
|
-
|
|
24405
|
-
if (process.env.BERTH_SESSION_ID !== id || !process.env.TMUX)
|
|
24406
|
-
throw new Error(
|
|
24407
|
-
"Registration must run inside the matching Berth terminal session."
|
|
24408
|
-
);
|
|
24409
|
-
const session = await client.terminalSession.read.query(id);
|
|
24410
|
-
const machine = resolveSessionMachine(await client.config.read.query());
|
|
24411
|
-
if (session.machineId !== machine.id || !tmuxSessionExists(session.terminalSessionId) || currentTmuxSessionName() !== session.terminalSessionId)
|
|
24412
|
-
throw new Error("Registration must run in this exact terminal session.");
|
|
24413
|
-
return client.terminalSession.register.mutate(id);
|
|
24414
|
-
}
|
|
24436
|
+
if (action === "register" && value && !agentValue)
|
|
24437
|
+
return registerTerminalSession(value);
|
|
24415
24438
|
if (action === "start" && value && !instanceSlug) {
|
|
24416
24439
|
const taskId = external_exports.uuid().parse(value);
|
|
24417
24440
|
const workerTypeId = await prepareTaskWorkerInstance(taskId, agentValue);
|