Skip to content

feat(omp-leaf-context): deliver leaf AGENTS.md on first tool result - #185

Open
systemfsoftware-maker wants to merge 7 commits into
mainfrom
remove-guard-protect-writes
Open

feat(omp-leaf-context): deliver leaf AGENTS.md on first tool result#185
systemfsoftware-maker wants to merge 7 commits into
mainfrom
remove-guard-protect-writes

Conversation

@systemfsoftware-maker

Copy link
Copy Markdown
Collaborator

Summary

Replaces the deleted blocking Claude-format hook (deliver-leaf-agents-md.ts) with a non-blocking, in-process OMP extension: @systemfsoftware/omp-leaf-context.

For every tool call touching a path under a leaf (a packages/*/AGENTS.md-governed directory), the first matching tool_result is appended with the governing leaf's content — once per leaf per session, repos/ excluded, leaves up to 6144 UTF-8 bytes inlined and larger ones delivered as a pointer. The tool result's original content is preserved; the block is appended, never substituted. Handlers never block or revise tool calls; faults log and no-op, I/O failures during the walk or read surface as LeafContextError on the error channel.

Cells follow the repo's impure/pure/impure sandwich: the ACL decodes the target, the workflow cell (decide) owns every skip reason (no governing leaf, self-injection when the touched file IS the leaf, already delivered this session) before any file I/O, and the executor reads the leaf only after a Select verdict — a repeat touch costs one walk, zero reads.

Changes

  • New omp/plugins/omp-leaf-context plugin (7 source cells, 13 Gherkin integration scenarios over effect-memfs, oxlint + tsdown build, changeset minor)
  • Root AGENTS.md: governance cell for omp/ packages now names the plugin-delivered leaf and its gate
  • .claude/hooks/deliver-leaf-agents-md.ts deleted; settings entry removed
  • docs/solutions/architecture-patterns/omp-leaf-context-delivery-pattern.md: the delivery pattern, its invariants, and the Effect v4 API surface it required

Review

Three review passes ran before this PR: ce-simplify-code (3 reviewers), ce-code-review (7 reviewers, 35 raw findings -> 17 merged), and ce-compound (learning captured). All mechanical findings are applied in the two fix commits: append-vs-replace contract test, traversal-escape hardening for absolute .. targets, single-source decide with content materialization after Select, run-safe collapse, session-scoped pending-call keys, threshold boundary tests (6144/6145 bytes, multibyte), and self-injection guard.

One decision gate for the reviewer: Claude-format sessions no longer receive leaf governance (the hook was Claude-only); root AGENTS.md documents the OMP gate. The OMP-only delivery is the approved plan's intent. ctx.cwd-rooted resolution and process-lifetime dedupe are documented deltas (residual risks in the review report).

Verification

  • tsc, 13/13 vitest scenarios, oxlint, tsdown build, smoke-plugin (tool_call + tool_result handlers listed), omp plugin link + doctor, pnpm check:local all green on the final commit
  • Live-session proof: first read under packages/effect-atom injected the leaf; second touch under the same leaf clean; read under packages/effect-memfs injected its leaf; repos/oh-my-pi read clean

Review artifacts: /tmp/compound-engineering-0/ce-code-review/20260816-225852-26b3b0f0/ (report.md, per-reviewer JSON).

Replaces the .claude deliver-leaf-agents-md PreToolUse hook with a
non-blocking OMP extension: the governing leaf's AGENTS.md is appended
to the first tool result touching that leaf, once per leaf per session
Cut the toolCallId record to the target only, consolidate error→string
mapping into the executor, gate eligibility before the leaf read (repeat
touches skip I/O), break the walk at the first existing leaf, harden the
repos/ skip to the exact node, measure the inline threshold in bytes,
and single-decode the ACL input
Single-source the dedupe/eligibility decision in the workflow cell
(decide returns Select | Skip; content materialized only after a
Select), collapse run-safe into one honest module, key pending
targets by session:toolCallId, reject .. traversal in absolute
targets, skip injection when the touched file IS the leaf, and add
boundary/traversal/self-touch/append-contract tests
Capture the tool-result injection delivery shape, its invariants
(emission not gate, regulate before read, append-never-replace,
session-keyed state) and the effect-v4 API surface it required
Restructure off the cell-role suffixes (acl/executor/handler/workflow/
run-safe) onto the clanka/effect-torch module shape: Target (decode +
relativeToRoot), LeafContext (the eligibility decision as a
Workflow.make from @systemfsoftware/effect-cell-types, one exhaustive
dispatch over a closed classify), LeafContextExtension (the I/O
sandwich: walk, decide, then read-and-append kept in the shell), and
internal/ for the fs seam and runSafe. The decision gains a real error
channel: an invalid governing-leaf path (absolute, ascending, repos/,
or mis-suffixed) is refused as LeafContextError instead of a silent
skip. Tests: 14 integration scenarios including the host-facing entry
factory, plus workflow property laws over the closed classification
Re-key every gate onto the Workflow.make boundary and import edges:
the sandwich plus workflow shape, the TaggedError channel rule audited
per make site, the ACL1 decode rule audited across all source, and a
failure-mode row that names the rename hazard. The plugins leaf PLG2
check now scans all source instead of the handler suffix glob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant