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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/3686-host-web-executor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@schlessera/brain-backend-pi": minor
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-react": minor
---

Pi's web tools now run on the host. Wherever the pi backend is configured, the server starts a trusted web executor for each conversation that uses them: the pinned upstream `pi-web-access` 0.41.0 extension in a real Pi SDK session, now a dependency of the pi backend. That process loads only that extension, with empty settings, in a fresh private directory beside the UI database. It reads a sanitized copy of the host's `web-search.json` and gets the catalog providers' API keys from the host environment. Nothing reaches the worker. The copy turns off the extension's workflow, curator, summary, media, GitHub-cloning, command and browser-cookie paths, and removes every `!command` credential, which the host never runs. The directory is removed when the executor ends, and one that dies is replaced on the next call.

`GET /api/web-search` reports what the web tools do not offer, as `unavailable`, and marks a provider whose stored key is a credential command with `keyIsCommand`. Such a key no longer counts as a credential, so it cannot enable a provider. The Settings card lists the unavailable features, and the Pi system prompt names them for sessions that list the web tools. Pi no longer reads `web-search.json` inside the worker for its brief. `buildSystemPromptAppend` accepts `webTools: true`.
7 changes: 7 additions & 0 deletions api-report/ui-backend-pi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ export "." (./src/index.ts)

export "./internal" (./src/internal.ts)
DEFAULT_PI_ALLOWED_TOOLS
PINNED_WEB_EXTENSION
type PrepareWebExecutorStateOptions
type SanitizedWebConfig
TOOL_RISK
type WebExecutorState
createBrainAccess
createBrainTools
createTurnContext
prepareWebExecutorState
sanitizeWebExecutorConfig
webExecutorCommand

export "./package.json" (./package.json) [asset]

Expand Down
6 changes: 6 additions & 0 deletions api-report/ui-react.txt
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,11 @@ signatures (every public export and the types it is made of)
overriddenBy: string | null;
appliesTo: string[];
providers: WebSearchProvider[];
unavailable?: Array<{
id: string;
label: string;
kind: "deferred" | "excluded";
}>;
}
WebSearchProvider (packages/ui-react/src/lib/api-client.ts)
export interface WebSearchProvider {
Expand All @@ -978,6 +983,7 @@ signatures (every public export and the types it is made of)
hasKeyField: boolean;
keyConfigured: boolean;
keyFromEnv: boolean;
keyIsCommand?: boolean;
keyless: boolean;
costNote: string;
blurb: string;
Expand Down
4 changes: 4 additions & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,7 @@ export "./internal" (./src/internal.ts)
WEB_SEARCH_FALLBACK_ON
WEB_SEARCH_PROVIDERS
WEB_SEARCH_PROVIDER_KEYS
WEB_TOOL_UNAVAILABLE_FEATURES
WORKER_AREA_ROOT
WORKER_DATA_ROOT
WORKER_EGRESS_DIR
Expand All @@ -1349,6 +1350,7 @@ export "./internal" (./src/internal.ts)
WORKER_STATE_BYTES_ENV
WORKER_WORKTREE_ROOT
WORKER_XDG_DIRS
type WebToolUnavailableFeature
type WorkerCommandPolicy
type WorkerDataTree
WorkerHostError
Expand Down Expand Up @@ -1482,6 +1484,7 @@ export "./internal" (./src/internal.ts)
turnTempSpace
verifiedWorkerIdentity
webSearchBrief
webSearchKeySource
webSearchProvider
workerCleanupUnconfirmed
workerCommandPolicyNote
Expand Down Expand Up @@ -13238,6 +13241,7 @@ signatures (every public export and the types it is made of)
turnBudgetMs?: number;
execution?: ExecutionBrief;
webSearch?: WebSearchBrief;
webTools?: boolean;
}): string;
checkEditedApproval (packages/ui-sdk/src/server/permission-gate.ts)
export function checkEditedApproval(options: EditedApprovalCheckInput): string | null;
Expand Down
219 changes: 216 additions & 3 deletions bun.lock

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4682,6 +4682,53 @@ reserves the executor choice until that comparison is reviewed. Neither this
amendment nor a successful plain-search prototype selects an executor or grants
additional host model, UI, browser, shell or credential-command authority.

### Executor, workflow and credential rulings — 2026-10-15, built in #3686

Three later rulings on #1863 settle what the paragraph above left open, and
#3686 builds them:

- **Executor A** ([ruling](https://github.com/schlessera/brain-kit/issues/1863#issuecomment-6194810790)):
the full upstream extension runs in an actual trusted Pi session on the
host. The host web executor (`packages/ui-backend-pi/src/web-executor-entry.ts`)
is one child process per principal's session, started by the broker
(`packages/ui-server/src/web-tools/host.ts`). It loads exactly one
extension, the pinned `pi-web-access` 0.41.0 (`PINNED_WEB_EXTENSION`,
`packages/ui-backend-pi/src/web-executor.ts`), from the backend's own
dependency, and refuses to start if anything else loaded. Discovery,
skills, prompts, themes and context files are off and its settings are
empty and in memory. Its cwd, HOME, Pi agent directory, cache and temp
are a fresh private directory beside the UI database, which every worker
already has masked. No repository extension, hook, setting or brain file
enters this credentialed process.
- **Workflow A** ([ruling](https://github.com/schlessera/brain-kit/issues/1863#issuecomment-6197482861)):
only `web_search`, `fetch_content`, `get_search_content` and
`source_check`. No model turn runs: each call goes straight to the
session's tool pipeline (`runToolCall`) with the session's real extension
context, so commands, shortcuts and nested callbacks are unreachable. The
executor's sanitized copy of `web-search.json` also turns off the
workflow, curator, summary, image, video and YouTube paths and every
command, so none of them is available through configuration either.
GitHub repository cloning is off as well until
[#3687](https://github.com/schlessera/brain-kit/issues/3687) qualifies
the executor's subprocess egress.
- **Credential exclusion A** ([ruling](https://github.com/schlessera/brain-kit/issues/1863#issuecomment-6197680635)):
no browser-cookie, browser-profile or keyring discovery and no
`!command` credential. The sanitized copy forces `allowBrowserCookies:
false`, drops the cookie profile and removes every credential-command
value; the executor's private HOME holds no browser or `gh` login. Literal
keys and the catalog's environment variables remain under the existing
trusted host policy. Opt-in adapters are
[#1989](https://github.com/schlessera/brain-kit/issues/1989).

These features are reported unavailable from one list,
`WEB_TOOL_UNAVAILABLE_FEATURES` (`packages/ui-sdk/src/server/web-search.ts`).
The Settings route, its card and the system-prompt brief all read that list,
and a call that asks for one answers `unsupported`. Mandatory egress and
per-call admission are [#3687](https://github.com/schlessera/brain-kit/issues/3687).
Subscription and current-model search is [#3688](https://github.com/schlessera/brain-kit/issues/3688).
Until those land, the egress and spend-coverage limits above still hold for
the executor.


#### Approved host OAuth refresh placement (2026-10-16)

Expand Down
14 changes: 14 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ SDK gains the tool contracts, `WebToolEnvelope`, `parseWebToolInput`,
and [the package component](integration-contract/package-api.md#host-owned-web-tools-additive-0450-3685).
This ships in a minor.

## Host web executor for Pi (additive, 0.45.0, #3686)

The four web tools now run on a host executor: the pinned upstream
`pi-web-access` 0.41.0 in a trusted Pi session, one child process per
principal's session, with provider configuration and keys on the host only.
Their names, inputs and envelopes are unchanged. `GET /api/web-search` gains
two fields. `unavailable` lists the features the host web tools do not
offer, each `{ id, label, kind }` with `kind` either `deferred` or
`excluded`. Each provider gains `keyIsCommand`, true when its stored key is a
`!command` credential, which the host never runs. Such a key no longer counts
as a credential, so it cannot enable a provider. `buildSystemPromptAppend`
accepts `webTools: true`, which adds the brief's line on what the web tools
do not offer. This ships in a minor.

## Retained barge-in and conversation end (additive, 0.45.0, #3729)

`DialogueEvidence` gains `voice_interruption`, written when the host forwards
Expand Down
10 changes: 10 additions & 0 deletions docs/integration-contract/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,16 @@ Each call taints the session (`web_search` or `web_fetch`) before it runs, and
its result is recorded before the model receives it. A call appends an
ordinary tool result; no earlier message, tool or system text changes.

Since #3686 the host runs these tools on the pinned upstream extension in a
trusted Pi session. One child process serves each principal's session, and
its stored results live and end with it. The brief of a session that lists
the tools names what they do not offer. Those features come from one list,
`WEB_TOOL_UNAVAILABLE_FEATURES`: curator review and automatic summaries,
answer mode, image, video and YouTube analysis, GitHub repository cloning,
the extension's commands and shortcuts, and the excluded browser-cookie and
credential-command modes. `GET /api/web-search` reports the same list as
`unavailable`.

## Hosted policy proposal (additive, #1662)

`propose_policy_change` (Claude: `mcp__brain-ui__propose_policy_change`)
Expand Down
22 changes: 19 additions & 3 deletions packages/ui-backend-pi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 +322,30 @@ the calling session. Answer mode, summaries, curator review, video analysis
and the browser-cookie and credential-command modes answer `unsupported`. Each
result passes the input-safety collector before the model receives it.
Autonomous turns get none of these tools. A host without a web executor
refuses them before they run. The production executor is not built yet
(#3686); until it is, the tools are listed but refused.
refuses them before they run.

The host web executor (#3686) runs the pinned upstream extension,
`pi-web-access` 0.41.0, in a real Pi SDK session on the host, one child
process per conversation. That process loads only that extension, with empty
settings and no discovery. It runs in a fresh private directory (HOME, Pi
agent directory, cache and temp) beside the UI database, which workers
already have masked. It reads a sanitized copy of the host's
`web-search.json` and gets the catalog providers' API keys from the host
environment. The copy turns off the extension's workflow, curator, summary,
media, GitHub-cloning, command and browser-cookie paths, and removes every
`!command` credential. Settings, the Settings card and the system-prompt
brief list the same unavailable features (`WEB_TOOL_UNAVAILABLE_FEATURES`).
The directory is removed when the executor ends; an executor that dies is
replaced on the next call, and its stored results go with it. Mandatory
egress and per-call admission are #3687; subscription and current-model
search is #3688.

## Extensions (MCP, subagents)

Managed turns currently refuse every loaded external extension, including
`pi-web-access`, `pi-mcp-adapter` and `pi-subagents`. Web search does not need
`pi-web-access` (see Web tools above). A tool permission gate or a
a worker-loaded `pi-web-access` (see Web tools above): the host runs its own
pinned copy. A tool permission gate or a
final `tool_result` observer cannot qualify these packages: Pi also exposes live
messages/results after that observer, independent custom-message injection and
provider-payload hooks. There is no trusted extension path, name or package
Expand Down
1 change: 1 addition & 0 deletions packages/ui-backend-pi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@earendil-works/pi-coding-agent": "0.99.2",
"@earendil-works/pi-agent-core": "0.99.2",
"@earendil-works/pi-ai": "0.99.2",
"pi-web-access": "0.41.0",
"typebox": "1.1.38",
"zod": "^4.4.3"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/ui-backend-pi/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
export { DEFAULT_PI_ALLOWED_TOOLS, TOOL_RISK, createBrainTools } from "./tools.js";
export { createBrainAccess } from "./brain-access.js";
export { createTurnContext } from "./turn-context.js";
// The trusted host web executor (#3686): ui-server's broker starts one per session.
export { PINNED_WEB_EXTENSION, prepareWebExecutorState, sanitizeWebExecutorConfig, webExecutorCommand } from "./web-executor.js";
export type { PrepareWebExecutorStateOptions, SanitizedWebConfig, WebExecutorState } from "./web-executor.js";
59 changes: 8 additions & 51 deletions packages/ui-backend-pi/src/session-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
SettingsManager,
getAgentDir,
} from "@earendil-works/pi-coding-agent";
import { buildSystemPromptAppend, type WebSearchBrief } from "@schlessera/brain-ui-sdk/server";
import { resolveWebSearchConfigPath, webSearchBrief } from "@schlessera/brain-ui-sdk/internal";
import { buildSystemPromptAppend } from "@schlessera/brain-ui-sdk/server";
import { existsSync, readFileSync } from "fs";
import { join } from "path";

Expand All @@ -16,7 +15,6 @@ import type {
SessionToolkit,
} from "./backend-options.js";
import type { BrainAccess } from "./brain-access.js";
import { resolveWebSearchEnv } from "./config/env.js";
import { createPermissionGate } from "./permission-gate.js";
import { restrictedResources } from "./restricted-resources.js";
import { createTurnContext } from "./turn-context.js";
Expand Down Expand Up @@ -112,17 +110,12 @@ export function createSessionResources(options: {
}
const subagentTool =
loadExtensions && hasPackage(settingsManager, "pi-subagents") ? "subagent" : false;
// No web extension, no search tool — and nothing to say about providers.
const webSearch =
loadExtensions && hasPackage(settingsManager, "pi-web-access")
? readWebSearchBrief()
: undefined;
const brief = env.autonomous?.systemPromptAppend ?? buildAppend(backend, env, subagentTool, webSearch, Boolean(options.shellCwd));
const brief = env.autonomous?.systemPromptAppend ?? buildAppend(backend, env, subagentTool, Boolean(options.shellCwd));
const append = env.autonomous ? [brief, options.sandboxNote].filter(Boolean).join("\n\n")
: options.fixedAppend ?? [buildAppend(backend, { ...env, client: undefined, turnBudgetMs: undefined, caps: {
policyChange: true, askUser: true, askUserList: true, askUserRank: true, askUserForm: true,
location: true, activity: true, inbox: true, mask: true, turnTemp: true, reference: true, compute: true,
} }, subagentTool, webSearch, Boolean(options.shellCwd)), env.sessionBudgetLimits].filter(Boolean).join("\n\n");
location: true, activity: true, inbox: true, mask: true, turnTemp: true, reference: true, compute: true, web: true,
} }, subagentTool, Boolean(options.shellCwd)), env.sessionBudgetLimits].filter(Boolean).join("\n\n");
options.observeAppend?.(append);
const loader = new DefaultResourceLoader({
cwd: brainPath,
Expand Down Expand Up @@ -176,7 +169,6 @@ function buildAppend(
options: CreatePiBackendOptions,
env: SessionEnv,
subagentTool: string | false,
webSearch: WebSearchBrief | undefined,
perTurnProcess: boolean
): string {
// The chat-surface brief for one session: what the answer renders into
Expand All @@ -188,9 +180,10 @@ function buildAppend(
buildSystemPromptAppend({
...(env.client ? { client: env.client } : {}),
...(env.turnBudgetMs ? { turnBudgetMs: env.turnBudgetMs } : {}),
// Which search providers this deployment actually reaches. Omitted when
// the web extension is absent — there is no search tool then.
...(webSearch ? { webSearch } : {}),
// The host-owned web tools (#3686), listed in every interactive
// session: the brief says what they do not offer. The worker never
// reads the host's web configuration.
...(env.caps.web ? { webTools: true } : {}),
// Named only when the bridge actually provides the handler — the toolkit
// registers each tool on the same condition.
tools: {
Expand Down Expand Up @@ -247,39 +240,3 @@ function hasPackage(settingsManager: SettingsManager, name: string): boolean {
}
}

/**
* The web-search brief for this session, read from the same `web-search.json`
* the pi-web-access extension reads.
*
* Resolved through the SDK helper, NOT from `agentDir`: pi puts its agent dir
* at `~/.pi/agent` while the extension reads `~/.pi/web-search.json`, one level
* up. Reading the wrong one finds nothing and would silently tell the model no
* providers are configured.
*
* The extension lets its tool be renamed (`toolNames.webSearch`), so the brief
* names whatever the model will actually see.
*/
function readWebSearchBrief(): WebSearchBrief | undefined {
try {
const env = resolveWebSearchEnv();
const path = resolveWebSearchConfigPath(env);
const raw = existsSync(path) ? readFileSync(path, "utf-8") : "{}";
const parsed = JSON.parse(raw) as unknown;
const config =
parsed && typeof parsed === "object" && !Array.isArray(parsed)
? (parsed as Record<string, unknown>)
: {};
const names = config.toolNames;
const named =
names && typeof names === "object" && !Array.isArray(names)
? (names as Record<string, unknown>).webSearch
: undefined;
const toolName =
typeof named === "string" && named.trim() ? named.trim() : "web_search";
return webSearchBrief(config, { toolName, env });
} catch {
// A malformed config is the extension's problem to report; the brief just
// stays silent rather than claiming a provider set it cannot read.
return undefined;
}
}
Loading
Loading