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,39 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
|
|
6
|
+
// gentle-shell#2686: on network-mounted workspaces a single unbounded recursive
|
|
7
|
+
// scan (`grep -r … .`) over raw `bash` cost up to 24.8 minutes (21–75× SMB I/O),
|
|
8
|
+
// and six such calls turned a trivial verification into a 49.6-minute wait. The
|
|
9
|
+
// dedicated `grep`/`find` tools honour `.gitignore`, and a
|
|
10
|
+
// bounded scan is faster even on local disks (0.06 s vs 1.8 s on an 8.7 MB repo),
|
|
11
|
+
// so the bound is unconditional: it never depends on the model detecting a
|
|
12
|
+
// network mount. Like the other prompt contracts here, this pins instruction
|
|
13
|
+
// delivery, not model adherence.
|
|
14
|
+
// These are instruction-delivery contracts, not proof of model adherence.
|
|
15
|
+
|
|
16
|
+
const read = (relative: string): string => readFileSync(join(import.meta.dirname, "..", relative), "utf8");
|
|
17
|
+
const verify = read("assets/agents/gentle-ai-verify.md");
|
|
18
|
+
const worker = read("assets/agents/gentle-ai-worker.md");
|
|
19
|
+
|
|
20
|
+
function containsAll(text: string, clauses: readonly string[], label: string): void {
|
|
21
|
+
const folded = text.toLowerCase();
|
|
22
|
+
for (const clause of clauses) assert.ok(folded.includes(clause.toLowerCase()), `${label} is missing: ${clause}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
for (const [label, prompt] of [["verify", verify], ["worker", worker]] as const) {
|
|
26
|
+
test(`${label}: prefers the dedicated tools over raw bash grep`, () => {
|
|
27
|
+
containsAll(prompt, [
|
|
28
|
+
"prefer the dedicated `grep`/`find` tools over raw `bash` grep",
|
|
29
|
+
"they honour `.gitignore`",
|
|
30
|
+
], `${label} search bounds`);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test(`${label}: forbids unbounded recursive scans`, () => {
|
|
34
|
+
containsAll(prompt, [
|
|
35
|
+
"Never run an unbounded recursive scan (`grep -r … .`, `find .` from the workspace root)",
|
|
36
|
+
"bound to source directories and pass `--exclude-dir={.git,vendor,node_modules}`",
|
|
37
|
+
], `${label} search bounds`);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { priceBridgeMessage } from "../lib/bridge-cost.ts";
|
|
4
|
+
|
|
5
|
+
const OPUS = { input: 4, output: 20, cacheRead: 0.2, cacheWrite: 5 };
|
|
6
|
+
const zeroCost = () => ({ input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 });
|
|
7
|
+
const bridgeMessage = (overrides: Record<string, unknown> = {}) => ({
|
|
8
|
+
role: "assistant", provider: "claude-bridge", model: "claude-opus-5-5",
|
|
9
|
+
usage: { input: 1_000_000, output: 100_000, cacheRead: 2_000_000, cacheWrite: 200_000, totalTokens: 3_300_000, cost: zeroCost() },
|
|
10
|
+
...overrides,
|
|
11
|
+
});
|
|
12
|
+
const catalog = (provider: string, id: string) => (provider === "anthropic" && id === "claude-opus-5-5" ? OPUS : undefined);
|
|
13
|
+
|
|
14
|
+
test("priceBridgeMessage prices a zero-cost claude-bridge message at the Anthropic list price", () => {
|
|
15
|
+
const message = bridgeMessage();
|
|
16
|
+
const priced = priceBridgeMessage(message, catalog);
|
|
17
|
+
assert.ok(priced);
|
|
18
|
+
// 1M input * $4 + 100k output * $20 + 2M cache read * $0.2 + 200k cache write * $5
|
|
19
|
+
assert.deepEqual(priced.usage.cost, { input: 4, output: 2, cacheRead: 0.4, cacheWrite: 1, total: 7.4 });
|
|
20
|
+
assert.equal(priced.usage.totalTokens, 3_300_000, "token counts stay as the bridge reported them");
|
|
21
|
+
assert.equal(message.usage.cost.total, 0, "the original message is not mutated");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("priceBridgeMessage leaves messages it must not price untouched", () => {
|
|
25
|
+
assert.equal(priceBridgeMessage(bridgeMessage({ provider: "anthropic" }), catalog), undefined, "other providers price themselves");
|
|
26
|
+
assert.equal(priceBridgeMessage(bridgeMessage({ role: "user" }), catalog), undefined);
|
|
27
|
+
assert.equal(priceBridgeMessage(bridgeMessage({ model: "claude-unknown" }), catalog), undefined, "no catalog price, no guess");
|
|
28
|
+
const alreadyPriced = bridgeMessage();
|
|
29
|
+
alreadyPriced.usage.cost = { input: 1, output: 0, cacheRead: 0, cacheWrite: 0, total: 1 };
|
|
30
|
+
assert.equal(priceBridgeMessage(alreadyPriced, catalog), undefined, "a bridge that reports cost wins");
|
|
31
|
+
assert.equal(priceBridgeMessage(bridgeMessage({ usage: undefined }), catalog), undefined);
|
|
32
|
+
});
|
|
@@ -1179,9 +1179,8 @@ posixTest("writeNpmrcAuth writes the filtered npmrc 0600 inside the prefix; user
|
|
|
1179
1179
|
});
|
|
1180
1180
|
|
|
1181
1181
|
test("pnpmEnvironment keeps the variables the prefix npmrc references and still drops npm settings", () => {
|
|
1182
|
-
const
|
|
1183
|
-
const layout = prefixLayout({ platform: "linux", env: {}, home:
|
|
1184
|
-
mkdirSync(join(layout.root, "pnpm", "config"), { recursive: true });
|
|
1182
|
+
const config = join(home(), "npmrc");
|
|
1183
|
+
const layout = { ...prefixLayout({ platform: "linux", env: {}, home: "/home/me" }), npmrc: config };
|
|
1185
1184
|
writeFileSync(layout.npmrc, "//npm.acme.dev/:_authToken=${NPM_TOKEN}\n//h/:_auth=${npm_config_x}\n");
|
|
1186
1185
|
const env = pnpmEnvironment(layout, { platform: "linux", env: { PATH: "/usr/bin", NPM_TOKEN: "secret", NPM_OTHER: "o", npm_config_x: "x",
|
|
1187
1186
|
npm_config_cache: "/home/me/.npm" } });
|
|
@@ -1526,7 +1525,10 @@ test("Pi reads the bundled npmCommand as npm and installs git extensions with np
|
|
|
1526
1525
|
: prefixLayout({ platform: process.platform, env: {}, home: "/home/npm" });
|
|
1527
1526
|
const pi = await piPackageManager(bundledNpmCommand(host));
|
|
1528
1527
|
assert.equal(pi.getPackageManagerName(), "npm");
|
|
1529
|
-
|
|
1528
|
+
const args = pi.getGitDependencyInstallArgs();
|
|
1529
|
+
const npmFlags = ["install", "--omit=dev", "--legacy-peer-deps"];
|
|
1530
|
+
// Pi 1.5 adds two npm-only flags; reject any vector other than the audited 1.4/1.5 forms.
|
|
1531
|
+
assert.deepEqual(args, args.length === npmFlags.length ? npmFlags : [...npmFlags, "--no-audit", "--no-fund"]);
|
|
1530
1532
|
// The command before N1 read as `node`: plain `npm install` for git extensions.
|
|
1531
1533
|
const before = await piPackageManager([host.node, host.npmCli, ...bundledNpmCommand(host).slice(2)]);
|
|
1532
1534
|
assert.equal(before.getPackageManagerName(), "node");
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
|
|
5
|
+
test("CI only cancels superseded PR runs, with unique groups for other events", () => {
|
|
6
|
+
const workflow = readFileSync(new URL("../.github/workflows/ci.yml", import.meta.url), "utf8");
|
|
7
|
+
const header = workflow.slice(0, workflow.indexOf("\njobs:"));
|
|
8
|
+
assert.equal((header.match(/^concurrency:$/gm) ?? []).length, 1);
|
|
9
|
+
assert.ok(header.includes(" group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.run_id }}\n"));
|
|
10
|
+
assert.ok(header.includes(" cancel-in-progress: ${{ github.event_name == 'pull_request' }}\n"));
|
|
11
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
|
|
8
|
+
const workflow = readFileSync(process.env.CI_MERGE_BASE_IDENTITY_WORKFLOW ?? new URL("../.github/workflows/ci.yml", import.meta.url), "utf8");
|
|
9
|
+
const identityError = "Checkout is not the declared PR synthetic merge of base and head";
|
|
10
|
+
|
|
11
|
+
test("Windows CI executes its checkout identity regressions", () => {
|
|
12
|
+
assert.match(workflow, /name: Test immutable checkout identity\r?\n\s+shell: pwsh\r?\n\s+run: node --experimental-strip-types --test tests\/ci-merge-base-identity\.test\.ts/);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("CI checkout identity through native Windows PowerShell", { skip: process.platform !== "win32" }, async (t) => {
|
|
16
|
+
const step = workflow.indexOf(" - name: Verify merged inventory and run focused routing cases");
|
|
17
|
+
const run = workflow.indexOf(" run: |", step);
|
|
18
|
+
const inventory = workflow.indexOf(" $names = @(", run);
|
|
19
|
+
assert.ok(step >= 0 && run > step && inventory > run, "public CI guard boundaries must exist");
|
|
20
|
+
const prefix = workflow.slice(workflow.indexOf("\n", run) + 1, inventory)
|
|
21
|
+
.split(/\r?\n/).map((line) => {
|
|
22
|
+
assert.ok(line === "" || line.startsWith(" "));
|
|
23
|
+
return line.slice(10);
|
|
24
|
+
}).join("\n");
|
|
25
|
+
|
|
26
|
+
const root = mkdtempSync(join(tmpdir(), "ci-merge-identity-"));
|
|
27
|
+
const repo = join(root, "repo");
|
|
28
|
+
mkdirSync(repo);
|
|
29
|
+
const cleanEnv = Object.fromEntries(Object.entries(process.env).filter(([name]) => !/^GIT_/i.test(name)));
|
|
30
|
+
const parents = new Map<string, string[]>();
|
|
31
|
+
function git(args: string[], input?: string): string {
|
|
32
|
+
const result = spawnSync("git", ["-c", "user.name=CI fixture", "-c", "user.email=fixture@example.invalid", "-c", "commit.gpgsign=false", ...args], {
|
|
33
|
+
cwd: repo, env: cleanEnv, encoding: "utf8", input, timeout: 10_000,
|
|
34
|
+
});
|
|
35
|
+
assert.equal(result.error, undefined, String(result.error));
|
|
36
|
+
assert.equal(result.status, 0, result.stderr);
|
|
37
|
+
return result.stdout.trim();
|
|
38
|
+
}
|
|
39
|
+
function tree(content: string): string {
|
|
40
|
+
const blob = git(["hash-object", "-w", "--stdin"], content);
|
|
41
|
+
return git(["mktree"], `100644 blob ${blob}\tsentinel.txt\n`);
|
|
42
|
+
}
|
|
43
|
+
function commit(treeId: string, previous: string[], message: string): string {
|
|
44
|
+
const sha = git(["commit-tree", treeId, ...previous.flatMap((sha) => ["-p", sha]), "-m", message]);
|
|
45
|
+
parents.set(sha, previous);
|
|
46
|
+
return sha;
|
|
47
|
+
}
|
|
48
|
+
function snapshot(): string {
|
|
49
|
+
return JSON.stringify({
|
|
50
|
+
head: git(["rev-parse", "HEAD"]),
|
|
51
|
+
refs: git(["for-each-ref", "--format=%(refname):%(objectname)"]),
|
|
52
|
+
status: git(["status", "--porcelain=v1"]),
|
|
53
|
+
sentinel: readFileSync(join(repo, "sentinel.txt"), "utf8"),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
git(["init", "--quiet", "-b", "fixture"]);
|
|
59
|
+
const originalTree = tree("unchanged fixture data\n");
|
|
60
|
+
const base = commit(originalTree, [], "event base");
|
|
61
|
+
const advancedBase = commit(originalTree, [base], "advanced base");
|
|
62
|
+
const head = commit(originalTree, [base], "PR head");
|
|
63
|
+
const otherHead = commit(originalTree, [base], "different PR head");
|
|
64
|
+
const originalMerge = commit(originalTree, [base, head], "original run merge");
|
|
65
|
+
const runMerge = commit(originalTree, [advancedBase, head], "current run merge");
|
|
66
|
+
const wrongTree = commit(tree("different tree with identical parents\n"), [advancedBase, head], "wrong tree");
|
|
67
|
+
const wrongHead = commit(originalTree, [advancedBase, otherHead], "wrong head");
|
|
68
|
+
const script = join(root, "guard.ps1");
|
|
69
|
+
// Only package-manager version metadata is stubbed; Git and the CI guard execute unchanged.
|
|
70
|
+
writeFileSync(script, `$ErrorActionPreference = 'Stop'\nfunction pnpm { 'fixture-pnpm' }\ntry {\n${prefix}\n} catch {\n[Console]::Error.WriteLine($_.Exception.Message)\nexit 1\n}\n`);
|
|
71
|
+
|
|
72
|
+
const cases: { name: string; checkout: string; run: string; base?: string; status: number; override?: string }[] = [
|
|
73
|
+
{ name: "matching event tuple retains its previous success", checkout: originalMerge, run: originalMerge, base, status: 0 },
|
|
74
|
+
{ name: "reported older event base does not reject the immutable run merge", checkout: runMerge, run: runMerge, base, status: 0 },
|
|
75
|
+
{ name: "a newer event base does not redefine the already selected run", checkout: originalMerge, run: originalMerge, base: advancedBase, status: 0 },
|
|
76
|
+
{ name: "stale checkout is rejected even when its event parents match", checkout: originalMerge, run: runMerge, base, status: 1 },
|
|
77
|
+
{ name: "another tree with identical parents is rejected", checkout: wrongTree, run: runMerge, base: advancedBase, status: 1 },
|
|
78
|
+
{ name: "declared PR head remains mandatory", checkout: wrongHead, run: wrongHead, base: advancedBase, status: 1 },
|
|
79
|
+
{ name: "two-parent synthetic merge remains mandatory", checkout: head, run: head, base, status: 1 },
|
|
80
|
+
{ name: "missing independent run SHA is rejected", checkout: originalMerge, run: "", base, status: 1 },
|
|
81
|
+
{ name: "missing event base metadata is still rejected", checkout: originalMerge, run: originalMerge, status: 1 },
|
|
82
|
+
{ name: "inherited Git overrides remain blocked without revealing values", checkout: originalMerge, run: originalMerge, base, status: 1, override: "override-value-must-not-appear" },
|
|
83
|
+
];
|
|
84
|
+
for (const [index, entry] of cases.entries()) {
|
|
85
|
+
await t.test(entry.name, () => {
|
|
86
|
+
git(["checkout", "--quiet", "--detach", entry.checkout]);
|
|
87
|
+
const before = snapshot();
|
|
88
|
+
const evidenceDir = join(root, String(index));
|
|
89
|
+
mkdirSync(evidenceDir);
|
|
90
|
+
const eventPath = join(evidenceDir, "event.json");
|
|
91
|
+
writeFileSync(eventPath, JSON.stringify({ pull_request: { head: { sha: head }, base: { sha: entry.base } } }));
|
|
92
|
+
const result = spawnSync("pwsh", ["-NoLogo", "-NoProfile", "-NonInteractive", "-File", script], {
|
|
93
|
+
cwd: repo, encoding: "utf8", timeout: 30_000,
|
|
94
|
+
env: { ...cleanEnv, RUNNER_TEMP: evidenceDir, GITHUB_EVENT_PATH: eventPath, GITHUB_SHA: entry.run, ...(entry.override ? { GIT_DIR: entry.override } : {}) },
|
|
95
|
+
});
|
|
96
|
+
assert.equal(result.error, undefined, String(result.error));
|
|
97
|
+
assert.equal(result.signal, null);
|
|
98
|
+
assert.equal(result.status, entry.status, result.stderr);
|
|
99
|
+
const stdout = result.stdout.replace(/\r\n/g, "\n");
|
|
100
|
+
const stderr = result.stderr.replace(/\r\n/g, "\n");
|
|
101
|
+
const expected = entry.override
|
|
102
|
+
? "Blocked inherited Git overrides (names only): GIT_DIR\n"
|
|
103
|
+
: `checkout=${entry.checkout} parents=${[entry.checkout, ...parents.get(entry.checkout)!].join(" ")} prHead=${head} prBase=${entry.base ?? ""} runMerge=${entry.run} node=${process.version} pnpm=fixture-pnpm\n`;
|
|
104
|
+
assert.equal(stdout, expected);
|
|
105
|
+
assert.equal(stderr, entry.status === 0 ? "" : `${entry.override ? "Inherited Git environment equivalence is unproved" : identityError}\n`);
|
|
106
|
+
assert.equal(readFileSync(join(evidenceDir, "review-routing-focused-windows.tap.log"), "utf8").replace(/\r\n/g, "\n"), expected);
|
|
107
|
+
assert.equal(snapshot(), before, "guard must not mutate checkout data or refs");
|
|
108
|
+
if (entry.override) assert.ok(!stdout.includes(entry.override) && !stderr.includes(entry.override));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
} finally {
|
|
112
|
+
rmSync(root, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
@@ -9,6 +9,7 @@ import codeGraphTools, {
|
|
|
9
9
|
createCodeGraphTool,
|
|
10
10
|
codeGraphNodeScript,
|
|
11
11
|
findCodeGraphNodeScriptOnPath,
|
|
12
|
+
isSameDirectory,
|
|
12
13
|
type CodeGraphRunner,
|
|
13
14
|
} from "../extensions/codegraph-tools.ts";
|
|
14
15
|
|
|
@@ -39,6 +40,74 @@ test("CodeGraph tool rejects non-project, nested-project, HOME, and temporary wo
|
|
|
39
40
|
assert.equal(calls, 0);
|
|
40
41
|
});
|
|
41
42
|
|
|
43
|
+
test("CodeGraph workspace guard compares directories by identity, not path spelling (#2558)", (t) => {
|
|
44
|
+
// A mapped drive and its UNC form name one directory; an alias reproduces that without a network share.
|
|
45
|
+
const root = workspace(t);
|
|
46
|
+
const holder = realpathSync(mkdtempSync(join(tmpdir(), "gentle-pi-codegraph-alias-")));
|
|
47
|
+
t.after(() => rmSync(holder, { recursive: true, force: true }));
|
|
48
|
+
const alias = join(holder, "root");
|
|
49
|
+
symlinkSync(root, alias, "junction");
|
|
50
|
+
t.after(() => rmSync(alias, { force: true }));
|
|
51
|
+
const nested = join(root, "nested");
|
|
52
|
+
mkdirSync(nested);
|
|
53
|
+
assert.notEqual(alias, root);
|
|
54
|
+
assert.equal(isSameDirectory(alias, root), true);
|
|
55
|
+
assert.equal(isSameDirectory(root, nested), false);
|
|
56
|
+
assert.equal(isSameDirectory(root, join(root, "missing")), false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("CodeGraph tool accepts the Git root reached through a different spelling of the same directory (#2558)", async (t) => {
|
|
60
|
+
// A mapped drive is one such spelling; on a case-insensitive filesystem a different letter case is another.
|
|
61
|
+
const root = workspace(t);
|
|
62
|
+
const respelled = [...root].map((char) => (char === char.toLowerCase() ? char.toUpperCase() : char.toLowerCase())).join("");
|
|
63
|
+
if (respelled === root || !existsSync(respelled)) {
|
|
64
|
+
t.skip("case-sensitive filesystem: no second spelling of the same directory");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const cwds: string[] = [];
|
|
68
|
+
const tool = createCodeGraphTool(async (_args, options) => {
|
|
69
|
+
cwds.push(options.cwd);
|
|
70
|
+
return { stdout: "ok", stderr: "" };
|
|
71
|
+
});
|
|
72
|
+
await tool.execute("test", { operation: "query", query: "symbol" }, undefined, undefined, { cwd: respelled } as ExtensionContext);
|
|
73
|
+
assert.deepEqual(cwds, [realpathSync(respelled)]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("CodeGraph workspace rejection names the compared paths and Git's own error (#2558)", async (t) => {
|
|
77
|
+
const nonProject = realpathSync(mkdtempSync(join(tmpdir(), "gentle-pi-codegraph-non-project-")));
|
|
78
|
+
t.after(() => rmSync(nonProject, { recursive: true, force: true }));
|
|
79
|
+
const root = workspace(t);
|
|
80
|
+
const nested = join(root, "nested");
|
|
81
|
+
mkdirSync(nested);
|
|
82
|
+
let calls = 0;
|
|
83
|
+
const tool = createCodeGraphTool(async () => {
|
|
84
|
+
calls += 1;
|
|
85
|
+
return { stdout: "unexpected", stderr: "" };
|
|
86
|
+
});
|
|
87
|
+
const rejection = async (cwd: string): Promise<string> => {
|
|
88
|
+
try {
|
|
89
|
+
await tool.execute("test", { operation: "init" }, undefined, undefined, { cwd } as ExtensionContext);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
return (error as Error).message;
|
|
92
|
+
}
|
|
93
|
+
assert.fail(`expected ${cwd} to be rejected`);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
assert.equal(
|
|
97
|
+
await rejection(nested),
|
|
98
|
+
`CodeGraph requires a real Git project root equal to the current workspace.\n workspace: ${nested}\n git toplevel: ${root}`,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const [prefix, workspaceLine, gitLine, ...rest] = (await rejection(nonProject)).split("\n");
|
|
102
|
+
assert.equal(prefix, "CodeGraph requires a real Git project root equal to the current workspace.");
|
|
103
|
+
assert.equal(workspaceLine, ` workspace: ${nonProject}`);
|
|
104
|
+
// Git's stderr, not Node's "Command failed" wrapper; Git may localize the text itself.
|
|
105
|
+
assert.match(gitLine, /^ git: \S/);
|
|
106
|
+
assert.doesNotMatch(gitLine, /Command failed/);
|
|
107
|
+
for (const line of rest) assert.match(line, /^ /);
|
|
108
|
+
assert.equal(calls, 0);
|
|
109
|
+
});
|
|
110
|
+
|
|
42
111
|
test("CodeGraph query timeout is reported distinctly from user abort and never bounds init (#1901)", async (t) => {
|
|
43
112
|
const cwd = workspace(t);
|
|
44
113
|
const ctx = { cwd } as ExtensionContext;
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "@earendil-works/pi-coding-agent";
|
|
12
12
|
import { getCapabilities, imageFallback, setCapabilities, visibleWidth } from "@earendil-works/pi-tui";
|
|
13
13
|
import quietTools from "../extensions/quiet-tools.ts";
|
|
14
|
-
import { decorateCodemodeTool, registerCompactCodemode } from "../lib/codemode-renderer.ts";
|
|
14
|
+
import { CODEMODE_GUIDELINES, decorateCodemodeTool, registerCompactCodemode } from "../lib/codemode-renderer.ts";
|
|
15
15
|
import { CARD_STYLE, cardStyle, setCardStyle } from "../lib/shell-card.ts";
|
|
16
16
|
import { stripAnsi } from "../lib/terminal-theme.ts";
|
|
17
17
|
|
|
@@ -88,7 +88,7 @@ test("public factory runs once and every non-presentation field retains its exac
|
|
|
88
88
|
assert.equal(hooks.length, 1);
|
|
89
89
|
assert.ok(original);
|
|
90
90
|
for (const key of Object.keys(original)) {
|
|
91
|
-
if (["renderCall", "renderResult", "renderShell"].includes(key)) continue;
|
|
91
|
+
if (["renderCall", "renderResult", "renderShell", "promptGuidelines"].includes(key)) continue;
|
|
92
92
|
assert.equal(Reflect.get(tools[0]!, key), Reflect.get(original, key), `${key} must remain upstream-owned`);
|
|
93
93
|
}
|
|
94
94
|
assert.equal(tools[0]!.execute, original.execute);
|
|
@@ -97,6 +97,26 @@ test("public factory runs once and every non-presentation field retains its exac
|
|
|
97
97
|
assert.equal(tools[0]!.exposure, original.exposure);
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
+
test("codemode keeps upstream prompt guidelines first and appends the thin-orchestration rules", async () => {
|
|
101
|
+
const { pi, tools } = registry();
|
|
102
|
+
let original: ToolDefinition | undefined;
|
|
103
|
+
await registerCompactCodemode(pi, (api) => createCodemodeExtension()(new Proxy(api, {
|
|
104
|
+
get(target, property, receiver) {
|
|
105
|
+
if (property === "registerTool") return (tool: ToolDefinition) => { original = tool; api.registerTool(tool); };
|
|
106
|
+
return Reflect.get(target, property, receiver);
|
|
107
|
+
},
|
|
108
|
+
})));
|
|
109
|
+
assert.ok(original);
|
|
110
|
+
const upstream = original.promptGuidelines ?? [];
|
|
111
|
+
assert.ok(upstream.length > 0, "upstream codemode ships its own guideline");
|
|
112
|
+
assert.deepEqual(tools[0]!.promptGuidelines, [...upstream, ...CODEMODE_GUIDELINES]);
|
|
113
|
+
assert.deepEqual(registeredCodemode().promptGuidelines?.slice(-CODEMODE_GUIDELINES.length), [...CODEMODE_GUIDELINES]);
|
|
114
|
+
const rules = CODEMODE_GUIDELINES.join("\n");
|
|
115
|
+
for (const rule of [/one coherent objective/, /Promise\.allSettled\(\)/, /exit_code/, /isError/, /not transactional/, /never repeat a side effect/, /background tools when they are available/, /bounded direct foreground call with an explicit timeout/, /searchTools\(\)/, /describeTool\(\)/, /direct tool call/]) {
|
|
116
|
+
assert.match(rules, rule);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
100
120
|
test("public loadout modes preserve hidden and deferred exposure policy", async () => {
|
|
101
121
|
for (const mode of ["on", "only"] as const) {
|
|
102
122
|
const { pi, tools } = registry();
|
|
@@ -188,6 +188,20 @@ test("ctrl+j and ctrl+k also move the selection", () => {
|
|
|
188
188
|
assert.deepEqual(results, [{ type: "run", name: "gentle:models" }]);
|
|
189
189
|
});
|
|
190
190
|
|
|
191
|
+
test("tab captures the next key for the highlighted command, and esc cancels the capture", () => {
|
|
192
|
+
const results: CommandPaletteResult[] = [];
|
|
193
|
+
const palette = new CommandPalette([{ title: "Session", items: [{ command: "gentle:design", label: "Design" }, { command: "gentle:voice", label: "Voice" }] }], (result) => results.push(result));
|
|
194
|
+
palette.handleInput("\x1b[B");
|
|
195
|
+
palette.handleInput("\t");
|
|
196
|
+
assert.match(palette.render(80).join("\n"), /Press the new key for Voice · esc cancel/);
|
|
197
|
+
palette.handleInput("\x1b");
|
|
198
|
+
assert.deepEqual(results, [], "esc only cancels the capture");
|
|
199
|
+
assert.match(palette.render(80).join("\n"), /tab set key/);
|
|
200
|
+
palette.handleInput("\t");
|
|
201
|
+
palette.handleInput("\x1bv");
|
|
202
|
+
assert.deepEqual(results, [{ type: "bind", name: "gentle:voice", data: "\x1bv" }]);
|
|
203
|
+
});
|
|
204
|
+
|
|
191
205
|
test("enter runs the highlighted item and is a no-op with no match", () => {
|
|
192
206
|
const { palette, results } = createPalette(GROUPS);
|
|
193
207
|
type(palette, "nothing-like-this");
|
|
@@ -296,7 +310,7 @@ test("render escapes control characters in labels and shortcuts", () => {
|
|
|
296
310
|
|
|
297
311
|
test("render footer lists the key bindings", () => {
|
|
298
312
|
const lines = render(GROUPS, "").join("\n");
|
|
299
|
-
assert.match(lines,
|
|
313
|
+
assert.match(lines, /↑\/↓ move • enter run • tab set key • esc close/);
|
|
300
314
|
});
|
|
301
315
|
|
|
302
316
|
test("render keeps the right border aligned when a label has wide characters", () => {
|
|
@@ -373,7 +387,7 @@ test("COMMAND_PALETTE_CATALOG matches the curated command set, in order", () =>
|
|
|
373
387
|
"gentle:telemetry",
|
|
374
388
|
"gentle:dev-binary",
|
|
375
389
|
]);
|
|
376
|
-
assert.deepEqual(byTitle("Session"), ["gentle:yolo", "gentle:changes", "gentle:agents", "gentle:jobs", "gentle:usage", "gentle:review-session-permission", "gentle:voice", "gentle:design"]);
|
|
390
|
+
assert.deepEqual(byTitle("Session"), ["gentle:guide", "gentle:yolo", "gentle:changes", "gentle:agents", "gentle:jobs", "gentle:usage", "gentle:review-session-permission", "gentle:voice", "gentle:design"]);
|
|
377
391
|
assert.deepEqual(byTitle("Diagnostics"), ["gentle:status", "gentle:doctor"]);
|
|
378
392
|
assert.equal(byTitle("SDD"), undefined);
|
|
379
393
|
assert.deepEqual(byTitle("Skills"), ["skill-registry:refresh"]);
|
|
@@ -2,7 +2,7 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import { execFileSync } from "node:child_process";
|
|
3
3
|
import { appendFileSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
|
-
import { join } from "node:path";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
6
|
import test, { type TestContext } from "node:test";
|
|
7
7
|
import { commitSliceReport, commitSliceToolResult, commitTargetDirectory, isGitCommitCommand } from "../lib/commit-slice-signal.ts";
|
|
8
8
|
|
|
@@ -46,19 +46,21 @@ test("isGitCommitCommand counts a git invocation that starts a shell segment, no
|
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
test("commitTargetDirectory follows git -C and a leading cd", () => {
|
|
49
|
-
|
|
50
|
-
assert.equal(commitTargetDirectory("git
|
|
51
|
-
assert.equal(commitTargetDirectory("
|
|
49
|
+
const repo = resolve("/work/repo");
|
|
50
|
+
assert.equal(commitTargetDirectory("git commit -m x", repo), repo);
|
|
51
|
+
assert.equal(commitTargetDirectory("git -C ../other commit -m x", repo), resolve(repo, "../other"));
|
|
52
|
+
assert.equal(commitTargetDirectory("cd /tmp/x && git commit -m x", repo), resolve(repo, "/tmp/x"));
|
|
52
53
|
});
|
|
53
54
|
|
|
54
55
|
// PR #2290 review: only a leading `cd <dir> &&` moved the count, so a commit after
|
|
55
56
|
// `cd <dir>;` or a later `cd` counted the session cwd instead.
|
|
56
57
|
test("commitTargetDirectory follows a cd that precedes the commit through ;, && or ||", () => {
|
|
57
|
-
|
|
58
|
-
assert.equal(commitTargetDirectory("
|
|
59
|
-
assert.equal(commitTargetDirectory("
|
|
60
|
-
assert.equal(commitTargetDirectory("cd
|
|
61
|
-
assert.equal(commitTargetDirectory("
|
|
58
|
+
const repo = resolve("/work/repo");
|
|
59
|
+
assert.equal(commitTargetDirectory("cd /tmp/x; git commit -m x", repo), resolve(repo, "/tmp/x"));
|
|
60
|
+
assert.equal(commitTargetDirectory("git add -A && cd pkg && git commit -m x", repo), resolve(repo, "pkg"));
|
|
61
|
+
assert.equal(commitTargetDirectory("cd /tmp/x || exit 1; git commit -m x", repo), resolve(repo, "/tmp/x"));
|
|
62
|
+
assert.equal(commitTargetDirectory("cd a && cd 'b c'\ngit -C d commit -m x", repo), resolve(repo, "a/b c/d"));
|
|
63
|
+
assert.equal(commitTargetDirectory("git commit -m x && cd /tmp/x", repo), repo, "a cd after the commit does not move it");
|
|
62
64
|
});
|
|
63
65
|
|
|
64
66
|
test("a feature branch reports authored changed lines since the default branch, lock files excluded", async (t) => {
|
|
@@ -38,15 +38,16 @@ test("AC1: the core writer rule fires on named reasons, never on size or file co
|
|
|
38
38
|
for (const clause of [
|
|
39
39
|
"never by file count or a large task alone",
|
|
40
40
|
"`orchestrator-writer.md`",
|
|
41
|
-
"2+ independent units of behavior
|
|
42
|
-
"
|
|
43
|
-
"
|
|
41
|
+
"2+ independent units of behavior",
|
|
42
|
+
"each heavier than a subagent start",
|
|
43
|
+
"several minutes of work: several files or roughly 100+ changed lines",
|
|
44
44
|
"Tests, docs, and code of the same behavior are one unit, never separate writers",
|
|
45
|
-
"a delivery that depends on an earlier one is not independent",
|
|
46
45
|
"Context backstop",
|
|
47
46
|
]) {
|
|
48
47
|
assert.ok(coreWriter.includes(clause), `core Writer rule is missing: ${clause}`);
|
|
49
48
|
}
|
|
49
|
+
assert.match(coreWriter, /(?:a small change to one module or one command is done inline even when several such changes are independent|Small module or command changes stay inline, even when independent)/);
|
|
50
|
+
assert.match(coreWriter, /(?:a delivery that depends on an earlier one is not independent|dependent deliveries are not independent)/);
|
|
50
51
|
assert.ok(!core.includes("large task → one bounded `gentle-ai-worker` per task"), "core keeps the size-based writer rule");
|
|
51
52
|
assert.ok(
|
|
52
53
|
core.includes("large tasks get ODD tracking and workers only by the Writer rule, else inline"),
|
|
@@ -562,9 +562,13 @@ function openEvents(port: number) {
|
|
|
562
562
|
req.on("error", reject);
|
|
563
563
|
});
|
|
564
564
|
req.end();
|
|
565
|
-
|
|
565
|
+
// A waiter that never matches must fail loud, not hang the whole suite:
|
|
566
|
+
// an exhausted inotify limit silently stops the server's change events.
|
|
567
|
+
const waitFor = (pattern: RegExp) => new Promise<RegExpExecArray>((resolve, reject) => {
|
|
568
|
+
const timeout = setTimeout(() => reject(new Error(`events never matched ${pattern} within 5s; got: ${JSON.stringify(buffer.slice(-200))}`)), 5000);
|
|
569
|
+
const settle = (match: RegExpExecArray) => { clearTimeout(timeout); resolve(match); };
|
|
566
570
|
const match = pattern.exec(buffer);
|
|
567
|
-
if (match)
|
|
571
|
+
if (match) settle(match); else waiters.push({ pattern, resolve: settle });
|
|
568
572
|
});
|
|
569
573
|
return { ready, waitFor, req };
|
|
570
574
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { createExplorationBudget } from "../lib/exploration-budget.ts";
|
|
4
|
+
|
|
5
|
+
const event = (id: string, toolName = "read", text = "x", isError = false, input: Record<string, unknown> = {}, details?: unknown) => ({
|
|
6
|
+
toolCallId: id, toolName, isError, input, details, content: [{ type: "text" as const, text }],
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
test("cumulative successful lookups cross at four and notify only once", () => {
|
|
10
|
+
const budget = createExplorationBudget();
|
|
11
|
+
budget.start("s");
|
|
12
|
+
for (let i = 1; i <= 3; i++) {
|
|
13
|
+
budget.call("s", String(i));
|
|
14
|
+
assert.equal(budget.result("s", event(String(i))), undefined);
|
|
15
|
+
}
|
|
16
|
+
budget.call("s", "4");
|
|
17
|
+
const notice = budget.result("s", event("4"));
|
|
18
|
+
assert.match(notice ?? "", /Exploration budget:.*4.*4.*bytes/);
|
|
19
|
+
assert.match(notice ?? "", /one configured explorer/i);
|
|
20
|
+
assert.match(notice ?? "", /read.only.*initially small/i);
|
|
21
|
+
assert.match(notice ?? "", /preparation.*already.understood.*authorized inline write/i);
|
|
22
|
+
assert.match(notice ?? "", /no.*mutation.*guard.*bypass/i);
|
|
23
|
+
budget.call("s", "5");
|
|
24
|
+
assert.equal(budget.result("s", event("5")), undefined);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("UTF-8 text bytes cross strictly above 40000 and duplicate IDs do not count", () => {
|
|
28
|
+
const budget = createExplorationBudget();
|
|
29
|
+
budget.start("s");
|
|
30
|
+
budget.call("s", "1");
|
|
31
|
+
assert.equal(budget.result("s", event("1", "grep", "é".repeat(20000))), undefined);
|
|
32
|
+
assert.equal(budget.result("s", event("1", "grep", "x")), undefined);
|
|
33
|
+
budget.call("s", "2");
|
|
34
|
+
assert.match(budget.result("s", event("2", "find", "x")) ?? "", /40,?001.*bytes/);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("ignore child, aborted, non-discovery, error, stale and duplicate results across requests", () => {
|
|
38
|
+
const budget = createExplorationBudget();
|
|
39
|
+
budget.start("s");
|
|
40
|
+
budget.call("s", "old");
|
|
41
|
+
budget.start("s");
|
|
42
|
+
assert.equal(budget.result("s", event("old")), undefined);
|
|
43
|
+
for (const [id, name, error, primary, aborted] of [
|
|
44
|
+
["child", "read", false, false, false], ["aborted", "read", false, true, true],
|
|
45
|
+
["failed", "read", true, true, false], ["review", "gentle_review", false, true, false],
|
|
46
|
+
["write", "write", false, true, false], ["bash", "bash", false, true, false],
|
|
47
|
+
] as const) {
|
|
48
|
+
budget.call("s", id);
|
|
49
|
+
assert.equal(budget.result("s", event(id, name, "x".repeat(50000), error), primary, aborted), undefined);
|
|
50
|
+
}
|
|
51
|
+
for (const [i, name] of ["read", "grep", "find", "ls"].entries()) {
|
|
52
|
+
budget.call("s", `new${i}`);
|
|
53
|
+
const notice = budget.result("s", event(`new${i}`, name));
|
|
54
|
+
if (i < 3) assert.equal(notice, undefined);
|
|
55
|
+
else assert.match(notice ?? "", /Exploration budget:/);
|
|
56
|
+
}
|
|
57
|
+
budget.settle("s");
|
|
58
|
+
budget.call("s", "late");
|
|
59
|
+
assert.equal(budget.result("s", event("late")), undefined);
|
|
60
|
+
budget.start("s");
|
|
61
|
+
budget.call("s", "fresh");
|
|
62
|
+
assert.equal(budget.result("s", event("fresh")), undefined);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("known shell inspections reuse phase inference without counting checks, writes or unknown scripts", () => {
|
|
66
|
+
const budget = createExplorationBudget();
|
|
67
|
+
budget.start("s");
|
|
68
|
+
for (const command of ["node --test example.test.ts", "pnpm build", "cat src/a > out", "unknown-script arg"]) {
|
|
69
|
+
budget.call("s", command, "bash");
|
|
70
|
+
assert.equal(budget.result("s", event(command, "bash", "x".repeat(50000), false, { command })), undefined);
|
|
71
|
+
}
|
|
72
|
+
for (const [i, [name, command]] of [["bash", "pwd"], ["bash", "cd src && rg needle ."], ["bash", "git status"], ["powershell", "git diff"]].entries()) {
|
|
73
|
+
budget.call("s", String(i), name);
|
|
74
|
+
const notice = budget.result("s", event(String(i), name, "x", false, { command }));
|
|
75
|
+
if (i < 3) assert.equal(notice, undefined);
|
|
76
|
+
else assert.match(notice ?? "", /Exploration budget:.*4 tracked lookups.*4 UTF-8/);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("read-only memory recall counts and memory mutation or diagnostics never count", () => {
|
|
81
|
+
const budget = createExplorationBudget();
|
|
82
|
+
budget.start("s");
|
|
83
|
+
for (const name of ["mem_current_project", "mem_stats", "mem_save", "mem_update", "mem_review"]) {
|
|
84
|
+
budget.call("s", name);
|
|
85
|
+
assert.equal(budget.result("s", event(name, name, "x".repeat(50000))), undefined);
|
|
86
|
+
}
|
|
87
|
+
for (const [i, name] of ["mem_search", "mem_get_observation", "mem_context", "read"].entries()) {
|
|
88
|
+
budget.call("s", name);
|
|
89
|
+
const notice = budget.result("s", event(name, name));
|
|
90
|
+
if (i < 3) assert.equal(notice, undefined);
|
|
91
|
+
else assert.match(notice ?? "", /Exploration budget:.*4 tracked lookups/);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("nested reads inside review, mutation or verification are not discovery", () => {
|
|
96
|
+
const budget = createExplorationBudget();
|
|
97
|
+
budget.start("s");
|
|
98
|
+
for (const [i, name] of ["gentle_review", "write", "verification"].entries()) {
|
|
99
|
+
const parent = `p${i}`;
|
|
100
|
+
budget.call("s", parent, name);
|
|
101
|
+
budget.call("s", `${parent}/1`, "read", parent);
|
|
102
|
+
assert.equal(budget.result("s", { ...event(`${parent}/1`, "read", "x".repeat(50000)), parentToolCallId: parent }), undefined);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("codegraph query and explore count but init and failed fallbacks do not", () => {
|
|
107
|
+
const budget = createExplorationBudget();
|
|
108
|
+
budget.start("s");
|
|
109
|
+
for (const [id, input, details] of [
|
|
110
|
+
["init", { operation: "init" }, undefined],
|
|
111
|
+
["failed", { operation: "query" }, { status: "failed" }],
|
|
112
|
+
["unavailable", { operation: "explore" }, { status: "unavailable" }],
|
|
113
|
+
] as const) {
|
|
114
|
+
budget.call("s", id);
|
|
115
|
+
assert.equal(budget.result("s", event(id, "codegraph", "x".repeat(50000), false, input, details)), undefined);
|
|
116
|
+
}
|
|
117
|
+
const calls = [
|
|
118
|
+
event("1", "codegraph", "x", false, { operation: "query" }),
|
|
119
|
+
event("2", "codegraph", "x", false, { operation: "explore" }),
|
|
120
|
+
event("3", "codegraph_query"), event("4", "codegraph_explore"),
|
|
121
|
+
];
|
|
122
|
+
for (const [i, item] of calls.entries()) {
|
|
123
|
+
budget.call("s", item.toolCallId);
|
|
124
|
+
const result = budget.result("s", item);
|
|
125
|
+
if (i === 3) assert.match(result ?? "", /Exploration budget:/);
|
|
126
|
+
else assert.equal(result, undefined);
|
|
127
|
+
}
|
|
128
|
+
});
|