Skip to content

feat(core): 支持用户和 peer 级内容目标#2564

Open
qin-ctx wants to merge 2 commits into
mainfrom
feat/user-content-targets
Open

feat(core): 支持用户和 peer 级内容目标#2564
qin-ctx wants to merge 2 commits into
mainfrom
feat/user-content-targets

Conversation

@qin-ctx

@qin-ctx qin-ctx commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Description

本 PR 将 OpenViking 的资源、技能、记忆等用户内容目标统一到更明确的 viking://user/... 命名空间规则下,并补齐 API、Python SDK、Rust CLI 与检索路径之间的行为一致性。

核心目标是让“写入到哪里”和“从哪里检索”不再依赖各调用点各自推断,而是通过统一的内容目标解析规则完成:

  • 公共资源仍可写入 viking://resources/...
  • 当前用户的私有资源/技能可以使用短写法,例如 viking://user/resourcesviking://user/skills,服务端会按当前身份 canonicalize 到 viking://user/<current_user>/resourcesviking://user/<current_user>/skills
  • 指定用户或 peer 的内容可以显式写入 viking://user/<user_id>/...viking://user/<user_id>/peers/<peer_id>/...
  • peer_iduser_id 等路径身份片段统一走共享校验,避免冒号、路径分隔、... 等不适合作为 URI path segment 的值进入存储路径。

举例:

# 将本地文档加入当前用户资源根下,最终目标类似:
# viking://user/alice/resources/docs
ov add-resource ./docs --parent viking://user/resources --wait

# 将技能安装到指定 peer 的技能空间
ov add-skill ./skills/support-helper \
  --to viking://user/support_bot/peers/web-visitor-alice/skills/support-helper \
  --wait

# 只列出某个 peer 下安装的技能,不混入当前用户默认 skills 根
ov skills list --root-uri viking://user/support_bot/peers/web-visitor-alice/skills

# 检索时指定 peer_id,会检索当前用户内容 + 该 peer 的 memories/resources/skills,
# 不会默认扫所有 peer 内容
ov find "invoice follow-up" --peer-id web-visitor-alice

兼容性影响:

  • peer_id 现在必须是安全的单段标识,例如 web-visitor-alice;类似 web:visitor:alice 的值会被拒绝,因为它不符合共享 path segment 校验规则。
  • viking://user/resourcesviking://user/skills 等短写法现在明确表示“当前请求用户的内容根”,不会被误解为 user_id 等于 resourcesskills
  • skills API 新增 root_uri 后,list/show/find/update/remove 可以操作非默认 skills 根,例如 peer skills 根。

Related Issue

无关联 issue。

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • 新增共享内容目标模型 ContentTargetSpec,统一处理 toparentcreate_parent 的互斥关系、路径变量解析、URI canonicalization 与权限校验,资源和技能写入都复用这一入口。
  • 新增共享 identifier 校验模块,统一 account_iduser_idpeer_id 等身份片段的安全规则,并在 namespace、session、CLI 用户标识和 peer 检索路径中复用,避免路径语义漂移。
  • 扩展 viking://user/... 命名空间解析能力,支持当前用户短写内容根、用户级 resources/skills、peer 级 memories/resources/skills,并让 URI 分类、owner 推导、ovpack、VikingFS 路径转换等共享同一套规则。
  • 扩展 skills HTTP API 与客户端能力:list/show/find/update/remove 支持 root_uriadd_skill 支持 toparentcreate_parent,并保证 skill 内容名必须和目标 URI leaf 一致。
  • 扩展 Rust ov CLI:add-skill 支持 --to--parent--parent-auto-createov skills list/show/find/update/remove 支持 --root-uri,方便管理用户或 peer 的独立 skills 根。
  • 调整检索默认目标:普通检索默认包含当前用户 memories/resources/skills 与公共 resources;传入 peer_id 时只额外加入指定 peer 的内容根,不再隐式扫所有 peers。
  • 补充和更新 API、namespace、peer 检索、session memory、HTTP client 和 CLI 相关测试,覆盖用户短写 URI、peer 内容根、非法身份片段拒绝、skills root_uri 管理等场景。

Testing

按前序验证结果,单测已经跑过;本轮创建 PR 时未重复执行完整单测。

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

已覆盖的关键验证包括:

pytest tests/server/test_api_resources.py tests/server/test_api_skills.py tests/server/test_peer_id_compat.py tests/unit/test_namespace_uri_classification.py tests/cli/test_user_identifier.py tests/client/test_http_client_config.py tests/session/test_session_messages.py tests/session/test_session_commit.py tests/session/test_tool_result_externalization.py tests/session/memory/test_memory_isolation_handler.py tests/session/memory/test_memory_react_system_prompt.py tests/session/memory/test_memory_timestamp_parsing.py

cargo test -p ov_cli

本轮提交前额外执行过:

git diff --cached --check

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

不涉及 UI 截图。

Additional Notes

这个 PR 主要是收敛底层规则,不是只在单个 API 上加参数。后续如果继续扩展 team/project 级命名空间,建议也沿用 ContentTargetSpecvalidate_content_target_uri 作为写入入口,避免各调用点重新推断目标路径。

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🏅 Score: 85
🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Extract identifier validation to shared module

Relevant files:

  • openviking/core/identifiers.py
  • openviking_cli/session/user_id.py

Sub-PR theme: Add skill target URI support

Relevant files:

  • openviking/server/routers/skills.py
  • openviking/service/resource_service.py
  • openviking/utils/skill_processor.py

⚡ Recommended focus areas for review

Missing to/parent conflict check

The add_resource endpoint removed the check that prevents specifying both 'to' and 'parent' parameters. While this may be handled in ContentTargetSpec.from_fields, the validation should happen early at the API boundary to provide immediate feedback.

@router.post("/resources")
async def add_resource(
    http_request: Request,
    request: AddResourceRequest,
    _ctx: RequestContext = Depends(get_request_context),
):
    """Add resource to OpenViking."""

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant