@tangle-network/agent-runtime 5.0.0 → 6.0.2

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 (83) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/{activation-DGLWxFJu.js → activation-BRfZOfwb.js} +4 -4
  3. package/dist/{activation-DGLWxFJu.js.map → activation-BRfZOfwb.js.map} +1 -1
  4. package/dist/{activation-CtLdCiH3.d.ts → activation-DEKw9CDD.d.ts} +2 -2
  5. package/dist/agent.d.ts +1 -1
  6. package/dist/agent.js +3 -3
  7. package/dist/{bundle-CV4Ts0cS.js → bundle-vFFiCigS.js} +2 -2
  8. package/dist/{bundle-CV4Ts0cS.js.map → bundle-vFFiCigS.js.map} +1 -1
  9. package/dist/candidate-execution/index.d.ts +70 -3
  10. package/dist/candidate-execution/index.js +4 -4
  11. package/dist/{coordination-manager-D74AZg7m.js → coordination-manager-RSJg5GmY.js} +10 -9
  12. package/dist/coordination-manager-RSJg5GmY.js.map +1 -0
  13. package/dist/coordination-map-routing-DVjW5Gx0.js.map +1 -1
  14. package/dist/{delegate-BVyFJ9AX.js → delegate-C0cprMUN.js} +2 -2
  15. package/dist/{delegate-BVyFJ9AX.js.map → delegate-C0cprMUN.js.map} +1 -1
  16. package/dist/durable.d.ts +2 -2
  17. package/dist/durable.js +9 -9
  18. package/dist/{graph-r8zcRxbi.js → graph-cEg-gquv.js} +5 -5
  19. package/dist/{graph-r8zcRxbi.js.map → graph-cEg-gquv.js.map} +1 -1
  20. package/dist/{improve-D12GulmK.js → improve-DNl4_6lP.js} +7 -7
  21. package/dist/{improve-D12GulmK.js.map → improve-DNl4_6lP.js.map} +1 -1
  22. package/dist/index.d.ts +6 -6
  23. package/dist/index.js +10 -10
  24. package/dist/intelligence.d.ts +4 -4
  25. package/dist/intelligence.js +7 -7
  26. package/dist/kernel.d.ts +3 -3
  27. package/dist/kernel.js +12 -12
  28. package/dist/{loop-runner-BHBabRIw.d.ts → loop-runner-CDad0CCY.d.ts} +2 -2
  29. package/dist/{loop-runner-CYcN11I4.js → loop-runner-DQJjowz0.js} +2 -2
  30. package/dist/{loop-runner-CYcN11I4.js.map → loop-runner-DQJjowz0.js.map} +1 -1
  31. package/dist/loop-runner-bin.d.ts +1 -1
  32. package/dist/loop-runner-bin.js +1 -1
  33. package/dist/mcp/bin.js +3 -3
  34. package/dist/mcp/index.d.ts +1 -1
  35. package/dist/mcp/index.js +6 -6
  36. package/dist/{prepare-DutbxpWr.js → prepare-B6SQA12v.js} +3 -3
  37. package/dist/{prepare-DutbxpWr.js.map → prepare-B6SQA12v.js.map} +1 -1
  38. package/dist/{profile-ClvuI8aY.js → profile-DN8Dw2Kp.js} +2 -2
  39. package/dist/{profile-ClvuI8aY.js.map → profile-DN8Dw2Kp.js.map} +1 -1
  40. package/dist/profiles.d.ts +1 -1
  41. package/dist/{protected-model-port-DEsNIYi1.d.ts → protected-model-port-uN4M48vT.d.ts} +2 -2
  42. package/dist/{provision-supervisor-BiqHJ-d4.js → provision-supervisor-CtAaJCUa.js} +5 -5
  43. package/dist/{provision-supervisor-BiqHJ-d4.js.map → provision-supervisor-CtAaJCUa.js.map} +1 -1
  44. package/dist/{run-cancellation-D5R-7UQt.js → run-cancellation-BCuu6khW.js} +2 -2
  45. package/dist/{run-cancellation-D5R-7UQt.js.map → run-cancellation-BCuu6khW.js.map} +1 -1
  46. package/dist/{run-state-DRh8BOFi.js → run-state-ByHiAjUs.js} +6 -5
  47. package/dist/{run-state-DRh8BOFi.js.map → run-state-ByHiAjUs.js.map} +1 -1
  48. package/dist/{runtime-BX_9-DJB.js → runtime-9EYvBcHG.js} +13 -13
  49. package/dist/{runtime-BX_9-DJB.js.map → runtime-9EYvBcHG.js.map} +1 -1
  50. package/dist/runtime-hooks-CsW2pfFk.js.map +1 -1
  51. package/dist/{runtime-hooks-ZQqPw-0g.d.ts → runtime-hooks-DPghSHV7.d.ts} +11 -16
  52. package/dist/{scope-JcCkUy_z.js → scope-DzhBJrRN.js} +3510 -3451
  53. package/dist/scope-DzhBJrRN.js.map +1 -0
  54. package/dist/{search-executor-CdmaS5r4.js → search-executor-BJRNavck.js} +4 -4
  55. package/dist/{search-executor-CdmaS5r4.js.map → search-executor-BJRNavck.js.map} +1 -1
  56. package/dist/{server-BY6OluUf.js → server-DH0P6OY_.js} +4 -4
  57. package/dist/{server-BY6OluUf.js.map → server-DH0P6OY_.js.map} +1 -1
  58. package/dist/{structural-rollout-BjMUUXLn.js → structural-rollout-DgvJLTO0.js} +4 -4
  59. package/dist/{structural-rollout-BjMUUXLn.js.map → structural-rollout-DgvJLTO0.js.map} +1 -1
  60. package/dist/{supervise-rYEsVVcn.js → supervise-Cqhkb2Oj.js} +244 -80
  61. package/dist/supervise-Cqhkb2Oj.js.map +1 -0
  62. package/dist/{supervision-discovery-D95Ack4J.js → supervision-discovery-DI5GIFBJ.js} +3 -3
  63. package/dist/{supervision-discovery-D95Ack4J.js.map → supervision-discovery-DI5GIFBJ.js.map} +1 -1
  64. package/dist/{supervisor-B-bX69uL.js → supervisor-B6sl14OR.js} +243 -962
  65. package/dist/supervisor-B6sl14OR.js.map +1 -0
  66. package/dist/testing.d.ts +1 -1
  67. package/dist/testing.js +13 -13
  68. package/dist/tool-loop.d.ts +1 -1
  69. package/dist/{top-web-D-wH9ipn.js → top-web-DGoXGxH8.js} +4 -4
  70. package/dist/{top-web-D-wH9ipn.js.map → top-web-DGoXGxH8.js.map} +1 -1
  71. package/dist/tui/bin.js +3 -3
  72. package/dist/tui/index.d.ts +2 -2
  73. package/dist/tui/index.js +2 -2
  74. package/dist/{types-DblV14Oe.d.ts → types-niKnm6ux.d.ts} +86 -242
  75. package/dist/{workspace-streams-DbKiDOWA.d.ts → workspace-archive-DS9E9tUr.d.ts} +2 -69
  76. package/dist/{workspace-streams-8ALHaZzx.js → workspace-streams-BqNM06y4.js} +34 -9
  77. package/dist/workspace-streams-BqNM06y4.js.map +1 -0
  78. package/package.json +5 -5
  79. package/dist/coordination-manager-D74AZg7m.js.map +0 -1
  80. package/dist/scope-JcCkUy_z.js.map +0 -1
  81. package/dist/supervise-rYEsVVcn.js.map +0 -1
  82. package/dist/supervisor-B-bX69uL.js.map +0 -1
  83. package/dist/workspace-streams-8ALHaZzx.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-hooks-CsW2pfFk.js","names":[],"sources":["../src/runtime-hooks.ts"],"sourcesContent":["/**\n *\n * Runtime hook contracts. Hooks are execution-scoped observers, not part of an\n * `AgentProfile`: profiles stay portable agent recipes; hooks attach to the\n * loop or product harness that is running the profile.\n *\n * A `pursuitId` is deliberately orthogonal to `runId`: a pursuit can span many\n * resumed/retried/forked runs while every event remains attributable to the\n * durable objective that caused it. The observer plane is outside the agent\n * environment and must never be required for agent correctness.\n *\n * @experimental\n */\n\nexport type RuntimeHookPhase = 'before' | 'after' | 'error' | 'event'\n\nexport type RuntimeHookTarget =\n | 'agent.run'\n | 'agent.turn'\n | 'agent.tool_call'\n | 'agent.spawn'\n | 'agent.child'\n | 'agent.plan'\n | 'agent.decision'\n | (string & {})\n\nexport type RuntimeDecisionKind =\n | 'continue'\n | 'verify'\n | 'ask'\n | 'retry'\n | 'stop'\n | 'memory-write'\n | 'memory-read'\n | 'tool-select'\n | 'skill-select'\n | 'workflow-select'\n | 'surface-promote'\n | (string & {})\n\nexport interface RuntimeHookEvent<Payload = unknown> {\n id: string\n /** Stable identity for the long-lived objective. One pursuit may contain many runs. */\n pursuitId?: string\n runId: string\n scenarioId?: string\n target: RuntimeHookTarget\n phase: RuntimeHookPhase\n timestamp: number\n stepIndex?: number\n parentId?: string\n payload?: Payload\n metadata?: Record<string, unknown>\n}\n\nexport interface RuntimeHookContext {\n signal?: AbortSignal\n}\n\nexport interface RuntimeDecisionEvidenceRef {\n source: string\n id: string\n detail?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface RuntimeDecisionPoint {\n id: string\n /** Stable identity for the long-lived objective. One pursuit may contain many runs. */\n pursuitId?: string\n runId: string\n scenarioId?: string\n stepIndex: number\n kind: RuntimeDecisionKind\n candidateActions: string[]\n context?: string\n evidence: RuntimeDecisionEvidenceRef[]\n metadata?: Record<string, unknown>\n}\n\nexport interface RuntimeHookErrorContext {\n hook: 'onEvent' | 'onDecisionPoint'\n eventId?: string\n target?: RuntimeHookTarget\n phase?: RuntimeHookPhase\n decisionId?: string\n decisionKind?: RuntimeDecisionKind\n}\n\n/**\n * The observation seam attached to a running loop (never to the portable genome).\n * Implement the optional hooks to receive lifecycle events, semantic decision points,\n * and hook errors. Author with {@link defineRuntimeHooks} for inference, and attach N\n * observers at once with {@link composeRuntimeHooks} — there is ONE event stream, not a\n * callback-prop zoo.\n */\nexport interface RuntimeHooks {\n /**\n * General before/after/event hook. Use this for telemetry, memory capture,\n * policy wrapping, child lifecycle observers, or product-specific extension\n * points.\n */\n onEvent?: (event: RuntimeHookEvent, context: RuntimeHookContext) => void | Promise<void>\n /**\n * Semantic decision hook. Belief-state evaluation consumes this, but runtime\n * code should keep emitting ordinary lifecycle events as the base layer.\n */\n onDecisionPoint?: (\n point: RuntimeDecisionPoint,\n context: RuntimeHookContext,\n ) => void | Promise<void>\n onHookError?: (error: Error, context: RuntimeHookErrorContext) => void | Promise<void>\n}\n\n/** Identity helper that types a {@link RuntimeHooks} literal so the fields are inferred. */\nexport function defineRuntimeHooks(hooks: RuntimeHooks): RuntimeHooks {\n return hooks\n}\n\n/**\n * Attach a stable pursuit identity to the entire observer stream without changing\n * agent code or teaching individual runtimes about pursuits. Because recursive Scope\n * execution already inherits one RuntimeHooks instance, this wrapper automatically\n * covers descendants, nested drivers, and resumed execution that reuses the wrapper.\n *\n * Existing matching pursuit ids are preserved. A conflicting id fails closed: silently\n * rewriting attribution would make the meta-observer untrustworthy.\n */\nexport function withPursuitContext(pursuitId: string, hooks: RuntimeHooks): RuntimeHooks {\n const stableId = pursuitId.trim()\n if (stableId.length === 0) throw new TypeError('withPursuitContext: pursuitId must be non-empty')\n\n const assertAndStamp = <T extends RuntimeHookEvent | RuntimeDecisionPoint>(value: T): T => {\n if (value.pursuitId !== undefined && value.pursuitId !== stableId) {\n throw new Error(\n `withPursuitContext: observer identity conflict (${value.pursuitId} !== ${stableId})`,\n )\n }\n if (value.pursuitId === stableId) return value\n return { ...value, pursuitId: stableId }\n }\n\n return {\n onEvent: hooks.onEvent\n ? (event, context) => hooks.onEvent?.(assertAndStamp(event), context)\n : undefined,\n onDecisionPoint: hooks.onDecisionPoint\n ? (point, context) => hooks.onDecisionPoint?.(assertAndStamp(point), context)\n : undefined,\n onHookError: hooks.onHookError,\n }\n}\n\n/**\n * Merge several {@link RuntimeHooks} into one. Falsy entries are dropped (so you can\n * pass `flag && hooks`), and every observer's `onEvent`/`onDecisionPoint` fires for each\n * event. Use this to attach N observers to a loop instead of a second event bus.\n */\nexport function composeRuntimeHooks(\n ...entries: Array<RuntimeHooks | undefined | null | false>\n): RuntimeHooks {\n const hooks = entries.filter((entry): entry is RuntimeHooks => !!entry)\n return {\n onEvent: hooks.some((hook) => hook.onEvent)\n ? (event, context) => {\n const pending: Promise<unknown>[] = []\n for (const hook of hooks) {\n const result = hook.onEvent?.(event, context)\n if (isThenable(result)) pending.push(Promise.resolve(result))\n }\n if (pending.length > 0) return Promise.all(pending).then(() => undefined)\n return undefined\n }\n : undefined,\n onDecisionPoint: hooks.some((hook) => hook.onDecisionPoint)\n ? (point, context) => {\n const pending: Promise<unknown>[] = []\n for (const hook of hooks) {\n const result = hook.onDecisionPoint?.(point, context)\n if (isThenable(result)) pending.push(Promise.resolve(result))\n }\n if (pending.length > 0) return Promise.all(pending).then(() => undefined)\n return undefined\n }\n : undefined,\n onHookError: hooks.some((hook) => hook.onHookError)\n ? (error, context) => {\n const pending: Promise<unknown>[] = []\n for (const hook of hooks) {\n const result = hook.onHookError?.(error, context)\n if (isThenable(result)) pending.push(Promise.resolve(result))\n }\n if (pending.length > 0) return Promise.all(pending).then(() => undefined)\n return undefined\n }\n : undefined,\n }\n}\n\n/** Fire `hooks.onEvent`, swallowing sync throws and surfacing async failures to `onError`. */\nexport function notifyRuntimeHookEvent(\n hooks: RuntimeHooks | undefined,\n event: RuntimeHookEvent,\n context: RuntimeHookContext = {},\n): void {\n const onEvent = hooks?.onEvent\n if (!onEvent) return\n\n try {\n const result = onEvent(event, context)\n if (isThenable(result)) {\n void result.catch((error) => {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onEvent',\n eventId: event.id,\n target: event.target,\n phase: event.phase,\n })\n })\n }\n } catch (error) {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onEvent',\n eventId: event.id,\n target: event.target,\n phase: event.phase,\n })\n }\n}\n\n/** Fire `hooks.onDecisionPoint`, swallowing sync throws and surfacing async failures to `onError`. */\nexport function notifyRuntimeDecisionPoint(\n hooks: RuntimeHooks | undefined,\n point: RuntimeDecisionPoint,\n context: RuntimeHookContext = {},\n): void {\n const onDecisionPoint = hooks?.onDecisionPoint\n if (!onDecisionPoint) return\n\n try {\n const result = onDecisionPoint(point, context)\n if (isThenable(result)) {\n void result.catch((error) => {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onDecisionPoint',\n decisionId: point.id,\n decisionKind: point.kind,\n })\n })\n }\n } catch (error) {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onDecisionPoint',\n decisionId: point.id,\n decisionKind: point.kind,\n })\n }\n}\n\nfunction notifyRuntimeHookError(\n hooks: RuntimeHooks | undefined,\n error: Error,\n context: RuntimeHookErrorContext,\n): void {\n try {\n const result = hooks?.onHookError?.(error, context)\n if (isThenable(result)) void result.catch(() => undefined)\n } catch {\n // Hook errors must never become agent-loop errors.\n }\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof (value as { then?: unknown }).then === 'function'\n )\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error))\n}\n"],"mappings":";;AAmHA,SAAgB,mB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AAY,MAAM;IAClB,cAAc,MAAM;GACtB,CAAC;EACH,CAAC;CAEL,SAAS,OAAO;EACd,uBAAuB,OAAO,QAAQ,KAAK,GAAG;GAC5C,MAAM;GACN,YAAY,MAAM;GAClB,cAAc,MAAM;EACtB,CAAC;CACH;AACF;AAEA,SAAS,uBACP,OACA,OACA,SACM;CACN,IAAI;EACF,MAAM,SAAS,OAAO,cAAc,OAAO,OAAO;EAClD,IAAI,WAAW,MAAM,GAAG,OAAY,YAAY,KAAA,CAAS;CAC3D,QAAQ,CAER;AACF;AAEA,SAAS,WAAW,OAA+C;CACjE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,OAAQ,MAA6B,SAAS;AAElD;AAEA,SAAS,QAAQ,OAAuB;CACtC,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE"}
1
+ {"version":3,"file":"runtime-hooks-CsW2pfFk.js","names":[],"sources":["../src/runtime-hooks.ts"],"sourcesContent":["/**\n *\n * Runtime hook contracts. Hooks are execution-scoped observers, not part of an\n * `AgentProfile`: profiles stay portable agent recipes; hooks attach to the\n * loop or product harness that is running the profile.\n *\n * A `pursuitId` is deliberately orthogonal to `runId`: a pursuit can span many\n * resumed/retried/forked runs while every event remains attributable to the\n * durable objective that caused it. The observer plane is outside the agent\n * environment and must never be required for agent correctness.\n *\n * @experimental\n */\n\nimport type { AgentExactRunControlRef } from '@tangle-network/agent-interface'\n\nexport type RuntimeHookPhase = 'before' | 'after' | 'error' | 'event'\n\nexport type RuntimeHookTarget =\n | 'agent.run'\n | 'agent.turn'\n | 'agent.tool_call'\n | 'agent.spawn'\n | 'agent.child'\n | 'agent.plan'\n | 'agent.decision'\n | 'agent.execution'\n | 'agent.model'\n | 'agent.steer'\n | (string & {})\n\nexport type RuntimeDecisionKind =\n | 'continue'\n | 'verify'\n | 'ask'\n | 'retry'\n | 'stop'\n | 'memory-write'\n | 'memory-read'\n | 'tool-select'\n | 'skill-select'\n | 'workflow-select'\n | 'surface-promote'\n | (string & {})\n\nexport interface RuntimeHookEvent<Payload = unknown> {\n id: string\n /** Stable identity for the long-lived objective. One pursuit may contain many runs. */\n pursuitId?: string\n runId: string\n scenarioId?: string\n target: RuntimeHookTarget\n phase: RuntimeHookPhase\n timestamp: number\n stepIndex?: number\n parentId?: string\n payload?: Payload\n metadata?: Record<string, unknown>\n}\n\nexport interface RuntimeHookContext {\n signal?: AbortSignal\n}\n\n/** A provider acknowledged this exact execution; planned and refused dispatches emit none. */\nexport interface RuntimeExecutionAdmittedPayload {\n readonly attemptId?: string\n readonly nodeId: string\n readonly controlRef: AgentExactRunControlRef\n readonly sessionId: string\n}\n\nexport interface RuntimeDecisionEvidenceRef {\n source: string\n id: string\n detail?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface RuntimeDecisionPoint {\n id: string\n /** Stable identity for the long-lived objective. One pursuit may contain many runs. */\n pursuitId?: string\n runId: string\n scenarioId?: string\n stepIndex: number\n kind: RuntimeDecisionKind\n candidateActions: string[]\n context?: string\n evidence: RuntimeDecisionEvidenceRef[]\n metadata?: Record<string, unknown>\n}\n\nexport interface RuntimeHookErrorContext {\n hook: 'onEvent' | 'onDecisionPoint'\n eventId?: string\n target?: RuntimeHookTarget\n phase?: RuntimeHookPhase\n decisionId?: string\n decisionKind?: RuntimeDecisionKind\n}\n\n/**\n * The observation seam attached to a running loop (never to the portable genome).\n * Implement the optional hooks to receive lifecycle events, semantic decision points,\n * and hook errors. Author with {@link defineRuntimeHooks} for inference, and attach N\n * observers at once with {@link composeRuntimeHooks} — there is ONE event stream, not a\n * callback-prop zoo.\n */\nexport interface RuntimeHooks {\n /**\n * General before/after/event hook. Use this for telemetry, memory capture,\n * policy wrapping, child lifecycle observers, or product-specific extension\n * points.\n */\n onEvent?: (event: RuntimeHookEvent, context: RuntimeHookContext) => void | Promise<void>\n /**\n * Semantic decision hook. Belief-state evaluation consumes this, but runtime\n * code should keep emitting ordinary lifecycle events as the base layer.\n */\n onDecisionPoint?: (\n point: RuntimeDecisionPoint,\n context: RuntimeHookContext,\n ) => void | Promise<void>\n onHookError?: (error: Error, context: RuntimeHookErrorContext) => void | Promise<void>\n}\n\n/** Identity helper that types a {@link RuntimeHooks} literal so the fields are inferred. */\nexport function defineRuntimeHooks(hooks: RuntimeHooks): RuntimeHooks {\n return hooks\n}\n\n/**\n * Attach a stable pursuit identity to the entire observer stream without changing\n * agent code or teaching individual runtimes about pursuits. Because recursive Scope\n * execution already inherits one RuntimeHooks instance, this wrapper automatically\n * covers descendants, nested drivers, and resumed execution that reuses the wrapper.\n *\n * Existing matching pursuit ids are preserved. A conflicting id fails closed: silently\n * rewriting attribution would make the meta-observer untrustworthy.\n */\nexport function withPursuitContext(pursuitId: string, hooks: RuntimeHooks): RuntimeHooks {\n const stableId = pursuitId.trim()\n if (stableId.length === 0) throw new TypeError('withPursuitContext: pursuitId must be non-empty')\n\n const assertAndStamp = <T extends RuntimeHookEvent | RuntimeDecisionPoint>(value: T): T => {\n if (value.pursuitId !== undefined && value.pursuitId !== stableId) {\n throw new Error(\n `withPursuitContext: observer identity conflict (${value.pursuitId} !== ${stableId})`,\n )\n }\n if (value.pursuitId === stableId) return value\n return { ...value, pursuitId: stableId }\n }\n\n return {\n onEvent: hooks.onEvent\n ? (event, context) => hooks.onEvent?.(assertAndStamp(event), context)\n : undefined,\n onDecisionPoint: hooks.onDecisionPoint\n ? (point, context) => hooks.onDecisionPoint?.(assertAndStamp(point), context)\n : undefined,\n onHookError: hooks.onHookError,\n }\n}\n\n/**\n * Merge several {@link RuntimeHooks} into one. Falsy entries are dropped (so you can\n * pass `flag && hooks`), and every observer's `onEvent`/`onDecisionPoint` fires for each\n * event. Use this to attach N observers to a loop instead of a second event bus.\n */\nexport function composeRuntimeHooks(\n ...entries: Array<RuntimeHooks | undefined | null | false>\n): RuntimeHooks {\n const hooks = entries.filter((entry): entry is RuntimeHooks => !!entry)\n return {\n onEvent: hooks.some((hook) => hook.onEvent)\n ? (event, context) => {\n const pending: Promise<unknown>[] = []\n for (const hook of hooks) {\n const result = hook.onEvent?.(event, context)\n if (isThenable(result)) pending.push(Promise.resolve(result))\n }\n if (pending.length > 0) return Promise.all(pending).then(() => undefined)\n return undefined\n }\n : undefined,\n onDecisionPoint: hooks.some((hook) => hook.onDecisionPoint)\n ? (point, context) => {\n const pending: Promise<unknown>[] = []\n for (const hook of hooks) {\n const result = hook.onDecisionPoint?.(point, context)\n if (isThenable(result)) pending.push(Promise.resolve(result))\n }\n if (pending.length > 0) return Promise.all(pending).then(() => undefined)\n return undefined\n }\n : undefined,\n onHookError: hooks.some((hook) => hook.onHookError)\n ? (error, context) => {\n const pending: Promise<unknown>[] = []\n for (const hook of hooks) {\n const result = hook.onHookError?.(error, context)\n if (isThenable(result)) pending.push(Promise.resolve(result))\n }\n if (pending.length > 0) return Promise.all(pending).then(() => undefined)\n return undefined\n }\n : undefined,\n }\n}\n\n/** Fire `hooks.onEvent`, swallowing sync throws and surfacing async failures to `onError`. */\nexport function notifyRuntimeHookEvent(\n hooks: RuntimeHooks | undefined,\n event: RuntimeHookEvent,\n context: RuntimeHookContext = {},\n): void {\n const onEvent = hooks?.onEvent\n if (!onEvent) return\n\n try {\n const result = onEvent(event, context)\n if (isThenable(result)) {\n void result.catch((error) => {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onEvent',\n eventId: event.id,\n target: event.target,\n phase: event.phase,\n })\n })\n }\n } catch (error) {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onEvent',\n eventId: event.id,\n target: event.target,\n phase: event.phase,\n })\n }\n}\n\n/** Fire `hooks.onDecisionPoint`, swallowing sync throws and surfacing async failures to `onError`. */\nexport function notifyRuntimeDecisionPoint(\n hooks: RuntimeHooks | undefined,\n point: RuntimeDecisionPoint,\n context: RuntimeHookContext = {},\n): void {\n const onDecisionPoint = hooks?.onDecisionPoint\n if (!onDecisionPoint) return\n\n try {\n const result = onDecisionPoint(point, context)\n if (isThenable(result)) {\n void result.catch((error) => {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onDecisionPoint',\n decisionId: point.id,\n decisionKind: point.kind,\n })\n })\n }\n } catch (error) {\n notifyRuntimeHookError(hooks, toError(error), {\n hook: 'onDecisionPoint',\n decisionId: point.id,\n decisionKind: point.kind,\n })\n }\n}\n\nfunction notifyRuntimeHookError(\n hooks: RuntimeHooks | undefined,\n error: Error,\n context: RuntimeHookErrorContext,\n): void {\n try {\n const result = hooks?.onHookError?.(error, context)\n if (isThenable(result)) void result.catch(() => undefined)\n } catch {\n // Hook errors must never become agent-loop errors.\n }\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'then' in value &&\n typeof (value as { then?: unknown }).then === 'function'\n )\n}\n\nfunction toError(error: unknown): Error {\n return error instanceof Error ? error : new Error(String(error))\n}\n"],"mappings":";;AAgIA,SAAgB,mBAAmB,OAAmC;CACpE,OAAO;AACT;;;;;;;;;;AAWA,SAAgB,mBAAmB,WAAmB,OAAmC;CACvF,MAAM,WAAW,UAAU,KAAK;CAChC,IAAI,SAAS,WAAW,GAAG,MAAM,IAAI,UAAU,iDAAiD;CAEhG,MAAM,kBAAqE,UAAgB;EACzF,IAAI,MAAM,cAAc,KAAA,KAAa,MAAM,cAAc,UACvD,MAAM,IAAI,MACR,mDAAmD,MAAM,UAAU,OAAO,SAAS,EACrF;EAEF,IAAI,MAAM,cAAc,UAAU,OAAO;EACzC,OAAO;GAAE,GAAG;GAAO,WAAW;EAAS;CACzC;CAEA,OAAO;EACL,SAAS,MAAM,WACV,OAAO,YAAY,MAAM,UAAU,eAAe,KAAK,GAAG,OAAO,IAClE,KAAA;EACJ,iBAAiB,MAAM,mBAClB,OAAO,YAAY,MAAM,kBAAkB,eAAe,KAAK,GAAG,OAAO,IAC1E,KAAA;EACJ,aAAa,MAAM;CACrB;AACF;;;;;;AAOA,SAAgB,oBACd,GAAG,SACW;CACd,MAAM,QAAQ,QAAQ,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I,WAAW,MAAM,GACnB,OAAY,OAAO,UAAU;GAC3B,uBAAuB,OAAO,QAAQ,KAAK,GAAG;IAC5C,MAAM;IACN,SAAS,MAAM;IACf,QAAQ,MAAM;IACd,OAAO,MAAM;GACf,CAAC;EACH,CAAC;CAEL,SAAS,OAAO;EACd,uBAAuB,OAAO,QAAQ,KAAK,GAAG;GAC5C,MAAM;GACN,SAAS,MAAM;GACf,QAAQ,MAAM;GACd,OAAO,MAAM;EACf,CAAC;CACH;AACF;;AAGA,SAAgB,2BACd,OACA,OACA,UAA8B,CAAC,GACzB;CACN,MAAM,kBAAkB,OAAO;CAC/B,IAAI,CAAC,iBAAiB;CAEtB,IAAI;EACF,MAAM,SAAS,gBAAgB,OAAO,OAAO;EAC7C,IAAI,WAAW,MAAM,GACnB,OAAY,OAAO,UAAU;GAC3B,uBAAuB,OAAO,QAAQ,KAAK,GAAG;IAC5C,MAAM;IACN,YAAY,MAAM;IAClB,cAAc,MAAM;GACtB,CAAC;EACH,CAAC;CAEL,SAAS,OAAO;EACd,uBAAuB,OAAO,QAAQ,KAAK,GAAG;GAC5C,MAAM;GACN,YAAY,MAAM;GAClB,cAAc,MAAM;EACtB,CAAC;CACH;AACF;AAEA,SAAS,uBACP,OACA,OACA,SACM;CACN,IAAI;EACF,MAAM,SAAS,OAAO,cAAc,OAAO,OAAO;EAClD,IAAI,WAAW,MAAM,GAAG,OAAY,YAAY,KAAA,CAAS;CAC3D,QAAQ,CAER;AACF;AAEA,SAAS,WAAW,OAA+C;CACjE,OACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,OAAQ,MAA6B,SAAS;AAElD;AAEA,SAAS,QAAQ,OAAuB;CACtC,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,OAAO,KAAK,CAAC;AACjE"}
@@ -1,18 +1,6 @@
1
- /**
2
- *
3
- * Runtime hook contracts. Hooks are execution-scoped observers, not part of an
4
- * `AgentProfile`: profiles stay portable agent recipes; hooks attach to the
5
- * loop or product harness that is running the profile.
6
- *
7
- * A `pursuitId` is deliberately orthogonal to `runId`: a pursuit can span many
8
- * resumed/retried/forked runs while every event remains attributable to the
9
- * durable objective that caused it. The observer plane is outside the agent
10
- * environment and must never be required for agent correctness.
11
- *
12
- * @experimental
13
- */
1
+ import { AgentExactRunControlRef } from "@tangle-network/agent-interface";
14
2
  type RuntimeHookPhase = 'before' | 'after' | 'error' | 'event';
15
- type RuntimeHookTarget = 'agent.run' | 'agent.turn' | 'agent.tool_call' | 'agent.spawn' | 'agent.child' | 'agent.plan' | 'agent.decision' | (string & {});
3
+ type RuntimeHookTarget = 'agent.run' | 'agent.turn' | 'agent.tool_call' | 'agent.spawn' | 'agent.child' | 'agent.plan' | 'agent.decision' | 'agent.execution' | 'agent.model' | 'agent.steer' | (string & {});
16
4
  type RuntimeDecisionKind = 'continue' | 'verify' | 'ask' | 'retry' | 'stop' | 'memory-write' | 'memory-read' | 'tool-select' | 'skill-select' | 'workflow-select' | 'surface-promote' | (string & {});
17
5
  interface RuntimeHookEvent<Payload = unknown> {
18
6
  id: string;
@@ -31,6 +19,13 @@ interface RuntimeHookEvent<Payload = unknown> {
31
19
  interface RuntimeHookContext {
32
20
  signal?: AbortSignal;
33
21
  }
22
+ /** A provider acknowledged this exact execution; planned and refused dispatches emit none. */
23
+ interface RuntimeExecutionAdmittedPayload {
24
+ readonly attemptId?: string;
25
+ readonly nodeId: string;
26
+ readonly controlRef: AgentExactRunControlRef;
27
+ readonly sessionId: string;
28
+ }
34
29
  interface RuntimeDecisionEvidenceRef {
35
30
  source: string;
36
31
  id: string;
@@ -87,5 +82,5 @@ declare function defineRuntimeHooks(hooks: RuntimeHooks): RuntimeHooks;
87
82
  * event. Use this to attach N observers to a loop instead of a second event bus.
88
83
  */
89
84
  declare function composeRuntimeHooks(...entries: Array<RuntimeHooks | undefined | null | false>): RuntimeHooks;
90
- export { RuntimeHookErrorContext as a, RuntimeHookTarget as c, defineRuntimeHooks as d, RuntimeHookContext as i, RuntimeHooks as l, RuntimeDecisionKind as n, RuntimeHookEvent as o, RuntimeDecisionPoint as r, RuntimeHookPhase as s, RuntimeDecisionEvidenceRef as t, composeRuntimeHooks as u };
91
- //# sourceMappingURL=runtime-hooks-ZQqPw-0g.d.ts.map
85
+ export { RuntimeHookContext as a, RuntimeHookPhase as c, composeRuntimeHooks as d, defineRuntimeHooks as f, RuntimeExecutionAdmittedPayload as i, RuntimeHookTarget as l, RuntimeDecisionKind as n, RuntimeHookErrorContext as o, RuntimeDecisionPoint as r, RuntimeHookEvent as s, RuntimeDecisionEvidenceRef as t, RuntimeHooks as u };
86
+ //# sourceMappingURL=runtime-hooks-DPghSHV7.d.ts.map