Fix daemon project-root resolution when launched from src via tsx (#162)

resolveProjectRoot only stripped a 'dist' suffix from the caller's
module directory, so when the daemon sidecar is started by tools-dev
(which runs apps/daemon/src/server.ts directly through tsx) the
computed PROJECT_ROOT pointed at apps/ instead of the repo root.
That made SKILLS_DIR, DESIGN_SYSTEMS_DIR, STATIC_DIR and the default
RUNTIME_DATA_DIR all resolve to non-existent paths, so /api/skills
returned an empty list and the web "examples" page reported
"No skills available. Is the daemon running?".

Treat 'src' the same as 'dist' so resolution works for both the tsx
source entry and the compiled build, and add a regression test for
the src case alongside the existing dist/daemon-root cases.
This commit is contained in:
pan 2026-04-30 12:31:38 +02:00 committed by GitHub
parent 53722bb545
commit 7294929490
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View file

@ -70,7 +70,8 @@ import {
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export function resolveProjectRoot(moduleDir: string): string {
const daemonDir = path.basename(moduleDir) === 'dist'
const base = path.basename(moduleDir);
const daemonDir = base === 'dist' || base === 'src'
? path.dirname(moduleDir)
: moduleDir;
return path.resolve(daemonDir, '../..');

View file

@ -14,4 +14,10 @@ describe('resolveProjectRoot', () => {
expect(resolveProjectRoot(path.join(root, 'apps', 'daemon', 'dist'))).toBe(root);
});
it('resolves the repository root from the daemon src directory (tsx entry)', () => {
const root = path.resolve(import.meta.dirname, '../../..');
expect(resolveProjectRoot(path.join(root, 'apps', 'daemon', 'src'))).toBe(root);
});
});