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,37 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const SKILL_VIEW_TOOL_NAME: "skill_view";
3
- export interface SkillViewToolParams {
4
- name: string;
5
- filePath?: string;
6
- }
7
- export declare const SKILL_VIEW_TOOL_SCHEMA: {
8
- readonly type: "object";
9
- readonly properties: {
10
- readonly name: {
11
- readonly type: "string";
12
- readonly description: "Skill name to view (e.g. 'code-review', 'deploy-ecs').";
13
- };
14
- readonly filePath: {
15
- readonly type: "string";
16
- readonly description: string;
17
- };
18
- };
19
- readonly required: readonly ["name"];
20
- };
21
- export interface SkillViewOutput {
22
- name: string;
23
- content: string;
24
- referenceFiles?: string[];
25
- tags?: string[];
26
- }
27
- /**
28
- * Host-provided skill viewer.
29
- */
30
- export interface SkillViewToolDeps {
31
- /**
32
- * Read skill content. Returns the main SKILL.md or a specific file.
33
- * Returns null if skill not found.
34
- */
35
- viewSkill(name: string, filePath?: string): Promise<SkillViewOutput | null>;
36
- }
37
- export declare function createSkillViewTool(deps: SkillViewToolDeps): PortableTool<SkillViewToolParams>;
@@ -1,72 +0,0 @@
1
- // ============================================================
2
- // Skill View Tool — view full skill content.
3
- // Reference: hermes-agent-2026.4.30/tools/skills_tool.py (skill_view)
4
- // Category: skill
5
- // ============================================================
6
- export const SKILL_VIEW_TOOL_NAME = "skill_view";
7
- export const SKILL_VIEW_TOOL_SCHEMA = {
8
- type: "object",
9
- properties: {
10
- name: {
11
- type: "string",
12
- description: "Skill name to view (e.g. 'code-review', 'deploy-ecs').",
13
- },
14
- filePath: {
15
- type: "string",
16
- description: "Optional: view a specific file within the skill (e.g. 'references/api.md'). " +
17
- "Omit to view the main SKILL.md.",
18
- },
19
- },
20
- required: ["name"],
21
- };
22
- export function createSkillViewTool(deps) {
23
- return {
24
- name: SKILL_VIEW_TOOL_NAME,
25
- label: "View Skill",
26
- description: "View the full content of a skill (instructions, configuration, reference files). " +
27
- "Use skill_list to discover available skills first.",
28
- parameters: SKILL_VIEW_TOOL_SCHEMA,
29
- execute: async (_toolCallId, params) => {
30
- if (!params.name || params.name.trim().length === 0) {
31
- return {
32
- content: [{ type: "text", text: "Error: skill name is required." }],
33
- details: { type: "skill_view", error: "empty_name" },
34
- };
35
- }
36
- const result = await deps.viewSkill(params.name.trim(), params.filePath);
37
- if (!result) {
38
- return {
39
- content: [{
40
- type: "text",
41
- text: `Skill "${params.name}" not found. Use skill_list to see available skills.`,
42
- }],
43
- details: { type: "skill_view", error: "not_found", name: params.name },
44
- };
45
- }
46
- const lines = [];
47
- if (params.filePath) {
48
- lines.push(`## ${result.name} / ${params.filePath}`);
49
- }
50
- else {
51
- lines.push(`## Skill: ${result.name}`);
52
- if (result.tags && result.tags.length > 0) {
53
- lines.push(`Tags: ${result.tags.join(", ")}`);
54
- }
55
- if (result.referenceFiles && result.referenceFiles.length > 0) {
56
- lines.push(`Reference files: ${result.referenceFiles.join(", ")}`);
57
- }
58
- }
59
- lines.push("");
60
- lines.push(result.content);
61
- return {
62
- content: [{ type: "text", text: lines.join("\n") }],
63
- details: {
64
- type: "skill_view",
65
- name: result.name,
66
- filePath: params.filePath,
67
- referenceFiles: result.referenceFiles,
68
- },
69
- };
70
- },
71
- };
72
- }
@@ -1,49 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const SLEEP_TOOL_NAME: "sleep";
3
- export interface SleepToolParams {
4
- /** Duration to sleep in seconds (1–3600). */
5
- duration: number;
6
- /** Reason for sleeping — helps the runtime decide whether to interrupt. */
7
- reason?: string;
8
- }
9
- export declare const SLEEP_TOOL_SCHEMA: {
10
- readonly type: "object";
11
- readonly properties: {
12
- readonly duration: {
13
- readonly type: "number";
14
- readonly description: "Duration to sleep in seconds (1–3600). Prefer short sleeps (10–60s) to stay responsive.";
15
- readonly minimum: 1;
16
- readonly maximum: 3600;
17
- };
18
- readonly reason: {
19
- readonly type: "string";
20
- readonly description: string;
21
- };
22
- };
23
- readonly required: readonly ["duration"];
24
- };
25
- /** The result returned after a sleep completes or is interrupted. */
26
- export interface SleepResult {
27
- /** Actual time slept in seconds (may be less if interrupted). */
28
- sleptSeconds: number;
29
- /** Whether the sleep was interrupted before completing. */
30
- interrupted: boolean;
31
- /** The event that caused the interruption (undefined if not interrupted). */
32
- interruptReason?: string;
33
- }
34
- /**
35
- * Runtime dependencies injected by the host.
36
- *
37
- * The sleep mechanism is host-provided — the tool itself does NOT call
38
- * setTimeout. The host decides how to implement the wait (timer, event loop
39
- * integration, tick prompt scheduling, etc.).
40
- */
41
- export interface SleepToolDeps {
42
- /**
43
- * Perform the actual sleep. Must resolve after `durationMs` or when
44
- * interrupted (whichever is first). The AbortSignal fires if the user
45
- * or the system requests an interrupt.
46
- */
47
- sleep(durationMs: number, signal: AbortSignal): Promise<SleepResult>;
48
- }
49
- export declare function createSleepTool(deps: SleepToolDeps): PortableTool<SleepToolParams>;
@@ -1,81 +0,0 @@
1
- // ============================================================
2
- // Sleep Tool — lightweight wait with tick/interrupt support.
3
- // Reference: claude-code-haha/src/tools/SleepTool/prompt.ts
4
- // Category: autonomous / proactive mode
5
- // ============================================================
6
- export const SLEEP_TOOL_NAME = "sleep";
7
- export const SLEEP_TOOL_SCHEMA = {
8
- type: "object",
9
- properties: {
10
- duration: {
11
- type: "number",
12
- description: "Duration to sleep in seconds (1–3600). Prefer short sleeps (10–60s) to stay responsive.",
13
- minimum: 1,
14
- maximum: 3600,
15
- },
16
- reason: {
17
- type: "string",
18
- description: "Brief reason for sleeping. Examples: \"waiting for build to finish\", " +
19
- "\"nothing to do\", \"user asked to rest\".",
20
- },
21
- },
22
- required: ["duration"],
23
- };
24
- export function createSleepTool(deps) {
25
- return {
26
- name: SLEEP_TOOL_NAME,
27
- label: "Sleep",
28
- shouldDefer: true,
29
- isConcurrencySafe: true,
30
- isReadOnly: true,
31
- searchHint: "wait sleep rest idle tick proactive",
32
- description: [
33
- "Wait for a specified duration. The user can interrupt the sleep at any time.",
34
- "",
35
- "Use this when:",
36
- "• You have nothing useful to do right now",
37
- "• You're waiting for an external process to complete",
38
- "• The user tells you to sleep or rest",
39
- "• You receive a <tick> check-in with no actionable work",
40
- "",
41
- "Prefer this over `exec(sleep ...)` — it doesn't hold a shell process.",
42
- "You can call this concurrently with other tools — it won't interfere with them.",
43
- "",
44
- "Each wake-up costs an API call, but the prompt cache expires after 5 minutes " +
45
- "of inactivity — balance accordingly.",
46
- ].join("\n"),
47
- parameters: SLEEP_TOOL_SCHEMA,
48
- execute: async (_toolCallId, params, signal) => {
49
- const durationSec = Math.max(1, Math.min(3600, Math.round(params.duration)));
50
- const durationMs = durationSec * 1000;
51
- // Create a child AbortController so we can forward the outer signal
52
- const controller = new AbortController();
53
- const onAbort = () => controller.abort();
54
- signal?.addEventListener("abort", onAbort, { once: true });
55
- // Handle pre-aborted signal
56
- if (signal?.aborted)
57
- controller.abort();
58
- try {
59
- const result = await deps.sleep(durationMs, controller.signal);
60
- const lines = [];
61
- if (result.interrupted) {
62
- lines.push(`Sleep interrupted after ${result.sleptSeconds}s.`);
63
- if (result.interruptReason) {
64
- lines.push(`Reason: ${result.interruptReason}`);
65
- }
66
- lines.push("Check for new messages or tasks.");
67
- }
68
- else {
69
- lines.push(`Slept for ${result.sleptSeconds}s. Waking up.`);
70
- }
71
- return {
72
- content: [{ type: "text", text: lines.join("\n") }],
73
- details: { ...result, requestedSeconds: durationSec },
74
- };
75
- }
76
- finally {
77
- signal?.removeEventListener("abort", onAbort);
78
- }
79
- },
80
- };
81
- }
@@ -1,116 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const STRUCTURED_OUTPUT_TOOL_NAME: "structured_output";
3
- /** Maximum content size for structured output results. */
4
- export declare const STRUCTURED_OUTPUT_MAX_CHARS = 100000;
5
- export interface StructuredOutputToolParams {
6
- /** The structured data to return. Must conform to the session's output schema. */
7
- data: Record<string, unknown>;
8
- }
9
- /**
10
- * Base schema — accepts any object.
11
- * When used with createConfiguredStructuredOutputTool, the host overrides
12
- * this with the actual JSON Schema from `response_format.json_schema`.
13
- */
14
- export declare const STRUCTURED_OUTPUT_TOOL_SCHEMA: {
15
- readonly type: "object";
16
- readonly properties: {
17
- readonly data: {
18
- readonly type: "object";
19
- readonly description: string;
20
- readonly additionalProperties: true;
21
- };
22
- };
23
- readonly required: readonly ["data"];
24
- };
25
- /** Schema validation error detail. */
26
- export interface SchemaValidationError {
27
- path: string;
28
- message: string;
29
- keyword?: string;
30
- }
31
- /** Result of structured output validation. */
32
- export interface StructuredOutputResult {
33
- valid: boolean;
34
- errors?: SchemaValidationError[];
35
- }
36
- /**
37
- * Whether the structured output tool should be enabled for this session.
38
- * CC equivalent: `isSyntheticOutputToolEnabled`.
39
- */
40
- export declare function isStructuredOutputEnabled(opts: {
41
- isNonInteractiveSession: boolean;
42
- }): boolean;
43
- /**
44
- * Runtime dependencies injected by the host.
45
- *
46
- * The host provides:
47
- * 1. The JSON Schema to validate against (from session config)
48
- * 2. A validator function (host may use Ajv, Zod, or any validator)
49
- * 3. An output sink to deliver the validated data
50
- *
51
- * The tool is only available in non-interactive (SDK/API) sessions
52
- * where a `response_format.json_schema` has been specified.
53
- */
54
- export interface StructuredOutputToolDeps {
55
- /**
56
- * Get the JSON Schema that the output must conform to.
57
- * Returns undefined if no schema is configured (tool should not be registered).
58
- */
59
- getOutputSchema(): Record<string, unknown> | undefined;
60
- /**
61
- * Validate data against the output schema.
62
- * Returns { valid: true } or { valid: false, errors: [...] }.
63
- */
64
- validateOutput(data: Record<string, unknown>): StructuredOutputResult;
65
- /**
66
- * Deliver the validated output to the caller.
67
- * Called only after successful validation.
68
- */
69
- deliverOutput(data: Record<string, unknown>): Promise<void>;
70
- }
71
- /**
72
- * Create the base structured output tool with DI-based validation.
73
- * This is the standard factory for runtime integration.
74
- */
75
- export declare function createStructuredOutputTool(deps: StructuredOutputToolDeps): PortableTool<StructuredOutputToolParams>;
76
- /**
77
- * Result of creating a configured structured output tool.
78
- * Success: { tool } — ready-to-use tool with compiled schema.
79
- * Failure: { error } — schema was invalid.
80
- */
81
- export type ConfiguredToolResult = {
82
- tool: PortableTool<StructuredOutputToolParams>;
83
- } | {
84
- error: string;
85
- };
86
- /**
87
- * Host-provided schema compilation interface.
88
- * Allows the host to use any validator (Ajv, Zod, custom).
89
- */
90
- export interface SchemaCompiler {
91
- /**
92
- * Validate that the schema itself is a valid JSON Schema.
93
- * Returns null if valid, or an error message string if invalid.
94
- */
95
- validateSchema(schema: Record<string, unknown>): string | null;
96
- /**
97
- * Compile the schema into a reusable validator function.
98
- * Returns a function that validates data and returns StructuredOutputResult.
99
- */
100
- compile(schema: Record<string, unknown>): (data: Record<string, unknown>) => StructuredOutputResult;
101
- }
102
- /**
103
- * Create a StructuredOutputTool configured with a specific JSON Schema.
104
- * Mirrors CC's `createSyntheticOutputTool(jsonSchema)`.
105
- *
106
- * Features:
107
- * - Validates the schema itself at creation time
108
- * - Compiles the validator for reuse (cached via WeakMap)
109
- * - Overrides the tool's `parameters` with the provided schema (dynamic input)
110
- * - Returns { tool } on success or { error } if schema is invalid
111
- *
112
- * @param jsonSchema The JSON Schema to validate output against.
113
- * @param compiler Schema compiler/validator provided by the host.
114
- * @param deliver Output delivery function (called after successful validation).
115
- */
116
- export declare function createConfiguredStructuredOutputTool(jsonSchema: Record<string, unknown>, compiler: SchemaCompiler, deliver: (data: Record<string, unknown>) => Promise<void>): ConfiguredToolResult;
@@ -1,176 +0,0 @@
1
- // ============================================================
2
- // Structured Output Tool — validated JSON schema output for
3
- // non-interactive (SDK/API) sessions.
4
- // Reference: claude-code-haha/src/tools/SyntheticOutputTool/SyntheticOutputTool.ts
5
- // Category: output / structured
6
- // ============================================================
7
- export const STRUCTURED_OUTPUT_TOOL_NAME = "structured_output";
8
- /** Maximum content size for structured output results. */
9
- export const STRUCTURED_OUTPUT_MAX_CHARS = 100_000;
10
- /**
11
- * Base schema — accepts any object.
12
- * When used with createConfiguredStructuredOutputTool, the host overrides
13
- * this with the actual JSON Schema from `response_format.json_schema`.
14
- */
15
- export const STRUCTURED_OUTPUT_TOOL_SCHEMA = {
16
- type: "object",
17
- properties: {
18
- data: {
19
- type: "object",
20
- description: "The structured JSON data to return as this turn's output. " +
21
- "Must conform to the output schema specified for this session.",
22
- additionalProperties: true,
23
- },
24
- },
25
- required: ["data"],
26
- };
27
- /**
28
- * Whether the structured output tool should be enabled for this session.
29
- * CC equivalent: `isSyntheticOutputToolEnabled`.
30
- */
31
- export function isStructuredOutputEnabled(opts) {
32
- return opts.isNonInteractiveSession;
33
- }
34
- /**
35
- * Create the base structured output tool with DI-based validation.
36
- * This is the standard factory for runtime integration.
37
- */
38
- export function createStructuredOutputTool(deps) {
39
- return {
40
- name: STRUCTURED_OUTPUT_TOOL_NAME,
41
- label: "Structured Output",
42
- shouldDefer: false,
43
- isConcurrencySafe: true,
44
- isReadOnly: true,
45
- searchHint: "return the final response as structured JSON",
46
- maxResultSizeChars: STRUCTURED_OUTPUT_MAX_CHARS,
47
- description: [
48
- "Return your final response as structured JSON data.",
49
- "",
50
- "Use this tool ONLY when the session requests structured output (via response_format).",
51
- "You MUST call this tool exactly once at the end of your response to provide the structured output.",
52
- "The data you provide must conform to the output JSON Schema specified for this session.",
53
- "",
54
- "Rules:",
55
- "• Call this exactly once at the end of your turn to deliver results",
56
- "• The data must be a valid JSON object matching the required schema",
57
- "• If validation fails, you'll see the errors — fix your data and try again",
58
- "• This is typically the last tool call in a turn",
59
- ].join("\n"),
60
- parameters: STRUCTURED_OUTPUT_TOOL_SCHEMA,
61
- execute: async (_toolCallId, params) => {
62
- const schema = deps.getOutputSchema();
63
- if (!schema) {
64
- return {
65
- content: [{
66
- type: "text",
67
- text: "Error: No output schema configured for this session. " +
68
- "structured_output is only available when response_format.json_schema is specified.",
69
- }],
70
- details: { valid: false, error: "no_schema" },
71
- };
72
- }
73
- const validation = deps.validateOutput(params.data);
74
- if (!validation.valid) {
75
- const errorLines = (validation.errors ?? []).map((e) => ` • ${e.path || "/"}: ${e.message}`);
76
- return {
77
- content: [{
78
- type: "text",
79
- text: [
80
- "Output does not match required schema:",
81
- ...errorLines,
82
- ].join("\n"),
83
- }],
84
- details: { valid: false, errors: validation.errors },
85
- };
86
- }
87
- // Validation passed — deliver the output
88
- await deps.deliverOutput(params.data);
89
- return {
90
- content: [{ type: "text", text: "Structured output provided successfully." }],
91
- details: { valid: true, structured_output: params.data },
92
- };
93
- },
94
- };
95
- }
96
- /** WeakMap cache for compiled schema tools (mirrors CC's toolCache). */
97
- const configuredToolCache = new WeakMap();
98
- /**
99
- * Create a StructuredOutputTool configured with a specific JSON Schema.
100
- * Mirrors CC's `createSyntheticOutputTool(jsonSchema)`.
101
- *
102
- * Features:
103
- * - Validates the schema itself at creation time
104
- * - Compiles the validator for reuse (cached via WeakMap)
105
- * - Overrides the tool's `parameters` with the provided schema (dynamic input)
106
- * - Returns { tool } on success or { error } if schema is invalid
107
- *
108
- * @param jsonSchema The JSON Schema to validate output against.
109
- * @param compiler Schema compiler/validator provided by the host.
110
- * @param deliver Output delivery function (called after successful validation).
111
- */
112
- export function createConfiguredStructuredOutputTool(jsonSchema, compiler, deliver) {
113
- const cached = configuredToolCache.get(jsonSchema);
114
- if (cached)
115
- return cached;
116
- const result = buildConfiguredTool(jsonSchema, compiler, deliver);
117
- configuredToolCache.set(jsonSchema, result);
118
- return result;
119
- }
120
- function buildConfiguredTool(jsonSchema, compiler, deliver) {
121
- try {
122
- // Step 1: Validate the schema itself
123
- const schemaError = compiler.validateSchema(jsonSchema);
124
- if (schemaError) {
125
- return { error: `Invalid JSON Schema: ${schemaError}` };
126
- }
127
- // Step 2: Compile the validator
128
- const validate = compiler.compile(jsonSchema);
129
- // Step 3: Build the tool with dynamic input schema
130
- const tool = {
131
- name: STRUCTURED_OUTPUT_TOOL_NAME,
132
- label: "Structured Output",
133
- shouldDefer: false,
134
- isConcurrencySafe: true,
135
- isReadOnly: true,
136
- searchHint: "return the final response as structured JSON",
137
- maxResultSizeChars: STRUCTURED_OUTPUT_MAX_CHARS,
138
- description: [
139
- "Use this tool to return your final response in the requested structured format.",
140
- "You MUST call this tool exactly once at the end of your response to provide the structured output.",
141
- ].join(" "),
142
- // Dynamic: override with the actual JSON Schema so LLM gets type guidance
143
- parameters: {
144
- type: "object",
145
- properties: {
146
- data: jsonSchema,
147
- },
148
- required: ["data"],
149
- },
150
- execute: async (_toolCallId, params) => {
151
- const validation = validate(params.data);
152
- if (!validation.valid) {
153
- const errors = (validation.errors ?? [])
154
- .map((e) => `${e.path || "root"}: ${e.message}`)
155
- .join(", ");
156
- return {
157
- content: [{
158
- type: "text",
159
- text: `Output does not match required schema: ${errors}`,
160
- }],
161
- details: { valid: false, errors: validation.errors },
162
- };
163
- }
164
- await deliver(params.data);
165
- return {
166
- content: [{ type: "text", text: "Structured output provided successfully." }],
167
- details: { valid: true, structured_output: params.data },
168
- };
169
- },
170
- };
171
- return { tool };
172
- }
173
- catch (e) {
174
- return { error: e instanceof Error ? e.message : String(e) };
175
- }
176
- }
@@ -1,104 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const TASK_TOOL_NAME: "task";
3
- export type TaskAction = "create" | "get" | "list" | "output" | "stop";
4
- export type TaskStatus = "pending" | "running" | "completed" | "failed" | "stopped";
5
- export interface TaskToolParams {
6
- action: TaskAction;
7
- /** Task ID (required for get/output/stop) */
8
- taskId?: string;
9
- /** Task prompt (required for create) */
10
- prompt?: string;
11
- /** Short description (3-7 words, for create) */
12
- description?: string;
13
- /** Allowed tools for the background agent */
14
- allowedTools?: string[];
15
- /** Working directory for the task */
16
- cwd?: string;
17
- /** Model override for the task agent */
18
- model?: string;
19
- /** Max output lines to return (for output action, default 100) */
20
- maxLines?: number;
21
- }
22
- export declare const TASK_TOOL_SCHEMA: {
23
- readonly type: "object";
24
- readonly properties: {
25
- readonly action: {
26
- readonly type: "string";
27
- readonly enum: readonly ["create", "get", "list", "output", "stop"];
28
- readonly description: string;
29
- };
30
- readonly taskId: {
31
- readonly type: "string";
32
- readonly description: "Task ID. Required for get/output/stop.";
33
- };
34
- readonly prompt: {
35
- readonly type: "string";
36
- readonly description: string;
37
- };
38
- readonly description: {
39
- readonly type: "string";
40
- readonly description: "Short (3-7 word) description of the task. Used for tracking and display.";
41
- };
42
- readonly allowedTools: {
43
- readonly type: "array";
44
- readonly items: {
45
- readonly type: "string";
46
- };
47
- readonly description: "Restrict background agent to only these tools. If omitted, inherits parent's tools.";
48
- };
49
- readonly cwd: {
50
- readonly type: "string";
51
- readonly description: "Working directory for the background task (absolute path).";
52
- };
53
- readonly model: {
54
- readonly type: "string";
55
- readonly description: "Model override for the task agent (e.g. 'sonnet', 'opus').";
56
- };
57
- readonly maxLines: {
58
- readonly type: "number";
59
- readonly description: "Max output lines to return for the 'output' action (default: 100).";
60
- readonly minimum: 1;
61
- readonly maximum: 2000;
62
- };
63
- };
64
- readonly required: readonly ["action"];
65
- };
66
- export interface TaskInfo {
67
- taskId: string;
68
- status: TaskStatus;
69
- description?: string;
70
- prompt?: string;
71
- createdAt: number;
72
- completedAt?: number;
73
- result?: string;
74
- error?: string;
75
- }
76
- export interface TaskResult {
77
- success: boolean;
78
- task?: TaskInfo;
79
- tasks?: TaskInfo[];
80
- output?: string;
81
- error?: string;
82
- }
83
- /** Host-provided task management backend. */
84
- export interface TaskToolDeps {
85
- /** Create a new background agent task. Returns the created task info. */
86
- createTask(params: {
87
- prompt: string;
88
- description?: string;
89
- allowedTools?: string[];
90
- cwd?: string;
91
- model?: string;
92
- }): Promise<TaskInfo>;
93
- /** Get a task by ID. Returns null if not found. */
94
- getTask(taskId: string): Promise<TaskInfo | null>;
95
- /** List all tasks (optionally filtered by status). */
96
- listTasks(filter?: {
97
- status?: TaskStatus;
98
- }): Promise<TaskInfo[]>;
99
- /** Get output/logs from a task. */
100
- getTaskOutput(taskId: string, maxLines?: number): Promise<string>;
101
- /** Stop a running task. Returns true if stopped successfully. */
102
- stopTask(taskId: string): Promise<boolean>;
103
- }
104
- export declare function createTaskTool(deps: TaskToolDeps): PortableTool<TaskToolParams>;