Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions desktop/src-tauri/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ pub fn project(
"service_manager",
"server_liveness",
"server_readiness",
"server_memory_protocol",
"plugin_memory_protocol",
]
.contains(&field.as_str())
{
Expand Down
33 changes: 33 additions & 0 deletions desktop/src-tauri/tests/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,36 @@ async fn non_regular_registration_is_rejected_without_blocking_shutdown() {
.expect("shutdown must not wait on a FIFO registration")
.unwrap();
}

#[test]
fn memory_protocol_checks_survive_projection_without_private_details() {
for status in ["ok", "skipped", "degraded", "failed"] {
let ok = status == "ok";
let host_ok = ok || status == "skipped";
let input = serde_json::json!({
"ok": host_ok,
"hosts": {"pi": {
"ok": host_ok, "status": if host_ok { "ok" } else { status },
"checks": {
"server_memory_protocol": {"ok": ok, "status": status, "detail": "private-server"},
"plugin_memory_protocol": {"ok": ok, "status": status,
"detail": "private-package", "checks": {"memory_protocol": "secret-token"}}
}
}}
});
let report = project(
DiagnosticKind::Integrations,
&serde_json::to_vec(&input).unwrap(),
i32::from(!host_ok),
)
.unwrap();
assert_eq!(report.hosts.len(), 1);
assert_eq!(report.hosts[0].checks.len(), 2);
for check in &report.hosts[0].checks {
assert_eq!(check.status, status);
}
let output = serde_json::to_string(&report).unwrap();
assert!(!output.contains("private"));
assert!(!output.contains("secret-token"));
}
}
25 changes: 25 additions & 0 deletions docs/en/development/plugin-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,28 @@ This contract does not define:
- the Bub integration.

Those decisions require their own implementation evidence and review boundary.


## Memory protocol upgrades

`legacy_memory_operation_unsupported` (HTTP 422) MUST survive direct-tool and command mapping with fixed recovery
instructions: update the CLI/SDK and affected host plugin, rerun setup for the selected profile, fully restart the host,
rerun Doctor, and obtain a fresh Atomic Memory reference. Never drop collection CAS or automatically replay writes.
Do not render arbitrary Server error details as recovery text. This code stays a domain rejection; it is not inferred
from an exception message and is not rewritten to `version_mismatch` or `invalid_response`.

A Doctor compatibility check MUST be independent of liveness/readiness. DSH inspects the OpenAPI `memory.explicit`
contract major and required Atomic routes; Pi, OpenCode and Hermes inspect the same feature's version in ServerInfo.
Supported major 1 accepts additive minor versions. Missing declarations, inaccessible discovery, and uninspectable
installed packages cannot establish compatibility. A legacy mutation still visible in DSH's native MCP catalog fails
Doctor even when the Server itself advertises a current contract.

The CLI inspects installed Memory contract declarations for DSH, Pi, OpenCode, OpenClaw and Hermes. DSH resolves the
selected Web/Desktop bundle with the installed host's parser; Pi uses the paths reported by `pi list`; OpenClaw uses
native `plugins inspect`; OpenCode records the source package declaration beside the copied managed bundle; Hermes
ships it in `powercontext.json`. JS packages use `package.json`'s `powercontext.memoryProtocol`. The declaration is
`atomic-artifact-v1`; absence is unverified/degraded. Neither package version strings nor registration prove compatibility.
A managed OpenCode marker does not attest to separately configured plugins or externally modified files.

Native MCP adapters (Codex, Claude Code, WorkBuddy, ZCode and Kimi Code) discover tool schemas from the Server. Their
HTTP hook success does not attest to session MCP caches or mutation behavior. See [upgrade recovery](../docs/operate/atomic-memory-migration.md#client-and-agent-host-compatibility).
12 changes: 7 additions & 5 deletions docs/en/docs/integrations/dsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ messages or recalled content. `ok: true` means these read-only checks passed, no
| `not_ready` / `degraded` | Inspect the reported dependency, such as `database` or `inference.generation`; use its recovery action. |
| `required_route_missing` | The named operation returned untyped 404. Inspect its proxy route/base path and matching versions; 404 alone does not prove a version mismatch. |
| `required_route_undeclared` | The Server OpenAPI document lacks the listed operation declarations. |
| `memory_protocol_mismatch` / `legacy_memory_operation_unsupported` | Align Server/CLI/plugin contracts, rerun setup for the active profile, restart, and search again for an Atomic reference. Never drop collection CAS. |
| `contract_unavailable` | Declarations are unchecked; expose `/openapi.json` through the same base path or verify the contract separately. |
| `scope_not_found` / `unscoped` | Check the explicit Scope override, workspace binding, and Server default. Doctor does not alter them. |
| `invalid_response` | The response fails protocol checks, even if HTTP status was 200. |
Expand All @@ -183,10 +184,11 @@ The route check reads the Server's existing `/openapi.json` and distinguishes de
Doctor never executes capture, remember, flush, binding changes or injection. A missing contract is unchecked, and
a missing Scope skips prepare with an explicit reason. Write/processing verification belongs to acceptance below.

Standalone `powercontext doctor dsh` checks Web-profile registration only and reports that the running host
configuration and Server checks were not observed. Exit success means registration checks passed.
`powercontext doctor` uses its own `--server-url` / `POWERCONTEXT_CLIENT_SERVER_URL`; use it for the existing
service/health diagnostics after aligning that URL, without assuming it observes DSH overrides.
Standalone `powercontext doctor dsh` checks registration and the installed plugin Memory protocol declaration for the
selected profile. It also checks the Server at the endpoint resolved by the CLI. These checks cannot observe environment
overrides or cached tools inside an already running DSH process. Restart the affected profile and run `/pc doctor` there.
An undeclared installed protocol or unavailable Server contract produces a non-success result; registration alone is
insufficient. Bare `powercontext doctor` uses its own selected client endpoint.

## Inspect the last automatic attempt

Expand Down Expand Up @@ -415,7 +417,7 @@ powercontext doctor
powercontext doctor dsh
```

`doctor` checks the package and Server. `doctor dsh` checks the DeepSeek Harness CLI and that dump-config contains the plugin id `powercontext-dsh`.
`doctor` checks the package and Server. `doctor dsh` checks the DeepSeek Harness CLI, registration and installed Memory protocol declaration. A package without a declaration is unverified/degraded; update the plugin and restart the actual Web/Desktop profile. See [protocol upgrade recovery](../operate/atomic-memory-migration.md#client-and-agent-host-compatibility).

## Environment variables

Expand Down
32 changes: 32 additions & 0 deletions docs/en/docs/operate/atomic-memory-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ public tables, the legacy entry tables no longer reference them, and the public
legacy `memory_citations` columns. It reads neither the archive nor the
legacy entry tables; complete per-entry verification is the job of `verify`.


## Client and Agent host compatibility

A successful database migration and healthy `/health/live` or `/health/ready` do not establish plugin compatibility.
Legacy collection citations and collection CAS preconditions cannot be replayed against Atomic Memory. HTTP 422
`legacy_memory_operation_unsupported` is a protocol rejection, not a temporary outage or a request to retry without CAS.

1. Update the CLI/SDK and the affected plugin to releases or source refs compatible with the Server. Updating the Server
alone does not replace a host's installed plugin. Plugin package versions can remain unchanged across Server releases.
2. Run `powercontext setup HOST` with the intended `--source` / `--ref` and existing endpoint settings. For DSH, select
the actual profile explicitly: `powercontext setup dsh --profile web` or `powercontext setup dsh --profile desktop`.
3. Fully restart that host or Gateway, including existing sessions that cache tool schemas. Run `powercontext doctor HOST`
with the updated CLI. For DSH also run `/pc doctor` inside the restarted session; Pi and OpenCode have `/pc doctor`,
while Hermes exposes the separate Memory protocol check through `/pc status`.
4. Search or list again to obtain an Atomic Memory artifact reference. For edits, read its current content ETag; for
lifecycle changes, use its current `state_version`. Do not remove old CAS conditions, invent new preconditions, or
automatically replay an earlier write. If an older SDK rejected a successful write's response, inspect the current
inventory before submitting another write.

The updated standalone Doctor reports Server protocol declarations separately from health. Its installed-package check
covers DSH, Pi, OpenCode, OpenClaw and Hermes: `atomic-artifact-v1` is a package declaration, independent of npm/plugin
version. Packages with no declaration are **unverified**, not confirmed incompatible; they produce a degraded result and
update instructions instead of an all-green result. A declaration does not prove that an already running process has
reloaded. Missing or inaccessible Server discovery also remains unverified. Discovery reuses the selected host’s URL-bound stored credential. If discovery requires authorization and no credential
is available, the check is skipped with credential guidance and does not fail installation or Doctor by itself.
Rejected configured credentials still produce a degraded result. These read-only checks do not execute writes.

Codex, Claude Code, WorkBuddy, ZCode and Kimi Code use the Server's native MCP schemas for Memory operations. Reconnect
these hosts after updating the Server; their hook preparation/capture checks do not validate a cached MCP tool catalog.
The Server preserves the legacy error code and recovery instructions on HTTP/MCP responses. Host adapters must not
collapse that code to a generic `invalid_request` or encourage automatic retries.

## Run the maintenance task

On a database with `pc_schema_revision` or a Server identity marker, this compatibility command delegates
Expand Down
22 changes: 22 additions & 0 deletions docs/zh/development/plugin-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,25 @@ key 是 outcome,不能使用 user input 或 request payload。
- Bub 集成。

这些决定需要独立的实现证据和评审边界。


## Memory 协议升级

HTTP 422 `legacy_memory_operation_unsupported` MUST 在直接工具和命令的结果中保留,并附带固定的恢复步骤:
更新 CLI/SDK 与受影响的 Host 插件,为实际 profile 重新执行 setup,完整重启 Host,重新运行 Doctor,再取得新的
Atomic Memory 引用。不得移除集合 CAS 或自动重放写入。恢复文本不能直接展示任意 Server 错误详情。这个错误仍是
领域拒绝,不能根据异常文本猜测,也不能改写成 `version_mismatch` 或 `invalid_response`。

Doctor 的兼容性检查 MUST 独立于存活、就绪状态。DSH 检查 OpenAPI 的 `memory.explicit` 协议主版本和必需的 Atomic
路由;Pi、OpenCode、Hermes 检查 ServerInfo 中相同特性的版本。支持主版本 1,并接受兼容的次版本扩展。声明缺失、
发现接口不可访问或已安装包无法检查,都不能证明兼容。即使 Server 声明当前协议,DSH 原生 MCP 工具目录中仍暴露
旧版集合修改操作时,Doctor 也必须失败。

CLI 检查 DSH、Pi、OpenCode、OpenClaw 和 Hermes 已安装包的 Memory 协议声明。DSH 使用已安装 Host 的解析器定位
选定 Web/Desktop bundle;Pi 使用 `pi list` 返回的路径;OpenClaw 使用原生 `plugins inspect`;OpenCode 在受管理的
bundle 副本旁记录源包声明;Hermes 将声明放在 `powercontext.json`。JS 包使用 `package.json` 的
`powercontext.memoryProtocol` 字段。声明值为 `atomic-artifact-v1`;缺失时返回未验证/degraded。包版本号和注册成功
都不能证明协议兼容。OpenCode 的受管理标记也不能证明另行配置的插件或外部修改后的文件兼容。

原生 MCP 适配器(Codex、Claude Code、WorkBuddy、ZCode、Kimi Code)从 Server 发现工具 schema。它们的 HTTP Hook
成功不能证明会话 MCP 缓存或修改操作正常。恢复步骤见 [协议升级](../docs/operate/atomic-memory-migration.md#客户端与-agent-host-的协议兼容)。
17 changes: 13 additions & 4 deletions docs/zh/docs/integrations/dsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Readiness 保留已识别的依赖状态,包括 HTTP 503 的检查结果,不
| `not_ready` / `degraded` | 检查报告指出的依赖,例如 `database` 或 `inference.generation`,按该项恢复提示处理。 |
| `required_route_missing` | 指定操作返回无业务码的 404;检查代理路由、base path 和版本匹配,404 本身不能确定是版本问题。 |
| `required_route_undeclared` | Server 的 OpenAPI 文档缺少列出的操作声明。 |
| `memory_protocol_mismatch` / `legacy_memory_operation_unsupported` | 对齐 Server/CLI/插件协议,为实际 profile 重新 setup、重启,再搜索取得 Atomic 引用;不得移除集合 CAS。 |
| `contract_unavailable` | 无法核对路由声明;通过同一 base path 提供 `/openapi.json`,或单独核对部署的契约。 |
| `scope_not_found` / `unscoped` | 检查显式 Scope 覆盖、workspace binding 和 Server 默认 Scope;Doctor 不修改它们。 |
| `invalid_response` | 响应未通过协议校验,即使 HTTP status 是 200。 |
Expand All @@ -151,10 +152,10 @@ Readiness 保留已识别的依赖状态,包括 HTTP 503 的检查结果,不
Doctor 不执行 capture、remember、flush、binding 修改或注入。契约不可读时标为未检查;
Scope 不可用时跳过 prepare 并说明原因。实际写入与处理由下方显式验收负责。

独立 CLI 的 `powercontext doctor dsh` 仅检查 Web profile 注册,并明确报告没有观察到运行中宿主的配置,
没有执行 Server 检查。退出成功只表示注册检查通过。
`powercontext doctor` 使用自己的 `--server-url` / `POWERCONTEXT_CLIENT_SERVER_URL`;
对齐 URL 后可复用它的 service/health 诊断,但不能认为它观察到了 DSH 的覆盖配置。
独立 CLI 的 `powercontext doctor dsh` 检查所选 profile 的注册状态和已安装插件 Memory 协议声明,并检查 CLI
解析到的端点上的 Server。这些检查不能观察已运行 DSH 进程的环境覆盖或工具缓存;请重启受影响的 profile,
再在会话里运行 `/pc doctor`。已安装包未声明协议或 Server 契约不可读时,整体结果不会显示成功;注册通过本身
不足以证明兼容。不指定 Host 的 `powercontext doctor` 使用其选定的客户端端点。

## 查看最近一次自动执行

Expand Down Expand Up @@ -388,3 +389,11 @@ Doctor 在 `configuration.readiness_request_timeout_ms` 中报告该预算,同
环回地址默认允许明文 HTTP;远程 HTTP 需要显式设置 `POWERCONTEXT_DSH_ALLOW_INSECURE_HTTP=true`,
HTTPS 证书校验仍然启用。主机地址变量依次读取 `BASE_URL`、`SERVER_URL`、`ENDPOINT`,然后才读取
`POWERCONTEXT_CLIENT_SERVER_URL`。安装与持久化同意见[连接远程 Server](../operate/connect-remote-server.md)。


### Memory 协议升级检查

独立的 `powercontext doctor dsh` 会检查所选 Web/Desktop profile 的注册状态与已安装插件协议声明。缺少声明的旧包
显示为未验证/degraded,并提示更新;不能仅凭包版本号或健康检查判定兼容。会话内的 `/pc doctor` 还会核对 Server 的
Memory 协议声明、Atomic 路由及过期的原生 MCP 修改工具。恢复时保留 `legacy_memory_operation_unsupported`,不移除
CAS、不自动重放写入。具体步骤见 [协议升级](../operate/atomic-memory-migration.md#客户端与-agent-host-的协议兼容)。
29 changes: 29 additions & 0 deletions docs/zh/docs/operate/atomic-memory-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@ description: "备份数据库后,将旧版 Memory 集合离线转换为 Atomic
普通服务启动只做轻量残留检查:公共表中没有旧集合、没有指向旧集合的 lineage,旧 entry 表到公共表的
外键已解除,公共表也不再有旧的 `memory_citations` 列。它不读取归档表或旧 entry 表;逐条完整核验由 `verify` 执行。


## 客户端与 Agent Host 的协议兼容

数据库迁移成功、`/health/live` 或 `/health/ready` 正常,都不能证明插件协议兼容。旧集合引用和集合 CAS
前置条件不能直接重放到 Atomic Memory。HTTP 422 `legacy_memory_operation_unsupported` 表示协议拒绝,
不是临时故障,也不表示可以去掉 CAS 后重试。

1. 将 CLI/SDK 和受影响的插件更新到与 Server 兼容的发布版本或源码 ref。只升级 Server 不会替换 Host 中
已安装的插件;插件自己的包版本号也可能在多个 Server 发布版本间保持不变。
2. 使用预期的 `--source` / `--ref` 和现有服务端地址执行 `powercontext setup HOST`。DSH 要明确选择实际使用的
profile:`powercontext setup dsh --profile web` 或 `powercontext setup dsh --profile desktop`。
3. 完整重启相应 Host 或 Gateway,包括缓存工具 schema 的旧会话。使用更新后的 CLI 执行
`powercontext doctor HOST`。DSH 还要在重启后的会话里执行 `/pc doctor`;Pi、OpenCode 同样提供 `/pc doctor`,
Hermes 在 `/pc status` 中单独展示 Memory 协议检查。
4. 重新搜索或列举,取得 Atomic Memory 的 artifact 引用。修改内容时读取当前内容 ETag,改变生命周期时使用当前
`state_version`。不要移除旧 CAS、猜测新前置条件或自动重放写入。如果旧 SDK 在写入成功后因响应解析失败而报错,
先检查当前记录,再决定是否再次写入。

更新后的独立 Doctor 将 Server 协议声明与健康状态分开报告。已安装包检查覆盖 DSH、Pi、OpenCode、OpenClaw
和 Hermes:`atomic-artifact-v1` 是包声明,与 npm/插件版本号无关。没有声明的包是**兼容性未验证**,不等于已确认
不兼容;诊断会返回 degraded 并提示更新,不再整体显示正常。有声明也不能证明正在运行的进程已经重新加载。
Server 协议发现接口缺失或不可访问时,同样不能判定兼容。发现请求会复用所选 Host 按 URL 绑定的已存凭据。发现接口要求鉴权但没有可用凭据时,
检查显示 skipped 并提示配置凭据,单独这项不会使安装或 Doctor 失败;已配置的凭据被拒绝时仍返回 degraded。
这些只读检查不会执行写入。

Codex、Claude Code、WorkBuddy、ZCode 和 Kimi Code 的 Memory 操作使用 Server 原生 MCP schema。升级 Server 后
需要重新连接这些 Host;Hook 的上下文准备或采集检查不能验证缓存中的 MCP 工具目录。Server 会在 HTTP/MCP 错误
响应中保留原错误码与恢复步骤,Host 适配器不能将其归并为通用 `invalid_request`,也不能引导自动重试。

## 执行顺序

数据库已有 `pc_schema_revision` 或 Server 身份标记时,这个兼容命令将 `plan`、`apply`、`verify`
Expand Down
Loading
Loading