@leing2021/super-pi 0.22.1 → 0.23.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 (117) hide show
  1. package/README.md +66 -293
  2. package/extensions/ce-core/index.ts +276 -48
  3. package/extensions/ce-core/tools/parallel-subagent.ts +3 -3
  4. package/extensions/ce-core/tools/subagent.ts +2 -2
  5. package/package.json +4 -20
  6. package/rules/common/naming.md +154 -0
  7. package/skills/01-brainstorm/SKILL.md +42 -79
  8. package/skills/01-brainstorm/references/ce-brainstorm-mode.md +47 -0
  9. package/skills/02-plan/SKILL.md +43 -61
  10. package/skills/02-plan/references/solution-search.md +46 -0
  11. package/skills/03-work/SKILL.md +34 -52
  12. package/skills/03-work/references/completion-report.md +51 -0
  13. package/skills/04-review/SKILL.md +44 -51
  14. package/skills/04-review/references/solution-search.md +46 -0
  15. package/skills/06-next/SKILL.md +35 -20
  16. package/skills/06-next/references/recommendation-logic.md +47 -2
  17. package/skills/07-worktree/SKILL.md +21 -20
  18. package/skills/08-help/SKILL.md +46 -0
  19. package/skills/08-help/references/workflow-sequence.md +135 -0
  20. package/skills/references/language-detection.md +44 -0
  21. package/LICENSE +0 -21
  22. package/THIRD-PARTY-NOTICES.md +0 -35
  23. package/extensions/subagent/__tests__/async-job-tracker.test.ts +0 -21
  24. package/extensions/subagent/__tests__/execution-activity.test.ts +0 -15
  25. package/extensions/subagent/__tests__/parallel-render-stress.test.ts +0 -82
  26. package/extensions/subagent/__tests__/render-dedup.test.ts +0 -98
  27. package/extensions/subagent/__tests__/render-widget.test.ts +0 -28
  28. package/extensions/subagent/__tests__/throttle.test.ts +0 -90
  29. package/extensions/subagent/agent-management.ts +0 -596
  30. package/extensions/subagent/agent-manager-chain-detail.ts +0 -163
  31. package/extensions/subagent/agent-manager-detail.ts +0 -232
  32. package/extensions/subagent/agent-manager-edit.ts +0 -391
  33. package/extensions/subagent/agent-manager-list.ts +0 -279
  34. package/extensions/subagent/agent-manager-parallel.ts +0 -305
  35. package/extensions/subagent/agent-manager.ts +0 -706
  36. package/extensions/subagent/agent-scope.ts +0 -9
  37. package/extensions/subagent/agent-selection.ts +0 -26
  38. package/extensions/subagent/agent-serializer.ts +0 -124
  39. package/extensions/subagent/agent-templates.ts +0 -63
  40. package/extensions/subagent/agents/context-builder.md +0 -37
  41. package/extensions/subagent/agents/delegate.md +0 -9
  42. package/extensions/subagent/agents/oracle.md +0 -73
  43. package/extensions/subagent/agents/planner.md +0 -52
  44. package/extensions/subagent/agents/researcher.md +0 -50
  45. package/extensions/subagent/agents/reviewer.md +0 -38
  46. package/extensions/subagent/agents/scout.md +0 -48
  47. package/extensions/subagent/agents/worker.md +0 -52
  48. package/extensions/subagent/agents.ts +0 -762
  49. package/extensions/subagent/artifacts.ts +0 -101
  50. package/extensions/subagent/async-execution.ts +0 -521
  51. package/extensions/subagent/async-job-tracker.ts +0 -240
  52. package/extensions/subagent/async-status.ts +0 -242
  53. package/extensions/subagent/chain-clarify.ts +0 -1365
  54. package/extensions/subagent/chain-execution.ts +0 -854
  55. package/extensions/subagent/chain-serializer.ts +0 -127
  56. package/extensions/subagent/completion-dedupe.ts +0 -66
  57. package/extensions/subagent/doctor.ts +0 -201
  58. package/extensions/subagent/execution.ts +0 -748
  59. package/extensions/subagent/file-coalescer.ts +0 -43
  60. package/extensions/subagent/fork-context.ts +0 -64
  61. package/extensions/subagent/formatters.ts +0 -123
  62. package/extensions/subagent/frontmatter.ts +0 -32
  63. package/extensions/subagent/index.ts +0 -586
  64. package/extensions/subagent/intercom-bridge.ts +0 -241
  65. package/extensions/subagent/jsonl-writer.ts +0 -84
  66. package/extensions/subagent/model-fallback.ts +0 -109
  67. package/extensions/subagent/notify.ts +0 -111
  68. package/extensions/subagent/parallel-utils.ts +0 -109
  69. package/extensions/subagent/pi-args.ts +0 -139
  70. package/extensions/subagent/pi-spawn.ts +0 -101
  71. package/extensions/subagent/post-exit-stdio-guard.ts +0 -88
  72. package/extensions/subagent/prompt-template-bridge.ts +0 -400
  73. package/extensions/subagent/prompts/gather-context-and-clarify.md +0 -13
  74. package/extensions/subagent/prompts/parallel-cleanup.md +0 -42
  75. package/extensions/subagent/prompts/parallel-research.md +0 -50
  76. package/extensions/subagent/prompts/parallel-review.md +0 -40
  77. package/extensions/subagent/render-helpers.ts +0 -83
  78. package/extensions/subagent/render.ts +0 -908
  79. package/extensions/subagent/result-intercom.ts +0 -238
  80. package/extensions/subagent/result-watcher.ts +0 -172
  81. package/extensions/subagent/run-history.ts +0 -58
  82. package/extensions/subagent/run-status.ts +0 -137
  83. package/extensions/subagent/schemas.ts +0 -165
  84. package/extensions/subagent/session-tokens.ts +0 -51
  85. package/extensions/subagent/settings.ts +0 -368
  86. package/extensions/subagent/single-output.ts +0 -98
  87. package/extensions/subagent/skills.ts +0 -627
  88. package/extensions/subagent/slash-bridge.ts +0 -177
  89. package/extensions/subagent/slash-commands.ts +0 -304
  90. package/extensions/subagent/slash-live-state.ts +0 -295
  91. package/extensions/subagent/subagent-control.ts +0 -151
  92. package/extensions/subagent/subagent-executor.ts +0 -1915
  93. package/extensions/subagent/subagent-prompt-runtime.ts +0 -76
  94. package/extensions/subagent/subagent-runner.ts +0 -1471
  95. package/extensions/subagent/subagents-status.ts +0 -473
  96. package/extensions/subagent/text-editor.ts +0 -273
  97. package/extensions/subagent/throttle.ts +0 -77
  98. package/extensions/subagent/top-level-async.ts +0 -16
  99. package/extensions/subagent/types.ts +0 -624
  100. package/extensions/subagent/utils.ts +0 -457
  101. package/extensions/subagent/worktree.ts +0 -580
  102. package/extensions/super-pi-extension/agents/ce-oracle.md +0 -109
  103. package/extensions/super-pi-extension/agents/ce-planner.md +0 -116
  104. package/extensions/super-pi-extension/agents/ce-reviewer.md +0 -99
  105. package/extensions/super-pi-extension/agents/ce-scout.md +0 -80
  106. package/extensions/super-pi-extension/agents/ce-worker.md +0 -78
  107. package/extensions/super-pi-extension/chains/ce-parallel-review.chain.md +0 -34
  108. package/extensions/super-pi-extension/chains/ce-review-only.chain.md +0 -12
  109. package/extensions/super-pi-extension/chains/ce-standard.chain.md +0 -28
  110. package/extensions/super-pi-extension/index.ts +0 -129
  111. package/extensions/super-pi-extension/model-sync.ts +0 -204
  112. package/skills/08-status/SKILL.md +0 -41
  113. package/skills/08-status/references/artifact-locations.md +0 -10
  114. package/skills/09-help/SKILL.md +0 -37
  115. package/skills/09-help/references/workflow-sequence.md +0 -9
  116. package/skills/10-rules/SKILL.md +0 -76
  117. package/skills/pi-subagents/SKILL.md +0 -566
@@ -1,279 +0,0 @@
1
- // SPDX-FileCopyrightText: 2025 Nico Bailon
2
- // SPDX-License-Identifier: MIT
3
- // Source: https://github.com/nicobailon/pi-subagents
4
- import type { Theme } from "@mariozechner/pi-coding-agent";
5
- import type { AgentSource } from "./agents.ts";
6
- import { matchesKey, truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
7
- import { pad, row, renderHeader, renderFooter, fuzzyFilter, formatScrollInfo } from "./render-helpers.ts";
8
-
9
- export interface ListAgent {
10
- id: string;
11
- name: string;
12
- description: string;
13
- model?: string;
14
- source: AgentSource;
15
- overrideScope?: "user" | "project";
16
- disabled?: boolean;
17
- kind: "agent" | "chain";
18
- stepCount?: number;
19
- }
20
-
21
- export interface ListState {
22
- cursor: number;
23
- scrollOffset: number;
24
- filterQuery: string;
25
- selected: string[];
26
- }
27
-
28
- export type ListAction =
29
- | { type: "open-detail"; id: string }
30
- | { type: "clone"; id: string }
31
- | { type: "new" }
32
- | { type: "delete"; id: string }
33
- | { type: "run-chain"; ids: string[] }
34
- | { type: "run-parallel"; ids: string[] }
35
- | { type: "close" };
36
-
37
- const LIST_VIEWPORT_HEIGHT = 8;
38
-
39
- function selectionCount(selected: string[], id: string): number {
40
- let count = 0;
41
- for (const s of selected) if (s === id) count++;
42
- return count;
43
- }
44
-
45
- function clampCursor(state: ListState, filtered: ListAgent[]): void {
46
- if (filtered.length === 0) {
47
- state.cursor = 0;
48
- state.scrollOffset = 0;
49
- return;
50
- }
51
-
52
- state.cursor = Math.max(0, Math.min(state.cursor, filtered.length - 1));
53
- const maxOffset = Math.max(0, filtered.length - LIST_VIEWPORT_HEIGHT);
54
- state.scrollOffset = Math.max(0, Math.min(state.scrollOffset, maxOffset));
55
-
56
- if (state.cursor < state.scrollOffset) {
57
- state.scrollOffset = state.cursor;
58
- } else if (state.cursor >= state.scrollOffset + LIST_VIEWPORT_HEIGHT) {
59
- state.scrollOffset = state.cursor - LIST_VIEWPORT_HEIGHT + 1;
60
- }
61
- }
62
-
63
- export function handleListInput(state: ListState, agents: ListAgent[], data: string): ListAction | undefined {
64
- const filtered = fuzzyFilter(agents, state.filterQuery);
65
-
66
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
67
- if (state.filterQuery.length > 0) {
68
- state.filterQuery = "";
69
- state.cursor = 0;
70
- state.scrollOffset = 0;
71
- return;
72
- }
73
- if (state.selected.length > 0) {
74
- state.selected.length = 0;
75
- return;
76
- }
77
- return { type: "close" };
78
- }
79
-
80
- if (matchesKey(data, "return")) {
81
- if (filtered.length > 0) {
82
- const agent = filtered[state.cursor];
83
- if (agent) return { type: "open-detail", id: agent.id };
84
- }
85
- return;
86
- }
87
-
88
- if (matchesKey(data, "up") || matchesKey(data, "down")) {
89
- if (matchesKey(data, "up")) state.cursor -= 1;
90
- if (matchesKey(data, "down")) state.cursor += 1;
91
- clampCursor(state, filtered);
92
- return;
93
- }
94
-
95
- if (matchesKey(data, "backspace")) {
96
- if (state.filterQuery.length > 0) {
97
- state.filterQuery = state.filterQuery.slice(0, -1);
98
- state.cursor = 0;
99
- state.scrollOffset = 0;
100
- }
101
- return;
102
- }
103
-
104
- if (matchesKey(data, "alt+n")) {
105
- return { type: "new" };
106
- }
107
-
108
- if (matchesKey(data, "ctrl+k")) {
109
- const agent = filtered[state.cursor];
110
- if (agent) return { type: "clone", id: agent.id };
111
- return;
112
- }
113
-
114
- if (matchesKey(data, "ctrl+d") || matchesKey(data, "delete")) {
115
- const agent = filtered[state.cursor];
116
- if (agent) return { type: "delete", id: agent.id };
117
- return;
118
- }
119
-
120
- if (matchesKey(data, "tab")) {
121
- const agent = filtered[state.cursor];
122
- if (!agent) return;
123
- if (agent.kind !== "agent") return;
124
- state.selected.push(agent.id);
125
- return;
126
- }
127
-
128
- if (matchesKey(data, "shift+tab")) {
129
- const agent = filtered[state.cursor];
130
- if (!agent) return;
131
- const lastIdx = state.selected.lastIndexOf(agent.id);
132
- if (lastIdx >= 0) state.selected.splice(lastIdx, 1);
133
- return;
134
- }
135
-
136
- if (matchesKey(data, "ctrl+r")) {
137
- if (state.selected.length > 0) return { type: "run-chain", ids: [...state.selected] };
138
- const agent = filtered[state.cursor];
139
- if (agent && agent.kind === "agent") return { type: "run-chain", ids: [agent.id] };
140
- return;
141
- }
142
-
143
- if (matchesKey(data, "ctrl+p")) {
144
- if (state.selected.length > 0) return { type: "run-parallel", ids: [...state.selected] };
145
- const agent = filtered[state.cursor];
146
- if (agent && agent.kind === "agent") return { type: "run-parallel", ids: [agent.id] };
147
- return;
148
- }
149
-
150
- if (data.length === 1 && data.charCodeAt(0) >= 32) {
151
- state.filterQuery += data;
152
- state.cursor = 0;
153
- state.scrollOffset = 0;
154
- return;
155
- }
156
-
157
- return;
158
- }
159
-
160
- export function renderList(
161
- state: ListState,
162
- agents: ListAgent[],
163
- width: number,
164
- theme: Theme,
165
- statusMessage?: { text: string; type: "error" | "info" },
166
- ): string[] {
167
- const lines: string[] = [];
168
- const filtered = fuzzyFilter(agents, state.filterQuery);
169
- clampCursor(state, filtered);
170
-
171
- const agentCount = agents.filter((a) => a.kind === "agent").length;
172
- const chainCount = agents.filter((a) => a.kind === "chain").length;
173
- const headerText = chainCount
174
- ? ` Subagents [${agentCount} agents ${chainCount} chains] `
175
- : ` Subagents [${agentCount}] `;
176
- lines.push(renderHeader(headerText, width, theme));
177
- lines.push(row("", width, theme));
178
-
179
- const cursor = theme.fg("accent", "│");
180
- const searchIcon = theme.fg("dim", "◎");
181
- const placeholder = theme.fg("dim", "\x1b[3mtype to filter...\x1b[23m");
182
- const queryDisplay = state.filterQuery ? `${state.filterQuery}${cursor}` : `${cursor}${placeholder}`;
183
- lines.push(row(` ${searchIcon} ${queryDisplay}`, width, theme));
184
- lines.push(row("", width, theme));
185
-
186
- const userNames = new Set(agents.filter((a) => a.source === "user" && a.kind === "agent").map((a) => a.name));
187
- const startIdx = state.scrollOffset;
188
- const endIdx = Math.min(filtered.length, startIdx + LIST_VIEWPORT_HEIGHT);
189
- const visible = filtered.slice(startIdx, endIdx);
190
-
191
- if (filtered.length === 0) {
192
- lines.push(row(` ${theme.fg("dim", "No matching agents")}`, width, theme));
193
- for (let i = 1; i < LIST_VIEWPORT_HEIGHT; i++) lines.push(row("", width, theme));
194
- } else {
195
- const innerW = width - 2;
196
- const nameWidth = 16;
197
- const modelWidth = 12;
198
- const scopeWidth = 21;
199
-
200
- for (let i = 0; i < visible.length; i++) {
201
- const agent = visible[i]!;
202
- const index = startIdx + i;
203
- const isCursor = index === state.cursor;
204
- const count = selectionCount(state.selected, agent.id);
205
- const isShadowed = agent.kind === "agent" && agent.source === "project" && userNames.has(agent.name);
206
-
207
- const cursorChar = isCursor ? theme.fg("accent", ">") : " ";
208
- const selectBadge = count > 0 ? theme.fg("accent", String(count).padStart(2)) : " ";
209
- const shadowMarker = isShadowed ? theme.fg("warning", "!") : " ";
210
- const prefix = `${cursorChar}${selectBadge}${shadowMarker} `;
211
-
212
- const modelRaw = agent.kind === "chain" ? `${agent.stepCount ?? 0} steps` : (agent.model ?? "default");
213
- const modelDisplay = modelRaw.includes("/") ? modelRaw.split("/").pop() ?? modelRaw : modelRaw;
214
- const nameText = isCursor ? theme.fg("accent", agent.name) : agent.name;
215
- const modelText = theme.fg("dim", modelDisplay);
216
- const scopeLabel = agent.kind === "chain"
217
- ? "[chain]"
218
- : agent.source === "builtin"
219
- ? (agent.disabled
220
- ? (agent.overrideScope ? `[builtin off+${agent.overrideScope}]` : "[builtin off]")
221
- : (agent.overrideScope ? `[builtin+${agent.overrideScope}]` : "[builtin]"))
222
- : agent.source === "project"
223
- ? "[proj]"
224
- : "[user]";
225
- const scopeBadge = theme.fg("dim", scopeLabel);
226
- const descText = theme.fg("dim", agent.description);
227
-
228
- const descWidth = Math.max(0, innerW - 1 - visibleWidth(prefix) - nameWidth - modelWidth - scopeWidth - 3);
229
- const line =
230
- prefix +
231
- pad(truncateToWidth(nameText, nameWidth), nameWidth) +
232
- " " +
233
- pad(truncateToWidth(modelText, modelWidth), modelWidth) +
234
- " " +
235
- pad(scopeBadge, scopeWidth) +
236
- " " +
237
- truncateToWidth(descText, descWidth);
238
-
239
- lines.push(row(` ${line}`, width, theme));
240
- }
241
-
242
- for (let i = visible.length; i < LIST_VIEWPORT_HEIGHT; i++) {
243
- lines.push(row("", width, theme));
244
- }
245
- }
246
-
247
- const scrollInfo = formatScrollInfo(state.scrollOffset, Math.max(0, filtered.length - (state.scrollOffset + LIST_VIEWPORT_HEIGHT)));
248
- const selectedNames = state.selected
249
- .map((id) => agents.find((a) => a.id === id))
250
- .filter((a): a is ListAgent => Boolean(a))
251
- .map((a) => a.name);
252
- const preview = selectedNames.length > 0 ? truncateToWidth(selectedNames.join(" → "), width - 4) : "";
253
-
254
- lines.push(row("", width, theme));
255
-
256
- if (statusMessage) {
257
- const color = statusMessage.type === "error" ? "error" : "success";
258
- lines.push(row(` ${theme.fg(color, truncateToWidth(statusMessage.text, width - 4))}`, width, theme));
259
- } else if (preview) {
260
- lines.push(row(` ${theme.fg("dim", preview)}`, width, theme));
261
- } else {
262
- const cursorAgent = filtered[state.cursor];
263
- const desc = cursorAgent ? truncateToWidth(cursorAgent.description, width - 4) : "";
264
- const content = desc || scrollInfo;
265
- lines.push(row(content ? ` ${theme.fg("dim", content)}` : "", width, theme));
266
- }
267
-
268
- lines.push(row("", width, theme));
269
-
270
- const selCount = state.selected.length;
271
- const footerText = selCount > 1
272
- ? ` [ctrl+r] chain [ctrl+p] parallel [tab] add [shift+tab] remove [esc] clear (${selCount}) `
273
- : selCount === 1
274
- ? " [ctrl+r] run [ctrl+p] parallel [tab] add more [shift+tab] remove [esc] clear "
275
- : " [enter] view [ctrl+r] run [tab] select [alt+n] new [esc] close ";
276
- lines.push(renderFooter(footerText, width, theme));
277
-
278
- return lines;
279
- }
@@ -1,305 +0,0 @@
1
- // SPDX-FileCopyrightText: 2025 Nico Bailon
2
- // SPDX-License-Identifier: MIT
3
- // Source: https://github.com/nicobailon/pi-subagents
4
- import type { Theme } from "@mariozechner/pi-coding-agent";
5
- import { matchesKey, truncateToWidth, visibleWidth } from "@mariozechner/pi-tui";
6
- import type { TextEditorState } from "./text-editor.ts";
7
- import { createEditorState, handleEditorInput, renderEditor, wrapText, getCursorDisplayPos, ensureCursorVisible } from "./text-editor.ts";
8
- import { pad, row, renderHeader, renderFooter, fuzzyFilter } from "./render-helpers.ts";
9
-
10
- export interface ParallelSlot {
11
- agentName: string;
12
- customTask: string;
13
- }
14
-
15
- export interface ParallelState {
16
- slots: ParallelSlot[];
17
- cursor: number;
18
- scrollOffset: number;
19
- mode: "browse" | "add" | "edit-task";
20
- addQuery: string;
21
- addCursor: number;
22
- editIndex: number;
23
- editEditor: TextEditorState | null;
24
- }
25
-
26
- export type ParallelAction =
27
- | { type: "proceed" }
28
- | { type: "back" };
29
-
30
- export interface AgentOption {
31
- name: string;
32
- description: string;
33
- model?: string;
34
- }
35
-
36
- const CONTENT_HEIGHT = 14;
37
- const SLOT_VIEWPORT_BROWSE = 12;
38
- const SLOT_VIEWPORT_COMPACT = 5;
39
- const ADD_RESULTS_MAX = 5;
40
-
41
- export function createParallelState(agentNames: string[]): ParallelState {
42
- return {
43
- slots: agentNames.map((name) => ({ agentName: name, customTask: "" })),
44
- cursor: 0,
45
- scrollOffset: 0,
46
- mode: "browse",
47
- addQuery: "",
48
- addCursor: 0,
49
- editIndex: -1,
50
- editEditor: null,
51
- };
52
- }
53
-
54
- function clampSlotScroll(state: ParallelState, viewport: number): void {
55
- if (state.slots.length === 0) { state.cursor = 0; state.scrollOffset = 0; return; }
56
- state.cursor = Math.max(0, Math.min(state.cursor, state.slots.length - 1));
57
- const maxOffset = Math.max(0, state.slots.length - viewport);
58
- state.scrollOffset = Math.max(0, Math.min(state.scrollOffset, maxOffset));
59
- if (state.cursor < state.scrollOffset) state.scrollOffset = state.cursor;
60
- else if (state.cursor >= state.scrollOffset + viewport) state.scrollOffset = state.cursor - viewport + 1;
61
- }
62
-
63
- export function handleParallelInput(
64
- state: ParallelState,
65
- agents: AgentOption[],
66
- data: string,
67
- width: number,
68
- ): ParallelAction | undefined {
69
- switch (state.mode) {
70
- case "browse": return handleBrowse(state, data);
71
- case "add": return handleAdd(state, agents, data);
72
- case "edit-task": return handleEditTask(state, data, width);
73
- }
74
- }
75
-
76
- function handleBrowse(state: ParallelState, data: string): ParallelAction | undefined {
77
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) return { type: "back" };
78
- if (matchesKey(data, "up")) { state.cursor = Math.max(0, state.cursor - 1); clampSlotScroll(state, SLOT_VIEWPORT_BROWSE); return; }
79
- if (matchesKey(data, "down")) { state.cursor = Math.min(state.slots.length - 1, state.cursor + 1); clampSlotScroll(state, SLOT_VIEWPORT_BROWSE); return; }
80
-
81
- if (matchesKey(data, "ctrl+a")) {
82
- state.mode = "add";
83
- state.addQuery = "";
84
- state.addCursor = 0;
85
- return;
86
- }
87
-
88
- if (matchesKey(data, "delete") || matchesKey(data, "ctrl+d")) {
89
- if (state.slots.length > 1) {
90
- state.slots.splice(state.cursor, 1);
91
- state.cursor = Math.min(state.cursor, state.slots.length - 1);
92
- clampSlotScroll(state, SLOT_VIEWPORT_BROWSE);
93
- }
94
- return;
95
- }
96
-
97
- if (matchesKey(data, "return")) {
98
- if (state.slots.length === 0) return;
99
- state.mode = "edit-task";
100
- state.editIndex = state.cursor;
101
- state.editEditor = createEditorState(state.slots[state.cursor]!.customTask);
102
- return;
103
- }
104
-
105
- if (matchesKey(data, "ctrl+r")) {
106
- if (state.slots.length >= 2) return { type: "proceed" };
107
- return;
108
- }
109
-
110
- return;
111
- }
112
-
113
- function handleAdd(state: ParallelState, agents: AgentOption[], data: string): ParallelAction | undefined {
114
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) { state.mode = "browse"; return; }
115
-
116
- const filtered = fuzzyFilter(agents, state.addQuery);
117
-
118
- if (matchesKey(data, "up")) { state.addCursor = Math.max(0, state.addCursor - 1); return; }
119
- if (matchesKey(data, "down")) { state.addCursor = Math.min(Math.max(0, filtered.length - 1), state.addCursor + 1); return; }
120
-
121
- if (matchesKey(data, "return")) {
122
- const selected = filtered[state.addCursor];
123
- if (selected) {
124
- state.slots.push({ agentName: selected.name, customTask: "" });
125
- state.cursor = state.slots.length - 1;
126
- clampSlotScroll(state, SLOT_VIEWPORT_BROWSE);
127
- }
128
- state.mode = "browse";
129
- return;
130
- }
131
-
132
- if (matchesKey(data, "backspace")) {
133
- state.addQuery = state.addQuery.slice(0, -1);
134
- state.addCursor = 0;
135
- return;
136
- }
137
-
138
- if (data.length === 1 && data.charCodeAt(0) >= 32) {
139
- state.addQuery += data;
140
- state.addCursor = 0;
141
- return;
142
- }
143
-
144
- return;
145
- }
146
-
147
- function handleEditTask(state: ParallelState, data: string, width: number): ParallelAction | undefined {
148
- if (!state.editEditor) { state.mode = "browse"; return; }
149
-
150
- if (matchesKey(data, "escape") || matchesKey(data, "ctrl+c")) {
151
- state.editEditor = null;
152
- state.mode = "browse";
153
- return;
154
- }
155
-
156
- if (matchesKey(data, "return")) {
157
- const slot = state.slots[state.editIndex];
158
- if (slot) slot.customTask = state.editEditor.buffer.trim();
159
- state.editEditor = null;
160
- state.mode = "browse";
161
- return;
162
- }
163
-
164
- if (matchesKey(data, "tab")) return;
165
-
166
- const innerW = width - 2;
167
- const boxInnerWidth = Math.max(10, innerW - 4);
168
- const nextState = handleEditorInput(state.editEditor, data, boxInnerWidth);
169
- if (nextState) state.editEditor = nextState;
170
- return;
171
- }
172
-
173
- function renderSlotLine(
174
- slot: ParallelSlot,
175
- slotNumber: number,
176
- isCursor: boolean,
177
- width: number,
178
- theme: Theme,
179
- ): string {
180
- const cursor = isCursor ? theme.fg("accent", "▸") : " ";
181
- const num = theme.fg("accent", slotNumber.toString().padStart(2));
182
- const name = isCursor ? theme.fg("accent", slot.agentName) : slot.agentName;
183
- const nameWidth = 16;
184
- const prefix = `${cursor} ${num} `;
185
- const prefixVis = visibleWidth(prefix);
186
- const nameStr = pad(truncateToWidth(name, nameWidth), nameWidth);
187
-
188
- if (slot.customTask) {
189
- const taskWidth = Math.max(0, width - 2 - prefixVis - nameWidth - 3);
190
- const taskPreview = theme.fg("dim", `"${truncateToWidth(slot.customTask, Math.max(0, taskWidth - 2))}"`);
191
- return ` ${prefix}${nameStr} ${taskPreview}`;
192
- }
193
- return ` ${prefix}${nameStr}`;
194
- }
195
-
196
- export function renderParallel(
197
- state: ParallelState,
198
- agents: AgentOption[],
199
- width: number,
200
- theme: Theme,
201
- ): string[] {
202
- const lines: string[] = [];
203
- lines.push(renderHeader(" Parallel Builder ", width, theme));
204
- lines.push(row("", width, theme));
205
-
206
- const contentLines: string[] = [];
207
-
208
- if (state.mode === "browse") {
209
- clampSlotScroll(state, SLOT_VIEWPORT_BROWSE);
210
- const start = state.scrollOffset;
211
- const end = Math.min(state.slots.length, start + SLOT_VIEWPORT_BROWSE);
212
- for (let i = start; i < end; i++) {
213
- contentLines.push(renderSlotLine(state.slots[i]!, i + 1, i === state.cursor, width, theme));
214
- }
215
- } else if (state.mode === "add") {
216
- const slotLines = Math.min(state.slots.length, SLOT_VIEWPORT_COMPACT);
217
- const slotStart = Math.max(0, state.slots.length - slotLines);
218
- for (let i = slotStart; i < state.slots.length; i++) {
219
- contentLines.push(renderSlotLine(state.slots[i]!, i + 1, false, width, theme));
220
- }
221
- contentLines.push("");
222
-
223
- const searchIcon = theme.fg("dim", "◎");
224
- const cursor = theme.fg("accent", "│");
225
- const placeholder = theme.fg("dim", "\x1b[3msearch agents...\x1b[23m");
226
- const queryDisplay = state.addQuery ? `${state.addQuery}${cursor}` : `${cursor}${placeholder}`;
227
- contentLines.push(` ${searchIcon} ${queryDisplay}`);
228
-
229
- const filtered = fuzzyFilter(agents, state.addQuery);
230
- const addStart = Math.max(0, Math.min(state.addCursor - ADD_RESULTS_MAX + 1, filtered.length - ADD_RESULTS_MAX));
231
- const addEnd = Math.min(filtered.length, addStart + ADD_RESULTS_MAX);
232
- for (let i = addStart; i < addEnd; i++) {
233
- const a = filtered[i]!;
234
- const isCursor = i === state.addCursor;
235
- const cur = isCursor ? theme.fg("accent", "▸") : " ";
236
- const nameStr = isCursor ? theme.fg("accent", a.name) : a.name;
237
- const descWidth = Math.max(0, width - 2 - 1 - 1 - 16 - 2);
238
- contentLines.push(` ${cur} ${pad(truncateToWidth(nameStr, 16), 16)} ${theme.fg("dim", truncateToWidth(a.description, descWidth))}`);
239
- }
240
- } else if (state.mode === "edit-task") {
241
- const slotLines = Math.min(state.slots.length, SLOT_VIEWPORT_COMPACT);
242
- const slotStart = Math.max(0, Math.min(state.editIndex - Math.floor(slotLines / 2), state.slots.length - slotLines));
243
- for (let i = slotStart; i < slotStart + slotLines; i++) {
244
- contentLines.push(renderSlotLine(state.slots[i]!, i + 1, i === state.editIndex, width, theme));
245
- }
246
- contentLines.push("");
247
-
248
- const slot = state.slots[state.editIndex];
249
- const label = slot ? `Task for ${slot.agentName} (slot ${state.editIndex + 1}):` : "Task:";
250
- contentLines.push(` ${theme.fg("dim", label)}`);
251
-
252
- const innerW = width - 2;
253
- const boxInnerWidth = Math.max(10, innerW - 4);
254
- contentLines.push(` \u250C${"\u2500".repeat(boxInnerWidth)}\u2510`);
255
-
256
- if (state.editEditor) {
257
- const editorState = { ...state.editEditor };
258
- const wrapped = wrapText(editorState.buffer, boxInnerWidth);
259
- const cursorPos = getCursorDisplayPos(editorState.cursor, wrapped.starts);
260
- editorState.viewportOffset = ensureCursorVisible(cursorPos.line, 1, editorState.viewportOffset);
261
- const editorLine = renderEditor(editorState, boxInnerWidth, 1)[0] ?? "";
262
- contentLines.push(` \u2502${pad(editorLine, boxInnerWidth)}\u2502`);
263
- } else {
264
- contentLines.push(` \u2502${pad("", boxInnerWidth)}\u2502`);
265
- }
266
-
267
- contentLines.push(` \u2514${"\u2500".repeat(boxInnerWidth)}\u2518`);
268
- contentLines.push(` ${theme.fg("dim", "Empty = use shared task")}`);
269
- }
270
-
271
- for (const line of contentLines) lines.push(row(line, width, theme));
272
- for (let i = contentLines.length; i < CONTENT_HEIGHT; i++) lines.push(row("", width, theme));
273
-
274
- let statusText = "";
275
- if (state.mode === "browse") {
276
- if (state.slots.length < 2) {
277
- statusText = theme.fg("dim", `${state.slots.length} agent — add at least 2 for parallel`);
278
- } else {
279
- statusText = theme.fg("dim", formatSlotSummary(state.slots));
280
- }
281
- }
282
- lines.push(row(statusText ? ` ${statusText}` : "", width, theme));
283
-
284
- let footerText: string;
285
- if (state.mode === "add") {
286
- footerText = " [enter] add [esc] cancel ";
287
- } else if (state.mode === "edit-task") {
288
- footerText = " [enter] save [esc] cancel ";
289
- } else {
290
- footerText = " [ctrl+a] add [del] remove [enter] edit task [ctrl+r] continue [esc] back ";
291
- }
292
- lines.push(renderFooter(footerText, width, theme));
293
-
294
- return lines;
295
- }
296
-
297
- function formatSlotSummary(slots: ParallelSlot[]): string {
298
- const counts = new Map<string, number>();
299
- for (const s of slots) counts.set(s.agentName, (counts.get(s.agentName) ?? 0) + 1);
300
- return [...counts.entries()].map(([name, count]) => count > 1 ? `${count}\u00D7 ${name}` : name).join(" + ");
301
- }
302
-
303
- export function formatParallelTitle(slots: ParallelSlot[]): string {
304
- return `Parallel: ${formatSlotSummary(slots)}`;
305
- }