@aiworker/web 1.23.0 → 1.23.2
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.
- package/dist/assets/{CodeMirrorCommentWidgets-B1Gizi3a.js → CodeMirrorCommentWidgets-COGJG0Iv.js} +1 -1
- package/dist/assets/DiffView-BviYY3zL.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-aig6zJjg.js → DirtyBranchSwitchDialog-C26DvfVJ.js} +1 -1
- package/dist/assets/FilesView-D0ZU_nCt.js +13 -0
- package/dist/assets/{GitView-BXsS3jG6.js → GitView-CYgiDRH-.js} +4 -4
- package/dist/assets/{JsonTreeView-D_hpXBnF.js → JsonTreeView-GsV9UScz.js} +1 -1
- package/dist/assets/{LinearIssuesView-BoUiLQG1.js → LinearIssuesView-shqUS8nl.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-B_B_a9KS.js → MarkdownImageGallery-CQSTFp6m.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-xgyyLiBM.js → MarkdownRendererImpl-DJWP3A8X.js} +2 -2
- package/dist/assets/{OnboardingScreen-DIp84OWt.js → OnboardingScreen-CTuu4lgo.js} +1 -1
- package/dist/assets/{PatchDiff-8p6nLJaU.js → PatchDiff-Dp53v2pl.js} +1 -1
- package/dist/assets/{PierreDiffViewer-DjC8nTk9.js → PierreDiffViewer-B5l0djPS.js} +1 -1
- package/dist/assets/PlanView-CLUWkGiG.js +5 -0
- package/dist/assets/SettingsView-CojPQVHx.js +28 -0
- package/dist/assets/{SettingsWindow-Cpb4hM6q.js → SettingsWindow-DbgEnZ6T.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DfaKZXNU.js → ToolOutputDialog-Du-RZj-a.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-DtZLzrSK.js → ToolPartDiffPreview-HBLSokoe.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-C8i9HpTB.js → VirtualizedFileDiff-Bzp3hClU.js} +4 -4
- package/dist/assets/WalkthroughView-CpgA4s9w.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-BBI7ZwrC.js → computeVirtualFileMetrics-CI1PC_z2.js} +2 -2
- package/dist/assets/de-BX8b4hDD.js +10 -0
- package/dist/assets/es-e98cS-yM.js +16 -0
- package/dist/assets/fr-BOiqxJAs.js +14 -0
- package/dist/assets/index-BD8ILbxF.js +40 -0
- package/dist/assets/{index-jXSK5RrB.js → index-Cmn74sw-.js} +1 -1
- package/dist/assets/index-zhgg-SDz.css +1 -0
- package/dist/assets/{isDiffPlainText-B_x_rVon.js → isDiffPlainText-DVralkU-.js} +1 -1
- package/dist/assets/{isFilePlainText-DW_xMer1.js → isFilePlainText-CgTREsRX.js} +1 -1
- package/dist/assets/ja-aoO55hGu.js +16 -0
- package/dist/assets/{ko-idhXGF8j.js → ko-BGzFLogk.js} +3 -3
- package/dist/assets/{main-CzdPuL0s.js → main-BgfXQ-4g.js} +2 -2
- package/dist/assets/main-DGYUWmIt.js +930 -0
- package/dist/assets/{markdownCore-Cn4Tyejo.js → markdownCore-BesaNs_G.js} +3 -3
- package/dist/assets/{miniChat-CCkqKOLp.js → miniChat-DHKXp-_I.js} +2 -2
- package/dist/assets/{mobile-mvxTo055.js → mobile-lXQ08VnX.js} +2 -2
- package/dist/assets/patchFileDiff-i1lTtNbn.js +13 -0
- package/dist/assets/{pl-CGZWUqZJ.js → pl-B5x19laq.js} +3 -3
- package/dist/assets/pt-BR-C3oU51Il.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-CuO4ue6B.js +2 -0
- package/dist/assets/renderMobileApp-B3zFlHy4.js +25 -0
- package/dist/assets/runtimeEndpointReset-BLzrtrmj.js +41 -0
- package/dist/assets/scheduledTasksApi-BEuUF_cj.js +1 -0
- package/dist/assets/{shikiHighlight-CRl0SUC9.js → shikiHighlight-ctlcPvvx.js} +1 -1
- package/dist/assets/surface-COKb77Ua.js +1 -0
- package/dist/assets/tr-C0QQa7et.js +7 -0
- package/dist/assets/uk-CqLSe9wT.js +16 -0
- package/dist/assets/{useAppFontEffects-CPKeOpUo.js → useAppFontEffects-B6OfEypo.js} +153 -155
- package/dist/assets/useGitComparison-BXZXEAW6.js +1 -0
- package/dist/assets/{useInlineCommentController-BiWz4AVb.js → useInlineCommentController-CgbrpEWu.js} +2 -2
- package/dist/assets/{useRootScrollLock-BS4-kr7P.js → useRootScrollLock-Me41OjBT.js} +1 -1
- package/dist/assets/{vendor-base-ui-DdV8vhHn.js → vendor-base-ui-BY_5qla_.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-Bg4AEeCr.js → vendor-codemirror-language-data-SJuFp0a0.js} +2 -2
- package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
- package/dist/assets/{vendor-zod-BPAANqvH.js → vendor-zod-B6551dwG.js} +2 -2
- package/dist/assets/{web-components-z7hfnS8n.js → web-components-D8GS8Ork.js} +1 -1
- package/dist/assets/zh-CN-iJEie4d6.js +16 -0
- package/dist/assets/zh-TW-CyslEwlK.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +1 -1
- package/server/index.js +3 -13
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/agent-memory/runtime.test.js +22 -0
- package/server/lib/event-stream/DOCUMENTATION.md +3 -0
- package/server/lib/event-stream/global-hub.js +29 -4
- package/server/lib/event-stream/global-hub.test.js +22 -0
- package/server/lib/event-stream/global-ws-bridge.js +15 -18
- package/server/lib/event-stream/protocol.js +21 -7
- package/server/lib/event-stream/runtime.js +9 -6
- package/server/lib/event-stream/runtime.test.js +60 -0
- package/server/lib/git/DOCUMENTATION.md +10 -1
- package/server/lib/git/routes.js +21 -8
- package/server/lib/git/routes.test.js +78 -0
- package/server/lib/git/service.js +159 -4
- package/server/lib/git/service.test.js +74 -0
- package/server/lib/github/DOCUMENTATION.md +5 -0
- package/server/lib/github/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +7 -0
- package/server/lib/message-queue/runtime.js +13 -0
- package/server/lib/message-queue/runtime.test.js +31 -1
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/emitter-runtime.js +4 -3
- package/server/lib/opencode/DOCUMENTATION.md +18 -4
- package/server/lib/opencode/env-runtime.js +5 -1
- package/server/lib/opencode/env-runtime.test.js +72 -0
- package/server/lib/opencode/feature-routes-runtime.js +15 -1
- package/server/lib/opencode/lifecycle.js +4 -3
- package/server/lib/opencode/lifecycle.test.js +29 -0
- package/server/lib/opencode/managed-plugin-config.js +1 -1
- package/server/lib/opencode/proxy.js +33 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +11 -1
- package/server/lib/opencode/settings-registry.json +3 -0
- package/server/lib/opencode/settings-runtime.js +36 -9
- package/server/lib/opencode/settings-runtime.test.js +158 -2
- package/server/lib/project-context/DOCUMENTATION.md +13 -3
- package/server/lib/project-context/runtime.js +8 -2
- package/server/lib/project-context/runtime.test.js +54 -0
- package/server/lib/projects/DOCUMENTATION.md +2 -1
- package/server/lib/projects/project-config.js +38 -9
- package/server/lib/projects/project-config.test.js +97 -0
- package/server/lib/projects/project-id.js +26 -0
- package/server/lib/relay/DOCUMENTATION.md +20 -0
- package/server/lib/relay/host-client.js +7 -0
- package/server/lib/relay/host-client.test.js +14 -0
- package/server/lib/scheduled-tasks/DOCUMENTATION.md +9 -1
- package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +28 -0
- package/server/lib/scheduled-tasks/runtime.js +12 -2
- package/server/lib/scheduled-tasks/runtime.test.js +53 -0
- package/server/lib/session-assist/DOCUMENTATION.md +131 -66
- package/server/lib/session-assist/context.js +127 -0
- package/server/lib/session-assist/context.test.js +132 -0
- package/server/lib/session-assist/prompt.js +54 -0
- package/server/lib/session-assist/runtime.js +111 -257
- package/server/lib/session-assist/runtime.test.js +203 -0
- package/server/lib/walkthrough/DOCUMENTATION.md +15 -5
- package/server/lib/walkthrough/pr-source.test.js +21 -0
- package/server/lib/walkthrough/pull-request.js +7 -4
- package/server/lib/walkthrough/pull-request.test.js +16 -0
- package/server/lib/walkthrough/routes.js +19 -0
- package/server/lib/walkthrough/routes.test.js +26 -0
- package/server/lib/walkthrough/sources.js +13 -2
- package/server/opencode-worktree-readiness.test.js +130 -0
- package/dist/assets/DiffView-DXjVsEOw.js +0 -4
- package/dist/assets/FilesView-CJdG0-wk.js +0 -17
- package/dist/assets/PlanView-CJTmOF6I.js +0 -5
- package/dist/assets/SettingsView-DD-JqIJx.js +0 -28
- package/dist/assets/WalkthroughView-DeKMvZlL.js +0 -4
- package/dist/assets/de-DCrsQ5zS.js +0 -10
- package/dist/assets/es-Dwv4YfH6.js +0 -16
- package/dist/assets/fr-BCWg4Cnx.js +0 -14
- package/dist/assets/index-B68h5S5B.css +0 -1
- package/dist/assets/index-DVwMarHI.js +0 -39
- package/dist/assets/ja-Bruw3RYC.js +0 -16
- package/dist/assets/main-BkyaQhJX.js +0 -930
- package/dist/assets/patchFileDiff-Csk4iNUi.js +0 -13
- package/dist/assets/pt-BR-B8V7u7tA.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-BxoyujA5.js +0 -2
- package/dist/assets/renderMobileApp-B48CsP4r.js +0 -25
- package/dist/assets/runtimeEndpointReset-Bg5gx18H.js +0 -17
- package/dist/assets/scheduledTasksApi-BW0Etzwz.js +0 -1
- package/dist/assets/surface-oMvhsog3.js +0 -1
- package/dist/assets/tr-BK_KiO2V.js +0 -7
- package/dist/assets/uk-CG74xV8N.js +0 -16
- package/dist/assets/useGitComparison-DH220WmO.js +0 -1
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
- package/dist/assets/zh-CN-T4AXofZI.js +0 -16
- package/dist/assets/zh-TW-Dte40sxp.js +0 -16
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +0 -55
- package/server/lib/mcp-reconnect/runtime.js +0 -122
- package/server/lib/mcp-reconnect/runtime.test.js +0 -140
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Managed MCP Reconnect
|
|
2
|
-
|
|
3
|
-
## Purpose
|
|
4
|
-
|
|
5
|
-
OpenCode connects each configured MCP server once, when a project directory is
|
|
6
|
-
first used. A server that does not come up then is marked `failed` and never
|
|
7
|
-
retried; a server whose live connection later drops is marked `failed` too and
|
|
8
|
-
stays that way until OpenCode restarts. This module injects a small plugin into
|
|
9
|
-
the OpenCode process AiWorker launches that reconnects those servers, so a
|
|
10
|
-
server that was slow to start or crashed mid-session comes back on its own.
|
|
11
|
-
|
|
12
|
-
## Runtime flow
|
|
13
|
-
|
|
14
|
-
1. `prepareManagedOpenCodeEnv(configContent)` materializes the plugin under
|
|
15
|
-
`<openchamber-data-dir>/mcp-reconnect/` and appends its `file://` URL to
|
|
16
|
-
`OPENCODE_CONFIG_CONTENT` through the shared merge in
|
|
17
|
-
`packages/web/server/lib/opencode/managed-plugin-config.js`.
|
|
18
|
-
2. It is always on for managed OpenCode. There is no setting, because it only
|
|
19
|
-
acts on servers OpenCode has already given up on.
|
|
20
|
-
3. OpenCode loads the plugin once per project directory with an SDK client
|
|
21
|
-
scoped to that directory, so each directory reconnects its own servers.
|
|
22
|
-
4. The plugin reads MCP status one second after load, calls connect for every
|
|
23
|
-
server in the `failed` state, then re-reads status after a per-server delay
|
|
24
|
-
that doubles from one second to a cap of thirty. A server seen in any other
|
|
25
|
-
state resets its counter. While nothing is failed it checks every thirty
|
|
26
|
-
seconds.
|
|
27
|
-
5. A dropped connection publishes `mcp.tools.changed`, which the plugin uses to
|
|
28
|
-
check right away instead of waiting out the idle interval.
|
|
29
|
-
6. OpenCode calls the plugin's `dispose` hook when it tears the directory down,
|
|
30
|
-
which stops the loop.
|
|
31
|
-
|
|
32
|
-
## Invariants
|
|
33
|
-
|
|
34
|
-
- Only `failed` is retried. `disabled` is the user's choice, and `needs_auth`
|
|
35
|
-
or `needs_client_registration` need the user to act; retrying those would
|
|
36
|
-
either re-enable a server the user turned off or loop on a login prompt.
|
|
37
|
-
- The plugin logs nothing and swallows every error. OpenCode already logs each
|
|
38
|
-
failed attempt, and a status call failing during an OpenCode restart is not
|
|
39
|
-
news.
|
|
40
|
-
- One check runs at a time; a wake-up arriving during a check is honored once
|
|
41
|
-
it finishes rather than starting a second loop.
|
|
42
|
-
|
|
43
|
-
## What the UI sees
|
|
44
|
-
|
|
45
|
-
OpenCode publishes no event when a reconnect succeeds. The chat picks the
|
|
46
|
-
server up on the next prompt because tools are resolved from live state, but
|
|
47
|
-
the MCP page reads status on bootstrap and refresh, so it can show `failed` for
|
|
48
|
-
a while after the server is back.
|
|
49
|
-
|
|
50
|
-
## Runtime parity
|
|
51
|
-
|
|
52
|
-
- Web and Desktop managed OpenCode: injected automatically.
|
|
53
|
-
- External OpenCode (`OPENCODE_HOST` or skip-start) and VS Code's separate
|
|
54
|
-
OpenCode lifecycle: not injected, because AiWorker does not control that
|
|
55
|
-
process environment.
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { pathToFileURL } from 'node:url';
|
|
2
|
-
import { appendManagedPlugin } from '../opencode/managed-plugin-config.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* OpenCode marks an MCP server `failed` when it does not come up at startup or
|
|
6
|
-
* when a live connection drops, and never tries again. This plugin runs inside
|
|
7
|
-
* the managed OpenCode process and reconnects those servers with a per-server
|
|
8
|
-
* exponential backoff, so a server that was merely slow to start, or a local
|
|
9
|
-
* one that crashed, comes back without an OpenCode restart.
|
|
10
|
-
*
|
|
11
|
-
* Only `failed` is retried. `needs_auth`, `needs_client_registration`, and
|
|
12
|
-
* `disabled` are user decisions or need user action, and retrying them would
|
|
13
|
-
* either loop on a login prompt or re-enable a server the user turned off.
|
|
14
|
-
*
|
|
15
|
-
* The plugin talks to OpenCode through the SDK client OpenCode hands it, which
|
|
16
|
-
* is scoped to one project directory, so each open directory reconnects its
|
|
17
|
-
* own servers. Nothing is logged: OpenCode already reports each failed attempt.
|
|
18
|
-
*/
|
|
19
|
-
const createPluginSource = () => String.raw`
|
|
20
|
-
const INITIAL_RETRY_MS = 1000
|
|
21
|
-
const MAX_RETRY_MS = 30000
|
|
22
|
-
const IDLE_CHECK_MS = 30000
|
|
23
|
-
|
|
24
|
-
export const AiWorkerMcpReconnectPlugin = async ({ client }) => {
|
|
25
|
-
let disposed = false
|
|
26
|
-
let running = false
|
|
27
|
-
let wakeRequested = false
|
|
28
|
-
let timer
|
|
29
|
-
// Consecutive failed attempts per server, cleared once it is seen healthy.
|
|
30
|
-
const attempts = new Map()
|
|
31
|
-
const dueAt = new Map()
|
|
32
|
-
|
|
33
|
-
const schedule = (delayMs) => {
|
|
34
|
-
if (disposed) return
|
|
35
|
-
clearTimeout(timer)
|
|
36
|
-
timer = setTimeout(tick, delayMs)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const tick = async () => {
|
|
40
|
-
if (running) {
|
|
41
|
-
wakeRequested = true
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
running = true
|
|
45
|
-
let delay = IDLE_CHECK_MS
|
|
46
|
-
try {
|
|
47
|
-
const statuses = (await client.mcp.status())?.data ?? {}
|
|
48
|
-
const now = Date.now()
|
|
49
|
-
const due = []
|
|
50
|
-
for (const [name, entry] of Object.entries(statuses)) {
|
|
51
|
-
if (entry?.status !== "failed") {
|
|
52
|
-
attempts.delete(name)
|
|
53
|
-
dueAt.delete(name)
|
|
54
|
-
continue
|
|
55
|
-
}
|
|
56
|
-
const at = dueAt.get(name) ?? now
|
|
57
|
-
if (at > now) {
|
|
58
|
-
delay = Math.min(delay, at - now)
|
|
59
|
-
continue
|
|
60
|
-
}
|
|
61
|
-
due.push(name)
|
|
62
|
-
}
|
|
63
|
-
for (const name of attempts.keys()) {
|
|
64
|
-
if (!Object.hasOwn(statuses, name)) {
|
|
65
|
-
attempts.delete(name)
|
|
66
|
-
dueAt.delete(name)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
await Promise.allSettled(due.map((name) => client.mcp.connect({ path: { name } })))
|
|
71
|
-
|
|
72
|
-
// The result is read on the next tick: a server that came back clears
|
|
73
|
-
// its counter there, one still failed waits out its backoff.
|
|
74
|
-
const after = Date.now()
|
|
75
|
-
for (const name of due) {
|
|
76
|
-
const count = (attempts.get(name) ?? 0) + 1
|
|
77
|
-
const wait = Math.min(INITIAL_RETRY_MS * 2 ** (count - 1), MAX_RETRY_MS)
|
|
78
|
-
attempts.set(name, count)
|
|
79
|
-
dueAt.set(name, after + wait)
|
|
80
|
-
delay = Math.min(delay, wait)
|
|
81
|
-
}
|
|
82
|
-
} catch {
|
|
83
|
-
// Status is unavailable while OpenCode is shutting down or restarting;
|
|
84
|
-
// the idle check picks up again when it is back.
|
|
85
|
-
} finally {
|
|
86
|
-
running = false
|
|
87
|
-
const wake = wakeRequested
|
|
88
|
-
wakeRequested = false
|
|
89
|
-
schedule(wake ? INITIAL_RETRY_MS : delay)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
schedule(INITIAL_RETRY_MS)
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
// A dropped connection publishes this event; checking right away beats
|
|
97
|
-
// waiting out the idle interval.
|
|
98
|
-
event: async ({ event }) => {
|
|
99
|
-
if (event?.type === "mcp.tools.changed") schedule(INITIAL_RETRY_MS)
|
|
100
|
-
},
|
|
101
|
-
dispose: async () => {
|
|
102
|
-
disposed = true
|
|
103
|
-
clearTimeout(timer)
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
`;
|
|
108
|
-
|
|
109
|
-
export const createMcpReconnectRuntime = ({ fsPromises, path, dataDir }) => {
|
|
110
|
-
const pluginDirectory = path.join(dataDir, 'mcp-reconnect');
|
|
111
|
-
const pluginPath = path.join(pluginDirectory, 'openchamber-mcp-reconnect-plugin.js');
|
|
112
|
-
|
|
113
|
-
const prepareManagedOpenCodeEnv = async (rawConfig) => {
|
|
114
|
-
await fsPromises.mkdir(pluginDirectory, { recursive: true });
|
|
115
|
-
await fsPromises.writeFile(pluginPath, createPluginSource(), { mode: 0o600 });
|
|
116
|
-
return {
|
|
117
|
-
OPENCODE_CONFIG_CONTENT: appendManagedPlugin(rawConfig, pathToFileURL(pluginPath).href, 'MCP reconnect plugin'),
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
return { prepareManagedOpenCodeEnv };
|
|
122
|
-
};
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs/promises';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { pathToFileURL } from 'node:url';
|
|
5
|
-
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { createMcpReconnectRuntime } from './runtime.js';
|
|
8
|
-
|
|
9
|
-
const temporaryDirectories = [];
|
|
10
|
-
const disposers = [];
|
|
11
|
-
|
|
12
|
-
afterEach(async () => {
|
|
13
|
-
await Promise.all(disposers.splice(0).map((dispose) => dispose()));
|
|
14
|
-
vi.useRealTimers();
|
|
15
|
-
await Promise.all(temporaryDirectories.splice(0).map((directory) => fs.rm(directory, { recursive: true, force: true })));
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const materialize = async (rawConfig = '{}') => {
|
|
19
|
-
const dataDir = await fs.mkdtemp(path.join(os.tmpdir(), 'openchamber-mcp-reconnect-'));
|
|
20
|
-
temporaryDirectories.push(dataDir);
|
|
21
|
-
const runtime = createMcpReconnectRuntime({ fsPromises: fs, path, dataDir });
|
|
22
|
-
const prepared = await runtime.prepareManagedOpenCodeEnv(rawConfig);
|
|
23
|
-
const pluginPath = path.join(dataDir, 'mcp-reconnect', 'openchamber-mcp-reconnect-plugin.js');
|
|
24
|
-
const pluginModule = await import(`${pathToFileURL(pluginPath).href}?test=${Date.now()}-${Math.random()}`);
|
|
25
|
-
return { prepared, pluginPath, plugin: pluginModule.AiWorkerMcpReconnectPlugin };
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A stand-in for the SDK client OpenCode hands to plugins. `statuses` is live
|
|
30
|
-
* state the test mutates; `connect` records when each attempt happened.
|
|
31
|
-
*/
|
|
32
|
-
const createClient = (statuses, { onConnect } = {}) => {
|
|
33
|
-
const attempts = [];
|
|
34
|
-
return {
|
|
35
|
-
attempts,
|
|
36
|
-
statuses,
|
|
37
|
-
mcp: {
|
|
38
|
-
status: vi.fn(async () => ({ data: { ...statuses } })),
|
|
39
|
-
connect: vi.fn(async ({ path: { name } }) => {
|
|
40
|
-
attempts.push({ name, at: Date.now() });
|
|
41
|
-
onConnect?.(name);
|
|
42
|
-
return { data: true };
|
|
43
|
-
}),
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const start = async (plugin, client) => {
|
|
49
|
-
const hooks = await plugin({ client });
|
|
50
|
-
disposers.push(hooks.dispose);
|
|
51
|
-
return hooks;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
describe('managed MCP reconnect runtime', () => {
|
|
55
|
-
it('materializes the plugin and preserves existing plugin entries', async () => {
|
|
56
|
-
const { prepared, pluginPath } = await materialize('{ "plugin": ["file:///existing.js"], "model": "test/model" }');
|
|
57
|
-
const config = JSON.parse(prepared.OPENCODE_CONFIG_CONTENT);
|
|
58
|
-
expect(config.model).toBe('test/model');
|
|
59
|
-
expect(config.plugin).toEqual(['file:///existing.js', pathToFileURL(pluginPath).href]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('reconnects only servers in the failed state', async () => {
|
|
63
|
-
vi.useFakeTimers();
|
|
64
|
-
const { plugin } = await materialize();
|
|
65
|
-
const client = createClient({
|
|
66
|
-
broken: { status: 'failed', error: 'spawn ENOENT' },
|
|
67
|
-
healthy: { status: 'connected' },
|
|
68
|
-
off: { status: 'disabled' },
|
|
69
|
-
login: { status: 'needs_auth' },
|
|
70
|
-
registration: { status: 'needs_client_registration', error: 'no client id' },
|
|
71
|
-
});
|
|
72
|
-
await start(plugin, client);
|
|
73
|
-
|
|
74
|
-
await vi.advanceTimersByTimeAsync(1000);
|
|
75
|
-
|
|
76
|
-
expect(client.attempts.map((attempt) => attempt.name)).toEqual(['broken']);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('backs off per server up to a cap while it keeps failing', async () => {
|
|
80
|
-
vi.useFakeTimers();
|
|
81
|
-
const { plugin } = await materialize();
|
|
82
|
-
const client = createClient({ broken: { status: 'failed', error: 'refused' } });
|
|
83
|
-
const started = Date.now();
|
|
84
|
-
await start(plugin, client);
|
|
85
|
-
|
|
86
|
-
await vi.advanceTimersByTimeAsync(92_000);
|
|
87
|
-
|
|
88
|
-
expect(client.attempts.map((attempt) => attempt.at - started)).toEqual([
|
|
89
|
-
1000, 2000, 4000, 8000, 16_000, 32_000, 62_000, 92_000,
|
|
90
|
-
]);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('stops retrying once a server is back and starts fresh when it drops again', async () => {
|
|
94
|
-
vi.useFakeTimers();
|
|
95
|
-
const { plugin } = await materialize();
|
|
96
|
-
const statuses = { flaky: { status: 'failed', error: 'refused' } };
|
|
97
|
-
const client = createClient(statuses, {
|
|
98
|
-
onConnect: () => { statuses.flaky = { status: 'connected' }; },
|
|
99
|
-
});
|
|
100
|
-
const hooks = await start(plugin, client);
|
|
101
|
-
|
|
102
|
-
await vi.advanceTimersByTimeAsync(60_000);
|
|
103
|
-
expect(client.attempts).toHaveLength(1);
|
|
104
|
-
|
|
105
|
-
statuses.flaky = { status: 'failed', error: 'Connection closed' };
|
|
106
|
-
await hooks.event({ event: { type: 'mcp.tools.changed', properties: { server: 'flaky' } } });
|
|
107
|
-
await vi.advanceTimersByTimeAsync(1000);
|
|
108
|
-
|
|
109
|
-
expect(client.attempts).toHaveLength(2);
|
|
110
|
-
expect(client.attempts[1].at - client.attempts[0].at).toBeGreaterThan(30_000);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('keeps going when status is temporarily unavailable', async () => {
|
|
114
|
-
vi.useFakeTimers();
|
|
115
|
-
const { plugin } = await materialize();
|
|
116
|
-
const client = createClient({ broken: { status: 'failed', error: 'refused' } });
|
|
117
|
-
client.mcp.status.mockRejectedValueOnce(new Error('ECONNREFUSED'));
|
|
118
|
-
await start(plugin, client);
|
|
119
|
-
|
|
120
|
-
await vi.advanceTimersByTimeAsync(1000);
|
|
121
|
-
expect(client.attempts).toHaveLength(0);
|
|
122
|
-
|
|
123
|
-
await vi.advanceTimersByTimeAsync(30_000);
|
|
124
|
-
expect(client.attempts).toHaveLength(1);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('does nothing after dispose', async () => {
|
|
128
|
-
vi.useFakeTimers();
|
|
129
|
-
const { plugin } = await materialize();
|
|
130
|
-
const client = createClient({ broken: { status: 'failed', error: 'refused' } });
|
|
131
|
-
const hooks = await plugin({ client });
|
|
132
|
-
|
|
133
|
-
await hooks.dispose();
|
|
134
|
-
await hooks.event({ event: { type: 'mcp.tools.changed', properties: { server: 'broken' } } });
|
|
135
|
-
await vi.advanceTimersByTimeAsync(120_000);
|
|
136
|
-
|
|
137
|
-
expect(client.mcp.status).not.toHaveBeenCalled();
|
|
138
|
-
expect(client.attempts).toHaveLength(0);
|
|
139
|
-
});
|
|
140
|
-
});
|