@dzhi/ocpg 0.6.2 → 0.7.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 +15 -25
- package/ocpg.ts +8 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,41 +12,31 @@ In `opencode.json`:
|
|
|
12
12
|
```json
|
|
13
13
|
{
|
|
14
14
|
"plugin": [
|
|
15
|
-
|
|
15
|
+
"@dzhi/ocpg"
|
|
16
16
|
]
|
|
17
17
|
}
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
## Connecting to the database
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Configure the connection via environment variables, e.g. in `~/.zshenv`. Any Postgres user and database name will do — use whatever names fit your setup and mirror them here:
|
|
23
23
|
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"host": "localhost",
|
|
31
|
-
"port": 5432,
|
|
32
|
-
"user": "pguser",
|
|
33
|
-
"database": "agent-memory"
|
|
34
|
-
}
|
|
35
|
-
]
|
|
36
|
-
]
|
|
37
|
-
}
|
|
24
|
+
```bash
|
|
25
|
+
export OCPG_HOST="localhost"
|
|
26
|
+
export OCPG_PORT="5432"
|
|
27
|
+
export OCPG_USER="ocpguser"
|
|
28
|
+
export OCPG_PASSWORD="your-postgres-password"
|
|
29
|
+
export OCPG_DB="ocpg"
|
|
38
30
|
```
|
|
39
31
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
| `
|
|
45
|
-
| `
|
|
46
|
-
| `user` | `OCPG_USER` | `pguser` |
|
|
47
|
-
| `database` | `OCPG_DB` | `agent-memory` |
|
|
32
|
+
| Env var | Default |
|
|
33
|
+
| --------------- | ------------ |
|
|
34
|
+
| `OCPG_HOST` | `localhost` |
|
|
35
|
+
| `OCPG_PORT` | `5432` |
|
|
36
|
+
| `OCPG_USER` | `ocpguser` |
|
|
37
|
+
| `OCPG_DB` | `ocpg` |
|
|
48
38
|
|
|
49
|
-
**Password is
|
|
39
|
+
**Password is env-only.** If `OCPG_PASSWORD` is unset, the plugin falls back to `pass show postgres-workstation-password` at startup.
|
|
50
40
|
|
|
51
41
|
## Tools
|
|
52
42
|
|
package/ocpg.ts
CHANGED
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
import { SQL } from "bun";
|
|
3
3
|
import { Plugin } from "@opencode/plugin";
|
|
4
4
|
|
|
5
|
-
// --- DB config:
|
|
6
|
-
type
|
|
7
|
-
host
|
|
8
|
-
port
|
|
9
|
-
user
|
|
10
|
-
database
|
|
5
|
+
// --- DB config: env > defaults. Plugin options are not read; password is deliberately env-only (never in config).
|
|
6
|
+
type DbConfig = {
|
|
7
|
+
host: string;
|
|
8
|
+
port: number;
|
|
9
|
+
user: string;
|
|
10
|
+
database: string;
|
|
11
11
|
};
|
|
12
|
-
type DbConfig = Required<DbOptions>;
|
|
13
12
|
type RecallArgs = { query?: string; global?: boolean; limit?: number };
|
|
14
13
|
type RememberArgs = { content: string; tags?: string[] };
|
|
15
14
|
|
|
@@ -17,8 +16,8 @@ type RememberArgs = { content: string; tags?: string[] };
|
|
|
17
16
|
const defaultConfig: DbConfig = {
|
|
18
17
|
host: process.env.OCPG_HOST || "localhost",
|
|
19
18
|
port: Number(process.env.OCPG_PORT) || 5432,
|
|
20
|
-
user: process.env.OCPG_USER || "
|
|
21
|
-
database: process.env.OCPG_DB || "
|
|
19
|
+
user: process.env.OCPG_USER || "ocpguser",
|
|
20
|
+
database: process.env.OCPG_DB || "ocpg",
|
|
22
21
|
};
|
|
23
22
|
const password =
|
|
24
23
|
process.env.OCPG_PASSWORD ||
|
|
@@ -41,14 +40,6 @@ function makeSql(cfg: DbConfig): SQL {
|
|
|
41
40
|
|
|
42
41
|
let sql = makeSql(defaultConfig);
|
|
43
42
|
|
|
44
|
-
// Swap the pool when the plugin loads with config options ({ "package": "@dzhi/ocpg", "options": {...} } in opencode.jsonc).
|
|
45
|
-
// No-op without options so the module-level env/default config stands. Pools are lazy — a never-connected pool closes cleanly.
|
|
46
|
-
function reconfigure(options?: DbOptions): void {
|
|
47
|
-
if (!options) return;
|
|
48
|
-
void sql.close().catch(() => {});
|
|
49
|
-
sql = makeSql({ ...defaultConfig, ...options });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
43
|
export interface MemoryRow {
|
|
53
44
|
id: number;
|
|
54
45
|
content: string;
|
|
@@ -256,7 +247,6 @@ function invalidateInjection(sessionID: string): void {
|
|
|
256
247
|
const ocpg = Plugin.define({
|
|
257
248
|
id: "ocpg",
|
|
258
249
|
async setup(ctx) {
|
|
259
|
-
reconfigure(ctx.options as DbOptions | undefined);
|
|
260
250
|
const directory = ctx.location.directory;
|
|
261
251
|
|
|
262
252
|
// Inject project memories into every model request's system context.
|
|
@@ -320,7 +310,6 @@ const __internals = {
|
|
|
320
310
|
get sql() {
|
|
321
311
|
return sql;
|
|
322
312
|
},
|
|
323
|
-
reconfigure,
|
|
324
313
|
truncateMemory,
|
|
325
314
|
formatBlock,
|
|
326
315
|
handleTransform,
|