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
|
@@ -25,6 +25,7 @@ import type { Api, AssistantMessage, Context, Model, ProviderEnv, ProviderHeader
|
|
|
25
25
|
import type { completeSimple } from "@earendil-works/pi-ai/compat";
|
|
26
26
|
import { SAFE_MODEL_ID_PATTERN, type ServiceTier } from "./model-routing-authority.ts";
|
|
27
27
|
import { applyOpenAITier, supportsOpenAIFast } from "./openai-fast-tier.ts";
|
|
28
|
+
import { readReviewerStream, type ReviewerStream, type ReviewerProgressObserver } from "./reviewer-stream.ts";
|
|
28
29
|
|
|
29
30
|
// ---------------------------------------------------------------------------
|
|
30
31
|
// Registry seam — a structural subset of pi's live ModelRegistry
|
|
@@ -40,11 +41,12 @@ import { applyOpenAITier, supportsOpenAIFast } from "./openai-fast-tier.ts";
|
|
|
40
41
|
|
|
41
42
|
/**
|
|
42
43
|
* The single method this module needs from a resolved provider. pi's
|
|
43
|
-
* `Provider.streamSimple` returns an `AssistantMessageEventStream
|
|
44
|
-
*
|
|
44
|
+
* `Provider.streamSimple` returns an `AssistantMessageEventStream`. Observe
|
|
45
|
+
* content activity when iterable; result-only compatibility seams retain the
|
|
46
|
+
* overall deadline without inventing stream progress.
|
|
45
47
|
*/
|
|
46
48
|
export interface InProcessReviewerProvider {
|
|
47
|
-
streamSimple(model: Model<Api>, context: Context, options?: SimpleStreamOptions):
|
|
49
|
+
streamSimple(model: Model<Api>, context: Context, options?: SimpleStreamOptions): ReviewerStream;
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export interface InProcessReviewerRegistry {
|
|
@@ -70,6 +72,20 @@ export const INPROCESS_REVIEWER_FAILURE = {
|
|
|
70
72
|
} as const;
|
|
71
73
|
export type InProcessReviewerFailureCode = (typeof INPROCESS_REVIEWER_FAILURE)[keyof typeof INPROCESS_REVIEWER_FAILURE];
|
|
72
74
|
|
|
75
|
+
// gentle-ai#6095: an empty completion has more than one cause, and only the
|
|
76
|
+
// completion itself carries the facts that tell them apart. Attributing it
|
|
77
|
+
// generically ("reviewer produced no text") pushed the diagnosis onto whoever
|
|
78
|
+
// read the transcript next: the recorded model id, stop reason and usage split
|
|
79
|
+
// stayed uninterpreted, so six relay runs had to be correlated by hand before
|
|
80
|
+
// a single model's reasoning budget was visible as the cause. Each cause below
|
|
81
|
+
// names what actually went wrong and what can be done about it. Nothing here
|
|
82
|
+
// infers a candidate defect: a generation failure is not a review finding.
|
|
83
|
+
export const INPROCESS_REVIEWER_EMPTY_OUTPUT_CAUSE = {
|
|
84
|
+
REASONING_EXHAUSTED_OUTPUT_BUDGET: "reasoning-exhausted-output-budget",
|
|
85
|
+
EMPTY_COMPLETION: "empty-completion",
|
|
86
|
+
} as const;
|
|
87
|
+
export type InProcessReviewerEmptyOutputCause = (typeof INPROCESS_REVIEWER_EMPTY_OUTPUT_CAUSE)[keyof typeof INPROCESS_REVIEWER_EMPTY_OUTPUT_CAUSE];
|
|
88
|
+
|
|
73
89
|
export interface InProcessReviewerRequest {
|
|
74
90
|
/** "provider/id" from models.json routing; already validated by SAFE_MODEL_ID_PATTERN upstream, re-validated here. */
|
|
75
91
|
readonly selection: string;
|
|
@@ -81,6 +97,8 @@ export interface InProcessReviewerRequest {
|
|
|
81
97
|
/** Frozen Go-materialized prompt bytes, submitted verbatim as the one user message. */
|
|
82
98
|
readonly prompt: Buffer;
|
|
83
99
|
readonly timeoutMs: number;
|
|
100
|
+
readonly firstOutputTimeoutMs?: number;
|
|
101
|
+
readonly idleTimeoutMs?: number;
|
|
84
102
|
readonly signal?: AbortSignal;
|
|
85
103
|
/**
|
|
86
104
|
* The live pi session id, threaded from the extension context. Pi's main
|
|
@@ -105,6 +123,7 @@ export interface InProcessReviewerDeps {
|
|
|
105
123
|
readonly now?: () => number;
|
|
106
124
|
/** Host-only facts, including on thrown auth errors. Never awaited; observer failure is non-authoritative. */
|
|
107
125
|
readonly onEvidence?: (evidence: Record<string, unknown>) => void | Promise<void>;
|
|
126
|
+
readonly onProgress?: ReviewerProgressObserver;
|
|
108
127
|
}
|
|
109
128
|
|
|
110
129
|
// No existing bound covers the reviewer's completion text: the child this
|
|
@@ -159,6 +178,58 @@ function isTextContent(part: { type?: unknown }): part is TextContent {
|
|
|
159
178
|
return part.type === "text";
|
|
160
179
|
}
|
|
161
180
|
|
|
181
|
+
/** A counter the completion actually reported, or undefined; never a calculated one. */
|
|
182
|
+
function reportedCounter(value: unknown): number | undefined {
|
|
183
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Attribute an empty completion from the facts the completion itself reported.
|
|
188
|
+
* Two shapes are attributable today (gentle-ai#6095):
|
|
189
|
+
*
|
|
190
|
+
* - `stopReason: "length"` whose output budget was consumed by reasoning. This
|
|
191
|
+
* is deterministic for the routed model, not an incident: a lens routed to a
|
|
192
|
+
* model that spends the whole ceiling thinking cannot ever emit a verdict.
|
|
193
|
+
* - `stopReason: "stop"` that reported zero output tokens: the provider
|
|
194
|
+
* returned no completion at all.
|
|
195
|
+
*
|
|
196
|
+
* Every other empty shape stays unattributed — the host has no evidence to
|
|
197
|
+
* name a cause, and inventing one would be worse than the generic refusal.
|
|
198
|
+
* Exported so the vocabulary is asserted directly, not only through prose.
|
|
199
|
+
*/
|
|
200
|
+
export function classifyEmptyOutput(assistant: Pick<AssistantMessage, "stopReason" | "usage">): InProcessReviewerEmptyOutputCause | undefined {
|
|
201
|
+
const output = reportedCounter(assistant.usage?.output);
|
|
202
|
+
const reasoning = reportedCounter(assistant.usage?.reasoning);
|
|
203
|
+
if (assistant.stopReason === "length" && output !== undefined && output > 0 && reasoning !== undefined && reasoning > 0 && reasoning >= output) {
|
|
204
|
+
return INPROCESS_REVIEWER_EMPTY_OUTPUT_CAUSE.REASONING_EXHAUSTED_OUTPUT_BUDGET;
|
|
205
|
+
}
|
|
206
|
+
if (assistant.stopReason === "stop" && output === 0) {
|
|
207
|
+
return INPROCESS_REVIEWER_EMPTY_OUTPUT_CAUSE.EMPTY_COMPLETION;
|
|
208
|
+
}
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Names the attributed cause, the model or provider response responsible for
|
|
214
|
+
* it, the facts the completion reported, and the remedy that fits this cause.
|
|
215
|
+
* The closing sentence is deliberate: an empty generation is a transport
|
|
216
|
+
* outcome, never a candidate issue, and this message is what a blocked capture
|
|
217
|
+
* returns as its `reason`.
|
|
218
|
+
*/
|
|
219
|
+
function emptyOutputRefusalMessage(cause: InProcessReviewerEmptyOutputCause, routingKey: string, reviewerModel: string, assistant: AssistantMessage): string {
|
|
220
|
+
const output = reportedCounter(assistant.usage?.output);
|
|
221
|
+
const reasoning = reportedCounter(assistant.usage?.reasoning);
|
|
222
|
+
const facts = [
|
|
223
|
+
`stopReason: ${assistant.stopReason}`,
|
|
224
|
+
...(output === undefined ? [] : [`output: ${output}`]),
|
|
225
|
+
...(reasoning === undefined ? [] : [`reasoning: ${reasoning}`]),
|
|
226
|
+
].join("; ");
|
|
227
|
+
if (cause === INPROCESS_REVIEWER_EMPTY_OUTPUT_CAUSE.REASONING_EXHAUSTED_OUTPUT_BUDGET) {
|
|
228
|
+
return `Reviewer model ${reviewerModel} exhausted its ${output}-token output budget on reasoning before emitting a verdict for ${routingKey} (${facts}). Route this lens to a reviewer model with a sufficient output ceiling, raise the output budget, or reduce reasoning. No candidate issue is inferred from this generation failure.`;
|
|
229
|
+
}
|
|
230
|
+
return `The provider returned no completion for ${routingKey} from reviewer model ${reviewerModel} (${facts}). Retry the slot. No candidate issue is inferred from this generation failure.`;
|
|
231
|
+
}
|
|
232
|
+
|
|
162
233
|
/** Completion diagnostics are facts only; never copy provider text, errors, or payloads. */
|
|
163
234
|
function completionEvidence(model: Model<Api>, assistant: AssistantMessage): Record<string, unknown> {
|
|
164
235
|
const evidence: Record<string, unknown> = { reviewerModel: `${model.provider}/${model.id}`.slice(0, 512) };
|
|
@@ -166,7 +237,8 @@ function completionEvidence(model: Model<Api>, assistant: AssistantMessage): Rec
|
|
|
166
237
|
evidence.stopReason = assistant.stopReason;
|
|
167
238
|
}
|
|
168
239
|
const addCounter = (target: Record<string, number>, key: string, value: unknown) => {
|
|
169
|
-
|
|
240
|
+
const counter = reportedCounter(value);
|
|
241
|
+
if (counter !== undefined) target[key] = counter;
|
|
170
242
|
};
|
|
171
243
|
const usage: Record<string, number> = {};
|
|
172
244
|
for (const key of ["input", "output", "reasoning", "cacheRead", "cacheWrite", "totalTokens"] as const) {
|
|
@@ -252,6 +324,13 @@ function reviewerDeadline(request: InProcessReviewerRequest) {
|
|
|
252
324
|
return {
|
|
253
325
|
signal: controller.signal,
|
|
254
326
|
failure,
|
|
327
|
+
timeout(phase: "first-output" | "stream-idle", limitMs: number) {
|
|
328
|
+
if (failure() !== undefined) return;
|
|
329
|
+
refusal = refuse(INPROCESS_REVIEWER_FAILURE.TIMED_OUT,
|
|
330
|
+
`Reviewer ${request.routingKey} exceeded its ${limitMs}ms ${phase} bound; no result was admitted.`,
|
|
331
|
+
{ timeoutPhase: phase, streamTimeoutMs: limitMs });
|
|
332
|
+
controller.abort(new DOMException("Reviewer stream stalled", "TimeoutError"));
|
|
333
|
+
},
|
|
255
334
|
wait<T>(start: () => Promise<T>): Promise<T> {
|
|
256
335
|
return new Promise<T>((resolve, reject) => {
|
|
257
336
|
if (failure() !== undefined) { reject(interrupted); return; }
|
|
@@ -460,14 +539,16 @@ export async function runInProcessReviewer(request: InProcessReviewerRequest, de
|
|
|
460
539
|
: {}),
|
|
461
540
|
};
|
|
462
541
|
|
|
463
|
-
//
|
|
464
|
-
//
|
|
465
|
-
// exactly what pi-ai's own compat layer does with the same stream.
|
|
542
|
+
// Observe the composed SDK stream while retaining the original result.
|
|
543
|
+
// The promise-only compatibility seam has only the overall deadline.
|
|
466
544
|
let assistant: AssistantMessage;
|
|
467
545
|
try {
|
|
468
546
|
assistant = await deadline.wait(() => {
|
|
469
547
|
phase = "completion"; completionStarted = performance.now();
|
|
470
|
-
return provider === undefined ? deps.complete(requestModel, context, options) : provider.streamSimple(requestModel, context, options)
|
|
548
|
+
return provider === undefined ? deps.complete(requestModel, context, options) : readReviewerStream(provider.streamSimple(requestModel, context, options), {
|
|
549
|
+
routingKey: request.routingKey, firstOutputTimeoutMs: request.firstOutputTimeoutMs, idleTimeoutMs: request.idleTimeoutMs,
|
|
550
|
+
wait: deadline.wait, timeout: deadline.timeout, onProgress: deps.onProgress,
|
|
551
|
+
});
|
|
471
552
|
});
|
|
472
553
|
resolvedAssistant = assistant;
|
|
473
554
|
} catch (error) {
|
|
@@ -503,10 +584,13 @@ export async function runInProcessReviewer(request: InProcessReviewerRequest, de
|
|
|
503
584
|
const text = assistant.content.filter(isTextContent).map((part) => part.text).join("");
|
|
504
585
|
if (text.length === 0) {
|
|
505
586
|
const stopReason = ["pending", "stop", "length", "toolUse", "error", "aborted", "deferred"].includes(assistant.stopReason) ? assistant.stopReason : undefined;
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
587
|
+
const cause = classifyEmptyOutput(assistant);
|
|
588
|
+
// An attributed cause keeps the same failure code and the same evidence
|
|
589
|
+
// facts; it adds the interpretation (as `cause`) and replaces only the
|
|
590
|
+
// message, so no other empty shape changes its refusal.
|
|
591
|
+
return finish(cause === undefined
|
|
592
|
+
? refuse(INPROCESS_REVIEWER_FAILURE.EMPTY_OUTPUT, `Reviewer produced no text for ${request.routingKey} (stopReason: ${stopReason ?? "unknown"}).`)
|
|
593
|
+
: refuse(INPROCESS_REVIEWER_FAILURE.EMPTY_OUTPUT, emptyOutputRefusalMessage(cause, request.routingKey, `${model.provider}/${model.id}`, assistant), { cause }));
|
|
510
594
|
}
|
|
511
595
|
|
|
512
596
|
const textBytes = Buffer.byteLength(text, "utf8");
|
|
@@ -89,8 +89,15 @@ type UsageLike = {
|
|
|
89
89
|
* a reading with room releases it. A full window whose reset already passed
|
|
90
90
|
* is a stale reading and blocks nothing; a spent limit with no reset time at
|
|
91
91
|
* all waits the usual exhausted time. A model's own failures stay.
|
|
92
|
+
* NaN's reading is advisory: it reports legacy per-model token caps while
|
|
93
|
+
* billing from a shared credit pool, so it never cools anything down; NaN's
|
|
94
|
+
* real quota errors still do, through `mark`.
|
|
92
95
|
*/
|
|
93
96
|
export function syncUsageCooldown(usage: UsageLike, cooldown: ModelCooldown, now: number): void {
|
|
97
|
+
if (ADVISORY_USAGE_PROVIDERS.has(usage.provider)) {
|
|
98
|
+
cooldown.clearProvider(usage.provider);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
94
101
|
const spentUntil = (limit: UsageLike["limits"][number]): number | undefined => {
|
|
95
102
|
const full = limit.windows.filter((window) => limit.limitReached || window.usedPercent >= 100);
|
|
96
103
|
if (!limit.limitReached && full.length === 0) return undefined;
|
|
@@ -115,6 +122,8 @@ export function syncUsageCooldown(usage: UsageLike, cooldown: ModelCooldown, now
|
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
const SAFE_MODEL_NAME = /^[A-Za-z0-9._~:@+%-]+$/;
|
|
125
|
+
// Kept local so the agents runner never loads the shell's usage module.
|
|
126
|
+
const ADVISORY_USAGE_PROVIDERS: ReadonlySet<string> = new Set(["nan"]);
|
|
118
127
|
|
|
119
128
|
const SHARED = Symbol.for("gentle-pi.model-fallback.cooldown");
|
|
120
129
|
/** One registry per process: the orchestrator and the agents runner share what ran out. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { access, readFile } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
3
4
|
|
|
4
5
|
export const THINKING_LEVELS = [
|
|
5
6
|
"off",
|
|
@@ -107,6 +108,14 @@ function parseModelConfigFileValue(value: Record<string, unknown>): AgentModelCo
|
|
|
107
108
|
return config;
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
/** The two stores the saved global routing is read from: global first, then the legacy project file. */
|
|
112
|
+
export function modelConfigPaths(configHome: string, cwd: string): { global: string; project: string } {
|
|
113
|
+
return {
|
|
114
|
+
global: join(configHome, "models.json"),
|
|
115
|
+
project: join(cwd, ".pi", "gentle-ai", "models.json"),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
export function readModelConfigFile(path: string): ModelConfigFileResult {
|
|
111
120
|
if (!existsSync(path)) return { status: "missing" };
|
|
112
121
|
try {
|
package/lib/nan-provider.ts
CHANGED
|
@@ -13,38 +13,32 @@ export interface NanProviderOptions {
|
|
|
13
13
|
|
|
14
14
|
type NanChatModelConfig = Extract<ProviderModelConfig, { type?: "chat" }>;
|
|
15
15
|
|
|
16
|
-
// Pi requires numeric rates; NaN
|
|
16
|
+
// Pi requires numeric rates; NaN does not publish per-token prices. Zero is a placeholder, not a free-price claim.
|
|
17
17
|
const ZERO_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
18
18
|
|
|
19
19
|
// Maintained chat subset from https://nan.builders/docs/models.
|
|
20
|
-
// Decimal bounds conservatively interpret the documented 1M/262K/131K labels.
|
|
20
|
+
// Decimal bounds conservatively interpret the documented 1M/262K/131K/393K/64K labels.
|
|
21
21
|
// Pi models text/image inputs only; documented audio/video inputs are not advertised.
|
|
22
|
-
// Reasoning
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
// GLM 5.3 / GLM 5.3 Flash: low · medium · high · max, fully controllable and without an off.
|
|
22
|
+
// Reasoning and answer share the output budget. DeepSeek Flash uses its exact published
|
|
23
|
+
// 393,216 budget and GLM 5.3 Flash its exact published 131,072 (NaN lowers anything
|
|
24
|
+
// above); Qwen 3.8 Flash retains 131,000 and Gemma 4 and Qwen 3.6 retain 65,536. The
|
|
25
|
+
// November larger models now publish Max answer caps (Kimi K3.1 Pro 1M, Qwen 3.8 Max
|
|
26
|
+
// 131K, DeepSeek V4 Pro 393K, Hy4 64K); glm5.3 publishes no maximum and keeps 32,768.
|
|
27
|
+
// Pi requires explicit xhigh/max mappings to offer those levels; missing ordinary
|
|
28
|
+
// levels pass through. GLM always reasons, while none disables all other models.
|
|
30
29
|
const GLM_THINKING_LEVEL_MAP: NanChatModelConfig["thinkingLevelMap"] = {
|
|
31
|
-
off: null,
|
|
30
|
+
off: null, xhigh: "xhigh", max: "max",
|
|
32
31
|
};
|
|
33
|
-
// Qwen 3.6 and Gemma 4 honor none · minimal · low · medium · high · max as depth controls.
|
|
34
|
-
// DeepSeek V4 Flash, Qwen 3.8 Flash, and MiMo accept the same values while NaN manages their
|
|
35
|
-
// depth itself; none disables reasoning only where NaN honors it.
|
|
36
32
|
const EXTENDED_THINKING_LEVEL_MAP: NanChatModelConfig["thinkingLevelMap"] = {
|
|
37
|
-
off: "none", xhigh:
|
|
33
|
+
off: "none", xhigh: "xhigh", max: "max",
|
|
34
|
+
};
|
|
35
|
+
// MiMo accepts minimal and xhigh as aliases for low and max respectively.
|
|
36
|
+
const MIMO_THINKING_LEVEL_MAP: NanChatModelConfig["thinkingLevelMap"] = {
|
|
37
|
+
off: "none", minimal: "low", xhigh: "max", max: "max",
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
* level never changes it. Qwen 3.6 and Gemma 4 share the extended map yet honor the level as a
|
|
43
|
-
* reasoning budget, so the distinction lives here and the shell labels only these three automatic.
|
|
44
|
-
*/
|
|
45
|
-
export const NAN_ADAPTIVE_REASONING_MODEL_IDS: ReadonlySet<string> = new Set([
|
|
46
|
-
"deepseek-v4-flash", "qwen3.8-flash", "mimo-v2.6-flash",
|
|
47
|
-
]);
|
|
40
|
+
/** @deprecated The old automatic-depth classification is obsolete; efforts can affect depth. */
|
|
41
|
+
export const NAN_ADAPTIVE_REASONING_MODEL_IDS: ReadonlySet<string> = new Set();
|
|
48
42
|
|
|
49
43
|
export function isNanAdaptiveReasoningModel(model: { provider: string; id: string } | undefined): boolean {
|
|
50
44
|
return model !== undefined && model.provider === NAN_PROVIDER_ID && NAN_ADAPTIVE_REASONING_MODEL_IDS.has(model.id);
|
|
@@ -57,13 +51,13 @@ const CHAT_MODELS: NanChatModelConfig[] = ([
|
|
|
57
51
|
},
|
|
58
52
|
{
|
|
59
53
|
id: "deepseek-v4-flash", name: "DeepSeek V4 Flash", input: ["text", "image"], contextWindow: 1_000_000,
|
|
60
|
-
thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens:
|
|
61
|
-
// NaN
|
|
54
|
+
thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 393_216,
|
|
55
|
+
// Preserve the established field; NaN accepts both fields as a shared reasoning/answer budget.
|
|
62
56
|
compat: { maxTokensField: "max_tokens" },
|
|
63
57
|
},
|
|
64
58
|
{
|
|
65
59
|
id: "glm5.3-flash", name: "GLM 5.3 Flash", input: ["text", "image"], contextWindow: 1_000_000,
|
|
66
|
-
thinkingLevelMap: GLM_THINKING_LEVEL_MAP,
|
|
60
|
+
thinkingLevelMap: GLM_THINKING_LEVEL_MAP, maxTokens: 131_072,
|
|
67
61
|
},
|
|
68
62
|
{
|
|
69
63
|
id: "qwen3.8-flash", name: "Qwen 3.8 Flash", input: ["text", "image"], contextWindow: 1_048_576,
|
|
@@ -71,7 +65,7 @@ const CHAT_MODELS: NanChatModelConfig[] = ([
|
|
|
71
65
|
},
|
|
72
66
|
{
|
|
73
67
|
id: "mimo-v2.6-flash", name: "MiMo V2.6 Flash", input: ["text", "image"], contextWindow: 1_000_000,
|
|
74
|
-
thinkingLevelMap:
|
|
68
|
+
thinkingLevelMap: MIMO_THINKING_LEVEL_MAP,
|
|
75
69
|
},
|
|
76
70
|
{
|
|
77
71
|
id: "gemma4", name: "Gemma 4", input: ["text", "image"], contextWindow: 262_000,
|
|
@@ -81,6 +75,22 @@ const CHAT_MODELS: NanChatModelConfig[] = ([
|
|
|
81
75
|
id: "qwen3.6", name: "Qwen 3.6", input: ["text", "image"], contextWindow: 262_000,
|
|
82
76
|
thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 65_536,
|
|
83
77
|
},
|
|
78
|
+
{
|
|
79
|
+
id: "kimi-k3.1-pro", name: "Kimi K3.1 Pro", input: ["text", "image"], contextWindow: 1_000_000,
|
|
80
|
+
thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 1_000_000,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "qwen3.8-max", name: "Qwen 3.8 Max", input: ["text", "image"], contextWindow: 1_000_000,
|
|
84
|
+
thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 131_000,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "deepseek-v4-pro", name: "DeepSeek V4 Pro", input: ["text"], contextWindow: 1_000_000,
|
|
88
|
+
thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 393_000,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
id: "hy4", name: "Hy4", input: ["text", "image"], contextWindow: 1_000_000,
|
|
92
|
+
thinkingLevelMap: EXTENDED_THINKING_LEVEL_MAP, maxTokens: 64_000,
|
|
93
|
+
},
|
|
84
94
|
] satisfies Partial<NanChatModelConfig>[]).map((model) => ({
|
|
85
95
|
...model,
|
|
86
96
|
api: "openai-completions",
|
|
@@ -89,6 +99,9 @@ const CHAT_MODELS: NanChatModelConfig[] = ([
|
|
|
89
99
|
maxTokens: model.maxTokens ?? 32_768,
|
|
90
100
|
}));
|
|
91
101
|
|
|
102
|
+
/** The maintained chat catalog's ids; anything else NaN reports (a retired model) is not ours to show. */
|
|
103
|
+
export const NAN_CHAT_MODEL_IDS: ReadonlySet<string> = new Set(CHAT_MODELS.map((model) => model.id));
|
|
104
|
+
|
|
92
105
|
// The cold/offline baseline declares documented chat support, not key entitlement.
|
|
93
106
|
// A successful live catalog remains authoritative for the credential that fetched it.
|
|
94
107
|
const OFFLINE_MODELS = CHAT_MODELS;
|
|
@@ -98,7 +111,8 @@ function cloneModel(model: NanChatModelConfig): NanChatModelConfig {
|
|
|
98
111
|
...model,
|
|
99
112
|
input: [...model.input],
|
|
100
113
|
cost: { ...model.cost },
|
|
101
|
-
|
|
114
|
+
// structuredClone keeps the declared type: Pi 1.5 types the map `unknown` under strict: false, which a spread rejects.
|
|
115
|
+
thinkingLevelMap: model.thinkingLevelMap ? structuredClone(model.thinkingLevelMap) : undefined,
|
|
102
116
|
...(model.compat ? { compat: { ...model.compat } } : {}),
|
|
103
117
|
};
|
|
104
118
|
}
|
package/lib/native-review-cli.ts
CHANGED
|
@@ -492,6 +492,45 @@ const NATIVE_REVIEW_UNKNOWN_UNACHIEVABLE_VERB_REFUSAL = /unknown review command
|
|
|
492
492
|
// flags with this exact typed preflight cause, before reading the repository.
|
|
493
493
|
const NATIVE_REVIEW_UNKNOWN_LENS_FLAG_CAUSE = /^flag provided but not defined: -lenses(?:-reason)?$/;
|
|
494
494
|
|
|
495
|
+
// A provider older than gentle-ai#6088 refuses the STATUS opt-in with this
|
|
496
|
+
// exact typed preflight cause, before reading the repository.
|
|
497
|
+
const NATIVE_REVIEW_UNKNOWN_NON_BLOCKING_FLAG_CAUSE = /^flag provided but not defined: -non-blocking-findings$/;
|
|
498
|
+
|
|
499
|
+
/** Reports a not-started STATUS refusal caused only by an unknown --non-blocking-findings flag. */
|
|
500
|
+
function isNativeReviewNonBlockingFindingsUnsupported(error: unknown): boolean {
|
|
501
|
+
if (!(error instanceof NativeReviewIntegrationError)) return false;
|
|
502
|
+
const failure = error.failureEnvelope;
|
|
503
|
+
return failure.code === "invalid_request" && failure.mutationOutcome === "not_started" &&
|
|
504
|
+
typeof failure.cause === "string" && NATIVE_REVIEW_UNKNOWN_NON_BLOCKING_FLAG_CAUSE.test(failure.cause);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Provider binaries (executable path to its sha256) that refused
|
|
508
|
+
// --non-blocking-findings in this process. A replaced binary at the same path
|
|
509
|
+
// has another digest and is asked again. Never a capability claim.
|
|
510
|
+
const nonBlockingFindingsRefusals = new Map<string, string>();
|
|
511
|
+
|
|
512
|
+
function nonBlockingFindingsRefused(executable: string): boolean {
|
|
513
|
+
const digest = nonBlockingFindingsRefusals.get(executable);
|
|
514
|
+
if (digest === undefined) return false;
|
|
515
|
+
try {
|
|
516
|
+
return binaryDigest(executable) === digest;
|
|
517
|
+
} catch {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
function nonBlockingExecutableDigest(executable: string): string | undefined {
|
|
523
|
+
try { return binaryDigest(executable); } catch { return undefined; }
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function rememberNonBlockingFindingsRefusal(executable: string, digest: string | undefined): void {
|
|
527
|
+
// An old in-flight refusal must neither label a replacement unsupported
|
|
528
|
+
// nor erase a newer request's cache entry when identity cannot be read.
|
|
529
|
+
if (digest !== undefined && nonBlockingExecutableDigest(executable) === digest) {
|
|
530
|
+
nonBlockingFindingsRefusals.set(executable, digest);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
495
534
|
/** Reports a not-started STATUS refusal caused only by an unknown --lenses flag. */
|
|
496
535
|
export function isNativeReviewLensSelectionUnsupported(error: unknown): boolean {
|
|
497
536
|
if (!(error instanceof NativeReviewIntegrationError)) return false;
|
|
@@ -598,6 +637,14 @@ export interface NativeTargetStatusRequest extends NativeUntrackedSelectionReque
|
|
|
598
637
|
* back rather than version-sniff.
|
|
599
638
|
*/
|
|
600
639
|
agent?: "pi";
|
|
640
|
+
/**
|
|
641
|
+
* Ask the provider for the opt-in `non_blocking_findings` of a compact
|
|
642
|
+
* correction_required or escalated authority (`--non-blocking-findings`,
|
|
643
|
+
* gentle-ai#6088). Sent only on this client's own contracted STATUS. A
|
|
644
|
+
* provider that refuses the unknown flag is asked once more without it, and
|
|
645
|
+
* that binary is not sent the flag again in this process.
|
|
646
|
+
*/
|
|
647
|
+
nonBlockingFindings?: true;
|
|
601
648
|
signal?: AbortSignal;
|
|
602
649
|
}
|
|
603
650
|
export const NATIVE_REVIEW_AUTHORITY_STATUS = {
|
|
@@ -1122,6 +1169,16 @@ export const NATIVE_CLI_CONTRACTS = Object.freeze({
|
|
|
1122
1169
|
// 58450471280aeb357443d6a28c819132d8c8eb78dd25b12bac64296b2f8c27c2.
|
|
1123
1170
|
// No new negotiated capability identity is asserted.
|
|
1124
1171
|
"4.4.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
1172
|
+
// v4.5.0 repeats 4.4.0: the published binary still advertises
|
|
1173
|
+
// capabilities/v2.6 (protocol minor 6) under review-integration/v2, and the
|
|
1174
|
+
// provider contract moved from 1.4.0 to 1.5.0 additively (one stop reason,
|
|
1175
|
+
// no negotiated START/STATUS field), with published provider-contract tarball
|
|
1176
|
+
// SHA-256 08fdb65329b47a2cd2563edfa62b5781fd5ec7b0d1e8812e8e29a01a486da838.
|
|
1177
|
+
// Ground truth: `review capabilities --contract gentle-ai.review-integration/v2`
|
|
1178
|
+
// on the released darwin/arm64 v4.5.0 binary reports schema
|
|
1179
|
+
// gentle-ai.review-integration.capabilities/v2.6 with protocol minor 6.
|
|
1180
|
+
// No new negotiated capability identity is asserted.
|
|
1181
|
+
"4.5.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
1125
1182
|
});
|
|
1126
1183
|
|
|
1127
1184
|
export interface NativeReviewProcessDiagnostics {
|
|
@@ -2494,7 +2551,12 @@ export class NativeReviewCliV216 implements NativeReviewCli {
|
|
|
2494
2551
|
NATIVE_REQUEST_CONTEXT_UNSUPPORTED_MESSAGE, undefined, false);
|
|
2495
2552
|
}
|
|
2496
2553
|
}
|
|
2497
|
-
|
|
2554
|
+
// The opt-in rides only this client's own contracted STATUS, never a
|
|
2555
|
+
// provider-issued selection submission.
|
|
2556
|
+
const nonBlockingExecutable = request.nonBlockingFindings === true && submittedTokens === undefined
|
|
2557
|
+
? contextExecutable ?? measureStatusSync("resolution", () => this.executablePath(NATIVE_REVIEW_OPERATION.STATUS, false))
|
|
2558
|
+
: undefined;
|
|
2559
|
+
const statusArguments = (nonBlockingFindings: boolean) => submittedTokens === undefined ? [
|
|
2498
2560
|
"review", "status", "--contract", REVIEW_INTEGRATION_CONTRACT, "--cwd", request.cwd,
|
|
2499
2561
|
"--projection", request.projection ?? "workspace",
|
|
2500
2562
|
...nativeUntrackedSelectionArguments(selection),
|
|
@@ -2503,11 +2565,24 @@ export class NativeReviewCliV216 implements NativeReviewCli {
|
|
|
2503
2565
|
...(request.agent === undefined ? [] : ["--agent", request.agent]),
|
|
2504
2566
|
...nativeLensSelectionArguments(request),
|
|
2505
2567
|
...requestContextArguments,
|
|
2568
|
+
...(nonBlockingFindings ? ["--non-blocking-findings"] : []),
|
|
2506
2569
|
"--next-transition",
|
|
2507
2570
|
] : ["review", "status", "--cwd", request.cwd, ...submittedTokens, ...forwardedBaseRef, ...forwardedLineage, ...nativeLensSelectionArguments(request), ...requestContextArguments];
|
|
2508
|
-
const
|
|
2509
|
-
|
|
2510
|
-
|
|
2571
|
+
const executable = nonBlockingExecutable ?? contextExecutable;
|
|
2572
|
+
const run = (nonBlockingFindings: boolean) => executable === undefined
|
|
2573
|
+
? this.negotiated(NATIVE_REVIEW_OPERATION.STATUS, request.cwd, statusArguments(nonBlockingFindings), false, request.signal)
|
|
2574
|
+
: this.invoke(NATIVE_REVIEW_OPERATION.STATUS, request.cwd, statusArguments(nonBlockingFindings), false, request.signal, executable);
|
|
2575
|
+
const sendNonBlocking = nonBlockingExecutable !== undefined && !nonBlockingFindingsRefused(nonBlockingExecutable);
|
|
2576
|
+
const nonBlockingDigest = sendNonBlocking ? nonBlockingExecutableDigest(nonBlockingExecutable!) : undefined;
|
|
2577
|
+
let execution: NegotiatedExecution;
|
|
2578
|
+
try {
|
|
2579
|
+
execution = await run(sendNonBlocking);
|
|
2580
|
+
} catch (error) {
|
|
2581
|
+
// Only the unknown-flag refusal falls back, once; every other failure is the caller's.
|
|
2582
|
+
if (!sendNonBlocking || !isNativeReviewNonBlockingFindingsUnsupported(error)) throw error;
|
|
2583
|
+
rememberNonBlockingFindingsRefusal(nonBlockingExecutable!, nonBlockingDigest);
|
|
2584
|
+
execution = await run(false);
|
|
2585
|
+
}
|
|
2511
2586
|
measureStatusSync("decode", () => assertSupportedNextTransitionOperation(execution.body));
|
|
2512
2587
|
return decode(NATIVE_REVIEW_OPERATION.STATUS, false, () => decodeReviewStatusV3(execution.body));
|
|
2513
2588
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readCatalog, type CatalogPage } from "./orchestrator-catalog.ts";
|
|
2
2
|
import type { PublishedWork } from "./orchestrator-work.ts";
|
|
3
3
|
import type { PresenceRecord } from "./agents-session-transport.ts";
|
|
4
|
-
import { activationHash, discoveryAbsent,
|
|
4
|
+
import { activationHash, discoveryAbsent, PresenceCursor, readDiscovery, sessionHash, type DiscoveryMetadata, type PresencePage } from "./orchestrator-presence.ts";
|
|
5
5
|
|
|
6
6
|
export interface OrchestratorCandidate {
|
|
7
7
|
sessionId: string;
|
|
@@ -27,11 +27,48 @@ export interface OrchestratorCandidate {
|
|
|
27
27
|
publication?: { incarnation: string; activation: string; heartbeat: number };
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** Total directory-entry budget for one discovery scan. A directory this large
|
|
31
|
+
* is treated as flooded and fails closed; aligns with SWEEP_MAX_FILES in
|
|
32
|
+
* agents-session-transport.ts. */
|
|
33
|
+
const SCAN_MAX_ENTRIES = 4096;
|
|
34
|
+
|
|
35
|
+
/** Mirrors orchestrator-presence's reason() for the cursor constructor's throw,
|
|
36
|
+
* which next() would otherwise report as an unavailable page. */
|
|
37
|
+
function presenceUnavailable(error: unknown): string {
|
|
38
|
+
const code = (error as NodeJS.ErrnoException).code;
|
|
39
|
+
return code === "ENOENT" ? "missing" : code ? "io-error" : error instanceof SyntaxError ? "malformed" : (error as Error).message;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Full pagination over PresenceCursor instead of the first-page-only listPresence:
|
|
43
|
+
* legitimate busy directories (hundreds of header + activity + discovery sidecars)
|
|
44
|
+
* must not blind every peer behind the 128-entry first page (#3185). Overflow is
|
|
45
|
+
* reported only when the total directory-entry budget is exceeded; any per-page
|
|
46
|
+
* unavailable result still fails closed. */
|
|
47
|
+
function scanPresence(profile: string, now: number): PresencePage {
|
|
48
|
+
let cursor: PresenceCursor;
|
|
49
|
+
try { cursor = new PresenceCursor(profile); }
|
|
50
|
+
catch (error) { return { entries: [], scanned: 0, rejected: 0, overflow: false, unavailable: presenceUnavailable(error) }; }
|
|
51
|
+
const entries: PresencePage["entries"] = [];
|
|
52
|
+
let scanned = 0;
|
|
53
|
+
let rejected = 0;
|
|
54
|
+
try {
|
|
55
|
+
for (;;) {
|
|
56
|
+
const page = cursor.next(now);
|
|
57
|
+
entries.push(...page.entries);
|
|
58
|
+
scanned += page.scanned;
|
|
59
|
+
rejected += page.rejected;
|
|
60
|
+
if (page.unavailable) return { entries, scanned, rejected, overflow: false, unavailable: page.unavailable };
|
|
61
|
+
if (!page.overflow) return { entries, scanned, rejected, overflow: false };
|
|
62
|
+
if (scanned >= SCAN_MAX_ENTRIES) return { entries, scanned, rejected, overflow: true };
|
|
63
|
+
}
|
|
64
|
+
} finally { cursor.close(); }
|
|
65
|
+
}
|
|
66
|
+
|
|
30
67
|
/** One bounded metadata page, no thread reads or transport probes. The registry
|
|
31
68
|
* selects a canonical routing activation; metadata must bind to that exact one.
|
|
32
69
|
* Incomplete scans and duplicate presence headers fail closed. */
|
|
33
70
|
export function discoverOrchestrators(profile: string, peers: readonly PresenceRecord[], now = Date.now(), selection?: { recipientSessionId?: string; cursor?: string; consultation?: boolean; includeWork?: boolean; stateOnly?: boolean }): OrchestratorCandidate[] {
|
|
34
|
-
const page =
|
|
71
|
+
const page = scanPresence(profile, now);
|
|
35
72
|
const ids = [...new Set(peers.map(peer => peer.sessionId))];
|
|
36
73
|
return ids.filter(id => selection?.recipientSessionId === undefined || selection.recipientSessionId === id).map(sessionId => {
|
|
37
74
|
const unknown: OrchestratorCandidate = { sessionId, reachability: "unknown", freshness: "unknown" };
|
|
@@ -11,10 +11,17 @@
|
|
|
11
11
|
//
|
|
12
12
|
// The anchor is added only when the context's tail is automated, never mid tool
|
|
13
13
|
// loop, and only when no anchor already follows that tail. The caller persists it
|
|
14
|
-
// once,
|
|
15
|
-
//
|
|
14
|
+
// once (gentle-shell#1662, #2195), but Pi appends a message sent while streaming
|
|
15
|
+
// only once the turn ends, after the reply and its tool results, so the saved copy
|
|
16
|
+
// lands later than the request's trailing copy did. Each anchor therefore records
|
|
17
|
+
// the message it followed and its own timestamp, and `placePersistedReplyAnchors`
|
|
18
|
+
// moves every saved copy back to that spot: request k+1 then starts with exactly
|
|
19
|
+
// the messages of request k, and the provider's prompt cache keeps its prefix
|
|
20
|
+
// (pi-claude-bridge "Extensions that add a message to every request"). The
|
|
21
|
+
// placement lives in lib/request-context-placement.ts. Pure: no pi imports.
|
|
16
22
|
|
|
17
23
|
import type { ContextEvent } from "@earendil-works/pi-coding-agent";
|
|
24
|
+
import { placePersistedMessages, requestMessagePosition, type PersistedPlacement } from "./request-context-placement.ts";
|
|
18
25
|
|
|
19
26
|
type AgentMessage = ContextEvent["messages"][number];
|
|
20
27
|
|
|
@@ -62,6 +69,24 @@ function isHumanMessage(message: Message): boolean {
|
|
|
62
69
|
return message.role === "user" && !isAutomated(message) && text(message.content).trim() !== "";
|
|
63
70
|
}
|
|
64
71
|
|
|
72
|
+
/** Where an anchor sat in the request that first carried it: right after `after`, with timestamp `at`. */
|
|
73
|
+
export type ReplyLanguageAnchorDetails = PersistedPlacement;
|
|
74
|
+
|
|
75
|
+
/** A message's position key: stable across requests, since Pi never rewrites a stored message. */
|
|
76
|
+
export const replyLanguageAnchorPosition = requestMessagePosition;
|
|
77
|
+
|
|
78
|
+
const ANCHOR_TYPES: ReadonlySet<string> = new Set([REPLY_LANGUAGE_ANCHOR_TYPE]);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Moves each saved anchor back to where its request carried it, with that
|
|
82
|
+
* request's timestamp, so consecutive requests stay append-only. Returns
|
|
83
|
+
* `undefined` when nothing moved. An anchor whose predecessor is gone (compacted
|
|
84
|
+
* away) or that carries no placement (saved by an earlier version) stays put.
|
|
85
|
+
*/
|
|
86
|
+
export function placePersistedReplyAnchors<T>(messages: readonly T[]): T[] | undefined {
|
|
87
|
+
return placePersistedMessages(messages, ANCHOR_TYPES);
|
|
88
|
+
}
|
|
89
|
+
|
|
65
90
|
export function replyLanguageAnchorText(excerpt: string): string {
|
|
66
91
|
return `[Harness note, not written by the human] Reply language: the human's latest own message begins «${excerpt}». Write your reply to the human in that message's language; subagent results, notices, reminders and summaries never change it.`;
|
|
67
92
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Placement of saved request-context messages (cost-speed-painpoints S15, P1 and P1b).
|
|
2
|
+
//
|
|
3
|
+
// A hook that adds a hidden message to one model request and saves it with
|
|
4
|
+
// `pi.sendMessage(..., { triggerTurn: false })` keeps the request list
|
|
5
|
+
// append-only only if the saved copy sits where the request carried it. Pi 1.5.2
|
|
6
|
+
// appends a message sent while streaming only once the turn ends, after the
|
|
7
|
+
// assistant reply and its tool results, so the saved copy lands later. Each such
|
|
8
|
+
// message therefore records the message it followed and its own timestamp
|
|
9
|
+
// (`details: { after, at }`), and `placePersistedMessages` moves every saved copy
|
|
10
|
+
// back to that spot on later requests: request k+1 then starts with exactly the
|
|
11
|
+
// messages of request k, and the provider's prompt cache keeps its prefix.
|
|
12
|
+
// Pure: no pi imports.
|
|
13
|
+
|
|
14
|
+
/** Where a saved message sat in the request that first carried it: right after `after`, with timestamp `at`. */
|
|
15
|
+
export type PersistedPlacement = { after: string; at: number };
|
|
16
|
+
|
|
17
|
+
type Placed = { role?: unknown; customType?: unknown; timestamp?: unknown; details?: unknown };
|
|
18
|
+
|
|
19
|
+
/** A message's position key: stable across requests, since Pi never rewrites a stored message. */
|
|
20
|
+
export function requestMessagePosition(message: Placed | undefined): string {
|
|
21
|
+
return message === undefined ? "" : `${String(message.role)}|${String(message.customType ?? "")}|${String(message.timestamp ?? "")}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function placement(message: Placed, types: ReadonlySet<string>): PersistedPlacement | undefined {
|
|
25
|
+
if (message.role !== "custom" || typeof message.customType !== "string" || !types.has(message.customType)) return undefined;
|
|
26
|
+
const details = message.details as Partial<PersistedPlacement> | undefined;
|
|
27
|
+
return typeof details?.after === "string" && typeof details.at === "number" ? { after: details.after, at: details.at } : undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Moves each saved custom message of `types` back to where its request carried
|
|
32
|
+
* it, with that request's timestamp, so consecutive requests stay append-only.
|
|
33
|
+
* Returns `undefined` when nothing moved. A message whose predecessor is gone
|
|
34
|
+
* (compacted away) or that carries no placement (saved by an earlier version)
|
|
35
|
+
* stays put. A message is only ever placed right after an earlier one, so the
|
|
36
|
+
* leading message keeps its place.
|
|
37
|
+
*/
|
|
38
|
+
export function placePersistedMessages<T>(messages: readonly T[], types: ReadonlySet<string>): T[] | undefined {
|
|
39
|
+
let list: T[] | undefined;
|
|
40
|
+
const current = () => list ?? messages;
|
|
41
|
+
for (let index = 0; index < current().length; index++) {
|
|
42
|
+
const message = current()[index] as Placed;
|
|
43
|
+
const where = placement(message, types);
|
|
44
|
+
if (where === undefined) continue;
|
|
45
|
+
let target = index - 1;
|
|
46
|
+
while (target >= 0 && requestMessagePosition(current()[target] as Placed) !== where.after) target--;
|
|
47
|
+
if (target < 0 || (target === index - 1 && message.timestamp === where.at)) continue;
|
|
48
|
+
list ??= [...messages];
|
|
49
|
+
list.splice(index, 1);
|
|
50
|
+
list.splice(target + 1, 0, { ...message, timestamp: where.at } as T);
|
|
51
|
+
}
|
|
52
|
+
return list;
|
|
53
|
+
}
|