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
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { readSessionProfileBinding } from "../lib/session-profile-binding.ts";
|
|
3
|
+
import { readSessionProfileAuthority } from "../lib/session-profile-authority.ts";
|
|
4
|
+
import { gentlePiConfigHome } from "../lib/agent-home.ts";
|
|
5
|
+
import { freezeSessionProfileAtStartup, readFrozenDefaultOrchestrator } from "../lib/session-profile-freeze.ts";
|
|
6
|
+
import { isServiceTier } from "../lib/model-routing-authority.ts";
|
|
7
|
+
import { applyOpenAITier, CHILD_TIER_ENV, PROFILE_TIER_EVENT } from "../lib/openai-fast-tier.ts";
|
|
8
|
+
|
|
9
|
+
type Selection = "standard" | "fast" | undefined;
|
|
10
|
+
|
|
11
|
+
export default function (pi: ExtensionAPI) {
|
|
12
|
+
let selection: Selection;
|
|
13
|
+
let profileModel: string | undefined;
|
|
14
|
+
|
|
15
|
+
function restore(ctx: ExtensionContext) {
|
|
16
|
+
const sessionId = ctx.sessionManager?.getSessionId?.();
|
|
17
|
+
// The authority can replay the disk-corroborated branch even when this
|
|
18
|
+
// extension starts before the profile owner's session_start handler.
|
|
19
|
+
const authority = typeof ctx.sessionManager?.getBranch === "function" ? readSessionProfileAuthority(ctx.sessionManager) : undefined;
|
|
20
|
+
const binding = authority ? authority.available ? authority.binding : undefined : readSessionProfileBinding(sessionId);
|
|
21
|
+
const cwd = ctx.sessionManager?.getCwd?.() ?? ctx.cwd;
|
|
22
|
+
if (process.env.GENTLE_PI_AGENTS_CHILD !== "1" && sessionId && typeof cwd === "string") {
|
|
23
|
+
// Idempotent across extension load order and reload: never re-read a
|
|
24
|
+
// later default into a session that already froze its startup choice.
|
|
25
|
+
freezeSessionProfileAtStartup({ sessionId, cwd, configHome: gentlePiConfigHome() });
|
|
26
|
+
}
|
|
27
|
+
const entry = binding ? binding.modelProfiles.orchestrator
|
|
28
|
+
: authority && !authority.available ? undefined : readFrozenDefaultOrchestrator(sessionId);
|
|
29
|
+
const matches = entry?.model === `${ctx.model?.provider}/${ctx.model?.id}`;
|
|
30
|
+
let child: { tier?: unknown; model?: unknown } | undefined;
|
|
31
|
+
try { if (process.env.GENTLE_PI_AGENTS_CHILD === "1") child = JSON.parse(process.env[CHILD_TIER_ENV] ?? "null") ?? undefined; } catch { /* Invalid child selection is ignored. */ }
|
|
32
|
+
const childMatches = child?.model === `${ctx.model?.provider}/${ctx.model?.id}`;
|
|
33
|
+
selection = process.env.GENTLE_PI_AGENTS_CHILD === "1"
|
|
34
|
+
? childMatches && isServiceTier(child?.tier) ? child.tier : undefined
|
|
35
|
+
: matches ? entry?.tier : undefined;
|
|
36
|
+
profileModel = selection ? `${ctx.model?.provider}/${ctx.model?.id}` : undefined;
|
|
37
|
+
}
|
|
38
|
+
let currentContext: ExtensionContext | undefined;
|
|
39
|
+
pi.on("session_start", (_event, ctx) => { currentContext = ctx; restore(ctx); });
|
|
40
|
+
pi.on("session_tree", (_event, ctx) => restore(ctx));
|
|
41
|
+
pi.events?.on(PROFILE_TIER_EVENT, (value: unknown) => {
|
|
42
|
+
const event = value as { sessionId?: string; tier?: unknown; model?: unknown } | undefined;
|
|
43
|
+
if (!currentContext || !event || event.sessionId !== currentContext.sessionManager?.getSessionId?.()) return;
|
|
44
|
+
selection = isServiceTier(event.tier) ? event.tier : undefined;
|
|
45
|
+
profileModel = selection && typeof event.model === "string" ? event.model : undefined;
|
|
46
|
+
});
|
|
47
|
+
pi.on("model_select", (event) => {
|
|
48
|
+
if (profileModel && profileModel !== `${event.model.provider}/${event.model.id}`) {
|
|
49
|
+
selection = undefined;
|
|
50
|
+
profileModel = undefined;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
pi.on("before_provider_request", (event, ctx) => {
|
|
54
|
+
const model = ctx.model;
|
|
55
|
+
if (profileModel && profileModel !== `${model?.provider}/${model?.id}`) {
|
|
56
|
+
selection = undefined;
|
|
57
|
+
profileModel = undefined;
|
|
58
|
+
}
|
|
59
|
+
return applyOpenAITier(event.payload, selection, model);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { TUI } from "@earendil-works/pi-tui";
|
|
3
|
+
import { Type } from "typebox";
|
|
4
|
+
import { appendSystemPromptOnce } from "../lib/append-system-prompt.ts";
|
|
5
|
+
import { guidePlacement, GuidePopover, guideStepText, guideSteps, GuideTour, type GuideMode, type GuideResult } from "../lib/gentle-guide.ts";
|
|
6
|
+
import { sidebarState } from "../lib/shell-sidebar.ts";
|
|
7
|
+
|
|
8
|
+
// /gentle:guide: a guided tour of Gentle Shell. With a model, the agent
|
|
9
|
+
// drives it through the gentle_guide tool, one step per turn, and the
|
|
10
|
+
// popover stays beside the prompt without taking its focus, so the user can
|
|
11
|
+
// ask questions mid-tour. Without one (or with `local`), the user steps
|
|
12
|
+
// through it with the arrow keys. Pi reads overlay options only when an
|
|
13
|
+
// overlay opens, so a step for another region closes the popover and
|
|
14
|
+
// reopens it there.
|
|
15
|
+
|
|
16
|
+
export const GUIDE_COMMAND_NAME = "gentle:guide";
|
|
17
|
+
export const GUIDE_TOOL_NAME = "gentle_guide";
|
|
18
|
+
const GUIDE_MESSAGE_TYPE = "gentle-guide";
|
|
19
|
+
const USAGE = "Usage: /gentle:guide [local|stop]";
|
|
20
|
+
|
|
21
|
+
export const GUIDE_AGENT_REQUEST = `The user ran /gentle:guide. Give them the guided tour of Gentle Shell, one step per turn: call ${GUIDE_TOOL_NAME} with action "start", explain that step in two or three sentences in the user's language, and end your turn asking whether to continue or if they have a question. When they want to continue, call ${GUIDE_TOOL_NAME} with action "next" and do the same. If they ask something, answer it and stay on the current step. After the last step, call ${GUIDE_TOOL_NAME} with action "end".`;
|
|
22
|
+
|
|
23
|
+
export const GUIDE_PROMPT_HINT = `Gentle Shell guided tour: when the user asks how to use Gentle Shell or what it can do, offer /gentle:guide; you can also drive it with the ${GUIDE_TOOL_NAME} tool (start, next, previous, show, end), one step per turn.`;
|
|
24
|
+
|
|
25
|
+
const GuideParams = Type.Object({
|
|
26
|
+
action: Type.Union([Type.Literal("start"), Type.Literal("next"), Type.Literal("previous"), Type.Literal("show"), Type.Literal("end")], { description: "start opens the first step; next and previous move; show jumps to a step id; end closes the tour." }),
|
|
27
|
+
step: Type.Optional(Type.String({ description: "show only: the step id to jump to." })),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
interface GuideParamsValue {
|
|
31
|
+
action: "start" | "next" | "previous" | "show" | "end";
|
|
32
|
+
step?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface Session {
|
|
36
|
+
tour: GuideTour;
|
|
37
|
+
mode: GuideMode;
|
|
38
|
+
ctx: ExtensionContext;
|
|
39
|
+
/** Closes the popover with `result`; a no-op once it is closed. */
|
|
40
|
+
close(result: GuideResult): void;
|
|
41
|
+
/** The placement the popover opened with, to tell whether a step needs it elsewhere. */
|
|
42
|
+
placement: string;
|
|
43
|
+
/** Resolves when this popover closes; immediately resolved without a terminal. */
|
|
44
|
+
settled: Promise<GuideResult | undefined>;
|
|
45
|
+
/** True without a terminal: the agent explains the steps in text only. */
|
|
46
|
+
headless?: boolean;
|
|
47
|
+
tui?: TUI;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function railColumns(tui: TUI | undefined): number | undefined {
|
|
51
|
+
if (!tui) return undefined;
|
|
52
|
+
const state = sidebarState(tui);
|
|
53
|
+
return state.active && (state.ownsHost?.() ?? true) ? state.railColumns : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default function gentleGuide(pi: ExtensionAPI, env: NodeJS.ProcessEnv = process.env): void {
|
|
57
|
+
// Delegated children only run their task.
|
|
58
|
+
if (env.GENTLE_PI_AGENTS_CHILD === "1") return;
|
|
59
|
+
let active: Session | undefined;
|
|
60
|
+
|
|
61
|
+
const available = (): Set<string> => new Set([...pi.getCommands().map((command) => command.name), ...pi.getAllTools().map((tool) => tool.name)]);
|
|
62
|
+
const placementOf = (session: Pick<Session, "tour" | "mode" | "tui">) => {
|
|
63
|
+
const columns = session.tui?.terminal.columns ?? 80;
|
|
64
|
+
return guidePlacement(session.tour.current().region, columns, railColumns(session.tui), session.mode);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Opens the popover at the tour's current step; resolves with how it closed. */
|
|
68
|
+
const open = (ctx: ExtensionContext, tour: GuideTour, mode: GuideMode): Promise<GuideResult | undefined> => {
|
|
69
|
+
active?.close("ended");
|
|
70
|
+
const session: Session = { tour, mode, ctx, close: () => {}, placement: "", settled: Promise.resolve(undefined) };
|
|
71
|
+
active = session;
|
|
72
|
+
const settled = ctx.ui.custom<GuideResult | undefined>((tui, theme, _keybindings, done) => {
|
|
73
|
+
session.tui = tui;
|
|
74
|
+
let closed = false;
|
|
75
|
+
session.close = (result) => { if (!closed) { closed = true; done(result); } };
|
|
76
|
+
return new GuidePopover({
|
|
77
|
+
tour, mode, theme, env,
|
|
78
|
+
railColumns: () => railColumns(tui),
|
|
79
|
+
onMove: () => moved(session),
|
|
80
|
+
done: (result) => session.close(result),
|
|
81
|
+
});
|
|
82
|
+
}, { overlay: true, overlayOptions: () => {
|
|
83
|
+
const placement = placementOf(session);
|
|
84
|
+
session.placement = JSON.stringify(placement);
|
|
85
|
+
return placement;
|
|
86
|
+
} });
|
|
87
|
+
session.settled = settled.finally(() => { if (active === session) active = undefined; });
|
|
88
|
+
return session.settled;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** After the tour moved: repaint in place, or reopen the popover beside the new step. */
|
|
92
|
+
const moved = (session: Session): Promise<GuideResult | undefined> | undefined => {
|
|
93
|
+
if (session.headless) return undefined;
|
|
94
|
+
if (JSON.stringify(placementOf(session)) === session.placement) {
|
|
95
|
+
session.tui?.requestRender();
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
session.close("moved");
|
|
99
|
+
return open(session.ctx, session.tour, session.mode);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const runLocal = async (ctx: ExtensionContext): Promise<void> => {
|
|
103
|
+
const tour = new GuideTour(guideSteps(available()));
|
|
104
|
+
let result = await open(ctx, tour, "local");
|
|
105
|
+
// A move reopens the popover; the new one carries the same tour on.
|
|
106
|
+
while (result === "moved") {
|
|
107
|
+
const next = active;
|
|
108
|
+
if (!next || next.tour !== tour) return;
|
|
109
|
+
result = await next.settled;
|
|
110
|
+
}
|
|
111
|
+
if (result === "finished") ctx.ui.notify("Tour finished. Run /gentle:guide any time to see it again.", "info");
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
pi.registerCommand(GUIDE_COMMAND_NAME, {
|
|
115
|
+
description: "Take a guided tour of what Gentle Shell can do, explained by the agent (local: step through it yourself with the arrow keys; stop: end it).",
|
|
116
|
+
handler: async (args, ctx) => {
|
|
117
|
+
if (!ctx.hasUI) return;
|
|
118
|
+
const arg = args.trim().toLowerCase();
|
|
119
|
+
if (arg === "stop") {
|
|
120
|
+
if (!active) return ctx.ui.notify("No guided tour is running.", "info");
|
|
121
|
+
active.close("ended");
|
|
122
|
+
return ctx.ui.notify("Guided tour ended.", "info");
|
|
123
|
+
}
|
|
124
|
+
if (arg !== "" && arg !== "local") return ctx.ui.notify(USAGE, "warning");
|
|
125
|
+
if (ctx.mode !== "tui") return ctx.ui.notify("The guided tour requires an interactive terminal.", "warning");
|
|
126
|
+
if (arg === "local" || !ctx.model) return runLocal(ctx);
|
|
127
|
+
pi.sendMessage({ customType: GUIDE_MESSAGE_TYPE, content: GUIDE_AGENT_REQUEST, display: false }, ctx.isIdle() ? { triggerTurn: true } : { triggerTurn: true, deliverAs: "followUp" });
|
|
128
|
+
ctx.ui.notify("Starting the guided tour with the agent…", "info");
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
pi.registerTool({
|
|
133
|
+
name: GUIDE_TOOL_NAME,
|
|
134
|
+
label: "Gentle guide",
|
|
135
|
+
description: "Drive the /gentle:guide tour of Gentle Shell: start shows the first step as a popover beside the part of the screen it describes and returns its text to explain; next, previous and show (with a step id) move; end closes the popover. Show one step per turn and let the user ask questions between steps.",
|
|
136
|
+
promptSnippet: "Show the Gentle Shell guided tour one step at a time and explain each step.",
|
|
137
|
+
parameters: GuideParams,
|
|
138
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
139
|
+
const { action, step } = params as GuideParamsValue;
|
|
140
|
+
const text = (value: string) => ({ content: [{ type: "text" as const, text: value }], details: {} });
|
|
141
|
+
if (action === "start") {
|
|
142
|
+
const tour = new GuideTour(guideSteps(available()));
|
|
143
|
+
if (ctx.hasUI && ctx.mode === "tui") void open(ctx, tour, "agent");
|
|
144
|
+
else {
|
|
145
|
+
active?.close("ended");
|
|
146
|
+
const headless: Session = { tour, mode: "agent", ctx, placement: "", settled: Promise.resolve(undefined), headless: true, close: () => { if (active === headless) active = undefined; } };
|
|
147
|
+
active = headless;
|
|
148
|
+
}
|
|
149
|
+
return text(`${guideStepText(tour, env)}\nTour steps: ${tour.steps.map((item) => item.title).join(", ")}`);
|
|
150
|
+
}
|
|
151
|
+
const session = active;
|
|
152
|
+
if (!session) return text(`No tour is running. Call ${GUIDE_TOOL_NAME} with action "start".`);
|
|
153
|
+
if (action === "end") {
|
|
154
|
+
session.close("ended");
|
|
155
|
+
return text("Tour ended.");
|
|
156
|
+
}
|
|
157
|
+
const { tour } = session;
|
|
158
|
+
if (action === "show" && !tour.show(step ?? "")) return text(`Unknown step "${step ?? ""}". Steps: ${tour.steps.map((item) => item.id).join(", ")}`);
|
|
159
|
+
if (action === "next" && !tour.next()) return text(`This was the last step. Call ${GUIDE_TOOL_NAME} with action "end".`);
|
|
160
|
+
if (action === "previous" && !tour.previous()) return text(`This is the first step.\n${guideStepText(tour, env)}`);
|
|
161
|
+
void moved(session);
|
|
162
|
+
return text(guideStepText(tour, env));
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
pi.on("before_agent_start", (event) => {
|
|
167
|
+
appendSystemPromptOnce(event.systemPromptOptions, GUIDE_PROMPT_HINT);
|
|
168
|
+
return undefined;
|
|
169
|
+
});
|
|
170
|
+
pi.on("session_shutdown", () => {
|
|
171
|
+
active?.close("ended");
|
|
172
|
+
active = undefined;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { statSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { HERDR_TASK_SUMMARY_CHANGED, resolveHerdrTaskSummarySettings } from "../lib/herdr-task-summary-policy.ts";
|
|
2
4
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
5
|
import { activitySummary, ActivityPublisher, createActivityColumns, herdrDetected, metadataTransport } from "../lib/herdr-activity.ts";
|
|
4
6
|
import { replayTodo, type TodoState } from "../lib/shell-todo.ts";
|
|
5
7
|
|
|
6
8
|
interface ActivityOptions {
|
|
9
|
+
gentlePiConfigHome?: string;
|
|
7
10
|
env?: NodeJS.ProcessEnv;
|
|
8
11
|
isSocket?: (path: string) => boolean;
|
|
9
12
|
send?: (summary: string | null, seq: number) => Promise<void>;
|
|
@@ -21,6 +24,8 @@ export function createHerdrActivityExtension(options: ActivityOptions = {}) {
|
|
|
21
24
|
});
|
|
22
25
|
let publisher: ActivityPublisher | undefined;
|
|
23
26
|
let stop: (() => void) | undefined;
|
|
27
|
+
let unsubscribeSettings: (() => void) | undefined;
|
|
28
|
+
let enabled = true;
|
|
24
29
|
let owner: string | undefined;
|
|
25
30
|
let tasks: TodoState["tasks"] = [];
|
|
26
31
|
let active = false;
|
|
@@ -28,7 +33,7 @@ export function createHerdrActivityExtension(options: ActivityOptions = {}) {
|
|
|
28
33
|
const columns = options.columns ?? createActivityColumns(env.HERDR_SOCKET_PATH!, options.now);
|
|
29
34
|
const owns = (ctx: ExtensionContext) => owner !== undefined && ctx.sessionManager.getSessionId() === owner;
|
|
30
35
|
const publish = () => {
|
|
31
|
-
if (!active || !publisher) return;
|
|
36
|
+
if (!active || !publisher || !enabled) return;
|
|
32
37
|
const now = (options.now ?? Date.now)();
|
|
33
38
|
publisher.update(activitySummary(tasks, columns()), now >= refreshAt);
|
|
34
39
|
if (now >= refreshAt) refreshAt = now + 10000;
|
|
@@ -36,12 +41,26 @@ export function createHerdrActivityExtension(options: ActivityOptions = {}) {
|
|
|
36
41
|
const idle = () => { active = false; publisher?.update(null); };
|
|
37
42
|
const startSession = (ctx: ExtensionContext) => {
|
|
38
43
|
idle(); stop?.(); stop = undefined;
|
|
44
|
+
unsubscribeSettings?.(); unsubscribeSettings = undefined;
|
|
39
45
|
owner = undefined;
|
|
40
46
|
if (ctx.mode !== "tui" || !ctx.hasUI || !isSocket(env.HERDR_SOCKET_PATH!)) return;
|
|
41
47
|
owner = ctx.sessionManager.getSessionId();
|
|
42
48
|
if (!owner) return;
|
|
43
49
|
publisher ??= new ActivityPublisher(options.send ?? metadataTransport(env));
|
|
44
50
|
publisher.update(null, true);
|
|
51
|
+
const preferences = resolveHerdrTaskSummarySettings({ gentlePiConfigHome: options.gentlePiConfigHome });
|
|
52
|
+
const configHome = dirname(preferences.globalFile);
|
|
53
|
+
enabled = preferences.settings.enabled;
|
|
54
|
+
unsubscribeSettings = pi.events.on(HERDR_TASK_SUMMARY_CHANGED, (data: unknown) => {
|
|
55
|
+
if (typeof data !== "object" || data === null || !("configHome" in data)
|
|
56
|
+
|| typeof data.configHome !== "string" || resolve(data.configHome) !== configHome) return;
|
|
57
|
+
const next = resolveHerdrTaskSummarySettings({ gentlePiConfigHome: configHome });
|
|
58
|
+
// Rejected store changes have no transport or state effects.
|
|
59
|
+
if (next.malformed || next.readError || next.settings.enabled === enabled) return;
|
|
60
|
+
enabled = next.settings.enabled;
|
|
61
|
+
if (!enabled) publisher?.update(null);
|
|
62
|
+
else { refreshAt = 0; publish(); }
|
|
63
|
+
});
|
|
45
64
|
tasks = replayTodo(ctx.sessionManager.getBranch()).tasks;
|
|
46
65
|
const watch = options.watch ?? ((tick: () => void) => {
|
|
47
66
|
const timer = setInterval(tick, 1000); timer.unref(); return () => clearInterval(timer);
|
|
@@ -72,6 +91,7 @@ export function createHerdrActivityExtension(options: ActivityOptions = {}) {
|
|
|
72
91
|
pi.on("session_shutdown", (_event, ctx) => {
|
|
73
92
|
if (!owns(ctx)) return;
|
|
74
93
|
idle(); stop?.(); stop = undefined;
|
|
94
|
+
unsubscribeSettings?.(); unsubscribeSettings = undefined;
|
|
75
95
|
publisher?.close(); publisher = undefined; owner = undefined; tasks = [];
|
|
76
96
|
});
|
|
77
97
|
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import net from "node:net";
|
|
2
|
+
import { posix, win32 } from "node:path";
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { HERDR_REPORTER_ENV } from "../lib/gentle-shell-launcher.ts";
|
|
5
|
+
import { herdrAgentLabel, herdrDetected } from "../lib/herdr-activity.ts";
|
|
6
|
+
|
|
7
|
+
// Gentle Shell's own Herdr agent integration (gentle-shell#2705). Herdr's
|
|
8
|
+
// managed Pi bridge always reports `agent: "pi"`, so the launcher stops
|
|
9
|
+
// loading it and sets HERDR_REPORTER_ENV; this extension then reports the
|
|
10
|
+
// same lifecycle under Herdr's documented custom-agent contract: its own
|
|
11
|
+
// stable source (never `herdr:`) and its own agent name. One reporter per pane.
|
|
12
|
+
const SOURCE = "gentle-shell";
|
|
13
|
+
|
|
14
|
+
type AgentState = "working" | "blocked" | "idle";
|
|
15
|
+
type HerdrRequest = { id: string; method: string; params: Record<string, unknown> };
|
|
16
|
+
|
|
17
|
+
interface HerdrAgentOptions {
|
|
18
|
+
env?: NodeJS.ProcessEnv;
|
|
19
|
+
send?: (request: HerdrRequest) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Same socket framing and retry budget as Herdr's bridge; failures never block Pi. */
|
|
23
|
+
function socketTransport(env: NodeJS.ProcessEnv): (request: HerdrRequest) => Promise<void> {
|
|
24
|
+
const socketPath = env.HERDR_SOCKET_PATH!;
|
|
25
|
+
const endpoint = process.platform === "win32" ? `\\\\.\\pipe\\${socketPath}` : socketPath;
|
|
26
|
+
const attempt = (request: HerdrRequest, timeoutMs: number) => new Promise<boolean>((resolve) => {
|
|
27
|
+
let done = false;
|
|
28
|
+
const socket = net.createConnection(endpoint);
|
|
29
|
+
const finish = (delivered: boolean) => {
|
|
30
|
+
if (done) return;
|
|
31
|
+
done = true;
|
|
32
|
+
clearTimeout(timeout);
|
|
33
|
+
socket.destroy();
|
|
34
|
+
resolve(delivered);
|
|
35
|
+
};
|
|
36
|
+
socket.on("error", () => finish(false));
|
|
37
|
+
socket.on("connect", () => socket.write(`${JSON.stringify(request)}\n`));
|
|
38
|
+
socket.on("data", () => finish(true));
|
|
39
|
+
socket.on("end", () => finish(false));
|
|
40
|
+
const timeout = setTimeout(() => finish(false), timeoutMs);
|
|
41
|
+
timeout.unref?.();
|
|
42
|
+
});
|
|
43
|
+
return async (request) => {
|
|
44
|
+
if (!(await attempt(request, 500))) await attempt(request, 1500);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createHerdrAgentExtension(options: HerdrAgentOptions = {}) {
|
|
49
|
+
return (pi: ExtensionAPI): void => {
|
|
50
|
+
const env = options.env ?? process.env;
|
|
51
|
+
if (env[HERDR_REPORTER_ENV] !== "1" || env.GENTLE_PI_AGENTS_CHILD === "1" || !herdrDetected(env)) return;
|
|
52
|
+
const agent = herdrAgentLabel(env);
|
|
53
|
+
const paneId = env.HERDR_PANE_ID!;
|
|
54
|
+
const send = options.send ?? socketTransport(env);
|
|
55
|
+
let seq = Date.now() * 1000;
|
|
56
|
+
let sessionRef: Record<string, string> | undefined;
|
|
57
|
+
let rootSession = false;
|
|
58
|
+
let agentActive = false;
|
|
59
|
+
let blockedCount = 0;
|
|
60
|
+
let blockedMessage: string | undefined;
|
|
61
|
+
let last: { state: AgentState; message?: string } | undefined;
|
|
62
|
+
let queued: { state: AgentState; message?: string; seq: number } | undefined;
|
|
63
|
+
let inFlight = false;
|
|
64
|
+
const request = (method: string, params: Record<string, unknown>): HerdrRequest => ({
|
|
65
|
+
id: `${SOURCE}:${Date.now()}:${Math.random().toString(36).slice(2)}`,
|
|
66
|
+
method,
|
|
67
|
+
params: { pane_id: paneId, source: SOURCE, agent, ...params, ...sessionRef },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Prefer the session file, as Herdr's bridge does; fall back to the id.
|
|
71
|
+
const updateSessionRef = (ctx: ExtensionContext) => {
|
|
72
|
+
let file: unknown;
|
|
73
|
+
let id: unknown;
|
|
74
|
+
try { file = ctx.sessionManager?.getSessionFile?.(); } catch { file = undefined; }
|
|
75
|
+
try { id = ctx.sessionManager?.getSessionId?.(); } catch { id = undefined; }
|
|
76
|
+
sessionRef = typeof file === "string" && (posix.isAbsolute(file) || win32.isAbsolute(file))
|
|
77
|
+
? { agent_session_path: file }
|
|
78
|
+
: typeof id === "string" && id.length > 0 ? { agent_session_id: id } : undefined;
|
|
79
|
+
};
|
|
80
|
+
const reportSession = (sessionStartSource?: string) => sessionRef
|
|
81
|
+
? send(request("pane.report_agent_session", { seq: ++seq, session_start_source: sessionStartSource })).catch(() => {})
|
|
82
|
+
: Promise.resolve();
|
|
83
|
+
// One report in flight, only the latest state queued behind it.
|
|
84
|
+
const drain = async () => {
|
|
85
|
+
if (inFlight) return;
|
|
86
|
+
inFlight = true;
|
|
87
|
+
try {
|
|
88
|
+
while (queued) {
|
|
89
|
+
const next = queued;
|
|
90
|
+
queued = undefined;
|
|
91
|
+
await send(request("pane.report_agent", { state: next.state, message: next.message, seq: next.seq })).catch(() => {});
|
|
92
|
+
}
|
|
93
|
+
} finally {
|
|
94
|
+
inFlight = false;
|
|
95
|
+
if (queued) void drain();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const publish = (force = false) => {
|
|
99
|
+
const next = blockedCount > 0 ? { state: "blocked" as const, message: blockedMessage }
|
|
100
|
+
: { state: agentActive ? "working" as const : "idle" as const, message: undefined };
|
|
101
|
+
if (!force && next.state === last?.state && next.message === last?.message) return;
|
|
102
|
+
last = next;
|
|
103
|
+
queued = { ...next, seq: ++seq };
|
|
104
|
+
void drain();
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
pi.events.on("herdr:blocked", (data: unknown) => {
|
|
108
|
+
if (!rootSession) return;
|
|
109
|
+
const event = data as { active?: boolean; label?: string } | undefined;
|
|
110
|
+
if (!event?.active) {
|
|
111
|
+
blockedCount = Math.max(0, blockedCount - 1);
|
|
112
|
+
if (blockedCount === 0) blockedMessage = undefined;
|
|
113
|
+
} else {
|
|
114
|
+
blockedCount += 1;
|
|
115
|
+
blockedMessage = event.label;
|
|
116
|
+
}
|
|
117
|
+
publish();
|
|
118
|
+
});
|
|
119
|
+
pi.on("session_start", async (event, ctx) => {
|
|
120
|
+
// TUI only: RPC still reports hasUI, so mode is the reliable gate.
|
|
121
|
+
if (ctx.mode !== "tui") return;
|
|
122
|
+
rootSession = true;
|
|
123
|
+
updateSessionRef(ctx);
|
|
124
|
+
await reportSession((event as { reason?: string } | undefined)?.reason);
|
|
125
|
+
// A reload can replace this extension mid-run without another agent_start.
|
|
126
|
+
agentActive = ctx.isIdle?.() === false;
|
|
127
|
+
publish(true);
|
|
128
|
+
});
|
|
129
|
+
pi.on("agent_start", (_event, ctx) => {
|
|
130
|
+
if (!rootSession) return;
|
|
131
|
+
updateSessionRef(ctx);
|
|
132
|
+
void reportSession();
|
|
133
|
+
agentActive = true;
|
|
134
|
+
publish();
|
|
135
|
+
});
|
|
136
|
+
pi.on("agent_settled", (_event, ctx) => {
|
|
137
|
+
if (!rootSession || ctx.isIdle?.() !== true) return;
|
|
138
|
+
agentActive = false;
|
|
139
|
+
publish();
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export default createHerdrAgentExtension();
|
|
@@ -27,6 +27,9 @@ export type MusicControlCommand = (typeof MUSIC_CONTROL_COMMANDS)[number];
|
|
|
27
27
|
|
|
28
28
|
export const MUSIC_INSTALL_TITLE = "Install the music player?";
|
|
29
29
|
export const MUSIC_INSTALL_OFFER = "Install the gentle-stream music player inside Gentle Shell? It downloads uv, Python 3.13 and the player (about 150 MB) into the Gentle Shell folder.";
|
|
30
|
+
// gentle-stream needs POSIX (fcntl locks, an AF_UNIX control socket, process
|
|
31
|
+
// groups), so a native Windows Pi can neither install nor run it; WSL is Linux.
|
|
32
|
+
export const MUSIC_WINDOWS_UNSUPPORTED = "/gentle:music is not available on Windows yet: the gentle-stream player runs on macOS and Linux. It works when Gentle Shell runs inside WSL.";
|
|
30
33
|
const UV_INSTALL_URL = "https://docs.astral.sh/uv/getting-started/installation/";
|
|
31
34
|
const CTL_TIMEOUT_MS = 30_000;
|
|
32
35
|
const SHUTDOWN_TIMEOUT_MS = 2_000;
|
|
@@ -85,6 +88,8 @@ export interface GentleMusicDeps {
|
|
|
85
88
|
which?: MusicWhich;
|
|
86
89
|
/** The bundled install's player, or undefined outside a bundled install. */
|
|
87
90
|
bundled?: () => Promise<BundledMusicPlayer | undefined>;
|
|
91
|
+
/** The platform Pi runs on; gentle-stream does not run on native Windows. */
|
|
92
|
+
platform?: NodeJS.Platform;
|
|
88
93
|
spawn?: MusicSpawn;
|
|
89
94
|
signals?: MusicSignals;
|
|
90
95
|
usage?: MusicUsage;
|
|
@@ -259,6 +264,7 @@ export default function gentleMusic(pi: ExtensionAPI, deps: GentleMusicDeps = {}
|
|
|
259
264
|
const usage = deps.usage ?? processUsage();
|
|
260
265
|
const shutdownTimeoutMs = deps.shutdownTimeoutMs ?? SHUTDOWN_TIMEOUT_MS;
|
|
261
266
|
const bundled = deps.bundled ?? defaultBundled;
|
|
267
|
+
const platform = deps.platform ?? process.platform;
|
|
262
268
|
|
|
263
269
|
const findPlayer = async (): Promise<{ stream?: GentleStreamCommand; offer?: BundledMusicPlayer }> => {
|
|
264
270
|
let player: BundledMusicPlayer | undefined;
|
|
@@ -326,6 +332,10 @@ export default function gentleMusic(pi: ExtensionAPI, deps: GentleMusicDeps = {}
|
|
|
326
332
|
description: "Open gentle-stream full screen (optional mood text); b returns with the music playing, q stops it. next, pause, play, stop, status control the music without leaving Pi.",
|
|
327
333
|
handler: async (args, ctx) => {
|
|
328
334
|
if (!ctx.hasUI) return;
|
|
335
|
+
if (platform === "win32") {
|
|
336
|
+
ctx.ui.notify(MUSIC_WINDOWS_UNSUPPORTED, "warning");
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
329
339
|
if (ctx.mode !== "tui") {
|
|
330
340
|
ctx.ui.notify("/gentle:music needs the interactive terminal.", "warning");
|
|
331
341
|
return;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { ProgramStatus, Terminal } from "@earendil-works/pi-tui";
|
|
3
|
+
|
|
4
|
+
const WIDGET_KEY = "gentle-shell:program-identity";
|
|
5
|
+
const STATES = new Set(["idle", "working", "blocked", "done", "error", "clear"]);
|
|
6
|
+
|
|
7
|
+
function installIdentity(terminal: Terminal): () => void {
|
|
8
|
+
const original = terminal.setProgramStatus;
|
|
9
|
+
if (typeof original !== "function") return () => {};
|
|
10
|
+
let active = true;
|
|
11
|
+
let latest: ProgramStatus | undefined;
|
|
12
|
+
const wrapped = (status: ProgramStatus) => {
|
|
13
|
+
if (!active) return original.call(terminal, status);
|
|
14
|
+
latest = { ...status };
|
|
15
|
+
original.call(terminal, status.state === "clear" ? status : { ...status, app: "gentle-shell" });
|
|
16
|
+
};
|
|
17
|
+
terminal.setProgramStatus = wrapped;
|
|
18
|
+
|
|
19
|
+
// Pi reports before session_start. Replay its exact cached state rather than
|
|
20
|
+
// inventing idle and potentially erasing a native blocked/working report.
|
|
21
|
+
// This cache is a guarded Pi implementation detail, not an extension API.
|
|
22
|
+
const cached = (terminal as unknown as { programStatus?: unknown }).programStatus;
|
|
23
|
+
if (cached && typeof cached === "object" && "state" in cached
|
|
24
|
+
&& typeof cached.state === "string" && STATES.has(cached.state)) {
|
|
25
|
+
wrapped(cached as ProgramStatus);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
if (!active) return;
|
|
30
|
+
active = false;
|
|
31
|
+
// A later extension may wrap ours. Leave its method installed; our
|
|
32
|
+
// inactive wrapper becomes a transparent pass-through in that chain.
|
|
33
|
+
if (terminal.setProgramStatus !== wrapped) return;
|
|
34
|
+
terminal.setProgramStatus = original;
|
|
35
|
+
if (latest) original.call(terminal, latest);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createProgramIdentityExtension(env: NodeJS.ProcessEnv = process.env) {
|
|
40
|
+
return (pi: ExtensionAPI): void => {
|
|
41
|
+
if (env.PI_PROGRAM_STATUS_APP !== "gentle-shell" || env.GENTLE_PI_AGENTS_CHILD === "1") return;
|
|
42
|
+
let dispose: (() => void) | undefined;
|
|
43
|
+
pi.on("session_start", (_event, ctx) => {
|
|
44
|
+
dispose?.(); dispose = undefined;
|
|
45
|
+
if (ctx.mode !== "tui" || !ctx.hasUI) return;
|
|
46
|
+
ctx.ui.setWidget(WIDGET_KEY, (tui) => {
|
|
47
|
+
const cleanup = installIdentity(tui.terminal);
|
|
48
|
+
dispose = cleanup;
|
|
49
|
+
return { render: () => [], invalidate() {}, dispose: cleanup };
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
pi.on("session_shutdown", (_event, ctx) => {
|
|
53
|
+
const cleanup = dispose;
|
|
54
|
+
dispose = undefined;
|
|
55
|
+
cleanup?.();
|
|
56
|
+
if (cleanup && ctx.mode === "tui" && ctx.hasUI) ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default createProgramIdentityExtension();
|