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
package/lib/agents-runner.ts
CHANGED
|
@@ -5,15 +5,16 @@ import { isSessionChangeEvidence, type SessionChangeEvidence } from "./session-c
|
|
|
5
5
|
import { chmodSync, existsSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { DefaultPackageManager, SettingsManager } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import { tmpdir, userInfo } from "node:os";
|
|
8
|
-
import { dirname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
8
|
+
import { basename, dirname, isAbsolute, join, resolve, win32 } from "node:path";
|
|
9
9
|
import { Duplex, type Readable, type Writable } from "node:stream";
|
|
10
10
|
import { stripVTControlCharacters } from "node:util";
|
|
11
|
+
import { fileURLToPath } from "node:url";
|
|
11
12
|
import { withoutInteractiveHost } from "./rpc-host.ts";
|
|
12
13
|
import { gentlePiConfigHome } from "./agent-home.ts";
|
|
13
14
|
import { resolveBackgroundSubagentsPolicy } from "./background-subagents-policy.ts";
|
|
14
15
|
import { childPackageExtensionArgs } from "./child-package-injection.ts";
|
|
15
16
|
import { AGENT_MODE, formatModelRef, parseModelRef, type AgentDefinition, type AgentMode, type ModelRef } from "./agents-config.ts";
|
|
16
|
-
import { CHILD_QUERY_MAX_INFLIGHT, CHILD_QUERY_TIMEOUT_MS, parseChildFrame, parseChildJobState, validChildMessage, validChildQueryId } from "./agents-messaging.ts";
|
|
17
|
+
import { CHILD_MESSAGE_MAX_BYTES, CHILD_QUERY_MAX_INFLIGHT, CHILD_QUERY_TIMEOUT_ERROR, CHILD_QUERY_TIMEOUT_MS, parseChildFrame, parseChildJobState, validChildMessage, validChildQueryId } from "./agents-messaging.ts";
|
|
17
18
|
import { ParentStandingReviewPermissionBroker } from "./review-session-standing-permission-ipc.ts";
|
|
18
19
|
import { isFinished, normalizeRpcEvent, ToolArgumentProgress, TASK_EVENT, TASK_STATUS, taskLabel, type AskRequest, type ChildResponseObservation, type TaskRecord, type TaskStore, type TerminalErrorCategory } from "./agents-protocol.ts";
|
|
19
20
|
import { WriterSurfaceRegistry, writerSurfaceConflictMessage } from "./writer-surfaces.ts";
|
|
@@ -202,6 +203,8 @@ interface Pending {
|
|
|
202
203
|
interface PendingQuery {
|
|
203
204
|
cancel: () => void;
|
|
204
205
|
replying: boolean;
|
|
206
|
+
/** When the query expires; the stall watchdog never fires before it. */
|
|
207
|
+
deadline: number;
|
|
205
208
|
}
|
|
206
209
|
|
|
207
210
|
interface PendingReply {
|
|
@@ -222,6 +225,8 @@ interface LiveTask {
|
|
|
222
225
|
queries: Map<string, PendingQuery>;
|
|
223
226
|
replies: Map<string, PendingReply>;
|
|
224
227
|
cancelStall: () => void;
|
|
228
|
+
/** True while the armed stall budget was lengthened to cover a pending query. */
|
|
229
|
+
stallCoversQuery?: boolean;
|
|
225
230
|
cancelGrace: () => void;
|
|
226
231
|
processGroup: number | undefined;
|
|
227
232
|
terminal: { status: TaskRecord["status"]; error: string | null } | undefined;
|
|
@@ -266,6 +271,8 @@ export const CHILD_JOBS_ENV = "GENTLE_PI_AGENTS_CHILD_JOBS";
|
|
|
266
271
|
const PARENT_NOTIFICATION_TOOL = "subagent_parent_message";
|
|
267
272
|
/** The exact --tools list, so the child can report requested names Pi dropped silently (#1690). */
|
|
268
273
|
export const REQUESTED_TOOLS_ENV = "GENTLE_PI_AGENTS_REQUESTED_TOOLS";
|
|
274
|
+
/** Set only for the package-owned generic agents: the child drops Pi's skills catalog. */
|
|
275
|
+
export const CHILD_SKILLS_CATALOG_ENV = "GENTLE_PI_AGENTS_NO_SKILLS_CATALOG";
|
|
269
276
|
const DEFAULT_TOOLS: readonly string[] = [];
|
|
270
277
|
const TERMINATION_GRACE_MS = 250;
|
|
271
278
|
const GROUP_CONFIRM_MS = 25;
|
|
@@ -284,10 +291,25 @@ const QUERY_REJECTION_ERRORS = new Set([
|
|
|
284
291
|
"task parent is not the active host session",
|
|
285
292
|
"duplicate query request",
|
|
286
293
|
"too many pending parent queries",
|
|
287
|
-
|
|
294
|
+
CHILD_QUERY_TIMEOUT_ERROR,
|
|
288
295
|
"parent rejected query",
|
|
289
296
|
]);
|
|
290
297
|
const QUERY_REJECTION = Symbol("query rejection");
|
|
298
|
+
// Queries that settled unanswered (expired or closed) stay answerable once as a
|
|
299
|
+
// steering message; bounded per task and across tasks.
|
|
300
|
+
const CLOSED_QUERIES_PER_TASK = 16;
|
|
301
|
+
const CLOSED_QUERY_TASKS = 64;
|
|
302
|
+
// A child waiting on its query is not stalled: the watchdog waits for the
|
|
303
|
+
// query's own deadline plus this margin, then the normal budget returns.
|
|
304
|
+
export const QUERY_STALL_MARGIN_MS = 5_000;
|
|
305
|
+
|
|
306
|
+
/** What a late answer to a closed query became; see `AgentRunner.replyLate`. */
|
|
307
|
+
export type LateReply = "delivered" | "not running" | "too large";
|
|
308
|
+
|
|
309
|
+
/** The steering text a late answer reaches the child with. */
|
|
310
|
+
export function lateQueryAnswer(requestId: string, message: string): string {
|
|
311
|
+
return `Answer to your earlier question (${requestId}; it expired before the reply arrived): ${message}`;
|
|
312
|
+
}
|
|
291
313
|
|
|
292
314
|
function rejectQuery(error: string): never {
|
|
293
315
|
throw { [QUERY_REJECTION]: error };
|
|
@@ -340,6 +362,18 @@ function requestedWebPackagePaths(request: TaskRequest): string[] {
|
|
|
340
362
|
}
|
|
341
363
|
}
|
|
342
364
|
|
|
365
|
+
// The package-owned generic agents receive the exact skill paths they need in
|
|
366
|
+
// the task and read them with `read`, so their children drop Pi's skills
|
|
367
|
+
// catalog (extensions/child-context.ts). Identified by name plus the global
|
|
368
|
+
// `agents/` directory the package installs into; a project or `subagents/`
|
|
369
|
+
// agent reusing a name keeps the catalog.
|
|
370
|
+
const NO_SKILLS_CATALOG_AGENTS = new Set(["gentle-ai-worker", "gentle-ai-explore", "gentle-ai-verify"]);
|
|
371
|
+
|
|
372
|
+
function dropsSkillsCatalog(agent: TaskRequest["agent"]): boolean {
|
|
373
|
+
return NO_SKILLS_CATALOG_AGENTS.has(agent.name) && agent.scope === "global" &&
|
|
374
|
+
basename(dirname(agent.filePath)) === "agents" && basename(agent.filePath) === `${agent.name}.md`;
|
|
375
|
+
}
|
|
376
|
+
|
|
343
377
|
export function childArguments(request: TaskRequest, instructionsPath?: string): string[] {
|
|
344
378
|
const args = ["--mode", "rpc", "--session-dir", request.sessionDir];
|
|
345
379
|
const extensionPaths = [...new Set(request.extensionPaths ?? [])];
|
|
@@ -526,6 +560,7 @@ export class AgentRunner {
|
|
|
526
560
|
private readonly waiters = new Map<string, Array<(task: TaskRecord) => void>>();
|
|
527
561
|
private readonly queryWaiters = new Map<string, Array<(query: TaskQuery | undefined) => void>>();
|
|
528
562
|
private readonly firstQueries = new Map<string, TaskQuery>();
|
|
563
|
+
private readonly closedQueries = new Map<string, string[]>();
|
|
529
564
|
private readonly writers = new WriterSurfaceRegistry();
|
|
530
565
|
private counter = 0;
|
|
531
566
|
|
|
@@ -619,10 +654,34 @@ export class AgentRunner {
|
|
|
619
654
|
query.cancel();
|
|
620
655
|
live.queries.delete(requestId);
|
|
621
656
|
this.hooks.onQuerySettled?.(id, requestId, "replied");
|
|
657
|
+
this.restoreStall(id, live);
|
|
622
658
|
}
|
|
623
659
|
return accepted;
|
|
624
660
|
}
|
|
625
661
|
|
|
662
|
+
/** A reply to a query that settled unanswered: delivered once through `steer`
|
|
663
|
+
* while the task runs; otherwise reported as not running. Undefined when the
|
|
664
|
+
* request was never a closed query of this owner, or was already answered. */
|
|
665
|
+
replyLate(id: string, requestId: string, message: string, parentSessionId: string): LateReply | undefined {
|
|
666
|
+
const task = this.store.get(id);
|
|
667
|
+
const closed = this.closedQueries.get(id);
|
|
668
|
+
if (!task || task.parentSessionId !== parentSessionId || !closed?.includes(requestId)) return undefined;
|
|
669
|
+
// Too large is reported, not consumed: a shorter answer can still go.
|
|
670
|
+
if (Buffer.byteLength(message, "utf8") > CHILD_MESSAGE_MAX_BYTES) return "too large";
|
|
671
|
+
if (!validChildMessage(message)) return undefined;
|
|
672
|
+
closed.splice(closed.indexOf(requestId), 1);
|
|
673
|
+
const live = this.live.get(id);
|
|
674
|
+
if (!live || live.terminal || isFinished(task.status)) return "not running";
|
|
675
|
+
return this.steer(id, lateQueryAnswer(requestId, message)) ? "delivered" : "not running";
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
private recordClosedQuery(taskId: string, requestId: string): void {
|
|
679
|
+
const closed = this.closedQueries.get(taskId) ?? [];
|
|
680
|
+
this.closedQueries.delete(taskId);
|
|
681
|
+
this.closedQueries.set(taskId, [...closed.filter((id) => id !== requestId), requestId].slice(-CLOSED_QUERIES_PER_TASK));
|
|
682
|
+
if (this.closedQueries.size > CLOSED_QUERY_TASKS) this.closedQueries.delete(this.closedQueries.keys().next().value!);
|
|
683
|
+
}
|
|
684
|
+
|
|
626
685
|
cancel(id: string, reason = "cancelled"): boolean {
|
|
627
686
|
const queued = this.queue.findIndex((entry) => entry.task.id === id);
|
|
628
687
|
if (queued >= 0) {
|
|
@@ -688,6 +747,8 @@ export class AgentRunner {
|
|
|
688
747
|
// Do not forward stale legacy child selection or authorization.
|
|
689
748
|
delete env.GENTLE_PI_SDD_REMEDIATION_PLAN;
|
|
690
749
|
delete env.GENTLE_PI_RESEARCH_SELECTION;
|
|
750
|
+
if (request.agent.name === "gentle-ai-verify") env.GENTLE_PI_VERIFIER_PREPARER = fileURLToPath(new URL("../scripts/prepare-verifier.mjs", import.meta.url));
|
|
751
|
+
else delete env.GENTLE_PI_VERIFIER_PREPARER;
|
|
691
752
|
const tools = requestedTools(request);
|
|
692
753
|
if (request.agent.tools.includes("bash_background")) {
|
|
693
754
|
const policy = resolveBackgroundSubagentsPolicy(request.cwd, { env: request.env, gentlePiConfigHome: gentlePiConfigHome(request.env) });
|
|
@@ -703,6 +764,8 @@ export class AgentRunner {
|
|
|
703
764
|
} else delete env[CHILD_JOBS_ENV];
|
|
704
765
|
if (tools !== undefined) env[REQUESTED_TOOLS_ENV] = tools;
|
|
705
766
|
else delete env[REQUESTED_TOOLS_ENV];
|
|
767
|
+
if (dropsSkillsCatalog(request.agent)) env[CHILD_SKILLS_CATALOG_ENV] = "1";
|
|
768
|
+
else delete env[CHILD_SKILLS_CATALOG_ENV];
|
|
706
769
|
let instructionsTransportDir: string | undefined;
|
|
707
770
|
let instructionsTransportPath: string | undefined;
|
|
708
771
|
if (Buffer.byteLength(request.agent.instructions, "utf8") > MAX_INLINE_INSTRUCTIONS_BYTES) {
|
|
@@ -850,7 +913,12 @@ export class AgentRunner {
|
|
|
850
913
|
private armStall(id: string, live: LiveTask): void {
|
|
851
914
|
live.cancelStall();
|
|
852
915
|
const tool = live.inFlightTools.values().next().value;
|
|
853
|
-
const
|
|
916
|
+
const base = tool === undefined ? this.limits.stallTimeoutMs : Math.max(this.limits.toolStallTimeoutMs ?? this.limits.stallTimeoutMs, this.limits.stallTimeoutMs);
|
|
917
|
+
const now = this.deps.now();
|
|
918
|
+
let queryWait = 0;
|
|
919
|
+
for (const query of live.queries.values()) queryWait = Math.max(queryWait, query.deadline - now + QUERY_STALL_MARGIN_MS);
|
|
920
|
+
const budget = Math.max(base, queryWait);
|
|
921
|
+
live.stallCoversQuery = budget > base;
|
|
854
922
|
live.cancelStall = this.deps.schedule(() => {
|
|
855
923
|
const lastStep = this.store.get(id)?.lastStep ?? "starting";
|
|
856
924
|
const minutes = Math.round(budget / 60_000);
|
|
@@ -996,8 +1064,12 @@ export class AgentRunner {
|
|
|
996
1064
|
try {
|
|
997
1065
|
if (live.queries.has(parsed.frame.id)) rejectQuery("duplicate query request");
|
|
998
1066
|
if (live.queries.size >= CHILD_QUERY_MAX_INFLIGHT) rejectQuery("too many pending parent queries");
|
|
999
|
-
query = { replying: false,
|
|
1067
|
+
query = { replying: false, deadline: this.deps.now() + CHILD_QUERY_TIMEOUT_MS, cancel: () => {} };
|
|
1000
1068
|
live.queries.set(parsed.frame.id, query);
|
|
1069
|
+
// Lengthen the stall budget first, so the query's own deadline stays the last timer armed.
|
|
1070
|
+
this.armStall(id, live);
|
|
1071
|
+
const admitted = query;
|
|
1072
|
+
admitted.cancel = this.deps.schedule(() => this.expireQuery(id, live, parsed.frame!.id), CHILD_QUERY_TIMEOUT_MS);
|
|
1001
1073
|
if (!this.hooks.onQuery) rejectQuery("task parent cannot accept queries");
|
|
1002
1074
|
if (this.hooks.onQuery(task, parsed.frame.id, parsed.frame.message) === false) rejectQuery("task parent is not the active host session");
|
|
1003
1075
|
if (task.mode === AGENT_MODE.TASK && !this.firstQueries.has(id)) {
|
|
@@ -1010,6 +1082,7 @@ export class AgentRunner {
|
|
|
1010
1082
|
if (query && live.queries.get(parsed.frame.id) === query) {
|
|
1011
1083
|
query.cancel();
|
|
1012
1084
|
live.queries.delete(parsed.frame.id);
|
|
1085
|
+
this.restoreStall(id, live);
|
|
1013
1086
|
}
|
|
1014
1087
|
this.sendQueryError(live, parsed.frame.id, queryRejection(error));
|
|
1015
1088
|
}
|
|
@@ -1021,7 +1094,16 @@ export class AgentRunner {
|
|
|
1021
1094
|
live.queries.delete(id);
|
|
1022
1095
|
this.hooks.onQuerySettled?.(taskId, id, "expired");
|
|
1023
1096
|
if (query.replying) this.settleReply(live, id, false);
|
|
1024
|
-
else
|
|
1097
|
+
else {
|
|
1098
|
+
this.recordClosedQuery(taskId, id);
|
|
1099
|
+
this.sendQueryError(live, id, CHILD_QUERY_TIMEOUT_ERROR);
|
|
1100
|
+
}
|
|
1101
|
+
this.restoreStall(taskId, live);
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
/** After a query settles, a stall budget lengthened for it returns to normal. */
|
|
1105
|
+
private restoreStall(taskId: string, live: LiveTask): void {
|
|
1106
|
+
if (live.stallCoversQuery && !live.terminal && this.live.get(taskId) === live) this.armStall(taskId, live);
|
|
1025
1107
|
}
|
|
1026
1108
|
|
|
1027
1109
|
private sendQueryError(live: LiveTask, id: string, error: string): void {
|
|
@@ -1059,8 +1141,11 @@ export class AgentRunner {
|
|
|
1059
1141
|
private closeIpc(live: LiveTask): void {
|
|
1060
1142
|
if (live.ipcClosed) return;
|
|
1061
1143
|
live.ipcClosed = true;
|
|
1144
|
+
const taskId = [...this.live].find(([, entry]) => entry === live)?.[0];
|
|
1145
|
+
for (const [requestId, query] of live.queries) if (taskId !== undefined && !query.replying) this.recordClosedQuery(taskId, requestId);
|
|
1062
1146
|
for (const query of live.queries.values()) query.cancel();
|
|
1063
1147
|
live.queries.clear();
|
|
1148
|
+
if (taskId !== undefined) this.restoreStall(taskId, live);
|
|
1064
1149
|
for (const pending of live.replies.values()) pending.resolve(false);
|
|
1065
1150
|
live.replies.clear();
|
|
1066
1151
|
live.child.channel?.unref?.();
|
|
@@ -184,7 +184,23 @@ export class SessionPresenceRegistry {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
} catch (error) { boundary(error); }
|
|
187
|
-
|
|
187
|
+
// gentle-shell#1443: advertises() only proves the socket file exists, not
|
|
188
|
+
// that its listener is alive — a session killed without unlinking would
|
|
189
|
+
// stay advertised forever otherwise. Probe each candidate once, bounded,
|
|
190
|
+
// with the sweep's own refusal-only liveness: provably dead records are
|
|
191
|
+
// excluded and purged; ambiguous outcomes stay advertised.
|
|
192
|
+
const advertised = [...newest.values()];
|
|
193
|
+
const live = new Set<string>();
|
|
194
|
+
let next = 0;
|
|
195
|
+
const worker = async () => {
|
|
196
|
+
while (next < advertised.length) {
|
|
197
|
+
const record = advertised[next++];
|
|
198
|
+
if (await this.liveness(record.endpoint) !== "dead") live.add(record.sessionId);
|
|
199
|
+
else await this.removeOwn(record).catch(() => {});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
await Promise.all(Array.from({ length: Math.min(SWEEP_PROBE_CONCURRENCY, advertised.length) }, worker));
|
|
203
|
+
return advertised.filter((record) => live.has(record.sessionId)).sort((left, right) => left.sessionId.localeCompare(right.sessionId));
|
|
188
204
|
}
|
|
189
205
|
|
|
190
206
|
resolve(id: string): Promise<PresenceRecord> {
|
|
@@ -24,6 +24,11 @@ const quoted = (job: JobRecord) => `${job.id} ("${job.label}")`;
|
|
|
24
24
|
const noun = (job: JobRecord) => (job.kind === "monitor" ? "Monitor" : "Background job");
|
|
25
25
|
const plural = (count: number, word: string) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
26
26
|
|
|
27
|
+
/** What changed on the registry, so a listener can ignore a no-op stop. */
|
|
28
|
+
export type BackgroundJobsChange =
|
|
29
|
+
| { kind: "start"; job: JobRecord }
|
|
30
|
+
| { kind: "stop"; job: JobRecord; changed: boolean };
|
|
31
|
+
|
|
27
32
|
/** One-line outcome, shared by the notice, the list, and the jobs view. */
|
|
28
33
|
export function jobOutcome(job: JobRecord): string {
|
|
29
34
|
if (job.status === "running") return "running";
|
|
@@ -79,7 +84,7 @@ export interface BackgroundJobToolsOptions {
|
|
|
79
84
|
sessionId(ctx: ExtensionContext): string;
|
|
80
85
|
now(): number;
|
|
81
86
|
/** Called after a job starts or stops, so views can refresh. */
|
|
82
|
-
onChange?(): void;
|
|
87
|
+
onChange?(change: BackgroundJobsChange): void;
|
|
83
88
|
/** Starts and stops monitors; without it the monitor tool is not offered. */
|
|
84
89
|
monitors?: MonitorController;
|
|
85
90
|
}
|
|
@@ -113,7 +118,7 @@ export function registerBackgroundJobTools(pi: ExtensionAPI, options: Background
|
|
|
113
118
|
const input = params as { command?: unknown; label?: unknown };
|
|
114
119
|
if (typeof input.command !== "string" || !input.command.trim()) throw new Error("bash_background requires a non-empty command");
|
|
115
120
|
const job = registry.start({ command: input.command, cwd: ctx.cwd, ownerSessionId: options.sessionId(ctx), label: typeof input.label === "string" ? input.label : undefined });
|
|
116
|
-
options.onChange?.();
|
|
121
|
+
options.onChange?.({ kind: "start", job });
|
|
117
122
|
return text(
|
|
118
123
|
`Started background job ${quoted(job)}.\nOutput: ${job.outputPath}\nYou will be notified once when it exits; keep working or end your turn. Stop it with job_stop.`,
|
|
119
124
|
jobDetails(job),
|
|
@@ -146,7 +151,7 @@ export function registerBackgroundJobTools(pi: ExtensionAPI, options: Background
|
|
|
146
151
|
if (typeof input.command !== "string" || !input.command.trim()) throw new Error("monitor requires a non-empty command");
|
|
147
152
|
const timeoutSeconds = typeof input.timeout_seconds === "number" ? input.timeout_seconds : Number.NaN;
|
|
148
153
|
const job = monitors.start({ command: input.command, cwd: ctx.cwd, ownerSessionId: options.sessionId(ctx), label: typeof input.label === "string" ? input.label : undefined, timeoutSeconds });
|
|
149
|
-
options.onChange?.();
|
|
154
|
+
options.onChange?.({ kind: "start", job });
|
|
150
155
|
return text(
|
|
151
156
|
`Started monitor ${quoted(job)} for up to ${timeoutSeconds}s.\nOutput: ${job.outputPath}\nEach new output line reaches you as an event; keep working or end your turn. Stop it with job_stop.`,
|
|
152
157
|
jobDetails(job),
|
|
@@ -166,7 +171,7 @@ export function registerBackgroundJobTools(pi: ExtensionAPI, options: Background
|
|
|
166
171
|
const wasRunning = job.status === "running";
|
|
167
172
|
options.monitors?.cancel(job.id);
|
|
168
173
|
registry.stop(job.id);
|
|
169
|
-
options.onChange?.();
|
|
174
|
+
options.onChange?.({ kind: "stop", job, changed: wasRunning });
|
|
170
175
|
return text(wasRunning ? `Stopped ${quoted(job)}.` : `${quoted(job)} was already ${jobOutcome(job)}.`, jobDetails(job));
|
|
171
176
|
},
|
|
172
177
|
});
|
|
@@ -4,10 +4,13 @@ import { basename, dirname, isAbsolute, parse, relative, resolve } from "node:pa
|
|
|
4
4
|
import type { OrchestratorMode } from "./agent-profiles.ts";
|
|
5
5
|
import { contextBackstopReached, type MeasuredContext } from "./context-backstop.ts";
|
|
6
6
|
import { resolveSessionWorktree, type WorktreeResolver } from "./session-worktree-registry.ts";
|
|
7
|
+
import type { MessageToolCall } from "./writer-batch-admission.ts";
|
|
8
|
+
import { overlappingSurfaces } from "./writer-surfaces.ts";
|
|
7
9
|
|
|
8
10
|
const WRITER_NAMES = ["gentle-ai-worker", "worker", "jd-fix-agent"];
|
|
11
|
+
// The rule sentence closes every rejection, after the specific problem (cost-speed P9b).
|
|
9
12
|
export const WRITER_EDIT_SURFACE_REJECTION =
|
|
10
|
-
"
|
|
13
|
+
"Fix only that section, then relaunch with the rest of the task unchanged, never shortened or re-summarized; derive the surfaces from the task (narrow repository-relative paths or globs, one per line, until the next Markdown heading) and do not ask the human to author paths or globs.";
|
|
11
14
|
// One heading matcher: the parser scans with the global form, and continuation
|
|
12
15
|
// inheritance tests presence with the same source (review R3-003).
|
|
13
16
|
const ALLOWED_EDIT_SURFACES_HEADING_LINE = /^## Allowed edit surfaces[ \t]*$/im;
|
|
@@ -23,48 +26,175 @@ function isTaskScopedRepositoryRelativePath(value: string, backticked: boolean):
|
|
|
23
26
|
return !/[?*\[\]{}]/.test(path.split("/")[0]);
|
|
24
27
|
}
|
|
25
28
|
|
|
29
|
+
const INVISIBLE = /\p{Cc}|\p{Zl}|\p{Zp}/u;
|
|
30
|
+
const MARKER_ONLY = /^(?:[-*+]|\d+[.)])$/;
|
|
31
|
+
// An echoed entry is at most this many UTF-8 bytes, ellipsis included (after escaping and masking), cut on a code point.
|
|
32
|
+
const SHOWN_ENTRY_BYTES = 80;
|
|
33
|
+
const ELLIPSIS = "…";
|
|
34
|
+
|
|
35
|
+
function surfaceEntry(source: string): { path: string; valid: boolean } {
|
|
36
|
+
const line = source.replace(/^ {0,3}/, "");
|
|
37
|
+
const unlisted = line.replace(MARKDOWN_LIST_MARKER, "");
|
|
38
|
+
const quoted = unlisted.match(/^`([^`]+)`$/);
|
|
39
|
+
const path = quoted?.[1] ?? unlisted;
|
|
40
|
+
return { path, valid: !(MARKER_ONLY.test(line) || (unlisted.includes("`") && !quoted) || INVISIBLE.test(source) || !isTaskScopedRepositoryRelativePath(path, !!quoted)) };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Why an entry `surfaceEntry` rejected is invalid, and its fix. Rule (verifier blocker 3): the fix, applied
|
|
44
|
+
// literally to the entry, yields the path the author meant or an input that is still rejected, never a
|
|
45
|
+
// different accepted surface. So wrapping is suggested only for an entry that reads as one path with spaces,
|
|
46
|
+
// text beside a path is moved out rather than wrapped, and the path-shape reasons come before the whitespace ones.
|
|
47
|
+
function surfaceEntryProblem(source: string): string {
|
|
48
|
+
const line = source.replace(/^ {0,3}/, "");
|
|
49
|
+
const unlisted = line.replace(MARKDOWN_LIST_MARKER, "");
|
|
50
|
+
const quoted = unlisted.match(/^`([^`]+)`$/);
|
|
51
|
+
const path = quoted?.[1] ?? unlisted;
|
|
52
|
+
if (MARKER_ONLY.test(line)) return "is a list marker with no path; put the path after it or delete the line";
|
|
53
|
+
if (INVISIBLE.test(source)) return "contains a control or line-separator character; retype it without that character";
|
|
54
|
+
if (unlisted.includes("`") && !quoted) return /`[^`]+`/.test(unlisted)
|
|
55
|
+
? "has text outside its backticked path; move that text below another Markdown heading"
|
|
56
|
+
: "has stray backticks; remove them";
|
|
57
|
+
// The raw line, not the unlisted one: a real indented heading keeps its leftover indent, while `- # foo`
|
|
58
|
+
// is list text, and moving it to the line start would make a heading that ends the section (PR #3114 review).
|
|
59
|
+
if (/^ +#{1,6} /.test(line)) return "is a heading indented 4+ spaces, so it does not end the section; start it at the line start";
|
|
60
|
+
if (unlisted !== line && /^#{1,6}\s/.test(unlisted)) return "is text under a list marker, not a path; move it below another Markdown heading, as a line of its own outside the list";
|
|
61
|
+
const spaced = !quoted && /\p{White_Space}/u.test(unlisted);
|
|
62
|
+
const normalized = path.replace(/\\/g, "/");
|
|
63
|
+
const relativePath = normalized.replace(/^(?:\.\/)+/, "");
|
|
64
|
+
const firstSegment = relativePath.split("/")[0];
|
|
65
|
+
if (spaced ? /^(?:\/|~\/|[A-Za-z]:\/)/.test(normalized) : isAbsolute(path) || /^(?:[A-Za-z]:|\/|~)/.test(normalized) || relativePath.startsWith("/")) return "is absolute or home-relative; use a repository-relative path";
|
|
66
|
+
if (!relativePath || relativePath === ".") return "names the whole repository; list only the paths or narrow globs the task edits";
|
|
67
|
+
if (relativePath.split("/").includes("..")) return "has a `..` segment; use a path inside the repository";
|
|
68
|
+
if (/[?*\[\]{}]/.test(firstSegment) && !/\p{White_Space}/u.test(firstSegment)) return "starts with a glob, so it spans the whole repository; start with a directory, for example `src/**/*.ts`";
|
|
69
|
+
if (spaced) {
|
|
70
|
+
if (!isTaskScopedRepositoryRelativePath(unlisted, true)) return "is not a path; move it below another Markdown heading";
|
|
71
|
+
const words = unlisted.split(/\p{White_Space}+/u);
|
|
72
|
+
const first = words[0], rest = unlisted.slice(first.length);
|
|
73
|
+
const pathLike = (word: string) => isTaskScopedRepositoryRelativePath(word, false) && (word.includes("/") || /\.[\w-]{1,10}$/.test(word));
|
|
74
|
+
const parts = commaParts(unlisted);
|
|
75
|
+
if (parts.length > 1 && parts.every(part => isTaskScopedRepositoryRelativePath(part, false))) return "lists several paths; put one path per line";
|
|
76
|
+
if (pathLike(first.replace(/:$/, "")) && (first.endsWith(":") || /^\p{White_Space}+(?:#|\/\/|\(|—|–|-|:)/u.test(rest))) return "has text after the path; move that text below another Markdown heading";
|
|
77
|
+
if (words.length === 2 && first.endsWith(":") && pathLike(words[1])) return "has a label before the path; keep only the path";
|
|
78
|
+
if (!first.endsWith(":") && !/[.:;,!?]$/.test(unlisted) && /\.[\w-]{1,10}$|\/$|\*$/.test(words.at(-1)!)) return "has spaces outside backticks; if it is one path, wrap the whole entry in backticks, otherwise move it below another Markdown heading";
|
|
79
|
+
return "looks like prose; move it below another Markdown heading";
|
|
80
|
+
}
|
|
81
|
+
return "is not a narrow repository-relative path or glob; use one";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const WHITE_SPACE = /\p{White_Space}/u;
|
|
85
|
+
|
|
86
|
+
// `text.split(/\p{White_Space}*,\p{White_Space}*/u).filter(Boolean)` in linear time: that regex backtracks
|
|
87
|
+
// quadratically over a long whitespace run with no comma (PR #3114 review).
|
|
88
|
+
function commaParts(text: string): string[] {
|
|
89
|
+
const raw = text.split(",");
|
|
90
|
+
return raw.map((part, index) => {
|
|
91
|
+
let start = 0, end = part.length;
|
|
92
|
+
if (index > 0) while (start < end && WHITE_SPACE.test(part[start])) start++;
|
|
93
|
+
if (index < raw.length - 1) while (end > start && WHITE_SPACE.test(part[end - 1])) end--;
|
|
94
|
+
return part.slice(start, end);
|
|
95
|
+
}).filter(Boolean);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const SECRET_WORDS = ["key", "token", "secret", "password", "passwd", "pwd", "credential", "credentials", "auth"];
|
|
99
|
+
const isWordCode = (code: number) => (code >= 48 && code <= 57) || (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code === 95;
|
|
100
|
+
const isLabelCode = (code: number) => isWordCode(code) || code === 46 || code === 45; // [\w.-]
|
|
101
|
+
const isTokenCode = (code: number) => isWordCode(code) || code === 43 || code === 61 || code === 45; // [\w+=-]
|
|
102
|
+
const isLineTerminator = (code: number) => code === 10 || code === 13 || code === 0x2028 || code === 0x2029;
|
|
103
|
+
const isRegExpSpace = (char: string) => /\s/.test(char);
|
|
104
|
+
|
|
105
|
+
// Masking in one forward scan with no backtracking (PR #3114 review), equal to the earlier
|
|
106
|
+
// `.replace(/([\w.-]*(?:key|token|secret|passw(?:or)?d|pwd|credentials?|auth)\s*[:=]\s*).*/i, "$1***")`
|
|
107
|
+
// then `.replace(/[\w+=-]{24,}/g, run => /\d/.test(run) ? "***" : run)`. The keyword must end its [\w.-] run
|
|
108
|
+
// (neither `\s`, `:` nor `=` is in it), so the first run ending in one and followed by `\s*[:=]` is the match,
|
|
109
|
+
// starting at that run's first character. Whole runs are masked, so no masked token is ever cut.
|
|
110
|
+
function maskSecrets(text: string): string {
|
|
111
|
+
let masked = text;
|
|
112
|
+
for (let index = 0; index < text.length;) {
|
|
113
|
+
if (!isLabelCode(text.charCodeAt(index))) { index++; continue; }
|
|
114
|
+
const start = index;
|
|
115
|
+
while (index < text.length && isLabelCode(text.charCodeAt(index))) index++;
|
|
116
|
+
const tail = text.slice(Math.max(start, index - 11), index).toLowerCase();
|
|
117
|
+
if (!SECRET_WORDS.some(word => tail.endsWith(word))) continue;
|
|
118
|
+
let value = index;
|
|
119
|
+
while (value < text.length && isRegExpSpace(text[value])) value++;
|
|
120
|
+
if (text[value] !== ":" && text[value] !== "=") continue;
|
|
121
|
+
value++;
|
|
122
|
+
while (value < text.length && isRegExpSpace(text[value])) value++;
|
|
123
|
+
let end = value;
|
|
124
|
+
while (end < text.length && !isLineTerminator(text.charCodeAt(end))) end++;
|
|
125
|
+
masked = `${text.slice(0, value)}***${text.slice(end)}`;
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
const pieces: string[] = [];
|
|
129
|
+
for (let index = 0; index < masked.length;) {
|
|
130
|
+
const start = index;
|
|
131
|
+
while (index < masked.length && isTokenCode(masked.charCodeAt(index))) index++;
|
|
132
|
+
if (index === start) { pieces.push(masked[index++]); continue; }
|
|
133
|
+
const run = masked.slice(start, index);
|
|
134
|
+
pieces.push(run.length >= 24 && /\d/.test(run) ? "***" : run);
|
|
135
|
+
}
|
|
136
|
+
return pieces.join("");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Quote an offending line without echoing a secret or an unbounded line: secret-looking assignment values
|
|
140
|
+
// and long digit-bearing tokens are masked, invisible characters escaped, then cut at SHOWN_ENTRY_BYTES.
|
|
141
|
+
// Only ASCII spaces are stripped from the ends, so a tab at either end is shown escaped (PR #3114 review).
|
|
142
|
+
// Every step is linear in the line length.
|
|
143
|
+
function shownEntry(line: string): string {
|
|
144
|
+
let start = 0, end = line.length;
|
|
145
|
+
while (start < end && line[start] === " ") start++;
|
|
146
|
+
while (end > start && line[end - 1] === " ") end--;
|
|
147
|
+
const text = maskSecrets(line.slice(start, end))
|
|
148
|
+
.replace(/\p{Cc}|\p{Zl}|\p{Zp}/gu, char => `\\u${char.codePointAt(0)!.toString(16).padStart(4, "0")}`);
|
|
149
|
+
if (Buffer.byteLength(text) <= SHOWN_ENTRY_BYTES) return text;
|
|
150
|
+
let shown = "", bytes = Buffer.byteLength(ELLIPSIS);
|
|
151
|
+
for (const char of text) {
|
|
152
|
+
bytes += Buffer.byteLength(char);
|
|
153
|
+
if (bytes > SHOWN_ENTRY_BYTES) break;
|
|
154
|
+
shown += char;
|
|
155
|
+
}
|
|
156
|
+
return `${shown}${ELLIPSIS}`;
|
|
157
|
+
}
|
|
158
|
+
|
|
26
159
|
// This is the same canonical parser used by both the tool hook and executor.
|
|
27
160
|
// Prose cannot close the section, and repeated sections must agree exactly.
|
|
28
161
|
// A rejection carries the concrete problem so the caller repairs only the
|
|
29
162
|
// section instead of re-summarizing the whole task (gentle-shell#1713).
|
|
30
163
|
function parseAllowedEditSurfaces(values: readonly unknown[]): { paths: string[] } | { problem: string } {
|
|
31
164
|
let expected: string[] | undefined;
|
|
165
|
+
let section = 0;
|
|
32
166
|
for (const value of values) {
|
|
33
167
|
if (typeof value !== "string") continue;
|
|
34
168
|
for (const heading of value.matchAll(ALLOWED_EDIT_SURFACES_HEADING)) {
|
|
169
|
+
section++;
|
|
35
170
|
const lines = value.slice((heading.index ?? 0) + heading[0].length).split(/\r?\n/);
|
|
36
171
|
const end = lines.findIndex(line => MARKDOWN_HEADING_LINE.test(line));
|
|
37
172
|
const entries = (end === -1 ? lines : lines.slice(0, end)).map(line => line.replace(/ +$/g, "")).filter(Boolean);
|
|
38
|
-
if (!entries.length) return { problem: "The section has no entries." };
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const quotable = prose && !quoted && !unlisted.includes("`") && !/\p{Cc}|\p{Zl}|\p{Zp}/u.test(source) && isTaskScopedRepositoryRelativePath(unlisted, true);
|
|
52
|
-
const shown = (prose ? source.trim() : path).replace(/\p{Cc}|\p{Zl}|\p{Zp}/gu, " ");
|
|
53
|
-
const bounded = shown.length > 120 ? `${shown.slice(0, 120)}...` : shown;
|
|
54
|
-
return { problem: quotable
|
|
55
|
-
? `Line "${bounded}" is not a valid surface entry; if it is a path, wrap the whole entry in backticks, otherwise move it under a following Markdown heading.`
|
|
56
|
-
: prose
|
|
57
|
-
? `Line "${bounded}" is not a valid surface entry; move prose under a following Markdown heading.`
|
|
58
|
-
: `Entry "${bounded}" is not a narrow repository-relative path; remove absolute paths, \`..\` segments, root globs, and stray backticks.` };
|
|
59
|
-
}
|
|
60
|
-
paths.push(path);
|
|
173
|
+
if (!entries.length) return { problem: "The `## Allowed edit surfaces` section has no entries; add one path per line before the next heading." };
|
|
174
|
+
const parsed = entries.map(surfaceEntry);
|
|
175
|
+
const invalid = parsed.findIndex(entry => !entry.valid);
|
|
176
|
+
if (invalid !== -1) {
|
|
177
|
+
const more = parsed.slice(invalid + 1).filter(entry => !entry.valid).length;
|
|
178
|
+
const position = `non-empty line ${invalid + 1}${section > 1 ? ` of section ${section}` : ""}`;
|
|
179
|
+
return { problem: `Allowed edit surfaces entry "${shownEntry(entries[invalid])}" (${position}) ${surfaceEntryProblem(entries[invalid])}.${more ? ` ${more} more invalid line${more === 1 ? " follows" : "s follow"}.` : ""}` };
|
|
180
|
+
}
|
|
181
|
+
const unique = [...new Set(parsed.map(entry => entry.path))].sort();
|
|
182
|
+
if (expected) {
|
|
183
|
+
const previous = expected;
|
|
184
|
+
const differing = [...previous.filter(path => !unique.includes(path)), ...unique.filter(path => !previous.includes(path))].sort()[0];
|
|
185
|
+
if (differing !== undefined) return { problem: `Repeated \`## Allowed edit surfaces\` sections disagree on "${shownEntry(differing)}"; keep one section or list the same entries in each.` };
|
|
61
186
|
}
|
|
62
|
-
const unique = [...new Set(paths)].sort();
|
|
63
|
-
if (expected && (expected.length !== unique.length || expected.some((path, index) => path !== unique[index]))) return { problem: "Repeated sections list different surfaces." };
|
|
64
187
|
expected = unique;
|
|
65
188
|
}
|
|
66
189
|
}
|
|
67
|
-
|
|
190
|
+
if (expected) return { paths: expected };
|
|
191
|
+
// A near-miss heading (wrong level, trailing colon, missing word) is the usual cause: name it.
|
|
192
|
+
for (const value of values) {
|
|
193
|
+
if (typeof value !== "string") continue;
|
|
194
|
+
const alias = value.split(/\r?\n/).find(line => /^ {0,3}#{1,6}[ \t]/.test(line) && /\b(?:edit[ \t]+surfaces?|allowed[ \t]+(?:edit|files|paths))\b/i.test(line));
|
|
195
|
+
if (alias) return { problem: `No \`## Allowed edit surfaces\` heading was found; "${shownEntry(alias)}" is close: rename it to exactly \`## Allowed edit surfaces\`.` };
|
|
196
|
+
}
|
|
197
|
+
return { problem: "No `## Allowed edit surfaces` heading was found; add it with one path per line." };
|
|
68
198
|
}
|
|
69
199
|
|
|
70
200
|
export function allowedEditSurfaces(...values: unknown[]): string[] | undefined {
|
|
@@ -78,19 +208,39 @@ export function rejectUnscopedBoundedWriterDispatch(input: unknown): { block: tr
|
|
|
78
208
|
if (typeof record.agent !== "string" || !WRITER_NAMES.includes(record.agent)) return undefined;
|
|
79
209
|
const parsed = parseAllowedEditSurfaces([record.task, record.context]);
|
|
80
210
|
if ("paths" in parsed) return undefined;
|
|
81
|
-
return { block: true, reason: `${
|
|
211
|
+
return { block: true, reason: `${parsed.problem} ${WRITER_EDIT_SURFACE_REJECTION}` };
|
|
82
212
|
}
|
|
83
213
|
|
|
84
214
|
// Pain-point iteration S16: prompt rules alone did not stop small-task delegation (a two-feature request still
|
|
85
215
|
// started two writers for ~35-line units). A generic writer launch is admitted only for a task of an existing ODD
|
|
86
|
-
// feature document,
|
|
87
|
-
// runtime notice, lib/context-backstop.ts). Judgment Day fix agents and continuations keep their own protocols.
|
|
216
|
+
// feature document, when the parent's measured context reaches the context backstop (the same threshold as the
|
|
217
|
+
// runtime notice, lib/context-backstop.ts), or as one of 2+ disjoint writers alone in one message (P6, below). Judgment Day fix agents and continuations keep their own protocols.
|
|
88
218
|
// A line that starts with `Spec:` (optionally as a list item), names an odd/tasks document, and names a task
|
|
89
219
|
// `T<n>` later on the same line: covers the canon (`, T2, S3-S4`), the delegation card (`(read until "## Log").
|
|
90
220
|
// Do T2; S3.`), and comma-free forms (`.md T1 S1;`). A mention inside prose does not start the line.
|
|
91
221
|
const FEATURE_DOCUMENT_TASK = /^[ \t]*(?:[-*+][ \t]+)?Spec:[ \t]*`?(odd\/tasks\/[^\s,`()]+\.md)`?[^\n]*?\bT\d+\b/gm;
|
|
92
222
|
export const WRITER_FEATURE_DOCUMENT_REJECTION =
|
|
93
|
-
"Writers run only for a task of an existing ODD feature document (`Spec: odd/tasks/<feature>.md, T<n>` in the task)
|
|
223
|
+
"Writers run only for a task of an existing ODD feature document (`Spec: odd/tasks/<feature>.md, T<n>` in the task), when your measured context reaches the context backstop, or as two or more writers with disjoint `## Allowed edit surfaces` launched together in one message with no other tool call. This unit has none: write this unit inline yourself now; do not retry the launch, and never create a feature document only to launch writers.";
|
|
224
|
+
|
|
225
|
+
// cost-speed P6 (R1, L41): the parallel reason is two or more independent units launched together in one turn,
|
|
226
|
+
// in background mode or not. Pi runs one message's calls in parallel unless one is sequential, so the batch must
|
|
227
|
+
// hold only generic writer launches: any other call beside them (a sequential `todo`, an explorer, a verifier)
|
|
228
|
+
// voids it. Admission cannot measure unit size; "each heavier than a subagent start" stays a prompt rule.
|
|
229
|
+
function parallelWriterBatch(calls: readonly MessageToolCall[] | undefined): boolean {
|
|
230
|
+
if (!calls || calls.length < 2) return false;
|
|
231
|
+
const claims: string[][] = [];
|
|
232
|
+
for (const call of calls) {
|
|
233
|
+
const input = call.arguments;
|
|
234
|
+
if (call.name !== "subagent_run" || !input || typeof input !== "object" || Array.isArray(input)) return false;
|
|
235
|
+
const record = input as Record<string, unknown>;
|
|
236
|
+
if (typeof record.agent !== "string" || !isGenericBoundedWriter(record.agent)) return false;
|
|
237
|
+
const surfaces = allowedEditSurfaces(record.task, record.context);
|
|
238
|
+
if (!surfaces) return false;
|
|
239
|
+
if (claims.some(other => overlappingSurfaces(surfaces, other).length > 0)) return false;
|
|
240
|
+
claims.push(surfaces);
|
|
241
|
+
}
|
|
242
|
+
return true;
|
|
243
|
+
}
|
|
94
244
|
|
|
95
245
|
function featureDocumentExists(root: string, relativePath: string): boolean {
|
|
96
246
|
// Resolve symlinks on both sides so a document linked from outside the root, or an odd/tasks directory linked
|
|
@@ -131,6 +281,8 @@ export function rejectUndocumentedWriterLaunch(
|
|
|
131
281
|
* Omitted means organic, the admission above.
|
|
132
282
|
*/
|
|
133
283
|
orchestratorMode?: OrchestratorMode;
|
|
284
|
+
/** Every tool call of the assistant message that issued this launch, itself included (`sameMessageToolCalls`). */
|
|
285
|
+
sameMessageCalls?: readonly MessageToolCall[];
|
|
134
286
|
},
|
|
135
287
|
): { block: true; reason: string } | undefined {
|
|
136
288
|
if (!input || typeof input !== "object" || Array.isArray(input)) return undefined;
|
|
@@ -139,6 +291,7 @@ export function rejectUndocumentedWriterLaunch(
|
|
|
139
291
|
if (options.orchestratorMode === "full-delegation") return undefined;
|
|
140
292
|
if (namesExistingFeatureDocumentTask([record.task, record.context], options.root)) return undefined;
|
|
141
293
|
if (contextBackstopReached(options.contextUsage, options.env)) return undefined;
|
|
294
|
+
if (parallelWriterBatch(options.sameMessageCalls)) return undefined;
|
|
142
295
|
return { block: true, reason: WRITER_FEATURE_DOCUMENT_REJECTION };
|
|
143
296
|
}
|
|
144
297
|
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
// same context files as the orchestrator, including gentle-ai managed blocks
|
|
3
3
|
// that bind themselves to the orchestrator only. Those blocks cost ~37k prefix
|
|
4
4
|
// tokens per child and give a worker orchestration rules it must not follow.
|
|
5
|
-
// This module removes exactly those blocks
|
|
5
|
+
// This module removes exactly those blocks plus the engram-protocol memory
|
|
6
|
+
// block and keeps everything else. The primary session applies the same filter
|
|
7
|
+
// while Gentle Shell injects its own orchestrator prompt and gentle-engram
|
|
8
|
+
// injects its own MEMORY_INSTRUCTIONS (extensions/gentle-ai.ts
|
|
9
|
+
// before_agent_start). Only the injected context is filtered: every file on
|
|
10
|
+
// disk keeps its blocks byte-for-byte for runtimes that read them as workspace
|
|
11
|
+
// files and carry no runtime-injected equivalent (OpenClaw).
|
|
6
12
|
|
|
7
13
|
export const ORCHESTRATOR_ONLY_MANAGED_BLOCKS = [
|
|
8
14
|
"orchestrator",
|
|
@@ -13,6 +19,15 @@ export const ORCHESTRATOR_ONLY_MANAGED_BLOCKS = [
|
|
|
13
19
|
|
|
14
20
|
export type OrchestratorOnlyManagedBlock = (typeof ORCHESTRATOR_ONLY_MANAGED_BLOCKS)[number];
|
|
15
21
|
|
|
22
|
+
// gentle-ai's managed memory protocol. Dropped from injected context like an
|
|
23
|
+
// orchestrator-only block, but for a different reason: gentle-engram injects
|
|
24
|
+
// the equivalent instructions every turn, so the loaded copy is a duplicate
|
|
25
|
+
// that only adds session-start ceremony.
|
|
26
|
+
export const ENGRAM_PROTOCOL_MANAGED_BLOCK = "engram-protocol";
|
|
27
|
+
|
|
28
|
+
// Every managed block this filter removes from an injected context file.
|
|
29
|
+
const DROPPED_MANAGED_BLOCKS: ReadonlySet<string> = new Set([...ORCHESTRATOR_ONLY_MANAGED_BLOCKS, ENGRAM_PROTOCOL_MANAGED_BLOCK]);
|
|
30
|
+
|
|
16
31
|
export interface ContextFile {
|
|
17
32
|
path: string;
|
|
18
33
|
content: string;
|
|
@@ -37,8 +52,6 @@ export interface ContextFileOptions {
|
|
|
37
52
|
contextFiles?: ContextFile[];
|
|
38
53
|
}
|
|
39
54
|
|
|
40
|
-
const REMOVED_NAMES: ReadonlySet<string> = new Set(ORCHESTRATOR_ONLY_MANAGED_BLOCKS);
|
|
41
|
-
|
|
42
55
|
// A managed marker counts only when it is alone on its line. Inline mentions
|
|
43
56
|
// (prose, inline code) and markers inside fenced code are plain text.
|
|
44
57
|
const MARKER_LINE = /^[ \t]*<!--[ \t]*(\/?)gentle-ai:([A-Za-z0-9][A-Za-z0-9._-]*)[ \t]*-->[ \t]*$/;
|
|
@@ -94,7 +107,7 @@ export function filterOrchestratorOnlyBlocks(content: string): ManagedBlockFilte
|
|
|
94
107
|
// A block reopened inside itself is ambiguous: fail safe.
|
|
95
108
|
if (stack.includes(name)) return unchanged(content);
|
|
96
109
|
stack.push(name);
|
|
97
|
-
if (
|
|
110
|
+
if (DROPPED_MANAGED_BLOCKS.has(name)) removedBlocks += 1;
|
|
98
111
|
lines.push({ text, owner: name });
|
|
99
112
|
continue;
|
|
100
113
|
}
|
|
@@ -112,7 +125,7 @@ export function filterOrchestratorOnlyBlocks(content: string): ManagedBlockFilte
|
|
|
112
125
|
let trailingBlanks = 0;
|
|
113
126
|
let afterRemoval = false;
|
|
114
127
|
for (const line of lines) {
|
|
115
|
-
if (line.owner !== null &&
|
|
128
|
+
if (line.owner !== null && DROPPED_MANAGED_BLOCKS.has(line.owner)) {
|
|
116
129
|
afterRemoval = true;
|
|
117
130
|
continue;
|
|
118
131
|
}
|
|
@@ -154,7 +167,9 @@ export function filterChildContextFiles<T extends ContextFile>(files: readonly T
|
|
|
154
167
|
// Replaces contextFiles on the SAME options object: pi-claude-bridge keeps a
|
|
155
168
|
// reference to it and rebuilds its prompt from its contextFiles. Never
|
|
156
169
|
// throws; on any error the original context files stay in place.
|
|
157
|
-
export function filterChildSessionContextFiles(
|
|
170
|
+
export function filterChildSessionContextFiles(
|
|
171
|
+
options: ContextFileOptions | null | undefined,
|
|
172
|
+
): ChildContextFilesResult<ContextFile> | null {
|
|
158
173
|
try {
|
|
159
174
|
if (!options || !Array.isArray(options.contextFiles)) return null;
|
|
160
175
|
const result = filterChildContextFiles(options.contextFiles);
|