ccdeck 3.82.4 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSING.md +42 -4
- package/README.md +183 -72
- package/THIRD_PARTY_NOTICES.md +243 -17
- package/bin/cli/tui.js +58 -4
- package/bin/deck.js +27 -1
- package/dist/web/assets/AccountBridge-OQHT5qmS.js +1 -0
- package/dist/web/assets/AccountSection-BpIHPhF3.js +1 -0
- package/dist/web/assets/BrowserWatchModal-DBdt52v7.js +1 -0
- package/dist/web/assets/FeedbackConversations-BJjgXI0-.js +1 -0
- package/dist/web/assets/IntegrationModal-DQ0vEz4X.js +7 -0
- package/dist/web/assets/IntegrationSkeleton-JCPbqp96.js +1 -0
- package/dist/web/assets/RadioPanel-Be6AkrKl.js +1 -0
- package/dist/web/assets/StageShell-Dq0JOQhd.js +4 -0
- package/dist/web/assets/TrafficRadar-7jqJbhaK.js +8 -0
- package/dist/web/assets/UsageHistoryModal-ckawZGoe.js +1 -0
- package/dist/web/assets/addon-unicode-graphemes-DW3WJwyh.js +18 -0
- package/dist/web/assets/addon-web-links-BWjmmSgS.js +12 -0
- package/dist/web/assets/addon-webgl-CLK4R-_u.js +75 -0
- package/dist/web/assets/app-40gNTTfq.js +361 -0
- package/dist/web/assets/app-BRjYF6oD.css +1 -0
- package/dist/web/assets/{index-B-l-VxLm.js → index-XIY3yFiN.js} +1 -1
- package/dist/web/assets/inspector-status-pane-BV_m7eBv.js +1 -0
- package/dist/web/assets/screens-9_ivqfcF.js +12 -0
- package/dist/web/assets/screens-DUniTTbC.css +1 -0
- package/dist/web/assets/stage-board-NF_wgGRA.js +2 -0
- package/dist/web/assets/use-account-BUmI-A8e.js +1 -0
- package/dist/web/assets/xterm-4jYizCpg.js +27 -0
- package/dist/web/assets/xterm-sheet-6GBZ9nXN.css +32 -0
- package/dist/web/index.html +16 -6
- package/package.json +13 -1
- package/release-notes.json +67 -0
- package/src/server/account-client.mjs +196 -0
- package/src/server/account-connect.mjs +238 -0
- package/src/server/account-flag.mjs +106 -0
- package/src/server/account-projects.mjs +1 -1
- package/src/server/account-service.mjs +532 -0
- package/src/server/account-status.mjs +293 -0
- package/src/server/account-store.mjs +137 -0
- package/src/server/account-sync.mjs +473 -0
- package/src/server/account-token-store.mjs +216 -0
- package/src/server/account-ui-fields.mjs +126 -0
- package/src/server/account-watch.mjs +1 -1
- package/src/server/browser-watch-log.mjs +1 -1
- package/src/server/browser-watch-store.mjs +1 -1
- package/src/server/ccdeck-account-routes.mjs +252 -0
- package/src/server/ccusage-install.mjs +2 -2
- package/src/server/ccusage-registry.mjs +4 -4
- package/src/server/ccusage-session.mjs +11 -0
- package/src/server/claude-accounts.mjs +1 -1
- package/src/server/claude-recovery.mjs +9 -4
- package/src/server/claude-settings-catalog.mjs +6 -6
- package/src/server/claude-settings.mjs +1 -1
- package/src/server/codex-auto.mjs +1 -1
- package/src/server/codex-cost-usage.mjs +7 -2
- package/src/server/codex-live-checkpoint.mjs +24 -9
- package/src/server/codex-live-engine.mjs +14 -4
- package/src/server/codex-live-handoff.mjs +53 -9
- package/src/server/codex-names.mjs +49 -0
- package/src/server/codex-translate.mjs +1 -1
- package/src/server/codex-ultrafast.d.mts +3 -0
- package/src/server/codex-ultrafast.mjs +5 -0
- package/src/server/codex-watch.mjs +25 -0
- package/src/server/command-panel-engine.mjs +300 -0
- package/src/server/command-panel-platform.mjs +99 -0
- package/src/server/cswap-auto-choice.mjs +1 -1
- package/src/server/cswap-auto-loop.mjs +1 -1
- package/src/server/cswap-install.mjs +21 -40
- package/src/server/deck-home.mjs +6 -0
- package/src/server/deck-prefs.mjs +53 -1
- package/src/server/detach.mjs +1 -1
- package/src/server/engine-download.mjs +277 -0
- package/src/server/engine-install.mjs +378 -0
- package/src/server/engine-package.mjs +267 -0
- package/src/server/event-log.mjs +7 -1
- package/src/server/event-pipeline.mjs +29 -1
- package/src/server/ghostty-handoff.mjs +81 -0
- package/src/server/index.mjs +143 -5
- package/src/server/installer.mjs +4 -1
- package/src/server/integrations/jira-write-guard.mjs +14 -208
- package/src/server/integrations/store.mjs +37 -19
- package/src/server/integrations/write-guard.mjs +223 -0
- package/src/server/intel-cpu-temperature.mjs +26 -0
- package/src/server/lifecycle.mjs +69 -6
- package/src/server/log-replay.mjs +4 -0
- package/src/server/login-service.mjs +7 -1
- package/src/server/macmon.mjs +1 -1
- package/src/server/npm-latest.mjs +1 -1
- package/src/server/org-telemetry.mjs +1 -1
- package/src/server/output-watch.mjs +4 -1
- package/src/server/panel-provenance.mjs +390 -0
- package/src/server/pinned-build.mjs +14 -0
- package/src/server/prefs-refusal.mjs +8 -1
- package/src/server/prefs-routes.mjs +60 -11
- package/src/server/pro-engine-client.mjs +339 -0
- package/src/server/pro-engine-install.mjs +294 -0
- package/src/server/pro-engine-terminal.mjs +308 -0
- package/src/server/project-discovery.mjs +139 -0
- package/src/server/provider-session-name.mjs +58 -0
- package/src/server/quota-closes.mjs +1 -1
- package/src/server/quota-history.mjs +1 -1
- package/src/server/reports.mjs +86 -21
- package/src/server/request-gates.mjs +34 -5
- package/src/server/restart-note.mjs +1 -1
- package/src/server/seed-boundary.mjs +489 -0
- package/src/server/session-counts.mjs +244 -0
- package/src/server/session-deck-names.mjs +143 -0
- package/src/server/session-enrichment.mjs +43 -6
- package/src/server/session-name-route.mjs +73 -0
- package/src/server/session-summary.mjs +12 -1
- package/src/server/session-transcript-routes.mjs +167 -0
- package/src/server/swap-log.mjs +1 -1
- package/src/server/system-metrics.mjs +57 -0
- package/src/server/terminal-bridge.mjs +485 -0
- package/src/server/terminal-folder.mjs +61 -0
- package/src/server/terminal-js-routes.mjs +752 -0
- package/src/server/terminal-routes.mjs +553 -0
- package/src/server/terminal-sessions.mjs +759 -0
- package/src/server/terminal-socket.mjs +403 -0
- package/src/server/terminal-target.mjs +928 -0
- package/src/server/thermal-metrics.mjs +13 -9
- package/src/server/tmux-control.mjs +1319 -0
- package/src/server/tmux-download.mjs +220 -0
- package/src/server/tmux.mjs +542 -0
- package/src/server/token-redact.mjs +42 -3
- package/src/server/tool-audit-report.mjs +44 -6
- package/src/server/tool-audit-routes.mjs +12 -1
- package/src/server/tool-audit.mjs +42 -8
- package/src/server/traffic-radar-monitor.mjs +1 -1
- package/src/server/traffic-radar-permission.mjs +1 -1
- package/src/server/transcript-gate.mjs +1 -1
- package/src/server/transcript-scan.mjs +15 -7
- package/src/server/transcript-turns.mjs +154 -0
- package/src/server/tui-network.mjs +1 -0
- package/src/server/tui-view.mjs +28 -0
- package/src/server/utf8-carry.mjs +159 -0
- package/src/server/uv-bootstrap.mjs +2 -2
- package/src/server/windows-acl.mjs +158 -0
- package/src/server/ws-frames.mjs +690 -0
- package/dist/web/assets/BrowserWatchModal-CWVooKxD.js +0 -1
- package/dist/web/assets/IntegrationModal-DLX43RIK.js +0 -7
- package/dist/web/assets/RadioPanel-Cj6PjrvQ.js +0 -1
- package/dist/web/assets/TrafficRadar-Bq1YcuHB.js +0 -8
- package/dist/web/assets/UsageHistoryModal-CMSCca5_.js +0 -1
- package/dist/web/assets/app-BHxsMz3-.js +0 -358
- package/dist/web/assets/app-CbXmr9rC.css +0 -1
package/src/server/index.mjs
CHANGED
|
@@ -138,7 +138,14 @@ import { armLifecycle, handlePresence, handleRestart, handleStop, handleUpgrade,
|
|
|
138
138
|
export { markDeckReady, releaseRestart } from "./lifecycle.mjs";
|
|
139
139
|
// The settings as this process holds them, and every write that changes them —
|
|
140
140
|
// see prefs-state.mjs.
|
|
141
|
-
import { prefsRead } from "./prefs-state.mjs";
|
|
141
|
+
import { heldPrefs, prefsRead } from "./prefs-state.mjs";
|
|
142
|
+
// Whether this deck has a ccdeck account at all — hidden, and off unless
|
|
143
|
+
// CCDECK_ACCOUNT=1 or the deck-owned `account` pref says so; see
|
|
144
|
+
// account-flag.mjs. The account's own modules are imported only behind it.
|
|
145
|
+
import { accountOn } from "./account-flag.mjs";
|
|
146
|
+
// The way out a launcher takes, for the steps the server registers on it (the
|
|
147
|
+
// account's last status frame) — see lifecycle.mjs onBeforeShutdown.
|
|
148
|
+
export { beforeShutdown } from "./lifecycle.mjs";
|
|
142
149
|
// Quota read for the account notifications while no page reads it — only while
|
|
143
150
|
// one of their quota switches is on (account-watch.mjs).
|
|
144
151
|
import { startAccountWatch, noteCodexAutoTick } from "./account-watch.mjs";
|
|
@@ -150,6 +157,10 @@ import { applyLanPrefs, resetLanLoaded } from "./lan-deck.mjs";
|
|
|
150
157
|
import { handleLanInvite, handleLanPeer, handleLanStatus, handleLanSync } from "./lan-routes.mjs";
|
|
151
158
|
// GET and POST /api/prefs — see prefs-routes.mjs.
|
|
152
159
|
import { handlePrefsGiveBack, handlePrefsRead, handlePrefsWrite } from "./prefs-routes.mjs";
|
|
160
|
+
// POST /api/session-name, and the names it keeps (internal #101) — see
|
|
161
|
+
// session-name-route.mjs and session-deck-names.mjs.
|
|
162
|
+
import { announceKeptNames, handleSessionNameWrite } from "./session-name-route.mjs";
|
|
163
|
+
import { loadDeckNames } from "./session-deck-names.mjs";
|
|
153
164
|
// Usage reports and the feedback dialog (#1853). The requests to
|
|
154
165
|
// api.ccdeck.dev are made in reports.mjs, never in this file.
|
|
155
166
|
import {
|
|
@@ -174,6 +185,7 @@ import { handleBestOfNostalgia, handleCafeMusicBgm, handleClaudeFm, handleFmStat
|
|
|
174
185
|
// The usage panel's quota and history reads — see usage-routes.mjs.
|
|
175
186
|
import { startToolAudit } from "./tool-audit.mjs";
|
|
176
187
|
import { handleToolAudit } from "./tool-audit-routes.mjs";
|
|
188
|
+
import { handleSessionTranscript, SESSION_TRANSCRIPT_ROUTE } from "./session-transcript-routes.mjs";
|
|
177
189
|
import { startQuotaHistory } from "./quota-history.mjs";
|
|
178
190
|
import { startQuotaCloses } from "./quota-closes.mjs";
|
|
179
191
|
import { startQuotaCloseWatch } from "./quota-close-watch.mjs";
|
|
@@ -181,6 +193,27 @@ import { handleCcusage, handleCcusageSession, handleCodexQuota, handleCodexUsage
|
|
|
181
193
|
// Connected trackers (#2178) and each provider's own reads. See
|
|
182
194
|
// integrations/routes.mjs; nothing in it is shared with paired decks.
|
|
183
195
|
import { handleIntegrations } from "./integrations/routes.mjs";
|
|
196
|
+
// The Command Panel's eight routes, every one absent while the panel is
|
|
197
|
+
// switched off and answered by the optional local engine while it is on —
|
|
198
|
+
// see terminal-routes.mjs — its folder check, which the deck answers itself
|
|
199
|
+
// under the same switch, and the WebSocket upgrade that carries a session,
|
|
200
|
+
// which runs its own gates because the route table never sees an upgrade
|
|
201
|
+
// (terminal-socket.mjs).
|
|
202
|
+
import {
|
|
203
|
+
handleTerminalAdopt, handleTerminalBackground, handleTerminalClaim, handleTerminalEndHosts, handleTerminalFolder, handleTerminalHosts, handleTerminalLaunch, handleTerminalOpen,
|
|
204
|
+
handleTerminalStatus, handleTerminalTarget, handleTerminalProjects, terminalUpgradeOptions,
|
|
205
|
+
handleEngineStatus, handleEngineAction,
|
|
206
|
+
} from "./terminal-routes.mjs";
|
|
207
|
+
import { installTerminalUpgrade } from "./terminal-socket.mjs";
|
|
208
|
+
// Whether this deck's platform has the Command Panel, which Settings' switch
|
|
209
|
+
// follows: Linux and macOS; on Windows only the test-only preview, which no
|
|
210
|
+
// production entry can ask for (command-panel-platform.mjs).
|
|
211
|
+
import { commandPanelPlatform } from "./command-panel-platform.mjs";
|
|
212
|
+
// For bin/deck.js's shutdown: an upgraded socket is not in the HTTP server's
|
|
213
|
+
// connection list, so closeAllConnections() never reaches a terminal; and the
|
|
214
|
+
// Command Panel's engine, a child of this process, is stopped beside them.
|
|
215
|
+
export { closeAllTerminals } from "./terminal-socket.mjs";
|
|
216
|
+
export { stopCommandPanelEngine } from "./command-panel-engine.mjs";
|
|
184
217
|
// The port fallback, one listen attempt, and the words for a failed one — see
|
|
185
218
|
// listen.mjs. The loop that uses them is startServer's.
|
|
186
219
|
import { listenFailure, portRetryable, randomPort, tryListen } from "./listen.mjs";
|
|
@@ -205,13 +238,61 @@ export function requestUrl(rawUrl) {
|
|
|
205
238
|
catch { return null; }
|
|
206
239
|
}
|
|
207
240
|
|
|
208
|
-
|
|
241
|
+
// The ccdeck account's routes, loaded the first time they are wanted and only
|
|
242
|
+
// while the account is on (account-flag.mjs) — so a deck with it off never
|
|
243
|
+
// evaluates a line of them. One per process, like the deck's token.
|
|
244
|
+
let accountRoutes = null;
|
|
245
|
+
function loadAccountRoutes(deps) {
|
|
246
|
+
accountRoutes ??= import("./ccdeck-account-routes.mjs")
|
|
247
|
+
.then(m => m.startAccountRoutes(deps))
|
|
248
|
+
.catch(err => { accountRoutes = null; throw err; });
|
|
249
|
+
return accountRoutes;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** The account at boot, once the settings are read: loaded and started when
|
|
253
|
+
* it is on — which also loads it before any install can replace the tree, the
|
|
254
|
+
* pin pinned-build.mjs cannot give a module a deck with the account off must
|
|
255
|
+
* never evaluate — and nothing at all when it is off. */
|
|
256
|
+
async function startAccountWhenOn(deps) {
|
|
257
|
+
try {
|
|
258
|
+
await prefsRead;
|
|
259
|
+
if (accountOn(heldPrefs.current())) await loadAccountRoutes(deps);
|
|
260
|
+
} catch (err) {
|
|
261
|
+
console.error(`${PRODUCT}: the account could not start:`, err?.message ?? err);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** An /api/account route: with the account off, exactly the 404 an /api path
|
|
266
|
+
* with no route answers, asked of nothing else — see account-flag-off.test.ts. */
|
|
267
|
+
async function accountRoute(req, res, url, deps) {
|
|
268
|
+
await prefsRead;
|
|
269
|
+
if (!accountOn(heldPrefs.current())) return send(res, 404, { error: "not found" });
|
|
270
|
+
const routes = await loadAccountRoutes(deps);
|
|
271
|
+
return routes.handle(req, res, url);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// `account` is handed to the account's service as its stand-ins (a token store
|
|
275
|
+
// that never reaches a real keychain, a clock): the suite's, like `terminal`
|
|
276
|
+
// on the terminal branch. The product passes nothing.
|
|
277
|
+
// `terminal` is handed to the Command Panel's routes and its upgrade as their
|
|
278
|
+
// stand-ins (see terminalDeps in terminal-routes.mjs). The product passes
|
|
279
|
+
// nothing. A test passes an engine's terminal as `terminal.engine`
|
|
280
|
+
// (engineTerminals in pro-engine-terminal.mjs), or the JS backend as
|
|
281
|
+
// `terminal.jsBackend` (terminal-js-routes.mjs) to run the routes on a tmux
|
|
282
|
+
// server of its own: only a caller of startServer can, and nothing the deck
|
|
283
|
+
// runs imports that backend, so no setting, variable, flag or request reaches
|
|
284
|
+
// it.
|
|
285
|
+
export async function startServer({ port = 4317, host = "127.0.0.1", persist = null, portRange = [4318, 4400], workspace = "", codex = true, claude = true, onRestart = null, onStop = null, cswapQuiet = null, terminal = {}, account = {} } = {}) {
|
|
209
286
|
startQuotaHistory();
|
|
210
287
|
startQuotaCloses();
|
|
211
288
|
await startToolAudit();
|
|
212
289
|
armLifecycle({ onRestart, onStop, persist, onSelfUpdate: () => reporter.noteSelfUpdate() });
|
|
213
290
|
// Which tree and which CLIs, normalised once — see setDeckScope.
|
|
214
291
|
setDeckScope({ workspace, claude, codex });
|
|
292
|
+
// Whether the Command Panel's switch is offered here, asked once: the
|
|
293
|
+
// platform's answer, nothing loaded, unless a test-only preview option is
|
|
294
|
+
// handed on Windows (command-panel-platform.mjs).
|
|
295
|
+
const panelPlatform = await commandPanelPlatform(terminal);
|
|
215
296
|
// A boot is the one moment the file, and not the engine, is the authority on
|
|
216
297
|
// the key, the pairings and the port. See lanApplyFields.
|
|
217
298
|
resetLanLoaded();
|
|
@@ -247,6 +328,10 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
247
328
|
// already. Just keep the buffer + seq counter primed.
|
|
248
329
|
}
|
|
249
330
|
}
|
|
331
|
+
// The names a reader gave sessions in the deck, read once (internal #101),
|
|
332
|
+
// and told to the sessions the replay put back — see announceKeptNames.
|
|
333
|
+
await loadDeckNames();
|
|
334
|
+
announceKeptNames(eventsSince(0));
|
|
250
335
|
// The async handlers below are dispatched as floating promises. Node's
|
|
251
336
|
// default for an unhandled rejection is to kill the process, which would
|
|
252
337
|
// take the whole deck down — SSE stream, hook ingest and all — because one
|
|
@@ -339,19 +424,21 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
339
424
|
if (req.method === "POST" && url.pathname === "/api/presence") return guard(handlePresence(req, res), res);
|
|
340
425
|
if (req.method === "POST" && url.pathname === "/api/shutdown") return guard(handleStop(req, res), res);
|
|
341
426
|
if (["GET", "POST"].includes(req.method) && ["/api/tool-audit", "/api/tool-audit/storage"].includes(url.pathname)) return guard(handleToolAudit(req, res), res);
|
|
427
|
+
if (url.pathname === SESSION_TRANSCRIPT_ROUTE) return guard(handleSessionTranscript(req, res), res);
|
|
342
428
|
if (req.method === "GET" && url.pathname === "/api/quota/history") return guard(handleQuotaHistory(req, res), res);
|
|
343
429
|
if (req.method === "GET" && url.pathname === "/api/quota/closes") return guard(handleQuotaCloses(req, res), res);
|
|
344
430
|
if (req.method === "GET" && url.pathname === "/api/quota") return guard(handleQuota(req, res), res);
|
|
345
431
|
if (req.method === "GET" && url.pathname === "/api/codex-usage") return guard(handleCodexUsage(req, res), res);
|
|
346
432
|
// Machine state, not session state: sampled on the server's own timer and
|
|
347
433
|
// deliberately kept out of the event stream. See src/server/system-metrics.mjs.
|
|
348
|
-
if (req.method === "GET" && url.pathname === "/api/prefs") return handlePrefsRead(req, res);
|
|
434
|
+
if (req.method === "GET" && url.pathname === "/api/prefs") return handlePrefsRead(req, res, panelPlatform);
|
|
349
435
|
if (req.method === "GET" && url.pathname === "/api/lan") return handleLanStatus(req, res);
|
|
350
436
|
if (req.method === "POST" && url.pathname === "/api/lan/peer") return guard(handleLanPeer(req, res), res);
|
|
351
437
|
if (req.method === "POST" && url.pathname === "/api/lan/invite") return guard(handleLanInvite(req, res), res);
|
|
352
438
|
if (req.method === "POST" && url.pathname === "/api/lan/sync") return guard(handleLanSync(req, res), res);
|
|
353
|
-
if (req.method === "POST" && url.pathname === "/api/prefs") return guard(handlePrefsWrite(req, res), res);
|
|
354
|
-
if (req.method === "POST" && url.pathname === "/api/
|
|
439
|
+
if (req.method === "POST" && url.pathname === "/api/prefs") return guard(handlePrefsWrite(req, res, panelPlatform), res);
|
|
440
|
+
if (req.method === "POST" && url.pathname === "/api/session-name") return guard(handleSessionNameWrite(req, res), res);
|
|
441
|
+
if (req.method === "POST" && url.pathname === "/api/prefs/give-back") return guard(handlePrefsGiveBack(req, res, panelPlatform), res);
|
|
355
442
|
if (req.method === "POST" && url.pathname === "/api/reports") return guard(handleReportsWrite(req, res), res);
|
|
356
443
|
if (req.method === "POST" && url.pathname === "/api/ui-language") return guard(handleUiLanguageWrite(req, res), res);
|
|
357
444
|
if (req.method === "GET" && url.pathname === "/api/feedback") return handleFeedbackFacts(req, res);
|
|
@@ -474,6 +561,43 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
474
561
|
// once per name per day. A name, never what was in it. See feature-use.mjs.
|
|
475
562
|
if (req.method === "POST" && url.pathname === "/api/feature") return guard(handleFeature(req, res), res);
|
|
476
563
|
|
|
564
|
+
// The Command Panel. While it is switched off each of these answers the
|
|
565
|
+
// 404 below, word for word, without asking anything of anyone — see
|
|
566
|
+
// terminal-routes.mjs. Session ids ride in the query or the body, never in
|
|
567
|
+
// the path, so GUARDED_READS can name the three reads exactly.
|
|
568
|
+
if (req.method === "GET" && url.pathname === "/api/terminal/status") return guard(handleTerminalStatus(req, res, terminal), res);
|
|
569
|
+
if (req.method === "GET" && url.pathname === "/api/terminal/projects") return guard(handleTerminalProjects(req, res, terminal), res);
|
|
570
|
+
if (req.method === "GET" && url.pathname === "/api/terminal/target") return guard(handleTerminalTarget(req, res, url, terminal), res);
|
|
571
|
+
if (req.method === "GET" && url.pathname === "/api/terminal/hosts") return guard(handleTerminalHosts(req, res, terminal), res);
|
|
572
|
+
if (req.method === "POST" && url.pathname === "/api/terminal/hosts/end") return guard(handleTerminalEndHosts(req, res, terminal), res);
|
|
573
|
+
if (req.method === "POST" && url.pathname === "/api/terminal/open") return guard(handleTerminalOpen(req, res, terminal), res);
|
|
574
|
+
if (req.method === "POST" && url.pathname === "/api/terminal/background") return guard(handleTerminalBackground(req, res, terminal), res);
|
|
575
|
+
if (req.method === "POST" && url.pathname === "/api/terminal/adopt") return guard(handleTerminalAdopt(req, res, terminal), res);
|
|
576
|
+
if (req.method === "POST" && url.pathname === "/api/terminal/launch") return guard(handleTerminalLaunch(req, res, terminal), res);
|
|
577
|
+
if (req.method === "POST" && url.pathname === "/api/terminal/claim") return guard(handleTerminalClaim(req, res, terminal), res);
|
|
578
|
+
if (req.method === "POST" && url.pathname === "/api/terminal/folder") return guard(handleTerminalFolder(req, res, terminal), res);
|
|
579
|
+
// The engine's install, from the page (engine-install.mjs): its state, an
|
|
580
|
+
// install from the registry or from a file, a cancel and a remove.
|
|
581
|
+
if (req.method === "GET" && url.pathname === "/api/terminal/engine") return guard(handleEngineStatus(req, res, terminal), res);
|
|
582
|
+
if (req.method === "POST" && url.pathname.startsWith("/api/terminal/engine/")) return guard(handleEngineAction(req, res, url.pathname.slice("/api/terminal/engine/".length), terminal), res);
|
|
583
|
+
// The ccdeck account (account-flag.mjs). Switched off, each of these is
|
|
584
|
+
// the 404 below, word for word, and nothing of the account is loaded. The
|
|
585
|
+
// two reads are in GUARDED_READS; the POSTs are mutations like any other.
|
|
586
|
+
if (req.method === "GET" && url.pathname === "/api/account") return guard(accountRoute(req, res, url, account), res);
|
|
587
|
+
if (req.method === "POST" && url.pathname === "/api/account/connect") return guard(accountRoute(req, res, url, account), res);
|
|
588
|
+
if (req.method === "POST" && url.pathname === "/api/account/connect/cancel") return guard(accountRoute(req, res, url, account), res);
|
|
589
|
+
if (req.method === "POST" && url.pathname === "/api/account/disconnect") return guard(accountRoute(req, res, url, account), res);
|
|
590
|
+
if (req.method === "POST" && url.pathname === "/api/account/ui") return guard(accountRoute(req, res, url, account), res);
|
|
591
|
+
if (req.method === "POST" && url.pathname === "/api/account/ui/applied") return guard(accountRoute(req, res, url, account), res);
|
|
592
|
+
if (req.method === "GET" && url.pathname === "/api/account/sync/preview") return guard(accountRoute(req, res, url, account), res);
|
|
593
|
+
if (req.method === "POST" && url.pathname === "/api/account/sync/mode") return guard(accountRoute(req, res, url, account), res);
|
|
594
|
+
if (req.method === "POST" && url.pathname === "/api/account/sync/resolve") return guard(accountRoute(req, res, url, account), res);
|
|
595
|
+
if (req.method === "POST" && url.pathname === "/api/account/sync/upload") return guard(accountRoute(req, res, url, account), res);
|
|
596
|
+
// The account's feedback conversations, the list and everything under it
|
|
597
|
+
// (ccdeck-account-routes.mjs): the reads are guarded by prefix.
|
|
598
|
+
if (req.method === "GET" && (url.pathname === "/api/account/feedback/threads" || url.pathname.startsWith("/api/account/feedback/threads/"))) return guard(accountRoute(req, res, url, account), res);
|
|
599
|
+
if (req.method === "POST" && (url.pathname === "/api/account/feedback/threads" || url.pathname.startsWith("/api/account/feedback/threads/"))) return guard(accountRoute(req, res, url, account), res);
|
|
600
|
+
|
|
477
601
|
// AN UNMATCHED /api/ PATH IS A 404, not the SPA shell.
|
|
478
602
|
//
|
|
479
603
|
// serveStatic falls back to index.html for a path it cannot find, which is
|
|
@@ -541,6 +665,16 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
541
665
|
}
|
|
542
666
|
});
|
|
543
667
|
|
|
668
|
+
// THE ONE 'upgrade' LISTENER, and what having one costs: while it is there
|
|
669
|
+
// Node hands every request that carries an Upgrade header to it instead of
|
|
670
|
+
// to `route`, on any path and past every gate above. So it answers a 404 to
|
|
671
|
+
// everything that is not the terminal's own socket, and runs the gates again
|
|
672
|
+
// itself for the one path it takes. It is there only while the panel is
|
|
673
|
+
// switched on (installTerminalUpgrade follows the switch), so a deck with
|
|
674
|
+
// the panel off answers an offered upgrade the way it always did. Before the
|
|
675
|
+
// listen loop, so it is armed on whichever port binds.
|
|
676
|
+
installTerminalUpgrade(server, terminalUpgradeOptions(terminal));
|
|
677
|
+
|
|
544
678
|
// Try requested port first, then up to 10 random ports from portRange.
|
|
545
679
|
const candidates = [port];
|
|
546
680
|
for (let i = 0; i < 10; i++) candidates.push(randomPort(portRange[0], portRange[1]));
|
|
@@ -601,6 +735,10 @@ export async function startServer({ port = 4317, host = "127.0.0.1", persist = n
|
|
|
601
735
|
// unref'd timers. Switched off in Appearance, or with
|
|
602
736
|
// AGENTS_DECK_NO_REPORTS / AGENTS_DECK_NO_INSTALL, nothing is sent.
|
|
603
737
|
reporter.start();
|
|
738
|
+
// The ccdeck account, when it is on: the status frames and the settings
|
|
739
|
+
// sync of a deck that is connected, after the reporter as the design
|
|
740
|
+
// orders them. Off — the default — nothing here is even imported.
|
|
741
|
+
void startAccountWhenOn(account);
|
|
604
742
|
// Auto-switch resumes only if the user previously turned it on; the
|
|
605
743
|
// module reads its own persisted flag and does nothing otherwise. Its
|
|
606
744
|
// ticks wait for `cswapQuiet`, the launcher's word that claude-swap is not
|
package/src/server/installer.mjs
CHANGED
|
@@ -227,8 +227,11 @@ function isOurEntry(g) {
|
|
|
227
227
|
return withoutOurCommands(g) !== g;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
/** Every folder this makes, and any missing one above it, is its owner's
|
|
231
|
+
* alone (0700): agent-dag is the deck's data folder when CLAUDE_CONFIG_DIR
|
|
232
|
+
* is set. A folder already there keeps its mode. */
|
|
230
233
|
async function ensureDir(p) {
|
|
231
|
-
if (!existsSync(p)) await mkdir(p, { recursive: true });
|
|
234
|
+
if (!existsSync(p)) await mkdir(p, { recursive: true, mode: 0o700 });
|
|
232
235
|
}
|
|
233
236
|
|
|
234
237
|
/**
|
|
@@ -1,218 +1,24 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
import { chmod, link, mkdir, open, readFile, readdir, unlink } from 'node:fs/promises';
|
|
1
|
+
// The Jira side of the write guard: what a Jira write scope looks like. The
|
|
2
|
+
// reservations, locks and liveness checks live in write-guard.mjs.
|
|
4
3
|
import { join } from 'node:path';
|
|
5
|
-
import { createConnection, createServer } from 'node:net';
|
|
6
|
-
import { setTimeout as delay } from 'node:timers/promises';
|
|
7
|
-
import { createRequire } from 'node:module';
|
|
8
|
-
import { dirname } from 'node:path';
|
|
9
|
-
import { integrationError } from './errors.mjs';
|
|
10
4
|
import { deckDataDir } from '../deck-home.mjs';
|
|
11
|
-
import { createTemp, renameWithRetry } from '../atomic-write.mjs';
|
|
12
5
|
import { STORE_DIR } from './store.mjs';
|
|
6
|
+
import { createWriteGuard } from './write-guard.mjs';
|
|
13
7
|
|
|
14
|
-
const require = createRequire(import.meta.url);
|
|
15
|
-
let binding;
|
|
16
|
-
function nativeLock() {
|
|
17
|
-
if (!binding) {
|
|
18
|
-
// The exact dependency version pins this N-API layout and ABI. Loading the
|
|
19
|
-
// shipped binding directly avoids its resolver's Node 20-only Array.with.
|
|
20
|
-
// Keep this lazy so unsupported targets can still run the read-only deck.
|
|
21
|
-
const root = dirname(require.resolve('fs-native-extensions/package.json'));
|
|
22
|
-
binding = require(join(root, 'prebuilds', `${process.platform}-${process.arch}`, 'fs-native-extensions.node'));
|
|
23
|
-
}
|
|
24
|
-
return binding;
|
|
25
|
-
}
|
|
26
|
-
const nativeLocks = {
|
|
27
|
-
tryLock(fd) {
|
|
28
|
-
try { nativeLock().tryLock(fd, 0, 0, true); return true; }
|
|
29
|
-
catch (err) { if (err.code === 'EAGAIN') return false; throw err; }
|
|
30
|
-
},
|
|
31
|
-
unlock(fd) { nativeLock().unlock(fd, 0, 0); },
|
|
32
|
-
};
|
|
33
|
-
const active = new Set();
|
|
34
|
-
const listeners = new Map();
|
|
35
8
|
const keyPattern = /^[A-Z][A-Z0-9_]{0,40}-[1-9]\d{0,11}$/;
|
|
36
|
-
const uuidPattern = /^[0-9a-f-]{36}$/;
|
|
37
|
-
const scope = record => createHash('sha256').update(JSON.stringify([record.connectionId, record.kind, record.kind === 'move' ? '' : record.issueKey])).digest('hex');
|
|
38
|
-
const alive = pid => { try { process.kill(pid, 0); return true; } catch (e) { return e.code !== 'ESRCH'; } };
|
|
39
9
|
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
server.removeListener('error', reject);
|
|
48
|
-
resolve(server);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
const close = server => new Promise((resolve, reject) => server.close(err => err ? reject(err) : resolve()));
|
|
53
|
-
async function startMarker(op) {
|
|
54
|
-
const token = randomUUID();
|
|
55
|
-
let server;
|
|
56
|
-
do {
|
|
57
|
-
server = await listen(0, socket => {
|
|
58
|
-
socket.setTimeout(1000, () => socket.destroy());
|
|
59
|
-
socket.end(token);
|
|
60
|
-
});
|
|
61
|
-
} while (!server);
|
|
62
|
-
server.unref();
|
|
63
|
-
listeners.set(op.operationId, server);
|
|
64
|
-
return { port: server.address().port, token };
|
|
65
|
-
}
|
|
66
|
-
async function stopMarker(op) {
|
|
67
|
-
const server = listeners.get(op.operationId);
|
|
68
|
-
if (server) { listeners.delete(op.operationId); await close(server); }
|
|
69
|
-
}
|
|
70
|
-
function markerAlive(marker) {
|
|
71
|
-
return new Promise(resolve => {
|
|
72
|
-
let data = '';
|
|
73
|
-
let settled = false;
|
|
74
|
-
const socket = createConnection({ host: '127.0.0.1', port: marker.port });
|
|
75
|
-
const done = value => { if (!settled) { settled = true; socket.destroy(); resolve(value); } };
|
|
76
|
-
// Ambiguous failures are treated as live; never acknowledge on a timeout.
|
|
77
|
-
socket.setTimeout(1000, () => done(true));
|
|
78
|
-
socket.on('data', chunk => { data += chunk.toString(); if (data.length >= marker.token.length) done(data === marker.token); });
|
|
79
|
-
socket.on('end', () => done(data === marker.token));
|
|
80
|
-
socket.on('error', err => done(err.code !== 'ECONNREFUSED'));
|
|
81
|
-
});
|
|
10
|
+
// Validates a Jira write and builds the stored record, field order included.
|
|
11
|
+
function record(input) {
|
|
12
|
+
const { connectionId, kind } = input;
|
|
13
|
+
if (typeof connectionId !== 'string' || !connectionId || connectionId.length > 64 || !['comment', 'status', 'move'].includes(kind)) throw new Error('Invalid guard scope');
|
|
14
|
+
const op = { connectionId, kind, ...(kind === 'move' ? { boardId: input.boardId, issueKeys: input.issueKeys } : { issueKey: input.issueKey }) };
|
|
15
|
+
if (kind === 'move' ? typeof op.boardId !== 'string' || !/^[1-9]\d{0,11}$/.test(op.boardId) || !Array.isArray(op.issueKeys) || op.issueKeys.length < 1 || op.issueKeys.length > 50 || op.issueKeys.some(k => !keyPattern.test(k)) : !keyPattern.test(op.issueKey)) throw new Error('Invalid guard issue keys');
|
|
16
|
+
return op;
|
|
82
17
|
}
|
|
18
|
+
// The scope hash is made from this string; it must never change.
|
|
19
|
+
const key = rec => JSON.stringify([rec.connectionId, rec.kind, rec.kind === 'move' ? '' : rec.issueKey]);
|
|
83
20
|
|
|
84
|
-
export function createJiraWriteGuard({ dir = () => join(deckDataDir(), STORE_DIR, 'jira-write-guard'), locks
|
|
85
|
-
|
|
86
|
-
const root = dir();
|
|
87
|
-
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
88
|
-
if (process.platform !== 'win32') await chmod(root, 0o700);
|
|
89
|
-
return root;
|
|
90
|
-
}
|
|
91
|
-
async function syncDir(root) {
|
|
92
|
-
// Windows does not support opening directories for fsync.
|
|
93
|
-
if (process.platform === 'win32') return;
|
|
94
|
-
const h = await open(root, 'r'); try { await h.sync(); } finally { await h.close(); }
|
|
95
|
-
}
|
|
96
|
-
async function read(path) {
|
|
97
|
-
try { return JSON.parse(await readFile(path, 'utf8')); }
|
|
98
|
-
catch (e) { if (e.code === 'ENOENT') return null; throw e; }
|
|
99
|
-
}
|
|
100
|
-
async function running(root, op) {
|
|
101
|
-
if (active.has(op.operationId)) return true;
|
|
102
|
-
const names = await readdir(root);
|
|
103
|
-
const prefix = `running-${op.operationId}-`;
|
|
104
|
-
for (const name of names.filter(name => name.startsWith(prefix))) {
|
|
105
|
-
const marker = await read(join(root, name)).catch(err => {
|
|
106
|
-
// Older releases used empty PID-only marker files. Preserve their
|
|
107
|
-
// conservative behaviour while those processes may still be running.
|
|
108
|
-
if (err instanceof SyntaxError) return null;
|
|
109
|
-
throw err;
|
|
110
|
-
});
|
|
111
|
-
if (marker && Number.isInteger(marker.port) && marker.port > 0 && marker.port <= 65535 && typeof marker.token === 'string' && uuidPattern.test(marker.token)) {
|
|
112
|
-
if (await markerAlive(marker)) return true;
|
|
113
|
-
} else if (alive(Number(name.slice(prefix.length)))) return true;
|
|
114
|
-
}
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
async function state(root, op) { return { ...op, state: await running(root, op) ? 'pending' : op.state === 'confirmed' ? 'confirmed' : 'uncertain' }; }
|
|
118
|
-
async function lock(root, op, fn) {
|
|
119
|
-
// Keep the inode forever: unlinking/replacing a locked file would allow
|
|
120
|
-
// two processes to lock different inodes for the same scope. The kernel
|
|
121
|
-
// releases ownership on descriptor close or process death, not file age.
|
|
122
|
-
const handle = await open(join(root, `lock-${scope(op)}`), 'a+', 0o600);
|
|
123
|
-
let acquired = false;
|
|
124
|
-
try {
|
|
125
|
-
while (!(acquired = locks.tryLock(handle.fd))) await delay(10);
|
|
126
|
-
return await fn();
|
|
127
|
-
} finally {
|
|
128
|
-
try { if (acquired) locks.unlock(handle.fd); }
|
|
129
|
-
finally { await handle.close(); }
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
async begin(input) {
|
|
134
|
-
const { connectionId, kind } = input;
|
|
135
|
-
if (typeof connectionId !== 'string' || !connectionId || connectionId.length > 64 || !['comment', 'status', 'move'].includes(kind)) throw new Error('Invalid guard scope');
|
|
136
|
-
const op = { connectionId, kind, ...(kind === 'move' ? { boardId: input.boardId, issueKeys: input.issueKeys } : { issueKey: input.issueKey }), operationId: randomUUID(), state: 'pending' };
|
|
137
|
-
if (kind === 'move' ? typeof op.boardId !== 'string' || !/^[1-9]\d{0,11}$/.test(op.boardId) || !Array.isArray(op.issueKeys) || op.issueKeys.length < 1 || op.issueKeys.length > 50 || op.issueKeys.some(k => !keyPattern.test(k)) : !keyPattern.test(op.issueKey)) throw new Error('Invalid guard issue keys');
|
|
138
|
-
const root = await prepare();
|
|
139
|
-
// Check the actual filesystem and native support before any Jira write.
|
|
140
|
-
try { await lock(root, op, async () => {}); }
|
|
141
|
-
catch { throw integrationError('unavailable', 'Jira writes are unavailable because this system cannot safely coordinate them.'); }
|
|
142
|
-
const path = join(root, `${scope(op)}.json`);
|
|
143
|
-
const marker = join(root, `running-${op.operationId}-${process.pid}`);
|
|
144
|
-
const temp = join(root, `tmp-${op.operationId}`);
|
|
145
|
-
let returned = false;
|
|
146
|
-
active.add(op.operationId);
|
|
147
|
-
try {
|
|
148
|
-
const identity = await startMarker(op);
|
|
149
|
-
const markerHandle = await open(marker, 'wx', 0o600);
|
|
150
|
-
try { await markerHandle.writeFile(JSON.stringify(identity)); } finally { await markerHandle.close(); }
|
|
151
|
-
const h = await open(temp, 'wx', 0o600);
|
|
152
|
-
try { await h.writeFile(JSON.stringify(op)); await h.sync(); } finally { await h.close(); }
|
|
153
|
-
try { await link(temp, path); }
|
|
154
|
-
catch (e) {
|
|
155
|
-
if (e.code !== 'EEXIST') throw e;
|
|
156
|
-
const existing = await read(path);
|
|
157
|
-
if (!existing) return await this.begin(input);
|
|
158
|
-
return { conflict: await state(root, existing) };
|
|
159
|
-
}
|
|
160
|
-
await syncDir(root);
|
|
161
|
-
returned = true;
|
|
162
|
-
return { operation: { ...op, state: 'pending' } };
|
|
163
|
-
} finally {
|
|
164
|
-
await unlink(temp).catch(() => {});
|
|
165
|
-
if (!returned) { active.delete(op.operationId); await stopMarker(op); await unlink(marker).catch(() => {}); }
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
async finish(op, outcome) {
|
|
169
|
-
const root = await prepare();
|
|
170
|
-
try {
|
|
171
|
-
if (outcome === true || outcome === 'confirmed') {
|
|
172
|
-
const result = await lock(root, op, async () => {
|
|
173
|
-
const path = join(root, `${scope(op)}.json`);
|
|
174
|
-
const current = await read(path);
|
|
175
|
-
if (current?.operationId !== op.operationId) return { ok: false };
|
|
176
|
-
if (outcome === true) await unlink(path);
|
|
177
|
-
else {
|
|
178
|
-
const { tmp, handle } = await createTemp(path, { mode: 0o600 });
|
|
179
|
-
try {
|
|
180
|
-
try { await handle.writeFile(JSON.stringify({ ...current, state: 'confirmed' })); await handle.sync(); }
|
|
181
|
-
finally { await handle.close(); }
|
|
182
|
-
await renameWithRetry(tmp, path);
|
|
183
|
-
} finally { await unlink(tmp).catch(() => {}); }
|
|
184
|
-
}
|
|
185
|
-
await syncDir(root);
|
|
186
|
-
return { ok: true };
|
|
187
|
-
});
|
|
188
|
-
if (!result.ok) throw new Error('Jira write guard could not finalize the operation');
|
|
189
|
-
}
|
|
190
|
-
} finally {
|
|
191
|
-
active.delete(op.operationId);
|
|
192
|
-
await stopMarker(op);
|
|
193
|
-
await unlink(join(root, `running-${op.operationId}-${process.pid}`)).catch(() => {});
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
async list(connectionId) {
|
|
197
|
-
const root = await prepare();
|
|
198
|
-
const names = (await readdir(root)).filter(n => /^[a-f0-9]{64}\.json$/.test(n));
|
|
199
|
-
const records = await Promise.all(names.map(n => read(join(root, n))));
|
|
200
|
-
return Promise.all(records.filter(x => x?.connectionId === connectionId).map(x => state(root, x)));
|
|
201
|
-
},
|
|
202
|
-
async acknowledge(connectionId, operationId) {
|
|
203
|
-
if (typeof operationId !== 'string' || !uuidPattern.test(operationId)) return { ok: false };
|
|
204
|
-
const root = await prepare();
|
|
205
|
-
const op = (await this.list(connectionId)).find(x => x.operationId === operationId);
|
|
206
|
-
if (!op) return { ok: false };
|
|
207
|
-
return lock(root, op, async () => {
|
|
208
|
-
const path = join(root, `${scope(op)}.json`);
|
|
209
|
-
const current = await read(path);
|
|
210
|
-
if (!current || current.operationId !== operationId) return { ok: false };
|
|
211
|
-
if (await running(root, current)) return { conflict: await state(root, current) };
|
|
212
|
-
await unlink(path); await syncDir(root);
|
|
213
|
-
return { ok: true };
|
|
214
|
-
});
|
|
215
|
-
},
|
|
216
|
-
};
|
|
21
|
+
export function createJiraWriteGuard({ dir = () => join(deckDataDir(), STORE_DIR, 'jira-write-guard'), locks } = {}) {
|
|
22
|
+
return createWriteGuard({ name: 'Jira', dir, locks, scope: { record, key } });
|
|
217
23
|
}
|
|
218
24
|
export const jiraWriteGuard = createJiraWriteGuard();
|
|
@@ -39,6 +39,13 @@ const DIR_MODE = 0o700;
|
|
|
39
39
|
export const MAX_CONNECTIONS = 50;
|
|
40
40
|
/** The folder both files live in, inside the deck's home. */
|
|
41
41
|
export const STORE_DIR = "integrations";
|
|
42
|
+
/** The providers a usage report may name, in the order it names them. */
|
|
43
|
+
export const REPORTED_KINDS = ["jira", "github", "gitlab"];
|
|
44
|
+
/** The most connections of one kind a usage report counts: the cap the report
|
|
45
|
+
* puts on its other counts too (depth-facts.mjs COUNT_CAP, which the reporter
|
|
46
|
+
* holds the answer to again). The store saves no more than MAX_CONNECTIONS in
|
|
47
|
+
* all, so this bites only on a file edited by hand. */
|
|
48
|
+
export const REPORTED_CONNECTIONS_MAX = 50;
|
|
42
49
|
|
|
43
50
|
const text = (v, max = 500) => (typeof v === "string" ? v.slice(0, max) : "");
|
|
44
51
|
|
|
@@ -152,27 +159,38 @@ export function createIntegrationsStore({ dir = () => join(deckDataDir(), STORE_
|
|
|
152
159
|
* whether one is saved. */
|
|
153
160
|
const publicOf = (conn, secrets) => ({ ...conn, tokenSaved: secrets.has(conn.id) });
|
|
154
161
|
|
|
162
|
+
/**
|
|
163
|
+
* How many saved connections each supported provider has, capped at
|
|
164
|
+
* REPORTED_CONNECTIONS_MAX — never credentials, account identity, connection
|
|
165
|
+
* ID, name or address. Metadata alone is read: the secrets file is not even
|
|
166
|
+
* opened for usage reporting.
|
|
167
|
+
* null = unavailable/unreadable; all zeros = no file yet, or nothing connected.
|
|
168
|
+
*/
|
|
169
|
+
async function connectionCounts() {
|
|
170
|
+
const counts = Object.fromEntries(REPORTED_KINDS.map(k => [k, 0]));
|
|
171
|
+
try {
|
|
172
|
+
const raw = await readFile(join(dir(), META_FILE), "utf8");
|
|
173
|
+
const doc = JSON.parse(raw.replace(/^\uFEFF/, ""));
|
|
174
|
+
if (!doc || !Array.isArray(doc.connections)) return null;
|
|
175
|
+
for (const c of doc.connections) {
|
|
176
|
+
if (c && typeof c === "object" && REPORTED_KINDS.includes(c.kind)) counts[c.kind] += 1;
|
|
177
|
+
}
|
|
178
|
+
for (const k of REPORTED_KINDS) counts[k] = Math.min(counts[k], REPORTED_CONNECTIONS_MAX);
|
|
179
|
+
return counts;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (error?.code === "ENOENT") return counts;
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
155
186
|
return {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* null = unavailable/unreadable; [] = successfully read, nothing connected.
|
|
161
|
-
*/
|
|
187
|
+
connectionCounts,
|
|
188
|
+
/** The supported providers with at least one saved connection, in
|
|
189
|
+
* REPORTED_KINDS order, off the same read as connectionCounts.
|
|
190
|
+
* null = unavailable/unreadable; [] = nothing connected. */
|
|
162
191
|
async connectedKinds() {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const doc = JSON.parse(raw.replace(/^\uFEFF/, ""));
|
|
166
|
-
if (!doc || !Array.isArray(doc.connections)) return null;
|
|
167
|
-
const kinds = new Set(doc.connections
|
|
168
|
-
.filter(c => c && typeof c === "object" && typeof c.kind === "string")
|
|
169
|
-
.map(c => c.kind)
|
|
170
|
-
.filter(k => k === "jira" || k === "github" || k === "gitlab"));
|
|
171
|
-
return ["jira", "github", "gitlab"].filter(k => kinds.has(k));
|
|
172
|
-
} catch (error) {
|
|
173
|
-
if (error?.code === "ENOENT") return [];
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
192
|
+
const counts = await connectionCounts();
|
|
193
|
+
return counts && REPORTED_KINDS.filter(k => counts[k] > 0);
|
|
176
194
|
},
|
|
177
195
|
/** Every connection, as a page may see it. `own(conn, secret)`, when
|
|
178
196
|
* given, is handed each connection that has a secret, with it, and
|