mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-03 23:22:14 +08:00
Cindy 是心动网络 (X.D. Network Inc.) 的跨端 AI Agent 客户端。 本次提交包含 Desktop(Electron)、Mobile(Expo)及全部共享 packages 的完整源码,以 Apache-2.0 协议开源。 This is the first public release of Cindy, X.D. Network's cross-platform AI agent client: the Electron desktop app, the Expo mobile app, and all shared workspace packages, licensed under Apache-2.0. - 许可与合规:根 LICENSE(Apache-2.0)+ NOTICE;第三方组件归属声明与 SPDX SBOM 收口在 docs/legal/notices/,由 pnpm licenses:generate 生成。 - 社区文件:README / CONTRIBUTING / CODE_OF_CONDUCT / SECURITY / SUPPORT 中英双语;issue / PR 模板与 CI workflow 在 .github/。 - 协议层以公开 submodule 引入:github.com/makecindy/cindy-protocol。 - 提交前已通过仓库门禁:全量 pnpm test:unit 与涉及 package 的 typecheck。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
104 lines
3.4 KiB
JavaScript
104 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Internal TTY-preserving runner for restart-desktop-remote.mjs.
|
|
* Electron writes the ready status; this runner records an early pnpm/Forge exit.
|
|
*/
|
|
import { spawn } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
const mode = process.argv[2];
|
|
if (mode !== 'remote' && mode !== 'local') {
|
|
console.error(`desktop-dev-runner: mode must be remote or local, received ${mode ?? '(empty)'}`);
|
|
process.exit(2);
|
|
}
|
|
|
|
const devScript = mode === 'local' ? 'dev:desktop' : 'dev:desktop:remote';
|
|
const pnpmExecPath = process.env.npm_execpath;
|
|
const hasPnpmExecPath = Boolean(
|
|
pnpmExecPath && /pnpm/i.test(path.basename(pnpmExecPath)) && fs.existsSync(pnpmExecPath),
|
|
);
|
|
// The restart pipeline opens a fresh Windows cmd.exe. That environment does
|
|
// not always carry npm_execpath, and Node cannot spawn a command shim with the
|
|
// default shell:false behavior. Let cmd.exe resolve the extension-neutral
|
|
// command through PATH/PATHEXT so both pnpm.cmd and standalone pnpm.exe
|
|
// installations work.
|
|
const command = hasPnpmExecPath ? process.execPath : 'pnpm';
|
|
const args = hasPnpmExecPath
|
|
? [pnpmExecPath, devScript]
|
|
: [devScript];
|
|
|
|
const child = spawn(command, args, {
|
|
cwd: rootDir,
|
|
env: { ...process.env, COREPACK_ENABLE_AUTO_PIN: '0' },
|
|
stdio: 'inherit',
|
|
windowsHide: false,
|
|
shell: process.platform === 'win32' && !hasPnpmExecPath,
|
|
});
|
|
|
|
child.once('error', (error) => {
|
|
writeFailedStatus({ exitCode: null, error: error.message });
|
|
console.error(`desktop-dev-runner: ${error.message}`);
|
|
process.exit(1);
|
|
});
|
|
|
|
child.once('exit', (code, signal) => {
|
|
const statusPath = process.env.XDT_DESKTOP_DEV_STARTUP_STATUS_FILE;
|
|
const existing = statusPath ? readStatus(statusPath) : null;
|
|
if (statusPath) {
|
|
if (existing?.state === 'ready' || existing?.state === 'abandoned' || !existing) {
|
|
fs.rmSync(statusPath, { force: true });
|
|
} else if (existing.state !== 'failed') {
|
|
writeFailedStatus({ exitCode: code, signal });
|
|
}
|
|
}
|
|
|
|
if (signal && process.platform !== 'win32') {
|
|
process.kill(process.pid, signal);
|
|
return;
|
|
}
|
|
process.exit(code ?? 1);
|
|
});
|
|
|
|
function readStatus(statusPath) {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(statusPath, 'utf8'));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function writeFailedStatus(detail) {
|
|
const statusPath = process.env.XDT_DESKTOP_DEV_STARTUP_STATUS_FILE;
|
|
const state = statusPath ? readStatus(statusPath)?.state : null;
|
|
if (!statusPath || state === 'ready' || state === 'abandoned') return;
|
|
const errorMessage = detail.error ? ` Desktop dev command failed: ${detail.error}` : '';
|
|
writeStatus(statusPath, {
|
|
state: 'failed',
|
|
code: 'DEV_PROCESS_EXITED',
|
|
message: `The desktop dev process exited before the main window became ready.${errorMessage}`,
|
|
detail: {
|
|
rootDir,
|
|
command,
|
|
devScript,
|
|
...detail,
|
|
},
|
|
...detail,
|
|
pid: process.pid,
|
|
at: Date.now(),
|
|
});
|
|
}
|
|
|
|
function writeStatus(statusPath, status) {
|
|
const tempPath = `${statusPath}.${process.pid}.tmp`;
|
|
try {
|
|
fs.writeFileSync(tempPath, `${JSON.stringify(status)}\n`, { mode: 0o600 });
|
|
fs.renameSync(tempPath, statusPath);
|
|
} catch (error) {
|
|
fs.rmSync(tempPath, { force: true });
|
|
console.error(`desktop-dev-runner: failed to write startup status: ${error.message}`);
|
|
}
|
|
}
|