Files
msd-core/tests/enh-2790-skill-consolidation.test.cjs
Tom Boucher a375c4b354 feat(#956): add MemPalace memory capability (ADR-857 feature plug-in) (#1201)
* feat(#956): add MemPalace memory capability (ADR-857 feature plug-in)

Adds an opt-in, default-resilient ADR-857 feature capability that wires
MemPalace (local-first memory: MCP server + CLI) into the GSD loop:
deliberate recall before discuss/plan and verbatim + temporal-KG capture
at phase boundaries. Three memory modes (augment default; kg_backend and
replace forward-declared). Master gate mempalace.enabled (default off);
every hook onError:skip, zero gates; absent/disabled MemPalace => loop
unchanged. Transport is rendered-markdown only — MemPalace runs
out-of-process, no third-party code in gsd-core (ADR-857 §7).

Capability: capabilities/mempalace/ (manifest + 2 fragments), skills
commands/gsd/mempalace-{recall,capture}.md, agent
agents/gsd-mempalace-curator.md. Registration: ns-context router,
utility cluster, KNOWN_SKILLS, help full.md, model-catalog, copilot
install list, size baselines; regenerated capability-registry +
inventory manifest. ship:post wired into ship.md (wire-on-demand).

HELD on #1196: this capability also declares hooks at discuss:pre and
discuss:post, which are structurally un-wireable until the host-loop
conformance model covers the discuss phase (discuss-phase.md is not in
HOST_LOOP_FILES). The phase6-capstone-conformance gate therefore fails
on exactly those two orphaned points by design — see #1196. Once #1196
lands, rebase onto next and the gate goes green with no further change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* docs(#956): backfill changeset PR number (#1201)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-14 02:09:10 -04:00

414 lines
14 KiB
JavaScript

// allow-test-rule: source-text-is-the-product
// commands/gsd/*.md files ARE what the runtime loads — testing their
// existence/non-existence tests the deployed skill surface contract.
'use strict';
const { describe, test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const { assertWithinAllowlist } = require('../scripts/lib/allowlist-ratchet.cjs');
// ---------------------------------------------------------------------------
// Allowlisted set of user-invocable skills (commands/gsd/*.md, ns-* excluded).
// Consolidation target ~58; this set may only SHRINK.
// Adding a new skill requires adding it here with justification.
// Removing a consolidated skill requires pruning it here.
// ---------------------------------------------------------------------------
const KNOWN_SKILLS = new Set([
'add-tests.md',
'ai-integration-phase.md',
'audit-fix.md',
'audit-milestone.md',
'audit-uat.md',
'autonomous.md',
'capture.md',
'cleanup.md',
'code-review.md',
'complete-milestone.md',
'config.md',
'debug.md',
'discuss-phase.md',
'docs-update.md',
'eval-review.md',
'execute-phase.md',
'explore.md',
'extract-learnings.md',
'fast.md',
'forensics.md',
'graphify.md',
'health.md',
'help.md',
'import.md',
'inbox.md',
'ingest-docs.md',
'manager.md',
'map-codebase.md',
'mempalace-capture.md',
'mempalace-recall.md',
'milestone-summary.md',
'mvp-phase.md',
'new-milestone.md',
'new-project.md',
'pause-work.md',
'phase.md',
'plan-phase.md',
'plan-review-convergence.md',
'pr-branch.md',
'profile-user.md',
'progress.md',
'quick.md',
'resume-work.md',
'review-backlog.md',
'review.md',
'secure-phase.md',
'settings.md',
'ship.md',
'sketch.md',
'spec-phase.md',
'spike.md',
'stats.md',
'surface.md',
'thread.md',
'ui-phase.md',
'ui-review.md',
'ultraplan-phase.md',
'undo.md',
'update.md',
'validate-phase.md',
'verify-work.md',
'workspace.md',
'workstreams.md',
]);
const COMMANDS_DIR = path.join(__dirname, '..', 'commands', 'gsd');
/**
* Parse the YAML frontmatter from a skill .md file.
* Returns an object with the frontmatter fields as strings.
* Only handles simple scalar and array values needed by these tests.
*/
function parseFrontmatter(filePath) {
const raw = fs.readFileSync(filePath, 'utf8');
// CRLF-tolerant: Windows checkouts leave \r on every line. lines.indexOf('---', 1)
// would never match because elements would be '---\r' instead of '---'.
const lines = raw.split(/\r?\n/);
if (lines[0].trim() !== '---') return {};
const endIdx = lines.indexOf('---', 1);
if (endIdx === -1) return {};
const fmLines = lines.slice(1, endIdx);
const result = {};
let currentKey = null;
for (const line of fmLines) {
const kvMatch = line.match(/^([a-zA-Z0-9_-]+):\s*(.*)/);
if (kvMatch) {
currentKey = kvMatch[1];
result[currentKey] = kvMatch[2].trim();
} else if (currentKey && line.match(/^\s+-\s+/)) {
// array item — append to existing string value so callers can check membership
const item = line.replace(/^\s+-\s+/, '').trim();
result[currentKey] = result[currentKey] ? [result[currentKey], item].join('\n') : item;
}
}
return result;
}
function skillPath(name) {
return path.join(COMMANDS_DIR, `${name}.md`);
}
// ---------------------------------------------------------------------------
// Group: New consolidated skills exist
// ---------------------------------------------------------------------------
describe('new consolidated skills exist', () => {
test('commands/gsd/capture.md exists', () => {
assert.ok(fs.existsSync(skillPath('capture')), 'capture.md does not exist');
});
test('commands/gsd/phase.md exists', () => {
assert.ok(fs.existsSync(skillPath('phase')), 'phase.md does not exist');
});
test('commands/gsd/config.md exists', () => {
assert.ok(fs.existsSync(skillPath('config')), 'config.md does not exist');
});
test('commands/gsd/workspace.md exists', () => {
assert.ok(fs.existsSync(skillPath('workspace')), 'workspace.md does not exist');
});
});
// ---------------------------------------------------------------------------
// Group: Absorbed skills are removed
// ---------------------------------------------------------------------------
describe('absorbed skills are removed', () => {
const absorbed = [
['add-todo', 'absorbed into capture.md'],
['note', 'absorbed into capture.md'],
['add-backlog', 'absorbed into capture.md'],
['plant-seed', 'absorbed into capture.md'],
['check-todos', 'absorbed into capture.md'],
['add-phase', 'absorbed into phase.md'],
['insert-phase', 'absorbed into phase.md'],
['remove-phase', 'absorbed into phase.md'],
['edit-phase', 'absorbed into phase.md'],
['settings-advanced', 'absorbed into config.md'],
['settings-integrations', 'absorbed into config.md'],
['set-profile', 'absorbed into config.md'],
['new-workspace', 'absorbed into workspace.md'],
['list-workspaces', 'absorbed into workspace.md'],
['remove-workspace', 'absorbed into workspace.md'],
['sync-skills', 'absorbed into update.md'],
['reapply-patches', 'absorbed into update.md'],
['sketch-wrap-up', 'absorbed into sketch.md'],
['spike-wrap-up', 'absorbed into spike.md'],
['scan', 'absorbed into map-codebase.md'],
['intel', 'absorbed into map-codebase.md'],
['code-review-fix', 'absorbed into code-review.md'],
['next', 'absorbed into progress.md'],
['do', 'absorbed into progress.md'],
];
for (const [name, reason] of absorbed) {
test(`commands/gsd/${name}.md does NOT exist (${reason})`, () => {
assert.ok(
!fs.existsSync(skillPath(name)),
[
`${name}.md still exists but should have been deleted`,
`(${reason})`,
].join(' '),
);
});
}
});
// ---------------------------------------------------------------------------
// Group: Outright deletions
// ---------------------------------------------------------------------------
describe('outright deleted dead skills are removed', () => {
const deleted = [
'join-discord',
// research-phase → plan-phase --research-phase (PR #3045, already absorbed)
// plan-milestone-gaps → inline in audit-milestone (PR #3038, already absorbed)
// list-phase-assumptions → discuss-phase --assumptions (pending #3131)
// session-report → pause-work --report (pending #3131)
// analyze-dependencies → manager --analyze-deps (pending #3131)
// from-gsd2 → import --from-gsd2 (pending #3131)
];
for (const name of deleted) {
test(`commands/gsd/${name}.md does NOT exist`, () => {
assert.ok(
!fs.existsSync(skillPath(name)),
`${name}.md still exists but should have been deleted (outright dead skill)`,
);
});
}
});
// ---------------------------------------------------------------------------
// Group: #3131 — re-wired workflows absorbed as flags
// ---------------------------------------------------------------------------
describe('#3131 re-wired workflows: standalone command files must not exist', () => {
const rewired = [
['list-phase-assumptions', 'absorbed into discuss-phase.md --assumptions'],
['session-report', 'absorbed into pause-work.md --report'],
['analyze-dependencies', 'absorbed into manager.md --analyze-deps'],
['from-gsd2', 'absorbed into import.md --from-gsd2'],
];
for (const [name, reason] of rewired) {
test(`commands/gsd/${name}.md does NOT exist (${reason})`, () => {
assert.ok(
!fs.existsSync(skillPath(name)),
`${name}.md still exists as a standalone command but should be absorbed (${reason})`,
);
});
}
});
describe('#3131 re-wired workflows: parent command argument-hints advertise the new flags', () => {
test('discuss-phase.md argument-hint contains --assumptions', () => {
const fm = parseFrontmatter(skillPath('discuss-phase'));
assert.ok(
(fm['argument-hint'] || '').includes('--assumptions'),
'discuss-phase.md argument-hint does not contain --assumptions. got: ' + (fm['argument-hint'] || '(none)'),
);
});
test('pause-work.md argument-hint contains --report', () => {
const fm = parseFrontmatter(skillPath('pause-work'));
assert.ok(
(fm['argument-hint'] || '').includes('--report'),
'pause-work.md argument-hint does not contain --report. got: ' + (fm['argument-hint'] || '(none)'),
);
});
test('manager.md argument-hint contains --analyze-deps', () => {
const fm = parseFrontmatter(skillPath('manager'));
assert.ok(
(fm['argument-hint'] || '').includes('--analyze-deps'),
'manager.md argument-hint does not contain --analyze-deps. got: ' + (fm['argument-hint'] || '(none)'),
);
});
test('import.md argument-hint contains --from-gsd2', () => {
const fm = parseFrontmatter(skillPath('import'));
assert.ok(
(fm['argument-hint'] || '').includes('--from-gsd2'),
'import.md argument-hint does not contain --from-gsd2. got: ' + (fm['argument-hint'] || '(none)'),
);
});
});
describe('#3131 re-wired workflows: parent command bodies dispatch to workflow files', () => {
function bodyContains(name, substring) {
const raw = fs.readFileSync(skillPath(name), 'utf8');
return raw.includes(substring);
}
test('discuss-phase.md body references list-phase-assumptions.md', () => {
assert.ok(
bodyContains('discuss-phase', 'list-phase-assumptions.md'),
'discuss-phase.md body does not reference list-phase-assumptions.md — --assumptions flag dispatch is missing',
);
});
test('pause-work.md body references session-report.md', () => {
assert.ok(
bodyContains('pause-work', 'session-report.md'),
'pause-work.md body does not reference session-report.md — --report flag dispatch is missing',
);
});
test('manager.md body references analyze-dependencies.md', () => {
assert.ok(
bodyContains('manager', 'analyze-dependencies.md'),
'manager.md body does not reference analyze-dependencies.md — --analyze-deps flag dispatch is missing',
);
});
test('import.md body references from-gsd2', () => {
assert.ok(
bodyContains('import', 'from-gsd2'),
'import.md body does not reference from-gsd2 — --from-gsd2 flag dispatch is missing',
);
});
});
// ---------------------------------------------------------------------------
// Group: Parent skills updated with new flags
// ---------------------------------------------------------------------------
describe('parent skills updated with new flags in argument-hint', () => {
test('update.md argument-hint contains --sync', () => {
const fm = parseFrontmatter(skillPath('update'));
assert.ok(
(fm['argument-hint'] || '').includes('--sync'),
[
'update.md argument-hint does not contain --sync',
'got: ' + (fm['argument-hint'] || '(none)'),
].join('. '),
);
});
test('update.md argument-hint contains --reapply', () => {
const fm = parseFrontmatter(skillPath('update'));
assert.ok(
(fm['argument-hint'] || '').includes('--reapply'),
[
'update.md argument-hint does not contain --reapply',
'got: ' + (fm['argument-hint'] || '(none)'),
].join('. '),
);
});
test('sketch.md argument-hint contains --wrap-up', () => {
const fm = parseFrontmatter(skillPath('sketch'));
assert.ok(
(fm['argument-hint'] || '').includes('--wrap-up'),
[
'sketch.md argument-hint does not contain --wrap-up',
'got: ' + (fm['argument-hint'] || '(none)'),
].join('. '),
);
});
test('spike.md argument-hint contains --wrap-up', () => {
const fm = parseFrontmatter(skillPath('spike'));
assert.ok(
(fm['argument-hint'] || '').includes('--wrap-up'),
[
'spike.md argument-hint does not contain --wrap-up',
'got: ' + (fm['argument-hint'] || '(none)'),
].join('. '),
);
});
test('map-codebase.md argument-hint contains --fast', () => {
const fm = parseFrontmatter(skillPath('map-codebase'));
assert.ok(
(fm['argument-hint'] || '').includes('--fast'),
[
'map-codebase.md argument-hint does not contain --fast',
'got: ' + (fm['argument-hint'] || '(none)'),
].join('. '),
);
});
test('code-review.md argument-hint contains --fix', () => {
const fm = parseFrontmatter(skillPath('code-review'));
assert.ok(
(fm['argument-hint'] || '').includes('--fix'),
[
'code-review.md argument-hint does not contain --fix',
'got: ' + (fm['argument-hint'] || '(none)'),
].join('. '),
);
});
test('progress.md argument-hint contains --do', () => {
const fm = parseFrontmatter(skillPath('progress'));
assert.ok(
(fm['argument-hint'] || '').includes('--do'),
[
'progress.md argument-hint does not contain --do',
'got: ' + (fm['argument-hint'] || '(none)'),
].join('. '),
);
});
});
// ---------------------------------------------------------------------------
// Group: settings.md is NOT deleted
// ---------------------------------------------------------------------------
describe('settings.md is kept (merged into config entry point or remains standalone)', () => {
test('commands/gsd/settings.md still exists', () => {
assert.ok(
fs.existsSync(skillPath('settings')),
'settings.md was deleted — it should be kept (or renamed to config.md, but not both missing)',
);
});
});
// ---------------------------------------------------------------------------
// Group: Skill set allowlisted (identity-based, consolidating toward ~58)
// ---------------------------------------------------------------------------
describe('skill set', () => {
test('user-invocable skill set is allowlisted (consolidating toward ~58)', () => {
// Exclude `ns-*.md` namespace meta-skills (#2792) from this guard.
// Those are descriptor-only routers selected first by the model and
// are not part of the consolidation surface this test tracks; their
// own contract is enforced by tests/enh-2792-namespace-skills.test.cjs.
const currentBasenames = fs.readdirSync(COMMANDS_DIR)
.filter((f) => f.endsWith('.md') && !f.startsWith('ns-'));
assertWithinAllowlist({
label: 'user-invocable skills (commands/gsd)',
current: currentBasenames,
known: KNOWN_SKILLS,
fail: assert.fail,
pruneHint: 'edit KNOWN_SKILLS in tests/enh-2790-skill-consolidation.test.cjs',
});
});
});