pi-crew 0.1.44 → 0.1.45

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 (142) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/agents/analyst.md +11 -11
  3. package/agents/critic.md +11 -11
  4. package/agents/executor.md +11 -11
  5. package/agents/explorer.md +11 -11
  6. package/agents/planner.md +11 -11
  7. package/agents/reviewer.md +11 -11
  8. package/agents/security-reviewer.md +11 -11
  9. package/agents/test-engineer.md +11 -11
  10. package/agents/verifier.md +11 -11
  11. package/agents/writer.md +11 -11
  12. package/docs/refactor-tasks-phase3.md +394 -394
  13. package/docs/refactor-tasks-phase4.md +564 -564
  14. package/docs/refactor-tasks-phase5.md +402 -402
  15. package/docs/refactor-tasks-phase6.md +662 -662
  16. package/docs/research-extension-examples.md +297 -297
  17. package/docs/research-extension-system.md +324 -324
  18. package/docs/research-optimization-plan.md +548 -548
  19. package/docs/research-phase10-distillation.md +198 -198
  20. package/docs/research-phase11-distillation.md +201 -201
  21. package/docs/research-pi-coding-agent.md +357 -357
  22. package/docs/research-source-pi-crew-reference.md +174 -174
  23. package/docs/runtime-flow.md +148 -148
  24. package/docs/source-runtime-refactor-map.md +83 -83
  25. package/index.ts +6 -6
  26. package/package.json +1 -1
  27. package/src/agents/agent-serializer.ts +34 -34
  28. package/src/extension/cross-extension-rpc.ts +82 -82
  29. package/src/extension/register.ts +8 -1
  30. package/src/extension/registration/commands.ts +18 -2
  31. package/src/extension/registration/compaction-guard.ts +125 -125
  32. package/src/extension/registration/subagent-tools.ts +148 -148
  33. package/src/extension/registration/team-tool.ts +26 -8
  34. package/src/extension/run-bundle-schema.ts +89 -89
  35. package/src/extension/run-maintenance.ts +43 -43
  36. package/src/extension/team-tool/cancel.ts +105 -102
  37. package/src/extension/team-tool/context.ts +1 -0
  38. package/src/extension/team-tool/handle-settings.ts +188 -188
  39. package/src/extension/team-tool/inspect.ts +41 -41
  40. package/src/extension/team-tool/lifecycle-actions.ts +79 -79
  41. package/src/extension/team-tool/plan.ts +19 -19
  42. package/src/extension/team-tool/respond.ts +83 -66
  43. package/src/extension/team-tool/run.ts +1 -0
  44. package/src/i18n.ts +184 -184
  45. package/src/observability/exporters/otlp-exporter.ts +77 -77
  46. package/src/prompt/prompt-runtime.ts +72 -72
  47. package/src/runtime/agent-control.ts +63 -63
  48. package/src/runtime/agent-memory.ts +72 -72
  49. package/src/runtime/agent-observability.ts +114 -114
  50. package/src/runtime/async-marker.ts +26 -26
  51. package/src/runtime/attention-events.ts +28 -28
  52. package/src/runtime/background-runner.ts +53 -53
  53. package/src/runtime/child-pi.ts +444 -444
  54. package/src/runtime/completion-guard.ts +190 -190
  55. package/src/runtime/crew-agent-records.ts +8 -0
  56. package/src/runtime/delivery-coordinator.ts +153 -142
  57. package/src/runtime/direct-run.ts +35 -35
  58. package/src/runtime/foreground-control.ts +82 -82
  59. package/src/runtime/green-contract.ts +46 -46
  60. package/src/runtime/group-join.ts +106 -106
  61. package/src/runtime/heartbeat-gradient.ts +28 -28
  62. package/src/runtime/heartbeat-watcher.ts +124 -124
  63. package/src/runtime/live-agent-control.ts +87 -87
  64. package/src/runtime/live-agent-manager.ts +85 -85
  65. package/src/runtime/live-control-realtime.ts +36 -36
  66. package/src/runtime/live-session-runtime.ts +305 -305
  67. package/src/runtime/overflow-recovery.ts +175 -156
  68. package/src/runtime/parallel-research.ts +44 -44
  69. package/src/runtime/pi-json-output.ts +111 -111
  70. package/src/runtime/policy-engine.ts +79 -79
  71. package/src/runtime/progress-event-coalescer.ts +43 -43
  72. package/src/runtime/recovery-recipes.ts +74 -74
  73. package/src/runtime/retry-executor.ts +64 -64
  74. package/src/runtime/role-permission.ts +39 -39
  75. package/src/runtime/session-resources.ts +25 -25
  76. package/src/runtime/session-snapshot.ts +59 -59
  77. package/src/runtime/session-usage.ts +79 -79
  78. package/src/runtime/sidechain-output.ts +29 -29
  79. package/src/runtime/stale-reconciler.ts +199 -179
  80. package/src/runtime/supervisor-contact.ts +59 -59
  81. package/src/runtime/task-display.ts +38 -38
  82. package/src/runtime/task-output-context.ts +127 -127
  83. package/src/runtime/task-runner/live-executor.ts +101 -101
  84. package/src/runtime/task-runner/progress.ts +119 -119
  85. package/src/runtime/task-runner/result-utils.ts +14 -14
  86. package/src/runtime/task-runner/state-helpers.ts +22 -22
  87. package/src/runtime/team-runner.ts +13 -4
  88. package/src/runtime/worker-heartbeat.ts +21 -21
  89. package/src/runtime/worker-startup.ts +57 -57
  90. package/src/state/state-store.ts +43 -0
  91. package/src/state/task-claims.ts +44 -44
  92. package/src/state/types.ts +2 -0
  93. package/src/state/usage.ts +29 -29
  94. package/src/subagents/async-entry.ts +1 -1
  95. package/src/subagents/index.ts +3 -3
  96. package/src/subagents/live/control.ts +1 -1
  97. package/src/subagents/live/manager.ts +1 -1
  98. package/src/subagents/live/realtime.ts +1 -1
  99. package/src/subagents/live/session-runtime.ts +1 -1
  100. package/src/subagents/manager.ts +1 -1
  101. package/src/subagents/spawn.ts +1 -1
  102. package/src/teams/team-serializer.ts +38 -38
  103. package/src/types/diff.d.ts +18 -18
  104. package/src/ui/crew-footer.ts +101 -101
  105. package/src/ui/crew-select-list.ts +111 -111
  106. package/src/ui/crew-widget.ts +5 -1
  107. package/src/ui/dashboard-panes/mailbox-pane.ts +2 -1
  108. package/src/ui/dashboard-panes/metrics-pane.ts +34 -34
  109. package/src/ui/dynamic-border.ts +25 -25
  110. package/src/ui/layout-primitives.ts +106 -106
  111. package/src/ui/loaders.ts +158 -158
  112. package/src/ui/powerbar-publisher.ts +1 -1
  113. package/src/ui/render-diff.ts +119 -119
  114. package/src/ui/render-scheduler.ts +143 -143
  115. package/src/ui/run-snapshot-cache.ts +56 -37
  116. package/src/ui/snapshot-types.ts +5 -0
  117. package/src/ui/spinner.ts +17 -17
  118. package/src/ui/status-colors.ts +58 -58
  119. package/src/ui/syntax-highlight.ts +116 -116
  120. package/src/utils/atomic-write.ts +33 -33
  121. package/src/utils/completion-dedupe.ts +63 -63
  122. package/src/utils/frontmatter.ts +68 -68
  123. package/src/utils/git.ts +262 -262
  124. package/src/utils/ids.ts +12 -12
  125. package/src/utils/names.ts +27 -27
  126. package/src/utils/redaction.ts +44 -44
  127. package/src/utils/safe-paths.ts +47 -47
  128. package/src/utils/sleep.ts +32 -32
  129. package/src/workflows/validate-workflow.ts +40 -40
  130. package/src/worktree/branch-freshness.ts +45 -45
  131. package/teams/default.team.md +12 -12
  132. package/teams/fast-fix.team.md +11 -11
  133. package/teams/implementation.team.md +18 -18
  134. package/teams/parallel-research.team.md +14 -14
  135. package/teams/research.team.md +11 -11
  136. package/teams/review.team.md +12 -12
  137. package/workflows/default.workflow.md +29 -29
  138. package/workflows/fast-fix.workflow.md +22 -22
  139. package/workflows/implementation.workflow.md +38 -38
  140. package/workflows/parallel-research.workflow.md +46 -46
  141. package/workflows/research.workflow.md +22 -22
  142. package/workflows/review.workflow.md +30 -30
@@ -1,111 +1,111 @@
1
- import { pad, truncate } from "../utils/visual.ts";
2
- import type { CrewTheme } from "./theme-adapter.ts";
3
-
4
- export interface CrewSelectItem<T = string> {
5
- value: T;
6
- label: string;
7
- description?: string;
8
- }
9
-
10
- export interface CrewSelectListOptions<T = string> {
11
- onSelect: (item: CrewSelectItem<T>) => void;
12
- onCancel: () => void;
13
- onPreview?: (item: CrewSelectItem<T>) => void;
14
- maxHeight?: number;
15
- }
16
-
17
- export class CrewSelectList<T = string> {
18
- private readonly items: CrewSelectItem<T>[];
19
- private readonly theme: CrewTheme;
20
- private readonly options: CrewSelectListOptions<T>;
21
- private selectedIndex = 0;
22
- private scrollOffset = 0;
23
-
24
- constructor(items: CrewSelectItem<T>[], theme: CrewTheme, options: CrewSelectListOptions<T>) {
25
- this.items = [...items];
26
- this.theme = theme;
27
- this.options = options;
28
- this.selectedIndex = this.items.length ? 0 : -1;
29
- }
30
-
31
- invalidate(): void {}
32
-
33
- getSelected(): CrewSelectItem<T> | undefined {
34
- return this.selectedIndex >= 0 ? this.items[this.selectedIndex] : undefined;
35
- }
36
-
37
- setSelectedIndex(index: number): void {
38
- if (!this.items.length) {
39
- this.selectedIndex = -1;
40
- this.scrollOffset = 0;
41
- return;
42
- }
43
- const next = Math.min(this.items.length - 1, Math.max(0, index));
44
- const changed = next !== this.selectedIndex;
45
- this.selectedIndex = next;
46
- this.ensureVisible();
47
- if (changed) {
48
- const selected = this.getSelected();
49
- if (selected) this.options.onPreview?.(selected);
50
- }
51
- }
52
-
53
- handleInput(data: string): void {
54
- if (data === "q" || data === "\u001b") {
55
- this.options.onCancel();
56
- return;
57
- }
58
- if (data === "j" || data === "\u001b[B") {
59
- this.setSelectedIndex(this.selectedIndex + 1);
60
- return;
61
- }
62
- if (data === "k" || data === "\u001b[A") {
63
- this.setSelectedIndex(this.selectedIndex - 1);
64
- return;
65
- }
66
- if (data === "\r" || data === "\n") {
67
- const selected = this.getSelected();
68
- if (selected) this.options.onSelect(selected);
69
- }
70
- }
71
-
72
- render(width: number): string[] {
73
- if (!this.items.length) return [this.theme.fg("muted", "(no items)")];
74
- const maxHeight = Math.max(1, Math.floor(this.options.maxHeight ?? this.items.length));
75
- this.ensureVisible();
76
- const hasTop = this.scrollOffset > 0;
77
- const availableWithoutBottom = Math.max(1, maxHeight - (hasTop ? 1 : 0));
78
- const hasBottom = this.scrollOffset + availableWithoutBottom < this.items.length;
79
- const slots = this.visibleItemSlots(maxHeight, hasTop, hasBottom);
80
- const visibleItems = this.items.slice(this.scrollOffset, this.scrollOffset + slots);
81
- const lines: string[] = [];
82
- if (hasTop) lines.push(this.theme.fg("muted", `↑ ${this.scrollOffset} more`));
83
- for (const [offset, item] of visibleItems.entries()) {
84
- const index = this.scrollOffset + offset;
85
- const prefix = index === this.selectedIndex ? " → " : " ";
86
- const suffix = item.description ? this.theme.fg("dim", ` — ${item.description}`) : "";
87
- const raw = `${prefix}${item.label}${suffix}`;
88
- const line = index === this.selectedIndex ? this.theme.inverse?.(raw) ?? raw : raw;
89
- lines.push(pad(truncate(line, width, "..."), Math.max(1, width)));
90
- }
91
- if (hasBottom) lines.push(this.theme.fg("muted", `↓ ${this.items.length - (this.scrollOffset + slots)} more`));
92
- return lines.slice(0, maxHeight);
93
- }
94
-
95
- private visibleItemSlots(maxHeight: number, hasTop: boolean, hasBottom: boolean): number {
96
- return Math.max(1, maxHeight - (hasTop ? 1 : 0) - (hasBottom ? 1 : 0));
97
- }
98
-
99
- private ensureVisible(): void {
100
- if (this.selectedIndex < 0) return;
101
- const maxHeight = Math.max(1, Math.floor(this.options.maxHeight ?? this.items.length));
102
- const reservedTop = this.scrollOffset > 0 ? 1 : 0;
103
- const visibleSlots = Math.max(1, maxHeight - reservedTop - 1);
104
- if (this.selectedIndex < this.scrollOffset) {
105
- this.scrollOffset = this.selectedIndex;
106
- } else if (this.selectedIndex >= this.scrollOffset + visibleSlots) {
107
- this.scrollOffset = Math.max(0, this.selectedIndex - visibleSlots + 1);
108
- }
109
- this.scrollOffset = Math.min(this.scrollOffset, Math.max(0, this.items.length - 1));
110
- }
111
- }
1
+ import { pad, truncate } from "../utils/visual.ts";
2
+ import type { CrewTheme } from "./theme-adapter.ts";
3
+
4
+ export interface CrewSelectItem<T = string> {
5
+ value: T;
6
+ label: string;
7
+ description?: string;
8
+ }
9
+
10
+ export interface CrewSelectListOptions<T = string> {
11
+ onSelect: (item: CrewSelectItem<T>) => void;
12
+ onCancel: () => void;
13
+ onPreview?: (item: CrewSelectItem<T>) => void;
14
+ maxHeight?: number;
15
+ }
16
+
17
+ export class CrewSelectList<T = string> {
18
+ private readonly items: CrewSelectItem<T>[];
19
+ private readonly theme: CrewTheme;
20
+ private readonly options: CrewSelectListOptions<T>;
21
+ private selectedIndex = 0;
22
+ private scrollOffset = 0;
23
+
24
+ constructor(items: CrewSelectItem<T>[], theme: CrewTheme, options: CrewSelectListOptions<T>) {
25
+ this.items = [...items];
26
+ this.theme = theme;
27
+ this.options = options;
28
+ this.selectedIndex = this.items.length ? 0 : -1;
29
+ }
30
+
31
+ invalidate(): void {}
32
+
33
+ getSelected(): CrewSelectItem<T> | undefined {
34
+ return this.selectedIndex >= 0 ? this.items[this.selectedIndex] : undefined;
35
+ }
36
+
37
+ setSelectedIndex(index: number): void {
38
+ if (!this.items.length) {
39
+ this.selectedIndex = -1;
40
+ this.scrollOffset = 0;
41
+ return;
42
+ }
43
+ const next = Math.min(this.items.length - 1, Math.max(0, index));
44
+ const changed = next !== this.selectedIndex;
45
+ this.selectedIndex = next;
46
+ this.ensureVisible();
47
+ if (changed) {
48
+ const selected = this.getSelected();
49
+ if (selected) this.options.onPreview?.(selected);
50
+ }
51
+ }
52
+
53
+ handleInput(data: string): void {
54
+ if (data === "q" || data === "\u001b") {
55
+ this.options.onCancel();
56
+ return;
57
+ }
58
+ if (data === "j" || data === "\u001b[B") {
59
+ this.setSelectedIndex(this.selectedIndex + 1);
60
+ return;
61
+ }
62
+ if (data === "k" || data === "\u001b[A") {
63
+ this.setSelectedIndex(this.selectedIndex - 1);
64
+ return;
65
+ }
66
+ if (data === "\r" || data === "\n") {
67
+ const selected = this.getSelected();
68
+ if (selected) this.options.onSelect(selected);
69
+ }
70
+ }
71
+
72
+ render(width: number): string[] {
73
+ if (!this.items.length) return [this.theme.fg("muted", "(no items)")];
74
+ const maxHeight = Math.max(1, Math.floor(this.options.maxHeight ?? this.items.length));
75
+ this.ensureVisible();
76
+ const hasTop = this.scrollOffset > 0;
77
+ const availableWithoutBottom = Math.max(1, maxHeight - (hasTop ? 1 : 0));
78
+ const hasBottom = this.scrollOffset + availableWithoutBottom < this.items.length;
79
+ const slots = this.visibleItemSlots(maxHeight, hasTop, hasBottom);
80
+ const visibleItems = this.items.slice(this.scrollOffset, this.scrollOffset + slots);
81
+ const lines: string[] = [];
82
+ if (hasTop) lines.push(this.theme.fg("muted", `↑ ${this.scrollOffset} more`));
83
+ for (const [offset, item] of visibleItems.entries()) {
84
+ const index = this.scrollOffset + offset;
85
+ const prefix = index === this.selectedIndex ? " → " : " ";
86
+ const suffix = item.description ? this.theme.fg("dim", ` — ${item.description}`) : "";
87
+ const raw = `${prefix}${item.label}${suffix}`;
88
+ const line = index === this.selectedIndex ? this.theme.inverse?.(raw) ?? raw : raw;
89
+ lines.push(pad(truncate(line, width, "..."), Math.max(1, width)));
90
+ }
91
+ if (hasBottom) lines.push(this.theme.fg("muted", `↓ ${this.items.length - (this.scrollOffset + slots)} more`));
92
+ return lines.slice(0, maxHeight);
93
+ }
94
+
95
+ private visibleItemSlots(maxHeight: number, hasTop: boolean, hasBottom: boolean): number {
96
+ return Math.max(1, maxHeight - (hasTop ? 1 : 0) - (hasBottom ? 1 : 0));
97
+ }
98
+
99
+ private ensureVisible(): void {
100
+ if (this.selectedIndex < 0) return;
101
+ const maxHeight = Math.max(1, Math.floor(this.options.maxHeight ?? this.items.length));
102
+ const reservedTop = this.scrollOffset > 0 ? 1 : 0;
103
+ const visibleSlots = Math.max(1, maxHeight - reservedTop - 1);
104
+ if (this.selectedIndex < this.scrollOffset) {
105
+ this.scrollOffset = this.selectedIndex;
106
+ } else if (this.selectedIndex >= this.scrollOffset + visibleSlots) {
107
+ this.scrollOffset = Math.max(0, this.selectedIndex - visibleSlots + 1);
108
+ }
109
+ this.scrollOffset = Math.min(this.scrollOffset, Math.max(0, this.items.length - 1));
110
+ }
111
+ }
@@ -118,9 +118,11 @@ function statusSummary(runs: WidgetRun[]): string {
118
118
  const agents = runs.flatMap((item) => item.agents);
119
119
  const runningAgents = agents.filter((agent) => agent.status === "running").length;
120
120
  const queuedAgents = agents.filter((agent) => agent.status === "queued").length;
121
+ const waitingAgents = agents.filter((agent) => agent.status === "waiting").length;
121
122
  const completedAgents = agents.filter((agent) => agent.status === "completed").length;
122
123
  const parts = [`${runningAgents} running`];
123
124
  if (queuedAgents) parts.push(`${queuedAgents} queued`);
125
+ if (waitingAgents) parts.push(`${waitingAgents} waiting`);
124
126
  if (completedAgents) parts.push(`${completedAgents}/${agents.length} done`);
125
127
  return `Crew: ${parts.join(", ")}`;
126
128
  }
@@ -136,9 +138,11 @@ export function widgetHeader(runs: WidgetRun[], runningGlyph: string, maxLines =
136
138
  const agents = runs.flatMap((item) => item.agents);
137
139
  const runningAgents = agents.filter((agent) => agent.status === "running").length;
138
140
  const queuedAgents = agents.filter((agent) => agent.status === "queued").length;
141
+ const waitingAgents = agents.filter((agent) => agent.status === "waiting").length;
139
142
  const completedAgents = agents.filter((agent) => agent.status === "completed").length;
140
143
  const parts = [`${runningAgents} running`];
141
144
  if (queuedAgents) parts.push(`${queuedAgents} queued`);
145
+ if (waitingAgents) parts.push(`${waitingAgents} waiting`);
142
146
  if (completedAgents) parts.push(`${completedAgents}/${agents.length} done`);
143
147
  return `${runningGlyph} Crew agents${notificationBadge(notificationCount)} · ${parts.join(" · ")} · /team-dashboard`;
144
148
  }
@@ -153,7 +157,7 @@ export function buildCrewWidgetLines(cwd: string, frame = 0, maxLines = 8, provi
153
157
  const runningGlyph = SPINNER[frame % SPINNER.length] ?? SPINNER[0];
154
158
  const lines: string[] = [widgetHeader(runs, runningGlyph, maxLines, notificationCount)];
155
159
  for (const { run, agents } of runs) {
156
- const activeAgents = agents.filter((item) => item.status === "running" || item.status === "queued");
160
+ const activeAgents = agents.filter((item) => item.status === "running" || item.status === "queued" || item.status === "waiting");
157
161
  const completed = agents.filter((agent) => agent.status === "completed").length;
158
162
  const runGlyph = iconForStatus(run.status, { runningGlyph });
159
163
  lines.push(`├─ ${runGlyph} ${shortRunLabel(run)} · ${completed}/${agents.length} done · ${run.runId.slice(-8)}`);
@@ -3,8 +3,9 @@ import type { RunUiSnapshot } from "../snapshot-types.ts";
3
3
  export function renderMailboxPane(snapshot: RunUiSnapshot | undefined): string[] {
4
4
  if (!snapshot) return ["Mailbox pane: snapshot unavailable"];
5
5
  const mailbox = snapshot.mailbox;
6
+ const approx = mailbox.approximate ? " · approximate (tail)" : "";
6
7
  return [
7
- `Mailbox pane: inbox unread=${mailbox.inboxUnread} · outbox pending=${mailbox.outboxPending} · attention=${mailbox.needsAttention}`,
8
+ `Mailbox pane: inbox unread=${mailbox.inboxUnread} · outbox pending=${mailbox.outboxPending} · attention=${mailbox.needsAttention}${approx}`,
8
9
  mailbox.needsAttention > 0 ? "Needs attention: press Enter for detail · A ack · N nudge · C compose · X ack all." : "No mailbox items need attention. Press Enter for detail or C compose.",
9
10
  ];
10
11
  }
@@ -1,34 +1,34 @@
1
- import type { MetricRegistry } from "../../observability/metric-registry.ts";
2
- import type { HistogramPoint, MetricLabels, MetricPoint } from "../../observability/metrics-primitives.ts";
3
- import type { RunUiSnapshot } from "../snapshot-types.ts";
4
-
5
- export interface MetricsPaneOptions {
6
- registry?: MetricRegistry;
7
- maxCounters?: number;
8
- }
9
-
10
- function labelsText(labels: MetricLabels): string {
11
- const entries = Object.entries(labels);
12
- return entries.length ? `{${entries.map(([key, value]) => `${key}=${value}`).join(",")}}` : "";
13
- }
14
-
15
- function isHistogramPoint(point: MetricPoint | HistogramPoint): point is HistogramPoint {
16
- return "quantiles" in point;
17
- }
18
-
19
- export function renderMetricsPane(_snapshot: RunUiSnapshot | undefined, opts: MetricsPaneOptions = {}): string[] {
20
- if (!opts.registry) return ["Metrics pane: registry unavailable"];
21
- const snapshots = opts.registry.snapshot();
22
- if (!snapshots.length) return ["Metrics pane: no metrics recorded"];
23
- const lines = ["Metrics pane: top metrics"];
24
- for (const snapshot of snapshots.slice(0, opts.maxCounters ?? 10)) {
25
- const first = snapshot.values[0];
26
- if (!first) {
27
- lines.push(`${snapshot.name}: empty`);
28
- continue;
29
- }
30
- if (isHistogramPoint(first)) lines.push(`${snapshot.name}${labelsText(first.labels)} count=${first.count} p95=${Number.isFinite(first.quantiles.p95) ? Math.round(first.quantiles.p95) : "n/a"}`);
31
- else lines.push(`${snapshot.name}${labelsText(first.labels)} ${first.value}`);
32
- }
33
- return lines;
34
- }
1
+ import type { MetricRegistry } from "../../observability/metric-registry.ts";
2
+ import type { HistogramPoint, MetricLabels, MetricPoint } from "../../observability/metrics-primitives.ts";
3
+ import type { RunUiSnapshot } from "../snapshot-types.ts";
4
+
5
+ export interface MetricsPaneOptions {
6
+ registry?: MetricRegistry;
7
+ maxCounters?: number;
8
+ }
9
+
10
+ function labelsText(labels: MetricLabels): string {
11
+ const entries = Object.entries(labels);
12
+ return entries.length ? `{${entries.map(([key, value]) => `${key}=${value}`).join(",")}}` : "";
13
+ }
14
+
15
+ function isHistogramPoint(point: MetricPoint | HistogramPoint): point is HistogramPoint {
16
+ return "quantiles" in point;
17
+ }
18
+
19
+ export function renderMetricsPane(_snapshot: RunUiSnapshot | undefined, opts: MetricsPaneOptions = {}): string[] {
20
+ if (!opts.registry) return ["Metrics pane: registry unavailable"];
21
+ const snapshots = opts.registry.snapshot();
22
+ if (!snapshots.length) return ["Metrics pane: no metrics recorded"];
23
+ const lines = ["Metrics pane: top metrics"];
24
+ for (const snapshot of snapshots.slice(0, opts.maxCounters ?? 10)) {
25
+ const first = snapshot.values[0];
26
+ if (!first) {
27
+ lines.push(`${snapshot.name}: empty`);
28
+ continue;
29
+ }
30
+ if (isHistogramPoint(first)) lines.push(`${snapshot.name}${labelsText(first.labels)} count=${first.count} p95=${Number.isFinite(first.quantiles.p95) ? Math.round(first.quantiles.p95) : "n/a"}`);
31
+ else lines.push(`${snapshot.name}${labelsText(first.labels)} ${first.value}`);
32
+ }
33
+ return lines;
34
+ }
@@ -1,25 +1,25 @@
1
- import type { CrewTheme } from "./theme-adapter.ts";
2
-
3
- export interface DynamicCrewBorderOptions {
4
- color?: (value: string) => string;
5
- char?: string;
6
- }
7
-
8
- export class DynamicCrewBorder {
9
- private readonly theme: CrewTheme;
10
- private readonly color?: (value: string) => string;
11
- private readonly char: string;
12
-
13
- constructor(theme: CrewTheme, options: DynamicCrewBorderOptions = {}) {
14
- this.theme = theme;
15
- this.color = options.color;
16
- this.char = options.char && options.char.length > 0 ? options.char : "─";
17
- }
18
-
19
- render(width: number): string[] {
20
- const line = this.char.repeat(Math.max(0, width));
21
- return [this.color ? this.color(line) : this.theme.fg("border", line)];
22
- }
23
-
24
- invalidate(): void {}
25
- }
1
+ import type { CrewTheme } from "./theme-adapter.ts";
2
+
3
+ export interface DynamicCrewBorderOptions {
4
+ color?: (value: string) => string;
5
+ char?: string;
6
+ }
7
+
8
+ export class DynamicCrewBorder {
9
+ private readonly theme: CrewTheme;
10
+ private readonly color?: (value: string) => string;
11
+ private readonly char: string;
12
+
13
+ constructor(theme: CrewTheme, options: DynamicCrewBorderOptions = {}) {
14
+ this.theme = theme;
15
+ this.color = options.color;
16
+ this.char = options.char && options.char.length > 0 ? options.char : "─";
17
+ }
18
+
19
+ render(width: number): string[] {
20
+ const line = this.char.repeat(Math.max(0, width));
21
+ return [this.color ? this.color(line) : this.theme.fg("border", line)];
22
+ }
23
+
24
+ invalidate(): void {}
25
+ }
@@ -1,106 +1,106 @@
1
- import { pad, wrapHard } from "../utils/visual.ts";
2
-
3
- export interface RenderableComponent {
4
- invalidate(): void;
5
- render(width: number): string[];
6
- }
7
-
8
- export class Container implements RenderableComponent {
9
- private children: RenderableComponent[] = [];
10
-
11
- addChild(child: RenderableComponent): void {
12
- this.children.push(child);
13
- }
14
-
15
- clear(): void {
16
- this.children = [];
17
- }
18
-
19
- invalidate(): void {
20
- for (const child of this.children) {
21
- child.invalidate();
22
- }
23
- }
24
-
25
- render(width: number): string[] {
26
- const lines: string[] = [];
27
- for (const child of this.children) {
28
- lines.push(...child.render(width));
29
- }
30
- return lines;
31
- }
32
- }
33
-
34
- export class Box extends Container {
35
- private readonly paddingX: number;
36
- private readonly paddingY: number;
37
-
38
- constructor(paddingX = 0, paddingY = 0) {
39
- super();
40
- this.paddingX = paddingX;
41
- this.paddingY = paddingY;
42
- }
43
-
44
- render(width: number): string[] {
45
- const innerWidth = Math.max(1, width - this.paddingX * 2);
46
- const rows = super.render(innerWidth);
47
- const paddedRows: string[] = [];
48
- const left = " ".repeat(this.paddingX);
49
- const right = " ".repeat(this.paddingX);
50
- for (const row of rows) {
51
- paddedRows.push(pad(`${left}${row}${right}`, width));
52
- }
53
- const emptyRow = pad("", width);
54
- if (this.paddingY <= 0) return paddedRows;
55
- if (this.paddingY > 0) {
56
- const topAndBottom = Array.from({ length: this.paddingY }, () => emptyRow);
57
- return [...topAndBottom, ...paddedRows, ...topAndBottom];
58
- }
59
- return paddedRows;
60
- }
61
- }
62
-
63
- export class Text implements RenderableComponent {
64
- private text: string;
65
- private cachedWidth = 0;
66
- private cachedResult: string[] = [];
67
-
68
- constructor(text = "") {
69
- this.text = text;
70
- }
71
-
72
- setText(text: string): void {
73
- if (text === this.text) return;
74
- this.text = text;
75
- this.invalidate();
76
- }
77
-
78
- invalidate(): void {
79
- this.cachedWidth = 0;
80
- this.cachedResult = [];
81
- }
82
-
83
- render(width: number): string[] {
84
- if (this.cachedWidth === width) return this.cachedResult;
85
- const wrapped = wrapHard(this.text, Math.max(1, width));
86
- const lines = wrapped.length ? wrapped : [""];
87
- this.cachedWidth = width;
88
- this.cachedResult = lines.map((line) => pad(line, width));
89
- return this.cachedResult;
90
- }
91
- }
92
-
93
- export class Spacer implements RenderableComponent {
94
- private readonly rows: number;
95
-
96
- constructor(rows = 0) {
97
- this.rows = rows;
98
- }
99
-
100
- render(width: number): string[] {
101
- if (this.rows <= 0) return [];
102
- return Array.from({ length: Math.max(0, this.rows) }, () => pad("", width));
103
- }
104
-
105
- invalidate(): void {}
106
- }
1
+ import { pad, wrapHard } from "../utils/visual.ts";
2
+
3
+ export interface RenderableComponent {
4
+ invalidate(): void;
5
+ render(width: number): string[];
6
+ }
7
+
8
+ export class Container implements RenderableComponent {
9
+ private children: RenderableComponent[] = [];
10
+
11
+ addChild(child: RenderableComponent): void {
12
+ this.children.push(child);
13
+ }
14
+
15
+ clear(): void {
16
+ this.children = [];
17
+ }
18
+
19
+ invalidate(): void {
20
+ for (const child of this.children) {
21
+ child.invalidate();
22
+ }
23
+ }
24
+
25
+ render(width: number): string[] {
26
+ const lines: string[] = [];
27
+ for (const child of this.children) {
28
+ lines.push(...child.render(width));
29
+ }
30
+ return lines;
31
+ }
32
+ }
33
+
34
+ export class Box extends Container {
35
+ private readonly paddingX: number;
36
+ private readonly paddingY: number;
37
+
38
+ constructor(paddingX = 0, paddingY = 0) {
39
+ super();
40
+ this.paddingX = paddingX;
41
+ this.paddingY = paddingY;
42
+ }
43
+
44
+ render(width: number): string[] {
45
+ const innerWidth = Math.max(1, width - this.paddingX * 2);
46
+ const rows = super.render(innerWidth);
47
+ const paddedRows: string[] = [];
48
+ const left = " ".repeat(this.paddingX);
49
+ const right = " ".repeat(this.paddingX);
50
+ for (const row of rows) {
51
+ paddedRows.push(pad(`${left}${row}${right}`, width));
52
+ }
53
+ const emptyRow = pad("", width);
54
+ if (this.paddingY <= 0) return paddedRows;
55
+ if (this.paddingY > 0) {
56
+ const topAndBottom = Array.from({ length: this.paddingY }, () => emptyRow);
57
+ return [...topAndBottom, ...paddedRows, ...topAndBottom];
58
+ }
59
+ return paddedRows;
60
+ }
61
+ }
62
+
63
+ export class Text implements RenderableComponent {
64
+ private text: string;
65
+ private cachedWidth = 0;
66
+ private cachedResult: string[] = [];
67
+
68
+ constructor(text = "") {
69
+ this.text = text;
70
+ }
71
+
72
+ setText(text: string): void {
73
+ if (text === this.text) return;
74
+ this.text = text;
75
+ this.invalidate();
76
+ }
77
+
78
+ invalidate(): void {
79
+ this.cachedWidth = 0;
80
+ this.cachedResult = [];
81
+ }
82
+
83
+ render(width: number): string[] {
84
+ if (this.cachedWidth === width) return this.cachedResult;
85
+ const wrapped = wrapHard(this.text, Math.max(1, width));
86
+ const lines = wrapped.length ? wrapped : [""];
87
+ this.cachedWidth = width;
88
+ this.cachedResult = lines.map((line) => pad(line, width));
89
+ return this.cachedResult;
90
+ }
91
+ }
92
+
93
+ export class Spacer implements RenderableComponent {
94
+ private readonly rows: number;
95
+
96
+ constructor(rows = 0) {
97
+ this.rows = rows;
98
+ }
99
+
100
+ render(width: number): string[] {
101
+ if (this.rows <= 0) return [];
102
+ return Array.from({ length: Math.max(0, this.rows) }, () => pad("", width));
103
+ }
104
+
105
+ invalidate(): void {}
106
+ }