@pellux/goodvibes-agent 1.4.4 → 1.5.1

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.
Files changed (230) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +52 -7
  3. package/dist/package/main.js +7491 -12253
  4. package/docs/README.md +2 -2
  5. package/docs/channels-remote-and-api.md +1 -1
  6. package/docs/getting-started.md +2 -2
  7. package/docs/release-and-publishing.md +1 -1
  8. package/docs/tools-and-commands.md +5 -5
  9. package/package.json +4 -2
  10. package/release/live-verification/live-verification.json +13 -13
  11. package/release/live-verification/live-verification.md +15 -15
  12. package/release/performance-snapshot.json +2 -2
  13. package/release/release-notes.md +5 -7
  14. package/release/release-readiness.json +6 -6
  15. package/src/agent/behavior-discovery-summary.ts +4 -18
  16. package/src/agent/calendar-registry.ts +322 -0
  17. package/src/agent/competitive-feature-inventory.ts +268 -130
  18. package/src/agent/document-registry.ts +5 -1
  19. package/src/agent/email/email-service.ts +350 -0
  20. package/src/agent/email/imap-client.ts +596 -0
  21. package/src/agent/email/smtp-client.ts +453 -0
  22. package/src/agent/ics-calendar.ts +662 -0
  23. package/src/agent/ics-timezone.ts +172 -0
  24. package/src/agent/markdown-frontmatter.ts +31 -0
  25. package/src/agent/memory-safety.ts +1 -1
  26. package/src/agent/note-registry.ts +3 -9
  27. package/src/agent/persona-discovery.ts +3 -15
  28. package/src/agent/persona-registry.ts +1 -10
  29. package/src/agent/research-source-registry.ts +5 -1
  30. package/src/agent/routine-discovery.ts +3 -15
  31. package/src/agent/runtime-profile.ts +3 -0
  32. package/src/agent/skill-discovery.ts +3 -15
  33. package/src/agent/skill-draft-proposer.ts +203 -0
  34. package/src/agent/skill-draft-runner.ts +201 -0
  35. package/src/agent/skill-registry.ts +36 -1
  36. package/src/agent/skill-standard.ts +99 -0
  37. package/src/agent/vibe-file.ts +7 -22
  38. package/src/cli/completion.ts +1 -1
  39. package/src/cli/config-overrides.ts +10 -1
  40. package/src/cli/redaction.ts +17 -5
  41. package/src/config/provider-model.ts +2 -1
  42. package/src/config/secret-config.ts +13 -6
  43. package/src/core/activity-feed.ts +97 -0
  44. package/src/core/away-digest.ts +161 -0
  45. package/src/core/conversation-rendering.ts +7 -3
  46. package/src/core/conversation.ts +22 -15
  47. package/src/core/hardware-profile.ts +362 -0
  48. package/src/core/last-seen-store.ts +78 -0
  49. package/src/core/plain-language.ts +52 -0
  50. package/src/core/setup-incomplete-hint.ts +90 -0
  51. package/src/core/system-message-router.ts +38 -87
  52. package/src/input/agent-workspace-basic-command-editor-submission.ts +60 -220
  53. package/src/input/agent-workspace-basic-command-editors.ts +39 -141
  54. package/src/input/agent-workspace-categories.ts +40 -125
  55. package/src/input/agent-workspace-command-editor.ts +4 -0
  56. package/src/input/agent-workspace-host-category.ts +0 -5
  57. package/src/input/agent-workspace-local-editor-submission.ts +3 -1
  58. package/src/input/agent-workspace-navigation.ts +10 -3
  59. package/src/input/agent-workspace-onboarding-actions.ts +132 -0
  60. package/src/input/agent-workspace-onboarding-categories.ts +29 -26
  61. package/src/input/agent-workspace-onboarding-finish.ts +11 -4
  62. package/src/input/agent-workspace-onboarding-state.ts +111 -0
  63. package/src/input/agent-workspace-profile-editor-submission.ts +260 -0
  64. package/src/input/agent-workspace-profile-editors.ts +155 -0
  65. package/src/input/agent-workspace-subscription-editor.ts +7 -0
  66. package/src/input/agent-workspace-types.ts +5 -1
  67. package/src/input/agent-workspace.ts +65 -39
  68. package/src/input/command-registry.ts +18 -5
  69. package/src/input/commands/agent-runtime-profile-runtime.ts +2 -1
  70. package/src/input/commands/agent-skills-runtime.ts +60 -3
  71. package/src/input/commands/calendar-runtime.ts +209 -0
  72. package/src/input/commands/channels-runtime.ts +1 -0
  73. package/src/input/commands/command-error.ts +9 -0
  74. package/src/input/commands/compat-runtime.ts +1 -0
  75. package/src/input/commands/config.ts +1 -0
  76. package/src/input/commands/conversation-runtime.ts +1 -1
  77. package/src/input/commands/delegation-runtime.ts +5 -6
  78. package/src/input/commands/email-runtime.ts +387 -0
  79. package/src/input/commands/experience-runtime.ts +17 -4
  80. package/src/input/commands/guidance-runtime.ts +1 -1
  81. package/src/input/commands/health-runtime.ts +6 -1
  82. package/src/input/commands/knowledge-format.ts +73 -0
  83. package/src/input/commands/knowledge.ts +9 -74
  84. package/src/input/commands/local-provider-runtime.ts +2 -1
  85. package/src/input/commands/local-runtime.ts +10 -4
  86. package/src/input/commands/mcp-runtime.ts +7 -0
  87. package/src/input/commands/notify-runtime.ts +17 -1
  88. package/src/input/commands/onboarding-runtime.ts +1 -0
  89. package/src/input/commands/operator-actions-runtime.ts +1 -0
  90. package/src/input/commands/operator-runtime.ts +3 -0
  91. package/src/input/commands/personas-runtime.ts +1 -0
  92. package/src/input/commands/platform-access-runtime.ts +40 -17
  93. package/src/input/commands/product-runtime.ts +6 -1
  94. package/src/input/commands/provider-accounts-runtime.ts +3 -2
  95. package/src/input/commands/qrcode-runtime.ts +1 -0
  96. package/src/input/commands/routines-runtime.ts +1 -0
  97. package/src/input/commands/runtime-services.ts +0 -13
  98. package/src/input/commands/security-runtime.ts +1 -0
  99. package/src/input/commands/session-content.ts +1 -0
  100. package/src/input/commands/shell-core.ts +5 -2
  101. package/src/input/commands/subscription-runtime.ts +33 -9
  102. package/src/input/commands/support-bundle-runtime.ts +8 -1
  103. package/src/input/commands/tasks-runtime.ts +1 -0
  104. package/src/input/commands/tts-runtime.ts +1 -0
  105. package/src/input/commands/vibe-runtime.ts +1 -0
  106. package/src/input/commands.ts +4 -0
  107. package/src/input/feed-context-factory.ts +3 -12
  108. package/src/input/handler-command-route.ts +7 -60
  109. package/src/input/handler-feed-routes.ts +0 -194
  110. package/src/input/handler-feed.ts +2 -54
  111. package/src/input/handler-interactions.ts +0 -2
  112. package/src/input/handler-modal-stack.ts +0 -9
  113. package/src/input/handler-picker-routes.ts +24 -1
  114. package/src/input/handler-shortcuts.ts +11 -40
  115. package/src/input/handler-ui-state.ts +13 -0
  116. package/src/input/handler.ts +8 -35
  117. package/src/input/keybindings.ts +40 -17
  118. package/src/input/model-picker-local-fit.ts +130 -0
  119. package/src/input/shell-passthrough.ts +58 -0
  120. package/src/input/submission-router.ts +0 -5
  121. package/src/main.ts +129 -90
  122. package/src/renderer/activity-sidebar.ts +186 -0
  123. package/src/renderer/agent-workspace-context-lines.ts +5 -48
  124. package/src/renderer/agent-workspace-style.ts +1 -1
  125. package/src/renderer/agent-workspace.ts +14 -2
  126. package/src/renderer/compositor.ts +37 -125
  127. package/src/renderer/conversation-overlays.ts +3 -3
  128. package/src/renderer/help-overlay.ts +7 -5
  129. package/src/renderer/model-workspace.ts +101 -86
  130. package/src/{panels → renderer}/polish.ts +3 -3
  131. package/src/renderer/shell-surface.ts +4 -5
  132. package/src/renderer/status-token.ts +31 -11
  133. package/src/renderer/tab-strip.ts +1 -1
  134. package/src/renderer/tool-call.ts +7 -8
  135. package/src/renderer/tool-labels.ts +92 -0
  136. package/src/renderer/ui-factory.ts +48 -96
  137. package/src/runtime/bootstrap-command-context.ts +0 -5
  138. package/src/runtime/bootstrap-command-parts.ts +6 -15
  139. package/src/runtime/bootstrap-core.ts +34 -13
  140. package/src/runtime/bootstrap-hook-bridge.ts +3 -1
  141. package/src/runtime/bootstrap-shell.ts +3 -50
  142. package/src/runtime/bootstrap.ts +3 -4
  143. package/src/runtime/context.ts +1 -1
  144. package/src/runtime/diagnostics/panels/index.ts +0 -1
  145. package/src/runtime/diagnostics/panels/policy.ts +1 -1
  146. package/src/runtime/execution-ledger.ts +16 -1
  147. package/src/runtime/index.ts +6 -1
  148. package/src/runtime/onboarding/index.ts +1 -0
  149. package/src/runtime/onboarding/onboarding-state.ts +200 -0
  150. package/src/{panels → runtime}/provider-account-snapshot.ts +5 -2
  151. package/src/runtime/services.ts +16 -4
  152. package/src/runtime/terminal-output-guard.ts +7 -0
  153. package/src/runtime/tool-permission-safety.ts +1 -1
  154. package/src/runtime/ui/model-picker/data-provider.ts +1 -1
  155. package/src/runtime/ui/model-picker/health-enrichment.ts +2 -2
  156. package/src/runtime/ui/model-picker/types.ts +2 -2
  157. package/src/runtime/ui/provider-health/data-provider.ts +3 -3
  158. package/src/runtime/ui/provider-health/types.ts +2 -2
  159. package/src/runtime/ui-services.ts +0 -2
  160. package/src/shell/agent-workspace-fullscreen.ts +0 -1
  161. package/src/shell/autonomy-surfacing.ts +272 -0
  162. package/src/shell/session-continuity-hints.ts +0 -6
  163. package/src/shell/startup-wiring.ts +221 -0
  164. package/src/shell/ui-openers.ts +18 -29
  165. package/src/tools/agent-context-policy.ts +1 -1
  166. package/src/tools/agent-harness-background-processes.ts +4 -4
  167. package/src/tools/agent-harness-browser-cockpit-route.ts +3 -3
  168. package/src/tools/agent-harness-command-runner.ts +6 -1
  169. package/src/tools/agent-harness-document-ops.ts +26 -53
  170. package/src/tools/agent-harness-execution-history.ts +1 -13
  171. package/src/tools/agent-harness-execution-posture.ts +0 -15
  172. package/src/tools/agent-harness-keybinding-metadata.ts +28 -29
  173. package/src/tools/agent-harness-local-model-cookbook.ts +24 -1
  174. package/src/tools/agent-harness-metadata.ts +16 -0
  175. package/src/tools/agent-harness-mode-catalog.ts +2 -9
  176. package/src/tools/agent-harness-provider-account-metadata.ts +2 -2
  177. package/src/tools/agent-harness-setup-posture-utils.ts +1 -1
  178. package/src/tools/agent-harness-tool-schema.ts +13 -14
  179. package/src/tools/agent-harness-tool.ts +27 -23
  180. package/src/tools/agent-harness-ui-surface-metadata.ts +10 -20
  181. package/src/tools/agent-harness-workspace-action-runner.ts +3 -4
  182. package/src/tools/agent-workspace-tool.ts +2 -33
  183. package/src/utils/terminal-width.ts +9 -3
  184. package/src/version.ts +1 -1
  185. package/src/input/agent-workspace-panel-route.ts +0 -44
  186. package/src/input/panel-integration-actions.ts +0 -26
  187. package/src/panels/approval-panel.ts +0 -149
  188. package/src/panels/automation-control-panel.ts +0 -212
  189. package/src/panels/base-panel.ts +0 -254
  190. package/src/panels/builtin/agent.ts +0 -58
  191. package/src/panels/builtin/knowledge.ts +0 -26
  192. package/src/panels/builtin/operations.ts +0 -121
  193. package/src/panels/builtin/session.ts +0 -138
  194. package/src/panels/builtin/shared.ts +0 -275
  195. package/src/panels/builtin/usage.ts +0 -21
  196. package/src/panels/builtin-panels.ts +0 -23
  197. package/src/panels/confirm-state.ts +0 -61
  198. package/src/panels/context-visualizer-panel.ts +0 -204
  199. package/src/panels/cost-tracker-panel.ts +0 -444
  200. package/src/panels/docs-panel.ts +0 -285
  201. package/src/panels/index.ts +0 -25
  202. package/src/panels/knowledge-panel.ts +0 -417
  203. package/src/panels/memory-panel.ts +0 -226
  204. package/src/panels/panel-list-panel.ts +0 -464
  205. package/src/panels/panel-manager.ts +0 -570
  206. package/src/panels/provider-accounts-panel.ts +0 -233
  207. package/src/panels/provider-health-domains.ts +0 -208
  208. package/src/panels/provider-health-panel.ts +0 -720
  209. package/src/panels/provider-health-tracker.ts +0 -115
  210. package/src/panels/provider-stats-panel.ts +0 -366
  211. package/src/panels/qr-panel.ts +0 -207
  212. package/src/panels/schedule-panel.ts +0 -321
  213. package/src/panels/scrollable-list-panel.ts +0 -491
  214. package/src/panels/search-focus.ts +0 -32
  215. package/src/panels/security-panel.ts +0 -295
  216. package/src/panels/session-browser-panel.ts +0 -395
  217. package/src/panels/session-maintenance.ts +0 -125
  218. package/src/panels/subscription-panel.ts +0 -263
  219. package/src/panels/system-messages-panel.ts +0 -230
  220. package/src/panels/tasks-panel.ts +0 -344
  221. package/src/panels/thinking-panel.ts +0 -304
  222. package/src/panels/token-budget-panel.ts +0 -475
  223. package/src/panels/tool-inspector-panel.ts +0 -436
  224. package/src/panels/types.ts +0 -54
  225. package/src/renderer/panel-composite.ts +0 -158
  226. package/src/renderer/panel-tab-bar.ts +0 -69
  227. package/src/renderer/panel-workspace-bar.ts +0 -42
  228. package/src/runtime/diagnostics/panels/panel-resources.ts +0 -118
  229. package/src/tools/agent-harness-panel-metadata.ts +0 -211
  230. /package/src/runtime/perf/{panel-health-monitor.ts → component-health.ts} +0 -0
@@ -1,115 +0,0 @@
1
- export type ProviderStatus = 'online' | 'rate-limited' | 'error' | 'unknown';
2
-
3
- export interface ProviderHealth {
4
- name: string;
5
- status: ProviderStatus;
6
- lastLatencyMs?: number;
7
- lastErrorMessage?: string;
8
- lastSuccessAt?: number;
9
- lastErrorAt?: number;
10
- rateLimitExpiresAt: number;
11
- }
12
-
13
- /**
14
- * Tracks provider request posture from shell-facing turn and provider events.
15
- * The panel owns event subscriptions and feeds those events into this tracker.
16
- */
17
- export class ProviderHealthTracker {
18
- private records = new Map<string, ProviderHealth>();
19
- private streamStartMs: number | null = null;
20
- private turnStartMs: number | null = null;
21
-
22
- private static readonly DEFAULT_COOLDOWN_MS = 60_000;
23
-
24
- onTurnStart(): void {
25
- this.turnStartMs = Date.now();
26
- }
27
-
28
- onStreamStart(): void {
29
- this.streamStartMs = Date.now();
30
- }
31
-
32
- onLlmResponse(providerName: string): void {
33
- const now = Date.now();
34
- const latencyMs =
35
- this.streamStartMs !== null
36
- ? now - this.streamStartMs
37
- : this.turnStartMs !== null
38
- ? now - this.turnStartMs
39
- : undefined;
40
- this.streamStartMs = null;
41
-
42
- this.recordSuccess(providerName, latencyMs);
43
- }
44
-
45
- onTurnError(error: string, providerName = 'unknown'): void {
46
- this.streamStartMs = null;
47
- this.turnStartMs = null;
48
- const isRateLimit = this.isRateLimitMessage(error);
49
-
50
- this.recordError(providerName, error, isRateLimit);
51
- }
52
-
53
- onProvidersChanged(providerIds: readonly string[]): void {
54
- try {
55
- for (const providerId of providerIds) {
56
- if (!this.records.has(providerId)) {
57
- this.ensureRecord(providerId);
58
- }
59
- }
60
- } catch {
61
- // Ignore provider catalog churn while the shell is refreshing.
62
- }
63
- }
64
-
65
- getAll(): ProviderHealth[] {
66
- return [...this.records.values()];
67
- }
68
-
69
- get(name: string): ProviderHealth | undefined {
70
- return this.records.get(name);
71
- }
72
-
73
- private ensureRecord(name: string): ProviderHealth {
74
- let record = this.records.get(name);
75
- if (!record) {
76
- record = { name, status: 'unknown', rateLimitExpiresAt: 0 };
77
- this.records.set(name, record);
78
- }
79
- return record;
80
- }
81
-
82
- private recordSuccess(name: string, latencyMs?: number): void {
83
- const record = this.ensureRecord(name);
84
- record.status = 'online';
85
- record.lastSuccessAt = Date.now();
86
- record.lastErrorMessage = undefined;
87
- if (latencyMs !== undefined) {
88
- record.lastLatencyMs = latencyMs;
89
- }
90
- if (record.rateLimitExpiresAt > 0 && record.rateLimitExpiresAt <= Date.now()) {
91
- record.rateLimitExpiresAt = 0;
92
- }
93
- }
94
-
95
- private recordError(name: string, message: string, isRateLimit: boolean): void {
96
- const record = this.ensureRecord(name);
97
- record.lastErrorAt = Date.now();
98
- record.lastErrorMessage = message.slice(0, 120);
99
- if (isRateLimit) {
100
- record.status = 'rate-limited';
101
- record.rateLimitExpiresAt = Date.now() + ProviderHealthTracker.DEFAULT_COOLDOWN_MS;
102
- return;
103
- }
104
- record.status = 'error';
105
- }
106
-
107
- private isRateLimitMessage(message: string): boolean {
108
- const lower = message.toLowerCase();
109
- return (
110
- lower.includes('429')
111
- || lower.includes('402')
112
- || /rate.limit|too many requests|quota exceeded|throttl|depleted|credits/.test(lower)
113
- );
114
- }
115
- }
@@ -1,366 +0,0 @@
1
- import { BasePanel } from './base-panel.ts';
2
- import type { Line } from '../types/grid.ts';
3
- import type { ProviderEvent, TurnEvent } from '@/runtime/index.ts';
4
- import type { UiEventFeed } from '../runtime/ui-events.ts';
5
- import type { UiProvidersSnapshot, UiReadModel } from '../runtime/ui-read-models.ts';
6
- import {
7
- buildEmptyState,
8
- buildKeyValueLine,
9
- buildStyledPanelLine,
10
- buildPanelWorkspace,
11
- DEFAULT_PANEL_PALETTE,
12
- type PanelWorkspaceSection,
13
- } from './polish.ts';
14
- import { truncateDisplay } from '../utils/terminal-width.ts';
15
-
16
- // ---------------------------------------------------------------------------
17
- // Constants
18
- // ---------------------------------------------------------------------------
19
-
20
- const SPARKLINE_CHARS = '._-:=+*#';
21
- const LATENCY_RING_SIZE = 20;
22
-
23
- /** Latency thresholds in ms for color-coding. */
24
- const LATENCY_GREEN = 500;
25
- const LATENCY_YELLOW = 2000;
26
-
27
- // ---------------------------------------------------------------------------
28
- // Types
29
- // ---------------------------------------------------------------------------
30
-
31
- interface ProviderRecord {
32
- /** Provider name (e.g. 'anthropic', 'openai'). */
33
- name: string;
34
- /** Currently active model ID for this provider (last seen). */
35
- lastModelId: string;
36
- /** Ring buffer of per-request latencies in ms (most-recent last). */
37
- latencies: number[];
38
- /** Total request count. */
39
- requests: number;
40
- /** Error count. */
41
- errors: number;
42
- /** Total input + output tokens summed across all requests. */
43
- totalTokens: number;
44
- }
45
-
46
- // ---------------------------------------------------------------------------
47
- // ProviderStatsPanel
48
- // ---------------------------------------------------------------------------
49
-
50
- export class ProviderStatsPanel extends BasePanel {
51
- /** Per-provider metrics keyed by provider name. */
52
- private records: Map<string, ProviderRecord> = new Map();
53
-
54
- /** Timestamp (ms) recorded at turn:start — used to compute turn latency. */
55
- private _turnStartMs: number | null = null;
56
-
57
- /** Timestamp for the current streaming LLM call start. */
58
- private _streamStartMs: number | null = null;
59
-
60
- /** Unsubscribe functions for event listeners. */
61
- private _unsubs: Array<() => void> = [];
62
-
63
- constructor(
64
- private readonly turnEvents: UiEventFeed<TurnEvent>,
65
- private readonly providerEvents: UiEventFeed<ProviderEvent>,
66
- private readonly requestRender: () => void = () => {},
67
- private readonly providers: UiReadModel<UiProvidersSnapshot>,
68
- ) {
69
- super('providers', 'Providers', 'R', 'monitoring');
70
- this._subscribe();
71
- }
72
-
73
- // -------------------------------------------------------------------------
74
- // Event subscription
75
- // -------------------------------------------------------------------------
76
-
77
- private _subscribe(): void {
78
- // Record when a turn starts so we can compute latency later
79
- this._unsubs.push(
80
- this.turnEvents.on('TURN_SUBMITTED', () => {
81
- this._turnStartMs = Date.now();
82
- }),
83
- );
84
-
85
- // Per-streaming-call timing (each iteration of the agentic loop)
86
- this._unsubs.push(
87
- this.turnEvents.on('STREAM_START', () => {
88
- this._streamStartMs = Date.now();
89
- }),
90
- );
91
-
92
- // After each LLM response (streamed or not), record metrics for the
93
- // current provider call inside the turn loop.
94
- this._unsubs.push(
95
- this.turnEvents.on('LLM_RESPONSE_RECEIVED', (env) => {
96
- const now = Date.now();
97
- const latencyMs = this._streamStartMs !== null
98
- ? now - this._streamStartMs
99
- : this._turnStartMs !== null
100
- ? now - this._turnStartMs
101
- : 0;
102
- // Reset stream start — ready for next iteration in the agentic loop
103
- this._streamStartMs = null;
104
- this._recordRequest(
105
- env.provider,
106
- env.model,
107
- latencyMs,
108
- false,
109
- env.inputTokens
110
- + env.outputTokens
111
- + (env.cacheReadTokens ?? 0)
112
- + (env.cacheWriteTokens ?? 0),
113
- );
114
-
115
- this.markDirty();
116
- this.requestRender();
117
- }),
118
- );
119
-
120
- // On error, record a failed request
121
- this._unsubs.push(
122
- this.turnEvents.on('TURN_ERROR', () => {
123
- this._turnStartMs = null;
124
- this._streamStartMs = null;
125
- this._recordRequest('unknown', 'unknown', 0, true, 0);
126
-
127
- this.markDirty();
128
- this.requestRender();
129
- }),
130
- );
131
-
132
- // Re-render when providers change (new custom providers loaded)
133
- this._unsubs.push(
134
- this.providerEvents.on('PROVIDERS_CHANGED', () => {
135
- this.markDirty();
136
- this.requestRender();
137
- }),
138
- );
139
- }
140
-
141
- // -------------------------------------------------------------------------
142
- // Metric recording
143
- // -------------------------------------------------------------------------
144
-
145
- private _recordRequest(
146
- providerName: string,
147
- modelId: string,
148
- latencyMs: number,
149
- isError: boolean,
150
- tokens: number,
151
- ): void {
152
- let rec = this.records.get(providerName);
153
- if (!rec) {
154
- rec = {
155
- name: providerName,
156
- lastModelId: modelId,
157
- latencies: [],
158
- requests: 0,
159
- errors: 0,
160
- totalTokens: 0,
161
- };
162
- this.records.set(providerName, rec);
163
- }
164
-
165
- rec.lastModelId = modelId;
166
- rec.requests++;
167
- if (isError) rec.errors++;
168
- rec.totalTokens += tokens;
169
-
170
- if (latencyMs > 0) {
171
- rec.latencies.push(latencyMs);
172
- // Keep only the most recent LATENCY_RING_SIZE samples
173
- if (rec.latencies.length > LATENCY_RING_SIZE) {
174
- rec.latencies.shift();
175
- }
176
- }
177
- }
178
-
179
- // -------------------------------------------------------------------------
180
- // Lifecycle
181
- // -------------------------------------------------------------------------
182
-
183
- override onDestroy(): void {
184
- for (const unsub of this._unsubs) unsub();
185
- this._unsubs = [];
186
- }
187
-
188
- // -------------------------------------------------------------------------
189
- // Rendering
190
- // -------------------------------------------------------------------------
191
-
192
- override render(width: number, height: number): Line[] {
193
- const knownProviders = [...this.providers.getSnapshot().providerIds];
194
-
195
- if (knownProviders.length === 0) {
196
- return buildPanelWorkspace(width, height, {
197
- title: ' Provider Stats',
198
- intro: 'Per-provider request performance, latency distribution, error pressure, and session totals.',
199
- sections: [
200
- {
201
- lines: buildEmptyState(
202
- width,
203
- ' No providers registered',
204
- 'Load or configure a provider to begin collecting per-provider latency and error metrics.',
205
- [],
206
- DEFAULT_PANEL_PALETTE,
207
- ),
208
- },
209
- ],
210
- palette: DEFAULT_PANEL_PALETTE,
211
- });
212
- }
213
-
214
- const totalReq = [...this.records.values()].reduce((sum, rec) => sum + rec.requests, 0);
215
- const totalErr = [...this.records.values()].reduce((sum, rec) => sum + rec.errors, 0);
216
- const totalTok = [...this.records.values()].reduce((sum, rec) => sum + rec.totalTokens, 0);
217
- const allLatencies = [...this.records.values()].flatMap((rec) => rec.latencies);
218
- const providerSections: PanelWorkspaceSection[] = [
219
- {
220
- title: 'Session',
221
- lines: [
222
- buildKeyValueLine(width, [
223
- { label: 'Providers', value: String(knownProviders.length) },
224
- { label: 'Requests', value: String(totalReq), valueColor: DEFAULT_PANEL_PALETTE.info },
225
- { label: 'Errors', value: String(totalErr), valueColor: totalErr > 0 ? DEFAULT_PANEL_PALETTE.bad : DEFAULT_PANEL_PALETTE.good },
226
- { label: 'Tokens', value: String(totalTok), valueColor: DEFAULT_PANEL_PALETTE.value },
227
- ], DEFAULT_PANEL_PALETTE),
228
- buildKeyValueLine(width, [
229
- { label: 'Avg Latency', value: this._fmtMs(this._avg(allLatencies)), valueColor: this._latencyColor(this._avg(allLatencies)) },
230
- { label: 'P95', value: this._fmtMs(this._p95(allLatencies)), valueColor: DEFAULT_PANEL_PALETTE.warn },
231
- ], DEFAULT_PANEL_PALETTE),
232
- ],
233
- },
234
- ];
235
-
236
- for (const provName of knownProviders) {
237
- const rec = this.records.get(provName);
238
- providerSections.push({
239
- title: provName,
240
- lines: this._buildProviderRows(provName, rec, width),
241
- });
242
- }
243
-
244
- return buildPanelWorkspace(width, height, {
245
- title: ' Provider Stats',
246
- intro: 'Per-provider request performance, latency distribution, error pressure, and session totals.',
247
- sections: providerSections,
248
- palette: DEFAULT_PANEL_PALETTE,
249
- });
250
- }
251
-
252
- // -------------------------------------------------------------------------
253
- // Line builders
254
- // -------------------------------------------------------------------------
255
-
256
- private _buildProviderRows(
257
- provName: string,
258
- rec: ProviderRecord | undefined,
259
- width: number,
260
- ): Line[] {
261
- const rows: Line[] = [];
262
-
263
- // Determine health
264
- const hasErrors = rec !== undefined && rec.errors > 0;
265
- const dotColor = hasErrors ? '#ef4444' : '#22c55e';
266
-
267
- // Model ID (truncated)
268
- const modelId = rec?.lastModelId ?? 'n/a';
269
- const modelDisplay = truncateDisplay(modelId, 30);
270
-
271
- // Header row: * provider model
272
- // Build as segments to avoid multi-byte char indexing issues
273
- const headerLine = buildStyledPanelLine(width, [
274
- { text: ' ', fg: '#94a3b8' },
275
- { text: '●', fg: dotColor },
276
- { text: ' ', fg: '#94a3b8' },
277
- { text: `${truncateDisplay(provName, 14).padEnd(14)} `, fg: '#e2e8f0', bold: true },
278
- { text: modelDisplay, fg: '#cbd5e1' },
279
- ]);
280
-
281
- rows.push(headerLine);
282
-
283
- if (rec === undefined || rec.requests === 0) {
284
- rows.push(buildStyledPanelLine(width, [
285
- { text: ' No requests yet.', fg: '#6b7280' },
286
- ]));
287
- } else {
288
- const avgLatency = this._avg(rec.latencies);
289
- const p95Latency = this._p95(rec.latencies);
290
- const errRate = rec.requests > 0 ? (rec.errors / rec.requests) * 100 : 0;
291
- const sparkline = this._sparkline(rec.latencies);
292
-
293
- const latFg = avgLatency < LATENCY_GREEN
294
- ? '#22c55e'
295
- : avgLatency < LATENCY_YELLOW
296
- ? '#eab308'
297
- : '#ef4444';
298
-
299
- const segments = [
300
- { text: ' avg ', fg: '#6b7280' },
301
- { text: this._fmtMs(avgLatency).padStart(6), fg: latFg, bold: true },
302
- { text: ' p95 ', fg: '#6b7280' },
303
- { text: this._fmtMs(p95Latency).padStart(6), fg: '#a78bfa' },
304
- { text: ' ', fg: '#374151' },
305
- { text: sparkline, fg: latFg },
306
- { text: ' err ', fg: '#6b7280' },
307
- { text: `${errRate.toFixed(0).padStart(3)}%`, fg: errRate > 0 ? '#ef4444' : '#22c55e' },
308
- { text: ` ${rec.requests.toString().padStart(4)}r`, fg: '#94a3b8' },
309
- ] as const;
310
- const tokenSegment = rec.totalTokens > 0
311
- ? [{ text: ` ${rec.totalTokens.toString().padStart(6)}tok`, fg: '#64748b' }]
312
- : [];
313
- rows.push(buildStyledPanelLine(width, [...segments, ...tokenSegment]));
314
- }
315
-
316
- return rows;
317
- }
318
-
319
- // -------------------------------------------------------------------------
320
- // Utilities
321
- // -------------------------------------------------------------------------
322
-
323
- private _avg(arr: number[]): number {
324
- if (arr.length === 0) return 0;
325
- return arr.reduce((s, v) => s + v, 0) / arr.length;
326
- }
327
-
328
- private _p95(arr: number[]): number {
329
- if (arr.length === 0) return 0;
330
- const sorted = [...arr].sort((a, b) => a - b);
331
- const idx = Math.floor(sorted.length * 0.95);
332
- return sorted[Math.min(idx, sorted.length - 1)] ?? 0;
333
- }
334
-
335
- private _sparkline(latencies: number[]): string {
336
- if (latencies.length === 0) return ' '.repeat(LATENCY_RING_SIZE);
337
- const vals = latencies.slice(-LATENCY_RING_SIZE);
338
- const minV = Math.min(...vals);
339
- const maxV = Math.max(...vals);
340
- const range = maxV - minV || 1;
341
- const spark: string[] = vals.map((v) => {
342
- const idx = Math.min(
343
- SPARKLINE_CHARS.length - 1,
344
- Math.floor(((v - minV) / range) * (SPARKLINE_CHARS.length - 1)),
345
- );
346
- return SPARKLINE_CHARS[idx] ?? '.';
347
- });
348
- // Pad left to always be LATENCY_RING_SIZE wide
349
- while (spark.length < LATENCY_RING_SIZE) spark.unshift(' ');
350
- return spark.join('');
351
- }
352
-
353
- private _fmtMs(ms: number): string {
354
- if (ms <= 0) return 'n/a';
355
- if (ms >= 10000) return `${(ms / 1000).toFixed(1)}s`;
356
- if (ms >= 1000) return `${(ms / 1000).toFixed(2)}s`;
357
- return `${Math.round(ms)}ms`;
358
- }
359
-
360
- private _latencyColor(ms: number): string {
361
- if (ms <= 0) return DEFAULT_PANEL_PALETTE.dim;
362
- if (ms < LATENCY_GREEN) return DEFAULT_PANEL_PALETTE.good;
363
- if (ms < LATENCY_YELLOW) return DEFAULT_PANEL_PALETTE.warn;
364
- return DEFAULT_PANEL_PALETTE.bad;
365
- }
366
- }
@@ -1,207 +0,0 @@
1
- import type { Line } from '../types/grid.ts';
2
- import { createEmptyLine } from '../types/grid.ts';
3
- import { BasePanel } from './base-panel.ts';
4
- import {
5
- buildPanelLine,
6
- DEFAULT_PANEL_PALETTE,
7
- } from './polish.ts';
8
- import { renderQrMatrix, generateQrMatrix } from '../renderer/qr-renderer.ts';
9
- import { encodeConnectionPayload } from '@pellux/goodvibes-sdk/platform/pairing';
10
- import { GOODVIBES_AGENT_PAIRING_SURFACE } from '../config/surface.ts';
11
-
12
- const C = {
13
- ...DEFAULT_PANEL_PALETTE,
14
- url: '#38bdf8',
15
- token: '#a78bfa',
16
- hint: '#64748b',
17
- qrFg: '#000000',
18
- qrBg: '#ffffff',
19
- } as const;
20
-
21
- /**
22
- * Connection info passed to the QR panel.
23
- * Populated at construction; updated when the token is regenerated.
24
- */
25
- export interface QrPanelConnectionInfo {
26
- /** Full connection URL (e.g. http://192.168.1.x:3141) */
27
- readonly url: string;
28
- /** Auth token */
29
- readonly token: string;
30
- /** Username associated with the companion session */
31
- readonly username: string;
32
- /** Bootstrap password for companion authentication */
33
- readonly password?: string;
34
- /** Pairing payload version (defaults to '0.0.0' if omitted) */
35
- readonly version?: string;
36
- /** Surface identifier (defaults to GoodVibes Agent if omitted) */
37
- readonly surface?: string;
38
- }
39
-
40
- /**
41
- * Callback used by the panel to regenerate the companion token.
42
- * Returns updated connection info.
43
- */
44
- export type RegenerateTokenFn = () => QrPanelConnectionInfo;
45
-
46
- /**
47
- * Callback used by the panel to copy text to the clipboard.
48
- */
49
- export type CopyToClipboardFn = (text: string) => void;
50
-
51
- /**
52
- * QrPanel - displays a QR code for companion app pairing.
53
- *
54
- * Shows connection URL, truncated token, and username above the QR code.
55
- * Supports `r` to regenerate the token and `c` to copy the token.
56
- *
57
- * QR matrix generation uses `generateQrMatrix` via `encodeConnectionPayload`.
58
- */
59
- export class QrPanel extends BasePanel {
60
- private connectionInfo: QrPanelConnectionInfo;
61
- private readonly regenerateToken: RegenerateTokenFn | undefined;
62
- private readonly copyToClipboard: CopyToClipboardFn | undefined;
63
- private lastStatus = '';
64
-
65
- public constructor(
66
- connectionInfo: QrPanelConnectionInfo,
67
- regenerateToken?: RegenerateTokenFn,
68
- copyToClipboard?: CopyToClipboardFn,
69
- ) {
70
- super('qr-code', 'QR Code', 'Q', 'session');
71
- this.connectionInfo = connectionInfo;
72
- this.regenerateToken = regenerateToken;
73
- this.copyToClipboard = copyToClipboard;
74
- }
75
-
76
- public handleInput(key: string): boolean {
77
- if (key === 'r') {
78
- if (this.regenerateToken) {
79
- this.connectionInfo = this.regenerateToken();
80
- this.lastStatus = 'Token regenerated.';
81
- } else {
82
- this.lastStatus = 'Token rotation belongs to the connected host.';
83
- }
84
- this.markDirty();
85
- return true;
86
- }
87
- if (key === 'c') {
88
- if (!this.connectionInfo.token) {
89
- this.lastStatus = 'No connected-host token is available to copy.';
90
- } else if (this.copyToClipboard) {
91
- this.copyToClipboard(this.connectionInfo.token);
92
- this.lastStatus = 'Token copied to clipboard.';
93
- } else {
94
- this.lastStatus = 'Clipboard not available.';
95
- }
96
- this.markDirty();
97
- return true;
98
- }
99
- return false;
100
- }
101
-
102
- public render(width: number, height: number): Line[] {
103
- this.needsRender = false;
104
- const lines: Line[] = [];
105
-
106
- const { url, token, username, password } = this.connectionInfo;
107
-
108
- // ── Connection info header ─────────────────────────────────────────────
109
- lines.push(createEmptyLine(width));
110
- lines.push(
111
- buildPanelLine(width, [
112
- [' URL ', C.label],
113
- [url.slice(0, Math.max(0, width - 12)), C.url],
114
- ]),
115
- );
116
- lines.push(
117
- buildPanelLine(width, [
118
- [' Token ', C.label],
119
- [token, C.token],
120
- ]),
121
- );
122
- lines.push(
123
- buildPanelLine(width, [
124
- [' Username ', C.label],
125
- [username.slice(0, Math.max(0, width - 12)), C.value],
126
- ]),
127
- );
128
- if (password !== undefined) {
129
- lines.push(
130
- buildPanelLine(width, [
131
- [' Password ', C.label],
132
- [password, C.value],
133
- ]),
134
- );
135
- }
136
- lines.push(createEmptyLine(width));
137
-
138
- // ── QR code ────────────────────────────────────────────────────────────
139
- if (this.connectionInfo.token) {
140
- const payload = encodeConnectionPayload({
141
- url: this.connectionInfo.url,
142
- token: this.connectionInfo.token,
143
- username: this.connectionInfo.username,
144
- ...(this.connectionInfo.password !== undefined ? { password: this.connectionInfo.password } : {}),
145
- version: this.connectionInfo.version ?? '0.0.0',
146
- surface: this.connectionInfo.surface ?? GOODVIBES_AGENT_PAIRING_SURFACE,
147
- });
148
- const matrix = generateQrMatrix(payload);
149
- const qrLines = renderQrMatrix(matrix.modules, width, { fg: C.qrFg, bg: C.qrBg });
150
- for (const qrLine of qrLines) {
151
- lines.push(qrLine);
152
- }
153
- } else {
154
- lines.push(
155
- buildPanelLine(width, [
156
- [' Pairing unavailable ', C.hint],
157
- ]),
158
- );
159
- lines.push(
160
- buildPanelLine(width, [
161
- [' Connected-host operator token is missing. Use confirmed setup to create or repair it. ', C.dim],
162
- ]),
163
- );
164
- lines.push(
165
- buildPanelLine(width, [
166
- [' agent_harness mode:"provision_connected_host_token" then reopen this panel. ', C.dim],
167
- ]),
168
- );
169
- }
170
-
171
- lines.push(createEmptyLine(width));
172
-
173
- // ── Status message (ephemeral) ─────────────────────────────────────────
174
- if (this.lastStatus) {
175
- lines.push(
176
- buildPanelLine(width, [
177
- [` ${this.lastStatus} `, C.hint],
178
- ]),
179
- );
180
- }
181
-
182
- // ── Hints ──────────────────────────────────────────────────────────────
183
- const hintParts: Array<[string, string]> = this.connectionInfo.token
184
- ? [
185
- [' c ', C.hint],
186
- ['copy token', C.dim],
187
- ]
188
- : [
189
- [' h ', C.hint],
190
- ['host auth required', C.dim],
191
- ];
192
- const hintsLine = buildPanelLine(width, hintParts);
193
-
194
- // Push hints at the bottom if we have room, otherwise append after QR
195
- const remaining = height - lines.length;
196
- if (remaining > 2) {
197
- // Fill with empty lines to push hints toward bottom
198
- const fillCount = Math.max(0, remaining - 2);
199
- for (let i = 0; i < fillCount; i++) {
200
- lines.push(createEmptyLine(width));
201
- }
202
- }
203
- lines.push(hintsLine);
204
-
205
- return lines;
206
- }
207
- }