Skip to content

[Feature] inject project context into all skills and enforce constraints#703

Open
lsmonki wants to merge 1 commit intoFission-AI:mainfrom
lsmonki:feature/project-context-all-skills
Open

[Feature] inject project context into all skills and enforce constraints#703
lsmonki wants to merge 1 commit intoFission-AI:mainfrom
lsmonki:feature/project-context-all-skills

Conversation

@lsmonki
Copy link

@lsmonki lsmonki commented Feb 12, 2026

Summary

  • Add openspec instructions --context CLI command to expose project context from config.yaml independently of any change or artifact
  • Inject project context into apply instructions output via a new context field
  • Update all skill templates (explore, continue, apply, ff, archive, bulk-archive, sync, verify) to load project context at session start
  • Strengthen enforcement language from "IMPORTANT" to "MANDATORY" for context, rules, and instruction fields across all skill and opsx command templates

Motivation

The config.yaml context field defines critical project constraints (tech stack, conventions, cross-platform rules), but not all skills had access to it. Explore mode, archive, bulk-archive, and sync operated without project context entirely. Other skills used softer language ("constraints for you") that agents sometimes ignored.

Changes

CLI (src/cli/index.ts, src/commands/workflow/instructions.ts)

  • New --context flag on openspec instructions that returns project context without requiring a change or artifact
  • Exclusive flag: cannot be combined with --change, --schema, or an artifact argument
  • Supports --json output for agent consumption

Apply instructions (src/commands/workflow/instructions.ts, src/commands/workflow/shared.ts)

  • generateApplyInstructions() now reads and returns project context in the context field
  • printApplyInstructionsText() outputs context in a <project_context> block with AI-directed suppression comment

Skill templates (src/core/templates/skill-templates.ts)

  • All skills now call openspec instructions --context --json at session start
  • Enforcement language upgraded: "IMPORTANT" -> "MANDATORY", "constraints for you" -> "you MUST follow"
  • Consistent phrasing across all skill and opsx command templates
  • instruction field elevated to same mandatory status as context and rules

Docs (docs/cli.md)

  • Document the three modes of openspec instructions: artifact, apply, context-only
  • Add examples for --context and --context --json
  • Document context-only JSON output format

Tests (test/commands/artifact-workflow.test.ts)

  • Tests for contextInstructionsCommand with and without config
  • Tests for --context flag exclusivity validation
  • Tests for project context injection in apply instructions

Related issues

Summary by CodeRabbit

Release Notes

  • New Features

    • New --context flag for instructions command outputs project context from config.yaml in text or JSON format
    • Project context is now automatically included in apply instructions output
    • Skills now enforce project context as mandatory constraints that must be followed
  • Documentation

    • Updated CLI documentation with new --context flag, usage, and examples
  • Tests

    • Added test coverage for context flag behavior and integration

Add `openspec instructions --context` CLI command to expose project
context from config.yaml independently of any change. Update all skill
templates (explore, continue, apply, ff, archive, bulk-archive, sync,
verify) to load project context at session start and follow it as
mandatory constraints. Strengthen enforcement language from "IMPORTANT"
to "MANDATORY" for context, rules, and instruction fields across all
skill and opsx command templates. Inject project context into apply
instructions output via a new `context` field.
@lsmonki lsmonki requested a review from TabishB as a code owner February 12, 2026 17:52
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

This PR introduces a --context flag to the openspec instructions command for retrieving project context from config.yaml. It extends the instruction generation system to propagate context into ApplyInstructions and updates skill templates to enforce and consume project context as mandatory constraints across artifact creation and verification workflows.

Changes

Cohort / File(s) Summary
CLI & Workflow Commands
src/cli/index.ts, src/commands/workflow/index.ts, src/commands/workflow/instructions.ts, src/commands/workflow/shared.ts
Adds --context flag to instructions command with exclusivity validation (incompatible with --change, --schema, artifact args); introduces contextInstructionsCommand to read and output project context from config.yaml; extends ApplyInstructions interface with optional context field; updates instruction generation and printing logic to include context blocks in both text and JSON formats.
Skill Templates
src/core/templates/skill-templates.ts
Updates artifact creation and code-operating skill templates with standardized "Project Context" directive blocks; adds context loading via openspec instructions --context --json; reframes context/rules/instruction fields as mandatory constraints (not to be copied into artifacts); applies consistent enforcement language across multiple skill templates (Continue, FF, New, Onboard, Apply, Verify, Explore, Archive, Sync, Bulk Archive).
Documentation & Design
docs/cli.md, openspec/changes/project-context-all-skills/design.md, openspec/changes/project-context-all-skills/proposal.md, openspec/changes/project-context-all-skills/specs/*
Adds comprehensive design document, proposal, and requirement specifications for context flag feature; documents three instruction modes (artifact, apply, context-only); includes behavior for missing config/context fields and output format examples (text and JSON); provides CLI usage examples and validation rules.
Configuration & Testing
openspec/changes/project-context-all-skills/.openspec.yaml, test/commands/artifact-workflow.test.ts
Introduces project spec-driven configuration; adds comprehensive test coverage for context flag behavior (JSON/text outputs, exclusivity validation, graceful fallbacks when config is missing or lacks context field), and verifies context propagation in apply instructions across all scenarios.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • TabishB

🐰 A flag named --context hops into view,
Project config now flows where instructions grew,
Mandatory constraints in templates so bright,
Context and rules enforced—all done right! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding project context injection to all skills with enforced constraints via new CLI flag and mandatory language updates.
Linked Issues check ✅ Passed The PR fully addresses issue #696 by implementing a standalone CLI flag (openspec instructions --context) that allows all skills to load project context without requiring artifact/change coupling, and adds mandatory enforcement language across skill templates.
Out of Scope Changes check ✅ Passed All changes align with the PR objectives: new --context CLI flag, context injection into ApplyInstructions, skill template updates to load context, mandatory enforcement language, documentation, and tests. No unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 90.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/core/templates/skill-templates.ts (1)

2115-2127: ⚠️ Potential issue | 🟡 Minor

Opsx FF command template is missing the MANDATORY guardrail block present in the FF skill template.

The FF skill template (getFfChangeSkillTemplate, lines 767-771) includes a **MANDATORY** block reinforcing that context, rules, and instruction must be followed and not copied. The corresponding opsx command template here omits that block, though it does have MUST language earlier (lines 2082-2090).

Per the skill-context-enforcement spec (line 52-57), generated slash commands should reflect the same enforcement language as their skill templates.

Proposed fix — add MANDATORY block to opsx:ff guidelines
 **Artifact Creation Guidelines**

 - Follow the \`instruction\` field from \`openspec instructions\` for each artifact type
 - The schema defines what each artifact should contain - follow it
 - Read dependency artifacts for context before creating new ones
 - Use the \`template\` as a starting point, filling in based on context
+- **MANDATORY**: \`context\`, \`rules\`, and \`instruction\` from the instructions output are constraints you MUST follow
+  - \`context\`: Project-level constraints (tech stack, conventions) — follow them, do NOT copy into the artifact
+  - \`rules\`: Artifact-specific rules — follow them, do NOT copy into the artifact
+  - \`instruction\`: Directives for how to create this artifact — follow them
+  - Do NOT copy \`<context>\`, \`<rules>\`, \`<project_context>\` blocks into the artifact

 **Guardrails**
🧹 Nitpick comments (1)
src/commands/workflow/instructions.ts (1)

515-533: Consider extracting the shared config-reading pattern.

Lines 519-524 duplicate the pattern from lines 396-401 (readProjectConfig + extract context + try/catch). Both could share a small helper like readProjectContext(projectRoot): string | null. Low priority since there are only two call sites and the return types intentionally differ (null vs undefined).

@greptile-apps
Copy link

greptile-apps bot commented Feb 12, 2026

Greptile Overview

Greptile Summary

This PR ensures all skills have access to project context from config.yaml and strengthens enforcement of constraints. Previously, only artifact-creating skills (Continue, FF, New) received project context, while Apply/Verify and exploration skills (Explore, Archive, Sync) operated without it.

Major changes:

  • Added openspec instructions --context CLI command to expose project context independently
  • Injected context field into apply instructions output via generateApplyInstructions()
  • Updated all 10+ skill templates to load project context at session start
  • Strengthened enforcement language from "IMPORTANT" to "MANDATORY" across all skills
  • Added comprehensive test coverage (9 new test cases)

Implementation quality:

  • Clean separation of concerns: context-only, artifact, and apply modes
  • Proper flag exclusivity validation prevents misuse
  • Graceful degradation when no config exists
  • Consistent error handling with try-catch blocks
  • Well-documented with inline comments and updated CLI docs

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The implementation is well-architected with comprehensive test coverage, proper error handling, backward compatibility, and clear documentation. All changes follow existing patterns, validation prevents misuse, and the feature gracefully degrades when config is missing.
  • No files require special attention

Important Files Changed

Filename Overview
src/cli/index.ts Added --context flag to instructions command with proper exclusivity validation
src/commands/workflow/instructions.ts Implemented context injection in apply instructions and new context-only command
src/commands/workflow/shared.ts Added optional context field to ApplyInstructions interface
src/core/templates/skill-templates.ts Updated all skill templates to load project context and strengthened enforcement language from IMPORTANT to MANDATORY
test/commands/artifact-workflow.test.ts Comprehensive test coverage for context injection in apply instructions and context-only command
docs/cli.md Documented the three modes of instructions command including new --context flag

Sequence Diagram

sequenceDiagram
    participant Agent as AI Agent/Skill
    participant CLI as openspec CLI
    participant Config as readProjectConfig()
    participant Instructions as generateInstructions()
    participant ApplyInst as generateApplyInstructions()
    
    Note over Agent,ApplyInst: Context-only mode (Explore, Archive, Sync, etc.)
    Agent->>CLI: openspec instructions --context --json
    CLI->>Config: Read config.yaml
    Config-->>CLI: {context: "..."}
    CLI-->>Agent: {context: "..."}
    
    Note over Agent,ApplyInst: Artifact mode (Continue, FF, New, etc.)
    Agent->>CLI: openspec instructions <artifact> --change <name> --json
    CLI->>Instructions: generateInstructions()
    Instructions->>Config: Read config.yaml
    Config-->>Instructions: {context, rules}
    Instructions-->>CLI: {context, rules, template, instruction, ...}
    CLI-->>Agent: Full artifact instructions
    
    Note over Agent,ApplyInst: Apply mode (Apply, Verify)
    Agent->>CLI: openspec instructions apply --change <name> --json
    CLI->>ApplyInst: generateApplyInstructions()
    ApplyInst->>Config: Read config.yaml (NEW)
    Config-->>ApplyInst: {context}
    ApplyInst-->>CLI: {context, tasks, progress, ...}
    CLI-->>Agent: Apply instructions with context
Loading

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.

[Bug] Explore skill doesn't read project context from config.yaml

1 participant