* fix(harness): start Pi sessions with MCP tools under Node The desktop app always gives Pi OpenPencil's MCP server, and the published companion failed every such session: - @ai-sdk/harness-pi imports pi-mcp-adapter, which publishes only TypeScript sources, and Node refuses to strip types under node_modules. A module load hook now strips them for TypeScript dependencies only; Bun runs them as is. (vercel/ai#22040) - pi-mcp-adapter imports @earendil-works/pi-tui but declares it as an optional peer, so npm leaves it out. The companion depends on it at the version pi-coding-agent uses, and a test keeps the two in step. (nicobailon/pi-mcp-adapter#805) - Pi reports live-process resume, yet the service handed it state saved by an earlier session, and the just-bash sandbox cannot resume, so every later session with that ID failed. Live-process backends now start fresh and drop saved state. Pi also installs the packages from a person's Pi settings with npm on every session, writing npm's output to the companion's stdout. The companion now keeps the real stdout for protocol messages, sends other writes to stderr, and quiets npm on success. The app logs companion stderr as diagnostics, since failures arrive as protocol errors. * fix(harness): reject another backend's state before dropping it loadResumeState removed saved state for a live-process backend before createSession checked which backend owned it, so state saved by another backend was lost instead of rejected. Ownership is checked first, and only state that belongs to the live-process backend is dropped.
35 lines
1.5 KiB
TypeScript
35 lines
1.5 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { spawnSync } from 'node:child_process'
|
|
import { join } from 'node:path'
|
|
|
|
const output = join(import.meta.dir, '../src/output.ts')
|
|
// The companion runs under Node, whose console writes through process.stdout.
|
|
const nodeRunsTypeScript =
|
|
spawnSync('node', ['-e', 'process.exit(process.features.typescript ? 0 : 1)']).status === 0
|
|
|
|
describe('reserveProtocolOutput', () => {
|
|
test.skipIf(!nodeRunsTypeScript)(
|
|
'keeps stdout for protocol messages and quiets npm runs its children start',
|
|
() => {
|
|
const script = `
|
|
import { spawnSync } from 'node:child_process'
|
|
const { reserveProtocolOutput } = await import(${JSON.stringify(output)})
|
|
const writeProtocol = reserveProtocolOutput()
|
|
console.log('library noise')
|
|
process.stdout.write('more noise\\n')
|
|
writeProtocol('{"type":"response"}\\n')
|
|
const child = spawnSync(process.execPath, ['-p', 'process.env.npm_config_loglevel + " " + process.env.npm_config_audit'], { encoding: 'utf8' })
|
|
writeProtocol(JSON.stringify({ npm: child.stdout.trim() }) + '\\n')
|
|
`
|
|
const result = spawnSync('node', ['--input-type=module', '-e', script], { encoding: 'utf8' })
|
|
const lines = result.stdout.trim().split('\n')
|
|
expect(lines.map((line) => JSON.parse(line))).toEqual([
|
|
{ type: 'response' },
|
|
{ npm: 'silent false' }
|
|
])
|
|
expect(result.stderr).toContain('library noise')
|
|
expect(result.stderr).toContain('more noise')
|
|
}
|
|
)
|
|
})
|