@herbertgao/pi-extensions 2026.11.14 → 2026.11.15

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -4
  3. package/THIRD_PARTY_NOTICES.md +1 -1
  4. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +6 -0
  5. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +3 -2
  6. package/node_modules/@herbertgao/pi-cc-extensions/README.md +3 -2
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +5 -0
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +9 -0
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/index.ts +32 -2
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/markdown-enhance.ts +26 -21
  11. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/table-copy.ts +753 -0
  12. package/node_modules/@herbertgao/pi-cc-extensions/extensions/utils/fullscreen-detect.ts +11 -0
  13. package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
  14. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  15. package/node_modules/@herbertgao/pi-subagents/README.md +18 -16
  16. package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
  17. package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
  18. package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +18 -5
  19. package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +88 -0
  20. package/node_modules/@herbertgao/pi-subagents/src/index.ts +16 -92
  21. package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +6 -2
  22. package/node_modules/@herbertgao/pi-subagents/src/nested-tools.ts +18 -2
  23. package/node_modules/@herbertgao/pi-subagents/src/prompts.ts +25 -3
  24. package/node_modules/pi-commandcode-provider/CHANGELOG.md +20 -0
  25. package/node_modules/pi-commandcode-provider/README.md +1 -1
  26. package/node_modules/pi-commandcode-provider/index.ts +2 -1
  27. package/node_modules/pi-commandcode-provider/package.json +1 -1
  28. package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +9 -2
  29. package/node_modules/pi-commandcode-provider/src/pricing.ts +5 -1
  30. package/node_modules/pi-commandcode-provider/src/responses-compat.ts +24 -1
  31. package/node_modules/pi-commandcode-provider/src/responses-stream.ts +99 -6
  32. package/package.json +4 -4
@@ -13,6 +13,17 @@ export function isLazyProxyTui(tui: any): boolean {
13
13
  return typeof probe === "function" && probe !== tui.requestRender;
14
14
  }
15
15
 
16
+ /** The actual screen mode, independent of whether the host exposes a lazy Proxy. */
17
+ export function isFullscreenTui(tui: unknown): boolean {
18
+ if (tui === null || typeof tui !== "object") return false;
19
+ try {
20
+ return (tui as { mode?: unknown }).mode === "fullscreen";
21
+ } catch {
22
+ // A renderer-switching or disposed host reference is not an active screen.
23
+ return false;
24
+ }
25
+ }
26
+
16
27
  type MainScreenDoRenderPatch = {
17
28
  active: boolean;
18
29
  original: (lines: string[]) => string[];
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herbertgao/pi-cc-extensions",
3
- "version": "1.0.20-local.1",
3
+ "version": "1.0.21-local.1",
4
4
  "license": "MIT",
5
5
  "description": "A Pi productivity suite with Claude Code-style UI, context inspection, and agent/session references",
6
6
  "type": "module",
@@ -74,10 +74,10 @@
74
74
  },
75
75
  "x-upstream": {
76
76
  "package": "pi-cc-extensions",
77
- "version": "1.0.20",
78
- "reviewedVersion": "1.0.20",
77
+ "version": "1.0.21",
78
+ "reviewedVersion": "1.0.21",
79
79
  "repository": "https://github.com/minuque/pi-cc-extensions",
80
- "commit": "1c3a42614709c1b14a836b669359771c71939200",
80
+ "commit": "9a0ecdd29f9cecca9c34ae591b0de85896f2c07e",
81
81
  "trackVersion": true
82
82
  }
83
83
  }
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.26.1-local.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#392](https://github.com/HerbertGao/pi-extensions/pull/392) [`e233ef6`](https://github.com/HerbertGao/pi-extensions/commit/e233ef6cee8184ff322521eae67bfa2b57bf483d) Thanks [@HerbertGao](https://github.com/HerbertGao)! - Replay upstream pi-subagents 0.26.1. Reopening an agent keeps the model and thinking level from its session, and warns if Pi has to fall back. A mention clone shows the working directory once. The nested Agent tool lists the allowed agent types. A failed worktree cleanup and an unread result still stay recoverable.
8
+
3
9
  ## 0.26.0-local.1
4
10
 
5
11
  ### Minor Changes
@@ -228,7 +228,7 @@ Two things to weigh against `direct`: the clone re-sends the whole conversation,
228
228
 
229
229
  **Named agents.** The `Agent` tool takes an optional `name`, so the orchestrator can call one `auth-audit` instead of leaving you to tell `@explore-2` from `@explore-3`. A name is _additive_: the type-derived handle is still assigned, so `@explore` keeps reaching that agent rather than starting a second one beside it. Both names share one namespace — an alias can never shadow a live handle or the reverse — and the popup shows one row per agent, under its alias, with the type moved into the description. `steer_subagent` and `get_subagent_result` accept a handle too, so you and the model address agents the same way.
230
230
 
231
- **Resuming much later.** Because subagent sessions are persisted by default ([`rememberAgents`](#persistent-settings)), a handle keeps working after the agent's in-memory record is evicted: `@explore anything else?` reopens the conversation from disk. Only the _definition_ is re-resolved, so a continuation runs under the agent type's current frontmatter, not the one the first run used. If the type has since been deleted or disabled, the resume is refused rather than falling back to another agent — re-enable it and the handle works again. Names from an evicted agent stay reserved, so a later Explore becomes `explore-2` rather than shadowing something you can still reach; the 100 most recent are kept, and all of them are forgotten on `/new` and session switch. A resumed agent takes those names back, so `@explore` keeps meaning the same conversation. An agent whose session was only ever in memory leaves nothing to reopen, and the mention starts a fresh one instead; if the session file has since been deleted, the mention says so and frees the handle rather than silently sending your message to a new agent.
231
+ **Resuming much later.** Because subagent sessions are persisted by default ([`rememberAgents`](#persistent-settings)), a handle keeps working after the agent's in-memory record is evicted: `@explore anything else?` reopens the conversation from disk. Only the _definition_ is re-resolved, so a continuation runs under the agent type's current prompt and tools, not the ones the first run used. The model and thinking level are the ones the session recorded; if that model can no longer be used, pi falls back to its default and warns. If the type has since been deleted or disabled, the resume is refused rather than falling back to another agent — re-enable it and the handle works again. Names from an evicted agent stay reserved, so a later Explore becomes `explore-2` rather than shadowing something you can still reach; the 100 most recent are kept, and all of them are forgotten on `/new` and session switch. A resumed agent takes those names back, so `@explore` keeps meaning the same conversation. An agent whose session was only ever in memory leaves nothing to reopen, and the mention starts a fresh one instead; if the session file has since been deleted, the mention says so and frees the handle rather than silently sending your message to a new agent.
232
232
 
233
233
  The grammar mirrors Claude Code's, and is deliberately narrow so nothing gets swallowed by accident:
234
234
 
@@ -379,6 +379,8 @@ allowed_subagents: support-file-finder, support-callsite-tracer # or `all`
379
379
 
380
380
  **The allowlist is a privilege boundary, not just a routing hint.** A child runs with _its own_ `tools:`, `extensions:`, and `isolated:` — the parent's restrictions are not inherited — so delegation grants the parent the union of what the listed agents can do. The read-only agent above can write and run commands through any listed agent that can, and `all` reaches every enabled agent including `general-purpose`. Choose the list as carefully as you would choose `tools:` itself; that is the main reason this is default-off.
381
381
 
382
+ The nested `Agent` tool lists the allowed agent types with their descriptions and tools, as the main session's does, and follows [`toolDescriptionMode`](#persistent-settings) `"compact"`.
383
+
382
384
  `allowed_subagents` is runtime-enforced. A comma-separated list restricts nesting to those types; `all` (or `"*"` / `true`, matching how `extensions:` and `skills:` take booleans) allows any enabled agent; omitted, empty, `none`, or `false` means no nested tools are injected at all. Unknown, disabled, and out-of-list types are rejected rather than falling back — regardless of the project's [fallback agent](#persistent-settings) setting, so a configured fallback can never hand a nested caller an agent outside its allowlist — and a nested `model:` is validated against [Model Scope](#model-scope) exactly like a top-level spawn. Result, resume, and steering operations are ownership-scoped, so a parent can control only its own children. Nested records remain internal to that parent and do not appear in top-level tools, lifecycle events, or agent UI other than [FleetView](#fleetview) (which lists them under their parent with their own usage) and `/agents → Running agents` — so when a parent finishes, is stopped, or ends a resumed turn, its nested children are stopped with it. They do write their own `.output` transcript (subject to the same `output_transcript` gate), filed under the root session's directory alongside their ancestors', so a nested run can still be inspected after the fact. Their token usage is folded into every ancestor's totals up to the top-level agent (lifecycle events, completion notifications, `/agents`), so nested spend stays attributable at any depth on surfaces where the children themselves stay hidden. A nested result that ends `stopped`, `aborted`, or `steered` is labelled as partial, the same guarantee top-level results carry.
383
385
 
384
386
  `maxSubagentDepth` (default `2`) is the deepest level an agent may run at, counted from the main session (0). An agent can spawn only while its own depth is below it:
@@ -493,20 +495,20 @@ Four rules define the feature:
493
495
 
494
496
  Launch a sub-agent.
495
497
 
496
- | Parameter | Type | Required | Description |
497
- | ------------------- | ----------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
498
- | `prompt` | string | yes | The task for the agent |
499
- | `description` | string | yes | Short 3-5 word summary (shown in UI) |
500
- | `name` | string | no | Memorable name for this agent (`auth-audit`), addressable as `@name` and accepted by `steer_subagent`/`get_subagent_result`. Additive — the type-derived handle is still assigned |
501
- | `subagent_type` | string | yes | Agent type (built-in or custom) |
502
- | `model` | string | no | Model — `provider/modelId` or fuzzy name (`"haiku"`, `"sonnet"`). Resolved tolerantly (`.`/`-` and a trailing date stamp interchangeable) with provider fallback |
503
- | `thinking` | string | no | Thinking level: off, minimal, low, medium, high, xhigh, max (availability depends on pi version and model) |
504
- | `max_turns` | number | no | Max agentic turns. Omit for unlimited (default) |
505
- | `run_in_background` | boolean | no | Defaults to `true`; `false` blocks and returns the result inline, until [`ctrl+b`](#sending-a-foreground-agent-to-the-background) hands it to the background |
506
- | `resume` | string | no | Agent ID to resume a previous session. The resumed run gets a fresh `max_turns` budget. Works after the agent's record is evicted (about ten minutes after it finishes) or lost to a reload: the agent is reopened from its saved session under the same id, running under its type's current definition and never in a new worktree. Refused, with the reason, when the session was never saved, its file is gone, or it ran in a worktree that held changes (the worktree was removed when the agent finished, and its changes are on the branch named in the result) |
507
- | `isolated` | boolean | no | No extension/MCP tools |
508
- | `isolation` | `"off"` \| `"worktree"` | no | `worktree` runs in an isolated git worktree; `off` (the default) does not. Absent from the schema entirely when `worktreeIsolation: false` |
509
- | `inherit_context` | boolean | no | Fork parent conversation into agent |
498
+ | Parameter | Type | Required | Description |
499
+ | ------------------- | ----------------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
500
+ | `prompt` | string | yes | The task for the agent |
501
+ | `description` | string | yes | Short 3-5 word summary (shown in UI) |
502
+ | `name` | string | no | Memorable name for this agent (`auth-audit`), addressable as `@name` and accepted by `steer_subagent`/`get_subagent_result`. Additive — the type-derived handle is still assigned |
503
+ | `subagent_type` | string | yes | Agent type (built-in or custom) |
504
+ | `model` | string | no | Model — `provider/modelId` or fuzzy name (`"haiku"`, `"sonnet"`). Resolved tolerantly (`.`/`-` and a trailing date stamp interchangeable) with provider fallback |
505
+ | `thinking` | string | no | Thinking level: off, minimal, low, medium, high, xhigh, max (availability depends on pi version and model) |
506
+ | `max_turns` | number | no | Max agentic turns. Omit for unlimited (default) |
507
+ | `run_in_background` | boolean | no | Defaults to `true`; `false` blocks and returns the result inline, until [`ctrl+b`](#sending-a-foreground-agent-to-the-background) hands it to the background |
508
+ | `resume` | string | no | Agent ID to resume a previous session. The resumed run gets a fresh `max_turns` budget. The agent keeps its own type, model and thinking level; only `prompt`, `max_turns` and `run_in_background` apply. Works after the agent's record is evicted (about ten minutes after it finishes) or lost to a reload: the agent is reopened from its saved session under the same id, with its type's current prompt and tools, on the model and thinking level that session recorded, and never in a new worktree. If that model can no longer be used, pi falls back to its default model and warns. Refused, with the reason, when the session was never saved, its file is gone, or it ran in a worktree that held changes (the worktree was removed when the agent finished, and its changes are on the branch named in the result) |
509
+ | `isolated` | boolean | no | No extension/MCP tools |
510
+ | `isolation` | `"off"` \| `"worktree"` | no | `worktree` runs in an isolated git worktree; `off` (the default) does not. Absent from the schema entirely when `worktreeIsolation: false` |
511
+ | `inherit_context` | boolean | no | Fork parent conversation into agent |
510
512
 
511
513
  ### `SubagentWorkflow`
512
514
 
@@ -834,7 +836,7 @@ Leaving it unset is not quite the same as `true`. Unset means _auto_: on, unless
834
836
 
835
837
  The match is on the exact tool names `Workflow` (Claude Code's) and `SubagentWorkflow` (ours), never a substring, so a `list_workflows` or `github_workflow_run` from some CI integration does not silently take the feature down. The check runs at `session_start` and nowhere earlier, because `getAllTools` throws during extension loading and load order means a check at registration time could not see an extension that has not loaded yet — so the tool is registered first and withdrawn from the active set through `setActiveTools`, which rebuilds the system prompt before any turn runs. When the other extension took the `SubagentWorkflow` name itself, pi's first-registration-wins rule already dropped ours, so there is nothing to withdraw and only the menu and the CLI flag come down.
836
838
 
837
- **Tool description** (`toolDescriptionMode`, default `"full"`): which Agent tool description the LLM sees. `"full"` is the rich Claude Code-style prompt (~1,400 tokens with the default agents); `"compact"` is ~75% smaller — one-line agent type list, terse usage notes — for small/local models where tool-spec tokens are expensive. Per-option details stay in the parameter descriptions in every mode (the parameter schema is never customizable). Applies on the next pi session. For the `SubagentWorkflow` tool, the token saving is [`workflowToolExposure`](#persistent-settings) `"skill"` or `"deferred"`, below.
839
+ **Tool description** (`toolDescriptionMode`, default `"full"`): which Agent tool description the LLM sees. `"full"` is the rich Claude Code-style prompt (~1,400 tokens with the default agents); `"compact"` is ~75% smaller — one-line agent type list, terse usage notes — for small/local models where tool-spec tokens are expensive. Per-option details stay in the parameter descriptions in every mode (the parameter schema is never customizable). Applies on the next pi session (to nested `Agent` tools, on the next subagent started). For the `SubagentWorkflow` tool, the token saving is [`workflowToolExposure`](#persistent-settings) `"skill"` or `"deferred"`, below.
838
840
 
839
841
  `"custom"` registers your own description from `<cwd>/.pi/agent-tool-description.md` (project) or `<agentDir>/agent-tool-description.md` (global; project wins). The file is read once at tool registration, so edits also apply on the next pi session. Dynamic parts stay live via placeholders — a static agent list would go stale the moment you add a custom agent:
840
842
 
@@ -288,7 +288,7 @@ Any other key is rejected **by name** at the call. Note that this checks option
288
288
 
289
289
  Combination rules: `resume` cannot be combined with `agentType`, `model`, `effort`, `isolation`, `disallowedTools`, `gate` or `schema` — a resumed child keeps the agent type, model, tools and tree it was started with, and its session predates the `StructuredOutput` tool.
290
290
 
291
- A child stays resumable for the whole run. The manager evicts a finished child's record about ten minutes after it settles, and a review or a merge queue easily takes longer; `resume` then reopens the child's saved session under the same id, still owned by the run. That reopen runs under the agent type's current definition, so the model and tree the script chose for the first run are not carried over. It fails, resolving to `null` with the reason on that agent's row in the card and the inspector, when the child's session was never saved (`rememberAgents` off, or `persist_session: false`), its file is gone, or it ran with `isolation: "worktree"` and left changes: that worktree was removed when the child finished, with its changes on a branch, and continuing the work anywhere else would split it. A child whose worktree held no changes reopens in the run's directory, as in Claude Code.
291
+ A child stays resumable for the whole run. The manager evicts a finished child's record about ten minutes after it settles, and a review or a merge queue easily takes longer; `resume` then reopens the child's saved session under the same id, still owned by the run. That reopen keeps the model and effort the child's session recorded, so the script's choice for the first run carries over. It runs under the agent type's current prompt and tools, and never in a new worktree. It fails, resolving to `null` with the reason on that agent's row in the card and the inspector, when the child's session was never saved (`rememberAgents` off, or `persist_session: false`), its file is gone, or it ran with `isolation: "worktree"` and left changes: that worktree was removed when the child finished, with its changes on a branch, and continuing the work anywhere else would split it. A child whose worktree held no changes reopens in the run's directory, as in Claude Code.
292
292
 
293
293
  ### `agentError(label)`
294
294
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herbertgao/pi-subagents",
3
- "version": "0.26.0-local.1",
3
+ "version": "0.26.1-local.1",
4
4
  "description": "Claude Code-style autonomous subagents and workflow orchestration for Pi, with HerbertGao-maintained UI extensions.",
5
5
  "keywords": [
6
6
  "agent",
@@ -74,10 +74,10 @@
74
74
  },
75
75
  "x-upstream": {
76
76
  "package": "@tintinweb/pi-subagents",
77
- "version": "0.26.0",
78
- "reviewedVersion": "0.26.0",
77
+ "version": "0.26.1",
78
+ "reviewedVersion": "0.26.1",
79
79
  "repository": "https://github.com/tintinweb/pi-subagents",
80
- "commit": "dbbd769781847f9c0f74ba2a8545ff33c4b26e7c",
80
+ "commit": "14ef1946b439ad2c7e7db618ecdb36f5532052e7",
81
81
  "trackVersion": true
82
82
  }
83
83
  }
@@ -1314,17 +1314,26 @@ export async function runAgent(
1314
1314
  }
1315
1315
  }
1316
1316
 
1317
- // Resolve model: explicit option > config.model > parent model
1317
+ // A reopened conversation carries the model and thinking level it ran with,
1318
+ // and createAgentSession restores both when none is passed — so a reopen keeps
1319
+ // them, as a live resume keeps its session's (#462). Only an explicit option
1320
+ // outranks them; the agent file and the parent do not.
1321
+ const reopening = options.resumeSessionFile !== undefined
1322
+
1323
+ // Resolve model: explicit option > (reopen: the session's own) > config.model > parent model
1318
1324
  const model =
1319
1325
  options.model ??
1320
- resolveDefaultModel(ctx.model, ctx.modelRegistry, agentConfig?.model)
1326
+ (reopening
1327
+ ? undefined
1328
+ : resolveDefaultModel(ctx.model, ctx.modelRegistry, agentConfig?.model))
1321
1329
 
1322
- // Resolve thinking level: explicit option > agent config > parent session level.
1330
+ // Resolve thinking level: explicit option > (reopen: the session's own) > agent config > parent session level.
1323
1331
  // Without the parent step, an unset level falls through to pi's
1324
1332
  // defaultThinkingLevel (e.g. "max") instead of matching the spawning session.
1325
1333
  // Same idiom as mention-clone.ts.
1326
1334
  const thinkingLevel =
1327
- options.thinkingLevel ?? agentConfig?.thinking ?? ctx.thinkingLevel
1335
+ options.thinkingLevel ??
1336
+ (reopening ? undefined : (agentConfig?.thinking ?? ctx.thinkingLevel))
1328
1337
 
1329
1338
  // The `agent({ schema })` contract: this child reports its answer by calling
1330
1339
  // StructuredOutput, and `structuredJson` below is what the caller reads. The
@@ -1536,9 +1545,13 @@ export async function runAgent(
1536
1545
  sessionOpts.thinkingLevel = thinkingLevel
1537
1546
  }
1538
1547
 
1539
- const { session } = await runInChildSessionContext(() =>
1548
+ const { session, modelFallbackMessage } = await runInChildSessionContext(() =>
1540
1549
  createAgentSession(sessionOpts),
1541
1550
  )
1551
+ // Pi could not use the model the reopened conversation recorded and fell back
1552
+ // to its default. Warned the way pi warns at its own session start, and the
1553
+ // way an out-of-scope model is warned: to the user, not the model.
1554
+ if (modelFallbackMessage) ctx.ui.notify(modelFallbackMessage, "warning")
1542
1555
 
1543
1556
  const baseSessionName = agentConfig?.name ?? type
1544
1557
  session.setSessionName(
@@ -10,6 +10,7 @@ import {
10
10
  createReadOnlyTools,
11
11
  } from "@earendil-works/pi-coding-agent"
12
12
  import { DEFAULT_AGENTS } from "./default-agents.js"
13
+ import type { ToolDescriptionMode } from "./settings.js"
13
14
  import type { AgentConfig } from "./types.js"
14
15
 
15
16
  /**
@@ -387,3 +388,90 @@ export function getConfig(type: string): {
387
388
  promptMode: "append",
388
389
  }
389
390
  }
391
+
392
+ /**
393
+ * Which Agent tool description the LLM sees (#91). Module state rather than an
394
+ * index.ts closure because nested `Agent` tools, built per subagent session,
395
+ * follow it too. Read when a tool is built.
396
+ */
397
+ let toolDescriptionMode: ToolDescriptionMode = "full"
398
+
399
+ export function getToolDescriptionMode(): ToolDescriptionMode {
400
+ return toolDescriptionMode
401
+ }
402
+ export function setToolDescriptionMode(mode: ToolDescriptionMode): void {
403
+ toolDescriptionMode = mode
404
+ }
405
+
406
+ /** Derive a short model label from a model string. */
407
+ export function getModelLabelFromConfig(model: string): string {
408
+ // Strip provider prefix (e.g. "anthropic/claude-sonnet-4-6" → "claude-sonnet-4-6")
409
+ const name = model.includes("/") ? model.split("/").pop()! : model
410
+ // Strip trailing date suffix (e.g. "claude-haiku-4-5-20251001" → "claude-haiku-4-5")
411
+ return name.replace(/-\d{8}$/, "")
412
+ }
413
+
414
+ /** First sentence of an agent description — for the compact type list. */
415
+ function firstSentence(text: string): string {
416
+ const match = text.match(/^.*?[.!?](?=\s|$)/s)
417
+ return (match ? match[0] : text).replace(/\s+/g, " ").trim()
418
+ }
419
+
420
+ /**
421
+ * The "Available agent types" list in an Agent tool description, one line per
422
+ * name. Full lines carry the description, the model label and the tool scope;
423
+ * compact lines the description's first sentence and the tool scope.
424
+ */
425
+ export function formatAgentTypeList(
426
+ names: string[],
427
+ lookup: (name: string) => AgentConfig | undefined,
428
+ compact: boolean,
429
+ ): string {
430
+ return names
431
+ .map((name) => {
432
+ const cfg = lookup(name)
433
+ const tools = ` (Tools: ${formatToolsSuffix(cfg)})`
434
+ if (compact)
435
+ return `- ${name}: ${firstSentence(cfg?.description ?? name)}${tools}`
436
+ const model = cfg?.model ? ` (${getModelLabelFromConfig(cfg.model)})` : ""
437
+ return `- ${name}: ${cfg?.description ?? name}${model}${tools}`
438
+ })
439
+ .join("\n")
440
+ }
441
+
442
+ /**
443
+ * Format an agent's tool scope for the Agent tool description.
444
+ *
445
+ * This suffix describes BUILT-IN scope only — extension tools are resolved when
446
+ * the agent runs (extensions can register asynchronously), so they cannot be
447
+ * enumerated while the description is being built. That is why an agent with
448
+ * `tools: "*, ext:mcp/search"` renders "*" and always has.
449
+ *
450
+ * Two distinctions matter, both of them capability claims the orchestrator acts on:
451
+ *
452
+ * - absent vs empty. `builtinToolNames: undefined` means the agent never narrowed
453
+ * its tools (the shipped defaults); `[]` is what `tools: none` and an `ext:`-only
454
+ * `tools:` parse to, and the runtime really does hand those agents no built-ins.
455
+ * Rendering both "*" tells the orchestrator a tool-less agent can run `bash`.
456
+ * - empty-with-extensions vs empty-without. Zero built-ins does NOT imply zero
457
+ * tools: `tools: none` alongside `extensions:` still surfaces every extension
458
+ * tool (see test/fixtures/.pi/agents/tools-none.md, which expects three). Calling
459
+ * that "none" understates the agent instead of overstating it — better, but still
460
+ * wrong, and it would route work away from the only agent able to do it. "none"
461
+ * is therefore reserved for agents that genuinely can call nothing: `isolated`
462
+ * agents and those with `extensions: false`.
463
+ */
464
+ export function formatToolsSuffix(cfg: AgentConfig | undefined): string {
465
+ const tools = cfg?.builtinToolNames
466
+ if (!tools) return "*"
467
+ if (tools.length === 0) {
468
+ // `isolated` overrides extensions to false in the runner, so both mean the
469
+ // agent has no extension tools either — and then it truly has nothing.
470
+ const noExtensionTools = cfg?.isolated === true || cfg?.extensions === false
471
+ return noExtensionTools ? "none" : "no built-ins, extension tools only"
472
+ }
473
+ const isFullSet =
474
+ tools.length === BUILTIN_TOOL_NAMES.length &&
475
+ BUILTIN_TOOL_NAMES.every((t) => tools.includes(t))
476
+ return isFullSet ? "*" : tools.join(", ")
477
+ }
@@ -54,11 +54,13 @@ import {
54
54
  steerAgent,
55
55
  } from "./agent-runner.js"
56
56
  import {
57
- BUILTIN_TOOL_NAMES,
57
+ formatAgentTypeList,
58
58
  getAgentConfig,
59
59
  getAvailableTypes,
60
60
  getConfig,
61
61
  getFallbackSubagent,
62
+ getModelLabelFromConfig,
63
+ getToolDescriptionMode,
62
64
  isDefaultsDisabled,
63
65
  NO_FALLBACK,
64
66
  registerAgents,
@@ -66,6 +68,7 @@ import {
66
68
  resolveType,
67
69
  setDefaultsDisabled,
68
70
  setFallbackSubagent,
71
+ setToolDescriptionMode,
69
72
  } from "./agent-types.js"
70
73
  import { inChildSessionContext } from "./child-context.js"
71
74
  import { CompletionOutbox, NOTIFICATION_HOLD_MS } from "./completion-outbox.js"
@@ -140,7 +143,6 @@ import {
140
143
  partialOutputSuffix,
141
144
  } from "./status-note.js"
142
145
  import {
143
- type AgentConfig,
144
146
  type AgentInvocation,
145
147
  type AgentMentionMode,
146
148
  type AgentRecord,
@@ -475,43 +477,6 @@ function buildNotificationDetails(
475
477
  }
476
478
  }
477
479
 
478
- /**
479
- * Format an agent's tool scope for the Agent tool description.
480
- *
481
- * This suffix describes BUILT-IN scope only — extension tools are resolved when
482
- * the agent runs (extensions can register asynchronously), so they cannot be
483
- * enumerated while the description is being built. That is why an agent with
484
- * `tools: "*, ext:mcp/search"` renders "*" and always has.
485
- *
486
- * Two distinctions matter, both of them capability claims the orchestrator acts on:
487
- *
488
- * - absent vs empty. `builtinToolNames: undefined` means the agent never narrowed
489
- * its tools (the shipped defaults); `[]` is what `tools: none` and an `ext:`-only
490
- * `tools:` parse to, and the runtime really does hand those agents no built-ins.
491
- * Rendering both "*" tells the orchestrator a tool-less agent can run `bash`.
492
- * - empty-with-extensions vs empty-without. Zero built-ins does NOT imply zero
493
- * tools: `tools: none` alongside `extensions:` still surfaces every extension
494
- * tool (see test/fixtures/.pi/agents/tools-none.md, which expects three). Calling
495
- * that "none" understates the agent instead of overstating it — better, but still
496
- * wrong, and it would route work away from the only agent able to do it. "none"
497
- * is therefore reserved for agents that genuinely can call nothing: `isolated`
498
- * agents and those with `extensions: false`.
499
- */
500
- export function formatToolsSuffix(cfg: AgentConfig | undefined): string {
501
- const tools = cfg?.builtinToolNames
502
- if (!tools) return "*"
503
- if (tools.length === 0) {
504
- // `isolated` overrides extensions to false in the runner, so both mean the
505
- // agent has no extension tools either — and then it truly has nothing.
506
- const noExtensionTools = cfg?.isolated === true || cfg?.extensions === false
507
- return noExtensionTools ? "none" : "no built-ins, extension tools only"
508
- }
509
- const isFullSet =
510
- tools.length === BUILTIN_TOOL_NAMES.length &&
511
- BUILTIN_TOOL_NAMES.every((t) => tools.includes(t))
512
- return isFullSet ? "*" : tools.join(", ")
513
- }
514
-
515
480
  /** CLI flag that runs a workflow script at session start. */
516
481
  export const WORKFLOW_FILE_FLAG = "subagents-workflow-file"
517
482
 
@@ -1817,17 +1782,6 @@ export default function (pi: ExtensionAPI) {
1817
1782
  reloadCustomAgents() // re-register with new setting
1818
1783
  }
1819
1784
 
1820
- // ---- Agent tool description mode ----
1821
- // "full" (default) keeps the rich Claude Code-style description; "compact"
1822
- // swaps in a ~75% smaller one for small/local models (#91). Read once at
1823
- // tool registration — flipping it applies on the next pi session.
1824
- let toolDescriptionMode: ToolDescriptionMode = "full"
1825
- function getToolDescriptionMode(): ToolDescriptionMode {
1826
- return toolDescriptionMode
1827
- }
1828
- function setToolDescriptionMode(mode: ToolDescriptionMode): void {
1829
- toolDescriptionMode = mode
1830
- }
1831
1785
  let workflowToolExposure: WorkflowToolExposureMode = "inline"
1832
1786
  function getWorkflowToolExposure(): WorkflowToolExposureMode {
1833
1787
  return workflowToolExposure
@@ -2018,44 +1972,10 @@ export default function (pi: ExtensionAPI) {
2018
1972
  pi.on("agent_end", () => outbox.onAgentEnd())
2019
1973
  pi.on("agent_settled", () => outbox.onAgentEnd())
2020
1974
 
2021
- /** Build the full type list text dynamically from available agents only. */
2022
- const buildTypeListText = () => {
2023
- const available = getAvailableTypes()
2024
-
2025
- return available
2026
- .map((name) => {
2027
- const cfg = getAgentConfig(name)
2028
- const modelSuffix = cfg?.model
2029
- ? ` (${getModelLabelFromConfig(cfg.model)})`
2030
- : ""
2031
- const toolsSuffix = ` (Tools: ${formatToolsSuffix(cfg)})`
2032
- return `- ${name}: ${cfg?.description ?? name}${modelSuffix}${toolsSuffix}`
2033
- })
2034
- .join("\n")
2035
- }
2036
-
2037
- /** First sentence of an agent description — for the compact type list. */
2038
- const firstSentence = (text: string): string => {
2039
- const match = text.match(/^.*?[.!?](?=\s|$)/s)
2040
- return (match ? match[0] : text).replace(/\s+/g, " ").trim()
2041
- }
2042
-
2043
- /** Compact type list: one line per agent, first sentence only. */
1975
+ const buildTypeListText = () =>
1976
+ formatAgentTypeList(getAvailableTypes(), getAgentConfig, false)
2044
1977
  const buildCompactTypeListText = () =>
2045
- getAvailableTypes()
2046
- .map((name) => {
2047
- const cfg = getAgentConfig(name)
2048
- return `- ${name}: ${firstSentence(cfg?.description ?? name)} (Tools: ${formatToolsSuffix(cfg)})`
2049
- })
2050
- .join("\n")
2051
-
2052
- /** Derive a short model label from a model string. */
2053
- function getModelLabelFromConfig(model: string): string {
2054
- // Strip provider prefix (e.g. "anthropic/claude-sonnet-4-6" → "claude-sonnet-4-6")
2055
- const name = model.includes("/") ? model.split("/").pop()! : model
2056
- // Strip trailing date suffix (e.g. "claude-haiku-4-5-20251001" → "claude-haiku-4-5")
2057
- return name.replace(/-\d{8}$/, "")
2058
- }
1978
+ formatAgentTypeList(getAvailableTypes(), getAgentConfig, true)
2059
1979
 
2060
1980
  // Apply persisted settings on startup and emit `subagents:settings_loaded`.
2061
1981
  // Global + project merged; missing → defaults; corrupt file emits a warning
@@ -2520,8 +2440,9 @@ Terse command-style prompts produce shallow, generic work.
2520
2440
  // and picks up the widget, fleet row, transcript, join batching and
2521
2441
  // completion notification unchanged. Only the prompt, the turn budget and
2522
2442
  // run_in_background carry over from the call: like a live resume, it
2523
- // ignores `subagent_type`, model and the rest, and runs under the agent
2524
- // type's current definition.
2443
+ // ignores `subagent_type`, model, thinking and the rest. It runs under the
2444
+ // agent type's current prompt and tools, on the model and thinking level
2445
+ // its own session recorded (#462) — see the model resolution below.
2525
2446
  // `schedule` is left to its own branch, which refuses the combination.
2526
2447
  const saved =
2527
2448
  callParams.resume !== undefined &&
@@ -2606,8 +2527,11 @@ Terse command-style prompts produce shallow, generic work.
2606
2527
  )
2607
2528
 
2608
2529
  // Resolve model from agent config first; tool-call params only fill gaps.
2609
- let model = ctx.model
2610
- if (resolvedConfig.modelInput) {
2530
+ // A reopen resolves none: runAgent leaves the model and thinking level to
2531
+ // the reopened session, which restores the ones the agent ran with. The
2532
+ // agent file and the parent would both override them (#462).
2533
+ let model = reopenOptions ? undefined : ctx.model
2534
+ if (resolvedConfig.modelInput && !reopenOptions) {
2611
2535
  const resolved = resolveModel(
2612
2536
  resolvedConfig.modelInput,
2613
2537
  ctx.modelRegistry,
@@ -2635,7 +2559,7 @@ Terse command-style prompts produce shallow, generic work.
2635
2559
  if (scopeVerdict.kind === "warn")
2636
2560
  ctx.ui.notify(scopeVerdict.message, "warning")
2637
2561
 
2638
- const thinking = resolvedConfig.thinking
2562
+ const thinking = reopenOptions ? undefined : resolvedConfig.thinking
2639
2563
  const inheritContext = resolvedConfig.inheritContext
2640
2564
  const runInBackground = resolvedConfig.runInBackground
2641
2565
  const isolated = resolvedConfig.isolated
@@ -64,6 +64,7 @@ import {
64
64
  } from "@earendil-works/pi-coding-agent"
65
65
  import { runInChildSessionContext } from "./child-context.js"
66
66
  import { agentMentionReminder } from "./mention.js"
67
+ import { withoutCwdSection } from "./prompts.js"
67
68
  import type { SubagentType } from "./types.js"
68
69
 
69
70
  export interface MentionCloneOptions {
@@ -152,8 +153,11 @@ export async function runMentionClone(
152
153
  // The live system prompt, not the one the clone would build from cwd and
153
154
  // agentDir — extensions contribute to it per turn. Everything the loader
154
155
  // would add on top (AGENTS.md, skills, APPEND_SYSTEM.md) is already in the
155
- // rendered prompt, so it is suppressed, as agent-runner does.
156
- const systemPrompt = ctx.getSystemPrompt()
156
+ // rendered prompt, so it is suppressed, as agent-runner does. The `cwd`
157
+ // section cannot be suppressed — pi renders it after any prompt — so the
158
+ // parent's copy is removed instead. Extension sections stay: the clone
159
+ // loads no extensions to render them again.
160
+ const systemPrompt = withoutCwdSection(ctx.getSystemPrompt(), ctx.cwd)
157
161
  const loader = new DefaultResourceLoader({
158
162
  cwd: ctx.cwd,
159
163
  agentDir: getAgentDir(),
@@ -10,8 +10,10 @@ import { Type } from "typebox"
10
10
  import { abortable } from "./abortable.js"
11
11
  import {
12
12
  buildAgentRegistry,
13
+ formatAgentTypeList,
13
14
  getAgentConfigIn,
14
15
  getAvailableTypesIn,
16
+ getToolDescriptionMode,
15
17
  resolveEnabledTypeIn,
16
18
  resolveTypeIn,
17
19
  } from "./agent-types.js"
@@ -196,12 +198,26 @@ export function createNestedSubagentTools(
196
198
  )
197
199
  }
198
200
 
201
+ const registry = loadRegistry()
202
+ const available = availableIn(registry)
203
+ // Same list as the main session's Agent tool (#457); a "custom" description
204
+ // is written for the main session, so it counts as full here.
205
+ const typeList =
206
+ available.length > 0
207
+ ? formatAgentTypeList(
208
+ available,
209
+ (name) => getAgentConfigIn(registry, name),
210
+ getToolDescriptionMode() === "compact",
211
+ )
212
+ : "none"
213
+
199
214
  const agentTool = defineTool({
200
215
  name: NESTED_TOOL_NAMES[0],
201
216
  label: "Agent",
202
217
  description:
203
218
  "Launch a child-safe nested subagent for bounded delegated work. " +
204
- "Only use agent types allowed by this parent agent; nesting is depth-limited. " +
219
+ "Only use agent types allowed by this parent agent; nesting is depth-limited.\n\n" +
220
+ `Available agent types and the tools they have access to:\n${typeList}\n\n` +
205
221
  // Overrides the main session's inherited Agent guideline ("you will be
206
222
  // notified on completion"), which does not hold for nested children.
207
223
  "A background nested agent does NOT notify you when it finishes: collect each one with get_subagent_result (wait: true) before you end your turn, or it is stopped and its work is lost.",
@@ -213,7 +229,7 @@ export function createNestedSubagentTools(
213
229
  description: "Short 3-5 word task description.",
214
230
  }),
215
231
  subagent_type: Type.String({
216
- description: `Allowed nested agent type. Available: ${availableIn(loadRegistry()).join(", ") || "none"}.`,
232
+ description: `Allowed nested agent type. Available: ${available.join(", ") || "none"}.`,
217
233
  }),
218
234
  model: Type.Optional(
219
235
  Type.String({ description: "Optional provider/model override." }),
@@ -189,9 +189,7 @@ ${envBlock}`
189
189
  * @param cwd The cwd the parent's prompt was rendered with.
190
190
  */
191
191
  export function inheritableParentPrompt(rendered: string, cwd: string): string {
192
- const cwdAt = rendered.lastIndexOf(
193
- `\n\n<cwd>\n${cwd.replace(/\\/g, "/")}\n</cwd>`,
194
- )
192
+ const cwdAt = rendered.lastIndexOf(cwdSection(cwd))
195
193
  if (cwdAt < 0) return rendered
196
194
  const head = rendered.slice(0, cwdAt)
197
195
  if (!head.endsWith("\n</skills>")) return head
@@ -199,6 +197,30 @@ export function inheritableParentPrompt(rendered: string, cwd: string): string {
199
197
  return skillsAt < 0 ? head : head.slice(0, skillsAt)
200
198
  }
201
199
 
200
+ /**
201
+ * The parent's rendered system prompt without its `cwd` section, for a session that
202
+ * renders its own `cwd` after the prompt it is given and adds nothing else.
203
+ *
204
+ * Everything else is kept, including sections after `cwd` (extension sections present
205
+ * while the parent's turn runs). A prompt without the section (for example, a forced
206
+ * prompt) is returned unchanged.
207
+ *
208
+ * @param rendered The parent's `ctx.getSystemPrompt()`.
209
+ * @param cwd The cwd the parent's prompt was rendered with.
210
+ */
211
+ export function withoutCwdSection(rendered: string, cwd: string): string {
212
+ const section = cwdSection(cwd)
213
+ const at = rendered.lastIndexOf(section)
214
+ return at < 0
215
+ ? rendered
216
+ : rendered.slice(0, at) + rendered.slice(at + section.length)
217
+ }
218
+
219
+ /** The `cwd` section as pi renders it after the preceding section. */
220
+ function cwdSection(cwd: string): string {
221
+ return `\n\n<cwd>\n${cwd.replace(/\\/g, "/")}\n</cwd>`
222
+ }
223
+
202
224
  /** Fallback base prompt when parent system prompt is unavailable in append mode. */
203
225
  const genericBase = `# Role
204
226
  You are a general-purpose coding agent for complex, multi-step tasks.