@ken-jo/agent-connector 0.1.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/LICENSE +202 -0
- package/NOTICE +6 -0
- package/README.md +348 -0
- package/dist/amp-QSFH2V7Y.js +217 -0
- package/dist/amp-QSFH2V7Y.js.map +1 -0
- package/dist/amp-TULUPXXL.js +237 -0
- package/dist/amp-TULUPXXL.js.map +1 -0
- package/dist/antigravity-CX2YLSY7.js +17 -0
- package/dist/antigravity-CX2YLSY7.js.map +1 -0
- package/dist/antigravity-STHZWMP3.js +171 -0
- package/dist/antigravity-STHZWMP3.js.map +1 -0
- package/dist/antigravity-cli-P6HADOAO.js +121 -0
- package/dist/antigravity-cli-P6HADOAO.js.map +1 -0
- package/dist/antigravity-cli-YQDFVV4U.js +86 -0
- package/dist/antigravity-cli-YQDFVV4U.js.map +1 -0
- package/dist/chunk-54EMKTTX.js +191 -0
- package/dist/chunk-54EMKTTX.js.map +1 -0
- package/dist/chunk-7L6ITC4T.js +54 -0
- package/dist/chunk-7L6ITC4T.js.map +1 -0
- package/dist/chunk-7MSDGHJW.js +316 -0
- package/dist/chunk-7MSDGHJW.js.map +1 -0
- package/dist/chunk-BCHWFTV4.js +196 -0
- package/dist/chunk-BCHWFTV4.js.map +1 -0
- package/dist/chunk-DBQMX75U.js +36 -0
- package/dist/chunk-DBQMX75U.js.map +1 -0
- package/dist/chunk-EXLS7BSI.js +29 -0
- package/dist/chunk-EXLS7BSI.js.map +1 -0
- package/dist/chunk-JNM3TPLX.js +593 -0
- package/dist/chunk-JNM3TPLX.js.map +1 -0
- package/dist/chunk-JWNT5KW7.js +197 -0
- package/dist/chunk-JWNT5KW7.js.map +1 -0
- package/dist/chunk-KHO5WNTP.js +30 -0
- package/dist/chunk-KHO5WNTP.js.map +1 -0
- package/dist/chunk-LTT56GI3.js +155 -0
- package/dist/chunk-LTT56GI3.js.map +1 -0
- package/dist/chunk-MEH7GC7R.js +111 -0
- package/dist/chunk-MEH7GC7R.js.map +1 -0
- package/dist/chunk-MQPNU2CY.js +64 -0
- package/dist/chunk-MQPNU2CY.js.map +1 -0
- package/dist/chunk-OPXAP3AC.js +12 -0
- package/dist/chunk-OPXAP3AC.js.map +1 -0
- package/dist/chunk-RK6VBLXP.js +50 -0
- package/dist/chunk-RK6VBLXP.js.map +1 -0
- package/dist/chunk-TIIP3RG2.js +420 -0
- package/dist/chunk-TIIP3RG2.js.map +1 -0
- package/dist/chunk-TRKWUNO4.js +702 -0
- package/dist/chunk-TRKWUNO4.js.map +1 -0
- package/dist/chunk-TRQKHP7D.js +93 -0
- package/dist/chunk-TRQKHP7D.js.map +1 -0
- package/dist/chunk-WCETQWWK.js +59 -0
- package/dist/chunk-WCETQWWK.js.map +1 -0
- package/dist/chunk-WV63X7IK.js +357 -0
- package/dist/chunk-WV63X7IK.js.map +1 -0
- package/dist/chunk-XD7MY6HB.js +343 -0
- package/dist/chunk-XD7MY6HB.js.map +1 -0
- package/dist/chunk-XNAM7F35.js +276 -0
- package/dist/chunk-XNAM7F35.js.map +1 -0
- package/dist/chunk-XUCWLJY5.js +238 -0
- package/dist/chunk-XUCWLJY5.js.map +1 -0
- package/dist/chunk-YNZU6PAV.js +800 -0
- package/dist/chunk-YNZU6PAV.js.map +1 -0
- package/dist/chunk-YT43MUSJ.js +146 -0
- package/dist/chunk-YT43MUSJ.js.map +1 -0
- package/dist/claude-code-HKDV7T32.js +637 -0
- package/dist/claude-code-HKDV7T32.js.map +1 -0
- package/dist/claude-code-W74MNTAC.js +652 -0
- package/dist/claude-code-W74MNTAC.js.map +1 -0
- package/dist/cli/sdk.d.ts +54 -0
- package/dist/cli/sdk.js +82 -0
- package/dist/cli/sdk.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -0
- package/dist/codebuff-3PMZJJHP.js +307 -0
- package/dist/codebuff-3PMZJJHP.js.map +1 -0
- package/dist/codebuff-QX57FJDN.js +220 -0
- package/dist/codebuff-QX57FJDN.js.map +1 -0
- package/dist/codex-JFQTS6LU.js +593 -0
- package/dist/codex-JFQTS6LU.js.map +1 -0
- package/dist/codex-Q3ATRRX3.js +364 -0
- package/dist/codex-Q3ATRRX3.js.map +1 -0
- package/dist/copilot-cli-MTCGHZ2T.js +622 -0
- package/dist/copilot-cli-MTCGHZ2T.js.map +1 -0
- package/dist/copilot-cli-SJGIXVSD.js +369 -0
- package/dist/copilot-cli-SJGIXVSD.js.map +1 -0
- package/dist/crush-I7PK3FGI.js +360 -0
- package/dist/crush-I7PK3FGI.js.map +1 -0
- package/dist/crush-LN5QFFR2.js +183 -0
- package/dist/crush-LN5QFFR2.js.map +1 -0
- package/dist/cursor-4TMXKJOZ.js +603 -0
- package/dist/cursor-4TMXKJOZ.js.map +1 -0
- package/dist/cursor-QZ6MTO74.js +194 -0
- package/dist/cursor-QZ6MTO74.js.map +1 -0
- package/dist/detect-WIAGVYS4.js +68 -0
- package/dist/detect-WIAGVYS4.js.map +1 -0
- package/dist/doctor-EZW2K4NI.js +372 -0
- package/dist/doctor-EZW2K4NI.js.map +1 -0
- package/dist/droid-KN6VRMMT.js +424 -0
- package/dist/droid-KN6VRMMT.js.map +1 -0
- package/dist/droid-W5WF5XEX.js +224 -0
- package/dist/droid-W5WF5XEX.js.map +1 -0
- package/dist/gemini-cli-CIRW37TU.js +369 -0
- package/dist/gemini-cli-CIRW37TU.js.map +1 -0
- package/dist/gemini-cli-Y35FFK4M.js +705 -0
- package/dist/gemini-cli-Y35FFK4M.js.map +1 -0
- package/dist/goose-A3M5GODH.js +212 -0
- package/dist/goose-A3M5GODH.js.map +1 -0
- package/dist/goose-ZTGTSUFJ.js +480 -0
- package/dist/goose-ZTGTSUFJ.js.map +1 -0
- package/dist/hermes-H2KV44GK.js +470 -0
- package/dist/hermes-H2KV44GK.js.map +1 -0
- package/dist/hermes-ZYLMOFLZ.js +196 -0
- package/dist/hermes-ZYLMOFLZ.js.map +1 -0
- package/dist/hook-YVDILAMZ.js +75 -0
- package/dist/hook-YVDILAMZ.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/install-HQRYZOQ2.js +60 -0
- package/dist/install-HQRYZOQ2.js.map +1 -0
- package/dist/jetbrains-copilot-HWA3DMH7.js +633 -0
- package/dist/jetbrains-copilot-HWA3DMH7.js.map +1 -0
- package/dist/kilo-NSWAVP6P.js +235 -0
- package/dist/kilo-NSWAVP6P.js.map +1 -0
- package/dist/kilo-QXJRCSLT.js +384 -0
- package/dist/kilo-QXJRCSLT.js.map +1 -0
- package/dist/kilo-cli-EAQTHXUW.js +587 -0
- package/dist/kilo-cli-EAQTHXUW.js.map +1 -0
- package/dist/kilo-cli-EVBKUODA.js +160 -0
- package/dist/kilo-cli-EVBKUODA.js.map +1 -0
- package/dist/kimi-EI3UM3ZV.js +155 -0
- package/dist/kimi-EI3UM3ZV.js.map +1 -0
- package/dist/kimi-GQ7VXNYT.js +423 -0
- package/dist/kimi-GQ7VXNYT.js.map +1 -0
- package/dist/kiro-UCLSLBW2.js +217 -0
- package/dist/kiro-UCLSLBW2.js.map +1 -0
- package/dist/kiro-VQTT6LO2.js +451 -0
- package/dist/kiro-VQTT6LO2.js.map +1 -0
- package/dist/leaderboard-K6ON3SWW.js +137 -0
- package/dist/leaderboard-K6ON3SWW.js.map +1 -0
- package/dist/mux-T2TV4CIQ.js +211 -0
- package/dist/mux-T2TV4CIQ.js.map +1 -0
- package/dist/mux-ZMLVAXOO.js +96 -0
- package/dist/mux-ZMLVAXOO.js.map +1 -0
- package/dist/omp-PB4VDKS6.js +586 -0
- package/dist/omp-PB4VDKS6.js.map +1 -0
- package/dist/openclaw-ETN2M63O.js +751 -0
- package/dist/openclaw-ETN2M63O.js.map +1 -0
- package/dist/openclaw-IYA7ASL6.js +150 -0
- package/dist/openclaw-IYA7ASL6.js.map +1 -0
- package/dist/opencode-FZ33JKUZ.js +734 -0
- package/dist/opencode-FZ33JKUZ.js.map +1 -0
- package/dist/opencode-HWT3RSMN.js +216 -0
- package/dist/opencode-HWT3RSMN.js.map +1 -0
- package/dist/package-DLOVE2E4.js +1132 -0
- package/dist/package-DLOVE2E4.js.map +1 -0
- package/dist/pi-CIU2QHT4.js +208 -0
- package/dist/pi-CIU2QHT4.js.map +1 -0
- package/dist/pi-UFX2OYFV.js +139 -0
- package/dist/pi-UFX2OYFV.js.map +1 -0
- package/dist/qwen-code-5POCNU6P.js +573 -0
- package/dist/qwen-code-5POCNU6P.js.map +1 -0
- package/dist/qwen-code-W7NUCDEN.js +134 -0
- package/dist/qwen-code-W7NUCDEN.js.map +1 -0
- package/dist/roo-code-IOIUXRDE.js +242 -0
- package/dist/roo-code-IOIUXRDE.js.map +1 -0
- package/dist/roo-code-ZLKH4A7N.js +229 -0
- package/dist/roo-code-ZLKH4A7N.js.map +1 -0
- package/dist/runtime/index.d.ts +157 -0
- package/dist/runtime/index.js +20 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/serve-HVWWY4B6.js +65 -0
- package/dist/serve-HVWWY4B6.js.map +1 -0
- package/dist/status-FE7TECZD.js +128 -0
- package/dist/status-FE7TECZD.js.map +1 -0
- package/dist/synthetic-UKR6SMGS.js +178 -0
- package/dist/synthetic-UKR6SMGS.js.map +1 -0
- package/dist/telemetry-36GESKQQ.js +349 -0
- package/dist/telemetry-36GESKQQ.js.map +1 -0
- package/dist/trae-JSNDZFKL.js +204 -0
- package/dist/trae-JSNDZFKL.js.map +1 -0
- package/dist/trae-PA26DPBW.js +157 -0
- package/dist/trae-PA26DPBW.js.map +1 -0
- package/dist/types-CYUB1OTr.d.ts +427 -0
- package/dist/uninstall-IGCKNOSF.js +72 -0
- package/dist/uninstall-IGCKNOSF.js.map +1 -0
- package/dist/upgrade-JV2VK242.js +104 -0
- package/dist/upgrade-JV2VK242.js.map +1 -0
- package/dist/usage-6ER6EMEY.js +324 -0
- package/dist/usage-6ER6EMEY.js.map +1 -0
- package/dist/usage-event-JKBI6XCF.js +48 -0
- package/dist/usage-event-JKBI6XCF.js.map +1 -0
- package/dist/vscode-copilot-CK3NO54M.js +715 -0
- package/dist/vscode-copilot-CK3NO54M.js.map +1 -0
- package/dist/warp-JNQA7PBU.js +126 -0
- package/dist/warp-JNQA7PBU.js.map +1 -0
- package/dist/warp-QNVDXOG4.js +199 -0
- package/dist/warp-QNVDXOG4.js.map +1 -0
- package/dist/zed-NNNX5MNT.js +272 -0
- package/dist/zed-NNNX5MNT.js.map +1 -0
- package/dist/zed-VRJKWYUR.js +209 -0
- package/dist/zed-VRJKWYUR.js.map +1 -0
- package/package.json +79 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
renderFrontmatterMd
|
|
4
|
+
} from "./chunk-7L6ITC4T.js";
|
|
5
|
+
import {
|
|
6
|
+
backupsDir,
|
|
7
|
+
ensureDir
|
|
8
|
+
} from "./chunk-TRQKHP7D.js";
|
|
9
|
+
|
|
10
|
+
// src/core/jsonc.ts
|
|
11
|
+
function stripJsonc(text) {
|
|
12
|
+
const n = text.length;
|
|
13
|
+
let out = "";
|
|
14
|
+
let i = 0;
|
|
15
|
+
let inString = false;
|
|
16
|
+
let quote = "";
|
|
17
|
+
while (i < n) {
|
|
18
|
+
const ch = text[i];
|
|
19
|
+
if (inString) {
|
|
20
|
+
out += ch;
|
|
21
|
+
if (ch === "\\") {
|
|
22
|
+
if (i + 1 < n) {
|
|
23
|
+
out += text[i + 1];
|
|
24
|
+
i += 2;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
} else if (ch === quote) {
|
|
28
|
+
inString = false;
|
|
29
|
+
}
|
|
30
|
+
i += 1;
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const next = i + 1 < n ? text[i + 1] : "";
|
|
34
|
+
if (ch === '"' || ch === "'") {
|
|
35
|
+
inString = true;
|
|
36
|
+
quote = ch;
|
|
37
|
+
out += ch;
|
|
38
|
+
i += 1;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (ch === "/" && next === "/") {
|
|
42
|
+
i += 2;
|
|
43
|
+
while (i < n && text[i] !== "\n") i += 1;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (ch === "/" && next === "*") {
|
|
47
|
+
i += 2;
|
|
48
|
+
while (i < n && !(text[i] === "*" && text[i + 1] === "/")) i += 1;
|
|
49
|
+
i += 2;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (ch === ",") {
|
|
53
|
+
const closer = nextSignificant(text, i + 1);
|
|
54
|
+
if (closer === "}" || closer === "]") {
|
|
55
|
+
i += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
out += ch;
|
|
60
|
+
i += 1;
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
function nextSignificant(text, from) {
|
|
65
|
+
const n = text.length;
|
|
66
|
+
let i = from;
|
|
67
|
+
while (i < n) {
|
|
68
|
+
const ch = text[i];
|
|
69
|
+
if (ch === " " || ch === " " || ch === "\r" || ch === "\n") {
|
|
70
|
+
i += 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const next = i + 1 < n ? text[i + 1] : "";
|
|
74
|
+
if (ch === "/" && next === "/") {
|
|
75
|
+
i += 2;
|
|
76
|
+
while (i < n && text[i] !== "\n") i += 1;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (ch === "/" && next === "*") {
|
|
80
|
+
i += 2;
|
|
81
|
+
while (i < n && !(text[i] === "*" && text[i + 1] === "/")) i += 1;
|
|
82
|
+
i += 2;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
return ch;
|
|
86
|
+
}
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
function parseJsonc(text) {
|
|
90
|
+
return JSON.parse(stripJsonc(text));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/adapters/base.ts
|
|
94
|
+
import {
|
|
95
|
+
copyFileSync,
|
|
96
|
+
existsSync,
|
|
97
|
+
readdirSync,
|
|
98
|
+
readFileSync,
|
|
99
|
+
rmSync,
|
|
100
|
+
statSync,
|
|
101
|
+
writeFileSync
|
|
102
|
+
} from "fs";
|
|
103
|
+
import { basename, dirname, join, relative, resolve, sep } from "path";
|
|
104
|
+
var BaseAdapter = class {
|
|
105
|
+
// ── Content surfaces (commands / skills / subagents) ─────────────────────
|
|
106
|
+
// CONCRETE (overridable) defaults so every adapter inherits all six methods
|
|
107
|
+
// and the installer can call them without optional-chaining. Each returns a
|
|
108
|
+
// single skip when the connector declares no entries of that surface, else a
|
|
109
|
+
// single "warn" — mirroring the mcp-only hook handling. Supporting adapters
|
|
110
|
+
// override only the surfaces they honor.
|
|
111
|
+
installCommands(ctx) {
|
|
112
|
+
return this.unsupportedSurface(ctx, "commands", ctx.connector.commands.length);
|
|
113
|
+
}
|
|
114
|
+
uninstallCommands(ctx) {
|
|
115
|
+
return this.unsupportedSurface(ctx, "commands", ctx.connector.commands.length);
|
|
116
|
+
}
|
|
117
|
+
installSkills(ctx) {
|
|
118
|
+
return this.unsupportedSurface(ctx, "skills", ctx.connector.skills.length);
|
|
119
|
+
}
|
|
120
|
+
uninstallSkills(ctx) {
|
|
121
|
+
return this.unsupportedSurface(ctx, "skills", ctx.connector.skills.length);
|
|
122
|
+
}
|
|
123
|
+
installSubagents(ctx) {
|
|
124
|
+
return this.unsupportedSurface(ctx, "subagents", ctx.connector.subagents.length);
|
|
125
|
+
}
|
|
126
|
+
uninstallSubagents(ctx) {
|
|
127
|
+
return this.unsupportedSurface(ctx, "subagents", ctx.connector.subagents.length);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Default response for a content surface this platform cannot honor: a single
|
|
131
|
+
* skip when the connector declares none of that surface, else a single "warn"
|
|
132
|
+
* ChangeRecord noting how many were skipped. Mirrors mcp-only hook handling.
|
|
133
|
+
*/
|
|
134
|
+
unsupportedSurface(_ctx, surface, count) {
|
|
135
|
+
if (count === 0) {
|
|
136
|
+
return [{ platform: this.id, action: "skip", detail: `connector declares no ${surface}` }];
|
|
137
|
+
}
|
|
138
|
+
return [
|
|
139
|
+
{
|
|
140
|
+
platform: this.id,
|
|
141
|
+
action: "warn",
|
|
142
|
+
detail: `${surface} not supported on ${this.id}; ${count} skipped`
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
// ── Content-file helpers (used by surface-supporting adapters) ────────────
|
|
147
|
+
/**
|
|
148
|
+
* Write a content file idempotently: "skip" when the existing bytes are
|
|
149
|
+
* already identical, else "create"/"update". Creates parent dirs (mkdir -p).
|
|
150
|
+
* Honors dryRun (computes the action but writes nothing).
|
|
151
|
+
*/
|
|
152
|
+
writeContentFile(path, contents, dryRun) {
|
|
153
|
+
let action;
|
|
154
|
+
if (!existsSync(path)) {
|
|
155
|
+
action = "create";
|
|
156
|
+
} else {
|
|
157
|
+
let current = null;
|
|
158
|
+
try {
|
|
159
|
+
current = readFileSync(path, "utf8");
|
|
160
|
+
} catch {
|
|
161
|
+
current = null;
|
|
162
|
+
}
|
|
163
|
+
action = current === contents ? "skip" : "update";
|
|
164
|
+
}
|
|
165
|
+
if (action !== "skip" && !dryRun) {
|
|
166
|
+
ensureDir(dirname(path));
|
|
167
|
+
writeFileSync(path, contents, "utf8");
|
|
168
|
+
}
|
|
169
|
+
return { platform: this.id, action, path, detail: basename(path) };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Remove a content file we wrote; "skip" when already absent. Honors dryRun.
|
|
173
|
+
* Uses rmSync with `force` to also tolerate a path that is a directory tree
|
|
174
|
+
* (e.g. a skill folder removed by the supporting adapter).
|
|
175
|
+
*/
|
|
176
|
+
removeContentFile(path, dryRun) {
|
|
177
|
+
if (!existsSync(path)) {
|
|
178
|
+
return { platform: this.id, action: "skip", path, detail: `${basename(path)} absent` };
|
|
179
|
+
}
|
|
180
|
+
if (!dryRun) {
|
|
181
|
+
rmSync(path, { recursive: true, force: true });
|
|
182
|
+
}
|
|
183
|
+
return { platform: this.id, action: "remove", path, detail: basename(path) };
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Defense-in-depth path containment: resolve `rel` against `baseDir` and
|
|
187
|
+
* return the absolute path ONLY when it stays inside `baseDir`. Returns null
|
|
188
|
+
* when `rel` escapes (absolute path, `..` traversal, etc.) so a caller can
|
|
189
|
+
* skip-and-warn rather than write/delete outside the surface dir. This is the
|
|
190
|
+
* runtime backstop behind the config-time validation in normalizeSkills.
|
|
191
|
+
*/
|
|
192
|
+
resolveWithin(baseDir, rel) {
|
|
193
|
+
const base = resolve(baseDir);
|
|
194
|
+
const target = resolve(base, rel);
|
|
195
|
+
if (target === base) return null;
|
|
196
|
+
const rind = relative(base, target);
|
|
197
|
+
if (rind === "" || rind.startsWith("..") || resolve(base, rind) !== target) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
if (rind === ".." || rind.startsWith(`..${sep}`)) return null;
|
|
201
|
+
return target;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Recursively report whether a directory tree contains any regular FILE (vs
|
|
205
|
+
* only empty/nested-empty subdirectories). Symlinks count as files (we never
|
|
206
|
+
* recurse through them). Used by removeDirIfEmpty to decide if a tree is safe
|
|
207
|
+
* to drop. An unreadable entry is treated as "a file is present" (conservative).
|
|
208
|
+
*/
|
|
209
|
+
dirTreeHasFile(dir) {
|
|
210
|
+
let entries;
|
|
211
|
+
try {
|
|
212
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
213
|
+
} catch {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
for (const e of entries) {
|
|
217
|
+
if (e.isDirectory()) {
|
|
218
|
+
if (this.dirTreeHasFile(join(dir, e.name))) return true;
|
|
219
|
+
} else {
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Remove a directory ONLY when its tree holds NO regular files — i.e. it is
|
|
227
|
+
* empty or contains only (nested) empty directories, such as the intermediate
|
|
228
|
+
* dirs our own nested skill resources created. Replaces the unconditional
|
|
229
|
+
* `rm -rf <dir>` that uninstallSkills used to call, which destroyed user-added
|
|
230
|
+
* files / sibling-tool files / shared skill dirs the connector never wrote.
|
|
231
|
+
* When ANY file remains (at any depth) the whole tree is left in place and the
|
|
232
|
+
* skip is noted. Honors dryRun (computes the action but removes nothing). A
|
|
233
|
+
* missing dir is a no-op "skip".
|
|
234
|
+
*/
|
|
235
|
+
removeDirIfEmpty(dir, dryRun) {
|
|
236
|
+
if (!existsSync(dir)) {
|
|
237
|
+
return { platform: this.id, action: "skip", path: dir, detail: `${basename(dir)} absent` };
|
|
238
|
+
}
|
|
239
|
+
let stat;
|
|
240
|
+
try {
|
|
241
|
+
stat = statSync(dir);
|
|
242
|
+
} catch {
|
|
243
|
+
return {
|
|
244
|
+
platform: this.id,
|
|
245
|
+
action: "skip",
|
|
246
|
+
path: dir,
|
|
247
|
+
detail: `${basename(dir)} unreadable; left in place`
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (!stat.isDirectory()) {
|
|
251
|
+
return {
|
|
252
|
+
platform: this.id,
|
|
253
|
+
action: "skip",
|
|
254
|
+
path: dir,
|
|
255
|
+
detail: `${basename(dir)} not a directory; left in place`
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
if (this.dirTreeHasFile(dir)) {
|
|
259
|
+
return {
|
|
260
|
+
platform: this.id,
|
|
261
|
+
action: "skip",
|
|
262
|
+
path: dir,
|
|
263
|
+
detail: `${basename(dir)} still holds files we did not write; left in place`
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
if (!dryRun) {
|
|
267
|
+
try {
|
|
268
|
+
rmSync(dir, { recursive: true, force: true });
|
|
269
|
+
} catch {
|
|
270
|
+
return {
|
|
271
|
+
platform: this.id,
|
|
272
|
+
action: "skip",
|
|
273
|
+
path: dir,
|
|
274
|
+
detail: `${basename(dir)} could not be removed; left in place`
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return { platform: this.id, action: "remove", path: dir, detail: basename(dir) };
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Render a YAML-frontmatter + markdown body document:
|
|
282
|
+
* "---\n" + <yaml> + "---\n\n" + <body> + "\n".
|
|
283
|
+
* Delegates to the shared renderer (adapters/claude-code/render) so every
|
|
284
|
+
* content-file path — adapters AND the plugin packager — emits identical bytes.
|
|
285
|
+
*/
|
|
286
|
+
renderFrontmatterMd(frontmatter, body) {
|
|
287
|
+
return renderFrontmatterMd(frontmatter, body);
|
|
288
|
+
}
|
|
289
|
+
// ── JSON config helpers (used by JSON-format adapters) ───────────────────
|
|
290
|
+
/**
|
|
291
|
+
* Read + parse a JSON/JSONC config file, returning null when it is absent OR
|
|
292
|
+
* unparseable. Parses TOLERANTLY via parseJsonc (strips // and /* *\/ comments
|
|
293
|
+
* and trailing commas) so a perfectly valid JSONC file never false-fails to
|
|
294
|
+
* null — that null is what `?? {}` would otherwise turn into a clobbering
|
|
295
|
+
* overwrite of the user's whole config.
|
|
296
|
+
*/
|
|
297
|
+
readJson(path) {
|
|
298
|
+
if (!existsSync(path)) return null;
|
|
299
|
+
try {
|
|
300
|
+
return parseJsonc(readFileSync(path, "utf8"));
|
|
301
|
+
} catch {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* True when `path` exists and holds non-whitespace content but readJson cannot
|
|
307
|
+
* parse it (even after JSONC stripping). The overwrite guard: writing a
|
|
308
|
+
* `{}`-based config over a present-but-broken settings file would silently
|
|
309
|
+
* destroy the user's data, so callers warn-and-skip instead.
|
|
310
|
+
*/
|
|
311
|
+
isPresentButUnparseable(path) {
|
|
312
|
+
if (!existsSync(path)) return false;
|
|
313
|
+
let raw;
|
|
314
|
+
try {
|
|
315
|
+
if (statSync(path).size === 0) return false;
|
|
316
|
+
raw = readFileSync(path, "utf8");
|
|
317
|
+
} catch {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
if (raw.trim() === "") return false;
|
|
321
|
+
return this.readJson(path) === null;
|
|
322
|
+
}
|
|
323
|
+
writeJson(path, data, dryRun = false) {
|
|
324
|
+
if (dryRun) return;
|
|
325
|
+
ensureDir(dirname(path));
|
|
326
|
+
writeFileSync(path, `${JSON.stringify(data, null, 2)}
|
|
327
|
+
`, "utf8");
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Upsert `entry` at `config[rootKey][serverId]` in a JSON file, creating the
|
|
331
|
+
* file/object as needed. Returns a ChangeRecord describing create/update/skip.
|
|
332
|
+
* Idempotent: an identical entry yields "skip".
|
|
333
|
+
*/
|
|
334
|
+
upsertServerInJson(configPath, rootKey, serverId, entry, dryRun = false) {
|
|
335
|
+
if (this.isPresentButUnparseable(configPath)) {
|
|
336
|
+
return {
|
|
337
|
+
platform: this.id,
|
|
338
|
+
action: "warn",
|
|
339
|
+
path: configPath,
|
|
340
|
+
detail: `existing ${configPath} is not parseable; left untouched (back it up / fix it, then re-run)`
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
const cfg = this.readJson(configPath) ?? {};
|
|
344
|
+
const bucket = cfg[rootKey] ??= {};
|
|
345
|
+
const before = JSON.stringify(bucket[serverId]);
|
|
346
|
+
const after = JSON.stringify(entry);
|
|
347
|
+
let action;
|
|
348
|
+
if (before === void 0) action = "create";
|
|
349
|
+
else if (before === after) action = "skip";
|
|
350
|
+
else action = "update";
|
|
351
|
+
if (action !== "skip") {
|
|
352
|
+
bucket[serverId] = entry;
|
|
353
|
+
this.writeJson(configPath, cfg, dryRun);
|
|
354
|
+
}
|
|
355
|
+
return { platform: this.id, action, path: configPath, detail: `${rootKey}.${serverId}` };
|
|
356
|
+
}
|
|
357
|
+
/** Remove `config[rootKey][serverId]` from a JSON file. */
|
|
358
|
+
removeServerFromJson(configPath, rootKey, serverId, dryRun = false) {
|
|
359
|
+
if (this.isPresentButUnparseable(configPath)) {
|
|
360
|
+
return {
|
|
361
|
+
platform: this.id,
|
|
362
|
+
action: "warn",
|
|
363
|
+
path: configPath,
|
|
364
|
+
detail: `existing ${configPath} is not parseable; left untouched (back it up / fix it, then re-run)`
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
const cfg = this.readJson(configPath);
|
|
368
|
+
const bucket = cfg?.[rootKey];
|
|
369
|
+
if (!cfg || !bucket || !(serverId in bucket)) {
|
|
370
|
+
return { platform: this.id, action: "skip", path: configPath, detail: `${rootKey}.${serverId} absent` };
|
|
371
|
+
}
|
|
372
|
+
delete bucket[serverId];
|
|
373
|
+
this.writeJson(configPath, cfg, dryRun);
|
|
374
|
+
return { platform: this.id, action: "remove", path: configPath, detail: `${rootKey}.${serverId}` };
|
|
375
|
+
}
|
|
376
|
+
// ── Backup ───────────────────────────────────────────────────────────────
|
|
377
|
+
backupSettings(ctx) {
|
|
378
|
+
const files = [.../* @__PURE__ */ new Set([this.getServerConfigPath(ctx), this.getHookConfigPath(ctx)])].filter(
|
|
379
|
+
(f) => existsSync(f)
|
|
380
|
+
);
|
|
381
|
+
if (files.length === 0) return null;
|
|
382
|
+
if (ctx.dryRun) return null;
|
|
383
|
+
ensureDir(backupsDir());
|
|
384
|
+
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
385
|
+
let last = null;
|
|
386
|
+
for (const f of files) {
|
|
387
|
+
const dest = join(backupsDir(), `${this.id}-${stamp}-${basename(f)}`);
|
|
388
|
+
copyFileSync(f, dest);
|
|
389
|
+
last = dest;
|
|
390
|
+
}
|
|
391
|
+
return last;
|
|
392
|
+
}
|
|
393
|
+
doctor(ctx) {
|
|
394
|
+
const results = [];
|
|
395
|
+
const cfg = this.getServerConfigPath(ctx);
|
|
396
|
+
results.push(
|
|
397
|
+
existsSync(cfg) ? { check: `${this.name}: config present`, status: "pass", message: cfg } : {
|
|
398
|
+
check: `${this.name}: config present`,
|
|
399
|
+
status: "warn",
|
|
400
|
+
message: `not found: ${cfg}`,
|
|
401
|
+
fix: `agent-connector install --targets ${this.id}`
|
|
402
|
+
}
|
|
403
|
+
);
|
|
404
|
+
for (const hc of this.getHealthChecks?.(ctx) ?? []) {
|
|
405
|
+
const r = hc.check();
|
|
406
|
+
results.push({
|
|
407
|
+
check: hc.name,
|
|
408
|
+
status: r.status === "OK" ? "pass" : "fail",
|
|
409
|
+
message: r.detail ?? r.status
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
return results;
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
export {
|
|
417
|
+
parseJsonc,
|
|
418
|
+
BaseAdapter
|
|
419
|
+
};
|
|
420
|
+
//# sourceMappingURL=chunk-TIIP3RG2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/jsonc.ts","../src/adapters/base.ts"],"sourcesContent":["/**\n * core/jsonc — tolerant JSONC / JSON5-lite parsing.\n *\n * Many hosts document their config file as JSONC (or JSON5): // line comments,\n * /* *\\/ block comments, and trailing commas are all legal. A strict JSON.parse\n * false-fails such a perfectly valid file → null → and a careless `?? {}` then\n * OVERWRITES the user's entire config with just our entry (data loss). To avoid\n * that, every JSON/JSONC adapter parses through `parseJsonc`, which strips\n * comments + trailing commas in ONE string-aware pass before JSON.parse.\n *\n * The single pass is deliberately string-literal aware: a // or /* inside a\n * quoted value (e.g. \"http://x//y\") is NOT a comment, and a comma inside a\n * string (e.g. \"a,]\") is NOT a trailing comma — both must survive verbatim.\n */\n\n/**\n * Strip // line comments, /* *\\/ block comments, and trailing commas from JSONC\n * text in a SINGLE string-aware pass.\n *\n * Rules:\n * - While inside a string literal, every character (including //, /*, and ,)\n * is copied verbatim; backslash escapes the next character.\n * - Outside a string, // … runs to end-of-line and /* … *\\/ to its close.\n * - A comma is dropped ONLY when the next non-whitespace, non-comment token is\n * a closing `}` or `]` (a trailing comma). A comma followed by another value\n * or by end-of-input is preserved (the latter lets JSON.parse report the\n * real syntax error instead of us masking it).\n */\nexport function stripJsonc(text: string): string {\n const n = text.length;\n let out = \"\";\n let i = 0;\n let inString = false;\n let quote = \"\";\n\n while (i < n) {\n const ch = text[i] as string;\n\n if (inString) {\n out += ch;\n if (ch === \"\\\\\") {\n // Copy the escaped character verbatim (covers \\\" \\\\ \\/ etc.).\n if (i + 1 < n) {\n out += text[i + 1] as string;\n i += 2;\n continue;\n }\n } else if (ch === quote) {\n inString = false;\n }\n i += 1;\n continue;\n }\n\n const next = i + 1 < n ? (text[i + 1] as string) : \"\";\n\n // Enter a string literal.\n if (ch === '\"' || ch === \"'\") {\n inString = true;\n quote = ch;\n out += ch;\n i += 1;\n continue;\n }\n\n // Line comment — skip to end of line (keep the newline for line tracking).\n if (ch === \"/\" && next === \"/\") {\n i += 2;\n while (i < n && text[i] !== \"\\n\") i += 1;\n continue;\n }\n\n // Block comment — skip to the closing */.\n if (ch === \"/\" && next === \"*\") {\n i += 2;\n while (i < n && !(text[i] === \"*\" && text[i + 1] === \"/\")) i += 1;\n i += 2; // consume the closing */\n continue;\n }\n\n // Trailing comma — drop it only when the next significant token (skipping\n // whitespace AND comments) is a closing } or ]. This stays string-aware\n // because we only reach here outside a string.\n if (ch === \",\") {\n const closer = nextSignificant(text, i + 1);\n if (closer === \"}\" || closer === \"]\") {\n i += 1; // drop the trailing comma\n continue;\n }\n }\n\n out += ch;\n i += 1;\n }\n\n return out;\n}\n\n/**\n * Peek the next significant (non-whitespace, non-comment) character at/after\n * `from`, returning \"\" at end-of-input. Used only outside string literals.\n */\nfunction nextSignificant(text: string, from: number): string {\n const n = text.length;\n let i = from;\n while (i < n) {\n const ch = text[i] as string;\n if (ch === \" \" || ch === \"\\t\" || ch === \"\\r\" || ch === \"\\n\") {\n i += 1;\n continue;\n }\n const next = i + 1 < n ? (text[i + 1] as string) : \"\";\n if (ch === \"/\" && next === \"/\") {\n i += 2;\n while (i < n && text[i] !== \"\\n\") i += 1;\n continue;\n }\n if (ch === \"/\" && next === \"*\") {\n i += 2;\n while (i < n && !(text[i] === \"*\" && text[i + 1] === \"/\")) i += 1;\n i += 2;\n continue;\n }\n return ch;\n }\n return \"\";\n}\n\n/**\n * Parse JSONC text tolerantly: strip comments + trailing commas, then JSON.parse.\n * Throws (like JSON.parse) on genuinely malformed input — callers that want a\n * fail-soft null should wrap in try/catch (BaseAdapter.readJson does).\n */\nexport function parseJsonc<T = unknown>(text: string): T {\n return JSON.parse(stripJsonc(text)) as T;\n}\n","/**\n * adapters/base — shared adapter foundation.\n *\n * Provides JSON config IO, settings backup, and a default doctor. Per-platform\n * specifics (paths, capabilities, native render format, runtime parse/format)\n * are abstract and implemented by each adapter. TOML/YAML adapters override the\n * JSON helpers entirely.\n */\n\nimport {\n copyFileSync,\n existsSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport type { Dirent } from \"node:fs\";\nimport { basename, dirname, join, relative, resolve, sep } from \"node:path\";\n\nimport type {\n ChangeRecord,\n DetectedPlatform,\n DiagnosticResult,\n HealthCheck,\n HookParadigm,\n PlatformCapabilities,\n PlatformId,\n} from \"../core/types.js\";\nimport { backupsDir, ensureDir } from \"../core/paths.js\";\nimport { parseJsonc } from \"../core/jsonc.js\";\nimport { renderFrontmatterMd } from \"./claude-code/render.js\";\nimport type { Adapter, InstallContext } from \"./spi.js\";\n\n/** Content-surface kinds with BaseAdapter default install/uninstall handling. */\ntype ContentSurface = \"commands\" | \"skills\" | \"subagents\";\n\nexport abstract class BaseAdapter implements Adapter {\n abstract readonly id: PlatformId;\n abstract readonly name: string;\n abstract readonly paradigm: HookParadigm;\n abstract readonly capabilities: PlatformCapabilities;\n\n abstract detectInstalled(projectDir: string): DetectedPlatform;\n abstract getConfigDir(ctx: InstallContext): string;\n abstract getServerConfigPath(ctx: InstallContext): string;\n abstract getHookConfigPath(ctx: InstallContext): string;\n abstract installServer(ctx: InstallContext): ChangeRecord[];\n abstract uninstallServer(ctx: InstallContext): ChangeRecord[];\n abstract installHooks(ctx: InstallContext): ChangeRecord[];\n abstract uninstallHooks(ctx: InstallContext): ChangeRecord[];\n\n // ── Content surfaces (commands / skills / subagents) ─────────────────────\n // CONCRETE (overridable) defaults so every adapter inherits all six methods\n // and the installer can call them without optional-chaining. Each returns a\n // single skip when the connector declares no entries of that surface, else a\n // single \"warn\" — mirroring the mcp-only hook handling. Supporting adapters\n // override only the surfaces they honor.\n\n installCommands(ctx: InstallContext): ChangeRecord[] {\n return this.unsupportedSurface(ctx, \"commands\", ctx.connector.commands.length);\n }\n uninstallCommands(ctx: InstallContext): ChangeRecord[] {\n return this.unsupportedSurface(ctx, \"commands\", ctx.connector.commands.length);\n }\n installSkills(ctx: InstallContext): ChangeRecord[] {\n return this.unsupportedSurface(ctx, \"skills\", ctx.connector.skills.length);\n }\n uninstallSkills(ctx: InstallContext): ChangeRecord[] {\n return this.unsupportedSurface(ctx, \"skills\", ctx.connector.skills.length);\n }\n installSubagents(ctx: InstallContext): ChangeRecord[] {\n return this.unsupportedSurface(ctx, \"subagents\", ctx.connector.subagents.length);\n }\n uninstallSubagents(ctx: InstallContext): ChangeRecord[] {\n return this.unsupportedSurface(ctx, \"subagents\", ctx.connector.subagents.length);\n }\n\n /**\n * Default response for a content surface this platform cannot honor: a single\n * skip when the connector declares none of that surface, else a single \"warn\"\n * ChangeRecord noting how many were skipped. Mirrors mcp-only hook handling.\n */\n protected unsupportedSurface(\n _ctx: InstallContext,\n surface: ContentSurface,\n count: number,\n ): ChangeRecord[] {\n if (count === 0) {\n return [{ platform: this.id, action: \"skip\", detail: `connector declares no ${surface}` }];\n }\n return [\n {\n platform: this.id,\n action: \"warn\",\n detail: `${surface} not supported on ${this.id}; ${count} skipped`,\n },\n ];\n }\n\n // ── Content-file helpers (used by surface-supporting adapters) ────────────\n\n /**\n * Write a content file idempotently: \"skip\" when the existing bytes are\n * already identical, else \"create\"/\"update\". Creates parent dirs (mkdir -p).\n * Honors dryRun (computes the action but writes nothing).\n */\n protected writeContentFile(path: string, contents: string, dryRun: boolean): ChangeRecord {\n let action: ChangeRecord[\"action\"];\n if (!existsSync(path)) {\n action = \"create\";\n } else {\n let current: string | null = null;\n try {\n current = readFileSync(path, \"utf8\");\n } catch {\n current = null;\n }\n action = current === contents ? \"skip\" : \"update\";\n }\n if (action !== \"skip\" && !dryRun) {\n ensureDir(dirname(path));\n writeFileSync(path, contents, \"utf8\");\n }\n return { platform: this.id, action, path, detail: basename(path) };\n }\n\n /**\n * Remove a content file we wrote; \"skip\" when already absent. Honors dryRun.\n * Uses rmSync with `force` to also tolerate a path that is a directory tree\n * (e.g. a skill folder removed by the supporting adapter).\n */\n protected removeContentFile(path: string, dryRun: boolean): ChangeRecord {\n if (!existsSync(path)) {\n return { platform: this.id, action: \"skip\", path, detail: `${basename(path)} absent` };\n }\n if (!dryRun) {\n rmSync(path, { recursive: true, force: true });\n }\n return { platform: this.id, action: \"remove\", path, detail: basename(path) };\n }\n\n /**\n * Defense-in-depth path containment: resolve `rel` against `baseDir` and\n * return the absolute path ONLY when it stays inside `baseDir`. Returns null\n * when `rel` escapes (absolute path, `..` traversal, etc.) so a caller can\n * skip-and-warn rather than write/delete outside the surface dir. This is the\n * runtime backstop behind the config-time validation in normalizeSkills.\n */\n protected resolveWithin(baseDir: string, rel: string): string | null {\n const base = resolve(baseDir);\n const target = resolve(base, rel);\n if (target === base) return null; // rel resolved to the dir itself (e.g. \"\" / \".\")\n const rind = relative(base, target);\n // Outside when the relative path climbs out (`..`) or is itself absolute.\n if (rind === \"\" || rind.startsWith(\"..\") || resolve(base, rind) !== target) {\n return null;\n }\n if (rind === \"..\" || rind.startsWith(`..${sep}`)) return null;\n return target;\n }\n\n /**\n * Recursively report whether a directory tree contains any regular FILE (vs\n * only empty/nested-empty subdirectories). Symlinks count as files (we never\n * recurse through them). Used by removeDirIfEmpty to decide if a tree is safe\n * to drop. An unreadable entry is treated as \"a file is present\" (conservative).\n */\n private dirTreeHasFile(dir: string): boolean {\n let entries: Dirent[];\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return true; // unreadable → assume it holds data; do not remove\n }\n for (const e of entries) {\n if (e.isDirectory()) {\n if (this.dirTreeHasFile(join(dir, e.name))) return true;\n } else {\n return true; // a file / symlink / special → the tree is not \"empty\"\n }\n }\n return false;\n }\n\n /**\n * Remove a directory ONLY when its tree holds NO regular files — i.e. it is\n * empty or contains only (nested) empty directories, such as the intermediate\n * dirs our own nested skill resources created. Replaces the unconditional\n * `rm -rf <dir>` that uninstallSkills used to call, which destroyed user-added\n * files / sibling-tool files / shared skill dirs the connector never wrote.\n * When ANY file remains (at any depth) the whole tree is left in place and the\n * skip is noted. Honors dryRun (computes the action but removes nothing). A\n * missing dir is a no-op \"skip\".\n */\n protected removeDirIfEmpty(dir: string, dryRun: boolean): ChangeRecord {\n if (!existsSync(dir)) {\n return { platform: this.id, action: \"skip\", path: dir, detail: `${basename(dir)} absent` };\n }\n let stat: ReturnType<typeof statSync>;\n try {\n stat = statSync(dir);\n } catch {\n return {\n platform: this.id,\n action: \"skip\",\n path: dir,\n detail: `${basename(dir)} unreadable; left in place`,\n };\n }\n if (!stat.isDirectory()) {\n return {\n platform: this.id,\n action: \"skip\",\n path: dir,\n detail: `${basename(dir)} not a directory; left in place`,\n };\n }\n if (this.dirTreeHasFile(dir)) {\n return {\n platform: this.id,\n action: \"skip\",\n path: dir,\n detail: `${basename(dir)} still holds files we did not write; left in place`,\n };\n }\n if (!dryRun) {\n try {\n // The tree is files-free: only (possibly nested) empty dirs remain, which\n // are ours / inert. A recursive remove drops them without touching data.\n rmSync(dir, { recursive: true, force: true });\n } catch {\n // Lost a race or perms — non-fatal; report as a skip.\n return {\n platform: this.id,\n action: \"skip\",\n path: dir,\n detail: `${basename(dir)} could not be removed; left in place`,\n };\n }\n }\n return { platform: this.id, action: \"remove\", path: dir, detail: basename(dir) };\n }\n\n /**\n * Render a YAML-frontmatter + markdown body document:\n * \"---\\n\" + <yaml> + \"---\\n\\n\" + <body> + \"\\n\".\n * Delegates to the shared renderer (adapters/claude-code/render) so every\n * content-file path — adapters AND the plugin packager — emits identical bytes.\n */\n protected renderFrontmatterMd(\n frontmatter: Record<string, unknown>,\n body: string,\n ): string {\n return renderFrontmatterMd(frontmatter, body);\n }\n\n // ── JSON config helpers (used by JSON-format adapters) ───────────────────\n\n /**\n * Read + parse a JSON/JSONC config file, returning null when it is absent OR\n * unparseable. Parses TOLERANTLY via parseJsonc (strips // and /* *\\/ comments\n * and trailing commas) so a perfectly valid JSONC file never false-fails to\n * null — that null is what `?? {}` would otherwise turn into a clobbering\n * overwrite of the user's whole config.\n */\n protected readJson<T = Record<string, unknown>>(path: string): T | null {\n if (!existsSync(path)) return null;\n try {\n return parseJsonc<T>(readFileSync(path, \"utf8\"));\n } catch {\n return null;\n }\n }\n\n /**\n * True when `path` exists and holds non-whitespace content but readJson cannot\n * parse it (even after JSONC stripping). The overwrite guard: writing a\n * `{}`-based config over a present-but-broken settings file would silently\n * destroy the user's data, so callers warn-and-skip instead.\n */\n protected isPresentButUnparseable(path: string): boolean {\n if (!existsSync(path)) return false;\n let raw: string;\n try {\n if (statSync(path).size === 0) return false;\n raw = readFileSync(path, \"utf8\");\n } catch {\n return false;\n }\n if (raw.trim() === \"\") return false;\n return this.readJson(path) === null;\n }\n\n protected writeJson(path: string, data: unknown, dryRun = false): void {\n if (dryRun) return;\n ensureDir(dirname(path));\n writeFileSync(path, `${JSON.stringify(data, null, 2)}\\n`, \"utf8\");\n }\n\n /**\n * Upsert `entry` at `config[rootKey][serverId]` in a JSON file, creating the\n * file/object as needed. Returns a ChangeRecord describing create/update/skip.\n * Idempotent: an identical entry yields \"skip\".\n */\n protected upsertServerInJson(\n configPath: string,\n rootKey: string,\n serverId: string,\n entry: unknown,\n dryRun = false,\n ): ChangeRecord {\n // OVERWRITE GUARD: never replace a present, non-empty, unparseable settings\n // file with a `{}`-based config — that would silently destroy the user's\n // data. Warn and skip so they can back it up / fix it and re-run.\n if (this.isPresentButUnparseable(configPath)) {\n return {\n platform: this.id,\n action: \"warn\",\n path: configPath,\n detail: `existing ${configPath} is not parseable; left untouched (back it up / fix it, then re-run)`,\n };\n }\n const cfg = this.readJson<Record<string, Record<string, unknown>>>(configPath) ?? {};\n const bucket = (cfg[rootKey] ??= {});\n const before = JSON.stringify(bucket[serverId]);\n const after = JSON.stringify(entry);\n let action: ChangeRecord[\"action\"];\n if (before === undefined) action = \"create\";\n else if (before === after) action = \"skip\";\n else action = \"update\";\n if (action !== \"skip\") {\n bucket[serverId] = entry;\n this.writeJson(configPath, cfg, dryRun);\n }\n return { platform: this.id, action, path: configPath, detail: `${rootKey}.${serverId}` };\n }\n\n /** Remove `config[rootKey][serverId]` from a JSON file. */\n protected removeServerFromJson(\n configPath: string,\n rootKey: string,\n serverId: string,\n dryRun = false,\n ): ChangeRecord {\n // OVERWRITE GUARD (see upsertServerInJson): a present-but-unparseable file\n // would round-trip to `{}` and erase the user's config, so warn and skip.\n if (this.isPresentButUnparseable(configPath)) {\n return {\n platform: this.id,\n action: \"warn\",\n path: configPath,\n detail: `existing ${configPath} is not parseable; left untouched (back it up / fix it, then re-run)`,\n };\n }\n const cfg = this.readJson<Record<string, Record<string, unknown>>>(configPath);\n const bucket = cfg?.[rootKey];\n if (!cfg || !bucket || !(serverId in bucket)) {\n return { platform: this.id, action: \"skip\", path: configPath, detail: `${rootKey}.${serverId} absent` };\n }\n delete bucket[serverId];\n this.writeJson(configPath, cfg, dryRun);\n return { platform: this.id, action: \"remove\", path: configPath, detail: `${rootKey}.${serverId}` };\n }\n\n // ── Backup ───────────────────────────────────────────────────────────────\n\n backupSettings(ctx: InstallContext): string | null {\n const files = [...new Set([this.getServerConfigPath(ctx), this.getHookConfigPath(ctx)])].filter(\n (f) => existsSync(f),\n );\n if (files.length === 0) return null;\n if (ctx.dryRun) return null;\n ensureDir(backupsDir());\n const stamp = new Date().toISOString().replace(/[:.]/g, \"-\");\n let last: string | null = null;\n for (const f of files) {\n const dest = join(backupsDir(), `${this.id}-${stamp}-${basename(f)}`);\n copyFileSync(f, dest);\n last = dest;\n }\n return last;\n }\n\n // ── Diagnostics ─────────────────────────────────────────────────────────\n\n getHealthChecks?(ctx: InstallContext): readonly HealthCheck[];\n\n doctor(ctx: InstallContext): DiagnosticResult[] {\n const results: DiagnosticResult[] = [];\n const cfg = this.getServerConfigPath(ctx);\n results.push(\n existsSync(cfg)\n ? { check: `${this.name}: config present`, status: \"pass\", message: cfg }\n : {\n check: `${this.name}: config present`,\n status: \"warn\",\n message: `not found: ${cfg}`,\n fix: `agent-connector install --targets ${this.id}`,\n },\n );\n for (const hc of this.getHealthChecks?.(ctx) ?? []) {\n const r = hc.check();\n results.push({\n check: hc.name,\n status: r.status === \"OK\" ? \"pass\" : \"fail\",\n message: r.detail ?? r.status,\n });\n }\n return results;\n }\n}\n"],"mappings":";;;;;;;;;;AA4BO,SAAS,WAAW,MAAsB;AAC/C,QAAM,IAAI,KAAK;AACf,MAAI,MAAM;AACV,MAAI,IAAI;AACR,MAAI,WAAW;AACf,MAAI,QAAQ;AAEZ,SAAO,IAAI,GAAG;AACZ,UAAM,KAAK,KAAK,CAAC;AAEjB,QAAI,UAAU;AACZ,aAAO;AACP,UAAI,OAAO,MAAM;AAEf,YAAI,IAAI,IAAI,GAAG;AACb,iBAAO,KAAK,IAAI,CAAC;AACjB,eAAK;AACL;AAAA,QACF;AAAA,MACF,WAAW,OAAO,OAAO;AACvB,mBAAW;AAAA,MACb;AACA,WAAK;AACL;AAAA,IACF;AAEA,UAAM,OAAO,IAAI,IAAI,IAAK,KAAK,IAAI,CAAC,IAAe;AAGnD,QAAI,OAAO,OAAO,OAAO,KAAK;AAC5B,iBAAW;AACX,cAAQ;AACR,aAAO;AACP,WAAK;AACL;AAAA,IACF;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