Skip to content

feat(ai): project rules — load AGENTS.md into the agent's system prompt - #21

Merged
ndemianc merged 2 commits into
developfrom
feat/agents-md-project-rules
Jul 19, 2026
Merged

feat(ai): project rules — load AGENTS.md into the agent's system prompt#21
ndemianc merged 2 commits into
developfrom
feat/agents-md-project-rules

Conversation

@ndemianc

Copy link
Copy Markdown
Contributor

Project rules — drop an AGENTS.md (or CLAUDE.md / .cursorrules) in a repo and the agent follows it from turn one.

  • projectRules.js — pure loader (loadProjectRules(folders, readFile)); file reading is injected as a callback, so it's unit-testable without a filesystem. Multi-root aware, first-present-file wins, empty files skipped, capped at 16KB.
  • agent.js — folds the rules into the cached system block (byte-stable per run → rides the prompt cache at ~0.1×), and posts a quiet 📋 project rules · AGENTS.md chip so you can see it's active.
  • test/projectRules.test.js — 10 cases (discovery, alias fallback, first-present-wins, multi-root, empty-skip, truncation, throwing reader) + a real-filesystem smoke test.
  • docs/PROJECT-RULES.md — how it works, precedence, and the trust model (rules yield to a direct request; they can't disable the host-side safety gates).

All 13 test files pass.

🤖 Generated with Claude Code

Drop an AGENTS.md (or CLAUDE.md / .cursorrules) in a repo and the agent follows
it from turn one. Loaded once per run into the cached system block (byte-stable,
so it rides the prompt cache), multi-root aware, first-present-file wins, capped
at 16KB. A quiet timeline chip shows when rules are active.

- projectRules.js: pure loader (file reading injected -> unit-testable)
- agent.js: fold rules.text into the system prompt + the indicator chip
- test/projectRules.test.js: 10 cases + a real-filesystem smoke test
- docs/PROJECT-RULES.md: how it works, precedence, and the trust model

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 19, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds “project rules” support to the LevelCode AI agent by loading repo-local rules files (e.g. AGENTS.md) once per agent run and injecting them into the agent’s system prompt, making repository conventions effective from the first turn.

Changes:

  • Introduces a pure, unit-testable rules loader (loadProjectRules) with filename precedence and per-file size capping.
  • Integrates project rules into the agent’s cached system prompt and surfaces an activity-timeline chip showing which rules files were loaded.
  • Adds unit tests and end-user documentation for behavior, precedence, and trust model.

Reviewed changes

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

File Description
extensions/levelcode-ai/projectRules.js Implements rules discovery/loading/formatting for injection into the system prompt.
extensions/levelcode-ai/agent.js Loads project rules once per run, appends them to the system prompt, and posts a “project rules” timeline chip.
extensions/levelcode-ai/test/projectRules.test.js Adds unit tests covering discovery, precedence, multi-root labeling, skipping empty files, truncation, and error handling.
docs/PROJECT-RULES.md Documents how rules are discovered, applied, labeled in multi-root workspaces, and bounded for safety/cost.

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

Comment thread extensions/levelcode-ai/projectRules.js Outdated
Comment thread docs/PROJECT-RULES.md Outdated
… test

- projectRules: a folder entry with a root but no name produced
  "undefined/AGENTS.md" in multi-root labels; fall back to path.basename(f.root).
- test: add the real-filesystem smoke test the doc referenced (writes an on-disk
  AGENTS.md and reads it back) — it was only run inline before — plus a case for
  the name fallback. 12 cases now.
- docs: describe the test coverage accurately.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ndemianc
ndemianc merged commit 3943d66 into develop Jul 19, 2026
1 check passed
@ndemianc
ndemianc deleted the feat/agents-md-project-rules branch July 21, 2026 17:06
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.

2 participants