fix(#2329): write opencode slash commands to commands/ (plural), migrate legacy command/ (#2354)

* test(#2329): fail-first tests for opencode commands/ (plural) command dir

Red phase, empirically probed: global/local install lands in command/ (singular)
with 71 gsd-*.md files and no commands/; the manifest records 71 keys under
command/ and zero under commands/; all four declaring sites report 'command'.
Migration coverage is black-box (two sequential install runs against one
configDir) so it holds regardless of how the fix implements cleanup.

The Kilo guard passes today by design — a forward-looking no-collateral check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* fix(#2329): write opencode commands to commands/ (plural), migrate legacy command/

OpenCode discovers slash commands from commands/ (plural); the installer wrote
them to command/ (singular), so none of the ~71 /gsd-* commands appeared in the
TUI. Five sites declared the directory and all had to agree:

- capabilities/opencode/capability.json: both artifactLayout destSubpath entries
  (global + local) and hostBehaviors.flatCommandDir
- bin/install.js: the manifest prefix was a SEPARATE hardcoded 'command/' literal,
  so the manifest would have diverged from the descriptor even after a rename. It
  now derives from _hostBehaviors(runtime).flatCommandDir.
- src/install-engine.cts installOpencodeFamilyArtifacts: the actual write target,
  which bypasses resolveRuntimeArtifactLayout via combinedFamilyInstall. This was
  a fifth site the issue did not list — without it the descriptor change alone
  would not have moved a single file.

Migration: an upgrade over a pre-fix install removes only manifest-proven
GSD-managed files from the legacy command/ dir and rmdirs it once empty.
Unmanifested user files are preserved, never deleted.

Kilo shares the opencode family install path and is explicitly unaffected —
pinned by a no-collateral test.

Note on the tests: the migration cases originally built their legacy fixture by
running the installer and relying on it to produce command/ — i.e. they depended
on the bug to set up the fixture, and became unsatisfiable the moment it was
fixed (block 1 requires command/ to be absent after a fresh install). They now
fabricate the legacy layout explicitly, including rewriting the manifest keys to
the command/ prefix — which is load-bearing, since the migration only removes
manifest-proven files and an unrewritten fixture would silently no-op and pass
even against a broken migration.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* test(#2329): regenerate opencode install golden after rebase onto next

The golden conflicted on rebase because #2322 also regenerated it. Resolved by
regenerating from the merged source rather than hand-merging a generated file;
the only delta is the 71 command/gsd-*.md -> commands/gsd-*.md key renames.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* test(#2329): update stale tests that pinned opencode's singular command/ dir

Seven tests encoded the old contract (opencode: command/gsd-help.md exists, the
descriptor's flatCommandDir, the install-integration contract, and the
resolveRuntimeArtifactLayout golden). They passed in the red phase precisely
because they pinned the buggy singular dir; the fix intentionally changes that
contract, so these are stale-test corrections, not regressions.

Kilo shares the opencode family install path and is deliberately NOT changing —
it stays on command/ (singular). The shared opencode/kilo test is now split via
an explicit per-runtime dir map so the two cannot be conflated, and Kilo's own
layout test is untouched. tests/opencode-command-dir-plural.test.cjs
independently pins Kilo unchanged end-to-end.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* docs(#2329): changeset for opencode commands/ dir fix

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* docs(#2329): backfill PR number 2354 into changeset

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* docs(#2329): correct the changeset — do not assert opencode ignores command/

The changeset repeated the issue's stated mechanism ("OpenCode discovers them
from commands/ ... a clean install produced no usable commands in the TUI at
all"). OpenCode's source contradicts that: packages/core/src/v1/config/command.ts
globs {command,commands}/**/*.md, so BOTH names resolve, and its own skill doc
still calls .opencode/command/ typical. Shipping that claim as a release note
would document a mechanism that does not exist.

The change is still right, for the stronger reason: OpenCode's config docs list
plural as the convention and singular as backwards compatibility, so GSD was
shipping on the alias the vendor may withdraw. Reworded to describe it as the
alignment it is, decided on OpenCode's source and docs rather than on bug reports
in either repo.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* fix(#2329): baseline opencode's commands/ surface — closes a data-loss path this PR opened

Not a bookkeeping gap. Moving opencode's command dir to commands/ moved the
install destination to a surface the first-time baseline scan does not cover:
000-first-time-baseline's RUNTIME_SURFACES.opencode lists ['gsd-core','command',
'skills','agents'] — no 'commands'.

installOpencodeFamilyCommands unconditionally unlinks every gsd-*.md under its
destination before writing the fresh set (install-engine.cts:870-873), with zero
manifest or migration involvement. The only thing that protects a pre-existing
file is assertInstallerMigrationsUnblocked, which runs before materialization and
halts when the baseline scan flags an unknown file at a KNOWN surface.

Probed: a pre-existing commands/gsd-plan.md is silently destroyed (install exits
0). The identical file under the legacy, already-baselined command/ surface
correctly halts the install with "installer migration blocked pending user
choice". So this PR would have traded a protected surface for an unprotected one.

Fixed with a NEW fix-forward migration rather than editing 000, per
docs/installer-migrations.md:131-134 — an applied migration never re-runs, so
editing 000 would only protect fresh installs and leave every existing machine
exposed. A new id runs for both populations and drifts no shipped checksum;
adding its entry to EXPECTED_CHECKSUMS is the case that test explicitly sanctions.
All five pre-existing shipped checksums verified byte-identical.

Kilo is excluded by the migration's runtimes filter and keeps command/.

This was previously deferred as a PR-body note claiming "low impact — nothing
else acts on baseline-scan misses". That claim was never probed and was wrong.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

* docs(#2329): drop the parenthetical product description from the changeset

The product-name purity guard (#1777) rejects "Kilo (which still uses
command/)" — fragment prose renders verbatim into CHANGELOG.md, so a product
name must not carry a parenthetical. Reworded to a plain sentence; the meaning
is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SLufH5sDuqA1AiEGu45cuA

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-07-17 08:14:59 -04:00
committed by GitHub
parent 15b3cc8690
commit ed06b6a4b9
22 changed files with 1139 additions and 175 deletions

View File

@@ -17,6 +17,7 @@ const {
writeInstallState,
} = require('../gsd-core/bin/lib/installer-migrations.cjs');
const firstTimeBaselineMigration = require('../gsd-core/bin/lib/installer-migrations/000-first-time-baseline.cjs');
const opencodeBaselineCommandsDirMigration = require('../gsd-core/bin/lib/installer-migrations/005-opencode-baseline-commands-dir.cjs');
function createTempInstall() {
return fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-installer-migrations-'));
@@ -315,6 +316,194 @@ test('records known generated agent artifacts so profile cleanup can remove them
}
});
// ---------------------------------------------------------------------------
// Migration 005: OpenCode commands/ (plural) baseline scan (#2329 follow-up)
//
// 000-first-time-baseline.cts's RUNTIME_SURFACES.opencode is a shipped,
// immutable body that still only names the legacy singular `command/`
// directory (see docs/installer-migrations.md#state-files). These tests
// pin migration 005's widened scan of the plural `commands/` surface.
// ---------------------------------------------------------------------------
test('baselines pre-existing OpenCode commands/ files: managed, unknown, and stale-GSD-looking', () => {
const configDir = createTempInstall();
try {
writeFile(configDir, 'commands/gsd-plan-phase.md', 'managed command\n');
writeFile(configDir, 'commands/my-custom-command.md', 'user command\n');
writeFile(configDir, 'commands/gsd-retired-command.md', 'stale gsd-looking file, not in manifest\n');
writeManifest(configDir, {
'commands/gsd-plan-phase.md': sha256('managed command\n'),
});
const result = runInstallerMigrations({
configDir,
runtime: 'opencode',
scope: 'global',
migrations: [opencodeBaselineCommandsDirMigration],
baselineScan: true,
now: () => '2026-07-17T00:00:00.000Z',
});
assert.deepEqual(
result.plan.actions.map((action) => ({
type: action.type,
relPath: action.relPath,
classification: action.classification,
})),
[
{
type: 'record-baseline',
relPath: 'commands/gsd-plan-phase.md',
classification: 'managed-pristine',
},
{
type: 'baseline-preserve-user',
relPath: 'commands/my-custom-command.md',
classification: 'unknown',
},
{
type: 'prompt-user',
relPath: 'commands/gsd-retired-command.md',
classification: 'stale-gsd-looking',
},
]
);
// The stale-GSD-looking file blocks the plan (needs explicit user choice),
// so nothing was applied and no install state was written yet.
assert.deepEqual(result.appliedMigrationIds, []);
assert.equal(fs.existsSync(path.join(configDir, INSTALL_STATE_NAME)), false);
// Every file on disk is untouched — baseline-preserve-user/record-baseline/
// prompt-user are all non-mutating classification actions.
assert.equal(fs.readFileSync(path.join(configDir, 'commands/gsd-plan-phase.md'), 'utf8'), 'managed command\n');
assert.equal(fs.readFileSync(path.join(configDir, 'commands/my-custom-command.md'), 'utf8'), 'user command\n');
assert.equal(fs.readFileSync(path.join(configDir, 'commands/gsd-retired-command.md'), 'utf8'), 'stale gsd-looking file, not in manifest\n');
} finally {
cleanup(configDir);
}
});
test('OpenCode commands/ baseline is idempotent — a second run does not re-plan already-applied files', () => {
const configDir = createTempInstall();
try {
writeFile(configDir, 'commands/gsd-plan-phase.md', 'managed command\n');
writeFile(configDir, 'commands/my-custom-command.md', 'user command\n');
writeManifest(configDir, {
'commands/gsd-plan-phase.md': sha256('managed command\n'),
});
const first = runInstallerMigrations({
configDir,
runtime: 'opencode',
scope: 'global',
migrations: [opencodeBaselineCommandsDirMigration],
baselineScan: true,
now: () => '2026-07-17T00:00:01.000Z',
});
assert.deepEqual(first.appliedMigrationIds, ['2026-07-17-opencode-baseline-commands-dir']);
assert.deepEqual(readInstallState(configDir).appliedMigrations.map((entry) => entry.id), [
'2026-07-17-opencode-baseline-commands-dir',
]);
// Second run: the migration id is now applied, so it must never re-run,
// regardless of what baselineScan is passed.
const second = runInstallerMigrations({
configDir,
runtime: 'opencode',
scope: 'global',
migrations: [opencodeBaselineCommandsDirMigration],
baselineScan: true,
now: () => '2026-07-17T00:00:02.000Z',
});
assert.deepEqual(second.appliedMigrationIds, []);
assert.deepEqual(second.plan.actions, []);
assert.deepEqual(readInstallState(configDir).appliedMigrations.map((entry) => entry.id), [
'2026-07-17-opencode-baseline-commands-dir',
]);
// Files remain untouched across both runs.
assert.equal(fs.readFileSync(path.join(configDir, 'commands/gsd-plan-phase.md'), 'utf8'), 'managed command\n');
assert.equal(fs.readFileSync(path.join(configDir, 'commands/my-custom-command.md'), 'utf8'), 'user command\n');
} finally {
cleanup(configDir);
}
});
test('OpenCode commands/ baseline migration is scoped to opencode and never plans for Kilo', () => {
const configDir = createTempInstall();
try {
// Kilo's descriptor keeps the singular `command/` dir; a `commands/` (plural)
// directory here would be unrelated to Kilo's install surface. This proves the
// migration's `runtimes: ['opencode']` scoping keeps Kilo installs untouched.
writeFile(configDir, 'commands/gsd-plan-phase.md', 'managed command\n');
writeFile(configDir, 'command/gsd-plan-phase.md', 'kilo managed command\n');
writeManifest(configDir, {
'commands/gsd-plan-phase.md': sha256('managed command\n'),
'command/gsd-plan-phase.md': sha256('kilo managed command\n'),
});
const result = runInstallerMigrations({
configDir,
runtime: 'kilo',
scope: 'global',
migrations: [opencodeBaselineCommandsDirMigration],
baselineScan: true,
now: () => '2026-07-17T00:00:03.000Z',
});
// migrationMatchesContext filters this migration out entirely for kilo
// (runtimes: ['opencode']) before plan() is ever invoked: it is not
// "pending", produces zero actions, is never applied, and no install-state
// file is written for this run at all.
assert.deepEqual(result.plan.actions, []);
assert.deepEqual(result.appliedMigrationIds, []);
assert.equal(fs.existsSync(path.join(configDir, INSTALL_STATE_NAME)), false);
assert.equal(fs.readFileSync(path.join(configDir, 'commands/gsd-plan-phase.md'), 'utf8'), 'managed command\n');
assert.equal(fs.readFileSync(path.join(configDir, 'command/gsd-plan-phase.md'), 'utf8'), 'kilo managed command\n');
} finally {
cleanup(configDir);
}
});
test('regression (#2329 follow-up): pre-existing unmanifested commands/gsd-*.md is no longer silently destroyed', () => {
const configDir = createTempInstall();
try {
// Simulates a pre-existing, non-GSD file sitting under OpenCode's commands/
// directory before GSD's first-ever migration-tracked run against this
// configDir (no manifest, no install state yet).
writeFile(configDir, 'commands/gsd-retired-plan.md', 'pre-existing file, not GSD-written\n');
// Full default migration set (all shipped migrations, including 000 AND 005),
// matching production: bin/install.js calls runInstallerMigrations with no
// explicit `migrations` override.
const result = runInstallerMigrations({
configDir,
runtime: 'opencode',
scope: 'global',
baselineScan: true,
now: () => '2026-07-17T00:00:04.000Z',
});
// Before this fix, RUNTIME_SURFACES.opencode omitted `commands/`, so this file
// was invisible to every migration and ordinary materialization would delete it
// unconditionally with a clean exit. Now it is caught and blocks the install
// pending an explicit user choice — the same protection the legacy `command/`
// surface already had.
assert.deepEqual(result.appliedMigrationIds, []);
assert.ok(Array.isArray(result.blocked) && result.blocked.length > 0, 'expected a blocked prompt-user action');
const blockedForFile = result.blocked.find((action) => action.relPath === 'commands/gsd-retired-plan.md');
assert.ok(blockedForFile, 'expected commands/gsd-retired-plan.md to be blocked pending user choice');
assert.equal(blockedForFile.type, 'prompt-user');
assert.equal(blockedForFile.migrationId, '2026-07-17-opencode-baseline-commands-dir');
// The file itself was never touched — migrations only classify, they do not
// mutate disk.
assert.equal(
fs.readFileSync(path.join(configDir, 'commands/gsd-retired-plan.md'), 'utf8'),
'pre-existing file, not GSD-written\n'
);
} finally {
cleanup(configDir);
}
});
test('plans a pending migration against an unchanged managed file', () => {
const configDir = createTempInstall();
try {
@@ -1468,6 +1657,14 @@ test('shipped installer-migration checksums are locked to a committed baseline (
// Migration 004: prune stale gsd-pristine/get-shit-done/ snapshots (#934) // gsd-allow-legacy-name
'2026-06-09-prune-stale-pristine-get-shit-done': // gsd-allow-legacy-name
'sha256:6555dd044659276fbc204e81793cd92c5315d54e7316bcdd82d2c98d15a7e9e8',
// Migration 005 (NEW, added here per this test's own sanctioned "adding a new
// migration" case — not a shipped-body edit): baseline OpenCode's commands/
// (plural) directory during the first-time scan. #2329 moved OpenCode command
// materialization from legacy command/ to commands/, but 000's RUNTIME_SURFACES
// is a shipped, immutable body that still only names command/, so this
// fix-forward migration widens the scanned surface without touching 000.
'2026-07-17-opencode-baseline-commands-dir':
'sha256:0f6080b5f9b75fb5adbe9664a71152e23a5336813453b0a77e4df6fd483ad38e',
};
const { DEFAULT_MIGRATIONS_DIR, migrationChecksum: computeChecksum } = require('../gsd-core/bin/lib/installer-migrations.cjs');