Skip to content

Add path-scoped Copilot instructions for context/ and routing/#146

Merged
dgenio merged 8 commits intomainfrom
copilot/add-copilot-instructions-context-routing
Mar 10, 2026
Merged

Add path-scoped Copilot instructions for context/ and routing/#146
dgenio merged 8 commits intomainfrom
copilot/add-copilot-instructions-context-routing

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

Summary

The two largest subsystems — context engine (11 modules) and routing engine (9 modules) — lacked agent-facing guidance scoped to their directories. Agents editing manager.py or graph.py had no subsystem-specific invariants to follow, risking broken pipeline ordering, firewall bypasses, or invalid graph states.

Changes

  • .github/instructions/context.instructions.md (applyTo: src/contextweaver/context/**)

  • .github/instructions/routing.instructions.md (applyTo: src/contextweaver/routing/**)

    • All 4 ChoiceGraph._validate() invariants documented (root exists, children resolve, no cycles, all items reachable)
    • Eager cycle detection in add_edge() — must not be bypassed
    • TreeBuilder 3-strategy priority order (namespace → Jaccard clustering → alphabetical) with fallback conditions
    • Router determinism: (-score, id) sort key must not change; confidence_gap bounds
    • generate_sample_catalog seed=42 is a contract — demos and tests depend on it
    • ChoiceCard schema prohibition; sync-only routing; no cross-engine imports

Both files are ≤100 lines, documentation-only, and grounded in actual code.

Checklist

  • Tests added or updated for every new/changed public function
  • make ci passes locally (fmt + lint + type + test + example + demo)
  • CHANGELOG.md updated under ## [Unreleased]
  • Docstrings added for all new public APIs (Google-style)
  • Every modified module stays ≤ 300 lines (or a decomposition issue is linked above)
  • Related issue linked in the summary above
  • Agent-facing docs updated if pipeline, API, or conventions changed

Notes for reviewers

Instruction files are loaded automatically by VS Code Copilot when editing files under the targeted paths — no tooling changes required. Content is derived directly from manager.py docstring, graph.py._validate(), router.py.route(), tree.py.build(), and catalog.py.generate_sample_catalog() — reviewers should cross-check those sources if any rule seems off.

Original prompt

This section details on the original issue you should resolve

<issue_title>[agent] Add path-scoped Copilot instructions for context/ and routing/</issue_title>
<issue_description>## Problem

The two largest subsystems — context engine (9 modules, 1113 lines) and routing engine (9 modules, 1568 lines) — lack module-specific agent guidance. Root-level files (AGENTS.md, CLAUDE.md, .github/copilot-instructions.md) provide general conventions but don't cover subsystem-specific invariants.

Agents editing context/manager.py (629 lines, the largest module) or routing/graph.py (316 lines) need scoped rules to avoid breaking critical invariants like pipeline stage ordering, firewall guarantees, or ChoiceGraph validation constraints.

Evidence:

Proposal

Create 2 path-scoped Copilot instruction files that VS Code Copilot automatically loads when editing files in the corresponding directories.

.github/instructions/context.instructions.md

Apply to src/contextweaver/context/**. Should cover:

.github/instructions/routing.instructions.md

Apply to src/contextweaver/routing/**. Should cover:

  • ChoiceGraph validation rules: root must exist, all children must resolve, all items must be reachable, no cycles
  • TreeBuilder strategies: namespace grouping → Jaccard clustering → alphabetical fallback
  • Router beam-search constraints: deterministic tie-break by ID, confidence_gap threshold
  • Catalog invariants: generate_sample_catalog is seeded for reproducibility
  • ChoiceCard: never include full schemas (keeps prompt tokens minimal)
  • All routing is synchronous (pure computation, no async)

Acceptance criteria

File paths

  • .github/instructions/context.instructions.md (create)
  • .github/instructions/routing.instructions.md (create)

Dependencies

  • None (independent)

Estimated effort

S (1-2 days)</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: dgenio <12731907+dgenio@users.noreply.github.com>
Copilot AI changed the title [WIP] Add path-scoped Copilot instructions for context and routing subsystems Add path-scoped Copilot instructions for context/ and routing/ Mar 9, 2026
@dgenio dgenio requested a review from Copilot March 9, 2026 14:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds path-scoped Copilot instruction files to provide subsystem-specific invariants and editing guidance for the context engine and routing engine directories.

Changes:

  • Introduces .github/instructions/context.instructions.md scoped to src/contextweaver/context/** with pipeline/firewall/sensitivity guidance.
  • Introduces .github/instructions/routing.instructions.md scoped to src/contextweaver/routing/** with ChoiceGraph/TreeBuilder/Router/Catalog invariants and determinism rules.

Reviewed changes

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

File Description
.github/instructions/context.instructions.md Adds context-engine pipeline ordering and firewall/sensitivity invariants for agents editing src/contextweaver/context/**.
.github/instructions/routing.instructions.md Adds routing-engine graph validation + determinism + catalog/card constraints for agents editing src/contextweaver/routing/**.

You can also share your feedback on Copilot code review. Take the survey.

@dgenio dgenio marked this pull request as ready for review March 9, 2026 14:27
dgenio added 6 commits March 10, 2026 06:08
Stage 5 in context.instructions.md incorrectly described scoring as
'TF-IDF relevance scoring'. The actual implementation in scoring.py
uses recency + Jaccard token overlap + kind priority + token penalty.

Addresses review comment on PR #146.
…ctions

_build() is the synchronous core; both build() (async) and build_sync()
delegate directly to it. There is no asyncio.run() wrapper. Updated the
async-first pattern section to match the actual implementation.

Addresses review comment on PR #146.
Exact line counts go stale with every edit. The issue reference
(#73) already tracks module size  no need to duplicate the count
in the instruction file.

Addresses review comment on PR #146.
The _ensure_index() filter is 'node_id not in self._items', which
selects non-item nodes (navigation/structural), not non-leaf nodes.
A navigation node can be a leaf, so 'non-leaf' was imprecise.

Addresses review comment on PR #146.
Both _build() and _build_call_prompt() follow the same sync-core /
async-wrapper / sync-wrapper delegation pattern. Added a bullet so
agents editing call-prompt methods see the pattern applies there too.

Addresses nit review comment on PR #146.
Adds an entry under [Unreleased] / ### Added for the new context/
and routing/ instruction files.

Addresses PR #146 checklist item.
@dgenio dgenio merged commit 33b0d08 into main Mar 10, 2026
3 checks passed
@dgenio dgenio deleted the copilot/add-copilot-instructions-context-routing branch March 10, 2026 06:24
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.

[agent] Add path-scoped Copilot instructions for context/ and routing/

3 participants