gentle-pi 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/assets/agents/gentle-ai-verify.md +4 -0
- package/assets/agents/gentle-ai-worker.md +1 -0
- package/assets/migrations/agent-body-history.json +147 -0
- package/assets/orchestrator-delegation-reference.md +3 -3
- package/assets/orchestrator-delegation.md +2 -2
- package/assets/orchestrator-verification.md +10 -6
- package/assets/orchestrator.md +8 -8
- package/bin/gentle-shell.mjs +61 -26
- package/docs/ci-performance.md +11 -0
- package/docs/delegated-verification.md +6 -0
- package/docs/fast-mode.md +15 -0
- package/docs/gentle-agents-activity.md +8 -0
- package/docs/gentle-music.md +6 -3
- package/docs/gentle-shell.md +70 -20
- package/docs/install-wizard.md +1 -1
- package/docs/mcp-status.md +52 -0
- package/docs/prompt-budget.md +28 -0
- package/docs/readme-reference.md +82 -21
- package/docs/session-profile-format.md +20 -5
- package/docs/sound-notifications.md +1 -1
- package/docs/star-prompt.md +32 -0
- package/docs/work-continuity.md +46 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/codegraph-tools.ts +38 -4
- package/extensions/gentle-agents.ts +477 -50
- package/extensions/gentle-ai.ts +1046 -191
- package/extensions/gentle-fast.ts +61 -0
- package/extensions/gentle-guide.ts +174 -0
- package/extensions/gentle-herdr-activity.ts +21 -1
- package/extensions/gentle-herdr-agent.ts +144 -0
- package/extensions/gentle-music.ts +10 -0
- package/extensions/gentle-program-identity.ts +61 -0
- package/extensions/gentle-shell.ts +642 -97
- package/extensions/gentle-star-prompt.ts +334 -0
- package/extensions/gentle-stats.ts +5 -5
- package/extensions/gentle-todo.ts +42 -22
- package/extensions/history/store.ts +18 -12
- package/extensions/skill-registry.ts +35 -3
- package/extensions/startup-banner.ts +39 -7
- package/lib/agent-assets.ts +74 -17
- package/lib/agent-profiles.ts +1 -1
- package/lib/agents-config.ts +12 -3
- package/lib/agents-keys.ts +8 -16
- package/lib/agents-protocol.ts +80 -4
- package/lib/agents-runner.ts +105 -4
- package/lib/agents-view.ts +6 -1
- package/lib/agents-widget.ts +132 -9
- package/lib/bridge-cost.ts +28 -0
- package/lib/codemode-renderer.ts +16 -0
- package/lib/command-palette-catalog.ts +1 -0
- package/lib/command-palette.ts +21 -8
- package/lib/exploration-budget.ts +62 -0
- package/lib/gentle-guide.ts +201 -0
- package/lib/gentle-shell-launcher.ts +4 -0
- package/lib/herdr-activity.ts +9 -3
- package/lib/herdr-task-summary-policy.ts +85 -0
- package/lib/inprocess-reviewer.ts +33 -13
- package/lib/jobs-sidebar-state.ts +5 -6
- package/lib/jobs-widget.ts +16 -52
- package/lib/keymaps-customize.ts +81 -0
- package/lib/keymaps.ts +291 -0
- package/lib/model-fallback-notice.ts +61 -0
- package/lib/model-fallback-policy.ts +141 -0
- package/lib/model-fallback-store.ts +143 -0
- package/lib/model-routing-authority.ts +10 -2
- package/lib/nan-provider.ts +3 -2
- package/lib/native-review-cli.ts +7 -2
- package/lib/notification-customize.ts +48 -51
- package/lib/openai-fast-tier.ts +22 -0
- package/lib/orchestrator-discovery.ts +5 -1
- package/lib/orchestrator-fallback.ts +75 -0
- package/lib/pasted-image-paths.ts +113 -0
- package/lib/questionnaire/questionnaire-view.ts +121 -7
- package/lib/review-candidate-view-owner.ts +4 -0
- package/lib/review-candidate-view.ts +10 -7
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +22 -7
- package/lib/review-repository.ts +5 -0
- package/lib/session-profile-append-controller.ts +21 -6
- package/lib/session-profile-authority.ts +119 -0
- package/lib/session-profile-binding.ts +54 -5
- package/lib/session-profile-freeze.ts +105 -9
- package/lib/session-profile-integration.ts +313 -0
- package/lib/session-profile-persistence.ts +63 -9
- package/lib/shell-bar.ts +171 -56
- package/lib/shell-card.ts +26 -6
- package/lib/shell-page.ts +120 -0
- package/lib/shell-panel.ts +149 -0
- package/lib/shell-prompt.ts +53 -1
- package/lib/shell-sidebar-layout.ts +98 -25
- package/lib/shell-sidebar.ts +54 -1
- package/lib/shell-stats.ts +123 -0
- package/lib/shell-todo.ts +71 -0
- package/lib/shell-usage.ts +12 -2
- package/lib/star-prompt.ts +197 -0
- package/lib/verifier-admission.ts +18 -8
- package/lib/verifier-settle-reminder.ts +64 -0
- package/lib/vim-editor-adapter.ts +6 -1
- package/lib/visual-customization-policy.ts +41 -6
- package/lib/visual-customize-view.ts +164 -26
- package/lib/visual-layout-preview.ts +43 -0
- package/lib/yolo-session-policy.ts +28 -1
- package/package.json +1 -1
- package/runtime/gentle-shell-launcher.mjs +4 -0
- package/runtime/native-review-cli.mjs +7 -2
- package/runtime/review-integration-v2.mjs +22 -7
- package/runtime/windows-session-transport.ps1 +60 -3
- package/scripts/bootstrap.sh +4 -1
- package/scripts/installer-preflight.mjs +1 -1
- package/scripts/pi-update.mjs +113 -3
- package/scripts/run-test-suite.mjs +17 -1
- package/scripts/shell-snapshot.mjs +340 -0
- package/scripts/test-packed-runner.mjs +1 -1
- package/scripts/update-agent-body-history.mjs +41 -0
- package/scripts/verify-installer-tap.mjs +45 -0
- package/scripts/verify-package-files.mjs +2 -0
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/tui-design/NOTICE.md +5 -0
- package/skills/tui-design/SKILL.md +56 -0
- package/skills/tui-design/references/commands.md +75 -0
- package/skills/tui-design/references/critique.md +48 -0
- package/skills/tui-design/references/design-doc.md +44 -0
- package/skills/tui-design/references/terminal-craft.md +64 -0
- package/skills/tui-design/references/visual-loop.md +32 -0
- package/tests/agents-protocol.test.ts +53 -1
- package/tests/agents-runner.test.ts +168 -3
- package/tests/agents-view.test.ts +27 -0
- package/tests/agents-widget.test.ts +312 -10
- package/tests/bounded-scan-contract.test.ts +39 -0
- package/tests/bridge-cost.test.ts +32 -0
- package/tests/bundled-install.test.ts +6 -4
- package/tests/ci-concurrency.test.ts +11 -0
- package/tests/ci-merge-base-identity.test.ts +114 -0
- package/tests/codegraph-tools.test.ts +69 -0
- package/tests/codemode-rendering.test.ts +22 -2
- package/tests/command-palette.test.ts +16 -2
- package/tests/commit-slice-signal.test.ts +11 -9
- package/tests/delegate-for-reason-contract.test.ts +5 -4
- package/tests/design-canvas-server.test.ts +6 -2
- package/tests/exploration-budget.test.ts +128 -0
- package/tests/fixtures/agent-assets/gentle-ai-worker.strict-tdd-era.md +122 -0
- package/tests/fixtures/measure-orchestrator-prompt.mjs +2 -1
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +18 -10
- package/tests/fixtures/session-profile-v1/replay.ts +125 -0
- package/tests/fixtures/session-profile-v1/session-profile-authority.ts +113 -0
- package/tests/fixtures/session-profile-v1/session-profile-binding.ts +83 -0
- package/tests/fixtures/session-profile-v1/session-profile-disk-reader.ts +182 -0
- package/tests/fixtures/session-profile-v1/session-profile-freeze.ts +290 -0
- package/tests/fixtures/session-profile-v1/session-profile-persistence.ts +195 -0
- package/tests/fixtures/session-profile-v1/v1-inputs.ts +16 -0
- package/tests/fixtures/windows-pipe-availability.ps1 +26 -0
- package/tests/fixtures/windows-session-bootstrap.ps1 +6 -2
- package/tests/gentle-agents.test.ts +416 -21
- package/tests/gentle-ai-exploration-budget.test.ts +135 -0
- package/tests/gentle-ai.test.ts +1011 -37
- package/tests/gentle-fast.test.ts +73 -0
- package/tests/gentle-guide.test.ts +208 -0
- package/tests/gentle-herdr-activity.test.ts +76 -2
- package/tests/gentle-herdr-agent.test.ts +111 -0
- package/tests/gentle-music.test.ts +36 -1
- package/tests/gentle-program-identity.test.ts +197 -0
- package/tests/gentle-shell-bin.test.ts +49 -26
- package/tests/gentle-shell-launcher.test.ts +18 -2
- package/tests/gentle-shell.test.ts +1068 -37
- package/tests/gentle-stats.test.ts +15 -2
- package/tests/gentle-todo.test.ts +50 -4
- package/tests/herdr-task-summary-policy.test.ts +128 -0
- package/tests/history-store-private-mode.test.ts +40 -0
- package/tests/image-paste-chips.test.ts +42 -0
- package/tests/inprocess-reviewer.test.ts +122 -0
- package/tests/installer-posix-bootstrap.test.ts +67 -5
- package/tests/installer-server.test.ts +2 -2
- package/tests/installer-windows-diagnostics.test.ts +4 -5
- package/tests/isolated-config-home.ts +28 -0
- package/tests/jobs-widget.test.ts +25 -37
- package/tests/keymaps-customize.test.ts +114 -0
- package/tests/keymaps.test.ts +103 -0
- package/tests/maintainer/mcp-status.maintest.ts +88 -0
- package/tests/maintainer/pi-update-source.maintest.ts +116 -0
- package/tests/model-fallback-notice.test.ts +45 -0
- package/tests/model-fallback-policy.test.ts +83 -0
- package/tests/model-fallback-store.test.ts +111 -0
- package/tests/nan-provider.test.ts +4 -4
- package/tests/no-self-pause-contract.test.ts +19 -0
- package/tests/notification-customize.test.ts +58 -34
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/odd-routing-contract.test.ts +1 -1
- package/tests/orchestrator-fallback.test.ts +82 -0
- package/tests/orchestrator-prompt-budget.test.ts +131 -0
- package/tests/package-manifest.test.ts +160 -7
- package/tests/pasted-image-paths.test.ts +118 -0
- package/tests/persona-reply-language.test.ts +61 -0
- package/tests/pi-update-launcher.test.ts +32 -8
- package/tests/pi-update-source.test.ts +162 -0
- package/tests/profile-fast-tier.test.ts +311 -0
- package/tests/profile-tier-footer.test.ts +79 -0
- package/tests/questionnaire-view.test.ts +150 -0
- package/tests/review-candidate-owner-sweep.test.ts +93 -0
- package/tests/review-candidate-view.test.ts +51 -0
- package/tests/review-controller-native-routing.test.ts +120 -6
- package/tests/review-gate.test.ts +24 -0
- package/tests/review-inspect-preflight.test.ts +197 -0
- package/tests/review-integration-v2-forward.test.ts +59 -0
- package/tests/review-repository.test.ts +52 -1
- package/tests/review-sidebar-state.test.ts +5 -5
- package/tests/run-test-suite.test.ts +61 -5
- package/tests/sensitive-path-tools.test.ts +74 -0
- package/tests/session-profile-append-controller.test.ts +63 -0
- package/tests/session-profile-authority.test.ts +259 -0
- package/tests/session-profile-binding.test.ts +15 -0
- package/tests/session-profile-extension.test.ts +615 -0
- package/tests/session-profile-freeze.test.ts +110 -2
- package/tests/session-profile-integration.test.ts +857 -0
- package/tests/session-profile-persistence.test.ts +57 -0
- package/tests/session-profile-v1-compat.test.ts +221 -0
- package/tests/shell-bar.test.ts +113 -55
- package/tests/shell-card.test.ts +13 -1
- package/tests/shell-page.test.ts +108 -0
- package/tests/shell-panel.test.ts +332 -0
- package/tests/shell-prompt.test.ts +54 -0
- package/tests/shell-render-cache.test.ts +5 -0
- package/tests/shell-sidebar-fullscreen.test.ts +12 -0
- package/tests/shell-sidebar-layout.test.ts +159 -27
- package/tests/shell-stats.test.ts +90 -0
- package/tests/shell-usage.test.ts +14 -0
- package/tests/skill-registry.test.ts +68 -1
- package/tests/star-prompt.test.ts +470 -0
- package/tests/startup-banner.test.ts +57 -1
- package/tests/task-size-routing-contract.test.ts +45 -1
- package/tests/verifier-settle-reminder.test.ts +281 -0
- package/tests/verify-first-launch-contract.test.ts +56 -5
- package/tests/verify-installer-tap.test.ts +57 -0
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/visual-customization-policy.test.ts +61 -7
- package/tests/visual-customize-view.test.ts +253 -8
- package/tests/visual-layout-preview.test.ts +28 -0
- package/tests/windows-session-bootstrap.test.ts +105 -2
- package/tests/work-continuity-contract.test.ts +86 -0
- package/tests/writer-surfaces.test.ts +12 -10
- package/tests/yolo-customize.test.ts +30 -11
- package/tests/yolo-mode-runtime.test.ts +4 -2
- package/tests/yolo-mode.test.ts +16 -2
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { visibleWidth, type Component, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
3
|
+
import { gentlePiConfigHome } from "../lib/agent-home.ts";
|
|
4
|
+
import { NativePointerRegion } from "../lib/native-pointer-region.ts";
|
|
5
|
+
import { paintHoverable, type HoverTheme } from "../lib/shell-hover.ts";
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_STAR_PROMPT_STATE,
|
|
8
|
+
DISMISS_CHORD,
|
|
9
|
+
PROMPTS_BEFORE_ASKING,
|
|
10
|
+
STAR_CHORD,
|
|
11
|
+
STAR_PROMPT_IDLE_MS,
|
|
12
|
+
STAR_PROMPT_REPOSITORY_URLS,
|
|
13
|
+
STAR_PROMPT_VISIBLE_MS,
|
|
14
|
+
ghStar,
|
|
15
|
+
ghStarred,
|
|
16
|
+
matchesStarPromptChord,
|
|
17
|
+
openRepositoryInBrowser,
|
|
18
|
+
readStarPromptState,
|
|
19
|
+
shouldOfferStarPrompt,
|
|
20
|
+
writeStarPromptState,
|
|
21
|
+
type GhOutcome,
|
|
22
|
+
type StarPromptState,
|
|
23
|
+
} from "../lib/star-prompt.ts";
|
|
24
|
+
|
|
25
|
+
type Unsubscribe = () => void;
|
|
26
|
+
type Timer = { cancel: () => void };
|
|
27
|
+
|
|
28
|
+
export interface StarPromptDeps {
|
|
29
|
+
configHome?: string;
|
|
30
|
+
readState?: (configHome: string) => { state: StarPromptState; unusable: boolean };
|
|
31
|
+
writeState?: (configHome: string, state: StarPromptState) => void;
|
|
32
|
+
/** Schedules the idle/visible waits; returns a canceller. Defaults to setTimeout. */
|
|
33
|
+
schedule?: (ms: number, fn: () => void) => Timer;
|
|
34
|
+
now?: () => number;
|
|
35
|
+
ghStarred?: () => Promise<GhOutcome>;
|
|
36
|
+
ghStar?: () => Promise<GhOutcome>;
|
|
37
|
+
openRepository?: (url: string) => Promise<{ opened: boolean; error?: string }>;
|
|
38
|
+
/** Skips offering entirely (headless environments). */
|
|
39
|
+
headless?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface SessionRuntime {
|
|
43
|
+
state: StarPromptState;
|
|
44
|
+
unusable: boolean;
|
|
45
|
+
offeredThisSession: boolean;
|
|
46
|
+
agentRunning: boolean;
|
|
47
|
+
visible: boolean;
|
|
48
|
+
waitingIdle: boolean;
|
|
49
|
+
lastInputAt: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const STATUS_KEY = "star-prompt";
|
|
53
|
+
const OFFER_TEXT = `Enjoying Gentle Shell? Ctrl+G stars both Gentleman-Programming repos (${STAR_PROMPT_REPOSITORY_URLS.map((url) => url.replace("https://", "")).join(" and ")}) on GitHub, Alt+D never asks again`;
|
|
54
|
+
|
|
55
|
+
const STAR_BUTTON = "[star]";
|
|
56
|
+
/** Longest first: the row shows the longest wording that fits whole, so no word
|
|
57
|
+
* is ever cut, and the [star] button keeps working even when none fits. */
|
|
58
|
+
const OFFER_WORDINGS = [
|
|
59
|
+
OFFER_TEXT,
|
|
60
|
+
"Enjoying Gentle Shell? Ctrl+G stars gentle-shell and gentle-ai on GitHub, Alt+D never asks again",
|
|
61
|
+
"Enjoying Gentle Shell? Ctrl+G stars us on GitHub, Alt+D never asks again",
|
|
62
|
+
"Ctrl+G stars us on GitHub, Alt+D never asks again",
|
|
63
|
+
"Ctrl+G star, Alt+D dismiss",
|
|
64
|
+
"Ctrl+G star",
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
/** The one-row offer below the editor: the green offer text in the longest
|
|
68
|
+
* wording that fits, then the [star] button right-aligned like the changes
|
|
69
|
+
* row's /gentle:changes hint, with the shell's shared hover treatment.
|
|
70
|
+
* Clicking it does exactly what Ctrl+G does. Mouse reports only arrive in
|
|
71
|
+
* fullscreen; elsewhere the chords keep working. */
|
|
72
|
+
function offerRow(theme: HoverTheme, tui: { requestRender(): void }, onStar: () => void): Component & { handleMouse(event: TuiMouseEvent): unknown; dispose(): void } {
|
|
73
|
+
let hovered = false;
|
|
74
|
+
let buttonStart = -1;
|
|
75
|
+
const row: Component = {
|
|
76
|
+
render(width) {
|
|
77
|
+
const buttonWidth = visibleWidth(STAR_BUTTON);
|
|
78
|
+
if (width < buttonWidth) {
|
|
79
|
+
buttonStart = -1;
|
|
80
|
+
return [""];
|
|
81
|
+
}
|
|
82
|
+
const room = width - buttonWidth - 1;
|
|
83
|
+
const text = OFFER_WORDINGS.find((wording) => visibleWidth(wording) <= room) ?? "";
|
|
84
|
+
buttonStart = width - buttonWidth;
|
|
85
|
+
const gap = " ".repeat(buttonStart - visibleWidth(text));
|
|
86
|
+
return [`${text ? theme.fg("success", text) : ""}${gap}${paintHoverable(theme, STAR_BUTTON, hovered, "accent")}`];
|
|
87
|
+
},
|
|
88
|
+
invalidate() {
|
|
89
|
+
hovered = false;
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
const onButton = (event: TuiMouseEvent) => buttonStart >= 0 && event.x >= buttonStart && event.x < buttonStart + visibleWidth(STAR_BUTTON);
|
|
93
|
+
const region = new NativePointerRegion(row, {
|
|
94
|
+
onHover(event) {
|
|
95
|
+
// The region spans the whole row, but only the button is clickable, so a
|
|
96
|
+
// move over the offer text clears hover like leaving the row would.
|
|
97
|
+
const next = onButton(event);
|
|
98
|
+
if (next === hovered) return { handled: true };
|
|
99
|
+
hovered = next;
|
|
100
|
+
return { handled: true, render: true };
|
|
101
|
+
},
|
|
102
|
+
onLeave() {
|
|
103
|
+
if (!hovered) return;
|
|
104
|
+
hovered = false;
|
|
105
|
+
tui.requestRender();
|
|
106
|
+
},
|
|
107
|
+
onClick(event) {
|
|
108
|
+
if (event.button !== "left" || !onButton(event)) return undefined;
|
|
109
|
+
onStar();
|
|
110
|
+
return { handled: true, render: true };
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
render: (width) => region.render(width),
|
|
115
|
+
invalidate: () => region.invalidate(),
|
|
116
|
+
handleMouse: (event) => region.handleMouse(event),
|
|
117
|
+
dispose: () => region.dispose(),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function defaultSchedule(ms: number, fn: () => void): Timer {
|
|
122
|
+
const id = setTimeout(fn, ms);
|
|
123
|
+
return { cancel: () => clearTimeout(id) };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Non-blocking GitHub star offer, cloned from t3code's GitHubStarPrompt courtesies:
|
|
127
|
+
* asks only engaged users (after 5 sent prompts), only while idle with no agent
|
|
128
|
+
* running, at most once per session, and never again after any dismissal — and
|
|
129
|
+
* when state cannot be persisted it never asks at all. The star chord (or the
|
|
130
|
+
* [star] button) stars through the authenticated gh account after that explicit
|
|
131
|
+
* action, and opens the repository URLs only when gh cannot star. */
|
|
132
|
+
export function createStarPromptExtension(pi: ExtensionAPI, deps: StarPromptDeps = {}): void {
|
|
133
|
+
const configHome = deps.configHome ?? gentlePiConfigHome();
|
|
134
|
+
const schedule = deps.schedule ?? defaultSchedule;
|
|
135
|
+
const now = deps.now ?? (() => Date.now());
|
|
136
|
+
const runGhStarred = deps.ghStarred ?? (() => ghStarred());
|
|
137
|
+
const runGhStar = deps.ghStar ?? (() => ghStar());
|
|
138
|
+
const openRepository = deps.openRepository ?? ((url: string) => openRepositoryInBrowser(url));
|
|
139
|
+
|
|
140
|
+
let runtime: SessionRuntime | undefined;
|
|
141
|
+
let unsubscribeInput: Unsubscribe | undefined;
|
|
142
|
+
let idleTimer: Timer | undefined;
|
|
143
|
+
let visibleTimer: Timer | undefined;
|
|
144
|
+
|
|
145
|
+
const readCurrent = (): SessionRuntime => {
|
|
146
|
+
if (runtime) return runtime;
|
|
147
|
+
const read = deps.readState ? deps.readState(configHome) : readStarPromptState(configHome);
|
|
148
|
+
runtime = {
|
|
149
|
+
state: read.state,
|
|
150
|
+
unusable: read.unusable,
|
|
151
|
+
offeredThisSession: false,
|
|
152
|
+
agentRunning: false,
|
|
153
|
+
visible: false,
|
|
154
|
+
waitingIdle: false,
|
|
155
|
+
lastInputAt: now(),
|
|
156
|
+
};
|
|
157
|
+
return runtime;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const clearTimers = () => {
|
|
161
|
+
if (idleTimer) {
|
|
162
|
+
idleTimer.cancel();
|
|
163
|
+
idleTimer = undefined;
|
|
164
|
+
}
|
|
165
|
+
if (visibleTimer) {
|
|
166
|
+
visibleTimer.cancel();
|
|
167
|
+
visibleTimer = undefined;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const hide = (ctx: ExtensionContext) => {
|
|
172
|
+
clearTimers();
|
|
173
|
+
if (runtime) runtime.visible = false;
|
|
174
|
+
ctx.ui.setWidget(STATUS_KEY, undefined);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const persist = (ctx: ExtensionContext, next: StarPromptState): boolean => {
|
|
178
|
+
try {
|
|
179
|
+
if (deps.writeState) deps.writeState(configHome, next);
|
|
180
|
+
else writeStarPromptState(configHome, next);
|
|
181
|
+
} catch {
|
|
182
|
+
// A dismissal that cannot be saved must disable asking (t3code courtesy).
|
|
183
|
+
if (runtime) runtime.unusable = true;
|
|
184
|
+
hide(ctx);
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (runtime) runtime.state = next;
|
|
188
|
+
return true;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const finishSession = () => {
|
|
192
|
+
clearTimers();
|
|
193
|
+
if (unsubscribeInput) {
|
|
194
|
+
unsubscribeInput();
|
|
195
|
+
unsubscribeInput = undefined;
|
|
196
|
+
}
|
|
197
|
+
runtime = undefined;
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const starNow = async (ctx: ExtensionContext) => {
|
|
201
|
+
const current = readCurrent();
|
|
202
|
+
hide(ctx);
|
|
203
|
+
current.offeredThisSession = true;
|
|
204
|
+
if (await runGhStar() === "yes") {
|
|
205
|
+
persist(ctx, { ...current.state, dismissed: true });
|
|
206
|
+
ctx.ui.notify("Thanks for the stars! They really help both repos grow.", "info");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
// Unknown or failed gh: fall through to the browser so the chord never dead-ends.
|
|
210
|
+
const results = await Promise.all(STAR_PROMPT_REPOSITORY_URLS.map((url) => openRepository(url)));
|
|
211
|
+
if (results.every((result) => result.opened)) persist(ctx, { ...current.state, dismissed: true });
|
|
212
|
+
else ctx.ui.notify(`Could not open the browser (${results.find((r) => !r.opened)?.error ?? "unknown error"}). Star us at ${STAR_PROMPT_REPOSITORY_URLS.join(" and ")}`, "info");
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const dismissForever = (ctx: ExtensionContext) => {
|
|
216
|
+
const current = readCurrent();
|
|
217
|
+
current.offeredThisSession = true;
|
|
218
|
+
hide(ctx);
|
|
219
|
+
persist(ctx, { ...current.state, dismissed: true });
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const handleTerminalInput = (ctx: ExtensionContext) => (data: string): { consume?: boolean; data?: string } | undefined => {
|
|
223
|
+
const current = readCurrent();
|
|
224
|
+
current.lastInputAt = now();
|
|
225
|
+
if (current.visible) {
|
|
226
|
+
if (matchesStarPromptChord(data, STAR_CHORD)) {
|
|
227
|
+
void starNow(ctx);
|
|
228
|
+
return { consume: true };
|
|
229
|
+
}
|
|
230
|
+
if (matchesStarPromptChord(data, DISMISS_CHORD)) {
|
|
231
|
+
dismissForever(ctx);
|
|
232
|
+
return { consume: true };
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Activity alone restarts the idle wait; typing is never consumed.
|
|
236
|
+
if (!current.visible && idleTimer) armIdle(ctx, current);
|
|
237
|
+
return undefined;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const offer = (ctx: ExtensionContext) => {
|
|
241
|
+
const current = readCurrent();
|
|
242
|
+
if (!shouldOfferStarPrompt({
|
|
243
|
+
sent: current.state.sent,
|
|
244
|
+
dismissed: current.state.dismissed,
|
|
245
|
+
unusable: current.unusable,
|
|
246
|
+
offeredThisSession: current.offeredThisSession,
|
|
247
|
+
agentRunning: current.agentRunning,
|
|
248
|
+
})) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (current.waitingIdle) return;
|
|
252
|
+
current.waitingIdle = true;
|
|
253
|
+
current.lastInputAt = now();
|
|
254
|
+
if (!unsubscribeInput) unsubscribeInput = ctx.ui.onTerminalInput(handleTerminalInput(ctx));
|
|
255
|
+
void runGhStarred().then((starred) => {
|
|
256
|
+
if (runtime !== current) return;
|
|
257
|
+
current.waitingIdle = false;
|
|
258
|
+
if (starred === "yes") {
|
|
259
|
+
current.offeredThisSession = true;
|
|
260
|
+
persist(ctx, { ...current.state, dismissed: true });
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (starred === "unknown") {
|
|
264
|
+
current.offeredThisSession = true;
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
// A pending idle wait (or a visible offer) already covers this session.
|
|
268
|
+
if (idleTimer || current.visible) return;
|
|
269
|
+
armIdle(ctx, current);
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/** One idle wait: when it fires still idle and uncontended, the footer shows the offer. */
|
|
274
|
+
const armIdle = (ctx: ExtensionContext, current: SessionRuntime) => {
|
|
275
|
+
if (idleTimer) idleTimer.cancel();
|
|
276
|
+
idleTimer = schedule(STAR_PROMPT_IDLE_MS, () => {
|
|
277
|
+
idleTimer = undefined;
|
|
278
|
+
if (runtime !== current || current.agentRunning || current.visible || current.waitingIdle) return;
|
|
279
|
+
if (now() - current.lastInputAt < STAR_PROMPT_IDLE_MS) {
|
|
280
|
+
// A near-simultaneous keystroke won the race: wait out the new idle window.
|
|
281
|
+
armIdle(ctx, current);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
current.visible = true;
|
|
285
|
+
// The success green of added lines in the changes view, so the offer stands out.
|
|
286
|
+
ctx.ui.setWidget(STATUS_KEY, (tui, theme) => offerRow(theme, tui, () => void starNow(ctx)), { placement: "belowEditor" });
|
|
287
|
+
visibleTimer = schedule(STAR_PROMPT_VISIBLE_MS, () => {
|
|
288
|
+
if (runtime !== current) return;
|
|
289
|
+
current.visible = false;
|
|
290
|
+
current.offeredThisSession = true;
|
|
291
|
+
ctx.ui.setWidget(STATUS_KEY, undefined);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
pi.on("session_start", () => {
|
|
297
|
+
finishSession();
|
|
298
|
+
if (deps.headless) return;
|
|
299
|
+
readCurrent();
|
|
300
|
+
});
|
|
301
|
+
pi.on("session_shutdown", () => {
|
|
302
|
+
finishSession();
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
pi.on("input", (event) => {
|
|
306
|
+
if (event.source !== "interactive" && event.source !== "rpc") return;
|
|
307
|
+
const current = readCurrent();
|
|
308
|
+
current.state = { ...current.state, sent: current.state.sent + 1 };
|
|
309
|
+
current.lastInputAt = now();
|
|
310
|
+
try {
|
|
311
|
+
if (deps.writeState) deps.writeState(configHome, current.state);
|
|
312
|
+
else writeStarPromptState(configHome, current.state);
|
|
313
|
+
} catch {
|
|
314
|
+
// A counter that cannot persist means no future dismissal can either.
|
|
315
|
+
current.unusable = true;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
pi.on("agent_start", () => {
|
|
320
|
+
readCurrent().agentRunning = true;
|
|
321
|
+
});
|
|
322
|
+
pi.on("agent_end", (_event, ctx) => {
|
|
323
|
+
const current = readCurrent();
|
|
324
|
+
current.agentRunning = false;
|
|
325
|
+
offer(ctx);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export const STAR_PROMPT_THRESHOLD = PROMPTS_BEFORE_ASKING;
|
|
330
|
+
export const STAR_PROMPT_DEFAULTS = DEFAULT_STAR_PROMPT_STATE;
|
|
331
|
+
|
|
332
|
+
export default function gentleStarPrompt(pi: ExtensionAPI): void {
|
|
333
|
+
createStarPromptExtension(pi);
|
|
334
|
+
}
|
|
@@ -6,6 +6,7 @@ import { createNativeFullscreenInteraction } from "../lib/native-fullscreen-inte
|
|
|
6
6
|
import { withOverlayRepaint } from "../lib/overlay-repaint.ts";
|
|
7
7
|
import { createStatsLoader, currentSessionStats, type StatsLoader } from "../lib/stats-collector.ts";
|
|
8
8
|
import { StatsView } from "../lib/stats-view.ts";
|
|
9
|
+
import { effectiveKey, loadKeymaps, type KeymapBindings } from "../lib/keymaps.ts";
|
|
9
10
|
|
|
10
11
|
// Gentle Stats: /gentle:stats opens a full-terminal panel over local Pi
|
|
11
12
|
// session history (tokens, cost, models, activity). It only reads the
|
|
@@ -19,10 +20,9 @@ import { StatsView } from "../lib/stats-view.ts";
|
|
|
19
20
|
|
|
20
21
|
export const STATS_COMMAND_NAME = "gentle:stats";
|
|
21
22
|
|
|
22
|
-
/** Optional shortcut; there is no default key because the common alt+ keys are taken. */
|
|
23
|
-
export function statsViewKey(env: NodeJS.ProcessEnv = process.env): string | undefined {
|
|
24
|
-
|
|
25
|
-
return !value || value.toLowerCase() === "off" ? undefined : value;
|
|
23
|
+
/** Optional shortcut; there is no default key because the common alt+ keys are taken. A key saved in keymaps.json applies when the variable is unset. */
|
|
24
|
+
export function statsViewKey(env: NodeJS.ProcessEnv = process.env, bindings: KeymapBindings = {}): string | undefined {
|
|
25
|
+
return effectiveKey("stats.view", env, bindings);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/** The sessions roots /gentle:stats reads: the active home and the user's original Pi home. */
|
|
@@ -87,7 +87,7 @@ export default function gentleStats(pi: ExtensionAPI, deps: GentleStatsDeps = {}
|
|
|
87
87
|
description: "Show local Pi usage stats: activity heatmap, tokens, cost, models, and this session. r cycles the range, s the project scope.",
|
|
88
88
|
handler: async (_args, ctx) => openOverlay(ctx),
|
|
89
89
|
});
|
|
90
|
-
const viewKey = statsViewKey(env);
|
|
90
|
+
const viewKey = statsViewKey(env, loadKeymaps(env).bindings);
|
|
91
91
|
if (viewKey) {
|
|
92
92
|
pi.registerShortcut(viewKey as Parameters<ExtensionAPI["registerShortcut"]>[0], {
|
|
93
93
|
description: "Show local Pi usage stats",
|
|
@@ -3,12 +3,17 @@ import { ScrollView, Text, truncateToWidth, type Component, type TUI } from "@ea
|
|
|
3
3
|
import { appendSystemPromptOnce } from "../lib/append-system-prompt.ts";
|
|
4
4
|
import { NativePointerRegion } from "../lib/native-pointer-region.ts";
|
|
5
5
|
import { panelHeaderRow } from "../lib/shell-card.ts";
|
|
6
|
+
import { renderPanelRow } from "../lib/shell-panel.ts";
|
|
6
7
|
import { sidebarPart, sidebarState } from "../lib/shell-sidebar.ts";
|
|
7
8
|
import { invalidateSidebar } from "../lib/shell-sidebar-layout.ts";
|
|
9
|
+
import { loadKeymaps } from "../lib/keymaps.ts";
|
|
8
10
|
import {
|
|
9
11
|
applyTodo,
|
|
10
12
|
emptyTodo,
|
|
11
13
|
renderTodoCard,
|
|
14
|
+
renderTodoSection,
|
|
15
|
+
todoCollapseKey,
|
|
16
|
+
todoWorkSummary,
|
|
12
17
|
replayTodo,
|
|
13
18
|
staleTurns,
|
|
14
19
|
TODO_DETAILS_KEY,
|
|
@@ -38,7 +43,6 @@ import {
|
|
|
38
43
|
|
|
39
44
|
const WIDGET_KEY = "gentle-todo";
|
|
40
45
|
const STATUS_ENUM = ["pending", "in_progress", "blocked", "done", "dropped"];
|
|
41
|
-
const COLLAPSE_KEY_DEFAULT = "ctrl+shift+t";
|
|
42
46
|
const REMIND_AFTER_TOOL_TURNS = 4;
|
|
43
47
|
const TODO_REMINDER = "The todo plan has not been reviewed during several tool-use turns. Check whether it still matches the work performed and update tasks where needed. Do not mark work done without verification.";
|
|
44
48
|
const TOOL_PARAMETERS = {
|
|
@@ -75,11 +79,8 @@ export function todoEnabled(env: NodeJS.ProcessEnv = process.env): boolean {
|
|
|
75
79
|
return !(value === "0" || value === "false" || value === "off");
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (value === undefined) return COLLAPSE_KEY_DEFAULT;
|
|
81
|
-
return value === "" || value.toLowerCase() === "off" ? undefined : value;
|
|
82
|
-
}
|
|
82
|
+
// The collapse key moved to lib/shell-todo.ts so the rail's key hints can read it.
|
|
83
|
+
export { todoCollapseKey } from "../lib/shell-todo.ts";
|
|
83
84
|
|
|
84
85
|
interface TodoSession {
|
|
85
86
|
state: TodoState;
|
|
@@ -109,7 +110,7 @@ function sessionKey(ctx: ExtensionContext): string {
|
|
|
109
110
|
export default function gentleTodo(pi: ExtensionAPI, env: NodeJS.ProcessEnv = process.env): void {
|
|
110
111
|
if (!todoEnabled(env)) return;
|
|
111
112
|
const sessions = new Map<string, TodoSession>();
|
|
112
|
-
const collapseKey = todoCollapseKey(env);
|
|
113
|
+
const collapseKey = todoCollapseKey(env, loadKeymaps(env).bindings);
|
|
113
114
|
|
|
114
115
|
const session = (ctx: ExtensionContext): TodoSession => {
|
|
115
116
|
const key = sessionKey(ctx);
|
|
@@ -136,7 +137,7 @@ export default function gentleTodo(pi: ExtensionAPI, env: NodeJS.ProcessEnv = pr
|
|
|
136
137
|
current.host?.requestRender();
|
|
137
138
|
};
|
|
138
139
|
|
|
139
|
-
const todoCard = (current: TodoSession, theme: Parameters<typeof renderTodoCard>[1], spacer: boolean): Component & { dispose(): void; digest(): string; scrollBy(lines: number): void } => {
|
|
140
|
+
const todoCard = (current: TodoSession, theme: Parameters<typeof renderTodoCard>[1], spacer: boolean): Component & { dispose(): void; digest(): string; scrollBy(lines: number): void; surface?: "panel"; summary?(): ReturnType<typeof todoWorkSummary> } => {
|
|
140
141
|
let hovered = false;
|
|
141
142
|
let body: string[] = [];
|
|
142
143
|
let collapsed = current.collapsed;
|
|
@@ -156,14 +157,30 @@ export default function gentleTodo(pi: ExtensionAPI, env: NodeJS.ProcessEnv = pr
|
|
|
156
157
|
const card: Component = {
|
|
157
158
|
render(width: number) {
|
|
158
159
|
const stale = staleTurns(current.state, current.turn);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
// The fullscreen rail draws a panel section (header row, task rows, no
|
|
161
|
+
// closing rule); the bottom widget keeps the card with its chrome.
|
|
162
|
+
let head: string[];
|
|
163
|
+
let foot: string[];
|
|
164
|
+
if (spacer) {
|
|
165
|
+
headerRow = panelHeaderRow(theme, width, todoCardTone(stale));
|
|
166
|
+
const lines = renderTodoCard(current.state, theme, width, {
|
|
167
|
+
collapsed: current.collapsed,
|
|
168
|
+
staleTurns: stale,
|
|
169
|
+
collapseKey,
|
|
170
|
+
hovered,
|
|
171
|
+
scrollable: true,
|
|
172
|
+
});
|
|
173
|
+
const bodyStart = headerRow === 1 ? 3 : 1;
|
|
174
|
+
head = lines.slice(0, bodyStart);
|
|
175
|
+
body = lines.slice(bodyStart, -1);
|
|
176
|
+
foot = lines.slice(-1);
|
|
177
|
+
} else {
|
|
178
|
+
headerRow = 0;
|
|
179
|
+
const section = renderTodoSection(current.state, theme, width, { collapsed: current.collapsed, staleTurns: stale, hovered });
|
|
180
|
+
head = section.header ? [section.header] : [];
|
|
181
|
+
body = section.body;
|
|
182
|
+
foot = [];
|
|
183
|
+
}
|
|
167
184
|
if (collapsed !== current.collapsed) {
|
|
168
185
|
collapsed = current.collapsed;
|
|
169
186
|
scroll.scrollToStart();
|
|
@@ -172,14 +189,16 @@ export default function gentleTodo(pi: ExtensionAPI, env: NodeJS.ProcessEnv = pr
|
|
|
172
189
|
// on every render so a mobile resize immediately releases chat space.
|
|
173
190
|
const terminalRows = current.tui?.terminal?.rows ?? 48;
|
|
174
191
|
const height = Math.min(16, Math.floor(terminalRows / 3));
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
const room = Math.max(1, height - bodyStart - 1 - Number(spacer) - Number(overflow));
|
|
192
|
+
if (head.length === 0) return [];
|
|
193
|
+
const overflow = !current.collapsed && head.length + body.length + foot.length + Number(spacer) > height;
|
|
194
|
+
const room = Math.max(1, height - head.length - foot.length - Number(spacer) - Number(overflow));
|
|
179
195
|
scroll.updateLayout(body.length, current.collapsed ? body.length : room, () => current.host?.requestRender());
|
|
180
196
|
const visible = scroll.render(width).slice(scroll.scrollTop, scroll.scrollTop + scroll.viewportHeight);
|
|
181
|
-
const output = [...
|
|
182
|
-
if (overflow)
|
|
197
|
+
const output = [...head, ...visible, ...foot];
|
|
198
|
+
if (overflow) {
|
|
199
|
+
const position = `↑↓ ${scroll.scrollTop + 1}–${scroll.scrollTop + visible.length}/${body.length} · alt+shift+↑/↓`;
|
|
200
|
+
output.push(spacer ? theme.fg("muted", truncateToWidth(position, width)) : renderPanelRow(width, theme.fg("muted", position)));
|
|
201
|
+
}
|
|
183
202
|
return spacer && output.length > 0 ? [...output, ""] : output;
|
|
184
203
|
},
|
|
185
204
|
invalidate() {
|
|
@@ -216,6 +235,7 @@ export default function gentleTodo(pi: ExtensionAPI, env: NodeJS.ProcessEnv = pr
|
|
|
216
235
|
scrollBy,
|
|
217
236
|
// Sidebar caches must observe height-only resizes and local viewport
|
|
218
237
|
// changes, even when terminal width and task content stay the same.
|
|
238
|
+
...(spacer ? {} : { surface: "panel" as const, summary: () => todoWorkSummary(current.state, theme) }),
|
|
219
239
|
digest: () => JSON.stringify([current.tui?.terminal?.rows, current.collapsed, current.turn, hovered, scroll.scrollTop]),
|
|
220
240
|
render: (width) => region.render(width),
|
|
221
241
|
handleMouse: (event) => region.handleMouse(event),
|
|
@@ -23,6 +23,12 @@ import {
|
|
|
23
23
|
type ExtractedPrompt,
|
|
24
24
|
} from "./session-scan.ts";
|
|
25
25
|
|
|
26
|
+
// Prompts can carry anything pasted into the composer, so the store keeps its
|
|
27
|
+
// files private and the directories it creates owner-only, like the package's
|
|
28
|
+
// other state files. Modes apply on creation; rewrites recreate the file.
|
|
29
|
+
const PRIVATE_DIR = 0o700;
|
|
30
|
+
const PRIVATE_FILE = { encoding: "utf8", mode: 0o600 } as const;
|
|
31
|
+
|
|
26
32
|
// ===========================================================================
|
|
27
33
|
// Paths (formerly store-paths.ts)
|
|
28
34
|
// ===========================================================================
|
|
@@ -107,8 +113,8 @@ function readRegistry(root: string): RegistryData {
|
|
|
107
113
|
function writeRegistryAtomic(root: string, data: RegistryData): void {
|
|
108
114
|
const target = registryPath(root);
|
|
109
115
|
const tmp = `${target}.tmp-${process.pid}-${Date.now()}`;
|
|
110
|
-
fs.mkdirSync(root, { recursive: true });
|
|
111
|
-
fs.writeFileSync(tmp, JSON.stringify(data, null, 2) + "\n",
|
|
116
|
+
fs.mkdirSync(root, { recursive: true, mode: PRIVATE_DIR });
|
|
117
|
+
fs.writeFileSync(tmp, JSON.stringify(data, null, 2) + "\n", PRIVATE_FILE);
|
|
112
118
|
fs.renameSync(tmp, target);
|
|
113
119
|
}
|
|
114
120
|
|
|
@@ -250,8 +256,8 @@ export function appendSessionCapture(
|
|
|
250
256
|
|
|
251
257
|
const entry: StoreEntry = { v: 1, text };
|
|
252
258
|
if (ts !== undefined) entry.ts = ts;
|
|
253
|
-
fs.mkdirSync(path.dirname(state.filePath), { recursive: true });
|
|
254
|
-
fs.appendFileSync(state.filePath, serializeEntry(entry) + "\n",
|
|
259
|
+
fs.mkdirSync(path.dirname(state.filePath), { recursive: true, mode: PRIVATE_DIR });
|
|
260
|
+
fs.appendFileSync(state.filePath, serializeEntry(entry) + "\n", PRIVATE_FILE);
|
|
255
261
|
state.lineCount += 1;
|
|
256
262
|
}
|
|
257
263
|
|
|
@@ -524,7 +530,7 @@ function sweepFile(file: string, key: string): number {
|
|
|
524
530
|
}
|
|
525
531
|
if (removed === 0) return 0;
|
|
526
532
|
tmp = `${file}.tmp-${process.pid}-${Date.now()}`;
|
|
527
|
-
fs.writeFileSync(tmp, kept.length > 0 ? kept.join("\n") + "\n" : "",
|
|
533
|
+
fs.writeFileSync(tmp, kept.length > 0 ? kept.join("\n") + "\n" : "", PRIVATE_FILE);
|
|
528
534
|
fs.renameSync(tmp, file);
|
|
529
535
|
tmp = null;
|
|
530
536
|
// Lines another instance appended to the replaced inode since the read.
|
|
@@ -556,14 +562,14 @@ function sweepFile(file: string, key: string): number {
|
|
|
556
562
|
*/
|
|
557
563
|
function carryIntoRewrite(file: string, carried: Buffer): void {
|
|
558
564
|
try {
|
|
559
|
-
fs.appendFileSync(file, carried);
|
|
565
|
+
fs.appendFileSync(file, carried, { mode: 0o600 });
|
|
560
566
|
} catch {
|
|
561
567
|
trimTornTail(file);
|
|
562
568
|
const text = carried.toString("utf8");
|
|
563
569
|
fs.writeFileSync(
|
|
564
570
|
`${file}.carry-${process.pid}-${Date.now()}.jsonl`,
|
|
565
571
|
text.endsWith("\n") ? text : `${text}\n`,
|
|
566
|
-
{ flag: "wx" },
|
|
572
|
+
{ flag: "wx", mode: 0o600 },
|
|
567
573
|
);
|
|
568
574
|
}
|
|
569
575
|
}
|
|
@@ -686,10 +692,10 @@ export function migrateLegacyStores(
|
|
|
686
692
|
agentDir: string,
|
|
687
693
|
): MigrationResult {
|
|
688
694
|
const seed = globalSeedPath(root);
|
|
689
|
-
fs.mkdirSync(root, { recursive: true });
|
|
695
|
+
fs.mkdirSync(root, { recursive: true, mode: PRIVATE_DIR });
|
|
690
696
|
const lock = `${seed}.migration-lock`;
|
|
691
697
|
try {
|
|
692
|
-
fs.mkdirSync(lock);
|
|
698
|
+
fs.mkdirSync(lock, { mode: PRIVATE_DIR });
|
|
693
699
|
} catch (error) {
|
|
694
700
|
if ((error as NodeJS.ErrnoException).code === "EEXIST") {
|
|
695
701
|
return { migrated: 0, ran: false };
|
|
@@ -748,7 +754,7 @@ function migrateLegacyStoresLocked(seed: string, agentDir: string): MigrationRes
|
|
|
748
754
|
fs.writeFileSync(
|
|
749
755
|
tmp,
|
|
750
756
|
[...existing, ...collected].map((e) => JSON.stringify(e)).join("\n") + "\n",
|
|
751
|
-
|
|
757
|
+
PRIVATE_FILE,
|
|
752
758
|
);
|
|
753
759
|
fs.renameSync(tmp, seed);
|
|
754
760
|
|
|
@@ -861,12 +867,12 @@ export function bootstrapProjectSeed(
|
|
|
861
867
|
|
|
862
868
|
collected.reverse(); // chronological (oldest first)
|
|
863
869
|
const seed = seedFilePath(root, cwd);
|
|
864
|
-
fs.mkdirSync(path.dirname(seed), { recursive: true });
|
|
870
|
+
fs.mkdirSync(path.dirname(seed), { recursive: true, mode: PRIVATE_DIR });
|
|
865
871
|
const tmp = `${seed}.tmp-${process.pid}-${Date.now()}`;
|
|
866
872
|
fs.writeFileSync(
|
|
867
873
|
tmp,
|
|
868
874
|
collected.map((e) => JSON.stringify(e)).join("\n") + "\n",
|
|
869
|
-
|
|
875
|
+
PRIVATE_FILE,
|
|
870
876
|
);
|
|
871
877
|
fs.renameSync(tmp, seed);
|
|
872
878
|
return { seeded: collected.length, ran: true };
|
|
@@ -103,6 +103,15 @@ function projectSkillDirs(cwd: string): string[] {
|
|
|
103
103
|
];
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
// gentle-shell#373: only storage-capacity/permission faults degrade the
|
|
107
|
+
// registry to a typed unavailable result. Anything else (ELOOP, ENOSPC, a
|
|
108
|
+
// failing device) keeps its own diagnostic through the ordinary error path.
|
|
109
|
+
function isStorageUnavailableError(error: unknown): boolean {
|
|
110
|
+
if (typeof error !== "object" || error === null || !("code" in error)) return false;
|
|
111
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
112
|
+
return code === "EACCES" || code === "EPERM" || code === "EROFS" || code === "ENOTDIR" || code === "EISDIR" || code === "EEXIST";
|
|
113
|
+
}
|
|
114
|
+
|
|
106
115
|
function isMissingSkillFileError(error: unknown): boolean {
|
|
107
116
|
if (typeof error !== "object" || error === null || !("code" in error)) return false;
|
|
108
117
|
return error.code === "ENOENT" || error.code === "ENOTDIR";
|
|
@@ -525,9 +534,27 @@ async function regenerateRegistry(
|
|
|
525
534
|
return rel.startsWith("..") ? d : rel || ".";
|
|
526
535
|
});
|
|
527
536
|
const md = renderRegistry(cwd, sources, deduped);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
537
|
+
try {
|
|
538
|
+
await mkdir(join(cwd, ".atl"), { recursive: true });
|
|
539
|
+
await writeFile(registryPath, md);
|
|
540
|
+
await writeFile(cachePath, JSON.stringify({ fingerprint: fp }, null, 2));
|
|
541
|
+
} catch (error) {
|
|
542
|
+
if (isStorageUnavailableError(error)) {
|
|
543
|
+
// gentle-shell#373: an unwritable storage location must never
|
|
544
|
+
// report a successful regeneration. The typed result names the
|
|
545
|
+
// offending path and the safe next action; unexpected I/O keeps
|
|
546
|
+
// its own diagnostic by rethrowing.
|
|
547
|
+
const path = typeof (error as NodeJS.ErrnoException).path === "string" ? (error as NodeJS.ErrnoException).path as string : registryPath;
|
|
548
|
+
const relativePath = relative(cwd, path).split(sep).join("/") || REGISTRY_REL_PATH;
|
|
549
|
+
return {
|
|
550
|
+
regenerated: false,
|
|
551
|
+
skillCount: 0,
|
|
552
|
+
reason: "storage-unavailable",
|
|
553
|
+
warning: `Skill registry is unavailable: ${relativePath} is not writable (${(error as NodeJS.ErrnoException).code}). Restore write access, then run /skill-registry:refresh.`,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
throw error;
|
|
557
|
+
}
|
|
531
558
|
return {
|
|
532
559
|
regenerated: true,
|
|
533
560
|
skillCount: deduped.length,
|
|
@@ -681,6 +708,7 @@ export const __testing = {
|
|
|
681
708
|
userSkillDirs,
|
|
682
709
|
findSkillFiles,
|
|
683
710
|
isMissingSkillFileError,
|
|
711
|
+
isStorageUnavailableError,
|
|
684
712
|
uniqueExistingDirs,
|
|
685
713
|
dedupeBySkillName,
|
|
686
714
|
scopeForPath,
|
|
@@ -796,6 +824,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
796
824
|
try {
|
|
797
825
|
await ensureAtlIgnored(ctx.cwd, true);
|
|
798
826
|
const result = await regenerateRegistry(ctx.cwd, true, true);
|
|
827
|
+
if (result.reason === "storage-unavailable") {
|
|
828
|
+
ctx.ui.notify(result.warning ?? "Skill registry is unavailable.", "warning");
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
799
831
|
ctx.ui.notify(
|
|
800
832
|
`Skill registry: ${result.skillCount} skill(s) written to ${REGISTRY_REL_PATH}`,
|
|
801
833
|
"info",
|