mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-04 04:40:48 +08:00
Address the open review findings on the Host web client without changing how the desktop starts: the desktop no longer auto-discovers and joins a running Host (only an explicit CINDY_HOST_API does). - pairing: one-time pairing exchanges for a session cookie; the home page no longer issues credentials or embeds the API token; Host/Origin checks, session expiry closes event streams, logout clears cookies. - credentials/accounts: provider keys are scoped by account/provider/engine and never fall back to the gateway key; model catalog cache is isolated per account; logout reuses the desktop saved-account tombstone policy; macOS and Windows credentials go through a private Electron safeStorage helper. - execution: input queue claims its slot before async preparation, keeps input on failure, stops cleanly while preserving streamed output, pauses on save failure, and deleting a task stops and clears it; SDK session context is restored after refresh and Host restart. - web shim: unsupported actions fail instead of reporting success. - desktop explicit Host mode: auth, interaction and input-queue events reach the existing channels; shared storage cores (project aliases, recent workdirs, ghost snapshot worker) are used by both desktop and Host. - CI: Host regression matrix on macOS, Windows and Linux; fix the task tag migration test to use the new migration config. Out of scope here: a windowless Electron helper and custom MCP storage extraction. Simulated OS tests do not replace real keychain/DPAPI or three-platform validation; see docs/host/pr-9246-completion.md. Assisted-by: Cindy (https://cindy.app) Signed-off-by: Dash <125997726+dashhuang@users.noreply.github.com>
97 lines
3.2 KiB
JavaScript
Executable File
97 lines
3.2 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Run the desktop against a cindy-host.
|
|
*
|
|
* This explicit developer entry reads host-endpoint.json and sets CINDY_HOST_API
|
|
* for its desktop child. Normal desktop startup does not discover a host.
|
|
* The wrapper starts a host when needed and reuses an existing one as-is.
|
|
*/
|
|
import { spawn } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { resolveHostDataDir } from '../apps/host/src/profile-path.mjs';
|
|
|
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const userDataDir = resolveHostDataDir();
|
|
const endpointFile = path.join(userDataDir, 'host-endpoint.json');
|
|
|
|
function runningEndpoint() {
|
|
try {
|
|
const parsed = JSON.parse(fs.readFileSync(endpointFile, 'utf-8'));
|
|
if (typeof parsed?.pid !== 'number' || typeof parsed?.baseUrl !== 'string') return null;
|
|
process.kill(parsed.pid, 0);
|
|
return parsed;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function waitForEndpoint(timeoutMs) {
|
|
const deadline = Date.now() + timeoutMs;
|
|
while (Date.now() < deadline) {
|
|
const endpoint = runningEndpoint();
|
|
if (endpoint) return endpoint;
|
|
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* The host serves the real renderer bundle, and a desktop build wipes it. Build
|
|
* it first so `pnpm dev:host` never serves a 404 to the browser client.
|
|
*/
|
|
async function ensureRendererBundle() {
|
|
const entry = path.join(repoRoot, 'apps/desktop/.vite/renderer/main_window/index.html');
|
|
if (fs.existsSync(entry)) return;
|
|
console.log('[dev:host] building the renderer bundle');
|
|
const build = spawn(process.execPath, [process.env.npm_execpath, '--filter', 'desktop', 'exec', 'vite', 'build', '--config', 'vite.renderer.config.ts'], {
|
|
cwd: repoRoot,
|
|
stdio: 'inherit',
|
|
});
|
|
const code = await new Promise((resolve) => build.on('exit', resolve));
|
|
if (code !== 0) {
|
|
console.error('[dev:host] renderer build failed');
|
|
process.exit(code ?? 1);
|
|
}
|
|
}
|
|
|
|
let host = null;
|
|
await ensureRendererBundle();
|
|
if (!runningEndpoint()) {
|
|
console.log(`[dev:host] starting cindy-host for ${userDataDir}`);
|
|
host = spawn(
|
|
process.execPath,
|
|
['--import', 'tsx', '--import', './apps/host/src/loaders/register-raw.mjs', 'apps/host/src/main.ts'],
|
|
{
|
|
cwd: repoRoot,
|
|
stdio: 'inherit',
|
|
env: { ...process.env, CINDY_HOST_DATA_DIR: userDataDir },
|
|
},
|
|
);
|
|
const endpoint = await waitForEndpoint(15_000);
|
|
if (!endpoint) {
|
|
console.error('[dev:host] cindy-host did not publish an endpoint; stopping');
|
|
host.kill('SIGTERM');
|
|
process.exit(1);
|
|
}
|
|
console.log(`[dev:host] cindy-host ready at ${endpoint.baseUrl}`);
|
|
}
|
|
|
|
const desktop = spawn(process.execPath, [process.env.npm_execpath, '--filter', 'desktop', 'dev', ...process.argv.slice(2)], {
|
|
cwd: repoRoot,
|
|
stdio: 'inherit',
|
|
env: { ...process.env, XDT_USER_DATA_DIR: userDataDir, CINDY_HOST_API: runningEndpoint().baseUrl },
|
|
});
|
|
|
|
const shutdown = (signal) => {
|
|
host?.kill(signal);
|
|
};
|
|
process.on('SIGINT', () => shutdown('SIGINT'));
|
|
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
|
|
desktop.on('exit', (code) => {
|
|
shutdown('SIGTERM');
|
|
process.exit(code ?? 0);
|
|
});
|