doer-agent 0.4.1 → 0.4.2
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.js +15 -29
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -21,7 +21,6 @@ const settingsRpcCodec = StringCodec();
|
|
|
21
21
|
const gitRpcCodec = StringCodec();
|
|
22
22
|
const skillRpcCodec = StringCodec();
|
|
23
23
|
const runEventsCodec = StringCodec();
|
|
24
|
-
const retainedRuns = new Map();
|
|
25
24
|
const activeSessionWatchers = new Map();
|
|
26
25
|
const sessionLineIndexCache = new Map();
|
|
27
26
|
const ANSI_RE = /\u001b\[[0-9;]*m/g;
|
|
@@ -1004,9 +1003,9 @@ function cloneRunTask(task, _sinceSeq) {
|
|
|
1004
1003
|
...task,
|
|
1005
1004
|
};
|
|
1006
1005
|
}
|
|
1007
|
-
function
|
|
1006
|
+
function buildImmediateRunEvent(task, type) {
|
|
1008
1007
|
return {
|
|
1009
|
-
type
|
|
1008
|
+
type,
|
|
1010
1009
|
agentId: task.agentId,
|
|
1011
1010
|
sessionId: task.sessionId,
|
|
1012
1011
|
filePath: task.sessionFilePath,
|
|
@@ -1020,8 +1019,8 @@ function buildImmediateRunChangedEvent(task) {
|
|
|
1020
1019
|
finishedAt: task.finishedAt,
|
|
1021
1020
|
};
|
|
1022
1021
|
}
|
|
1023
|
-
function
|
|
1024
|
-
args.nc.publish(buildAgentRunEventsSubject(args.userId, args.task.agentId), runEventsCodec.encode(JSON.stringify(
|
|
1022
|
+
function publishImmediateRunEvent(args) {
|
|
1023
|
+
args.nc.publish(buildAgentRunEventsSubject(args.userId, args.task.agentId), runEventsCodec.encode(JSON.stringify(buildImmediateRunEvent(args.task, args.type ?? "run.changed"))));
|
|
1025
1024
|
}
|
|
1026
1025
|
async function findSessionFilePathBySessionId(sessionId) {
|
|
1027
1026
|
const targetSessionId = sessionId.trim();
|
|
@@ -1159,7 +1158,7 @@ async function updateRunSessionMetadata(task, metadata) {
|
|
|
1159
1158
|
task.updatedAt = formatLocalTimestamp();
|
|
1160
1159
|
await persistRunTask(task).catch(() => undefined);
|
|
1161
1160
|
if (metadata.nc) {
|
|
1162
|
-
|
|
1161
|
+
publishImmediateRunEvent({
|
|
1163
1162
|
nc: metadata.nc,
|
|
1164
1163
|
userId: task.userId,
|
|
1165
1164
|
task,
|
|
@@ -1173,9 +1172,6 @@ async function updateRunSessionMetadata(task, metadata) {
|
|
|
1173
1172
|
}).catch(() => undefined);
|
|
1174
1173
|
}
|
|
1175
1174
|
}
|
|
1176
|
-
function persistRetainedRun(task) {
|
|
1177
|
-
retainedRuns.set(task.id, cloneRunTask(task));
|
|
1178
|
-
}
|
|
1179
1175
|
function normalizePersistedRunTask(value) {
|
|
1180
1176
|
if (!value || typeof value !== "object") {
|
|
1181
1177
|
return null;
|
|
@@ -1239,10 +1235,10 @@ async function getStoredRun(runId) {
|
|
|
1239
1235
|
}
|
|
1240
1236
|
}
|
|
1241
1237
|
catch {
|
|
1242
|
-
// Ignore malformed persisted state
|
|
1238
|
+
// Ignore malformed persisted state.
|
|
1243
1239
|
}
|
|
1244
1240
|
}
|
|
1245
|
-
return
|
|
1241
|
+
return null;
|
|
1246
1242
|
}
|
|
1247
1243
|
async function startManagedRun(args) {
|
|
1248
1244
|
const prepared = await prepareCommandExecution({
|
|
@@ -1321,8 +1317,8 @@ async function startManagedRun(args) {
|
|
|
1321
1317
|
task.status = "failed";
|
|
1322
1318
|
task.error = message;
|
|
1323
1319
|
task.finishedAt = formatLocalTimestamp();
|
|
1324
|
-
|
|
1325
|
-
|
|
1320
|
+
publishImmediateRunEvent({ nc: args.nc, userId: task.userId, task });
|
|
1321
|
+
publishImmediateRunEvent({ nc: args.nc, userId: task.userId, task, type: "run.finished" });
|
|
1326
1322
|
void removeRunTask(task.id).catch(() => undefined);
|
|
1327
1323
|
void releaseRunStartSlot({ runId: task.id, sessionId: task.sessionId }).catch(() => undefined);
|
|
1328
1324
|
void prepared.codexAuthCleanup().catch(() => undefined);
|
|
@@ -1339,16 +1335,15 @@ async function startManagedRun(args) {
|
|
|
1339
1335
|
task.finishedAt = formatLocalTimestamp();
|
|
1340
1336
|
task.status = task.cancelRequested ? "canceled" : (task.resultExitCode ?? 1) === 0 ? "completed" : "failed";
|
|
1341
1337
|
task.error = task.status === "failed" ? `Command exited with code ${task.resultExitCode ?? "null"}` : null;
|
|
1342
|
-
|
|
1343
|
-
|
|
1338
|
+
publishImmediateRunEvent({ nc: args.nc, userId: task.userId, task });
|
|
1339
|
+
publishImmediateRunEvent({ nc: args.nc, userId: task.userId, task, type: "run.finished" });
|
|
1344
1340
|
void removeRunTask(task.id).catch(() => undefined);
|
|
1345
1341
|
void releaseRunStartSlot({ runId: task.id, sessionId: task.sessionId }).catch(() => undefined);
|
|
1346
1342
|
void prepared.codexAuthCleanup().catch(() => undefined);
|
|
1347
1343
|
writeRunStatus(task.id, `completed status=${task.status} exitCode=${task.resultExitCode ?? "null"} signal=${task.resultSignal ?? "null"}`);
|
|
1348
1344
|
});
|
|
1349
|
-
persistRetainedRun(task);
|
|
1350
1345
|
void persistRunTask(task).catch(() => undefined);
|
|
1351
|
-
|
|
1346
|
+
publishImmediateRunEvent({ nc: args.nc, userId: task.userId, task });
|
|
1352
1347
|
writeRunStatus(task.id, `started requestId=${args.requestId} cwd=${prepared.taskWorkspace}`);
|
|
1353
1348
|
if (!task.sessionId) {
|
|
1354
1349
|
void pollPendingSession();
|
|
@@ -2411,17 +2406,8 @@ async function handleRunRpcMessage(args) {
|
|
|
2411
2406
|
return;
|
|
2412
2407
|
}
|
|
2413
2408
|
if (request.action === "list") {
|
|
2414
|
-
const
|
|
2415
|
-
|
|
2416
|
-
for (const task of persisted) {
|
|
2417
|
-
mergedById.set(task.id, cloneRunTask(task));
|
|
2418
|
-
}
|
|
2419
|
-
for (const task of retainedRuns.values()) {
|
|
2420
|
-
if (!mergedById.has(task.id)) {
|
|
2421
|
-
mergedById.set(task.id, cloneRunTask(task));
|
|
2422
|
-
}
|
|
2423
|
-
}
|
|
2424
|
-
const merged = [...mergedById.values()]
|
|
2409
|
+
const merged = (await listPersistedRunTasks())
|
|
2410
|
+
.map((task) => cloneRunTask(task))
|
|
2425
2411
|
.sort((a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt))
|
|
2426
2412
|
.slice(0, request.limit);
|
|
2427
2413
|
publishRunRpcResponse({ nc: args.jetstream.nc, responseSubject, payload: { requestId, ok: true, tasks: merged } });
|
|
@@ -2439,7 +2425,7 @@ async function handleRunRpcMessage(args) {
|
|
|
2439
2425
|
target.cancelRequested = true;
|
|
2440
2426
|
target.updatedAt = formatLocalTimestamp();
|
|
2441
2427
|
await persistRunTask(target);
|
|
2442
|
-
|
|
2428
|
+
publishImmediateRunEvent({ nc: args.jetstream.nc, userId: target.userId, task: target });
|
|
2443
2429
|
writeRunStatus(target.id, `cancel requested pid=${target.processPid}`);
|
|
2444
2430
|
sendSignalToPid(target.processPid, "SIGINT");
|
|
2445
2431
|
const task = cloneRunTask(target);
|