@pipemd-core/pipemd 1.0.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 (96) hide show
  1. package/AI_SETUP_PIPEMD.md +184 -0
  2. package/CHANGELOG.md +47 -0
  3. package/LICENSE +15 -0
  4. package/README.md +535 -0
  5. package/dist/index.js +6647 -0
  6. package/dist/plugins/opencode-server.js +235 -0
  7. package/dist/plugins/opencode-tui.js +914 -0
  8. package/dist/templates/agent-decision-tree.md +113 -0
  9. package/dist/templates/static-rules.md +7 -0
  10. package/package.json +68 -0
  11. package/scripts/C-CPP/architecture/arch.sh +229 -0
  12. package/scripts/C-CPP/lib/limit.sh +146 -0
  13. package/scripts/C-CPP/project/class-diagram.sh +96 -0
  14. package/scripts/C-CPP/project/cmake-targets.sh +68 -0
  15. package/scripts/C-CPP/project/deps.sh +44 -0
  16. package/scripts/C-CPP/project/find-todos.sh +6 -0
  17. package/scripts/C-CPP/project/include-graph.sh +110 -0
  18. package/scripts/C-CPP/project/interfaces.sh +108 -0
  19. package/scripts/C-CPP/project/tree.sh +5 -0
  20. package/scripts/C-CPP/quality/lint.sh +14 -0
  21. package/scripts/C-CPP/quality/test-summary.sh +22 -0
  22. package/scripts/C-CPP/quality/type-check.sh +26 -0
  23. package/scripts/DevOps/architecture/arch.sh +186 -0
  24. package/scripts/DevOps/devops/aws-context.sh +34 -0
  25. package/scripts/DevOps/devops/docker-stats.sh +42 -0
  26. package/scripts/DevOps/devops/k8s-unhealthy.sh +41 -0
  27. package/scripts/DevOps/devops/tf-state.sh +65 -0
  28. package/scripts/DevOps/lib/limit.sh +143 -0
  29. package/scripts/Generic/architecture/arch.sh +570 -0
  30. package/scripts/Generic/lib/limit.sh +140 -0
  31. package/scripts/Go/architecture/arch.sh +79 -0
  32. package/scripts/Go/lib/limit.sh +142 -0
  33. package/scripts/Go/project/deps.sh +35 -0
  34. package/scripts/Go/project/find-todos.sh +6 -0
  35. package/scripts/Go/project/go-interfaces.sh +18 -0
  36. package/scripts/Go/project/go-packages.sh +28 -0
  37. package/scripts/Go/project/tree.sh +5 -0
  38. package/scripts/Go/quality/lint.sh +16 -0
  39. package/scripts/Go/quality/test-summary.sh +16 -0
  40. package/scripts/Go/quality/type-check.sh +16 -0
  41. package/scripts/Node-TypeScript/api/express-routes.sh +14 -0
  42. package/scripts/Node-TypeScript/api/nest-controllers.sh +18 -0
  43. package/scripts/Node-TypeScript/architecture/arch.sh +174 -0
  44. package/scripts/Node-TypeScript/frontend/angular-routes.sh +15 -0
  45. package/scripts/Node-TypeScript/frontend/nextjs-app-router.sh +13 -0
  46. package/scripts/Node-TypeScript/frontend/react-components.sh +20 -0
  47. package/scripts/Node-TypeScript/lib/limit.sh +146 -0
  48. package/scripts/Node-TypeScript/project/deps.sh +15 -0
  49. package/scripts/Node-TypeScript/project/find-todos.sh +6 -0
  50. package/scripts/Node-TypeScript/quality/lint.sh +10 -0
  51. package/scripts/Node-TypeScript/quality/test-summary.sh +39 -0
  52. package/scripts/Node-TypeScript/quality/type-check.sh +10 -0
  53. package/scripts/Python/api/fastapi-routes.sh +12 -0
  54. package/scripts/Python/architecture/arch.sh +220 -0
  55. package/scripts/Python/db/django-models.sh +12 -0
  56. package/scripts/Python/db/sqlalchemy.sh +17 -0
  57. package/scripts/Python/lib/limit.sh +144 -0
  58. package/scripts/Python/project/deps.sh +28 -0
  59. package/scripts/Python/project/find-todos.sh +6 -0
  60. package/scripts/Python/quality/lint.sh +13 -0
  61. package/scripts/Python/quality/test-summary.sh +11 -0
  62. package/scripts/Python/quality/type-check.sh +10 -0
  63. package/scripts/Rust/architecture/arch.sh +176 -0
  64. package/scripts/Rust/lib/limit.sh +142 -0
  65. package/scripts/Rust/project/cargo-deps.sh +42 -0
  66. package/scripts/Rust/project/cargo-features.sh +26 -0
  67. package/scripts/Rust/project/find-todos.sh +6 -0
  68. package/scripts/Rust/project/tree.sh +5 -0
  69. package/scripts/Rust/quality/lint.sh +16 -0
  70. package/scripts/Rust/quality/test-summary.sh +16 -0
  71. package/scripts/Rust/quality/type-check.sh +16 -0
  72. package/scripts/Shared/api/express-routes.sh +11 -0
  73. package/scripts/Shared/api/fastapi-routes.sh +10 -0
  74. package/scripts/Shared/api/nest-controllers.sh +22 -0
  75. package/scripts/Shared/architecture/normalize.sh +178 -0
  76. package/scripts/Shared/crew/crew.sh +15 -0
  77. package/scripts/Shared/db/django-models.sh +11 -0
  78. package/scripts/Shared/db/prisma.sh +33 -0
  79. package/scripts/Shared/db/sqlalchemy.sh +12 -0
  80. package/scripts/Shared/frontend/angular-routes.sh +11 -0
  81. package/scripts/Shared/frontend/nextjs-app-router.sh +13 -0
  82. package/scripts/Shared/frontend/react-components.sh +11 -0
  83. package/scripts/Shared/git/diff-stat.sh +6 -0
  84. package/scripts/Shared/git/git-branch.sh +16 -0
  85. package/scripts/Shared/git/git-log.sh +6 -0
  86. package/scripts/Shared/git/git-status.sh +6 -0
  87. package/scripts/Shared/lib/limit.sh +144 -0
  88. package/scripts/Shared/project/compose-md.sh +182 -0
  89. package/scripts/Shared/project/deps.sh +69 -0
  90. package/scripts/Shared/project/find-todos.sh +6 -0
  91. package/scripts/Shared/project/tree.sh +5 -0
  92. package/scripts/Shared/quality/lint.sh +81 -0
  93. package/scripts/Shared/quality/test-summary.sh +103 -0
  94. package/scripts/Shared/quality/type-check.sh +114 -0
  95. package/scripts/copy-plugins.mjs +4 -0
  96. package/scripts/copy-templates.mjs +5 -0
@@ -0,0 +1,184 @@
1
+ # PipeMD Context Reference
2
+
3
+ > This file explains how PipeMD context files work so AI agents can read, edit, and improve them effectively.
4
+
5
+ ## How the Context File Works
6
+
7
+ PipeMD maintains a live context file (e.g. `AGENTS.md`, `CLAUDE.md`) that AI agents read for project information. The daemon refreshes `<!-- pmd: -->` blocks on every cycle with up-to-date data from bash scripts (tree, git status, deps, lint errors, etc.).
8
+
9
+ ## File Structure
10
+
11
+ The context file has two zones separated by `<!-- pmd-context -->`:
12
+
13
+ ```
14
+ ┌─────────────────────────────────────┐
15
+ │ Base section (above separator) │
16
+ │ ─ editable, routes to base.md │
17
+ │ ─ rules, notes, instructions │
18
+ ├─────────────────────────────────────┤
19
+ │ <!-- pmd-context --> │
20
+ ├─────────────────────────────────────┤
21
+ │ Template section (below separator) │
22
+ │ ─ contains <!-- pmd: --> blocks │
23
+ │ ─ editable outside those blocks │
24
+ │ ─ edits route to template.md │
25
+ └─────────────────────────────────────┘
26
+ ```
27
+
28
+ ### Edit Routing
29
+
30
+ | Where you edit | Where it persists |
31
+ |---|---|
32
+ | Above `<!-- pmd-context -->` | `.pipemd/base.md` |
33
+ | Below `<!-- pmd-context -->`, outside `<!-- pmd: -->` blocks | `.pipemd/template.md` via reverseInject |
34
+ | Inside `<!-- pmd: -->` blocks | **Nowhere** — overwritten every cycle |
35
+
36
+ ## What You Can and Cannot Edit
37
+
38
+ **Can edit:**
39
+ - Rules, notes, and checkboxes above `<!-- pmd-context -->` — these persist in `base.md`
40
+ - Section headers, labels, and any content below `<!-- pmd-context -->` that is outside `<!-- pmd: -->` blocks — these persist in `template.md`
41
+
42
+ **Cannot edit:**
43
+ - Anything inside `<!-- pmd: ... -->` ... `<!-- /pmd -->` blocks — the daemon overwrites these on every refresh cycle. Your edits will be lost.
44
+
45
+ ## Volatility and Cache Optimization
46
+
47
+ Content is ordered by volatility so that LLM Prompt Prefix Caching works efficiently:
48
+
49
+ | Volatility | Meaning | Examples |
50
+ |---|---|---|
51
+ | 1 | Rarely changes | `arch`, `tree`, `deps` |
52
+ | 2 | Changes on commit | `todos`, `git-log`, `git-branch`, `type-check` |
53
+ | 3 | Changes on file save | `git-status` |
54
+ | 4 | Changes continuously | `diff-stat` |
55
+
56
+ Stable content (volatility 1-2) goes in the **Project Context** section at the top. Rapidly changing content (volatility 3-4) goes in the **Volatile State** section at the bottom. This minimizes cache invalidation — the top portion stays identical across reads.
57
+
58
+ ## Self-Improvement
59
+
60
+ You can improve this context file over time:
61
+
62
+ - **Edit rules above `<!-- pmd-context -->`** to refine your own instructions (persists in `base.md`)
63
+ - **Reorder or relabel sections below `<!-- pmd-context -->`** to change context priority (persists in `template.md`)
64
+ - **Add or remove `<!-- pmd: -->` blocks** in `.pipemd/template.md` to tune what data you receive
65
+ - **Adjust volatility** in `.pipemd/config.yml` to control cache stability
66
+ - **Change token profile** in `.pipemd/config.yml` if context is too long or too sparse
67
+ - **Add or remove scripts** in `.pipemd/config.yml` to change what data the daemon collects
68
+
69
+ ## Working Alongside Other Agents (Crew)
70
+
71
+ If this project uses PipeMD Crew, a **Crew Activity** block appears in the
72
+ context file showing every agent currently working the repo, the files each
73
+ has claimed, and any conflicts. The coordination model is
74
+ **Harness → Coordinator → sub-agents** — one coordinator per harness, with
75
+ PipeMD as the neutral meta-coordinator that renders the union.
76
+
77
+ **Before editing a file, check the Crew Activity block.** A `⚠️ CONFLICT` line
78
+ means another agent has claimed a file you are about to touch — coordinate or
79
+ pick different work; treat it as blocking.
80
+
81
+ Report your own work so other agents see it:
82
+
83
+ ```bash
84
+ pmd crew claim src/auth.ts --note "refactoring login" # claim files you're editing
85
+ pmd crew note "running the test suite" # post your current task
86
+ pmd crew release src/auth.ts # release when done
87
+ pmd crew status # see the whole crew
88
+ ```
89
+
90
+ If edit hooks were installed (`pmd crew install-hooks`), claims happen
91
+ automatically on every file edit — no manual calls needed. Sub-agents that need
92
+ their own session call `pmd crew join --role worker` and export the printed
93
+ `PMD_SESSION` value.
94
+
95
+ ## Smart Context Injection
96
+
97
+ If this project uses **Active** or **Expert** delivery mode, PipeMD installs hooks that inject fresh context into your working memory on every tool call. This means you don't need to re-read the context file to see updated state — the latest information is delivered to you automatically.
98
+
99
+ ### What you'll see
100
+
101
+ On tool calls, you may see messages like:
102
+
103
+ ```
104
+ [pmd:crew-locks → src/foo.ts]
105
+ File src/foo.ts: claimed by Claude Code (cr_abc123) 30s ago
106
+ ```
107
+
108
+ ```
109
+ [pmd:file-errors → src/foo.ts]
110
+ No known errors in src/foo.ts
111
+ ```
112
+
113
+ ```
114
+ [pmd:validate-file → src/foo.ts]
115
+ After your edit to src/foo.ts: No errors found
116
+ ```
117
+
118
+ ### When context is injected
119
+
120
+ | What you're doing | What gets injected |
121
+ |---|---|
122
+ | Reading a file | Crew status (who's working, any conflicts) |
123
+ | Editing a file | Crew locks for that file, lint/type errors for that file, git context |
124
+ | Just edited a file | Validation results (lint + type-check) on next tool call |
125
+ | Idle | Crew status changes, git delta |
126
+
127
+ ### How to use this
128
+
129
+ - **Before editing**: check the injected crew locks. If a file is claimed by another agent, coordinate or pick different work.
130
+ - **After editing**: the validation result appears on your next tool call. If errors remain, fix them.
131
+ - **You don't need to do anything** — injection is automatic and deduplicated (unchanged data is skipped).
132
+
133
+ ### Configuration
134
+
135
+ Injection rules live in `.pipemd/injection.yml`. In Active mode, sensible defaults are pre-configured. In Expert mode, you can customize triggers, sources, scopes, and limits.
136
+
137
+ ## Configuration Files
138
+
139
+ | File | Purpose |
140
+ |---|---|
141
+ | `.pipemd/config.yml` | Daemon config: scripts, pipes, token profile, target files |
142
+ | `.pipemd/template.md` | Template with `<!-- pmd: -->` block placement and section structure |
143
+ | `.pipemd/base.md` | Your editable rules and instructions (prepended to served context) |
144
+ | `.pipemd/injection.yml` | Smart injection rules: triggers, sources, scopes (Active/Expert mode) |
145
+ | `.pipemd/scripts/` | Bash scripts that generate the live data |
146
+
147
+ ## CLI Reference
148
+
149
+ ```bash
150
+ pmd init --headless # Auto-detect ecosystem, harnesses, scripts; configure everything
151
+ pmd start # Start the daemon (serves context via named pipes or file-watch)
152
+ pmd stop # Stop the daemon
153
+ pmd restart # Restart (reloads config.yml)
154
+ pmd status # Check if daemon is running
155
+ pmd run # One-shot render to stdout (no daemon)
156
+ pmd refresh # Sync bundled scripts; add newly available ones
157
+ pmd doctor # Diagnose common issues
158
+ pmd inject --trigger before-edit --file src/foo.ts # (internal) Resolve injection payloads for a trigger
159
+ pmd crew status # Show agents currently coordinating on this repo
160
+ ```
161
+
162
+ ### Custom Init Options
163
+
164
+ ```bash
165
+ pmd init --headless --harnesses OpenCode,"Claude Code" # Override auto-detected harnesses
166
+ pmd init --headless --ecosystem Python # Force a specific ecosystem
167
+ pmd init --headless --scripts tree,git-status,deps,todos # Pick specific scripts
168
+ ```
169
+
170
+ ## After Setup: Reading the Context
171
+
172
+ The target file depends on your harness:
173
+
174
+ | Harness | Target file |
175
+ |---|---|
176
+ | OpenCode | `AGENTS.md` |
177
+ | Claude Code | `CLAUDE.md` |
178
+ | Cursor | `.cursorrules` |
179
+ | Gemini | `AI_CONTEXT.md` |
180
+ | Aider | `CONVENTIONS.md` |
181
+ | OpenClaw / Hermes | `WORKSPACE_CONTEXT.md` |
182
+ | OS Agent (fallback) | `AGENTS.md` |
183
+
184
+ After `pmd init --headless`, look for `PIPEDM_HEADLESS_RESULT=` in stdout for a JSON summary with `targetFiles`, `scripts`, `ecosystem`, and `profile`.
package/CHANGELOG.md ADDED
@@ -0,0 +1,47 @@
1
+ # Changelog
2
+
3
+ All notable changes to PipeMD.
4
+
5
+ ## [1.0.0] — 2026-05-21
6
+
7
+ ### Added
8
+
9
+ - **Render-on-read daemon** — serves live context via OS-level named pipes (`mkfifo`)
10
+ - **Smart Context Injection** — event-driven, per-file context payloads delivered via harness hooks on `before-read`, `before-edit`, `after-edit`, `on-idle` triggers
11
+ - **Three delivery modes** — Passive (render-only), Active (hooks + sensible defaults), Expert (full `injection.yml` customization)
12
+ - **Bidirectional write-back** — AI edits outside `<!-- pmd: -->` blocks persist to disk; `reverseInject` de-renders blocks back to template form
13
+ - **Crew coordination** — multi-harness parallel-worker coordination with per-session JSON ledger, file claiming, conflict detection, and passive agent awareness
14
+ - **OpenCode TUI sidebar panel** — real-time PipeMD status, crew sessions, injection stats, hook event log rendered via `@opentui/solid` programmatic API
15
+ - **Architecture visualization** — Mermaid `graph TD` dependency diagrams for 7 ecosystems (Node/TypeScript, Python, Rust, Go, C/C++, DevOps, Generic)
16
+ - **Compose-md** — doc-assembly from multiple templates into one context file
17
+ - **Agent/File mode** — `pmd init` branches into Agent mode (daemon + pipes) or File mode (`pmd run` for CI/docs)
18
+ - **Headless mode** — `--yes`, `--mode`, `--output` flags for non-interactive CI usage
19
+ - **Auto-detection** — ecosystem detection (`detect.ts`) and AI harness detection (`detectHarness.ts`) for Claude Code, Gemini CLI, OpenCode, Cursor, Aider
20
+ - **Full harness hook coverage:**
21
+ - Claude Code: 7 events (SessionStart, PreToolUse, PostToolUse, SubagentStart, SubagentStop, Stop, SessionEnd)
22
+ - OpenCode: 3 handlers (tool.execute.before, tool.execute.after, session.idle) + server plugin v9 with injection tracking
23
+ - Gemini CLI: 2 events (BeforeTool, AfterTool) with `--format gemini-json`
24
+ - **`pmd inject` command** — internal command resolving injection payloads; `--format` (plain, claude-hook, gemini-json), `--async-validate` self-spawn, `--session` dedup
25
+ - **Per-session deduplication** — content-hash based dedup across tool calls; stable session identity via `resolveAgentIdentity()` (process tree walk)
26
+ - **Async validation** — `--async-validate` spawns detached child for lint/type-check, returns immediately (doesn't block agent)
27
+ - **Script library** — 84 bash/python scripts across 8 categories (project, git, quality, architecture, db, api, frontend, cpp) for 7 ecosystems
28
+ - **`pmd doctor`** — diagnostics for daemon, config, scripts, crew sessions, hooks, injection config
29
+ - **`pmd status`** — daemon health, active pipes, last render time
30
+ - **`pmd refresh`** — sync scripts, add new ones without re-init
31
+ - **`pmd uninstall`** — clean removal with context backup/restore
32
+ - **Base/template separation** — `base.md` holds agent-authored instructions; `template.md` holds pmd blocks; composed with separator
33
+ - **Prompt cache optimization** — static rules at top, volatile data at bottom, ordered for LLM prefix cache warmth
34
+ - **Windows fallback** — legacy mode via chokidar file watcher when `mkfifo` unavailable
35
+ - **Security** — `execFileSync` with arg arrays everywhere (OpenCode plugin, eslint, tsc); no shell interpolation of user file paths
36
+
37
+ ### Test Suite
38
+
39
+ - 368 assertions, 0 failures across 9 suites (2 pre-existing arch test exemptions)
40
+ - `test:unit` (7) — reverseInject logic
41
+ - `test:e2e` (36) — full CLI lifecycle (init/start/stop/run/pipe/doctor/file-mode/headless)
42
+ - `test:bidir` (27) — write-back, base.md, template edits
43
+ - `test:arch` (63) — architecture extraction across 7 ecosystems
44
+ - `test:compose` (17) — compose-md assembly
45
+ - `test:crew` (92) — crew lifecycle, hooks, TUI, status JSON, removal
46
+ - `test:scripts` (79) — all script categories across fixtures
47
+ - `test:inject` (47) — injection delivery, formats, dedup, validation, session isolation
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2025-2026, Ivann Rudrauf
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.