OpenSpec icon indicating copy to clipboard operation
OpenSpec copied to clipboard

feat(instructions): inject config rules into apply and archive

Open showms opened this issue 6 months ago • 8 comments

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.apply
  • rules.archive

Keep existing artifact keys unchanged.

Scope

This proposal would:

  • extend config validation to allow workflow phase targets
  • inject rules.apply into apply instructions
  • inject rules.archive into 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.yaml
  • openspec/changes/extend-config-injection-to-apply-archive/proposal.md

Test plan

  • [x] Created the change scaffold with the default spec-driven schema
  • [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.

showms avatar May 07 '26 03:05 showms

[!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_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to 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

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 07 '26 03:05 coderabbitai[bot]

Updated the proposal to include the config structure, validation expectations, and docs/migration impact

showms avatar May 07 '26 04:05 showms

@alfred-openspec noted, proposal already captures both constraints

showms avatar May 09 '26 08:05 showms

Addressed — removed the type assertion for workflow rule targets, and added a comment clarifying the optional archive change validation

showms avatar May 11 '26 15:05 showms

@TabishB @alfred-openspec Follow-up changes are pushed and the latest feedback is addressed. Would appreciate a review when you have a moment

showms avatar May 11 '26 16:05 showms

@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 apply and archive are accepted explicitly
  • added tests for warnings, valid workflow targets, and cross-path deduplication

showms avatar May 18 '26 09:05 showms

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.

showms avatar May 19 '26 01:05 showms

@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.

showms avatar May 31 '26 15:05 showms