opencode-context-persistence 0.1.5 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-context-persistence",
3
- "version": "0.1.5",
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",
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
- export const ContextPersistence: Plugin = async ({ directory, worktree }) => {
6
- const agentsPath = join(worktree || directory, "AGENTS.md")
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
- const readAgents = (): string => {
9
- try {
10
- if (existsSync(agentsPath)) {
11
- return readFileSync(agentsPath, "utf-8")
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
- } catch {
14
- // ignore read errors
18
+ return ""
15
19
  }
16
- return ""
17
- }
18
20
 
19
- return {
20
- "experimental.session.compacting": async (_input, output) => {
21
- const agents = readAgents()
22
- if (agents) {
23
- output.context.push(`
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 ContextPersistence
38
+ export default plugin
@@ -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 function", async () => {
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(typeof mod.default).toBe("function")
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
  })