@leing2021/super-pi 0.22.0 → 0.23.0

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