gentle-pi 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +122 -8
- package/assets/agents/gentle-ai-explore.md +11 -4
- package/assets/agents/gentle-ai-verify.md +23 -4
- package/assets/agents/gentle-ai-worker.md +6 -6
- package/assets/install-wizard/index.html +47 -0
- package/assets/install-wizard/wizard.css +1279 -0
- package/assets/install-wizard/wizard.js +951 -0
- package/assets/orchestrator-delegation.md +70 -163
- package/assets/orchestrator-memory.md +11 -4
- package/assets/orchestrator-prompts.md +48 -0
- package/assets/orchestrator-tracking.md +53 -0
- package/assets/orchestrator-verification.md +28 -0
- package/assets/orchestrator-writer.md +38 -0
- package/assets/orchestrator.md +29 -25
- package/assets/sounds/LICENSE.md +52 -0
- package/assets/sounds/attention.wav +0 -0
- package/assets/sounds/error.wav +0 -0
- package/assets/sounds/success.wav +0 -0
- package/bin/engram-guard +9 -0
- package/bin/gentle-shell-install.mjs +302 -0
- package/bin/gentle-shell.mjs +703 -22
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +7 -7
- package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/manifest.json +2 -2
- package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/orchestration/pi.md +16 -4
- package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/generated/provider-capabilities.baseline.json +2 -2
- package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/bundled-install.md +397 -0
- package/docs/delegated-verification.md +3 -5
- package/docs/gentle-agents-activity.md +513 -0
- package/docs/gentle-shell-uninstall.md +136 -0
- package/docs/gentle-shell.md +81 -31
- package/docs/install-wizard.md +2040 -0
- package/docs/native-authority-architecture.md +1 -1
- package/docs/permission-modes.md +82 -0
- package/docs/prompt-history.md +1 -1
- package/docs/readme-reference.md +267 -40
- package/docs/render-cache-performance.md +28 -0
- package/docs/sound-notifications-proposal.md +191 -0
- package/docs/sound-notifications.md +114 -0
- package/docs/yolo-mode.md +9 -9
- package/extensions/child-context.ts +11 -2
- package/extensions/child-safety.ts +4 -2
- package/extensions/codegraph-tools.ts +18 -5
- package/extensions/gentle-agents.ts +688 -88
- package/extensions/gentle-ai.ts +886 -238
- package/extensions/gentle-herdr-activity.ts +81 -0
- package/extensions/gentle-notifications.ts +104 -0
- package/extensions/gentle-shell.ts +265 -69
- package/extensions/gentle-todo.ts +108 -13
- package/extensions/history/index.ts +11 -6
- package/extensions/pi-pretty.ts +39 -3
- package/extensions/quiet-tools.ts +91 -21
- package/extensions/skill-registry.ts +175 -46
- package/extensions/startup-banner.ts +11 -2
- package/lib/agent-home.ts +10 -1
- package/lib/agent-model-resolution.ts +80 -0
- package/lib/agent-profiles.ts +13 -3
- package/lib/agents-completion-delivery.ts +11 -3
- package/lib/agents-messaging.ts +1 -1
- package/lib/agents-protocol.ts +40 -1
- package/lib/agents-runner.ts +90 -15
- package/lib/auto-permission-classifier.ts +280 -0
- package/lib/auto-permission-runtime.ts +268 -0
- package/lib/background-jobs-tools.ts +202 -0
- package/lib/background-jobs.ts +253 -0
- package/lib/background-monitor.ts +154 -0
- package/lib/bounded-writer-admission.ts +83 -10
- package/lib/builtin-codemode-optout.ts +166 -0
- package/lib/card-content-policy.ts +85 -0
- package/lib/child-package-injection.ts +62 -0
- package/lib/codemode-renderer.ts +14 -4
- package/lib/command-palette-catalog.ts +3 -2
- package/lib/context-threshold.ts +26 -0
- package/lib/gentle-ai-binary.ts +109 -4
- package/lib/gentle-shell-bundled.ts +517 -0
- package/lib/gentle-shell-launcher.ts +74 -23
- package/lib/gentle-shell-startup-flow.ts +54 -0
- package/lib/gentle-shell-startup-update.ts +92 -0
- package/lib/gentle-shell-uninstall.ts +840 -0
- package/lib/gentle-shell-update-panel.ts +231 -0
- package/lib/herdr-activity.ts +183 -0
- package/lib/inprocess-reviewer.ts +3 -0
- package/lib/jobs-sidebar-state.ts +20 -0
- package/lib/jobs-view.ts +161 -0
- package/lib/model-price-ratio.ts +83 -0
- package/lib/nan-provider.ts +33 -11
- package/lib/native-review-cli.ts +194 -73
- package/lib/notification-audio-native.ts +162 -0
- package/lib/notification-audio-windows.ts +399 -0
- package/lib/notification-audio.ts +332 -0
- package/lib/notification-customize.ts +241 -0
- package/lib/notification-events.ts +113 -0
- package/lib/notification-policy.ts +148 -0
- package/lib/notification-pulse-client.ts +367 -0
- package/lib/notification-pulse-protocol.ts +305 -0
- package/lib/notification-pulse-stream.ts +213 -0
- package/lib/notification-pulse-worker.ts +66 -0
- package/lib/notification-scheduler.ts +173 -0
- package/lib/notification-service.ts +202 -0
- package/lib/notification-ui.ts +87 -0
- package/lib/odd-phase.ts +1 -1
- package/lib/orchestrator-alias.ts +20 -0
- package/lib/orchestrator-catalog.ts +79 -0
- package/lib/orchestrator-consultation.ts +61 -0
- package/lib/orchestrator-discovery.ts +49 -0
- package/lib/orchestrator-helper-consent.ts +122 -0
- package/lib/orchestrator-helper.ts +167 -0
- package/lib/orchestrator-message-card.ts +105 -0
- package/lib/orchestrator-presence.ts +115 -14
- package/lib/orchestrator-scope.ts +80 -0
- package/lib/orchestrator-state.ts +107 -0
- package/lib/orchestrator-tool-card.ts +280 -0
- package/lib/orchestrator-work-search.ts +218 -0
- package/lib/orchestrator-work.ts +79 -0
- package/lib/permission-mode-policy.ts +59 -0
- package/lib/review-candidate-view-owner.ts +8 -6
- package/lib/review-candidate-view.ts +3 -2
- package/lib/review-compact-contract.ts +2 -2
- package/lib/review-host-relay.ts +7 -2
- package/lib/review-integration-v2.ts +100 -22
- package/lib/review-publication-gate.ts +1 -1
- package/lib/review-risk-assessment.ts +77 -51
- package/lib/review-sidebar-state.ts +2 -1
- package/lib/review-transaction.ts +72 -3
- package/lib/runtime-metrics-children.ts +1 -1
- package/lib/runtime-metrics-native.ts +3 -2
- package/lib/selection-engine.ts +18 -6
- package/lib/session-change-capture.ts +5 -4
- package/lib/session-changes.ts +27 -22
- package/lib/session-profile-binding.ts +83 -0
- package/lib/session-profile-freeze.ts +266 -0
- package/lib/session-worktree-registry.ts +74 -8
- package/lib/shell-bar.ts +41 -11
- package/lib/shell-changes-view.ts +40 -13
- package/lib/shell-changes.ts +86 -71
- package/lib/shell-sidebar-layout.ts +5 -1
- package/lib/shell-todo.ts +62 -19
- package/lib/shell-usage.ts +4 -3
- package/lib/status-timing-diagnostics.ts +201 -0
- package/lib/telemetry-trigger.ts +3 -1
- package/lib/vim-editor-adapter.ts +7 -3
- package/lib/visual-customization-policy.ts +20 -9
- package/lib/visual-customize-view.ts +171 -20
- package/lib/writer-surfaces.ts +162 -0
- package/lib/yolo-session-policy.ts +198 -121
- package/package.json +1 -1
- package/runtime/child-package-injection.mjs +63 -0
- package/runtime/gentle-ai-binary.mjs +109 -4
- package/runtime/gentle-shell-bundled.mjs +518 -0
- package/runtime/gentle-shell-launcher.mjs +73 -22
- package/runtime/gentle-shell-startup-flow.mjs +55 -0
- package/runtime/gentle-shell-startup-update.mjs +93 -0
- package/runtime/gentle-shell-uninstall.mjs +841 -0
- package/runtime/gentle-shell-update-panel.mjs +232 -0
- package/runtime/native-review-cli.mjs +191 -70
- package/runtime/review-integration-v2.mjs +100 -22
- package/runtime/review-risk-assessment.mjs +77 -51
- package/runtime/status-timing-diagnostics.mjs +202 -0
- package/runtime/telemetry-trigger.mjs +3 -1
- package/scripts/bootstrap.cmd +255 -0
- package/scripts/bootstrap.sh +168 -0
- package/scripts/build-distribution.mjs +157 -0
- package/scripts/build-installer-bundles.mjs +136 -0
- package/scripts/build-runtime-modules.mjs +7 -0
- package/scripts/bundled-install.mjs +1308 -0
- package/scripts/bundled-wizard.mjs +399 -0
- package/scripts/check-types.mjs +4 -6
- package/scripts/gentle-ai-installer.mjs +79 -32
- package/scripts/install-gentle-ai.mjs +48 -1
- package/scripts/install-tui-mode-setting.mjs +10 -1
- package/scripts/install-wizard-preview.mjs +154 -0
- package/scripts/installer-downloads.mjs +648 -0
- package/scripts/installer-preflight.mjs +387 -0
- package/scripts/installer-probes.mjs +564 -0
- package/scripts/installer-runner.mjs +1102 -0
- package/scripts/installer-server.mjs +881 -0
- package/scripts/installer-windows-artifacts.json +15 -0
- package/scripts/installer-windows.mjs +752 -0
- package/scripts/main-channel.mjs +452 -0
- package/scripts/npm-pack-result.mjs +31 -0
- package/scripts/render-cache-performance-worker.mjs +205 -0
- package/scripts/render-cache-performance.mjs +115 -0
- package/scripts/run-test-suite.mjs +22 -8
- package/scripts/test-installer-acceptance.sh +161 -0
- package/scripts/test-packed-runner.mjs +23 -5
- package/scripts/types-baseline.json +2 -92
- package/scripts/verify-package-files.mjs +82 -18
- package/skills/gentle-ai/SKILL.md +12 -11
- package/tests/agent-home.test.ts +56 -3
- package/tests/agent-model-resolution.test.ts +113 -0
- package/tests/agent-profiles.test.ts +12 -0
- package/tests/agent-risk-escalation.test.ts +123 -0
- package/tests/agents-completion-delivery.test.ts +17 -0
- package/tests/agents-protocol.test.ts +57 -0
- package/tests/agents-queries.test.ts +9 -9
- package/tests/agents-runner-process.test.ts +31 -0
- package/tests/agents-runner.test.ts +89 -4
- package/tests/auto-mode-invariants.test.ts +258 -0
- package/tests/auto-mode-sdk.test.ts +57 -0
- package/tests/auto-mode.test.ts +49 -0
- package/tests/auto-permission-classifier.test.ts +283 -0
- package/tests/auto-permission-runtime.test.ts +196 -0
- package/tests/background-cache-warming.test.ts +2 -1
- package/tests/background-jobs.test.ts +227 -0
- package/tests/background-monitor.test.ts +195 -0
- package/tests/background-subagents-default-mode.test.ts +28 -5
- package/tests/bounded-stop-contract.test.ts +85 -0
- package/tests/bounded-writer-admission.test.ts +52 -1
- package/tests/bridge-wake-lifecycle.test.ts +129 -0
- package/tests/bridge-wake-rendering.test.ts +56 -0
- package/tests/build-distribution.test.ts +269 -0
- package/tests/builtin-codemode-optout.test.ts +242 -0
- package/tests/bundled-install.test.ts +1319 -0
- package/tests/bundled-wizard.test.ts +505 -0
- package/tests/card-content-policy.test.ts +68 -0
- package/tests/card-style-policy.test.ts +34 -2
- package/tests/child-codegraph-bootstrap.test.ts +74 -0
- package/tests/child-package-entrypoints.test.ts +65 -0
- package/tests/child-package-injection.test.ts +74 -0
- package/tests/child-safety.test.ts +12 -0
- package/tests/child-web-package.test.ts +224 -0
- package/tests/codegraph-tools.test.ts +35 -0
- package/tests/codemode-rendering.test.ts +107 -2
- package/tests/command-palette.test.ts +5 -5
- package/tests/context-threshold.test.ts +31 -0
- package/tests/delegate-for-reason-contract.test.ts +327 -0
- package/tests/delegated-key-learnings-contract.test.ts +3 -2
- package/tests/devbinary/native-review-parity.devtest.ts +1 -1
- package/tests/devbinary/pi-host-relay.devtest.ts +173 -3
- package/tests/engram-safety.test.ts +288 -0
- package/tests/generic-agent-tools.test.ts +16 -1
- package/tests/gentle-agents.test.ts +1722 -59
- package/tests/gentle-ai-binary-isolation.test.ts +135 -0
- package/tests/gentle-ai-binary.test.ts +19 -2
- package/tests/gentle-ai-child-guards.test.ts +202 -0
- package/tests/gentle-ai-dev-binary-surfacing.test.ts +125 -15
- package/tests/gentle-ai-installer.test.ts +548 -58
- package/tests/gentle-ai-prompt-model-routing.test.ts +123 -0
- package/tests/gentle-ai-renderer.test.ts +6 -6
- package/tests/gentle-ai.test.ts +999 -31
- package/tests/gentle-herdr-activity.test.ts +100 -0
- package/tests/gentle-notifications.test.ts +427 -0
- package/tests/gentle-shell-bin.test.ts +249 -5
- package/tests/gentle-shell-bundled.test.ts +1002 -0
- package/tests/gentle-shell-launcher.test.ts +234 -13
- package/tests/gentle-shell-startup-flow.test.ts +75 -0
- package/tests/gentle-shell-startup-update.test.ts +85 -0
- package/tests/gentle-shell-uninstall.test.ts +978 -0
- package/tests/gentle-shell-update-panel.test.ts +158 -0
- package/tests/gentle-shell.test.ts +541 -96
- package/tests/gentle-todo.test.ts +253 -2
- package/tests/herdr-activity.test.ts +243 -0
- package/tests/history-agent-home.test.ts +81 -0
- package/tests/history-child-guard.test.ts +70 -0
- package/tests/inprocess-reviewer.test.ts +20 -0
- package/tests/install-gentle-ai-failure.test.ts +69 -0
- package/tests/install-tui-mode-setting.test.ts +15 -0
- package/tests/install-wizard.test.ts +1223 -0
- package/tests/installer-bundles.test.ts +122 -0
- package/tests/installer-posix-bootstrap.test.ts +1201 -0
- package/tests/installer-preflight.test.ts +750 -0
- package/tests/installer-probes.test.ts +1106 -0
- package/tests/installer-runner.test.ts +2158 -0
- package/tests/installer-server.test.ts +1567 -0
- package/tests/installer-windows-bootstrap.test.ts +2410 -0
- package/tests/jobs-view.test.ts +160 -0
- package/tests/main-channel-upgrade.test.ts +389 -0
- package/tests/main-channel.test.ts +344 -0
- package/tests/maintainer/provider-relay.maintest.ts +13 -12
- package/tests/model-price-ratio.test.ts +116 -0
- package/tests/model-profiles-preservation.test.ts +153 -0
- package/tests/model-routing-package.test.ts +10 -0
- package/tests/nan-provider-runtime.test.ts +156 -0
- package/tests/nan-provider.test.ts +28 -18
- package/tests/native-binary-gate.test.ts +2 -0
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +236 -1
- package/tests/native-review-consent.test.ts +2 -2
- package/tests/native-review-parity-runtime.test.ts +1 -1
- package/tests/native-review-parity.test.ts +12 -48
- package/tests/native-risk-evidence-parity.test.ts +21 -0
- package/tests/no-self-pause-contract.test.ts +87 -0
- package/tests/notification-audio-native.test.ts +281 -0
- package/tests/notification-audio-windows.test.ts +581 -0
- package/tests/notification-audio.test.ts +548 -0
- package/tests/notification-customize.test.ts +655 -0
- package/tests/notification-events.test.ts +115 -0
- package/tests/notification-policy.test.ts +201 -0
- package/tests/notification-pulse-client.test.ts +356 -0
- package/tests/notification-pulse-protocol.test.ts +213 -0
- package/tests/notification-pulse-stream.test.ts +320 -0
- package/tests/notification-scheduler.test.ts +258 -0
- package/tests/notification-ui.test.ts +157 -0
- package/tests/npm-pack-result.test.ts +41 -0
- package/tests/odd-integration.test.ts +14 -5
- package/tests/odd-routing-canonical-ratchet.test.ts +53 -12
- package/tests/odd-routing-contract.test.ts +80 -23
- package/tests/orchestrator-budget.test.ts +29 -6
- package/tests/orchestrator-catalog.test.ts +146 -0
- package/tests/orchestrator-consultation-sdk.test.ts +614 -0
- package/tests/orchestrator-consultation.test.ts +111 -0
- package/tests/orchestrator-discovery.test.ts +241 -0
- package/tests/orchestrator-helper-consent.test.ts +171 -0
- package/tests/orchestrator-helper.test.ts +297 -0
- package/tests/orchestrator-message-card.test.ts +190 -0
- package/tests/orchestrator-presence.test.ts +23 -0
- package/tests/orchestrator-rdd-ownership.test.ts +6 -5
- package/tests/orchestrator-scope.test.ts +107 -0
- package/tests/orchestrator-state.test.ts +114 -0
- package/tests/orchestrator-status-publication-contract.test.ts +34 -0
- package/tests/orchestrator-tool-card.test.ts +398 -0
- package/tests/orchestrator-work-search.test.ts +318 -0
- package/tests/orchestrator-work.test.ts +147 -0
- package/tests/package-manifest.test.ts +101 -17
- package/tests/packed-runner-owned-path.test.ts +35 -1
- package/tests/parallel-reason-contract.test.ts +21 -0
- package/tests/parallel-writer-admission.test.ts +210 -0
- package/tests/permission-mode-policy.test.ts +194 -0
- package/tests/persona-single-channel.test.ts +4 -12
- package/tests/pi-pretty.test.ts +56 -0
- package/tests/provider-defect-handoff.test.ts +4 -3
- package/tests/quiet-tool-rendering.test.ts +160 -3
- package/tests/rdd-aware-verification-contract.test.ts +29 -41
- package/tests/render-cache-performance.test.ts +48 -0
- package/tests/review-agent-end-preflight.test.ts +62 -10
- package/tests/review-candidate-view.test.ts +101 -12
- package/tests/review-contract-prompt.test.ts +33 -4
- package/tests/review-controller-native-recovery.test.ts +327 -17
- package/tests/review-controller-native-routing.test.ts +255 -1
- package/tests/review-controller-workspace-root.test.ts +43 -2
- package/tests/review-controller.test.ts +2 -2
- package/tests/review-correction-lifecycle.test.ts +2 -1
- package/tests/review-gate.test.ts +7 -4
- package/tests/review-graph-schema.test.ts +2 -2
- package/tests/review-host-relay-routing.test.ts +5 -3
- package/tests/review-host-relay.test.ts +49 -2
- package/tests/review-integration-v2-forward.test.ts +21 -1
- package/tests/review-json-arguments.test.ts +167 -0
- package/tests/review-last-event-closure.test.ts +157 -8
- package/tests/review-ledger-contract.test.ts +5 -4
- package/tests/review-policy-judgment-day.test.ts +1 -1
- package/tests/review-policy-ordinary.test.ts +2 -2
- package/tests/review-relay-transport-agent.test.ts +66 -1
- package/tests/review-risk-assessment.test.ts +109 -33
- package/tests/review-session-standing-permission-controller.test.ts +16 -17
- package/tests/review-session-standing-permission-ipc.test.ts +6 -5
- package/tests/review-test-fixtures.ts +7 -1
- package/tests/review-transaction.test.ts +18 -1
- package/tests/run-test-suite.test.ts +83 -5
- package/tests/runtime-harness.mjs +42 -15
- package/tests/runtime-metrics-extension.test.ts +1 -1
- package/tests/runtime-metrics-native.test.ts +31 -1
- package/tests/selection-engine.test.ts +30 -0
- package/tests/session-change-capture.test.ts +10 -10
- package/tests/session-changes-shell.test.ts +242 -48
- package/tests/session-changes.test.ts +17 -24
- package/tests/session-profile-binding.test.ts +163 -0
- package/tests/session-profile-freeze.test.ts +381 -0
- package/tests/session-subject-routing-contract.test.ts +34 -0
- package/tests/session-worktree-registry.test.ts +57 -2
- package/tests/shell-bar.test.ts +40 -0
- package/tests/shell-changes-view.test.ts +85 -34
- package/tests/shell-changes.test.ts +61 -62
- package/tests/shell-render-cache-runtime.test.ts +69 -0
- package/tests/shell-render-cache.test.ts +129 -0
- package/tests/shell-sidebar-layout.test.ts +27 -2
- package/tests/shell-todo.test.ts +120 -2
- package/tests/shell-usage-view.test.ts +1 -1
- package/tests/shell-usage.test.ts +35 -0
- package/tests/short-check-routing-contract.test.ts +49 -0
- package/tests/skill-registry-watcher.test.ts +119 -0
- package/tests/skill-registry.test.ts +311 -5
- package/tests/startup-banner.test.ts +117 -3
- package/tests/startup-home-repo.test.ts +170 -0
- package/tests/status-timing-diagnostics.test.ts +283 -0
- package/tests/support/orchestrator-modules.ts +19 -0
- package/tests/task-size-routing-contract.test.ts +241 -0
- package/tests/telemetry-trigger.test.ts +27 -1
- package/tests/test-strength-contract.test.ts +124 -0
- package/tests/verify-agent-contract.test.ts +90 -0
- package/tests/verify-first-launch-contract.test.ts +139 -0
- package/tests/verify-package-files.test.ts +56 -0
- package/tests/vim-editor-adapter.test.ts +7 -7
- package/tests/visual-customization-policy.test.ts +32 -3
- package/tests/visual-customize-view.test.ts +288 -10
- package/tests/writer-edit-surface-scope.test.ts +59 -2
- package/tests/writer-surfaces.test.ts +199 -0
- package/tests/yolo-customize.test.ts +18 -3
- package/tests/yolo-mode-runtime.test.ts +37 -10
- package/tests/yolo-mode.test.ts +32 -4
- package/tests/yolo-session-policy.test.ts +1 -1
- /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import fsPromises from "node:fs/promises";
|
|
6
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
|
|
10
|
+
import { AutoPermissionClassifier } from "../lib/auto-permission-classifier.ts";
|
|
11
|
+
|
|
12
|
+
const model = {
|
|
13
|
+
id: "local", provider: "fixture", api: "fixture", name: "Local", baseUrl: "http://invalid.local",
|
|
14
|
+
reasoning: false, input: ["text"], contextWindow: 32000, maxTokens: 1024,
|
|
15
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Public hooks plus the real ESM SDK session tree and classifier; no provider I/O.
|
|
19
|
+
function fixture(t: test.TestContext) {
|
|
20
|
+
const root = mkdtempSync(join(tmpdir(), "auto-invariants-")), home = join(root, "config");
|
|
21
|
+
mkdirSync(home);
|
|
22
|
+
const previous = process.env.GENTLE_PI_CONFIG_HOME;
|
|
23
|
+
process.env.GENTLE_PI_CONFIG_HOME = home;
|
|
24
|
+
t.after(() => {
|
|
25
|
+
if (previous === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
|
|
26
|
+
else process.env.GENTLE_PI_CONFIG_HOME = previous;
|
|
27
|
+
rmSync(root, { recursive: true, force: true });
|
|
28
|
+
});
|
|
29
|
+
const manager = SessionManager.inMemory(root), anchor = manager.appendCustomEntry("probe-anchor", {});
|
|
30
|
+
const commands = new Map<string, any>(), hooks = new Map<string, any[]>();
|
|
31
|
+
const receipts: any[] = [], providerCalls: any[] = [], notices: string[] = [], statuses: any[] = [];
|
|
32
|
+
let decision = "allow", pending = false, announce!: () => void, receiptChanged: (() => void) | undefined;
|
|
33
|
+
const started = new Promise<void>(resolve => { announce = resolve; });
|
|
34
|
+
const registry: any = {
|
|
35
|
+
streamSimple(selected: any, context: any, options: any) {
|
|
36
|
+
assert.deepEqual(context.tools, []);
|
|
37
|
+
assert.equal(options.toolChoice, "none");
|
|
38
|
+
assert.equal(options.maxRetries, 0);
|
|
39
|
+
let resolve!: (value: any) => void;
|
|
40
|
+
const promise = new Promise(r => { resolve = r; });
|
|
41
|
+
const call = { selected, context, options, resolve: () => resolve({
|
|
42
|
+
role: "assistant", api: "fixture", provider: selected.provider, model: selected.id,
|
|
43
|
+
stopReason: "stop", timestamp: 1,
|
|
44
|
+
content: [{ type: "text", text: JSON.stringify({ decision, reason: decision === "deny"
|
|
45
|
+
? "Only inspection is authorized; do not change files." : "Local fixture action." }) }],
|
|
46
|
+
usage: { input: 5, output: 3, cacheRead: 0, cacheWrite: 0, totalTokens: 8,
|
|
47
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0.02 } },
|
|
48
|
+
}) };
|
|
49
|
+
providerCalls.push(call);
|
|
50
|
+
announce();
|
|
51
|
+
if (!pending) queueMicrotask(call.resolve);
|
|
52
|
+
return { result: () => promise };
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const engine = new AutoPermissionClassifier(registry, { deadlineMs: 1000 });
|
|
56
|
+
const ctx: any = { cwd: root, mode: "tui", hasUI: true, sessionManager: manager, model: { ...model },
|
|
57
|
+
modelRegistry: registry, signal: new AbortController().signal,
|
|
58
|
+
ui: { notify: (text: string) => notices.push(text), setStatus: (...args: any[]) => statuses.push(args),
|
|
59
|
+
setWidget() {}, confirm: async () => false } };
|
|
60
|
+
const pi: any = {
|
|
61
|
+
events: { on() { return () => {}; }, emit() {} },
|
|
62
|
+
on(name: string, fn: any) { hooks.set(name, [...hooks.get(name) ?? [], fn]); },
|
|
63
|
+
registerCommand(name: string, value: any) { commands.set(name, value); },
|
|
64
|
+
registerTool() {}, registerFlag() {}, registerMessageRenderer() {}, getActiveTools: () => [],
|
|
65
|
+
appendEntry(type: string, data: any) { receipts.push({ type, data }); receiptChanged?.(); },
|
|
66
|
+
};
|
|
67
|
+
createGentleAiExtension({ processEnv: { GENTLE_PI_CONFIG_HOME: home }, nativeReviewCli: null,
|
|
68
|
+
candidateViews: null, resolveTelemetryTriggerBinary: () => { throw Error("network/native disabled"); },
|
|
69
|
+
autoPermissionClassifier: engine })(pi);
|
|
70
|
+
const emit = async (name: string, event: any) => {
|
|
71
|
+
let output: any;
|
|
72
|
+
for (const fn of hooks.get(name) ?? []) { const next = await fn(event, ctx); if (next !== undefined) output = next; }
|
|
73
|
+
return output;
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
root, home, ctx, manager, anchor, receipts, providerCalls, statuses, notices, emit, commands,
|
|
77
|
+
input: async (text: string, source = "interactive") => {
|
|
78
|
+
assert.deepEqual(await emit("input", { text, source }), { action: "continue" });
|
|
79
|
+
manager.appendMessage({ role: "user", content: text, timestamp: 1 });
|
|
80
|
+
},
|
|
81
|
+
call: (toolName: string, input: any) => emit("tool_call", { toolName, input, toolCallId: "probe-call" }),
|
|
82
|
+
enable: () => commands.get("gentle:mode").handler("auto", ctx),
|
|
83
|
+
setDecision(value: string) { decision = value; }, setPending(value: boolean) { pending = value; },
|
|
84
|
+
started: () => deadline(started, "one inference started"),
|
|
85
|
+
waitForReceipts(count: number) {
|
|
86
|
+
if (receipts.length >= count) return Promise.resolve();
|
|
87
|
+
return deadline(new Promise<void>(resolve => {
|
|
88
|
+
receiptChanged = () => { if (receipts.length >= count) { receiptChanged = undefined; resolve(); } };
|
|
89
|
+
}), `${count} receipts observed`);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function deadline<T>(event: Promise<T>, label: string): Promise<T> {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
const timer = setTimeout(() => reject(new Error(`Deadline: ${label}`)), 1500);
|
|
97
|
+
event.then(value => { clearTimeout(timer); resolve(value); }, error => { clearTimeout(timer); reject(error); });
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function assertUsage(receipt: any, late: boolean) {
|
|
102
|
+
assert.equal(receipt.type, "gentle-auto-permission");
|
|
103
|
+
assert.equal(receipt.data.late, late);
|
|
104
|
+
assert.equal(receipt.data.usageKnown, true);
|
|
105
|
+
assert.equal(receipt.data.usage.totalTokens, 8);
|
|
106
|
+
assert.equal(receipt.data.usage.costTotal, 0.02);
|
|
107
|
+
assert.equal(Object.hasOwn(receipt.data, "reason"), false, "no model rationale is persisted");
|
|
108
|
+
assert.equal(Object.hasOwn(receipt.data, "input"), false, "no action input is persisted");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
test("public shell hook blocks a stale mode lookup after Auto is reselected", async t => {
|
|
112
|
+
const f = fixture(t); await f.enable(); await f.input("Inspect only. Do not run commands.");
|
|
113
|
+
const original = fsPromises.realpath;
|
|
114
|
+
let lookups = 0, release!: () => void, captured!: () => void;
|
|
115
|
+
const blockedLookup = new Promise<void>(resolve => { captured = resolve; });
|
|
116
|
+
t.mock.method(fsPromises, "realpath", async (path: string) => {
|
|
117
|
+
if (++lookups === 2) {
|
|
118
|
+
captured();
|
|
119
|
+
await new Promise<void>(resolve => { release = resolve; });
|
|
120
|
+
}
|
|
121
|
+
return original(path);
|
|
122
|
+
});
|
|
123
|
+
syncBuiltinESMExports();
|
|
124
|
+
t.after(() => { t.mock.restoreAll(); syncBuiltinESMExports(); });
|
|
125
|
+
const pending = f.call("bash", { command: "pwd" });
|
|
126
|
+
await deadline(blockedLookup, "second tool admission identity lookup");
|
|
127
|
+
await f.enable();
|
|
128
|
+
release();
|
|
129
|
+
const result = await pending;
|
|
130
|
+
let executions = 0; if (!result?.block) executions++;
|
|
131
|
+
assert.equal(executions, 0, "invalidated mode lookup must not bypass Auto");
|
|
132
|
+
assert.equal(result.block, true); assert.match(result.reason, /changed|expired/i);
|
|
133
|
+
assert.equal(f.providerCalls.length, 0);
|
|
134
|
+
assert.match(f.statuses.filter(([key]) => key === "gentle:mode").at(-1)[1], /AUTO/);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("stable Normal and YOLO shell admission retains the non-classifier path", async t => {
|
|
138
|
+
const f = fixture(t);
|
|
139
|
+
for (const mode of ["normal", "yolo"]) {
|
|
140
|
+
await f.commands.get("gentle:mode").handler(mode, f.ctx);
|
|
141
|
+
assert.equal(await f.call("bash", { command: "pwd" }), undefined);
|
|
142
|
+
}
|
|
143
|
+
assert.equal(f.providerCalls.length, 0);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("public hook read-only request classifies authorized reads and denies mutation before execution", async t => {
|
|
147
|
+
const f = fixture(t); await f.enable(); await f.input("Investigate only. Do not edit any files.");
|
|
148
|
+
const file = join(f.root, "app.ts"); writeFileSync(file, "unchanged\n");
|
|
149
|
+
assert.equal(await f.call("read", { path: file }), undefined);
|
|
150
|
+
assert.equal(f.providerCalls.length, 1);
|
|
151
|
+
assert.deepEqual(JSON.parse(f.providerCalls[0].context.messages[0].content).action,
|
|
152
|
+
{ toolName: "read", input: { path: file } });
|
|
153
|
+
assert.equal(f.receipts.length, 1); assert.equal(f.receipts[0].data.decision, "allow"); assertUsage(f.receipts[0], false);
|
|
154
|
+
f.setDecision("deny");
|
|
155
|
+
const result = await f.call("edit", { path: file, oldText: "unchanged", newText: "mutated" });
|
|
156
|
+
let executions = 0;
|
|
157
|
+
if (!result?.block) { executions++; writeFileSync(file, "mutated\n"); }
|
|
158
|
+
assert.equal(executions, 0); assert.equal(readFileSync(file, "utf8"), "unchanged\n");
|
|
159
|
+
assert.equal(f.providerCalls.length, 2);
|
|
160
|
+
for (const call of f.providerCalls)
|
|
161
|
+
assert.deepEqual(JSON.parse(call.context.messages[0].content).trustedMessages,
|
|
162
|
+
["Investigate only. Do not edit any files."]);
|
|
163
|
+
assert.match(result.reason, /Only inspection is authorized/);
|
|
164
|
+
assert.equal(f.receipts.length, 2); assert.equal(f.receipts[1].data.decision, "deny"); assertUsage(f.receipts[1], false);
|
|
165
|
+
assert.equal(f.receipts.reduce((tokens, receipt) => tokens + receipt.data.usage.totalTokens, 0), 16);
|
|
166
|
+
assert.match(f.statuses.filter(([key]) => key === "gentle:auto-usage").at(-1)[1], /Auto checks 2 · 16 tokens · \$0\.0400 \(separate\)/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("public hook explicit prohibition classifies a local read and blocks exposure", async t => {
|
|
170
|
+
const f = fixture(t); await f.enable();
|
|
171
|
+
const instruction = "Investigate app.ts only. Do not read excluded.ts.";
|
|
172
|
+
await f.input(instruction); f.setDecision("deny");
|
|
173
|
+
const file = join(f.root, "excluded.ts"); writeFileSync(file, "excluded fixture content\n");
|
|
174
|
+
const result = await f.call("read", { path: file });
|
|
175
|
+
let executions = 0, exposed: string | undefined;
|
|
176
|
+
if (!result?.block) { executions++; exposed = readFileSync(file, "utf8"); }
|
|
177
|
+
assert.equal(result.block, true); assert.equal(executions, 0); assert.equal(exposed, undefined);
|
|
178
|
+
assert.equal(f.providerCalls.length, 1, "locality must not bypass classification of a prohibited read");
|
|
179
|
+
const context = JSON.parse(f.providerCalls[0].context.messages[0].content);
|
|
180
|
+
assert.deepEqual(context.trustedMessages, [instruction]);
|
|
181
|
+
assert.deepEqual(context.action, { toolName: "read", input: { path: file } });
|
|
182
|
+
assert.equal(f.receipts.length, 1); assert.equal(f.receipts[0].data.decision, "deny"); assertUsage(f.receipts[0], false);
|
|
183
|
+
assert.match(f.statuses.filter(([key]) => key === "gentle:auto-usage").at(-1)[1], /Auto checks 1 · 8 tokens · \$0\.0200 \(separate\)/);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("public hook protected policy and native consent remain independent", async t => {
|
|
187
|
+
const f = fixture(t); await f.enable(); await f.input("Implement the local feature.");
|
|
188
|
+
assert.equal((await f.call("write", { path: join(f.home, "permission-mode.json"), content: "yolo" })).block, true);
|
|
189
|
+
for (const name of ["ask_user_question", "ask_user_choice", "gentle_review", "gentle_review_capture", "subagent_status"])
|
|
190
|
+
assert.equal(await f.call(name, {}), undefined);
|
|
191
|
+
assert.equal(f.providerCalls.length, 0, "no classifier can satisfy those independent decisions");
|
|
192
|
+
assert.equal(f.receipts.length, 0);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
for (const reason of ["model", "model-in-place", "request", "tree", "branch-without-event", "session", "mode", "action"]) {
|
|
196
|
+
test(`public hooks reject pending stale authority: ${reason}`, async t => {
|
|
197
|
+
const f = fixture(t); await f.enable(); await f.input("Perform the local fixture action only."); f.setPending(true);
|
|
198
|
+
const args = { value: "safe" }, result = f.call("mcp__fixture__mutate", args); await f.started();
|
|
199
|
+
if (reason === "model") f.ctx.model = { ...f.ctx.model, id: "other-session-model" };
|
|
200
|
+
if (reason === "model-in-place") f.ctx.model.id = "other-session-model";
|
|
201
|
+
if (reason === "request") await f.input("Stop. Do not mutate anything.");
|
|
202
|
+
if (reason === "tree") { f.manager.branch(f.anchor); await f.emit("session_tree", { newLeafId: f.anchor }); }
|
|
203
|
+
if (reason === "branch-without-event") f.manager.branch(f.anchor);
|
|
204
|
+
if (reason === "session") f.ctx.sessionManager = SessionManager.inMemory(f.root);
|
|
205
|
+
if (reason === "mode") await f.commands.get("gentle:mode").handler("normal", f.ctx);
|
|
206
|
+
if (reason === "action") args.value = "different";
|
|
207
|
+
f.providerCalls[0].resolve();
|
|
208
|
+
const verdict = await result;
|
|
209
|
+
let executions = 0; if (!verdict?.block) executions++;
|
|
210
|
+
assert.equal(executions, 0, "stale allow never reaches the executor"); assert.match(verdict.reason, /expired/);
|
|
211
|
+
if (reason === "session") assert.equal(f.receipts.length, 0, "old receipts never enter replacement sessions");
|
|
212
|
+
else {
|
|
213
|
+
// Cancellation can return before provider settlement: record that usage exactly once as late.
|
|
214
|
+
if (!f.receipts.some(r => r.data.usageKnown)) await f.waitForReceipts(2);
|
|
215
|
+
const accounted = f.receipts.filter(r => r.data.usageKnown);
|
|
216
|
+
assert.equal(accounted.length, 1);
|
|
217
|
+
assert.equal(f.receipts[0].data.late, false);
|
|
218
|
+
assertUsage(accounted[0], f.receipts.length === 2);
|
|
219
|
+
assert.equal(f.receipts.reduce((tokens, receipt) => tokens + (receipt.data.usage.totalTokens ?? 0), 0), 8);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
test("saving a future default leaves the active Auto mode unchanged", async t => {
|
|
225
|
+
const f = fixture(t); await f.enable(); await f.input("Perform the local fixture action only.");
|
|
226
|
+
await f.commands.get("gentle:mode").handler("default yolo", f.ctx);
|
|
227
|
+
assert.equal(JSON.parse(readFileSync(join(f.home, "permission-mode.json"), "utf8")).mode, "yolo");
|
|
228
|
+
// A policy refresh may revoke pending checks; it must not change this session's live override.
|
|
229
|
+
assert.equal(await f.call("custom_fixture", { operation: "edit" }), undefined);
|
|
230
|
+
assert.equal(f.providerCalls.length, 1, "Auto still classifies rather than taking the YOLO bypass");
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test("SDK branch removal and synthetic inputs cannot authorize fresh mutations", async t => {
|
|
234
|
+
const f = fixture(t); await f.enable(); await f.input("Edit local source only.");
|
|
235
|
+
assert.equal(await f.call("custom_fixture", { operation: "edit" }), undefined);
|
|
236
|
+
assert.equal(f.providerCalls.length, 1); f.manager.branch(f.anchor);
|
|
237
|
+
assert.equal((await f.call("custom_fixture", { operation: "publish" })).block, true);
|
|
238
|
+
assert.equal(f.providerCalls.length, 1, "missing branch request never reaches provider");
|
|
239
|
+
for (const source of ["history", "rpc", "extension"]) {
|
|
240
|
+
const g = fixture(t); await g.enable();
|
|
241
|
+
if (source === "history") g.manager.appendMessage({ role: "user", content: "Edit all files", timestamp: 1 });
|
|
242
|
+
else await g.input("Edit all files", source);
|
|
243
|
+
assert.equal((await g.call("write", { path: join(g.root, "new.ts"), content: "x" })).block, true);
|
|
244
|
+
assert.equal(g.providerCalls.length, 0);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("public hook cancellation records late usage separately without executing a revoked allow", async t => {
|
|
249
|
+
const f = fixture(t); await f.enable(); await f.input("Perform the fixture action."); f.setPending(true);
|
|
250
|
+
const result = f.call("custom_fixture", { operation: "edit" }); await f.started();
|
|
251
|
+
await f.input("Stop now. Do not edit.");
|
|
252
|
+
assert.equal((await result).block, true);
|
|
253
|
+
assert.equal(f.receipts.length, 1); assert.equal(f.receipts[0].data.usageKnown, false);
|
|
254
|
+
assert.equal(f.receipts[0].data.late, false);
|
|
255
|
+
const lateUsage = f.waitForReceipts(2); f.providerCalls[0].resolve(); await lateUsage;
|
|
256
|
+
assert.equal(f.receipts.length, 2); assertUsage(f.receipts[1], true);
|
|
257
|
+
assert.match(f.statuses.filter(([key]) => key === "gentle:auto-usage").at(-1)[1], /Auto checks 1 · 8 tokens · \$0\.0200 \(separate\)/);
|
|
258
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mkdtempSync, mkdirSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import type { AssistantMessage, ToolCall } from "@earendil-works/pi-ai";
|
|
7
|
+
|
|
8
|
+
test("actual SDK gates direct and nested custom/MCP execution before side effects, with independent denied-call receipts",{timeout:20_000},async t=>{
|
|
9
|
+
const root=mkdtempSync(join(tmpdir(),"auto-sdk-")),profile=join(root,"profile"),config=join(root,"config");mkdirSync(profile);
|
|
10
|
+
const bindings={PI_CODING_AGENT_DIR:profile,PI_CODING_AGENT_SESSION_DIR:join(root,"sessions"),GENTLE_PI_AGENT_HOME:profile,GENTLE_PI_CONFIG_HOME:config};
|
|
11
|
+
const previous=Object.fromEntries(Object.keys(bindings).map(key=>[key,process.env[key]]));Object.assign(process.env,bindings);
|
|
12
|
+
t.after(()=>{for(const [key,value]of Object.entries(previous))if(value===undefined)delete process.env[key];else process.env[key]=value;rmSync(root,{recursive:true,force:true});});
|
|
13
|
+
const sdk=await import("@earendil-works/pi-coding-agent"),ai=await import("@earendil-works/pi-ai");
|
|
14
|
+
const {Type}=await import("typebox");
|
|
15
|
+
const {createGentleAiExtension}=await import("../extensions/gentle-ai.ts");
|
|
16
|
+
const {writePermissionModePolicy}=await import("../lib/permission-mode-policy.ts");
|
|
17
|
+
writePermissionModePolicy("auto",{gentlePiConfigHome:config});
|
|
18
|
+
const requests:any[]=[],errors:string[]=[],executed:string[]=[],observed:any[]=[];
|
|
19
|
+
let next:{name:string;arguments:any}|undefined,denied=false,calls=0;
|
|
20
|
+
const model:any={id:"driver",name:"Local driver",provider:"auto-fixture",api:"auto-fixture",baseUrl:"http://invalid.local",reasoning:false,input:["text"],contextWindow:1_000_000,maxTokens:1024,cost:{input:0,output:0,cacheRead:0,cacheWrite:0}};
|
|
21
|
+
const manager=sdk.SessionManager.inMemory(root),settings=sdk.SettingsManager.inMemory({compaction:{enabled:false},retry:{enabled:false},cacheWarming:"off",packages:[]});
|
|
22
|
+
const runtime=await sdk.ModelRuntime.create({credentials:new ai.InMemoryCredentialStore(),modelsPath:null,modelsStorePath:join(root,"models.json"),refreshOnCreate:false,allowModelNetwork:false});
|
|
23
|
+
const loader=new sdk.DefaultResourceLoader({cwd:root,agentDir:profile,settingsManager:settings,noExtensions:true,noSkills:true,noPromptTemplates:true,noThemes:true,noContextFiles:true,
|
|
24
|
+
systemPrompt:"Execute one fixture tool, then finish. No external requests.",extensionFactories:[pi=>{
|
|
25
|
+
createGentleAiExtension({nativeReviewCli:null,candidateViews:null,processEnv:bindings,resolveTelemetryTriggerBinary:()=>{throw Error("fixture");},
|
|
26
|
+
autoPermissionClassifier:{cancel(){},run:async(request:any)=>{requests.push(request);return {status:"available",decision:denied && request.action.toolName==="mcp__fixture__write" ? "deny":"allow",reason:"Fixture policy",usage:{totalTokens:7,costTotal:0.01},usageKnown:true};}}})(pi);
|
|
27
|
+
pi.on("tool_result",event=>{observed.push(event);});
|
|
28
|
+
pi.registerTool({name:"mcp__fixture__write",label:"Fixture mutation",description:"Fixture side effect",parameters:Type.Object({value:Type.String()}),annotations:{destructiveHint:true},
|
|
29
|
+
execute:async(_id,args)=>{executed.push(args.value);return {content:[{type:"text",text:"wrote fixture"}],details:undefined};}});
|
|
30
|
+
pi.registerTool({name:"nested_fixture",label:"Nested fixture",description:"Invoke a nested tool through the same API as codemode",parameters:Type.Object({value:Type.String()}),
|
|
31
|
+
execute:async(_id,args,_signal,_update,ctx)=>{const outcome=await ctx.executeTool("mcp__fixture__write",args);return {...outcome.result,isError:outcome.isError};}});
|
|
32
|
+
pi.registerProvider("auto-fixture",{api:"auto-fixture",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}],
|
|
33
|
+
streamSimple(){
|
|
34
|
+
const stream=ai.createAssistantMessageEventStream(),request=next;next=undefined;calls++;
|
|
35
|
+
const msg:AssistantMessage={role:"assistant",api:model.api,provider:model.provider,model:model.id,content:[],stopReason:"pending",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}}};
|
|
36
|
+
queueMicrotask(()=>{stream.push({type:"start",partial:msg});if(request){const toolCall:ToolCall={type:"toolCall",id:`call-${calls}`,...request};msg.content.push(toolCall);stream.push({type:"toolcall_start",contentIndex:0,partial:msg});stream.push({type:"toolcall_delta",contentIndex:0,delta:JSON.stringify(request.arguments),partial:msg});stream.push({type:"toolcall_end",contentIndex:0,toolCall,partial:msg});}
|
|
37
|
+
msg.stopReason=request?"toolUse":"stop";stream.push({type:"done",reason:msg.stopReason,message:msg});stream.end();});return stream;
|
|
38
|
+
}});
|
|
39
|
+
}]});
|
|
40
|
+
await loader.reload();assert.deepEqual(loader.getExtensions().errors,[]);
|
|
41
|
+
const {session}=await sdk.createAgentSession({cwd:root,agentDir:profile,modelRuntime:runtime,model,thinkingLevel:"off",resourceLoader:loader,tools:["mcp__fixture__write","nested_fixture"],sessionManager:manager,settingsManager:settings});
|
|
42
|
+
t.after(async()=>{await session.abort();session.dispose();});
|
|
43
|
+
await session.bindExtensions({mode:"json",onError:error=>errors.push(error.error)});
|
|
44
|
+
const call=async(name:string,value:string)=>{next={name,arguments:{value}};await session.prompt(`Perform the fixture action ${value} only.`,{source:"interactive"});};
|
|
45
|
+
await call("mcp__fixture__write","direct");assert.deepEqual(executed,["direct"]);
|
|
46
|
+
await call("nested_fixture","nested");assert.deepEqual(executed,["direct","nested"]);
|
|
47
|
+
denied=true;await call("nested_fixture","denied-nested");assert.deepEqual(executed,["direct","nested"]);
|
|
48
|
+
await call("mcp__fixture__write","denied-direct");assert.deepEqual(executed,["direct","nested"]);
|
|
49
|
+
assert.deepEqual(errors,[]);
|
|
50
|
+
assert.ok(requests.every(r=>r.trustedMessages.some((text:string)=>text.startsWith("Perform the fixture action"))),"only captured live requests reach classifier");
|
|
51
|
+
assert.equal(requests.filter(r=>r.action.toolName==="mcp__fixture__write").length,4);
|
|
52
|
+
assert.equal(observed.filter(e=>e.toolName==="mcp__fixture__write").length,2,"denied nested/direct calls have no tool_result");
|
|
53
|
+
assert.deepEqual(observed.filter(e=>e.toolName==="nested_fixture").map(e=>e.isError),[false,true],"outer tool preserves nested success and denial outcomes");
|
|
54
|
+
const receipts=manager.getEntries().filter((e:any)=>e.type==="custom"&&e.customType==="gentle-auto-permission") as any[];
|
|
55
|
+
assert.equal(receipts.filter(e=>e.data.decision==="deny").length,2);
|
|
56
|
+
assert.equal(receipts.length,6,"both nested outer calls and all four inner/direct calls recorded independently");
|
|
57
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
|
|
7
|
+
|
|
8
|
+
function harness(t:test.TestContext) {
|
|
9
|
+
const home=mkdtempSync(join(tmpdir(),"auto-hook-"));t.after(()=>rmSync(home,{recursive:true,force:true}));
|
|
10
|
+
const previous=process.env.GENTLE_PI_CONFIG_HOME;process.env.GENTLE_PI_CONFIG_HOME=home;
|
|
11
|
+
t.after(()=>{if(previous===undefined)delete process.env.GENTLE_PI_CONFIG_HOME;else process.env.GENTLE_PI_CONFIG_HOME=previous;});
|
|
12
|
+
const commands=new Map<string,any>(),handlers=new Map<string,any[]>(),entries:any[]=[],requests:any[]=[],records:any[]=[];
|
|
13
|
+
let confirmations=0,decision="allow";
|
|
14
|
+
const ctx:any={cwd:process.cwd(),mode:"tui",hasUI:true,sessionManager:{getSessionId:()=>"auto-test",getBranch:()=>entries},
|
|
15
|
+
model:{provider:"test",id:"test"},modelRegistry:{},ui:{notify(){},setStatus(){},setWidget(){},confirm:async()=>{confirmations++;return false;}}};
|
|
16
|
+
const pi:any={on(name:string,fn:any){handlers.set(name,[...handlers.get(name)??[],fn]);},registerCommand(name:string,v:any){commands.set(name,v);},
|
|
17
|
+
registerTool(){},registerMessageRenderer(){},registerFlag(){},events:{emit(){},on(){return ()=>{};}},getActiveTools:()=>[],appendEntry:(...v:any[])=>records.push(v)};
|
|
18
|
+
createGentleAiExtension({nativeReviewCli:null,candidateViews:null,processEnv:{GENTLE_PI_CONFIG_HOME:home},
|
|
19
|
+
resolveTelemetryTriggerBinary:()=>{throw Error("fixture");},autoPermissionClassifier:{cancel(){},run:async(request:any)=>{requests.push(request);return {status:"available",decision,reason:"Fixture",usage:{totalTokens:3}};}}} as any)(pi);
|
|
20
|
+
const emit=async(name:string,event:any)=>{let output:any;for(const fn of handlers.get(name)??[]){const value=await fn(event,ctx);if(value!==undefined)output=value;}return output;};
|
|
21
|
+
return {home,ctx,commands,requests,records,confirmations:()=>confirmations,setDecision:(v:string)=>decision=v,emit,
|
|
22
|
+
enable:async()=>{assert.ok(commands.get("gentle:mode"));await commands.get("gentle:mode").handler("auto",ctx);},
|
|
23
|
+
input:async(text:string)=>{await emit("input",{text,source:"interactive"});entries.push({type:"message",id:"human-1",message:{role:"user",content:text}});},
|
|
24
|
+
call:(toolName:string,input:any)=>emit("tool_call",{toolName,input,toolCallId:"call"})};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
test("production hook Auto reviews eligible default confirmations and all tool families without per-call questions",async t=>{
|
|
28
|
+
const h=harness(t);await h.enable();await h.input("Implement my change, run tests, and push this branch.");
|
|
29
|
+
for(const tool of ["bash","bash_background","monitor"]){assert.equal(await h.call(tool,{command:"git push origin feature"}),undefined);}
|
|
30
|
+
for(const tool of ["powershell","mcp__fixture__update","custom_tool","codemode"]){assert.equal(await h.call(tool,{command:"local work"}),undefined);}
|
|
31
|
+
assert.equal(h.requests.length,7);assert.equal(h.confirmations(),0);assert.equal(h.records.length,7);
|
|
32
|
+
h.setDecision("deny");assert.equal((await h.call("custom_tool",{action:"publish"})).block,true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("Auto cannot bypass data-loss, configured confirmation, protected paths or independent consent",async t=>{
|
|
36
|
+
const h=harness(t);await h.enable();await h.input("Implement the feature");
|
|
37
|
+
assert.equal((await h.call("bash",{command:"git reset --hard"})).block,true);assert.equal(h.confirmations(),0,"existing unconditional destructive block remains");assert.equal(h.requests.length,0);
|
|
38
|
+
writeFileSync(join(h.home,"runtime-guardrails.json"),JSON.stringify({guardedCommands:{gitPush:"confirm"}}));
|
|
39
|
+
assert.equal((await h.call("bash",{command:"git push origin feature"})).block,true);assert.equal(h.confirmations(),1);assert.equal(h.requests.length,0);
|
|
40
|
+
assert.equal((await h.call("write",{path:join(h.home,"permission-mode.json"),content:"yolo"})).block,true);
|
|
41
|
+
for(const tool of ["gentle_review","gentle_review_capture","ask_user_choice"]){assert.equal(await h.call(tool,{}),undefined);}
|
|
42
|
+
assert.equal(h.requests.length,0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("normal mode preserves previous guard behavior and named children do not inherit Auto",async t=>{
|
|
46
|
+
const h=harness(t);assert.equal((await h.call("bash",{command:"git push origin feature"})).block,true);assert.equal(h.requests.length,0);
|
|
47
|
+
await h.enable();await h.emit("before_agent_start",{agent:{name:"worker"},systemPromptOptions:{}});
|
|
48
|
+
assert.equal((await h.call("bash",{command:"git push origin feature"})).block,true);assert.equal(h.requests.length,0);
|
|
49
|
+
});
|