fix: all CLI script resolution uses bundled-first resolveTool() #362

Merged
jason.woltje merged 1 commits from fix/cli-sync-issues into main 2026-04-03 02:28:08 +00:00
3 changed files with 17 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@mosaic/cli",
"version": "0.0.7",
"version": "0.0.8",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View File

@@ -68,7 +68,7 @@ function checkSoul(): void {
}
// Fallback: legacy bash mosaic-init
const initBin = join(MOSAIC_HOME, 'tools', '_scripts', 'mosaic-init');
const initBin = fwScript('mosaic-init');
if (existsSync(initBin)) {
spawnSync(initBin, [], { stdio: 'inherit' });
} else {
@@ -79,7 +79,7 @@ function checkSoul(): void {
}
function checkSequentialThinking(runtime: string): void {
const checker = join(MOSAIC_HOME, 'tools', '_scripts', 'mosaic-ensure-sequential-thinking');
const checker = fwScript('mosaic-ensure-sequential-thinking');
if (!existsSync(checker)) return; // Skip if checker doesn't exist
const result = spawnSync(checker, ['--check', '--runtime', runtime], { stdio: 'ignore' });
if (result.status !== 0) {
@@ -493,24 +493,28 @@ function delegateToScript(scriptPath: string, args: string[], env?: Record<strin
}
/**
* Resolve a framework script path. Prefers the version bundled in the
* @mosaic/mosaic npm package (always matches the installed CLI version)
* over the deployed copy in ~/.config/mosaic/ (may be stale).
* Resolve a path under the framework tools directory. Prefers the version
* bundled in the @mosaic/mosaic npm package (always matches the installed
* CLI version) over the deployed copy in ~/.config/mosaic/ (may be stale).
*/
function fwScript(name: string): string {
function resolveTool(...segments: string[]): string {
try {
const require = createRequire(import.meta.url);
const mosaicPkg = dirname(require.resolve('@mosaic/mosaic/package.json'));
const bundled = join(mosaicPkg, 'framework', 'tools', '_scripts', name);
const req = createRequire(import.meta.url);
const mosaicPkg = dirname(req.resolve('@mosaic/mosaic/package.json'));
const bundled = join(mosaicPkg, 'framework', 'tools', ...segments);
if (existsSync(bundled)) return bundled;
} catch {
// Fall through to deployed copy
}
return join(MOSAIC_HOME, 'tools', '_scripts', name);
return join(MOSAIC_HOME, 'tools', ...segments);
}
function fwScript(name: string): string {
return resolveTool('_scripts', name);
}
function toolScript(toolDir: string, name: string): string {
return join(MOSAIC_HOME, 'tools', toolDir, name);
return resolveTool(toolDir, name);
}
// ─── Coord (mission orchestrator) ───────────────────────────────────────────

View File

@@ -1,6 +1,6 @@
{
"name": "@mosaic/mosaic",
"version": "0.0.7",
"version": "0.0.8",
"description": "Mosaic agent framework — installation wizard and meta package",
"type": "module",
"main": "dist/index.js",