Skip to content

Commit 39de170

Browse files
SmithSmith
authored andcommitted
feat(docs): enhance LLM behavior guidelines with business intent preservation in code documentation
1 parent bcbbea5 commit 39de170

5 files changed

Lines changed: 79 additions & 0 deletions

File tree

.github/copilot-instructions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ Agent engineering policies are in `docs/agent-engineering/`:
6363
- Adding/editing agents or skills: follow the agent-contribution process in `CONTRIBUTING.md` (create agent file, schema, eval scenarios, register in `plans/project-context.md`).
6464
- Tool and agent permission grants are in `governance/` (`agent-grants.json`, `tool-grants.json`, `runtime-policy.json`, `rename-allowlist.json`). Update these when changing an agent's tool profile.
6565

66+
## Code Documentation and Language
67+
- Before completing an implementation phase, review the changed code for documentation that preserves non-obvious business rules, invariants, exceptions, constraints, and decision rationale. Comments should explain **why** the behavior exists or what business condition it protects, not narrate syntax or restate the code.
68+
- For new or materially changed public or extensible symbols that need API documentation, use the language/ecosystem-native format and the project's existing level of detail (for example, XML documentation comments in C#, docstrings in Python, or JSDoc/TSDoc in JavaScript/TypeScript). Document contract details such as parameters, return values, side effects, and expected exceptions only where they are meaningful and consistent with nearby code.
69+
- Match the natural language of the nearest existing code documentation. Use this precedence: the same symbol or type, then the current file/module, then the project's primary documentation language. If no reliable convention exists, use concise English. Do not mix languages within a local documentation block or translate unrelated existing comments unless the task explicitly requires it.
70+
- Do not add comments by quota, boilerplate documentation for self-explanatory code, or documentation churn in untouched areas. Update stale nearby documentation only when the code change makes it inaccurate.
71+
6672
## Agent System
6773
13 agents in the ControlFlow system:
6874
- **Orchestration:** Orchestrator

evals/tests/prompt-behavior-contract.test.mjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,45 @@ console.log('\n=== Shared Policy — Behavioral Invariants ===');
769769
/TRIVIAL/i.test(src) && /SMALL/i.test(src) &&
770770
/MEDIUM/i.test(src) && /LARGE/i.test(src)
771771
);
772+
773+
const codexShared = readFileSync(
774+
join(ROOT, 'plugins', 'controlflow-shared-source', 'skills', 'controlflow-planning', 'references', 'llm-behavior-guidelines.md'),
775+
'utf8'
776+
);
777+
const codexGenerated = readFileSync(
778+
join(ROOT, 'plugins', 'controlflow-codex', 'skills', 'controlflow-planning', 'references', 'llm-behavior-guidelines.md'),
779+
'utf8'
780+
);
781+
const claudeCode = readFileSync(
782+
join(ROOT, 'plugins', 'controlflow-claude-code', 'skills', 'controlflow-plan', 'references', 'llm-behavior-guidelines.md'),
783+
'utf8'
784+
);
785+
const documentationSurfaces = [src, codexShared, codexGenerated, claudeCode];
786+
787+
check(
788+
'Code documentation: core, Codex, and Claude preserve business intent without narrating code',
789+
documentationSurfaces.every(text =>
790+
/non-obvious business\s+rules/i.test(text) &&
791+
/decision\s+rationale/i.test(text) &&
792+
/(do not narrate|not narrate)/i.test(text)
793+
)
794+
);
795+
check(
796+
'Code documentation: native API docs include XML example and follow nearby documentation language',
797+
documentationSurfaces.every(text =>
798+
/language\/ecosystem-native\s+format/i.test(text) &&
799+
/XML documentation comments in\s+C#/i.test(text) &&
800+
/nearest existing code\s+documentation/i.test(text) &&
801+
/project's primary documentation\s+language/i.test(text)
802+
)
803+
);
804+
check(
805+
'Code documentation: no comment quotas or boilerplate for self-explanatory code',
806+
documentationSurfaces.every(text =>
807+
/comments by quota/i.test(text) &&
808+
/boilerplate documentation for self-explanatory code/i.test(text)
809+
)
810+
);
772811
}
773812

774813
// ──────────────────────────────────────────────

plugins/controlflow-claude-code/skills/controlflow-plan/references/llm-behavior-guidelines.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ main ControlFlow prompt set.
4747
- For multi-phase work, keep phase acceptance criteria and quality gates explicit.
4848
- Match verification strength to the completion claim, then state any residual gap.
4949

50+
### 5. Preserve Business Intent in Code Documentation
51+
52+
- Before completing an implementation phase, review changed code for non-obvious business
53+
rules, invariants, exceptions, constraints, and decision rationale that future
54+
maintainers would not recover safely from syntax alone. Explain why the behavior exists
55+
or what business condition it protects; do not narrate the code.
56+
- For new or materially changed public or extensible symbols that need API documentation,
57+
use the language/ecosystem-native format and the project's existing level of detail (for
58+
example, XML documentation comments in C#, docstrings in Python, or JSDoc/TSDoc in
59+
JavaScript/TypeScript).
60+
- Match the natural language of the nearest existing code documentation: prefer the same
61+
symbol or type, then the current file/module, then the project's primary documentation
62+
language. If no reliable convention exists, use concise English. Do not mix languages
63+
within one local documentation block or translate unrelated comments unless requested.
64+
- Do not add comments by quota or boilerplate documentation for self-explanatory code.
65+
Update nearby documentation only when the implementation change makes it inaccurate.
66+
5067
## Anti-Rationalization Table
5168

5269
| Pattern | Required Action |
@@ -57,6 +74,7 @@ main ControlFlow prompt set.
5774
| Clean up adjacent code while editing nearby lines | Keep edits tied to task scope and report unrelated observations without changing them. |
5875
| Skip verification because a change is prompt-only or documentation-only | Run the smallest relevant check plus any workflow-required gate. |
5976
| Treat a narrow pass as proof of a broad claim | Match the command to the claim and state what remains unverified. |
77+
| Add comments to make the diff look documented | Document only non-obvious business intent or meaningful API contracts, using the nearest established documentation language and style. |
6078

6179
## Decision Table
6280

plugins/controlflow-codex/skills/controlflow-planning/references/llm-behavior-guidelines.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Portable ControlFlow-Codex guardrails for avoiding common LLM coding anti-patter
4646
- For multi-phase work, keep phase acceptance criteria and quality gates explicit.
4747
- Match verification strength to the completion claim, then state any residual gap.
4848

49+
### 5. Preserve Business Intent in Code Documentation
50+
51+
- Before completing an implementation phase, review changed code for non-obvious business rules, invariants, exceptions, constraints, and decision rationale that future maintainers would not recover safely from syntax alone. Explain why the behavior exists or what business condition it protects; do not narrate the code.
52+
- For new or materially changed public or extensible symbols that need API documentation, use the language/ecosystem-native format and the project's existing level of detail (for example, XML documentation comments in C#, docstrings in Python, or JSDoc/TSDoc in JavaScript/TypeScript).
53+
- Match the natural language of the nearest existing code documentation: prefer the same symbol or type, then the current file/module, then the project's primary documentation language. If no reliable convention exists, use concise English. Do not mix languages within one local documentation block or translate unrelated comments unless requested.
54+
- Do not add comments by quota or boilerplate documentation for self-explanatory code. Update nearby documentation only when the implementation change makes it inaccurate.
55+
4956
## Anti-Rationalization Table
5057

5158
| Pattern | Required Action |
@@ -56,6 +63,7 @@ Portable ControlFlow-Codex guardrails for avoiding common LLM coding anti-patter
5663
| Clean up adjacent code while editing nearby lines | Keep edits tied to task scope and report unrelated observations without changing them. |
5764
| Skip verification because a change is prompt-only or documentation-only | Run the smallest relevant check plus any workflow-required gate. |
5865
| Treat a narrow pass as proof of a broad claim | Match the command to the claim and state what remains unverified. |
66+
| Add comments to make the diff look documented | Document only non-obvious business intent or meaningful API contracts, using the nearest established documentation language and style. |
5967

6068
## Decision Table
6169

plugins/controlflow-shared-source/skills/controlflow-planning/references/llm-behavior-guidelines.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ Portable ControlFlow-Codex guardrails for avoiding common LLM coding anti-patter
4646
- For multi-phase work, keep phase acceptance criteria and quality gates explicit.
4747
- Match verification strength to the completion claim, then state any residual gap.
4848

49+
### 5. Preserve Business Intent in Code Documentation
50+
51+
- Before completing an implementation phase, review changed code for non-obvious business rules, invariants, exceptions, constraints, and decision rationale that future maintainers would not recover safely from syntax alone. Explain why the behavior exists or what business condition it protects; do not narrate the code.
52+
- For new or materially changed public or extensible symbols that need API documentation, use the language/ecosystem-native format and the project's existing level of detail (for example, XML documentation comments in C#, docstrings in Python, or JSDoc/TSDoc in JavaScript/TypeScript).
53+
- Match the natural language of the nearest existing code documentation: prefer the same symbol or type, then the current file/module, then the project's primary documentation language. If no reliable convention exists, use concise English. Do not mix languages within one local documentation block or translate unrelated comments unless requested.
54+
- Do not add comments by quota or boilerplate documentation for self-explanatory code. Update nearby documentation only when the implementation change makes it inaccurate.
55+
4956
## Anti-Rationalization Table
5057

5158
| Pattern | Required Action |
@@ -56,6 +63,7 @@ Portable ControlFlow-Codex guardrails for avoiding common LLM coding anti-patter
5663
| Clean up adjacent code while editing nearby lines | Keep edits tied to task scope and report unrelated observations without changing them. |
5764
| Skip verification because a change is prompt-only or documentation-only | Run the smallest relevant check plus any workflow-required gate. |
5865
| Treat a narrow pass as proof of a broad claim | Match the command to the claim and state what remains unverified. |
66+
| Add comments to make the diff look documented | Document only non-obvious business intent or meaningful API contracts, using the nearest established documentation language and style. |
5967

6068
## Decision Table
6169

0 commit comments

Comments
 (0)