opencode-context-persistence 0.0.0-stage → 0.1.5

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.
@@ -0,0 +1,22 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-node@v4
18
+ with:
19
+ node-version: "24"
20
+ registry-url: "https://registry.npmjs.org"
21
+ - run: npm install
22
+ - run: npm publish --provenance --access public
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alfonso de la Guarda Reyes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
1
+ # opencode-context-persistence
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ OpenCode plugin that re-injects `AGENTS.md` context
4
+ after compaction to prevent context loss.
5
+
6
+ ## Problem
7
+
8
+ Long OpenCode sessions compact older conversation into a summary. When this
9
+ happens, project rules in `AGENTS.md` can be dropped, causing the agent to
10
+ forget mandates (issues-first, conventional commits, no hardcoded values, etc.).
11
+
12
+ ## Solution
13
+
14
+ This plugin hooks into `experimental.session.compacting` and injects the
15
+ contents of `AGENTS.md` into the compaction context, ensuring the rules
16
+ survive compaction.
17
+
18
+ ## Installation
19
+
20
+ ### From npm (when published)
21
+
22
+ ```json
23
+ {
24
+ "$schema": "https://opencode.ai/config.json",
25
+ "plugin": ["opencode-context-persistence"]
26
+ }
27
+ ```
28
+
29
+ ### From local files
30
+
31
+ Copy `src/index.ts` to `.opencode/plugins/context-persistence.ts` in your
32
+ project, or to `~/.config/opencode/plugins/context-persistence.ts` for global
33
+ use.
34
+
35
+ ## Usage
36
+
37
+ Place an `AGENTS.md` at your project root. The plugin reads it automatically
38
+ and re-injects it after every compaction.
39
+
40
+ ## License
41
+
42
+ MIT
package/package.json CHANGED
@@ -1,6 +1,27 @@
1
1
  {
2
2
  "name": "opencode-context-persistence",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.5",
4
+ "description": "OpenCode plugin that re-injects AGENTS.md context after compaction to prevent context loss.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "scripts": {
8
+ "build": "bun build src/index.ts --target bun --outfile dist/index.js",
9
+ "test": "bun test"
10
+ },
11
+ "dependencies": {
12
+ "@opencode-ai/plugin": "^1.19.0"
13
+ },
14
+ "keywords": [
15
+ "opencode",
16
+ "plugin",
17
+ "context",
18
+ "compaction",
19
+ "agents-md"
20
+ ],
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/alfonsodg/opencode-context-persistence.git"
25
+ },
26
+ "author": "Alfonso de la Guarda Reyes <alfonsodg@gmail.com>"
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,35 @@
1
+ import type { Plugin } from "@opencode-ai/plugin"
2
+ import { readFileSync, existsSync } from "node:fs"
3
+ import { join } from "node:path"
4
+
5
+ export const ContextPersistence: Plugin = async ({ directory, worktree }) => {
6
+ const agentsPath = join(worktree || directory, "AGENTS.md")
7
+
8
+ const readAgents = (): string => {
9
+ try {
10
+ if (existsSync(agentsPath)) {
11
+ return readFileSync(agentsPath, "utf-8")
12
+ }
13
+ } catch {
14
+ // ignore read errors
15
+ }
16
+ return ""
17
+ }
18
+
19
+ return {
20
+ "experimental.session.compacting": async (_input, output) => {
21
+ const agents = readAgents()
22
+ if (agents) {
23
+ output.context.push(`
24
+ ## Re-injected AGENTS.md (context persistence)
25
+ The following rules were re-injected after compaction to prevent context loss.
26
+ Follow them without exception:
27
+
28
+ ${agents}
29
+ `)
30
+ }
31
+ },
32
+ }
33
+ }
34
+
35
+ export default ContextPersistence
@@ -0,0 +1,8 @@
1
+ import { describe, test, expect } from "bun:test"
2
+
3
+ describe("ContextPersistence plugin", () => {
4
+ test("module exports a default function", async () => {
5
+ const mod = await import("../src/index.ts")
6
+ expect(typeof mod.default).toBe("function")
7
+ })
8
+ })