@pellux/goodvibes-agent 0.1.0
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/.goodvibes/GOODVIBES.md +35 -0
- package/.goodvibes/agents/reviewer.md +48 -0
- package/.goodvibes/skills/add-provider/SKILL.md +199 -0
- package/CHANGELOG.md +25 -0
- package/README.md +74 -0
- package/bin/goodvibes-agent.ts +2 -0
- package/docs/README.md +23 -0
- package/docs/deployment-and-services.md +57 -0
- package/docs/getting-started.md +53 -0
- package/docs/release-and-publishing.md +46 -0
- package/package.json +134 -0
- package/scripts/check-bun.sh +20 -0
- package/src/audio/player.ts +156 -0
- package/src/audio/spoken-turn-controller.ts +203 -0
- package/src/audio/spoken-turn-model-routing.ts +117 -0
- package/src/audio/spoken-turn-wiring.ts +44 -0
- package/src/audio/text-chunker.ts +110 -0
- package/src/cli/bundle-command.ts +227 -0
- package/src/cli/completion.ts +90 -0
- package/src/cli/config-overrides.ts +159 -0
- package/src/cli/endpoints.ts +63 -0
- package/src/cli/entrypoint.ts +172 -0
- package/src/cli/help.ts +299 -0
- package/src/cli/index.ts +11 -0
- package/src/cli/management-commands.ts +426 -0
- package/src/cli/management.ts +744 -0
- package/src/cli/network-posture.ts +46 -0
- package/src/cli/package-verification.ts +123 -0
- package/src/cli/parser.ts +369 -0
- package/src/cli/provider-auth-routes.ts +22 -0
- package/src/cli/provider-classification.ts +107 -0
- package/src/cli/redaction.ts +105 -0
- package/src/cli/service-command.ts +26 -0
- package/src/cli/service-posture.ts +482 -0
- package/src/cli/status.ts +383 -0
- package/src/cli/surface-command.ts +247 -0
- package/src/cli/tui-startup.ts +32 -0
- package/src/cli/types.ts +69 -0
- package/src/cli-flags.ts +21 -0
- package/src/config/goodvibes-home-audit.ts +465 -0
- package/src/config/index.ts +57 -0
- package/src/config/provider-model.ts +23 -0
- package/src/config/secret-config.ts +119 -0
- package/src/config/secrets.ts +71 -0
- package/src/config/surface.ts +1 -0
- package/src/core/composer-state.ts +61 -0
- package/src/core/conversation-rendering.ts +359 -0
- package/src/core/conversation.ts +551 -0
- package/src/core/history.ts +45 -0
- package/src/core/orchestrator.ts +7 -0
- package/src/core/system-message-router.ts +171 -0
- package/src/daemon/cli.ts +55 -0
- package/src/daemon/safe-serve.ts +61 -0
- package/src/input/agent-workspace.ts +428 -0
- package/src/input/autocomplete.ts +96 -0
- package/src/input/bookmark-modal.ts +115 -0
- package/src/input/command-args-hint.ts +36 -0
- package/src/input/command-registry.ts +329 -0
- package/src/input/commands/agent-externalized-tui.ts +73 -0
- package/src/input/commands/agent-workspace-runtime.ts +17 -0
- package/src/input/commands/branch-runtime.ts +72 -0
- package/src/input/commands/cloudflare-runtime.ts +370 -0
- package/src/input/commands/config.ts +18 -0
- package/src/input/commands/control-room-runtime.ts +255 -0
- package/src/input/commands/conversation-runtime.ts +207 -0
- package/src/input/commands/discovery-runtime.ts +52 -0
- package/src/input/commands/eval.ts +204 -0
- package/src/input/commands/experience-runtime.ts +278 -0
- package/src/input/commands/guidance-runtime.ts +106 -0
- package/src/input/commands/health-runtime.ts +434 -0
- package/src/input/commands/hooks-runtime.ts +148 -0
- package/src/input/commands/incident-runtime.ts +95 -0
- package/src/input/commands/integration-runtime.ts +394 -0
- package/src/input/commands/intelligence-runtime.ts +223 -0
- package/src/input/commands/knowledge.ts +531 -0
- package/src/input/commands/local-auth-runtime.ts +105 -0
- package/src/input/commands/local-provider-runtime.ts +170 -0
- package/src/input/commands/local-runtime.ts +392 -0
- package/src/input/commands/local-setup-review.ts +199 -0
- package/src/input/commands/local-setup-transfer.ts +135 -0
- package/src/input/commands/local-setup.ts +282 -0
- package/src/input/commands/managed-runtime.ts +209 -0
- package/src/input/commands/marketplace-runtime.ts +290 -0
- package/src/input/commands/mcp-runtime.ts +432 -0
- package/src/input/commands/memory-product-runtime.ts +111 -0
- package/src/input/commands/memory.ts +151 -0
- package/src/input/commands/notify-runtime.ts +83 -0
- package/src/input/commands/onboarding-runtime.ts +14 -0
- package/src/input/commands/operator-panel-runtime.ts +146 -0
- package/src/input/commands/operator-runtime.ts +392 -0
- package/src/input/commands/planning-runtime.ts +205 -0
- package/src/input/commands/platform-access-runtime.ts +422 -0
- package/src/input/commands/platform-services-runtime.ts +246 -0
- package/src/input/commands/policy-dispatch.ts +339 -0
- package/src/input/commands/policy.ts +17 -0
- package/src/input/commands/product-runtime.ts +351 -0
- package/src/input/commands/profile-sync-runtime.ts +99 -0
- package/src/input/commands/provider-accounts-runtime.ts +113 -0
- package/src/input/commands/provider.ts +363 -0
- package/src/input/commands/qrcode-runtime.ts +20 -0
- package/src/input/commands/quit-shared.ts +162 -0
- package/src/input/commands/recall-bundle.ts +132 -0
- package/src/input/commands/recall-capture.ts +152 -0
- package/src/input/commands/recall-query.ts +229 -0
- package/src/input/commands/recall-review.ts +98 -0
- package/src/input/commands/recall-shared.ts +22 -0
- package/src/input/commands/remote-runtime-pool.ts +106 -0
- package/src/input/commands/remote-runtime-setup.ts +199 -0
- package/src/input/commands/remote-runtime.ts +431 -0
- package/src/input/commands/replay-runtime.ts +18 -0
- package/src/input/commands/runtime-services.ts +291 -0
- package/src/input/commands/schedule-runtime.ts +91 -0
- package/src/input/commands/services-runtime.ts +209 -0
- package/src/input/commands/session-content.ts +408 -0
- package/src/input/commands/session-workflow.ts +464 -0
- package/src/input/commands/session.ts +375 -0
- package/src/input/commands/settings-sync-runtime.ts +174 -0
- package/src/input/commands/share-runtime.ts +119 -0
- package/src/input/commands/shell-core.ts +307 -0
- package/src/input/commands/skills-runtime.ts +221 -0
- package/src/input/commands/subscription-runtime.ts +434 -0
- package/src/input/commands/tasks-runtime.ts +230 -0
- package/src/input/commands/teamwork-runtime.ts +339 -0
- package/src/input/commands/teleport-runtime.ts +57 -0
- package/src/input/commands/tts-runtime.ts +29 -0
- package/src/input/commands/work-plan-runtime.ts +169 -0
- package/src/input/commands.ts +131 -0
- package/src/input/feed-context-factory.ts +254 -0
- package/src/input/file-picker.ts +192 -0
- package/src/input/handler-command-route.ts +180 -0
- package/src/input/handler-content-actions.ts +497 -0
- package/src/input/handler-feed-routes.ts +648 -0
- package/src/input/handler-feed.ts +452 -0
- package/src/input/handler-interactions.ts +281 -0
- package/src/input/handler-modal-routes.ts +418 -0
- package/src/input/handler-modal-stack.ts +263 -0
- package/src/input/handler-modal-token-routes.ts +329 -0
- package/src/input/handler-onboarding-cloudflare.ts +391 -0
- package/src/input/handler-onboarding.ts +620 -0
- package/src/input/handler-picker-routes.ts +472 -0
- package/src/input/handler-prompt-buffer.ts +320 -0
- package/src/input/handler-shortcuts.ts +213 -0
- package/src/input/handler-ui-state.ts +372 -0
- package/src/input/handler.ts +729 -0
- package/src/input/input-history.ts +297 -0
- package/src/input/keybindings.ts +292 -0
- package/src/input/mcp-workspace.ts +554 -0
- package/src/input/model-picker-provider-filter.ts +28 -0
- package/src/input/model-picker-types.ts +137 -0
- package/src/input/model-picker.ts +797 -0
- package/src/input/onboarding/handler-onboarding-routes.ts +125 -0
- package/src/input/onboarding/onboarding-runtime-status.ts +87 -0
- package/src/input/onboarding/onboarding-wizard-apply.ts +277 -0
- package/src/input/onboarding/onboarding-wizard-cloudflare-step.ts +494 -0
- package/src/input/onboarding/onboarding-wizard-cloudflare.ts +204 -0
- package/src/input/onboarding/onboarding-wizard-constants.ts +158 -0
- package/src/input/onboarding/onboarding-wizard-external-surface-extra-specs.ts +130 -0
- package/src/input/onboarding/onboarding-wizard-external-surfaces.ts +762 -0
- package/src/input/onboarding/onboarding-wizard-helpers.ts +167 -0
- package/src/input/onboarding/onboarding-wizard-rules.ts +256 -0
- package/src/input/onboarding/onboarding-wizard-state.ts +365 -0
- package/src/input/onboarding/onboarding-wizard-steps.ts +798 -0
- package/src/input/onboarding/onboarding-wizard-types.ts +195 -0
- package/src/input/onboarding/onboarding-wizard.ts +711 -0
- package/src/input/panel-integration-actions.ts +78 -0
- package/src/input/profile-picker-modal.ts +222 -0
- package/src/input/search.ts +100 -0
- package/src/input/selection-modal.ts +163 -0
- package/src/input/selection.ts +135 -0
- package/src/input/session-picker-modal.ts +136 -0
- package/src/input/settings-modal-behavior.ts +37 -0
- package/src/input/settings-modal-secrets.ts +41 -0
- package/src/input/settings-modal-subscriptions.ts +95 -0
- package/src/input/settings-modal-types.ts +91 -0
- package/src/input/settings-modal.ts +793 -0
- package/src/input/submission-intent.ts +17 -0
- package/src/input/submission-router.ts +59 -0
- package/src/input/tts-settings-actions.ts +100 -0
- package/src/main.ts +792 -0
- package/src/mcp/runtime-reload.ts +81 -0
- package/src/panels/agent-inspector-panel.ts +521 -0
- package/src/panels/agent-inspector-shared.ts +94 -0
- package/src/panels/agent-logs-panel.ts +559 -0
- package/src/panels/agent-logs-shared.ts +129 -0
- package/src/panels/approval-panel.ts +150 -0
- package/src/panels/automation-control-panel.ts +212 -0
- package/src/panels/base-panel.ts +254 -0
- package/src/panels/builtin/agent.ts +117 -0
- package/src/panels/builtin/development.ts +31 -0
- package/src/panels/builtin/knowledge.ts +26 -0
- package/src/panels/builtin/operations.ts +349 -0
- package/src/panels/builtin/session.ts +129 -0
- package/src/panels/builtin/shared.ts +274 -0
- package/src/panels/builtin-panels.ts +23 -0
- package/src/panels/cockpit-panel.ts +183 -0
- package/src/panels/communication-panel.ts +153 -0
- package/src/panels/confirm-state.ts +61 -0
- package/src/panels/context-visualizer-panel.ts +204 -0
- package/src/panels/control-plane-panel.ts +211 -0
- package/src/panels/cost-tracker-panel.ts +444 -0
- package/src/panels/debug-panel.ts +432 -0
- package/src/panels/diff-panel.ts +520 -0
- package/src/panels/docs-panel.ts +283 -0
- package/src/panels/eval-panel.ts +399 -0
- package/src/panels/file-explorer-panel.ts +584 -0
- package/src/panels/file-preview-panel.ts +434 -0
- package/src/panels/forensics-panel.ts +364 -0
- package/src/panels/git-panel.ts +638 -0
- package/src/panels/hooks-panel.ts +239 -0
- package/src/panels/incident-review-panel.ts +197 -0
- package/src/panels/index.ts +46 -0
- package/src/panels/intelligence-panel.ts +176 -0
- package/src/panels/knowledge-panel.ts +345 -0
- package/src/panels/local-auth-panel.ts +130 -0
- package/src/panels/marketplace-panel.ts +212 -0
- package/src/panels/memory-panel.ts +225 -0
- package/src/panels/ops-control-panel.ts +150 -0
- package/src/panels/ops-strategy-panel.ts +235 -0
- package/src/panels/orchestration-panel.ts +273 -0
- package/src/panels/panel-list-panel.ts +509 -0
- package/src/panels/panel-manager.ts +570 -0
- package/src/panels/panel-picker.ts +106 -0
- package/src/panels/plan-dashboard-panel.ts +274 -0
- package/src/panels/plugins-panel.ts +178 -0
- package/src/panels/policy-panel.ts +308 -0
- package/src/panels/polish.ts +717 -0
- package/src/panels/project-planning-panel.ts +711 -0
- package/src/panels/provider-account-snapshot.ts +259 -0
- package/src/panels/provider-accounts-panel.ts +218 -0
- package/src/panels/provider-health-domains.ts +215 -0
- package/src/panels/provider-health-panel.ts +727 -0
- package/src/panels/provider-health-tracker.ts +115 -0
- package/src/panels/provider-stats-panel.ts +366 -0
- package/src/panels/qr-panel.ts +182 -0
- package/src/panels/remote-panel.ts +449 -0
- package/src/panels/routes-panel.ts +178 -0
- package/src/panels/sandbox-panel.ts +283 -0
- package/src/panels/schedule-panel.ts +329 -0
- package/src/panels/scrollable-list-panel.ts +491 -0
- package/src/panels/search-focus.ts +32 -0
- package/src/panels/security-panel.ts +295 -0
- package/src/panels/services-panel.ts +231 -0
- package/src/panels/session-browser-panel.ts +400 -0
- package/src/panels/session-maintenance.ts +125 -0
- package/src/panels/settings-sync-panel.ts +120 -0
- package/src/panels/skills-panel.ts +431 -0
- package/src/panels/subscription-panel.ts +263 -0
- package/src/panels/symbol-outline-panel.ts +486 -0
- package/src/panels/system-messages-panel.ts +230 -0
- package/src/panels/tasks-panel.ts +399 -0
- package/src/panels/thinking-panel.ts +304 -0
- package/src/panels/token-budget-panel.ts +475 -0
- package/src/panels/tool-inspector-panel.ts +429 -0
- package/src/panels/types.ts +54 -0
- package/src/panels/watchers-panel.ts +193 -0
- package/src/panels/work-plan-panel.ts +175 -0
- package/src/panels/worktree-panel.ts +182 -0
- package/src/panels/wrfc-panel.ts +609 -0
- package/src/permissions/prompt.ts +165 -0
- package/src/planning/project-planning-coordinator.ts +543 -0
- package/src/plugins/loader.ts +15 -0
- package/src/renderer/agent-detail-modal.ts +331 -0
- package/src/renderer/agent-workspace.ts +238 -0
- package/src/renderer/ansi-sanitize.ts +76 -0
- package/src/renderer/autocomplete-overlay.ts +154 -0
- package/src/renderer/block-actions.ts +76 -0
- package/src/renderer/bookmark-modal.ts +101 -0
- package/src/renderer/bottom-bar.ts +58 -0
- package/src/renderer/buffer.ts +113 -0
- package/src/renderer/code-block.ts +373 -0
- package/src/renderer/compositor.ts +283 -0
- package/src/renderer/context-inspector.ts +219 -0
- package/src/renderer/conversation-layout.ts +67 -0
- package/src/renderer/conversation-overlays.ts +140 -0
- package/src/renderer/conversation-surface.ts +260 -0
- package/src/renderer/diff-view.ts +132 -0
- package/src/renderer/diff.ts +130 -0
- package/src/renderer/file-picker-overlay.ts +101 -0
- package/src/renderer/file-tree.ts +153 -0
- package/src/renderer/fullscreen-primitives.ts +130 -0
- package/src/renderer/fullscreen-workspace.ts +199 -0
- package/src/renderer/git-status.ts +89 -0
- package/src/renderer/help-overlay.ts +267 -0
- package/src/renderer/history-search-overlay.ts +73 -0
- package/src/renderer/layout-engine.ts +97 -0
- package/src/renderer/layout.ts +32 -0
- package/src/renderer/live-tail-modal.ts +156 -0
- package/src/renderer/markdown.ts +635 -0
- package/src/renderer/mcp-workspace.ts +237 -0
- package/src/renderer/modal-factory.ts +467 -0
- package/src/renderer/modal-utils.ts +24 -0
- package/src/renderer/model-picker-overlay.ts +473 -0
- package/src/renderer/model-workspace.ts +488 -0
- package/src/renderer/onboarding/onboarding-wizard.ts +615 -0
- package/src/renderer/overlay-box.ts +146 -0
- package/src/renderer/overlay-viewport.ts +104 -0
- package/src/renderer/panel-composite.ts +158 -0
- package/src/renderer/panel-picker-overlay.ts +202 -0
- package/src/renderer/panel-tab-bar.ts +69 -0
- package/src/renderer/panel-workspace-bar.ts +42 -0
- package/src/renderer/process-indicator.ts +96 -0
- package/src/renderer/process-modal.ts +656 -0
- package/src/renderer/process-summary.ts +67 -0
- package/src/renderer/profile-picker-modal.ts +129 -0
- package/src/renderer/progress.ts +98 -0
- package/src/renderer/qr-renderer.ts +120 -0
- package/src/renderer/search-overlay.ts +54 -0
- package/src/renderer/selection-modal-overlay.ts +214 -0
- package/src/renderer/semantic-diff.ts +369 -0
- package/src/renderer/session-picker-modal.ts +127 -0
- package/src/renderer/settings-modal-helpers.ts +193 -0
- package/src/renderer/settings-modal.ts +537 -0
- package/src/renderer/shell-surface.ts +88 -0
- package/src/renderer/status-glyphs.ts +21 -0
- package/src/renderer/status-token.ts +67 -0
- package/src/renderer/surface-layout.ts +101 -0
- package/src/renderer/syntax-highlighter.ts +542 -0
- package/src/renderer/system-message.ts +83 -0
- package/src/renderer/tab-strip.ts +108 -0
- package/src/renderer/text-layout.ts +31 -0
- package/src/renderer/thinking.ts +17 -0
- package/src/renderer/tool-call.ts +234 -0
- package/src/renderer/ui-factory.ts +524 -0
- package/src/renderer/ui-primitives.ts +96 -0
- package/src/runtime/bootstrap-command-context.ts +278 -0
- package/src/runtime/bootstrap-command-parts.ts +386 -0
- package/src/runtime/bootstrap-core.ts +540 -0
- package/src/runtime/bootstrap-hook-bridge.ts +112 -0
- package/src/runtime/bootstrap-shell.ts +283 -0
- package/src/runtime/bootstrap.ts +575 -0
- package/src/runtime/cloudflare-control-plane.ts +349 -0
- package/src/runtime/context.ts +142 -0
- package/src/runtime/diagnostics/panels/index.ts +24 -0
- package/src/runtime/diagnostics/panels/ops.ts +156 -0
- package/src/runtime/diagnostics/panels/panel-resources.ts +118 -0
- package/src/runtime/diagnostics/panels/policy.ts +177 -0
- package/src/runtime/index.ts +662 -0
- package/src/runtime/onboarding/apply.ts +642 -0
- package/src/runtime/onboarding/derivation.ts +534 -0
- package/src/runtime/onboarding/index.ts +7 -0
- package/src/runtime/onboarding/markers.ts +148 -0
- package/src/runtime/onboarding/snapshot.ts +406 -0
- package/src/runtime/onboarding/state.ts +141 -0
- package/src/runtime/onboarding/types.ts +404 -0
- package/src/runtime/onboarding/verify.ts +171 -0
- package/src/runtime/operator-token-cleanup.ts +27 -0
- package/src/runtime/perf/panel-contracts.ts +32 -0
- package/src/runtime/perf/panel-health-monitor.ts +18 -0
- package/src/runtime/sandbox-public-gaps.ts +358 -0
- package/src/runtime/services.ts +670 -0
- package/src/runtime/store/domains/domain-read-matrix.ts +15 -0
- package/src/runtime/store/domains/index.ts +222 -0
- package/src/runtime/store/domains/panels.ts +117 -0
- package/src/runtime/store/domains/ui-perf.ts +103 -0
- package/src/runtime/store/index.ts +305 -0
- package/src/runtime/store/selectors/index.ts +359 -0
- package/src/runtime/store/state.ts +145 -0
- package/src/runtime/surface-feature-flags.ts +65 -0
- package/src/runtime/terminal-output-guard.ts +228 -0
- package/src/runtime/ui/index.ts +39 -0
- package/src/runtime/ui/model-picker/data-provider.ts +182 -0
- package/src/runtime/ui/model-picker/health-enrichment.ts +228 -0
- package/src/runtime/ui/model-picker/index.ts +59 -0
- package/src/runtime/ui/model-picker/types.ts +149 -0
- package/src/runtime/ui/provider-health/data-provider.ts +244 -0
- package/src/runtime/ui/provider-health/fallback-visualizer.ts +71 -0
- package/src/runtime/ui/provider-health/index.ts +46 -0
- package/src/runtime/ui/provider-health/types.ts +146 -0
- package/src/runtime/ui-events.ts +1 -0
- package/src/runtime/ui-read-model-helpers.ts +1 -0
- package/src/runtime/ui-read-models-observability-maintenance.ts +1 -0
- package/src/runtime/ui-read-models-observability-options.ts +1 -0
- package/src/runtime/ui-read-models-observability-remote.ts +1 -0
- package/src/runtime/ui-read-models-observability-security.ts +1 -0
- package/src/runtime/ui-read-models-observability-system.ts +1 -0
- package/src/runtime/ui-read-models-observability.ts +1 -0
- package/src/runtime/ui-read-models.ts +61 -0
- package/src/runtime/ui-service-queries.ts +1 -0
- package/src/runtime/ui-services.ts +190 -0
- package/src/scripts/process-messages.ts +42 -0
- package/src/shell/blocking-input.ts +98 -0
- package/src/shell/service-settings-sync.ts +273 -0
- package/src/shell/ui-openers.ts +352 -0
- package/src/tools/index.ts +1 -0
- package/src/tools/wrfc-agent-guard.ts +49 -0
- package/src/types/grid.ts +48 -0
- package/src/types/sql-js.d.ts +15 -0
- package/src/utils/clipboard.ts +22 -0
- package/src/utils/splash-lines.ts +46 -0
- package/src/utils/terminal-width.ts +185 -0
- package/src/verification/live-verifier.ts +430 -0
- package/src/verification/verification-ledger.ts +242 -0
- package/src/version.ts +17 -0
- package/src/widget/index.ts +2 -0
- package/src/widget/types.ts +9 -0
- package/src/widget/widget.ts +8 -0
- package/src/work-plans/work-plan-store.ts +374 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// CostTrackerPanel — per-session / per-agent / per-plan cost estimates
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
import type { Line } from '../types/grid.ts';
|
|
6
|
+
import { createStyledCell, createEmptyLine } from '../types/grid.ts';
|
|
7
|
+
import { BasePanel } from './base-panel.ts';
|
|
8
|
+
import type { AgentEvent, TurnEvent } from '@/runtime/index.ts';
|
|
9
|
+
import type { UiEventFeed } from '../runtime/ui-events.ts';
|
|
10
|
+
import {
|
|
11
|
+
buildEmptyState,
|
|
12
|
+
buildPanelLine,
|
|
13
|
+
buildStyledPanelLine,
|
|
14
|
+
buildPanelWorkspace,
|
|
15
|
+
resolveScrollablePanelSection,
|
|
16
|
+
DEFAULT_PANEL_PALETTE,
|
|
17
|
+
type PanelWorkspaceSection,
|
|
18
|
+
} from './polish.ts';
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Pricing table (USD per 1M tokens)
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
interface ModelPricing {
|
|
25
|
+
input: number;
|
|
26
|
+
output: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const MODEL_PRICING: Record<string, ModelPricing> = {
|
|
30
|
+
// Free tier
|
|
31
|
+
'openrouter/free': { input: 0, output: 0 },
|
|
32
|
+
|
|
33
|
+
// InceptionLabs
|
|
34
|
+
'mercury-2': { input: 0.50, output: 1.50 },
|
|
35
|
+
'mercury-edit': { input: 0.50, output: 1.50 },
|
|
36
|
+
|
|
37
|
+
// OpenAI
|
|
38
|
+
'gpt-5.4': { input: 5, output: 15 },
|
|
39
|
+
'gpt-5.3-chat-latest': { input: 3, output: 10 },
|
|
40
|
+
'gpt-5-mini': { input: 0.15, output: 0.60 },
|
|
41
|
+
'gpt-5-nano': { input: 0.05, output: 0.20 },
|
|
42
|
+
'gpt-oss-120b': { input: 0, output: 0 },
|
|
43
|
+
|
|
44
|
+
// Anthropic (correct registry IDs)
|
|
45
|
+
'claude-opus-4-6': { input: 15, output: 75 },
|
|
46
|
+
'claude-sonnet-4-6': { input: 3, output: 15 },
|
|
47
|
+
'claude-haiku-4-5': { input: 0.80, output: 4 },
|
|
48
|
+
|
|
49
|
+
// Google
|
|
50
|
+
'gemini-3.1-pro': { input: 1.25, output: 5 },
|
|
51
|
+
'gemini-3-flash': { input: 0.075, output: 0.30 },
|
|
52
|
+
'gemini-3.1-flash-lite': { input: 0.02, output: 0.10 },
|
|
53
|
+
'gemini-2.5-pro': { input: 1.25, output: 5 },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Look up pricing from the model catalog.
|
|
58
|
+
* Returns { input: 0, output: 0 } for free models and unknown models.
|
|
59
|
+
*/
|
|
60
|
+
function getCostFromCatalogForPanel(modelId: string): ModelPricing {
|
|
61
|
+
if (modelId.endsWith(':free')) return { input: 0, output: 0 };
|
|
62
|
+
return { input: 0, output: 0 };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getPricing(modelId: string): ModelPricing {
|
|
66
|
+
// 2. Hardcoded table — exact match
|
|
67
|
+
if (MODEL_PRICING[modelId]) return MODEL_PRICING[modelId]!;
|
|
68
|
+
// 1. OpenRouter :free suffix — treat as free
|
|
69
|
+
if (modelId.endsWith(':free')) return { input: 0, output: 0 };
|
|
70
|
+
// 2. Prefix match (e.g. "openrouter/free:..." or "claude-sonnet-4-6-20..")
|
|
71
|
+
for (const [key, pricing] of Object.entries(MODEL_PRICING)) {
|
|
72
|
+
if (modelId.startsWith(key) || modelId.includes(key)) return pricing;
|
|
73
|
+
}
|
|
74
|
+
// 3. Unknown model — default to free-ish safe fallback
|
|
75
|
+
return getCostFromCatalogForPanel(modelId);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function calcCost(inputTokens: number, outputTokens: number, pricing: ModelPricing): number {
|
|
79
|
+
return (inputTokens * pricing.input + outputTokens * pricing.output) / 1_000_000;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function formatCost(usd: number): string {
|
|
83
|
+
if (usd === 0) return '$0.00';
|
|
84
|
+
if (usd < 0.0001) return '<$0.0001';
|
|
85
|
+
if (usd < 0.01) return `$${usd.toFixed(4)}`;
|
|
86
|
+
return `$${usd.toFixed(3)}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function formatTokens(n: number): string {
|
|
90
|
+
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
|
|
91
|
+
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k`;
|
|
92
|
+
return String(n);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
// Internal types
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
|
|
99
|
+
interface UsageSnapshot {
|
|
100
|
+
input: number;
|
|
101
|
+
output: number;
|
|
102
|
+
cacheRead: number;
|
|
103
|
+
cacheWrite: number;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
interface AgentEntry {
|
|
107
|
+
id: string; // short form, e.g. first 8 chars
|
|
108
|
+
task: string;
|
|
109
|
+
model: string;
|
|
110
|
+
inputTokens: number;
|
|
111
|
+
outputTokens: number;
|
|
112
|
+
cost: number;
|
|
113
|
+
status: 'running' | 'done' | 'failed';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Sparkline history (rolling last N cost-per-turn values)
|
|
117
|
+
const SPARKLINE_BARS = '._-:=+*#';
|
|
118
|
+
const SPARKLINE_LEN = 16;
|
|
119
|
+
|
|
120
|
+
function buildSparkline(history: number[]): string {
|
|
121
|
+
if (history.length === 0) return '';
|
|
122
|
+
const max = Math.max(...history);
|
|
123
|
+
if (max === 0) return '.'.repeat(history.length);
|
|
124
|
+
return history
|
|
125
|
+
.map(v => {
|
|
126
|
+
const idx = Math.round((v / max) * (SPARKLINE_BARS.length - 1));
|
|
127
|
+
return SPARKLINE_BARS[idx] ?? '.';
|
|
128
|
+
})
|
|
129
|
+
.join('');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
// Colour palette
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
const C = {
|
|
137
|
+
header: '#ffffff',
|
|
138
|
+
label: '#aaaaaa',
|
|
139
|
+
value: '#00ff88',
|
|
140
|
+
cost: '#ffdd44',
|
|
141
|
+
alert: '#ff4444',
|
|
142
|
+
dim: '#555555',
|
|
143
|
+
model: '#88aaff',
|
|
144
|
+
running: '#88aaff',
|
|
145
|
+
done: '#00ff88',
|
|
146
|
+
failed: '#ff4444',
|
|
147
|
+
separator: '#333333',
|
|
148
|
+
bg: '',
|
|
149
|
+
} as const;
|
|
150
|
+
|
|
151
|
+
// ---------------------------------------------------------------------------
|
|
152
|
+
// CostTrackerPanel
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
|
|
155
|
+
export class CostTrackerPanel extends BasePanel {
|
|
156
|
+
// Session-level usage (from main orchestrator)
|
|
157
|
+
private sessionUsage: UsageSnapshot = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };
|
|
158
|
+
private sessionModel = 'unknown';
|
|
159
|
+
|
|
160
|
+
// Per-turn cost history for sparkline
|
|
161
|
+
private costHistory: number[] = [];
|
|
162
|
+
private lastSessionCost = 0;
|
|
163
|
+
|
|
164
|
+
// Per-agent tracking (keyed by agent id)
|
|
165
|
+
private agents = new Map<string, AgentEntry>();
|
|
166
|
+
|
|
167
|
+
// Budget alert threshold in USD (0 = disabled)
|
|
168
|
+
private budgetThreshold: number;
|
|
169
|
+
|
|
170
|
+
// Scroll offset for agent list
|
|
171
|
+
private scrollOffset = 0;
|
|
172
|
+
|
|
173
|
+
// Unsubscribe functions
|
|
174
|
+
private unsubs: Array<() => void> = [];
|
|
175
|
+
|
|
176
|
+
// Getter for live orchestrator usage
|
|
177
|
+
private readonly getOrchestratorUsage: () => UsageSnapshot & { model?: string };
|
|
178
|
+
|
|
179
|
+
constructor(
|
|
180
|
+
turnEvents: UiEventFeed<TurnEvent>,
|
|
181
|
+
agentEvents: UiEventFeed<AgentEvent>,
|
|
182
|
+
getOrchestratorUsage: () => UsageSnapshot & { model?: string },
|
|
183
|
+
opts: { budgetThreshold?: number } = {},
|
|
184
|
+
) {
|
|
185
|
+
super('cost', 'Cost', '$', 'monitoring');
|
|
186
|
+
this.getOrchestratorUsage = getOrchestratorUsage;
|
|
187
|
+
this.budgetThreshold = opts.budgetThreshold ?? 0;
|
|
188
|
+
this.attachEvents(turnEvents, agentEvents);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// -------------------------------------------------------------------------
|
|
192
|
+
// Bus wiring
|
|
193
|
+
// -------------------------------------------------------------------------
|
|
194
|
+
|
|
195
|
+
private attachEvents(turnEvents: UiEventFeed<TurnEvent>, agentEvents: UiEventFeed<AgentEvent>): void {
|
|
196
|
+
// Refresh after every completed turn
|
|
197
|
+
this.unsubs.push(
|
|
198
|
+
turnEvents.on('TURN_COMPLETED', () => this.onTurnComplete()),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// Track agent spawns
|
|
202
|
+
this.unsubs.push(
|
|
203
|
+
agentEvents.on('AGENT_SPAWNING', (payload) => {
|
|
204
|
+
this.agents.set(payload.agentId, {
|
|
205
|
+
id: payload.agentId.slice(0, 8),
|
|
206
|
+
task: payload.task.length > 40 ? payload.task.slice(0, 37) + '...' : payload.task,
|
|
207
|
+
model: 'unknown',
|
|
208
|
+
inputTokens: 0,
|
|
209
|
+
outputTokens: 0,
|
|
210
|
+
cost: 0,
|
|
211
|
+
status: 'running',
|
|
212
|
+
});
|
|
213
|
+
this.markDirty();
|
|
214
|
+
}),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
// Agent completed — capture token data from result if available
|
|
218
|
+
this.unsubs.push(
|
|
219
|
+
agentEvents.on('AGENT_COMPLETED', (payload) => {
|
|
220
|
+
const entry = this.agents.get(payload.agentId);
|
|
221
|
+
if (entry) {
|
|
222
|
+
entry.status = 'done';
|
|
223
|
+
this.markDirty();
|
|
224
|
+
}
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
// Agent error
|
|
229
|
+
this.unsubs.push(
|
|
230
|
+
agentEvents.on('AGENT_FAILED', (payload) => {
|
|
231
|
+
const entry = this.agents.get(payload.agentId);
|
|
232
|
+
if (entry) {
|
|
233
|
+
entry.status = 'failed';
|
|
234
|
+
this.markDirty();
|
|
235
|
+
}
|
|
236
|
+
}),
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
private onTurnComplete(): void {
|
|
241
|
+
const usage = this.getOrchestratorUsage();
|
|
242
|
+
this.sessionUsage = {
|
|
243
|
+
input: usage.input,
|
|
244
|
+
output: usage.output,
|
|
245
|
+
cacheRead: usage.cacheRead,
|
|
246
|
+
cacheWrite: usage.cacheWrite,
|
|
247
|
+
};
|
|
248
|
+
if (usage.model) this.sessionModel = usage.model;
|
|
249
|
+
|
|
250
|
+
// Record cost delta for sparkline
|
|
251
|
+
const sessionProvider = this.sessionModel.includes('/') ? this.sessionModel.split('/')[0]! : '';
|
|
252
|
+
const pricing = getPricing(this.sessionModel);
|
|
253
|
+
const totalCost = calcCost(usage.input + usage.cacheRead + usage.cacheWrite, usage.output, pricing);
|
|
254
|
+
const delta = Math.max(0, totalCost - this.lastSessionCost);
|
|
255
|
+
this.lastSessionCost = totalCost;
|
|
256
|
+
this.costHistory.push(delta);
|
|
257
|
+
if (this.costHistory.length > SPARKLINE_LEN) {
|
|
258
|
+
this.costHistory.shift();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.markDirty();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// -------------------------------------------------------------------------
|
|
265
|
+
// Lifecycle
|
|
266
|
+
// -------------------------------------------------------------------------
|
|
267
|
+
|
|
268
|
+
override onActivate(): void {
|
|
269
|
+
// Sync latest usage on activation
|
|
270
|
+
const usage = this.getOrchestratorUsage();
|
|
271
|
+
this.sessionUsage = {
|
|
272
|
+
input: usage.input,
|
|
273
|
+
output: usage.output,
|
|
274
|
+
cacheRead: usage.cacheRead,
|
|
275
|
+
cacheWrite: usage.cacheWrite,
|
|
276
|
+
};
|
|
277
|
+
this.needsRender = true;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
override onDestroy(): void {
|
|
281
|
+
for (const unsub of this.unsubs) unsub();
|
|
282
|
+
this.unsubs = [];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// -------------------------------------------------------------------------
|
|
286
|
+
// Input
|
|
287
|
+
// -------------------------------------------------------------------------
|
|
288
|
+
|
|
289
|
+
handleInput(key: string): boolean {
|
|
290
|
+
switch (key) {
|
|
291
|
+
case 'up': return this.scroll(-1);
|
|
292
|
+
case 'down': return this.scroll(1);
|
|
293
|
+
case 'pageup': return this.scroll(-10);
|
|
294
|
+
case 'pagedown': return this.scroll(10);
|
|
295
|
+
default: return false;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private scroll(delta: number): boolean {
|
|
300
|
+
const prev = this.scrollOffset;
|
|
301
|
+
this.scrollOffset = Math.max(0, this.scrollOffset + delta);
|
|
302
|
+
if (this.scrollOffset !== prev) this.markDirty();
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// -------------------------------------------------------------------------
|
|
307
|
+
// Render
|
|
308
|
+
// -------------------------------------------------------------------------
|
|
309
|
+
|
|
310
|
+
render(width: number, height: number): Line[] {
|
|
311
|
+
if (height <= 0 || width <= 0) return [];
|
|
312
|
+
|
|
313
|
+
const sessionProvider = this.sessionModel.includes('/') ? this.sessionModel.split('/')[0]! : '';
|
|
314
|
+
const pricing = getPricing(this.sessionModel);
|
|
315
|
+
const totalInputTokens = this.sessionUsage.input + this.sessionUsage.cacheRead + this.sessionUsage.cacheWrite;
|
|
316
|
+
const sessionCost = calcCost(this.sessionUsage.input + this.sessionUsage.cacheRead + this.sessionUsage.cacheWrite, this.sessionUsage.output, pricing);
|
|
317
|
+
const overBudget = this.budgetThreshold > 0 && sessionCost > this.budgetThreshold;
|
|
318
|
+
const sparkline = buildSparkline(this.costHistory);
|
|
319
|
+
const costStr = formatCost(sessionCost);
|
|
320
|
+
const costFg = overBudget ? C.alert : C.cost;
|
|
321
|
+
const budgetStr = this.budgetThreshold > 0
|
|
322
|
+
? ` / ${formatCost(this.budgetThreshold)}`
|
|
323
|
+
: '';
|
|
324
|
+
const alertStr = overBudget ? ' ! OVER BUDGET' : '';
|
|
325
|
+
const sessionLines: Line[] = [
|
|
326
|
+
this.renderKeyValue(width, ' Total', `${costStr}${budgetStr}${alertStr}`, costFg),
|
|
327
|
+
];
|
|
328
|
+
if (sparkline.length > 0) sessionLines.push(this.renderLabeledLine(width, ' Trend', sparkline, C.value));
|
|
329
|
+
sessionLines.push(this.renderKeyValue(width, ' Input', formatTokens(this.sessionUsage.input), C.label));
|
|
330
|
+
sessionLines.push(this.renderKeyValue(width, ' Output', formatTokens(this.sessionUsage.output), C.label));
|
|
331
|
+
if (this.sessionUsage.cacheRead > 0 || this.sessionUsage.cacheWrite > 0) {
|
|
332
|
+
sessionLines.push(this.renderKeyValue(width, ' Cache W', formatTokens(this.sessionUsage.cacheWrite), C.dim));
|
|
333
|
+
sessionLines.push(this.renderKeyValue(width, ' Cache R', formatTokens(this.sessionUsage.cacheRead), C.dim));
|
|
334
|
+
}
|
|
335
|
+
sessionLines.push(this.renderKeyValue(width, ' Total T', formatTokens(totalInputTokens + this.sessionUsage.output), C.label));
|
|
336
|
+
sessionLines.push(this.renderKeyValue(width, ' Model', this.sessionModel, C.model));
|
|
337
|
+
|
|
338
|
+
const sections: PanelWorkspaceSection[] = [
|
|
339
|
+
{
|
|
340
|
+
title: 'Session Cost',
|
|
341
|
+
lines: sessionLines,
|
|
342
|
+
},
|
|
343
|
+
];
|
|
344
|
+
|
|
345
|
+
const agentList = Array.from(this.agents.values());
|
|
346
|
+
if (agentList.length > 0) {
|
|
347
|
+
const planCost = agentList.reduce((sum, a) => sum + a.cost, 0);
|
|
348
|
+
const agentRows: Line[] = [
|
|
349
|
+
this.renderKeyValue(width, ' Plan total', formatCost(planCost + sessionCost), C.cost),
|
|
350
|
+
this.renderDivider(width),
|
|
351
|
+
];
|
|
352
|
+
for (const agent of agentList) {
|
|
353
|
+
const statusFg = agent.status === 'running' ? C.running
|
|
354
|
+
: agent.status === 'failed' ? C.failed
|
|
355
|
+
: C.done;
|
|
356
|
+
const statusIcon = agent.status === 'running' ? '…'
|
|
357
|
+
: agent.status === 'failed' ? '✕'
|
|
358
|
+
: '✓';
|
|
359
|
+
|
|
360
|
+
const agentLabel = `${statusIcon} ${agent.id}`;
|
|
361
|
+
const taskText = agent.task;
|
|
362
|
+
agentRows.push(this.renderAgent(width, agentLabel, taskText, statusFg));
|
|
363
|
+
|
|
364
|
+
if (agent.inputTokens > 0 || agent.outputTokens > 0) {
|
|
365
|
+
const tokenInfo = ` in:${formatTokens(agent.inputTokens)} out:${formatTokens(agent.outputTokens)} ${formatCost(agent.cost)}`;
|
|
366
|
+
agentRows.push(this.renderLabeledLine(width, '', tokenInfo, C.dim));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const sessionSection: PanelWorkspaceSection = sections[0]!;
|
|
370
|
+
const agentsSection = resolveScrollablePanelSection(width, height, {
|
|
371
|
+
intro: 'Track per-session and per-agent token spend using model pricing and live usage snapshots.',
|
|
372
|
+
footerLines: [
|
|
373
|
+
buildPanelLine(width, [[' Up/Down', DEFAULT_PANEL_PALETTE.info], [' scroll agents', DEFAULT_PANEL_PALETTE.dim]]),
|
|
374
|
+
],
|
|
375
|
+
palette: DEFAULT_PANEL_PALETTE,
|
|
376
|
+
beforeSections: [sessionSection],
|
|
377
|
+
section: {
|
|
378
|
+
title: 'Agents',
|
|
379
|
+
scrollableLines: agentRows,
|
|
380
|
+
scrollOffset: this.scrollOffset,
|
|
381
|
+
minRows: 4,
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
this.scrollOffset = agentsSection.scrollOffset;
|
|
385
|
+
sections.push(agentsSection.section);
|
|
386
|
+
} else {
|
|
387
|
+
sections.push({
|
|
388
|
+
title: 'Agents',
|
|
389
|
+
lines: buildEmptyState(
|
|
390
|
+
width,
|
|
391
|
+
' No delegated agent cost records',
|
|
392
|
+
'Agent-level cost estimates appear only for explicit delegated build/review session records.',
|
|
393
|
+
[],
|
|
394
|
+
DEFAULT_PANEL_PALETTE,
|
|
395
|
+
),
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
return buildPanelWorkspace(width, height, {
|
|
400
|
+
title: ' Cost Tracker',
|
|
401
|
+
intro: 'Track per-session and per-agent token spend using model pricing and live usage snapshots.',
|
|
402
|
+
sections,
|
|
403
|
+
footerLines: [
|
|
404
|
+
buildPanelLine(width, [[' Up/Down', DEFAULT_PANEL_PALETTE.info], [' scroll agents', DEFAULT_PANEL_PALETTE.dim]]),
|
|
405
|
+
],
|
|
406
|
+
palette: DEFAULT_PANEL_PALETTE,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// -------------------------------------------------------------------------
|
|
411
|
+
// Render helpers
|
|
412
|
+
// -------------------------------------------------------------------------
|
|
413
|
+
|
|
414
|
+
private renderKeyValue(width: number, label: string, value: string, valueFg: string): Line {
|
|
415
|
+
const LABEL_W = 10;
|
|
416
|
+
return buildStyledPanelLine(width, [
|
|
417
|
+
{ text: label.padEnd(LABEL_W).slice(0, LABEL_W), fg: C.label, bg: C.bg },
|
|
418
|
+
{ text: ': ', fg: C.dim, bg: C.bg },
|
|
419
|
+
{ text: value, fg: valueFg, bg: C.bg, bold: true },
|
|
420
|
+
]);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private renderLabeledLine(width: number, label: string, value: string, valueFg: string): Line {
|
|
424
|
+
return buildStyledPanelLine(width, [
|
|
425
|
+
...(label.length > 0 ? [{ text: `${label.slice(0, 10).padEnd(10)} `, fg: C.label }] : []),
|
|
426
|
+
{ text: value, fg: valueFg },
|
|
427
|
+
]);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
private renderAgent(width: number, label: string, task: string, fg: string): Line {
|
|
431
|
+
const LABEL_W = 12;
|
|
432
|
+
const remaining = width - LABEL_W - 1;
|
|
433
|
+
const trimmed = task.length > remaining ? task.slice(0, remaining - 3) + '...' : task;
|
|
434
|
+
return buildStyledPanelLine(width, [
|
|
435
|
+
{ text: `${label.padEnd(LABEL_W).slice(0, LABEL_W)} `, fg, bold: true },
|
|
436
|
+
{ text: trimmed, fg: C.label },
|
|
437
|
+
]);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
private renderDivider(width: number): Line {
|
|
441
|
+
return buildStyledPanelLine(width, [{ text: '─'.repeat(width), fg: C.separator }]);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
}
|