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
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { execFileSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import { Worker } from "node:worker_threads";
|
|
8
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { DESKTOP_CHANGES_SERVICE_CHANNEL, type DesktopChangesService } from "../lib/desktop-rpc-changes.ts";
|
|
10
|
+
|
|
11
|
+
function install(shell: typeof import("../extensions/gentle-shell.ts").default, root: string, config: string, id: string) {
|
|
12
|
+
const handlers = new Map<string, Array<(event: unknown, ctx: ExtensionContext) => unknown>>();
|
|
13
|
+
const listeners = new Map<string, (event: unknown) => void>();
|
|
14
|
+
const entries: unknown[] = [];
|
|
15
|
+
const pi = {
|
|
16
|
+
on: (key: string, handler: (event: unknown, ctx: ExtensionContext) => unknown) => handlers.set(key, [...(handlers.get(key) ?? []), handler]),
|
|
17
|
+
events: { on: (key: string, listener: (event: unknown) => void) => { listeners.set(key, listener); return () => undefined; }, emit() {} },
|
|
18
|
+
appendEntry: (customType: string, data: unknown) => entries.push({ type: "custom", customType, data }),
|
|
19
|
+
registerCommand() {}, registerTool() {}, registerShortcut() {}, registerMessageRenderer() {},
|
|
20
|
+
} as unknown as ExtensionAPI;
|
|
21
|
+
shell(pi, { GENTLE_PI_CONFIG_HOME: config }, {
|
|
22
|
+
devBinary: () => undefined,
|
|
23
|
+
resolveWorktree: () => ({ root, commonDir: join(root, ".git") }),
|
|
24
|
+
});
|
|
25
|
+
const ctx = {
|
|
26
|
+
mode: "rpc", hasUI: true, cwd: root,
|
|
27
|
+
sessionManager: { getSessionId: () => id, getEntries: () => entries },
|
|
28
|
+
ui: { setFooter() {}, getEditorComponent: () => ({}), setWorkingVisible() {}, setWidget() {}, notify() {} },
|
|
29
|
+
} as unknown as ExtensionContext;
|
|
30
|
+
return {
|
|
31
|
+
async fire(event: string) { for (const handle of handlers.get(event) ?? []) await handle({}, ctx); },
|
|
32
|
+
read() {
|
|
33
|
+
let adapter: DesktopChangesService | undefined;
|
|
34
|
+
listeners.get(DESKTOP_CHANGES_SERVICE_CHANNEL)!({ context: ctx, respond: (service: DesktopChangesService) => { adapter = service; } });
|
|
35
|
+
assert.ok(adapter, "the active session exposes the public Changes service");
|
|
36
|
+
return adapter.read();
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
test("Git workers drain on shutdown, do not accumulate on reload, and restart lazily", { skip: process.platform === "win32", timeout: 15_000 }, async (t) => {
|
|
42
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "gentle-worker-reload-")));
|
|
43
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
44
|
+
const config = join(root, ".test-config");
|
|
45
|
+
mkdirSync(config);
|
|
46
|
+
const git = (...args: string[]) => execFileSync("git", ["-C", root, "-c", "user.name=test", "-c", "user.email=test@example.com", "-c", "commit.gpgsign=false", ...args]);
|
|
47
|
+
git("init", "-q", "--initial-branch=main");
|
|
48
|
+
git("commit", "-q", "--allow-empty", "-m", "base");
|
|
49
|
+
writeFileSync(join(root, "new.txt"), "hello\n");
|
|
50
|
+
|
|
51
|
+
const workers = new Set<Worker>();
|
|
52
|
+
let onPost: (() => void) | undefined;
|
|
53
|
+
const post = Worker.prototype.postMessage;
|
|
54
|
+
t.mock.method(Worker.prototype, "postMessage", function (this: Worker, ...args: Parameters<Worker["postMessage"]>) {
|
|
55
|
+
workers.add(this);
|
|
56
|
+
post.apply(this, args);
|
|
57
|
+
onPost?.();
|
|
58
|
+
});
|
|
59
|
+
// Count actual Node worker handles used by the production Git runner. Node
|
|
60
|
+
// resets threadId to -1 on exit, including for a worker that was unref'd.
|
|
61
|
+
const live = () => [...workers].filter((worker) => worker.threadId !== -1).length;
|
|
62
|
+
t.after(async () => { await Promise.all([...workers].filter((worker) => worker.threadId !== -1).map((worker) => worker.terminate())); });
|
|
63
|
+
const shutdownCounts: number[] = [];
|
|
64
|
+
for (let cycle = 0; cycle < 3; cycle++) {
|
|
65
|
+
const { default: shell } = await import(`../extensions/gentle-shell.ts?git-worker-reload=${cycle}`) as typeof import("../extensions/gentle-shell.ts");
|
|
66
|
+
const app = install(shell, root, config, `session-${cycle}`);
|
|
67
|
+
const previous = workers.size;
|
|
68
|
+
await app.fire("session_start");
|
|
69
|
+
assert.equal(workers.size, previous, "startup is lazy");
|
|
70
|
+
assert.equal((await app.read())?.files.find((file) => file.path === "new.txt")?.added, 1);
|
|
71
|
+
assert.equal(workers.size, previous + 1, "the real runner started one worker");
|
|
72
|
+
await app.fire("session_shutdown");
|
|
73
|
+
shutdownCounts.push(live());
|
|
74
|
+
|
|
75
|
+
if (cycle === 2) {
|
|
76
|
+
// Restart on the same factory, and take shutdown between posting a worktree
|
|
77
|
+
// request and delivering its reply. The old scan must not start a new worker.
|
|
78
|
+
await app.fire("session_start");
|
|
79
|
+
assert.equal((await app.read())?.files.find((file) => file.path === "new.txt")?.added, 1);
|
|
80
|
+
const pending = Promise.withResolvers<void>();
|
|
81
|
+
onPost = pending.resolve;
|
|
82
|
+
const reading = app.read();
|
|
83
|
+
await pending.promise;
|
|
84
|
+
onPost = undefined;
|
|
85
|
+
await app.fire("session_shutdown");
|
|
86
|
+
assert.equal(await reading, undefined, "the in-flight read settled for the closed session");
|
|
87
|
+
shutdownCounts.push(live());
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
assert.deepEqual(shutdownCounts, [0, 0, 0, 0], "no worker survived its session or accumulated across reloads");
|
|
91
|
+
});
|
|
@@ -1,13 +1,266 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test, { type TestContext } from "node:test";
|
|
6
|
+
import { stripVTControlCharacters as stripAnsi } from "node:util";
|
|
7
|
+
import { initTheme, type ExtensionAPI, type ExtensionContext, type ToolDefinition } from "@earendil-works/pi-coding-agent";
|
|
8
|
+
import { Container, setCapabilityOverrides, TuiAltScreen, type Component, type TuiMouseEvent } from "@earendil-works/pi-tui";
|
|
5
9
|
import { createChatViewport } from "../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/chat-viewport.js";
|
|
10
|
+
import { ToolExecutionComponent } from "../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.js";
|
|
6
11
|
import { buildShellBarModel, type ShellFooterData } from "../extensions/gentle-shell.ts";
|
|
7
12
|
import { createQuietToolRenderer } from "../extensions/quiet-tools.ts";
|
|
13
|
+
import gentleAgents, { AGENTS_RESULT_TYPE } from "../extensions/gentle-agents.ts";
|
|
14
|
+
import { JOB_NOTICE_TYPE } from "../lib/background-jobs-tools.ts";
|
|
15
|
+
import { CARD_CONTENT, cardContent, setCardContent } from "../lib/card-content-policy.ts";
|
|
16
|
+
import { CARD_STYLE, cardStyle, setCardStyle } from "../lib/shell-card.ts";
|
|
8
17
|
|
|
18
|
+
// Freeze the ANSI mode of the host-generated key hints in the byte checks.
|
|
19
|
+
setCapabilityOverrides({ trueColor: true });
|
|
9
20
|
initTheme("dark");
|
|
10
21
|
|
|
22
|
+
function transcriptCards(t: TestContext) {
|
|
23
|
+
const home = mkdtempSync(join(tmpdir(), "render-cards-"));
|
|
24
|
+
const previousStyle = cardStyle();
|
|
25
|
+
const previousContent = cardContent();
|
|
26
|
+
t.after(() => {
|
|
27
|
+
setCardStyle(previousStyle);
|
|
28
|
+
setCardContent(previousContent);
|
|
29
|
+
rmSync(home, { recursive: true, force: true });
|
|
30
|
+
});
|
|
31
|
+
setCardStyle(CARD_STYLE.FLOAT);
|
|
32
|
+
setCardContent(CARD_CONTENT.MINIMAL);
|
|
33
|
+
const renderers = new Map<string, Parameters<ExtensionAPI["registerMessageRenderer"]>[1]>();
|
|
34
|
+
const tools = new Map<string, ToolDefinition>();
|
|
35
|
+
gentleAgents({
|
|
36
|
+
registerMessageRenderer: (type: string, render: Parameters<ExtensionAPI["registerMessageRenderer"]>[1]) => renderers.set(type, render),
|
|
37
|
+
registerTool: (tool: ToolDefinition) => tools.set(tool.name, tool),
|
|
38
|
+
registerCommand() {}, registerShortcut() {}, registerEntryRenderer() {}, registerMarkdownTransformer() {},
|
|
39
|
+
on() {}, events: { on: () => () => {}, emit() {} },
|
|
40
|
+
} as unknown as ExtensionAPI, { GENTLE_PI_CONFIG_HOME: home }, { home });
|
|
41
|
+
const work = { agent: 0, job: 0, bash: 0, bashBody: 0, agentTool: 0 };
|
|
42
|
+
let palette = 31;
|
|
43
|
+
const theme = {
|
|
44
|
+
fg(role: string, text: string) {
|
|
45
|
+
// renderCard colors body paragraphs immediately before cardBodyRows wraps them.
|
|
46
|
+
if (role === "text" && text.startsWith("Agent paragraph")) work.agent++;
|
|
47
|
+
if (role === "text" && text.startsWith("Job paragraph")) work.job++;
|
|
48
|
+
if (role === "toolOutput" && text.startsWith("Bash result")) work.bashBody++;
|
|
49
|
+
return `\x1b[${palette}m${text}\x1b[39m`;
|
|
50
|
+
},
|
|
51
|
+
bg(role: string, text: string) {
|
|
52
|
+
// The completed agent tool enters floatRows once before it wraps its answer.
|
|
53
|
+
if (role === "toolSuccessBg") work.agentTool++;
|
|
54
|
+
return `\x1b[48;5;${role === "toolErrorBg" ? 52 : 235}m${text}\x1b[49m`;
|
|
55
|
+
},
|
|
56
|
+
// Every bash heading uses bold exactly once before cardTopRows wraps it.
|
|
57
|
+
bold(text: string) { work.bash++; return `\x1b[1m${text}\x1b[22m`; },
|
|
58
|
+
};
|
|
59
|
+
const agent = (index: number, expanded = false, status = "completed", extra = "") => renderers.get(AGENTS_RESULT_TYPE)!({
|
|
60
|
+
content: `Agent paragraph ${index}: ${"analysis and verification 広い ".repeat(15)}${extra}`,
|
|
61
|
+
details: { gentleAgents: { taskId: `task-${index}`, agent: "worker", status, model: "synthetic/test" } },
|
|
62
|
+
} as never, { expanded } as never, theme as never)!;
|
|
63
|
+
const job = (index: number, expanded = false, status = "exited", extra = "") => renderers.get(JOB_NOTICE_TYPE)!({
|
|
64
|
+
content: `Job paragraph ${index}: ${"background output record 広い ".repeat(15)}${extra}`,
|
|
65
|
+
details: { gentleJobs: { label: `job-${index}`, kind: status === "running" ? "monitor" : "bash", status, exitCode: status === "failed" ? 1 : 0, event: status === "running" ? "events" : undefined } },
|
|
66
|
+
} as never, { expanded } as never, theme as never)!;
|
|
67
|
+
const agentTool = (index: number, expanded = false, status = "completed", extra = "") => tools.get("subagent_result")!.renderResult!({
|
|
68
|
+
content: [{ type: "text", text: `Agent tool paragraph ${index}: ${"analysis and verification 広い ".repeat(15)}${extra}` }],
|
|
69
|
+
details: { gentleAgents: { taskId: `task-${index}`, agent: "worker", status, model: "synthetic/test" } },
|
|
70
|
+
}, { expanded, isPartial: false }, theme as never, { state: {}, isError: status === "failed" } as never);
|
|
71
|
+
const tool = createQuietToolRenderer("bash");
|
|
72
|
+
const bashArgs = (index: number) => ({ command: `cd /repo && printf 'command ${index} ${"long Bash argument ".repeat(14)}'\nprintf done` });
|
|
73
|
+
const bash = (index: number, expanded = false, running = false): Component => {
|
|
74
|
+
const args = bashArgs(index);
|
|
75
|
+
return tool.renderCall!(args, theme as never, { args, argsComplete: true, expanded, isPartial: running, state: {} } as never);
|
|
76
|
+
};
|
|
77
|
+
const bashBody = (index: number) => tool.renderResult!({
|
|
78
|
+
content: [{ type: "text", text: `Bash result ${index}: ${"output record 広い ".repeat(20)}` }], details: {},
|
|
79
|
+
}, { expanded: true, isPartial: false }, theme as never, {} as never);
|
|
80
|
+
return { agent, job, agentTool, bash, bashBody, bashArgs, tool, work, changeTheme: () => { palette = 32; } };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
for (const kind of ["agent", "job", "bash", "bashBody", "agentTool"] as const) test(`settled ${kind} cards wrap once per transcript width`, (t) => {
|
|
84
|
+
const fixture = transcriptCards(t);
|
|
85
|
+
const transcript = new Container();
|
|
86
|
+
const count = 12;
|
|
87
|
+
for (let index = 0; index < count; index++) transcript.addChild(fixture[kind](index));
|
|
88
|
+
const lines = transcript.render(100);
|
|
89
|
+
assert.equal(fixture.work[kind], count, "one cold wrap per card");
|
|
90
|
+
for (let frame = 0; frame < 12; frame++) assert.deepEqual(transcript.render(100), lines);
|
|
91
|
+
assert.equal(fixture.work[kind], count, "steady frames must not rewrap settled rows");
|
|
92
|
+
assert.notDeepEqual(transcript.render(75), lines);
|
|
93
|
+
assert.equal(fixture.work[kind], count * 2, "one new wrap per narrower card");
|
|
94
|
+
assert.deepEqual(transcript.render(100), lines);
|
|
95
|
+
assert.equal(fixture.work[kind], count * 3, "replacing a width evicts the previous frame");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Opt-in raw ANSI rows for a differential run against the same fixture on HEAD.
|
|
99
|
+
function recordFrames(t: TestContext, kind: string, frames: Record<string, readonly string[]>) {
|
|
100
|
+
if (process.env.GENTLE_PI_CARD_FRAME_DUMP === "1") t.diagnostic(`CARD-FRAMES ${kind} ${Buffer.from(JSON.stringify(frames)).toString("base64")}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for (const kind of ["agent", "job", "agentTool"] as const) test(`${kind} card preserves its settled and updated notices`, (t) => {
|
|
104
|
+
const fixture = transcriptCards(t);
|
|
105
|
+
const card = fixture[kind](0);
|
|
106
|
+
const first = card.render(100);
|
|
107
|
+
const resized = card.render(76);
|
|
108
|
+
const narrow = card.render(8);
|
|
109
|
+
const expanded = fixture[kind](0, true).render(100);
|
|
110
|
+
const updated = fixture[kind](0, true, undefined, "\nnew output line").render(100);
|
|
111
|
+
const failed = fixture[kind](0, true, "failed", "\nerror output line").render(100);
|
|
112
|
+
const progress = fixture[kind](0, true, "running", "\nprogress output line").render(100);
|
|
113
|
+
assert.ok(expanded.length > first.length);
|
|
114
|
+
assert.deepEqual(fixture[kind](0).render(100), first, "collapsing returns to the original bytes");
|
|
115
|
+
assert.match(stripAnsi(updated.join("\n")), /new output line/);
|
|
116
|
+
assert.match(stripAnsi(failed.join("\n")), /error output line/);
|
|
117
|
+
assert.notDeepEqual(failed, updated);
|
|
118
|
+
if (kind === "agentTool") assert.deepEqual(progress, [], "polling a running answer is deliberately hidden");
|
|
119
|
+
else assert.match(stripAnsi(progress.join("\n")), kind === "agent" ? /RUNNING/ : /Monitor/);
|
|
120
|
+
assert.deepEqual(card.render(100), first);
|
|
121
|
+
setCardStyle(CARD_STYLE.NEON);
|
|
122
|
+
const neon = card.render(100);
|
|
123
|
+
assert.notDeepEqual(neon, first);
|
|
124
|
+
setCardStyle(CARD_STYLE.FLOAT);
|
|
125
|
+
assert.deepEqual(card.render(100), first);
|
|
126
|
+
fixture.changeTheme();
|
|
127
|
+
card.invalidate();
|
|
128
|
+
const recolored = card.render(100);
|
|
129
|
+
assert.notDeepEqual(recolored, first, "invalidation repaints at the same width and style");
|
|
130
|
+
recordFrames(t, kind, { first, resized, narrow, expanded, updated, failed, progress, neon, recolored });
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("Bash heading preserves its settled and running appearance", (t) => {
|
|
134
|
+
const fixture = transcriptCards(t);
|
|
135
|
+
const card = fixture.bash(0);
|
|
136
|
+
const first = card.render(100);
|
|
137
|
+
const resized = card.render(76);
|
|
138
|
+
const updated = fixture.bash(1).render(100);
|
|
139
|
+
const expanded = fixture.bash(0, true).render(100);
|
|
140
|
+
const pending = fixture.bash(0, false, true).render(100);
|
|
141
|
+
assert.notDeepEqual(updated, first);
|
|
142
|
+
assert.ok(expanded.length > first.length);
|
|
143
|
+
assert.match(stripAnsi(pending.join("\n")), /running…/);
|
|
144
|
+
assert.deepEqual(card.render(100), first);
|
|
145
|
+
fixture.changeTheme();
|
|
146
|
+
card.invalidate();
|
|
147
|
+
const recolored = card.render(100);
|
|
148
|
+
assert.notDeepEqual(recolored, first);
|
|
149
|
+
setCardContent(CARD_CONTENT.DEFAULT);
|
|
150
|
+
const preview = fixture.bash(0).render(100);
|
|
151
|
+
recordFrames(t, "bash-heading", { first, resized, updated, expanded, pending, recolored, preview });
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("Bash heading cache reflows on a live Card content preference change", (t) => {
|
|
155
|
+
const fixture = transcriptCards(t);
|
|
156
|
+
const card = fixture.bash(0);
|
|
157
|
+
const minimal = card.render(100);
|
|
158
|
+
setCardContent(CARD_CONTENT.DEFAULT);
|
|
159
|
+
const preview = fixture.bash(0).render(100);
|
|
160
|
+
assert.notDeepEqual(preview, minimal);
|
|
161
|
+
const beforePreferenceChange = fixture.work.bash;
|
|
162
|
+
assert.deepEqual(card.render(100), preview, "same width and theme must not reuse the old bash heading after content level changes");
|
|
163
|
+
assert.equal(fixture.work.bash, beforePreferenceChange + 1);
|
|
164
|
+
assert.deepEqual(card.render(100), preview);
|
|
165
|
+
assert.equal(fixture.work.bash, beforePreferenceChange + 1, "the new presentation is also cached");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("Pi keeps Bash output live, mouse-expands it and repaints settled rows", (t) => {
|
|
169
|
+
const { tool, bashArgs } = transcriptCards(t);
|
|
170
|
+
const card = new ToolExecutionComponent("bash", "call-0", bashArgs(0), {}, tool, { requestRender() {} } as never, "/repo");
|
|
171
|
+
const width = 100;
|
|
172
|
+
const text = (frame: readonly string[]) => stripAnsi(frame.join("\n"));
|
|
173
|
+
const show = (line: string, isPartial: boolean, isError = false) => card.updateResult({ content: [{ type: "text", text: line }], isError }, isPartial);
|
|
174
|
+
const mouse = (type: TuiMouseEvent["type"], button: TuiMouseEvent["button"], height: number): TuiMouseEvent => ({ type, button, x: 5, y: 2, screenX: 5, screenY: 2, width, height, shift: false, alt: false, ctrl: false });
|
|
175
|
+
card.setArgsComplete();
|
|
176
|
+
card.markExecutionStarted();
|
|
177
|
+
const running = card.render(width);
|
|
178
|
+
assert.match(text(running), /running…/);
|
|
179
|
+
card.setExpanded(true);
|
|
180
|
+
show("first chunk", true);
|
|
181
|
+
const partial = card.render(width);
|
|
182
|
+
assert.match(text(partial), /first chunk/);
|
|
183
|
+
assert.doesNotMatch(text(partial), /running…/, "only the result slot closes the frame after output arrives");
|
|
184
|
+
show("first chunk\nsecond chunk", true);
|
|
185
|
+
const streaming = card.render(width);
|
|
186
|
+
assert.match(text(streaming), /second chunk/);
|
|
187
|
+
show("first chunk\nsecond chunk\ndone", false);
|
|
188
|
+
const done = card.render(width);
|
|
189
|
+
assert.match(text(done), /\bdone\b/);
|
|
190
|
+
assert.doesNotMatch(text(done), /… bash/);
|
|
191
|
+
assert.equal(card.handleMouse(mouse("move", "none", done.length)), undefined);
|
|
192
|
+
assert.deepEqual(card.render(width), done, "hover does not change card chrome");
|
|
193
|
+
assert.equal(card.handleMouse(mouse("click", "left", done.length))?.handled, true);
|
|
194
|
+
const collapsed = card.render(width);
|
|
195
|
+
assert.doesNotMatch(text(collapsed), /second chunk/);
|
|
196
|
+
assert.equal(card.handleMouse(mouse("click", "left", collapsed.length))?.handled, true);
|
|
197
|
+
assert.deepEqual(card.render(width), done);
|
|
198
|
+
show("failure on exit", false, true);
|
|
199
|
+
const failed = card.render(width);
|
|
200
|
+
assert.match(text(failed), /failure on exit/);
|
|
201
|
+
assert.doesNotMatch(text(failed), /second chunk/);
|
|
202
|
+
const resized = card.render(76);
|
|
203
|
+
assert.notDeepEqual(resized, failed);
|
|
204
|
+
card.render(width);
|
|
205
|
+
initTheme("light");
|
|
206
|
+
t.after(() => initTheme("dark"));
|
|
207
|
+
card.invalidate();
|
|
208
|
+
const recolored = card.render(width);
|
|
209
|
+
assert.notDeepEqual(recolored, failed);
|
|
210
|
+
assert.equal(text(recolored), text(failed));
|
|
211
|
+
recordFrames(t, "bash-lifecycle", { running, partial, streaming, done, collapsed, failed, resized, recolored });
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("quiet Bash still advances and freezes the timer on a live Gentle AI card", async (t) => {
|
|
215
|
+
const { tool } = transcriptCards(t);
|
|
216
|
+
t.mock.timers.enable({ apis: ["Date", "setTimeout"], now: 1000 });
|
|
217
|
+
let requested = 0;
|
|
218
|
+
const card = new ToolExecutionComponent("bash", "clock", { command: "gentle-ai review status" }, {}, tool,
|
|
219
|
+
{ requestRender() { requested++; } } as never, "/repo");
|
|
220
|
+
card.setArgsComplete();
|
|
221
|
+
card.markExecutionStarted();
|
|
222
|
+
const running = card.render(100);
|
|
223
|
+
assert.match(stripAnsi(running.join("\n")), /0s/);
|
|
224
|
+
const requests = requested;
|
|
225
|
+
t.mock.timers.tick(1000);
|
|
226
|
+
const tick = card.render(100);
|
|
227
|
+
assert.equal(requested, requests + 1, "the live clock schedules a repaint");
|
|
228
|
+
assert.match(stripAnsi(tick.join("\n")), /1s/);
|
|
229
|
+
card.updateResult({ content: [{ type: "text", text: "finished" }], isError: false });
|
|
230
|
+
await Promise.resolve(); // let the result renderer's scheduled invalidation finish
|
|
231
|
+
const done = card.render(100);
|
|
232
|
+
assert.match(stripAnsi(done.join("\n")), /1s/);
|
|
233
|
+
const settledRequests = requested;
|
|
234
|
+
t.mock.timers.tick(10_000);
|
|
235
|
+
assert.deepEqual(card.render(100), done);
|
|
236
|
+
assert.equal(requested, settledRequests, "a settled card does not schedule further ticks");
|
|
237
|
+
recordFrames(t, "bash-clock", { running, tick, done });
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test("mixed settled-card frame timing", { skip: process.env.GENTLE_PI_CARD_FRAME_BENCH !== "1" }, (t) => {
|
|
241
|
+
const { agent, job, bash, bashBody, agentTool, work } = transcriptCards(t);
|
|
242
|
+
const transcript = new Container();
|
|
243
|
+
for (let index = 0; index < 16; index++) {
|
|
244
|
+
transcript.addChild(agent(index));
|
|
245
|
+
transcript.addChild(job(index * 2));
|
|
246
|
+
transcript.addChild(job(index * 2 + 1));
|
|
247
|
+
const toolCard = new Container();
|
|
248
|
+
toolCard.addChild(bash(index, true));
|
|
249
|
+
toolCard.addChild(bashBody(index));
|
|
250
|
+
transcript.addChild(toolCard);
|
|
251
|
+
transcript.addChild(agentTool(index));
|
|
252
|
+
}
|
|
253
|
+
for (let frame = 0; frame < 10; frame++) transcript.render(100);
|
|
254
|
+
const warm = { ...work };
|
|
255
|
+
const samples = Array.from({ length: 80 }, () => {
|
|
256
|
+
const start = performance.now();
|
|
257
|
+
transcript.render(100);
|
|
258
|
+
return performance.now() - start;
|
|
259
|
+
}).sort((a, b) => a - b);
|
|
260
|
+
const wrapStarts = Object.fromEntries((Object.keys(work) as Array<keyof typeof work>).map((kind) => [kind, work[kind] - warm[kind]]));
|
|
261
|
+
t.diagnostic(`80 cards / ${samples.length} frames: median ${samples[40]!.toFixed(3)} ms; p95 ${samples[75]!.toFixed(3)} ms; wrap starts: ${JSON.stringify(wrapStarts)}`);
|
|
262
|
+
});
|
|
263
|
+
|
|
11
264
|
test("native fullscreen scroll frames reuse complete tool cards and session statistics", () => {
|
|
12
265
|
let decoration = 0;
|
|
13
266
|
let scans = 0;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import fs from "node:fs/promises";
|
|
4
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { basename, join } from "node:path";
|
|
7
|
+
import test, { type TestContext } from "node:test";
|
|
8
|
+
import { WorktreeChangesTracker } from "../lib/shell-changes.ts";
|
|
9
|
+
import { shellUntrackedLines } from "../lib/shell-untracked-lines.ts";
|
|
10
|
+
|
|
11
|
+
async function fixture(t: TestContext) {
|
|
12
|
+
const tmp = await fs.mkdtemp(join(tmpdir(), "gentle-untracked-cache-"));
|
|
13
|
+
t.after(() => fs.rm(tmp, { recursive: true, force: true }));
|
|
14
|
+
const root = join(tmp, "repo");
|
|
15
|
+
const otherRoot = join(tmp, "other-repo");
|
|
16
|
+
const directory = join(tmp, "cache", "untracked");
|
|
17
|
+
await Promise.all([fs.mkdir(root), fs.mkdir(otherRoot)]);
|
|
18
|
+
const key = createHash("sha256").update(await fs.realpath(root)).digest("hex");
|
|
19
|
+
const cacheFile = join(directory, `${key}.json`);
|
|
20
|
+
const files = new Map<string, { bytes: Buffer; mtimeMs: number }>();
|
|
21
|
+
const put = (path: string, content: string | Buffer, mtimeMs = 1) => files.set(path, { bytes: Buffer.from(content), mtimeMs });
|
|
22
|
+
function session(repo = root, cacheDirectory = directory) {
|
|
23
|
+
const reads: string[] = [];
|
|
24
|
+
const io = {
|
|
25
|
+
lstat: async (path: string) => {
|
|
26
|
+
const { bytes, mtimeMs } = files.get(path.slice(repo.length + 1))!;
|
|
27
|
+
return { isFile: () => true, size: bytes.length, mtimeMs };
|
|
28
|
+
},
|
|
29
|
+
read: async (path: string, length: number, offset: number) => {
|
|
30
|
+
const relative = path.slice(repo.length + 1);
|
|
31
|
+
reads.push(relative);
|
|
32
|
+
return files.get(relative)!.bytes.subarray(offset, offset + length);
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const tracker = new WorktreeChangesTracker(
|
|
36
|
+
async () => ({ stdout: `worktree ${repo}\0branch refs/heads/main\0\0`, code: 0 }),
|
|
37
|
+
() => async ([cmd]) => ({ stdout: cmd === "status" ? [...files.keys()].map((path) => `?? ${path}\0`).join("") : "", code: 0 }),
|
|
38
|
+
undefined, () => [repo], undefined, shellUntrackedLines(io, undefined, cacheDirectory),
|
|
39
|
+
);
|
|
40
|
+
return { tracker, reads, start: () => tracker.start(), close: () => tracker.closeUntrackedCounts(),
|
|
41
|
+
counts: () => tracker.model.files.map(({ path, added, countsUnavailable }) => [path, added, countsUnavailable]) };
|
|
42
|
+
}
|
|
43
|
+
return { put, files, session, tmp, root, otherRoot, directory, cacheFile,
|
|
44
|
+
readCache: async () => JSON.parse(await fs.readFile(cacheFile, "utf8")) };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const missing = { code: "ENOENT" };
|
|
48
|
+
const count = (path: string, added: number) => [path, added, undefined];
|
|
49
|
+
|
|
50
|
+
test("a new counter uses the same real root's saved counts without reading unchanged content", async (t) => {
|
|
51
|
+
const f = await fixture(t);
|
|
52
|
+
f.put("binary", Buffer.from([0, 10]));
|
|
53
|
+
f.put("sub/file", "a\nb\n");
|
|
54
|
+
const cold = f.session();
|
|
55
|
+
await cold.start();
|
|
56
|
+
assert.deepEqual(cold.counts(), [count("binary", 0), count("sub/file", 2)]);
|
|
57
|
+
assert.deepEqual(cold.reads.sort(), ["binary", "sub/file"]);
|
|
58
|
+
await assert.rejects(fs.stat(f.cacheFile), missing, "scanning does not write immediately");
|
|
59
|
+
await cold.close();
|
|
60
|
+
const warm = f.session(await fs.realpath(f.root));
|
|
61
|
+
await warm.start();
|
|
62
|
+
assert.deepEqual(warm.counts(), cold.counts());
|
|
63
|
+
assert.deepEqual(warm.reads, []);
|
|
64
|
+
await warm.close();
|
|
65
|
+
const other = f.session(f.otherRoot);
|
|
66
|
+
await other.start();
|
|
67
|
+
assert.deepEqual(other.counts(), cold.counts());
|
|
68
|
+
assert.deepEqual(other.reads.sort(), ["binary", "sub/file"], "different roots do not share counts");
|
|
69
|
+
await other.close();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("changes to either size or mtime force a new read, never unchanged siblings", async (t) => {
|
|
73
|
+
const f = await fixture(t);
|
|
74
|
+
f.put("mtime", "ab"); f.put("size", "ab"); f.put("stable", "a\n");
|
|
75
|
+
const before = f.session(); await before.start(); await before.close();
|
|
76
|
+
f.put("mtime", "\n\n", 2); f.put("size", "\n\n\n");
|
|
77
|
+
const after = f.session(); await after.start();
|
|
78
|
+
assert.deepEqual(after.counts(), [count("mtime", 2), count("size", 3), count("stable", 1)]);
|
|
79
|
+
assert.deepEqual(after.reads.sort(), ["mtime", "size"]);
|
|
80
|
+
await after.close();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("paths that leave the Git inventory are pruned from the saved snapshot", async (t) => {
|
|
84
|
+
const f = await fixture(t);
|
|
85
|
+
f.put("gone", "a\n"); f.put("live", "b\n");
|
|
86
|
+
const before = f.session(); await before.start(); await before.close();
|
|
87
|
+
f.files.delete("gone");
|
|
88
|
+
const after = f.session(); await after.start(); await after.close();
|
|
89
|
+
assert.deepEqual(after.counts(), [count("live", 1)]);
|
|
90
|
+
assert.deepEqual(after.reads, []);
|
|
91
|
+
assert.deepEqual(await f.readCache(), { version: 1, entries: { live: { size: 2, mtimeMs: 1, added: 1 } } });
|
|
92
|
+
f.files.clear();
|
|
93
|
+
const empty = f.session(); await empty.start(); await empty.close();
|
|
94
|
+
assert.deepEqual(empty.counts(), []);
|
|
95
|
+
assert.deepEqual(await f.readCache(), { version: 1, entries: {} });
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("malformed JSON, another version and malformed entries fall back to recounting", async (t) => {
|
|
99
|
+
const f = await fixture(t);
|
|
100
|
+
f.put("text", "one\ntwo\n");
|
|
101
|
+
await fs.mkdir(f.directory, { recursive: true });
|
|
102
|
+
for (const data of ["{", JSON.stringify({ version: 2, entries: { text: { size: 8, mtimeMs: 1, added: 100 } } }),
|
|
103
|
+
JSON.stringify({ version: 1, entries: { text: { size: 8, mtimeMs: 1, added: "not a number" }, "../outside": { size: 2, mtimeMs: 1, added: 1 } } })]) {
|
|
104
|
+
await fs.writeFile(f.cacheFile, data);
|
|
105
|
+
const session = f.session(); await session.start(); await session.close();
|
|
106
|
+
assert.deepEqual(session.counts(), [count("text", 2)]);
|
|
107
|
+
assert.deepEqual(session.reads, ["text"]);
|
|
108
|
+
assert.deepEqual(await f.readCache(), { version: 1, entries: { text: { size: 8, mtimeMs: 1, added: 2 } } });
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("slow failed cache writes do not block scans or repeatedly retry in a read-only directory", { skip: process.platform === "win32", timeout: 10_000 }, async (t) => {
|
|
113
|
+
const f = await fixture(t);
|
|
114
|
+
await fs.mkdir(f.directory, { recursive: true });
|
|
115
|
+
await fs.chmod(f.directory, 0o500);
|
|
116
|
+
const started = Promise.withResolvers<void>(), release = Promise.withResolvers<void>();
|
|
117
|
+
let attempts = 0;
|
|
118
|
+
const writeFile = fs.writeFile;
|
|
119
|
+
const mock = t.mock.method(fs, "writeFile", async (...args: Parameters<typeof fs.writeFile>) => {
|
|
120
|
+
attempts++;
|
|
121
|
+
started.resolve();
|
|
122
|
+
await release.promise;
|
|
123
|
+
// Also exercise the failure on CI running as root (which can write to 0500).
|
|
124
|
+
if (process.getuid?.() === 0) throw Object.assign(new Error("read-only"), { code: "EACCES" });
|
|
125
|
+
return writeFile(...args);
|
|
126
|
+
});
|
|
127
|
+
syncBuiltinESMExports();
|
|
128
|
+
try {
|
|
129
|
+
f.put("f", "a\n");
|
|
130
|
+
const live = f.session(); await live.start();
|
|
131
|
+
assert.deepEqual(live.counts(), [count("f", 1)]);
|
|
132
|
+
assert.equal(attempts, 0);
|
|
133
|
+
let deadline: ReturnType<typeof setTimeout> | undefined;
|
|
134
|
+
try {
|
|
135
|
+
const attempted = new Promise<boolean>((resolve) => { deadline = setTimeout(resolve, 8_000, false); });
|
|
136
|
+
assert.equal(await Promise.race([started.promise.then(() => true), attempted]), true, "the debounced writer did attempt a write");
|
|
137
|
+
} finally {
|
|
138
|
+
clearTimeout(deadline);
|
|
139
|
+
}
|
|
140
|
+
f.put("f", "\n\n", 2);
|
|
141
|
+
await live.tracker.refresh();
|
|
142
|
+
assert.deepEqual(live.counts(), [count("f", 2)], "the scan settled while the write was blocked");
|
|
143
|
+
release.resolve();
|
|
144
|
+
await live.close();
|
|
145
|
+
assert.equal(attempts, 1);
|
|
146
|
+
assert.deepEqual(await fs.readdir(f.directory), []);
|
|
147
|
+
} finally {
|
|
148
|
+
release.resolve();
|
|
149
|
+
mock.mock.restore(); syncBuiltinESMExports();
|
|
150
|
+
await fs.chmod(f.directory, 0o700);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("two concurrent sessions leave one complete reusable snapshot for the same root", async (t) => {
|
|
155
|
+
const f = await fixture(t);
|
|
156
|
+
f.put("first", "a\n"); f.put("second", "b\nc\n");
|
|
157
|
+
const a = f.session(), b = f.session();
|
|
158
|
+
await Promise.all([a.start(), b.start()]);
|
|
159
|
+
assert.deepEqual(a.reads.sort(), ["first", "second"]);
|
|
160
|
+
assert.deepEqual(b.reads.sort(), ["first", "second"]);
|
|
161
|
+
await Promise.all([a.close(), b.close()]);
|
|
162
|
+
assert.deepEqual(await fs.readdir(f.directory), [basename(f.cacheFile)]);
|
|
163
|
+
const next = f.session(); await next.start(); await next.close();
|
|
164
|
+
assert.deepEqual(next.counts(), [count("first", 1), count("second", 2)]);
|
|
165
|
+
assert.deepEqual(next.reads, []);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("cache directories and snapshots are created with user-only permissions", { skip: process.platform === "win32" }, async (t) => {
|
|
169
|
+
const f = await fixture(t);
|
|
170
|
+
f.put("f", "a\n");
|
|
171
|
+
const s = f.session(); await s.start(); await s.close();
|
|
172
|
+
assert.equal((await fs.stat(f.directory)).mode & 0o777, 0o700);
|
|
173
|
+
assert.equal((await fs.stat(f.cacheFile)).mode & 0o777, 0o600);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("an injected cache directory inside the repository is not used", async (t) => {
|
|
177
|
+
const f = await fixture(t);
|
|
178
|
+
f.put("f", "a\n");
|
|
179
|
+
const inside = join(f.root, "cache", "untracked");
|
|
180
|
+
const s = f.session(f.root, inside); await s.start(); await s.close();
|
|
181
|
+
assert.deepEqual(s.counts(), [count("f", 1)]);
|
|
182
|
+
assert.deepEqual(s.reads, ["f"]);
|
|
183
|
+
await assert.rejects(fs.stat(inside), missing);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("a scan with nothing to remember does not create a cache directory", async (t) => {
|
|
187
|
+
const f = await fixture(t);
|
|
188
|
+
const s = f.session(); await s.start(); await s.close();
|
|
189
|
+
assert.deepEqual(s.counts(), []);
|
|
190
|
+
assert.deepEqual(s.reads, []);
|
|
191
|
+
await assert.rejects(fs.stat(f.directory), missing);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// The memory names the user's untracked paths: it is only ever published in a
|
|
195
|
+
// directory nobody else can read, also when that directory already existed.
|
|
196
|
+
test("a snapshot is never published in a non-private cache directory", { skip: process.platform === "win32" }, async (t) => {
|
|
197
|
+
const f = await fixture(t);
|
|
198
|
+
await fs.mkdir(f.directory, { recursive: true });
|
|
199
|
+
await fs.chmod(f.directory, 0o755);
|
|
200
|
+
f.put("f", "a\n");
|
|
201
|
+
const s = f.session();
|
|
202
|
+
await s.start();
|
|
203
|
+
assert.deepEqual(s.counts(), [count("f", 1)]);
|
|
204
|
+
await s.close();
|
|
205
|
+
const published = await fs.stat(f.cacheFile).catch((error) => {
|
|
206
|
+
if (error.code === "ENOENT") return undefined;
|
|
207
|
+
throw error;
|
|
208
|
+
});
|
|
209
|
+
if (published) {
|
|
210
|
+
assert.equal((await fs.stat(f.directory)).mode & 0o777, 0o700);
|
|
211
|
+
assert.equal(published.mode & 0o777, 0o600);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
@@ -23,23 +23,27 @@ const guide = readFileSync(new URL("../docs/gentle-shell.md", import.meta.url),
|
|
|
23
23
|
for (const [name, text] of Object.entries({ registeredDescription: background.description, guide })) {
|
|
24
24
|
test(`${name}: synchronous checks have an inclusive explicit 30-second limit and safe fallback`, () => {
|
|
25
25
|
for (const clause of [
|
|
26
|
-
"
|
|
27
|
-
"explicit
|
|
28
|
-
"
|
|
29
|
-
"
|
|
26
|
+
"Report synchronous timeouts as failures. Read output and diagnose the cause.",
|
|
27
|
+
"Rerun with a fix within explicit limits, never the same timed-out invocation.",
|
|
28
|
+
"If duration is the cause, say so; the same command may run in background.",
|
|
29
|
+
"local, finite, deterministic checks likely to finish within 30s",
|
|
30
|
+
"explicit timeout <= 30s, inclusive",
|
|
31
|
+
"longer or unknown duration, external waits, CI, builds, servers, deploys, and long tests",
|
|
30
32
|
"Preserve RED/GREEN and public-check exit codes, stdout, and stderr",
|
|
31
33
|
"Engram bugfix saves and session summaries", "RDD", "not a performance guarantee",
|
|
32
34
|
]) assert.ok(text.includes(clause), `${name} missing: ${clause}`);
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
test("inline still means the same parent, and the public background API stays asynchronous", () => {
|
|
38
|
+
test("inline still means the same parent, and the public background API stays asynchronous", (t) => {
|
|
39
|
+
const { name, description, parameters } = background;
|
|
40
|
+
t.diagnostic(`bash_background model declaration: ${Buffer.byteLength(JSON.stringify({ name, description, parameters }), "utf8")} B`);
|
|
37
41
|
assert.ok(core.includes("Small path: inline (parent; `bash_background` policy);"));
|
|
38
42
|
assert.ok(guide.includes("Inline means the same parent, not necessarily synchronous bash"));
|
|
39
43
|
assert.ok(core.includes("run the focused test and the suite inline in one command"));
|
|
40
44
|
assert.match(background.description, /return a job id at once/);
|
|
41
|
-
assert.match(background.description, /
|
|
42
|
-
assert.match(background.description, /
|
|
45
|
+
assert.match(background.description, /One automatic exit notice gives the exit code, tail and log path/);
|
|
46
|
+
assert.match(background.description, /Do not poll, sleep, or delegate a subagent to wait/);
|
|
43
47
|
assert.deepEqual(background.parameters, {
|
|
44
48
|
type: "object", additionalProperties: false, required: ["command"], properties: {
|
|
45
49
|
command: { type: "string", description: "Shell command to run in the background, in the session working directory." },
|
|
@@ -715,13 +715,13 @@ test("regenerateRegistry carries a skill resolved from a non-default PI_CODING_A
|
|
|
715
715
|
const cwd = join(tmpdir(), `gentle-pi-agentdir-cwd-${Date.now()}`);
|
|
716
716
|
const isolatedHome = join(tmpdir(), `gentle-pi-agentdir-home-${Date.now()}`);
|
|
717
717
|
const agentDir = join(tmpdir(), `gentle-pi-agentdir-root-${Date.now()}`);
|
|
718
|
-
const skillPath = join(agentDir, "skills", "
|
|
718
|
+
const skillPath = join(agentDir, "skills", "external-tool", "SKILL.md");
|
|
719
719
|
mkdirSync(dirname(skillPath), { recursive: true });
|
|
720
|
-
writeFileSync(skillPath, "---\nname:
|
|
720
|
+
writeFileSync(skillPath, "---\nname: external-tool\ndescription: Trigger: agent-dir skill.\n---\n");
|
|
721
721
|
|
|
722
722
|
const resolved: ResolvedSkill[] = [
|
|
723
723
|
{
|
|
724
|
-
name: "
|
|
724
|
+
name: "external-tool",
|
|
725
725
|
description: "Trigger: agent-dir skill.",
|
|
726
726
|
filePath: skillPath,
|
|
727
727
|
sourceInfo: { scope: "user" },
|