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.
- package/README.md +9 -6
- package/assets/agents/gentle-ai-verify.md +4 -0
- package/assets/agents/gentle-ai-worker.md +1 -0
- package/assets/migrations/agent-body-history.json +147 -0
- package/assets/orchestrator-delegation-reference.md +3 -3
- package/assets/orchestrator-delegation.md +2 -2
- package/assets/orchestrator-verification.md +10 -6
- package/assets/orchestrator.md +8 -8
- package/bin/gentle-shell.mjs +61 -26
- package/docs/ci-performance.md +11 -0
- package/docs/delegated-verification.md +6 -0
- package/docs/fast-mode.md +15 -0
- package/docs/gentle-agents-activity.md +8 -0
- package/docs/gentle-music.md +6 -3
- package/docs/gentle-shell.md +70 -20
- package/docs/install-wizard.md +1 -1
- package/docs/mcp-status.md +52 -0
- package/docs/prompt-budget.md +28 -0
- package/docs/readme-reference.md +82 -21
- package/docs/session-profile-format.md +20 -5
- package/docs/sound-notifications.md +1 -1
- package/docs/star-prompt.md +32 -0
- package/docs/work-continuity.md +46 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/codegraph-tools.ts +38 -4
- package/extensions/gentle-agents.ts +477 -50
- package/extensions/gentle-ai.ts +1046 -191
- package/extensions/gentle-fast.ts +61 -0
- package/extensions/gentle-guide.ts +174 -0
- package/extensions/gentle-herdr-activity.ts +21 -1
- package/extensions/gentle-herdr-agent.ts +144 -0
- package/extensions/gentle-music.ts +10 -0
- package/extensions/gentle-program-identity.ts +61 -0
- package/extensions/gentle-shell.ts +642 -97
- package/extensions/gentle-star-prompt.ts +334 -0
- package/extensions/gentle-stats.ts +5 -5
- package/extensions/gentle-todo.ts +42 -22
- package/extensions/history/store.ts +18 -12
- package/extensions/skill-registry.ts +35 -3
- package/extensions/startup-banner.ts +39 -7
- package/lib/agent-assets.ts +74 -17
- package/lib/agent-profiles.ts +1 -1
- package/lib/agents-config.ts +12 -3
- package/lib/agents-keys.ts +8 -16
- package/lib/agents-protocol.ts +80 -4
- package/lib/agents-runner.ts +105 -4
- package/lib/agents-view.ts +6 -1
- package/lib/agents-widget.ts +132 -9
- package/lib/bridge-cost.ts +28 -0
- package/lib/codemode-renderer.ts +16 -0
- package/lib/command-palette-catalog.ts +1 -0
- package/lib/command-palette.ts +21 -8
- package/lib/exploration-budget.ts +62 -0
- package/lib/gentle-guide.ts +201 -0
- package/lib/gentle-shell-launcher.ts +4 -0
- package/lib/herdr-activity.ts +9 -3
- package/lib/herdr-task-summary-policy.ts +85 -0
- package/lib/inprocess-reviewer.ts +33 -13
- package/lib/jobs-sidebar-state.ts +5 -6
- package/lib/jobs-widget.ts +16 -52
- package/lib/keymaps-customize.ts +81 -0
- package/lib/keymaps.ts +291 -0
- package/lib/model-fallback-notice.ts +61 -0
- package/lib/model-fallback-policy.ts +141 -0
- package/lib/model-fallback-store.ts +143 -0
- package/lib/model-routing-authority.ts +10 -2
- package/lib/nan-provider.ts +3 -2
- package/lib/native-review-cli.ts +7 -2
- package/lib/notification-customize.ts +48 -51
- package/lib/openai-fast-tier.ts +22 -0
- package/lib/orchestrator-discovery.ts +5 -1
- package/lib/orchestrator-fallback.ts +75 -0
- package/lib/pasted-image-paths.ts +113 -0
- package/lib/questionnaire/questionnaire-view.ts +121 -7
- package/lib/review-candidate-view-owner.ts +4 -0
- package/lib/review-candidate-view.ts +10 -7
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +22 -7
- package/lib/review-repository.ts +5 -0
- package/lib/session-profile-append-controller.ts +21 -6
- package/lib/session-profile-authority.ts +119 -0
- package/lib/session-profile-binding.ts +54 -5
- package/lib/session-profile-freeze.ts +105 -9
- package/lib/session-profile-integration.ts +313 -0
- package/lib/session-profile-persistence.ts +63 -9
- package/lib/shell-bar.ts +171 -56
- package/lib/shell-card.ts +26 -6
- package/lib/shell-page.ts +120 -0
- package/lib/shell-panel.ts +149 -0
- package/lib/shell-prompt.ts +53 -1
- package/lib/shell-sidebar-layout.ts +98 -25
- package/lib/shell-sidebar.ts +54 -1
- package/lib/shell-stats.ts +123 -0
- package/lib/shell-todo.ts +71 -0
- package/lib/shell-usage.ts +12 -2
- package/lib/star-prompt.ts +197 -0
- package/lib/verifier-admission.ts +18 -8
- package/lib/verifier-settle-reminder.ts +64 -0
- package/lib/vim-editor-adapter.ts +6 -1
- package/lib/visual-customization-policy.ts +41 -6
- package/lib/visual-customize-view.ts +164 -26
- package/lib/visual-layout-preview.ts +43 -0
- package/lib/yolo-session-policy.ts +28 -1
- package/package.json +1 -1
- package/runtime/gentle-shell-launcher.mjs +4 -0
- package/runtime/native-review-cli.mjs +7 -2
- package/runtime/review-integration-v2.mjs +22 -7
- package/runtime/windows-session-transport.ps1 +60 -3
- package/scripts/bootstrap.sh +4 -1
- package/scripts/installer-preflight.mjs +1 -1
- package/scripts/pi-update.mjs +113 -3
- package/scripts/run-test-suite.mjs +17 -1
- package/scripts/shell-snapshot.mjs +340 -0
- package/scripts/test-packed-runner.mjs +1 -1
- package/scripts/update-agent-body-history.mjs +41 -0
- package/scripts/verify-installer-tap.mjs +45 -0
- package/scripts/verify-package-files.mjs +2 -0
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/tui-design/NOTICE.md +5 -0
- package/skills/tui-design/SKILL.md +56 -0
- package/skills/tui-design/references/commands.md +75 -0
- package/skills/tui-design/references/critique.md +48 -0
- package/skills/tui-design/references/design-doc.md +44 -0
- package/skills/tui-design/references/terminal-craft.md +64 -0
- package/skills/tui-design/references/visual-loop.md +32 -0
- package/tests/agents-protocol.test.ts +53 -1
- package/tests/agents-runner.test.ts +168 -3
- package/tests/agents-view.test.ts +27 -0
- package/tests/agents-widget.test.ts +312 -10
- package/tests/bounded-scan-contract.test.ts +39 -0
- package/tests/bridge-cost.test.ts +32 -0
- package/tests/bundled-install.test.ts +6 -4
- package/tests/ci-concurrency.test.ts +11 -0
- package/tests/ci-merge-base-identity.test.ts +114 -0
- package/tests/codegraph-tools.test.ts +69 -0
- package/tests/codemode-rendering.test.ts +22 -2
- package/tests/command-palette.test.ts +16 -2
- package/tests/commit-slice-signal.test.ts +11 -9
- package/tests/delegate-for-reason-contract.test.ts +5 -4
- package/tests/design-canvas-server.test.ts +6 -2
- package/tests/exploration-budget.test.ts +128 -0
- package/tests/fixtures/agent-assets/gentle-ai-worker.strict-tdd-era.md +122 -0
- package/tests/fixtures/measure-orchestrator-prompt.mjs +2 -1
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +18 -10
- package/tests/fixtures/session-profile-v1/replay.ts +125 -0
- package/tests/fixtures/session-profile-v1/session-profile-authority.ts +113 -0
- package/tests/fixtures/session-profile-v1/session-profile-binding.ts +83 -0
- package/tests/fixtures/session-profile-v1/session-profile-disk-reader.ts +182 -0
- package/tests/fixtures/session-profile-v1/session-profile-freeze.ts +290 -0
- package/tests/fixtures/session-profile-v1/session-profile-persistence.ts +195 -0
- package/tests/fixtures/session-profile-v1/v1-inputs.ts +16 -0
- package/tests/fixtures/windows-pipe-availability.ps1 +26 -0
- package/tests/fixtures/windows-session-bootstrap.ps1 +6 -2
- package/tests/gentle-agents.test.ts +416 -21
- package/tests/gentle-ai-exploration-budget.test.ts +135 -0
- package/tests/gentle-ai.test.ts +1011 -37
- package/tests/gentle-fast.test.ts +73 -0
- package/tests/gentle-guide.test.ts +208 -0
- package/tests/gentle-herdr-activity.test.ts +76 -2
- package/tests/gentle-herdr-agent.test.ts +111 -0
- package/tests/gentle-music.test.ts +36 -1
- package/tests/gentle-program-identity.test.ts +197 -0
- package/tests/gentle-shell-bin.test.ts +49 -26
- package/tests/gentle-shell-launcher.test.ts +18 -2
- package/tests/gentle-shell.test.ts +1068 -37
- package/tests/gentle-stats.test.ts +15 -2
- package/tests/gentle-todo.test.ts +50 -4
- package/tests/herdr-task-summary-policy.test.ts +128 -0
- package/tests/history-store-private-mode.test.ts +40 -0
- package/tests/image-paste-chips.test.ts +42 -0
- package/tests/inprocess-reviewer.test.ts +122 -0
- package/tests/installer-posix-bootstrap.test.ts +67 -5
- package/tests/installer-server.test.ts +2 -2
- package/tests/installer-windows-diagnostics.test.ts +4 -5
- package/tests/isolated-config-home.ts +28 -0
- package/tests/jobs-widget.test.ts +25 -37
- package/tests/keymaps-customize.test.ts +114 -0
- package/tests/keymaps.test.ts +103 -0
- package/tests/maintainer/mcp-status.maintest.ts +88 -0
- package/tests/maintainer/pi-update-source.maintest.ts +116 -0
- package/tests/model-fallback-notice.test.ts +45 -0
- package/tests/model-fallback-policy.test.ts +83 -0
- package/tests/model-fallback-store.test.ts +111 -0
- package/tests/nan-provider.test.ts +4 -4
- package/tests/no-self-pause-contract.test.ts +19 -0
- package/tests/notification-customize.test.ts +58 -34
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/odd-routing-contract.test.ts +1 -1
- package/tests/orchestrator-fallback.test.ts +82 -0
- package/tests/orchestrator-prompt-budget.test.ts +131 -0
- package/tests/package-manifest.test.ts +160 -7
- package/tests/pasted-image-paths.test.ts +118 -0
- package/tests/persona-reply-language.test.ts +61 -0
- package/tests/pi-update-launcher.test.ts +32 -8
- package/tests/pi-update-source.test.ts +162 -0
- package/tests/profile-fast-tier.test.ts +311 -0
- package/tests/profile-tier-footer.test.ts +79 -0
- package/tests/questionnaire-view.test.ts +150 -0
- package/tests/review-candidate-owner-sweep.test.ts +93 -0
- package/tests/review-candidate-view.test.ts +51 -0
- package/tests/review-controller-native-routing.test.ts +120 -6
- package/tests/review-gate.test.ts +24 -0
- package/tests/review-inspect-preflight.test.ts +197 -0
- package/tests/review-integration-v2-forward.test.ts +59 -0
- package/tests/review-repository.test.ts +52 -1
- package/tests/review-sidebar-state.test.ts +5 -5
- package/tests/run-test-suite.test.ts +61 -5
- package/tests/sensitive-path-tools.test.ts +74 -0
- package/tests/session-profile-append-controller.test.ts +63 -0
- package/tests/session-profile-authority.test.ts +259 -0
- package/tests/session-profile-binding.test.ts +15 -0
- package/tests/session-profile-extension.test.ts +615 -0
- package/tests/session-profile-freeze.test.ts +110 -2
- package/tests/session-profile-integration.test.ts +857 -0
- package/tests/session-profile-persistence.test.ts +57 -0
- package/tests/session-profile-v1-compat.test.ts +221 -0
- package/tests/shell-bar.test.ts +113 -55
- package/tests/shell-card.test.ts +13 -1
- package/tests/shell-page.test.ts +108 -0
- package/tests/shell-panel.test.ts +332 -0
- package/tests/shell-prompt.test.ts +54 -0
- package/tests/shell-render-cache.test.ts +5 -0
- package/tests/shell-sidebar-fullscreen.test.ts +12 -0
- package/tests/shell-sidebar-layout.test.ts +159 -27
- package/tests/shell-stats.test.ts +90 -0
- package/tests/shell-usage.test.ts +14 -0
- package/tests/skill-registry.test.ts +68 -1
- package/tests/star-prompt.test.ts +470 -0
- package/tests/startup-banner.test.ts +57 -1
- package/tests/task-size-routing-contract.test.ts +45 -1
- package/tests/verifier-settle-reminder.test.ts +281 -0
- package/tests/verify-first-launch-contract.test.ts +56 -5
- package/tests/verify-installer-tap.test.ts +57 -0
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/visual-customization-policy.test.ts +61 -7
- package/tests/visual-customize-view.test.ts +253 -8
- package/tests/visual-layout-preview.test.ts +28 -0
- package/tests/windows-session-bootstrap.test.ts +105 -2
- package/tests/work-continuity-contract.test.ts +86 -0
- package/tests/writer-surfaces.test.ts +12 -10
- package/tests/yolo-customize.test.ts +30 -11
- package/tests/yolo-mode-runtime.test.ts +4 -2
- package/tests/yolo-mode.test.ts +16 -2
package/lib/agents-widget.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { visibleWidth } from "@earendil-works/pi-tui";
|
|
|
2
2
|
import { isFinished, TASK_STATUS, type TaskRecord, type TaskStatus } from "./agents-protocol.ts";
|
|
3
3
|
import { formatCost, formatTokens } from "./shell-bar.ts";
|
|
4
4
|
import { paintHoverable } from "./shell-hover.ts";
|
|
5
|
-
import { CARD_TONE, panelExtraRows, panelInnerWidth, renderCard, type CardTheme, type CardTone } from "./shell-card.ts";
|
|
5
|
+
import { CARD_TONE, paintSurfaceRow, panelExtraRows, panelHeaderRow, panelInnerWidth, renderCard, surfaceOpener, type CardTheme, type CardTone } from "./shell-card.ts";
|
|
6
|
+
import { fitPanelLine, PANEL_ROW_INDENT, renderPanelHeader, renderPanelRow } from "./shell-panel.ts";
|
|
6
7
|
|
|
7
8
|
// Gentle Agents widget: the card above the editor. Reads task records only
|
|
8
9
|
// (status, prompt, counters, timestamps), so drawing it costs nothing per
|
|
@@ -22,6 +23,10 @@ export interface AgentsWidgetOptions {
|
|
|
22
23
|
// same control the Todos card carries; hovered paints its hover role.
|
|
23
24
|
collapseControl?: boolean;
|
|
24
25
|
hovered?: boolean;
|
|
26
|
+
/** Physical row under the pointer, including the header and panel chrome. */
|
|
27
|
+
hoveredRow?: number;
|
|
28
|
+
/** Publish the physical rows actually occupied by individual agents. */
|
|
29
|
+
onAgentRow?: (row: number) => void;
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
interface StatusLook {
|
|
@@ -252,21 +257,28 @@ function columns(tasks: readonly TaskRecord[], inner: number, now: number): Colu
|
|
|
252
257
|
return { inner, name, meta: Math.max(0, Math.min(inner - fixed, narrow)), task: 0, columnar: false };
|
|
253
258
|
}
|
|
254
259
|
|
|
255
|
-
function row(task: TaskRecord, theme: CardTheme, cols: Columns, now: number, allowMetadataRow: boolean): string[] {
|
|
260
|
+
function row(task: TaskRecord, theme: CardTheme, cols: Columns, now: number, allowMetadataRow: boolean, hoveredRow?: number): string[] {
|
|
256
261
|
const look = LOOK[task.status];
|
|
257
262
|
const name = clip(task.agent, cols.name);
|
|
258
|
-
const
|
|
263
|
+
const paint = (role: string, text: string, index: number) => paintHoverable(theme, text, hoveredRow === index, role);
|
|
264
|
+
const head = `${theme.fg(look.role, look.glyph)}${GLYPH_GAP}${paint(NAME_ROLE, name, 0)}${" ".repeat(cols.name - visibleWidth(name))}`;
|
|
259
265
|
const metadata = cols.columnar && cols.metaWidths ? metaRowText(task, now, cols.metaWidths) : task.status === TASK_STATUS.QUEUED ? clip("queued", cols.meta) : executionLabel(task, cols.meta);
|
|
260
|
-
const tail =
|
|
266
|
+
const tail = paint(META_ROLE, " ".repeat(Math.max(0, cols.meta - visibleWidth(metadata))) + metadata, 0);
|
|
261
267
|
if (cols.inner < 3) return [theme.fg(look.role, clip(look.glyph, cols.inner))];
|
|
262
268
|
// The scrollable sidebar can preserve identity and execution metadata on
|
|
263
269
|
// separate rows. The height-capped above-editor widget keeps its row budget.
|
|
264
|
-
if (
|
|
265
|
-
|
|
270
|
+
if (cols.task === 0) {
|
|
271
|
+
const separateMetadata = allowMetadataRow && !cols.columnar && task.status !== TASK_STATUS.QUEUED && visibleWidth(executionLabel(task)) > cols.meta;
|
|
272
|
+
const activity = clip(taskText(task), cols.inner);
|
|
273
|
+
const hasActivity = allowMetadataRow && Boolean(activity);
|
|
274
|
+
const rows = separateMetadata
|
|
275
|
+
? [head, paint(META_ROLE, executionLabel(task, cols.inner), hasActivity ? 2 : 1)]
|
|
276
|
+
: [`${head}${" ".repeat(Math.max(0, cols.inner - visibleWidth(head) - visibleWidth(tail)))}${tail}`];
|
|
277
|
+
if (hasActivity) rows.splice(1, 0, paint(TASK_ROLE, activity, 1));
|
|
278
|
+
return rows;
|
|
266
279
|
}
|
|
267
|
-
if (cols.task === 0) return [`${head}${" ".repeat(Math.max(0, cols.inner - visibleWidth(head) - visibleWidth(tail)))}${tail}`];
|
|
268
280
|
const text = clip(taskText(task), cols.task);
|
|
269
|
-
return [`${head}${COLUMN_GAP}${
|
|
281
|
+
return [`${head}${COLUMN_GAP}${paint(TASK_ROLE, text, 0)}${" ".repeat(cols.task - visibleWidth(text))}${COLUMN_GAP}${tail}`];
|
|
270
282
|
}
|
|
271
283
|
|
|
272
284
|
function counts(tasks: readonly TaskRecord[]): string {
|
|
@@ -318,7 +330,13 @@ export function renderAgentsCard(tasks: readonly TaskRecord[], theme: CardTheme,
|
|
|
318
330
|
const maxRows = options.maxRows === undefined ? undefined : options.maxRows - extraRows;
|
|
319
331
|
const { listed, hidden } = options.collapsed ? { listed: [shown[0]], hidden: 0 } : visibleRows(shown, maxRows, extraRows > 0);
|
|
320
332
|
const hint = options.collapsed && options.collapseKey ? `${options.collapseKey} expand` : shown.length > 1 ? batchElapsed(shown, now) : undefined;
|
|
321
|
-
|
|
333
|
+
let bodyRow = panelHeaderRow(theme, width, tone(shown)) + 1 + (extraRows > 0 ? 1 : 0);
|
|
334
|
+
const body = listed.flatMap((task) => {
|
|
335
|
+
const rows = row(task, theme, cols, now, options.maxRows === undefined, options.hoveredRow === undefined ? undefined : options.hoveredRow - bodyRow);
|
|
336
|
+
for (let index = 0; index < rows.length; index++) options.onAgentRow?.(bodyRow + index);
|
|
337
|
+
bodyRow += rows.length;
|
|
338
|
+
return rows;
|
|
339
|
+
});
|
|
322
340
|
if (hidden > 0) body.push(overflowRow(hidden, theme, options.viewKey));
|
|
323
341
|
const icon = options.collapsed ? "▸" : "▾";
|
|
324
342
|
const control = `${icon} ${width >= 28 ? (options.collapsed ? "Expand" : "Collapse") : ""}`.trimEnd();
|
|
@@ -330,3 +348,108 @@ export function renderAgentsCard(tasks: readonly TaskRecord[], theme: CardTheme,
|
|
|
330
348
|
{ expanded: true, hint, panel: true },
|
|
331
349
|
);
|
|
332
350
|
}
|
|
351
|
+
|
|
352
|
+
// The fullscreen rail's panel section (design/shell-rework/06-many-agents.html):
|
|
353
|
+
// one row per agent with the task first, then the agent kind and its tokens and
|
|
354
|
+
// time, ordered by what needs you (waiting, running, queued, failed); finished
|
|
355
|
+
// and cancelled work fold into one row each, and a long list keeps its first
|
|
356
|
+
// rows and counts the rest.
|
|
357
|
+
const SECTION_ROWS = 8;
|
|
358
|
+
const KIND_MAX = 10;
|
|
359
|
+
const AGENTS_VIEW = "/gentle:agents";
|
|
360
|
+
const SECTION_ORDER: TaskStatus[] = [TASK_STATUS.WAITING, TASK_STATUS.RUNNING, TASK_STATUS.QUEUED, TASK_STATUS.FAILED, TASK_STATUS.TIMED_OUT];
|
|
361
|
+
const SECTION_TEXT_ROLE: Partial<Record<TaskStatus, string>> = { [TASK_STATUS.WAITING]: "warning", [TASK_STATUS.QUEUED]: "muted", [TASK_STATUS.FAILED]: "error", [TASK_STATUS.TIMED_OUT]: "error" };
|
|
362
|
+
|
|
363
|
+
function agentKind(agent: string): string {
|
|
364
|
+
return agent.replace(/^gentle-ai-/, "");
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function sectionRight(task: TaskRecord, now: number): string {
|
|
368
|
+
if (task.status === TASK_STATUS.WAITING) return "asks you";
|
|
369
|
+
if (task.status === TASK_STATUS.QUEUED) return "queued";
|
|
370
|
+
if (task.status === TASK_STATUS.FAILED) return `failed ${elapsed(task, now)}`;
|
|
371
|
+
if (task.status === TASK_STATUS.TIMED_OUT) return `timed out ${elapsed(task, now)}`;
|
|
372
|
+
return [task.tokens > 0 ? formatTokens(task.tokens) : "", elapsed(task, now)].filter(Boolean).join(" ");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function sectionCount(shown: readonly TaskRecord[]): string {
|
|
376
|
+
const count = (status: TaskStatus) => shown.filter((task) => task.status === status).length;
|
|
377
|
+
const live = ([[TASK_STATUS.RUNNING, "running"], [TASK_STATUS.WAITING, "waiting"]] as const)
|
|
378
|
+
.map(([status, label]) => [count(status), label] as const).filter(([n]) => n > 0).map(([n, label]) => `${n} ${label}`);
|
|
379
|
+
if (live.length > 0) return live.join(" · ");
|
|
380
|
+
const rest = ([[TASK_STATUS.QUEUED, "queued"], [TASK_STATUS.FAILED, "failed"], [TASK_STATUS.COMPLETED, "done"]] as const)
|
|
381
|
+
.map(([status, label]) => [count(status), label] as const).filter(([n]) => n > 0).map(([n, label]) => `${n} ${label}`);
|
|
382
|
+
return rest.length > 0 ? rest.join(" · ") : "idle";
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export function renderAgentsSection(tasks: readonly TaskRecord[], theme: CardTheme, width: number, now: number, options: Pick<AgentsWidgetOptions, "collapsed" | "hovered" | "hoveredRow" | "onAgentRow">): string[] {
|
|
386
|
+
const shown = widgetTasks(tasks, now);
|
|
387
|
+
const header = renderPanelHeader(theme, width, { title: "Agents", count: sectionCount(shown), open: !options.collapsed, hovered: options.hovered });
|
|
388
|
+
if (shown.length === 0) return [header, renderPanelRow(width, theme.fg(META_ROLE, `none running · ${AGENTS_VIEW}`))];
|
|
389
|
+
const ordered = SECTION_ORDER.flatMap((status) => shown.filter((task) => task.status === status).sort(startOrder));
|
|
390
|
+
const summaries = ([[TASK_STATUS.COMPLETED, "done"], [TASK_STATUS.CANCELLED, "cancelled"]] as const)
|
|
391
|
+
.map(([status, label]) => [shown.filter((task) => task.status === status).length, status, label] as const)
|
|
392
|
+
.filter(([n]) => n > 0)
|
|
393
|
+
.map(([n, status, label], index) => renderPanelRow(width, `${theme.fg(LOOK[status].role, LOOK[status].glyph)} ${theme.fg(META_ROLE, `${n} ${label}${index === 0 ? ` · ${AGENTS_VIEW}` : ""}`)}`));
|
|
394
|
+
const fits = ordered.length + summaries.length <= SECTION_ROWS;
|
|
395
|
+
const listed = fits ? ordered : ordered.slice(0, Math.max(0, SECTION_ROWS - 1 - summaries.length));
|
|
396
|
+
const kindWidth = Math.min(KIND_MAX, Math.max(0, ...listed.map((task) => visibleWidth(agentKind(task.agent)))));
|
|
397
|
+
const rightWidth = Math.max(0, ...listed.map((task) => visibleWidth(sectionRight(task, now))));
|
|
398
|
+
const taskWidth = Math.max(1, width - PANEL_ROW_INDENT - 2 - 1 - kindWidth - 1 - rightWidth);
|
|
399
|
+
const rows = listed.map((task, index) => {
|
|
400
|
+
if (!options.collapsed || index === 0) options.onAgentRow?.(index + 1);
|
|
401
|
+
const look = LOOK[task.status];
|
|
402
|
+
const hovered = options.hoveredRow === index + 1;
|
|
403
|
+
const paint = (role: string, text: string) => paintHoverable(theme, text, hovered, role);
|
|
404
|
+
// A run that moved to a fallback model is marked in its own task column,
|
|
405
|
+
// the flexible one, so the shared kind and right columns never change;
|
|
406
|
+
// the task stays first and the model follows when there is room.
|
|
407
|
+
const text = clip(task.fallbackFrom ? `↪ ${taskText(task)} · ${task.model.slice(task.model.lastIndexOf("/") + 1)}` : taskText(task), taskWidth);
|
|
408
|
+
const kind = clip(agentKind(task.agent), kindWidth);
|
|
409
|
+
const left = `${theme.fg(look.role, look.glyph)} ${paint(SECTION_TEXT_ROLE[task.status] ?? NAME_ROLE, text)}${" ".repeat(taskWidth - visibleWidth(text))} ${paint(TASK_ROLE, kind)}`;
|
|
410
|
+
return renderPanelRow(width, left, paint(META_ROLE, sectionRight(task, now).padStart(rightWidth)));
|
|
411
|
+
});
|
|
412
|
+
if (!fits) rows.push(renderPanelRow(width, theme.fg(META_ROLE, `${ELLIPSIS} ${ordered.length - listed.length} more · ${AGENTS_VIEW}`)));
|
|
413
|
+
const body = [...rows, ...summaries];
|
|
414
|
+
return [header, ...(options.collapsed ? body.slice(0, 1) : body)];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// The "needs you" row above the editor in the wide IDE chrome: the first agent
|
|
418
|
+
// waiting on a question relayed to this session's UI (TASK_EVENT.ASK, whose
|
|
419
|
+
// lastStep reads "asked: <title>"), and how many more wait.
|
|
420
|
+
const ALERT_SURFACE_ROLE = "selectedBg";
|
|
421
|
+
|
|
422
|
+
export function renderAgentsAlert(tasks: readonly TaskRecord[], theme: CardTheme, width: number): string[] {
|
|
423
|
+
const waiting = tasks.filter((task) => task.status === TASK_STATUS.WAITING).sort(startOrder);
|
|
424
|
+
const first = waiting[0];
|
|
425
|
+
if (!first) return [];
|
|
426
|
+
const target = Math.max(0, Math.floor(width));
|
|
427
|
+
const left = `${theme.fg("warning", "?")} ${theme.fg("warning", agentKind(first.agent))} ${theme.fg(NAME_ROLE, first.lastStep)}`;
|
|
428
|
+
const right = theme.fg(META_ROLE, `${waiting.length > 1 ? `+${waiting.length - 1} more · ` : ""}${AGENTS_VIEW}`);
|
|
429
|
+
return [paintSurfaceRow(` ${fitPanelLine(left, right, Math.max(0, target - 2))} `, surfaceOpener(theme, ALERT_SURFACE_ROLE))];
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/** What started subagents spent, for the Stats section; undefined before the first one starts. */
|
|
433
|
+
export function agentsSpend(tasks: readonly TaskRecord[]): { runs: number; tokens: number; cost: number } | undefined {
|
|
434
|
+
const started = tasks.filter((task) => task.status !== TASK_STATUS.QUEUED);
|
|
435
|
+
if (started.length === 0) return undefined;
|
|
436
|
+
return {
|
|
437
|
+
runs: started.length,
|
|
438
|
+
tokens: started.reduce((sum, task) => sum + (Number.isFinite(task.tokens) && task.tokens > 0 ? task.tokens : 0), 0),
|
|
439
|
+
cost: started.reduce((sum, task) => sum + (Number.isFinite(task.cost) && task.cost > 0 ? task.cost : 0), 0),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** The mobile work row's digest of live agents: how many run, wait for the user, and failed; undefined when none is live. */
|
|
444
|
+
export function agentsSummary(tasks: readonly TaskRecord[], theme: CardTheme, now: number): { left: string; priority: number } | undefined {
|
|
445
|
+
const shown = widgetTasks(tasks, now);
|
|
446
|
+
const live = shown.filter((task) => !isFinished(task.status)).length;
|
|
447
|
+
const waiting = shown.filter((task) => task.status === TASK_STATUS.WAITING).length;
|
|
448
|
+
const failed = shown.filter((task) => task.status === TASK_STATUS.FAILED || task.status === TASK_STATUS.TIMED_OUT).length;
|
|
449
|
+
const parts = [
|
|
450
|
+
live ? `${theme.fg("accent", LOOK[TASK_STATUS.RUNNING].glyph)} ${theme.fg("accent", `${live} ${live === 1 ? "agent" : "agents"}`)}` : "",
|
|
451
|
+
waiting ? theme.fg("warning", `? ${waiting} waiting`) : "",
|
|
452
|
+
failed ? theme.fg("error", `✗ ${failed}`) : "",
|
|
453
|
+
].filter(Boolean);
|
|
454
|
+
return live || failed ? { left: parts.join(theme.fg(META_ROLE, " · ")), priority: 1 } : undefined;
|
|
455
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { calculateCost, type Model, type Usage } from "@earendil-works/pi-ai";
|
|
2
|
+
|
|
3
|
+
// pi-claude-bridge serves Claude Code on a Claude subscription and registers every
|
|
4
|
+
// model with a zero price, so each turn it records costs $0. Pricing those turns at
|
|
5
|
+
// the Anthropic list price gives the API-equivalent spend: what the same tokens would
|
|
6
|
+
// cost on the API, not what the subscription bills.
|
|
7
|
+
export const CLAUDE_BRIDGE_PROVIDER = "claude-bridge";
|
|
8
|
+
const LIST_PRICE_PROVIDER = "anthropic";
|
|
9
|
+
|
|
10
|
+
type CatalogCost = Model<never>["cost"];
|
|
11
|
+
type PricedMessage = { role?: unknown; provider?: unknown; model?: unknown; usage?: Usage };
|
|
12
|
+
|
|
13
|
+
/** Returns a copy of a zero-cost claude-bridge assistant message priced from the
|
|
14
|
+
* catalog, or undefined when the message is not one or the catalog has no price. */
|
|
15
|
+
export function priceBridgeMessage<T extends PricedMessage>(
|
|
16
|
+
message: T,
|
|
17
|
+
findCost: (provider: string, modelId: string) => CatalogCost | undefined,
|
|
18
|
+
): T | undefined {
|
|
19
|
+
if (message.role !== "assistant" || message.provider !== CLAUDE_BRIDGE_PROVIDER || typeof message.model !== "string") return undefined;
|
|
20
|
+
const usage = message.usage;
|
|
21
|
+
// A bridge that reports its own cost wins.
|
|
22
|
+
if (!usage?.cost || usage.cost.total !== 0) return undefined;
|
|
23
|
+
const cost = findCost(LIST_PRICE_PROVIDER, message.model);
|
|
24
|
+
if (!cost) return undefined;
|
|
25
|
+
const priced: Usage = { ...usage, cost: { ...usage.cost } };
|
|
26
|
+
calculateCost({ cost } as Model<never>, priced);
|
|
27
|
+
return { ...message, usage: priced };
|
|
28
|
+
}
|
package/lib/codemode-renderer.ts
CHANGED
|
@@ -124,9 +124,25 @@ class CodemodeCard implements Component {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/** Replace presentation only: execute, schema and every loadout/exposure field retain their references. */
|
|
127
|
+
/**
|
|
128
|
+
* Appended after Pi's own codemode guideline, which only says to batch calls.
|
|
129
|
+
* Pi adds a tool's guidelines to the system prompt while the tool is active, so
|
|
130
|
+
* these rules cost nothing when codemode is off and reach delegated children too.
|
|
131
|
+
*/
|
|
132
|
+
export const CODEMODE_GUIDELINES: readonly string[] = [
|
|
133
|
+
"Use codemode as a thin orchestration layer that cuts model/tool round trips, not a place for the whole task: give each script one coherent objective (gather context, prepare one change, run checks, or save evidence) and never mix uncertain exploration, file mutations, and remote publishing in one script.",
|
|
134
|
+
"In codemode, parallelize by independence, not by count: run independent calls together with Promise.allSettled() and label each result so partial failures stay attributable; run dependent steps (read, decide, edit, verify) sequentially and never parallelize writes that can overlap.",
|
|
135
|
+
"In codemode, a fulfilled promise is not success: check each result's own failure fields (bash exit_code, MCP isError, truncation flags) and throw or report the failure instead of assuming the call worked. Await every tool call before the script ends.",
|
|
136
|
+
"Codemode side effects are not transactional: a change made before a later failure stays made. Validate prerequisites before mutating, never repeat a side effect merely because the script failed afterward, and inspect the real state after a partial failure.",
|
|
137
|
+
"From codemode, return decision-relevant evidence: affected files, exit codes, test totals, relevant errors, truncation indicators, and full-log paths. Filter noise, never evidence; a summary must never turn a failure into success.",
|
|
138
|
+
"Keep long waits out of codemode: run builds, CI, servers, and long suites with the background tools when they are available and continue on their completion event; when they are not, use one bounded direct foreground call with an explicit timeout. Never poll inside a script.",
|
|
139
|
+
"In codemode, discover unfamiliar tools with searchTools() and describeTool() before calling them instead of inventing names or arguments; respect direct-only tools, permissions, consent, and sandbox boundaries, which codemode never bypasses; prefer a direct tool call when a script adds no real benefit.",
|
|
140
|
+
];
|
|
141
|
+
|
|
127
142
|
export function decorateCodemodeTool(tool: ToolDefinition): ToolDefinition {
|
|
128
143
|
return {
|
|
129
144
|
...tool,
|
|
145
|
+
promptGuidelines: [...(tool.promptGuidelines ?? []), ...CODEMODE_GUIDELINES],
|
|
130
146
|
renderShell: "self",
|
|
131
147
|
renderCall(args, theme, context) {
|
|
132
148
|
const tone = context.isError ? CARD_TONE.ERROR : context.isPartial ? CARD_TONE.WARNING : CARD_TONE.INFO;
|
|
@@ -35,6 +35,7 @@ export const COMMAND_PALETTE_CATALOG: readonly CommandPaletteCatalogGroup[] = [
|
|
|
35
35
|
{
|
|
36
36
|
title: "Session",
|
|
37
37
|
items: [
|
|
38
|
+
{ command: "gentle:guide", label: "Guided tour of Gentle Shell" },
|
|
38
39
|
{ command: "gentle:yolo", label: "🚀 YOLO 🔥 session permission" },
|
|
39
40
|
{ command: "gentle:changes", label: "Browse changes" },
|
|
40
41
|
{ command: "gentle:agents", label: "Subagents" },
|
package/lib/command-palette.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isKeyRelease, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { effectiveKey, type KeymapBindings } from "./keymaps.ts";
|
|
2
3
|
import { stripAnsi } from "./terminal-theme.ts";
|
|
3
4
|
|
|
4
5
|
// Command palette: a pure, curated, grouped overlay component for
|
|
@@ -21,7 +22,8 @@ export interface CommandPaletteGroup {
|
|
|
21
22
|
items: CommandPaletteItem[];
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
/** `bind` carries the raw key pressed after Tab, for the caller to assign to `name`. */
|
|
26
|
+
export type CommandPaletteResult = { type: "run"; name: string } | { type: "bind"; name: string; data: string } | { type: "close" };
|
|
25
27
|
|
|
26
28
|
export interface CommandPaletteTheme {
|
|
27
29
|
fg(color: string, text: string): string;
|
|
@@ -166,6 +168,7 @@ export class CommandPalette {
|
|
|
166
168
|
private query = "";
|
|
167
169
|
private selected = 0;
|
|
168
170
|
private completed = false;
|
|
171
|
+
private capturing: CommandPaletteItem | undefined;
|
|
169
172
|
private readonly groups: readonly CommandPaletteGroup[];
|
|
170
173
|
private readonly done: (result: CommandPaletteResult) => void;
|
|
171
174
|
private readonly theme: CommandPaletteTheme | undefined;
|
|
@@ -182,6 +185,17 @@ export class CommandPalette {
|
|
|
182
185
|
|
|
183
186
|
handleInput(data: string): void {
|
|
184
187
|
if (this.completed || isKeyRelease(data)) return;
|
|
188
|
+
// After Tab the next key is the one to assign, whatever it is; esc only cancels.
|
|
189
|
+
if (this.capturing) {
|
|
190
|
+
const item = this.capturing;
|
|
191
|
+
this.capturing = undefined;
|
|
192
|
+
if (!matchesKey(data, "escape")) this.finish({ type: "bind", name: item.command, data });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (matchesKey(data, "tab")) {
|
|
196
|
+
this.capturing = itemAt(this.matches(), this.selected);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
185
199
|
// A bare line feed ("\n") is both ctrl+j and, on non-Kitty terminals,
|
|
186
200
|
// a synonym for Enter: check the scroll/move keys first so ctrl+j
|
|
187
201
|
// always scrolls instead of running the highlighted command (same
|
|
@@ -267,7 +281,8 @@ export class CommandPalette {
|
|
|
267
281
|
lines.push(...this.renderGroups(groups, width, budget));
|
|
268
282
|
}
|
|
269
283
|
lines.push("");
|
|
270
|
-
lines.push(this.renderLine(
|
|
284
|
+
if (this.capturing) lines.push(this.renderLine(`Press the new key for ${this.capturing.label} · esc cancel`, width, "accent"));
|
|
285
|
+
else lines.push(this.renderLine("↑/↓ move • enter run • tab set key • esc close", width, "muted"));
|
|
271
286
|
return lines;
|
|
272
287
|
}
|
|
273
288
|
|
|
@@ -347,11 +362,9 @@ export class CommandPalette {
|
|
|
347
362
|
* defaults to "alt+k" (ctrl+k is reserved by Pi's editor for
|
|
348
363
|
* delete-to-line-end, so an extension shortcut on it is skipped); an empty
|
|
349
364
|
* value or "off" (case-insensitive) disables the shortcut; anything else is
|
|
350
|
-
* used as-is (trimmed).
|
|
351
|
-
*
|
|
365
|
+
* used as-is (trimmed). Unset, a key saved in keymaps.json wins over the
|
|
366
|
+
* default (lib/keymaps.ts).
|
|
352
367
|
*/
|
|
353
|
-
export function commandsKey(env: NodeJS.ProcessEnv = process.env): string | undefined {
|
|
354
|
-
|
|
355
|
-
if (value === undefined) return "alt+k";
|
|
356
|
-
return value === "" || value.toLowerCase() === "off" ? undefined : value;
|
|
368
|
+
export function commandsKey(env: NodeJS.ProcessEnv = process.env, bindings: KeymapBindings = {}): string | undefined {
|
|
369
|
+
return effectiveKey("commands", env, bindings);
|
|
357
370
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { ToolResultEvent } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { inferOddPhase } from "./odd-phase-inference.ts";
|
|
3
|
+
|
|
4
|
+
// Explicit discovery tools; existing shell inference below is advisory, never authorization.
|
|
5
|
+
const DISCOVERY_TOOLS = new Set([
|
|
6
|
+
"read", "grep", "find", "ls", "codegraph_query", "codegraph_explore",
|
|
7
|
+
"mem_search", "mem_get_observation", "mem_context",
|
|
8
|
+
"mcp__codegraph__codegraph_query", "mcp__codegraph__codegraph_explore",
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
type DiscoveryResult = Pick<ToolResultEvent, "toolCallId" | "toolName" | "isError" | "content" | "input" | "details" | "parentToolCallId">;
|
|
12
|
+
type PendingCall = { toolName: string; parentToolCallId?: string };
|
|
13
|
+
type RequestBudget = { pending: Map<string, PendingCall>; seen: Set<string>; lookups: number; bytes: number; notified: boolean };
|
|
14
|
+
|
|
15
|
+
function isDiscovery(event: DiscoveryResult): boolean {
|
|
16
|
+
if (DISCOVERY_TOOLS.has(event.toolName)) return true;
|
|
17
|
+
if (event.toolName === "bash" || event.toolName === "powershell") return inferOddPhase(event.toolName, event.input) === "exploring";
|
|
18
|
+
if (event.toolName !== "codegraph" || (event.input.operation !== "query" && event.input.operation !== "explore")) return false;
|
|
19
|
+
// This local tool reports unavailable/failed as successful fallback results.
|
|
20
|
+
const details = event.details;
|
|
21
|
+
return !(details && typeof details === "object" && "status" in details && (details.status === "failed" || details.status === "unavailable"));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Ephemeral per-request facts. Only calls observed in this request can contribute results. */
|
|
25
|
+
export function createExplorationBudget() {
|
|
26
|
+
const requests = new Map<unknown, RequestBudget>();
|
|
27
|
+
return {
|
|
28
|
+
start(session: unknown) {
|
|
29
|
+
requests.set(session, { pending: new Map(), seen: new Set(), lookups: 0, bytes: 0, notified: false });
|
|
30
|
+
},
|
|
31
|
+
call(session: unknown, id: string, toolName = "", parentToolCallId?: string) {
|
|
32
|
+
const request = requests.get(session);
|
|
33
|
+
if (request && !request.seen.has(id)) request.pending.set(id, { toolName, parentToolCallId });
|
|
34
|
+
},
|
|
35
|
+
result(session: unknown, event: DiscoveryResult, primary = true, aborted = false): string | undefined {
|
|
36
|
+
const request = requests.get(session);
|
|
37
|
+
const call = request?.pending.get(event.toolCallId);
|
|
38
|
+
if (!request || !call) return undefined;
|
|
39
|
+
request.pending.delete(event.toolCallId);
|
|
40
|
+
request.seen.add(event.toolCallId);
|
|
41
|
+
if (!primary || aborted || event.isError) return undefined;
|
|
42
|
+
if (call.parentToolCallId !== event.parentToolCallId) return undefined;
|
|
43
|
+
if (call.parentToolCallId !== undefined) {
|
|
44
|
+
const parent = request.pending.get(call.parentToolCallId);
|
|
45
|
+
if (!parent || parent.parentToolCallId !== undefined || !["codemode", "mcp"].includes(parent.toolName)) return undefined;
|
|
46
|
+
}
|
|
47
|
+
if (!isDiscovery(event)) return undefined;
|
|
48
|
+
request.lookups++;
|
|
49
|
+
for (const part of event.content) {
|
|
50
|
+
if (part.type === "text") request.bytes += Buffer.byteLength(part.text, "utf8");
|
|
51
|
+
}
|
|
52
|
+
if (request.notified || (request.lookups <= 3 && request.bytes <= 40_000)) return undefined;
|
|
53
|
+
request.notified = true;
|
|
54
|
+
return `Exploration budget: ${request.lookups.toLocaleString("en-US")} tracked lookups and ${request.bytes.toLocaleString("en-US")} UTF-8 text bytes (an approximate evidence budget). Ongoing discovery needs one configured explorer, even if read-only or initially small. Preparation for an already-understood authorized inline write remains exempt. This is runtime context for the original task, not a new user request. This notice grants no mutation or guard bypass authority.`;
|
|
55
|
+
},
|
|
56
|
+
facts(session: unknown): { lookups: number; textBytes: number } | undefined {
|
|
57
|
+
const request = requests.get(session);
|
|
58
|
+
return request ? { lookups: request.lookups, textBytes: request.bytes } : undefined;
|
|
59
|
+
},
|
|
60
|
+
settle(session: unknown) { requests.delete(session); },
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { isKeyRelease, matchesKey, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
|
+
import { renderPaletteCard, type CommandPaletteTheme } from "./command-palette.ts";
|
|
3
|
+
import { effectiveKey, loadKeymaps } from "./keymaps.ts";
|
|
4
|
+
|
|
5
|
+
// The /gentle:guide tour, driver.js style: one popover per step, placed
|
|
6
|
+
// beside the part of the screen the step describes. Pure (no Pi extension
|
|
7
|
+
// API), so extensions/gentle-guide.ts owns the overlay and the agent tool,
|
|
8
|
+
// and tests drive the steps, placement and keys directly.
|
|
9
|
+
|
|
10
|
+
/** Where a step points: the prompt, the sidebar rail (or the cards around the prompt without it), or nothing in particular. */
|
|
11
|
+
export type GuideRegion = "center" | "editor" | "sidebar";
|
|
12
|
+
export type GuideMode = "local" | "agent";
|
|
13
|
+
/** How a popover ends: the last step was passed, the user or agent ended it, or it closed to reopen elsewhere. */
|
|
14
|
+
export type GuideResult = "finished" | "ended" | "moved";
|
|
15
|
+
|
|
16
|
+
export interface GuideStep {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
body: string;
|
|
20
|
+
region: GuideRegion;
|
|
21
|
+
/** The slash command to try, shown with its current key. */
|
|
22
|
+
command?: string;
|
|
23
|
+
/** The keymap id whose key the step shows (lib/keymaps.ts). */
|
|
24
|
+
keymap?: string;
|
|
25
|
+
/** A command or tool that must exist in the session for the step to be shown. */
|
|
26
|
+
requires?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const GUIDE_STEPS: readonly GuideStep[] = [
|
|
30
|
+
{ id: "welcome", title: "Welcome to Gentle Shell", region: "center",
|
|
31
|
+
body: "el Gentleman is a coding agent harness: it explores before it writes, tracks larger work, delegates to subagents and checks its own changes. This tour shows where everything lives." },
|
|
32
|
+
{ id: "prompt", title: "The prompt", region: "editor",
|
|
33
|
+
body: "Ask for what you want in plain language. Slash commands start with /, and Esc stops the agent's current turn." },
|
|
34
|
+
{ id: "palette", title: "Command palette", region: "center", command: "gentle:commands", keymap: "commands", requires: "gentle:commands",
|
|
35
|
+
body: "Every Gentle command, grouped and searchable. Tab on a row gives that command a key of its own." },
|
|
36
|
+
{ id: "keymaps", title: "Keymaps", region: "center", command: "gentle:customize", requires: "gentle:customize",
|
|
37
|
+
body: "Customize → Keymaps lists every shortcut: press Enter on one and then the new key. Changes apply after /reload." },
|
|
38
|
+
{ id: "models", title: "Models and profiles", region: "center", command: "gentle:profiles", requires: "gentle:profiles",
|
|
39
|
+
body: "Pick the model for the main agent and for each kind of subagent, and save the mix as a profile." },
|
|
40
|
+
{ id: "agents", title: "Subagents", region: "sidebar", command: "gentle:agents", keymap: "agents.view", requires: "gentle:agents",
|
|
41
|
+
body: "The agent hands exploration, writing or verification to subagents. They appear as they run; open them to read what they are doing." },
|
|
42
|
+
{ id: "todos", title: "Task list", region: "sidebar", keymap: "todo.collapse", requires: "todo",
|
|
43
|
+
body: "For larger work the agent keeps a visible task list and updates it as each task starts and finishes." },
|
|
44
|
+
{ id: "jobs", title: "Background jobs", region: "sidebar", command: "gentle:jobs", keymap: "jobs.collapse", requires: "gentle:jobs",
|
|
45
|
+
body: "Long commands such as builds or test suites run in the background while you keep talking to the agent." },
|
|
46
|
+
{ id: "changes", title: "Changes", region: "editor", command: "gentle:changes", keymap: "changes", requires: "gentle:changes",
|
|
47
|
+
body: "Every uncommitted change of the session and its subagents' worktrees, with its diff. Press o to open a file in your editor." },
|
|
48
|
+
{ id: "design", title: "Design canvas", region: "center", command: "gentle:design", requires: "gentle:design",
|
|
49
|
+
body: "Ask for a screen, mockup or landing page and get HTML artboards on a local canvas to compare, comment and hand off." },
|
|
50
|
+
{ id: "voice", title: "Voice", region: "center", command: "gentle:voice", requires: "gentle:voice",
|
|
51
|
+
body: "Dictate prompts with push-to-talk; the transcription runs locally." },
|
|
52
|
+
{ id: "music", title: "Music", region: "center", command: "gentle:music", requires: "gentle:music",
|
|
53
|
+
body: "Background music while you work, controlled from the prompt." },
|
|
54
|
+
{ id: "customize", title: "Customize", region: "center", command: "gentle:customize", requires: "gentle:customize",
|
|
55
|
+
body: "Themes, layout, banner, cards, animations, audio notifications, Vim editing and prompt history, previewed before they apply." },
|
|
56
|
+
{ id: "permissions", title: "Permissions", region: "center", command: "gentle:yolo", requires: "gentle:yolo",
|
|
57
|
+
body: "YOLO lets the agent work without permission questions for this session. Secrets and credentials stay off-limits either way." },
|
|
58
|
+
{ id: "memory", title: "Memory", region: "center", requires: "mem_search",
|
|
59
|
+
body: "The agent saves decisions, fixes and discoveries, and recalls them in later sessions. Ask it what you did last time." },
|
|
60
|
+
{ id: "usage", title: "Usage", region: "center", command: "gentle:usage", keymap: "usage", requires: "gentle:usage",
|
|
61
|
+
body: "Your subscription's usage windows; /gentle:stats adds tokens, cost and models over time." },
|
|
62
|
+
{ id: "diagnostics", title: "Diagnostics", region: "center", command: "gentle:doctor", requires: "gentle:doctor",
|
|
63
|
+
body: "/gentle:doctor and /gentle:status check the installation when something looks off." },
|
|
64
|
+
{ id: "end", title: "That's the tour", region: "center",
|
|
65
|
+
body: "Run /gentle:guide again any time, or just ask the agent how to do something." },
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
/** The steps for one session: those without a requirement, and those whose command or tool exists. */
|
|
69
|
+
export function guideSteps(available: ReadonlySet<string>, steps: readonly GuideStep[] = GUIDE_STEPS): GuideStep[] {
|
|
70
|
+
return steps.filter((step) => !step.requires || available.has(step.requires));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Position within a non-empty list of steps. */
|
|
74
|
+
export class GuideTour {
|
|
75
|
+
readonly steps: readonly GuideStep[];
|
|
76
|
+
private index = 0;
|
|
77
|
+
|
|
78
|
+
constructor(steps: readonly GuideStep[]) {
|
|
79
|
+
if (steps.length === 0) throw new Error("A tour needs at least one step.");
|
|
80
|
+
this.steps = steps;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
current(): GuideStep { return this.steps[this.index]!; }
|
|
84
|
+
position(): number { return this.index + 1; }
|
|
85
|
+
isLast(): boolean { return this.index === this.steps.length - 1; }
|
|
86
|
+
/** False, without moving, on the last step. */
|
|
87
|
+
next(): boolean { if (this.isLast()) return false; this.index += 1; return true; }
|
|
88
|
+
/** False, without moving, on the first step. */
|
|
89
|
+
previous(): boolean { if (this.index === 0) return false; this.index -= 1; return true; }
|
|
90
|
+
show(id: string): boolean {
|
|
91
|
+
const found = this.steps.findIndex((step) => step.id === id);
|
|
92
|
+
if (found < 0) return false;
|
|
93
|
+
this.index = found;
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const GUIDE_POPOVER_WIDTH = 56;
|
|
99
|
+
const MIN_POPOVER_WIDTH = 40;
|
|
100
|
+
/** Rows between the bottom of the screen and the popover for prompt steps: the prompt, its rule and the status bar stay visible. */
|
|
101
|
+
const EDITOR_OFFSET_ROWS = 6;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Overlay options for a step: left of the sidebar rail when it shows, above
|
|
105
|
+
* the prompt for prompt steps, centered otherwise. In agent mode the popover
|
|
106
|
+
* never takes focus, so the user keeps typing in the prompt.
|
|
107
|
+
*/
|
|
108
|
+
export function guidePlacement(region: GuideRegion, columns: number, railColumns: number | undefined, mode: GuideMode) {
|
|
109
|
+
const width = Math.min(GUIDE_POPOVER_WIDTH, Math.max(MIN_POPOVER_WIDTH, columns - 4));
|
|
110
|
+
const nonCapturing = mode === "agent";
|
|
111
|
+
if (region === "sidebar" && railColumns) return { anchor: "right-center" as const, offsetX: -(railColumns + 1), width, nonCapturing };
|
|
112
|
+
if (region === "editor") return { anchor: "bottom-center" as const, offsetY: -EDITOR_OFFSET_ROWS, width, nonCapturing };
|
|
113
|
+
return { anchor: "center" as const, width, nonCapturing };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** "Try: /command · key" for a step, with the key the user has now; undefined when there is nothing to try. */
|
|
117
|
+
export function guideTryLine(step: GuideStep, env: NodeJS.ProcessEnv): string | undefined {
|
|
118
|
+
const key = step.keymap ? effectiveKey(step.keymap, env, loadKeymaps(env).bindings) : undefined;
|
|
119
|
+
const parts = [step.command ? `/${step.command}` : undefined, key].filter((part): part is string => Boolean(part));
|
|
120
|
+
return parts.length ? `Try: ${parts.join(" · ")}` : undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function pointerLine(region: GuideRegion, railColumns: number | undefined): string | undefined {
|
|
124
|
+
if (region === "sidebar") return railColumns ? "▸ In the sidebar on the right" : "▾ In the cards around the prompt";
|
|
125
|
+
if (region === "editor") return "▾ Below, at the prompt";
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface GuidePopoverOptions {
|
|
130
|
+
tour: GuideTour;
|
|
131
|
+
mode: GuideMode;
|
|
132
|
+
theme: CommandPaletteTheme;
|
|
133
|
+
env: NodeJS.ProcessEnv;
|
|
134
|
+
/** The sidebar rail's columns while it shows; undefined without it. */
|
|
135
|
+
railColumns?: () => number | undefined;
|
|
136
|
+
/** Called after a local key moved the tour, so the owner can reopen the popover beside the new step. */
|
|
137
|
+
onMove?: () => void;
|
|
138
|
+
done(result: GuideResult): void;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export class GuidePopover {
|
|
142
|
+
private completed = false;
|
|
143
|
+
private readonly options: GuidePopoverOptions;
|
|
144
|
+
|
|
145
|
+
constructor(options: GuidePopoverOptions) {
|
|
146
|
+
this.options = options;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
invalidate(): void {}
|
|
150
|
+
|
|
151
|
+
/** Local mode only: in agent mode the popover never has focus. */
|
|
152
|
+
handleInput(data: string): void {
|
|
153
|
+
if (this.completed || this.options.mode !== "local" || isKeyRelease(data)) return;
|
|
154
|
+
const { tour } = this.options;
|
|
155
|
+
if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c") || data === "q") return this.finish("ended");
|
|
156
|
+
if (matchesKey(data, "right") || matchesKey(data, "enter") || matchesKey(data, "return") || data === " " || data === "l") {
|
|
157
|
+
if (!tour.next()) return this.finish("finished");
|
|
158
|
+
this.options.onMove?.();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if ((matchesKey(data, "left") || data === "h") && tour.previous()) this.options.onMove?.();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
render(width: number): string[] {
|
|
165
|
+
const { tour, theme, mode } = this.options;
|
|
166
|
+
const step = tour.current();
|
|
167
|
+
const inner = Math.max(1, width - 4);
|
|
168
|
+
const fg = (color: string, text: string) => theme.fg(color, text);
|
|
169
|
+
const lines: string[] = [];
|
|
170
|
+
const counter = `${tour.position()}/${tour.steps.length}`;
|
|
171
|
+
const title = truncateToWidth(step.title, Math.max(1, inner - counter.length - 1), "…");
|
|
172
|
+
lines.push(`${fg("accent", title)}${" ".repeat(Math.max(1, inner - visibleWidth(title) - counter.length))}${fg("muted", counter)}`);
|
|
173
|
+
const pointer = pointerLine(step.region, this.options.railColumns?.());
|
|
174
|
+
if (pointer) lines.push(fg("accent", pointer));
|
|
175
|
+
lines.push("");
|
|
176
|
+
for (const line of wrapTextWithAnsi(step.body, inner)) lines.push(fg("text", line));
|
|
177
|
+
const tryLine = guideTryLine(step, this.options.env);
|
|
178
|
+
if (tryLine) lines.push("", fg("accent", truncateToWidth(tryLine, inner, "…")));
|
|
179
|
+
lines.push("");
|
|
180
|
+
const footer = mode === "local" ? "→ next · ← back · esc end" : "Reply in the chat · /gentle:guide stop ends";
|
|
181
|
+
lines.push(fg("muted", truncateToWidth(footer, inner, "…")));
|
|
182
|
+
return renderPaletteCard(lines, width, theme);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private finish(result: GuideResult): void {
|
|
186
|
+
if (this.completed) return;
|
|
187
|
+
this.completed = true;
|
|
188
|
+
this.options.done(result);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** What the gentle_guide tool returns for the current step, so the agent can explain it. */
|
|
193
|
+
export function guideStepText(tour: GuideTour, env: NodeJS.ProcessEnv): string {
|
|
194
|
+
const step = tour.current();
|
|
195
|
+
const lines = [`Step ${tour.position()}/${tour.steps.length} · ${step.title}`, step.body];
|
|
196
|
+
const tryLine = guideTryLine(step, env);
|
|
197
|
+
if (tryLine) lines.push(tryLine);
|
|
198
|
+
if (tour.isLast()) lines.push('This is the last step: call gentle_guide with action "end" when the user is done.');
|
|
199
|
+
else lines.push(`Next: ${tour.steps[tour.position()]!.title}`);
|
|
200
|
+
return lines.join("\n");
|
|
201
|
+
}
|
|
@@ -214,6 +214,9 @@ function linkDir(env: Record<string, string | undefined>, homedir: string): stri
|
|
|
214
214
|
// launched from inside a Gentle Shell session sees the outer isolated home as
|
|
215
215
|
// PI_CODING_AGENT_DIR, so `--link` must not re-select it (#2015).
|
|
216
216
|
export const USER_PI_HOME_ENV = "GENTLE_SHELL_USER_PI_HOME";
|
|
217
|
+
// Set by bin/gentle-shell.mjs only when Gentle Shell, not Herdr's Pi bridge,
|
|
218
|
+
// owns the pane's Herdr agent reports (extensions/gentle-herdr-agent.ts).
|
|
219
|
+
export const HERDR_REPORTER_ENV = "GENTLE_SHELL_HERDR_REPORTER";
|
|
217
220
|
|
|
218
221
|
export function userPiHome(env: Record<string, string | undefined>, homedir: string): string {
|
|
219
222
|
return env[USER_PI_HOME_ENV] || linkDir(env, homedir);
|
|
@@ -1083,6 +1086,7 @@ export function buildPiInvocation(input: BuildPiInvocationInput): PiInvocation {
|
|
|
1083
1086
|
const env: Record<string, string | undefined> = {
|
|
1084
1087
|
...input.baseEnv,
|
|
1085
1088
|
PI_CODING_AGENT_DIR: input.home.dir,
|
|
1089
|
+
PI_PROGRAM_STATUS_APP: "gentle-shell",
|
|
1086
1090
|
GENTLE_PI_AGENT_HOME: input.home.dir,
|
|
1087
1091
|
[USER_PI_HOME_ENV]: userPiHome(input.baseEnv, input.homedir),
|
|
1088
1092
|
};
|
package/lib/herdr-activity.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import { closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, join } from "node:path";
|
|
4
4
|
import { stripTerminalSequences, visibleWidth } from "@earendil-works/pi-tui";
|
|
5
|
+
import { HERDR_REPORTER_ENV } from "./gentle-shell-launcher.ts";
|
|
5
6
|
|
|
6
7
|
const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
7
8
|
|
|
@@ -135,18 +136,23 @@ export function herdrSetupHint(
|
|
|
135
136
|
];
|
|
136
137
|
}
|
|
137
138
|
|
|
138
|
-
|
|
139
|
+
/** The agent label this pane reports to Herdr: Gentle Shell's own, or Herdr's Pi bridge. */
|
|
140
|
+
export function herdrAgentLabel(env: NodeJS.ProcessEnv): "gentle-shell" | "pi" {
|
|
141
|
+
return env[HERDR_REPORTER_ENV] === "1" ? "gentle-shell" : "pi";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function metadataArgs(pane: string, summary: string | null, seq: number, agent = "pi"): string[] {
|
|
139
145
|
const rows = summary?.split("\n") ?? [];
|
|
140
146
|
const tokens = ["summary", "summary2"].flatMap((token, index) => rows[index]
|
|
141
147
|
? ["--token", `${token}=${rows[index]}`] : ["--clear-token", token]);
|
|
142
|
-
return ["pane", "report-metadata", pane, "--source", "gentle:activity", "--agent",
|
|
148
|
+
return ["pane", "report-metadata", pane, "--source", "gentle:activity", "--agent", agent,
|
|
143
149
|
"--seq", String(seq), "--ttl-ms", "30000", ...tokens];
|
|
144
150
|
}
|
|
145
151
|
|
|
146
152
|
export function metadataTransport(env: NodeJS.ProcessEnv): (summary: string | null, seq: number) => Promise<void> {
|
|
147
153
|
return (summary, seq) => new Promise((resolve) => {
|
|
148
154
|
// No shell, bounded output/time, and failure never blocks Pi's handlers.
|
|
149
|
-
execFile(env.HERDR_BIN_PATH ?? "herdr", metadataArgs(env.HERDR_PANE_ID!, summary, seq), {
|
|
155
|
+
execFile(env.HERDR_BIN_PATH ?? "herdr", metadataArgs(env.HERDR_PANE_ID!, summary, seq, herdrAgentLabel(env)), {
|
|
150
156
|
env, timeout: 1500, maxBuffer: 4096, windowsHide: true,
|
|
151
157
|
}, () => resolve());
|
|
152
158
|
});
|