@xynogen/pix-core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/package.json +42 -0
- package/skills/ask-user/SKILL.md +48 -0
- package/src/commands/clear/clear.ts +32 -0
- package/src/commands/copy-all/copy-all.ts +89 -0
- package/src/commands/diff/diff.ts +138 -0
- package/src/commands/lg/lg.ts +32 -0
- package/src/commands/models/models.test.ts +95 -0
- package/src/commands/models/models.ts +362 -0
- package/src/commands/tools.test.ts +15 -0
- package/src/commands/update/update.test.ts +112 -0
- package/src/commands/update/update.ts +271 -0
- package/src/commands/yeet/yeet.ts +29 -0
- package/src/index.ts +49 -0
- package/src/lib/data.ts +241 -0
- package/src/nudge/capability.test.ts +198 -0
- package/src/nudge/capability.ts +152 -0
- package/src/nudge/index.ts +17 -0
- package/src/nudge/tools.test.ts +145 -0
- package/src/nudge/tools.ts +214 -0
- package/src/tool/ask/ask.test.ts +232 -0
- package/src/tool/ask/ask.ts +1081 -0
- package/src/tool/ask/single-select-layout.test.ts +108 -0
- package/src/tool/ask/single-select-layout.ts +203 -0
- package/src/tool/todo/todo.test.ts +602 -0
- package/src/tool/todo/todo.ts +194 -0
- package/src/tool/toolbox/toolbox.test.ts +312 -0
- package/src/tool/toolbox/toolbox.ts +563 -0
- package/src/ui/diagnostics.ts +148 -0
- package/src/ui/footer.ts +513 -0
- package/src/ui/welcome.test.ts +124 -0
- package/src/ui/welcome.ts +369 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { renderSingleSelectRows } from "./single-select-layout";
|
|
3
|
+
|
|
4
|
+
describe("renderSingleSelectRows", () => {
|
|
5
|
+
test("wraps long option titles instead of truncating them away", () => {
|
|
6
|
+
const rows = renderSingleSelectRows({
|
|
7
|
+
options: [
|
|
8
|
+
{
|
|
9
|
+
title:
|
|
10
|
+
"I want help with a coding or implementation task that involves changing, creating, reviewing, refactoring, or understanding code in a project",
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
selectedIndex: 0,
|
|
14
|
+
width: 40,
|
|
15
|
+
allowFreeform: false,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
expect(rows.length).toBeGreaterThan(1);
|
|
19
|
+
expect(rows.map((r) => r.line).join(" ")).toContain("implementation task");
|
|
20
|
+
expect(rows.map((r) => r.line).join(" ")).toContain("understanding code");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("wraps long descriptions under their option instead of clipping them", () => {
|
|
24
|
+
const rows = renderSingleSelectRows({
|
|
25
|
+
options: [
|
|
26
|
+
{
|
|
27
|
+
title: "Planning help",
|
|
28
|
+
description:
|
|
29
|
+
"Choose this if you are still deciding what to do, want a plan first, need architecture guidance, or want to evaluate alternatives before touching code.",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
selectedIndex: 0,
|
|
33
|
+
width: 44,
|
|
34
|
+
allowFreeform: false,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const rendered = rows.map((r) => r.line).join(" ").replace(/\s+/g, " ").trim();
|
|
38
|
+
expect(rendered).toContain("want a plan first");
|
|
39
|
+
expect(rendered).toContain("before touching code");
|
|
40
|
+
expect(rows.length).toBeGreaterThan(2);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("caps the rendered rows and keeps the selected option visible when content is taller than the viewport", () => {
|
|
44
|
+
const rows = renderSingleSelectRows({
|
|
45
|
+
options: [
|
|
46
|
+
{
|
|
47
|
+
title:
|
|
48
|
+
"I want help with a coding or implementation task that involves changing, creating, reviewing, refactoring, or understanding code in a project",
|
|
49
|
+
description:
|
|
50
|
+
"Choose this if your main goal is to build something, fix code, understand existing code, add a feature, improve architecture, write tests, or get help with development work.",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
title:
|
|
54
|
+
"I want help troubleshooting, debugging, diagnosing, reproducing, isolating, or explaining a bug, failure, regression, flaky test, unexpected behavior, runtime error, build issue, deployment problem, configuration mistake, performance bottleneck, or environment-specific issue",
|
|
55
|
+
description:
|
|
56
|
+
"Choose this if something is broken, inconsistent, failing, slow, confusing, or behaving differently than expected and you want systematic help narrowing it down.",
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
selectedIndex: 1,
|
|
60
|
+
width: 44,
|
|
61
|
+
allowFreeform: false,
|
|
62
|
+
maxRows: 6,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
expect(rows.length).toBeLessThanOrEqual(6);
|
|
66
|
+
expect(rows.map((r) => r.line).join(" ").replace(/\s+/g, " ")).toContain("troubleshooting");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("does not duplicate a short word after wrapping an exact-width long word", () => {
|
|
70
|
+
const rows = renderSingleSelectRows({
|
|
71
|
+
options: [
|
|
72
|
+
{
|
|
73
|
+
title: "Alpha",
|
|
74
|
+
description: "hi aaaaaaaaaaaaaaaa",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
selectedIndex: 0,
|
|
78
|
+
width: 12,
|
|
79
|
+
allowFreeform: false,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(rows.map((r) => r.line).filter((line) => line.trim() === "hi")).toHaveLength(1);
|
|
83
|
+
expect(rows.map((r) => r.line).filter((line) => line.trim() === "aaaaaaaa")).toHaveLength(2);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("marks selected item rows as selected in annotated output", () => {
|
|
87
|
+
const rows = renderSingleSelectRows({
|
|
88
|
+
options: [
|
|
89
|
+
{ title: "Alpha" },
|
|
90
|
+
{ title: "Beta with a very long title that should wrap to multiple lines when rendered" },
|
|
91
|
+
{ title: "Gamma" },
|
|
92
|
+
],
|
|
93
|
+
selectedIndex: 1,
|
|
94
|
+
width: 30,
|
|
95
|
+
allowFreeform: false,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const selectedRows = rows.filter((r) => r.selected);
|
|
99
|
+
const nonSelectedRows = rows.filter((r) => !r.selected);
|
|
100
|
+
|
|
101
|
+
expect(selectedRows.length).toBeGreaterThan(1);
|
|
102
|
+
for (const row of selectedRows) {
|
|
103
|
+
expect(row.line).not.toContain("Alpha");
|
|
104
|
+
expect(row.line).not.toContain("Gamma");
|
|
105
|
+
}
|
|
106
|
+
expect(nonSelectedRows.length).toBeGreaterThan(0);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
export interface QuestionOption {
|
|
2
|
+
title: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface AnnotatedRow {
|
|
7
|
+
line: string;
|
|
8
|
+
selected: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface RenderSingleSelectRowsParams {
|
|
12
|
+
options: QuestionOption[];
|
|
13
|
+
selectedIndex: number;
|
|
14
|
+
width: number;
|
|
15
|
+
allowFreeform: boolean;
|
|
16
|
+
allowComment?: boolean;
|
|
17
|
+
commentEnabled?: boolean;
|
|
18
|
+
maxRows?: number;
|
|
19
|
+
hideDescriptions?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function wrapText(text: string, width: number): string[] {
|
|
23
|
+
const normalized = text.replace(/\s+/g, " ").trim();
|
|
24
|
+
if (!normalized) return [""];
|
|
25
|
+
if (width <= 1) return normalized.split("");
|
|
26
|
+
|
|
27
|
+
const words = normalized.split(" ");
|
|
28
|
+
const lines: string[] = [];
|
|
29
|
+
let current = "";
|
|
30
|
+
|
|
31
|
+
for (const word of words) {
|
|
32
|
+
if (!current) {
|
|
33
|
+
if (word.length <= width) {
|
|
34
|
+
current = word;
|
|
35
|
+
} else {
|
|
36
|
+
for (let i = 0; i < word.length; i += width) {
|
|
37
|
+
lines.push(word.slice(i, i + width));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const candidate = `${current} ${word}`;
|
|
44
|
+
if (candidate.length <= width) {
|
|
45
|
+
current = candidate;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
lines.push(current);
|
|
50
|
+
if (word.length <= width) {
|
|
51
|
+
current = word;
|
|
52
|
+
} else {
|
|
53
|
+
current = "";
|
|
54
|
+
for (let i = 0; i < word.length; i += width) {
|
|
55
|
+
const chunk = word.slice(i, i + width);
|
|
56
|
+
if (chunk.length === width || i + width < word.length) lines.push(chunk);
|
|
57
|
+
else current = chunk;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (current) lines.push(current);
|
|
63
|
+
return lines;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function padLine(prefix: string, content: string): string {
|
|
67
|
+
return `${prefix}${content}`.trimEnd();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface ItemBlock {
|
|
71
|
+
itemIndex: number;
|
|
72
|
+
lines: string[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type ListItem =
|
|
76
|
+
| { type: "option"; option: QuestionOption }
|
|
77
|
+
| { type: "comment-toggle"; option: QuestionOption }
|
|
78
|
+
| { type: "freeform"; option: QuestionOption };
|
|
79
|
+
|
|
80
|
+
function buildItemBlocks(
|
|
81
|
+
options: QuestionOption[],
|
|
82
|
+
width: number,
|
|
83
|
+
allowFreeform: boolean,
|
|
84
|
+
allowComment: boolean,
|
|
85
|
+
commentEnabled: boolean,
|
|
86
|
+
selectedIndex: number,
|
|
87
|
+
hideDescriptions = false,
|
|
88
|
+
): ItemBlock[] {
|
|
89
|
+
const normalizedWidth = Math.max(12, width);
|
|
90
|
+
const freeformLabel = "Type something. — Enter a custom response";
|
|
91
|
+
const commentToggleLabel = `${commentEnabled ? "[✓]" : "[ ]"} Add extra context after selection`;
|
|
92
|
+
const allItems: ListItem[] = options.map((option) => ({ type: "option", option }));
|
|
93
|
+
if (allowComment) {
|
|
94
|
+
allItems.push({ type: "comment-toggle", option: { title: commentToggleLabel } });
|
|
95
|
+
}
|
|
96
|
+
if (allowFreeform) {
|
|
97
|
+
allItems.push({ type: "freeform", option: { title: freeformLabel } });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return allItems.map((item, itemIndex) => {
|
|
101
|
+
const pointer = itemIndex === selectedIndex ? "→" : " ";
|
|
102
|
+
const lines: string[] = [];
|
|
103
|
+
|
|
104
|
+
if (item.type === "comment-toggle" || item.type === "freeform") {
|
|
105
|
+
const prefix = `${pointer} `;
|
|
106
|
+
const wrapped = wrapText(item.option.title, Math.max(8, normalizedWidth - prefix.length));
|
|
107
|
+
wrapped.forEach((line, lineIndex) => {
|
|
108
|
+
lines.push(padLine(lineIndex === 0 ? prefix : " ".repeat(prefix.length), line));
|
|
109
|
+
});
|
|
110
|
+
return { itemIndex, lines };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const numberPrefix = `${pointer} ${itemIndex + 1}. `;
|
|
114
|
+
const continuationPrefix = " ".repeat(numberPrefix.length);
|
|
115
|
+
const titleLines = wrapText(item.option.title, Math.max(8, normalizedWidth - numberPrefix.length));
|
|
116
|
+
titleLines.forEach((line, lineIndex) => {
|
|
117
|
+
lines.push(padLine(lineIndex === 0 ? numberPrefix : continuationPrefix, line));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
if (item.option.description && !hideDescriptions) {
|
|
121
|
+
const descriptionPrefix = " ";
|
|
122
|
+
const descriptionLines = wrapText(
|
|
123
|
+
item.option.description,
|
|
124
|
+
Math.max(8, normalizedWidth - descriptionPrefix.length),
|
|
125
|
+
);
|
|
126
|
+
descriptionLines.forEach((line) => {
|
|
127
|
+
lines.push(padLine(descriptionPrefix, line));
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return { itemIndex, lines };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function flatten(blocks: ItemBlock[], selectedIndex: number): AnnotatedRow[] {
|
|
136
|
+
return blocks.flatMap((block) =>
|
|
137
|
+
block.lines.map((line) => ({
|
|
138
|
+
line,
|
|
139
|
+
selected: block.itemIndex === selectedIndex,
|
|
140
|
+
})),
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function renderSingleSelectRows({
|
|
145
|
+
options,
|
|
146
|
+
selectedIndex,
|
|
147
|
+
width,
|
|
148
|
+
allowFreeform,
|
|
149
|
+
allowComment = false,
|
|
150
|
+
commentEnabled = false,
|
|
151
|
+
maxRows,
|
|
152
|
+
hideDescriptions,
|
|
153
|
+
}: RenderSingleSelectRowsParams): AnnotatedRow[] {
|
|
154
|
+
const itemCount = options.length + (allowComment ? 1 : 0) + (allowFreeform ? 1 : 0);
|
|
155
|
+
const blocks = buildItemBlocks(options, width, allowFreeform, allowComment, commentEnabled, selectedIndex, hideDescriptions);
|
|
156
|
+
const allRows = flatten(blocks, selectedIndex);
|
|
157
|
+
|
|
158
|
+
if (!Number.isFinite(maxRows) || !maxRows || maxRows <= 0 || allRows.length <= maxRows) {
|
|
159
|
+
return allRows;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const safeMaxRows = Math.max(1, Math.floor(maxRows));
|
|
163
|
+
const selectedBlock = blocks[selectedIndex] ?? blocks[0];
|
|
164
|
+
if (!selectedBlock) return [];
|
|
165
|
+
|
|
166
|
+
const indicator = ` (${selectedIndex + 1}/${itemCount})`;
|
|
167
|
+
const availableRows = safeMaxRows > 1 ? safeMaxRows - 1 : 1;
|
|
168
|
+
|
|
169
|
+
if (selectedBlock.lines.length >= availableRows) {
|
|
170
|
+
const visible = selectedBlock.lines.slice(0, availableRows).map((line) => ({
|
|
171
|
+
line,
|
|
172
|
+
selected: true,
|
|
173
|
+
}));
|
|
174
|
+
if (safeMaxRows > 1) visible.push({ line: indicator, selected: false });
|
|
175
|
+
return visible.slice(0, safeMaxRows);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
let start = selectedIndex;
|
|
179
|
+
let end = selectedIndex + 1;
|
|
180
|
+
let usedRows = selectedBlock.lines.length;
|
|
181
|
+
|
|
182
|
+
while (true) {
|
|
183
|
+
const nextCanFit = end < blocks.length && usedRows + blocks[end]!.lines.length <= availableRows;
|
|
184
|
+
if (nextCanFit) {
|
|
185
|
+
usedRows += blocks[end]!.lines.length;
|
|
186
|
+
end += 1;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const prevCanFit = start > 0 && usedRows + blocks[start - 1]!.lines.length <= availableRows;
|
|
191
|
+
if (prevCanFit) {
|
|
192
|
+
start -= 1;
|
|
193
|
+
usedRows += blocks[start]!.lines.length;
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const visible = flatten(blocks.slice(start, end), selectedIndex);
|
|
201
|
+
visible.push({ line: indicator, selected: false });
|
|
202
|
+
return visible.slice(0, safeMaxRows);
|
|
203
|
+
}
|