Skip to content

feat(sdd): inject canonical language contract into rendered sub-agent prompts - #1749

Open
pablontiv wants to merge 3 commits into
Gentleman-Programming:mainfrom
pablontiv:feat/agent-language-contract
Open

feat(sdd): inject canonical language contract into rendered sub-agent prompts#1749
pablontiv wants to merge 3 commits into
Gentleman-Programming:mainfrom
pablontiv:feat/agent-language-contract

Conversation

@pablontiv

@pablontiv pablontiv commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked Issue

Closes #1702

Chained series: this is PR3 of 4 under #1702 (the series was consolidated from the 5 PRs announced in the issue — render-time injection replaced the original plan of duplicating a contract block into all 66 agent assets, so former PR3+PR4 are now this single PR). Independent of #1712/#1713 — based directly on main. If this merge auto-closes the issue, please reopen — PR4 (main-thread hardening) completes the series.


🏷️ PR Type

  • type:feature — New feature (non-breaking change that adds functionality)

📝 Summary

Fixes defect 4 of #1702: executor sub-agents carried no artifact-language contract, so an executor spawned inside a Spanish conversation mimicked its dialect (voseo included) when writing specs, comments, UI copy, memory entries, and reports.

Instead of duplicating a block into the 66 static agent assets, this follows the repo's reuse pattern (engram's canonical protocol.md, the CodeGraph guidance injection): ONE canonical asset, injected at render time into every installed sub-agent prompt.

  • internal/assets/generic/agent-language-contract.md — single source of truth: artifacts default to English; explicitly-requested Spanish artifacts use neutral/professional Spanish; never regional slang or dialect regardless of conversation language.
  • injectLanguageContractIntoPrompt — marker-bound (filemerge.InjectMarkdownSection, section agent-language-contract), so re-renders are idempotent; wired into the step-3c render loop next to the CodeGraph guidance injection. Covers the claude/cursor/kimi/kiro markdown agents; a NEW agent asset inherits the contract structurally, with no per-file lint needed.
  • OpenCode parity: injectLanguageContractIntoOpenCodeSubagentPrompts mirrors the CodeGraph OpenCode variant — JSON-embedded sub-agent prompts get the same contract; primary-mode (persona) agents and {file:...} indirections are skipped.

📂 Changes

File / Area What Changed
internal/assets/generic/agent-language-contract.md New — canonical executor language contract
internal/components/sdd/prompts.go agentLanguageContract(), injectLanguageContractIntoPrompt(), injectLanguageContractIntoOpenCodeSubagentPrompts()
internal/components/sdd/inject.go Two wiring calls: markdown render loop + OpenCode agents map
internal/components/sdd/language_contract_injection_test.go New — canonical block, idempotence, OpenCode skip semantics
testdata/golden/sdd-{claude,kiro}-agent-*.golden, sdd-opencode-*-settings.golden Rendered output now carries the managed contract section (contract-only diffs)

🧪 Test Plan

Unit Tests

go test ./...

Go Format

go run ./internal/gofmtcheck

E2E Tests (Docker required)

cd e2e && ./docker-test.sh
  • Unit tests pass (go test ./internal/components/... ./internal/assets/; full suite except ./internal/cli, which has 3 machine-local pre-existing failures documented in fix(persona): remap gentleman-neutral-artifacts alias to neutral #1712 — deferring the authoritative verdict to CI)
  • Go format passes (go run ./internal/gofmtcheck)
  • E2E tests — deferring to CI (no local Docker run)
  • Manually tested locally (test-level; golden diffs inspected to be contract-only)

✅ Contributor Checklist


💬 Notes for Reviewers

Cursor/kimi have no rendered-agent goldens (verified — only claude/kiro do), which is why the golden diff covers claude+kiro+opencode only; the injection itself runs for every adapter in the loop. Primary-mode OpenCode agents are deliberately excluded: the persona channel owns conversation-tone rules, and the executor contract is artifact-scoped (PR4 hardens the persona channels themselves).

Summary by CodeRabbit

  • New Features
    • Generated sub-agent prompts now include a managed language contract section (English by default; neutral professional Spanish when explicitly requested).
    • The contract is applied consistently across native Markdown sub-agent artifacts and OpenCode sub-agent prompt content, while preserving existing prompt references.
  • Chores
    • Local CodeGraph artifacts are excluded from version control.
  • Tests
    • Added unit tests for contract injection, idempotency, and OpenCode prompt parity.
    • Updated review protocol rendering expectations for impacted scenarios.

Copilot AI review requested due to automatic review settings July 23, 2026 02:03
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c3564b95-240c-4490-8043-b510207e58ae

📥 Commits

Reviewing files that changed from the base of the PR and between 8c33db7 and 829fa41.

📒 Files selected for processing (2)
  • internal/components/sdd/language_contract_injection_test.go
  • internal/components/sdd/prompts.go

📝 Walkthrough

Walkthrough

Generated artifact prompts now receive a canonical language contract across native Markdown and OpenCode SDD sub-agent flows. Tests cover idempotency and exclusions, rendered character thresholds are updated, and local CodeGraph artifacts are ignored.

Changes

Language contract injection

Layer / File(s) Summary
Contract definition and managed prompt injection
internal/assets/generic/agent-language-contract.md, internal/components/sdd/prompts.go
Defines the artifact language rules and injects them as an idempotent managed Markdown section.
Sub-agent wiring and validation
internal/components/sdd/inject.go, internal/components/sdd/prompts.go, internal/components/sdd/language_contract_injection_test.go, internal/components/sdd/review_ledger_contract_test.go
Applies the contract to native and OpenCode sub-agent prompts, validates eligible and excluded prompts, shared prompt files, and updated rendered character expectations.

CodeGraph repository policy

Layer / File(s) Summary
Local CodeGraph artifact ignore rules
.codegraph/.gitignore
Ignores transient CodeGraph contents while retaining the .gitignore file.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Inject
  participant OpenCodeOverlay
  participant LanguageContractInjector
  participant GeneratedPrompt
  Inject->>LanguageContractInjector: inject contract into Markdown sub-agent prompt
  OpenCodeOverlay->>LanguageContractInjector: inject contract into eligible sub-agent prompt
  LanguageContractInjector->>GeneratedPrompt: produce managed prompt content
Loading

Possibly related PRs

Suggested labels: type:feature

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The .codegraph/.gitignore addition is unrelated to the language-contract fix and is not part of the linked issue scope. Move the .codegraph ignore change to a separate housekeeping PR, or drop it if it is not required for this fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed It clearly states the main change: injecting a canonical language contract into rendered sub-agent prompts.
Linked Issues check ✅ Passed The contract injection and tests match the defect 4 objective of keeping executor-generated artifacts neutral in language.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copilot AI 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.

Pull request overview

This PR addresses #1702 (defect 4) by introducing a single canonical “Artifact Language Contract” asset and injecting it at render time into SDD sub-agent prompts (including OpenCode’s JSON-embedded subagent prompts), avoiding per-agent duplication and keeping re-renders idempotent via filemerge.InjectMarkdownSection.

Changes:

  • Added a canonical language-contract markdown asset and injected it into rendered sub-agent prompts via marker-bound sections.
  • Wired language-contract injection into the SDD render loop and OpenCode agent-map prompt inlining.
  • Added focused unit tests and updated goldens / prompt-cost expectations to reflect the injected section.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/assets/generic/agent-language-contract.md New canonical Artifact Language Contract content (single source of truth).
internal/components/sdd/prompts.go Adds contract accessor + injection helpers for markdown prompts and OpenCode embedded prompts.
internal/components/sdd/inject.go Wires contract injection into the markdown render loop and OpenCode agents-map processing.
internal/components/sdd/language_contract_injection_test.go New tests for canonical block presence, idempotence, and OpenCode skip semantics.
internal/components/sdd/review_ledger_contract_test.go Updates deterministic rendered-character budgets to account for the new injected content.
testdata/golden/sdd-opencode-multi-settings.golden Updates OpenCode rendered settings golden to include the managed contract section for inlined subagents.
testdata/golden/sdd-kiro-agent-sdd-apply.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-archive.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-design.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-explore.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-init.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-onboard.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-propose.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-spec.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-tasks.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-kiro-agent-sdd-verify.golden Updates Kiro rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-apply.golden Updates Claude rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-archive.golden Updates Claude rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-design.golden Updates Claude rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-explore.golden Updates Claude rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-propose.golden Updates Claude rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-spec.golden Updates Claude rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-tasks.golden Updates Claude rendered agent golden to include the managed contract section.
testdata/golden/sdd-claude-agent-sdd-verify.golden Updates Claude rendered agent golden to include the managed contract section.
.codegraph/.gitignore Prevents accidental commits of local CodeGraph transient data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/components/sdd/prompts.go
Comment thread internal/components/sdd/language_contract_injection_test.go Outdated

@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: 2

🤖 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 `@internal/components/sdd/inject.go`:
- Line 725: Update the SDD user-config write flow around
injectLanguageContractIntoPrompt to journal or back up the original files before
calling filemerge.WriteFileAtomic or mergeJSONFile. Use the existing
restore-compatible backup mechanism so both config changes can be rolled back,
preserving the original contents and handling files that did not previously
exist.

In `@internal/components/sdd/language_contract_injection_test.go`:
- Around line 11-24: Add an assertion in
TestInjectLanguageContractIntoPromptAppendsCanonicalBlock that the injected
prompt contains the explicit requirement to use neutral, professional Spanish
when Spanish is explicitly requested. Keep the existing English-default,
dialect-prohibition, and marker assertions unchanged.
🪄 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: c380779d-bfcc-4995-befe-63ea0b1e1a0a

📥 Commits

Reviewing files that changed from the base of the PR and between 807adc4 and cb74125.

⛔ Files ignored due to path filters (19)
  • testdata/golden/sdd-claude-agent-sdd-apply.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-archive.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-design.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-explore.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-propose.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-spec.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-tasks.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-verify.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-apply.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-archive.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-design.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-explore.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-init.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-onboard.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-propose.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-spec.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-tasks.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-verify.golden is excluded by !testdata/**
  • testdata/golden/sdd-opencode-multi-settings.golden is excluded by !testdata/**
📒 Files selected for processing (6)
  • .codegraph/.gitignore
  • internal/assets/generic/agent-language-contract.md
  • internal/components/sdd/inject.go
  • internal/components/sdd/language_contract_injection_test.go
  • internal/components/sdd/prompts.go
  • internal/components/sdd/review_ledger_contract_test.go

Comment thread internal/components/sdd/inject.go
Comment thread internal/components/sdd/language_contract_injection_test.go
Copilot AI review requested due to automatic review settings July 23, 2026 15:29
@pablontiv
pablontiv force-pushed the feat/agent-language-contract branch from cb74125 to 8c33db7 Compare July 23, 2026 15:29

@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 `@internal/components/sdd/inject.go`:
- Line 946: Update WriteSharedPromptFiles to inject the agent-language-contract
into shared SDD prompt contents before writing the referenced files, ensuring
OpenCode multi-mode agents receive it through {file:...} prompts. Preserve the
existing codegraph guidance and non-file prompt injection behavior without
duplicating the contract.
🪄 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: f8483a87-3e04-44c7-91c5-7031b982fa7e

📥 Commits

Reviewing files that changed from the base of the PR and between cb74125 and 8c33db7.

⛔ Files ignored due to path filters (19)
  • testdata/golden/sdd-claude-agent-sdd-apply.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-archive.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-design.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-explore.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-propose.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-spec.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-tasks.golden is excluded by !testdata/**
  • testdata/golden/sdd-claude-agent-sdd-verify.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-apply.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-archive.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-design.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-explore.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-init.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-onboard.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-propose.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-spec.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-tasks.golden is excluded by !testdata/**
  • testdata/golden/sdd-kiro-agent-sdd-verify.golden is excluded by !testdata/**
  • testdata/golden/sdd-opencode-multi-settings.golden is excluded by !testdata/**
📒 Files selected for processing (6)
  • .codegraph/.gitignore
  • internal/assets/generic/agent-language-contract.md
  • internal/components/sdd/inject.go
  • internal/components/sdd/language_contract_injection_test.go
  • internal/components/sdd/prompts.go
  • internal/components/sdd/review_ledger_contract_test.go

Comment thread internal/components/sdd/inject.go

Copilot AI 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.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

internal/components/sdd/prompts.go:223

  • OpenCode multi-mode SDD agents use {file:...} prompt indirections (see updated golden testdata/golden/sdd-opencode-multi-settings.golden where sdd-apply etc point to ./prompts/sdd/*.md). This function skips {file:...} prompts, but WriteSharedPromptFiles() currently only injects CodeGraph guidance, not the language contract. Result: the canonical Artifact Language Contract is still missing from the SDD executor prompt files in multi-mode, so defect #1702/4 remains for those executors.
		}
		if mode, _ := agent["mode"].(string); mode == "primary" {
			continue

Copilot AI review requested due to automatic review settings July 23, 2026 15:35

Copilot AI 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.

Pull request overview

Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.

@dnlrsls dnlrsls added the type:feature New feature label Jul 27, 2026
@dnlrsls

dnlrsls commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

PR policy requires an approved linked issue. Issue #1702 is still open with status:needs-design, so this PR remains blocked pending a maintainer decision on #1702. No rebase or other changes are requested yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature

Projects

None yet

3 participants