@maheidem/pi-delegate 0.8.0 → 0.10.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/CHANGELOG.md +17 -0
- package/README.md +83 -0
- package/extensions/application.ts +68 -17
- package/extensions/ask.ts +50 -0
- package/extensions/config.ts +206 -25
- package/extensions/index.ts +175 -44
- package/extensions/rpc-jsonl.ts +25 -0
- package/extensions/run-store.ts +32 -8
- package/extensions/runner.ts +103 -28
- package/extensions/types.ts +55 -0
- package/extensions/ui/event-card.ts +96 -0
- package/extensions/ui/peek-view.ts +24 -2
- package/extensions/ui/running-view.ts +119 -16
- package/package.json +1 -1
- package/roles/general.md +5 -0
- package/roles/research.md +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.10.0]
|
|
4
|
+
|
|
5
|
+
- Standard project context for children: default child args no longer pass `--no-skills`/`--no-prompt-templates`/`--no-themes` (only `child.context: "minimal"` re-disables them). Children now see the same skills, prompt templates and themes as the main session.
|
|
6
|
+
- Project-level child config: `.pi/delegate/config.json` accepts a validated `child` object (`model`, `thinking`, `tools`, `trustProject`, `context`). Resolution is per-invocation > project > parent. The resolved config is persisted in the receipt (`childConfig`) and shown in `/delegate doctor`/`inspect`/`status`.
|
|
7
|
+
- Interactive TUI for every running child (foreground + background): the foreground panel accepts follow-up messages (enter), cancel (x / esc x2) and shows the child's live provider/model/effort from a cached `get_state` RPC response (fallback to the pinned display, labeled).
|
|
8
|
+
- Better parent guidance: foreground-vs-background decision table in the tool description and promptGuidelines, README, and role prompts.
|
|
9
|
+
- Every middle-of-run informational message (delegate question/note/handoff, background progress/result) renders through a shared event-card component instead of bare text.
|
|
10
|
+
|
|
11
|
+
## [0.9.0]
|
|
12
|
+
|
|
13
|
+
- Security: strict `toolCallId` allowlist in `ask.ts` (read + write paths) — path traversal refused, fails closed.
|
|
14
|
+
- Security: strict env allowlist for child spawns (`buildChildEnv`) — parent environment (secrets) no longer inherited.
|
|
15
|
+
- Correctness: removed `.unref()` from safety timers in `runner.ts` (hard/inactivity/handoff grace/enforce/kill escalation/handoff settle); only the periodic progress heartbeat stays unref'd. Header contract updated.
|
|
16
|
+
- Robustness: `run-store.ts` silent catches now emit a debug-gated diagnostic (never throws).
|
|
17
|
+
- Robustness: nested `progressReports` and `askParent` config validated field-by-field with diagnostics; `PI_DELEGATE_ASK_DIR` validated (absolute, stays inside agent dir, created 0700) and timeout/max clamped.
|
|
18
|
+
- Housekeeping: removed stray root `dbg3.mts`; README security notes; AGENTS.md stale line ref fixed.
|
|
19
|
+
|
|
3
20
|
## [0.8.0]
|
|
4
21
|
|
|
5
22
|
- Move the runtime code to `extensions/`. The pi entry is `./extensions/index.ts`.
|
package/README.md
CHANGED
|
@@ -43,6 +43,28 @@ To try a local checkout without an install, run `pi -e ./extensions/index.ts` in
|
|
|
43
43
|
|
|
44
44
|
Any unrecognized first word is shorthand for `run general …`.
|
|
45
45
|
|
|
46
|
+
### Picking the execution mode (foreground vs background)
|
|
47
|
+
|
|
48
|
+
Both modes delegate the same task to the same child; the difference is only
|
|
49
|
+
how you get the result back:
|
|
50
|
+
|
|
51
|
+
- **Foreground** (`background: false`, `/delegate fg …`) — the call blocks
|
|
52
|
+
this turn until the child finishes, and the live panel accepts follow-up
|
|
53
|
+
messages (enter → steer the child; x → arm cancel). Use it when the very
|
|
54
|
+
next step depends on the result, or you want to nudge the child
|
|
55
|
+
interactively.
|
|
56
|
+
- **Background** (`background: true`, the default for the `delegate` tool
|
|
57
|
+
and `/delegate bg …`) — the call returns a runId immediately and the
|
|
58
|
+
terminal report arrives later as a message. Use it for independent
|
|
59
|
+
parallel work, long-running exploration, or work that finishes after you
|
|
60
|
+
continue.
|
|
61
|
+
|
|
62
|
+
Always pass `description` (3–6 words) for every delegation, foreground
|
|
63
|
+
included. Use `delegate_send` to correct or redirect a **live** run — never
|
|
64
|
+
`resumeFrom` for corrections; reserve `resumeFrom` for finished runs whose
|
|
65
|
+
work you want to continue in the same session. When in doubt, choose
|
|
66
|
+
background.
|
|
67
|
+
|
|
46
68
|
### Terminal UI (v0.3.0)
|
|
47
69
|
|
|
48
70
|
One centralized experience built on the `SettingsPanel` of
|
|
@@ -280,6 +302,43 @@ never free text we hope has the right shape:
|
|
|
280
302
|
apply after `/reload` in that session — the version line makes a stale
|
|
281
303
|
copy self-evident instead of indistinguishable from a regression.
|
|
282
304
|
|
|
305
|
+
### Project-wide child config (v0.9.0)
|
|
306
|
+
|
|
307
|
+
A project file `<project>/.pi/delegate/config.json` may also pin **how the
|
|
308
|
+
child is launched** — the `child` object (all keys optional):
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
{
|
|
312
|
+
"child": {
|
|
313
|
+
"model": "proj/model-id",
|
|
314
|
+
"thinking": "high",
|
|
315
|
+
"tools": ["read", "grep", "bash"],
|
|
316
|
+
"trustProject": false,
|
|
317
|
+
"context": "standard"
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Resolution order — **per-invocation > project > parent**:
|
|
323
|
+
|
|
324
|
+
- the `delegate` tool's `model` / `thinking` parameters beat everything;
|
|
325
|
+
- the project `child` block otherwise overrides the parent's current model
|
|
326
|
+
and thinking level;
|
|
327
|
+
- `tools` replaces the role's closed ceiling (the child still always gets
|
|
328
|
+
`handoff`, and `ask_parent` when the background ask channel is enabled);
|
|
329
|
+
names the parent session does not register are dropped with a diagnostic,
|
|
330
|
+
never silently enabled;
|
|
331
|
+
- `context: "minimal"` passes `--no-skills --no-prompt-templates --no-themes`
|
|
332
|
+
to the child; **the default is standard** (project skills, prompt
|
|
333
|
+
templates and themes are kept);
|
|
334
|
+
- `trustProject` overrides the parent session's approval state for the child.
|
|
335
|
+
|
|
336
|
+
The `child` block is **project-only**: the user config never carries it
|
|
337
|
+
(an attempt to put it there is diagnosed as an unknown, ignored key). A
|
|
338
|
+
corrupt project file never breaks a delegation — the user config wins and
|
|
339
|
+
corruption is diagnosed. Tool details and `/delegate doctor` show the
|
|
340
|
+
resolved shape (model source, thinking, tools, context, trust).
|
|
341
|
+
|
|
283
342
|
## Configuration
|
|
284
343
|
|
|
285
344
|
- The user config file is `<agent dir>/delegate/config.json`. The agent dir comes from `getAgentDir()` (normally `~/.pi/agent`). The code exports the path as `CONFIG_PATH` from `extensions/config.ts`.
|
|
@@ -322,6 +381,30 @@ never free text we hope has the right shape:
|
|
|
322
381
|
- Research requires a Firecrawl-capable tool path in the parent session;
|
|
323
382
|
Reddit is supplementary.
|
|
324
383
|
|
|
384
|
+
## Security notes
|
|
385
|
+
|
|
386
|
+
- **Env allowlist for children.** The child process inherits only `PATH`,
|
|
387
|
+
`HOME`, `TMPDIR`, `LANG`/`LC_*`, `TERM`, `USER`, `XDG_*` plus the
|
|
388
|
+
`PI_DELEGATE_*` contract vars (`PI_DELEGATE_CHILD`, `PI_DELEGATE_RUN_ID`,
|
|
389
|
+
`PI_DELEGATE_PARENT_PID`, and the ask-channel vars for background runs).
|
|
390
|
+
Everything else — API keys, tokens, cloud credentials — is dropped. A
|
|
391
|
+
missing `PATH` falls back to a minimal default.
|
|
392
|
+
- **Ask-id validation.** The `ask_parent` tool reads and writes
|
|
393
|
+
`<askDir>/<toolCallId>.json`. The id is validated against a strict
|
|
394
|
+
allowlist (`^[A-Za-z0-9._-]{1,128}$`, no `/`, no `..`); anything else
|
|
395
|
+
fails closed (the read returns null, the write throws). `PI_DELEGATE_ASK_DIR`
|
|
396
|
+
itself is resolved to an absolute path at registration (relative paths are
|
|
397
|
+
resolved against the agent dir and must stay inside it) and created with
|
|
398
|
+
mode `0700`; junk values disable the channel instead of breaking the run.
|
|
399
|
+
- **Timer contract.** Safety timers (hard, inactivity, handoffSettle,
|
|
400
|
+
killEscalate, handoffGrace, handoffEnforce) are NOT `unref()`'d — they
|
|
401
|
+
always get a chance to fire. The only unref'd timer is the periodic
|
|
402
|
+
progress heartbeat (background runs), which must never keep the process
|
|
403
|
+
alive on its own.
|
|
404
|
+
- The run store is `0700` / `0600` files; the child never inherits more
|
|
405
|
+
than the allowlist above. Failures in single-file store reads/writes are
|
|
406
|
+
logged (debug-gated via `PI_DELEGATE_DEBUG=1`) but never fail the run.
|
|
407
|
+
|
|
325
408
|
## Development
|
|
326
409
|
|
|
327
410
|
```bash
|
|
@@ -34,12 +34,14 @@ import type {
|
|
|
34
34
|
TranscriptRecordV1,
|
|
35
35
|
SessionEntryLike,
|
|
36
36
|
BackgroundRunHandle,
|
|
37
|
+
ChildLiveState,
|
|
38
|
+
ResolvedChildConfig,
|
|
37
39
|
RunState,
|
|
38
40
|
RunTerminalState,
|
|
39
41
|
} from "./types.ts";
|
|
40
42
|
import { FeedRing, type FeedEvent } from "./transcript-feed.ts";
|
|
41
43
|
import { decodeTranscriptRecord, isTerminalRunState } from "./types.ts";
|
|
42
|
-
import { applyProjectOverlay, clampConfigField, formatDuration, normalizeConfig, parseDuration, projectConfigPath, resolveRunTimeouts, saveConfig, saveProjectConfig, type DelegateConfigV1 } from "./config.ts";
|
|
44
|
+
import { applyProjectOverlay, clampConfigField, formatDuration, normalizeConfig, parseDuration, projectConfigPath, resolveChildConfig, resolveRunTimeouts, saveConfig, saveProjectConfig, type DelegateConfigV1 } from "./config.ts";
|
|
43
45
|
import { EMPTY_USAGE } from "./types.ts";
|
|
44
46
|
import { isRoleName, resolveRole, rolePromptExists, DELEGATE_ROLES } from "./roles.ts";
|
|
45
47
|
import type { DelegateRole } from "./types.ts";
|
|
@@ -261,6 +263,35 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
261
263
|
return { update: this.activeStream, events: this.activeRing.all(), queue: this.runQueue.length, hardMs: this.activeRun.hardMs };
|
|
262
264
|
}
|
|
263
265
|
|
|
266
|
+
/** Host/TUI hook: send get_state to the live child (best-effort, fire-and-forget). */
|
|
267
|
+
requestChildState(): void {
|
|
268
|
+
try {
|
|
269
|
+
this.activeRun?.runner.requestChildState();
|
|
270
|
+
} catch {
|
|
271
|
+
// best-effort
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** Host/TUI hook: cached live child state (get_state) of the active run. */
|
|
276
|
+
activeRunChildState(): ChildLiveState | undefined {
|
|
277
|
+
try {
|
|
278
|
+
return this.activeRun?.runner.getChildState();
|
|
279
|
+
} catch {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
activeRunId(): string | null {
|
|
285
|
+
return this.activeRun?.id ?? null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Host/TUI hook: steer the live child (follow-up message). */
|
|
289
|
+
steerActiveRun(message: string): { ok: true } | { ok: false; error: string } {
|
|
290
|
+
const runner = this.activeRun?.runner;
|
|
291
|
+
if (!runner) return { ok: false, error: "no active run to steer" };
|
|
292
|
+
return runner.steer(message);
|
|
293
|
+
}
|
|
294
|
+
|
|
264
295
|
/** Advanced knobs for the dashboard's Configure-advanced screen (§ S7). */
|
|
265
296
|
panelConfig(): Pick<DelegateConfigV1, "queueLimit" | "killGraceMs" | "handoffGraceMs" | "handoffEnforceTimeoutMs" | "stuckToolTimeoutMs" | "maxTaskBytes" | "maxResultBytes" | "updateThrottleMs" | "defaultRole" | "defaultExecution" | "maxRuns" | "maxRunAgeDays" | "progressReports"> {
|
|
266
297
|
const c = this.liveConfig;
|
|
@@ -335,7 +366,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
335
366
|
private async startRun(request: DelegateRequest, hooks: RunHooks = {}): Promise<RunAttemptResult> {
|
|
336
367
|
const prepared = this.prepareRun(request);
|
|
337
368
|
if ("error" in prepared) return prepared.error;
|
|
338
|
-
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir } = prepared;
|
|
369
|
+
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig } = prepared;
|
|
339
370
|
const agentDir = this.ports.agentDir;
|
|
340
371
|
|
|
341
372
|
// 8. Reservation NOW covers the child lifecycle.
|
|
@@ -360,11 +391,12 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
360
391
|
role,
|
|
361
392
|
task,
|
|
362
393
|
runId: opened.metadata.runId,
|
|
363
|
-
parentModel:
|
|
394
|
+
parentModel: request.parentModel ?? "",
|
|
364
395
|
thinkingLevel: request.thinkingLevel,
|
|
365
396
|
cwd: request.cwd,
|
|
366
397
|
projectTrusted: request.projectTrusted,
|
|
367
398
|
registeredTools: this.lastRegisteredTools,
|
|
399
|
+
childConfig,
|
|
368
400
|
...(resumeOf ? { resumeOf } : {}),
|
|
369
401
|
...(sessionPath ? { sessionPath } : {}),
|
|
370
402
|
...(sessionDir ? { sessionDir } : {}),
|
|
@@ -391,7 +423,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
391
423
|
} catch {
|
|
392
424
|
// cleanup failure is warning-only
|
|
393
425
|
}
|
|
394
|
-
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(request.description ? { description: request.description } : {}) });
|
|
426
|
+
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(request.description ? { description: request.description } : {}), ...(childConfig ? { childConfig } : {}) });
|
|
395
427
|
} catch (error) {
|
|
396
428
|
this.activeRun = null;
|
|
397
429
|
return errorResult(opened.metadata.runId, role.name, "E_CHILD_EXIT", `Delegation failed unexpectedly: ${(error as Error).message}`);
|
|
@@ -405,7 +437,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
405
437
|
runBackground(request: DelegateRequest, hooks: { onAsk?: RunHooks["onAsk"]; onProgress?: RunHooks["onProgress"] } = {}): { error: DelegateRunResult } | { handle: BackgroundRunHandle } {
|
|
406
438
|
const prepared = this.prepareRun(request);
|
|
407
439
|
if ("error" in prepared) return { error: prepared.error };
|
|
408
|
-
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir } = prepared;
|
|
440
|
+
const { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig } = prepared;
|
|
409
441
|
const agentDir = this.ports.agentDir;
|
|
410
442
|
// R17: ask channel plumbing — answers dir + budget env for the child.
|
|
411
443
|
const askEnabled = this.liveConfig.askParent?.enabled !== false;
|
|
@@ -422,11 +454,12 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
422
454
|
role,
|
|
423
455
|
task,
|
|
424
456
|
runId: opened.metadata.runId,
|
|
425
|
-
parentModel:
|
|
457
|
+
parentModel: request.parentModel ?? "",
|
|
426
458
|
thinkingLevel: request.thinkingLevel,
|
|
427
459
|
cwd: request.cwd,
|
|
428
460
|
projectTrusted: request.projectTrusted,
|
|
429
461
|
registeredTools: this.lastRegisteredTools,
|
|
462
|
+
childConfig,
|
|
430
463
|
...(resumeOf ? { resumeOf } : {}),
|
|
431
464
|
...(sessionPath ? { sessionPath } : {}),
|
|
432
465
|
...(sessionDir ? { sessionDir } : {}),
|
|
@@ -454,7 +487,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
454
487
|
} catch {
|
|
455
488
|
// cleanup failure is warning-only
|
|
456
489
|
}
|
|
457
|
-
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote });
|
|
490
|
+
return outcomeToRunResult(outcome, opened.metadata, role.name, model, request.thinkingLevel, { timeoutInfo, modelNote, ...(childConfig ? { childConfig } : {}) });
|
|
458
491
|
},
|
|
459
492
|
(error: unknown) => {
|
|
460
493
|
this.backgroundStreams.delete(opened.metadata.runId);
|
|
@@ -494,6 +527,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
494
527
|
resumeOf: string | undefined;
|
|
495
528
|
sessionPath: string | undefined;
|
|
496
529
|
sessionDir: string | undefined;
|
|
530
|
+
childConfig: ResolvedChildConfig;
|
|
497
531
|
} {
|
|
498
532
|
const agentDir = this.ports.agentDir;
|
|
499
533
|
// Config cascade: project .pi/delegate/config.json overlays the
|
|
@@ -504,10 +538,11 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
504
538
|
// Strip the overlay's diagnostic keys so only real config fields
|
|
505
539
|
// reach the runner (a spurious key would survive into metadata).
|
|
506
540
|
const overlay = applyProjectOverlay(this.liveConfig, request.projectRoot);
|
|
507
|
-
const { projectOverrides, projectSetKeys, projectCorrupt, ...rest } = overlay as unknown as DelegateConfigV1 & {
|
|
541
|
+
const { projectOverrides, projectSetKeys, projectCorrupt, projectDiagnostics: _pd, ...rest } = overlay as unknown as DelegateConfigV1 & {
|
|
508
542
|
projectOverrides: string[];
|
|
509
543
|
projectSetKeys: string[];
|
|
510
544
|
projectCorrupt?: string;
|
|
545
|
+
projectDiagnostics?: string[];
|
|
511
546
|
};
|
|
512
547
|
void projectSetKeys; // display-only; run resolution uses projectOverrides
|
|
513
548
|
projectSetsHard = projectOverrides.includes("hardTimeoutMs");
|
|
@@ -550,15 +585,29 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
550
585
|
return { error: errorResult("", role.name, "E_PROJECT_UNTRUSTED", "Project is not trusted; a write-capable child cannot run. Approve trust or use the research role.") };
|
|
551
586
|
}
|
|
552
587
|
|
|
553
|
-
// 5.
|
|
554
|
-
//
|
|
555
|
-
const
|
|
588
|
+
// 5. Child config resolution (R5, project-level child config):
|
|
589
|
+
// per-invocation (tool arg) > project overlay > parent's current.
|
|
590
|
+
const childConfig =
|
|
591
|
+
request.childConfig ??
|
|
592
|
+
resolveChildConfig({
|
|
593
|
+
perInvocation: request.model ? { model: request.model } : undefined,
|
|
594
|
+
projectRoot: request.projectRoot,
|
|
595
|
+
baseConfig: this.liveConfig,
|
|
596
|
+
parentModel: request.parentModel,
|
|
597
|
+
parentThinking: request.thinkingLevel,
|
|
598
|
+
registeredTools: this.lastRegisteredTools,
|
|
599
|
+
});
|
|
600
|
+
// 5b. Model resolution: the resolved child model wins; otherwise the
|
|
601
|
+
// parent's current model is inherited as before.
|
|
602
|
+
const model = childConfig.model?.trim() || "";
|
|
556
603
|
if (!model) {
|
|
557
604
|
return { error: errorResult("", role.name, "E_MODEL_UNAVAILABLE", "No parent model available to inherit. Select or configure a model, or pass an explicit child model.") };
|
|
558
605
|
}
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
|
|
606
|
+
const parentModel = request.parentModel?.trim() ?? "";
|
|
607
|
+
const modelNote =
|
|
608
|
+
model !== parentModel
|
|
609
|
+
? `child model pinned to ${model} (${childConfig.modelSource === "project" ? "project child config" : "tool arg"}; parent model ${parentModel || "none"} not inherited)`
|
|
610
|
+
: undefined;
|
|
562
611
|
|
|
563
612
|
// R3: resume — re-enter a prior run's durable child session.
|
|
564
613
|
let resumeOf: string | undefined;
|
|
@@ -583,7 +632,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
583
632
|
// 7. Open run store entry (atomic, 0700/0600).
|
|
584
633
|
let opened;
|
|
585
634
|
try {
|
|
586
|
-
opened = openRun(agentDir, { ...request, task, role: role.name });
|
|
635
|
+
opened = openRun(agentDir, { ...request, task, role: role.name, childConfig });
|
|
587
636
|
} catch (error) {
|
|
588
637
|
return { error: errorResult("", role.name, "E_STORE", `Run store could not initialize: ${(error as Error).message}`) };
|
|
589
638
|
}
|
|
@@ -599,7 +648,7 @@ export class DelegateApplicationImpl implements DelegateApplication {
|
|
|
599
648
|
}
|
|
600
649
|
}
|
|
601
650
|
|
|
602
|
-
return { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir };
|
|
651
|
+
return { opened, role, task, model, cfg, timeoutInfo, modelNote, resumeOf, sessionPath, sessionDir, childConfig };
|
|
603
652
|
}
|
|
604
653
|
|
|
605
654
|
/** Queued-call introspection for status views. */
|
|
@@ -956,7 +1005,7 @@ function outcomeToRunResult(
|
|
|
956
1005
|
role: RoleName,
|
|
957
1006
|
model: string,
|
|
958
1007
|
thinkingLevel?: string,
|
|
959
|
-
provenance?: { timeoutInfo?: string; modelNote?: string; description?: string },
|
|
1008
|
+
provenance?: { timeoutInfo?: string; modelNote?: string; description?: string; childConfig?: ResolvedChildConfig },
|
|
960
1009
|
): DelegateRunResult {
|
|
961
1010
|
const ok = outcome.state === "succeeded";
|
|
962
1011
|
const details: DelegateDetails = {
|
|
@@ -978,6 +1027,8 @@ function outcomeToRunResult(
|
|
|
978
1027
|
...(provenance?.timeoutInfo ? { timeoutInfo: provenance.timeoutInfo } : {}),
|
|
979
1028
|
// R22: foreground results return the validated description inline.
|
|
980
1029
|
...(provenance?.description ? { description: provenance.description } : {}),
|
|
1030
|
+
// Resolved child config (receipt copy) — inspectable in details.
|
|
1031
|
+
...(provenance?.childConfig ? { childConfig: provenance.childConfig } : {}),
|
|
981
1032
|
transcriptPath: outcome.transcriptPath,
|
|
982
1033
|
stderrPath: outcome.stderrPath,
|
|
983
1034
|
displayItems: outcome.displayItems,
|
package/extensions/ask.ts
CHANGED
|
@@ -67,6 +67,50 @@ export function validateAskSubmission(params: unknown): { ok: true; value: AskSu
|
|
|
67
67
|
return { ok: true, value: { kind: raw.kind as "question" | "note", topic, text } };
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Strict allowlist for a toolCallId used to build a filename. Anything else
|
|
72
|
+
* (slashes, `..`, leading dots, over-long, control chars) is rejected —
|
|
73
|
+
* fail closed so the id can never escape the ask dir.
|
|
74
|
+
*/
|
|
75
|
+
export function assertSafeAskId(id: string): string {
|
|
76
|
+
if (!/^[A-Za-z0-9._-]{1,128}$/.test(id) || id.includes("..") || /^\.+$/.test(id)) {
|
|
77
|
+
throw new Error("E_ASK: unsafe toolCallId");
|
|
78
|
+
}
|
|
79
|
+
return id;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Resolve and validate the ask_parent env contract for a child process.
|
|
84
|
+
* Returns null when the channel must not be registered (junk/empty askDir).
|
|
85
|
+
* Relative askDir resolves against the agent dir; a relative path that
|
|
86
|
+
* escapes it (e.g. ../) is rejected. Timeout/max are clamped to sane bounds.
|
|
87
|
+
*/
|
|
88
|
+
export function resolveAskEnv(
|
|
89
|
+
raw: { askDir?: string; timeoutMs?: string; maxQuestions?: string },
|
|
90
|
+
agentDir: string,
|
|
91
|
+
): { askDir: string; timeoutMs: number; maxQuestions: number } | null {
|
|
92
|
+
const rawDir = raw.askDir?.trim();
|
|
93
|
+
if (!rawDir || rawDir.includes("\0")) return null;
|
|
94
|
+
let askDir: string;
|
|
95
|
+
if (path.isAbsolute(rawDir)) {
|
|
96
|
+
askDir = path.normalize(rawDir);
|
|
97
|
+
} else {
|
|
98
|
+
const resolved = path.resolve(agentDir, rawDir);
|
|
99
|
+
const root = path.resolve(agentDir);
|
|
100
|
+
if (resolved !== root && !resolved.startsWith(root + path.sep)) return null;
|
|
101
|
+
askDir = resolved;
|
|
102
|
+
}
|
|
103
|
+
const timeoutRaw = Number(raw.timeoutMs);
|
|
104
|
+
const timeoutMs = Number.isFinite(timeoutRaw) && timeoutRaw > 0
|
|
105
|
+
? Math.min(3_600_000, Math.max(5_000, Math.trunc(timeoutRaw)))
|
|
106
|
+
: 600_000;
|
|
107
|
+
const maxRaw = Number(raw.maxQuestions);
|
|
108
|
+
const maxQuestions = Number.isFinite(maxRaw) && maxRaw > 0
|
|
109
|
+
? Math.min(20, Math.max(1, Math.trunc(maxRaw)))
|
|
110
|
+
: 5;
|
|
111
|
+
return { askDir, timeoutMs, maxQuestions };
|
|
112
|
+
}
|
|
113
|
+
|
|
70
114
|
export interface AskEnv {
|
|
71
115
|
askDir?: string;
|
|
72
116
|
timeoutMs: number;
|
|
@@ -100,6 +144,11 @@ export function registerAskParentTool(pi: ExtensionAPI, env: AskEnv): void {
|
|
|
100
144
|
const notesFiled = { count: 0 };
|
|
101
145
|
const sleep = env.sleep ?? ((ms: number) => new Promise<void>((r) => setTimeout(r, ms)));
|
|
102
146
|
const readAnswer = env.readAnswer ?? ((toolCallId: string) => {
|
|
147
|
+
try {
|
|
148
|
+
assertSafeAskId(toolCallId);
|
|
149
|
+
} catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
103
152
|
const file = path.join(env.askDir ?? "", `${toolCallId}.json`);
|
|
104
153
|
try {
|
|
105
154
|
const raw = JSON.parse(fs.readFileSync(file, "utf8")) as { answeredBy?: string; answer?: string };
|
|
@@ -186,6 +235,7 @@ export interface AskAnswerFile {
|
|
|
186
235
|
}
|
|
187
236
|
|
|
188
237
|
export function writeAskAnswerFile(askDir: string, toolCallId: string, payload: AskAnswerFile): void {
|
|
238
|
+
assertSafeAskId(toolCallId);
|
|
189
239
|
fs.mkdirSync(askDir, { recursive: true, mode: 0o700 });
|
|
190
240
|
fs.writeFileSync(path.join(askDir, `${toolCallId}.json`), JSON.stringify(payload), { mode: 0o600 });
|
|
191
241
|
}
|