@maheidem/pi-delegate 0.1.5 → 0.2.0
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/README.md +86 -1
- package/application.ts +54 -4
- package/commands.ts +14 -2
- package/config.ts +26 -3
- package/handoff.ts +265 -0
- package/index.ts +109 -10
- package/package.json +68 -66
- package/roles/general.md +24 -18
- package/roles/research.md +9 -19
- package/rpc-jsonl.ts +10 -2
- package/runner.ts +436 -22
- package/types.ts +33 -0
- package/version.ts +28 -0
package/types.ts
CHANGED
|
@@ -21,6 +21,8 @@ export interface DelegateRole {
|
|
|
21
21
|
writeCapable: boolean;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
import type { HandoffSubmission } from "./handoff.ts";
|
|
25
|
+
|
|
24
26
|
// ── Errors ────────────────────────────────────────────────────────────────
|
|
25
27
|
|
|
26
28
|
export const DELEGATE_ERROR_CODES = [
|
|
@@ -37,6 +39,7 @@ export const DELEGATE_ERROR_CODES = [
|
|
|
37
39
|
"E_RPC_PROMPT_REJECTED",
|
|
38
40
|
"E_CHILD_EXIT",
|
|
39
41
|
"E_CHILD_MODEL",
|
|
42
|
+
"E_PROVIDER_ERROR",
|
|
40
43
|
"E_NO_HANDOFF",
|
|
41
44
|
"E_CANCELLED",
|
|
42
45
|
"E_TIMEOUT_IDLE",
|
|
@@ -105,6 +108,8 @@ export interface DelegateRequest {
|
|
|
105
108
|
cwd: string;
|
|
106
109
|
/** "provider/model-id" of the parent model. */
|
|
107
110
|
parentModel: string;
|
|
111
|
+
/** R5: explicit child model pin ("provider/model-id"); overrides inheritance. */
|
|
112
|
+
model?: string;
|
|
108
113
|
/** Parent thinking level, when available. */
|
|
109
114
|
thinkingLevel?: string;
|
|
110
115
|
projectTrusted: boolean;
|
|
@@ -112,6 +117,8 @@ export interface DelegateRequest {
|
|
|
112
117
|
timeoutMs?: number;
|
|
113
118
|
/** Project root for the project-wide config overlay (optional). */
|
|
114
119
|
projectRoot?: string;
|
|
120
|
+
/** R3: resume a prior run's child session (its session file is re-entered). */
|
|
121
|
+
resumeFrom?: string;
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
/** Bounded, parent-visible tool result details (schema v1). */
|
|
@@ -130,6 +137,12 @@ export interface DelegateDetails {
|
|
|
130
137
|
usage: DelegateUsage;
|
|
131
138
|
outputBytes: number;
|
|
132
139
|
outputTruncated: boolean;
|
|
140
|
+
/** R2: partial handoff captured from a killed child (timeouts). */
|
|
141
|
+
partialHandoff?: string;
|
|
142
|
+
/** R3: the child's persisted session file, when session capture is on. */
|
|
143
|
+
sessionPath?: string;
|
|
144
|
+
/** R7: resolved timeout provenance, e.g. "hard 45m (per-run) · idle 22m30s". */
|
|
145
|
+
timeoutInfo?: string;
|
|
133
146
|
transcriptPath: string;
|
|
134
147
|
stderrPath: string;
|
|
135
148
|
displayItems: DelegateDisplayItem[];
|
|
@@ -144,6 +157,8 @@ export interface DelegateRunResult {
|
|
|
144
157
|
/** Bounded final handoff for the parent context ("" on failure). */
|
|
145
158
|
handoff: string;
|
|
146
159
|
details: DelegateDetails;
|
|
160
|
+
/** R5/R7: provenance notes (model pin, partial-handoff availability). */
|
|
161
|
+
modelNote?: string;
|
|
147
162
|
error?: DelegateError;
|
|
148
163
|
}
|
|
149
164
|
|
|
@@ -152,6 +167,8 @@ export interface RunnerOutcome {
|
|
|
152
167
|
runId: string;
|
|
153
168
|
state: RunTerminalState;
|
|
154
169
|
handoff: string;
|
|
170
|
+
/** R2: bounded partial handoff captured at timeout kill. */
|
|
171
|
+
partialHandoff?: string;
|
|
155
172
|
outputBytes: number;
|
|
156
173
|
outputTruncated: boolean;
|
|
157
174
|
startedAt: string;
|
|
@@ -193,6 +210,20 @@ export interface RunMetadataV1 {
|
|
|
193
210
|
outputBytes?: number;
|
|
194
211
|
outputTruncated?: boolean;
|
|
195
212
|
finalHandoff?: string;
|
|
213
|
+
/** R2: partial handoff captured from a killed child (timeouts). */
|
|
214
|
+
partialHandoff?: string;
|
|
215
|
+
/** Structured handoff submitted through the child's handoff tool. */
|
|
216
|
+
handoffData?: HandoffSubmission;
|
|
217
|
+
/** R3: the child's persisted session file (durable resume anchor). */
|
|
218
|
+
sessionPath?: string;
|
|
219
|
+
/** R3: prior run whose child session this run resumed. */
|
|
220
|
+
resumeOf?: string;
|
|
221
|
+
/** R6: git HEAD at run start ("<sha>" when the cwd is a git worktree). */
|
|
222
|
+
gitBase?: string;
|
|
223
|
+
/** R6: bounded `git status --porcelain` at run start. */
|
|
224
|
+
gitStatus?: string;
|
|
225
|
+
/** R6: bounded post-run `git diff --stat` (worktree vs. run start). */
|
|
226
|
+
gitDelta?: string;
|
|
196
227
|
transcriptPath: string;
|
|
197
228
|
stderrPath: string;
|
|
198
229
|
/** Present only on manually curated receipts (one-time data repair). */
|
|
@@ -342,6 +373,8 @@ export interface RunStreamUpdate {
|
|
|
342
373
|
runId: string;
|
|
343
374
|
role: RoleName;
|
|
344
375
|
phase: "starting" | "running" | `tool:${string}` | "finalizing";
|
|
376
|
+
/** R5: the resolved child model, echoed in live updates. */
|
|
377
|
+
model?: string;
|
|
345
378
|
elapsedMs: number;
|
|
346
379
|
lastActions: string[];
|
|
347
380
|
usage: DelegateUsage;
|
package/version.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* delegate — loaded-version provenance (R7).
|
|
3
|
+
*
|
|
4
|
+
* A running Pi session keeps whatever extension code it loaded at startup;
|
|
5
|
+
* newer npm-store installs only apply after /reload. Every result header
|
|
6
|
+
* and /delegate status therefore carries the version actually executing,
|
|
7
|
+
* so "stale copy in this process" is self-evident instead of mysterious.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as fs from "node:fs";
|
|
11
|
+
import * as path from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
let cached: string | null = null;
|
|
15
|
+
|
|
16
|
+
export function delegateVersion(): string {
|
|
17
|
+
if (cached) return cached;
|
|
18
|
+
try {
|
|
19
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(here, "package.json"), "utf8")) as {
|
|
21
|
+
version?: string;
|
|
22
|
+
};
|
|
23
|
+
cached = pkg.version ?? "unknown";
|
|
24
|
+
} catch {
|
|
25
|
+
cached = "unknown";
|
|
26
|
+
}
|
|
27
|
+
return cached;
|
|
28
|
+
}
|