233 lines
9.4 KiB
TypeScript
233 lines
9.4 KiB
TypeScript
/**
|
||
* Embedded System Knowledge & Architectural Specifications
|
||
*
|
||
* This file contains static, read-only documentation and system contracts
|
||
* bundled directly into the standalone binary. It requires zero network access
|
||
* and performs zero disk writes.
|
||
*/
|
||
|
||
export interface DirectorySpec {
|
||
name: string;
|
||
category: "config" | "binary" | "skill" | "export" | "temp";
|
||
standardPath: string;
|
||
purpose: string;
|
||
accessMode: "read-write" | "executable" | "transient";
|
||
retention: "persistent" | "cache" | "ephemeral";
|
||
}
|
||
|
||
export interface SecurityPolicySpec {
|
||
topic: string;
|
||
guarantee: string;
|
||
enforcement: string;
|
||
}
|
||
|
||
export interface DomainCapabilitySpec {
|
||
domain: string;
|
||
summary: string;
|
||
primaryCommands: string[];
|
||
}
|
||
|
||
export const EMBEDDED_DIRECTORY_SPECS: DirectorySpec[] = [
|
||
{
|
||
name: "配置与状态根目录",
|
||
category: "config",
|
||
standardPath: "~/.config/seal-use",
|
||
purpose: "用户本地持久化配置根目录,存放企业连接元数据、会话缓存与全局状态。",
|
||
accessMode: "read-write",
|
||
retention: "persistent"
|
||
},
|
||
{
|
||
name: "企业配置文件目录",
|
||
category: "config",
|
||
standardPath: "~/.config/seal-use/enterprises",
|
||
purpose: "存放各已添加企业的配置 JSON 文件(如 xiezihao.json),存储企业域名、脱敏 Token、员工绑定关系等。",
|
||
accessMode: "read-write",
|
||
retention: "persistent"
|
||
},
|
||
{
|
||
name: "全局配置文件",
|
||
category: "config",
|
||
standardPath: "~/.config/seal-use/config.json",
|
||
purpose: "维护全局工作模式(stateful/stateless)、默认激活企业 defaultCorpId 以及 Lint 偏好。",
|
||
accessMode: "read-write",
|
||
retention: "persistent"
|
||
},
|
||
{
|
||
name: "会话凭据安全缓存",
|
||
category: "config",
|
||
standardPath: "~/.config/seal-use/seal_tokens.json",
|
||
purpose: "缓存已认证租户的 Bearer Token 与过期时间戳,避免高频调用上游 OAuth 换票接口。",
|
||
accessMode: "read-write",
|
||
retention: "cache"
|
||
},
|
||
{
|
||
name: "规则版本映射快照",
|
||
category: "config",
|
||
standardPath: "~/.config/seal-use/mappings",
|
||
purpose: "存储 corps sync-test 生成的生产与测试规则版本/编号对照映射快照,供 rules map 离线毫秒级速查。",
|
||
accessMode: "read-write",
|
||
retention: "persistent"
|
||
},
|
||
{
|
||
name: "全局命令行程序",
|
||
category: "binary",
|
||
standardPath: "/opt/homebrew/bin/seal-use",
|
||
purpose: "macOS / Linux 全局独立单文件二进制程序;旧版 seal-home 命令仅保留解析兼容,不再新建全局别名。",
|
||
accessMode: "executable",
|
||
retention: "persistent"
|
||
},
|
||
{
|
||
name: "AI Agent 技能主目录",
|
||
category: "skill",
|
||
standardPath: "~/.agents/skills/seal-use",
|
||
purpose: "面向 Antigravity、Codex 等 AI 智能体的标准技能目录,包含 SKILL.md、参考文档与操作规程。",
|
||
accessMode: "read-write",
|
||
retention: "persistent"
|
||
},
|
||
{
|
||
name: "报表默认导出目录",
|
||
category: "export",
|
||
standardPath: "~/Downloads",
|
||
purpose: "执行 approval-runs export 等大盘报表命令且未指定 --out 时,默认写入的 Excel 文件路径。",
|
||
accessMode: "read-write",
|
||
retention: "persistent"
|
||
},
|
||
{
|
||
name: "系统隔离临时目录",
|
||
category: "temp",
|
||
standardPath: "/tmp 或 /var/folders/.../T",
|
||
purpose: "自动化测试(bun test)生成的隔离工作副本,执行完毕后通过 afterEach 钩子彻底删除,零残留。",
|
||
accessMode: "transient",
|
||
retention: "ephemeral"
|
||
}
|
||
];
|
||
|
||
export const EMBEDDED_SECURITY_POLICIES: SecurityPolicySpec[] = [
|
||
{
|
||
topic: "敏感凭据脱敏保护",
|
||
guarantee: "appSecurity、password 等高危密钥永不回显在 stdout,Session Token 采用掩码处理(如 5oUL...Y%3D)。",
|
||
enforcement: "CLI 所有展示接口(corps get、corps list、probe 等)均经 formatSafeSourceDetail 脱敏过滤。"
|
||
},
|
||
{
|
||
topic: "正式环境与测试环境严格隔离",
|
||
guarantee: "正式企业与测试企业必须严格 1 对 1 下挂,禁止多层级级联绑定;环境标记需显式 --confirm 确认。",
|
||
enforcement: "corps bind-test 与 mark 强制要求 --confirm,缺少时阻断并返回退出码 10(confirmationRequired)。"
|
||
},
|
||
{
|
||
topic: "跨环境规则同步安全基线",
|
||
guarantee: "corps sync-test 仅将正式企业偏好与规则覆盖同步至测试企业并自动发布,正式企业规则严格维持草稿态永不发布。",
|
||
enforcement: "规则同步流水线由 sync-test 独占受控,正式环境端仅执行拉取草稿读取操作,零发版变更。"
|
||
},
|
||
{
|
||
topic: "只读诊断无副作用原则",
|
||
guarantee: "doctor、search、get、list、context、probe 等命令为严格只读操作,不修改用户本地文件系统,零写入污染。",
|
||
enforcement: "核心领域函数严格分离 Mutation 操作与 Query 操作,Query 路径杜绝写文件与环境篡改。"
|
||
}
|
||
];
|
||
|
||
export const EMBEDDED_DOMAIN_CAPABILITIES: DomainCapabilitySpec[] = [
|
||
{
|
||
domain: "corps (企业管理)",
|
||
summary: "多租户接入、智能软搜索、富属性查看、环境标记、测试绑定与配置规则同步",
|
||
primaryCommands: ["corps list", "corps search <query>", "corps get <corpId>", "corps mark", "corps bind-test", "corps sync-test"]
|
||
},
|
||
{
|
||
domain: "approval-runs (审核大盘)",
|
||
summary: "AI 审核单据检索、统计分析、引证规则查看、附件全链路追踪、Excel 报表导出、单据直达链接与免登",
|
||
primaryCommands: ["approval-runs list", "approval-runs stats", "approval-runs get", "approval-runs export", "approval-runs link"]
|
||
},
|
||
{
|
||
domain: "rules (规则治理)",
|
||
summary: "审核规则拉取、本地 Lint 质量检查、增量差量推送、离线版本与编号对照映射速查",
|
||
primaryCommands: ["rules pull", "rules lint", "rules push", "rules map", "rules count"]
|
||
},
|
||
{
|
||
domain: "preference (决策偏好)",
|
||
summary: "AI 审核偏好读取与更新、全局与分品类思考深度策略(medium/high)配置",
|
||
primaryCommands: ["preference get", "preference decision update", "preference thinking-depth set"]
|
||
},
|
||
{
|
||
domain: "simulation (模拟演练)",
|
||
summary: "合思单据指定、材料包导入、飞书/泛微三方审批定义演练、批次轮询等待与数据清理",
|
||
primaryCommands: ["simulation create", "simulation status", "simulation wait", "simulation clean"]
|
||
},
|
||
{
|
||
domain: "webhook (通道与重放)",
|
||
summary: "Webhook 回调通道配置、材料包校验推送、线上单据向 Webhook 通道测试重放",
|
||
primaryCommands: ["webhook list", "webhook add", "webhook replay", "webhook material-pack push"]
|
||
},
|
||
{
|
||
domain: "deploy (费控集成)",
|
||
summary: "Seal AI 智能审核能力发布到合思费控企业、对接要求检测与配置同步",
|
||
primaryCommands: ["deploy hosecloud requirements", "deploy hosecloud status", "deploy hosecloud sync"]
|
||
},
|
||
{
|
||
domain: "doctor (系统诊断)",
|
||
summary: "整机环境健康自检、目录全景体检看板、内置架构与规范白皮书离线查阅",
|
||
primaryCommands: ["doctor", "doctor guide", "doctor paths"]
|
||
}
|
||
];
|
||
|
||
/**
|
||
* Generates the full formatted embedded documentation in Markdown.
|
||
*/
|
||
export function getEmbeddedGuideMarkdown(): string {
|
||
return `# Seal Use 系统架构与运行规范白皮书
|
||
|
||
> 本文档由 \`seal-use\` 单文件二进制程序内嵌提供,纯内存只读,未向用户电脑写入任何临时文件。
|
||
|
||
---
|
||
|
||
## 1. 系统定位与设计哲学
|
||
|
||
\`seal-use\` 是合思与 Seal AI 体系的企业级智能审核、规则治理与模拟演练 CLI 工具包,兼具人类工程师命令行使用与 AI Agent Harness 自动化集成能力。
|
||
|
||
### 核心交互契约
|
||
- **机器通道 (\`stdout\`)**:所有命令默认在标准输出返回干净、严格类型化的 JSON 载荷,供自动化脚本及 AI Agent 解析。
|
||
- **指导与诊断通道 (\`stderr\`)**:标准错误专用于输出运行状态、网络探测日志、自愈指引以及显式的下一步动作建议(如 \`👉 Next action: seal-use ...\`)。
|
||
- **退出码契约**:成功为 \`0\`,参数校验失败、未确认拦截或上游 API 报错均赋予非零退出码(如 \`1\`、\`2\`、\`10\`),杜绝盲目吞错。
|
||
|
||
---
|
||
|
||
## 2. 系统目录全景规范
|
||
|
||
\`seal-use\` 在用户计算机上的所有文件访问严格收敛于以下明确定义的目录中:
|
||
|
||
| 目录名称 | 类别 | 规范路径 | 作用与生命周期 |
|
||
| :--- | :--- | :--- | :--- |
|
||
${EMBEDDED_DIRECTORY_SPECS.map(
|
||
(s) => `| **${s.name}** | \`${s.category}\` | \`${s.standardPath}\` | ${s.purpose} (${s.retention}) |`
|
||
).join("\n")}
|
||
|
||
---
|
||
|
||
## 3. 安全与数据隐私保证
|
||
|
||
${EMBEDDED_SECURITY_POLICIES.map(
|
||
(p, idx) => `### 3.${idx + 1} ${p.topic}
|
||
- **安全承诺**:${p.guarantee}
|
||
- **实现约束**:${p.enforcement}
|
||
`
|
||
).join("\n")}
|
||
|
||
---
|
||
|
||
## 4. 业务域能力图谱
|
||
|
||
${EMBEDDED_DOMAIN_CAPABILITIES.map(
|
||
(c) => `### \`seal-use ${c.domain}\`
|
||
* **能力定位**:${c.summary}
|
||
* **核心命令**:${c.primaryCommands.map((cmd) => `\`seal-use ${cmd}\``).join("、")}
|
||
`
|
||
).join("\n")}
|
||
|
||
---
|
||
|
||
## 5. 快速排错与健康诊断指引
|
||
|
||
- **环境自检**:运行 \`seal-use doctor\`,一键检查当前运行时版本、本地目录健康度、企业资产接入数量以及守护服务状态。
|
||
- **查看企业配置源文件**:运行 \`seal-use corps get <corpId>\`,可直接查看指定企业的本地 JSON 存储绝对路径。
|
||
- **查阅完整操作手册**:运行 \`seal-use doctor guide\` 随时在离线状态下查看本文档。
|
||
`;
|
||
}
|