fix: ship capability packs and starter skills, report the usable model (UF-066, UF-067)

The SDK reads pack manifests and starter skills next to its own module,
which in the bundle is service.js, and no build step copied them there:
installed builds showed no packs and no starter skills. build-sidecar now
copies both folders next to service.js and Tauri bundles them (UF-066).

GET /api/agent/status returned the configured model even when it had no
key, so the status bar named Claude while chats ran on the local model.
It now resolves the model the way the chat route does (UF-067).
This commit is contained in:
shumeiko.it
2026-11-01 11:15:37 +01:00
parent 8e528b3467
commit bf74f02420
9 changed files with 102 additions and 15 deletions

View File

@@ -12,14 +12,19 @@ export interface CapabilityPack {
}
/**
* Get the directory containing capability pack JSON manifests.
* Resolves to the source directory containing .json files.
* Get the directory containing capability pack JSON manifests: the package's
* src/ when running from src/ or dist/, or the `capability-packs` folder that
* scripts/build-sidecar.mjs copies next to the bundled service.js.
*/
export function getCapabilityPacksDir(): string {
// When running from compiled output (dist/), go up to package root then into src/
const srcDir = path.resolve(__dirname, '..', '..', 'src', 'capability-packs');
if (fs.existsSync(srcDir) && fs.readdirSync(srcDir).some(f => f.endsWith('.json'))) {
return srcDir;
const candidates = [
path.resolve(__dirname, '..', '..', 'src', 'capability-packs'),
path.join(__dirname, 'capability-packs'),
];
for (const dir of candidates) {
if (fs.existsSync(dir) && fs.readdirSync(dir).some(f => f.endsWith('.json'))) {
return dir;
}
}
// Fallback: same directory (running directly from source)
return __dirname;

View File

@@ -5,15 +5,19 @@ import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
/**
* Get the directory containing starter skill files.
* Resolves to the source directory containing .md files.
* Get the directory containing starter skill files: the package's src/ when
* running from src/ or dist/, or the `starter-skills` folder that
* scripts/build-sidecar.mjs copies next to the bundled service.js.
*/
export function getStarterSkillsDir(): string {
// When running from compiled output (dist/), go up to package root then into src/
// When running from source (src/), we're already in the right place
const srcDir = path.resolve(__dirname, '..', '..', 'src', 'starter-skills');
if (fs.existsSync(srcDir) && fs.readdirSync(srcDir).some(f => f.endsWith('.md'))) {
return srcDir;
const candidates = [
path.resolve(__dirname, '..', '..', 'src', 'starter-skills'),
path.join(__dirname, 'starter-skills'),
];
for (const dir of candidates) {
if (fs.existsSync(dir) && fs.readdirSync(dir).some(f => f.endsWith('.md'))) {
return dir;
}
}
// Fallback: same directory (running directly from source)
return __dirname;

View File

@@ -32,9 +32,17 @@ export const agentRoutes: FastifyPluginAsync = async (server) => {
// GET /api/agent/status — agent status including cost stats
server.get('/api/agent/status', async () => {
const stats = costTracker.getStats();
// Report the model a chat will run on: chat.ts resolves the configured
// model the same way, so without a provider key this is the local model.
let model = server.agentState.currentModel;
try {
model = await resolveUsableModel(server, model);
} catch {
// Nothing usable yet; show the configured model.
}
return {
running: true,
model: server.agentState.currentModel,
model,
tokensUsed: stats.totalInputTokens + stats.totalOutputTokens,
estimatedCost: stats.estimatedCost,
turns: stats.turns,

View File

@@ -432,6 +432,30 @@ describe('LiteLLM Management API', () => {
expect(body.model).toBe('ollama/llama3.2:latest');
});
it('GET /api/agent/status reports the model chats will use, not an unusable default (UF-067)', async () => {
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const url = String(input);
if (url.endsWith('/api/tags')) {
return {
ok: true,
json: async () => ({ models: [{ name: 'llama3.2:latest', size: 2_000_000_000 }] }),
} as Response;
}
return { ok: false, status: 503 } as Response;
});
const priorCurrentModel = server.agentState.currentModel;
// As after a restart: the configured default has no key and nothing resolved it yet.
server.agentState.currentModel = 'claude-sonnet-4-6';
try {
const res = await injectWithAuth(server, { method: 'GET', url: '/api/agent/status' });
expect(res.statusCode).toBe(200);
expect(JSON.parse(res.body).model).toBe('ollama/llama3.2:latest');
expect(server.agentState.currentModel).toBe('claude-sonnet-4-6');
} finally {
server.agentState.currentModel = priorCurrentModel;
}
});
it('prefers a deterministic credentialed cloud fallback over an unrelated host Ollama model', async () => {
const runtimePath = path.join(dataDir, 'litellm.runtime.json');
const priorRuntime = fs.existsSync(runtimePath) ? fs.readFileSync(runtimePath, 'utf-8') : null;

View File

@@ -213,6 +213,9 @@ describe('Tauri Production Configuration', () => {
it('tauri.conf.json bundles resources directory', () => {
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
expect(conf.bundle.resources).toContain('resources/*');
// UF-066: the bundled SDK reads these next to service.js.
expect(conf.bundle.resources).toContain('resources/capability-packs/*');
expect(conf.bundle.resources).toContain('resources/starter-skills/*');
});
it('tauri.conf.json has correct window settings', () => {
@@ -479,6 +482,8 @@ describe('Tauri Production Configuration', () => {
['package-lock.json', '{"lockfileVersion":3}\n'],
['package.json', '{"name":"sidecar-tsconfig-fixture","private":true}\n'],
['packages/marketplace/marketplace.db', 'fixture database'],
['packages/sdk/src/capability-packs/research-workflow.json', '{"id":"research-workflow"}\n'],
['packages/sdk/src/starter-skills/brainstorm.md', '# Brainstorm\n'],
['packages/server/package.json', '{"name":"@waggle/server"}\n'],
['packages/server/src/local/service.ts', 'export const fixture = true;\n'],
['packages/server/tsconfig.json', '{"extends":"../../tsconfig.base"}\n'],
@@ -566,6 +571,10 @@ describe('Tauri Production Configuration', () => {
trackedFiles.get('packages/marketplace/marketplace.db')!,
);
expect(fs.readFileSync(marketplaceResourcePath)).toEqual(committedMarketplace);
// UF-066: the SDK reads packs and starter skills next to service.js.
const resourcesRoot = path.join(fixtureRoot, 'app', 'src-tauri', 'resources');
expect(fs.existsSync(path.join(resourcesRoot, 'capability-packs', 'research-workflow.json'))).toBe(true);
expect(fs.existsSync(path.join(resourcesRoot, 'starter-skills', 'brainstorm.md'))).toBe(true);
fs.writeFileSync(marketplacePath, 'dirty worktree database');
const dirtyMarketplaceResult = runResult(