gentle-pi 4.5.0 → 4.6.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.
Files changed (243) hide show
  1. package/README.md +9 -6
  2. package/assets/agents/gentle-ai-verify.md +4 -0
  3. package/assets/agents/gentle-ai-worker.md +1 -0
  4. package/assets/migrations/agent-body-history.json +147 -0
  5. package/assets/orchestrator-delegation-reference.md +3 -3
  6. package/assets/orchestrator-delegation.md +2 -2
  7. package/assets/orchestrator-verification.md +10 -6
  8. package/assets/orchestrator.md +8 -8
  9. package/bin/gentle-shell.mjs +61 -26
  10. package/docs/ci-performance.md +11 -0
  11. package/docs/delegated-verification.md +6 -0
  12. package/docs/fast-mode.md +15 -0
  13. package/docs/gentle-agents-activity.md +8 -0
  14. package/docs/gentle-music.md +6 -3
  15. package/docs/gentle-shell.md +70 -20
  16. package/docs/install-wizard.md +1 -1
  17. package/docs/mcp-status.md +52 -0
  18. package/docs/prompt-budget.md +28 -0
  19. package/docs/readme-reference.md +82 -21
  20. package/docs/session-profile-format.md +20 -5
  21. package/docs/sound-notifications.md +1 -1
  22. package/docs/star-prompt.md +32 -0
  23. package/docs/work-continuity.md +46 -0
  24. package/extensions/ask-user-question.ts +1 -0
  25. package/extensions/codegraph-tools.ts +38 -4
  26. package/extensions/gentle-agents.ts +477 -50
  27. package/extensions/gentle-ai.ts +1046 -191
  28. package/extensions/gentle-fast.ts +61 -0
  29. package/extensions/gentle-guide.ts +174 -0
  30. package/extensions/gentle-herdr-activity.ts +21 -1
  31. package/extensions/gentle-herdr-agent.ts +144 -0
  32. package/extensions/gentle-music.ts +10 -0
  33. package/extensions/gentle-program-identity.ts +61 -0
  34. package/extensions/gentle-shell.ts +642 -97
  35. package/extensions/gentle-star-prompt.ts +334 -0
  36. package/extensions/gentle-stats.ts +5 -5
  37. package/extensions/gentle-todo.ts +42 -22
  38. package/extensions/history/store.ts +18 -12
  39. package/extensions/skill-registry.ts +35 -3
  40. package/extensions/startup-banner.ts +39 -7
  41. package/lib/agent-assets.ts +74 -17
  42. package/lib/agent-profiles.ts +1 -1
  43. package/lib/agents-config.ts +12 -3
  44. package/lib/agents-keys.ts +8 -16
  45. package/lib/agents-protocol.ts +80 -4
  46. package/lib/agents-runner.ts +105 -4
  47. package/lib/agents-view.ts +6 -1
  48. package/lib/agents-widget.ts +132 -9
  49. package/lib/bridge-cost.ts +28 -0
  50. package/lib/codemode-renderer.ts +16 -0
  51. package/lib/command-palette-catalog.ts +1 -0
  52. package/lib/command-palette.ts +21 -8
  53. package/lib/exploration-budget.ts +62 -0
  54. package/lib/gentle-guide.ts +201 -0
  55. package/lib/gentle-shell-launcher.ts +4 -0
  56. package/lib/herdr-activity.ts +9 -3
  57. package/lib/herdr-task-summary-policy.ts +85 -0
  58. package/lib/inprocess-reviewer.ts +33 -13
  59. package/lib/jobs-sidebar-state.ts +5 -6
  60. package/lib/jobs-widget.ts +16 -52
  61. package/lib/keymaps-customize.ts +81 -0
  62. package/lib/keymaps.ts +291 -0
  63. package/lib/model-fallback-notice.ts +61 -0
  64. package/lib/model-fallback-policy.ts +141 -0
  65. package/lib/model-fallback-store.ts +143 -0
  66. package/lib/model-routing-authority.ts +10 -2
  67. package/lib/nan-provider.ts +3 -2
  68. package/lib/native-review-cli.ts +7 -2
  69. package/lib/notification-customize.ts +48 -51
  70. package/lib/openai-fast-tier.ts +22 -0
  71. package/lib/orchestrator-discovery.ts +5 -1
  72. package/lib/orchestrator-fallback.ts +75 -0
  73. package/lib/pasted-image-paths.ts +113 -0
  74. package/lib/questionnaire/questionnaire-view.ts +121 -7
  75. package/lib/review-candidate-view-owner.ts +4 -0
  76. package/lib/review-candidate-view.ts +10 -7
  77. package/lib/review-host-relay.ts +5 -1
  78. package/lib/review-integration-v2.ts +22 -7
  79. package/lib/review-repository.ts +5 -0
  80. package/lib/session-profile-append-controller.ts +21 -6
  81. package/lib/session-profile-authority.ts +119 -0
  82. package/lib/session-profile-binding.ts +54 -5
  83. package/lib/session-profile-freeze.ts +105 -9
  84. package/lib/session-profile-integration.ts +313 -0
  85. package/lib/session-profile-persistence.ts +63 -9
  86. package/lib/shell-bar.ts +171 -56
  87. package/lib/shell-card.ts +26 -6
  88. package/lib/shell-page.ts +120 -0
  89. package/lib/shell-panel.ts +149 -0
  90. package/lib/shell-prompt.ts +53 -1
  91. package/lib/shell-sidebar-layout.ts +98 -25
  92. package/lib/shell-sidebar.ts +54 -1
  93. package/lib/shell-stats.ts +123 -0
  94. package/lib/shell-todo.ts +71 -0
  95. package/lib/shell-usage.ts +12 -2
  96. package/lib/star-prompt.ts +197 -0
  97. package/lib/verifier-admission.ts +18 -8
  98. package/lib/verifier-settle-reminder.ts +64 -0
  99. package/lib/vim-editor-adapter.ts +6 -1
  100. package/lib/visual-customization-policy.ts +41 -6
  101. package/lib/visual-customize-view.ts +164 -26
  102. package/lib/visual-layout-preview.ts +43 -0
  103. package/lib/yolo-session-policy.ts +28 -1
  104. package/package.json +1 -1
  105. package/runtime/gentle-shell-launcher.mjs +4 -0
  106. package/runtime/native-review-cli.mjs +7 -2
  107. package/runtime/review-integration-v2.mjs +22 -7
  108. package/runtime/windows-session-transport.ps1 +60 -3
  109. package/scripts/bootstrap.sh +4 -1
  110. package/scripts/installer-preflight.mjs +1 -1
  111. package/scripts/pi-update.mjs +113 -3
  112. package/scripts/run-test-suite.mjs +17 -1
  113. package/scripts/shell-snapshot.mjs +340 -0
  114. package/scripts/test-packed-runner.mjs +1 -1
  115. package/scripts/update-agent-body-history.mjs +41 -0
  116. package/scripts/verify-installer-tap.mjs +45 -0
  117. package/scripts/verify-package-files.mjs +2 -0
  118. package/skills/gentle-ai/SKILL.md +2 -2
  119. package/skills/tui-design/NOTICE.md +5 -0
  120. package/skills/tui-design/SKILL.md +56 -0
  121. package/skills/tui-design/references/commands.md +75 -0
  122. package/skills/tui-design/references/critique.md +48 -0
  123. package/skills/tui-design/references/design-doc.md +44 -0
  124. package/skills/tui-design/references/terminal-craft.md +64 -0
  125. package/skills/tui-design/references/visual-loop.md +32 -0
  126. package/tests/agents-protocol.test.ts +53 -1
  127. package/tests/agents-runner.test.ts +168 -3
  128. package/tests/agents-view.test.ts +27 -0
  129. package/tests/agents-widget.test.ts +312 -10
  130. package/tests/bounded-scan-contract.test.ts +39 -0
  131. package/tests/bridge-cost.test.ts +32 -0
  132. package/tests/bundled-install.test.ts +6 -4
  133. package/tests/ci-concurrency.test.ts +11 -0
  134. package/tests/ci-merge-base-identity.test.ts +114 -0
  135. package/tests/codegraph-tools.test.ts +69 -0
  136. package/tests/codemode-rendering.test.ts +22 -2
  137. package/tests/command-palette.test.ts +16 -2
  138. package/tests/commit-slice-signal.test.ts +11 -9
  139. package/tests/delegate-for-reason-contract.test.ts +5 -4
  140. package/tests/design-canvas-server.test.ts +6 -2
  141. package/tests/exploration-budget.test.ts +128 -0
  142. package/tests/fixtures/agent-assets/gentle-ai-worker.strict-tdd-era.md +122 -0
  143. package/tests/fixtures/measure-orchestrator-prompt.mjs +2 -1
  144. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +18 -10
  145. package/tests/fixtures/session-profile-v1/replay.ts +125 -0
  146. package/tests/fixtures/session-profile-v1/session-profile-authority.ts +113 -0
  147. package/tests/fixtures/session-profile-v1/session-profile-binding.ts +83 -0
  148. package/tests/fixtures/session-profile-v1/session-profile-disk-reader.ts +182 -0
  149. package/tests/fixtures/session-profile-v1/session-profile-freeze.ts +290 -0
  150. package/tests/fixtures/session-profile-v1/session-profile-persistence.ts +195 -0
  151. package/tests/fixtures/session-profile-v1/v1-inputs.ts +16 -0
  152. package/tests/fixtures/windows-pipe-availability.ps1 +26 -0
  153. package/tests/fixtures/windows-session-bootstrap.ps1 +6 -2
  154. package/tests/gentle-agents.test.ts +416 -21
  155. package/tests/gentle-ai-exploration-budget.test.ts +135 -0
  156. package/tests/gentle-ai.test.ts +1011 -37
  157. package/tests/gentle-fast.test.ts +73 -0
  158. package/tests/gentle-guide.test.ts +208 -0
  159. package/tests/gentle-herdr-activity.test.ts +76 -2
  160. package/tests/gentle-herdr-agent.test.ts +111 -0
  161. package/tests/gentle-music.test.ts +36 -1
  162. package/tests/gentle-program-identity.test.ts +197 -0
  163. package/tests/gentle-shell-bin.test.ts +49 -26
  164. package/tests/gentle-shell-launcher.test.ts +18 -2
  165. package/tests/gentle-shell.test.ts +1068 -37
  166. package/tests/gentle-stats.test.ts +15 -2
  167. package/tests/gentle-todo.test.ts +50 -4
  168. package/tests/herdr-task-summary-policy.test.ts +128 -0
  169. package/tests/history-store-private-mode.test.ts +40 -0
  170. package/tests/image-paste-chips.test.ts +42 -0
  171. package/tests/inprocess-reviewer.test.ts +122 -0
  172. package/tests/installer-posix-bootstrap.test.ts +67 -5
  173. package/tests/installer-server.test.ts +2 -2
  174. package/tests/installer-windows-diagnostics.test.ts +4 -5
  175. package/tests/isolated-config-home.ts +28 -0
  176. package/tests/jobs-widget.test.ts +25 -37
  177. package/tests/keymaps-customize.test.ts +114 -0
  178. package/tests/keymaps.test.ts +103 -0
  179. package/tests/maintainer/mcp-status.maintest.ts +88 -0
  180. package/tests/maintainer/pi-update-source.maintest.ts +116 -0
  181. package/tests/model-fallback-notice.test.ts +45 -0
  182. package/tests/model-fallback-policy.test.ts +83 -0
  183. package/tests/model-fallback-store.test.ts +111 -0
  184. package/tests/nan-provider.test.ts +4 -4
  185. package/tests/no-self-pause-contract.test.ts +19 -0
  186. package/tests/notification-customize.test.ts +58 -34
  187. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  188. package/tests/odd-routing-contract.test.ts +1 -1
  189. package/tests/orchestrator-fallback.test.ts +82 -0
  190. package/tests/orchestrator-prompt-budget.test.ts +131 -0
  191. package/tests/package-manifest.test.ts +160 -7
  192. package/tests/pasted-image-paths.test.ts +118 -0
  193. package/tests/persona-reply-language.test.ts +61 -0
  194. package/tests/pi-update-launcher.test.ts +32 -8
  195. package/tests/pi-update-source.test.ts +162 -0
  196. package/tests/profile-fast-tier.test.ts +311 -0
  197. package/tests/profile-tier-footer.test.ts +79 -0
  198. package/tests/questionnaire-view.test.ts +150 -0
  199. package/tests/review-candidate-owner-sweep.test.ts +93 -0
  200. package/tests/review-candidate-view.test.ts +51 -0
  201. package/tests/review-controller-native-routing.test.ts +120 -6
  202. package/tests/review-gate.test.ts +24 -0
  203. package/tests/review-inspect-preflight.test.ts +197 -0
  204. package/tests/review-integration-v2-forward.test.ts +59 -0
  205. package/tests/review-repository.test.ts +52 -1
  206. package/tests/review-sidebar-state.test.ts +5 -5
  207. package/tests/run-test-suite.test.ts +61 -5
  208. package/tests/sensitive-path-tools.test.ts +74 -0
  209. package/tests/session-profile-append-controller.test.ts +63 -0
  210. package/tests/session-profile-authority.test.ts +259 -0
  211. package/tests/session-profile-binding.test.ts +15 -0
  212. package/tests/session-profile-extension.test.ts +615 -0
  213. package/tests/session-profile-freeze.test.ts +110 -2
  214. package/tests/session-profile-integration.test.ts +857 -0
  215. package/tests/session-profile-persistence.test.ts +57 -0
  216. package/tests/session-profile-v1-compat.test.ts +221 -0
  217. package/tests/shell-bar.test.ts +113 -55
  218. package/tests/shell-card.test.ts +13 -1
  219. package/tests/shell-page.test.ts +108 -0
  220. package/tests/shell-panel.test.ts +332 -0
  221. package/tests/shell-prompt.test.ts +54 -0
  222. package/tests/shell-render-cache.test.ts +5 -0
  223. package/tests/shell-sidebar-fullscreen.test.ts +12 -0
  224. package/tests/shell-sidebar-layout.test.ts +159 -27
  225. package/tests/shell-stats.test.ts +90 -0
  226. package/tests/shell-usage.test.ts +14 -0
  227. package/tests/skill-registry.test.ts +68 -1
  228. package/tests/star-prompt.test.ts +470 -0
  229. package/tests/startup-banner.test.ts +57 -1
  230. package/tests/task-size-routing-contract.test.ts +45 -1
  231. package/tests/verifier-settle-reminder.test.ts +281 -0
  232. package/tests/verify-first-launch-contract.test.ts +56 -5
  233. package/tests/verify-installer-tap.test.ts +57 -0
  234. package/tests/vim-editor-adapter.test.ts +2 -2
  235. package/tests/visual-customization-policy.test.ts +61 -7
  236. package/tests/visual-customize-view.test.ts +253 -8
  237. package/tests/visual-layout-preview.test.ts +28 -0
  238. package/tests/windows-session-bootstrap.test.ts +105 -2
  239. package/tests/work-continuity-contract.test.ts +86 -0
  240. package/tests/writer-surfaces.test.ts +12 -10
  241. package/tests/yolo-customize.test.ts +30 -11
  242. package/tests/yolo-mode-runtime.test.ts +4 -2
  243. package/tests/yolo-mode.test.ts +16 -2
@@ -20,7 +20,8 @@ const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
20
20
  // Decimal bounds conservatively interpret the documented 1M/262K/131K labels.
21
21
  // Pi models text/image inputs only; documented audio/video inputs are not advertised.
22
22
  // Reasoning shares max_tokens with the answer: 65,536 leaves answer room after a
23
- // 32,768 reasoning budget; DeepSeek uses NaN's 16,384 floor. Qwen 3.8 retains its
23
+ // 32,768 reasoning budget; DeepSeek gets a generous 131,072 output budget: NaN counts reasoning
24
+ // against max_tokens and dense review prompts exceed 16K reasoning tokens (gentle-shell#2840). Qwen 3.8 retains its
24
25
  // published 131K output maximum. The remaining 32,768 caps are configured, not NaN-published limits.
25
26
  // Pi requires explicit max mappings to offer that level; a null hides a level Pi would otherwise
26
27
  // offer, and missing ordinary levels pass through. Each map exposes exactly the efforts NaN's
@@ -56,7 +57,7 @@ const CHAT_MODELS: NanChatModelConfig[] = ([
56
57
  },
57
58
  {
58
59
  id: "deepseek-v4-flash", name: "DeepSeek V4 Flash", input: ["text", "image"], contextWindow: 1_000_000,
59
- thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 16_384,
60
+ thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 131_072,
60
61
  // NaN's DeepSeek route enforces this field, not max_completion_tokens.
61
62
  compat: { maxTokensField: "max_tokens" },
62
63
  },
@@ -18,6 +18,7 @@ import {
18
18
  decodeReviewStartV3,
19
19
  decodeReviewStartV4,
20
20
  decodeReviewStatusV3,
21
+ intendedUntrackedSubmissionCarriesTarget,
21
22
  type ReviewAcknowledgedExpectationV1,
22
23
  type ReviewAcknowledgedV1,
23
24
  type ReviewConsentEnvelope,
@@ -2399,7 +2400,11 @@ export class NativeReviewCliV216 implements NativeReviewCli {
2399
2400
  // value for the same flag. providerFlagValue also fails closed on a
2400
2401
  // dangling `--flag` (last token, no value) or an empty `--flag=`.
2401
2402
  const submittedBaseRefValue = submittedTokens === undefined ? undefined : providerFlagValue(submittedTokens, "base-ref");
2402
- if (request.baseRef !== undefined && submittedBaseRefValue !== undefined && submittedBaseRefValue !== request.baseRef) throw new TypeError("Native intended-untracked selection already carries a conflicting base-ref");
2403
+ // A provider-issued base-diff selector (base tree plus scope) already binds
2404
+ // the target the request named; the tree is not textually comparable to
2405
+ // the request's ref, so it runs as issued and nothing is re-forwarded.
2406
+ const providerOwnsTarget = submitted !== undefined && intendedUntrackedSubmissionCarriesTarget(submitted.argumentTokens);
2407
+ if (!providerOwnsTarget && request.baseRef !== undefined && submittedBaseRefValue !== undefined && submittedBaseRefValue !== request.baseRef) throw new TypeError("Native intended-untracked selection already carries a conflicting base-ref");
2403
2408
  const submittedLineageValue = submittedTokens === undefined ? undefined : providerFlagValue(submittedTokens, "lineage");
2404
2409
  if (request.lineageId !== undefined && submittedLineageValue !== undefined && submittedLineageValue !== request.lineageId) throw new TypeError("Native intended-untracked selection already carries a conflicting lineage");
2405
2410
  let submittedHasCommittedOnly = false;
@@ -2412,7 +2417,7 @@ export class NativeReviewCliV216 implements NativeReviewCli {
2412
2417
  // Append only the half of the base-ref/committed-only pair the provider
2413
2418
  // did not already carry (a present base-ref already equals
2414
2419
  // request.baseRef; the throw above ruled out the conflicting case).
2415
- const forwardedBaseRef = request.baseRef === undefined ? [] : [
2420
+ const forwardedBaseRef = request.baseRef === undefined || providerOwnsTarget ? [] : [
2416
2421
  ...(submittedBaseRefValue === undefined ? ["--base-ref", request.baseRef] : []),
2417
2422
  ...(submittedHasCommittedOnly ? [] : ["--committed-only"]),
2418
2423
  ];
@@ -7,7 +7,7 @@ import {
7
7
  import { getNotificationService, type NotificationService } from "./notification-service.ts";
8
8
  import type { CustomizeInline, CustomizeRow } from "./visual-customize-view.ts";
9
9
 
10
- /** Silence first, then the builtins; Enter wraps back to silence. Priority is the event's, not the sound's. */
10
+ /** Inline sound options: silence, builtins, then custom. Priority belongs to the event. */
11
11
  const SOUND_CYCLE: readonly NotificationSound[] = [null, ...BUILTIN_NOTIFICATION_IDS.map(id => `builtin:${id}` as const)];
12
12
  /** Human labels for the builtin tones; the basic card never prints a `builtin:` id. */
13
13
  const HUMAN_TONES: Readonly<Record<string, string>> = Object.freeze({
@@ -15,19 +15,19 @@ const HUMAN_TONES: Readonly<Record<string, string>> = Object.freeze({
15
15
  "builtin:error": "error tone",
16
16
  "builtin:attention": "attention tone",
17
17
  });
18
+ const CUSTOM_SOUND = "custom";
18
19
  /** Footer hint shared by every row that can assign its own sound (basic groups and per-event exceptions). */
19
- const SOUND_ROW_HINT = "Tab panes · Enter change · f sound · p test · Esc close";
20
+ const SOUND_ROW_HINT = "←/→ choose · Enter apply · f sound · p test · Esc close";
20
21
 
21
22
  interface GroupPlan {
22
23
  name: string;
23
- recommended: `builtin:${typeof BUILTIN_NOTIFICATION_IDS[number]}`;
24
24
  targets: readonly NotificationEvent[];
25
25
  }
26
26
  /** Fixed, verified targets per basic type. Attention never intersects `subagent.waiting`. */
27
27
  const GROUP_PLANS: readonly GroupPlan[] = [
28
- { name: "Success", recommended: "builtin:success", targets: ["agent.completed", "subagent.completed"] },
29
- { name: "Error", recommended: "builtin:error", targets: ["agent.failed", "subagent.failed", "subagent.timed_out"] },
30
- { name: "Attention", recommended: "builtin:attention", targets: ["agent.attention"] },
28
+ { name: "Success", targets: ["agent.completed", "subagent.completed"] },
29
+ { name: "Error", targets: ["agent.failed", "subagent.failed", "subagent.timed_out"] },
30
+ { name: "Attention", targets: ["agent.attention"] },
31
31
  ];
32
32
 
33
33
  /** Human basename for a local audio reference; never leaks the absolute path or the `file:` prefix. */
@@ -135,7 +135,20 @@ export function buildNotificationRows(ctx: ExtensionContext): CustomizeRow[] {
135
135
  };
136
136
 
137
137
  const rows: CustomizeRow[] = [];
138
- rows.push({
138
+ const choices = <T>(row: Omit<CustomizeRow, "action" | "choice">, setting: string,
139
+ options: readonly { value: T; label: string }[], read: () => T | undefined,
140
+ apply: (value: T, inline: CustomizeInline) => unknown): void => {
141
+ for (const option of options) rows.push({ ...row,
142
+ choice: { setting, value: option.label, current: () => read() === option.value, applyOnMove: false },
143
+ action: async inline => { await apply(option.value, inline); },
144
+ });
145
+ };
146
+ const onOff = [{ value: false, label: "off" }, { value: true, label: "on" }];
147
+ const sounds: { value: NotificationSound | typeof CUSTOM_SOUND; label: string }[] = [
148
+ ...SOUND_CYCLE.map(value => ({ value, label: selectionLabel(value) })), { value: CUSTOM_SOUND, label: "custom" },
149
+ ];
150
+ const soundValue = (sound: NotificationSound): NotificationSound | typeof CUSTOM_SOUND => sound?.startsWith("file:") ? CUSTOM_SOUND : sound;
151
+ choices({
139
152
  category,
140
153
  label: () => { const current = state(); return `Audio notifications: ${current ? (current.settings.enabled ? "on" : "off") : "unavailable"}`; },
141
154
  preview: () => {
@@ -143,25 +156,18 @@ export function buildNotificationRows(ctx: ExtensionContext): CustomizeRow[] {
143
156
  return { title: "Audio notifications · global switch",
144
157
  sample: current ? `opt-in audio · ${current.settings.enabled ? "enabled" : "disabled"} · mute: ${current.muted ? "on" : "off"} · separate from visual settings` : "Unavailable in this session" };
145
158
  },
146
- action: async inline => {
147
- const service = serviceOrNotify();
148
- if (!service) return;
149
- const enabled = !service.getState().settings.enabled;
150
- await mutate(inline, settings => { settings.enabled = enabled; });
151
- },
152
- });
153
- rows.push({
159
+ }, "Enabled", onOff, () => state()?.settings.enabled,
160
+ (enabled, inline) => mutate(inline, settings => { settings.enabled = enabled; }));
161
+ choices({
154
162
  category,
155
163
  label: () => { const current = state(); return `Audio: ${current ? (current.muted ? "muted" : "unmuted") : "unavailable"}`; },
156
164
  preview: () => ({ title: "Audio · process mute", sample: "mute survives reload and session replacement; restarting Pi clears it; muted or disabled events are never replayed" }),
157
- action: () => {
158
- const service = serviceOrNotify();
159
- if (!service) return;
160
- if (!service.setMuted(ctx, !service.getState().muted)) notify("Audio mute could not be changed.", true);
161
- },
165
+ }, "Mute", onOff, () => state()?.muted, muted => {
166
+ const service = serviceOrNotify();
167
+ if (service && !service.setMuted(ctx, muted)) notify("Audio mute could not be changed.", true);
162
168
  });
163
169
  for (const group of GROUP_PLANS) {
164
- rows.push({
170
+ choices({
165
171
  category,
166
172
  keyhint: SOUND_ROW_HINT,
167
173
  label: () => { const current = state(); return current ? `${group.name}: ${groupSelectionLabel(current.settings, group)}` : `${group.name}: unavailable`; },
@@ -170,18 +176,10 @@ export function buildNotificationRows(ctx: ExtensionContext): CustomizeRow[] {
170
176
  if (!current) return { title: `${group.name} sounds`, sample: "Unavailable in this session" };
171
177
  const selection = groupSelection(current.settings, group);
172
178
  const detail = selection.kind === "mixed" ? `mixes several sounds across ${group.targets.length} events · expand Advanced for per-event exceptions`
173
- : selection.sound === null ? "silence · Enter cycles tone or assign your own sound with f"
179
+ : selection.sound === null ? "silence · choose a tone or assign your own sound with f"
174
180
  : selection.sound.startsWith("builtin:") ? `${selectionLabel(selection.sound)} · builtin tone · f assigns your own sound`
175
181
  : `${selectionLabel(selection.sound)} (own group file) · f replaces it`;
176
- return { title: `${group.name} sounds · applies to ${group.targets.length} event${group.targets.length === 1 ? "" : "s"}`, sample: `${detail} · p tests the selected sound` };
177
- },
178
- action: async inline => {
179
- const service = serviceOrNotify();
180
- if (!service) return;
181
- const selection = groupSelection(service.getState().settings, group);
182
- const next = selection.kind === "mixed" ? group.recommended
183
- : SOUND_CYCLE[(SOUND_CYCLE.indexOf(selection.sound) + 1) % SOUND_CYCLE.length]!;
184
- await setTargets(inline, group.targets, next);
182
+ return { title: `${group.name} sounds · applies to ${group.targets.length} event${group.targets.length === 1 ? "" : "s"}`, sample: `${group.name}: ${groupSelectionLabel(current.settings, group)} · ${detail} · p tests the configured sound` };
185
183
  },
186
184
  key: (data, inline) => {
187
185
  if (matchesKey(data, "p")) {
@@ -193,49 +191,48 @@ export function buildNotificationRows(ctx: ExtensionContext): CustomizeRow[] {
193
191
  return true;
194
192
  }
195
193
  if (matchesKey(data, "f")) {
196
- const service = getNotificationService();
197
- const selection = service ? groupSelection(service.getState().settings, group) : undefined;
198
- const prefill = selection?.kind === "uniform" && selection.sound !== null && selection.sound.startsWith("file:")
199
- ? selection.sound.slice(5) : "";
200
- return chooseFileFor(inline, group.targets, prefill);
194
+ const current = state();
195
+ const selection = current ? groupSelection(current.settings, group) : undefined;
196
+ return chooseFileFor(inline, group.targets, selection?.kind === "uniform" && selection.sound?.startsWith("file:") ? selection.sound.slice(5) : "");
201
197
  }
202
198
  return false;
203
199
  },
200
+ }, group.name, sounds, () => {
201
+ const current = state();
202
+ if (!current) return undefined;
203
+ const selection = groupSelection(current.settings, group);
204
+ return selection.kind === "mixed" ? CUSTOM_SOUND : soundValue(selection.sound);
205
+ }, (sound, inline) => {
206
+ if (sound !== CUSTOM_SOUND) return setTargets(inline, group.targets, sound);
207
+ const current = state();
208
+ const selection = current ? groupSelection(current.settings, group) : undefined;
209
+ return chooseFileFor(inline, group.targets, selection?.kind === "uniform" && selection.sound?.startsWith("file:") ? selection.sound.slice(5) : "");
204
210
  });
205
211
  }
206
- rows.push({
212
+ choices({
207
213
  category,
208
214
  label: () => `Advanced: ${advanced ? "hide" : "show"} per-event exceptions`,
209
215
  preview: () => ({ title: "Advanced · per-event exceptions", sample: advanced ? "hiding folds the per-event rows again; the basic type choices are unaffected" : "reveals one-off per-event overrides; the basic type choices stay independent" }),
210
- action: () => { advanced = !advanced; },
211
- });
216
+ }, "Advanced", [{ value: false, label: "hidden" }, { value: true, label: "shown" }], () => advanced, value => { advanced = value; });
212
217
  const events = getNotificationService()?.getState().supportedEvents
213
218
  ?? NOTIFICATION_EVENTS.filter(event => event !== "session.shutdown");
214
219
  for (const event of events) {
215
- rows.push({
220
+ choices({
216
221
  category,
217
222
  visible: () => advanced,
218
223
  keyhint: SOUND_ROW_HINT,
219
224
  label: () => { const current = state(); const sound = current?.settings.audio.events[event] ?? null; return `${event}: ${sound === null ? "silence" : sound}`; },
220
225
  preview: () => {
221
226
  const sound = state()?.settings.audio.events[event] ?? null;
222
- return { title: `${event} · audio event`, sample: `selected: ${soundDescription(sound)} · Enter cycles silence/success/error/attention · f local sound · p test sound` };
223
- },
224
- action: async inline => {
225
- const service = serviceOrNotify();
226
- if (!service) return;
227
- const current = service.getState().settings.audio.events[event] ?? null;
228
- const index = SOUND_CYCLE.findIndex(candidate => candidate === current);
229
- const next = SOUND_CYCLE[(index + 1) % SOUND_CYCLE.length]!;
230
- await mutate(inline, settings => { settings.audio.events[event] = next; });
227
+ return { title: `${event} · audio event`, sample: `${event}: ${sound === null ? "silence" : sound} · ${soundDescription(sound)} · Enter applies the chosen option · f local sound · p test sound` };
231
228
  },
232
229
  key: (data, inline) => {
233
230
  if (matchesKey(data, "p")) { previewSound(getNotificationService()?.getState().settings.audio.events[event] ?? null); return true; }
234
- // Return the field/validation promise so the view keeps the card busy until it settles.
235
231
  if (matchesKey(data, "f")) return chooseFileFor(inline, [event], "");
236
232
  return false;
237
233
  },
238
- });
234
+ }, event, sounds, () => { const current = state(); return current ? soundValue(current.settings.audio.events[event] ?? null) : undefined; },
235
+ (sound, inline) => sound === CUSTOM_SOUND ? chooseFileFor(inline, [event], "") : setTargets(inline, [event], sound));
239
236
  }
240
237
  return rows;
241
238
  }
@@ -0,0 +1,22 @@
1
+ import type { ServiceTier } from "./model-routing-authority.ts";
2
+
3
+ // Conservative intersection of the installed catalog and OpenAI's Fast list.
4
+ const FAST_MODELS = new Set([
5
+ "gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra",
6
+ "gpt-6-astra", "gpt-6-sol", "gpt-6-luna", "gpt-6.1-sol", "gpt-6.1-terra",
7
+ ]);
8
+
9
+ export const PROFILE_TIER_EVENT = "gentle-pi:profile-tier";
10
+ export const CHILD_TIER_ENV = "GENTLE_PI_AGENT_SERVICE_TIER";
11
+
12
+ export function supportsOpenAIFast(model: { provider?: string; api?: string; id?: string } | null | undefined): boolean {
13
+ return !!model && typeof model.id === "string" && FAST_MODELS.has(model.id) && (
14
+ (model.provider === "openai" && model.api === "openai-responses") ||
15
+ (model.provider === "openai-codex" && model.api === "openai-codex-responses")
16
+ );
17
+ }
18
+
19
+ export function applyOpenAITier(payload: unknown, tier: ServiceTier | undefined, model: { provider?: string; api?: string; id?: string } | null | undefined): unknown {
20
+ if (!tier || !supportsOpenAIFast(model) || !payload || typeof payload !== "object" || Array.isArray(payload)) return undefined;
21
+ return { ...payload, service_tier: tier === "fast" ? "priority" : "default" };
22
+ }
@@ -12,6 +12,9 @@ export interface OrchestratorCandidate {
12
12
  * its schema-1 header heartbeats, but it never writes a discovery sidecar. */
13
13
  legacyLabel?: string;
14
14
  aliases?: DiscoveryMetadata["aliases"];
15
+ /** stateOnly selection: whether this peer published owner-curated state. Boolean
16
+ * only — curated state prose stays out of the default session list. */
17
+ statePublished?: boolean;
15
18
  workspace?: string;
16
19
  tasks?: DiscoveryMetadata["tasks"];
17
20
  omitted?: number;
@@ -27,7 +30,7 @@ export interface OrchestratorCandidate {
27
30
  /** One bounded metadata page, no thread reads or transport probes. The registry
28
31
  * selects a canonical routing activation; metadata must bind to that exact one.
29
32
  * Incomplete scans and duplicate presence headers fail closed. */
30
- export function discoverOrchestrators(profile: string, peers: readonly PresenceRecord[], now = Date.now(), selection?: { recipientSessionId?: string; cursor?: string; consultation?: boolean; includeWork?: boolean }): OrchestratorCandidate[] {
33
+ export function discoverOrchestrators(profile: string, peers: readonly PresenceRecord[], now = Date.now(), selection?: { recipientSessionId?: string; cursor?: string; consultation?: boolean; includeWork?: boolean; stateOnly?: boolean }): OrchestratorCandidate[] {
31
34
  const page = listPresence(profile, now);
32
35
  const ids = [...new Set(peers.map(peer => peer.sessionId))];
33
36
  return ids.filter(id => selection?.recipientSessionId === undefined || selection.recipientSessionId === id).map(sessionId => {
@@ -48,6 +51,7 @@ export function discoverOrchestrators(profile: string, peers: readonly PresenceR
48
51
  ...(selection?.consultation ? { publication: { incarnation: header.incarnation, activation: metadata.activation, heartbeat: header.heartbeat } } : {}),
49
52
  ...(selection?.includeWork && metadata.state?.sessionId === sessionId
50
53
  ? { workRecord: { work: metadata.state.state?.work ?? null, recordedAt: metadata.state.recordedAt } } : {}),
54
+ ...(selection?.stateOnly ? { statePublished: metadata.state?.sessionId === sessionId } : {}),
51
55
  ...(!selection?.includeWork && selection?.recipientSessionId === sessionId && metadata.state?.sessionId === sessionId ? { state: metadata.state } : {}) };
52
56
  });
53
57
  }
@@ -0,0 +1,75 @@
1
+ import { assistantErrorCategory } from "./agents-protocol.ts";
2
+ import { fallbackContinuePrompt, type FallbackChange } from "./model-fallback-notice.ts";
3
+ import { pickModel, shouldFallBack, type ModelCooldown } from "./model-fallback-policy.ts";
4
+ import type { FallbackChain } from "./model-fallback-store.ts";
5
+ import type { ThinkingLevel } from "./model-routing-authority.ts";
6
+
7
+ // The main session's fallback. Pi fires agent_end on every failed attempt and
8
+ // only then decides to retry, so the decision waits for agent_settled: the
9
+ // run's last attempt failed after Pi's own retries. Then the `orchestrator`
10
+ // chain of the session's profile picks the next model, the session switches
11
+ // to it and a message resumes the work. An episode lasts until a turn
12
+ // succeeds or the user aborts, so a chain is walked at most once.
13
+
14
+ export interface OrchestratorFallbackDeps {
15
+ chain(): FallbackChain;
16
+ /** `provider/id` of the session model, undefined when unknown. */
17
+ current(): string | undefined;
18
+ /** The model is in Pi's catalog and can be selected. */
19
+ available(model: string): boolean;
20
+ setModel(model: string): Promise<boolean>;
21
+ setThinking(level: ThinkingLevel): void;
22
+ /** The session's effort when the episode began: a step without its own effort runs at it. */
23
+ thinking(): ThinkingLevel | undefined;
24
+ announce(change: FallbackChange): void;
25
+ resume(message: string): void;
26
+ cooldown: ModelCooldown;
27
+ now(): number;
28
+ }
29
+
30
+ type AssistantLike = { role?: unknown; stopReason?: unknown; errorMessage?: unknown };
31
+
32
+ export function createOrchestratorFallback(deps: OrchestratorFallbackDeps) {
33
+ const tried = new Set<string>();
34
+ let episodeThinking: ThinkingLevel | undefined;
35
+ return {
36
+ /** Handles a settled run (its last attempt's messages); true when the session moved to a fallback and resumed. */
37
+ async onSettled(messages: readonly unknown[], settled: { aborted?: boolean } = {}): Promise<boolean> {
38
+ if (settled.aborted) {
39
+ // The user stopped the run: never resume it on another model.
40
+ tried.clear();
41
+ return false;
42
+ }
43
+ const last = [...messages].reverse().find((message) => (message as AssistantLike)?.role === "assistant") as AssistantLike | undefined;
44
+ const category = assistantErrorCategory(last);
45
+ if (category === undefined) {
46
+ // Success or an abort ends the episode.
47
+ tried.clear();
48
+ return false;
49
+ }
50
+ const chain = deps.chain();
51
+ if (!chain.length || !shouldFallBack(category)) return false;
52
+ const now = deps.now();
53
+ const current = deps.current();
54
+ if (tried.size === 0) episodeThinking = deps.thinking();
55
+ if (current) {
56
+ tried.add(current);
57
+ deps.cooldown.mark(current, category, now);
58
+ }
59
+ for (;;) {
60
+ const pick = pickModel(current, chain, { cooldown: deps.cooldown, now, tried });
61
+ if (!pick?.fallback || !pick.model) return false;
62
+ tried.add(pick.model);
63
+ if (!deps.available(pick.model)) continue;
64
+ // Pi may refuse or throw (an expired login): the next step gets its turn.
65
+ const switched = await deps.setModel(pick.model).catch(() => false);
66
+ if (!switched) continue;
67
+ const level = pick.thinking ?? episodeThinking;
68
+ if (level) deps.setThinking(level);
69
+ deps.announce({ agent: "orchestrator", from: current ?? "default", to: pick.model, category });
70
+ deps.resume(fallbackContinuePrompt(current, pick.model, category));
71
+ return true;
72
+ }
73
+ },
74
+ };
75
+ }
@@ -0,0 +1,113 @@
1
+ import { readFileSync, statSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { isAbsolute } from "node:path";
4
+ import { sniffImageMimeType, type ClipboardImage } from "./clipboard-image.ts";
5
+
6
+ // Some terminals hand an image over as a path instead of clipboard bytes.
7
+ // Herdr does this for a terminal on another machine: the desktop app and
8
+ // `herdr --remote` write the clipboard image to a temp file there and paste
9
+ // its path (`herdr-paste-*.png`, `client-N-clipboard-*.png`). Dropping an image
10
+ // on a Herdr pane, or copying files in a file manager, arrives the same way:
11
+ // quoted paths. A paste made only of image paths becomes chips like a
12
+ // clipboard image, so the model sees the picture instead of a path string.
13
+
14
+ const MAX_PASTED_PATHS = 8;
15
+ const MAX_PASTED_BYTES = 64 * 1024 * 1024;
16
+ const IMAGE_PATH_EXTENSIONS = [".png", ".jpg", ".jpeg", ".webp", ".gif"];
17
+
18
+ export interface PastedImagePathOptions {
19
+ /** Test seam: read a file's bytes. */
20
+ readFile?(path: string): Uint8Array;
21
+ /** Test seam: does a regular file exist at this path? */
22
+ isFile?(path: string): boolean;
23
+ /** Test seam: the home directory `~/` expands to. */
24
+ home?: string;
25
+ }
26
+
27
+ /**
28
+ * Whitespace-separated shell-like tokens. Herdr quotes each dropped file with
29
+ * single quotes and escapes an embedded quote as `'\''`; terminals that paste
30
+ * several files quote them the same way. Newlines separate tokens too.
31
+ */
32
+ export function parsePathTokens(text: string): string[] {
33
+ const tokens: string[] = [];
34
+ let current = "";
35
+ let started = false;
36
+ for (let index = 0; index < text.length; index += 1) {
37
+ const char = text[index];
38
+ if (/\s/.test(char)) {
39
+ if (started) { tokens.push(current); current = ""; started = false; }
40
+ continue;
41
+ }
42
+ started = true;
43
+ if (char === "'") {
44
+ // Close, escaped quote, reopen (`'\''`) is one literal quote.
45
+ for (index += 1; index < text.length; index += 1) {
46
+ if (text[index] !== "'") { current += text[index]; continue; }
47
+ if (text[index + 1] === "\\" && text[index + 2] === "'" && text[index + 3] === "'") {
48
+ current += "'";
49
+ index += 3;
50
+ continue;
51
+ }
52
+ break;
53
+ }
54
+ continue;
55
+ }
56
+ if (char === '"') {
57
+ for (index += 1; index < text.length; index += 1) {
58
+ if (text[index] === "\\" && (text[index + 1] === '"' || text[index + 1] === "\\")) { current += text[index + 1]; index += 1; continue; }
59
+ if (text[index] === '"') break;
60
+ current += text[index];
61
+ }
62
+ continue;
63
+ }
64
+ if (char === "\\" && index + 1 < text.length) { current += text[index + 1]; index += 1; continue; }
65
+ current += char;
66
+ }
67
+ if (started) tokens.push(current);
68
+ return tokens;
69
+ }
70
+
71
+ /** Absolute path for one token, or undefined when it cannot name a local file. */
72
+ function resolveToken(token: string, home: string): string | undefined {
73
+ if (/[\u0000-\u001f\u007f]/.test(token)) return undefined;
74
+ let path = token;
75
+ if (path.startsWith("file://")) {
76
+ try { path = decodeURIComponent(path.slice("file://".length)); } catch { return undefined; }
77
+ }
78
+ if (path === "~") path = home;
79
+ else if (path.startsWith("~/")) path = `${home}${path.slice(1)}`;
80
+ return isAbsolute(path) ? path : undefined;
81
+ }
82
+
83
+ /**
84
+ * Images from a paste whose entire text is image paths, in paste order.
85
+ * Anything else — text, a sentence that mentions a path, a missing or
86
+ * unsupported file — returns [] so Pi's own paste handler runs unchanged.
87
+ */
88
+ export function readPastedImagePaths(text: string, options: PastedImagePathOptions = {}): ClipboardImage[] {
89
+ const tokens = parsePathTokens(text);
90
+ if (tokens.length === 0 || tokens.length > MAX_PASTED_PATHS) return [];
91
+ const home = options.home ?? homedir();
92
+ const readFile = options.readFile ?? ((path: string) => readFileSync(path));
93
+ const isFile = options.isFile ?? ((path: string) => {
94
+ try {
95
+ const stat = statSync(path);
96
+ return stat.isFile() && stat.size > 0 && stat.size <= MAX_PASTED_BYTES;
97
+ } catch { return false; }
98
+ });
99
+ const images: ClipboardImage[] = [];
100
+ for (const token of tokens) {
101
+ const path = resolveToken(token, home);
102
+ if (!path || !IMAGE_PATH_EXTENSIONS.some((extension) => path.toLowerCase().endsWith(extension))) return [];
103
+ if (!isFile(path)) return [];
104
+ let bytes: Uint8Array;
105
+ try { bytes = readFile(path); } catch { return []; }
106
+ if (bytes.length === 0 || bytes.length > MAX_PASTED_BYTES) return [];
107
+ // The extension only narrows the candidates; the bytes decide the type.
108
+ const mimeType = sniffImageMimeType(bytes);
109
+ if (!mimeType) return [];
110
+ images.push({ bytes, mimeType });
111
+ }
112
+ return images;
113
+ }