@tea-agent/loop-agent 0.39.0-next.3 → 0.39.0-next.30
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/AGENTS.md +4 -1
- package/CHANGELOG.md +267 -65
- package/README.md +11 -5
- package/bin/loop-agent.js +7 -3
- package/dist/application/dag/generate-task-dag.js +9 -0
- package/dist/application/task-lifecycle/advance.js +4 -0
- package/dist/build-stamp.json +3 -3
- package/dist/cli/command-definitions.js +16 -5
- package/dist/cli/program.js +16 -2
- package/dist/cli/update/notifier.js +2 -2
- package/dist/cli.js +2 -1
- package/dist/commands/dag-rerun.js +55 -1
- package/dist/commands/init-model-catalog.js +464 -0
- package/dist/commands/init-upgrade.js +265 -97
- package/dist/commands/init.js +428 -27
- package/dist/commands/inspect-next.js +8 -0
- package/dist/commands/task-advance.js +31 -0
- package/dist/executors/dag-pi-executor.js +118 -14
- package/dist/executors/pi-event-serializer.js +42 -1
- package/dist/executors/pi-executor.js +51 -0
- package/dist/executors/pi-extension-resolver.js +233 -0
- package/dist/executors/pi-playwright-cli-tool.js +8 -1
- package/dist/executors/pi-sdk-executor.js +187 -59
- package/dist/executors/shell-executor.js +533 -29
- package/dist/executors/shell-write-guard.js +7 -0
- package/dist/shared/dag-prompt-override.js +28 -0
- package/dist/shared/operator/capabilities.js +181 -27
- package/dist/shared/update/console-notifier.js +100 -0
- package/dist/{cli → shared}/update/npm-client.js +41 -8
- package/dist/{cli → shared}/update/state.js +41 -13
- package/dist/task/config-types.js +22 -0
- package/dist/task/contract/constants.js +1 -0
- package/dist/task/contract/diff.js +26 -0
- package/dist/task/contract/project.js +5 -0
- package/dist/task/contract/schema.js +6 -1
- package/dist/task/source-prepare/build-draft.js +15 -0
- package/dist/worker/cli.js +31 -1
- package/dist/worker/console/chat/deferred-turn.js +91 -0
- package/dist/worker/console/chat/mcp-inventory.js +221 -0
- package/dist/worker/console/chat/pi-runtime.js +165 -83
- package/dist/worker/console/chat/repo-walk.js +10 -1
- package/dist/worker/console/chat/routes.js +478 -55
- package/dist/worker/console/chat/semantic-activity.js +20 -8
- package/dist/worker/console/chat/session-store.js +146 -2
- package/dist/worker/console/chat/turn-process.js +17 -30
- package/dist/worker/console/harness-pi-model-matrix.js +137 -0
- package/dist/worker/console/operator-actions.js +244 -4
- package/dist/worker/console/operator-user-error.js +19 -0
- package/dist/worker/console/pi-readiness.js +12 -5
- package/dist/worker/console/recovery-cta.js +4 -4
- package/dist/worker/console/recovery-error-copy.js +4 -4
- package/dist/worker/console/routes.js +43 -2
- package/dist/worker/console/security.js +83 -10
- package/dist/worker/console/server.js +42 -6
- package/dist/worker/console/static/assets/{abnfDiagram-N423BO3Z-DSvF6RXQ.js → abnfDiagram-N423BO3Z-CiGOV5eG.js} +1 -1
- package/dist/worker/console/static/assets/{arc-DuI4ogtJ.js → arc-Ds9Gyfd8.js} +1 -1
- package/dist/worker/console/static/assets/{architectureDiagram-T3A2C74G-DdBbgD4y.js → architectureDiagram-T3A2C74G-C6V6uC98.js} +1 -1
- package/dist/worker/console/static/assets/{blockDiagram-VBNYF7ZC-xQC2HELm.js → blockDiagram-VBNYF7ZC-DezF7Ol9.js} +1 -1
- package/dist/worker/console/static/assets/{c4Diagram-5PPSVZJV-DPMSgwIZ.js → c4Diagram-5PPSVZJV-BCWk3gCT.js} +1 -1
- package/dist/worker/console/static/assets/channel-DMvu1nmi.js +1 -0
- package/dist/worker/console/static/assets/{chunk-2GRJ4B5K-WTEKTxin.js → chunk-2GRJ4B5K-DbYr-Cxy.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-2Q5K7J3B-B6vZ0Pv_.js → chunk-2Q5K7J3B-XSlusW4G.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5RXB4S5H-BrerNAix.js → chunk-5RXB4S5H-BtcKAj9i.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-5VM5RSS4-D_ch2aaI.js → chunk-5VM5RSS4-BF57lhXj.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-6Q2QTUOP-VvfacNrq.js → chunk-6Q2QTUOP-DJIlR25o.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-GF5L2VYU-B-uGFIg2.js → chunk-GF5L2VYU-DklNc7dm.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-JWPE2WC7-BlysCtod.js → chunk-JWPE2WC7-fZNtEdQZ.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-KBJHAD2P-BjAUAfcT.js → chunk-KBJHAD2P-BBgLqV4h.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-RYQCIY6F-BeZnBmb-.js → chunk-RYQCIY6F-Dl9e5n_J.js} +1 -1
- package/dist/worker/console/static/assets/{chunk-XXDRQBXY-Bbfe3UJG.js → chunk-XXDRQBXY-B0JK51NT.js} +1 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-DVzM-02m.js +1 -0
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-DVzM-02m.js +1 -0
- package/dist/worker/console/static/assets/{cose-bilkent-JH36ORCC-BKJQnYVM.js → cose-bilkent-JH36ORCC-Ch-ajv4O.js} +1 -1
- package/dist/worker/console/static/assets/{cynefin-VYW2F7L2-B1wtI3hU.js → cynefin-VYW2F7L2-xn_NxcfB.js} +1 -1
- package/dist/worker/console/static/assets/{cynefinDiagram-MW4NZA55-DCF6DBSu.js → cynefinDiagram-MW4NZA55-DRD0fyga.js} +1 -1
- package/dist/worker/console/static/assets/{dagre-VZM6K2ZE-BJyNGRlP.js → dagre-VZM6K2ZE-COtnKp4B.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-7IWD3JNH-B7j1-VsZ.js → diagram-7IWD3JNH-BQp_CAqG.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-B4RE2ZJO-BREJ140a.js → diagram-B4RE2ZJO-x0y-vNgq.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-LBJQPF4R-CDPHmHGH.js → diagram-LBJQPF4R-N2ezwL31.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-Q27KOJAE-BtZLrez1.js → diagram-Q27KOJAE-CSaxRH6Q.js} +1 -1
- package/dist/worker/console/static/assets/{diagram-UB23O5K3-mzybu8oU.js → diagram-UB23O5K3-6Ro7Kpbd.js} +1 -1
- package/dist/worker/console/static/assets/{ebnfDiagram-BXEA7PRR-Dk3I2uO6.js → ebnfDiagram-BXEA7PRR-CrIIQEAI.js} +1 -1
- package/dist/worker/console/static/assets/{erDiagram-JOGREHBK-BT97u_tQ.js → erDiagram-JOGREHBK-DivKcq8g.js} +1 -1
- package/dist/worker/console/static/assets/{flowDiagram-UKHOOZJN-CMOtYzui.js → flowDiagram-UKHOOZJN-BXrfDo8y.js} +1 -1
- package/dist/worker/console/static/assets/{ganttDiagram-PKOTCBZU-DiNydkuY.js → ganttDiagram-PKOTCBZU-LTTQmMRJ.js} +1 -1
- package/dist/worker/console/static/assets/{gitGraphDiagram-DS77QQ5N-Cwt6fLkl.js → gitGraphDiagram-DS77QQ5N-DP3o_5qd.js} +1 -1
- package/dist/worker/console/static/assets/index-C2jmYBfu.js +404 -0
- package/dist/worker/console/static/assets/index-C8rOIAJr.css +1 -0
- package/dist/worker/console/static/assets/{infoDiagram-6WML65LV-AsGIGKKB.js → infoDiagram-6WML65LV-wVfSY1WH.js} +1 -1
- package/dist/worker/console/static/assets/{ishikawaDiagram-WSZJBQD7-BL8ITZh3.js → ishikawaDiagram-WSZJBQD7-BRKfFL0I.js} +1 -1
- package/dist/worker/console/static/assets/{journeyDiagram-NVQOT4AX-VPKAUX8M.js → journeyDiagram-NVQOT4AX-DEml3jLb.js} +1 -1
- package/dist/worker/console/static/assets/{kanban-definition-27J2QSJJ-BL56hfGp.js → kanban-definition-27J2QSJJ-DTzBmOqN.js} +1 -1
- package/dist/worker/console/static/assets/{linear-BmSG3nIZ.js → linear-Cpy1d873.js} +1 -1
- package/dist/worker/console/static/assets/{mermaid.core-DWGK9kwP.js → mermaid.core-C1cSavOy.js} +5 -5
- package/dist/worker/console/static/assets/{mindmap-definition-FAOFIHXS--vvKLjo0.js → mindmap-definition-FAOFIHXS-BEBSKvYM.js} +1 -1
- package/dist/worker/console/static/assets/{pegDiagram-VL7TDLO6-B41mxb2-.js → pegDiagram-VL7TDLO6-BrLs4Oac.js} +1 -1
- package/dist/worker/console/static/assets/{pieDiagram-7S7Q4E2Y-DTlu77sw.js → pieDiagram-7S7Q4E2Y-B47AZcLa.js} +1 -1
- package/dist/worker/console/static/assets/{quadrantDiagram-CIZ2JOQS-Bk5A7alv.js → quadrantDiagram-CIZ2JOQS-s0dVeYR2.js} +1 -1
- package/dist/worker/console/static/assets/{railroadDiagram-AXF67PYL-Csf9jzQy.js → railroadDiagram-AXF67PYL-lW8aJ7Q6.js} +1 -1
- package/dist/worker/console/static/assets/{requirementDiagram-LRYGKXZP-CeptoSNx.js → requirementDiagram-LRYGKXZP-BcHJPf6Q.js} +1 -1
- package/dist/worker/console/static/assets/{sankeyDiagram-W5VNT64P-A-DLCLer.js → sankeyDiagram-W5VNT64P-DdegpUUf.js} +1 -1
- package/dist/worker/console/static/assets/{sequenceDiagram-SI44F4Z6-22VbPdOI.js → sequenceDiagram-SI44F4Z6-BxFWqNv8.js} +1 -1
- package/dist/worker/console/static/assets/{sizeCapture-X5ZJPWSS-DWvAyBC9.js → sizeCapture-X5ZJPWSS-cOdUDPbR.js} +1 -1
- package/dist/worker/console/static/assets/{stateDiagram-OKZ733FA-qICZ75yT.js → stateDiagram-OKZ733FA-DpxlYl8P.js} +1 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-BwecGAkM.js +1 -0
- package/dist/worker/console/static/assets/{swimlanes-SLNWSIFB-xi7lcMyp.js → swimlanes-SLNWSIFB-DQOfurE0.js} +2 -2
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-D5WW_LbN.js +8 -0
- package/dist/worker/console/static/assets/{timeline-definition-Z64GVDOM-Bu6Nl6O2.js → timeline-definition-Z64GVDOM-CIp3tC6V.js} +1 -1
- package/dist/worker/console/static/assets/{vennDiagram-T6HMQDX7-BzMz4Bn9.js → vennDiagram-T6HMQDX7-C-adIPKn.js} +1 -1
- package/dist/worker/console/static/assets/{wardleyDiagram-T6FBY63Y-CxaJnzc5.js → wardleyDiagram-T6FBY63Y-CiYrar9M.js} +1 -1
- package/dist/worker/console/static/assets/{xychartDiagram-ELKLHX3M-5JK-omQK.js → xychartDiagram-ELKLHX3M-WHrdTV0-.js} +1 -1
- package/dist/worker/console/static/index.html +2 -2
- package/dist/worker/console/static-src/app/console-types.js +39 -0
- package/dist/worker/console/static-src/app/useOperatorActions.js +1 -1
- package/dist/worker/console/static-src/app/useRecoveryActions.js +2 -2
- package/dist/worker/console/static-src/operator-chat/chat-sse-events.js +82 -22
- package/dist/worker/console/static-src/operator-chat/mutation-gate.js +45 -0
- package/dist/worker/console/static-src/operator-chat/open-preview-in-browser.js +328 -0
- package/dist/worker/console/static-src/operator-chat/resource-diagnostics.js +204 -0
- package/dist/worker/console/static-src/operator-chat/turn-stream-controller.js +8 -1
- package/dist/worker/console/static-src/operator-chat/turn-submission.js +42 -0
- package/dist/worker/console/static-src/operator-chat/useChatSessions.js +18 -0
- package/dist/worker/console/static-src/operator-chat/useChatStream.js +216 -10
- package/dist/worker/console/static-src/operator-chat/useChatThread.js +50 -22
- package/dist/worker/console/static-src/operator-chat/useRepoBrowser.js +26 -1
- package/dist/worker/observe/node-input.js +74 -3
- package/dist/worker/observe/node-process.js +377 -0
- package/dist/worker/observe/routes.js +36 -3
- package/dist/worker/observe/shell-handler-keys.js +34 -0
- package/dist/worker/observe/static/api.js +66 -0
- package/dist/worker/observe/static/constants.js +8 -1
- package/dist/worker/observe/static/dag-history-labels.js +4 -0
- package/dist/worker/observe/static/format.js +23 -0
- package/dist/worker/observe/static/markdown-render.js +20 -1
- package/dist/worker/observe/static/operator-chrome.js +4 -0
- package/dist/worker/observe/static/state.js +13 -2
- package/dist/worker/observe/static/styles.css +73 -0
- package/dist/worker/observe/static/views/dag-inspector.js +612 -8
- package/dist/worker/observe/static/views/dag.js +8 -1
- package/dist/worker/observe/static/views/session-timeline.js +78 -9
- package/dist/workflows/dag/backend-test-case-coverage-analysis.js +827 -53
- package/dist/workflows/dag/backend-test-case-manifest.js +4 -0
- package/dist/workflows/dag/backend-test-execution-contract.js +18 -9
- package/dist/workflows/dag/backend-test-gap-fill.js +205 -0
- package/dist/workflows/dag/backend-test-intake-context.js +32 -0
- package/dist/workflows/dag/backend-test-layout.js +133 -0
- package/dist/workflows/dag/backend-test-markdown-workflow.js +167 -32
- package/dist/workflows/dag/backend-test-module-stem.js +5 -0
- package/dist/workflows/dag/backend-test-pytest-collection.js +368 -33
- package/dist/workflows/dag/backend-test-result-contract.js +1 -1
- package/dist/workflows/dag/backend-test-scenario-param.js +884 -140
- package/dist/workflows/dag/backend-test-scenario-partitions.js +321 -0
- package/dist/workflows/dag/backend-test-writer-completeness.js +100 -56
- package/dist/workflows/dag/contract-output-registry.js +15 -0
- package/dist/workflows/dag/contract-validator-registrations.js +3 -1
- package/dist/workflows/dag/convergence/controller.js +141 -0
- package/dist/workflows/dag/dynamic-runtime/map.js +24 -8
- package/dist/workflows/dag/dynamic-runtime/shared.js +1 -1
- package/dist/workflows/dag/failure-category.js +12 -0
- package/dist/workflows/dag/frontend-implementation-contract.js +493 -2
- package/dist/workflows/dag/frontend-plan-render.js +90 -0
- package/dist/workflows/dag/frontend-prewrite-gate.js +221 -31
- package/dist/workflows/dag/frontend-test-case-quality.js +5 -13
- package/dist/workflows/dag/frontend-test-environment-probe.js +227 -0
- package/dist/workflows/dag/frontend-test-markdown.js +61 -0
- package/dist/workflows/dag/frontend-test-result-contract.js +10 -18
- package/dist/workflows/dag/frontend-test-standard-scenarios.js +68 -0
- package/dist/workflows/dag/init-hybrid.js +805 -113
- package/dist/workflows/dag/node-execution.js +194 -6
- package/dist/workflows/dag/prompt.js +60 -1
- package/dist/workflows/dag/rerun-feedback.js +212 -0
- package/dist/workflows/dag/rerun-plan.js +224 -27
- package/dist/workflows/dag/rerun-run.js +61 -6
- package/dist/workflows/dag/rerun-task.js +61 -2
- package/dist/workflows/dag/retry-policy.js +113 -0
- package/dist/workflows/dag/structured-output-repair.js +712 -0
- package/dist/workflows/dag/types.js +157 -1
- package/dist/workflows/dag/validate.js +41 -1
- package/docs/init-surface.manifest.json +5 -0
- package/docs/operations/README.md +1 -1
- package/docs/operations/local-development-environment.md +1 -5
- package/docs/skills/vetted-skill-registry.md +14 -0
- package/docs/templates/README.md +1 -1
- package/docs/templates/agent-dag.schema.json +44 -0
- package/docs/templates/backend-test-dag.json +60 -35
- package/docs/templates/frontend-implementation-contract.schema.json +9 -2
- package/docs/templates/frontend-test-dag.json +8 -10
- package/docs/templates/frontend-test-dag.retrieve-context.prompt.md +1 -1
- package/docs/templates/init-managed-agents.md +13 -3
- package/harness.json +3 -1
- package/package.json +12 -4
- package/scripts/next-info.mjs +356 -0
- package/scripts/next-publish-gate.mjs +238 -0
- package/scripts/release-source-binding.mjs +251 -0
- package/skills/analyze-product-requirements/SKILL.md +8 -5
- package/skills/analyze-product-requirements/references/acceptance-criteria.md +1 -1
- package/skills/analyze-product-requirements/references/clarification-and-knowledge.md +10 -6
- package/skills/analyze-product-requirements/references/example.md +50 -0
- package/skills/analyze-product-requirements/references/forward-test-cases.md +11 -7
- package/skills/analyze-product-requirements/references/kb-integration.md +5 -5
- package/skills/analyze-product-requirements/references/product-analysis-schema.md +8 -4
- package/skills/analyze-product-requirements/references/product-requirement-schema.md +2 -2
- package/skills/analyze-product-requirements/references/requirement-clarification-schema.md +1 -1
- package/skills/analyze-product-requirements/scripts/test-validators.mjs +11 -1
- package/skills/analyze-product-requirements/scripts/validate-product-analysis.mjs +20 -1
- package/skills/analyze-product-requirements/scripts/validate-requirement-clarification.mjs +9 -0
- package/skills/codebase-scout/SKILL.md +1 -1
- package/skills/frontend-design-review/references/review-checklist.md +2 -0
- package/skills/frontend-implementation/references/design-spec.md +16 -19
- package/skills/frontend-implementation/references/node-contracts.md +9 -6
- package/skills/improve-codebase-architecture/SKILL.md +81 -0
- package/skills/improve-codebase-architecture/deepening.md +37 -0
- package/skills/improve-codebase-architecture/html-report.md +123 -0
- package/skills/improve-codebase-architecture/interface-design.md +44 -0
- package/skills/improve-codebase-architecture/language.md +53 -0
- package/skills/loop-agent/references/command-reference.md +11 -4
- package/dist/worker/console/static/assets/channel-DLVz9TYW.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-JCYQIIEL-BeAuGcO9.js +0 -1
- package/dist/worker/console/static/assets/classDiagram-v2-OCEON4UE-BeAuGcO9.js +0 -1
- package/dist/worker/console/static/assets/index-DQxiso1w.js +0 -325
- package/dist/worker/console/static/assets/index-_j0Hzo69.css +0 -1
- package/dist/worker/console/static/assets/stateDiagram-v2-UEYNNEHI-DzKvfHTX.js +0 -1
- package/dist/worker/console/static/assets/swimlanesDiagram-ULZ7WXOC-Cxqr_qM1.js +0 -8
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { computeExtensionToolAllowlistExtras } from "./pi-extension-resolver.js";
|
|
4
|
+
import { BoundedTextPreview, classifyPiFailure, createPiJsonlStreamCollector, DEFAULT_ABORT_GRACE_MS, DEFAULT_STALL_TIMEOUT_MS, DEFAULT_TIMEOUT_MS, extractPiEventStopReason, extractAssistantTextFromPiJson, } from "./pi-executor.js";
|
|
4
5
|
import { serializeSessionEvent } from "./pi-event-serializer.js";
|
|
5
6
|
import { PI_RECOMMENDED_COMPACTION, PI_RECOMMENDED_RETRY, } from "../shared/pi-retry-settings.js";
|
|
7
|
+
/** Same-session recovery after a transport stall. Exactly one continue per SDK attempt. */
|
|
8
|
+
export const PI_SDK_STALL_CONTINUE_MAX = 1;
|
|
9
|
+
/**
|
|
10
|
+
* Fixed follow-up sent after aborting a stalled prompt.
|
|
11
|
+
* Kept short so the model can resume without repeating the original task payload.
|
|
12
|
+
*/
|
|
13
|
+
export const PI_SDK_STALL_CONTINUE_PROMPT = "继续。上一轮因长时间无 provider 活动已被中止;请从中断处接着完成,不要重复已完成的步骤。若此前没有有效输出,请重新执行原任务。";
|
|
6
14
|
let sdkSessionFactoryOverride;
|
|
7
15
|
let sdkImportOverrideForTests;
|
|
8
16
|
let sdkModuleOverrideForTests;
|
|
@@ -44,15 +52,15 @@ export async function resetPiSdkReuseScopeForTests() {
|
|
|
44
52
|
export function setPiSdkSessionFactoryForTests(factory) {
|
|
45
53
|
sdkSessionFactoryOverride = factory;
|
|
46
54
|
}
|
|
47
|
-
/** Test hook: simulate SDK import success/failure without relying on
|
|
55
|
+
/** Test hook: simulate SDK import success/failure without relying on installed SDK state. */
|
|
48
56
|
export function setPiSdkImportOverrideForTests(fn) {
|
|
49
57
|
sdkImportOverrideForTests = fn;
|
|
50
58
|
}
|
|
51
|
-
/** Test hook: inject a mock Pi SDK module to exercise resolveSdkSessionFactory without
|
|
59
|
+
/** Test hook: inject a mock Pi SDK module to exercise resolveSdkSessionFactory without loading the real SDK. */
|
|
52
60
|
export function setPiSdkModuleOverrideForTests(fn) {
|
|
53
61
|
sdkModuleOverrideForTests = fn;
|
|
54
62
|
}
|
|
55
|
-
/** Check whether the Pi SDK
|
|
63
|
+
/** Check whether the Pi SDK runtime dependency satisfies the 0.83.0 runtime contract. */
|
|
56
64
|
export async function checkPiSdkAvailability(_repoRoot) {
|
|
57
65
|
if (sdkSessionFactoryOverride) {
|
|
58
66
|
return { ok: true, detail: "pi SDK session factory override active" };
|
|
@@ -68,10 +76,10 @@ export async function checkPiSdkAvailability(_repoRoot) {
|
|
|
68
76
|
typeof ModelRuntime?.create !== "function") {
|
|
69
77
|
return {
|
|
70
78
|
ok: false,
|
|
71
|
-
detail: "pi SDK incompatible: requires createAgentSession, getAgentDir, and ModelRuntime.create (0.
|
|
79
|
+
detail: "pi SDK incompatible: requires createAgentSession, getAgentDir, and ModelRuntime.create (0.83.0 contract)",
|
|
72
80
|
};
|
|
73
81
|
}
|
|
74
|
-
return { ok: true, detail: "pi SDK 0.
|
|
82
|
+
return { ok: true, detail: "pi SDK 0.83.0 contract available" };
|
|
75
83
|
}
|
|
76
84
|
catch (error) {
|
|
77
85
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -222,6 +230,9 @@ async function createSdkSession(sdk, input, shared) {
|
|
|
222
230
|
noContextFiles: true,
|
|
223
231
|
noSkills: true,
|
|
224
232
|
noExtensions: true,
|
|
233
|
+
...(input.additionalExtensionPaths && input.additionalExtensionPaths.length > 0
|
|
234
|
+
? { additionalExtensionPaths: input.additionalExtensionPaths }
|
|
235
|
+
: {}),
|
|
225
236
|
...(settingsManager ? { settingsManager } : {}),
|
|
226
237
|
appendSystemPromptOverride: (base) => [
|
|
227
238
|
...base,
|
|
@@ -229,6 +240,19 @@ async function createSdkSession(sdk, input, shared) {
|
|
|
229
240
|
],
|
|
230
241
|
});
|
|
231
242
|
await loader.reload();
|
|
243
|
+
// Discover extension-registered tool names BEFORE session creation (plan
|
|
244
|
+
// 2026-08-21 D5): verified against the real SDK — passing extension tool
|
|
245
|
+
// names in createAgentSession `tools` activates them, while a post-create
|
|
246
|
+
// setActiveToolsByName pin leaves the active set unchanged. Merge filtered
|
|
247
|
+
// extras into the create-time allowlist; protected builtins, the deny
|
|
248
|
+
// surface, and write-capable extension tools never join.
|
|
249
|
+
const extensionToolExtras = [];
|
|
250
|
+
if (input.additionalExtensionPaths &&
|
|
251
|
+
input.additionalExtensionPaths.length > 0) {
|
|
252
|
+
const registered = collectLoaderExtensionToolNames(loader);
|
|
253
|
+
extensionToolExtras.push(...computeExtensionToolAllowlistExtras(registered.map((name) => ({ name })), input.toolNames));
|
|
254
|
+
}
|
|
255
|
+
const sessionToolNames = [...input.toolNames, ...extensionToolExtras];
|
|
232
256
|
if (input.requireWriterCustomTools) {
|
|
233
257
|
if (!Array.isArray(input.customTools) || input.customTools.length === 0) {
|
|
234
258
|
throw new Error("pi writer tool policy missing customTools; refusing to create uncontrolled writer session");
|
|
@@ -238,7 +262,7 @@ async function createSdkSession(sdk, input, shared) {
|
|
|
238
262
|
cwd: input.cwd,
|
|
239
263
|
sessionManager: SessionManager.inMemory(input.cwd),
|
|
240
264
|
resourceLoader: loader,
|
|
241
|
-
tools:
|
|
265
|
+
tools: sessionToolNames,
|
|
242
266
|
modelRuntime,
|
|
243
267
|
...(settingsManager ? { settingsManager } : {}),
|
|
244
268
|
...(model ? { model } : {}),
|
|
@@ -247,6 +271,22 @@ async function createSdkSession(sdk, input, shared) {
|
|
|
247
271
|
? { customTools: input.customTools }
|
|
248
272
|
: {}),
|
|
249
273
|
});
|
|
274
|
+
if (extensionToolExtras.length > 0) {
|
|
275
|
+
// Fail closed when merged extension tools did not activate: a silent
|
|
276
|
+
// pin failure must never let the node run without its declared tools.
|
|
277
|
+
const activeTools = created.session.agent?.state?.tools;
|
|
278
|
+
if (!Array.isArray(activeTools)) {
|
|
279
|
+
throw new Error("pi SDK session does not expose agent.state.tools; refusing unverifiable extension-tool activation");
|
|
280
|
+
}
|
|
281
|
+
const activeNames = new Set(activeTools
|
|
282
|
+
.map((tool) => typeof tool?.name === "string" ? tool.name : undefined)
|
|
283
|
+
.filter((name) => Boolean(name)));
|
|
284
|
+
for (const extensionToolName of extensionToolExtras) {
|
|
285
|
+
if (!activeNames.has(extensionToolName)) {
|
|
286
|
+
throw new Error(`pi SDK extension-tool activation mismatch for ${extensionToolName}: tool did not activate at session creation`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
250
290
|
const customToolNames = (input.customTools ?? [])
|
|
251
291
|
.map((tool) => isRecord(tool) && typeof tool.name === "string" ? tool.name : undefined)
|
|
252
292
|
.filter((name) => Boolean(name));
|
|
@@ -259,7 +299,7 @@ async function createSdkSession(sdk, input, shared) {
|
|
|
259
299
|
.map((tool) => typeof tool?.name === "string" ? tool.name : undefined)
|
|
260
300
|
.filter((name) => Boolean(name)));
|
|
261
301
|
for (const customToolName of customToolNames) {
|
|
262
|
-
const expectedActive =
|
|
302
|
+
const expectedActive = sessionToolNames.includes(customToolName);
|
|
263
303
|
if (activeNames.has(customToolName) !== expectedActive) {
|
|
264
304
|
throw new Error(`pi SDK custom-tool activation mismatch for ${customToolName}: expectedActive=${expectedActive}`);
|
|
265
305
|
}
|
|
@@ -267,6 +307,47 @@ async function createSdkSession(sdk, input, shared) {
|
|
|
267
307
|
}
|
|
268
308
|
return created.session;
|
|
269
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Collect tool names registered by loader-resolved extensions. The SDK exposes
|
|
312
|
+
* each extension's `tools` as a Record (name → definition) or Map; both shapes
|
|
313
|
+
* are handled. Missing getExtensions (older SDK) yields no extras — the node
|
|
314
|
+
* then runs with the baseline allowlist only.
|
|
315
|
+
*/
|
|
316
|
+
function collectLoaderExtensionToolNames(loader) {
|
|
317
|
+
const getExtensions = loader?.getExtensions;
|
|
318
|
+
if (typeof getExtensions !== "function")
|
|
319
|
+
return [];
|
|
320
|
+
let parsed;
|
|
321
|
+
try {
|
|
322
|
+
parsed = getExtensions.call(loader);
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
return [];
|
|
326
|
+
}
|
|
327
|
+
if (!parsed || typeof parsed !== "object")
|
|
328
|
+
return [];
|
|
329
|
+
const extensions = parsed.extensions;
|
|
330
|
+
if (!Array.isArray(extensions))
|
|
331
|
+
return [];
|
|
332
|
+
const names = [];
|
|
333
|
+
for (const extension of extensions) {
|
|
334
|
+
if (!extension || typeof extension !== "object")
|
|
335
|
+
continue;
|
|
336
|
+
const tools = extension.tools;
|
|
337
|
+
if (tools instanceof Map) {
|
|
338
|
+
for (const key of tools.keys()) {
|
|
339
|
+
if (typeof key === "string")
|
|
340
|
+
names.push(key);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else if (tools && typeof tools === "object") {
|
|
344
|
+
for (const key of Object.keys(tools)) {
|
|
345
|
+
names.push(key);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return names;
|
|
350
|
+
}
|
|
270
351
|
/**
|
|
271
352
|
* Throttle high-noise Pi SDK events from session-events.jsonl.
|
|
272
353
|
* Always keeps tool lifecycle, turn/agent end, assistant messages, and errors.
|
|
@@ -404,25 +485,6 @@ function extractSdkUsageSample(event) {
|
|
|
404
485
|
const responseKey = responseKeyCandidates.find((value) => typeof value === "string" && value.length > 0);
|
|
405
486
|
return responseKey ? { responseKey, tokens } : { tokens };
|
|
406
487
|
}
|
|
407
|
-
/** Extract a non-empty stop reason from a terminal SDK event.
|
|
408
|
-
* Probes multiple field shapes across SDK versions so a missing field fails
|
|
409
|
-
* open (undefined) rather than misclassifying an attempt. */
|
|
410
|
-
function readStopReason(event) {
|
|
411
|
-
const message = isRecord(event.message) ? event.message : undefined;
|
|
412
|
-
const candidates = [
|
|
413
|
-
message?.stop_reason,
|
|
414
|
-
message?.stopReason,
|
|
415
|
-
event.stopReason,
|
|
416
|
-
event.stop_reason,
|
|
417
|
-
];
|
|
418
|
-
for (const candidate of candidates) {
|
|
419
|
-
if (typeof candidate === "string" &&
|
|
420
|
-
candidate.trim().length > 0) {
|
|
421
|
-
return candidate.trim();
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return undefined;
|
|
425
|
-
}
|
|
426
488
|
function aggregateSdkTokenUsage(samples) {
|
|
427
489
|
const identified = new Map();
|
|
428
490
|
let anonymousMaximum = 0;
|
|
@@ -444,6 +506,8 @@ function aggregateSdkTokenUsage(samples) {
|
|
|
444
506
|
* When reuseScope is active, only shared auth/model resources are reused; each attempt still
|
|
445
507
|
* creates and disposes its own session and resource loader. Session reuse across steps is
|
|
446
508
|
* deferred until a proven reset/isolation strategy exists.
|
|
509
|
+
* A transport stall may abort the current prompt and send one continue on the
|
|
510
|
+
* same session; that is in-attempt recovery, not cross-step session reuse.
|
|
447
511
|
*/
|
|
448
512
|
export async function executeSingleSdkAttempt(options) {
|
|
449
513
|
const modelConfig = options.modelConfig;
|
|
@@ -494,7 +558,7 @@ export async function executeSingleSdkAttempt(options) {
|
|
|
494
558
|
type === "message_end" ||
|
|
495
559
|
type === "agent_end" ||
|
|
496
560
|
type === "agent_settled") {
|
|
497
|
-
const candidate =
|
|
561
|
+
const candidate = extractPiEventStopReason(event);
|
|
498
562
|
if (candidate)
|
|
499
563
|
stopReason = candidate;
|
|
500
564
|
}
|
|
@@ -555,20 +619,37 @@ export async function executeSingleSdkAttempt(options) {
|
|
|
555
619
|
? { customTools: writerCustomTools }
|
|
556
620
|
: {}),
|
|
557
621
|
...(requireWriterCustomTools ? { requireWriterCustomTools: true } : {}),
|
|
622
|
+
...(options.piExtensionPaths && options.piExtensionPaths.length > 0
|
|
623
|
+
? { additionalExtensionPaths: options.piExtensionPaths }
|
|
624
|
+
: {}),
|
|
558
625
|
});
|
|
559
626
|
let resolveStall;
|
|
560
627
|
let resolveSettlement;
|
|
561
628
|
let settled = false;
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
629
|
+
let abortConfirmed = true;
|
|
630
|
+
const persistRuntimeNote = (event) => {
|
|
631
|
+
const line = serializeSessionEvent(event);
|
|
632
|
+
stdoutPreview.append(`${line}\n`);
|
|
633
|
+
stdoutCollector.append(`${line}\n`);
|
|
634
|
+
sessionEventAppender?.append(line, event);
|
|
635
|
+
};
|
|
636
|
+
const resetSettlement = () => {
|
|
637
|
+
settled = false;
|
|
638
|
+
return new Promise((resolve) => {
|
|
639
|
+
resolveSettlement = resolve;
|
|
640
|
+
});
|
|
641
|
+
};
|
|
642
|
+
const resetStallPromise = () => {
|
|
643
|
+
if (stallTimeoutMs <= 0) {
|
|
644
|
+
resolveStall = undefined;
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
return new Promise((resolve) => {
|
|
567
648
|
resolveStall = resolve;
|
|
568
|
-
})
|
|
569
|
-
|
|
649
|
+
});
|
|
650
|
+
};
|
|
570
651
|
const armStallWatchdog = () => {
|
|
571
|
-
if (
|
|
652
|
+
if (stallTimeoutMs <= 0 || !resolveStall)
|
|
572
653
|
return;
|
|
573
654
|
if (stallHandle)
|
|
574
655
|
clearTimeout(stallHandle);
|
|
@@ -609,17 +690,6 @@ export async function executeSingleSdkAttempt(options) {
|
|
|
609
690
|
stdoutCollector.append(`${line}\n`);
|
|
610
691
|
sessionEventAppender?.append(line, event);
|
|
611
692
|
});
|
|
612
|
-
const filePrefix = options.attachedFiles
|
|
613
|
-
.map((file) => `@${file}`)
|
|
614
|
-
.join(" ");
|
|
615
|
-
const promptMessage = filePrefix
|
|
616
|
-
? `${filePrefix}\n${options.userMessage}`
|
|
617
|
-
: options.userMessage;
|
|
618
|
-
const promptPromise = session.prompt(promptMessage);
|
|
619
|
-
// A settlement event is permitted to win the race while prompt() remains
|
|
620
|
-
// pending. Observe a later rejection so it never becomes unhandled.
|
|
621
|
-
void promptPromise.catch(() => { });
|
|
622
|
-
armStallWatchdog();
|
|
623
693
|
const timeoutPromise = timeoutMs > 0
|
|
624
694
|
? new Promise((resolve) => {
|
|
625
695
|
timeoutHandle = setTimeout(() => {
|
|
@@ -627,21 +697,79 @@ export async function executeSingleSdkAttempt(options) {
|
|
|
627
697
|
}, timeoutMs);
|
|
628
698
|
})
|
|
629
699
|
: null;
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
700
|
+
const runTurn = async (userMessage) => {
|
|
701
|
+
const settlementPromise = resetSettlement();
|
|
702
|
+
const stallPromise = resetStallPromise();
|
|
703
|
+
const promptPromise = session.prompt(userMessage);
|
|
704
|
+
// A settlement event is permitted to win the race while prompt() remains
|
|
705
|
+
// pending. Observe a later rejection so it never becomes unhandled.
|
|
706
|
+
void promptPromise.catch(() => { });
|
|
707
|
+
armStallWatchdog();
|
|
708
|
+
return Promise.race([
|
|
709
|
+
promptPromise.then(() => "done"),
|
|
710
|
+
settlementPromise,
|
|
711
|
+
...(timeoutPromise ? [timeoutPromise] : []),
|
|
712
|
+
...(stallPromise ? [stallPromise] : []),
|
|
713
|
+
]);
|
|
714
|
+
};
|
|
715
|
+
const disposeSession = async () => {
|
|
642
716
|
disposeAttempted = true;
|
|
643
717
|
const disposeConfirmed = await runSessionActionWithGrace("dispose", () => session.dispose());
|
|
644
718
|
terminationConfirmed = abortConfirmed && disposeConfirmed;
|
|
719
|
+
};
|
|
720
|
+
const failClosedAfterWait = async (reason, extraStderr, abortFirst = true) => {
|
|
721
|
+
timedOut = true;
|
|
722
|
+
appendStderr(reason === "stall"
|
|
723
|
+
? `pi SDK step stalled after ${stallTimeoutMs}ms with no provider activity`
|
|
724
|
+
: `pi SDK step timed out after ${timeoutMs}ms`);
|
|
725
|
+
if (extraStderr)
|
|
726
|
+
appendStderr(extraStderr);
|
|
727
|
+
if (abortFirst) {
|
|
728
|
+
abortConfirmed = await runSessionActionWithGrace("abort", () => session.abort());
|
|
729
|
+
}
|
|
730
|
+
await disposeSession();
|
|
731
|
+
};
|
|
732
|
+
const filePrefix = options.attachedFiles
|
|
733
|
+
.map((file) => `@${file}`)
|
|
734
|
+
.join(" ");
|
|
735
|
+
const promptMessage = filePrefix
|
|
736
|
+
? `${filePrefix}\n${options.userMessage}`
|
|
737
|
+
: options.userMessage;
|
|
738
|
+
let continuesSent = 0;
|
|
739
|
+
let raced = await runTurn(promptMessage);
|
|
740
|
+
if (raced === "stall") {
|
|
741
|
+
abortConfirmed = await runSessionActionWithGrace("abort", () => session.abort());
|
|
742
|
+
const withinAbsoluteTimeout = timeoutMs <= 0 || Date.now() - startedAt < timeoutMs;
|
|
743
|
+
const canContinue = abortConfirmed &&
|
|
744
|
+
writeToolCallCount === 0 &&
|
|
745
|
+
withinAbsoluteTimeout &&
|
|
746
|
+
continuesSent < PI_SDK_STALL_CONTINUE_MAX;
|
|
747
|
+
if (canContinue) {
|
|
748
|
+
// The aborted turn's stopReason must not leak onto a recovered continue.
|
|
749
|
+
stopReason = undefined;
|
|
750
|
+
continuesSent += 1;
|
|
751
|
+
persistRuntimeNote({
|
|
752
|
+
type: "loop-agent-stall-continue",
|
|
753
|
+
prompt: PI_SDK_STALL_CONTINUE_PROMPT,
|
|
754
|
+
maxContinues: PI_SDK_STALL_CONTINUE_MAX,
|
|
755
|
+
});
|
|
756
|
+
raced = await runTurn(PI_SDK_STALL_CONTINUE_PROMPT);
|
|
757
|
+
if (raced !== "done" && raced !== "settled") {
|
|
758
|
+
await failClosedAfterWait(raced === "stall" ? "stall" : "absolute-timeout", raced === "stall"
|
|
759
|
+
? "pi SDK stall continue did not recover; treating as timeout"
|
|
760
|
+
: "pi SDK stall continue hit the absolute timeout", true);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
else {
|
|
764
|
+
await failClosedAfterWait("stall", !abortConfirmed
|
|
765
|
+
? undefined
|
|
766
|
+
: writeToolCallCount > 0
|
|
767
|
+
? "pi SDK stall continue skipped because write tools already ran"
|
|
768
|
+
: "pi SDK stall continue skipped because absolute timeout elapsed", false);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
else if (raced === "absolute-timeout") {
|
|
772
|
+
await failClosedAfterWait("absolute-timeout");
|
|
645
773
|
}
|
|
646
774
|
}
|
|
647
775
|
catch (error) {
|