feat(#2099): drive GitHub Copilot through the EoS descriptor + multi-event hook bus (ADR-1239)
Fold Copilot's residual runtime-literal branches onto descriptor-driven hostBehaviors. Several issue premises were inaccurate (verified via research) and deliberately NOT followed: writesSharedSettings/"legacy exclusion list" (per-runtime descriptor data, copilot's false is correct); RUNTIME_CONTENT_DISPATCH.copilot + installSurface==='copilot-instructions' (already descriptor-driven); extendedHookEvents (closed Claude/Gemini enum — hooks extended in code instead); reapply ternary (already folded, kimi #2095). Real folds (all byte-parity — golden byte-identical for every runtime): - src/install-engine.cts + src/surface.cts: the two `.agent.md` filename cutovers (_copyStaged + _syncGsdDir) unified onto hostBehaviors.agentFileExtension via a new exported agentFileExtensionFor() accessor (kills the two-mechanism divergence). - src/runtime-artifact-conversion.cts: applyAgentPathRewrites' copilot skip → hostBehaviors.noPathRewrite:true (antigravity #2096 precedent). - bin/install.js uninstall: the two isCopilot cleanup branches → installSurface=== 'copilot-instructions' gate (symmetric with install-time). - bin/install.js: `!isCopilot` in the two skipSharedHooksInstall checks → hostBehaviors.skipSharedHooksInstall:true (copilot has no shared gsd-*.js hooks). - bin/install.js: three dead legacy inline-agent-loop isCopilot refs removed (copilot ∈ _DESCRIPTOR_AGENTS_RUNTIMES → unreachable; byte-parity proven by clean golden + real reachable-runtime install diffs). isCopilot dropped from 4 destructures. Zero live `runtime==='copilot'`/`isCopilot` branches remain in bin/install.js, install-engine.cts, surface.cts, or runtime-artifact-conversion.cts (AC2 guard scans all four). UPGRADE 1 (multi-event hook bus): buildCopilotHookConfig() now emits preToolUse/ postToolUse/userPromptSubmitted/sessionEnd advisory handlers alongside sessionStart (static inline bash/powershell — deterministic, golden-trackable). Only copilot.json's gsd-session.json hash changes. UPGRADE 2 (background dispatch): surfaced via the negotiated contract only — dispatch.background:true exceeds the declarative-cli baseline and survives negotiation with no downgrade warning. NO .agent.md frontmatter field (copilot has none). MCP companion out of scope (AC4 names only 2 upgrades). Tests: declarative-reference-copilot (adapter/axes/fail-closed + AC2 4-file source-grep guard) + copilot-upgrades (live 5-event hook wiring; dispatch.background negotiation). Matrix EoS note + how-to; changeset (Changed). capability-registry regenerated. Incidental flaky-test RE-ARCHITECTURE (no-defer, maintainer-directed): tests/opencode-review-reconstruction.property.test.cjs spawned ~600 synchronous execFileSync('jq') subprocesses (numRuns:200 × 3 fast-check properties, one jq per generated stream); a single jq freezing on a contended macos-22 CI runner hung the whole unit-test chunk to its 600s kill (this PR's CI). --test-force-exit can't interrupt a synchronous execFileSync, so the cure is to stop spawning per case, not just time-bound it. Re-architected to run the SHIPPED jq program over the whole fast-check corpus in ONE jq process: each generated stream is one compact-JSON array per line in a temp file, `jq -c <PROGRAM>` (no -s) applies PROGRAM to each array (`.` == the array, exactly what production's `jq -rs <file>` sees after slurping) and emits one result per line — empirically byte-identical to the per-stream form across embedded-newline/empty/quote/ unicode/null-drop cases, and file-input (like production) so there's no stdin pipe to deadlock on large I/O. ~600 spawns → 6; coverage unchanged (200-case corpus per property, deterministic seeds) plus explicit boundary/diagnostic example batches. Still property- tests the real shipped jq (no JS reimplementation). Per-call jq timeout retained as a belt-and-suspenders bound. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -342,9 +342,13 @@ function _copyStaged(stagedDir: string, destDir: string, kind: any, configDir: s
|
||||
let destName: string;
|
||||
if (kind.kind === 'agents') {
|
||||
// Agent files already carry the gsd- prefix in the source dir.
|
||||
// #1575: copilot agents get .agent.md suffix (mirrors inline loop line ~9118).
|
||||
destName = runtime === 'copilot'
|
||||
? entry.name.replace(/\.md$/, '.agent.md')
|
||||
// #2099: descriptor-driven via hostBehaviors.agentFileExtension (was
|
||||
// hardcoded `runtime === 'copilot'`). copilot declares '.agent.md';
|
||||
// every other runtime's descriptor leaves this unset, so destName falls
|
||||
// back to entry.name unchanged (byte-parity, #1575 origin comment).
|
||||
const _agentExt = runtime ? _hostBehaviors(runtime).agentFileExtension : undefined;
|
||||
destName = _agentExt
|
||||
? entry.name.replace(/\.md$/, _agentExt)
|
||||
: entry.name;
|
||||
} else if (namespacedByDir) {
|
||||
// Directory is the namespace; don't double-prefix the filename
|
||||
|
||||
@@ -83,6 +83,21 @@ function _hostBehaviors(runtime: string): Record<string, unknown> {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Public accessor for the `hostBehaviors.agentFileExtension` descriptor field
|
||||
* (ADR-1239 / #2099 / #2103). Returns the runtime's declared agent-file
|
||||
* destination-suffix rename target (e.g. copilot's `.agent.md`), or
|
||||
* `undefined` when the runtime declares none (the generic no-rename
|
||||
* default). Exported so callers outside this module (surface.cts's
|
||||
* `_syncGsdDir`) can derive the SAME rename decision as
|
||||
* install-engine.cts's staged-copy loop from ONE descriptor read, instead of
|
||||
* duplicating a hardcoded `runtime === 'copilot'` check (#2103 fold).
|
||||
*/
|
||||
function agentFileExtensionFor(runtime: string): string | undefined {
|
||||
const ext = _hostBehaviors(runtime).agentFileExtension;
|
||||
return typeof ext === 'string' ? ext : undefined;
|
||||
}
|
||||
|
||||
|
||||
const colorNameToHex = {
|
||||
cyan: '#00FFFF',
|
||||
@@ -2756,10 +2771,12 @@ function normalizeAgentBodyForRuntime(content: string, runtime: string, cmdNames
|
||||
* ~/\.claude\b → normalizedPathPrefix
|
||||
* $HOME/\.claude\b → normalizedPathPrefix
|
||||
*
|
||||
* Skipped for copilot (hardcoded — #2099 will fold it) and for any runtime
|
||||
* that declares `hostBehaviors.noPathRewrite` (descriptor-driven, ADR-1239 /
|
||||
* #2096 — folds the prior hardcoded `runtime === 'antigravity'` literal;
|
||||
* Antigravity does NOT do path rewrites in the inline loop). NO stamp
|
||||
* Skipped for any runtime that declares `hostBehaviors.noPathRewrite`
|
||||
* (descriptor-driven, ADR-1239 / #2096 — folds the prior hardcoded
|
||||
* `runtime === 'antigravity'` literal; Antigravity does NOT do path rewrites
|
||||
* in the inline loop / #2103 — folds the prior hardcoded
|
||||
* `runtime === 'copilot'` literal onto the same descriptor field, since
|
||||
* copilot also skips these rewrites). NO stamp
|
||||
* (_stampNonClaudeRuntimeDefaults) — agents are NOT stamped in the inline loop.
|
||||
*
|
||||
* ADR-1235 §1: pre-converter cross-cutting for descriptor-driven agent pipeline.
|
||||
@@ -2769,10 +2786,10 @@ function normalizeAgentBodyForRuntime(content: string, runtime: string, cmdNames
|
||||
* @param content raw agent file content
|
||||
* @param runtime canonical runtime ID
|
||||
* @param pathPrefix trailing-slash path prefix (e.g. '$HOME/.cursor/')
|
||||
* @returns content with path-prefix rewrites applied (or unchanged for copilot / noPathRewrite runtimes)
|
||||
* @returns content with path-prefix rewrites applied (or unchanged for noPathRewrite runtimes, e.g. copilot)
|
||||
*/
|
||||
function applyAgentPathRewrites(content: string, runtime: string, pathPrefix: string): string {
|
||||
if (runtime === 'copilot' || _hostBehaviors(runtime).noPathRewrite === true) return content;
|
||||
if (_hostBehaviors(runtime).noPathRewrite === true) return content;
|
||||
const normalizedPathPrefix = pathPrefix.replace(/\/$/, '');
|
||||
content = content.replace(/~\/\.claude\//g, pathPrefix);
|
||||
content = content.replace(/\$HOME\/\.claude\//g, pathPrefix);
|
||||
@@ -2813,6 +2830,11 @@ function processAttribution(
|
||||
|
||||
export = {
|
||||
processAttribution,
|
||||
// #2103: public accessor for hostBehaviors.agentFileExtension, exported so
|
||||
// surface.cts's _syncGsdDir can derive the .agent.md rename from the SAME
|
||||
// descriptor read as install-engine.cts (folds a duplicated hardcoded
|
||||
// `runtime === 'copilot'` literal).
|
||||
agentFileExtensionFor,
|
||||
yamlIdentifier,
|
||||
yamlQuote,
|
||||
toSingleLine,
|
||||
|
||||
@@ -84,6 +84,39 @@ const GSD_COPILOT_SESSION_HOOK_PWSH =
|
||||
`{ '{"additionalContext":"${GSD_COPILOT_SESSION_MSG_PRESENT}"}' } ` +
|
||||
`else { '{"additionalContext":"${GSD_COPILOT_SESSION_MSG_ABSENT}"}' }`;
|
||||
|
||||
// #2099 UPGRADE 1: multi-event hook bus. Each additional event is a static,
|
||||
// deterministic advisory (no branching/no-op-style, matching sessionStart's
|
||||
// tone) so the emitted hooks/gsd-session.json stays golden-trackable — no
|
||||
// node-runner invocation, no filesystem probing beyond what sessionStart
|
||||
// already does.
|
||||
const GSD_COPILOT_PRE_TOOL_MSG =
|
||||
'GSD: confirm this tool use is in scope for the active phase before proceeding.';
|
||||
const GSD_COPILOT_PRE_TOOL_HOOK_BASH =
|
||||
`printf '%s' '{"additionalContext":"${GSD_COPILOT_PRE_TOOL_MSG}"}'`;
|
||||
const GSD_COPILOT_PRE_TOOL_HOOK_PWSH =
|
||||
`'{"additionalContext":"${GSD_COPILOT_PRE_TOOL_MSG}"}'`;
|
||||
|
||||
const GSD_COPILOT_POST_TOOL_MSG =
|
||||
'GSD: review the tool result against the active phase before continuing.';
|
||||
const GSD_COPILOT_POST_TOOL_HOOK_BASH =
|
||||
`printf '%s' '{"additionalContext":"${GSD_COPILOT_POST_TOOL_MSG}"}'`;
|
||||
const GSD_COPILOT_POST_TOOL_HOOK_PWSH =
|
||||
`'{"additionalContext":"${GSD_COPILOT_POST_TOOL_MSG}"}'`;
|
||||
|
||||
const GSD_COPILOT_PROMPT_SUBMIT_MSG =
|
||||
'GSD: check this request against .planning/STATE.md scope before acting.';
|
||||
const GSD_COPILOT_PROMPT_SUBMIT_HOOK_BASH =
|
||||
`printf '%s' '{"additionalContext":"${GSD_COPILOT_PROMPT_SUBMIT_MSG}"}'`;
|
||||
const GSD_COPILOT_PROMPT_SUBMIT_HOOK_PWSH =
|
||||
`'{"additionalContext":"${GSD_COPILOT_PROMPT_SUBMIT_MSG}"}'`;
|
||||
|
||||
const GSD_COPILOT_SESSION_END_MSG =
|
||||
'GSD: update .planning/STATE.md with the session outcome before ending.';
|
||||
const GSD_COPILOT_SESSION_END_HOOK_BASH =
|
||||
`printf '%s' '{"additionalContext":"${GSD_COPILOT_SESSION_END_MSG}"}'`;
|
||||
const GSD_COPILOT_SESSION_END_HOOK_PWSH =
|
||||
`'{"additionalContext":"${GSD_COPILOT_SESSION_END_MSG}"}'`;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Cursor hook constants
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1147,6 +1180,41 @@ function buildCopilotHookConfig(): Record<string, unknown> {
|
||||
timeoutSec: 10,
|
||||
},
|
||||
],
|
||||
// #2099 UPGRADE 1: multi-event hook bus — preToolUse (worktree/read-safety
|
||||
// advisory), postToolUse (context-monitor advisory), userPromptSubmitted
|
||||
// (prompt-guard advisory), sessionEnd (session-finalize advisory).
|
||||
preToolUse: [
|
||||
{
|
||||
type: 'command',
|
||||
bash: GSD_COPILOT_PRE_TOOL_HOOK_BASH,
|
||||
powershell: GSD_COPILOT_PRE_TOOL_HOOK_PWSH,
|
||||
timeoutSec: 10,
|
||||
},
|
||||
],
|
||||
postToolUse: [
|
||||
{
|
||||
type: 'command',
|
||||
bash: GSD_COPILOT_POST_TOOL_HOOK_BASH,
|
||||
powershell: GSD_COPILOT_POST_TOOL_HOOK_PWSH,
|
||||
timeoutSec: 10,
|
||||
},
|
||||
],
|
||||
userPromptSubmitted: [
|
||||
{
|
||||
type: 'command',
|
||||
bash: GSD_COPILOT_PROMPT_SUBMIT_HOOK_BASH,
|
||||
powershell: GSD_COPILOT_PROMPT_SUBMIT_HOOK_PWSH,
|
||||
timeoutSec: 10,
|
||||
},
|
||||
],
|
||||
sessionEnd: [
|
||||
{
|
||||
type: 'command',
|
||||
bash: GSD_COPILOT_SESSION_END_HOOK_BASH,
|
||||
powershell: GSD_COPILOT_SESSION_END_HOOK_PWSH,
|
||||
timeoutSec: 10,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -521,10 +521,14 @@ function _syncGsdDir(stagedDir: string, destDir: string, kind: ArtifactKind | st
|
||||
const kindName = (typeof kind === 'string') ? kind : kind.kind;
|
||||
const kindPrefix = (typeof kind === 'object' && kind !== null) ? kind.prefix : 'gsd-';
|
||||
|
||||
// #1575: copilot agents are renamed .md -> .agent.md at copy time, mirroring
|
||||
// the inline agent loop in bin/install.js (line ~9118). Other runtimes keep
|
||||
// the staged filename verbatim.
|
||||
const isCopilotAgents = runtime === 'copilot' && kindName === 'agents';
|
||||
// #1575 / #2103: agent files are renamed .md -> <agentFileExtension> at copy
|
||||
// time when the runtime's descriptor declares hostBehaviors.agentFileExtension
|
||||
// (e.g. copilot's '.agent.md'), mirroring install-engine.cts's staged-copy
|
||||
// loop (`_copyStaged`) — ONE descriptor read shared by both surfaces instead
|
||||
// of a duplicated hardcoded `runtime === 'copilot'` literal. Other runtimes
|
||||
// (no agentFileExtension declared) keep the staged filename verbatim.
|
||||
const _agentExt = runtime ? runtimeArtifactConversion.agentFileExtensionFor(runtime) : undefined;
|
||||
const isRenamedAgents = !!_agentExt && kindName === 'agents';
|
||||
|
||||
if (kindName === 'skills') {
|
||||
// Skills kind: work with directories, not files.
|
||||
@@ -564,8 +568,8 @@ function _syncGsdDir(stagedDir: string, destDir: string, kind: ArtifactKind | st
|
||||
const stagedFiles = fs.readdirSync(stagedDir).filter(f => f.endsWith('.md'));
|
||||
const stagedDestNames = new Set<string>();
|
||||
for (const file of stagedFiles) {
|
||||
const destName = isCopilotAgents
|
||||
? file.replace(/\.md$/, '.agent.md')
|
||||
const destName = isRenamedAgents
|
||||
? file.replace(/\.md$/, _agentExt)
|
||||
: (kindName === 'agents' || namespacedByDir)
|
||||
? file
|
||||
: `${kindPrefix}${file.slice(0, -3)}.md`;
|
||||
|
||||
Reference in New Issue
Block a user