@fclef819/cdx 0.1.2 → 0.1.3
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/bin/cdx.js +30 -74
- package/package.json +1 -1
package/bin/cdx.js
CHANGED
|
@@ -179,11 +179,15 @@ function runCodex(args, cwd, verbose) {
|
|
|
179
179
|
if (result.status !== 0) process.exit(result.status ?? 1);
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
182
|
+
function suggestByNumber(input, choices) {
|
|
183
|
+
const term = (input || "").trim();
|
|
184
|
+
if (!term) return choices;
|
|
185
|
+
if (/^\d+$/.test(term)) {
|
|
186
|
+
const number = Number.parseInt(term, 10);
|
|
187
|
+
return choices.filter((choice) => choice.number === number);
|
|
188
|
+
}
|
|
189
|
+
const lower = term.toLowerCase();
|
|
190
|
+
return choices.filter((choice) => choice.title.toLowerCase().includes(lower));
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
async function selectSession(entries) {
|
|
@@ -191,41 +195,21 @@ async function selectSession(entries) {
|
|
|
191
195
|
return { type: "new" };
|
|
192
196
|
}
|
|
193
197
|
|
|
194
|
-
printSessionList(entries);
|
|
195
|
-
while (true) {
|
|
196
|
-
const numberInput = await prompts({
|
|
197
|
-
type: "text",
|
|
198
|
-
name: "value",
|
|
199
|
-
message: "Select by number (Enter for list selection)",
|
|
200
|
-
validate: (value) => {
|
|
201
|
-
if (!value || !value.trim()) return true;
|
|
202
|
-
if (!/^\d+$/.test(value.trim())) return "Enter a number";
|
|
203
|
-
const index = Number.parseInt(value.trim(), 10);
|
|
204
|
-
if (index < 0 || index > entries.length) return "Out of range";
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
if (!numberInput.value && numberInput.value !== "0") break;
|
|
210
|
-
const index = Number.parseInt(String(numberInput.value).trim(), 10);
|
|
211
|
-
if (Number.isNaN(index)) break;
|
|
212
|
-
if (index === 0) return { type: "new" };
|
|
213
|
-
return { type: "resume", entry: entries[index - 1] };
|
|
214
|
-
}
|
|
215
|
-
|
|
216
198
|
const choices = [
|
|
217
|
-
{ title: "new", value: { type: "new" } },
|
|
218
|
-
...entries.map((entry) => ({
|
|
219
|
-
title: `${entry.label} (${entry.uuid})`,
|
|
220
|
-
value: { type: "resume", entry }
|
|
199
|
+
{ title: "0: new", value: { type: "new" }, number: 0 },
|
|
200
|
+
...entries.map((entry, index) => ({
|
|
201
|
+
title: `${index + 1}: ${entry.label} (${entry.uuid})`,
|
|
202
|
+
value: { type: "resume", entry },
|
|
203
|
+
number: index + 1
|
|
221
204
|
}))
|
|
222
205
|
];
|
|
223
206
|
|
|
224
207
|
const response = await prompts({
|
|
225
|
-
type: "
|
|
208
|
+
type: "autocomplete",
|
|
226
209
|
name: "selection",
|
|
227
|
-
message: "Select a session",
|
|
228
|
-
choices
|
|
210
|
+
message: "Select a session (arrow keys or number+Enter)",
|
|
211
|
+
choices,
|
|
212
|
+
suggest: suggestByNumber
|
|
229
213
|
});
|
|
230
214
|
|
|
231
215
|
return response.selection;
|
|
@@ -310,48 +294,20 @@ async function runRemove(startDir, verbose) {
|
|
|
310
294
|
}
|
|
311
295
|
|
|
312
296
|
console.log(`.cdx: ${targetPath}`);
|
|
313
|
-
|
|
314
|
-
|
|
297
|
+
const response = await prompts({
|
|
298
|
+
type: "autocomplete",
|
|
299
|
+
name: "selection",
|
|
300
|
+
message: "Select a session to remove (arrow keys or number+Enter)",
|
|
301
|
+
choices: entries.map((entry, index) => ({
|
|
302
|
+
title: `${index + 1}: ${entry.label} (${entry.uuid})`,
|
|
303
|
+
value: entry.uuid,
|
|
304
|
+
number: index + 1
|
|
305
|
+
})),
|
|
306
|
+
suggest: suggestByNumber
|
|
315
307
|
});
|
|
316
308
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const numberInput = await prompts({
|
|
320
|
-
type: "text",
|
|
321
|
-
name: "value",
|
|
322
|
-
message: "Select by number (Enter for list selection)",
|
|
323
|
-
validate: (value) => {
|
|
324
|
-
if (!value || !value.trim()) return true;
|
|
325
|
-
if (!/^\d+$/.test(value.trim())) return "Enter a number";
|
|
326
|
-
const index = Number.parseInt(value.trim(), 10);
|
|
327
|
-
if (index < 1 || index > entries.length) return "Out of range";
|
|
328
|
-
return true;
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
if (!numberInput.value) break;
|
|
333
|
-
const index = Number.parseInt(String(numberInput.value).trim(), 10);
|
|
334
|
-
if (!Number.isNaN(index)) {
|
|
335
|
-
selectedUuid = entries[index - 1].uuid;
|
|
336
|
-
}
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
if (!selectedUuid) {
|
|
341
|
-
const response = await prompts({
|
|
342
|
-
type: "select",
|
|
343
|
-
name: "selection",
|
|
344
|
-
message: "Select a session to remove",
|
|
345
|
-
choices: entries.map((entry) => ({
|
|
346
|
-
title: `${entry.label} (${entry.uuid})`,
|
|
347
|
-
value: entry.uuid
|
|
348
|
-
}))
|
|
349
|
-
});
|
|
350
|
-
if (!response.selection) return;
|
|
351
|
-
selectedUuid = response.selection;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
const remaining = entries.filter((entry) => entry.uuid !== selectedUuid);
|
|
309
|
+
if (!response.selection) return;
|
|
310
|
+
const remaining = entries.filter((entry) => entry.uuid !== response.selection);
|
|
355
311
|
writeEntries(targetPath, remaining, verbose);
|
|
356
312
|
}
|
|
357
313
|
|