gentle-pi 4.6.0 → 4.7.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 +10 -11
- package/assets/agents/gentle-ai-explore.md +1 -0
- package/assets/agents/gentle-ai-verify.md +5 -2
- package/assets/agents/gentle-ai-worker.md +3 -0
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +1 -0
- package/assets/agents/jd-judge-b.md +1 -0
- package/assets/design-canvas/canvas.css +13 -1
- package/assets/design-canvas/canvas.js +11 -2
- package/assets/install-wizard/wizard.js +1 -0
- package/assets/migrations/agent-body-history.json +16 -1
- package/assets/orchestrator-delegation-reference.md +4 -4
- package/assets/orchestrator-delegation.md +1 -1
- package/assets/orchestrator-full-delegation-card.md +65 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +3 -3
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator-verification.md +7 -5
- package/assets/orchestrator.md +3 -3
- package/bin/gentle-shell.mjs +164 -56
- package/docs/agent-status.md +61 -0
- package/docs/bundled-install.md +7 -5
- package/docs/delegated-verification.md +29 -7
- package/docs/gentle-agents-activity.md +14 -0
- package/docs/gentle-shell.md +54 -16
- package/docs/install-wizard.md +1 -1
- package/docs/permission-modes.md +9 -4
- package/docs/readme-reference.md +75 -30
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +33 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/voice.md +6 -3
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/child-safety.ts +3 -0
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +326 -34
- package/extensions/gentle-ai.ts +1496 -454
- package/extensions/gentle-shell.ts +293 -63
- package/extensions/gentle-todo.ts +18 -2
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +175 -18
- package/extensions/startup-banner.ts +30 -3
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +160 -2
- package/lib/agent-status.ts +105 -0
- package/lib/agents-config.ts +46 -0
- package/lib/agents-history.ts +24 -5
- package/lib/agents-messaging.ts +47 -5
- package/lib/agents-runner.ts +183 -12
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/bounded-writer-admission.ts +13 -1
- package/lib/card-content-policy.ts +8 -6
- package/lib/command-palette.ts +133 -17
- package/lib/context-backstop.ts +14 -5
- package/lib/destructive-command-guard.ts +48 -4
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +4 -2
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-design.ts +3 -0
- package/lib/gentle-shell-bundled.ts +6 -19
- package/lib/gentle-shell-launcher.ts +43 -8
- package/lib/herdr-activity.ts +14 -2
- package/lib/herdr-busy.ts +45 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +270 -140
- package/lib/jobs-view.ts +198 -11
- package/lib/model-routing-authority.ts +22 -4
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +96 -19
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/questionnaire/questionnaire-view.ts +105 -12
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +104 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +81 -44
- package/lib/review-continuation-registry.ts +99 -0
- package/lib/review-coordinator.ts +163 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +46 -10
- package/lib/review-integration-v2.ts +7 -1
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/session-profile-freeze.ts +4 -2
- package/lib/shell-bar.ts +140 -58
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-panel.ts +17 -3
- package/lib/shell-sidebar-layout.ts +112 -40
- package/lib/shell-sidebar.ts +7 -0
- package/lib/shell-todo.ts +10 -3
- package/lib/verifier-admission.ts +1 -1
- package/lib/visual-customization-policy.ts +36 -16
- package/lib/visual-customize-view.ts +216 -21
- package/lib/visual-layout-preview.ts +9 -5
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/yolo-session-policy.ts +40 -15
- package/package.json +2 -1
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +6 -19
- package/runtime/gentle-shell-launcher.mjs +42 -7
- package/runtime/native-review-cli.mjs +93 -16
- package/runtime/review-integration-v2.mjs +7 -1
- package/scripts/build-full-delegation-card.mjs +175 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-preflight.mjs +5 -5
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +8 -7
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +40 -28
- package/scripts/verify-package-files.mjs +12 -2
- package/scripts/voice-worker.cjs +32 -6
- package/skills/design/SKILL.md +11 -8
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- package/skills/skill-registry/SKILL.md +4 -2
- package/skills/work-unit-commits/SKILL.md +6 -7
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -0
- package/tests/agents-config.test.ts +96 -0
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +178 -2
- package/tests/append-system-prompt-route.test.ts +4 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +97 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-stop-contract.test.ts +43 -3
- package/tests/bridge-cost.test.ts +19 -4
- package/tests/bundled-install.test.ts +30 -5
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-safety.test.ts +11 -0
- package/tests/codegraph-tools.test.ts +11 -5
- package/tests/command-palette.test.ts +284 -1
- package/tests/delegate-for-reason-contract.test.ts +3 -3
- package/tests/design-canvas-assets.test.ts +185 -2
- package/tests/destructive-command-guard.test.ts +52 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/execution-surface-guard.test.ts +55 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +53 -6
- package/tests/full-delegation-closure.test.ts +131 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1070 -12
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +18 -2
- package/tests/gentle-ai-installer.test.ts +134 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai.test.ts +113 -38
- package/tests/gentle-design.test.ts +21 -0
- package/tests/gentle-herdr-activity.test.ts +9 -6
- package/tests/gentle-shell-bin.test.ts +123 -0
- package/tests/gentle-shell-bundled.test.ts +207 -31
- package/tests/gentle-shell-launcher.test.ts +77 -10
- package/tests/gentle-shell.test.ts +899 -59
- package/tests/gentle-todo.test.ts +19 -2
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +8 -4
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/independent-recovery-delivery.test.ts +83 -0
- package/tests/inprocess-reviewer.test.ts +176 -4
- package/tests/installer-posix-bootstrap.test.ts +1 -1
- package/tests/installer-preflight.test.ts +5 -4
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +14 -11
- package/tests/jobs-view.test.ts +260 -6
- package/tests/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +269 -1
- package/tests/no-self-pause-contract.test.ts +4 -1
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-delegation-mode.test.ts +153 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +3 -1
- package/tests/orchestrator-rdd-ownership.test.ts +2 -2
- package/tests/package-manifest.test.ts +11 -9
- package/tests/permission-allowlist.test.ts +202 -0
- package/tests/pi-update-launcher.test.ts +8 -0
- package/tests/pnpm-workspace-config.test.ts +58 -0
- package/tests/primary-session-prompt.test.ts +13 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +5 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/questionnaire-view.test.ts +115 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +16 -11
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +18 -0
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor.test.ts +173 -0
- package/tests/review-agent-end-preflight.test.ts +1 -1
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +1 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +76 -0
- package/tests/review-controller-native-routing.test.ts +261 -5
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +96 -11
- package/tests/review-coordinator-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +195 -0
- package/tests/review-failure-facts.test.ts +87 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +65 -10
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
- package/tests/review-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +12 -2
- package/tests/review-reviewer-evidence.test.ts +183 -0
- package/tests/review-risk-assessment.test.ts +74 -3
- package/tests/review-session-standing-permission-controller.test.ts +21 -1
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +121 -0
- package/tests/run-test-suite.test.ts +122 -1
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +181 -5
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-binding.test.ts +19 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-v1-compat.test.ts +35 -1
- package/tests/shell-bar.test.ts +186 -42
- package/tests/shell-panel.test.ts +50 -22
- package/tests/shell-sidebar-fullscreen.test.ts +5 -5
- package/tests/shell-sidebar-layout.test.ts +294 -23
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -0
- package/tests/skill-registry.test.ts +838 -5
- package/tests/startup-banner.test.ts +152 -1
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/review-coordinator-runtime.ts +69 -0
- package/tests/task-size-routing-contract.test.ts +5 -3
- package/tests/verifier-admission.test.ts +49 -0
- package/tests/verify-first-launch-contract.test.ts +78 -3
- package/tests/visual-customization-policy.test.ts +39 -6
- package/tests/visual-customize-view.test.ts +573 -9
- package/tests/visual-layout-preview.test.ts +15 -1
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +28 -0
- package/tests/writer-feature-document-admission.test.ts +92 -0
- package/tests/yolo-customize.test.ts +27 -4
- package/tests/yolo-mode.test.ts +23 -18
- package/tests/yolo-session-policy.test.ts +270 -1
package/lib/agents-runner.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { pickModel, sharedCooldown, shouldFallBack, type ModelCooldown } from ".
|
|
|
2
2
|
import type { FallbackChain } from "./model-fallback-store.ts";
|
|
3
3
|
import { fallbackContinuePrompt } from "./model-fallback-notice.ts";
|
|
4
4
|
import { isSessionChangeEvidence, type SessionChangeEvidence } from "./session-changes.ts";
|
|
5
|
-
import { chmodSync, existsSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { chmodSync, existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { DefaultPackageManager, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import { tmpdir, userInfo } from "node:os";
|
|
8
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
8
|
+
import { dirname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
9
9
|
import { Duplex, type Readable, type Writable } from "node:stream";
|
|
10
10
|
import { stripVTControlCharacters } from "node:util";
|
|
11
11
|
import { withoutInteractiveHost } from "./rpc-host.ts";
|
|
@@ -13,7 +13,7 @@ import { gentlePiConfigHome } from "./agent-home.ts";
|
|
|
13
13
|
import { resolveBackgroundSubagentsPolicy } from "./background-subagents-policy.ts";
|
|
14
14
|
import { childPackageExtensionArgs } from "./child-package-injection.ts";
|
|
15
15
|
import { AGENT_MODE, formatModelRef, parseModelRef, type AgentDefinition, type AgentMode, type ModelRef } from "./agents-config.ts";
|
|
16
|
-
import { CHILD_QUERY_MAX_INFLIGHT, CHILD_QUERY_TIMEOUT_MS, parseChildFrame, validChildMessage, validChildQueryId } from "./agents-messaging.ts";
|
|
16
|
+
import { CHILD_QUERY_MAX_INFLIGHT, CHILD_QUERY_TIMEOUT_MS, parseChildFrame, parseChildJobState, validChildMessage, validChildQueryId } from "./agents-messaging.ts";
|
|
17
17
|
import { ParentStandingReviewPermissionBroker } from "./review-session-standing-permission-ipc.ts";
|
|
18
18
|
import { isFinished, normalizeRpcEvent, ToolArgumentProgress, TASK_EVENT, TASK_STATUS, taskLabel, type AskRequest, type ChildResponseObservation, type TaskRecord, type TaskStore, type TerminalErrorCategory } from "./agents-protocol.ts";
|
|
19
19
|
import { WriterSurfaceRegistry, writerSurfaceConflictMessage } from "./writer-surfaces.ts";
|
|
@@ -79,6 +79,8 @@ export interface RunnerLimits {
|
|
|
79
79
|
toolStallTimeoutMs?: number;
|
|
80
80
|
// Bounded asynchronous cleanup window allowed after settlement before escalating to SIGTERM/SIGKILL.
|
|
81
81
|
cleanupTimeoutMs?: number;
|
|
82
|
+
// One bounded drain granted when agent_settled arrives while a child background job still runs.
|
|
83
|
+
drainTimeoutMs?: number;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
export interface AskAnswer {
|
|
@@ -190,6 +192,7 @@ interface ProcessLike {
|
|
|
190
192
|
execPath: string;
|
|
191
193
|
argv: string[];
|
|
192
194
|
env: NodeJS.ProcessEnv;
|
|
195
|
+
platform?: NodeJS.Platform;
|
|
193
196
|
}
|
|
194
197
|
|
|
195
198
|
interface Pending {
|
|
@@ -228,6 +231,10 @@ interface LiveTask {
|
|
|
228
231
|
/** The child's own TMPDIR, removed when the child ends unless its exit is unconfirmed. */
|
|
229
232
|
scratchDir?: string;
|
|
230
233
|
cleanupDeadlineAt: number | undefined;
|
|
234
|
+
/** The child's last reported background-job state, if any (#2266). */
|
|
235
|
+
childJobState?: { running: number; pending: boolean };
|
|
236
|
+
/** One bounded post-settlement drain while the child's background jobs finish (#2266). */
|
|
237
|
+
drain?: { status: TaskRecord["status"]; error: string | null; cancel: () => void };
|
|
231
238
|
quarantined: boolean;
|
|
232
239
|
nextId: number;
|
|
233
240
|
permissionBroker?: ParentStandingReviewPermissionBroker;
|
|
@@ -254,6 +261,8 @@ export const MAX_INLINE_INSTRUCTIONS_BYTES = 1000;
|
|
|
254
261
|
const MAX_TRANSPORT_PREFIX_CHARS = 64;
|
|
255
262
|
const CHILD_MARKER = "GENTLE_PI_AGENTS_CHILD";
|
|
256
263
|
const IPC_MARKER = "GENTLE_PI_AGENTS_OWNED_IPC";
|
|
264
|
+
/** Forwarded to the child only when a declared `bash_background` admitted its policy (#2266). */
|
|
265
|
+
export const CHILD_JOBS_ENV = "GENTLE_PI_AGENTS_CHILD_JOBS";
|
|
257
266
|
const PARENT_NOTIFICATION_TOOL = "subagent_parent_message";
|
|
258
267
|
/** The exact --tools list, so the child can report requested names Pi dropped silently (#1690). */
|
|
259
268
|
export const REQUESTED_TOOLS_ENV = "GENTLE_PI_AGENTS_REQUESTED_TOOLS";
|
|
@@ -263,6 +272,8 @@ const GROUP_CONFIRM_MS = 25;
|
|
|
263
272
|
const GROUP_CONFIRM_DEADLINE_MS = 1_000;
|
|
264
273
|
const QUARANTINE_PROBE_MS = 1_000;
|
|
265
274
|
export const DEFAULT_CLEANUP_TIMEOUT_MS = 5_000;
|
|
275
|
+
// One bounded drain window for a child's own background jobs at settlement (#2266).
|
|
276
|
+
export const DEFAULT_DRAIN_TIMEOUT_MS = 5_000;
|
|
266
277
|
const QUERY_REJECTION_ERRORS = new Set([
|
|
267
278
|
"invalid child IPC frame",
|
|
268
279
|
"invalid child IPC correlation",
|
|
@@ -353,16 +364,124 @@ export function childArguments(request: TaskRequest, instructionsPath?: string):
|
|
|
353
364
|
return args;
|
|
354
365
|
}
|
|
355
366
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
367
|
+
/**
|
|
368
|
+
* Resolves the underlying JavaScript entry point targeted by a Windows .cmd or .bat shim.
|
|
369
|
+
*
|
|
370
|
+
* Scans the shim text for referenced .js/.mjs/.cjs files (such as npm or pnpm cmd-shims)
|
|
371
|
+
* or inspects adjacent package metadata without invoking cmd.exe or a shell.
|
|
372
|
+
*/
|
|
373
|
+
export function resolvePiScriptFromCmd(
|
|
374
|
+
cmdPath: string,
|
|
375
|
+
exists: (path: string) => boolean = existsSync,
|
|
376
|
+
readFile: (path: string) => string = (p) => readFileSync(p, "utf8"),
|
|
377
|
+
): string | undefined {
|
|
378
|
+
const baseDir = win32.dirname(cmdPath);
|
|
379
|
+
let text = "";
|
|
380
|
+
try {
|
|
381
|
+
text = readFile(cmdPath);
|
|
382
|
+
} catch {
|
|
383
|
+
text = "";
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (text) {
|
|
387
|
+
const targetMatch = /^#\s*cmd-shim-target\s*=\s*([^\r\n]+)$/m.exec(text);
|
|
388
|
+
if (targetMatch) {
|
|
389
|
+
const candidate = targetMatch[1].trim();
|
|
390
|
+
const resolved = win32.isAbsolute(candidate) ? candidate : win32.resolve(baseDir, candidate);
|
|
391
|
+
if (exists(resolved)) return resolved;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const scriptMatches = text.matchAll(/(?:["'])([^"']+\.[cm]?js)(?:["'])|(?:^|\s)((?:%~?dp0|%dp0%)\\?[^\s"']+\.[cm]?js)(?:\s|$)/gi);
|
|
395
|
+
for (const m of scriptMatches) {
|
|
396
|
+
const raw = (m[1] ?? m[2])?.trim();
|
|
397
|
+
if (!raw) continue;
|
|
398
|
+
const stripped = raw.replace(/^(?:%~?dp0|%dp0%)\\?/i, "");
|
|
399
|
+
const candidate = /^(?:%~?dp0|%dp0%)/i.test(raw) || !win32.isAbsolute(stripped)
|
|
400
|
+
? win32.resolve(baseDir, stripped)
|
|
401
|
+
: stripped;
|
|
402
|
+
if (exists(candidate)) return candidate;
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const standardPaths = [
|
|
407
|
+
win32.join(baseDir, "node_modules", "@earendil-works", "pi-coding-agent", "dist", "cli.js"),
|
|
408
|
+
win32.join(baseDir, "node_modules", "@earendil-works", "pi-coding-agent", "dist", "bundle", "cli.js"),
|
|
409
|
+
win32.join(baseDir, "pi-launcher.js"),
|
|
410
|
+
win32.join(baseDir, "dist", "cli.js"),
|
|
411
|
+
win32.join(baseDir, "dist", "bundle", "cli.js"),
|
|
412
|
+
];
|
|
413
|
+
for (const candidate of standardPaths) {
|
|
414
|
+
if (exists(candidate)) return candidate;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return undefined;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Searches the Windows PATH and known locations for an installed pi command,
|
|
422
|
+
* resolving .cmd shims to their direct Node script entry points to avoid cmd.exe shell invocation.
|
|
423
|
+
*/
|
|
424
|
+
export function findWindowsPiCommand(
|
|
425
|
+
proc: ProcessLike = process,
|
|
426
|
+
exists: (path: string) => boolean = existsSync,
|
|
427
|
+
readFile: (path: string) => string = (p) => readFileSync(p, "utf8"),
|
|
428
|
+
): PiCommand | undefined {
|
|
429
|
+
const pathEnv = proc.env.Path ?? proc.env.PATH ?? "";
|
|
430
|
+
for (const entry of pathEnv.split(";")) {
|
|
431
|
+
const dir = entry.length >= 2 && entry.startsWith('"') && entry.endsWith('"')
|
|
432
|
+
? entry.slice(1, -1)
|
|
433
|
+
: entry;
|
|
434
|
+
if (!dir) continue;
|
|
435
|
+
|
|
436
|
+
const candidateExe = win32.join(dir, "pi.exe");
|
|
437
|
+
if (exists(candidateExe)) {
|
|
438
|
+
return { command: candidateExe, args: [] };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
for (const ext of [".cmd", ".bat"]) {
|
|
442
|
+
const candidateCmd = win32.join(dir, `pi${ext}`);
|
|
443
|
+
if (exists(candidateCmd)) {
|
|
444
|
+
const script = resolvePiScriptFromCmd(candidateCmd, exists, readFile);
|
|
445
|
+
if (script) {
|
|
446
|
+
return { command: proc.execPath, args: [script] };
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
return undefined;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Resolves the pi invocation command for subagent execution.
|
|
456
|
+
*
|
|
457
|
+
* Reuses the running pi CLI entry point while it exists on disk.
|
|
458
|
+
* When the running entry point disappears (e.g. after a package upgrade on Windows),
|
|
459
|
+
* re-resolves the current installation from PATH and returns Node plus the target script
|
|
460
|
+
* so arguments are never passed through an unescaped shell wrapper.
|
|
461
|
+
*/
|
|
462
|
+
export function piCommand(
|
|
463
|
+
proc: ProcessLike = process,
|
|
464
|
+
exists: (path: string) => boolean = existsSync,
|
|
465
|
+
readFile: (path: string) => string = (p) => readFileSync(p, "utf8"),
|
|
466
|
+
): PiCommand {
|
|
359
467
|
const override = proc.env.GENTLE_PI_AGENTS_PI?.trim();
|
|
360
468
|
if (override) {
|
|
361
469
|
const [command, ...args] = override.split(/\s+/);
|
|
470
|
+
if (/\.(?:cmd|bat)$/i.test(command) && exists(command)) {
|
|
471
|
+
const script = resolvePiScriptFromCmd(command, exists, readFile);
|
|
472
|
+
if (script) return { command: proc.execPath, args: [script, ...args] };
|
|
473
|
+
}
|
|
362
474
|
return { command, args };
|
|
363
475
|
}
|
|
364
476
|
const entry = proc.argv[1];
|
|
365
477
|
if (entry && /(^|[\\/])cli\.js$/.test(entry) && exists(entry)) return { command: proc.execPath, args: [entry] };
|
|
478
|
+
const isWin32 = proc.platform !== undefined
|
|
479
|
+
? proc.platform === "win32"
|
|
480
|
+
: (proc === process ? process.platform === "win32" : /^[a-zA-Z]:\\/i.test(proc.execPath) || /\\/.test(proc.execPath));
|
|
481
|
+
if (isWin32) {
|
|
482
|
+
const resolved = findWindowsPiCommand(proc, exists, readFile);
|
|
483
|
+
if (resolved) return resolved;
|
|
484
|
+
}
|
|
366
485
|
return { command: "pi", args: [] };
|
|
367
486
|
}
|
|
368
487
|
|
|
@@ -578,7 +697,10 @@ export class AgentRunner {
|
|
|
578
697
|
this.finish(id, TASK_STATUS.FAILED, `could not start pi: explicit tool bash_background requires background-subagents policy on. Set ${file} to {"schema":"gentle-pi.background-subagents/v1","policy":"on"}; inspect or change policy with /gentle:background-subagents enable|disable|status.`);
|
|
579
698
|
return;
|
|
580
699
|
}
|
|
581
|
-
|
|
700
|
+
// Admission passed: the child registers its own private job tools and is
|
|
701
|
+
// trusted to report job state for the settlement drain.
|
|
702
|
+
env[CHILD_JOBS_ENV] = "1";
|
|
703
|
+
} else delete env[CHILD_JOBS_ENV];
|
|
582
704
|
if (tools !== undefined) env[REQUESTED_TOOLS_ENV] = tools;
|
|
583
705
|
else delete env[REQUESTED_TOOLS_ENV];
|
|
584
706
|
let instructionsTransportDir: string | undefined;
|
|
@@ -846,8 +968,8 @@ export class AgentRunner {
|
|
|
846
968
|
}
|
|
847
969
|
const task = this.store.get(id);
|
|
848
970
|
if (!task || live.terminal || isFinished(task.status) || task.parentSessionId === "") {
|
|
849
|
-
if (parsed.frame.kind === "
|
|
850
|
-
else this.
|
|
971
|
+
if (parsed.frame.kind === "query") this.sendQueryError(live, parsed.frame.id, "task is not a live owned recipient");
|
|
972
|
+
else this.acknowledge(live, parsed.frame.id, false, "task is not a live owned recipient");
|
|
851
973
|
return;
|
|
852
974
|
}
|
|
853
975
|
if (parsed.frame.kind === "notification") {
|
|
@@ -858,6 +980,18 @@ export class AgentRunner {
|
|
|
858
980
|
} catch { this.acknowledge(live, parsed.frame.id, false, "parent rejected notification"); }
|
|
859
981
|
return;
|
|
860
982
|
}
|
|
983
|
+
if (parsed.frame.kind === "job") {
|
|
984
|
+
const state = parseChildJobState(parsed.frame.message);
|
|
985
|
+
if (!state) {
|
|
986
|
+
this.acknowledge(live, parsed.frame.id, false, "invalid child job state");
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
// Ack before the report can open a drain that closes IPC.
|
|
990
|
+
this.acknowledge(live, parsed.frame.id, true);
|
|
991
|
+
live.childJobState = state;
|
|
992
|
+
if (live.drain && state.running === 0 && !state.pending) this.beginSettle(id, live);
|
|
993
|
+
return;
|
|
994
|
+
}
|
|
861
995
|
let query: PendingQuery | undefined;
|
|
862
996
|
try {
|
|
863
997
|
if (live.queries.has(parsed.frame.id)) rejectQuery("duplicate query request");
|
|
@@ -1021,9 +1155,9 @@ export class AgentRunner {
|
|
|
1021
1155
|
if (live.observations) live.observations.agentSettled = true;
|
|
1022
1156
|
const terminal = this.store.get(id);
|
|
1023
1157
|
if (terminal?.error && this.fallBack(id, request, live)) { /* The child keeps going on its next model. */ }
|
|
1024
|
-
else if (terminal?.error) this.
|
|
1025
|
-
else if (terminal?.result) this.
|
|
1026
|
-
else this.
|
|
1158
|
+
else if (terminal?.error) this.settleOrDrain(id, TASK_STATUS.FAILED, terminal.error, live);
|
|
1159
|
+
else if (terminal?.result) this.settleOrDrain(id, TASK_STATUS.COMPLETED, null, live);
|
|
1160
|
+
else this.settleOrDrain(id, TASK_STATUS.FAILED, "assistant settled without a final report", live);
|
|
1027
1161
|
}
|
|
1028
1162
|
}
|
|
1029
1163
|
if (!live.terminal && progress) this.armStall(id, live);
|
|
@@ -1064,6 +1198,34 @@ export class AgentRunner {
|
|
|
1064
1198
|
}
|
|
1065
1199
|
}
|
|
1066
1200
|
|
|
1201
|
+
/**
|
|
1202
|
+
* Settles a task, but when the child still reports running background jobs
|
|
1203
|
+
* (#2266) it grants one bounded drain window first so the jobs can finish;
|
|
1204
|
+
* the drain ends early when the child reports nothing left.
|
|
1205
|
+
*/
|
|
1206
|
+
private settleOrDrain(id: string, status: TaskRecord["status"], error: string | null, live: LiveTask): void {
|
|
1207
|
+
if (live.drain || live.terminal) return;
|
|
1208
|
+
const state = live.childJobState;
|
|
1209
|
+
// No child job work, or the child already reports none: settle as before.
|
|
1210
|
+
if (!state || (state.running === 0 && !state.pending)) {
|
|
1211
|
+
this.settleOrderly(id, status, error);
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
// One bounded extension: the child keeps running its jobs, and the drain
|
|
1215
|
+
// ends early on a report with nothing left. A late report cannot re-open it.
|
|
1216
|
+
const cancel = this.deps.schedule(() => this.beginSettle(id, live), this.limits.drainTimeoutMs ?? DEFAULT_DRAIN_TIMEOUT_MS);
|
|
1217
|
+
live.drain = { status, error, cancel };
|
|
1218
|
+
if (this.store.get(id)?.status === TASK_STATUS.RUNNING) this.store.update(id, { lastStep: "draining background jobs" });
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
private beginSettle(id: string, live: LiveTask): void {
|
|
1222
|
+
const drain = live.drain;
|
|
1223
|
+
if (!drain || this.live.get(id) !== live) return;
|
|
1224
|
+
live.drain = undefined;
|
|
1225
|
+
drain.cancel();
|
|
1226
|
+
this.settleOrderly(id, drain.status, drain.error);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1067
1229
|
/**
|
|
1068
1230
|
* Requests orderly child shutdown via stdin upon settlement and schedules
|
|
1069
1231
|
* bounded signal escalation if the child process does not exit within cleanupTimeoutMs.
|
|
@@ -1071,6 +1233,8 @@ export class AgentRunner {
|
|
|
1071
1233
|
private settleOrderly(id: string, status: TaskRecord["status"], error: string | null): void {
|
|
1072
1234
|
const live = this.live.get(id);
|
|
1073
1235
|
if (!live || live.terminal) return;
|
|
1236
|
+
live.drain?.cancel();
|
|
1237
|
+
live.drain = undefined;
|
|
1074
1238
|
live.terminal = { status, error };
|
|
1075
1239
|
live.mutationStarts.clear();
|
|
1076
1240
|
live.inFlightTools.clear();
|
|
@@ -1102,6 +1266,8 @@ export class AgentRunner {
|
|
|
1102
1266
|
private requestStop(id: string, status: TaskRecord["status"], error: string | null, abort = false): void {
|
|
1103
1267
|
const live = this.live.get(id);
|
|
1104
1268
|
if (!live || live.terminal) return;
|
|
1269
|
+
live.drain?.cancel();
|
|
1270
|
+
live.drain = undefined;
|
|
1105
1271
|
live.terminal = { status, error };
|
|
1106
1272
|
live.mutationStarts.clear();
|
|
1107
1273
|
live.inFlightTools.clear();
|
|
@@ -1181,6 +1347,8 @@ export class AgentRunner {
|
|
|
1181
1347
|
this.closeIpc(live);
|
|
1182
1348
|
live.cancelStall();
|
|
1183
1349
|
live.cancelGrace();
|
|
1350
|
+
live.drain?.cancel();
|
|
1351
|
+
live.drain = undefined;
|
|
1184
1352
|
if (live.instructionsTransportDir) {
|
|
1185
1353
|
try { rmSync(live.instructionsTransportDir, { recursive: true, force: true }); } catch { /* best effort */ }
|
|
1186
1354
|
live.instructionsTransportDir = undefined;
|
|
@@ -1213,6 +1381,9 @@ export class AgentRunner {
|
|
|
1213
1381
|
if (!live) return;
|
|
1214
1382
|
live.childExit = code;
|
|
1215
1383
|
live.childExitSignal = signal ?? null;
|
|
1384
|
+
// A child that exits mid-drain still settles on the run agent_settled already
|
|
1385
|
+
// produced; the ordinary orderly shutdown then owns the exit.
|
|
1386
|
+
if (live.drain) this.beginSettle(id, live);
|
|
1216
1387
|
const exitDesc = formatChildExit(code, signal);
|
|
1217
1388
|
if (this.groupExists(live)) {
|
|
1218
1389
|
if (!live.terminal) this.requestStop(id, TASK_STATUS.FAILED, `pi exited with ${exitDesc} before agent_settled${this.stderrSuffix(live)}`);
|
|
@@ -38,7 +38,7 @@ type BranchItem = {id: string; type: string; message?: {role: string; content: u
|
|
|
38
38
|
type AuthoredInput = {text: string; order:number; before: Set<string>; entryId?: string; prompt?: string};
|
|
39
39
|
// These are independent authority/dialog/delegation surfaces, not Auto approvals.
|
|
40
40
|
const OWNED_CONTROL_TOOLS = new Set([
|
|
41
|
-
"ask_user_choice", "ask_user_question", "gentle_review", "gentle_review_capture", "gentle_review_capture_group",
|
|
41
|
+
"ask_user_choice", "ask_user_question", "gentle_review", "gentle_review_capture", "gentle_review_capture_group", "gentle_review_run",
|
|
42
42
|
"subagent_run", "subagent_continue", "subagent_reply", "subagent_cancel", "subagent_send_message",
|
|
43
43
|
"subagent_status", "subagent_result", "subagent_list_tasks", "subagent_list_agents",
|
|
44
44
|
"gentle_odd_phase", "todo",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { basename, dirname, isAbsolute, parse, relative, resolve } from "node:path";
|
|
4
|
+
import type { OrchestratorMode } from "./agent-profiles.ts";
|
|
4
5
|
import { contextBackstopReached, type MeasuredContext } from "./context-backstop.ts";
|
|
5
6
|
import { resolveSessionWorktree, type WorktreeResolver } from "./session-worktree-registry.ts";
|
|
6
7
|
|
|
@@ -120,11 +121,22 @@ export function namesExistingFeatureDocumentTask(values: readonly unknown[], roo
|
|
|
120
121
|
|
|
121
122
|
export function rejectUndocumentedWriterLaunch(
|
|
122
123
|
input: unknown,
|
|
123
|
-
options: {
|
|
124
|
+
options: {
|
|
125
|
+
root: string;
|
|
126
|
+
contextUsage: MeasuredContext | undefined;
|
|
127
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
128
|
+
/**
|
|
129
|
+
* The parent's workflow mode. In full delegation mode the orchestrator never implements, so every authorized
|
|
130
|
+
* change, small ones included, belongs to a writer: rejecting it here would leave the task with no legal route.
|
|
131
|
+
* Omitted means organic, the admission above.
|
|
132
|
+
*/
|
|
133
|
+
orchestratorMode?: OrchestratorMode;
|
|
134
|
+
},
|
|
124
135
|
): { block: true; reason: string } | undefined {
|
|
125
136
|
if (!input || typeof input !== "object" || Array.isArray(input)) return undefined;
|
|
126
137
|
const record = input as Record<string, unknown>;
|
|
127
138
|
if (typeof record.agent !== "string" || !isGenericBoundedWriter(record.agent)) return undefined;
|
|
139
|
+
if (options.orchestratorMode === "full-delegation") return undefined;
|
|
128
140
|
if (namesExistingFeatureDocumentTask([record.task, record.context], options.root)) return undefined;
|
|
129
141
|
if (contextBackstopReached(options.contextUsage, options.env)) return undefined;
|
|
130
142
|
return { block: true, reason: WRITER_FEATURE_DOCUMENT_REJECTION };
|
|
@@ -5,9 +5,8 @@ import { gentlePiConfigHome } from "./agent-home.ts";
|
|
|
5
5
|
|
|
6
6
|
// The conversation card content level chosen in Gentle → Customize. `default`
|
|
7
7
|
// keeps the quiet tools' result previews; `minimal` draws every quiet tool
|
|
8
|
-
// card as the command alone. A missing file means
|
|
9
|
-
//
|
|
10
|
-
// default, and the writer refuses
|
|
8
|
+
// card as the command alone. A missing file means minimal, the default; a
|
|
9
|
+
// malformed or unreadable one also reads as minimal, and the writer refuses
|
|
11
10
|
// to replace it so a hand edit is never lost. There is no environment override.
|
|
12
11
|
export const CARD_CONTENT_SCHEMA = "gentle-pi.card-content/v1";
|
|
13
12
|
const CARD_CONTENT_FILE = "card-content.json";
|
|
@@ -18,6 +17,8 @@ export const CARD_CONTENT = {
|
|
|
18
17
|
} as const;
|
|
19
18
|
|
|
20
19
|
export type CardContent = (typeof CARD_CONTENT)[keyof typeof CARD_CONTENT];
|
|
20
|
+
/** What a missing or unreadable preference means: command-only cards. `default` names the preview level. */
|
|
21
|
+
export const DEFAULT_CARD_CONTENT: CardContent = CARD_CONTENT.MINIMAL;
|
|
21
22
|
|
|
22
23
|
interface CardContentOptions { gentlePiConfigHome?: string }
|
|
23
24
|
|
|
@@ -45,10 +46,10 @@ export function resolveCardContent(options: CardContentOptions = {}): CardConten
|
|
|
45
46
|
const globalFile = join(options.gentlePiConfigHome ?? gentlePiConfigHome(), CARD_CONTENT_FILE);
|
|
46
47
|
try {
|
|
47
48
|
const content = parseCardContentFile(readFileSync(globalFile, "utf8"));
|
|
48
|
-
return { content: content ??
|
|
49
|
+
return { content: content ?? DEFAULT_CARD_CONTENT, source: "global_file", malformed: content === undefined, globalFile };
|
|
49
50
|
} catch (error) {
|
|
50
51
|
const missing = typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
|
|
51
|
-
return { content:
|
|
52
|
+
return { content: DEFAULT_CARD_CONTENT, source: missing ? "default" : "global_file", malformed: !missing, globalFile };
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -72,7 +73,8 @@ export function writeCardContent(content: CardContent, options: CardContentOptio
|
|
|
72
73
|
// Pi loads every extension with its own module cache, so the renderers in
|
|
73
74
|
// quiet-tools and the customize command in gentle-shell never share a module
|
|
74
75
|
// instance. The process-wide slot keeps one live content level per process,
|
|
75
|
-
// exactly like the card style slot; an unset slot
|
|
76
|
+
// exactly like the card style slot; an unset slot (no Gentle Shell resolution
|
|
77
|
+
// yet, e.g. a host without it) reads as the `default` preview level.
|
|
76
78
|
const CARD_CONTENT_SLOT = Symbol.for("gentle-pi.card-content");
|
|
77
79
|
const contentState = globalThis as typeof globalThis & { [CARD_CONTENT_SLOT]?: unknown };
|
|
78
80
|
|
package/lib/command-palette.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { isKeyRelease, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
1
|
+
import { isKeyRelease, matchesKey, truncateToWidth, visibleWidth, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
|
|
2
2
|
import { effectiveKey, type KeymapBindings } from "./keymaps.ts";
|
|
3
|
+
import { paintHoverable } from "./shell-hover.ts";
|
|
3
4
|
import { stripAnsi } from "./terminal-theme.ts";
|
|
4
5
|
|
|
5
6
|
// Command palette: a pure, curated, grouped overlay component for
|
|
@@ -137,6 +138,19 @@ const DEFAULT_ROWS = 40;
|
|
|
137
138
|
|
|
138
139
|
type PaletteRow = { kind: "title"; text: string } | { kind: "blank" } | { kind: "item"; item: CommandPaletteItem; itemIndex: number };
|
|
139
140
|
|
|
141
|
+
interface PalettePointerHit {
|
|
142
|
+
y: number;
|
|
143
|
+
itemIndex: number;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
interface PalettePointerFrame {
|
|
147
|
+
width: number;
|
|
148
|
+
height: number;
|
|
149
|
+
availableRows: number;
|
|
150
|
+
modelKey: string;
|
|
151
|
+
hits: PalettePointerHit[];
|
|
152
|
+
}
|
|
153
|
+
|
|
140
154
|
function buildRows(groups: readonly CommandPaletteGroup[]): PaletteRow[] {
|
|
141
155
|
const rows: PaletteRow[] = [];
|
|
142
156
|
let itemIndex = 0;
|
|
@@ -168,7 +182,13 @@ export class CommandPalette {
|
|
|
168
182
|
private query = "";
|
|
169
183
|
private selected = 0;
|
|
170
184
|
private completed = false;
|
|
185
|
+
private disposed = false;
|
|
171
186
|
private capturing: CommandPaletteItem | undefined;
|
|
187
|
+
private hovered: number | undefined;
|
|
188
|
+
private pointerFrame: PalettePointerFrame | undefined;
|
|
189
|
+
private renderedWidth: number | undefined;
|
|
190
|
+
private renderedRows: number | undefined;
|
|
191
|
+
private renderedModelKey: string | undefined;
|
|
172
192
|
private readonly groups: readonly CommandPaletteGroup[];
|
|
173
193
|
private readonly done: (result: CommandPaletteResult) => void;
|
|
174
194
|
private readonly theme: CommandPaletteTheme | undefined;
|
|
@@ -181,10 +201,55 @@ export class CommandPalette {
|
|
|
181
201
|
this.rowsFn = rows;
|
|
182
202
|
}
|
|
183
203
|
|
|
184
|
-
invalidate(): void {
|
|
204
|
+
invalidate(): void {
|
|
205
|
+
this.pointerFrame = undefined;
|
|
206
|
+
this.hovered = undefined;
|
|
207
|
+
this.renderedWidth = undefined;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
dispose(): void {
|
|
211
|
+
this.disposed = true;
|
|
212
|
+
this.invalidate();
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Mouse events are local to the last painted card, including its borders. */
|
|
216
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
|
|
217
|
+
if (this.completed || this.disposed || this.capturing) return undefined;
|
|
218
|
+
const frame = this.pointerFrame;
|
|
219
|
+
if (!frame || frame.width !== event.width || frame.height !== event.height ||
|
|
220
|
+
frame.availableRows !== this.rowsFn() || frame.modelKey !== this.modelKey()) {
|
|
221
|
+
this.pointerFrame = undefined;
|
|
222
|
+
const changed = this.setHover(undefined);
|
|
223
|
+
return changed && event.type === "move" && event.button === "none" ? { handled: true, render: true } : undefined;
|
|
224
|
+
}
|
|
225
|
+
const inside = event.x >= 2 && event.x < frame.width - 2 && event.y >= 0 && event.y < frame.height;
|
|
226
|
+
const hit = inside ? frame.hits.find((candidate) => candidate.y === event.y) : undefined;
|
|
227
|
+
if (event.type === "move" && event.button === "none") {
|
|
228
|
+
return { handled: true, render: this.setHover(hit?.itemIndex) };
|
|
229
|
+
}
|
|
230
|
+
if (event.type === "wheel" && inside && event.wheelDelta) {
|
|
231
|
+
const before = this.selected;
|
|
232
|
+
this.moveSelection(Math.sign(event.wheelDelta));
|
|
233
|
+
const changed = this.selected !== before;
|
|
234
|
+
const hoverChanged = this.setHover(undefined);
|
|
235
|
+
if (changed) this.pointerFrame = undefined;
|
|
236
|
+
return { handled: true, render: changed || hoverChanged };
|
|
237
|
+
}
|
|
238
|
+
if (event.button !== "left" || !hit) return undefined;
|
|
239
|
+
if (event.type === "press") return { handled: true, render: false };
|
|
240
|
+
if (event.type === "click") {
|
|
241
|
+
this.selected = hit.itemIndex;
|
|
242
|
+
this.pointerFrame = undefined;
|
|
243
|
+
this.runSelected();
|
|
244
|
+
return { handled: true, render: true };
|
|
245
|
+
}
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
185
248
|
|
|
186
249
|
handleInput(data: string): void {
|
|
187
|
-
if (this.completed || isKeyRelease(data)) return;
|
|
250
|
+
if (this.completed || this.disposed || isKeyRelease(data)) return;
|
|
251
|
+
this.pointerFrame = undefined;
|
|
252
|
+
this.hovered = undefined;
|
|
188
253
|
// After Tab the next key is the one to assign, whatever it is; esc only cancels.
|
|
189
254
|
if (this.capturing) {
|
|
190
255
|
const item = this.capturing;
|
|
@@ -213,8 +278,7 @@ export class CommandPalette {
|
|
|
213
278
|
return;
|
|
214
279
|
}
|
|
215
280
|
if (matchesKey(data, "enter") || matchesKey(data, "return")) {
|
|
216
|
-
|
|
217
|
-
if (item) this.finish({ type: "run", name: item.command });
|
|
281
|
+
this.runSelected();
|
|
218
282
|
return;
|
|
219
283
|
}
|
|
220
284
|
if (matchesKey(data, "backspace")) {
|
|
@@ -229,9 +293,23 @@ export class CommandPalette {
|
|
|
229
293
|
}
|
|
230
294
|
|
|
231
295
|
render(width: number): string[] {
|
|
296
|
+
const availableRows = this.rowsFn();
|
|
297
|
+
const modelKey = this.modelKey();
|
|
298
|
+
if (this.renderedWidth !== width || this.renderedRows !== availableRows || this.renderedModelKey !== modelKey) this.hovered = undefined;
|
|
299
|
+
this.renderedWidth = width;
|
|
300
|
+
this.renderedRows = availableRows;
|
|
301
|
+
this.renderedModelKey = modelKey;
|
|
232
302
|
const innerWidth = Math.max(1, width - CARD_PADDING);
|
|
233
|
-
const maxTotalLines = Math.max(MIN_TOTAL_ROWS, Math.floor(
|
|
234
|
-
|
|
303
|
+
const maxTotalLines = Math.max(MIN_TOTAL_ROWS, Math.floor(availableRows * HEIGHT_RATIO));
|
|
304
|
+
const hits: PalettePointerHit[] = [];
|
|
305
|
+
const frame = renderPaletteCard(this.renderBody(innerWidth, maxTotalLines, hits), width, this.theme);
|
|
306
|
+
// showCommandPalette caps the overlay at 85% even when the card's
|
|
307
|
+
// minimum height is larger. Only the actually visible prefix can act.
|
|
308
|
+
const visibleHeight = Math.min(frame.length, Math.max(1, Math.floor(availableRows * HEIGHT_RATIO)));
|
|
309
|
+
this.pointerFrame = this.disposed || this.completed || width <= CARD_PADDING ? undefined : {
|
|
310
|
+
width, height: visibleHeight, availableRows, modelKey, hits,
|
|
311
|
+
};
|
|
312
|
+
return frame;
|
|
235
313
|
}
|
|
236
314
|
|
|
237
315
|
/**
|
|
@@ -262,13 +340,30 @@ export class CommandPalette {
|
|
|
262
340
|
return rankPaletteGroups(this.groups, this.query);
|
|
263
341
|
}
|
|
264
342
|
|
|
343
|
+
private modelKey(): string {
|
|
344
|
+
return JSON.stringify(this.groups.map((group) => [group.title, group.items.map((item) => [item.command, item.label, item.description, item.shortcut])]));
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private setHover(index: number | undefined): boolean {
|
|
348
|
+
if (this.hovered === index) return false;
|
|
349
|
+
this.hovered = index;
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
private runSelected(): void {
|
|
354
|
+
const item = itemAt(this.matches(), this.selected);
|
|
355
|
+
if (item) this.finish({ type: "run", name: item.command });
|
|
356
|
+
}
|
|
357
|
+
|
|
265
358
|
private finish(result: CommandPaletteResult): void {
|
|
266
|
-
if (this.completed) return;
|
|
359
|
+
if (this.completed || this.disposed) return;
|
|
267
360
|
this.completed = true;
|
|
361
|
+
this.pointerFrame = undefined;
|
|
362
|
+
this.hovered = undefined;
|
|
268
363
|
this.done(result);
|
|
269
364
|
}
|
|
270
365
|
|
|
271
|
-
private renderBody(width: number, maxTotalLines: number): string[] {
|
|
366
|
+
private renderBody(width: number, maxTotalLines: number, hits: PalettePointerHit[]): string[] {
|
|
272
367
|
const lines: string[] = [];
|
|
273
368
|
lines.push(this.renderHeaderRow(width));
|
|
274
369
|
lines.push(this.query.length > 0 ? this.renderLine(`› ${this.query}`, width) : this.renderLine("› Search", width, "muted"));
|
|
@@ -278,7 +373,7 @@ export class CommandPalette {
|
|
|
278
373
|
lines.push(this.renderLine(`No commands match "${this.query}"`, width, "muted"));
|
|
279
374
|
} else {
|
|
280
375
|
const budget = Math.max(1, maxTotalLines - CARD_BORDER_ROWS - CHROME_ROWS);
|
|
281
|
-
lines.push(...this.renderGroups(groups, width, budget));
|
|
376
|
+
lines.push(...this.renderGroups(groups, width, budget, hits));
|
|
282
377
|
}
|
|
283
378
|
lines.push("");
|
|
284
379
|
if (this.capturing) lines.push(this.renderLine(`Press the new key for ${this.capturing.label} · esc cancel`, width, "accent"));
|
|
@@ -292,37 +387,58 @@ export class CommandPalette {
|
|
|
292
387
|
return this.justifyToWidth(left, right, width);
|
|
293
388
|
}
|
|
294
389
|
|
|
295
|
-
private renderGroups(groups: CommandPaletteGroup[], width: number, budget: number): string[] {
|
|
390
|
+
private renderGroups(groups: CommandPaletteGroup[], width: number, budget: number, hits: PalettePointerHit[]): string[] {
|
|
296
391
|
const rows = buildRows(groups);
|
|
297
392
|
const selected = Math.max(0, Math.min(countItems(groups) - 1, this.selected));
|
|
298
|
-
|
|
393
|
+
const result: string[] = [];
|
|
394
|
+
const appendRow = (row: PaletteRow) => {
|
|
395
|
+
if (row.kind === "item" && this.itemFits(row.item, width)) {
|
|
396
|
+
// Border + header, query and blank precede the grouped rows.
|
|
397
|
+
hits.push({ y: 4 + result.length, itemIndex: row.itemIndex });
|
|
398
|
+
}
|
|
399
|
+
result.push(this.renderRow(row, width, selected));
|
|
400
|
+
};
|
|
401
|
+
if (rows.length <= budget) {
|
|
402
|
+
for (const row of rows) appendRow(row);
|
|
403
|
+
return result;
|
|
404
|
+
}
|
|
299
405
|
const windowSize = Math.max(1, budget - SCROLL_INDICATOR_ROWS);
|
|
300
406
|
const selectedRowIndex = Math.max(0, rows.findIndex((row) => row.kind === "item" && row.itemIndex === selected));
|
|
301
407
|
const start = Math.max(0, Math.min(selectedRowIndex - Math.floor(windowSize / 2), Math.max(0, rows.length - windowSize)));
|
|
302
408
|
const end = Math.min(rows.length, start + windowSize);
|
|
303
|
-
const result: string[] = [];
|
|
304
409
|
if (start > 0) result.push(this.renderLine(` ↑ ${start} more`, width, "muted"));
|
|
305
410
|
for (let i = start; i < end; i++) {
|
|
306
411
|
const row = rows[i];
|
|
307
|
-
if (row)
|
|
412
|
+
if (row) appendRow(row);
|
|
308
413
|
}
|
|
309
414
|
if (end < rows.length) result.push(this.renderLine(` ↓ ${rows.length - end} more`, width, "muted"));
|
|
310
415
|
return result;
|
|
311
416
|
}
|
|
312
417
|
|
|
418
|
+
private itemFits(item: CommandPaletteItem, width: number): boolean {
|
|
419
|
+
const label = sanitizeTerminalText(item.label);
|
|
420
|
+
const shortcut = item.shortcut ? sanitizeTerminalText(item.shortcut) : "";
|
|
421
|
+
return label.trim().length > 0 && 2 + visibleWidth(label) + (shortcut ? 1 + visibleWidth(shortcut) : 0) <= width;
|
|
422
|
+
}
|
|
423
|
+
|
|
313
424
|
private renderRow(row: PaletteRow, width: number, selected: number): string {
|
|
314
425
|
if (row.kind === "blank") return "";
|
|
315
426
|
if (row.kind === "title") return this.renderLine(row.text, width, "accent");
|
|
316
|
-
return this.renderItemRow(row.item, row.itemIndex === selected, width);
|
|
427
|
+
return this.renderItemRow(row.item, row.itemIndex === selected, width, this.hovered === row.itemIndex);
|
|
317
428
|
}
|
|
318
429
|
|
|
319
|
-
private renderItemRow(item: CommandPaletteItem, focused: boolean, width: number): string {
|
|
430
|
+
private renderItemRow(item: CommandPaletteItem, focused: boolean, width: number, hovered: boolean): string {
|
|
320
431
|
const canHighlightBg = focused && this.theme?.bg !== undefined;
|
|
321
432
|
const label = sanitizeTerminalText(item.label);
|
|
322
433
|
const shortcut = item.shortcut ? sanitizeTerminalText(item.shortcut) : "";
|
|
323
434
|
if (canHighlightBg) {
|
|
324
435
|
const plainRow = this.justifyToWidth(` ${label}`, shortcut, width);
|
|
325
|
-
|
|
436
|
+
const text = this.theme ? paintHoverable(this.theme, plainRow, hovered) : plainRow;
|
|
437
|
+
return this.theme?.bg?.("selectedBg", text) ?? text;
|
|
438
|
+
}
|
|
439
|
+
if (hovered && this.theme) {
|
|
440
|
+
const prefix = focused ? "▸ " : " ";
|
|
441
|
+
return paintHoverable(this.theme, prefix + this.justifyToWidth(label, shortcut, Math.max(0, width - 2)), true);
|
|
326
442
|
}
|
|
327
443
|
const prefix = focused ? this.renderText("▸ ", "accent") : " ";
|
|
328
444
|
const prefixWidth = visibleWidth(stripAnsi(prefix));
|