Skip to content

Commit c20c96e

Browse files
igorcostaAutohand Evolve
andcommitted
Merge home path shortening into the welcome banner
Keep current startup formatting and display home-relative paths on Unix and Windows. Add a built-terminal regression that reproduces the absolute path before the change and confirms the shortened path afterward. Validation: lint and build passed; full proof passed 12,737 unit tests and 416 terminal tests. The three remaining resume-help and Zit package fixture failures also reproduce on untouched main. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
2 parents 50cc28c + b7715f5 commit c20c96e

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎src/testing/scenarios/startupReturningBrandingScenario.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ export function returningStartupLogoRows(output: string): string[] {
2121
return stripAnsi(output).split('\n').map((line) => line.trimEnd())
2222
.filter(isStartupLogoRow);
2323
}
24+
25+
export function startupWelcomeStatusLine(output: string): string | undefined {
26+
return stripAnsi(output).split(/\r?\n/u)
27+
.find((line) => line.startsWith('model:') && line.includes('| directory:'));
28+
}

‎src/ui/theme/startup.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import os from 'node:os';
78
import chalk from 'chalk';
89
import { themedFg } from './Theme.js';
910
import { t } from '../../i18n/index.js';
@@ -33,6 +34,17 @@ export function formatWelcomeGreeting(nameOrEmail: string): string {
3334
return themedFg('success', `Welcome back, ${nameOrEmail}!`, chalk.green);
3435
}
3536

37+
/** Shows the home folder as `~`, so the banner matches the status line and doesn't print a username. */
38+
export function formatWelcomeDirectory(dir: string, home: string = os.homedir()): string {
39+
if (!home) return dir;
40+
if (dir === home) return '~';
41+
for (const sep of ['/', '\\']) {
42+
const prefix = home.endsWith(sep) ? home : home + sep;
43+
if (dir.startsWith(prefix)) return `~${sep}${dir.slice(prefix.length)}`;
44+
}
45+
return dir;
46+
}
47+
3648
export function formatWelcomeStatusLine(model: string, ccEnabled: boolean, dir: string): string {
3749
const ccStatus = ccEnabled
3850
? themedFg('success', '[CC: ON]', chalk.green)
@@ -43,7 +55,7 @@ export function formatWelcomeStatusLine(model: string, ccEnabled: boolean, dir:
4355
themedFg('accent', model, chalk.cyan),
4456
ccStatus,
4557
themedFg('muted', '| directory:', chalk.gray),
46-
themedFg('accent', dir, chalk.cyan),
58+
themedFg('accent', formatWelcomeDirectory(dir), chalk.cyan),
4759
].join(' ');
4860
}
4961

‎tests/tuistory/built-cli-smoke.tuistory.test.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import path from 'node:path';
1313
import stripAnsi from 'strip-ansi';
1414
import packageJson from '../../package.json' with { type: 'json' };
1515
import { createStalledGitVersionPreload } from '../../src/testing/scenarios/gitVersionScenario.js';
16+
import { startupWelcomeStatusLine } from '../../src/testing/scenarios/startupReturningBrandingScenario.js';
1617
import {
1718
createMockAutohandAINativeSequenceServer,
1819
createMockAutohandAINativeToolServer,
@@ -42,6 +43,41 @@ import {
4243
registerBuiltCliCleanup();
4344

4445
describe('built CLI Tuistory smoke tests', () => {
46+
it('shortens the home directory in the command-mode welcome banner', async () => {
47+
const provider = await createMockAutohandAINativeSequenceServer([{ content: 'WELCOME_DIRECTORY_OK' }]);
48+
mockServers.push(provider);
49+
const state = await createTempAutohandHome({
50+
config: {
51+
provider: 'autohandai',
52+
autohandai: {
53+
plan: 'cloud', authMode: 'api-key', apiKey: 'tuistory-autohand-api-key',
54+
model: 'moa', baseUrl: provider.baseUrl,
55+
},
56+
features: { autohand_inference: true },
57+
agent: { maxIterations: 2, sessionRetryLimit: 0, autoMemory: false },
58+
network: { maxRetries: 0, retryDelay: 0 },
59+
},
60+
});
61+
tempStates.push(state);
62+
const workspace = path.join(state.workspaceRoot, 'demo', 'kowhai-coffee');
63+
await fs.ensureDir(workspace);
64+
const session = await trackSession(launchBuiltAutohand([
65+
'--path', workspace, '--config', state.configPath,
66+
'--prompt', 'Say WELCOME_DIRECTORY_OK.', '--ephemeral', '--y',
67+
], {
68+
autohandHome: state.autohandHome,
69+
cwd: workspace,
70+
cols: 180,
71+
env: { HOME: state.workspaceRoot },
72+
}));
73+
await waitForExit(session, 30_000);
74+
const welcome = startupWelcomeStatusLine(session.getRawOutput());
75+
expect(welcome).toContain('| directory: ~/demo/kowhai-coffee');
76+
expect(welcome).not.toContain(state.workspaceRoot);
77+
expect(session.readAll()).toContain('WELCOME_DIRECTORY_OK');
78+
expectCleanExit(session);
79+
}, 45_000);
80+
4581
it('keeps a prior-session goal dormant when a fresh MOA session starts with an acknowledgement', async () => {
4682
const nativeToolServer = await createMockAutohandAINativeSequenceServer([
4783
{

‎tests/ui/theme/startup.spec.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { COLOR_TOKENS, type ResolvedColors } from '../../../src/ui/theme/types.j
1111
import {
1212
formatStartupBanner,
1313
formatPeerSessionsLine,
14+
formatWelcomeDirectory,
1415
formatWelcomeStatusLine,
1516
formatWelcomeSuggestion,
1617
formatWelcomeHint,
@@ -73,4 +74,13 @@ describe('startup theme formatting', () => {
7374
expect(hint).toBe('Describe a task, or use /help to see commands.');
7475
expect(hint.split('\n')).toHaveLength(1);
7576
});
77+
78+
it('shows the home folder as ~ in the welcome directory, like the status line', () => {
79+
expect(formatWelcomeDirectory('/Users/ana/demo/kowhai-coffee', '/Users/ana')).toBe('~/demo/kowhai-coffee');
80+
expect(formatWelcomeDirectory('/Users/ana', '/Users/ana')).toBe('~');
81+
expect(formatWelcomeDirectory('/Users/anabel/repo', '/Users/ana')).toBe('/Users/anabel/repo');
82+
expect(formatWelcomeDirectory('/srv/repo', '/Users/ana')).toBe('/srv/repo');
83+
expect(formatWelcomeDirectory('C:\\Users\\ana\\repo', 'C:\\Users\\ana')).toBe('~\\repo');
84+
expect(formatWelcomeDirectory('/srv/repo', '')).toBe('/srv/repo');
85+
});
7686
});

0 commit comments

Comments
 (0)