lean-agent-harness 1.3.2 → 1.4.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/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project are documented here. Format based on [Keep a
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [1.4.0] - 2026-11-04
8
+
9
+ ### Added
10
+
11
+ - A divergent user `AGENTS.md`/`CLAUDE.md` is now merged instead of only backed up: the original is still saved as `.bak` (`.bak.1`, ...), and its rules survive in the agent's context as a `## Project Rules` section delimited by `lah:project-rules` comments. Reinstalls over a merged file are a no-op; payload upgrades replace only the harness part and keep the section. Files the harness itself deployed (the `lean-agent-harness` marker or the 1.x signature lines — `Single source of truth for all coding agents`, `# Claude Code Project Configuration`) are replaced without absorbing the old harness text. The affected `manifest.tsv` rows carry the new `merge` mode, and installer parity now runs the merge through both installers.
12
+
7
13
  ## [1.3.2] - 2026-10-31
8
14
 
9
15
  ### Added
package/CLAUDE.md CHANGED
@@ -1,3 +1,4 @@
1
+ <!-- Managed by lean-agent-harness. -->
1
2
  # Claude Code Project Configuration
2
3
 
3
4
  Single source of truth is defined in `AGENTS.md`. All directives, subagents, skills, and lifecycle commands apply here.
package/GLOSSARY.md CHANGED
@@ -14,7 +14,8 @@ Single source of truth for the domain vocabulary of this project. Both human eng
14
14
  | **Target** | One deployment destination with its native layout. `agents` is the cross-tool `.agents/skills` location read by Pi, OpenCode, Codex, Copilot and Cursor; `claude` uses `.claude/skills`. | `target` column of `manifest.tsv` | Declared only in `manifest.tsv`; both installers read it. |
15
15
  | **Manifest** | Tab-separated table mapping package sources to destinations per scope (local/global). | `manifest.tsv` | Single source for `bin/cli.js` and `install.sh`; `test/cli.test.js` asserts identical output trees. |
16
16
  | **Adapter** | A static file that bridges one agent's native mechanism to a skill (OpenCode command stubs). | `adapters/` | Contains no rules, only a pointer to the skill. |
17
- | **Instruction Stub** | A file that makes an agent read the shared rules (`AGENTS.md`, `CLAUDE.md`, `copilot-instructions.md`). | `file` rows in `manifest.tsv` | Content must derive from the package `AGENTS.md`; installed once per scope where the agent reads `AGENTS.md` natively; user customizations are kept as `.bak`, or the next free `.bak.N`, on overwrite; an existing backup is never overwritten. |
17
+ | **Instruction Stub** | A file that makes an agent read the shared rules (`AGENTS.md`, `CLAUDE.md`, `copilot-instructions.md`). | `file` rows in `manifest.tsv` | Content must derive from the package `AGENTS.md`; installed once per scope where the agent reads `AGENTS.md` natively; user customizations are kept as `.bak`, or the next free `.bak.N`, and in `merge` mode also survive in context as the Project Rules Section; an existing backup is never overwritten. |
18
+ | **Project Rules Section** | The `## Project Rules` block, delimited by `lah:project-rules:start`/`:end` comments, that a `merge`-mode instruction file appends to hold the rules of the user's previous file. | Delimited block at the end of a deployed Instruction Stub | Preserved verbatim across reinstalls and payload upgrades; a file the harness itself deployed (identity marker or the 1.x signature lines) is replaced bare and never absorbed into it. |
18
19
  | **ODD (Organic Driven Development)** | Decomposition style: complex work becomes small, feature-complete, reviewable milestone slices chained across PRs. | `plan-flow` output in `.tasks/current.md` | A slice must satisfy its DoD before the next starts. |
19
20
  | **Slice** | One feature-complete ODD unit (e.g., migration + model + service + tests). | `- [ ] Slice N:` checklist item | No fragmented single-line micro-slices. |
20
21
  | **DoD (Definition of Done)** | Verification gate: 0 linter/compiler errors, passing tests with cited terminal output, no debug residue, glossary-aligned naming, isolated `git status`. | `orchestrate` skill DoD; `commit` skill step 1 | Evidence without raw terminal output is invalid. |
package/README.md CHANGED
@@ -41,12 +41,12 @@ curl -fsSL https://raw.githubusercontent.com/lnardev/lean-agent-harness/main/ins
41
41
  curl -fsSL https://raw.githubusercontent.com/lnardev/lean-agent-harness/main/install.sh | bash -s -- --global --auto
42
42
  ```
43
43
 
44
- `install.sh` accepts `--global`, `--local`, `--all`, `--auto`, `--profile core|full`, auto-detects existing environments and never blocks without a TTY. An existing `AGENTS.md`/`CLAUDE.md` that differs is saved as `.bak` before it is replaced; if a `.bak` already exists, the next one is `.bak.1`, `.bak.2`, and so on, so no version is lost. An existing `GLOSSARY.md` is never touched; a missing one is seeded from `templates/GLOSSARY.md`.
44
+ `install.sh` accepts `--global`, `--local`, `--all`, `--auto`, `--profile core|full`, auto-detects existing environments and never blocks without a TTY. An existing `AGENTS.md`/`CLAUDE.md` that differs is never lost: the original is saved as `.bak` (then `.bak.1`, `.bak.2`, ...), and its rules are merged into the deployed file under a `## Project Rules` section delimited by `lah:project-rules` comments, so they stay in the agent's context. Reinstalls change nothing over a merged file; upgrades replace only the harness part and keep the section. A file the harness itself deployed (the `lean-agent-harness` marker, the 1.x `Single source of truth` line or the 1.x `# Claude Code Project Configuration` heading) is replaced without absorbing the old harness text. An existing `GLOSSARY.md` is never touched; a missing one is seeded from `templates/GLOSSARY.md`.
45
45
 
46
46
  **Pinning and verifying the `curl` install.** The one-liner runs the `main` branch unless you pin it:
47
47
 
48
48
  ```bash
49
- curl -fsSL https://raw.githubusercontent.com/lnardev/lean-agent-harness/main/install.sh | LAH_VERSION=1.3.2 LAH_SHA256=<sha256-of-the-archive> bash -s -- --global --auto
49
+ curl -fsSL https://raw.githubusercontent.com/lnardev/lean-agent-harness/main/install.sh | LAH_VERSION=1.4.0 LAH_SHA256=<sha256-of-the-archive> bash -s -- --global --auto
50
50
  ```
51
51
 
52
52
  `LAH_VERSION` downloads that release tag. `LAH_SHA256` makes the installer abort, before deploying anything, if the archive does not match. Without it the installer says that the checksum is not verified. GitHub does not publish archive checksums, so compute the value once from a copy you trust, for example `shasum -a 256` on the archive of that tag. GitHub's generated archives are not guaranteed to stay byte-identical over time, so if a previously valid checksum stops matching, recompute it from a trusted copy before assuming tampering.
package/bin/cli.js CHANGED
@@ -32,7 +32,9 @@ const PKG_ROOT = path.resolve(__dirname, "..");
32
32
  * opencode-permission = merge permission rules into an OpenCode opencode.json
33
33
  * @property {string} src Path relative to the package root
34
34
  * @property {string} dest Path relative to the target base
35
- * @property {string} mode "" or "if-missing" (file kind: never overwrite an existing dest)
35
+ * @property {string} mode "" | "if-missing" (file kind: never overwrite an existing dest)
36
+ * | "merge" (file kind: back up a divergent dest and merge its rules into the
37
+ * deployed file as a "Project Rules" section)
36
38
  *
37
39
  * @typedef {Object} Target
38
40
  * @property {string} name Human-readable label
@@ -162,10 +164,40 @@ function backupPath(destPath) {
162
164
  return candidate;
163
165
  }
164
166
 
167
+ /** Merge mode: markers delimiting the user's rules inside a deployed instruction file. */
168
+ const MERGE_START = "<!-- lah:project-rules:start -->";
169
+ const MERGE_END = "<!-- lah:project-rules:end -->";
170
+ const MERGE_HEADING = "## Project Rules\n\n";
171
+ /** Strings identifying a file the harness itself deployed (any version): replaced bare, never absorbed. */
172
+ const HARNESS_MARKS = [
173
+ "lean-agent-harness",
174
+ "Single source of truth for all coding agents",
175
+ "# Claude Code Project Configuration",
176
+ ];
177
+
165
178
  /**
166
- * Write an instruction file. If the destination exists and differs from the
167
- * package payload, the user's file is preserved as "<name>.bak" (or the next free
168
- * "<name>.bak.N") first. With mode "if-missing" an existing destination is left untouched (seed files).
179
+ * The user's section inside a managed instruction file (between the markers, trimmed),
180
+ * or null when the file carries no markers.
181
+ * @param {string} text
182
+ * @returns {string | null}
183
+ */
184
+ function sectionOf(text) {
185
+ const at = text.indexOf(MERGE_START);
186
+ if (at === -1) return null;
187
+ let body = text.slice(at + MERGE_START.length);
188
+ const end = body.indexOf(MERGE_END);
189
+ if (end !== -1) body = body.slice(0, end);
190
+ return body.trim();
191
+ }
192
+
193
+ /**
194
+ * Write an instruction file. A destination that differs from the package payload is
195
+ * preserved as "<name>.bak" (or the next free "<name>.bak.N") first. With mode
196
+ * "if-missing" an existing destination is left untouched (seed files). With mode
197
+ * "merge" the divergent destination's rules also survive in context: a user file is
198
+ * merged as a "Project Rules" section, a managed file keeps its section across
199
+ * payload upgrades, and a file the harness itself deployed is replaced bare.
200
+ * Writing a byte-identical result is a no-op, so reinstalling is stable.
169
201
  *
170
202
  * @param {string} srcPath
171
203
  * @param {string} destPath
@@ -173,18 +205,32 @@ function backupPath(destPath) {
173
205
  */
174
206
  function writeInstruction(srcPath, destPath, mode = "") {
175
207
  if (mode === "if-missing" && fs.existsSync(destPath)) return;
208
+ const payload = fs.readFileSync(srcPath, "utf8");
176
209
  fs.mkdirSync(path.dirname(destPath), { recursive: true });
210
+ let current = null;
177
211
  try {
178
- const current = fs.readFileSync(destPath, "utf8");
179
- if (current !== fs.readFileSync(srcPath, "utf8")) {
180
- fs.copyFileSync(destPath, backupPath(destPath));
181
- }
212
+ current = fs.readFileSync(destPath, "utf8");
182
213
  } catch (err) {
183
214
  if (err.code !== "ENOENT") {
184
215
  throw err;
185
216
  }
186
217
  }
187
- fs.copyFileSync(srcPath, destPath);
218
+ if (current === null) {
219
+ fs.copyFileSync(srcPath, destPath);
220
+ return;
221
+ }
222
+ if (current === payload) return;
223
+ let next = null;
224
+ if (mode === "merge") {
225
+ const marked = sectionOf(current);
226
+ const userRules = marked === null && !HARNESS_MARKS.some((m) => current.includes(m)) ? current.trim() : "";
227
+ const body = marked ?? (userRules ? MERGE_HEADING + userRules : "");
228
+ next = body ? `${payload.replace(/\s+$/, "")}\n\n${MERGE_START}\n${body}\n${MERGE_END}\n` : payload;
229
+ }
230
+ if (next !== null && next === current) return;
231
+ fs.copyFileSync(destPath, backupPath(destPath));
232
+ if (next !== null) fs.writeFileSync(destPath, next);
233
+ else fs.copyFileSync(srcPath, destPath);
188
234
  }
189
235
 
190
236
  /**
package/install.sh CHANGED
@@ -207,14 +207,64 @@ backup_path() {
207
207
  printf '%s' "$candidate"
208
208
  }
209
209
 
210
+ # Merge mode: markers delimiting the user's rules inside a deployed instruction file,
211
+ # and the strings identifying a file the harness itself deployed (replaced bare, never absorbed).
212
+ MERGE_START='<!-- lah:project-rules:start -->'
213
+ MERGE_END='<!-- lah:project-rules:end -->'
214
+ MERGE_HEADING=$'## Project Rules\n\n'
215
+
216
+ # Leading and trailing whitespace (newlines included), matching the JS side's String.trim().
217
+ trim_ws() {
218
+ local t="$1"
219
+ t="${t#"${t%%[![:space:]]*}"}"
220
+ printf '%s' "${t%"${t##*[![:space:]]}"}"
221
+ }
222
+
210
223
  # Instruction file: a divergent existing destination is preserved as .bak (or the next free .bak.N).
211
224
  # mode "if-missing": an existing destination is left untouched (seed files).
225
+ # mode "merge": the divergent destination's rules also survive in context — a user file is merged
226
+ # as a "Project Rules" section, a managed file keeps its section across payload upgrades, and a
227
+ # file the harness itself deployed is replaced bare. Writing a byte-identical result is a no-op.
212
228
  write_instruction() {
213
229
  local src="$1" dest="$2" mode="${3:-}"
214
230
  if [ "$mode" = "if-missing" ] && [ -e "$dest" ]; then return 0; fi
215
231
  mkdir -p "$(dirname "$dest")"
216
- if [ -f "$dest" ] && ! cmp -s "$src" "$dest"; then cp "$dest" "$(backup_path "$dest")"; fi
232
+ if [ ! -e "$dest" ]; then cp "$src" "$dest"; return 0; fi
233
+ if cmp -s "$src" "$dest"; then return 0; fi
234
+ if [ "$mode" != "merge" ]; then
235
+ cp "$dest" "$(backup_path "$dest")"
236
+ cp "$src" "$dest"
237
+ return 0
238
+ fi
239
+ local current section composed payload
240
+ payload="$(cat "$src")"
241
+ payload="${payload%"${payload##*[![:space:]]}"}"
242
+ current="$(cat "$dest")"
243
+ case "$current" in
244
+ *"$MERGE_START"*)
245
+ section="$current"
246
+ section="${section#*"$MERGE_START"}"
247
+ section="${section%%"$MERGE_END"*}"
248
+ section="$(trim_ws "$section")"
249
+ ;;
250
+ *lean-agent-harness*|*"Single source of truth for all coding agents"*|*"# Claude Code Project Configuration"*)
251
+ section=""
252
+ ;;
253
+ *)
254
+ section="$(trim_ws "$current")"
255
+ if [ -n "$section" ]; then section="${MERGE_HEADING}${section}"; fi
256
+ ;;
257
+ esac
258
+ if [ -n "$section" ]; then
259
+ composed="$(printf '%s\n\n%s\n%s\n%s\n' "$payload" "$MERGE_START" "$section" "$MERGE_END")"
260
+ if printf '%s\n' "$composed" | cmp -s - "$dest"; then return 0; fi
261
+ cp "$dest" "$(backup_path "$dest")"
262
+ printf '%s\n' "$composed" > "$dest"
263
+ return 0
264
+ fi
265
+ cp "$dest" "$(backup_path "$dest")"
217
266
  cp "$src" "$dest"
267
+ return 0
218
268
  }
219
269
 
220
270
  # Skill folders omitted by --profile core (profile-extras.txt, shared with bin/cli.js).
package/manifest.tsv CHANGED
@@ -6,25 +6,27 @@
6
6
  # | settings-hook (merge the hook in src into the Claude Code settings.json at dest)
7
7
  # | opencode-permission (merge the permission rules in src into the OpenCode opencode.json at dest)
8
8
  # mode: if-missing (file kind only: never overwrite an existing dest)
9
+ # merge (file kind only: back up a divergent dest and merge its rules into the deployed
10
+ # file as a "Project Rules" section; a dest the harness itself deployed is replaced bare)
9
11
  # Target "agents" = the cross-tool Agent Skills location (.agents/skills), read natively by
10
12
  # Pi, OpenCode, Codex, Copilot and Cursor. Claude Code reads .claude/skills instead.
11
- local core file AGENTS.md AGENTS.md
12
- local core file CLAUDE.md CLAUDE.md
13
+ local core file AGENTS.md AGENTS.md merge
14
+ local core file CLAUDE.md CLAUDE.md merge
13
15
  local core file templates/GLOSSARY.md GLOSSARY.md if-missing
14
16
  local claude dir skills .claude/skills
15
17
  local agents dir skills .agents/skills
16
18
  local opencode dir adapters/opencode/commands .opencode/commands
17
19
  local commandcode dir skills .commandcode/skills
18
- global claude file AGENTS.md .claude/AGENTS.md
19
- global claude file CLAUDE.md .claude/CLAUDE.md
20
+ global claude file AGENTS.md .claude/AGENTS.md merge
21
+ global claude file CLAUDE.md .claude/CLAUDE.md merge
20
22
  global claude dir skills .claude/skills
21
23
  global agents dir skills .agents/skills
22
- global pi file AGENTS.md .pi/agent/AGENTS.md
23
- global opencode file AGENTS.md .config/opencode/AGENTS.md
24
+ global pi file AGENTS.md .pi/agent/AGENTS.md merge
25
+ global opencode file AGENTS.md .config/opencode/AGENTS.md merge
24
26
  global opencode dir adapters/opencode/commands .config/opencode/commands
25
- global codex file AGENTS.md .codex/AGENTS.md
26
- global copilot file AGENTS.md .copilot/copilot-instructions.md
27
- global commandcode file AGENTS.md .commandcode/AGENTS.md
27
+ global codex file AGENTS.md .codex/AGENTS.md merge
28
+ global copilot file AGENTS.md .copilot/copilot-instructions.md merge
29
+ global commandcode file AGENTS.md .commandcode/AGENTS.md merge
28
30
  global commandcode dir skills .commandcode/skills
29
31
  global-guard pi-guard dir guard/pi/lah-guard .pi/agent/extensions/lah-guard
30
32
  global-guard claude-guard dir guard/claude/lah-guard .claude/hooks/lah-guard
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lean-agent-harness",
3
- "version": "1.3.2",
3
+ "version": "1.4.0",
4
4
  "description": "Zero-bloat, token-efficient agent harness for Claude Code, Cursor, OpenCode, Pi, Codex, and CommandCode.",
5
5
  "author": "lnardev",
6
6
  "bin": {