Merge licensing: shipped notices, Apache-2.0 core files and LGPL terms
Every installer and the server archive carry LICENSE and the third-party notices, and Settings > General links to both. The files copied from hive-mind-core keep Apache-2.0 with SPDX headers. The LGPL components name their versions and where their source is. ADR-0010 settles the marketplace catalog question. Logs UF-069 and marks UF-059 Fixed.
This commit is contained in:
@@ -156,6 +156,7 @@ import { identityRoutes } from './routes/identity.js';
|
||||
import { agentRunRoutes } from './routes/agent-run.js';
|
||||
import { agentRunsRoutes } from './routes/agent-runs.js';
|
||||
import { localInferenceRoutes } from './routes/local-inference.js';
|
||||
import { legalRoutes } from './routes/legal.js';
|
||||
import { OfflineManager } from './offline-manager.js';
|
||||
import { listOllamaChatModelIds } from './model-availability.js';
|
||||
import { log, createLogger } from './logger.js';
|
||||
@@ -2045,6 +2046,7 @@ export async function buildLocalServer(config: Partial<LocalConfig> = {}) {
|
||||
await server.register(agentRunRoutes);
|
||||
await server.register(agentRunsRoutes);
|
||||
await server.register(localInferenceRoutes);
|
||||
await server.register(legalRoutes);
|
||||
|
||||
// ── Static file serving for web mode ──────────────────────────
|
||||
// When WAGGLE_FRONTEND_DIR is set, serve the React frontend as static files.
|
||||
|
||||
47
packages/server/src/local/routes/legal.ts
Normal file
47
packages/server/src/local/routes/legal.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* The license and the third-party notices, read-only, for Settings (UF-059).
|
||||
*
|
||||
* GET /api/legal/license LICENSE, text/plain
|
||||
* GET /api/legal/third-party-notices THIRD_PARTY_NOTICES.md, text/markdown
|
||||
*
|
||||
* The desktop app and the server archive carry both files next to service.js
|
||||
* (scripts/build-sidecar.mjs). Run from source, they come from the repository root.
|
||||
*/
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
|
||||
const LEGAL_DOCUMENTS = [
|
||||
{ route: '/api/legal/license', file: 'LICENSE', contentType: 'text/plain; charset=utf-8' },
|
||||
{ route: '/api/legal/third-party-notices', file: 'THIRD_PARTY_NOTICES.md', contentType: 'text/markdown; charset=utf-8' },
|
||||
] as const;
|
||||
|
||||
export interface LegalRoutesOptions {
|
||||
/** Directories searched in order for the files. */
|
||||
searchDirs?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The directory of this module (service.js in a packaged build), then the
|
||||
* repository root when this module runs from packages/server/{src,dist}/local/routes.
|
||||
*/
|
||||
export function defaultLegalSearchDirs(moduleDir = path.dirname(fileURLToPath(import.meta.url))): string[] {
|
||||
const repositoryRoot = path.resolve(moduleDir, '..', '..', '..', '..', '..');
|
||||
const fromSource = fs.existsSync(path.join(repositoryRoot, 'packages', 'server', 'package.json'));
|
||||
return fromSource ? [moduleDir, repositoryRoot] : [moduleDir];
|
||||
}
|
||||
|
||||
export async function legalRoutes(fastify: FastifyInstance, options: LegalRoutesOptions = {}) {
|
||||
const searchDirs = options.searchDirs ?? defaultLegalSearchDirs();
|
||||
for (const document of LEGAL_DOCUMENTS) {
|
||||
fastify.get(document.route, async (_request, reply) => {
|
||||
const file = searchDirs.map((dir) => path.join(dir, document.file)).find((candidate) => fs.existsSync(candidate));
|
||||
if (!file) {
|
||||
return reply.code(404).send({ error: `${document.file} is not part of this installation` });
|
||||
}
|
||||
return reply.type(document.contentType).send(await fs.promises.readFile(file, 'utf8'));
|
||||
});
|
||||
}
|
||||
}
|
||||
116
packages/server/tests/local/legal-routes.test.ts
Normal file
116
packages/server/tests/local/legal-routes.test.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* GET /api/legal/license and GET /api/legal/third-party-notices (UF-059).
|
||||
*
|
||||
* Packaged builds read the files next to service.js; a source checkout reads
|
||||
* them from the repository root.
|
||||
*/
|
||||
|
||||
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
|
||||
import fs from 'node:fs';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
import Fastify, { type FastifyInstance } from 'fastify';
|
||||
import { buildLocalServer } from '../../src/local/index.js';
|
||||
import { defaultLegalSearchDirs, legalRoutes } from '../../src/local/routes/legal.js';
|
||||
import { injectWithAuth } from '../test-utils.js';
|
||||
|
||||
const REPO_ROOT = path.resolve(import.meta.dirname, '..', '..', '..', '..');
|
||||
const ROUTES_DIR = path.resolve(import.meta.dirname, '..', '..', 'src', 'local', 'routes');
|
||||
|
||||
const temps: string[] = [];
|
||||
function tempDir(): string {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-legal-'));
|
||||
temps.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
async function serverWith(searchDirs: string[]): Promise<FastifyInstance> {
|
||||
const server = Fastify({ logger: false });
|
||||
await server.register(legalRoutes, { searchDirs });
|
||||
return server;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of temps.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('legal routes', () => {
|
||||
it('serves the copies next to service.js in a packaged build', async () => {
|
||||
const resources = tempDir();
|
||||
fs.writeFileSync(path.join(resources, 'LICENSE'), 'MIT License (packaged)\n');
|
||||
fs.writeFileSync(path.join(resources, 'THIRD_PARTY_NOTICES.md'), '# Third-party notices (packaged)\n');
|
||||
const server = await serverWith(defaultLegalSearchDirs(resources));
|
||||
try {
|
||||
const notices = await server.inject({ method: 'GET', url: '/api/legal/third-party-notices' });
|
||||
expect(notices.statusCode).toBe(200);
|
||||
expect(notices.headers['content-type']).toBe('text/markdown; charset=utf-8');
|
||||
expect(notices.payload).toBe('# Third-party notices (packaged)\n');
|
||||
|
||||
const license = await server.inject({ method: 'GET', url: '/api/legal/license' });
|
||||
expect(license.statusCode).toBe(200);
|
||||
expect(license.headers['content-type']).toBe('text/plain; charset=utf-8');
|
||||
expect(license.payload).toBe('MIT License (packaged)\n');
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('falls back to the repository root when run from source', async () => {
|
||||
expect(defaultLegalSearchDirs(ROUTES_DIR)).toEqual([ROUTES_DIR, REPO_ROOT]);
|
||||
const server = await serverWith(defaultLegalSearchDirs(ROUTES_DIR));
|
||||
try {
|
||||
const notices = await server.inject({ method: 'GET', url: '/api/legal/third-party-notices' });
|
||||
expect(notices.statusCode).toBe(200);
|
||||
expect(notices.payload).toBe(fs.readFileSync(path.join(REPO_ROOT, 'THIRD_PARTY_NOTICES.md'), 'utf8'));
|
||||
const license = await server.inject({ method: 'GET', url: '/api/legal/license' });
|
||||
expect(license.payload).toBe(fs.readFileSync(path.join(REPO_ROOT, 'LICENSE'), 'utf8'));
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
|
||||
it('does not look outside the packaged folder when it is not in a source checkout', () => {
|
||||
const resources = tempDir();
|
||||
expect(defaultLegalSearchDirs(resources)).toEqual([resources]);
|
||||
});
|
||||
|
||||
it('answers 404 when a file is missing', async () => {
|
||||
const server = await serverWith([tempDir()]);
|
||||
try {
|
||||
const res = await server.inject({ method: 'GET', url: '/api/legal/third-party-notices' });
|
||||
expect(res.statusCode).toBe(404);
|
||||
expect(JSON.parse(res.payload).error).toContain('THIRD_PARTY_NOTICES.md');
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('legal routes in the sidecar', () => {
|
||||
let server: FastifyInstance;
|
||||
let dataDir: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
// Exercise the real auth path: no loopback trust (vitest.setup.ts turns it on).
|
||||
vi.stubEnv('WAGGLE_TRUST_LOCALHOST', '0');
|
||||
dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-legal-server-'));
|
||||
server = await buildLocalServer({ dataDir });
|
||||
}, 60_000);
|
||||
|
||||
afterAll(async () => {
|
||||
await server.close();
|
||||
fs.rmSync(dataDir, { recursive: true, force: true });
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
it('serves the notices to an authenticated client', async () => {
|
||||
const res = await injectWithAuth(server, { method: 'GET', url: '/api/legal/third-party-notices' });
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.payload).toContain('# Third-party notices');
|
||||
});
|
||||
|
||||
it('requires the session token like every other API route', async () => {
|
||||
const res = await server.inject({ method: 'GET', url: '/api/legal/third-party-notices' });
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
});
|
||||
@@ -218,6 +218,16 @@ describe('Tauri Production Configuration', () => {
|
||||
expect(conf.bundle.resources).toContain('resources/starter-skills/*');
|
||||
});
|
||||
|
||||
it('bundles LICENSE and THIRD_PARTY_NOTICES.md next to service.js, untracked (UF-059)', () => {
|
||||
// `resources/*` covers the top-level files build-sidecar.mjs copies there.
|
||||
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
||||
expect(conf.bundle.resources).toContain('resources/*');
|
||||
for (const name of ['LICENSE', 'THIRD_PARTY_NOTICES.md']) {
|
||||
const ignored = spawnSync('git', ['check-ignore', '-q', `app/src-tauri/resources/${name}`], { cwd: ROOT });
|
||||
expect(ignored.status, `${name} copy is not ignored`).toBe(0);
|
||||
}
|
||||
});
|
||||
|
||||
it('tauri.conf.json has correct window settings', () => {
|
||||
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
||||
const win = conf.app.windows[0];
|
||||
@@ -479,6 +489,8 @@ describe('Tauri Production Configuration', () => {
|
||||
path.join(fixtureRoot, 'scripts', 'build-sidecar.mjs'),
|
||||
);
|
||||
const trackedFiles = new Map<string, string>([
|
||||
['LICENSE', 'MIT License\n'],
|
||||
['THIRD_PARTY_NOTICES.md', '# Third-party notices\n'],
|
||||
['package-lock.json', '{"lockfileVersion":3}\n'],
|
||||
['package.json', '{"name":"sidecar-tsconfig-fixture","private":true}\n'],
|
||||
['packages/marketplace/marketplace.db', 'fixture database'],
|
||||
@@ -575,6 +587,10 @@ describe('Tauri Production Configuration', () => {
|
||||
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);
|
||||
// UF-059: the license and the notices ship next to service.js.
|
||||
for (const name of ['LICENSE', 'THIRD_PARTY_NOTICES.md']) {
|
||||
expect(fs.readFileSync(path.join(resourcesRoot, name), 'utf8')).toBe(trackedFiles.get(name));
|
||||
}
|
||||
|
||||
fs.writeFileSync(marketplacePath, 'dirty worktree database');
|
||||
const dirtyMarketplaceResult = runResult(
|
||||
|
||||
Reference in New Issue
Block a user