@sideboard-ai/core 0.1.348 → 0.1.350
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/{abletime-CGFJZB7L.js → abletime-TX7BTTR2.js} +5 -5
- package/dist/{abletime-3HRWLQZJ.js → abletime-URSRZW7P.js} +4 -4
- package/dist/{abletime-oauth-QNJQLHR4.js → abletime-oauth-QS3WPSCC.js} +3 -3
- package/dist/{abletime-oauth-JQDSH5OL.js → abletime-oauth-SL3NMNEC.js} +4 -4
- package/dist/{abletime-rest-TANL5TMY.js → abletime-rest-GGQLUO55.js} +3 -3
- package/dist/{abletime-rest-UQA2CRZN.js → abletime-rest-JZU6JJCV.js} +4 -4
- package/dist/agents/acp-runner.cjs +491 -0
- package/dist/agents/acp-runner.d.cts +46 -0
- package/dist/agents/acp-runner.d.ts +46 -0
- package/dist/agents/acp-runner.js +323 -0
- package/dist/agents/cursor-runner.js +3 -3
- package/dist/{agents-T4XBZZDA.js → agents-P5QIV24I.js} +38 -8
- package/dist/{agents-5MFGVK7C.js → agents-RGAV5OHD.js} +44 -13
- package/dist/{app-settings-SNOPJ7P5.js → app-settings-IA7ZZKWQ.js} +2 -2
- package/dist/{app-settings-PPIMYJKS.js → app-settings-XILTSD6L.js} +1 -1
- package/dist/{chunk-UGUWFONI.js → chunk-2E2HMJDU.js} +1 -1
- package/dist/{chunk-OH3BAUMC.js → chunk-2MESZ5XR.js} +273 -84
- package/dist/{chunk-RUIHNWRV.js → chunk-37ZBEBP6.js} +6 -6
- package/dist/{chunk-Y6VQX2LY.js → chunk-5AHWUJRT.js} +1927 -1718
- package/dist/{chunk-7B2OUQON.js → chunk-5TCMXEYL.js} +48 -3
- package/dist/{chunk-FDYMVJFU.js → chunk-5WF54R3B.js} +5 -5
- package/dist/{chunk-PVCECFJK.js → chunk-7ZD4OK6G.js} +1 -1
- package/dist/{chunk-RYPD7XWV.js → chunk-B4EFQTMP.js} +5 -5
- package/dist/chunk-BF6INES4.js +144 -0
- package/dist/{chunk-IVRWRYTH.js → chunk-BZK62VPT.js} +2 -2
- package/dist/{chunk-AJMERXZP.js → chunk-CCWQ65VD.js} +2 -2
- package/dist/{chunk-62ALWH3T.js → chunk-DL4OHDBV.js} +3 -3
- package/dist/{chunk-6TV6L2DD.js → chunk-EZ2MUWNW.js} +7 -6
- package/dist/{chunk-4NXGVJA6.js → chunk-F4RFFE2H.js} +48 -3
- package/dist/{chunk-E77SRVVO.js → chunk-FCKTBE26.js} +1 -1
- package/dist/{chunk-NTY5WGRD.js → chunk-FQ3JYUKI.js} +2 -2
- package/dist/{chunk-CEQ4Z32M.js → chunk-J4EA5SHF.js} +3 -3
- package/dist/{chunk-ORO4ENZR.js → chunk-LESWJ7L4.js} +1 -0
- package/dist/{chunk-XNGW4OYD.js → chunk-LFSTOECH.js} +7 -6
- package/dist/{chunk-OHUAAX3O.js → chunk-M45WGODR.js} +2 -2
- package/dist/{chunk-ZJMYCDYQ.js → chunk-MANERA6F.js} +55 -10
- package/dist/{chunk-Q4TZA4MN.js → chunk-NDEVAA34.js} +1629 -1486
- package/dist/{chunk-OPXEJJBM.js → chunk-PWOFUPYM.js} +1 -0
- package/dist/{chunk-UJMCTGV7.js → chunk-PXSWVZIL.js} +2 -2
- package/dist/{chunk-MOUAM6ZC.js → chunk-SMSD6U3N.js} +135 -3
- package/dist/{chunk-ATS7SYHG.js → chunk-TCEUNSLX.js} +135 -3
- package/dist/chunk-TRMPDDVL.js +232 -0
- package/dist/{chunk-6WMNIX2U.js → chunk-UFUAIVNV.js} +9 -5
- package/dist/{chunk-2HPVGTHF.js → chunk-VHQ6OG3U.js} +2 -2
- package/dist/{chunk-WWU4SYZR.js → chunk-VL6F2KRE.js} +5 -1
- package/dist/{chunk-WMD77UCY.js → chunk-W5GHFT7E.js} +279 -87
- package/dist/{chunk-5FUAOU3G.js → chunk-WB3G2LQO.js} +1 -1
- package/dist/{chunk-JCYGQKER.js → chunk-WFX4ZVSZ.js} +1 -1
- package/dist/{chunk-F7WP2U5I.js → chunk-WJURGCBR.js} +1 -1
- package/dist/{chunk-BIM24I3O.js → chunk-WWBPK7GB.js} +1 -1
- package/dist/chunk-YE7Z5WH3.js +142 -0
- package/dist/{chunk-5YCKATG6.js → chunk-YVN7L4KG.js} +1 -1
- package/dist/{chunk-GAGTEI6B.js → chunk-ZBSEJIOV.js} +56 -11
- package/dist/{conductor-LYQKONSA.js → conductor-HVOGBK63.js} +7 -6
- package/dist/{conductor-EMGMDNHL.js → conductor-VGCXUUG6.js} +9 -8
- package/dist/connected-teams-2YDE2EZ2.js +1 -1
- package/dist/{coordinator-prompt-DLY3FS2L.js → coordinator-prompt-DPO7L2JO.js} +5 -5
- package/dist/{coordinator-prompt-WALVMGKI.js → coordinator-prompt-E736TJBS.js} +4 -4
- package/dist/{global-workspace-UG2A3CEM.js → global-workspace-4RDPAOTT.js} +5 -5
- package/dist/{global-workspace-7OQ5O6JT.js → global-workspace-TG2TVLUF.js} +4 -4
- package/dist/index.cjs +2881 -1761
- package/dist/index.d.cts +140 -877
- package/dist/index.d.ts +140 -877
- package/dist/index.js +865 -559
- package/dist/{linear-PKYJH4WK.js → linear-E3BX5PX5.js} +2 -2
- package/dist/{linear-MIJO6DCV.js → linear-WG23LBCX.js} +3 -3
- package/dist/{linear-list-JPQ27RXG.js → linear-list-OINZWVV5.js} +1 -1
- package/dist/{linear-list-N57PR6JM.js → linear-list-VU47BNUV.js} +1 -1
- package/dist/mcp/run-stdio.cjs +2112 -1287
- package/dist/mcp/run-stdio.js +318 -230
- package/dist/{optional-cli-4GTEDEYJ.js → optional-cli-K6HX2X5O.js} +4 -3
- package/dist/{optional-cli-RPJIQBDX.js → optional-cli-SA3EQYML.js} +6 -5
- package/dist/{orchestrator-KNOMW5CZ.js → orchestrator-3I2FLEZL.js} +20 -18
- package/dist/{orchestrator-4SXTORD2.js → orchestrator-QDHZ56LA.js} +12 -11
- package/dist/thread-CJRchYLj.d.cts +856 -0
- package/dist/thread-CJRchYLj.d.ts +856 -0
- package/dist/{thread-store-R3G5VBII.js → thread-store-4YTOV2HL.js} +3 -3
- package/dist/{thread-store-MEUWZDVV.js → thread-store-LME2ICZP.js} +2 -2
- package/dist/{workspaces-KWGTP7DI.js → workspaces-4PA24IX6.js} +4 -4
- package/dist/{workspaces-35T6FW57.js → workspaces-6TMYV4N2.js} +5 -5
- package/dist/{worktree-ROJXGBWS.js → worktree-4ATMCYIE.js} +3 -3
- package/dist/{worktree-5P7SCST3.js → worktree-DA6SKIU5.js} +4 -4
- package/package.json +3 -3
- /package/dist/{chunk-XOEKCE6L.js → chunk-OHXNGBC4.js} +0 -0
|
@@ -3,31 +3,44 @@ import {
|
|
|
3
3
|
brightsyMcpServerName,
|
|
4
4
|
ensureCliTeamTracked,
|
|
5
5
|
ensureConnectedBrightsyTeamTokens
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-OHXNGBC4.js";
|
|
7
|
+
import {
|
|
8
|
+
loadBrightsyConfig
|
|
9
|
+
} from "./chunk-RSA47QYR.js";
|
|
7
10
|
import {
|
|
8
11
|
listAssignedLinearIssues
|
|
9
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-WB3G2LQO.js";
|
|
10
13
|
import {
|
|
11
14
|
looksLikeConversationSummary,
|
|
12
15
|
looksLikeSkillBody,
|
|
13
16
|
skillCommandFromBody,
|
|
14
17
|
withEventParentId
|
|
15
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-WWBPK7GB.js";
|
|
19
|
+
import {
|
|
20
|
+
acpHarnessLabel,
|
|
21
|
+
defaultAcpHarness,
|
|
22
|
+
detectAcpHarness,
|
|
23
|
+
isAcpHarnessId,
|
|
24
|
+
resolveAcpHarnessCommand
|
|
25
|
+
} from "./chunk-YE7Z5WH3.js";
|
|
26
|
+
import {
|
|
27
|
+
httpFetch
|
|
28
|
+
} from "./chunk-JAT3JFOS.js";
|
|
16
29
|
import {
|
|
17
30
|
isOrchestratorThread
|
|
18
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-LFSTOECH.js";
|
|
19
32
|
import {
|
|
20
33
|
codexUnattendedGitConfigArgs,
|
|
21
34
|
mergeAgentGitAuthEnv,
|
|
22
35
|
resolveAgentGitAuthEnv,
|
|
23
36
|
resolveCodexGitWritableRoots
|
|
24
|
-
} from "./chunk-
|
|
25
|
-
import {
|
|
26
|
-
loadBrightsyConfig
|
|
27
|
-
} from "./chunk-RSA47QYR.js";
|
|
37
|
+
} from "./chunk-FQ3JYUKI.js";
|
|
28
38
|
import {
|
|
29
|
-
|
|
30
|
-
|
|
39
|
+
acpPriorTranscript,
|
|
40
|
+
acpUserStdioServers,
|
|
41
|
+
parseAcpRunnerLine,
|
|
42
|
+
toAcpMcpServers
|
|
43
|
+
} from "./chunk-TRMPDDVL.js";
|
|
31
44
|
import {
|
|
32
45
|
BASE_ALLOWED_TOOLS,
|
|
33
46
|
CLAUDE_CHROME_ALLOWED_TOOLS,
|
|
@@ -48,13 +61,13 @@ import {
|
|
|
48
61
|
packagedMcpStdioPath,
|
|
49
62
|
parseCursorRunnerLine,
|
|
50
63
|
resolveNodeLaunch
|
|
51
|
-
} from "./chunk-
|
|
64
|
+
} from "./chunk-2E2HMJDU.js";
|
|
52
65
|
import {
|
|
53
66
|
extractJsonErrorMessage,
|
|
54
67
|
formatUnknownDetail,
|
|
55
68
|
looksLikeAgentFailureMessage,
|
|
56
69
|
looksLikeBrightsyEmptyCompletion
|
|
57
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-PWOFUPYM.js";
|
|
58
71
|
import {
|
|
59
72
|
githubAgentAuthReady,
|
|
60
73
|
run
|
|
@@ -80,7 +93,7 @@ import {
|
|
|
80
93
|
requestOccupancy,
|
|
81
94
|
resolveAgentExecutable,
|
|
82
95
|
resolveClaudeExecutable
|
|
83
|
-
} from "./chunk-
|
|
96
|
+
} from "./chunk-UFUAIVNV.js";
|
|
84
97
|
import {
|
|
85
98
|
isElectronLikeCommand,
|
|
86
99
|
unwrapStrippedElectronLaunch
|
|
@@ -89,1591 +102,1708 @@ import {
|
|
|
89
102
|
appDataDir
|
|
90
103
|
} from "./chunk-H4UEFJRI.js";
|
|
91
104
|
|
|
92
|
-
// src/agents/
|
|
93
|
-
import { existsSync } from "fs";
|
|
105
|
+
// src/agents/acp.ts
|
|
106
|
+
import { existsSync as existsSync5 } from "fs";
|
|
107
|
+
import { createRequire as createRequire2 } from "module";
|
|
108
|
+
import { homedir as homedir5 } from "os";
|
|
109
|
+
import { dirname as dirname3, join as join6 } from "path";
|
|
110
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
94
111
|
|
|
95
|
-
// src/agents/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
// src/agents/orch-mcp-isolation.ts
|
|
113
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "fs";
|
|
114
|
+
|
|
115
|
+
// src/agents/claude-plugins.ts
|
|
116
|
+
import { existsSync, readFileSync } from "fs";
|
|
117
|
+
import { homedir } from "os";
|
|
118
|
+
import { isAbsolute, join, relative, resolve } from "path";
|
|
119
|
+
|
|
120
|
+
// src/mcp-ui/meta.ts
|
|
121
|
+
var HTML_MAX = 15e5;
|
|
122
|
+
function matchClaudeMcpTool(toolName, serverNames) {
|
|
123
|
+
const name = toolName.trim();
|
|
124
|
+
if (!name.startsWith("mcp__")) return null;
|
|
125
|
+
const ranked = [...serverNames].filter((s) => s.trim()).sort((a, b) => b.length - a.length);
|
|
126
|
+
for (const server of ranked) {
|
|
127
|
+
const prefix = `mcp__${server}__`;
|
|
128
|
+
if (!name.startsWith(prefix)) continue;
|
|
129
|
+
const tool = name.slice(prefix.length).trim();
|
|
130
|
+
if (!tool) continue;
|
|
131
|
+
return { server, tool };
|
|
104
132
|
}
|
|
105
|
-
|
|
106
|
-
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
function parseMcpServerLaunch(entry) {
|
|
136
|
+
const command = typeof entry.command === "string" ? entry.command.trim() : "";
|
|
137
|
+
if (command) {
|
|
138
|
+
const args = Array.isArray(entry.args) ? entry.args.filter((a) => typeof a === "string") : [];
|
|
139
|
+
const env = stringRecord(entry.env);
|
|
140
|
+
const cwd = typeof entry.cwd === "string" && entry.cwd.trim() ? entry.cwd.trim() : void 0;
|
|
107
141
|
return {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
142
|
+
kind: "stdio",
|
|
143
|
+
command,
|
|
144
|
+
args,
|
|
145
|
+
...env ? { env } : {},
|
|
146
|
+
...cwd ? { cwd } : {}
|
|
111
147
|
};
|
|
112
148
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return { type: "agent", id: raw };
|
|
149
|
+
const url = typeof entry.url === "string" ? entry.url.trim() : "";
|
|
150
|
+
if (!url) return null;
|
|
151
|
+
let parsed;
|
|
152
|
+
try {
|
|
153
|
+
parsed = new URL(url);
|
|
154
|
+
} catch {
|
|
155
|
+
return null;
|
|
121
156
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// src/agents/turn-input.ts
|
|
126
|
-
function normalizeTurnInput(input) {
|
|
127
|
-
if (typeof input === "string") return { prompt: input };
|
|
157
|
+
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
|
|
158
|
+
const type = typeof entry.type === "string" ? entry.type.trim().toLowerCase() : "";
|
|
159
|
+
const headers = stringRecord(entry.headers);
|
|
128
160
|
return {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
...input.isolateCodexPlugins ? { isolateCodexPlugins: true } : {}
|
|
161
|
+
kind: type === "sse" ? "sse" : "http",
|
|
162
|
+
url: parsed.toString(),
|
|
163
|
+
...headers ? { headers } : {}
|
|
133
164
|
};
|
|
134
165
|
}
|
|
135
|
-
function
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
return turn;
|
|
145
|
-
}
|
|
146
|
-
function flattenTurnInput(input) {
|
|
147
|
-
const { cachedPrefix, prompt, systemPrompt } = normalizeTurnInput(input);
|
|
148
|
-
if (cachedPrefix) return `${cachedPrefix}
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
Current request:
|
|
153
|
-
${prompt}`;
|
|
154
|
-
if (systemPrompt) return `${systemPrompt}
|
|
155
|
-
|
|
156
|
-
${prompt}`;
|
|
157
|
-
return prompt;
|
|
166
|
+
function uiResourceUriFromMeta(meta) {
|
|
167
|
+
const rec = asRecord(meta);
|
|
168
|
+
const nested = asRecord(rec.ui);
|
|
169
|
+
const fromNested = typeof nested.resourceUri === "string" ? nested.resourceUri.trim() : "";
|
|
170
|
+
const legacy = typeof rec["ui/resourceUri"] === "string" ? rec["ui/resourceUri"].trim() : "";
|
|
171
|
+
const uri = fromNested || legacy;
|
|
172
|
+
return uri.startsWith("ui://") ? uri : null;
|
|
158
173
|
}
|
|
159
|
-
function
|
|
160
|
-
const
|
|
174
|
+
function cspFromMeta(meta) {
|
|
175
|
+
const ui = asRecord(asRecord(meta).ui);
|
|
176
|
+
const csp = asRecord(ui.csp);
|
|
177
|
+
const connectDomains = originList(csp.connectDomains);
|
|
178
|
+
const resourceDomains = originList(csp.resourceDomains);
|
|
179
|
+
const frameDomains = originList(csp.frameDomains);
|
|
180
|
+
const baseUriDomains = originList(csp.baseUriDomains);
|
|
181
|
+
if (!connectDomains?.length && !resourceDomains?.length && !frameDomains?.length && !baseUriDomains?.length) {
|
|
182
|
+
return void 0;
|
|
183
|
+
}
|
|
161
184
|
return {
|
|
162
|
-
|
|
163
|
-
|
|
185
|
+
...connectDomains?.length ? { connectDomains } : {},
|
|
186
|
+
...resourceDomains?.length ? { resourceDomains } : {},
|
|
187
|
+
...frameDomains?.length ? { frameDomains } : {},
|
|
188
|
+
...baseUriDomains?.length ? { baseUriDomains } : {}
|
|
164
189
|
};
|
|
165
190
|
}
|
|
166
|
-
function
|
|
167
|
-
|
|
191
|
+
function htmlFromResourceContent(content) {
|
|
192
|
+
const uri = content.uri?.trim() ?? "";
|
|
193
|
+
if (!uri.startsWith("ui://")) return null;
|
|
194
|
+
const mimeType = content.mimeType?.trim() || "text/html";
|
|
195
|
+
if (!isHtmlMime(mimeType)) return null;
|
|
196
|
+
const html = htmlText(content.text, content.blob);
|
|
197
|
+
if (!html) return null;
|
|
198
|
+
return { uri, mimeType, html };
|
|
168
199
|
}
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
200
|
+
function mcpUiContentSecurityPolicy(csp) {
|
|
201
|
+
const resource = (csp?.resourceDomains ?? []).join(" ");
|
|
202
|
+
const connect = (csp?.connectDomains ?? []).join(" ");
|
|
203
|
+
const frames = csp?.frameDomains?.length ? csp.frameDomains.join(" ") : "'none'";
|
|
204
|
+
const base = csp?.baseUriDomains?.length ? csp.baseUriDomains.join(" ") : "'none'";
|
|
205
|
+
const connectSrc = connect ? `'self' ${connect}`.trim() : "'none'";
|
|
206
|
+
return [
|
|
207
|
+
"default-src 'none'",
|
|
208
|
+
`script-src 'self' 'unsafe-inline' ${resource}`.trim(),
|
|
209
|
+
`style-src 'self' 'unsafe-inline' ${resource}`.trim(),
|
|
210
|
+
`img-src 'self' data: ${resource}`.trim(),
|
|
211
|
+
`font-src 'self' ${resource}`.trim(),
|
|
212
|
+
`connect-src ${connectSrc}`,
|
|
213
|
+
`media-src 'self' data: ${resource}`.trim(),
|
|
214
|
+
`frame-src ${frames}`,
|
|
215
|
+
`base-uri ${base}`,
|
|
216
|
+
"object-src 'none'"
|
|
217
|
+
].join("; ");
|
|
178
218
|
}
|
|
179
|
-
function
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
219
|
+
function htmlText(text, blob) {
|
|
220
|
+
if (typeof text === "string" && text.trim()) {
|
|
221
|
+
return text.length <= HTML_MAX ? text : null;
|
|
222
|
+
}
|
|
223
|
+
if (typeof blob !== "string" || !blob.trim()) return null;
|
|
224
|
+
try {
|
|
225
|
+
const decoded = decodeBase64(blob.trim());
|
|
226
|
+
if (!decoded.trim() || decoded.length > HTML_MAX) return null;
|
|
227
|
+
return decoded;
|
|
228
|
+
} catch {
|
|
229
|
+
return null;
|
|
191
230
|
}
|
|
192
|
-
return { saw5m, invalid: null };
|
|
193
231
|
}
|
|
194
|
-
function
|
|
195
|
-
return
|
|
232
|
+
function decodeBase64(blob) {
|
|
233
|
+
if (typeof Buffer !== "undefined") return Buffer.from(blob, "base64").toString("utf8");
|
|
234
|
+
const bin = atob(blob);
|
|
235
|
+
const bytes = Uint8Array.from(bin, (c) => c.charCodeAt(0));
|
|
236
|
+
return new TextDecoder().decode(bytes);
|
|
196
237
|
}
|
|
197
|
-
function
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
for (const block of blocks) {
|
|
201
|
-
if (block.cache_control) count++;
|
|
202
|
-
if (Array.isArray(block.content)) {
|
|
203
|
-
count += countCacheControlBlocks(block.content);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return count;
|
|
238
|
+
function isHtmlMime(mime) {
|
|
239
|
+
const base = mime.split(";")[0]?.trim().toLowerCase() ?? "";
|
|
240
|
+
return base === "text/html";
|
|
207
241
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
outputTokens: Number(usage.completion_tokens ?? 0),
|
|
216
|
-
cachedInputTokens: Number(usage.prompt_tokens_details?.cached_tokens ?? 0)
|
|
217
|
-
});
|
|
218
|
-
if (!mapped) return null;
|
|
219
|
-
if (usage.cost != null && Number.isFinite(Number(usage.cost))) {
|
|
220
|
-
mapped.costUsd = Number(usage.cost);
|
|
242
|
+
function originList(value) {
|
|
243
|
+
if (!Array.isArray(value)) return void 0;
|
|
244
|
+
const out = [];
|
|
245
|
+
for (const item of value) {
|
|
246
|
+
if (typeof item !== "string") continue;
|
|
247
|
+
const origin = originToken(item);
|
|
248
|
+
if (origin && !out.includes(origin)) out.push(origin);
|
|
221
249
|
}
|
|
222
|
-
return
|
|
250
|
+
return out;
|
|
223
251
|
}
|
|
224
|
-
function
|
|
225
|
-
const trimmed =
|
|
226
|
-
if (
|
|
252
|
+
function originToken(value) {
|
|
253
|
+
const trimmed = value.trim();
|
|
254
|
+
if (/^(https?|wss?):\/\/\*\.[a-z0-9.-]+(?::\d+)?$/i.test(trimmed)) return trimmed;
|
|
227
255
|
try {
|
|
228
|
-
const
|
|
229
|
-
if (
|
|
230
|
-
if (looksLikeBrightsyEmptyCompletion(obj.text)) {
|
|
231
|
-
return [
|
|
232
|
-
{ type: "stderr", data: obj.text },
|
|
233
|
-
{ type: "stdout", data: `Error: ${obj.text}` }
|
|
234
|
-
];
|
|
235
|
-
}
|
|
236
|
-
return { type: "stdout", data: obj.text };
|
|
237
|
-
}
|
|
238
|
-
if (obj.type === "thinking" && typeof obj.text === "string") {
|
|
239
|
-
return { type: "thinking", data: obj.text };
|
|
240
|
-
}
|
|
241
|
-
if (obj.type === "error") {
|
|
242
|
-
const msg = extractJsonErrorMessage(obj) || formatUnknownDetail(obj.error) || formatUnknownDetail(obj.message) || trimmed;
|
|
243
|
-
return [
|
|
244
|
-
{ type: "stderr", data: msg },
|
|
245
|
-
{ type: "stdout", data: `Error: ${msg}` }
|
|
246
|
-
];
|
|
247
|
-
}
|
|
248
|
-
if (obj.type === "usage") {
|
|
249
|
-
const usage = usageFromBrightsy(obj.usage);
|
|
250
|
-
return usage ? { type: "usage", data: usage } : null;
|
|
251
|
-
}
|
|
252
|
-
if (obj.type === "tool_use") {
|
|
253
|
-
const id = typeof obj.id === "string" && obj.id || `brightsy-tool-${Date.now()}`;
|
|
254
|
-
const name = typeof obj.name === "string" && obj.name || "brightsy_tool";
|
|
255
|
-
const input = obj.input && typeof obj.input === "object" && !Array.isArray(obj.input) ? obj.input : void 0;
|
|
256
|
-
return { type: "tool_use", id, name, input };
|
|
257
|
-
}
|
|
258
|
-
if (obj.type === "tool_result" || obj.type === "tool") {
|
|
259
|
-
const id = typeof obj.id === "string" && obj.id || typeof obj.tool_call_id === "string" && obj.tool_call_id || `brightsy-tool-${Date.now()}`;
|
|
260
|
-
const content = typeof obj.content === "string" ? obj.content : obj.content != null ? JSON.stringify(obj.content) : void 0;
|
|
261
|
-
return {
|
|
262
|
-
type: "tool_result",
|
|
263
|
-
id,
|
|
264
|
-
content,
|
|
265
|
-
isError: obj.isError === true
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
if (obj.type === "done") return null;
|
|
269
|
-
if (typeof obj.type === "string" && ["tool_use", "tool_result", "tool", "thinking", "usage", "error", "done", "text"].includes(
|
|
270
|
-
obj.type
|
|
271
|
-
)) {
|
|
256
|
+
const url = new URL(trimmed);
|
|
257
|
+
if (url.protocol !== "https:" && url.protocol !== "http:" && url.protocol !== "wss:" && url.protocol !== "ws:") {
|
|
272
258
|
return null;
|
|
273
259
|
}
|
|
274
|
-
return
|
|
260
|
+
return url.origin;
|
|
275
261
|
} catch {
|
|
276
|
-
|
|
277
|
-
return null;
|
|
278
|
-
}
|
|
279
|
-
if (looksLikeBrightsyEmptyCompletion(trimmed) || /error|failed|unauthorized|quota|limit|not logged in/i.test(trimmed)) {
|
|
280
|
-
return [
|
|
281
|
-
{ type: "stderr", data: trimmed },
|
|
282
|
-
{ type: "stdout", data: `Error: ${trimmed}` }
|
|
283
|
-
];
|
|
284
|
-
}
|
|
285
|
-
return { type: "stdout", data: line };
|
|
262
|
+
return null;
|
|
286
263
|
}
|
|
287
264
|
}
|
|
288
|
-
function
|
|
289
|
-
|
|
290
|
-
|
|
265
|
+
function stringRecord(value) {
|
|
266
|
+
const rec = asRecord(value);
|
|
267
|
+
const out = {};
|
|
268
|
+
for (const [key, item] of Object.entries(rec)) {
|
|
269
|
+
if (typeof item === "string") out[key] = item;
|
|
291
270
|
}
|
|
292
|
-
return
|
|
271
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
293
272
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
{
|
|
298
|
-
type: "agent",
|
|
299
|
-
id: "default",
|
|
300
|
-
name: "Default Agent",
|
|
301
|
-
description: "Account default agent (tools + memory)",
|
|
302
|
-
accountId: team.id,
|
|
303
|
-
accountSlug: team.slug,
|
|
304
|
-
accountName: team.name
|
|
305
|
-
}
|
|
306
|
-
];
|
|
307
|
-
let models = [];
|
|
308
|
-
try {
|
|
309
|
-
const res = await fetch(`${endpoint}/api/v1beta/${team.id}/agents`, {
|
|
310
|
-
headers: { Authorization: `Bearer ${team.access_token}` }
|
|
311
|
-
});
|
|
312
|
-
if (res.ok) {
|
|
313
|
-
const json = await res.json();
|
|
314
|
-
const listed = (json.data || []).filter(
|
|
315
|
-
(a) => Boolean(a?.id && a?.name)
|
|
316
|
-
).filter((a) => a.id !== "default").map((a) => ({
|
|
317
|
-
type: "agent",
|
|
318
|
-
id: a.id,
|
|
319
|
-
name: a.name,
|
|
320
|
-
description: a.description,
|
|
321
|
-
accountId: team.id,
|
|
322
|
-
accountSlug: team.slug,
|
|
323
|
-
accountName: team.name
|
|
324
|
-
}));
|
|
325
|
-
agents = [...agents, ...listed];
|
|
326
|
-
if (Array.isArray(json.models)) {
|
|
327
|
-
models = json.models.filter(
|
|
328
|
-
(m) => Boolean(m?.id && m?.name)
|
|
329
|
-
).slice(0, 12).map((m) => ({
|
|
330
|
-
type: "model",
|
|
331
|
-
id: m.id,
|
|
332
|
-
name: m.name,
|
|
333
|
-
description: m.description,
|
|
334
|
-
accountId: team.id,
|
|
335
|
-
accountSlug: team.slug,
|
|
336
|
-
accountName: team.name
|
|
337
|
-
}));
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
} catch {
|
|
341
|
-
}
|
|
342
|
-
return {
|
|
343
|
-
accountId: team.id,
|
|
344
|
-
accountSlug: team.slug,
|
|
345
|
-
accountName: team.name,
|
|
346
|
-
agents,
|
|
347
|
-
models
|
|
348
|
-
};
|
|
273
|
+
function asRecord(value) {
|
|
274
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
275
|
+
return value;
|
|
349
276
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
);
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
277
|
+
|
|
278
|
+
// src/agents/claude-plugins.ts
|
|
279
|
+
function claudePluginServerId(pluginName, serverName) {
|
|
280
|
+
return `plugin_${pluginName}_${serverName}`.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
281
|
+
}
|
|
282
|
+
function listEnabledClaudePluginMcpServers(opts) {
|
|
283
|
+
const home = opts?.home ?? homedir();
|
|
284
|
+
const pluginsRoot = claudePluginsRoot(home);
|
|
285
|
+
const enabled = enabledPluginIds(home, opts?.projectDirs ?? []);
|
|
286
|
+
const installed = readInstalledPlugins(join(pluginsRoot, "installed_plugins.json"));
|
|
287
|
+
const out = {};
|
|
288
|
+
for (const [id, on] of enabled) {
|
|
289
|
+
if (!on) continue;
|
|
290
|
+
const root = installPathFor(id, installed);
|
|
291
|
+
if (!root || !existsSync(root)) continue;
|
|
292
|
+
const pluginName = manifestName(root) || id.split("@")[0]?.trim() || "";
|
|
293
|
+
if (!pluginName) continue;
|
|
294
|
+
const dataDir = join(pluginsRoot, "data", pluginDataId(id));
|
|
295
|
+
for (const [serverName, entry] of Object.entries(loadPluginMcpServers(root))) {
|
|
296
|
+
const expanded = expandPluginEntry(entry, root, dataDir);
|
|
297
|
+
if (!parseMcpServerLaunch(expanded)) continue;
|
|
298
|
+
const key = claudePluginServerId(pluginName, serverName);
|
|
299
|
+
if (!key || key === "plugin__") continue;
|
|
300
|
+
out[key] = expanded;
|
|
374
301
|
}
|
|
375
|
-
const agents = (Array.isArray(parsed.agents) ? parsed.agents : []).map((a) => ({
|
|
376
|
-
...a,
|
|
377
|
-
accountId: accountId ?? void 0,
|
|
378
|
-
accountSlug,
|
|
379
|
-
accountName
|
|
380
|
-
}));
|
|
381
|
-
const models = (Array.isArray(parsed.models) ? parsed.models : []).map((m) => ({
|
|
382
|
-
...m,
|
|
383
|
-
accountId: accountId ?? void 0,
|
|
384
|
-
accountSlug,
|
|
385
|
-
accountName
|
|
386
|
-
}));
|
|
387
|
-
const teams = accountId ? [
|
|
388
|
-
{
|
|
389
|
-
accountId,
|
|
390
|
-
accountSlug,
|
|
391
|
-
accountName,
|
|
392
|
-
agents,
|
|
393
|
-
models
|
|
394
|
-
}
|
|
395
|
-
] : [];
|
|
396
|
-
return { teams, agents, models, activeAccountId: accountId };
|
|
397
|
-
} catch {
|
|
398
|
-
throw new Error("Brightsy --list-targets returned invalid JSON");
|
|
399
302
|
}
|
|
303
|
+
return out;
|
|
400
304
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
305
|
+
function claudePluginsRoot(home) {
|
|
306
|
+
const override = process.env.CLAUDE_CODE_PLUGIN_CACHE_DIR?.trim();
|
|
307
|
+
if (override && isAbsolute(override)) return override;
|
|
308
|
+
return join(home, ".claude", "plugins");
|
|
309
|
+
}
|
|
310
|
+
function pluginDataId(pluginId) {
|
|
311
|
+
return pluginId.replace(/[^A-Za-z0-9_-]/g, "-");
|
|
312
|
+
}
|
|
313
|
+
function enabledPluginIds(home, projectDirs) {
|
|
314
|
+
const enabled = /* @__PURE__ */ new Map();
|
|
315
|
+
applyEnabled(enabled, readEnabledPlugins(join(home, ".claude", "settings.json")));
|
|
316
|
+
const dirs = [...new Set(projectDirs.map((dir) => dir.trim()).filter(Boolean))];
|
|
317
|
+
for (const dir of dirs) {
|
|
318
|
+
applyEnabled(enabled, readEnabledPlugins(join(dir, ".claude", "settings.json")));
|
|
406
319
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
activeAccountId = loadBrightsyConfig().account_id;
|
|
410
|
-
} catch {
|
|
411
|
-
activeAccountId = teamsRaw[0]?.id ?? null;
|
|
320
|
+
for (const dir of dirs) {
|
|
321
|
+
applyEnabled(enabled, readEnabledPlugins(join(dir, ".claude", "settings.local.json")));
|
|
412
322
|
}
|
|
413
|
-
|
|
414
|
-
teams.sort((a, b) => {
|
|
415
|
-
if (a.accountId === activeAccountId) return -1;
|
|
416
|
-
if (b.accountId === activeAccountId) return 1;
|
|
417
|
-
return a.accountSlug.localeCompare(b.accountSlug);
|
|
418
|
-
});
|
|
419
|
-
const active = teams.find((t) => t.accountId === activeAccountId) ?? teams[0] ?? null;
|
|
420
|
-
return {
|
|
421
|
-
teams,
|
|
422
|
-
agents: active?.agents ?? [],
|
|
423
|
-
models: active?.models ?? [],
|
|
424
|
-
activeAccountId
|
|
425
|
-
};
|
|
323
|
+
return enabled;
|
|
426
324
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
try {
|
|
433
|
-
const cfg = loadBrightsyConfig();
|
|
434
|
-
if (cfg.account_id === team.id && cfg.access_token === team.access_token) {
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
} catch {
|
|
325
|
+
function applyEnabled(into, next) {
|
|
326
|
+
for (const [id, on] of Object.entries(next)) {
|
|
327
|
+
const key = id.trim();
|
|
328
|
+
if (!key) continue;
|
|
329
|
+
into.set(key, on);
|
|
438
330
|
}
|
|
439
|
-
applyConnectedTeamToCli(team);
|
|
440
331
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
reason: "brightsy CLI not found on PATH \u2014 npm i -g @brightsy/cli"
|
|
466
|
-
};
|
|
467
|
-
}
|
|
332
|
+
function readEnabledPlugins(path) {
|
|
333
|
+
const root = readJson(path);
|
|
334
|
+
const raw = root.enabledPlugins;
|
|
335
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
336
|
+
const out = {};
|
|
337
|
+
for (const [id, value] of Object.entries(raw)) {
|
|
338
|
+
if (value === true || value === false) out[id] = value;
|
|
339
|
+
}
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
function readInstalledPlugins(path) {
|
|
343
|
+
const root = readJson(path);
|
|
344
|
+
const plugins = root.plugins;
|
|
345
|
+
if (!plugins || typeof plugins !== "object" || Array.isArray(plugins)) return {};
|
|
346
|
+
const out = {};
|
|
347
|
+
for (const [id, value] of Object.entries(plugins)) {
|
|
348
|
+
const rows = Array.isArray(value) ? value : [value];
|
|
349
|
+
const installs = [];
|
|
350
|
+
for (const row of rows) {
|
|
351
|
+
if (!row || typeof row !== "object" || Array.isArray(row)) continue;
|
|
352
|
+
const installPath = row.installPath;
|
|
353
|
+
installs.push({
|
|
354
|
+
...typeof installPath === "string" && installPath.trim() ? { installPath: installPath.trim() } : {}
|
|
355
|
+
});
|
|
468
356
|
}
|
|
469
|
-
|
|
470
|
-
const authenticated = who.exitCode === 0 && /logged in as/i.test(who.stdout);
|
|
471
|
-
return {
|
|
472
|
-
agent: "brightsy",
|
|
473
|
-
installed: true,
|
|
474
|
-
authenticated,
|
|
475
|
-
linearMcp: false,
|
|
476
|
-
warnings: [],
|
|
477
|
-
reason: authenticated ? void 0 : "not logged in \u2014 run `brightsy login`"
|
|
478
|
-
};
|
|
479
|
-
},
|
|
480
|
-
async buildTurn(thread, input) {
|
|
481
|
-
const prompt = flattenTurnInput(input);
|
|
482
|
-
const target = decodeBrightsyTarget(thread.model);
|
|
483
|
-
await syncCliForTarget(target.accountId);
|
|
484
|
-
const mode = thread.planMode ? "plan" : target.type === "model" ? "ask" : "agent";
|
|
485
|
-
const args = [
|
|
486
|
-
"chat",
|
|
487
|
-
"--json",
|
|
488
|
-
"--mode",
|
|
489
|
-
mode,
|
|
490
|
-
target.type === "model" ? "--model" : "--agent",
|
|
491
|
-
target.id
|
|
492
|
-
];
|
|
493
|
-
return {
|
|
494
|
-
file: resolveAgentExecutable("brightsy"),
|
|
495
|
-
args,
|
|
496
|
-
cwd: thread.worktreePath,
|
|
497
|
-
// Piped stdin becomes the message body (avoids ARG_MAX for long seeds).
|
|
498
|
-
stdin: prompt
|
|
499
|
-
};
|
|
500
|
-
},
|
|
501
|
-
parseEvent(line) {
|
|
502
|
-
return parseBrightsyCliLine(line);
|
|
503
|
-
},
|
|
504
|
-
async resolveSessionId() {
|
|
505
|
-
return null;
|
|
506
|
-
},
|
|
507
|
-
async buildAttach(thread) {
|
|
508
|
-
const target = decodeBrightsyTarget(thread.model);
|
|
509
|
-
await syncCliForTarget(target.accountId);
|
|
510
|
-
const args = target.type === "model" ? ["chat", "--model", target.id] : ["chat", "--agent", target.id];
|
|
511
|
-
return {
|
|
512
|
-
file: resolveAgentExecutable("brightsy"),
|
|
513
|
-
args,
|
|
514
|
-
cwd: thread.worktreePath
|
|
515
|
-
};
|
|
357
|
+
if (installs.length) out[id] = installs;
|
|
516
358
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
"
|
|
529
|
-
"
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
359
|
+
return out;
|
|
360
|
+
}
|
|
361
|
+
function installPathFor(id, installed) {
|
|
362
|
+
const rows = installed[id] ?? [];
|
|
363
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
364
|
+
const path = rows[i]?.installPath;
|
|
365
|
+
if (path && existsSync(path)) return path;
|
|
366
|
+
}
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
function manifestName(root) {
|
|
370
|
+
const manifest = readJson(join(root, ".claude-plugin", "plugin.json"));
|
|
371
|
+
return typeof manifest.name === "string" ? manifest.name.trim() : "";
|
|
372
|
+
}
|
|
373
|
+
function loadPluginMcpServers(root) {
|
|
374
|
+
const servers = {};
|
|
375
|
+
mergeServerMap(servers, serversFromFile(join(root, ".mcp.json"), root));
|
|
376
|
+
const manifest = readJson(join(root, ".claude-plugin", "plugin.json"));
|
|
377
|
+
mergeServerMap(servers, serversFromManifest(manifest.mcpServers, root));
|
|
378
|
+
return servers;
|
|
379
|
+
}
|
|
380
|
+
function serversFromManifest(value, root) {
|
|
381
|
+
if (!value) return {};
|
|
382
|
+
if (typeof value === "string") return serversFromFile(resolveInside(root, value), root);
|
|
383
|
+
if (Array.isArray(value)) {
|
|
384
|
+
const out = {};
|
|
385
|
+
for (const item of value) {
|
|
386
|
+
if (typeof item === "string") mergeServerMap(out, serversFromFile(resolveInside(root, item), root));
|
|
387
|
+
else mergeServerMap(out, serverMap(item, root));
|
|
542
388
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
389
|
+
return out;
|
|
390
|
+
}
|
|
391
|
+
return serverMap(value, root);
|
|
392
|
+
}
|
|
393
|
+
function serversFromFile(path, root) {
|
|
394
|
+
if (!path || !existsSync(path)) return {};
|
|
395
|
+
return serverMap(readJson(path), root);
|
|
396
|
+
}
|
|
397
|
+
function serverMap(value, root) {
|
|
398
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
399
|
+
const record = value;
|
|
400
|
+
const wrapped = record.mcpServers;
|
|
401
|
+
const source = wrapped && typeof wrapped === "object" && !Array.isArray(wrapped) ? wrapped : record;
|
|
402
|
+
if (typeof wrapped === "string") return serversFromFile(resolveInside(root, wrapped), root);
|
|
403
|
+
const out = {};
|
|
404
|
+
for (const [name, entry] of Object.entries(source)) {
|
|
405
|
+
if (!name.trim() || !entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
406
|
+
const row = entry;
|
|
407
|
+
if (row.disabled === true) continue;
|
|
408
|
+
if (typeof row.command !== "string" && typeof row.url !== "string") continue;
|
|
409
|
+
out[name.trim()] = row;
|
|
410
|
+
}
|
|
411
|
+
return out;
|
|
412
|
+
}
|
|
413
|
+
function mergeServerMap(into, extra) {
|
|
414
|
+
for (const [name, entry] of Object.entries(extra)) into[name] = entry;
|
|
415
|
+
}
|
|
416
|
+
function expandPluginEntry(entry, root, dataDir) {
|
|
417
|
+
const next = { ...entry };
|
|
418
|
+
if (typeof next.command === "string") next.command = expandVars(next.command, root, dataDir);
|
|
419
|
+
if (Array.isArray(next.args)) {
|
|
420
|
+
next.args = next.args.map((arg) => typeof arg === "string" ? expandVars(arg, root, dataDir) : arg);
|
|
421
|
+
}
|
|
422
|
+
if (typeof next.url === "string") next.url = expandVars(next.url, root, dataDir);
|
|
423
|
+
if (next.env && typeof next.env === "object" && !Array.isArray(next.env)) {
|
|
424
|
+
const env = {};
|
|
425
|
+
for (const [key, value] of Object.entries(next.env)) {
|
|
426
|
+
if (typeof value === "string") env[key] = expandVars(value, root, dataDir);
|
|
555
427
|
}
|
|
428
|
+
env.CLAUDE_PLUGIN_ROOT = env.CLAUDE_PLUGIN_ROOT || root;
|
|
429
|
+
env.CLAUDE_PLUGIN_DATA = env.CLAUDE_PLUGIN_DATA || dataDir;
|
|
430
|
+
next.env = env;
|
|
431
|
+
} else if (typeof next.command === "string") {
|
|
432
|
+
next.env = { CLAUDE_PLUGIN_ROOT: root, CLAUDE_PLUGIN_DATA: dataDir };
|
|
556
433
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
434
|
+
if (next.headers && typeof next.headers === "object" && !Array.isArray(next.headers)) {
|
|
435
|
+
const headers = {};
|
|
436
|
+
for (const [key, value] of Object.entries(next.headers)) {
|
|
437
|
+
if (typeof value === "string") headers[key] = expandVars(value, root, dataDir);
|
|
438
|
+
}
|
|
439
|
+
next.headers = headers;
|
|
440
|
+
}
|
|
441
|
+
return next;
|
|
442
|
+
}
|
|
443
|
+
function expandVars(value, root, dataDir) {
|
|
444
|
+
return value.replaceAll("${CLAUDE_PLUGIN_ROOT}", root).replaceAll("${CLAUDE_PLUGIN_DATA}", dataDir);
|
|
445
|
+
}
|
|
446
|
+
function resolveInside(root, spec) {
|
|
447
|
+
const trimmed = spec.trim();
|
|
448
|
+
if (!trimmed || trimmed.endsWith(".mcpb") || trimmed.endsWith(".dxt")) return null;
|
|
449
|
+
if (/^https?:\/\//i.test(trimmed)) return null;
|
|
450
|
+
const abs = resolve(root, trimmed);
|
|
451
|
+
const rel = relative(root, abs);
|
|
452
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
453
|
+
return abs;
|
|
454
|
+
}
|
|
455
|
+
function readJson(path) {
|
|
456
|
+
if (!existsSync(path)) return {};
|
|
457
|
+
try {
|
|
458
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
459
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
460
|
+
return parsed;
|
|
461
|
+
} catch {
|
|
462
|
+
return {};
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/agents/orch-mcp-isolation.ts
|
|
467
|
+
import { homedir as homedir4 } from "os";
|
|
468
|
+
import { join as join5 } from "path";
|
|
469
|
+
import { parse as parseToml } from "smol-toml";
|
|
470
|
+
|
|
471
|
+
// src/agents/user-mcp-config.ts
|
|
472
|
+
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync3 } from "fs";
|
|
473
|
+
import { homedir as homedir3 } from "os";
|
|
474
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
475
|
+
|
|
476
|
+
// src/agents/injected-mcp.ts
|
|
477
|
+
import { existsSync as existsSync2, mkdtempSync, writeFileSync as writeFileSync2 } from "fs";
|
|
478
|
+
import { createRequire } from "module";
|
|
479
|
+
import { tmpdir } from "os";
|
|
480
|
+
import { dirname, join as join3 } from "path";
|
|
481
|
+
import { fileURLToPath } from "url";
|
|
482
|
+
|
|
483
|
+
// src/mcp/profile.ts
|
|
484
|
+
var SIDEBOARD_MCP_PROFILE_ENV = "SIDEBOARD_MCP_PROFILE";
|
|
485
|
+
var SIDEBOARD_THREAD_ID_ENV = "SIDEBOARD_THREAD_ID";
|
|
486
|
+
function agentRpcOwnsPilotTools(env = process.env) {
|
|
487
|
+
return env[AGENT_RPC_NATIVE_ENV]?.trim() === "1";
|
|
488
|
+
}
|
|
489
|
+
function injectedSideboardMcpEnv(opts) {
|
|
490
|
+
const orchId = opts.orchestratorThreadId?.trim();
|
|
491
|
+
const threadId = opts.threadId?.trim() || orchId;
|
|
492
|
+
const env = {
|
|
493
|
+
SIDEBOARD_APP_DATA: appDataDir(),
|
|
494
|
+
[SIDEBOARD_MCP_PROFILE_ENV]: orchId ? "orchestration" : "worktree"
|
|
495
|
+
};
|
|
496
|
+
if (orchId) env.SIDEBOARD_ORCHESTRATOR_THREAD_ID = orchId;
|
|
497
|
+
if (threadId) env[SIDEBOARD_THREAD_ID_ENV] = threadId;
|
|
498
|
+
if (opts.rpcNativeTools) env[AGENT_RPC_NATIVE_ENV] = "1";
|
|
499
|
+
return env;
|
|
500
|
+
}
|
|
501
|
+
var AGENT_RPC_PILOT_MCP_TOOLS = [
|
|
502
|
+
"present_artifact",
|
|
503
|
+
"wait_for_job",
|
|
504
|
+
"stop_job"
|
|
505
|
+
];
|
|
506
|
+
function shouldRegisterMcpWaitForTurn(env = process.env) {
|
|
507
|
+
return !agentRpcOwnsPilotTools(env);
|
|
508
|
+
}
|
|
509
|
+
function worktreeMcpToolNames(env = process.env) {
|
|
510
|
+
if (!agentRpcOwnsPilotTools(env)) return WORKTREE_MCP_TOOLS;
|
|
511
|
+
const omit = new Set(AGENT_RPC_PILOT_MCP_TOOLS);
|
|
512
|
+
return WORKTREE_MCP_TOOLS.filter((name) => !omit.has(name));
|
|
513
|
+
}
|
|
514
|
+
var WORKTREE_MCP_TOOLS = [
|
|
515
|
+
"present_artifact",
|
|
516
|
+
"ask_user",
|
|
517
|
+
"present_plan",
|
|
518
|
+
"present_schema",
|
|
519
|
+
"present_files",
|
|
520
|
+
"wait_for_job",
|
|
521
|
+
"stop_job",
|
|
522
|
+
"list_run_scripts",
|
|
523
|
+
"run_dev_script",
|
|
524
|
+
"stop_dev_script",
|
|
525
|
+
"get_run_log",
|
|
526
|
+
"get_orchestrator",
|
|
527
|
+
"notify_orchestrator",
|
|
528
|
+
"set_workspace_tags",
|
|
529
|
+
"set_wake_on_github_edges",
|
|
530
|
+
"get_viewer_context",
|
|
531
|
+
"update_viewer_context",
|
|
532
|
+
"list_env",
|
|
533
|
+
"set_env",
|
|
534
|
+
"delete_env",
|
|
535
|
+
"list_schedules",
|
|
536
|
+
"create_schedule",
|
|
537
|
+
"update_schedule",
|
|
538
|
+
"delete_schedule",
|
|
539
|
+
"run_schedule",
|
|
540
|
+
"list_follow_ups",
|
|
541
|
+
"create_follow_up",
|
|
542
|
+
"delete_follow_up",
|
|
543
|
+
"list_order",
|
|
544
|
+
"show_plan",
|
|
545
|
+
"set_dependency",
|
|
546
|
+
"clear_dependency",
|
|
547
|
+
"satisfy_dependency"
|
|
548
|
+
];
|
|
549
|
+
var WORKTREE_GITHUB_MCP_TOOLS = [
|
|
550
|
+
"github_search_issues",
|
|
551
|
+
"github_list_projects",
|
|
552
|
+
"github_get_issue",
|
|
553
|
+
"github_download_attachment",
|
|
554
|
+
"github_comment",
|
|
555
|
+
"github_update_issue",
|
|
556
|
+
"github_create_issue"
|
|
557
|
+
];
|
|
558
|
+
var WORKTREE_LINEAR_MCP_TOOLS = [
|
|
559
|
+
"linear_list_teams",
|
|
560
|
+
"linear_list_projects",
|
|
561
|
+
"linear_search_issues",
|
|
562
|
+
"linear_get_issue",
|
|
563
|
+
"linear_download_attachment",
|
|
564
|
+
"linear_create_issue",
|
|
565
|
+
"linear_update_issue",
|
|
566
|
+
"linear_comment"
|
|
567
|
+
];
|
|
568
|
+
var WORKTREE_ABLETIME_MCP_TOOLS = [
|
|
569
|
+
"abletime_orientation",
|
|
570
|
+
"abletime_list_projects",
|
|
571
|
+
"abletime_list_tasks",
|
|
572
|
+
"abletime_search_tasks",
|
|
573
|
+
"abletime_get_task",
|
|
574
|
+
"abletime_download_attachment",
|
|
575
|
+
"abletime_comment",
|
|
576
|
+
"abletime_update_task",
|
|
577
|
+
"abletime_create_task",
|
|
578
|
+
"abletime_ensure_task"
|
|
579
|
+
];
|
|
580
|
+
function sideboardMcpProfile(env = process.env) {
|
|
581
|
+
return env[SIDEBOARD_MCP_PROFILE_ENV]?.trim().toLowerCase() === "worktree" ? "worktree" : "orchestration";
|
|
564
582
|
}
|
|
565
|
-
|
|
566
|
-
|
|
583
|
+
|
|
584
|
+
// src/agents/codex-mcp-profile.ts
|
|
585
|
+
import { randomBytes } from "crypto";
|
|
586
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
587
|
+
import { homedir as homedir2 } from "os";
|
|
588
|
+
import { join as join2 } from "path";
|
|
589
|
+
function isCodexSecretEnvKey(key) {
|
|
590
|
+
return /token|secret|password|credential|oauth|api_key|_key$/i.test(key);
|
|
567
591
|
}
|
|
568
|
-
function
|
|
569
|
-
return /
|
|
570
|
-
status
|
|
571
|
-
);
|
|
592
|
+
function tomlBasicString(value) {
|
|
593
|
+
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r")}"`;
|
|
572
594
|
}
|
|
573
|
-
function
|
|
574
|
-
|
|
595
|
+
function secretEnv(env) {
|
|
596
|
+
if (!env) return void 0;
|
|
597
|
+
const out = { ...env };
|
|
598
|
+
delete out.ELECTRON_RUN_AS_NODE;
|
|
599
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
575
600
|
}
|
|
576
|
-
function
|
|
577
|
-
|
|
601
|
+
function writeCodexMcpSecretProfile(servers) {
|
|
602
|
+
const blocks = [];
|
|
603
|
+
for (const s of servers) {
|
|
604
|
+
const env = secretEnv(s.env);
|
|
605
|
+
if (!env) continue;
|
|
606
|
+
const secrets = Object.entries(env).filter(([key]) => isCodexSecretEnvKey(key));
|
|
607
|
+
if (secrets.length === 0) continue;
|
|
608
|
+
const lines = [`[mcp_servers.${s.name}.env]`];
|
|
609
|
+
for (const [key, value] of secrets) lines.push(`${key} = ${tomlBasicString(value)}`);
|
|
610
|
+
blocks.push(lines.join("\n"));
|
|
611
|
+
}
|
|
612
|
+
if (blocks.length === 0) return null;
|
|
613
|
+
const home = process.env.CODEX_HOME?.trim() || join2(homedir2(), ".codex");
|
|
614
|
+
mkdirSync(home, { recursive: true, mode: 448 });
|
|
615
|
+
const profile = `sideboard-${randomBytes(8).toString("hex")}`;
|
|
616
|
+
const file = join2(home, `${profile}.config.toml`);
|
|
617
|
+
writeFileSync(file, `${blocks.join("\n\n")}
|
|
618
|
+
`, { mode: 384 });
|
|
619
|
+
return { profile, file };
|
|
578
620
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
621
|
+
|
|
622
|
+
// src/agents/injected-mcp.ts
|
|
623
|
+
var SIDEBOARD_MCP_ALLOWED_TOOLS = [
|
|
624
|
+
"mcp__sideboard",
|
|
625
|
+
"mcp__sideboard__*"
|
|
626
|
+
];
|
|
627
|
+
var SIDEBOARD_ARTIFACT_MCP_ALLOWED_TOOLS = [
|
|
628
|
+
"mcp__sideboard__present_artifact",
|
|
629
|
+
"mcp__sideboard__present_schema",
|
|
630
|
+
"mcp__sideboard__present_files",
|
|
631
|
+
"mcp__sideboard__ask_user",
|
|
632
|
+
"mcp__sideboard__present_plan",
|
|
633
|
+
"mcp__sideboard__wait_for_job",
|
|
634
|
+
"mcp__sideboard__stop_job",
|
|
635
|
+
"mcp__sideboard__list_run_scripts",
|
|
636
|
+
"mcp__sideboard__run_dev_script",
|
|
637
|
+
"mcp__sideboard__stop_dev_script",
|
|
638
|
+
"mcp__sideboard__get_run_log",
|
|
639
|
+
"mcp__sideboard__get_orchestrator",
|
|
640
|
+
"mcp__sideboard__notify_orchestrator",
|
|
641
|
+
"mcp__sideboard__set_workspace_tags",
|
|
642
|
+
"mcp__sideboard__set_wake_on_github_edges",
|
|
643
|
+
"mcp__sideboard__get_viewer_context",
|
|
644
|
+
"mcp__sideboard__update_viewer_context",
|
|
645
|
+
"mcp__sideboard__list_env",
|
|
646
|
+
"mcp__sideboard__set_env",
|
|
647
|
+
"mcp__sideboard__delete_env",
|
|
648
|
+
"mcp__sideboard__list_schedules",
|
|
649
|
+
"mcp__sideboard__create_schedule",
|
|
650
|
+
"mcp__sideboard__update_schedule",
|
|
651
|
+
"mcp__sideboard__delete_schedule",
|
|
652
|
+
"mcp__sideboard__run_schedule",
|
|
653
|
+
"mcp__sideboard__list_follow_ups",
|
|
654
|
+
"mcp__sideboard__create_follow_up",
|
|
655
|
+
"mcp__sideboard__delete_follow_up",
|
|
656
|
+
"mcp__sideboard__list_order",
|
|
657
|
+
"mcp__sideboard__show_plan",
|
|
658
|
+
"mcp__sideboard__set_dependency",
|
|
659
|
+
"mcp__sideboard__clear_dependency",
|
|
660
|
+
"mcp__sideboard__satisfy_dependency",
|
|
661
|
+
"mcp__sideboard__posthog_api"
|
|
662
|
+
];
|
|
663
|
+
var SIDEBOARD_GITHUB_MCP_ALLOWED_TOOLS = ["mcp__sideboard__github_*"];
|
|
664
|
+
var SIDEBOARD_LINEAR_MCP_ALLOWED_TOOLS = ["mcp__sideboard__linear_*"];
|
|
665
|
+
var SIDEBOARD_ABLETIME_MCP_ALLOWED_TOOLS = ["mcp__sideboard__abletime_*"];
|
|
666
|
+
function sideboardWorktreeAllowedTools(opts) {
|
|
667
|
+
const out = SIDEBOARD_ARTIFACT_MCP_ALLOWED_TOOLS.filter(
|
|
668
|
+
(tool) => (opts?.planMode || tool !== "mcp__sideboard__present_plan") && (opts?.posthog || tool !== "mcp__sideboard__posthog_api")
|
|
669
|
+
);
|
|
670
|
+
if (opts?.github !== false) out.push(...SIDEBOARD_GITHUB_MCP_ALLOWED_TOOLS);
|
|
671
|
+
if (opts?.linear) out.push(...SIDEBOARD_LINEAR_MCP_ALLOWED_TOOLS);
|
|
672
|
+
if (opts?.abletime) out.push(...SIDEBOARD_ABLETIME_MCP_ALLOWED_TOOLS);
|
|
673
|
+
return out;
|
|
582
674
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
675
|
+
var BRIGHTSY_MCP_ALLOWED_TOOLS = [
|
|
676
|
+
"mcp__brightsy",
|
|
677
|
+
"mcp__brightsy__*"
|
|
678
|
+
];
|
|
679
|
+
var brightsyMcpCommandCache = null;
|
|
680
|
+
async function resolveBrightsyMcpCommand() {
|
|
681
|
+
const now = Date.now();
|
|
682
|
+
if (brightsyMcpCommandCache && now - brightsyMcpCommandCache.at < 6e4 && brightsyMcpCommandCache.command) {
|
|
683
|
+
return brightsyMcpCommandCache.command;
|
|
590
684
|
}
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
else if (/^plugin_/i.test(body)) body = body.slice("plugin_".length);
|
|
596
|
-
else if (/^plugin:/i.test(body)) body = body.slice("plugin:".length);
|
|
597
|
-
else if (/^mcp_/i.test(body)) body = body.slice("mcp_".length);
|
|
598
|
-
const head = body.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)[0];
|
|
599
|
-
if (!head || !SIDEBOARD_CONNECTOR_SERVICES.includes(head)) return null;
|
|
600
|
-
return head;
|
|
685
|
+
const which = await run("which", ["brightsy-mcp"], { reject: false });
|
|
686
|
+
const command = which.exitCode === 0 && which.stdout.trim() ? "brightsy-mcp" : "npx";
|
|
687
|
+
brightsyMcpCommandCache = { at: now, command };
|
|
688
|
+
return command;
|
|
601
689
|
}
|
|
602
|
-
function
|
|
603
|
-
let github = false;
|
|
604
|
-
try {
|
|
605
|
-
github = githubAgentAuthReady();
|
|
606
|
-
} catch {
|
|
607
|
-
github = false;
|
|
608
|
-
}
|
|
609
|
-
let linear = false;
|
|
610
|
-
let posthog = false;
|
|
611
|
-
let vercel = false;
|
|
612
|
-
let supabase = false;
|
|
613
|
-
let sentry = false;
|
|
690
|
+
function isBrightsyConnected() {
|
|
614
691
|
try {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
const integrations = loadAppSettings().integrations ?? {};
|
|
618
|
-
if (integrations.githubPat?.trim()) github = true;
|
|
619
|
-
vercel = Boolean(integrations.vercelToken?.trim());
|
|
620
|
-
supabase = Boolean(integrations.supabaseAccessToken?.trim());
|
|
621
|
-
sentry = Boolean(integrations.sentryAuthToken?.trim());
|
|
692
|
+
loadBrightsyConfig();
|
|
693
|
+
return true;
|
|
622
694
|
} catch {
|
|
695
|
+
return false;
|
|
623
696
|
}
|
|
624
|
-
return { github, linear, posthog, vercel, supabase, sentry };
|
|
625
697
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (isMcpAuthStatus(server.status)) return false;
|
|
630
|
-
const service = sideboardServiceForClaudeConnector(server.name);
|
|
631
|
-
if (service) return !(sideboardOk && coverage[service]);
|
|
632
|
-
if (isVendorClaudeAiMcpName(server.name)) return false;
|
|
633
|
-
return true;
|
|
698
|
+
var BRIGHTSY_WORD = /(?<![a-z0-9_-])brightsy(?![a-z0-9_-])/i;
|
|
699
|
+
function promptMentionsBrightsy(text) {
|
|
700
|
+
return BRIGHTSY_WORD.test(text ?? "");
|
|
634
701
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
import { homedir as homedir5 } from "os";
|
|
639
|
-
|
|
640
|
-
// src/agents/orch-mcp-isolation.ts
|
|
641
|
-
import { existsSync as existsSync5, readFileSync as readFileSync3 } from "fs";
|
|
642
|
-
|
|
643
|
-
// src/agents/claude-plugins.ts
|
|
644
|
-
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
645
|
-
import { homedir } from "os";
|
|
646
|
-
import { isAbsolute, join, relative, resolve } from "path";
|
|
647
|
-
|
|
648
|
-
// src/mcp-ui/meta.ts
|
|
649
|
-
var HTML_MAX = 15e5;
|
|
650
|
-
function matchClaudeMcpTool(toolName, serverNames) {
|
|
651
|
-
const name = toolName.trim();
|
|
652
|
-
if (!name.startsWith("mcp__")) return null;
|
|
653
|
-
const ranked = [...serverNames].filter((s) => s.trim()).sort((a, b) => b.length - a.length);
|
|
654
|
-
for (const server of ranked) {
|
|
655
|
-
const prefix = `mcp__${server}__`;
|
|
656
|
-
if (!name.startsWith(prefix)) continue;
|
|
657
|
-
const tool = name.slice(prefix.length).trim();
|
|
658
|
-
if (!tool) continue;
|
|
659
|
-
return { server, tool };
|
|
660
|
-
}
|
|
661
|
-
return null;
|
|
702
|
+
function isBrightsyMcpToolName(name) {
|
|
703
|
+
const n = name.toLowerCase();
|
|
704
|
+
return n === "brightsy" || n.startsWith("mcp__brightsy") || n.startsWith("brightsy_");
|
|
662
705
|
}
|
|
663
|
-
function
|
|
664
|
-
const
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
const url = typeof entry.url === "string" ? entry.url.trim() : "";
|
|
678
|
-
if (!url) return null;
|
|
679
|
-
let parsed;
|
|
680
|
-
try {
|
|
681
|
-
parsed = new URL(url);
|
|
682
|
-
} catch {
|
|
683
|
-
return null;
|
|
684
|
-
}
|
|
685
|
-
if (parsed.protocol !== "https:" && parsed.protocol !== "http:") return null;
|
|
686
|
-
const type = typeof entry.type === "string" ? entry.type.trim().toLowerCase() : "";
|
|
687
|
-
const headers = stringRecord(entry.headers);
|
|
688
|
-
return {
|
|
689
|
-
kind: type === "sse" ? "sse" : "http",
|
|
690
|
-
url: parsed.toString(),
|
|
691
|
-
...headers ? { headers } : {}
|
|
692
|
-
};
|
|
706
|
+
function toolInputUsesBrightsyDatasource(input) {
|
|
707
|
+
const ds = input?.datasource;
|
|
708
|
+
return typeof ds === "string" && ds.toLowerCase() === "brightsy";
|
|
709
|
+
}
|
|
710
|
+
function messageUsedBrightsyMcp(msg) {
|
|
711
|
+
if (msg.role === "user" && promptMentionsBrightsy(msg.text)) return true;
|
|
712
|
+
for (const part of msg.parts ?? []) {
|
|
713
|
+
if (part.type !== "tool") continue;
|
|
714
|
+
if (isBrightsyMcpToolName(part.name)) return true;
|
|
715
|
+
if (/present_(schema|files)$/i.test(part.name) && toolInputUsesBrightsyDatasource(part.input)) {
|
|
716
|
+
return true;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return false;
|
|
693
720
|
}
|
|
694
|
-
function
|
|
695
|
-
|
|
696
|
-
const nested = asRecord(rec.ui);
|
|
697
|
-
const fromNested = typeof nested.resourceUri === "string" ? nested.resourceUri.trim() : "";
|
|
698
|
-
const legacy = typeof rec["ui/resourceUri"] === "string" ? rec["ui/resourceUri"].trim() : "";
|
|
699
|
-
const uri = fromNested || legacy;
|
|
700
|
-
return uri.startsWith("ui://") ? uri : null;
|
|
721
|
+
function threadRequestsBrightsyMcp(thread) {
|
|
722
|
+
return (thread?.messages ?? []).some(messageUsedBrightsyMcp);
|
|
701
723
|
}
|
|
702
|
-
function
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
const
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
724
|
+
function shouldInjectBrightsyMcp(thread, opts) {
|
|
725
|
+
if (!(opts?.connected ?? isBrightsyConnected())) return false;
|
|
726
|
+
if (opts?.orchestrator) return true;
|
|
727
|
+
const alwaysOn = opts?.alwaysOnWorktree ?? Boolean(loadAppSettings().brightsy?.injectWorktreeMcp);
|
|
728
|
+
if (alwaysOn) return true;
|
|
729
|
+
return threadRequestsBrightsyMcp(thread);
|
|
730
|
+
}
|
|
731
|
+
function mcpLaunch(cmd, name, env) {
|
|
732
|
+
if (cmd === "brightsy-mcp") {
|
|
733
|
+
return { name, command: "brightsy-mcp", ...env ? { env } : {} };
|
|
711
734
|
}
|
|
712
735
|
return {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
...
|
|
736
|
+
name,
|
|
737
|
+
command: "npx",
|
|
738
|
+
args: ["-y", "@brightsy/mcp-server"],
|
|
739
|
+
...env ? { env } : {}
|
|
717
740
|
};
|
|
718
741
|
}
|
|
719
|
-
function
|
|
720
|
-
const
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
742
|
+
function teamEnv(team) {
|
|
743
|
+
const endpoint = (team.endpoint || "https://brightsy.ai").replace(/\/$/, "");
|
|
744
|
+
return {
|
|
745
|
+
BRIGHTSY_API_TOKEN: team.access_token,
|
|
746
|
+
...team.refresh_token ? { BRIGHTSY_REFRESH_TOKEN: team.refresh_token } : {},
|
|
747
|
+
...team.oauth_client_id ? { BRIGHTSY_OAUTH_CLIENT_ID: team.oauth_client_id } : {},
|
|
748
|
+
BRIGHTSY_ACCOUNT_ID: team.id,
|
|
749
|
+
BRIGHTSY_API_URL: endpoint
|
|
750
|
+
};
|
|
727
751
|
}
|
|
728
|
-
function
|
|
729
|
-
const
|
|
730
|
-
const
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
return [
|
|
735
|
-
"default-src 'none'",
|
|
736
|
-
`script-src 'self' 'unsafe-inline' ${resource}`.trim(),
|
|
737
|
-
`style-src 'self' 'unsafe-inline' ${resource}`.trim(),
|
|
738
|
-
`img-src 'self' data: ${resource}`.trim(),
|
|
739
|
-
`font-src 'self' ${resource}`.trim(),
|
|
740
|
-
`connect-src ${connectSrc}`,
|
|
741
|
-
`media-src 'self' data: ${resource}`.trim(),
|
|
742
|
-
`frame-src ${frames}`,
|
|
743
|
-
`base-uri ${base}`,
|
|
744
|
-
"object-src 'none'"
|
|
745
|
-
].join("; ");
|
|
752
|
+
function brightsyMcpAllowedTools(serverNames) {
|
|
753
|
+
const out = [];
|
|
754
|
+
for (const name of serverNames) {
|
|
755
|
+
out.push(`mcp__${name}`, `mcp__${name}__*`);
|
|
756
|
+
}
|
|
757
|
+
return out;
|
|
746
758
|
}
|
|
747
|
-
function
|
|
748
|
-
|
|
749
|
-
|
|
759
|
+
function corePackageDir() {
|
|
760
|
+
const cjsDir = typeof __dirname !== "undefined" ? __dirname : "";
|
|
761
|
+
if (cjsDir) return cjsDir;
|
|
762
|
+
try {
|
|
763
|
+
const url = import.meta.url;
|
|
764
|
+
if (typeof url === "string" && url.length > 0) {
|
|
765
|
+
return dirname(fileURLToPath(url));
|
|
766
|
+
}
|
|
767
|
+
} catch {
|
|
750
768
|
}
|
|
751
|
-
if (typeof blob !== "string" || !blob.trim()) return null;
|
|
752
769
|
try {
|
|
753
|
-
const
|
|
754
|
-
|
|
755
|
-
return decoded;
|
|
770
|
+
const req = createRequire(join3(process.cwd(), "package.json"));
|
|
771
|
+
return dirname(req.resolve("@sideboard-ai/core"));
|
|
756
772
|
} catch {
|
|
757
|
-
return
|
|
773
|
+
return process.cwd();
|
|
758
774
|
}
|
|
759
775
|
}
|
|
760
|
-
function
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const
|
|
764
|
-
|
|
776
|
+
function findSideboardMcpJsEntry() {
|
|
777
|
+
const override = process.env.SIDEBOARD_MCP_ENTRY?.trim() || process.env.SIDEBOARD_CLI?.trim();
|
|
778
|
+
if (override && existsSync2(override)) return override;
|
|
779
|
+
const packaged = packagedMcpStdioPath();
|
|
780
|
+
if (packaged) return packaged;
|
|
781
|
+
let dir = corePackageDir();
|
|
782
|
+
for (let i = 0; i < 10; i++) {
|
|
783
|
+
const candidates = [
|
|
784
|
+
join3(dir, "mcp/run-stdio.js"),
|
|
785
|
+
join3(dir, "mcp/run-stdio.cjs"),
|
|
786
|
+
join3(dir, "dist/mcp/run-stdio.js"),
|
|
787
|
+
join3(dir, "dist/mcp/run-stdio.cjs"),
|
|
788
|
+
join3(dir, "packages/core/dist/mcp/run-stdio.js"),
|
|
789
|
+
join3(dir, "packages/cli/dist/index.js"),
|
|
790
|
+
join3(dir, "cli/dist/index.js")
|
|
791
|
+
];
|
|
792
|
+
for (const p of candidates) {
|
|
793
|
+
if (existsSync2(p) && !isAsarPath(p)) return p;
|
|
794
|
+
}
|
|
795
|
+
const parent = dirname(dir);
|
|
796
|
+
if (parent === dir) break;
|
|
797
|
+
dir = parent;
|
|
798
|
+
}
|
|
799
|
+
return null;
|
|
765
800
|
}
|
|
766
|
-
function
|
|
767
|
-
const
|
|
768
|
-
|
|
801
|
+
async function resolveSideboardMcpServer() {
|
|
802
|
+
const entry = findSideboardMcpJsEntry();
|
|
803
|
+
if (entry) {
|
|
804
|
+
const isCli = /[/\\]cli[/\\]dist[/\\]index\.js$/.test(entry);
|
|
805
|
+
const scriptArgs = isCli ? [entry, "mcp"] : [entry];
|
|
806
|
+
const launch = applyNodeLaunch(await resolveNodeLaunch(entry), scriptArgs);
|
|
807
|
+
if (launch.file !== "/bin/sh" && !isElectronLikeCommand(launch.file)) {
|
|
808
|
+
return {
|
|
809
|
+
name: "sideboard",
|
|
810
|
+
command: launch.file,
|
|
811
|
+
args: launch.args,
|
|
812
|
+
...Object.keys(launch.env).length > 0 ? { env: launch.env } : {}
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
const which = await run("which", ["sideboard"], { reject: false });
|
|
817
|
+
if (which.exitCode === 0 && which.stdout.trim()) {
|
|
818
|
+
return { name: "sideboard", command: which.stdout.trim(), args: ["mcp"] };
|
|
819
|
+
}
|
|
820
|
+
return { name: "sideboard", command: "sideboard", args: ["mcp"] };
|
|
769
821
|
}
|
|
770
|
-
function
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
822
|
+
async function buildInjectedMcpServers(opts) {
|
|
823
|
+
const servers = [];
|
|
824
|
+
if (opts.includeSideboard) {
|
|
825
|
+
const sideboard = await resolveSideboardMcpServer();
|
|
826
|
+
sideboard.env = {
|
|
827
|
+
...sideboard.env ?? {},
|
|
828
|
+
...injectedSideboardMcpEnv(opts)
|
|
829
|
+
};
|
|
830
|
+
try {
|
|
831
|
+
mergeAgentGitAuthEnv(
|
|
832
|
+
sideboard.env,
|
|
833
|
+
await resolveAgentGitAuthEnv(sideboard.env)
|
|
834
|
+
);
|
|
835
|
+
} catch {
|
|
836
|
+
}
|
|
837
|
+
applyAgentRunnerHeapEnv(sideboard.env);
|
|
838
|
+
servers.push(sideboard);
|
|
839
|
+
}
|
|
840
|
+
if (opts.includeBrightsy && isBrightsyConnected()) {
|
|
841
|
+
const cmd = await resolveBrightsyMcpCommand();
|
|
842
|
+
const teams = await ensureConnectedBrightsyTeamTokens();
|
|
843
|
+
if (teams.length > 0) {
|
|
844
|
+
const used = /* @__PURE__ */ new Set();
|
|
845
|
+
for (const team of teams) {
|
|
846
|
+
let name = brightsyMcpServerName(team.slug);
|
|
847
|
+
if (used.has(name)) name = `${name}_${team.id.slice(0, 8)}`;
|
|
848
|
+
used.add(name);
|
|
849
|
+
servers.push(mcpLaunch(cmd, name, teamEnv(team)));
|
|
850
|
+
}
|
|
851
|
+
} else {
|
|
852
|
+
servers.push(mcpLaunch(cmd, "brightsy"));
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return servers;
|
|
856
|
+
}
|
|
857
|
+
function cursorSafeMcpLaunch(command, args) {
|
|
858
|
+
if (process.platform === "win32") {
|
|
859
|
+
return args && args.length > 0 ? { command, args } : { command };
|
|
860
|
+
}
|
|
861
|
+
const unwrapped = unwrapStrippedElectronLaunch(command, args);
|
|
862
|
+
const file = unwrapped?.file ?? command;
|
|
863
|
+
const fileArgs = unwrapped?.args ?? args ?? [];
|
|
864
|
+
return fileArgs.length > 0 ? { command: file, args: fileArgs } : { command: file };
|
|
865
|
+
}
|
|
866
|
+
function mcpSpawnEnv(env) {
|
|
867
|
+
if (!env) return void 0;
|
|
868
|
+
const out = { ...env };
|
|
869
|
+
delete out.ELECTRON_RUN_AS_NODE;
|
|
870
|
+
delete out.ELECTRON_RUN_AS_NODE;
|
|
871
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
872
|
+
}
|
|
873
|
+
function toCursorMcpServers(servers) {
|
|
874
|
+
const out = {};
|
|
875
|
+
for (const s of servers) {
|
|
876
|
+
const env = mcpSpawnEnv(s.env);
|
|
877
|
+
const launch = cursorSafeMcpLaunch(s.command, s.args);
|
|
878
|
+
out[s.name] = {
|
|
879
|
+
type: "stdio",
|
|
880
|
+
command: launch.command,
|
|
881
|
+
...launch.args && launch.args.length > 0 ? { args: launch.args } : {},
|
|
882
|
+
...env ? { env } : {}
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
return out;
|
|
886
|
+
}
|
|
887
|
+
function toCodexMcpConfigArgs(servers) {
|
|
888
|
+
const args = [];
|
|
889
|
+
for (const s of servers) {
|
|
890
|
+
const prefix = `mcp_servers.${s.name}`;
|
|
891
|
+
args.push("-c", `${prefix}.command=${JSON.stringify(s.command)}`);
|
|
892
|
+
if (s.args?.length) {
|
|
893
|
+
args.push("-c", `${prefix}.args=${JSON.stringify(s.args)}`);
|
|
894
|
+
}
|
|
895
|
+
const env = mcpSpawnEnv(s.env);
|
|
896
|
+
if (env) {
|
|
897
|
+
for (const [key, value] of Object.entries(env)) {
|
|
898
|
+
if (isCodexSecretEnvKey(key)) continue;
|
|
899
|
+
args.push("-c", `${prefix}.env.${key}=${JSON.stringify(value)}`);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
args.push("-c", `${prefix}.default_tools_approval_mode=${JSON.stringify("approve")}`);
|
|
903
|
+
args.push("-c", `${prefix}.tool_timeout_sec=300`);
|
|
904
|
+
args.push("-c", `${prefix}.startup_timeout_sec=30`);
|
|
905
|
+
}
|
|
906
|
+
return args;
|
|
907
|
+
}
|
|
908
|
+
function toOpencodeMcpConfigContent(servers, opts) {
|
|
909
|
+
const mcp = {};
|
|
910
|
+
for (const s of servers) {
|
|
911
|
+
const env = mcpSpawnEnv(s.env);
|
|
912
|
+
mcp[s.name] = {
|
|
913
|
+
type: "local",
|
|
914
|
+
command: [s.command, ...s.args ?? []],
|
|
915
|
+
enabled: true,
|
|
916
|
+
...env ? { environment: env } : {}
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
for (const name of opts?.disableNames ?? []) {
|
|
920
|
+
const key = name.trim();
|
|
921
|
+
if (!key || mcp[key]?.enabled === true) continue;
|
|
922
|
+
mcp[key] = { ...mcp[key], enabled: false };
|
|
777
923
|
}
|
|
778
|
-
return
|
|
924
|
+
return JSON.stringify({ mcp });
|
|
779
925
|
}
|
|
780
|
-
function
|
|
781
|
-
const
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
926
|
+
function stripElectronFromUserMcpEntry(entry) {
|
|
927
|
+
const next = { ...entry };
|
|
928
|
+
const env = next.env;
|
|
929
|
+
if (!env || typeof env !== "object" || Array.isArray(env)) return next;
|
|
930
|
+
const cleaned = { ...env };
|
|
931
|
+
delete cleaned.ELECTRON_RUN_AS_NODE;
|
|
932
|
+
next.env = cleaned;
|
|
933
|
+
return next;
|
|
934
|
+
}
|
|
935
|
+
function mcpServersRecord(servers, extraServers) {
|
|
936
|
+
const mcpServers = {};
|
|
937
|
+
for (const s of servers) {
|
|
938
|
+
const env = mcpSpawnEnv(s.env);
|
|
939
|
+
mcpServers[s.name] = {
|
|
940
|
+
command: s.command,
|
|
941
|
+
...s.args ? { args: s.args } : {},
|
|
942
|
+
...env ? { env } : {}
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
if (extraServers) {
|
|
946
|
+
for (const [rawName, entry] of Object.entries(extraServers)) {
|
|
947
|
+
const name = rawName.trim();
|
|
948
|
+
if (!name || mcpServers[name] || !entry) continue;
|
|
949
|
+
mcpServers[name] = stripElectronFromUserMcpEntry(entry);
|
|
787
950
|
}
|
|
788
|
-
return url.origin;
|
|
789
|
-
} catch {
|
|
790
|
-
return null;
|
|
791
951
|
}
|
|
952
|
+
return mcpServers;
|
|
792
953
|
}
|
|
793
|
-
function
|
|
794
|
-
const
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
}
|
|
799
|
-
return
|
|
954
|
+
function writeMcpServersConfig(servers, extraServers) {
|
|
955
|
+
const mcpServers = mcpServersRecord(servers, extraServers);
|
|
956
|
+
if (Object.keys(mcpServers).length === 0) return null;
|
|
957
|
+
const dir = mkdtempSync(join3(tmpdir(), "sideboard-mcp-"));
|
|
958
|
+
const cfgPath = join3(dir, "mcp.json");
|
|
959
|
+
writeFileSync2(cfgPath, JSON.stringify({ mcpServers }, null, 2), { mode: 384 });
|
|
960
|
+
return cfgPath;
|
|
800
961
|
}
|
|
801
|
-
function
|
|
802
|
-
|
|
803
|
-
return value;
|
|
962
|
+
async function writeInjectedMcpConfig(opts) {
|
|
963
|
+
return writeMcpServersConfig(await buildInjectedMcpServers(opts));
|
|
804
964
|
}
|
|
805
965
|
|
|
806
|
-
// src/agents/
|
|
807
|
-
function
|
|
808
|
-
return
|
|
966
|
+
// src/agents/user-mcp-config.ts
|
|
967
|
+
function userCursorMcpConfigPath() {
|
|
968
|
+
return join4(homedir3(), ".cursor", "mcp.json");
|
|
809
969
|
}
|
|
810
|
-
function
|
|
811
|
-
|
|
812
|
-
const pluginsRoot = claudePluginsRoot(home);
|
|
813
|
-
const enabled = enabledPluginIds(home, opts?.projectDirs ?? []);
|
|
814
|
-
const installed = readInstalledPlugins(join(pluginsRoot, "installed_plugins.json"));
|
|
815
|
-
const out = {};
|
|
816
|
-
for (const [id, on] of enabled) {
|
|
817
|
-
if (!on) continue;
|
|
818
|
-
const root = installPathFor(id, installed);
|
|
819
|
-
if (!root || !existsSync2(root)) continue;
|
|
820
|
-
const pluginName = manifestName(root) || id.split("@")[0]?.trim() || "";
|
|
821
|
-
if (!pluginName) continue;
|
|
822
|
-
const dataDir = join(pluginsRoot, "data", pluginDataId(id));
|
|
823
|
-
for (const [serverName, entry] of Object.entries(loadPluginMcpServers(root))) {
|
|
824
|
-
const expanded = expandPluginEntry(entry, root, dataDir);
|
|
825
|
-
if (!parseMcpServerLaunch(expanded)) continue;
|
|
826
|
-
const key = claudePluginServerId(pluginName, serverName);
|
|
827
|
-
if (!key || key === "plugin__") continue;
|
|
828
|
-
out[key] = expanded;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
return out;
|
|
970
|
+
function userClaudeMcpConfigPath() {
|
|
971
|
+
return join4(homedir3(), ".claude.json");
|
|
832
972
|
}
|
|
833
|
-
function
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
return join(home, ".claude", "plugins");
|
|
973
|
+
function asObject(value) {
|
|
974
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
975
|
+
return { ...value };
|
|
837
976
|
}
|
|
838
|
-
function
|
|
839
|
-
|
|
977
|
+
function stripElectronSpawnEnv(env) {
|
|
978
|
+
if (!env) return void 0;
|
|
979
|
+
const next = { ...env };
|
|
980
|
+
delete next.ELECTRON_RUN_AS_NODE;
|
|
981
|
+
delete next.ELECTRON_RUN_AS_NODE;
|
|
982
|
+
return Object.keys(next).length > 0 ? next : void 0;
|
|
840
983
|
}
|
|
841
|
-
function
|
|
842
|
-
const
|
|
843
|
-
|
|
844
|
-
const
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
984
|
+
function mergeSideboardIntoMcpServersJson(existing, sideboard) {
|
|
985
|
+
const root = asObject(existing);
|
|
986
|
+
const servers = asObject(root.mcpServers);
|
|
987
|
+
const env = stripElectronSpawnEnv(sideboard.env);
|
|
988
|
+
servers.sideboard = {
|
|
989
|
+
type: "stdio",
|
|
990
|
+
command: sideboard.command,
|
|
991
|
+
...sideboard.args && sideboard.args.length > 0 ? { args: sideboard.args } : {},
|
|
992
|
+
...env ? { env } : {}
|
|
993
|
+
};
|
|
994
|
+
return { ...root, mcpServers: servers };
|
|
995
|
+
}
|
|
996
|
+
function writeMergedMcpServersJson(configPath, sideboard) {
|
|
997
|
+
let existing = {};
|
|
998
|
+
if (existsSync3(configPath)) {
|
|
999
|
+
try {
|
|
1000
|
+
existing = JSON.parse(readFileSync2(configPath, "utf8"));
|
|
1001
|
+
} catch {
|
|
1002
|
+
existing = {};
|
|
1003
|
+
}
|
|
850
1004
|
}
|
|
851
|
-
|
|
1005
|
+
const next = mergeSideboardIntoMcpServersJson(existing, sideboard);
|
|
1006
|
+
mkdirSync2(dirname2(configPath), { recursive: true });
|
|
1007
|
+
writeFileSync3(configPath, `${JSON.stringify(next, null, 2)}
|
|
1008
|
+
`);
|
|
852
1009
|
}
|
|
853
|
-
function
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1010
|
+
function launchFromResolved(server) {
|
|
1011
|
+
return {
|
|
1012
|
+
command: server.command,
|
|
1013
|
+
args: server.args,
|
|
1014
|
+
env: {
|
|
1015
|
+
...server.env ?? {},
|
|
1016
|
+
SIDEBOARD_APP_DATA: appDataDir()
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
}
|
|
1020
|
+
async function registerPackagedUserMcpClients() {
|
|
1021
|
+
const launch = launchFromResolved(await resolveSideboardMcpServer());
|
|
1022
|
+
const cursor = userCursorMcpConfigPath();
|
|
1023
|
+
writeMergedMcpServersJson(cursor, launch);
|
|
1024
|
+
const claude = userClaudeMcpConfigPath();
|
|
1025
|
+
if (existsSync3(claude)) {
|
|
1026
|
+
writeMergedMcpServersJson(claude, launch);
|
|
1027
|
+
return { cursor, claude };
|
|
858
1028
|
}
|
|
1029
|
+
return { cursor };
|
|
859
1030
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
1031
|
+
|
|
1032
|
+
// src/agents/orch-mcp-isolation.ts
|
|
1033
|
+
function isInjectedOrchMcpName(name) {
|
|
1034
|
+
const n = name.trim().toLowerCase();
|
|
1035
|
+
return n === "sideboard" || n === "brightsy" || n.startsWith("brightsy_");
|
|
1036
|
+
}
|
|
1037
|
+
function asObject2(value) {
|
|
1038
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return {};
|
|
1039
|
+
return value;
|
|
1040
|
+
}
|
|
1041
|
+
function listMcpNamesFromJsonMap(raw, key) {
|
|
1042
|
+
return Object.keys(asObject2(asObject2(raw)[key])).filter((n) => n.trim());
|
|
1043
|
+
}
|
|
1044
|
+
function listMcpNamesFromCodexToml(text) {
|
|
1045
|
+
try {
|
|
1046
|
+
const parsed = parseToml(text);
|
|
1047
|
+
return Object.keys(asObject2(parsed.mcp_servers)).filter((n) => n.trim());
|
|
1048
|
+
} catch {
|
|
1049
|
+
return [];
|
|
867
1050
|
}
|
|
868
|
-
return out;
|
|
869
1051
|
}
|
|
870
|
-
function
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
for (const [id, value] of Object.entries(plugins)) {
|
|
876
|
-
const rows = Array.isArray(value) ? value : [value];
|
|
877
|
-
const installs = [];
|
|
878
|
-
for (const row of rows) {
|
|
879
|
-
if (!row || typeof row !== "object" || Array.isArray(row)) continue;
|
|
880
|
-
const installPath = row.installPath;
|
|
881
|
-
installs.push({
|
|
882
|
-
...typeof installPath === "string" && installPath.trim() ? { installPath: installPath.trim() } : {}
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
if (installs.length) out[id] = installs;
|
|
1052
|
+
function readJsonObject(path) {
|
|
1053
|
+
try {
|
|
1054
|
+
return JSON.parse(readFileSync3(path, "utf8"));
|
|
1055
|
+
} catch {
|
|
1056
|
+
return {};
|
|
886
1057
|
}
|
|
887
|
-
return out;
|
|
888
1058
|
}
|
|
889
|
-
function
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
1059
|
+
function readText(path) {
|
|
1060
|
+
try {
|
|
1061
|
+
return readFileSync3(path, "utf8");
|
|
1062
|
+
} catch {
|
|
1063
|
+
return "";
|
|
894
1064
|
}
|
|
895
|
-
return null;
|
|
896
1065
|
}
|
|
897
|
-
function
|
|
898
|
-
const
|
|
899
|
-
|
|
1066
|
+
function userCodexConfigPaths(home = homedir4()) {
|
|
1067
|
+
const paths = [
|
|
1068
|
+
join5(home, ".codex", "config.toml"),
|
|
1069
|
+
join5(home, ".config", "codex", "config.toml")
|
|
1070
|
+
];
|
|
1071
|
+
const codexHome = process.env.CODEX_HOME?.trim();
|
|
1072
|
+
if (codexHome) paths.unshift(join5(codexHome, "config.toml"));
|
|
1073
|
+
return paths;
|
|
900
1074
|
}
|
|
901
|
-
function
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
return servers;
|
|
1075
|
+
function userOpencodeConfigPaths(home = homedir4()) {
|
|
1076
|
+
return [
|
|
1077
|
+
join5(home, ".config", "opencode", "opencode.json"),
|
|
1078
|
+
join5(home, ".config", "opencode", "opencode.jsonc")
|
|
1079
|
+
];
|
|
907
1080
|
}
|
|
908
|
-
function
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
1081
|
+
function userMcpNamesToDisable(opts) {
|
|
1082
|
+
const keep = new Set(
|
|
1083
|
+
[...opts.injectedNames ?? []].map((n) => n.trim().toLowerCase()).filter(Boolean)
|
|
1084
|
+
);
|
|
1085
|
+
const out = [];
|
|
1086
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1087
|
+
for (const raw of opts.names) {
|
|
1088
|
+
const name = raw.trim();
|
|
1089
|
+
if (!name) continue;
|
|
1090
|
+
const key = name.toLowerCase();
|
|
1091
|
+
if (seen.has(key) || keep.has(key) || isInjectedOrchMcpName(name)) continue;
|
|
1092
|
+
seen.add(key);
|
|
1093
|
+
out.push(name);
|
|
918
1094
|
}
|
|
919
|
-
return
|
|
1095
|
+
return out;
|
|
920
1096
|
}
|
|
921
|
-
function
|
|
922
|
-
|
|
923
|
-
|
|
1097
|
+
function listUserCodexMcpNames(home = homedir4()) {
|
|
1098
|
+
const names = [];
|
|
1099
|
+
for (const path of userCodexConfigPaths(home)) {
|
|
1100
|
+
if (!existsSync4(path)) continue;
|
|
1101
|
+
names.push(...listMcpNamesFromCodexToml(readText(path)));
|
|
1102
|
+
}
|
|
1103
|
+
return names;
|
|
924
1104
|
}
|
|
925
|
-
function
|
|
926
|
-
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
if (typeof wrapped === "string") return serversFromFile(resolveInside(root, wrapped), root);
|
|
931
|
-
const out = {};
|
|
932
|
-
for (const [name, entry] of Object.entries(source)) {
|
|
933
|
-
if (!name.trim() || !entry || typeof entry !== "object" || Array.isArray(entry)) continue;
|
|
934
|
-
const row = entry;
|
|
935
|
-
if (row.disabled === true) continue;
|
|
936
|
-
if (typeof row.command !== "string" && typeof row.url !== "string") continue;
|
|
937
|
-
out[name.trim()] = row;
|
|
1105
|
+
function listUserOpencodeMcpNames(home = homedir4()) {
|
|
1106
|
+
const names = [];
|
|
1107
|
+
for (const path of userOpencodeConfigPaths(home)) {
|
|
1108
|
+
if (!existsSync4(path)) continue;
|
|
1109
|
+
names.push(...listMcpNamesFromJsonMap(readJsonObject(path), "mcp"));
|
|
938
1110
|
}
|
|
939
|
-
return
|
|
1111
|
+
return names;
|
|
940
1112
|
}
|
|
941
|
-
function
|
|
942
|
-
|
|
1113
|
+
function userClaudeMcpConfigObject(home = homedir4()) {
|
|
1114
|
+
const claudePath = home === homedir4() ? userClaudeMcpConfigPath() : join5(home, ".claude.json");
|
|
1115
|
+
if (!existsSync4(claudePath)) return {};
|
|
1116
|
+
return asObject2(asObject2(readJsonObject(claudePath)).mcpServers);
|
|
943
1117
|
}
|
|
944
|
-
function
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
if (next.env && typeof next.env === "object" && !Array.isArray(next.env)) {
|
|
952
|
-
const env = {};
|
|
953
|
-
for (const [key, value] of Object.entries(next.env)) {
|
|
954
|
-
if (typeof value === "string") env[key] = expandVars(value, root, dataDir);
|
|
955
|
-
}
|
|
956
|
-
env.CLAUDE_PLUGIN_ROOT = env.CLAUDE_PLUGIN_ROOT || root;
|
|
957
|
-
env.CLAUDE_PLUGIN_DATA = env.CLAUDE_PLUGIN_DATA || dataDir;
|
|
958
|
-
next.env = env;
|
|
959
|
-
} else if (typeof next.command === "string") {
|
|
960
|
-
next.env = { CLAUDE_PLUGIN_ROOT: root, CLAUDE_PLUGIN_DATA: dataDir };
|
|
1118
|
+
function listUserClaudeMcpServerEntries(home = homedir4(), projectDirs) {
|
|
1119
|
+
const out = {};
|
|
1120
|
+
for (const [name, entry] of Object.entries(
|
|
1121
|
+
listEnabledClaudePluginMcpServers({ home, projectDirs })
|
|
1122
|
+
)) {
|
|
1123
|
+
if (!name || isInjectedOrchMcpName(name)) continue;
|
|
1124
|
+
out[name] = entry;
|
|
961
1125
|
}
|
|
962
|
-
|
|
963
|
-
const
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
next.headers = headers;
|
|
1126
|
+
for (const [rawName, value] of Object.entries(userClaudeMcpConfigObject(home))) {
|
|
1127
|
+
const name = rawName.trim();
|
|
1128
|
+
if (!name || isInjectedOrchMcpName(name)) continue;
|
|
1129
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
1130
|
+
out[name] = value;
|
|
968
1131
|
}
|
|
969
|
-
return
|
|
970
|
-
}
|
|
971
|
-
function expandVars(value, root, dataDir) {
|
|
972
|
-
return value.replaceAll("${CLAUDE_PLUGIN_ROOT}", root).replaceAll("${CLAUDE_PLUGIN_DATA}", dataDir);
|
|
973
|
-
}
|
|
974
|
-
function resolveInside(root, spec) {
|
|
975
|
-
const trimmed = spec.trim();
|
|
976
|
-
if (!trimmed || trimmed.endsWith(".mcpb") || trimmed.endsWith(".dxt")) return null;
|
|
977
|
-
if (/^https?:\/\//i.test(trimmed)) return null;
|
|
978
|
-
const abs = resolve(root, trimmed);
|
|
979
|
-
const rel = relative(root, abs);
|
|
980
|
-
if (!rel || rel.startsWith("..") || isAbsolute(rel)) return null;
|
|
981
|
-
return abs;
|
|
1132
|
+
return out;
|
|
982
1133
|
}
|
|
983
|
-
function
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
return parsed;
|
|
989
|
-
} catch {
|
|
990
|
-
return {};
|
|
1134
|
+
function toCodexDisableUserMcpArgs(names) {
|
|
1135
|
+
const args = [];
|
|
1136
|
+
for (const name of names) {
|
|
1137
|
+
if (!/^[A-Za-z0-9_-]+$/.test(name)) continue;
|
|
1138
|
+
args.push("-c", `mcp_servers.${name}.enabled=false`);
|
|
991
1139
|
}
|
|
1140
|
+
return args;
|
|
992
1141
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
// src/agents/injected-mcp.ts
|
|
1005
|
-
import { existsSync as existsSync3, mkdtempSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1006
|
-
import { createRequire } from "module";
|
|
1007
|
-
import { tmpdir } from "os";
|
|
1008
|
-
import { dirname, join as join3 } from "path";
|
|
1009
|
-
import { fileURLToPath } from "url";
|
|
1010
|
-
|
|
1011
|
-
// src/mcp/profile.ts
|
|
1012
|
-
var SIDEBOARD_MCP_PROFILE_ENV = "SIDEBOARD_MCP_PROFILE";
|
|
1013
|
-
var SIDEBOARD_THREAD_ID_ENV = "SIDEBOARD_THREAD_ID";
|
|
1014
|
-
function agentRpcOwnsPilotTools(env = process.env) {
|
|
1015
|
-
return env[AGENT_RPC_NATIVE_ENV]?.trim() === "1";
|
|
1142
|
+
function toCodexUnattendedAppsArgs() {
|
|
1143
|
+
return [
|
|
1144
|
+
"-c",
|
|
1145
|
+
"features.apps=false",
|
|
1146
|
+
"-c",
|
|
1147
|
+
"apps._default.enabled=false",
|
|
1148
|
+
"-c",
|
|
1149
|
+
"apps.posthog.enabled=false",
|
|
1150
|
+
"-c",
|
|
1151
|
+
"features.plugins=false"
|
|
1152
|
+
];
|
|
1016
1153
|
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1154
|
+
|
|
1155
|
+
// src/agents/turn-input.ts
|
|
1156
|
+
function normalizeTurnInput(input) {
|
|
1157
|
+
if (typeof input === "string") return { prompt: input };
|
|
1158
|
+
return {
|
|
1159
|
+
prompt: input.prompt,
|
|
1160
|
+
cachedPrefix: input.cachedPrefix?.trim() || void 0,
|
|
1161
|
+
systemPrompt: input.systemPrompt?.trim() || void 0,
|
|
1162
|
+
...input.isolateCodexPlugins ? { isolateCodexPlugins: true } : {}
|
|
1023
1163
|
};
|
|
1024
|
-
if (orchId) env.SIDEBOARD_ORCHESTRATOR_THREAD_ID = orchId;
|
|
1025
|
-
if (threadId) env[SIDEBOARD_THREAD_ID_ENV] = threadId;
|
|
1026
|
-
if (opts.rpcNativeTools) env[AGENT_RPC_NATIVE_ENV] = "1";
|
|
1027
|
-
return env;
|
|
1028
|
-
}
|
|
1029
|
-
var AGENT_RPC_PILOT_MCP_TOOLS = [
|
|
1030
|
-
"present_artifact",
|
|
1031
|
-
"wait_for_job",
|
|
1032
|
-
"stop_job"
|
|
1033
|
-
];
|
|
1034
|
-
function shouldRegisterMcpWaitForTurn(env = process.env) {
|
|
1035
|
-
return !agentRpcOwnsPilotTools(env);
|
|
1036
|
-
}
|
|
1037
|
-
function worktreeMcpToolNames(env = process.env) {
|
|
1038
|
-
if (!agentRpcOwnsPilotTools(env)) return WORKTREE_MCP_TOOLS;
|
|
1039
|
-
const omit = new Set(AGENT_RPC_PILOT_MCP_TOOLS);
|
|
1040
|
-
return WORKTREE_MCP_TOOLS.filter((name) => !omit.has(name));
|
|
1041
1164
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
"stop_dev_script",
|
|
1053
|
-
"get_run_log",
|
|
1054
|
-
"get_orchestrator",
|
|
1055
|
-
"notify_orchestrator",
|
|
1056
|
-
"set_workspace_tags",
|
|
1057
|
-
"set_wake_on_github_edges",
|
|
1058
|
-
"get_viewer_context",
|
|
1059
|
-
"update_viewer_context",
|
|
1060
|
-
"list_env",
|
|
1061
|
-
"set_env",
|
|
1062
|
-
"delete_env",
|
|
1063
|
-
"list_schedules",
|
|
1064
|
-
"create_schedule",
|
|
1065
|
-
"update_schedule",
|
|
1066
|
-
"delete_schedule",
|
|
1067
|
-
"run_schedule",
|
|
1068
|
-
"list_order",
|
|
1069
|
-
"show_plan",
|
|
1070
|
-
"set_dependency",
|
|
1071
|
-
"clear_dependency",
|
|
1072
|
-
"satisfy_dependency"
|
|
1073
|
-
];
|
|
1074
|
-
var WORKTREE_GITHUB_MCP_TOOLS = [
|
|
1075
|
-
"github_search_issues",
|
|
1076
|
-
"github_list_projects",
|
|
1077
|
-
"github_get_issue",
|
|
1078
|
-
"github_download_attachment",
|
|
1079
|
-
"github_comment",
|
|
1080
|
-
"github_update_issue",
|
|
1081
|
-
"github_create_issue"
|
|
1082
|
-
];
|
|
1083
|
-
var WORKTREE_LINEAR_MCP_TOOLS = [
|
|
1084
|
-
"linear_list_teams",
|
|
1085
|
-
"linear_list_projects",
|
|
1086
|
-
"linear_search_issues",
|
|
1087
|
-
"linear_get_issue",
|
|
1088
|
-
"linear_download_attachment",
|
|
1089
|
-
"linear_create_issue",
|
|
1090
|
-
"linear_update_issue",
|
|
1091
|
-
"linear_comment"
|
|
1092
|
-
];
|
|
1093
|
-
var WORKTREE_ABLETIME_MCP_TOOLS = [
|
|
1094
|
-
"abletime_orientation",
|
|
1095
|
-
"abletime_list_projects",
|
|
1096
|
-
"abletime_list_tasks",
|
|
1097
|
-
"abletime_search_tasks",
|
|
1098
|
-
"abletime_get_task",
|
|
1099
|
-
"abletime_download_attachment",
|
|
1100
|
-
"abletime_comment",
|
|
1101
|
-
"abletime_update_task",
|
|
1102
|
-
"abletime_create_task",
|
|
1103
|
-
"abletime_ensure_task"
|
|
1104
|
-
];
|
|
1105
|
-
function sideboardMcpProfile(env = process.env) {
|
|
1106
|
-
return env[SIDEBOARD_MCP_PROFILE_ENV]?.trim().toLowerCase() === "worktree" ? "worktree" : "orchestration";
|
|
1165
|
+
function dropCachedPrefixOnResume(input, sessionId) {
|
|
1166
|
+
const turn = normalizeTurnInput(input);
|
|
1167
|
+
if (sessionId) {
|
|
1168
|
+
return {
|
|
1169
|
+
prompt: turn.prompt,
|
|
1170
|
+
...turn.systemPrompt ? { systemPrompt: turn.systemPrompt } : {},
|
|
1171
|
+
...turn.isolateCodexPlugins ? { isolateCodexPlugins: true } : {}
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
return turn;
|
|
1107
1175
|
}
|
|
1176
|
+
function flattenTurnInput(input) {
|
|
1177
|
+
const { cachedPrefix, prompt, systemPrompt } = normalizeTurnInput(input);
|
|
1178
|
+
if (cachedPrefix) return `${cachedPrefix}
|
|
1108
1179
|
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1180
|
+
---
|
|
1181
|
+
|
|
1182
|
+
Current request:
|
|
1183
|
+
${prompt}`;
|
|
1184
|
+
if (systemPrompt) return `${systemPrompt}
|
|
1185
|
+
|
|
1186
|
+
${prompt}`;
|
|
1187
|
+
return prompt;
|
|
1116
1188
|
}
|
|
1117
|
-
function
|
|
1118
|
-
|
|
1189
|
+
function splitTurnInputForSystemPrompt(input) {
|
|
1190
|
+
const turn = normalizeTurnInput(input);
|
|
1191
|
+
return {
|
|
1192
|
+
promptText: flattenTurnInput({ cachedPrefix: turn.cachedPrefix, prompt: turn.prompt }),
|
|
1193
|
+
systemPrompt: turn.systemPrompt
|
|
1194
|
+
};
|
|
1119
1195
|
}
|
|
1120
|
-
function
|
|
1121
|
-
|
|
1122
|
-
const out = { ...env };
|
|
1123
|
-
delete out.ELECTRON_RUN_AS_NODE;
|
|
1124
|
-
return Object.keys(out).length > 0 ? out : void 0;
|
|
1196
|
+
function buildCachedUserContent(input) {
|
|
1197
|
+
return [{ type: "text", text: flattenTurnInput(input) }];
|
|
1125
1198
|
}
|
|
1126
|
-
function
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1199
|
+
function buildClaudeStreamJsonUserMessage(input) {
|
|
1200
|
+
return `${JSON.stringify({
|
|
1201
|
+
type: "user",
|
|
1202
|
+
message: {
|
|
1203
|
+
role: "user",
|
|
1204
|
+
content: buildCachedUserContent(input)
|
|
1205
|
+
}
|
|
1206
|
+
})}
|
|
1207
|
+
`;
|
|
1208
|
+
}
|
|
1209
|
+
function walkCacheControls(blocks, saw5m) {
|
|
1210
|
+
if (!blocks?.length) return { saw5m, invalid: null };
|
|
1211
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
1212
|
+
const block = blocks[i];
|
|
1213
|
+
const ttl = block.cache_control?.ttl ?? (block.cache_control ? "5m" : null);
|
|
1214
|
+
if (ttl === "5m") saw5m = true;
|
|
1215
|
+
if (ttl === "1h" && saw5m) return { saw5m, invalid: { index: i, ttl: "1h" } };
|
|
1216
|
+
if (Array.isArray(block.content)) {
|
|
1217
|
+
const nested = walkCacheControls(block.content, saw5m);
|
|
1218
|
+
if (nested.invalid) return { saw5m: nested.saw5m, invalid: { index: i, ttl: "1h" } };
|
|
1219
|
+
saw5m = nested.saw5m;
|
|
1220
|
+
}
|
|
1136
1221
|
}
|
|
1137
|
-
|
|
1138
|
-
const home = process.env.CODEX_HOME?.trim() || join2(homedir2(), ".codex");
|
|
1139
|
-
mkdirSync(home, { recursive: true, mode: 448 });
|
|
1140
|
-
const profile = `sideboard-${randomBytes(8).toString("hex")}`;
|
|
1141
|
-
const file = join2(home, `${profile}.config.toml`);
|
|
1142
|
-
writeFileSync(file, `${blocks.join("\n\n")}
|
|
1143
|
-
`, { mode: 384 });
|
|
1144
|
-
return { profile, file };
|
|
1222
|
+
return { saw5m, invalid: null };
|
|
1145
1223
|
}
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
var SIDEBOARD_MCP_ALLOWED_TOOLS = [
|
|
1149
|
-
"mcp__sideboard",
|
|
1150
|
-
"mcp__sideboard__*"
|
|
1151
|
-
];
|
|
1152
|
-
var SIDEBOARD_ARTIFACT_MCP_ALLOWED_TOOLS = [
|
|
1153
|
-
"mcp__sideboard__present_artifact",
|
|
1154
|
-
"mcp__sideboard__present_schema",
|
|
1155
|
-
"mcp__sideboard__present_files",
|
|
1156
|
-
"mcp__sideboard__ask_user",
|
|
1157
|
-
"mcp__sideboard__present_plan",
|
|
1158
|
-
"mcp__sideboard__wait_for_job",
|
|
1159
|
-
"mcp__sideboard__stop_job",
|
|
1160
|
-
"mcp__sideboard__list_run_scripts",
|
|
1161
|
-
"mcp__sideboard__run_dev_script",
|
|
1162
|
-
"mcp__sideboard__stop_dev_script",
|
|
1163
|
-
"mcp__sideboard__get_run_log",
|
|
1164
|
-
"mcp__sideboard__get_orchestrator",
|
|
1165
|
-
"mcp__sideboard__notify_orchestrator",
|
|
1166
|
-
"mcp__sideboard__set_workspace_tags",
|
|
1167
|
-
"mcp__sideboard__set_wake_on_github_edges",
|
|
1168
|
-
"mcp__sideboard__get_viewer_context",
|
|
1169
|
-
"mcp__sideboard__update_viewer_context",
|
|
1170
|
-
"mcp__sideboard__list_env",
|
|
1171
|
-
"mcp__sideboard__set_env",
|
|
1172
|
-
"mcp__sideboard__delete_env",
|
|
1173
|
-
"mcp__sideboard__list_schedules",
|
|
1174
|
-
"mcp__sideboard__create_schedule",
|
|
1175
|
-
"mcp__sideboard__update_schedule",
|
|
1176
|
-
"mcp__sideboard__delete_schedule",
|
|
1177
|
-
"mcp__sideboard__run_schedule",
|
|
1178
|
-
"mcp__sideboard__list_order",
|
|
1179
|
-
"mcp__sideboard__show_plan",
|
|
1180
|
-
"mcp__sideboard__set_dependency",
|
|
1181
|
-
"mcp__sideboard__clear_dependency",
|
|
1182
|
-
"mcp__sideboard__satisfy_dependency",
|
|
1183
|
-
"mcp__sideboard__posthog_api"
|
|
1184
|
-
];
|
|
1185
|
-
var SIDEBOARD_GITHUB_MCP_ALLOWED_TOOLS = ["mcp__sideboard__github_*"];
|
|
1186
|
-
var SIDEBOARD_LINEAR_MCP_ALLOWED_TOOLS = ["mcp__sideboard__linear_*"];
|
|
1187
|
-
var SIDEBOARD_ABLETIME_MCP_ALLOWED_TOOLS = ["mcp__sideboard__abletime_*"];
|
|
1188
|
-
function sideboardWorktreeAllowedTools(opts) {
|
|
1189
|
-
const out = SIDEBOARD_ARTIFACT_MCP_ALLOWED_TOOLS.filter(
|
|
1190
|
-
(tool) => (opts?.planMode || tool !== "mcp__sideboard__present_plan") && (opts?.posthog || tool !== "mcp__sideboard__posthog_api")
|
|
1191
|
-
);
|
|
1192
|
-
if (opts?.github !== false) out.push(...SIDEBOARD_GITHUB_MCP_ALLOWED_TOOLS);
|
|
1193
|
-
if (opts?.linear) out.push(...SIDEBOARD_LINEAR_MCP_ALLOWED_TOOLS);
|
|
1194
|
-
if (opts?.abletime) out.push(...SIDEBOARD_ABLETIME_MCP_ALLOWED_TOOLS);
|
|
1195
|
-
return out;
|
|
1224
|
+
function findInvalidCacheControlTtlOrder(blocks) {
|
|
1225
|
+
return walkCacheControls(blocks, false).invalid;
|
|
1196
1226
|
}
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
return brightsyMcpCommandCache.command;
|
|
1227
|
+
function countCacheControlBlocks(blocks) {
|
|
1228
|
+
if (!blocks?.length) return 0;
|
|
1229
|
+
let count = 0;
|
|
1230
|
+
for (const block of blocks) {
|
|
1231
|
+
if (block.cache_control) count++;
|
|
1232
|
+
if (Array.isArray(block.content)) {
|
|
1233
|
+
count += countCacheControlBlocks(block.content);
|
|
1234
|
+
}
|
|
1206
1235
|
}
|
|
1207
|
-
|
|
1208
|
-
const command = which.exitCode === 0 && which.stdout.trim() ? "brightsy-mcp" : "npx";
|
|
1209
|
-
brightsyMcpCommandCache = { at: now, command };
|
|
1210
|
-
return command;
|
|
1236
|
+
return count;
|
|
1211
1237
|
}
|
|
1212
|
-
|
|
1238
|
+
var MAX_ANTHROPIC_CACHE_CONTROL_BLOCKS = 4;
|
|
1239
|
+
|
|
1240
|
+
// src/agents/acp.ts
|
|
1241
|
+
var ACP_ATTACH_ERROR = "ACP harnesses have no interactive attach. Continue the chat in Sideboard.";
|
|
1242
|
+
function entryDir() {
|
|
1243
|
+
const cjsDir = typeof __dirname !== "undefined" ? __dirname : "";
|
|
1244
|
+
if (cjsDir) return cjsDir;
|
|
1213
1245
|
try {
|
|
1214
|
-
|
|
1215
|
-
return true;
|
|
1246
|
+
return dirname3(fileURLToPath2(import.meta.url));
|
|
1216
1247
|
} catch {
|
|
1217
|
-
|
|
1248
|
+
try {
|
|
1249
|
+
const req = createRequire2(process.cwd() + "/");
|
|
1250
|
+
return dirname3(req.resolve("@sideboard-ai/core"));
|
|
1251
|
+
} catch {
|
|
1252
|
+
return process.cwd();
|
|
1253
|
+
}
|
|
1218
1254
|
}
|
|
1219
1255
|
}
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1256
|
+
function acpRunnerPath() {
|
|
1257
|
+
const packagedRoot = packagedCursorRuntimeDir();
|
|
1258
|
+
if (packagedRoot) {
|
|
1259
|
+
const packaged = join6(packagedRoot, "core-dist", "agents", "acp-runner.js");
|
|
1260
|
+
if (existsSync5(packaged)) return packaged;
|
|
1261
|
+
}
|
|
1262
|
+
const root = entryDir();
|
|
1263
|
+
const candidates = [
|
|
1264
|
+
join6(root, "agents", "acp-runner.js"),
|
|
1265
|
+
join6(root, "agents", "acp-runner.cjs"),
|
|
1266
|
+
join6(root, "dist", "agents", "acp-runner.js"),
|
|
1267
|
+
join6(root, "dist", "agents", "acp-runner.cjs"),
|
|
1268
|
+
join6(root, "acp-runner.ts"),
|
|
1269
|
+
join6(root, "src", "agents", "acp-runner.ts")
|
|
1270
|
+
];
|
|
1271
|
+
for (const candidate of candidates) {
|
|
1272
|
+
if (existsSync5(candidate)) return candidate;
|
|
1273
|
+
}
|
|
1274
|
+
return candidates[0];
|
|
1227
1275
|
}
|
|
1228
|
-
function
|
|
1229
|
-
|
|
1230
|
-
return typeof ds === "string" && ds.toLowerCase() === "brightsy";
|
|
1276
|
+
function harnessFor(thread) {
|
|
1277
|
+
return isAcpHarnessId(thread.acpHarness) ? thread.acpHarness : defaultAcpHarness();
|
|
1231
1278
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1279
|
+
var acpAdapter = {
|
|
1280
|
+
kind: "acp",
|
|
1281
|
+
async detect() {
|
|
1282
|
+
return detectAcpHarness(defaultAcpHarness());
|
|
1283
|
+
},
|
|
1284
|
+
async buildTurn(thread, input) {
|
|
1285
|
+
const harness = harnessFor(thread);
|
|
1286
|
+
const command = await resolveAcpHarnessCommand(harness);
|
|
1287
|
+
const sessionId = await this.resolveSessionId(thread.worktreePath, thread.sessionId);
|
|
1288
|
+
const prompt = flattenTurnInput(input);
|
|
1289
|
+
const resumePrompt = flattenTurnInput(dropCachedPrefixOnResume(input, sessionId));
|
|
1290
|
+
const isOrchestrator = isOrchestratorThread(thread);
|
|
1291
|
+
const injected = await buildInjectedMcpServers({
|
|
1292
|
+
includeSideboard: true,
|
|
1293
|
+
includeBrightsy: shouldInjectBrightsyMcp(thread, { orchestrator: isOrchestrator }),
|
|
1294
|
+
orchestratorThreadId: isOrchestrator ? thread.id : null,
|
|
1295
|
+
threadId: thread.id
|
|
1296
|
+
});
|
|
1297
|
+
const injectedAcp = toAcpMcpServers(injected);
|
|
1298
|
+
const userMcp = isOrchestrator ? [] : acpUserStdioServers(
|
|
1299
|
+
listUserClaudeMcpServerEntries(homedir5(), [thread.repoPath, thread.worktreePath]),
|
|
1300
|
+
new Set(injectedAcp.map((server) => server.name))
|
|
1301
|
+
);
|
|
1302
|
+
const req = {
|
|
1303
|
+
prompt,
|
|
1304
|
+
resumePrompt,
|
|
1305
|
+
transcript: acpPriorTranscript(thread.messages ?? []),
|
|
1306
|
+
cwd: thread.worktreePath,
|
|
1307
|
+
sessionId,
|
|
1308
|
+
harness,
|
|
1309
|
+
command: command.file,
|
|
1310
|
+
args: command.args,
|
|
1311
|
+
mcpServers: [...injectedAcp, ...userMcp],
|
|
1312
|
+
planMode: thread.planMode,
|
|
1313
|
+
autonomy: thread.autonomy
|
|
1314
|
+
};
|
|
1315
|
+
const runner = acpRunnerPath();
|
|
1316
|
+
const isTs = runner.endsWith(".ts");
|
|
1317
|
+
const launch = applyNodeLaunch(
|
|
1318
|
+
await resolveNodeLaunch(runner),
|
|
1319
|
+
isTs ? ["--import", "tsx", runner] : [runner]
|
|
1320
|
+
);
|
|
1321
|
+
return {
|
|
1322
|
+
file: launch.file,
|
|
1323
|
+
args: launch.args,
|
|
1324
|
+
cwd: thread.worktreePath,
|
|
1325
|
+
stdin: JSON.stringify(req),
|
|
1326
|
+
env: launch.env
|
|
1327
|
+
};
|
|
1328
|
+
},
|
|
1329
|
+
parseEvent(line) {
|
|
1330
|
+
return parseAcpRunnerLine(line);
|
|
1331
|
+
},
|
|
1332
|
+
async resolveSessionId(_worktreePath, cached) {
|
|
1333
|
+
return cached?.trim() || null;
|
|
1334
|
+
},
|
|
1335
|
+
async buildAttach(_thread) {
|
|
1336
|
+
throw new Error(ACP_ATTACH_ERROR);
|
|
1240
1337
|
}
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
return (thread
|
|
1338
|
+
};
|
|
1339
|
+
function acpHarnessDisplayName(thread) {
|
|
1340
|
+
if (thread.agent !== "acp") return thread.agent;
|
|
1341
|
+
return acpHarnessLabel(thread.acpHarness);
|
|
1245
1342
|
}
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1343
|
+
|
|
1344
|
+
// src/agents/brightsy.ts
|
|
1345
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1346
|
+
|
|
1347
|
+
// src/agents/brightsy-targets.ts
|
|
1348
|
+
function encodeBrightsyTarget(type, id, accountId) {
|
|
1349
|
+
if (accountId) return `team:${accountId}:${type}:${id}`;
|
|
1350
|
+
return `${type}:${id}`;
|
|
1252
1351
|
}
|
|
1253
|
-
function
|
|
1254
|
-
|
|
1255
|
-
|
|
1352
|
+
function decodeBrightsyTarget(model) {
|
|
1353
|
+
const raw = model?.trim();
|
|
1354
|
+
if (!raw || raw === "default" || raw === "agent:default") {
|
|
1355
|
+
return { type: "agent", id: "default" };
|
|
1256
1356
|
}
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1357
|
+
const teamMatch = raw.match(/^team:([^:]+):(agent|model):(.+)$/);
|
|
1358
|
+
if (teamMatch) {
|
|
1359
|
+
return {
|
|
1360
|
+
type: teamMatch[2],
|
|
1361
|
+
id: teamMatch[3] || "default",
|
|
1362
|
+
accountId: teamMatch[1]
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
if (raw.startsWith("agent:")) {
|
|
1366
|
+
return { type: "agent", id: raw.slice("agent:".length) || "default" };
|
|
1367
|
+
}
|
|
1368
|
+
if (raw.startsWith("model:")) {
|
|
1369
|
+
return { type: "model", id: raw.slice("model:".length) };
|
|
1370
|
+
}
|
|
1371
|
+
if (/^[0-9a-f]{8}-[0-9a-f-]{27,}$/i.test(raw) || raw === "default") {
|
|
1372
|
+
return { type: "agent", id: raw };
|
|
1373
|
+
}
|
|
1374
|
+
return { type: "model", id: raw };
|
|
1273
1375
|
}
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1376
|
+
|
|
1377
|
+
// src/agents/brightsy.ts
|
|
1378
|
+
function usageFromBrightsy(usage) {
|
|
1379
|
+
if (!usage) return null;
|
|
1380
|
+
const mapped = fromInclusiveInputUsage({
|
|
1381
|
+
inputTokens: Number(usage.prompt_tokens ?? 0),
|
|
1382
|
+
outputTokens: Number(usage.completion_tokens ?? 0),
|
|
1383
|
+
cachedInputTokens: Number(usage.prompt_tokens_details?.cached_tokens ?? 0)
|
|
1384
|
+
});
|
|
1385
|
+
if (!mapped) return null;
|
|
1386
|
+
if (usage.cost != null && Number.isFinite(Number(usage.cost))) {
|
|
1387
|
+
mapped.costUsd = Number(usage.cost);
|
|
1278
1388
|
}
|
|
1279
|
-
return
|
|
1389
|
+
return mapped;
|
|
1280
1390
|
}
|
|
1281
|
-
function
|
|
1282
|
-
const
|
|
1283
|
-
if (
|
|
1391
|
+
function parseBrightsyCliLine(line) {
|
|
1392
|
+
const trimmed = line.trim();
|
|
1393
|
+
if (!trimmed) return null;
|
|
1284
1394
|
try {
|
|
1285
|
-
const
|
|
1286
|
-
if (
|
|
1287
|
-
|
|
1395
|
+
const obj = JSON.parse(trimmed);
|
|
1396
|
+
if (obj.type === "text" && typeof obj.text === "string") {
|
|
1397
|
+
if (looksLikeBrightsyEmptyCompletion(obj.text)) {
|
|
1398
|
+
return [
|
|
1399
|
+
{ type: "stderr", data: obj.text },
|
|
1400
|
+
{ type: "stdout", data: `Error: ${obj.text}` }
|
|
1401
|
+
];
|
|
1402
|
+
}
|
|
1403
|
+
return { type: "stdout", data: obj.text };
|
|
1404
|
+
}
|
|
1405
|
+
if (obj.type === "thinking" && typeof obj.text === "string") {
|
|
1406
|
+
return { type: "thinking", data: obj.text };
|
|
1407
|
+
}
|
|
1408
|
+
if (obj.type === "error") {
|
|
1409
|
+
const msg = extractJsonErrorMessage(obj) || formatUnknownDetail(obj.error) || formatUnknownDetail(obj.message) || trimmed;
|
|
1410
|
+
return [
|
|
1411
|
+
{ type: "stderr", data: msg },
|
|
1412
|
+
{ type: "stdout", data: `Error: ${msg}` }
|
|
1413
|
+
];
|
|
1414
|
+
}
|
|
1415
|
+
if (obj.type === "usage") {
|
|
1416
|
+
const usage = usageFromBrightsy(obj.usage);
|
|
1417
|
+
return usage ? { type: "usage", data: usage } : null;
|
|
1418
|
+
}
|
|
1419
|
+
if (obj.type === "tool_use") {
|
|
1420
|
+
const id = typeof obj.id === "string" && obj.id || `brightsy-tool-${Date.now()}`;
|
|
1421
|
+
const name = typeof obj.name === "string" && obj.name || "brightsy_tool";
|
|
1422
|
+
const input = obj.input && typeof obj.input === "object" && !Array.isArray(obj.input) ? obj.input : void 0;
|
|
1423
|
+
return { type: "tool_use", id, name, input };
|
|
1424
|
+
}
|
|
1425
|
+
if (obj.type === "tool_result" || obj.type === "tool") {
|
|
1426
|
+
const id = typeof obj.id === "string" && obj.id || typeof obj.tool_call_id === "string" && obj.tool_call_id || `brightsy-tool-${Date.now()}`;
|
|
1427
|
+
const content = typeof obj.content === "string" ? obj.content : obj.content != null ? JSON.stringify(obj.content) : void 0;
|
|
1428
|
+
return {
|
|
1429
|
+
type: "tool_result",
|
|
1430
|
+
id,
|
|
1431
|
+
content,
|
|
1432
|
+
isError: obj.isError === true
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
if (obj.type === "done") return null;
|
|
1436
|
+
if (typeof obj.type === "string" && ["tool_use", "tool_result", "tool", "thinking", "usage", "error", "done", "text"].includes(
|
|
1437
|
+
obj.type
|
|
1438
|
+
)) {
|
|
1439
|
+
return null;
|
|
1288
1440
|
}
|
|
1441
|
+
return { type: "stdout", data: trimmed };
|
|
1289
1442
|
} catch {
|
|
1443
|
+
if (trimmed.startsWith("{") && /"type"\s*:\s*"(tool_use|tool_result|tool|text|thinking|usage|done|error)"/.test(trimmed)) {
|
|
1444
|
+
return null;
|
|
1445
|
+
}
|
|
1446
|
+
if (looksLikeBrightsyEmptyCompletion(trimmed) || /error|failed|unauthorized|quota|limit|not logged in/i.test(trimmed)) {
|
|
1447
|
+
return [
|
|
1448
|
+
{ type: "stderr", data: trimmed },
|
|
1449
|
+
{ type: "stdout", data: `Error: ${trimmed}` }
|
|
1450
|
+
];
|
|
1451
|
+
}
|
|
1452
|
+
return { type: "stdout", data: line };
|
|
1290
1453
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
return process.cwd();
|
|
1454
|
+
}
|
|
1455
|
+
function adjustBrightsyTurnExit(exitCode, assistantText) {
|
|
1456
|
+
if (looksLikeBrightsyEmptyCompletion(assistantText) && (exitCode === 0 || exitCode == null)) {
|
|
1457
|
+
return 2;
|
|
1296
1458
|
}
|
|
1459
|
+
return exitCode;
|
|
1297
1460
|
}
|
|
1298
|
-
function
|
|
1299
|
-
const
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
join3(dir, "dist/mcp/run-stdio.cjs"),
|
|
1310
|
-
join3(dir, "packages/core/dist/mcp/run-stdio.js"),
|
|
1311
|
-
join3(dir, "packages/cli/dist/index.js"),
|
|
1312
|
-
join3(dir, "cli/dist/index.js")
|
|
1313
|
-
];
|
|
1314
|
-
for (const p of candidates) {
|
|
1315
|
-
if (existsSync3(p) && !isAsarPath(p)) return p;
|
|
1461
|
+
async function fetchTeamChatTargets(team) {
|
|
1462
|
+
const endpoint = (team.endpoint || "https://brightsy.ai").replace(/\/$/, "");
|
|
1463
|
+
let agents = [
|
|
1464
|
+
{
|
|
1465
|
+
type: "agent",
|
|
1466
|
+
id: "default",
|
|
1467
|
+
name: "Default Agent",
|
|
1468
|
+
description: "Account default agent (tools + memory)",
|
|
1469
|
+
accountId: team.id,
|
|
1470
|
+
accountSlug: team.slug,
|
|
1471
|
+
accountName: team.name
|
|
1316
1472
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1473
|
+
];
|
|
1474
|
+
let models = [];
|
|
1475
|
+
try {
|
|
1476
|
+
const res = await fetch(`${endpoint}/api/v1beta/${team.id}/agents`, {
|
|
1477
|
+
headers: { Authorization: `Bearer ${team.access_token}` }
|
|
1478
|
+
});
|
|
1479
|
+
if (res.ok) {
|
|
1480
|
+
const json = await res.json();
|
|
1481
|
+
const listed = (json.data || []).filter(
|
|
1482
|
+
(a) => Boolean(a?.id && a?.name)
|
|
1483
|
+
).filter((a) => a.id !== "default").map((a) => ({
|
|
1484
|
+
type: "agent",
|
|
1485
|
+
id: a.id,
|
|
1486
|
+
name: a.name,
|
|
1487
|
+
description: a.description,
|
|
1488
|
+
accountId: team.id,
|
|
1489
|
+
accountSlug: team.slug,
|
|
1490
|
+
accountName: team.name
|
|
1491
|
+
}));
|
|
1492
|
+
agents = [...agents, ...listed];
|
|
1493
|
+
if (Array.isArray(json.models)) {
|
|
1494
|
+
models = json.models.filter(
|
|
1495
|
+
(m) => Boolean(m?.id && m?.name)
|
|
1496
|
+
).slice(0, 12).map((m) => ({
|
|
1497
|
+
type: "model",
|
|
1498
|
+
id: m.id,
|
|
1499
|
+
name: m.name,
|
|
1500
|
+
description: m.description,
|
|
1501
|
+
accountId: team.id,
|
|
1502
|
+
accountSlug: team.slug,
|
|
1503
|
+
accountName: team.name
|
|
1504
|
+
}));
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
} catch {
|
|
1320
1508
|
}
|
|
1321
|
-
return
|
|
1509
|
+
return {
|
|
1510
|
+
accountId: team.id,
|
|
1511
|
+
accountSlug: team.slug,
|
|
1512
|
+
accountName: team.name,
|
|
1513
|
+
agents,
|
|
1514
|
+
models
|
|
1515
|
+
};
|
|
1322
1516
|
}
|
|
1323
|
-
async function
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
if (launch.file !== "/bin/sh" && !isElectronLikeCommand(launch.file)) {
|
|
1330
|
-
return {
|
|
1331
|
-
name: "sideboard",
|
|
1332
|
-
command: launch.file,
|
|
1333
|
-
args: launch.args,
|
|
1334
|
-
...Object.keys(launch.env).length > 0 ? { env: launch.env } : {}
|
|
1335
|
-
};
|
|
1517
|
+
async function listBrightsyChatTargetsViaCli() {
|
|
1518
|
+
const listed = await run(
|
|
1519
|
+
resolveAgentExecutable("brightsy"),
|
|
1520
|
+
["chat", "--list-targets", "--json"],
|
|
1521
|
+
{
|
|
1522
|
+
reject: false
|
|
1336
1523
|
}
|
|
1524
|
+
);
|
|
1525
|
+
if (listed.exitCode !== 0 || !listed.stdout.trim()) {
|
|
1526
|
+
throw new Error(
|
|
1527
|
+
listed.stderr.trim() || "Failed to list Brightsy chat targets \u2014 is `brightsy` installed and logged in?"
|
|
1528
|
+
);
|
|
1337
1529
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
}
|
|
1344
|
-
async function buildInjectedMcpServers(opts) {
|
|
1345
|
-
const servers = [];
|
|
1346
|
-
if (opts.includeSideboard) {
|
|
1347
|
-
const sideboard = await resolveSideboardMcpServer();
|
|
1348
|
-
sideboard.env = {
|
|
1349
|
-
...sideboard.env ?? {},
|
|
1350
|
-
...injectedSideboardMcpEnv(opts)
|
|
1351
|
-
};
|
|
1530
|
+
try {
|
|
1531
|
+
const parsed = JSON.parse(listed.stdout);
|
|
1532
|
+
let accountId = null;
|
|
1533
|
+
let accountSlug = "team";
|
|
1534
|
+
let accountName = "Brightsy";
|
|
1352
1535
|
try {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1536
|
+
const cfg = loadBrightsyConfig();
|
|
1537
|
+
accountId = cfg.account_id;
|
|
1538
|
+
accountSlug = cfg.account_slug || accountSlug;
|
|
1539
|
+
accountName = cfg.account_slug || accountName;
|
|
1357
1540
|
} catch {
|
|
1358
1541
|
}
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1542
|
+
const agents = (Array.isArray(parsed.agents) ? parsed.agents : []).map((a) => ({
|
|
1543
|
+
...a,
|
|
1544
|
+
accountId: accountId ?? void 0,
|
|
1545
|
+
accountSlug,
|
|
1546
|
+
accountName
|
|
1547
|
+
}));
|
|
1548
|
+
const models = (Array.isArray(parsed.models) ? parsed.models : []).map((m) => ({
|
|
1549
|
+
...m,
|
|
1550
|
+
accountId: accountId ?? void 0,
|
|
1551
|
+
accountSlug,
|
|
1552
|
+
accountName
|
|
1553
|
+
}));
|
|
1554
|
+
const teams = accountId ? [
|
|
1555
|
+
{
|
|
1556
|
+
accountId,
|
|
1557
|
+
accountSlug,
|
|
1558
|
+
accountName,
|
|
1559
|
+
agents,
|
|
1560
|
+
models
|
|
1372
1561
|
}
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1562
|
+
] : [];
|
|
1563
|
+
return { teams, agents, models, activeAccountId: accountId };
|
|
1564
|
+
} catch {
|
|
1565
|
+
throw new Error("Brightsy --list-targets returned invalid JSON");
|
|
1376
1566
|
}
|
|
1377
|
-
return servers;
|
|
1378
1567
|
}
|
|
1379
|
-
function
|
|
1380
|
-
|
|
1381
|
-
|
|
1568
|
+
async function listBrightsyChatTargets() {
|
|
1569
|
+
ensureCliTeamTracked();
|
|
1570
|
+
const teamsRaw = await ensureConnectedBrightsyTeamTokens();
|
|
1571
|
+
if (teamsRaw.length === 0) {
|
|
1572
|
+
return listBrightsyChatTargetsViaCli();
|
|
1382
1573
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
function mcpSpawnEnv(env) {
|
|
1389
|
-
if (!env) return void 0;
|
|
1390
|
-
const out = { ...env };
|
|
1391
|
-
delete out.ELECTRON_RUN_AS_NODE;
|
|
1392
|
-
delete out.ELECTRON_RUN_AS_NODE;
|
|
1393
|
-
return Object.keys(out).length > 0 ? out : void 0;
|
|
1394
|
-
}
|
|
1395
|
-
function toCursorMcpServers(servers) {
|
|
1396
|
-
const out = {};
|
|
1397
|
-
for (const s of servers) {
|
|
1398
|
-
const env = mcpSpawnEnv(s.env);
|
|
1399
|
-
const launch = cursorSafeMcpLaunch(s.command, s.args);
|
|
1400
|
-
out[s.name] = {
|
|
1401
|
-
type: "stdio",
|
|
1402
|
-
command: launch.command,
|
|
1403
|
-
...launch.args && launch.args.length > 0 ? { args: launch.args } : {},
|
|
1404
|
-
...env ? { env } : {}
|
|
1405
|
-
};
|
|
1574
|
+
let activeAccountId = null;
|
|
1575
|
+
try {
|
|
1576
|
+
activeAccountId = loadBrightsyConfig().account_id;
|
|
1577
|
+
} catch {
|
|
1578
|
+
activeAccountId = teamsRaw[0]?.id ?? null;
|
|
1406
1579
|
}
|
|
1407
|
-
|
|
1580
|
+
const teams = await Promise.all(teamsRaw.map((t) => fetchTeamChatTargets(t)));
|
|
1581
|
+
teams.sort((a, b) => {
|
|
1582
|
+
if (a.accountId === activeAccountId) return -1;
|
|
1583
|
+
if (b.accountId === activeAccountId) return 1;
|
|
1584
|
+
return a.accountSlug.localeCompare(b.accountSlug);
|
|
1585
|
+
});
|
|
1586
|
+
const active = teams.find((t) => t.accountId === activeAccountId) ?? teams[0] ?? null;
|
|
1587
|
+
return {
|
|
1588
|
+
teams,
|
|
1589
|
+
agents: active?.agents ?? [],
|
|
1590
|
+
models: active?.models ?? [],
|
|
1591
|
+
activeAccountId
|
|
1592
|
+
};
|
|
1408
1593
|
}
|
|
1409
|
-
function
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
if (env) {
|
|
1419
|
-
for (const [key, value] of Object.entries(env)) {
|
|
1420
|
-
if (isCodexSecretEnvKey(key)) continue;
|
|
1421
|
-
args.push("-c", `${prefix}.env.${key}=${JSON.stringify(value)}`);
|
|
1422
|
-
}
|
|
1594
|
+
async function syncCliForTarget(accountId) {
|
|
1595
|
+
if (!accountId) return;
|
|
1596
|
+
const teams = await ensureConnectedBrightsyTeamTokens();
|
|
1597
|
+
const team = teams.find((t) => t.id === accountId);
|
|
1598
|
+
if (!team) return;
|
|
1599
|
+
try {
|
|
1600
|
+
const cfg = loadBrightsyConfig();
|
|
1601
|
+
if (cfg.account_id === team.id && cfg.access_token === team.access_token) {
|
|
1602
|
+
return;
|
|
1423
1603
|
}
|
|
1424
|
-
|
|
1425
|
-
args.push("-c", `${prefix}.tool_timeout_sec=300`);
|
|
1426
|
-
args.push("-c", `${prefix}.startup_timeout_sec=30`);
|
|
1604
|
+
} catch {
|
|
1427
1605
|
}
|
|
1428
|
-
|
|
1606
|
+
applyConnectedTeamToCli(team);
|
|
1429
1607
|
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
const
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1608
|
+
var brightsyAdapter = {
|
|
1609
|
+
kind: "brightsy",
|
|
1610
|
+
async detect() {
|
|
1611
|
+
const brightsy = resolveAgentExecutable("brightsy");
|
|
1612
|
+
if (brightsy !== "brightsy") {
|
|
1613
|
+
if (!existsSync6(brightsy)) {
|
|
1614
|
+
return {
|
|
1615
|
+
agent: "brightsy",
|
|
1616
|
+
installed: false,
|
|
1617
|
+
authenticated: false,
|
|
1618
|
+
linearMcp: false,
|
|
1619
|
+
warnings: [],
|
|
1620
|
+
reason: `Brightsy executable not found: ${brightsy}`
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
} else {
|
|
1624
|
+
const which = await run("which", ["brightsy"], { reject: false });
|
|
1625
|
+
if (which.exitCode !== 0) {
|
|
1626
|
+
return {
|
|
1627
|
+
agent: "brightsy",
|
|
1628
|
+
installed: false,
|
|
1629
|
+
authenticated: false,
|
|
1630
|
+
linearMcp: false,
|
|
1631
|
+
warnings: [],
|
|
1632
|
+
reason: "brightsy CLI not found on PATH \u2014 npm i -g @brightsy/cli"
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
const who = await run(brightsy, ["whoami"], { reject: false });
|
|
1637
|
+
const authenticated = who.exitCode === 0 && /logged in as/i.test(who.stdout);
|
|
1638
|
+
return {
|
|
1639
|
+
agent: "brightsy",
|
|
1640
|
+
installed: true,
|
|
1641
|
+
authenticated,
|
|
1642
|
+
linearMcp: false,
|
|
1643
|
+
warnings: [],
|
|
1644
|
+
reason: authenticated ? void 0 : "not logged in \u2014 run `brightsy login`"
|
|
1439
1645
|
};
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1646
|
+
},
|
|
1647
|
+
async buildTurn(thread, input) {
|
|
1648
|
+
const prompt = flattenTurnInput(input);
|
|
1649
|
+
const target = decodeBrightsyTarget(thread.model);
|
|
1650
|
+
await syncCliForTarget(target.accountId);
|
|
1651
|
+
const mode = thread.planMode ? "plan" : target.type === "model" ? "ask" : "agent";
|
|
1652
|
+
const args = [
|
|
1653
|
+
"chat",
|
|
1654
|
+
"--json",
|
|
1655
|
+
"--mode",
|
|
1656
|
+
mode,
|
|
1657
|
+
target.type === "model" ? "--model" : "--agent",
|
|
1658
|
+
target.id
|
|
1659
|
+
];
|
|
1660
|
+
return {
|
|
1661
|
+
file: resolveAgentExecutable("brightsy"),
|
|
1662
|
+
args,
|
|
1663
|
+
cwd: thread.worktreePath,
|
|
1664
|
+
// Piped stdin becomes the message body (avoids ARG_MAX for long seeds).
|
|
1665
|
+
stdin: prompt
|
|
1666
|
+
};
|
|
1667
|
+
},
|
|
1668
|
+
parseEvent(line) {
|
|
1669
|
+
return parseBrightsyCliLine(line);
|
|
1670
|
+
},
|
|
1671
|
+
async resolveSessionId() {
|
|
1672
|
+
return null;
|
|
1673
|
+
},
|
|
1674
|
+
async buildAttach(thread) {
|
|
1675
|
+
const target = decodeBrightsyTarget(thread.model);
|
|
1676
|
+
await syncCliForTarget(target.accountId);
|
|
1677
|
+
const args = target.type === "model" ? ["chat", "--model", target.id] : ["chat", "--agent", target.id];
|
|
1678
|
+
return {
|
|
1679
|
+
file: resolveAgentExecutable("brightsy"),
|
|
1680
|
+
args,
|
|
1681
|
+
cwd: thread.worktreePath
|
|
1465
1682
|
};
|
|
1466
1683
|
}
|
|
1467
|
-
|
|
1468
|
-
for (const [rawName, entry] of Object.entries(extraServers)) {
|
|
1469
|
-
const name = rawName.trim();
|
|
1470
|
-
if (!name || mcpServers[name] || !entry) continue;
|
|
1471
|
-
mcpServers[name] = stripElectronFromUserMcpEntry(entry);
|
|
1472
|
-
}
|
|
1473
|
-
}
|
|
1474
|
-
return mcpServers;
|
|
1475
|
-
}
|
|
1476
|
-
function writeMcpServersConfig(servers, extraServers) {
|
|
1477
|
-
const mcpServers = mcpServersRecord(servers, extraServers);
|
|
1478
|
-
if (Object.keys(mcpServers).length === 0) return null;
|
|
1479
|
-
const dir = mkdtempSync(join3(tmpdir(), "sideboard-mcp-"));
|
|
1480
|
-
const cfgPath = join3(dir, "mcp.json");
|
|
1481
|
-
writeFileSync2(cfgPath, JSON.stringify({ mcpServers }, null, 2), { mode: 384 });
|
|
1482
|
-
return cfgPath;
|
|
1483
|
-
}
|
|
1484
|
-
async function writeInjectedMcpConfig(opts) {
|
|
1485
|
-
return writeMcpServersConfig(await buildInjectedMcpServers(opts));
|
|
1486
|
-
}
|
|
1684
|
+
};
|
|
1487
1685
|
|
|
1488
|
-
// src/agents/
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
existing = {};
|
|
1686
|
+
// src/agents/claude.ts
|
|
1687
|
+
import { existsSync as existsSync9 } from "fs";
|
|
1688
|
+
import { dirname as dirname5 } from "path";
|
|
1689
|
+
|
|
1690
|
+
// src/agents/claude-mcp-status.ts
|
|
1691
|
+
var SIDEBOARD_CONNECTOR_SERVICES = [
|
|
1692
|
+
"github",
|
|
1693
|
+
"linear",
|
|
1694
|
+
"posthog",
|
|
1695
|
+
"vercel",
|
|
1696
|
+
"supabase",
|
|
1697
|
+
"sentry"
|
|
1698
|
+
];
|
|
1699
|
+
function mcpStatusThinkingFromClaudeInit(obj) {
|
|
1700
|
+
const raw = obj.mcp_servers ?? obj.mcpServers;
|
|
1701
|
+
const servers = [];
|
|
1702
|
+
if (Array.isArray(raw)) {
|
|
1703
|
+
for (const item of raw) {
|
|
1704
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
1705
|
+
const rec = item;
|
|
1706
|
+
const name = typeof rec.name === "string" && rec.name.trim() || typeof rec.server === "string" && rec.server.trim() || "";
|
|
1707
|
+
const status = typeof rec.status === "string" && rec.status.trim() || typeof rec.state === "string" && rec.state.trim() || "";
|
|
1708
|
+
if (name) servers.push({ name, status: status || "unknown" });
|
|
1709
|
+
}
|
|
1710
|
+
} else if (raw && typeof raw === "object") {
|
|
1711
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
1712
|
+
if (!name.trim()) continue;
|
|
1713
|
+
if (typeof value === "string" && value.trim()) {
|
|
1714
|
+
servers.push({ name, status: value.trim() });
|
|
1715
|
+
continue;
|
|
1716
|
+
}
|
|
1717
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
1718
|
+
const rec = value;
|
|
1719
|
+
const status = typeof rec.status === "string" && rec.status.trim() || typeof rec.state === "string" && rec.state.trim() || "unknown";
|
|
1720
|
+
servers.push({ name, status });
|
|
1721
|
+
}
|
|
1525
1722
|
}
|
|
1526
1723
|
}
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1724
|
+
const coverage = claudeConnectorCoverage();
|
|
1725
|
+
const sideboardOk = sideboardMcpOk(servers);
|
|
1726
|
+
const notable = servers.filter(
|
|
1727
|
+
(server) => isNotableMcpInitStatus(server, sideboardOk, coverage)
|
|
1728
|
+
);
|
|
1729
|
+
if (notable.length === 0) return null;
|
|
1730
|
+
return `MCP: ${notable.map((s) => `${s.name} ${s.status}`).join(", ")}`;
|
|
1531
1731
|
}
|
|
1532
|
-
function
|
|
1533
|
-
return
|
|
1534
|
-
command: server.command,
|
|
1535
|
-
args: server.args,
|
|
1536
|
-
env: {
|
|
1537
|
-
...server.env ?? {},
|
|
1538
|
-
SIDEBOARD_APP_DATA: appDataDir()
|
|
1539
|
-
}
|
|
1540
|
-
};
|
|
1732
|
+
function isCleanMcpConnect(status) {
|
|
1733
|
+
return /^(connected|ok|ready|success)$/i.test(status.trim());
|
|
1541
1734
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
const claude = userClaudeMcpConfigPath();
|
|
1547
|
-
if (existsSync4(claude)) {
|
|
1548
|
-
writeMergedMcpServersJson(claude, launch);
|
|
1549
|
-
return { cursor, claude };
|
|
1550
|
-
}
|
|
1551
|
-
return { cursor };
|
|
1735
|
+
function isMcpAuthStatus(status) {
|
|
1736
|
+
return /needs[_-]?auth|needs authentication|unauthorized|not authenticated|authrequired/i.test(
|
|
1737
|
+
status
|
|
1738
|
+
);
|
|
1552
1739
|
}
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
function isInjectedOrchMcpName(name) {
|
|
1556
|
-
const n = name.trim().toLowerCase();
|
|
1557
|
-
return n === "sideboard" || n === "brightsy" || n.startsWith("brightsy_");
|
|
1740
|
+
function isSideboardMcpName(name) {
|
|
1741
|
+
return /^sideboard$/i.test(name.trim()) || /^mcp__sideboard$/i.test(name.trim());
|
|
1558
1742
|
}
|
|
1559
|
-
function
|
|
1560
|
-
|
|
1561
|
-
return value;
|
|
1743
|
+
function isVendorClaudeAiMcpName(name) {
|
|
1744
|
+
return /^claude\.ai\b/i.test(name.trim()) || /^mcp__claude_ai_/i.test(name.trim());
|
|
1562
1745
|
}
|
|
1563
|
-
function
|
|
1564
|
-
|
|
1746
|
+
function sideboardMcpOk(servers) {
|
|
1747
|
+
const row = servers.find((server) => isSideboardMcpName(server.name));
|
|
1748
|
+
return Boolean(row && isCleanMcpConnect(row.status));
|
|
1565
1749
|
}
|
|
1566
|
-
function
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1750
|
+
function sideboardServiceForClaudeConnector(name) {
|
|
1751
|
+
const raw = name.trim();
|
|
1752
|
+
if (!raw || isSideboardMcpName(raw)) return null;
|
|
1753
|
+
const pluginLike = /^(?:plugin[:_]|mcp__plugin_|claude\.ai\s|(?:mcp__)?claude_ai_)/i.test(raw);
|
|
1754
|
+
const doubled = raw.match(/^mcp_([a-z0-9]+)_([a-z0-9]+)$/i);
|
|
1755
|
+
if (!pluginLike && !(doubled && doubled[1].toLowerCase() === doubled[2].toLowerCase())) {
|
|
1756
|
+
return null;
|
|
1572
1757
|
}
|
|
1758
|
+
let body = raw;
|
|
1759
|
+
if (/^claude\.ai\s+/i.test(body)) body = body.replace(/^claude\.ai\s+/i, "");
|
|
1760
|
+
else if (/^(?:mcp__)?claude_ai_/i.test(body)) body = body.replace(/^(?:mcp__)?claude_ai_/i, "");
|
|
1761
|
+
else if (/^mcp__plugin_/i.test(body)) body = body.slice("mcp__plugin_".length);
|
|
1762
|
+
else if (/^plugin_/i.test(body)) body = body.slice("plugin_".length);
|
|
1763
|
+
else if (/^plugin:/i.test(body)) body = body.slice("plugin:".length);
|
|
1764
|
+
else if (/^mcp_/i.test(body)) body = body.slice("mcp_".length);
|
|
1765
|
+
const head = body.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)[0];
|
|
1766
|
+
if (!head || !SIDEBOARD_CONNECTOR_SERVICES.includes(head)) return null;
|
|
1767
|
+
return head;
|
|
1573
1768
|
}
|
|
1574
|
-
function
|
|
1769
|
+
function claudeConnectorCoverage() {
|
|
1770
|
+
let github = false;
|
|
1575
1771
|
try {
|
|
1576
|
-
|
|
1772
|
+
github = githubAgentAuthReady();
|
|
1577
1773
|
} catch {
|
|
1578
|
-
|
|
1774
|
+
github = false;
|
|
1579
1775
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1776
|
+
let linear = false;
|
|
1777
|
+
let posthog = false;
|
|
1778
|
+
let vercel = false;
|
|
1779
|
+
let supabase = false;
|
|
1780
|
+
let sentry = false;
|
|
1582
1781
|
try {
|
|
1583
|
-
|
|
1782
|
+
linear = isLinearConnected();
|
|
1783
|
+
posthog = isPosthogConnected();
|
|
1784
|
+
const integrations = loadAppSettings().integrations ?? {};
|
|
1785
|
+
if (integrations.githubPat?.trim()) github = true;
|
|
1786
|
+
vercel = Boolean(integrations.vercelToken?.trim());
|
|
1787
|
+
supabase = Boolean(integrations.supabaseAccessToken?.trim());
|
|
1788
|
+
sentry = Boolean(integrations.sentryAuthToken?.trim());
|
|
1584
1789
|
} catch {
|
|
1585
|
-
return "";
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
|
-
function userCodexConfigPaths(home = homedir4()) {
|
|
1589
|
-
const paths = [
|
|
1590
|
-
join5(home, ".codex", "config.toml"),
|
|
1591
|
-
join5(home, ".config", "codex", "config.toml")
|
|
1592
|
-
];
|
|
1593
|
-
const codexHome = process.env.CODEX_HOME?.trim();
|
|
1594
|
-
if (codexHome) paths.unshift(join5(codexHome, "config.toml"));
|
|
1595
|
-
return paths;
|
|
1596
|
-
}
|
|
1597
|
-
function userOpencodeConfigPaths(home = homedir4()) {
|
|
1598
|
-
return [
|
|
1599
|
-
join5(home, ".config", "opencode", "opencode.json"),
|
|
1600
|
-
join5(home, ".config", "opencode", "opencode.jsonc")
|
|
1601
|
-
];
|
|
1602
|
-
}
|
|
1603
|
-
function userMcpNamesToDisable(opts) {
|
|
1604
|
-
const keep = new Set(
|
|
1605
|
-
[...opts.injectedNames ?? []].map((n) => n.trim().toLowerCase()).filter(Boolean)
|
|
1606
|
-
);
|
|
1607
|
-
const out = [];
|
|
1608
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1609
|
-
for (const raw of opts.names) {
|
|
1610
|
-
const name = raw.trim();
|
|
1611
|
-
if (!name) continue;
|
|
1612
|
-
const key = name.toLowerCase();
|
|
1613
|
-
if (seen.has(key) || keep.has(key) || isInjectedOrchMcpName(name)) continue;
|
|
1614
|
-
seen.add(key);
|
|
1615
|
-
out.push(name);
|
|
1616
|
-
}
|
|
1617
|
-
return out;
|
|
1618
|
-
}
|
|
1619
|
-
function listUserCodexMcpNames(home = homedir4()) {
|
|
1620
|
-
const names = [];
|
|
1621
|
-
for (const path of userCodexConfigPaths(home)) {
|
|
1622
|
-
if (!existsSync5(path)) continue;
|
|
1623
|
-
names.push(...listMcpNamesFromCodexToml(readText(path)));
|
|
1624
|
-
}
|
|
1625
|
-
return names;
|
|
1626
|
-
}
|
|
1627
|
-
function listUserOpencodeMcpNames(home = homedir4()) {
|
|
1628
|
-
const names = [];
|
|
1629
|
-
for (const path of userOpencodeConfigPaths(home)) {
|
|
1630
|
-
if (!existsSync5(path)) continue;
|
|
1631
|
-
names.push(...listMcpNamesFromJsonMap(readJsonObject(path), "mcp"));
|
|
1632
|
-
}
|
|
1633
|
-
return names;
|
|
1634
|
-
}
|
|
1635
|
-
function userClaudeMcpConfigObject(home = homedir4()) {
|
|
1636
|
-
const claudePath = home === homedir4() ? userClaudeMcpConfigPath() : join5(home, ".claude.json");
|
|
1637
|
-
if (!existsSync5(claudePath)) return {};
|
|
1638
|
-
return asObject2(asObject2(readJsonObject(claudePath)).mcpServers);
|
|
1639
|
-
}
|
|
1640
|
-
function listUserClaudeMcpServerEntries(home = homedir4(), projectDirs) {
|
|
1641
|
-
const out = {};
|
|
1642
|
-
for (const [name, entry] of Object.entries(
|
|
1643
|
-
listEnabledClaudePluginMcpServers({ home, projectDirs })
|
|
1644
|
-
)) {
|
|
1645
|
-
if (!name || isInjectedOrchMcpName(name)) continue;
|
|
1646
|
-
out[name] = entry;
|
|
1647
|
-
}
|
|
1648
|
-
for (const [rawName, value] of Object.entries(userClaudeMcpConfigObject(home))) {
|
|
1649
|
-
const name = rawName.trim();
|
|
1650
|
-
if (!name || isInjectedOrchMcpName(name)) continue;
|
|
1651
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
1652
|
-
out[name] = value;
|
|
1653
|
-
}
|
|
1654
|
-
return out;
|
|
1655
|
-
}
|
|
1656
|
-
function toCodexDisableUserMcpArgs(names) {
|
|
1657
|
-
const args = [];
|
|
1658
|
-
for (const name of names) {
|
|
1659
|
-
if (!/^[A-Za-z0-9_-]+$/.test(name)) continue;
|
|
1660
|
-
args.push("-c", `mcp_servers.${name}.enabled=false`);
|
|
1661
1790
|
}
|
|
1662
|
-
return
|
|
1791
|
+
return { github, linear, posthog, vercel, supabase, sentry };
|
|
1663
1792
|
}
|
|
1664
|
-
function
|
|
1665
|
-
return
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
"-c",
|
|
1673
|
-
"features.plugins=false"
|
|
1674
|
-
];
|
|
1793
|
+
function isNotableMcpInitStatus(server, sideboardOk, coverage) {
|
|
1794
|
+
if (isCleanMcpConnect(server.status)) return false;
|
|
1795
|
+
if (isSideboardMcpName(server.name)) return true;
|
|
1796
|
+
if (isMcpAuthStatus(server.status)) return false;
|
|
1797
|
+
const service = sideboardServiceForClaudeConnector(server.name);
|
|
1798
|
+
if (service) return !(sideboardOk && coverage[service]);
|
|
1799
|
+
if (isVendorClaudeAiMcpName(server.name)) return false;
|
|
1800
|
+
return true;
|
|
1675
1801
|
}
|
|
1676
1802
|
|
|
1803
|
+
// src/mcp-ui/host.ts
|
|
1804
|
+
import { createHash } from "crypto";
|
|
1805
|
+
import { homedir as homedir6 } from "os";
|
|
1806
|
+
|
|
1677
1807
|
// src/mcp-ui/proxy-http.ts
|
|
1678
1808
|
import { randomBytes as randomBytes2, randomUUID } from "crypto";
|
|
1679
1809
|
import { createServer } from "http";
|
|
@@ -2145,7 +2275,7 @@ var singleton;
|
|
|
2145
2275
|
function getMcpUiHost() {
|
|
2146
2276
|
if (!singleton) {
|
|
2147
2277
|
singleton = new McpUiHost({
|
|
2148
|
-
entries: (projectDirs) => listUserClaudeMcpServerEntries(
|
|
2278
|
+
entries: (projectDirs) => listUserClaudeMcpServerEntries(homedir6(), projectDirs)
|
|
2149
2279
|
});
|
|
2150
2280
|
}
|
|
2151
2281
|
return singleton;
|
|
@@ -2153,7 +2283,7 @@ function getMcpUiHost() {
|
|
|
2153
2283
|
async function proxyClaudeUserMcp(orchestrator, projectDirs) {
|
|
2154
2284
|
if (orchestrator) return {};
|
|
2155
2285
|
const dirs = projectDirs.filter((d) => typeof d === "string" && d.length > 0);
|
|
2156
|
-
return getMcpUiHost().proxyEntries(listUserClaudeMcpServerEntries(
|
|
2286
|
+
return getMcpUiHost().proxyEntries(listUserClaudeMcpServerEntries(homedir6(), dirs), dirs);
|
|
2157
2287
|
}
|
|
2158
2288
|
function closeMcpUiHost() {
|
|
2159
2289
|
const host = singleton;
|
|
@@ -2166,9 +2296,9 @@ function dirsKeyFor(projectDirs) {
|
|
|
2166
2296
|
}
|
|
2167
2297
|
|
|
2168
2298
|
// src/agents/claude-usage-client.ts
|
|
2169
|
-
import { existsSync as
|
|
2170
|
-
import { homedir as
|
|
2171
|
-
import { join as
|
|
2299
|
+
import { existsSync as existsSync7, readFileSync as readFileSync4 } from "fs";
|
|
2300
|
+
import { homedir as homedir7 } from "os";
|
|
2301
|
+
import { join as join7 } from "path";
|
|
2172
2302
|
|
|
2173
2303
|
// src/agents/claude-usage.ts
|
|
2174
2304
|
var WINDOW_META = {
|
|
@@ -2426,12 +2556,12 @@ function accessTokenFromCredentialsJson(raw) {
|
|
|
2426
2556
|
}
|
|
2427
2557
|
}
|
|
2428
2558
|
function claudeCredentialsPath(configDir) {
|
|
2429
|
-
const root = configDir?.trim() || process.env.CLAUDE_CONFIG_DIR?.trim() ||
|
|
2430
|
-
return
|
|
2559
|
+
const root = configDir?.trim() || process.env.CLAUDE_CONFIG_DIR?.trim() || join7(homedir7(), ".claude");
|
|
2560
|
+
return join7(root, ".credentials.json");
|
|
2431
2561
|
}
|
|
2432
2562
|
async function readFileAccessToken(configDir) {
|
|
2433
2563
|
const path = claudeCredentialsPath(configDir);
|
|
2434
|
-
if (!
|
|
2564
|
+
if (!existsSync7(path)) return null;
|
|
2435
2565
|
try {
|
|
2436
2566
|
return accessTokenFromCredentialsJson(readFileSync4(path, "utf8"));
|
|
2437
2567
|
} catch {
|
|
@@ -2683,10 +2813,10 @@ function agentRpcChildEnv(rpc, cwd) {
|
|
|
2683
2813
|
}
|
|
2684
2814
|
|
|
2685
2815
|
// src/agents/claude-host.ts
|
|
2686
|
-
import { existsSync as
|
|
2687
|
-
import { createRequire as
|
|
2688
|
-
import { dirname as
|
|
2689
|
-
import { fileURLToPath as
|
|
2816
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2817
|
+
import { createRequire as createRequire3 } from "module";
|
|
2818
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
2819
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2690
2820
|
function claudePilotSdkAllowedTools() {
|
|
2691
2821
|
return PILOT_TOOL_NAMES.map(
|
|
2692
2822
|
(name) => `mcp__${AGENT_RPC_CLAUDE_SDK_SERVER}__${name}`
|
|
@@ -2696,15 +2826,15 @@ function withClaudePilotRpcTools(allowed) {
|
|
|
2696
2826
|
const omit = new Set(PILOT_TOOL_NAMES.map((name) => `mcp__sideboard__${name}`));
|
|
2697
2827
|
return [...allowed.filter((name) => !omit.has(name)), ...claudePilotSdkAllowedTools()];
|
|
2698
2828
|
}
|
|
2699
|
-
function
|
|
2829
|
+
function entryDir2() {
|
|
2700
2830
|
const cjsDir = typeof __dirname !== "undefined" ? __dirname : "";
|
|
2701
2831
|
if (cjsDir) return cjsDir;
|
|
2702
2832
|
try {
|
|
2703
|
-
return
|
|
2833
|
+
return dirname4(fileURLToPath3(import.meta.url));
|
|
2704
2834
|
} catch {
|
|
2705
2835
|
try {
|
|
2706
|
-
const req =
|
|
2707
|
-
return
|
|
2836
|
+
const req = createRequire3(process.cwd() + "/");
|
|
2837
|
+
return dirname4(req.resolve("@sideboard-ai/core"));
|
|
2708
2838
|
} catch {
|
|
2709
2839
|
return process.cwd();
|
|
2710
2840
|
}
|
|
@@ -2713,20 +2843,20 @@ function entryDir() {
|
|
|
2713
2843
|
function claudeRunnerPath() {
|
|
2714
2844
|
const packagedDir = packagedCursorRuntimeDir();
|
|
2715
2845
|
if (packagedDir) {
|
|
2716
|
-
const packaged =
|
|
2717
|
-
if (
|
|
2846
|
+
const packaged = join8(packagedDir, "core-dist", "agents", "claude-runner.js");
|
|
2847
|
+
if (existsSync8(packaged)) return packaged;
|
|
2718
2848
|
}
|
|
2719
|
-
const root =
|
|
2849
|
+
const root = entryDir2();
|
|
2720
2850
|
const candidates = [
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2851
|
+
join8(root, "agents", "claude-runner.js"),
|
|
2852
|
+
join8(root, "agents", "claude-runner.cjs"),
|
|
2853
|
+
join8(root, "dist", "agents", "claude-runner.js"),
|
|
2854
|
+
join8(root, "dist", "agents", "claude-runner.cjs"),
|
|
2855
|
+
join8(root, "claude-runner.ts"),
|
|
2856
|
+
join8(root, "src", "agents", "claude-runner.ts")
|
|
2727
2857
|
];
|
|
2728
2858
|
for (const candidate of candidates) {
|
|
2729
|
-
if (
|
|
2859
|
+
if (existsSync8(candidate)) return candidate;
|
|
2730
2860
|
}
|
|
2731
2861
|
return candidates[0];
|
|
2732
2862
|
}
|
|
@@ -3082,7 +3212,7 @@ var claudeAdapter = {
|
|
|
3082
3212
|
async detect() {
|
|
3083
3213
|
const claude = resolveClaudeExecutable();
|
|
3084
3214
|
if (claude !== "claude") {
|
|
3085
|
-
if (!
|
|
3215
|
+
if (!existsSync9(claude)) {
|
|
3086
3216
|
return {
|
|
3087
3217
|
agent: "claude",
|
|
3088
3218
|
installed: false,
|
|
@@ -3131,7 +3261,7 @@ var claudeAdapter = {
|
|
|
3131
3261
|
);
|
|
3132
3262
|
}
|
|
3133
3263
|
const mode = permissionMode(thread);
|
|
3134
|
-
const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-
|
|
3264
|
+
const { isOrchestratorThread: isOrchestratorThread2 } = await import("./global-workspace-4RDPAOTT.js");
|
|
3135
3265
|
const isOrchestrator = isOrchestratorThread2(thread);
|
|
3136
3266
|
const rpc = worktreeAgentRpc(isOrchestrator);
|
|
3137
3267
|
const injectedServers = await buildInjectedMcpServers({
|
|
@@ -3240,7 +3370,7 @@ ${hint}` : hint;
|
|
|
3240
3370
|
cwd: thread.worktreePath,
|
|
3241
3371
|
stdin: useStdin ? `${promptText}
|
|
3242
3372
|
` : void 0,
|
|
3243
|
-
...mcpConfigPath ? { cleanupDirs: [
|
|
3373
|
+
...mcpConfigPath ? { cleanupDirs: [dirname5(mcpConfigPath)] } : {},
|
|
3244
3374
|
// Nested Task/Agent thinking+text in stream-json (Claude Code 2.1.211+).
|
|
3245
3375
|
// Raise the -p background-agent wait so long TaskOutput polls are not
|
|
3246
3376
|
// abandoned at Claude Code’s 10-minute default.
|
|
@@ -3368,15 +3498,15 @@ ${hint}` : hint;
|
|
|
3368
3498
|
return { file: claude, args, cwd: thread.worktreePath };
|
|
3369
3499
|
},
|
|
3370
3500
|
async listLinearIssues(_repoPath) {
|
|
3371
|
-
const { listAssignedLinearIssues: listAssignedLinearIssues2 } = await import("./linear-list-
|
|
3501
|
+
const { listAssignedLinearIssues: listAssignedLinearIssues2 } = await import("./linear-list-VU47BNUV.js");
|
|
3372
3502
|
return listAssignedLinearIssues2();
|
|
3373
3503
|
}
|
|
3374
3504
|
};
|
|
3375
3505
|
|
|
3376
3506
|
// src/agents/codex.ts
|
|
3377
|
-
import { existsSync as
|
|
3378
|
-
import { homedir as
|
|
3379
|
-
import { join as
|
|
3507
|
+
import { existsSync as existsSync10, statSync } from "fs";
|
|
3508
|
+
import { homedir as homedir8 } from "os";
|
|
3509
|
+
import { join as join9 } from "path";
|
|
3380
3510
|
|
|
3381
3511
|
// src/agents/codex-items.ts
|
|
3382
3512
|
function eventsFromCodexItem(eventType, item) {
|
|
@@ -3428,7 +3558,7 @@ async function listCodexModels() {
|
|
|
3428
3558
|
if (codex === "codex") {
|
|
3429
3559
|
const which = await run("which", ["codex"], { reject: false });
|
|
3430
3560
|
if (which.exitCode !== 0) return FALLBACK_CODEX_MODELS;
|
|
3431
|
-
} else if (!
|
|
3561
|
+
} else if (!existsSync10(codex)) {
|
|
3432
3562
|
return FALLBACK_CODEX_MODELS;
|
|
3433
3563
|
}
|
|
3434
3564
|
const listed = await run(codex, ["debug", "models"], { reject: false });
|
|
@@ -3465,7 +3595,7 @@ function usageFromCodex(usage, asContext = false) {
|
|
|
3465
3595
|
return occ > 0 ? { ...mapped, lastRequestTokens: occ } : mapped;
|
|
3466
3596
|
}
|
|
3467
3597
|
function codexHomeDir() {
|
|
3468
|
-
return process.env.CODEX_HOME?.trim() ||
|
|
3598
|
+
return process.env.CODEX_HOME?.trim() || join9(homedir8(), ".codex");
|
|
3469
3599
|
}
|
|
3470
3600
|
function unwrapCodexMcpResult(result) {
|
|
3471
3601
|
if (result == null) return void 0;
|
|
@@ -3494,8 +3624,8 @@ function asRecord4(value) {
|
|
|
3494
3624
|
return void 0;
|
|
3495
3625
|
}
|
|
3496
3626
|
function codexLooksAuthenticated() {
|
|
3497
|
-
const authPath =
|
|
3498
|
-
if (!
|
|
3627
|
+
const authPath = join9(codexHomeDir(), "auth.json");
|
|
3628
|
+
if (!existsSync10(authPath)) return false;
|
|
3499
3629
|
try {
|
|
3500
3630
|
return statSync(authPath).size > 2;
|
|
3501
3631
|
} catch {
|
|
@@ -3507,7 +3637,7 @@ var codexAdapter = {
|
|
|
3507
3637
|
async detect() {
|
|
3508
3638
|
const codex = resolveAgentExecutable("codex");
|
|
3509
3639
|
if (codex !== "codex") {
|
|
3510
|
-
if (!
|
|
3640
|
+
if (!existsSync10(codex)) {
|
|
3511
3641
|
return {
|
|
3512
3642
|
agent: "codex",
|
|
3513
3643
|
installed: false,
|
|
@@ -3539,7 +3669,7 @@ var codexAdapter = {
|
|
|
3539
3669
|
authenticated,
|
|
3540
3670
|
linearMcp,
|
|
3541
3671
|
warnings,
|
|
3542
|
-
reason: authenticated ? void 0 : `Codex auth not found \u2014 run \`codex login\` (expected ${
|
|
3672
|
+
reason: authenticated ? void 0 : `Codex auth not found \u2014 run \`codex login\` (expected ${join9(codexHomeDir(), "auth.json")})`
|
|
3543
3673
|
};
|
|
3544
3674
|
},
|
|
3545
3675
|
async buildTurn(thread, input) {
|
|
@@ -3767,10 +3897,10 @@ var codexAdapter = {
|
|
|
3767
3897
|
};
|
|
3768
3898
|
|
|
3769
3899
|
// src/agents/cursor.ts
|
|
3770
|
-
import { existsSync as
|
|
3771
|
-
import { createRequire as
|
|
3772
|
-
import { dirname as
|
|
3773
|
-
import { fileURLToPath as
|
|
3900
|
+
import { existsSync as existsSync11 } from "fs";
|
|
3901
|
+
import { createRequire as createRequire4 } from "module";
|
|
3902
|
+
import { dirname as dirname6, join as join10 } from "path";
|
|
3903
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
3774
3904
|
var FALLBACK_CURSOR_MODELS = [
|
|
3775
3905
|
{ id: "default", displayName: "Auto" },
|
|
3776
3906
|
{ id: "composer-2.5", displayName: "Composer 2.5" },
|
|
@@ -3817,15 +3947,15 @@ async function listCursorModels() {
|
|
|
3817
3947
|
return cachedModels?.models ?? FALLBACK_CURSOR_MODELS;
|
|
3818
3948
|
}
|
|
3819
3949
|
}
|
|
3820
|
-
function
|
|
3950
|
+
function entryDir3() {
|
|
3821
3951
|
const cjsDir = typeof __dirname !== "undefined" ? __dirname : "";
|
|
3822
3952
|
if (cjsDir) return cjsDir;
|
|
3823
3953
|
try {
|
|
3824
|
-
return
|
|
3954
|
+
return dirname6(fileURLToPath4(import.meta.url));
|
|
3825
3955
|
} catch {
|
|
3826
3956
|
try {
|
|
3827
|
-
const req =
|
|
3828
|
-
return
|
|
3957
|
+
const req = createRequire4(process.cwd() + "/");
|
|
3958
|
+
return dirname6(req.resolve("@sideboard-ai/core"));
|
|
3829
3959
|
} catch {
|
|
3830
3960
|
return process.cwd();
|
|
3831
3961
|
}
|
|
@@ -3834,19 +3964,19 @@ function entryDir2() {
|
|
|
3834
3964
|
function cursorRunnerPath() {
|
|
3835
3965
|
const packaged = packagedCursorRunnerPath();
|
|
3836
3966
|
if (packaged) return packaged;
|
|
3837
|
-
const root =
|
|
3967
|
+
const root = entryDir3();
|
|
3838
3968
|
const candidates = [
|
|
3839
|
-
|
|
3840
|
-
|
|
3969
|
+
join10(root, "agents", "cursor-runner.js"),
|
|
3970
|
+
join10(root, "agents", "cursor-runner.cjs"),
|
|
3841
3971
|
// If somehow resolved from package root instead of dist/
|
|
3842
|
-
|
|
3843
|
-
|
|
3972
|
+
join10(root, "dist", "agents", "cursor-runner.js"),
|
|
3973
|
+
join10(root, "dist", "agents", "cursor-runner.cjs"),
|
|
3844
3974
|
// Source tree (dev): packages/core/src/agents/cursor-runner.ts
|
|
3845
|
-
|
|
3846
|
-
|
|
3975
|
+
join10(root, "cursor-runner.ts"),
|
|
3976
|
+
join10(root, "src", "agents", "cursor-runner.ts")
|
|
3847
3977
|
];
|
|
3848
3978
|
for (const candidate of candidates) {
|
|
3849
|
-
if (
|
|
3979
|
+
if (existsSync11(candidate)) return candidate;
|
|
3850
3980
|
}
|
|
3851
3981
|
return candidates[0];
|
|
3852
3982
|
}
|
|
@@ -3952,14 +4082,14 @@ var cursorAdapter = {
|
|
|
3952
4082
|
};
|
|
3953
4083
|
|
|
3954
4084
|
// src/agents/opencode.ts
|
|
3955
|
-
import { existsSync as
|
|
4085
|
+
import { existsSync as existsSync13 } from "fs";
|
|
3956
4086
|
|
|
3957
4087
|
// src/agent-rpc/opencode-host.ts
|
|
3958
4088
|
import { pathToFileURL } from "url";
|
|
3959
4089
|
|
|
3960
4090
|
// src/agent-rpc/opencode-hook.ts
|
|
3961
|
-
import { existsSync as
|
|
3962
|
-
import { join as
|
|
4091
|
+
import { existsSync as existsSync12, mkdirSync as mkdirSync3, readFileSync as readFileSync5, renameSync, writeFileSync as writeFileSync4 } from "fs";
|
|
4092
|
+
import { join as join11 } from "path";
|
|
3963
4093
|
var OPENCODE_PLUGIN_SOURCE = `import { tool } from "@opencode-ai/plugin"
|
|
3964
4094
|
|
|
3965
4095
|
const RPC_URL = process.env[${JSON.stringify(AGENT_RPC_URL_ENV)}] || ""
|
|
@@ -4069,10 +4199,10 @@ export const SideboardRpc = async (ctx) => {
|
|
|
4069
4199
|
}
|
|
4070
4200
|
`;
|
|
4071
4201
|
function writeOpencodeRpcPlugin() {
|
|
4072
|
-
const pluginDir =
|
|
4202
|
+
const pluginDir = join11(appDataDir(), "agent-rpc", "opencode");
|
|
4073
4203
|
mkdirSync3(pluginDir, { recursive: true });
|
|
4074
|
-
const pluginFile =
|
|
4075
|
-
if (
|
|
4204
|
+
const pluginFile = join11(pluginDir, "sideboard-rpc.js");
|
|
4205
|
+
if (existsSync12(pluginFile)) {
|
|
4076
4206
|
try {
|
|
4077
4207
|
if (readFileSync5(pluginFile, "utf8") === OPENCODE_PLUGIN_SOURCE) return pluginFile;
|
|
4078
4208
|
} catch {
|
|
@@ -4173,7 +4303,7 @@ async function listOpencodeModels() {
|
|
|
4173
4303
|
if (opencode === "opencode") {
|
|
4174
4304
|
const which = await run("which", ["opencode"], { reject: false });
|
|
4175
4305
|
if (which.exitCode !== 0) return FALLBACK_OPENCODE_MODELS;
|
|
4176
|
-
} else if (!
|
|
4306
|
+
} else if (!existsSync13(opencode)) {
|
|
4177
4307
|
return FALLBACK_OPENCODE_MODELS;
|
|
4178
4308
|
}
|
|
4179
4309
|
const listed = await run(opencode, ["models"], { reject: false });
|
|
@@ -4208,7 +4338,7 @@ var opencodeAdapter = {
|
|
|
4208
4338
|
async detect() {
|
|
4209
4339
|
const opencode = resolveAgentExecutable("opencode");
|
|
4210
4340
|
if (opencode !== "opencode") {
|
|
4211
|
-
if (!
|
|
4341
|
+
if (!existsSync13(opencode)) {
|
|
4212
4342
|
return {
|
|
4213
4343
|
agent: "opencode",
|
|
4214
4344
|
installed: false,
|
|
@@ -4459,7 +4589,7 @@ var opencodeAdapter = {
|
|
|
4459
4589
|
};
|
|
4460
4590
|
},
|
|
4461
4591
|
async listLinearIssues(_repoPath) {
|
|
4462
|
-
const { listAssignedLinearIssues: listAssignedLinearIssues2 } = await import("./linear-list-
|
|
4592
|
+
const { listAssignedLinearIssues: listAssignedLinearIssues2 } = await import("./linear-list-VU47BNUV.js");
|
|
4463
4593
|
return listAssignedLinearIssues2();
|
|
4464
4594
|
}
|
|
4465
4595
|
};
|
|
@@ -4491,7 +4621,7 @@ async function listBrightsyModels() {
|
|
|
4491
4621
|
}
|
|
4492
4622
|
}
|
|
4493
4623
|
async function listModelsForAgent(agent) {
|
|
4494
|
-
const kinds = agent ? [agent] : ["claude", "codex", "opencode", "cursor", "brightsy"];
|
|
4624
|
+
const kinds = agent ? [agent] : ["claude", "codex", "opencode", "cursor", "brightsy", "acp"];
|
|
4495
4625
|
const out = [];
|
|
4496
4626
|
for (const kind of kinds) {
|
|
4497
4627
|
if (kind === "claude") {
|
|
@@ -4530,6 +4660,15 @@ async function listModelsForAgent(agent) {
|
|
|
4530
4660
|
});
|
|
4531
4661
|
continue;
|
|
4532
4662
|
}
|
|
4663
|
+
if (kind === "acp") {
|
|
4664
|
+
out.push({
|
|
4665
|
+
agent: kind,
|
|
4666
|
+
auto: true,
|
|
4667
|
+
models: [],
|
|
4668
|
+
note: "Gemini CLI and Copilot CLI choose the model. Leave model unset."
|
|
4669
|
+
});
|
|
4670
|
+
continue;
|
|
4671
|
+
}
|
|
4533
4672
|
if (kind === "brightsy") {
|
|
4534
4673
|
const models = await listBrightsyModels();
|
|
4535
4674
|
out.push({
|
|
@@ -4648,7 +4787,8 @@ var adapters = {
|
|
|
4648
4787
|
codex: codexAdapter,
|
|
4649
4788
|
opencode: opencodeAdapter,
|
|
4650
4789
|
brightsy: brightsyAdapter,
|
|
4651
|
-
cursor: cursorAdapter
|
|
4790
|
+
cursor: cursorAdapter,
|
|
4791
|
+
acp: acpAdapter
|
|
4652
4792
|
};
|
|
4653
4793
|
function getAdapter(kind) {
|
|
4654
4794
|
return adapters[kind];
|
|
@@ -4673,7 +4813,6 @@ export {
|
|
|
4673
4813
|
adjustBrightsyTurnExit,
|
|
4674
4814
|
listBrightsyChatTargets,
|
|
4675
4815
|
brightsyAdapter,
|
|
4676
|
-
mcpStatusThinkingFromClaudeInit,
|
|
4677
4816
|
mcpUiContentSecurityPolicy,
|
|
4678
4817
|
SIDEBOARD_MCP_PROFILE_ENV,
|
|
4679
4818
|
SIDEBOARD_THREAD_ID_ENV,
|
|
@@ -4698,6 +4837,10 @@ export {
|
|
|
4698
4837
|
registerPackagedUserMcpClients,
|
|
4699
4838
|
isInjectedOrchMcpName,
|
|
4700
4839
|
userMcpNamesToDisable,
|
|
4840
|
+
acpRunnerPath,
|
|
4841
|
+
acpAdapter,
|
|
4842
|
+
acpHarnessDisplayName,
|
|
4843
|
+
mcpStatusThinkingFromClaudeInit,
|
|
4701
4844
|
getMcpUiHost,
|
|
4702
4845
|
closeMcpUiHost,
|
|
4703
4846
|
parseClaudeUsagePayload,
|