agentpostmortem 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.
package/INSTALL.md ADDED
@@ -0,0 +1,96 @@
1
+ # Installation Guide
2
+
3
+ ## npm (recommended)
4
+
5
+ ### 1. Add the plugin to your OpenCode config
6
+
7
+ In your project root, add the plugin to `opencode.json` (create the file if it doesn't exist):
8
+
9
+ ```json
10
+ {
11
+ "$schema": "https://opencode.ai/config.json",
12
+ "plugin": ["agentpostmortem"]
13
+ }
14
+ ```
15
+
16
+ OpenCode automatically installs npm plugins using Bun. No `npm install` or `bun install` needed in your project.
17
+
18
+ ### 2. Install command and skill templates (optional but recommended)
19
+
20
+ Run the init command to copy command wrappers and skill definitions into your project:
21
+
22
+ ```bash
23
+ npx --package agentpostmortem postmortem-init
24
+ ```
25
+
26
+ This copies:
27
+ - `.opencode/commands/*.md` — slash command wrappers (`/inspect`, `/retry`, `/failures`, etc.)
28
+ - `.opencode/skills/*/SKILL.md` — skill definitions for OpenCode agents
29
+ - `.opencode/postmortem.json` — empty per-project config stub
30
+
31
+ The init command is safe to re-run: it skips files that already exist.
32
+
33
+ ### 3. Restart OpenCode
34
+
35
+ The plugin loads at OpenCode startup. Restart OpenCode after adding it to the config.
36
+
37
+ ---
38
+
39
+ ## Local file install (fallback)
40
+
41
+ If you cannot use npm or prefer a self-contained setup, use the bundled plugin file.
42
+
43
+ ### 1. Download the bundled plugin
44
+
45
+ Get `dist/postmortem.plugin.js` from the npm CDN (or build it yourself: `bun run build`).
46
+ ```bash
47
+ curl -fsSL https://unpkg.com/agentpostmortem@latest/dist/postmortem.plugin.js -o postmortem.plugin.js
48
+ ```
49
+ ### 2. Place it in your project
50
+
51
+ ```bash
52
+ mkdir -p .opencode/plugins
53
+ cp postmortem.plugin.js .opencode/plugins/
54
+ ```
55
+
56
+ OpenCode automatically loads all `.js` and `.ts` files from `.opencode/plugins/`.
57
+
58
+ ### 3. Install templates
59
+
60
+ Run the init command (requires Node.js):
61
+
62
+ ```bash
63
+ npx --package agentpostmortem postmortem-init
64
+ ```
65
+
66
+ Or manually copy templates from the [src/templates/](src/templates/) directory.
67
+
68
+ ### 4. Restart OpenCode
69
+
70
+ ---
71
+
72
+ ## Per-project configuration
73
+
74
+ The plugin works out of the box with no configuration. By default, postmortem data is stored in your user data directory (scoped by project).
75
+
76
+ To enable repo-local storage (stored in `.opencode/postmortems/` inside your project), create or edit `.opencode/postmortem.json`:
77
+
78
+ ```json
79
+ {
80
+ "storage": "repo"
81
+ }
82
+ ```
83
+
84
+ > **Note**: Repo-local storage is only safe if `.opencode/` is not a symlink. The plugin checks this automatically.
85
+
86
+ ---
87
+
88
+ ## Verifying the install
89
+
90
+ In an OpenCode session, run:
91
+
92
+ ```
93
+ tool: postmortem_config --action show --json
94
+ ```
95
+
96
+ You should see the config, storage path, and project ID.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tpypan
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 ADDED
@@ -0,0 +1,116 @@
1
+ # AgentPostmortem
2
+
3
+ `agentpostmortem` adds a complete postmortem loop to OpenCode: capture failures, analyze root causes, create guardrails, and retry with context-aware constraints.
4
+
5
+ This repository is the standalone plugin distribution (not the OpenCode source tree).
6
+
7
+ ## Why this plugin is useful
8
+
9
+ - Persist failure history across sessions instead of losing context after one run.
10
+ - Generate deterministic failure analysis and reusable prevention rules.
11
+ - Keep retries bounded and explainable (`/retry --explain`).
12
+ - Evaluate repeat-failure trends locally (`/postmortem-eval`) without telemetry.
13
+
14
+ ## What this plugin adds
15
+
16
+ - `postmortem_inspect`: view the latest redacted last-run snapshot
17
+ - `postmortem_record_failure`: persist a durable failure record
18
+ - `postmortem_why_failed`: deterministic analysis + 1-3 prevention rules
19
+ - `postmortem_rules`: list/show/enable/disable/edit/rate/import rules
20
+ - `postmortem_failures`: list/show/forget/delete/prune/purge failures
21
+ - `postmortem_retry`: generate a retry prompt with relevant guardrails (`--explain` supported)
22
+ - `postmortem_disable_lessons`: disable/enable injection for the current session
23
+ - `postmortem_config`: show/set storage mode (`user` or `repo`)
24
+ - `postmortem_eval`: local-only repeat-failure evaluation metrics
25
+
26
+ ## Install
27
+
28
+ See [INSTALL.md](INSTALL.md) for full setup.
29
+
30
+ Quick start:
31
+
32
+ 1. Add "agentpostmortem" to your `opencode.json` plugin array.
33
+ 2. Run `npx --package agentpostmortem postmortem-init` in your project.
34
+ 3. Restart OpenCode.
35
+
36
+ ## Usage examples
37
+
38
+ The sections below show realistic command sequences you can run in OpenCode.
39
+ For the full per-command catalog, see [commands.md](examples/minimal/commands.md).
40
+
41
+ ### 1) Capture and analyze a failure in minutes
42
+
43
+ ```text
44
+ /inspect --json --errors
45
+ /record-failure --yes --json
46
+ /why-failed --latest --json
47
+ ```
48
+
49
+ Use this when a run fails and you want a durable record plus deterministic hypotheses before trying fixes.
50
+
51
+ ### 2) Build guardrails, then retry with context
52
+
53
+ ```text
54
+ /rules --action list --json
55
+ /retry --explain
56
+ /retry --yes
57
+ ```
58
+
59
+ This sequence helps you review active rules, see why each rule was selected, then execute a guarded retry prompt.
60
+
61
+ ### 3) Tune behavior during a long debugging session
62
+
63
+ ```text
64
+ /disable-lessons --json
65
+ /disable-lessons --enable --json
66
+ /postmortem-config --action show --json
67
+ ```
68
+
69
+ Use `/disable-lessons` when you want a temporary clean session, then re-enable guardrail injection when you are ready.
70
+
71
+ ### 4) Manage failure memory and clean up stale records
72
+
73
+ ```text
74
+ /failures --action list --json
75
+ /failures --action show --id <failure-id> --json
76
+ /forget <failure-id>
77
+ ```
78
+
79
+ You can inspect specific incidents and retire low-value memory entries while preserving the rest of your history.
80
+
81
+ ### 5) Evaluate if failures are repeating
82
+
83
+ ```text
84
+ /postmortem-eval --json --window 20
85
+ ```
86
+
87
+ This reports repeat-failure metrics so you can measure whether new rules are reducing recurrence.
88
+
89
+ ## Examples folder
90
+
91
+ - `examples/minimal/opencode.json` - minimal plugin config for a project
92
+ - `examples/minimal/README.md` - minimal setup walkthrough and file map
93
+ - `examples/minimal/commands.md` - full flag-by-flag reference for every command
94
+ - `examples/minimal/playbooks.md` - end-to-end incident response and maintenance workflows
95
+ - `examples/minimal/commands/` - per-command deep-dive examples
96
+
97
+ ## Repository layout
98
+
99
+ - `src/` - plugin implementation (TypeScript source)
100
+ - `src/templates/` - command and skill templates copied by `postmortem-init`
101
+ - `test/` - test suite
102
+ - `scripts/` - init script source
103
+ - `examples/` - runnable configuration and command examples
104
+ - `dist/` - build output (npm ESM + bundled fallback)
105
+
106
+ ## Storage and safety
107
+
108
+ - Default storage is user-data scoped by project ID.
109
+ - Optional repo-local storage can be enabled with `.opencode/postmortem.json` and `{ "storage": "repo" }`.
110
+ - Redaction and caps are applied before persistence and before display/injection.
111
+
112
+ ## References
113
+
114
+ - Plugins docs: https://opencode.ai/docs/plugins
115
+ - Commands docs: https://opencode.ai/docs/commands
116
+ - Skills docs: https://opencode.ai/docs/skills