psyche-core (dsh-companion-lab)
v0.3.0 · LivingMemory v2 × Living Cognitive Engine for DeepSeek Harness (DSH) — channel-agnostic cognitive companion runtime with a 7-state Recursive Self-Improvement (RSI) state machine, 3-tier cognitive distillation, Super-Agent cross-window continuity, and a built-in WebUI telemetry/governance console.
1. 核心能力(What's New in v0.3.0)
psyche-core(包名 dsh-companion-lab)是面向 DeepSeek Harness (DSH) 核心管线的渠道无关长期记忆与认知陪伴插件,遵循 TypeScript 单写者 SQLite(node:sqlite Schema v6)+ 可选只读 Python Sidecar 契约:
- Living Cognitive Engine(v0.3.0 七状态前沿 RSI + 三阶认知蒸馏):
- 七状态持久化 RSI 状态机(+
QUARANTINE熔断):OBSERVE → CAUSAL_DIAGNOSE(反事实归因,识别 P6 外部扰动 / LivingMemory 超参偏差 / L1·L3 策略失配)→SYNTHESIZE(TextGrad 语义梯度 + MAP-Elites 按场域/场景分格档案库)→SHADOW_REPLAY(离线失败轨迹与真实群聊黄金切片回归门控)→CANARY(上下文 Thompson Sampling 灰度)→EVAL_DECIDE(多目标 Wald SPRT 序列检验 + 原子 Commit / 回滚 / 方向黑名单)→META_EVOLVE(二阶元演化)。 - 三阶认知蒸馏管线:Tier-1 个体心智模型(
mind/<id>)→ Tier-2 概念晶体与 ReasoningBank 推导范式(crystal/<id>,带refines/superseded_by图边与防概念污染hypothesis → verified门控)→ Tier-3 隔离沙箱可执行技能(skill/<id>,AST 白名单 + 子进程单测通过后经静态挂载的run_distilled_skill调度执行,保持tools_hash恒定不破坏 KV Cache)。
- 七状态持久化 RSI 状态机(+
- LivingMemory v2 × 实证群聊先验与工程防噪:
- 6 类细粒度
memory_atoms生命周期与三阶段淘汰(episodic/planned/factual/relational/preference/unknown)、严格主动访问强化防回音室、漏跑日补偿衰减、可恢复归档与孤立memory_sources原始出处库。 - 双路四模意图动态检索 + MMR 多样性 + 双域保底槽位 +
RecallTrace,配合 5 大共享预算 Agentic 记忆工具与四分区版本化ProfileManager。 - 公域群聊实证校准与防噪:仅在
public_group场域启用脱敏实证先验(SCP VAR(1)、双重时间性、FadeMem、群聊防抖2500/6000/11000ms、FastGate8/28与DecisionGate 0.60),private_dm严格保留结构默认值不外推;内置 15 秒同发言者多气泡归并 与 第三方工具 Bot / 结构化卡片显式降权。
- 6 类细粒度
- Super-Agent 跨窗协作、四后端前置门控与零摩擦降级:
- 跨会话共享
RoleLifeState(作息/精力/四维非对称情绪)、单向群聊→私聊连续性、主动触发与 48hfollowup_review、前台dispatch_task→ 后台高思考companion-worker工程工单状态机。 - 开箱零摩擦优雅降级:无 Python 环境(
ENOENT)、Sidecar 启动超时/断连、未配置远程 Embedding 或缺失 ONNX 权重时,绝不阻塞宿主启动或抛出未捕获异常,自动切换至内置纯 TypeScript 引擎(FTS5 + 本地 CJK/Latin 哈希向量 + TS RSI/蒸馏/规则门控),并在/api/companion/health、/companion与启动日志输出清晰的中英双语诊断提示。
- 跨会话共享
2. 一键安装与 WebUI 启动(Quick Install)
环境要求(Requirements)
- Node.js
>= 24.0.0(内置node:sqlite与原生 ESM,零原生 C++ 编译依赖) - DeepSeek Harness (
dsh>= 0.1.0-rc.1) 与pnpm - Python
>= 3.10(完全可选;安装numpy可启用全部 Python Sidecar 算法与 Tier-3 技能沙箱;无 Python 时全流程自动降级至 TypeScript 内置引擎)
标准 DSH 插件安装
# 方式 A:通过 Release 压缩包安装(推荐,最快且免源码构建)
dsh plugin --profile web add https://github.com/albumsean441-lang/psyche-core/releases/download/v0.3.0/dsh-companion-lab-0.3.0.tgz
# 方式 B:直接从 GitHub 仓库安装
dsh plugin --profile web add github:albumsean441-lang/psyche-core
# 检查合并后的 Cordis 配置树
dsh --profile web --dump-config
# 启动 DSH 宿主(自动挂载插件、可选 Python Sidecar 与内置 WebUI 控制台)
dsh --profile web
安装完成后无需任何额外配置即可直接开始对话(未绑定会话自动按 Tier-3 session_isolated 安全隔离运行),内置 WebUI 控制台自动托管于:
- WebUI 控制台与 API:
http://127.0.0.1:3789 - 健康与降级诊断探针:
GET http://127.0.0.1:3789/api/companion/health - 可选 Bearer Token 鉴权:启动前设置
COMPANION_API_TOKEN=<secret>,所有业务接口自动开启Authorization: Bearer <secret>校验。
最小覆盖配置示例(可选)
仅在需要自定义端口、关闭 Python Sidecar 或接入外部 Embedding 时,于 $DSH_HOME/profiles/web/cordis.patch.yml 中追加覆盖项:
- id: dsh-companion-lab
config:
apiServer:
enabled: true
port: 3789
sidecar:
enabled: true # 无 Python 环境可显式设为 false,或留 true 自动静默降级
embeddings:
baseUrl: '' # 留空默认启用零依赖本地 CJK/Latin 哈希向量
experiment:
guardrailMode: 'suspended_research'
strictPrivacyIsolation: true
独立启动 WebUI / API Server 与干净卸载
# 独立运行 WebUI + API Server(无需 DSH 宿主)
npm run start:api -- --db ./companion.sqlite3 --port 3789 --host 127.0.0.1
# 干净卸载插件(宿主退出时自动释放 HTTP 端口、停止 Sidecar 并关闭 SQLite)
dsh plugin --profile web remove dsh-companion-lab
3. 核心配置与暴露接口速查
标注 .volatile() 的实验参数均可在 WebUI 或 PATCH /api/companion/config 中免重启热更新:
| 配置键 | 默认值 | .volatile() |
说明 |
|---|---|---|---|
dbPath |
$DSH_HOME/companion-lab/companion.sqlite3 |
否 | 单写者 SQLite Schema v6 主库路径 |
apiServer.enabled / port |
true / 3789 |
否 | 随 Cordis 生命周期启停内置 API Server 与 WebUI |
sidecar.enabled / budgetMs |
true / 250 |
budgetMs |
Python 只读 Sidecar 开关与毫秒级超时(失败自动 60s 退避降级至 TS) |
experiment.guardrailMode |
'suspended_research' |
是 | 科研悬置模式(仅做技术穿帮清洗)或 'compliant_guarded' 合规护栏 |
experiment.strictPrivacyIsolation |
true |
是 | 群聊 / 私聊三维隐私物理隔离锁 |
experiment.reasoningEffort / highThinkingMaxTokensFloor |
'high' / 8192 |
是 | 高思考推理档位与 max_tokens 下限余量(含代码/分析任务风格豁免) |
experiment.decisionBackend |
'dsh_llm' |
是 | 前置决策门控后端:dsh_llm / http_classifier / local_onnx / rule_only |
experiment.decisionGroupThreshold / decisionMaxTokens |
0.6 / 48 |
是 | 群聊实证意愿阈值(含第三方 Bot/卡片降权)与无思考输出上限 |
debounce.enabled |
true(分场域自适应) |
否 | public_group 自动 2500/6000/11000ms,private_dm 保持 1500/4000/8000ms |
fastGate.groupHighIntensityThreshold / groupInterjectMaxDaily |
8 / 28 |
否 | 群聊高频收口与每日主动插话实证限额 |
experiment.mmrLambda / dynamicRouteWeighting |
0.7 / true |
是 | LivingMemory v2 MMR 多样性系数与查询意图动态调权 |
- 静态挂载 DSH 工具(保持
tools_hash恒定保护 KV Cache):recall_read、recall_long_term_memory、read_memory_evidence、memorize_long_term_memory、forget_long_term_memory、update_user_profile、run_distilled_skill、group_skip、dispatch_task - 斜杠命令:
/context(12 桶上下文预算与压缩账本透视)、/companion(生命体征、RSI/蒸馏统计、后端状态与双语降级提示) - v0.3.0 只读治理 API:
/api/companion/health、/api/companion/rsi/state、/api/companion/rsi/elites、/api/companion/rsi/transitions、/api/companion/cognitive/minds、/api/companion/cognitive/crystals、/api/companion/cognitive/skills
4. 开发构建与全量验证
# 1. 构建宿主纯 ESM 产物 (lib/) 与 WebUI 静态产物 (apps/webui/dist/)
npm run build
# 2. 运行全部 TypeScript 单元测试(Node 24 原生执行)
npm run test:ts
# 3. 运行全部 Python Sidecar 单元测试
npm run test:py
5. 开源许可、衍生声明与上游致谢(License & Attributions)
本项目遵循 GNU Affero General Public License v3.0 only (AGPL-3.0-only) 开源发布。
本仓库属于在深度研究与架构迁移基础上对上游 AGPL-3.0 项目的衍生创作与跨宿主重构。根据 AGPL-3.0 第 13 条(Remote Network Interaction),任何修改本软件并通过网络向用户提供交互服务(包括部署 packages/api-server、WebUI 控制台或面向 IM/Web 终端的对话服务)的衍生版本,均须在 AGPL-3.0-only 许可下向交互用户提供完整对应源代码。
特此向以下核心上游与参考开源项目正式署名致谢:
lxfight-s-Astrbot-Plugins/astrbot_plugin_livingmemory(上游 AGPL-3.0 核心记忆体系灵感来源)— 启发了 6 类类型化memory_atoms生命周期、严格主动强化防回音室、漏跑日补偿衰减、可恢复归档、memory_sources原始出处库、双路四模意图动态检索 + MMR +RecallTrace、5 大 Agentic 工具、ProfileManager、Union-Find 聚类巩固与加权 Louvain 社区发现。menglimi/astrbot_plugin_private_companion(上游 AGPL-3.0 核心陪伴领域灵感来源)— 启发了拟人分段与打字节奏、跨会话角色作息/精力/四维非对称情绪、主动搭话与 48hfollowup_review、336h 表达衰减轮换、群聊社交习惯与关系权限锁。dearbld/dsh-living-memory(MIT 参考来源)— 启发了双时间轴活记忆、FadeMem 半衰期衰减、SQLite FTS5 + 稠密向量混合召回及新旧事实冲突裁决设计。bowenliang123/dsh-context— 启发了 DSH 会话日志实时分桶透视(/context)、防御性.volatile()Schemastery 配置写法与 Cordis Host Bundle 规范。deepseek-ai/deepseek-harness与dsh-superagent-prototype— 提供了 Cordis 4 插件宿主管线、surfaceOp: replace折叠语义,以及嵌套SAVEPOINT事务、DurableEffectRunner、SuperAgentOutbox、CrossWindowBridge与后台 Worker 派单架构参考。
No comments yet. Be the first to write one.