@schilderlabs/pitown-core 0.2.6 → 0.2.7
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-runner.mjs +118 -4
- package/dist/agent-runner.mjs.map +1 -1
- package/dist/index.d.mts +26 -1
- package/dist/index.mjs +4 -357
- package/dist/index.mjs.map +1 -1
- package/dist/orchestration-D6XeSl8s.mjs +689 -0
- package/dist/orchestration-D6XeSl8s.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/tasks-BfQm-7-O.mjs +0 -195
- package/dist/tasks-BfQm-7-O.mjs.map +0 -1
package/dist/agent-runner.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createWriteStream, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
1
|
+
import { A as getLatestAgentSession, C as createAgentState, F as writeAgentState, P as readAgentState, S as createAgentSessionRecord, h as updateTaskRecordStatus, o as resumeAgentTurnDetached, r as notifyTaskDelegator, w as getAgentDir, x as appendAgentMessage } from "./orchestration-D6XeSl8s.mjs";
|
|
2
|
+
import { createWriteStream, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { finished } from "node:stream/promises";
|
|
5
5
|
|
|
@@ -90,7 +90,25 @@ async function runDetachedAgent(payload) {
|
|
|
90
90
|
from: payload.agentId,
|
|
91
91
|
body: completionMessage
|
|
92
92
|
});
|
|
93
|
-
if (payload.taskId)
|
|
93
|
+
if (payload.taskId) {
|
|
94
|
+
updateTaskRecordStatus(payload.artifactsDir, payload.taskId, exitCode === 0 ? "completed" : "blocked");
|
|
95
|
+
notifyTaskDelegator({
|
|
96
|
+
artifactsDir: payload.artifactsDir,
|
|
97
|
+
agentId: payload.agentId,
|
|
98
|
+
taskId: payload.taskId,
|
|
99
|
+
completionMessage,
|
|
100
|
+
outcome: exitCode === 0 ? "completed" : "blocked"
|
|
101
|
+
});
|
|
102
|
+
if (payload.autoResumeTarget) resumeAgentTurnDetached({
|
|
103
|
+
repoRoot: payload.repoRoot,
|
|
104
|
+
artifactsDir: payload.artifactsDir,
|
|
105
|
+
agentId: payload.autoResumeTarget.agentId,
|
|
106
|
+
message: payload.autoResumeTarget.message,
|
|
107
|
+
from: payload.agentId,
|
|
108
|
+
appendedSystemPrompt: payload.autoResumeTarget.appendedSystemPrompt,
|
|
109
|
+
extensionPath: payload.autoResumeTarget.extensionPath
|
|
110
|
+
});
|
|
111
|
+
}
|
|
94
112
|
const finalState = readAgentState(payload.artifactsDir, payload.agentId);
|
|
95
113
|
if (finalState) writeAgentState(payload.artifactsDir, createAgentState({
|
|
96
114
|
...finalState,
|
|
@@ -107,10 +125,106 @@ async function runDetachedAgent(payload) {
|
|
|
107
125
|
})
|
|
108
126
|
}));
|
|
109
127
|
}
|
|
128
|
+
async function runDetachedTurn(payload) {
|
|
129
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
130
|
+
const agentArtifactsDir = getAgentDir(payload.artifactsDir, payload.agentId);
|
|
131
|
+
const stdoutPath = `${agentArtifactsDir}/latest-stdout.txt`;
|
|
132
|
+
const stderrPath = `${agentArtifactsDir}/latest-stderr.txt`;
|
|
133
|
+
const invocationPath = `${agentArtifactsDir}/latest-invocation.json`;
|
|
134
|
+
mkdirSync(agentArtifactsDir, { recursive: true });
|
|
135
|
+
const stdoutStream = createWriteStream(stdoutPath, { encoding: "utf-8" });
|
|
136
|
+
const stderrStream = createWriteStream(stderrPath, { encoding: "utf-8" });
|
|
137
|
+
const child = spawn("pi", payload.piArgs, {
|
|
138
|
+
cwd: payload.repoRoot,
|
|
139
|
+
env: process.env,
|
|
140
|
+
stdio: [
|
|
141
|
+
"ignore",
|
|
142
|
+
"pipe",
|
|
143
|
+
"pipe"
|
|
144
|
+
]
|
|
145
|
+
});
|
|
146
|
+
if (child.stdout) child.stdout.pipe(stdoutStream);
|
|
147
|
+
if (child.stderr) child.stderr.pipe(stderrStream);
|
|
148
|
+
const currentState = readAgentState(payload.artifactsDir, payload.agentId);
|
|
149
|
+
if (currentState) writeAgentState(payload.artifactsDir, createAgentState({
|
|
150
|
+
...currentState,
|
|
151
|
+
status: "running",
|
|
152
|
+
lastMessage: `Responding to ${payload.from}: ${payload.message}`,
|
|
153
|
+
waitingOn: null,
|
|
154
|
+
blocked: false,
|
|
155
|
+
session: createAgentSessionRecord({
|
|
156
|
+
sessionDir: currentState.session.sessionDir,
|
|
157
|
+
sessionId: currentState.session.sessionId,
|
|
158
|
+
sessionPath: currentState.session.sessionPath,
|
|
159
|
+
processId: child.pid ?? null,
|
|
160
|
+
lastAttachedAt: currentState.session.lastAttachedAt
|
|
161
|
+
})
|
|
162
|
+
}));
|
|
163
|
+
writeFileSync(invocationPath, `${JSON.stringify({
|
|
164
|
+
command: "pi",
|
|
165
|
+
args: payload.piArgs,
|
|
166
|
+
exitCode: null,
|
|
167
|
+
sessionDir: currentState?.session.sessionDir ?? null,
|
|
168
|
+
sessionPath: currentState?.session.sessionPath ?? null,
|
|
169
|
+
sessionId: currentState?.session.sessionId ?? null,
|
|
170
|
+
processId: child.pid ?? null,
|
|
171
|
+
startedAt
|
|
172
|
+
}, null, 2)}\n`, "utf-8");
|
|
173
|
+
const { exitCode, error } = await waitForChild(child);
|
|
174
|
+
if (!stdoutStream.writableEnded) stdoutStream.end();
|
|
175
|
+
if (!stderrStream.writableEnded) stderrStream.end();
|
|
176
|
+
await Promise.all([finished(stdoutStream), finished(stderrStream)]);
|
|
177
|
+
const stdout = readFileSync(stdoutPath, "utf-8");
|
|
178
|
+
const stderr = readFileSync(stderrPath, "utf-8");
|
|
179
|
+
const latestSession = getLatestAgentSession(payload.artifactsDir, payload.agentId);
|
|
180
|
+
const completionMessage = stdout.trim() || (error?.message?.trim() ?? "") || (exitCode === 0 ? `${payload.role} turn completed` : `${payload.role} turn exited with code ${exitCode}`);
|
|
181
|
+
if (error) writeFileSync(stderrPath, `${stderr}${stderr.endsWith("\n") || stderr.length === 0 ? "" : "\n"}${error.message}\n`, "utf-8");
|
|
182
|
+
writeFileSync(invocationPath, `${JSON.stringify({
|
|
183
|
+
command: "pi",
|
|
184
|
+
args: payload.piArgs,
|
|
185
|
+
exitCode,
|
|
186
|
+
sessionDir: latestSession.sessionDir,
|
|
187
|
+
sessionPath: latestSession.sessionPath,
|
|
188
|
+
sessionId: latestSession.sessionId,
|
|
189
|
+
processId: child.pid ?? null,
|
|
190
|
+
startedAt,
|
|
191
|
+
endedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
192
|
+
}, null, 2)}\n`, "utf-8");
|
|
193
|
+
appendAgentMessage({
|
|
194
|
+
artifactsDir: payload.artifactsDir,
|
|
195
|
+
agentId: payload.agentId,
|
|
196
|
+
box: "outbox",
|
|
197
|
+
from: payload.agentId,
|
|
198
|
+
body: completionMessage
|
|
199
|
+
});
|
|
200
|
+
const finalState = readAgentState(payload.artifactsDir, payload.agentId);
|
|
201
|
+
if (finalState) writeAgentState(payload.artifactsDir, createAgentState({
|
|
202
|
+
...finalState,
|
|
203
|
+
status: exitCode === 0 ? "idle" : "blocked",
|
|
204
|
+
lastMessage: completionMessage,
|
|
205
|
+
waitingOn: exitCode === 0 ? null : "human-or-follow-up-run",
|
|
206
|
+
blocked: exitCode !== 0,
|
|
207
|
+
session: createAgentSessionRecord({
|
|
208
|
+
sessionDir: latestSession.sessionDir,
|
|
209
|
+
sessionId: latestSession.sessionId,
|
|
210
|
+
sessionPath: latestSession.sessionPath,
|
|
211
|
+
processId: null,
|
|
212
|
+
lastAttachedAt: finalState.session.lastAttachedAt
|
|
213
|
+
})
|
|
214
|
+
}));
|
|
215
|
+
try {
|
|
216
|
+
rmSync(payload.wakeLockPath, { force: true });
|
|
217
|
+
} catch {}
|
|
218
|
+
}
|
|
110
219
|
async function main() {
|
|
111
220
|
const [encodedPayload] = process.argv.slice(2);
|
|
112
221
|
if (!encodedPayload) throw new Error("Missing detached agent payload");
|
|
113
|
-
|
|
222
|
+
const payload = JSON.parse(Buffer.from(encodedPayload, "base64url").toString("utf-8"));
|
|
223
|
+
if (payload.kind === "turn") {
|
|
224
|
+
await runDetachedTurn(payload);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
await runDetachedAgent(payload);
|
|
114
228
|
}
|
|
115
229
|
main().catch((error) => {
|
|
116
230
|
console.error(error instanceof Error ? error.stack ?? error.message : String(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.mjs","names":[],"sources":["../src/agent-runner.ts"],"sourcesContent":["import { spawn } from \"node:child_process\"\nimport { createWriteStream, mkdirSync, readFileSync, writeFileSync } from \"node:fs\"\nimport { finished } from \"node:stream/promises\"\nimport {\n\tappendAgentMessage,\n\tcreateAgentSessionRecord,\n\tcreateAgentState,\n\tgetAgentDir,\n\tgetLatestAgentSession,\n\treadAgentState,\n\twriteAgentState,\n} from \"./agents.js\"\nimport { updateTaskRecordStatus } from \"./tasks.js\"\n\ninterface DetachedAgentRunPayload {\n\trepoRoot: string\n\tartifactsDir: string\n\tagentId: string\n\trole: string\n\ttask: string | null\n\ttaskId: string | null\n\tsessionDir: string\n\tpiArgs: string[]\n}\n\ninterface ChildCompletion {\n\texitCode: number\n\terror: Error | null\n}\n\nasync function waitForChild(child: ReturnType<typeof spawn>): Promise<ChildCompletion> {\n\treturn new Promise((resolve) => {\n\t\tlet error: Error | null = null\n\t\tchild.once(\"error\", (value) => {\n\t\t\terror = value\n\t\t})\n\t\tchild.once(\"close\", (code) => {\n\t\t\tresolve({\n\t\t\t\texitCode: code ?? 1,\n\t\t\t\terror,\n\t\t\t})\n\t\t})\n\t})\n}\n\nasync function runDetachedAgent(payload: DetachedAgentRunPayload) {\n\tconst startedAt = new Date().toISOString()\n\tconst agentArtifactsDir = getAgentDir(payload.artifactsDir, payload.agentId)\n\tconst stdoutPath = `${agentArtifactsDir}/latest-stdout.txt`\n\tconst stderrPath = `${agentArtifactsDir}/latest-stderr.txt`\n\tconst invocationPath = `${agentArtifactsDir}/latest-invocation.json`\n\tmkdirSync(agentArtifactsDir, { recursive: true })\n\n\tconst stdoutStream = createWriteStream(stdoutPath, { encoding: \"utf-8\" })\n\tconst stderrStream = createWriteStream(stderrPath, { encoding: \"utf-8\" })\n\tconst child = spawn(\"pi\", payload.piArgs, {\n\t\tcwd: payload.repoRoot,\n\t\tenv: process.env,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t})\n\n\tif (child.stdout) child.stdout.pipe(stdoutStream)\n\tif (child.stderr) child.stderr.pipe(stderrStream)\n\n\tconst currentState = readAgentState(payload.artifactsDir, payload.agentId)\n\tif (currentState) {\n\t\twriteAgentState(\n\t\t\tpayload.artifactsDir,\n\t\t\tcreateAgentState({\n\t\t\t\t...currentState,\n\t\t\t\tstatus: \"running\",\n\t\t\t\tlastMessage: payload.task ? `Running ${payload.role} task: ${payload.task}` : `Running ${payload.role} agent`,\n\t\t\t\twaitingOn: null,\n\t\t\t\tblocked: false,\n\t\t\t\tsession: createAgentSessionRecord({\n\t\t\t\t\tsessionDir: payload.sessionDir,\n\t\t\t\t\tsessionId: currentState.session.sessionId,\n\t\t\t\t\tsessionPath: currentState.session.sessionPath,\n\t\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\t\tlastAttachedAt: currentState.session.lastAttachedAt,\n\t\t\t\t}),\n\t\t\t}),\n\t\t)\n\t}\n\n\twriteFileSync(\n\t\tinvocationPath,\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\tcommand: \"pi\",\n\t\t\t\targs: payload.piArgs,\n\t\t\t\texitCode: null,\n\t\t\t\tsessionDir: payload.sessionDir,\n\t\t\t\tsessionPath: null,\n\t\t\t\tsessionId: null,\n\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\tstartedAt,\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)}\\n`,\n\t\t\"utf-8\",\n\t)\n\n\tconst { exitCode, error } = await waitForChild(child)\n\tif (!stdoutStream.writableEnded) stdoutStream.end()\n\tif (!stderrStream.writableEnded) stderrStream.end()\n\tawait Promise.all([finished(stdoutStream), finished(stderrStream)])\n\n\tconst stdout = readFileSync(stdoutPath, \"utf-8\")\n\tconst stderr = readFileSync(stderrPath, \"utf-8\")\n\tconst latestSession = getLatestAgentSession(payload.artifactsDir, payload.agentId)\n\tconst completionMessage =\n\t\tstdout.trim() ||\n\t\t(error?.message?.trim() ?? \"\") ||\n\t\t(exitCode === 0 ? `${payload.role} run completed` : `${payload.role} run exited with code ${exitCode}`)\n\n\tif (error) {\n\t\twriteFileSync(stderrPath, `${stderr}${stderr.endsWith(\"\\n\") || stderr.length === 0 ? \"\" : \"\\n\"}${error.message}\\n`, \"utf-8\")\n\t}\n\n\twriteFileSync(\n\t\tinvocationPath,\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\tcommand: \"pi\",\n\t\t\t\targs: payload.piArgs,\n\t\t\t\texitCode,\n\t\t\t\tsessionDir: latestSession.sessionDir ?? payload.sessionDir,\n\t\t\t\tsessionPath: latestSession.sessionPath,\n\t\t\t\tsessionId: latestSession.sessionId,\n\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\tstartedAt,\n\t\t\t\tendedAt: new Date().toISOString(),\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)}\\n`,\n\t\t\"utf-8\",\n\t)\n\n\tappendAgentMessage({\n\t\tartifactsDir: payload.artifactsDir,\n\t\tagentId: payload.agentId,\n\t\tbox: \"outbox\",\n\t\tfrom: payload.agentId,\n\t\tbody: completionMessage,\n\t})\n\n\tif (payload.taskId) {\n\t\tupdateTaskRecordStatus(payload.artifactsDir, payload.taskId, exitCode === 0 ? \"completed\" : \"blocked\")\n\t}\n\n\tconst finalState = readAgentState(payload.artifactsDir, payload.agentId)\n\tif (finalState) {\n\t\twriteAgentState(\n\t\t\tpayload.artifactsDir,\n\t\t\tcreateAgentState({\n\t\t\t\t...finalState,\n\t\t\t\tstatus: exitCode === 0 ? \"idle\" : \"blocked\",\n\t\t\t\tlastMessage: completionMessage,\n\t\t\t\twaitingOn: exitCode === 0 ? null : \"human-or-follow-up-run\",\n\t\t\t\tblocked: exitCode !== 0,\n\t\t\t\tsession: createAgentSessionRecord({\n\t\t\t\t\tsessionDir: latestSession.sessionDir ?? payload.sessionDir,\n\t\t\t\t\tsessionId: latestSession.sessionId,\n\t\t\t\t\tsessionPath: latestSession.sessionPath,\n\t\t\t\t\tprocessId: null,\n\t\t\t\t\tlastAttachedAt: finalState.session.lastAttachedAt,\n\t\t\t\t}),\n\t\t\t}),\n\t\t)\n\t}\n}\n\nasync function main() {\n\tconst [encodedPayload] = process.argv.slice(2)\n\tif (!encodedPayload) {\n\t\tthrow new Error(\"Missing detached agent payload\")\n\t}\n\n\tconst payload = JSON.parse(Buffer.from(encodedPayload, \"base64url\").toString(\"utf-8\")) as DetachedAgentRunPayload\n\tawait runDetachedAgent(payload)\n}\n\nvoid main().catch((error) => {\n\tconsole.error(error instanceof Error ? error.stack ?? error.message : String(error))\n\tprocess.exitCode = 1\n})\n"],"mappings":";;;;;;AA8BA,eAAe,aAAa,OAA2D;AACtF,QAAO,IAAI,SAAS,YAAY;EAC/B,IAAI,QAAsB;AAC1B,QAAM,KAAK,UAAU,UAAU;AAC9B,WAAQ;IACP;AACF,QAAM,KAAK,UAAU,SAAS;AAC7B,WAAQ;IACP,UAAU,QAAQ;IAClB;IACA,CAAC;IACD;GACD;;AAGH,eAAe,iBAAiB,SAAkC;CACjE,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;CAC1C,MAAM,oBAAoB,YAAY,QAAQ,cAAc,QAAQ,QAAQ;CAC5E,MAAM,aAAa,GAAG,kBAAkB;CACxC,MAAM,aAAa,GAAG,kBAAkB;CACxC,MAAM,iBAAiB,GAAG,kBAAkB;AAC5C,WAAU,mBAAmB,EAAE,WAAW,MAAM,CAAC;CAEjD,MAAM,eAAe,kBAAkB,YAAY,EAAE,UAAU,SAAS,CAA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C,OAAO,UAAU;AAC5B,SAAQ,MAAM,iBAAiB,QAAQ,MAAM,SAAS,MAAM,UAAU,OAAO,MAAM,CAAC;AACpF,SAAQ,WAAW;EAClB"}
|
|
1
|
+
{"version":3,"file":"agent-runner.mjs","names":[],"sources":["../src/agent-runner.ts"],"sourcesContent":["import { spawn } from \"node:child_process\"\nimport { createWriteStream, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\"\nimport { finished } from \"node:stream/promises\"\nimport {\n\tappendAgentMessage,\n\tcreateAgentSessionRecord,\n\tcreateAgentState,\n\tgetAgentDir,\n\tgetLatestAgentSession,\n\treadAgentState,\n\twriteAgentState,\n} from \"./agents.js\"\nimport { notifyTaskDelegator, resumeAgentTurnDetached } from \"./orchestration.js\"\nimport { updateTaskRecordStatus } from \"./tasks.js\"\n\ninterface DetachedAgentRunPayload {\n\tkind?: \"spawn\"\n\trepoRoot: string\n\tartifactsDir: string\n\tagentId: string\n\trole: string\n\ttask: string | null\n\ttaskId: string | null\n\tsessionDir: string\n\tpiArgs: string[]\n\tautoResumeTarget?: {\n\t\tagentId: string\n\t\tmessage: string\n\t\tappendedSystemPrompt?: string | null\n\t\textensionPath?: string | null\n\t} | null\n}\n\ninterface DetachedAgentTurnPayload {\n\tkind: \"turn\"\n\trepoRoot: string\n\tartifactsDir: string\n\tagentId: string\n\trole: string\n\tmessage: string\n\tfrom: string\n\tpiArgs: string[]\n\twakeLockPath: string\n}\n\ninterface ChildCompletion {\n\texitCode: number\n\terror: Error | null\n}\n\nasync function waitForChild(child: ReturnType<typeof spawn>): Promise<ChildCompletion> {\n\treturn new Promise((resolve) => {\n\t\tlet error: Error | null = null\n\t\tchild.once(\"error\", (value) => {\n\t\t\terror = value\n\t\t})\n\t\tchild.once(\"close\", (code) => {\n\t\t\tresolve({\n\t\t\t\texitCode: code ?? 1,\n\t\t\t\terror,\n\t\t\t})\n\t\t})\n\t})\n}\n\nasync function runDetachedAgent(payload: DetachedAgentRunPayload) {\n\tconst startedAt = new Date().toISOString()\n\tconst agentArtifactsDir = getAgentDir(payload.artifactsDir, payload.agentId)\n\tconst stdoutPath = `${agentArtifactsDir}/latest-stdout.txt`\n\tconst stderrPath = `${agentArtifactsDir}/latest-stderr.txt`\n\tconst invocationPath = `${agentArtifactsDir}/latest-invocation.json`\n\tmkdirSync(agentArtifactsDir, { recursive: true })\n\n\tconst stdoutStream = createWriteStream(stdoutPath, { encoding: \"utf-8\" })\n\tconst stderrStream = createWriteStream(stderrPath, { encoding: \"utf-8\" })\n\tconst child = spawn(\"pi\", payload.piArgs, {\n\t\tcwd: payload.repoRoot,\n\t\tenv: process.env,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t})\n\n\tif (child.stdout) child.stdout.pipe(stdoutStream)\n\tif (child.stderr) child.stderr.pipe(stderrStream)\n\n\tconst currentState = readAgentState(payload.artifactsDir, payload.agentId)\n\tif (currentState) {\n\t\twriteAgentState(\n\t\t\tpayload.artifactsDir,\n\t\t\tcreateAgentState({\n\t\t\t\t...currentState,\n\t\t\t\tstatus: \"running\",\n\t\t\t\tlastMessage: payload.task ? `Running ${payload.role} task: ${payload.task}` : `Running ${payload.role} agent`,\n\t\t\t\twaitingOn: null,\n\t\t\t\tblocked: false,\n\t\t\t\tsession: createAgentSessionRecord({\n\t\t\t\t\tsessionDir: payload.sessionDir,\n\t\t\t\t\tsessionId: currentState.session.sessionId,\n\t\t\t\t\tsessionPath: currentState.session.sessionPath,\n\t\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\t\tlastAttachedAt: currentState.session.lastAttachedAt,\n\t\t\t\t}),\n\t\t\t}),\n\t\t)\n\t}\n\n\twriteFileSync(\n\t\tinvocationPath,\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\tcommand: \"pi\",\n\t\t\t\targs: payload.piArgs,\n\t\t\t\texitCode: null,\n\t\t\t\tsessionDir: payload.sessionDir,\n\t\t\t\tsessionPath: null,\n\t\t\t\tsessionId: null,\n\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\tstartedAt,\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)}\\n`,\n\t\t\"utf-8\",\n\t)\n\n\tconst { exitCode, error } = await waitForChild(child)\n\tif (!stdoutStream.writableEnded) stdoutStream.end()\n\tif (!stderrStream.writableEnded) stderrStream.end()\n\tawait Promise.all([finished(stdoutStream), finished(stderrStream)])\n\n\tconst stdout = readFileSync(stdoutPath, \"utf-8\")\n\tconst stderr = readFileSync(stderrPath, \"utf-8\")\n\tconst latestSession = getLatestAgentSession(payload.artifactsDir, payload.agentId)\n\tconst completionMessage =\n\t\tstdout.trim() ||\n\t\t(error?.message?.trim() ?? \"\") ||\n\t\t(exitCode === 0 ? `${payload.role} run completed` : `${payload.role} run exited with code ${exitCode}`)\n\n\tif (error) {\n\t\twriteFileSync(stderrPath, `${stderr}${stderr.endsWith(\"\\n\") || stderr.length === 0 ? \"\" : \"\\n\"}${error.message}\\n`, \"utf-8\")\n\t}\n\n\twriteFileSync(\n\t\tinvocationPath,\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\tcommand: \"pi\",\n\t\t\t\targs: payload.piArgs,\n\t\t\t\texitCode,\n\t\t\t\tsessionDir: latestSession.sessionDir ?? payload.sessionDir,\n\t\t\t\tsessionPath: latestSession.sessionPath,\n\t\t\t\tsessionId: latestSession.sessionId,\n\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\tstartedAt,\n\t\t\t\tendedAt: new Date().toISOString(),\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)}\\n`,\n\t\t\"utf-8\",\n\t)\n\n\tappendAgentMessage({\n\t\tartifactsDir: payload.artifactsDir,\n\t\tagentId: payload.agentId,\n\t\tbox: \"outbox\",\n\t\tfrom: payload.agentId,\n\t\tbody: completionMessage,\n\t})\n\n\tif (payload.taskId) {\n\t\tupdateTaskRecordStatus(payload.artifactsDir, payload.taskId, exitCode === 0 ? \"completed\" : \"blocked\")\n\t\tnotifyTaskDelegator({\n\t\t\tartifactsDir: payload.artifactsDir,\n\t\t\tagentId: payload.agentId,\n\t\t\ttaskId: payload.taskId,\n\t\t\tcompletionMessage,\n\t\t\toutcome: exitCode === 0 ? \"completed\" : \"blocked\",\n\t\t})\n\t\tif (payload.autoResumeTarget) {\n\t\t\tresumeAgentTurnDetached({\n\t\t\t\trepoRoot: payload.repoRoot,\n\t\t\t\tartifactsDir: payload.artifactsDir,\n\t\t\t\tagentId: payload.autoResumeTarget.agentId,\n\t\t\t\tmessage: payload.autoResumeTarget.message,\n\t\t\t\tfrom: payload.agentId,\n\t\t\t\tappendedSystemPrompt: payload.autoResumeTarget.appendedSystemPrompt,\n\t\t\t\textensionPath: payload.autoResumeTarget.extensionPath,\n\t\t\t})\n\t\t}\n\t}\n\n\tconst finalState = readAgentState(payload.artifactsDir, payload.agentId)\n\tif (finalState) {\n\t\twriteAgentState(\n\t\t\tpayload.artifactsDir,\n\t\t\tcreateAgentState({\n\t\t\t\t...finalState,\n\t\t\t\tstatus: exitCode === 0 ? \"idle\" : \"blocked\",\n\t\t\t\tlastMessage: completionMessage,\n\t\t\t\twaitingOn: exitCode === 0 ? null : \"human-or-follow-up-run\",\n\t\t\t\tblocked: exitCode !== 0,\n\t\t\t\tsession: createAgentSessionRecord({\n\t\t\t\t\tsessionDir: latestSession.sessionDir ?? payload.sessionDir,\n\t\t\t\t\tsessionId: latestSession.sessionId,\n\t\t\t\t\tsessionPath: latestSession.sessionPath,\n\t\t\t\t\tprocessId: null,\n\t\t\t\t\tlastAttachedAt: finalState.session.lastAttachedAt,\n\t\t\t\t}),\n\t\t\t}),\n\t\t)\n\t}\n}\n\nasync function runDetachedTurn(payload: DetachedAgentTurnPayload) {\n\tconst startedAt = new Date().toISOString()\n\tconst agentArtifactsDir = getAgentDir(payload.artifactsDir, payload.agentId)\n\tconst stdoutPath = `${agentArtifactsDir}/latest-stdout.txt`\n\tconst stderrPath = `${agentArtifactsDir}/latest-stderr.txt`\n\tconst invocationPath = `${agentArtifactsDir}/latest-invocation.json`\n\tmkdirSync(agentArtifactsDir, { recursive: true })\n\n\tconst stdoutStream = createWriteStream(stdoutPath, { encoding: \"utf-8\" })\n\tconst stderrStream = createWriteStream(stderrPath, { encoding: \"utf-8\" })\n\tconst child = spawn(\"pi\", payload.piArgs, {\n\t\tcwd: payload.repoRoot,\n\t\tenv: process.env,\n\t\tstdio: [\"ignore\", \"pipe\", \"pipe\"],\n\t})\n\n\tif (child.stdout) child.stdout.pipe(stdoutStream)\n\tif (child.stderr) child.stderr.pipe(stderrStream)\n\n\tconst currentState = readAgentState(payload.artifactsDir, payload.agentId)\n\tif (currentState) {\n\t\twriteAgentState(\n\t\t\tpayload.artifactsDir,\n\t\t\tcreateAgentState({\n\t\t\t\t...currentState,\n\t\t\t\tstatus: \"running\",\n\t\t\t\tlastMessage: `Responding to ${payload.from}: ${payload.message}`,\n\t\t\t\twaitingOn: null,\n\t\t\t\tblocked: false,\n\t\t\t\tsession: createAgentSessionRecord({\n\t\t\t\t\tsessionDir: currentState.session.sessionDir,\n\t\t\t\t\tsessionId: currentState.session.sessionId,\n\t\t\t\t\tsessionPath: currentState.session.sessionPath,\n\t\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\t\tlastAttachedAt: currentState.session.lastAttachedAt,\n\t\t\t\t}),\n\t\t\t}),\n\t\t)\n\t}\n\n\twriteFileSync(\n\t\tinvocationPath,\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\tcommand: \"pi\",\n\t\t\t\targs: payload.piArgs,\n\t\t\t\texitCode: null,\n\t\t\t\tsessionDir: currentState?.session.sessionDir ?? null,\n\t\t\t\tsessionPath: currentState?.session.sessionPath ?? null,\n\t\t\t\tsessionId: currentState?.session.sessionId ?? null,\n\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\tstartedAt,\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)}\\n`,\n\t\t\"utf-8\",\n\t)\n\n\tconst { exitCode, error } = await waitForChild(child)\n\tif (!stdoutStream.writableEnded) stdoutStream.end()\n\tif (!stderrStream.writableEnded) stderrStream.end()\n\tawait Promise.all([finished(stdoutStream), finished(stderrStream)])\n\n\tconst stdout = readFileSync(stdoutPath, \"utf-8\")\n\tconst stderr = readFileSync(stderrPath, \"utf-8\")\n\tconst latestSession = getLatestAgentSession(payload.artifactsDir, payload.agentId)\n\tconst completionMessage =\n\t\tstdout.trim() ||\n\t\t(error?.message?.trim() ?? \"\") ||\n\t\t(exitCode === 0 ? `${payload.role} turn completed` : `${payload.role} turn exited with code ${exitCode}`)\n\n\tif (error) {\n\t\twriteFileSync(stderrPath, `${stderr}${stderr.endsWith(\"\\n\") || stderr.length === 0 ? \"\" : \"\\n\"}${error.message}\\n`, \"utf-8\")\n\t}\n\n\twriteFileSync(\n\t\tinvocationPath,\n\t\t`${JSON.stringify(\n\t\t\t{\n\t\t\t\tcommand: \"pi\",\n\t\t\t\targs: payload.piArgs,\n\t\t\t\texitCode,\n\t\t\t\tsessionDir: latestSession.sessionDir,\n\t\t\t\tsessionPath: latestSession.sessionPath,\n\t\t\t\tsessionId: latestSession.sessionId,\n\t\t\t\tprocessId: child.pid ?? null,\n\t\t\t\tstartedAt,\n\t\t\t\tendedAt: new Date().toISOString(),\n\t\t\t},\n\t\t\tnull,\n\t\t\t2,\n\t\t)}\\n`,\n\t\t\"utf-8\",\n\t)\n\n\tappendAgentMessage({\n\t\tartifactsDir: payload.artifactsDir,\n\t\tagentId: payload.agentId,\n\t\tbox: \"outbox\",\n\t\tfrom: payload.agentId,\n\t\tbody: completionMessage,\n\t})\n\n\tconst finalState = readAgentState(payload.artifactsDir, payload.agentId)\n\tif (finalState) {\n\t\twriteAgentState(\n\t\t\tpayload.artifactsDir,\n\t\t\tcreateAgentState({\n\t\t\t\t...finalState,\n\t\t\t\tstatus: exitCode === 0 ? \"idle\" : \"blocked\",\n\t\t\t\tlastMessage: completionMessage,\n\t\t\t\twaitingOn: exitCode === 0 ? null : \"human-or-follow-up-run\",\n\t\t\t\tblocked: exitCode !== 0,\n\t\t\t\tsession: createAgentSessionRecord({\n\t\t\t\t\tsessionDir: latestSession.sessionDir,\n\t\t\t\t\tsessionId: latestSession.sessionId,\n\t\t\t\t\tsessionPath: latestSession.sessionPath,\n\t\t\t\t\tprocessId: null,\n\t\t\t\t\tlastAttachedAt: finalState.session.lastAttachedAt,\n\t\t\t\t}),\n\t\t\t}),\n\t\t)\n\t}\n\n\ttry {\n\t\trmSync(payload.wakeLockPath, { force: true })\n\t} catch {\n\t\t// ignore wake lock cleanup failures\n\t}\n}\n\nasync function main() {\n\tconst [encodedPayload] = process.argv.slice(2)\n\tif (!encodedPayload) {\n\t\tthrow new Error(\"Missing detached agent payload\")\n\t}\n\n\tconst payload = JSON.parse(Buffer.from(encodedPayload, \"base64url\").toString(\"utf-8\")) as DetachedAgentRunPayload | DetachedAgentTurnPayload\n\tif (payload.kind === \"turn\") {\n\t\tawait runDetachedTurn(payload)\n\t\treturn\n\t}\n\n\tawait runDetachedAgent(payload)\n}\n\nvoid main().catch((error) => {\n\tconsole.error(error instanceof Error ? error.stack ?? error.message : String(error))\n\tprocess.exitCode = 1\n})\n"],"mappings":";;;;;;AAkDA,eAAe,aAAa,OAA2D;AACtF,QAAO,IAAI,SAAS,YAAY;EAC/B,IAAI,QAAsB;AAC1B,QAAM,KAAK,UAAU,UAAU;AAC9B,WAAQ;IACP;AACF,QAAM,KAAK,UAAU,SAAS;AAC7B,WAAQ;IACP,UAAU,QAAQ;IAClB;IACA,CAAC;IACD;GACD;;AAGH,eAAe,iBAAiB,SAAkC;CACjE,MAAM,6BAAY,IAAI,MAAM,EAAC,aAAa;CAC1C,MAAM,oBAAoB,YAAY,QAAQ,cAAc,QAAQ,QAAQ;CAC5E,MAAM,aAAa,GAAG,kBAAkB;CACxC,MAAM,aAAa,GAAG,kBAAkB;CACxC,MAAM,iBAAiB,GAAG,kBAAkB;AAC5C,WAAU,mBAAmB,EAAE,WAAW,MAAM,CAAC;C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AAW,aAAa,IAAI,OAAO;EACnC,SAAS,aAAa;EACtB,SAAS,yBAAyB;GACjC,YAAY,cAAc;GAC1B,WAAW,cAAc;GACzB,aAAa,cAAc;GAC3B,WAAW;GACX,gBAAgB,WAAW,QAAQ;GACnC,CAAC;EACF,CAAC,CACF;AAGF,KAAI;AACH,SAAO,QAAQ,cAAc,EAAE,OAAO,MAAM,CAAC;SACtC;;AAKT,eAAe,OAAO;CACrB,MAAM,CAAC,kBAAkB,QAAQ,KAAK,MAAM,EAAE;AAC9C,KAAI,CAAC,eACJ,OAAM,IAAI,MAAM,iCAAiC;CAGlD,MAAM,UAAU,KAAK,MAAM,OAAO,KAAK,gBAAgB,YAAY,CAAC,SAAS,QAAQ,CAAC;AACtF,KAAI,QAAQ,SAAS,QAAQ;AAC5B,QAAM,gBAAgB,QAAQ;AAC9B;;AAGD,OAAM,iBAAiB,QAAQ;;AAG3B,MAAM,CAAC,OAAO,UAAU;AAC5B,SAAQ,MAAM,iBAAiB,QAAQ,MAAM,SAAS,MAAM,UAAU,OAAO,MAAM,CAAC;AACpF,SAAQ,WAAW;EAClB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -293,6 +293,7 @@ interface SpawnAgentRunOptions {
|
|
|
293
293
|
appendedSystemPrompt?: string | null | undefined;
|
|
294
294
|
extensionPath?: string | null | undefined;
|
|
295
295
|
taskId?: string | null | undefined;
|
|
296
|
+
autoResumeTarget?: AutoResumeTarget | null | undefined;
|
|
296
297
|
}
|
|
297
298
|
interface SpawnAgentRunResult {
|
|
298
299
|
launch: {
|
|
@@ -309,6 +310,7 @@ interface DelegateTaskOptions {
|
|
|
309
310
|
agentId?: string | null | undefined;
|
|
310
311
|
appendedSystemPrompt?: string | null | undefined;
|
|
311
312
|
extensionPath?: string | null | undefined;
|
|
313
|
+
completionAutoResumeTarget?: AutoResumeTarget | null | undefined;
|
|
312
314
|
task: string;
|
|
313
315
|
}
|
|
314
316
|
interface DelegateTaskResult {
|
|
@@ -321,6 +323,21 @@ interface ResolvedAgentSession {
|
|
|
321
323
|
state: AgentStateSnapshot;
|
|
322
324
|
session: AgentSessionRecord;
|
|
323
325
|
}
|
|
326
|
+
interface AutoResumeTarget {
|
|
327
|
+
agentId: string;
|
|
328
|
+
message: string;
|
|
329
|
+
appendedSystemPrompt?: string | null | undefined;
|
|
330
|
+
extensionPath?: string | null | undefined;
|
|
331
|
+
}
|
|
332
|
+
interface ResumeAgentTurnDetachedOptions {
|
|
333
|
+
repoRoot: string;
|
|
334
|
+
artifactsDir: string;
|
|
335
|
+
agentId: string;
|
|
336
|
+
message: string;
|
|
337
|
+
from?: string;
|
|
338
|
+
appendedSystemPrompt?: string | null | undefined;
|
|
339
|
+
extensionPath?: string | null | undefined;
|
|
340
|
+
}
|
|
324
341
|
interface RunAgentTurnOptions {
|
|
325
342
|
repoRoot: string;
|
|
326
343
|
artifactsDir: string;
|
|
@@ -344,12 +361,20 @@ declare function createRolePrompt(input: {
|
|
|
344
361
|
repoRoot: string;
|
|
345
362
|
}): string;
|
|
346
363
|
declare function resolveAgentSession(agentId: string, artifactsDir: string): ResolvedAgentSession;
|
|
364
|
+
declare function resumeAgentTurnDetached(options: ResumeAgentTurnDetachedOptions): SpawnAgentRunResult | null;
|
|
347
365
|
declare function queueAgentMessage(input: {
|
|
348
366
|
artifactsDir: string;
|
|
349
367
|
agentId: string;
|
|
350
368
|
from: string;
|
|
351
369
|
body: string;
|
|
352
370
|
}): void;
|
|
371
|
+
declare function notifyTaskDelegator(input: {
|
|
372
|
+
artifactsDir: string;
|
|
373
|
+
agentId: string;
|
|
374
|
+
taskId: string | null;
|
|
375
|
+
completionMessage: string;
|
|
376
|
+
outcome: "completed" | "blocked";
|
|
377
|
+
}): void;
|
|
353
378
|
declare function updateAgentStatus(input: {
|
|
354
379
|
artifactsDir: string;
|
|
355
380
|
agentId: string;
|
|
@@ -462,5 +487,5 @@ declare function updateTaskRecordStatus(artifactsDir: string, taskId: string, st
|
|
|
462
487
|
declare function readTaskRecord(artifactsDir: string, taskId: string): TaskRecord | null;
|
|
463
488
|
declare function listTaskRecords(artifactsDir: string): TaskRecord[];
|
|
464
489
|
//#endregion
|
|
465
|
-
export { AgentMailbox, AgentMessageRecord, AgentSessionRecord, AgentStateSnapshot, AgentStatus, BoardSnapshot, CommandResult, ControllerRunResult, CreateInterruptInput, DelegateTaskOptions, DelegateTaskResult, FeedbackCycle, FixType, InterruptCategory, InterruptRecord, LoopIterationResult, LoopOptions, LoopRunResult, LoopStopReason, MetricsSnapshot, PiInvocationRecord, RepoLeaseRecord, ResolvedAgentSession, RunAgentTurnOptions, RunAgentTurnResult, RunManifest, RunMode, RunOptions, RunSummary, SpawnAgentRunOptions, SpawnAgentRunResult, StopAgentResult, StopManagedAgentsOptions, StopManagedAgentsResult, StopRepoLeaseResult, StopRepoLeasesOptions, StopRepoLeasesResult, TaskAttempt, TaskRecord, TaskStatus, acquireRepoLease, appendAgentMessage, appendJsonl, assertCommandAvailable, assertSuccess, computeAutonomousCompletionRate, computeContextCoverageScore, computeFeedbackToDemoCycleTime, computeInterruptRate, computeMeanTimeToCorrect, computeMetrics, createAgentSessionRecord, createAgentState, createInterruptRecord, createPiAuthHelpMessage, createRepoSlug, createRolePrompt, createTaskRecord, delegateTask, detectPiAuthFailure, evaluateStopCondition, getAgentDir, getAgentMailboxPath, getAgentSessionPath, getAgentSessionsDir, getAgentStatePath, getAgentsDir, getCurrentBranch, getLatestAgentSession, getRepoIdentity, getRepoRoot, getSessionIdFromPath, getTaskPath, getTasksDir, isGitRepo, listAgentStates, listRepoLeases, listTaskRecords, queueAgentMessage, readAgentMessages, readAgentState, readJsonl, readTaskRecord, resolveAgentSession, resolveInterrupt, runAgentTurn, runCommandInteractive, runCommandSync, runController, runLoop, snapshotBoard, spawnAgentRun, stopManagedAgents, stopRepoLeases, updateAgentStatus, updateTaskRecordStatus, writeAgentState, writeTaskRecord };
|
|
490
|
+
export { AgentMailbox, AgentMessageRecord, AgentSessionRecord, AgentStateSnapshot, AgentStatus, AutoResumeTarget, BoardSnapshot, CommandResult, ControllerRunResult, CreateInterruptInput, DelegateTaskOptions, DelegateTaskResult, FeedbackCycle, FixType, InterruptCategory, InterruptRecord, LoopIterationResult, LoopOptions, LoopRunResult, LoopStopReason, MetricsSnapshot, PiInvocationRecord, RepoLeaseRecord, ResolvedAgentSession, ResumeAgentTurnDetachedOptions, RunAgentTurnOptions, RunAgentTurnResult, RunManifest, RunMode, RunOptions, RunSummary, SpawnAgentRunOptions, SpawnAgentRunResult, StopAgentResult, StopManagedAgentsOptions, StopManagedAgentsResult, StopRepoLeaseResult, StopRepoLeasesOptions, StopRepoLeasesResult, TaskAttempt, TaskRecord, TaskStatus, acquireRepoLease, appendAgentMessage, appendJsonl, assertCommandAvailable, assertSuccess, computeAutonomousCompletionRate, computeContextCoverageScore, computeFeedbackToDemoCycleTime, computeInterruptRate, computeMeanTimeToCorrect, computeMetrics, createAgentSessionRecord, createAgentState, createInterruptRecord, createPiAuthHelpMessage, createRepoSlug, createRolePrompt, createTaskRecord, delegateTask, detectPiAuthFailure, evaluateStopCondition, getAgentDir, getAgentMailboxPath, getAgentSessionPath, getAgentSessionsDir, getAgentStatePath, getAgentsDir, getCurrentBranch, getLatestAgentSession, getRepoIdentity, getRepoRoot, getSessionIdFromPath, getTaskPath, getTasksDir, isGitRepo, listAgentStates, listRepoLeases, listTaskRecords, notifyTaskDelegator, queueAgentMessage, readAgentMessages, readAgentState, readJsonl, readTaskRecord, resolveAgentSession, resolveInterrupt, resumeAgentTurnDetached, runAgentTurn, runCommandInteractive, runCommandSync, runController, runLoop, snapshotBoard, spawnAgentRun, stopManagedAgents, stopRepoLeases, updateAgentStatus, updateTaskRecordStatus, writeAgentState, writeTaskRecord };
|
|
466
491
|
//# sourceMappingURL=index.d.mts.map
|