Skip to content

feat(plugins): seal secrets in Claude Code and pi - #8445

Merged
t0saki merged 4 commits into
volcengine:mainfrom
t0saki:feat/plugins-seal-secrets
Nov 26, 2026
Merged

t0saki merged 4 commits into
volcengine:mainfrom
t0saki:feat/plugins-seal-secrets

Conversation

@t0saki

@t0saki t0saki commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Plugin part of the RFC in #7335 ("Agent 密钥可用不可见") and its supplement on auto-enrollment (comment).

With the new setting sealSecrets on, the Claude Code plugin and the pi extension replace the user's secrets with {{ov_privacy:…}} references in what the user types and in every tool result before the model sees them, and turn a reference the model writes into a tool call back into the real value before the tool runs. It runs on the user's machine and needs no gateway. It is off by default. Once it is on, what cannot be sealed is stopped rather than sent unsealed.

Stacked on #8408 (server feature table) and #8384 (server seal endpoint). Until those merge, their commits show up here as the first two; review only the last commit, feat(plugins): seal secrets in Claude Code and pi.

This PR was split out of #8384, which used to hold the server, gateway and plugin parts together. The gateway part is #8444, which sits on top of this PR because it reads the feature table row added here.

What changes

  • One shared core, examples/memory-plugin-shared/lib/seal-core.mjs, and two thin adapters. The core calls the seal and resolve endpoints, builds the sealed text from the returned spans, and reads server support from the feature table row privacy_seal (0.5.7).
  • Feature table row. Adds "privacy_seal": "0.5.7" to the server feature table from feat(gateway,plugins): one table for the server features clients depend on #8408, with its synced gateway copy, the type union and the shared version cases.
  • Claude Code: hooks-module mods seal the prompt, tool results and attached files, and unseal tool arguments. The mod itself explains references to the model, with the first prompt it seals in a session and again after a compaction, so the explanation appears only where sealing actually runs.
  • pi: handlers on input, tool_result and tool_call seal before pi stores or sends anything, so the session file holds references too.
  • New tokens the user types are stored by the server in the auto category, and the model is asked to save them under a proper name. enrollToolSecrets (off by default) also stores tokens found in tool output.
  • When sealing cannot be done, it stops. Server too old, version unreadable, or a failed call: the input is not sent, a tool result is withheld, a tool call whose references cannot be resolved does not run. The message names the case and what to do (upgrade or reach the server, or turn sealSecrets off). There is no option that lets such traffic through. After a stop the server is asked again on the next prompt, so sealing resumes once the server can seal, without a new session.
  • The openviking-memory skill gains a "Saved credentials" section (references, ov privacy run, naming with a description), synced to every host.
  • The URI guard no longer fires on viking:// inside a privacy reference.
  • Docs: the plugin READMEs and the Claude Code and pi integration pages (en and zh).

Size

67 files, +4676/−62 in this PR's own commit. About 1350 of those lines are generated copies (the synced scripts/shared/* files and the 12 copies of the skill text). Written by hand: about 1480 lines of source, 1660 of tests and 180 of docs.

How it was tested

On this branch, rebased on main at b6ab3ef (the node tests, claude plugin test and the two checks were rerun there; the docs rows are from the previous base, and the docs have not changed since):

Suite Result
examples/memory-plugin-shared node tests 620 of 628 passed, 7 failed, 1 skipped
Claude Code node tests (scripts, scripts/lib) 91 passed
claude plugin test (mods/seal/seal.test.ts, Claude Code 2.1.331) 26 passed
pi node tests 314 passed, 7 skipped
Codex, agent-hook, OpenCode, magpie node tests 208 / 147 / 70 / 220 passed
Sync check, plugin version-bump check pass
Docs: check:docs, check:api pass
Docs: site build, built-anchor check pass two rebases ago, not rerun since

The 7 failing shared tests need the zip command, which the machine I ran on does not have; they fail the same way on main. The dsh plugin's tests were not run: they need the semver package, which is not installed there. The skipped one compares the session text with the gateway's and skips while the gateway source is absent; it passes on a tree that has both PRs.

mods/seal/seal.test.ts runs only under claude plugin test, which CI does not run.

End to end with a real model (deepseek-v4-1-flash) and a recording proxy in front of the model endpoint, on the combined tree before the split and before the last rebase (the stopping behaviour was then behind an option, sealSecretsStrict; it is now the only behaviour and was not rerun end to end): Claude Code 2.1.331 and pi 1.6.0, each with the plugin only. The user typed a new token; no request to the provider carried it; the model saved the entry as credential/github with a description by passing the temporary reference to privacy_upsert, then used it through ov privacy run; the tool got the real value.

Known limits

  • With sealSecrets on, prompts are stopped while the server is unreachable or older than 0.5.7. That is the intended trade: the setting is opt-in, and it promises that nothing goes on unsealed.
  • Plugin-side sealing does not cover the system prompt, slash-command arguments or history from before it was turned on.
  • Claude Code reads the setting through a small helper process. On surfaces without the process API (the Desktop Code tab, the VS Code panel) sealing stays off, and the model is not told about references; if OPENVIKING_SEAL_SECRETS=1 asks for it there, prompts are stopped with that reason.
  • OpenViking's own tools are recognised by name. If the OpenViking MCP server is registered under a name without openviking, references in calls to its tools reach the tool as values.
  • Encoded file content in a tool result (a data: URI, or long base64 under data / file_data) is not scanned. A long base64 string under any other key is.
  • Only Claude Code and pi seal. Codex, OpenCode, agent-hook, dsh and magpie get the skill text, the config fields (no effect there) and a version bump.

Notes for reviewers

  • All seven plugins take a second patch bump on top of the one in feat(gateway,plugins): one table for the server features clients depend on #8408, because the shared library changes again here and check-plugin-version-bumps.sh counts that as a change to each of them.
  • The comparison "gateway or plugin" (table and figure) and the links between the plugin pages and the gateway page are left out of both PRs, so that each one's docs build alone. A small follow-up adds them once both have merged.

https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

…nd on

The gateway and the plugins each need to know whether the OpenViking server
they talk to already has a capability, and today each answers that on its
own: the gateway hard-codes "0.5.0" for working memory opt-in, and a plugin
that needed the same answer would carry its own number and its own version
parser. Two copies of a fact drift, and two parsers disagree about the same
string.

examples/memory-plugin-shared/lib/server-features.json now lists each such
capability with the first server version that has it. The JS reader
(lib/server-features.mjs) answers for the plugins; the sync script copies
the table byte for byte into the gateway package, where client.py reads it.
Rules for a row, and the steps to add one, are in the shared README: the
version is the next unreleased release when the server change merges, only
the release part counts (0.5.7.dev44 is 0.5.7), an unreadable version counts
as not supporting, and callers ask the table instead of inferring support
from a 404.

The gateway's working memory check now reads its version from the table and
is otherwise unchanged: it still goes through health(), so a /health that
fails, a root key, or a version below the gateway minimum or unreadable stops
create_session and commit as before. One answer does move: under the
release-part rule, pre-releases and dev builds of 0.5.0 (0.5.0rc1,
0.5.0.devN) now count as 0.5.0 and get the 0.5.0 bodies.

Both readers take (feature, version) and accept PEP 440 and nothing else, so
they give the same answer for the same string; tests/fixtures holds one list
of version cases that both test suites run, and both the gateway workflow and
the plugin job now trigger on it. The sync now carries a JSON file a module
reads beside itself along with that module, and the PR check fails when the
gateway's committed copy differs from the source.

No plugin imports the reader yet, so no plugin ships a copy in this change;
the "every shared module is reachable" test exempts server-features.mjs. Its
first consumer is the privacy seal change, whose plugins import it for
featureStatus and healthVersion; that change removes the exemption. Every
distributed plugin still gets a patch bump, because the version check counts
any change under memory-plugin-shared/lib as a change to all of them.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/plugins-seal-secrets branch from 796834e to 568d713 Compare November 26, 2026 07:16
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on volcengine#8384 (the seal endpoint and the `auto`
category), on volcengine#8408 (the server feature table `supports` comes from) and
on volcengine#8445, which adds the table's `privacy_seal` row. This branch sits on
volcengine#8445.

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is volcengine#8445. The gateway code uses nothing from it but
that row. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New tokens in the latest user message are stored by the server in the
  `auto` category; the model gets a note asking it to save the entry
  under a proper name with privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/plugins-seal-secrets branch from 568d713 to 5c41722 Compare November 26, 2026 07:30
… values

A secret pasted into an agent conversation is sent to the model provider
with that message and again with every later request. This change gives
OpenViking the server half of "sealing": clients send model-bound text to
the server, get it back with the user's secrets replaced by
{{ov_privacy:...}} references, and turn references back into values only
when a tool runs. This PR is the server side only; the gateway and the
Claude Code and pi plugin halves are in their own pull requests and are
not in this PR.

It touches no plugin or gateway file and sits directly on main. The
`privacy_seal` row of the server feature table (volcengine#8408) comes with the
plugin PR, the first client that reads it.

What it adds:
- POST /api/v1/privacy-configs/seal takes a list of texts and returns,
  per text, the spans whose value matched a registered secret, with the
  reference that replaces it. Matching covers the current and earlier
  versions of `credential` targets and the `auto` category, so a rotated
  token is still replaced. It works whatever the user's privacy mode is,
  fails with an error rather than returning unsealed text, and returns a
  revision that callers can cache results on.
- Texts marked `enroll` also have new tokens found by the existing
  detector stored, each in its own target of a new `auto` category under
  a generated name, and replaced. A span reports `temporary` while its
  target is still in `auto` and `created` when this call stored it. One
  call stores at most 1024 new values. A match longer than a stored
  value may be (64 KiB) is left as it is. Only this endpoint writes to
  `auto`; upsert and patch reject `category=auto`.
- A value given to upsert, patch or the MCP `privacy_upsert` tool may be
  a whole reference: the server copies the referenced field's value, and
  removes the source when it was an `auto` entry. This is how a model
  gives a temporary entry a proper name without ever seeing the value.
  When a reference was given, the response shows references, not values.
- A target can carry a description; `privacy_upsert` takes it and the
  privacy tree returns it. MCP `privacy_tree` leaves `auto` out unless it
  is asked for.
- The endpoint's own state (the credential revision and the enroll lock)
  lives under the user's settings/ directory, not in the privacy
  category namespace.

Behaviour changes for existing callers of upsert, patch and the storage
sanitizer:
- A value that contains {{ov_privacy: inside a longer string is now
  rejected with INVALID_ARGUMENT in every category; before, it was stored
  literally.
- A top-level value that is a whole reference used to be stored literally;
  it is now replaced by the referenced field's value.
- Upsert and patch with category=auto are rejected.
- The sanitizer's credential revision moved from an in-process counter to
  a file under settings/. Every storage-path sanitize reads it, the first
  sanitize for a user writes it under a lock, and every credential write
  takes an exact lock and bumps it. This fixes the cross-worker cache
  staleness that the TTL used to paper over.
- Credential warnings are computed on the stored values after the write.

Docs: the seal endpoint and the reference-as-value rules in the Privacy
API reference (en and zh).

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
A secret a user pastes into an agent conversation goes to the model
provider with that message and with every later request. This adds
plugin-side sealing to the Claude Code plugin and the pi extension: with
`sealSecrets` on, what the user types and every tool result reach the
model with the user's secrets replaced by {{ov_privacy:...}} references,
and a reference the model writes into a tool call is turned back into the
real value before the tool runs. It runs on the user's machine and uses
the server's seal endpoint (POST /api/v1/privacy-configs/seal, server
0.5.7 or newer, from the privacy PR this one is based on); it needs no
gateway and does not depend on the gateway PR.

- One shared core, memory-plugin-shared/lib/seal-core.mjs, talks to the
  seal and resolve endpoints, builds sealed text from the returned spans
  and decides support from the server feature table row `privacy_seal`.
  Claude Code and pi now import the table's reader, so the sync test no
  longer exempts server-features.mjs.
- The server feature table (volcengine#8408) gets the row "privacy_seal": "0.5.7",
  the first release with the endpoint; its synced gateway copy, the type
  union and the shared version fixture move with it.
- Claude Code: hooks-module mods on prompt submit, tool calls and
  attachments seal the prompt, tool results and the files, reminders and
  hook context Claude Code attaches; the first sealed prompt of a session
  (and the first after a compaction) carries the text that explains
  references to the model. The setting is read once per session by a
  small helper process; where that cannot run (surfaces without the
  process API, such as the Desktop Code tab or the VS Code panel),
  sealing stays off silently unless OPENVIKING_SEAL_SECRETS=1 asks for it,
  and then prompts are stopped with the reason.
- pi: handlers on input, tool_result and tool_call seal before pi stores
  or sends anything, so the session file holds references too.
- New tokens in what the user types are stored by the server in the
  `auto` category, and the model is asked to save them under a proper
  name. `enrollToolSecrets` (off by default) also stores new tokens found
  in tool output.
- Once sealing is on, nothing goes on unsealed: when the server is too
  old, its version cannot be read or a call fails, the input is stopped,
  the tool result withheld or the tool call blocked, with a message that
  names the case and what to do. After a stop the server is asked again,
  so sealing resumes once it can seal.
- The openviking-memory skill gains a "Saved credentials" section on
  references and the `ov privacy` CLI, synced to every host.
- The URI guard no longer fires on viking:// inside a privacy reference.

Both settings are off by default and can be set in ovcli.conf or
the environment. Docs: the plugin READMEs and the Claude Code and pi
integration pages (en and zh).

Not in this PR:
- Only Claude Code and pi seal. codex, opencode, agent-hook, dsh and
  magpie get only the skill text, the config knobs (no effect there) and
  a version bump.
- The gateway side of sealing is a separate PR on top of this one,
  because it reads the `privacy_seal` row added here. Nothing here names
  a gateway option or links to gateway pages.
  The comparison of sealing in the plugin and in the gateway (table and
  figure) and the cross-links between the two docs come in a follow-up
  once both have merged. One shared test compares the session text with
  the gateway's and skips while the gateway source is absent.
- mods/seal/seal.test.ts runs only under `claude plugin test`, which CI
  does not run; it passed locally (26/26 with sources.test.ts, Claude
  Code 2.1.331). `tsc -p mods/seal` was not run, since it needs the types
  `claude --plugin-dir` generates.
- This branch sits on volcengine#8408 and the server PR. volcengine#8408 already bumps
  every plugin once; the second patch bump here is expected, because the
  shared library changes again.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/plugins-seal-secrets branch from 5c41722 to b5f9444 Compare November 26, 2026 08:07
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on volcengine#8384 (the seal endpoint and the `auto`
category), on volcengine#8408 (the server feature table `supports` comes from) and
on volcengine#8445, which adds the table's `privacy_seal` row. This branch sits on
volcengine#8445.

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is volcengine#8445. The gateway code uses nothing from it but
that row. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New tokens in the latest user message are stored by the server in the
  `auto` category; the model gets a note asking it to save the entry
  under a proper name with privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

@ZaynJarvis ZaynJarvis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

# Conflicts:
#	examples/agent-hook-plugin/hosts/codebuddy/plugin.json
#	examples/agent-hook-plugin/hosts/cursor/openviking.integration.json
#	examples/agent-hook-plugin/hosts/kimicode/kimi.plugin.json
#	examples/agent-hook-plugin/hosts/kimicode/openviking.integration.json
#	examples/agent-hook-plugin/hosts/qoder/plugin.json
#	examples/agent-hook-plugin/hosts/trae/openviking.integration.json
#	examples/agent-hook-plugin/hosts/zcode/openviking.integration.json
#	examples/agent-hook-plugin/plugin.json
#	examples/claude-code-memory-plugin/.claude-plugin/plugin.json
#	examples/claude-code-memory-plugin/package.json
#	examples/codex-memory-plugin/.codex-plugin/plugin.json
#	examples/dsh-memory-plugin/package-lock.json
#	examples/dsh-memory-plugin/package.json
#	examples/magpie-memory-plugin/README.md
#	examples/magpie-memory-plugin/README_CN.md
#	examples/magpie-memory-plugin/package.json
#	examples/memory-plugin-shared/lib/server-features.d.mts
#	examples/memory-plugin-shared/lib/server-features.json
#	examples/opencode-plugin/package.json
#	examples/pi-coding-agent-extension/package-lock.json
#	examples/pi-coding-agent-extension/package.json
#	openviking_gateway/server-features.json
#	tests/fixtures/server_feature_versions.json
@t0saki
t0saki merged commit 659a027 into volcengine:main Nov 26, 2026
15 of 16 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Nov 26, 2026
t0saki added a commit that referenced this pull request Nov 26, 2026
…ls (#8444)

* feat(gateway,plugins): one table for the server features clients depend on

The gateway and the plugins each need to know whether the OpenViking server
they talk to already has a capability, and today each answers that on its
own: the gateway hard-codes "0.5.0" for working memory opt-in, and a plugin
that needed the same answer would carry its own number and its own version
parser. Two copies of a fact drift, and two parsers disagree about the same
string.

examples/memory-plugin-shared/lib/server-features.json now lists each such
capability with the first server version that has it. The JS reader
(lib/server-features.mjs) answers for the plugins; the sync script copies
the table byte for byte into the gateway package, where client.py reads it.
Rules for a row, and the steps to add one, are in the shared README: the
version is the next unreleased release when the server change merges, only
the release part counts (0.5.7.dev44 is 0.5.7), an unreadable version counts
as not supporting, and callers ask the table instead of inferring support
from a 404.

The gateway's working memory check now reads its version from the table and
is otherwise unchanged: it still goes through health(), so a /health that
fails, a root key, or a version below the gateway minimum or unreadable stops
create_session and commit as before. One answer does move: under the
release-part rule, pre-releases and dev builds of 0.5.0 (0.5.0rc1,
0.5.0.devN) now count as 0.5.0 and get the 0.5.0 bodies.

Both readers take (feature, version) and accept PEP 440 and nothing else, so
they give the same answer for the same string; tests/fixtures holds one list
of version cases that both test suites run, and both the gateway workflow and
the plugin job now trigger on it. The sync now carries a JSON file a module
reads beside itself along with that module, and the PR check fails when the
gateway's committed copy differs from the source.

No plugin imports the reader yet, so no plugin ships a copy in this change;
the "every shared module is reachable" test exempts server-features.mjs. Its
first consumer is the privacy seal change, whose plugins import it for
featureStatus and healthVersion; that change removes the exemption. Every
distributed plugin still gets a patch bump, because the version check counts
any change under memory-plugin-shared/lib as a change to all of them.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

* feat(privacy): seal endpoint, auto-enrolled credentials and reference values

A secret pasted into an agent conversation is sent to the model provider
with that message and again with every later request. This change gives
OpenViking the server half of "sealing": clients send model-bound text to
the server, get it back with the user's secrets replaced by
{{ov_privacy:...}} references, and turn references back into values only
when a tool runs. This PR is the server side only; the gateway and the
Claude Code and pi plugin halves are in their own pull requests and are
not in this PR.

It touches no plugin or gateway file and sits directly on main. The
`privacy_seal` row of the server feature table (#8408) comes with the
plugin PR, the first client that reads it.

What it adds:
- POST /api/v1/privacy-configs/seal takes a list of texts and returns,
  per text, the spans whose value matched a registered secret, with the
  reference that replaces it. Matching covers the current and earlier
  versions of `credential` targets and the `auto` category, so a rotated
  token is still replaced. It works whatever the user's privacy mode is,
  fails with an error rather than returning unsealed text, and returns a
  revision that callers can cache results on.
- Texts marked `enroll` also have new tokens found by the existing
  detector stored, each in its own target of a new `auto` category under
  a generated name, and replaced. A span reports `temporary` while its
  target is still in `auto` and `created` when this call stored it. One
  call stores at most 1024 new values. A match longer than a stored
  value may be (64 KiB) is left as it is. Only this endpoint writes to
  `auto`; upsert and patch reject `category=auto`.
- A value given to upsert, patch or the MCP `privacy_upsert` tool may be
  a whole reference: the server copies the referenced field's value, and
  removes the source when it was an `auto` entry. This is how a model
  gives a temporary entry a proper name without ever seeing the value.
  When a reference was given, the response shows references, not values.
- A target can carry a description; `privacy_upsert` takes it and the
  privacy tree returns it. MCP `privacy_tree` leaves `auto` out unless it
  is asked for.
- The endpoint's own state (the credential revision and the enroll lock)
  lives under the user's settings/ directory, not in the privacy
  category namespace.

Behaviour changes for existing callers of upsert, patch and the storage
sanitizer:
- A value that contains {{ov_privacy: inside a longer string is now
  rejected with INVALID_ARGUMENT in every category; before, it was stored
  literally.
- A top-level value that is a whole reference used to be stored literally;
  it is now replaced by the referenced field's value.
- Upsert and patch with category=auto are rejected.
- The sanitizer's credential revision moved from an in-process counter to
  a file under settings/. Every storage-path sanitize reads it, the first
  sanitize for a user writes it under a lock, and every credential write
  takes an exact lock and bumps it. This fixes the cross-worker cache
  staleness that the TTL used to paper over.
- Credential warnings are computed on the stored values after the write.

Docs: the seal endpoint and the reference-as-value rules in the Privacy
API reference (en and zh).

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

* feat(plugins): seal secrets in Claude Code and pi

A secret a user pastes into an agent conversation goes to the model
provider with that message and with every later request. This adds
plugin-side sealing to the Claude Code plugin and the pi extension: with
`sealSecrets` on, what the user types and every tool result reach the
model with the user's secrets replaced by {{ov_privacy:...}} references,
and a reference the model writes into a tool call is turned back into the
real value before the tool runs. It runs on the user's machine and uses
the server's seal endpoint (POST /api/v1/privacy-configs/seal, server
0.5.7 or newer, from the privacy PR this one is based on); it needs no
gateway and does not depend on the gateway PR.

- One shared core, memory-plugin-shared/lib/seal-core.mjs, talks to the
  seal and resolve endpoints, builds sealed text from the returned spans
  and decides support from the server feature table row `privacy_seal`.
  Claude Code and pi now import the table's reader, so the sync test no
  longer exempts server-features.mjs.
- The server feature table (#8408) gets the row "privacy_seal": "0.5.7",
  the first release with the endpoint; its synced gateway copy, the type
  union and the shared version fixture move with it.
- Claude Code: hooks-module mods on prompt submit, tool calls and
  attachments seal the prompt, tool results and the files, reminders and
  hook context Claude Code attaches; the first sealed prompt of a session
  (and the first after a compaction) carries the text that explains
  references to the model. The setting is read once per session by a
  small helper process; where that cannot run (surfaces without the
  process API, such as the Desktop Code tab or the VS Code panel),
  sealing stays off silently unless OPENVIKING_SEAL_SECRETS=1 asks for it,
  and then prompts are stopped with the reason.
- pi: handlers on input, tool_result and tool_call seal before pi stores
  or sends anything, so the session file holds references too.
- New tokens in what the user types are stored by the server in the
  `auto` category, and the model is asked to save them under a proper
  name. `enrollToolSecrets` (off by default) also stores new tokens found
  in tool output.
- Once sealing is on, nothing goes on unsealed: when the server is too
  old, its version cannot be read or a call fails, the input is stopped,
  the tool result withheld or the tool call blocked, with a message that
  names the case and what to do. After a stop the server is asked again,
  so sealing resumes once it can seal.
- The openviking-memory skill gains a "Saved credentials" section on
  references and the `ov privacy` CLI, synced to every host.
- The URI guard no longer fires on viking:// inside a privacy reference.

Both settings are off by default and can be set in ovcli.conf or
the environment. Docs: the plugin READMEs and the Claude Code and pi
integration pages (en and zh).

Not in this PR:
- Only Claude Code and pi seal. codex, opencode, agent-hook, dsh and
  magpie get only the skill text, the config knobs (no effect there) and
  a version bump.
- The gateway side of sealing is a separate PR on top of this one,
  because it reads the `privacy_seal` row added here. Nothing here names
  a gateway option or links to gateway pages.
  The comparison of sealing in the plugin and in the gateway (table and
  figure) and the cross-links between the two docs come in a follow-up
  once both have merged. One shared test compares the session text with
  the gateway's and skips while the gateway source is absent.
- mods/seal/seal.test.ts runs only under `claude plugin test`, which CI
  does not run; it passed locally (26/26 with sources.test.ts, Claude
  Code 2.1.331). `tsc -p mods/seal` was not run, since it needs the types
  `claude --plugin-dir` generates.
- This branch sits on #8408 and the server PR. #8408 already bumps
  every plugin once; the second patch bump here is expected, because the
  shared library changes again.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

* feat(gateway): seal secrets out of model requests and unseal tool calls

A secret a user pastes into a conversation goes to the model provider with
that message and with every later request. This adds a context-profile
switch, `seal_secrets` (off by default), that makes the gateway send a
user's registered secrets, and new tokens the user types, to the provider
only as {{ov_privacy:...}} references, while client tools still get the
real value. It uses the server's seal endpoint (POST
/api/v1/privacy-configs/seal, server 0.5.7 or newer).

Depends on #8384 (the seal endpoint and the `auto`
category), on #8408 (the server feature table `supports` comes from) and
on #8445, which adds the table's `privacy_seal` row. This branch sits on
#8445.

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is #8445. The gateway code uses nothing from it but
that row. The "gateway or plugin" comparison moved to that PR, and the
cross-links between the gateway and plugin pages follow once both merge.

How it works:
- Before a request leaves, the gateway sends the content of every JSON
  model request (user, assistant and system text, tool results, attached
  blocks, history) to the seal endpoint with the user's own key and
  writes the references back. Structure is not touched (model, tool
  names, IDs, schemas, signed reasoning); JSON inside strings is
  rewritten in place. A final sweep covers what the gateway adds itself:
  recall, compaction summaries and its hidden OpenViking tool rounds.
  Results are cached in process memory by user, revision and text, never
  in shared storage.
- New tokens in the latest user message are stored by the server in the
  `auto` category; the model gets a note asking it to save the entry
  under a proper name with privacy_upsert, plus a short explanation of
  references. A conversation that started before the switch was turned on
  gets the explanation once, with its next turn. `enroll_tool_secrets` (off by default) also stores new
  tokens from tool output and attached blocks, without a note.
- References the model writes into client tool-call arguments are turned
  back into values in what the client receives. Assistant text, the
  gateway's own records, OpenViking's own tools and `ov privacy` commands
  keep the reference. With sealing on, tool-call arguments are no longer
  streamed piece by piece; replies the kernel did not prepare go through
  an unseal-only relay.
- Conversation identity ignores which reference a secret maps to, so
  saving, renaming or rotating a credential does not split a session. This
  applies whether or not sealing is on, and NORMALIZATION_VERSION stays as
  it is: a stored conversation whose history already holds a literal
  {{ov_privacy:...}} reference (from privacy configs or `ov privacy run`)
  hashes differently after the upgrade and starts a new gateway session
  once, losing its recorded injection. This is a one-time effect.

Once sealing is on, nothing goes out unsealed. When the server is too old,
its version cannot be read, a seal call fails or the request cannot be
sealed, the request is refused: 503 `secret_seal_failed` (the call failed
or the server cannot seal) or 400 `secret_seal_invalid_request` (the
request cannot be sealed). A reply whose tool calls cannot be unsealed
fails with 502 `secret_unseal_failed`. Each message names the case and
what to do. Support is decided from the server feature table row
`privacy_seal` through a new `VikingClient.server_version`; the version is
read again within 30 s, so sealing resumes without a gateway restart. Seal
and resolve calls count toward the per-account OpenViking circuit breaker
like any other call. The `X-OpenViking-Context` header cannot set either
switch.

Also: the Studio profile editor gets the two switches, request records
count `secrets_sealed`, `secrets_enrolled`, `secrets_unsealed`,
`seal_calls`, `seal_cache_hits` and `seal_ms`, and the docs get a new page,
"Secret sealing in the gateway" (en and zh), with entries in context
profiles, configuration, security and troubleshooting. The Privacy API
reference now links to that page, and the gateway API reference lists the
three new model-route errors.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

---------

Co-authored-by: zhengxiao.wu <x@x>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants