@abaigram/abai-stub 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -2
  3. package/dist/audit.d.ts +70 -0
  4. package/dist/audit.d.ts.map +1 -0
  5. package/dist/audit.js +166 -0
  6. package/dist/audit.js.map +1 -0
  7. package/dist/cells/fit.d.ts +6 -0
  8. package/dist/cells/fit.d.ts.map +1 -0
  9. package/dist/cells/fit.js +44 -0
  10. package/dist/cells/fit.js.map +1 -0
  11. package/dist/content.d.ts +17 -0
  12. package/dist/content.d.ts.map +1 -0
  13. package/dist/content.js +71 -0
  14. package/dist/content.js.map +1 -0
  15. package/dist/endpoint.d.ts +90 -0
  16. package/dist/endpoint.d.ts.map +1 -0
  17. package/dist/endpoint.js +789 -0
  18. package/dist/endpoint.js.map +1 -0
  19. package/dist/entry.d.ts +36 -0
  20. package/dist/entry.d.ts.map +1 -0
  21. package/dist/entry.js +409 -0
  22. package/dist/entry.js.map +1 -0
  23. package/dist/env.d.ts +38 -0
  24. package/dist/env.d.ts.map +1 -0
  25. package/dist/env.js +69 -0
  26. package/dist/env.js.map +1 -0
  27. package/dist/harness-binding.d.ts +223 -0
  28. package/dist/harness-binding.d.ts.map +1 -0
  29. package/dist/harness-binding.js +589 -0
  30. package/dist/harness-binding.js.map +1 -0
  31. package/dist/index.d.ts +17 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +17 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/manifest/index.d.ts +3 -0
  36. package/dist/manifest/index.d.ts.map +1 -0
  37. package/dist/manifest/index.js +3 -0
  38. package/dist/manifest/index.js.map +1 -0
  39. package/dist/manifest/manifest.d.ts +172 -0
  40. package/dist/manifest/manifest.d.ts.map +1 -0
  41. package/dist/manifest/manifest.js +443 -0
  42. package/dist/manifest/manifest.js.map +1 -0
  43. package/dist/manifest/render.d.ts +6 -0
  44. package/dist/manifest/render.d.ts.map +1 -0
  45. package/dist/manifest/render.js +39 -0
  46. package/dist/manifest/render.js.map +1 -0
  47. package/dist/null-harness.d.ts +32 -0
  48. package/dist/null-harness.d.ts.map +1 -0
  49. package/dist/null-harness.js +162 -0
  50. package/dist/null-harness.js.map +1 -0
  51. package/dist/program.d.ts +250 -0
  52. package/dist/program.d.ts.map +1 -0
  53. package/dist/program.js +877 -0
  54. package/dist/program.js.map +1 -0
  55. package/dist/region.d.ts +72 -0
  56. package/dist/region.d.ts.map +1 -0
  57. package/dist/region.js +92 -0
  58. package/dist/region.js.map +1 -0
  59. package/dist/registry.d.ts +57 -0
  60. package/dist/registry.d.ts.map +1 -0
  61. package/dist/registry.js +101 -0
  62. package/dist/registry.js.map +1 -0
  63. package/dist/wire/descriptor.d.ts +38 -0
  64. package/dist/wire/descriptor.d.ts.map +1 -0
  65. package/dist/wire/descriptor.js +144 -0
  66. package/dist/wire/descriptor.js.map +1 -0
  67. package/dist/wire/framing.d.ts +11 -0
  68. package/dist/wire/framing.d.ts.map +1 -0
  69. package/dist/wire/framing.js +42 -0
  70. package/dist/wire/framing.js.map +1 -0
  71. package/dist/wire/index.d.ts +4 -0
  72. package/dist/wire/index.d.ts.map +1 -0
  73. package/dist/wire/index.js +4 -0
  74. package/dist/wire/index.js.map +1 -0
  75. package/dist/wire/protocol.d.ts +255 -0
  76. package/dist/wire/protocol.d.ts.map +1 -0
  77. package/dist/wire/protocol.js +15 -0
  78. package/dist/wire/protocol.js.map +1 -0
  79. package/package.json +36 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-binding.js","sourceRoot":"","sources":["../src/harness-binding.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,4EAA4E;AAC5E,6EAA6E;AAC7E,wEAAwE;AACxE,4EAA4E;AAC5E,0EAA0E;AAC1E,4EAA4E;AAC5E,wCAAwC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACp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CACH;IAED,OAAO,CAAC,GAAW,EAAQ;QAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;QACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QACnD,IAAI,IAAI;YAAE,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAAA,CAChD;CACD","sourcesContent":["// The direct face (abaigrammar section 4.1): what the stub hands a harness\n// that attaches in-process. One object serves both sides. To the program it\n// is the AttachedHarness that decisions, turns, touchpoints and emits reach;\n// to the harness it is the channels: cells and events to read, knobs to\n// write, capabilities to call, decisions and turns to answer, the audit log\n// to tail, the counters to take. Every act of control is audited here, on\n// the program side, as section 10 says, with the consent the harness states\n// for an act whose policy is `confirm`.\nimport { resolve } from \"node:path\";\nimport { AuditLog, type AuditOutcome, type AuditTail, capValue, summarizeAnswer } from \"./audit.ts\";\nimport { validateKnobValue } from \"./cells/fit.ts\";\nimport { expandHome } from \"./env.ts\";\nimport {\n\ttype CapabilityDecl,\n\ttype DecisionDecl,\n\tdurationMs,\n\ttype FieldSchema,\n\tfieldOf,\n\ttype Manifest,\n\tmatchesType,\n\ttype TurnDecl,\n} from \"./manifest/manifest.ts\";\nimport type { Abaigram, AttachedHarness, CounterSnapshot } from \"./program.ts\";\nimport type { EventSlot } from \"./region.ts\";\nimport type { WireErrorCode } from \"./wire/protocol.ts\";\n\nexport interface DecisionRequest {\n\tid: string;\n\tname: string;\n\tdecision: DecisionDecl;\n\tcontext: Record<string, unknown>;\n\t/** Epoch milliseconds by which an answer must arrive. */\n\tdeadline: number;\n}\n\nexport interface TurnRequest {\n\tid: string;\n\tname: string;\n\tturn: TurnDecl;\n\tdeadline: number;\n\t/** The content slot for this turn, when the program has one. */\n\tcontent: string | undefined;\n}\n\nexport type TouchpointKind = \"install\" | \"session\";\n\nexport interface TouchpointRequest {\n\tid: string;\n\tkind: TouchpointKind;\n\tcontent: string | undefined;\n}\n\nexport interface LiveEvent {\n\tseq: number;\n\tname: string;\n\tpayload: Record<string, unknown> | undefined;\n\ttruncated: boolean;\n\tts: number;\n}\n\nexport interface EventBatch {\n\tevents: LiveEvent[];\n\t/** Events overwritten before they were read; the harness synthesizes `abai.events.dropped` from it. */\n\tdropped: number;\n\tnext: number;\n}\n\nexport interface CellReading {\n\tvalue: unknown;\n\tversion: number;\n}\n\nexport interface KnobWriteOutcome {\n\tvalue: unknown;\n\toutcome: \"done\" | \"failed\";\n\terror?: string;\n\t/** Why it failed, in the capability error vocabulary (the endpoint sends it under `call_codes`). */\n\tcode?: CallErrorCode;\n}\n\n/**\n * What the harness states about an act whose policy is `confirm` (section\n * 10): a person approved it, the harness approved it without asking (auto\n * mode, or the exercise form standing in for the abaigrammer), or it was\n * denied. An act under `auto` policy needs none.\n */\nexport type Consent = \"approved\" | \"auto\" | \"denied\";\n\n/** Why a call failed: the one vocabulary, in process and on the wire. */\nexport type CallErrorCode = WireErrorCode;\n\nexport type LifecycleOutcome = { ok: true; data?: unknown } | { ok: false; code: CallErrorCode; error: string };\n\n/** A capability call that did not return a result. */\nexport class CallError extends Error {\n\treadonly code: CallErrorCode;\n\tconstructor(code: CallErrorCode, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"CallError\";\n\t\tthis.code = code;\n\t}\n}\n\nexport interface BindingEvents {\n\tevent: (event: LiveEvent) => void;\n\tdecision: (request: DecisionRequest) => void;\n\t/** The decision expired: the program applied the default. */\n\tdecision_timeout: (id: string, name: string) => void;\n\tturn: (request: TurnRequest) => void;\n\ttouchpoint: (request: TouchpointRequest) => void;\n\tdetach: (reason: string) => void;\n}\n\n/**\n * The harness's view of the stub, in-process. The optional trailing `conn`\n * of the acting methods names the connection that acts, for a front end\n * that multiplexes several (the sidecar endpoint); the audit record carries\n * it. An in-process harness passes none and is audited under the binding's\n * own label.\n */\nexport interface HarnessBinding {\n\treadonly manifest: Manifest;\n\treadonly name: string;\n\treadonly connection: string;\n\tcontent(): {\n\t\tidentity: string;\n\t\tinstall: string | undefined;\n\t\tuse: string | undefined;\n\t\tturn(name: string): string | undefined;\n\t};\n\treadCells(names?: string[]): { seq: number; cells: Record<string, CellReading> };\n\treadEvents(after: number): EventBatch;\n\twriteKnob(name: string, value: unknown, reason: string, consent?: Consent, conn?: string): Promise<KnobWriteOutcome>;\n\tcall(\n\t\tname: string,\n\t\tparams: Record<string, unknown> | undefined,\n\t\treason: string,\n\t\tconsent?: Consent,\n\t\tconn?: string,\n\t): Promise<unknown>;\n\tauditTail(limit: number): AuditTail;\n\t/** Where the audit log is, and the error that latched it off, if any. */\n\tauditInfo(): { path: string; failed: string | null };\n\ttakeCounters(): CounterSnapshot;\n\ton<K extends keyof BindingEvents>(type: K, listener: BindingEvents[K]): () => void;\n\t/** Answer a pending decision; `null` means \"apply the default\" with this reason. Throws when the answer is invalid. */\n\tanswerDecision(id: string, answer: unknown, reason: string, consent?: Consent, conn?: string): void;\n\t/**\n\t * Let a pending decision take its default now, for a cause of the front\n\t * end's: `no_harness` when nobody holds it, `timeout` when a claim's own\n\t * shorter wait ran out, `detached` when its claimant went away. Audited\n\t * like every other settlement, and `decision_timeout` is notified for a\n\t * timeout, so one path serves every cause.\n\t */\n\tdefaultDecision(id: string, cause: string, conn?: string): void;\n\t/** @internal Name the connection that was asked a pending decision, so its settlement is audited under it. */\n\tassignDecision(id: string, conn: string): void;\n\tpendingDecisions(): DecisionRequest[];\n\t/** End a turn. `cause` says why the agent did nothing with it (the grammar's `budget`), and is audited. */\n\tendTurn(id: string, conn?: string, cause?: string): void;\n\tendTouchpoint(id: string): void;\n\t/**\n\t * A lifecycle operation of the program's own (section 5.5): `status`,\n\t * `pause` and `resume` for a cooperative pause, `stop` for the declared\n\t * stop handler. Policy and consent are checked here like any act of\n\t * control, and the acts that change something are audited.\n\t */\n\tlifecycle(op: string, reason: string, consent?: Consent, conn?: string): LifecycleOutcome;\n\tdetach(reason: string): void;\n\treadonly attached: boolean;\n}\n\ninterface Pending<T> {\n\tresolve: (value: T) => void;\n\treject: (error: Error) => void;\n\ttimer: NodeJS.Timeout | undefined;\n\tstartedAt: number;\n\t/** The connection this was asked of, when a front end named one. */\n\tconn?: string;\n}\n\n/**\n * A touchpoint has no timeout of its own, so nothing of the program's holds\n * its event loop open while a harness in another process holds the\n * touchpoint; this ref'd timer does, and never fires in practice (the\n * longest delay a timer takes). Cleared when the touchpoint ends.\n */\nconst TOUCHPOINT_KEEPALIVE_MS = 2 ** 31 - 1;\n\nexport interface BindingOptions {\n\t/** Where the audit log goes; default: the manifest's path, `~` expanded, relative to the program's root. */\n\tauditPath?: string;\n\tconnection?: string;\n}\n\n/**\n * Check a value against a schema: an object with no undeclared field, whose\n * every present field is of its declared type. A declared field may be\n * absent (decided 2026-10-14: the schema language has no required marker,\n * and a manifest's own defaults omit fields); `nullable` governs an\n * explicit null. Nested objects and lists are checked by `matchesType`.\n */\nexport function schemaProblem(schema: Record<string, FieldSchema>, value: unknown, what: string): string | undefined {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return `${what} must be an object`;\n\tconst record = value as Record<string, unknown>;\n\tfor (const [key, field] of Object.entries(schema)) {\n\t\tconst item = record[key];\n\t\tif (item === undefined) continue;\n\t\tif (!matchesType(item, field)) return `${what}.${key} must be a ${fieldOf(field).type}`;\n\t}\n\tfor (const key of Object.keys(record)) {\n\t\tif (!(key in schema)) return `${what} has an undeclared field ${key}`;\n\t}\n\treturn undefined;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction consentGranted(consent: Consent | undefined): boolean {\n\treturn consent === \"approved\" || consent === \"auto\";\n}\n\nexport class DirectBinding implements HarnessBinding, AttachedHarness {\n\treadonly manifest: Manifest;\n\treadonly name: string;\n\treadonly connection: string;\n\tprivate readonly app: Abaigram;\n\tprivate readonly audit: AuditLog;\n\tprivate readonly listeners: { [K in keyof BindingEvents]: Set<BindingEvents[K]> } = {\n\t\tevent: new Set(),\n\t\tdecision: new Set(),\n\t\tdecision_timeout: new Set(),\n\t\tturn: new Set(),\n\t\ttouchpoint: new Set(),\n\t\tdetach: new Set(),\n\t};\n\tprivate readonly decisions = new Map<string, Pending<unknown> & { request: DecisionRequest }>();\n\tprivate readonly turns = new Map<string, Pending<void> & { request: TurnRequest }>();\n\tprivate readonly touchpoints = new Map<string, Pending<void> & { request: TouchpointRequest }>();\n\tprivate readonly capabilityIndex = new Map<string, CapabilityDecl>();\n\t/** Touchpoints in progress: while one is open the program sits at a safepoint, so queued work runs at once (section 5.3). */\n\tprivate openTouchpoints = 0;\n\tprivate nextId = 1;\n\tprivate _attached = true;\n\n\tconstructor(app: Abaigram, options: BindingOptions = {}) {\n\t\tthis.app = app;\n\t\tthis.manifest = app.manifest;\n\t\tthis.name = app.manifest.name;\n\t\tthis.connection = options.connection ?? \"direct\";\n\t\tfor (const capability of this.manifest.capabilities) this.capabilityIndex.set(capability.name, capability);\n\t\tconst auditPath = options.auditPath ?? resolve(app.content.root, expandHome(this.manifest.audit.path));\n\t\tthis.audit = new AuditLog(auditPath, (error) => {\n\t\t\tapp.emitLibrary(\"abai.audit.failed\", { error });\n\t\t});\n\t}\n\n\tget attached(): boolean {\n\t\treturn this._attached;\n\t}\n\n\t/** @internal Called by the program once the binding is set: the counters go to the log first (section 10). */\n\tflushCounters(): void {\n\t\tconst counters = this.app.takeCounters();\n\t\tfor (const [name, count] of Object.entries(counters)) {\n\t\t\tif (count === 0) continue;\n\t\t\tconst cause = name === \"abai.mode_fallback\" ? \"mode_fallback\" : \"no_harness\";\n\t\t\tthis.audit.append({ act: \"counters\", name, outcome: \"default\", cause, count });\n\t\t}\n\t}\n\n\t/** Queue work for the program's next safepoint, or run it now when a touchpoint holds the program at one. */\n\tprivate atSafepoint(work: () => void): void {\n\t\tthis.app.enqueue(work);\n\t\tif (this.openTouchpoints > 0) this.app.drain();\n\t}\n\n\t/**\n\t * @internal The program is at a safepoint and will stay there (its entry\n\t * serving an MCP client): safepoint-dispatched work runs at once rather\n\t * than waiting for a safepoint the program would never reach. Paired\n\t * with `leaveSafepoint`.\n\t */\n\tenterSafepoint(): void {\n\t\tthis.openTouchpoints += 1;\n\t\tthis.app.drain();\n\t}\n\n\t/** @internal */\n\tleaveSafepoint(): void {\n\t\tif (this.openTouchpoints > 0) this.openTouchpoints -= 1;\n\t}\n\n\t// -----------------------------------------------------------------------\n\t// Harness side\n\t// -----------------------------------------------------------------------\n\n\tcontent(): {\n\t\tidentity: string;\n\t\tinstall: string | undefined;\n\t\tuse: string | undefined;\n\t\tturn(name: string): string | undefined;\n\t} {\n\t\tconst slots = this.app.content;\n\t\treturn {\n\t\t\tidentity: slots.identity(),\n\t\t\tinstall: slots.install(),\n\t\t\tuse: slots.use(),\n\t\t\tturn: (name) => slots.turn(name),\n\t\t};\n\t}\n\n\treadCells(names?: string[]): { seq: number; cells: Record<string, CellReading> } {\n\t\tconst all = this.app.readCells();\n\t\tconst cells: Record<string, CellReading> = {};\n\t\tfor (const name of names ?? Object.keys(all)) {\n\t\t\tif (!(name in all)) throw new Error(`unknown cell: ${name}`);\n\t\t\tcells[name] = { value: all[name], version: this.app.version(name) };\n\t\t}\n\t\treturn { seq: this.app.region.lastSeq, cells };\n\t}\n\n\treadEvents(after: number): EventBatch {\n\t\tconst read = this.app.region.readEvents(after);\n\t\treturn { events: read.slots.map((slot) => this.live(slot)), dropped: read.dropped, next: read.next };\n\t}\n\n\tprivate live(slot: EventSlot): LiveEvent {\n\t\treturn {\n\t\t\tseq: slot.seq,\n\t\t\tname: this.app.eventName(slot.event),\n\t\t\tpayload: slot.payload,\n\t\t\ttruncated: slot.truncated,\n\t\t\tts: slot.ts,\n\t\t};\n\t}\n\n\tasync writeKnob(\n\t\tname: string,\n\t\tvalue: unknown,\n\t\treason: string,\n\t\tconsent?: Consent,\n\t\tconn?: string,\n\t): Promise<KnobWriteOutcome> {\n\t\tconst decl = this.manifest.cells.find((cell) => cell.name === name);\n\t\tconst started = this.app.now();\n\t\tconst record = (\n\t\t\toutcome: AuditOutcome,\n\t\t\tlanded: unknown,\n\t\t\terror?: string,\n\t\t\tcause?: CallErrorCode,\n\t\t): KnobWriteOutcome => {\n\t\t\tthis.audit.append({\n\t\t\t\tconn: conn ?? this.connection,\n\t\t\t\tact: \"knob\",\n\t\t\t\tname,\n\t\t\t\tvalue: capValue(landed),\n\t\t\t\toutcome,\n\t\t\t\t...(cause === undefined ? {} : { cause }),\n\t\t\t\t...(consent === undefined ? {} : { consent }),\n\t\t\t\treason,\n\t\t\t\t...(error === undefined ? {} : { error }),\n\t\t\t\tms: this.app.now() - started,\n\t\t\t});\n\t\t\treturn outcome === \"ok\"\n\t\t\t\t? { value: landed, outcome: \"done\" }\n\t\t\t\t: { value: landed, outcome: \"failed\", error, ...(cause === undefined ? {} : { code: cause }) };\n\t\t};\n\t\tif (!decl) return record(\"error\", undefined, `unknown cell: ${name}`, \"unknown\");\n\t\tif (decl.access !== \"readwrite\") return record(\"error\", undefined, `${name} is read-only`, \"invalid\");\n\t\tif (decl.policy === \"confirm\" && !consentGranted(consent)) {\n\t\t\treturn record(\"error\", undefined, `${name} needs consent (its policy is confirm)`, \"denied\");\n\t\t}\n\t\tconst problem = validateKnobValue(decl, value);\n\t\tif (problem !== undefined) return record(\"error\", undefined, problem, \"invalid\");\n\t\tconst sized = decl.type === \"string\" || decl.type === \"object\" || decl.type === \"list\";\n\t\tif (!sized) {\n\t\t\tthis.app.knob(name).set(value);\n\t\t\treturn record(\"ok\", this.app.cell(name).get());\n\t\t}\n\t\t// a sized knob is delivered at the program's next safepoint, to its handler, within its delivery timeout (section 5.2)\n\t\tconst handler = this.app.knobHandler(name);\n\t\tif (!handler) {\n\t\t\treturn record(\"failed\", undefined, `no handler registered for ${name}: nothing can receive it`, \"error\");\n\t\t}\n\t\tconst timeoutMs = durationMs(decl.timeout ?? \"30s\");\n\t\treturn new Promise<KnobWriteOutcome>((done) => {\n\t\t\tlet settled = false;\n\t\t\tconst work = (): void => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tthis.app.cell(name).set(value);\n\t\t\t\tconst landed = this.app.cell(name).get();\n\t\t\t\ttry {\n\t\t\t\t\thandler(landed);\n\t\t\t\t\tdone(record(\"ok\", landed));\n\t\t\t\t} catch (error) {\n\t\t\t\t\tdone(record(\"error\", landed, errorMessage(error), \"error\"));\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tthis.app.dequeue(work);\n\t\t\t\tdone(\n\t\t\t\t\trecord(\n\t\t\t\t\t\t\"failed\",\n\t\t\t\t\t\tundefined,\n\t\t\t\t\t\t`not delivered within ${decl.timeout ?? \"30s\"}: the program reached no safepoint`,\n\t\t\t\t\t\t\"timeout\",\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}, timeoutMs);\n\t\t\ttimer.unref();\n\t\t\tthis.atSafepoint(work);\n\t\t});\n\t}\n\n\tasync call(\n\t\tname: string,\n\t\tparams: Record<string, unknown> | undefined,\n\t\treason: string,\n\t\tconsent?: Consent,\n\t\tconn?: string,\n\t): Promise<unknown> {\n\t\tconst decl = this.capabilityIndex.get(name);\n\t\tconst started = this.app.now();\n\t\tconst record = (outcome: AuditOutcome, extra: { error?: string; cause?: string } = {}): void => {\n\t\t\tthis.audit.append({\n\t\t\t\tconn: conn ?? this.connection,\n\t\t\t\tact: \"capability\",\n\t\t\t\tname,\n\t\t\t\tparams: capValue(params),\n\t\t\t\toutcome,\n\t\t\t\t...(consent === undefined ? {} : { consent }),\n\t\t\t\treason,\n\t\t\t\t...extra,\n\t\t\t\tms: this.app.now() - started,\n\t\t\t});\n\t\t};\n\t\tconst fail = (code: CallErrorCode, message: string): CallError => {\n\t\t\trecord(code === \"forbidden\" ? \"forbidden\" : \"error\", { error: message, cause: code });\n\t\t\treturn new CallError(code, message);\n\t\t};\n\t\tif (!decl) throw fail(\"unknown\", `${this.name} declares no capability ${name}`);\n\t\tif (decl.policy === \"forbid\") throw fail(\"forbidden\", `the program's policy forbids ${name}`);\n\t\tif (decl.policy === \"confirm\" && !consentGranted(consent))\n\t\t\tthrow fail(\"denied\", `${name} needs consent (its policy is confirm)`);\n\t\tconst problem = schemaProblem(decl.params, params ?? {}, \"params\");\n\t\tif (problem !== undefined) throw fail(\"invalid\", problem);\n\t\tconst timeoutMs = durationMs(decl.timeout ?? \"30s\");\n\t\tconst result = await new Promise<unknown>((done, reject) => {\n\t\t\tlet settled = false;\n\t\t\tconst settle = (fn: () => void): void => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tfn();\n\t\t\t};\n\t\t\t// the handler is resolved at dispatch, so one registered after startup still serves\n\t\t\tconst run = (): void => {\n\t\t\t\tif (settled) return;\n\t\t\t\tconst handler = this.app.capabilityHandler(name);\n\t\t\t\tif (!handler) {\n\t\t\t\t\tsettle(() => reject(new CallError(\"error\", `${name} has no handler registered`)));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlet outcome: unknown;\n\t\t\t\ttry {\n\t\t\t\t\toutcome = handler(params ?? {}); // synchronous part runs inside the safepoint, on the program's thread\n\t\t\t\t} catch (error) {\n\t\t\t\t\tsettle(() => reject(new CallError(\"error\", errorMessage(error))));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tPromise.resolve(outcome).then(\n\t\t\t\t\t(value) => settle(() => done(value)),\n\t\t\t\t\t(error) => settle(() => reject(new CallError(\"error\", errorMessage(error)))),\n\t\t\t\t);\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tif (settled) return;\n\t\t\t\tsettled = true;\n\t\t\t\tthis.app.dequeue(run);\n\t\t\t\treject(new CallError(\"timeout\", `${name} did not answer within ${decl.timeout ?? \"30s\"}`));\n\t\t\t}, timeoutMs);\n\t\t\ttimer.unref();\n\t\t\tif (decl.dispatch === \"immediate\") run();\n\t\t\telse this.atSafepoint(run);\n\t\t}).catch((error: CallError) => {\n\t\t\trecord(\"error\", { error: error.message, cause: error.code });\n\t\t\tthrow error;\n\t\t});\n\t\trecord(\"ok\");\n\t\treturn result;\n\t}\n\n\tauditTail(limit: number): AuditTail {\n\t\treturn this.audit.tail(limit);\n\t}\n\n\tauditInfo(): { path: string; failed: string | null } {\n\t\treturn { path: this.audit.path, failed: this.audit.failed ?? null };\n\t}\n\n\ttakeCounters(): CounterSnapshot {\n\t\treturn this.app.takeCounters();\n\t}\n\n\ton<K extends keyof BindingEvents>(type: K, listener: BindingEvents[K]): () => void {\n\t\tconst set = this.listeners[type] as Set<BindingEvents[K]>;\n\t\tset.add(listener);\n\t\treturn () => {\n\t\t\tset.delete(listener);\n\t\t};\n\t}\n\n\tprivate notify<K extends keyof BindingEvents>(type: K, ...args: Parameters<BindingEvents[K]>): void {\n\t\tfor (const listener of this.listeners[type]) {\n\t\t\ttry {\n\t\t\t\t(listener as (...a: Parameters<BindingEvents[K]>) => void)(...args);\n\t\t\t} catch {\n\t\t\t\t// a harness listener's failure never reaches the program\n\t\t\t}\n\t\t}\n\t}\n\n\tanswerDecision(id: string, answer: unknown, reason: string, consent?: Consent, conn?: string): void {\n\t\tconst pending = this.decisions.get(id);\n\t\tif (!pending) throw new Error(`no pending decision ${id}`);\n\t\tif (reason.trim() === \"\") throw new Error(\"a decision needs a reason\");\n\t\tif (conn !== undefined) pending.conn = conn;\n\t\tconst { decision } = pending.request;\n\t\tif (answer !== null) {\n\t\t\tconst problem = decision.options\n\t\t\t\t? decision.options.includes(answer as string)\n\t\t\t\t\t? undefined\n\t\t\t\t\t: `answer must be one of: ${decision.options.join(\", \")}`\n\t\t\t\t: schemaProblem(decision.answer ?? {}, answer, \"answer\");\n\t\t\tif (problem !== undefined) {\n\t\t\t\tthis.settleDecision(id, { source: \"default\", cause: \"invalid\", reason, answer });\n\t\t\t\tthrow new Error(problem);\n\t\t\t}\n\t\t\tif (decision.policy === \"confirm\" && !consentGranted(consent)) {\n\t\t\t\tthis.settleDecision(id, { source: \"default\", cause: \"denied\", reason, consent });\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tthis.settleDecision(\n\t\t\tid,\n\t\t\tanswer === null\n\t\t\t\t? { source: \"default\", cause: \"answered\", reason }\n\t\t\t\t: { source: \"agent\", reason, answer, consent },\n\t\t);\n\t}\n\n\tdefaultDecision(id: string, cause: string, conn?: string): void {\n\t\tconst pending = this.decisions.get(id);\n\t\tif (!pending) return;\n\t\tif (conn !== undefined) pending.conn = conn;\n\t\tthis.settleDecision(id, { source: \"default\", cause });\n\t}\n\n\tassignDecision(id: string, conn: string): void {\n\t\tconst pending = this.decisions.get(id);\n\t\tif (pending) pending.conn = conn;\n\t}\n\n\tpendingDecisions(): DecisionRequest[] {\n\t\treturn [...this.decisions.values()].map((p) => p.request);\n\t}\n\n\tprivate settleDecision(\n\t\tid: string,\n\t\toutcome: { source: \"agent\" | \"default\"; cause?: string; reason?: string; answer?: unknown; consent?: Consent },\n\t): void {\n\t\tconst pending = this.decisions.get(id);\n\t\tif (!pending) return;\n\t\tthis.decisions.delete(id);\n\t\tif (pending.timer) clearTimeout(pending.timer);\n\t\tthis.openTouchpoints -= 1;\n\t\tconst { decision } = pending.request;\n\t\tthis.audit.append({\n\t\t\tconn: pending.conn ?? this.connection,\n\t\t\tact: \"decision\",\n\t\t\tname: decision.name,\n\t\t\tid,\n\t\t\tvalue: summarizeAnswer(decision, outcome.source === \"agent\" ? outcome.answer : decision.default),\n\t\t\toutcome: outcome.source,\n\t\t\t...(outcome.cause === undefined ? {} : { cause: outcome.cause }),\n\t\t\t...(outcome.consent === undefined ? {} : { consent: outcome.consent }),\n\t\t\t...(outcome.reason === undefined ? {} : { reason: outcome.reason }),\n\t\t\tms: this.app.now() - pending.startedAt,\n\t\t});\n\t\tif (outcome.source === \"agent\") pending.resolve(outcome.answer);\n\t\telse pending.reject(new Error(outcome.cause ?? \"default\"));\n\t\tif (outcome.cause === \"timeout\") this.notify(\"decision_timeout\", id, decision.name);\n\t}\n\n\tendTurn(id: string, conn?: string, cause?: string): void {\n\t\tconst pending = this.turns.get(id);\n\t\tif (!pending) return;\n\t\tif (conn !== undefined) pending.conn = conn;\n\t\t// a turn the agent did nothing with (held back by its budget) is a default, with the cause it names\n\t\tif (cause === undefined) this.settleTurn(id, \"ok\");\n\t\telse this.settleTurn(id, \"default\", cause);\n\t}\n\n\t/** @internal Queue work for the program's next safepoint, running it now when one is held open. */\n\tatNextSafepoint(work: () => void): void {\n\t\tthis.atSafepoint(work);\n\t}\n\n\tlifecycle(op: string, reason: string, consent?: Consent, conn?: string): LifecycleOutcome {\n\t\tconst declared = this.manifest.lifecycle;\n\t\tconst started = this.app.now();\n\t\tconst record = (outcome: AuditOutcome, extra: { cause?: string; error?: string } = {}): void => {\n\t\t\tthis.audit.append({\n\t\t\t\tconn: conn ?? this.connection,\n\t\t\t\tact: \"lifecycle\",\n\t\t\t\tname: op,\n\t\t\t\toutcome,\n\t\t\t\t...(consent === undefined ? {} : { consent }),\n\t\t\t\treason,\n\t\t\t\t...extra,\n\t\t\t\tms: this.app.now() - started,\n\t\t\t});\n\t\t};\n\t\tconst refuse = (code: CallErrorCode, error: string): LifecycleOutcome => {\n\t\t\trecord(code === \"forbidden\" ? \"forbidden\" : \"error\", { cause: code, error });\n\t\t\treturn { ok: false, code, error };\n\t\t};\n\t\tif (op === \"status\") return { ok: true, data: this.app.lifecycleStatus() };\n\t\tif (op !== \"pause\" && op !== \"resume\" && op !== \"stop\" && op !== \"restart\" && op !== \"start\") {\n\t\t\treturn { ok: false, code: \"unknown\", error: `unknown lifecycle operation: ${op}` };\n\t\t}\n\t\t// section 10: pause and resume are auto, stop and restart confirm, unless the manifest says otherwise\n\t\tconst policy =\n\t\t\tdeclared?.policy?.[op as \"pause\" | \"resume\" | \"stop\" | \"restart\"] ??\n\t\t\t(op === \"stop\" || op === \"restart\" ? \"confirm\" : \"auto\");\n\t\tif (policy === \"forbid\") return refuse(\"forbidden\", `the program's policy forbids lifecycle ${op}`);\n\t\tif (policy === \"confirm\" && !consentGranted(consent)) {\n\t\t\treturn refuse(\"denied\", `lifecycle ${op} needs consent (its policy is confirm)`);\n\t\t}\n\t\tswitch (op) {\n\t\t\tcase \"pause\":\n\t\t\t\tif (declared?.pause !== \"cooperative\") {\n\t\t\t\t\treturn refuse(\n\t\t\t\t\t\t\"invalid\",\n\t\t\t\t\t\tdeclared?.pause === \"os\"\n\t\t\t\t\t\t\t? \"this program declares os pause, which its launcher performs\"\n\t\t\t\t\t\t\t: \"this program declares no cooperative pause\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tthis.app.requestPause();\n\t\t\t\trecord(\"ok\");\n\t\t\t\treturn { ok: true };\n\t\t\tcase \"resume\":\n\t\t\t\tthis.app.resumeFromPause();\n\t\t\t\trecord(\"ok\");\n\t\t\t\treturn { ok: true };\n\t\t\tcase \"stop\": {\n\t\t\t\tif (!this.app.stopHandler) return refuse(\"invalid\", \"this program declares no stop handler\");\n\t\t\t\t// a stop supersedes a pause: a program held at a touchpoint goes on to the safepoint where the handler runs\n\t\t\t\tthis.app.resumeFromPause();\n\t\t\t\t// at the next safepoint, on the thread that reaches it (5.5); the program is expected to exit\n\t\t\t\tconst handler = this.app.stopHandler;\n\t\t\t\tthis.atNextSafepoint(() => {\n\t\t\t\t\t// on the thread that reached the safepoint; a failing handler is the program's own matter, and the\n\t\t\t\t\t// launcher's window runs either way\n\t\t\t\t\ttry {\n\t\t\t\t\t\tPromise.resolve(handler()).catch(() => {});\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// same\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t\trecord(\"ok\");\n\t\t\t\treturn { ok: true, data: { op, requested: true } };\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn refuse(\"invalid\", `lifecycle ${op} is the launcher's, not the program's`);\n\t\t}\n\t}\n\n\tprivate settleTurn(id: string, outcome: AuditOutcome, cause?: string): void {\n\t\tconst pending = this.turns.get(id);\n\t\tif (!pending) return;\n\t\tthis.turns.delete(id);\n\t\tif (pending.timer) clearTimeout(pending.timer);\n\t\tthis.openTouchpoints -= 1;\n\t\tthis.audit.append({\n\t\t\tconn: pending.conn ?? this.connection,\n\t\t\tact: \"turn\",\n\t\t\tname: pending.request.name,\n\t\t\tid,\n\t\t\toutcome,\n\t\t\t...(cause === undefined ? {} : { cause }),\n\t\t\tms: this.app.now() - pending.startedAt,\n\t\t});\n\t\tpending.resolve();\n\t}\n\n\tendTouchpoint(id: string): void {\n\t\tconst pending = this.touchpoints.get(id);\n\t\tif (!pending) return;\n\t\tthis.touchpoints.delete(id);\n\t\tif (pending.timer) clearInterval(pending.timer);\n\t\tthis.openTouchpoints -= 1;\n\t\tpending.resolve();\n\t}\n\n\tdetach(reason: string): void {\n\t\tif (!this._attached) return;\n\t\tthis._attached = false;\n\t\tfor (const id of [...this.decisions.keys()])\n\t\t\tthis.settleDecision(id, { source: \"default\", cause: \"detached\", reason });\n\t\tfor (const id of [...this.turns.keys()]) this.settleTurn(id, \"default\", \"detached\");\n\t\tfor (const id of [...this.touchpoints.keys()]) this.endTouchpoint(id);\n\t\tthis.notify(\"detach\", reason);\n\t\tthis.app.clearHarness(reason);\n\t\tthis.audit.close();\n\t}\n\n\t// -----------------------------------------------------------------------\n\t// Program side (AttachedHarness)\n\t// -----------------------------------------------------------------------\n\n\tdecide(decision: DecisionDecl, context: Record<string, unknown>, deadline: number): Promise<unknown> {\n\t\tif (decision.policy === \"forbid\") {\n\t\t\tthis.audit.append({\n\t\t\t\tconn: this.connection,\n\t\t\t\tact: \"decision\",\n\t\t\t\tname: decision.name,\n\t\t\t\toutcome: \"default\",\n\t\t\t\tcause: \"forbidden\",\n\t\t\t});\n\t\t\treturn Promise.reject(new Error(\"forbidden\"));\n\t\t}\n\t\tconst id = `d${this.nextId++}`;\n\t\tconst request: DecisionRequest = { id, name: decision.name, decision, context, deadline };\n\t\treturn new Promise<unknown>((resolve, reject) => {\n\t\t\t// this timer bounds the program's own wait: it keeps the process alive until the answer or the default\n\t\t\tconst timer = setTimeout(\n\t\t\t\t() => this.settleDecision(id, { source: \"default\", cause: \"timeout\" }),\n\t\t\t\tMath.max(0, deadline - this.app.now()),\n\t\t\t);\n\t\t\tthis.decisions.set(id, { request, resolve, reject, timer, startedAt: this.app.now() });\n\t\t\tthis.openTouchpoints += 1;\n\t\t\tthis.notify(\"decision\", request);\n\t\t});\n\t}\n\n\tturn(turn: TurnDecl, deadline: number): Promise<void> {\n\t\tconst id = `t${this.nextId++}`;\n\t\tconst request: TurnRequest = { id, name: turn.name, turn, deadline, content: this.app.content.turn(turn.name) };\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst timer = setTimeout(\n\t\t\t\t() => this.settleTurn(id, \"default\", \"timeout\"),\n\t\t\t\tMath.max(0, deadline - this.app.now()),\n\t\t\t);\n\t\t\tthis.turns.set(id, { request, resolve, reject, timer, startedAt: this.app.now() });\n\t\t\tthis.openTouchpoints += 1;\n\t\t\tthis.notify(\"turn\", request);\n\t\t});\n\t}\n\n\t/** @internal A program-initiated `install` or `session`; resolves when the harness ends it or detaches. */\n\ttouchpoint(kind: TouchpointKind): Promise<void> {\n\t\tconst id = `p${this.nextId++}`;\n\t\tconst content = kind === \"install\" ? this.app.content.install() : this.app.content.use();\n\t\tconst request: TouchpointRequest = { id, kind, content };\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tconst timer = setInterval(() => {}, TOUCHPOINT_KEEPALIVE_MS);\n\t\t\tthis.touchpoints.set(id, { request, resolve, reject, timer, startedAt: this.app.now() });\n\t\t\tthis.openTouchpoints += 1;\n\t\t\tthis.notify(\"touchpoint\", request);\n\t\t});\n\t}\n\n\temitted(seq: number): void {\n\t\tconst read = this.app.region.readEvents(seq - 1);\n\t\tconst slot = read.slots.find((s) => s.seq === seq);\n\t\tif (slot) this.notify(\"event\", this.live(slot));\n\t}\n}\n"]}
@@ -0,0 +1,17 @@
1
+ /** The abai stub: the library a TypeScript program includes to become an abaigram. See spec/abaigrammar.md. */
2
+ export declare const ABAI_STUB_VERSION = "0.1.0";
3
+ export { type AuditAct, AuditLog, type AuditOutcome, type AuditRecord, capValue, summarizeAnswer } from "./audit.ts";
4
+ export { fitValue, validateKnobValue } from "./cells/fit.ts";
5
+ export { type ContentSlots, createContent, findRoot, MANIFEST_FILE } from "./content.ts";
6
+ export { CONSECUTIVE_TIMEOUTS_LIMIT, DEFAULT_MAX_BUFFERED, Endpoint, type EndpointOptions, shortSocketPath, } from "./endpoint.ts";
7
+ export { type DoctorCheck, type DoctorReport, type EntryIo, runDoctor, runEntry } from "./entry.ts";
8
+ export { attachWaitMsFrom, DEFAULT_ATTACH_WAIT_MS, ENV_ATTACH_WAIT_MS, ENV_HARNESS, ENV_HARNESS_BIN, ENV_LAUNCH_SOCKET, ENV_MODE, ENV_RUN_DIR, expandHome, type HarnessSelection, runDirFrom, selectHarness, selectMode, } from "./env.ts";
9
+ export { type BindingEvents, CallError, type CallErrorCode, type CellReading, type Consent, type DecisionRequest, DirectBinding, type EventBatch, type HarnessBinding, type KnobWriteOutcome, type LiveEvent, schemaProblem, type TouchpointKind, type TouchpointRequest, type TurnRequest, } from "./harness-binding.ts";
10
+ export * from "./manifest/index.ts";
11
+ export { attachNullHarness, type NullForm, type NullHarness, type NullHarnessReport } from "./null-harness.ts";
12
+ export { Abaigram, AbaigramAbort, type AbaigramExtras, type AttachedHarness, type CellHandle, type CounterSnapshot, createAbaigram, ENV_HARNESS_MODULE, type EventHandle, type HarnessFactory, type KnobHandle, } from "./program.ts";
13
+ export { type EventSlot, FLAG_ATTACHED, FLAG_PARKED, FLAG_PAUSED, FLAG_QUEUE, Region, RING_CAPACITY, } from "./region.ts";
14
+ export { type AbaigramOptions, buildManifest, type CapabilityHandler, type CapabilityOptions, type CellOptions, type DecisionOptions, type EventOptions, INSTANTIATION_DEVIATIONS, type KnobHandler, SIDECAR_DEVIATION, type StopHandler, type TurnOptions, } from "./registry.ts";
15
+ export { MAX_SOCKET_PATH_BYTES } from "./wire/descriptor.ts";
16
+ export * from "./wire/index.ts";
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,eAAO,MAAM,iBAAiB,UAAU,CAAC;AAEzC,OAAO,EAAE,KAAK,QAAQ,EAAE,QAAQ,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACrH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,KAAK,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzF,OAAO,EACN,0BAA0B,EAC1B,oBAAoB,EACpB,QAAQ,EACR,KAAK,eAAe,EACpB,eAAe,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,KAAK,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EACN,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,UAAU,EACV,KAAK,gBAAgB,EACrB,UAAU,EACV,aAAa,EACb,UAAU,GACV,MAAM,UAAU,CAAC;AAClB,OAAO,EACN,KAAK,aAAa,EAClB,SAAS,EACT,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,eAAe,EACpB,aAAa,EACb,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,WAAW,GAChB,MAAM,sBAAsB,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,EACN,QAAQ,EACR,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,cAAc,EACd,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,UAAU,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACN,KAAK,SAAS,EACd,aAAa,EACb,WAAW,EACX,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,KAAK,eAAe,EACpB,aAAa,EACb,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,wBAAwB,EACxB,KAAK,WAAW,EAChB,iBAAiB,EACjB,KAAK,WAAW,EAChB,KAAK,WAAW,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,cAAc,iBAAiB,CAAC","sourcesContent":["/** The abai stub: the library a TypeScript program includes to become an abaigram. See spec/abaigrammar.md. */\nexport const ABAI_STUB_VERSION = \"0.1.0\";\n\nexport { type AuditAct, AuditLog, type AuditOutcome, type AuditRecord, capValue, summarizeAnswer } from \"./audit.ts\";\nexport { fitValue, validateKnobValue } from \"./cells/fit.ts\";\nexport { type ContentSlots, createContent, findRoot, MANIFEST_FILE } from \"./content.ts\";\nexport {\n\tCONSECUTIVE_TIMEOUTS_LIMIT,\n\tDEFAULT_MAX_BUFFERED,\n\tEndpoint,\n\ttype EndpointOptions,\n\tshortSocketPath,\n} from \"./endpoint.ts\";\nexport { type DoctorCheck, type DoctorReport, type EntryIo, runDoctor, runEntry } from \"./entry.ts\";\nexport {\n\tattachWaitMsFrom,\n\tDEFAULT_ATTACH_WAIT_MS,\n\tENV_ATTACH_WAIT_MS,\n\tENV_HARNESS,\n\tENV_HARNESS_BIN,\n\tENV_LAUNCH_SOCKET,\n\tENV_MODE,\n\tENV_RUN_DIR,\n\texpandHome,\n\ttype HarnessSelection,\n\trunDirFrom,\n\tselectHarness,\n\tselectMode,\n} from \"./env.ts\";\nexport {\n\ttype BindingEvents,\n\tCallError,\n\ttype CallErrorCode,\n\ttype CellReading,\n\ttype Consent,\n\ttype DecisionRequest,\n\tDirectBinding,\n\ttype EventBatch,\n\ttype HarnessBinding,\n\ttype KnobWriteOutcome,\n\ttype LiveEvent,\n\tschemaProblem,\n\ttype TouchpointKind,\n\ttype TouchpointRequest,\n\ttype TurnRequest,\n} from \"./harness-binding.ts\";\nexport * from \"./manifest/index.ts\";\nexport { attachNullHarness, type NullForm, type NullHarness, type NullHarnessReport } from \"./null-harness.ts\";\nexport {\n\tAbaigram,\n\tAbaigramAbort,\n\ttype AbaigramExtras,\n\ttype AttachedHarness,\n\ttype CellHandle,\n\ttype CounterSnapshot,\n\tcreateAbaigram,\n\tENV_HARNESS_MODULE,\n\ttype EventHandle,\n\ttype HarnessFactory,\n\ttype KnobHandle,\n} from \"./program.ts\";\nexport {\n\ttype EventSlot,\n\tFLAG_ATTACHED,\n\tFLAG_PARKED,\n\tFLAG_PAUSED,\n\tFLAG_QUEUE,\n\tRegion,\n\tRING_CAPACITY,\n} from \"./region.ts\";\nexport {\n\ttype AbaigramOptions,\n\tbuildManifest,\n\ttype CapabilityHandler,\n\ttype CapabilityOptions,\n\ttype CellOptions,\n\ttype DecisionOptions,\n\ttype EventOptions,\n\tINSTANTIATION_DEVIATIONS,\n\ttype KnobHandler,\n\tSIDECAR_DEVIATION,\n\ttype StopHandler,\n\ttype TurnOptions,\n} from \"./registry.ts\";\nexport { MAX_SOCKET_PATH_BYTES } from \"./wire/descriptor.ts\";\nexport * from \"./wire/index.ts\";\n"]}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ /** The abai stub: the library a TypeScript program includes to become an abaigram. See spec/abaigrammar.md. */
2
+ export const ABAI_STUB_VERSION = "0.1.0";
3
+ export { AuditLog, capValue, summarizeAnswer } from "./audit.js";
4
+ export { fitValue, validateKnobValue } from "./cells/fit.js";
5
+ export { createContent, findRoot, MANIFEST_FILE } from "./content.js";
6
+ export { CONSECUTIVE_TIMEOUTS_LIMIT, DEFAULT_MAX_BUFFERED, Endpoint, shortSocketPath, } from "./endpoint.js";
7
+ export { runDoctor, runEntry } from "./entry.js";
8
+ export { attachWaitMsFrom, DEFAULT_ATTACH_WAIT_MS, ENV_ATTACH_WAIT_MS, ENV_HARNESS, ENV_HARNESS_BIN, ENV_LAUNCH_SOCKET, ENV_MODE, ENV_RUN_DIR, expandHome, runDirFrom, selectHarness, selectMode, } from "./env.js";
9
+ export { CallError, DirectBinding, schemaProblem, } from "./harness-binding.js";
10
+ export * from "./manifest/index.js";
11
+ export { attachNullHarness } from "./null-harness.js";
12
+ export { Abaigram, AbaigramAbort, createAbaigram, ENV_HARNESS_MODULE, } from "./program.js";
13
+ export { FLAG_ATTACHED, FLAG_PARKED, FLAG_PAUSED, FLAG_QUEUE, Region, RING_CAPACITY, } from "./region.js";
14
+ export { buildManifest, INSTANTIATION_DEVIATIONS, SIDECAR_DEVIATION, } from "./registry.js";
15
+ export { MAX_SOCKET_PATH_BYTES } from "./wire/descriptor.js";
16
+ export * from "./wire/index.js";
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+GAA+G;AAC/G,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAEzC,OAAO,EAAiB,QAAQ,EAAuC,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACrH,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAqB,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACzF,OAAO,EACN,0BAA0B,EAC1B,oBAAoB,EACpB,QAAQ,EAER,eAAe,GACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAqD,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACpG,OAAO,EACN,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,UAAU,EAEV,UAAU,EACV,aAAa,EACb,UAAU,GACV,MAAM,UAAU,CAAC;AAClB,OAAO,EAEN,SAAS,EAKT,aAAa,EAKb,aAAa,GAIb,MAAM,sBAAsB,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,OAAO,EAAE,iBAAiB,EAA2D,MAAM,mBAAmB,CAAC;AAC/G,OAAO,EACN,QAAQ,EACR,aAAa,EAKb,cAAc,EACd,kBAAkB,GAIlB,MAAM,cAAc,CAAC;AACtB,OAAO,EAEN,aAAa,EACb,WAAW,EACX,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAEN,aAAa,EAMb,wBAAwB,EAExB,iBAAiB,GAGjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,cAAc,iBAAiB,CAAC","sourcesContent":["/** The abai stub: the library a TypeScript program includes to become an abaigram. See spec/abaigrammar.md. */\nexport const ABAI_STUB_VERSION = \"0.1.0\";\n\nexport { type AuditAct, AuditLog, type AuditOutcome, type AuditRecord, capValue, summarizeAnswer } from \"./audit.ts\";\nexport { fitValue, validateKnobValue } from \"./cells/fit.ts\";\nexport { type ContentSlots, createContent, findRoot, MANIFEST_FILE } from \"./content.ts\";\nexport {\n\tCONSECUTIVE_TIMEOUTS_LIMIT,\n\tDEFAULT_MAX_BUFFERED,\n\tEndpoint,\n\ttype EndpointOptions,\n\tshortSocketPath,\n} from \"./endpoint.ts\";\nexport { type DoctorCheck, type DoctorReport, type EntryIo, runDoctor, runEntry } from \"./entry.ts\";\nexport {\n\tattachWaitMsFrom,\n\tDEFAULT_ATTACH_WAIT_MS,\n\tENV_ATTACH_WAIT_MS,\n\tENV_HARNESS,\n\tENV_HARNESS_BIN,\n\tENV_LAUNCH_SOCKET,\n\tENV_MODE,\n\tENV_RUN_DIR,\n\texpandHome,\n\ttype HarnessSelection,\n\trunDirFrom,\n\tselectHarness,\n\tselectMode,\n} from \"./env.ts\";\nexport {\n\ttype BindingEvents,\n\tCallError,\n\ttype CallErrorCode,\n\ttype CellReading,\n\ttype Consent,\n\ttype DecisionRequest,\n\tDirectBinding,\n\ttype EventBatch,\n\ttype HarnessBinding,\n\ttype KnobWriteOutcome,\n\ttype LiveEvent,\n\tschemaProblem,\n\ttype TouchpointKind,\n\ttype TouchpointRequest,\n\ttype TurnRequest,\n} from \"./harness-binding.ts\";\nexport * from \"./manifest/index.ts\";\nexport { attachNullHarness, type NullForm, type NullHarness, type NullHarnessReport } from \"./null-harness.ts\";\nexport {\n\tAbaigram,\n\tAbaigramAbort,\n\ttype AbaigramExtras,\n\ttype AttachedHarness,\n\ttype CellHandle,\n\ttype CounterSnapshot,\n\tcreateAbaigram,\n\tENV_HARNESS_MODULE,\n\ttype EventHandle,\n\ttype HarnessFactory,\n\ttype KnobHandle,\n} from \"./program.ts\";\nexport {\n\ttype EventSlot,\n\tFLAG_ATTACHED,\n\tFLAG_PARKED,\n\tFLAG_PAUSED,\n\tFLAG_QUEUE,\n\tRegion,\n\tRING_CAPACITY,\n} from \"./region.ts\";\nexport {\n\ttype AbaigramOptions,\n\tbuildManifest,\n\ttype CapabilityHandler,\n\ttype CapabilityOptions,\n\ttype CellOptions,\n\ttype DecisionOptions,\n\ttype EventOptions,\n\tINSTANTIATION_DEVIATIONS,\n\ttype KnobHandler,\n\tSIDECAR_DEVIATION,\n\ttype StopHandler,\n\ttype TurnOptions,\n} from \"./registry.ts\";\nexport { MAX_SOCKET_PATH_BYTES } from \"./wire/descriptor.ts\";\nexport * from \"./wire/index.ts\";\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./manifest.ts";
2
+ export * from "./render.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/manifest/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./manifest.ts\";\nexport * from \"./render.ts\";\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./manifest.js";
2
+ export * from "./render.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/manifest/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC","sourcesContent":["export * from \"./manifest.ts\";\nexport * from \"./render.ts\";\n"]}
@@ -0,0 +1,172 @@
1
+ export declare const ABAIGRAMMAR_VERSION = "0.1";
2
+ export type ScalarType = "bool" | "int" | "float" | "enum";
3
+ export type SizedType = "string" | "object" | "list";
4
+ export type ValueType = ScalarType | SizedType;
5
+ export type Mode = "turns" | "thread" | "sidecar";
6
+ export declare const MODES: readonly Mode[];
7
+ export type Access = "read" | "readwrite";
8
+ export type Effect = "read" | "mutate";
9
+ export type Dispatch = "immediate" | "safepoint";
10
+ export type Policy = "auto" | "confirm" | "forbid";
11
+ export type Wakes = "always" | "never" | string;
12
+ /** Default `max` sizes of the sized types (grammar section 5, common rules). */
13
+ export declare const DEFAULT_STRING_MAX = 256;
14
+ export declare const DEFAULT_SIZED_MAX = 1024;
15
+ /** Payload bytes an event slot holds; a larger declared payload must be `large`. */
16
+ export declare const EVENT_SLOT_BYTES = 4096;
17
+ /** Bytes counted for a scalar field. */
18
+ export declare const SCALAR_BYTES = 8;
19
+ /**
20
+ * A schema field: a bare type name when the defaults suffice, or an object
21
+ * with `type` and `max` (and, beyond the grammar, `enum` values, an object's
22
+ * `fields`, a list's `items`, `nullable` and a `doc`).
23
+ */
24
+ export type FieldSchema = ValueType | {
25
+ type: ValueType;
26
+ max?: number;
27
+ enum?: string[];
28
+ fields?: Schema;
29
+ items?: FieldSchema;
30
+ nullable?: boolean;
31
+ doc?: string;
32
+ };
33
+ export type Schema = Record<string, FieldSchema>;
34
+ export interface CellDecl {
35
+ name: string;
36
+ type: ValueType;
37
+ access: Access;
38
+ doc: string;
39
+ /** Sized types only. */
40
+ max?: number;
41
+ /** `enum` cells. */
42
+ enum?: string[];
43
+ /** `int` and `float` cells. */
44
+ range?: [number, number];
45
+ /** Required for `readwrite`. */
46
+ default?: unknown;
47
+ /** Hint in milliseconds. */
48
+ cadence?: number;
49
+ /** `readwrite` only; knobs are never `forbid`. */
50
+ policy?: "auto" | "confirm";
51
+ /** Sized knobs only: delivery timeout. */
52
+ timeout?: string;
53
+ /** `object` cells: the fields. */
54
+ fields?: Schema;
55
+ /** `list` cells: the item schema. */
56
+ items?: FieldSchema;
57
+ /** Extension: the value may be null. */
58
+ nullable?: boolean;
59
+ }
60
+ export interface EventDecl {
61
+ name: string;
62
+ doc: string;
63
+ payload: Schema;
64
+ wakes?: Wakes;
65
+ large?: boolean;
66
+ }
67
+ export interface CapabilityDecl {
68
+ name: string;
69
+ doc: string;
70
+ params: Schema;
71
+ result: Schema;
72
+ effect: Effect;
73
+ dispatch: Dispatch;
74
+ timeout?: string;
75
+ policy: Policy;
76
+ example?: Record<string, unknown>;
77
+ /** Extension: the knob this capability sets; such calls are audited as knob writes. */
78
+ writes?: string;
79
+ }
80
+ export interface DecisionDecl {
81
+ name: string;
82
+ doc: string;
83
+ context: Schema;
84
+ /** Either `options` (an enum of choices) or `answer` (a schema). */
85
+ options?: string[];
86
+ answer?: Schema;
87
+ default: unknown;
88
+ timeout: string;
89
+ policy: Policy;
90
+ }
91
+ export interface TurnDecl {
92
+ name: string;
93
+ doc: string;
94
+ timeout: string;
95
+ }
96
+ export interface Manifest {
97
+ abaigrammar: string;
98
+ name: string;
99
+ entry: string;
100
+ modes: Mode[];
101
+ harness?: {
102
+ path: string | null;
103
+ };
104
+ model?: Record<string, unknown>;
105
+ check?: {
106
+ run: string;
107
+ overhead?: string;
108
+ };
109
+ content: {
110
+ identity: string;
111
+ install?: string;
112
+ use?: string;
113
+ turns?: string;
114
+ };
115
+ audit: {
116
+ path: string;
117
+ };
118
+ lifecycle?: {
119
+ pause: "cooperative" | "os" | "none";
120
+ stop?: {
121
+ graceful: string;
122
+ handler: string;
123
+ };
124
+ policy?: Partial<Record<"pause" | "resume" | "stop" | "restart", Policy>>;
125
+ };
126
+ attention?: {
127
+ budget?: {
128
+ wakes_per_minute?: number;
129
+ tokens_per_hour?: number;
130
+ };
131
+ };
132
+ policy?: {
133
+ confirm_timeout?: string;
134
+ };
135
+ /** Where this instantiation departs from the grammar, one sentence each (section 7); a program may add its own. */
136
+ deviations?: string[];
137
+ cells: CellDecl[];
138
+ events: EventDecl[];
139
+ capabilities: CapabilityDecl[];
140
+ decisions: DecisionDecl[];
141
+ turns: TurnDecl[];
142
+ }
143
+ /** Events the library (the stub) emits under the reserved `abai.` prefix. */
144
+ export declare const LIBRARY_EVENTS: readonly string[];
145
+ /** A valid abai name: lowercase segments joined by dots, words joined by underscores. */
146
+ export declare function isValidName(name: unknown): name is string;
147
+ export declare function isDuration(value: unknown): value is string;
148
+ /** A duration string in milliseconds. */
149
+ export declare function durationMs(value: string): number;
150
+ /** Normalize a field schema to its object form. */
151
+ export declare function fieldOf(field: FieldSchema): Exclude<FieldSchema, string>;
152
+ /** Bytes a field counts toward an event slot: scalars 8, sized fields their `max`. */
153
+ export declare function fieldBytes(field: FieldSchema): number;
154
+ /** Bytes a payload counts toward an event slot (grammar section 5.1). */
155
+ export declare function payloadBytes(schema: Schema): number;
156
+ /** Whether a value has a declared type. `int` accepts integers only; `float` any finite number. */
157
+ export declare function matchesType(value: unknown, field: FieldSchema): boolean;
158
+ /** Encoded size of a value in bytes, as the wire would carry it. */
159
+ export declare function encodedBytes(value: unknown): number;
160
+ /**
161
+ * Cut a string to at most `maxBytes` of UTF-8 without splitting a code
162
+ * point: one encode, a cut, a step back over continuation bytes, one decode.
163
+ */
164
+ export declare function cutUtf8(value: string, maxBytes: number): string;
165
+ /**
166
+ * Validate a manifest in either form. Returns the violations, each
167
+ * `<where>: <what>`; an empty list means the manifest validates.
168
+ */
169
+ export declare function validateManifest(value: unknown): string[];
170
+ /** Narrow an unknown value to a Manifest; throws with the violations otherwise. */
171
+ export declare function assertManifest(value: unknown): Manifest;
172
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/manifest/manifest.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAEzC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAC3D,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AACrD,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,SAAS,CAAC;AAE/C,MAAM,MAAM,IAAI,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAClD,eAAO,MAAM,KAAK,EAAE,SAAS,IAAI,EAAmC,CAAC;AAErE,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,WAAW,CAAC;AAC1C,MAAM,MAAM,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AACvC,MAAM,MAAM,QAAQ,GAAG,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 and 7).\n//\n// The manifest exists in two forms that must agree: in code (the program's\n// declarations, the source of truth at runtime) and in the repo\n// (abaigram.yaml, rendered by render.ts). The validator here checks either\n// form, so `<entry> doctor` and the self-check test apply the same rules.\n// Fields beyond the grammar (`deviations`, `writes`, `nullable`) are\n// extensions a partial realization needs; the manifest's `deviations` list\n// names them.\n\nexport const ABAIGRAMMAR_VERSION = \"0.1\";\n\nexport type ScalarType = \"bool\" | \"int\" | \"float\" | \"enum\";\nexport type SizedType = \"string\" | \"object\" | \"list\";\nexport type ValueType = ScalarType | SizedType;\n\nexport type Mode = \"turns\" | \"thread\" | \"sidecar\";\nexport const MODES: readonly Mode[] = [\"turns\", \"thread\", \"sidecar\"];\n\nexport type Access = \"read\" | \"readwrite\";\nexport type Effect = \"read\" | \"mutate\";\nexport type Dispatch = \"immediate\" | \"safepoint\";\nexport type Policy = \"auto\" | \"confirm\" | \"forbid\";\nexport type Wakes = \"always\" | \"never\" | string;\n\n/** Default `max` sizes of the sized types (grammar section 5, common rules). */\nexport const DEFAULT_STRING_MAX = 256;\nexport const DEFAULT_SIZED_MAX = 1024;\n/** Payload bytes an event slot holds; a larger declared payload must be `large`. */\nexport const EVENT_SLOT_BYTES = 4096;\n/** Bytes counted for a scalar field. */\nexport const SCALAR_BYTES = 8;\n\n/**\n * A schema field: a bare type name when the defaults suffice, or an object\n * with `type` and `max` (and, beyond the grammar, `enum` values, an object's\n * `fields`, a list's `items`, `nullable` and a `doc`).\n */\nexport type FieldSchema =\n\t| ValueType\n\t| {\n\t\t\ttype: ValueType;\n\t\t\tmax?: number;\n\t\t\tenum?: string[];\n\t\t\tfields?: Schema;\n\t\t\titems?: FieldSchema;\n\t\t\tnullable?: boolean;\n\t\t\tdoc?: string;\n\t };\n\nexport type Schema = Record<string, FieldSchema>;\n\nexport interface CellDecl {\n\tname: string;\n\ttype: ValueType;\n\taccess: Access;\n\tdoc: string;\n\t/** Sized types only. */\n\tmax?: number;\n\t/** `enum` cells. */\n\tenum?: string[];\n\t/** `int` and `float` cells. */\n\trange?: [number, number];\n\t/** Required for `readwrite`. */\n\tdefault?: unknown;\n\t/** Hint in milliseconds. */\n\tcadence?: number;\n\t/** `readwrite` only; knobs are never `forbid`. */\n\tpolicy?: \"auto\" | \"confirm\";\n\t/** Sized knobs only: delivery timeout. */\n\ttimeout?: string;\n\t/** `object` cells: the fields. */\n\tfields?: Schema;\n\t/** `list` cells: the item schema. */\n\titems?: FieldSchema;\n\t/** Extension: the value may be null. */\n\tnullable?: boolean;\n}\n\nexport interface EventDecl {\n\tname: string;\n\tdoc: string;\n\tpayload: Schema;\n\twakes?: Wakes;\n\tlarge?: boolean;\n}\n\nexport interface CapabilityDecl {\n\tname: string;\n\tdoc: string;\n\tparams: Schema;\n\tresult: Schema;\n\teffect: Effect;\n\tdispatch: Dispatch;\n\ttimeout?: string;\n\tpolicy: Policy;\n\texample?: Record<string, unknown>;\n\t/** Extension: the knob this capability sets; such calls are audited as knob writes. */\n\twrites?: string;\n}\n\nexport interface DecisionDecl {\n\tname: string;\n\tdoc: string;\n\tcontext: Schema;\n\t/** Either `options` (an enum of choices) or `answer` (a schema). */\n\toptions?: string[];\n\tanswer?: Schema;\n\tdefault: unknown;\n\ttimeout: string;\n\tpolicy: Policy;\n}\n\nexport interface TurnDecl {\n\tname: string;\n\tdoc: string;\n\ttimeout: string;\n}\n\nexport interface Manifest {\n\tabaigrammar: string;\n\tname: string;\n\tentry: string;\n\tmodes: Mode[];\n\tharness?: { path: string | null };\n\tmodel?: Record<string, unknown>;\n\tcheck?: { run: string; overhead?: string };\n\tcontent: { identity: string; install?: string; use?: string; turns?: string };\n\taudit: { path: string };\n\tlifecycle?: {\n\t\tpause: \"cooperative\" | \"os\" | \"none\";\n\t\tstop?: { graceful: string; handler: string };\n\t\tpolicy?: Partial<Record<\"pause\" | \"resume\" | \"stop\" | \"restart\", Policy>>;\n\t};\n\tattention?: { budget?: { wakes_per_minute?: number; tokens_per_hour?: number } };\n\tpolicy?: { confirm_timeout?: string };\n\t/** Where this instantiation departs from the grammar, one sentence each (section 7); a program may add its own. */\n\tdeviations?: string[];\n\tcells: CellDecl[];\n\tevents: EventDecl[];\n\tcapabilities: CapabilityDecl[];\n\tdecisions: DecisionDecl[];\n\tturns: TurnDecl[];\n}\n\n/** Events the library (the stub) emits under the reserved `abai.` prefix. */\nexport const LIBRARY_EVENTS: readonly string[] = [\n\t\"abai.events.dropped\",\n\t\"abai.knob.reset\",\n\t\"abai.lifecycle.exited\",\n\t\"abai.pause.blocked\",\n\t\"abai.io.stdout\",\n\t\"abai.io.stderr\",\n\t\"abai.audit.failed\",\n];\n\nconst NAME = /^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)*$/;\nconst DURATION = /^[0-9]+(ms|s|m|h)$/;\nconst VALUE_TYPES: readonly string[] = [\"bool\", \"int\", \"float\", \"enum\", \"string\", \"object\", \"list\"];\nconst SIZED_TYPES: readonly string[] = [\"string\", \"object\", \"list\"];\nconst POLICIES: readonly string[] = [\"auto\", \"confirm\", \"forbid\"];\n\n/** A valid abai name: lowercase segments joined by dots, words joined by underscores. */\nexport function isValidName(name: unknown): name is string {\n\treturn typeof name === \"string\" && NAME.test(name);\n}\n\nexport function isDuration(value: unknown): value is string {\n\treturn typeof value === \"string\" && DURATION.test(value);\n}\n\n/** A duration string in milliseconds. */\nexport function durationMs(value: string): number {\n\tconst match = /^([0-9]+)(ms|s|m|h)$/.exec(value);\n\tif (!match) throw new Error(`not a duration: ${value}`);\n\tconst n = Number(match[1]);\n\tswitch (match[2]) {\n\t\tcase \"ms\":\n\t\t\treturn n;\n\t\tcase \"s\":\n\t\t\treturn n * 1000;\n\t\tcase \"m\":\n\t\t\treturn n * 60_000;\n\t\tdefault:\n\t\t\treturn n * 3_600_000;\n\t}\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction isPositiveInt(value: unknown): value is number {\n\treturn typeof value === \"number\" && Number.isInteger(value) && value > 0;\n}\n\n/** Normalize a field schema to its object form. */\nexport function fieldOf(field: FieldSchema): Exclude<FieldSchema, string> {\n\treturn typeof field === \"string\" ? { type: field } : field;\n}\n\n/** Bytes a field counts toward an event slot: scalars 8, sized fields their `max`. */\nexport function fieldBytes(field: FieldSchema): number {\n\tconst f = fieldOf(field);\n\tif (f.type === \"string\") return f.max ?? DEFAULT_STRING_MAX;\n\tif (f.type === \"object\" || f.type === \"list\") return f.max ?? DEFAULT_SIZED_MAX;\n\treturn SCALAR_BYTES;\n}\n\n/** Bytes a payload counts toward an event slot (grammar section 5.1). */\nexport function payloadBytes(schema: Schema): number {\n\tlet total = 0;\n\tfor (const field of Object.values(schema)) total += fieldBytes(field);\n\treturn total;\n}\n\n/** Whether a value has a declared type. `int` accepts integers only; `float` any finite number. */\nexport function matchesType(value: unknown, field: FieldSchema): boolean {\n\tconst f = fieldOf(field);\n\tif (value === null) return f.nullable === true;\n\tswitch (f.type) {\n\t\tcase \"bool\":\n\t\t\treturn typeof value === \"boolean\";\n\t\tcase \"int\":\n\t\t\treturn typeof value === \"number\" && Number.isInteger(value);\n\t\tcase \"float\":\n\t\t\treturn typeof value === \"number\" && Number.isFinite(value);\n\t\tcase \"enum\":\n\t\t\treturn typeof value === \"string\" && (f.enum?.includes(value) ?? false);\n\t\tcase \"string\":\n\t\t\treturn typeof value === \"string\";\n\t\tcase \"object\":\n\t\t\tif (!isRecord(value)) return false;\n\t\t\tif (f.fields) {\n\t\t\t\tfor (const [key, sub] of Object.entries(f.fields)) {\n\t\t\t\t\tif (!matchesType(value[key], sub)) return false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\tcase \"list\":\n\t\t\tif (!Array.isArray(value)) return false;\n\t\t\tif (f.items) {\n\t\t\t\tconst items = f.items;\n\t\t\t\treturn value.every((item) => matchesType(item, items));\n\t\t\t}\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/** Encoded size of a value in bytes, as the wire would carry it. */\nexport function encodedBytes(value: unknown): number {\n\treturn Buffer.byteLength(typeof value === \"string\" ? value : JSON.stringify(value), \"utf8\");\n}\n\n/**\n * Cut a string to at most `maxBytes` of UTF-8 without splitting a code\n * point: one encode, a cut, a step back over continuation bytes, one decode.\n */\nexport function cutUtf8(value: string, maxBytes: number): string {\n\tconst bytes = Buffer.from(value, \"utf8\");\n\tif (bytes.length <= maxBytes) return value;\n\tlet end = Math.max(0, maxBytes);\n\twhile (end > 0 && (bytes[end] & 0xc0) === 0x80) end -= 1;\n\treturn bytes.toString(\"utf8\", 0, end);\n}\n\n// ---------------------------------------------------------------------------\n// Validation\n// ---------------------------------------------------------------------------\n\nclass Violations {\n\treadonly list: string[] = [];\n\tadd(where: string, what: string): void {\n\t\tthis.list.push(`${where}: ${what}`);\n\t}\n}\n\nfunction validateSchema(v: Violations, where: string, schema: unknown): void {\n\tif (!isRecord(schema)) {\n\t\tv.add(where, \"must be an object of fields\");\n\t\treturn;\n\t}\n\tfor (const [key, field] of Object.entries(schema)) {\n\t\tconst at = `${where}.${key}`;\n\t\tif (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) v.add(at, \"field names are identifiers\");\n\t\tif (typeof field === \"string\") {\n\t\t\tif (!VALUE_TYPES.includes(field)) v.add(at, `unknown type ${JSON.stringify(field)}`);\n\t\t\telse if (field === \"enum\") v.add(at, \"an enum field needs its values (use the object form)\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (!isRecord(field) || typeof field.type !== \"string\" || !VALUE_TYPES.includes(field.type)) {\n\t\t\tv.add(at, \"must be a type name or an object with a valid type\");\n\t\t\tcontinue;\n\t\t}\n\t\tif (field.max !== undefined) {\n\t\t\tif (!isPositiveInt(field.max)) v.add(at, \"max must be a positive integer\");\n\t\t\tif (!SIZED_TYPES.includes(field.type)) v.add(at, \"max applies to sized types only\");\n\t\t}\n\t\tif (field.type === \"enum\") {\n\t\t\tif (!Array.isArray(field.enum) || field.enum.length === 0 || !field.enum.every((e) => typeof e === \"string\")) {\n\t\t\t\tv.add(at, \"enum fields need a non-empty list of string values\");\n\t\t\t}\n\t\t} else if (field.enum !== undefined) v.add(at, \"enum values belong to enum fields only\");\n\t\tif (field.fields !== undefined) {\n\t\t\tif (field.type !== \"object\") v.add(at, \"fields belong to object fields only\");\n\t\t\telse validateSchema(v, at, field.fields);\n\t\t}\n\t\tif (field.items !== undefined) {\n\t\t\tif (field.type !== \"list\") v.add(at, \"items belong to list fields only\");\n\t\t\telse validateSchema(v, at, { item: field.items });\n\t\t}\n\t\tif (field.nullable !== undefined && typeof field.nullable !== \"boolean\") v.add(at, \"nullable must be a boolean\");\n\t\tif (field.doc !== undefined && typeof field.doc !== \"string\") v.add(at, \"doc must be a string\");\n\t}\n}\n\nfunction validateNamed(v: Violations, where: string, items: unknown, seen: Set<string>): Record<string, unknown>[] {\n\tif (!Array.isArray(items)) {\n\t\tv.add(where, \"must be a list\");\n\t\treturn [];\n\t}\n\tconst valid: Record<string, unknown>[] = [];\n\titems.forEach((item, index) => {\n\t\tconst at = `${where}[${index}]`;\n\t\tif (!isRecord(item)) {\n\t\t\tv.add(at, \"must be an object\");\n\t\t\treturn;\n\t\t}\n\t\tif (!isValidName(item.name)) {\n\t\t\tv.add(at, `invalid name ${JSON.stringify(item.name)}`);\n\t\t\treturn;\n\t\t}\n\t\tif (seen.has(item.name)) v.add(`${where}.${item.name}`, \"duplicate name\");\n\t\tseen.add(item.name);\n\t\tif (item.name.startsWith(\"abai.\") && !(where === \"events\" && LIBRARY_EVENTS.includes(item.name))) {\n\t\t\tv.add(`${where}.${item.name}`, \"the abai. prefix is reserved for the library\");\n\t\t}\n\t\tif (typeof item.doc !== \"string\" || item.doc.trim() === \"\") v.add(`${where}.${item.name}`, \"doc is required\");\n\t\tvalid.push(item);\n\t});\n\treturn valid;\n}\n\nfunction validateCell(v: Violations, cell: Record<string, unknown>): void {\n\tconst at = `cells.${cell.name}`;\n\tconst type = cell.type;\n\tif (typeof type !== \"string\" || !VALUE_TYPES.includes(type)) {\n\t\tv.add(at, `unknown type ${JSON.stringify(type)}`);\n\t\treturn;\n\t}\n\tif (cell.access !== \"read\" && cell.access !== \"readwrite\") v.add(at, \"access must be read or readwrite\");\n\tif (cell.max !== undefined) {\n\t\tif (!isPositiveInt(cell.max)) v.add(at, \"max must be a positive integer\");\n\t\tif (!SIZED_TYPES.includes(type)) v.add(at, \"max applies to sized types only\");\n\t}\n\tif (type === \"enum\") {\n\t\tif (!Array.isArray(cell.enum) || cell.enum.length === 0 || !cell.enum.every((e) => typeof e === \"string\")) {\n\t\t\tv.add(at, \"enum cells need a non-empty list of string values\");\n\t\t}\n\t} else if (cell.enum !== undefined) v.add(at, \"enum values belong to enum cells only\");\n\tif (cell.range !== undefined) {\n\t\tconst range = cell.range;\n\t\tif (\n\t\t\t!Array.isArray(range) ||\n\t\t\trange.length !== 2 ||\n\t\t\ttypeof range[0] !== \"number\" ||\n\t\t\ttypeof range[1] !== \"number\" ||\n\t\t\trange[0] > range[1]\n\t\t) {\n\t\t\tv.add(at, \"range must be [min, max]\");\n\t\t}\n\t\tif (type !== \"int\" && type !== \"float\") v.add(at, \"range applies to int and float cells only\");\n\t}\n\tif (cell.cadence !== undefined && !isPositiveInt(cell.cadence)) v.add(at, \"cadence must be a positive integer\");\n\tif (cell.fields !== undefined) {\n\t\tif (type !== \"object\") v.add(at, \"fields belong to object cells only\");\n\t\telse validateSchema(v, at, cell.fields);\n\t}\n\tif (cell.items !== undefined) {\n\t\tif (type !== \"list\") v.add(at, \"items belong to list cells only\");\n\t\telse validateSchema(v, at, { item: cell.items });\n\t}\n\tif (cell.nullable !== undefined && typeof cell.nullable !== \"boolean\") v.add(at, \"nullable must be a boolean\");\n\tif (cell.access === \"readwrite\") {\n\t\tif (cell.default === undefined) v.add(at, \"a readwrite cell needs a default\");\n\t\telse if (!matchesType(cell.default, cell as unknown as FieldSchema))\n\t\t\tv.add(at, \"default is not of the cell's type\");\n\t\tif (cell.policy !== undefined && cell.policy !== \"auto\" && cell.policy !== \"confirm\") {\n\t\t\tv.add(at, \"a knob's policy is auto or confirm\");\n\t\t}\n\t\tif (cell.timeout !== undefined) {\n\t\t\tif (!isDuration(cell.timeout)) v.add(at, \"timeout must be a duration such as 30s\");\n\t\t\tif (!SIZED_TYPES.includes(type)) v.add(at, \"a delivery timeout applies to sized knobs only\");\n\t\t}\n\t} else {\n\t\tif (cell.policy !== undefined) v.add(at, \"policy applies to readwrite cells only\");\n\t\tif (cell.timeout !== undefined) v.add(at, \"timeout applies to readwrite cells only\");\n\t\tif (cell.default !== undefined) v.add(at, \"default applies to readwrite cells only\");\n\t}\n}\n\nfunction validateEvent(v: Violations, event: Record<string, unknown>): void {\n\tconst at = `events.${event.name}`;\n\tvalidateSchema(v, `${at}.payload`, event.payload);\n\tif (event.wakes !== undefined && (typeof event.wakes !== \"string\" || event.wakes.trim() === \"\")) {\n\t\tv.add(at, \"wakes must be always, never or a condition\");\n\t}\n\tif (event.large !== undefined && typeof event.large !== \"boolean\") v.add(at, \"large must be a boolean\");\n\tif (isRecord(event.payload)) {\n\t\tconst bytes = payloadBytes(event.payload as Schema);\n\t\tif (bytes > EVENT_SLOT_BYTES && event.large !== true) {\n\t\t\tv.add(at, `payload counts ${bytes} bytes, over ${EVENT_SLOT_BYTES}: declare large: true`);\n\t\t}\n\t}\n}\n\nfunction validateCapability(v: Violations, cap: Record<string, unknown>, knobs: ReadonlySet<string>): void {\n\tconst at = `capabilities.${cap.name}`;\n\tvalidateSchema(v, `${at}.params`, cap.params);\n\tvalidateSchema(v, `${at}.result`, cap.result);\n\tif (cap.effect !== \"read\" && cap.effect !== \"mutate\") v.add(at, \"effect must be read or mutate\");\n\tif (cap.dispatch !== \"immediate\" && cap.dispatch !== \"safepoint\") v.add(at, \"dispatch must be declared\");\n\tif (typeof cap.policy !== \"string\" || !POLICIES.includes(cap.policy)) v.add(at, \"policy must be declared\");\n\tif (cap.timeout !== undefined && !isDuration(cap.timeout)) v.add(at, \"timeout must be a duration such as 30s\");\n\tif (cap.example !== undefined) {\n\t\tif (!isRecord(cap.example)) v.add(at, \"example must be an object of parameters\");\n\t\telse if (isRecord(cap.params)) {\n\t\t\tfor (const key of Object.keys(cap.example)) {\n\t\t\t\tif (!(key in cap.params)) v.add(at, `example has an undeclared parameter ${key}`);\n\t\t\t}\n\t\t}\n\t}\n\tif (cap.writes !== undefined) {\n\t\tif (!isValidName(cap.writes)) v.add(at, \"writes must name a cell\");\n\t\telse if (!knobs.has(cap.writes)) v.add(at, `writes names ${cap.writes}, which is not a readwrite cell`);\n\t}\n}\n\nfunction validateDecision(v: Violations, decision: Record<string, unknown>): void {\n\tconst at = `decisions.${decision.name}`;\n\tvalidateSchema(v, `${at}.context`, decision.context);\n\tconst hasOptions = decision.options !== undefined;\n\tconst hasAnswer = decision.answer !== undefined;\n\tif (hasOptions === hasAnswer) v.add(at, \"declare either options or answer\");\n\tif (hasOptions) {\n\t\tconst options = decision.options;\n\t\tif (!Array.isArray(options) || options.length === 0 || !options.every((o) => typeof o === \"string\")) {\n\t\t\tv.add(at, \"options must be a non-empty list of strings\");\n\t\t} else if (decision.default !== \"abort\" && !options.includes(decision.default as string)) {\n\t\t\tv.add(at, \"default must be one of the options or abort\");\n\t\t}\n\t}\n\tif (hasAnswer) validateSchema(v, `${at}.answer`, decision.answer);\n\tif (decision.default === undefined) v.add(at, \"default is required\");\n\tif (!isDuration(decision.timeout)) v.add(at, \"timeout is required (a duration such as 30s)\");\n\tif (typeof decision.policy !== \"string\" || !POLICIES.includes(decision.policy)) v.add(at, \"policy must be declared\");\n}\n\nfunction validateTurn(v: Violations, turn: Record<string, unknown>): void {\n\tif (!isDuration(turn.timeout)) v.add(`turns.${turn.name}`, \"timeout is required (a duration such as 30s)\");\n}\n\n/**\n * Validate a manifest in either form. Returns the violations, each\n * `<where>: <what>`; an empty list means the manifest validates.\n */\nexport function validateManifest(value: unknown): string[] {\n\tconst v = new Violations();\n\tif (!isRecord(value)) return [\"manifest: must be an object\"];\n\tif (value.abaigrammar !== ABAIGRAMMAR_VERSION) {\n\t\tv.add(\"abaigrammar\", `must be ${JSON.stringify(ABAIGRAMMAR_VERSION)}`);\n\t}\n\tif (typeof value.name !== \"string\" || value.name.trim() === \"\") v.add(\"name\", \"is required\");\n\tif (typeof value.entry !== \"string\" || value.entry.trim() === \"\") v.add(\"entry\", \"is required\");\n\tconst modes = value.modes;\n\tif (!Array.isArray(modes) || modes.length === 0) v.add(\"modes\", \"must list at least one mode\");\n\telse {\n\t\tmodes.forEach((mode, index) => {\n\t\t\tif (!(MODES as readonly unknown[]).includes(mode))\n\t\t\t\tv.add(`modes[${index}]`, `unknown mode ${JSON.stringify(mode)}`);\n\t\t});\n\t\tif (new Set(modes).size !== modes.length) v.add(\"modes\", \"must not repeat a mode\");\n\t}\n\tif (!isRecord(value.content) || typeof value.content.identity !== \"string\" || value.content.identity === \"\") {\n\t\tv.add(\"content.identity\", \"is required\");\n\t}\n\tif (!isRecord(value.audit) || typeof value.audit.path !== \"string\" || value.audit.path === \"\") {\n\t\tv.add(\"audit.path\", \"is required\");\n\t}\n\tif (value.lifecycle !== undefined) {\n\t\tconst lifecycle = value.lifecycle;\n\t\tif (!isRecord(lifecycle) || ![\"cooperative\", \"os\", \"none\"].includes(lifecycle.pause as string)) {\n\t\t\tv.add(\"lifecycle.pause\", \"must be cooperative, os or none\");\n\t\t}\n\t}\n\tif (value.deviations !== undefined) {\n\t\tconst deviations = value.deviations;\n\t\tif (!Array.isArray(deviations) || !deviations.every((d) => typeof d === \"string\" && d.trim() !== \"\")) {\n\t\t\tv.add(\"deviations\", \"must be a list of non-empty strings\");\n\t\t}\n\t}\n\tif (value.check !== undefined && (!isRecord(value.check) || typeof value.check.run !== \"string\")) {\n\t\tv.add(\"check.run\", \"is required when check is declared\");\n\t}\n\n\tconst cells = validateNamed(v, \"cells\", value.cells, new Set());\n\tfor (const cell of cells) validateCell(v, cell);\n\tconst knobs = new Set(cells.filter((cell) => cell.access === \"readwrite\").map((cell) => cell.name as string));\n\tfor (const event of validateNamed(v, \"events\", value.events, new Set())) validateEvent(v, event);\n\tfor (const cap of validateNamed(v, \"capabilities\", value.capabilities, new Set())) {\n\t\tvalidateCapability(v, cap, knobs);\n\t}\n\tfor (const decision of validateNamed(v, \"decisions\", value.decisions, new Set())) validateDecision(v, decision);\n\tfor (const turn of validateNamed(v, \"turns\", value.turns, new Set())) validateTurn(v, turn);\n\treturn v.list;\n}\n\n/** Narrow an unknown value to a Manifest; throws with the violations otherwise. */\nexport function assertManifest(value: unknown): Manifest {\n\tconst violations = validateManifest(value);\n\tif (violations.length > 0) throw new Error(`manifest does not validate:\\n${violations.join(\"\\n\")}`);\n\treturn value as Manifest;\n}\n"]}