@humain/humain-code 0.4.12 → 0.4.14
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/CHANGELOG.md +21 -1
- package/dist/bun/sandbox-env-setup.js +1 -1
- package/dist/bun/sandbox-env-setup.js.map +1 -1
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/anthropic-messages-YSAHA7QM.js +67 -0
- package/dist/bundle/chunks/azure-openai-responses-Z5XYDPHS.js +15 -0
- package/dist/bundle/chunks/bedrock-converse-stream.js +393 -314
- package/dist/bundle/chunks/{chunk-EDKZRYWJ.js → chunk-2TTB6GIB.js} +2 -2
- package/dist/bundle/chunks/{chunk-HSDTSUZE.js → chunk-36Q5UVQL.js} +47 -89
- package/dist/bundle/chunks/chunk-4DXXZHY2.js +540 -0
- package/dist/bundle/chunks/{chunk-BKJU56SM.js → chunk-A7QKOI62.js} +142 -126
- package/dist/bundle/chunks/{chunk-UW4GMZL3.js → chunk-AIXI6RIE.js} +264 -248
- package/dist/bundle/chunks/{chunk-V5ZF7Q7L.js → chunk-BVHXWQLD.js} +52 -47
- package/dist/bundle/chunks/{chunk-I2ZWZAIV.js → chunk-COF5P635.js} +222 -148
- package/dist/bundle/chunks/{chunk-SCIGZFN5.js → chunk-DNGJMRJW.js} +11 -11
- package/dist/bundle/chunks/{chunk-XGO43DKL.js → chunk-DUSJT2W4.js} +21 -25
- package/dist/bundle/chunks/chunk-EYIYBQAR.js +7 -0
- package/dist/bundle/chunks/chunk-FRUFMISJ.js +505 -0
- package/dist/bundle/chunks/{chunk-R5VIAWGA.js → chunk-H2FY3PEV.js} +9 -8
- package/dist/bundle/chunks/{chunk-45ZBHMQG.js → chunk-HDA2IGKA.js} +4 -4
- package/dist/bundle/chunks/{chunk-KGI4EX6R.js → chunk-IUKCPYKD.js} +442 -442
- package/dist/bundle/chunks/{chunk-NLTW6A7G.js → chunk-KA7K6ECX.js} +3730 -3353
- package/dist/bundle/chunks/{chunk-AS2Y2MO6.js → chunk-KK3KUUMM.js} +643 -624
- package/dist/bundle/chunks/{chunk-6KAMTNN3.js → chunk-L3J4P5JR.js} +1 -1
- package/dist/bundle/chunks/chunk-L6Z6JKKC.js +3 -0
- package/dist/bundle/chunks/{chunk-DZ5C66IU.js → chunk-LUL775V7.js} +33 -33
- package/dist/bundle/chunks/{chunk-BRXQUQSC.js → chunk-MF2NEHP4.js} +778 -775
- package/dist/bundle/chunks/chunk-MG5PX4KU.js +31 -0
- package/dist/bundle/chunks/{chunk-LCOHFEZZ.js → chunk-NNKA2PAP.js} +1 -1
- package/dist/bundle/chunks/{chunk-HMWAH7ZY.js → chunk-OX2IBCCA.js} +53 -49
- package/dist/bundle/chunks/{chunk-WBJN6PEI.js → chunk-QYCOHSI7.js} +1 -1
- package/dist/bundle/chunks/{chunk-77EWF2NW.js → chunk-TJG52LZB.js} +1 -1
- package/dist/bundle/chunks/{chunk-5XD3DHYL.js → chunk-UDVC7A5S.js} +1 -1
- package/dist/bundle/chunks/chunk-UGXYG7HN.js +22 -0
- package/dist/bundle/chunks/{chunk-VYIIPF57.js → chunk-UHLW4KJ7.js} +419 -413
- package/dist/bundle/chunks/{chunk-FF26YENK.js → chunk-W2QRCQBX.js} +4 -3
- package/dist/bundle/chunks/chunk-XQRYOCHA.js +26 -0
- package/dist/bundle/chunks/{chunk-7Z5MWPYE.js → chunk-Y3RFGBG2.js} +1 -1
- package/dist/bundle/chunks/chunk-YJ3NQWES.js +9 -0
- package/dist/bundle/chunks/{chunk-YJBE3IGR.js → chunk-YRCLNWFV.js} +20 -20
- package/dist/bundle/chunks/chunk-YZMQXAJM.js +8 -0
- package/dist/bundle/chunks/{chunk-BHM75BJJ.js → chunk-Z74ZYQPX.js} +207 -79
- package/dist/bundle/chunks/{cli-5ACW3WND.js → cli-SRI4UOSL.js} +6 -6
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-FZ3UQCZ7.js → cloudflare-workers-ai-system-one-JGN7NZCV.js} +1 -1
- package/dist/bundle/chunks/codemode-worker.js +27 -14
- package/dist/bundle/chunks/{compat-KXWWOFHQ.js → compat-OQMUE3QD.js} +6 -6
- package/dist/bundle/chunks/{dist-6SWVHFCS.js → dist-65YQEF26.js} +277 -72
- package/dist/bundle/chunks/dist-MNSGVI4C.js +7 -0
- package/dist/bundle/chunks/{dist-cjs-RL2OCAP2.js → dist-cjs-4BMVQ74V.js} +1 -1
- package/dist/bundle/chunks/{easter-egg-3d-3L3IKAT6.js → easter-egg-3d-ZJ2JUFOA.js} +1 -1
- package/dist/bundle/chunks/es-YEFEOGR3.js +1905 -0
- package/dist/bundle/chunks/{esm-763X2IA7.js → esm-NCUV2DF7.js} +1 -1
- package/dist/bundle/chunks/{event-streams-R5OECII4.js → event-streams-NXFTZDSF.js} +1 -1
- package/dist/bundle/chunks/execute-LRTXH4YJ.js +553 -0
- package/dist/bundle/chunks/{extract-DLZ425VI.js → extract-OZW5JHG6.js} +140 -120
- package/dist/bundle/chunks/{google-generative-ai-JD2FVOIX.js → google-generative-ai-YXXFSTX7.js} +2 -2
- package/dist/bundle/chunks/{google-vertex-PFBMDCBW.js → google-vertex-3IVWLYJ5.js} +2 -2
- package/dist/bundle/chunks/host-2RMBOGA7.js +2 -0
- package/dist/bundle/chunks/{mistral-conversations-D74NZ65O.js → mistral-conversations-Y7GWO3QB.js} +14 -13
- package/dist/bundle/chunks/{node-W47VUEGE.js → node-ELWNZC34.js} +328 -337
- package/dist/bundle/chunks/{node-4GGYDW5Q.js → node-SPBTZUUS.js} +26 -25
- package/dist/bundle/chunks/{openai-codex-responses-JAAA7MSS.js → openai-codex-responses-NSXWHIDT.js} +3 -4
- package/dist/bundle/chunks/{openai-completions-PGPMGQPU.js → openai-completions-WGBQHTYA.js} +9 -8
- package/dist/bundle/chunks/{openai-decisions-QQ4MEABI.js → openai-decisions-QWEISDVO.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-FG2R2M4L.js → openai-responses-OKGCSIEY.js} +6 -6
- package/dist/bundle/chunks/{openrouter-images-NTBP3UUE.js → openrouter-images-BMVMAROU.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-JD4O7KIP.js → pi-messages-XNEG23NU.js} +1 -1
- package/dist/bundle/chunks/runtime-VGSK3QCM.js +2 -0
- package/dist/bundle/chunks/{typesafe-system-one-TTC7YCO3.js → typesafe-system-one-62YHYXZV.js} +1 -1
- package/dist/bundle/chunks/{undici-EEOUTE5F.js → undici-7EW63V4X.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-5KW36RPG.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/flow/package.json +5 -6
- package/dist/bundle/index.js +6 -6
- package/dist/bundle/rpc-entry.js +2 -2
- package/dist/coordination/adapter/delivery.d.ts.map +1 -1
- package/dist/coordination/adapter/delivery.js +1 -0
- package/dist/coordination/adapter/delivery.js.map +1 -1
- package/dist/coordination/adapter/index.d.ts.map +1 -1
- package/dist/coordination/adapter/index.js +3 -1
- package/dist/coordination/adapter/index.js.map +1 -1
- package/dist/coordination/adapter/receipts.d.ts +2 -1
- package/dist/coordination/adapter/receipts.d.ts.map +1 -1
- package/dist/coordination/adapter/receipts.js +7 -4
- package/dist/coordination/adapter/receipts.js.map +1 -1
- package/dist/coordination/adapter/supervisor.d.ts.map +1 -1
- package/dist/coordination/adapter/supervisor.js +8 -0
- package/dist/coordination/adapter/supervisor.js.map +1 -1
- package/dist/coordination/broker/broker.d.ts +11 -0
- package/dist/coordination/broker/broker.d.ts.map +1 -1
- package/dist/coordination/broker/broker.js +195 -18
- package/dist/coordination/broker/broker.js.map +1 -1
- package/dist/coordination/client/client.d.ts +5 -0
- package/dist/coordination/client/client.d.ts.map +1 -1
- package/dist/coordination/client/client.js +23 -9
- package/dist/coordination/client/client.js.map +1 -1
- package/dist/coordination/transport/protocol.d.ts.map +1 -1
- package/dist/coordination/transport/protocol.js +8 -1
- package/dist/coordination/transport/protocol.js.map +1 -1
- package/dist/coordination/transport/types.d.ts +6 -0
- package/dist/coordination/transport/types.d.ts.map +1 -1
- package/dist/coordination/transport/types.js +2 -1
- package/dist/coordination/transport/types.js.map +1 -1
- package/dist/core/agent-session.d.ts +44 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +305 -124
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +20 -13
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/auto-effort.d.ts +16 -0
- package/dist/core/auto-effort.d.ts.map +1 -0
- package/dist/core/auto-effort.js +69 -0
- package/dist/core/auto-effort.js.map +1 -0
- package/dist/core/auto-session-namer.d.ts.map +1 -1
- package/dist/core/auto-session-namer.js +2 -12
- package/dist/core/auto-session-namer.js.map +1 -1
- package/dist/core/bug-report.d.ts +11 -1
- package/dist/core/bug-report.d.ts.map +1 -1
- package/dist/core/bug-report.js +2 -2
- package/dist/core/bug-report.js.map +1 -1
- package/dist/core/compaction/branch-summarization.d.ts +3 -2
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +1 -1
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +13 -4
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +94 -5
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/utils.d.ts +6 -0
- package/dist/core/compaction/utils.d.ts.map +1 -1
- package/dist/core/compaction/utils.js +7 -8
- package/dist/core/compaction/utils.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +4 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +6 -3
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +33 -7
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/key-id-schema.d.ts +6 -0
- package/dist/core/key-id-schema.d.ts.map +1 -0
- package/dist/core/key-id-schema.js +16 -0
- package/dist/core/key-id-schema.js.map +1 -0
- package/dist/core/keybindings-schema.d.ts +4 -0
- package/dist/core/keybindings-schema.d.ts.map +1 -0
- package/dist/core/keybindings-schema.js +16 -0
- package/dist/core/keybindings-schema.js.map +1 -0
- package/dist/core/keybindings.d.ts +198 -63
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +26 -23
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-config.d.ts +695 -74
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +16 -166
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +39 -4
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +3 -3
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/project-trust.d.ts.map +1 -1
- package/dist/core/project-trust.js +2 -1
- package/dist/core/project-trust.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts +13 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +110 -27
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +5 -1
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/session-export.d.ts.map +1 -1
- package/dist/core/session-export.js +2 -2
- package/dist/core/session-export.js.map +1 -1
- package/dist/core/session-manager.d.ts +36 -5
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +164 -40
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-defaults.d.ts +65 -0
- package/dist/core/settings-defaults.d.ts.map +1 -0
- package/dist/core/settings-defaults.js +66 -0
- package/dist/core/settings-defaults.js.map +1 -0
- package/dist/core/settings-manager.d.ts +10 -175
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +64 -44
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +257 -0
- package/dist/core/settings-schema.d.ts.map +1 -0
- package/dist/core/settings-schema.js +311 -0
- package/dist/core/settings-schema.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +4 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +480 -29
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +18 -0
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +46 -0
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/core/tools/renderers/bash.d.ts.map +1 -1
- package/dist/core/tools/renderers/bash.js +17 -46
- package/dist/core/tools/renderers/bash.js.map +1 -1
- package/dist/core/tools/renderers/edit.d.ts +19 -1
- package/dist/core/tools/renderers/edit.d.ts.map +1 -1
- package/dist/core/tools/renderers/edit.js +38 -7
- package/dist/core/tools/renderers/edit.js.map +1 -1
- package/dist/core/tools/renderers/find.d.ts.map +1 -1
- package/dist/core/tools/renderers/find.js +3 -0
- package/dist/core/tools/renderers/find.js.map +1 -1
- package/dist/core/tools/renderers/grep.d.ts.map +1 -1
- package/dist/core/tools/renderers/grep.js +3 -0
- package/dist/core/tools/renderers/grep.js.map +1 -1
- package/dist/core/tools/renderers/highlighting.d.ts +13 -0
- package/dist/core/tools/renderers/highlighting.d.ts.map +1 -0
- package/dist/core/tools/renderers/highlighting.js +42 -0
- package/dist/core/tools/renderers/highlighting.js.map +1 -0
- package/dist/core/tools/renderers/ls.d.ts.map +1 -1
- package/dist/core/tools/renderers/ls.js +3 -0
- package/dist/core/tools/renderers/ls.js.map +1 -1
- package/dist/core/tools/renderers/read.d.ts.map +1 -1
- package/dist/core/tools/renderers/read.js +3 -0
- package/dist/core/tools/renderers/read.js.map +1 -1
- package/dist/core/tools/renderers/write.d.ts.map +1 -1
- package/dist/core/tools/renderers/write.js +3 -1
- package/dist/core/tools/renderers/write.js.map +1 -1
- package/dist/core/tools/subagent.d.ts +4 -0
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +85 -8
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/tools/truncate.d.ts.map +1 -1
- package/dist/core/tools/truncate.js +92 -44
- package/dist/core/tools/truncate.js.map +1 -1
- package/dist/core/usage-totals.d.ts +8 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +106 -10
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/codemode/execute.d.ts.map +1 -1
- package/dist/extensions/codemode/execute.js +64 -45
- package/dist/extensions/codemode/execute.js.map +1 -1
- package/dist/extensions/codemode/index.d.ts.map +1 -1
- package/dist/extensions/codemode/index.js +2 -1
- package/dist/extensions/codemode/index.js.map +1 -1
- package/dist/extensions/codemode/renderer.d.ts +2 -2
- package/dist/extensions/codemode/renderer.d.ts.map +1 -1
- package/dist/extensions/codemode/renderer.js +9 -3
- package/dist/extensions/codemode/renderer.js.map +1 -1
- package/dist/extensions/codemode/tool.d.ts +6 -12
- package/dist/extensions/codemode/tool.d.ts.map +1 -1
- package/dist/extensions/codemode/tool.js +44 -32
- package/dist/extensions/codemode/tool.js.map +1 -1
- package/dist/extensions/mcp/cli.js +5 -8
- package/dist/extensions/mcp/cli.js.map +1 -1
- package/dist/extensions/mcp/index.d.ts.map +1 -1
- package/dist/extensions/mcp/index.js +26 -23
- package/dist/extensions/mcp/index.js.map +1 -1
- package/dist/extensions/mcp/resources.d.ts +0 -6
- package/dist/extensions/mcp/resources.d.ts.map +1 -1
- package/dist/extensions/mcp/resources.js +1 -1
- package/dist/extensions/mcp/resources.js.map +1 -1
- package/dist/extensions/mcp/runtime.d.ts +3 -6
- package/dist/extensions/mcp/runtime.d.ts.map +1 -1
- package/dist/extensions/mcp/runtime.js +4 -39
- package/dist/extensions/mcp/runtime.js.map +1 -1
- package/dist/extensions/mcp/tools.d.ts +2 -3
- package/dist/extensions/mcp/tools.d.ts.map +1 -1
- package/dist/extensions/mcp/tools.js +62 -6
- package/dist/extensions/mcp/tools.js.map +1 -1
- package/dist/extensions/tool-search/tool.d.ts +0 -2
- package/dist/extensions/tool-search/tool.d.ts.map +1 -1
- package/dist/extensions/tool-search/tool.js +2 -4
- package/dist/extensions/tool-search/tool.js.map +1 -1
- package/dist/humain/adhd/index.d.ts +3 -2
- package/dist/humain/adhd/index.d.ts.map +1 -1
- package/dist/humain/adhd/index.js +22 -10
- package/dist/humain/adhd/index.js.map +1 -1
- package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +306 -20
- package/dist/humain/caveman/index.d.ts +4 -2
- package/dist/humain/caveman/index.d.ts.map +1 -1
- package/dist/humain/caveman/index.js +51 -16
- package/dist/humain/caveman/index.js.map +1 -1
- package/dist/humain/ponytail/index.d.ts +2 -0
- package/dist/humain/ponytail/index.d.ts.map +1 -1
- package/dist/humain/ponytail/index.js +2 -0
- package/dist/humain/ponytail/index.js.map +1 -1
- package/dist/humain/ponytail/vendor/hooks/ponytail-config.d.ts.map +1 -1
- package/dist/humain/ponytail/vendor/hooks/ponytail-config.js +39 -9
- package/dist/humain/ponytail/vendor/hooks/ponytail-config.js.map +1 -1
- package/dist/humain/ponytail/vendor/hooks/ponytail-instructions.js +1 -1
- package/dist/humain/ponytail/vendor/hooks/ponytail-instructions.js.map +1 -1
- package/dist/humain/ponytail/vendor/pi-extension/index.d.ts +4 -0
- package/dist/humain/ponytail/vendor/pi-extension/index.d.ts.map +1 -1
- package/dist/humain/ponytail/vendor/pi-extension/index.js +8 -0
- package/dist/humain/ponytail/vendor/pi-extension/index.js.map +1 -1
- package/dist/humain/web-access/vendor/baizhi.js.map +1 -1
- package/dist/humain/web-access/vendor/brave.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/brave.js +19 -2
- package/dist/humain/web-access/vendor/brave.js.map +1 -1
- package/dist/humain/web-access/vendor/ceramic.d.ts +4 -0
- package/dist/humain/web-access/vendor/ceramic.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/ceramic.js +212 -0
- package/dist/humain/web-access/vendor/ceramic.js.map +1 -0
- package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/content-find.js +2 -1
- package/dist/humain/web-access/vendor/content-find.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-page.js +3 -1
- package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/curator-server.js +2 -0
- package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/duckduckgo.js +5 -1
- package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
- package/dist/humain/web-access/vendor/endpoint-pdf-extract.d.ts +23 -0
- package/dist/humain/web-access/vendor/endpoint-pdf-extract.d.ts.map +1 -0
- package/dist/humain/web-access/vendor/endpoint-pdf-extract.js +193 -0
- package/dist/humain/web-access/vendor/endpoint-pdf-extract.js.map +1 -0
- package/dist/humain/web-access/vendor/extract.d.ts +5 -1
- package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/extract.js +49 -12
- package/dist/humain/web-access/vendor/extract.js.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.d.ts +2 -0
- package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/fetch-params.js +9 -0
- package/dist/humain/web-access/vendor/fetch-params.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-api.d.ts +5 -0
- package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-api.js +16 -0
- package/dist/humain/web-access/vendor/gemini-api.js.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
- package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/gemini-search.js +48 -172
- package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
- package/dist/humain/web-access/vendor/github-extract.d.ts +7 -0
- package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/github-extract.js +31 -2
- package/dist/humain/web-access/vendor/github-extract.js.map +1 -1
- package/dist/humain/web-access/vendor/github-issue-pr.d.ts +2 -0
- package/dist/humain/web-access/vendor/github-issue-pr.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/github-issue-pr.js +86 -74
- package/dist/humain/web-access/vendor/github-issue-pr.js.map +1 -1
- package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/index.js +68 -27
- package/dist/humain/web-access/vendor/index.js.map +1 -1
- package/dist/humain/web-access/vendor/openai-search.js +3 -3
- package/dist/humain/web-access/vendor/openai-search.js.map +1 -1
- package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/page-query.js +6 -9
- package/dist/humain/web-access/vendor/page-query.js.map +1 -1
- package/dist/humain/web-access/vendor/parallel-mcp.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/parallel-mcp.js +2 -0
- package/dist/humain/web-access/vendor/parallel-mcp.js.map +1 -1
- package/dist/humain/web-access/vendor/pdf-extract.d.ts +1 -1
- package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/pdf-extract.js +31 -1
- package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/perplexity.js +21 -2
- package/dist/humain/web-access/vendor/perplexity.js.map +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js +1 -1
- package/dist/humain/web-access/vendor/query-rewrite.js.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts +4 -0
- package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/ssrf-protection.js +19 -4
- package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
- package/dist/humain/web-access/vendor/storage.d.ts +14 -0
- package/dist/humain/web-access/vendor/storage.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/storage.js +48 -0
- package/dist/humain/web-access/vendor/storage.js.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/summary-review.js +18 -6
- package/dist/humain/web-access/vendor/summary-review.js.map +1 -1
- package/dist/humain/web-access/vendor/tool-arguments.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/tool-arguments.js +5 -2
- package/dist/humain/web-access/vendor/tool-arguments.js.map +1 -1
- package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/utils.js +21 -6
- package/dist/humain/web-access/vendor/utils.js.map +1 -1
- package/dist/humain/web-access/vendor/video-extract.js +6 -2
- package/dist/humain/web-access/vendor/video-extract.js.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts +2 -1
- package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
- package/dist/humain/web-access/vendor/web-tool-core.js +56 -13
- package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
- package/dist/humain/web-access/vendor/zai.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +3 -3
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +21 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +79 -10
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts +8 -3
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +156 -133
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +1 -1
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +10 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +83 -7
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +2 -2
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
- package/dist/modes/interactive/components/themed-text.js +3 -1
- package/dist/modes/interactive/components/themed-text.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +7 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +36 -19
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/transcript-container.d.ts +12 -0
- package/dist/modes/interactive/components/transcript-container.d.ts.map +1 -0
- package/dist/modes/interactive/components/transcript-container.js +31 -0
- package/dist/modes/interactive/components/transcript-container.js.map +1 -0
- package/dist/modes/interactive/components/user-message.d.ts +6 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +20 -5
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.d.ts +20 -5
- package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
- package/dist/modes/interactive/components/visual-truncate.js +42 -3
- package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +125 -19
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme-schema.d.ts +28 -0
- package/dist/modes/interactive/theme/theme-schema.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-schema.js +105 -0
- package/dist/modes/interactive/theme/theme-schema.js.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts +257 -0
- package/dist/modes/interactive/theme/theme-tokens.d.ts.map +1 -0
- package/dist/modes/interactive/theme/theme-tokens.js +94 -0
- package/dist/modes/interactive/theme/theme-tokens.js.map +1 -0
- package/dist/modes/interactive/theme/theme.d.ts +15 -16
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +26 -29
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +4 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/utils/child-process.d.ts +0 -7
- package/dist/utils/child-process.d.ts.map +1 -1
- package/dist/utils/child-process.js +12 -3
- package/dist/utils/child-process.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +6 -1
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/image-convert.d.ts +7 -0
- package/dist/utils/image-convert.d.ts.map +1 -1
- package/dist/utils/image-convert.js +35 -3
- package/dist/utils/image-convert.js.map +1 -1
- package/dist/utils/image-resize.d.ts.map +1 -1
- package/dist/utils/image-resize.js +2 -2
- package/dist/utils/image-resize.js.map +1 -1
- package/dist/utils/syntax-highlight.d.ts +7 -0
- package/dist/utils/syntax-highlight.d.ts.map +1 -1
- package/dist/utils/syntax-highlight.js +54 -3
- package/dist/utils/syntax-highlight.js.map +1 -1
- package/dist/utils/windows-path.js +1 -1
- package/dist/utils/windows-path.js.map +1 -1
- package/dist/utils/zip.d.ts.map +1 -1
- package/dist/utils/zip.js +3 -1
- package/dist/utils/zip.js.map +1 -1
- package/docs/auto-session-namer.md +4 -0
- package/docs/cli-integration.md +1 -1
- package/docs/cli.md +1 -1
- package/docs/codemode.md +1 -1
- package/docs/compaction.md +9 -5
- package/docs/coordination.md +7 -0
- package/docs/environment-variables.md +1 -0
- package/docs/extensions.md +7 -4
- package/docs/keybindings.md +1 -0
- package/docs/mcp.md +1 -1
- package/docs/models.md +1 -0
- package/docs/providers.md +20 -0
- package/docs/session-format.md +16 -2
- package/docs/settings.md +16 -1
- package/docs/themes.md +4 -2
- package/docs/tui.md +1 -1
- package/docs/usage.md +6 -2
- package/examples/extensions/custom-provider-anthropic/package-lock.json +6 -6
- package/examples/extensions/custom-provider-anthropic/package.json +2 -2
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/dynamic-resources/dynamic.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +20 -20
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/overlay-test.ts +2 -2
- package/examples/extensions/plan-mode/index.ts +6 -2
- package/examples/extensions/sandbox/package-lock.json +8 -8
- package/examples/extensions/sandbox/package.json +2 -2
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/plugins/pi-example-plugin/package.json +2 -2
- package/examples/plugins/pi-example-plugin/src/contract.ts +1 -1
- package/examples/plugins/pi-example-plugin/src/session.ts +1 -1
- package/examples/plugins/pi-example-plugin/src/tui.ts +1 -1
- package/npm-shrinkwrap.json +174 -190
- package/package.json +24 -23
- package/schemas/keybindings.schema.json +397 -0
- package/schemas/models.schema.json +1157 -0
- package/schemas/settings.schema.json +875 -0
- package/schemas/theme.schema.json +365 -0
- package/src/coordination/UPSTREAM.md +36 -3
- package/src/coordination/upstream.json +3 -2
- package/src/humain/adhd/UPSTREAM.md +21 -3
- package/src/humain/adhd/upstream.json +1 -1
- package/src/humain/caveman/UPSTREAM.md +24 -3
- package/src/humain/ponytail/UPSTREAM.md +51 -4
- package/src/humain/ponytail/upstream.json +12 -12
- package/src/humain/ponytail/vendor/skills/ponytail/SKILL.md +1 -1
- package/src/humain/ponytail/vendor/skills/ponytail-audit/SKILL.md +1 -1
- package/src/humain/ponytail/vendor/skills/ponytail-debt/SKILL.md +13 -10
- package/src/humain/ponytail/vendor/skills/ponytail-help/SKILL.md +1 -1
- package/src/humain/ponytail/vendor/skills/ponytail-review/SKILL.md +1 -1
- package/src/humain/web-access/UPSTREAM.md +55 -1
- package/src/humain/web-access/upstream.json +4 -4
- package/dist/bundle/chunks/anthropic-messages-UNHXXOD4.js +0 -70
- package/dist/bundle/chunks/azure-openai-responses-4QRYJCC2.js +0 -14
- package/dist/bundle/chunks/chunk-GVVRXZHN.js +0 -17
- package/dist/bundle/chunks/chunk-QMUIATLD.js +0 -209
- package/dist/bundle/chunks/chunk-QSPDLT2R.js +0 -160
- package/dist/bundle/chunks/chunk-SZRZXVVZ.js +0 -125
- package/dist/bundle/chunks/chunk-XMHLSV3I.js +0 -48
- package/dist/bundle/chunks/chunk-YKZGL4MB.js +0 -86
- package/dist/bundle/chunks/dist-VNSMKBZ6.js +0 -7
- package/dist/bundle/chunks/es-N6YFJOD7.js +0 -1901
- package/dist/bundle/chunks/execute-4X6G65NZ.js +0 -536
- package/dist/bundle/chunks/host-4J7H7KDS.js +0 -2
- package/dist/bundle/chunks/runtime-SI76JZNE.js +0 -2
- package/dist/bundle/chunks/virtual-modules-GZY3Y4GX.js +0 -5
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// Derived from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit b93895d2; modified for HUMAIN Code CLI.
|
|
1
2
|
/**
|
|
2
3
|
* AgentSession - Core abstraction for agent lifecycle and session management.
|
|
3
4
|
*
|
|
@@ -28,8 +29,11 @@ import { processImage } from "../utils/image-process.js";
|
|
|
28
29
|
import { sleep } from "../utils/sleep.js";
|
|
29
30
|
import { normalizeToolResultImages } from "../utils/tool-result-images.js";
|
|
30
31
|
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
32
|
+
import { AUTO_EFFORT_ENTRY_TYPE, getAutoEffortSessionOverride, selectAutoEffort, } from "./auto-effort.js";
|
|
33
|
+
import { AUTO_NAMER_DEFAULT_MODEL } from "./auto-session-namer.js";
|
|
31
34
|
import { executeBashWithOperations } from "./bash-executor.js";
|
|
32
35
|
import { generateBugReportSummary } from "./bug-report.js";
|
|
36
|
+
import { SummarizationAbortedError } from "./compaction/compaction.js";
|
|
33
37
|
import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateProjectedContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
|
|
34
38
|
import { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from "./defaults.js";
|
|
35
39
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
@@ -51,7 +55,7 @@ import { buildSystemPrompt, buildSystemPromptSections, diffSystemPromptSections,
|
|
|
51
55
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
52
56
|
import { createAllToolDefinitions } from "./tools/index.js";
|
|
53
57
|
import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
|
|
54
|
-
import { addUsageToTotals, combineUsage, createUsageTotals } from "./usage-totals.js";
|
|
58
|
+
import { addUsageToTotals, combineUsage, createUsageTotals, getSessionUsage } from "./usage-totals.js";
|
|
55
59
|
import { findLatestResponse, getBranchSelection, getVirtualModelState, isVirtualModel, VIRTUAL_MODEL_STATE_ENTRY, } from "./virtual-models.js";
|
|
56
60
|
/**
|
|
57
61
|
* Parse a skill block from message text.
|
|
@@ -98,6 +102,11 @@ export class AgentSession {
|
|
|
98
102
|
sessionManager;
|
|
99
103
|
settingsManager;
|
|
100
104
|
_scopedModels;
|
|
105
|
+
_autoEffortInteractive = false;
|
|
106
|
+
_autoEffortController;
|
|
107
|
+
_thinkingSelectionRevision = 0;
|
|
108
|
+
_autoEffortInputs = new WeakMap();
|
|
109
|
+
_autoEffortPendingInputs = new Map();
|
|
101
110
|
// Event subscription state
|
|
102
111
|
_unsubscribeAgent;
|
|
103
112
|
_eventListeners = [];
|
|
@@ -156,6 +165,7 @@ export class AgentSession {
|
|
|
156
165
|
* retry is routed with it as `failed`, since the context no longer contains it.
|
|
157
166
|
*/
|
|
158
167
|
_failedResponse;
|
|
168
|
+
_contextEstimate;
|
|
159
169
|
// Bash execution state
|
|
160
170
|
_bashAbortControllers = new Set();
|
|
161
171
|
_pendingBashMessages = [];
|
|
@@ -573,22 +583,116 @@ export class AgentSession {
|
|
|
573
583
|
});
|
|
574
584
|
return this._nestedToolCalls.execute(parentToolCallId, name, args, options);
|
|
575
585
|
}
|
|
576
|
-
/** Whether
|
|
577
|
-
_exceedsCompactionThreshold(model
|
|
586
|
+
/** Whether the current session projection exceeds the compaction threshold of `model`. */
|
|
587
|
+
_exceedsCompactionThreshold(model) {
|
|
578
588
|
if (model.contextWindow <= 0)
|
|
579
589
|
return false;
|
|
580
|
-
return shouldCompact(
|
|
590
|
+
return shouldCompact(this._contextTokenEstimate().tokens, model.contextWindow, this.settingsManager.getCompactionSettings(this.model));
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* The context size estimate of the current projection, kept until the projection changes: the compaction check
|
|
594
|
+
* runs before every request and the footer asks after every entry, and each estimate walks the whole context.
|
|
595
|
+
* `knownAfterCompaction` is false when the latest compaction has no projected assistant response with usage after it
|
|
596
|
+
* (the size is unknown until the next response).
|
|
597
|
+
*/
|
|
598
|
+
_contextTokenEstimate() {
|
|
599
|
+
const sessionManager = this.sessionManager;
|
|
600
|
+
const revision = sessionManager.getProjectionRevision();
|
|
601
|
+
const cached = this._contextEstimate;
|
|
602
|
+
if (cached && cached.sessionManager === sessionManager && cached.revision === revision)
|
|
603
|
+
return cached;
|
|
604
|
+
const projection = sessionManager.peekSessionProjection();
|
|
605
|
+
const branch = sessionManager.getBranch();
|
|
606
|
+
let knownAfterCompaction = true;
|
|
607
|
+
const latestCompaction = getLatestCompactionEntry(branch);
|
|
608
|
+
if (latestCompaction) {
|
|
609
|
+
const projectedAssistants = new Set(projection.entries.flatMap((entry) => entry.messages.some((message) => message.role === "assistant" &&
|
|
610
|
+
message.stopReason !== "aborted" &&
|
|
611
|
+
message.stopReason !== "error" &&
|
|
612
|
+
calculateContextTokens(message.usage) > 0)
|
|
613
|
+
? [entry.sourceEntry.id]
|
|
614
|
+
: []));
|
|
615
|
+
const compactionIndex = branch.findIndex((entry) => entry.id === latestCompaction.id);
|
|
616
|
+
knownAfterCompaction = branch.slice(compactionIndex + 1).some((entry) => projectedAssistants.has(entry.id));
|
|
617
|
+
}
|
|
618
|
+
const tokens = estimateProjectedContextTokens(projection, branch).tokens;
|
|
619
|
+
this._contextEstimate = { sessionManager, revision, tokens, knownAfterCompaction };
|
|
620
|
+
return this._contextEstimate;
|
|
581
621
|
}
|
|
582
622
|
async _compactBeforeNextAssistantResponse(context) {
|
|
583
623
|
const projection = this.sessionManager.buildSessionProjection();
|
|
584
624
|
// A virtual selection is checked in prepareRequest, against the model the request is routed to.
|
|
585
625
|
const model = this.model;
|
|
586
|
-
if (!model || isVirtualModel(model) || !this._exceedsCompactionThreshold(model
|
|
626
|
+
if (!model || isVirtualModel(model) || !this._exceedsCompactionThreshold(model)) {
|
|
587
627
|
return { ...context, messages: projection.messages };
|
|
588
628
|
}
|
|
589
629
|
await this._runAutoCompaction("threshold", false);
|
|
590
630
|
return { ...context, messages: this.sessionManager.buildSessionProjection().messages };
|
|
591
631
|
}
|
|
632
|
+
setAutoEffortInteractive(enabled) {
|
|
633
|
+
this._autoEffortInteractive = enabled;
|
|
634
|
+
if (!enabled)
|
|
635
|
+
this._autoEffortController?.abort();
|
|
636
|
+
}
|
|
637
|
+
get autoEffortSelecting() {
|
|
638
|
+
return this._autoEffortController !== undefined;
|
|
639
|
+
}
|
|
640
|
+
async _prepareAutoEffort(projection, model, signal) {
|
|
641
|
+
const inputs = [];
|
|
642
|
+
for (const entry of projection.entries) {
|
|
643
|
+
const text = this._autoEffortPendingInputs.get(entry.sourceEntry.id);
|
|
644
|
+
if (text === undefined)
|
|
645
|
+
continue;
|
|
646
|
+
this._autoEffortPendingInputs.delete(entry.sourceEntry.id);
|
|
647
|
+
if (entry.messages.some((message) => message.role === "user"))
|
|
648
|
+
inputs.push(text);
|
|
649
|
+
}
|
|
650
|
+
if (!inputs.length ||
|
|
651
|
+
!this._autoEffortInteractive ||
|
|
652
|
+
!this.autoEffortEnabled ||
|
|
653
|
+
!model.reasoning ||
|
|
654
|
+
isVirtualModel(model) ||
|
|
655
|
+
this.model !== model)
|
|
656
|
+
return;
|
|
657
|
+
const text = inputs.join("\n\n");
|
|
658
|
+
if (!text.trim())
|
|
659
|
+
return;
|
|
660
|
+
const reference = this.settingsManager.getSettings().autoSessionNamer?.model ?? AUTO_NAMER_DEFAULT_MODEL;
|
|
661
|
+
const slash = typeof reference === "string" ? reference.indexOf("/") : -1;
|
|
662
|
+
const judge = slash > 0 ? this._modelRuntime.getModel(reference.slice(0, slash), reference.slice(slash + 1)) : undefined;
|
|
663
|
+
if (!judge) {
|
|
664
|
+
this._emit({ type: "auto_effort_state_changed", selecting: false, failure: "unavailable" });
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const sessionId = this.sessionId;
|
|
668
|
+
const controller = new AbortController();
|
|
669
|
+
this._autoEffortController = controller;
|
|
670
|
+
this._emit({ type: "auto_effort_state_changed", selecting: true });
|
|
671
|
+
let failure;
|
|
672
|
+
try {
|
|
673
|
+
// Keep the published trace-purpose contract unchanged; usage identifies the auxiliary call.
|
|
674
|
+
const result = await this._observeRequests("chat", () => selectAutoEffort(this._modelRuntime, judge, text, this.getAvailableThinkingLevels(), signal ? AbortSignal.any([signal, controller.signal]) : controller.signal));
|
|
675
|
+
signal?.throwIfAborted();
|
|
676
|
+
if (this.sessionId !== sessionId)
|
|
677
|
+
return;
|
|
678
|
+
if (result.response) {
|
|
679
|
+
const entry = this.sessionManager.appendUsage("auto-effort", judge.provider, judge.id, result.response.usage);
|
|
680
|
+
this._emit({ type: "entry_appended", entry });
|
|
681
|
+
}
|
|
682
|
+
failure = result.failure;
|
|
683
|
+
if (!controller.signal.aborted && this.model === model && this.autoEffortEnabled && result.level) {
|
|
684
|
+
this.setThinkingLevel(result.level);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
catch {
|
|
688
|
+
signal?.throwIfAborted();
|
|
689
|
+
}
|
|
690
|
+
finally {
|
|
691
|
+
if (this._autoEffortController === controller)
|
|
692
|
+
this._autoEffortController = undefined;
|
|
693
|
+
this._emit({ type: "auto_effort_state_changed", selecting: false, failure });
|
|
694
|
+
}
|
|
695
|
+
}
|
|
592
696
|
_installAgentRequestProjection() {
|
|
593
697
|
const previousPrepareRequest = this.agent.prepareRequest;
|
|
594
698
|
this.agent.prepareRequest = async (request, signal) => {
|
|
@@ -616,9 +720,22 @@ export class AgentSession {
|
|
|
616
720
|
const model = accountRetry?.model ?? previous?.model ?? this.agent.state.model;
|
|
617
721
|
const thinkingLevel = accountRetry?.thinkingLevel ?? previous?.thinkingLevel ?? this.agent.state.thinkingLevel;
|
|
618
722
|
if (!isVirtualModel(model)) {
|
|
619
|
-
|
|
620
|
-
|
|
723
|
+
const selectedModel = this.agent.state.model;
|
|
724
|
+
const revision = this._thinkingSelectionRevision;
|
|
725
|
+
await this._prepareAutoEffort(projection, model, signal);
|
|
726
|
+
signal?.throwIfAborted();
|
|
727
|
+
const effectiveModel = this.agent.state.model === selectedModel ? model : this.agent.state.model;
|
|
728
|
+
await this._prepareAccountRequest(effectiveModel.provider, signal);
|
|
729
|
+
const effectiveThinking = revision === this._thinkingSelectionRevision ? thinkingLevel : this.agent.state.thinkingLevel;
|
|
730
|
+
return {
|
|
731
|
+
...previous,
|
|
732
|
+
context,
|
|
733
|
+
model: effectiveModel,
|
|
734
|
+
thinkingLevel: effectiveThinking,
|
|
735
|
+
};
|
|
621
736
|
}
|
|
737
|
+
for (const entry of projection.entries)
|
|
738
|
+
this._autoEffortPendingInputs.delete(entry.sourceEntry.id);
|
|
622
739
|
// The selection stays in agent state; only this request uses the routed model. A routing
|
|
623
740
|
// failure rejects, which ends the run with an error response. Only messages the user wrote
|
|
624
741
|
// start a turn; extension messages can follow them, e.g. from before_agent_start.
|
|
@@ -640,7 +757,7 @@ export class AgentSession {
|
|
|
640
757
|
}
|
|
641
758
|
// The route stands: the router already decided this request. The state entry does not change
|
|
642
759
|
// the projection.
|
|
643
|
-
if (this._exceedsCompactionThreshold(route.model
|
|
760
|
+
if (this._exceedsCompactionThreshold(route.model)) {
|
|
644
761
|
await this._runAutoCompaction("threshold", false);
|
|
645
762
|
({ previous, context } = await prepare());
|
|
646
763
|
}
|
|
@@ -872,6 +989,10 @@ export class AgentSession {
|
|
|
872
989
|
}
|
|
873
990
|
/** Internal handler for agent events - shared by subscribe and reconnect */
|
|
874
991
|
_handleAgentEvent = async (event) => {
|
|
992
|
+
// An abort requested while the run was starting, e.g. during before_agent_start, stops it
|
|
993
|
+
// here. agent_start is awaited before the first request.
|
|
994
|
+
if (event.type === "agent_start" && this._agentRunAbortRequested)
|
|
995
|
+
this.agent.abort();
|
|
875
996
|
// Record the calls a tool made through ctx.executeTool() and their usage on its result message.
|
|
876
997
|
if (this._nestedToolCalls) {
|
|
877
998
|
if (event.type === "message_start" && event.message.role === "toolResult") {
|
|
@@ -953,8 +1074,14 @@ export class AgentSession {
|
|
|
953
1074
|
// Regular LLM message - persist as SessionMessageEntry
|
|
954
1075
|
entryId = this.sessionManager.appendMessage(event.message);
|
|
955
1076
|
}
|
|
956
|
-
if (entryId)
|
|
1077
|
+
if (entryId) {
|
|
957
1078
|
this._entryIdsByMessage.set(event.message, entryId);
|
|
1079
|
+
const input = this._autoEffortInputs.get(event.message);
|
|
1080
|
+
if (input !== undefined) {
|
|
1081
|
+
this._autoEffortPendingInputs.set(entryId, input);
|
|
1082
|
+
this._autoEffortInputs.delete(event.message);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
958
1085
|
if (event.message.role === "user" &&
|
|
959
1086
|
[...this._controlContinuations.values()].some((pending) => pending.timestamp === event.message.timestamp && pending.withdrawn))
|
|
960
1087
|
this._omitControlContinuation(event.message.timestamp);
|
|
@@ -1274,6 +1401,8 @@ export class AgentSession {
|
|
|
1274
1401
|
* Call this when completely done with the session.
|
|
1275
1402
|
*/
|
|
1276
1403
|
dispose() {
|
|
1404
|
+
this._autoEffortController?.abort();
|
|
1405
|
+
this._autoEffortPendingInputs.clear();
|
|
1277
1406
|
void closeSessionFlowControl(this);
|
|
1278
1407
|
this._withdrawControlContinuations();
|
|
1279
1408
|
this._agentRunAbortController?.abort();
|
|
@@ -1379,6 +1508,7 @@ export class AgentSession {
|
|
|
1379
1508
|
exposure: this._getToolExposure(definition.name),
|
|
1380
1509
|
...(definition.namespace ? { namespace: definition.namespace } : {}),
|
|
1381
1510
|
...(definition.annotations ? { annotations: { ...definition.annotations } } : {}),
|
|
1511
|
+
...(definition.reachesTools ? { reachesTools: definition.reachesTools } : {}),
|
|
1382
1512
|
sourceInfo,
|
|
1383
1513
|
}));
|
|
1384
1514
|
}
|
|
@@ -1672,8 +1802,32 @@ export class AgentSession {
|
|
|
1672
1802
|
// =========================================================================
|
|
1673
1803
|
// Prompting
|
|
1674
1804
|
// =========================================================================
|
|
1675
|
-
|
|
1805
|
+
/**
|
|
1806
|
+
* Start a run from a user or custom message. The session counts as busy from here on, so
|
|
1807
|
+
* messages sent while before_agent_start handlers run are queued into this run instead of
|
|
1808
|
+
* starting another, and an abort requested meanwhile aborts the run as soon as it exists.
|
|
1809
|
+
* @param onStarted Called once the run's messages are prepared, before the first request.
|
|
1810
|
+
* @param autoEffortText Raw interactive input the automatic effort judge sees for a user trigger.
|
|
1811
|
+
*/
|
|
1812
|
+
async _startRun(trigger, onStarted, autoEffortText) {
|
|
1813
|
+
this._isAgentRunActive = true;
|
|
1676
1814
|
this._agentRunAbortRequested = false;
|
|
1815
|
+
let messages;
|
|
1816
|
+
try {
|
|
1817
|
+
messages = await this._prepareRun(trigger, autoEffortText);
|
|
1818
|
+
}
|
|
1819
|
+
catch (error) {
|
|
1820
|
+
this._isAgentRunActive = false;
|
|
1821
|
+
this._flushPendingBashMessages();
|
|
1822
|
+
this._flushPendingCustomMessages();
|
|
1823
|
+
this._resolveIdleWaitIfIdle();
|
|
1824
|
+
throw error;
|
|
1825
|
+
}
|
|
1826
|
+
// Messages held while the run was starting go before its starting messages, as they would
|
|
1827
|
+
// have while idle. No run exists yet, so they cannot split a tool call from its result.
|
|
1828
|
+
this._flushPendingBashMessages();
|
|
1829
|
+
this._flushPendingCustomMessages();
|
|
1830
|
+
onStarted?.();
|
|
1677
1831
|
const runAbortController = new AbortController();
|
|
1678
1832
|
this._agentRunAbortController = runAbortController;
|
|
1679
1833
|
// Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
|
|
@@ -1705,9 +1859,8 @@ export class AgentSession {
|
|
|
1705
1859
|
this._oauthPoolWarmupFailed = true;
|
|
1706
1860
|
}
|
|
1707
1861
|
}
|
|
1708
|
-
//
|
|
1709
|
-
|
|
1710
|
-
await this._observeRequests("chat", () => this.agent.prompt(messages));
|
|
1862
|
+
// agent_start applies an abort requested during preparation or warm-up before any provider request.
|
|
1863
|
+
await this._observeRequests("chat", () => this.agent.prompt(messages));
|
|
1711
1864
|
while (!this._agentRunAbortRequested) {
|
|
1712
1865
|
if (await this._handlePostAgentRun()) {
|
|
1713
1866
|
if (this._agentRunAbortRequested)
|
|
@@ -1734,6 +1887,66 @@ export class AgentSession {
|
|
|
1734
1887
|
await this._emitAgentSettled();
|
|
1735
1888
|
}
|
|
1736
1889
|
}
|
|
1890
|
+
/**
|
|
1891
|
+
* Prepare a run and return its starting messages: compact first when needed, emit
|
|
1892
|
+
* before_agent_start, apply the run's prompt options and tool loadout, and build the starting
|
|
1893
|
+
* message followed by pending nextTurn messages (consumed here) and handler messages, with a
|
|
1894
|
+
* system patch first when the prompt changed.
|
|
1895
|
+
*/
|
|
1896
|
+
async _prepareRun(trigger, autoEffortText) {
|
|
1897
|
+
// Check if we need to compact before sending (catches aborted responses).
|
|
1898
|
+
// The starting message is sent below, so do not call agent.continue() here.
|
|
1899
|
+
const lastAssistant = this._findLastAssistantMessage();
|
|
1900
|
+
if (lastAssistant) {
|
|
1901
|
+
await this._checkCompaction(lastAssistant, false);
|
|
1902
|
+
}
|
|
1903
|
+
const selectedToolsBefore = this._baseSystemPromptOptions.selectedTools;
|
|
1904
|
+
const result = await this._extensionRunner.emitBeforeAgentStart(trigger, this._baseSystemPromptOptions);
|
|
1905
|
+
// Handlers may edit event.systemPromptOptions.selectedTools or call setActiveTools(),
|
|
1906
|
+
// which updates the live loadout instead. An explicit edit wins; otherwise the live
|
|
1907
|
+
// loadout is authoritative, so a setActiveTools() call is not undone here.
|
|
1908
|
+
const handlerEditedTools = result.systemPromptOptions.selectedTools.length !== selectedToolsBefore.length ||
|
|
1909
|
+
result.systemPromptOptions.selectedTools.some((name, index) => name !== selectedToolsBefore[index]);
|
|
1910
|
+
if (!handlerEditedTools)
|
|
1911
|
+
result.systemPromptOptions.selectedTools = this.getActiveToolNames();
|
|
1912
|
+
const messages = [];
|
|
1913
|
+
if (trigger.messageType === "custom") {
|
|
1914
|
+
messages.push(trigger.message);
|
|
1915
|
+
}
|
|
1916
|
+
else {
|
|
1917
|
+
// Normalize images after before_agent_start so extension-driven model selection
|
|
1918
|
+
// determines the resize profile used for the request and history.
|
|
1919
|
+
const normalized = await this._normalizePromptImages(trigger.images);
|
|
1920
|
+
const text = normalized.hints.length > 0 ? `${trigger.prompt}\n\n${normalized.hints.join("\n")}` : trigger.prompt;
|
|
1921
|
+
const userMessage = {
|
|
1922
|
+
role: "user",
|
|
1923
|
+
content: [{ type: "text", text }, ...normalized.images],
|
|
1924
|
+
timestamp: Date.now(),
|
|
1925
|
+
};
|
|
1926
|
+
if (autoEffortText !== undefined)
|
|
1927
|
+
this._autoEffortInputs.set(userMessage, autoEffortText);
|
|
1928
|
+
messages.push(userMessage);
|
|
1929
|
+
}
|
|
1930
|
+
// Inject any pending "nextTurn" messages as context alongside the starting message
|
|
1931
|
+
messages.push(...this._pendingNextTurnMessages);
|
|
1932
|
+
this._pendingNextTurnMessages = [];
|
|
1933
|
+
for (const msg of result.messages) {
|
|
1934
|
+
messages.push({
|
|
1935
|
+
role: "custom",
|
|
1936
|
+
customType: msg.customType,
|
|
1937
|
+
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1938
|
+
content: msg.content ?? [],
|
|
1939
|
+
display: msg.display,
|
|
1940
|
+
details: msg.details,
|
|
1941
|
+
timestamp: Date.now(),
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
const updateMessage = this._preparePromptAndToolLoadout(result.systemPromptOptions);
|
|
1945
|
+
this._runSystemPromptOptions = result.systemPromptOptions;
|
|
1946
|
+
if (updateMessage)
|
|
1947
|
+
messages.unshift(updateMessage);
|
|
1948
|
+
return messages;
|
|
1949
|
+
}
|
|
1737
1950
|
async _handlePostAgentRun() {
|
|
1738
1951
|
const message = this._lastAssistantMessage;
|
|
1739
1952
|
const toolResults = this._lastAssistantToolResults;
|
|
@@ -1883,17 +2096,14 @@ export class AgentSession {
|
|
|
1883
2096
|
throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
|
|
1884
2097
|
}
|
|
1885
2098
|
if (options.streamingBehavior === "followUp") {
|
|
1886
|
-
await this._queueFollowUp(expandedText, currentImages);
|
|
2099
|
+
await this._queueFollowUp(expandedText, currentImages, (options?.source ?? "interactive") === "interactive" ? currentText : undefined);
|
|
1887
2100
|
}
|
|
1888
2101
|
else {
|
|
1889
|
-
await this._queueSteer(expandedText, currentImages);
|
|
2102
|
+
await this._queueSteer(expandedText, currentImages, (options?.source ?? "interactive") === "interactive" ? currentText : undefined);
|
|
1890
2103
|
}
|
|
1891
2104
|
preflightResult?.("queued");
|
|
1892
2105
|
return;
|
|
1893
2106
|
}
|
|
1894
|
-
// Flush any pending bash and custom messages before the new prompt
|
|
1895
|
-
this._flushPendingBashMessages();
|
|
1896
|
-
this._flushPendingCustomMessages();
|
|
1897
2107
|
// Validate model
|
|
1898
2108
|
if (!this.model) {
|
|
1899
2109
|
throw new Error(formatNoModelSelectedMessage());
|
|
@@ -1909,56 +2119,7 @@ export class AgentSession {
|
|
|
1909
2119
|
}
|
|
1910
2120
|
throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
|
|
1911
2121
|
}
|
|
1912
|
-
|
|
1913
|
-
// The user's new prompt is sent below, so do not call agent.continue() here.
|
|
1914
|
-
const lastAssistant = this._findLastAssistantMessage();
|
|
1915
|
-
if (lastAssistant) {
|
|
1916
|
-
await this._checkCompaction(lastAssistant, false);
|
|
1917
|
-
}
|
|
1918
|
-
// Emit before_agent_start before normalizing images so extension-driven model
|
|
1919
|
-
// selection determines the resize profile used for the request and history.
|
|
1920
|
-
const selectedToolsBefore = this._baseSystemPromptOptions.selectedTools;
|
|
1921
|
-
const result = await this._extensionRunner.emitBeforeAgentStart(expandedText, currentImages, this._baseSystemPromptOptions);
|
|
1922
|
-
// Handlers may edit event.systemPromptOptions.selectedTools or call setActiveTools(),
|
|
1923
|
-
// which updates the live loadout instead. An explicit edit wins; otherwise the live
|
|
1924
|
-
// loadout is authoritative, so a setActiveTools() call is not undone here.
|
|
1925
|
-
const handlerEditedTools = result.systemPromptOptions.selectedTools.length !== selectedToolsBefore.length ||
|
|
1926
|
-
result.systemPromptOptions.selectedTools.some((name, index) => name !== selectedToolsBefore[index]);
|
|
1927
|
-
if (!handlerEditedTools)
|
|
1928
|
-
result.systemPromptOptions.selectedTools = this.getActiveToolNames();
|
|
1929
|
-
const normalized = await this._normalizePromptImages(currentImages);
|
|
1930
|
-
const userText = normalized.hints.length > 0 ? `${expandedText}\n\n${normalized.hints.join("\n")}` : expandedText;
|
|
1931
|
-
// Build messages only after hooks and image normalization have completed.
|
|
1932
|
-
const messages = [];
|
|
1933
|
-
const userContent = [{ type: "text", text: userText }];
|
|
1934
|
-
userContent.push(...normalized.images);
|
|
1935
|
-
messages.push({
|
|
1936
|
-
role: "user",
|
|
1937
|
-
content: userContent,
|
|
1938
|
-
timestamp: Date.now(),
|
|
1939
|
-
});
|
|
1940
|
-
// Inject any pending "nextTurn" messages as context alongside the user message
|
|
1941
|
-
for (const msg of this._pendingNextTurnMessages) {
|
|
1942
|
-
messages.push(msg);
|
|
1943
|
-
}
|
|
1944
|
-
this._pendingNextTurnMessages = [];
|
|
1945
|
-
for (const msg of result.messages) {
|
|
1946
|
-
messages.push({
|
|
1947
|
-
role: "custom",
|
|
1948
|
-
customType: msg.customType,
|
|
1949
|
-
// Untyped extensions can pass null/missing content; normalize at ingestion.
|
|
1950
|
-
content: msg.content ?? [],
|
|
1951
|
-
display: msg.display,
|
|
1952
|
-
details: msg.details,
|
|
1953
|
-
timestamp: Date.now(),
|
|
1954
|
-
});
|
|
1955
|
-
}
|
|
1956
|
-
const updateMessage = this._preparePromptAndToolLoadout(result.systemPromptOptions);
|
|
1957
|
-
this._runSystemPromptOptions = result.systemPromptOptions;
|
|
1958
|
-
if (updateMessage)
|
|
1959
|
-
messages.unshift(updateMessage);
|
|
1960
|
-
preflightResult?.("started");
|
|
1961
|
-
await this._runAgentPrompt(messages);
|
|
2122
|
+
await this._startRun({ messageType: "user", prompt: expandedText, images: currentImages }, () => preflightResult?.("started"), (options?.source ?? "interactive") === "interactive" ? currentText : undefined);
|
|
1962
2123
|
}
|
|
1963
2124
|
/**
|
|
1964
2125
|
* Try to execute an extension command. Returns true if command was found and executed.
|
|
@@ -2027,10 +2188,10 @@ export class AgentSession {
|
|
|
2027
2188
|
let expandedText = this._expandSkillCommand(processedInput.text);
|
|
2028
2189
|
expandedText = expandPromptTemplate(expandedText, [...this.promptTemplates]);
|
|
2029
2190
|
if (behavior === "steer") {
|
|
2030
|
-
await this._queueSteer(expandedText, processedInput.images);
|
|
2191
|
+
await this._queueSteer(expandedText, processedInput.images, source === "interactive" ? processedInput.text : undefined);
|
|
2031
2192
|
}
|
|
2032
2193
|
else {
|
|
2033
|
-
await this._queueFollowUp(expandedText, processedInput.images);
|
|
2194
|
+
await this._queueFollowUp(expandedText, processedInput.images, source === "interactive" ? processedInput.text : undefined);
|
|
2034
2195
|
}
|
|
2035
2196
|
return "queued";
|
|
2036
2197
|
}
|
|
@@ -2116,30 +2277,32 @@ export class AgentSession {
|
|
|
2116
2277
|
/**
|
|
2117
2278
|
* Internal: Queue a steering message (already expanded, no extension command check).
|
|
2118
2279
|
*/
|
|
2119
|
-
async _queueSteer(text, images) {
|
|
2280
|
+
async _queueSteer(text, images, autoEffortText) {
|
|
2120
2281
|
this._steeringMessages.push(text);
|
|
2121
2282
|
this._emitQueueUpdate();
|
|
2122
2283
|
const content = [{ type: "text", text }];
|
|
2123
2284
|
if (images) {
|
|
2124
2285
|
content.push(...images);
|
|
2125
2286
|
}
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
});
|
|
2287
|
+
const message = { role: "user", content, timestamp: Date.now() };
|
|
2288
|
+
if (autoEffortText !== undefined)
|
|
2289
|
+
this._autoEffortInputs.set(message, autoEffortText);
|
|
2290
|
+
this.agent.steer(message);
|
|
2131
2291
|
}
|
|
2132
2292
|
/**
|
|
2133
2293
|
* Internal: Queue a follow-up message (already expanded, no extension command check).
|
|
2134
2294
|
*/
|
|
2135
|
-
async _queueFollowUp(text, images) {
|
|
2295
|
+
async _queueFollowUp(text, images, autoEffortText) {
|
|
2136
2296
|
this._followUpMessages.push(text);
|
|
2137
2297
|
this._emitQueueUpdate();
|
|
2138
2298
|
const content = [{ type: "text", text }];
|
|
2139
2299
|
if (images) {
|
|
2140
2300
|
content.push(...images);
|
|
2141
2301
|
}
|
|
2142
|
-
|
|
2302
|
+
const message = { role: "user", content, timestamp: Date.now() };
|
|
2303
|
+
if (autoEffortText !== undefined)
|
|
2304
|
+
this._autoEffortInputs.set(message, autoEffortText);
|
|
2305
|
+
this.agent.followUp(message);
|
|
2143
2306
|
}
|
|
2144
2307
|
/**
|
|
2145
2308
|
* Throw an error if the text is an extension command.
|
|
@@ -2188,10 +2351,10 @@ export class AgentSession {
|
|
|
2188
2351
|
}
|
|
2189
2352
|
else if (options?.triggerTurn) {
|
|
2190
2353
|
if (this._isEmittingAgentSettled) {
|
|
2191
|
-
this._deferredSettledActions.push(async () => await this.
|
|
2354
|
+
this._deferredSettledActions.push(async () => await this.sendCustomMessage(message, options));
|
|
2192
2355
|
return;
|
|
2193
2356
|
}
|
|
2194
|
-
await this.
|
|
2357
|
+
await this._startRun({ messageType: "custom", message: appMessage });
|
|
2195
2358
|
}
|
|
2196
2359
|
else if (this.isStreaming) {
|
|
2197
2360
|
// Appending now would put the message between an assistant tool call and its
|
|
@@ -2437,7 +2600,28 @@ export class AgentSession {
|
|
|
2437
2600
|
* Saves the clamped level to the session transcript only if the level actually changes.
|
|
2438
2601
|
* Persists the requested level to global defaults only when options.persist is true.
|
|
2439
2602
|
*/
|
|
2603
|
+
get autoEffortEnabled() {
|
|
2604
|
+
return (getAutoEffortSessionOverride(this.sessionManager.getEntries(), this.sessionManager.getSessionId()) ??
|
|
2605
|
+
this.settingsManager.getAutoEffortEnabled());
|
|
2606
|
+
}
|
|
2607
|
+
setAutoEffortSessionEnabled(enabled) {
|
|
2608
|
+
this._autoEffortController?.abort();
|
|
2609
|
+
const id = this.sessionManager.appendCustomEntry(AUTO_EFFORT_ENTRY_TYPE, {
|
|
2610
|
+
version: 1,
|
|
2611
|
+
sessionId: this.sessionManager.getSessionId(),
|
|
2612
|
+
enabled,
|
|
2613
|
+
});
|
|
2614
|
+
const entry = this.sessionManager.getEntry(id);
|
|
2615
|
+
if (entry)
|
|
2616
|
+
this._emit({ type: "entry_appended", entry });
|
|
2617
|
+
}
|
|
2618
|
+
setManualThinkingLevel(level, options = {}) {
|
|
2619
|
+
this.setAutoEffortSessionEnabled(false);
|
|
2620
|
+
this.setThinkingLevel(level, options);
|
|
2621
|
+
}
|
|
2440
2622
|
setThinkingLevel(level, options = {}) {
|
|
2623
|
+
this._thinkingSelectionRevision++;
|
|
2624
|
+
this._autoEffortController?.abort();
|
|
2441
2625
|
const availableLevels = this.getAvailableThinkingLevels();
|
|
2442
2626
|
const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
|
|
2443
2627
|
// Only persist if actually changing
|
|
@@ -2529,11 +2713,11 @@ export class AgentSession {
|
|
|
2529
2713
|
// Compaction
|
|
2530
2714
|
// =========================================================================
|
|
2531
2715
|
/** Generate Pi's built-in compaction summary for manual and automatic compaction. */
|
|
2532
|
-
async _runDefaultCompaction(preparation, model, customInstructions, signal, reason) {
|
|
2716
|
+
async _runDefaultCompaction(preparation, model, customInstructions, signal, reason, usageEntryIds) {
|
|
2533
2717
|
// Resolve the request only when Pi summarizes itself: routing may call models or fail.
|
|
2534
2718
|
return this._observeRequests("compaction", async () => {
|
|
2535
2719
|
const request = await this._getSummarizationRequestAuth(model, signal);
|
|
2536
|
-
return compact(preparation, request.model, request.apiKey, request.headers, customInstructions, signal, request.thinkingLevel, this._auxiliaryStreamFunction, request.env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }), undefined);
|
|
2720
|
+
return compact(preparation, request.model, request.apiKey, request.headers, customInstructions, signal, request.thinkingLevel, this._auxiliaryStreamFunction, request.env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }, usageEntryIds), undefined);
|
|
2537
2721
|
});
|
|
2538
2722
|
}
|
|
2539
2723
|
_clearManualCompactionState() {
|
|
@@ -2561,6 +2745,7 @@ export class AgentSession {
|
|
|
2561
2745
|
this._emit({ type: "compaction_start", reason: "manual" });
|
|
2562
2746
|
let fromExtension = false;
|
|
2563
2747
|
let cancelledByExtension = false;
|
|
2748
|
+
const usageEntryIds = [];
|
|
2564
2749
|
try {
|
|
2565
2750
|
const model = this.model;
|
|
2566
2751
|
if (!model) {
|
|
@@ -2612,7 +2797,7 @@ export class AgentSession {
|
|
|
2612
2797
|
}
|
|
2613
2798
|
else {
|
|
2614
2799
|
// Shared default summary generator, also used by automatic compaction.
|
|
2615
|
-
const result = await this._runDefaultCompaction(preparation, model, customInstructions, this._compactionAbortController.signal, "manual");
|
|
2800
|
+
const result = await this._runDefaultCompaction(preparation, model, customInstructions, this._compactionAbortController.signal, "manual", usageEntryIds);
|
|
2616
2801
|
summary = result.summary;
|
|
2617
2802
|
firstKeptEntryId = result.firstKeptEntryId;
|
|
2618
2803
|
tokensBefore = result.tokensBefore;
|
|
@@ -2622,7 +2807,7 @@ export class AgentSession {
|
|
|
2622
2807
|
if (this._compactionAbortController.signal.aborted) {
|
|
2623
2808
|
throw new Error("Compaction cancelled");
|
|
2624
2809
|
}
|
|
2625
|
-
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
|
|
2810
|
+
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage, usageEntryIds.length ? usageEntryIds : undefined);
|
|
2626
2811
|
const newEntries = this.sessionManager.getEntries();
|
|
2627
2812
|
this._refreshFinalizedContext();
|
|
2628
2813
|
const estimatedTokensAfter = estimateMessagesTokens(this.sessionManager.buildSessionProjection().messages);
|
|
@@ -2643,6 +2828,7 @@ export class AgentSession {
|
|
|
2643
2828
|
tokensBefore,
|
|
2644
2829
|
estimatedTokensAfter,
|
|
2645
2830
|
usage,
|
|
2831
|
+
...(usageEntryIds.length ? { usageEntryIds: [...usageEntryIds] } : {}),
|
|
2646
2832
|
details,
|
|
2647
2833
|
};
|
|
2648
2834
|
// compaction_end listeners may submit queued prompts, so expose idle state before notifying them.
|
|
@@ -2658,13 +2844,16 @@ export class AgentSession {
|
|
|
2658
2844
|
}
|
|
2659
2845
|
catch (error) {
|
|
2660
2846
|
const message = error instanceof Error ? error.message : String(error);
|
|
2661
|
-
const aborted = this._compactionAbortController.signal.aborted ||
|
|
2847
|
+
const aborted = this._compactionAbortController.signal.aborted ||
|
|
2848
|
+
cancelledByExtension ||
|
|
2849
|
+
error instanceof SummarizationAbortedError;
|
|
2662
2850
|
const errorMessage = aborted ? undefined : `Compaction failed: ${message}`;
|
|
2663
2851
|
this._clearManualCompactionState();
|
|
2664
2852
|
this._emit({
|
|
2665
2853
|
type: "compaction_end",
|
|
2666
2854
|
reason: "manual",
|
|
2667
2855
|
result: undefined,
|
|
2856
|
+
...(usageEntryIds.length ? { usageEntryIds: [...usageEntryIds] } : {}),
|
|
2668
2857
|
aborted,
|
|
2669
2858
|
willRetry: false,
|
|
2670
2859
|
errorMessage,
|
|
@@ -2853,6 +3042,7 @@ export class AgentSession {
|
|
|
2853
3042
|
let started = false;
|
|
2854
3043
|
let fromExtension = false;
|
|
2855
3044
|
let cancelledByExtension = false;
|
|
3045
|
+
const usageEntryIds = [];
|
|
2856
3046
|
try {
|
|
2857
3047
|
if (!model) {
|
|
2858
3048
|
return false;
|
|
@@ -2903,7 +3093,7 @@ export class AgentSession {
|
|
|
2903
3093
|
}
|
|
2904
3094
|
else {
|
|
2905
3095
|
// Shared default summary generator, also used by manual compaction.
|
|
2906
|
-
const compactResult = await this._runDefaultCompaction(preparation, model, undefined, abortController.signal, reason);
|
|
3096
|
+
const compactResult = await this._runDefaultCompaction(preparation, model, undefined, abortController.signal, reason, usageEntryIds);
|
|
2907
3097
|
summary = compactResult.summary;
|
|
2908
3098
|
firstKeptEntryId = compactResult.firstKeptEntryId;
|
|
2909
3099
|
tokensBefore = compactResult.tokensBefore;
|
|
@@ -2911,7 +3101,7 @@ export class AgentSession {
|
|
|
2911
3101
|
details = compactResult.details;
|
|
2912
3102
|
}
|
|
2913
3103
|
abortController.signal.throwIfAborted();
|
|
2914
|
-
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
|
|
3104
|
+
this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage, usageEntryIds.length ? usageEntryIds : undefined);
|
|
2915
3105
|
const newEntries = this.sessionManager.getEntries();
|
|
2916
3106
|
this._refreshFinalizedContext();
|
|
2917
3107
|
const estimatedTokensAfter = estimateMessagesTokens(this.sessionManager.buildSessionProjection().messages);
|
|
@@ -2932,6 +3122,7 @@ export class AgentSession {
|
|
|
2932
3122
|
tokensBefore,
|
|
2933
3123
|
estimatedTokensAfter,
|
|
2934
3124
|
usage,
|
|
3125
|
+
...(usageEntryIds.length ? { usageEntryIds: [...usageEntryIds] } : {}),
|
|
2935
3126
|
details,
|
|
2936
3127
|
};
|
|
2937
3128
|
this._emit({ type: "compaction_end", reason, result, aborted: false, willRetry });
|
|
@@ -2943,7 +3134,9 @@ export class AgentSession {
|
|
|
2943
3134
|
}
|
|
2944
3135
|
catch (error) {
|
|
2945
3136
|
const message = error instanceof Error ? error.message : "compaction failed";
|
|
2946
|
-
const aborted = abortController?.signal.aborted === true ||
|
|
3137
|
+
const aborted = abortController?.signal.aborted === true ||
|
|
3138
|
+
cancelledByExtension ||
|
|
3139
|
+
error instanceof SummarizationAbortedError;
|
|
2947
3140
|
if (started) {
|
|
2948
3141
|
const errorMessage = aborted
|
|
2949
3142
|
? undefined
|
|
@@ -2954,6 +3147,7 @@ export class AgentSession {
|
|
|
2954
3147
|
type: "compaction_end",
|
|
2955
3148
|
reason,
|
|
2956
3149
|
result: undefined,
|
|
3150
|
+
...(usageEntryIds.length ? { usageEntryIds: [...usageEntryIds] } : {}),
|
|
2957
3151
|
aborted,
|
|
2958
3152
|
willRetry: false,
|
|
2959
3153
|
errorMessage,
|
|
@@ -3381,11 +3575,17 @@ export class AgentSession {
|
|
|
3381
3575
|
* stream drop no longer fails the whole operation. `source` carries the context
|
|
3382
3576
|
* the TUI needs to render the retry and recreate the underlying indicator.
|
|
3383
3577
|
*/
|
|
3384
|
-
_summarizationRetryCallbacks(source) {
|
|
3578
|
+
_summarizationRetryCallbacks(source, usageEntryIds) {
|
|
3385
3579
|
return {
|
|
3580
|
+
onUsage: (usage, provider, model) => {
|
|
3581
|
+
const entry = this.sessionManager.appendUsage(source.source, provider, model, usage);
|
|
3582
|
+
usageEntryIds.push(entry.id);
|
|
3583
|
+
this._emit({ type: "entry_appended", entry });
|
|
3584
|
+
},
|
|
3386
3585
|
onRetryScheduled: (attempt, maxAttempts, delayMs, errorMessage) => {
|
|
3387
3586
|
this._emit({
|
|
3388
3587
|
type: "summarization_retry_scheduled",
|
|
3588
|
+
usageEntryIds: [...usageEntryIds],
|
|
3389
3589
|
attempt,
|
|
3390
3590
|
maxAttempts,
|
|
3391
3591
|
delayMs,
|
|
@@ -3393,10 +3593,11 @@ export class AgentSession {
|
|
|
3393
3593
|
});
|
|
3394
3594
|
},
|
|
3395
3595
|
onRetryAttemptStart: () => {
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3596
|
+
if (source.source !== "bugReport")
|
|
3597
|
+
this._emit({
|
|
3598
|
+
type: "summarization_retry_attempt_start",
|
|
3599
|
+
...source,
|
|
3600
|
+
});
|
|
3400
3601
|
},
|
|
3401
3602
|
onRetryFinished: () => {
|
|
3402
3603
|
this._emit({ type: "summarization_retry_finished" });
|
|
@@ -4339,6 +4540,7 @@ export class AgentSession {
|
|
|
4339
4540
|
let summaryText;
|
|
4340
4541
|
let summaryDetails;
|
|
4341
4542
|
let summaryUsage;
|
|
4543
|
+
const usageEntryIds = [];
|
|
4342
4544
|
if (options.summarize && entriesToSummarize.length > 0 && !extensionSummary) {
|
|
4343
4545
|
const signal = this._branchSummaryAbortController.signal;
|
|
4344
4546
|
const branchSummarySettings = this.settingsManager.getBranchSummarySettings();
|
|
@@ -4350,7 +4552,7 @@ export class AgentSession {
|
|
|
4350
4552
|
reserveTokens: branchSummarySettings.reserveTokens,
|
|
4351
4553
|
streamFn: this._auxiliaryStreamFunction,
|
|
4352
4554
|
retry: this.settingsManager.getRetrySettings(),
|
|
4353
|
-
callbacks: this._summarizationRetryCallbacks({ source: "branchSummary" }),
|
|
4555
|
+
callbacks: this._summarizationRetryCallbacks({ source: "branchSummary" }, usageEntryIds),
|
|
4354
4556
|
}));
|
|
4355
4557
|
if (result.aborted) {
|
|
4356
4558
|
return { cancelled: true, aborted: true };
|
|
@@ -4392,7 +4594,7 @@ export class AgentSession {
|
|
|
4392
4594
|
let summaryEntry;
|
|
4393
4595
|
if (summaryText) {
|
|
4394
4596
|
// Create summary at target position (can be null for root)
|
|
4395
|
-
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension, summaryUsage);
|
|
4597
|
+
const summaryId = this.sessionManager.branchWithSummary(newLeafId, summaryText, summaryDetails, fromExtension, summaryUsage, usageEntryIds.length ? usageEntryIds : undefined);
|
|
4396
4598
|
summaryEntry = this.sessionManager.getEntry(summaryId);
|
|
4397
4599
|
// Attach label to the summary entry
|
|
4398
4600
|
if (label) {
|
|
@@ -4460,13 +4662,10 @@ export class AgentSession {
|
|
|
4460
4662
|
let totalMessages = 0;
|
|
4461
4663
|
let toolCalls = 0;
|
|
4462
4664
|
const usageTotals = createUsageTotals();
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
else if ((entry.type === "branch_summary" || entry.type === "compaction") && entry.usage) {
|
|
4468
|
-
addUsageToTotals(usageTotals, entry.usage);
|
|
4469
|
-
}
|
|
4665
|
+
const entries = this.sessionManager.getEntries();
|
|
4666
|
+
for (const { usage } of getSessionUsage(entries))
|
|
4667
|
+
addUsageToTotals(usageTotals, usage);
|
|
4668
|
+
for (const entry of entries) {
|
|
4470
4669
|
if (entry.type !== "message")
|
|
4471
4670
|
continue;
|
|
4472
4671
|
totalMessages++;
|
|
@@ -4476,9 +4675,6 @@ export class AgentSession {
|
|
|
4476
4675
|
}
|
|
4477
4676
|
else if (message.role === "toolResult") {
|
|
4478
4677
|
toolResults++;
|
|
4479
|
-
if (message.usage) {
|
|
4480
|
-
addUsageToTotals(usageTotals, message.usage);
|
|
4481
|
-
}
|
|
4482
4678
|
}
|
|
4483
4679
|
else if (message.role === "assistant") {
|
|
4484
4680
|
assistantMessages++;
|
|
@@ -4486,7 +4682,6 @@ export class AgentSession {
|
|
|
4486
4682
|
if (Array.isArray(assistantMsg.content)) {
|
|
4487
4683
|
toolCalls += assistantMsg.content.filter((c) => c.type === "toolCall").length;
|
|
4488
4684
|
}
|
|
4489
|
-
addUsageToTotals(usageTotals, assistantMsg.usage);
|
|
4490
4685
|
}
|
|
4491
4686
|
}
|
|
4492
4687
|
return {
|
|
@@ -4519,24 +4714,9 @@ export class AgentSession {
|
|
|
4519
4714
|
// After compaction, the last assistant usage reflects pre-compaction context size.
|
|
4520
4715
|
// We can only trust usage from an assistant that responded after the latest compaction.
|
|
4521
4716
|
// If no such assistant exists, context token count is unknown until the next LLM response.
|
|
4522
|
-
const
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
if (latestCompaction) {
|
|
4526
|
-
const projectedAssistants = new Set(projection.entries.flatMap((entry) => entry.messages.some((message) => message.role === "assistant" &&
|
|
4527
|
-
message.stopReason !== "aborted" &&
|
|
4528
|
-
message.stopReason !== "error" &&
|
|
4529
|
-
calculateContextTokens(message.usage) > 0)
|
|
4530
|
-
? [entry.sourceEntry.id]
|
|
4531
|
-
: []));
|
|
4532
|
-
const compactionIndex = branch.findIndex((entry) => entry.id === latestCompaction.id);
|
|
4533
|
-
const hasPostCompactionUsage = branch
|
|
4534
|
-
.slice(compactionIndex + 1)
|
|
4535
|
-
.some((entry) => projectedAssistants.has(entry.id));
|
|
4536
|
-
if (!hasPostCompactionUsage)
|
|
4537
|
-
return { tokens: null, contextWindow, percent: null };
|
|
4538
|
-
}
|
|
4539
|
-
const estimate = estimateProjectedContextTokens(projection, branch);
|
|
4717
|
+
const estimate = this._contextTokenEstimate();
|
|
4718
|
+
if (!estimate.knownAfterCompaction)
|
|
4719
|
+
return { tokens: null, contextWindow, percent: null };
|
|
4540
4720
|
const percent = (estimate.tokens / contextWindow) * 100;
|
|
4541
4721
|
return {
|
|
4542
4722
|
tokens: estimate.tokens,
|
|
@@ -4590,6 +4770,7 @@ export class AgentSession {
|
|
|
4590
4770
|
streamFn: this._auxiliaryStreamFunction,
|
|
4591
4771
|
retry: this.settingsManager.getRetrySettings(),
|
|
4592
4772
|
sessionId: this.sessionId,
|
|
4773
|
+
callbacks: this._summarizationRetryCallbacks({ source: "bugReport" }, []),
|
|
4593
4774
|
}));
|
|
4594
4775
|
}
|
|
4595
4776
|
// =========================================================================
|