Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions plugins/genie/.codex-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
"keywords": ["workflow", "orchestration", "codex", "skills", "agents"],
"skills": "./skills/",
"hooks": "./hooks/codex-hooks.json",
"mcpServers": "./.mcp.json",
"interface": {
"displayName": "Genie",
"shortDescription": "Plan, execute, review, and ship with Genie",
"longDescription": "First-class Genie workflows for Codex, including shared skills, lifecycle hooks, and MCP task state. Genie CLI setup can install optional role agents.",
"developerName": "Namastex Labs",
"category": "Developer Tools",
"capabilities": ["Skills", "Hooks", "MCP"],
"capabilities": ["Skills", "Hooks"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore Codex health checks after removing plugin MCP

Removing the Codex plugin MCP declaration makes the newly shipped plugin fail Genie's existing activation health path: probeCodexGeniePlugin() still delegates to inspectCodexPluginMcpUsability(), which requires manifest.mcpServers === './.mcp.json', and proveCodexPluginHealth() rejects any snapshot with usable !== true. In an install/update/doctor run against this manifest, the active plugin is therefore reported as unusable (or the setup/update proof aborts) even though the project fallback is now the intended route; update those probes/checks to validate the new project-route contract instead of the removed plugin route.

Useful? React with 👍 / 👎.

"websiteURL": "https://github.com/automagik-dev/genie",
"defaultPrompt": [
"Use $genie:wish to turn this request into an executable plan.",
Expand Down
7 changes: 0 additions & 7 deletions plugins/genie/.mcp.json

This file was deleted.

1 change: 0 additions & 1 deletion scripts/build-binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ for required in \
".agents/plugins/marketplace.json" \
".claude-plugin/marketplace.json" \
"plugins/genie/.codex-plugin/plugin.json" \
"plugins/genie/.mcp.json" \
"plugins/genie/scripts/mcp-launcher.cjs" \
"plugins/genie/.claude-plugin/plugin.json" \
"plugins/genie/hooks/hooks.json" \
Expand Down
26 changes: 15 additions & 11 deletions scripts/codex-plugin-only-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,22 @@ function isRecord(value: unknown): value is Record<string, unknown> {

function assertInstalledPluginMcpShape(iso: IsolatedHome, version: string): void {
const root = join(iso.codexHome, 'plugins', 'cache', 'automagik', 'genie', version);
const config: unknown = JSON.parse(readFileSync(join(root, '.mcp.json'), 'utf8'));
const configRecord = isRecord(config) ? config : {};
const wrapped = configRecord.mcp_servers;
const servers = isRecord(wrapped) ? wrapped : configRecord;
const genie = servers.genie;
const command = isRecord(genie) ? genie.command : undefined;
const args = isRecord(genie) ? genie.args : undefined;
const cwd = isRecord(genie) ? genie.cwd : undefined;
if (command !== 'node' || !Array.isArray(args) || args[0] !== './scripts/mcp-launcher.cjs' || cwd !== '.') {
fail(`installed plugin MCP entry shape is wrong: ${JSON.stringify(genie)}`);
// Group A removed the Codex plugin MCP route: the installed manifest declares no
// mcpServers and no MCP capability, and ships no `.mcp.json`. Codex MCP now comes
// ONLY from the marker-owned project route reconciled by `genie init` (asserted
// separately as the project `.mcp.json`/`.codex/config.toml`).
const manifest: unknown = JSON.parse(readFileSync(join(root, '.codex-plugin', 'plugin.json'), 'utf8'));
const manifestRecord = isRecord(manifest) ? manifest : {};
if ('mcpServers' in manifestRecord) {
fail('installed Codex plugin manifest must not declare mcpServers (plugin MCP route removed)');
}
if (!existsSync(join(root, 'scripts', 'mcp-launcher.cjs'))) fail('installed plugin MCP launcher is missing');
const iface = isRecord(manifestRecord.interface) ? manifestRecord.interface : {};
if (Array.isArray(iface.capabilities) && iface.capabilities.includes('MCP')) {
fail('installed Codex plugin must not advertise the MCP capability (plugin MCP route removed)');
}
if (existsSync(join(root, '.mcp.json'))) fail('installed Codex plugin must not ship a .mcp.json route file');
// The plugin-local launcher stays — Claude drives it via its own inline manifest entry.
if (!existsSync(join(root, 'scripts', 'mcp-launcher.cjs'))) fail('plugin MCP launcher (Claude) is missing');
}

function assertSessionStartHook(iso: IsolatedHome, version: string): void {
Expand Down
8 changes: 5 additions & 3 deletions scripts/fresh-install-smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('fresh-install-smoke', () => {
}
});

test('rejects unsupported camelCase plugin MCP config before source/cache packaging passes', () => {
test('rejects any plugin .mcp.json route file (the Codex plugin MCP route was removed)', () => {
const root = mkdtempSync(join(tmpdir(), 'genie-plugin-mcp-schema-fixture-'));
try {
const pluginRoot = join(root, 'plugin');
Expand All @@ -300,18 +300,20 @@ describe('fresh-install-smoke', () => {
dereference: false,
verbatimSymlinks: true,
});
// A resurrected plugin `.mcp.json` (in any shape) must fail the smoke: the
// Codex plugin no longer provides an MCP route, so shipping one is a defect.
writeFileSync(
join(pluginRoot, '.mcp.json'),
JSON.stringify({
mcpServers: {
mcp_servers: {
genie: { command: 'node', args: ['./scripts/mcp-launcher.cjs'], cwd: '.' },
},
}),
);

const result = runSmoke(['--skills-dir', join(REPO_ROOT, 'skills'), '--plugin-root', pluginRoot]);
expect(result.code).not.toBe(0);
expect(result.stderr).toContain('must not use unsupported camelCase mcpServers');
expect(result.stderr).toContain('must not ship a .mcp.json route file');
} finally {
rmSync(root, { recursive: true, force: true });
}
Expand Down
43 changes: 16 additions & 27 deletions scripts/fresh-install-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,39 +440,28 @@ function checkStarterPrompts(manifest: Record<string, unknown>, names: string[])
}

function checkPluginMcpLayout(pluginRoot: string, manifest: Record<string, unknown>): void {
if (manifest.mcpServers !== './.mcp.json') {
fail('Codex plugin manifest mcpServers must point to ./.mcp.json');
}
const configPath = join(pluginRoot, '.mcp.json');
if (!existsSync(configPath)) fail(`Codex plugin MCP config missing: ${configPath}`);
const config = JSON.parse(readFileSync(configPath, 'utf8')) as Record<string, unknown>;
if ('mcpServers' in config) fail('Codex plugin .mcp.json must not use unsupported camelCase mcpServers');
const wrapped = config.mcp_servers;
const serverMap =
typeof wrapped === 'object' && wrapped !== null && !Array.isArray(wrapped)
? (wrapped as Record<string, unknown>)
: config;
const rawEntry = serverMap.genie;
const entry =
typeof rawEntry === 'object' && rawEntry !== null && !Array.isArray(rawEntry)
? (rawEntry as { command?: unknown; args?: unknown; cwd?: unknown })
// Group A removed the Codex plugin MCP route: the manifest declares no mcpServers
// and no MCP capability, and the payload ships no `.mcp.json`. Codex MCP is
// provided ONLY by the marker-owned project route reconciled by `genie init`.
if ('mcpServers' in manifest) fail('Codex plugin manifest must not declare mcpServers (plugin MCP route removed)');
const iface = manifest.interface;
const capabilities =
typeof iface === 'object' && iface !== null && !Array.isArray(iface)
? (iface as { capabilities?: unknown }).capabilities
: undefined;
if (
entry?.command !== 'node' ||
!Array.isArray(entry.args) ||
entry.args.length !== 1 ||
entry.args[0] !== './scripts/mcp-launcher.cjs' ||
entry.cwd !== '.'
) {
fail('Codex plugin MCP entry must run node ./scripts/mcp-launcher.cjs with cwd "."');
if (Array.isArray(capabilities) && capabilities.includes('MCP')) {
fail('Codex plugin must not advertise the MCP capability (plugin MCP route removed)');
}
const launcher = resolve(pluginRoot, entry.args[0]);
if (existsSync(join(pluginRoot, '.mcp.json'))) fail('Codex plugin must not ship a .mcp.json route file');
// The plugin-local launcher persists — Claude drives it via its own inline
// ${CLAUDE_PLUGIN_ROOT}-anchored manifest entry (checked in checkClaudePluginMcpLayout).
const launcher = resolve(pluginRoot, 'scripts', 'mcp-launcher.cjs');
if (!isWithin(resolve(pluginRoot), launcher)) fail('Codex MCP launcher escapes the plugin root');
if (!existsSync(launcher) || !lstatSync(launcher).isFile() || lstatSync(launcher).isSymbolicLink()) {
fail(`Codex MCP launcher must be a physical plugin-local file: ${launcher}`);
fail(`plugin-local MCP launcher must be a physical file: ${launcher}`);
}
if (!isWithin(realpathSync(pluginRoot), realpathSync(launcher))) {
fail('Codex MCP launcher resolves outside the plugin root');
fail('plugin-local MCP launcher resolves outside the plugin root');
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/lib/codex-mcp-health-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ describe('runBoundedCodexMcpSession', () => {
expect(result.detail).toContain('read-only genie_wish_status did not return a non-error result');
});

test('accepts a fail-closed typed "no project context" wish_status (throwaway non-project cwd)', () => {
// The probe cwd is not a project, so the fail-closed server returns a typed
// error rather than an empty board — that IS the read-only health signal.
for (const kind of ['project-context-unavailable', 'project-database-unavailable', 'unsupported-project-layout']) {
const stdout = `${[
{ jsonrpc: '2.0', id: 1, result: { protocolVersion: '2024-11-05', serverInfo: { name: 'genie' } } },
{ jsonrpc: '2.0', id: 2, result: { tools: REQUIRED_GENIE_MCP_TOOLS.map((name) => ({ name })) } },
{
jsonrpc: '2.0',
id: 3,
result: { isError: true, structuredContent: { error: kind, detail: kind } },
},
]
.map((reply) => JSON.stringify(reply))
.join('\n')}\n`;
const result = runBoundedCodexMcpSession({ ...base, spawn: fakeSpawn({ stdout }) });
expect(result.ok).toBe(true);
expect(result.wishStatusReadOnly).toBe(true);
}
});

test('rejects a session whose tools/list reply never arrived', () => {
const stdout = `${JSON.stringify({ jsonrpc: '2.0', id: 1, result: { protocolVersion: '2024-11-05' } })}\n`;
const result = runBoundedCodexMcpSession({ ...base, spawn: fakeSpawn({ stdout }) });
Expand Down
44 changes: 38 additions & 6 deletions src/lib/codex-mcp-health-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,31 @@
* bounds the whole session.
*
* The server opens `.genie/genie.db` READ-ONLY and only writes to stdout, so the
* probe never mutates disk. Callers still hand it an isolated throwaway `cwd` so
* a missing db degrades to an empty board (never creating -wal/-shm siblings in
* real home/state trees). runtime-integrations proves the zero-mutation
* guarantee with a digest-around-session test.
* probe never mutates disk. Callers still hand it an isolated throwaway `cwd`
* that is not a project: the fail-closed server returns a typed "no project
* context" wish_status there rather than fabricating an empty board (never
* creating -wal/-shm siblings in real home/state trees), and this probe treats
* that typed refusal as read-only-healthy. runtime-integrations proves the
* zero-mutation guarantee with a digest-around-session test.
*/

export const MCP_HEALTH_PROTOCOL_VERSION = '2024-11-05';
export const DEFAULT_HEALTH_SESSION_TIMEOUT_MS = 10_000;

/**
* The fail-closed project-context error kinds the read-only `genie mcp` server
* returns (structuredContent `{ error, detail }`, `isError: true`) instead of a
* fabricated empty board when the cwd is not a resolvable project. Source of
* truth: `ProjectContextKind` in `src/lib/v5/genie-db.ts`. The health probe runs
* in a throwaway non-project cwd, so one of these is the EXPECTED wish_status
* outcome and proves the read-only path works — it is not a failure.
*/
const NO_PROJECT_CONTEXT_ERROR_KINDS = new Set<string>([
'project-context-unavailable',
'project-database-unavailable',
'unsupported-project-layout',
]);

/** The five read-only Genie tools every healthy plugin launcher must expose. */
export const REQUIRED_GENIE_MCP_TOOLS = [
'genie_board',
Expand Down Expand Up @@ -138,6 +154,22 @@ function replyError(reply: JsonRpcReply | undefined, label: string): string | nu
return null;
}

/**
* A read-only wish_status is healthy when it either returns a non-error board
* (`isError === false`) OR a well-formed fail-closed "no project context" typed
* error. The health probe deliberately runs in a throwaway non-project cwd where
* the latter is expected: the server correctly refuses to serve an empty board
* without mutating disk. Any other `isError: true` (an unrecognized/real tool
* failure) is still rejected.
*/
function wishStatusIsReadOnlyHealthy(result: { isError?: unknown; structuredContent?: unknown }): boolean {
if (result.isError === false) return true;
if (result.isError !== true) return false;
const structured = result.structuredContent;
const kind = structured && typeof structured === 'object' ? (structured as { error?: unknown }).error : undefined;
return typeof kind === 'string' && NO_PROJECT_CONTEXT_ERROR_KINDS.has(kind);
}

function listedToolNames(reply: JsonRpcReply): string[] {
const result = reply.result as { tools?: unknown };
if (!Array.isArray(result.tools)) return [];
Expand Down Expand Up @@ -199,8 +231,8 @@ export function runBoundedCodexMcpSession(options: BoundedCodexMcpSessionOptions
const callReply = byId.get(3);
const callError = replyError(callReply, 'genie_wish_status');
if (callError !== null) return { ok: false, detail: callError };
const callResult = (callReply as JsonRpcReply).result as { isError?: unknown };
if (callResult.isError !== false) {
const callResult = (callReply as JsonRpcReply).result as { isError?: unknown; structuredContent?: unknown };
if (!wishStatusIsReadOnlyHealthy(callResult)) {
return { ok: false, detail: 'read-only genie_wish_status did not return a non-error result' };
}

Expand Down
75 changes: 75 additions & 0 deletions src/lib/codex-project-mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import {
type CodexPluginProbe,
genieFacadeMcpEntry,
genieMcpEntry,
inspectCodexPluginMcpUsability,
inspectCodexProjectMcp,
Expand Down Expand Up @@ -76,7 +77,16 @@ function seedActivePlugin(version = '1.2.3'): {
const manifestPath = join(pluginRoot, '.codex-plugin', 'plugin.json');
const manifest = JSON.parse(readFileSync(manifestPath, 'utf8')) as Record<string, unknown>;
manifest.version = version;
// Group A removed the Codex plugin MCP route from the SHIPPED payload, so the
// fixture reconstructs a hypothetical plugin-with-MCP layout to keep exercising
// the fail-closed usability guard (launcher/node/binary). The removal itself is
// proven separately against the real source plugin.
manifest.mcpServers = './.mcp.json';
writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
writeFileSync(
join(pluginRoot, '.mcp.json'),
`${JSON.stringify({ mcp_servers: { genie: { command: 'node', args: ['./scripts/mcp-launcher.cjs'], cwd: '.' } } }, null, 2)}\n`,
);
const genieHome = join(root, 'genie-home');
const binary = join(genieHome, 'bin', process.platform === 'win32' ? 'genie.exe' : 'genie');
const nodePath = join(root, 'controlled-bin', 'node');
Expand Down Expand Up @@ -122,6 +132,71 @@ describe('project MCP executable entry', () => {
});
});

describe('genieFacadeMcpEntry (marker-owned Codex route)', () => {
test('is the stable <GENIE_HOME>/bin/genie facade with args ["mcp"] and no cwd override', () => {
expect(genieFacadeMcpEntry('/home/u/.genie', 'linux')).toEqual({
command: '/home/u/.genie/bin/genie',
args: ['mcp'],
});
// No effective cwd override is part of the entry (source omits it entirely).
expect(genieFacadeMcpEntry('/home/u/.genie', 'linux')).not.toHaveProperty('cwd');
});

test('uses genie.exe on win32 and is independent of the running executable', () => {
expect(genieFacadeMcpEntry('C:/Users/u/.genie', 'win32')).toEqual({
command: 'C:/Users/u/.genie/bin/genie.exe',
args: ['mcp'],
});
// A relocated GENIE_HOME yields a different facade — the command is not the cache/execPath.
expect(genieFacadeMcpEntry('/relocated/home', 'linux').command).toBe('/relocated/home/bin/genie');
});
});

describe('Codex plugin MCP route removal (Group A)', () => {
test('the shipped Codex plugin manifest declares NO mcpServers and NO MCP capability', () => {
const manifest = JSON.parse(
readFileSync(join(import.meta.dir, '..', '..', 'plugins', 'genie', '.codex-plugin', 'plugin.json'), 'utf8'),
) as { mcpServers?: unknown; interface?: { capabilities?: unknown } };
expect(manifest.mcpServers).toBeUndefined();
expect(manifest.interface?.capabilities).not.toContain('MCP');
});

test('the shipped Codex plugin payload ships no .mcp.json route file', () => {
expect(existsSync(join(import.meta.dir, '..', '..', 'plugins', 'genie', '.mcp.json'))).toBe(false);
});

test('a real (unaltered) plugin copy is never a usable MCP provider — the guard fails closed', () => {
const pluginRoot = join(root, 'real-plugin');
cpSync(join(import.meta.dir, '..', '..', 'plugins', 'genie'), pluginRoot, {
recursive: true,
dereference: false,
verbatimSymlinks: true,
});
const manifest = JSON.parse(readFileSync(join(pluginRoot, '.codex-plugin', 'plugin.json'), 'utf8')) as {
version: string;
};
const result = inspectCodexPluginMcpUsability({
pluginRoot,
expectedPluginName: 'genie',
expectedVersion: manifest.version,
genieHome: join(root, 'genie-home'),
resolveCommand: () => join(root, 'node'),
});
expect(result.usable).toBe(false);
// It fails at the manifest indirection because the route was removed.
expect(result.detail).toContain('mcpServers');
});

// Claude's separate inline launcher contract MUST remain intact.
test("Claude's plugin manifest still declares its own inline mcpServers launcher", () => {
const claude = JSON.parse(
readFileSync(join(import.meta.dir, '..', '..', 'plugins', 'genie', '.claude-plugin', 'plugin.json'), 'utf8'),
) as { mcpServers?: { genie?: { command?: string; args?: string[] } } };
expect(claude.mcpServers?.genie?.command).toBe('node');
expect(claude.mcpServers?.genie?.args?.[0]).toContain('mcp-launcher.cjs');
});
});

describe('resolveGitWorktreeRoot', () => {
test('resolves root, nested directory, and linked worktree to their own working-tree roots', () => {
const repo = join(root, 'repo');
Expand Down
Loading
Loading