Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 35 additions & 17 deletions docs/en/docs/integrations/dsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -689,23 +689,24 @@ terminal stream and captures the completed turn.

### Turn the plugin's prompt recall and capture off

Turn the plugin's prompt-time recall and prompt capture off before starting DSH:
Turn the plugin's prompt-time recall and prompt capture off, and name the gateway provider, before starting DSH:

```bash
export POWERCONTEXT_DSH_PROMPT_RECALL=false
export POWERCONTEXT_DSH_CAPTURE_PROMPTS=false
export POWERCONTEXT_DSH_GATEWAY_PROVIDER=powercontext-gateway
dsh web
```

The plugin patch settings `promptRecall` and `capturePrompts` do the same. With recall off, the plugin sends no
preparation request and adds no message to the step. The gateway takes the latest user message that is not a
standalone host reminder as the turn's message, so any other message added after the prompt would replace the prompt
as the gateway's recall query and captured user text. The plugin therefore adds the Scope routing to DSH's runtime
context instead, which DSH sends as a `<system-reminder>` user message after the step's messages. DSH sends the runtime
context on a session's first request and again only when any part of it changes, such as the Scope, the approval
policy, or a compaction that replaced it, so a later prompt stays the last user message while the context is
unchanged. The plugin does not provide the [companion memory service](#read-only-companion-memory-service) either,
because that service returns a prepared-context block.
The plugin patch settings `promptRecall`, `capturePrompts`, and `gatewayProvider` do the same. With recall off, the
plugin sends no preparation request and adds no message to the step. The gateway takes the latest user message that is
not a standalone host reminder as the turn's message, so any other message added after the prompt would replace the
prompt as the gateway's recall query and captured user text. The plugin therefore adds the Scope routing to DSH's
runtime context instead, which DSH sends as a `<system-reminder>` user message after the step's messages. DSH sends the
runtime context on a session's first request and again only when any part of it changes, such as the Scope, the approval
policy, or a compaction that replaced it, so a later prompt stays the last user message while the context is unchanged.
The plugin does not provide the [companion memory service](#read-only-companion-memory-service) either, because that
service returns a prepared-context block.

The plugin still resolves the Scope for each prompt and still captures prompts while
`POWERCONTEXT_DSH_CAPTURE_PROMPTS` is `true`; with both off, it sends only Scope resolution for a prompt. The MCP
Expand All @@ -732,6 +733,19 @@ DSH sends these headers to whichever provider serves the request, including one
not forward them upstream. DSH's Responses requests already carry the session ID as `prompt_cache_key` unless the
provider sets `cacheRetention: "none"`.

`POWERCONTEXT_DSH_GATEWAY_PROVIDER` names the `llm-pi-ai` provider that points at the gateway, by its key under
`providers`. While recall is off, the plugin sends the Scope it resolves for the session's workspace, the one `/pc`
prints, as `X-PowerContext-Scope-ID` on every request to that provider, compaction, session-title, and auto-review
requests included. The gateway then prepares and captures turns in that Scope instead of `PC_GATEWAY_DEFAULT_SCOPE`,
and Core checks each request in it. Requests to any other provider carry no Scope header. The plugin resolves the
Scope once per prompt, so a changed binding applies from the next prompt. The request carries no Scope header, and
the gateway uses `PC_GATEWAY_DEFAULT_SCOPE`, when the variable is unset, when the session's latest prompt resolved no
Scope, or when the header cannot carry the Scope's ID, which can happen with a Scope from an early release. In the
last two cases the plugin logs one `gateway_scope` diagnostic for that prompt, with `reason: scope_unresolved` or
`reason: scope_id_unsupported`. For a Scope whose ID the header cannot carry, the plugin's own prompt capture and MCP
tools still use that Scope. See [Gateway request Scope](../operate/deploy-server.md#gateway-request-scope) for the IDs
the header can carry.

Restart DSH after changing these settings, then start a new session. A session in which the plugin recalled context
keeps that context in its history, and DSH resends it with later requests, so Core rejects them. The gateway removes
a plugin block only from a tool result, and on the Responses route also from a developer message; the plugin's
Expand All @@ -748,16 +762,19 @@ default. Set:
- When Core enforces authentication, `PC_GATEWAY_CORE_TOKEN` to an authenticated service identity. Grant it
`server.observer` on the Server resource for `POWERCONTEXT_SERVER_ACCESS_DEPLOYMENT_ID` (default `powercontext`),
and `scope.contributor` (which includes `scope.read`) on `PC_GATEWAY_DEFAULT_SCOPE` and on every Scope that requests
select with `X-PowerContext-Scope-ID`. Because the gateway captures turns, use `scope.contributor` rather than
`scope.viewer`. See
select with `X-PowerContext-Scope-ID`. With `POWERCONTEXT_DSH_GATEWAY_PROVIDER` set, those are the workspace Scopes
that the plugin sends. Because the gateway captures turns, use `scope.contributor` rather than `scope.viewer`. See
[Gateway authentication boundaries](../operate/deploy-server.md#gateway-authentication-boundaries).
- `PC_GATEWAY_SEDIMENT=on`, so that the gateway captures each completed turn as a Source.
- `PC_GATEWAY_DEFAULT_SCOPE` to the Scope this plugin resolves for the workspace, which `/pc` prints.
- `PC_GATEWAY_DEFAULT_SCOPE` to the Scope for requests that carry no Scope header. With
`POWERCONTEXT_DSH_GATEWAY_PROVIDER` unset, set it to the Scope this plugin resolves for the workspace, which `/pc`
prints.

The plugin does not send `X-PowerContext-Scope-ID`, so the gateway prepares and captures every conversation in the one
Scope set by `PC_GATEWAY_DEFAULT_SCOPE`, not in the Scope this plugin resolves for each workspace. For the gateway's
authentication settings and request size limit, see
[Deploy the Server](../operate/deploy-server.md#gateway-authentication-boundaries).
The gateway key does not limit which Scope a request selects: any client that can call the gateway can select any
Scope that the gateway's Core credential can access; see
[Gateway request Scope](../operate/deploy-server.md#gateway-request-scope). When Core enforces authentication, grant
these roles on a new workspace's Scope before DSH works there. For the gateway's authentication settings and request
size limit, see [Deploy the Server](../operate/deploy-server.md#gateway-authentication-boundaries).

## Connect to an authenticated local Server

Expand Down Expand Up @@ -794,6 +811,7 @@ powercontext doctor dsh
| `POWERCONTEXT_DSH_SCOPE_ID` | unset | Explicit existing Scope before workspace binding and Server default |
| `POWERCONTEXT_DSH_AUTHORIZATION` | unset | Complete `Bearer <token>` header for MCP and lifecycle HTTP requests |
| `POWERCONTEXT_DSH_PROMPT_RECALL` | `true` | Prepare and add context before each model step and provide the companion memory service; `false` leaves prompt-time context to the gateway and sends the gateway conversation and internal-turn headers |
| `POWERCONTEXT_DSH_GATEWAY_PROVIDER` | unset | `llm-pi-ai` provider that routes through the gateway; while prompt recall is off, only its requests carry the session's Scope as `X-PowerContext-Scope-ID` |
| `POWERCONTEXT_DSH_CAPTURE_PROMPTS` | `true` | Capture user prompts as Source evidence |
| `POWERCONTEXT_DSH_FLUSH_ON_CAPTURE` | `false` | Wait for Source processing after capture |

Expand Down
31 changes: 24 additions & 7 deletions docs/zh/docs/integrations/dsh.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,16 @@ enforcing 模式的 Core 会扣留流式响应,gateway 返回 HTTP 400。

### 关闭插件的提示词召回和采集

启动 DSH 前,关闭插件的提示词时召回和提示词采集:
启动 DSH 前,关闭插件的提示词时召回和提示词采集,并指定 gateway provider:

```bash
export POWERCONTEXT_DSH_PROMPT_RECALL=false
export POWERCONTEXT_DSH_CAPTURE_PROMPTS=false
export POWERCONTEXT_DSH_GATEWAY_PROVIDER=powercontext-gateway
dsh web
```

插件 patch 配置 `promptRecall` 和 `capturePrompts` 的作用相同。关闭召回后,插件不发送准备请求,
插件 patch 配置 `promptRecall`、`capturePrompts` 和 `gatewayProvider` 的作用相同。关闭召回后,插件不发送准备请求,
也不向这一步添加任何消息。gateway 把最近一条不是独立宿主提醒的用户消息当作这一轮的消息,
因此加在提示词之后的其他消息,都会取代提示词成为 gateway 的召回查询和采集的用户文本。
所以插件把 Scope 路由加到 DSH 的运行时上下文中,DSH 会把它作为 `<system-reminder>` 用户消息,
Expand Down Expand Up @@ -628,6 +629,19 @@ gateway 仍会让 Core 检查这类请求,但不为它准备或注入上下文
DSH 会把这些请求头发给处理该请求的任何 provider,包括它直接调用的 provider;gateway 不会把它们转发给上游。
除非 provider 设置了 `cacheRetention: "none"`,DSH 的 Responses 请求本来就以 `prompt_cache_key` 携带会话 ID。

`POWERCONTEXT_DSH_GATEWAY_PROVIDER` 以 `providers` 下的键指定指向 gateway 的 `llm-pi-ai` provider。
关闭召回后,插件会把它为会话 workspace 解析的 Scope(即 `/pc` 打印的 Scope)作为 `X-PowerContext-Scope-ID`,
发送到这个 provider 的每个请求上,压缩、会话标题和 auto review 请求也包括在内。
gateway 随后在这个 Scope 而不是 `PC_GATEWAY_DEFAULT_SCOPE` 中准备和采集各轮,Core 也在这个 Scope 中检查每个请求。
发给其他 provider 的请求不带 Scope 请求头。插件每条提示词解析一次 Scope,因此 binding 改变后,从下一条提示词起生效。
未设置这个变量、会话最近一条提示词没有解析出 Scope,
或请求头无法携带该 Scope 的 ID(早期版本的 Scope 可能如此)时,
请求不带 Scope 请求头,gateway 使用 `PC_GATEWAY_DEFAULT_SCOPE`。
在后两种情况下,插件为这条提示词记录一条 `gateway_scope` 诊断,
`reason` 为 `scope_unresolved` 或 `scope_id_unsupported`。
对于请求头无法携带其 ID 的 Scope,插件自己的提示词采集和 MCP 工具仍使用该 Scope。
请求头能携带哪些 ID,见[Gateway 请求 Scope](../operate/deploy-server.md#gateway-请求-scope)。

修改这些设置后请重启 DSH,然后新建会话。插件召回过上下文的会话会在历史中保留这些上下文,
DSH 之后的请求会再次发送它们,因此 Core 会拒绝这些请求。gateway 只从工具结果中移除插件块,
在 Responses 路由上还会从 developer 消息中移除;插件的快照是用户消息。
Expand All @@ -642,15 +656,17 @@ DSH 之后的请求会再次发送它们,因此 Core 会拒绝这些请求。g
- Core 启用鉴权时,把 `PC_GATEWAY_CORE_TOKEN` 设为经过认证的服务身份。
请在 `POWERCONTEXT_SERVER_ACCESS_DEPLOYMENT_ID`(默认 `powercontext`)对应的 Server 资源上授予它 `server.observer`,
并在 `PC_GATEWAY_DEFAULT_SCOPE` 以及每个通过 `X-PowerContext-Scope-ID` 选择的 Scope 上授予 `scope.contributor`(包含 `scope.read`)。
设置 `POWERCONTEXT_DSH_GATEWAY_PROVIDER` 后,这些 Scope 就是插件发送的各个 workspace Scope。
gateway 会采集各轮,因此请使用 `scope.contributor` 而不是 `scope.viewer`。
见[网关认证边界](../operate/deploy-server.md#网关认证边界)。
- `PC_GATEWAY_SEDIMENT=on`,让 gateway 把每个完成的轮次采集为 Source。
- `PC_GATEWAY_DEFAULT_SCOPE` 设为插件为该 workspace 解析的 Scope,`/pc` 会打印这个 Scope。
- `PC_GATEWAY_DEFAULT_SCOPE` 设为不带 Scope 请求头的请求所用的 Scope。
未设置 `POWERCONTEXT_DSH_GATEWAY_PROVIDER` 时,把它设为插件为该 workspace 解析的 Scope,`/pc` 会打印这个 Scope。

插件不发送 `X-PowerContext-Scope-ID`,
因此 gateway 把所有会话都放在 `PC_GATEWAY_DEFAULT_SCOPE` 指定的同一个 Scope 中准备和采集,
而不是插件为每个 workspace 解析的 Scope。gateway 的鉴权设置和请求大小上限,
见[部署 Server](../operate/deploy-server.md#网关认证边界)。
gateway 密钥不限制请求选择哪个 Scope:任何能调用 gateway 的客户端,
都能选择 gateway 的 Core 凭据可访问的任何 Scope。见[Gateway 请求 Scope](../operate/deploy-server.md#gateway-请求-scope)。
Core 启用鉴权时,DSH 在新的 workspace 中工作之前,请先在它的 Scope 上授予这些角色。
gateway 的鉴权设置和请求大小上限,见[部署 Server](../operate/deploy-server.md#网关认证边界)。

## 连接启用鉴权的本地 Server

Expand Down Expand Up @@ -687,6 +703,7 @@ powercontext doctor dsh
| `POWERCONTEXT_DSH_SCOPE_ID` | 未设置 | 在 workspace binding 和 Server 默认值之前显式选择已有 Scope |
| `POWERCONTEXT_DSH_AUTHORIZATION` | 未设置 | MCP 与生命周期 HTTP 请求使用的完整 `Bearer <token>` header |
| `POWERCONTEXT_DSH_PROMPT_RECALL` | `true` | 每次模型调用前准备并添加上下文,并提供桌宠记忆服务;`false` 把提示词时上下文交给 gateway,并发送 gateway 会话请求头和 internal 轮次请求头 |
| `POWERCONTEXT_DSH_GATEWAY_PROVIDER` | 未设置 | 经由 gateway 的 `llm-pi-ai` provider;关闭提示词召回时,只有它的请求以 `X-PowerContext-Scope-ID` 携带会话的 Scope |
| `POWERCONTEXT_DSH_CAPTURE_PROMPTS` | `true` | 把用户提示词采集为 Source 证据 |
| `POWERCONTEXT_DSH_FLUSH_ON_CAPTURE` | `false` | 采集后等待 Source 处理 |

Expand Down
9 changes: 6 additions & 3 deletions integrations/dsh/plugins/powercontext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ make js-api-generate-check
```

The plugin resolves an explicit Scope, a durable workspace binding, or the Server default. Environment overrides use
the `POWERCONTEXT_DSH_` prefix for `BASE_URL`, `AUTHORIZATION`, `SCOPE_ID`, `PROMPT_RECALL`, `CAPTURE_PROMPTS`, and
`FLUSH_ON_CAPTURE`. Set `POWERCONTEXT_DSH_PROMPT_RECALL=false` when DeepSeek Harness reaches its model through the
PowerContext gateway, which then prepares context for each turn.
the `POWERCONTEXT_DSH_` prefix for `BASE_URL`, `AUTHORIZATION`, `SCOPE_ID`, `PROMPT_RECALL`, `GATEWAY_PROVIDER`,
`CAPTURE_PROMPTS`, and `FLUSH_ON_CAPTURE`. Set `POWERCONTEXT_DSH_PROMPT_RECALL=false` when DeepSeek Harness reaches its
model through the PowerContext gateway, which then prepares context for each turn, and set
`POWERCONTEXT_DSH_GATEWAY_PROVIDER` to the gateway's `llm-pi-ai` provider so that the gateway works in the workspace's
Scope. A Scope whose ID the gateway's Scope header cannot carry, which can happen with a Scope from an early release,
is not sent; the gateway then uses its default Scope, and the plugin logs a `gateway_scope` diagnostic.
`timeoutMs`, `requestTimeoutMs`, `maxBytes`, `flushMaxCalls`, and `ownerLocal` are plugin patch settings. Context
returned by recall is labelled as untrusted history. An unavailable Server never blocks normal Harness work.

Expand Down
2 changes: 2 additions & 0 deletions integrations/dsh/plugins/powercontext/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ interface PluginConfig {
maxBytes?: number;
/** Prepare and inject context before each model step; turn off when a gateway does this. */
promptRecall?: boolean;
/** The `llm-pi-ai` provider that routes model requests through the gateway; only it receives the Scope header. */
gatewayProvider?: string;
capturePrompts?: boolean;
flushOnCapture?: boolean;
flushMaxCalls?: number;
Expand Down
Loading