@scemoon/cdh 1.0.8 → 1.0.9-beta.2
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/ai-dlc-skill/SKILL.md +106 -0
- package/ai-dlc-skill/architecture/project-structure.md +78 -0
- package/ai-dlc-skill/brownfield/README.md +36 -0
- package/ai-dlc-skill/brownfield/entry.md +45 -0
- package/ai-dlc-skill/brownfield/generate-context.sh +64 -0
- package/ai-dlc-skill/brownfield/scripts/deps.sh +27 -0
- package/ai-dlc-skill/brownfield/scripts/discover.sh +34 -0
- package/ai-dlc-skill/brownfield/scripts/extract-api.sh +45 -0
- package/ai-dlc-skill/components/backend.md +47 -0
- package/ai-dlc-skill/components/desktop.md +63 -0
- package/ai-dlc-skill/components/mya.md +219 -0
- package/ai-dlc-skill/components/native.md +73 -0
- package/ai-dlc-skill/components/tta.md +235 -0
- package/ai-dlc-skill/components/web.md +77 -0
- package/ai-dlc-skill/components/wxa.md +219 -0
- package/ai-dlc-skill/contracts/README.md +25 -0
- package/ai-dlc-skill/core/adaptive-flow.md +107 -0
- package/ai-dlc-skill/core/security.md +29 -0
- package/ai-dlc-skill/core/task-registry.md +153 -0
- package/ai-dlc-skill/cross-tool/README.md +20 -0
- package/ai-dlc-skill/cross-tool/cline/export.sh +38 -0
- package/ai-dlc-skill/cross-tool/copilot/export.sh +41 -0
- package/ai-dlc-skill/cross-tool/cursor/export.sh +53 -0
- package/ai-dlc-skill/cross-tool/onecode/export.sh +27 -0
- package/ai-dlc-skill/cross-tool/opencode/export.sh +38 -0
- package/ai-dlc-skill/phases/debug/entry.md +48 -0
- package/ai-dlc-skill/phases/debug/lifecycle.md +284 -0
- package/ai-dlc-skill/phases/deliver/entry.md +35 -0
- package/ai-dlc-skill/phases/deliver/lifecycle.md +185 -0
- package/ai-dlc-skill/phases/deliver/prompt.md +54 -0
- package/ai-dlc-skill/phases/deliver/rules.md +61 -0
- package/ai-dlc-skill/phases/plan/design_system/accessibility.md +268 -0
- package/ai-dlc-skill/phases/plan/design_system/atomic_design.md +341 -0
- package/ai-dlc-skill/phases/plan/design_system/component_spec.md +398 -0
- package/ai-dlc-skill/phases/plan/design_system/design_tokens.md +190 -0
- package/ai-dlc-skill/phases/plan/design_system/iconography.md +299 -0
- package/ai-dlc-skill/phases/plan/design_system/platform_ui/desktop.md +318 -0
- package/ai-dlc-skill/phases/plan/design_system/platform_ui/mya.md +354 -0
- package/ai-dlc-skill/phases/plan/design_system/platform_ui/native.md +328 -0
- package/ai-dlc-skill/phases/plan/design_system/platform_ui/tta.md +394 -0
- package/ai-dlc-skill/phases/plan/design_system/platform_ui/web.md +287 -0
- package/ai-dlc-skill/phases/plan/design_system/platform_ui/wxa.md +374 -0
- package/ai-dlc-skill/phases/plan/design_system/theme_system.md +318 -0
- package/ai-dlc-skill/phases/plan/entry.md +33 -0
- package/ai-dlc-skill/phases/plan/lifecycle.md +260 -0
- package/ai-dlc-skill/phases/plan/prompt.md +75 -0
- package/ai-dlc-skill/phases/plan/rules.md +60 -0
- package/ai-dlc-skill/phases/understand/entry.md +36 -0
- package/ai-dlc-skill/phases/understand/lifecycle.md +184 -0
- package/ai-dlc-skill/phases/understand/prompt.md +58 -0
- package/ai-dlc-skill/phases/understand/rules.md +49 -0
- package/ai-dlc-skill/phases/verify/config/base_url.md +65 -0
- package/ai-dlc-skill/phases/verify/entry.md +59 -0
- package/ai-dlc-skill/phases/verify/gates/browser_e2e.md +96 -0
- package/ai-dlc-skill/phases/verify/lifecycle.md +217 -0
- package/ai-dlc-skill/phases/verify/prompt.md +73 -0
- package/ai-dlc-skill/phases/verify/rules.md +91 -0
- package/ai-dlc-skill/phases/verify/runners/playwright_local.md +103 -0
- package/ai-dlc-skill/practices/bdd.md +119 -0
- package/ai-dlc-skill/practices/sdd.md +84 -0
- package/ai-dlc-skill/practices/tdd.md +128 -0
- package/ai-dlc-skill/providers/README.md +114 -0
- package/ai-dlc-skill/providers/aliyun/SKILL.md +204 -0
- package/ai-dlc-skill/providers/aliyun/api/rest-api.md +214 -0
- package/ai-dlc-skill/providers/aliyun/api/sdk.md +307 -0
- package/ai-dlc-skill/providers/aliyun/best-practices/database-design.md +363 -0
- package/ai-dlc-skill/providers/aliyun/best-practices/function-design.md +424 -0
- package/ai-dlc-skill/providers/aliyun/best-practices/troubleshooting.md +258 -0
- package/ai-dlc-skill/providers/aliyun/cli/database.md +263 -0
- package/ai-dlc-skill/providers/aliyun/cli/functions.md +263 -0
- package/ai-dlc-skill/providers/aliyun/cli/hosting.md +226 -0
- package/ai-dlc-skill/providers/aliyun/cli/setup.md +235 -0
- package/ai-dlc-skill/providers/aliyun/cli/storage.md +315 -0
- package/ai-dlc-skill/providers/aliyun/deployment.yaml +66 -0
- package/ai-dlc-skill/providers/aliyun/integration/ci-cd.md +288 -0
- package/ai-dlc-skill/providers/aliyun/preview.yaml +84 -0
- package/ai-dlc-skill/providers/aliyun/provider.yaml +160 -0
- package/ai-dlc-skill/providers/aliyun/security/authentication.md +254 -0
- package/ai-dlc-skill/providers/aliyun/services/cdn-hosting.md +220 -0
- package/ai-dlc-skill/providers/aliyun/services/database.md +319 -0
- package/ai-dlc-skill/providers/aliyun/services/function-compute.md +273 -0
- package/ai-dlc-skill/providers/aliyun/services/overview.md +163 -0
- package/ai-dlc-skill/providers/aliyun/services/serverless-app-engine.md +266 -0
- package/ai-dlc-skill/providers/aliyun/services/storage.md +269 -0
- package/ai-dlc-skill/providers/tcb/SKILL.md +208 -0
- package/ai-dlc-skill/providers/tcb/api/rest-api.md +338 -0
- package/ai-dlc-skill/providers/tcb/api/sdk.md +288 -0
- package/ai-dlc-skill/providers/tcb/best-practices/database-design.md +452 -0
- package/ai-dlc-skill/providers/tcb/best-practices/function-design.md +502 -0
- package/ai-dlc-skill/providers/tcb/best-practices/troubleshooting.md +462 -0
- package/ai-dlc-skill/providers/tcb/cli/cls.md +133 -0
- package/ai-dlc-skill/providers/tcb/cli/database.md +230 -0
- package/ai-dlc-skill/providers/tcb/cli/env.md +207 -0
- package/ai-dlc-skill/providers/tcb/cli/functions.md +276 -0
- package/ai-dlc-skill/providers/tcb/cli/hosting.md +219 -0
- package/ai-dlc-skill/providers/tcb/cli/setup.md +218 -0
- package/ai-dlc-skill/providers/tcb/cli/storage.md +233 -0
- package/ai-dlc-skill/providers/tcb/deployment.yaml +111 -0
- package/ai-dlc-skill/providers/tcb/integration/ci-cd.md +309 -0
- package/ai-dlc-skill/providers/tcb/integration/mcp-server.md +371 -0
- package/ai-dlc-skill/providers/tcb/preview.yaml +83 -0
- package/ai-dlc-skill/providers/tcb/provider.yaml +172 -0
- package/ai-dlc-skill/providers/tcb/security/authentication.md +241 -0
- package/ai-dlc-skill/providers/tcb/services/cloud-database.md +299 -0
- package/ai-dlc-skill/providers/tcb/services/cloud-functions.md +265 -0
- package/ai-dlc-skill/providers/tcb/services/cloud-hosting.md +264 -0
- package/ai-dlc-skill/providers/tcb/services/cloud-run.md +285 -0
- package/ai-dlc-skill/providers/tcb/services/cloud-storage.md +245 -0
- package/ai-dlc-skill/providers/tcb/services/overview.md +174 -0
- package/ai-dlc-skill/pybdd/README.md +41 -0
- package/ai-dlc-skill/pybdd/conftest.py +17 -0
- package/ai-dlc-skill/pybdd/example/auth/login.feature +32 -0
- package/ai-dlc-skill/pybdd/pytest.ini +5 -0
- package/ai-dlc-skill/pybdd/steps/.gitkeep +1 -0
- package/ai-dlc-skill/pybdd/steps/test_example_steps.py +65 -0
- package/ai-dlc-skill/requirements.md +140 -0
- package/ai-dlc-skill/skill.yaml +135 -0
- package/ai-dlc-skill/templates/brownfield/context.md +78 -0
- package/ai-dlc-skill/templates/integration/CHANGELOG.md +41 -0
- package/ai-dlc-skill/templates/integration/asyncapi.yaml +43 -0
- package/ai-dlc-skill/templates/integration/contract-diff.md +63 -0
- package/ai-dlc-skill/templates/integration/contract-spec.md +49 -0
- package/ai-dlc-skill/templates/integration/openapi.yaml +18 -0
- package/ai-dlc-skill/templates/integration/runtime-contract.yaml +36 -0
- package/ai-dlc-skill/templates/plan/design.md +49 -0
- package/ai-dlc-skill/templates/plan/task-list.md +32 -0
- package/ai-dlc-skill/templates/project/README.md +126 -0
- package/ai-dlc-skill/templates/project/template.md +119 -0
- package/ai-dlc-skill/templates/understand/feature.feature +30 -0
- package/ai-dlc-skill/templates/understand/intent.md +29 -0
- package/ai-dlc-skill/templates/understand/spec-delta.md +47 -0
- package/ai-dlc-skill/templates/verify/test-unit.py +27 -0
- package/ai-dlc-skill/walkthrough/collect.sh +50 -0
- package/ai-dlc-skill/walkthrough/template.md +54 -0
- package/cdh/__init__.py +0 -0
- package/cdh/__main__.py +4 -0
- package/cdh/__pycache__/__init__.cpython-314.pyc +0 -0
- package/cdh/__pycache__/cli.cpython-314.pyc +0 -0
- package/cdh/__pycache__/cli_logging.cpython-314.pyc +0 -0
- package/cdh/__pycache__/config.cpython-314.pyc +0 -0
- package/cdh/__pycache__/project_loader.cpython-314.pyc +0 -0
- package/cdh/__pycache__/scaffold.cpython-314.pyc +0 -0
- package/cdh/__pycache__/session_store.cpython-314.pyc +0 -0
- package/cdh/cdh_session_aggregator.py +258 -0
- package/cdh/cli.py +3000 -0
- package/cdh/cli_logging.py +45 -0
- package/cdh/config.py +28 -0
- package/cdh/event_loop/__init__.py +7 -0
- package/cdh/event_loop/bus.py +123 -0
- package/cdh/event_loop/events.py +25 -0
- package/cdh/event_loop/runner.py +28 -0
- package/cdh/event_loop/scheduler.py +158 -0
- package/cdh/generators/__init__.py +35 -0
- package/cdh/generators/_runtime.py +176 -0
- package/cdh/generators/ada/MANIFEST.toml +14 -0
- package/cdh/generators/ada/template.ads.tmpl +7 -0
- package/cdh/generators/bash/MANIFEST.toml +14 -0
- package/cdh/generators/bash/template.sh.tmpl +16 -0
- package/cdh/generators/builtin_index.json +590 -0
- package/cdh/generators/c/MANIFEST.toml +14 -0
- package/cdh/generators/c/template.h.tmpl +20 -0
- package/cdh/generators/cli.py +379 -0
- package/cdh/generators/clojure/MANIFEST.toml +14 -0
- package/cdh/generators/clojure/template.clj.tmpl +13 -0
- package/cdh/generators/cobol/MANIFEST.toml +14 -0
- package/cdh/generators/cobol/template.cbl.tmpl +14 -0
- package/cdh/generators/cpp/MANIFEST.toml +14 -0
- package/cdh/generators/cpp/template.hpp.tmpl +32 -0
- package/cdh/generators/crystal/MANIFEST.toml +14 -0
- package/cdh/generators/crystal/template.cr.tmpl +11 -0
- package/cdh/generators/csharp/MANIFEST.toml +23 -0
- package/cdh/generators/csharp/template.cs.tmpl +14 -0
- package/cdh/generators/cython/MANIFEST.toml +14 -0
- package/cdh/generators/cython/template.pyx.tmpl +17 -0
- package/cdh/generators/d/MANIFEST.toml +14 -0
- package/cdh/generators/d/template.d.tmpl +24 -0
- package/cdh/generators/dart/MANIFEST.toml +17 -0
- package/cdh/generators/dart/template.dart.tmpl +27 -0
- package/cdh/generators/elixir/MANIFEST.toml +17 -0
- package/cdh/generators/elixir/template.ex.tmpl +27 -0
- package/cdh/generators/elm/MANIFEST.toml +14 -0
- package/cdh/generators/elm/template.elm.tmpl +20 -0
- package/cdh/generators/erlang/MANIFEST.toml +14 -0
- package/cdh/generators/erlang/template.erl.tmpl +18 -0
- package/cdh/generators/fortran/MANIFEST.toml +14 -0
- package/cdh/generators/fortran/template.f90.tmpl +24 -0
- package/cdh/generators/fsharp/MANIFEST.toml +14 -0
- package/cdh/generators/fsharp/template.fs.tmpl +17 -0
- package/cdh/generators/go/MANIFEST.toml +18 -0
- package/cdh/generators/go/imports.go.tmpl +3 -0
- package/cdh/generators/go/template.go.tmpl +9 -0
- package/cdh/generators/graphql-schema/MANIFEST.toml +18 -0
- package/cdh/generators/graphql-schema/template.graphqls.tmpl +12 -0
- package/cdh/generators/groovy/MANIFEST.toml +14 -0
- package/cdh/generators/groovy/template.groovy.tmpl +28 -0
- package/cdh/generators/hack/MANIFEST.toml +14 -0
- package/cdh/generators/hack/template.hh.tmpl +24 -0
- package/cdh/generators/haskell/MANIFEST.toml +14 -0
- package/cdh/generators/haskell/template.hs.tmpl +20 -0
- package/cdh/generators/haxe/MANIFEST.toml +14 -0
- package/cdh/generators/haxe/template.hx.tmpl +20 -0
- package/cdh/generators/idris/MANIFEST.toml +14 -0
- package/cdh/generators/idris/template.idr.tmpl +22 -0
- package/cdh/generators/java/MANIFEST.toml +18 -0
- package/cdh/generators/java/template.java.tmpl +13 -0
- package/cdh/generators/julia/MANIFEST.toml +14 -0
- package/cdh/generators/julia/template.jl.tmpl +27 -0
- package/cdh/generators/kotlin/MANIFEST.toml +18 -0
- package/cdh/generators/kotlin/template.kt.tmpl +12 -0
- package/cdh/generators/lua/MANIFEST.toml +14 -0
- package/cdh/generators/lua/template.lua.tmpl +27 -0
- package/cdh/generators/matlab/MANIFEST.toml +14 -0
- package/cdh/generators/matlab/template.m.tmpl +26 -0
- package/cdh/generators/nim/MANIFEST.toml +14 -0
- package/cdh/generators/nim/template.nim.tmpl +12 -0
- package/cdh/generators/nix/MANIFEST.toml +14 -0
- package/cdh/generators/nix/template.nix.tmpl +8 -0
- package/cdh/generators/objective-c/MANIFEST.toml +14 -0
- package/cdh/generators/objective-c/template.m.tmpl +31 -0
- package/cdh/generators/ocaml/MANIFEST.toml +14 -0
- package/cdh/generators/ocaml/template.ml.tmpl +13 -0
- package/cdh/generators/pascal/MANIFEST.toml +14 -0
- package/cdh/generators/pascal/template.pas.tmpl +5 -0
- package/cdh/generators/perl/MANIFEST.toml +14 -0
- package/cdh/generators/perl/template.pm.tmpl +27 -0
- package/cdh/generators/php/MANIFEST.toml +17 -0
- package/cdh/generators/php/template.php.tmpl +31 -0
- package/cdh/generators/powershell/MANIFEST.toml +14 -0
- package/cdh/generators/powershell/template.ps1.tmpl +20 -0
- package/cdh/generators/protobuf/MANIFEST.toml +18 -0
- package/cdh/generators/protobuf/template.proto.tmpl +13 -0
- package/cdh/generators/python/MANIFEST.toml +18 -0
- package/cdh/generators/python/template.py.tmpl +12 -0
- package/cdh/generators/r/MANIFEST.toml +14 -0
- package/cdh/generators/r/template.R.tmpl +29 -0
- package/cdh/generators/racket/MANIFEST.toml +14 -0
- package/cdh/generators/racket/template.rkt.tmpl +15 -0
- package/cdh/generators/registry.py +211 -0
- package/cdh/generators/ruby/MANIFEST.toml +17 -0
- package/cdh/generators/ruby/template.rb.tmpl +27 -0
- package/cdh/generators/rust/MANIFEST.toml +18 -0
- package/cdh/generators/rust/template.rs.tmpl +16 -0
- package/cdh/generators/scala/MANIFEST.toml +20 -0
- package/cdh/generators/scala/template.scala.tmpl +13 -0
- package/cdh/generators/scheme/MANIFEST.toml +14 -0
- package/cdh/generators/scheme/template.scm.tmpl +16 -0
- package/cdh/generators/solidity/MANIFEST.toml +14 -0
- package/cdh/generators/solidity/template.sol.tmpl +24 -0
- package/cdh/generators/swift/MANIFEST.toml +18 -0
- package/cdh/generators/swift/template.swift.tmpl +10 -0
- package/cdh/generators/typescript/MANIFEST.toml +18 -0
- package/cdh/generators/typescript/template.ts.tmpl +7 -0
- package/cdh/generators/version.py +214 -0
- package/cdh/generators/zig/MANIFEST.toml +14 -0
- package/cdh/generators/zig/template.zig.tmpl +20 -0
- package/cdh/logging.py +314 -0
- package/cdh/optimizer/__init__.py +7 -0
- package/cdh/optimizer/loop.py +201 -0
- package/cdh/optimizer/mutation.py +85 -0
- package/cdh/optimizer/reward.py +51 -0
- package/cdh/optimizer/tracker.py +118 -0
- package/cdh/project_loader.py +1022 -0
- package/cdh/rules/patterns.yaml +132 -0
- package/cdh/rules/spectral.yaml +301 -0
- package/cdh/scaffold.py +1436 -0
- package/cdh/session_store.py +221 -0
- package/cdh/state_schema.py +127 -0
- package/cdh/tools/__init__.py +57 -0
- package/cdh/tools/cls_search.py +406 -0
- package/cdh/tools/contract_diff.py +644 -0
- package/cdh/tools/deploy_stack.py +590 -0
- package/cdh/tools/generate_shared.py +300 -0
- package/cdh/tools/iac_gen.py +224 -0
- package/cdh/tools/otel_export.py +125 -0
- package/cdh/tools/pattern_detect.py +451 -0
- package/cdh/tools/retrofit_labels.py +505 -0
- package/cdh/trace/__init__.py +101 -0
- package/cdh/trace/__pycache__/__init__.cpython-314.pyc +0 -0
- package/cdh/trace/dashboard/__init__.py +61 -0
- package/cdh/trace/dashboard/api.py +1032 -0
- package/cdh/trace/dashboard/app.html +1321 -0
- package/cdh/trace/dashboard/server.py +310 -0
- package/cdh/trace/otel_exporter.py +462 -0
- package/cdh/trace/otel_tracer.py +281 -0
- package/cdh/tui.py +1084 -0
- package/cdh/validators/__init__.py +16 -0
- package/cdh/validators/__pycache__/__init__.cpython-314.pyc +0 -0
- package/cdh/validators/__pycache__/bdd.cpython-314.pyc +0 -0
- package/cdh/validators/__pycache__/dag.cpython-314.pyc +0 -0
- package/cdh/validators/__pycache__/ears.cpython-314.pyc +0 -0
- package/cdh/validators/__pycache__/fr_namespace.cpython-314.pyc +0 -0
- package/cdh/validators/bdd.py +144 -0
- package/cdh/validators/dag.py +179 -0
- package/cdh/validators/ears.py +452 -0
- package/cdh/validators/fr_namespace.py +143 -0
- package/cdh/validators/spectral.py +475 -0
- package/cdh/verification/__init__.py +3 -0
- package/cdh/verification/aggregation.py +53 -0
- package/cdh/verification/gates/__init__.py +5 -0
- package/cdh/verification/gates/base.py +18 -0
- package/cdh/verification/gates/lint_gate.py +37 -0
- package/cdh/verification/gates/test_gate.py +41 -0
- package/cdh/verification/loop.py +93 -0
- package/cdh/verification/policy.py +24 -0
- package/onecode/__init__.py +1 -0
- package/onecode/__main__.py +4 -0
- package/onecode/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/__pycache__/cli.cpython-314.pyc +0 -0
- package/onecode/__pycache__/commands.cpython-314.pyc +0 -0
- package/onecode/__pycache__/config.cpython-314.pyc +0 -0
- package/onecode/__pycache__/migrate.cpython-314.pyc +0 -0
- package/onecode/agent/__init__.py +0 -0
- package/onecode/agent/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/cdh_loader.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/checkpoint.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/context.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/engine.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/hooks.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/onecode_agent_acp.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/permissions.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/permissions_store.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/project_doc.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/session.cpython-314.pyc +0 -0
- package/onecode/agent/__pycache__/turn_record.cpython-314.pyc +0 -0
- package/onecode/agent/agents/__init__.py +29 -0
- package/onecode/agent/agents/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/agent/agents/__pycache__/types.cpython-314.pyc +0 -0
- package/onecode/agent/agents/prompts/build-agent.md +50 -0
- package/onecode/agent/agents/prompts/compaction-instructions.md +12 -0
- package/onecode/agent/agents/prompts/explore-agent.md +42 -0
- package/onecode/agent/agents/prompts/plan-agent.md +44 -0
- package/onecode/agent/agents/prompts/plan-gate-hard.md +4 -0
- package/onecode/agent/agents/prompts/plan-gate-soft.md +3 -0
- package/onecode/agent/agents/prompts/solo-agent.md +57 -0
- package/onecode/agent/agents/prompts/subagent-constraints.md +10 -0
- package/onecode/agent/agents/prompts/summary-instructions.md +7 -0
- package/onecode/agent/agents/prompts/title-instructions.md +3 -0
- package/onecode/agent/agents/prompts/tool-descriptions.md +129 -0
- package/onecode/agent/agents/types.py +786 -0
- package/onecode/agent/attachments.py +112 -0
- package/onecode/agent/cdh_loader.py +3 -0
- package/onecode/agent/checkpoint.py +285 -0
- package/onecode/agent/context.py +465 -0
- package/onecode/agent/engine.py +3547 -0
- package/onecode/agent/event_bridge.py +75 -0
- package/onecode/agent/hooks.py +86 -0
- package/onecode/agent/onecode_agent_acp.py +2993 -0
- package/onecode/agent/permissions.py +150 -0
- package/onecode/agent/permissions_store.py +73 -0
- package/onecode/agent/project_doc.py +19 -0
- package/onecode/agent/question_detect.py +230 -0
- package/onecode/agent/session.py +3 -0
- package/onecode/agent/snapshot.py +144 -0
- package/onecode/agent/tools/__init__.py +17 -0
- package/onecode/agent/tools/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/agent_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/apply_patch_tool.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/bash_tool.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/communication_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/config_tool.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/cron_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/errors.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/file_ops.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/file_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/git_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/lsp_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/mcp_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/permission_handler.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/permissions.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/protocol.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/registry.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/sandbox.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/schema_validation.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/skill_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/todo_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/__pycache__/web_tools.cpython-314.pyc +0 -0
- package/onecode/agent/tools/agent_tools.py +128 -0
- package/onecode/agent/tools/apply_patch_tool.py +138 -0
- package/onecode/agent/tools/bash_tool.py +121 -0
- package/onecode/agent/tools/communication_tools.py +154 -0
- package/onecode/agent/tools/config_tool.py +130 -0
- package/onecode/agent/tools/cron_tools.py +178 -0
- package/onecode/agent/tools/errors.py +17 -0
- package/onecode/agent/tools/file_ops.py +221 -0
- package/onecode/agent/tools/file_tools.py +225 -0
- package/onecode/agent/tools/git_tools.py +88 -0
- package/onecode/agent/tools/lsp_tools.py +404 -0
- package/onecode/agent/tools/mcp_tools.py +211 -0
- package/onecode/agent/tools/permission_handler.py +46 -0
- package/onecode/agent/tools/permissions.py +77 -0
- package/onecode/agent/tools/protocol.py +20 -0
- package/onecode/agent/tools/registry.py +210 -0
- package/onecode/agent/tools/sandbox.py +460 -0
- package/onecode/agent/tools/schema_validation.py +100 -0
- package/onecode/agent/tools/skill_tools.py +52 -0
- package/onecode/agent/tools/todo_tools.py +208 -0
- package/onecode/agent/tools/web_tools.py +530 -0
- package/onecode/agent/turn_record.py +28 -0
- package/onecode/builtin_skills/agent-browser/SKILL.md +212 -0
- package/onecode/builtin_skills/agent-browser/skill.yaml +8 -0
- package/onecode/builtin_skills/cloudbase/SKILL.md +162 -0
- package/onecode/builtin_skills/cloudbase/skill.yaml +7 -0
- package/onecode/builtin_skills/git/SKILL.md +64 -0
- package/onecode/builtin_skills/git/skill.yaml +7 -0
- package/onecode/builtin_skills/shell/SKILL.md +58 -0
- package/onecode/builtin_skills/shell/skill.yaml +8 -0
- package/onecode/builtin_skills/skill-creator/SKILL.md +106 -0
- package/onecode/builtin_skills/skill-creator/skill.yaml +8 -0
- package/onecode/cli.py +1325 -0
- package/onecode/codebase/__init__.py +69 -0
- package/onecode/codebase/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/chunker.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/indexer.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/retriever.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/storage.cpython-314.pyc +0 -0
- package/onecode/codebase/__pycache__/tools.cpython-314.pyc +0 -0
- package/onecode/codebase/chunker.py +125 -0
- package/onecode/codebase/indexer.py +154 -0
- package/onecode/codebase/retriever.py +240 -0
- package/onecode/codebase/storage.py +153 -0
- package/onecode/codebase/tools.py +59 -0
- package/onecode/commands.py +673 -0
- package/onecode/config.py +539 -0
- package/onecode/config_screen.py +486 -0
- package/onecode/cron/__init__.py +3 -0
- package/onecode/lsp/__init__.py +3 -0
- package/onecode/mcp/__init__.py +11 -0
- package/onecode/mcp/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/mcp/__pycache__/client.cpython-314.pyc +0 -0
- package/onecode/mcp/__pycache__/cloudbase.cpython-314.pyc +0 -0
- package/onecode/mcp/__pycache__/config.cpython-314.pyc +0 -0
- package/onecode/mcp/__pycache__/manager.cpython-314.pyc +0 -0
- package/onecode/mcp/__pycache__/oauth.cpython-314.pyc +0 -0
- package/onecode/mcp/client.py +305 -0
- package/onecode/mcp/cloudbase.py +188 -0
- package/onecode/mcp/config.py +363 -0
- package/onecode/mcp/manager.py +603 -0
- package/onecode/mcp/oauth.py +199 -0
- package/onecode/memory/__init__.py +106 -0
- package/onecode/memory/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/backend.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/pyramid.cpython-314.pyc +0 -0
- package/onecode/memory/__pycache__/recall.cpython-314.pyc +0 -0
- package/onecode/memory/backend.py +179 -0
- package/onecode/memory/pyramid.py +145 -0
- package/onecode/memory/recall.py +322 -0
- package/onecode/migrate.py +122 -0
- package/onecode/models/__init__.py +4 -0
- package/onecode/models/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/errors.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/messages.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/ollama_manager.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/provider.cpython-314.pyc +0 -0
- package/onecode/models/__pycache__/registry.cpython-314.pyc +0 -0
- package/onecode/models/errors.py +104 -0
- package/onecode/models/messages.py +750 -0
- package/onecode/models/ollama_manager.py +167 -0
- package/onecode/models/provider.py +730 -0
- package/onecode/models/providers/__init__.py +17 -0
- package/onecode/models/providers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/anthropic_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/deepseek_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/glm_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/minimax_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/minimaxi_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/ollama_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/__pycache__/openai_provider.cpython-314.pyc +0 -0
- package/onecode/models/providers/anthropic_provider.py +286 -0
- package/onecode/models/providers/deepseek_provider.py +221 -0
- package/onecode/models/providers/glm_provider.py +219 -0
- package/onecode/models/providers/minimax_provider.py +182 -0
- package/onecode/models/providers/minimaxi_provider.py +426 -0
- package/onecode/models/providers/ollama_provider.py +183 -0
- package/onecode/models/providers/openai_provider.py +234 -0
- package/onecode/models/registry.py +349 -0
- package/onecode/server/__init__.py +3 -0
- package/onecode/server/app.py +251 -0
- package/onecode/skills/__init__.py +11 -0
- package/onecode/skills/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/argument_substitution.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/bootstrap.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/create.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/frontmatter.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/loader.cpython-314.pyc +0 -0
- package/onecode/skills/__pycache__/model.cpython-314.pyc +0 -0
- package/onecode/skills/argument_substitution.py +38 -0
- package/onecode/skills/bootstrap.py +37 -0
- package/onecode/skills/create.py +56 -0
- package/onecode/skills/frontmatter.py +33 -0
- package/onecode/skills/loader.py +215 -0
- package/onecode/skills/manager.py +75 -0
- package/onecode/skills/model.py +43 -0
- package/onecode/storage/__init__.py +0 -0
- package/onecode/storage/activity.py +63 -0
- package/onecode/storage/project.py +54 -0
- package/onecode/storage/session.py +112 -0
- package/onecode/tasks/__init__.py +26 -0
- package/onecode/tasks/manager.py +232 -0
- package/onecode/tasks/models.py +240 -0
- package/onecode/trace/__init__.py +0 -0
- package/onecode/trace/tracer.py +173 -0
- package/onecode/utils/__init__.py +0 -0
- package/onecode/utils/helpers.py +20 -0
- package/onecode/verification/__init__.py +5 -0
- package/onecode/verification/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/verification/__pycache__/aggregation.cpython-314.pyc +0 -0
- package/onecode/verification/__pycache__/loop.cpython-314.pyc +0 -0
- package/onecode/verification/__pycache__/policy.cpython-314.pyc +0 -0
- package/onecode/verification/aggregation.py +53 -0
- package/onecode/verification/gates/__init__.py +6 -0
- package/onecode/verification/gates/__pycache__/__init__.cpython-314.pyc +0 -0
- package/onecode/verification/gates/__pycache__/base.cpython-314.pyc +0 -0
- package/onecode/verification/gates/__pycache__/lint_gate.cpython-314.pyc +0 -0
- package/onecode/verification/gates/__pycache__/test_gate.cpython-314.pyc +0 -0
- package/onecode/verification/gates/__pycache__/type_gate.cpython-314.pyc +0 -0
- package/onecode/verification/gates/base.py +20 -0
- package/onecode/verification/gates/lint_gate.py +45 -0
- package/onecode/verification/gates/test_gate.py +62 -0
- package/onecode/verification/gates/type_gate.py +46 -0
- package/onecode/verification/loop.py +95 -0
- package/onecode/verification/policy.py +29 -0
- package/package.json +2 -2
- package/pyproject.toml +84 -0
- package/tui/__init__.py +46 -0
- package/tui/__main__.py +4 -0
- package/tui/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/__pycache__/_loop.cpython-314.pyc +0 -0
- package/tui/__pycache__/_path_fuzzy_search.cpython-314.pyc +0 -0
- package/tui/__pycache__/_path_match.cpython-314.pyc +0 -0
- package/tui/__pycache__/agent.cpython-314.pyc +0 -0
- package/tui/__pycache__/agent_schema.cpython-314.pyc +0 -0
- package/tui/__pycache__/agents.cpython-314.pyc +0 -0
- package/tui/__pycache__/answer.cpython-314.pyc +0 -0
- package/tui/__pycache__/app.cpython-314.pyc +0 -0
- package/tui/__pycache__/atomic.cpython-314.pyc +0 -0
- package/tui/__pycache__/complete.cpython-314.pyc +0 -0
- package/tui/__pycache__/constants.cpython-314.pyc +0 -0
- package/tui/__pycache__/conversation_markdown.cpython-314.pyc +0 -0
- package/tui/__pycache__/db.cpython-314.pyc +0 -0
- package/tui/__pycache__/dec.cpython-314.pyc +0 -0
- package/tui/__pycache__/directory.cpython-314.pyc +0 -0
- package/tui/__pycache__/directory_watcher.cpython-314.pyc +0 -0
- package/tui/__pycache__/format_path.cpython-314.pyc +0 -0
- package/tui/__pycache__/fuzzy.cpython-314.pyc +0 -0
- package/tui/__pycache__/fuzzy_index.cpython-314.pyc +0 -0
- package/tui/__pycache__/history.cpython-314.pyc +0 -0
- package/tui/__pycache__/jsonrpc.cpython-314.pyc +0 -0
- package/tui/__pycache__/menus.cpython-314.pyc +0 -0
- package/tui/__pycache__/message_log.cpython-314.pyc +0 -0
- package/tui/__pycache__/messages.cpython-314.pyc +0 -0
- package/tui/__pycache__/path_complete.cpython-314.pyc +0 -0
- package/tui/__pycache__/path_filter.cpython-314.pyc +0 -0
- package/tui/__pycache__/paths.cpython-314.pyc +0 -0
- package/tui/__pycache__/pill.cpython-314.pyc +0 -0
- package/tui/__pycache__/platform_commands.cpython-314.pyc +0 -0
- package/tui/__pycache__/protocol.cpython-314.pyc +0 -0
- package/tui/__pycache__/session_tracker.cpython-314.pyc +0 -0
- package/tui/__pycache__/settings.cpython-314.pyc +0 -0
- package/tui/__pycache__/settings_schema.cpython-314.pyc +0 -0
- package/tui/__pycache__/shell.cpython-314.pyc +0 -0
- package/tui/__pycache__/shell_read.cpython-314.pyc +0 -0
- package/tui/__pycache__/slash_command.cpython-314.pyc +0 -0
- package/tui/__pycache__/version.cpython-314.pyc +0 -0
- package/tui/_loop.py +86 -0
- package/tui/_path_fuzzy_search.py +48 -0
- package/tui/_path_match.py +141 -0
- package/tui/about.py +95 -0
- package/tui/acp/__pycache__/agent.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/api.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/encode_tool_call_id.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/event_tap.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/messages.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/prompt.cpython-314.pyc +0 -0
- package/tui/acp/__pycache__/protocol.cpython-314.pyc +0 -0
- package/tui/acp/agent.py +1212 -0
- package/tui/acp/api.py +79 -0
- package/tui/acp/encode_tool_call_id.py +12 -0
- package/tui/acp/event_tap.py +107 -0
- package/tui/acp/messages.py +222 -0
- package/tui/acp/prompt.py +53 -0
- package/tui/acp/protocol.py +551 -0
- package/tui/agent.py +70 -0
- package/tui/agent_schema.py +76 -0
- package/tui/agents.py +46 -0
- package/tui/ansi/__init__.py +1 -0
- package/tui/ansi/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_ansi.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_ansi_colors.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_control_codes.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_keys.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_sgr_styles.cpython-314.pyc +0 -0
- package/tui/ansi/__pycache__/_stream_parser.cpython-314.pyc +0 -0
- package/tui/ansi/_ansi.py +1689 -0
- package/tui/ansi/_ansi_colors.py +264 -0
- package/tui/ansi/_control_codes.py +37 -0
- package/tui/ansi/_keys.py +251 -0
- package/tui/ansi/_sgr_styles.py +64 -0
- package/tui/ansi/_stream_parser.py +418 -0
- package/tui/answer.py +12 -0
- package/tui/app.py +1195 -0
- package/tui/atomic.py +37 -0
- package/tui/cli.py +208 -0
- package/tui/code_analyze.py +27 -0
- package/tui/complete.py +38 -0
- package/tui/constants.py +61 -0
- package/tui/conversation_markdown.py +30 -0
- package/tui/danger.py +372 -0
- package/tui/data/agents/ampcode.com.toml +52 -0
- package/tui/data/agents/augmentcode.com.toml +41 -0
- package/tui/data/agents/cdh.cloud-dev-harness.toml +23 -0
- package/tui/data/agents/claude.com.toml +41 -0
- package/tui/data/agents/copilot.github.com.toml +29 -0
- package/tui/data/agents/crowai.dev.toml +36 -0
- package/tui/data/agents/cursor.com.toml +38 -0
- package/tui/data/agents/deepagents.langchain.com +34 -0
- package/tui/data/agents/docker.com.toml +60 -0
- package/tui/data/agents/geminicli.com.toml +28 -0
- package/tui/data/agents/goose.ai.toml +52 -0
- package/tui/data/agents/inference.huggingface.co.toml +41 -0
- package/tui/data/agents/kimi.com.toml +35 -0
- package/tui/data/agents/kiro.dev.toml +43 -0
- package/tui/data/agents/onecode.dev.toml +22 -0
- package/tui/data/agents/openai.com.toml +53 -0
- package/tui/data/agents/openclaw.ai.toml +37 -0
- package/tui/data/agents/opencode.ai.toml +39 -0
- package/tui/data/agents/openhands.dev.toml +46 -0
- package/tui/data/agents/stakpak.dev.toml +62 -0
- package/tui/data/agents/vibe.mistral.ai.toml +31 -0
- package/tui/data/agents/vtcode.dev.toml +63 -0
- package/tui/data/images/frog.png +0 -0
- package/tui/data/sounds/question.wav +0 -0
- package/tui/data/sounds/turn-over.wav +0 -0
- package/tui/db.py +213 -0
- package/tui/dec.py +332 -0
- package/tui/diff_utils.py +131 -0
- package/tui/directory.py +234 -0
- package/tui/directory_suggester.py +93 -0
- package/tui/directory_watcher.py +231 -0
- package/tui/format_path.py +25 -0
- package/tui/fuzzy.py +140 -0
- package/tui/fuzzy_index.py +275 -0
- package/tui/gist.py +33 -0
- package/tui/history.py +138 -0
- package/tui/jsonrpc.py +599 -0
- package/tui/menus.py +14 -0
- package/tui/message_log.py +69 -0
- package/tui/messages.py +144 -0
- package/tui/option_content.py +51 -0
- package/tui/os.py +0 -0
- package/tui/path_complete.py +217 -0
- package/tui/path_filter.py +124 -0
- package/tui/paths.py +87 -0
- package/tui/pill.py +23 -0
- package/tui/platform_commands.py +52 -0
- package/tui/prompt/__pycache__/extract.cpython-314.pyc +0 -0
- package/tui/prompt/__pycache__/resource.cpython-314.pyc +0 -0
- package/tui/prompt/extract.py +19 -0
- package/tui/prompt/resource.py +68 -0
- package/tui/protocol.py +28 -0
- package/tui/screens/__init__.py +0 -0
- package/tui/screens/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/diff_screen.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/main.cpython-314.pyc +0 -0
- package/tui/screens/__pycache__/sessions.cpython-314.pyc +0 -0
- package/tui/screens/action_modal.py +94 -0
- package/tui/screens/agent_modal.py +175 -0
- package/tui/screens/command_edit_modal.py +74 -0
- package/tui/screens/diff_explorer_screen.py +419 -0
- package/tui/screens/diff_screen.py +84 -0
- package/tui/screens/ide_screen.py +461 -0
- package/tui/screens/main.py +397 -0
- package/tui/screens/main.tcss +662 -0
- package/tui/screens/permissions.py +404 -0
- package/tui/screens/permissions.tcss +72 -0
- package/tui/screens/projects.tcss +84 -0
- package/tui/screens/projects_app.py +341 -0
- package/tui/screens/projects_screen.py +277 -0
- package/tui/screens/session_resume_modal.py +172 -0
- package/tui/screens/session_resume_modal.tcss +35 -0
- package/tui/screens/sessions.py +171 -0
- package/tui/screens/sessions.tcss +119 -0
- package/tui/screens/settings.py +293 -0
- package/tui/screens/settings.tcss +113 -0
- package/tui/screens/store.py +502 -0
- package/tui/screens/store.tcss +274 -0
- package/tui/screens/tool_content_screen.py +59 -0
- package/tui/screens/trace.py +317 -0
- package/tui/session_tracker.py +123 -0
- package/tui/settings.py +353 -0
- package/tui/settings_schema.py +467 -0
- package/tui/shell.py +304 -0
- package/tui/shell_read.py +42 -0
- package/tui/slash_command.py +34 -0
- package/tui/tui.tcss +246 -0
- package/tui/twitter.py +38 -0
- package/tui/version.py +80 -0
- package/tui/visuals/__init__.py +0 -0
- package/tui/visuals/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/visuals/__pycache__/columns.cpython-314.pyc +0 -0
- package/tui/visuals/columns.py +272 -0
- package/tui/widgets/__init__.py +0 -0
- package/tui/widgets/__pycache__/__init__.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/agent_response.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/agent_thought.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/aidlc.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/ask_user.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/condensed_path.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/context_stats.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/conversation.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/diff_view.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/flash.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/future_text.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/grid_select.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/highlighted_textarea.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/load_more.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/menu.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/modified_files.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/non_selectable_label.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/note.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/path_search.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/pending_prompts.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/plan.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/project_directory_tree.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/prompt.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/question.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/session_grid_select.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/session_summary.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/session_tabs.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/shell_terminal.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/side_bar.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/slash_complete.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/strike_text.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/terminal.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/throbber.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/tool_call.cpython-314.pyc +0 -0
- package/tui/widgets/__pycache__/user_input.cpython-314.pyc +0 -0
- package/tui/widgets/acp_content.py +70 -0
- package/tui/widgets/agent_response.py +76 -0
- package/tui/widgets/agent_thought.py +167 -0
- package/tui/widgets/aidlc.py +334 -0
- package/tui/widgets/ask_user.py +604 -0
- package/tui/widgets/command_pane.py +223 -0
- package/tui/widgets/condensed_path.py +115 -0
- package/tui/widgets/context_stats.py +66 -0
- package/tui/widgets/conversation.py +3235 -0
- package/tui/widgets/danger_warning.py +65 -0
- package/tui/widgets/diff_view.py +69 -0
- package/tui/widgets/directory_input.py +8 -0
- package/tui/widgets/edit_field.py +206 -0
- package/tui/widgets/flash.py +81 -0
- package/tui/widgets/future_text.py +126 -0
- package/tui/widgets/grid_select.py +234 -0
- package/tui/widgets/highlighted_textarea.py +183 -0
- package/tui/widgets/load_more.py +24 -0
- package/tui/widgets/mandelbrot.py +294 -0
- package/tui/widgets/markdown_note.py +13 -0
- package/tui/widgets/menu.py +147 -0
- package/tui/widgets/model_status.py +230 -0
- package/tui/widgets/modified_files.py +315 -0
- package/tui/widgets/non_selectable_label.py +5 -0
- package/tui/widgets/note.py +18 -0
- package/tui/widgets/path_search.py +492 -0
- package/tui/widgets/pending_prompts.py +36 -0
- package/tui/widgets/plan.py +285 -0
- package/tui/widgets/project_directory_tree.py +102 -0
- package/tui/widgets/project_grid_select.py +68 -0
- package/tui/widgets/project_summary.py +33 -0
- package/tui/widgets/prompt.py +935 -0
- package/tui/widgets/question.py +360 -0
- package/tui/widgets/session_grid_select.py +230 -0
- package/tui/widgets/session_summary.py +115 -0
- package/tui/widgets/session_tabs.py +194 -0
- package/tui/widgets/shell_result.py +35 -0
- package/tui/widgets/shell_terminal.py +40 -0
- package/tui/widgets/side_bar.py +124 -0
- package/tui/widgets/slash_complete.py +235 -0
- package/tui/widgets/strike_text.py +70 -0
- package/tui/widgets/subagent.py +287 -0
- package/tui/widgets/subagent_screen.py +715 -0
- package/tui/widgets/terminal.py +576 -0
- package/tui/widgets/terminal_tool.py +360 -0
- package/tui/widgets/throbber.py +100 -0
- package/tui/widgets/tool_call.py +432 -0
- package/tui/widgets/user_input.py +23 -0
- package/tui/widgets/version.py +5 -0
- package/tui/widgets/welcome.py +31 -0
|
@@ -0,0 +1,1032 @@
|
|
|
1
|
+
"""Trace dashboard API — all SQL queries."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import sqlite3
|
|
7
|
+
from datetime import datetime, timedelta
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _connect(db_path: Path) -> sqlite3.Connection | None:
|
|
13
|
+
if not db_path.exists():
|
|
14
|
+
return None
|
|
15
|
+
conn = sqlite3.connect(str(db_path))
|
|
16
|
+
conn.row_factory = sqlite3.Row
|
|
17
|
+
try:
|
|
18
|
+
conn.execute("SELECT COUNT(*) FROM traces")
|
|
19
|
+
except sqlite3.OperationalError:
|
|
20
|
+
conn.close()
|
|
21
|
+
return None
|
|
22
|
+
conn.execute("PRAGMA journal_mode=WAL")
|
|
23
|
+
return conn
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _require_db(db_path: Path):
|
|
27
|
+
"""Return a connection or raise a clear error about empty DB."""
|
|
28
|
+
conn = _connect(db_path)
|
|
29
|
+
if conn is None:
|
|
30
|
+
raise EmptyTraceDB("No traces yet. Run an agent session to collect data.")
|
|
31
|
+
return conn
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class EmptyTraceDB(Exception):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _json_val(column: str) -> str:
|
|
39
|
+
"""Return a SQLite expression to extract a value from the data JSON column.
|
|
40
|
+
|
|
41
|
+
Checks both top-level and nested kwargs paths.
|
|
42
|
+
"""
|
|
43
|
+
return (
|
|
44
|
+
f"COALESCE(JSON_EXTRACT(data, '$.{column}'), "
|
|
45
|
+
f"JSON_EXTRACT(data, '$.kwargs.{column}'))"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _tags_val(key: str) -> str:
|
|
50
|
+
"""Return a SQLite expression to extract a tag from the tags JSON column."""
|
|
51
|
+
return f"JSON_EXTRACT(tags, '$.{key}')"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _model_val() -> str:
|
|
55
|
+
"""Return a SQLite expression to extract model from data.kwargs.model or tags.model."""
|
|
56
|
+
return (
|
|
57
|
+
"COALESCE("
|
|
58
|
+
"JSON_EXTRACT(data, '$.kwargs.model'), "
|
|
59
|
+
"JSON_EXTRACT(data, '$.model'), "
|
|
60
|
+
f"{_tags_val('model')}"
|
|
61
|
+
")"
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _parse_row(row: sqlite3.Row) -> dict:
|
|
66
|
+
d = dict(row)
|
|
67
|
+
if isinstance(d.get("tags"), str):
|
|
68
|
+
try:
|
|
69
|
+
d["tags"] = json.loads(d["tags"])
|
|
70
|
+
except (json.JSONDecodeError, TypeError):
|
|
71
|
+
d["tags"] = {}
|
|
72
|
+
if isinstance(d.get("data"), str):
|
|
73
|
+
try:
|
|
74
|
+
data = json.loads(d["data"])
|
|
75
|
+
d["data"] = data
|
|
76
|
+
for k, v in data.items():
|
|
77
|
+
if k not in d or d[k] is None:
|
|
78
|
+
d[k] = v
|
|
79
|
+
if isinstance(data.get("kwargs"), dict):
|
|
80
|
+
for k, v in data["kwargs"].items():
|
|
81
|
+
if k not in d or d[k] is None:
|
|
82
|
+
d[k] = v
|
|
83
|
+
if k not in data:
|
|
84
|
+
data[k] = v
|
|
85
|
+
except (json.JSONDecodeError, TypeError):
|
|
86
|
+
d["data"] = {}
|
|
87
|
+
d["type"] = d.pop("trace_type", d.get("type", ""))
|
|
88
|
+
d["function"] = d.pop("function_name", d.get("function", ""))
|
|
89
|
+
return d
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _percentile(sorted_data: list[float], p: float) -> float:
|
|
93
|
+
if not sorted_data:
|
|
94
|
+
return 0.0
|
|
95
|
+
idx = int(len(sorted_data) * p / 100.0)
|
|
96
|
+
idx = min(idx, len(sorted_data) - 1)
|
|
97
|
+
return sorted_data[idx]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def get_overview(db_path: Path, start: str | None = None, end: str | None = None) -> dict:
|
|
101
|
+
conn = _connect(db_path)
|
|
102
|
+
if conn is None:
|
|
103
|
+
return {
|
|
104
|
+
"total": 0, "total_today": 0, "sessions": 0, "agents": 0,
|
|
105
|
+
"avg_duration": 0, "p50_duration": 0, "p95_duration": 0, "p99_duration": 0,
|
|
106
|
+
"error_count": 0, "error_rate": 0,
|
|
107
|
+
"total_tokens": 0, "input_tokens": 0, "output_tokens": 0,
|
|
108
|
+
"cached_tokens": 0, "cache_hit_rate": 0,
|
|
109
|
+
"total_cost": 0, "estimated_cost": True,
|
|
110
|
+
"lines_added": 0, "tokens_per_kloc": 0,
|
|
111
|
+
"type_distribution": {}, "hourly": [], "agent_breakdown": [],
|
|
112
|
+
"model_breakdown": [], "daily_cost": [], "db_path": str(db_path),
|
|
113
|
+
}
|
|
114
|
+
try:
|
|
115
|
+
now = datetime.utcnow()
|
|
116
|
+
today_start = now.strftime("%Y-%m-%dT00:00:00")
|
|
117
|
+
|
|
118
|
+
time_filter = ""
|
|
119
|
+
time_params: list[Any] = []
|
|
120
|
+
if start:
|
|
121
|
+
time_filter += " AND timestamp >= ?"
|
|
122
|
+
time_params.append(start)
|
|
123
|
+
if end:
|
|
124
|
+
time_filter += " AND timestamp <= ?"
|
|
125
|
+
time_params.append(end)
|
|
126
|
+
|
|
127
|
+
total = conn.execute(f"SELECT COUNT(*) FROM traces WHERE 1=1{time_filter}", time_params).fetchone()[0]
|
|
128
|
+
total_today = conn.execute(
|
|
129
|
+
f"SELECT COUNT(*) FROM traces WHERE timestamp >= ?{time_filter}", (today_start, *time_params)
|
|
130
|
+
).fetchone()[0]
|
|
131
|
+
sessions = conn.execute(
|
|
132
|
+
f"SELECT COUNT(DISTINCT session_id) FROM traces WHERE 1=1{time_filter}", time_params
|
|
133
|
+
).fetchone()[0]
|
|
134
|
+
agents = conn.execute(
|
|
135
|
+
f"SELECT COUNT(DISTINCT {_tags_val('agent')}) FROM traces WHERE {_tags_val('agent')} IS NOT NULL{time_filter}", time_params
|
|
136
|
+
).fetchone()[0]
|
|
137
|
+
|
|
138
|
+
durations = [
|
|
139
|
+
float(r[0])
|
|
140
|
+
for r in conn.execute(
|
|
141
|
+
f"SELECT {_json_val('duration_ms')} FROM traces WHERE {_json_val('duration_ms')} IS NOT NULL{time_filter}",
|
|
142
|
+
time_params
|
|
143
|
+
).fetchall()
|
|
144
|
+
if r[0] is not None
|
|
145
|
+
]
|
|
146
|
+
sorted_d = sorted(durations)
|
|
147
|
+
avg_duration = sum(sorted_d) / len(sorted_d) if sorted_d else 0
|
|
148
|
+
p50 = _percentile(sorted_d, 50)
|
|
149
|
+
p95 = _percentile(sorted_d, 95)
|
|
150
|
+
p99 = _percentile(sorted_d, 99)
|
|
151
|
+
|
|
152
|
+
type_dist = {
|
|
153
|
+
r["trace_type"]: r["cnt"]
|
|
154
|
+
for r in conn.execute(
|
|
155
|
+
f"SELECT trace_type, COUNT(*) as cnt FROM traces WHERE 1=1{time_filter} GROUP BY trace_type ORDER BY cnt DESC",
|
|
156
|
+
time_params
|
|
157
|
+
).fetchall()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
week_ago = (now - timedelta(days=7)).isoformat()
|
|
161
|
+
hourly_filter = " AND timestamp >= ?"
|
|
162
|
+
hourly_params = [start] if start else [week_ago]
|
|
163
|
+
hourly = [
|
|
164
|
+
{"bucket": r["bucket"], "count": r["cnt"]}
|
|
165
|
+
for r in conn.execute(
|
|
166
|
+
f"""SELECT strftime('%Y-%m-%dT%H:00:00', timestamp) as bucket,
|
|
167
|
+
COUNT(*) as cnt
|
|
168
|
+
FROM traces WHERE 1=1{hourly_filter}
|
|
169
|
+
GROUP BY bucket ORDER BY bucket""",
|
|
170
|
+
hourly_params,
|
|
171
|
+
).fetchall()
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
errors = conn.execute(
|
|
175
|
+
f"SELECT COUNT(*) FROM traces WHERE {_json_val('error')} IS NOT NULL AND {_json_val('error')} != ''{time_filter}",
|
|
176
|
+
time_params
|
|
177
|
+
).fetchone()[0]
|
|
178
|
+
|
|
179
|
+
total_tokens = conn.execute(
|
|
180
|
+
f"SELECT COALESCE(SUM({_json_val('token_count')}), 0) FROM traces WHERE 1=1{time_filter}",
|
|
181
|
+
time_params
|
|
182
|
+
).fetchone()[0]
|
|
183
|
+
input_tokens = conn.execute(
|
|
184
|
+
f"SELECT COALESCE(SUM({_json_val('input_tokens')}), 0) FROM traces WHERE 1=1{time_filter}",
|
|
185
|
+
time_params
|
|
186
|
+
).fetchone()[0]
|
|
187
|
+
output_tokens = conn.execute(
|
|
188
|
+
f"SELECT COALESCE(SUM({_json_val('output_tokens')}), 0) FROM traces WHERE 1=1{time_filter}",
|
|
189
|
+
time_params
|
|
190
|
+
).fetchone()[0]
|
|
191
|
+
cached_tokens = conn.execute(
|
|
192
|
+
f"SELECT COALESCE(SUM({_json_val('cached_input_tokens')}), 0) FROM traces WHERE 1=1{time_filter}",
|
|
193
|
+
time_params
|
|
194
|
+
).fetchone()[0]
|
|
195
|
+
cache_hit_rate = round(cached_tokens / input_tokens * 100, 1) if input_tokens else 0
|
|
196
|
+
|
|
197
|
+
total_lines_added = conn.execute(
|
|
198
|
+
f"SELECT COALESCE(SUM({_json_val('lines_added')}), 0) FROM traces WHERE 1=1{time_filter}",
|
|
199
|
+
time_params
|
|
200
|
+
).fetchone()[0]
|
|
201
|
+
tokens_per_kloc = (
|
|
202
|
+
round(total_tokens / (total_lines_added / 1000), 2)
|
|
203
|
+
if total_lines_added else 0
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
agent_breakdown = [
|
|
207
|
+
{"agent": r["agent"], "count": r["cnt"]}
|
|
208
|
+
for r in conn.execute(
|
|
209
|
+
f"SELECT MAX({_tags_val('agent')}) as agent, COUNT(*) as cnt FROM traces WHERE {_tags_val('agent')} IS NOT NULL{time_filter} GROUP BY LOWER({_tags_val('agent')}) ORDER BY cnt DESC",
|
|
210
|
+
time_params
|
|
211
|
+
).fetchall()
|
|
212
|
+
]
|
|
213
|
+
|
|
214
|
+
model_breakdown = [
|
|
215
|
+
{
|
|
216
|
+
"model": r["model"],
|
|
217
|
+
"count": r["cnt"],
|
|
218
|
+
"total_tokens": r["tokens"],
|
|
219
|
+
"avg_duration": round(r["avg_dur"], 3) if r["avg_dur"] else 0,
|
|
220
|
+
}
|
|
221
|
+
for r in conn.execute(
|
|
222
|
+
f"""SELECT {_model_val()} as model,
|
|
223
|
+
COUNT(*) as cnt,
|
|
224
|
+
COALESCE(SUM({_json_val('token_count')}), 0) as tokens,
|
|
225
|
+
AVG({_json_val('duration_ms')}) as avg_dur
|
|
226
|
+
FROM traces
|
|
227
|
+
WHERE {_model_val()} IS NOT NULL AND {_model_val()} != ''{time_filter}
|
|
228
|
+
GROUP BY model
|
|
229
|
+
ORDER BY tokens DESC
|
|
230
|
+
LIMIT 10""",
|
|
231
|
+
time_params
|
|
232
|
+
).fetchall()
|
|
233
|
+
]
|
|
234
|
+
|
|
235
|
+
daily_cost = [
|
|
236
|
+
{
|
|
237
|
+
"day": r["day"],
|
|
238
|
+
"total_tokens": r["total_tokens"],
|
|
239
|
+
"input_tokens": r["total_input"],
|
|
240
|
+
"output_tokens": r["total_output"],
|
|
241
|
+
}
|
|
242
|
+
for r in conn.execute(
|
|
243
|
+
f"""SELECT strftime('%%Y-%%m-%%d', timestamp) as day,
|
|
244
|
+
SUM(COALESCE({_json_val('token_count')}, 0)) as total_tokens,
|
|
245
|
+
SUM(COALESCE({_json_val('input_tokens')}, 0)) as total_input,
|
|
246
|
+
SUM(COALESCE({_json_val('output_tokens')}, 0)) as total_output
|
|
247
|
+
FROM traces
|
|
248
|
+
WHERE {_json_val('token_count')} IS NOT NULL{time_filter}
|
|
249
|
+
GROUP BY day
|
|
250
|
+
ORDER BY day DESC
|
|
251
|
+
LIMIT 30""",
|
|
252
|
+
time_params
|
|
253
|
+
).fetchall()
|
|
254
|
+
]
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
"total": total,
|
|
258
|
+
"total_today": total_today,
|
|
259
|
+
"sessions": sessions,
|
|
260
|
+
"agents": agents,
|
|
261
|
+
"avg_duration": round(avg_duration, 3),
|
|
262
|
+
"p50_duration": round(p50, 3),
|
|
263
|
+
"p95_duration": round(p95, 3),
|
|
264
|
+
"p99_duration": round(p99, 3),
|
|
265
|
+
"error_count": errors,
|
|
266
|
+
"error_rate": round(errors / total * 100, 2) if total else 0,
|
|
267
|
+
"total_tokens": total_tokens,
|
|
268
|
+
"input_tokens": input_tokens,
|
|
269
|
+
"output_tokens": output_tokens,
|
|
270
|
+
"cached_tokens": cached_tokens,
|
|
271
|
+
"cache_hit_rate": cache_hit_rate,
|
|
272
|
+
"total_cost": 0,
|
|
273
|
+
"estimated_cost": True,
|
|
274
|
+
"lines_added": total_lines_added,
|
|
275
|
+
"tokens_per_kloc": tokens_per_kloc,
|
|
276
|
+
"type_distribution": type_dist,
|
|
277
|
+
"hourly": hourly,
|
|
278
|
+
"agent_breakdown": agent_breakdown,
|
|
279
|
+
"model_breakdown": model_breakdown,
|
|
280
|
+
"daily_cost": daily_cost,
|
|
281
|
+
"db_path": str(db_path),
|
|
282
|
+
}
|
|
283
|
+
finally:
|
|
284
|
+
conn.close()
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def get_traces(
|
|
288
|
+
db_path: Path,
|
|
289
|
+
limit: int = 50,
|
|
290
|
+
offset: int = 0,
|
|
291
|
+
trace_type: str | None = None,
|
|
292
|
+
agent: str | None = None,
|
|
293
|
+
model: str | None = None,
|
|
294
|
+
status: str | None = None,
|
|
295
|
+
session_id: str | None = None,
|
|
296
|
+
search: str | None = None,
|
|
297
|
+
start: str | None = None,
|
|
298
|
+
end: str | None = None,
|
|
299
|
+
user_id: str | None = None,
|
|
300
|
+
env: str | None = None,
|
|
301
|
+
tag: str | None = None,
|
|
302
|
+
) -> dict:
|
|
303
|
+
conn = _connect(db_path)
|
|
304
|
+
if conn is None:
|
|
305
|
+
return {"traces": [], "total": 0, "limit": limit, "offset": offset}
|
|
306
|
+
try:
|
|
307
|
+
where = ["1=1"]
|
|
308
|
+
params: list[Any] = []
|
|
309
|
+
|
|
310
|
+
if trace_type:
|
|
311
|
+
where.append("trace_type = ?")
|
|
312
|
+
params.append(trace_type)
|
|
313
|
+
if agent:
|
|
314
|
+
where.append("{} = ?".format(_tags_val("agent")))
|
|
315
|
+
params.append(agent)
|
|
316
|
+
if model:
|
|
317
|
+
where.append("{} = ?".format(_json_val("model")))
|
|
318
|
+
params.append(model)
|
|
319
|
+
if status:
|
|
320
|
+
where.append("{} = ?".format(_json_val("status")))
|
|
321
|
+
params.append(status)
|
|
322
|
+
if session_id:
|
|
323
|
+
where.append("session_id = ?")
|
|
324
|
+
params.append(session_id)
|
|
325
|
+
if search:
|
|
326
|
+
where.append("function_name LIKE ?")
|
|
327
|
+
params.append(f"%{search}%")
|
|
328
|
+
if start:
|
|
329
|
+
where.append("timestamp >= ?")
|
|
330
|
+
params.append(start)
|
|
331
|
+
if end:
|
|
332
|
+
where.append("timestamp <= ?")
|
|
333
|
+
params.append(end)
|
|
334
|
+
if user_id:
|
|
335
|
+
where.append("{} = ?".format(_tags_val("user_id")))
|
|
336
|
+
params.append(user_id)
|
|
337
|
+
if env:
|
|
338
|
+
where.append("{} = ?".format(_tags_val("environment")))
|
|
339
|
+
params.append(env)
|
|
340
|
+
if tag:
|
|
341
|
+
where.append("{} LIKE ?".format(_tags_val("tags")))
|
|
342
|
+
params.append(f"%{tag}%")
|
|
343
|
+
|
|
344
|
+
where_clause = " AND ".join(where)
|
|
345
|
+
|
|
346
|
+
# Count total matching
|
|
347
|
+
count_row = conn.execute(
|
|
348
|
+
f"SELECT COUNT(*) FROM traces WHERE {where_clause}", params
|
|
349
|
+
).fetchone()[0]
|
|
350
|
+
|
|
351
|
+
# Fetch rows
|
|
352
|
+
rows = conn.execute(
|
|
353
|
+
f"SELECT * FROM traces WHERE {where_clause} ORDER BY timestamp DESC LIMIT ? OFFSET ?",
|
|
354
|
+
[*params, limit, offset],
|
|
355
|
+
).fetchall()
|
|
356
|
+
|
|
357
|
+
traces = [_parse_row(r) for r in rows]
|
|
358
|
+
return {"traces": traces, "total": count_row, "limit": limit, "offset": offset}
|
|
359
|
+
finally:
|
|
360
|
+
conn.close()
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
def get_sessions(db_path: Path, limit: int = 100, offset: int = 0) -> dict:
|
|
364
|
+
conn = _connect(db_path)
|
|
365
|
+
if conn is None:
|
|
366
|
+
return {"sessions": [], "total": 0, "limit": limit, "offset": offset}
|
|
367
|
+
try:
|
|
368
|
+
count_row = conn.execute(
|
|
369
|
+
"SELECT COUNT(DISTINCT session_id) FROM traces"
|
|
370
|
+
).fetchone()[0]
|
|
371
|
+
|
|
372
|
+
rows = conn.execute(
|
|
373
|
+
f"""SELECT session_id,
|
|
374
|
+
COUNT(*) as span_count,
|
|
375
|
+
MIN(timestamp) as first_ts,
|
|
376
|
+
MAX(timestamp) as last_ts,
|
|
377
|
+
COUNT(DISTINCT {_tags_val('agent')}) as agent_count,
|
|
378
|
+
COUNT(DISTINCT {_json_val('model')}) as model_count,
|
|
379
|
+
MAX({_json_val('error')}) as last_error,
|
|
380
|
+
SUM(CASE WHEN {_json_val('status')} IN ('error','failed') THEN 1 ELSE 0 END) as error_spans,
|
|
381
|
+
SUM(COALESCE({_json_val('token_count')}, 0)) as total_tokens,
|
|
382
|
+
SUM(COALESCE({_json_val('lines_added')}, 0)) as lines_added
|
|
383
|
+
FROM traces
|
|
384
|
+
GROUP BY session_id
|
|
385
|
+
ORDER BY last_ts DESC
|
|
386
|
+
LIMIT ? OFFSET ?""",
|
|
387
|
+
(limit, offset),
|
|
388
|
+
).fetchall()
|
|
389
|
+
|
|
390
|
+
sessions_list = []
|
|
391
|
+
for r in rows:
|
|
392
|
+
d = dict(r)
|
|
393
|
+
agents = conn.execute(
|
|
394
|
+
"SELECT DISTINCT {} FROM traces WHERE session_id = ? AND {} IS NOT NULL".format(
|
|
395
|
+
_tags_val("agent"), _tags_val("agent")
|
|
396
|
+
),
|
|
397
|
+
(d["session_id"],),
|
|
398
|
+
).fetchall()
|
|
399
|
+
d["agents"] = [a[0] for a in agents if a[0]]
|
|
400
|
+
sessions_list.append(d)
|
|
401
|
+
|
|
402
|
+
return {"sessions": sessions_list, "total": count_row, "limit": limit, "offset": offset}
|
|
403
|
+
finally:
|
|
404
|
+
conn.close()
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def get_session_detail(db_path: Path, session_id: str) -> dict | None:
|
|
408
|
+
conn = _connect(db_path)
|
|
409
|
+
if conn is None:
|
|
410
|
+
return None
|
|
411
|
+
try:
|
|
412
|
+
rows = conn.execute(
|
|
413
|
+
"SELECT * FROM traces WHERE session_id = ? ORDER BY timestamp ASC",
|
|
414
|
+
(session_id,),
|
|
415
|
+
).fetchall()
|
|
416
|
+
|
|
417
|
+
if not rows:
|
|
418
|
+
return None
|
|
419
|
+
|
|
420
|
+
spans = [_parse_row(r) for r in rows]
|
|
421
|
+
|
|
422
|
+
# Build call tree from parent_span_id
|
|
423
|
+
span_map: dict[str, dict] = {}
|
|
424
|
+
root_spans: list[dict] = []
|
|
425
|
+
orphan_spans: list[dict] = []
|
|
426
|
+
|
|
427
|
+
for s in spans:
|
|
428
|
+
s["children"] = []
|
|
429
|
+
span_id = s.get("id", "")
|
|
430
|
+
if span_id:
|
|
431
|
+
span_map[span_id] = s
|
|
432
|
+
|
|
433
|
+
# Build tree
|
|
434
|
+
subagent_parents: dict[str, dict] = {}
|
|
435
|
+
for s in spans:
|
|
436
|
+
pid = s.get("parent_span_id", "") or ""
|
|
437
|
+
if pid == "session_root" or not pid:
|
|
438
|
+
root_spans.append(s)
|
|
439
|
+
elif pid.startswith("subagent:"):
|
|
440
|
+
sa_id = pid[len("subagent:"):]
|
|
441
|
+
if sa_id not in subagent_parents:
|
|
442
|
+
subagent_parents[sa_id] = []
|
|
443
|
+
subagent_parents[sa_id].append(s)
|
|
444
|
+
else:
|
|
445
|
+
parent = span_map.get(pid)
|
|
446
|
+
if parent:
|
|
447
|
+
parent.setdefault("children", []).append(s)
|
|
448
|
+
else:
|
|
449
|
+
orphan_spans.append(s)
|
|
450
|
+
|
|
451
|
+
# Attach subagent children to their parent span.
|
|
452
|
+
# Preferred: match by explicit subagent_id (recorded on subagent_start since the fix).
|
|
453
|
+
# Fallback: pair remaining subagent children with subagent_start roots in emission order.
|
|
454
|
+
matched_ids: set[str] = set()
|
|
455
|
+
for s in root_spans:
|
|
456
|
+
s_data = s.get("data") or {}
|
|
457
|
+
if isinstance(s_data, str):
|
|
458
|
+
try:
|
|
459
|
+
s_data = json.loads(s_data)
|
|
460
|
+
except Exception:
|
|
461
|
+
s_data = {}
|
|
462
|
+
s_tags = s.get("tags") or {}
|
|
463
|
+
if isinstance(s_tags, str):
|
|
464
|
+
try:
|
|
465
|
+
s_tags = json.loads(s_tags)
|
|
466
|
+
except Exception:
|
|
467
|
+
s_tags = {}
|
|
468
|
+
sa_id = s_data.get("subagent_id") or s_tags.get("subagent_id")
|
|
469
|
+
if sa_id and sa_id in subagent_parents:
|
|
470
|
+
s.setdefault("children", []).extend(subagent_parents[sa_id])
|
|
471
|
+
matched_ids.add(sa_id)
|
|
472
|
+
|
|
473
|
+
# Sequential fallback for data without an explicit subagent_id link:
|
|
474
|
+
# subagent_start spans carry agent_type and appear in the same order as their children.
|
|
475
|
+
if subagent_parents:
|
|
476
|
+
subagent_roots = [
|
|
477
|
+
s for s in root_spans
|
|
478
|
+
if not (s.get("data") or {}).get("children") and (
|
|
479
|
+
s.get("function") == "subagent_start"
|
|
480
|
+
or (s.get("data") or {}).get("agent_type")
|
|
481
|
+
)
|
|
482
|
+
]
|
|
483
|
+
remaining = [sid for sid in subagent_parents if sid not in matched_ids]
|
|
484
|
+
for i, sa_id in enumerate(remaining):
|
|
485
|
+
if i < len(subagent_roots):
|
|
486
|
+
subagent_roots[i].setdefault("children", []).extend(subagent_parents[sa_id])
|
|
487
|
+
|
|
488
|
+
# Never drop data: attach any still-orphaned spans to the root level.
|
|
489
|
+
if orphan_spans:
|
|
490
|
+
root_spans.extend(orphan_spans)
|
|
491
|
+
|
|
492
|
+
stats = _compute_session_stats(spans)
|
|
493
|
+
|
|
494
|
+
return {"session_id": session_id, "spans": spans, "tree": root_spans, "stats": stats}
|
|
495
|
+
finally:
|
|
496
|
+
conn.close()
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def _matches_subagent(span: dict, subagent_id: str, _children: list) -> bool:
|
|
500
|
+
tags = span.get("tags") or {}
|
|
501
|
+
data = span.get("data") or {}
|
|
502
|
+
# Check various places where subagent_id could be stored
|
|
503
|
+
if isinstance(tags, dict) and tags.get("subagent_id") == subagent_id:
|
|
504
|
+
return True
|
|
505
|
+
if isinstance(data, dict) and data.get("subagent_id") == subagent_id:
|
|
506
|
+
return True
|
|
507
|
+
if subagent_id in (span.get("agent_type") or ""):
|
|
508
|
+
return True
|
|
509
|
+
return False
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
def _compute_session_stats(spans: list[dict]) -> dict:
|
|
513
|
+
if not spans:
|
|
514
|
+
return {}
|
|
515
|
+
|
|
516
|
+
first = spans[0]
|
|
517
|
+
last = spans[-1]
|
|
518
|
+
total_dur = 0
|
|
519
|
+
total_tokens = 0
|
|
520
|
+
total_lines = 0
|
|
521
|
+
errors = []
|
|
522
|
+
agents = set()
|
|
523
|
+
models = set()
|
|
524
|
+
tool_calls = 0
|
|
525
|
+
tools: dict[str, int] = {}
|
|
526
|
+
|
|
527
|
+
for s in spans:
|
|
528
|
+
d = s.get("data") or {}
|
|
529
|
+
if isinstance(d, str):
|
|
530
|
+
try:
|
|
531
|
+
d = json.loads(d)
|
|
532
|
+
except Exception:
|
|
533
|
+
d = {}
|
|
534
|
+
tags = s.get("tags") or {}
|
|
535
|
+
if isinstance(tags, str):
|
|
536
|
+
try:
|
|
537
|
+
tags = json.loads(tags)
|
|
538
|
+
except Exception:
|
|
539
|
+
tags = {}
|
|
540
|
+
|
|
541
|
+
dur = float(d.get("duration_ms") or s.get("duration_ms") or 0)
|
|
542
|
+
total_dur += dur
|
|
543
|
+
|
|
544
|
+
tok = int(d.get("token_count") or s.get("token_count") or 0)
|
|
545
|
+
total_tokens += tok
|
|
546
|
+
|
|
547
|
+
loc = int(d.get("lines_added") or s.get("lines_added") or 0)
|
|
548
|
+
total_lines += loc
|
|
549
|
+
|
|
550
|
+
if isinstance(tags, dict) and tags.get("agent"):
|
|
551
|
+
agents.add(tags["agent"])
|
|
552
|
+
|
|
553
|
+
model = d.get("model") or d.get("kwargs", {}).get("model") or s.get("model")
|
|
554
|
+
if model:
|
|
555
|
+
models.add(model)
|
|
556
|
+
|
|
557
|
+
if s.get("function") == "tool_call":
|
|
558
|
+
tool_calls += 1
|
|
559
|
+
tname = d.get("tool_name") or s.get("tool_name", "")
|
|
560
|
+
if tname:
|
|
561
|
+
tools[tname] = tools.get(tname, 0) + 1
|
|
562
|
+
|
|
563
|
+
err = d.get("error") or s.get("error")
|
|
564
|
+
if err:
|
|
565
|
+
errors.append({"span_id": s.get("id", ""), "function": s.get("function", ""), "error": err})
|
|
566
|
+
|
|
567
|
+
tokens_per_kloc = round(total_tokens / (total_lines / 1000), 2) if total_lines else 0
|
|
568
|
+
return {
|
|
569
|
+
"first_ts": first.get("timestamp"),
|
|
570
|
+
"last_ts": last.get("timestamp"),
|
|
571
|
+
"duration_ms": total_dur,
|
|
572
|
+
"total_tokens": total_tokens,
|
|
573
|
+
"lines_added": total_lines,
|
|
574
|
+
"tokens_per_kloc": tokens_per_kloc,
|
|
575
|
+
"agents": list(agents),
|
|
576
|
+
"models": list(models),
|
|
577
|
+
"tool_calls": tool_calls,
|
|
578
|
+
"tools": tools,
|
|
579
|
+
"errors": errors,
|
|
580
|
+
"error_count": len(errors),
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
def get_agents(db_path: Path) -> list[dict]:
|
|
585
|
+
conn = _connect(db_path)
|
|
586
|
+
if conn is None:
|
|
587
|
+
return []
|
|
588
|
+
try:
|
|
589
|
+
return [
|
|
590
|
+
{
|
|
591
|
+
"agent": r["agent"],
|
|
592
|
+
"span_count": r["span_count"],
|
|
593
|
+
"session_count": r["session_count"],
|
|
594
|
+
"avg_duration": r["avg_dur"] if r["avg_dur"] else 0,
|
|
595
|
+
"error_count": r["error_count"],
|
|
596
|
+
}
|
|
597
|
+
for r in conn.execute(
|
|
598
|
+
f"""SELECT {_tags_val('agent')} as agent,
|
|
599
|
+
COUNT(*) as span_count,
|
|
600
|
+
COUNT(DISTINCT session_id) as session_count,
|
|
601
|
+
AVG({_json_val('duration_ms')}) as avg_dur,
|
|
602
|
+
SUM(CASE WHEN {_json_val('status')} IN ('error','failed') OR ({_json_val('error')} IS NOT NULL AND {_json_val('error')} != '') THEN 1 ELSE 0 END) as error_count
|
|
603
|
+
FROM traces
|
|
604
|
+
WHERE {_tags_val('agent')} IS NOT NULL
|
|
605
|
+
GROUP BY agent
|
|
606
|
+
ORDER BY span_count DESC"""
|
|
607
|
+
).fetchall()
|
|
608
|
+
]
|
|
609
|
+
finally:
|
|
610
|
+
conn.close()
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
def get_user_stats(db_path: Path) -> list[dict]:
|
|
614
|
+
conn = _connect(db_path)
|
|
615
|
+
if conn is None:
|
|
616
|
+
return []
|
|
617
|
+
try:
|
|
618
|
+
return [
|
|
619
|
+
{
|
|
620
|
+
"user_id": r["user_id"],
|
|
621
|
+
"trace_count": r["trace_count"],
|
|
622
|
+
"session_count": r["session_count"],
|
|
623
|
+
"total_tokens": r["total_tokens"],
|
|
624
|
+
"total_cost": r["total_cost"],
|
|
625
|
+
}
|
|
626
|
+
for r in conn.execute(
|
|
627
|
+
f"""SELECT {_tags_val('user_id')} as user_id,
|
|
628
|
+
COUNT(*) as trace_count,
|
|
629
|
+
COUNT(DISTINCT session_id) as session_count,
|
|
630
|
+
COALESCE(SUM({_json_val('token_count')}), 0) as total_tokens,
|
|
631
|
+
0 as total_cost
|
|
632
|
+
FROM traces
|
|
633
|
+
WHERE {_tags_val('user_id')} IS NOT NULL AND {_tags_val('user_id')} != ''
|
|
634
|
+
GROUP BY user_id
|
|
635
|
+
ORDER BY trace_count DESC
|
|
636
|
+
LIMIT 100"""
|
|
637
|
+
).fetchall()
|
|
638
|
+
]
|
|
639
|
+
finally:
|
|
640
|
+
conn.close()
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
def get_tag_stats(db_path: Path) -> list[dict]:
|
|
644
|
+
conn = _connect(db_path)
|
|
645
|
+
if conn is None:
|
|
646
|
+
return []
|
|
647
|
+
try:
|
|
648
|
+
tags_data = conn.execute(
|
|
649
|
+
f"SELECT tags FROM traces WHERE tags IS NOT NULL"
|
|
650
|
+
).fetchall()
|
|
651
|
+
tag_counts: dict[str, int] = {}
|
|
652
|
+
for row in tags_data:
|
|
653
|
+
try:
|
|
654
|
+
tags = json.loads(row[0]) if isinstance(row[0], str) else row[0]
|
|
655
|
+
if isinstance(tags, dict):
|
|
656
|
+
for k, v in tags.items():
|
|
657
|
+
key = str(k)
|
|
658
|
+
val = str(v) if v is not None else ""
|
|
659
|
+
tag_key = f"{key}={val}"
|
|
660
|
+
tag_counts[tag_key] = tag_counts.get(tag_key, 0) + 1
|
|
661
|
+
except:
|
|
662
|
+
pass
|
|
663
|
+
return sorted(
|
|
664
|
+
[{"tag": k, "count": v} for k, v in tag_counts.items()],
|
|
665
|
+
key=lambda x: x["count"],
|
|
666
|
+
reverse=True
|
|
667
|
+
)[:50]
|
|
668
|
+
finally:
|
|
669
|
+
conn.close()
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
def get_env_stats(db_path: Path) -> dict:
|
|
673
|
+
conn = _connect(db_path)
|
|
674
|
+
if conn is None:
|
|
675
|
+
return {"environments": [], "current": None}
|
|
676
|
+
try:
|
|
677
|
+
envs = [
|
|
678
|
+
{"environment": r["env"], "count": r["cnt"], "error_rate": r["error_rate"]}
|
|
679
|
+
for r in conn.execute(
|
|
680
|
+
f"""SELECT {_tags_val('environment')} as env,
|
|
681
|
+
COUNT(*) as cnt,
|
|
682
|
+
SUM(CASE WHEN {_json_val('error')} IS NOT NULL AND {_json_val('error')} != '' THEN 1 ELSE 0 END) * 100.0 / COUNT(*) as error_rate
|
|
683
|
+
FROM traces
|
|
684
|
+
WHERE {_tags_val('environment')} IS NOT NULL
|
|
685
|
+
GROUP BY env
|
|
686
|
+
ORDER BY cnt DESC"""
|
|
687
|
+
).fetchall()
|
|
688
|
+
]
|
|
689
|
+
return {"environments": envs}
|
|
690
|
+
finally:
|
|
691
|
+
conn.close()
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
def get_scatter_data(db_path: Path, limit: int = 500) -> list[dict]:
|
|
695
|
+
conn = _connect(db_path)
|
|
696
|
+
if conn is None:
|
|
697
|
+
return []
|
|
698
|
+
try:
|
|
699
|
+
rows = conn.execute(
|
|
700
|
+
f"""SELECT
|
|
701
|
+
{_json_val('duration_ms')} as duration_ms,
|
|
702
|
+
{_json_val('token_count')} as token_count,
|
|
703
|
+
{_json_val('model')} as model,
|
|
704
|
+
{_json_val('status')} as status,
|
|
705
|
+
timestamp
|
|
706
|
+
FROM traces
|
|
707
|
+
WHERE {_json_val('duration_ms')} IS NOT NULL
|
|
708
|
+
AND {_json_val('token_count')} IS NOT NULL
|
|
709
|
+
AND {_json_val('model')} IS NOT NULL
|
|
710
|
+
ORDER BY timestamp DESC
|
|
711
|
+
LIMIT ?""",
|
|
712
|
+
(limit,)
|
|
713
|
+
).fetchall()
|
|
714
|
+
return [
|
|
715
|
+
{
|
|
716
|
+
"x": float(r["duration_ms"] or 0),
|
|
717
|
+
"y": int(r["token_count"] or 0),
|
|
718
|
+
"model": r["model"] or "unknown",
|
|
719
|
+
"status": r["status"] or "unknown",
|
|
720
|
+
"timestamp": r["timestamp"],
|
|
721
|
+
}
|
|
722
|
+
for r in rows
|
|
723
|
+
]
|
|
724
|
+
finally:
|
|
725
|
+
conn.close()
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
def get_model_stats(db_path: Path) -> list[dict]:
|
|
729
|
+
conn = _connect(db_path)
|
|
730
|
+
if conn is None:
|
|
731
|
+
return []
|
|
732
|
+
try:
|
|
733
|
+
return [
|
|
734
|
+
{
|
|
735
|
+
"model": r["model"],
|
|
736
|
+
"span_count": r["span_count"],
|
|
737
|
+
"total_tokens": r["total_tokens"],
|
|
738
|
+
"input_tokens": r["input_tokens"],
|
|
739
|
+
"output_tokens": r["output_tokens"],
|
|
740
|
+
"avg_duration": round(r["avg_dur"], 3) if r["avg_dur"] else 0,
|
|
741
|
+
"error_count": r["error_count"],
|
|
742
|
+
"error_rate": round(r["error_count"] / r["span_count"] * 100, 2) if r["span_count"] else 0,
|
|
743
|
+
"success_rate": round((r["span_count"] - r["error_count"]) / r["span_count"] * 100, 2) if r["span_count"] else 0,
|
|
744
|
+
}
|
|
745
|
+
for r in conn.execute(
|
|
746
|
+
f"""SELECT {_model_val()} as model,
|
|
747
|
+
COUNT(*) as span_count,
|
|
748
|
+
COALESCE(SUM({_json_val('token_count')}), 0) as total_tokens,
|
|
749
|
+
COALESCE(SUM({_json_val('input_tokens')}), 0) as input_tokens,
|
|
750
|
+
COALESCE(SUM({_json_val('output_tokens')}), 0) as output_tokens,
|
|
751
|
+
AVG({_json_val('duration_ms')}) as avg_dur,
|
|
752
|
+
SUM(CASE WHEN {_json_val('status')} IN ('error','failed') OR ({_json_val('error')} IS NOT NULL AND {_json_val('error')} != '') THEN 1 ELSE 0 END) as error_count
|
|
753
|
+
FROM traces
|
|
754
|
+
WHERE {_model_val()} IS NOT NULL AND {_model_val()} != ''
|
|
755
|
+
GROUP BY model
|
|
756
|
+
ORDER BY total_tokens DESC"""
|
|
757
|
+
).fetchall()
|
|
758
|
+
]
|
|
759
|
+
finally:
|
|
760
|
+
conn.close()
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
def get_tool_stats(db_path: Path) -> list[dict]:
|
|
764
|
+
conn = _connect(db_path)
|
|
765
|
+
if conn is None:
|
|
766
|
+
return []
|
|
767
|
+
try:
|
|
768
|
+
return [
|
|
769
|
+
{
|
|
770
|
+
"tool": r["tool"],
|
|
771
|
+
"call_count": r["call_count"],
|
|
772
|
+
"avg_duration": r["avg_dur"] if r["avg_dur"] else 0,
|
|
773
|
+
"error_count": r["error_count"],
|
|
774
|
+
}
|
|
775
|
+
for r in conn.execute(
|
|
776
|
+
f"""SELECT {_json_val('tool_name')} as tool,
|
|
777
|
+
COUNT(*) as call_count,
|
|
778
|
+
AVG({_json_val('duration_ms')}) as avg_dur,
|
|
779
|
+
SUM(CASE WHEN {_json_val('status')} IN ('error','failed') THEN 1 ELSE 0 END) as error_count
|
|
780
|
+
FROM traces
|
|
781
|
+
WHERE {_json_val('tool_name')} IS NOT NULL AND {_json_val('tool_name')} != ''
|
|
782
|
+
GROUP BY tool
|
|
783
|
+
ORDER BY call_count DESC"""
|
|
784
|
+
).fetchall()
|
|
785
|
+
]
|
|
786
|
+
finally:
|
|
787
|
+
conn.close()
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
def get_error_stats(db_path: Path) -> list[dict]:
|
|
791
|
+
conn = _connect(db_path)
|
|
792
|
+
if conn is None:
|
|
793
|
+
return []
|
|
794
|
+
try:
|
|
795
|
+
return [
|
|
796
|
+
{
|
|
797
|
+
"error": r["error"],
|
|
798
|
+
"count": r["cnt"],
|
|
799
|
+
"latest": r["latest"],
|
|
800
|
+
"latest_session": r["latest_session"],
|
|
801
|
+
}
|
|
802
|
+
for r in conn.execute(
|
|
803
|
+
f"""SELECT {_json_val('error')} as error,
|
|
804
|
+
COUNT(*) as cnt,
|
|
805
|
+
MAX(timestamp) as latest,
|
|
806
|
+
(SELECT session_id FROM traces WHERE {_json_val('error')} IS NOT NULL AND {_json_val('error')} != '' ORDER BY timestamp DESC LIMIT 1) as latest_session
|
|
807
|
+
FROM traces
|
|
808
|
+
WHERE {_json_val('error')} IS NOT NULL AND {_json_val('error')} != ''
|
|
809
|
+
GROUP BY error
|
|
810
|
+
ORDER BY cnt DESC"""
|
|
811
|
+
).fetchall()
|
|
812
|
+
]
|
|
813
|
+
finally:
|
|
814
|
+
conn.close()
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
def get_latency_stats(db_path: Path) -> dict:
|
|
818
|
+
conn = _connect(db_path)
|
|
819
|
+
if conn is None:
|
|
820
|
+
return {"p50": 0, "p95": 0, "p99": 0, "histogram": []}
|
|
821
|
+
try:
|
|
822
|
+
durations = sorted([
|
|
823
|
+
float(r[0])
|
|
824
|
+
for r in conn.execute(
|
|
825
|
+
"SELECT {} FROM traces WHERE {} IS NOT NULL AND {} > 0".format(
|
|
826
|
+
_json_val("duration_ms"), _json_val("duration_ms"), _json_val("duration_ms")
|
|
827
|
+
)
|
|
828
|
+
).fetchall()
|
|
829
|
+
if r[0] is not None
|
|
830
|
+
])
|
|
831
|
+
|
|
832
|
+
if not durations:
|
|
833
|
+
return {"p50": 0, "p95": 0, "p99": 0, "histogram": []}
|
|
834
|
+
|
|
835
|
+
p50 = _percentile(durations, 50)
|
|
836
|
+
p95 = _percentile(durations, 95)
|
|
837
|
+
p99 = _percentile(durations, 99)
|
|
838
|
+
|
|
839
|
+
max_dur = max(durations)
|
|
840
|
+
bucket_count = 20
|
|
841
|
+
bucket_size = max_dur / bucket_count
|
|
842
|
+
histogram = [0] * bucket_count
|
|
843
|
+
for d in durations:
|
|
844
|
+
idx = min(int(d / bucket_size), bucket_count - 1)
|
|
845
|
+
histogram[idx] += 1
|
|
846
|
+
|
|
847
|
+
buckets = [
|
|
848
|
+
{"range": f"{round(i * bucket_size, 2)}-{round((i + 1) * bucket_size, 2)}", "count": histogram[i]}
|
|
849
|
+
for i in range(bucket_count)
|
|
850
|
+
]
|
|
851
|
+
|
|
852
|
+
return {
|
|
853
|
+
"p50": round(p50, 3),
|
|
854
|
+
"p95": round(p95, 3),
|
|
855
|
+
"p99": round(p99, 99),
|
|
856
|
+
"avg": round(sum(durations) / len(durations), 3),
|
|
857
|
+
"total": len(durations),
|
|
858
|
+
"histogram": buckets,
|
|
859
|
+
}
|
|
860
|
+
finally:
|
|
861
|
+
conn.close()
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
def get_cost_stats(db_path: Path, model_prices: dict[str, float] | None = None) -> dict:
|
|
865
|
+
conn = _connect(db_path)
|
|
866
|
+
if conn is None:
|
|
867
|
+
return {"total_tokens": 0, "total_input": 0, "total_output": 0, "daily": [], "by_model": []}
|
|
868
|
+
try:
|
|
869
|
+
# Only treat prices as real when the caller supplied a non-empty map.
|
|
870
|
+
# Otherwise we must NOT fabricate a cost (no prices => estimated=false, cost=0).
|
|
871
|
+
prices = model_prices or {}
|
|
872
|
+
has_real_prices = bool(prices)
|
|
873
|
+
|
|
874
|
+
# By day
|
|
875
|
+
daily = []
|
|
876
|
+
for r in conn.execute(
|
|
877
|
+
f"""SELECT strftime('%%Y-%%m-%%d', timestamp) as day,
|
|
878
|
+
SUM(COALESCE({_json_val('token_count')}, 0)) as total_tokens,
|
|
879
|
+
SUM(COALESCE({_json_val('input_tokens')}, 0)) as total_input,
|
|
880
|
+
SUM(COALESCE({_json_val('output_tokens')}, 0)) as total_output
|
|
881
|
+
FROM traces
|
|
882
|
+
WHERE {_json_val('token_count')} IS NOT NULL
|
|
883
|
+
GROUP BY day
|
|
884
|
+
ORDER BY day ASC"""
|
|
885
|
+
).fetchall():
|
|
886
|
+
entry = dict(r)
|
|
887
|
+
entry["cost"] = 0
|
|
888
|
+
entry["cost_details"] = {}
|
|
889
|
+
daily.append(entry)
|
|
890
|
+
|
|
891
|
+
# Total
|
|
892
|
+
total_tokens = conn.execute(
|
|
893
|
+
"SELECT COALESCE(SUM({}), 0) FROM traces".format(_json_val("token_count"))
|
|
894
|
+
).fetchone()[0]
|
|
895
|
+
total_input = conn.execute(
|
|
896
|
+
"SELECT COALESCE(SUM({}), 0) FROM traces".format(_json_val("input_tokens"))
|
|
897
|
+
).fetchone()[0]
|
|
898
|
+
total_output = conn.execute(
|
|
899
|
+
"SELECT COALESCE(SUM({}), 0) FROM traces".format(_json_val("output_tokens"))
|
|
900
|
+
).fetchone()[0]
|
|
901
|
+
|
|
902
|
+
# By model
|
|
903
|
+
by_model = [
|
|
904
|
+
{
|
|
905
|
+
"model": r["model"],
|
|
906
|
+
"tokens": r["tokens"],
|
|
907
|
+
"cost": round(r["tokens"] / 1000 * prices[r["model"]], 4) if has_real_prices else 0,
|
|
908
|
+
}
|
|
909
|
+
for r in conn.execute(
|
|
910
|
+
f"""SELECT {_json_val('model')} as model,
|
|
911
|
+
SUM(COALESCE({_json_val('token_count')}, 0)) as tokens
|
|
912
|
+
FROM traces
|
|
913
|
+
WHERE {_json_val('model')} IS NOT NULL AND {_json_val('model')} != ''
|
|
914
|
+
GROUP BY model
|
|
915
|
+
ORDER BY tokens DESC"""
|
|
916
|
+
).fetchall()
|
|
917
|
+
]
|
|
918
|
+
|
|
919
|
+
return {
|
|
920
|
+
"total_tokens": total_tokens,
|
|
921
|
+
"total_input": total_input,
|
|
922
|
+
"total_output": total_output,
|
|
923
|
+
"daily": daily,
|
|
924
|
+
"by_model": by_model,
|
|
925
|
+
"prices": prices,
|
|
926
|
+
"estimated": not has_real_prices,
|
|
927
|
+
}
|
|
928
|
+
finally:
|
|
929
|
+
conn.close()
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
def get_loc_stats(db_path: Path) -> dict:
|
|
933
|
+
"""Lines-of-code productivity metrics.
|
|
934
|
+
|
|
935
|
+
Returns total lines added (Edit/Write), total tokens, and the derived
|
|
936
|
+
"tokens per 1k lines of code" efficiency metric, both overall and broken
|
|
937
|
+
down per model.
|
|
938
|
+
"""
|
|
939
|
+
conn = _connect(db_path)
|
|
940
|
+
if conn is None:
|
|
941
|
+
return {
|
|
942
|
+
"total_lines_added": 0,
|
|
943
|
+
"total_tokens": 0,
|
|
944
|
+
"tokens_per_kloc": 0,
|
|
945
|
+
"by_model": [],
|
|
946
|
+
}
|
|
947
|
+
try:
|
|
948
|
+
total_lines = conn.execute(
|
|
949
|
+
"SELECT COALESCE(SUM({}), 0) FROM traces".format(_json_val("lines_added"))
|
|
950
|
+
).fetchone()[0]
|
|
951
|
+
total_tokens = conn.execute(
|
|
952
|
+
"SELECT COALESCE(SUM({}), 0) FROM traces".format(_json_val("token_count"))
|
|
953
|
+
).fetchone()[0]
|
|
954
|
+
|
|
955
|
+
by_model = [
|
|
956
|
+
{
|
|
957
|
+
"model": r["model"],
|
|
958
|
+
"lines_added": r["lines"],
|
|
959
|
+
"tokens": r["tokens"],
|
|
960
|
+
"tokens_per_kloc": (
|
|
961
|
+
round(r["tokens"] / (r["lines"] / 1000), 2) if r["lines"] else 0
|
|
962
|
+
),
|
|
963
|
+
}
|
|
964
|
+
for r in conn.execute(
|
|
965
|
+
f"""SELECT {_json_val('model')} as model,
|
|
966
|
+
COALESCE(SUM({_json_val('lines_added')}), 0) as lines,
|
|
967
|
+
COALESCE(SUM({_json_val('token_count')}), 0) as tokens
|
|
968
|
+
FROM traces
|
|
969
|
+
WHERE {_json_val('model')} IS NOT NULL AND {_json_val('model')} != ''
|
|
970
|
+
GROUP BY model
|
|
971
|
+
ORDER BY tokens DESC"""
|
|
972
|
+
).fetchall()
|
|
973
|
+
]
|
|
974
|
+
|
|
975
|
+
return {
|
|
976
|
+
"total_lines_added": total_lines,
|
|
977
|
+
"total_tokens": total_tokens,
|
|
978
|
+
"tokens_per_kloc": (
|
|
979
|
+
round(total_tokens / (total_lines / 1000), 2) if total_lines else 0
|
|
980
|
+
),
|
|
981
|
+
"by_model": by_model,
|
|
982
|
+
}
|
|
983
|
+
finally:
|
|
984
|
+
conn.close()
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
def export_traces(
|
|
988
|
+
db_path: Path,
|
|
989
|
+
fmt: str = "json",
|
|
990
|
+
trace_type: str | None = None,
|
|
991
|
+
agent: str | None = None,
|
|
992
|
+
session_id: str | None = None,
|
|
993
|
+
limit: int = 500,
|
|
994
|
+
) -> Any:
|
|
995
|
+
conn = _connect(db_path)
|
|
996
|
+
if conn is None:
|
|
997
|
+
return [] if fmt == "json" else ""
|
|
998
|
+
conn.close()
|
|
999
|
+
result = get_traces(
|
|
1000
|
+
db_path=db_path,
|
|
1001
|
+
limit=limit,
|
|
1002
|
+
offset=0,
|
|
1003
|
+
trace_type=trace_type,
|
|
1004
|
+
agent=agent,
|
|
1005
|
+
session_id=session_id,
|
|
1006
|
+
)
|
|
1007
|
+
if fmt == "json":
|
|
1008
|
+
return result["traces"]
|
|
1009
|
+
elif fmt == "csv":
|
|
1010
|
+
import io
|
|
1011
|
+
|
|
1012
|
+
output = io.StringIO()
|
|
1013
|
+
traces = result["traces"]
|
|
1014
|
+
if traces:
|
|
1015
|
+
keys = ["id", "session_id", "timestamp", "type", "function", "agent", "model", "duration_ms"]
|
|
1016
|
+
output.write(",".join(keys) + "\n")
|
|
1017
|
+
for t in traces:
|
|
1018
|
+
tags = t.get("tags") or {}
|
|
1019
|
+
data = t.get("data") or {}
|
|
1020
|
+
row = [
|
|
1021
|
+
str(t.get("id", "")),
|
|
1022
|
+
str(t.get("session_id", "")),
|
|
1023
|
+
str(t.get("timestamp", "")),
|
|
1024
|
+
str(t.get("type", "")),
|
|
1025
|
+
str(t.get("function", "")),
|
|
1026
|
+
str((tags if isinstance(tags, dict) else {}).get("agent", "")),
|
|
1027
|
+
str(data.get("model", "")),
|
|
1028
|
+
str(data.get("duration_ms", "")),
|
|
1029
|
+
]
|
|
1030
|
+
output.write(",".join(row) + "\n")
|
|
1031
|
+
return output.getvalue()
|
|
1032
|
+
return result["traces"]
|