Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): print upgrade progress as plain ASCII (#6539)

Joey9ccf1d19b7e4
diff --git a/.changeset/cli-spec-ascii-upgrade-output.md b/.changeset/cli-spec-ascii-upgrade-output.md
new file mode 100644
index 0000000000..baf8339590
--- /dev/null
+++ b/.changeset/cli-spec-ascii-upgrade-output.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx upgrade` human output is now plain ASCII. Progress and codemod lines use `[ok]`, `!` and `!!` instead of check, warning and cross glyphs, and dashes and arrows print as `-` and `->`, including in codemod titles listed by `--list`. `--json` output is unchanged.
+
+@josephfarina
diff --git a/packages/cli/api/upgrade/_adapter.mjs b/packages/cli/api/upgrade/_adapter.mjs
index bd6fc8f6b4..6ca0cf6a87 100644
--- a/packages/cli/api/upgrade/_adapter.mjs
+++ b/packages/cli/api/upgrade/_adapter.mjs
@@ -147,7 +147,7 @@ export async function runPostCodemodHooks(hooks, context) {
env: {...process.env, ...(cmd.options?.env ?? {})},
}),
);
- logger.log(`✓ Post-codemod hook ${label} completed.`);
+ logger.log(`[ok] Post-codemod hook ${label} completed.`);
}
}
@@ -186,7 +186,7 @@ export async function prepareAgentDocsRefresh({
if (initial.status === 'missing') {
summary.action = 'nudge-init';
logger.warn(
- `No Astryx agent-docs block found — AI agents have no component index. Run \`${formatCliCommand('astryx init --features agents')}\` to install it.`,
+ `No Astryx agent-docs block found - AI agents have no component index. Run \`${formatCliCommand('astryx init --features agents')}\` to install it.`,
);
return {cwd, renderedBlock: null, summary};
}
@@ -240,7 +240,7 @@ export function applyAgentDocsRefresh(plan) {
summary.files = written;
summary.action = summary.refreshed ? 'refreshed' : 'error';
if (summary.refreshed) {
- logger.log(`✓ Agent docs refreshed → ${written.join(', ')}`);
+ logger.log(`[ok] Agent docs refreshed -> ${written.join(', ')}`);
} else {
logger.warn(
`Agent docs look stale but couldn't be refreshed. Run \`${formatCliCommand('astryx init --features agents')}\` to reinstall the block.`,
diff --git a/packages/cli/api/upgrade/list/list.mjs b/packages/cli/api/upgrade/list/list.mjs
index 83520a179e..8dad65bb62 100644
--- a/packages/cli/api/upgrade/list/list.mjs
+++ b/packages/cli/api/upgrade/list/list.mjs
@@ -10,6 +10,7 @@
import {collectAllCodemods} from '../_adapter.mjs';
import {logger} from '../../logger.mjs';
+import {toAscii} from '../../../assets/codemods/term-log.mjs';
/**
* List every available codemod (oldest→newest).
@@ -19,7 +20,7 @@ export async function list() {
const codemods = await collectAllCodemods();
logger.log('Available codemods:');
for (const {name, title, pr, optional} of codemods) {
- logger.log(` ${name} — ${title}${optional ? ' (optional)' : ''} (${pr})`);
+ logger.log(` ${name} - ${toAscii(title)}${optional ? ' (optional)' : ''} (${pr})`);
}
logger.log('Done\n');
return {
diff --git a/packages/cli/api/upgrade/status/status.mjs b/packages/cli/api/upgrade/status/status.mjs
index ab32b021ce..28b06e1cb7 100644
--- a/packages/cli/api/upgrade/status/status.mjs
+++ b/packages/cli/api/upgrade/status/status.mjs
@@ -24,7 +24,7 @@ import {logger} from '../../logger.mjs';
* @returns {import('../upgrade.type.mjs').UpgradeStatusResponse}
*/
export function statusUpToDate({from, to, agentDocs, registryCompositions}) {
- logger.log('✓ Already up to date — no codemods to run.');
+ logger.log('[ok] Already up to date - no codemods to run.');
logger.log('Use --force to run codemods anyway.');
logger.log(registryCompositions?.ok === false ? 'Finished with unresolved registry items\n' : 'Done\n');
return {
@@ -45,7 +45,7 @@ export function statusUpToDate({from, to, agentDocs, registryCompositions}) {
* @returns {import('../upgrade.type.mjs').UpgradeStatusResponse}
*/
export function statusNoCodemods({from, to, agentDocs, registryCompositions}) {
- logger.log('✓ No codemods available for this version range.');
+ logger.log('[ok] No codemods available for this version range.');
logger.log(registryCompositions?.ok === false ? 'Finished with unresolved registry items\n' : 'Done\n');
return {
type: 'upgrade.status',
diff --git a/packages/cli/assets/codemods/term-log.mjs b/packages/cli/assets/codemods/term-log.mjs
index 7aa0c861d7..01c9c84155 100644
--- a/packages/cli/assets/codemods/term-log.mjs
+++ b/packages/cli/assets/codemods/term-log.mjs
@@ -11,6 +11,8 @@
* `p.log.step(...)`, `p.log.success(...)`, etc. All output routes through
* `humanLog`, the CLI's stdout-discipline primitive, which is a no-op in
* `--json` mode — so these human logs can never corrupt a JSON envelope.
+ * Every line is plain ASCII: level prefixes are ASCII and typographic glyphs
+ * in a message are transliterated before it is printed.
*
* The side-effecting API commands (upgrade/init/themeBuild) do NOT use this;
* they write through the shared `logger` (api/logger.mjs).
@@ -18,8 +20,30 @@
import {humanLog} from '../../foundation/response/json.mjs';
-/** @param {unknown} msg */
-const toStr = (msg) => (msg === undefined || msg === null ? '' : String(msg));
+/** @type {Array<[RegExp, string]>} */
+const ASCII_GLYPHS = [
+ [/[\u2014\u2013]/g, '-'],
+ [/\u2192/g, '->'],
+ [/\u2713/g, '[ok]'],
+ [/\u2717/g, '!!'],
+ [/\u26a0\ufe0f?/g, '!'],
+ [/\u2022/g, '-'],
+ [/\u2026/g, '...'],
+ [/[\u2018\u2019]/g, "'"],
+ [/[\u201c\u201d]/g, '"'],
+ [/\u00a0/g, ' '],
+];
+
+/**
+ * A message as plain ASCII: typographic glyphs become their ASCII spelling.
+ * @param {unknown} msg
+ * @returns {string}
+ */
+export function toAscii(msg) {
+ let text = msg === undefined || msg === null ? '' : String(msg);
+ for (const [glyph, ascii] of ASCII_GLYPHS) text = text.replace(glyph, ascii);
+ return text;
+}
/**
* Human-facing log surface (the small `log` API codemods use). All lines go to
@@ -28,15 +52,15 @@ const toStr = (msg) => (msg === undefined || msg === null ? '' : String(msg));
*/
export const log = {
/** @param {unknown} msg */
- message: (msg) => humanLog(toStr(msg)),
+ message: (msg) => humanLog(toAscii(msg)),
/** @param {unknown} msg */
- info: (msg) => humanLog(toStr(msg)),
+ info: (msg) => humanLog(toAscii(msg)),
/** @param {unknown} msg */
- step: (msg) => humanLog(toStr(msg)),
+ step: (msg) => humanLog(toAscii(msg)),
/** @param {unknown} msg */
- success: (msg) => humanLog(`✓ ${toStr(msg)}`),
+ success: (msg) => humanLog(`[ok] ${toAscii(msg)}`),
/** @param {unknown} msg */
- warn: (msg) => humanLog(`⚠ ${toStr(msg)}`),
+ warn: (msg) => humanLog(`! ${toAscii(msg)}`),
/** @param {unknown} msg */
- error: (msg) => humanLog(`✗ ${toStr(msg)}`),
+ error: (msg) => humanLog(`!! ${toAscii(msg)}`),
};
diff --git a/packages/cli/assets/codemods/term-log.test.mjs b/packages/cli/assets/codemods/term-log.test.mjs
index 8c94265a4c..0fc8135261 100644
--- a/packages/cli/assets/codemods/term-log.test.mjs
+++ b/packages/cli/assets/codemods/term-log.test.mjs
@@ -51,7 +51,7 @@ describe('sanity: helpers are live in human mode', () => {
setJsonMode(false);
p.log.success('done');
expect(logSpy).toHaveBeenCalledTimes(1);
- expect(logSpy).toHaveBeenCalledWith('✓ done');
+ expect(logSpy).toHaveBeenCalledWith('[ok] done');
});
it('every log helper emits exactly one stdout line in human mode', () => {
@@ -60,3 +60,21 @@ describe('sanity: helpers are live in human mode', () => {
expect(logSpy).toHaveBeenCalledTimes(6);
});
});
+
+describe('ASCII output', () => {
+ it('prints ASCII level prefixes and transliterates glyphs in messages', () => {
+ setJsonMode(false);
+ p.log.success('src/a.tsx');
+ p.log.warn('stale \u2014 refresh');
+ p.log.error(' \u2717 src/b.tsx \u2014 rename \u2192 failed');
+ p.log.info(' \u2022 name \u2014 title\u2026');
+ const lines = logSpy.mock.calls.map(call => call.join(' '));
+ expect(lines).toEqual([
+ '[ok] src/a.tsx',
+ '! stale - refresh',
+ '!! !! src/b.tsx - rename -> failed',
+ ' - name - title...',
+ ]);
+ for (const line of lines) expect(line).not.toMatch(/[\u0080-\uFFFF]/);
+ });
+});
diff --git a/packages/cli/clients/cli/commands/upgrade.ascii-output.test.mjs b/packages/cli/clients/cli/commands/upgrade.ascii-output.test.mjs
new file mode 100644
index 0000000000..d85c397d32
--- /dev/null
+++ b/packages/cli/clients/cli/commands/upgrade.ascii-output.test.mjs
@@ -0,0 +1,87 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file `astryx upgrade` human output is plain ASCII on every path: the codemod
+ * list, up to date, an empty range, a dry run, and an apply that runs a
+ * post-codemod hook and refreshes the agent docs.
+ */
+
+import {describe, it, expect, beforeEach, afterEach} from 'vitest';
+import * as fs from 'node:fs';
+import * as path from 'node:path';
+import {runCli} from '../../../test-utils/run-cli.mjs';
+import {generateCompressedIndex} from '../../../foundation/agent-docs/agent-docs.mjs';
+
+const NON_ASCII = /[\u0080-\uFFFF]/;
+
+let tmpDir;
+
+/** @param {string} rel @param {string} body */
+function write(rel, body) {
+ const file = path.join(tmpDir, rel);
+ fs.mkdirSync(path.dirname(file), {recursive: true});
+ fs.writeFileSync(file, body);
+}
+
+/**
+ * Output lines (stdout and stderr) that contain a non-ASCII character.
+ * @param {string[]} args
+ */
+async function nonAsciiLines(args) {
+ const r = await runCli(args, {cwd: tmpDir});
+ expect(r.status).toBe(0);
+ return `${r.stdout}\n${r.stderr}`
+ .split('\n')
+ .filter(line => NON_ASCII.test(line));
+}
+
+beforeEach(() => {
+ // Repo-local so the config module can be imported under Vitest.
+ tmpDir = fs.mkdtempSync(path.join(process.cwd(), '.astryx-upgrade-ascii-'));
+ write('package.json', JSON.stringify({name: 'consumer', private: true}));
+ write(
+ 'node_modules/@astryxdesign/core/package.json',
+ JSON.stringify({name: '@astryxdesign/core', version: '0.6.0'}),
+ );
+ write(
+ 'src/panel.tsx',
+ "import {useResizable} from '@astryxdesign/core';\n" +
+ 'export const usePanel = () => useResizable({defaultSize: 250, minSizePx: 200});\n',
+ );
+});
+
+afterEach(() => {
+ fs.rmSync(tmpDir, {recursive: true, force: true});
+});
+
+describe('upgrade human output is ASCII', () => {
+ it('lists codemods', async () => {
+ expect(await nonAsciiLines(['upgrade', '--list'])).toEqual([]);
+ });
+
+ it('reports up to date and a missing agent-docs block', async () => {
+ expect(await nonAsciiLines(['upgrade', '--from', '0.6.0'])).toEqual([]);
+ });
+
+ it('reports a range with no codemods', async () => {
+ expect(
+ await nonAsciiLines(['upgrade', '--from', '0.6.0', '--force']),
+ ).toEqual([]);
+ });
+
+ it('previews and applies codemods, runs a hook, and refreshes agent docs', async () => {
+ write(
+ 'astryx.config.mjs',
+ `export default {hooks: {postCodemod: [{name: 'noop', buildCommand: () => ({command: ${JSON.stringify(process.execPath)}, args: ['-e', '0']})}]}};\n`,
+ );
+ write('AGENTS.md', `# Agents\n\n${generateCompressedIndex('0.5.0')}\n`);
+
+ expect(await nonAsciiLines(['upgrade', '--from', '0.5.0'])).toEqual([]);
+ expect(
+ await nonAsciiLines(['upgrade', '--from', '0.5.0', '--apply']),
+ ).toEqual([]);
+ expect(fs.readFileSync(path.join(tmpDir, 'src/panel.tsx'), 'utf8')).toContain(
+ 'minSize: 200',
+ );
+ });
+});