Skip to content

๐Ÿ›ก๏ธ @webcontextinterface/context API โ€‹

Site-wide context loader and PolicyEngine for wci.txt / wci.json / wci.md.

WciContextLoader โ€‹

static load(baseUrl?: string, headers?: Headers): Promise<SiteContext> โ€‹

Fetches and parses site context files in parallel.

URL resolution (highest โ†’ lowest):

  1. <meta name="wci:directives">, wci:manifest, wci:context in the page head
  2. Response headers: X-WCI-Directives, X-WCI-Manifest, X-WCI-Context
  3. Root defaults: /wci.txt, /wci.json, /wci.md

Fetch fallbacks: When meta or headers do not set an explicit URL, well-known paths are fetched in parallel as backup: /.well-known/wci/directives.txt, manifest.json, context.md. Content from the resolved root or explicit URL wins over well-known when both return a body.

Defaults baseUrl to window.location.origin when omitted.

Missing files resolve to null / empty policy โ€” no throw.

Returns SiteContext โ€‹

FieldTypeDescription
policyPolicyEngineParsed wci.txt rules
manifestSiteManifest | nullParsed wci.json
narrativestring | nullRaw wci.md for LLM system prompt

PolicyEngine โ€‹

Wraps a parsed WciPolicy from wci.txt.

constructor(policy: WciPolicy) โ€‹

isScopeDenied(scopeId: string): boolean โ€‹

Returns true when:

  • scopeId is in deniedScopes, or
  • allowedScopes is non-empty and scopeId is not listed.

assertScopeAllowed(scopeId: string): void โ€‹

Throws ScopeDeniedError when scope is denied. Use for pre-flight validation before building an ActionRequest.

When using @webcontextinterface/bridge, prefer bridge.setPolicy(ctx.policy) โ€” the bridge enforces the same rules automatically on dispatch.

requiresAuth(scopeId: string): boolean โ€‹

Listed in Auth-Required in wci.txt.

requiresHumanConfirmation(scopeId: string): boolean โ€‹

Listed in Require-Human-Confirmation.

readonly policy: WciPolicy โ€‹

Raw parsed policy object.

ScopeDeniedError โ€‹

typescript
class ScopeDeniedError extends Error {
  readonly scopeId: string;
}

Message instructs the agent not to retry the denied scope.

WciPolicy fields โ€‹

wci.txt keyField
Allow-ScopeallowedScopes: string[]
Deny-ScopedeniedScopes: string[]
Auth-RequiredauthRequired: string[]
Require-Human-ConfirmationrequireHumanConfirmation: string[]
Rate-Limit-ActionsrateLimitActions: number
Rate-Limit-DistilrateLimitDistil: number
Site-Name, Site-Purpose, Contact, โ€ฆSite metadata

Integration with bridge โ€‹

typescript
import { WciContextLoader } from '@webcontextinterface/context';
import { WciBridge } from '@webcontextinterface/bridge';

const ctx = await WciContextLoader.load(origin);
const bridge = new WciBridge(scopeRoot);
bridge.setPolicy(ctx.policy);

Re-exported types โ€‹

WciPolicy, SiteManifest, TaskFlow, ScopeDescriptor from @webcontextinterface/spec.

Install โ€‹

bash
npm install @webcontextinterface/context
typescript
import {
  WciContextLoader,
  PolicyEngine,
  ScopeDeniedError,
  type SiteContext,
} from '@webcontextinterface/context';

Dependency: @webcontextinterface/spec

See also โ€‹