Skip to content

[Feature] standalone API 补 profile / rules 只读路由(外部工具可读用户画像) #180

Closed

Description

@modusensus

背景

standalone 外部 API(api-standalone.js,默认 127.0.0.1:8790,Bearer token)目前只有 health / status / memories CRUD / search 五类路由——用户画像(profile)与规则(rules)读不出来。外部工具(以及规划中的 MCP server)无法获取用户画像;#175 的冲突对里甚至出现了「模型绕道直读 memory.db 的 user_settings 表」的变通行为,说明这个能力缺口是真实需求。

方案

  • GET /api/external/.../profile:返回 user_settings.profile(同面板 /api/dsh-mneme/profile 的读取逻辑,settings.js 复用)
  • GET .../rules:返回规则列表
  • 只读;Bearer 鉴权与现有路由同款;无则返回空值而非 404(调用方好处理)

验收

  • 带 token curl 两个路由返回与面板 API 相同的数据
  • 现有测试套件补路由用例

难度:低。照 dream-status / list 的现有路由模式写即可,适合新手(认领前在评论区报备即可)。

Activity

  1. z2Ace0107 commented on Sep 15, 2026

    @z2Ace0107
    Contributor

    我想参与这个 Issue。

    计划先做一个小而可验证的实现:

    1. 在 dsh-mneme/src/api-standalone.js 增加经过现有 Bearer 鉴权的 GET /profile 和 GET /rules 只读路由,复用 settings.getProfile() / settings.getRules() 的现有语义;
    2. 在 dsh-mneme/test/standalone-api.test.js 增加未授权返回 401、已保存数据返回、空值返回的测试;
    3. 按仓库规则只修改 src/,运行 npm run sync 同步 lib/,再运行 npm test。

    我注意到 Issue 文案使用了 /api/external/.../profile 和 /rules 的表述,而 standalone server 当前路由风格是根路径;如果这里要求完整的 /api/external/... 前缀,请在我开始前帮忙确认实际路径。否则我会按现有 standalone 路由约定实现。

    如果这个范围和路径方向合适,我再开始准备 PR。

  2. modusensus commented on Sep 15, 2026

    @modusensus
    MemberAuthor

    欢迎认领!范围、测试计划、只改 src/ + npm run sync 的流程都对,可以开始。

    路径确认:按现有 standalone 根路径风格走——GET /profile 与 GET /rules(与 /health /status /memories /search 同层),issue 里的 /api/external/.../profile 只是占位表述,不是路径要求。

    几个对齐细节:

    1. 返回形状与面板 API 保持一致(调用方心智统一):
      • GET /profile → { "profile": "<文本>" }(未设置返回 { "profile": "" },200 而非 404)
      • GET /rules → { "rules": [ ... ] }(未设置返回空数组)
    2. 鉴权:与现有路由同款(Bearer,兼容 x-dsh-mneme-token 头),/health 之外的豁免规则不变;
    3. 文档:README「外部 API 与 CLI」章节的路由清单里补这两条(一段话即可);
    4. 测试三条(401 / 有数据 / 空值)正好,若顺手再加一条「token 错误返回 401」更完整。

    等你的 PR,CI 绿了我们尽快合。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions