๐ก๏ธ @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):
<meta name="wci:directives">,wci:manifest,wci:contextin the page head- Response headers:
X-WCI-Directives,X-WCI-Manifest,X-WCI-Context - 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 โ
| Field | Type | Description |
|---|---|---|
policy | PolicyEngine | Parsed wci.txt rules |
manifest | SiteManifest | null | Parsed wci.json |
narrative | string | null | Raw wci.md for LLM system prompt |
PolicyEngine โ
Wraps a parsed WciPolicy from wci.txt.
constructor(policy: WciPolicy) โ
isScopeDenied(scopeId: string): boolean โ
Returns true when:
scopeIdis indeniedScopes, orallowedScopesis non-empty andscopeIdis 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 โ
class ScopeDeniedError extends Error {
readonly scopeId: string;
}Message instructs the agent not to retry the denied scope.
WciPolicy fields โ
wci.txt key | Field |
|---|---|
Allow-Scope | allowedScopes: string[] |
Deny-Scope | deniedScopes: string[] |
Auth-Required | authRequired: string[] |
Require-Human-Confirmation | requireHumanConfirmation: string[] |
Rate-Limit-Actions | rateLimitActions: number |
Rate-Limit-Distil | rateLimitDistil: number |
Site-Name, Site-Purpose, Contact, โฆ | Site metadata |
Integration with bridge โ
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 โ
npm install @webcontextinterface/contextimport {
WciContextLoader,
PolicyEngine,
ScopeDeniedError,
type SiteContext,
} from '@webcontextinterface/context';Dependency: @webcontextinterface/spec
See also โ
- Site policy
- Bridge API โ automatic policy enforcement on dispatch
