Skip to content

feat: generate Copilot coding agent files on openspec init (github-copilot)#1274

Open
NicoAvanzDev wants to merge 8 commits into
Fission-AI:mainfrom
NicoAvanzDev:restore/pr-858-on-main
Open

feat: generate Copilot coding agent files on openspec init (github-copilot)#1274
NicoAvanzDev wants to merge 8 commits into
Fission-AI:mainfrom
NicoAvanzDev:restore/pr-858-on-main

Conversation

@NicoAvanzDev

@NicoAvanzDev NicoAvanzDev commented Jun 29, 2026

Copy link
Copy Markdown

Restores and updates #858 on top of current main.

Summary

When a user runs openspec init or openspec update with the github-copilot tool configured, OpenSpec generates the GitHub Copilot coding agent support files:

  • .github/workflows/copilot-setup-steps.yml
  • .github/agents/openspec.agent.md

The generated files are only written when missing, so user customizations are preserved. If github-copilot is no longer configured, openspec update removes the generated cloud-agent files when present.

Drift handled while restoring

  • Rebased the original two commits from feat: generate Copilot coding agent files on openspec init (github-copilot) #858 onto current main.
  • Updated the custom agent tool aliases to current Copilot custom-agent names (execute, read, search, edit).
  • Moved openspec update cloud-file sync so the files are created even when github-copilot is already up to date and smart update exits early.
  • Added file-operation coverage for write/skip/force/remove behavior plus an update regression test for the up-to-date path.

Testing

./node_modules/.bin/vitest run test/core/github-copilot-cloud-agent.test.ts test/core/update.test.ts
npm run build --ignore-scripts
git diff --check origin/main...HEAD

Restored from closed PR: #858

Summary by CodeRabbit

  • New Features
    • Added GitHub Copilot Cloud support to generate Copilot setup workflow and agent guidance files when Copilot is selected.
    • Files are created during initialization and kept in sync during update runs.
  • Bug Fixes
    • Copilot Cloud files are removed when Copilot is no longer selected to prevent stale artifacts.
    • Update recreates missing/outdated Copilot Cloud files; Copilot sync errors no longer block the update.
  • Tests
    • Added Vitest coverage for Copilot Cloud file generation, write/force behavior, and safe cleanup that preserves user changes.

…selected

When `openspec init` or `openspec update` is run with the github-copilot
tool selected, two additional files are now generated in the user's project:

1. `.github/workflows/copilot-setup-steps.yml` - A GitHub Actions workflow
   that pre-installs the OpenSpec CLI in the Copilot coding agent's
   ephemeral environment (required for the agent to use `openspec` commands).

2. `.github/agents/openspec.agent.md` - A custom agent definition that
   instructs the GitHub Copilot coding agent how to use the OpenSpec CLI,
   including all agent-compatible commands with `--json` output, workflow
   patterns, and best practices.

These files are only written if they don't already exist (to preserve
user customizations). The generation is non-fatal — if it fails, init/update
still completes successfully.

New module: src/core/github-copilot/cloud-agent.ts
Tests: test/core/github-copilot-cloud-agent.test.ts
When github-copilot is not in the configured tools during update,
remove the cloud agent files (copilot-setup-steps.yml and
openspec.agent.md) if they exist.
@NicoAvanzDev
NicoAvanzDev requested a review from TabishB as a code owner June 29, 2026 10:26
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

Adds GitHub Copilot cloud-agent file generation and lifecycle management. Initialization creates the files when Copilot is selected, while updates create or remove them according to configured tools. Tests cover content generation, filesystem behavior, legacy handling, and update integration.

Changes

Copilot Cloud Agent Files

Layer / File(s) Summary
Copilot cloud file generation and lifecycle
src/core/github-copilot/cloud-agent.ts
Adds Copilot detection, workflow and agent Markdown generators, managed-content recognition, conditional writing, and safe removal.
Init and update synchronization
src/core/init.ts, src/core/update.ts
Init writes Copilot files after tool setup. Update synchronizes them on early-return and completion paths, suppressing synchronization errors.
Cloud agent helper and filesystem validation
test/core/github-copilot-cloud-agent.test.ts
Tests generated content, paths, write and overwrite behavior, managed-file removal, customization preservation, and legacy agent content.
Update synchronization validation
test/core/update.test.ts
Tests removal when no tools are configured and recreation when Copilot is configured.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant InitCommand
  participant UpdateCommand
  participant CloudAgent
  participant ProjectFiles
  InitCommand->>CloudAgent: Detect github-copilot and write files
  UpdateCommand->>CloudAgent: Synchronize configured tool state
  CloudAgent->>ProjectFiles: Create, preserve, or remove .github files
Loading

Possibly related PRs

Suggested reviewers: tabishb, clay-good, xianzhetm

🚥 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 matches the main change: generating Copilot agent files during openspec init for github-copilot.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

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

Inline comments:
In `@src/core/github-copilot/cloud-agent.ts`:
- Around line 186-199: The cleanup in removeCopilotCloudFiles currently deletes
any existing file at the Copilot cloud paths, which can remove user-customized
files. Update removeCopilotCloudFiles to only unlink files that are known to be
generated/managed by the extension, and skip files that have been modified or
created by the user; use COPILOT_CLOUD_FILES and FileSystemUtils.fileExists as
the entry points for the check, and add a reliable ownership/safeguard before
calling fs.promises.unlink.

In `@src/core/update.ts`:
- Line 156: The no-tools early return in execute() is skipping Copilot file
cleanup, so stale cloud files can remain when github-copilot is removed. Move
the syncCopilotCloudFiles call in update.ts so it runs before the return path
that handles an empty tools list, and make sure both execute() and the related
sync flow around syncCopilotCloudFiles use the resolvedProjectPath and tool set
consistently even when there are no configured tools.

In `@test/core/github-copilot-cloud-agent.test.ts`:
- Around line 51-60: The test in generateCopilotAgentFile only verifies the
presence of execute, so it can miss regressions in the Copilot agent tool
aliases. Tighten the expectations in github-copilot-cloud-agent.test.ts to
assert all four aliases exposed by the updated contract are present: execute,
read, search, and edit, alongside the existing frontmatter and command checks.
- Around line 63-67: The COPILOT_CLOUD_FILES path assertions are too loose
because `toContain(...)` only checks filenames and can miss incorrect parent
directories or POSIX-only regressions. Update the
`github-copilot-cloud-agent.test.ts` checks to compare the full expected
relative paths using `path.join(...)`, referencing
`COPILOT_CLOUD_FILES.setupSteps` and `COPILOT_CLOUD_FILES.agent` so the test
validates separator behavior on Windows as well.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d3078b54-83db-4187-acde-3e207441355f

📥 Commits

Reviewing files that changed from the base of the PR and between 546224e and 6298928.

📒 Files selected for processing (5)
  • src/core/github-copilot/cloud-agent.ts
  • src/core/init.ts
  • src/core/update.ts
  • test/core/github-copilot-cloud-agent.test.ts
  • test/core/update.test.ts

Comment thread src/core/github-copilot/cloud-agent.ts
Comment thread src/core/update.ts Outdated
Comment thread test/core/github-copilot-cloud-agent.test.ts
Comment thread test/core/github-copilot-cloud-agent.test.ts

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for restoring this. The current guard is much safer for customized files, but I think the cleanup is now too strict: removeCopilotCloudFiles() only deletes files whose content exactly matches the current generated template.

That means a user who generated these files with an older OpenSpec version, then removed github-copilot, would keep stale generated .github/workflows/copilot-setup-steps.yml / .github/agents/openspec.agent.md files forever. That is the path this PR is explicitly trying to clean up.

I’d change the ownership check to recognize OpenSpec-generated legacy/current variants, e.g. a managed marker in new files plus a conservative legacy recognizer for the two templates this PR introduced. Customized files should still be skipped, but previously generated files should be removable when github-copilot is no longer configured.

Verified locally: pnpm exec vitest run test/core/github-copilot-cloud-agent.test.ts test/core/update.test.ts passes, 70 tests.

@NicoAvanzDev

Copy link
Copy Markdown
Author

Thanks for restoring this. The current guard is much safer for customized files, but I think the cleanup is now too strict: removeCopilotCloudFiles() only deletes files whose content exactly matches the current generated template.

That means a user who generated these files with an older OpenSpec version, then removed github-copilot, would keep stale generated .github/workflows/copilot-setup-steps.yml / .github/agents/openspec.agent.md files forever. That is the path this PR is explicitly trying to clean up.

I’d change the ownership check to recognize OpenSpec-generated legacy/current variants, e.g. a managed marker in new files plus a conservative legacy recognizer for the two templates this PR introduced. Customized files should still be skipped, but previously generated files should be removable when github-copilot is no longer configured.

Verified locally: pnpm exec vitest run test/core/github-copilot-cloud-agent.test.ts test/core/update.test.ts passes, 70 tests.

Thanks for reviewing this, I changed the cleanup logic and added tests for edge cases.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@test/core/github-copilot-cloud-agent.test.ts`:
- Around line 17-45: The synthetic legacy fixture helpers currently use silent
string replacements, so template drift can go unnoticed and the legacy-removal
path may stop being exercised. Harden removeManagedMarker and
generateLegacyCopilotAgentFile by asserting each expected replace target exists
before transforming the content, and fail the test immediately if any marker or
legacy text is missing. This should make the fixture generation loud when
generateCopilotAgentFile changes and keep the markerless/legacy tests
meaningful.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 863f6c2d-366b-4903-b8e9-a310e29e3a28

📥 Commits

Reviewing files that changed from the base of the PR and between e0a33e4 and 8349bb9.

📒 Files selected for processing (2)
  • src/core/github-copilot/cloud-agent.ts
  • test/core/github-copilot-cloud-agent.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/core/github-copilot/cloud-agent.ts

Comment thread test/core/github-copilot-cloud-agent.test.ts Outdated

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good. The latest commits address the legacy cleanup path without deleting customized files, and the fixture hardening makes the markerless legacy tests fail loudly if the generated templates drift.\n\nVerified locally: pnpm exec vitest run test/core/github-copilot-cloud-agent.test.ts test/core/update.test.ts, pnpm run lint, and pnpm run build.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/core/init.ts (1)

615-623: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Warn when Copilot file generation fails.

Keeping initialization non-fatal is reasonable, but the empty catch makes the command report success while the Copilot files may be missing. Emit a warning with the error details before continuing so users can diagnose the incomplete setup.

Suggested adjustment
-      } catch {
+      } catch (error) {
+        const message = error instanceof Error ? error.message : String(error);
+        console.warn(`Warning: failed to generate Copilot cloud agent files: ${message}`);
         // Non-fatal: don't block init if cloud agent files fail
       }
🤖 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/init.ts` around lines 615 - 623, Update the catch block around
writeCopilotCloudFiles in the GitHub Copilot initialization path to emit a
warning containing the caught error details, while preserving the non-fatal
behavior so initialization continues.
🤖 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/core/init.ts`:
- Around line 615-623: Update the catch block around writeCopilotCloudFiles in
the GitHub Copilot initialization path to emit a warning containing the caught
error details, while preserving the non-fatal behavior so initialization
continues.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 334da9d5-0d71-4164-9b3c-82c167408e3c

📥 Commits

Reviewing files that changed from the base of the PR and between 4388e7f and 1a258bd.

📒 Files selected for processing (3)
  • src/core/init.ts
  • src/core/update.ts
  • test/core/update.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/core/update.ts
  • test/core/update.test.ts

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.

3 participants