mirror of
https://github.com/makecindy/cindy.git
synced 2026-12-07 04:18:07 +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>
109 lines
3.9 KiB
JavaScript
109 lines
3.9 KiB
JavaScript
// Compiles apps/desktop/help-knowledge/*.md into a generated TS module that the
|
|
// main process imports (main is Vite-bundled and can't read loose .md at runtime).
|
|
// Run after editing any help doc: pnpm gen:help-kb (commit the generated file)
|
|
// CI drift check (regenerate + compare, no write): pnpm gen:help-kb:check
|
|
import { readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
import { dirname, join, resolve } from 'node:path';
|
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
import process from 'node:process';
|
|
import matter from 'gray-matter';
|
|
|
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
const KB_DIR = resolve(here, '../help-knowledge');
|
|
const OUT = resolve(here, '../src/main/maker-ipc/helpKnowledge.generated.ts');
|
|
// Must stay in sync with HelpTabId in src/shared/helpTypes.ts.
|
|
const ALLOWED_TABS = new Set([
|
|
'general',
|
|
'personalization',
|
|
'api-keys',
|
|
'providers',
|
|
'voice-input',
|
|
'import',
|
|
'connections',
|
|
'im-bot',
|
|
'about',
|
|
'ghosts',
|
|
'remote-control',
|
|
]);
|
|
|
|
function fail(msg) {
|
|
console.error(`[gen-help-kb] ${msg}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
/**
|
|
* Read + validate help-knowledge/*.md and render the generated TS module.
|
|
* Pure (no write) so both the writer (CLI) and the drift guard can share it.
|
|
* Validation failures hard-exit (used by both paths).
|
|
*/
|
|
export function renderHelpKnowledgeModule() {
|
|
const files = readdirSync(KB_DIR).filter((f) => f.endsWith('.md')).sort();
|
|
if (files.length === 0) fail(`no .md files found in ${KB_DIR}`);
|
|
|
|
const seen = new Set();
|
|
const docs = [];
|
|
for (const file of files) {
|
|
const { data, content } = matter(readFileSync(join(KB_DIR, file), 'utf8'));
|
|
const id = String(data.id ?? '').trim();
|
|
const title = String(data.title ?? '').trim();
|
|
const summary = String(data.summary ?? '').trim();
|
|
const tab = data.tab === undefined ? undefined : String(data.tab).trim();
|
|
// Normalize EOL so generated output is deterministic regardless of the
|
|
// checkout's line endings (Windows autocrlf would otherwise embed \r\n).
|
|
const body = content.replace(/\r\n/g, '\n').trim();
|
|
if (!id) fail(`${file}: missing 'id'`);
|
|
if (!/^[a-z0-9-]+$/.test(id)) fail(`${file}: id '${id}' must be kebab-case [a-z0-9-]`);
|
|
if (seen.has(id)) fail(`${file}: duplicate id '${id}'`);
|
|
if (!title) fail(`${file}: missing 'title'`);
|
|
if (!summary) fail(`${file}: missing 'summary'`);
|
|
if (tab !== undefined && !ALLOWED_TABS.has(tab)) {
|
|
fail(`${file}: tab '${tab}' not in [${[...ALLOWED_TABS].join(', ')}]`);
|
|
}
|
|
if (!body) fail(`${file}: empty body`);
|
|
seen.add(id);
|
|
docs.push({ id, title, summary, tab, content: body });
|
|
}
|
|
|
|
docs.sort((a, b) => a.id.localeCompare(b.id));
|
|
|
|
const entries = docs
|
|
.map((d) => {
|
|
const lines = [
|
|
' {',
|
|
` id: ${JSON.stringify(d.id)},`,
|
|
` title: ${JSON.stringify(d.title)},`,
|
|
` summary: ${JSON.stringify(d.summary)},`,
|
|
];
|
|
if (d.tab !== undefined) lines.push(` tab: ${JSON.stringify(d.tab)},`);
|
|
lines.push(` content: ${JSON.stringify(d.content)},`, ' },');
|
|
return lines.join('\n');
|
|
})
|
|
.join('\n');
|
|
|
|
const content = `// AUTO-GENERATED by scripts/gen-help-kb.mjs — do not edit by hand.
|
|
// Source: apps/desktop/help-knowledge/*.md · Regenerate: pnpm gen:help-kb
|
|
import type { HelpTabId } from '../../shared/helpTypes.js';
|
|
|
|
export interface HelpKnowledgeDoc {
|
|
id: string;
|
|
title: string;
|
|
summary: string;
|
|
tab?: HelpTabId;
|
|
content: string;
|
|
}
|
|
|
|
export const HELP_KNOWLEDGE: HelpKnowledgeDoc[] = [
|
|
${entries}
|
|
];
|
|
`;
|
|
|
|
return { outPath: OUT, content, count: docs.length };
|
|
}
|
|
|
|
// CLI: write the generated file when run directly (not when imported by the guard).
|
|
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
const { outPath, content, count } = renderHelpKnowledgeModule();
|
|
writeFileSync(outPath, content, 'utf8');
|
|
console.log(`[gen-help-kb] wrote ${count} docs -> ${outPath}`);
|
|
}
|