@chengchenccc/oh-my-agent 0.1.1-rc.1

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 (276) hide show
  1. package/README.md +79 -0
  2. package/dist/cli/args.d.ts +24 -0
  3. package/dist/cli/args.d.ts.map +1 -0
  4. package/dist/cli/args.js +120 -0
  5. package/dist/cli/initial-input.d.ts +32 -0
  6. package/dist/cli/initial-input.d.ts.map +1 -0
  7. package/dist/cli/initial-input.js +131 -0
  8. package/dist/cli.d.ts +3 -0
  9. package/dist/cli.d.ts.map +1 -0
  10. package/dist/cli.js +3 -0
  11. package/dist/core/__fixtures__/echo-model.d.ts +6 -0
  12. package/dist/core/__fixtures__/echo-model.d.ts.map +1 -0
  13. package/dist/core/__fixtures__/echo-model.js +10 -0
  14. package/dist/core/__fixtures__/mcp-echo-server.d.ts +2 -0
  15. package/dist/core/__fixtures__/mcp-echo-server.d.ts.map +1 -0
  16. package/dist/core/__fixtures__/mcp-echo-server.js +54 -0
  17. package/dist/core/agent-runtime.d.ts +21 -0
  18. package/dist/core/agent-runtime.d.ts.map +1 -0
  19. package/dist/core/agent-runtime.js +14 -0
  20. package/dist/core/memory/autonomous-memory.d.ts +21 -0
  21. package/dist/core/memory/autonomous-memory.d.ts.map +1 -0
  22. package/dist/core/memory/autonomous-memory.js +202 -0
  23. package/dist/core/persistence/in-memory-session-store.d.ts +3 -0
  24. package/dist/core/persistence/in-memory-session-store.d.ts.map +1 -0
  25. package/dist/core/persistence/in-memory-session-store.js +109 -0
  26. package/dist/core/persistence/session-store.contract.d.ts +5 -0
  27. package/dist/core/persistence/session-store.contract.d.ts.map +1 -0
  28. package/dist/core/persistence/session-store.contract.js +183 -0
  29. package/dist/core/persistence/session-store.d.ts +33 -0
  30. package/dist/core/persistence/session-store.d.ts.map +1 -0
  31. package/dist/core/persistence/session-store.js +22 -0
  32. package/dist/core/persistence/session-tree.d.ts +49 -0
  33. package/dist/core/persistence/session-tree.d.ts.map +1 -0
  34. package/dist/core/persistence/session-tree.js +1 -0
  35. package/dist/core/plugins/plugin-code.d.ts +13 -0
  36. package/dist/core/plugins/plugin-code.d.ts.map +1 -0
  37. package/dist/core/plugins/plugin-code.js +62 -0
  38. package/dist/core/plugins/plugin-marketplace.d.ts +72 -0
  39. package/dist/core/plugins/plugin-marketplace.d.ts.map +1 -0
  40. package/dist/core/plugins/plugin-marketplace.js +340 -0
  41. package/dist/core/plugins/plugin-resolve.d.ts +32 -0
  42. package/dist/core/plugins/plugin-resolve.d.ts.map +1 -0
  43. package/dist/core/plugins/plugin-resolve.js +101 -0
  44. package/dist/core/plugins/plugin-trust.d.ts +24 -0
  45. package/dist/core/plugins/plugin-trust.d.ts.map +1 -0
  46. package/dist/core/plugins/plugin-trust.js +89 -0
  47. package/dist/core/runtime/agent-event.d.ts +98 -0
  48. package/dist/core/runtime/agent-event.d.ts.map +1 -0
  49. package/dist/core/runtime/agent-event.js +1 -0
  50. package/dist/core/runtime/agent-loop.d.ts +142 -0
  51. package/dist/core/runtime/agent-loop.d.ts.map +1 -0
  52. package/dist/core/runtime/agent-loop.js +1008 -0
  53. package/dist/core/runtime/approval.d.ts +23 -0
  54. package/dist/core/runtime/approval.d.ts.map +1 -0
  55. package/dist/core/runtime/approval.js +25 -0
  56. package/dist/core/runtime/compaction.d.ts +22 -0
  57. package/dist/core/runtime/compaction.d.ts.map +1 -0
  58. package/dist/core/runtime/compaction.js +90 -0
  59. package/dist/core/runtime/context-estimate.d.ts +42 -0
  60. package/dist/core/runtime/context-estimate.d.ts.map +1 -0
  61. package/dist/core/runtime/context-estimate.js +34 -0
  62. package/dist/core/runtime/create-runtime.d.ts +81 -0
  63. package/dist/core/runtime/create-runtime.d.ts.map +1 -0
  64. package/dist/core/runtime/create-runtime.js +250 -0
  65. package/dist/core/runtime/fake-provider.d.ts +3 -0
  66. package/dist/core/runtime/fake-provider.d.ts.map +1 -0
  67. package/dist/core/runtime/fake-provider.js +87 -0
  68. package/dist/core/runtime/logger.d.ts +13 -0
  69. package/dist/core/runtime/logger.d.ts.map +1 -0
  70. package/dist/core/runtime/logger.js +38 -0
  71. package/dist/core/runtime/loop-input.d.ts +39 -0
  72. package/dist/core/runtime/loop-input.d.ts.map +1 -0
  73. package/dist/core/runtime/loop-input.js +38 -0
  74. package/dist/core/runtime/message-cache.d.ts +16 -0
  75. package/dist/core/runtime/message-cache.d.ts.map +1 -0
  76. package/dist/core/runtime/message-cache.js +23 -0
  77. package/dist/core/runtime/model-catalog.d.ts +10 -0
  78. package/dist/core/runtime/model-catalog.d.ts.map +1 -0
  79. package/dist/core/runtime/model-catalog.js +14 -0
  80. package/dist/core/runtime/plugin-runtime.d.ts +41 -0
  81. package/dist/core/runtime/plugin-runtime.d.ts.map +1 -0
  82. package/dist/core/runtime/plugin-runtime.js +1 -0
  83. package/dist/core/runtime/plugin.d.ts +86 -0
  84. package/dist/core/runtime/plugin.d.ts.map +1 -0
  85. package/dist/core/runtime/plugin.js +23 -0
  86. package/dist/core/runtime/process-tree.d.ts +12 -0
  87. package/dist/core/runtime/process-tree.d.ts.map +1 -0
  88. package/dist/core/runtime/process-tree.js +40 -0
  89. package/dist/core/runtime/prompt.d.ts +23 -0
  90. package/dist/core/runtime/prompt.d.ts.map +1 -0
  91. package/dist/core/runtime/prompt.js +29 -0
  92. package/dist/core/runtime/prompts.d.ts +16 -0
  93. package/dist/core/runtime/prompts.d.ts.map +1 -0
  94. package/dist/core/runtime/prompts.js +36 -0
  95. package/dist/core/runtime/retry.d.ts +20 -0
  96. package/dist/core/runtime/retry.d.ts.map +1 -0
  97. package/dist/core/runtime/retry.js +60 -0
  98. package/dist/core/runtime/run-runtime.d.ts +93 -0
  99. package/dist/core/runtime/run-runtime.d.ts.map +1 -0
  100. package/dist/core/runtime/run-runtime.js +664 -0
  101. package/dist/core/runtime/runtime-catalog.d.ts +12 -0
  102. package/dist/core/runtime/runtime-catalog.d.ts.map +1 -0
  103. package/dist/core/runtime/runtime-catalog.js +89 -0
  104. package/dist/core/runtime/stream-rules.d.ts +9 -0
  105. package/dist/core/runtime/stream-rules.d.ts.map +1 -0
  106. package/dist/core/runtime/stream-rules.js +44 -0
  107. package/dist/core/runtime/title.d.ts +7 -0
  108. package/dist/core/runtime/title.d.ts.map +1 -0
  109. package/dist/core/runtime/title.js +114 -0
  110. package/dist/core/runtime/todo.d.ts +16 -0
  111. package/dist/core/runtime/todo.d.ts.map +1 -0
  112. package/dist/core/runtime/todo.js +40 -0
  113. package/dist/core/runtime/tool-filter.d.ts +12 -0
  114. package/dist/core/runtime/tool-filter.d.ts.map +1 -0
  115. package/dist/core/runtime/tool-filter.js +23 -0
  116. package/dist/core/runtime/tool-pruning.d.ts +29 -0
  117. package/dist/core/runtime/tool-pruning.d.ts.map +1 -0
  118. package/dist/core/runtime/tool-pruning.js +105 -0
  119. package/dist/core/session/input-history.d.ts +8 -0
  120. package/dist/core/session/input-history.d.ts.map +1 -0
  121. package/dist/core/session/input-history.js +41 -0
  122. package/dist/core/session/session-file.d.ts +84 -0
  123. package/dist/core/session/session-file.d.ts.map +1 -0
  124. package/dist/core/session/session-file.js +392 -0
  125. package/dist/core/session/session-loop.d.ts +33 -0
  126. package/dist/core/session/session-loop.d.ts.map +1 -0
  127. package/dist/core/session/session-loop.js +30 -0
  128. package/dist/core/settings/project-settings.d.ts +46 -0
  129. package/dist/core/settings/project-settings.d.ts.map +1 -0
  130. package/dist/core/settings/project-settings.js +85 -0
  131. package/dist/core/settings/workspace-context.d.ts +10 -0
  132. package/dist/core/settings/workspace-context.d.ts.map +1 -0
  133. package/dist/core/settings/workspace-context.js +48 -0
  134. package/dist/core/tools/agent-fs-like.d.ts +15 -0
  135. package/dist/core/tools/agent-fs-like.d.ts.map +1 -0
  136. package/dist/core/tools/agent-fs-like.js +4 -0
  137. package/dist/core/tools/ask-question.d.ts +5 -0
  138. package/dist/core/tools/ask-question.d.ts.map +1 -0
  139. package/dist/core/tools/ask-question.js +51 -0
  140. package/dist/core/tools/bash.d.ts +5 -0
  141. package/dist/core/tools/bash.d.ts.map +1 -0
  142. package/dist/core/tools/bash.js +109 -0
  143. package/dist/core/tools/eval.d.ts +10 -0
  144. package/dist/core/tools/eval.d.ts.map +1 -0
  145. package/dist/core/tools/eval.js +83 -0
  146. package/dist/core/tools/file-tools.d.ts +18 -0
  147. package/dist/core/tools/file-tools.d.ts.map +1 -0
  148. package/dist/core/tools/file-tools.js +249 -0
  149. package/dist/core/tools/glob.d.ts +5 -0
  150. package/dist/core/tools/glob.d.ts.map +1 -0
  151. package/dist/core/tools/glob.js +54 -0
  152. package/dist/core/tools/grep.d.ts +5 -0
  153. package/dist/core/tools/grep.d.ts.map +1 -0
  154. package/dist/core/tools/grep.js +61 -0
  155. package/dist/core/tools/index.d.ts +14 -0
  156. package/dist/core/tools/index.d.ts.map +1 -0
  157. package/dist/core/tools/index.js +14 -0
  158. package/dist/core/tools/ls-tree.d.ts +10 -0
  159. package/dist/core/tools/ls-tree.d.ts.map +1 -0
  160. package/dist/core/tools/ls-tree.js +177 -0
  161. package/dist/core/tools/mcp-mount.d.ts +63 -0
  162. package/dist/core/tools/mcp-mount.d.ts.map +1 -0
  163. package/dist/core/tools/mcp-mount.js +287 -0
  164. package/dist/core/tools/read-image.d.ts +6 -0
  165. package/dist/core/tools/read-image.d.ts.map +1 -0
  166. package/dist/core/tools/read-image.js +98 -0
  167. package/dist/core/tools/skill.d.ts +11 -0
  168. package/dist/core/tools/skill.d.ts.map +1 -0
  169. package/dist/core/tools/skill.js +65 -0
  170. package/dist/core/tools/skills.d.ts +10 -0
  171. package/dist/core/tools/skills.d.ts.map +1 -0
  172. package/dist/core/tools/skills.js +116 -0
  173. package/dist/core/tools/todo-store.d.ts +8 -0
  174. package/dist/core/tools/todo-store.d.ts.map +1 -0
  175. package/dist/core/tools/todo-store.js +100 -0
  176. package/dist/core/tools/todo.d.ts +8 -0
  177. package/dist/core/tools/todo.d.ts.map +1 -0
  178. package/dist/core/tools/todo.js +91 -0
  179. package/dist/core/tools/url-guard.d.ts +12 -0
  180. package/dist/core/tools/url-guard.d.ts.map +1 -0
  181. package/dist/core/tools/url-guard.js +58 -0
  182. package/dist/core/tools/web-ports-std.d.ts +6 -0
  183. package/dist/core/tools/web-ports-std.d.ts.map +1 -0
  184. package/dist/core/tools/web-ports-std.js +145 -0
  185. package/dist/core/tools/web-ports.d.ts +56 -0
  186. package/dist/core/tools/web-ports.d.ts.map +1 -0
  187. package/dist/core/tools/web-ports.js +62 -0
  188. package/dist/core/tools/workspace-sandbox.d.ts +20 -0
  189. package/dist/core/tools/workspace-sandbox.d.ts.map +1 -0
  190. package/dist/core/tools/workspace-sandbox.js +84 -0
  191. package/dist/core/workflow/subagent-registry.d.ts +40 -0
  192. package/dist/core/workflow/subagent-registry.d.ts.map +1 -0
  193. package/dist/core/workflow/subagent-registry.js +118 -0
  194. package/dist/core/workflow/workflow-evaluator.d.ts +23 -0
  195. package/dist/core/workflow/workflow-evaluator.d.ts.map +1 -0
  196. package/dist/core/workflow/workflow-evaluator.js +21 -0
  197. package/dist/core/workflow/workflow-executor.d.ts +108 -0
  198. package/dist/core/workflow/workflow-executor.d.ts.map +1 -0
  199. package/dist/core/workflow/workflow-executor.js +549 -0
  200. package/dist/core/workflow/workflow-tools.d.ts +50 -0
  201. package/dist/core/workflow/workflow-tools.d.ts.map +1 -0
  202. package/dist/core/workflow/workflow-tools.js +217 -0
  203. package/dist/index.d.ts +14 -0
  204. package/dist/index.d.ts.map +1 -0
  205. package/dist/index.js +13 -0
  206. package/dist/main.d.ts +9 -0
  207. package/dist/main.d.ts.map +1 -0
  208. package/dist/main.js +97 -0
  209. package/dist/modes/json-mode.d.ts +5 -0
  210. package/dist/modes/json-mode.d.ts.map +1 -0
  211. package/dist/modes/json-mode.js +46 -0
  212. package/dist/modes/print-mode.d.ts +20 -0
  213. package/dist/modes/print-mode.d.ts.map +1 -0
  214. package/dist/modes/print-mode.js +82 -0
  215. package/dist/modes/rpc/jsonl.d.ts +23 -0
  216. package/dist/modes/rpc/jsonl.d.ts.map +1 -0
  217. package/dist/modes/rpc/jsonl.js +88 -0
  218. package/dist/modes/rpc/rpc-mode.d.ts +18 -0
  219. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -0
  220. package/dist/modes/rpc/rpc-mode.js +326 -0
  221. package/dist/modes/tui/settings-overlay.d.ts +23 -0
  222. package/dist/modes/tui/settings-overlay.d.ts.map +1 -0
  223. package/dist/modes/tui/settings-overlay.js +136 -0
  224. package/dist/modes/tui/tui-commands-session.d.ts +3 -0
  225. package/dist/modes/tui/tui-commands-session.d.ts.map +1 -0
  226. package/dist/modes/tui/tui-commands-session.js +191 -0
  227. package/dist/modes/tui/tui-commands.d.ts +52 -0
  228. package/dist/modes/tui/tui-commands.d.ts.map +1 -0
  229. package/dist/modes/tui/tui-commands.js +373 -0
  230. package/dist/modes/tui/tui-components.d.ts +81 -0
  231. package/dist/modes/tui/tui-components.d.ts.map +1 -0
  232. package/dist/modes/tui/tui-components.js +248 -0
  233. package/dist/modes/tui/tui-format.d.ts +65 -0
  234. package/dist/modes/tui/tui-format.d.ts.map +1 -0
  235. package/dist/modes/tui/tui-format.js +246 -0
  236. package/dist/modes/tui/tui-frame-provider.d.ts +16 -0
  237. package/dist/modes/tui/tui-frame-provider.d.ts.map +1 -0
  238. package/dist/modes/tui/tui-frame-provider.js +31 -0
  239. package/dist/modes/tui/tui-interactive.d.ts +16 -0
  240. package/dist/modes/tui/tui-interactive.d.ts.map +1 -0
  241. package/dist/modes/tui/tui-interactive.js +123 -0
  242. package/dist/modes/tui/tui-io.d.ts +12 -0
  243. package/dist/modes/tui/tui-io.d.ts.map +1 -0
  244. package/dist/modes/tui/tui-io.js +620 -0
  245. package/dist/modes/tui/tui-mode.d.ts +120 -0
  246. package/dist/modes/tui/tui-mode.d.ts.map +1 -0
  247. package/dist/modes/tui/tui-mode.js +391 -0
  248. package/dist/modes/tui/tui-render.d.ts +54 -0
  249. package/dist/modes/tui/tui-render.d.ts.map +1 -0
  250. package/dist/modes/tui/tui-render.js +399 -0
  251. package/dist/modes/tui/tui-slash.d.ts +12 -0
  252. package/dist/modes/tui/tui-slash.d.ts.map +1 -0
  253. package/dist/modes/tui/tui-slash.js +64 -0
  254. package/dist/modes/tui/tui-tool-render.d.ts +6 -0
  255. package/dist/modes/tui/tui-tool-render.d.ts.map +1 -0
  256. package/dist/modes/tui/tui-tool-render.js +79 -0
  257. package/dist/modes/tui/tui-transcript-reconciler.d.ts +25 -0
  258. package/dist/modes/tui/tui-transcript-reconciler.d.ts.map +1 -0
  259. package/dist/modes/tui/tui-transcript-reconciler.js +97 -0
  260. package/dist/modes/tui/view-state.d.ts +67 -0
  261. package/dist/modes/tui/view-state.d.ts.map +1 -0
  262. package/dist/modes/tui/view-state.js +353 -0
  263. package/dist/prompts/agents/subagent.md +26 -0
  264. package/dist/prompts/system/base.md +20 -0
  265. package/dist/prompts/system/memory.md +23 -0
  266. package/dist/prompts/system/safety.md +12 -0
  267. package/dist/protocol/index.d.ts +5 -0
  268. package/dist/protocol/index.d.ts.map +1 -0
  269. package/dist/protocol/index.js +2 -0
  270. package/dist/protocol/mapping.d.ts +25 -0
  271. package/dist/protocol/mapping.d.ts.map +1 -0
  272. package/dist/protocol/mapping.js +115 -0
  273. package/dist/protocol/transport.d.ts +1396 -0
  274. package/dist/protocol/transport.d.ts.map +1 -0
  275. package/dist/protocol/transport.js +170 -0
  276. package/package.json +49 -0
@@ -0,0 +1,89 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { agentDir } from "../session/session-file.js";
5
+ function trustedPath() {
6
+ return join(agentDir(), "trusted-plugins.json");
7
+ }
8
+ /** Directory hash (spec): recursive sha256 over sorted (relpath, fileHash)
9
+ * pairs, excluding node_modules. */
10
+ export function computePluginHash(pluginRoot) {
11
+ const files = [];
12
+ const walk = (dir, prefix) => {
13
+ for (const ent of readdirSync(dir, { withFileTypes: true })) {
14
+ if (ent.name === "node_modules")
15
+ continue;
16
+ const full = join(dir, ent.name);
17
+ const rel = prefix ? `${prefix}/${ent.name}` : ent.name;
18
+ if (ent.isDirectory())
19
+ walk(full, rel);
20
+ else if (ent.isFile()) {
21
+ files.push({
22
+ rel,
23
+ fileHash: createHash("sha256").update(readFileSync(full)).digest("hex"),
24
+ });
25
+ }
26
+ }
27
+ };
28
+ walk(pluginRoot, "");
29
+ files.sort((a, b) => (a.rel < b.rel ? -1 : a.rel > b.rel ? 1 : 0));
30
+ const aggregate = files.map((f) => `${f.rel}\0${f.fileHash}`).join("\n");
31
+ return `sha256:${createHash("sha256").update(aggregate).digest("hex")}`;
32
+ }
33
+ /** Corrupt file = empty map (all untrusted) — never throws (spec failure
34
+ * semantics). */
35
+ export function readTrustedPlugins() {
36
+ try {
37
+ const parsed = JSON.parse(readFileSync(trustedPath(), "utf8"));
38
+ if (typeof parsed !== "object" || parsed === null)
39
+ return new Map();
40
+ const out = new Map();
41
+ for (const [root, rec] of Object.entries(parsed)) {
42
+ if (typeof rec === "object" &&
43
+ rec !== null &&
44
+ typeof rec.hash === "string") {
45
+ out.set(root, rec);
46
+ }
47
+ }
48
+ return out;
49
+ }
50
+ catch {
51
+ return new Map();
52
+ }
53
+ }
54
+ export function writeTrustedPlugins(map) {
55
+ const obj = {};
56
+ for (const [root, rec] of map)
57
+ obj[root] = rec;
58
+ writeFileSync(trustedPath(), `${JSON.stringify(obj, null, 2)}\n`);
59
+ }
60
+ /** Record explicit user trust for a plugin root at its current hash. */
61
+ export function trustPlugin(pluginRoot) {
62
+ const map = readTrustedPlugins();
63
+ map.set(pluginRoot, {
64
+ hash: computePluginHash(pluginRoot),
65
+ trustedAt: new Date().toISOString(),
66
+ });
67
+ writeTrustedPlugins(map);
68
+ }
69
+ /** Trust decision: approved only when the recorded hash matches the
70
+ * current content hash (any file change re-untrusts). */
71
+ export function isPluginTrusted(pluginRoot, trusted) {
72
+ const rec = trusted.get(pluginRoot);
73
+ return rec !== undefined && rec.hash === computePluginHash(pluginRoot);
74
+ }
75
+ /** Content hash of a single file (workspace .mcp.json gating). */
76
+ export function computeFileHash(path) {
77
+ return `sha256:${createHash("sha256").update(readFileSync(path)).digest("hex")}`;
78
+ }
79
+ /** Record explicit user trust for a single file at its current hash. */
80
+ export function trustFile(path) {
81
+ const map = readTrustedPlugins();
82
+ map.set(path, { hash: computeFileHash(path), trustedAt: new Date().toISOString() });
83
+ writeTrustedPlugins(map);
84
+ }
85
+ /** File trust decision: recorded hash must match current content. */
86
+ export function isFileTrusted(path, trusted) {
87
+ const rec = trusted.get(path);
88
+ return rec !== undefined && rec.hash === computeFileHash(path);
89
+ }
@@ -0,0 +1,98 @@
1
+ import type { TodoItem } from "./todo.js";
2
+ /** Pi-style typed lifecycle events per runtime/oma.md. */
3
+ export type OmaLoopEvent = {
4
+ type: "agent_start";
5
+ } | {
6
+ type: "agent_end";
7
+ status: "completed" | "failed" | "stopped";
8
+ } | {
9
+ type: "turn_start";
10
+ turn: number;
11
+ } | {
12
+ type: "turn_end";
13
+ turn: number;
14
+ } | {
15
+ type: "message_start";
16
+ } | {
17
+ type: "message_update";
18
+ text: string;
19
+ } | {
20
+ type: "thinking_update";
21
+ text: string;
22
+ } | {
23
+ type: "message_end";
24
+ } | {
25
+ type: "tool_execution_start";
26
+ toolName: string;
27
+ kind?: "native" | "product";
28
+ callId: string;
29
+ /** The tool's resolved input (model call args), for transcript display. */
30
+ input?: Readonly<Record<string, unknown>>;
31
+ /** Wall-clock timeout for this tool (ms, 0 = disabled). */
32
+ timeoutMs?: number;
33
+ } | {
34
+ type: "tool_execution_end";
35
+ toolName: string;
36
+ kind?: "native" | "product";
37
+ callId: string;
38
+ result?: Readonly<Record<string, unknown>>;
39
+ } | {
40
+ /** Streaming partial output from a running tool (bash stdout). */
41
+ type: "tool_output";
42
+ toolName: string;
43
+ callId: string;
44
+ text: string;
45
+ } | {
46
+ type: "retry_start";
47
+ attempt: number;
48
+ } | {
49
+ type: "retry_end";
50
+ } | {
51
+ type: "compaction_start";
52
+ } | {
53
+ type: "compaction_end";
54
+ }
55
+ /** Emitted when the loop drains queued steers at a safe boundary.
56
+ * `drained` carries the injected user texts (pi's message_start(user) →
57
+ * addMessageToChat): surfaces render the user message when the loop
58
+ * actually takes it, not when it was submitted. */
59
+ | {
60
+ type: "queue_update";
61
+ drained?: readonly string[];
62
+ } | {
63
+ type: "stream_rule_triggered";
64
+ rule: string;
65
+ } | {
66
+ type: "todo_update";
67
+ items: readonly TodoItem[];
68
+ } | {
69
+ type: "workflow_started";
70
+ workflowId: string;
71
+ label: string;
72
+ agentCount: number;
73
+ } | {
74
+ type: "workflow_agent_started";
75
+ workflowId: string;
76
+ agentId: string;
77
+ label: string;
78
+ } | {
79
+ type: "workflow_agent_completed";
80
+ workflowId: string;
81
+ agentId: string;
82
+ label: string;
83
+ ok: boolean;
84
+ error?: string;
85
+ usage?: unknown;
86
+ } | {
87
+ type: "workflow_completed";
88
+ workflowId: string;
89
+ ok: boolean;
90
+ agentCount: number;
91
+ totalTokens: number;
92
+ } | {
93
+ type: "workflow_failed";
94
+ workflowId: string;
95
+ error: string;
96
+ };
97
+ export type AgentLoopListener = (event: OmaLoopEvent) => void | Promise<void>;
98
+ //# sourceMappingURL=agent-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-event.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/agent-event.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,0DAA0D;AAC1D,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAA;CAAE,GACjE;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,UAAU,CAAC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,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACnF;IAAE,IAAI,EAAE,wBAAwB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACtF;IACE,IAAI,EAAE,0BAA0B,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GACD;IACE,IAAI,EAAE,oBAAoB,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,EAAE,EAAE,OAAO,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,GACD;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,142 @@
1
+ import type { AskQuestionInput, AskQuestionResult, BackendInputMessage, Usage } from "@chengchenccc/agent-contract";
2
+ import type { AIMessageChunk, Message } from "@chengchenccc/message";
3
+ import type { SessionStore } from "../persistence/session-store.js";
4
+ import type { AgentLoopListener, OmaLoopEvent } from "./agent-event.js";
5
+ import type { ApprovalHandler } from "./approval.js";
6
+ import { type CompactionBudget } from "./compaction.js";
7
+ import type { CodingLoopInput } from "./loop-input.js";
8
+ import type { Plugin, PluginTool } from "./plugin.js";
9
+ import type { PluginRuntime } from "./plugin-runtime.js";
10
+ import { type PruneConfig } from "./tool-pruning.js";
11
+ export type { AgentLoopListener, OmaLoopEvent };
12
+ /** Summarizes covered messages into a compact context summary. Receives full
13
+ * Message objects (including tool_use/tool_result blocks) so tool semantics
14
+ * survive compaction. Injected by the caller (Phase 3 Worker uses
15
+ * ModelRuntime; tests inject a fake). */
16
+ export type ContextSummarizer = (messages: readonly Message[], signal?: AbortSignal) => Promise<string>;
17
+ /** Token-aware context budget for proactive compaction. Extends the compaction
18
+ * budget with a trigger ratio: compaction triggers when estimated tokens
19
+ * exceed limit * triggerRatio. Phase 3 injects a real model limit and token
20
+ * estimator; tests inject a simple char/4 proxy. */
21
+ export interface ContextBudget extends CompactionBudget {
22
+ /** Compaction triggers when estimated tokens exceed limit * triggerRatio. */
23
+ readonly triggerRatio: number;
24
+ }
25
+ export interface OmaSessionOptions {
26
+ readonly sessionId: string;
27
+ readonly store: SessionStore;
28
+ readonly plugins: readonly Plugin[];
29
+ readonly maxSteps: number;
30
+ readonly maxForceContinues: number;
31
+ /** The model call for one turn. */
32
+ readonly modelStream: (messages: readonly Message[], signal?: AbortSignal,
33
+ /** Current tool table (static plugins + per-Run resolved tools). */
34
+ tools?: readonly PluginTool[]) => AsyncIterable<AIMessageChunk>;
35
+ readonly summarize: ContextSummarizer;
36
+ /** HITL approval pipeline (spec): resolves options.request calls from
37
+ * tools and the ask-mode gate for plugin code tools. Absent = tools see
38
+ * no `request` and decide themselves. */
39
+ readonly approvalHandler?: ApprovalHandler;
40
+ /** HITL ask pipeline (ask_question tool): resolves options.ask calls. */
41
+ readonly askHandler?: (input: AskQuestionInput) => Promise<AskQuestionResult | null>;
42
+ /** Native-tool permission gate (run-runtime, ADR 0020 permissionMode): runs
43
+ * AFTER plugin beforeTool hooks; a block result prevents execution. Native
44
+ * high-risk tools (bash/write/edit/mcp__*) route here so ask/deny apply to
45
+ * them too — one pipeline for plugin AND native tools. */
46
+ readonly permissionGate?: (toolName: string, input: unknown) => Promise<{
47
+ block: boolean;
48
+ reason?: string;
49
+ } | undefined>;
50
+ /** Resolve the model display identity for a run's model ref, used to render
51
+ * the per-loop Meta. Optional: when omitted (tests), Meta omits the model line. */
52
+ readonly resolveModel?: (modelId: string) => Promise<{
53
+ provider: string;
54
+ id: string;
55
+ }>;
56
+ /** Resolve per-Run additional tools (e.g. the Product Tool manifest from
57
+ * `input.run.productTools`). Merged into the tool table at each runLoop
58
+ * start so snapshot changes apply on the next Run without a rebuild. */
59
+ readonly resolveTools?: (input: CodingLoopInput) => Promise<readonly PluginTool[]>;
60
+ /** Runtime capabilities injected into plugin hooks (model stream, store,
61
+ * workspace, emit). Optional: when omitted, hooks receive a stub with
62
+ * emit only (backward-compatible with pre-existing plugins). */
63
+ readonly pluginRuntime?: PluginRuntime;
64
+ readonly maxRetries?: number;
65
+ /** Token-aware proactive compaction budget. When estimated context tokens
66
+ * exceed limit * triggerRatio before a model turn, compact once. Leave
67
+ * undefined to disable proactive compaction. */
68
+ readonly contextBudget?: ContextBudget;
69
+ /** Tool-output pruning config. When set, old tool
70
+ * results outside the protect window are truncated to a summary before
71
+ * each model call — a lighter touch than full compaction. Protected
72
+ * tools (skills, plans) are never pruned. */
73
+ readonly pruneConfig?: Partial<PruneConfig>;
74
+ /** TTSR-style stream rules (absorbed from oh-my-pi): a regex watched
75
+ * against the assistant text stream. On match the turn is aborted, the
76
+ * partial output discarded, the rule injected as a hidden
77
+ * <system-reminder> user message, and the model retried in the same
78
+ * turn. Tool-argument streams are NOT matched: raw partial JSON escaping
79
+ * makes it unreliable (pi needed per-tool matcherDigest hooks for that). */
80
+ readonly streamRules?: readonly StreamRule[];
81
+ /** Prepend a <system-reminder> to failed tool results instructing the
82
+ * model to fix the cause and retry instead of proceeding as if it
83
+ * succeeded. Default: enabled. */
84
+ readonly toolFailureReminder?: boolean;
85
+ /** Called after each persist of conversational messages (prompt, steer,
86
+ * follow_up, assistant, tool_result — never meta/product_history). Lets
87
+ * the caller write the session file in real time (pi's appendMessage):
88
+ * a killed/failed process still leaves its message trail behind. */
89
+ readonly onPersistMessages?: (messages: readonly Message[]) => void;
90
+ }
91
+ /** One TTSR-style stream rule. Matching is text-only; each rule fires at
92
+ * most `maxInjections` (default 1) times per Run — pi's repeatMode
93
+ * "once". Patterns must be non-global (loader-side contract). */
94
+ export interface StreamRule {
95
+ readonly name: string;
96
+ readonly pattern: RegExp;
97
+ /** Reminder body injected inside <system-reminder> on trigger. */
98
+ readonly message: string;
99
+ /** Max injections per rule per Run. Default 1. */
100
+ readonly maxInjections?: number;
101
+ }
102
+ /** Terminal result of a loop. `messages` is the canonical message sequence
103
+ * this Run produced (ADR 0017): assistant(tool_use) / tool(tool_result) /
104
+ * assistant(text) as separate messages in branch order — never merged into
105
+ * an assistant message. `usage` is the last usage chunk from the model
106
+ * stream; `error` is a redacted reason for failed/stopped outcomes. */
107
+ export interface OmaLoopResult {
108
+ readonly status: "completed" | "failed" | "stopped";
109
+ readonly messages?: readonly Message[];
110
+ readonly usage?: Usage;
111
+ readonly error?: string;
112
+ /** Auto-generated conversation title (first Run only; backend guards). */
113
+ readonly title?: string;
114
+ }
115
+ export interface OmaSession {
116
+ readonly sessionId: string;
117
+ readonly status: "idle" | "running" | "completed" | "failed" | "stopped";
118
+ startLoop(input: CodingLoopInput): Promise<OmaLoopResult>;
119
+ startFollowUp(input: CodingLoopInput): Promise<OmaLoopResult>;
120
+ /** Inject a steer input into the active loop. No Meta, no new Loop: the
121
+ * message is queued and appended at the next safe boundary. */
122
+ steer(input: BackendInputMessage): void;
123
+ stop(): void;
124
+ compact(): Promise<void>;
125
+ onEvent(listener: AgentLoopListener): () => void;
126
+ /** Emit a UI-transient event to all subscribers (for PluginRuntime). */
127
+ emit(event: OmaLoopEvent): void;
128
+ }
129
+ /** One model turn, accumulated purely from the stream: raw outputs
130
+ * before any persistence. */
131
+ /** One delta in a turn, in the order it arrived — the only source that can
132
+ * reconstruct why a reasoning strand was interrupted by a text passage and
133
+ * resumed. Persisting text/thinking as concatenated strings loses this. */
134
+ export type TurnBlock = {
135
+ type: "text";
136
+ text: string;
137
+ } | {
138
+ type: "thinking";
139
+ text: string;
140
+ };
141
+ export declare function createOmaSession(opts: OmaSessionOptions): OmaSession;
142
+ //# sourceMappingURL=agent-loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,KAAK,EACN,MAAM,8BAA8B,CAAC;AAGtC,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,gBAAgB,EAAkB,MAAM,iBAAiB,CAAC;AAQxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIzD,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,mBAAmB,CAAC;AAE1E,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,CAAC;AAUhD;;;0CAG0C;AAC1C,MAA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