heyio 0.42.0 → 1.0.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 (100) hide show
  1. package/README.md +40 -52
  2. package/dist/api/auth.js +35 -38
  3. package/dist/api/server.js +157 -1139
  4. package/dist/config.js +49 -32
  5. package/dist/copilot/agents.js +72 -1055
  6. package/dist/copilot/client.js +6 -17
  7. package/dist/copilot/io-scheduler.js +55 -139
  8. package/dist/copilot/model-router.js +100 -72
  9. package/dist/copilot/orchestrator.js +91 -515
  10. package/dist/copilot/scheduler.js +67 -189
  11. package/dist/copilot/skills.js +41 -366
  12. package/dist/copilot/system-message.js +40 -200
  13. package/dist/copilot/tools.js +191 -2042
  14. package/dist/daemon.js +54 -201
  15. package/dist/index.js +15 -133
  16. package/dist/mcp/config.js +23 -31
  17. package/dist/mcp/index.js +2 -3
  18. package/dist/mcp/registry.js +33 -88
  19. package/dist/notify.js +18 -100
  20. package/dist/paths.js +13 -24
  21. package/dist/setup.js +35 -0
  22. package/dist/store/db.js +111 -297
  23. package/dist/store/feed.js +29 -97
  24. package/dist/store/instances.js +56 -121
  25. package/dist/store/schedules.js +21 -73
  26. package/dist/store/squads.js +35 -186
  27. package/dist/store/tasks.js +25 -168
  28. package/dist/telegram/bot.js +20 -312
  29. package/dist/telegram/handlers.js +39 -3
  30. package/dist/watchdog.js +31 -45
  31. package/dist/wiki/fs.js +38 -155
  32. package/dist/wiki/search.js +31 -44
  33. package/package.json +5 -8
  34. package/web-dist/assets/ChatView-EFFiln1H.js +11 -0
  35. package/web-dist/assets/FeedView-bN4NMOL7.js +6 -0
  36. package/web-dist/assets/LoginView-CNtasq3n.js +1 -0
  37. package/web-dist/assets/McpView-C2CHiwsi.js +1 -0
  38. package/web-dist/assets/SchedulesView-CyilLban.js +1 -0
  39. package/web-dist/assets/SettingsView-1wLXKEF4.js +1 -0
  40. package/web-dist/assets/SkillsView-BLsD-0u0.js +1 -0
  41. package/web-dist/assets/SquadDetailView-CsCw2ZLp.js +21 -0
  42. package/web-dist/assets/SquadsView-DQ3vFlyO.js +6 -0
  43. package/web-dist/assets/WikiView-19M3oqnq.js +21 -0
  44. package/web-dist/assets/api-WGvTsXaE.js +1 -0
  45. package/web-dist/assets/index-D7M5O-_l.css +1 -0
  46. package/web-dist/assets/index-DZOS9syn.js +95 -0
  47. package/web-dist/assets/plus-BOvyX1BC.js +6 -0
  48. package/web-dist/assets/trash-2-DHoetkC4.js +6 -0
  49. package/web-dist/favicon.svg +4 -1
  50. package/web-dist/index.html +7 -10
  51. package/dist/api/logout.test.js +0 -129
  52. package/dist/api/mcp.test.js +0 -285
  53. package/dist/api/wiki.test.js +0 -283
  54. package/dist/auth/session-logic.js +0 -79
  55. package/dist/auth/session-logic.test.js +0 -201
  56. package/dist/copilot/auto-complete-instance.test.js +0 -104
  57. package/dist/copilot/cron.js +0 -136
  58. package/dist/copilot/event-summary.js +0 -286
  59. package/dist/copilot/instance-deactivate.test.js +0 -119
  60. package/dist/copilot/model-router.test.js +0 -71
  61. package/dist/copilot/review-backfill.js +0 -57
  62. package/dist/copilot/session-timeout.js +0 -112
  63. package/dist/copilot/session-timeout.test.js +0 -372
  64. package/dist/copilot/skills.test.js +0 -55
  65. package/dist/copilot/universes.js +0 -469
  66. package/dist/instance-watchdog.js +0 -104
  67. package/dist/instance-watchdog.test.js +0 -183
  68. package/dist/mcp/client.js +0 -109
  69. package/dist/mcp/client.test.js +0 -99
  70. package/dist/mcp/config.test.js +0 -49
  71. package/dist/mcp/registry.test.js +0 -79
  72. package/dist/notify.test.js +0 -232
  73. package/dist/store/feed.test.js +0 -279
  74. package/dist/store/instances.test.js +0 -310
  75. package/dist/store/io-schedules.js +0 -63
  76. package/dist/store/notifications.js +0 -79
  77. package/dist/store/notifications.test.js +0 -197
  78. package/dist/store/schedule-runs.js +0 -46
  79. package/dist/store/squads.test.js +0 -405
  80. package/dist/store/tasks.test.js +0 -150
  81. package/dist/store/worktrees.js +0 -83
  82. package/dist/tui/index.js +0 -286
  83. package/dist/update.js +0 -81
  84. package/dist/watchdog.test.js +0 -83
  85. package/dist/wiki/wiki-squad.test.js +0 -54
  86. package/web-dist/assets/AgentActivityView-CedxxE6K.js +0 -1
  87. package/web-dist/assets/ChatView-DMkYQo_V.js +0 -4
  88. package/web-dist/assets/FeedView-BH4q-31V.js +0 -1
  89. package/web-dist/assets/InboxView-BVwVP4EW.js +0 -1
  90. package/web-dist/assets/LoginView-DRPDhnwu.js +0 -1
  91. package/web-dist/assets/McpView-D8yWz-lq.js +0 -1
  92. package/web-dist/assets/SchedulesView-BzzyncGF.js +0 -1
  93. package/web-dist/assets/SettingsTabs.vue_vue_type_script_setup_true_lang-oW3ySu7Y.js +0 -1
  94. package/web-dist/assets/SkillsView-oxpYuhx7.js +0 -1
  95. package/web-dist/assets/SquadsView-CaKUIKlq.js +0 -1
  96. package/web-dist/assets/StatusIndicator.vue_vue_type_script_setup_true_lang-8U15Qp_Q.js +0 -1
  97. package/web-dist/assets/WikiView-C5jXUlfW.js +0 -1
  98. package/web-dist/assets/index-BrWzNw-N.css +0 -10
  99. package/web-dist/assets/index-f67odrrt.js +0 -81
  100. package/web-dist/icons.svg +0 -24
@@ -1,183 +0,0 @@
1
- import { before, after, beforeEach, describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { mkdtempSync, rmSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
- import { setDbPathForTests, closeDb, getDb } from "./store/db.js";
7
- import { ensureInstanceTables } from "./store/instances.js";
8
- import { findStaleInstances, startInstanceWatchdog } from "./instance-watchdog.js";
9
- let tmpDir;
10
- before(() => {
11
- tmpDir = mkdtempSync(join(tmpdir(), "io-inst-watchdog-test-"));
12
- setDbPathForTests(join(tmpDir, "io.db"));
13
- ensureInstanceTables();
14
- });
15
- after(() => {
16
- closeDb();
17
- rmSync(tmpDir, { recursive: true, force: true });
18
- });
19
- beforeEach(() => {
20
- const db = getDb();
21
- db.prepare("DELETE FROM agent_tasks").run();
22
- db.prepare("DELETE FROM squad_instances").run();
23
- db.prepare("DELETE FROM squads").run();
24
- db.prepare("INSERT INTO squads (slug, name, project_path) VALUES (?, ?, ?)").run("test-squad", "Test", "/tmp/test");
25
- });
26
- describe("instance watchdog", () => {
27
- describe("findStaleInstances — active instances", () => {
28
- it("detects stale active instances with no task activity", () => {
29
- const db = getDb();
30
- db.prepare(`
31
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
32
- VALUES (?, ?, ?, ?, 'active', datetime('now', '-60 minutes'))
33
- `).run("test-squad--old", "test-squad", "/tmp/wt", "test-squad/instance/old");
34
- const stale = findStaleInstances(30 * 60_000);
35
- assert.strictEqual(stale.length, 1);
36
- assert.strictEqual(stale[0].instance.id, "test-squad--old");
37
- });
38
- it("does not flag instances with recent task activity", () => {
39
- const db = getDb();
40
- db.prepare(`
41
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
42
- VALUES (?, ?, ?, ?, 'active', datetime('now', '-60 minutes'))
43
- `).run("test-squad--recent", "test-squad", "/tmp/wt2", "test-squad/instance/recent");
44
- db.prepare(`
45
- INSERT INTO agent_tasks (task_id, agent_slug, description, instance_id, started_at)
46
- VALUES (?, ?, ?, ?, datetime('now', '-5 minutes'))
47
- `).run("task-recent", "agent-1", "Work", "test-squad--recent");
48
- const stale = findStaleInstances(30 * 60_000);
49
- assert.strictEqual(stale.length, 0);
50
- });
51
- it("does not flag non-active/non-merging instances", () => {
52
- const db = getDb();
53
- db.prepare(`
54
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
55
- VALUES (?, ?, ?, ?, 'done', datetime('now', '-120 minutes'))
56
- `).run("test-squad--done", "test-squad", "/tmp/wt3", "test-squad/instance/done");
57
- const stale = findStaleInstances(30 * 60_000);
58
- assert.strictEqual(stale.length, 0);
59
- });
60
- it("calculates idleMs correctly relative to now", () => {
61
- const db = getDb();
62
- db.prepare(`
63
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
64
- VALUES (?, ?, ?, ?, 'active', datetime('now', '-45 minutes'))
65
- `).run("test-squad--mid", "test-squad", "/tmp/wt4", "test-squad/instance/mid");
66
- const stale = findStaleInstances(30 * 60_000);
67
- assert.strictEqual(stale.length, 1);
68
- assert.ok(stale[0].idleMs >= 44 * 60_000);
69
- assert.ok(stale[0].idleMs <= 46 * 60_000);
70
- });
71
- it("skips active instances whose latest task status is done (#261)", () => {
72
- const db = getDb();
73
- db.prepare(`
74
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
75
- VALUES (?, ?, ?, ?, 'active', datetime('now', '-60 minutes'))
76
- `).run("test-squad--task-done", "test-squad", "/tmp/wt7", "test-squad/instance/task-done");
77
- db.prepare(`
78
- INSERT INTO agent_tasks (task_id, agent_slug, description, status, instance_id, started_at, completed_at)
79
- VALUES (?, ?, ?, 'done', ?, datetime('now', '-35 minutes'), datetime('now', '-34 minutes'))
80
- `).run("task-done-1", "agent-1", "Finished work", "test-squad--task-done");
81
- const stale = findStaleInstances(30 * 60_000);
82
- assert.strictEqual(stale.length, 0);
83
- });
84
- });
85
- describe("findStaleInstances — merging instances (#267)", () => {
86
- it("detects merging instance older than merging threshold", () => {
87
- const db = getDb();
88
- db.prepare(`
89
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
90
- VALUES (?, ?, ?, ?, 'merging', datetime('now', '-30 minutes'))
91
- `).run("test-squad--stuck-merge", "test-squad", "/tmp/wt-merge1", "test-squad/instance/merge1");
92
- // Task completed 10 minutes ago — merging has been stuck since then
93
- db.prepare(`
94
- INSERT INTO agent_tasks (task_id, agent_slug, description, status, instance_id, started_at, completed_at)
95
- VALUES (?, ?, ?, 'done', ?, datetime('now', '-15 minutes'), datetime('now', '-10 minutes'))
96
- `).run("task-merge-1", "agent-1", "Work done", "test-squad--stuck-merge");
97
- // 10 min since last task completed > 5 min merging threshold
98
- const stale = findStaleInstances(30 * 60_000, 5 * 60_000);
99
- assert.strictEqual(stale.length, 1);
100
- assert.strictEqual(stale[0].instance.id, "test-squad--stuck-merge");
101
- assert.strictEqual(stale[0].instance.status, "merging");
102
- });
103
- it("does not flag merging instance younger than merging threshold", () => {
104
- const db = getDb();
105
- db.prepare(`
106
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
107
- VALUES (?, ?, ?, ?, 'merging', datetime('now', '-30 minutes'))
108
- `).run("test-squad--fresh-merge", "test-squad", "/tmp/wt-merge2", "test-squad/instance/merge2");
109
- // Task completed 2 minutes ago — merging just started
110
- db.prepare(`
111
- INSERT INTO agent_tasks (task_id, agent_slug, description, status, instance_id, started_at, completed_at)
112
- VALUES (?, ?, ?, 'done', ?, datetime('now', '-5 minutes'), datetime('now', '-2 minutes'))
113
- `).run("task-merge-2", "agent-1", "Work done", "test-squad--fresh-merge");
114
- // 2 min since last task completed < 5 min merging threshold
115
- const stale = findStaleInstances(30 * 60_000, 5 * 60_000);
116
- assert.strictEqual(stale.length, 0);
117
- });
118
- it("uses created_at as fallback when merging instance has no tasks", () => {
119
- const db = getDb();
120
- db.prepare(`
121
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
122
- VALUES (?, ?, ?, ?, 'merging', datetime('now', '-10 minutes'))
123
- `).run("test-squad--no-tasks-merge", "test-squad", "/tmp/wt-merge3", "test-squad/instance/merge3");
124
- // No tasks at all — falls back to created_at (10 min ago > 5 min threshold)
125
- const stale = findStaleInstances(30 * 60_000, 5 * 60_000);
126
- assert.strictEqual(stale.length, 1);
127
- assert.strictEqual(stale[0].instance.id, "test-squad--no-tasks-merge");
128
- });
129
- it("does not apply done-task skip logic to merging instances", () => {
130
- const db = getDb();
131
- db.prepare(`
132
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
133
- VALUES (?, ?, ?, ?, 'merging', datetime('now', '-30 minutes'))
134
- `).run("test-squad--merging-done-task", "test-squad", "/tmp/wt-merge4", "test-squad/instance/merge4");
135
- // Latest task is done — but for merging instances this should NOT skip
136
- db.prepare(`
137
- INSERT INTO agent_tasks (task_id, agent_slug, description, status, instance_id, started_at, completed_at)
138
- VALUES (?, ?, ?, 'done', ?, datetime('now', '-20 minutes'), datetime('now', '-10 minutes'))
139
- `).run("task-merge-4", "agent-1", "Done", "test-squad--merging-done-task");
140
- // 10 min since task completed > 5 min merging threshold — should be detected
141
- const stale = findStaleInstances(30 * 60_000, 5 * 60_000);
142
- assert.strictEqual(stale.length, 1);
143
- assert.strictEqual(stale[0].instance.id, "test-squad--merging-done-task");
144
- });
145
- });
146
- describe("startInstanceWatchdog", () => {
147
- it("calls onAbort for stale instances and stops cleanly", async () => {
148
- const db = getDb();
149
- db.prepare(`
150
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
151
- VALUES (?, ?, ?, ?, 'active', datetime('now', '-60 minutes'))
152
- `).run("test-squad--stale", "test-squad", "/tmp/wt5", "test-squad/instance/stale");
153
- const aborted = [];
154
- const stop = startInstanceWatchdog({
155
- checkIntervalMs: 50,
156
- staleThresholdMs: 30 * 60_000,
157
- onAbort: (inst) => aborted.push(inst.id),
158
- });
159
- await new Promise((r) => setTimeout(r, 150));
160
- stop();
161
- assert.ok(aborted.includes("test-squad--stale"));
162
- const row = db.prepare("SELECT status FROM squad_instances WHERE id = ?").get("test-squad--stale");
163
- assert.strictEqual(row.status, "failed");
164
- });
165
- it("stop function prevents further checks", async () => {
166
- const db = getDb();
167
- db.prepare(`
168
- INSERT INTO squad_instances (id, master_squad_slug, worktree_path, branch_name, status, created_at)
169
- VALUES (?, ?, ?, ?, 'active', datetime('now', '-60 minutes'))
170
- `).run("test-squad--late", "test-squad", "/tmp/wt6", "test-squad/instance/late");
171
- let abortCount = 0;
172
- const stop = startInstanceWatchdog({
173
- checkIntervalMs: 50,
174
- staleThresholdMs: 30 * 60_000,
175
- onAbort: () => abortCount++,
176
- });
177
- stop();
178
- await new Promise((r) => setTimeout(r, 150));
179
- assert.strictEqual(abortCount, 0);
180
- });
181
- });
182
- });
183
- //# sourceMappingURL=instance-watchdog.test.js.map
@@ -1,109 +0,0 @@
1
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
4
- export class McpConnectionManager {
5
- connections = new Map();
6
- connecting = new Map();
7
- async getClient(config) {
8
- const existing = this.connections.get(config.name);
9
- if (existing)
10
- return existing;
11
- // Deduplicate concurrent connection attempts
12
- const pending = this.connecting.get(config.name);
13
- if (pending)
14
- return pending;
15
- const promise = this.connect(config);
16
- this.connecting.set(config.name, promise);
17
- try {
18
- const client = await promise;
19
- this.connections.set(config.name, client);
20
- return client;
21
- }
22
- finally {
23
- this.connecting.delete(config.name);
24
- }
25
- }
26
- async connect(config) {
27
- const client = new Client({ name: "io-assistant", version: "1.0.0" }, { capabilities: {} });
28
- let transport;
29
- if (config.url) {
30
- transport = new SSEClientTransport(new URL(config.url));
31
- }
32
- else if (config.command) {
33
- transport = new StdioClientTransport({
34
- command: config.command,
35
- args: config.args,
36
- env: config.env,
37
- });
38
- }
39
- else {
40
- throw new Error(`MCP server "${config.name}" has no command or url configured`);
41
- }
42
- await client.connect(transport);
43
- return client;
44
- }
45
- async listTools(config) {
46
- const execute = async () => {
47
- const client = await this.getClient(config);
48
- const result = await client.listTools();
49
- return (result.tools ?? []).map((t) => ({
50
- name: t.name,
51
- description: t.description,
52
- inputSchema: t.inputSchema,
53
- }));
54
- };
55
- try {
56
- return await execute();
57
- }
58
- catch (err) {
59
- console.error(`[mcp] listTools failed for ${config.name}, attempting reconnect:`, err instanceof Error ? err.message : err);
60
- this.connections.delete(config.name);
61
- return await execute();
62
- }
63
- }
64
- async callTool(config, toolName, args) {
65
- const execute = async () => {
66
- const client = await this.getClient(config);
67
- const result = await client.callTool({ name: toolName, arguments: args });
68
- // MCP returns content as an array of content blocks
69
- if (result.content && Array.isArray(result.content)) {
70
- return result.content
71
- .map((block) => block.type === "text" ? block.text : JSON.stringify(block))
72
- .join("\n");
73
- }
74
- return result.content ?? result;
75
- };
76
- try {
77
- return await execute();
78
- }
79
- catch (err) {
80
- // Connection likely dead — clear and retry once
81
- console.error(`[mcp] Tool call failed for ${config.name}/${toolName}, attempting reconnect:`, err instanceof Error ? err.message : err);
82
- this.connections.delete(config.name);
83
- try {
84
- return await execute();
85
- }
86
- catch (retryErr) {
87
- throw new Error(`MCP tool ${config.name}/${toolName} failed after reconnect: ${retryErr instanceof Error ? retryErr.message : String(retryErr)}`);
88
- }
89
- }
90
- }
91
- async disconnect(name) {
92
- const client = this.connections.get(name);
93
- if (client) {
94
- try {
95
- await client.close();
96
- }
97
- catch { /* ignore */ }
98
- this.connections.delete(name);
99
- }
100
- }
101
- async disconnectAll() {
102
- const names = [...this.connections.keys()];
103
- await Promise.allSettled(names.map((n) => this.disconnect(n)));
104
- }
105
- isConnected(name) {
106
- return this.connections.has(name);
107
- }
108
- }
109
- //# sourceMappingURL=client.js.map
@@ -1,99 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { McpConnectionManager } from "./client.js";
4
- describe("McpConnectionManager — auto-reconnect", () => {
5
- const testConfig = { name: "test-server", command: "echo", args: ["hello"] };
6
- it("callTool retries once on connection failure", async () => {
7
- const manager = new McpConnectionManager();
8
- let attempts = 0;
9
- // Inject a mock client that fails on first callTool, succeeds on second
10
- const mockClient = {
11
- callTool: async () => {
12
- attempts++;
13
- if (attempts === 1)
14
- throw new Error("connection reset");
15
- return { content: [{ type: "text", text: "success" }] };
16
- },
17
- listTools: async () => ({ tools: [] }),
18
- close: async () => { },
19
- };
20
- // Inject into connections map
21
- manager.connections.set("test-server", mockClient);
22
- // Override getClient to return a fresh mock on reconnect
23
- const originalGetClient = manager.getClient.bind(manager);
24
- manager.getClient = async (config) => {
25
- if (!manager.connections.has(config.name)) {
26
- // Simulate reconnect — put a working mock
27
- const freshMock = {
28
- callTool: async () => ({ content: [{ type: "text", text: "reconnected" }] }),
29
- close: async () => { },
30
- };
31
- manager.connections.set(config.name, freshMock);
32
- return freshMock;
33
- }
34
- return manager.connections.get(config.name);
35
- };
36
- const result = await manager.callTool(testConfig, "test_tool", {});
37
- assert.equal(result, "reconnected");
38
- });
39
- it("callTool throws after retry also fails", async () => {
40
- const manager = new McpConnectionManager();
41
- const failingClient = {
42
- callTool: async () => { throw new Error("permanently broken"); },
43
- close: async () => { },
44
- };
45
- manager.connections.set("test-server", failingClient);
46
- // Override getClient to always return a broken client
47
- manager.getClient = async () => failingClient;
48
- await assert.rejects(() => manager.callTool(testConfig, "test_tool", {}), (err) => {
49
- assert.ok(err.message.includes("failed after reconnect"));
50
- return true;
51
- });
52
- });
53
- it("listTools retries once on connection failure", async () => {
54
- const manager = new McpConnectionManager();
55
- let attempts = 0;
56
- const mockClient = {
57
- listTools: async () => {
58
- attempts++;
59
- if (attempts === 1)
60
- throw new Error("connection lost");
61
- return { tools: [{ name: "tool1", description: "A tool", inputSchema: {} }] };
62
- },
63
- close: async () => { },
64
- };
65
- manager.connections.set("test-server", mockClient);
66
- manager.getClient = async (config) => {
67
- if (!manager.connections.has(config.name)) {
68
- const freshMock = {
69
- listTools: async () => ({ tools: [{ name: "tool1", description: "A tool", inputSchema: {} }] }),
70
- close: async () => { },
71
- };
72
- manager.connections.set(config.name, freshMock);
73
- return freshMock;
74
- }
75
- return manager.connections.get(config.name);
76
- };
77
- const tools = await manager.listTools(testConfig);
78
- assert.equal(tools.length, 1);
79
- assert.equal(tools[0].name, "tool1");
80
- });
81
- it("clears dead connection from map on failure", async () => {
82
- const manager = new McpConnectionManager();
83
- const deadClient = {
84
- callTool: async () => { throw new Error("dead"); },
85
- close: async () => { },
86
- };
87
- manager.connections.set("test-server", deadClient);
88
- assert.ok(manager.isConnected("test-server"));
89
- // Override getClient to simulate a reconnect failure too
90
- manager.getClient = async () => { throw new Error("cannot reconnect"); };
91
- try {
92
- await manager.callTool(testConfig, "test_tool", {});
93
- }
94
- catch { /* expected */ }
95
- // Dead connection should have been cleared
96
- assert.ok(!manager.isConnected("test-server"));
97
- });
98
- });
99
- //# sourceMappingURL=client.test.js.map
@@ -1,49 +0,0 @@
1
- import { describe, it, before, after } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { mkdtempSync, rmSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
- // We need to override MCP_CONFIG_PATH for testing.
7
- // Since config.ts uses IO_HOME from paths.ts, we'll test by directly
8
- // exercising the functions with a mocked path approach.
9
- import { loadMcpConfig, saveMcpConfig } from "./config.js";
10
- describe("MCP config", () => {
11
- let tmpDir;
12
- let originalConfigPath;
13
- before(() => {
14
- tmpDir = mkdtempSync(join(tmpdir(), "io-mcp-config-test-"));
15
- });
16
- after(() => {
17
- rmSync(tmpDir, { recursive: true, force: true });
18
- });
19
- it("loadMcpConfig returns empty servers when no file exists", () => {
20
- // MCP_CONFIG_PATH points to ~/.io/mcp.json which may or may not exist
21
- // but the function handles missing files gracefully
22
- const config = loadMcpConfig();
23
- assert.ok(Array.isArray(config.servers));
24
- });
25
- it("saveMcpConfig and loadMcpConfig round-trip correctly", () => {
26
- const testConfig = {
27
- servers: [
28
- { name: "figma", command: "npx", args: ["-y", "@anthropic/mcp-server-figma"], enabled: true },
29
- { name: "postgres", url: "http://localhost:3001/sse", enabled: false },
30
- ],
31
- };
32
- saveMcpConfig(testConfig);
33
- const loaded = loadMcpConfig();
34
- assert.equal(loaded.servers.length, 2);
35
- assert.equal(loaded.servers[0].name, "figma");
36
- assert.equal(loaded.servers[0].command, "npx");
37
- assert.deepEqual(loaded.servers[0].args, ["-y", "@anthropic/mcp-server-figma"]);
38
- assert.equal(loaded.servers[1].name, "postgres");
39
- assert.equal(loaded.servers[1].url, "http://localhost:3001/sse");
40
- assert.equal(loaded.servers[1].enabled, false);
41
- });
42
- it("loadMcpConfig handles malformed JSON gracefully", () => {
43
- // This test verifies the catch block — in production, a corrupt file
44
- // won't crash the app
45
- const config = loadMcpConfig();
46
- assert.ok(config.servers !== undefined);
47
- });
48
- });
49
- //# sourceMappingURL=config.test.js.map
@@ -1,79 +0,0 @@
1
- import { describe, it } from "node:test";
2
- import assert from "node:assert/strict";
3
- import { createMcpTools } from "./registry.js";
4
- // Mock connection manager that returns predefined tools
5
- function createMockManager(toolsMap) {
6
- return {
7
- listTools: async (config) => {
8
- return toolsMap[config.name] ?? [];
9
- },
10
- callTool: async (_config, toolName, args) => {
11
- return `Called ${toolName} with ${JSON.stringify(args)}`;
12
- },
13
- getClient: async () => { throw new Error("not needed"); },
14
- disconnect: async () => { },
15
- disconnectAll: async () => { },
16
- isConnected: () => false,
17
- };
18
- }
19
- describe("MCP registry", () => {
20
- it("creates namespaced tools from MCP server tools", async () => {
21
- const manager = createMockManager({
22
- figma: [
23
- { name: "get_file", description: "Get a Figma file", inputSchema: { type: "object", properties: { file_key: { type: "string", description: "Figma file key" } }, required: ["file_key"] } },
24
- { name: "list_projects", description: "List projects" },
25
- ],
26
- });
27
- const config = {
28
- servers: [{ name: "figma", command: "npx", args: ["-y", "@anthropic/mcp-figma"], enabled: true }],
29
- };
30
- const entries = await createMcpTools(manager, config);
31
- assert.equal(entries.length, 2);
32
- assert.equal(entries[0].tool.name, "mcp_figma_get_file");
33
- assert.equal(entries[1].tool.name, "mcp_figma_list_projects");
34
- assert.equal(entries[0].serverName, "figma");
35
- assert.equal(entries[0].mcpToolName, "get_file");
36
- });
37
- it("skips disabled servers", async () => {
38
- const manager = createMockManager({
39
- figma: [{ name: "get_file", description: "Get file" }],
40
- postgres: [{ name: "query", description: "Run query" }],
41
- });
42
- const config = {
43
- servers: [
44
- { name: "figma", command: "npx", enabled: true },
45
- { name: "postgres", command: "pg-mcp", enabled: false },
46
- ],
47
- };
48
- const entries = await createMcpTools(manager, config);
49
- assert.equal(entries.length, 1);
50
- assert.equal(entries[0].serverName, "figma");
51
- });
52
- it("sanitizes tool names to valid identifiers", async () => {
53
- const manager = createMockManager({
54
- "my-server": [{ name: "get-data.v2", description: "Get data" }],
55
- });
56
- const config = {
57
- servers: [{ name: "my-server", command: "cmd", enabled: true }],
58
- };
59
- const entries = await createMcpTools(manager, config);
60
- assert.equal(entries[0].tool.name, "mcp_my_server_get_data_v2");
61
- });
62
- it("handles server connection failure gracefully", async () => {
63
- const manager = {
64
- listTools: async () => { throw new Error("Connection refused"); },
65
- callTool: async () => { throw new Error("not connected"); },
66
- getClient: async () => { throw new Error("not connected"); },
67
- disconnect: async () => { },
68
- disconnectAll: async () => { },
69
- isConnected: () => false,
70
- };
71
- const config = {
72
- servers: [{ name: "broken", command: "bad-cmd", enabled: true }],
73
- };
74
- // Should not throw — just returns empty
75
- const entries = await createMcpTools(manager, config);
76
- assert.equal(entries.length, 0);
77
- });
78
- });
79
- //# sourceMappingURL=registry.test.js.map