@pensar/apex 2.6.1 → 2.7.0-canary.1572d9a4
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/build/{agent-ayreaj6z.js → agent-3g1b578v.js} +6 -5
- package/build/{agent-yby11zaq.js → agent-p8cezgbb.js} +7 -6
- package/build/{agent-runs-g37vkrjr.js → agent-runs-f86emmgg.js} +23 -20
- package/build/agent-vaq31je6.js +14 -0
- package/build/agent-vvdqga09.js +14 -0
- package/build/{apps-xn6km9yn.js → apps-3stwnmen.js} +16 -13
- package/build/{auth-d105wc64.js → auth-7md9kwda.js} +16 -13
- package/build/blackboxAgent-ct8bejef.js +14 -0
- package/build/{blackboxPentest-ps78v3w7.js → blackboxPentest-w2nr4md3.js} +21 -15
- package/build/{cli-c05y640n.js → cli-1j28cbhy.js} +1 -1
- package/build/{cli-d37a42dc.js → cli-2jz2jz06.js} +206 -90
- package/build/{cli-az3xq70v.js → cli-4a8dsz2k.js} +4 -4
- package/build/{cli-qgz1q9g5.js → cli-58781vcf.js} +1192 -1473
- package/build/{cli-gx71jcke.js → cli-7067zzeb.js} +1 -1
- package/build/{cli-3sp6nd8d.js → cli-81smmd5w.js} +5 -5
- package/build/{cli-k2nwxta0.js → cli-8b25dhky.js} +2 -2
- package/build/{cli-fy6vh2a7.js → cli-8sw5zpqz.js} +1 -1
- package/build/{cli-709rvekb.js → cli-cg3ypx5n.js} +14 -7
- package/build/{cli-dpsw2fe6.js → cli-e9v6zg6h.js} +40941 -40172
- package/build/cli-fjxmphg1.js +36 -0
- package/build/{cli-7eea4e2y.js → cli-gzb6qrzh.js} +31 -60
- package/build/{cli-65g6rcat.js → cli-khnf5xrf.js} +2 -1
- package/build/{cli-1ve18npr.js → cli-mdzt2e8j.js} +4 -2
- package/build/{cli-n2en7j5b.js → cli-n8mmw4c4.js} +1 -1
- package/build/cli-pndb7mh9.js +1193 -0
- package/build/cli-px6ehzqx.js +54 -0
- package/build/{cli-xtc2t6me.js → cli-qs4msn6x.js} +111 -47
- package/build/{cli-kb21qhvm.js → cli-rvybdhgn.js} +4 -3
- package/build/{cli-ae8jqxqr.js → cli-v739h7hb.js} +2 -2
- package/build/{cli-ngq9dr8n.js → cli-wm8ech0x.js} +3 -3
- package/build/cli.js +170 -51
- package/build/{config-zpqkd5cz.js → config-e5v1bkh1.js} +1 -1
- package/build/{fastStrike-mcjdvwez.js → fastStrike-efp0rjs3.js} +74 -17
- package/build/{fixes-kytx5dmj.js → fixes-926cw1ej.js} +16 -13
- package/build/{index-n65z6v7b.js → index-3t41p258.js} +7 -6
- package/build/{index-qv4cc65p.js → index-bv09af6g.js} +19 -15
- package/build/{index-je6hcsqr.js → index-bv6dtwse.js} +1 -1
- package/build/{index-4vqdgb42.js → index-jt52ffgn.js} +1657 -1400
- package/build/{index-ns4m4s01.js → index-np405b9e.js} +11 -7
- package/build/{index-r9yjkfrv.js → index-qys178kp.js} +5 -4
- package/build/{index-wqetp6gq.js → index-tpyzq2wq.js} +42 -11
- package/build/{index-fv64eb32.js → index-vrcdyebh.js} +2 -2
- package/build/{index-dr3tg1w3.js → index-z1g8vbtm.js} +1 -1
- package/build/{issues-eb3q9d3a.js → issues-sncyqh14.js} +16 -13
- package/build/{knowledge-fqsvtx0f.js → knowledge-esgvy5ws.js} +16 -13
- package/build/lance-sacfgs1z.js +232 -0
- package/build/lib/{chunk-9yksqgzr.js → chunk-4aevegnc.js} +77 -45
- package/build/lib/{chunk-9tt2021m.js → chunk-4kf4a15q.js} +13 -13
- package/build/lib/{chunk-fy3bbbqy.js → chunk-5avnedwm.js} +7 -1
- package/build/lib/{chunk-bb0ekhkw.js → chunk-5nz5tk3p.js} +76 -22
- package/build/lib/{chunk-4hwzqthr.js → chunk-7s8e5wrd.js} +3 -2
- package/build/lib/{chunk-yrnrbjes.js → chunk-85kpxwzs.js} +4 -2
- package/build/lib/{chunk-mg03jdmt.js → chunk-9jkzk9nc.js} +1 -1
- package/build/lib/{chunk-r4j8ybn9.js → chunk-9wwts6r6.js} +824 -77
- package/build/lib/{chunk-nhfax4gb.js → chunk-bxznzxdy.js} +5 -1
- package/build/lib/{chunk-r2dkp4tb.js → chunk-cqxm95md.js} +1 -1
- package/build/lib/{chunk-w66ce82a.js → chunk-e3agqspc.js} +12 -4
- package/build/lib/{chunk-ba41jh41.js → chunk-eh5yw385.js} +1137 -333
- package/build/lib/{chunk-1azdancq.js → chunk-ewc9r84m.js} +5 -1
- package/build/lib/{chunk-2njv7wz3.js → chunk-hbyxyxdc.js} +4 -0
- package/build/lib/{chunk-e8yy2k73.js → chunk-jhhwts6w.js} +28 -2
- package/build/lib/{chunk-1jvwqnem.js → chunk-kbxbd1kn.js} +108 -44
- package/build/lib/{chunk-7pwa92rn.js → chunk-mph5fvk7.js} +1 -1
- package/build/lib/chunk-psc23epq.js +107 -0
- package/build/lib/{chunk-acgbyf5h.js → chunk-qxad7qjd.js} +4 -2
- package/build/lib/{chunk-3c00n0cy.js → chunk-r0v3vvgm.js} +54 -33
- package/build/lib/{chunk-1yct6cra.js → chunk-rt13120a.js} +1 -1
- package/build/lib/{chunk-v3dk9j7k.js → chunk-sgya016v.js} +93 -22
- package/build/lib/{chunk-1fy8azee.js → chunk-txef92hq.js} +1 -1
- package/build/lib/{chunk-2qsq76xq.js → chunk-vcd90qrn.js} +189 -90
- package/build/lib/{chunk-7gjdygcx.js → chunk-vwr9w3ab.js} +2 -0
- package/build/lib/{chunk-z137x08b.js → chunk-wf6ak0m3.js} +92 -70
- package/build/lib/{chunk-xhdpgpkm.js → chunk-xft0ms9j.js} +2 -2
- package/build/lib/core/agents/agentRuntime.d.ts +3 -1
- package/build/lib/core/agents/defineAgent.d.ts +3 -2
- package/build/lib/core/agents/lance.d.ts +153 -0
- package/build/lib/core/agents/lanceJudge.d.ts +3 -0
- package/build/lib/core/agents/offSecAgent/index.d.ts +3 -1
- package/build/lib/core/agents/offSecAgent/index.js +16 -14
- package/build/lib/core/agents/offSecAgent/offensiveSecurityAgent.d.ts +4 -0
- package/build/lib/core/agents/offSecAgent/prompt.d.ts +3 -1
- package/build/lib/core/agents/offSecAgent/subagentSpawner.d.ts +18 -2
- package/build/lib/core/agents/offSecAgent/subagentSpawner.js +10 -8
- package/build/lib/core/agents/offSecAgent/toolExecutionContext.d.ts +3 -0
- package/build/lib/core/agents/offSecAgent/toolLifecycle.d.ts +1 -0
- package/build/lib/core/agents/offSecAgent/tools/index.js +10 -6
- package/build/lib/core/agents/offSecAgent/tools/listMemories.d.ts +11 -1
- package/build/lib/core/agents/offSecAgent/tools/reportError.d.ts +2 -1
- package/build/lib/core/agents/offSecAgent/tools/runPentestWorkflow.d.ts +20 -1
- package/build/lib/core/agents/offSecAgent/tools/spawnPentestAgent.d.ts +4 -7
- package/build/lib/core/agents/offSecAgent/tools/spawnPentestSwarm.d.ts +7 -1
- package/build/lib/core/agents/offSecAgent/tools/types.d.ts +6 -3
- package/build/lib/core/agents/offSecAgent/tools/whiteboxCandidates.d.ts +2 -2
- package/build/lib/core/agents/offSecAgent/types.d.ts +19 -3
- package/build/lib/core/agents/specialized/attackSurface/blackboxAgent.js +13 -13
- package/build/lib/core/agents/specialized/attackSurface/schemas.js +12 -12
- package/build/lib/core/agents/specialized/authenticationAgent/index.js +14 -14
- package/build/lib/core/agents/specialized/codeAgent/agent.js +13 -13
- package/build/lib/core/agents/specialized/codeAgent/prompts.d.ts +1 -0
- package/build/lib/core/agents/specialized/cvssScorer/index.d.ts +2 -1
- package/build/lib/core/agents/specialized/findingJudge/agent.js +11 -11
- package/build/lib/core/agents/specialized/findingJudge/index.d.ts +2 -1
- package/build/lib/core/agents/specialized/findingJudge/index.js +4 -4
- package/build/lib/core/agents/specialized/patching/index.js +14 -14
- package/build/lib/core/agents/specialized/pentest/agent.d.ts +18 -4
- package/build/lib/core/agents/specialized/pentest/agent.js +15 -13
- package/build/lib/core/agents/specialized/whiteboxAttackSurface/endpointDocumentationAgent.d.ts +2 -1
- package/build/lib/core/agents/specialized/whiteboxAttackSurface/index.js +13 -13
- package/build/lib/core/ai/ai.d.ts +29 -70
- package/build/lib/core/ai/ai.js +5 -3
- package/build/lib/core/ai/index.d.ts +1 -0
- package/build/lib/core/ai/index.js +16 -4
- package/build/lib/core/ai/models/claude-capabilities.d.ts +3 -2
- package/build/lib/core/ai/models/concentrate.d.ts +1 -0
- package/build/lib/core/ai/models/index.d.ts +1 -1
- package/build/lib/core/ai/providers/concentrate.d.ts +1 -0
- package/build/lib/core/ai/reasoning.d.ts +44 -0
- package/build/lib/core/ai/utils.d.ts +2 -0
- package/build/lib/core/ai/utils.js +5 -3
- package/build/lib/core/api/index.d.ts +6 -0
- package/build/lib/core/api/index.js +32 -23
- package/build/lib/core/api/lance.d.ts +6 -0
- package/build/lib/core/api/offesecAgent.d.ts +1 -0
- package/build/lib/core/api/reasoning.d.ts +12 -0
- package/build/lib/core/api/targetedPentest.d.ts +1 -0
- package/build/lib/core/api/targetedPentest.js +14 -14
- package/build/lib/core/cli/reasoning.d.ts +4 -0
- package/build/lib/core/config/config.d.ts +10 -2
- package/build/lib/core/config/customProviders.d.ts +11 -0
- package/build/lib/core/config/index.js +1 -1
- package/build/lib/core/eventBus.js +1 -1
- package/build/lib/core/findings/registry.d.ts +3 -1
- package/build/lib/core/findings/registry.js +4 -4
- package/build/lib/core/observability/index.js +1 -1
- package/build/lib/core/observability/telemetry.d.ts +4 -0
- package/build/lib/core/session/index.d.ts +47 -0
- package/build/lib/core/session/index.js +6 -4
- package/build/lib/core/session/persistence.d.ts +7 -0
- package/build/lib/core/session/persistence.js +8 -4
- package/build/lib/core/tools/backends/index.js +1 -1
- package/build/lib/core/tools/backends/resolve.d.ts +1 -0
- package/build/lib/core/workflows/fastStrike.d.ts +3 -1
- package/build/lib/core/workflows/pentest.d.ts +12 -2
- package/build/lib/core/workflows/pentest.js +19 -19
- package/build/lib/core/workflows/seams.js +5 -5
- package/build/lib/core/workflows/threatModel.d.ts +1 -0
- package/build/lib/core/workflows/whiteboxAttackSurface.d.ts +6 -4
- package/build/lib/core/workflows/whiteboxAttackSurface.js +15 -15
- package/build/lib/index.js +25 -25
- package/build/{logs-x62b7hk1.js → logs-bcbjpjp6.js} +16 -13
- package/build/{native-rollout-evidence-c9yhfqcs.js → native-rollout-evidence-rph1774m.js} +5 -5
- package/build/offesecAgent-81h1p6ee.js +32 -0
- package/build/pentest-2q20q6n1.js +23 -0
- package/build/{pentests-e0f32aqx.js → pentests-jgw031mc.js} +16 -13
- package/build/recordedRunClient-6axj6fba.js +11 -0
- package/build/subagentSpawner-a861gvt0.js +12 -0
- package/build/targetedPentest-6yxznt7s.js +91 -0
- package/build/{targets-xj9g3q0z.js → targets-bjah19dp.js} +16 -13
- package/build/threatModel-739kpexm.js +24 -0
- package/build/{uninstall-7s784q4a.js → uninstall-yxrn9edt.js} +1 -1
- package/build/{upload-4gvhwmvr.js → upload-34ewrjp5.js} +4 -4
- package/build/{utils-cjrz64pc.js → utils-fzm66efw.js} +5 -5
- package/package.json +2 -1
- package/src/cli/issues.test.ts +17 -1
- package/src/cli/lance-verifier.test.ts +57 -0
- package/src/cli/lance-verifier.ts +73 -0
- package/src/cli/lance.test.ts +71 -0
- package/src/cli/lance.ts +48 -0
- package/src/cli.ts +109 -19
- package/src/core/agents/agentRuntime.test.ts +42 -0
- package/src/core/agents/agentRuntime.ts +7 -2
- package/src/core/agents/defineAgent.ts +3 -1
- package/src/core/agents/lance.test.ts +421 -0
- package/src/core/agents/lance.ts +701 -0
- package/src/core/agents/lanceJudge.test.ts +166 -0
- package/src/core/agents/lanceJudge.ts +115 -0
- package/src/core/agents/offSecAgent/index.ts +3 -0
- package/src/core/agents/offSecAgent/interruptedStepFinalization.test.ts +51 -0
- package/src/core/agents/offSecAgent/lance.test.ts +188 -0
- package/src/core/agents/offSecAgent/offensiveSecurityAgent.test.ts +92 -5
- package/src/core/agents/offSecAgent/offensiveSecurityAgent.ts +244 -41
- package/src/core/agents/offSecAgent/prompt.test.ts +46 -0
- package/src/core/agents/offSecAgent/prompt.ts +52 -8
- package/src/core/agents/offSecAgent/selectiveConstruction.publicPath.test.ts +38 -0
- package/src/core/agents/offSecAgent/selectiveConstruction.test.ts +64 -0
- package/src/core/agents/offSecAgent/subagentSpawner.hooks.test.ts +11 -3
- package/src/core/agents/offSecAgent/subagentSpawner.reasoning.test.ts +167 -0
- package/src/core/agents/offSecAgent/subagentSpawner.ts +82 -28
- package/src/core/agents/offSecAgent/toolExecutionContext.test.ts +230 -0
- package/src/core/agents/offSecAgent/toolExecutionContext.ts +56 -0
- package/src/core/agents/offSecAgent/toolLifecycle.ts +2 -0
- package/src/core/agents/offSecAgent/tools/delegateAuth.ts +4 -2
- package/src/core/agents/offSecAgent/tools/documentFinding.test.ts +9 -4
- package/src/core/agents/offSecAgent/tools/documentFinding.ts +10 -9
- package/src/core/agents/offSecAgent/tools/listMemories.test.ts +230 -0
- package/src/core/agents/offSecAgent/tools/listMemories.ts +73 -6
- package/src/core/agents/offSecAgent/tools/reportError.test.ts +6 -0
- package/src/core/agents/offSecAgent/tools/reportError.ts +10 -2
- package/src/core/agents/offSecAgent/tools/runAttackSurface.ts +7 -4
- package/src/core/agents/offSecAgent/tools/runPentestWorkflow.test.ts +57 -0
- package/src/core/agents/offSecAgent/tools/runPentestWorkflow.ts +21 -1
- package/src/core/agents/offSecAgent/tools/runWhiteboxScan.ts +5 -2
- package/src/core/agents/offSecAgent/tools/spawnCodingAgent.ts +50 -67
- package/src/core/agents/offSecAgent/tools/spawnPentestAgent.test.ts +79 -3
- package/src/core/agents/offSecAgent/tools/spawnPentestAgent.ts +36 -16
- package/src/core/agents/offSecAgent/tools/spawnPentestSwarm.ts +28 -5
- package/src/core/agents/offSecAgent/tools/threatModelGenerator.ts +4 -3
- package/src/core/agents/offSecAgent/tools/types.ts +12 -2
- package/src/core/agents/offSecAgent/tools/updateTask.ts +5 -1
- package/src/core/agents/offSecAgent/tools/whiteboxCandidates.ts +11 -4
- package/src/core/agents/offSecAgent/types.ts +22 -1
- package/src/core/agents/specialized/codeAgent/agent.test.ts +7 -0
- package/src/core/agents/specialized/codeAgent/agent.ts +9 -2
- package/src/core/agents/specialized/codeAgent/prompts.ts +6 -0
- package/src/core/agents/specialized/cvssScorer/index.test.ts +2 -1
- package/src/core/agents/specialized/cvssScorer/index.ts +3 -0
- package/src/core/agents/specialized/findingJudge/index.ts +6 -0
- package/src/core/agents/specialized/pentest/agent.test.ts +155 -0
- package/src/core/agents/specialized/pentest/agent.ts +181 -52
- package/src/core/agents/specialized/pentest/results.test.ts +59 -4
- package/src/core/agents/specialized/whiteboxAttackSurface/endpointDocumentationAgent.concurrency.test.ts +59 -2
- package/src/core/agents/specialized/whiteboxAttackSurface/endpointDocumentationAgent.hooks.test.ts +127 -0
- package/src/core/agents/specialized/whiteboxAttackSurface/endpointDocumentationAgent.ts +74 -68
- package/src/core/ai/ai.durability-hooks.test.ts +25 -7
- package/src/core/ai/ai.lance.test.ts +581 -0
- package/src/core/ai/ai.operator-context.bench.test.ts +1390 -0
- package/src/core/ai/ai.recorded-context.test.ts +89 -8
- package/src/core/ai/ai.test.ts +81 -59
- package/src/core/ai/ai.ts +453 -327
- package/src/core/ai/compactionTelemetry.test.ts +69 -17
- package/src/core/ai/index.ts +11 -0
- package/src/core/ai/models/anthropic.ts +6 -0
- package/src/core/ai/models/bedrock.ts +18 -0
- package/src/core/ai/models/claude-capabilities.ts +29 -8
- package/src/core/ai/models/concentrate.ts +52 -0
- package/src/core/ai/models/index.ts +25 -4
- package/src/core/ai/models/models.test.ts +179 -7
- package/src/core/ai/models/openrouter-reasoning.json +219 -0
- package/src/core/ai/models/openrouter.ts +43 -1
- package/src/core/ai/providers/anthropic-models.test.ts +60 -1
- package/src/core/ai/providers/bedrock-models.test.ts +81 -0
- package/src/core/ai/providers/concentrate.test.ts +31 -0
- package/src/core/ai/providers/concentrate.ts +11 -0
- package/src/core/ai/providers/custom.test.ts +74 -0
- package/src/core/ai/providers/custom.ts +3 -1
- package/src/core/ai/providers/gateway-models.test.ts +16 -6
- package/src/core/ai/providers/pensarFormatters.ts +8 -1
- package/src/core/ai/reasoning.test.ts +313 -0
- package/src/core/ai/reasoning.ts +500 -0
- package/src/core/ai/streamIdleTimeout.test.ts +21 -0
- package/src/core/ai/utils.native-rollout-evidence.test.ts +21 -8
- package/src/core/ai/utils.ts +269 -163
- package/src/core/api/attackSurface.ts +1 -0
- package/src/core/api/blackboxPentest.ts +9 -1
- package/src/core/api/index.ts +17 -0
- package/src/core/api/lance.ts +23 -0
- package/src/core/api/offesecAgent.test.ts +51 -0
- package/src/core/api/offesecAgent.ts +15 -1
- package/src/core/api/reasoning.test.ts +213 -0
- package/src/core/api/reasoning.ts +44 -0
- package/src/core/api/recordedRun.loop.test.ts +5 -1
- package/src/core/api/targetedPentest.test.ts +14 -2
- package/src/core/api/targetedPentest.ts +52 -5
- package/src/core/cli/reasoning.test.ts +149 -0
- package/src/core/cli/reasoning.ts +95 -0
- package/src/core/config/config.test.ts +35 -0
- package/src/core/config/config.ts +11 -0
- package/src/core/config/customProviders.ts +21 -2
- package/src/core/eventBus.ts +1 -0
- package/src/core/findings/registry.test.ts +9 -1
- package/src/core/findings/registry.ts +6 -0
- package/src/core/observability/telemetry.test.ts +131 -79
- package/src/core/observability/telemetry.ts +5 -0
- package/src/core/runtime/sqliteRunObservation.test.ts +1 -1
- package/src/core/session/index.ts +38 -0
- package/src/core/session/persistence.test.ts +62 -0
- package/src/core/session/persistence.ts +56 -0
- package/src/core/tools/backends/resolve.ts +7 -0
- package/src/core/tools/backends/whiteboxJobs.test.ts +9 -8
- package/src/core/workflows/fastStrike.seams.test.ts +149 -0
- package/src/core/workflows/fastStrike.test.ts +18 -1
- package/src/core/workflows/fastStrike.ts +106 -11
- package/src/core/workflows/pentest.test.ts +104 -0
- package/src/core/workflows/pentest.ts +128 -7
- package/src/core/workflows/seams.test.ts +13 -0
- package/src/core/workflows/seams.ts +5 -1
- package/src/core/workflows/threatModel.ts +2 -0
- package/src/core/workflows/whiteboxAttackSurface.test.ts +74 -2
- package/src/core/workflows/whiteboxAttackSurface.ts +102 -73
- package/src/tui/command-registry.test.ts +12 -0
- package/src/tui/command-registry.ts +10 -0
- package/src/tui/components/chat/config-view.tsx +6 -10
- package/src/tui/components/chat/home-view.tsx +2 -2
- package/src/tui/components/chat/input-area.tsx +2 -2
- package/src/tui/components/chat/loading-indicator.tsx +20 -4
- package/src/tui/components/chat/message-list.tsx +1 -0
- package/src/tui/components/commands/__tests__/advanced-settings-lifecycle.tsx +164 -0
- package/src/tui/components/commands/advanced-settings.test.ts +34 -0
- package/src/tui/components/commands/advanced-settings.tsx +220 -31
- package/src/tui/components/commands/models-display.tsx +7 -1
- package/src/tui/components/model-picker/ModelPicker.tsx +65 -103
- package/src/tui/components/model-picker/ModelPickerDialog.tsx +8 -14
- package/src/tui/components/model-picker/__tests__/reasoning-control.tsx +162 -0
- package/src/tui/components/model-picker/reasoning-control.test.ts +15 -0
- package/src/tui/components/operator-dashboard/index.tsx +166 -50
- package/src/tui/components/operator-dashboard/logic.test.ts +144 -2
- package/src/tui/components/operator-dashboard/logic.ts +54 -3
- package/src/tui/components/operator-dashboard/run-events.test.ts +3 -1
- package/src/tui/components/shared/__tests__/tool-renderer-lifecycle.tsx +18 -0
- package/src/tui/components/shared/action-label.test.ts +9 -0
- package/src/tui/components/shared/compacting-icon.tsx +18 -0
- package/src/tui/components/shared/index.ts +1 -0
- package/src/tui/components/shared/tool-registry.ts +1 -0
- package/src/tui/components/shared/tool-renderer.tsx +21 -7
- package/src/tui/context/agent.tsx +32 -79
- package/src/tui/context/route.tsx +2 -0
- package/src/tui/index.tsx +1 -0
- package/src/tui/keybindings/registry.ts +2 -0
- package/build/agent-6w7egcf1.js +0 -13
- package/build/agent-9zx75feh.js +0 -13
- package/build/blackboxAgent-s56sgx9b.js +0 -13
- package/build/cli-g06s7edq.js +0 -11
- package/build/lib/chunk-z96pbjhd.js +0 -56
- package/build/offesecAgent-5whnpeta.js +0 -22
- package/build/pentest-e61hc38s.js +0 -22
- package/build/recordedRunClient-dp032c32.js +0 -11
- package/build/targetedPentest-rcbs4nvp.js +0 -57
- package/build/threatModel-jkxfa40s.js +0 -21
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { LanguageModelV3StreamPart } from "@ai-sdk/provider";
|
|
5
|
+
import { simulateReadableStream } from "ai";
|
|
6
|
+
import { MockLanguageModelV3 } from "ai/test";
|
|
7
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { ApprovalGate } from "../operator/approvalGate";
|
|
9
|
+
import type { SessionInfo } from "../session";
|
|
10
|
+
|
|
11
|
+
const state = vi.hoisted(() => ({
|
|
12
|
+
model: null as MockLanguageModelV3 | null,
|
|
13
|
+
}));
|
|
14
|
+
vi.mock("./utils", async (original) => ({
|
|
15
|
+
...(await original<Record<string, unknown>>()),
|
|
16
|
+
getProviderModel: () => state.model,
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
import { OffensiveSecurityAgent } from "../agents/offSecAgent";
|
|
20
|
+
import { inProcessSubagentSpawner } from "../agents/offSecAgent/subagentSpawner";
|
|
21
|
+
|
|
22
|
+
const usage = {
|
|
23
|
+
inputTokens: { total: 100, noCache: 100, cacheRead: 0, cacheWrite: 0 },
|
|
24
|
+
outputTokens: { total: 10, text: 10, reasoning: undefined },
|
|
25
|
+
};
|
|
26
|
+
const roots: string[] = [];
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
for (const root of roots.splice(0))
|
|
29
|
+
rmSync(root, { recursive: true, force: true });
|
|
30
|
+
vi.clearAllMocks();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function agent(options: Record<string, unknown> = {}) {
|
|
34
|
+
const root = mkdtempSync(join(tmpdir(), "lance-sdk-"));
|
|
35
|
+
roots.push(root);
|
|
36
|
+
return new OffensiveSecurityAgent({
|
|
37
|
+
mode: "lance",
|
|
38
|
+
prompt: "Capture the flag",
|
|
39
|
+
model: "claude-sonnet-4-5",
|
|
40
|
+
activeTools: [],
|
|
41
|
+
session: {
|
|
42
|
+
id: "ses_lance",
|
|
43
|
+
version: "1",
|
|
44
|
+
time: { created: Date.now(), updated: Date.now() },
|
|
45
|
+
logsPath: join(root, "logs"),
|
|
46
|
+
rootPath: root,
|
|
47
|
+
config: {},
|
|
48
|
+
targets: [],
|
|
49
|
+
findingsPath: join(root, "findings"),
|
|
50
|
+
scratchpadPath: join(root, "scratchpad"),
|
|
51
|
+
pocsPath: join(root, "pocs"),
|
|
52
|
+
} as SessionInfo,
|
|
53
|
+
sandbox: {
|
|
54
|
+
type: "linux",
|
|
55
|
+
execute: async () => {
|
|
56
|
+
throw new Error("Unexpected shell execution");
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
...options,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function stream(chunks: LanguageModelV3StreamPart[]) {
|
|
64
|
+
return {
|
|
65
|
+
stream: simulateReadableStream({
|
|
66
|
+
chunks,
|
|
67
|
+
initialDelayInMs: null,
|
|
68
|
+
chunkDelayInMs: null,
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Compaction streams, so the summarizer reaches the model through doStream
|
|
74
|
+
// alongside the agent's own turns; its request carries the compaction instruction.
|
|
75
|
+
function isSummaryCall(options: { prompt: unknown }): boolean {
|
|
76
|
+
return JSON.stringify(options.prompt).includes("Compact this conversation");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
describe("Lance with the real AI SDK loop", () => {
|
|
80
|
+
it("keeps conversations open and waits for new user input after verified success", async () => {
|
|
81
|
+
let turn = 0;
|
|
82
|
+
const doStream = vi.fn(async () => {
|
|
83
|
+
turn++;
|
|
84
|
+
return stream(
|
|
85
|
+
turn !== 3
|
|
86
|
+
? [
|
|
87
|
+
{ type: "text-start", id: "reply" },
|
|
88
|
+
{
|
|
89
|
+
type: "text-delta",
|
|
90
|
+
id: "reply",
|
|
91
|
+
delta:
|
|
92
|
+
turn === 1 ? "What is the target?" : "What is the objective?",
|
|
93
|
+
},
|
|
94
|
+
{ type: "text-end", id: "reply" },
|
|
95
|
+
{
|
|
96
|
+
type: "finish",
|
|
97
|
+
finishReason: { unified: "stop", raw: "stop" },
|
|
98
|
+
usage,
|
|
99
|
+
},
|
|
100
|
+
]
|
|
101
|
+
: [
|
|
102
|
+
{
|
|
103
|
+
type: "tool-call",
|
|
104
|
+
toolCallId: "proof",
|
|
105
|
+
toolName: "submit_objective",
|
|
106
|
+
input: '{"evidence":"proof"}',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: "finish",
|
|
110
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
111
|
+
usage,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
);
|
|
115
|
+
});
|
|
116
|
+
state.model = new MockLanguageModelV3({ doStream });
|
|
117
|
+
const lance = {
|
|
118
|
+
interactive: true,
|
|
119
|
+
verifyObjective: async () => ({ verified: true, verifierId: "host" }),
|
|
120
|
+
};
|
|
121
|
+
const first = agent({ prompt: "hello there!", lance });
|
|
122
|
+
await first.consume();
|
|
123
|
+
expect(first.lanceRuntime!.metrics("m").outcome).toBe("awaiting_input");
|
|
124
|
+
const messages = (prompt: string) => [
|
|
125
|
+
...JSON.parse(
|
|
126
|
+
readFileSync(join(first.session.rootPath, "messages.json"), "utf8"),
|
|
127
|
+
),
|
|
128
|
+
{ role: "user", content: prompt },
|
|
129
|
+
];
|
|
130
|
+
const second = agent({
|
|
131
|
+
session: first.session,
|
|
132
|
+
messages: messages("http://example.test"),
|
|
133
|
+
prompt: "http://example.test",
|
|
134
|
+
lance,
|
|
135
|
+
});
|
|
136
|
+
await second.consume();
|
|
137
|
+
expect(second.lanceRuntime!.metrics("m").outcome).toBe("awaiting_input");
|
|
138
|
+
const third = agent({
|
|
139
|
+
session: first.session,
|
|
140
|
+
messages: messages("Capture the flag"),
|
|
141
|
+
prompt: "Capture the flag",
|
|
142
|
+
lance,
|
|
143
|
+
});
|
|
144
|
+
await third.consume();
|
|
145
|
+
expect(third.lanceRuntime!.metrics("m")).toMatchObject({
|
|
146
|
+
outcome: "verified",
|
|
147
|
+
harnessVerifiedSuccess: true,
|
|
148
|
+
});
|
|
149
|
+
expect(JSON.stringify(state.model.doStreamCalls[1].prompt)).toContain(
|
|
150
|
+
"What is the target?",
|
|
151
|
+
);
|
|
152
|
+
expect(JSON.stringify(state.model.doStreamCalls[2].prompt)).toContain(
|
|
153
|
+
"What is the objective?",
|
|
154
|
+
);
|
|
155
|
+
expect(() =>
|
|
156
|
+
agent({ session: first.session, prompt: "One more thing" }),
|
|
157
|
+
).toThrow("terminal");
|
|
158
|
+
expect(doStream).toHaveBeenCalledTimes(3);
|
|
159
|
+
const followUp = agent({
|
|
160
|
+
session: first.session,
|
|
161
|
+
messages: messages("Explain the result"),
|
|
162
|
+
prompt: "Explain the result",
|
|
163
|
+
lance,
|
|
164
|
+
});
|
|
165
|
+
await followUp.consume();
|
|
166
|
+
expect(followUp.lanceRuntime!.metrics("m").outcome).toBe("awaiting_input");
|
|
167
|
+
expect(doStream).toHaveBeenCalledTimes(4);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("never invokes the Finding Judge when the judge setting is disabled", async () => {
|
|
171
|
+
const spawn = vi.spyOn(inProcessSubagentSpawner, "spawn");
|
|
172
|
+
state.model = new MockLanguageModelV3({
|
|
173
|
+
doStream: async () =>
|
|
174
|
+
stream([
|
|
175
|
+
{
|
|
176
|
+
type: "tool-call",
|
|
177
|
+
toolCallId: "proof",
|
|
178
|
+
toolName: "finish_task",
|
|
179
|
+
input: JSON.stringify({
|
|
180
|
+
summary: "Finished the requested test",
|
|
181
|
+
evidence: "claim",
|
|
182
|
+
poc: {
|
|
183
|
+
script: "echo proof",
|
|
184
|
+
type: "bash",
|
|
185
|
+
stdout: "proof",
|
|
186
|
+
stderr: "",
|
|
187
|
+
exitCode: 0,
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
type: "finish",
|
|
193
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
194
|
+
usage,
|
|
195
|
+
},
|
|
196
|
+
]),
|
|
197
|
+
});
|
|
198
|
+
try {
|
|
199
|
+
const running = agent({ findingPolicy: "external" });
|
|
200
|
+
await running.consume();
|
|
201
|
+
expect(spawn).not.toHaveBeenCalled();
|
|
202
|
+
expect(running.lanceRuntime?.metrics("m")).toMatchObject({
|
|
203
|
+
outcome: "completed",
|
|
204
|
+
judgeUsage: { requests: 0 },
|
|
205
|
+
harnessVerifiedSuccess: false,
|
|
206
|
+
});
|
|
207
|
+
} finally {
|
|
208
|
+
spawn.mockRestore();
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("uses the existing Finding Judge only when enabled and stops after its acceptance", async () => {
|
|
213
|
+
let requests = 0;
|
|
214
|
+
const doStream = vi.fn(async () => {
|
|
215
|
+
const judging = requests++ > 0;
|
|
216
|
+
return stream([
|
|
217
|
+
{
|
|
218
|
+
type: "tool-call",
|
|
219
|
+
toolCallId: judging ? "verdict" : "proof",
|
|
220
|
+
toolName: judging ? "response" : "submit_objective",
|
|
221
|
+
input: JSON.stringify(
|
|
222
|
+
judging
|
|
223
|
+
? {
|
|
224
|
+
result: {
|
|
225
|
+
valid: true,
|
|
226
|
+
findingType: "vulnerability",
|
|
227
|
+
confidence: 0.95,
|
|
228
|
+
reasoning: "Verified",
|
|
229
|
+
concerns: [],
|
|
230
|
+
verificationSteps: [],
|
|
231
|
+
toolEvidence: [],
|
|
232
|
+
reproducedPoc: true,
|
|
233
|
+
webResearchUsed: false,
|
|
234
|
+
limitations: [],
|
|
235
|
+
},
|
|
236
|
+
}
|
|
237
|
+
: {
|
|
238
|
+
evidence: "protected proof",
|
|
239
|
+
poc: {
|
|
240
|
+
script: "curl http://example.test/proof",
|
|
241
|
+
type: "bash",
|
|
242
|
+
stdout: "proof",
|
|
243
|
+
stderr: "",
|
|
244
|
+
exitCode: 0,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
),
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
type: "finish",
|
|
251
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
252
|
+
usage,
|
|
253
|
+
},
|
|
254
|
+
]);
|
|
255
|
+
});
|
|
256
|
+
state.model = new MockLanguageModelV3({ doStream });
|
|
257
|
+
const running = agent({
|
|
258
|
+
findingPolicy: "native",
|
|
259
|
+
target: "http://example.test",
|
|
260
|
+
});
|
|
261
|
+
await running.consume();
|
|
262
|
+
expect(doStream).toHaveBeenCalledTimes(2);
|
|
263
|
+
expect(running.lanceRuntime?.metrics("m")).toMatchObject({
|
|
264
|
+
outcome: "judge_accepted",
|
|
265
|
+
modelJudgedSuccess: true,
|
|
266
|
+
harnessVerifiedSuccess: false,
|
|
267
|
+
judgeUsage: { requests: 1 },
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it("returns before the hard deadline when inference stalls", async () => {
|
|
272
|
+
const doStream = vi.fn(async () => ({
|
|
273
|
+
stream: new ReadableStream<LanguageModelV3StreamPart>(),
|
|
274
|
+
}));
|
|
275
|
+
state.model = new MockLanguageModelV3({ doStream });
|
|
276
|
+
const running = agent({
|
|
277
|
+
lance: { timeoutMs: 1500, shutdownReserveMs: 1200 },
|
|
278
|
+
});
|
|
279
|
+
await running.consume();
|
|
280
|
+
const metrics = running.lanceRuntime!.metrics("m");
|
|
281
|
+
expect(metrics.outcome).toBe("deadline_exhausted");
|
|
282
|
+
expect(metrics.elapsedMs).toBeLessThan(1500);
|
|
283
|
+
expect(metrics.usage.usageComplete).toBe(false);
|
|
284
|
+
expect(doStream).toHaveBeenCalledTimes(1);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("cancels pending approval without executing or leaving a timer behind", async () => {
|
|
288
|
+
state.model = new MockLanguageModelV3({
|
|
289
|
+
doStream: async () =>
|
|
290
|
+
stream([
|
|
291
|
+
{ type: "stream-start", warnings: [] },
|
|
292
|
+
{
|
|
293
|
+
type: "tool-call",
|
|
294
|
+
toolCallId: "approval",
|
|
295
|
+
toolName: "execute_command",
|
|
296
|
+
input: JSON.stringify({
|
|
297
|
+
command: "echo forbidden",
|
|
298
|
+
toolCallDescription: "approval test",
|
|
299
|
+
}),
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
type: "finish",
|
|
303
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
304
|
+
usage,
|
|
305
|
+
},
|
|
306
|
+
]),
|
|
307
|
+
});
|
|
308
|
+
const gate = new ApprovalGate({ requireApproval: true });
|
|
309
|
+
const execute = vi.fn();
|
|
310
|
+
const requested = vi.fn();
|
|
311
|
+
gate.on("approval-needed", requested);
|
|
312
|
+
const running = agent({
|
|
313
|
+
activeTools: ["execute_command"],
|
|
314
|
+
approvalGate: gate,
|
|
315
|
+
sandbox: { type: "linux", execute },
|
|
316
|
+
lance: { timeoutMs: 1500, shutdownReserveMs: 1200 },
|
|
317
|
+
});
|
|
318
|
+
await running.consume();
|
|
319
|
+
expect(requested).toHaveBeenCalledTimes(1);
|
|
320
|
+
expect(execute).not.toHaveBeenCalled();
|
|
321
|
+
expect(gate.getPendingApprovals()).toEqual([]);
|
|
322
|
+
expect(running.lanceRuntime!.metrics("m").outcome).toBe(
|
|
323
|
+
"deadline_exhausted",
|
|
324
|
+
);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it.each([
|
|
328
|
+
"submit_objective",
|
|
329
|
+
"finish_task",
|
|
330
|
+
])("stops same-response work and subsequent requests after %s", async (completionTool) => {
|
|
331
|
+
const doStream = vi.fn(async () =>
|
|
332
|
+
stream([
|
|
333
|
+
{ type: "stream-start", warnings: [] },
|
|
334
|
+
{
|
|
335
|
+
type: "tool-call",
|
|
336
|
+
toolCallId: "proof",
|
|
337
|
+
toolName: completionTool,
|
|
338
|
+
input: JSON.stringify(
|
|
339
|
+
completionTool === "finish_task"
|
|
340
|
+
? { summary: "Requested test is complete" }
|
|
341
|
+
: { evidence: "FLAG{proof}" },
|
|
342
|
+
),
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
type: "tool-call",
|
|
346
|
+
toolCallId: "late",
|
|
347
|
+
toolName: "execute_command",
|
|
348
|
+
input: JSON.stringify({
|
|
349
|
+
command: "echo should-not-run",
|
|
350
|
+
toolCallDescription: "late work",
|
|
351
|
+
}),
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
type: "finish",
|
|
355
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
356
|
+
usage,
|
|
357
|
+
},
|
|
358
|
+
]),
|
|
359
|
+
);
|
|
360
|
+
const doGenerate = vi.fn();
|
|
361
|
+
state.model = new MockLanguageModelV3({ doStream, doGenerate });
|
|
362
|
+
const running = agent({
|
|
363
|
+
lance: {
|
|
364
|
+
verifyObjective: async () => ({
|
|
365
|
+
verified: true,
|
|
366
|
+
verifierId: "test-host",
|
|
367
|
+
}),
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
await running.consume();
|
|
371
|
+
expect(doStream).toHaveBeenCalledTimes(1);
|
|
372
|
+
expect(doGenerate).not.toHaveBeenCalled();
|
|
373
|
+
expect(running.lanceRuntime?.metrics("m")).toMatchObject({
|
|
374
|
+
outcome: completionTool === "finish_task" ? "completed" : "verified",
|
|
375
|
+
toolCalls: 1,
|
|
376
|
+
usage: { requests: 1 },
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it("does not repair forbidden tools with another model", async () => {
|
|
381
|
+
let step = 0;
|
|
382
|
+
const doStream = vi.fn(async () =>
|
|
383
|
+
stream(
|
|
384
|
+
step++ === 0
|
|
385
|
+
? [
|
|
386
|
+
{ type: "stream-start", warnings: [] },
|
|
387
|
+
{
|
|
388
|
+
type: "tool-call",
|
|
389
|
+
toolCallId: "forbidden",
|
|
390
|
+
toolName: "spawn_pentest_agent",
|
|
391
|
+
input: "{}",
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
type: "finish",
|
|
395
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
396
|
+
usage,
|
|
397
|
+
},
|
|
398
|
+
]
|
|
399
|
+
: [
|
|
400
|
+
{
|
|
401
|
+
type: "finish",
|
|
402
|
+
finishReason: { unified: "stop", raw: "stop" },
|
|
403
|
+
usage,
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
),
|
|
407
|
+
);
|
|
408
|
+
const doGenerate = vi.fn();
|
|
409
|
+
state.model = new MockLanguageModelV3({ doStream, doGenerate });
|
|
410
|
+
const running = agent();
|
|
411
|
+
await running.consume();
|
|
412
|
+
expect(doGenerate).not.toHaveBeenCalled();
|
|
413
|
+
expect(running.lanceRuntime?.metrics("m").policyViolations).toMatchObject([
|
|
414
|
+
{ kind: "forbidden_tool", name: "spawn_pentest_agent" },
|
|
415
|
+
]);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it("compacts repeatedly with the same model, restores the latest plan, and meters all work", async () => {
|
|
419
|
+
let summaries = 0;
|
|
420
|
+
let steps = 0;
|
|
421
|
+
const summaryToolChoices: unknown[] = [];
|
|
422
|
+
const doStream = vi.fn(async (options) => {
|
|
423
|
+
if (isSummaryCall(options)) {
|
|
424
|
+
summaryToolChoices.push(options.toolChoice);
|
|
425
|
+
return stream([
|
|
426
|
+
{ type: "text-start", id: "s" },
|
|
427
|
+
{
|
|
428
|
+
type: "text-delta",
|
|
429
|
+
id: "s",
|
|
430
|
+
delta: `summary-${++summaries}: stay within example.test`,
|
|
431
|
+
},
|
|
432
|
+
{ type: "text-end", id: "s" },
|
|
433
|
+
{
|
|
434
|
+
type: "finish",
|
|
435
|
+
finishReason: { unified: "stop", raw: "stop" },
|
|
436
|
+
usage,
|
|
437
|
+
},
|
|
438
|
+
]);
|
|
439
|
+
}
|
|
440
|
+
return stream(
|
|
441
|
+
++steps === 1
|
|
442
|
+
? [
|
|
443
|
+
{ type: "text-start", id: "long" },
|
|
444
|
+
{
|
|
445
|
+
type: "text-delta",
|
|
446
|
+
id: "long",
|
|
447
|
+
delta: "observation ".repeat(80_000),
|
|
448
|
+
},
|
|
449
|
+
{ type: "text-end", id: "long" },
|
|
450
|
+
{
|
|
451
|
+
type: "tool-call",
|
|
452
|
+
toolCallId: "plan",
|
|
453
|
+
toolName: "update_plan",
|
|
454
|
+
input: JSON.stringify({
|
|
455
|
+
explanation:
|
|
456
|
+
"Evidence and failed probes are in scratchpad.md",
|
|
457
|
+
plan: [
|
|
458
|
+
{
|
|
459
|
+
step: "Verify the remaining hypothesis",
|
|
460
|
+
status: "in_progress",
|
|
461
|
+
},
|
|
462
|
+
],
|
|
463
|
+
}),
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
type: "finish",
|
|
467
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
468
|
+
usage,
|
|
469
|
+
},
|
|
470
|
+
]
|
|
471
|
+
: [
|
|
472
|
+
{
|
|
473
|
+
type: "tool-call",
|
|
474
|
+
toolCallId: "done",
|
|
475
|
+
toolName: "finish_task",
|
|
476
|
+
input: JSON.stringify({ summary: "Done", evidence: "proof" }),
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
type: "finish",
|
|
480
|
+
finishReason: { unified: "tool-calls", raw: "tool_calls" },
|
|
481
|
+
usage,
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
);
|
|
485
|
+
});
|
|
486
|
+
state.model = new MockLanguageModelV3({ doStream });
|
|
487
|
+
const running = agent({
|
|
488
|
+
messages: [
|
|
489
|
+
{
|
|
490
|
+
role: "user",
|
|
491
|
+
content:
|
|
492
|
+
"Capture the objective on example.test. " +
|
|
493
|
+
"history ".repeat(100_000),
|
|
494
|
+
},
|
|
495
|
+
],
|
|
496
|
+
lance: {
|
|
497
|
+
pricing: { input: 1, output: 2, cacheRead: 0, cacheWrite: 0 },
|
|
498
|
+
verifyObjective: async () => ({ verified: true, verifierId: "host" }),
|
|
499
|
+
},
|
|
500
|
+
});
|
|
501
|
+
await running.consume();
|
|
502
|
+
const agentTurns = state.model.doStreamCalls.filter(
|
|
503
|
+
(request) => !isSummaryCall(request),
|
|
504
|
+
);
|
|
505
|
+
expect(summaries).toBe(2);
|
|
506
|
+
expect(agentTurns).toHaveLength(2);
|
|
507
|
+
for (const toolChoice of summaryToolChoices)
|
|
508
|
+
expect(toolChoice).toEqual({ type: "none" });
|
|
509
|
+
const continued = JSON.stringify(agentTurns[1].prompt);
|
|
510
|
+
expect(continued).toContain("summary-2");
|
|
511
|
+
expect(continued).not.toContain("summary-1");
|
|
512
|
+
expect(continued).toContain("Verify the remaining hypothesis");
|
|
513
|
+
expect(continued).toContain("scratchpad.md");
|
|
514
|
+
expect(running.lanceRuntime?.metrics("m")).toMatchObject({
|
|
515
|
+
outcome: "verified",
|
|
516
|
+
usage: {
|
|
517
|
+
requests: 4,
|
|
518
|
+
inputTokens: 400,
|
|
519
|
+
outputTokens: 40,
|
|
520
|
+
costUsd: 0.00048,
|
|
521
|
+
},
|
|
522
|
+
usageBeforeSuccess: { requests: 4 },
|
|
523
|
+
compactionUsage: {
|
|
524
|
+
requests: 2,
|
|
525
|
+
inputTokens: 200,
|
|
526
|
+
outputTokens: 20,
|
|
527
|
+
costUsd: 0.00024,
|
|
528
|
+
},
|
|
529
|
+
judgeUsage: { requests: 0 },
|
|
530
|
+
policyViolations: [],
|
|
531
|
+
});
|
|
532
|
+
const persisted = readFileSync(
|
|
533
|
+
join(running.session.rootPath, "messages.json"),
|
|
534
|
+
"utf8",
|
|
535
|
+
);
|
|
536
|
+
expect(persisted.includes("summary-2")).toBe(true);
|
|
537
|
+
expect(persisted).toContain("scratchpad.md");
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it("cancels a stalled compaction before the deadline without resuming inference", async () => {
|
|
541
|
+
const summaryCall = vi.fn();
|
|
542
|
+
const agentTurn = vi.fn();
|
|
543
|
+
const doStream = vi.fn((options) => {
|
|
544
|
+
(isSummaryCall(options) ? summaryCall : agentTurn)();
|
|
545
|
+
return new Promise<never>(() => {});
|
|
546
|
+
});
|
|
547
|
+
state.model = new MockLanguageModelV3({ doStream });
|
|
548
|
+
const running = agent({
|
|
549
|
+
messages: [{ role: "user", content: "history ".repeat(100_000) }],
|
|
550
|
+
lance: { timeoutMs: 1500, shutdownReserveMs: 1200 },
|
|
551
|
+
});
|
|
552
|
+
await running.consume();
|
|
553
|
+
expect(summaryCall).toHaveBeenCalledTimes(1);
|
|
554
|
+
expect(agentTurn).not.toHaveBeenCalled();
|
|
555
|
+
expect(running.lanceRuntime!.metrics("m")).toMatchObject({
|
|
556
|
+
outcome: "deadline_exhausted",
|
|
557
|
+
compactionUsage: { requests: 1, usageComplete: false, costUsd: null },
|
|
558
|
+
});
|
|
559
|
+
expect(running.lanceRuntime!.metrics("m").elapsedMs).toBeLessThan(1500);
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
it("ends gracefully when compaction cannot fit, without a reset that discards progress", async () => {
|
|
563
|
+
const summaryCall = vi.fn();
|
|
564
|
+
const agentTurn = vi.fn();
|
|
565
|
+
const doStream = vi.fn(async (options) => {
|
|
566
|
+
(isSummaryCall(options) ? summaryCall : agentTurn)();
|
|
567
|
+
throw new Error("maximum context length exceeded");
|
|
568
|
+
});
|
|
569
|
+
state.model = new MockLanguageModelV3({ doStream });
|
|
570
|
+
const running = agent({
|
|
571
|
+
messages: [{ role: "user", content: "history ".repeat(100_000) }],
|
|
572
|
+
});
|
|
573
|
+
await running.consume();
|
|
574
|
+
expect(summaryCall.mock.calls.length).toBeGreaterThan(0);
|
|
575
|
+
expect(summaryCall.mock.calls.length).toBeLessThanOrEqual(8);
|
|
576
|
+
expect(agentTurn).not.toHaveBeenCalled();
|
|
577
|
+
expect(running.lanceRuntime!.metrics("m").outcome).toBe(
|
|
578
|
+
"context_exhausted",
|
|
579
|
+
);
|
|
580
|
+
});
|
|
581
|
+
});
|