refactor: remove dead descriptor-driven mechanisms (no remaining consumer)
Drop code whose only consumer was a retired runtime: hostBehaviors readers for agentFileExtension, localTargetIsProjectRoot, sharedHooksDirName, skillsManifestPrefix and skipCodexSkillsManifest; the empty NON_REGISTRY_CONFIG_HOME_DESCRIPTORS array and live-config-guard plumbing; the empty RUNTIME_NOTE_AUDIENCE_BY_HEADING filter; the unused resolveVersionFrom export; and the WINDSURF_SESSION_ID workstream session key. Delete tests that only exercised those mechanisms.
This commit is contained in:
@@ -33,7 +33,6 @@ const WORKSTREAM_SESSION_ENV_KEYS: ReadonlyArray<string> = [
|
||||
'OPENCODE_SESSION_ID',
|
||||
'GEMINI_SESSION_ID',
|
||||
'CURSOR_SESSION_ID',
|
||||
'WINDSURF_SESSION_ID',
|
||||
'TERM_SESSION_ID',
|
||||
'WT_SESSION',
|
||||
'TMUX_PANE',
|
||||
|
||||
@@ -159,17 +159,10 @@ function getAgentsDir(runtime?: string, projectRoot?: string): string {
|
||||
return installRelative;
|
||||
}
|
||||
if (projectRoot) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
const { runtimes } = require('./capability-registry.cjs') as {
|
||||
runtimes: Record<string, { runtime?: { hostBehaviors?: { localTargetIsProjectRoot?: boolean } } }>;
|
||||
};
|
||||
const runtimeConfig = runtimes[resolved]?.runtime;
|
||||
const localConfigDirName = getDirName(resolved);
|
||||
const localConfigDir = localConfigDirName === NO_LOCAL_CONFIG_DIR_SENTINEL
|
||||
? undefined
|
||||
: runtimeConfig?.hostBehaviors?.localTargetIsProjectRoot
|
||||
? projectRoot
|
||||
: path.join(projectRoot, localConfigDirName);
|
||||
: path.join(projectRoot, localConfigDirName);
|
||||
if (!localConfigDir) {
|
||||
return path.join(getGlobalConfigDir(resolved), 'agents');
|
||||
}
|
||||
|
||||
@@ -789,13 +789,7 @@ function _copyStaged(stagedDir: string, destDir: string, kind: any, configDir: s
|
||||
let destName: string;
|
||||
if (kind.kind === 'agents') {
|
||||
// Agent files already carry the msd- prefix in the source dir.
|
||||
// #2099: descriptor-driven via hostBehaviors.agentFileExtension. No
|
||||
// current runtime declares one, 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;
|
||||
destName = entry.name;
|
||||
} else {
|
||||
// Commands: filename composition (namespacedByDir ? `${stem}.md` :
|
||||
// `${prefix}${stem}.md`) is single-sourced with resolveTriggerSurface's
|
||||
@@ -1919,7 +1913,7 @@ function installOpencodeFamilyArtifacts(
|
||||
homeDir: posixNormalize(os.homedir()),
|
||||
// #4377: the runtime's own localConfigDir, so an opted-in local install
|
||||
// emits `<dir>/...` instead of this checkout's absolute path.
|
||||
localDirName: runtimeArtifactConversion._localIncludeDirName(runtime),
|
||||
localDirName: getDirName(runtime),
|
||||
});
|
||||
|
||||
// #2329: destDir is derived from the SAME hostBehaviors.flatCommandDir
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
import path from 'node:path';
|
||||
import os from 'node:os';
|
||||
import fs from 'node:fs';
|
||||
// #2874 (ADR-58 cleanup phase): route this module's content-rewrite-pass fs
|
||||
// calls through the installRuntimeArtifacts call tree's injectable seam —
|
||||
// see install-fs-adapter.cts's module doc. Resolves to real `node:fs` unless
|
||||
@@ -49,40 +48,6 @@ import { isGlobalScope } from './install-scope.cjs';
|
||||
import installEffortResolver = require('./install-effort-resolver.cjs');
|
||||
const { readMsdEffectiveEffortConfig, resolveInstallTimeEffort, _getMsdEffortCatalog } = installEffortResolver;
|
||||
|
||||
// #1383: resolve MSD's version WITHOUT a top-level
|
||||
// `require('../../../package.json')`. That require ran at module load on every
|
||||
// msd-tools invocation (this module sits in the msd-tools loader chain) and
|
||||
// threw `Cannot find module '../../../package.json'` on runtimes whose root has
|
||||
// no package.json — originally just Codex, where the installer never wrote the
|
||||
// synthetic root package.json; since #2544 that is true of EVERY runtime, as
|
||||
// MSD's markers moved into `hooks/` and the native plugin dir and the config
|
||||
// root is no longer written at all — taking the entire CLI down before it did
|
||||
// anything. And even where it used to resolve (the synthetic
|
||||
// `{"type":"commonjs"}`), there is no `version` field, so the single consumer
|
||||
// below already emitted `version: undefined`. Resolve lazily and defensively
|
||||
// instead:
|
||||
// 1. Installed trees carry <root>/msd-core/VERSION (written by the installer);
|
||||
// this module lives at <root>/msd-core/bin/lib, so VERSION is two dirs up.
|
||||
// 2. The source / npm-package tree has no msd-core/VERSION but carries a real
|
||||
// package.json three dirs up — read it lazily, never at module-load time.
|
||||
// A failed/invalid lookup degrades to '' (the caller omits the field) rather
|
||||
// than crashing or emitting `version: undefined`. Both sources are validated
|
||||
// against the same semver shape the repo's other VERSION reader enforces
|
||||
// (src/update-context.cts) so a garbled VERSION file is never emitted verbatim.
|
||||
// Exported for the #1383 regression (no in-module consumer remains).
|
||||
const SEMVER_PREFIX = /^\d+\.\d+\.\d+/; // mirrors src/update-context.cts SEMVER_PREFIX
|
||||
function resolveVersionFrom(libDir: string): string {
|
||||
try {
|
||||
const v = fs.readFileSync(path.join(libDir, '..', '..', 'VERSION'), 'utf8').trim();
|
||||
if (SEMVER_PREFIX.test(v)) return v;
|
||||
} catch { /* not an installed tree (no msd-core/VERSION) */ }
|
||||
try {
|
||||
const pkg = require(path.join(libDir, '..', '..', '..', 'package.json'));
|
||||
if (pkg && typeof pkg.version === 'string' && SEMVER_PREFIX.test(pkg.version)) return pkg.version;
|
||||
} catch { /* runtime root has no package.json (e.g. Codex) */ }
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Host-specific install behaviors declared on the runtime descriptor
|
||||
* (capabilities/<runtime>/capability.json -> runtime.hostBehaviors). Mirrors
|
||||
@@ -104,19 +69,6 @@ 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, or `undefined` when the runtime declares
|
||||
* none (the generic no-rename default). Exported so callers outside this
|
||||
* module (surface.cts's `_syncMsdDir`) can derive the SAME rename decision as
|
||||
* install-engine.cts's staged-copy loop from ONE descriptor read (#2103 fold).
|
||||
*/
|
||||
function agentFileExtensionFor(runtime: string): string | undefined {
|
||||
const ext = _hostBehaviors(runtime).agentFileExtension;
|
||||
return typeof ext === 'string' ? ext : undefined;
|
||||
}
|
||||
|
||||
|
||||
const colorNameToHex = {
|
||||
cyan: '#00FFFF',
|
||||
@@ -874,24 +826,11 @@ function frontmatterScalar(key: string, value: string): string {
|
||||
: `${key} ${value}`;
|
||||
}
|
||||
|
||||
// Bold `**<Runtime>:**` section headings inside a `<runtime_note>` that are
|
||||
// scoped to one runtime. Empty today — every runtime that declared one has
|
||||
// been retired — but the filter below still honours the map so a future
|
||||
// runtime-scoped heading can be added without touching the parser.
|
||||
const RUNTIME_NOTE_AUDIENCE_BY_HEADING = new Map<string, string>([]);
|
||||
|
||||
function filterRuntimeNotesForTarget(content: string, targetRuntime: string): string {
|
||||
return content.replace(/<runtime_note(?:\s+runtime=["']([^"']+)["'])?>([\s\S]*?)<\/runtime_note>/g,
|
||||
(whole, declaredAudience: string | undefined, inner: string) => {
|
||||
if (declaredAudience && declaredAudience.toLowerCase() !== targetRuntime) return '';
|
||||
const remaining = inner.replace(
|
||||
/(?:^|\n)[ \t]*\*\*([^*\n]+):\*\*[^\n]*(?:\n(?![ \t]*\n)[^\n]*)*/g,
|
||||
(section, heading: string) => {
|
||||
const audience = RUNTIME_NOTE_AUDIENCE_BY_HEADING.get(heading.trim().toLowerCase());
|
||||
return audience && audience !== targetRuntime ? '' : section;
|
||||
},
|
||||
);
|
||||
const body = remaining.trim();
|
||||
const body = inner.trim();
|
||||
return body ? `<runtime_note>\n${body}\n</runtime_note>` : '';
|
||||
});
|
||||
}
|
||||
@@ -1456,14 +1395,6 @@ function projectRelativePrefixFromProjectRoot(projectRoot: unknown, resolvedTarg
|
||||
return projectRelativePrefix(relative);
|
||||
}
|
||||
|
||||
/**
|
||||
* A runtime installed directly at the project root cannot use its descriptor
|
||||
* directory in a project-relative include: that directory was never created.
|
||||
*/
|
||||
function localIncludeDirName(runtime: string): string | undefined {
|
||||
return _hostBehaviors(runtime).localTargetIsProjectRoot === true ? undefined : getDirName(runtime);
|
||||
}
|
||||
|
||||
/**
|
||||
* #4377: the project-relative prefix for a local install, or `''` when the
|
||||
* runtime cannot express one and the caller must fall back to absolute.
|
||||
@@ -1982,7 +1913,7 @@ function rewriteStagedSkillBodies(stagedDir, opts) {
|
||||
const isWindowsHost = platform === 'win32';
|
||||
// #4377: localDirName lets a local install emit a project-relative prefix
|
||||
// when opted in; ignored for a global install and when the opt-in is off.
|
||||
const pathPrefix = computePathPrefix({ isGlobal, isOpencode, isWindowsHost, resolvedTarget, homeDir, localDirName: localIncludeDirName(runtime) });
|
||||
const pathPrefix = computePathPrefix({ isGlobal, isOpencode, isWindowsHost, resolvedTarget, homeDir, localDirName: getDirName(runtime) });
|
||||
const attribution = resolveAttribution ? resolveAttribution(runtime) : undefined;
|
||||
|
||||
applyRuntimeContentRewritesInPlace(stagedDir, runtime, pathPrefix, isGlobal, attribution);
|
||||
@@ -2036,7 +1967,7 @@ function rewriteStagedCommandBodies(stagedDir, opts) {
|
||||
const isWindowsHost = platform === 'win32';
|
||||
// #4377: localDirName lets a local install emit a project-relative prefix
|
||||
// when opted in; ignored for a global install and when the opt-in is off.
|
||||
const pathPrefix = computePathPrefix({ isGlobal, isOpencode, isWindowsHost, resolvedTarget, homeDir, localDirName: localIncludeDirName(runtime) });
|
||||
const pathPrefix = computePathPrefix({ isGlobal, isOpencode, isWindowsHost, resolvedTarget, homeDir, localDirName: getDirName(runtime) });
|
||||
const attribution = resolveAttribution ? resolveAttribution(runtime) : undefined;
|
||||
|
||||
return applyRuntimeContentRewritesForCommandsInPlace(stagedDir, runtime, pathPrefix, isGlobal, attribution);
|
||||
@@ -2305,10 +2236,6 @@ function processAttribution(
|
||||
export = {
|
||||
processAttribution,
|
||||
appendAgentTools,
|
||||
// #2103: public accessor for hostBehaviors.agentFileExtension, exported so
|
||||
// surface.cts's _syncMsdDir can derive any agent-file rename from the SAME
|
||||
// descriptor read as install-engine.cts.
|
||||
agentFileExtensionFor,
|
||||
yamlIdentifier,
|
||||
yamlQuote,
|
||||
toSingleLine,
|
||||
@@ -2345,9 +2272,6 @@ export = {
|
||||
_splitToolScalars: splitToolScalars,
|
||||
readMsdCommandNames,
|
||||
transformContentToHyphen,
|
||||
// #1383: version resolver (exported for regression test of the Codex
|
||||
// missing-package.json crash + the VERSION-file source of truth).
|
||||
resolveVersionFrom,
|
||||
// #1182: agent converters + tool-name table dependency closure
|
||||
claudeToAntigravityTools,
|
||||
convertAntigravityToolName,
|
||||
@@ -2384,7 +2308,6 @@ export = {
|
||||
_relativeIncludesEnabled: relativeIncludesEnabled,
|
||||
_projectRelativePrefix: projectRelativePrefix,
|
||||
_projectRelativePrefixFromProjectRoot: projectRelativePrefixFromProjectRoot,
|
||||
_localIncludeDirName: localIncludeDirName,
|
||||
_restoreClaudeGlobalAtRefTilde: restoreClaudeGlobalAtRefTilde,
|
||||
_applyRuntimeRewrites,
|
||||
_stampNonClaudeRuntimeDefaults,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
const _require: NodeRequire = require;
|
||||
const path = _require('node:path') as typeof import('node:path');
|
||||
const { tryWithinRootLexical } = _require('./security.cjs') as typeof import('./security.cjs');
|
||||
const { getDirName } = _require('./runtime-name-policy.cjs') as typeof import('./runtime-name-policy.cjs');
|
||||
|
||||
// #2870: InstallScope is owned by install-scope.cts, not re-declared here.
|
||||
// `isGlobalScope` centralizes the `scope === 'global'` boolean projection
|
||||
@@ -93,7 +94,6 @@ interface RuntimeArtifactConversionExports {
|
||||
rewriteStagedSkillBodies: (stagedDir: string, opts: RewriteOpts) => string | void;
|
||||
rewriteStagedCommandBodies: (stagedDir: string, opts: RewriteOpts) => string | void;
|
||||
_computePathPrefix: (opts: ComputePathPrefixOpts) => string;
|
||||
_localIncludeDirName: (runtime: string) => string | undefined;
|
||||
}
|
||||
|
||||
interface PlanItem {
|
||||
@@ -222,7 +222,7 @@ function createRuntimeArtifactInstallPlan(args: CreateRuntimeArtifactInstallPlan
|
||||
const isWindowsHost = (platform ?? process.platform) === 'win32';
|
||||
// #4377: descriptor-derived local dir name, so an opted-in local install
|
||||
// emits a project-relative prefix instead of this checkout's absolute path.
|
||||
const pathPrefix = conversionExports._computePathPrefix({ isGlobal, isOpencode, isWindowsHost, resolvedTarget, homeDir, localDirName: conversionExports._localIncludeDirName(layout.runtime) });
|
||||
const pathPrefix = conversionExports._computePathPrefix({ isGlobal, isOpencode, isWindowsHost, resolvedTarget, homeDir, localDirName: getDirName(layout.runtime) });
|
||||
const attribution = resolveAttribution ? resolveAttribution(layout.runtime) : undefined;
|
||||
// #2875 Part 2 (row I1): layout.configDir IS the install root the inline
|
||||
// agent loop called `targetDir` — same value, same resolution.
|
||||
|
||||
@@ -410,16 +410,6 @@ export function detectAntigravityDirAmbiguity(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Config-home descriptors resolved OUTSIDE the capability registry.
|
||||
*
|
||||
* Anything added here is picked up by every derived consumer in the same commit —
|
||||
* which is the property that makes the derivation structurally incapable of being
|
||||
* narrower than the surface it guards. Adding a hardcoded resolver WITHOUT adding
|
||||
* its descriptor here is the defect this array exists to make hard.
|
||||
*/
|
||||
export const NON_REGISTRY_CONFIG_HOME_DESCRIPTORS: ConfigHomeDescriptor[] = [];
|
||||
|
||||
/**
|
||||
* MSD's OWN location vars — a second family, not runtime configHomes.
|
||||
*
|
||||
|
||||
@@ -63,6 +63,7 @@ import type { ClusterMap } from './clusters.cjs';
|
||||
import { isGlobalScope } from './install-scope.cjs';
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import runtimeArtifactLayout = require('./runtime-artifact-layout.cjs');
|
||||
import { getDirName } from './runtime-name-policy.cjs';
|
||||
const { findInstallSourceRoot } = runtimeArtifactLayout;
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
import runtimeArtifactConversion = require('./runtime-artifact-conversion.cjs');
|
||||
@@ -425,7 +426,7 @@ function applySurface(runtimeConfigDir: string, layout: Layout, manifest: Map<st
|
||||
// A later msd-tools surface apply runs in another process, so it must reuse
|
||||
// the persisted, root-relative prefix the installer actually emitted.
|
||||
const _relativeIncludePrefix = readRelativeIncludePrefix(runtimeConfigDir);
|
||||
const _pathPrefix = runtimeArtifactConversion._computePathPrefix({ isGlobal: _isGlobal, isOpencode: _isOpencode, isWindowsHost: _isWindowsHost, resolvedTarget: _resolvedTarget, homeDir: _homeDir, projectRelative: !_isGlobal && typeof _relativeIncludePrefix === 'string', projectRelativePath: _relativeIncludePrefix, localDirName: runtimeArtifactConversion._localIncludeDirName(layout.runtime) });
|
||||
const _pathPrefix = runtimeArtifactConversion._computePathPrefix({ isGlobal: _isGlobal, isOpencode: _isOpencode, isWindowsHost: _isWindowsHost, resolvedTarget: _resolvedTarget, homeDir: _homeDir, projectRelative: !_isGlobal && typeof _relativeIncludePrefix === 'string', projectRelativePath: _relativeIncludePrefix, localDirName: getDirName(layout.runtime) });
|
||||
const _attribution = opts?.resolveAttribution ? opts.resolveAttribution(layout.runtime) : undefined;
|
||||
// #2875 Part 2 (row I1): layout.configDir is this call's install root.
|
||||
const agentCtx: AgentCtx = { runtime: layout.runtime, pathPrefix: _pathPrefix, attribution: _attribution, targetDir: layout.configDir };
|
||||
@@ -495,7 +496,7 @@ function applySurface(runtimeConfigDir: string, layout: Layout, manifest: Map<st
|
||||
// and the persisted surface state untouched.
|
||||
retiredArtifactCleanup.pruneRetiredRuntimeArtifacts(layout.runtime, layout.configDir);
|
||||
for (const item of stagedKinds) {
|
||||
_syncMsdDir(item.staged, item.dest, item.kind, skillManifest, layout.runtime);
|
||||
_syncMsdDir(item.staged, item.dest, item.kind, skillManifest);
|
||||
}
|
||||
|
||||
if (hasCandidateState) {
|
||||
@@ -642,7 +643,7 @@ function pruneSkillDirs(skillsDir: string, retainedNames: Set<string>, prefix: s
|
||||
* user-owned dirs. MSD-owned = stem in manifest; removal targets = in manifest AND
|
||||
* not in staged set. User-owned (not in manifest) are always preserved.
|
||||
*/
|
||||
function _syncMsdDir(stagedDir: string, destDir: string, kind: ArtifactKind | string, manifest?: Map<string, string[]>, runtime?: string): void {
|
||||
function _syncMsdDir(stagedDir: string, destDir: string, kind: ArtifactKind | string, manifest?: Map<string, string[]>): void {
|
||||
if (!fs.existsSync(stagedDir)) return;
|
||||
fs.mkdirSync(destDir, { recursive: true });
|
||||
|
||||
@@ -650,15 +651,6 @@ function _syncMsdDir(stagedDir: string, destDir: string, kind: ArtifactKind | st
|
||||
const kindName = (typeof kind === 'string') ? kind : kind.kind;
|
||||
const kindPrefix = (typeof kind === 'object' && kind !== null) ? kind.prefix : 'msd-';
|
||||
|
||||
// #1575 / #2103: agent files are renamed .md -> <agentFileExtension> at copy
|
||||
// time when the runtime's descriptor declares hostBehaviors.agentFileExtension
|
||||
// mirroring install-engine.cts's staged-copy loop (`_copyStaged`) — ONE
|
||||
// descriptor read shared by both surfaces. Runtimes with no
|
||||
// agentFileExtension declared (all of them today) 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.
|
||||
// Each staged entry is a directory named ${prefix}${stem}.
|
||||
@@ -695,11 +687,9 @@ function _syncMsdDir(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 = isRenamedAgents
|
||||
? file.replace(/\.md$/, _agentExt)
|
||||
: (kindName === 'agents' || namespacedByDir)
|
||||
? file
|
||||
: `${kindPrefix}${file.slice(0, -3)}.md`;
|
||||
const destName = (kindName === 'agents' || namespacedByDir)
|
||||
? file
|
||||
: `${kindPrefix}${file.slice(0, -3)}.md`;
|
||||
fs.copyFileSync(path.join(stagedDir, file), path.join(destDir, destName));
|
||||
stagedDestNames.add(destName);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user