opencode-memsearch 0.3.0 → 0.4.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/README.md CHANGED
@@ -97,21 +97,27 @@ your-project/
97
97
 
98
98
  You should add `.memsearch/` to your `.gitignore`.
99
99
 
100
- ## Seed script
100
+ ## CLI
101
101
 
102
- The package includes a seed script that can backfill memory from existing OpenCode sessions. This is useful when first installing the plugin on a project you've already been working on.
102
+ The package includes a CLI for utility tasks. It requires [Bun](https://bun.sh/) to run.
103
103
 
104
- The seed script requires [Bun](https://bun.sh/) to run.
104
+ ```bash
105
+ bunx opencode-memsearch --help
106
+ ```
107
+
108
+ ### Seed
109
+
110
+ Backfill memory from existing OpenCode sessions. This is useful when first installing the plugin on a project you've already been working on.
105
111
 
106
112
  ```bash
107
113
  # Seed from the last 14 days of sessions (default)
108
- npx opencode-memsearch-seed
114
+ bunx opencode-memsearch seed
109
115
 
110
116
  # Seed from the last 30 days
111
- npx opencode-memsearch-seed --days 30
117
+ bunx opencode-memsearch seed --days 30
112
118
  ```
113
119
 
114
- Run the script from your project directory. It reads directly from the OpenCode SQLite database, summarizes each conversation turn, and writes the results to `.memsearch/memory/`. The seed script respects the same [configuration](#configuration) as the plugin (config file and environment variables).
120
+ The command reads directly from the OpenCode SQLite database, processes all sessions across all projects, summarizes each conversation turn, and writes the results to each project's `.memsearch/memory/` directory. It can be run from anywhere. The seed command respects the same [configuration](#configuration) as the plugin (config file and environment variables).
115
121
 
116
122
  ## Configuration
117
123
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-memsearch",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Persistent cross-session memory for OpenCode, powered by memsearch",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  }
13
13
  },
14
14
  "bin": {
15
- "opencode-memsearch-seed": "scripts/seed-memories.ts"
15
+ "opencode-memsearch": "scripts/cli.ts"
16
16
  },
17
17
  "files": [
18
18
  "dist",
package/scripts/cli.ts ADDED
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env bun
2
+ /**
3
+ * opencode-memsearch CLI — utilities for the opencode-memsearch plugin.
4
+ *
5
+ * Usage:
6
+ * bunx opencode-memsearch <command> [options]
7
+ *
8
+ * Requires Bun (https://bun.sh/) to run.
9
+ */
10
+
11
+ import { seed } from "./seed-memories"
12
+
13
+ const HELP = `opencode-memsearch — CLI utilities for the opencode-memsearch plugin
14
+
15
+ Usage:
16
+ opencode-memsearch <command> [options]
17
+
18
+ Commands:
19
+ seed Backfill memory from existing OpenCode sessions
20
+
21
+ Options:
22
+ --help, -h Show this help message
23
+
24
+ Run 'opencode-memsearch <command> --help' for command-specific help.`
25
+
26
+ const SEED_HELP = `Seed memsearch memory files from recent OpenCode sessions.
27
+
28
+ Reads all sessions from the OpenCode SQLite database, summarizes each
29
+ conversation turn via an LLM, and writes the results to each project's
30
+ .memsearch/memory/ directory. Processes all projects; can be run from anywhere.
31
+
32
+ Usage:
33
+ opencode-memsearch seed [--days <n>]
34
+
35
+ Options:
36
+ --days <n> Number of days of history to process (default: 14)
37
+ --help, -h Show this help message`
38
+
39
+ function parseSeedArgs(args: string[]): { days: number } {
40
+ let days = 14
41
+ for (let i = 0; i < args.length; i++) {
42
+ if (args[i] === "--days" && args[i + 1]) {
43
+ days = parseInt(args[i + 1], 10)
44
+ if (isNaN(days) || days < 1) {
45
+ console.error("Invalid --days value, using default 14")
46
+ days = 14
47
+ }
48
+ }
49
+ }
50
+ return { days }
51
+ }
52
+
53
+ async function main() {
54
+ const args = process.argv.slice(2)
55
+ const command = args[0]
56
+
57
+ if (!command || command === "--help" || command === "-h") {
58
+ console.log(HELP)
59
+ process.exit(0)
60
+ }
61
+
62
+ switch (command) {
63
+ case "seed": {
64
+ const subArgs = args.slice(1)
65
+ if (subArgs.includes("--help") || subArgs.includes("-h")) {
66
+ console.log(SEED_HELP)
67
+ process.exit(0)
68
+ }
69
+ const { days } = parseSeedArgs(subArgs)
70
+ await seed({ days })
71
+ break
72
+ }
73
+ default:
74
+ console.error(`Unknown command: ${command}`)
75
+ console.error()
76
+ console.log(HELP)
77
+ process.exit(1)
78
+ }
79
+ }
80
+
81
+ main().catch((err) => {
82
+ console.error("Fatal error:", err)
83
+ process.exit(1)
84
+ })
@@ -1,13 +1,9 @@
1
- #!/usr/bin/env bun
2
1
  /**
3
2
  * seed-memories.ts — Seed memsearch memory files from recent OpenCode sessions.
4
3
  *
5
- * Usage:
6
- * npx opencode-memsearch-seed [--days 14]
4
+ * This module exports a `seed` function used by the CLI (cli.ts).
7
5
  *
8
- * Requires Bun (https://bun.sh/) to run.
9
- *
10
- * This script:
6
+ * What it does:
11
7
  * 1. Reads session + message data directly from the OpenCode SQLite database
12
8
  * 2. For each session, formats each conversation turn as a transcript
13
9
  * 3. Summarizes each turn via `opencode run` (model is configurable, see README)
@@ -107,21 +103,6 @@ function formatTime(epochMs: number): string {
107
103
  return `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`
108
104
  }
109
105
 
110
- function parseArgs(): { days: number } {
111
- const args = process.argv.slice(2)
112
- let days = 14
113
- for (let i = 0; i < args.length; i++) {
114
- if (args[i] === "--days" && args[i + 1]) {
115
- days = parseInt(args[i + 1], 10)
116
- if (isNaN(days) || days < 1) {
117
- console.error("Invalid --days value, using default 14")
118
- days = 14
119
- }
120
- }
121
- }
122
- return { days }
123
- }
124
-
125
106
  // --- Database types ---
126
107
 
127
108
  interface DbSession {
@@ -354,8 +335,8 @@ async function summarizeWithOpencode(transcript: string, tempFile: string, model
354
335
 
355
336
  // --- Main ---
356
337
 
357
- async function main() {
358
- const { days } = parseArgs()
338
+ export async function seed(opts: { days: number }) {
339
+ const { days } = opts
359
340
  const cutoff = Date.now() - days * 24 * 60 * 60 * 1000
360
341
 
361
342
  console.log(`Seeding memories from the last ${days} days...`)
@@ -514,7 +495,4 @@ async function main() {
514
495
  }
515
496
  }
516
497
 
517
- main().catch((err) => {
518
- console.error("Fatal error:", err)
519
- process.exit(1)
520
- })
498
+