gentle-pi 5.0.0 → 5.1.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 +1 -1
- package/assets/agents/gentle-ai-explore.md +3 -6
- package/assets/agents/gentle-ai-verify.md +1 -1
- package/assets/agents/gentle-ai-worker.md +9 -9
- package/assets/agents/jd-fix-agent.md +1 -1
- package/assets/agents/jd-judge-a.md +0 -1
- package/assets/agents/jd-judge-b.md +0 -1
- package/assets/migrations/agent-body-history.json +6 -0
- package/assets/orchestrator-full-delegation.md +1 -1
- package/assets/orchestrator-maintenance.md +11 -0
- package/assets/orchestrator-quota-recovery.md +1 -1
- package/assets/orchestrator-skills.md +10 -0
- package/assets/orchestrator-verification.md +9 -7
- package/assets/orchestrator.md +1 -1
- package/bin/gentle-shell.mjs +67 -15
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +10 -10
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/manifest.json +5 -5
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/orchestration/pi.md +5 -3
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/routing/pi.md +1 -1
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/lens.schema.json +3 -3
- package/contracts/review-provider-contract-mirror/v1.7.0/bundle/vectors/lens.json +1 -0
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/generated/provider-roles.baseline.json +3 -3
- package/docs/bundled-install.md +2 -2
- package/docs/delegated-verification.md +8 -4
- package/docs/desktop-feed.md +15 -6
- package/docs/desktop-rpc.md +44 -20
- package/docs/gentle-shell-desktop.md +10 -3
- package/docs/gentle-shell.md +17 -13
- package/docs/install-wizard.md +2 -2
- package/docs/odd-preparation-continuity.md +2 -2
- package/docs/permission-modes.md +10 -2
- package/docs/readme-reference.md +46 -11
- package/docs/session-profile-format.md +33 -7
- package/docs/work-continuity.md +7 -7
- package/docs/yolo-mode.md +1 -1
- package/extensions/child-context.ts +2 -11
- package/extensions/gentle-agents.ts +47 -28
- package/extensions/gentle-ai.ts +573 -353
- package/extensions/gentle-desktop-feed.ts +13 -3
- package/extensions/gentle-fast.ts +9 -2
- package/extensions/gentle-shell.ts +142 -55
- package/extensions/gentle-tps.ts +5 -0
- package/extensions/quiet-tools.ts +13 -22
- package/extensions/skill-registry.ts +9 -1
- package/herdr/mods/gentle-agents/snapshot.js +30 -23
- package/herdr/mods/gentle-chat/feed.js +6 -0
- package/herdr/mods/gentle-chat/main.js +76 -16
- package/herdr/mods/gentle-chat/session.js +13 -5
- package/herdr/mods/gentle-chat/snapshot.js +30 -23
- package/herdr/mods/gentle-chat/ui.js +7 -1
- package/herdr/mods/gentle-inspector/main.js +2 -0
- package/herdr/mods/gentle-inspector/snapshot.js +30 -23
- package/herdr/mods/gentle-palette/main.js +1 -1
- package/herdr/mods/gentle-palette/snapshot.js +30 -23
- package/herdr/mods/gentle-pane/snapshot.js +30 -23
- package/herdr/mods/gentle-sidebar/snapshot.js +30 -23
- package/herdr/mods/gentle-spaces/snapshot.js +30 -23
- package/herdr/mods/gentle-status/snapshot.js +30 -23
- package/herdr/mods/gentle-tabs/main.js +3 -2
- package/herdr/mods/gentle-tabs/new-tab.js +9 -0
- package/herdr/mods/gentle-tabs/snapshot.js +30 -23
- package/herdr/mods/gentle-tokens/snapshot.js +30 -23
- package/lib/agent-profiles.ts +50 -10
- package/lib/agents-config.ts +59 -4
- package/lib/agents-runner.ts +34 -1
- package/lib/auto-permission-runtime.ts +2 -1
- package/lib/background-jobs-tools.ts +24 -16
- package/lib/claude-bridge-config.ts +41 -0
- package/lib/desktop-agent-definitions-service.ts +10 -6
- package/lib/desktop-command-rpc.ts +71 -0
- package/lib/desktop-feed-sources.ts +44 -1
- package/lib/desktop-feed.ts +41 -29
- package/lib/desktop-rpc-agent-definitions.ts +7 -3
- package/lib/desktop-rpc-changes.ts +13 -4
- package/lib/desktop-rpc-config.ts +106 -3
- package/lib/exploration-budget.ts +3 -7
- package/lib/gentle-design.ts +23 -4
- package/lib/gentle-shell-desktop.ts +85 -0
- package/lib/gentle-shell-launcher.ts +106 -3
- package/lib/mcp-config.ts +214 -0
- package/lib/native-review-cli.ts +78 -34
- package/lib/odd-phase-inference.ts +1 -1
- package/lib/orchestrator-mode-policy.ts +25 -12
- package/lib/path-consent-fence.ts +113 -0
- package/lib/pi-settings.ts +157 -0
- package/lib/review-continuation-registry.ts +7 -20
- package/lib/review-coordinator.ts +5 -0
- package/lib/review-host-relay.ts +2 -35
- package/lib/review-integration-v2.ts +31 -12
- package/lib/sensitive-paths.ts +22 -2
- package/lib/session-profile-freeze.ts +11 -4
- package/lib/session-worktree-registry.ts +11 -5
- package/lib/shell-card.ts +27 -1
- package/lib/shell-changes-view.ts +6 -2
- package/lib/shell-changes.ts +94 -37
- package/lib/shell-git-worker.ts +158 -0
- package/lib/shell-idle-changes.ts +88 -0
- package/lib/shell-untracked-cache.ts +142 -0
- package/lib/shell-untracked-lines.ts +178 -0
- package/lib/tps-policy.ts +85 -0
- package/lib/vim-editor-adapter.ts +3 -2
- package/lib/voice-artifacts.ts +8 -1
- package/lib/voice-install.ts +7 -3
- package/lib/yolo-session-policy.ts +2 -2
- package/package.json +1 -1
- package/runtime/gentle-shell-desktop.mjs +85 -0
- package/runtime/gentle-shell-launcher.mjs +106 -3
- package/runtime/native-review-cli.mjs +77 -33
- package/runtime/review-integration-v2.mjs +31 -12
- package/runtime/sensitive-paths.mjs +22 -2
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/main-channel.mjs +27 -7
- package/scripts/verify-package-files.mjs +13 -12
- package/skills/rdd-defect-workflow/SKILL.md +2 -2
- package/tests/agent-profiles-workflow.test.ts +102 -0
- package/tests/agents-config.test.ts +1 -2
- package/tests/agents-protocol.test.ts +1 -1
- package/tests/agents-runner.test.ts +94 -2
- package/tests/append-system-prompt-route.test.ts +16 -11
- package/tests/auto-permission-runtime.test.ts +4 -4
- package/tests/bounded-stop-contract.test.ts +50 -62
- package/tests/child-context-files.test.ts +6 -6
- package/tests/child-web-package.test.ts +1 -1
- package/tests/controlled-engineering-editor.test.ts +192 -0
- package/tests/controlled-engineering-launch.test.ts +136 -0
- package/tests/controlled-engineering.test.ts +244 -0
- package/tests/delivery-b-rendered-surfaces.test.ts +1 -1
- package/tests/desktop-feed-tool-summaries.test.ts +1 -1
- package/tests/desktop-feed-transcript.test.ts +17 -0
- package/tests/desktop-feed.test.ts +141 -7
- package/tests/desktop-liveness.test.ts +125 -0
- package/tests/desktop-persona.test.ts +17 -0
- package/tests/desktop-rpc-agent-definitions.test.ts +23 -2
- package/tests/desktop-rpc-changes.test.ts +80 -3
- package/tests/desktop-rpc-config-mcp-fidelity.test.ts +106 -0
- package/tests/desktop-rpc-config-readonly-stores.test.ts +458 -0
- package/tests/desktop-rpc-config.test.ts +5 -2
- package/tests/desktop-rpc-design.test.ts +21 -0
- package/tests/desktop-rpc-session-snapshot-commands.test.ts +50 -0
- package/tests/desktop-session-switch.test.ts +237 -0
- package/tests/desktop-target-session.test.ts +104 -0
- package/tests/destructive-command-guard.test.ts +187 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +73 -9
- package/tests/exploration-budget.test.ts +2 -26
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +14 -10
- package/tests/full-delegation-closure.test.ts +19 -9
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agents.test.ts +214 -9
- package/tests/gentle-ai-exploration-budget.test.ts +3 -2
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai.test.ts +29 -5
- package/tests/gentle-chat-read-failure.test.ts +74 -0
- package/tests/gentle-chat-session-read.test.ts +127 -0
- package/tests/gentle-design.test.ts +39 -0
- package/tests/gentle-shell-desktop.test.ts +108 -0
- package/tests/gentle-shell-launcher-auto-provision.test.ts +152 -0
- package/tests/gentle-shell-launcher-machine-output.test.ts +356 -0
- package/tests/gentle-shell.test.ts +93 -12
- package/tests/gentle-tps.test.ts +57 -0
- package/tests/independent-recovery-delivery.test.ts +15 -13
- package/tests/installer-preflight.test.ts +3 -2
- package/tests/job-turn-end-texts.test.ts +57 -0
- package/tests/lazy-module-contradictions-contract.test.ts +1 -2
- package/tests/main-channel.test.ts +12 -1
- package/tests/maintainer/desktop-rpc.maintest.ts +2 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +113 -1
- package/tests/no-self-pause-contract.test.ts +8 -7
- package/tests/odd-phase-inference.test.ts +2 -2
- package/tests/odd-routing-canonical-ratchet.test.ts +1 -1
- package/tests/odd-routing-contract.test.ts +1 -1
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +5 -5
- package/tests/orchestrator-skills-inline-contract.test.ts +26 -0
- package/tests/package-manifest.test.ts +11 -16
- package/tests/packaged-agent-codemode.test.ts +79 -0
- package/tests/path-consent-fence.test.ts +326 -0
- package/tests/pi-update-launcher.test.ts +1 -1
- package/tests/primary-session-prompt.test.ts +9 -7
- package/tests/profile-fast-tier.test.ts +79 -4
- package/tests/progress-rule-contract.test.ts +54 -0
- package/tests/rdd-delivery-warning.test.ts +42 -4
- package/tests/review-actor-tool-deny.test.ts +1 -2
- package/tests/review-continuation-registry.test.ts +17 -17
- package/tests/review-controller-native-recovery.test.ts +100 -0
- package/tests/review-controller-native-routing.test.ts +129 -24
- package/tests/review-coordinator.test.ts +14 -0
- package/tests/review-host-relay-restart-parity.test.ts +2 -52
- package/tests/review-host-relay-routing.test.ts +57 -297
- package/tests/review-host-relay.test.ts +0 -46
- package/tests/review-integration-v2-forward.test.ts +39 -2
- package/tests/review-json-arguments.test.ts +30 -9
- package/tests/review-one-call-findings.test.ts +1 -0
- package/tests/review-untracked-inventory-replay.test.ts +181 -0
- package/tests/runtime-harness.mjs +27 -1
- package/tests/sensitive-path-tools.test.ts +155 -4
- package/tests/session-profile-extension.test.ts +90 -11
- package/tests/session-profile-freeze.test.ts +49 -2
- package/tests/session-profile-v1-compat.test.ts +11 -3
- package/tests/session-worktree-registry.test.ts +23 -0
- package/tests/shell-changes-idle-start.test.ts +510 -0
- package/tests/shell-changes-untracked-bound.test.ts +230 -0
- package/tests/shell-changes-view.test.ts +8 -2
- package/tests/shell-changes.test.ts +134 -0
- package/tests/shell-git-runner-stall.test.ts +74 -0
- package/tests/shell-git-worker-fallback.test.ts +140 -0
- package/tests/shell-git-worker-lifetime.test.ts +91 -0
- package/tests/shell-render-cache-runtime.test.ts +256 -3
- package/tests/shell-untracked-cache.test.ts +213 -0
- package/tests/short-check-routing-contract.test.ts +11 -7
- package/tests/skill-registry.test.ts +3 -3
- package/tests/support/chat-ui.ts +39 -0
- package/tests/t7-recovery-preservation.test.ts +68 -0
- package/tests/tps-policy.test.ts +96 -0
- package/tests/turn-end-rule-contract.test.ts +155 -0
- package/tests/turn-end-scope.test.ts +39 -0
- package/tests/verification-scoped-stop-contract.test.ts +1 -1
- package/tests/verification-tiers-contract.test.ts +4 -3
- package/tests/verify-first-launch-contract.test.ts +19 -7
- package/tests/vim-editor-adapter.test.ts +4 -4
- package/tests/voice-install.test.ts +97 -11
- package/tests/windows-hidden-processes.test.ts +11 -44
- package/tests/work-continuity-contract.test.ts +48 -55
- package/tests/yolo-session-policy.test.ts +2 -0
- package/contracts/review-provider-contract-mirror/v1.6.0/bundle/vectors/lens.json +0 -1
- package/extensions/codegraph-tools.ts +0 -437
- package/tests/child-codegraph-bootstrap.test.ts +0 -74
- package/tests/codegraph-tools.test.ts +0 -554
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.6.0 → v1.7.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { realpathSync } from "node:fs";
|
|
2
2
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
-
import { resolveGentlePiAgentHome } from "../lib/agent-home.ts";
|
|
3
|
+
import { gentlePiConfigHome, resolveGentlePiAgentHome } from "../lib/agent-home.ts";
|
|
4
|
+
import { resolvePersonaMode, type PersonaMode } from "../lib/persona-config.ts";
|
|
4
5
|
import { CLAUDE_BRIDGE_PROVIDER } from "../lib/bridge-cost.ts";
|
|
5
6
|
import { isHomeOrBroadUserDirectory } from "../lib/bounded-writer-admission.ts";
|
|
6
7
|
import {
|
|
@@ -24,7 +25,7 @@ import { createDesktopFeedStore, sweepDesktopFeedOrphans, type DesktopFeedStore
|
|
|
24
25
|
import { answerableFromDesktop, createDesktopActionInbox, DESKTOP_ACTION_LIMITS, createDesktopActivityTimeline, providerDecisionIn, questionShape, sweepDesktopActionOrphans, watchDesktopActionInbox, type DesktopActionInbox, type DesktopActionQuestion, type DesktopActivityTimeline } from "../lib/desktop-feed-actions.ts";
|
|
25
26
|
import { askAnswerHandle } from "../lib/desktop-feed-answers.ts";
|
|
26
27
|
import { DesktopPermissionBridge } from "../lib/desktop-rpc-permissions.ts";
|
|
27
|
-
import { createDesktopFeedProfileReader, createUntrackedLineCounter, desktopFeedGitRunner, processAncestors,
|
|
28
|
+
import { createDesktopFeedProfileReader, createUntrackedLineCounter, desktopFeedGitRunner, processAncestors, type DesktopFeedProfile, type ParentOf, type UntrackedLineCounter } from "../lib/desktop-feed-sources.ts";
|
|
28
29
|
import { DesktopAgentsBridge } from "../lib/desktop-agents-service.ts";
|
|
29
30
|
import { DesktopJobsBridge } from "../lib/desktop-jobs-service.ts";
|
|
30
31
|
import { DesktopUsageBridge } from "../lib/desktop-usage-service.ts";
|
|
@@ -72,6 +73,8 @@ export interface DesktopFeedOptions {
|
|
|
72
73
|
git?: (root: string) => GitRunner;
|
|
73
74
|
parentOf?: ParentOf;
|
|
74
75
|
profile?: (cwd: string, sessionId: string | undefined) => DesktopFeedProfile;
|
|
76
|
+
/** The persona for a session cwd; defaults to the persona.json resolution the TUI uses. */
|
|
77
|
+
persona?: (cwd: string) => PersonaMode | undefined;
|
|
75
78
|
realpath?: (path: string) => string | undefined;
|
|
76
79
|
rootExists?: (root: string) => boolean;
|
|
77
80
|
sweep?: (agentDir: string, keep: string) => void;
|
|
@@ -83,6 +86,11 @@ export interface DesktopFeedOptions {
|
|
|
83
86
|
|
|
84
87
|
const SUBSCRIPTION_PROVIDERS = new Set([CLAUDE_BRIDGE_PROVIDER]);
|
|
85
88
|
|
|
89
|
+
// A persona that cannot be read leaves the feed field null instead of failing the snapshot.
|
|
90
|
+
function safePersona(read: (cwd: string) => PersonaMode | undefined, cwd: string): PersonaMode | undefined {
|
|
91
|
+
try { return read(cwd); } catch { return undefined; }
|
|
92
|
+
}
|
|
93
|
+
|
|
86
94
|
function permissionDetail(mode: string): string | undefined {
|
|
87
95
|
const text = mode === "yolo" ? YOLO_STATUS_TEXT : mode === "super-yolo" ? SUPER_YOLO_STATUS_TEXT : undefined;
|
|
88
96
|
return text?.includes(" — ") ? text.slice(text.indexOf(" — ") + 3).trim() : text;
|
|
@@ -189,6 +197,7 @@ export function createDesktopFeedExtension(options: DesktopFeedOptions = {}) {
|
|
|
189
197
|
const timers = options.timers ?? realDesktopFeedTimers;
|
|
190
198
|
const gitFor = options.git ?? ((root: string) => desktopFeedGitRunner(root, env));
|
|
191
199
|
const readProfile = options.profile ?? createDesktopFeedProfileReader(env);
|
|
200
|
+
const readPersona = options.persona ?? ((cwd: string) => resolvePersonaMode(cwd, gentlePiConfigHome(env)));
|
|
192
201
|
const rootExists = options.rootExists ?? ((root: string) => { try { return realpathSync(root) !== ""; } catch { return false; } });
|
|
193
202
|
const realpath = options.realpath ?? ((path: string) => { try { return realpathSync.native(path); } catch { return undefined; } });
|
|
194
203
|
const activityClock = options.activityClock ?? Date.now;
|
|
@@ -285,6 +294,7 @@ export function createDesktopFeedExtension(options: DesktopFeedOptions = {}) {
|
|
|
285
294
|
thinkingLevel,
|
|
286
295
|
subscription,
|
|
287
296
|
profile: session.profile,
|
|
297
|
+
persona: safePersona(readPersona, ctx.cwd),
|
|
288
298
|
context: context ? { percent: context.percent, tokens: context.tokens, contextWindow: context.contextWindow } : undefined,
|
|
289
299
|
usage: session.usage,
|
|
290
300
|
usageProviders: session.usageProviders,
|
|
@@ -525,7 +535,7 @@ export function createDesktopFeedExtension(options: DesktopFeedOptions = {}) {
|
|
|
525
535
|
session.yolo = { adapter, unobserve };
|
|
526
536
|
refreshPermission(session);
|
|
527
537
|
}, () => undefined);
|
|
528
|
-
void processAncestors(process.ppid, DESKTOP_FEED_LIMITS.ancestors, options.parentOf
|
|
538
|
+
void processAncestors(process.ppid, DESKTOP_FEED_LIMITS.ancestors, options.parentOf).then((ancestors) => {
|
|
529
539
|
if (!current(session) || ancestors.length === 0) return;
|
|
530
540
|
session.ancestors = ancestors;
|
|
531
541
|
schedule();
|
|
@@ -2,12 +2,19 @@ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-a
|
|
|
2
2
|
import { readSessionProfileBinding } from "../lib/session-profile-binding.ts";
|
|
3
3
|
import { readSessionProfileAuthority } from "../lib/session-profile-authority.ts";
|
|
4
4
|
import { gentlePiConfigHome } from "../lib/agent-home.ts";
|
|
5
|
-
import { freezeSessionProfileAtStartup, readFrozenDefaultOrchestrator } from "../lib/session-profile-freeze.ts";
|
|
5
|
+
import { freezeSessionProfileAtStartup, profileFollowEnabled, readFrozenDefaultOrchestrator } from "../lib/session-profile-freeze.ts";
|
|
6
6
|
import { isServiceTier } from "../lib/model-routing-authority.ts";
|
|
7
7
|
import { applyOpenAITier, CHILD_TIER_ENV, PROFILE_TIER_EVENT } from "../lib/openai-fast-tier.ts";
|
|
8
8
|
|
|
9
9
|
type Selection = "standard" | "fast" | undefined;
|
|
10
10
|
|
|
11
|
+
// gentle-shell#1064 A3 S4 reading side: a `follow` session ignores the startup
|
|
12
|
+
// record and resolves the current defaults, exactly as `resolveSessionProfile`
|
|
13
|
+
// does. An explicit choice is not a startup state and still wins.
|
|
14
|
+
function ignoredStartupBinding(binding: { origin: string }): boolean {
|
|
15
|
+
return binding.origin !== "user" && profileFollowEnabled();
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
export default function (pi: ExtensionAPI) {
|
|
12
19
|
let selection: Selection;
|
|
13
20
|
let profileModel: string | undefined;
|
|
@@ -24,7 +31,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
24
31
|
// later default into a session that already froze its startup choice.
|
|
25
32
|
freezeSessionProfileAtStartup({ sessionId, cwd, configHome: gentlePiConfigHome() });
|
|
26
33
|
}
|
|
27
|
-
const entry = binding ? binding.modelProfiles.orchestrator
|
|
34
|
+
const entry = binding && !ignoredStartupBinding(binding) ? binding.modelProfiles.orchestrator
|
|
28
35
|
: authority && !authority.available ? undefined : readFrozenDefaultOrchestrator(sessionId);
|
|
29
36
|
const matches = entry?.model === `${ctx.model?.provider}/${ctx.model?.id}`;
|
|
30
37
|
let child: { tier?: unknown; model?: unknown } | undefined;
|
|
@@ -9,14 +9,17 @@ import { defaultCacheRoot, ImageDiskCache } from "../lib/image-disk-cache.ts";
|
|
|
9
9
|
import { execFile, spawnSync } from "node:child_process";
|
|
10
10
|
import { openInExternalEditor, type ExternalEditorHost } from "../lib/external-editor.ts";
|
|
11
11
|
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
12
|
-
import { lstat
|
|
12
|
+
import { lstat } from "node:fs/promises";
|
|
13
13
|
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { createShellGitWorker, failedGitRead, gitExecResult, type GitExecError, type ShellGitWorkerRead } from "../lib/shell-git-worker.ts";
|
|
15
|
+
import { shellUntrackedLines } from "../lib/shell-untracked-lines.ts";
|
|
16
|
+
import { createIdleChanges, scheduleChangesIdle, type ChangesIdleScheduler } from "../lib/shell-idle-changes.ts";
|
|
14
17
|
import { profilesFilePath, profileRoleEntries, readProfilesFileResult } from "../lib/agent-profiles.ts";
|
|
15
18
|
import { resolveSessionProfile, sessionProfileLabel, sessionProfileModelProfiles } from "../lib/session-profile-freeze.ts";
|
|
16
19
|
import * as os from "node:os";
|
|
17
20
|
import { dirname, join, resolve } from "node:path";
|
|
18
21
|
import { buildShellHeaderModel, renderShellBar, renderShellBelowInputFloat, renderShellBottomOnlyBar, renderShellHeaderChrome, renderShellSidebarBar, renderShellStatusBar, renderShellStatusSections, renderShellChromeBar, renderShellChromePad, renderShellTitleRow, type StatusSection, type StatusTarget, keepNativeWorkingRow, shellEnabled, shellHeaderUsageHit, shellJobsCount, type ShellBarModel, type ShellBarTheme } from "../lib/shell-bar.ts";
|
|
19
|
-
import { DIFF_MAX_BYTES, WorktreeChangesTracker, changesDigest, renderChangesWidget, type ChangedFile, type ChangesModel, type FileRevision, type GitRunner, type
|
|
22
|
+
import { DIFF_MAX_BYTES, WorktreeChangesTracker, changesDigest, renderChangesWidget, type ChangedFile, type ChangesModel, type FileRevision, type GitRunner, type UntrackedLineCounts, type WorktreeChanges } from "../lib/shell-changes.ts";
|
|
20
23
|
import { WorktreeChangesView } from "../lib/shell-changes-view.ts";
|
|
21
24
|
import { changeDirectoryInsideRoot, loadFileDiff, repositoryGitDirectories, runFileDiff } from "../lib/change-diff.ts";
|
|
22
25
|
import { DESKTOP_CHANGES_SERVICE_CHANNEL, DESKTOP_CHANGES_SERVICE_SCHEMA, projectDesktopChanges, projectDesktopDiff, type DesktopChangesService } from "../lib/desktop-rpc-changes.ts";
|
|
@@ -48,10 +51,11 @@ import { oddPhaseRegistry } from "../lib/odd-phase.ts";
|
|
|
48
51
|
import { CLAUDE_BRIDGE_PROVIDER, priceBridgeMessage } from "../lib/bridge-cost.ts";
|
|
49
52
|
import { inferOddPhase } from "../lib/odd-phase-inference.ts";
|
|
50
53
|
import { isInteractiveMode } from "../lib/rpc-host.ts";
|
|
51
|
-
import { gentlePiConfigHome } from "../lib/agent-home.ts";
|
|
54
|
+
import { gentlePiConfigHome, resolveGentlePiAgentHome } from "../lib/agent-home.ts";
|
|
52
55
|
import { resolveAnimationPolicy, writeAnimationPolicy, type AnimationPolicy } from "../lib/animation-policy.ts";
|
|
53
56
|
import { resolveVimPolicy, writeVimPolicy, type VimPolicy } from "../lib/vim-policy.ts";
|
|
54
57
|
import { resolveHistoryCapture, writeHistoryCapturePolicy } from "../lib/history-capture-policy.ts";
|
|
58
|
+
import { resolveTpsSettings, writeTpsSettings } from "../lib/tps-policy.ts";
|
|
55
59
|
import { HERDR_TASK_SUMMARY_CHANGED, resolveHerdrTaskSummarySettings, writeHerdrTaskSummarySettings } from "../lib/herdr-task-summary-policy.ts";
|
|
56
60
|
import { createRequire } from "node:module";
|
|
57
61
|
import { createVimEditorAdapter, isAuditedPiEditorVersion } from "../lib/vim-editor-adapter.ts";
|
|
@@ -202,6 +206,10 @@ export interface ShellDeps {
|
|
|
202
206
|
gitRunner(cwd: string, maxBuffer?: number): GitRunner;
|
|
203
207
|
/** A root Changes may scan: removed worktrees and leftover directories are skipped. */
|
|
204
208
|
rootExists(root: string): boolean;
|
|
209
|
+
scheduleChangesIdle: ChangesIdleScheduler;
|
|
210
|
+
/** Override the per-user untracked count cache directory. */
|
|
211
|
+
changesCacheDirectory?: string;
|
|
212
|
+
changesLineCache(directory?: string): UntrackedLineCounts;
|
|
205
213
|
vimRuntimeVersion?(): string | undefined;
|
|
206
214
|
/** Clipboard image source for the prompt's attachment chips; tests inject a fake. */
|
|
207
215
|
readClipboardImage?(): Promise<ClipboardImage | null>;
|
|
@@ -295,7 +303,7 @@ function ambientDevBinary(): DevBinaryNotice | undefined {
|
|
|
295
303
|
}
|
|
296
304
|
}
|
|
297
305
|
|
|
298
|
-
const defaultShellDeps: Omit<ShellDeps, "activeProfile"> = { fetch: (input, init) => globalThis.fetch(input, init), now: () => Date.now(), devBinary: ambientDevBinary, resolveWorktree: resolveSessionWorktree,
|
|
306
|
+
const defaultShellDeps: Omit<ShellDeps, "activeProfile" | "gitRunner"> = { fetch: (input, init) => globalThis.fetch(input, init), now: () => Date.now(), devBinary: ambientDevBinary, resolveWorktree: resolveSessionWorktree, rootExists: (root) => existsSync(join(root, ".git")), scheduleChangesIdle, changesLineCache: (directory) => shellUntrackedLines(undefined, undefined, directory) };
|
|
299
307
|
|
|
300
308
|
interface AssistantUsageEntry {
|
|
301
309
|
type: string;
|
|
@@ -1658,17 +1666,35 @@ const COMMANDS_COMMAND_NAME = "gentle:commands";
|
|
|
1658
1666
|
// calling back; cut them after this grace so the scan still settles.
|
|
1659
1667
|
const GIT_TREE_KILL_GRACE_MS = 1_000;
|
|
1660
1668
|
|
|
1661
|
-
|
|
1669
|
+
const GIT_WORKER_SHUTDOWN_MS = GIT_TIMEOUT_MS + GIT_TREE_KILL_GRACE_MS;
|
|
1670
|
+
const standaloneGitWorker = createShellGitWorker(GIT_WORKER_SHUTDOWN_MS);
|
|
1671
|
+
|
|
1672
|
+
export function shellGitRunner(cwd: string, env: NodeJS.ProcessEnv = process.env, run: typeof execFile = execFile, maxBuffer = Infinity, killProcessTree: ProcessTreeKiller | undefined = process.platform === "win32" ? windowsProcessTreeKiller : undefined, timeoutMs = GIT_TIMEOUT_MS, readGitOnWorker: ShellGitWorkerRead = standaloneGitWorker.read): GitRunner {
|
|
1662
1673
|
// Pi exec cannot replace the inherited environment. Use argv directly and
|
|
1663
1674
|
// a complete sanitized environment for discovery, status, and lazy diffs.
|
|
1664
1675
|
const childEnv = worktreeGitEnvironment(env);
|
|
1676
|
+
const options = {
|
|
1677
|
+
env: childEnv,
|
|
1678
|
+
encoding: "utf8",
|
|
1679
|
+
shell: false,
|
|
1680
|
+
windowsHide: true,
|
|
1681
|
+
// Only a single diff passes a bound, and is told when it hit it.
|
|
1682
|
+
// Large porcelain inventories must not become partial successful scans.
|
|
1683
|
+
maxBuffer,
|
|
1684
|
+
} as const;
|
|
1685
|
+
// execFile's UTF-8 maxBuffer slices the boundary chunk in string units
|
|
1686
|
+
// after tracking bytes. Moving that reader to a worker changes chunking
|
|
1687
|
+
// (notably during a UI stall), and can change the text of a bounded diff.
|
|
1688
|
+
// Keep lazy, bounded reads on the legacy reader; inventory stays off-thread.
|
|
1689
|
+
if (maxBuffer === Infinity && process.platform !== "win32" && !killProcessTree && run === execFile) {
|
|
1690
|
+
return (args) => readGitOnWorker(["-C", cwd, ...args], { ...options, timeout: timeoutMs });
|
|
1691
|
+
}
|
|
1665
1692
|
// A timed-out Git scan on Windows is more than one process: `git` hands the
|
|
1666
1693
|
// status work to a descendant, and that descendant survives the direct child
|
|
1667
1694
|
// Node itself kills, so a large repository whose scan passes the timeout
|
|
1668
1695
|
// leaks another orphaned git.exe on every poll until physical memory is
|
|
1669
1696
|
// exhausted (#927). Windows therefore owns the deadline below, so the tree
|
|
1670
|
-
// kill lands while the parent is still alive for taskkill to walk
|
|
1671
|
-
// else execFile's own timeout stays exactly as it was.
|
|
1697
|
+
// kill lands while the parent is still alive for taskkill to walk.
|
|
1672
1698
|
const treeKiller = killProcessTree;
|
|
1673
1699
|
return (args) => new Promise((resolve) => {
|
|
1674
1700
|
let deadline: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -1677,28 +1703,19 @@ export function shellGitRunner(cwd: string, env: NodeJS.ProcessEnv = process.env
|
|
|
1677
1703
|
// A scan that passed its deadline is a failed scan, never a partial
|
|
1678
1704
|
// success, even if the direct child exited 0 before its pipes closed.
|
|
1679
1705
|
let timedOut = false;
|
|
1680
|
-
const settle = (error:
|
|
1706
|
+
const settle = (error: GitExecError | null, stdout: string): void => {
|
|
1681
1707
|
settled = true;
|
|
1682
1708
|
if (deadline !== undefined) clearTimeout(deadline);
|
|
1683
1709
|
if (grace !== undefined) clearTimeout(grace);
|
|
1684
|
-
if (error?.code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER") { resolve({ stdout, code: 1, truncated: true }); return; }
|
|
1685
|
-
const code = timedOut ? 1 : error ? typeof error.code === "number" ? error.code : 1 : 0;
|
|
1686
1710
|
// Without a tree killer execFile owns the timeout and reports its kill on the error.
|
|
1687
|
-
resolve(
|
|
1711
|
+
resolve(gitExecResult(error, stdout, timedOut || Boolean(treeKiller === undefined && error?.killed)));
|
|
1688
1712
|
};
|
|
1689
1713
|
let child: ReturnType<typeof execFile>;
|
|
1690
1714
|
try {
|
|
1691
1715
|
child = run("git", ["-C", cwd, ...args], {
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
windowsHide: true,
|
|
1696
|
-
...(treeKiller === undefined ? { timeout: GIT_TIMEOUT_MS } : {}),
|
|
1697
|
-
// Pi exec accumulates output without a maxBuffer cap. In particular,
|
|
1698
|
-
// large porcelain inventories must not become partial successful scans.
|
|
1699
|
-
// Only a single diff passes a bound, and is told when it hit it.
|
|
1700
|
-
maxBuffer,
|
|
1701
|
-
}, (error, stdout) => settle(error, stdout));
|
|
1716
|
+
...options,
|
|
1717
|
+
...(treeKiller === undefined ? { timeout: timeoutMs } : {}),
|
|
1718
|
+
}, settle);
|
|
1702
1719
|
} catch (error) {
|
|
1703
1720
|
// A spawn that throws (invalid options, an injected runner) is a failed scan.
|
|
1704
1721
|
settle(error as { code?: unknown }, "");
|
|
@@ -1721,7 +1738,7 @@ export function shellGitRunner(cwd: string, env: NodeJS.ProcessEnv = process.env
|
|
|
1721
1738
|
child.stderr?.destroy();
|
|
1722
1739
|
}, GIT_TREE_KILL_GRACE_MS);
|
|
1723
1740
|
grace.unref?.();
|
|
1724
|
-
},
|
|
1741
|
+
}, timeoutMs);
|
|
1725
1742
|
deadline.unref?.();
|
|
1726
1743
|
});
|
|
1727
1744
|
}
|
|
@@ -1729,14 +1746,7 @@ export function shellGitRunner(cwd: string, env: NodeJS.ProcessEnv = process.env
|
|
|
1729
1746
|
// One file's diff lives in lib/change-diff.ts so the panel and Desktop RPC show the same text.
|
|
1730
1747
|
export { loadFileDiff };
|
|
1731
1748
|
|
|
1732
|
-
|
|
1733
|
-
const untrackedLines = (root: string): LineCounter => async (path) => {
|
|
1734
|
-
const target = join(root, path);
|
|
1735
|
-
const info = await lstat(target);
|
|
1736
|
-
if (!info.isFile() || info.size > DIFF_MAX_BYTES) return 0;
|
|
1737
|
-
const text = await readFile(target, "utf8");
|
|
1738
|
-
return text === "" ? 0 : text.split("\n").length - (text.endsWith("\n") ? 1 : 0);
|
|
1739
|
-
};
|
|
1749
|
+
export { shellUntrackedLines };
|
|
1740
1750
|
// Same-count edits still change size or mtime, so an open diff reloads.
|
|
1741
1751
|
const fileRevision = (root: string): FileRevision => async (path) => {
|
|
1742
1752
|
const info = await lstat(join(root, path));
|
|
@@ -2025,8 +2035,8 @@ async function fetchFromSource(source: UsageSource, apiKey: string | undefined,
|
|
|
2025
2035
|
}
|
|
2026
2036
|
}
|
|
2027
2037
|
|
|
2028
|
-
// Changes refreshes
|
|
2029
|
-
//
|
|
2038
|
+
// Fire-and-forget Changes refreshes are tracked so tests can wait for them
|
|
2039
|
+
// instead of guessing a delay.
|
|
2030
2040
|
const backgroundChangeRefreshes = new Set<Promise<void>>();
|
|
2031
2041
|
function trackChangeRefresh(refresh: Promise<void>): void {
|
|
2032
2042
|
const tracked = refresh.catch(() => {}).finally(() => { backgroundChangeRefreshes.delete(tracked); });
|
|
@@ -2061,7 +2071,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2061
2071
|
ctx.ui.notify(`Keymaps: ${keymaps.path} is unreadable or malformed; using the default keys.`, "warning");
|
|
2062
2072
|
});
|
|
2063
2073
|
const profileReader = createActiveProfileReader(env);
|
|
2064
|
-
const deps
|
|
2074
|
+
const deps = { ...defaultShellDeps, activeProfile: profileReader, ...overrides };
|
|
2065
2075
|
let closeCustomize: (() => void) | undefined;
|
|
2066
2076
|
let customizeGeneration = 0;
|
|
2067
2077
|
let profilePoll: ReturnType<typeof setInterval> | undefined;
|
|
@@ -2533,6 +2543,8 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2533
2543
|
gentlePiConfigHome: doubleEscCancelConfigHome,
|
|
2534
2544
|
}).policy;
|
|
2535
2545
|
let changes: WorktreeChangesTracker | undefined;
|
|
2546
|
+
let changesGit: { run: ShellDeps["gitRunner"]; dispose(): Promise<void> } | undefined;
|
|
2547
|
+
let changesIdle: ReturnType<typeof createIdleChanges> | undefined;
|
|
2536
2548
|
let registry: SessionWorktreeRegistry | undefined;
|
|
2537
2549
|
let currentContext: ExtensionContext | undefined;
|
|
2538
2550
|
let disposeFooter: (() => void) | undefined;
|
|
@@ -2568,21 +2580,33 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2568
2580
|
shown = fingerprint;
|
|
2569
2581
|
showChanges(ctx, model, visualSettings.visibility.changes, (width) => groupedChangesOwner(width));
|
|
2570
2582
|
};
|
|
2571
|
-
|
|
2572
|
-
//
|
|
2573
|
-
|
|
2574
|
-
const changesTracker = (ctx: ExtensionContext) => {
|
|
2583
|
+
// Changes inventories the session's surviving roots. The first background
|
|
2584
|
+
// scan waits until after startup and the first quiet paint.
|
|
2585
|
+
const changesTracker = (ctx: ExtensionContext, git: ShellDeps["gitRunner"]) => {
|
|
2575
2586
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
2576
2587
|
const roots = () => {
|
|
2577
2588
|
try { return sessionChangeRoots(sessionId, ctx.sessionManager.getEntries()).filter((root) => deps.rootExists(root) && !isHomeOrBroadUserDirectory(root)); }
|
|
2578
2589
|
catch { return []; }
|
|
2579
2590
|
};
|
|
2580
|
-
|
|
2591
|
+
// An injected environment without an agent home stays isolated from the
|
|
2592
|
+
// user's cache unless the caller explicitly supplies a cache directory.
|
|
2593
|
+
const directory = deps.changesCacheDirectory ?? (env === process.env || env.GENTLE_PI_AGENT_HOME || env.PI_CODING_AGENT_DIR
|
|
2594
|
+
? join(resolveGentlePiAgentHome(env), "cache", "gentle-shell-untracked-lines") : undefined);
|
|
2595
|
+
return new WorktreeChangesTracker(git(ctx.cwd), (root) => git(root), undefined, roots, fileRevision, deps.changesLineCache(directory));
|
|
2596
|
+
};
|
|
2597
|
+
const refreshChangesTracker = async (tracker: WorktreeChangesTracker, fromIdle = false) => {
|
|
2598
|
+
// Opening the panel (or another explicit refresh) can cover a waiting
|
|
2599
|
+
// idle scan. Concurrent callers still share the tracker's in-flight scan.
|
|
2600
|
+
const idle = changes === tracker ? changesIdle : undefined;
|
|
2601
|
+
const turn = idle?.scanStarted();
|
|
2602
|
+
const model = await tracker.refresh();
|
|
2603
|
+
idle?.scanFinished(tracker.untrackedCountsPendingFiles, model, tracker.failedRoots.length, fromIdle ? turn : undefined);
|
|
2604
|
+
return model;
|
|
2581
2605
|
};
|
|
2582
|
-
const refreshChanges = async (ctx: ExtensionContext) => {
|
|
2606
|
+
const refreshChanges = async (ctx: ExtensionContext, fromIdle = false) => {
|
|
2583
2607
|
const tracker = changes;
|
|
2584
2608
|
if (!tracker || !ctx.hasUI || registry?.sessionId !== ctx.sessionManager.getSessionId()) return;
|
|
2585
|
-
const model = await tracker
|
|
2609
|
+
const model = await refreshChangesTracker(tracker, fromIdle);
|
|
2586
2610
|
if (changes === tracker) applyChanges(ctx, model);
|
|
2587
2611
|
};
|
|
2588
2612
|
// Desktop's changes slice reaches this tracker only through a versioned,
|
|
@@ -2597,7 +2621,8 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2597
2621
|
if (typeof request.respond !== "function" || !request.context) return;
|
|
2598
2622
|
let sessionId: string;
|
|
2599
2623
|
try { sessionId = request.context.sessionManager.getSessionId(); } catch { return; }
|
|
2600
|
-
|
|
2624
|
+
const git = changesGit;
|
|
2625
|
+
if (!git || !changes || registry?.sessionId !== sessionId) return;
|
|
2601
2626
|
let disposed = false;
|
|
2602
2627
|
const ids = new Map<string, string>();
|
|
2603
2628
|
const idFor = (root: string) => {
|
|
@@ -2607,19 +2632,24 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2607
2632
|
};
|
|
2608
2633
|
// No tracked worktree, a failed root, or a replaced session is
|
|
2609
2634
|
// unavailable: a failed scan is never reported as a clean root.
|
|
2610
|
-
const scan = async (): Promise<WorktreeChangesTracker | undefined> => {
|
|
2635
|
+
const scan = async (maxPasses = 1): Promise<WorktreeChangesTracker | undefined> => {
|
|
2611
2636
|
const tracker = changes;
|
|
2612
|
-
if (disposed || !tracker || registry?.sessionId !== sessionId) return undefined;
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2637
|
+
if (disposed || !tracker || changesGit !== git || registry?.sessionId !== sessionId) return undefined;
|
|
2638
|
+
for (let pass = 0; pass < maxPasses; pass++) {
|
|
2639
|
+
await refreshChangesTracker(tracker);
|
|
2640
|
+
if (disposed || changes !== tracker) return undefined;
|
|
2641
|
+
if (!tracker.untrackedCountsPending || tracker.failedRoots.length > 0) break;
|
|
2642
|
+
}
|
|
2643
|
+
if (currentContext) applyChanges(currentContext, tracker.model);
|
|
2616
2644
|
return tracker.scannedRootCount === 0 || tracker.failedRoots.length > 0 ? undefined : tracker;
|
|
2617
2645
|
};
|
|
2618
2646
|
try {
|
|
2619
2647
|
request.respond({
|
|
2620
2648
|
schema: DESKTOP_CHANGES_SERVICE_SCHEMA,
|
|
2621
2649
|
async read() {
|
|
2622
|
-
|
|
2650
|
+
// One extra pass handles inventories just over 64 MiB, without
|
|
2651
|
+
// letting a huge or continuously edited tree hold an RPC open.
|
|
2652
|
+
const tracker = await scan(2);
|
|
2623
2653
|
return tracker ? projectDesktopChanges(tracker.worktrees, idFor) : undefined;
|
|
2624
2654
|
},
|
|
2625
2655
|
async diff(rootId, path) {
|
|
@@ -2634,12 +2664,12 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2634
2664
|
// Git lists files behind a directory link (a Windows junction) as
|
|
2635
2665
|
// part of the tree; Desktop never serves content outside the root,
|
|
2636
2666
|
// nor the repository's own git dir reached through an alias in it.
|
|
2637
|
-
const gitDirectories = await repositoryGitDirectories(
|
|
2667
|
+
const gitDirectories = await repositoryGitDirectories(git.run(tree.root), tree.root);
|
|
2638
2668
|
if (disposed || !gitDirectories) return { kind: "unavailable" };
|
|
2639
2669
|
if (!(await changeDirectoryInsideRoot(tree.root, file.path, gitDirectories))) return { kind: "not_found" };
|
|
2640
2670
|
// Unlike the panel, never run a command the repository's config
|
|
2641
2671
|
// names (textconv, external diff, fsmonitor) for a Desktop read.
|
|
2642
|
-
const projected = projectDesktopDiff(await runFileDiff(
|
|
2672
|
+
const projected = projectDesktopDiff(await runFileDiff(git.run(tree.root, DIFF_MAX_BYTES), file, { inertRepositoryCommands: true }));
|
|
2643
2673
|
if (disposed || !projected) return { kind: "unavailable" };
|
|
2644
2674
|
return { kind: "ok", ...projected };
|
|
2645
2675
|
},
|
|
@@ -2663,6 +2693,8 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2663
2693
|
},
|
|
2664
2694
|
});
|
|
2665
2695
|
pi.on("session_start", async (_event, ctx) => {
|
|
2696
|
+
changesIdle?.dispose();
|
|
2697
|
+
changesIdle = undefined;
|
|
2666
2698
|
customizeGeneration++;
|
|
2667
2699
|
if (imagesDiskCachePolicy === "session") {
|
|
2668
2700
|
const cacheRoot = defaultCacheRoot(env);
|
|
@@ -2681,6 +2713,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2681
2713
|
}
|
|
2682
2714
|
stopProfilePoll();
|
|
2683
2715
|
registry?.close();
|
|
2716
|
+
void changes?.closeUntrackedCounts();
|
|
2684
2717
|
currentContext = ctx;
|
|
2685
2718
|
changes = undefined;
|
|
2686
2719
|
registry = new SessionWorktreeRegistry(pi, ctx.sessionManager, ctx.cwd, deps.resolveWorktree);
|
|
@@ -2701,8 +2734,27 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
2701
2734
|
}, 2_000);
|
|
2702
2735
|
profilePoll.unref?.();
|
|
2703
2736
|
}
|
|
2704
|
-
|
|
2737
|
+
void changesGit?.dispose();
|
|
2738
|
+
const worker = createShellGitWorker(GIT_WORKER_SHUTDOWN_MS);
|
|
2739
|
+
const git: NonNullable<typeof changesGit> = {
|
|
2740
|
+
run(cwd, maxBuffer) {
|
|
2741
|
+
const run = overrides.gitRunner?.(cwd, maxBuffer) ?? shellGitRunner(cwd, process.env, execFile, maxBuffer, undefined, GIT_TIMEOUT_MS, worker.read);
|
|
2742
|
+
// A stale scan may request more Git work after its current call
|
|
2743
|
+
// settles. It must never start a worker for a closed session.
|
|
2744
|
+
return (args) => changesGit === git ? run(args) : Promise.resolve(failedGitRead());
|
|
2745
|
+
},
|
|
2746
|
+
dispose: worker.dispose,
|
|
2747
|
+
};
|
|
2748
|
+
changesGit = git;
|
|
2749
|
+
changes = changesTracker(ctx, git.run);
|
|
2705
2750
|
const tracker = changes;
|
|
2751
|
+
const idle = changesIdle = createIdleChanges({
|
|
2752
|
+
isIdle: () => ctx.isIdle(),
|
|
2753
|
+
refresh: () => trackChangeRefresh(refreshChanges(ctx, true)),
|
|
2754
|
+
// Observe only: returning undefined neither consumes nor rewrites the input.
|
|
2755
|
+
observeInput: (listener) => ctx.ui.onTerminalInput?.(() => { listener(); return undefined; }),
|
|
2756
|
+
schedule: deps.scheduleChangesIdle,
|
|
2757
|
+
});
|
|
2706
2758
|
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
2707
2759
|
disposeFooter?.();
|
|
2708
2760
|
sidebarTui = tui;
|
|
@@ -3028,6 +3080,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3028
3080
|
return { ...part,
|
|
3029
3081
|
render(width: number) {
|
|
3030
3082
|
if (disposed) return [];
|
|
3083
|
+
idle.firstPaint();
|
|
3031
3084
|
// Running-only: a finished tail must never paint a ⧗ 0 jobs row.
|
|
3032
3085
|
const compactRunningJobs = runningJobs?.filter((job) => job.status === undefined);
|
|
3033
3086
|
if (visualSettings.statusPlacement === "hidden" && (tui as TUI & { mode?: string }).mode !== "fullscreen" && compactRunningJobs?.length) {
|
|
@@ -3088,6 +3141,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3088
3141
|
if (changes !== tracker) return;
|
|
3089
3142
|
shown = "";
|
|
3090
3143
|
applyChanges(ctx, tracker.model);
|
|
3144
|
+
idle.started();
|
|
3091
3145
|
});
|
|
3092
3146
|
// Chips still in the submitted draft travel as real image attachments, so
|
|
3093
3147
|
// the model sees the image without calling `read` on a temp-file path.
|
|
@@ -3103,7 +3157,12 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3103
3157
|
}
|
|
3104
3158
|
return { action: "transform", text: submitted.text, images: [...(event.images ?? []), ...submitted.images] };
|
|
3105
3159
|
});
|
|
3106
|
-
pi.on("session_shutdown", (_event, ctx) => {
|
|
3160
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
3161
|
+
const gitStopped = changesGit?.dispose();
|
|
3162
|
+
const countsSaved = changes?.closeUntrackedCounts();
|
|
3163
|
+
changesGit = undefined;
|
|
3164
|
+
changesIdle?.dispose();
|
|
3165
|
+
changesIdle = undefined;
|
|
3107
3166
|
customizeGeneration++;
|
|
3108
3167
|
disposeFooter?.();
|
|
3109
3168
|
imageAttachments.dispose();
|
|
@@ -3134,11 +3193,13 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3134
3193
|
registry = undefined;
|
|
3135
3194
|
changes = undefined;
|
|
3136
3195
|
currentContext = undefined;
|
|
3196
|
+
await Promise.all([gitStopped, countsSaved]);
|
|
3137
3197
|
});
|
|
3138
3198
|
const openChanges = async (ctx: ExtensionContext) => {
|
|
3139
|
-
|
|
3199
|
+
const git = changesGit;
|
|
3200
|
+
if (!changes || !git) return;
|
|
3140
3201
|
const tracker = changes;
|
|
3141
|
-
const model = await tracker
|
|
3202
|
+
const model = await refreshChangesTracker(tracker);
|
|
3142
3203
|
if (changes !== tracker) return;
|
|
3143
3204
|
applyChanges(ctx, model);
|
|
3144
3205
|
// A failed root scan is unknown, never clean: say so whenever one failed.
|
|
@@ -3155,7 +3216,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3155
3216
|
return;
|
|
3156
3217
|
}
|
|
3157
3218
|
if (failed > 0) ctx.ui.notify(`Git status failed for ${failed} ${failed === 1 ? "root" : "roots"}; ${failed === 1 ? "its" : "their"} changes are not listed.`, "warning");
|
|
3158
|
-
await showChangesOverlay(ctx, { loadDiff: (root, file) => loadFileDiff(
|
|
3219
|
+
await showChangesOverlay(ctx, { loadDiff: (root, file) => loadFileDiff(git.run(root, DIFF_MAX_BYTES), file), worktrees: () => tracker.worktrees, refresh: () => refreshChangesTracker(tracker), apply: applyChanges, pollMs: changesPollMs(env) });
|
|
3159
3220
|
};
|
|
3160
3221
|
pi.registerCommand(IMAGES_COMMAND_NAME, {
|
|
3161
3222
|
description: "List the on-disk paths of images pasted in this draft (needs GENTLE_PI_IMAGES_DISK_CACHE=session).",
|
|
@@ -3240,7 +3301,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3240
3301
|
});
|
|
3241
3302
|
}
|
|
3242
3303
|
pi.registerCommand("gentle:customize", {
|
|
3243
|
-
description: "Configure appearance, task summary publishing, audio notifications, Vim editing, RDD, session permissions and global Auto/YOLO defaults, and prompt history capture.",
|
|
3304
|
+
description: "Configure appearance, task summary publishing, TPS usage notification, audio notifications, Vim editing, RDD, session permissions and global Auto/YOLO defaults, and prompt history capture.",
|
|
3244
3305
|
handler: async (_args, ctx) => {
|
|
3245
3306
|
if (ctx.mode !== "tui" || !ctx.hasUI) {
|
|
3246
3307
|
if (ctx.hasUI) ctx.ui.notify("Customization requires an interactive terminal.", "warning");
|
|
@@ -3514,6 +3575,30 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3514
3575
|
else ctx.ui.notify(result.enabled ? "Prompt history capture: on. Applies from the next prompt; stored history is kept." : "Prompt history capture: off. New prompts are not recorded; stored history is kept.", "info");
|
|
3515
3576
|
},
|
|
3516
3577
|
});
|
|
3578
|
+
// The TPS extension rereads this preference at every agent end, so a change
|
|
3579
|
+
// applies from the next run without reload. Fail open keeps a broken file
|
|
3580
|
+
// notifying like today; an explicit toggle here replaces that file.
|
|
3581
|
+
const tpsPolicy = () => resolveTpsSettings({ gentlePiConfigHome: doubleEscCancelConfigHome });
|
|
3582
|
+
category = "Notifications";
|
|
3583
|
+
for (const enabled of [true, false] as const) rows.push({
|
|
3584
|
+
category,
|
|
3585
|
+
label: () => `TPS usage notification: ${enabled ? "ON" : "OFF"}${tpsPolicy().settings.enabled === enabled ? " (current)" : ""}`,
|
|
3586
|
+
choice: explicitChoice("TPS usage notification", enabled ? "ON" : "OFF", () => tpsPolicy().settings.enabled === enabled),
|
|
3587
|
+
preview: () => {
|
|
3588
|
+
const current = tpsPolicy();
|
|
3589
|
+
return { title: "TPS usage notification · end-of-run summary", sample: enabled
|
|
3590
|
+
? `Shows one info line after each agent run: "TPS 410.0 tok/s. out …, cache r/w …, total …, 2.5s".${current.malformed ? " The saved file is malformed; saving replaces it." : ""}`
|
|
3591
|
+
: "Hides the per-run token/latency summary; nothing else changes." };
|
|
3592
|
+
},
|
|
3593
|
+
action: async () => {
|
|
3594
|
+
writeTpsSettings({ enabled }, { gentlePiConfigHome: doubleEscCancelConfigHome });
|
|
3595
|
+
const result = tpsPolicy();
|
|
3596
|
+
if (result.settings.enabled !== enabled) throw new Error(`TPS preference did not persist; inspect ${result.globalFile}`);
|
|
3597
|
+
ctx.ui.notify(enabled
|
|
3598
|
+
? "TPS usage notification: on. Applies from the next agent run."
|
|
3599
|
+
: "TPS usage notification: off. Applies from the next agent run; nothing is collected while hidden.", "info");
|
|
3600
|
+
},
|
|
3601
|
+
});
|
|
3517
3602
|
rows.push(...buildNotificationRows(ctx));
|
|
3518
3603
|
category = "Layout";
|
|
3519
3604
|
const taskSummary = () => resolveHerdrTaskSummarySettings(home);
|
|
@@ -3801,6 +3886,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3801
3886
|
},
|
|
3802
3887
|
});
|
|
3803
3888
|
pi.on("agent_start", (_event, ctx) => {
|
|
3889
|
+
if (registry?.sessionId === ctx.sessionManager.getSessionId()) changesIdle?.turnStarted();
|
|
3804
3890
|
// A turn can start any other way (the user sending the draft, an
|
|
3805
3891
|
// extension, a shortcut) before the aborted run's own agent_settled
|
|
3806
3892
|
// below has delivered the pending text. Nothing is sent from here: Pi
|
|
@@ -3858,6 +3944,7 @@ export default function gentleShell(pi: ExtensionAPI, env: NodeJS.ProcessEnv = p
|
|
|
3858
3944
|
}
|
|
3859
3945
|
});
|
|
3860
3946
|
pi.on("agent_end", async (_event, ctx) => {
|
|
3947
|
+
if (registry?.sessionId === ctx.sessionManager.getSessionId()) changesIdle?.turnEnded();
|
|
3861
3948
|
// A slow or failing Git never holds the turn end.
|
|
3862
3949
|
trackChangeRefresh(refreshChanges(ctx));
|
|
3863
3950
|
void refreshUsage(ctx, false);
|
package/extensions/gentle-tps.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
2
2
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { isChildSession } from "../lib/child-session.ts";
|
|
4
|
+
import { resolveTpsSettings } from "../lib/tps-policy.ts";
|
|
4
5
|
|
|
5
6
|
function isAssistantMessage(message: unknown): message is AssistantMessage {
|
|
6
7
|
if (!message || typeof message !== "object") return false;
|
|
@@ -45,6 +46,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
45
46
|
const elapsedSeconds = elapsedMs / 1000;
|
|
46
47
|
const tokensPerSecond = output / elapsedSeconds;
|
|
47
48
|
const message = `TPS ${tokensPerSecond.toFixed(1)} tok/s. out ${output.toLocaleString()}, in ${input.toLocaleString()}, cache r/w ${cacheRead.toLocaleString()}/${cacheWrite.toLocaleString()}, total ${totalTokens.toLocaleString()}, ${elapsedSeconds.toFixed(1)}s`;
|
|
49
|
+
// Reread on every run: a /gentle:customize toggle applies from the next run
|
|
50
|
+
// without a reload. Fail open: missing, malformed or unreadable policy keeps
|
|
51
|
+
// the notification (today's behavior).
|
|
52
|
+
if (!resolveTpsSettings().settings.enabled) return;
|
|
48
53
|
ctx.ui.notify(message, "info");
|
|
49
54
|
});
|
|
50
55
|
}
|
|
@@ -19,7 +19,7 @@ import { registerCompactCodemode } from "../lib/codemode-renderer.ts";
|
|
|
19
19
|
import { offerBuiltinCodemodeOptOut, type BuiltinCodemodeOptOutOptions } from "../lib/builtin-codemode-optout.ts";
|
|
20
20
|
import { getGentleAiRenderState, renderGentleAiLifecycleCall, renderGentleAiResult, type GentleAiRenderContext } from "../lib/gentle-ai-renderer.ts";
|
|
21
21
|
import {
|
|
22
|
-
CARD_TONE, cardAwaitingResult, cardBottom, cardInnerWidth, cardLine, cardRunningLine,
|
|
22
|
+
CARD_TONE, CardFrame, cardAwaitingResult, cardBottom, cardInnerWidth, cardLine, cardRunningLine, cardTopRows, floatRows, markCardResult,
|
|
23
23
|
type CardRowContext, type CardTheme,
|
|
24
24
|
} from "../lib/shell-card.ts";
|
|
25
25
|
import { sanitizeTerminalText, stripAnsi } from "../lib/terminal-theme.ts";
|
|
@@ -608,31 +608,18 @@ function toolTone(pending: boolean, failed: boolean): ToolTone {
|
|
|
608
608
|
return pending ? CARD_TONE.WARNING : CARD_TONE.SUCCESS;
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
-
/** One settled frame per component: bounded memory, including all card chrome. */
|
|
612
|
-
class ToolCardRows {
|
|
613
|
-
private frame?: { width: number; style: ReturnType<typeof cardStyle>; running: boolean; lines: string[] };
|
|
614
|
-
|
|
615
|
-
render(width: number, running: boolean, build: () => string[]): string[] {
|
|
616
|
-
const style = cardStyle();
|
|
617
|
-
if (this.frame?.width === width && this.frame.style === style && this.frame.running === running) return this.frame.lines;
|
|
618
|
-
const lines = build();
|
|
619
|
-
this.frame = { width, style, running, lines };
|
|
620
|
-
return lines;
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
invalidate(): void { this.frame = undefined; }
|
|
624
|
-
}
|
|
625
|
-
|
|
626
611
|
class ToolCardTop implements Component {
|
|
627
|
-
private readonly rows = new
|
|
612
|
+
private readonly rows = new CardFrame();
|
|
628
613
|
private readonly header: (inner: number) => string;
|
|
629
614
|
private readonly glyph: string;
|
|
630
615
|
private readonly tone: ToolTone;
|
|
631
616
|
private readonly theme: CardTheme;
|
|
632
617
|
private readonly hint: string | undefined;
|
|
633
618
|
private readonly row: CardRowContext | undefined;
|
|
619
|
+
private readonly followsCardContent: boolean;
|
|
634
620
|
|
|
635
|
-
constructor(header: (inner: number) => string, tone: ToolTone, theme: CardTheme, glyph: string, hint?: string, row?: CardRowContext) {
|
|
621
|
+
constructor(header: (inner: number) => string, tone: ToolTone, theme: CardTheme, glyph: string, hint?: string, row?: CardRowContext, followsCardContent = false) {
|
|
622
|
+
this.followsCardContent = followsCardContent;
|
|
636
623
|
this.header = header;
|
|
637
624
|
this.glyph = glyph;
|
|
638
625
|
this.tone = tone;
|
|
@@ -646,7 +633,11 @@ class ToolCardTop implements Component {
|
|
|
646
633
|
const target = Math.max(0, Math.floor(width));
|
|
647
634
|
if (target === 0) return [];
|
|
648
635
|
const running = this.row !== undefined && cardAwaitingResult(this.row);
|
|
649
|
-
|
|
636
|
+
// Bash headings also read the live Card content preference. Neither input
|
|
637
|
+
// should invalidate unrelated cards or make a settled heading track a clock.
|
|
638
|
+
const minimal = this.followsCardContent && cardContent() === CARD_CONTENT.MINIMAL;
|
|
639
|
+
const revision = (running ? 1 : 0) | (minimal ? 2 : 0);
|
|
640
|
+
return this.rows.render(target, revision, () => floatRows(this.tone, this.theme, target, (inner) => ({
|
|
650
641
|
head: cardTopRows({ title: this.header(inner), glyph: this.glyph, body: [], tone: this.tone }, this.theme, inner, this.hint),
|
|
651
642
|
body: running ? [cardRunningLine(this.tone, this.theme, inner)] : undefined,
|
|
652
643
|
bottom: running ? cardBottom(this.tone, this.theme, inner) : undefined,
|
|
@@ -657,7 +648,7 @@ class ToolCardTop implements Component {
|
|
|
657
648
|
}
|
|
658
649
|
|
|
659
650
|
class ToolCardBody implements Component {
|
|
660
|
-
private readonly rows = new
|
|
651
|
+
private readonly rows = new CardFrame();
|
|
661
652
|
private readonly inner: () => Component;
|
|
662
653
|
private readonly tone: ToolTone;
|
|
663
654
|
private readonly theme: CardTheme;
|
|
@@ -680,7 +671,7 @@ class ToolCardBody implements Component {
|
|
|
680
671
|
bottom: cardBottom(this.tone, this.theme, inner),
|
|
681
672
|
afterHeading: true,
|
|
682
673
|
}));
|
|
683
|
-
return this.cacheable ? this.rows.render(target,
|
|
674
|
+
return this.cacheable ? this.rows.render(target, undefined, build) : build();
|
|
684
675
|
}
|
|
685
676
|
|
|
686
677
|
invalidate(): void { this.rows.invalidate(); }
|
|
@@ -781,7 +772,7 @@ export function createQuietToolRenderer(
|
|
|
781
772
|
const hint = finished ? stripAnsi(keyHint("app.tools.expand", renderContext.expanded === true ? "to collapse" : "to expand")) : undefined;
|
|
782
773
|
// Minimal collapsed cards fit the call in the top rule; the room leaves the rule's glyph, edges and hint.
|
|
783
774
|
const summary = renderContext.expanded === true ? undefined : (inner: number) => ({ width: inner - CARD_TOP_CHROME - (hint ? visibleWidth(hint) + 2 : 0) });
|
|
784
|
-
return new ToolCardTop((inner) => formatToolCall(toolName, callArgs, theme, summary?.(inner)), tone, theme, TOOL_GLYPH[toolName], hint, renderContext);
|
|
775
|
+
return new ToolCardTop((inner) => formatToolCall(toolName, callArgs, theme, summary?.(inner)), tone, theme, TOOL_GLYPH[toolName], hint, renderContext, toolName === "bash");
|
|
785
776
|
},
|
|
786
777
|
/** Builds the card component for this render pass; collapsed cards delegate to the wrapped-line cache keyed by the tool result object. */
|
|
787
778
|
renderResult(result, options, theme, context) {
|