@oni.bot/core 1.0.3 → 1.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 (146) hide show
  1. package/dist/checkpointers/postgres.d.ts.map +1 -1
  2. package/dist/checkpointers/postgres.js +2 -1
  3. package/dist/checkpointers/postgres.js.map +1 -1
  4. package/dist/cli/inspect.d.ts.map +1 -1
  5. package/dist/cli/inspect.js +4 -2
  6. package/dist/cli/inspect.js.map +1 -1
  7. package/dist/coordination/request-reply.d.ts +11 -2
  8. package/dist/coordination/request-reply.d.ts.map +1 -1
  9. package/dist/coordination/request-reply.js.map +1 -1
  10. package/dist/events/bus.d.ts.map +1 -1
  11. package/dist/events/bus.js +1 -0
  12. package/dist/events/bus.js.map +1 -1
  13. package/dist/graph.d.ts +11 -1
  14. package/dist/graph.d.ts.map +1 -1
  15. package/dist/graph.js +4 -2
  16. package/dist/graph.js.map +1 -1
  17. package/dist/harness/agent-loop.d.ts +1 -7
  18. package/dist/harness/agent-loop.d.ts.map +1 -1
  19. package/dist/harness/agent-loop.js +2 -642
  20. package/dist/harness/agent-loop.js.map +1 -1
  21. package/dist/harness/loop/hooks.d.ts +7 -0
  22. package/dist/harness/loop/hooks.d.ts.map +1 -0
  23. package/dist/harness/loop/hooks.js +46 -0
  24. package/dist/harness/loop/hooks.js.map +1 -0
  25. package/dist/harness/loop/index.d.ts +8 -0
  26. package/dist/harness/loop/index.d.ts.map +1 -0
  27. package/dist/harness/loop/index.js +257 -0
  28. package/dist/harness/loop/index.js.map +1 -0
  29. package/dist/harness/loop/inference.d.ts +19 -0
  30. package/dist/harness/loop/inference.d.ts.map +1 -0
  31. package/dist/harness/loop/inference.js +121 -0
  32. package/dist/harness/loop/inference.js.map +1 -0
  33. package/dist/harness/loop/memory.d.ts +22 -0
  34. package/dist/harness/loop/memory.d.ts.map +1 -0
  35. package/dist/harness/loop/memory.js +73 -0
  36. package/dist/harness/loop/memory.js.map +1 -0
  37. package/dist/harness/loop/safety.d.ts +8 -0
  38. package/dist/harness/loop/safety.d.ts.map +1 -0
  39. package/dist/harness/loop/safety.js +21 -0
  40. package/dist/harness/loop/safety.js.map +1 -0
  41. package/dist/harness/loop/tools.d.ts +24 -0
  42. package/dist/harness/loop/tools.d.ts.map +1 -0
  43. package/dist/harness/loop/tools.js +184 -0
  44. package/dist/harness/loop/tools.js.map +1 -0
  45. package/dist/harness/loop/types.d.ts +7 -0
  46. package/dist/harness/loop/types.d.ts.map +1 -0
  47. package/dist/harness/loop/types.js +9 -0
  48. package/dist/harness/loop/types.js.map +1 -0
  49. package/dist/harness/memory/fs-compat.d.ts +3 -0
  50. package/dist/harness/memory/fs-compat.d.ts.map +1 -0
  51. package/dist/harness/memory/fs-compat.js +26 -0
  52. package/dist/harness/memory/fs-compat.js.map +1 -0
  53. package/dist/harness/memory/index.d.ts +105 -0
  54. package/dist/harness/memory/index.d.ts.map +1 -0
  55. package/dist/harness/memory/index.js +491 -0
  56. package/dist/harness/memory/index.js.map +1 -0
  57. package/dist/harness/memory/prompter.d.ts +7 -0
  58. package/dist/harness/memory/prompter.d.ts.map +1 -0
  59. package/dist/harness/memory/prompter.js +24 -0
  60. package/dist/harness/memory/prompter.js.map +1 -0
  61. package/dist/harness/memory/ranker.d.ts +15 -0
  62. package/dist/harness/memory/ranker.d.ts.map +1 -0
  63. package/dist/harness/memory/ranker.js +72 -0
  64. package/dist/harness/memory/ranker.js.map +1 -0
  65. package/dist/harness/memory/scanner.d.ts +26 -0
  66. package/dist/harness/memory/scanner.d.ts.map +1 -0
  67. package/dist/harness/memory/scanner.js +187 -0
  68. package/dist/harness/memory/scanner.js.map +1 -0
  69. package/dist/harness/memory/types.d.ts +50 -0
  70. package/dist/harness/memory/types.d.ts.map +1 -0
  71. package/dist/harness/memory/types.js +7 -0
  72. package/dist/harness/memory/types.js.map +1 -0
  73. package/dist/harness/memory-loader.d.ts +2 -149
  74. package/dist/harness/memory-loader.d.ts.map +1 -1
  75. package/dist/harness/memory-loader.js +1 -713
  76. package/dist/harness/memory-loader.js.map +1 -1
  77. package/dist/hitl/interrupt.d.ts.map +1 -1
  78. package/dist/hitl/interrupt.js +2 -1
  79. package/dist/hitl/interrupt.js.map +1 -1
  80. package/dist/prebuilt/react-agent.d.ts.map +1 -1
  81. package/dist/prebuilt/react-agent.js +6 -2
  82. package/dist/prebuilt/react-agent.js.map +1 -1
  83. package/dist/pregel/checkpointing.d.ts +12 -0
  84. package/dist/pregel/checkpointing.d.ts.map +1 -0
  85. package/dist/pregel/checkpointing.js +60 -0
  86. package/dist/pregel/checkpointing.js.map +1 -0
  87. package/dist/pregel/execution.d.ts +7 -0
  88. package/dist/pregel/execution.d.ts.map +1 -0
  89. package/dist/pregel/execution.js +178 -0
  90. package/dist/pregel/execution.js.map +1 -0
  91. package/dist/pregel/index.d.ts +61 -0
  92. package/dist/pregel/index.d.ts.map +1 -0
  93. package/dist/pregel/index.js +154 -0
  94. package/dist/pregel/index.js.map +1 -0
  95. package/dist/pregel/interrupts.d.ts +3 -0
  96. package/dist/pregel/interrupts.d.ts.map +1 -0
  97. package/dist/pregel/interrupts.js +7 -0
  98. package/dist/pregel/interrupts.js.map +1 -0
  99. package/dist/pregel/state-helpers.d.ts +12 -0
  100. package/dist/pregel/state-helpers.d.ts.map +1 -0
  101. package/dist/pregel/state-helpers.js +71 -0
  102. package/dist/pregel/state-helpers.js.map +1 -0
  103. package/dist/pregel/streaming.d.ts +5 -0
  104. package/dist/pregel/streaming.d.ts.map +1 -0
  105. package/dist/pregel/streaming.js +462 -0
  106. package/dist/pregel/streaming.js.map +1 -0
  107. package/dist/pregel/types.d.ts +48 -0
  108. package/dist/pregel/types.d.ts.map +1 -0
  109. package/dist/pregel/types.js +5 -0
  110. package/dist/pregel/types.js.map +1 -0
  111. package/dist/pregel.d.ts +1 -66
  112. package/dist/pregel.d.ts.map +1 -1
  113. package/dist/pregel.js +2 -854
  114. package/dist/pregel.js.map +1 -1
  115. package/dist/swarm/agent-node.d.ts +11 -0
  116. package/dist/swarm/agent-node.d.ts.map +1 -0
  117. package/dist/swarm/agent-node.js +156 -0
  118. package/dist/swarm/agent-node.js.map +1 -0
  119. package/dist/swarm/compile-ext.d.ts +5 -0
  120. package/dist/swarm/compile-ext.d.ts.map +1 -0
  121. package/dist/swarm/compile-ext.js +126 -0
  122. package/dist/swarm/compile-ext.js.map +1 -0
  123. package/dist/swarm/config.d.ts +147 -0
  124. package/dist/swarm/config.d.ts.map +1 -0
  125. package/dist/swarm/config.js +17 -0
  126. package/dist/swarm/config.js.map +1 -0
  127. package/dist/swarm/factories.d.ts +37 -0
  128. package/dist/swarm/factories.d.ts.map +1 -0
  129. package/dist/swarm/factories.js +703 -0
  130. package/dist/swarm/factories.js.map +1 -0
  131. package/dist/swarm/graph.d.ts +14 -147
  132. package/dist/swarm/graph.d.ts.map +1 -1
  133. package/dist/swarm/graph.js +30 -917
  134. package/dist/swarm/graph.js.map +1 -1
  135. package/dist/swarm/pool.js.map +1 -1
  136. package/dist/swarm/supervisor.js.map +1 -1
  137. package/dist/testing/index.d.ts +2 -2
  138. package/dist/testing/index.d.ts.map +1 -1
  139. package/dist/testing/index.js +3 -2
  140. package/dist/testing/index.js.map +1 -1
  141. package/dist/tools/define.d.ts +2 -1
  142. package/dist/tools/define.d.ts.map +1 -1
  143. package/dist/tools/define.js +3 -1
  144. package/dist/tools/define.js.map +1 -1
  145. package/dist/tools/types.d.ts.map +1 -1
  146. package/package.json +1 -1
@@ -0,0 +1,73 @@
1
+ // ============================================================
2
+ // @oni.bot/core/harness/loop — Memory
3
+ // MemoryLoader wake/orient/match integration.
4
+ // ============================================================
5
+ import { MemoryLoader } from "../memory-loader.js";
6
+ /**
7
+ * Initialize MemoryLoader and run wake/orient/match if configured.
8
+ * Returns the loader instance and the built system prompt prefix.
9
+ */
10
+ export function initMemory(prompt, config) {
11
+ const memoryLoader = config.memoryRoot
12
+ ? MemoryLoader.fromRoot(config.memoryRoot, {
13
+ budgets: config.memoryBudgets,
14
+ debug: config.memoryDebug,
15
+ })
16
+ : null;
17
+ let memoryContext = "";
18
+ if (memoryLoader && !config.signal?.aborted) {
19
+ memoryLoader.wake();
20
+ memoryLoader.orient();
21
+ const t2 = memoryLoader.match(prompt);
22
+ if (config.memoryDebug && t2.dropped.length > 0) {
23
+ console.log(`[MemoryLoader] match() dropped ${t2.dropped.length} units over T2 budget`);
24
+ }
25
+ memoryContext = memoryLoader.buildSystemPrompt([0, 1, 2]);
26
+ }
27
+ return { memoryLoader, memoryContext };
28
+ }
29
+ /**
30
+ * buildEpisodicLog — Assemble session log for persistEpisodic().
31
+ *
32
+ * When compactor.getLastSummary() is unavailable (not yet implemented),
33
+ * ## What Happened falls back to the raw task description.
34
+ */
35
+ export function buildEpisodicLog(sessionId, taskDescription, turnCount, outcome, compactor) {
36
+ const c = compactor;
37
+ const summary = c?.getLastSummary?.() ?? null;
38
+ const openThreads = c?.getOpenThreads?.() ?? "none";
39
+ const outcomeNote = outcome === "budget-exceeded"
40
+ ? "Session ended at turn limit. Task may be incomplete — check Open Threads before assuming prior work is done."
41
+ : "";
42
+ return [
43
+ `---`,
44
+ `type: episodic`,
45
+ `session: ${sessionId}`,
46
+ `outcome: ${outcome}`,
47
+ `turns: ${turnCount}`,
48
+ `created: ${new Date().toISOString()}`,
49
+ `---`,
50
+ ``,
51
+ `## What Happened`,
52
+ summary ?? taskDescription,
53
+ ``,
54
+ `## Turns`,
55
+ String(turnCount),
56
+ ``,
57
+ `## Outcome`,
58
+ outcome,
59
+ ...(outcomeNote ? [``, outcomeNote] : []),
60
+ ``,
61
+ `## Open Threads`,
62
+ openThreads,
63
+ ].join("\n");
64
+ }
65
+ /** Persist episodic memory and reset session state. */
66
+ export function finalizeMemory(memoryLoader, sessionId, prompt, turn, sessionOutcome, config) {
67
+ if (memoryLoader) {
68
+ const log = buildEpisodicLog(sessionId, prompt, turn, sessionOutcome, config.compactor);
69
+ memoryLoader.persistEpisodic(sessionId, log);
70
+ memoryLoader.resetSession();
71
+ }
72
+ }
73
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/harness/loop/memory.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,sCAAsC;AACtC,8CAA8C;AAC9C,+DAA+D;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAWnD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,MAAuB;IAChE,MAAM,YAAY,GAAG,MAAM,CAAC,UAAU;QACpC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE;YACvC,OAAO,EAAE,MAAM,CAAC,aAAa;YAC7B,KAAK,EAAE,MAAM,CAAC,WAAW;SAC1B,CAAC;QACJ,CAAC,CAAC,IAAI,CAAC;IAET,IAAI,aAAa,GAAG,EAAE,CAAC;IACvB,IAAI,YAAY,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;QAC5C,YAAY,CAAC,IAAI,EAAE,CAAC;QACpB,YAAY,CAAC,MAAM,EAAE,CAAC;QACtB,MAAM,EAAE,GAAG,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACtC,IAAI,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,GAAG,CAAC,kCAAkC,EAAE,CAAC,OAAO,CAAC,MAAM,uBAAuB,CAAC,CAAC;QAC1F,CAAC;QACD,aAAa,GAAG,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AACzC,CAAC;AAUD;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAiB,EACjB,eAAuB,EACvB,SAAiB,EACjB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SafetyCheckResult } from "../safety-gate.js";
2
+ /**
3
+ * Run a safety gate check for a tool call.
4
+ * Returns the check result, or null if no gate is configured or the tool
5
+ * does not require a check.
6
+ */
7
+ export declare function checkSafety(safetyGate: SafetyGate | undefined, toolCallId: string, toolName: string, toolArgs: Record<string, unknown>): Promise<SafetyCheckResult | null>;
8
+ //# sourceMappingURL=safety.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safety.d.ts","sourceRoot":"","sources":["../../../src/harness/loop/safety.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAIvE;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,UAAU,GAAG,SAAS,EAClC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAUnC"}
@@ -0,0 +1,21 @@
1
+ // ============================================================
2
+ // @oni.bot/core/harness/loop — Safety
3
+ // SafetyGate check integration.
4
+ // ============================================================
5
+ // ─── checkSafety ────────────────────────────────────────────────────────────
6
+ /**
7
+ * Run a safety gate check for a tool call.
8
+ * Returns the check result, or null if no gate is configured or the tool
9
+ * does not require a check.
10
+ */
11
+ export async function checkSafety(safetyGate, toolCallId, toolName, toolArgs) {
12
+ if (!safetyGate || !safetyGate.requiresCheck(toolName)) {
13
+ return null;
14
+ }
15
+ return safetyGate.check({
16
+ id: toolCallId,
17
+ name: toolName,
18
+ args: toolArgs,
19
+ });
20
+ }
21
+ //# sourceMappingURL=safety.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safety.js","sourceRoot":"","sources":["../../../src/harness/loop/safety.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,sCAAsC;AACtC,gCAAgC;AAChC,+DAA+D;AAI/D,+EAA+E;AAE/E;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,UAAkC,EAClC,UAAkB,EAClB,QAAgB,EAChB,QAAiC;IAEjC,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,UAAU,CAAC,KAAK,CAAC;QACtB,EAAE,EAAE,UAAU;QACd,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { LLMToolDef, ONIModelToolCall } from "../../models/types.js";
2
+ import type { ToolDefinition } from "../../tools/types.js";
3
+ import type { LoopToolResult, LoopMessage, AgentLoopConfig } from "../types.js";
4
+ /** Convert ToolDefinition[] to LLMToolDef[] for the model adapter. */
5
+ export declare function buildLLMTools(tools: ToolDefinition[]): LLMToolDef[];
6
+ /** Build a name → ToolDefinition lookup map. */
7
+ export declare function buildToolMap(tools: ToolDefinition[]): Map<string, ToolDefinition>;
8
+ export interface ToolExecutionContext {
9
+ sessionId: string;
10
+ threadId: string;
11
+ turn: number;
12
+ config: AgentLoopConfig;
13
+ toolMap: Map<string, ToolDefinition>;
14
+ hasMemoryLoader: boolean;
15
+ }
16
+ /**
17
+ * Execute all tool calls for a turn.
18
+ * Returns tool results and any yield-able events (tool_start, tool_metadata).
19
+ */
20
+ export declare function executeTools(toolCalls: ONIModelToolCall[], ctx: ToolExecutionContext): Promise<{
21
+ toolResults: LoopToolResult[];
22
+ events: LoopMessage[];
23
+ }>;
24
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/harness/loop/tools.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EACV,cAAc,EAEd,WAAW,EACX,eAAe,EAChB,MAAM,aAAa,CAAC;AAOrB,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,UAAU,EAAE,CAMnE;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAMjF;AAID,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;IACxB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IACrC,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,GAAG,EAAE,oBAAoB,GACxB,OAAO,CAAC;IAAE,WAAW,EAAE,cAAc,EAAE,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAAC,CAsKnE"}
@@ -0,0 +1,184 @@
1
+ // ============================================================
2
+ // @oni.bot/core/harness/loop — Tools
3
+ // Tool schema → adapter conversion + sequential execution.
4
+ // ============================================================
5
+ import { validateToolArgs } from "../validate-args.js";
6
+ import { makeMessage } from "./types.js";
7
+ import { checkSafety } from "./safety.js";
8
+ // ─── buildLLMTools ──────────────────────────────────────────────────────────
9
+ /** Convert ToolDefinition[] to LLMToolDef[] for the model adapter. */
10
+ export function buildLLMTools(tools) {
11
+ return tools.map((t) => ({
12
+ name: t.name,
13
+ description: t.description,
14
+ parameters: t.schema,
15
+ }));
16
+ }
17
+ /** Build a name → ToolDefinition lookup map. */
18
+ export function buildToolMap(tools) {
19
+ const toolMap = new Map();
20
+ for (const t of tools) {
21
+ toolMap.set(t.name, t);
22
+ }
23
+ return toolMap;
24
+ }
25
+ /**
26
+ * Execute all tool calls for a turn.
27
+ * Returns tool results and any yield-able events (tool_start, tool_metadata).
28
+ */
29
+ export async function executeTools(toolCalls, ctx) {
30
+ const { sessionId, threadId, turn, config, toolMap, hasMemoryLoader } = ctx;
31
+ const toolResults = [];
32
+ const events = [];
33
+ for (const toolCall of toolCalls) {
34
+ // Fire PreToolUse hook
35
+ if (config.hooksEngine) {
36
+ const preResult = await config.hooksEngine.fire("PreToolUse", {
37
+ sessionId,
38
+ toolName: toolCall.name,
39
+ input: toolCall.args,
40
+ });
41
+ if (preResult?.decision === "deny") {
42
+ toolResults.push({
43
+ toolCallId: toolCall.id,
44
+ toolName: toolCall.name,
45
+ content: `Tool use denied: ${preResult.reason ?? "blocked by hook"}`,
46
+ isError: true,
47
+ });
48
+ continue;
49
+ }
50
+ // Apply modifiedInput if hook returned one
51
+ if (preResult?.modifiedInput) {
52
+ Object.assign(toolCall.args, preResult.modifiedInput);
53
+ }
54
+ }
55
+ // Safety gate check
56
+ const safetyResult = await checkSafety(config.safetyGate, toolCall.id, toolCall.name, toolCall.args);
57
+ if (safetyResult !== null && !safetyResult.approved) {
58
+ toolResults.push({
59
+ toolCallId: toolCall.id,
60
+ toolName: toolCall.name,
61
+ content: `Tool blocked by safety gate: ${safetyResult.reason ?? "unsafe operation"}`,
62
+ isError: true,
63
+ });
64
+ continue;
65
+ }
66
+ // Find tool
67
+ const toolDef = toolMap.get(toolCall.name);
68
+ if (!toolDef) {
69
+ toolResults.push({
70
+ toolCallId: toolCall.id,
71
+ toolName: toolCall.name,
72
+ content: `Unknown tool: ${toolCall.name}`,
73
+ isError: true,
74
+ });
75
+ continue;
76
+ }
77
+ // Validate tool arguments before execution
78
+ if (toolDef.schema) {
79
+ const validationError = validateToolArgs(toolCall.args, toolDef.schema, toolCall.name);
80
+ if (validationError) {
81
+ toolResults.push({
82
+ toolCallId: toolCall.id,
83
+ toolName: toolCall.name,
84
+ content: `${validationError}. Please retry with correct arguments.`,
85
+ isError: true,
86
+ });
87
+ continue;
88
+ }
89
+ }
90
+ // Yield tool_start so the conductor can emit tool.call events
91
+ events.push(makeMessage("tool_start", sessionId, turn, {
92
+ metadata: {
93
+ toolName: toolCall.name,
94
+ toolArgs: toolCall.args,
95
+ toolCallId: toolCall.id,
96
+ },
97
+ }));
98
+ const metadataUpdates = [];
99
+ const toolCtx = {
100
+ config: {},
101
+ store: null,
102
+ state: {},
103
+ emit: () => { },
104
+ sessionId,
105
+ threadId,
106
+ agentName: config.agentName,
107
+ turn,
108
+ signal: config.signal,
109
+ metadata: (update) => {
110
+ metadataUpdates.push(update);
111
+ },
112
+ };
113
+ try {
114
+ const startTime = Date.now();
115
+ const rawResult = await toolDef.execute(toolCall.args, toolCtx);
116
+ const durationMs = Date.now() - startTime;
117
+ const content = typeof rawResult === "string" ? rawResult : JSON.stringify(rawResult);
118
+ // Push the successful result first — before the hook — so a hook
119
+ // throw cannot retroactively mark this tool call as failed.
120
+ toolResults.push({
121
+ toolCallId: toolCall.id,
122
+ toolName: toolCall.name,
123
+ content,
124
+ durationMs,
125
+ });
126
+ // Yield collected metadata updates from ctx.metadata() calls
127
+ for (const mu of metadataUpdates) {
128
+ events.push(makeMessage("tool_metadata", sessionId, turn, {
129
+ metadata: {
130
+ toolCallId: toolCall.id,
131
+ toolName: toolCall.name,
132
+ title: mu.title,
133
+ data: mu.metadata,
134
+ },
135
+ }));
136
+ }
137
+ // Fire PostToolUse — in its own try/catch so a hook error does not
138
+ // corrupt the conversation history by triggering PostToolUseFailure
139
+ // for a tool that actually succeeded.
140
+ if (config.hooksEngine) {
141
+ try {
142
+ await config.hooksEngine.fire("PostToolUse", {
143
+ sessionId,
144
+ toolName: toolCall.name,
145
+ input: toolCall.args,
146
+ output: rawResult,
147
+ durationMs,
148
+ });
149
+ }
150
+ catch {
151
+ // Hook errors are non-fatal — the tool result is already recorded.
152
+ }
153
+ }
154
+ }
155
+ catch (err) {
156
+ const errorMsg = err instanceof Error ? err.message : String(err);
157
+ // Fire PostToolUseFailure — in its own try/catch so a hook error does not
158
+ // drop the error result from toolResults or corrupt conversation history.
159
+ if (config.hooksEngine) {
160
+ try {
161
+ await config.hooksEngine.fire("PostToolUseFailure", {
162
+ sessionId,
163
+ toolName: toolCall.name,
164
+ input: toolCall.args,
165
+ error: err instanceof Error ? err : errorMsg,
166
+ });
167
+ }
168
+ catch {
169
+ // Hook errors are non-fatal — the tool error result is still recorded.
170
+ }
171
+ }
172
+ toolResults.push({
173
+ toolCallId: toolCall.id,
174
+ toolName: toolCall.name,
175
+ content: hasMemoryLoader
176
+ ? `Tool error: ${errorMsg}\n\nMemory query may help — call memory_query with a specific topic if this failure suggests a knowledge gap.`
177
+ : `Tool error: ${errorMsg}`,
178
+ isError: true,
179
+ });
180
+ }
181
+ }
182
+ return { toolResults, events };
183
+ }
184
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/harness/loop/tools.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,qCAAqC;AACrC,2DAA2D;AAC3D,+DAA+D;AAU/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,+EAA+E;AAE/E,sEAAsE;AACtE,MAAM,UAAU,aAAa,CAAC,KAAuB;IACnD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,UAAU,EAAE,CAAC,CAAC,MAAM;KACrB,CAAC,CAAC,CAAC;AACN,CAAC;AAED,gDAAgD;AAChD,MAAM,UAAU,YAAY,CAAC,KAAuB;IAClD,MAAM,OAAO,GAAG,IAAI,GAAG,EAA0B,CA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AAC,MAAM,CAAC;oBACP,uEAAuE;gBACzE,CAAC;YACH,CAAC;YAED,WAAW,CAAC,IAAI,CAAC;gBACf,UAAU,EAAE,QAAQ,CAAC,EAAE;gBACvB,QAAQ,EAAE,QAAQ,CAAC,IAAI;gBACvB,OAAO,EAAE,eAAe;oBACtB,CAAC,CAAC,eAAe,QAAQ,+GAA+G;oBACxI,CAAC,CAAC,eAAe,QAAQ,EAAE;gBAC7B,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACjC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type { AgentLoopConfig, LoopMessage, LoopMessageType, LoopToolResult, HarnessToolContext, SessionOutcome, } from "../types.js";
2
+ export type { ONIModelMessage, ChatResponse, LLMToolDef, } from "../../models/types.js";
3
+ export type { ToolDefinition } from "../../tools/types.js";
4
+ export { generateId } from "../types.js";
5
+ import type { LoopMessage, LoopMessageType } from "../types.js";
6
+ export declare function makeMessage(type: LoopMessageType, sessionId: string, turn: number, overrides?: Partial<LoopMessage>): LoopMessage;
7
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/harness/loop/types.ts"],"names":[],"mappings":"AAOA,YAAY,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,eAAe,EACf,YAAY,EACZ,UAAU,GACX,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAKzC,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAAgB,WAAW,CACzB,IAAI,EAAE,eAAe,EACrB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,SAAS,GAAE,OAAO,CAAC,WAAW,CAAM,GACnC,WAAW,CAEb"}
@@ -0,0 +1,9 @@
1
+ // ============================================================
2
+ // @oni.bot/core/harness/loop — Internal types
3
+ // Shared types used across the loop sub-modules.
4
+ // ============================================================
5
+ export { generateId } from "../types.js";
6
+ export function makeMessage(type, sessionId, turn, overrides = {}) {
7
+ return { type, sessionId, turn, timestamp: Date.now(), ...overrides };
8
+ }
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/harness/loop/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,8CAA8C;AAC9C,iDAAiD;AACjD,+DAA+D;AAqB/D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,MAAM,UAAU,WAAW,CACzB,IAAqB,EACrB,SAAiB,EACjB,IAAY,EACZ,YAAkC,EAAE;IAEpC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,GAAG,SAAS,EAAE,CAAC;AACxE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function getFs(): typeof import("fs") | null;
2
+ export declare function getPath(): typeof import("path") | null;
3
+ //# sourceMappingURL=fs-compat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-compat.d.ts","sourceRoot":"","sources":["../../../src/harness/memory/fs-compat.ts"],"names":[],"mappings":"AAQA,wBAAgB,KAAK,IAAI,cAAc,IAAI,CAAC,GAAG,IAAI,CAOlD;AAED,wBAAgB,OAAO,IAAI,cAAc,MAAM,CAAC,GAAG,IAAI,CAOtD"}
@@ -0,0 +1,26 @@
1
+ // ============================================================
2
+ // @oni.bot/core/harness/memory — fs-compat
3
+ //
4
+ // Lazy fs/path helpers for browser compatibility.
5
+ // Single source of truth — all modules that need fs must import
6
+ // from here, NOT use top-level import * as fs from 'node:fs'.
7
+ // ============================================================
8
+ export function getFs() {
9
+ try {
10
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
11
+ return require("fs");
12
+ }
13
+ catch {
14
+ return null;
15
+ }
16
+ }
17
+ export function getPath() {
18
+ try {
19
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
20
+ return require("path");
21
+ }
22
+ catch {
23
+ return null;
24
+ }
25
+ }
26
+ //# sourceMappingURL=fs-compat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs-compat.js","sourceRoot":"","sources":["../../../src/harness/memory/fs-compat.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,2CAA2C;AAC3C,EAAE;AACF,kDAAkD;AAClD,gEAAgE;AAChE,8DAA8D;AAC9D,+DAA+D;AAE/D,MAAM,UAAU,KAAK;IACnB,IAAI,CAAC;QACH,iEAAiE;QACjE,OAAO,OAAO,CAAC,IAAI,CAAwB,CAAC;IAC9C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,OAAO;IACrB,IAAI,CAAC;QACH,iEAAiE;QACjE,OAAO,OAAO,CAAC,MAAM,CAA0B,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,105 @@
1
+ import type { ToolDefinition } from "../../tools/types.js";
2
+ export * from "./types.js";
3
+ import type { MemoryTier, MemoryType, MemoryUnit, LoadResult, MemoryLoaderConfig } from "./types.js";
4
+ export declare class MemoryLoader {
5
+ private readonly config;
6
+ private units;
7
+ private loaded;
8
+ private static readonly DEFAULT_BUDGETS;
9
+ constructor(config: MemoryLoaderConfig);
10
+ static fromRoot(root: string, opts?: Partial<MemoryLoaderConfig>): MemoryLoader;
11
+ private ensureDirectoryStructure;
12
+ scan(): void;
13
+ private registerFileSelf;
14
+ /**
15
+ * wake() — Load Tier 0 (identity). Always called first.
16
+ * Additive: already-loaded units are skipped.
17
+ */
18
+ wake(): LoadResult;
19
+ /**
20
+ * orient() — Load Tier 1 (working, user/PROFILE, INDEX files).
21
+ * Additive.
22
+ */
23
+ orient(): LoadResult;
24
+ /**
25
+ * match(task) — Load Tier 2 units relevant to the task string.
26
+ * Scored by tag-overlap × recency. Additive.
27
+ * Returns empty LoadResult if taskTokens is empty (no error).
28
+ */
29
+ match(task: string): LoadResult;
30
+ /**
31
+ * query(topic) — Load Tier 3 units. Called only via the memory_query tool.
32
+ * Additive.
33
+ */
34
+ query(topic: string): LoadResult;
35
+ /**
36
+ * load(key) — Directly load a specific memory unit by key. Additive.
37
+ */
38
+ load(key: string): MemoryUnit | null;
39
+ /**
40
+ * loadType(type) — Load all units of a given memory type.
41
+ * Budget: 16000t fixed (intentional escape hatch). Additive.
42
+ */
43
+ loadType(type: MemoryType): LoadResult;
44
+ /**
45
+ * buildSystemPrompt(tiers) — Assemble loaded units into a system prompt string.
46
+ * Default tiers: [0, 1, 2]
47
+ */
48
+ buildSystemPrompt(tiers?: MemoryTier[]): string;
49
+ /**
50
+ * getLoadedManifest() — Compact list of loaded keys + costs.
51
+ * Format: "- <key> (T<tier>, <cost>t)" per line.
52
+ */
53
+ getLoadedManifest(): string;
54
+ /** resetSession() — Clear loaded set and release hydrated content. Does not remove files. */
55
+ resetSession(): void;
56
+ /**
57
+ * persist() — Write a memory unit to disk.
58
+ * autoIndex: rebuildIndex() called synchronously before return when autoIndex === true.
59
+ * Returns MemoryUnit with content populated.
60
+ */
61
+ persist(type: MemoryType, filename: string, content: string, subfolder?: string): MemoryUnit;
62
+ private persistInternal;
63
+ /**
64
+ * persistEpisodic() — Write session log to episodic/recent/<date>_<sessionId>.md.
65
+ * Triggers compaction if recent/ has files older than episodicRecentDays.
66
+ */
67
+ persistEpisodic(sessionId: string, content: string): MemoryUnit;
68
+ /**
69
+ * persistSemantic() — Write knowledge unit to semantic/<domain>/<topic>.md.
70
+ * Rebuilds both domain INDEX.md and root semantic INDEX.md.
71
+ */
72
+ persistSemantic(domain: string, topic: string, content: string): MemoryUnit;
73
+ /**
74
+ * rebuildIndex() — Rewrite the INDEX.md for a given folder.
75
+ * INDEX.md files are write-only — never read back by the loader.
76
+ */
77
+ rebuildIndex(folder: string): void;
78
+ /** rebuildAllIndexes() — Rebuild every INDEX.md in the tree. */
79
+ rebuildAllIndexes(): void;
80
+ stats(): {
81
+ totalUnits: number;
82
+ currentlyLoaded: number;
83
+ totalTokensOnDisk: number;
84
+ byType: Record<string, number>;
85
+ byTier: Record<string, number>;
86
+ root: string;
87
+ };
88
+ /**
89
+ * getQueryTool() — Returns the memory_query ToolDefinition.
90
+ * The `reason` param is prompting-only — not used in execute logic.
91
+ * `_ctx` is typed as ToolContext (base); MemoryLoader needs no harness-specific context.
92
+ */
93
+ getQueryTool(): ToolDefinition<{
94
+ topic: string;
95
+ reason: string;
96
+ }, object>;
97
+ private loadByTier;
98
+ private getUnitsByTier;
99
+ private getBudget;
100
+ private hydrate;
101
+ private injectFrontmatter;
102
+ private compactEpisodicIfNeeded;
103
+ private log;
104
+ }
105
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/harness/memory/index.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,sBAAsB,CAAC;AAcxE,cAAc,YAAY,CAAC;AAE3B,OAAO,KAAK,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,UAAU,EACV,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAIpB,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;IACtD,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,MAAM,CAA0B;IAExC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAKrC;gBAEU,MAAM,EAAE,kBAAkB;IAetC,MAAM,CAAC,QAAQ,CAAC,IAAI,EA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