qlogicagent 0.2.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/README.md +45 -45
  2. package/package.json +56 -42
  3. package/dist/agent/agent.d.ts +0 -43
  4. package/dist/agent/agent.js +0 -113
  5. package/dist/agent/tool-loop.d.ts +0 -64
  6. package/dist/agent/tool-loop.js +0 -575
  7. package/dist/agent/types.d.ts +0 -175
  8. package/dist/agent/types.js +0 -14
  9. package/dist/cli/main.d.ts +0 -11
  10. package/dist/cli/main.js +0 -23
  11. package/dist/cli/stdio-server.d.ts +0 -45
  12. package/dist/cli/stdio-server.js +0 -463
  13. package/dist/config/config.d.ts +0 -17
  14. package/dist/config/config.js +0 -21
  15. package/dist/contracts/hooks.d.ts +0 -120
  16. package/dist/contracts/hooks.js +0 -7
  17. package/dist/contracts/index.d.ts +0 -10
  18. package/dist/contracts/index.js +0 -10
  19. package/dist/contracts/planner.d.ts +0 -35
  20. package/dist/contracts/planner.js +0 -2
  21. package/dist/contracts/skill-candidate.d.ts +0 -63
  22. package/dist/contracts/skill-candidate.js +0 -195
  23. package/dist/contracts/todo.d.ts +0 -14
  24. package/dist/contracts/todo.js +0 -9
  25. package/dist/index.d.ts +0 -13
  26. package/dist/index.js +0 -15
  27. package/dist/llm/builtin-providers.d.ts +0 -10
  28. package/dist/llm/builtin-providers.js +0 -531
  29. package/dist/llm/index.d.ts +0 -15
  30. package/dist/llm/index.js +0 -14
  31. package/dist/llm/llm-client.d.ts +0 -43
  32. package/dist/llm/llm-client.js +0 -67
  33. package/dist/llm/model-catalog.d.ts +0 -53
  34. package/dist/llm/model-catalog.js +0 -191
  35. package/dist/llm/provider-def.d.ts +0 -59
  36. package/dist/llm/provider-def.js +0 -12
  37. package/dist/llm/provider-registry.d.ts +0 -54
  38. package/dist/llm/provider-registry.js +0 -147
  39. package/dist/llm/transport.d.ts +0 -62
  40. package/dist/llm/transport.js +0 -27
  41. package/dist/llm/transports/anthropic-messages.d.ts +0 -31
  42. package/dist/llm/transports/anthropic-messages.js +0 -293
  43. package/dist/llm/transports/openai-chat.d.ts +0 -36
  44. package/dist/llm/transports/openai-chat.js +0 -165
  45. package/dist/orchestration/agent-registry.d.ts +0 -41
  46. package/dist/orchestration/agent-registry.js +0 -116
  47. package/dist/orchestration/approval-aware-tool-plan.d.ts +0 -32
  48. package/dist/orchestration/approval-aware-tool-plan.js +0 -87
  49. package/dist/orchestration/context-compression.d.ts +0 -220
  50. package/dist/orchestration/context-compression.js +0 -583
  51. package/dist/orchestration/conversation-repair.d.ts +0 -61
  52. package/dist/orchestration/conversation-repair.js +0 -429
  53. package/dist/orchestration/curator-scheduler.d.ts +0 -119
  54. package/dist/orchestration/curator-scheduler.js +0 -135
  55. package/dist/orchestration/embedded-failover-policy.d.ts +0 -110
  56. package/dist/orchestration/embedded-failover-policy.js +0 -168
  57. package/dist/orchestration/error-classification.d.ts +0 -12
  58. package/dist/orchestration/error-classification.js +0 -77
  59. package/dist/orchestration/failover-classification.d.ts +0 -8
  60. package/dist/orchestration/failover-classification.js +0 -381
  61. package/dist/orchestration/failover-error.d.ts +0 -33
  62. package/dist/orchestration/failover-error.js +0 -198
  63. package/dist/orchestration/fork-subagent.d.ts +0 -100
  64. package/dist/orchestration/fork-subagent.js +0 -98
  65. package/dist/orchestration/index.d.ts +0 -120
  66. package/dist/orchestration/index.js +0 -267
  67. package/dist/orchestration/memory-flush-policy.d.ts +0 -57
  68. package/dist/orchestration/memory-flush-policy.js +0 -85
  69. package/dist/orchestration/memory-provider.d.ts +0 -14
  70. package/dist/orchestration/memory-provider.js +0 -2
  71. package/dist/orchestration/parallel-tool-calls.d.ts +0 -41
  72. package/dist/orchestration/parallel-tool-calls.js +0 -59
  73. package/dist/orchestration/prompt-cache-strategy.d.ts +0 -126
  74. package/dist/orchestration/prompt-cache-strategy.js +0 -228
  75. package/dist/orchestration/reactive-compact.d.ts +0 -73
  76. package/dist/orchestration/reactive-compact.js +0 -78
  77. package/dist/orchestration/retry-loop.d.ts +0 -22
  78. package/dist/orchestration/retry-loop.js +0 -24
  79. package/dist/orchestration/skill-candidate.d.ts +0 -52
  80. package/dist/orchestration/skill-candidate.js +0 -141
  81. package/dist/orchestration/skill-consolidation.d.ts +0 -123
  82. package/dist/orchestration/skill-consolidation.js +0 -220
  83. package/dist/orchestration/skill-improvement.d.ts +0 -59
  84. package/dist/orchestration/skill-improvement.js +0 -66
  85. package/dist/orchestration/skill-similarity.d.ts +0 -98
  86. package/dist/orchestration/skill-similarity.js +0 -131
  87. package/dist/orchestration/streaming-tool-executor.d.ts +0 -73
  88. package/dist/orchestration/streaming-tool-executor.js +0 -96
  89. package/dist/orchestration/team-orchestration.d.ts +0 -195
  90. package/dist/orchestration/team-orchestration.js +0 -369
  91. package/dist/orchestration/team-tool-loop-wiring.d.ts +0 -92
  92. package/dist/orchestration/team-tool-loop-wiring.js +0 -147
  93. package/dist/orchestration/tool-choice-policy.d.ts +0 -54
  94. package/dist/orchestration/tool-choice-policy.js +0 -164
  95. package/dist/orchestration/tool-loop-state.d.ts +0 -50
  96. package/dist/orchestration/tool-loop-state.js +0 -133
  97. package/dist/orchestration/tool-schema.d.ts +0 -39
  98. package/dist/orchestration/tool-schema.js +0 -297
  99. package/dist/orchestration/transcript-repair.d.ts +0 -42
  100. package/dist/orchestration/transcript-repair.js +0 -426
  101. package/dist/orchestration/turn-loop-guard.d.ts +0 -86
  102. package/dist/orchestration/turn-loop-guard.js +0 -92
  103. package/dist/orchestration/web-browser-policy.d.ts +0 -17
  104. package/dist/orchestration/web-browser-policy.js +0 -39
  105. package/dist/runtime/context-compression.d.ts +0 -61
  106. package/dist/runtime/context-compression.js +0 -274
  107. package/dist/runtime/hook-registry.d.ts +0 -12
  108. package/dist/runtime/hook-registry.js +0 -53
  109. package/dist/runtime/memory-hooks.d.ts +0 -23
  110. package/dist/runtime/memory-hooks.js +0 -65
  111. package/dist/runtime/tool-eligibility.d.ts +0 -59
  112. package/dist/runtime/tool-eligibility.js +0 -111
  113. package/dist/skills/index.d.ts +0 -108
  114. package/dist/skills/index.js +0 -82
  115. package/dist/skills/memory-extractor.d.ts +0 -64
  116. package/dist/skills/memory-extractor.js +0 -173
  117. package/dist/skills/memory-query-tool.d.ts +0 -43
  118. package/dist/skills/memory-query-tool.js +0 -127
  119. package/dist/skills/memory-store.d.ts +0 -66
  120. package/dist/skills/memory-store.js +0 -228
  121. package/dist/skills/memory-tool.d.ts +0 -67
  122. package/dist/skills/memory-tool.js +0 -192
  123. package/dist/skills/portable-tool.d.ts +0 -71
  124. package/dist/skills/portable-tool.js +0 -14
  125. package/dist/skills/qmemory-adapter.d.ts +0 -52
  126. package/dist/skills/qmemory-adapter.js +0 -165
  127. package/dist/skills/skill-frontmatter.d.ts +0 -19
  128. package/dist/skills/skill-frontmatter.js +0 -344
  129. package/dist/skills/skill-guard.d.ts +0 -23
  130. package/dist/skills/skill-guard.js +0 -229
  131. package/dist/skills/skill-loader.d.ts +0 -16
  132. package/dist/skills/skill-loader.js +0 -303
  133. package/dist/skills/skill-source.d.ts +0 -119
  134. package/dist/skills/skill-source.js +0 -126
  135. package/dist/skills/skill-types.d.ts +0 -199
  136. package/dist/skills/skill-types.js +0 -6
  137. package/dist/skills/think-tool.d.ts +0 -16
  138. package/dist/skills/think-tool.js +0 -59
  139. package/dist/skills/todo-tool.d.ts +0 -63
  140. package/dist/skills/todo-tool.js +0 -114
  141. package/dist/skills/tools/agent-tool.d.ts +0 -91
  142. package/dist/skills/tools/agent-tool.js +0 -142
  143. package/dist/skills/tools/apply-patch-tool.d.ts +0 -29
  144. package/dist/skills/tools/apply-patch-tool.js +0 -184
  145. package/dist/skills/tools/ask-user-tool.d.ts +0 -80
  146. package/dist/skills/tools/ask-user-tool.js +0 -121
  147. package/dist/skills/tools/brief-tool.d.ts +0 -74
  148. package/dist/skills/tools/brief-tool.js +0 -95
  149. package/dist/skills/tools/browser-tool.d.ts +0 -114
  150. package/dist/skills/tools/browser-tool.js +0 -155
  151. package/dist/skills/tools/checkpoint-tool.d.ts +0 -66
  152. package/dist/skills/tools/checkpoint-tool.js +0 -102
  153. package/dist/skills/tools/config-tool.d.ts +0 -63
  154. package/dist/skills/tools/config-tool.js +0 -143
  155. package/dist/skills/tools/cron-tool.d.ts +0 -116
  156. package/dist/skills/tools/cron-tool.js +0 -175
  157. package/dist/skills/tools/edit-tool.d.ts +0 -43
  158. package/dist/skills/tools/edit-tool.js +0 -70
  159. package/dist/skills/tools/exec-tool.d.ts +0 -102
  160. package/dist/skills/tools/exec-tool.js +0 -133
  161. package/dist/skills/tools/image-generate-tool.d.ts +0 -62
  162. package/dist/skills/tools/image-generate-tool.js +0 -67
  163. package/dist/skills/tools/instructions-tool.d.ts +0 -103
  164. package/dist/skills/tools/instructions-tool.js +0 -187
  165. package/dist/skills/tools/lsp-tool.d.ts +0 -153
  166. package/dist/skills/tools/lsp-tool.js +0 -227
  167. package/dist/skills/tools/mcp-client-types.d.ts +0 -269
  168. package/dist/skills/tools/mcp-client-types.js +0 -53
  169. package/dist/skills/tools/mcp-tool.d.ts +0 -249
  170. package/dist/skills/tools/mcp-tool.js +0 -503
  171. package/dist/skills/tools/memory-tool.d.ts +0 -74
  172. package/dist/skills/tools/memory-tool.js +0 -88
  173. package/dist/skills/tools/monitor-tool.d.ts +0 -113
  174. package/dist/skills/tools/monitor-tool.js +0 -131
  175. package/dist/skills/tools/music-generate-tool.d.ts +0 -55
  176. package/dist/skills/tools/music-generate-tool.js +0 -62
  177. package/dist/skills/tools/notify-tool.d.ts +0 -53
  178. package/dist/skills/tools/notify-tool.js +0 -62
  179. package/dist/skills/tools/patch-tool.d.ts +0 -45
  180. package/dist/skills/tools/patch-tool.js +0 -505
  181. package/dist/skills/tools/pdf-tool.d.ts +0 -66
  182. package/dist/skills/tools/pdf-tool.js +0 -88
  183. package/dist/skills/tools/plan-mode-tool.d.ts +0 -59
  184. package/dist/skills/tools/plan-mode-tool.js +0 -122
  185. package/dist/skills/tools/read-tool.d.ts +0 -51
  186. package/dist/skills/tools/read-tool.js +0 -84
  187. package/dist/skills/tools/repl-tool.d.ts +0 -70
  188. package/dist/skills/tools/repl-tool.js +0 -69
  189. package/dist/skills/tools/search-tool.d.ts +0 -112
  190. package/dist/skills/tools/search-tool.js +0 -225
  191. package/dist/skills/tools/send-message-tool.d.ts +0 -51
  192. package/dist/skills/tools/send-message-tool.js +0 -76
  193. package/dist/skills/tools/skill-list-tool.d.ts +0 -33
  194. package/dist/skills/tools/skill-list-tool.js +0 -54
  195. package/dist/skills/tools/skill-manage-tool.d.ts +0 -73
  196. package/dist/skills/tools/skill-manage-tool.js +0 -153
  197. package/dist/skills/tools/skill-view-tool.d.ts +0 -37
  198. package/dist/skills/tools/skill-view-tool.js +0 -72
  199. package/dist/skills/tools/sleep-tool.d.ts +0 -49
  200. package/dist/skills/tools/sleep-tool.js +0 -81
  201. package/dist/skills/tools/structured-output-tool.d.ts +0 -116
  202. package/dist/skills/tools/structured-output-tool.js +0 -176
  203. package/dist/skills/tools/task-tool.d.ts +0 -104
  204. package/dist/skills/tools/task-tool.js +0 -161
  205. package/dist/skills/tools/team-tool.d.ts +0 -89
  206. package/dist/skills/tools/team-tool.js +0 -105
  207. package/dist/skills/tools/tool-search-tool.d.ts +0 -51
  208. package/dist/skills/tools/tool-search-tool.js +0 -110
  209. package/dist/skills/tools/tts-tool.d.ts +0 -38
  210. package/dist/skills/tools/tts-tool.js +0 -45
  211. package/dist/skills/tools/video-edit-tool.d.ts +0 -69
  212. package/dist/skills/tools/video-edit-tool.js +0 -74
  213. package/dist/skills/tools/video-generate-tool.d.ts +0 -62
  214. package/dist/skills/tools/video-generate-tool.js +0 -66
  215. package/dist/skills/tools/video-merge-tool.d.ts +0 -105
  216. package/dist/skills/tools/video-merge-tool.js +0 -92
  217. package/dist/skills/tools/video-upscale-tool.d.ts +0 -45
  218. package/dist/skills/tools/video-upscale-tool.js +0 -52
  219. package/dist/skills/tools/web-fetch-tool.d.ts +0 -78
  220. package/dist/skills/tools/web-fetch-tool.js +0 -92
  221. package/dist/skills/tools/web-search-tool.d.ts +0 -57
  222. package/dist/skills/tools/web-search-tool.js +0 -86
  223. package/dist/skills/tools/worktree-tool.d.ts +0 -69
  224. package/dist/skills/tools/worktree-tool.js +0 -147
  225. package/dist/skills/tools/write-tool.d.ts +0 -45
  226. package/dist/skills/tools/write-tool.js +0 -81
@@ -1,463 +0,0 @@
1
- /**
2
- * StdioServer — JSON-RPC 2.0 over stdio protocol handler.
3
- *
4
- * Reads line-delimited JSON from stdin, dispatches to handlers,
5
- * writes JSON-RPC responses/notifications to stdout.
6
- * All log output goes to stderr.
7
- *
8
- * Protocol: each line on stdin/stdout is a single JSON-RPC 2.0 message.
9
- */
10
- import { createInterface } from "node:readline";
11
- import { randomUUID } from "node:crypto";
12
- import { Agent } from "../agent/agent.js";
13
- import { ProviderRegistry, createLLMClient, autoDetectProvider, } from "../llm/index.js";
14
- import { createHookRegistry } from "../runtime/hook-registry.js";
15
- import { registerMemoryHooks } from "../runtime/memory-hooks.js";
16
- import { createQMemoryAdapter } from "../skills/qmemory-adapter.js";
17
- import { AGENT_RPC_ERROR_CODES, AGENT_RPC_PROTOCOL_VERSION, isAgentRpcRequest, } from "qlogicagent-runtime-contracts";
18
- export class StdioServer {
19
- running = false;
20
- activeTurn = null;
21
- pendingToolResults = new Map();
22
- verbose;
23
- registry;
24
- agent = null;
25
- lastLlmConfigKey = "";
26
- currentSessionId = "";
27
- currentHooks = null;
28
- constructor(config) {
29
- this.verbose = config.verbose;
30
- this.registry = new ProviderRegistry();
31
- }
32
- start() {
33
- this.running = true;
34
- this.log("qlogicagent CLI started, waiting for JSON-RPC on stdin...");
35
- const rl = createInterface({
36
- input: process.stdin,
37
- crlfDelay: Number.POSITIVE_INFINITY,
38
- });
39
- rl.on("line", (line) => {
40
- const trimmed = line.trim();
41
- if (!trimmed)
42
- return;
43
- try {
44
- const parsed = JSON.parse(trimmed);
45
- if (!isAgentRpcRequest(parsed)) {
46
- this.log(`[warn] ignoring non-request message: ${trimmed.slice(0, 200)}`);
47
- return;
48
- }
49
- this.handleMessage(parsed);
50
- }
51
- catch {
52
- this.log(`[warn] invalid JSON on stdin: ${trimmed.slice(0, 200)}`);
53
- }
54
- });
55
- rl.on("close", () => {
56
- this.log("stdin closed, shutting down");
57
- this.stop();
58
- });
59
- }
60
- stop() {
61
- if (!this.running)
62
- return;
63
- this.running = false;
64
- // Fire session.ended for active session
65
- if (this.currentSessionId && this.currentHooks) {
66
- this.currentHooks.invoke("session.ended", { sessionId: this.currentSessionId }).catch(() => { });
67
- }
68
- // Abort active turn if any
69
- if (this.activeTurn) {
70
- this.activeTurn.abort();
71
- this.activeTurn = null;
72
- }
73
- // Reject all pending tool results
74
- for (const [callId, pending] of this.pendingToolResults) {
75
- pending.resolve({ result: "", error: "Agent process shutting down" });
76
- }
77
- this.pendingToolResults.clear();
78
- this.log("stopped");
79
- }
80
- // ── Message dispatch ──────────────────────────────────────────────────
81
- handleMessage(msg) {
82
- switch (msg.method) {
83
- case "agent.hello":
84
- this.handleHello(msg);
85
- break;
86
- case "agent.ping":
87
- this.handlePing(msg);
88
- break;
89
- case "agent.turn":
90
- this.handleTurn(msg);
91
- break;
92
- case "memory.dream":
93
- // Dream turns use the same agent.turn pipeline with dream-specific
94
- // system prompt and messages. The Gateway sends memory.dream but the
95
- // agent treats it as a regular turn with dream context.
96
- this.handleTurn(msg);
97
- break;
98
- case "agent.abort":
99
- this.handleAbort(msg);
100
- break;
101
- case "tool.result":
102
- this.handleToolResult(msg);
103
- break;
104
- default:
105
- if (msg.id !== undefined) {
106
- this.sendResponse(msg.id, undefined, {
107
- code: AGENT_RPC_ERROR_CODES.METHOD_NOT_FOUND,
108
- message: `Unknown method: ${msg.method}`,
109
- });
110
- }
111
- }
112
- }
113
- // ── Handlers ──────────────────────────────────────────────────────────
114
- handleHello(msg) {
115
- const params = msg.params;
116
- const hostVersion = params?.protocolVersion ?? "unknown";
117
- const majorHost = hostVersion.split(".")[0];
118
- const majorSelf = AGENT_RPC_PROTOCOL_VERSION.split(".")[0];
119
- if (majorHost !== majorSelf) {
120
- this.log(`protocol mismatch: host=${hostVersion} agent=${AGENT_RPC_PROTOCOL_VERSION}`);
121
- if (msg.id !== undefined) {
122
- this.sendResponse(msg.id, undefined, {
123
- code: AGENT_RPC_ERROR_CODES.PROTOCOL_MISMATCH,
124
- message: `Protocol version mismatch: host=${hostVersion}, agent=${AGENT_RPC_PROTOCOL_VERSION}`,
125
- });
126
- }
127
- return;
128
- }
129
- this.log(`hello from ${params?.hostName ?? "unknown"} v${params?.hostVersion ?? "?"} (protocol ${hostVersion})`);
130
- if (msg.id !== undefined) {
131
- this.sendResponse(msg.id, {
132
- protocolVersion: AGENT_RPC_PROTOCOL_VERSION,
133
- agentName: "qlogicagent",
134
- agentVersion: "0.1.0",
135
- capabilities: ["turn", "tool-invoke", "streaming"],
136
- });
137
- }
138
- }
139
- handlePing(msg) {
140
- if (msg.id !== undefined) {
141
- this.sendResponse(msg.id, { status: "ok" });
142
- }
143
- this.sendNotification("pong", {});
144
- }
145
- handleAbort(msg) {
146
- const turnId = msg.params?.turnId ?? "";
147
- this.log(`abort requested for turn ${turnId}`);
148
- if (this.activeTurn) {
149
- this.activeTurn.abort();
150
- this.activeTurn = null;
151
- }
152
- if (msg.id !== undefined) {
153
- this.sendResponse(msg.id, { aborted: true });
154
- }
155
- }
156
- handleToolResult(msg) {
157
- const callId = msg.params?.callId;
158
- const result = msg.params?.result ?? "";
159
- const error = msg.params?.error;
160
- if (!callId) {
161
- this.log("[warn] tool.result missing callId");
162
- return;
163
- }
164
- const pending = this.pendingToolResults.get(callId);
165
- if (pending) {
166
- pending.resolve({ result, error });
167
- this.pendingToolResults.delete(callId);
168
- }
169
- else {
170
- this.log(`[warn] no pending tool call for callId ${callId}`);
171
- }
172
- }
173
- async handleTurn(msg) {
174
- const params = msg.params ?? {};
175
- const turnId = params.turnId ?? randomUUID();
176
- const sessionId = params.sessionId;
177
- const messages = params.messages ?? [];
178
- const tools = params.tools ?? [];
179
- const config = params.config;
180
- if (msg.id !== undefined) {
181
- this.sendResponse(msg.id, { accepted: true, turnId });
182
- }
183
- // Session lifecycle: fire session.created when sessionId changes
184
- if (sessionId && sessionId !== this.currentSessionId) {
185
- if (this.currentSessionId && this.currentHooks) {
186
- this.currentHooks.invoke("session.ended", { sessionId: this.currentSessionId }).catch(() => { });
187
- }
188
- this.currentSessionId = sessionId;
189
- // session.created is fired after hooks are available (below in resolveAgent)
190
- }
191
- const ac = new AbortController();
192
- this.activeTurn = ac;
193
- this.log(`turn ${turnId} starting (session: ${sessionId})`);
194
- try {
195
- // ─── Resolve or create Agent with LLM config ──────────────
196
- const turnConfig = {
197
- provider: config?.provider,
198
- model: config?.model,
199
- apiKey: config?.apiKey,
200
- baseUrl: config?.baseUrl,
201
- maxRounds: config?.maxRounds,
202
- temperature: config?.temperature,
203
- contextWindowTokens: config?.contextWindowTokens,
204
- maxOutputTokens: config?.maxOutputTokens,
205
- modelMaxOutputTokens: config?.modelMaxOutputTokens,
206
- };
207
- const agent = this.resolveAgent(turnConfig);
208
- if (!agent) {
209
- this.sendNotification("turn.start", { turnId });
210
- this.sendNotification("turn.error", {
211
- turnId,
212
- error: "No LLM provider configured. Provide provider/model/apiKey in agent.turn config, " +
213
- "or set DEEPSEEK_API_KEY / OPENAI_API_KEY / ANTHROPIC_API_KEY environment variable.",
214
- code: "NO_PROVIDER",
215
- });
216
- return;
217
- }
218
- // ─── Stream events from Agent ─────────────────────────────
219
- const systemPrompt = config?.systemPrompt;
220
- for await (const event of agent.run({
221
- turnId,
222
- sessionId,
223
- messages,
224
- tools,
225
- systemPrompt,
226
- config: turnConfig,
227
- }, ac.signal)) {
228
- // Forward all TurnEvent as JSON-RPC notifications
229
- switch (event.type) {
230
- case "start":
231
- this.sendNotification("turn.start", { turnId: event.turnId });
232
- break;
233
- case "delta":
234
- this.sendNotification("turn.delta", {
235
- turnId: event.turnId,
236
- text: event.text,
237
- });
238
- break;
239
- case "end":
240
- this.sendNotification("turn.end", {
241
- turnId: event.turnId,
242
- content: event.content,
243
- usage: event.usage,
244
- model: event.model,
245
- provider: event.provider,
246
- });
247
- break;
248
- case "error":
249
- this.sendNotification("turn.error", {
250
- turnId: event.turnId,
251
- error: event.error,
252
- code: event.code,
253
- });
254
- break;
255
- case "skill_instruction":
256
- this.sendNotification("turn.skill_instruction", {
257
- turnId: event.turnId,
258
- instruction: event.instruction,
259
- });
260
- break;
261
- case "tool_call":
262
- // Informational only — actual execution RPC is handled
263
- // by requestToolExecution() when toolInvoker.invoke() is called.
264
- break;
265
- case "tool_result":
266
- this.sendNotification("turn.tool_result", {
267
- turnId: event.turnId,
268
- callId: event.callId,
269
- name: event.name,
270
- ok: event.ok,
271
- ...(event.error ? { error: event.error } : {}),
272
- });
273
- break;
274
- case "sidechain_started":
275
- this.sendNotification("turn.sidechain_started", {
276
- turnId: event.turnId,
277
- depth: event.depth,
278
- role: event.role,
279
- });
280
- break;
281
- case "sidechain_completed":
282
- this.sendNotification("turn.sidechain_completed", {
283
- turnId: event.turnId,
284
- depth: event.depth,
285
- toolCallCount: event.toolCallCount,
286
- });
287
- break;
288
- case "tool_blocked":
289
- this.sendNotification("turn.tool_blocked", {
290
- turnId: event.turnId,
291
- callId: event.callId,
292
- name: event.name,
293
- reason: event.reason,
294
- });
295
- break;
296
- case "recovery":
297
- this.sendNotification("turn.recovery", {
298
- turnId: event.turnId,
299
- action: event.action,
300
- ...(event.detail ? { detail: event.detail } : {}),
301
- });
302
- break;
303
- case "plan_update":
304
- this.sendNotification("turn.plan_update", {
305
- turnId: event.turnId,
306
- slug: event.slug,
307
- content: event.content,
308
- });
309
- break;
310
- }
311
- }
312
- this.log(`turn ${turnId} completed`);
313
- }
314
- catch (err) {
315
- if (ac.signal.aborted) {
316
- this.sendNotification("turn.error", {
317
- turnId,
318
- error: "Turn aborted",
319
- code: "ABORTED",
320
- });
321
- }
322
- else {
323
- const message = err instanceof Error ? err.message : String(err);
324
- this.sendNotification("turn.error", {
325
- turnId,
326
- error: message,
327
- code: "INTERNAL_ERROR",
328
- });
329
- }
330
- }
331
- finally {
332
- if (this.activeTurn === ac) {
333
- this.activeTurn = null;
334
- }
335
- }
336
- }
337
- // ── Agent resolution (lazy create / re-create on config change) ───────
338
- resolveAgent(config) {
339
- // Build a config key to detect provider/model/key changes
340
- const configKey = `${config.provider ?? ""}:${config.model ?? ""}:${config.apiKey?.slice(0, 8) ?? ""}:${config.baseUrl ?? ""}`;
341
- if (this.agent && this.lastLlmConfigKey === configKey) {
342
- return this.agent;
343
- }
344
- // Try explicit config first
345
- let provider = config.provider;
346
- let model = config.model;
347
- let apiKey = config.apiKey;
348
- const baseUrl = config.baseUrl;
349
- if (!provider || !apiKey) {
350
- // Fallback: auto-detect from env
351
- const detected = autoDetectProvider(this.registry);
352
- if (detected) {
353
- provider = provider ?? detected.providerId;
354
- apiKey = apiKey ?? detected.apiKey;
355
- model = model ?? detected.defaultModel;
356
- this.log(`auto-detected provider: ${provider}, model: ${model}`);
357
- }
358
- }
359
- if (!provider || !apiKey) {
360
- return null;
361
- }
362
- model = model ?? this.registry.getProvider(provider)?.defaultModel ?? "";
363
- const client = createLLMClient({ provider, model, apiKey, baseUrl }, this.registry);
364
- const log = {
365
- info: (m) => this.log(m),
366
- warn: (m) => this.log(`[warn] ${m}`),
367
- error: (m) => this.log(`[error] ${m}`),
368
- debug: (m) => {
369
- if (this.verbose)
370
- this.log(`[debug] ${m}`);
371
- },
372
- };
373
- const toolInvoker = {
374
- invoke: (turnId, name, args, signal) => this.requestToolExecution(turnId, name, args, signal),
375
- };
376
- // ─── HookRegistry ────────────────────────────────────────
377
- // Skill learning: handled directly in tool-loop (has full metrics context).
378
- // The tool-loop yields `skill_instruction` events → forwarded above in handleTurn().
379
- // HookRegistry is available for context-compression and future hooks.
380
- const hooks = createHookRegistry(log);
381
- this.currentHooks = hooks;
382
- // ─── Memory hooks (qmemory REST API) ─────────────────────
383
- const qmemoryBaseUrl = (process.env.QMEMORY_BASE_URL ??
384
- process.env.QLOGICAGENT_QMEMORY_BASE_URL ??
385
- "").trim().replace(/\/+$/, "");
386
- if (qmemoryBaseUrl) {
387
- const memoryProvider = createQMemoryAdapter({
388
- baseUrl: qmemoryBaseUrl,
389
- apiKey: (process.env.QMEMORY_API_KEY ?? "").trim() || undefined,
390
- timeoutMs: 5_000,
391
- });
392
- registerMemoryHooks(hooks, {
393
- memoryProvider,
394
- userId: this.currentSessionId ?? "default",
395
- log: { debug: (m) => log.debug(m), warn: (m) => log.warn(m) },
396
- });
397
- }
398
- // Fire session.created for the current session
399
- if (this.currentSessionId) {
400
- hooks.invoke("session.created", { sessionId: this.currentSessionId }).catch(() => { });
401
- }
402
- this.agent = new Agent({
403
- llmTransport: client.transport,
404
- apiKey: client.apiKey,
405
- toolInvoker,
406
- log,
407
- hooks,
408
- maxRounds: config.maxRounds,
409
- verbose: this.verbose,
410
- });
411
- this.lastLlmConfigKey = configKey;
412
- this.log(`created Agent (provider: ${provider}, model: ${model})`);
413
- return this.agent;
414
- }
415
- // ── Tool call request (used by real Agent in Phase 2+) ────────────────
416
- /**
417
- * Request tool execution from the Gateway host.
418
- * Sends a turn.tool_call notification and waits for tool.result.
419
- */
420
- async requestToolExecution(turnId, name, args, signal) {
421
- const callId = `tc_${randomUUID().slice(0, 8)}`;
422
- return new Promise((resolve, reject) => {
423
- if (signal?.aborted) {
424
- reject(new Error("Aborted"));
425
- return;
426
- }
427
- this.pendingToolResults.set(callId, { resolve });
428
- const onAbort = () => {
429
- this.pendingToolResults.delete(callId);
430
- reject(new Error("Aborted"));
431
- };
432
- signal?.addEventListener("abort", onAbort, { once: true });
433
- this.sendNotification("turn.tool_call", {
434
- turnId,
435
- callId,
436
- name,
437
- arguments: args,
438
- });
439
- });
440
- }
441
- // ── Helpers ───────────────────────────────────────────────────────────
442
- // ── I/O ───────────────────────────────────────────────────────────────
443
- sendResponse(id, result, error) {
444
- const msg = { jsonrpc: "2.0", id };
445
- if (error)
446
- msg.error = error;
447
- else
448
- msg.result = result;
449
- this.writeStdout(msg);
450
- }
451
- sendNotification(method, params) {
452
- const msg = { jsonrpc: "2.0", method, params };
453
- this.writeStdout(msg);
454
- }
455
- writeStdout(msg) {
456
- process.stdout.write(`${JSON.stringify(msg)}\n`);
457
- }
458
- log(message) {
459
- if (this.verbose) {
460
- process.stderr.write(`[qlogicagent] ${message}\n`);
461
- }
462
- }
463
- }
@@ -1,17 +0,0 @@
1
- /**
2
- * Centralized CLI startup configuration.
3
- *
4
- * Parses and validates all configuration from CLI args and environment.
5
- * Single source of truth for qlogicagent runtime config.
6
- */
7
- export interface AgentConfig {
8
- /** Enable verbose logging to stderr. */
9
- verbose: boolean;
10
- }
11
- /**
12
- * Parse CLI arguments into AgentConfig.
13
- *
14
- * Supports:
15
- * --verbose / -v Enable verbose logging
16
- */
17
- export declare function parseCliArgs(argv: string[]): AgentConfig;
@@ -1,21 +0,0 @@
1
- /**
2
- * Centralized CLI startup configuration.
3
- *
4
- * Parses and validates all configuration from CLI args and environment.
5
- * Single source of truth for qlogicagent runtime config.
6
- */
7
- /**
8
- * Parse CLI arguments into AgentConfig.
9
- *
10
- * Supports:
11
- * --verbose / -v Enable verbose logging
12
- */
13
- export function parseCliArgs(argv) {
14
- const config = { verbose: false };
15
- for (const arg of argv.slice(2)) {
16
- if (arg === "--verbose" || arg === "-v") {
17
- config.verbose = true;
18
- }
19
- }
20
- return config;
21
- }
@@ -1,120 +0,0 @@
1
- /**
2
- * Hook system types for the Agent Runtime.
3
- *
4
- * Hooks allow hosts and middleware to intercept, modify, or observe events
5
- * at well-defined lifecycle points during session, turn, and tool execution.
6
- */
7
- /**
8
- * All supported hook points in the Agent Runtime lifecycle.
9
- */
10
- export type HookPoint = "session.created" | "session.ended" | "turn.submitted" | "turn.before_inference" | "turn.after_inference" | "turn.completed" | "turn.failed" | "tool.before_invoke" | "tool.after_invoke" | "tool.invoke_failed" | "approval.requested" | "approval.responded" | "context.before_compact" | "context.after_compact" | "memory.before_recall" | "memory.after_recall";
11
- export interface HookSessionContext {
12
- sessionId: string;
13
- gatewayId?: string;
14
- deviceId?: string;
15
- mode?: string;
16
- }
17
- export interface HookTurnContext extends HookSessionContext {
18
- turnId: string;
19
- executionId?: string;
20
- rootExecutionId?: string;
21
- }
22
- export interface HookToolContext extends HookTurnContext {
23
- callId: string;
24
- toolName: string;
25
- arguments?: Record<string, unknown>;
26
- }
27
- export interface HookApprovalContext extends HookTurnContext {
28
- approvalId: string;
29
- callId?: string;
30
- toolName?: string;
31
- decision?: "approved" | "denied" | "expired" | "cancelled";
32
- }
33
- export interface HookContextMap {
34
- "session.created": HookSessionContext;
35
- "session.ended": HookSessionContext;
36
- "turn.submitted": HookTurnContext & {
37
- prompt?: string;
38
- };
39
- "turn.before_inference": HookTurnContext & {
40
- model?: string;
41
- messages?: unknown[];
42
- };
43
- "turn.after_inference": HookTurnContext & {
44
- model?: string;
45
- response?: unknown;
46
- success?: boolean;
47
- error?: string;
48
- };
49
- "turn.completed": HookTurnContext & {
50
- outcomeId?: string;
51
- };
52
- "turn.failed": HookTurnContext & {
53
- code?: string;
54
- error?: string;
55
- };
56
- "tool.before_invoke": HookToolContext;
57
- "tool.after_invoke": HookToolContext & {
58
- result?: unknown;
59
- ok: boolean;
60
- };
61
- "tool.invoke_failed": HookToolContext & {
62
- error?: string;
63
- };
64
- "approval.requested": HookApprovalContext;
65
- "approval.responded": HookApprovalContext;
66
- "context.before_compact": HookTurnContext & {
67
- tokenCount?: number;
68
- messageCount?: number;
69
- };
70
- "context.after_compact": HookTurnContext & {
71
- tokenCount?: number;
72
- removedCount?: number;
73
- };
74
- "memory.before_recall": HookTurnContext & {
75
- query?: string;
76
- };
77
- "memory.after_recall": HookTurnContext & {
78
- blockCount?: number;
79
- };
80
- }
81
- /**
82
- * Result of a hook handler invocation.
83
- *
84
- * - `continue`: proceed normally (optionally with modified context)
85
- * - `abort`: stop execution (for "before" hooks only)
86
- * - `skip`: skip this step but continue the overall flow
87
- */
88
- export interface HookResult<T = unknown> {
89
- action: "continue" | "abort" | "skip";
90
- /** Modified context to pass downstream (only for "continue") */
91
- context?: T;
92
- /** Reason for abort/skip (for logging) */
93
- reason?: string;
94
- }
95
- /**
96
- * A hook handler function.
97
- *
98
- * @param point - The hook point being invoked
99
- * @param context - Event-specific context data
100
- * @returns A HookResult or void (treated as "continue")
101
- */
102
- export type HookHandler<P extends HookPoint = HookPoint> = (point: P, context: HookContextMap[P]) => HookResult<HookContextMap[P]> | void | Promise<HookResult<HookContextMap[P]> | void>;
103
- /**
104
- * Hook registration entry.
105
- */
106
- export interface HookRegistration<P extends HookPoint = HookPoint> {
107
- point: P;
108
- handler: HookHandler<P>;
109
- /** Priority (lower = earlier). Default: 100 */
110
- priority?: number;
111
- /** Optional label for debugging */
112
- label?: string;
113
- }
114
- /**
115
- * Interface for a hook registry that manages hook handlers.
116
- */
117
- export interface HookRegistry {
118
- register<P extends HookPoint>(registration: HookRegistration<P>): () => void;
119
- invoke<P extends HookPoint>(point: P, context: HookContextMap[P]): Promise<HookResult<HookContextMap[P]>>;
120
- }
@@ -1,7 +0,0 @@
1
- /**
2
- * Hook system types for the Agent Runtime.
3
- *
4
- * Hooks allow hosts and middleware to intercept, modify, or observe events
5
- * at well-defined lifecycle points during session, turn, and tool execution.
6
- */
7
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * Internal contracts — types internalized from qlogicagent-runtime-contracts.
3
- *
4
- * These types are only consumed within qlogicagent itself (agent runtime + hub).
5
- * They were removed from the public npm package to slim the cross-repo API surface.
6
- */
7
- export * from "./planner.js";
8
- export * from "./todo.js";
9
- export * from "./hooks.js";
10
- export * from "./skill-candidate.js";
@@ -1,10 +0,0 @@
1
- /**
2
- * Internal contracts — types internalized from qlogicagent-runtime-contracts.
3
- *
4
- * These types are only consumed within qlogicagent itself (agent runtime + hub).
5
- * They were removed from the public npm package to slim the cross-repo API surface.
6
- */
7
- export * from "./planner.js";
8
- export * from "./todo.js";
9
- export * from "./hooks.js";
10
- export * from "./skill-candidate.js";
@@ -1,35 +0,0 @@
1
- export declare const TASK_STEP_STATUS_VALUES: readonly ["pending", "in-progress", "completed", "skipped"];
2
- export type TaskStepStatus = (typeof TASK_STEP_STATUS_VALUES)[number];
3
- export declare const TASK_PLAN_STATUS_VALUES: readonly ["active", "completed", "abandoned"];
4
- export type TaskPlanStatus = (typeof TASK_PLAN_STATUS_VALUES)[number];
5
- export interface TaskStep {
6
- index: number;
7
- description: string;
8
- status: TaskStepStatus;
9
- result?: string;
10
- }
11
- export interface TaskPlan {
12
- id: string;
13
- sessionId: string;
14
- userId: string;
15
- goal: string;
16
- steps: TaskStep[];
17
- status: TaskPlanStatus;
18
- createdAt: string;
19
- updatedAt: string;
20
- constraints?: string[];
21
- keyIdentifiers?: string[];
22
- }
23
- export interface TaskPlanContextSnippet {
24
- text: string;
25
- tokens: number;
26
- planId: string;
27
- }
28
- export interface TaskPlanProgressSnapshot {
29
- goal: string;
30
- steps: Array<{
31
- description: string;
32
- status: TaskStepStatus | string;
33
- result?: string;
34
- }>;
35
- }