Repository navigation
feat(claude): add opt-in rich terminal output #33131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 53 commits
d9f7cc2
c2e9890
2a854d4
7c436fd
907072c
7e7780a
51e7b9b
cf290ec
7d9f9ea
baf7b56
c49e948
a8d3c18
677d3ae
bd86cb6
8c55b30
39bb9b8
f407e5f
f625489
2c8000f
1054139
8916b05
4b9b7fb
01e733f
9b74134
620628b
0caad26
a2e5edf
5da7924
7119b21
05e0df3
e4e1d7d
4976b34
81a16ea
f7d8d5b
6d1c1ac
c635724
4d75273
061d5d7
e15b98f
197864d
27c444d
63b8ea2
a4aa01b
ff0e4a1
3d1e608
ac10df1
a697240
f0868f7
4bfc6f3
75e4ff4
4abfe68
969b568
2085788
f308bd4
b3b6a5f
6a85e60
aa40e7e
582b172
8336fc7
358cb13
550d858
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,111 @@ | ||||||
| import { build } from 'esbuild' | ||||||
| import { | ||||||
| existsSync, | ||||||
| readFileSync, | ||||||
| readdirSync, | ||||||
| writeFileSync, | ||||||
| rmSync, | ||||||
| realpathSync, | ||||||
| statSync | ||||||
| } from 'node:fs' | ||||||
| import { join, sep } from 'node:path' | ||||||
| import { fileURLToPath } from 'node:url' | ||||||
| import { runProcess } from '@orca/process-host' | ||||||
| import { withClaudeRichOutputBuildLock } from './claude-rich-output-build-lock.mjs' | ||||||
| import { computeClaudeRichOutputSourceHash } from './claude-rich-output-source-hash.mjs' | ||||||
| import { resolvePnpmCliInvocation } from './pnpm-cli-invocation.mjs' | ||||||
| import { claudeRichOutputAssetFilenames } from '../../src/shared/claude-rich-output-artifacts.ts' | ||||||
|
|
||||||
| const root = fileURLToPath(new URL('../..', import.meta.url)) | ||||||
| const output = join(root, 'out', 'claude-rich-output') | ||||||
| const marker = join(output, '.source-hash') | ||||||
| function deploymentIsComplete() { | ||||||
| try { | ||||||
| const directory = `${realpathSync(output)}${sep}` | ||||||
| return claudeRichOutputAssetFilenames( | ||||||
| readFileSync(join(output, 'manifest.json'), 'utf8') | ||||||
| ).every((asset) => { | ||||||
| const file = join(root, 'out', asset) | ||||||
| return statSync(file).isFile() && realpathSync(file).startsWith(directory) | ||||||
| }) | ||||||
| } catch { | ||||||
| return false | ||||||
| } | ||||||
| } | ||||||
| await withClaudeRichOutputBuildLock(root, async (assertLockHeld) => { | ||||||
| const key = computeClaudeRichOutputSourceHash(root) | ||||||
| if (!existsSync(marker) || readFileSync(marker, 'utf8') !== key || !deploymentIsComplete()) { | ||||||
| const { command, prefixArgs } = resolvePnpmCliInvocation() | ||||||
| const result = await runProcess({ | ||||||
| program: command, | ||||||
| args: [ | ||||||
| ...prefixArgs, | ||||||
| '--filter', | ||||||
| '@orca/claude-rich-output', | ||||||
| 'deploy', | ||||||
| '--prod', | ||||||
| '--legacy', | ||||||
| '--force', | ||||||
| '--config.allowUnusedPatches=true', | ||||||
| '--config.nodeLinker=hoisted', | ||||||
| output | ||||||
| ], | ||||||
| cwd: root, | ||||||
| stdio: 'inherit', | ||||||
| timeoutMs: 120_000 | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
| timeoutMs: 120_000 | |
| timeoutMs: null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the deployment path and the process-host timeout handling. The 120-second limit is an actual finite deployment budget, and exceeding it deliberately fails the required asset build rather than packaging incomplete assets. Removing it or extending it would weaken the existing deadline, which this contribution must preserve. I have not reproduced a valid deployment exceeding that budget, and local passing builds would not establish a bound for slower Windows/Linux disks. I am retaining timeoutMs: 120_000 and leaving this portability tradeoff open for maintainer judgment; the current main-compatibility repair does not claim to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JhaceLam Understood. Retain timeoutMs: 120_000 to preserve the finite deployment budget.
My recommendation to remove the deadline was too strong without a reproduced valid deployment that exceeds it. The Windows/Linux portability concern remains unverified, not a confirmed defect. This tradeoff remains open for maintainer judgment; the main-compatibility repair does not address it.
You are interacting with an AI system.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { mkdirSync } from 'node:fs' | ||
| import { join } from 'node:path' | ||
| import lockfile from 'proper-lockfile' | ||
|
|
||
| export async function withClaudeRichOutputBuildLock(root, action) { | ||
| mkdirSync(join(root, 'out'), { recursive: true }) | ||
| let compromised | ||
| const release = await lockfile.lock(root, { | ||
| lockfilePath: join(root, 'out', '.claude-rich-output-build.lock'), | ||
| realpath: false, | ||
| stale: 30_000, | ||
| retries: { retries: 1_000, minTimeout: 50, maxTimeout: 250 }, | ||
| onCompromised: (error) => { | ||
| compromised = error | ||
| } | ||
| }) | ||
| const assertLockHeld = () => { | ||
| if (compromised) { | ||
| throw compromised | ||
| } | ||
| } | ||
| try { | ||
| assertLockHeld() | ||
| const result = await action(assertLockHeld) | ||
| assertLockHeld() | ||
| return result | ||
| } finally { | ||
| if (!compromised) { | ||
| await release().catch((error) => { | ||
| console.warn('[claude-rich-output] Could not release build lock:', error) | ||
| }) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { runProcessSync } from '@orca/process-host' | ||
| import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' | ||
| import { tmpdir } from 'node:os' | ||
| import { dirname, join } from 'node:path' | ||
| import { expect } from 'vitest' | ||
|
|
||
| const scripts = import.meta.dirname | ||
| const directories = [] | ||
| export function cleanupClaudeRichOutputBuildFixtures() { | ||
| for (const directory of directories.splice(0)) { | ||
| rmSync(directory, { recursive: true, force: true }) | ||
| } | ||
| } | ||
|
|
||
| export function createClaudeRichOutputBuildFixture() { | ||
| const root = mkdtempSync(join(tmpdir(), 'rich-output-cache-')) | ||
| directories.push(root) | ||
| const put = (name, source) => { | ||
| const file = join(root, name) | ||
| mkdirSync(dirname(file), { recursive: true }) | ||
| writeFileSync(file, source) | ||
| } | ||
| for (const name of [ | ||
| 'build-claude-rich-output.mjs', | ||
| 'claude-rich-output-build-lock.mjs', | ||
| 'claude-rich-output-source-hash.mjs', | ||
| 'pnpm-cli-invocation.mjs' | ||
| ]) { | ||
| put(`config/scripts/${name}`, readFileSync(join(scripts, name))) | ||
| } | ||
| put( | ||
| 'src/shared/claude-rich-output-artifacts.ts', | ||
| readFileSync(join(scripts, '../../src/shared/claude-rich-output-artifacts.ts')) | ||
| ) | ||
| put('pnpm-lock.yaml', 'fixture lock') | ||
| put('resources/claude-rich-output/foo', 'barvalue') | ||
| put( | ||
| 'node_modules/esbuild/package.json', | ||
| JSON.stringify({ type: 'module', exports: './index.js' }) | ||
| ) | ||
| put('node_modules/esbuild/index.js', 'export async function build() {}') | ||
| put( | ||
| 'node_modules/proper-lockfile/package.json', | ||
| JSON.stringify({ type: 'module', exports: './index.js' }) | ||
| ) | ||
| put( | ||
| 'node_modules/proper-lockfile/index.js', | ||
| `export { default } from ${JSON.stringify(import.meta.resolve('proper-lockfile'))}` | ||
| ) | ||
| put( | ||
| 'node_modules/@orca/process-host/package.json', | ||
| JSON.stringify({ type: 'module', exports: './index.js' }) | ||
| ) | ||
| put( | ||
| 'node_modules/@orca/process-host/index.js', | ||
| `import { appendFileSync, cpSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| export function runProcessSync({ args }) { | ||
| const root = process.cwd(); | ||
| const output = args.at(-1); | ||
| rmSync(output, { recursive: true, force: true }); | ||
| cpSync(join(root, 'resources/claude-rich-output'), output, { recursive: true }); | ||
| mkdirSync(join(output, 'node_modules/@mathjax/src'), { recursive: true }); | ||
| mkdirSync(join(output, 'node_modules/@mathjax/src/bundle'), { recursive: true }); | ||
| writeFileSync(join(output, 'node_modules/@mathjax/src/bundle/node-main.js'), 'fixture dependency'); | ||
| mkdirSync(join(output, 'node_modules/@mathjax/mathjax-newcm-font'), { recursive: true }); | ||
| appendFileSync(join(root, 'deploy.log'), 'deploy\\n'); | ||
| return { code: 0 }; | ||
| } | ||
| export async function runProcess(options) { return runProcessSync(options) }` | ||
| ) | ||
| const runBuild = (env = process.env) => | ||
| runProcessSync({ | ||
| program: process.execPath, | ||
| args: [join(root, 'config/scripts/build-claude-rich-output.mjs')], | ||
| cwd: root, | ||
| env, | ||
| timeoutMs: 30_000 | ||
| }) | ||
| const build = () => { | ||
| const result = runBuild() | ||
| expect(result.code, result.stderr).toBe(0) | ||
| } | ||
| const deployments = () => readFileSync(join(root, 'deploy.log'), 'utf8').trim().split('\n').length | ||
| return { root, put, build, runBuild, deployments } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.