loop-task 1.3.0 → 1.4.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 (43) hide show
  1. package/README.md +279 -195
  2. package/dist/board/App.js +225 -87
  3. package/dist/board/components/ActionButtons.js +28 -8
  4. package/dist/board/components/CreateForm.js +230 -70
  5. package/dist/board/components/CreateProjectModal.js +104 -0
  6. package/dist/board/components/DeleteProjectConfirm.js +53 -0
  7. package/dist/board/components/EditProjectModal.js +106 -0
  8. package/dist/board/components/FilterBar.js +5 -4
  9. package/dist/board/components/Footer.js +19 -6
  10. package/dist/board/components/Header.js +33 -3
  11. package/dist/board/components/HelpModal.js +11 -10
  12. package/dist/board/components/Inspector.js +1 -1
  13. package/dist/board/components/LogModal.js +39 -8
  14. package/dist/board/components/Navigator.js +30 -14
  15. package/dist/board/components/ProjectsModal.js +70 -0
  16. package/dist/board/components/ProjectsPage.js +105 -0
  17. package/dist/board/components/RunHistory.js +48 -9
  18. package/dist/board/components/TaskBrowser.js +96 -0
  19. package/dist/board/components/TaskFilterBar.js +6 -0
  20. package/dist/board/components/TaskForm.js +175 -0
  21. package/dist/board/daemon.js +56 -0
  22. package/dist/board/format.js +19 -12
  23. package/dist/board/hooks/useBoardKeybindings.js +264 -156
  24. package/dist/board/hooks/useTaskKeybindings.js +130 -0
  25. package/dist/board/router.js +16 -0
  26. package/dist/board/state.js +18 -14
  27. package/dist/cli.js +61 -6
  28. package/dist/client/commands.js +157 -1
  29. package/dist/config/constants.js +15 -0
  30. package/dist/config/paths.js +6 -0
  31. package/dist/core/command-runner.js +2 -0
  32. package/dist/core/foreground-loop.js +4 -1
  33. package/dist/core/loop-controller.js +210 -32
  34. package/dist/daemon/index.js +5 -2
  35. package/dist/daemon/manager.js +113 -34
  36. package/dist/daemon/projects.js +104 -0
  37. package/dist/daemon/server.js +177 -6
  38. package/dist/daemon/state.js +32 -1
  39. package/dist/daemon/task-manager.js +58 -0
  40. package/dist/i18n/en.json +140 -21
  41. package/dist/loop-config.js +13 -4
  42. package/dist/shared/clipboard.js +19 -0
  43. package/package.json +13 -3
@@ -5,75 +5,83 @@ import fs from "node:fs";
5
5
  import { buildLoopOptions, parseCommandLine } from "../../loop-config.js";
6
6
  import { t } from "../../i18n/index.js";
7
7
  import { commandLine } from "../format.js";
8
- import { createLoop, updateLoop } from "../daemon.js";
8
+ import { createLoop, updateLoop, listTasks } from "../daemon.js";
9
9
  import { useHoverState } from "../hooks/useHoverState.js";
10
10
  import { HOVER_BG } from "../../config/constants.js";
11
- export const createFields = ["interval", "command", "description", "cwd", "runNow", "maxRuns"];
12
- export function createInitialValues(loop) {
11
+ export const TASK_MODE_INLINE = "inline";
12
+ export const TASK_MODE_EXISTING = "existing";
13
+ export const createFields = ["interval", "taskMode", "command", "cwd", "taskId", "description", "runNow", "maxRuns", "project"];
14
+ export function createInitialValues(loop, currentProjectId) {
13
15
  if (!loop) {
14
16
  return {
15
17
  interval: "30m",
18
+ taskMode: TASK_MODE_INLINE,
16
19
  command: "",
17
- description: "",
18
20
  cwd: process.cwd(),
21
+ taskId: "",
22
+ description: "",
19
23
  runNow: "n",
20
24
  maxRuns: "",
25
+ project: currentProjectId ?? "default",
21
26
  };
22
27
  }
23
28
  return {
24
29
  interval: loop.intervalHuman,
30
+ taskMode: loop.taskId ? TASK_MODE_EXISTING : TASK_MODE_INLINE,
25
31
  command: commandLine(loop.command, loop.commandArgs),
26
- description: loop.description ?? "",
27
32
  cwd: loop.cwd ?? "",
33
+ taskId: loop.taskId ?? "",
34
+ description: loop.description ?? "",
28
35
  runNow: loop.immediate ? "y" : "n",
29
36
  maxRuns: loop.maxRuns !== null ? String(loop.maxRuns) : "",
37
+ project: loop.projectId ?? currentProjectId ?? "default",
30
38
  };
31
39
  }
32
40
  export function CreateView(props) {
33
- const fields = props.mode === "edit"
34
- ? createFields.filter((field) => field !== "runNow")
35
- : createFields;
36
- const saveIndex = fields.length;
37
- const cancelIndex = fields.length + 1;
38
- const labels = {
39
- interval: t("board.labelInterval"),
40
- command: t("board.labelCommand"),
41
- description: t("board.labelDescription"),
42
- cwd: t("board.labelCwd"),
43
- runNow: t("board.labelRunNow"),
44
- maxRuns: t("board.labelMaxRuns"),
45
- };
46
- const hints = {
47
- interval: t("board.hintInterval"),
48
- command: t("board.hintCommand"),
49
- description: t("board.hintDescription"),
50
- cwd: t("board.hintCwd"),
51
- runNow: t("board.hintRunNow"),
52
- maxRuns: t("board.hintMaxRuns"),
53
- };
54
- const examples = {
55
- interval: t("board.exampleInterval"),
56
- command: t("board.exampleCommand"),
57
- description: t("board.exampleDescription"),
58
- cwd: "",
59
- runNow: "",
60
- maxRuns: "",
61
- };
62
- const runNowOptions = [
63
- { name: t("board.runNowNo"), description: "", value: "n" },
64
- { name: t("board.runNowYes"), description: "", value: "y" },
65
- ];
66
- const [values, setValues] = useState(props.initial);
41
+ const [values, setValues] = useState({
42
+ ...props.initial,
43
+ project: props.currentProjectId ?? props.initial.project ?? "default",
44
+ });
67
45
  const valuesRef = useRef(values);
68
46
  const [focusIndex, setFocusIndex] = useState(0);
69
47
  const [error, setError] = useState("");
70
48
  const [isSubmitting, setIsSubmitting] = useState(false);
49
+ const [selectedTaskName, setSelectedTaskName] = useState(props.selectedTaskName ?? null);
50
+ useState(() => {
51
+ if (values.taskId && !selectedTaskName) {
52
+ void listTasks().then((tasks) => {
53
+ const found = tasks.find((t) => t.id === values.taskId);
54
+ if (found)
55
+ setSelectedTaskName(found.name);
56
+ }).catch(() => { });
57
+ }
58
+ });
71
59
  const { width: termWidth } = useTerminalDimensions();
72
60
  const btnWidth = Math.max(10, Math.min(14, Math.floor(termWidth / 6)));
61
+ const isInline = values.taskMode === TASK_MODE_INLINE;
62
+ const visibleFields = props.mode === "edit"
63
+ ? createFields.filter((f) => f !== "runNow")
64
+ : [...createFields];
65
+ const filteredFields = visibleFields.filter((f) => {
66
+ if (f === "command")
67
+ return isInline;
68
+ if (f === "taskId")
69
+ return !isInline;
70
+ return true;
71
+ });
72
+ const chooseTaskIdx = filteredFields.indexOf("taskId");
73
+ const saveIndex = filteredFields.length;
74
+ const cancelIndex = filteredFields.length + 1;
73
75
  function updateValues(next) {
74
76
  valuesRef.current = next;
75
77
  setValues(next);
76
78
  }
79
+ if (props.selectedTaskId && props.selectedTaskId !== values.taskId) {
80
+ const next = { ...valuesRef.current, taskId: props.selectedTaskId, taskMode: TASK_MODE_EXISTING };
81
+ valuesRef.current = next;
82
+ setValues(next);
83
+ setSelectedTaskName(props.selectedTaskName ?? props.selectedTaskId);
84
+ }
77
85
  useKeyboard((key) => {
78
86
  if (key.name === "tab") {
79
87
  setFocusIndex((i) => {
@@ -82,11 +90,50 @@ export function CreateView(props) {
82
90
  });
83
91
  return;
84
92
  }
85
- if ((key.name === "left" || key.name === "right") && focusIndex >= saveIndex) {
86
- setFocusIndex(key.name === "left" ? saveIndex : cancelIndex);
87
- return;
93
+ if (key.name === "left" || key.name === "right") {
94
+ if (focusIndex === saveIndex) {
95
+ setFocusIndex(key.name === "right" ? cancelIndex : focusIndex - 1 >= 0 ? filteredFields.length - 1 : 0);
96
+ return;
97
+ }
98
+ if (focusIndex === cancelIndex) {
99
+ setFocusIndex(key.name === "right" ? 0 : saveIndex);
100
+ return;
101
+ }
102
+ if (key.name === "right") {
103
+ if (focusIndex + 1 < filteredFields.length) {
104
+ setFocusIndex((i) => i + 1);
105
+ }
106
+ else {
107
+ setFocusIndex(saveIndex);
108
+ }
109
+ return;
110
+ }
111
+ if (key.name === "left") {
112
+ if (focusIndex > 0) {
113
+ setFocusIndex((i) => i - 1);
114
+ }
115
+ else {
116
+ setFocusIndex(cancelIndex);
117
+ }
118
+ return;
119
+ }
88
120
  }
89
- if (key.name === "return" || key.name === "enter") {
121
+ if (key.name === "return" || key.name === "enter" || key.name === " ") {
122
+ const field = filteredFields[focusIndex];
123
+ if (field === "taskMode") {
124
+ const next = valuesRef.current.taskMode === TASK_MODE_INLINE ? TASK_MODE_EXISTING : TASK_MODE_INLINE;
125
+ updateValues({ ...valuesRef.current, taskMode: next });
126
+ return;
127
+ }
128
+ if (field === "runNow") {
129
+ const next = valuesRef.current.runNow === "y" ? "n" : "y";
130
+ updateValues({ ...valuesRef.current, runNow: next });
131
+ return;
132
+ }
133
+ if (focusIndex === chooseTaskIdx && !isInline) {
134
+ props.onChooseTask();
135
+ return;
136
+ }
90
137
  if (focusIndex === saveIndex) {
91
138
  void submit(valuesRef.current);
92
139
  }
@@ -94,33 +141,87 @@ export function CreateView(props) {
94
141
  props.onCancel();
95
142
  }
96
143
  }
144
+ if (key.name === "up" || key.name === "down") {
145
+ const field = filteredFields[focusIndex];
146
+ if (field === "project" && projectOptions.length > 1) {
147
+ const currentIdx = projectOptions.findIndex((p) => p.value === valuesRef.current.project);
148
+ const nextIdx = key.name === "down"
149
+ ? (currentIdx + 1) % projectOptions.length
150
+ : (currentIdx - 1 + projectOptions.length) % projectOptions.length;
151
+ const next = projectOptions[nextIdx];
152
+ if (next)
153
+ updateValues({ ...valuesRef.current, project: next.value });
154
+ return;
155
+ }
156
+ }
97
157
  });
98
158
  async function submit(current) {
99
- if (isSubmitting) {
159
+ if (isSubmitting)
100
160
  return;
101
- }
102
161
  try {
103
162
  setIsSubmitting(true);
104
163
  setError("");
105
- const cwd = current.cwd.trim();
106
- if (cwd && !fs.existsSync(cwd)) {
107
- setError(t("board.cwdMissing", { cwd }));
108
- return;
164
+ if (current.taskMode === TASK_MODE_INLINE) {
165
+ const cwd = current.cwd.trim();
166
+ if (cwd && !fs.existsSync(cwd)) {
167
+ setError(t("board.cwdMissing", { cwd }));
168
+ return;
169
+ }
170
+ const tokens = parseCommandLine(current.command.trim());
171
+ const [command, ...commandArgs] = tokens;
172
+ if (!command) {
173
+ setError(t("errors.commandEmpty"));
174
+ return;
175
+ }
176
+ if (!current.description.trim()) {
177
+ setError(t("errors.descriptionEmpty"));
178
+ return;
179
+ }
180
+ const built = buildLoopOptions(current.interval.trim(), {
181
+ now: props.mode === "create" && current.runNow === "y",
182
+ maxRuns: current.maxRuns.trim() || null,
183
+ verbose: false,
184
+ description: current.description.trim(),
185
+ command,
186
+ commandArgs,
187
+ cwd,
188
+ });
189
+ built.options.projectId = current.project || "default";
190
+ const request = props.mode === "edit" && props.editId
191
+ ? updateLoop(props.editId, built.options, built.intervalHuman)
192
+ : createLoop(built.options, built.intervalHuman);
193
+ const id = await request;
194
+ props.onDone(props.mode === "edit", id, current.description.trim());
195
+ }
196
+ else {
197
+ if (!current.taskId) {
198
+ setError(t("errors.commandEmpty"));
199
+ return;
200
+ }
201
+ if (!current.description.trim()) {
202
+ setError(t("errors.descriptionEmpty"));
203
+ return;
204
+ }
205
+ const cwd = current.cwd.trim();
206
+ if (cwd && !fs.existsSync(cwd)) {
207
+ setError(t("board.cwdMissing", { cwd }));
208
+ return;
209
+ }
210
+ const built = buildLoopOptions(current.interval.trim(), {
211
+ now: props.mode === "create" && current.runNow === "y",
212
+ maxRuns: current.maxRuns.trim() || null,
213
+ verbose: false,
214
+ description: current.description.trim(),
215
+ taskId: current.taskId,
216
+ cwd,
217
+ });
218
+ built.options.projectId = current.project || "default";
219
+ const request = props.mode === "edit" && props.editId
220
+ ? updateLoop(props.editId, built.options, built.intervalHuman)
221
+ : createLoop(built.options, built.intervalHuman);
222
+ const id = await request;
223
+ props.onDone(props.mode === "edit", id, current.description.trim());
109
224
  }
110
- const tokens = parseCommandLine(current.command.trim());
111
- const [command, ...commandArgs] = tokens;
112
- const built = buildLoopOptions(current.interval.trim(), command ?? "", commandArgs, {
113
- now: props.mode === "create" && current.runNow === "y",
114
- maxRuns: current.maxRuns.trim() || null,
115
- verbose: false,
116
- cwd,
117
- description: current.description.trim(),
118
- });
119
- const request = props.mode === "edit" && props.editId
120
- ? updateLoop(props.editId, built.options, built.intervalHuman)
121
- : createLoop(built.options, built.intervalHuman);
122
- const id = await request;
123
- props.onDone(props.mode === "edit", id);
124
225
  }
125
226
  catch (e) {
126
227
  setError(e instanceof Error ? e.message : String(e));
@@ -129,11 +230,55 @@ export function CreateView(props) {
129
230
  setIsSubmitting(false);
130
231
  }
131
232
  }
233
+ const labels = {
234
+ interval: t("board.labelInterval"),
235
+ taskMode: t("board.labelTaskMode"),
236
+ command: t("board.labelCommand"),
237
+ cwd: t("board.labelCwd"),
238
+ taskId: t("board.labelTask"),
239
+ description: t("board.labelDescription"),
240
+ runNow: t("board.labelRunNow"),
241
+ maxRuns: t("board.labelMaxRuns"),
242
+ project: t("project.projectsLabel"),
243
+ };
244
+ const hints = {
245
+ interval: t("board.hintInterval"),
246
+ taskMode: t("board.hintTaskMode"),
247
+ command: t("board.hintCommand"),
248
+ cwd: t("board.hintCwd"),
249
+ taskId: t("board.hintTask"),
250
+ description: t("board.hintDescription"),
251
+ runNow: t("board.hintRunNow"),
252
+ maxRuns: t("board.hintMaxRuns"),
253
+ project: t("project.hintColor"),
254
+ };
255
+ const examples = {
256
+ interval: t("board.exampleInterval"),
257
+ taskMode: "",
258
+ command: t("board.exampleCommand"),
259
+ cwd: "",
260
+ taskId: "",
261
+ description: t("board.exampleDescription"),
262
+ runNow: "",
263
+ maxRuns: "",
264
+ project: "",
265
+ };
266
+ const taskModeOptions = [
267
+ { name: t("board.taskModeInline"), description: "", value: TASK_MODE_INLINE },
268
+ { name: t("board.taskModeExisting"), description: "", value: TASK_MODE_EXISTING },
269
+ ];
270
+ const runNowOptions = [
271
+ { name: t("board.runNowNo"), description: "", value: "n" },
272
+ { name: t("board.runNowYes"), description: "", value: "y" },
273
+ ];
274
+ const projectOptions = (props.projects ?? []).length > 0
275
+ ? props.projects.map((p) => ({ name: p.name, value: p.id, color: p.color }))
276
+ : [{ name: "Default", value: "default", color: "#ffffff" }];
132
277
  const title = props.mode === "edit" ? t("board.editTitle") : t("board.createTitle");
133
- return (_jsxs("box", { title: title, border: true, style: { flexDirection: "column", flexGrow: 1, padding: 1, backgroundColor: "#0b0b0b" }, children: [_jsxs("box", { style: { flexDirection: "column", marginBottom: 1 }, children: [_jsx("text", { fg: "#9ca3af", children: t("board.exampleHeading") }), _jsx("text", { fg: "#d1d5db", children: t("board.exampleFull") })] }), _jsx("box", { style: { flexDirection: "column", flexGrow: 1 }, children: Array.from({ length: Math.ceil(fields.length / 2) }, (_, row) => {
134
- const leftField = fields[row * 2];
135
- const rightField = row * 2 + 1 < fields.length ? fields[row * 2 + 1] : null;
136
- return (_jsxs("box", { style: { flexDirection: "row", marginBottom: 1 }, children: [_jsx(FormField, { field: leftField, index: row * 2, focusIndex: focusIndex, values: values, valuesRef: valuesRef, updateValues: updateValues, setFocusIndex: setFocusIndex, submit: submit, labels: labels, hints: hints, examples: examples, runNowOptions: runNowOptions, fields: fields, style: { width: "50%", paddingRight: 1 } }), rightField ? (_jsx(FormField, { field: rightField, index: row * 2 + 1, focusIndex: focusIndex, values: values, valuesRef: valuesRef, updateValues: updateValues, setFocusIndex: setFocusIndex, submit: submit, labels: labels, hints: hints, examples: examples, runNowOptions: runNowOptions, fields: fields, style: { width: "50%" } })) : (_jsx("box", { style: { width: "50%" } }))] }, row));
278
+ return (_jsxs("box", { title: title, border: true, style: { flexDirection: "column", flexGrow: 1, padding: 1, backgroundColor: "#0b0b0b" }, children: [_jsxs("box", { style: { flexDirection: "column", marginBottom: 1 }, children: [_jsx("text", { fg: "#9ca3af", children: t("board.exampleHeading") }), _jsx("text", { fg: "#d1d5db", children: t("board.exampleFull") })] }), _jsx("box", { style: { flexDirection: "column", flexGrow: 1 }, children: Array.from({ length: Math.ceil(filteredFields.length / 2) }, (_, row) => {
279
+ const leftField = filteredFields[row * 2];
280
+ const rightField = row * 2 + 1 < filteredFields.length ? filteredFields[row * 2 + 1] : null;
281
+ return (_jsxs("box", { style: { flexDirection: "row", marginBottom: 1 }, children: [_jsx(FormRow, { field: leftField, index: row * 2, focusIndex: focusIndex, values: values, valuesRef: valuesRef, updateValues: updateValues, setFocusIndex: setFocusIndex, submit: submit, labels: labels, hints: hints, examples: examples, taskModeOptions: taskModeOptions, runNowOptions: runNowOptions, projectOptions: projectOptions, selectedTaskName: selectedTaskName, fields: filteredFields, onChooseTask: props.onChooseTask, style: { width: "50%", paddingRight: 1 } }), rightField ? (_jsx(FormRow, { field: rightField, index: row * 2 + 1, focusIndex: focusIndex, values: values, valuesRef: valuesRef, updateValues: updateValues, setFocusIndex: setFocusIndex, submit: submit, labels: labels, hints: hints, examples: examples, taskModeOptions: taskModeOptions, runNowOptions: runNowOptions, projectOptions: projectOptions, selectedTaskName: selectedTaskName, fields: filteredFields, onChooseTask: props.onChooseTask, style: { width: "50%" } })) : (_jsx("box", { style: { width: "50%" } }))] }, row));
137
282
  }) }), _jsxs("box", { style: { flexDirection: "row", height: 3, marginBottom: 1, backgroundColor: "#0b0b0b" }, children: [_jsx(HoverButton, { label: isSubmitting ? t("board.saving") : props.mode === "edit" ? t("board.save") : t("board.create"), onMouseDown: () => void submit(valuesRef.current), selected: focusIndex === saveIndex, width: btnWidth, marginRight: 1 }), _jsx(HoverButton, { label: t("board.cancel"), onMouseDown: props.onCancel, selected: focusIndex === cancelIndex, width: btnWidth })] }), _jsx("text", { fg: "#9ca3af", children: t("board.formNav") }), error ? _jsx("text", { fg: "#f87171", children: error }) : null] }));
138
283
  }
139
284
  function HoverButton(props) {
@@ -142,9 +287,24 @@ function HoverButton(props) {
142
287
  const borderColor = props.selected ? "#38bdf8" : undefined;
143
288
  return (_jsx("box", { border: true, onMouseDown: props.onMouseDown, borderColor: borderColor, style: { width: props.width, justifyContent: "center", alignItems: "center", marginRight: props.marginRight, backgroundColor: bg }, ...hoverProps, children: _jsx("text", { fg: "#e5e7eb", children: _jsx("strong", { children: props.label }) }) }));
144
289
  }
145
- function FormField(props) {
146
- const { field, index, focusIndex, values, valuesRef, updateValues, setFocusIndex, submit, labels, hints, examples, runNowOptions, fields, style } = props;
147
- return (_jsxs("box", { style: { flexDirection: "column", ...style }, children: [_jsx("text", { fg: focusIndex === index ? "#38bdf8" : "#e5e7eb", children: labels[field] }), _jsx("text", { fg: "#6b7280", children: hints[field] }), field === "runNow" ? (_jsx("box", { border: true, borderColor: focusIndex === index ? "#38bdf8" : undefined, style: { height: runNowOptions.length + 2, backgroundColor: "#0b0b0b" }, children: _jsx("select", { focused: focusIndex === index, options: runNowOptions, selectedIndex: values.runNow === "y" ? 1 : 0, showDescription: false, style: { flexGrow: 1 }, onChange: (_index, option) => updateValues({ ...valuesRef.current, runNow: option?.value ?? "n" }) }) })) : (_jsx("box", { border: true, borderColor: focusIndex === index ? "#38bdf8" : undefined, style: { height: 3, backgroundColor: "#0b0b0b" }, children: _jsx("input", { focused: focusIndex === index, value: values[field], placeholder: examples[field] ? t("board.placeholderExample", { example: examples[field] }) : t("board.placeholderBlank"), onInput: (value) => updateValues({ ...valuesRef.current, [field]: value }), onSubmit: () => {
290
+ function FormRow(props) {
291
+ const { field, index, focusIndex, values, valuesRef, updateValues, setFocusIndex, submit, labels, hints, examples, taskModeOptions, runNowOptions, projectOptions, selectedTaskName, fields, onChooseTask, style } = props;
292
+ const { isHovered, hoverProps } = useHoverState();
293
+ const isFocused = focusIndex === index;
294
+ const isToggleField = field === "taskMode" || field === "runNow";
295
+ const isTaskButton = field === "taskId";
296
+ const isProjectField = field === "project";
297
+ const toggleOptions = field === "taskMode" ? taskModeOptions : runNowOptions;
298
+ const toggleValue = field === "taskMode" ? values.taskMode : values.runNow;
299
+ return (_jsxs("box", { style: { flexDirection: "column", ...style }, children: [_jsx("text", { fg: isFocused ? "#38bdf8" : "#e5e7eb", children: labels[field] }), _jsx("text", { fg: "#6b7280", children: hints[field] }), isToggleField ? (_jsx("box", { border: true, borderColor: isFocused ? "#38bdf8" : undefined, style: { height: 3, flexDirection: "row", backgroundColor: "#0b0b0b", alignItems: "center" }, children: toggleOptions.map((opt) => {
300
+ const isActive = toggleValue === opt.value;
301
+ return (_jsx("box", { onMouseDown: () => updateValues({ ...valuesRef.current, [field]: opt.value }), style: { backgroundColor: isActive ? "#1e3a8a" : undefined, paddingLeft: 1, paddingRight: 1, marginRight: 1 }, ...hoverProps, children: _jsx("text", { fg: isActive ? "#ffffff" : isHovered ? "#e5e7eb" : "#9ca3af", children: _jsx("strong", { children: opt.name }) }) }, opt.value));
302
+ }) })) : isTaskButton ? (_jsx("box", { border: true, borderColor: isFocused ? "#38bdf8" : undefined, style: { height: 3, flexDirection: "row", backgroundColor: "#0b0b0b", alignItems: "center", paddingLeft: 1 }, onMouseDown: () => { setFocusIndex(index); onChooseTask(); }, children: _jsx("text", { fg: values.taskId ? "#4ade80" : "#9ca3af", children: values.taskId
303
+ ? t("board.selectedTask", { name: selectedTaskName ?? values.taskId })
304
+ : t("board.chooseTask") }) })) : isProjectField ? (_jsx("box", { border: true, borderColor: isFocused ? "#38bdf8" : undefined, style: { height: 3, flexDirection: "row", backgroundColor: "#0b0b0b", alignItems: "center", paddingLeft: 1 }, onMouseDown: () => setFocusIndex(index), children: projectOptions.map((opt) => {
305
+ const isActive = values.project === opt.value;
306
+ return (_jsx("box", { onMouseDown: () => updateValues({ ...valuesRef.current, project: opt.value }), style: { backgroundColor: isActive ? "#1e3a8a" : undefined, paddingLeft: 1, paddingRight: 1, marginRight: 1 }, children: _jsx("text", { fg: isActive ? "#ffffff" : "#9ca3af", children: `● ${opt.name}` }) }, opt.value));
307
+ }) })) : (_jsx("box", { border: true, borderColor: isFocused ? "#38bdf8" : undefined, style: { height: 3, backgroundColor: "#0b0b0b" }, children: _jsx("input", { focused: isFocused, value: values[field], placeholder: examples[field] ? t("board.placeholderExample", { example: examples[field] }) : t("board.placeholderBlank"), onInput: (value) => updateValues({ ...valuesRef.current, [field]: value }), onSubmit: () => {
148
308
  if (index < fields.length - 1) {
149
309
  setFocusIndex(index + 1);
150
310
  }
@@ -0,0 +1,104 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useKeyboard, useTerminalDimensions } from "@opentui/react";
4
+ import { t } from "../../i18n/index.js";
5
+ import { createProject } from "../daemon.js";
6
+ import { PROJECT_COLORS, PROJECT_COLOR_KEYS } from "../../config/constants.js";
7
+ export function CreateProjectModal(props) {
8
+ const { onDone, onCancel } = props;
9
+ const { width } = useTerminalDimensions();
10
+ const defaultColorKey = PROJECT_COLOR_KEYS.indexOf("cyan") >= 0 ? "cyan" : PROJECT_COLOR_KEYS[0] ?? "white";
11
+ const [name, setName] = useState("");
12
+ const [selectedColorKey, setSelectedColorKey] = useState(defaultColorKey);
13
+ const [error, setError] = useState("");
14
+ const [isSubmitting, setIsSubmitting] = useState(false);
15
+ const [focusField, setFocusField] = useState("name");
16
+ useKeyboard((key) => {
17
+ if (key.name === "tab") {
18
+ const order = ["name", "color", "save", "cancel"];
19
+ const idx = order.indexOf(focusField);
20
+ const next = key.shift ? order[(idx - 1 + order.length) % order.length] : order[(idx + 1) % order.length];
21
+ setFocusField(next ?? "name");
22
+ return;
23
+ }
24
+ if (key.name === "escape") {
25
+ onCancel();
26
+ return;
27
+ }
28
+ if (key.name === "return" || key.name === "enter") {
29
+ if (focusField === "cancel") {
30
+ onCancel();
31
+ return;
32
+ }
33
+ void submit();
34
+ return;
35
+ }
36
+ if (focusField === "color") {
37
+ if (key.name === "left") {
38
+ const idx = PROJECT_COLOR_KEYS.indexOf(selectedColorKey);
39
+ setSelectedColorKey(PROJECT_COLOR_KEYS[(idx - 1 + PROJECT_COLOR_KEYS.length) % PROJECT_COLOR_KEYS.length] ?? selectedColorKey);
40
+ return;
41
+ }
42
+ if (key.name === "right") {
43
+ const idx = PROJECT_COLOR_KEYS.indexOf(selectedColorKey);
44
+ setSelectedColorKey(PROJECT_COLOR_KEYS[(idx + 1) % PROJECT_COLOR_KEYS.length] ?? selectedColorKey);
45
+ return;
46
+ }
47
+ }
48
+ });
49
+ async function submit() {
50
+ if (isSubmitting)
51
+ return;
52
+ if (!name.trim()) {
53
+ setError(t("project.error.nameRequired"));
54
+ return;
55
+ }
56
+ try {
57
+ setIsSubmitting(true);
58
+ setError("");
59
+ const color = PROJECT_COLORS[selectedColorKey] ?? "#ffffff";
60
+ const project = await createProject(name.trim(), color);
61
+ onDone(project);
62
+ }
63
+ catch (err) {
64
+ setError(err instanceof Error ? err.message : String(err));
65
+ }
66
+ finally {
67
+ setIsSubmitting(false);
68
+ }
69
+ }
70
+ return (_jsx("box", { style: {
71
+ position: "absolute",
72
+ top: 0,
73
+ left: 0,
74
+ width: "100%",
75
+ height: "100%",
76
+ justifyContent: "center",
77
+ alignItems: "center",
78
+ zIndex: 100,
79
+ }, children: _jsxs("box", { title: t("project.createTitle"), border: true, style: {
80
+ flexDirection: "column",
81
+ padding: 1,
82
+ minWidth: Math.min(44, width - 4),
83
+ backgroundColor: "#111827",
84
+ }, children: [_jsx("text", { fg: focusField === "name" ? "#38bdf8" : "#e5e7eb", children: t("project.labelName") }), _jsx("text", { fg: "#6b7280", children: t("project.hintName") }), _jsx("box", { border: true, borderColor: focusField === "name" ? "#38bdf8" : undefined, style: { height: 3, backgroundColor: "#0b0b0b", marginBottom: 1 }, children: _jsx("input", { focused: focusField === "name", value: name, placeholder: "My Project", onInput: (value) => setName(value), onSubmit: () => setFocusField("color") }) }), _jsx("text", { fg: focusField === "color" ? "#38bdf8" : "#e5e7eb", children: t("project.labelColor") }), _jsx("text", { fg: "#6b7280", children: t("project.hintColor") }), _jsx("box", { border: true, borderColor: focusField === "color" ? "#38bdf8" : undefined, style: { height: 3, flexDirection: "row", backgroundColor: "#0b0b0b", alignItems: "center", marginBottom: 1 }, children: PROJECT_COLOR_KEYS.map((colorKey) => {
85
+ const isActive = selectedColorKey === colorKey;
86
+ return (_jsx("box", { onMouseDown: () => { setFocusField("color"); setSelectedColorKey(colorKey); }, style: {
87
+ backgroundColor: isActive ? "#1e3a8a" : undefined,
88
+ paddingLeft: 1,
89
+ paddingRight: 1,
90
+ marginRight: 1,
91
+ }, children: _jsxs("text", { children: [_jsx("span", { fg: PROJECT_COLORS[colorKey] ?? "#ffffff", children: "\u25CF" }), ` ${colorKey}`] }) }, colorKey));
92
+ }) }), error ? _jsx("text", { fg: "#f87171", children: error }) : null, _jsxs("box", { style: { flexDirection: "row", marginTop: 1 }, children: [_jsx("box", { border: true, borderColor: focusField === "save" ? "#38bdf8" : undefined, onMouseDown: () => void submit(), style: {
93
+ width: 12,
94
+ justifyContent: "center",
95
+ alignItems: "center",
96
+ marginRight: 1,
97
+ backgroundColor: focusField === "save" ? "#1e3a8a" : "#0b0b0b",
98
+ }, children: _jsx("text", { fg: "#e5e7eb", children: _jsx("strong", { children: isSubmitting ? t("board.saving") : t("board.create") }) }) }), _jsx("box", { border: true, borderColor: focusField === "cancel" ? "#38bdf8" : undefined, onMouseDown: onCancel, style: {
99
+ width: 12,
100
+ justifyContent: "center",
101
+ alignItems: "center",
102
+ backgroundColor: focusField === "cancel" ? "#1e3a8a" : "#0b0b0b",
103
+ }, children: _jsx("text", { fg: "#e5e7eb", children: _jsx("strong", { children: t("board.cancel") }) }) })] })] }) }));
104
+ }
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useKeyboard, useTerminalDimensions } from "@opentui/react";
4
+ import { t } from "../../i18n/index.js";
5
+ import { deleteProject } from "../daemon.js";
6
+ export function DeleteProjectConfirm(props) {
7
+ const { project, loopCount, onDone, onCancel } = props;
8
+ const { width } = useTerminalDimensions();
9
+ const [isDeleting, setIsDeleting] = useState(false);
10
+ const [error, setError] = useState("");
11
+ useKeyboard((key) => {
12
+ if (key.name === "escape") {
13
+ onCancel();
14
+ }
15
+ if (key.name === "return" || key.name === "enter") {
16
+ void handleDelete();
17
+ }
18
+ });
19
+ async function handleDelete() {
20
+ if (isDeleting)
21
+ return;
22
+ try {
23
+ setIsDeleting(true);
24
+ setError("");
25
+ await deleteProject(project.id);
26
+ onDone();
27
+ }
28
+ catch (err) {
29
+ setError(err instanceof Error ? err.message : String(err));
30
+ setIsDeleting(false);
31
+ }
32
+ }
33
+ return (_jsx("box", { style: {
34
+ position: "absolute",
35
+ top: 0,
36
+ left: 0,
37
+ width: "100%",
38
+ height: "100%",
39
+ justifyContent: "center",
40
+ alignItems: "center",
41
+ zIndex: 100,
42
+ }, children: _jsxs("box", { title: t("project.deleteTitle"), border: true, style: {
43
+ flexDirection: "column",
44
+ padding: 1,
45
+ minWidth: Math.min(50, width - 4),
46
+ backgroundColor: "#111827",
47
+ }, children: [_jsx("text", { fg: "#e5e7eb", children: t("project.deleteConfirm", { name: project.name }) }), loopCount > 0 ? (_jsx("text", { fg: "#f59e0b", children: t("project.deleteWarning", { count: String(loopCount) }) })) : null, error ? _jsx("text", { fg: "#f87171", children: error }) : null, _jsx("text", { children: " " }), _jsxs("box", { style: { flexDirection: "row" }, children: [_jsx("box", { border: true, onMouseDown: () => void handleDelete(), style: {
48
+ paddingLeft: 1,
49
+ paddingRight: 1,
50
+ marginRight: 1,
51
+ backgroundColor: "#7f1d1d",
52
+ }, children: _jsx("text", { fg: "#fca5a5", children: _jsx("strong", { children: isDeleting ? "Deleting..." : t("project.moveToDefault") }) }) }), _jsx("box", { border: true, onMouseDown: onCancel, style: { paddingLeft: 1, paddingRight: 1, backgroundColor: "#0b0b0b" }, children: _jsx("text", { fg: "#e5e7eb", children: _jsx("strong", { children: t("board.cancel") }) }) })] })] }) }));
53
+ }
@@ -0,0 +1,106 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { useKeyboard, useTerminalDimensions } from "@opentui/react";
4
+ import { t } from "../../i18n/index.js";
5
+ import { updateProject } from "../daemon.js";
6
+ import { PROJECT_COLORS, PROJECT_COLOR_KEYS } from "../../config/constants.js";
7
+ export function EditProjectModal(props) {
8
+ const { project, onDone, onCancel } = props;
9
+ const { width } = useTerminalDimensions();
10
+ const [name, setName] = useState(project.name);
11
+ const [selectedColorKey, setSelectedColorKey] = useState(() => {
12
+ const found = PROJECT_COLOR_KEYS.find((k) => PROJECT_COLORS[k] === project.color);
13
+ return found ?? PROJECT_COLOR_KEYS[0] ?? "white";
14
+ });
15
+ const [error, setError] = useState("");
16
+ const [isSubmitting, setIsSubmitting] = useState(false);
17
+ const [focusField, setFocusField] = useState("name");
18
+ useKeyboard((key) => {
19
+ if (key.name === "tab") {
20
+ const order = ["name", "color", "save", "cancel"];
21
+ const idx = order.indexOf(focusField);
22
+ const next = key.shift ? order[(idx - 1 + order.length) % order.length] : order[(idx + 1) % order.length];
23
+ setFocusField(next ?? "name");
24
+ return;
25
+ }
26
+ if (key.name === "escape") {
27
+ onCancel();
28
+ return;
29
+ }
30
+ if (key.name === "return" || key.name === "enter") {
31
+ if (focusField === "cancel") {
32
+ onCancel();
33
+ return;
34
+ }
35
+ void submit();
36
+ return;
37
+ }
38
+ if (focusField === "color") {
39
+ if (key.name === "left") {
40
+ const idx = PROJECT_COLOR_KEYS.indexOf(selectedColorKey);
41
+ setSelectedColorKey(PROJECT_COLOR_KEYS[(idx - 1 + PROJECT_COLOR_KEYS.length) % PROJECT_COLOR_KEYS.length] ?? selectedColorKey);
42
+ return;
43
+ }
44
+ if (key.name === "right") {
45
+ const idx = PROJECT_COLOR_KEYS.indexOf(selectedColorKey);
46
+ setSelectedColorKey(PROJECT_COLOR_KEYS[(idx + 1) % PROJECT_COLOR_KEYS.length] ?? selectedColorKey);
47
+ return;
48
+ }
49
+ }
50
+ });
51
+ async function submit() {
52
+ if (isSubmitting)
53
+ return;
54
+ if (!name.trim()) {
55
+ setError(t("project.error.nameEmpty"));
56
+ return;
57
+ }
58
+ try {
59
+ setIsSubmitting(true);
60
+ setError("");
61
+ const color = PROJECT_COLORS[selectedColorKey] ?? project.color;
62
+ await updateProject(project.id, name.trim(), color);
63
+ onDone();
64
+ }
65
+ catch (err) {
66
+ setError(err instanceof Error ? err.message : String(err));
67
+ }
68
+ finally {
69
+ setIsSubmitting(false);
70
+ }
71
+ }
72
+ return (_jsx("box", { style: {
73
+ position: "absolute",
74
+ top: 0,
75
+ left: 0,
76
+ width: "100%",
77
+ height: "100%",
78
+ justifyContent: "center",
79
+ alignItems: "center",
80
+ zIndex: 100,
81
+ }, children: _jsxs("box", { title: t("project.editTitle"), border: true, style: {
82
+ flexDirection: "column",
83
+ padding: 1,
84
+ minWidth: Math.min(44, width - 4),
85
+ backgroundColor: "#111827",
86
+ }, children: [_jsx("text", { fg: focusField === "name" ? "#38bdf8" : "#e5e7eb", children: t("project.labelName") }), _jsx("text", { fg: "#6b7280", children: t("project.hintName") }), _jsx("box", { border: true, borderColor: focusField === "name" ? "#38bdf8" : undefined, style: { height: 3, backgroundColor: "#0b0b0b", marginBottom: 1 }, children: _jsx("input", { focused: focusField === "name", value: name, placeholder: project.name, onInput: (value) => setName(value), onSubmit: () => setFocusField("color") }) }), _jsx("text", { fg: focusField === "color" ? "#38bdf8" : "#e5e7eb", children: t("project.labelColor") }), _jsx("text", { fg: "#6b7280", children: t("project.hintColor") }), _jsx("box", { border: true, borderColor: focusField === "color" ? "#38bdf8" : undefined, style: { height: 3, flexDirection: "row", backgroundColor: "#0b0b0b", alignItems: "center", marginBottom: 1 }, children: PROJECT_COLOR_KEYS.map((colorKey) => {
87
+ const isActive = selectedColorKey === colorKey;
88
+ return (_jsx("box", { onMouseDown: () => { setFocusField("color"); setSelectedColorKey(colorKey); }, style: {
89
+ backgroundColor: isActive ? "#1e3a8a" : undefined,
90
+ paddingLeft: 1,
91
+ paddingRight: 1,
92
+ marginRight: 1,
93
+ }, children: _jsxs("text", { children: [_jsx("span", { fg: PROJECT_COLORS[colorKey] ?? "#ffffff", children: "\u25CF" }), ` ${colorKey}`] }) }, colorKey));
94
+ }) }), error ? _jsx("text", { fg: "#f87171", children: error }) : null, _jsxs("box", { style: { flexDirection: "row", marginTop: 1 }, children: [_jsx("box", { border: true, borderColor: focusField === "save" ? "#38bdf8" : undefined, onMouseDown: () => void submit(), style: {
95
+ width: 12,
96
+ justifyContent: "center",
97
+ alignItems: "center",
98
+ marginRight: 1,
99
+ backgroundColor: focusField === "save" ? "#1e3a8a" : "#0b0b0b",
100
+ }, children: _jsx("text", { fg: "#e5e7eb", children: _jsx("strong", { children: isSubmitting ? t("board.saving") : t("board.save") }) }) }), _jsx("box", { border: true, borderColor: focusField === "cancel" ? "#38bdf8" : undefined, onMouseDown: onCancel, style: {
101
+ width: 12,
102
+ justifyContent: "center",
103
+ alignItems: "center",
104
+ backgroundColor: focusField === "cancel" ? "#1e3a8a" : "#0b0b0b",
105
+ }, children: _jsx("text", { fg: "#e5e7eb", children: _jsx("strong", { children: t("board.cancel") }) }) })] })] }) }));
106
+ }