Skip to content

Propose extending config injection to apply and archive.#1062

Open
showms wants to merge 5 commits into
Fission-AI:mainfrom
showms:feat/extend-config-injection-to-apply-archive
Open

Propose extending config injection to apply and archive.#1062
showms wants to merge 5 commits into
Fission-AI:mainfrom
showms:feat/extend-config-injection-to-apply-archive

Conversation

@showms
Copy link
Copy Markdown

@showms showms commented May 7, 2026

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

  • Created the change scaffold with the default spec-driven schema
  • Reviewed the proposal scope and backward-compatibility expectations
  • Confirmed this PR contains proposal files only
  • 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, and CLI JSON behavior.
  • Behavior
    • Workflow rule targets (apply/archive) no longer produce artifact-ID validation warnings.

Keep the existing context and rules model, but make it available on the apply and archive instruction surfaces for proposal-first upstream discussion.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@showms showms requested a review from TabishB as a code owner May 7, 2026 03:36
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f5609088-12fc-4a4c-b4a3-f278062235c9

📥 Commits

Reviewing files that changed from the base of the PR and between 21bfbe6 and 3bfc5eb.

📒 Files selected for processing (3)
  • src/commands/workflow/instructions.ts
  • src/core/artifact-graph/instruction-loader.ts
  • src/core/project-config.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/core/project-config.ts
  • src/core/artifact-graph/instruction-loader.ts
  • src/commands/workflow/instructions.ts

📝 Walkthrough

Walkthrough

This PR extends project-level context and rules injection to apply/archive instruction outputs, adds an openspec instructions archive command and archive instruction generation/printing, filters workflow rule keys from artifact validation, updates templates/skills to consume returned constraints, and adds tests/specs/docs.

Changes

Config Injection Extension Proposal

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
openspec/changes/extend-config-injection-to-apply-archive/proposal.md, design.md
Defines goals/scope, validation changes, WORKFLOW_RULE_TARGETS, instruction generation/printing contract, and implementation touchpoints.
Workflow Targets & Config
src/core/project-config.ts, src/core/config-prompts.ts, openspec/config.yaml
Adds WORKFLOW_RULE_TARGETS = {'apply','archive'} and updates config prompt comments and sample config.yaml to include rules.apply and rules.archive.
CLI & Exports
src/cli/index.ts, src/commands/workflow/index.ts
Adds routing for artifactId === 'archive' and re-exports archiveInstructionsCommand and options types.
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 generateApplyInstructions.
Instruction Printing
src/commands/workflow/instructions.ts
Printers render <project_context> and <rules> blocks after built-in template/instruction content for apply and archive text output.
Validation Filtering
src/core/artifact-graph/instruction-loader.ts
Strips workflow rule keys before calling validateConfigRules() to avoid unknown-artifact warnings for apply/archive.
Templates & Workflows
src/core/templates/workflows/*
Apply/archive/bulk-archive templates updated to fetch openspec instructions archive --json, apply returned context/rules as constraints (not copied into outputs), and renumber workflow steps.
Specs & Docs
openspec/changes/.../specs/*, docs/opsx.md
Add CLI archive-instructions spec, context/rules injection specs, opsx archive/bulk-archive requirements, and docs updates describing <project_context>/<rules> injection and workflow-phase keys.
Tests & Parity
test/**/*
Add tests for generate/print instructions, validation warning behavior, CLI JSON output; update skill-template parity hashes.
Tasks / Rollout
openspec/changes/extend-config-injection-to-apply-archive/tasks.md
Checklist for validation, unit/integration tests, CLI wiring, template regeneration, and docs/examples updates.

Sequence Diagram(s)

sequenceDiagram
  participant UserCLI as CLI
  participant InstrMod as InstructionsModule
  participant ProjectCfg as ProjectConfig
  participant Validator as Validator
  UserCLI->>InstrMod: request apply/archive instructions (--json)
  InstrMod->>ProjectCfg: read config (context, rules)
  InstrMod->>Validator: filter workflow keys (apply, archive)
  InstrMod->>InstrMod: build template + attach optional context/rules
  InstrMod->>UserCLI: return { template, context?, rules? }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • TabishB
  • alfred-openspec

Poem

🐰 I hop through configs, tidy and bright,

I tuck context in instructions by night,
Apply and archive hear rules I convey,
Gentle guidance — then off I hop away.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.78% 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.
Title check ✅ Passed The title accurately summarizes the main change: extending config injection mechanism to apply and archive workflow phases, which is the core objective of the PR.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Copy Markdown
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.

🧹 Nitpick comments (3)
openspec/changes/extend-config-injection-to-apply-archive/proposal.md (3)

9-10: ⚡ Quick win

Document the config structure for workflow-specific rules.

The proposal mentions extending rules to provide workflow-specific guidance, but doesn't specify how users will structure their config. The PR description mentions rules.apply and rules.archive as reserved targets, but this detail should be documented in the proposal itself for implementation clarity.

📋 Suggested addition

Consider adding a subsection under "What Changes" that shows the config structure:

### Config Structure

Users will specify workflow-specific rules using reserved targets:
- `rules.apply`: guidance applied during `/opsx:apply` instruction generation
- `rules.archive`: guidance applied during `/opsx:archive` instruction generation
- Artifact keys (e.g., `rules.api`, `rules.workflow`) remain unchanged for backward compatibility
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openspec/changes/extend-config-injection-to-apply-archive/proposal.md` around
lines 9 - 10, Add a short "Config Structure" subsection under "What Changes"
that documents how to specify workflow-specific rules and context: explain that
`rules.apply` and `rules.archive` are reserved targets for guidance applied
during `/opsx:apply` and `/opsx:archive` instruction generation, that `context`
injection will make the existing project context available to `apply` and
`archive` workflows as well as artifact instructions, and note that existing
artifact keys like `rules.api` and `rules.workflow` remain supported for
backward compatibility.

7-14: 💤 Low value

Consider documenting validation and error handling expectations.

The proposal doesn't discuss how the system should handle invalid or conflicting rules (e.g., malformed rules.apply, conflicts between artifact and workflow rules). While not essential for initial proposal review, documenting these expectations would help guide implementation and testing.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openspec/changes/extend-config-injection-to-apply-archive/proposal.md` around
lines 7 - 14, Add a short section to the proposal describing validation and
error-handling expectations for the extended injection: specify schema/format
checks for rules (e.g., rules.apply), how to detect and report malformed rules,
precedence rules when workflow-level rules conflict with artifact-level rules,
and the expected runtime behavior (reject/ignore/merge) and error messages for
apply and archive instruction processing; reference the injected symbols
`context`, the `rules` object and `rules.apply`/`rules.archive` and state that
implementations must surface validation errors to callers and include
unit/integration test coverage for these cases.

26-31: ⚡ Quick win

Consider adding user-facing documentation to the impact list.

The impact section identifies implementation areas (config parsing, instruction generation, templates, tests) but doesn't mention user-facing documentation, examples, or migration guidance. Adding these would help users understand how to adopt the new workflow-specific rules.

📚 Suggested addition

Consider adding to the impact list:

- User documentation will need examples showing how to configure `rules.apply` 
  and `rules.archive` alongside existing artifact rules.
- Consider providing migration examples for teams currently restating guidance 
  across artifact instructions and manual apply/archive steps.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@openspec/changes/extend-config-injection-to-apply-archive/proposal.md` around
lines 26 - 31, Add user-facing documentation and migration guidance to the
Impact list: update the Impact section to explicitly include user documentation,
examples, and migration notes showing how to configure rules.apply and
rules.archive alongside artifact rules, and where to find/update docs
(referencing changes in src/core/project-config.ts,
src/commands/workflow/instructions.ts, archive templates, and
src/core/config-prompts.ts); include example snippets and a short migration
guide for teams converting artifact-based guidance to workflow-specific rules so
docs, prompts, and tests reflect the new instruction surfaces.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@openspec/changes/extend-config-injection-to-apply-archive/proposal.md`:
- Around line 9-10: Add a short "Config Structure" subsection under "What
Changes" that documents how to specify workflow-specific rules and context:
explain that `rules.apply` and `rules.archive` are reserved targets for guidance
applied during `/opsx:apply` and `/opsx:archive` instruction generation, that
`context` injection will make the existing project context available to `apply`
and `archive` workflows as well as artifact instructions, and note that existing
artifact keys like `rules.api` and `rules.workflow` remain supported for
backward compatibility.
- Around line 7-14: Add a short section to the proposal describing validation
and error-handling expectations for the extended injection: specify
schema/format checks for rules (e.g., rules.apply), how to detect and report
malformed rules, precedence rules when workflow-level rules conflict with
artifact-level rules, and the expected runtime behavior (reject/ignore/merge)
and error messages for apply and archive instruction processing; reference the
injected symbols `context`, the `rules` object and `rules.apply`/`rules.archive`
and state that implementations must surface validation errors to callers and
include unit/integration test coverage for these cases.
- Around line 26-31: Add user-facing documentation and migration guidance to the
Impact list: update the Impact section to explicitly include user documentation,
examples, and migration notes showing how to configure rules.apply and
rules.archive alongside artifact rules, and where to find/update docs
(referencing changes in src/core/project-config.ts,
src/commands/workflow/instructions.ts, archive templates, and
src/core/config-prompts.ts); include example snippets and a short migration
guide for teams converting artifact-based guidance to workflow-specific rules so
docs, prompts, and tests reflect the new instruction surfaces.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9486a521-0d63-47ca-bf4f-329bc9133923

📥 Commits

Reviewing files that changed from the base of the PR and between 053d8a5 and b50f737.

📒 Files selected for processing (2)
  • openspec/changes/extend-config-injection-to-apply-archive/.openspec.yaml
  • openspec/changes/extend-config-injection-to-apply-archive/proposal.md

Document reserved apply and archive rule targets, validation expectations, and user-facing docs impact for the proposal discussion.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@showms
Copy link
Copy Markdown
Author

showms commented May 7, 2026

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

Copy link
Copy Markdown
Collaborator

@alfred-openspec alfred-openspec left a comment

Choose a reason for hiding this comment

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

This is the right direction: workflow-phase guidance belongs on apply/archive, and proposal-only scope is a good way to settle the contract before implementation. I’d keep rules.apply and rules.archive as reserved workflow targets, but the implementation should avoid turning them into artifact-rule warnings and should keep the built-in apply/archive safety prompts higher priority than config guidance.

@showms
Copy link
Copy Markdown
Author

showms commented May 9, 2026

@alfred-openspec noted, proposal already captures both constraints

…kflows

Add WORKFLOW_RULE_TARGETS constant for 'apply' and 'archive'
Add openspec instructions archive command
Extend generateApplyInstructions with context and rules.apply
Update apply/archive/bulk-archive templates to consume injected config
Add workflow rule examples to generated config.yaml
Document rules.apply and rules.archive in opsx.md
Refs: openspec/changes/extend-config-injection-to-apply-archive
Copy link
Copy Markdown
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.

🧹 Nitpick comments (2)
src/core/artifact-graph/instruction-loader.ts (1)

246-251: ⚡ Quick win

Consider eliminating the type assertion for better type safety.

The filtering logic is correct, but the type assertion (WORKFLOW_RULE_TARGETS as Set<string>) on line 248 bypasses TypeScript's type checking. Since WORKFLOW_RULE_TARGETS is defined as Set<WorkflowId>, the .has() method expects a WorkflowId, but receives an arbitrary string from Object.entries().

A cleaner approach would be to define WORKFLOW_RULE_TARGETS as Set<string> in project-config.ts:

export const WORKFLOW_RULE_TARGETS = new Set<string>(['apply', 'archive'] as const satisfies readonly WorkflowId[]);

This maintains compile-time checking that the values are valid WorkflowId literals while allowing runtime string comparison without type assertions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/artifact-graph/instruction-loader.ts` around lines 246 - 251, The
code uses a type assertion (WORKFLOW_RULE_TARGETS as Set<string>) to allow
.has(key) when filtering projectConfig.rules, which weakens type safety; change
the declaration of WORKFLOW_RULE_TARGETS in project-config.ts to be Set<string>
(e.g., construct it from readonly WorkflowId[] but typed Set<string>) so you can
call WORKFLOW_RULE_TARGETS.has(key) without assertions, then remove the cast in
instruction-loader.ts where artifactOnlyRules is built and keep the call into
validateConfigRules unchanged.
src/commands/workflow/instructions.ts (1)

497-499: 💤 Low value

Clarify the purpose of optional change validation.

The command validates that the change exists when provided, but generateArchiveInstructions (line 501) doesn't accept or use the change name. This validation appears to be either:

  1. A courtesy check to ensure the user is in the right context, or
  2. Future-proofing for change-specific archive logic not yet implemented.

If it's (1), consider adding a comment explaining the intent. If it's (2), consider whether the validation should be deferred until the feature is needed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/workflow/instructions.ts` around lines 497 - 499, The optional
call to validateChangeExists(options.change, projectRoot) is ambiguous because
generateArchiveInstructions does not use the change name; either add a one-line
comment above this if-block clarifying that this is a courtesy/contextual
validation (i.e., "ensure provided change name exists so the user is in the
right context") or, if the intent is future change-specific logic, remove/defer
the validation until that feature is implemented; refer to validateChangeExists,
options.change and generateArchiveInstructions when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/commands/workflow/instructions.ts`:
- Around line 497-499: The optional call to validateChangeExists(options.change,
projectRoot) is ambiguous because generateArchiveInstructions does not use the
change name; either add a one-line comment above this if-block clarifying that
this is a courtesy/contextual validation (i.e., "ensure provided change name
exists so the user is in the right context") or, if the intent is future
change-specific logic, remove/defer the validation until that feature is
implemented; refer to validateChangeExists, options.change and
generateArchiveInstructions when making the change.

In `@src/core/artifact-graph/instruction-loader.ts`:
- Around line 246-251: The code uses a type assertion (WORKFLOW_RULE_TARGETS as
Set<string>) to allow .has(key) when filtering projectConfig.rules, which
weakens type safety; change the declaration of WORKFLOW_RULE_TARGETS in
project-config.ts to be Set<string> (e.g., construct it from readonly
WorkflowId[] but typed Set<string>) so you can call
WORKFLOW_RULE_TARGETS.has(key) without assertions, then remove the cast in
instruction-loader.ts where artifactOnlyRules is built and keep the call into
validateConfigRules unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 785f619e-962c-4b51-ac1c-a4d23b545921

📥 Commits

Reviewing files that changed from the base of the PR and between ecd5d38 and 21bfbe6.

📒 Files selected for processing (25)
  • docs/opsx.md
  • openspec/changes/extend-config-injection-to-apply-archive/design.md
  • openspec/changes/extend-config-injection-to-apply-archive/proposal.md
  • openspec/changes/extend-config-injection-to-apply-archive/specs/cli-archive-instructions/spec.md
  • openspec/changes/extend-config-injection-to-apply-archive/specs/cli-artifact-workflow/spec.md
  • openspec/changes/extend-config-injection-to-apply-archive/specs/context-injection/spec.md
  • openspec/changes/extend-config-injection-to-apply-archive/specs/opsx-archive-skill/spec.md
  • openspec/changes/extend-config-injection-to-apply-archive/specs/opsx-bulk-archive-skill/spec.md
  • openspec/changes/extend-config-injection-to-apply-archive/specs/rules-injection/spec.md
  • openspec/changes/extend-config-injection-to-apply-archive/tasks.md
  • openspec/config.yaml
  • src/cli/index.ts
  • src/commands/workflow/index.ts
  • src/commands/workflow/instructions.ts
  • src/commands/workflow/shared.ts
  • src/core/artifact-graph/instruction-loader.ts
  • src/core/config-prompts.ts
  • src/core/project-config.ts
  • src/core/templates/workflows/apply-change.ts
  • src/core/templates/workflows/archive-change.ts
  • src/core/templates/workflows/bulk-archive-change.ts
  • test/commands/apply-archive-instructions.test.ts
  • test/commands/artifact-workflow.test.ts
  • test/core/artifact-graph/instruction-loader.test.ts
  • test/core/templates/skill-templates-parity.test.ts
✅ Files skipped from review due to trivial changes (7)
  • src/commands/workflow/index.ts
  • openspec/changes/extend-config-injection-to-apply-archive/specs/cli-archive-instructions/spec.md
  • openspec/changes/extend-config-injection-to-apply-archive/specs/opsx-archive-skill/spec.md
  • src/core/config-prompts.ts
  • openspec/changes/extend-config-injection-to-apply-archive/specs/opsx-bulk-archive-skill/spec.md
  • docs/opsx.md
  • openspec/changes/extend-config-injection-to-apply-archive/tasks.md

@showms
Copy link
Copy Markdown
Author

showms commented May 11, 2026

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

@showms
Copy link
Copy Markdown
Author

showms commented May 11, 2026

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

@showms showms requested a review from alfred-openspec May 11, 2026 16:00
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.

2 participants