@kaleidorg/mind 0.5.0 → 0.6.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 (109) hide show
  1. package/dist/autonomy/index.d.ts +21 -0
  2. package/dist/autonomy/index.d.ts.map +1 -0
  3. package/dist/autonomy/index.js +16 -0
  4. package/dist/autonomy/index.js.map +1 -0
  5. package/dist/autonomy/prompt.d.ts +21 -0
  6. package/dist/autonomy/prompt.d.ts.map +1 -0
  7. package/dist/autonomy/prompt.js +37 -0
  8. package/dist/autonomy/prompt.js.map +1 -0
  9. package/dist/autonomy/risk.d.ts +53 -0
  10. package/dist/autonomy/risk.d.ts.map +1 -0
  11. package/dist/autonomy/risk.js +74 -0
  12. package/dist/autonomy/risk.js.map +1 -0
  13. package/dist/autonomy/run-state.d.ts +39 -0
  14. package/dist/autonomy/run-state.d.ts.map +1 -0
  15. package/dist/autonomy/run-state.js +118 -0
  16. package/dist/autonomy/run-state.js.map +1 -0
  17. package/dist/autonomy/scheduler.d.ts +18 -0
  18. package/dist/autonomy/scheduler.d.ts.map +1 -0
  19. package/dist/autonomy/scheduler.js +113 -0
  20. package/dist/autonomy/scheduler.js.map +1 -0
  21. package/dist/autonomy/task-store.d.ts +44 -0
  22. package/dist/autonomy/task-store.d.ts.map +1 -0
  23. package/dist/autonomy/task-store.js +139 -0
  24. package/dist/autonomy/task-store.js.map +1 -0
  25. package/dist/autonomy/types.d.ts +164 -0
  26. package/dist/autonomy/types.d.ts.map +1 -0
  27. package/dist/autonomy/types.js +20 -0
  28. package/dist/autonomy/types.js.map +1 -0
  29. package/dist/funnel.d.ts.map +1 -1
  30. package/dist/funnel.js +12 -0
  31. package/dist/funnel.js.map +1 -1
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +4 -0
  35. package/dist/index.js.map +1 -1
  36. package/dist/knowledge/bitcoin-copilot.js +2 -2
  37. package/dist/knowledge/bitcoin-copilot.js.map +1 -1
  38. package/dist/qvac/index.d.ts +1 -1
  39. package/dist/qvac/index.d.ts.map +1 -1
  40. package/dist/qvac/index.js.map +1 -1
  41. package/dist/qvac/parse.d.ts +33 -0
  42. package/dist/qvac/parse.d.ts.map +1 -1
  43. package/dist/qvac/parse.js +69 -5
  44. package/dist/qvac/parse.js.map +1 -1
  45. package/dist/qvac/provider.d.ts +16 -0
  46. package/dist/qvac/provider.d.ts.map +1 -1
  47. package/dist/qvac/provider.js +17 -1
  48. package/dist/qvac/provider.js.map +1 -1
  49. package/dist/qvac/stream.d.ts +16 -0
  50. package/dist/qvac/stream.d.ts.map +1 -1
  51. package/dist/qvac/stream.js +21 -1
  52. package/dist/qvac/stream.js.map +1 -1
  53. package/dist/qvac/text.d.ts.map +1 -1
  54. package/dist/qvac/text.js +4 -0
  55. package/dist/qvac/text.js.map +1 -1
  56. package/dist/recipe/buy-asset-channel.d.ts +1 -1
  57. package/dist/recipe/buy-asset-channel.d.ts.map +1 -1
  58. package/dist/recipe/buy-asset-channel.js +4 -3
  59. package/dist/recipe/buy-asset-channel.js.map +1 -1
  60. package/dist/recipe/kaleidoswap-atomic.d.ts +1 -1
  61. package/dist/recipe/kaleidoswap-atomic.d.ts.map +1 -1
  62. package/dist/recipe/kaleidoswap-atomic.js +5 -4
  63. package/dist/recipe/kaleidoswap-atomic.js.map +1 -1
  64. package/dist/recipe/runner.d.ts.map +1 -1
  65. package/dist/recipe/runner.js +38 -0
  66. package/dist/recipe/runner.js.map +1 -1
  67. package/dist/tools/mcp.d.ts +19 -0
  68. package/dist/tools/mcp.d.ts.map +1 -1
  69. package/dist/tools/mcp.js +51 -9
  70. package/dist/tools/mcp.js.map +1 -1
  71. package/package.json +2 -1
  72. package/skills/channel-manager/SKILL.md +59 -0
  73. package/skills/dca/SKILL.md +48 -0
  74. package/skills/kaleido-lsps/SKILL.md +12 -12
  75. package/skills/kaleido-trading/SKILL.md +1 -1
  76. package/skills/liquidity-optimizer/SKILL.md +91 -0
  77. package/skills/merchant-finder/SKILL.md +1 -1
  78. package/skills/portfolio-manager/SKILL.md +67 -0
  79. package/skills/rgb-lightning-node/SKILL.md +3 -3
  80. package/skills/wallet-assistant/SKILL.md +1 -1
  81. package/src/autonomy/autonomy.test.ts +348 -0
  82. package/src/autonomy/index.ts +50 -0
  83. package/src/autonomy/prompt.ts +48 -0
  84. package/src/autonomy/risk.ts +139 -0
  85. package/src/autonomy/run-state.ts +144 -0
  86. package/src/autonomy/scheduler.ts +120 -0
  87. package/src/autonomy/task-store.ts +167 -0
  88. package/src/autonomy/types.ts +186 -0
  89. package/src/funnel.mind.test.ts +390 -0
  90. package/src/funnel.ts +14 -0
  91. package/src/index.ts +41 -0
  92. package/src/knowledge/bitcoin-copilot.ts +2 -2
  93. package/src/qvac/index.ts +1 -0
  94. package/src/qvac/parse.test.ts +70 -1
  95. package/src/qvac/parse.ts +91 -5
  96. package/src/qvac/provider.test.ts +17 -0
  97. package/src/qvac/provider.ts +37 -1
  98. package/src/qvac/stream.test.ts +25 -0
  99. package/src/qvac/stream.ts +38 -1
  100. package/src/qvac/text.ts +4 -0
  101. package/src/recipe/buy-asset-channel.test.ts +5 -0
  102. package/src/recipe/buy-asset-channel.ts +6 -3
  103. package/src/recipe/kaleidoswap-atomic.test.ts +3 -3
  104. package/src/recipe/kaleidoswap-atomic.ts +5 -4
  105. package/src/recipe/recipe.test.ts +16 -0
  106. package/src/recipe/runner.ts +41 -0
  107. package/src/tools/mcp.live.test.ts +116 -0
  108. package/src/tools/mcp.parse.test.ts +37 -0
  109. package/src/tools/mcp.ts +55 -9
package/src/tools/mcp.ts CHANGED
@@ -20,6 +20,18 @@
20
20
 
21
21
  import type { ToolDef } from '../types.js';
22
22
  import type { ToolSource } from './source.js';
23
+ import { isKaleidoswapSpendTool } from '../kaleidoswap/contract.js';
24
+ import { isLsps1SpendTool } from '../lsps1/contract.js';
25
+ import { isSpendTool } from '../wallet/contract.js';
26
+
27
+ function toolRequiresConfirmation(name: string, description: string): boolean {
28
+ return (
29
+ isSpendTool(name) ||
30
+ isKaleidoswapSpendTool(name) ||
31
+ isLsps1SpendTool(name) ||
32
+ /\bSPEND\b.*\bconfirm/i.test(description)
33
+ );
34
+ }
23
35
 
24
36
  export type McpTransport =
25
37
  | { kind: 'stdio'; command: string; args?: string[]; env?: Record<string, string> }
@@ -30,10 +42,47 @@ export interface McpToolSourceOptions {
30
42
  transport: McpTransport;
31
43
  /** Optional allowlist — only expose these tool names if provided. */
32
44
  allow?: string[];
45
+ /** Optional prefix denylist applied after discovery (for host-specific rails). */
46
+ denyPrefixes?: string[];
33
47
  /** Per-call timeout (ms). Default 60_000. */
34
48
  timeoutMs?: number;
35
49
  }
36
50
 
51
+ /**
52
+ * Normalize an MCP `callTool` result into a structured value.
53
+ *
54
+ * Two fixes vs. returning the raw text content:
55
+ * - `isError` (the MCP failure signal) becomes an `{ error }` object, so callers
56
+ * — the recipe runner's `toolFailure`, the agent — treat it as a FAILURE
57
+ * instead of a successful result. Without this the agent claimed a spend had
58
+ * succeeded when the wallet actually rejected it.
59
+ * - JSON text is PARSED, so recipes thread real fields (rfq_id, total_sat,
60
+ * order_id) and any failure fields (error/status) are visible. A raw string
61
+ * hid both — the quote's rfq_id never reached the create call, and the canned
62
+ * success summary fired regardless. Non-JSON text passes through unchanged;
63
+ * the engine re-stringifies objects when feeding the model.
64
+ *
65
+ * Exported for unit testing.
66
+ */
67
+ export function parseMcpResult(res: unknown): unknown {
68
+ const r = res as { content?: Array<{ type?: string; text?: string }>; isError?: boolean } | null;
69
+ const text = Array.isArray(r?.content)
70
+ ? r!.content
71
+ .filter((c) => c?.type === 'text')
72
+ .map((c) => c?.text ?? '')
73
+ .join('\n')
74
+ : '';
75
+ if (r?.isError) return { error: text || 'The tool reported an error.' };
76
+ if (text) {
77
+ try {
78
+ return JSON.parse(text);
79
+ } catch {
80
+ return text;
81
+ }
82
+ }
83
+ return Array.isArray(r?.content) ? r!.content : res;
84
+ }
85
+
37
86
  export class McpToolSource implements ToolSource {
38
87
  readonly id: string;
39
88
  private readonly opts: McpToolSourceOptions;
@@ -71,12 +120,15 @@ export class McpToolSource implements ToolSource {
71
120
 
72
121
  const listed = await this.client.listTools();
73
122
  const allow = this.opts.allow ? new Set(this.opts.allow) : null;
123
+ const denied = this.opts.denyPrefixes ?? [];
74
124
  this.tools = (listed.tools ?? [])
75
125
  .filter((t: any) => !allow || allow.has(t.name))
126
+ .filter((t: any) => !denied.some((prefix) => t.name.startsWith(prefix)))
76
127
  .map((t: any) => ({
77
128
  name: t.name,
78
129
  description: t.description ?? '',
79
130
  parameters: t.inputSchema ?? { type: 'object', properties: {} },
131
+ requiresConfirmation: toolRequiresConfirmation(t.name, t.description ?? ''),
80
132
  }));
81
133
  }
82
134
 
@@ -95,15 +147,9 @@ export class McpToolSource implements ToolSource {
95
147
  undefined,
96
148
  { timeout: this.opts.timeoutMs ?? 60_000 },
97
149
  );
98
- // MCP returns content blocks; surface text content as the tool result.
99
- if (Array.isArray(res?.content)) {
100
- const text = res.content
101
- .filter((c: any) => c.type === 'text')
102
- .map((c: any) => c.text)
103
- .join('\n');
104
- return text || res.content;
105
- }
106
- return res;
150
+ // Parse JSON + surface isError so recipes/agent get structured results and
151
+ // real failures (not an opaque string that hid both). See parseMcpResult.
152
+ return parseMcpResult(res);
107
153
  }
108
154
 
109
155
  async close(): Promise<void> {