@bojackduy/opencode-telescope 0.1.19 → 0.1.20
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/package.json +1 -1
- package/search.ts +26 -4
- package/telescope.tsx +2 -0
- package/tui.tsx +6 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@bojackduy/opencode-telescope",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.20",
|
|
5
5
|
"description": "Fuzzy search across all OpenCode conversations — grep session and chat history, find code snippets, and jump to any chat instantly",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|
package/search.ts
CHANGED
|
@@ -631,12 +631,31 @@ function indexedTextRows(db: Database, dbPath: string, limit: number, query: str
|
|
|
631
631
|
|
|
632
632
|
function indexedRecentRows(db: Database, dbPath: string, limit: number, directory?: string, offset?: number, role?: SearchRole) {
|
|
633
633
|
try {
|
|
634
|
-
const index = ensureSearchIndex(db, dbPath, { rebuild: false })
|
|
634
|
+
const index = ensureSearchIndex(db, dbPath, { rebuild: false, useStale: true })
|
|
635
635
|
if (!index) {
|
|
636
|
-
|
|
636
|
+
debug.log("query:recent:index:missing", { dbPath })
|
|
637
637
|
return
|
|
638
638
|
}
|
|
639
639
|
|
|
640
|
+
const rowCount = index.query<{ count: number }, []>("SELECT COUNT(*) as count FROM document_index").get()?.count ?? 0
|
|
641
|
+
if (rowCount === 0) {
|
|
642
|
+
debug.log("query:recent:index:empty", { dbPath })
|
|
643
|
+
return
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
const state = sourceState(db, dbPath)
|
|
647
|
+
const currentDataVersion = getMeta(index, "source_data_version")
|
|
648
|
+
const currentMtimeMs = getMeta(index, "source_mtime_ms")
|
|
649
|
+
const currentPath = getMeta(index, "source_path")
|
|
650
|
+
const currentIndexVersion = getMeta(index, "index_version")
|
|
651
|
+
if (currentPath !== dbPath || currentDataVersion !== String(state.dataVersion) || currentMtimeMs !== String(state.mtimeMs) || currentIndexVersion !== SEARCH_INDEX_VERSION) {
|
|
652
|
+
debug.log("query:recent:index:stale", {
|
|
653
|
+
dbPath,
|
|
654
|
+
expectedDataVersion: state.dataVersion,
|
|
655
|
+
actualDataVersion: currentDataVersion,
|
|
656
|
+
})
|
|
657
|
+
}
|
|
658
|
+
|
|
640
659
|
const conditions: string[] = ["part_type = 'text'"]
|
|
641
660
|
const params: (string | number)[] = []
|
|
642
661
|
if (role) {
|
|
@@ -711,7 +730,7 @@ function visibleTextRows(db: Database, limit: number, query?: string, directory?
|
|
|
711
730
|
return rows
|
|
712
731
|
}
|
|
713
732
|
|
|
714
|
-
function ensureSearchIndex(source: Database, sourcePath: string, options?: { rebuild?: boolean }) {
|
|
733
|
+
function ensureSearchIndex(source: Database, sourcePath: string, options?: { rebuild?: boolean; useStale?: boolean }) {
|
|
715
734
|
const indexPath = searchIndexPath(sourcePath)
|
|
716
735
|
if (!_indexDb || _indexDbPath !== indexPath) {
|
|
717
736
|
_indexDb?.close()
|
|
@@ -726,7 +745,10 @@ function ensureSearchIndex(source: Database, sourcePath: string, options?: { reb
|
|
|
726
745
|
const currentPath = getMeta(_indexDb, "source_path")
|
|
727
746
|
const currentIndexVersion = getMeta(_indexDb, "index_version")
|
|
728
747
|
if (currentPath !== sourcePath || currentDataVersion !== String(state.dataVersion) || currentMtimeMs !== String(state.mtimeMs) || currentIndexVersion !== SEARCH_INDEX_VERSION) {
|
|
729
|
-
if (options?.rebuild === false)
|
|
748
|
+
if (options?.rebuild === false) {
|
|
749
|
+
if (options?.useStale) return _indexDb
|
|
750
|
+
return
|
|
751
|
+
}
|
|
730
752
|
rebuildSearchIndex(source, _indexDb, sourcePath, state)
|
|
731
753
|
}
|
|
732
754
|
return _indexDb
|
package/telescope.tsx
CHANGED
|
@@ -23,6 +23,7 @@ import { inputSafeKeys, keyListLabel, matchesKey, prevent } from "./ui/keyboard.
|
|
|
23
23
|
import { findRenderableByID, jumpToRenderedTarget, messageTargetID, previewScrollAmount, scrollPreviewToTarget } from "./ui/render-target.ts"
|
|
24
24
|
|
|
25
25
|
export const Telescope = (props: { api: TuiPluginApi; config: TelescopeConfig; onClose: () => void }) => {
|
|
26
|
+
debug.log("component:render:start")
|
|
26
27
|
type OwnerFilter = "all" | SearchRole
|
|
27
28
|
const dimensions = useTerminalDimensions()
|
|
28
29
|
const [query, setQuery] = createSignal("")
|
|
@@ -217,6 +218,7 @@ export const Telescope = (props: { api: TuiPluginApi; config: TelescopeConfig; o
|
|
|
217
218
|
}
|
|
218
219
|
debug.timeEnd("query:recent")
|
|
219
220
|
setLoading(false)
|
|
221
|
+
debug.log("component:interactive")
|
|
220
222
|
}, 1)
|
|
221
223
|
onCleanup(() => clearTimeout(timer))
|
|
222
224
|
return
|
package/tui.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @jsxImportSource @opentui/solid */
|
|
2
2
|
import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui"
|
|
3
3
|
import { Telescope } from "./telescope.tsx"
|
|
4
|
+
import { debug } from "./ui/debug.ts"
|
|
4
5
|
import { loadTelescopeConfig } from "./ui/config.ts"
|
|
5
6
|
|
|
6
7
|
const id = "opencode-telescope"
|
|
@@ -12,15 +13,19 @@ const enabled = (options: unknown) => {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
const tui: TuiPlugin = async (api: TuiPluginApi, options: unknown) => {
|
|
16
|
+
debug.log("plugin:setup:start")
|
|
15
17
|
if (!enabled(options)) return
|
|
16
18
|
|
|
17
19
|
const config = loadTelescopeConfig()
|
|
18
20
|
const command = "opencode.telescope.sessions"
|
|
19
21
|
const open = () => {
|
|
22
|
+
debug.log("plugin:dialog:open:start")
|
|
20
23
|
api.ui.dialog.replace(() => <Telescope api={api} config={config} onClose={() => api.ui.dialog.clear()} />)
|
|
21
24
|
api.ui.dialog.setSize("xlarge")
|
|
25
|
+
debug.log("plugin:dialog:open:done")
|
|
22
26
|
}
|
|
23
27
|
|
|
28
|
+
debug.log("plugin:setup:register-keymap")
|
|
24
29
|
const unregisterKeymap = api.keymap.registerLayer({
|
|
25
30
|
commands: [
|
|
26
31
|
{
|
|
@@ -38,6 +43,7 @@ const tui: TuiPlugin = async (api: TuiPluginApi, options: unknown) => {
|
|
|
38
43
|
api.lifecycle.onDispose(() => {
|
|
39
44
|
unregisterKeymap()
|
|
40
45
|
})
|
|
46
|
+
debug.log("plugin:setup:done")
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
const plugin: TuiPluginModule & { id: string } = {
|