mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-04 22:21:57 +09:00
feat(install): install converted rules for the copilot target
The copilot project target installed only skills and agents, dropping the entire rules/ tree even though Copilot CLI and VS Code read path-specific instructions from .github/instructions/**/*.instructions.md. Plan each rules/**/*.md file into .github/instructions/ecc/ as an .instructions.md file and add a copilot-rule-frontmatter transform that maps the Claude-style `paths:` list onto Copilot's `applyTo:` glob list. Rules without `paths:` become applyTo: "**", matching their always-on semantics in Claude Code. rules/README.md documents the rule set and is not installed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
25278e7d7b
commit
6425693e4b
6 files changed
+231
-13
No files matched your search
@@ -1,17 +1,23 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const {
|
||||
createInstallTargetAdapter,
|
||||
createManagedOperation,
|
||||
listRelativeFiles,
|
||||
normalizeRelativePath,
|
||||
} = require('./helpers');
|
||||
|
||||
// GitHub Copilot CLI discovers skills from `.github/skills/` and custom agents
|
||||
// from `.github/agents/`. Explicitly declared package-manager helpers live in
|
||||
// `.github/ecc/scripts/`, outside Copilot's discovery roots. ECC's hooks target
|
||||
// Claude Code's event model, and commands rely on slash-command argument
|
||||
// substitution Copilot does not provide, so neither is installed here.
|
||||
const SUPPORTED_SOURCE_PREFIXES = ['agents', 'skills'];
|
||||
// GitHub Copilot CLI discovers skills from `.github/skills/`, custom agents
|
||||
// from `.github/agents/`, and path-specific instructions from
|
||||
// `.github/instructions/**/*.instructions.md`. Rules are installed under
|
||||
// `instructions/ecc/` with their Claude-style `paths:` frontmatter converted
|
||||
// to Copilot's `applyTo:` glob list. Explicitly declared package-manager
|
||||
// helpers live in `.github/ecc/scripts/`, outside Copilot's discovery roots.
|
||||
// ECC's hooks target Claude Code's event model, and commands rely on
|
||||
// slash-command argument substitution Copilot does not provide, so neither is
|
||||
// installed here.
|
||||
const SUPPORTED_SOURCE_PREFIXES = ['agents', 'skills', 'rules'];
|
||||
const COPILOT_HELPER_PATHS = new Set([
|
||||
'scripts/setup-package-manager.js',
|
||||
'scripts/lib/package-manager.js',
|
||||
@@ -35,7 +41,36 @@ function stripPrefix(normalizedPath, prefix) {
|
||||
return normalizedPath === prefix ? '' : normalizedPath.slice(`${prefix}/`.length);
|
||||
}
|
||||
|
||||
function planSourcePathOperations(module, sourceRelativePath, targetRoot) {
|
||||
// Rules expand to per-file operations because the destination renames each
|
||||
// Markdown file to `.instructions.md`, which a directory-level copy cannot
|
||||
// express. `rules/README.md` documents the rule set and is not installed.
|
||||
function planCopilotRuleOperations(module, normalizedSourcePath, targetRoot, repoRoot) {
|
||||
const sourceRoot = path.join(repoRoot || '', normalizedSourcePath);
|
||||
if (!repoRoot || !fs.existsSync(sourceRoot)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const prefix = stripPrefix(normalizedSourcePath, 'rules');
|
||||
const sourceFiles = fs.statSync(sourceRoot).isDirectory()
|
||||
? listRelativeFiles(sourceRoot).map(file => ({ source: `${normalizedSourcePath}/${file}`, relative: prefix ? `${prefix}/${file}` : file }))
|
||||
: [{ source: normalizedSourcePath, relative: path.basename(normalizedSourcePath) }];
|
||||
|
||||
return sourceFiles
|
||||
.filter(({ relative }) => /\.md$/i.test(relative) && !/(^|\/)README\.md$/i.test(relative))
|
||||
.map(({ source, relative }) => createManagedOperation({
|
||||
moduleId: module.id,
|
||||
sourceRelativePath: source,
|
||||
destinationPath: path.join(
|
||||
targetRoot,
|
||||
'instructions',
|
||||
'ecc',
|
||||
relative.replace(/\.md$/i, '.instructions.md')
|
||||
),
|
||||
contentTransform: 'copilot-rule-frontmatter',
|
||||
}));
|
||||
}
|
||||
|
||||
function planSourcePathOperations(module, sourceRelativePath, targetRoot, repoRoot) {
|
||||
const normalizedSourcePath = normalizeRelativePath(sourceRelativePath);
|
||||
|
||||
if (hasPrefix(normalizedSourcePath, 'agents')) {
|
||||
@@ -65,6 +100,10 @@ function planSourcePathOperations(module, sourceRelativePath, targetRoot) {
|
||||
];
|
||||
}
|
||||
|
||||
if (hasPrefix(normalizedSourcePath, 'rules')) {
|
||||
return planCopilotRuleOperations(module, normalizedSourcePath, targetRoot, repoRoot);
|
||||
}
|
||||
|
||||
if (COPILOT_HELPER_PATHS.has(normalizedSourcePath)) {
|
||||
return [createManagedOperation({
|
||||
moduleId: module.id,
|
||||
@@ -105,7 +144,8 @@ module.exports = createInstallTargetAdapter({
|
||||
.flatMap(sourceRelativePath => planSourcePathOperations(
|
||||
module,
|
||||
sourceRelativePath,
|
||||
targetRoot
|
||||
targetRoot,
|
||||
repoRoot
|
||||
));
|
||||
});
|
||||
},
|
||||
|
||||
@@ -488,6 +488,7 @@ module.exports = {
|
||||
createNamespacedFlatRuleOperations,
|
||||
createRemappedOperation,
|
||||
isForeignPlatformPath,
|
||||
listRelativeFiles,
|
||||
normalizeRelativePath,
|
||||
planClaudeHooksOperations,
|
||||
isWSL,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
const { stripPluginNamespace } = require('./plugin-namespace');
|
||||
const { adaptAntigravityAgent } = require('./antigravity-agent');
|
||||
const { adaptCopilotAgent } = require('./copilot-agent');
|
||||
const { adaptCopilotRule } = require('./copilot-rule');
|
||||
const { disableOpenCodeHookPluginRegistration, getDisabledOpenCodePluginContent } = require('./hook-consent');
|
||||
|
||||
function rewriteCopilotWorkflowPaths(content, sourceRelativePath) {
|
||||
@@ -32,6 +33,9 @@ function transformInstallContent(operation, content) {
|
||||
if (operation.contentTransform === 'copilot-workflow-paths') {
|
||||
return rewriteCopilotWorkflowPaths(content, operation.sourceRelativePath);
|
||||
}
|
||||
if (operation.contentTransform === 'copilot-rule-frontmatter') {
|
||||
return adaptCopilotRule(content, operation.sourceRelativePath);
|
||||
}
|
||||
if (operation.contentTransform === 'opencode-disable-ecc-hooks') {
|
||||
return transformInstallContent({ ...operation, contentTransform: 'opencode-home-skills-path' },
|
||||
disableOpenCodeHookPluginRegistration(content, operation.sourceRelativePath));
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
'use strict';
|
||||
|
||||
// GitHub Copilot loads path-specific instructions from
|
||||
// `.github/instructions/**/*.instructions.md`, where the `applyTo` frontmatter
|
||||
// key carries a comma-separated glob list. ECC rules express the same scoping
|
||||
// with the Claude Code convention, a YAML `paths:` list, and rules without
|
||||
// frontmatter apply to every prompt. The transform maps one model onto the
|
||||
// other: `paths:` becomes `applyTo:`, and a rule without `paths` becomes
|
||||
// `applyTo: "**"` so it keeps applying globally.
|
||||
//
|
||||
// The transform is an allowlist: only `paths` is read, so frontmatter keys
|
||||
// added to ECC rules later cannot silently leak into the Copilot copy.
|
||||
|
||||
const GLOBAL_APPLY_TO = '**';
|
||||
|
||||
function splitFrontmatter(source, label) {
|
||||
const match = String(source || '').match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n/);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Keep YAML loading behind the transform boundary. Public help commands load
|
||||
// the installer graph without executing a transform, including in hermetic
|
||||
// packed-artifact checks where runtime dependencies are intentionally absent.
|
||||
const frontmatter = require('js-yaml').load(match[1]);
|
||||
if (!frontmatter || typeof frontmatter !== 'object' || Array.isArray(frontmatter)) {
|
||||
throw new Error(`Cannot adapt Copilot rule ${label}: frontmatter must be an object`);
|
||||
}
|
||||
|
||||
return {
|
||||
frontmatter,
|
||||
body: String(source).slice(match[0].length),
|
||||
};
|
||||
}
|
||||
|
||||
function serializeApplyTo(globs) {
|
||||
return require('js-yaml')
|
||||
.dump({ applyTo: globs }, { lineWidth: -1, noRefs: true })
|
||||
.trimEnd();
|
||||
}
|
||||
|
||||
function adaptCopilotRule(source, label = '<unknown>') {
|
||||
const parsed = splitFrontmatter(source, label);
|
||||
|
||||
if (!parsed) {
|
||||
return `---\napplyTo: "${GLOBAL_APPLY_TO}"\n---\n${String(source || '')}`;
|
||||
}
|
||||
|
||||
const { frontmatter, body } = parsed;
|
||||
const paths = frontmatter.paths;
|
||||
|
||||
if (paths === undefined) {
|
||||
return `---\napplyTo: "${GLOBAL_APPLY_TO}"\n---\n${body}`;
|
||||
}
|
||||
|
||||
if (!Array.isArray(paths) || paths.some(glob => typeof glob !== 'string' || glob.trim() === '')) {
|
||||
throw new Error(`Cannot adapt Copilot rule ${label}: "paths" must be a list of glob strings`);
|
||||
}
|
||||
|
||||
return `---\n${serializeApplyTo(paths.map(glob => glob.trim()).join(','))}\n---\n${body}`;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
adaptCopilotRule,
|
||||
GLOBAL_APPLY_TO,
|
||||
};
|
||||
Reference in new issue
Block a user