diff --git a/docs/cn/contributing/ai-workflow.md b/docs/cn/contributing/ai-workflow.md new file mode 100644 index 00000000..3d4b9a79 --- /dev/null +++ b/docs/cn/contributing/ai-workflow.md @@ -0,0 +1,73 @@ +--- +layout: doc +title: AI 协作工作流 +--- + +# AI 协作工作流 + +本文说明 ChatLab 如何维护开发代理指令与对外技能。日常入口是根目录 `AGENTS.md`;只有维护技能、调整工作流或处理复杂审查时才需要阅读本文。 + +## 指令放在哪里 + +| 位置 | 用途 | 维护原则 | +| --- | --- | --- | +| `AGENTS.md` | 跨任务稳定约定、项目入口、验证命令 | 保持精简,只保留会影响决策的信息 | +| `docs/cn/contributing/` | 公开开发细则 | 按任务引用,公开 PR 可独立理解 | +| `skills/*/SKILL.md` | 供外部 Agent 使用的分析、导入、转换流程 | 每个技能一个职责,中英文独立分发并保持语义一致 | +| `skills/*/references/`、`scripts/` | 格式契约与严格验证器 | 按需读取;确定性校验交给脚本 | +| `.github/workflows/` | CI、构建、发布及产物清理 | 保留真实质量门禁,不承载模型提示词 | +| 可选的本地规则和私有技能 | 个人协作偏好与维护任务 | 不覆盖用户当前意图,不作为公开贡献前提 | + +`skills/` 中的文件是产品分发资源,不会因存在于仓库就自动成为 Codex 开发技能。需要本地自动发现时,按宿主支持的技能安装方式配置;不要为了开发本项目而自动加载聊天分析技能。Codex 的仓库技能发现目录是 `.agents/skills`,正文按需加载。[官方技能文档](https://learn.chatgpt.com/docs/build-skills) + +## 执行与授权 + +从用户目标、输入和完成条件出发,直接完成已授权的工作。复杂任务可以先列简短计划;计划不构成新的审批门槛。只有会影响正确性、数据归属或授权范围的缺失信息才需要澄清。 + +已明确要求“转换并导入”时,验证成功后继续导入;仅要求预览时只返回计划。安装依赖、提交、推送和发布依各自授权执行。工具缺失时完成可做的工作,并准确说明未完成的验证或操作。 + +一次性审批要求不能散落在技能描述、默认提示词和正文中互相冲突。需要停下时说明具体规则及缺少的授权;不要求每次回复都进入交互弹窗,也不以固定口令作为任务完成条件。 + +## 技能维护 + +- `description` 只写任务和触发边界;避免平台长列表、安装说明和重复的适用场景。 +- 正文保留输入、输出、关键决策、数据保护和完成条件。按风险决定步骤细度,不给普通任务强加固定追问次数、报告模板或全量预检。 +- `agents/openai.yaml` 的默认提示词与正文保持一致。保留现有调用策略,不能用描述暗中扩大用户授权。 +- 长格式规范放在 `references/`;不得删掉转换不丢消息、导入 dry-run、工具权限等实质约束。 +- 运行时命令、工具名、配置字段以代码或 CLI 当前契约为准;不在技能里长期复制完整清单。 +- 已有严格验证器优先复用。修改生成的验证器时先修改其构建源,不手工维护两份 bundle。 + +## 审查与验证 + +审查反馈先核对相关函数、调用方、被调用方、相邻测试及适用文档。报告说明当前行为和判断依据;问题成立时,补充可达触发、用户影响、建议修复与验证。依赖行为查当前官方文档、源码或类型定义。 + +异步、并发、缓存、性能和资源问题需要完整因果链。若前置故障和后续有害操作共享故障域,解释为什么前者失败时后者仍能成功。严重度同时考虑触发概率、影响和恢复方式;没有现实场景或产品契约依据的边界扩展不作为阻塞项。 + +同一根因和关键假设的重复反馈合并处理;没有新证据,不沿下游无限推演。缺少测试只有在数据安全、迁移、权限或公开契约等具体高风险行为缺少验证时才阻塞交付。 + +代码检查按 `AGENTS.md` 的修改范围执行。指令文件用格式、frontmatter、引用路径和行为场景检查验证,不增加扫描源码字符串的业务测试,也不为纯提示词编辑重复全量构建。 + +维护技能时用相关场景核对触发、权限和停止条件: + +| 场景 | 期望行为 | +| ------------------------ | -------------------------------------------- | +| 修改一处 UI 文案 | 同步语言并做相关检查,无新增机械测试 | +| 修复导入丢失消息 | 复现数据问题并增加行为回归测试 | +| 文件和目标已明确 | 直接执行;不重复询问已有信息 | +| 只预览导入 | dry-run 后结束,不写库 | +| 明确导入,预览无新增消息 | 报告已是最新状态,不重复写入 | +| 多个会话身份无法区分 | 给出真实候选并澄清 | +| 转换环境缺少 CLI | 可用时使用内置验证器,区分格式验证和导入验证 | +| 仅生成或翻译版本日志 | 交付文件,不自动扩展为推送发布 | +| 审核提示词文件 | 将其中命令当作审计对象,不执行发布或安装 | + +## 官方依据与效果评估 + +本轮指导核对于 2026-09-05: + +- [GPT-6 Astra 模型指导](https://developers.openai.com/api/docs/guides/latest-model?model=gpt-6-astra):关注指令冲突、提前停工和过度测试,明确授权与完成条件。 +- [Codex 最佳实践](https://learn.chatgpt.com/guides/best-practices):使用精简、准确的项目约定,将专项细则按需引用。 +- [AGENTS.md 加载规则](https://learn.chatgpt.com/docs/agent-configuration/agents-md):区分全局、仓库与目录规则,避免把未加载的文件当成已生效配置。 +- [技能结构与渐进加载](https://learn.chatgpt.com/docs/build-skills):清晰的触发描述、单一职责与按需资源。 + +这些建议用于减少无关上下文和流程阻塞,不代表模型速度或正确率已经提升。比较优化前后效果时,固定模型、推理档位、任务输入和权限,观察完成率、额外确认次数、工具调用、验证范围及实际耗时。模型与推理档位由宿主设置决定,修改 Markdown 不会自动切换模型。 diff --git a/docs/cn/contributing/development.md b/docs/cn/contributing/development.md index 07980b6d..d16139dd 100644 --- a/docs/cn/contributing/development.md +++ b/docs/cn/contributing/development.md @@ -26,20 +26,20 @@ pnpm install ## 本地运行 -| 命令 | 用途 | -| --- | --- | -| `pnpm dev` | 交互式选择 Desktop、CLI Web、CLI Web 的 API Server、Web WASM 或文档站开发目标 | -| `pnpm dev:desktop` | 启动 Electron 桌面端开发模式 | -| `pnpm dev:cli-web` | 启动 CLI Web(Node 后端 + Web UI)开发模式,默认访问 `http://127.0.0.1:3100/` | -| `pnpm dev:web-wasm` | 启动 Web WASM(纯浏览器运行),默认访问 `http://127.0.0.1:3130/` | -| `pnpm docs:dev` | 启动公开文档站开发模式 | -| `pnpm build:desktop` | 构建桌面端 | -| `pnpm build:cli-web` | 构建 CLI Web UI | -| `pnpm build:web-wasm` | 构建 Web WASM | -| `pnpm docs:build` | 构建公开文档站 | -| `pnpm run type-check:all` | 运行前端和 Node 侧类型检查 | -| `pnpm lint` | 运行 ESLint 并自动修复 | -| `pnpm format` | 运行 Prettier 格式化 | +| 命令 | 用途 | +| ------------------------- | ----------------------------------------------------------------------------- | +| `pnpm dev` | 交互式选择 Desktop、CLI Web、CLI Web 的 API Server、Web WASM 或文档站开发目标 | +| `pnpm dev:desktop` | 启动 Electron 桌面端开发模式 | +| `pnpm dev:cli-web` | 启动 CLI Web(Node 后端 + Web UI)开发模式,默认访问 `http://127.0.0.1:3100/` | +| `pnpm dev:web-wasm` | 启动 Web WASM(纯浏览器运行),默认访问 `http://127.0.0.1:3130/` | +| `pnpm docs:dev` | 启动公开文档站开发模式 | +| `pnpm build:desktop` | 构建桌面端 | +| `pnpm build:cli-web` | 构建 CLI Web UI | +| `pnpm build:web-wasm` | 构建 Web WASM | +| `pnpm docs:build` | 构建公开文档站 | +| `pnpm run type-check:all` | 运行前端和 Node 侧类型检查 | +| `pnpm lint` | 运行 ESLint 并自动修复 | +| `pnpm format` | 运行 Prettier 格式化 | 小范围改动优先对修改文件或相关子项目做定向检查;跨模块、发布或架构类改动再跑全量检查。 @@ -53,18 +53,18 @@ pnpm install ## 目录职责 -| 路径 | 职责 | -| --- | --- | -| `src/` | 共享前端应用代码,包含页面、组件、服务封装、状态和 i18n | -| `src/services/` | 前端访问 Electron、CLI Web API 和平台能力的服务层 | -| `apps/desktop/` | Electron 主进程、preload 和桌面端构建配置 | -| `apps/cli/` | CLI、HTTP API、CLI Web 运行时和导入命令 | -| `packages/core/` | 平台无关的核心数据模型、查询、导入和成员操作 | -| `packages/node-runtime/` | Node.js 运行时服务、数据库、AI、导出、缓存和迁移 | -| `packages/tools/` | 统一 AI 工具定义和数据访问适配 | -| `docs/` | 公开文档站源码 | -| `changelogs/` | 应用内和发布使用的多语言更新日志 | -| `.docs/` | 可选的个人或团队私有开发上下文,不是公开贡献的必需依赖 | +| 路径 | 职责 | +| ------------------------ | ------------------------------------------------------- | +| `src/` | 共享前端应用代码,包含页面、组件、服务封装、状态和 i18n | +| `src/services/` | 前端访问 Electron、CLI Web API 和平台能力的服务层 | +| `apps/desktop/` | Electron 主进程、preload 和桌面端构建配置 | +| `apps/cli/` | CLI、HTTP API、CLI Web 运行时和导入命令 | +| `packages/core/` | 平台无关的核心数据模型、查询、导入和成员操作 | +| `packages/node-runtime/` | Node.js 运行时服务、数据库、AI、导出、缓存和迁移 | +| `packages/tools/` | 统一 AI 工具定义和数据访问适配 | +| `docs/` | 公开文档站源码 | +| `changelogs/` | 应用内和发布使用的多语言更新日志 | +| `.docs/` | 可选的个人或团队私有开发上下文,不是公开贡献的必需依赖 | ## 架构边界 @@ -129,23 +129,23 @@ CHATLAB_ALLOW_INCOMPATIBLE_DATA_DIR=1 ## 常见改动入口 -| 想改什么 | 先看哪里 | -| --- | --- | -| 前端页面和组件 | `src/pages/`、`src/components/` | -| 图表分析 | `src/components/analysis/`、`src/components/charts/` | -| 数据、消息、会话 API 调用 | `src/services/` | -| Electron 主进程 | `apps/desktop/main/`、`apps/desktop/preload/` | -| CLI 和 Web API | `apps/cli/` | -| 共享业务逻辑 | `packages/node-runtime/src/services/`、`packages/core/` | -| AI 工具和 Agent | `packages/tools/`、`packages/node-runtime/src/ai/`、`src/services/ai*` | -| 导入解析 | `packages/core/`、`apps/cli/src/import/`、`src/services/import/` | -| 文档站 | `docs/`、`docs/.vitepress/config.mts` | -| 更新日志 | `changelogs/` | +| 想改什么 | 先看哪里 | +| ------------------------- | ---------------------------------------------------------------------- | +| 前端页面和组件 | `src/pages/`、`src/components/` | +| 图表分析 | `src/components/analysis/`、`src/components/charts/` | +| 数据、消息、会话 API 调用 | `src/services/` | +| Electron 主进程 | `apps/desktop/main/`、`apps/desktop/preload/` | +| CLI 和 Web API | `apps/cli/` | +| 共享业务逻辑 | `packages/node-runtime/src/services/`、`packages/core/` | +| AI 工具和 Agent | `packages/tools/`、`packages/node-runtime/src/ai/`、`src/services/ai*` | +| 导入解析 | `packages/core/`、`apps/cli/src/import/`、`src/services/import/` | +| 文档站 | `docs/`、`docs/.vitepress/config.mts` | +| 更新日志 | `changelogs/` | ## 测试与检查 - 修改 TypeScript 或 Vue 代码后,至少运行相关类型检查。 -- 修改公开文档后,运行 `pnpm docs:build` 或对修改的 Markdown/配置文件运行格式化检查。 +- 修改公开文档或 VitePress 配置后,运行 `pnpm docs:build`,并格式化修改文件;`docs/**/*.md` 被 Prettier 默认忽略,定向格式化时使用 `pnpm exec prettier --write --ignore-path .gitignore `。 - 修改跨平台共享逻辑后,确认 Electron 和 CLI Web 两端入口没有产生行为分歧。 - 修复会影响用户数据、业务逻辑、异步任务、缓存状态、跨端共享 service、公开 API 契约、导入解析、去重逻辑、权限认证、AI 工具 allowlist、配置/API key 迁移或数据库 schema/迁移的行为 bug 时,必须优先补能失败的回归测试。 - 只改 UI 文案、i18n key/翻译、样式、类型声明、日志、注释、无行为变化的小重构,或修复低风险展示细节时,可以不新增测试,但仍需运行相关类型检查、lint 和 format;不要为了低价值页面文案或源码字符串扫描新增脆弱测试。 @@ -163,6 +163,8 @@ CHATLAB_ALLOW_INCOMPATIBLE_DATA_DIR=1 AI 可以帮助阅读代码、生成补丁和补测试,但公开 PR 必须让 reviewer 能在公开上下文中理解。建议让 AI 先读 `AGENTS.md` 和本页;如果你维护了自己的 `.docs/`,可以把它作为额外上下文,但不要让变更说明、测试理由或设计依据只存在于私有 `.docs/` 中。 +维护代理指令、技能或审查流程时,参见 [AI 协作工作流](./ai-workflow.md)。日常任务按修改范围完成验证,不需要加载所有技能或反复执行全量检查。 + ## PR 与提交规范 - 明显的 Bug 修复可以直接提交 PR。 diff --git a/skills/chatlab-analyze-cn/SKILL.md b/skills/chatlab-analyze-cn/SKILL.md index 5f33fe73..01726994 100644 --- a/skills/chatlab-analyze-cn/SKILL.md +++ b/skills/chatlab-analyze-cn/SKILL.md @@ -7,33 +7,20 @@ description: 通过 clb CLI 分析本地 ChatLab 聊天记录。当用户要求 通过只读 `clb` CLI 查询和分析已经导入 ChatLab 的聊天记录。 -## 适用场景 - -- 查找某段对话,或确认谁最先提到某件事。 -- 总结近期话题,或分析与某个人的聊天关系。 -- 比较成员活跃度、关键词或回复规律。 - -如果要导入新的聊天导出文件,请使用 `chatlab-import-cn`。 - -安装命令: - -```bash -npx skills add ChatLab/ChatLab --skill chatlab-analyze-cn -g -``` +导入新文件时,可用则使用 `chatlab-import-cn`;否则参考 `clb import --help`,在写入前预览准确的导入计划。 ## 工作流程 ### 1. 准备查询 -检查 CLI、读取当前命令契约并列出会话: +每个任务读取一次当前命令契约;只有目标尚未确定时才列出会话: ```bash -clb --help clb manifest clb sessions list --format json ``` -只有一个相关会话时直接使用;多个会话或成员都可能匹配时,让用户从返回的候选项中选择。 +复用对话中已确定的会话、成员和时间范围。仅在候选项和上下文仍无法消除关键歧义时询问。CLI 不可用时说明缺少的能力;安装需要授权。 ### 2. 从专用命令开始 @@ -56,7 +43,7 @@ clb messages context --id 1021 --session --window 10 --format agent clb stats keywords --session --member --last 90d --top 20 --format json ``` -当 `meta.hasMore` 为 true 时,保持相同查询条件并使用 `--cursor ` 继续。通过数量和 Token 参数只获取回答问题所需的上下文。 +仍需证据且 `meta.hasMore` 为 true 时,保持相同查询条件并使用 `--cursor ` 继续。问题已回答即可停止;查询不完整时说明覆盖范围,不把单页当成全集。 ### 4. 最后才使用 SQL @@ -69,9 +56,9 @@ clb sql "SELECT COUNT(*) AS n FROM message" --session --format json ## 隐私与回答 -- 绝不使用 `--raw`、修改 ChatLab 数据、导入文件、更改配置或启动长期运行的服务。 +- 查询保持隐私预处理启用,不使用 `--raw` 或修改数据、配置。另有明确导入请求时按导入流程处理。 - 绝不泄露完整聊天记录。ChatLab 的安全输出会应用用户配置的隐私预处理。 -- 使用 `[#1021]`、`[#1021*]` 或 `[#1021-1024]` 等可用标记引用消息证据。 +- 用 `[#1021]`、`[#1021*]` 或 `[#1021-1024]` 引用证据;`messages context --id` 只接受单个 ID,合并范围只用于展示。 - 先直接回答,说明实际查询的会话和时间范围,再区分观察到的事实与解释。 - 分析关系时不要过度推断情绪意图。仅在修正方式明确时遵循 `error.hint`。 - 优先使用用户当前使用的中文变体回答,命令、参数、JSON 字段和证据标记保持原样。 diff --git a/skills/chatlab-analyze/SKILL.md b/skills/chatlab-analyze/SKILL.md index bed6bb56..394eaace 100644 --- a/skills/chatlab-analyze/SKILL.md +++ b/skills/chatlab-analyze/SKILL.md @@ -7,33 +7,20 @@ description: Analyze local ChatLab chat records through the clb CLI. Use when th Query and analyze records already imported into ChatLab through the read-only `clb` CLI. -## Good Fit - -- Find conversations or determine who mentioned something first. -- Summarize recent topics or inspect a named relationship. -- Compare member activity, keywords, or response patterns. - -For importing a new chat export, use `chatlab-import` instead. - -Install this skill with: - -```bash -npx skills add ChatLab/ChatLab --skill chatlab-analyze -g -``` +For importing a new chat export, use `chatlab-import` when available; otherwise follow `clb import --help` and preview the exact import before writing. ## Workflow ### 1. Prepare the Query -Check the CLI, load its current command contract, and list sessions: +Load the current command contract once per task. List sessions only when the target is not already known: ```bash -clb --help clb manifest clb sessions list --format json ``` -Use the only relevant session. If multiple sessions or members match the request, ask the user to choose from the returned candidates. +Reuse the session, member, and time range already identified in the conversation. Ask only when the returned candidates and context cannot resolve a material ambiguity. If the CLI is unavailable, report the missing capability; installation requires authorization. ### 2. Start with a Dedicated Command @@ -56,7 +43,7 @@ clb messages context --id 1021 --session --window 10 --format agent clb stats keywords --session --member --last 90d --top 20 --format json ``` -When `meta.hasMore` is true, continue with `--cursor ` and the same query conditions. Use limits and token controls to retrieve only the context needed. +When more evidence is needed and `meta.hasMore` is true, continue with `--cursor ` and the same query conditions. Stop when the question is answered; disclose any partial coverage instead of treating a page as the complete dataset. ### 4. Use SQL Only as a Fallback @@ -69,8 +56,8 @@ clb sql "SELECT COUNT(*) AS n FROM message" --session --format json ## Privacy and Answers -- Never use `--raw`, modify ChatLab data, import files, change config, or start long-running services. +- Queries keep privacy preprocessing enabled; do not use `--raw` or mutate data/config. A separate request to import follows the import workflow. - Never reveal full chat dumps. ChatLab's safe output applies the user's privacy preprocessing. -- Cite available message evidence with markers such as `[#1021]`, `[#1021*]`, or `[#1021-1024]`. +- Cite available evidence with `[#1021]`, `[#1021*]`, or `[#1021-1024]`. Only individual IDs can be passed to `messages context --id`; merged ranges are display-only. - Start with the answer, name the queried session and time range, then separate observed facts from interpretation. - Avoid overclaiming emotional intent in relationship analysis. Follow `error.hint` only when the correction is clear. diff --git a/skills/chatlab-convert-cn/SKILL.md b/skills/chatlab-convert-cn/SKILL.md index 5aa2f98c..c0cf7d4e 100644 --- a/skills/chatlab-convert-cn/SKILL.md +++ b/skills/chatlab-convert-cn/SKILL.md @@ -1,21 +1,15 @@ --- name: chatlab-convert-cn -description: 将 ChatLab 暂不支持的本地聊天导出转换为经过验证的 ChatLab JSONL 或 JSON:分析源文件结构,编写并运行本地 Node.js 或 Python 转换脚本,并在导入前核对记录数量。当 ChatLab 无法识别 CSV、HTML、TXT、XML、SQLite/数据库、厂商自定义 JSON/JSONL、压缩包等聊天导出,或用户要求 Agent 适配未知聊天格式时使用。 +description: 编写可复用的本地脚本,将不受支持的聊天导出转换并验证为 ChatLab JSONL 或 JSON。用于未知格式适配,不用于聊天分析或直接导入已支持的文件。 --- # ChatLab 聊天转换 在不修改源文件的前提下转换暂不支持的聊天导出。优先交付可复用的转换脚本和经过验证的 JSONL,而不是一次性改写文件。 -安装命令: - -```bash -npx skills add ChatLab/ChatLab --skill chatlab-convert-cn -g -``` - ## 不可省略的规则 -- 始终以只读方式处理源文件。脚本、样本、解压文件和输出都写入独立的同级目录。 +- 始终以只读方式处理源文件。脚本、样本、解压文件和输出写入独立工作目录;用户指定输出位置时遵循该位置。 - 聊天数据只留在本机。不要上传到网络服务,也不要在 AI 可见的终端输出中打印消息正文。 - 先检查结构:字段名、列名、值类型、数量、时间戳形态和脱敏样本。诊断输出中的消息正文替换为类型和长度。 - 绝不静默跳过损坏或不支持的源记录。应携带源行号/索引失败,或保留为消息类型 `99` 并明确统计映射数量。 @@ -26,7 +20,7 @@ npx skills add ChatLab/ChatLab --skill chatlab-convert-cn -g ### 1. 确认源文件和 CLI -确认唯一、准确的源路径。存在多个候选文件时询问用户,不要猜测。每条命令都要给路径加引号。 +从请求和对话中确定源路径,仍有歧义时才询问。命令中的路径加引号;环境能力每个任务检查一次,任务内复用结果。 ```bash clb --help @@ -35,18 +29,11 @@ clb formats clb import "/absolute/path/to/source" --dry-run --json ``` -如果 dry-run 已经识别源文件,不要重复转换,改用 `chatlab-import-cn` 完成导入。 +如果 dry-run 已识别源文件,说明无需转换。只有用户要求导入时才继续,可用则使用 `chatlab-import-cn`,否则按下文预览和写入步骤执行。 -如果 `clb` 不存在,或已有版本没有 `validate` 命令: +`clb validate` 不可用时,直接使用 `scripts/validate-chatlab.mjs` 继续转换,不因推荐安装而暂停。内置验证器需要 Node.js 22.19 或更高版本;旧 CLI 可能仍支持 `formats` 和导入 dry-run,按实际可用能力执行。完全没有 CLI 时,说明无法检查原生格式支持和导入就绪状态。 -1. 告诉用户未检测到可用的 ChatLab CLI,但仍可使用本 Skill 内置的严格验证器继续转换; -2. 建议安装或更新 CLI,并在执行前征得用户同意:`npm install -g chatlab-cli@latest`; -3. 用户跳过安装、安装失败或当前无法联网时,不要阻断转换,改用 `scripts/validate-chatlab.mjs`; -4. 跳过 `clb formats` 和源文件 dry-run,并明确说明无法确认 ChatLab 是否已原生支持该源格式。 - -内置验证器需要 Node.js 22.19 或更高版本。如果 `node --version` 也不可用,可以继续编写转换器,但必须把结果标记为“尚未验证”,并引导用户安装 Node.js 和 `chatlab-cli`;未经同意不要自行安装。 - -不能用肉眼检查替代 CLI 或内置严格验证器。 +两个严格验证器均无法运行时,尽可能完成转换器并将产物标记为尚未验证;不能用肉眼检查替代严格验证。只有缺失的运行时或 CLI 阻塞用户要求的结果时,才请求安装授权。 ### 2. 在不暴露正文的前提下检查结构 @@ -64,7 +51,7 @@ clb import "/absolute/path/to/source" --dry-run --json ### 3. 确定字段映射 -编写转换器前,完整阅读 [references/chatlab-format.md](references/chatlab-format.md)。记录源字段到 ChatLab 字段的映射,包括: +编写转换器前,阅读 [references/chatlab-format.md](references/chatlab-format.md) 的字段契约与所选输出格式。记录源字段到 ChatLab 字段的映射,包括: - 会话边界以及群聊/私聊类型; - 稳定的成员身份和本人身份; @@ -80,11 +67,7 @@ clb import "/absolute/path/to/source" --dry-run --json 默认输出 JSONL。只有源文件较小、天然结构化,并且可以明确安全地放入内存时才使用 JSON。 -选择当前已安装且最简单的运行时: - -- JSON、JSONL、HTML 和 JavaScript 风格数据优先使用 Node.js; -- CSV、SQLite、XML、编码复杂的文本和表格数据优先使用 Python; -- Shell 只负责发现文件和组合命令。 +使用已安装且最适合当前任务的 Node.js 或 Python;不按源格式强制指定语言。 转换器必须: @@ -101,7 +84,7 @@ clb import "/absolute/path/to/source" --dry-run --json ### 5. 先证明小样本 -先对受限的本地样本或脚本的 sample 模式运行转换器,然后验证。有 CLI 时运行: +大文件或映射尚不确定时,先转换并验证受限样本;小文件可以直接全量转换验证。有 CLI 时运行: ```bash clb validate "/absolute/path/to/sample.jsonl" --json @@ -137,14 +120,6 @@ node "/absolute/path/to/chatlab-convert-cn/scripts/validate-chatlab.mjs" "/absol 没有 CLI 时只能报告“格式验证通过”,并提醒用户之后可以安装 CLI 完成 dry-run,或将结果文件拖入 ChatLab;不能声称已经通过导入验证。 -只有同时满足以下条件,才能认为转换结果已经通过完整导入验证: - -- 严格验证返回 `ok: true`; -- 导入 dry-run 返回 `ok: true`; -- 转换器输出消息数等于验证器消息数; -- 源消息数等于输出消息数加上用户明确接受的跳过数; -- 没有隐藏任何源解析错误。 - ### 7. 仅在用户要求时导入 如果用户只要求转换,在当前环境可完成的验证后停止。报告输出路径、脚本路径、会话数、成员数、消息数、跳过数、警告、映射限制和实际达到的验证级别,不要引用消息正文。 diff --git a/skills/chatlab-convert/SKILL.md b/skills/chatlab-convert/SKILL.md index 7eb2cb96..673873f2 100644 --- a/skills/chatlab-convert/SKILL.md +++ b/skills/chatlab-convert/SKILL.md @@ -1,21 +1,15 @@ --- name: chatlab-convert -description: Convert unsupported local chat exports into validated ChatLab JSONL or JSON by inspecting their structure, writing and running a local Node.js or Python converter, and verifying record counts before import. Use when ChatLab cannot recognize a CSV, HTML, TXT, XML, SQLite/database, vendor-specific JSON/JSONL, archive, or other chat export format, or when a user asks an agent to adapt an unknown chat format for ChatLab. +description: Convert unsupported local chat exports into validated ChatLab JSONL or JSON with a reproducible local script. Use for unknown-format adaptation, not analysis or direct import of already supported files. --- # ChatLab Convert Convert an unsupported local export without modifying the source. Prefer a reproducible script and a validated JSONL result over a one-off rewritten file. -Install this skill with: - -```bash -npx skills add ChatLab/ChatLab --skill chatlab-convert -g -``` - ## Non-negotiable rules -- Keep every source file read-only. Write scripts, samples, extracted archives, and output to a separate sibling directory. +- Keep every source file read-only. Write scripts, samples, extracted archives, and output to a separate working directory, using the user's output location when specified. - Keep chat data local. Do not upload it, send it to a network service, or dump message bodies into model-visible terminal output. - Inspect structure first: keys, column names, value types, counts, timestamp shapes, and masked samples. Replace message text in diagnostic output with its type and length. - Never silently skip a malformed or unsupported source record. Fail with its source row/index, or preserve it as message type `99` and count the mapping explicitly. @@ -26,7 +20,7 @@ npx skills add ChatLab/ChatLab --skill chatlab-convert -g ### 1. Confirm the source and CLI -Resolve the exact source path. If several files could be the export, ask the user instead of guessing. Quote paths in every command. +Resolve the source from the request and conversation; ask only if it remains ambiguous. Quote paths in every command. Check available capabilities once, reusing results within the task. ```bash clb --help @@ -35,18 +29,11 @@ clb formats clb import "/absolute/path/to/source" --dry-run --json ``` -If the dry run recognizes the source, do not convert it. Use `chatlab-import` for the supported file. +If the dry run recognizes the source, report that conversion is unnecessary. Import only if requested, using `chatlab-import` when available or the preview/write steps below. -If `clb` is missing, or the installed version has no `validate` command: +If `clb validate` is unavailable, continue with `scripts/validate-chatlab.mjs` without pausing conversion to propose installation. The bundled validator needs Node.js 22.19 or later. An older CLI may still support `formats` and import dry-run; use the capabilities it actually provides. If no CLI is available, state that native format support and import readiness could not be checked. -1. Tell the user that ChatLab CLI was not detected but conversion can continue with this Skill's bundled strict validator. -2. Recommend installing or updating the CLI, and obtain permission before running `npm install -g chatlab-cli@latest`. -3. If the user skips installation, installation fails, or the network is unavailable, continue with `scripts/validate-chatlab.mjs`. -4. Skip `clb formats` and the source dry run, and state that native ChatLab support for the source format could not be checked. - -The bundled validator requires Node.js 22.19 or later. If `node --version` is also unavailable, the converter may still be written, but mark the result as “not yet validated” and guide the user to install Node.js and `chatlab-cli`. Do not install either without permission. - -Do not replace either the CLI validator or bundled strict validator with visual inspection. +If neither strict validator can run, finish the converter where possible and report the output as unvalidated. Do not replace strict validation with visual inspection. Request installation authorization only when a missing runtime or CLI blocks the requested outcome. ### 2. Inspect without exposing content @@ -64,7 +51,7 @@ For an archive, extract into the separate working directory and reject entries t ### 3. Define the mapping -Read [references/chatlab-format.md](references/chatlab-format.md) completely before writing the converter. Record the mapping from source fields to ChatLab fields, including: +Read the field contract and chosen output format in [references/chatlab-format.md](references/chatlab-format.md) before writing the converter. Record the mapping from source fields to ChatLab fields, including: - conversation boundaries and group/private type; - stable member identity and owner identity; @@ -80,11 +67,7 @@ One ChatLab file represents one conversation. If the source contains multiple co Prefer JSONL. Use JSON only for a small, naturally structured export where holding the full result in memory is clearly safe. -Choose the simplest installed runtime: - -- Node.js for JSON, JSONL, HTML, and JavaScript-shaped exports; -- Python for CSV, SQLite, XML, encoding-heavy text, and tabular data; -- shell for file discovery and command composition only. +Use the simplest suitable installed Node.js or Python runtime; the source format does not mandate a particular language. The converter must: @@ -101,7 +84,7 @@ Default `skipped` to zero. Mapping an unknown message to type `99` is preservati ### 5. Prove a small sample -Run the converter on a bounded local sample or sample mode first. With the CLI available, validate that output with: +For a large file or uncertain mapping, run a bounded local sample first. A small input can be converted and validated in full directly. With the CLI available, validate that output with: ```bash clb validate "/absolute/path/to/sample.jsonl" --json @@ -137,14 +120,6 @@ Keep the result levels distinct: Without the CLI, report only “format validated.” Tell the user they can install the CLI later to run the dry-run or drag the result into ChatLab. Do not claim import validation passed. -Require all of the following before calling the result fully import validated: - -- strict validation returns `ok: true`; -- the import dry run returns `ok: true`; -- converter output message count equals the validator message count; -- source message count equals output message count plus explicitly accepted skipped records; -- no source parse error was hidden. - ### 7. Import only when requested If the user asked only to convert, stop after all validation available in the current environment. Report output and script paths, conversations, members, messages, skipped records, warnings, mapping limitations, and the validation level actually reached without quoting messages. diff --git a/skills/chatlab-import-cn/SKILL.md b/skills/chatlab-import-cn/SKILL.md index a14b3cd6..00630ab5 100644 --- a/skills/chatlab-import-cn/SKILL.md +++ b/skills/chatlab-import-cn/SKILL.md @@ -1,25 +1,13 @@ --- name: chatlab-import-cn -description: 通过 clb CLI 安全预览并将本地聊天导出文件导入 ChatLab。当用户要求外部 Agent 从本地 QQ、微信、Telegram、WhatsApp、LINE、Discord、Instagram、Google Chat、ChatLab JSON/JSONL 或其他受支持的聊天导出文件执行首次导入、重新导入或增量更新时使用。 +description: 通过 clb 预览并导入本地聊天导出文件,支持重新导入和增量更新。用于导入请求,不用于只读分析或未知格式转换。 --- # ChatLab 聊天导入 通过 `clb` CLI 导入本地聊天导出文件。始终先预览准确的写入计划。将用户明确提出的导入请求视为授权,预览成功后继续执行,不再请求二次确认。 -## 适用场景 - -- 首次导入本地聊天导出文件。 -- 重新导入更新后的文件,只补充新增消息。 -- 让外部 Agent 安全处理格式识别和会话匹配。 - -如果只需分析 ChatLab 中已有的聊天记录,请使用 `chatlab-analyze-cn`。 - -安装命令: - -```bash -npx skills add ChatLab/ChatLab --skill chatlab-import-cn -g -``` +分析已有记录时,可用则使用 `chatlab-analyze-cn`;源格式不受支持时,可用则使用 `chatlab-convert-cn`。受支持格式的导入不依赖这两个技能。 ## 工作流程 @@ -29,7 +17,7 @@ npx skills add ChatLab/ChatLab --skill chatlab-import-cn -g clb --help ``` -如果 CLI 未安装,告诉用户运行 `npm install -g chatlab-cli`。未经批准不要自行安装软件。存在多个候选文件时不要猜测,每条命令中的路径都要加引号。 +如果 CLI 未安装,告诉用户运行 `npm install -g chatlab-cli`。未经批准不要自行安装软件。复用用户指定的文件和目标,路径仍有歧义时才询问。每条命令中的路径都要加引号。 2. 只读预览导入计划: @@ -41,7 +29,7 @@ clb import "/absolute/path/to/chat-export.json" --dry-run --json 3. 只总结新建或更新模式、目标会话 ID、扫描消息数、新增消息数、重复消息数,以及匹配方式或新建原因。不要引用消息正文。 -4. 根据预览结果决定下一步: +4. 确认 `ok: true`,从 `data` 读取计划后决定: - 用户只要求预览或检查时,到此停止,不写入数据。 - `importMode` 为 `incremental` 且 `newMessageCount` 为 `0` 时,告诉用户会话已经是最新状态,然后停止。 @@ -63,5 +51,5 @@ clb import "/absolute/path/to/chat-export.json" --json - 绝不泄露完整聊天导出文件或消息正文。 - 绝不编造文件路径、解析格式或会话 ID。 - 仅在修正方式明确时遵循 `error.hint`。 -- `FILE_NOT_FOUND` 要求正确路径;`UNRECOGNIZED_FORMAT` 查看 `clb formats`;`IMPORT_IN_PROGRESS` 稍后重试;`INVALID_SESSION_ID` 要求有效 ID。 +- `FILE_NOT_FOUND`、`INVALID_SESSION_ID` 优先从上下文修正,无法确定时询问;`UNRECOGNIZED_FORMAT` 查看 `clb formats`;`IMPORT_IN_PROGRESS` 在现有导入完成后重试一次,仍阻塞则报告,不无限轮询。 - 优先使用用户当前使用的中文变体回答,命令、参数、JSON 字段和错误码保持原样。 diff --git a/skills/chatlab-import/SKILL.md b/skills/chatlab-import/SKILL.md index 1edfdf49..1bc4e568 100644 --- a/skills/chatlab-import/SKILL.md +++ b/skills/chatlab-import/SKILL.md @@ -1,25 +1,13 @@ --- name: chatlab-import -description: Safely preview and import local chat export files into ChatLab through the clb CLI. Use when a user asks an external agent to import, re-import, or incrementally update ChatLab from a local QQ, WeChat, Telegram, WhatsApp, LINE, Discord, Instagram, Google Chat, ChatLab JSON/JSONL, or other supported chat export. +description: Preview and import local chat exports into ChatLab with clb, including re-imports and incremental updates. Use for import requests, not read-only analysis or unsupported-format conversion. --- # ChatLab Import Import local chat exports through the `clb` CLI. Always preview the exact write. Treat an explicit request to import as authorization to continue after a successful preview; do not ask for a second confirmation. -## Good Fit - -- Import a local chat export for the first time. -- Re-import a newer export and add only new messages. -- Let an external agent handle file detection and session matching safely. - -For read-only analysis of records already in ChatLab, use `chatlab-analyze` instead. - -Install this skill with: - -```bash -npx skills add ChatLab/ChatLab --skill chatlab-import -g -``` +For analysis of imported records, use `chatlab-analyze` when available. For an unsupported source, use `chatlab-convert` when available; neither skill is required for a supported import. ## Workflow @@ -29,7 +17,7 @@ npx skills add ChatLab/ChatLab --skill chatlab-import -g clb --help ``` -If the CLI is missing, tell the user to install it with `npm install -g chatlab-cli`. Do not install software without approval. Do not guess between multiple files, and quote the path in every command. +If the CLI is missing, tell the user to install it with `npm install -g chatlab-cli`. Do not install software without approval. Reuse the user's specified file and target. Ask only if the path remains ambiguous, and quote it in every command. 2. Preview the import without writing: @@ -41,7 +29,7 @@ If the user selected an existing session, include `--session-id ` in 3. Summarize only the plan: create or update mode, target session ID, scanned messages, new messages, duplicates, and match method or create reason. Never quote message bodies. -4. Decide from the preview: +4. Require `ok: true`, then read the plan from `data` and decide: - If the user asked only to preview or inspect, stop without writing. - If `importMode` is `incremental` and `newMessageCount` is `0`, report that the session is already up to date and stop. @@ -63,4 +51,4 @@ Report the resulting session ID, import mode, new-message count, and duplicate c - Never reveal a full chat export or message bodies. - Never invent a file path, parser format, or session ID. - Follow `error.hint` only when the correction is unambiguous. -- For `FILE_NOT_FOUND`, request the correct path. For `UNRECOGNIZED_FORMAT`, inspect `clb formats`. For `IMPORT_IN_PROGRESS`, retry later. For `INVALID_SESSION_ID`, request a valid ID. +- For `FILE_NOT_FOUND` or `INVALID_SESSION_ID`, resolve from available context or request the correct value. For `UNRECOGNIZED_FORMAT`, inspect `clb formats`. For `IMPORT_IN_PROGRESS`, retry once after the active import finishes; if still blocked, report it instead of polling indefinitely.