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,101 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import test from "node:test";
|
|
5
|
+
|
|
6
|
+
// Cost/speed pain points S4 (T3; L3): children re-read SKILL.md files (~273k
|
|
7
|
+
// tokens; `work-unit-commits` 137 times, `cognitive-doc-design` 134 times by
|
|
8
|
+
// children that neither committed nor wrote docs) and ODD specs (~282k tokens),
|
|
9
|
+
// child reports pasted into the parent were the second-largest source of parent
|
|
10
|
+
// context growth, and part of the correction rounds came from the verifier's own
|
|
11
|
+
// setup mistakes. These pin prompt guidance, not model compliance.
|
|
12
|
+
|
|
13
|
+
const read = (relative: string): string => readFileSync(join(import.meta.dirname, "..", relative), "utf8");
|
|
14
|
+
const skills = read("assets/orchestrator-skills.md");
|
|
15
|
+
const agents = {
|
|
16
|
+
worker: read("assets/agents/gentle-ai-worker.md"),
|
|
17
|
+
verify: read("assets/agents/gentle-ai-verify.md"),
|
|
18
|
+
explore: read("assets/agents/gentle-ai-explore.md"),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function containsAll(text: string, clauses: readonly string[], label: string): void {
|
|
22
|
+
for (const clause of clauses) assert.ok(text.includes(clause), `${label} is missing: ${clause}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
test("S4 skills: the parent passes only skills matching the delegated task's files and actions, never a fixed set", () => {
|
|
26
|
+
containsAll(skills, [
|
|
27
|
+
"Pass only matching exact `Path` values to subagents under `## Skills to load before work`.",
|
|
28
|
+
"Match the delegated task's own files and actions, never a fixed set",
|
|
29
|
+
"a child that will not commit gets no commit skill, and one that writes no docs gets no docs skill",
|
|
30
|
+
], "orchestrator-skills.md");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("S4 continuations: a resumed child skips only material it already read and that did not change; first launch reads stay", () => {
|
|
34
|
+
const continuation =
|
|
35
|
+
"When resumed in the same child session, do not re-read skill files or spec sections you already read there unless they changed or the parent says so; read anything you have not read yet as usual";
|
|
36
|
+
for (const [name, body] of Object.entries(agents)) containsAll(body, [continuation], `gentle-ai-${name}`);
|
|
37
|
+
containsAll(agents.worker, ["Read every exact path under `## Skills to load before work`", "read it from the top until `## Log`"], "worker first launch");
|
|
38
|
+
containsAll(agents.verify, ["read all of it, including the verbatim user entries in `## Log`", "read anything you have not read yet as usual, including new `## Log` entries."], "verify first launch and new Log entries");
|
|
39
|
+
containsAll(agents.explore, ["read it until `## Log` for the requirements"], "explore first launch");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("S4 reports: every child report is compact, cites exact commands with exit codes and counts, and never restates the task", () => {
|
|
43
|
+
const noRestate = "never restate the task, the spec text, or unchanged file contents";
|
|
44
|
+
containsAll(agents.worker, [noRestate], "gentle-ai-worker");
|
|
45
|
+
containsAll(agents.explore, [noRestate], "gentle-ai-explore");
|
|
46
|
+
containsAll(agents.verify, ["never restate the task or spec beyond the line a finding contradicts, or unchanged file contents"], "gentle-ai-verify");
|
|
47
|
+
containsAll(agents.worker, [
|
|
48
|
+
"Return one compact handoff using the schema below; cite exact commands with exit codes and test counts",
|
|
49
|
+
"blockers with `path:line`",
|
|
50
|
+
"scratch paths",
|
|
51
|
+
], "worker report");
|
|
52
|
+
// The existing Return contract fields stay.
|
|
53
|
+
containsAll(agents.worker, [
|
|
54
|
+
"status: completed | partial | blocked | interaction_required",
|
|
55
|
+
"summary:",
|
|
56
|
+
"files_changed:",
|
|
57
|
+
"tdd_evidence:",
|
|
58
|
+
"validation:",
|
|
59
|
+
"risks:",
|
|
60
|
+
"review_focus:",
|
|
61
|
+
"skill_resolution: paths-injected | paths-invalid | none",
|
|
62
|
+
"unblock_response:",
|
|
63
|
+
], "worker Return contract");
|
|
64
|
+
containsAll(agents.verify, [
|
|
65
|
+
"Return a compact evidence handoff of at most ~2k tokens",
|
|
66
|
+
"exact commands with exit codes, test counts, and observed results",
|
|
67
|
+
"the verdict per spec item",
|
|
68
|
+
"blockers with `path:line`",
|
|
69
|
+
"scratch paths",
|
|
70
|
+
"Never claim a command ran or a check passed without observed output.",
|
|
71
|
+
], "verify report");
|
|
72
|
+
containsAll(agents.explore, ["Return a compact handoff of at most ~2k tokens", "`path:line`", "Never claim evidence you did not observe."], "explore report");
|
|
73
|
+
// The parent's Key Learnings closing block still follows the Return contract.
|
|
74
|
+
for (const [name, body] of Object.entries(agents)) containsAll(body, ["`## Key Learnings`"], `gentle-ai-${name}`);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("S4 verifier setup pitfalls: clean env, short scratch, one file per config role, flag check, no executing entry points", () => {
|
|
78
|
+
containsAll(agents.verify, [
|
|
79
|
+
"Setup pitfalls:",
|
|
80
|
+
"start every probe from a clean environment so parent-session variables do not leak",
|
|
81
|
+
"set `HOME` and `TMPDIR` inside the scratch directory",
|
|
82
|
+
"keep the scratch path short",
|
|
83
|
+
"give each config role its own file",
|
|
84
|
+
"check that a flag exists for the exact subcommand before using it",
|
|
85
|
+
"never import or execute an entry point just to inspect it",
|
|
86
|
+
// PR #3084 setup self-correction stays.
|
|
87
|
+
"make exactly one corrected attempt without asking anyone and report both attempts",
|
|
88
|
+
], "verify setup pitfalls");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("S4 verifier env applies to every probe", () => {
|
|
92
|
+
assert.match(agents.verify, /NO_UPDATE_NOTIFIER=1`?[^.;]*for every probe|env -i`[^)]*NODE_COMPILE_CACHE[^)]*NO_UPDATE_NOTIFIER/);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("S4 continuation never blocks unread material", () => {
|
|
96
|
+
for (const body of Object.values(agents)) assert.doesNotMatch(body, /; read only what the follow-up names\./);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("S4 worker presents the derived edit-surface candidates as the answer, not an example", () => {
|
|
100
|
+
assert.ok(agents.worker.includes("in `options` as the derived answer, not an example,"), "worker interaction contract lost the derived-answer nuance");
|
|
101
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
mkdirSync,
|
|
5
|
+
mkdtempSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
rmSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import test from "node:test";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { agentBody, installPackageAssets } from "../lib/agent-assets.ts";
|
|
15
|
+
import { discoverAgents } from "../lib/agents-config.ts";
|
|
16
|
+
|
|
17
|
+
// gentle-shell#3133 acceptance: the tool overlay is a load-time layer, so it
|
|
18
|
+
// adds/removes tools WITHOUT editing the package-owned agent file. The file
|
|
19
|
+
// stays pristine, `managed-assets.json` keeps owning it, and upgrades replace
|
|
20
|
+
// it freely while the overlay is re-applied on top.
|
|
21
|
+
|
|
22
|
+
const PACKAGE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
23
|
+
const WORKER_KEY = "agents/gentle-ai-worker.md";
|
|
24
|
+
const WORKER_SHIPPED = readFileSync(join(PACKAGE_ROOT, "assets", WORKER_KEY), "utf8");
|
|
25
|
+
const STALE_FIXTURE = readFileSync(
|
|
26
|
+
join(PACKAGE_ROOT, "tests", "fixtures", "agent-assets", "gentle-ai-worker.strict-tdd-era.md"),
|
|
27
|
+
"utf8",
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
function sha256(content: string): string {
|
|
31
|
+
return createHash("sha256").update(content).digest("hex");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isolatedHome() {
|
|
35
|
+
const agentHome = mkdtempSync(join(tmpdir(), "overlay-agent-home-"));
|
|
36
|
+
const previous = process.env.GENTLE_PI_AGENT_HOME;
|
|
37
|
+
const restore = () => {
|
|
38
|
+
if (previous === undefined) delete process.env.GENTLE_PI_AGENT_HOME;
|
|
39
|
+
else process.env.GENTLE_PI_AGENT_HOME = previous;
|
|
40
|
+
rmSync(agentHome, { recursive: true, force: true });
|
|
41
|
+
};
|
|
42
|
+
process.env.GENTLE_PI_AGENT_HOME = agentHome;
|
|
43
|
+
return { agentHome, restore };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isolatedRoots(agentHome: string) {
|
|
47
|
+
const configHome = mkdtempSync(join(tmpdir(), "overlay-config-home-"));
|
|
48
|
+
const cwd = mkdtempSync(join(tmpdir(), "overlay-cwd-"));
|
|
49
|
+
return {
|
|
50
|
+
configHome,
|
|
51
|
+
cwd,
|
|
52
|
+
cleanup: () => {
|
|
53
|
+
rmSync(configHome, { recursive: true, force: true });
|
|
54
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function manifestOwns(agentHome: string): string | undefined {
|
|
60
|
+
const manifest = JSON.parse(
|
|
61
|
+
readFileSync(join(agentHome, "gentle-ai", "managed-assets.json"), "utf8"),
|
|
62
|
+
) as { assets: Record<string, string> };
|
|
63
|
+
return manifest.assets[WORKER_KEY];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function workerTools(agentHome: string, configHome: string, cwd: string): string[] {
|
|
67
|
+
const agent = discoverAgents({ cwd, home: cwd, agentHome, configHome }).agents.find(
|
|
68
|
+
(candidate) => candidate.name === "gentle-ai-worker",
|
|
69
|
+
);
|
|
70
|
+
assert.ok(agent, "worker must be discovered");
|
|
71
|
+
return agent.tools;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
test("overlay adds a tool at load without editing the package-owned file, and removing it restores the shipped tools (S3.1, S3.3)", () => {
|
|
75
|
+
const { agentHome, restore } = isolatedHome();
|
|
76
|
+
const { configHome, cwd, cleanup } = isolatedRoots(agentHome);
|
|
77
|
+
try {
|
|
78
|
+
installPackageAssets(agentHome, false, ["delegation"]);
|
|
79
|
+
writeFileSync(
|
|
80
|
+
join(configHome, "tools.json"),
|
|
81
|
+
JSON.stringify({ "gentle-ai-worker": { add: ["bash_background"] } }),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// The overlay is applied at load, but the shipped file never declares it.
|
|
85
|
+
assert.ok(workerTools(agentHome, configHome, cwd).includes("bash_background"));
|
|
86
|
+
assert.doesNotMatch(WORKER_SHIPPED, /bash_background/);
|
|
87
|
+
assert.equal(readFileSync(join(agentHome, WORKER_KEY), "utf8"), WORKER_SHIPPED, "the file itself is untouched");
|
|
88
|
+
assert.ok(manifestOwns(agentHome), "manifest still owns the file");
|
|
89
|
+
|
|
90
|
+
// A forced refresh must not treat the overlay as a local edit.
|
|
91
|
+
const result = installPackageAssets(agentHome, true, ["delegation"]);
|
|
92
|
+
assert.equal(result.skipped, 0, "no skip: the overlay never edited the file");
|
|
93
|
+
assert.equal(manifestOwns(agentHome), sha256(WORKER_SHIPPED), "ownership kept through a forced refresh");
|
|
94
|
+
assert.ok(workerTools(agentHome, configHome, cwd).includes("bash_background"), "overlay survives the refresh");
|
|
95
|
+
|
|
96
|
+
// S3.3: removing the overlay entry drops the tool and the file equals shipped.
|
|
97
|
+
rmSync(join(configHome, "tools.json"));
|
|
98
|
+
assert.ok(!workerTools(agentHome, configHome, cwd).includes("bash_background"));
|
|
99
|
+
assert.equal(readFileSync(join(agentHome, WORKER_KEY), "utf8"), WORKER_SHIPPED);
|
|
100
|
+
} finally {
|
|
101
|
+
cleanup();
|
|
102
|
+
restore();
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test("an upgrade replaces an outdated body while the external overlay survives (S3.2)", () => {
|
|
107
|
+
const { agentHome, restore } = isolatedHome();
|
|
108
|
+
const { configHome, cwd, cleanup } = isolatedRoots(agentHome);
|
|
109
|
+
try {
|
|
110
|
+
installPackageAssets(agentHome, false, ["delegation"]);
|
|
111
|
+
writeFileSync(
|
|
112
|
+
join(configHome, "tools.json"),
|
|
113
|
+
JSON.stringify({ "gentle-ai-worker": { add: ["bash_background"] } }),
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
// Simulate an installed copy that predates the current shipped body.
|
|
117
|
+
const workerPath = join(agentHome, WORKER_KEY);
|
|
118
|
+
writeFileSync(workerPath, STALE_FIXTURE);
|
|
119
|
+
const manifestPath = join(agentHome, "gentle-ai", "managed-assets.json");
|
|
120
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as { assets: Record<string, string> };
|
|
121
|
+
delete manifest.assets[WORKER_KEY];
|
|
122
|
+
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
|
|
123
|
+
|
|
124
|
+
// The upgrade replaces the outdated body with the packaged one.
|
|
125
|
+
installPackageAssets(agentHome, true, ["delegation"]);
|
|
126
|
+
assert.equal(agentBody(readFileSync(workerPath, "utf8")), agentBody(WORKER_SHIPPED), "body updated to shipped");
|
|
127
|
+
assert.doesNotMatch(readFileSync(workerPath, "utf8"), /effective TDD mode/, "stale body is gone");
|
|
128
|
+
|
|
129
|
+
// The overlay is external, so the tool is still present after the upgrade.
|
|
130
|
+
assert.ok(workerTools(agentHome, configHome, cwd).includes("bash_background"), "overlay survives an upgrade that changed the body");
|
|
131
|
+
} finally {
|
|
132
|
+
cleanup();
|
|
133
|
+
restore();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("project overlay outranks the global overlay, and both outrank an extension drop-in (S3.4)", () => {
|
|
138
|
+
const { agentHome, restore } = isolatedHome();
|
|
139
|
+
const { configHome, cwd, cleanup } = isolatedRoots(agentHome);
|
|
140
|
+
try {
|
|
141
|
+
installPackageAssets(agentHome, false, ["delegation"]);
|
|
142
|
+
|
|
143
|
+
// Extension adds `ext_tool`, global removes it and adds `glob_tool`, project re-adds `ext_tool`.
|
|
144
|
+
const dropInDir = join(configHome, "agent-overlays.d");
|
|
145
|
+
mkdirSync(dropInDir, { recursive: true });
|
|
146
|
+
writeFileSync(join(dropInDir, "aa-extension.json"), JSON.stringify({ "gentle-ai-worker": { add: ["ext_tool"] } }));
|
|
147
|
+
writeFileSync(join(configHome, "tools.json"), JSON.stringify({ "gentle-ai-worker": { add: ["glob_tool"], remove: ["ext_tool"] } }));
|
|
148
|
+
mkdirSync(join(cwd, ".pi", "gentle-ai"), { recursive: true });
|
|
149
|
+
writeFileSync(join(cwd, ".pi", "gentle-ai", "tools.json"), JSON.stringify({ "gentle-ai-worker": { add: ["ext_tool"] } }));
|
|
150
|
+
|
|
151
|
+
const tools = workerTools(agentHome, configHome, cwd);
|
|
152
|
+
assert.ok(tools.includes("ext_tool"), "project re-add wins over the global remove");
|
|
153
|
+
assert.ok(tools.includes("glob_tool"), "distinct tools from different sources all apply");
|
|
154
|
+
} finally {
|
|
155
|
+
cleanup();
|
|
156
|
+
restore();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { applyToolOverlay, loadToolOverlays } from "../lib/agent-tool-overlay.ts";
|
|
7
|
+
import { discoverAgents } from "../lib/agents-config.ts";
|
|
8
|
+
|
|
9
|
+
function writeJson(path: string, value: unknown): void {
|
|
10
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
11
|
+
writeFileSync(path, JSON.stringify(value));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function tempRoot(): string {
|
|
15
|
+
return mkdtempSync(join(tmpdir(), "gentle-tool-overlay-"));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test("loadToolOverlays merges sources with higher precedence winning per tool", (t) => {
|
|
19
|
+
const root = tempRoot();
|
|
20
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
21
|
+
const configHome = join(root, "config");
|
|
22
|
+
const cwd = join(root, "project");
|
|
23
|
+
writeJson(join(configHome, "agent-overlays.d", "10-extension.json"), { worker: { add: ["ext"] } });
|
|
24
|
+
writeJson(join(configHome, "tools.json"), { worker: { add: ["a", "global-add"], remove: ["b"] } });
|
|
25
|
+
writeJson(join(cwd, ".pi", "gentle-ai", "tools.json"), { worker: { remove: ["a"], add: ["b", "project-add"] } });
|
|
26
|
+
|
|
27
|
+
const result = loadToolOverlays(configHome, cwd);
|
|
28
|
+
assert.deepEqual(result.notices, []);
|
|
29
|
+
const worker = result.entries.worker;
|
|
30
|
+
assert.ok(worker, "worker must have a merged overlay entry");
|
|
31
|
+
assert.deepEqual([...worker.add].sort(), ["b", "ext", "global-add", "project-add"]);
|
|
32
|
+
assert.deepEqual([...worker.remove], ["a"]);
|
|
33
|
+
// global add + project remove => removed; global remove + project add => re-added.
|
|
34
|
+
assert.equal(worker.add.includes("a"), false);
|
|
35
|
+
assert.equal(worker.remove.includes("a"), true);
|
|
36
|
+
assert.equal(worker.add.includes("b"), true);
|
|
37
|
+
assert.equal(worker.remove.includes("b"), false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("loadToolOverlays ignores invalid JSON and invalid entries with notices while valid files still load", (t) => {
|
|
41
|
+
const root = tempRoot();
|
|
42
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
43
|
+
const configHome = join(root, "config");
|
|
44
|
+
const cwd = join(root, "project");
|
|
45
|
+
writeJson(join(configHome, "agent-overlays.d", "valid.json"), { worker: { add: ["ext"] } });
|
|
46
|
+
writeFileSync(join(configHome, "agent-overlays.d", "broken.json"), "{ not json");
|
|
47
|
+
writeFileSync(join(configHome, "agent-overlays.d", "array.json"), "[1, 2, 3]");
|
|
48
|
+
writeJson(join(configHome, "tools.json"), { worker: { add: ["global"] }, bad: "not-an-object", other: { add: "not-an-array" } });
|
|
49
|
+
|
|
50
|
+
const result = loadToolOverlays(configHome, cwd);
|
|
51
|
+
assert.deepEqual([...result.entries.worker.add].sort(), ["ext", "global"]);
|
|
52
|
+
assert.ok(result.notices.includes(`ignored invalid tool overlay ${join(configHome, "agent-overlays.d", "broken.json")}`));
|
|
53
|
+
assert.ok(result.notices.includes(`ignored invalid tool overlay ${join(configHome, "agent-overlays.d", "array.json")}`));
|
|
54
|
+
assert.ok(result.notices.includes(`ignored invalid entry for "bad" in ${join(configHome, "tools.json")}`));
|
|
55
|
+
assert.ok(result.notices.includes(`ignored invalid entry for "other" in ${join(configHome, "tools.json")}`));
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("applyToolOverlay appends, dedups, removes package tools, and ignores absent removals", () => {
|
|
59
|
+
const tools = ["read", "grep", "bash"];
|
|
60
|
+
const overlaid = applyToolOverlay(tools, { add: ["bash", "web_search"], remove: ["grep", "absent"] });
|
|
61
|
+
assert.deepEqual(overlaid, ["read", "bash", "web_search"]);
|
|
62
|
+
assert.deepEqual(tools, ["read", "grep", "bash"], "the input array must not be mutated");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("applyToolOverlay with an undefined overlay returns the same array reference", () => {
|
|
66
|
+
const tools = ["read", "grep"];
|
|
67
|
+
assert.equal(applyToolOverlay(tools, undefined), tools);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test("discoverAgents applies the overlay and reports overlay keys naming no agent", (t) => {
|
|
71
|
+
const root = tempRoot();
|
|
72
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
73
|
+
const cwd = join(root, "cwd");
|
|
74
|
+
const agentHome = join(root, "agent");
|
|
75
|
+
const configHome = join(root, "config");
|
|
76
|
+
mkdirSync(join(agentHome, "agents"), { recursive: true });
|
|
77
|
+
writeFileSync(join(agentHome, "agents", "worker.md"), "---\nname: worker\ntools:\n - read\n - grep\n---\nbody");
|
|
78
|
+
writeJson(join(configHome, "tools.json"), {
|
|
79
|
+
worker: { add: ["bash_background"], remove: ["grep"] },
|
|
80
|
+
ghost: { add: ["read"] },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const { agents, errors, notices } = discoverAgents({ cwd, home: join(root, "home"), agentHome, configHome });
|
|
84
|
+
assert.deepEqual(errors, []);
|
|
85
|
+
const worker = agents.find((agent) => agent.name === "worker");
|
|
86
|
+
assert.ok(worker, "worker must be discovered");
|
|
87
|
+
assert.deepEqual(worker.tools, ["read", "bash_background"]);
|
|
88
|
+
assert.ok(notices.includes('overlay names unknown agent "ghost"'));
|
|
89
|
+
});
|
|
@@ -161,7 +161,7 @@ test("discoverAgents merges the four directories with project over global and su
|
|
|
161
161
|
assert.deepEqual(agents.map((agent) => `${agent.name}:${agent.description}:${agent.scope}`), ["gentle-ai-explore:Read-only exploration and mapping.:global", "shared:project agents:project"]);
|
|
162
162
|
assert.equal(errors.length, 1);
|
|
163
163
|
assert.match(errors[0], /broken\.md/);
|
|
164
|
-
assert.deepEqual(discoverAgents({ cwd: join(root, "empty"), home: join(root, "nohome") }), { agents: [], errors: [] });
|
|
164
|
+
assert.deepEqual(discoverAgents({ cwd: join(root, "empty"), home: join(root, "nohome") }), { agents: [], errors: [], notices: [] });
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
test("profile agent roots isolate global definitions and subagents.json while explicit homes keep their fallback", () => {
|
|
@@ -215,6 +215,15 @@ test("parseAgentsConfig resolves the tool-call stall ceiling above the idle sile
|
|
|
215
215
|
assert.equal(parseAgentsConfig({ stall_timeout_ms: 45 * 60_000, tool_stall_timeout_ms: 1_000 }, undefined).toolStallTimeoutMs, 45 * 60_000, "the tool ceiling must never fall below the idle budget");
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
+
test("parseAgentsConfig bounds the delivered child report at 16,384 bytes unless report_max_bytes says otherwise", () => {
|
|
219
|
+
assert.equal(parseAgentsConfig(undefined, undefined).reportMaxBytes, 16_384);
|
|
220
|
+
assert.equal(parseAgentsConfig({ report_max_bytes: 8_192 }, undefined).reportMaxBytes, 8_192);
|
|
221
|
+
assert.equal(parseAgentsConfig({ report_max_bytes: 8_192 }, { report_max_bytes: 32_768 }).reportMaxBytes, 32_768);
|
|
222
|
+
for (const invalid of ["big", 0, -1, 12.5, null]) {
|
|
223
|
+
assert.equal(parseAgentsConfig({ report_max_bytes: invalid }, undefined).reportMaxBytes, 16_384, `invalid report_max_bytes ${String(invalid)} must fall back to the default`);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
218
227
|
test("resolveAgentProfile prefers the profile, then the definition, then the defaults", () => {
|
|
219
228
|
const config = parseAgentsConfig({ default_model: "openai-codex/gpt-6-astra", default_effort: "medium", model_profiles: { "gentle-ai-explore": { effort: "high" } } }, undefined);
|
|
220
229
|
const explore = parseAgentDefinition(EXPLORER, "/x/explore.md", "global");
|
|
@@ -104,3 +104,39 @@ test("dropAll clears everything across session reset", () => {
|
|
|
104
104
|
assert.equal(queue.pendingCount(), 0);
|
|
105
105
|
assert.equal(queue.takeDeliverable(1050, "s1", () => true).length, 0);
|
|
106
106
|
});
|
|
107
|
+
|
|
108
|
+
// S15 P9a: a busy parent may reach its turn boundary after the query expired;
|
|
109
|
+
// the question still reaches it once, marked expired, so a late reply can go.
|
|
110
|
+
const EXPIRED_LINE = "This query expired before it reached you; a reply is delivered to the task as a message.";
|
|
111
|
+
|
|
112
|
+
test("a query that expires while queued is still delivered once, marked expired", () => {
|
|
113
|
+
const queue = createAgentMessageQueue();
|
|
114
|
+
queue.enqueueQuery({ id: "task-1", agent: "scout", parentSessionId: "s1" }, "q1", "Need approval", 1000);
|
|
115
|
+
queue.markQueryExpired("task-1", "q1");
|
|
116
|
+
const deliverable = queue.takeDeliverable(1050, "s1", () => true);
|
|
117
|
+
assert.equal(deliverable.length, 1);
|
|
118
|
+
assert.equal(deliverable[0]?.content, `Subagent scout asks:\nTask ID: task-1\nRequest ID: q1\nQuestion: Need approval\n${EXPIRED_LINE}`);
|
|
119
|
+
assert.equal(deliverable[0]?.requestId, "q1");
|
|
120
|
+
assert.equal((deliverable[0]?.details.gentleAgents as { expired?: boolean }).expired, true);
|
|
121
|
+
assert.equal(queue.takeDeliverable(1100, "s1", () => true).length, 0, "delivered at most once");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("an expired queued query is not delivered once its task ended", () => {
|
|
125
|
+
const queue = createAgentMessageQueue();
|
|
126
|
+
queue.enqueueQuery({ id: "task-1", agent: "scout", parentSessionId: "s1" }, "q1", "Need approval", 1000);
|
|
127
|
+
queue.markQueryExpired("task-1", "q1");
|
|
128
|
+
assert.equal(queue.takeDeliverable(1050, "s1", () => false).length, 0);
|
|
129
|
+
queue.enqueueQuery({ id: "task-2", agent: "scout", parentSessionId: "s1" }, "q1", "Need approval", 1000);
|
|
130
|
+
queue.markQueryExpired("task-2", "q1");
|
|
131
|
+
queue.invalidateTask("task-2");
|
|
132
|
+
assert.equal(queue.takeDeliverable(1050, "s1", () => true).length, 0);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("a query the parent already saw is not shown again when it expires", () => {
|
|
136
|
+
const queue = createAgentMessageQueue();
|
|
137
|
+
queue.enqueueQuery({ id: "task-1", agent: "scout", parentSessionId: "s1" }, "q1", "Need approval", 1000);
|
|
138
|
+
assert.equal(queue.takeDeliverable(1050, "s1", () => true).length, 1);
|
|
139
|
+
queue.markQueryExpired("task-1", "q1");
|
|
140
|
+
queue.enqueueQuery({ id: "task-1", agent: "scout", parentSessionId: "s1" }, "q1", "Need approval", 1100);
|
|
141
|
+
assert.equal(queue.takeDeliverable(1200, "s1", () => true).length, 0);
|
|
142
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
import { AGENT_MODE, type AgentDefinition, type AgentMode } from "../lib/agents-config.ts";
|
|
4
|
-
import { CHILD_MESSAGE_MAX_BYTES, ChildMessenger } from "../lib/agents-messaging.ts";
|
|
4
|
+
import { CHILD_MESSAGE_MAX_BYTES, CHILD_QUERY_ERROR_MAX_BYTES, CHILD_QUERY_TIMEOUT_ERROR, CHILD_QUERY_TIMEOUT_MS, ChildMessenger } from "../lib/agents-messaging.ts";
|
|
5
5
|
import { TaskStore } from "../lib/agents-protocol.ts";
|
|
6
|
-
import { AgentRunner } from "../lib/agents-runner.ts";
|
|
7
|
-
import { fakeChild } from "./agents-fake-child.ts";
|
|
6
|
+
import { AgentRunner, QUERY_STALL_MARGIN_MS } from "../lib/agents-runner.ts";
|
|
7
|
+
import { fakeChild, type FakeChild } from "./agents-fake-child.ts";
|
|
8
8
|
|
|
9
9
|
const tick = () => new Promise((resolve) => setImmediate(resolve));
|
|
10
10
|
const agent: AgentDefinition = { name: "worker", description: "", filePath: "/a.md", scope: "global", instructions: "", model: undefined, thinking: undefined, mode: undefined, tools: ["read"] };
|
|
@@ -34,6 +34,31 @@ test("ChildMessenger validates query replies and settles timeout, callback failu
|
|
|
34
34
|
await assert.rejects(disconnected, /closed/);
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
+
test("a timed-out query tells the child what the timeout means, within the error cap, from either side", async () => {
|
|
38
|
+
const guidance = "Parent query timed out: the parent did not answer in time. A late answer may still arrive as a message; continue with work that does not depend on it and state the open question in your report.";
|
|
39
|
+
assert.equal(CHILD_QUERY_TIMEOUT_ERROR, guidance);
|
|
40
|
+
assert.ok(Buffer.byteLength(guidance, "utf8") <= CHILD_QUERY_ERROR_MAX_BYTES);
|
|
41
|
+
// The child's own deadline.
|
|
42
|
+
const timers: Array<() => void> = [];
|
|
43
|
+
const own = new ChildMessenger({ send: () => true, on: () => undefined }, (fn) => { timers.push(fn); return () => {}; });
|
|
44
|
+
const ownTimeout = own.query("which file?");
|
|
45
|
+
timers.at(-1)!();
|
|
46
|
+
await assert.rejects(ownTimeout, (error: Error) => error.message === guidance);
|
|
47
|
+
// The runner's deadline reaches the child as a reply error frame it accepts.
|
|
48
|
+
const child = fakeChild();
|
|
49
|
+
const runnerTimers: Array<{ fn: () => void; ms: number }> = [];
|
|
50
|
+
const runner = new AgentRunner(new TaskStore(), { maxConcurrency: 1, stallTimeoutMs: 10_000 }, { spawn: () => child.child, now: () => 1, schedule: (fn, ms) => { runnerTimers.push({ fn, ms }); return () => {}; }, pi: { command: "pi", args: [] } }, { askUser: async () => ({ cancelled: true }), onQuery: () => {} });
|
|
51
|
+
runner.run(request());
|
|
52
|
+
await tick();
|
|
53
|
+
const listeners: Array<(value: unknown) => void> = [];
|
|
54
|
+
const messenger = new ChildMessenger({ send: (frame) => { child.message(frame as Record<string, unknown>); return true; }, on: (event, listener) => { if (event === "message") listeners.push(listener); } }, () => () => {});
|
|
55
|
+
child.child.send = (frame, done) => { for (const listener of listeners) listener(frame); done?.(null); return true; };
|
|
56
|
+
const before = runnerTimers.length;
|
|
57
|
+
const pending = messenger.query("wait");
|
|
58
|
+
runnerTimers.slice(before).find((timer) => timer.ms === CHILD_QUERY_TIMEOUT_MS)!.fn();
|
|
59
|
+
await assert.rejects(pending, (error: Error) => error.message === guidance);
|
|
60
|
+
});
|
|
61
|
+
|
|
37
62
|
test("ChildMessenger resolves one strictly correlated query reply", async () => {
|
|
38
63
|
const listeners = new Map<string, Array<(value: Record<string, unknown>) => void>>();
|
|
39
64
|
const frames: Array<Record<string, unknown>> = [];
|
|
@@ -168,7 +193,7 @@ test("query expiry, IPC revocation, delayed callbacks, and foreground admission
|
|
|
168
193
|
const task = runner.run(request());
|
|
169
194
|
await tick();
|
|
170
195
|
child.message({ id: "q1", kind: "query", message: "wait" });
|
|
171
|
-
assert.equal(timers.at(-1)?.ms,
|
|
196
|
+
assert.equal(timers.at(-1)?.ms, 120_000);
|
|
172
197
|
let callback: ((error: Error | null) => void) | undefined;
|
|
173
198
|
child.child.send = (_frame, done) => { callback = done; return false; };
|
|
174
199
|
const pending = runner.reply(task.id, "q1", "late", "s1");
|
|
@@ -188,3 +213,118 @@ test("query expiry, IPC revocation, delayed callbacks, and foreground admission
|
|
|
188
213
|
await tick();
|
|
189
214
|
assert.equal(foregroundQueries, 1);
|
|
190
215
|
});
|
|
216
|
+
|
|
217
|
+
// S15 P9a regression probes (independent verifier mwb7rj51-1n-h3x2): late
|
|
218
|
+
// replies, ownership, registry bounds, and the stall watchdog while a query waits.
|
|
219
|
+
function lateHarness(limits: { stallTimeoutMs: number; toolStallTimeoutMs?: number } = { stallTimeoutMs: 600_000 }) {
|
|
220
|
+
const children: FakeChild[] = [];
|
|
221
|
+
const timers: Array<{ fn: () => void; ms: number; cancelled: boolean }> = [];
|
|
222
|
+
const store = new TaskStore();
|
|
223
|
+
const runner = new AgentRunner(store, { maxConcurrency: 100, stallTimeoutMs: limits.stallTimeoutMs, toolStallTimeoutMs: limits.toolStallTimeoutMs }, {
|
|
224
|
+
spawn: () => { const created = fakeChild(); children.push(created); return created.child; }, now: () => 1,
|
|
225
|
+
schedule: (fn, ms) => { const timer = { fn, ms, cancelled: false }; timers.push(timer); return () => { timer.cancelled = true; }; }, pi: { command: "pi", args: [] },
|
|
226
|
+
}, { askUser: async () => ({ cancelled: true }), onQuery: () => {} });
|
|
227
|
+
const expire = () => { const timer = timers.filter((entry) => entry.ms === CHILD_QUERY_TIMEOUT_MS && !entry.cancelled).shift()!; timer.cancelled = true; timer.fn(); };
|
|
228
|
+
const steers = (index = 0) => children[index].written.filter((command) => command.type === "steer").map((command) => command.message as string);
|
|
229
|
+
return { runner, store, children, timers, expire, steers };
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
test("race-replying-then-expiry: a reply in flight when the query expires delivers nothing late", async () => {
|
|
233
|
+
const h = lateHarness();
|
|
234
|
+
const task = h.runner.run(request()); await tick();
|
|
235
|
+
h.children[0].message({ id: "q1", kind: "query", message: "?" });
|
|
236
|
+
let callback: ((error: Error | null) => void) | undefined;
|
|
237
|
+
h.children[0].child.send = (frame, done) => { h.children[0].sent.push(frame as never); callback = done; return true; };
|
|
238
|
+
const pending = h.runner.reply(task.id, "q1", "ans", "s1");
|
|
239
|
+
h.expire();
|
|
240
|
+
callback?.(null);
|
|
241
|
+
assert.equal(await pending, false);
|
|
242
|
+
assert.equal(h.runner.replyLate(task.id, "q1", "ans", "s1"), undefined);
|
|
243
|
+
await tick();
|
|
244
|
+
assert.deepEqual(h.steers(), []);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("wrong-session-late-not-consumed: another session cannot answer or spend a closed query", async () => {
|
|
248
|
+
const h = lateHarness();
|
|
249
|
+
const task = h.runner.run(request()); await tick();
|
|
250
|
+
h.children[0].message({ id: "q1", kind: "query", message: "?" }); h.expire();
|
|
251
|
+
assert.equal(h.runner.replyLate(task.id, "q1", "a", "other"), undefined);
|
|
252
|
+
assert.equal(h.runner.replyLate(task.id, "q1", "a", "s1"), "delivered");
|
|
253
|
+
assert.equal(h.runner.replyLate(task.id, "q1", "b", "s1"), undefined);
|
|
254
|
+
await tick();
|
|
255
|
+
assert.equal(h.steers().length, 1);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("continued-task-gets-no-stale-answer: a late reply to a finished task never reaches a later task", async () => {
|
|
259
|
+
const h = lateHarness();
|
|
260
|
+
const first = h.runner.run(request()); await tick();
|
|
261
|
+
h.children[0].message({ id: "q1", kind: "query", message: "?" }); h.expire();
|
|
262
|
+
h.runner.cancel(first.id); await tick(); await tick();
|
|
263
|
+
const second = h.runner.run(request()); await tick();
|
|
264
|
+
assert.notEqual(first.id, second.id);
|
|
265
|
+
assert.equal(h.runner.replyLate(first.id, "q1", "a", "s1"), "not running");
|
|
266
|
+
assert.equal(h.runner.replyLate(second.id, "q1", "a", "s1"), undefined);
|
|
267
|
+
await tick();
|
|
268
|
+
assert.deepEqual(h.steers(1), []);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
test("same-request-id-two-tasks: each late answer reaches only its own task", async () => {
|
|
272
|
+
const h = lateHarness();
|
|
273
|
+
const a = h.runner.run(request()); const b = h.runner.run(request()); await tick();
|
|
274
|
+
h.children[0].message({ id: "q1", kind: "query", message: "?" }); h.children[1].message({ id: "q1", kind: "query", message: "?" });
|
|
275
|
+
h.expire(); h.expire();
|
|
276
|
+
assert.equal(h.runner.replyLate(b.id, "q1", "forB", "s1"), "delivered"); await tick();
|
|
277
|
+
assert.deepEqual(h.steers(0), []); assert.equal(h.steers(1).length, 1);
|
|
278
|
+
assert.equal(h.runner.replyLate(a.id, "q1", "forA", "s1"), "delivered"); await tick();
|
|
279
|
+
assert.match(h.steers(0)[0], /forA$/); assert.equal(h.steers(1).length, 1);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("closed-registry-bounds: 16 closed queries per task and 64 tasks, never throwing", async () => {
|
|
283
|
+
const h = lateHarness();
|
|
284
|
+
const task = h.runner.run(request()); await tick();
|
|
285
|
+
for (let index = 1; index <= 17; index += 1) { h.children[0].message({ id: `q${index}`, kind: "query", message: "?" }); h.expire(); }
|
|
286
|
+
assert.equal(h.runner.replyLate(task.id, "q1", "a", "s1"), undefined);
|
|
287
|
+
assert.equal(h.runner.replyLate(task.id, "q2", "a", "s1"), "delivered");
|
|
288
|
+
const ids = [task.id];
|
|
289
|
+
for (let index = 1; index <= 64; index += 1) { const next = h.runner.run(request()); await tick(); ids.push(next.id); h.children[index].message({ id: "q1", kind: "query", message: "?" }); h.expire(); }
|
|
290
|
+
assert.equal(h.runner.replyLate(ids[0], "q3", "a", "s1"), undefined, "the oldest task is evicted");
|
|
291
|
+
assert.equal(h.runner.replyLate(ids[1], "q1", "a", "s1"), "delivered");
|
|
292
|
+
assert.equal(h.runner.replyLate(ids[64], "q1", "a", "s1"), "delivered");
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("oversize-late-not-consumed: a too-large late reply is reported and the request stays answerable", async () => {
|
|
296
|
+
const h = lateHarness();
|
|
297
|
+
const task = h.runner.run(request()); await tick();
|
|
298
|
+
h.children[0].message({ id: "q1", kind: "query", message: "?" }); h.expire();
|
|
299
|
+
assert.equal(h.runner.replyLate(task.id, "q1", "x".repeat(CHILD_MESSAGE_MAX_BYTES + 1), "s1"), "too large");
|
|
300
|
+
assert.equal(h.runner.replyLate(task.id, "q1", "x".repeat(CHILD_MESSAGE_MAX_BYTES), "s1"), "delivered");
|
|
301
|
+
await tick();
|
|
302
|
+
assert.equal(h.steers().length, 1);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test("query-wait-not-killed-by-tool-stall: no stall timer fires before a pending query's deadline", async () => {
|
|
306
|
+
const h = lateHarness({ stallTimeoutMs: 60_000, toolStallTimeoutMs: 60_000 });
|
|
307
|
+
const task = h.runner.run(request()); await tick();
|
|
308
|
+
h.children[0].emit({ type: "tool_execution_start", toolCallId: "c1", toolName: "subagent_parent_message", args: { kind: "query" } });
|
|
309
|
+
await tick();
|
|
310
|
+
h.children[0].message({ id: "q1", kind: "query", message: "?" });
|
|
311
|
+
const armed = h.timers.filter((timer) => !timer.cancelled).map((timer) => timer.ms);
|
|
312
|
+
assert.ok(armed.every((ms) => ms >= CHILD_QUERY_TIMEOUT_MS), `armed: ${JSON.stringify(armed)}`);
|
|
313
|
+
assert.ok(armed.includes(CHILD_QUERY_TIMEOUT_MS + QUERY_STALL_MARGIN_MS));
|
|
314
|
+
assert.equal(h.store.get(task.id)?.status, "running");
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("the normal stall budget returns once the query expires or is answered", async () => {
|
|
318
|
+
for (const settle of ["expire", "reply"] as const) {
|
|
319
|
+
const h = lateHarness({ stallTimeoutMs: 60_000, toolStallTimeoutMs: 60_000 });
|
|
320
|
+
const task = h.runner.run(request()); await tick();
|
|
321
|
+
h.children[0].message({ id: "q1", kind: "query", message: "?" });
|
|
322
|
+
if (settle === "expire") h.expire();
|
|
323
|
+
else assert.equal(await h.runner.reply(task.id, "q1", "ans", "s1"), true);
|
|
324
|
+
const stall = h.timers.filter((timer) => !timer.cancelled);
|
|
325
|
+
assert.deepEqual(stall.map((timer) => timer.ms), [60_000], settle);
|
|
326
|
+
stall[0]!.fn();
|
|
327
|
+
await tick();
|
|
328
|
+
assert.equal(h.store.get(task.id)?.status, "timed_out", `${settle}: a child that hangs afterwards is still caught`);
|
|
329
|
+
}
|
|
330
|
+
});
|