@fitchmultz/pi-mcp-adapter 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +12 -8
  3. package/dist/app-bridge.bundle.js +14 -14
  4. package/dist/config.js +41 -16
  5. package/dist/gateway-arguments.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/lifecycle.d.ts +2 -2
  8. package/dist/lifecycle.js +2 -2
  9. package/dist/mcp-auth-flow.js +2 -2
  10. package/dist/mcp-auth.d.ts +1 -1
  11. package/dist/mcp-auth.js +3 -3
  12. package/dist/mcp-code.d.ts +6 -6
  13. package/dist/mcp-code.js +11 -10
  14. package/dist/mcp-oauth-provider.d.ts +5 -5
  15. package/dist/mcp-oauth-provider.js +5 -5
  16. package/dist/mcp-output-guard.d.ts +1 -1
  17. package/dist/mcp-panel.d.ts +2 -2
  18. package/dist/mcp-panel.js +2 -2
  19. package/dist/mcp-setup-panel.d.ts +5 -4
  20. package/dist/mcp-setup-panel.js +15 -7
  21. package/dist/mcp-trace.d.ts +1 -1
  22. package/dist/mcp-trace.js +1 -1
  23. package/dist/npx-resolver.js +8 -4
  24. package/dist/proxy-modes.d.ts +2 -2
  25. package/dist/proxy-modes.js +9 -9
  26. package/dist/sampling-handler.js +1 -0
  27. package/dist/search-ranking.js +6 -2
  28. package/dist/server-manager.d.ts +2 -2
  29. package/dist/server-manager.js +44 -27
  30. package/dist/session-recovery.d.ts +7 -4
  31. package/dist/session-recovery.js +76 -10
  32. package/dist/tool-metadata.d.ts +43 -43
  33. package/dist/tool-result-renderer.d.ts +3 -3
  34. package/dist/tool-result-renderer.js +3 -3
  35. package/dist/ui-resource-handler.d.ts +2 -2
  36. package/dist/ui-resource-handler.js +2 -2
  37. package/dist/ui-server.js +4 -3
  38. package/dist/ui-stream-types.d.ts +8 -8
  39. package/dist/unix-socket-transport.d.ts +1 -1
  40. package/dist/unix-socket-transport.js +1 -1
  41. package/dist/utils.d.ts +1 -0
  42. package/dist/utils.js +14 -0
  43. package/package.json +34 -98
  44. package/abort.ts +0 -34
  45. package/agent-dir.ts +0 -24
  46. package/app-bridge.bundle.js +0 -109
  47. package/banner.png +0 -0
  48. package/checkpoint.ts +0 -55
  49. package/commands.ts +0 -622
  50. package/config.ts +0 -1204
  51. package/consent-manager.ts +0 -25
  52. package/direct-tools.ts +0 -75
  53. package/elicitation-handler.ts +0 -349
  54. package/error-signal.ts +0 -21
  55. package/gateway-arguments.ts +0 -73
  56. package/glimpse-ui.ts +0 -80
  57. package/host-html-template.ts +0 -456
  58. package/index.ts +0 -767
  59. package/init.ts +0 -613
  60. package/legacy-migration.ts +0 -47
  61. package/lifecycle.ts +0 -165
  62. package/logger.ts +0 -127
  63. package/mcp-auth-flow.ts +0 -975
  64. package/mcp-auth.ts +0 -793
  65. package/mcp-callback-server.ts +0 -450
  66. package/mcp-code.ts +0 -412
  67. package/mcp-keyring-helper.cjs +0 -89
  68. package/mcp-oauth-provider.ts +0 -774
  69. package/mcp-output-guard.ts +0 -530
  70. package/mcp-panel.ts +0 -907
  71. package/mcp-script-worker.mjs +0 -131
  72. package/mcp-setup-panel.ts +0 -666
  73. package/mcp-status.ts +0 -110
  74. package/mcp-trace.ts +0 -295
  75. package/metadata-cache.ts +0 -271
  76. package/npx-resolver.ts +0 -488
  77. package/onboarding-state.ts +0 -58
  78. package/panel-keys.ts +0 -37
  79. package/prompts.ts +0 -337
  80. package/proxy-modes.ts +0 -1109
  81. package/resource-tools.ts +0 -52
  82. package/runtime-owner.ts +0 -123
  83. package/sampling-handler.ts +0 -276
  84. package/scripts/build-app-bridge.mjs +0 -15
  85. package/scripts/build.mjs +0 -132
  86. package/scripts/prepare.mjs +0 -103
  87. package/search-ranking.ts +0 -132
  88. package/server-manager.ts +0 -1320
  89. package/session-recovery.ts +0 -316
  90. package/state.ts +0 -64
  91. package/tool-approval.ts +0 -78
  92. package/tool-loader.ts +0 -153
  93. package/tool-metadata.ts +0 -240
  94. package/tool-registrar.ts +0 -74
  95. package/tool-result-renderer.ts +0 -294
  96. package/tsconfig.build.json +0 -13
  97. package/tsconfig.json +0 -16
  98. package/types.ts +0 -785
  99. package/ui-resource-handler.ts +0 -249
  100. package/ui-server.ts +0 -808
  101. package/ui-session.ts +0 -568
  102. package/ui-stream-types.ts +0 -89
  103. package/ui-tool-visibility.ts +0 -25
  104. package/unix-socket-transport.ts +0 -85
  105. package/utils.ts +0 -307
package/npx-resolver.ts DELETED
@@ -1,488 +0,0 @@
1
- // npx-resolver.ts - Resolve npx/npm exec binaries to avoid npm parent processes
2
- import { existsSync, readFileSync, realpathSync, readdirSync, statSync, writeFileSync, renameSync, mkdirSync, openSync, readSync, closeSync } from "node:fs";
3
- import { join, dirname, extname, resolve, sep } from "node:path";
4
- import { getAdapterPath } from "./agent-dir.ts";
5
- import { throwIfAborted } from "./abort.ts";
6
- import crossSpawn from "cross-spawn";
7
-
8
- const CACHE_VERSION = 1;
9
- const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
10
- const EXACT_PACKAGE_VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?$/;
11
-
12
- interface NpxCacheEntry {
13
- resolvedBin: string;
14
- resolvedAt: number;
15
- packageVersion?: string;
16
- isJs: boolean;
17
- }
18
-
19
- interface NpxCache {
20
- version: number;
21
- entries: Record<string, NpxCacheEntry>;
22
- }
23
-
24
- export interface NpxResolution {
25
- binPath: string;
26
- extraArgs: string[];
27
- isJs: boolean;
28
- }
29
-
30
- interface ParsedInvocation {
31
- packageSpec: string;
32
- binName?: string;
33
- extraArgs: string[];
34
- }
35
-
36
- interface ParsedPackageSpec {
37
- packageName: string;
38
- exactVersion?: string;
39
- }
40
-
41
- export async function resolveNpxBinary(
42
- command: string,
43
- args: string[],
44
- signal?: AbortSignal,
45
- ): Promise<NpxResolution | null> {
46
- throwIfAborted(signal);
47
- const parsed = command === "npx"
48
- ? parseNpxArgs(args)
49
- : command === "npm"
50
- ? parseNpmExecArgs(args)
51
- : null;
52
-
53
- if (!parsed) return null;
54
-
55
- const packageSpec = parsePackageSpec(parsed.packageSpec);
56
- const cacheKey = JSON.stringify([command, ...args]);
57
- const cache = loadCache();
58
- const cached = cache?.entries?.[cacheKey];
59
-
60
- if (
61
- cached
62
- && Date.now() - cached.resolvedAt < CACHE_TTL_MS
63
- && existsSync(cached.resolvedBin)
64
- && (!packageSpec?.exactVersion || cached.packageVersion === packageSpec.exactVersion)
65
- ) {
66
- return { binPath: cached.resolvedBin, extraArgs: parsed.extraArgs, isJs: cached.isJs };
67
- }
68
-
69
- const resolved = resolveFromNpmCache(parsed.packageSpec, parsed.binName);
70
- if (resolved) {
71
- saveCacheEntry(cacheKey, resolved);
72
- return { binPath: resolved.resolvedBin, extraArgs: parsed.extraArgs, isJs: resolved.isJs };
73
- }
74
-
75
- // Slow path: force npx cache population
76
- await forceNpxCache(parsed.packageSpec, signal);
77
- const resolvedAfterInstall = resolveFromNpmCache(parsed.packageSpec, parsed.binName);
78
- if (resolvedAfterInstall) {
79
- saveCacheEntry(cacheKey, resolvedAfterInstall);
80
- return { binPath: resolvedAfterInstall.resolvedBin, extraArgs: parsed.extraArgs, isJs: resolvedAfterInstall.isJs };
81
- }
82
-
83
- return null;
84
- }
85
-
86
- function parseNpxArgs(args: string[]): ParsedInvocation | null {
87
- const separatorIndex = args.indexOf("--");
88
- const before = separatorIndex >= 0 ? args.slice(0, separatorIndex) : args;
89
- const after = separatorIndex >= 0 ? args.slice(separatorIndex + 1) : [];
90
-
91
- const positionals: string[] = [];
92
- let packageSpec: string | undefined;
93
- let sawPackageFlag = false;
94
- let foundFirstPositional = false;
95
-
96
- for (let i = 0; i < before.length; i++) {
97
- const arg = before[i];
98
- if (arg === undefined) return null;
99
- if (foundFirstPositional) {
100
- positionals.push(arg);
101
- continue;
102
- }
103
- if (arg === "-y" || arg === "--yes") continue;
104
- if (arg === "-p" || arg === "--package") {
105
- const value = before[i + 1];
106
- if (!value || value.startsWith("-")) return null;
107
- if (!packageSpec) packageSpec = value;
108
- sawPackageFlag = true;
109
- i++;
110
- continue;
111
- }
112
- if (arg.startsWith("--package=")) {
113
- const value = arg.slice("--package=".length);
114
- if (!value) return null;
115
- if (!packageSpec) packageSpec = value;
116
- sawPackageFlag = true;
117
- continue;
118
- }
119
- if (arg.startsWith("-")) {
120
- return null;
121
- }
122
- positionals.push(arg);
123
- foundFirstPositional = true;
124
- }
125
-
126
- const separatedAfter = separatorIndex >= 0 && after.length > 0 ? ["--", ...after] : after;
127
-
128
- if (sawPackageFlag) {
129
- const binName = positionals[0];
130
- if (!packageSpec || !binName) return null;
131
- const extraArgs = positionals.slice(1).concat(separatedAfter);
132
- return { packageSpec, binName, extraArgs };
133
- }
134
-
135
- const packagePositional = positionals[0];
136
- if (!packagePositional) return null;
137
- const extraArgs = positionals.slice(1).concat(separatedAfter);
138
- return { packageSpec: packagePositional, extraArgs };
139
- }
140
-
141
- function parseNpmExecArgs(args: string[]): ParsedInvocation | null {
142
- if (args[0] !== "exec") return null;
143
- const execArgs = args.slice(1);
144
- const separatorIndex = execArgs.indexOf("--");
145
- if (separatorIndex < 0) return null;
146
-
147
- const before = execArgs.slice(0, separatorIndex);
148
- const after = execArgs.slice(separatorIndex + 1);
149
-
150
- let packageSpec: string | undefined;
151
- for (let i = 0; i < before.length; i++) {
152
- const arg = before[i];
153
- if (arg === undefined) return null;
154
- if (arg === "-y" || arg === "--yes") continue;
155
- if (arg === "--package") {
156
- const value = before[i + 1];
157
- if (!value || value.startsWith("-")) return null;
158
- if (!packageSpec) packageSpec = value;
159
- i++;
160
- continue;
161
- }
162
- if (arg.startsWith("--package=")) {
163
- const value = arg.slice("--package=".length);
164
- if (!value) return null;
165
- if (!packageSpec) packageSpec = value;
166
- continue;
167
- }
168
- if (arg.startsWith("-")) {
169
- return null;
170
- }
171
- }
172
-
173
- const binName = after[0];
174
- if (!packageSpec || !binName) return null;
175
- const extraArgs = after.slice(1);
176
- return { packageSpec, binName, extraArgs };
177
- }
178
-
179
- function resolveFromNpmCache(packageSpec: string, binName?: string): NpxCacheEntry | null {
180
- const cacheDir = getNpmCacheDir();
181
- if (!cacheDir) return null;
182
-
183
- const parsedSpec = parsePackageSpec(packageSpec);
184
- if (!parsedSpec) return null;
185
-
186
- const { packageName, exactVersion } = parsedSpec;
187
- const packageDir = findCachedPackageDir(cacheDir, packageName, exactVersion);
188
- if (!packageDir) return null;
189
-
190
- const packageJsonPath = join(packageDir, "package.json");
191
- if (!existsSync(packageJsonPath)) return null;
192
-
193
- let pkg: { bin?: string | Record<string, string>; version?: string } | null = null;
194
- try {
195
- pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as {
196
- bin?: string | Record<string, string>;
197
- version?: string;
198
- };
199
- } catch {
200
- return null;
201
- }
202
-
203
- const binField = pkg?.bin;
204
- if (!binField) return null;
205
-
206
- const candidates = buildBinCandidates(packageName, binName);
207
- let chosenBinName: string | undefined;
208
- let binRel: string | undefined;
209
-
210
- if (typeof binField === "string") {
211
- chosenBinName = defaultBinName(packageName);
212
- binRel = binField;
213
- } else {
214
- for (const candidate of candidates) {
215
- if (binField[candidate]) {
216
- chosenBinName = candidate;
217
- binRel = binField[candidate];
218
- break;
219
- }
220
- }
221
- if (!binRel) {
222
- const firstEntry = Object.entries(binField)[0];
223
- if (firstEntry) {
224
- chosenBinName = firstEntry[0];
225
- binRel = firstEntry[1];
226
- }
227
- }
228
- }
229
-
230
- if (!binRel) return null;
231
-
232
- const nodeModulesDir = findNodeModulesDir(packageDir);
233
- const binLink = chosenBinName ? join(nodeModulesDir, ".bin", chosenBinName) : null;
234
- let resolvedBin = binLink && existsSync(binLink) ? safeRealpath(binLink) : "";
235
- if (!resolvedBin) {
236
- resolvedBin = resolve(packageDir, binRel);
237
- if (!existsSync(resolvedBin)) return null;
238
- }
239
-
240
- const isJs = detectJsBinary(resolvedBin);
241
- return {
242
- resolvedBin,
243
- resolvedAt: Date.now(),
244
- ...(pkg?.version !== undefined ? { packageVersion: pkg.version } : {}),
245
- isJs,
246
- };
247
- }
248
-
249
- const FORCE_CACHE_TIMEOUT_MS = 30_000;
250
-
251
- async function forceNpxCache(packageSpec: string, signal?: AbortSignal): Promise<void> {
252
- throwIfAborted(signal);
253
- try {
254
- await new Promise<void>((resolve, reject) => {
255
- const proc = crossSpawn(
256
- "npm",
257
- ["exec", "--yes", "--package", packageSpec, "--", "node", "-e", "1"],
258
- { stdio: "ignore" }
259
- );
260
- const timer = setTimeout(() => {
261
- proc.kill();
262
- reject(new Error("timeout"));
263
- }, FORCE_CACHE_TIMEOUT_MS);
264
- const abort = () => {
265
- proc.kill();
266
- reject(signal?.reason instanceof Error ? signal.reason : new Error("MCP request aborted"));
267
- };
268
- signal?.addEventListener("abort", abort, { once: true });
269
- timer.unref();
270
- proc.on("close", () => {
271
- clearTimeout(timer);
272
- signal?.removeEventListener("abort", abort);
273
- resolve();
274
- });
275
- proc.on("error", (err) => {
276
- clearTimeout(timer);
277
- signal?.removeEventListener("abort", abort);
278
- reject(err);
279
- });
280
- });
281
- } catch (error) {
282
- if (signal?.aborted) throwIfAborted(signal);
283
- // Ignore failures, resolution will fall back to original command
284
- }
285
- throwIfAborted(signal);
286
- }
287
-
288
- function buildBinCandidates(packageName: string, explicitBin?: string): string[] {
289
- const candidates: string[] = [];
290
- if (explicitBin) candidates.push(explicitBin);
291
-
292
- if (packageName.startsWith("@")) {
293
- const namePart = packageName.split("/")[1] ?? "";
294
- const scopePart = packageName.split("/")[0]?.replace("@", "") ?? "";
295
- if (namePart) candidates.push(namePart);
296
- if (scopePart && namePart) candidates.push(`${scopePart}-${namePart}`);
297
- } else {
298
- candidates.push(packageName);
299
- }
300
-
301
- return [...new Set(candidates.filter(Boolean))];
302
- }
303
-
304
- function parsePackageSpec(spec: string): ParsedPackageSpec | null {
305
- const trimmed = spec.trim();
306
- if (!trimmed) return null;
307
-
308
- let packageName: string;
309
- let requestedVersion: string | undefined;
310
- if (trimmed.startsWith("@")) {
311
- const slashIndex = trimmed.indexOf("/");
312
- if (slashIndex < 0) return null;
313
- const atIndex = trimmed.lastIndexOf("@");
314
- if (atIndex > slashIndex) {
315
- packageName = trimmed.slice(0, atIndex);
316
- requestedVersion = trimmed.slice(atIndex + 1);
317
- } else {
318
- packageName = trimmed;
319
- }
320
- } else {
321
- const atIndex = trimmed.indexOf("@");
322
- if (atIndex >= 0) {
323
- packageName = trimmed.slice(0, atIndex);
324
- requestedVersion = trimmed.slice(atIndex + 1);
325
- } else {
326
- packageName = trimmed;
327
- }
328
- }
329
-
330
- if (!packageName) return null;
331
- const normalizedVersion = requestedVersion?.replace(/^=/, "").replace(/^v/i, "");
332
- return {
333
- packageName,
334
- ...(normalizedVersion && EXACT_PACKAGE_VERSION_RE.test(normalizedVersion)
335
- ? { exactVersion: normalizedVersion }
336
- : {}),
337
- };
338
- }
339
-
340
- function defaultBinName(packageName: string): string {
341
- if (packageName.startsWith("@")) {
342
- const parts = packageName.split("/");
343
- return parts[1] ?? packageName.replace("@", "").replace("/", "-");
344
- }
345
- return packageName;
346
- }
347
-
348
- function findCachedPackageDir(cacheDir: string, packageName: string, exactVersion?: string): string | null {
349
- const npxDir = join(cacheDir, "_npx");
350
- if (!existsSync(npxDir)) return null;
351
-
352
- const packagePathParts = packageName.startsWith("@")
353
- ? packageName.split("/")
354
- : [packageName];
355
-
356
- const candidates = readdirSync(npxDir, { withFileTypes: true })
357
- .filter(entry => entry.isDirectory())
358
- .map(entry => {
359
- const full = join(npxDir, entry.name);
360
- const mtime = safeStatMtime(full);
361
- return { name: entry.name, mtime };
362
- })
363
- .sort((a, b) => b.mtime - a.mtime);
364
-
365
- for (const entry of candidates) {
366
- const pkgDir = join(npxDir, entry.name, "node_modules", ...packagePathParts);
367
- const packageJsonPath = join(pkgDir, "package.json");
368
- if (!existsSync(packageJsonPath)) continue;
369
- if (exactVersion) {
370
- try {
371
- const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as { version?: unknown };
372
- if (pkg.version !== exactVersion) continue;
373
- } catch {
374
- continue;
375
- }
376
- }
377
- return pkgDir;
378
- }
379
-
380
- return null;
381
- }
382
-
383
- function findNodeModulesDir(packageDir: string): string {
384
- const parts = packageDir.split(sep);
385
- const idx = parts.lastIndexOf("node_modules");
386
- if (idx >= 0) {
387
- return parts.slice(0, idx + 1).join(sep);
388
- }
389
- return join(packageDir, "..");
390
- }
391
-
392
- function detectJsBinary(binPath: string): boolean {
393
- const ext = extname(binPath).toLowerCase();
394
- if (ext === ".js" || ext === ".mjs" || ext === ".cjs") return true;
395
- try {
396
- const fd = openSync(binPath, "r");
397
- try {
398
- const buf = Buffer.alloc(256);
399
- readSync(fd, buf, 0, 256, 0);
400
- const firstLine = buf.toString("utf-8").split("\n")[0] ?? "";
401
- return firstLine.startsWith("#!") && firstLine.includes("node");
402
- } finally {
403
- closeSync(fd);
404
- }
405
- } catch {
406
- return false;
407
- }
408
- }
409
-
410
- let npmCacheDirCached: string | null | undefined;
411
-
412
- function getNpmCacheDir(): string | null {
413
- if (npmCacheDirCached !== undefined) return npmCacheDirCached;
414
- if (process.env.NPM_CONFIG_CACHE) {
415
- npmCacheDirCached = process.env.NPM_CONFIG_CACHE;
416
- return npmCacheDirCached;
417
- }
418
- try {
419
- const result = crossSpawn.sync("npm", ["config", "get", "cache"], { encoding: "utf-8" });
420
- if (result.status === 0) {
421
- const path = String(result.stdout).trim();
422
- npmCacheDirCached = path || null;
423
- return npmCacheDirCached;
424
- }
425
- } catch {
426
- npmCacheDirCached = null;
427
- return null;
428
- }
429
- npmCacheDirCached = null;
430
- return null;
431
- }
432
-
433
- function getNpxCachePath(): string {
434
- return getAdapterPath("mcp-npx-cache.json");
435
- }
436
-
437
- function loadCache(): NpxCache | null {
438
- const cachePath = getNpxCachePath();
439
- if (!existsSync(cachePath)) return null;
440
- try {
441
- const raw = JSON.parse(readFileSync(cachePath, "utf-8"));
442
- if (!raw || typeof raw !== "object") return null;
443
- if (raw.version !== CACHE_VERSION) return null;
444
- if (!raw.entries || typeof raw.entries !== "object") return null;
445
- return raw as NpxCache;
446
- } catch {
447
- return null;
448
- }
449
- }
450
-
451
- function saveCacheEntry(key: string, entry: NpxCacheEntry): void {
452
- const cachePath = getNpxCachePath();
453
- const dir = dirname(cachePath);
454
- mkdirSync(dir, { recursive: true });
455
-
456
- let merged: NpxCache = { version: CACHE_VERSION, entries: {} };
457
- try {
458
- if (existsSync(cachePath)) {
459
- const existing = JSON.parse(readFileSync(cachePath, "utf-8")) as NpxCache;
460
- if (existing && existing.version === CACHE_VERSION && existing.entries) {
461
- merged.entries = { ...existing.entries };
462
- }
463
- }
464
- } catch {
465
- // Ignore parse errors
466
- }
467
-
468
- merged.entries[key] = entry;
469
- const tmpPath = `${cachePath}.${process.pid}.tmp`;
470
- writeFileSync(tmpPath, JSON.stringify(merged, null, 2), "utf-8");
471
- renameSync(tmpPath, cachePath);
472
- }
473
-
474
- function safeRealpath(path: string): string {
475
- try {
476
- return realpathSync(path);
477
- } catch {
478
- return "";
479
- }
480
- }
481
-
482
- function safeStatMtime(path: string): number {
483
- try {
484
- return statSync(path).mtimeMs;
485
- } catch {
486
- return 0;
487
- }
488
- }
@@ -1,58 +0,0 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync } from "node:fs";
2
- import { dirname } from "node:path";
3
- import { getAdapterPath } from "./agent-dir.ts";
4
-
5
- export interface McpOnboardingState {
6
- version: 1;
7
- sharedConfigHintShown: boolean;
8
- setupCompleted: boolean;
9
- }
10
-
11
- const DEFAULT_STATE: McpOnboardingState = {
12
- version: 1,
13
- sharedConfigHintShown: false,
14
- setupCompleted: false,
15
- };
16
-
17
- export function getOnboardingStatePath(): string {
18
- return getAdapterPath("mcp-onboarding.json");
19
- }
20
-
21
- export function loadOnboardingState(): McpOnboardingState {
22
- const path = getOnboardingStatePath();
23
- if (!existsSync(path)) return { ...DEFAULT_STATE };
24
-
25
- try {
26
- const raw = JSON.parse(readFileSync(path, "utf-8")) as Partial<McpOnboardingState>;
27
- if (!raw || typeof raw !== "object") return { ...DEFAULT_STATE };
28
- return {
29
- version: 1,
30
- sharedConfigHintShown: raw.sharedConfigHintShown === true,
31
- setupCompleted: raw.setupCompleted === true,
32
- };
33
- } catch {
34
- return { ...DEFAULT_STATE };
35
- }
36
- }
37
-
38
- export function saveOnboardingState(state: McpOnboardingState): void {
39
- const path = getOnboardingStatePath();
40
- mkdirSync(dirname(path), { recursive: true });
41
- const tmpPath = `${path}.${process.pid}.tmp`;
42
- writeFileSync(tmpPath, `${JSON.stringify(state, null, 2)}\n`, "utf-8");
43
- renameSync(tmpPath, path);
44
- }
45
-
46
- export function updateOnboardingState(updater: (state: McpOnboardingState) => McpOnboardingState): McpOnboardingState {
47
- const next = updater(loadOnboardingState());
48
- saveOnboardingState(next);
49
- return next;
50
- }
51
-
52
- export function markSharedConfigHintShown(): McpOnboardingState {
53
- return updateOnboardingState((state) => ({ ...state, sharedConfigHintShown: true }));
54
- }
55
-
56
- export function markSetupCompleted(): McpOnboardingState {
57
- return updateOnboardingState((state) => ({ ...state, setupCompleted: true }));
58
- }
package/panel-keys.ts DELETED
@@ -1,37 +0,0 @@
1
- import { matchesKey } from "@earendil-works/pi-tui";
2
-
3
- /** The `tui.select.*` keybinding ids the adapter panels resolve. */
4
- export type PanelSelectKeybinding =
5
- | "tui.select.up"
6
- | "tui.select.down"
7
- | "tui.select.confirm";
8
-
9
- /** Structural subset of pi-tui's `KeybindingsManager` (which satisfies it). */
10
- export interface PanelKeybindings {
11
- matches(data: string, keybinding: PanelSelectKeybinding): boolean;
12
- }
13
-
14
- /**
15
- * Key matchers for list navigation: user's `tui.select.*` bindings when a
16
- * manager is provided, otherwise the previous hardcoded defaults.
17
- */
18
- export interface PanelKeys {
19
- selectUp(data: string): boolean;
20
- selectDown(data: string): boolean;
21
- selectConfirm(data: string): boolean;
22
- }
23
-
24
- export function createPanelKeys(keybindings?: PanelKeybindings): PanelKeys {
25
- if (keybindings) {
26
- return {
27
- selectUp: (data) => keybindings.matches(data, "tui.select.up"),
28
- selectDown: (data) => keybindings.matches(data, "tui.select.down"),
29
- selectConfirm: (data) => keybindings.matches(data, "tui.select.confirm"),
30
- };
31
- }
32
- return {
33
- selectUp: (data) => matchesKey(data, "up"),
34
- selectDown: (data) => matchesKey(data, "down"),
35
- selectConfirm: (data) => matchesKey(data, "return"),
36
- };
37
- }