@causyne/agent 1.20.121 → 1.20.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/bin/causyne.js +38 -15
- package/docs/SECURITY_REVIEW.md +42 -6
- package/package.json +5 -5
- package/src/acp/agentCatalog.js +141 -62
- package/src/acp/agentCatalog.ts +142 -65
- package/src/acp/client.js +489 -109
- package/src/acp/client.ts +465 -108
- package/src/acp/peerProfiles.js +55 -22
- package/src/acp/peerProfiles.ts +51 -22
- package/src/acp/protocol.js +181 -8
- package/src/acp/protocol.ts +189 -8
- package/src/acp/server.js +250 -53
- package/src/acp/server.ts +234 -53
- package/src/agent/errorClassifier.js +48 -8
- package/src/agent/errorClassifier.ts +50 -7
- package/src/agent/providerFailure.js +1 -1
- package/src/agent/providerFailure.ts +7 -1
- package/src/agent/toolArgValidator.js +38 -4
- package/src/agent/toolArgValidator.ts +39 -4
- package/src/agent/toolTurnIntegrity.js +28 -7
- package/src/agent/toolTurnIntegrity.ts +25 -6
- package/src/agent/workspaceBoundary.js +30 -4
- package/src/agent/workspaceBoundary.ts +32 -4
- package/src/agentLoop.js +609 -222
- package/src/agentLoop.ts +632 -220
- package/src/approvalGrants.js +19 -7
- package/src/approvalGrants.ts +20 -7
- package/src/approvalPolicy.js +76 -16
- package/src/approvalPolicy.ts +74 -16
- package/src/auditLog.js +641 -48
- package/src/auditLog.ts +661 -0
- package/src/autoUpdate.js +37 -7
- package/src/autoUpdate.ts +32 -7
- package/src/backgroundTasks.js +328 -0
- package/src/backgroundTasks.ts +339 -0
- package/src/benchmarks/codingEval.js +558 -0
- package/src/benchmarks/codingEval.ts +628 -0
- package/src/benchmarks/planCache.js +115 -134
- package/src/benchmarks/planCache.ts +163 -0
- package/src/browser/browserRuntime.js +52 -0
- package/src/browser/browserRuntime.ts +55 -0
- package/src/browser/causyneBrowser.js +887 -12
- package/src/browser/causyneBrowser.ts +1045 -34
- package/src/browser/searchProviders.js +95 -7
- package/src/browser/searchProviders.ts +90 -7
- package/src/browser/urlPolicy.js +8 -1
- package/src/browser/urlPolicy.ts +7 -1
- package/src/browser/workspacePathSafety.js +6 -4
- package/src/browser/workspacePathSafety.ts +7 -4
- package/src/capabilities.js +18 -17
- package/src/capabilities.ts +38 -0
- package/src/checkpoints.js +1241 -1127
- package/src/checkpoints.ts +1377 -0
- package/src/cliMode.js +707 -755
- package/src/cliMode.ts +780 -0
- package/src/codebase/repoMap.js +656 -0
- package/src/codebase/repoMap.ts +664 -0
- package/src/commands.js +3651 -2514
- package/src/commands.ts +3985 -0
- package/src/compiledSkills.js +8052 -8054
- package/src/compiledSkills.ts +8078 -0
- package/src/config.js +389 -250
- package/src/config.ts +451 -0
- package/src/configVault.js +113 -19
- package/src/configVault.ts +103 -19
- package/src/contextManager.js +473 -557
- package/src/contextManager.ts +599 -0
- package/src/continuum/adapters/antigravity.js +8 -3
- package/src/continuum/adapters/antigravity.ts +8 -3
- package/src/continuum/compactor.js +2 -1
- package/src/continuum/compactor.ts +2 -1
- package/src/continuum/sanitizer.js +33 -4
- package/src/continuum/sanitizer.ts +32 -4
- package/src/continuum/ui/continuumPicker.js +0 -2
- package/src/continuum/ui/continuumPicker.ts +0 -2
- package/src/continuum/ui/continuumPickerView.js +3 -4
- package/src/continuum/ui/continuumPickerView.ts +7 -22
- package/src/core/contextCompactor.js +88 -7
- package/src/core/contextCompactor.ts +87 -8
- package/src/cortex/vectorDb.js +26 -15
- package/src/cortex/vectorDb.ts +26 -16
- package/src/creative/liveBridge.js +10 -7
- package/src/creative/liveBridge.ts +11 -7
- package/src/creative/studioScripts.js +17 -6
- package/src/creative/studioScripts.ts +15 -6
- package/src/decideTools.js +7 -2
- package/src/decideTools.ts +7 -2
- package/src/decisionPolicy.js +26 -6
- package/src/decisionPolicy.ts +24 -6
- package/src/designPalettes.js +72 -84
- package/src/designPalettes.ts +111 -0
- package/src/devMode.js +2 -2
- package/src/devMode.ts +6 -0
- package/src/diffReview.js +370 -0
- package/src/diffReview.ts +407 -0
- package/src/documentEngine/antiSlopAuditor.js +10 -5
- package/src/documentEngine/antiSlopAuditor.ts +11 -5
- package/src/documentEngine/documentForge.js +47 -15
- package/src/documentEngine/documentForge.ts +43 -14
- package/src/dynamicCatalogue.js +311 -11
- package/src/dynamicCatalogue.ts +331 -11
- package/src/embodimentSession.js +143 -154
- package/src/embodimentSession.ts +173 -0
- package/src/engines/design.js +2 -1
- package/src/engines/design.ts +2 -1
- package/src/engines/film.js +4 -4
- package/src/engines/film.ts +2 -2
- package/src/engines/installer.js +60 -29
- package/src/engines/installer.ts +73 -22
- package/src/engines/light.js +2 -1
- package/src/engines/light.ts +2 -1
- package/src/engines/registry.js +1 -1
- package/src/engines/registry.ts +1 -1
- package/src/engines/reverseHarness.js +4 -3
- package/src/engines/reverseHarness.ts +4 -3
- package/src/enterprisePolicy.js +660 -0
- package/src/enterprisePolicy.ts +728 -0
- package/src/entrypoint.js +514 -268
- package/src/entrypoint.ts +607 -0
- package/src/gitSnapshot.js +417 -312
- package/src/gitSnapshot.ts +500 -0
- package/src/headlessCli.js +326 -14
- package/src/headlessCli.ts +323 -13
- package/src/historyPruner.js +3 -2
- package/src/historyPruner.ts +3 -2
- package/src/hooks.js +250 -26
- package/src/hooks.ts +239 -26
- package/src/ignoreRules.js +297 -0
- package/src/ignoreRules.ts +308 -0
- package/src/implementationPlan.js +28 -17
- package/src/implementationPlan.ts +29 -17
- package/src/infra/atomicWriter.js +96 -20
- package/src/infra/atomicWriter.ts +112 -20
- package/src/launchIntent.js +14 -3
- package/src/launchIntent.ts +14 -3
- package/src/licensing/entitlements.js +553 -237
- package/src/licensing/entitlements.ts +590 -0
- package/src/licensing/policy.js +17 -1
- package/src/licensing/policy.ts +31 -0
- package/src/lsp/lspCatalog.js +398 -0
- package/src/lsp/lspCatalog.ts +452 -0
- package/src/lsp/lspClient.js +699 -0
- package/src/lsp/lspClient.ts +799 -0
- package/src/lsp/lspProtocol.js +121 -0
- package/src/lsp/lspProtocol.ts +140 -0
- package/src/mcp/mcpClient.js +69 -8
- package/src/mcp/mcpClient.ts +66 -9
- package/src/mcp/mcpRegistry.js +180 -7
- package/src/mcp/mcpRegistry.ts +171 -7
- package/src/mcp/mcpSecurity.js +6 -7
- package/src/mcp/mcpSecurity.ts +7 -6
- package/src/memory/episodicStore.js +2 -5
- package/src/memory/episodicStore.ts +2 -5
- package/src/memory/scopedFacts.js +1 -1
- package/src/memory/scopedFacts.ts +1 -1
- package/src/memory/symbolFolder.js +1 -1
- package/src/memory/symbolFolder.ts +1 -1
- package/src/memory.js +80 -32
- package/src/memory.ts +111 -0
- package/src/memoryManager.js +151 -143
- package/src/memoryManager.ts +182 -0
- package/src/modelCatalogue.js +172 -195
- package/src/modelCatalogue.ts +201 -0
- package/src/modelIds.js +8 -27
- package/src/modelIds.ts +33 -0
- package/src/modelRouter.js +1 -1
- package/src/modelRouter.ts +1 -1
- package/src/modelVariants.js +600 -0
- package/src/modelVariants.ts +663 -0
- package/src/observer/evidence.js +15 -5
- package/src/observer/evidence.ts +15 -5
- package/src/osKeychain.js +79 -17
- package/src/osKeychain.ts +64 -17
- package/src/outputStore.js +210 -156
- package/src/outputStore.ts +321 -0
- package/src/perception.js +3 -2
- package/src/perception.ts +3 -2
- package/src/planCache.js +5 -8
- package/src/planCache.ts +5 -8
- package/src/plugins/pluginManager.js +689 -461
- package/src/plugins/pluginManager.ts +807 -0
- package/src/plugins/pluginRunner.js +82 -37
- package/src/plugins/pluginRunner.ts +98 -0
- package/src/plugins/pluginSkills.js +47 -9
- package/src/plugins/pluginSkills.ts +46 -8
- package/src/pluginsFactory/discovery.js +0 -1
- package/src/pluginsFactory/discovery.ts +0 -1
- package/src/pluginsFactory/pluginsFactory.js +19 -11
- package/src/pluginsFactory/pluginsFactory.ts +18 -11
- package/src/pluginsFactory/templates.js +17 -4
- package/src/pluginsFactory/templates.ts +17 -4
- package/src/prWorkflow.js +337 -0
- package/src/prWorkflow.ts +376 -0
- package/src/procSignal.js +1 -2
- package/src/procSignal.ts +1 -3
- package/src/projectInstructions.js +319 -0
- package/src/projectInstructions.ts +361 -0
- package/src/promptMentions.js +2 -2
- package/src/promptMentions.ts +2 -2
- package/src/providers/acp.js +235 -50
- package/src/providers/acp.ts +241 -51
- package/src/providers/anthropic.js +431 -400
- package/src/providers/anthropic.ts +493 -0
- package/src/providers/antigravity.js +575 -358
- package/src/providers/antigravity.ts +565 -359
- package/src/providers/base.js +229 -320
- package/src/providers/base.ts +348 -0
- package/src/providers/byokHttp.js +183 -30
- package/src/providers/byokHttp.ts +232 -32
- package/src/providers/byokStream.js +287 -70
- package/src/providers/byokStream.ts +282 -71
- package/src/providers/dashscope-byok.js +123 -89
- package/src/providers/dashscope-byok.ts +142 -0
- package/src/providers/deepseek.js +82 -72
- package/src/providers/deepseek.ts +108 -0
- package/src/providers/factory.js +76 -28
- package/src/providers/factory.ts +82 -0
- package/src/providers/gemini.js +279 -278
- package/src/providers/gemini.ts +313 -0
- package/src/providers/loopGuard.js +9 -5
- package/src/providers/loopGuard.ts +10 -5
- package/src/providers/moonshot.js +103 -72
- package/src/providers/moonshot.ts +122 -0
- package/src/providers/muse.js +82 -152
- package/src/providers/muse.ts +122 -0
- package/src/providers/ollama.js +360 -106
- package/src/providers/ollama.ts +408 -0
- package/src/providers/openai-compatible.js +168 -95
- package/src/providers/openai-compatible.ts +200 -0
- package/src/providers/openai.js +45 -15
- package/src/providers/openai.ts +52 -0
- package/src/providers/openrouter.js +342 -113
- package/src/providers/openrouter.ts +333 -116
- package/src/providers/pi.js +6 -0
- package/src/providers/pi.ts +6 -0
- package/src/providers/qwen-byok.js +122 -87
- package/src/providers/qwen-byok.ts +141 -0
- package/src/providers/toolContracts.js +40 -14
- package/src/providers/toolContracts.ts +35 -14
- package/src/providers/wireNormalizer.js +144 -11
- package/src/providers/wireNormalizer.ts +132 -12
- package/src/providers/xai.js +80 -72
- package/src/providers/xai.ts +103 -0
- package/src/provisioning/capabilityConsent.js +29 -11
- package/src/provisioning/capabilityConsent.ts +42 -0
- package/src/provisioning/capabilityProvisioner.js +309 -197
- package/src/provisioning/capabilityProvisioner.ts +413 -0
- package/src/provisioning/capabilityTools.js +31 -17
- package/src/provisioning/capabilityTools.ts +43 -0
- package/src/provisioning/npmInstall.js +33 -5
- package/src/provisioning/npmInstall.ts +33 -5
- package/src/reliability/assetEvidence.js +4 -2
- package/src/reliability/assetEvidence.ts +4 -2
- package/src/reporting.js +328 -326
- package/src/reporting.ts +482 -0
- package/src/sandbox.js +526 -554
- package/src/sandbox.ts +590 -0
- package/src/sandboxPolicy.js +95 -16
- package/src/sandboxPolicy.ts +97 -16
- package/src/sessionJournal.js +32 -6
- package/src/sessionJournal.ts +27 -6
- package/src/sessionStore.js +1 -2
- package/src/sessionStore.ts +2 -0
- package/src/skills/skillResourceSafety.js +19 -8
- package/src/skills/skillResourceSafety.ts +16 -7
- package/src/skillsManager.js +3 -3
- package/src/skillsManager.ts +3 -3
- package/src/slopDetector.js +202 -265
- package/src/slopDetector.ts +279 -0
- package/src/smartToolsUse.js +38 -8
- package/src/smartToolsUse.ts +39 -11
- package/src/stallGuard.js +53 -23
- package/src/stallGuard.ts +53 -23
- package/src/subagentJournal.js +6 -4
- package/src/subagentJournal.ts +6 -4
- package/src/taskBuffer.js +91 -40
- package/src/taskBuffer.ts +94 -0
- package/src/textDiff.js +6 -1
- package/src/textDiff.ts +6 -1
- package/src/timeMachine.js +7 -1
- package/src/timeMachine.ts +7 -1
- package/src/tokenTracker.js +120 -38
- package/src/tokenTracker.ts +110 -38
- package/src/toolPacks.js +8 -1
- package/src/toolPacks.ts +8 -1
- package/src/tools/applyPatch.js +610 -0
- package/src/tools/applyPatch.ts +661 -0
- package/src/tools/archive.js +372 -48
- package/src/tools/archive.ts +372 -48
- package/src/tools/astryxOracle.js +77 -72
- package/src/tools/astryxOracle.ts +95 -0
- package/src/tools/axSnapshot.js +127 -147
- package/src/tools/axSnapshot.ts +174 -0
- package/src/tools/backgroundTask.js +86 -0
- package/src/tools/backgroundTask.ts +121 -0
- package/src/tools/blenderAutomator.js +434 -390
- package/src/tools/blenderAutomator.ts +623 -0
- package/src/tools/checkSystemSpecs.js +54 -61
- package/src/tools/checkSystemSpecs.ts +73 -0
- package/src/tools/clipboard.js +42 -31
- package/src/tools/clipboard.ts +61 -0
- package/src/tools/codeSearchAst.js +359 -91
- package/src/tools/codeSearchAst.ts +399 -0
- package/src/tools/codeSearcher.js +179 -37
- package/src/tools/codeSearcher.ts +188 -33
- package/src/tools/codeTools.js +208 -245
- package/src/tools/codeTools.ts +271 -0
- package/src/tools/codebaseSearch.js +5 -0
- package/src/tools/codebaseSearch.ts +5 -0
- package/src/tools/computerUse.js +7 -3
- package/src/tools/computerUse.ts +7 -3
- package/src/tools/creativeApps.js +13 -8
- package/src/tools/creativeApps.ts +22 -9
- package/src/tools/deferredMcpSearch.js +26 -14
- package/src/tools/deferredMcpSearch.ts +26 -14
- package/src/tools/desktopAct.js +185 -197
- package/src/tools/desktopAct.ts +257 -0
- package/src/tools/desktopOpen.js +69 -10
- package/src/tools/desktopOpen.ts +70 -11
- package/src/tools/documentForge.js +167 -82
- package/src/tools/documentForge.ts +169 -84
- package/src/tools/dynamicLoader.js +4 -40
- package/src/tools/dynamicLoader.ts +13 -0
- package/src/tools/executeProceduralMedia.js +117 -86
- package/src/tools/executeProceduralMedia.ts +135 -0
- package/src/tools/fileTracker.js +74 -0
- package/src/tools/fileTracker.ts +94 -0
- package/src/tools/fsDelete.js +57 -47
- package/src/tools/fsDelete.ts +80 -0
- package/src/tools/fsEdit.js +250 -61
- package/src/tools/fsEdit.ts +265 -63
- package/src/tools/fsFind.js +8 -5
- package/src/tools/fsFind.ts +7 -4
- package/src/tools/fsMove.js +79 -52
- package/src/tools/fsMove.ts +108 -0
- package/src/tools/fsRead.js +163 -18
- package/src/tools/fsRead.ts +169 -18
- package/src/tools/fsSearch.js +5 -0
- package/src/tools/fsSearch.ts +5 -0
- package/src/tools/fsWrite.js +31 -11
- package/src/tools/fsWrite.ts +31 -13
- package/src/tools/gameAiBehaviorTree.js +74 -91
- package/src/tools/gameAiBehaviorTree.ts +219 -0
- package/src/tools/gameAnimationRig.js +128 -147
- package/src/tools/gameAnimationRig.ts +215 -0
- package/src/tools/gameAssetFetcher.js +403 -441
- package/src/tools/gameAssetFetcher.ts +477 -0
- package/src/tools/gameAssetHarvester.js +171 -200
- package/src/tools/gameAssetHarvester.ts +261 -0
- package/src/tools/gameAudioSynth.js +223 -259
- package/src/tools/gameAudioSynth.ts +255 -0
- package/src/tools/gameBuilder.js +100 -91
- package/src/tools/gameBuilder.ts +913 -0
- package/src/tools/gameCanvasAudit.js +138 -96
- package/src/tools/gameCanvasAudit.ts +157 -0
- package/src/tools/gameCinematicSequencer.js +93 -111
- package/src/tools/gameCinematicSequencer.ts +165 -0
- package/src/tools/gameDataForge.js +115 -118
- package/src/tools/gameDataForge.ts +151 -0
- package/src/tools/gameDialogueTreeGen.js +125 -156
- package/src/tools/gameDialogueTreeGen.ts +159 -0
- package/src/tools/gameEconomyBalancer.js +150 -153
- package/src/tools/gameEconomyBalancer.ts +186 -0
- package/src/tools/gameEntitySpawner.js +91 -108
- package/src/tools/gameEntitySpawner.ts +209 -0
- package/src/tools/gameLoreForge.js +125 -147
- package/src/tools/gameLoreForge.ts +162 -0
- package/src/tools/gameQuestArcBuilder.js +105 -144
- package/src/tools/gameQuestArcBuilder.ts +147 -0
- package/src/tools/gameSceneBuilder.js +143 -149
- package/src/tools/gameSceneBuilder.ts +196 -0
- package/src/tools/gameShaderForge.js +83 -101
- package/src/tools/gameShaderForge.ts +181 -0
- package/src/tools/gameTilemapGenerator.js +99 -129
- package/src/tools/gameTilemapGenerator.ts +158 -0
- package/src/tools/gameUiHudBuilder.js +109 -129
- package/src/tools/gameUiHudBuilder.ts +300 -0
- package/src/tools/gameVfxEmitterGen.js +86 -89
- package/src/tools/gameVfxEmitterGen.ts +133 -0
- package/src/tools/gameWebRuntimeInspector.js +153 -86
- package/src/tools/gameWebRuntimeInspector.ts +167 -0
- package/src/tools/generateMediaViaApi.js +126 -22
- package/src/tools/generateMediaViaApi.ts +123 -22
- package/src/tools/gitExec.js +133 -86
- package/src/tools/gitExec.ts +146 -0
- package/src/tools/gitWorktree.js +115 -0
- package/src/tools/gitWorktree.ts +150 -0
- package/src/tools/godotAutomator.js +417 -394
- package/src/tools/godotAutomator.ts +530 -0
- package/src/tools/lspCodeIntel.js +217 -0
- package/src/tools/lspCodeIntel.ts +260 -0
- package/src/tools/manageLocalAiDependencies.js +242 -206
- package/src/tools/manageLocalAiDependencies.ts +288 -0
- package/src/tools/memoryRecall.js +62 -11
- package/src/tools/memoryRecall.ts +70 -13
- package/src/tools/memoryWrite.js +27 -14
- package/src/tools/memoryWrite.ts +30 -14
- package/src/tools/multiEdit.js +73 -63
- package/src/tools/multiEdit.ts +80 -65
- package/src/tools/nativeEngine.js +33 -18
- package/src/tools/nativeEngine.ts +31 -18
- package/src/tools/openSourceToolProvisioner.js +49 -14
- package/src/tools/openSourceToolProvisioner.ts +54 -15
- package/src/tools/osSandbox.js +202 -25
- package/src/tools/osSandbox.ts +192 -25
- package/src/tools/palmierAutomator.js +147 -95
- package/src/tools/palmierAutomator.ts +171 -0
- package/src/tools/payloadSanitizer.js +40 -8
- package/src/tools/payloadSanitizer.ts +39 -8
- package/src/tools/pdfReader.js +95 -104
- package/src/tools/pdfReader.ts +125 -0
- package/src/tools/peerAgent.js +96 -34
- package/src/tools/peerAgent.ts +114 -37
- package/src/tools/persistentShell.js +267 -144
- package/src/tools/persistentShell.ts +314 -0
- package/src/tools/pluginManager.js +84 -72
- package/src/tools/pluginManager.ts +109 -0
- package/src/tools/pluginsFactory.js +38 -6
- package/src/tools/pluginsFactory.ts +42 -6
- package/src/tools/printer.js +278 -296
- package/src/tools/printer.ts +326 -0
- package/src/tools/procTerm.js +96 -83
- package/src/tools/procTerm.ts +127 -0
- package/src/tools/processList.js +45 -48
- package/src/tools/processList.ts +73 -0
- package/src/tools/readNativeSkill.js +10 -8
- package/src/tools/readNativeSkill.ts +10 -8
- package/src/tools/registry.js +298 -286
- package/src/tools/registry.ts +486 -0
- package/src/tools/repoMap.js +46 -0
- package/src/tools/repoMap.ts +66 -0
- package/src/tools/requestDecision.js +10 -3
- package/src/tools/requestDecision.ts +10 -3
- package/src/tools/resolveAutomator.js +91 -17
- package/src/tools/resolveAutomator.ts +102 -17
- package/src/tools/reverseEngineering.js +168 -41
- package/src/tools/reverseEngineering.ts +161 -41
- package/src/tools/subagentOrchestrator.js +404 -348
- package/src/tools/subagentOrchestrator.ts +457 -0
- package/src/tools/sysRun.js +148 -51
- package/src/tools/sysRun.ts +142 -46
- package/src/tools/toolDispatch.js +24 -1
- package/src/tools/toolDispatch.ts +21 -1
- package/src/tools/toolForge.js +84 -67
- package/src/tools/toolForge.ts +102 -0
- package/src/tools/toolOutputStore.js +62 -23
- package/src/tools/toolOutputStore.ts +56 -23
- package/src/tools/toolPathSafety.js +262 -0
- package/src/tools/toolPathSafety.ts +308 -0
- package/src/tools/toolScanner.js +41 -10
- package/src/tools/toolScanner.ts +42 -10
- package/src/tools/toolSelfRepair.js +115 -34
- package/src/tools/toolSelfRepair.ts +122 -34
- package/src/tools/uiForge.js +71 -6
- package/src/tools/uiForge.ts +74 -6
- package/src/tools/viewImage.js +62 -17
- package/src/tools/viewImage.ts +57 -12
- package/src/tools/visionInspector.js +15 -3
- package/src/tools/visionInspector.ts +15 -3
- package/src/tools/walkerSafety.js +2 -0
- package/src/tools/walkerSafety.ts +2 -0
- package/src/tools/webFetch.js +110 -12
- package/src/tools/webFetch.ts +110 -13
- package/src/toolsList.js +5 -0
- package/src/toolsList.ts +5 -0
- package/src/tui/ask.js +159 -168
- package/src/tui/ask.ts +259 -0
- package/src/tui/banner.js +3 -2
- package/src/tui/banner.ts +3 -2
- package/src/tui/block.js +0 -1
- package/src/tui/block.ts +0 -1
- package/src/tui/chatRenderer.js +1193 -1441
- package/src/tui/chatRenderer.ts +1336 -0
- package/src/tui/clipboardImage.js +36 -12
- package/src/tui/clipboardImage.ts +39 -13
- package/src/tui/clipboardSync.js +34 -9
- package/src/tui/clipboardSync.ts +38 -9
- package/src/tui/codeProgress.js +0 -1
- package/src/tui/codeProgress.ts +0 -1
- package/src/tui/completion.js +395 -371
- package/src/tui/completion.ts +574 -0
- package/src/tui/composerControls.js +113 -19
- package/src/tui/composerControls.ts +124 -19
- package/src/tui/consoleGuard.js +39 -11
- package/src/tui/consoleGuard.ts +38 -11
- package/src/tui/dialogs.js +864 -717
- package/src/tui/dialogs.ts +984 -0
- package/src/tui/diff.js +205 -195
- package/src/tui/diff.ts +336 -0
- package/src/tui/history.js +143 -108
- package/src/tui/history.ts +167 -0
- package/src/tui/home.js +165 -161
- package/src/tui/home.ts +251 -0
- package/src/tui/invocation.js +58 -65
- package/src/tui/invocation.ts +117 -0
- package/src/tui/keys.js +437 -420
- package/src/tui/keys.ts +597 -0
- package/src/tui/lineEditor.js +477 -432
- package/src/tui/lineEditor.ts +542 -0
- package/src/tui/messageActionPlacement.js +0 -1
- package/src/tui/messageActionPlacement.ts +0 -1
- package/src/tui/messageInteraction.js +2 -5
- package/src/tui/messageInteraction.ts +2 -5
- package/src/tui/modelPicker.js +1 -3
- package/src/tui/modelPicker.ts +4 -6
- package/src/tui/observerPicker.js +0 -2
- package/src/tui/observerPicker.ts +0 -2
- package/src/tui/overlay.js +3 -2
- package/src/tui/overlay.ts +3 -2
- package/src/tui/prompt.js +1816 -2151
- package/src/tui/prompt.ts +1870 -0
- package/src/tui/runningLight.js +0 -1
- package/src/tui/runningLight.ts +0 -1
- package/src/tui/selectList.js +365 -337
- package/src/tui/selectList.ts +441 -0
- package/src/tui/sessionPicker.js +3 -3
- package/src/tui/sessionPicker.ts +3 -3
- package/src/tui/sessionPickerView.js +7 -3
- package/src/tui/sessionPickerView.ts +10 -22
- package/src/tui/sessionSidebar.js +3 -1
- package/src/tui/sessionSidebar.ts +4 -1
- package/src/tui/setup.js +17 -5
- package/src/tui/setup.ts +19 -5
- package/src/tui/skillAuthoring.js +0 -2
- package/src/tui/skillAuthoring.ts +0 -3
- package/src/tui/stageSurface.js +829 -909
- package/src/tui/stageSurface.ts +1003 -0
- package/src/tui/statusLine.js +7 -4
- package/src/tui/statusLine.ts +7 -3
- package/src/tui/terminalInputFramer.js +82 -69
- package/src/tui/terminalInputFramer.ts +116 -0
- package/src/tui/text.js +25 -10
- package/src/tui/text.ts +24 -10
- package/src/tui/textLayout.js +0 -1
- package/src/tui/textLayout.ts +0 -1
- package/src/tui/theme.js +245 -250
- package/src/tui/theme.ts +441 -0
- package/src/tui/thinkingBox.js +0 -1
- package/src/tui/thinkingBox.ts +0 -1
- package/src/tui/toolOutputNormalizer.js +2 -3
- package/src/tui/toolOutputNormalizer.ts +4 -3
- package/src/tui/transcript.js +239 -216
- package/src/tui/transcript.ts +324 -0
- package/src/tui/turnRail.js +53 -54
- package/src/tui/turnRail.ts +51 -49
- package/src/tui/usageCard.js +0 -2
- package/src/tui/usageCard.ts +0 -2
- package/src/tui/viewport.js +4 -4
- package/src/tui/viewport.ts +5 -5
- package/src/tui/workspaceIdentity.js +2 -1
- package/src/tui/workspaceIdentity.ts +2 -1
- package/src/tui/workspaceSwitch.js +4 -2
- package/src/tui/workspaceSwitch.ts +5 -2
- package/src/types/contracts.ts +4 -1
- package/src/uncertainty.js +8 -3
- package/src/uncertainty.ts +8 -3
- package/src/utils/browserOpen.js +107 -0
- package/src/utils/browserOpen.ts +129 -0
- package/src/utils/cli_ui.js +0 -0
- package/src/utils/cli_ui.ts +158 -0
- package/src/utils/paths.js +8 -5
- package/src/utils/paths.ts +9 -7
- package/src/utils/winSpawn.js +248 -0
- package/src/utils/winSpawn.ts +275 -0
- package/src/verification/boundedExplorer.js +138 -107
- package/src/verification/boundedExplorer.ts +154 -0
- package/src/verification/byokSmokeProbe.js +193 -0
- package/src/verification/byokSmokeProbe.ts +234 -0
- package/src/verification/cliProbe.js +144 -110
- package/src/verification/cliProbe.ts +170 -0
- package/src/verification/featureMap.js +105 -75
- package/src/verification/featureMap.ts +124 -0
- package/src/verification/interactivePty.js +195 -100
- package/src/verification/interactivePty.ts +333 -0
- package/src/verification/propertyProbe.js +109 -101
- package/src/verification/propertyProbe.ts +159 -0
- package/src/verification/ptyProbe.js +168 -73
- package/src/verification/ptyProbe.ts +254 -0
- package/src/verification/skillCatalog.js +25 -25
- package/src/verification/skillCatalog.ts +66 -0
- package/src/verification/statechart.js +140 -127
- package/src/verification/statechart.ts +196 -0
- package/src/verification/uiRuntime.js +80 -49
- package/src/verification/uiRuntime.ts +88 -0
- package/src/version.js +37 -32
- package/src/version.ts +45 -0
- package/src/vfeTracker.js +9 -3
- package/src/vfeTracker.ts +9 -3
- package/src/web/guiLauncher.js +89 -0
- package/src/web/guiLauncher.ts +119 -0
- package/src/web/skybridgeBrowserBridge.js +256 -0
- package/src/web/skybridgeBrowserBridge.ts +285 -0
- package/src/web/skybridgeBrowserMcp.js +730 -0
- package/src/web/skybridgeBrowserMcp.ts +813 -0
- package/src/web/skybridgeClientScript.js +3951 -0
- package/src/web/skybridgeClientScript.ts +3952 -0
- package/src/web/skybridgeServer.js +2622 -0
- package/src/web/skybridgeServer.ts +2787 -0
- package/src/web/skybridgeStyles.js +827 -0
- package/src/web/skybridgeStyles.ts +828 -0
- package/src/web/skybridgeUi.js +472 -0
- package/src/web/skybridgeUi.ts +485 -0
- package/src/worktreeManager.js +511 -0
- package/src/worktreeManager.ts +546 -0
- package/src/zeroCostFailover.js +168 -0
- package/src/zeroCostFailover.ts +198 -0
- package/src/zeroCostRouting.js +391 -0
- package/src/zeroCostRouting.ts +437 -0
- package/src/agentLoop.d.ts +0 -65
- package/src/auditLog.d.ts +0 -3
- package/src/checkpoints.d.ts +0 -4
- package/src/compiledSkills.d.ts +0 -5
- package/src/config.d.ts +0 -2
- package/src/contextManager.d.ts +0 -14
- package/src/designPalettes.d.ts +0 -2
- package/src/devMode.d.ts +0 -1
- package/src/embodimentSession.d.ts +0 -2
- package/src/licensing/entitlements.d.ts +0 -14
- package/src/memory.d.ts +0 -13
- package/src/memoryManager.d.ts +0 -1
- package/src/modelCatalogue.d.ts +0 -6
- package/src/modelIds.d.ts +0 -2
- package/src/outputStore.d.ts +0 -4
- package/src/plugins/pluginManager.d.ts +0 -7
- package/src/providers/antigravity.d.ts +0 -19
- package/src/providers/base.d.ts +0 -94
- package/src/providers/factory.d.ts +0 -1
- package/src/provisioning/capabilityProvisioner.d.ts +0 -12
- package/src/sandbox.d.ts +0 -1
- package/src/slopDetector.d.ts +0 -3
- package/src/taskBuffer.d.ts +0 -1
- package/src/tools/desktopAct.d.ts +0 -10
- package/src/tools/registry.d.ts +0 -5
- package/src/tui/chatRenderer.d.ts +0 -27
- package/src/tui/diff.d.ts +0 -3
- package/src/utils/cli_ui.d.ts +0 -19
- package/src/utils/paths.d.ts +0 -3
- package/src/verification/skillCatalog.d.ts +0 -1
- package/src/version.d.ts +0 -1
package/src/tokenTracker.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { loadConfig } from './config.js';
|
|
@@ -9,10 +10,29 @@ function withUsageLock(fn) {
|
|
|
9
10
|
usageQueue = run.then(() => { }, () => { });
|
|
10
11
|
return run;
|
|
11
12
|
}
|
|
13
|
+
let usageTempCounter = 0;
|
|
12
14
|
function writeUsageFile(file, payload) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
16
|
+
const temp = `${file}.tmp_${process.pid}_${++usageTempCounter}_${crypto.randomBytes(4).toString('hex')}`;
|
|
17
|
+
try {
|
|
18
|
+
const fd = fs.openSync(temp, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600);
|
|
19
|
+
try {
|
|
20
|
+
fs.writeFileSync(fd, JSON.stringify(payload, null, 2), 'utf8');
|
|
21
|
+
fs.fsyncSync(fd);
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
fs.closeSync(fd);
|
|
25
|
+
}
|
|
26
|
+
fs.renameSync(temp, file);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
try {
|
|
30
|
+
if (fs.existsSync(temp))
|
|
31
|
+
fs.unlinkSync(temp);
|
|
32
|
+
}
|
|
33
|
+
catch { /* ignore */ }
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
16
36
|
}
|
|
17
37
|
function localDateKey(when = new Date()) {
|
|
18
38
|
const pad = (n) => String(n).padStart(2, '0');
|
|
@@ -42,12 +62,28 @@ export class TokenTracker {
|
|
|
42
62
|
this.ensureUsageDir();
|
|
43
63
|
}
|
|
44
64
|
getPricing(promptTokens = 0) {
|
|
45
|
-
const provider = this.config.provider?.toLowerCase();
|
|
65
|
+
const provider = this.config.provider?.toLowerCase() || '';
|
|
46
66
|
const model = this.config.model?.toLowerCase() || '';
|
|
67
|
+
// Strictly zero-cost routes: local Ollama, :free models, OpenRouter free router, ACP peers, Antigravity
|
|
68
|
+
if (provider === 'ollama'
|
|
69
|
+
|| provider === 'openrouter-free'
|
|
70
|
+
|| provider === 'acp'
|
|
71
|
+
|| provider.startsWith('acp/')
|
|
72
|
+
|| provider === 'antigravity'
|
|
73
|
+
|| provider === 'agy'
|
|
74
|
+
|| model === 'openrouter/free'
|
|
75
|
+
|| model.endsWith(':free')) {
|
|
76
|
+
return [0.00, 0.00];
|
|
77
|
+
}
|
|
78
|
+
if (provider === 'groq' || provider === 'cerebras') {
|
|
79
|
+
return [0.00, 0.00];
|
|
80
|
+
}
|
|
47
81
|
if (provider === 'deepseek') {
|
|
48
82
|
if (model.includes('pro'))
|
|
49
83
|
return [0.435, 0.87];
|
|
50
|
-
if (model.includes('
|
|
84
|
+
if (model.includes('reasoner'))
|
|
85
|
+
return [0.55, 2.19];
|
|
86
|
+
if (model.includes('flash') || model.includes('chat'))
|
|
51
87
|
return [0.14, 0.28];
|
|
52
88
|
return [0.14, 0.28];
|
|
53
89
|
}
|
|
@@ -61,7 +97,7 @@ export class TokenTracker {
|
|
|
61
97
|
return [1.25, 3.75];
|
|
62
98
|
if (model.includes('plus'))
|
|
63
99
|
return [0.32, 1.28];
|
|
64
|
-
if (model.includes('flash'))
|
|
100
|
+
if (model.includes('flash') || model.includes('turbo'))
|
|
65
101
|
return [0.19, 1.13];
|
|
66
102
|
return [0.32, 1.28];
|
|
67
103
|
}
|
|
@@ -75,6 +111,11 @@ export class TokenTracker {
|
|
|
75
111
|
return [2.50, 15.00];
|
|
76
112
|
if (model.includes('luna'))
|
|
77
113
|
return [1.00, 1.00];
|
|
114
|
+
if (model.includes('gpt-4o-mini') || model.includes('gpt-4.1-mini') || model.includes('o3-mini') || model.includes('o4-mini')) {
|
|
115
|
+
return [0.75, 4.50];
|
|
116
|
+
}
|
|
117
|
+
if (model.includes('gpt-4o') || model.includes('gpt-4.1'))
|
|
118
|
+
return [2.50, 10.00];
|
|
78
119
|
if (model.includes('mini'))
|
|
79
120
|
return [0.75, 4.50];
|
|
80
121
|
return [5.00, 30.00];
|
|
@@ -84,8 +125,9 @@ export class TokenTracker {
|
|
|
84
125
|
return [10.00, 50.00];
|
|
85
126
|
if (model.includes('opus'))
|
|
86
127
|
return [5.00, 25.00];
|
|
87
|
-
if (model.includes('sonnet-4-6'))
|
|
128
|
+
if (model.includes('sonnet-4-6') || model.includes('sonnet-4-5') || model.includes('3-7-sonnet') || model.includes('3-5-sonnet')) {
|
|
88
129
|
return [3.00, 15.00];
|
|
130
|
+
}
|
|
89
131
|
if (model.includes('sonnet'))
|
|
90
132
|
return [2.00, 10.00];
|
|
91
133
|
if (model.includes('haiku'))
|
|
@@ -97,17 +139,41 @@ export class TokenTracker {
|
|
|
97
139
|
return [2.00, 12.00];
|
|
98
140
|
if (model.includes('flash-lite'))
|
|
99
141
|
return [0.25, 1.50];
|
|
142
|
+
if (model.includes('2.5-flash') || model.includes('2.0-flash') || model.includes('1.5-flash'))
|
|
143
|
+
return [0.15, 0.60];
|
|
100
144
|
if (model.includes('3.6-flash') || model.includes('3-6-flash'))
|
|
101
145
|
return [1.50, 7.50];
|
|
102
146
|
if (model.includes('flash'))
|
|
103
147
|
return [1.50, 9.00];
|
|
104
148
|
return [1.50, 9.00];
|
|
105
149
|
}
|
|
106
|
-
if (provider === '
|
|
107
|
-
|
|
150
|
+
if (provider === 'mistral') {
|
|
151
|
+
if (model.includes('codestral') || model.includes('devstral'))
|
|
152
|
+
return [0.30, 0.90];
|
|
153
|
+
if (model.includes('large'))
|
|
154
|
+
return [2.00, 6.00];
|
|
155
|
+
return [0.20, 0.60];
|
|
108
156
|
}
|
|
109
|
-
if (provider === '
|
|
110
|
-
|
|
157
|
+
if (provider === 'xai') {
|
|
158
|
+
if (model.includes('mini'))
|
|
159
|
+
return [0.30, 0.50];
|
|
160
|
+
return [3.00, 15.00];
|
|
161
|
+
}
|
|
162
|
+
if (provider === 'moonshot') {
|
|
163
|
+
return [0.60, 2.50];
|
|
164
|
+
}
|
|
165
|
+
if (provider === 'openrouter') {
|
|
166
|
+
if (model.includes('deepseek'))
|
|
167
|
+
return [0.28, 0.56];
|
|
168
|
+
if (model.includes('qwen') || model.includes('llama') || model.includes('mistral'))
|
|
169
|
+
return [0.20, 0.60];
|
|
170
|
+
if (model.includes('haiku') || model.includes('mini') || model.includes('flash'))
|
|
171
|
+
return [0.50, 2.00];
|
|
172
|
+
if (model.includes('sonnet'))
|
|
173
|
+
return [3.00, 15.00];
|
|
174
|
+
if (model.includes('opus'))
|
|
175
|
+
return [5.00, 25.00];
|
|
176
|
+
return [1.00, 3.00];
|
|
111
177
|
}
|
|
112
178
|
return [5.00, 15.00];
|
|
113
179
|
}
|
|
@@ -133,15 +199,23 @@ export class TokenTracker {
|
|
|
133
199
|
return 0.5;
|
|
134
200
|
}
|
|
135
201
|
calculateCost(promptTokens, completionTokens, usageDetail = null) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
const
|
|
202
|
+
if (usageDetail && typeof usageDetail.costUsd === 'number' && Number.isFinite(usageDetail.costUsd) && usageDetail.costUsd >= 0) {
|
|
203
|
+
return usageDetail.costUsd;
|
|
204
|
+
}
|
|
205
|
+
const safePrompt = Number.isFinite(promptTokens) ? Math.max(0, Number(promptTokens)) : 0;
|
|
206
|
+
const safeCompletion = Number.isFinite(completionTokens) ? Math.max(0, Number(completionTokens)) : 0;
|
|
207
|
+
const [promptPrice, completionPrice] = this.getPricing(safePrompt);
|
|
208
|
+
const rawCached = Number(usageDetail?.cachedPromptTokens ?? 0);
|
|
209
|
+
const cachedTokens = Math.min(Number.isFinite(rawCached) ? Math.max(0, rawCached) : 0, safePrompt);
|
|
210
|
+
const rawWrite = Number(usageDetail?.cacheWriteTokens ?? 0);
|
|
211
|
+
const writeTokens = Math.min(Number.isFinite(rawWrite) ? Math.max(0, rawWrite) : 0, safePrompt - cachedTokens);
|
|
212
|
+
const fullPriceTokens = Math.max(0, safePrompt - cachedTokens - writeTokens);
|
|
213
|
+
const rawMult = Number(usageDetail?.cacheWriteMultiplier ?? 1.25);
|
|
214
|
+
const writeMultiplier = Number.isFinite(rawMult) && rawMult >= 0 ? rawMult : 1.25;
|
|
141
215
|
const promptCost = (fullPriceTokens / 1_000_000) * promptPrice +
|
|
142
216
|
(cachedTokens / 1_000_000) * promptPrice * this.cachedInputMultiplier() +
|
|
143
217
|
(writeTokens / 1_000_000) * promptPrice * writeMultiplier;
|
|
144
|
-
const completionCost = (
|
|
218
|
+
const completionCost = (safeCompletion / 1_000_000) * completionPrice;
|
|
145
219
|
return promptCost + completionCost;
|
|
146
220
|
}
|
|
147
221
|
getMediaPricing(provider = '', model = '', mediaType = 'image') {
|
|
@@ -184,22 +258,26 @@ export class TokenTracker {
|
|
|
184
258
|
this.budget = this.config.tokenBudget || { enabled: false };
|
|
185
259
|
this.applyEnforcedTaskLimit();
|
|
186
260
|
const unitPrice = this.getMediaPricing(provider, model, mediaType);
|
|
187
|
-
const
|
|
261
|
+
const safeUnits = Number.isFinite(quantityUnits) ? Math.max(0, Number(quantityUnits)) : 1;
|
|
262
|
+
const cost = unitPrice * safeUnits;
|
|
188
263
|
const equivalentTokens = Math.round(cost / 0.000002);
|
|
189
264
|
this.taskTokens += equivalentTokens;
|
|
190
265
|
this.sessionTokens = (this.sessionTokens || 0) + equivalentTokens;
|
|
191
266
|
this.taskCostUsd += cost;
|
|
192
267
|
this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
268
|
+
const { daily } = await withUsageLock(async () => {
|
|
269
|
+
const cumulative = await this.getCumulativeUsage();
|
|
270
|
+
const daily = await this.getDailyUsage();
|
|
271
|
+
daily.totalTokens += equivalentTokens;
|
|
272
|
+
daily.totalCalls += 1;
|
|
273
|
+
daily.totalCostUsd = (daily.totalCostUsd || 0) + cost;
|
|
274
|
+
await this.saveDailyUsage(daily);
|
|
275
|
+
cumulative.totalTokens += equivalentTokens;
|
|
276
|
+
cumulative.totalCalls += 1;
|
|
277
|
+
cumulative.totalCostUsd = (cumulative.totalCostUsd || 0) + cost;
|
|
278
|
+
await this.saveCumulativeUsage(cumulative);
|
|
279
|
+
return { daily };
|
|
280
|
+
});
|
|
203
281
|
if (!this.budget.enabled) {
|
|
204
282
|
return { allowed: true, used: daily.totalTokens, costUsd: daily.totalCostUsd, taskCostUsd: this.taskCostUsd, equivalentTokens };
|
|
205
283
|
}
|
|
@@ -306,16 +384,14 @@ export class TokenTracker {
|
|
|
306
384
|
writeUsageFile(this.getCumulativeFile(), usage);
|
|
307
385
|
}
|
|
308
386
|
async resetDailyUsage() {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
387
|
+
await withUsageLock(async () => {
|
|
388
|
+
fs.rmSync(this.getDailyFile(), { force: true });
|
|
389
|
+
});
|
|
313
390
|
}
|
|
314
391
|
async resetCumulativeUsage() {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
392
|
+
await withUsageLock(async () => {
|
|
393
|
+
fs.rmSync(this.getCumulativeFile(), { force: true });
|
|
394
|
+
});
|
|
319
395
|
}
|
|
320
396
|
async getReportedUsage() {
|
|
321
397
|
const daily = await this.getDailyUsage();
|
|
@@ -352,10 +428,16 @@ export class TokenTracker {
|
|
|
352
428
|
return { allowed: true, used: this.taskTokens, limit, projected };
|
|
353
429
|
}
|
|
354
430
|
extendBudget(extraTokens) {
|
|
431
|
+
if (!Number.isFinite(extraTokens) || extraTokens <= 0)
|
|
432
|
+
return;
|
|
355
433
|
if (this.budget && typeof this.budget === 'object') {
|
|
356
434
|
const current = Number(this.budget.maxTokensPerTask || 0);
|
|
357
435
|
if (current > 0) {
|
|
358
|
-
|
|
436
|
+
const next = Math.max(current + extraTokens, this.taskTokens + extraTokens);
|
|
437
|
+
this.budget.maxTokensPerTask = next;
|
|
438
|
+
if (this.enforcedTaskTokenLimit !== null) {
|
|
439
|
+
this.enforcedTaskTokenLimit = Math.floor(next);
|
|
440
|
+
}
|
|
359
441
|
}
|
|
360
442
|
}
|
|
361
443
|
}
|
|
@@ -439,7 +521,7 @@ export class TokenTracker {
|
|
|
439
521
|
this.taskTokens += freshStep;
|
|
440
522
|
this.sessionTokens = (this.sessionTokens || 0) + freshStep;
|
|
441
523
|
this.largestStepTokens = Math.max(this.largestStepTokens || 0, freshStep);
|
|
442
|
-
const cost = this.calculateCost(
|
|
524
|
+
const cost = this.calculateCost(pTokens, cTokens, usageDetail);
|
|
443
525
|
this.taskCostUsd += cost;
|
|
444
526
|
this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
|
|
445
527
|
const { daily, cumulative } = await withUsageLock(async () => {
|
package/src/tokenTracker.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { loadConfig } from './config.js';
|
|
@@ -12,10 +13,23 @@ function withUsageLock<T>(fn: () => Promise<T>): Promise<T> {
|
|
|
12
13
|
return run;
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
let usageTempCounter = 0;
|
|
15
17
|
function writeUsageFile(file: string, payload: unknown): void {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
19
|
+
const temp = `${file}.tmp_${process.pid}_${++usageTempCounter}_${crypto.randomBytes(4).toString('hex')}`;
|
|
20
|
+
try {
|
|
21
|
+
const fd = fs.openSync(temp, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600);
|
|
22
|
+
try {
|
|
23
|
+
fs.writeFileSync(fd, JSON.stringify(payload, null, 2), 'utf8');
|
|
24
|
+
fs.fsyncSync(fd);
|
|
25
|
+
} finally {
|
|
26
|
+
fs.closeSync(fd);
|
|
27
|
+
}
|
|
28
|
+
fs.renameSync(temp, file);
|
|
29
|
+
} catch (err: unknown) {
|
|
30
|
+
try { if (fs.existsSync(temp)) fs.unlinkSync(temp); } catch { /* ignore */ }
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
function localDateKey(when: Date = new Date()): string {
|
|
@@ -49,6 +63,7 @@ export interface UsageDetail {
|
|
|
49
63
|
cacheWriteTokens?: number;
|
|
50
64
|
cacheWriteMultiplier?: number;
|
|
51
65
|
uncachedPromptTokens?: number;
|
|
66
|
+
costUsd?: number;
|
|
52
67
|
[key: string]: unknown;
|
|
53
68
|
}
|
|
54
69
|
|
|
@@ -126,12 +141,31 @@ export class TokenTracker {
|
|
|
126
141
|
}
|
|
127
142
|
|
|
128
143
|
getPricing(promptTokens: number = 0): [number, number] {
|
|
129
|
-
const provider = this.config.provider?.toLowerCase();
|
|
144
|
+
const provider = this.config.provider?.toLowerCase() || '';
|
|
130
145
|
const model = this.config.model?.toLowerCase() || '';
|
|
131
146
|
|
|
147
|
+
// Strictly zero-cost routes: local Ollama, :free models, OpenRouter free router, ACP peers, Antigravity
|
|
148
|
+
if (
|
|
149
|
+
provider === 'ollama'
|
|
150
|
+
|| provider === 'openrouter-free'
|
|
151
|
+
|| provider === 'acp'
|
|
152
|
+
|| provider.startsWith('acp/')
|
|
153
|
+
|| provider === 'antigravity'
|
|
154
|
+
|| provider === 'agy'
|
|
155
|
+
|| model === 'openrouter/free'
|
|
156
|
+
|| model.endsWith(':free')
|
|
157
|
+
) {
|
|
158
|
+
return [0.00, 0.00];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (provider === 'groq' || provider === 'cerebras') {
|
|
162
|
+
return [0.00, 0.00];
|
|
163
|
+
}
|
|
164
|
+
|
|
132
165
|
if (provider === 'deepseek') {
|
|
133
166
|
if (model.includes('pro')) return [0.435, 0.87];
|
|
134
|
-
if (model.includes('
|
|
167
|
+
if (model.includes('reasoner')) return [0.55, 2.19];
|
|
168
|
+
if (model.includes('flash') || model.includes('chat')) return [0.14, 0.28];
|
|
135
169
|
return [0.14, 0.28];
|
|
136
170
|
}
|
|
137
171
|
|
|
@@ -143,7 +177,7 @@ export class TokenTracker {
|
|
|
143
177
|
if (provider === 'qwen' || provider === 'dashscope') {
|
|
144
178
|
if (model.includes('max')) return [1.25, 3.75];
|
|
145
179
|
if (model.includes('plus')) return [0.32, 1.28];
|
|
146
|
-
if (model.includes('flash')) return [0.19, 1.13];
|
|
180
|
+
if (model.includes('flash') || model.includes('turbo')) return [0.19, 1.13];
|
|
147
181
|
return [0.32, 1.28];
|
|
148
182
|
}
|
|
149
183
|
|
|
@@ -154,6 +188,10 @@ export class TokenTracker {
|
|
|
154
188
|
if (model.includes('sol')) return [5.00, 30.00];
|
|
155
189
|
if (model.includes('terra')) return [2.50, 15.00];
|
|
156
190
|
if (model.includes('luna')) return [1.00, 1.00];
|
|
191
|
+
if (model.includes('gpt-4o-mini') || model.includes('gpt-4.1-mini') || model.includes('o3-mini') || model.includes('o4-mini')) {
|
|
192
|
+
return [0.75, 4.50];
|
|
193
|
+
}
|
|
194
|
+
if (model.includes('gpt-4o') || model.includes('gpt-4.1')) return [2.50, 10.00];
|
|
157
195
|
if (model.includes('mini')) return [0.75, 4.50];
|
|
158
196
|
return [5.00, 30.00];
|
|
159
197
|
}
|
|
@@ -161,7 +199,9 @@ export class TokenTracker {
|
|
|
161
199
|
if (provider === 'anthropic') {
|
|
162
200
|
if (model.includes('fable') || model.includes('mythos')) return [10.00, 50.00];
|
|
163
201
|
if (model.includes('opus')) return [5.00, 25.00];
|
|
164
|
-
if (model.includes('sonnet-4-6'))
|
|
202
|
+
if (model.includes('sonnet-4-6') || model.includes('sonnet-4-5') || model.includes('3-7-sonnet') || model.includes('3-5-sonnet')) {
|
|
203
|
+
return [3.00, 15.00];
|
|
204
|
+
}
|
|
165
205
|
if (model.includes('sonnet')) return [2.00, 10.00];
|
|
166
206
|
if (model.includes('haiku')) return [1.00, 5.00];
|
|
167
207
|
return [2.00, 10.00];
|
|
@@ -170,17 +210,34 @@ export class TokenTracker {
|
|
|
170
210
|
if (provider === 'gemini') {
|
|
171
211
|
if (model.includes('pro')) return [2.00, 12.00];
|
|
172
212
|
if (model.includes('flash-lite')) return [0.25, 1.50];
|
|
213
|
+
if (model.includes('2.5-flash') || model.includes('2.0-flash') || model.includes('1.5-flash')) return [0.15, 0.60];
|
|
173
214
|
if (model.includes('3.6-flash') || model.includes('3-6-flash')) return [1.50, 7.50];
|
|
174
215
|
if (model.includes('flash')) return [1.50, 9.00];
|
|
175
216
|
return [1.50, 9.00];
|
|
176
217
|
}
|
|
177
218
|
|
|
178
|
-
if (provider === '
|
|
179
|
-
return [0.
|
|
219
|
+
if (provider === 'mistral') {
|
|
220
|
+
if (model.includes('codestral') || model.includes('devstral')) return [0.30, 0.90];
|
|
221
|
+
if (model.includes('large')) return [2.00, 6.00];
|
|
222
|
+
return [0.20, 0.60];
|
|
180
223
|
}
|
|
181
224
|
|
|
182
|
-
if (provider === '
|
|
183
|
-
return [0.
|
|
225
|
+
if (provider === 'xai') {
|
|
226
|
+
if (model.includes('mini')) return [0.30, 0.50];
|
|
227
|
+
return [3.00, 15.00];
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (provider === 'moonshot') {
|
|
231
|
+
return [0.60, 2.50];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (provider === 'openrouter') {
|
|
235
|
+
if (model.includes('deepseek')) return [0.28, 0.56];
|
|
236
|
+
if (model.includes('qwen') || model.includes('llama') || model.includes('mistral')) return [0.20, 0.60];
|
|
237
|
+
if (model.includes('haiku') || model.includes('mini') || model.includes('flash')) return [0.50, 2.00];
|
|
238
|
+
if (model.includes('sonnet')) return [3.00, 15.00];
|
|
239
|
+
if (model.includes('opus')) return [5.00, 25.00];
|
|
240
|
+
return [1.00, 3.00];
|
|
184
241
|
}
|
|
185
242
|
|
|
186
243
|
return [5.00, 15.00];
|
|
@@ -209,19 +266,27 @@ export class TokenTracker {
|
|
|
209
266
|
}
|
|
210
267
|
|
|
211
268
|
calculateCost(promptTokens: number, completionTokens: number, usageDetail: UsageDetail | null = null): number {
|
|
212
|
-
|
|
269
|
+
if (usageDetail && typeof usageDetail.costUsd === 'number' && Number.isFinite(usageDetail.costUsd) && usageDetail.costUsd >= 0) {
|
|
270
|
+
return usageDetail.costUsd;
|
|
271
|
+
}
|
|
272
|
+
const safePrompt = Number.isFinite(promptTokens) ? Math.max(0, Number(promptTokens)) : 0;
|
|
273
|
+
const safeCompletion = Number.isFinite(completionTokens) ? Math.max(0, Number(completionTokens)) : 0;
|
|
274
|
+
const [promptPrice, completionPrice] = this.getPricing(safePrompt);
|
|
213
275
|
|
|
214
|
-
const
|
|
215
|
-
const
|
|
216
|
-
const
|
|
276
|
+
const rawCached = Number(usageDetail?.cachedPromptTokens ?? 0);
|
|
277
|
+
const cachedTokens = Math.min(Number.isFinite(rawCached) ? Math.max(0, rawCached) : 0, safePrompt);
|
|
278
|
+
const rawWrite = Number(usageDetail?.cacheWriteTokens ?? 0);
|
|
279
|
+
const writeTokens = Math.min(Number.isFinite(rawWrite) ? Math.max(0, rawWrite) : 0, safePrompt - cachedTokens);
|
|
280
|
+
const fullPriceTokens = Math.max(0, safePrompt - cachedTokens - writeTokens);
|
|
217
281
|
|
|
218
|
-
const
|
|
282
|
+
const rawMult = Number(usageDetail?.cacheWriteMultiplier ?? 1.25);
|
|
283
|
+
const writeMultiplier = Number.isFinite(rawMult) && rawMult >= 0 ? rawMult : 1.25;
|
|
219
284
|
const promptCost =
|
|
220
285
|
(fullPriceTokens / 1_000_000) * promptPrice +
|
|
221
286
|
(cachedTokens / 1_000_000) * promptPrice * this.cachedInputMultiplier() +
|
|
222
287
|
(writeTokens / 1_000_000) * promptPrice * writeMultiplier;
|
|
223
288
|
|
|
224
|
-
const completionCost = (
|
|
289
|
+
const completionCost = (safeCompletion / 1_000_000) * completionPrice;
|
|
225
290
|
return promptCost + completionCost;
|
|
226
291
|
}
|
|
227
292
|
|
|
@@ -269,7 +334,8 @@ export class TokenTracker {
|
|
|
269
334
|
this.applyEnforcedTaskLimit();
|
|
270
335
|
|
|
271
336
|
const unitPrice = this.getMediaPricing(provider, model, mediaType);
|
|
272
|
-
const
|
|
337
|
+
const safeUnits = Number.isFinite(quantityUnits) ? Math.max(0, Number(quantityUnits)) : 1;
|
|
338
|
+
const cost = unitPrice * safeUnits;
|
|
273
339
|
|
|
274
340
|
const equivalentTokens = Math.round(cost / 0.000002);
|
|
275
341
|
|
|
@@ -278,17 +344,20 @@ export class TokenTracker {
|
|
|
278
344
|
this.taskCostUsd += cost;
|
|
279
345
|
this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
|
|
280
346
|
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
347
|
+
const { daily } = await withUsageLock(async () => {
|
|
348
|
+
const cumulative = await this.getCumulativeUsage();
|
|
349
|
+
const daily = await this.getDailyUsage();
|
|
350
|
+
daily.totalTokens += equivalentTokens;
|
|
351
|
+
daily.totalCalls += 1;
|
|
352
|
+
daily.totalCostUsd = (daily.totalCostUsd || 0) + cost;
|
|
353
|
+
await this.saveDailyUsage(daily);
|
|
287
354
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
355
|
+
cumulative.totalTokens += equivalentTokens;
|
|
356
|
+
cumulative.totalCalls += 1;
|
|
357
|
+
cumulative.totalCostUsd = (cumulative.totalCostUsd || 0) + cost;
|
|
358
|
+
await this.saveCumulativeUsage(cumulative);
|
|
359
|
+
return { daily };
|
|
360
|
+
});
|
|
292
361
|
|
|
293
362
|
if (!this.budget.enabled) {
|
|
294
363
|
return { allowed: true, used: daily.totalTokens, costUsd: daily.totalCostUsd, taskCostUsd: this.taskCostUsd, equivalentTokens };
|
|
@@ -406,17 +475,15 @@ export class TokenTracker {
|
|
|
406
475
|
}
|
|
407
476
|
|
|
408
477
|
async resetDailyUsage(): Promise<void> {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
478
|
+
await withUsageLock(async () => {
|
|
479
|
+
fs.rmSync(this.getDailyFile(), { force: true });
|
|
480
|
+
});
|
|
413
481
|
}
|
|
414
482
|
|
|
415
483
|
async resetCumulativeUsage(): Promise<void> {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
484
|
+
await withUsageLock(async () => {
|
|
485
|
+
fs.rmSync(this.getCumulativeFile(), { force: true });
|
|
486
|
+
});
|
|
420
487
|
}
|
|
421
488
|
|
|
422
489
|
async getReportedUsage(): Promise<{
|
|
@@ -467,10 +534,15 @@ export class TokenTracker {
|
|
|
467
534
|
}
|
|
468
535
|
|
|
469
536
|
extendBudget(extraTokens: number): void {
|
|
537
|
+
if (!Number.isFinite(extraTokens) || extraTokens <= 0) return;
|
|
470
538
|
if (this.budget && typeof this.budget === 'object') {
|
|
471
539
|
const current = Number(this.budget.maxTokensPerTask || 0);
|
|
472
540
|
if (current > 0) {
|
|
473
|
-
|
|
541
|
+
const next = Math.max(current + extraTokens, this.taskTokens + extraTokens);
|
|
542
|
+
this.budget.maxTokensPerTask = next;
|
|
543
|
+
if (this.enforcedTaskTokenLimit !== null) {
|
|
544
|
+
this.enforcedTaskTokenLimit = Math.floor(next);
|
|
545
|
+
}
|
|
474
546
|
}
|
|
475
547
|
}
|
|
476
548
|
}
|
|
@@ -567,7 +639,7 @@ export class TokenTracker {
|
|
|
567
639
|
this.sessionTokens = (this.sessionTokens || 0) + freshStep;
|
|
568
640
|
this.largestStepTokens = Math.max(this.largestStepTokens || 0, freshStep);
|
|
569
641
|
|
|
570
|
-
const cost = this.calculateCost(
|
|
642
|
+
const cost = this.calculateCost(pTokens, cTokens, usageDetail);
|
|
571
643
|
this.taskCostUsd += cost;
|
|
572
644
|
this.sessionCostUsd = (this.sessionCostUsd || 0) + cost;
|
|
573
645
|
|
package/src/toolPacks.js
CHANGED
|
@@ -114,6 +114,11 @@ export const PACKS = {
|
|
|
114
114
|
'peer_agent_delegate',
|
|
115
115
|
'code_search_ast',
|
|
116
116
|
'code_list_symbols',
|
|
117
|
+
'code_lsp',
|
|
118
|
+
'git_worktree',
|
|
119
|
+
'apply_patch',
|
|
120
|
+
'code_repo_map',
|
|
121
|
+
'task_bg',
|
|
117
122
|
'pdf_read'
|
|
118
123
|
],
|
|
119
124
|
reverse_engineering: [
|
|
@@ -377,7 +382,9 @@ export function routePacks(prompt, workspaceContext = null) {
|
|
|
377
382
|
for (const packName of PACK_NAMES) {
|
|
378
383
|
const matched = packName === 'reverse_engineering'
|
|
379
384
|
? isReverseEngineeringIntent(text)
|
|
380
|
-
:
|
|
385
|
+
: packName === 'web'
|
|
386
|
+
? isWebIntent(text)
|
|
387
|
+
: INTENT_MATCHERS[packName].test(text);
|
|
381
388
|
if (matched) {
|
|
382
389
|
unlocked.add(packName);
|
|
383
390
|
}
|
package/src/toolPacks.ts
CHANGED
|
@@ -141,6 +141,11 @@ export const PACKS: Record<PackName, string[]> = {
|
|
|
141
141
|
'peer_agent_delegate',
|
|
142
142
|
'code_search_ast',
|
|
143
143
|
'code_list_symbols',
|
|
144
|
+
'code_lsp',
|
|
145
|
+
'git_worktree',
|
|
146
|
+
'apply_patch',
|
|
147
|
+
'code_repo_map',
|
|
148
|
+
'task_bg',
|
|
144
149
|
'pdf_read'
|
|
145
150
|
],
|
|
146
151
|
reverse_engineering: [
|
|
@@ -431,7 +436,9 @@ export function routePacks(
|
|
|
431
436
|
for (const packName of PACK_NAMES) {
|
|
432
437
|
const matched = packName === 'reverse_engineering'
|
|
433
438
|
? isReverseEngineeringIntent(text)
|
|
434
|
-
:
|
|
439
|
+
: packName === 'web'
|
|
440
|
+
? isWebIntent(text)
|
|
441
|
+
: INTENT_MATCHERS[packName].test(text);
|
|
435
442
|
if (matched) {
|
|
436
443
|
unlocked.add(packName);
|
|
437
444
|
}
|