@schilderlabs/pitown-core 0.2.1 → 0.2.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/agent-runner.d.mts +1 -0
- package/dist/agent-runner.mjs +122 -0
- package/dist/agent-runner.mjs.map +1 -0
- package/dist/index.d.mts +76 -23
- package/dist/index.mjs +327 -277
- package/dist/index.mjs.map +1 -1
- package/dist/tasks-BfQm-7-O.mjs +195 -0
- package/dist/tasks-BfQm-7-O.mjs.map +1 -0
- package/package.json +14 -19
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { S as writeAgentState, _ as getLatestAgentSession, c as appendAgentMessage, d as getAgentDir, l as createAgentSessionRecord, o as updateTaskRecordStatus, u as createAgentState, x as readAgentState } from "./tasks-BfQm-7-O.mjs";
|
|
2
|
+
import { createWriteStream, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { finished } from "node:stream/promises";
|
|
5
|
+
|
|
6
|
+
//#region src/agent-runner.ts
|
|
7
|
+
async function waitForChild(child) {
|
|
8
|
+
return new Promise((resolve) => {
|
|
9
|
+
let error = null;
|
|
10
|
+
child.once("error", (value) => {
|
|
11
|
+
error = value;
|
|
12
|
+
});
|
|
13
|
+
child.once("close", (code) => {
|
|
14
|
+
resolve({
|
|
15
|
+
exitCode: code ?? 1,
|
|
16
|
+
error
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function runDetachedAgent(payload) {
|
|
22
|
+
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
23
|
+
const agentArtifactsDir = getAgentDir(payload.artifactsDir, payload.agentId);
|
|
24
|
+
const stdoutPath = `${agentArtifactsDir}/latest-stdout.txt`;
|
|
25
|
+
const stderrPath = `${agentArtifactsDir}/latest-stderr.txt`;
|
|
26
|
+
const invocationPath = `${agentArtifactsDir}/latest-invocation.json`;
|
|
27
|
+
mkdirSync(agentArtifactsDir, { recursive: true });
|
|
28
|
+
const stdoutStream = createWriteStream(stdoutPath, { encoding: "utf-8" });
|
|
29
|
+
const stderrStream = createWriteStream(stderrPath, { encoding: "utf-8" });
|
|
30
|
+
const child = spawn("pi", payload.piArgs, {
|
|
31
|
+
cwd: payload.repoRoot,
|
|
32
|
+
env: process.env,
|
|
33
|
+
stdio: [
|
|
34
|
+
"ignore",
|
|
35
|
+
"pipe",
|
|
36
|
+
"pipe"
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
if (child.stdout) child.stdout.pipe(stdoutStream);
|
|
40
|
+
if (child.stderr) child.stderr.pipe(stderrStream);
|
|
41
|
+
const currentState = readAgentState(payload.artifactsDir, payload.agentId);
|
|
42
|
+
if (currentState) writeAgentState(payload.artifactsDir, createAgentState({
|
|
43
|
+
...currentState,
|
|
44
|
+
status: "running",
|
|
45
|
+
lastMessage: payload.task ? `Running ${payload.role} task: ${payload.task}` : `Running ${payload.role} agent`,
|
|
46
|
+
waitingOn: null,
|
|
47
|
+
blocked: false,
|
|
48
|
+
session: createAgentSessionRecord({
|
|
49
|
+
sessionDir: payload.sessionDir,
|
|
50
|
+
sessionId: currentState.session.sessionId,
|
|
51
|
+
sessionPath: currentState.session.sessionPath,
|
|
52
|
+
processId: child.pid ?? null,
|
|
53
|
+
lastAttachedAt: currentState.session.lastAttachedAt
|
|
54
|
+
})
|
|
55
|
+
}));
|
|
56
|
+
writeFileSync(invocationPath, `${JSON.stringify({
|
|
57
|
+
command: "pi",
|
|
58
|
+
args: payload.piArgs,
|
|
59
|
+
exitCode: null,
|
|
60
|
+
sessionDir: payload.sessionDir,
|
|
61
|
+
sessionPath: null,
|
|
62
|
+
sessionId: null,
|
|
63
|
+
processId: child.pid ?? null,
|
|
64
|
+
startedAt
|
|
65
|
+
}, null, 2)}\n`, "utf-8");
|
|
66
|
+
const { exitCode, error } = await waitForChild(child);
|
|
67
|
+
if (!stdoutStream.writableEnded) stdoutStream.end();
|
|
68
|
+
if (!stderrStream.writableEnded) stderrStream.end();
|
|
69
|
+
await Promise.all([finished(stdoutStream), finished(stderrStream)]);
|
|
70
|
+
const stdout = readFileSync(stdoutPath, "utf-8");
|
|
71
|
+
const stderr = readFileSync(stderrPath, "utf-8");
|
|
72
|
+
const latestSession = getLatestAgentSession(payload.artifactsDir, payload.agentId);
|
|
73
|
+
const completionMessage = stdout.trim() || (error?.message?.trim() ?? "") || (exitCode === 0 ? `${payload.role} run completed` : `${payload.role} run exited with code ${exitCode}`);
|
|
74
|
+
if (error) writeFileSync(stderrPath, `${stderr}${stderr.endsWith("\n") || stderr.length === 0 ? "" : "\n"}${error.message}\n`, "utf-8");
|
|
75
|
+
writeFileSync(invocationPath, `${JSON.stringify({
|
|
76
|
+
command: "pi",
|
|
77
|
+
args: payload.piArgs,
|
|
78
|
+
exitCode,
|
|
79
|
+
sessionDir: latestSession.sessionDir ?? payload.sessionDir,
|
|
80
|
+
sessionPath: latestSession.sessionPath,
|
|
81
|
+
sessionId: latestSession.sessionId,
|
|
82
|
+
processId: child.pid ?? null,
|
|
83
|
+
startedAt,
|
|
84
|
+
endedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
85
|
+
}, null, 2)}\n`, "utf-8");
|
|
86
|
+
appendAgentMessage({
|
|
87
|
+
artifactsDir: payload.artifactsDir,
|
|
88
|
+
agentId: payload.agentId,
|
|
89
|
+
box: "outbox",
|
|
90
|
+
from: payload.agentId,
|
|
91
|
+
body: completionMessage
|
|
92
|
+
});
|
|
93
|
+
if (payload.taskId) updateTaskRecordStatus(payload.artifactsDir, payload.taskId, exitCode === 0 ? "completed" : "blocked");
|
|
94
|
+
const finalState = readAgentState(payload.artifactsDir, payload.agentId);
|
|
95
|
+
if (finalState) writeAgentState(payload.artifactsDir, createAgentState({
|
|
96
|
+
...finalState,
|
|
97
|
+
status: exitCode === 0 ? "idle" : "blocked",
|
|
98
|
+
lastMessage: completionMessage,
|
|
99
|
+
waitingOn: exitCode === 0 ? null : "human-or-follow-up-run",
|
|
100
|
+
blocked: exitCode !== 0,
|
|
101
|
+
session: createAgentSessionRecord({
|
|
102
|
+
sessionDir: latestSession.sessionDir ?? payload.sessionDir,
|
|
103
|
+
sessionId: latestSession.sessionId,
|
|
104
|
+
sessionPath: latestSession.sessionPath,
|
|
105
|
+
processId: null,
|
|
106
|
+
lastAttachedAt: finalState.session.lastAttachedAt
|
|
107
|
+
})
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
async function main() {
|
|
111
|
+
const [encodedPayload] = process.argv.slice(2);
|
|
112
|
+
if (!encodedPayload) throw new Error("Missing detached agent payload");
|
|
113
|
+
await runDetachedAgent(JSON.parse(Buffer.from(encodedPayload, "base64url").toString("utf-8")));
|
|
114
|
+
}
|
|
115
|
+
main().catch((error) => {
|
|
116
|
+
console.error(error instanceof Error ? error.stack ?? error.message : String(error));
|
|
117
|
+
process.exitCode = 1;
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
export { };
|
|
122
|
+
//# sourceMappingURL=agent-runner.mjs.map
|
|
@@ -0,0 +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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aAAa,IAAI,SAAS;EAClC,aAAa;EACb,WAAW,aAAa,IAAI,OAAO;EACnC,SAAS,aAAa;EACtB,SAAS,yBAAyB;GACjC,YAAY,cAAc,cAAc,QAAQ;GAChD,WAAW,cAAc;GACzB,aAAa,cAAc;GAC3B,WAAW;GACX,gBAAgB,WAAW,QAAQ;GACnC,CAAC;EACF,CAAC,CACF;;AAIH,eAAe,OAAO;CACrB,MAAM,CAAC,kBAAkB,QAAQ,KAAK,MAAM,EAAE;AAC9C,KAAI,CAAC,eACJ,OAAM,IAAI,MAAM,iCAAiC;AAIlD,OAAM,iBADU,KAAK,MAAM,OAAO,KAAK,gBAAgB,YAAY,CAAC,SAAS,QAAQ,CAAC,CACvD;;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
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
type InterruptCategory = "missing-context" | "spec-gap" | "policy-gap" | "validation-gap" | "tooling-failure" | "external-blocker";
|
|
3
3
|
type FixType = "adr" | "docs" | "policy" | "prompt" | "skill" | "tooling" | "validation";
|
|
4
4
|
type RunMode = "single-pi";
|
|
5
|
-
type AgentStatus = "queued" | "starting" | "running" | "idle" | "blocked" | "completed" | "failed";
|
|
5
|
+
type AgentStatus = "queued" | "starting" | "running" | "idle" | "blocked" | "completed" | "failed" | "stopped";
|
|
6
6
|
type AgentMailbox = "inbox" | "outbox";
|
|
7
|
-
type TaskStatus = "queued" | "running" | "blocked" | "completed";
|
|
7
|
+
type TaskStatus = "queued" | "running" | "blocked" | "completed" | "aborted";
|
|
8
8
|
interface AgentSessionRecord {
|
|
9
9
|
runtime: "pi";
|
|
10
10
|
persisted: boolean;
|
|
11
11
|
sessionDir: string | null;
|
|
12
12
|
sessionId: string | null;
|
|
13
13
|
sessionPath: string | null;
|
|
14
|
+
processId: number | null;
|
|
14
15
|
lastAttachedAt: string | null;
|
|
15
16
|
}
|
|
16
17
|
interface AgentStateSnapshot {
|
|
@@ -146,12 +147,13 @@ interface ControllerRunResult {
|
|
|
146
147
|
summary: RunSummary;
|
|
147
148
|
piInvocation: PiInvocationRecord;
|
|
148
149
|
}
|
|
149
|
-
type LoopStopReason = "all-tasks-completed" | "all-remaining-tasks-blocked" | "
|
|
150
|
+
type LoopStopReason = "all-tasks-completed" | "all-remaining-tasks-blocked" | "mayor-blocked" | "mayor-idle-no-work" | "max-iterations-reached" | "max-wall-time-reached" | "pi-exit-nonzero" | "high-interrupt-rate";
|
|
150
151
|
interface LoopOptions {
|
|
151
152
|
runOptions: RunOptions;
|
|
152
153
|
maxIterations?: number;
|
|
153
154
|
maxWallTimeMs?: number;
|
|
154
155
|
stopOnPiFailure?: boolean;
|
|
156
|
+
stopOnMayorIdleNoWork?: boolean;
|
|
155
157
|
interruptRateThreshold?: number | null;
|
|
156
158
|
onIterationComplete?: (iteration: LoopIterationResult) => void;
|
|
157
159
|
}
|
|
@@ -167,7 +169,7 @@ interface BoardSnapshot {
|
|
|
167
169
|
}>;
|
|
168
170
|
allTasksCompleted: boolean;
|
|
169
171
|
allRemainingTasksBlocked: boolean;
|
|
170
|
-
|
|
172
|
+
mayorBlocked: boolean;
|
|
171
173
|
hasQueuedOrRunningWork: boolean;
|
|
172
174
|
}
|
|
173
175
|
interface LoopIterationResult {
|
|
@@ -197,7 +199,7 @@ declare function getAgentSessionPath(artifactsDir: string, agentId: string): str
|
|
|
197
199
|
declare function getAgentMailboxPath(artifactsDir: string, agentId: string, box: AgentMailbox): string;
|
|
198
200
|
declare function getAgentSessionsDir(artifactsDir: string, agentId: string): string;
|
|
199
201
|
declare function getSessionIdFromPath(sessionPath: string | null | undefined): string | null;
|
|
200
|
-
declare function createAgentSessionRecord(input?: Partial<Pick<AgentSessionRecord, "sessionDir" | "sessionId" | "sessionPath" | "lastAttachedAt">>): AgentSessionRecord;
|
|
202
|
+
declare function createAgentSessionRecord(input?: Partial<Pick<AgentSessionRecord, "sessionDir" | "sessionId" | "sessionPath" | "processId" | "lastAttachedAt">>): AgentSessionRecord;
|
|
201
203
|
declare function createAgentState(input: {
|
|
202
204
|
agentId: string;
|
|
203
205
|
role: string;
|
|
@@ -259,6 +261,7 @@ declare function evaluateStopCondition(input: {
|
|
|
259
261
|
maxWallTimeMs: number;
|
|
260
262
|
piExitCode: number;
|
|
261
263
|
stopOnPiFailure: boolean;
|
|
264
|
+
stopOnMayorIdleNoWork: boolean;
|
|
262
265
|
board: BoardSnapshot;
|
|
263
266
|
metrics: MetricsSnapshot;
|
|
264
267
|
interruptRateThreshold: number | null;
|
|
@@ -287,37 +290,31 @@ interface SpawnAgentRunOptions {
|
|
|
287
290
|
role: string;
|
|
288
291
|
agentId: string;
|
|
289
292
|
task: string | null;
|
|
290
|
-
appendedSystemPrompt?: string | null;
|
|
291
|
-
extensionPath?: string | null;
|
|
292
|
-
taskId?: string | null;
|
|
293
|
+
appendedSystemPrompt?: string | null | undefined;
|
|
294
|
+
extensionPath?: string | null | undefined;
|
|
295
|
+
taskId?: string | null | undefined;
|
|
293
296
|
}
|
|
294
297
|
interface SpawnAgentRunResult {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
exitCode: number;
|
|
298
|
+
launch: {
|
|
299
|
+
processId: number;
|
|
300
|
+
startedAt: string;
|
|
299
301
|
};
|
|
300
302
|
latestSession: AgentSessionRecord;
|
|
301
|
-
completionMessage: string;
|
|
302
303
|
}
|
|
303
304
|
interface DelegateTaskOptions {
|
|
304
305
|
repoRoot: string;
|
|
305
306
|
artifactsDir: string;
|
|
306
307
|
fromAgentId: string;
|
|
307
308
|
role: string;
|
|
308
|
-
agentId?: string | null;
|
|
309
|
-
appendedSystemPrompt?: string | null;
|
|
310
|
-
extensionPath?: string | null;
|
|
309
|
+
agentId?: string | null | undefined;
|
|
310
|
+
appendedSystemPrompt?: string | null | undefined;
|
|
311
|
+
extensionPath?: string | null | undefined;
|
|
311
312
|
task: string;
|
|
312
313
|
}
|
|
313
314
|
interface DelegateTaskResult {
|
|
314
315
|
task: TaskRecord;
|
|
315
316
|
agentId: string;
|
|
316
|
-
|
|
317
|
-
stdout: string;
|
|
318
|
-
stderr: string;
|
|
319
|
-
exitCode: number;
|
|
320
|
-
};
|
|
317
|
+
launch: SpawnAgentRunResult["launch"];
|
|
321
318
|
latestSession: AgentSessionRecord;
|
|
322
319
|
}
|
|
323
320
|
interface ResolvedAgentSession {
|
|
@@ -356,7 +353,7 @@ declare function queueAgentMessage(input: {
|
|
|
356
353
|
declare function updateAgentStatus(input: {
|
|
357
354
|
artifactsDir: string;
|
|
358
355
|
agentId: string;
|
|
359
|
-
status: "queued" | "running" | "idle" | "blocked" | "completed" | "failed";
|
|
356
|
+
status: "queued" | "running" | "idle" | "blocked" | "completed" | "failed" | "stopped";
|
|
360
357
|
lastMessage?: string | null;
|
|
361
358
|
waitingOn?: string | null;
|
|
362
359
|
blocked?: boolean;
|
|
@@ -393,6 +390,62 @@ declare function runCommandInteractive(command: string, args: string[], options?
|
|
|
393
390
|
}): number;
|
|
394
391
|
declare function assertSuccess(result: CommandResult, context: string): void;
|
|
395
392
|
//#endregion
|
|
393
|
+
//#region src/stop.d.ts
|
|
394
|
+
interface LeaseData {
|
|
395
|
+
runId: string;
|
|
396
|
+
repoId: string;
|
|
397
|
+
branch: string;
|
|
398
|
+
pid: number;
|
|
399
|
+
hostname: string;
|
|
400
|
+
startedAt: string;
|
|
401
|
+
}
|
|
402
|
+
interface StopManagedAgentsOptions {
|
|
403
|
+
artifactsDir: string;
|
|
404
|
+
agentId?: string | null;
|
|
405
|
+
excludeAgentIds?: string[];
|
|
406
|
+
actorId?: string | null;
|
|
407
|
+
reason?: string | null;
|
|
408
|
+
force?: boolean;
|
|
409
|
+
graceMs?: number;
|
|
410
|
+
}
|
|
411
|
+
interface StopAgentResult {
|
|
412
|
+
agentId: string;
|
|
413
|
+
previousStatus: AgentStateSnapshot["status"];
|
|
414
|
+
nextStatus: AgentStateSnapshot["status"];
|
|
415
|
+
processId: number | null;
|
|
416
|
+
signal: "SIGTERM" | "SIGKILL" | null;
|
|
417
|
+
exited: boolean;
|
|
418
|
+
}
|
|
419
|
+
interface StopManagedAgentsResult {
|
|
420
|
+
results: StopAgentResult[];
|
|
421
|
+
stoppedAgents: number;
|
|
422
|
+
signaledProcesses: number;
|
|
423
|
+
}
|
|
424
|
+
interface RepoLeaseRecord extends LeaseData {
|
|
425
|
+
path: string;
|
|
426
|
+
}
|
|
427
|
+
interface StopRepoLeasesOptions {
|
|
428
|
+
repoId?: string | null;
|
|
429
|
+
force?: boolean;
|
|
430
|
+
graceMs?: number;
|
|
431
|
+
}
|
|
432
|
+
interface StopRepoLeaseResult {
|
|
433
|
+
path: string;
|
|
434
|
+
runId: string;
|
|
435
|
+
repoId: string;
|
|
436
|
+
branch: string;
|
|
437
|
+
processId: number;
|
|
438
|
+
signal: "SIGTERM" | "SIGKILL" | null;
|
|
439
|
+
exited: boolean;
|
|
440
|
+
}
|
|
441
|
+
interface StopRepoLeasesResult {
|
|
442
|
+
results: StopRepoLeaseResult[];
|
|
443
|
+
signaledProcesses: number;
|
|
444
|
+
}
|
|
445
|
+
declare function listRepoLeases(repoId?: string | null): RepoLeaseRecord[];
|
|
446
|
+
declare function stopRepoLeases(options: StopRepoLeasesOptions): StopRepoLeasesResult;
|
|
447
|
+
declare function stopManagedAgents(options: StopManagedAgentsOptions): StopManagedAgentsResult;
|
|
448
|
+
//#endregion
|
|
396
449
|
//#region src/tasks.d.ts
|
|
397
450
|
declare function getTasksDir(artifactsDir: string): string;
|
|
398
451
|
declare function getTaskPath(artifactsDir: string, taskId: string): string;
|
|
@@ -409,5 +462,5 @@ declare function updateTaskRecordStatus(artifactsDir: string, taskId: string, st
|
|
|
409
462
|
declare function readTaskRecord(artifactsDir: string, taskId: string): TaskRecord | null;
|
|
410
463
|
declare function listTaskRecords(artifactsDir: string): TaskRecord[];
|
|
411
464
|
//#endregion
|
|
412
|
-
export { AgentMailbox, AgentMessageRecord, AgentSessionRecord, AgentStateSnapshot, AgentStatus, BoardSnapshot, CommandResult, ControllerRunResult, CreateInterruptInput, DelegateTaskOptions, DelegateTaskResult, FeedbackCycle, FixType, InterruptCategory, InterruptRecord, LoopIterationResult, LoopOptions, LoopRunResult, LoopStopReason, MetricsSnapshot, PiInvocationRecord, ResolvedAgentSession, RunAgentTurnOptions, RunAgentTurnResult, RunManifest, RunMode, RunOptions, RunSummary, SpawnAgentRunOptions, SpawnAgentRunResult, 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, listTaskRecords, queueAgentMessage, readAgentMessages, readAgentState, readJsonl, readTaskRecord, resolveAgentSession, resolveInterrupt, runAgentTurn, runCommandInteractive, runCommandSync, runController, runLoop, snapshotBoard, spawnAgentRun, updateAgentStatus, updateTaskRecordStatus, writeAgentState, writeTaskRecord };
|
|
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 };
|
|
413
466
|
//# sourceMappingURL=index.d.mts.map
|