opencode-context-persistence 0.1.0 → 0.1.7
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/.github/workflows/publish.yml +1 -1
- package/package.json +2 -2
- package/src/index.ts +22 -19
- package/tests/index.test.ts +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-context-persistence",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "OpenCode plugin that re-injects AGENTS.md context after compaction to prevent context loss.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
|
-
"url": "https://github.com/alfonsodg/opencode-context-persistence.git"
|
|
24
|
+
"url": "git+https://github.com/alfonsodg/opencode-context-persistence.git"
|
|
25
25
|
},
|
|
26
26
|
"author": "Alfonso de la Guarda Reyes <alfonsodg@gmail.com>"
|
|
27
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,34 +2,37 @@ import type { Plugin } from "@opencode-ai/plugin"
|
|
|
2
2
|
import { readFileSync, existsSync } from "node:fs"
|
|
3
3
|
import { join } from "node:path"
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const plugin: Plugin = {
|
|
6
|
+
id: "context-persistence",
|
|
7
|
+
setup: async (ctx: { directory: string; worktree?: string }) => {
|
|
8
|
+
const agentsPath = join(ctx.worktree || ctx.directory, "AGENTS.md")
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const readAgents = (): string => {
|
|
11
|
+
try {
|
|
12
|
+
if (existsSync(agentsPath)) {
|
|
13
|
+
return readFileSync(agentsPath, "utf-8")
|
|
14
|
+
}
|
|
15
|
+
} catch {
|
|
16
|
+
// ignore read errors
|
|
12
17
|
}
|
|
13
|
-
|
|
14
|
-
// ignore read errors
|
|
18
|
+
return ""
|
|
15
19
|
}
|
|
16
|
-
return ""
|
|
17
|
-
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return {
|
|
22
|
+
"experimental.session.compacting": async (_input: any, output: any) => {
|
|
23
|
+
const agents = readAgents()
|
|
24
|
+
if (agents) {
|
|
25
|
+
output.context.push(`
|
|
24
26
|
## Re-injected AGENTS.md (context persistence)
|
|
25
27
|
The following rules were re-injected after compaction to prevent context loss.
|
|
26
28
|
Follow them without exception:
|
|
27
29
|
|
|
28
30
|
${agents}
|
|
29
31
|
`)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
},
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
export default
|
|
38
|
+
export default plugin
|
package/tests/index.test.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { describe, test, expect } from "bun:test"
|
|
2
2
|
|
|
3
|
-
describe("ContextPersistence plugin", () => {
|
|
4
|
-
test("module exports a default
|
|
3
|
+
describe("ContextPersistence plugin v2", () => {
|
|
4
|
+
test("module exports a default with id and setup", async () => {
|
|
5
5
|
const mod = await import("../src/index.ts")
|
|
6
|
-
expect(
|
|
6
|
+
expect(mod.default).toBeDefined()
|
|
7
|
+
expect(mod.default.id).toBe("context-persistence")
|
|
8
|
+
expect(typeof mod.default.setup).toBe("function")
|
|
7
9
|
})
|
|
8
10
|
})
|