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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/ci-paths.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ ignore = [

knowledge_base = ["frontend/knowledge-base/**", "plugins/knowledge-base/**", "tests/knowledge_base/**", "tests/e2e/test_knowledge_base*.py"]

gateway = [
"gateway/**", ".github/workflows/gateway.yml", "tests/e2e/gateway_tck.py",
"tests/e2e/test_gateway_authentication.py", "tests/e2e/test_gateway_target_real_process.py",
"tests/e2e/test_gateway_http1_lifecycle.py",
]
gateway = ["gateway/**", ".github/workflows/gateway.yml", "tests/e2e/gateway_tck.py", "tests/e2e/test_gateway_authentication.py", "tests/e2e/test_gateway_http1_lifecycle.py"]

helm = ["deploy/helm/**", "tests/test_helm*.py", "tests/e2e/helm_*.py"]
tests = [
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,10 @@ jobs:
uses: ./.github/actions/setup-python-env
with:
python-version: "3.12"
- name: Check Gateway authentication, target binding, and HTTP lifecycle over real listeners
- name: Check Gateway authentication and HTTP lifecycle over real listeners
run: |
cargo build --locked --manifest-path gateway/Cargo.toml --bin pc-gateway
test -x gateway/target/debug/pc-gateway
uv run --locked --no-sync pytest \
tests/e2e/test_gateway_authentication.py \
tests/e2e/test_gateway_target_real_process.py \
tests/e2e/test_gateway_http1_lifecycle.py -q
67 changes: 17 additions & 50 deletions docs/en/docs/get-started/agent-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ OPENAI_API_KEY=
- Leave the `OPENAI_API_KEY=` line empty and ask the user to fill it in with an editor. Continue after the user confirms.
- Wrap the JSON value in single quotes; otherwise configuration parsing strips its double quotes.
- Inference protection must stay `disabled` with the `approved-codex` target. Codex subscription requests carry no output limit, and enabled protection withholds them.
- Core authentication is required even in this personal, loopback Gateway setup. Append the enforced access mode and generate a random Server token without printing it:

```bash
printf 'POWERCONTEXT_SERVER_ACCESS_MODE=enforced\nPOWERCONTEXT_SERVER_AUTH_TOKEN=%s\n' "$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')" >> "$HOME/powercontext/.env"
```

Validate the configuration and register the personal service. The service starts at login: a systemd user service on Linux, a LaunchAgent on macOS.

Expand All @@ -122,12 +117,11 @@ powercontext config validate --env-file .env
powercontext service install --env-file .env
powercontext service status
export POWERCONTEXT_CLIENT_SERVER_URL=http://127.0.0.1:17429
export POWERCONTEXT_CLIENT_API_TOKEN="$(sed -n 's/^POWERCONTEXT_SERVER_AUTH_TOKEN=//p' "$HOME/powercontext/.env")"
powercontext ready
powercontext scope create --title personal --summary "Personal coding context"
```

Keep `POWERCONTEXT_CLIENT_API_TOKEN` in the shell that launches the CLI and host plugin; Core authentication applies to them too, and the Gateway key does not replace their Core credential. The last command prints a line such as `scp_... personal (version 1)`. The leading `scp_...` is the Scope ID, written `<scope_id>` below.
The last command prints a line such as `scp_... personal (version 1)`. The leading `scp_...` is the Scope ID, written `<scope_id>` below.

**Check:** `service status` shows `server liveness: live`. In `ready`, `database`, `inference.generation` and `runtime` are `ready`, and so is `inference.embedding` when an embedding model is configured.

Expand All @@ -142,24 +136,10 @@ PC_GATEWAY_INJECTION=on
PC_GATEWAY_SEDIMENT=on
PC_GATEWAY_SUBSCRIPTION=codex
PC_GATEWAY_SUBSCRIPTION_CREDENTIALS=<HOME>/.codex/auth.json
PC_GATEWAY_UPSTREAM_PROFILE_RESPONSES=approved-codex
PC_GATEWAY_UPSTREAM_PROFILE=approved-codex
```

The Gateway connects to the Server over HTTP, so it injects context only with `PC_GATEWAY_INJECTION=on`. Give it the Server token and generate a distinct client-facing key without displaying either value:

```bash
printf 'PC_GATEWAY_CORE_TOKEN=%s\n' "$(sed -n 's/^POWERCONTEXT_SERVER_AUTH_TOKEN=//p' "$HOME/powercontext/.env")" >> "$HOME/powercontext/gateway.env"
printf 'PC_GATEWAY_API_KEY=%s\n' "$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')" >> "$HOME/powercontext/gateway.env"
chmod 600 "$HOME/powercontext/gateway.env"
```

This personal flow reuses the Server token created above: `CORE_URL` is the value of `PC_GATEWAY_CORE_BASE`, and
`PC_GATEWAY_CORE_BASE` and `PC_GATEWAY_CORE_TOKEN` are in `gateway.env`; `ACCESS_ADMIN_TOKEN` is the
`POWERCONTEXT_SERVER_AUTH_TOKEN` in `.env`. The Server token is the
bootstrap administrator and has static Scope roles. Grant it `gateway.user` on `<scope_id>` before starting the
Gateway. A separate least-privilege Gateway identity instead needs `gateway.user`, `server.observer` on the Server
resource, and—because this setup enables capture—`scope.contributor` on the Scope. See [Gateway authentication and
target requirements](../operate/deploy-server.md#gateway-model-destination) for `/v1/access/me` and binding commands.
The Gateway connects to the Server over HTTP, so it injects context only with `PC_GATEWAY_INJECTION=on`.

Create the launch script `<HOME>/powercontext/run-gateway.sh` and run `chmod 755` on it. It starts the Gateway after the Server is ready:

Expand All @@ -172,12 +152,7 @@ until curl -sf http://127.0.0.1:17429/health/ready >/dev/null; do sleep 2; done
exec "<absolute path of pc-gateway>" >>"$HOME/powercontext/gateway.log" 2>&1
```

Get the absolute path with `command -v pc-gateway`. Because prefix extraction is enabled above, also add the Gateway key to the Server callback headers and reload the Server configuration:

```bash
printf "POWERCONTEXT_SERVER_INFERENCE_PREFIX_EXTRACTION_GATEWAY_HEADERS='{\"Authorization\":\"Bearer %s\"}'\n" "$(sed -n 's/^PC_GATEWAY_API_KEY=//p' "$HOME/powercontext/gateway.env")" >> "$HOME/powercontext/.env"
powercontext service install --env-file "$HOME/powercontext/.env"
```
Get the absolute path with `command -v pc-gateway`.

### Start the Gateway automatically

Expand Down Expand Up @@ -358,9 +333,9 @@ OPENAI_API_KEY=
POWERCONTEXT_SERVER_HTTP_HOST=0.0.0.0
```

Without authentication and without the Gateway, also append `POWERCONTEXT_SERVER_ALLOW_UNAUTHENTICATED_NON_LOOPBACK=true`.
Without authentication, also append `POWERCONTEXT_SERVER_ALLOW_UNAUTHENTICATED_NON_LOOPBACK=true`.

**When deploying the Gateway, authentication is required even on loopback.** It is also required when the administrator otherwise chooses authenticated access. Append `POWERCONTEXT_SERVER_ACCESS_MODE=enforced`, and generate the token straight into the file without showing it; tell the administrator it is stored as `POWERCONTEXT_SERVER_AUTH_TOKEN` in `.env`:
**With authentication,** append `POWERCONTEXT_SERVER_ACCESS_MODE=enforced`, and generate the token straight into the file with the command below. Do not show the token; tell the administrator that it is stored as `POWERCONTEXT_SERVER_AUTH_TOKEN` in `.env`:

```bash
printf 'POWERCONTEXT_SERVER_AUTH_TOKEN=%s\n' "$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')" >> "$HOME/powercontext/.env"
Expand All @@ -378,6 +353,12 @@ With prefix extraction, also append:
POWERCONTEXT_SERVER_INFERENCE_PREFIX_EXTRACTION_GATEWAY_URL=http://127.0.0.1:8787
```

The Server must also send the Gateway key when calling the Gateway. After writing the Gateway configuration, append it with the command below, without showing the key:

```bash
printf 'POWERCONTEXT_SERVER_INFERENCE_PREFIX_EXTRACTION_GATEWAY_HEADERS='"'"'{"Authorization":"Bearer %s"}'"'"'\n' "$(sed -n 's/^PC_GATEWAY_API_KEY=//p' "$HOME/powercontext/gateway.env")" >> "$HOME/powercontext/.env"
Comment thread
hidb4ai marked this conversation as resolved.
Resolved
```

Without one-pass, append `POWERCONTEXT_SERVER_RUNTIME_ATOMIC_MEMORY_PROCESSING_MODE=per_candidate`.

**Check:** `powercontext config validate --env-file "$HOME/powercontext/.env"` passes.
Expand Down Expand Up @@ -415,7 +396,7 @@ loginctl enable-linger "$USER"

`enable-linger` keeps the services running after the administrator logs out. If the command fails, ask the administrator to run it with an account that has permission.

Then check the Server and create the Scope the team uses. When deploying the Gateway or using any authenticated setup, read the token from `.env` first without showing it; clients and plugins must use their own Core credentials, not the Gateway API key:
Then check the Server and create the Scope the team uses. With authentication, read the token from `.env` first without showing it:

```bash
export POWERCONTEXT_CLIENT_SERVER_URL=http://127.0.0.1:17429
Expand All @@ -437,41 +418,27 @@ PC_GATEWAY_CORE_BASE=http://127.0.0.1:17429
PC_GATEWAY_DEFAULT_SCOPE=<scope_id>
PC_GATEWAY_INJECTION=on
PC_GATEWAY_SEDIMENT=on
PC_GATEWAY_UPSTREAM_PROFILE_RESPONSES=team-upstream
PC_GATEWAY_UPSTREAM_PROFILE=team-upstream
PC_GATEWAY_UPSTREAM_URL_RESPONSES=<upstream-endpoint>
PC_GATEWAY_UPSTREAM_API_KEY_RESPONSES=
```

- Leave `PC_GATEWAY_UPSTREAM_API_KEY_RESPONSES=` empty and ask the administrator to fill in the upstream API key. Start the Gateway only after the administrator confirms.
- To turn injection off, use `PC_GATEWAY_INJECTION=off`; to turn capture off, delete `PC_GATEWAY_SEDIMENT=on`. To turn Steering off, append `PC_GATEWAY_STEERING=off`; for team instructions, append `PC_GATEWAY_STEERING_FILE=<file path>`. To turn prefix extraction off, append `PC_GATEWAY_PREFIX_EXTRACTION=off`.
- The Gateway always needs the authenticated Server token to call Core. Copy it with the command below, without showing it; it must differ from `PC_GATEWAY_API_KEY`:
- With authentication, the Gateway needs the same token to call the Server. Copy it with the command below, without showing it:

```bash
printf 'PC_GATEWAY_CORE_TOKEN=%s\n' "$(sed -n 's/^POWERCONTEXT_SERVER_AUTH_TOKEN=//p' "$HOME/powercontext/.env")" >> "$HOME/powercontext/gateway.env"
```

- The Gateway requires a nonempty client-facing key on every listener, including loopback. Members use this key for model routes; it must differ from the Core token. Generate it without showing it:
- Members reach the Gateway through a reverse proxy or the network, so generate the Gateway key they use, without showing it:

```bash
printf 'PC_GATEWAY_API_KEY=%s\n' "$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')" >> "$HOME/powercontext/gateway.env"
```

- When listening on a network address, also append `PC_GATEWAY_LISTEN=0.0.0.0:8787`.

In this flow, `CORE_URL` is `PC_GATEWAY_CORE_BASE` from `gateway.env`, `PC_GATEWAY_CORE_TOKEN` is also in that file,
and `ACCESS_ADMIN_TOKEN` is the Server token in `.env`; that token is the bootstrap administrator credential. If you
replace it with a dedicated Gateway identity, bind `gateway.user`, `server.observer` and (because capture is enabled)
`scope.contributor` as described in [Gateway authentication and target requirements](../operate/deploy-server.md#gateway-model-destination).

With prefix extraction enabled, set the callback header from the Gateway key and reload the Server:

```bash
printf "POWERCONTEXT_SERVER_INFERENCE_PREFIX_EXTRACTION_GATEWAY_HEADERS='{\"Authorization\":\"Bearer %s\"}'\n" "$(sed -n 's/^PC_GATEWAY_API_KEY=//p' "$HOME/powercontext/gateway.env")" >> "$HOME/powercontext/.env"
powercontext config validate --env-file "$HOME/powercontext/.env"
powercontext service install --env-file "$HOME/powercontext/.env"
```

This team flow also uses the bootstrap Server token as the Gateway credential. Grant it `gateway.user` on `<scope_id>`; a dedicated Gateway identity instead needs the grants described above. The Gateway API key only authenticates model-route requests, while Core clients and plugins need their own Core credentials.

Run `chmod 600 "$HOME/powercontext/gateway.env"`, then create `run-gateway.sh` and start the Gateway automatically as in [step 3a](#start-the-gateway-automatically).

**Check:** `curl -s http://127.0.0.1:8787/healthz` responds.
Expand Down
24 changes: 10 additions & 14 deletions docs/en/docs/integrations/codex.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,9 @@ follows.
Codex does not send an output limit (`max_output_tokens`). An enforcing Core requires a token budget on the target and
an output limit on every generation request, so it withholds each Codex request (for example with
`output_limit_required`), the gateway returns HTTP 400, and the turn fails before the model receives it. Run Core with
inference protection in `disabled`, `shadow`, or `advisory` mode, with a target for the profile named by
`PC_GATEWAY_UPSTREAM_PROFILE_RESPONSES`. Core withholds a check for an unknown target in every mode. For example,
the following `default` target requires `PC_GATEWAY_UPSTREAM_PROFILE_RESPONSES=default`:
inference protection in `disabled`, `shadow`, or `advisory` mode, with a target for the profile that
`PC_GATEWAY_UPSTREAM_PROFILE` names (`default` unless set). Core withholds a check for an unknown target in every
mode. For example:

```bash
export POWERCONTEXT_SERVER_INFERENCE_PROTECTION='{
Expand Down Expand Up @@ -384,7 +384,8 @@ put the same keys in `~/.codex/powercontext-gateway.config.toml` and start Codex

Export the gateway's `PC_GATEWAY_API_KEY` value as `PC_GATEWAY_KEY` in the environment that starts Codex; Codex sends
it as the bearer token. While `PC_GATEWAY_KEY` is unset, Codex stops with `Missing environment variable` before it
sends a request. The gateway requires a nonempty `PC_GATEWAY_API_KEY` even on a loopback listener.
sends a request. A gateway on a loopback listener may run without `PC_GATEWAY_API_KEY` and then accepts any token, but
Codex still needs the variable.

In a combined deployment (`PC_GATEWAY_CORE_UDS`), the gateway forwards Core API and MCP requests to Core with the
client's own credentials, so the plugin can use the gateway's address as its Server URL
Expand Down Expand Up @@ -412,16 +413,11 @@ context, MCP tools, and diagnostics keep their own settings.
Run the gateway in a combined deployment (`PC_GATEWAY_CORE_UDS`), which injects requests that carry a conversation by
default. Set:

- `PC_GATEWAY_UPSTREAM_PROFILE_RESPONSES` to the Core `InferenceConfig.protection.targets` profile for the Responses
endpoint, protocol, and model (for the example above, `default`). Without this setting, the Responses route returns
HTTP 501 `responses_route_disabled`. Do not set `PC_GATEWAY_UPSTREAM_URL*`; legacy URL variables prevent startup.
- `PC_GATEWAY_UPSTREAM_API_KEY_RESPONSES` to the provider key for that approved target.
- `PC_GATEWAY_API_KEY` to a nonempty key that Codex sends as `PC_GATEWAY_KEY`.
- `PC_GATEWAY_CORE_TOKEN` to an authenticated Core service identity, distinct from the client-facing key. Core access
control must be `enforced` even when inference privacy protection is non-enforcing. Grant the identity `gateway.user`
(`gateway.invoke`) on the selected Scope, `server.observer` (`server.observe`) on the Server resource for
`POWERCONTEXT_SERVER_ACCESS_DEPLOYMENT_ID` (default `powercontext`), and `scope.contributor` instead of
`scope.viewer` because capture is enabled. See [Gateway authentication and target requirements](../operate/deploy-server.md#gateway-model-destination) for the `/v1/access/me` and binding requests.
- `PC_GATEWAY_UPSTREAM_URL_RESPONSES` to the target's `endpoint`, and `PC_GATEWAY_UPSTREAM_API_KEY_RESPONSES` to the
provider key. The gateway sends to this URL itself, and without it the Responses route returns HTTP 501
`responses_route_disabled`.
- `PC_GATEWAY_API_KEY` to the key that Codex sends as `PC_GATEWAY_KEY`. A non-loopback listener requires it.
- `PC_GATEWAY_CORE_TOKEN` when Core enforces authentication.
- `PC_GATEWAY_SEDIMENT=on`, so that the gateway captures each completed turn as a Source.
- `PC_GATEWAY_DEFAULT_SCOPE` to the fallback Scope. To use the Scope this plugin resolves for the workspace,
run `scope_binding.py` without
Expand Down
21 changes: 11 additions & 10 deletions docs/en/docs/integrations/deepagents.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,17 @@ Configure Core and the gateway as well:
enforcing rules: an enforcing Core withholds a Responses request without `store: false` or without an output limit
within the target's token budget, and the gateway returns HTTP 400. Restart the gateway after changing the mode,
because it discovers the mode at startup.
- For this Responses route, set `PC_GATEWAY_UPSTREAM_PROFILE_RESPONSES` to a Core target whose endpoint,
`openai-responses` protocol and model match the request. Without it, the route returns HTTP 501
`responses_route_disabled`. Set `PC_GATEWAY_UPSTREAM_API_KEY_RESPONSES` to the provider key and
`PC_GATEWAY_SEDIMENT=on`. Do not set `PC_GATEWAY_UPSTREAM_URL*`; these legacy variables prevent startup.
- Set a nonempty `PC_GATEWAY_API_KEY` even on loopback, and set `PC_GATEWAY_CORE_TOKEN` to an authenticated service
identity. Core access control must be `enforced`; grant it `gateway.user` on every Scope that requests select with
`X-PowerContext-Scope-ID`, not only on `PC_GATEWAY_DEFAULT_SCOPE`, and `server.observer` on the Server resource for
`POWERCONTEXT_SERVER_ACCESS_DEPLOYMENT_ID` (default `powercontext`). Because this guide enables capture, grant
`scope.contributor` (which includes `scope.read`) on those Scopes rather than `scope.viewer`.
See [Gateway authentication and target requirements](../operate/deploy-server.md#gateway-model-destination).
- Core needs a target for the profile that `PC_GATEWAY_UPSTREAM_PROFILE` names (`default` unless set), in every privacy
mode, including `disabled`. Without one, Core withholds each request with `target_unsupported` and the gateway
returns HTTP 400. See [Configure a supported target](../operate/inference-protection.md#configure-a-supported-target).
- Set `PC_GATEWAY_UPSTREAM_URL_RESPONSES` and `PC_GATEWAY_UPSTREAM_API_KEY_RESPONSES` to the provider's Responses
endpoint and key, and set `PC_GATEWAY_SEDIMENT=on`.
- When Core enforces authentication, set `PC_GATEWAY_CORE_TOKEN` to an authenticated service identity. Grant it
`server.observer` on the Server resource for `POWERCONTEXT_SERVER_ACCESS_DEPLOYMENT_ID` (default `powercontext`),
and `scope.contributor` (which includes `scope.read`) on `PC_GATEWAY_DEFAULT_SCOPE` and on every Scope
that requests select with `X-PowerContext-Scope-ID`. Because this guide enables capture, use `scope.contributor`
rather than `scope.viewer`. See
[Gateway authentication boundaries](../operate/deploy-server.md#gateway-authentication-boundaries).
- Set `PC_GATEWAY_DEFAULT_SCOPE` to the Scope for requests without `X-PowerContext-Scope-ID`. If the application does
not send the header, set it to the Scope the adapter used, so that the gateway recalls the Memory captured before.

Expand Down
Loading
Loading