gentle-pi 4.5.1 → 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-shell.md +69 -19
- 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 +79 -20
- 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 +1041 -188
- 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-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/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 +1007 -33
- 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-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 +20 -1
- 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,83 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { TERMINAL_ERROR_CATEGORY as C } from "../lib/agents-protocol.ts";
|
|
4
|
+
import { COOLDOWN_MS, ModelCooldown, pickModel, sharedCooldown, shouldFallBack, syncUsageCooldown } from "../lib/model-fallback-policy.ts";
|
|
5
|
+
|
|
6
|
+
test("only quota, auth and spent transient errors move a run to its next model", () => {
|
|
7
|
+
for (const category of [C.QUOTA, C.AUTH, C.RATE_LIMIT, C.PROVIDER_UNAVAILABLE, C.TIMEOUT, C.NETWORK]) assert.equal(shouldFallBack(category), true, category);
|
|
8
|
+
for (const category of [C.CONTEXT_LENGTH, C.INVALID_REQUEST, C.UNAVAILABLE, undefined]) assert.equal(shouldFallBack(category), false, String(category));
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("a model that ran out cools down for every agent; exhausted limits wait longer than transient ones", () => {
|
|
12
|
+
const cooldown = new ModelCooldown();
|
|
13
|
+
cooldown.mark("anthropic/opus", C.QUOTA, 1_000);
|
|
14
|
+
cooldown.mark("openai/gpt", C.RATE_LIMIT, 1_000);
|
|
15
|
+
assert.equal(cooldown.available("anthropic/opus", 1_000 + COOLDOWN_MS.exhausted - 1), false);
|
|
16
|
+
assert.equal(cooldown.available("anthropic/opus", 1_000 + COOLDOWN_MS.exhausted), true);
|
|
17
|
+
assert.equal(cooldown.available("openai/gpt", 1_000 + COOLDOWN_MS.transient), true);
|
|
18
|
+
assert.ok(COOLDOWN_MS.exhausted > COOLDOWN_MS.transient);
|
|
19
|
+
assert.equal(cooldown.available("never/marked", 0), true);
|
|
20
|
+
cooldown.mark("anthropic/opus", C.CONTEXT_LENGTH, 99_999_999);
|
|
21
|
+
assert.equal(cooldown.available("anthropic/opus", 1_000 + COOLDOWN_MS.exhausted), true, "errors that never fall back never cool a model down");
|
|
22
|
+
assert.equal(sharedCooldown(), sharedCooldown(), "one registry per process, shared by the shell and the agents");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("pickModel keeps the primary while it works, then walks the chain skipping tried and cooled models", () => {
|
|
26
|
+
const cooldown = new ModelCooldown();
|
|
27
|
+
const chain = [{ model: "openai/gpt-5.5", thinking: "high" as const }, { model: "qwen/qwen3.8" }];
|
|
28
|
+
assert.deepEqual(pickModel("anthropic/opus", chain, { cooldown, now: 0 }), { model: "anthropic/opus", fallback: false });
|
|
29
|
+
cooldown.mark("anthropic/opus", C.QUOTA, 0);
|
|
30
|
+
assert.deepEqual(pickModel("anthropic/opus", chain, { cooldown, now: 1 }), { model: "openai/gpt-5.5", thinking: "high", fallback: true }, "a cooled primary starts on the first fallback");
|
|
31
|
+
assert.deepEqual(pickModel("anthropic/opus", chain, { cooldown, now: 1, tried: new Set(["openai/gpt-5.5"]) }), { model: "qwen/qwen3.8", fallback: true });
|
|
32
|
+
cooldown.mark("qwen/qwen3.8", C.NETWORK, 1);
|
|
33
|
+
assert.equal(pickModel("anthropic/opus", chain, { cooldown, now: 2, tried: new Set(["openai/gpt-5.5"]) }), undefined, "nothing left");
|
|
34
|
+
assert.deepEqual(pickModel(undefined, chain, { cooldown: new ModelCooldown(), now: 0 }), { model: undefined, fallback: false }, "an inheriting agent keeps inheriting while it works");
|
|
35
|
+
assert.deepEqual(pickModel("anthropic/opus", chain, { cooldown: new ModelCooldown(), now: 0, tried: new Set(["anthropic/opus"]) }), { model: "openai/gpt-5.5", thinking: "high", fallback: true }, "a primary that just failed is tried");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("a full /gentle:usage window cools a whole provider until it resets, and a later fetch with room releases it", () => {
|
|
39
|
+
const cooldown = new ModelCooldown();
|
|
40
|
+
const window = (usedPercent: number, resetAt: number | null) => ({ label: "5h", usedPercent, windowSeconds: 18_000, resetAt });
|
|
41
|
+
syncUsageCooldown({ provider: "anthropic", limits: [{ name: "plan", limitReached: false, windows: [window(100, 50_000), window(40, 90_000)] }] }, cooldown, 1_000);
|
|
42
|
+
assert.equal(cooldown.available("anthropic/claude-opus-5-5", 49_999), false, "every model of the provider waits");
|
|
43
|
+
assert.equal(cooldown.reason("anthropic/claude-sonnet-5-5", 2_000), C.QUOTA);
|
|
44
|
+
assert.equal(cooldown.available("anthropic/claude-opus-5-5", 50_000), true, "until the full window resets");
|
|
45
|
+
assert.equal(cooldown.available("openai/gpt-5.5", 2_000), true, "other providers are untouched");
|
|
46
|
+
syncUsageCooldown({ provider: "openai", limits: [{ name: "plan", limitReached: true, windows: [window(80, null)] }] }, cooldown, 1_000);
|
|
47
|
+
assert.equal(cooldown.available("openai/gpt-5.5", 1_000 + COOLDOWN_MS.exhausted - 1), false, "a reached limit without a reset time waits the usual time");
|
|
48
|
+
syncUsageCooldown({ provider: "openai", limits: [{ name: "plan", limitReached: false, windows: [window(10, null)] }] }, cooldown, 2_000);
|
|
49
|
+
assert.equal(cooldown.available("openai/gpt-5.5", 2_000), true, "room again releases the provider");
|
|
50
|
+
cooldown.mark("openai/gpt-5.5", C.QUOTA, 2_000);
|
|
51
|
+
syncUsageCooldown({ provider: "openai", limits: [] }, cooldown, 3_000);
|
|
52
|
+
assert.equal(cooldown.available("openai/gpt-5.5", 3_000), false, "usage never clears a model's own failure");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("a provider that reports one limit per model only cools the exhausted model; the provider waits only when every limit is spent", () => {
|
|
56
|
+
const cooldown = new ModelCooldown();
|
|
57
|
+
const limit = (name: string, usedPercent: number, reached: boolean, resetAt: number | null) => ({ name, limitReached: reached, windows: [{ usedPercent, resetAt }] });
|
|
58
|
+
syncUsageCooldown({ provider: "nan", limits: [limit("glm5.2", 100, true, 90_000), limit("deepseek-v4-flash", 10, false, 90_000)] }, cooldown, 1_000);
|
|
59
|
+
assert.equal(cooldown.available("nan/glm5.2", 2_000), false, "the spent model waits");
|
|
60
|
+
assert.equal(cooldown.available("nan/deepseek-v4-flash", 2_000), true, "its siblings keep working");
|
|
61
|
+
assert.equal(cooldown.available("nan/glm5.2", 90_000), true, "until its own window resets");
|
|
62
|
+
syncUsageCooldown({ provider: "nan", limits: [limit("glm5.2", 100, true, 50_000), limit("deepseek-v4-flash", 100, true, 60_000)] }, cooldown, 1_000);
|
|
63
|
+
assert.equal(cooldown.available("nan/other", 49_999), false, "every limit spent: the whole provider waits");
|
|
64
|
+
assert.equal(cooldown.available("nan/other", 50_000), true, "until the earliest reset");
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("a full window whose reset already passed is a stale reading and blocks nothing", () => {
|
|
68
|
+
const cooldown = new ModelCooldown();
|
|
69
|
+
syncUsageCooldown({ provider: "anthropic", limits: [{ name: "plan", limitReached: false, windows: [{ usedPercent: 100, resetAt: 500 }] }] }, cooldown, 1_000);
|
|
70
|
+
assert.equal(cooldown.available("anthropic/claude-opus-5-5", 1_000), true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("a spent provider-wide limit (Codex's main one) skips every model; an extra limit's display name is matched as a model id", () => {
|
|
74
|
+
const cooldown = new ModelCooldown();
|
|
75
|
+
const window = (usedPercent: number, resetAt: number | null) => ({ usedPercent, resetAt });
|
|
76
|
+
syncUsageCooldown({ provider: "openai-codex", limits: [{ name: "codex", scope: "provider", limitReached: true, windows: [window(100, 80_000)] }, { name: "codex_spark", limitReached: false, windows: [window(10, 80_000)] }] }, cooldown, 1_000);
|
|
77
|
+
assert.equal(cooldown.available("openai-codex/gpt-5.5", 2_000), false, "the main limit holds every model");
|
|
78
|
+
assert.equal(cooldown.available("openai-codex/gpt-5.5", 80_000), true);
|
|
79
|
+
const extras = new ModelCooldown();
|
|
80
|
+
syncUsageCooldown({ provider: "openai-codex", limits: [{ name: "codex", scope: "provider", limitReached: false, windows: [window(40, 80_000)] }, { name: "GPT-5.3 Codex_Spark", limitReached: true, windows: [window(100, 90_000)] }] }, extras, 1_000);
|
|
81
|
+
assert.equal(extras.available("openai-codex/gpt-5.3-codex-spark", 2_000), false, "display names are matched in id form");
|
|
82
|
+
assert.equal(extras.available("openai-codex/gpt-5.5", 2_000), true);
|
|
83
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_CHAIN_KEY,
|
|
8
|
+
FALLBACKS_KIND,
|
|
9
|
+
chainFor,
|
|
10
|
+
emptyFallbacksFile,
|
|
11
|
+
fallbacksFilePath,
|
|
12
|
+
followProfileRename,
|
|
13
|
+
parseFallbacksFileText,
|
|
14
|
+
readFallbacksFile,
|
|
15
|
+
renameProfileFallbacks,
|
|
16
|
+
setChain,
|
|
17
|
+
writeFallbacksFile,
|
|
18
|
+
} from "../lib/model-fallback-store.ts";
|
|
19
|
+
|
|
20
|
+
const valid = {
|
|
21
|
+
kind: FALLBACKS_KIND,
|
|
22
|
+
version: 1,
|
|
23
|
+
profiles: {
|
|
24
|
+
work: {
|
|
25
|
+
orchestrator: [{ model: "openai/gpt-5.5", thinking: "high" }, { model: "qwen/qwen3.8" }],
|
|
26
|
+
"*": [{ model: "anthropic/claude-sonnet-5-5" }],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
test("chains live next to profiles.json in their own file", () => {
|
|
32
|
+
assert.equal(fallbacksFilePath("/cfg"), join("/cfg", "profile-fallbacks.json"));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("an agent's chain is its own, or the profile's * chain, or none", () => {
|
|
36
|
+
const file = parseFallbacksFileText(JSON.stringify(valid));
|
|
37
|
+
assert.equal(file.status, "valid");
|
|
38
|
+
if (file.status !== "valid") return;
|
|
39
|
+
assert.deepEqual(chainFor(file.file, "work", "orchestrator"), [{ model: "openai/gpt-5.5", thinking: "high" }, { model: "qwen/qwen3.8" }]);
|
|
40
|
+
assert.deepEqual(chainFor(file.file, "work", "explore"), [{ model: "anthropic/claude-sonnet-5-5" }], "agents without a chain use *");
|
|
41
|
+
assert.deepEqual(chainFor(file.file, "other", "explore"), [], "a profile without chains has none");
|
|
42
|
+
assert.deepEqual(chainFor(file.file, undefined, "explore"), [], "no active profile, no chain");
|
|
43
|
+
assert.equal(DEFAULT_CHAIN_KEY, "*");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("the reader is strict: unknown keys, unsafe ids, bad effort, duplicates or long chains reject the file", () => {
|
|
47
|
+
const bad = (patch: (value: typeof valid) => unknown) => parseFallbacksFileText(JSON.stringify(patch(structuredClone(valid)))).status;
|
|
48
|
+
assert.equal(parseFallbacksFileText("{").status, "invalid");
|
|
49
|
+
assert.equal(bad((v) => ({ ...v, kind: "other" })), "invalid");
|
|
50
|
+
assert.equal(bad((v) => ({ ...v, version: 2 })), "invalid");
|
|
51
|
+
assert.equal(bad((v) => ({ ...v, extra: 1 })), "invalid");
|
|
52
|
+
assert.equal(bad((v) => { (v.profiles.work as Record<string, unknown>)["bad agent!"] = []; return v; }), "invalid");
|
|
53
|
+
assert.equal(bad((v) => { v.profiles.work.orchestrator[0]!.model = "bad model"; return v; }), "invalid");
|
|
54
|
+
assert.equal(bad((v) => { (v.profiles.work.orchestrator[0] as Record<string, unknown>).thinking = "ultra"; return v; }), "invalid");
|
|
55
|
+
assert.equal(bad((v) => { (v.profiles.work.orchestrator[0] as Record<string, unknown>).extra = true; return v; }), "invalid");
|
|
56
|
+
assert.equal(bad((v) => { v.profiles.work.orchestrator.push({ model: "openai/gpt-5.5" }); return v; }), "invalid", "a model appears once per chain");
|
|
57
|
+
assert.equal(bad((v) => { v.profiles.work["*"] = Array.from({ length: 9 }, (_, i) => ({ model: `m/${i}` })); return v; }), "invalid", "at most 8 fallbacks");
|
|
58
|
+
assert.equal(bad((v) => { (v.profiles as Record<string, unknown>)["bad name!"] = {}; return v; }), "invalid");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("chains are written atomically, read back, and an empty chain removes the entry", () => {
|
|
62
|
+
const home = mkdtempSync(join(tmpdir(), "fallbacks-"));
|
|
63
|
+
try {
|
|
64
|
+
const path = fallbacksFilePath(home);
|
|
65
|
+
assert.equal(readFallbacksFile(path).status, "missing");
|
|
66
|
+
let file = setChain(emptyFallbacksFile(), "work", "orchestrator", [{ model: "openai/gpt-5.5" }]);
|
|
67
|
+
file = setChain(file, "work", "*", [{ model: "qwen/qwen3.8", thinking: "medium" }]);
|
|
68
|
+
writeFallbacksFile(path, file);
|
|
69
|
+
const read = readFallbacksFile(path);
|
|
70
|
+
assert.equal(read.status, "valid");
|
|
71
|
+
if (read.status !== "valid") return;
|
|
72
|
+
assert.deepEqual(read.file, file);
|
|
73
|
+
const cleared = setChain(setChain(read.file, "work", "orchestrator", []), "work", "*", []);
|
|
74
|
+
assert.deepEqual(cleared.profiles, {}, "a profile with no chains disappears");
|
|
75
|
+
assert.throws(() => setChain(file, "work", "orchestrator", [{ model: "a/b" }, { model: "a/b" }]), /once/);
|
|
76
|
+
writeFileSync(path, "{ broken");
|
|
77
|
+
assert.equal(readFallbacksFile(path).status, "invalid");
|
|
78
|
+
assert.equal(readFileSync(path, "utf8"), "{ broken", "reading never rewrites a broken file");
|
|
79
|
+
} finally {
|
|
80
|
+
rmSync(home, { recursive: true, force: true });
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("renaming or deleting a profile carries or drops its chains", () => {
|
|
85
|
+
const parsed = parseFallbacksFileText(JSON.stringify(valid));
|
|
86
|
+
if (parsed.status !== "valid") throw new Error("fixture");
|
|
87
|
+
const renamed = renameProfileFallbacks(parsed.file, "work", "job");
|
|
88
|
+
assert.deepEqual(Object.keys(renamed.profiles), ["job"]);
|
|
89
|
+
assert.deepEqual(renameProfileFallbacks(parsed.file, "work", undefined).profiles, {}, "a deleted profile loses its chains");
|
|
90
|
+
assert.equal(renameProfileFallbacks(parsed.file, "missing", "x"), parsed.file);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("followProfileRename moves or drops a profile's chains on disk and leaves a broken file alone", () => {
|
|
94
|
+
const home = mkdtempSync(join(tmpdir(), "fallbacks-follow-"));
|
|
95
|
+
try {
|
|
96
|
+
const path = fallbacksFilePath(home);
|
|
97
|
+
assert.equal(followProfileRename(home, "work", "job"), false, "no file, nothing to follow");
|
|
98
|
+
writeFallbacksFile(path, setChain(emptyFallbacksFile(), "work", "*", [{ model: "a/b" }]));
|
|
99
|
+
assert.equal(followProfileRename(home, "work", "job"), true);
|
|
100
|
+
const moved = readFallbacksFile(path);
|
|
101
|
+
assert.deepEqual(moved.status === "valid" && Object.keys(moved.file.profiles), ["job"]);
|
|
102
|
+
assert.equal(followProfileRename(home, "job", undefined), true);
|
|
103
|
+
const dropped = readFallbacksFile(path);
|
|
104
|
+
assert.deepEqual(dropped.status === "valid" && dropped.file.profiles, {});
|
|
105
|
+
writeFileSync(path, "{ broken");
|
|
106
|
+
assert.equal(followProfileRename(home, "job", "x"), false);
|
|
107
|
+
assert.equal(readFileSync(path, "utf8"), "{ broken");
|
|
108
|
+
} finally {
|
|
109
|
+
rmSync(home, { recursive: true, force: true });
|
|
110
|
+
}
|
|
111
|
+
});
|
|
@@ -192,7 +192,7 @@ test("initial catalog contains all seven documented chat models with configured
|
|
|
192
192
|
assert.deepEqual(model?.input, ["text", "image"]);
|
|
193
193
|
assert.equal(model?.contextWindow, 1_000_000);
|
|
194
194
|
assert.equal(models.length, 7);
|
|
195
|
-
assert.equal(model?.maxTokens,
|
|
195
|
+
assert.equal(model?.maxTokens, 131_072);
|
|
196
196
|
assert.deepEqual(model?.cost, { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 });
|
|
197
197
|
});
|
|
198
198
|
|
|
@@ -211,10 +211,10 @@ test("only NaN DeepSeek serializes its unchanged output cap as max_tokens", asyn
|
|
|
211
211
|
},
|
|
212
212
|
});
|
|
213
213
|
assert.equal(result.stopReason, "stop");
|
|
214
|
-
assert.equal(body?.max_tokens,
|
|
214
|
+
assert.equal(body?.max_tokens, 131_072);
|
|
215
215
|
assert.ok(!Object.hasOwn(body!, "max_completion_tokens"));
|
|
216
216
|
assert.equal(body?.reasoning_effort, "minimal");
|
|
217
|
-
assert.equal(model.maxTokens,
|
|
217
|
+
assert.equal(model.maxTokens, 131_072);
|
|
218
218
|
assert.equal(model.compat?.maxTokensField, "max_tokens");
|
|
219
219
|
assert.ok(models.filter((candidate) => candidate.id !== model.id).every((candidate) => candidate.compat === undefined));
|
|
220
220
|
});
|
|
@@ -347,7 +347,7 @@ test("live discovery uses the key-scoped endpoint and replaces the fallback with
|
|
|
347
347
|
test("known chat models retain documented capabilities without advertising audio", async () => {
|
|
348
348
|
const expected = [
|
|
349
349
|
["glm5.3", 1_000_000, ["text", "image"], 32_768],
|
|
350
|
-
["deepseek-v4-flash", 1_000_000, ["text", "image"],
|
|
350
|
+
["deepseek-v4-flash", 1_000_000, ["text", "image"], 131_072],
|
|
351
351
|
["glm5.3-flash", 1_000_000, ["text", "image"], 32_768],
|
|
352
352
|
["qwen3.8-flash", 1_048_576, ["text", "image"], 131_000],
|
|
353
353
|
["mimo-v2.6-flash", 1_000_000, ["text", "image"], 32_768],
|
|
@@ -16,6 +16,25 @@ const read = (relative: string): string => readFileSync(join(REPO_ROOT, relative
|
|
|
16
16
|
const tracking = read("assets/orchestrator-tracking.md");
|
|
17
17
|
const core = read("assets/orchestrator.md");
|
|
18
18
|
|
|
19
|
+
const contextualApproval = 'Interpret short replies such as "yes", "go ahead", or "eso mismo" against the immediately preceding proposal. When the human unambiguously accepts a concrete implementation action they already understand, execute that action within its agreed scope without asking again. Confirming a preference alone does not authorize implementation; genuinely unclear change intent still requires one focused question. Contextual approval never substitutes for provider-owned consent, exact-token authorization, or separate publishing and destructive-action permission.';
|
|
20
|
+
const informedClarification = 'Clarify scope, constraints, acceptance criteria, and non-goals when needed for the human to understand the action or to resolve consequential uncertainty. Reuse what is already established; after informed approval, proceed without repeating the clarification unless new consequential uncertainty appears.';
|
|
21
|
+
|
|
22
|
+
test("contextual approval continues the agreed action without weakening consent boundaries", () => {
|
|
23
|
+
assert.ok(__testing.buildGentlePrompt("gentleman").includes(contextualApproval));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("clarification preserves understanding without reopening informed approval", () => {
|
|
27
|
+
assert.ok(__testing.buildGentlePrompt("gentleman").includes(informedClarification));
|
|
28
|
+
assert.ok(read("skills/gentle-ai/SKILL.md").includes(informedClarification));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("resolved subdecisions retain the original authorized objective", () => {
|
|
32
|
+
const prompt = __testing.buildGentlePrompt("gentleman");
|
|
33
|
+
assert.ok(prompt.includes("Resolving an incident or subdecision does not complete or cancel the original authorized objective; resume safe, necessary in-scope steps automatically, using judgment for proportionate recovery and respecting explicit user dispositions. Investigate pending technical uncertainty rather than treating it alone as a new human decision."));
|
|
34
|
+
assert.ok(prompt.includes("Stop only for an unresolved consequential scope/product decision, required explicit consent, a denied action, unavailable required proof, or the human's explicit stop."));
|
|
35
|
+
assert.ok(prompt.includes("Do not infer permission for publishing, destructive actions, unrelated scope or native consent from this continuity rule."));
|
|
36
|
+
});
|
|
37
|
+
|
|
19
38
|
function authorizationSection(): string {
|
|
20
39
|
const start = tracking.indexOf("#### Authorization and progress");
|
|
21
40
|
assert.ok(start !== -1, "tracking module must keep its Authorization and progress section");
|
|
@@ -60,8 +60,8 @@ function harness(options: { malformed?: boolean; failWrite?: boolean; events?: P
|
|
|
60
60
|
rows: () => buildNotificationRows(ctx) };
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function findRow(rows: CustomizeRow[], label: string | RegExp): CustomizeRow {
|
|
64
|
-
const found = rows.find(row => { const text = typeof row.label === "function" ? row.label() : row.label; return typeof label === "string" ? text.startsWith(label) : label.test(text); });
|
|
63
|
+
function findRow(rows: CustomizeRow[], label: string | RegExp, value?: string): CustomizeRow {
|
|
64
|
+
const found = rows.find(row => { const text = typeof row.label === "function" ? row.label() : row.label; return (value === undefined || row.choice?.value === value) && (typeof label === "string" ? text.startsWith(label) : label.test(text)); });
|
|
65
65
|
assert.ok(found, `missing row ${label}`);
|
|
66
66
|
return found!;
|
|
67
67
|
}
|
|
@@ -70,21 +70,23 @@ function findRow(rows: CustomizeRow[], label: string | RegExp): CustomizeRow {
|
|
|
70
70
|
function isVisible(row: CustomizeRow): boolean {
|
|
71
71
|
try { return (row as CustomizeRow & { visible?: () => boolean }).visible?.() !== false; } catch { return false; }
|
|
72
72
|
}
|
|
73
|
-
function visibleRows(rows: CustomizeRow[]): CustomizeRow[] {
|
|
73
|
+
function visibleRows(rows: CustomizeRow[]): CustomizeRow[] {
|
|
74
|
+
return rows.filter(isVisible).filter((row, i, shown) => !row.choice || row.choice.setting !== shown[i - 1]?.choice?.setting);
|
|
75
|
+
}
|
|
74
76
|
function keyhintOf(row: CustomizeRow): string { return (row as CustomizeRow & { keyhint?: string }).keyhint ?? ""; }
|
|
75
77
|
|
|
76
78
|
function fakeInline(inputs: (string | undefined)[] = [], confirms: boolean[] = []): CustomizeInline {
|
|
77
|
-
return { input: async () => inputs.shift(), confirm: async () => confirms.shift() ?? false, disposed: false };
|
|
79
|
+
return { input: async () => inputs.shift(), capture: async () => undefined, confirm: async () => confirms.shift() ?? false, disposed: false };
|
|
78
80
|
}
|
|
79
81
|
function label(row: CustomizeRow): string { return typeof row.label === "function" ? row.label() : row.label; }
|
|
80
82
|
|
|
81
83
|
test("Notifications rows toggle and mute directly without any nested native dialog", async () => {
|
|
82
84
|
const h = harness(); try {
|
|
83
85
|
const rows = h.rows();
|
|
84
|
-
await findRow(rows, "Audio notifications: off").action(fakeInline());
|
|
86
|
+
await findRow(rows, "Audio notifications: off", "on").action(fakeInline());
|
|
85
87
|
assert.equal(getNotificationService()!.getState().settings.enabled, true);
|
|
86
88
|
assert.equal(h.writes, 1);
|
|
87
|
-
await findRow(rows, "Audio: unmuted").action(fakeInline());
|
|
89
|
+
await findRow(rows, "Audio: unmuted", "on").action(fakeInline());
|
|
88
90
|
assert.equal(getNotificationService()!.getState().muted, true);
|
|
89
91
|
assert.equal(h.writes, 1, "mute persists in-process without writing configuration");
|
|
90
92
|
assert.deepEqual(h.nested, { select: 0, input: 0, confirm: 0 });
|
|
@@ -101,10 +103,10 @@ test("labels and previews never probe, play or write and the card exposes no ava
|
|
|
101
103
|
} finally { h.owner.retire(); }
|
|
102
104
|
});
|
|
103
105
|
|
|
104
|
-
test("event rows
|
|
106
|
+
test("event rows apply explicit choices independently and p tests the selected sound without writing", async () => {
|
|
105
107
|
const h = harness(); try {
|
|
106
108
|
const rows = h.rows();
|
|
107
|
-
const failed = findRow(rows, "agent.failed:");
|
|
109
|
+
const failed = findRow(rows, "agent.failed:", "attention tone");
|
|
108
110
|
assert.match(label(failed), /builtin:error/);
|
|
109
111
|
await failed.action(fakeInline());
|
|
110
112
|
assert.equal(getNotificationService()!.getState().settings.audio.events["agent.failed"], "builtin:attention");
|
|
@@ -157,7 +159,7 @@ test("malformed configuration needs fresh strict consent per attempt; a failed w
|
|
|
157
159
|
for (const failWrite of [false, true]) {
|
|
158
160
|
const h = harness({ malformed: true, failWrite }); try {
|
|
159
161
|
const rows = h.rows();
|
|
160
|
-
const enable = findRow(rows, "Audio notifications:");
|
|
162
|
+
const enable = findRow(rows, "Audio notifications:", "on");
|
|
161
163
|
await enable.action(fakeInline([], [false]));
|
|
162
164
|
assert.equal(h.writes, 0, "cancel preserves the file and settings");
|
|
163
165
|
assert.equal(getNotificationService()!.getState().malformed, true);
|
|
@@ -200,25 +202,45 @@ function customizeView(rows: CustomizeRow[], onClose: () => void = () => {}) {
|
|
|
200
202
|
profiles: { list: () => [], save: () => {}, apply: () => {}, delete: () => {}, reset: () => {} } });
|
|
201
203
|
}
|
|
202
204
|
|
|
203
|
-
/**
|
|
205
|
+
/** Focus a row's inline setting without applying its highlighted value. */
|
|
204
206
|
function selectControl(view: VisualCustomizeView, prefix: string): void {
|
|
207
|
+
assert.ok(view.focus(prefix), `could not select a control labelled ${prefix}`);
|
|
205
208
|
view.render(76);
|
|
206
|
-
view.handleInput("\x1b[C");
|
|
207
|
-
for (let i = 0; i < 60; i++) {
|
|
208
|
-
if (view.render(76).join("\n").includes(`\u25b8 ${prefix}`)) return;
|
|
209
|
-
view.handleInput("\x1b[B");
|
|
210
|
-
}
|
|
211
|
-
assert.fail(`could not select a control labelled ${prefix}`);
|
|
212
209
|
}
|
|
213
210
|
|
|
214
211
|
/** Detailed event rows are folded by default: expand Advanced inside the same card, then select. */
|
|
215
212
|
async function expandAndSelect(view: VisualCustomizeView, prefix: string): Promise<void> {
|
|
216
213
|
selectControl(view, "Advanced");
|
|
214
|
+
view.handleInput("\x1b[C");
|
|
217
215
|
view.handleInput("\r");
|
|
218
216
|
await tick();
|
|
219
217
|
selectControl(view, prefix);
|
|
220
218
|
}
|
|
221
219
|
|
|
220
|
+
test("browsing notification choices neither saves nor opens a file or recovery prompt", async () => {
|
|
221
|
+
const h = harness();
|
|
222
|
+
try {
|
|
223
|
+
const before = structuredClone(getNotificationService()!.getState().settings);
|
|
224
|
+
const view = customizeView(h.rows());
|
|
225
|
+
for (const prefix of ["Audio notifications:", "Audio:", "Success:", "Advanced:"]) {
|
|
226
|
+
selectControl(view, prefix);
|
|
227
|
+
for (let i = 0; i < 4; i++) { view.handleInput("\x1b[C"); view.render(160); }
|
|
228
|
+
assert.doesNotMatch(view.render(160).join("\n"), /Local audio path|Replace malformed/);
|
|
229
|
+
}
|
|
230
|
+
assert.equal(h.writes, 0); assert.equal(h.probes, 0); assert.equal(h.played, 0);
|
|
231
|
+
assert.deepEqual(getNotificationService()!.getState().settings, before);
|
|
232
|
+
assert.deepEqual(h.nested, { select: 0, input: 0, confirm: 0 });
|
|
233
|
+
selectControl(view, "Success:");
|
|
234
|
+
for (let i = 0; i < 4; i++) view.handleInput("\x1b[C");
|
|
235
|
+
view.handleInput("\r");
|
|
236
|
+
assert.match(view.render(160).join("\n"), /Local audio path/);
|
|
237
|
+
view.handleInput("\x1b"); await tick(); await tick();
|
|
238
|
+
assert.equal(h.writes, 0);
|
|
239
|
+
assert.deepEqual(getNotificationService()!.getState().settings, before, "cancel preserves preferences");
|
|
240
|
+
view.dispose();
|
|
241
|
+
} finally { h.owner.retire(); }
|
|
242
|
+
});
|
|
243
|
+
|
|
222
244
|
test("an in-flight local sound validation keeps busy, blocking a second field and any write until it settles", async () => {
|
|
223
245
|
const h = harness(); try {
|
|
224
246
|
const rows = h.rows();
|
|
@@ -313,14 +335,14 @@ test("event rows cover supported events and never expose session.shutdown", () =
|
|
|
313
335
|
test("p on every basic non-event notification control stays on the audio card, opens no profiles and never previews", () => {
|
|
314
336
|
const h = harness(); try {
|
|
315
337
|
const rows = h.rows();
|
|
316
|
-
const targets = ["Audio notifications:", "Audio: unmuted", "Advanced"];
|
|
338
|
+
const targets = [["Audio notifications:", "Enabled"], ["Audio: unmuted", "Mute"], ["Advanced", "Advanced"]];
|
|
317
339
|
const listed: number[] = [];
|
|
318
340
|
const view = new VisualCustomizeView({ rows, theme: { fg: (_role: string, text: string) => text }, rowsAvailable: () => 24, requestRender: () => {}, onClose: () => {}, profiles: {
|
|
319
341
|
list: () => { listed.push(1); return []; }, save: () => {}, apply: () => {}, delete: () => {}, reset: () => {},
|
|
320
342
|
} });
|
|
321
|
-
for (const [i, target] of targets.entries()) {
|
|
343
|
+
for (const [i, [target, setting]] of targets.entries()) {
|
|
322
344
|
selectControl(view, target);
|
|
323
|
-
assert.ok(view.render(76).join("\n").includes(`\u25b8 ${
|
|
345
|
+
assert.ok(view.render(76).join("\n").includes(`\u25b8 ${setting} `), `non-event row ${i} (${target}) must be the selected control`);
|
|
324
346
|
view.handleInput("p");
|
|
325
347
|
const frame = view.render(76).join("\n");
|
|
326
348
|
assert.equal(view.title(), "Audio notifications", `non-event row ${i} must keep the audio header`);
|
|
@@ -351,15 +373,15 @@ test("the basic card exposes exactly six human controls and an Advanced toggle w
|
|
|
351
373
|
} finally { h.owner.retire(); }
|
|
352
374
|
});
|
|
353
375
|
|
|
354
|
-
test("context.high is exposed as an advanced per-event row
|
|
376
|
+
test("context.high is exposed as an advanced per-event row with independent choices", async () => {
|
|
355
377
|
const h = harness(); try {
|
|
356
378
|
const rows = h.rows();
|
|
357
379
|
assert.equal(label(findRow(rows, "context.high:")), "context.high: builtin:attention", "the attention tone is the context default");
|
|
358
|
-
await findRow(rows, /^Advanced
|
|
380
|
+
await findRow(rows, /^Advanced/, "shown").action(fakeInline());
|
|
359
381
|
assert.equal(visibleRows(rows).some(row => label(row).startsWith("context.high:")), true);
|
|
360
382
|
await findRow(rows, "context.high:").action(fakeInline());
|
|
361
383
|
const events = getNotificationService()!.getState().settings.audio.events;
|
|
362
|
-
assert.equal(events["context.high"], null, "Enter
|
|
384
|
+
assert.equal(events["context.high"], null, "Enter applies silence to the context tone without touching other events");
|
|
363
385
|
assert.equal(events["agent.attention"], "builtin:attention");
|
|
364
386
|
assert.equal(h.writes, 1);
|
|
365
387
|
} finally { h.owner.retire(); }
|
|
@@ -379,10 +401,10 @@ test("Advanced folds the fourteen detailed event rows inside the same card witho
|
|
|
379
401
|
const rows = h.rows();
|
|
380
402
|
const detail = () => visibleRows(rows).map(label).filter(text => /^(?:agent|subagent|session|context)\./.test(text));
|
|
381
403
|
assert.equal(detail().length, 0, "detailed event rows stay folded by default");
|
|
382
|
-
const toggle = findRow(rows, /^Advanced
|
|
404
|
+
const toggle = findRow(rows, /^Advanced/, "shown");
|
|
383
405
|
await toggle.action(fakeInline());
|
|
384
406
|
assert.equal(detail().length, 14, "expanding reveals the fourteen detailed rows");
|
|
385
|
-
await
|
|
407
|
+
await findRow(rows, /^Advanced/, "hidden").action(fakeInline());
|
|
386
408
|
assert.equal(detail().length, 0, "collapsing folds them again");
|
|
387
409
|
assert.equal(h.writes, 0); assert.equal(h.probes, 0); assert.equal(h.played, 0);
|
|
388
410
|
} finally { h.owner.retire(); }
|
|
@@ -394,7 +416,7 @@ test("global controls and the fold toggle advertise no sound key while group and
|
|
|
394
416
|
for (const prefix of ["Audio notifications:", "Audio: unmuted", "Advanced"])
|
|
395
417
|
assert.doesNotMatch(keyhintOf(findRow(rows, prefix)), /f sound/, `${prefix} is not a per-type file target`);
|
|
396
418
|
for (const { prefix } of GROUPS) assert.match(keyhintOf(findRow(rows, prefix)), /f sound/, `${prefix} assigns its own sound`);
|
|
397
|
-
await findRow(rows, /^Advanced
|
|
419
|
+
await findRow(rows, /^Advanced/, "shown").action(fakeInline());
|
|
398
420
|
for (const prefix of ["agent.failed:", "agent.completed:"]) assert.match(keyhintOf(findRow(rows, prefix)), /f sound/);
|
|
399
421
|
} finally { h.owner.retire(); }
|
|
400
422
|
});
|
|
@@ -402,7 +424,7 @@ test("global controls and the fold toggle advertise no sound key while group and
|
|
|
402
424
|
test("a group edit writes exactly its target events and preserves every other override", async () => {
|
|
403
425
|
const h = harness(); try {
|
|
404
426
|
const rows = h.rows();
|
|
405
|
-
await findRow(rows, "Success:").action(fakeInline());
|
|
427
|
+
await findRow(rows, "Success:", "error tone").action(fakeInline());
|
|
406
428
|
const events = getNotificationService()!.getState().settings.audio.events;
|
|
407
429
|
assert.equal(events["agent.completed"], "builtin:error");
|
|
408
430
|
assert.equal(events["subagent.completed"], "builtin:error");
|
|
@@ -416,7 +438,7 @@ test("a group edit writes exactly its target events and preserves every other ov
|
|
|
416
438
|
test("error and attention groups target verified events only and never add subagent.waiting", async () => {
|
|
417
439
|
const h = harness({ events: { "agent.failed": "builtin:error", "subagent.failed": "builtin:error", "subagent.timed_out": "builtin:error", "agent.attention": "builtin:attention", "subagent.waiting": "builtin:error" } }); try {
|
|
418
440
|
const rows = h.rows();
|
|
419
|
-
await findRow(rows, "Error:").action(fakeInline());
|
|
441
|
+
await findRow(rows, "Error:", "attention tone").action(fakeInline());
|
|
420
442
|
let events = getNotificationService()!.getState().settings.audio.events;
|
|
421
443
|
assert.equal(events["agent.failed"], "builtin:attention");
|
|
422
444
|
assert.equal(events["subagent.failed"], "builtin:attention");
|
|
@@ -428,10 +450,10 @@ test("error and attention groups target verified events only and never add subag
|
|
|
428
450
|
} finally { h.owner.retire(); }
|
|
429
451
|
});
|
|
430
452
|
|
|
431
|
-
test("a group whose targets diverge reads Custom until an explicit
|
|
453
|
+
test("a group whose targets diverge reads Custom until an explicit choice applies the success tone", async () => {
|
|
432
454
|
const h = harness({ events: { "agent.completed": "builtin:success", "subagent.completed": null } }); try {
|
|
433
455
|
const rows = h.rows();
|
|
434
|
-
const success = findRow(rows, "Success:");
|
|
456
|
+
const success = findRow(rows, "Success:", "success tone");
|
|
435
457
|
assert.equal(label(success), "Success: Custom (varies)");
|
|
436
458
|
assert.equal(h.writes, 0);
|
|
437
459
|
await success.action(fakeInline());
|
|
@@ -445,7 +467,7 @@ test("a group whose targets diverge reads Custom until an explicit Enter applies
|
|
|
445
467
|
test("an omitted group reads silence and its edit writes only its targets without merging the preset", async () => {
|
|
446
468
|
const h = harness({ events: {} }); try {
|
|
447
469
|
const rows = h.rows();
|
|
448
|
-
const success = findRow(rows, "Success:");
|
|
470
|
+
const success = findRow(rows, "Success:", "success tone");
|
|
449
471
|
assert.equal(label(success), "Success: silence");
|
|
450
472
|
await success.action(fakeInline());
|
|
451
473
|
const events = getNotificationService()!.getState().settings.audio.events;
|
|
@@ -480,7 +502,7 @@ test("group p previews an unambiguous tone and mixed groups only point at Advanc
|
|
|
480
502
|
test("Advanced expansion is ephemeral: rebuilding the card starts folded", async () => {
|
|
481
503
|
const h = harness(); try {
|
|
482
504
|
const first = h.rows();
|
|
483
|
-
await findRow(first, /^Advanced
|
|
505
|
+
await findRow(first, /^Advanced/, "shown").action(fakeInline());
|
|
484
506
|
assert.equal(visibleRows(first).map(label).filter(text => /^(?:agent|subagent|session)\./.test(text)).length, 13);
|
|
485
507
|
const second = h.rows();
|
|
486
508
|
assert.equal(visibleRows(second).map(label).filter(text => /^(?:agent|subagent|session)\./.test(text)).length, 0, "reopening folds the detailed rows");
|
|
@@ -557,7 +579,7 @@ test("a uniform file group shows the basename, prefills its path and previews th
|
|
|
557
579
|
assert.doesNotMatch(label(success), /builtin:|file:|agent\.|subagent\./, "the main label stays human and raw-reference free");
|
|
558
580
|
getNotificationService()!.validateFile = async () => true;
|
|
559
581
|
const requests: string[] = [];
|
|
560
|
-
const inline: CustomizeInline = { input: async request => { requests.push(request.value); return WAV_FIXTURES.success; }, confirm: async () => false, disposed: false };
|
|
582
|
+
const inline: CustomizeInline = { input: async request => { requests.push(request.value); return WAV_FIXTURES.success; }, capture: async () => undefined, confirm: async () => false, disposed: false };
|
|
561
583
|
await Promise.resolve(success.key!("f", inline));
|
|
562
584
|
await tick(); await tick();
|
|
563
585
|
assert.deepEqual(requests, [WAV_FIXTURES.success], "the field is prefilled with the current file path");
|
|
@@ -602,14 +624,15 @@ test("the rendered basic card shows three independent group choices and hides pe
|
|
|
602
624
|
view.render(76);
|
|
603
625
|
view.handleInput("\x1b[C");
|
|
604
626
|
const frame = () => view.render(76).join("\n");
|
|
605
|
-
for (const { prefix } of GROUPS) assert.match(frame(), new RegExp(prefix), `${prefix} must be visible on the basic card`);
|
|
627
|
+
for (const { prefix } of GROUPS) assert.match(frame(), new RegExp(`${prefix.slice(0, -1)}\\s+`), `${prefix} must be visible on the basic card`);
|
|
606
628
|
assert.doesNotMatch(frame(), /agent\.failed:/, "no per-event technical row is visible before Advanced");
|
|
607
629
|
selectControl(view, "Success:");
|
|
608
630
|
assert.match(frame(), /f sound/, "the selected group advertises its own file key");
|
|
609
631
|
selectControl(view, "Advanced:");
|
|
632
|
+
view.handleInput("\x1b[C");
|
|
610
633
|
view.handleInput("\r");
|
|
611
634
|
await tick();
|
|
612
|
-
assert.match(frame(), /agent\.failed
|
|
635
|
+
assert.match(frame(), /agent\.failed\s+/, "Advanced reveals the per-event exceptions");
|
|
613
636
|
} finally { h.owner.retire(); }
|
|
614
637
|
});
|
|
615
638
|
|
|
@@ -658,6 +681,7 @@ test("the Advanced per-event rows intentionally keep raw ids and builtin refs",
|
|
|
658
681
|
view.render(76);
|
|
659
682
|
view.handleInput("\x1b[C");
|
|
660
683
|
selectControl(view, "Advanced:");
|
|
684
|
+
view.handleInput("\x1b[C");
|
|
661
685
|
view.handleInput("\r");
|
|
662
686
|
await tick();
|
|
663
687
|
selectControl(view, "agent.failed:");
|
|
@@ -64,7 +64,7 @@ const ANCHORS: readonly RoutingAnchor[] = [
|
|
|
64
64
|
label: "triggers hold only when their condition truly holds",
|
|
65
65
|
canonical: "Each trigger holds only when its condition truly holds, and only then is it mandatory, not advisory; no trigger holds by default, and when in doubt work inline.",
|
|
66
66
|
mirrors: [
|
|
67
|
-
{ surface: DELEGATION, includes: "Each trigger holds only when its condition truly holds
|
|
67
|
+
{ surface: DELEGATION, includes: "Each trigger holds only when its condition truly holds; none holds by default. Inline stays within the evidence budget." },
|
|
68
68
|
{ surface: EXTENSION, includes: "No trigger holds by default and, when in doubt, work inline" },
|
|
69
69
|
],
|
|
70
70
|
},
|
|
@@ -98,8 +98,8 @@ const ANCHORS: readonly RoutingAnchor[] = [
|
|
|
98
98
|
label: "never explore to read files an inline write reads anyway",
|
|
99
99
|
canonical: "Never explore to read files you will read anyway before writing inline.",
|
|
100
100
|
mirrors: [
|
|
101
|
-
{ surface: DELEGATION, includes: "
|
|
102
|
-
{ surface: CORE, includes: "
|
|
101
|
+
{ surface: DELEGATION, includes: "Preparation for an already understood inline write stays inline, not further discovery." },
|
|
102
|
+
{ surface: CORE, includes: "Exempt only preparation for an understood inline write, not discovery" },
|
|
103
103
|
],
|
|
104
104
|
},
|
|
105
105
|
{
|
|
@@ -346,7 +346,7 @@ test("ODD defaults to applicable test-first without chat or TUI activation", ()
|
|
|
346
346
|
// once its condition truly holds; none holds by default, inline when in doubt.
|
|
347
347
|
test("delegation triggers are behavioral in the lazy canonical port and the always-on ODD step", () => {
|
|
348
348
|
for (const clause of [
|
|
349
|
-
"Each trigger holds only when its condition truly holds
|
|
349
|
+
"Each trigger holds only when its condition truly holds; none holds by default. Inline stays within the evidence budget.",
|
|
350
350
|
"stop and delegate through the runtime's subagent mechanism before continuing",
|
|
351
351
|
"executing past a fired trigger inline is a routing defect even if the work succeeds",
|
|
352
352
|
"**Mapping trigger",
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { ModelCooldown } from "../lib/model-fallback-policy.ts";
|
|
4
|
+
import { createOrchestratorFallback } from "../lib/orchestrator-fallback.ts";
|
|
5
|
+
|
|
6
|
+
const failed = (errorMessage: string) => [{ role: "user", content: "hi" }, { role: "assistant", content: [], stopReason: "error", errorMessage }];
|
|
7
|
+
const ok = [{ role: "assistant", content: [{ type: "text", text: "done" }], stopReason: "stop" }];
|
|
8
|
+
|
|
9
|
+
function setup(options: { chain?: Array<{ model: string; thinking?: "low" | "high" }>; catalog?: string[]; refuse?: string[]; throwing?: string[] } = {}) {
|
|
10
|
+
let current = "orc/primary";
|
|
11
|
+
const log: string[] = [];
|
|
12
|
+
const fallback = createOrchestratorFallback({
|
|
13
|
+
chain: () => options.chain ?? [{ model: "orc/second", thinking: "high" }, { model: "orc/third" }],
|
|
14
|
+
current: () => current,
|
|
15
|
+
available: (model) => (options.catalog ?? ["orc/primary", "orc/second", "orc/third"]).includes(model),
|
|
16
|
+
setModel: async (model) => {
|
|
17
|
+
if (options.throwing?.includes(model)) throw new Error("OAuth token expired");
|
|
18
|
+
if (options.refuse?.includes(model)) return false;
|
|
19
|
+
current = model;
|
|
20
|
+
log.push(`model ${model}`);
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
setThinking: (level) => log.push(`thinking ${level}`),
|
|
24
|
+
announce: (change) => log.push(`notice ${change.from}->${change.to} ${change.category}`),
|
|
25
|
+
resume: (message) => log.push(`resume ${/continue/i.test(message)}`),
|
|
26
|
+
thinking: () => "medium",
|
|
27
|
+
cooldown: new ModelCooldown(),
|
|
28
|
+
now: () => 1000,
|
|
29
|
+
});
|
|
30
|
+
return { fallback, log, current: () => current };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
test("an orchestrator turn that hits its usage limit switches the session model and resumes", async () => {
|
|
34
|
+
const { fallback, log, current } = setup();
|
|
35
|
+
assert.equal(await fallback.onSettled(failed("insufficient_quota: monthly usage limit")), true);
|
|
36
|
+
assert.equal(current(), "orc/second");
|
|
37
|
+
assert.deepEqual(log, ["model orc/second", "thinking high", "notice orc/primary->orc/second quota", "resume true"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("the orchestrator never switches on errors another model would repeat, on success or without a chain", async () => {
|
|
41
|
+
const context = setup();
|
|
42
|
+
assert.equal(await context.fallback.onSettled(failed("prompt is too long: maximum context length")), false);
|
|
43
|
+
assert.equal(await context.fallback.onSettled(ok), false);
|
|
44
|
+
assert.equal(await context.fallback.onSettled([{ role: "assistant", content: [], stopReason: "aborted" }]), false);
|
|
45
|
+
assert.deepEqual(context.log, []);
|
|
46
|
+
const none = setup({ chain: [] });
|
|
47
|
+
assert.equal(await none.fallback.onSettled(failed("rate limit exceeded")), false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("models outside the catalog or refused by Pi are skipped, and a spent chain stops", async () => {
|
|
51
|
+
const skip = setup({ catalog: ["orc/primary", "orc/third"] });
|
|
52
|
+
assert.equal(await skip.fallback.onSettled(failed("overloaded")), true);
|
|
53
|
+
assert.equal(skip.current(), "orc/third", "a model Pi does not know is skipped");
|
|
54
|
+
const refused = setup({ refuse: ["orc/second"] });
|
|
55
|
+
assert.equal(await refused.fallback.onSettled(failed("overloaded")), true);
|
|
56
|
+
assert.equal(refused.current(), "orc/third");
|
|
57
|
+
assert.equal(await refused.fallback.onSettled(failed("overloaded")), false, "every model was tried once");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("a successful turn ends the episode: a later failure may use the chain again", async () => {
|
|
61
|
+
const { fallback, current } = setup({ chain: [{ model: "orc/second" }] });
|
|
62
|
+
assert.equal(await fallback.onSettled(failed("network error")), true);
|
|
63
|
+
assert.equal(await fallback.onSettled(ok), false);
|
|
64
|
+
assert.equal(current(), "orc/second");
|
|
65
|
+
assert.equal(await fallback.onSettled(failed("network error")), false, "orc/primary cools down and orc/second just failed");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("an aborted run never resumes on a fallback, and a model Pi throws on gives way to the next", async () => {
|
|
69
|
+
const aborted = setup();
|
|
70
|
+
assert.equal(await aborted.fallback.onSettled(failed("insufficient_quota"), { aborted: true }), false);
|
|
71
|
+
assert.deepEqual(aborted.log, [], "the user stopped it: no switch, no resume");
|
|
72
|
+
const throwing = setup({ throwing: ["orc/second"] });
|
|
73
|
+
assert.equal(await throwing.fallback.onSettled(failed("insufficient_quota")), true);
|
|
74
|
+
assert.equal(throwing.current(), "orc/third");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("a fallback step without its own effort runs at the session's original effort, not the previous step's", async () => {
|
|
78
|
+
const { fallback, log } = setup({ chain: [{ model: "orc/second", thinking: "high" }, { model: "orc/third" }], refuse: [] });
|
|
79
|
+
await fallback.onSettled(failed("insufficient_quota"));
|
|
80
|
+
await fallback.onSettled(failed("insufficient_quota"));
|
|
81
|
+
assert.deepEqual(log.filter((line) => line.startsWith("thinking")), ["thinking high", "thinking medium"]);
|
|
82
|
+
});
|