@schilderlabs/pitown-core 0.1.1 → 0.2.1
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/index.d.mts +251 -1
- package/dist/index.mjs +795 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,47 @@
|
|
|
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";
|
|
6
|
+
type AgentMailbox = "inbox" | "outbox";
|
|
7
|
+
type TaskStatus = "queued" | "running" | "blocked" | "completed";
|
|
8
|
+
interface AgentSessionRecord {
|
|
9
|
+
runtime: "pi";
|
|
10
|
+
persisted: boolean;
|
|
11
|
+
sessionDir: string | null;
|
|
12
|
+
sessionId: string | null;
|
|
13
|
+
sessionPath: string | null;
|
|
14
|
+
lastAttachedAt: string | null;
|
|
15
|
+
}
|
|
16
|
+
interface AgentStateSnapshot {
|
|
17
|
+
agentId: string;
|
|
18
|
+
role: string;
|
|
19
|
+
status: AgentStatus;
|
|
20
|
+
taskId: string | null;
|
|
21
|
+
task: string | null;
|
|
22
|
+
branch: string | null;
|
|
23
|
+
updatedAt: string;
|
|
24
|
+
lastMessage: string | null;
|
|
25
|
+
waitingOn: string | null;
|
|
26
|
+
blocked: boolean;
|
|
27
|
+
runId: string | null;
|
|
28
|
+
session: AgentSessionRecord;
|
|
29
|
+
}
|
|
30
|
+
interface AgentMessageRecord {
|
|
31
|
+
box: AgentMailbox;
|
|
32
|
+
from: string;
|
|
33
|
+
body: string;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
}
|
|
36
|
+
interface TaskRecord {
|
|
37
|
+
taskId: string;
|
|
38
|
+
title: string;
|
|
39
|
+
status: TaskStatus;
|
|
40
|
+
role: string;
|
|
41
|
+
assignedAgentId: string;
|
|
42
|
+
createdBy: string;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
updatedAt: string;
|
|
45
|
+
}
|
|
5
46
|
interface InterruptRecord {
|
|
6
47
|
id: string;
|
|
7
48
|
runId: string;
|
|
@@ -47,6 +88,8 @@ interface RunOptions {
|
|
|
47
88
|
mode?: RunMode;
|
|
48
89
|
planPath?: string | null;
|
|
49
90
|
recommendedPlanDir?: string | null;
|
|
91
|
+
appendedSystemPrompt?: string | null;
|
|
92
|
+
extensionPath?: string | null;
|
|
50
93
|
piCommand?: string;
|
|
51
94
|
}
|
|
52
95
|
interface RunManifest {
|
|
@@ -75,6 +118,9 @@ interface PiInvocationRecord {
|
|
|
75
118
|
repoRoot: string;
|
|
76
119
|
planPath: string | null;
|
|
77
120
|
goal: string | null;
|
|
121
|
+
sessionDir: string | null;
|
|
122
|
+
sessionId: string | null;
|
|
123
|
+
sessionPath: string | null;
|
|
78
124
|
startedAt: string;
|
|
79
125
|
endedAt: string;
|
|
80
126
|
exitCode: number;
|
|
@@ -100,6 +146,83 @@ interface ControllerRunResult {
|
|
|
100
146
|
summary: RunSummary;
|
|
101
147
|
piInvocation: PiInvocationRecord;
|
|
102
148
|
}
|
|
149
|
+
type LoopStopReason = "all-tasks-completed" | "all-remaining-tasks-blocked" | "leader-blocked" | "max-iterations-reached" | "max-wall-time-reached" | "pi-exit-nonzero" | "high-interrupt-rate";
|
|
150
|
+
interface LoopOptions {
|
|
151
|
+
runOptions: RunOptions;
|
|
152
|
+
maxIterations?: number;
|
|
153
|
+
maxWallTimeMs?: number;
|
|
154
|
+
stopOnPiFailure?: boolean;
|
|
155
|
+
interruptRateThreshold?: number | null;
|
|
156
|
+
onIterationComplete?: (iteration: LoopIterationResult) => void;
|
|
157
|
+
}
|
|
158
|
+
interface BoardSnapshot {
|
|
159
|
+
tasks: Array<{
|
|
160
|
+
taskId: string;
|
|
161
|
+
status: TaskStatus;
|
|
162
|
+
}>;
|
|
163
|
+
agents: Array<{
|
|
164
|
+
agentId: string;
|
|
165
|
+
status: AgentStatus;
|
|
166
|
+
blocked: boolean;
|
|
167
|
+
}>;
|
|
168
|
+
allTasksCompleted: boolean;
|
|
169
|
+
allRemainingTasksBlocked: boolean;
|
|
170
|
+
leaderBlocked: boolean;
|
|
171
|
+
hasQueuedOrRunningWork: boolean;
|
|
172
|
+
}
|
|
173
|
+
interface LoopIterationResult {
|
|
174
|
+
iteration: number;
|
|
175
|
+
controllerResult: ControllerRunResult;
|
|
176
|
+
boardSnapshot: BoardSnapshot;
|
|
177
|
+
metrics: MetricsSnapshot;
|
|
178
|
+
elapsedMs: number;
|
|
179
|
+
continueReason: string | null;
|
|
180
|
+
stopReason: LoopStopReason | null;
|
|
181
|
+
}
|
|
182
|
+
interface LoopRunResult {
|
|
183
|
+
loopId: string;
|
|
184
|
+
iterations: LoopIterationResult[];
|
|
185
|
+
stopReason: LoopStopReason;
|
|
186
|
+
totalIterations: number;
|
|
187
|
+
totalElapsedMs: number;
|
|
188
|
+
finalBoardSnapshot: BoardSnapshot;
|
|
189
|
+
aggregateMetrics: MetricsSnapshot;
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/agents.d.ts
|
|
193
|
+
declare function getAgentsDir(artifactsDir: string): string;
|
|
194
|
+
declare function getAgentDir(artifactsDir: string, agentId: string): string;
|
|
195
|
+
declare function getAgentStatePath(artifactsDir: string, agentId: string): string;
|
|
196
|
+
declare function getAgentSessionPath(artifactsDir: string, agentId: string): string;
|
|
197
|
+
declare function getAgentMailboxPath(artifactsDir: string, agentId: string, box: AgentMailbox): string;
|
|
198
|
+
declare function getAgentSessionsDir(artifactsDir: string, agentId: string): string;
|
|
199
|
+
declare function getSessionIdFromPath(sessionPath: string | null | undefined): string | null;
|
|
200
|
+
declare function createAgentSessionRecord(input?: Partial<Pick<AgentSessionRecord, "sessionDir" | "sessionId" | "sessionPath" | "lastAttachedAt">>): AgentSessionRecord;
|
|
201
|
+
declare function createAgentState(input: {
|
|
202
|
+
agentId: string;
|
|
203
|
+
role: string;
|
|
204
|
+
status: AgentStatus;
|
|
205
|
+
taskId?: string | null;
|
|
206
|
+
task?: string | null;
|
|
207
|
+
branch?: string | null;
|
|
208
|
+
lastMessage?: string | null;
|
|
209
|
+
waitingOn?: string | null;
|
|
210
|
+
blocked?: boolean;
|
|
211
|
+
runId?: string | null;
|
|
212
|
+
session?: AgentSessionRecord;
|
|
213
|
+
}): AgentStateSnapshot;
|
|
214
|
+
declare function writeAgentState(artifactsDir: string, state: AgentStateSnapshot): void;
|
|
215
|
+
declare function readAgentState(artifactsDir: string, agentId: string): AgentStateSnapshot | null;
|
|
216
|
+
declare function listAgentStates(artifactsDir: string): AgentStateSnapshot[];
|
|
217
|
+
declare function appendAgentMessage(input: {
|
|
218
|
+
artifactsDir: string;
|
|
219
|
+
agentId: string;
|
|
220
|
+
box: AgentMailbox;
|
|
221
|
+
from: string;
|
|
222
|
+
body: string;
|
|
223
|
+
}): AgentMessageRecord;
|
|
224
|
+
declare function readAgentMessages(artifactsDir: string, agentId: string, box: AgentMailbox): AgentMessageRecord[];
|
|
225
|
+
declare function getLatestAgentSession(artifactsDir: string, agentId: string): AgentSessionRecord;
|
|
103
226
|
//#endregion
|
|
104
227
|
//#region src/controller.d.ts
|
|
105
228
|
declare function runController(options: RunOptions): ControllerRunResult;
|
|
@@ -127,6 +250,24 @@ declare function acquireRepoLease(runId: string, repoId: string, branch: string)
|
|
|
127
250
|
release: () => void;
|
|
128
251
|
};
|
|
129
252
|
//#endregion
|
|
253
|
+
//#region src/loop.d.ts
|
|
254
|
+
declare function snapshotBoard(artifactsDir: string): BoardSnapshot;
|
|
255
|
+
declare function evaluateStopCondition(input: {
|
|
256
|
+
iteration: number;
|
|
257
|
+
maxIterations: number;
|
|
258
|
+
elapsedMs: number;
|
|
259
|
+
maxWallTimeMs: number;
|
|
260
|
+
piExitCode: number;
|
|
261
|
+
stopOnPiFailure: boolean;
|
|
262
|
+
board: BoardSnapshot;
|
|
263
|
+
metrics: MetricsSnapshot;
|
|
264
|
+
interruptRateThreshold: number | null;
|
|
265
|
+
}): {
|
|
266
|
+
stopReason: LoopStopReason | null;
|
|
267
|
+
continueReason: string | null;
|
|
268
|
+
};
|
|
269
|
+
declare function runLoop(options: LoopOptions): LoopRunResult;
|
|
270
|
+
//#endregion
|
|
130
271
|
//#region src/metrics.d.ts
|
|
131
272
|
declare function computeInterruptRate(interrupts: InterruptRecord[], taskAttempts: TaskAttempt[]): number;
|
|
132
273
|
declare function computeAutonomousCompletionRate(taskAttempts: TaskAttempt[]): number;
|
|
@@ -139,6 +280,95 @@ declare function computeMetrics(input: {
|
|
|
139
280
|
feedbackCycles?: FeedbackCycle[];
|
|
140
281
|
}): MetricsSnapshot;
|
|
141
282
|
//#endregion
|
|
283
|
+
//#region src/orchestration.d.ts
|
|
284
|
+
interface SpawnAgentRunOptions {
|
|
285
|
+
repoRoot: string;
|
|
286
|
+
artifactsDir: string;
|
|
287
|
+
role: string;
|
|
288
|
+
agentId: string;
|
|
289
|
+
task: string | null;
|
|
290
|
+
appendedSystemPrompt?: string | null;
|
|
291
|
+
extensionPath?: string | null;
|
|
292
|
+
taskId?: string | null;
|
|
293
|
+
}
|
|
294
|
+
interface SpawnAgentRunResult {
|
|
295
|
+
piResult: {
|
|
296
|
+
stdout: string;
|
|
297
|
+
stderr: string;
|
|
298
|
+
exitCode: number;
|
|
299
|
+
};
|
|
300
|
+
latestSession: AgentSessionRecord;
|
|
301
|
+
completionMessage: string;
|
|
302
|
+
}
|
|
303
|
+
interface DelegateTaskOptions {
|
|
304
|
+
repoRoot: string;
|
|
305
|
+
artifactsDir: string;
|
|
306
|
+
fromAgentId: string;
|
|
307
|
+
role: string;
|
|
308
|
+
agentId?: string | null;
|
|
309
|
+
appendedSystemPrompt?: string | null;
|
|
310
|
+
extensionPath?: string | null;
|
|
311
|
+
task: string;
|
|
312
|
+
}
|
|
313
|
+
interface DelegateTaskResult {
|
|
314
|
+
task: TaskRecord;
|
|
315
|
+
agentId: string;
|
|
316
|
+
piResult: {
|
|
317
|
+
stdout: string;
|
|
318
|
+
stderr: string;
|
|
319
|
+
exitCode: number;
|
|
320
|
+
};
|
|
321
|
+
latestSession: AgentSessionRecord;
|
|
322
|
+
}
|
|
323
|
+
interface ResolvedAgentSession {
|
|
324
|
+
state: AgentStateSnapshot;
|
|
325
|
+
session: AgentSessionRecord;
|
|
326
|
+
}
|
|
327
|
+
interface RunAgentTurnOptions {
|
|
328
|
+
repoRoot: string;
|
|
329
|
+
artifactsDir: string;
|
|
330
|
+
agentId: string;
|
|
331
|
+
message: string;
|
|
332
|
+
from?: string;
|
|
333
|
+
runtimeArgs?: string[] | null;
|
|
334
|
+
}
|
|
335
|
+
interface RunAgentTurnResult {
|
|
336
|
+
piResult: {
|
|
337
|
+
stdout: string;
|
|
338
|
+
stderr: string;
|
|
339
|
+
exitCode: number;
|
|
340
|
+
};
|
|
341
|
+
latestSession: AgentSessionRecord;
|
|
342
|
+
completionMessage: string;
|
|
343
|
+
}
|
|
344
|
+
declare function createRolePrompt(input: {
|
|
345
|
+
role: string;
|
|
346
|
+
task: string | null;
|
|
347
|
+
repoRoot: string;
|
|
348
|
+
}): string;
|
|
349
|
+
declare function resolveAgentSession(agentId: string, artifactsDir: string): ResolvedAgentSession;
|
|
350
|
+
declare function queueAgentMessage(input: {
|
|
351
|
+
artifactsDir: string;
|
|
352
|
+
agentId: string;
|
|
353
|
+
from: string;
|
|
354
|
+
body: string;
|
|
355
|
+
}): void;
|
|
356
|
+
declare function updateAgentStatus(input: {
|
|
357
|
+
artifactsDir: string;
|
|
358
|
+
agentId: string;
|
|
359
|
+
status: "queued" | "running" | "idle" | "blocked" | "completed" | "failed";
|
|
360
|
+
lastMessage?: string | null;
|
|
361
|
+
waitingOn?: string | null;
|
|
362
|
+
blocked?: boolean;
|
|
363
|
+
}): void;
|
|
364
|
+
declare function spawnAgentRun(options: SpawnAgentRunOptions): SpawnAgentRunResult;
|
|
365
|
+
declare function runAgentTurn(options: RunAgentTurnOptions): RunAgentTurnResult;
|
|
366
|
+
declare function delegateTask(options: DelegateTaskOptions): DelegateTaskResult;
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/pi.d.ts
|
|
369
|
+
declare function detectPiAuthFailure(stderr: string, stdout: string): boolean;
|
|
370
|
+
declare function createPiAuthHelpMessage(): string;
|
|
371
|
+
//#endregion
|
|
142
372
|
//#region src/repo.d.ts
|
|
143
373
|
declare function isGitRepo(cwd: string): boolean;
|
|
144
374
|
declare function getRepoRoot(cwd: string): string;
|
|
@@ -157,7 +387,27 @@ declare function runCommandSync(command: string, args: string[], options?: {
|
|
|
157
387
|
env?: NodeJS.ProcessEnv;
|
|
158
388
|
}): CommandResult;
|
|
159
389
|
declare function assertCommandAvailable(command: string): void;
|
|
390
|
+
declare function runCommandInteractive(command: string, args: string[], options?: {
|
|
391
|
+
cwd?: string;
|
|
392
|
+
env?: NodeJS.ProcessEnv;
|
|
393
|
+
}): number;
|
|
160
394
|
declare function assertSuccess(result: CommandResult, context: string): void;
|
|
161
395
|
//#endregion
|
|
162
|
-
|
|
396
|
+
//#region src/tasks.d.ts
|
|
397
|
+
declare function getTasksDir(artifactsDir: string): string;
|
|
398
|
+
declare function getTaskPath(artifactsDir: string, taskId: string): string;
|
|
399
|
+
declare function createTaskRecord(input: {
|
|
400
|
+
taskId: string;
|
|
401
|
+
title: string;
|
|
402
|
+
status: TaskStatus;
|
|
403
|
+
role: string;
|
|
404
|
+
assignedAgentId: string;
|
|
405
|
+
createdBy: string;
|
|
406
|
+
}): TaskRecord;
|
|
407
|
+
declare function writeTaskRecord(artifactsDir: string, task: TaskRecord): void;
|
|
408
|
+
declare function updateTaskRecordStatus(artifactsDir: string, taskId: string, status: TaskStatus): TaskRecord | null;
|
|
409
|
+
declare function readTaskRecord(artifactsDir: string, taskId: string): TaskRecord | null;
|
|
410
|
+
declare function listTaskRecords(artifactsDir: string): TaskRecord[];
|
|
411
|
+
//#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 };
|
|
163
413
|
//# sourceMappingURL=index.d.mts.map
|