@broskees/opencode-codebase-graph 0.1.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.
Files changed (3) hide show
  1. package/README.md +61 -0
  2. package/index.ts +25 -0
  3. package/package.json +28 -0
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @broskees/opencode-codebase-graph
2
+
3
+ OpenCode plugin that injects a live codebase structural map into every LLM system prompt.
4
+
5
+ ## How It Works
6
+
7
+ 1. On plugin load, spawns `codebase-graph --watch` as a child process to keep `.codebase.md` up to date
8
+ 2. On every LLM call, reads `.codebase.md` from disk and pushes it onto the system prompt
9
+ 3. The agent always has a current structural map of the codebase — modules, symbols, hierarchies, dependencies
10
+
11
+ ## Installation
12
+
13
+ ### 1. Install the CLI tool
14
+
15
+ ```bash
16
+ pip install codebase-graph
17
+ ```
18
+
19
+ ### 2. Add the plugin to OpenCode
20
+
21
+ In your `opencode.json`:
22
+
23
+ ```json
24
+ {
25
+ "$schema": "https://opencode.ai/config.json",
26
+ "plugin": ["@broskees/opencode-codebase-graph"]
27
+ }
28
+ ```
29
+
30
+ That's it. The plugin auto-starts the watcher and injects the map on every LLM call.
31
+
32
+ ## Verifying It Works
33
+
34
+ 1. Start OpenCode in a project directory
35
+ 2. Check that `.codebase.md` appears in the project root (may take a moment on first run)
36
+ 3. The structural map is automatically included in every LLM call — no action needed
37
+
38
+ ## Troubleshooting
39
+
40
+ ### `.codebase.md` not appearing
41
+
42
+ - Ensure `codebase-graph` is in your PATH: `which codebase-graph`
43
+ - Try running it manually: `codebase-graph --watch --dir .`
44
+ - Check that the project directory contains supported files (`.py`, `.ts`, `.tsx`, `.js`, `.jsx`)
45
+
46
+ ### Plugin not loading
47
+
48
+ - Check OpenCode logs for plugin errors
49
+ - Ensure `@opencode-ai/plugin` peer dependency is satisfied
50
+
51
+ ## How It Integrates
52
+
53
+ ```
54
+ codebase-graph --watch → writes .codebase.md on disk
55
+
56
+ OpenCode plugin hook → reads .codebase.md on every LLM call
57
+
58
+ System prompt → agent sees live structural map
59
+ ```
60
+
61
+ The plugin is ~25 lines of TypeScript. All the heavy lifting (parsing, watching, TOON serialization) happens in the `codebase-graph` binary.
package/index.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { Plugin } from "@opencode-ai/plugin"
2
+ import { readFileSync } from "fs"
3
+ import { join } from "path"
4
+ import { spawn } from "child_process"
5
+
6
+ export const CodebaseGraph: Plugin = async ({ directory }) => {
7
+ const briefingPath = join(directory, ".codebase.md")
8
+
9
+ // Spawn watcher daemon — dies when plugin/OpenCode exits
10
+ spawn("codebase-graph", ["--watch", "--dir", directory], {
11
+ stdio: "ignore",
12
+ detached: false,
13
+ })
14
+
15
+ return {
16
+ "experimental.chat.system.transform": async (_incoming, output) => {
17
+ try {
18
+ const briefing = readFileSync(briefingPath, "utf-8")
19
+ output.system.push(briefing)
20
+ } catch {
21
+ // File doesn't exist yet (first index in progress), skip
22
+ }
23
+ },
24
+ }
25
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@broskees/opencode-codebase-graph",
3
+ "version": "0.1.0",
4
+ "description": "OpenCode plugin that injects a live codebase structural map into the system prompt",
5
+ "main": "index.ts",
6
+ "types": "index.ts",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/broskees/codebase-graph.git",
11
+ "directory": "plugins/opencode"
12
+ },
13
+ "keywords": [
14
+ "opencode",
15
+ "opencode-plugin",
16
+ "codebase",
17
+ "ai",
18
+ "coding-agent",
19
+ "structural-map"
20
+ ],
21
+ "files": [
22
+ "index.ts",
23
+ "README.md"
24
+ ],
25
+ "peerDependencies": {
26
+ "@opencode-ai/plugin": ">=1.0.0"
27
+ }
28
+ }