Skip to content

feat(harness): apply slim rules layer to named and SDD agents - #54

Open
pablontiv wants to merge 4 commits into
Gentleman-Programming:mainfrom
pablontiv:feat/subagent-rules-layer
Open

feat(harness): apply slim rules layer to named and SDD agents#54
pablontiv wants to merge 4 commits into
Gentleman-Programming:mainfrom
pablontiv:feat/subagent-rules-layer

Conversation

@pablontiv

@pablontiv pablontiv commented Jun 16, 2026

Copy link
Copy Markdown

Re-land of #43 (approved, then closed; head branch deleted, so this is a fresh PR with the same commit). Rebased onto current main (1c218795). Opened as draft for now.

What changed vs the original #43: rebased cleanly. Re-verified after the rebase that AGENT_SLIM_RULES still contains only the thin discipline floor — no persona, identity, or orchestrator content, and no voseo leak from #45's neutral-mode fix. The separation tests assert exactly this and pass. The harness logic is byte-identical to the approved commit.

Last in the stack, stacked on #42. This is the one PR that revisits the design call discussed in #39.

Part of #39 (please read the design note in the issue before reviewing this one). Stacked on #42 (review the last commit only).

Summary

  • Named and SDD agents currently receive an empty gentlePrompt. This PR keeps persona, identity, and orchestrator content out of them (that part of the design is unchanged) and appends a 9-line discipline floor instead: scope confinement, destructive-command safety, TDD evidence, no nested orchestration, honest reporting.
  • Parent sessions are untouched; they keep the full harness exactly as today.

Changes

File Change
extensions/gentle-ai.ts AGENT_SLIM_RULES const; before_agent_start appends it for named/SDD agents instead of the empty string
tests/gentle-ai.test.ts Slim rules content assertions; explicit absence checks for persona and orchestrator markers
tests/runtime-harness.mjs Assertions updated from exact-empty to pattern matching (slim rules present, persona markers absent)

Test plan

  • pnpm test green at this commit on current main: 168 pass, 0 fail (full stack). Original count on the older base was 67.

Notes

This is the one PR in the stack that revisits a deliberate design choice. If you prefer subagents fully clean, closing this PR drops the change without affecting #40, #41, or #42.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Improved orchestrator prompt handling by loading it on demand and safely returning an empty result when the file can’t be read.
  • New Features

    • Enhanced context management with smarter harness reminders, including refresh behavior after compaction and deduplication.
    • Improved agent prompt composition by reliably injecting the “slim rules” content.
  • Tests

    • Expanded unit tests for prompt loading and reminder/compaction logic, plus updated runtime harness assertions to match the new prompt composition.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Refactors the orchestrator prompt loader to read from disk on each call with error fallback, introduces a harness reminder system that injects context-aware reminders into the message stream on compaction events, injects AGENT_SLIM_RULES at agent start, and extends the __testing surface with all new helpers. Unit and runtime tests are updated accordingly.

Changes

Harness Reminder System and Prompt Refactor

Layer / File(s) Summary
On-demand orchestrator prompt loader
extensions/gentle-ai.ts, tests/gentle-ai.test.ts
Replaces the cached orchestrator prompt read with getOrchestratorPromptImpl(pathOverride?) that reads from disk each call and returns "" on ENOENT or any other read error. Tests verify fresh reads and missing-file fallback.
Harness reminder constants, state, and builder/applier
extensions/gentle-ai.ts, tests/gentle-ai.test.ts
Defines reminder markdown constants, adds compactionPending flag, and implements buildContextReminder() (conditional post-compaction block, one-shot flag clear) and applyHarnessReminder() (deduplication, append-as-last). Tests cover non-mutation, deduplication, mid-array removal, empty input, multi-turn persistence, and compaction-flag lifecycle.
Runtime event wiring, slim rules injection, and testing surface
extensions/gentle-ai.ts, tests/gentle-ai.test.ts
Wires compactionPending reset to session_start, sets it on session_compact, returns applyHarnessReminder-transformed messages from the context handler, injects AGENT_SLIM_RULES in the before_agent_start branch, introduces AGENT_SLIM_RULES constant, and extends __testing with all new helpers. Tests validate slim rules content and phrase inclusions.
Runtime harness assertion updates
tests/runtime-harness.mjs
Replaces strict equality assertions for worker subagent prompts with multi-fragment matching and explicit identity absence checks, enabling flexible rule composition while maintaining prompt integrity.

Sequence Diagram(s)

sequenceDiagram
  participant Session as Session Runtime
  participant CPFlag as compactionPending flag
  participant ACR as applyHarnessReminder
  participant BCR as buildContextReminder
  participant Messages as Message Array

  Session->>CPFlag: session_start → false
  Session->>CPFlag: session_compact → true
  Session->>ACR: context event (messages)
  ACR->>Messages: remove prior harness reminders
  ACR->>BCR: build reminder
  BCR->>CPFlag: read → true, then reset to false
  BCR-->>ACR: reminder with optional post-compaction block
  ACR->>Messages: append reminder as last item
  ACR-->>Session: updated messages
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Suggested labels

enhancement

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: applying slim rules to named and SDD agents, which aligns with the primary modification in the changeset where AGENT_SLIM_RULES are injected in the before_agent_start handler.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@extensions/gentle-ai.ts`:
- Around line 1923-1932: The module-global `compactionPending` boolean variable
at line 1923 is shared across all concurrent sessions, causing state leakage
where one session's compact event affects another session's reminder injection.
Replace the single `compactionPending` variable with a per-session map or object
keyed by session ID. Update the `buildContextReminder()` function to look up the
pending state using the current session's ID instead of reading the global flag,
and update all code that sets or consumes this flag (at lines 2024-2030) to use
the session ID as the key when accessing and modifying the per-session state
map.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 74456142-fabd-413e-bdbf-84e60d4494c3

📥 Commits

Reviewing files that changed from the base of the PR and between 1c21879 and 1a2cb5a.

📒 Files selected for processing (3)
  • extensions/gentle-ai.ts
  • tests/gentle-ai.test.ts
  • tests/runtime-harness.mjs

Comment thread extensions/gentle-ai.ts
@pablontiv
pablontiv force-pushed the feat/subagent-rules-layer branch from 1a2cb5a to bbe005a Compare June 16, 2026 18:33
Registers pi.on("context") handler that injects a gentle-harness-reminder message before each LLM call, ensuring the orchestrator pattern, TDD discipline, and artifact-driven decisions are reinforced at every interaction point — not just at agent start.

The handler returns a new message array with the reminder appended as the last message. It deduplicates if a reminder is already present (defensive for chained extensions). The reminder content is a single source of truth module constant and includes all el Gentleman discipline markers.

Pure logic exposed via __testing for verification. Full suite green (58/58 pass, runtime harness exit 0).
@pablontiv
pablontiv force-pushed the feat/subagent-rules-layer branch from bbe005a to c29a14f Compare June 16, 2026 20:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/runtime-harness.mjs`:
- Around line 216-219: The test assertions in the subagent prompt validation
currently only check that the identity string is absent but do not explicitly
verify that SDD preflight markers are absent from non-SDD subagent prompts,
which means the contract that non-SDD subagents must not receive SDD preflight
is not actually enforced. Add explicit negative assertions using
assert.doesNotMatch for the relevant SDD preflight markers and patterns to the
subagentPromptResult.systemPrompt check, and apply the same assertions to other
locations where non-SDD subagent prompt validation occurs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 43f7add8-6076-48e1-a8bc-629e5b4d6c71

📥 Commits

Reviewing files that changed from the base of the PR and between bbe005a and c29a14f.

📒 Files selected for processing (3)
  • extensions/gentle-ai.ts
  • tests/gentle-ai.test.ts
  • tests/runtime-harness.mjs

Comment thread tests/runtime-harness.mjs
@pablontiv
pablontiv force-pushed the feat/subagent-rules-layer branch from c29a14f to 73166e6 Compare June 16, 2026 20:25
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