@mp-lb/berth 0.1.3 → 0.1.5
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 +23 -34
- 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.5";
|
|
5999
5999
|
|
|
6000
6000
|
// src/runAuthCommand.ts
|
|
6001
6001
|
import { spawn } from "node:child_process";
|
|
@@ -23522,6 +23522,7 @@ var runMessageCommand = async (args2) => {
|
|
|
23522
23522
|
|
|
23523
23523
|
// ../../packages/core/src/work/schemas/agentPromptsSchema.ts
|
|
23524
23524
|
var agentPromptsSchema = external_exports.object({
|
|
23525
|
+
workerRecovery: external_exports.string().min(1).optional(),
|
|
23525
23526
|
workerLaunch: external_exports.string().min(1),
|
|
23526
23527
|
roleMessage: external_exports.string().min(1),
|
|
23527
23528
|
reassignedRoleMessage: external_exports.string().min(1)
|
|
@@ -24102,22 +24103,6 @@ var runPromptCommand = async (args2) => {
|
|
|
24102
24103
|
);
|
|
24103
24104
|
};
|
|
24104
24105
|
|
|
24105
|
-
// ../../packages/core/src/work/data/getSessionRecoveryProblem.ts
|
|
24106
|
-
var getSessionRecoveryProblem = (session, task) => {
|
|
24107
|
-
if (!task || session.taskId !== task.uuid || task.status !== "working" || task.archivedAt)
|
|
24108
|
-
return "Task is not in the working column.";
|
|
24109
|
-
if (task.workerRun?.completedAt)
|
|
24110
|
-
return "This worker has already completed its work.";
|
|
24111
|
-
const owner = task.ownership?.worker;
|
|
24112
|
-
if (owner && (!("sessionId" in owner) || owner.sessionId !== session.id || owner.machineId !== session.machineId))
|
|
24113
|
-
return "Task is assigned to another worker.";
|
|
24114
|
-
if (task.workerId && task.workerId !== session.workerSessionId)
|
|
24115
|
-
return "Task is assigned to another worker.";
|
|
24116
|
-
if (session.endedAt || !session.startedAt)
|
|
24117
|
-
return "Session is not an unexpectedly exited session.";
|
|
24118
|
-
return null;
|
|
24119
|
-
};
|
|
24120
|
-
|
|
24121
24106
|
// ../../packages/core/src/work/data/renderAgentPrompt.ts
|
|
24122
24107
|
var import_handlebars = __toESM(require_lib(), 1);
|
|
24123
24108
|
|
|
@@ -24125,7 +24110,8 @@ var import_handlebars = __toESM(require_lib(), 1);
|
|
|
24125
24110
|
var agentPromptDefaults_default = {
|
|
24126
24111
|
workerLaunch: "Run fm read 'worker.md' --store 'mp-lb/roles' and follow its instructions for task {{taskId}}.",
|
|
24127
24112
|
roleMessage: "You have a new Berth message ({{messageId}}). Read it with berth message read {{messageId}}.",
|
|
24128
|
-
reassignedRoleMessage: "Berth message {{messageId}} is ready for you. Read it with berth message read {{messageId}}."
|
|
24113
|
+
reassignedRoleMessage: "Berth message {{messageId}} is ready for you. Read it with berth message read {{messageId}}.",
|
|
24114
|
+
workerRecovery: "Your terminal was interrupted. Review your conversation and the current state of task {{taskId}} if one is linked. Continue only unfinished work still assigned to you, respect blockers, and do not repeat completed actions. If work is complete or assigned elsewhere, wait for instructions."
|
|
24129
24115
|
};
|
|
24130
24116
|
|
|
24131
24117
|
// ../../packages/core/src/work/data/defaultAgentPrompts.ts
|
|
@@ -24169,7 +24155,7 @@ var terminalSessionCreateSchema = terminalSessionSchema.pick({
|
|
|
24169
24155
|
var terminalSessionUpdateSchema = external_exports.strictObject({
|
|
24170
24156
|
id: external_exports.uuid(),
|
|
24171
24157
|
startedAt: external_exports.iso.datetime().optional(),
|
|
24172
|
-
endedAt: external_exports.iso.datetime().optional(),
|
|
24158
|
+
endedAt: external_exports.iso.datetime().nullable().optional(),
|
|
24173
24159
|
error: external_exports.string().max(2e3).nullable().optional(),
|
|
24174
24160
|
workerSessionId: external_exports.string().max(200).nullable().optional()
|
|
24175
24161
|
}).refine(
|
|
@@ -24177,7 +24163,9 @@ var terminalSessionUpdateSchema = external_exports.strictObject({
|
|
|
24177
24163
|
{
|
|
24178
24164
|
message: "Set startedAt or endedAt."
|
|
24179
24165
|
}
|
|
24180
|
-
)
|
|
24166
|
+
).refine((input) => input.endedAt !== null || input.startedAt !== void 0, {
|
|
24167
|
+
message: "Confirm startedAt when relaunching an ended worker."
|
|
24168
|
+
});
|
|
24181
24169
|
|
|
24182
24170
|
// src/renderWorkerCommand.ts
|
|
24183
24171
|
var renderWorkerCommand = (template, values) => {
|
|
@@ -24280,9 +24268,7 @@ var attachTmuxSession = (name) => {
|
|
|
24280
24268
|
};
|
|
24281
24269
|
|
|
24282
24270
|
// src/recoverTerminalSession.ts
|
|
24283
|
-
var recoverTerminalSession = async (session, worker) => {
|
|
24284
|
-
if (session.endedAt || !session.startedAt)
|
|
24285
|
-
throw new Error("Session is not an unexpectedly exited session.");
|
|
24271
|
+
var recoverTerminalSession = async (session, worker, prompts) => {
|
|
24286
24272
|
if (tmuxSessionExists(session.terminalSessionId))
|
|
24287
24273
|
throw new Error("Session is already running.");
|
|
24288
24274
|
if (session.workerTypeId !== "shell" && (!worker?.resumeCommand || !session.workerSessionId))
|
|
@@ -24296,7 +24282,9 @@ var recoverTerminalSession = async (session, worker) => {
|
|
|
24296
24282
|
"Resume command must include {{workerSessionId}} to resume the original conversation."
|
|
24297
24283
|
);
|
|
24298
24284
|
const command = worker ? renderWorkerCommand(worker.resumeCommand, {
|
|
24299
|
-
prompt:
|
|
24285
|
+
prompt: renderAgentPrompt(prompts, "workerRecovery", {
|
|
24286
|
+
taskId: session.taskId ?? ""
|
|
24287
|
+
}),
|
|
24300
24288
|
sessionId: session.id,
|
|
24301
24289
|
workerSessionId: session.workerSessionId ?? "",
|
|
24302
24290
|
taskId: session.taskId ?? "",
|
|
@@ -24385,18 +24373,19 @@ var runSessionCommand = async (args2) => {
|
|
|
24385
24373
|
const machine = resolveSessionMachine(config2);
|
|
24386
24374
|
if (session.machineId !== machine.id)
|
|
24387
24375
|
throw new Error("Session belongs to another work machine.");
|
|
24388
|
-
|
|
24389
|
-
throw new Error("Only task sessions can be recovered.");
|
|
24390
|
-
const tasks = await client.task.list.query({ status: "working" });
|
|
24391
|
-
const problem = getSessionRecoveryProblem(
|
|
24392
|
-
session,
|
|
24393
|
-
tasks.find((task) => task.uuid === session.taskId)
|
|
24394
|
-
);
|
|
24395
|
-
if (problem) throw new Error(problem);
|
|
24396
|
-
return recoverTerminalSession(
|
|
24376
|
+
const result = await recoverTerminalSession(
|
|
24397
24377
|
session,
|
|
24398
|
-
session.workerTypeId === "shell" ? null : findWorkerType(config2.workerTypes ?? [], session.workerTypeId)
|
|
24378
|
+
session.workerTypeId === "shell" ? null : findWorkerType(config2.workerTypes ?? [], session.workerTypeId),
|
|
24379
|
+
config2.agentPrompts
|
|
24399
24380
|
);
|
|
24381
|
+
if (session.endedAt || !session.startedAt || session.error)
|
|
24382
|
+
await client.terminalSession.update.mutate({
|
|
24383
|
+
id: session.id,
|
|
24384
|
+
startedAt: session.startedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
24385
|
+
endedAt: null,
|
|
24386
|
+
error: null
|
|
24387
|
+
});
|
|
24388
|
+
return result;
|
|
24400
24389
|
}
|
|
24401
24390
|
if (action === "attach" && value && !agentValue) {
|
|
24402
24391
|
const session = await client.terminalSession.read.query(
|