MINARA

已学习偏好

GET / POST /v1/preferences:列出、查看、批准、拒绝和弃用从用户对话中提取的偏好。

偏好演进系统从对话中提取持久的用户偏好(例如 “我从不交易迷因币”“简洁回复”“优先链上数据而非 K 线”),并在它们生效前使其经过状态机。

M1 提供只读端点;M2 增加了 approve / reject / deprecate 变更操作及列表端点的 total 字段;M3 增加了 undo 端点和对 hard_constraint 记录的工具级执行。

M4 增加桥接机制:每次迁移到 active 现在都会将偏好写入相应下游存储。对于命名有效 11 维标签的硬约束写入 user_tags;每条 personal_style 记录写入 memories 镜像(使风格提示可被 FTS 索引);目标为场景的 behavioral_preference 记录写入 scenario-classifier 增益;目标为 methodology ID 的记录写入方法论优先级乘数。离开 active(deprecate / reject)的迁移会反转每一项写入。桥接写入尽力执行,绝不阻塞状态迁移;失败通过带 learning/preference-bridge 的日志暴露。完整写入路径图请参阅自我改进系统

每项偏好有三条分类轴:

  • kindpersonal_stylebehavioral_preferencehard_constraint 之一。
  • dimensionriskchainasset_classtimingmethodologystyleconstraint 之一。
  • stateproposedactivedeprecatedrejected 之一。

完整生命周期请参阅 ~/.claude/plans/autoclaw-agent-agent-lazy-lollipop.md 中的项目计划。


GET /v1/preferences

使用可选筛选条件列出偏好。

方法GET
路径/v1/preferences
认证设置 GATEWAY_AUTH_TOKEN 时需要 Authorization: Bearer <token>
查询statedimensionkindlimit(默认 100,最大 500)
类别learning

响应 200

{
  "ok": true,
  "data": {
    "items": [
      {
        "id": "pref_a1b2c3d4e5f6",
        "user_id": "default",
        "dimension": "asset_class",
        "kind": "hard_constraint",
        "statement": "Never trade meme coins",
        "structured": { "operator": "exclude", "subjects": ["meme_coin"], "scope": ["buy", "swap"] },
        "evidence": null,
        "source": "manual",
        "state": "active",
        "confidence": 0.65,
        "times_observed": 4,
        "times_violated": 0,
        "dedup_key": "asset_class:hard_constraint:never trade meme coins",
        "bridges_user_tag": null,
        "approved_at": "2026-04-15T08:00:00Z",
        "last_ask_at": null,
        "created_at": "2026-04-13T10:00:00Z",
        "updated_at": "2026-04-15T08:00:00Z"
      }
    ],
    "count": 1,
    "total": 1
  }
}

count 是本页中的记录数(≤ limit);total 是整张表中符合筛选条件的记录数。当 count == limit && total > limit 时,请缩小筛选条件或使用更小的 limit 值分页,以查看其余记录。

statedimensionkindlimit 无效时,响应 422


GET /v1/preferences/:id

按 ID 获取单个偏好。

方法GET
路径/v1/preferences/:id
认证设置 GATEWAY_AUTH_TOKEN 时需要 Authorization: Bearer <token>
类别learning

响应 200:形状与上述 items[] 元素相同。

ID 不存在时,响应 404


POST /v1/preferences/:id/approve

proposed 记录提升为 active。如果尚未设置,则设置 approved_at。等同于 REPL /preferences approve 命令和 minara preferences approve <id>

方法POST
路径/v1/preferences/:id/approve
认证设置 GATEWAY_AUTH_TOKEN 时需要 Authorization: Bearer <token>
请求体可选的 { "reason": "..." }(审计记录,≤ 500 个字符)
类别learning

响应 200:标准封装中的已更新偏好记录。

ID 未找到时,响应 404

响应 409:无效迁移(例如记录已是 rejected),或其他写入者抢先完成(CAS 丢失;重新 GET 查看当前状态)。


POST /v1/preferences/:id/reject

proposed(或在退役现有偏好时的 active)提升为 rejected。形状与上述 approve 相同;rejected 是终态,记录作为审计轨迹保留,但不会再次浮现。

方法POST
路径/v1/preferences/:id/reject
认证设置 GATEWAY_AUTH_TOKEN 时需要 Authorization: Bearer <token>
请求体可选的 { "reason": "..." }
类别learning

POST /v1/preferences/:id/deprecate

active 提升为 deprecated。偏好不再注入系统提示词,但记录会保留,因此相似度闸门仍能将重新提议识别为重复项并跳过再次询问。如果希望记录永不作为相似陈述匹配再次出现,请使用 reject

方法POST
路径/v1/preferences/:id/deprecate
认证设置 GATEWAY_AUTH_TOKEN 时需要 Authorization: Bearer <token>
请求体可选的 { "reason": "..." }
类别learning

POST /v1/preferences/:id/undo

在配置的撤销窗口内撤回由强信号自动激活的 hard_constraint(默认 24 小时,参阅 PREFERENCE_HARD_UNDO_WINDOW_HOURS)。记录迁移为 deprecated,工具级执行会立即停止,审计轨迹(auto_activated_at 时间戳、原始陈述)会被保留。这是 M3 引入的功能。

当以下任一情况成立时,请使用 deprecate:(a) 偏好是手动批准的(所以 auto_activated_at 为 null),或 (b) 窗口已过期。

方法POST
路径/v1/preferences/:id/undo
认证设置 GATEWAY_AUTH_TOKEN 时需要 Authorization: Bearer <token>
请求体可选的 { "reason": "..." }(≤ 500 个字符)
类别learning

响应 200:记录已弃用。

响应 404:ID 未找到。

响应 410 Gone:记录已自动激活但撤销窗口已过期。请改用 deprecate

响应 413:请求体大于 4 KB。

响应 422:记录是手动批准的(没有 auto_activated_at)。请改用 deprecate

响应 409:CAS 丢失(其他写入者先更改了记录)或无效的结构迁移。

本页目录