diff --git a/CLAUDE.md b/CLAUDE.md index a74c241..9a923a6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -206,6 +206,11 @@ alias dacli='npx tsx $ccWorkDir/dacli/src/cli.ts' cd $ccWorkDir/dacli && npm install # 首次需装依赖 dacli app login --account=admin --password=123456 --appCode=testspace # 统一测试场, 不是 developSystem (baseline 只读) +# KB 知识库检索 (PostgreSQL 后端, 见 .claude/skills/dacli-ts/SKILL.md) +dacli kb search "" # tsvector 全文检索 (BM25 排序) +dacli kb search "" --domain= # 域过滤 +dacli kb list # 列所有域 + 陈旧候选数 + # E2E测试(playwright Node.js) cd $ccWorkDir/test && npx playwright test --project=chromium ``` diff --git a/skills/dacli-ts/SKILL.md b/skills/dacli-ts/SKILL.md index 6b1aaa4..59055cd 100644 --- a/skills/dacli-ts/SKILL.md +++ b/skills/dacli-ts/SKILL.md @@ -654,4 +654,66 @@ dacli app context --json # systemExists 字段, false = app 已删, 跑 dacli a dacli app status # 同样会检测 base_system 缺失 + 给重建命令 ``` -详细 9 bug 复盘: [[tds-9-dacli-bugs-2026-06-27]] (MEMORY) \ No newline at end of file +详细 9 bug 复盘: [[tds-9-dacli-bugs-2026-06-27]] (MEMORY) + +--- + +## KB 知识库 (PostgreSQL 后端, v0.16+) + +知识不入文件系统, 直接入 pg `ssw_kb` schema, AI 通过 `dacli kb` 命令检索。 + +### 检索 (AI 日常用) + +```bash +dacli kb list # 列所有域 +dacli kb show # 看域详情 +dacli kb search "" # tsvector 全文检索 (BM25 排序) +dacli kb search "" --domain= # 域过滤 +dacli kb search "" --all # 含过期/archived +dacli kb map # 域↔源文件 映射表 +dacli kb audit stale # 90 天陈旧候选 +``` + +### 写入 (开发者用) + +```bash +dacli kb init # 首次: 建 ssw_kb schema +dacli kb add # 新建域 (交互式) +dacli kb entry # 新增条目 (交互式) +dacli kb renew # 续期 (重置 last_reviewed) +dacli kb expire --on=YYYY-MM-DD # 设置过期 +dacli kb archive --reason=... # 归档 +dacli kb deprecate --replaced-by= # 废弃 + 链向新条目 +dacli kb rebuild-fts # 重建 tsvector (兜底) +``` + +### 自动特性 + +- `created_on` / `last_reviewed` 自动 NOW() +- `expires_on` 过期自动从 `active_entries` 视图过滤 +- `stale_candidates` 视图自动列 90 天未审查条目 +- `search` 命中自动更新 `access_count` + `last_accessed` + +### 跨进程访问 + +```bash +psql -h jnpf-postgres -U dacli -d dacli_kb -c "SELECT * FROM ssw_kb.active_entries WHERE search_vector @@ to_tsquery('dacli & form') LIMIT 5" +``` + +### 配置 + +`.env` (不入 git): +``` +PGHOST=jnpf-postgres +PGPORT=5432 +PGUSER=dacli +PGPASSWORD=dacli123 +PGDATABASE=dacli_kb +KB_SCHEMA=ssw_kb +``` + +### 测试 + +```bash +npx tsx tests/test-kb.ts # 8 步闭环测试 (清理→建域→条目→检索→过期→--all→renew→archive→清理) +``` \ No newline at end of file