Skip to content

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

Merged
t0saki merged 2 commits into
volcengine:mainfrom
t0saki:feat/server-feature-table
Nov 26, 2026
Merged

t0saki merged 2 commits into
volcengine:mainfrom
t0saki:feat/server-feature-table

Conversation

@t0saki

@t0saki t0saki commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The gateway and the plugins each need to know whether the OpenViking server they talk to already has a capability. Today each answers on its own: the gateway hard-codes 0.5.0 for working memory opt-in, and a plugin that needs the same kind of answer would carry its own number and its own version parser.

This PR puts that knowledge in one place: a table of the first server version that has each capability clients depend on, with one reader for the plugins (JS) and one for the gateway (Python) that give the same answer for the same version string.

It is split out of #8384 (privacy seal) so it can be reviewed on its own. Its first consumers are #8445 (plugins), which adds the row privacy_seal, and #8444 (gateway); both are stacked on this branch.

What changes

  • examples/memory-plugin-shared/lib/server-features.json is the table. It has one row for now, the capability main already depends on: "working_memory_opt_in": "0.5.0".
  • lib/server-features.mjs (+ .d.mts) is the reader for plugins: supports(feature, version), featureStatus(feature, version), healthVersion(fetchJSON).
  • The sync script copies the table byte for byte to openviking_gateway/server-features.json (package data in pyproject.toml and setup.py). openviking_gateway/client.py reads it: supports(feature, version) and VikingClient.supports(key, feature).
  • The gateway's working memory check asks the table instead of comparing against a literal.
  • The "generator output up to date" step in pr.yml now fails when the gateway's copy differs from the source.
  • The shared README explains the rules for a row and the steps to add one.

Rules for a row:

  • The version is the next unreleased release at the time the server change merges.
  • Only the release part of a version is compared, so 0.5.7.dev44 counts as 0.5.7.
  • A version that cannot be read counts as not supporting.
  • Callers ask the table instead of inferring support from a 404.

Behaviour

One answer moves: pre-releases and dev builds of 0.5.0 (0.5.0rc1, 0.5.0.devN) now count as 0.5.0 for working memory opt-in, under the release-part rule. Everything else about that check is unchanged. It still goes through health(), so a failing /health, a root key, or a version that is below the gateway minimum or unreadable stops create_session and commit exactly as before.

Notes for reviewers

  • No plugin imports the reader yet, so the sync gives no plugin a copy in this PR, and the "every shared module is reachable" test exempts server-features.mjs. Its first consumer is feat(plugins): seal secrets in Claude Code and pi #8445, which removes the exemption.
  • All seven distributed plugins get a patch bump although none of them ships a changed file. check-plugin-version-bumps.sh counts any change under memory-plugin-shared/lib as a change to all of them.
  • Both readers accept PEP 440 version strings and nothing else. tests/fixtures/server_feature_versions.json holds one list of version cases that both test suites run, so the two readers cannot drift apart unnoticed. The gateway workflow and the plugin job both trigger on that file.

How it was tested

Suite Result
tests/gateway 1267 passed, 86 skipped
tests/gateway/test_server_features.py alone 32 passed
examples/memory-plugin-shared node tests 634 of 641 passed
Plugin suites after the version bumps (Claude Code, Codex, agent-hook, magpie) 64 / 203 / 152 / 220 passed

The 7 failing shared tests are in release-marketplace.test.mjs and install-sources.test.mjs. They need the zip command, which the machine I ran on does not have; they fail the same way on an untouched checkout of main.

Drift was simulated two ways (the gateway copy edited by hand; a source row added without re-running the sync). In both, the sync test, the pytest check and the CI check sequence fail.

https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx

@t0saki
t0saki force-pushed the feat/server-feature-table branch from a48d79a to 3003f9c Compare November 25, 2026 09:37
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 25, 2026
… 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.

Depends on volcengine#8408 (server feature table); this branch sits on
feat/server-feature-table.

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. 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.

The server feature table gets the row "privacy_seal": "0.5.7", the first
release with the endpoint, so clients can tell whether a server can seal;
its synced gateway copy, the type union and the shared version fixture
move with it. Because the table lives in the shared plugin library, every
plugin takes a patch version bump.

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
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 25, 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, the `auto`
category and the `privacy_seal` feature row), which is based on volcengine#8408 (the
server feature table that `privacy_seal` and `supports` come from).

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is a sibling PR, also on volcengine#8384, that does not depend on
this one. 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.

Turning sealing on never adds a failure: when the server is too old, its
version cannot be read, a seal call fails or the request cannot be sealed,
the request goes out unsealed and the request record carries
`seal_unsupported`, `seal_failed` or `unseal_failed`. The option
`seal_secrets_strict` rejects such requests instead, with 503
`secret_seal_failed` (the call failed or the server cannot seal), 400
`secret_seal_invalid_request` (the request cannot be sealed) or, on the
reply side, 502 `secret_unseal_failed`. Support is decided from the server
feature table row `privacy_seal` through a new
`VikingClient.server_version`. Seal and resolve calls count toward the
per-account OpenViking circuit breaker like any other call. The
`X-OpenViking-Context` header cannot set any of the three switches.

Also: the Studio profile editor gets the three 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 reasons.

Claude-Session: https://claude.ai/code/session_01MSnwD1nmyEak2rMDLkSZMx
@t0saki
t0saki force-pushed the feat/server-feature-table branch from 3003f9c to 367b21b Compare November 26, 2026 04:48
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
… 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.

Depends on volcengine#8408 (server feature table); this branch sits on
feat/server-feature-table.

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.

The server feature table gets the row "privacy_seal": "0.5.7", the first
release with the endpoint, so clients can tell whether a server can seal;
its synced gateway copy, the type union and the shared version fixture
move with it. Because the table lives in the shared plugin library, every
plugin takes a patch version bump.

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
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, the `auto`
category and the `privacy_seal` feature row), which is based on volcengine#8408 (the
server feature table that `privacy_seal` and `supports` come from).

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is a sibling PR, also on volcengine#8384, that does not depend on
this one. 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
…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 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, the `auto`
category and the `privacy_seal` feature row), which is based on volcengine#8408 (the
server feature table that `privacy_seal` and `supports` come from).

Not in this PR: sealing in the Claude Code and pi plugins (`sealSecrets`,
`enrollToolSecrets`) is a sibling PR, also on volcengine#8384, that does not depend on
this one. 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/server-feature-table branch from 367b21b to 850c268 Compare November 26, 2026 07:16
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
… 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
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 pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
… 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
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
… 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
t0saki pushed a commit to t0saki/OpenViking that referenced this pull request Nov 26, 2026
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 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

ZaynJarvis pushed a commit that referenced this pull request Nov 26, 2026
… values (#8384)

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

Co-authored-by: zhengxiao.wu <x@x>
# Conflicts:
#	examples/claude-code-memory-plugin/.claude-plugin/plugin.json
#	examples/claude-code-memory-plugin/package.json
@t0saki
t0saki merged commit 019b351 into volcengine:main Nov 26, 2026
20 of 21 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
* 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

---------

Co-authored-by: zhengxiao.wu <x@x>
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