gentle-pi 4.7.0 → 4.8.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 +55 -44
- package/assets/agents/gentle-ai-explore.md +3 -3
- package/assets/agents/gentle-ai-verify.md +20 -6
- package/assets/agents/gentle-ai-worker.md +6 -6
- package/assets/agents/jd-judge-a.md +1 -3
- package/assets/agents/jd-judge-b.md +1 -3
- package/assets/agents/review-readability.md +1 -5
- package/assets/agents/review-reliability.md +1 -5
- package/assets/agents/review-resilience.md +1 -5
- package/assets/agents/review-risk.md +1 -5
- package/assets/design-canvas/canvas-api.js +45 -0
- package/assets/design-canvas/canvas-boards.js +456 -0
- package/assets/design-canvas/canvas-boot.js +217 -0
- package/assets/design-canvas/canvas-checks.js +491 -0
- package/assets/design-canvas/canvas-comments.js +315 -0
- package/assets/design-canvas/canvas-compare.js +159 -0
- package/assets/design-canvas/canvas-events.js +75 -0
- package/assets/design-canvas/canvas-export.js +393 -0
- package/assets/design-canvas/canvas-focus.js +203 -0
- package/assets/design-canvas/canvas-handoffs.js +150 -0
- package/assets/design-canvas/canvas-i18n-es.js +392 -0
- package/assets/design-canvas/canvas-i18n.js +108 -0
- package/assets/design-canvas/canvas-layout.js +526 -0
- package/assets/design-canvas/canvas-menu.js +213 -0
- package/assets/design-canvas/canvas-messages.js +86 -0
- package/assets/design-canvas/canvas-minimap.js +163 -0
- package/assets/design-canvas/canvas-parts.js +401 -0
- package/assets/design-canvas/canvas-popover.js +234 -0
- package/assets/design-canvas/canvas-rail.js +348 -0
- package/assets/design-canvas/canvas-sizes.js +524 -0
- package/assets/design-canvas/canvas-store.js +164 -0
- package/assets/design-canvas/canvas-tokens.js +674 -0
- package/assets/design-canvas/canvas-ui.js +24 -0
- package/assets/design-canvas/canvas-view.js +184 -0
- package/assets/design-canvas/canvas.css +746 -15
- package/assets/design-canvas/canvas.js +2 -1506
- package/assets/design-canvas/index.html +117 -36
- package/assets/design-canvas/inspector.js +546 -16
- package/assets/install-wizard/wizard.js +5 -1
- package/assets/migrations/agent-body-history.json +24 -0
- package/assets/orchestrator-delegation-reference.md +8 -14
- package/assets/orchestrator-delegation.md +4 -4
- package/assets/orchestrator-full-delegation-card.md +4 -5
- package/assets/orchestrator-full-delegation.md +8 -8
- package/assets/orchestrator-memory.md +2 -2
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-quota-recovery.md +5 -0
- package/assets/orchestrator-skills.md +13 -12
- package/assets/orchestrator-tracking.md +10 -14
- package/assets/orchestrator-verification.md +10 -8
- package/assets/orchestrator-writer.md +4 -4
- package/assets/orchestrator.md +18 -22
- package/bin/gentle-shell.mjs +128 -9
- package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
- package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
- package/docs/assets/brand/sponsor-banner.svg +60 -0
- package/docs/bundled-install.md +14 -6
- package/docs/delegated-verification.md +18 -2
- package/docs/desktop-rpc.md +1253 -0
- package/docs/gentle-agents-activity.md +26 -0
- package/docs/gentle-shell.md +39 -16
- package/docs/install-wizard.md +30 -21
- package/docs/odd-preparation-continuity.md +24 -0
- package/docs/permission-modes.md +9 -1
- package/docs/prompt-budget.md +12 -0
- package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
- package/docs/readme-reference.md +76 -24
- package/docs/review-coordinator.md +29 -9
- package/docs/review-delivery-preflight.md +22 -0
- package/docs/work-continuity.md +11 -1
- package/extensions/ask-user-question.ts +2 -2
- package/extensions/child-context.ts +21 -7
- package/extensions/gentle-agents.ts +234 -33
- package/extensions/gentle-ai.ts +576 -135
- package/extensions/gentle-design.ts +69 -3
- package/extensions/gentle-desktop-rpc.ts +143 -0
- package/extensions/gentle-guide.ts +3 -0
- package/extensions/gentle-shell.ts +105 -52
- package/extensions/gentle-todo.ts +48 -25
- package/extensions/skill-registry.ts +248 -223
- package/lib/agent-assets.ts +30 -6
- package/lib/agent-tool-overlay.ts +117 -0
- package/lib/agents-config.ts +47 -6
- package/lib/agents-message-delivery.ts +17 -0
- package/lib/agents-messaging.ts +8 -2
- package/lib/agents-protocol.ts +15 -0
- package/lib/agents-report-cap.ts +115 -0
- package/lib/agents-runner.ts +91 -6
- package/lib/agents-session-transport.ts +17 -1
- package/lib/background-jobs-tools.ts +9 -4
- package/lib/bounded-writer-admission.ts +184 -31
- package/lib/child-context-files.ts +21 -6
- package/lib/codemode-renderer.ts +1 -0
- package/lib/delivery-conflict-markers.ts +349 -0
- package/lib/design-canvas-assets.ts +36 -0
- package/lib/design-canvas-server.ts +241 -23
- package/lib/design-comments.ts +94 -4
- package/lib/design-handoffs.ts +2 -1
- package/lib/design-layout.ts +125 -0
- package/lib/design-parts.ts +281 -0
- package/lib/design-system-tokens.ts +111 -0
- package/lib/desktop-agents-service.ts +294 -0
- package/lib/desktop-design-service.ts +233 -0
- package/lib/desktop-jobs-service.ts +263 -0
- package/lib/desktop-rpc-agents.ts +294 -0
- package/lib/desktop-rpc-config.ts +731 -0
- package/lib/desktop-rpc-design.ts +138 -0
- package/lib/desktop-rpc-jobs.ts +181 -0
- package/lib/desktop-rpc-permissions.ts +177 -0
- package/lib/desktop-rpc-profiles.ts +196 -0
- package/lib/desktop-rpc-usage.ts +229 -0
- package/lib/desktop-rpc.ts +225 -0
- package/lib/desktop-usage-service.ts +310 -0
- package/lib/destructive-command-guard.ts +188 -13
- package/lib/gentle-ai-renderer.ts +13 -1
- package/lib/gentle-design.ts +201 -14
- package/lib/gentle-shell-bundled.ts +100 -9
- package/lib/hidden-tools.ts +35 -0
- package/lib/inprocess-reviewer.ts +96 -12
- package/lib/model-fallback-policy.ts +9 -0
- package/lib/model-routing-authority.ts +9 -0
- package/lib/nan-provider.ts +42 -28
- package/lib/native-review-cli.ts +79 -4
- package/lib/orchestrator-discovery.ts +39 -2
- package/lib/reply-language-anchor.ts +27 -2
- package/lib/request-context-placement.ts +53 -0
- package/lib/review-candidate-view.ts +11 -1
- package/lib/review-continuation-registry.ts +17 -0
- package/lib/review-coordinator.ts +252 -8
- package/lib/review-delivery-preflight.ts +85 -0
- package/lib/review-host-relay.ts +5 -1
- package/lib/review-integration-v2.ts +56 -3
- package/lib/reviewer-stream.ts +87 -0
- package/lib/shell-prompt.ts +16 -3
- package/lib/shell-usage.ts +10 -0
- package/lib/vim-editor-adapter.ts +9 -2
- package/lib/writer-batch-admission.ts +55 -0
- package/lib/yolo-session-policy.ts +6 -1
- package/package.json +2 -2
- package/prompts/skill-creation.md +1 -10
- package/runtime/design-canvas-assets.mjs +37 -0
- package/runtime/gentle-shell-bundled.mjs +100 -9
- package/runtime/native-review-cli.mjs +79 -4
- package/runtime/review-integration-v2.mjs +56 -3
- package/scripts/bootstrap.cmd +2 -2
- package/scripts/bootstrap.sh +41 -4
- package/scripts/build-full-delegation-card.mjs +4 -0
- package/scripts/build-runtime-modules.mjs +1 -0
- package/scripts/gentle-ai-installer.mjs +10 -10
- package/scripts/gentle-ai-proxy.mjs +1 -1
- package/scripts/installer-downloads.mjs +34 -8
- package/scripts/installer-preflight.mjs +28 -17
- package/scripts/installer-probes.mjs +25 -5
- package/scripts/installer-server.mjs +38 -9
- package/scripts/installer-windows.mjs +2 -2
- package/scripts/pi-update.mjs +166 -27
- package/scripts/prepare-verifier.mjs +107 -0
- package/scripts/update-agent-body-history.mjs +55 -8
- package/scripts/verify-package-files.mjs +40 -19
- package/skills/branch-pr/SKILL.md +16 -16
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/design/SKILL.md +6 -6
- package/skills/gentle-ai/SKILL.md +5 -5
- package/skills/judgment-day/SKILL.md +2 -2
- package/skills/judgment-day/references/prompts-and-formats.md +1 -1
- package/skills/rdd-defect-workflow/SKILL.md +6 -6
- package/skills/skill-improver/SKILL.md +2 -2
- package/skills/skill-registry/SKILL.md +11 -13
- package/skills/tui-design/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +5 -5
- package/tests/agent-prompt-diet-contract.test.ts +101 -0
- package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
- package/tests/agent-tool-overlay.test.ts +89 -0
- package/tests/agents-config.test.ts +10 -1
- package/tests/agents-message-delivery.test.ts +36 -0
- package/tests/agents-queries.test.ts +144 -4
- package/tests/agents-report-cap.test.ts +126 -0
- package/tests/agents-runner.test.ts +37 -1
- package/tests/agents-session-transport.test.ts +34 -0
- package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
- package/tests/append-system-prompt-route.test.ts +10 -2
- package/tests/approved-text-leftovers-contract.test.ts +136 -0
- package/tests/artifact-language.test.ts +1 -1
- package/tests/ask-user-question.test.ts +2 -1
- package/tests/audit-leftovers-contract.test.ts +51 -0
- package/tests/bounded-stop-contract.test.ts +9 -1
- package/tests/branch-pr-skill.test.ts +10 -1
- package/tests/bundled-install.test.ts +1 -1
- package/tests/child-context-files.test.ts +64 -8
- package/tests/child-skills-catalog.test.ts +56 -0
- package/tests/codemode-rendering.test.ts +4 -1
- package/tests/delegate-for-reason-contract.test.ts +30 -8
- package/tests/delivery-conflict-markers.test.ts +348 -0
- package/tests/design-canvas-all-sizes.test.ts +631 -0
- package/tests/design-canvas-allowlist.test.ts +32 -0
- package/tests/design-canvas-assets.test.ts +11 -878
- package/tests/design-canvas-boards.test.ts +77 -0
- package/tests/design-canvas-checks.test.ts +655 -0
- package/tests/design-canvas-compare.test.ts +79 -0
- package/tests/design-canvas-events.test.ts +59 -0
- package/tests/design-canvas-export.test.ts +1168 -0
- package/tests/design-canvas-focus.test.ts +113 -0
- package/tests/design-canvas-handoffs.test.ts +59 -0
- package/tests/design-canvas-i18n-review.test.ts +513 -0
- package/tests/design-canvas-i18n-views.test.ts +259 -0
- package/tests/design-canvas-i18n.test.ts +526 -0
- package/tests/design-canvas-inspector.test.ts +937 -0
- package/tests/design-canvas-layout.test.ts +1222 -0
- package/tests/design-canvas-minimap.test.ts +413 -0
- package/tests/design-canvas-modules.test.ts +90 -0
- package/tests/design-canvas-parts.test.ts +721 -0
- package/tests/design-canvas-rail.test.ts +799 -0
- package/tests/design-canvas-server.test.ts +855 -17
- package/tests/design-canvas-sizes.test.ts +548 -0
- package/tests/design-canvas-store.test.ts +180 -0
- package/tests/design-canvas-tokens.test.ts +965 -0
- package/tests/design-canvas-view.test.ts +299 -0
- package/tests/design-comments.test.ts +201 -1
- package/tests/design-handoffs.test.ts +20 -0
- package/tests/design-layout.test.ts +100 -0
- package/tests/design-parts.test.ts +260 -0
- package/tests/design-system-tokens.test.ts +215 -0
- package/tests/desktop-rpc-agents.test.ts +893 -0
- package/tests/desktop-rpc-config.test.ts +1452 -0
- package/tests/desktop-rpc-design.test.ts +662 -0
- package/tests/desktop-rpc-jobs.test.ts +796 -0
- package/tests/desktop-rpc-permissions.test.ts +311 -0
- package/tests/desktop-rpc-profiles.test.ts +140 -0
- package/tests/desktop-rpc-safety.test.ts +119 -0
- package/tests/desktop-rpc-usage.test.ts +697 -0
- package/tests/desktop-rpc.test.ts +252 -0
- package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
- package/tests/devbinary/review-session-consent.devtest.ts +84 -0
- package/tests/engram-safety.test.ts +111 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
- package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
- package/tests/fixtures/refusal-identity.probe.mjs +139 -0
- package/tests/full-delegation-closure.test.ts +29 -0
- package/tests/gentle-agents.test.ts +329 -4
- package/tests/gentle-ai-binary.test.ts +1 -1
- package/tests/gentle-ai-child-guards.test.ts +1 -0
- package/tests/gentle-ai-installer.test.ts +52 -51
- package/tests/gentle-ai-renderer.test.ts +36 -2
- package/tests/gentle-ai.test.ts +121 -6
- package/tests/gentle-design.test.ts +365 -1
- package/tests/gentle-shell-bundled.test.ts +91 -5
- package/tests/gentle-shell-launcher.test.ts +1 -1
- package/tests/gentle-shell.test.ts +118 -87
- package/tests/gentle-todo.test.ts +32 -9
- package/tests/hidden-tools.test.ts +188 -0
- package/tests/independent-recovery-delivery.test.ts +19 -5
- package/tests/inprocess-reviewer.test.ts +73 -0
- package/tests/install-wizard.test.ts +27 -1
- package/tests/installer-downloads.test.ts +30 -1
- package/tests/installer-posix-bootstrap.test.ts +114 -13
- package/tests/installer-preflight.test.ts +49 -1
- package/tests/installer-probes.test.ts +146 -0
- package/tests/installer-server.test.ts +203 -4
- package/tests/installer-windows-bootstrap.test.ts +19 -1
- package/tests/judgment-day-severity-admission.test.ts +46 -0
- package/tests/lazy-module-contradictions-contract.test.ts +158 -0
- package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
- package/tests/maintainer/pi-update-source.maintest.ts +48 -18
- package/tests/model-fallback-policy.test.ts +26 -7
- package/tests/nan-provider-runtime.test.ts +17 -3
- package/tests/nan-provider.test.ts +111 -56
- package/tests/native-review-capability-contract.test.ts +11 -1
- package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
- package/tests/native-review-parity.test.ts +24 -5
- package/tests/native-review-refusal-identity.test.ts +25 -0
- package/tests/no-self-pause-contract.test.ts +11 -3
- package/tests/odd-integration.test.ts +11 -3
- package/tests/odd-routing-contract.test.ts +80 -28
- package/tests/orchestrator-budget.test.ts +30 -5
- package/tests/orchestrator-consultation-sdk.test.ts +32 -6
- package/tests/orchestrator-delegation-mode.test.ts +2 -1
- package/tests/orchestrator-discovery.test.ts +28 -0
- package/tests/orchestrator-prompt-budget.test.ts +11 -2
- package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
- package/tests/orchestrator-rdd-ownership.test.ts +2 -1
- package/tests/orchestrator-work-search.test.ts +4 -2
- package/tests/package-files.test.ts +25 -1
- package/tests/package-manifest.test.ts +11 -10
- package/tests/parallel-reason-contract.test.ts +6 -3
- package/tests/permission-allowlist.test.ts +200 -30
- package/tests/persona-neutral-voseo.test.ts +4 -4
- package/tests/persona-reply-language.test.ts +1 -1
- package/tests/persona-single-channel.test.ts +13 -5
- package/tests/pi-update-launcher.test.ts +17 -7
- package/tests/pi-update-source.test.ts +113 -6
- package/tests/pi-update.test.ts +294 -19
- package/tests/pnpm-workspace-policy.test.ts +47 -0
- package/tests/primary-context-files.test.ts +233 -0
- package/tests/primary-context-three-files.test.ts +174 -0
- package/tests/provider-defect-handoff.test.ts +9 -2
- package/tests/rdd-aware-verification-contract.test.ts +1 -1
- package/tests/rdd-status-line.test.ts +94 -1
- package/tests/reply-language-anchor-placement.test.ts +184 -0
- package/tests/reply-language-anchor.test.ts +17 -1
- package/tests/request-context-append-only.test.ts +218 -0
- package/tests/request-context-placement.test.ts +148 -0
- package/tests/review-agent-end-preflight.test.ts +79 -1
- package/tests/review-candidate-view.test.ts +65 -0
- package/tests/review-continuation-registry.test.ts +31 -0
- package/tests/review-contract-prompt.test.ts +1 -1
- package/tests/review-controller.test.ts +2 -1
- package/tests/review-coordinator-correction-gate.test.ts +105 -0
- package/tests/review-coordinator-findings.test.ts +206 -0
- package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
- package/tests/review-coordinator.test.ts +271 -4
- package/tests/review-delivery-preflight.test.ts +462 -0
- package/tests/review-due-compaction.test.ts +31 -0
- package/tests/review-due-public-boundary.test.ts +26 -0
- package/tests/review-integration-nonblocking-findings.test.ts +108 -0
- package/tests/review-json-arguments.test.ts +41 -2
- package/tests/review-ledger-contract.test.ts +19 -40
- package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
- package/tests/review-one-call-findings.test.ts +131 -0
- package/tests/review-one-call-followups.test.ts +308 -0
- package/tests/review-one-call-reviewer-requests.test.ts +207 -0
- package/tests/review-one-call.test.ts +452 -0
- package/tests/review-relay-transport-agent.test.ts +28 -1
- package/tests/review-reviewer-evidence.test.ts +41 -1
- package/tests/review-risk-assessment.test.ts +52 -5
- package/tests/review-run-statement-guidance-independent.test.ts +54 -0
- package/tests/review-session-standing-permission-controller.test.ts +32 -2
- package/tests/review-tool-prose-budget.test.ts +1 -0
- package/tests/reviewer-stream.test.ts +149 -0
- package/tests/session-profile-extension.test.ts +2 -2
- package/tests/shell-prompt.test.ts +17 -0
- package/tests/shell-usage.test.ts +59 -10
- package/tests/skill-contradictions-contract.test.ts +122 -0
- package/tests/skill-registry-watcher.test.ts +216 -2
- package/tests/skill-registry.test.ts +929 -306
- package/tests/support/design-canvas-dom.ts +369 -0
- package/tests/support/review-coordinator-runtime.ts +212 -17
- package/tests/task-size-routing-contract.test.ts +42 -11
- package/tests/test-strength-contract.test.ts +2 -1
- package/tests/todo-request-append-only.test.ts +214 -0
- package/tests/tool-batching-contract.test.ts +3 -1
- package/tests/update-agent-body-history.test.ts +138 -0
- package/tests/verification-tiers-contract.test.ts +229 -0
- package/tests/verifier-preparation.test.ts +229 -0
- package/tests/verify-agent-contract.test.ts +20 -2
- package/tests/verify-first-launch-contract.test.ts +87 -11
- package/tests/vim-editor-adapter.test.ts +2 -2
- package/tests/work-continuity-contract.test.ts +54 -11
- package/tests/writer-admission-messages.test.ts +232 -0
- package/tests/writer-batch-admission.test.ts +66 -0
- package/tests/writer-edit-surface-scope.test.ts +52 -20
- package/tests/writer-feature-document-admission.test.ts +184 -0
- package/tests/yolo-mode.test.ts +39 -0
- package/skills/_shared/review-ledger-contract.md +0 -106
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
- /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test, { after, before } from "node:test";
|
|
3
|
+
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
|
|
8
|
+
import { ORCHESTRATOR_ONLY_MANAGED_BLOCKS } from "../lib/child-context-files.ts";
|
|
9
|
+
|
|
10
|
+
// The primary session loads ancestor context files such as a gentle-ai
|
|
11
|
+
// managed ~/AGENTS.md, whose orchestrator-only blocks carry a second
|
|
12
|
+
// orchestrator policy next to the one Gentle Shell injects. Whenever Gentle
|
|
13
|
+
// Shell's own orchestrator prompt is injected, the primary drops the same
|
|
14
|
+
// blocks a delegated child drops (gentle-shell#1587) plus the engram-protocol
|
|
15
|
+
// memory block, which gentle-engram injects itself. Everything else stays.
|
|
16
|
+
|
|
17
|
+
type Handler = (event: unknown, ctx: ExtensionContext) => unknown;
|
|
18
|
+
|
|
19
|
+
function block(name: string, body: string): string {
|
|
20
|
+
return `<!-- gentle-ai:${name} -->\n${body}\n<!-- /gentle-ai:${name} -->`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const REMOTE_AUTHORIZATION = block("remote-authorization", "## Remote operation authorization\n\nAsk before remote work.");
|
|
24
|
+
const ENGRAM_PROTOCOL = block("engram-protocol", "## Engram\n\nSave decisions.");
|
|
25
|
+
|
|
26
|
+
const MANAGED_AGENTS_MD = [
|
|
27
|
+
"# My own notes",
|
|
28
|
+
"",
|
|
29
|
+
"Prefer small commits.",
|
|
30
|
+
"",
|
|
31
|
+
block("orchestrator", "## Agent Teams Lite\n\nYou are a COORDINATOR."),
|
|
32
|
+
"",
|
|
33
|
+
block("sdd-orchestrator", [
|
|
34
|
+
"# SDD orchestrator",
|
|
35
|
+
"",
|
|
36
|
+
block("sdd-model-assignments", "| Phase | Model |\n|---|---|\n| sdd-apply | sonnet |"),
|
|
37
|
+
].join("\n")),
|
|
38
|
+
"",
|
|
39
|
+
ENGRAM_PROTOCOL,
|
|
40
|
+
"",
|
|
41
|
+
block("agent-routing", [
|
|
42
|
+
"## Implementation Routing",
|
|
43
|
+
"",
|
|
44
|
+
"Delegate on the 4-file rule.",
|
|
45
|
+
"",
|
|
46
|
+
REMOTE_AUTHORIZATION,
|
|
47
|
+
].join("\n")),
|
|
48
|
+
"",
|
|
49
|
+
"## Closing notes",
|
|
50
|
+
"Keep lines short.",
|
|
51
|
+
"",
|
|
52
|
+
].join("\n");
|
|
53
|
+
|
|
54
|
+
const EXPECTED_PRIMARY = [
|
|
55
|
+
"# My own notes",
|
|
56
|
+
"",
|
|
57
|
+
"Prefer small commits.",
|
|
58
|
+
"",
|
|
59
|
+
REMOTE_AUTHORIZATION,
|
|
60
|
+
"",
|
|
61
|
+
"## Closing notes",
|
|
62
|
+
"Keep lines short.",
|
|
63
|
+
"",
|
|
64
|
+
].join("\n");
|
|
65
|
+
|
|
66
|
+
// A project file that carries only its own engram-protocol block.
|
|
67
|
+
const PROJECT_AGENTS_MD = `# Repo rules\n\nRun the tests.\n\n${ENGRAM_PROTOCOL}\n`;
|
|
68
|
+
const PROJECT_AGENTS_MD_FILTERED = "# Repo rules\n\nRun the tests.\n";
|
|
69
|
+
|
|
70
|
+
let fixtureCwd: string;
|
|
71
|
+
let fixtureRoot: string | undefined;
|
|
72
|
+
const fixtureEnvironment: NodeJS.ProcessEnv = {};
|
|
73
|
+
const previousEnvironment = new Map<string, string | undefined>();
|
|
74
|
+
before(async () => {
|
|
75
|
+
const root = await mkdtemp(join(tmpdir(), "gentle-pi-primary-context-"));
|
|
76
|
+
fixtureRoot = root;
|
|
77
|
+
fixtureCwd = join(root, "project");
|
|
78
|
+
const home = join(root, "home");
|
|
79
|
+
for (const directory of [fixtureCwd, home]) await mkdir(directory);
|
|
80
|
+
Object.assign(fixtureEnvironment, {
|
|
81
|
+
HOME: home, USERPROFILE: home,
|
|
82
|
+
GENTLE_PI_CONFIG_HOME: join(home, "config"),
|
|
83
|
+
GENTLE_PI_AGENT_HOME: join(home, "agents"),
|
|
84
|
+
PI_CODING_AGENT_DIR: join(home, "pi"),
|
|
85
|
+
XDG_CONFIG_HOME: join(home, "xdg"),
|
|
86
|
+
});
|
|
87
|
+
for (const [key, value] of Object.entries(fixtureEnvironment)) {
|
|
88
|
+
previousEnvironment.set(key, process.env[key]);
|
|
89
|
+
process.env[key] = value;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
after(async () => {
|
|
93
|
+
for (const [key, value] of previousEnvironment) {
|
|
94
|
+
if (value === undefined) delete process.env[key];
|
|
95
|
+
else process.env[key] = value;
|
|
96
|
+
}
|
|
97
|
+
if (fixtureRoot !== undefined) await rm(fixtureRoot, { recursive: true, force: true });
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function beforeAgentStart(options: { processEnv?: NodeJS.ProcessEnv } = {}): Handler {
|
|
101
|
+
const handlers = new Map<string, Handler>();
|
|
102
|
+
const pi = {
|
|
103
|
+
on(name: string, handler: Handler) {
|
|
104
|
+
handlers.set(name, handler);
|
|
105
|
+
},
|
|
106
|
+
events: { emit() {} },
|
|
107
|
+
registerCommand() {},
|
|
108
|
+
registerTool() {},
|
|
109
|
+
} as unknown as ExtensionAPI;
|
|
110
|
+
createGentleAiExtension({
|
|
111
|
+
nativeReviewCli: null,
|
|
112
|
+
processEnv: { ...fixtureEnvironment, GENTLE_PI_AGENTS_CHILD: "0", ...options.processEnv, GENTLE_AI_TELEMETRY: "0" },
|
|
113
|
+
resolveTelemetryTriggerBinary: () => join(fixtureCwd, "never-executed"),
|
|
114
|
+
telemetryTriggerSpawn: () => assert.fail("Primary context fixtures must not spawn telemetry"),
|
|
115
|
+
})(pi);
|
|
116
|
+
return handlers.get("before_agent_start")!;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function ctx(): ExtensionContext {
|
|
120
|
+
return {
|
|
121
|
+
cwd: fixtureCwd,
|
|
122
|
+
hasUI: true,
|
|
123
|
+
ui: { notify() {}, setWidget() {} },
|
|
124
|
+
sessionManager: { getSessionId: () => "primary-context-session", getBranch: () => [] },
|
|
125
|
+
} as unknown as ExtensionContext;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Pi's order: files from the root toward the working directory, nearest last.
|
|
129
|
+
// The home file sits in an ancestor of the project directory (the cwd).
|
|
130
|
+
function startEvent(options: { extra?: Record<string, unknown>; home?: string; project?: string } = {}) {
|
|
131
|
+
const contextFiles = [
|
|
132
|
+
{ path: join(fixtureRoot!, "AGENTS.md"), content: options.home ?? MANAGED_AGENTS_MD },
|
|
133
|
+
{ path: join(fixtureCwd, "AGENTS.md"), content: options.project ?? PROJECT_AGENTS_MD },
|
|
134
|
+
];
|
|
135
|
+
const systemPromptOptions = { appendSystemPrompt: "", contextFiles };
|
|
136
|
+
return { contextFiles, systemPromptOptions, event: { systemPrompt: "base", systemPromptOptions, ...options.extra } };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const ORCHESTRATOR_HEADING = /el Gentleman Identity and Harness/;
|
|
140
|
+
|
|
141
|
+
for (const name of ORCHESTRATOR_ONLY_MANAGED_BLOCKS) {
|
|
142
|
+
test(`the primary drops the ${name} block while Gentle Shell's orchestrator is injected`, async () => {
|
|
143
|
+
const home = `Before\n\n${block(name, "Orchestrator only\n\nMore text")}\n\nAfter\n`;
|
|
144
|
+
const { systemPromptOptions, event } = startEvent({ home });
|
|
145
|
+
await beforeAgentStart()(event, ctx());
|
|
146
|
+
assert.match(systemPromptOptions.appendSystemPrompt, ORCHESTRATOR_HEADING, "Gentle Shell's orchestrator is active");
|
|
147
|
+
assert.equal(systemPromptOptions.contextFiles[0].content, "Before\n\nAfter\n");
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
test("the primary filters a managed AGENTS.md on the same options object without mutating the loaded entries", async () => {
|
|
152
|
+
const { contextFiles, systemPromptOptions, event } = startEvent({ project: "# Repo rules\n" });
|
|
153
|
+
const result = await beforeAgentStart()(event, ctx());
|
|
154
|
+
assert.equal(result, undefined, "the handler never returns a replacement system prompt");
|
|
155
|
+
assert.match(systemPromptOptions.appendSystemPrompt, ORCHESTRATOR_HEADING);
|
|
156
|
+
assert.equal(event.systemPromptOptions, systemPromptOptions, "the same options object stays in place");
|
|
157
|
+
assert.notEqual(systemPromptOptions.contextFiles, contextFiles, "filtered copies replace contextFiles");
|
|
158
|
+
assert.equal(contextFiles[0].content, MANAGED_AGENTS_MD, "the original entries are never mutated");
|
|
159
|
+
assert.deepEqual(systemPromptOptions.contextFiles.map((file) => file.path), contextFiles.map((file) => file.path));
|
|
160
|
+
assert.equal(systemPromptOptions.contextFiles[0].content, EXPECTED_PRIMARY, "the engram-protocol block is dropped");
|
|
161
|
+
assert.doesNotMatch(systemPromptOptions.contextFiles[0].content, /COORDINATOR|SDD orchestrator|sdd-apply|Implementation Routing|4-file rule|engram-protocol/);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("with engram-protocol in two loaded files the primary drops both copies", async () => {
|
|
165
|
+
const { contextFiles, systemPromptOptions, event } = startEvent();
|
|
166
|
+
await beforeAgentStart()(event, ctx());
|
|
167
|
+
assert.equal(systemPromptOptions.contextFiles[0].content, EXPECTED_PRIMARY, "the home copy goes");
|
|
168
|
+
assert.equal(systemPromptOptions.contextFiles[1].content, PROJECT_AGENTS_MD_FILTERED, "the project copy goes too");
|
|
169
|
+
assert.equal(contextFiles[1].content, PROJECT_AGENTS_MD, "the loaded entry is never mutated on disk");
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("the nested remote-authorization block survives in the primary although its enclosing agent-routing block is dropped", async () => {
|
|
173
|
+
const { systemPromptOptions, event } = startEvent();
|
|
174
|
+
await beforeAgentStart()(event, ctx());
|
|
175
|
+
const home = systemPromptOptions.contextFiles[0].content;
|
|
176
|
+
assert.ok(!home.includes("gentle-ai:agent-routing -->"), "the enclosing agent-routing block is dropped");
|
|
177
|
+
assert.ok(home.includes(REMOTE_AUTHORIZATION), "remote-authorization stays byte-for-byte");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("two engram-protocol copies at the same level, or off the working-directory chain, are all dropped", async () => {
|
|
181
|
+
for (const paths of [
|
|
182
|
+
[join(fixtureCwd, "AGENTS.md"), join(fixtureCwd, "CLAUDE.md")],
|
|
183
|
+
[join(fixtureRoot!, "elsewhere", "AGENTS.md"), join(fixtureCwd, "AGENTS.md")],
|
|
184
|
+
["relative/AGENTS.md", join(fixtureCwd, "AGENTS.md")],
|
|
185
|
+
]) {
|
|
186
|
+
const { contextFiles, systemPromptOptions, event } = startEvent({ home: PROJECT_AGENTS_MD });
|
|
187
|
+
contextFiles[0].path = paths[0];
|
|
188
|
+
contextFiles[1].path = paths[1];
|
|
189
|
+
await beforeAgentStart()(event, ctx());
|
|
190
|
+
assert.deepEqual(systemPromptOptions.contextFiles.map((file) => file.content), [PROJECT_AGENTS_MD_FILTERED, PROJECT_AGENTS_MD_FILTERED], `both copies go for ${paths[0]}`);
|
|
191
|
+
assert.deepEqual(contextFiles.map((file) => file.content), [PROJECT_AGENTS_MD, PROJECT_AGENTS_MD], "the loaded entries stay untouched");
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("user-authored text outside managed markers stays byte-for-byte in the primary", async () => {
|
|
196
|
+
const { systemPromptOptions, event } = startEvent();
|
|
197
|
+
await beforeAgentStart()(event, ctx());
|
|
198
|
+
const home = systemPromptOptions.contextFiles[0].content;
|
|
199
|
+
assert.ok(home.startsWith("# My own notes\n\nPrefer small commits.\n\n"));
|
|
200
|
+
assert.ok(home.endsWith("\n\n## Closing notes\nKeep lines short.\n"));
|
|
201
|
+
assert.ok(systemPromptOptions.contextFiles[1].content.startsWith("# Repo rules\n\nRun the tests.\n"));
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
test("a second primary turn over already-filtered context files removes nothing more", async () => {
|
|
205
|
+
const handler = beforeAgentStart();
|
|
206
|
+
const { contextFiles, systemPromptOptions, event } = startEvent();
|
|
207
|
+
await handler(event, ctx());
|
|
208
|
+
const filtered = systemPromptOptions.contextFiles;
|
|
209
|
+
assert.notEqual(filtered, contextFiles, "the first turn filtered");
|
|
210
|
+
await handler(event, ctx());
|
|
211
|
+
assert.equal(systemPromptOptions.contextFiles, filtered);
|
|
212
|
+
assert.equal(filtered[1].content, PROJECT_AGENTS_MD_FILTERED, "the already-filtered copy is never touched again");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
for (const scenario of ["child", "named-agent"] as const) {
|
|
216
|
+
test(`a ${scenario} start, where Gentle Shell's orchestrator is not injected, leaves context files untouched`, async () => {
|
|
217
|
+
const { contextFiles, systemPromptOptions, event } = startEvent({
|
|
218
|
+
extra: scenario === "named-agent" ? { agentName: "gentle-ai-worker" } : {},
|
|
219
|
+
});
|
|
220
|
+
await beforeAgentStart({ processEnv: scenario === "child" ? { GENTLE_PI_AGENTS_CHILD: "1" } : {} })(event, ctx());
|
|
221
|
+
assert.doesNotMatch(systemPromptOptions.appendSystemPrompt, ORCHESTRATOR_HEADING);
|
|
222
|
+
assert.equal(systemPromptOptions.contextFiles, contextFiles);
|
|
223
|
+
assert.equal(systemPromptOptions.contextFiles[0].content, MANAGED_AGENTS_MD);
|
|
224
|
+
assert.equal(systemPromptOptions.contextFiles[1].content, PROJECT_AGENTS_MD);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
test("malformed managed markers leave the primary context file unchanged", async () => {
|
|
229
|
+
const unbalanced = `<!-- gentle-ai:orchestrator -->\nno close\n${ENGRAM_PROTOCOL}\n`;
|
|
230
|
+
const { systemPromptOptions, event } = startEvent({ home: unbalanced });
|
|
231
|
+
await beforeAgentStart()(event, ctx());
|
|
232
|
+
assert.equal(systemPromptOptions.contextFiles[0].content, unbalanced);
|
|
233
|
+
});
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test, { after, before } from "node:test";
|
|
3
|
+
import { mkdir, mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
|
|
8
|
+
import { filterChildSessionContextFiles } from "../lib/child-context-files.ts";
|
|
9
|
+
|
|
10
|
+
// Three loaded context files in Pi's order (root toward the working directory):
|
|
11
|
+
// a home file with every managed block, a project file with engram-protocol and
|
|
12
|
+
// agent-routing, and a nested package file with user text only. With Gentle
|
|
13
|
+
// Shell's orchestrator injected, the primary drops the orchestrator-only blocks
|
|
14
|
+
// and the engram-protocol memory block, and keeps remote-authorization.
|
|
15
|
+
|
|
16
|
+
type Handler = (event: unknown, ctx: ExtensionContext) => unknown;
|
|
17
|
+
|
|
18
|
+
function block(name: string, body: string): string {
|
|
19
|
+
return `<!-- gentle-ai:${name} -->\n${body}\n<!-- /gentle-ai:${name} -->`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const REMOTE_AUTHORIZATION = block("remote-authorization", "## Remote operation authorization\n\nNo remote without consent.");
|
|
23
|
+
const ENGRAM_HOME = block("engram-protocol", "## Engram HOME copy\n\nrule H.");
|
|
24
|
+
const ENGRAM_PROJECT = block("engram-protocol", "## Engram PROJECT copy\n\nrule P.");
|
|
25
|
+
|
|
26
|
+
const HOME_MD = [
|
|
27
|
+
"# Home notes",
|
|
28
|
+
"",
|
|
29
|
+
"keep me 1",
|
|
30
|
+
"",
|
|
31
|
+
block("orchestrator", "## Teams\n\nCOORD"),
|
|
32
|
+
"",
|
|
33
|
+
block("sdd-orchestrator", `# SDD\n\n${block("sdd-model-assignments", "| a | b |")}`),
|
|
34
|
+
"",
|
|
35
|
+
ENGRAM_HOME,
|
|
36
|
+
"",
|
|
37
|
+
block("agent-routing", `## Routing\n\nrules\n\n${REMOTE_AUTHORIZATION}`),
|
|
38
|
+
"",
|
|
39
|
+
"## Tail",
|
|
40
|
+
"keep me 2",
|
|
41
|
+
"",
|
|
42
|
+
].join("\n");
|
|
43
|
+
const HOME_EXPECTED = ["# Home notes", "", "keep me 1", "", REMOTE_AUTHORIZATION, "", "## Tail", "keep me 2", ""].join("\n");
|
|
44
|
+
|
|
45
|
+
const PROJECT_MD = [
|
|
46
|
+
"# Project",
|
|
47
|
+
"",
|
|
48
|
+
"proj text",
|
|
49
|
+
"",
|
|
50
|
+
ENGRAM_PROJECT,
|
|
51
|
+
"",
|
|
52
|
+
block("agent-routing", "## Implementation Routing\n\n### Receipt-driven development is user-owned\n\nx"),
|
|
53
|
+
"",
|
|
54
|
+
].join("\n");
|
|
55
|
+
const PROJECT_EXPECTED = ["# Project", "", "proj text", ""].join("\n");
|
|
56
|
+
|
|
57
|
+
const NESTED_MD = "# Package notes\n\nOnly user text here.\n";
|
|
58
|
+
|
|
59
|
+
let fixtureRoot: string | undefined;
|
|
60
|
+
let homeDir: string;
|
|
61
|
+
let projectDir: string;
|
|
62
|
+
let packageDir: string;
|
|
63
|
+
const fixtureEnvironment: NodeJS.ProcessEnv = {};
|
|
64
|
+
const previousEnvironment = new Map<string, string | undefined>();
|
|
65
|
+
before(async () => {
|
|
66
|
+
const root = await mkdtemp(join(tmpdir(), "gentle-pi-three-context-files-"));
|
|
67
|
+
fixtureRoot = root;
|
|
68
|
+
homeDir = join(root, "home");
|
|
69
|
+
projectDir = join(homeDir, "work", "proj");
|
|
70
|
+
packageDir = join(projectDir, "pkg");
|
|
71
|
+
await mkdir(packageDir, { recursive: true });
|
|
72
|
+
Object.assign(fixtureEnvironment, {
|
|
73
|
+
HOME: homeDir, USERPROFILE: homeDir,
|
|
74
|
+
GENTLE_PI_CONFIG_HOME: join(root, "config"),
|
|
75
|
+
GENTLE_PI_AGENT_HOME: join(root, "agents"),
|
|
76
|
+
PI_CODING_AGENT_DIR: join(root, "pi"),
|
|
77
|
+
XDG_CONFIG_HOME: join(root, "xdg"),
|
|
78
|
+
});
|
|
79
|
+
for (const [key, value] of Object.entries(fixtureEnvironment)) {
|
|
80
|
+
previousEnvironment.set(key, process.env[key]);
|
|
81
|
+
process.env[key] = value;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
after(async () => {
|
|
85
|
+
for (const [key, value] of previousEnvironment) {
|
|
86
|
+
if (value === undefined) delete process.env[key];
|
|
87
|
+
else process.env[key] = value;
|
|
88
|
+
}
|
|
89
|
+
if (fixtureRoot !== undefined) await rm(fixtureRoot, { recursive: true, force: true });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
function beforeAgentStart(processEnv: NodeJS.ProcessEnv = {}): Handler {
|
|
93
|
+
const handlers = new Map<string, Handler>();
|
|
94
|
+
const pi = {
|
|
95
|
+
on(name: string, handler: Handler) {
|
|
96
|
+
handlers.set(name, handler);
|
|
97
|
+
},
|
|
98
|
+
events: { emit() {} },
|
|
99
|
+
registerCommand() {},
|
|
100
|
+
registerTool() {},
|
|
101
|
+
} as unknown as ExtensionAPI;
|
|
102
|
+
createGentleAiExtension({
|
|
103
|
+
nativeReviewCli: null,
|
|
104
|
+
processEnv: { ...fixtureEnvironment, GENTLE_PI_AGENTS_CHILD: "0", ...processEnv, GENTLE_AI_TELEMETRY: "0" },
|
|
105
|
+
resolveTelemetryTriggerBinary: () => join(fixtureRoot!, "never-executed"),
|
|
106
|
+
telemetryTriggerSpawn: () => assert.fail("Context file fixtures must not spawn telemetry"),
|
|
107
|
+
})(pi);
|
|
108
|
+
return handlers.get("before_agent_start")!;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function ctx(cwd: string): ExtensionContext {
|
|
112
|
+
return {
|
|
113
|
+
cwd,
|
|
114
|
+
hasUI: true,
|
|
115
|
+
ui: { notify() {}, setWidget() {} },
|
|
116
|
+
sessionManager: { getSessionId: () => "three-context-files-session", getBranch: () => [] },
|
|
117
|
+
} as unknown as ExtensionContext;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function startEvent(extra: Record<string, unknown> = {}) {
|
|
121
|
+
const contextFiles = [
|
|
122
|
+
{ path: join(homeDir, "AGENTS.md"), content: HOME_MD },
|
|
123
|
+
{ path: join(projectDir, "AGENTS.md"), content: PROJECT_MD },
|
|
124
|
+
{ path: join(packageDir, "AGENTS.md"), content: NESTED_MD },
|
|
125
|
+
];
|
|
126
|
+
const systemPromptOptions = { appendSystemPrompt: "", contextFiles };
|
|
127
|
+
return { contextFiles, systemPromptOptions, event: { systemPrompt: "base", systemPromptOptions, ...extra } };
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (const mode of ["organic", "full-delegation"] as const) {
|
|
131
|
+
test(`${mode}: three context files keep exactly the expected bytes`, async () => {
|
|
132
|
+
const { contextFiles, systemPromptOptions, event } = startEvent();
|
|
133
|
+
await beforeAgentStart({ GENTLE_PI_ORCHESTRATOR_MODE: mode })(event, ctx(packageDir));
|
|
134
|
+
assert.match(systemPromptOptions.appendSystemPrompt, /el Gentleman Identity and Harness/);
|
|
135
|
+
if (mode === "full-delegation") assert.match(systemPromptOptions.appendSystemPrompt, /COORDINATOR in full delegation mode/);
|
|
136
|
+
else assert.doesNotMatch(systemPromptOptions.appendSystemPrompt, /COORDINATOR in full delegation mode/);
|
|
137
|
+
assert.deepEqual(systemPromptOptions.contextFiles.map((file) => file.content), [HOME_EXPECTED, PROJECT_EXPECTED, NESTED_MD]);
|
|
138
|
+
assert.deepEqual(contextFiles.map((file) => file.content), [HOME_MD, PROJECT_MD, NESTED_MD], "the loaded entries are never mutated");
|
|
139
|
+
const filtered = systemPromptOptions.contextFiles;
|
|
140
|
+
await beforeAgentStart({ GENTLE_PI_ORCHESTRATOR_MODE: mode })(event, ctx(packageDir));
|
|
141
|
+
assert.equal(systemPromptOptions.contextFiles, filtered, "a second turn removes nothing more");
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
test("child and named-agent starts leave the three context files untouched", async () => {
|
|
146
|
+
const scenarios: Array<[Record<string, unknown>, NodeJS.ProcessEnv]> = [
|
|
147
|
+
[{}, { GENTLE_PI_AGENTS_CHILD: "1" }],
|
|
148
|
+
[{ agentName: "gentle-ai-worker" }, {}],
|
|
149
|
+
];
|
|
150
|
+
for (const [extra, processEnv] of scenarios) {
|
|
151
|
+
const { contextFiles, systemPromptOptions, event } = startEvent(extra);
|
|
152
|
+
await beforeAgentStart(processEnv)(event, ctx(packageDir));
|
|
153
|
+
assert.equal(systemPromptOptions.contextFiles, contextFiles);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
test("hostile input never throws, and a malformed file never costs another file its filtering", () => {
|
|
158
|
+
assert.doesNotThrow(() => filterChildSessionContextFiles({ contextFiles: [{ path: 5 as unknown as string, content: null as unknown as string }] }));
|
|
159
|
+
const options = { contextFiles: [{ path: "/a/AGENTS.md", content: ENGRAM_HOME }, { path: "/a/b/AGENTS.md", content: "<!-- gentle-ai:engram-protocol -->\nunclosed\n" }] };
|
|
160
|
+
filterChildSessionContextFiles(options);
|
|
161
|
+
assert.equal(options.contextFiles[0].content, "", "the balanced copy is still dropped");
|
|
162
|
+
assert.equal(options.contextFiles[1].content, "<!-- gentle-ai:engram-protocol -->\nunclosed\n", "the malformed file is passed through unchanged");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("engram-protocol is dropped even when it sits inside a dropped agent-routing block", () => {
|
|
166
|
+
const options = {
|
|
167
|
+
contextFiles: [
|
|
168
|
+
{ path: "/a/AGENTS.md", content: `${ENGRAM_HOME}\n` },
|
|
169
|
+
{ path: "/a/b/AGENTS.md", content: `${block("agent-routing", `r\n${ENGRAM_PROJECT}`)}\n` },
|
|
170
|
+
],
|
|
171
|
+
};
|
|
172
|
+
filterChildSessionContextFiles(options);
|
|
173
|
+
assert.deepEqual(options.contextFiles.map((file) => file.content), ["", ""], "no engram-protocol copy survives, nested or not");
|
|
174
|
+
});
|
|
@@ -170,8 +170,15 @@ test("orchestrator-delegation.md states the exact-captured-decline-invocation ru
|
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
test("orchestrator-delegation.md states handoff scope and mode preservation", () => {
|
|
173
|
-
|
|
174
|
-
assert.
|
|
173
|
+
// cost-speed P20 (PD-88): an explicit user request to stop RDD wins over the handoff scope rule.
|
|
174
|
+
assert.ok(
|
|
175
|
+
DELEGATION.includes(
|
|
176
|
+
"Unless the user explicitly asks, do not invoke `gentle-ai review mode disable` at clone or global scope or turn RDD off or on within this handoff.",
|
|
177
|
+
),
|
|
178
|
+
"the handoff scope rule must yield to an explicit user request",
|
|
179
|
+
);
|
|
180
|
+
assert.doesNotMatch(DELEGATION, /Do not invoke `gentle-ai review mode disable` at clone or global scope within this handoff/i);
|
|
181
|
+
assert.doesNotMatch(DELEGATION, /Do not turn RDD off or on within this handoff/i);
|
|
175
182
|
assert.match(DELEGATION, /The result carries no lineage or receipt; ordinary delivery is unmanaged by the candidate choice, and the next candidate asks again/i);
|
|
176
183
|
});
|
|
177
184
|
|
|
@@ -187,7 +187,7 @@ test("worker asset owns the canonical Known environmental failures definition",
|
|
|
187
187
|
test("delegation asset references the worker's Known environmental failures definition instead of restating it", () => {
|
|
188
188
|
assert.match(
|
|
189
189
|
delegation,
|
|
190
|
-
/`## Known environmental failures
|
|
190
|
+
/`## Known environmental failures`: `gentle-ai-worker`'s Verification contract\./,
|
|
191
191
|
);
|
|
192
192
|
// The full canonical wording ("lists exact test names or exact command
|
|
193
193
|
// lines that already fail on the base") must not be duplicated here.
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
-
import { __testing } from "../extensions/gentle-ai.ts";
|
|
3
|
+
import { createGentleAiExtension, __testing } from "../extensions/gentle-ai.ts";
|
|
4
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
8
|
import {
|
|
5
9
|
NATIVE_REVIEW_ERROR_CODE,
|
|
6
10
|
NATIVE_REVIEW_MODE_OPERATION,
|
|
@@ -40,6 +44,7 @@ const {
|
|
|
40
44
|
getOrchestratorPrompt,
|
|
41
45
|
clearRddStatusMemoForTesting,
|
|
42
46
|
RDD_STATUS_TIMEOUT_MS,
|
|
47
|
+
resolveRddStatusTimeoutMs,
|
|
43
48
|
RDD_STATUS_MEMO_TTL_MS,
|
|
44
49
|
} = __testing;
|
|
45
50
|
|
|
@@ -170,6 +175,94 @@ test("resolveRddModeStatus resolves to undefined when the native reviewMode call
|
|
|
170
175
|
assert.equal(status, undefined);
|
|
171
176
|
});
|
|
172
177
|
|
|
178
|
+
test("an expired startup budget does not dispatch another native status read", async () => {
|
|
179
|
+
clearRddStatusMemoForTesting();
|
|
180
|
+
const { cli, calls } = countingReviewMode(modeResult("on", NATIVE_REVIEW_MODE_SOURCE.GLOBAL));
|
|
181
|
+
const controller = new AbortController();
|
|
182
|
+
controller.abort(new DOMException("The operation was aborted", "AbortError"));
|
|
183
|
+
const first = await resolveRddStatusLine(cli, "/repo-already-aborted", controller.signal);
|
|
184
|
+
assert.match(first, /unknown/);
|
|
185
|
+
assert.equal(calls(), 0, "waiting for an existing startup read must not spawn again after its budget expired");
|
|
186
|
+
assert.equal(await resolveRddModeStatus(cli, "/repo-already-aborted"), undefined);
|
|
187
|
+
assert.equal(calls(), 0, "the failed-read memo also prevents a retry storm on following turns");
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("cancellation is reported separately from a native timeout without inventing a duration", async () => {
|
|
191
|
+
clearRddStatusMemoForTesting();
|
|
192
|
+
const cancelled = captureNotices();
|
|
193
|
+
const controller = new AbortController();
|
|
194
|
+
controller.abort();
|
|
195
|
+
await resolveRddModeStatus(fakeReviewMode(modeResult("on", NATIVE_REVIEW_MODE_SOURCE.GLOBAL)), "/repo-cancelled", controller.signal, Date.now, cancelled.ctx as never);
|
|
196
|
+
assert.match(cancelled.messages[0], /was cancelled/);
|
|
197
|
+
assert.doesNotMatch(cancelled.messages[0], /did not answer within/);
|
|
198
|
+
clearRddStatusMemoForTesting();
|
|
199
|
+
const timedOut = captureNotices();
|
|
200
|
+
const cli = fakeReviewMode(() => { throw new NativeReviewCliError(NATIVE_REVIEW_ERROR_CODE.TIMEOUT, NATIVE_REVIEW_OPERATION.MODE, true, false, "timeout"); });
|
|
201
|
+
await resolveRddModeStatus(cli, "/repo-native-timeout", undefined, Date.now, timedOut.ctx as never);
|
|
202
|
+
assert.match(timedOut.messages[0], /reported a native timeout/);
|
|
203
|
+
assert.doesNotMatch(timedOut.messages[0], /did not answer within/);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("RDD status timeout configuration stays bounded and rejects invalid values", () => {
|
|
207
|
+
assert.equal(resolveRddStatusTimeoutMs({}), 3000);
|
|
208
|
+
for (const value of ["0", "-1", "1.5", " 4000", "1e3", "10001", "Infinity", "999999999999999999999"]) {
|
|
209
|
+
assert.equal(resolveRddStatusTimeoutMs({ GENTLE_PI_RDD_STATUS_TIMEOUT_MS: value }), 3000, value);
|
|
210
|
+
}
|
|
211
|
+
for (const value of ["1", "4000", "10000"]) {
|
|
212
|
+
assert.equal(resolveRddStatusTimeoutMs({ GENTLE_PI_RDD_STATUS_TIMEOUT_MS: value }), Number(value));
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("a provider that aborts synchronously cannot publish its immediately resolved off status", async () => {
|
|
217
|
+
clearRddStatusMemoForTesting();
|
|
218
|
+
const controller = new AbortController();
|
|
219
|
+
const cli: Pick<NativeReviewCli, "reviewMode"> = { reviewMode: () => {
|
|
220
|
+
controller.abort();
|
|
221
|
+
return Promise.resolve(modeResult("off", NATIVE_REVIEW_MODE_SOURCE.GLOBAL));
|
|
222
|
+
} };
|
|
223
|
+
assert.match(await resolveRddStatusLine(cli, "/repo-aborting-provider", controller.signal), /unknown/);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("primary prompt uses its configured deadline and memoizes an unresponsive provider", async t => {
|
|
227
|
+
clearRddStatusMemoForTesting();
|
|
228
|
+
const home = mkdtempSync(join(tmpdir(), "rdd-status-deadline-"));
|
|
229
|
+
t.after(() => rmSync(home, { recursive: true, force: true }));
|
|
230
|
+
const handlers = new Map<string, (event: unknown, ctx: ExtensionContext) => Promise<unknown>>();
|
|
231
|
+
const notices: string[] = [];
|
|
232
|
+
const deadlines: number[] = [];
|
|
233
|
+
const controller = new AbortController();
|
|
234
|
+
let entered!: () => void, calls = 0;
|
|
235
|
+
const started = new Promise<void>(resolve => { entered = resolve; });
|
|
236
|
+
const cli = { reviewMode: async ({ signal }: NativeReviewModeRequest) => {
|
|
237
|
+
calls++;
|
|
238
|
+
assert.equal(signal, controller.signal);
|
|
239
|
+
entered();
|
|
240
|
+
return new Promise<NativeReviewModeResult>(() => {});
|
|
241
|
+
} } as NativeReviewCli;
|
|
242
|
+
const pi = { on: (name: string, fn: (event: unknown, ctx: ExtensionContext) => Promise<unknown>) => handlers.set(name, fn),
|
|
243
|
+
registerCommand() {}, registerTool() {}, registerMessageRenderer() {}, registerFlag() {},
|
|
244
|
+
events: { emit() {}, on: () => () => {} }, getActiveTools: () => [],
|
|
245
|
+
} as unknown as ExtensionAPI;
|
|
246
|
+
createGentleAiExtension({ nativeReviewCli: cli, candidateViews: null,
|
|
247
|
+
processEnv: { GENTLE_PI_CONFIG_HOME: home, GENTLE_PI_RDD_STATUS_TIMEOUT_MS: "7000" },
|
|
248
|
+
resolveTelemetryTriggerBinary: () => { throw new Error("disabled in test"); },
|
|
249
|
+
})(pi);
|
|
250
|
+
t.mock.method(AbortSignal, "timeout", (ms: number) => { deadlines.push(ms); return controller.signal; });
|
|
251
|
+
const ctx = { cwd: home, hasUI: true, mode: "tui", sessionManager: { getSessionId: () => "deadline-session" },
|
|
252
|
+
ui: { notify: (message: string) => notices.push(message), setStatus() {}, setWidget() {} },
|
|
253
|
+
} as unknown as ExtensionContext;
|
|
254
|
+
const event = { prompt: "task", systemPromptOptions: { appendSystemPrompt: "base" } };
|
|
255
|
+
const pending = handlers.get("before_agent_start")!(event, ctx);
|
|
256
|
+
await started;
|
|
257
|
+
controller.abort(new DOMException("deadline", "TimeoutError"));
|
|
258
|
+
await pending;
|
|
259
|
+
assert.match(event.systemPromptOptions.appendSystemPrompt, /Receipt-driven development: unknown/);
|
|
260
|
+
assert.match(notices.join("\n"), /did not answer within 7000 ms/);
|
|
261
|
+
await handlers.get("before_agent_start")!(event, ctx);
|
|
262
|
+
assert.deepEqual(deadlines, [7000, 7000]);
|
|
263
|
+
assert.equal(calls, 1, "the failed-read memo prevents another provider invocation");
|
|
264
|
+
});
|
|
265
|
+
|
|
173
266
|
test("resolveRddModeStatus resolves to undefined within the deadline when reviewMode never settles", async () => {
|
|
174
267
|
// gentle-pi#661 native-review escalation: a hung `gentle-ai` child must
|
|
175
268
|
// not stall session start. resolveRddModeStatus races the call against
|