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
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"plugins": [
{
"name": "genie",
"version": "4.260522.14",
"version": "4.260522.16",
"source": "./plugins/genie",
"description": "Human-AI partnership for Claude Code. Share a terminal, orchestrate workers, evolve together. Brainstorm ideas, wish them into plans, make with parallel agents, ship as one team. A coding genie that grows with your project."
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automagik/genie",
"version": "4.260522.14",
"version": "4.260522.16",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Update binarySha256 pins before merge.

CI is failing with SHA drift, which means the pinned hashes in package.json no longer match downloaded release assets. This release/version bump should include refreshed binarySha256 entries (or the asset set must be reverted to match current pins), otherwise release integrity checks stay red.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 3, The release bump updated "version" without updating
the pinned binary hashes, causing SHA drift; update the "binarySha256" entries
in package.json to match the current release assets (or revert the asset set to
match existing pins) so CI integrity checks pass—locate the binarySha256 fields
in package.json, fetch the correct SHA256 for each referenced release asset, and
replace the stale values with the new hashes before merging.

"description": "Collaborative terminal toolkit for human + AI workflows. NOTE: npm distribution discontinued 2026-05-09 — install via `curl -fsSL https://raw.githubusercontent.com/automagik-dev/genie/main/install.sh | bash` (cosign + SLSA verified). See https://automagik.dev/genie/release-process",
"type": "module",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion plugins/genie/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genie",
"version": "4.260522.14",
"version": "4.260522.16",
"description": "Human-AI partnership for Claude Code. Share a terminal, orchestrate workers, evolve together. Brainstorm ideas, turn them into wishes, execute with /work, validate with /review, and ship as one team.",
"author": {
"name": "Namastex Labs"
Expand Down
2 changes: 1 addition & 1 deletion plugins/genie/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "genie-plugin",
"version": "4.260522.14",
"version": "4.260522.16",
"private": true,
"description": "Runtime dependencies for genie bundled CLIs",
"type": "module",
Expand Down
36 changes: 36 additions & 0 deletions src/genie-commands/__tests__/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
downloadAndVerifyTarball,
ensureCanonicalInstall,
extractPgservePortFromStatus,
extractPgserveSocketDirFromStatus,
fetchLatestManifest,
formatVerifyBanner,
isGenieProcessSnapshotLine,
Expand Down Expand Up @@ -893,6 +894,41 @@ describe('Diagnostics schema (G5)', () => {
expect(extractPgservePortFromStatus('not-json')).toBe(null);
});

test('diagnostics derives pgserve socket dir from live pgserve runtime status json', () => {
const liveStatus = JSON.stringify({
installed: true,
status: 'online',
port: 8432,
socketDir: '/run/user/1000/pgserve',
runtime: { socketDir: '/run/user/1000/pgserve', port: 8432, live: true },
});

expect(extractPgserveSocketDirFromStatus(liveStatus)).toBe('/run/user/1000/pgserve');
});

test('diagnostics derives pgserve port from live pgserve runtime status json', () => {
const liveStatus = JSON.stringify({
installed: true,
status: 'online',
port: null,
runtime: { port: 8432, live: true },
});

expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});
Comment on lines +909 to +918

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Add a conflict-case test for runtime.port precedence.

Current coverage only checks runtime fallback when top-level port is null. Add a case where both are present but different, and assert runtime wins.

Suggested test addition
+  test('diagnostics prefers runtime.port over stale top-level port when both are present', () => {
+    const liveStatus = JSON.stringify({
+      port: 15432,
+      runtime: { port: 8432, live: true },
+    });
+    expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
+  });

As per coding guidelines: "Test edge cases and boundaries of every command, flag, and plugin contract".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
test('diagnostics derives pgserve port from live pgserve runtime status json', () => {
const liveStatus = JSON.stringify({
installed: true,
status: 'online',
port: null,
runtime: { port: 8432, live: true },
});
expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});
test('diagnostics derives pgserve port from live pgserve runtime status json', () => {
const liveStatus = JSON.stringify({
installed: true,
status: 'online',
port: null,
runtime: { port: 8432, live: true },
});
expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});
test('diagnostics prefers runtime.port over stale top-level port when both are present', () => {
const liveStatus = JSON.stringify({
port: 15432,
runtime: { port: 8432, live: true },
});
expect(extractPgservePortFromStatus(liveStatus)).toBe('8432');
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/genie-commands/__tests__/update.test.ts` around lines 909 - 918, Add a
test asserting that when both top-level port and runtime.port are present but
different, runtime.port takes precedence: create a JSON string with installed:
true, status: 'online', port: '1234' (or number), and runtime: { port: 8432,
live: true } and call extractPgservePortFromStatus to expect '8432'. Place this
new case alongside the existing diagnostics tests (same suite that contains the
current live-status test) so the behavior of extractPgservePortFromStatus is
verified for the conflict-case.


test('serve status reports pgserve transport from resolver instead of stale active port', () => {
const source = readFileSync(join(__dirname, '..', '..', 'term-commands', 'serve.ts'), 'utf-8');
const fnStart = source.indexOf('async function printPgserveHealth');
expect(fnStart).toBeGreaterThan(-1);
const fnBody = source.slice(fnStart, source.indexOf('/**', fnStart + 1));

expect(fnBody).toContain('resolvePgserveTransport');
expect(fnBody).toContain("transport?.kind === 'unix'");
expect(fnBody).not.toContain('isSocketMode()');
expect(fnBody).not.toContain('getActivePort()');
});

test('NO_COLOR honored via colorEnabled() helper', () => {
const source = readFileSync(join(__dirname, '..', 'update.ts'), 'utf-8');
expect(source).toContain('process.env.NO_COLOR');
Expand Down
26 changes: 24 additions & 2 deletions src/genie-commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1245,10 +1245,28 @@ export function isGenieProcessSnapshotLine(line: string): boolean {
);
}

export function extractPgserveSocketDirFromStatus(output: string): string | null {
try {
const parsed = JSON.parse(output) as {
socketDir?: unknown;
runtime?: { socketDir?: unknown };
};
const rawSocketDir = parsed.runtime?.socketDir ?? parsed.socketDir;
if (typeof rawSocketDir === 'string' && rawSocketDir.trim()) return rawSocketDir.trim();
} catch {
// best-effort diagnostics only; callers fall back to null.
}
return null;
}

export function extractPgservePortFromStatus(output: string): string | null {
try {
const parsed = JSON.parse(output) as { port?: unknown; instance?: { port?: unknown } };
const rawPort = parsed.port ?? parsed.instance?.port;
const parsed = JSON.parse(output) as {
port?: unknown;
instance?: { port?: unknown };
runtime?: { port?: unknown };
};
const rawPort = parsed.port ?? parsed.instance?.port ?? parsed.runtime?.port;
if (typeof rawPort === 'number' && Number.isFinite(rawPort)) return String(rawPort);
if (typeof rawPort === 'string' && rawPort.trim()) return rawPort.trim();
Comment on lines +1269 to 1271

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Prefer runtime.port over legacy status fields for live diagnostics.

Line 1269 currently prioritizes port/instance.port before runtime.port, which can report stale metadata even when live runtime data exists. This conflicts with the live-runtime diagnostics intent.

Suggested fix
-    const rawPort = parsed.port ?? parsed.instance?.port ?? parsed.runtime?.port;
+    const rawPort = parsed.runtime?.port ?? parsed.port ?? parsed.instance?.port;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const rawPort = parsed.port ?? parsed.instance?.port ?? parsed.runtime?.port;
if (typeof rawPort === 'number' && Number.isFinite(rawPort)) return String(rawPort);
if (typeof rawPort === 'string' && rawPort.trim()) return rawPort.trim();
const rawPort = parsed.runtime?.port ?? parsed.port ?? parsed.instance?.port;
if (typeof rawPort === 'number' && Number.isFinite(rawPort)) return String(rawPort);
if (typeof rawPort === 'string' && rawPort.trim()) return rawPort.trim();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/genie-commands/update.ts` around lines 1269 - 1271, The port-selection
logic currently uses parsed.port / parsed.instance?.port before live data,
causing stale values to be chosen; update the fallback order so
parsed.runtime?.port is preferred over legacy fields by computing rawPort from
parsed.runtime?.port ?? parsed.port ?? parsed.instance?.port (keep the same type
checks that follow: allow finite number -> String(...) and non-empty trimmed
string), and ensure you reference the same variable name rawPort so subsequent
checks (Number.isFinite and trim) still apply.

} catch {
Expand Down Expand Up @@ -1287,7 +1305,9 @@ async function collectUpdateDiagnostics(
const signals = summarizeJsonlSignals(schedulerLog);
const pgservePortFromFile = safeRead(join(GENIE_HOME, 'pgserve.port'), 200);
const pgserveStatusJson = (await runCommandSilent('pgserve', ['status', '--json'], undefined, 2000)).output.trim();
const pgserveSocketDir = extractPgserveSocketDirFromStatus(pgserveStatusJson);
const pgservePort = pgservePortFromFile ?? extractPgservePortFromStatus(pgserveStatusJson);
const pgserveTransport = pgserveSocketDir ? 'unix-socket' : pgservePort ? 'tcp' : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The transport detection logic should account for the SOCKET_PORT_SENTINEL (value "0"), which indicates a Unix socket transport even if the socketDir wasn't explicitly extracted from the status JSON. Additionally, since pgservePort might contain trailing whitespace if read from the legacy port file, it's safer to trim it during the check.

Suggested change
const pgserveTransport = pgserveSocketDir ? 'unix-socket' : pgservePort ? 'tcp' : null;
const pgserveTransport = pgserveSocketDir || pgservePort?.trim() === '0' ? 'unix-socket' : pgservePort?.trim() ? 'tcp' : null;
References
  1. It is acceptable to use hardcoded numeric limits or sentinel values in non-critical fallback logic to prevent performance issues or handle specific states.


const diagnostics = {
schemaVersion: UPDATE_DIAGNOSTIC_SCHEMA_VERSION,
Expand Down Expand Up @@ -1327,6 +1347,8 @@ async function collectUpdateDiagnostics(
genieBinPrevious: GENIE_BIN_PREVIOUS,
logsDir,
servePid: safeRead(join(GENIE_HOME, 'serve.pid'), 200),
pgserveTransport,
pgserveSocketDir,
Comment on lines +1350 to +1351

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This change introduces new fields (pgserveTransport, pgserveSocketDir) to the diagnostics report. According to the internal guidelines, UPDATE_DIAGNOSTIC_SCHEMA_VERSION should be incremented for any additive change to the schema to allow consumers to correctly identify the available metadata.

References
  1. Increment schema versioning for additive changes to diagnostic reports. (link)

pgservePort,
schedulerLog,
tuiCrashLog,
Expand Down
26 changes: 26 additions & 0 deletions src/term-commands/brain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ async function showVersion(): Promise<void> {
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);
if (isModuleNotFound(msg)) {
if (canRunStandaloneBrain()) {
executeStandaloneBrain(['--version']);
return;
}
console.log(' Brain is not installed. Run: genie brain install');
return;
}
Expand Down Expand Up @@ -492,6 +496,24 @@ function isModuleNotFound(msg: string): boolean {
return msg.includes('Cannot find') || msg.includes('not found') || msg.includes('MODULE_NOT_FOUND');
}

function shellQuote(value: string): string {
return `'${value.replace(/'/g, "'\\''")}'`;
}

function canRunStandaloneBrain(): boolean {
try {
execSync('command -v brain', { stdio: 'ignore', shell: '/bin/bash' });
return true;
} catch {
return false;
}
}

function executeStandaloneBrain(args: string[]): void {
const quotedArgs = args.map(shellQuote).join(' ');
execSync(`brain ${quotedArgs}`, { stdio: 'inherit', env: process.env, shell: '/bin/bash' });
}

function printNotInstalledMessage(): void {
console.log('');
console.log(' Brain is an enterprise knowledge graph engine.');
Expand Down Expand Up @@ -524,6 +546,10 @@ async function executeBrainCommand(args: string[]): Promise<void> {
} catch (err: unknown) {
const msg = err instanceof Error ? err.message : String(err);
if (isModuleNotFound(msg)) {
if (canRunStandaloneBrain()) {
executeStandaloneBrain(args);
return;
}
printNotInstalledMessage();
process.exit(1);
} else {
Expand Down
48 changes: 46 additions & 2 deletions src/term-commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1475,9 +1475,15 @@ async function stopServe(): Promise<void> {
/** Check pgserve health and print status */
async function printPgserveHealth(): Promise<void> {
try {
const { isAvailable, getActivePort, isSocketMode, resolvePgserveSocketDir } = await import('../lib/db.js');
const { isAvailable, resolvePgserveTransport } = await import('../lib/db.js');
const dbOk = await isAvailable();
const where = isSocketMode() ? `socket ${resolvePgserveSocketDir()}` : `port ${getActivePort()}`;
const transport = dbOk ? await resolvePgserveTransport() : null;
const where =
transport?.kind === 'unix'
? `socket ${transport.socketDir}`
: transport
? `tcp ${transport.host}:${transport.port}`
: null;
console.log(` pgserve: ${dbOk ? `healthy (${where})` : 'unreachable'}`);
} catch {
console.log(' pgserve: unavailable');
Expand Down Expand Up @@ -1552,6 +1558,43 @@ async function probeBrainHealth(brainPort: number): Promise<void> {
}
}

interface ActiveBrainConfigFile {
brainSlug?: string;
database?: string;
pid?: number;
port?: number;
}

function readActiveBrainConfigFile(): ActiveBrainConfigFile | null {
try {
const configPath = join(homedir(), '.brain', 'config.json');
if (!existsSync(configPath)) return null;
const config = JSON.parse(readFileSync(configPath, 'utf-8')) as ActiveBrainConfigFile;
if (!config.pid || !isProcessAlive(config.pid) || !config.port) return null;
return config;
} catch {
return null;
}
}

async function printStandaloneBrainStatus(): Promise<boolean> {
const config = readActiveBrainConfigFile();
if (!config?.port) return false;
try {
const resp = await fetch(`http://127.0.0.1:${config.port}/healthz`);
const label = config.brainSlug ?? config.database ?? `port ${config.port}`;
console.log(
resp.ok
? ` brain: running (${label}, port ${config.port})`
: ` brain: unhealthy (${label}, status ${resp.status})`,
);
return true;
} catch {
console.log(` brain: stopped (port ${config.port} unreachable)`);
return true;
}
}

async function printBrainStatus(): Promise<void> {
try {
// @ts-expect-error — brain is enterprise-only, not in genie's deps
Expand All @@ -1569,6 +1612,7 @@ async function printBrainStatus(): Promise<void> {
console.log(' brain: stopped');
}
} catch {
if (await printStandaloneBrainStatus()) return;
console.log(' brain: not installed');
}
}
Expand Down