Create and await ready
agindow@0.1.0-alpha.2, published on npm. Node 22+, ESM/CJS and declarations. createAgindow returns an SDK instance. Await sdk.ready, a settling Promise; loading failure remains a bypass and does not become successful protection.
Validated setup fixture
After npm install agindow@0.1.0-alpha.2, save the ts tab and run it with node --experimental-strip-types example.ts. It proves wrapper setup, readiness, return identity and one labelled synthetic bypass. It does not demonstrate drift detection: use Quickstart for the configured statistical finding.
import { createAgindow } from 'agindow';
const sdk = createAgindow({ mode: 'observe' });
await sdk.ready;
const payload = { id: 'synthetic-customer' };
let calls = 0;
const read = sdk.guard(() => { calls++; return payload; }, { tool: 'vendor.read', operation: 'read' });
const result = read();
if (result !== payload || calls !== 1) throw Error('Fixture identity changed');
// A labelled unavailable-engine fixture produces one bypass without a hosted key.
const unavailable = createAgindow({ mode: 'observe' }, async () => { throw Error('Synthetic loading fault'); });
await unavailable.ready;
const fallback = unavailable.wrap(() => payload);
if (fallback() !== payload || unavailable.recent().filter(e => e.type === 'bypass').length !== 1) throw Error('Missing bypass');
sdk.configure({ mode: 'observe' });
console.log('Synthetic fixture: original result retained; unavailable engine bypassed once.');import asyncio
from agindow import Agindow
sdk = Agindow(mode="observe")
payload = {"id": "synthetic-customer"}
@sdk.guard(tool="vendor.read", operation="read")
def read() -> dict[str, str]:
return payload
@sdk.guard(tool="vendor.read", operation="read")
async def read_async() -> dict[str, str]:
return payload
with sdk.context(mode="observe"):
assert read() is payload
async def main() -> None:
async with sdk.context(mode="observe"):
assert await read_async() is payload
asyncio.run(main())
# A closed engine is a labelled availability fixture, not vendor drift.
sdk.close()
assert read() is payload
assert len([event for event in sdk.recent() if event.type == "bypass"]) == 1
print("Synthetic fixture: sync/async identity retained; closed engine bypassed once.")guard, wrap and adapters
sdk.guard(fn, options) retains sync/async behavior, receiver, arguments, original exceptions and no-repair result identity. sdk.wrap selects a supported boundary. sdk.toolAdapter, sdk.clientAdapter and sdk.httpAdapter expose explicit adapters. Module exports guard and wrap use the default instance. HTTP streaming and framework batch paths have explicit capture limits; no universal framework adapter is implied.
configure and mode resolution
sdk.configure changes later calls. Resolution at construction is explicit > environment > nearest JSON .agindowrc > defaults. Calls freeze configuration through completion. Default mode is observe and statistical guest is default; configure windows to detect, with no default selective repair. Use operation: write or unknown explicitly for writes; generic callables default to read. Later configure updates can supersede existing guard options for future calls.
Events, audit and explicit remote API
sdk.on returns an unsubscribe callback; sdk.recent returns recent metadata up to the local capacity limit. Optional audit requires explicit tenant options and a host destination passed to sdk.drainAudit. guardRemote is a separate opt-in HTTP API, never the default guard. Write fallbacks require vendor-enforced idempotency. Reviewed selective repair is an explicit SDK option. Durable replay and hosted delivery remain unavailable.
Method reference
Signatures below use the published TypeScript names. Guard options are optional; mark writes explicitly. Setup validation can throw AgindowSetupError before a call runs.
| Method / input | Return / failure |
|---|---|
| createAgindow(options?) | SDK instance. options: mode, selection, onEvent, buffer, audit and other typed configuration. Invalid setup throws AgindowSetupError. |
| sdk.ready | Promise<void> that settles after loading; settlement alone does not prove detection was configured or loaded successfully. |
| sdk.guard(fn, {tool?, operation?, mode?, failClosed?}) | Same callable type, receiver, arguments and sync/async behavior. Original result or upstream exception; policy may throw AgindowDriftError. |
| sdk.wrap(target, options?) | Wrapped callable, tool map/array, supported client or HTTP target. Ambiguous boundaries require an explicit adapter. |
| sdk.toolAdapter / clientAdapter / httpAdapter(target, options?) | Explicit wrapped target of the original type. Unsupported shapes are setup errors; streaming inspection can bypass. |
| sdk.configure(config) | void. Applies changes to future calls; executing calls retain their configuration. |
| sdk.on(kind, listener) | Unsubscribe callback. kind: drift, repair, blocked, bypass or error. Listener faults do not affect upstream execution. |
| sdk.recent() | Recently retained event metadata, limited by local capacity; not a durable audit archive. |
| sdk.simulate(tool, {recorded, args?, partial?, contract?, mode?, operation?}) | Simulation with status, driftClass, confidence, changes, byte_identical and wouldWrite. Never calls upstream. partial evidence bypasses. |
| sdk.drainAudit(sink, limit = 64) | Promise<{delivered, pending, dropped, available}>. Requires explicit audit configuration; it sends records to your destination after the guarded call. Delivery failure remains visible as unavailable. |
| guardRemote(original, envelope, options) | Promise<Response | fallback result>. Explicit HTTP execution; see Remote SDK reference for timeout, feedback and fallback behavior. |
Configuration and events
Look up construction options, defaults, selection fields and per-call overrides before wrapping your client. Event metadata is separate from an audit archive.
Errors and outcomes
AgindowSetupError identifies deterministic setup misuse before execution. AgindowDriftError identifies a policy halt and exposes phase, verdict, retained outcome and feedback; preserve the original cause. Engine warming, loading failure and inspection faults emit bypass and preserve the original result or exception. A response-phase halt cannot undo a completed upstream write. A no-finding default call does not prove detection is active.
Continue
Use the pinned package for your application runtime and choose embedded or remote execution explicitly.