-
Notifications
You must be signed in to change notification settings - Fork 0
link-workspace-packages.cjs hardcodes package list — new workspace packages won't get node_modules symlinks or build pipeline entries #3
Description
Bug
Adding a new package under packages/ (e.g. packages/core/) does not automatically wire it into the symlink, auto-build, or build pipeline machinery. Three files must be manually updated or the package is silently unreachable at runtime.
Root Cause
1. scripts/link-workspace-packages.cjs
Hardcodes exactly 5 packages:
const packageMap = {
'native': 'native',
'pi-agent-core': 'pi-agent-core',
'pi-ai': 'pi-ai',
'pi-coding-agent': 'pi-coding-agent',
'pi-tui': 'pi-tui',
}This script runs during postinstall and creates node_modules/@gsd/* symlinks pointing into packages/. Both src/web/ (bundled by Next.js) and web/ (browser components) resolve @gsd/* by walking up to the root node_modules/@gsd/. Without the symlink, any import ... from "@gsd/core" fails with module-not-found at runtime, even though the package physically exists in packages/core/.
2. scripts/ensure-workspace-builds.cjs
Similarly hardcodes WORKSPACE_PACKAGES:
const WORKSPACE_PACKAGES = [
'native',
'pi-tui',
'pi-ai',
'pi-agent-core',
'pi-coding-agent',
]This auto-builds missing dist/index.js files during postinstall. A new package missing from this list won't be auto-built on fresh clone.
3. Root package.json
No build:core script and build:pi chain doesn't include it:
"build:pi": "npm run build:native-pkg && npm run build:pi-tui && npm run build:pi-ai && npm run build:pi-agent-core && npm run build:pi-coding-agent"build:web-host calls npm --prefix web run build which runs the Next.js build. If a new package's dist/ doesn't exist at that point, the web build fails. Correct build order is: build:pi (including new package) → build:web-host.
Fix
When adding packages/core/ (or any new workspace package), update all three:
scripts/link-workspace-packages.cjs:
const packageMap = {
'core': 'core', // add
'native': 'native',
'pi-agent-core': 'pi-agent-core',
'pi-ai': 'pi-ai',
'pi-coding-agent': 'pi-coding-agent',
'pi-tui': 'pi-tui',
}scripts/ensure-workspace-builds.cjs:
const WORKSPACE_PACKAGES = [
'native',
'pi-tui',
'pi-ai',
'pi-agent-core',
'pi-coding-agent',
'core', // add, after pi-coding-agent
]Root package.json:
"build:core": "npm run build -w @gsd/core",
"build:pi": "... && npm run build:pi-coding-agent && npm run build:core"Longer Term
These files should auto-discover packages from packages/ rather than maintaining a hardcoded list. A one-liner fs.readdirSync('packages/') with a filter for directories containing package.json would eliminate the maintenance burden entirely.
Affected Files
scripts/link-workspace-packages.cjsscripts/ensure-workspace-builds.cjspackage.json