-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Feature] inject project context into all skills and enforce constraints #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lsmonki
wants to merge
1
commit into
Fission-AI:main
Choose a base branch
from
lsmonki:feature/project-context-all-skills
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| schema: spec-driven | ||
| created: 2026-02-12 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| ## Context | ||
|
|
||
| Project context (`config.yaml` → `context` field) reaches only skills that call `openspec instructions <artifact>` — Continue, FF, New, Onboard. Skills that call `openspec instructions apply` (Apply, Verify) or no instructions at all (Explore, Archive, Bulk-archive, Sync) operate blind to project constraints. | ||
|
|
||
| Additionally, skills that do receive `context`, `rules`, and `instruction` use weak enforcement language ("guidance", "apply as constraints") rather than mandatory directives. | ||
|
|
||
| Current architecture: | ||
|
|
||
| ``` | ||
| readProjectConfig() | ||
| │ | ||
| └──► generateInstructions() ──► ArtifactInstructions { context, rules } | ||
| └──► `instructions <artifact>` command | ||
| └──► Continue, FF, New, Onboard ✅ | ||
|
|
||
| ╳ generateApplyInstructions() ──► ApplyInstructions { NO context } | ||
| └──► `instructions apply` command | ||
| └──► Apply, Verify ❌ | ||
|
|
||
| ╳ (no pathway) ──► Explore, Archive, Bulk-archive, Sync ❌ | ||
| ``` | ||
|
|
||
| ## Goals / Non-Goals | ||
|
|
||
| **Goals:** | ||
| - Every skill that generates, validates, or reasons about code/artifacts has access to project context | ||
| - `context`, `rules`, and `instruction` are communicated as mandatory constraints in all skill prompts | ||
| - Minimal CLI API surface change — reuse existing `instructions` command | ||
|
|
||
| **Non-Goals:** | ||
| - Changing how `rules` work (they remain per-artifact, only relevant to artifact-creating skills) | ||
| - Adding context to the Feedback skill (not project-work related) | ||
| - Caching or performance optimization of `readProjectConfig()` (already benchmarked as fast enough) | ||
|
|
||
| ## Decisions | ||
|
|
||
| ### 1. Add `--context` flag to existing `instructions` command | ||
|
|
||
| **Choice:** New `--context` flag on `openspec instructions` rather than a separate `openspec context` command. | ||
|
|
||
| **Rationale:** The `instructions` command is already the single entry point for AI agents to get guidance. Adding `--context` keeps the API surface small. The flag works without `--change` or artifact arguments since project context is change-independent. | ||
|
|
||
| **Usage:** | ||
| ```bash | ||
| openspec instructions --context # text output | ||
| openspec instructions --context --json # { "context": "..." } | ||
| ``` | ||
|
|
||
| **Behavior:** | ||
| - `--context` can be used alone (text output) or with `--json` (structured output) | ||
| - `--context` is incompatible with `--change`, `--schema`, and artifact arguments. Error if any are combined. | ||
| - Reads `config.yaml` via `readProjectConfig()` | ||
| - Returns only the `context` field (not `rules` — those are per-artifact) | ||
| - Returns empty/null gracefully if no config or no context defined | ||
|
|
||
| **Alternative considered:** Separate `openspec context` command. Rejected because it fragments the instruction pathway and adds a command that only returns one field. | ||
|
|
||
| ### 2. Add `context` to `ApplyInstructions` | ||
|
|
||
| **Choice:** Enrich `generateApplyInstructions()` to call `readProjectConfig()` and include `context` in the response, same pattern as `generateInstructions()`. | ||
|
|
||
| **Rationale:** Apply and Verify already call `instructions apply --json`. Adding `context` to the response means these skills get project context without changing their flow. | ||
|
|
||
| **Changes:** | ||
| - `ApplyInstructions` interface: add `context?: string` | ||
| - `generateApplyInstructions()`: call `readProjectConfig()`, extract `context` | ||
| - `printApplyInstructionsText()`: print `<project_context>` block (same format as artifact instructions) | ||
|
|
||
| ### 3. Standardize enforcement language across all skill prompts | ||
|
|
||
| **Choice:** Define a consistent block of text that every skill uses when describing how to handle `context`, `rules`, and `instruction`. | ||
|
|
||
| **Pattern for artifact-creating skills** (Continue, FF, New, Onboard): | ||
| ``` | ||
| **You MUST follow these fields from the instructions output:** | ||
| - `context`: Project constraints. You MUST follow these when creating artifacts. Do NOT include in output. | ||
| - `rules`: Artifact-specific rules. You MUST follow these. Do NOT include in output. | ||
| - `instruction`: Directives for how to create this artifact. You MUST follow these. | ||
| ``` | ||
|
|
||
| **Pattern for code-operating skills** (Apply, Verify): | ||
| ``` | ||
| **You MUST follow the `context` field** from the instructions output. | ||
| This contains project constraints (tech stack, conventions, cross-platform rules) | ||
| that you MUST respect when implementing/verifying code. Do NOT include in output. | ||
| ``` | ||
|
|
||
| **Pattern for change-independent skills** (Explore, Archive, Bulk-archive, Sync): | ||
| ``` | ||
| At the start, load project context: | ||
| \`\`\`bash | ||
| openspec instructions --context --json | ||
| \`\`\` | ||
| If it returns a `context` field, you MUST follow these project constraints | ||
| throughout the session. | ||
| ``` | ||
|
|
||
| ### 4. Per-skill context consumption | ||
|
|
||
| | Skill | Context source | What changes | | ||
| |-------|---------------|--------------| | ||
| | **Continue** | `instructions <artifact> --json` | Strengthen enforcement language | | ||
| | **FF** | `instructions <artifact> --json` | Strengthen enforcement language | | ||
| | **New** | `instructions <artifact> --json` | Strengthen enforcement language | | ||
| | **Onboard** | `instructions <artifact> --json` | Strengthen enforcement language | | ||
| | **Apply** | `instructions apply --json` | Add context consumption + enforcement | | ||
| | **Verify** | `instructions apply --json` | Add context consumption + enforcement | | ||
| | **Explore** | `instructions --context --json` | Add context loading at session start | | ||
| | **Archive** | `instructions --context --json` | Add context loading at session start | | ||
| | **Bulk-archive** | `instructions --context --json` | Add context loading at session start | | ||
| | **Sync** | `instructions --context --json` | Add context loading at session start | | ||
| | **Feedback** | N/A | No changes (not project-work related) | | ||
|
|
||
| ## Risks / Trade-offs | ||
|
|
||
| **[Prompt length increase]** → Every skill prompt grows by a few lines. Acceptable — clarity is worth the tokens. | ||
|
|
||
| **[`--context` flag overlap with other options]** → `--context` errors if combined with `--change`, `--schema`, or an artifact argument. Strict validation, no ambiguity. | ||
|
|
||
| **[No config file]** → Skills calling `--context` when no `config.yaml` exists. → Return gracefully (empty context), skill continues without constraints. Same behavior as `generateInstructions()` today. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ## Why | ||
|
|
||
| The project context defined in `openspec/config.yaml` (tech stack, conventions, cross-platform rules) doesn't reach most skills. Only skills that call `openspec instructions <artifact>` (Continue, FF, New, Onboard) receive it. Skills that call `openspec instructions apply` (Apply, Verify) or don't call instructions at all (Explore, Archive, Bulk-archive, Sync) operate without knowing basic project constraints. Additionally, even skills that do receive `context`, `rules`, and `instruction` describe them with weak language ("guidance", "apply as constraints") rather than treating them as mandatory directives. | ||
|
|
||
| Ref: [GitHub Issue #696](https://github.com/Fission-AI/OpenSpec/issues/696) | ||
|
|
||
| ## What Changes | ||
|
|
||
| - Add `context` field to `ApplyInstructions` interface and `generateApplyInstructions()` function, reading it from `readProjectConfig()` — same pattern as `generateInstructions()` already does for artifact instructions | ||
| - Add `openspec instructions --context` standalone flag that returns the project context from `config.yaml` without requiring a change name or artifact ID. Supports `--json` for structured output. Incompatible with `--change`, `--schema`, and artifact arguments; error if combined | ||
| - Update **all** skill prompts to consume project context and to use mandatory language ("you MUST follow", not "apply as constraints") for `context`, `rules`, and `instruction` fields | ||
| - Document the new `--context` flag in CLI documentation | ||
|
|
||
| ## Capabilities | ||
|
|
||
| ### New Capabilities | ||
| - `cli-instructions-context`: Standalone `--context` flag on the `instructions` command that returns project context without requiring a change or artifact | ||
| - `skill-context-enforcement`: Consistent, mandatory language across all skill prompts for how `context`, `rules`, and `instruction` fields must be followed | ||
|
|
||
| ### Modified Capabilities | ||
| - `instruction-loader`: Add `context` field to `ApplyInstructions` so `instructions apply` returns project context alongside tasks and progress | ||
|
|
||
| ## Impact | ||
|
|
||
| - `src/commands/workflow/instructions.ts` — `generateApplyInstructions()` must call `readProjectConfig()` and include `context` in output; `instructionsCommand()` must handle `--context` flag | ||
| - `src/commands/workflow/shared.ts` — `ApplyInstructions` interface gets `context` field | ||
| - `src/core/templates/skill-templates.ts` — All skill template prompts updated for context consumption and enforcement language | ||
| - `.claude/commands/opsx/*.md` — All generated slash command files updated accordingly | ||
| - CLI documentation for the `--context` flag | ||
| - Tests for instructions command and apply instructions |
42 changes: 42 additions & 0 deletions
42
openspec/changes/project-context-all-skills/specs/cli-instructions-context/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| ## ADDED Requirements | ||
|
|
||
| ### Requirement: Standalone context flag | ||
| The `openspec instructions` command SHALL support a `--context` flag that returns the project context from `config.yaml` without requiring a change name or artifact ID. | ||
|
|
||
| #### Scenario: Return project context as text | ||
| - **WHEN** `openspec instructions --context` is called | ||
| - **THEN** the command reads `openspec/config.yaml` via `readProjectConfig()` and outputs the `context` field as plain text | ||
|
|
||
| #### Scenario: Return project context as JSON | ||
| - **WHEN** `openspec instructions --context --json` is called | ||
| - **THEN** the command outputs `{ "context": "<context string>" }` | ||
|
|
||
| #### Scenario: No config file exists | ||
| - **WHEN** `openspec instructions --context` is called and no `openspec/config.yaml` exists | ||
| - **THEN** the command outputs nothing (text mode) or `{ "context": null }` (JSON mode) and exits with code 0 | ||
|
|
||
| #### Scenario: Config exists but no context field | ||
| - **WHEN** `openspec instructions --context` is called and `config.yaml` exists but has no `context` field | ||
| - **THEN** the command outputs nothing (text mode) or `{ "context": null }` (JSON mode) and exits with code 0 | ||
|
|
||
| ### Requirement: Context flag exclusivity | ||
| The `--context` flag SHALL be incompatible with change-specific and artifact-specific options. | ||
|
|
||
| #### Scenario: Combined with --change | ||
| - **WHEN** `openspec instructions --context --change "some-change"` is called | ||
| - **THEN** the command outputs an error message and exits with non-zero code | ||
|
|
||
| #### Scenario: Combined with --schema | ||
| - **WHEN** `openspec instructions --context --schema "some-schema"` is called | ||
| - **THEN** the command outputs an error message and exits with non-zero code | ||
|
|
||
| #### Scenario: Combined with artifact argument | ||
| - **WHEN** `openspec instructions proposal --context` is called | ||
| - **THEN** the command outputs an error message and exits with non-zero code | ||
|
|
||
| ### Requirement: CLI documentation | ||
| The `--context` flag SHALL be documented in the CLI reference documentation. | ||
|
|
||
| #### Scenario: Documentation includes context flag | ||
| - **WHEN** a user reads `docs/cli.md` | ||
| - **THEN** the `openspec instructions` section documents the `--context` flag with usage examples and behavior |
32 changes: 32 additions & 0 deletions
32
openspec/changes/project-context-all-skills/specs/instruction-loader/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| ## MODIFIED Requirements | ||
|
|
||
| ### Requirement: Template Enrichment | ||
| The system SHALL enrich templates with change-specific context. | ||
|
|
||
| #### Scenario: Include artifact metadata | ||
| - **WHEN** instructions are generated for an artifact | ||
| - **THEN** the output includes change name, artifact ID, schema name, and output path | ||
|
|
||
| #### Scenario: Include dependency status | ||
| - **WHEN** an artifact has dependencies | ||
| - **THEN** the output shows each dependency with completion status (done/missing) | ||
|
|
||
| #### Scenario: Include unlocked artifacts | ||
| - **WHEN** instructions are generated | ||
| - **THEN** the output includes which artifacts become available after this one | ||
|
|
||
| #### Scenario: Root artifact indicator | ||
| - **WHEN** an artifact has no dependencies | ||
| - **THEN** the dependency section indicates this is a root artifact | ||
|
|
||
| #### Scenario: Include project context in apply instructions | ||
| - **WHEN** `generateApplyInstructions()` is called for a change | ||
| - **THEN** the output includes a `context` field read from `config.yaml` via `readProjectConfig()` | ||
|
|
||
| #### Scenario: Apply instructions with no config | ||
| - **WHEN** `generateApplyInstructions()` is called and no `config.yaml` exists | ||
| - **THEN** the `context` field is `undefined` and the rest of the apply instructions are unaffected | ||
|
|
||
| #### Scenario: Apply instructions text output includes project context | ||
| - **WHEN** `printApplyInstructionsText()` is called with a non-empty `context` field | ||
| - **THEN** the text output includes a `<project_context>` block with the context content, matching the format used by artifact instructions |
57 changes: 57 additions & 0 deletions
57
...spec/changes/project-context-all-skills/specs/skill-context-enforcement/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| ## ADDED Requirements | ||
|
|
||
| ### Requirement: Mandatory enforcement language for artifact-creating skills | ||
| Skills that create artifacts (Continue, FF, New, Onboard) SHALL use mandatory language ("you MUST follow") when describing how to handle `context`, `rules`, and `instruction` fields from the instructions output. | ||
|
|
||
| #### Scenario: Continue skill enforcement | ||
| - **WHEN** the Continue skill prompt describes the `context`, `rules`, and `instruction` fields | ||
| - **THEN** it uses "you MUST follow" language and explicitly states these are mandatory constraints, not suggestions | ||
|
|
||
| #### Scenario: FF skill enforcement | ||
| - **WHEN** the FF skill prompt describes the `context`, `rules`, and `instruction` fields | ||
| - **THEN** it uses "you MUST follow" language and explicitly states these are mandatory constraints, not suggestions | ||
|
|
||
| #### Scenario: New skill enforcement | ||
| - **WHEN** the New skill prompt describes the `context`, `rules`, and `instruction` fields | ||
| - **THEN** it uses "you MUST follow" language and explicitly states these are mandatory constraints, not suggestions | ||
|
|
||
| #### Scenario: Onboard skill enforcement | ||
| - **WHEN** the Onboard skill prompt describes the `context`, `rules`, and `instruction` fields | ||
| - **THEN** it uses "you MUST follow" language and explicitly states these are mandatory constraints, not suggestions | ||
|
|
||
| ### Requirement: Context consumption for code-operating skills | ||
| Skills that operate on code (Apply, Verify) SHALL consume the `context` field from `instructions apply --json` and use mandatory enforcement language. | ||
|
|
||
| #### Scenario: Apply skill consumes context | ||
| - **WHEN** the Apply skill reads the output of `openspec instructions apply --json` | ||
| - **THEN** it treats the `context` field as mandatory project constraints that MUST be followed when implementing code | ||
|
|
||
| #### Scenario: Verify skill consumes context | ||
| - **WHEN** the Verify skill reads the output of `openspec instructions apply --json` | ||
| - **THEN** it treats the `context` field as mandatory project constraints that MUST be followed when verifying code | ||
|
|
||
| ### Requirement: Context loading for change-independent skills | ||
| Skills that operate without a change context (Explore, Archive, Bulk-archive, Sync) SHALL load project context at session start via `openspec instructions --context --json`. | ||
|
|
||
| #### Scenario: Explore skill loads context | ||
| - **WHEN** the Explore skill starts a session | ||
| - **THEN** it calls `openspec instructions --context --json` and treats the `context` field as mandatory project constraints | ||
|
|
||
| #### Scenario: Archive skill loads context | ||
| - **WHEN** the Archive skill starts a session | ||
| - **THEN** it calls `openspec instructions --context --json` and treats the `context` field as mandatory project constraints | ||
|
|
||
| #### Scenario: Bulk-archive skill loads context | ||
| - **WHEN** the Bulk-archive skill starts a session | ||
| - **THEN** it calls `openspec instructions --context --json` and treats the `context` field as mandatory project constraints | ||
|
|
||
| #### Scenario: Sync skill loads context | ||
| - **WHEN** the Sync skill starts a session | ||
| - **THEN** it calls `openspec instructions --context --json` and treats the `context` field as mandatory project constraints | ||
|
|
||
| ### Requirement: Generated slash commands match skill templates | ||
| The generated `.claude/commands/opsx/*.md` files SHALL reflect the same enforcement language as their corresponding skill templates in `skill-templates.ts`. | ||
|
|
||
| #### Scenario: Slash commands are regenerated | ||
| - **WHEN** skills are generated via `openspec skills generate` | ||
| - **THEN** all `.claude/commands/opsx/*.md` files contain the updated mandatory enforcement language matching their skill template |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would all skills need this? the context field is is meant to help guide planning or creating the change proposal?
I agree that yes, the
Exploreskill could benefit from this.But do the rest actually benefit from this? i.e
archive?sync,bulk-archive??There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I implemented this, I was already thinking ahead to the hook system from my other PR. My intention was to avoid introducing another refactor later if hooks start requiring contextual information.
You're right — at the moment there are no hooks, so strictly speaking the additional context is not required.
Also, in my current setup the context is not only about providing generic project metadata (like “this is a TS project with Node”). It explicitly instructs the agent to review the existing specs under specs/ before making changes, to ensure compliance with previous architectural decisions, conventions, constraints...
So the goal is consistency with existing specs, not just additional descriptive context.
That said, I understand that in the current state it may not be strictly necessary, and I’m fine simplifying it if you prefer to introduce it later.