gentle-pi 4.6.0 → 4.7.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 +10 -11
- package/assets/agents/gentle-ai-explore.md +1 -0
- package/assets/agents/gentle-ai-verify.md +5 -2
- package/assets/agents/gentle-ai-worker.md +3 -0
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +1 -0
- package/assets/agents/jd-judge-b.md +1 -0
- package/assets/design-canvas/canvas.css +13 -1
- package/assets/design-canvas/canvas.js +11 -2
- package/assets/install-wizard/wizard.js +1 -0
- package/assets/migrations/agent-body-history.json +16 -1
- package/assets/orchestrator-delegation-reference.md +4 -4
- package/assets/orchestrator-delegation.md +1 -1
- package/assets/orchestrator-full-delegation-card.md +65 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +3 -3
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator-verification.md +7 -5
- package/assets/orchestrator.md +3 -3
- package/bin/gentle-shell.mjs +164 -56
- package/docs/agent-status.md +61 -0
- package/docs/bundled-install.md +7 -5
- package/docs/delegated-verification.md +29 -7
- package/docs/gentle-agents-activity.md +14 -0
- package/docs/gentle-shell.md +54 -16
- package/docs/install-wizard.md +1 -1
- package/docs/permission-modes.md +9 -4
- package/docs/readme-reference.md +75 -30
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +33 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/voice.md +6 -3
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/child-safety.ts +3 -0
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +326 -34
- package/extensions/gentle-ai.ts +1496 -454
- package/extensions/gentle-shell.ts +293 -63
- package/extensions/gentle-todo.ts +18 -2
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +175 -18
- package/extensions/startup-banner.ts +30 -3
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +160 -2
- package/lib/agent-status.ts +105 -0
- package/lib/agents-config.ts +46 -0
- package/lib/agents-history.ts +24 -5
- package/lib/agents-messaging.ts +47 -5
- package/lib/agents-runner.ts +183 -12
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/bounded-writer-admission.ts +13 -1
- package/lib/card-content-policy.ts +8 -6
- package/lib/command-palette.ts +133 -17
- package/lib/context-backstop.ts +14 -5
- package/lib/destructive-command-guard.ts +48 -4
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +4 -2
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-design.ts +3 -0
- package/lib/gentle-shell-bundled.ts +6 -19
- package/lib/gentle-shell-launcher.ts +43 -8
- package/lib/herdr-activity.ts +14 -2
- package/lib/herdr-busy.ts +45 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +270 -140
- package/lib/jobs-view.ts +198 -11
- package/lib/model-routing-authority.ts +22 -4
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +96 -19
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/questionnaire/questionnaire-view.ts +105 -12
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +104 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +81 -44
- package/lib/review-continuation-registry.ts +99 -0
- package/lib/review-coordinator.ts +163 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +46 -10
- package/lib/review-integration-v2.ts +7 -1
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/session-profile-freeze.ts +4 -2
- package/lib/shell-bar.ts +140 -58
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-panel.ts +17 -3
- package/lib/shell-sidebar-layout.ts +112 -40
- package/lib/shell-sidebar.ts +7 -0
- package/lib/shell-todo.ts +10 -3
- package/lib/verifier-admission.ts +1 -1
- package/lib/visual-customization-policy.ts +36 -16
- package/lib/visual-customize-view.ts +216 -21
- package/lib/visual-layout-preview.ts +9 -5
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/yolo-session-policy.ts +40 -15
- package/package.json +2 -1
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +6 -19
- package/runtime/gentle-shell-launcher.mjs +42 -7
- package/runtime/native-review-cli.mjs +93 -16
- package/runtime/review-integration-v2.mjs +7 -1
- package/scripts/build-full-delegation-card.mjs +175 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-preflight.mjs +5 -5
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +8 -7
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +40 -28
- package/scripts/verify-package-files.mjs +12 -2
- package/scripts/voice-worker.cjs +32 -6
- package/skills/design/SKILL.md +11 -8
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- package/skills/skill-registry/SKILL.md +4 -2
- package/skills/work-unit-commits/SKILL.md +6 -7
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -0
- package/tests/agents-config.test.ts +96 -0
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +178 -2
- package/tests/append-system-prompt-route.test.ts +4 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +97 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-stop-contract.test.ts +43 -3
- package/tests/bridge-cost.test.ts +19 -4
- package/tests/bundled-install.test.ts +30 -5
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-safety.test.ts +11 -0
- package/tests/codegraph-tools.test.ts +11 -5
- package/tests/command-palette.test.ts +284 -1
- package/tests/delegate-for-reason-contract.test.ts +3 -3
- package/tests/design-canvas-assets.test.ts +185 -2
- package/tests/destructive-command-guard.test.ts +52 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/execution-surface-guard.test.ts +55 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +53 -6
- package/tests/full-delegation-closure.test.ts +131 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1070 -12
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +18 -2
- package/tests/gentle-ai-installer.test.ts +134 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai.test.ts +113 -38
- package/tests/gentle-design.test.ts +21 -0
- package/tests/gentle-herdr-activity.test.ts +9 -6
- package/tests/gentle-shell-bin.test.ts +123 -0
- package/tests/gentle-shell-bundled.test.ts +207 -31
- package/tests/gentle-shell-launcher.test.ts +77 -10
- package/tests/gentle-shell.test.ts +899 -59
- package/tests/gentle-todo.test.ts +19 -2
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +8 -4
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/independent-recovery-delivery.test.ts +83 -0
- package/tests/inprocess-reviewer.test.ts +176 -4
- package/tests/installer-posix-bootstrap.test.ts +1 -1
- package/tests/installer-preflight.test.ts +5 -4
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +14 -11
- package/tests/jobs-view.test.ts +260 -6
- package/tests/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +269 -1
- package/tests/no-self-pause-contract.test.ts +4 -1
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-delegation-mode.test.ts +153 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +3 -1
- package/tests/orchestrator-rdd-ownership.test.ts +2 -2
- package/tests/package-manifest.test.ts +11 -9
- package/tests/permission-allowlist.test.ts +202 -0
- package/tests/pi-update-launcher.test.ts +8 -0
- package/tests/pnpm-workspace-config.test.ts +58 -0
- package/tests/primary-session-prompt.test.ts +13 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +5 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/questionnaire-view.test.ts +115 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +16 -11
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +18 -0
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor.test.ts +173 -0
- package/tests/review-agent-end-preflight.test.ts +1 -1
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +1 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +76 -0
- package/tests/review-controller-native-routing.test.ts +261 -5
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +96 -11
- package/tests/review-coordinator-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +195 -0
- package/tests/review-failure-facts.test.ts +87 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +65 -10
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
- package/tests/review-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +12 -2
- package/tests/review-reviewer-evidence.test.ts +183 -0
- package/tests/review-risk-assessment.test.ts +74 -3
- package/tests/review-session-standing-permission-controller.test.ts +21 -1
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +121 -0
- package/tests/run-test-suite.test.ts +122 -1
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +181 -5
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-binding.test.ts +19 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-v1-compat.test.ts +35 -1
- package/tests/shell-bar.test.ts +186 -42
- package/tests/shell-panel.test.ts +50 -22
- package/tests/shell-sidebar-fullscreen.test.ts +5 -5
- package/tests/shell-sidebar-layout.test.ts +294 -23
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -0
- package/tests/skill-registry.test.ts +838 -5
- package/tests/startup-banner.test.ts +152 -1
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/review-coordinator-runtime.ts +69 -0
- package/tests/task-size-routing-contract.test.ts +5 -3
- package/tests/verifier-admission.test.ts +49 -0
- package/tests/verify-first-launch-contract.test.ts +78 -3
- package/tests/visual-customization-policy.test.ts +39 -6
- package/tests/visual-customize-view.test.ts +573 -9
- package/tests/visual-layout-preview.test.ts +15 -1
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +28 -0
- package/tests/writer-feature-document-admission.test.ts +92 -0
- package/tests/yolo-customize.test.ts +27 -4
- package/tests/yolo-mode.test.ts +23 -18
- package/tests/yolo-session-policy.test.ts +270 -1
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdirSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test, { type TestContext } from "node:test";
|
|
6
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import type { AssistantMessage } from "@earendil-works/pi-ai";
|
|
8
|
+
import { createGentleAiExtension, __testing } from "../extensions/gentle-ai.ts";
|
|
9
|
+
import type { NativeReviewCli, NativeReviewModeRequest, NativeReviewModeResult } from "../lib/native-review-cli.ts";
|
|
10
|
+
import { discoverRddModeControl } from "../lib/rdd-mode-control.ts";
|
|
11
|
+
|
|
12
|
+
const OPTIONS = ["Enable RDD for this repository", "Disable RDD for this repository", "Enable RDD machine-wide", "Disable RDD machine-wide"];
|
|
13
|
+
const CHANNEL = "gentle:rdd:host-ui";
|
|
14
|
+
type Handler = (event: any, context: any) => any;
|
|
15
|
+
type Mode = "" | "on" | "off";
|
|
16
|
+
|
|
17
|
+
function deferred<T>() {
|
|
18
|
+
let resolve!: (value: T) => void;
|
|
19
|
+
const promise = new Promise<T>((done) => { resolve = done; });
|
|
20
|
+
return { promise, resolve };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function fixture(t: TestContext, initial: Mode = "on") {
|
|
24
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "gentle-rdd-selector-")));
|
|
25
|
+
const home = join(root, "home");
|
|
26
|
+
const config = join(root, "config");
|
|
27
|
+
mkdirSync(home); mkdirSync(config);
|
|
28
|
+
const env = { HOME: root, USERPROFILE: root, XDG_CONFIG_HOME: join(root, "xdg"), PI_CODING_AGENT_DIR: home, GENTLE_PI_AGENT_HOME: home, GENTLE_PI_CONFIG_HOME: config, GENTLE_AI_TELEMETRY: "0" };
|
|
29
|
+
const previous = Object.fromEntries(Object.keys(env).map((key) => [key, process.env[key]]));
|
|
30
|
+
Object.assign(process.env, env);
|
|
31
|
+
__testing.clearRddStatusMemoForTesting();
|
|
32
|
+
t.after(() => {
|
|
33
|
+
__testing.clearRddStatusMemoForTesting();
|
|
34
|
+
for (const [key, value] of Object.entries(previous)) {
|
|
35
|
+
if (value === undefined) delete process.env[key]; else process.env[key] = value;
|
|
36
|
+
}
|
|
37
|
+
rmSync(root, { recursive: true, force: true });
|
|
38
|
+
});
|
|
39
|
+
let global: Mode = initial;
|
|
40
|
+
const clones = new Map<string, Mode>();
|
|
41
|
+
const calls: Array<{ cwd: string; operation: string; scope?: string }> = [];
|
|
42
|
+
const writes: Array<{ cwd: string; operation: string; scope?: string }> = [];
|
|
43
|
+
const assesses: string[] = [];
|
|
44
|
+
const targets: string[] = [];
|
|
45
|
+
let failure: "read" | "write" | "malformed" | undefined;
|
|
46
|
+
let held: ReturnType<typeof deferred<NativeReviewModeResult>> | undefined;
|
|
47
|
+
let started: ReturnType<typeof deferred<void>> | undefined;
|
|
48
|
+
let heldWrite: ReturnType<typeof deferred<NativeReviewModeResult>> | undefined;
|
|
49
|
+
let writeStarted: ReturnType<typeof deferred<void>> | undefined;
|
|
50
|
+
const status = (cwd: string) => {
|
|
51
|
+
const cloneLocal = clones.get(cwd) ?? "";
|
|
52
|
+
const source = cloneLocal === "off" ? "clone_local" : global ? "global" : "default";
|
|
53
|
+
return { global, cloneLocal, effective: cloneLocal === "off" ? "off" : global || "on", source } as NativeReviewModeResult["status"];
|
|
54
|
+
};
|
|
55
|
+
const native = {
|
|
56
|
+
async reviewMode(request: NativeReviewModeRequest) {
|
|
57
|
+
const call = { cwd: request.cwd, operation: request.operation, ...(request.scope ? { scope: request.scope } : {}) };
|
|
58
|
+
calls.push(call);
|
|
59
|
+
if (request.operation === "status") {
|
|
60
|
+
if (held) { const next = held; held = undefined; started!.resolve(); return next.promise; }
|
|
61
|
+
if (failure === "read") throw new Error("fixture status failed");
|
|
62
|
+
const current = status(request.cwd);
|
|
63
|
+
if (failure === "malformed") return { operation: "status", scope: "clone", status: { ...current, source: "invalid" } } as unknown as NativeReviewModeResult;
|
|
64
|
+
return { operation: "status", scope: "clone", status: current } as NativeReviewModeResult;
|
|
65
|
+
}
|
|
66
|
+
if (failure === "write") throw new Error("fixture write refused");
|
|
67
|
+
if (request.scope === "global") global = request.operation === "enable" ? "on" : "off";
|
|
68
|
+
else clones.set(request.cwd, request.operation === "disable" ? "off" : "");
|
|
69
|
+
writes.push(call);
|
|
70
|
+
const result = { operation: request.operation, scope: request.scope ?? "clone", status: status(request.cwd) } as NativeReviewModeResult;
|
|
71
|
+
if (heldWrite) { const next = heldWrite; heldWrite = undefined; writeStarted!.resolve(); return next.promise; }
|
|
72
|
+
return result;
|
|
73
|
+
},
|
|
74
|
+
async assess({ cwd }: { cwd: string }) {
|
|
75
|
+
assesses.push(cwd);
|
|
76
|
+
return { schema: "gentle-ai.review-assessment/v1", risk: "medium", reasons: [], changedPaths: 1, changedLines: 1, candidate: { kind: "current-changes" } };
|
|
77
|
+
},
|
|
78
|
+
async targetStatus({ cwd }: { cwd: string }) { targets.push(cwd); throw new Error("fixture target unavailable"); },
|
|
79
|
+
} as unknown as NativeReviewCli;
|
|
80
|
+
let serial = 0;
|
|
81
|
+
function host(options: { child?: boolean; unavailable?: boolean; mode?: string; hasUI?: boolean } = {}) {
|
|
82
|
+
const cwd = join(root, `workspace-${++serial}`); mkdirSync(cwd);
|
|
83
|
+
let id = `session-${serial}`, managerCwd = cwd;
|
|
84
|
+
const handlers = new Map<string, Handler[]>();
|
|
85
|
+
const commands = new Map<string, { handler: (args: string, ctx: any) => Promise<void> }>();
|
|
86
|
+
const tools = new Map<string, { execute: (...args: any[]) => Promise<any> }>();
|
|
87
|
+
const bus = new Map<string, Array<(payload: unknown) => void>>();
|
|
88
|
+
const notices: Array<{ message: string; type?: string }> = [];
|
|
89
|
+
const prompts: Array<{ title: string; options: string[] }> = [];
|
|
90
|
+
let confirmations = 0;
|
|
91
|
+
let select = async (_title: string, _options: string[]): Promise<string | undefined> => undefined;
|
|
92
|
+
const manager = { getSessionId: () => id, getCwd: () => managerCwd, getEntries: () => [], getBranch: () => [] };
|
|
93
|
+
const ui = new Proxy({
|
|
94
|
+
notify: (message: string, type?: string) => notices.push({ message, type }),
|
|
95
|
+
confirm: async () => { confirmations++; return false; },
|
|
96
|
+
select: async (title: string, choices: string[]) => { prompts.push({ title, options: choices }); return select(title, choices); },
|
|
97
|
+
}, { get(target, key) { return key in target ? Reflect.get(target, key) : () => undefined; } });
|
|
98
|
+
const ctx = { cwd, mode: options.mode ?? "tui", hasUI: options.hasUI ?? true, ui, sessionManager: manager } as unknown as ExtensionContext;
|
|
99
|
+
const pi = {
|
|
100
|
+
on(name: string, handler: Handler) { handlers.set(name, [...handlers.get(name) ?? [], handler]); },
|
|
101
|
+
events: {
|
|
102
|
+
on(name: string, handler: (payload: unknown) => void) { bus.set(name, [...bus.get(name) ?? [], handler]); },
|
|
103
|
+
emit(name: string, payload: unknown) { for (const handler of bus.get(name) ?? []) handler(payload); },
|
|
104
|
+
},
|
|
105
|
+
registerCommand(name: string, command: { handler: (args: string, ctx: any) => Promise<void> }) { commands.set(name, command); },
|
|
106
|
+
registerTool(tool: { name: string; execute: (...args: any[]) => Promise<any> }) { tools.set(tool.name, tool); },
|
|
107
|
+
registerMessageRenderer() {}, appendEntry() {}, getActiveTools: () => [], getThinkingLevel: () => "off",
|
|
108
|
+
} as unknown as ExtensionAPI;
|
|
109
|
+
createGentleAiExtension({ nativeReviewCli: options.unavailable ? null : native, candidateViews: null, processEnv: { ...env, GENTLE_PI_AGENTS_CHILD: options.child ? "1" : "0" }, resolveTelemetryTriggerBinary: () => { throw new Error("disabled"); } })(pi);
|
|
110
|
+
const emit = async (name: string, event: unknown = {}) => { for (const handler of handlers.get(name) ?? []) await handler(event, ctx); };
|
|
111
|
+
return {
|
|
112
|
+
cwd, ctx, manager, ui, notices, prompts, commands, tools, pi, emit,
|
|
113
|
+
start: () => emit("session_start", { type: "session_start", reason: "startup" }),
|
|
114
|
+
command: async (name: string, args = "") => { const command = commands.get(name); assert.ok(command, `/${name} is registered`); await command.handler(args, ctx); },
|
|
115
|
+
select: (fn: typeof select) => { select = fn; },
|
|
116
|
+
setId: (value: string) => { id = value; },
|
|
117
|
+
setManagerCwd: (value: string) => { managerCwd = value; },
|
|
118
|
+
confirmations: () => confirmations,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
host, native, calls, writes, assesses, targets, status,
|
|
123
|
+
state: () => ({ global, clones: [...clones] }),
|
|
124
|
+
fail: (value: typeof failure) => { failure = value; },
|
|
125
|
+
hold: () => { held = deferred<NativeReviewModeResult>(); started = deferred<void>(); return { read: held, started: started.promise }; },
|
|
126
|
+
holdWrite: () => { heldWrite = deferred<NativeReviewModeResult>(); writeStarted = deferred<void>(); return { write: heldWrite, started: writeStarted.promise }; },
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const report = (mode: string, source: string) => ({ message: `receipt-driven development: ${mode} (decided by ${source})`, type: "info" });
|
|
131
|
+
|
|
132
|
+
test("registered selector displays effective source and applies only explicit repository choices", async (t) => {
|
|
133
|
+
const f = fixture(t); const h = f.host(); await h.start();
|
|
134
|
+
h.select(async () => OPTIONS[1]);
|
|
135
|
+
await h.command("gentle:rdd");
|
|
136
|
+
assert.deepEqual(h.prompts, [{ title: "Receipt-driven development: on (decided by global)", options: OPTIONS }]);
|
|
137
|
+
assert.deepEqual(h.notices.at(-1), report("off", "clone_local"));
|
|
138
|
+
assert.deepEqual(f.writes, [{ cwd: h.cwd, operation: "disable" }]);
|
|
139
|
+
h.select(async () => OPTIONS[0]);
|
|
140
|
+
await h.command("gentle:rdd");
|
|
141
|
+
assert.deepEqual(h.notices.at(-1), report("on", "global"));
|
|
142
|
+
assert.deepEqual(f.writes, [{ cwd: h.cwd, operation: "disable" }, { cwd: h.cwd, operation: "enable" }]);
|
|
143
|
+
assert.deepEqual(f.calls.map(({ operation }) => operation), ["status", "disable", "status", "enable"]);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("machine-wide changes require the exact named menu choice and retain clone precedence", async (t) => {
|
|
147
|
+
const f = fixture(t, "off"); const h = f.host(); await h.start();
|
|
148
|
+
h.select(async () => OPTIONS[0]); await h.command("gentle:rdd");
|
|
149
|
+
assert.deepEqual(h.notices.at(-1), { message: "receipt-driven development: off (decided by global)\nThe repository setting cannot override machine-wide RDD off.", type: "warning" });
|
|
150
|
+
h.select(async () => OPTIONS[2]); await h.command("gentle:rdd");
|
|
151
|
+
assert.deepEqual(h.notices.at(-1), report("on", "global"));
|
|
152
|
+
h.select(async () => OPTIONS[1]); await h.command("gentle:rdd");
|
|
153
|
+
h.select(async () => OPTIONS[3]); await h.command("gentle:rdd");
|
|
154
|
+
h.select(async () => OPTIONS[2]); await h.command("gentle:rdd");
|
|
155
|
+
assert.deepEqual(h.notices.at(-1), { message: "receipt-driven development: off (decided by clone_local)\nThe repository override still keeps RDD off.", type: "warning" });
|
|
156
|
+
assert.deepEqual(f.writes, [
|
|
157
|
+
{ cwd: h.cwd, operation: "enable" }, { cwd: h.cwd, operation: "enable", scope: "global" },
|
|
158
|
+
{ cwd: h.cwd, operation: "disable" }, { cwd: h.cwd, operation: "disable", scope: "global" },
|
|
159
|
+
{ cwd: h.cwd, operation: "enable", scope: "global" },
|
|
160
|
+
]);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("RDD choices do not grant review consent or alter permission modes", async (t) => {
|
|
164
|
+
const f = fixture(t); const h = f.host(); await h.start();
|
|
165
|
+
await h.command("gentle:mode", "status"); const permission = h.notices.at(-1);
|
|
166
|
+
await h.command("gentle:review-session-permission", "status"); const consent = h.notices.at(-1);
|
|
167
|
+
h.select(async () => OPTIONS[3]); await h.command("gentle:rdd");
|
|
168
|
+
assert.deepEqual(h.notices.at(-1), report("off", "global"));
|
|
169
|
+
await h.command("gentle:mode", "status"); assert.deepEqual(h.notices.at(-1), permission);
|
|
170
|
+
await h.command("gentle:review-session-permission", "status"); assert.deepEqual(h.notices.at(-1), consent);
|
|
171
|
+
assert.equal(h.confirmations(), 0);
|
|
172
|
+
assert.deepEqual(f.writes, [{ cwd: h.cwd, operation: "disable", scope: "global" }]);
|
|
173
|
+
assert.deepEqual(f.assesses, []); assert.deepEqual(f.targets, []);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("cancellation and forged options or arguments leave mode and counters unchanged", async (t) => {
|
|
177
|
+
const f = fixture(t); const h = f.host(); await h.start();
|
|
178
|
+
const state = f.state();
|
|
179
|
+
await h.command("gentle:rdd");
|
|
180
|
+
assert.deepEqual(h.notices, []); assert.deepEqual(f.writes, []); assert.deepEqual(f.state(), state);
|
|
181
|
+
assert.deepEqual(f.calls, [{ cwd: h.cwd, operation: "status" }]);
|
|
182
|
+
h.select(async () => "enable"); await h.command("gentle:rdd");
|
|
183
|
+
assert.deepEqual(h.notices.at(-1), { message: "RDD unchanged: unrecognized selection.", type: "warning" });
|
|
184
|
+
const count = f.calls.length;
|
|
185
|
+
await h.command("gentle:rdd", "enable --global");
|
|
186
|
+
assert.deepEqual(h.notices.at(-1), { message: "Use /gentle:rdd without arguments to open the interactive selector. RDD unchanged.", type: "warning" });
|
|
187
|
+
assert.equal(f.calls.length, count); assert.deepEqual(f.writes, []); assert.deepEqual(f.state(), state);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("provider failures and invalid status do not write or retry", async (t) => {
|
|
191
|
+
const f = fixture(t); const h = f.host(); await h.start(); const state = f.state();
|
|
192
|
+
f.fail("read"); await h.command("gentle:rdd");
|
|
193
|
+
assert.deepEqual(h.notices.at(-1), { message: "fixture status failed", type: "error" });
|
|
194
|
+
f.fail("malformed"); await h.command("gentle:rdd");
|
|
195
|
+
assert.deepEqual(h.notices.at(-1), { message: "Gentle AI review mode returned an invalid status; RDD unchanged.", type: "error" });
|
|
196
|
+
f.fail("write"); h.select(async () => OPTIONS[3]); await h.command("gentle:rdd");
|
|
197
|
+
assert.deepEqual(h.notices.at(-1), { message: "fixture write refused", type: "error" });
|
|
198
|
+
assert.deepEqual(f.calls.map(({ operation }) => operation), ["status", "status", "status", "disable"]);
|
|
199
|
+
assert.equal(h.prompts.length, 1); assert.deepEqual(f.writes, []); assert.deepEqual(f.state(), state);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("unavailable, headless and child hosts do not open or mutate", async (t) => {
|
|
203
|
+
const f = fixture(t);
|
|
204
|
+
for (const options of [{ unavailable: true }, { mode: "print", hasUI: false }, { mode: "rpc", child: true }]) {
|
|
205
|
+
const h = f.host(options); await h.start(); const calls = f.calls.length; const state = f.state();
|
|
206
|
+
h.select(async () => OPTIONS[3]); await h.command("gentle:rdd");
|
|
207
|
+
assert.equal(h.prompts.length, 0); assert.equal(f.calls.length, calls); assert.deepEqual(f.writes, []); assert.deepEqual(f.state(), state);
|
|
208
|
+
assert.deepEqual(h.notices.at(-1), options.unavailable
|
|
209
|
+
? { message: "Gentle AI review mode is not available with the currently negotiated native version.", type: "info" }
|
|
210
|
+
: options.hasUI === false ? undefined : { message: "RDD unchanged: an interactive primary session is required.", type: "warning" });
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("session, workspace, UI and shutdown changes reject stale selections", async (t) => {
|
|
215
|
+
const f = fixture(t);
|
|
216
|
+
for (const cause of ["session", "cwd", "manager-cwd", "ui", "shutdown"] as const) {
|
|
217
|
+
const h = f.host(); await h.start(); const state = f.state();
|
|
218
|
+
assert.ok(h.commands.has("gentle:rdd"));
|
|
219
|
+
const priorCalls = f.calls.length;
|
|
220
|
+
const answer = deferred<string | undefined>(); const opened = deferred<void>();
|
|
221
|
+
h.select(() => { opened.resolve(); return answer.promise; });
|
|
222
|
+
const action = h.command("gentle:rdd");
|
|
223
|
+
await Promise.race([opened.promise, action]);
|
|
224
|
+
assert.equal(h.prompts.length, 1);
|
|
225
|
+
if (cause === "session") h.setId("another-session");
|
|
226
|
+
if (cause === "cwd") Object.assign(h.ctx, { cwd: `${h.cwd}-other` });
|
|
227
|
+
if (cause === "manager-cwd") h.setManagerCwd(`${h.cwd}-other`);
|
|
228
|
+
if (cause === "ui") Object.assign(h.ctx, { ui: { ...h.ui } });
|
|
229
|
+
if (cause === "shutdown") await h.emit("session_shutdown", { type: "session_shutdown", reason: "quit" });
|
|
230
|
+
answer.resolve(OPTIONS[3]); await action;
|
|
231
|
+
assert.deepEqual(f.calls.slice(priorCalls), [{ cwd: h.cwd, operation: "status" }], cause);
|
|
232
|
+
assert.deepEqual(f.writes, [], cause); assert.deepEqual(f.state(), state, cause); assert.deepEqual(h.notices, [], cause);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
test("shutdown during startup does not revive a stale UI owner", async (t) => {
|
|
237
|
+
const f = fixture(t); const h = f.host();
|
|
238
|
+
const startup = h.start();
|
|
239
|
+
await h.emit("session_shutdown", { type: "session_shutdown", reason: "quit" });
|
|
240
|
+
await startup;
|
|
241
|
+
h.select(async () => OPTIONS[3]); await h.command("gentle:rdd");
|
|
242
|
+
assert.deepEqual(h.prompts, []); assert.deepEqual(f.calls, []); assert.deepEqual(f.writes, []);
|
|
243
|
+
assert.equal(await discoverRddModeControl(h.pi), undefined);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
test("the bridge exposes only owner-held read and selector, never a caller UI or setter", async (t) => {
|
|
247
|
+
const f = fixture(t); const h = f.host(); await h.start();
|
|
248
|
+
let bridge: any;
|
|
249
|
+
const fake = { hasUI: true, ui: { select: async () => OPTIONS[3] } };
|
|
250
|
+
h.pi.events.emit(CHANNEL, { context: fake, respond: (value: unknown) => { bridge = value; } });
|
|
251
|
+
assert.ok(bridge); assert.equal(bridge.setMode, undefined); assert.equal(bridge.toggle, undefined);
|
|
252
|
+
assert.ok(await discoverRddModeControl(h.pi), "the Customize consumer can discover the owner without supplying a UI");
|
|
253
|
+
assert.deepEqual(await bridge.read(), { effective: "on", source: "global" });
|
|
254
|
+
h.select(async () => undefined); await bridge.open();
|
|
255
|
+
assert.equal(h.prompts.length, 1); assert.deepEqual(f.writes, []);
|
|
256
|
+
await h.emit("session_shutdown", { type: "session_shutdown", reason: "quit" });
|
|
257
|
+
assert.equal(await bridge.read(), undefined); await bridge.open();
|
|
258
|
+
assert.equal(h.prompts.length, 1); assert.deepEqual(f.writes, []);
|
|
259
|
+
const child = f.host({ child: true, mode: "rpc" }); await child.start();
|
|
260
|
+
assert.equal(await discoverRddModeControl(child.pi), undefined);
|
|
261
|
+
assert.deepEqual(f.writes, []);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("a global change suppresses a stale selector status before the menu opens", { timeout: 30_000 }, async (t) => {
|
|
265
|
+
const f = fixture(t, "off"); const first = f.host(); const second = f.host();
|
|
266
|
+
await first.start(); await second.start();
|
|
267
|
+
const pending = f.hold();
|
|
268
|
+
const opening = first.command("gentle:rdd"); await pending.started;
|
|
269
|
+
second.select(async () => OPTIONS[2]); await second.command("gentle:rdd");
|
|
270
|
+
pending.read.resolve({ operation: "status", scope: "clone", status: { global: "off", cloneLocal: "", effective: "off", source: "global" } });
|
|
271
|
+
await opening;
|
|
272
|
+
assert.deepEqual(first.prompts, []); assert.deepEqual(first.notices, []);
|
|
273
|
+
assert.deepEqual(second.notices, [report("on", "global")]);
|
|
274
|
+
assert.deepEqual(f.calls, [{ cwd: first.cwd, operation: "status" }, { cwd: second.cwd, operation: "status" }, { cwd: second.cwd, operation: "enable", scope: "global" }]);
|
|
275
|
+
assert.deepEqual(f.writes, [{ cwd: second.cwd, operation: "enable", scope: "global" }]);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
test("a machine-wide change invalidates a selection already open in another cwd", { timeout: 30_000 }, async (t) => {
|
|
279
|
+
const f = fixture(t); const first = f.host(); const second = f.host();
|
|
280
|
+
await first.start(); await second.start();
|
|
281
|
+
const answer = deferred<string | undefined>(); const opened = deferred<void>();
|
|
282
|
+
first.select(() => { opened.resolve(); return answer.promise; });
|
|
283
|
+
const opening = first.command("gentle:rdd");
|
|
284
|
+
await Promise.race([opened.promise, opening]);
|
|
285
|
+
assert.equal(first.prompts.length, 1);
|
|
286
|
+
second.select(async () => OPTIONS[3]); await second.command("gentle:rdd");
|
|
287
|
+
answer.resolve(OPTIONS[2]); await opening;
|
|
288
|
+
assert.deepEqual(first.notices, []);
|
|
289
|
+
assert.deepEqual(second.notices, [report("off", "global")]);
|
|
290
|
+
assert.deepEqual(f.calls, [{ cwd: first.cwd, operation: "status" }, { cwd: second.cwd, operation: "status" }, { cwd: second.cwd, operation: "disable", scope: "global" }]);
|
|
291
|
+
assert.deepEqual(f.writes, [{ cwd: second.cwd, operation: "disable", scope: "global" }]);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test("a later write suppresses an obsolete in-flight mutation response without retrying", { timeout: 30_000 }, async (t) => {
|
|
295
|
+
const f = fixture(t); const first = f.host(); const second = f.host();
|
|
296
|
+
await first.start(); await second.start();
|
|
297
|
+
first.select(async () => OPTIONS[1]);
|
|
298
|
+
const pending = f.holdWrite();
|
|
299
|
+
const earlier = first.command("gentle:rdd"); await pending.started;
|
|
300
|
+
second.select(async () => OPTIONS[3]); await second.command("gentle:rdd");
|
|
301
|
+
pending.write.resolve({ operation: "disable", scope: "clone", status: { global: "on", cloneLocal: "off", effective: "off", source: "clone_local" } });
|
|
302
|
+
await earlier;
|
|
303
|
+
assert.deepEqual(first.notices, []);
|
|
304
|
+
assert.deepEqual(second.notices, [report("off", "global")]);
|
|
305
|
+
assert.deepEqual(f.writes, [{ cwd: first.cwd, operation: "disable" }, { cwd: second.cwd, operation: "disable", scope: "global" }]);
|
|
306
|
+
assert.deepEqual(f.calls.map(({ operation }) => operation), ["status", "disable", "status", "disable"]);
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
test("a session change after dispatch suppresses the reply but never retries the write", { timeout: 30_000 }, async (t) => {
|
|
310
|
+
const f = fixture(t); const h = f.host(); await h.start(); h.select(async () => OPTIONS[3]);
|
|
311
|
+
const pending = f.holdWrite(); const action = h.command("gentle:rdd"); await pending.started;
|
|
312
|
+
h.setId("replacement");
|
|
313
|
+
pending.write.resolve({ operation: "disable", scope: "global", status: { global: "off", cloneLocal: "", effective: "off", source: "global" } });
|
|
314
|
+
await action;
|
|
315
|
+
assert.deepEqual(h.notices, []);
|
|
316
|
+
assert.deepEqual(f.calls, [{ cwd: h.cwd, operation: "status" }, { cwd: h.cwd, operation: "disable", scope: "global" }]);
|
|
317
|
+
assert.deepEqual(f.writes, [{ cwd: h.cwd, operation: "disable", scope: "global" }]);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test("global change invalidates a direct ASSESS read in a previously unseen cwd", async (t) => {
|
|
321
|
+
const f = fixture(t, "off"); const owner = f.host(); const other = f.host(); await owner.start(); await other.start();
|
|
322
|
+
// The existing checkout supplies a real worktree identity without creating
|
|
323
|
+
// or changing Git data. The native provider remains an in-memory fixture.
|
|
324
|
+
const assessmentCwd = process.cwd();
|
|
325
|
+
Object.assign(other.ctx, { cwd: assessmentCwd }); other.setManagerCwd(assessmentCwd);
|
|
326
|
+
assert.ok(owner.commands.has("gentle:rdd"));
|
|
327
|
+
const pending = f.hold();
|
|
328
|
+
const assessment = other.tools.get("gentle_review")!.execute("race", { operation: "assess" }, undefined, undefined, other.ctx);
|
|
329
|
+
await pending.started;
|
|
330
|
+
owner.select(async () => OPTIONS[2]); await owner.command("gentle:rdd");
|
|
331
|
+
pending.read.resolve({ operation: "status", scope: "clone", status: { global: "off", cloneLocal: "", effective: "off", source: "global" } });
|
|
332
|
+
const result = await assessment;
|
|
333
|
+
assert.equal(result.details.rddLine, "unknown");
|
|
334
|
+
assert.deepEqual(f.assesses, [assessmentCwd]); assert.deepEqual(f.targets, [assessmentCwd]);
|
|
335
|
+
assert.deepEqual(f.writes, [{ cwd: owner.cwd, operation: "enable", scope: "global" }]);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test("SDK sessions refresh pinned prompt state across cwd after an explicit global choice", { timeout: 30_000 }, async (t) => {
|
|
339
|
+
const f = fixture(t); const firstPath = f.host().cwd; const secondPath = f.host().cwd;
|
|
340
|
+
const sdk = await import("@earendil-works/pi-coding-agent");
|
|
341
|
+
const ai = await import("@earendil-works/pi-ai");
|
|
342
|
+
let serial = 0;
|
|
343
|
+
async function host(cwd: string) {
|
|
344
|
+
const id = ++serial;
|
|
345
|
+
const requests: string[] = [];
|
|
346
|
+
const notices: Array<{ message: string; type?: string }> = [];
|
|
347
|
+
let answer: string | undefined;
|
|
348
|
+
const ui = new Proxy({
|
|
349
|
+
notify: (message: string, type?: string) => notices.push({ message, type }),
|
|
350
|
+
select: async () => answer,
|
|
351
|
+
}, { get(target, key) { return key in target ? Reflect.get(target, key) : () => undefined; } });
|
|
352
|
+
const settings = sdk.SettingsManager.inMemory({ compaction: { enabled: false }, retry: { enabled: false }, cacheWarming: "off", packages: [] });
|
|
353
|
+
const runtime = await sdk.ModelRuntime.create({ credentials: new ai.InMemoryCredentialStore(), modelsPath: null, modelsStorePath: join(cwd, "models.json"), refreshOnCreate: false, allowModelNetwork: false });
|
|
354
|
+
const provider = `rdd-selector-${id}`;
|
|
355
|
+
const model = { id: "driver", name: "Fixture driver", provider, api: provider, baseUrl: "http://invalid.local", reasoning: false, input: ["text"], contextWindow: 1_000_000, maxTokens: 1024, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } } as const;
|
|
356
|
+
const loader = new sdk.DefaultResourceLoader({ cwd, agentDir: join(cwd, "agent"), settingsManager: settings, noExtensions: true, noSkills: true, noPromptTemplates: true, noThemes: true, noContextFiles: true,
|
|
357
|
+
extensionFactories: [(pi) => {
|
|
358
|
+
createGentleAiExtension({ nativeReviewCli: f.native, candidateViews: null, processEnv: { ...process.env, GENTLE_PI_AGENTS_CHILD: "0", GENTLE_AI_TELEMETRY: "0" }, resolveTelemetryTriggerBinary: () => { throw new Error("disabled"); } })(pi);
|
|
359
|
+
pi.registerProvider(provider, { api: provider, apiKey: "fixture-only", baseUrl: "http://invalid.local", models: [{ id: model.id, name: model.name, reasoning: false, input: ["text"], cost: model.cost, contextWindow: model.contextWindow, maxTokens: model.maxTokens }],
|
|
360
|
+
streamSimple(_model, context) {
|
|
361
|
+
requests.push(ai.getCurrentSystemPrompt(context.messages));
|
|
362
|
+
const stream = ai.createAssistantMessageEventStream();
|
|
363
|
+
const message: AssistantMessage = { role: "assistant", api: model.api, provider, model: model.id, content: [], stopReason: "stop", timestamp: Date.now(), usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } } };
|
|
364
|
+
queueMicrotask(() => { stream.push({ type: "start", partial: message }); stream.push({ type: "done", reason: "stop", message }); stream.end(); });
|
|
365
|
+
return stream;
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
}],
|
|
369
|
+
});
|
|
370
|
+
await loader.reload(); assert.deepEqual(loader.getExtensions().errors, []);
|
|
371
|
+
const { session } = await sdk.createAgentSession({ cwd, agentDir: join(cwd, "agent"), modelRuntime: runtime, model: model as never, thinkingLevel: "off", resourceLoader: loader, tools: ["read", "gentle_review"], sessionManager: sdk.SessionManager.inMemory(cwd), settingsManager: settings });
|
|
372
|
+
const errors: string[] = [];
|
|
373
|
+
await session.bindExtensions({ mode: "rpc", uiContext: ui as never, onError: (error) => errors.push(error.error) });
|
|
374
|
+
return { session, requests, notices, errors, select: (value: string) => { answer = value; }, prompt: (text: string) => session.prompt(text, { source: "interactive" }) };
|
|
375
|
+
}
|
|
376
|
+
const first = await host(firstPath), second = await host(secondPath);
|
|
377
|
+
try {
|
|
378
|
+
await first.prompt("Initial A"); await second.prompt("Initial B");
|
|
379
|
+
assert.match(second.requests.at(-1)!, /Receipt-driven development: on \(decided by global\)/);
|
|
380
|
+
first.select(OPTIONS[3]!); await first.prompt("/gentle:rdd");
|
|
381
|
+
assert.deepEqual(first.notices.at(-1), report("off", "global"));
|
|
382
|
+
await second.prompt("After machine-wide off");
|
|
383
|
+
assert.match(second.requests.at(-1)!, /Receipt-driven development: off \(decided by global\)/);
|
|
384
|
+
assert.ok(second.requests.at(-1)!.includes("RDD off does not require an assessment"));
|
|
385
|
+
first.select(OPTIONS[2]!); await first.prompt("/gentle:rdd");
|
|
386
|
+
assert.deepEqual(first.notices.at(-1), report("on", "global"));
|
|
387
|
+
await second.prompt("After machine-wide on");
|
|
388
|
+
assert.match(second.requests.at(-1)!, /Receipt-driven development: on \(decided by global\)/);
|
|
389
|
+
assert.equal(second.requests.at(-1)!.includes("RDD off does not require an assessment"), false);
|
|
390
|
+
assert.deepEqual(f.writes, [{ cwd: firstPath, operation: "disable", scope: "global" }, { cwd: firstPath, operation: "enable", scope: "global" }]);
|
|
391
|
+
assert.deepEqual([...first.errors, ...second.errors], []);
|
|
392
|
+
} finally {
|
|
393
|
+
await first.session.abort(); await second.session.abort(); first.session.dispose(); second.session.dispose();
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
test("existing review-mode retains clone-default requests and exact notices", async (t) => {
|
|
398
|
+
const f = fixture(t, ""); const h = f.host(); await h.start();
|
|
399
|
+
await h.command("gentle:review-mode", "disable");
|
|
400
|
+
assert.deepEqual(h.notices.at(-1), report("off", "clone_local"));
|
|
401
|
+
await h.command("gentle:review-mode", "enable");
|
|
402
|
+
assert.deepEqual(h.notices.at(-1), report("on", "default"));
|
|
403
|
+
await h.command("gentle:review-mode", "status");
|
|
404
|
+
assert.deepEqual(h.notices.at(-1), report("on", "default"));
|
|
405
|
+
assert.deepEqual(f.calls, [{ cwd: h.cwd, operation: "disable" }, { cwd: h.cwd, operation: "enable" }, { cwd: h.cwd, operation: "status" }]);
|
|
406
|
+
assert.deepEqual(f.writes, f.calls.slice(0, 2));
|
|
407
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { mkdtempSync, 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
|
+
import { createNativeReviewCli, NativeReviewCliV216 } from "../lib/native-review-cli.ts";
|
|
8
|
+
|
|
9
|
+
type Client = ReturnType<typeof createNativeReviewCli>;
|
|
10
|
+
type Executor = Parameters<typeof createNativeReviewCli>[0];
|
|
11
|
+
type BinaryResolver = NonNullable<Parameters<typeof createNativeReviewCli>[1]>;
|
|
12
|
+
type ModeRequest = Parameters<NonNullable<Client["reviewMode"]>>[0];
|
|
13
|
+
|
|
14
|
+
test("public mode clients snapshot scopes and reject requests without file or process effects", async (t) => {
|
|
15
|
+
const factories: Array<(execute: Executor, binary: BinaryResolver) => Client> = [
|
|
16
|
+
createNativeReviewCli,
|
|
17
|
+
(execute, binary) => new NativeReviewCliV216(execute, binary),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
for (const make of factories) {
|
|
21
|
+
const root = mkdtempSync(join(tmpdir(), "gentle-rdd-scope-"));
|
|
22
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
23
|
+
const file = join(root, "state.json");
|
|
24
|
+
writeFileSync(file, '{"global":"on","clone":""}\n');
|
|
25
|
+
const hash = () => createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
26
|
+
let calls = 0;
|
|
27
|
+
let writes = 0;
|
|
28
|
+
let resolutions = 0;
|
|
29
|
+
let cwdReads = 0;
|
|
30
|
+
const argv: string[][] = [];
|
|
31
|
+
const snapshot = () => ({ hash: hash(), calls, writes, resolutions, cwdReads });
|
|
32
|
+
|
|
33
|
+
const execute: Executor = async (request) => {
|
|
34
|
+
calls++;
|
|
35
|
+
argv.push([...request.arguments]);
|
|
36
|
+
const operation = request.arguments[2];
|
|
37
|
+
const scopeIndex = request.arguments.indexOf("--scope");
|
|
38
|
+
const scope = scopeIndex < 0 ? "both" : request.arguments[scopeIndex + 1];
|
|
39
|
+
const state: Record<string, string> = JSON.parse(readFileSync(file, "utf8"));
|
|
40
|
+
if (operation !== "status") {
|
|
41
|
+
state[scope] = operation === "disable" ? "off" : scope === "global" ? "on" : "";
|
|
42
|
+
writeFileSync(file, JSON.stringify(state));
|
|
43
|
+
writes++;
|
|
44
|
+
}
|
|
45
|
+
const effective = state.clone === "off" || state.global === "off" ? "off" : "on";
|
|
46
|
+
const source = state.clone === "off" ? "clone_local" : "global";
|
|
47
|
+
return {
|
|
48
|
+
stdout: JSON.stringify({
|
|
49
|
+
schema: "gentle-ai.review-mode/v1",
|
|
50
|
+
operation,
|
|
51
|
+
scope,
|
|
52
|
+
status: {
|
|
53
|
+
schema: "gentle-ai.rdd-mode-status/v1",
|
|
54
|
+
global: state.global,
|
|
55
|
+
clone_local: state.clone,
|
|
56
|
+
effective,
|
|
57
|
+
source,
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
stderr: "",
|
|
61
|
+
exitCode: 0,
|
|
62
|
+
signal: null,
|
|
63
|
+
timedOut: false,
|
|
64
|
+
outputLimitExceeded: false,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const client = make(execute, () => {
|
|
68
|
+
resolutions++;
|
|
69
|
+
return "/fixture/gentle-ai";
|
|
70
|
+
});
|
|
71
|
+
assert.ok(client.reviewMode);
|
|
72
|
+
const mode = client.reviewMode.bind(client);
|
|
73
|
+
|
|
74
|
+
for (const operation of ["enable", "disable", "status"] as const) {
|
|
75
|
+
for (const scope of [false, 0, [], {}, "GLOBAL", "both", "clone ", null]) {
|
|
76
|
+
const before = snapshot();
|
|
77
|
+
const request = {
|
|
78
|
+
operation,
|
|
79
|
+
scope,
|
|
80
|
+
get cwd() {
|
|
81
|
+
cwdReads++;
|
|
82
|
+
return process.cwd();
|
|
83
|
+
},
|
|
84
|
+
} as unknown as ModeRequest;
|
|
85
|
+
await assert.rejects(() => mode(request), {
|
|
86
|
+
name: "TypeError",
|
|
87
|
+
message: "Native review mode scope must be clone or global",
|
|
88
|
+
});
|
|
89
|
+
assert.deepEqual(snapshot(), before);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const scope of ["global", "clone"] as const) {
|
|
94
|
+
const before = snapshot();
|
|
95
|
+
const request: ModeRequest = {
|
|
96
|
+
operation: "status",
|
|
97
|
+
scope,
|
|
98
|
+
get cwd() {
|
|
99
|
+
cwdReads++;
|
|
100
|
+
return process.cwd();
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
await assert.rejects(() => mode(request), {
|
|
104
|
+
name: "TypeError",
|
|
105
|
+
message: "Native review mode scope is only valid for enable or disable",
|
|
106
|
+
});
|
|
107
|
+
assert.deepEqual(snapshot(), before);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
for (const operation of ["disable", "enable"] as const) {
|
|
111
|
+
for (const scope of [undefined, "clone", "global"] as const) {
|
|
112
|
+
const request: {
|
|
113
|
+
cwd: string;
|
|
114
|
+
operation: "disable" | "enable" | "status";
|
|
115
|
+
scope?: "clone" | "global" | "invalid";
|
|
116
|
+
} = { cwd: process.cwd(), operation, ...(scope === undefined ? {} : { scope }) };
|
|
117
|
+
const pending = mode(request as ModeRequest);
|
|
118
|
+
request.operation = "status";
|
|
119
|
+
request.scope = "invalid";
|
|
120
|
+
const result = await pending;
|
|
121
|
+
assert.equal(result.operation, operation);
|
|
122
|
+
assert.equal(result.scope, scope ?? "clone");
|
|
123
|
+
assert.deepEqual(argv.at(-1), [
|
|
124
|
+
"review", "mode", operation, "--cwd", process.cwd(),
|
|
125
|
+
"--scope", scope ?? "clone", "--json",
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const result = await mode({ cwd: process.cwd(), operation: "status" });
|
|
131
|
+
assert.equal(result.scope, "both");
|
|
132
|
+
assert.deepEqual(argv.at(-1), ["review", "mode", "status", "--cwd", process.cwd(), "--json"]);
|
|
133
|
+
assert.deepEqual({ calls, writes, resolutions, cwdReads }, {
|
|
134
|
+
calls: 7, writes: 6, resolutions: 7, cwdReads: 0,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import test from "node:test";
|
|
8
|
+
import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
|
|
9
|
+
|
|
10
|
+
test("RDD off plans retain checks and reject invalid input before native calls", async (t) => {
|
|
11
|
+
const root = mkdtempSync(join(tmpdir(), "independent-rdd-regression-"));
|
|
12
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
13
|
+
execFileSync("git", ["init", "-q"], {
|
|
14
|
+
cwd: root,
|
|
15
|
+
env: { PATH: process.env.PATH, HOME: root, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: "/dev/null" },
|
|
16
|
+
});
|
|
17
|
+
const state = join(root, "state.json");
|
|
18
|
+
writeFileSync(state, '{"authority":"unchanged"}\n');
|
|
19
|
+
const hash = () => createHash("sha256").update(readFileSync(state)).digest("hex");
|
|
20
|
+
const before = hash();
|
|
21
|
+
const tools = new Map<string, any>();
|
|
22
|
+
const calls = { mode: 0, assess: 0, target: 0, append: 0 };
|
|
23
|
+
createGentleAiExtension({ candidateViews: null, nativeReviewCli: {
|
|
24
|
+
reviewMode: async () => { calls.mode++; return { status: { effective: "off", source: "global" } }; },
|
|
25
|
+
assess: async () => { calls.assess++; throw Error("must not assess"); },
|
|
26
|
+
targetStatus: async () => { calls.target++; throw Error("must not query target"); },
|
|
27
|
+
} as any })({
|
|
28
|
+
on() {}, registerCommand() {},
|
|
29
|
+
registerTool(tool: any) { tools.set(tool.name, tool); },
|
|
30
|
+
appendEntry() { calls.append++; },
|
|
31
|
+
} as any);
|
|
32
|
+
const registry = [...tools.keys()];
|
|
33
|
+
const invoke = (input?: unknown, signal?: AbortSignal) => tools.get("gentle_review").execute(
|
|
34
|
+
"probe", { operation: "assess", ...(input === undefined ? {} : { input }) }, signal, undefined, { cwd: root },
|
|
35
|
+
);
|
|
36
|
+
for (const [input, message] of [
|
|
37
|
+
[{ baseRef: "HEAD" }, "Review assess baseRef requires committedOnly: true"],
|
|
38
|
+
[{ committedOnly: true }, "Review assess committedOnly requires an explicit baseRef"],
|
|
39
|
+
[{ escalate: { item: 0, reason: "Changes authority" } }, "escalate item must be an integer from 1 to 6 naming a high-risk item"],
|
|
40
|
+
[{ escalate: { item: 7, reason: "Changes authority" } }, "escalate item must be an integer from 1 to 6 naming a high-risk item"],
|
|
41
|
+
] as const) {
|
|
42
|
+
await assert.rejects(() => invoke(input), { message });
|
|
43
|
+
assert.equal(hash(), before);
|
|
44
|
+
assert.deepEqual([...tools.keys()], registry);
|
|
45
|
+
assert.deepEqual(calls, { mode: 0, assess: 0, target: 0, append: 0 });
|
|
46
|
+
}
|
|
47
|
+
await assert.rejects(() => invoke(undefined, AbortSignal.abort()), { message: "Review controller operation was cancelled" });
|
|
48
|
+
assert.deepEqual(calls, { mode: 0, assess: 0, target: 0, append: 0 });
|
|
49
|
+
for (const escalate of [undefined, { item: 6, reason: "Changes the shared state owner" }]) {
|
|
50
|
+
const result = await invoke({ baseRef: "HEAD", committedOnly: true, nativeReviewOutcome: "closed", ...(escalate ? { escalate } : {}) });
|
|
51
|
+
const details = result.details;
|
|
52
|
+
assert.deepEqual(result.content, [{ type: "text", text: JSON.stringify(details) }]);
|
|
53
|
+
assert.equal(details.rddLine, "off");
|
|
54
|
+
assert.equal(details.nativeRisk, "unassessable");
|
|
55
|
+
assert.equal(details.risk, escalate ? "high" : "medium");
|
|
56
|
+
assert.equal(details.candidate, null);
|
|
57
|
+
assert.equal(details.nativeReviewOutcome, "unknown");
|
|
58
|
+
assert.equal(details.changedPaths, 0);
|
|
59
|
+
assert.equal(details.changedLines, 0);
|
|
60
|
+
assert.match(details.reasons[0].detail, /counts were not measured/);
|
|
61
|
+
for (const key of ["reviewDue", "reviewDueReason", "nextTransition"]) assert.equal(Object.hasOwn(details, key), false);
|
|
62
|
+
assert.equal(details.plan.writerSelfVerification, true);
|
|
63
|
+
assert.equal(details.plan.structuralReadbackOnly, false);
|
|
64
|
+
assert.equal(details.plan.independentVerifier, Boolean(escalate));
|
|
65
|
+
assert.equal(hash(), before);
|
|
66
|
+
assert.deepEqual([...tools.keys()], registry);
|
|
67
|
+
}
|
|
68
|
+
assert.deepEqual(calls, { mode: 2, assess: 0, target: 0, append: 0 });
|
|
69
|
+
});
|
|
@@ -357,6 +357,24 @@ test("resolveRddModeStatus still follows a real status change after a re-read",
|
|
|
357
357
|
assert.equal((await resolveRddModeStatus(cli, cwd, undefined, now))?.effective, "off");
|
|
358
358
|
});
|
|
359
359
|
|
|
360
|
+
test("a failed fresh mode read never reuses a cached off status", async () => {
|
|
361
|
+
clearRddStatusMemoForTesting();
|
|
362
|
+
let fail = false;
|
|
363
|
+
let calls = 0;
|
|
364
|
+
const cli: Pick<NativeReviewCli, "reviewMode"> = {
|
|
365
|
+
async reviewMode() {
|
|
366
|
+
calls++;
|
|
367
|
+
if (fail) throw new Error("native review CLI unavailable");
|
|
368
|
+
return modeResult("off", NATIVE_REVIEW_MODE_SOURCE.GLOBAL);
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
const now = () => 1_000_000;
|
|
372
|
+
assert.equal((await resolveRddModeStatus(cli, "/repo-off-failure", undefined, now))?.effective, "off");
|
|
373
|
+
fail = true;
|
|
374
|
+
assert.equal(await resolveRddModeStatus(cli, "/repo-off-failure", undefined, now), undefined);
|
|
375
|
+
assert.equal(calls, 2);
|
|
376
|
+
});
|
|
377
|
+
|
|
360
378
|
test("resolveRddModeStatus stays unknown when no status was ever read", async () => {
|
|
361
379
|
clearRddStatusMemoForTesting();
|
|
362
380
|
const cli = fakeReviewMode(() => { throw new Error("never available"); });
|