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,73 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import fast from "../extensions/gentle-fast.ts";
|
|
4
|
+
import { PROFILE_TIER_EVENT } from "../lib/openai-fast-tier.ts";
|
|
5
|
+
|
|
6
|
+
const native = { provider: "openai", api: "openai-responses", id: "gpt-6.1-sol" };
|
|
7
|
+
const legacy = { provider: "openai-codex", api: "openai-codex-responses", id: "gpt-5.6-sol" };
|
|
8
|
+
|
|
9
|
+
function harness(model: any = native) {
|
|
10
|
+
const events = new Map<string, Function>();
|
|
11
|
+
const bus = new Map<string, Function>();
|
|
12
|
+
const commands = new Map<string, any>();
|
|
13
|
+
const statuses: (string | undefined)[] = [];
|
|
14
|
+
const ctx: any = { model, hasUI: true, sessionManager: { getSessionId: () => "fast-test" }, ui: { setStatus: (_key: string, value?: string) => statuses.push(value) } };
|
|
15
|
+
fast({ on: (name: string, fn: Function) => events.set(name, fn), events: { on: (name: string, fn: Function) => bus.set(name, fn) }, registerCommand: (name: string, command: any) => commands.set(name, command) } as any);
|
|
16
|
+
events.get("session_start")!({}, ctx);
|
|
17
|
+
return {
|
|
18
|
+
ctx, commands, statuses, hasEvent: (name: string) => events.has(name),
|
|
19
|
+
profile(tier?: string, ref = `${ctx.model.provider}/${ctx.model.id}`, id = "fast-test") { bus.get(PROFILE_TIER_EVENT)!({ sessionId: id, tier, model: ref }); },
|
|
20
|
+
event: (name: string, event: any = {}) => events.get(name)!(event, ctx),
|
|
21
|
+
request: (payload: unknown) => events.get("before_provider_request")!({ payload }, ctx),
|
|
22
|
+
stream: (data: unknown, source: any = ctx.model) => events.get("provider_stream_event")?.({ provider: source.provider, api: source.api, model: source.id, data }, ctx),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test("Profiles replaces the slash selector", () => {
|
|
27
|
+
const h = harness();
|
|
28
|
+
assert.equal(h.commands.has("fast"), false);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("Fast request handling publishes no integration status or response observer", () => {
|
|
32
|
+
for (const model of [native, legacy]) {
|
|
33
|
+
const h = harness(model);
|
|
34
|
+
h.profile("fast");
|
|
35
|
+
assert.equal((h.request({}) as any).service_tier, "priority");
|
|
36
|
+
h.stream({ type: "response.completed", response: { service_tier: "default" } });
|
|
37
|
+
assert.deepEqual(h.statuses, []);
|
|
38
|
+
assert.equal(h.hasEvent("provider_stream_event"), false);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("profile, model, session and tree changes keep request tier authority", () => {
|
|
43
|
+
const h = harness();
|
|
44
|
+
h.profile("fast"); assert.equal((h.request({}) as any).service_tier, "priority");
|
|
45
|
+
h.profile("standard", undefined, "foreign-session");
|
|
46
|
+
assert.equal((h.request({}) as any).service_tier, "priority");
|
|
47
|
+
h.profile("standard"); assert.equal((h.request({}) as any).service_tier, "default");
|
|
48
|
+
h.ctx.model = legacy; h.event("model_select", { model: legacy });
|
|
49
|
+
assert.equal(h.request({}), undefined);
|
|
50
|
+
h.profile("fast"); assert.equal((h.request({}) as any).service_tier, "priority");
|
|
51
|
+
h.event("session_tree"); assert.equal(h.request({}), undefined);
|
|
52
|
+
h.profile("fast"); h.event("session_start"); assert.equal(h.request({}), undefined);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("profile tiers rewrite only supported routes and preserve payload fields", () => {
|
|
56
|
+
const ids = ["gpt-5.6-luna", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-6-astra", "gpt-6-sol", "gpt-6-luna", "gpt-6.1-sol", "gpt-6.1-terra"];
|
|
57
|
+
for (const model of [native, legacy, ...ids.map((id) => ({ ...native, id }))]) {
|
|
58
|
+
const h = harness(model); h.profile("fast");
|
|
59
|
+
const payload = { model: model.id, input: [{ text: "hello" }], service_tier: "flex", tools: [{ type: "function" }] };
|
|
60
|
+
assert.deepEqual(h.request(payload), { ...payload, service_tier: "priority" });
|
|
61
|
+
assert.equal(payload.service_tier, "flex");
|
|
62
|
+
h.profile("standard"); assert.equal((h.request(payload) as any).service_tier, "default");
|
|
63
|
+
for (const invalid of [null, [], "text"]) assert.equal(h.request(invalid), undefined);
|
|
64
|
+
}
|
|
65
|
+
for (const model of [{ ...native, provider: "proxy" }, { ...native, api: "openai-completions" }, { ...native, provider: "openai-codex" }, { ...legacy, provider: "openai" }, { ...native, id: "gpt-6.1-sol-future" }, { ...native, id: "gpt-5.5" }]) {
|
|
66
|
+
const h = harness(model); h.profile("fast");
|
|
67
|
+
assert.equal(h.request({ service_tier: "flex" }), undefined);
|
|
68
|
+
h.stream({ type: "response.completed", response: { service_tier: "priority" } });
|
|
69
|
+
assert.deepEqual(h.statuses, []);
|
|
70
|
+
}
|
|
71
|
+
const h = harness();
|
|
72
|
+
assert.equal(h.request({ service_tier: "flex" }), undefined);
|
|
73
|
+
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test, { after } from "node:test";
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import installGentleGuide, { GUIDE_AGENT_REQUEST, GUIDE_PROMPT_HINT } from "../extensions/gentle-guide.ts";
|
|
5
|
+
import { GUIDE_STEPS, GuidePopover, GuideTour, guidePlacement, guideSteps, type GuideStep } from "../lib/gentle-guide.ts";
|
|
6
|
+
import { sidebarState } from "../lib/shell-sidebar.ts";
|
|
7
|
+
import { buildCommandPaletteGroups } from "../lib/command-palette-catalog.ts";
|
|
8
|
+
import { stripAnsi } from "../lib/terminal-theme.ts";
|
|
9
|
+
import { isolatedConfigEnv, keymapsConfigHome, removeIsolatedConfigHomes } from "./isolated-config-home.ts";
|
|
10
|
+
|
|
11
|
+
// /gentle:guide: a driver.js-style tour. Each step is a popover next to the
|
|
12
|
+
// part of the screen it describes; the agent drives it with the gentle_guide
|
|
13
|
+
// tool and explains each step in the chat, or the user steps through it
|
|
14
|
+
// locally with the arrow keys when no agent is available.
|
|
15
|
+
|
|
16
|
+
after(removeIsolatedConfigHomes);
|
|
17
|
+
|
|
18
|
+
const plainTheme = { fg: (_color: string, text: string) => text };
|
|
19
|
+
const ALL = new Set(GUIDE_STEPS.flatMap((step) => step.requires ? [step.requires] : []));
|
|
20
|
+
|
|
21
|
+
function sample(): GuideStep[] {
|
|
22
|
+
return [
|
|
23
|
+
{ id: "welcome", title: "Welcome", body: "Hello there.", region: "center" },
|
|
24
|
+
{ id: "palette", title: "Command palette", body: "Every command, searchable.", region: "editor", command: "gentle:commands", keymap: "commands" },
|
|
25
|
+
{ id: "end", title: "Done", body: "Bye.", region: "center" },
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test("the tour keeps only steps whose command or tool exists, and starts with a welcome and ends with a goodbye", () => {
|
|
30
|
+
const full = guideSteps(ALL);
|
|
31
|
+
assert.equal(full[0]!.id, "welcome");
|
|
32
|
+
assert.equal(full.at(-1)!.id, "end");
|
|
33
|
+
assert.ok(full.length >= 12, "it covers what Gentle Shell can do");
|
|
34
|
+
const bare = guideSteps(new Set(["gentle:commands"]));
|
|
35
|
+
assert.deepEqual(bare.map((step) => step.id), ["welcome", "prompt", "palette", "end"]);
|
|
36
|
+
for (const step of GUIDE_STEPS) assert.ok(step.title && step.body, step.id);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("the popover shows the step, its counter, how to try it with its current key, and the local keys", () => {
|
|
40
|
+
const tour = new GuideTour(sample());
|
|
41
|
+
tour.next();
|
|
42
|
+
const popover = new GuidePopover({ tour, mode: "local", theme: plainTheme, env: isolatedConfigEnv({ GENTLE_PI_CONFIG_HOME: keymapsConfigHome({ commands: "alt+j" }) }), done: () => {} });
|
|
43
|
+
const text = popover.render(56).map(stripAnsi).join("\n");
|
|
44
|
+
assert.match(text, /Command palette\s+2\/3/);
|
|
45
|
+
assert.match(text, /Every command, searchable\./);
|
|
46
|
+
assert.match(text, /Try: \/gentle:commands · alt\+j/);
|
|
47
|
+
assert.match(text, /→ next · ← back · esc end/);
|
|
48
|
+
for (const line of popover.render(56)) assert.ok(stripAnsi(line).length <= 56, line);
|
|
49
|
+
const agent = new GuidePopover({ tour, mode: "agent", theme: plainTheme, env: isolatedConfigEnv({}), done: () => {} });
|
|
50
|
+
assert.match(agent.render(56).map(stripAnsi).join("\n"), /Reply in the chat · \/gentle:guide stop ends/);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("locally, arrows and enter move through the steps, and esc or the last step ends the tour", () => {
|
|
54
|
+
const results: string[] = [];
|
|
55
|
+
const tour = new GuideTour(sample());
|
|
56
|
+
const popover = new GuidePopover({ tour, mode: "local", theme: plainTheme, env: isolatedConfigEnv({}), done: (result) => results.push(result) });
|
|
57
|
+
popover.handleInput("\x1b[C");
|
|
58
|
+
assert.equal(tour.current().id, "palette");
|
|
59
|
+
popover.handleInput("\x1b[D");
|
|
60
|
+
assert.equal(tour.current().id, "welcome");
|
|
61
|
+
popover.handleInput("\x1b[D");
|
|
62
|
+
assert.equal(tour.current().id, "welcome", "back on the first step stays there");
|
|
63
|
+
popover.handleInput("\r");
|
|
64
|
+
popover.handleInput(" ");
|
|
65
|
+
assert.equal(tour.current().id, "end");
|
|
66
|
+
popover.handleInput("\r");
|
|
67
|
+
assert.deepEqual(results, ["finished"]);
|
|
68
|
+
const early: string[] = [];
|
|
69
|
+
new GuidePopover({ tour: new GuideTour(sample()), mode: "local", theme: plainTheme, env: isolatedConfigEnv({}), done: (result) => early.push(result) }).handleInput("\x1b");
|
|
70
|
+
assert.deepEqual(early, ["ended"]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("the popover sits beside the region it describes and never takes the prompt's focus in agent mode", () => {
|
|
74
|
+
assert.deepEqual(guidePlacement("sidebar", 160, 53, "local"), { anchor: "right-center", offsetX: -54, width: 56, nonCapturing: false });
|
|
75
|
+
assert.deepEqual(guidePlacement("sidebar", 120, undefined, "agent"), { anchor: "center", width: 56, nonCapturing: true });
|
|
76
|
+
assert.deepEqual(guidePlacement("editor", 100, undefined, "agent"), { anchor: "bottom-center", offsetY: -6, width: 56, nonCapturing: true });
|
|
77
|
+
assert.deepEqual(guidePlacement("center", 44, undefined, "local"), { anchor: "center", width: 40, nonCapturing: false });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
interface Overlay { component: { render(width: number): string[]; handleInput(data: string): void }; options: () => Record<string, unknown>; done(value: unknown): void; settled: Promise<unknown> }
|
|
81
|
+
|
|
82
|
+
function harness(options: { model?: boolean; env?: NodeJS.ProcessEnv } = {}) {
|
|
83
|
+
const commands = new Map<string, { handler(args: string, ctx: ExtensionContext): Promise<void> }>();
|
|
84
|
+
const tools = new Map<string, { execute(id: string, params: unknown, signal: undefined, update: undefined, ctx: ExtensionContext): Promise<{ content: { text: string }[] }> }>();
|
|
85
|
+
const handlers = new Map<string, (event: unknown, ctx?: ExtensionContext) => unknown>();
|
|
86
|
+
const messages: Array<{ message: Record<string, unknown>; options: Record<string, unknown> }> = [];
|
|
87
|
+
const pi = {
|
|
88
|
+
registerCommand: (name: string, command: never) => commands.set(name, command),
|
|
89
|
+
registerTool: (tool: { name: string }) => tools.set(tool.name, tool as never),
|
|
90
|
+
on: (name: string, handler: never) => handlers.set(name, handler),
|
|
91
|
+
getCommands: () => [{ name: "gentle:commands" }, { name: "gentle:guide" }],
|
|
92
|
+
getAllTools: () => [],
|
|
93
|
+
sendMessage: (message: Record<string, unknown>, sendOptions: Record<string, unknown>) => messages.push({ message, options: sendOptions }),
|
|
94
|
+
} as unknown as ExtensionAPI;
|
|
95
|
+
installGentleGuide(pi, isolatedConfigEnv(options.env ?? {}));
|
|
96
|
+
const overlays: Overlay[] = [];
|
|
97
|
+
const notices: string[] = [];
|
|
98
|
+
const tui = { terminal: { columns: 160, rows: 40 }, requestRender() {} };
|
|
99
|
+
const ctx = {
|
|
100
|
+
hasUI: true, mode: "tui", model: options.model === false ? undefined : { id: "m", provider: "p" }, isIdle: () => true,
|
|
101
|
+
ui: {
|
|
102
|
+
notify: (message: string) => notices.push(message),
|
|
103
|
+
custom: (factory: (tui: unknown, theme: unknown, keys: unknown, done: (value: unknown) => void) => Overlay["component"], customOptions: { overlayOptions: Record<string, unknown> | (() => Record<string, unknown>) }) => {
|
|
104
|
+
let resolve!: (value: unknown) => void;
|
|
105
|
+
const settled = new Promise((done) => { resolve = done; });
|
|
106
|
+
// Pi reads overlay options once, when the overlay opens.
|
|
107
|
+
const placed = typeof customOptions.overlayOptions === "function" ? customOptions.overlayOptions() : customOptions.overlayOptions;
|
|
108
|
+
const overlay = { options: () => placed, settled } as Overlay;
|
|
109
|
+
overlay.done = resolve;
|
|
110
|
+
overlay.component = factory(tui, plainTheme, undefined, resolve);
|
|
111
|
+
overlays.push(overlay);
|
|
112
|
+
return settled;
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
} as unknown as ExtensionContext;
|
|
116
|
+
const call = async (params: unknown) => (await tools.get("gentle_guide")!.execute("t", params, undefined, undefined, ctx)).content[0]!.text;
|
|
117
|
+
return { commands, tools, handlers, messages, overlays, notices, ctx, tui, call };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
test("/gentle:guide asks the agent to drive the tour, which shows one step at a time beside the prompt", async () => {
|
|
121
|
+
const h = harness();
|
|
122
|
+
await h.commands.get("gentle:guide")!.handler("", h.ctx);
|
|
123
|
+
assert.deepEqual(h.messages, [{ message: { customType: "gentle-guide", content: GUIDE_AGENT_REQUEST, display: false }, options: { triggerTurn: true } }]);
|
|
124
|
+
assert.deepEqual(h.notices, ["Starting the guided tour with the agent…"]);
|
|
125
|
+
const started = await h.call({ action: "start" });
|
|
126
|
+
assert.match(started, /^Step 1\/4 · Welcome to Gentle Shell/);
|
|
127
|
+
assert.match(started, /Tour steps: Welcome to Gentle Shell, The prompt, Command palette, That's the tour/);
|
|
128
|
+
assert.equal(h.overlays.length, 1);
|
|
129
|
+
assert.equal(h.overlays[0]!.options().nonCapturing, true, "the user keeps typing in the prompt");
|
|
130
|
+
assert.match(await h.call({ action: "next" }), /^Step 2\/4 · The prompt/);
|
|
131
|
+
assert.equal(await h.overlays[0]!.settled, "moved", "a step for another region reopens the popover there");
|
|
132
|
+
assert.equal(h.overlays.length, 2);
|
|
133
|
+
assert.match(h.overlays[1]!.component.render(56).map(stripAnsi).join("\n"), /The prompt\s+2\/4/);
|
|
134
|
+
assert.deepEqual(h.overlays[1]!.options(), { anchor: "bottom-center", offsetY: -6, width: 56, nonCapturing: true });
|
|
135
|
+
assert.match(await h.call({ action: "show", step: "palette" }), /^Step 3\/4 · Command palette/);
|
|
136
|
+
assert.match(await h.call({ action: "show", step: "nope" }), /Unknown step "nope"\. Steps: welcome, prompt, palette, end/);
|
|
137
|
+
assert.match(await h.call({ action: "previous" }), /^Step 2\/4/);
|
|
138
|
+
await h.call({ action: "next" });
|
|
139
|
+
assert.match(await h.call({ action: "next" }), /^Step 4\/4 · That's the tour.*\nThis is the last step: call gentle_guide with action "end"/s);
|
|
140
|
+
assert.match(await h.call({ action: "next" }), /This was the last step/);
|
|
141
|
+
assert.equal(await h.call({ action: "end" }), "Tour ended.");
|
|
142
|
+
assert.equal(await h.overlays.at(-1)!.settled, "ended", "the popover closes");
|
|
143
|
+
assert.equal(await h.call({ action: "next" }), 'No tour is running. Call gentle_guide with action "start".');
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("/gentle:guide stop and session shutdown close the popover; starting again replaces it", async () => {
|
|
147
|
+
const h = harness();
|
|
148
|
+
await h.call({ action: "start" });
|
|
149
|
+
await h.call({ action: "start" });
|
|
150
|
+
assert.equal(h.overlays.length, 2);
|
|
151
|
+
await h.overlays[0]!.settled;
|
|
152
|
+
await h.commands.get("gentle:guide")!.handler("stop", h.ctx);
|
|
153
|
+
await h.overlays[1]!.settled;
|
|
154
|
+
assert.equal(h.notices.at(-1), "Guided tour ended.");
|
|
155
|
+
await h.commands.get("gentle:guide")!.handler("stop", h.ctx);
|
|
156
|
+
assert.equal(h.notices.at(-1), "No guided tour is running.");
|
|
157
|
+
await h.call({ action: "start" });
|
|
158
|
+
h.handlers.get("session_shutdown")!({});
|
|
159
|
+
await h.overlays[2]!.settled;
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test("without a model, or with local, the tour runs locally with the arrow keys", async () => {
|
|
163
|
+
for (const [model, args] of [[false, ""], [true, "local"]] as const) {
|
|
164
|
+
const h = harness({ model });
|
|
165
|
+
const run = h.commands.get("gentle:guide")!.handler(args, h.ctx);
|
|
166
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
167
|
+
assert.equal(h.messages.length, 0, "no agent turn");
|
|
168
|
+
assert.equal(h.overlays[0]!.options().nonCapturing, false, "the popover owns the keys");
|
|
169
|
+
for (let i = 0; i < 4; i++) {
|
|
170
|
+
h.overlays.at(-1)!.component.handleInput("\r");
|
|
171
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
172
|
+
}
|
|
173
|
+
await run;
|
|
174
|
+
assert.equal(h.overlays.length, 3, "welcome, then the prompt below, then back to the center");
|
|
175
|
+
assert.equal(h.notices.at(-1), "Tour finished. Run /gentle:guide any time to see it again.");
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("the agent is told about the tour, children get neither the tool nor the command", () => {
|
|
180
|
+
const h = harness();
|
|
181
|
+
const event = { systemPromptOptions: { appendSystemPrompt: "" } };
|
|
182
|
+
h.handlers.get("before_agent_start")!(event);
|
|
183
|
+
assert.equal(event.systemPromptOptions.appendSystemPrompt, GUIDE_PROMPT_HINT);
|
|
184
|
+
const child = harness({ env: { GENTLE_PI_AGENTS_CHILD: "1" } });
|
|
185
|
+
assert.equal(child.commands.size + child.tools.size, 0);
|
|
186
|
+
assert.ok(sidebarState(h.tui as never), "the fake terminal carries sidebar state");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("without a terminal the agent still walks the steps in text, and no popover opens", async () => {
|
|
190
|
+
const h = harness();
|
|
191
|
+
(h.ctx as unknown as { mode: string }).mode = "rpc";
|
|
192
|
+
assert.match(await h.call({ action: "start" }), /^Step 1\/4 · Welcome to Gentle Shell/);
|
|
193
|
+
assert.match(await h.call({ action: "next" }), /^Step 2\/4 · The prompt/);
|
|
194
|
+
assert.equal(await h.call({ action: "end" }), "Tour ended.");
|
|
195
|
+
assert.equal(h.overlays.length, 0);
|
|
196
|
+
assert.equal(await h.call({ action: "next" }), 'No tour is running. Call gentle_guide with action "start".');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
test("the palette lists the guided tour", () => {
|
|
200
|
+
const groups = buildCommandPaletteGroups([{ name: "gentle:guide", description: "Tour" }], {});
|
|
201
|
+
assert.deepEqual(groups.flatMap((group) => group.items.map((item) => [group.title, item.label])), [["Session", "Guided tour of Gentle Shell"]]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("a usage error lists the accepted arguments", async () => {
|
|
205
|
+
const h = harness();
|
|
206
|
+
await h.commands.get("gentle:guide")!.handler("bogus", h.ctx);
|
|
207
|
+
assert.equal(h.notices.at(-1), "Usage: /gentle:guide [local|stop]");
|
|
208
|
+
});
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { resolve, join } from "node:path";
|
|
3
5
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
6
|
import { createHerdrActivityExtension } from "../extensions/gentle-herdr-activity.ts";
|
|
5
7
|
import { oddPhaseRegistry } from "../lib/odd-phase.ts";
|
|
6
|
-
import { metadataArgs } from "../lib/herdr-activity.ts";
|
|
8
|
+
import { herdrAgentLabel, metadataArgs } from "../lib/herdr-activity.ts";
|
|
7
9
|
|
|
8
10
|
type Handler = (event: any, ctx: ExtensionContext) => void;
|
|
9
11
|
function harness(overrides: NodeJS.ProcessEnv = {}, socket = true) {
|
|
12
|
+
const home = resolve("odd/work/herdr-auto-apply-B/activity");
|
|
13
|
+
mkdirSync(home, { recursive: true });
|
|
14
|
+
const configHome = mkdtempSync(join(home, "session-"));
|
|
15
|
+
const subscribers = new Set<(data: unknown) => void>();
|
|
10
16
|
const handlers = new Map<string, Handler>();
|
|
11
17
|
const values: Array<string | null> = [];
|
|
12
18
|
const reports: string[][] = [];
|
|
@@ -15,6 +21,7 @@ function harness(overrides: NodeJS.ProcessEnv = {}, socket = true) {
|
|
|
15
21
|
let now = 1000;
|
|
16
22
|
let columns = 30;
|
|
17
23
|
const options = {
|
|
24
|
+
gentlePiConfigHome: configHome,
|
|
18
25
|
env: { HERDR_ENV: "1", HERDR_PANE_ID: "pane", HERDR_SOCKET_PATH: "/socket", ...overrides },
|
|
19
26
|
isSocket: () => socket,
|
|
20
27
|
now: () => now,
|
|
@@ -24,9 +31,21 @@ function harness(overrides: NodeJS.ProcessEnv = {}, socket = true) {
|
|
|
24
31
|
},
|
|
25
32
|
watch: (fn: () => void) => { tick = fn; return () => { stopped = true; }; },
|
|
26
33
|
};
|
|
27
|
-
createHerdrActivityExtension(options)({
|
|
34
|
+
createHerdrActivityExtension(options)({
|
|
35
|
+
on: (name: string, fn: Handler) => handlers.set(name, fn),
|
|
36
|
+
events: { on: (name: string, fn: (data: unknown) => void) => {
|
|
37
|
+
assert.equal(name, "gentle-pi:herdr-task-summary:changed");
|
|
38
|
+
subscribers.add(fn); return () => subscribers.delete(fn);
|
|
39
|
+
} },
|
|
40
|
+
} as unknown as ExtensionAPI);
|
|
28
41
|
const ctx = { mode: "tui", hasUI: true, sessionManager: { getSessionId: () => "root", getBranch: () => [] } } as unknown as ExtensionContext;
|
|
29
42
|
return { handlers, values, reports, ctx, tick: () => tick?.(), stopped: () => stopped,
|
|
43
|
+
listeners: () => subscribers.size,
|
|
44
|
+
settings: (enabled: boolean) => writeFileSync(join(configHome, "herdr-task-summary.json"), JSON.stringify({
|
|
45
|
+
schema: "gentle-pi.herdr-task-summary/v1", enabled, summaryColor: "success", continuationColor: "dim",
|
|
46
|
+
})),
|
|
47
|
+
change: (home = configHome) => { for (const fn of subscribers) fn({ configHome: home }); },
|
|
48
|
+
malformed: () => writeFileSync(join(configHome, "herdr-task-summary.json"), "{"),
|
|
30
49
|
advance: (ms: number) => { now += ms; }, columns: (value: number) => { columns = value; },
|
|
31
50
|
fire: (name: string, event = {}, context = ctx) => handlers.get(name)?.(event, context) };
|
|
32
51
|
}
|
|
@@ -34,6 +53,51 @@ const wait = () => new Promise((resolve) => setTimeout(resolve, 180));
|
|
|
34
53
|
const todo = (title?: string) => ({ toolName: "todo", result: { details: { gentleTodo: {
|
|
35
54
|
tasks: title === undefined ? [] : [{ title, status: "in_progress" }],
|
|
36
55
|
} } } });
|
|
56
|
+
test("live disable clears only owned rows, tracks Todo and resumes latest working title", async () => {
|
|
57
|
+
const h = harness(); assert.equal(h.listeners(), 0);
|
|
58
|
+
h.fire("session_start"); assert.equal(h.listeners(), 1);
|
|
59
|
+
h.fire("agent_start"); h.fire("tool_execution_end", todo("first")); await wait();
|
|
60
|
+
const before = h.values.length;
|
|
61
|
+
h.settings(false); h.change("/different-home"); await wait(); assert.equal(h.values.length, before);
|
|
62
|
+
h.change(); assert.equal(h.values.at(-1), null); await wait();
|
|
63
|
+
assert.equal(h.values.length, before + 1);
|
|
64
|
+
assert.deepEqual(h.reports.at(-1)?.slice(-4), ["--clear-token", "summary", "--clear-token", "summary2"]);
|
|
65
|
+
h.fire("tool_execution_end", todo("latest")); h.advance(10000); h.tick(); await wait();
|
|
66
|
+
assert.equal(h.values.length, before + 1);
|
|
67
|
+
h.settings(true); h.change(); await wait(); assert.equal(h.values.at(-1), "◐ latest");
|
|
68
|
+
assert.deepEqual(h.reports.at(-1)?.slice(-4), ["--token", "summary=◐ latest", "--clear-token", "summary2"]);
|
|
69
|
+
for (let i = 1; i < h.reports.length; i++) assert.equal(Number(h.reports[i][8]), Number(h.reports[i - 1][8]) + 1);
|
|
70
|
+
h.fire("session_shutdown"); await wait(); assert.equal(h.listeners(), 0); assert.ok(h.stopped());
|
|
71
|
+
const closed = h.values.length; h.settings(false); h.change(); h.tick(); await wait();
|
|
72
|
+
assert.equal(h.values.length, closed);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("disable supersedes queued title; idle and replaced sessions cannot resume stale activity", async () => {
|
|
76
|
+
const h = harness(); h.fire("session_start"); h.fire("agent_start");
|
|
77
|
+
h.fire("tool_execution_end", todo("queued")); h.settings(false); h.change(); await wait();
|
|
78
|
+
assert.ok(!h.values.includes("◐ queued"));
|
|
79
|
+
h.fire("tool_execution_end", todo("hidden")); h.fire("agent_settled");
|
|
80
|
+
const idle = h.values.length; h.settings(true); h.change(); await wait(); assert.equal(h.values.length, idle);
|
|
81
|
+
h.fire("agent_start"); await wait(); assert.equal(h.values.at(-1), "◐ hidden");
|
|
82
|
+
h.settings(false); h.change(); h.fire("session_start"); assert.equal(h.listeners(), 1); await wait();
|
|
83
|
+
const replaced = h.values.length; h.settings(true); h.change(); await wait(); assert.equal(h.values.length, replaced);
|
|
84
|
+
h.fire("session_shutdown");
|
|
85
|
+
const child = harness({ GENTLE_PI_AGENTS_CHILD: "1" }); child.settings(false);
|
|
86
|
+
child.fire("session_start"); child.settings(true); child.change(); child.fire("agent_start");
|
|
87
|
+
child.fire("tool_execution_end", todo("child")); await wait();
|
|
88
|
+
assert.deepEqual(child.values, []); assert.equal(child.listeners(), 0);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("initial disabled preference and rejected live changes have no summary effects", async () => {
|
|
92
|
+
const h = harness(); h.settings(false); h.fire("session_start"); h.fire("agent_start");
|
|
93
|
+
h.fire("tool_execution_end", todo("hidden")); h.tick(); await wait(); assert.deepEqual(h.values, [null]);
|
|
94
|
+
h.malformed(); h.change(); h.tick(); await wait(); assert.deepEqual(h.values, [null]);
|
|
95
|
+
h.settings(true); h.change(); await wait(); assert.deepEqual(h.values, [null, "◐ hidden"]);
|
|
96
|
+
const reports = structuredClone(h.reports);
|
|
97
|
+
h.malformed(); h.change(); h.tick(); await wait(); assert.deepEqual(h.reports, reports);
|
|
98
|
+
h.fire("session_shutdown");
|
|
99
|
+
});
|
|
100
|
+
|
|
37
101
|
test("tools and failed Todo snapshots never supply fallback summaries", async () => {
|
|
38
102
|
const h = harness(); h.fire("session_start"); h.fire("agent_start");
|
|
39
103
|
h.fire("tool_execution_start", { toolName: "read", args: { path: "secret" } });
|
|
@@ -89,6 +153,16 @@ test("width changes reproject and long-to-short/no-task/idle clear both rows tog
|
|
|
89
153
|
h.fire("session_shutdown");
|
|
90
154
|
});
|
|
91
155
|
|
|
156
|
+
test("activity metadata follows the agent label that owns the pane", () => {
|
|
157
|
+
assert.equal(herdrAgentLabel({ GENTLE_SHELL_HERDR_REPORTER: "1" }), "gentle-shell");
|
|
158
|
+
assert.equal(herdrAgentLabel({}), "pi");
|
|
159
|
+
assert.equal(herdrAgentLabel({ GENTLE_SHELL_HERDR_REPORTER: "0" }), "pi");
|
|
160
|
+
assert.deepEqual(metadataArgs("pane", "◐ one", 7, "gentle-shell"), ["pane", "report-metadata", "pane", "--source", "gentle:activity",
|
|
161
|
+
"--agent", "gentle-shell", "--seq", "7", "--ttl-ms", "30000", "--token", "summary=◐ one", "--clear-token", "summary2"]);
|
|
162
|
+
assert.deepEqual(metadataArgs("pane", null, 8), ["pane", "report-metadata", "pane", "--source", "gentle:activity",
|
|
163
|
+
"--agent", "pi", "--seq", "8", "--ttl-ms", "30000", "--clear-token", "summary", "--clear-token", "summary2"]);
|
|
164
|
+
});
|
|
165
|
+
|
|
92
166
|
test("malformed successful Todo snapshots clear previous activity, unlike failed snapshots", async () => {
|
|
93
167
|
const h = harness(); h.fire("session_start"); h.fire("agent_start");
|
|
94
168
|
for (const tasks of [null, {}, [{ title: 42, status: "in_progress" }]]) {
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
import { createHerdrAgentExtension } from "../extensions/gentle-herdr-agent.ts";
|
|
5
|
+
|
|
6
|
+
type Handler = (event: any, ctx: ExtensionContext) => unknown;
|
|
7
|
+
type Request = { id: string; method: string; params: Record<string, unknown> };
|
|
8
|
+
|
|
9
|
+
function harness(overrides: NodeJS.ProcessEnv = {}) {
|
|
10
|
+
const handlers = new Map<string, Handler>();
|
|
11
|
+
const events = new Map<string, (data: any) => void>();
|
|
12
|
+
const requests: Request[] = [];
|
|
13
|
+
let idle = true;
|
|
14
|
+
createHerdrAgentExtension({
|
|
15
|
+
env: {
|
|
16
|
+
HERDR_ENV: "1", HERDR_PANE_ID: "pane-1", HERDR_SOCKET_PATH: "/herdr.sock",
|
|
17
|
+
GENTLE_SHELL_HERDR_REPORTER: "1", ...overrides,
|
|
18
|
+
},
|
|
19
|
+
send: async (request) => { requests.push(request as Request); },
|
|
20
|
+
})({
|
|
21
|
+
on: (name: string, fn: Handler) => handlers.set(name, fn),
|
|
22
|
+
events: { on: (name: string, fn: (data: any) => void) => { events.set(name, fn); return () => events.delete(name); } },
|
|
23
|
+
} as unknown as ExtensionAPI);
|
|
24
|
+
const ctx = (mode = "tui") => ({
|
|
25
|
+
mode, isIdle: () => idle,
|
|
26
|
+
sessionManager: { getSessionFile: () => "/sessions/root.jsonl", getSessionId: () => "root" },
|
|
27
|
+
}) as unknown as ExtensionContext;
|
|
28
|
+
return {
|
|
29
|
+
requests, handlers, events,
|
|
30
|
+
setIdle: (value: boolean) => { idle = value; },
|
|
31
|
+
fire: async (name: string, event: unknown = {}, context = ctx()) => { await handlers.get(name)?.(event, context); },
|
|
32
|
+
emit: (name: string, data: unknown) => events.get(name)?.(data),
|
|
33
|
+
ctx,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const settle = () => new Promise((resolve) => setImmediate(resolve));
|
|
38
|
+
const summary = (requests: Request[]) => requests.map(({ method, params }) => [method, params.source, params.agent, params.state, params.message]);
|
|
39
|
+
|
|
40
|
+
test("Gentle Shell reports its own Herdr agent identity, session and lifecycle states", async () => {
|
|
41
|
+
const h = harness();
|
|
42
|
+
await h.fire("session_start", { reason: "startup" });
|
|
43
|
+
await settle();
|
|
44
|
+
assert.deepEqual(h.requests[0], {
|
|
45
|
+
id: h.requests[0].id, method: "pane.report_agent_session",
|
|
46
|
+
params: { pane_id: "pane-1", source: "gentle-shell", agent: "gentle-shell", seq: h.requests[0].params.seq,
|
|
47
|
+
session_start_source: "startup", agent_session_path: "/sessions/root.jsonl" },
|
|
48
|
+
});
|
|
49
|
+
assert.deepEqual(h.requests[1].params, { pane_id: "pane-1", source: "gentle-shell", agent: "gentle-shell",
|
|
50
|
+
state: "idle", message: undefined, seq: h.requests[1].params.seq, agent_session_path: "/sessions/root.jsonl" });
|
|
51
|
+
assert.ok((h.requests[1].params.seq as number) > (h.requests[0].params.seq as number));
|
|
52
|
+
h.setIdle(false);
|
|
53
|
+
await h.fire("agent_start");
|
|
54
|
+
h.emit("herdr:blocked", { active: true, label: "Waiting for a choice" });
|
|
55
|
+
await settle();
|
|
56
|
+
h.emit("herdr:blocked", { active: false });
|
|
57
|
+
h.setIdle(true);
|
|
58
|
+
await h.fire("agent_settled");
|
|
59
|
+
await settle(); await settle();
|
|
60
|
+
assert.deepEqual(summary(h.requests).filter(([method]) => method === "pane.report_agent").map(([, , , state, message]) => [state, message]), [
|
|
61
|
+
["idle", undefined], ["working", undefined], ["blocked", "Waiting for a choice"], ["working", undefined], ["idle", undefined],
|
|
62
|
+
]);
|
|
63
|
+
for (const request of h.requests) {
|
|
64
|
+
assert.equal(request.params.source, "gentle-shell");
|
|
65
|
+
assert.equal(request.params.agent, "gentle-shell");
|
|
66
|
+
}
|
|
67
|
+
const seqs = h.requests.map((request) => request.params.seq as number);
|
|
68
|
+
assert.deepEqual([...seqs].sort((a, b) => a - b), seqs);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("Gentle Shell Herdr reporter stays silent without the launcher handoff, outside Herdr, in children and headless modes", async () => {
|
|
72
|
+
for (const overrides of [{ GENTLE_SHELL_HERDR_REPORTER: undefined }, { GENTLE_SHELL_HERDR_REPORTER: "0" },
|
|
73
|
+
{ HERDR_ENV: undefined }, { HERDR_PANE_ID: "" }, { HERDR_SOCKET_PATH: "" }, { GENTLE_PI_AGENTS_CHILD: "1" }]) {
|
|
74
|
+
const h = harness(overrides);
|
|
75
|
+
assert.equal(h.handlers.size, 0, JSON.stringify(overrides));
|
|
76
|
+
}
|
|
77
|
+
for (const mode of ["rpc", "json", "print"]) {
|
|
78
|
+
const h = harness();
|
|
79
|
+
await h.fire("session_start", { reason: "startup" }, h.ctx(mode));
|
|
80
|
+
await h.fire("agent_start", {}, h.ctx(mode));
|
|
81
|
+
h.emit("herdr:blocked", { active: true, label: "x" });
|
|
82
|
+
await settle();
|
|
83
|
+
assert.deepEqual(h.requests, [], mode);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("Gentle Shell Herdr reporter keeps only the latest queued state while a report is in flight", async () => {
|
|
88
|
+
const requests: Request[] = [];
|
|
89
|
+
let release: (() => void) | undefined;
|
|
90
|
+
const handlers = new Map<string, Handler>();
|
|
91
|
+
createHerdrAgentExtension({
|
|
92
|
+
env: { HERDR_ENV: "1", HERDR_PANE_ID: "p", HERDR_SOCKET_PATH: "/s", GENTLE_SHELL_HERDR_REPORTER: "1" },
|
|
93
|
+
send: (request) => {
|
|
94
|
+
requests.push(request as Request);
|
|
95
|
+
return (request as Request).method === "pane.report_agent" && requests.length === 2
|
|
96
|
+
? new Promise<void>((resolve) => { release = resolve; }) : Promise.resolve();
|
|
97
|
+
},
|
|
98
|
+
})({ on: (name: string, fn: Handler) => handlers.set(name, fn), events: { on: () => () => {} } } as unknown as ExtensionAPI);
|
|
99
|
+
let idle = true;
|
|
100
|
+
const ctx = { mode: "tui", isIdle: () => idle, sessionManager: { getSessionFile: () => undefined, getSessionId: () => "id-1" } } as unknown as ExtensionContext;
|
|
101
|
+
await handlers.get("session_start")!({ reason: "startup" }, ctx);
|
|
102
|
+
await settle();
|
|
103
|
+
idle = false; await handlers.get("agent_start")!({}, ctx);
|
|
104
|
+
idle = true; await handlers.get("agent_settled")!({}, ctx);
|
|
105
|
+
idle = false; await handlers.get("agent_start")!({}, ctx);
|
|
106
|
+
release?.();
|
|
107
|
+
await settle(); await settle();
|
|
108
|
+
const states = requests.filter((request) => request.method === "pane.report_agent").map((request) => request.params.state);
|
|
109
|
+
assert.deepEqual(states, ["idle", "working"]);
|
|
110
|
+
assert.equal(requests.at(-1)?.params.agent_session_id, "id-1");
|
|
111
|
+
});
|
|
@@ -5,13 +5,14 @@ import { tmpdir } from "node:os";
|
|
|
5
5
|
import { delimiter, join } from "node:path";
|
|
6
6
|
import test, { type TestContext } from "node:test";
|
|
7
7
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
8
|
-
import
|
|
8
|
+
import gentleMusicExtension, {
|
|
9
9
|
findOnPath,
|
|
10
10
|
formatMusicStatus,
|
|
11
11
|
GENTLE_STREAM_SPEC,
|
|
12
12
|
installHint,
|
|
13
13
|
MUSIC_COMMAND_NAME,
|
|
14
14
|
MUSIC_INSTALL_OFFER,
|
|
15
|
+
MUSIC_WINDOWS_UNSUPPORTED,
|
|
15
16
|
MUSIC_INSTALL_TITLE,
|
|
16
17
|
musicTuiArgs,
|
|
17
18
|
parseMusicArgs,
|
|
@@ -20,6 +21,11 @@ import gentleMusic, {
|
|
|
20
21
|
type MusicSpawn,
|
|
21
22
|
} from "../extensions/gentle-music.ts";
|
|
22
23
|
|
|
24
|
+
// The music tests describe a supported (POSIX) host unless they pass `platform`,
|
|
25
|
+
// so they hold on every OS the suite runs on, Windows included.
|
|
26
|
+
const gentleMusic = (pi: Parameters<typeof gentleMusicExtension>[0], deps: Parameters<typeof gentleMusicExtension>[1] = {}) =>
|
|
27
|
+
gentleMusicExtension(pi, { platform: "linux", ...deps });
|
|
28
|
+
|
|
23
29
|
// /gentle:music hands the terminal to gentle-stream's own TUI, the way Pi's
|
|
24
30
|
// external editor does, and controls the background player with
|
|
25
31
|
// `gentle-stream ctl …` without taking the terminal.
|
|
@@ -411,6 +417,35 @@ test("accepting the offer installs the player with progress, then starts the mus
|
|
|
411
417
|
assert.deepEqual(spawned[0]!.args, ["--model", "anthropic/claude-sonnet-5-5", "--mood", "calm"]);
|
|
412
418
|
});
|
|
413
419
|
|
|
420
|
+
test("on Windows /gentle:music explains it is not available yet and never offers, installs or runs anything", async () => {
|
|
421
|
+
assert.equal(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.");
|
|
422
|
+
for (const args of ["", "calm", "status", "stop"]) {
|
|
423
|
+
const { pi, commands } = fakePi();
|
|
424
|
+
const context = fakeContext();
|
|
425
|
+
const asked = withConfirm(context, true);
|
|
426
|
+
const { spawn, spawned } = fakeSpawn([{ code: 0 }], context.calls);
|
|
427
|
+
const { state, bundled } = fakeBundled({ installed: true });
|
|
428
|
+
gentleMusic(pi, { which: onPath({ "gentle-stream": "C:\\bin\\gentle-stream.exe", uvx: "C:\\bin\\uvx.exe" }), spawn, bundled, signals: fakeSignals().signals, platform: "win32" });
|
|
429
|
+
await commands.get(MUSIC_COMMAND_NAME)!.handler(args, context.ctx);
|
|
430
|
+
assert.deepEqual(context.notices, [[MUSIC_WINDOWS_UNSUPPORTED, "warning"]], args);
|
|
431
|
+
assert.deepEqual(asked, [], args);
|
|
432
|
+
assert.equal(state.installs, 0, args);
|
|
433
|
+
assert.equal(spawned.length, 0, args);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
test("on Windows the not-available notice wins over the interactive-terminal notice", async () => {
|
|
438
|
+
for (const mode of ["rpc", "json", "print"]) {
|
|
439
|
+
const { pi, commands } = fakePi();
|
|
440
|
+
const context = fakeContext(mode);
|
|
441
|
+
const { spawn, spawned } = fakeSpawn([{ code: 0 }], context.calls);
|
|
442
|
+
gentleMusic(pi, { which: onPath({ uvx: "C:\\bin\\uvx.exe" }), spawn, platform: "win32" });
|
|
443
|
+
await commands.get(MUSIC_COMMAND_NAME)!.handler("", context.ctx);
|
|
444
|
+
assert.deepEqual(context.notices, [[MUSIC_WINDOWS_UNSUPPORTED, "warning"]], mode);
|
|
445
|
+
assert.equal(spawned.length, 0, mode);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
|
|
414
449
|
test("an installed prefix player is used without asking; PATH gentle-stream still comes first", async () => {
|
|
415
450
|
const { bundled } = fakeBundled({ installed: true });
|
|
416
451
|
for (const [names, expected] of [[{}, "/prefix/music/bin/gentle-stream"], [{ uvx: "/bin/uvx" }, "/prefix/music/bin/gentle-stream"], [{ "gentle-stream": "/bin/gentle-stream" }, "/bin/gentle-stream"]] as const) {
|