memeloop 0.0.1 → 0.1.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 (228) hide show
  1. package/README.md +63 -0
  2. package/dist/browser.cjs +1413 -0
  3. package/dist/browser.cjs.map +1 -0
  4. package/dist/browser.d.cts +3066 -0
  5. package/dist/browser.d.ts +3066 -0
  6. package/dist/browser.js +43 -0
  7. package/dist/chunk-2C6BJZI3.js +382 -0
  8. package/dist/chunk-2C6BJZI3.js.map +1 -0
  9. package/dist/chunk-426CJUZP.js +630 -0
  10. package/dist/chunk-426CJUZP.js.map +1 -0
  11. package/dist/chunk-7ZDTB4VZ.js +63 -0
  12. package/dist/chunk-7ZDTB4VZ.js.map +1 -0
  13. package/dist/chunk-AZFYDWIN.js +98 -0
  14. package/dist/chunk-AZFYDWIN.js.map +1 -0
  15. package/dist/chunk-BGPU4RR7.js +367 -0
  16. package/dist/chunk-BGPU4RR7.js.map +1 -0
  17. package/dist/chunk-CCEFAOSH.js +496 -0
  18. package/dist/chunk-CCEFAOSH.js.map +1 -0
  19. package/dist/chunk-FWSY5HOA.js +63 -0
  20. package/dist/chunk-FWSY5HOA.js.map +1 -0
  21. package/dist/chunk-GYIOMQMY.js +8726 -0
  22. package/dist/chunk-GYIOMQMY.js.map +1 -0
  23. package/dist/chunk-K6P63KD4.js +68 -0
  24. package/dist/chunk-K6P63KD4.js.map +1 -0
  25. package/dist/chunk-KFS2EJT6.js +42 -0
  26. package/dist/chunk-KFS2EJT6.js.map +1 -0
  27. package/dist/chunk-MAJWHAKR.js +3637 -0
  28. package/dist/chunk-MAJWHAKR.js.map +1 -0
  29. package/dist/chunk-MRKY4HGF.js +205 -0
  30. package/dist/chunk-MRKY4HGF.js.map +1 -0
  31. package/dist/chunk-T7FSXWFR.js +2744 -0
  32. package/dist/chunk-T7FSXWFR.js.map +1 -0
  33. package/dist/chunk-VZKQX5PP.js +1 -0
  34. package/dist/chunk-VZKQX5PP.js.map +1 -0
  35. package/dist/chunk-WAI6BODI.js +175 -0
  36. package/dist/chunk-WAI6BODI.js.map +1 -0
  37. package/dist/chunk-YMNXDNDW.js +798 -0
  38. package/dist/chunk-YMNXDNDW.js.map +1 -0
  39. package/dist/conversation.cjs +208 -0
  40. package/dist/conversation.cjs.map +1 -0
  41. package/dist/conversation.d.cts +100 -0
  42. package/dist/conversation.d.ts +100 -0
  43. package/dist/conversation.js +21 -0
  44. package/dist/conversation.js.map +1 -0
  45. package/dist/device-network-portable.cjs +702 -0
  46. package/dist/device-network-portable.cjs.map +1 -0
  47. package/dist/device-network-portable.d.cts +110 -0
  48. package/dist/device-network-portable.d.ts +110 -0
  49. package/dist/device-network-portable.js +53 -0
  50. package/dist/device-network-portable.js.map +1 -0
  51. package/dist/device-network.cjs +906 -0
  52. package/dist/device-network.cjs.map +1 -0
  53. package/dist/device-network.d.cts +6 -0
  54. package/dist/device-network.d.ts +6 -0
  55. package/dist/device-network.js +59 -0
  56. package/dist/device-network.js.map +1 -0
  57. package/dist/fetchProvider-WWnWnQFP.d.ts +91 -0
  58. package/dist/fetchProvider-toTHy5Nu.d.cts +91 -0
  59. package/dist/index.cjs +28051 -5459
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +94 -1320
  62. package/dist/index.d.ts +94 -1320
  63. package/dist/index.js +10616 -2420
  64. package/dist/index.js.map +1 -1
  65. package/dist/interface-IrKBFtL1.d.cts +493 -0
  66. package/dist/interface-IrKBFtL1.d.ts +493 -0
  67. package/dist/llm-providers.cjs +43 -8
  68. package/dist/llm-providers.cjs.map +1 -1
  69. package/dist/llm-providers.d.cts +2 -1
  70. package/dist/llm-providers.d.ts +2 -1
  71. package/dist/llm-providers.js +4 -2
  72. package/dist/llm-providers.js.map +1 -1
  73. package/dist/loop-api.cjs +5227 -2010
  74. package/dist/loop-api.cjs.map +1 -1
  75. package/dist/loop-api.d.cts +11 -5
  76. package/dist/loop-api.d.ts +11 -5
  77. package/dist/loop-api.js +86 -49
  78. package/dist/mobile.cjs +2711 -0
  79. package/dist/mobile.cjs.map +1 -0
  80. package/dist/mobile.d.cts +6 -0
  81. package/dist/mobile.d.ts +6 -0
  82. package/dist/mobile.js +22 -0
  83. package/dist/mobile.js.map +1 -0
  84. package/dist/orchestration-portable-BHB_YrNN.d.ts +2192 -0
  85. package/dist/orchestration-portable-mvYBvGBb.d.cts +2192 -0
  86. package/dist/orchestration-portable.cjs +9553 -0
  87. package/dist/orchestration-portable.cjs.map +1 -0
  88. package/dist/orchestration-portable.d.cts +5 -0
  89. package/dist/orchestration-portable.d.ts +5 -0
  90. package/dist/orchestration-portable.js +290 -0
  91. package/dist/orchestration-portable.js.map +1 -0
  92. package/dist/pairingInvite-BXPWY3aM.d.cts +149 -0
  93. package/dist/pairingInvite-Cuz0wuq9.d.ts +149 -0
  94. package/dist/promptConcat-0WNFTg4l.d.ts +516 -0
  95. package/dist/promptConcat-D6wr5V-V.d.cts +516 -0
  96. package/dist/providerRegistry-Bi6pAvSj.d.ts +86 -0
  97. package/dist/providerRegistry-CPsktuiX.d.cts +86 -0
  98. package/dist/registry-D0kbxksn.d.cts +393 -0
  99. package/dist/registry-DDbvhlhs.d.ts +393 -0
  100. package/dist/remoteClient-B_spK019.d.ts +87 -0
  101. package/dist/remoteClient-CBggnRy3.d.cts +87 -0
  102. package/dist/runtime-PGWR6FIV.js +18 -0
  103. package/dist/runtime-PGWR6FIV.js.map +1 -0
  104. package/dist/scriptDeploymentPipeline-CXJcC82H.d.ts +2464 -0
  105. package/dist/scriptDeploymentPipeline-yG1ZhVVI.d.cts +2464 -0
  106. package/dist/syncCloudDevices-BEqwgrhD.d.ts +49 -0
  107. package/dist/syncCloudDevices-Ds_Kcgrv.d.cts +49 -0
  108. package/dist/types-7pYti-k9.d.cts +255 -0
  109. package/dist/types-CdFVSntj.d.ts +255 -0
  110. package/package.json +110 -35
  111. package/dist/anthropic.cjs +0 -72
  112. package/dist/anthropic.cjs.map +0 -1
  113. package/dist/anthropic.d.cts +0 -21
  114. package/dist/anthropic.d.ts +0 -21
  115. package/dist/anthropic.js +0 -21
  116. package/dist/anthropic.js.map +0 -1
  117. package/dist/azure.cjs +0 -72
  118. package/dist/azure.cjs.map +0 -1
  119. package/dist/azure.d.cts +0 -21
  120. package/dist/azure.d.ts +0 -21
  121. package/dist/azure.js +0 -21
  122. package/dist/azure.js.map +0 -1
  123. package/dist/chunk-3CN7DFBL.js +0 -4894
  124. package/dist/chunk-3CN7DFBL.js.map +0 -1
  125. package/dist/chunk-4AZ4D7U5.js +0 -32
  126. package/dist/chunk-4AZ4D7U5.js.map +0 -1
  127. package/dist/chunk-6ON4XSOV.js +0 -63
  128. package/dist/chunk-6ON4XSOV.js.map +0 -1
  129. package/dist/chunk-DJQNGIXX.js +0 -4793
  130. package/dist/chunk-DJQNGIXX.js.map +0 -1
  131. package/dist/chunk-FKQP6AOQ.js +0 -32
  132. package/dist/chunk-FKQP6AOQ.js.map +0 -1
  133. package/dist/chunk-OVJ7JJBA.js +0 -35
  134. package/dist/chunk-OVJ7JJBA.js.map +0 -1
  135. package/dist/chunk-P4UZ7IXC.js +0 -42
  136. package/dist/chunk-YHJ2AEFR.js +0 -4933
  137. package/dist/chunk-YHJ2AEFR.js.map +0 -1
  138. package/dist/chunk-YVK7RYRO.js +0 -4973
  139. package/dist/chunk-YVK7RYRO.js.map +0 -1
  140. package/dist/code-assistant.json +0 -114
  141. package/dist/cohere.cjs +0 -72
  142. package/dist/cohere.cjs.map +0 -1
  143. package/dist/cohere.d.cts +0 -21
  144. package/dist/cohere.d.ts +0 -21
  145. package/dist/cohere.js +0 -21
  146. package/dist/cohere.js.map +0 -1
  147. package/dist/deepseek.cjs +0 -72
  148. package/dist/deepseek.cjs.map +0 -1
  149. package/dist/deepseek.d.cts +0 -21
  150. package/dist/deepseek.d.ts +0 -21
  151. package/dist/deepseek.js +0 -21
  152. package/dist/deepseek.js.map +0 -1
  153. package/dist/dist-65U7OYRG.js +0 -1257
  154. package/dist/dist-65U7OYRG.js.map +0 -1
  155. package/dist/fetchProvider-Cu4WkU5O.d.cts +0 -819
  156. package/dist/fetchProvider-Cu4WkU5O.d.ts +0 -819
  157. package/dist/frontend-ui-ux.json +0 -105
  158. package/dist/general-assistant.json +0 -95
  159. package/dist/git-master.json +0 -51
  160. package/dist/google-vertex.cjs +0 -72
  161. package/dist/google-vertex.cjs.map +0 -1
  162. package/dist/google-vertex.d.cts +0 -21
  163. package/dist/google-vertex.d.ts +0 -21
  164. package/dist/google-vertex.js +0 -21
  165. package/dist/google-vertex.js.map +0 -1
  166. package/dist/google.cjs +0 -72
  167. package/dist/google.cjs.map +0 -1
  168. package/dist/google.d.cts +0 -21
  169. package/dist/google.d.ts +0 -21
  170. package/dist/google.js +0 -21
  171. package/dist/google.js.map +0 -1
  172. package/dist/groq.cjs +0 -72
  173. package/dist/groq.cjs.map +0 -1
  174. package/dist/groq.d.cts +0 -21
  175. package/dist/groq.d.ts +0 -21
  176. package/dist/groq.js +0 -21
  177. package/dist/groq.js.map +0 -1
  178. package/dist/index.d.mts +0 -3203
  179. package/dist/index.mjs +0 -7064
  180. package/dist/index.mjs.map +0 -1
  181. package/dist/mistral.cjs +0 -72
  182. package/dist/mistral.cjs.map +0 -1
  183. package/dist/mistral.d.cts +0 -21
  184. package/dist/mistral.d.ts +0 -21
  185. package/dist/mistral.js +0 -21
  186. package/dist/mistral.js.map +0 -1
  187. package/dist/multipart-parser-EJCXIUHC.js +0 -372
  188. package/dist/multipart-parser-EJCXIUHC.js.map +0 -1
  189. package/dist/openai.cjs +0 -72
  190. package/dist/openai.cjs.map +0 -1
  191. package/dist/openai.d.cts +0 -21
  192. package/dist/openai.d.ts +0 -21
  193. package/dist/openai.js +0 -21
  194. package/dist/openai.js.map +0 -1
  195. package/dist/perplexity.cjs +0 -72
  196. package/dist/perplexity.cjs.map +0 -1
  197. package/dist/perplexity.d.cts +0 -21
  198. package/dist/perplexity.d.ts +0 -21
  199. package/dist/perplexity.js +0 -21
  200. package/dist/perplexity.js.map +0 -1
  201. package/dist/playwright.json +0 -52
  202. package/dist/promptConcat-BJdazTg5.d.cts +0 -1832
  203. package/dist/promptConcat-BJdazTg5.d.ts +0 -1832
  204. package/dist/promptConcat-CAkpni_8.d.cts +0 -1834
  205. package/dist/promptConcat-CAkpni_8.d.ts +0 -1834
  206. package/dist/promptConcat-CfH5-GAE.d.cts +0 -1036
  207. package/dist/promptConcat-ChcAZOOL.d.ts +0 -1036
  208. package/dist/promptConcat-G5TnJVRy.d.cts +0 -1800
  209. package/dist/promptConcat-G5TnJVRy.d.ts +0 -1800
  210. package/dist/promptConcat-L72eowzp.d.ts +0 -1090
  211. package/dist/promptConcat-eLHdN7K8.d.cts +0 -1090
  212. package/dist/src-VTSXKG72.js +0 -1409
  213. package/dist/src-VTSXKG72.js.map +0 -1
  214. package/dist/togetherai.cjs +0 -72
  215. package/dist/togetherai.cjs.map +0 -1
  216. package/dist/togetherai.d.cts +0 -21
  217. package/dist/togetherai.d.ts +0 -21
  218. package/dist/togetherai.js +0 -21
  219. package/dist/togetherai.js.map +0 -1
  220. package/dist/types-B0Jm2l38.d.cts +0 -767
  221. package/dist/types-B0Jm2l38.d.ts +0 -767
  222. package/dist/xai.cjs +0 -72
  223. package/dist/xai.cjs.map +0 -1
  224. package/dist/xai.d.cts +0 -21
  225. package/dist/xai.d.ts +0 -21
  226. package/dist/xai.js +0 -21
  227. package/dist/xai.js.map +0 -1
  228. /package/dist/{chunk-P4UZ7IXC.js.map → browser.js.map} +0 -0
@@ -1,1036 +0,0 @@
1
- import { A as AgentDefinition, y as AgentInstanceLatestStatus, b as AgentFrameworkConfig, x as AgentInstanceModel, R as ChatRole, a as ChatMessage, a9 as LoopProfileScriptReference, F as AgentLoopScriptPolicy, H as AgentLoopStep, j as AgentLoopInput, a6 as LoopProfile, E as AgentLoopRuntime, k as AgentLoopGenerator, B as AgentLoopDefinition, a1 as ILLMProvider, i as AgentFrameworkContext, z as AgentInstanceState, a5 as LoopPlugin, a7 as LoopProfilePluginEntry, P as PromptConcatTool, ad as PromptNode, J as AgentPromptDescription } from './fetchProvider-Cu4WkU5O.cjs';
2
-
3
- declare const BUILTIN_AGENT_AGENT_LOOP_QUALITY_GATE_SCRIPT_ID = "builtin:agent-agent-loop/quality-gate";
4
- declare const builtinAgentAgentLoopSources: Readonly<Record<string, string>>;
5
- declare function getBuiltinAgentAgentLoopSource(id: string): string | undefined;
6
-
7
- /**
8
- * Domain factories for creating canonical ChatMessage and AgentInstance objects.
9
- *
10
- * These factories ensure that every host (Desktop, Mobile, CLI, Cloud)
11
- * constructs messages and instances with the same required fields,
12
- * default values, and clock behavior.
13
- *
14
- * Hosts that need a different originNodeId, message ID scheme, or lamport
15
- * clock source should pass those values explicitly rather than creating
16
- * their own factory.
17
- */
18
-
19
- /**
20
- * Create a canonical ChatMessage with required defaults.
21
- *
22
- * @param input.messageId - Unique message identifier. Use nanoid or equivalent.
23
- * @param input.conversationId - The conversation/agent-instance this message belongs to.
24
- * @param input.role - Message role (user, assistant, tool, agent, error).
25
- * @param input.content - Message text content.
26
- * @param input.originNodeId - Node that originated this message. Core default is "unknown";
27
- * hosts should pass their own identifier (e.g. "tidgi-desktop", "memeloop-cli").
28
- * @param input.contentType - MIME type override (default "text/plain").
29
- * @param input.metadata - Optional metadata map.
30
- * @param input.duration - Processing duration in ms.
31
- * @param input.lamportClock - Lamport clock value. Defaults to `Date.now()`.
32
- * @param input.toolCalls - Tool calls associated with assistant messages.
33
- * @param input.reasoning_content - Reasoning/thinking content.
34
- * @param input.hidden - Whether the message is hidden from the UI.
35
- * @param input.detailRef - Reference to large tool output stored elsewhere.
36
- */
37
- declare function createChatMessage(input: {
38
- messageId: string;
39
- conversationId: string;
40
- role: ChatRole;
41
- content: string;
42
- originNodeId?: string;
43
- contentType?: string;
44
- metadata?: Record<string, unknown>;
45
- duration?: number | null;
46
- lamportClock?: number;
47
- toolCalls?: ChatMessage['toolCalls'];
48
- reasoning_content?: string;
49
- hidden?: boolean;
50
- attachments?: ChatMessage['attachments'];
51
- detailRef?: ChatMessage['detailRef'];
52
- }): ChatMessage;
53
- /**
54
- * Create an AgentInstance from an AgentDefinition.
55
- *
56
- * The returned instance has an empty message list, a default "completed"
57
- * status, and copies all definition-level fields as instance defaults.
58
- *
59
- * @param definition - The AgentDefinition to base the instance on.
60
- * @param overrides - Optional overrides for instance-specific fields:
61
- * - `id`: Instance ID (default: nanoid-equivalent, must be provided by host)
62
- * - `name`: Display name (default: definition.name)
63
- * - `status`: Initial status
64
- * - `volatile`: Whether the instance is ephemeral
65
- * - `closed`: Whether closed on creation
66
- * - `isDelegatedAgentRun`, `parentAgentRunId`: Delegated agent relationship
67
- * - `agentFrameworkConfig`: Per-instance framework config override
68
- */
69
- declare function createAgentInstanceFromDefinition(definition: AgentDefinition, overrides: {
70
- id: string;
71
- name?: string;
72
- status?: AgentInstanceLatestStatus;
73
- volatile?: boolean;
74
- closed?: boolean;
75
- isDelegatedAgentRun?: boolean;
76
- parentAgentRunId?: string;
77
- agentFrameworkConfig?: AgentFrameworkConfig;
78
- }): AgentInstanceModel;
79
-
80
- type AgentLoopScriptReference = string | LoopProfileScriptReference;
81
-
82
- type LoadAgentAgentLoopScriptOptions = AgentLoopScriptPolicy;
83
- type AgentAgentLoopScriptReference = AgentLoopScriptReference;
84
- declare function loadAgentAgentLoopScript(scriptReference: AgentAgentLoopScriptReference, options?: LoadAgentAgentLoopScriptOptions): Promise<AgentAgentLoopScript>;
85
-
86
- /**
87
- * AgentAgent_Loop — a loop that orchestrates child agents.
88
- *
89
- * This loop does NOT call the LLM directly. Instead it coordinates child agents:
90
- * - running a child agent and feeding its result to another child agent (review / verify)
91
- * - splitting work across multiple parallel child agents
92
- * - looping back to a child agent with feedback when a reviewer rejects the output
93
- *
94
- * The loop script (.mjs) holds the orchestration logic. This file provides the
95
- * runtime that invokes the script and manages child agent runs.
96
- */
97
-
98
- /**
99
- * Typed API passed to a AgentAgent `.mjs` script.
100
- *
101
- * The API is intentionally primitive: scripts decide the workflow shape, role
102
- * names, approval rules, retry limits, and delivery gates. This runtime only
103
- * handles child-agent execution, progress events, cancellation, state, and
104
- * checkpoints.
105
- */
106
- interface AgentAgentLoopScriptArguments {
107
- /** The parent turn input. `input.message` is the user's original goal. */
108
- input: AgentLoopInput;
109
- /** Host/runtime context for advanced integrations. Prefer the typed helpers below when possible. */
110
- context: AgentAgentLoopContext;
111
- /** Active profile. Scripts may define their own workflow-specific metadata keys here. */
112
- profile?: LoopProfile;
113
- /** Normalized worker agents read from `context.agents` or `profile.metadata.agents`. */
114
- agents: AgentAgentDescriptor[];
115
- /**
116
- * Read raw agent entries from `profile.metadata[key]`; defaults to `agents`.
117
- * This is deliberately generic so scripts can choose names like `critics`,
118
- * `builders`, `verifiers`, or any other workflow-specific role.
119
- */
120
- getAgentEntries: (key?: string) => AgentAgentConfigEntry[];
121
- /** Low-level runtime hooks. Prefer `state`, `checkpoint`, `emit`, and run helpers first. */
122
- runtime?: Partial<AgentLoopRuntime>;
123
- /** Run one child agent and collect all yielded steps into a text result. */
124
- runAgent: (input: AgentAgentRunAgentInput) => Promise<AgentAgentRunAgentResult>;
125
- /** Run child agents concurrently. Use `runSequential` when order matters. */
126
- runAgents: (inputs: AgentAgentRunAgentInput[]) => Promise<AgentAgentRunAgentResult[]>;
127
- /** Run a batch of agents in order, aggregating successful output and failures. */
128
- runSequential: (input?: AgentAgentBatchRunInput) => Promise<AgentAgentBatchRunResult>;
129
- /** Run a batch of agents concurrently, aggregating successful output and failures. */
130
- runParallel: (input?: AgentAgentBatchRunInput) => Promise<AgentAgentBatchRunResult>;
131
- /** Format a batch result for final delivery or an intermediate report. */
132
- formatAgentResults: (result: AgentAgentBatchRunResult, options?: AgentAgentFormatResultsOptions) => string;
133
- /** Emit a formatted batch result as the parent loop's final/user-visible message. */
134
- finishAgentResults: (result: AgentAgentBatchRunResult, options?: AgentAgentFormatResultsOptions) => void;
135
- /** Emit a raw loop step upstream. Use sparingly; helpers already emit progress. */
136
- emit: (step: AgentLoopStep) => void;
137
- /** Emit a user-visible message or step and end the script's work. */
138
- finish: (message: string | AgentLoopStep) => void;
139
- /** True when the host cancelled this parent run. Long-running scripts should check this between phases. */
140
- isCancelled: () => boolean;
141
- /** Write an observability event through the host runtime logger. */
142
- log: (event: string, data?: Record<string, unknown>) => void;
143
- /** Per-run persistent state scoped by the host runtime. */
144
- state: AgentLoopRuntime['state'];
145
- /** Record a resumable milestone for long workflows. */
146
- checkpoint: AgentLoopRuntime['checkpoint'];
147
- }
148
- type AgentAgentScriptContext = AgentAgentLoopScriptArguments;
149
- type AgentAgentContext = AgentAgentScriptContext;
150
- interface AgentAgentDescriptor {
151
- /** Child profile id to run. */
152
- profileId: string;
153
- /** Prompt override for this child run. Defaults to the parent input message. */
154
- prompt?: string;
155
- /** Conversation id override. Defaults to `${parent}:child:${index}` for batch helpers. */
156
- conversationId?: string;
157
- /** Optional human-readable role label, e.g. "implementer" or "reviewer". */
158
- label?: string;
159
- [key: string]: unknown;
160
- }
161
- type AgentAgentConfigEntry = string | ({
162
- profileId?: string;
163
- profile?: string;
164
- prompt?: string;
165
- conversationId?: string;
166
- label?: string;
167
- } & Record<string, unknown>);
168
- interface AgentAgentRunAgentInput {
169
- /** Child profile id. `profile` is accepted as an ergonomic alias for scripts. */
170
- profileId?: string;
171
- profile?: string;
172
- /** Defaults to the parent input message. */
173
- prompt?: string;
174
- conversationId?: string;
175
- label?: string;
176
- }
177
- interface AgentAgentRunAgentResult {
178
- profileId: string;
179
- conversationId: string;
180
- steps: AgentLoopStep[];
181
- text: string;
182
- }
183
- interface AgentAgentRunAgentFailure {
184
- profileId: string;
185
- conversationId?: string;
186
- error: string;
187
- }
188
- interface AgentAgentBatchRunInput {
189
- /** Agents to run. Defaults to `ctx.agents`. */
190
- agents?: AgentAgentConfigEntry[];
191
- /** Prompt shared by every agent in this batch. Defaults to the parent input message. */
192
- prompt?: string;
193
- /** When false, the first child failure rejects the batch. Defaults to true. */
194
- continueOnError?: boolean;
195
- }
196
- interface AgentAgentBatchRunResult {
197
- results: AgentAgentRunAgentResult[];
198
- failures: AgentAgentRunAgentFailure[];
199
- text: string;
200
- }
201
- interface AgentAgentFormatResultsOptions {
202
- emptyMessage?: string;
203
- failureHeader?: string;
204
- includeFailureSection?: boolean;
205
- }
206
- type AgentAgentLoopScriptResult = AgentLoopGenerator | AgentLoopStep | AgentLoopStep[] | string | undefined;
207
- type AgentAgentLoopScript = (scriptArguments: AgentAgentLoopScriptArguments) => AgentAgentLoopScriptResult | Promise<AgentAgentLoopScriptResult>;
208
- interface AgentAgentLoopContext {
209
- [key: string]: unknown;
210
- profile?: LoopProfile;
211
- runtime?: Partial<AgentLoopRuntime>;
212
- agents?: AgentAgentConfigEntry[];
213
- script?: AgentAgentLoopScript;
214
- loadScript?: (script: AgentAgentLoopScriptReference, context: AgentAgentLoopContext) => AgentAgentLoopScript | Promise<AgentAgentLoopScript>;
215
- scriptPolicy?: LoadAgentAgentLoopScriptOptions;
216
- }
217
- /**
218
- * Create the AgentAgent_Loop definition and register it with the loop registry.
219
- */
220
- declare function createAgentAgentLoopDefinition(): AgentLoopDefinition;
221
- /** Export loop id for consumers. */
222
- declare function getAgentAgentLoopId(): string;
223
-
224
- declare const BUILTIN_AGENT_TOOL_LOOP_DEFAULT_SCRIPT_ID = "builtin:agent-tool-loop/default";
225
- declare const builtinAgentToolLoopSources: Readonly<Record<string, string>>;
226
- declare function getBuiltinAgentToolLoopSource(id: string): string | undefined;
227
-
228
- interface CompactionOptions {
229
- /** Maximum token count to aim for after compaction (estimated by char count / 3.5). Default: 0 (no limit). */
230
- maxTokens?: number;
231
- /** Number of recent message turns (user+assistant pairs) to preserve. Default: 4. */
232
- recentTurnsToKeep?: number;
233
- /** Whether to attempt LLM summarization. Falls back to truncation if LLM unavailable or fails. Default: true. */
234
- useLlmSummary?: boolean;
235
- /** Optional LLM provider for summarization. */
236
- llmProvider?: ILLMProvider;
237
- }
238
- interface CompactionResult {
239
- /** Compacted messages (summary + recent turns). */
240
- messages: ChatMessage[];
241
- /** True if compaction reduced the message count. */
242
- compacted: boolean;
243
- /** Number of messages dropped. */
244
- droppedCount: number;
245
- /** Summary text generated or fallback notice. */
246
- summaryText: string;
247
- }
248
- /**
249
- * Deterministic compaction: keeps recent N turns and replaces older messages
250
- * with a single summary message.
251
- */
252
- declare function compactMessages(messages: ChatMessage[], options?: Omit<CompactionOptions, 'llmProvider' | 'useLlmSummary'>): CompactionResult;
253
- /**
254
- * Checks whether compaction is needed based on message count threshold.
255
- * @returns true if message count exceeds threshold (default 50).
256
- */
257
- declare function shouldCompact(messages: ChatMessage[], threshold?: number): boolean;
258
- /**
259
- * Auto-compact: estimates token usage, and if it exceeds maxTokens,
260
- * performs compaction to keep the context within bounds.
261
- *
262
- * Uses the LLM provider for summarization if available, falling back to
263
- * simple truncation + turn counting.
264
- */
265
- declare function autoCompact(messages: ChatMessage[], options?: CompactionOptions): Promise<CompactionResult>;
266
-
267
- /**
268
- * Layered permission system types.
269
- *
270
- * Permissions are resolved by merging rule sets from multiple layers
271
- * (default → agent → user → session), where later layers override earlier ones.
272
- */
273
- /** Permission action for a tool invocation. */
274
- type PermissionAction = 'allow' | 'deny' | 'ask';
275
- /** A single permission rule: matches a tool name pattern to an action. */
276
- interface PermissionRule {
277
- /** Wildcard-capable pattern, e.g. `"file.*"`, `"shell(rm)"`, `"*"`. */
278
- toolPattern: string;
279
- action: PermissionAction;
280
- }
281
- /** A set of permission rules belonging to a specific source/layer. */
282
- interface PermissionSet {
283
- rules: PermissionRule[];
284
- /** Human-readable source identifier for debugging (e.g. "default", "agent:cli-buddy", "user"). */
285
- source: string;
286
- }
287
- /**
288
- * Result of merging multiple `PermissionSet` layers.
289
- * Each array contains flattened, deduplicated tool patterns for that action.
290
- */
291
- interface MergedPermissions {
292
- allow: string[];
293
- deny: string[];
294
- ask: string[];
295
- }
296
-
297
- /**
298
- * Hook system types for memeloop.
299
- * Hooks are lifecycle callbacks that execute before/after key events in the agent loop.
300
- */
301
-
302
- /** Context passed to all hook handlers. */
303
- type HookContext = AgentFrameworkContext;
304
- /** Result returned by a hook handler. */
305
- interface HookResult {
306
- /** Whether to allow the action to proceed (false = block/deny) */
307
- allowed: boolean;
308
- /** Optional message explaining why the action was blocked */
309
- reason?: string;
310
- /** Optional data modified by the hook (e.g., transformed tool args) */
311
- modified?: Record<string, unknown>;
312
- /** Optional tool permission action. Interpreted by PreToolUse callers. */
313
- permissionAction?: PermissionAction;
314
- }
315
- /** Signature of a hook handler function. */
316
- type HookHandler = (context: HookContext, data: Record<string, unknown>) => Promise<HookResult>;
317
- /** Enum of supported hook event types. */
318
- type HookType = 'PreToolUse' | 'PostToolUse' | 'UserPromptSubmit' | 'ContextCompaction' | 'AgentStart' | 'AgentStop';
319
- /** Data passed to PreToolUse hooks. */
320
- interface PreToolUseData extends Record<string, unknown> {
321
- toolId: string;
322
- parameters: Record<string, unknown>;
323
- conversationId: string;
324
- }
325
- /** Data passed to PostToolUse hooks. */
326
- interface PostToolUseData extends Record<string, unknown> {
327
- toolId: string;
328
- parameters: Record<string, unknown>;
329
- result: string;
330
- isError: boolean;
331
- conversationId: string;
332
- }
333
- /** Data passed to UserPromptSubmit hooks. */
334
- interface UserPromptSubmitData extends Record<string, unknown> {
335
- message: string;
336
- conversationId: string;
337
- }
338
- /** Data passed to ContextCompaction hooks before built-in history compaction. */
339
- interface ContextCompactionData extends Record<string, unknown> {
340
- conversationId: string;
341
- iteration: number;
342
- history: ChatMessage[];
343
- autoCompact?: AgentFrameworkContext['agentToolLoop'] extends infer Options ? Options extends {
344
- autoCompact?: infer AutoCompact;
345
- } ? AutoCompact : never : never;
346
- contextCompaction?: AgentFrameworkContext['agentToolLoop'] extends infer Options ? Options extends {
347
- contextCompaction?: infer ContextCompaction;
348
- } ? ContextCompaction : never : never;
349
- }
350
- /** Data passed to AgentStart hooks. */
351
- interface AgentStartData extends Record<string, unknown> {
352
- conversationId: string;
353
- definitionId?: string;
354
- }
355
- /** Data passed to AgentStop hooks. */
356
- interface AgentStopData extends Record<string, unknown> {
357
- conversationId: string;
358
- reason: 'completed' | 'cancelled' | 'max-iterations' | 'error';
359
- }
360
-
361
- type LoadAgentToolLoopScriptOptions$1 = AgentLoopScriptPolicy;
362
- type AgentToolLoopScriptReference$1 = AgentLoopScriptReference;
363
- interface AgentToolLoopContext extends AgentFrameworkContext {
364
- profile?: LoopProfile;
365
- runtime?: Partial<AgentLoopRuntime>;
366
- script?: AgentToolLoopScript;
367
- loadScript?: (script: AgentToolLoopScriptReference$1, context: AgentToolLoopContext) => AgentToolLoopScript | Promise<AgentToolLoopScript>;
368
- scriptPolicy?: LoadAgentToolLoopScriptOptions$1;
369
- }
370
- interface AgentToolLoopState {
371
- iteration: number;
372
- maxIterations: number;
373
- recentToolCalls: string[];
374
- agentStarted: boolean;
375
- agentStopped: boolean;
376
- stopReason?: AgentStopData['reason'];
377
- }
378
- interface AgentToolLoopTurnStartResult {
379
- action: 'continue' | 'stop';
380
- step?: AgentLoopStep;
381
- }
382
- interface AgentToolLoopIterationResult {
383
- action: 'continue' | 'stop';
384
- reason?: AgentStopData['reason'];
385
- }
386
- type AgentToolLoopIterationGenerator = AsyncGenerator<AgentLoopStep, AgentToolLoopIterationResult, void>;
387
- interface AgentToolLoopScriptContext {
388
- /** The host turn input. `input.message` is the user prompt for this turn. */
389
- input: AgentLoopInput;
390
- /** Full host context for advanced integrations. Prefer the primitive helpers below. */
391
- context: AgentToolLoopContext;
392
- /** Active profile selected by the registry/runtime. */
393
- profile?: LoopProfile;
394
- /** Create mutable loop state for one turn. Scripts can store it in checkpoints if they implement resume. */
395
- createState: () => AgentToolLoopState;
396
- /** Persist the user turn and run pre-agent hooks. Returns a blocking step when a hook stops the turn. */
397
- startTurn: (state: AgentToolLoopState) => Promise<AgentToolLoopTurnStartResult>;
398
- /** Run exactly one LLM/tool iteration. The script owns the surrounding loop policy. */
399
- runIteration: (state: AgentToolLoopState) => AgentToolLoopIterationGenerator;
400
- /** Run AgentStop hooks once. Pass a reason when stopping because of an error outside `runIteration`. */
401
- stopTurn: (state: AgentToolLoopState, reason?: AgentStopData['reason']) => Promise<void>;
402
- /** Emit a raw loop step upstream. */
403
- emit: (step: AgentLoopStep) => void;
404
- /** Emit a user-visible message or step. */
405
- finish: (message: string | AgentLoopStep) => void;
406
- /** True when host cancellation has been requested for this conversation. */
407
- isCancelled: () => boolean;
408
- /** Write an observability event through the runtime and host logger. */
409
- log: (event: string, data?: Record<string, unknown>) => void;
410
- }
411
- type AgentToolLoopScriptResult = AgentLoopGenerator | AgentLoopStep | AgentLoopStep[] | string | undefined;
412
- type AgentToolLoopScript = (scriptContext: AgentToolLoopScriptContext) => AgentToolLoopScriptResult | Promise<AgentToolLoopScriptResult>;
413
-
414
- declare function createAgentToolLoopRunner(context: AgentFrameworkContext): (input: AgentLoopInput) => AgentLoopGenerator;
415
- declare function createAgentToolLoopDefinition(name?: string): AgentLoopDefinition;
416
-
417
- /**
418
- * AgentToolLoop runner — convenience API for driving a full loop turn.
419
- */
420
-
421
- interface RunAgentToolLoopTurnCallbacks {
422
- onStep?: (step: AgentLoopStep) => void | Promise<void>;
423
- onProgress?: (status: string, data: Record<string, unknown>, step: AgentLoopStep) => void | Promise<void>;
424
- agentToolLoop?: (input: AgentLoopInput) => AgentLoopGenerator;
425
- }
426
- interface RunAgentToolLoopTurnResult {
427
- state: AgentInstanceState;
428
- stepCount: number;
429
- }
430
- declare function resolveAgentToolLoopTerminalState(step: AgentLoopStep, current: AgentInstanceState): AgentInstanceState;
431
- declare function runAgentToolLoopTurn(context: AgentFrameworkContext, input: AgentLoopInput, callbacks?: RunAgentToolLoopTurnCallbacks): Promise<RunAgentToolLoopTurnResult>;
432
-
433
- type LoadAgentToolLoopScriptOptions = AgentLoopScriptPolicy;
434
- type AgentToolLoopScriptReference = AgentLoopScriptReference;
435
- declare function loadAgentToolLoopScript(scriptReference: AgentToolLoopScriptReference, options?: LoadAgentToolLoopScriptOptions): Promise<AgentToolLoopScript>;
436
-
437
- /**
438
- * Built-in loop registrations — installed at startup so getLoopRegistry().createRunner('agent-tool-loop') works.
439
- *
440
- * This module allows hosts to skip manual registerLoop() for the built-in loop types.
441
- * Hosts can still override by calling registerLoop() with the same id after.
442
- */
443
- declare const AGENT_TOOL_LOOP_ID = "agent-tool-loop";
444
- declare const AGENT_AGENT_LOOP_ID: string;
445
- /**
446
- * Register the default built-in loops (agent-tool-loop and agent-agent-loop) with the loop registry.
447
- * Safe to call multiple times — skips already-registered loops.
448
- */
449
- declare function registerBuiltinLoops(): void;
450
-
451
- /**
452
- * Builtin tool plugins — registers core tools as LoopPlugin entries.
453
- *
454
- * Each tool is a separate LoopPlugin that can be overridden by user/host plugins
455
- * with the same id. The plugin.install callback calls the tool registry to
456
- * register the tool implementation.
457
- *
458
- * These are registered in the loop registry at startup and loaded by
459
- * `registerBuiltinTools` via plugin discovery.
460
- */
461
-
462
- declare const PLUGIN_MCP_CLIENT = "builtin:mcp-client";
463
- declare const PLUGIN_MCP_FORWARD = "builtin:mcp-forward";
464
- declare const PLUGIN_SPAWN_AGENT = "builtin:spawn-agent";
465
- declare const PLUGIN_REMOTE_AGENT = "builtin:remote-agent";
466
- declare const PLUGIN_ASK_QUESTION = "builtin:ask-question";
467
- declare const PLUGIN_TODO_WRITE = "builtin:todo-write";
468
- declare const PLUGIN_ASK_USER_QUESTION = "builtin:ask-user-question";
469
- declare const PLUGIN_TASK = "builtin:task";
470
- declare const BUILTIN_TOOL_PLUGIN_IDS: readonly ["builtin:mcp-client", "builtin:mcp-forward", "builtin:spawn-agent", "builtin:remote-agent", "builtin:ask-question", "builtin:todo-write", "builtin:ask-user-question", "builtin:task"];
471
- declare function getBuiltinToolPlugins(): LoopPlugin[];
472
- /** Register all builtin tool plugins with the loop registry. */
473
- declare function registerBuiltinToolPlugins(): void;
474
-
475
- /**
476
- * Agent loop registry.
477
- *
478
- * Discovers, registers, and resolves loop types, loop profiles, and loop plugins.
479
- * Core does NOT hard-import any loop implementation; all are registered by host or plugin.
480
- */
481
-
482
- type LoopPluginSelection = string | LoopProfilePluginEntry;
483
- declare class LoopRegistryImpl {
484
- private readonly loops;
485
- private readonly profiles;
486
- private readonly plugins;
487
- registerLoop(definition: AgentLoopDefinition): void;
488
- getLoop(id: string): AgentLoopDefinition | undefined;
489
- listLoops(): AgentLoopDefinition[];
490
- registerProfile(profile: LoopProfile): void;
491
- getProfile(id: string): LoopProfile | undefined;
492
- listProfiles(): LoopProfile[];
493
- registerPlugin(plugin: LoopPlugin): void;
494
- getPlugin(id: string): LoopPlugin | undefined;
495
- listPlugins(): LoopPlugin[];
496
- installPluginsForLoop(loopId: string, target: {
497
- [key: string]: unknown;
498
- }, selected?: LoopPluginSelection[]): void;
499
- installPluginsForProfile(profile: LoopProfile, target: {
500
- [key: string]: unknown;
501
- }): void;
502
- createRunnerForProfile(profile: LoopProfile, context?: {
503
- [key: string]: unknown;
504
- }): ((input: AgentLoopInput) => AgentLoopGenerator) | null;
505
- createRunner(loopId: string, context?: {
506
- [key: string]: unknown;
507
- }): ((input: AgentLoopInput) => AgentLoopGenerator) | null;
508
- reset(): void;
509
- }
510
- declare function getLoopRegistry(): LoopRegistryImpl;
511
- declare function resetLoopRegistry(): void;
512
-
513
- interface TokenTrackerConfig {
514
- /** Maximum context window in tokens (default: 200000) */
515
- contextWindow?: number;
516
- /** Trigger compaction when usage exceeds this fraction (default: 0.90) */
517
- compactionThreshold?: number;
518
- /** Buffer tokens reserved for output (default: 16000) */
519
- outputBuffer?: number;
520
- }
521
- interface TokenUsage {
522
- promptTokens: number;
523
- completionTokens: number;
524
- totalTokens: number;
525
- contextWindow: number;
526
- usagePercent: number;
527
- shouldCompact: boolean;
528
- }
529
- /**
530
- * Tracks token usage and decides when to trigger auto-compaction.
531
- */
532
- declare class TokenTracker {
533
- private promptTokens;
534
- private completionTokens;
535
- private readonly contextWindow;
536
- private readonly compactionThreshold;
537
- private readonly outputBuffer;
538
- private compacting;
539
- private consecutiveCompactionFailures;
540
- private maxConsecutiveFailures;
541
- constructor(config?: TokenTrackerConfig);
542
- /** Record token usage from an LLM response */
543
- recordUsage(promptTokens: number, completionTokens: number): void;
544
- /** Manually set the prompt token count (e.g., from estimation) */
545
- setPromptTokens(tokens: number): void;
546
- /** Get current usage */
547
- getUsage(): TokenUsage;
548
- /** Check if auto-compaction should be triggered */
549
- shouldTriggerCompaction(): boolean;
550
- /** Mark that compaction is starting */
551
- markCompactionStart(): void;
552
- /** Mark that compaction succeeded — reset token counts */
553
- markCompactionSuccess(estimatedPostTokens: number): void;
554
- /** Mark that compaction failed */
555
- markCompactionFailure(): void;
556
- /** Reset all counters */
557
- reset(): void;
558
- /** Get a human-readable summary */
559
- formatUsage(): string;
560
- }
561
-
562
- interface CreateAgentOptions {
563
- definitionId: string;
564
- initialMessage?: string;
565
- }
566
- interface SendMessageOptions {
567
- conversationId: string;
568
- message: string;
569
- definitionId?: string;
570
- userMessage?: AgentLoopInput['userMessage'];
571
- resumeSession?: ChatMessage[];
572
- }
573
- interface MemeLoopRuntime {
574
- createAgent(options: CreateAgentOptions): Promise<{
575
- conversationId: string;
576
- }>;
577
- sendMessage(options: SendMessageOptions): Promise<void>;
578
- cancelAgent(conversationId: string): Promise<void>;
579
- subscribeToUpdates(conversationId: string, listener: (update: unknown) => void): () => void;
580
- }
581
- interface CreateAgentLoopRunnerOptions {
582
- definitionId: string;
583
- conversationId?: string;
584
- }
585
- declare function createAgentLoopRunner(context: AgentFrameworkContext, options: CreateAgentLoopRunnerOptions): Promise<((input: AgentLoopInput) => AgentLoopGenerator) | null>;
586
- declare function createMemeLoopRuntime(context: AgentFrameworkContext): MemeLoopRuntime;
587
-
588
- /**
589
- * Built-in Loop Profiles.
590
- *
591
- * Each profile defines which agent loop to run, which .mjs script to load,
592
- * which prompts, plugins, and hook plugins to enable.
593
- *
594
- * Replaces the old `src/prompt/loadBuiltins.ts`.
595
- */
596
-
597
- /** Get all built-in Loop Profiles. */
598
- declare function getBuiltinLoopProfiles(): LoopProfile[];
599
- /** Get a built-in Loop Profile by id. */
600
- declare function getBuiltinLoopProfile(id: string): LoopProfile | undefined;
601
- /** Register bundled profiles with the global loop registry. */
602
- declare function registerBuiltinLoopProfiles(): void;
603
-
604
- /**
605
- * Extended agent definition used by the agent profile registry.
606
- * Wraps the protocol-level AgentDefinition with additional runtime metadata.
607
- */
608
- interface AgentProfile {
609
- /** Unique ID for this agent (matches protocol id convention like "memeloop:build") */
610
- id: string;
611
- /** Display name */
612
- name: string;
613
- /** Agent type / role */
614
- type: AgentProfileType;
615
- /** System prompt / instructions for the agent */
616
- prompt: string;
617
- /** Tool permission rules (mutually exclusive with permissive defaults) */
618
- permissions: ToolPermissionRules;
619
- /** Optional model override (provider/model string) */
620
- model?: string;
621
- /** Underlying protocol-compatible definition for framework integration */
622
- protocolDef: AgentDefinition;
623
- }
624
- type AgentProfileType = 'build' | 'plan' | 'explore' | 'oracle' | 'librarian';
625
- interface ToolPermissionRules {
626
- /** Default action for tools not matching any rule */
627
- default: 'allow' | 'ask' | 'deny';
628
- /** Per-tool or wildcard rules */
629
- rules: Array<{
630
- pattern: string;
631
- action: 'allow' | 'ask' | 'deny';
632
- }>;
633
- }
634
- /**
635
- * Build agent: full access, default model.
636
- * Primary agent for executing tasks, writing code, running commands.
637
- */
638
- declare const buildAgent: AgentProfile;
639
- /**
640
- * Plan agent: read-only, denies file edits and terminal execution.
641
- * Used for high-level planning and task decomposition.
642
- */
643
- declare const planAgent: AgentProfile;
644
- /**
645
- * Explore agent: read + search tools only.
646
- * Fast search and codebase exploration without modification.
647
- */
648
- declare const exploreAgent: AgentProfile;
649
- /**
650
- * Oracle agent: read-only, for architecture consultation and code review.
651
- */
652
- declare const oracleAgent: AgentProfile;
653
- /**
654
- * Librarian agent: read + web search tools only.
655
- * External documentation lookup and context gathering.
656
- */
657
- declare const librarianAgent: AgentProfile;
658
- /** Built-in agent profiles used by the task delegation tool. */
659
- declare const BUILTIN_AGENT_PROFILES: AgentProfile[];
660
-
661
- /**
662
- * Registry for agent profiles used by task delegation.
663
- * Pre-seeded with built-in profiles (build, plan, explore, oracle, librarian).
664
- */
665
- declare class AgentProfileRegistry {
666
- private readonly profiles;
667
- constructor();
668
- /** Seed the registry with built-in agent profiles. */
669
- private seedDefaults;
670
- /**
671
- * Register a new agent profile or override an existing one.
672
- * Throws if the profile is invalid.
673
- */
674
- registerAgentProfile(profile: AgentProfile): void;
675
- /**
676
- * Get an agent profile by ID.
677
- * Returns undefined if not found.
678
- */
679
- getAgentProfile(id: string): AgentProfile | undefined;
680
- /**
681
- * List all registered agent profiles.
682
- */
683
- listAgentProfiles(): AgentProfile[];
684
- /**
685
- * List agent profiles filtered by type.
686
- */
687
- listAgentProfilesByType(type: AgentProfileType): AgentProfile[];
688
- /**
689
- * Remove an agent profile by ID.
690
- */
691
- unregisterAgentProfile(id: string): boolean;
692
- /**
693
- * Reset the registry to only built-in defaults.
694
- */
695
- reset(): void;
696
- }
697
- declare function getAgentProfileRegistry(): AgentProfileRegistry;
698
- declare function resetAgentProfileRegistry(): void;
699
-
700
- /**
701
- * Task category system for routing tasks to appropriate agent configurations.
702
- * Each category maps to a model, temperature, and description for delegation decisions.
703
- */
704
- type TaskCategory = 'visual-engineering' | 'ultrabrain' | 'artistry' | 'quick' | 'unspecified-low' | 'unspecified-high' | 'writing';
705
- interface CategoryConfig {
706
- /** Model identifier (e.g., "default", "gpt-4o", "claude-opus") */
707
- model: string;
708
- /** LLM temperature (0.0 = deterministic, 1.0 = creative) */
709
- temperature: number;
710
- /** Human-readable description of the category's purpose */
711
- description: string;
712
- }
713
- /**
714
- * Get the configuration for a task category.
715
- * @throws {Error} if the category is unknown
716
- */
717
- declare function getCategoryConfig(category: TaskCategory): CategoryConfig;
718
- /**
719
- * Type guard: check if a string is a valid TaskCategory.
720
- */
721
- declare function isTaskCategory(value: string): value is TaskCategory;
722
- /** All registered category identifiers (read-only). */
723
- declare const ALL_CATEGORIES: TaskCategory[];
724
- /**
725
- * Resolve a category string (or fallback to "unspecified-low").
726
- * Never throws; always returns a valid config.
727
- */
728
- declare function resolveCategory(category: string): CategoryConfig;
729
-
730
- interface ProviderConfig {
731
- name: string;
732
- baseUrl?: string;
733
- apiKey?: string;
734
- }
735
- interface RegisteredProvider {
736
- provider: ILLMProvider;
737
- config: ProviderConfig;
738
- }
739
- declare class ProviderRegistry {
740
- private providers;
741
- register(provider: ILLMProvider, config?: Omit<ProviderConfig, 'name'>): void;
742
- unregister(name: string): void;
743
- get(name: string): ILLMProvider | undefined;
744
- getConfig(name: string): ProviderConfig | undefined;
745
- upsertConfig(config: ProviderConfig): void;
746
- list(): string[];
747
- listConfigs(): ProviderConfig[];
748
- resolve(modelId: string): {
749
- provider: ILLMProvider;
750
- providerName: string;
751
- modelName?: string;
752
- };
753
- }
754
-
755
- /**
756
- * Hook registry for managing lifecycle hook handlers.
757
- * Hooks execute in registration order (first registered, first executed).
758
- *
759
- * Converted from module-level singletons to an instance class for test isolation
760
- * and multi-runtime support. Backward-compatible function exports delegate to a
761
- * default global instance.
762
- */
763
-
764
- /**
765
- * Instance-level hook registry. Each instance maintains its own handler state.
766
- */
767
- declare class HookRegistry {
768
- private readonly hookRegistry;
769
- private readonly hookOrder;
770
- /**
771
- * Register a hook handler for a specific lifecycle event.
772
- */
773
- registerHook(type: HookType, handler: HookHandler, name?: string): void;
774
- /**
775
- * Unregister a specific hook handler by name.
776
- */
777
- unregisterHook(type: HookType, name: string): boolean;
778
- /**
779
- * Execute all registered hooks for a given type in registration order.
780
- */
781
- executeHooks(type: HookType, context: HookContext, data: Record<string, unknown>): Promise<HookResult>;
782
- /**
783
- * Check if any hooks are registered for a given type.
784
- */
785
- hasHooks(type: HookType): boolean;
786
- /**
787
- * Remove all registered hooks of all types.
788
- */
789
- clearHooks(): void;
790
- /**
791
- * List all hook types that have at least one registered handler.
792
- */
793
- listRegisteredHookTypes(): HookType[];
794
- /**
795
- * Get the count of registered handlers for a hook type.
796
- */
797
- getHookCount(type: HookType): number;
798
- }
799
- declare function getDefaultHookRegistry(): HookRegistry;
800
- declare function registerHook(type: HookType, handler: HookHandler, name?: string): void;
801
- declare function unregisterHook(type: HookType, name: string): boolean;
802
- declare function executeHooks(type: HookType, context: HookContext, data: Record<string, unknown>): Promise<HookResult>;
803
- declare function hasHooks(type: HookType): boolean;
804
- declare function clearHooks(): void;
805
- declare function listRegisteredHookTypes(): HookType[];
806
- /**
807
- * Get the count of registered handlers for a hook type.
808
- */
809
- declare function getHookCount(type: HookType): number;
810
-
811
- /**
812
- * Test whether a tool name matches a wildcard pattern.
813
- *
814
- * Supported patterns:
815
- * - `*` → matches everything
816
- * - `file.*` → matches any tool starting with `file.`
817
- * - `shell(*)` → matches tools like `shell(rm)`, `shell(ls)` (literal parens)
818
- * - exact name → matches only that exact tool name
819
- *
820
- * Patterns are converted to anchored regexes internally.
821
- */
822
- declare function matchPattern(toolName: string, pattern: string): boolean;
823
- /**
824
- * Merge multiple permission sets from lowest to highest priority.
825
- *
826
- * Sets are processed in order; later rules override earlier ones for the same tool pattern.
827
- * Within a single set, rules are processed in order (last wins).
828
- *
829
- * @param sets - Ordered from lowest to highest priority (e.g. default → agent → user → session)
830
- * @returns Flattened `MergedPermissions` with all unique patterns per action.
831
- */
832
- declare function mergePermissionSets(sets: PermissionSet[]): MergedPermissions;
833
- /**
834
- * Check what action applies to a given tool name under merged permissions.
835
- *
836
- * Precedence: exact patterns always beat wildcards.
837
- * Within same specificity: deny > ask > allow.
838
- */
839
- declare function checkPermission(toolName: string, merged: MergedPermissions): PermissionAction;
840
-
841
- interface PermissionSqlStatement {
842
- get(...arguments_: unknown[]): unknown;
843
- run(...arguments_: unknown[]): unknown;
844
- }
845
- interface PermissionSqlDatabase {
846
- prepare(sql: string): PermissionSqlStatement;
847
- }
848
- /**
849
- * Load user-level permission set from SQLite.
850
- *
851
- * The `permissions` table stores JSON blobs keyed by `source`.
852
- * Returns an empty set if no persisted rules exist.
853
- */
854
- declare function loadUserPermissions(database: PermissionSqlDatabase): PermissionSet;
855
- /**
856
- * Persist user-level permission set to SQLite.
857
- *
858
- * Uses INSERT OR REPLACE so first-time saves work without explicit table detection.
859
- */
860
- declare function saveUserPermissions(database: PermissionSqlDatabase, set: PermissionSet): void;
861
- /** SQL statement to create the permissions table during migration. */
862
- declare const PERMISSIONS_TABLE_DDL = "\n CREATE TABLE IF NOT EXISTS permissions (\n source TEXT PRIMARY KEY,\n rulesJson TEXT NOT NULL,\n updatedAt INTEGER NOT NULL\n );\n";
863
-
864
- /**
865
- * Plugin marketplace architecture types.
866
- * Plugins can provide tools and hooks to extend memeloop.
867
- */
868
-
869
- /**
870
- * Plugin manifest schema.
871
- * Host adapters may read this from files or construct it programmatically.
872
- */
873
- interface PluginManifest {
874
- /** Unique plugin identifier (e.g. "plugin-hello", "@scope/my-plugin") */
875
- name: string;
876
- /** Semantic version */
877
- version: string;
878
- /** Human-readable description */
879
- description: string;
880
- /** Declared exports: what the plugin provides */
881
- exports?: PluginExports;
882
- /** Plugin author */
883
- author?: string;
884
- /** Minimum memeloop version requirement (semver range) */
885
- minMemeloopVersion?: string;
886
- }
887
- /** Declared capabilities a plugin may export. */
888
- interface PluginExports {
889
- /** Tool IDs this plugin implements */
890
- tools?: string[];
891
- /** Hook types this plugin listens for */
892
- hooks?: HookType[];
893
- }
894
- /**
895
- * Shape of a loaded plugin module's default export.
896
- * Plugins must export default an object conforming to this interface.
897
- */
898
- interface PluginModule {
899
- /** Plugin identity (must match manifest name) */
900
- name: string;
901
- /**
902
- * Called when the plugin is loaded. Receives the PluginAPI for registering
903
- * tools and hooks. Return a cleanup function for teardown.
904
- */
905
- activate: (api: PluginAPI) => (() => void) | Promise<() => void> | undefined;
906
- }
907
- /**
908
- * API surface exposed to plugins. Plugins call these methods in their
909
- * `activate` function to register their capabilities.
910
- */
911
- interface PluginAPI {
912
- /**
913
- * Register a tool implementation.
914
- * @param toolId - Unique tool ID (e.g. "plugin-hello.sayHi")
915
- * @param impl - Tool implementation function
916
- * @param schema - Optional parameter schema (Zod type)
917
- */
918
- registerTool(toolId: string, impl: (...arguments_: unknown[]) => unknown, schema?: unknown): void;
919
- /**
920
- * Register a lifecycle hook handler.
921
- * @param type - Hook event type
922
- * @param handler - Async handler function
923
- * @param name - Optional handler name (enables dedup/unregistration)
924
- */
925
- registerHook(type: HookType, handler: HookHandler, name?: string): void;
926
- /** Log to memeloop's logger (falls back to console). */
927
- logger: {
928
- debug: (message: string, ...arguments_: unknown[]) => void;
929
- info: (message: string, ...arguments_: unknown[]) => void;
930
- warn: (message: string, ...arguments_: unknown[]) => void;
931
- error: (message: string, ...arguments_: unknown[]) => void;
932
- };
933
- }
934
- /** Metadata about a loaded plugin instance. */
935
- interface LoadedPlugin {
936
- /** Manifest data */
937
- manifest: PluginManifest;
938
- /** Optional host-provided source identifier, e.g. package name or file path. */
939
- source: string;
940
- /** The loaded plugin module */
941
- module: PluginModule;
942
- /** Cleanup function returned by activate(), if any */
943
- cleanup: (() => void) | undefined;
944
- /** When the plugin was loaded */
945
- loadedAt: Date;
946
- }
947
-
948
- declare function validatePluginManifest(object: unknown): PluginManifest | null;
949
- interface LoadPluginModuleOptions {
950
- manifest: PluginManifest;
951
- module: PluginModule;
952
- api?: unknown;
953
- source?: string;
954
- }
955
- declare function loadPluginModule(options: LoadPluginModuleOptions): Promise<LoadedPlugin | null>;
956
- declare function loadPluginModules(plugins: LoadPluginModuleOptions[]): Promise<LoadedPlugin[]>;
957
- declare function unloadPlugin(name: string): boolean;
958
- declare function listPlugins(): LoadedPlugin[];
959
- declare function getLoadedPlugin(name: string): LoadedPlugin | undefined;
960
- declare function isPluginLoaded(name: string): boolean;
961
- declare function unloadAllPlugins(): void;
962
-
963
- /**
964
- * Plugin registry: bridges plugin exports to memeloop's tool and hook registries.
965
- *
966
- * Provides a `createPluginAPI()` factory that plugins call during `activate()`
967
- * to register their tools and hooks with the host runtime.
968
- *
969
- * Converted from module-level singletons to an instance class for test isolation
970
- * and multi-runtime support.
971
- */
972
-
973
- /** Plugin API factory options. */
974
- interface PluginAPIOptions {
975
- toolRegistry?: {
976
- registerTool(id: string, impl: unknown): void;
977
- };
978
- logger?: PluginAPI['logger'];
979
- }
980
- /**
981
- * Track which tools/plugins belong to each plugin so we can clean up on unload.
982
- */
983
- interface PluginRegistration {
984
- pluginName: string;
985
- tools: string[];
986
- hooks: Array<{
987
- type: HookType;
988
- name: string;
989
- }>;
990
- }
991
- declare function createPluginAPI(options?: PluginAPIOptions): PluginAPI;
992
- declare function registerPluginTools(pluginName: string, tools: Array<readonly [string, (...arguments_: unknown[]) => unknown, unknown?]>): void;
993
- declare function registerPluginHooks(pluginName: string, hooks: Array<readonly [HookType, HookHandler, string?]>): void;
994
- declare function getPluginRegistrations(pluginName: string): PluginRegistration | undefined;
995
- declare function clearPluginRegistrations(): void;
996
-
997
- /**
998
- * 注册内置 prompt 插件(fullReplacement、dynamicPosition)。
999
- * @param target 若传入(如节点 `ToolRegistry` 上的 Map),只写入该表;否则写入活动注册表(全局或 ALS)。
1000
- */
1001
- declare function registerBuiltinPromptPlugins(target?: Map<string, PromptConcatTool>): void;
1002
-
1003
- /** 扁平化后的 LLM 消息(不依赖 peer `ai` 包导出,避免 d.ts 与 SDK 主版本不一致) */
1004
- type PromptFlatModelMessage = {
1005
- role: 'system' | 'user' | 'assistant' | 'tool';
1006
- content: unknown;
1007
- };
1008
- declare function findPromptById(prompts: PromptNode[], id: string): {
1009
- prompt: PromptNode;
1010
- parent: PromptNode[];
1011
- index: number;
1012
- } | undefined;
1013
- declare function flattenPrompts(prompts: PromptNode[]): PromptFlatModelMessage[];
1014
- interface PromptConcatPluginPreview {
1015
- id: string;
1016
- toolId?: string;
1017
- caption?: string;
1018
- }
1019
- interface PromptConcatStreamState {
1020
- processedPrompts: PromptNode[];
1021
- flatPrompts: PromptFlatModelMessage[];
1022
- step: 'flatten' | 'complete' | 'plugin' | 'finalize';
1023
- isComplete: boolean;
1024
- /** prompt 节点 id → JSON 路径(如 agentFrameworkConfig.prompts.0) */
1025
- sourcePaths?: Record<string, string>;
1026
- /** Desktop UI: plugin currently being processed. */
1027
- currentPlugin?: PromptConcatPluginPreview;
1028
- /** Desktop UI: progress value between 0 and 1. */
1029
- progress?: number;
1030
- }
1031
- interface PromptConcatOptions {
1032
- readAttachmentFile?: (path: string) => Promise<Uint8Array | Buffer>;
1033
- }
1034
- declare function promptConcatStream(agentConfig: Pick<AgentPromptDescription, 'agentFrameworkConfig'>, messages: ChatMessage[], agentFrameworkContext: AgentFrameworkContext, options?: PromptConcatOptions): AsyncGenerator<PromptConcatStreamState, PromptConcatStreamState, unknown>;
1035
-
1036
- export { PERMISSIONS_TABLE_DDL as $, AGENT_AGENT_LOOP_ID as A, type AgentToolLoopScriptContext as B, type AgentToolLoopScriptReference as C, type AgentToolLoopState as D, type AgentToolLoopTurnStartResult as E, BUILTIN_AGENT_AGENT_LOOP_QUALITY_GATE_SCRIPT_ID as F, BUILTIN_AGENT_PROFILES as G, BUILTIN_AGENT_TOOL_LOOP_DEFAULT_SCRIPT_ID as H, BUILTIN_TOOL_PLUGIN_IDS as I, type CategoryConfig as J, type CompactionOptions as K, type CompactionResult as L, type MemeLoopRuntime as M, type ContextCompactionData as N, type CreateAgentLoopRunnerOptions as O, type CreateAgentOptions as P, type HookContext as Q, type HookHandler as R, HookRegistry as S, type HookResult as T, type HookType as U, type LoadAgentAgentLoopScriptOptions as V, type LoadAgentToolLoopScriptOptions as W, type LoadPluginModuleOptions as X, type LoadedPlugin as Y, LoopRegistryImpl as Z, type MergedPermissions as _, AGENT_TOOL_LOOP_ID as a, getPluginRegistrations as a$, PLUGIN_ASK_QUESTION as a0, PLUGIN_ASK_USER_QUESTION as a1, PLUGIN_MCP_CLIENT as a2, PLUGIN_MCP_FORWARD as a3, PLUGIN_REMOTE_AGENT as a4, PLUGIN_SPAWN_AGENT as a5, PLUGIN_TASK as a6, PLUGIN_TODO_WRITE as a7, type PermissionAction as a8, type PermissionRule as a9, checkPermission as aA, clearHooks as aB, clearPluginRegistrations as aC, compactMessages as aD, createAgentAgentLoopDefinition as aE, createAgentInstanceFromDefinition as aF, createAgentLoopRunner as aG, createAgentToolLoopDefinition as aH, createAgentToolLoopRunner as aI, createChatMessage as aJ, createMemeLoopRuntime as aK, createPluginAPI as aL, executeHooks as aM, exploreAgent as aN, flattenPrompts as aO, getAgentAgentLoopId as aP, getAgentProfileRegistry as aQ, getBuiltinAgentAgentLoopSource as aR, getBuiltinAgentToolLoopSource as aS, getBuiltinLoopProfile as aT, getBuiltinLoopProfiles as aU, getBuiltinToolPlugins as aV, getCategoryConfig as aW, getDefaultHookRegistry as aX, getHookCount as aY, getLoadedPlugin as aZ, getLoopRegistry as a_, type PermissionSet as aa, type PermissionSqlDatabase as ab, type PermissionSqlStatement as ac, type PluginAPI as ad, type PluginAPIOptions as ae, type PluginExports as af, type PluginManifest as ag, type PluginModule as ah, type PostToolUseData as ai, type PreToolUseData as aj, type PromptConcatPluginPreview as ak, type PromptConcatStreamState as al, type ProviderConfig as am, ProviderRegistry as an, type RegisteredProvider as ao, type RunAgentToolLoopTurnCallbacks as ap, type RunAgentToolLoopTurnResult as aq, type SendMessageOptions as ar, type TaskCategory as as, TokenTracker as at, type ToolPermissionRules as au, type UserPromptSubmitData as av, autoCompact as aw, buildAgent as ax, builtinAgentAgentLoopSources as ay, builtinAgentToolLoopSources as az, ALL_CATEGORIES as b, hasHooks as b0, isPluginLoaded as b1, isTaskCategory as b2, librarianAgent as b3, listPlugins as b4, listRegisteredHookTypes as b5, loadAgentAgentLoopScript as b6, loadAgentToolLoopScript as b7, loadPluginModule as b8, loadPluginModules as b9, loadUserPermissions as ba, matchPattern as bb, mergePermissionSets as bc, oracleAgent as bd, planAgent as be, promptConcatStream as bf, registerBuiltinLoops as bg, registerBuiltinPromptPlugins as bh, registerBuiltinToolPlugins as bi, registerHook as bj, registerPluginHooks as bk, registerPluginTools as bl, resetAgentProfileRegistry as bm, resetLoopRegistry as bn, resolveAgentToolLoopTerminalState as bo, resolveCategory as bp, runAgentToolLoopTurn as bq, saveUserPermissions as br, shouldCompact as bs, unloadAllPlugins as bt, unloadPlugin as bu, unregisterHook as bv, validatePluginManifest as bw, registerBuiltinLoopProfiles as bx, type AgentAgentBatchRunInput as c, type AgentAgentBatchRunResult as d, type AgentAgentConfigEntry as e, findPromptById as f, type AgentAgentContext as g, type AgentAgentDescriptor as h, type AgentAgentFormatResultsOptions as i, type AgentAgentLoopContext as j, type AgentAgentLoopScript as k, type AgentAgentLoopScriptArguments as l, type AgentAgentLoopScriptReference as m, type AgentAgentRunAgentFailure as n, type AgentAgentRunAgentInput as o, type AgentAgentRunAgentResult as p, type AgentAgentScriptContext as q, type AgentProfile as r, AgentProfileRegistry as s, type AgentProfileType as t, type AgentStartData as u, type AgentStopData as v, type AgentToolLoopContext as w, type AgentToolLoopIterationGenerator as x, type AgentToolLoopIterationResult as y, type AgentToolLoopScript as z };