Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
23884eb
chore(deps): pin pnpm 10.34.9
johncwaters Nov 25, 2026
703bfee
fix(tui): show what failed and offer to send the report
johncwaters Nov 25, 2026
06b938a
fix(tui): one failure card with plain copy, log opt-in from the menu
johncwaters Nov 25, 2026
a9d0469
fix(tui): drop the failure card border, say the error came without th…
johncwaters Nov 25, 2026
1fa5fd7
feat(tui): split the failure screen into a log question and retry steps
johncwaters Nov 25, 2026
fb5afdd
feat(tui): step-labelled failure screen that also covers failed logins
johncwaters Nov 25, 2026
8453cfa
Merge remote-tracking branch 'origin/main' into johnw/pnpm-10-34-9
johncwaters Nov 25, 2026
4c96ce5
Merge branch 'johnw/pnpm-10-34-9' into johnw/task-failure-outro
johncwaters Nov 25, 2026
f9f07b9
fix(auth): end a failed login as failed, on the failure screen
johncwaters Nov 25, 2026
88ae1c6
fix(test): drop the removed signup option from a react router test
johncwaters Nov 25, 2026
c7c235e
fix(tui): report only this run's log lines, kept in memory
johncwaters Nov 25, 2026
31142ad
Merge branch 'main' into johnw/pnpm-10-34-9
johncwaters Nov 27, 2026
528b62f
Merge branch 'johnw/pnpm-10-34-9' into johnw/task-failure-outro
johncwaters Nov 27, 2026
621a38b
fix(tui): show the failure screen only for program runs that need it
johncwaters Nov 27, 2026
31d0173
fix(tui): mask more secrets in the failure log and report logins once
johncwaters Nov 27, 2026
0f0119c
fix(tui): end a login that throws as a failed login, keep long log lines
johncwaters Nov 27, 2026
3cb6818
fix(tui): leave an oversized log line out of the failure report
johncwaters Nov 27, 2026
2324db1
Merge remote-tracking branch 'origin/main' into johnw/task-failure-outro
johncwaters Nov 27, 2026
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: 2 additions & 0 deletions docs/error-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ screen, debug log) keep the full detail.
| `PHW_AUTH_SETTINGS_CONFLICT` | auth | Claude settings file overrides the gateway credential | no |
| `PHW_AUTH_STORED_LOGIN_CONFLICT` | auth | SDK authenticated from a stored Claude login instead of the gateway token | no |
| `PHW_AUTH_PROJECT_FETCH_FAILED` | auth | user/project data fetch from the PostHog API failed | yes |
| `PHW_AUTH_LOGIN_FAILED` | auth | OAuth login failed for a reason other than a timeout or a denial | yes |
| `PHW_AUTH_ACCESS_DENIED` | auth | access denied on the OAuth consent screen | no |
| `PHW_ENV_LOCAL_SERVICES_DOWN` | env | a local dev target (`--local-*`) is not running | yes |
| `PHW_ENV_SERVICE_OUTAGE` | env | blocking external services down (interactive abort; non-interactive continues) | yes |
| `PHW_DETECT_BAD_DIRECTORY` | detect | install dir missing, not a directory, or unreadable | no |
Expand Down
12 changes: 12 additions & 0 deletions src/shared/errors/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ export const ERROR_CATALOG: Record<ErrorCode, ErrorCatalogEntry> = {
retry: 'yes',
description: 'Fetching user or project data from the PostHog API failed.',
},
[ErrorCodes.AuthLoginFailed]: {
group: 'auth',
retry: 'yes',
description:
'The OAuth login failed for a reason other than a timeout or a denial.',
},
[ErrorCodes.AuthAccessDenied]: {
group: 'auth',
retry: 'no',
description:
'The user denied the wizard access on the OAuth consent screen.',
},
[ErrorCodes.EnvLocalServicesDown]: {
group: 'env',
retry: 'yes',
Expand Down
2 changes: 2 additions & 0 deletions src/shared/errors/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const ErrorCodes = {
AuthSettingsConflict: 'PHW_AUTH_SETTINGS_CONFLICT',
AuthStoredLoginConflict: 'PHW_AUTH_STORED_LOGIN_CONFLICT',
AuthProjectFetchFailed: 'PHW_AUTH_PROJECT_FETCH_FAILED',
AuthLoginFailed: 'PHW_AUTH_LOGIN_FAILED',
AuthAccessDenied: 'PHW_AUTH_ACCESS_DENIED',
EnvLocalServicesDown: 'PHW_ENV_LOCAL_SERVICES_DOWN',
EnvServiceOutage: 'PHW_ENV_SERVICE_OUTAGE',
DetectBadDirectory: 'PHW_DETECT_BAD_DIRECTORY',
Expand Down
76 changes: 75 additions & 1 deletion src/shared/mcp-clients/__tests__/results.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,32 @@ describe('isOk', () => {
});
});

// Built from parts so the secret scanner does not read a test fixture as a key.
const BEGIN_KEY = ['-----BEGIN', 'PRIVATE KEY-----'].join(' ');
const END_KEY = ['-----END', 'PRIVATE KEY-----'].join(' ');

describe('redactSecrets', () => {
it('masks secrets logged as JSON tool inputs, raw and escaped', () => {
const logged =
'{"values": {"DB_PASSWORD": "hunter2hunter2"}} {\\"api_key\\": \\"abcd1234efgh\\"} pha_oauthtoken123';
const out = redactSecrets(logged);
expect(out).not.toContain('hunter2hunter2');
expect(out).not.toContain('abcd1234efgh');
expect(out).not.toContain('pha_oauthtoken123');
});

it('masks a whole JSON secret value, escapes and newlines included', () => {
const raw = JSON.stringify({
password: 'abc\\remaining-secret',
api_key: 'pa"leaked-after-quote',
private_key: '-----BEGIN KEY-----\nkeymaterial\n-----END KEY-----',
});
const out = redactSecrets(`${raw} ${JSON.stringify(raw)}`);
expect(out).not.toContain('remaining-secret');
expect(out).not.toContain('keymaterial');
expect(out).not.toContain('leaked-after-quote');
});

it('masks the bearer token the CLIs echo back in their error output', () => {
expect(
redactSecrets(
Expand Down Expand Up @@ -128,7 +153,44 @@ describe('redactSecrets', () => {
// value would file this as an exception instead of hinting.
expect(
redactSecrets('Missing OPENAI_API_KEY=sk-proj-0123456789abcdefghij'),
).toContain('OPENAI_API_KEY');
).toBe('Missing OPENAI_API_KEY=[redacted]');
});

it('masks a minted gateway token', () => {
expect(redactSecrets('gateway refused phe_abc123DEF456')).toBe(
'gateway refused [redacted]',
);
});

it('masks an env line inside a JSON-serialized tool output', () => {
const logged = JSON.stringify({ output: 'API_KEY="s3cr3t-value"' });
expect(redactSecrets(logged)).not.toContain('s3cr3t-value');
});

it('masks a password with punctuation', () => {
expect(redactSecrets("password: 'p@ss!word1234'")).not.toContain(
'p@ss!word1234',
);
});

it('masks the secret after a quoted value a log line cut short', () => {
const tail = 'TOKEN="abcdefgh\nnext line\nDB_PASSWORD="hunter2hunter2"';
expect(redactSecrets(tail)).not.toContain('hunter2hunter2');
});

it.each([
['its end', `tail:\n${BEGIN_KEY}\nMIIEvQIBADANBg`],
['its start', `MIIEvQIBADANBg\n${END_KEY}\nnext`],
])('masks a PEM block cut at %s', (_cut, text) => {
expect(redactSecrets(text)).not.toContain('MIIEvQIBADANBg');
});

it('masks a raw PEM private key block', () => {
const pem = `${BEGIN_KEY.replace(
'BEGIN',
'BEGIN RSA',
)}\nMIIEowIBAAKCAQEA\n${END_KEY.replace('END', 'END RSA')}`;
expect(redactSecrets(`key file:\n${pem}`)).toBe('key file:\n[redacted]');
});

it('leaves an ordinary URL and ordinary words alone', () => {
Expand Down Expand Up @@ -175,6 +237,18 @@ describe('namesWithStatus', () => {
});

describe('scrubHomePaths', () => {
it('scrubs a Windows user path nested twice in JSON', () => {
expect(
scrubHomePaths(JSON.stringify(JSON.stringify('C:\\Users\\alice\\proj'))),
).not.toContain('alice');
});

it('scrubs a Windows home path that JSON escaping doubled', () => {
expect(
scrubHomePaths('"cwd": "C:\\\\Users\\\\alice\\\\proj"'),
).not.toContain('alice');
});

it('replaces a unix home directory with ~ so one cause groups as one issue', () => {
expect(scrubHomePaths('spawn /Users/ada/.bun/bin/codex ENOENT')).toBe(
'spawn ~/.bun/bin/codex ENOENT',
Expand Down
28 changes: 25 additions & 3 deletions src/shared/mcp-clients/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface InstallResult {
reason?: string;
}

const SECRET_NAME =
'[A-Za-z0-9_-]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIALS?)[A-Za-z0-9_-]*';

/**
* Failure text comes from CLIs we invoke with the user's personal API key on the
* command line (`--header "Authorization: Bearer phx_..."`), so it can carry the
Expand All @@ -53,7 +56,7 @@ export interface InstallResult {
export const redactSecrets = (raw: string): string =>
raw
.replace(/Bearer\s+\S+/gi, 'Bearer [redacted]')
.replace(/ph[xspc]_[A-Za-z0-9_-]+/g, '[redacted]')
.replace(/ph[xspcare]_[A-Za-z0-9_-]+/g, '[redacted]')
// `https://user:token@github.com/...` — git prints the whole remote back;
// `postgres://user:password@host/db` is the same shape for a database.
.replace(/(\b[a-z][a-z0-9+.-]*:\/\/)[^/\s:@]+:[^/\s@]+@/gi, '$1[redacted]@')
Expand All @@ -66,13 +69,32 @@ export const redactSecrets = (raw: string): string =>
.replace(/\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}/g, '[redacted]')
// Google keys, which a config error quotes the same way.
.replace(/\bAIza[A-Za-z0-9_-]{16,}/g, '[redacted]')
.replace(
/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/g,
'[redacted]',
)
// A log tail or a sliced log line can cut a key block at either end.
.replace(/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*$/, '[redacted]')
.replace(/^[\s\S]*?-----END [A-Z0-9 ]*PRIVATE KEY-----/, '[redacted]')
// The catch-all for providers we have no shape for: a config error prints
// the offending line, and the variable's own name says it holds a secret.
// The name is kept — `OPENAI_API_KEY` is wording an expected-failure hint
// matches on, and masking it would turn that hint back into an exception.
.replace(
/\b([A-Za-z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIALS?)[A-Za-z0-9_]*)(\s*[=:]\s*)["']?[A-Za-z0-9_\-./+]{8,}["']?/gi,
/\b([A-Za-z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIALS?)[A-Za-z0-9_]*)(\s*[=:]\s*)(?:\\"(?:\\\\.|\\[^"\\]|[^\\\n])+\\"|"(?:[^"\\\n]|\\.)+"|'(?:[^'\\\n]|\\.)+'|["']?[^\s"'\\,;}[\])]{8,})/gi,
'$1$2[redacted]',
)
Comment thread
johncwaters marked this conversation as resolved.
Resolved
// The same names as JSON keys, raw or escaped, as tool inputs reach the log.
.replace(
new RegExp(
String.raw`(\\"${SECRET_NAME}\\"\s*:\s*\\")(?:\\\\(?:\\.|[^\\])|\\[^"\\]|[^\\])+`,
'gi',
),
'$1[redacted]',
)
.replace(
new RegExp(String.raw`("${SECRET_NAME}"\s*:\s*")(?:[^"\\]|\\.)+`, 'gi'),
'$1[redacted]',
);

/**
Expand All @@ -83,7 +105,7 @@ export const redactSecrets = (raw: string): string =>
export const scrubHomePaths = (raw: string): string =>
raw
.replace(/\/(?:Users|home)\/[^/\s'"]+/g, '~')
.replace(/[A-Za-z]:\\Users\\[^\\\s'"]+/gi, '~');
.replace(/[A-Za-z]:\\+Users\\+[^\\\s'"]+/gi, '~');

/**
* A failure that lives entirely in the user's environment: a CLI too old, a
Expand Down
20 changes: 20 additions & 0 deletions src/shared/utils/__tests__/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as path from 'path';
import {
configureLogFile,
getLogFilePath,
getProcessLogTail,
initLogFile,
logToFile,
} from '@utils/debug';
Expand All @@ -21,6 +22,25 @@ describe('log file writing', () => {
fs.rmSync(tmpRoot, { recursive: true, force: true });
});

it('keeps only whole lines from the last 64K of this process', () => {
configureLogFile({ path: path.join(tmpRoot, 'w.log'), enabled: true });
logToFile('first line that must age out');
for (let i = 0; i < 700; i++) logToFile(`line ${i} ${'x'.repeat(100)}`);
const tail = getProcessLogTail();
expect(tail.length).toBeLessThanOrEqual(64 * 1024);
expect(tail).not.toContain('first line that must age out');
expect(tail.startsWith('[')).toBe(true);
expect(tail).toContain('line 699');
});

it('leaves out a single line longer than the tail, so no unlabelled secret survives', () => {
configureLogFile({ path: path.join(tmpRoot, 'w.log'), enabled: true });
logToFile(`PASSWORD=${'y'.repeat(70 * 1024)}`);
const tail = getProcessLogTail();
expect(tail).toContain('log line over 64K left out');
expect(tail).not.toContain('yyyy');
});

it('creates a missing log directory instead of dropping the log', () => {
const logPath = path.join(tmpRoot, 'does', 'not', 'exist', 'wizard.log');
configureLogFile({ path: logPath, enabled: true });
Expand Down
22 changes: 22 additions & 0 deletions src/shared/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,31 @@ function reportLogFailureOnce(err: unknown): void {
});
}

// Every run appends to one shared file, so a failure report reads this process's own lines from memory.
const PROCESS_LOG_TAIL_CHARS = 64 * 1024;
const OVERSIZED_LINE_NOTE = '[log line over 64K left out]\n';
let processLogTail = '';

export function getProcessLogTail(): string {
return processLogTail;
}

function keepInProcessTail(text: string): void {
processLogTail += text;
if (processLogTail.length <= PROCESS_LOG_TAIL_CHARS) return;
const kept = processLogTail.slice(-PROCESS_LOG_TAIL_CHARS);
const firstBreak = kept.indexOf('\n');
// A cut line can keep a secret's value without the name that gets it masked, so a line too long to keep whole is left out.
processLogTail =
firstBreak >= 0 && firstBreak < kept.length - 1
? kept.slice(firstBreak + 1)
: OVERSIZED_LINE_NOTE;
}
Comment thread
johncwaters marked this conversation as resolved.
Resolved

// The log's directory isn't guaranteed to exist (Windows %TEMP%,
// POSTHOG_WIZARD_LOG_DIR) — create it on first failure.
function appendLine(text: string): void {
keepInProcessTail(text);
try {
appendFileSync(logFilePath, text);
} catch (err) {
Expand Down
Loading
Loading