@nandoblanco/opencode-local-search 1.0.2 → 1.2.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/CHANGELOG.md +29 -0
- package/README.md +31 -11
- package/cli.js +19 -1
- package/dist/gui-experimental.cjs +1 -0
- package/package.json +23 -3
- package/src/gui.css +662 -0
- package/src/gui.tsx +1251 -0
- package/src/index.ts +6 -6
- package/src/rpc.ts +113 -0
- package/src/search.ts +156 -63
- package/src/server.ts +112 -5
- package/src/sort.ts +5 -0
- package/src/tui.ts +64 -6
package/src/tui.ts
CHANGED
|
@@ -32,6 +32,8 @@ import {
|
|
|
32
32
|
type SearchSessionMatch,
|
|
33
33
|
searchSessionIndex,
|
|
34
34
|
type SessionIndex,
|
|
35
|
+
type SearchSort,
|
|
36
|
+
SEARCH_SORT_LABELS,
|
|
35
37
|
} from "./search.ts";
|
|
36
38
|
|
|
37
39
|
function splitHighlightedText(
|
|
@@ -133,6 +135,8 @@ function createTuiRenderer() {
|
|
|
133
135
|
const [role, setRole] = createSignal<RoleFilter>("all");
|
|
134
136
|
const [datePreset, setDatePreset] = createSignal<DatePreset>("all");
|
|
135
137
|
const [mode, setMode] = createSignal<SearchMode>("smart");
|
|
138
|
+
const [sort, setSort] = createSignal<SearchSort>("updated");
|
|
139
|
+
const [restoring, setRestoring] = createSignal(false);
|
|
136
140
|
const [focusPane, setFocusPane] = createSignal<"search" | "list" | "preview">("search");
|
|
137
141
|
const [selectedIndex, setSelectedIndex] = createSignal(0);
|
|
138
142
|
const [selectedSnippetIndex, setSelectedSnippetIndex] = createSignal(0);
|
|
@@ -242,6 +246,7 @@ function createTuiRenderer() {
|
|
|
242
246
|
const idx = indexData();
|
|
243
247
|
if (!idx.sessions.length) return [];
|
|
244
248
|
return searchSessionIndex(idx, query(), {
|
|
249
|
+
sort: sort(),
|
|
245
250
|
scope: scope(),
|
|
246
251
|
currentDirectory: props.currentDirectory,
|
|
247
252
|
role: role(),
|
|
@@ -257,6 +262,7 @@ function createTuiRenderer() {
|
|
|
257
262
|
role();
|
|
258
263
|
datePreset();
|
|
259
264
|
mode();
|
|
265
|
+
sort();
|
|
260
266
|
setSelectedIndex(0);
|
|
261
267
|
setSelectedSnippetIndex(0);
|
|
262
268
|
queueMicrotask(() => listScrollRef?.scrollTo?.(0));
|
|
@@ -310,6 +316,25 @@ function createTuiRenderer() {
|
|
|
310
316
|
setMode((prev: SearchMode) => MODE_CYCLE[(MODE_CYCLE.indexOf(prev) + 1) % MODE_CYCLE.length]);
|
|
311
317
|
};
|
|
312
318
|
|
|
319
|
+
const cycleSort = () => {
|
|
320
|
+
const sorts = Object.keys(SEARCH_SORT_LABELS) as SearchSort[];
|
|
321
|
+
setSort((prev) => sorts[(sorts.indexOf(prev) + 1) % sorts.length]);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const unarchiveSelected = async () => {
|
|
325
|
+
const session = selectedMatch()?.session;
|
|
326
|
+
if (!session?.archived || restoring()) return;
|
|
327
|
+
setRestoring(true);
|
|
328
|
+
try {
|
|
329
|
+
await props.context.client.session.update({ sessionID: session.id, archived: false });
|
|
330
|
+
await reloadIndex(true);
|
|
331
|
+
} catch (err) {
|
|
332
|
+
setErrorMsg(err instanceof Error ? err.message : String(err));
|
|
333
|
+
} finally {
|
|
334
|
+
setRestoring(false);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
313
338
|
const openSelected = (explicitHit?: SearchSessionMatch["matches"][number]) => {
|
|
314
339
|
const current = selectedMatch();
|
|
315
340
|
if (!current) return;
|
|
@@ -364,7 +389,7 @@ function createTuiRenderer() {
|
|
|
364
389
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
365
390
|
const handleKeyPress = (event: any) => {
|
|
366
391
|
const name = String(event.name || "").toLowerCase();
|
|
367
|
-
const enter = ["return", "enter", "linefeed"].includes(name);
|
|
392
|
+
const enter = ["return", "enter", "kpenter", "linefeed"].includes(name);
|
|
368
393
|
|
|
369
394
|
if (name === "escape") {
|
|
370
395
|
event.preventDefault();
|
|
@@ -396,6 +421,18 @@ function createTuiRenderer() {
|
|
|
396
421
|
toggleScope();
|
|
397
422
|
return;
|
|
398
423
|
}
|
|
424
|
+
if (event.ctrl && name === "s") {
|
|
425
|
+
event.preventDefault();
|
|
426
|
+
event.stopPropagation();
|
|
427
|
+
cycleSort();
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (event.ctrl && event.shift && name === "a") {
|
|
431
|
+
event.preventDefault();
|
|
432
|
+
event.stopPropagation();
|
|
433
|
+
void unarchiveSelected();
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
399
436
|
if (event.ctrl && name === "g") {
|
|
400
437
|
event.preventDefault();
|
|
401
438
|
event.stopPropagation();
|
|
@@ -721,6 +758,23 @@ function createTuiRenderer() {
|
|
|
721
758
|
active: () => parsedQuery().effectiveMode !== "smart",
|
|
722
759
|
onClick: cycleMode,
|
|
723
760
|
}),
|
|
761
|
+
Pill({
|
|
762
|
+
label: () => `sort:${SEARCH_SORT_LABELS[sort()]}`,
|
|
763
|
+
shortcut: "^s",
|
|
764
|
+
active: () => sort() !== "updated",
|
|
765
|
+
onClick: cycleSort,
|
|
766
|
+
}),
|
|
767
|
+
createComponent(Show, {
|
|
768
|
+
get when() { return selectedMatch()?.session.archived; },
|
|
769
|
+
get children() {
|
|
770
|
+
return Pill({
|
|
771
|
+
label: () => restoring() ? "Restoring..." : "Unarchive",
|
|
772
|
+
shortcut: "^shift+a",
|
|
773
|
+
active: () => true,
|
|
774
|
+
onClick: () => void unarchiveSelected(),
|
|
775
|
+
});
|
|
776
|
+
},
|
|
777
|
+
}),
|
|
724
778
|
createComponent(Show, {
|
|
725
779
|
get when() {
|
|
726
780
|
return Boolean(parsedQuery().fileFilter);
|
|
@@ -898,7 +952,7 @@ function createTuiRenderer() {
|
|
|
898
952
|
isSelected() ? TextAttributes.BOLD : undefined,
|
|
899
953
|
},
|
|
900
954
|
() =>
|
|
901
|
-
`${isSelected() ? "▸ " : " "}${item.session.title}`
|
|
955
|
+
`${isSelected() ? "▸ " : " "}${item.session.archived ? "[Archived] " : ""}${item.session.title}`
|
|
902
956
|
),
|
|
903
957
|
el(
|
|
904
958
|
"text",
|
|
@@ -911,7 +965,7 @@ function createTuiRenderer() {
|
|
|
911
965
|
: theme().text.action.primary.base,
|
|
912
966
|
},
|
|
913
967
|
() =>
|
|
914
|
-
` [${item.matchBadge}] ${formatRelativeTime(item.session.timeUpdated)}`
|
|
968
|
+
` [${item.matchBadge}] ${formatRelativeTime(item.session.timeUpdated)}${sort() === "context" ? ` · context: ${item.session.contextTokens?.toLocaleString() ?? "not recorded"}` : sort() === "tokens" ? ` · total: ${item.session.totalTokens?.toLocaleString() ?? "not recorded"}` : ""}`
|
|
915
969
|
)
|
|
916
970
|
),
|
|
917
971
|
el(
|
|
@@ -1290,9 +1344,13 @@ function scrollToMatchedMessage(
|
|
|
1290
1344
|
(a.viewport?.width ?? 0) * (a.viewport?.height ?? 0)
|
|
1291
1345
|
);
|
|
1292
1346
|
const scrollBox = scrollBoxes[0];
|
|
1293
|
-
const
|
|
1347
|
+
const contentRoot =
|
|
1294
1348
|
typeof scrollBox.content?.getChildren === "function"
|
|
1295
|
-
? scrollBox.content
|
|
1349
|
+
? scrollBox.content
|
|
1350
|
+
: scrollBox;
|
|
1351
|
+
const topChildren =
|
|
1352
|
+
typeof contentRoot?.getChildren === "function"
|
|
1353
|
+
? contentRoot.getChildren()
|
|
1296
1354
|
: [];
|
|
1297
1355
|
if (!topChildren.length || (scrollBox.scrollHeight ?? 0) <= 0) {
|
|
1298
1356
|
return false;
|
|
@@ -1355,7 +1413,7 @@ function scrollToMatchedMessage(
|
|
|
1355
1413
|
walkContent(child);
|
|
1356
1414
|
}
|
|
1357
1415
|
};
|
|
1358
|
-
walkContent(
|
|
1416
|
+
walkContent(contentRoot);
|
|
1359
1417
|
|
|
1360
1418
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1361
1419
|
let targetNode: any = idMatchNode;
|