mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-02 01:29:58 +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>
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
// One-shot CDP injector for renderer JS during Phase 6 E2E.
|
|
// Usage:
|
|
// node cdp-eval.mjs eval <expression-file>
|
|
// node cdp-eval.mjs screenshot <out-png-path>
|
|
// Connects to Electron renderer at port 9222, runs Runtime.evaluate or Page.captureScreenshot.
|
|
|
|
import WebSocket from 'ws';
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
|
|
const PORT = 9222;
|
|
const cmd = process.argv[2];
|
|
const arg = process.argv[3];
|
|
if (!cmd || !arg) {
|
|
console.error('usage: cdp-eval.mjs eval <expr.js> | screenshot <out.png>');
|
|
process.exit(2);
|
|
}
|
|
|
|
async function main() {
|
|
const list = await fetch(`http://127.0.0.1:${PORT}/json/list`).then(r => r.json());
|
|
const target = list.find(t => t.type === 'page' && t.url.startsWith('http://localhost:5173'));
|
|
if (!target) { console.error('renderer page target not found'); process.exit(3); }
|
|
const ws = new WebSocket(target.webSocketDebuggerUrl);
|
|
ws.on('error', (e) => { console.error('ws error', e.message); process.exit(4); });
|
|
setTimeout(() => { console.error('timeout'); process.exit(5); }, 60000);
|
|
|
|
await new Promise(res => ws.on('open', res));
|
|
|
|
if (cmd === 'eval') {
|
|
const expression = readFileSync(arg, 'utf8');
|
|
ws.send(JSON.stringify({
|
|
id: 1,
|
|
method: 'Runtime.evaluate',
|
|
params: { expression, awaitPromise: true, returnByValue: true, userGesture: true },
|
|
}));
|
|
ws.on('message', (raw) => {
|
|
const m = JSON.parse(raw.toString());
|
|
if (m.id === 1) {
|
|
console.log(JSON.stringify(m.result, null, 2));
|
|
ws.close(); process.exit(0);
|
|
}
|
|
});
|
|
} else if (cmd === 'screenshot') {
|
|
ws.send(JSON.stringify({ id: 1, method: 'Page.captureScreenshot', params: { format: 'png' } }));
|
|
ws.on('message', (raw) => {
|
|
const m = JSON.parse(raw.toString());
|
|
if (m.id === 1) {
|
|
if (m.error) { console.error('cdp error', m.error); process.exit(6); }
|
|
const buf = Buffer.from(m.result.data, 'base64');
|
|
writeFileSync(arg, buf);
|
|
console.log('screenshot saved:', arg, 'bytes', buf.length);
|
|
ws.close(); process.exit(0);
|
|
}
|
|
});
|
|
} else {
|
|
console.error('unknown cmd', cmd); process.exit(2);
|
|
}
|
|
}
|
|
main().catch(e => { console.error(e); process.exit(1); });
|