feat(instructions): inject config rules into apply and archive
Problem
openspec/config.yaml supports context and rules, but rules are only applied when generating artifact instructions. They are not surfaced in apply / archive flows, so project-level guidance becomes inconsistent across the workflow.
Why this matters
Users expect project constraints defined in config to apply throughout the workflow, not only while generating artifacts. This is especially important for:
- implementation constraints during
apply - safety and process constraints during
archive
In practice, this would make the workflow much more flexible. For example:
- during
apply, projects could specify execution guidance such as whether sub-agents are allowed, how much parallelization is appropriate, or what implementation constraints must still be followed - during
archive, projects could specify post-archive follow-up steps such as documentation cleanup, knowledge base updates, release note preparation, or other housekeeping actions
Proposed change
Allow reserved rules targets for workflow phases:
rules.applyrules.archive
Keep existing artifact keys unchanged.
Scope
This proposal would:
- extend config validation to allow workflow phase targets
- inject
rules.applyinto apply instructions - inject
rules.archiveinto archive workflow instructions - update tests and config help text
It does not redesign the config format.
In this PR
This PR only adds the OpenSpec proposal scaffolding for discussion before implementation:
openspec/changes/extend-config-injection-to-apply-archive/.openspec.yamlopenspec/changes/extend-config-injection-to-apply-archive/proposal.md
Test plan
- [x] Created the change scaffold with the default
spec-drivenschema - [x] Reviewed the proposal scope and backward-compatibility expectations
- [x] Confirmed this PR contains proposal files only
- [x] No runtime code changes in this PR, so no tests were run
Summary by CodeRabbit
- New Features
- Apply and Archive instruction outputs can include project-level context and workflow rules; added an Archive instructions command with JSON output (template, optional context, optional rules).
- Documentation
- Docs and config examples updated to show workflow rule keys (apply/archive) and how context/rules are injected and consumed.
- Tests
- Added unit and integration tests for instruction generation, rendering, validation, CLI JSON behavior, and warning deduplication.
- Behavior
- Workflow rule targets (apply/archive) accepted without artifact-ID warnings; unknown keys emit single-session warnings.
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] ▶️ Resume reviews
- [ ] 🔍 Trigger review
📝 Walkthrough
Walkthrough
Extends project-level context and rules injection to apply/archive instruction outputs, adds openspec instructions archive and archive instruction generation/printing, recognizes rules.apply/rules.archive as workflow targets, updates templates/CLI/types, and adds tests/specs/docs.
Changes
Config Injection Extension
| Layer / File(s) | Summary |
|---|---|
Proposal metadata openspec/changes/extend-config-injection-to-apply-archive/.openspec.yaml |
OpenSpec metadata file registers the proposal with schema: spec-driven and creation date. |
Proposal & design docs openspec/changes/extend-config-injection-to-apply-archive/proposal.md, design.md |
Defines goals, scope, validation changes, WORKFLOW_RULE_TARGETS, instruction-generation contract, and implementation touchpoints. |
Specs & docs openspec/changes/.../specs/*, docs/opsx.md |
Adds CLI archive-instructions spec, context/rules injection specs, opsx archive/bulk-archive requirements, and docs describing <project_context>/<rules> injection and workflow-phase keys. |
Config & prompts src/core/project-config.ts, src/core/config-prompts.ts, openspec/config.yaml |
Adds WORKFLOW_RULE_TARGETS, updates serializeConfig prompts/examples, and sample config.yaml entries for rules.apply and rules.archive. |
Instruction types & generation src/commands/workflow/shared.ts, src/commands/workflow/instructions.ts |
ApplyInstructions gains context? and rules?; adds ArchiveInstructions types, generateArchiveInstructions, archiveInstructionsCommand, and injects context/rules.apply into apply generation. |
CLI routing & exports src/cli/index.ts, src/commands/workflow/index.ts |
Routes instructions archive to archiveInstructionsCommand and re-exports archiveInstructionsCommand and ArchiveInstructionsOptions. |
Validation & loader src/core/artifact-graph/instruction-loader.ts, src/core/project-config.ts |
Centralizes config rule validation into emitConfigRuleWarnings(), accepts workflow targets as valid keys, and delegates warning dedupe to a session cache. |
Templates & workflows src/core/templates/workflows/* |
Apply/archive/bulk-archive templates updated to fetch openspec instructions archive --json, apply returned context/rules as behavioral constraints (not copied), and renumber steps. |
Tests & parity test/**/* |
Adds tests for generate/print apply/archive instructions, warning dedupe, CLI JSON output; updates template parity hashes. |
Tasks / Rollout openspec/changes/.../tasks.md |
Checklist for validation, unit/integration tests, CLI wiring, template regeneration, and docs/examples updates. |
Sequence Diagram(s)
sequenceDiagram
participant CLI as CLI
participant InstrMod as InstructionsModule
participant ProjectCfg as ProjectConfig
participant Validator as ConfigValidator
CLI->>InstrMod: request apply/archive instructions (--json)
InstrMod->>ProjectCfg: read config (context, rules)
InstrMod->>Validator: emitConfigRuleWarnings(rules, validArtifactIds, schema)
InstrMod->>InstrMod: build template + attach optional context/rules
InstrMod->>CLI: return { template, context?, rules? }
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- Fission-AI/OpenSpec#499: Related prior work on project-level config injection and instruction generation.
- Fission-AI/OpenSpec#698: Overlaps template logic for fetching instructions and template updates.
- Fission-AI/OpenSpec#547: Related separation of context/rules as JSON constraints (not embedded in templates).
Suggested reviewers
- TabishB
- alfred-openspec
Poem
🐰 I hop through configs, tidy and bright,
I tuck context in instructions at night,
Apply and archive now hear rules I convey,
I whisper guidance, then bound on my way.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 38.10% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Title check | ✅ Passed | The PR title accurately summarizes the main change: extending config rule injection to the apply and archive instruction generation paths, which is the core objective of this changeset. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Updated the proposal to include the config structure, validation expectations, and docs/migration impact
@alfred-openspec noted, proposal already captures both constraints
Addressed — removed the type assertion for workflow rule targets, and added a comment clarifying the optional archive change validation
@TabishB @alfred-openspec Follow-up changes are pushed and the latest feedback is addressed. Would appreciate a review when you have a moment
@alfred-openspec Thanks for the review — I addressed the validation gap in this update.
Changes made:
- apply/archive instructions now validate
rules.*keys against schema artifact IDs - reserved workflow targets
applyandarchiveare accepted explicitly - added tests for warnings, valid workflow targets, and cross-path deduplication
Follow-up update: the validation-gap fix is in, and I also addressed the latest CodeRabbit follow-ups.
@alfred-openspec @TabishB would appreciate a re-review when convenient.
@alfred-openspec friendly ping when you have a chance.
The validation-gap issue from the May 17 review has been fixed, and the latest follow-up is included in the current head commit from May 29.
I also noticed the CI run on the latest commit is showing action_required. If that needs maintainer approval or anything else from my side, I’m happy to help.