Skip to content

harness/core

The harness’s own core — path resolution, guard state, and the web-search seam’s vocabulary.

⚠ Schemas are NOT declared here. Every TypeBox schema in this repo lives in @enso/core, so that a shape is either declared there or does not exist. Re-exporting them from here would defeat that: a consumer could import GuardPolicy from two places and neither import would look wrong.

Import schemas from @enso/core directly. Import path helpers from here.

⚠ THE LIST IS WHAT THE EXTENSIONS IMPORT, AND NOTHING ELSE (#263). It used to be the modules’ full public surface, which is a different claim and an unfalsifiable one: 17 names were exported here and imported nowhere, and they sat in fallow-baseline.json — a suppression whose own note said it was waiting on #173’s zone rule, which shipped without taking it. A barrel entry nothing imports is not an inventory, it is a name a reader must check before concluding that removing something is safe.

So the surface is derived from consumption and test/harness-barrel-gate.test.ts holds the two directions: a name here that no extension imports is red, and an extension importing a name that is not here does not compile. Internal helpers keep living in their modules — shell-segments.ts and web-search/anthropic-wire.ts are imported by their siblings and by their own tests, which is what “internal” means. Adding one back here is adding a consumer, and the gate asks for it.

sessionIncidentPolicy(home, project): object

Defined in: packages/harness/core/session-config.ts:227

The incident policy (#466) a session runs under: the USER’s config.json, and over it — once the project is trusted — its approved .enso/config.json’s security.incidents, which can only TIGHTEN it (#753, tightenIncidentPolicy; a loosening key is ignored, and the session told so by sessionEnsoConfig). Synchronous, where the guard needs it (session_start, before any call is decided), so no trust question is asked here: project says what was decided. undefined — no session started yet — is the user’s alone. ⚠ Unreadable fails CLOSED, as every consumer of these files does: halting on, and problem says why.

string

{ cwd: string; trusted: boolean; } | undefined

object

readonly policy: EnsoIncidentPolicy

readonly optional problem?: string

userJudgeConfig(home): { backend: "off" | "jev"; problem?: string; } | { backend: "local"; local: { baseUrl: string; model: string; }; }

Defined in: packages/harness/core/session-config.ts:253

The command judge’s backend (#469) from the USER’s config.json alone: security.judge is user-only, so a project cannot switch a judge on, or off, for the user. Absent is off. ⚠ Unreadable fails CLOSED, which for the judge means OFF — nothing is sent anywhere — and problem says why; so does local without the router and model it needs (#532).

string

{ backend: "off" | "jev"; problem?: string; } | { backend: "local"; local: { baseUrl: string; model: string; }; }

Defined in: packages/harness/core/web-search/vocabulary.ts:79

Thrown by provider runs on failure.

requestDispatched says whether the HTTP request left the process — an honest “may have billed” bit (whether a failed request billed is the provider’s accounting, not knowable here), surfaced when the fallback re-searches.

  • Error

new WebSearchProviderError(providerId, message, options): WebSearchProviderError

Defined in: packages/harness/core/web-search/vocabulary.ts:83

WebSearchProviderId

string

boolean

WebSearchProviderError

Error.constructor

readonly providerId: WebSearchProviderId

Defined in: packages/harness/core/web-search/vocabulary.ts:80

readonly requestDispatched: boolean

Defined in: packages/harness/core/web-search/vocabulary.ts:81


Defined in: packages/harness/core/web-search/providers/deepseek.ts:37

apiKey: string | undefined

Defined in: packages/harness/core/web-search/providers/deepseek.ts:40

The key read at the composition root — never from config, never logged.

fetchUrl: FetchUrl

Defined in: packages/harness/core/web-search/providers/deepseek.ts:41

optional onProgress?: (text) => void

Defined in: packages/harness/core/web-search/providers/deepseek.ts:43

string

void

query: string

Defined in: packages/harness/core/web-search/providers/deepseek.ts:38

signal: AbortSignal | undefined

Defined in: packages/harness/core/web-search/providers/deepseek.ts:42


Defined in: packages/harness/core/web-search/vocabulary.ts:100

The init the fetch seam takes — a fetch init narrowed to what a provider run actually sets.

Named (not inline) so a fake in a test and the composition root’s real fetch wrapper can both annotate the parameter instead of leaning on inference.

optional body?: string

Defined in: packages/harness/core/web-search/vocabulary.ts:104

optional headers?: Record<string, string>

Defined in: packages/harness/core/web-search/vocabulary.ts:103

optional method?: string

Defined in: packages/harness/core/web-search/vocabulary.ts:101

optional redirect?: "manual"

Defined in: packages/harness/core/web-search/vocabulary.ts:102

optional signal?: AbortSignal

Defined in: packages/harness/core/web-search/vocabulary.ts:105


Defined in: packages/harness/core/web-search/vocabulary.ts:153

What a MODEL-ROUTED provider run receives (anthropic / google / openai).

optional claudeCodeVersion?: string

Defined in: packages/harness/core/web-search/vocabulary.ts:165

The Claude Code version to claim on a Claude login (claudeCode.version, #925); undefined claims the version pi’s conversations send. Read by the anthropic provider only.

fetchUrl: FetchUrl

Defined in: packages/harness/core/web-search/vocabulary.ts:157

model: SearchModel

Defined in: packages/harness/core/web-search/vocabulary.ts:155

optional onProgress?: (text) => void

Defined in: packages/harness/core/web-search/vocabulary.ts:160

Streaming progress for the UI; carries the accumulated answer text so far.

string

void

query: string

Defined in: packages/harness/core/web-search/vocabulary.ts:154

resolveAuth: (model) => Promise<ResolvedProviderAuth>

Defined in: packages/harness/core/web-search/vocabulary.ts:156

SearchModel

Promise<ResolvedProviderAuth>

signal: AbortSignal | undefined

Defined in: packages/harness/core/web-search/vocabulary.ts:158


Defined in: packages/harness/core/web-search/vocabulary.ts:136

The model the conversation runs on, as the PROVIDER SEAM sees it (L6 closed, #162): the seven fields the providers read, declared here as ours.

The runtime’s own model record is converted once, at the extension (extensions/web-search/index.ts#searchModelOf), and nothing under harness/core imports the runtime’s type for it any more. A provider that needs an eighth field adds it here, where the seam is, not by reaching for the vendor’s.

api: string

Defined in: packages/harness/core/web-search/vocabulary.ts:139

The wire API the model speaks — anthropic-messages, openai-responses, … — which routes the search.

baseUrl: string

Defined in: packages/harness/core/web-search/vocabulary.ts:142

optional headers?: Record<string, string>

Defined in: packages/harness/core/web-search/vocabulary.ts:145

id: string

Defined in: packages/harness/core/web-search/vocabulary.ts:137

maxTokens: number

Defined in: packages/harness/core/web-search/vocabulary.ts:144

provider: string

Defined in: packages/harness/core/web-search/vocabulary.ts:141

The provider’s id, which names the environment key that may authenticate it.

reasoning: boolean

Defined in: packages/harness/core/web-search/vocabulary.ts:143


Defined in: packages/harness/core/web-search/providers/tavily.ts:24

apiKey: string

Defined in: packages/harness/core/web-search/providers/tavily.ts:26

optional excludeDomains?: readonly string[]

Defined in: packages/harness/core/web-search/providers/tavily.ts:28

fetchUrl: FetchUrl

Defined in: packages/harness/core/web-search/providers/tavily.ts:29

optional includeDomains?: readonly string[]

Defined in: packages/harness/core/web-search/providers/tavily.ts:27

query: string

Defined in: packages/harness/core/web-search/providers/tavily.ts:25

signal: AbortSignal | undefined

Defined in: packages/harness/core/web-search/providers/tavily.ts:30


ResolvedProviderAuth = { apiKey?: string; baseUrl?: string; headers?: Record<string, string>; ok: true; } | { error: string; ok: false; }

Defined in: packages/harness/core/web-search/vocabulary.ts:121

Auth for one model-routed request, as pi’s model registry resolves it (plus the provider-env fallback — see auth.ts).


WebSearchOutcome = { answerText?: string; kind: "searched"; providerId: WebSearchProviderId; snippets?: WebSearchSnippet[]; sources: WebSource[]; } | { answerText: string; kind: "ungrounded"; providerId: WebSearchProviderId; }

Defined in: packages/harness/core/web-search/vocabulary.ts:53

What one provider run produced — the ACCURATE outcome union (#63, Daniel’s requirement).

⚠ searched vs ungrounded is keyed on evidence that a native search actually ran (a server_tool_use block on the Anthropic wire; each provider names its own signal), NEVER on source count: a real search can return zero results, and an ungrounded answer citing a hallucinated URL would read as grounded. Upstream’s grounded = sources.length > 0 had exactly that defect.

{ answerText?: string; kind: "searched"; providerId: WebSearchProviderId; snippets?: WebSearchSnippet[]; sources: WebSource[]; }

optional answerText?: string

The provider-synthesized answer, citation-marked. Absent for retrieval backends (Tavily).

kind: "searched"

providerId: WebSearchProviderId

optional snippets?: WebSearchSnippet[]

Retrieval results with snippets — the Tavily shape; model-native backends leave it absent.

sources: WebSource[]


{ answerText: string; kind: "ungrounded"; providerId: WebSearchProviderId; }

answerText: string

kind: "ungrounded"

The model answered WITHOUT searching — its own knowledge, not the live web.

providerId: WebSearchProviderId


WebSearchProviderId = "anthropic" | "google" | "openai" | "deepseek" | "tavily"

Defined in: packages/harness/core/web-search/vocabulary.ts:18

Every backend that can answer a web_search call.


const DEEPSEEK_API_KEY_VARIABLE: "DEEPSEEK_API_KEY" = 'DEEPSEEK_API_KEY'

Defined in: packages/harness/core/web-search/providers/deepseek.ts:30

The env var holding the key — the SAME name pi-ai’s own provider-env map uses.


resolveModelAuth(authSource, model, readProviderEnvironmentKey): Promise<ResolvedProviderAuth>

Defined in: packages/harness/core/web-search/auth.ts:64

readProviderEnvironmentKey is a SEAM: it defaults to pi-ai’s getEnvApiKey, which reads the launching process environment — injectable so the fallback’s POSITIVE path is testable without a test ever touching process.env.

ModelAuthSource

SearchModel

(provider) => string | undefined

Promise<ResolvedProviderAuth>


routedProviderIdForModel(model): "anthropic" | "google" | "openai" | undefined

Defined in: packages/harness/core/web-search/vocabulary.ts:177

Which model-routed provider serves a model, by its API kind.

undefined means no native search path exists for it — selection falls through to the fallback chain. (pi registers DeepSeek models as openai-completions, so they land here as undefined too: the DeepSeek backend is config-pinned, never model-routed — #63.)

SearchModel

"anthropic" | "google" | "openai" | undefined


runAnthropicProviderSearch(request): Promise<WebSearchOutcome>

Defined in: packages/harness/core/web-search/providers/anthropic.ts:114

ModelSearchRequest

Promise<WebSearchOutcome>


runDeepseekProviderSearch(request): Promise<WebSearchOutcome>

Defined in: packages/harness/core/web-search/providers/deepseek.ts:47

DeepseekSearchRequest

Promise<WebSearchOutcome>


runGoogleProviderSearch(request): Promise<WebSearchOutcome>

Defined in: packages/harness/core/web-search/providers/google.ts:101

ModelSearchRequest

Promise<WebSearchOutcome>


runOpenAiProviderSearch(request): Promise<WebSearchOutcome>

Defined in: packages/harness/core/web-search/providers/openai.ts:175

ModelSearchRequest

Promise<WebSearchOutcome>


runTavilyProviderSearch(request): Promise<WebSearchOutcome>

Defined in: packages/harness/core/web-search/providers/tavily.ts:34

TavilySearchRequest

Promise<WebSearchOutcome>

isFetchableContentType(contentTypeHeader): boolean

Defined in: packages/harness/core/web-fetch-policy.ts:95

True for response bodies worth returning as text.

An ABSENT Content-Type header is refused — web_fetch is a docs-reader, and “the server did not say” fails closed.

string | null

boolean


isHostAllowed(hostname, allowedHosts): boolean

Defined in: packages/harness/core/web-fetch-policy.ts:73

Exact, case-insensitive hostname match.

No wildcards and no subdomain inheritance, deliberately: one allowlist entry is one reviewable grant, and api.example.com is a different grant from example.com. Ports are not part of the match — the protocol gate already confines the scheme, and a host grant is a host grant on any port.

string

readonly string[]

boolean


isHtmlContentType(contentTypeHeader): boolean

Defined in: packages/harness/core/web-fetch-policy.ts:109

True for an HTML page, which web_fetch returns as its readable text (#927); every other fetchable type is returned as it came.

string | null

boolean


parseWebFetchUrl(rawUrl): WebFetchUrlDecision

Defined in: packages/harness/core/web-fetch-policy.ts:41

Parse and gate a raw URL string. Refusal reasons are written for the model to read.

string

WebFetchUrlDecision


readableTextOfHtml(html, pageUrl): string

Defined in: packages/harness/core/html-text.ts:738

The readable text of an HTML page: headings, paragraphs, lists, links as text <url> (relative targets resolved against pageUrl), code and tables, in a markdown-like form — and nothing the page hides or that is not its content (see the module header for the list).

string

URL

string

Defined in: packages/harness/core/guard-session.ts:245

The session’s project as the incident policy reads it (#753): its directory, and whether it is trusted.

readonly cwd: string

Defined in: packages/harness/core/guard-session.ts:246

readonly trusted: boolean

Defined in: packages/harness/core/guard-session.ts:247


Defined in: packages/harness/core/guard-session.ts:306

One thread’s guard: what a runtime’s hooks call, in the order the runtime raises them.

permissionDecision(raw): void

Defined in: packages/harness/core/guard-session.ts:311

A permission engine’s decision, as its channel carried it (#496).

unknown

void

start(facts): void

Defined in: packages/harness/core/guard-session.ts:307

GuardStart

void

toolCall(call): GuardCallOutcome

Defined in: packages/harness/core/guard-session.ts:308

GuardToolCall

GuardCallOutcome

toolResult(result): void

Defined in: packages/harness/core/guard-session.ts:309

GuardToolResult

void


createGuardSession(runtime, dependencies): GuardSession

Defined in: packages/harness/core/guard-session.ts:339

GuardRuntime

GuardSessionDependencies

GuardSession

guarded-tool-call A tool call through the guard: one verdict, first block wins, always a record Before any tool runs, the runtime raises tool_call and every extension’s handler answers in load order; the first { block: true, reason } ends the call, and nothing after it can un-block. Our guard is one handler with an ordered decide inside it: the fail-closed floor and an incident’s suspension (standingDenial), the shell denies, the write gates, then every other path-bearing tool as a reader. The bash analyzer is a library under that handler, not a participant of its own, so the count stays at two (#4, #9). Every answer is a log record. A refused call reaches the browser as a result flagged isError (the runtime’s shape for any failure) and beside it the guard’s own custom entry naming the call and the rule, which is what the page draws a refusal from, live and on resume (#387).

  • docs/seams/guards.md the guards seam: the policy, the dependencies, decide’s order and the L5 crossing
  • packages/harness/core/network-egress.ts the network bar, and what it does not cover (its header)
  • docs/glossary.md the words: guard, verdict, policy, rule, participant, arbiter, boundary vs bar (Permission)

guarded-tool-call/one-verdict The verdict is a denial with its reason, or nothing. decide returns a GuardDenial or undefined, and the glue hands its runtime its own shape back: every refusal is { block: true, reason }, every pass is undefined. Refusing is final: handlers are additive and the runtime returns on the first block, whatever loads after (the file header). HostedThread.probeToolCall pins this through the runtime’s own hook runner, with the real load order and participants: the guards’ refusal with its reason, and first block wins, so a later extension cannot un-block and its own block stands.

Defined in: packages/harness/core/guard-denials.ts:205

The bash analyzer’s refusal of a command (#9), in the guard’s words: the rule it is recorded under and the reason the model reads. The glue that wires a library under the guard produces it, applying that library’s own contract (the pi glue’s analyzer reads a throw as a deny), so the policy here never names the library.

readonly reason: string

Defined in: packages/harness/core/guard-denials.ts:207

readonly rule: "policy-mismatch" | "cc-safety-net" | "network-egress" | "environment-dump" | "secret-path" | "write-confinement" | "protected-internals" | "persistence-write" | "secret-write" | "stale-write" | "read-before-write" | "secret-read" | "incident-suspension" | "protected-records"

Defined in: packages/harness/core/guard-denials.ts:206


inputRecordOf(input): Record<string, unknown>

Defined in: packages/harness/core/guard-denials.ts:72

The tool’s arguments as a plain record, whatever actually arrived. A runtime’s contract says input is an object, but a guard hook must never throw (a throwing pi hook wedges print mode; in-process it yields a session with the guard half-set-up — see the pi glue’s header), so a missing or non-object input reads as “no arguments” rather than as a TypeError.

unknown

Record<string, unknown>

Defined in: packages/harness/core/session-config.ts:67

The session’s context, as pi hands it to session_start.

isProjectTrusted(): boolean

Defined in: packages/harness/core/session-config.ts:76

pi’s answer for this session: whether the project’s own scope is loaded.

boolean

readonly cwd: string

Defined in: packages/harness/core/session-config.ts:69

readonly hasUI: boolean

Defined in: packages/harness/core/session-config.ts:70

readonly home: string

Defined in: packages/harness/core/session-config.ts:68

readonly hostOwnsTrust: boolean

Defined in: packages/harness/core/session-config.ts:82

The web host decides trust (#502): it asks before a run, applies the answer to pi and reloads, so here the project’s config follows isProjectTrusted() and nothing is asked twice. The terminal has no host: there the question below is Enso’s own, as pi’s covers only .pi/.

readonly projectTrust: ProjectTrustRuntime

Defined in: packages/harness/core/session-config.ts:84

pi’s store and settings classes (#509), which the terminal’s question reads and writes.

readonly ui: object

Defined in: packages/harness/core/session-config.ts:71

notify(message, type?): void

string

"info" | "warning" | "error"

void

select(title, options): Promise<string | undefined>

string

string[]

Promise<string | undefined>


Defined in: packages/harness/core/session-config.ts:49

What a session’s tools read their policy from.

readonly path: string

Defined in: packages/harness/core/session-config.ts:53

The file a human changes to change this session’s policy: the project’s, when it was read.

readonly result: EnsoConfigParseResult

Defined in: packages/harness/core/session-config.ts:51

The merged config, or why it could not be read — a caller fails CLOSED on unreadable.

readonly sources: readonly string[]

Defined in: packages/harness/core/session-config.ts:59

The config files this resolution read, user first; empty when none exists (#435). Recorded here, where the reading happens: the resolution is cached per session, so a probe at record time would name files the cached result never saw.


decidedProjectTrust(context): boolean | undefined

Defined in: packages/harness/core/session-config.ts:278

The trust already decided for the session’s project, without asking: the web host’s answer when it owns trust (#502), else pi’s saved decision for the cwd or its nearest ancestor, else defaultProjectTrust — undefined when that is ask, the question sessionEnsoConfig asks. What the guard reads at session_start (#753), which cannot wait on a question: a project trusted only for one terminal session is untrusted there, so its tightening waits for a saved decision.

Pick<SessionConfigContext, "home" | "cwd" | "hostOwnsTrust" | "isProjectTrusted" | "projectTrust">

boolean | undefined


sessionConfigEnvironment(environment, projectTrust): Pick<SessionConfigContext, "home" | "hostOwnsTrust" | "projectTrust">

Defined in: packages/harness/core/session-config.ts:94

The context’s process-wide parts: the user’s ENSO_HOME and whether the web host owns project trust (it sets ENSO_PROJECT_TRUST_BY_HOST before its first session), read from environment; and pi’s trust classes, which the calling extension imports and passes in (#509).

Readonly<Record<string, string | undefined>>

ProjectTrustRuntime

Pick<SessionConfigContext, "home" | "hostOwnsTrust" | "projectTrust">


sessionEnsoConfig(session, context): Promise<SessionEnsoConfig>

Defined in: packages/harness/core/session-config.ts:117

The session’s config, resolved once per session (the context’s sessionManager) and trust answer: under the web host a Trust reloads the session, and the trusted resolution is a new one.

object

SessionConfigContext

Promise<SessionEnsoConfig>

runUnderDeadline<T>(callerSignal, deadline, run): Promise<T>

Defined in: packages/harness/core/deadline.ts:17

Run work under a deadline AND the caller’s abort signal, as one signal (#174; the shape web_fetch and web_search each carried).

Two things every copy had to get right:

  • A signal that is ALREADY aborted never fires its event (addEventListener is not retroactive), so an execute() entered post-abort would run to the deadline — the guard aborts first.
  • A budget already spent aborts BEFORE the work starts: a 0 ms timer would let fast work answer first, and a fallback must not start what the deadline already forbade.

The deadline’s reason is the caller’s — it names the tool and the budget in the refusal.

T

AbortSignal | undefined

() => Error

The error the work sees when the deadline, not the caller, ended it.

number

Milliseconds left; zero or less aborts before run.

(signal) => Promise<T>

Promise<T>