@commentkit/comment-kit 1.6.0 → 2.0.1

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 (137) hide show
  1. package/CHANGELOG.md +298 -590
  2. package/README.md +421 -145
  3. package/SECURITY.md +47 -46
  4. package/dist/node/THIRD_PARTY_NOTICES.txt +56 -0
  5. package/dist/node/browser.js +17 -0
  6. package/dist/node/cli/api.js +226 -0
  7. package/dist/node/cli/bin.js +18 -0
  8. package/dist/node/cli/credentials.js +268 -0
  9. package/dist/node/cli/doctor.js +789 -0
  10. package/dist/node/cli/format.js +54 -0
  11. package/dist/node/cli/init.js +686 -0
  12. package/dist/node/cli/main.js +537 -0
  13. package/dist/node/cli/mcp.js +295 -0
  14. package/dist/node/cli/open.js +20 -0
  15. package/dist/node/plugins/astro-B5y1Gtbf.js +31 -0
  16. package/dist/node/plugins/astro.js +26 -0
  17. package/dist/node/plugins/git-BIXLbL3f.js +92 -0
  18. package/dist/node/plugins/jsx-Bg4BdSph.js +7958 -0
  19. package/dist/node/plugins/next.js +48 -0
  20. package/dist/node/plugins/options-THop1K92.js +71 -0
  21. package/dist/node/plugins/transform-CKiAuSbk.js +1155 -0
  22. package/dist/node/plugins/vite-BdAYUW10.js +74 -0
  23. package/dist/node/plugins/vite.js +1 -0
  24. package/dist/node/plugins/webpack-R2U2DLlY.js +35 -0
  25. package/dist/node/plugins/webpack-loader.cjs +21 -0
  26. package/dist/node/plugins/webpack-loader.js +18 -0
  27. package/dist/node/plugins/webpack.js +1 -0
  28. package/dist/node/shared/dashboard-places.js +33 -0
  29. package/dist/node/shared/endpoint.js +26 -0
  30. package/dist/node/shared/format.js +63 -0
  31. package/dist/node/types/astro.d.ts +11 -0
  32. package/dist/node/types/next.d.ts +34 -0
  33. package/dist/node/types/options.d.ts +59 -0
  34. package/dist/node/types/vite.d.ts +11 -0
  35. package/dist/node/types/webpack-loader.d.ts +22 -0
  36. package/dist/node/types/webpack.d.ts +27 -0
  37. package/dist/npm/THIRD_PARTY_NOTICES.txt +6 -6
  38. package/dist/npm/chunks/AgentSend-DOy3jhyF.js +68 -0
  39. package/dist/npm/chunks/Checklist-CW_SwMpS.js +282 -0
  40. package/dist/npm/chunks/Composer-Bveq5QrK.js +727 -0
  41. package/dist/npm/chunks/Guest-7hcN765o.js +270 -0
  42. package/dist/npm/chunks/MarkupEditor-6bJGpWGO.js +345 -0
  43. package/dist/npm/chunks/Panel-ChPUB68C.js +1211 -0
  44. package/dist/npm/chunks/Settings-CB5eEKnf.js +231 -0
  45. package/dist/npm/chunks/Shortcuts-eAyjJ89P.js +62 -0
  46. package/dist/npm/chunks/StyleEditor-CZTdAA5c.js +46 -0
  47. package/dist/npm/chunks/StylePanel-B4pHQUL9.js +199 -0
  48. package/dist/npm/chunks/TaskFields-C8BX0Sgg.js +289 -0
  49. package/dist/npm/chunks/ThreadCard-B1EsX3PR.js +1160 -0
  50. package/dist/npm/chunks/Viewer-DY6zb90M.js +114 -0
  51. package/dist/npm/chunks/{agent-BDMQtOzH.js → agent-MTQHr9ei.js} +9 -9
  52. package/dist/npm/chunks/{anchor-BsradQhn.js → anchor-BsQNVkHj.js} +108 -85
  53. package/dist/npm/chunks/{ar-8tPch6W4.js → ar-L5cQ-NPe.js} +71 -19
  54. package/dist/npm/chunks/card-bits-CTdrkYn8.js +53 -0
  55. package/dist/npm/chunks/{client-EFTWxHbJ.js → client-7eVxvg5j.js} +282 -290
  56. package/dist/npm/chunks/confetti-BIs5s14P.js +49 -0
  57. package/dist/npm/chunks/context-BuMl7A07.js +48 -0
  58. package/dist/npm/chunks/context-Cf6khm7A.js +20 -0
  59. package/dist/npm/chunks/{de-C63897uD.js → de-D0C-v6tP.js} +62 -18
  60. package/dist/npm/chunks/dialog-DvdIkCW0.js +3 -0
  61. package/dist/npm/chunks/dpop-0A76OPa9.js +96 -0
  62. package/dist/npm/chunks/drafts-B0ctr1g9.js +21 -0
  63. package/dist/npm/chunks/{es-CI2bSpvB.js → es-Bw4Dj9tN.js} +62 -18
  64. package/dist/npm/chunks/extension-DFVOvciD.js +62 -0
  65. package/dist/npm/chunks/{extension-BST6LH1q.js → extension-SmoH5AA4.js} +20 -12
  66. package/dist/npm/chunks/files-4lV9YQIX.js +114 -0
  67. package/dist/npm/chunks/{fr-rsVe-Lqk.js → fr-TkuQaIAa.js} +120 -76
  68. package/dist/npm/chunks/{hi-cvwbSaWP.js → hi-DXSH2U8d.js} +63 -19
  69. package/dist/npm/chunks/{i18n-C4v0M-6z.js → i18n-aVSu9TcJ.js} +136 -92
  70. package/dist/npm/chunks/identify-BGYh2dVo.js +106 -0
  71. package/dist/npm/chunks/{it-C8tnV0BF.js → it-CiWA_bch.js} +81 -37
  72. package/dist/npm/chunks/{ja-BWxDfC2f.js → ja-C-QmR3yz.js} +60 -16
  73. package/dist/npm/chunks/late-words-80_VWt8S.js +14 -0
  74. package/dist/npm/chunks/live-BExWHzQ7.js +85 -0
  75. package/dist/npm/chunks/locale-D8Q4Q2Nt.js +26 -0
  76. package/dist/npm/chunks/{nl-DNQ6eCht.js → nl-CEmZRqjX.js} +63 -19
  77. package/dist/npm/chunks/page-key-HSY3Lze5.js +62 -0
  78. package/dist/npm/chunks/{pick-CLyOdjnD.js → pick-B3sR7jtS.js} +45 -44
  79. package/dist/npm/chunks/pkce-CfZhiNBi.js +8 -0
  80. package/dist/npm/chunks/placement-BF_HOUDD.js +74 -0
  81. package/dist/npm/chunks/privacy-BWUGlHw5.js +57 -0
  82. package/dist/npm/chunks/{pt-BR-CkG7vpU2.js → pt-BR-b-a8sxO8.js} +62 -18
  83. package/dist/npm/chunks/{realtime-DIo-Wth4.js → realtime-C79zF50C.js} +14 -12
  84. package/dist/npm/chunks/report-DaVuoRYS.js +44 -0
  85. package/dist/npm/chunks/show-BoN8AC-F.js +97 -0
  86. package/dist/npm/chunks/signin-BOWr_WCo.js +75 -0
  87. package/dist/npm/chunks/{source-CS7C6wJA.js → source-mk3rGBBQ.js} +1 -1
  88. package/dist/npm/chunks/src-C8rZFyL_.js +215 -0
  89. package/dist/npm/chunks/start-CV4j78_q.js +1894 -0
  90. package/dist/npm/chunks/states-b9Bv3Ci7.js +3 -0
  91. package/dist/npm/chunks/upload-B2mkgMeJ.js +42 -0
  92. package/dist/npm/chunks/uploads-8AxyRq7g.js +1147 -0
  93. package/dist/npm/chunks/wrap-DW6EFbVQ.js +69 -0
  94. package/dist/npm/chunks/{zh-CN-BKuZOLBE.js → zh-CN-JTscW8u8.js} +61 -17
  95. package/dist/npm/element.js +58 -21
  96. package/dist/npm/headless.js +7 -3
  97. package/dist/npm/index.js +3 -3
  98. package/dist/npm/react.js +18 -11
  99. package/dist/npm/svelte.js +28 -12
  100. package/dist/npm/types/adapters/react.d.ts +4 -1
  101. package/dist/npm/types/adapters/svelte.d.ts +4 -1
  102. package/dist/npm/types/adapters/vue.d.ts +35 -2
  103. package/dist/npm/types/anchor/index.d.ts +19 -0
  104. package/dist/npm/types/capture/privacy.d.ts +14 -0
  105. package/dist/npm/types/core/api.d.ts +20 -1
  106. package/dist/npm/types/core/auth.d.ts +40 -21
  107. package/dist/npm/types/core/client.d.ts +60 -4
  108. package/dist/npm/types/core/page-key.d.ts +42 -0
  109. package/dist/npm/types/core/types.d.ts +87 -4
  110. package/dist/npm/types/element.d.ts +17 -7
  111. package/dist/npm/types/headless.d.ts +2 -1
  112. package/dist/npm/types/index.d.ts +16 -6
  113. package/dist/npm/vue.js +44 -9
  114. package/package.json +90 -14
  115. package/dist/npm/chunks/AgentSend-2JPDseOo.js +0 -63
  116. package/dist/npm/chunks/Checklist-BpDXQebo.js +0 -257
  117. package/dist/npm/chunks/Composer-CAyj-c8e.js +0 -677
  118. package/dist/npm/chunks/Guest-ZdFmTcXI.js +0 -187
  119. package/dist/npm/chunks/MarkupEditor-BFplZwFy.js +0 -332
  120. package/dist/npm/chunks/Panel-BhZ4XRDR.js +0 -861
  121. package/dist/npm/chunks/Settings-SPG9EHUZ.js +0 -204
  122. package/dist/npm/chunks/Shortcuts-C28HVDw6.js +0 -58
  123. package/dist/npm/chunks/StyleEditor-ByZMtq10.js +0 -43
  124. package/dist/npm/chunks/StylePanel-Iwhce2tE.js +0 -197
  125. package/dist/npm/chunks/TaskFields-BsP_fVJg.js +0 -273
  126. package/dist/npm/chunks/ThreadCard-BzVZdDCb.js +0 -1030
  127. package/dist/npm/chunks/Viewer-CqtGrdD8.js +0 -108
  128. package/dist/npm/chunks/card-bits-Bna-g3Py.js +0 -124
  129. package/dist/npm/chunks/confetti-DTKpwF3O.js +0 -40
  130. package/dist/npm/chunks/drafts-akdBsOd0.js +0 -50
  131. package/dist/npm/chunks/extension-D-V3utTm.js +0 -53
  132. package/dist/npm/chunks/live-BCpJVBeN.js +0 -33
  133. package/dist/npm/chunks/report-BBrT3r89.js +0 -27
  134. package/dist/npm/chunks/src-C4FsVoUp.js +0 -148
  135. package/dist/npm/chunks/start-i9M-r3aH.js +0 -1800
  136. package/dist/npm/chunks/upload-DSv7EyBD.js +0 -41
  137. package/dist/npm/chunks/uploads-I01kdqQF.js +0 -1103
@@ -0,0 +1,295 @@
1
+ // `npx @commentkit/comment-kit mcp install <agent>`: add the hosted MCP server to a coding agent's config file.
2
+ // Merges into what is there, backs the file up first, and never replaces an entry without asking.
3
+ import { spawnSync } from "node:child_process";
4
+ import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { basename, dirname, join, relative } from "node:path";
7
+ import { CliError } from "./api.js";
8
+ import { credentialsPath } from "./credentials.js";
9
+ export const AGENTS = ["cursor", "vscode", "claude", "codex"];
10
+ const NAME = "commentkit";
11
+ /** The scope each agent's own docs lead with. */
12
+ export const DEFAULT_SCOPE = { cursor: "user", vscode: "project", claude: "user", codex: "user" };
13
+ export const NEXT_STEP = {
14
+ cursor: "Restart Cursor (or open Settings > MCP) and sign in when it asks.",
15
+ vscode: "Open the file in VS Code, click Start above the commentkit entry, and sign in when it asks.",
16
+ claude: "Restart Claude Code, run /mcp and choose Authenticate.",
17
+ codex: "Run: codex mcp login commentkit",
18
+ };
19
+ export function configPath(agent, scope, cwd, env = process.env, platform = process.platform) {
20
+ const home = (platform === "win32" ? env.USERPROFILE : env.HOME) || homedir();
21
+ switch (agent) {
22
+ case "cursor":
23
+ return scope === "project" ? join(cwd, ".cursor", "mcp.json") : join(home, ".cursor", "mcp.json");
24
+ case "claude":
25
+ return scope === "project" ? join(cwd, ".mcp.json") : join(home, ".claude.json");
26
+ case "codex":
27
+ if (scope === "project")
28
+ throw new CliError("Codex reads MCP servers from ~/.codex/config.toml only. Leave out --scope project.");
29
+ return join(env.CODEX_HOME || join(home, ".codex"), "config.toml");
30
+ case "vscode": {
31
+ if (scope === "project")
32
+ return join(cwd, ".vscode", "mcp.json");
33
+ const base = platform === "darwin" ? join(home, "Library", "Application Support") : platform === "win32" ? (env.APPDATA ?? join(home, "AppData", "Roaming")) : (env.XDG_CONFIG_HOME || join(home, ".config"));
34
+ return join(base, "Code", "User", "mcp.json");
35
+ }
36
+ }
37
+ }
38
+ /** The entry each agent expects for a remote (Streamable HTTP) server. */
39
+ export function entry(agent, url) {
40
+ return agent === "cursor" ? { url } : { type: "http", url };
41
+ }
42
+ /** The file's own indentation unit (a tab, or the smallest run of leading spaces), 2 spaces when it has none. */
43
+ export function indentOf(text) {
44
+ let unit = null;
45
+ for (const m of text.matchAll(/\n([ \t]+)\S/g)) {
46
+ const ws = m[1];
47
+ if (ws.startsWith("\t"))
48
+ return "\t";
49
+ if (unit === null || ws.length < unit.length)
50
+ unit = ws;
51
+ }
52
+ return unit ?? " ";
53
+ }
54
+ /** Positions in a JSON text that JSON.parse accepted: just enough to find an object's members. */
55
+ class Scan {
56
+ text;
57
+ constructor(text) {
58
+ this.text = text;
59
+ }
60
+ ws(i) {
61
+ while (i < this.text.length && /\s/.test(this.text[i]))
62
+ i++;
63
+ return i;
64
+ }
65
+ string(i) {
66
+ for (i++; this.text[i] !== '"'; i++)
67
+ if (this.text[i] === "\\")
68
+ i++;
69
+ return i + 1;
70
+ }
71
+ value(i) {
72
+ const c = this.text[i];
73
+ if (c === '"')
74
+ return this.string(i);
75
+ if (c === "{" || c === "[") {
76
+ const close = c === "{" ? "}" : "]";
77
+ i = this.ws(i + 1);
78
+ while (this.text[i] !== close) {
79
+ if (c === "{")
80
+ i = this.ws(this.string(i)) + 1; // the key, then its ':'
81
+ i = this.ws(this.value(this.ws(i)));
82
+ if (this.text[i] === ",")
83
+ i = this.ws(i + 1);
84
+ }
85
+ return i + 1;
86
+ }
87
+ const m = /^-?[\w.+-]+/.exec(this.text.slice(i));
88
+ return i + (m ? m[0].length : 1);
89
+ }
90
+ /** The members of the object whose `{` is at `open`, and where its `}` is. */
91
+ members(open) {
92
+ const members = [];
93
+ let i = this.ws(open + 1);
94
+ while (this.text[i] !== "}") {
95
+ const keyStart = i;
96
+ const keyEnd = this.string(i);
97
+ const valueStart = this.ws(this.ws(keyEnd) + 1);
98
+ const valueEnd = this.value(valueStart);
99
+ members.push({ key: JSON.parse(this.text.slice(keyStart, keyEnd)), keyStart, valueStart, valueEnd });
100
+ i = this.ws(valueEnd);
101
+ if (this.text[i] === ",")
102
+ i = this.ws(i + 1);
103
+ }
104
+ return { members, close: i };
105
+ }
106
+ }
107
+ /** The whitespace that starts the line holding `pos`. */
108
+ function lineIndent(text, pos) {
109
+ const start = text.lastIndexOf("\n", pos - 1) + 1;
110
+ return /^[ \t]*/.exec(text.slice(start))[0];
111
+ }
112
+ /** `value` as JSON laid out like the file: multi-line at `indent` with `unit`, or on one line. */
113
+ function layout(value, indent, unit, nl, inline, spaced) {
114
+ if (!inline)
115
+ return JSON.stringify(value, null, unit).split("\n").join(nl + indent);
116
+ if (!spaced)
117
+ return JSON.stringify(value);
118
+ const one = (v) => v && typeof v === "object" && !Array.isArray(v)
119
+ ? `{ ${Object.entries(v).map(([k, x]) => `${JSON.stringify(k)}: ${one(x)}`).join(", ")} }`
120
+ : JSON.stringify(v);
121
+ return one(value);
122
+ }
123
+ /**
124
+ * Set `key` to `value` in the object at `open`, as an edit to the text: the rest of the file keeps its
125
+ * indentation, line endings and trailing newline. A new member goes last, laid out like its neighbours.
126
+ */
127
+ function setMember(text, open, key, value, unit) {
128
+ const scan = new Scan(text);
129
+ const nl = text.includes("\r\n") ? "\r\n" : "\n";
130
+ const spaced = /"\s*:\s/.test(text) || !/"\s*:\S/.test(text);
131
+ const { members, close } = scan.members(open);
132
+ const existing = members.find((m) => m.key === key);
133
+ if (existing) {
134
+ const inline = !text.slice(existing.valueStart, existing.valueEnd).includes("\n") && !text.slice(open, close).includes("\n");
135
+ const indent = lineIndent(text, existing.keyStart);
136
+ return `${text.slice(0, existing.valueStart)}${layout(value, indent, unit, nl, inline, spaced)}${text.slice(existing.valueEnd)}`;
137
+ }
138
+ const name = JSON.stringify(key);
139
+ const colon = spaced ? ": " : ":";
140
+ if (members.length) {
141
+ const last = members.at(-1);
142
+ const multiline = text.slice(open, members[0].keyStart).includes("\n");
143
+ if (multiline) {
144
+ const indent = lineIndent(text, members[0].keyStart);
145
+ return `${text.slice(0, last.valueEnd)},${nl}${indent}${name}${colon}${layout(value, indent, unit, nl, false, spaced)}${text.slice(last.valueEnd)}`;
146
+ }
147
+ return `${text.slice(0, last.valueEnd)},${spaced ? " " : ""}${name}${colon}${layout(value, "", unit, nl, true, spaced)}${text.slice(last.valueEnd)}`;
148
+ }
149
+ // An empty object: multi-line when the file is, one line when it is all on one line.
150
+ const multiline = text.trimEnd().includes("\n") || text.slice(open, close).includes("\n");
151
+ if (!multiline)
152
+ return `${text.slice(0, open + 1)}${spaced ? " " : ""}${name}${colon}${layout(value, "", unit, nl, true, spaced)}${spaced ? " " : ""}${text.slice(close)}`;
153
+ const outer = lineIndent(text, open);
154
+ const inner = outer + unit;
155
+ return `${text.slice(0, open + 1)}${nl}${inner}${name}${colon}${layout(value, inner, unit, nl, false, spaced)}${nl}${outer}${text.slice(close)}`;
156
+ }
157
+ /**
158
+ * Add or replace mcpServers.commentkit (servers.commentkit for VS Code), keeping everything else. The file
159
+ * is edited as text, so the change is only the entry: its indentation (spaces or tabs), line endings and
160
+ * trailing newline (or none) stay as they were. If the edit would not give exactly the intended JSON, the
161
+ * file is written out whole instead, still with its own indentation and trailing-newline state.
162
+ */
163
+ export function mergeJson(text, agent, url) {
164
+ let root = {};
165
+ const empty = text === null || text.trim() === "";
166
+ if (!empty) {
167
+ try {
168
+ root = JSON.parse(text);
169
+ }
170
+ catch {
171
+ throw new CliError("it is not plain JSON (comments or trailing commas?), so it was left alone");
172
+ }
173
+ if (!root || typeof root !== "object" || Array.isArray(root))
174
+ throw new CliError("it does not hold a JSON object, so it was left alone");
175
+ }
176
+ const key = agent === "vscode" ? "servers" : "mcpServers";
177
+ const servers = root[key] ?? {};
178
+ if (!servers || typeof servers !== "object" || Array.isArray(servers))
179
+ throw new CliError(`its "${key}" is not an object, so it was left alone`);
180
+ const wanted = entry(agent, url);
181
+ const current = servers[NAME];
182
+ if (current !== undefined && JSON.stringify(current) === JSON.stringify(wanted))
183
+ return { status: "same", content: text ?? "" };
184
+ root[key] = { ...servers, [NAME]: wanted };
185
+ const status = current === undefined ? "added" : "replaced";
186
+ if (empty)
187
+ return { status, content: `${JSON.stringify(root, null, 2)}\n` };
188
+ const unit = indentOf(text);
189
+ let content = null;
190
+ try {
191
+ const open = text.indexOf("{");
192
+ const { members } = new Scan(text).members(open);
193
+ const holder = members.find((m) => m.key === key);
194
+ content = holder && text[holder.valueStart] === "{" ? setMember(text, holder.valueStart, NAME, wanted, unit) : setMember(text, open, key, { [NAME]: wanted }, unit);
195
+ if (JSON.stringify(JSON.parse(content)) !== JSON.stringify(root))
196
+ content = null;
197
+ }
198
+ catch {
199
+ content = null;
200
+ }
201
+ // Fallback: the whole file, in its own indentation and with its own trailing-newline state.
202
+ content ??= `${JSON.stringify(root, null, unit)}${/\n$/.test(text) ? (text.endsWith("\r\n") ? "\r\n" : "\n") : ""}`;
203
+ return { status, content };
204
+ }
205
+ const TABLE = /^[ \t]*\[[ \t]*mcp_servers[ \t]*\.[ \t]*"?commentkit"?[ \t]*\][ \t]*(#.*)?$/m;
206
+ /** Add or replace [mcp_servers.commentkit] in Codex's config.toml, as text, so comments and layout stay. */
207
+ export function mergeToml(text, url) {
208
+ const source = text ?? "";
209
+ const block = `[mcp_servers.${NAME}]\nurl = ${JSON.stringify(url)}\n`;
210
+ // Other spellings (dotted keys, an inline table under [mcp_servers]) are left to a person.
211
+ const dotted = /^[ \t]*mcp_servers[ \t]*\.[ \t]*"?commentkit"?[ \t]*[.=]/m.test(source);
212
+ const inline = /^[ \t]*\[[ \t]*mcp_servers[ \t]*\][ \t]*$/m.test(source) && /^[ \t]*"?commentkit"?[ \t]*=/m.test(source);
213
+ if (dotted || inline)
214
+ throw new CliError("it already names commentkit in a form this command does not edit, so it was left alone");
215
+ const match = TABLE.exec(source);
216
+ if (!match) {
217
+ const sep = source === "" ? "" : source.endsWith("\n\n") ? "" : source.endsWith("\n") ? "\n" : "\n\n";
218
+ return { status: "added", content: `${source}${sep}${block}` };
219
+ }
220
+ // The table runs to the next header that is not one of its own sub-tables (such as .env).
221
+ const start = match.index;
222
+ const bodyStart = start + match[0].length;
223
+ const rest = source.slice(bodyStart);
224
+ const next = /^[ \t]*\[(?![ \t]*mcp_servers[ \t]*\.[ \t]*"?commentkit"?[ \t]*\.)/m.exec(rest);
225
+ const end = next ? bodyStart + next.index : source.length;
226
+ const current = source.slice(start, end);
227
+ const lines = current.split("\n").map((l) => l.replace(/#.*$/, "").trim()).filter(Boolean);
228
+ if (lines.length === 2 && lines[1].replace(/\s+/g, "") === `url=${JSON.stringify(url)}`)
229
+ return { status: "same", content: source };
230
+ const tail = source.slice(end);
231
+ return { status: "replaced", content: `${source.slice(0, start)}${block}${tail ? `\n${tail}` : ""}` };
232
+ }
233
+ /**
234
+ * Is `file` (which may not exist yet) in a git work tree, and does git ignore it? Asks git itself
235
+ * (`git check-ignore -v`), so nested .gitignore files, .git/info/exclude and the global excludes file all
236
+ * count. Without git, a .git folder above the file means "in a repository, not ignored".
237
+ */
238
+ export function gitPlace(file) {
239
+ let dir = dirname(file);
240
+ while (!existsSync(dir) && dirname(dir) !== dir)
241
+ dir = dirname(dir);
242
+ const result = spawnSync("git", ["-C", dir, "check-ignore", "-v", "--", relative(dir, file)], { encoding: "utf8", timeout: 10_000, stdio: ["ignore", "pipe", "pipe"] });
243
+ if (result.error) {
244
+ for (let d = dir;; d = dirname(d)) {
245
+ if (existsSync(join(d, ".git")))
246
+ return { repo: true, ignored: false };
247
+ if (dirname(d) === d)
248
+ return { repo: false, ignored: false };
249
+ }
250
+ }
251
+ if (result.status === 0) {
252
+ // "<source>:<line>:<pattern>\t<path>"; the source is relative to `dir`, or absolute for a global excludes file.
253
+ const m = /^(.*?):(\d+):/.exec(result.stdout);
254
+ return { repo: true, ignored: true, ...(m ? { rule: `${m[1]}:${m[2]}` } : {}) };
255
+ }
256
+ // 1: not ignored. 128: not a repository (or git could not tell).
257
+ return { repo: result.status === 1, ignored: false };
258
+ }
259
+ /** Where backups go when one next to the file would sit in a git work tree for git to pick up. */
260
+ export function backupFolder(env = process.env) {
261
+ return join(dirname(credentialsPath(env)), "backups");
262
+ }
263
+ /**
264
+ * A copy of the file, named by the time, with the same permissions: next to the file, unless that copy
265
+ * would land in a git work tree without being ignored; then in the CLI's own folder (backupFolder()).
266
+ */
267
+ export function backup(file, now = new Date()) {
268
+ const name = `${basename(file)}.bak-${now.toISOString().replace(/[:.]/g, "-")}`;
269
+ const beside = join(dirname(file), name);
270
+ const place = gitPlace(beside);
271
+ let copy = beside;
272
+ if (place.repo && !place.ignored) {
273
+ mkdirSync(backupFolder(), { recursive: true, mode: 0o700 });
274
+ copy = join(backupFolder(), name);
275
+ }
276
+ copyFileSync(file, copy);
277
+ try {
278
+ chmodSync(copy, statSync(file).mode & 0o777);
279
+ }
280
+ catch {
281
+ // Windows: permissions come from the folder.
282
+ }
283
+ return copy;
284
+ }
285
+ /** Replace the file in one step, keeping its permissions. */
286
+ export function writeAtomic(file, content) {
287
+ mkdirSync(dirname(file), { recursive: true });
288
+ const mode = existsSync(file) ? statSync(file).mode & 0o777 : 0o644;
289
+ const tmp = `${file}.${process.pid}.tmp`;
290
+ writeFileSync(tmp, content, { mode });
291
+ renameSync(tmp, file);
292
+ }
293
+ export function readIfExists(file) {
294
+ return existsSync(file) ? readFileSync(file, "utf8") : null;
295
+ }
@@ -0,0 +1,20 @@
1
+ import { spawn } from "node:child_process";
2
+ /** Open a web address in the default browser, without a shell. Returns false when it could not. */
3
+ export function openUrl(url) {
4
+ if (!/^https?:\/\//.test(url) || process.env.COMMENTKIT_NO_BROWSER)
5
+ return Promise.resolve(false);
6
+ const [command, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["rundll32", ["url.dll,FileProtocolHandler", url]] : ["xdg-open", [url]];
7
+ return new Promise((resolve) => {
8
+ try {
9
+ const child = spawn(command, args, { stdio: "ignore", detached: true });
10
+ child.on("error", () => resolve(false));
11
+ child.on("spawn", () => {
12
+ child.unref();
13
+ resolve(true);
14
+ });
15
+ }
16
+ catch {
17
+ resolve(false);
18
+ }
19
+ });
20
+ }
@@ -0,0 +1,31 @@
1
+ import { i as e, n as t, r as n } from "./transform-CKiAuSbk.js";
2
+ import { tagJsxAst as r } from "./jsx-Bg4BdSph.js";
3
+ // plugins/transform/astro.ts
4
+ function i(e, t, n) {
5
+ let { ast: i } = t.parse(e);
6
+ r(i.body, n);
7
+ }
8
+ function a(e) {
9
+ if (!/[^\x00-\x7f]/.test(e)) return (e) => e;
10
+ let t = [], n = 0;
11
+ for (let r = 0; r < e.length; r++) {
12
+ let i = e.codePointAt(r), a = i < 128 ? 1 : i < 2048 ? 2 : i < 65536 ? 3 : 4;
13
+ for (let e = 0; e < a; e++) t[n + e] = r;
14
+ n += a, i >= 65536 && r++;
15
+ }
16
+ return t[n] = e.length, (e) => t[e] ?? -1;
17
+ }
18
+ async function o(r, i, o) {
19
+ let { ast: s } = await i.parse(r, { position: !0 }), c = a(r), l = (r, i) => {
20
+ for (let a of r ?? []) {
21
+ let r = i;
22
+ if ((a.type === "element" || a.type === "custom-element") && a.name) {
23
+ let s = a.name, l = a.position ? c(a.position.start.offset) : -1, u = a.attributes?.some((e) => e.name === t);
24
+ !i && l >= 0 && !e.has(s) && !u && o.verify(l, s) && o.add(l, l + 1 + s.length), (n.has(s) || s === "head" || s === "script" || s === "style") && (r = !0);
25
+ } else if (a.type === "frontmatter") continue;
26
+ l(a.children, r);
27
+ }
28
+ };
29
+ l(s.children, !1);
30
+ }
31
+ export { o as tagAstroGo, i as tagAstroRust };
@@ -0,0 +1,26 @@
1
+ import { n as e } from "./git-BIXLbL3f.js";
2
+ import { n as t, r as n, t as r } from "./vite-BdAYUW10.js";
3
+ import { a as i } from "./options-THop1K92.js";
4
+ import { resolve as a } from "node:path";
5
+ import { fileURLToPath as o } from "node:url";
6
+ // plugins/astro.ts
7
+ function s(s = {}) {
8
+ return {
9
+ name: "@commentkit/comment-kit",
10
+ hooks: { "astro:config:setup": ({ command: c, config: l, updateConfig: u, injectScript: d }) => {
11
+ let f = o(l.root), p = a(f, s.root ?? ".");
12
+ if (u({ vite: { plugins: [r({
13
+ ...s,
14
+ root: p,
15
+ inject: void 0
16
+ })] } }), c === "dev" && s.inject) {
17
+ let r = i(s.buildInfo, !0) ? e({ cwd: p }) : {
18
+ branch: null,
19
+ commit: null
20
+ }, a = n(s.inject, r);
21
+ a && d("page", t(a));
22
+ }
23
+ } }
24
+ };
25
+ }
26
+ export { s as commentkit, s as default };
@@ -0,0 +1,92 @@
1
+ import { execFileSync as e } from "node:child_process";
2
+ // plugins/git.ts
3
+ var t = [
4
+ {
5
+ name: "commentkit",
6
+ branch: ["COMMENTKIT_BRANCH"],
7
+ commit: ["COMMENTKIT_COMMIT"]
8
+ },
9
+ {
10
+ name: "vercel",
11
+ branch: ["VERCEL_GIT_COMMIT_REF"],
12
+ commit: ["VERCEL_GIT_COMMIT_SHA"]
13
+ },
14
+ {
15
+ name: "netlify",
16
+ when: "NETLIFY",
17
+ branch: ["HEAD", "BRANCH"],
18
+ commit: ["COMMIT_REF"]
19
+ },
20
+ {
21
+ name: "cloudflare-pages",
22
+ branch: ["CF_PAGES_BRANCH"],
23
+ commit: ["CF_PAGES_COMMIT_SHA"]
24
+ },
25
+ {
26
+ name: "github-actions",
27
+ when: "GITHUB_ACTIONS",
28
+ branch: ["GITHUB_HEAD_REF", "GITHUB_REF_NAME"],
29
+ commit: ["GITHUB_SHA"]
30
+ },
31
+ {
32
+ name: "gitlab",
33
+ when: "GITLAB_CI",
34
+ branch: ["CI_MERGE_REQUEST_SOURCE_BRANCH_NAME", "CI_COMMIT_REF_NAME"],
35
+ commit: ["CI_COMMIT_SHA"]
36
+ },
37
+ {
38
+ name: "render",
39
+ branch: ["RENDER_GIT_BRANCH"],
40
+ commit: ["RENDER_GIT_COMMIT"]
41
+ }
42
+ ], n = (e, t) => {
43
+ for (let n of t) {
44
+ let t = e[n]?.trim();
45
+ if (t) return t;
46
+ }
47
+ return null;
48
+ };
49
+ function r(e) {
50
+ let t = e?.trim().replace(/^refs\/heads\//, "");
51
+ return !t || t === "HEAD" || t.length > 255 || !/^[A-Za-z0-9._/-]+$/.test(t) ? null : t;
52
+ }
53
+ function i(e) {
54
+ let t = e?.trim().toLowerCase();
55
+ return t && /^[0-9a-f]{7,64}$/.test(t) ? t : null;
56
+ }
57
+ function a(t, n) {
58
+ try {
59
+ return e("git", t, {
60
+ cwd: n,
61
+ encoding: "utf8",
62
+ stdio: [
63
+ "ignore",
64
+ "pipe",
65
+ "ignore"
66
+ ],
67
+ timeout: 3e3,
68
+ windowsHide: !0
69
+ }).trim() || null;
70
+ } catch {
71
+ return null;
72
+ }
73
+ }
74
+ function o(e = {}) {
75
+ let o = e.env ?? process.env, s = e.cwd ?? process.cwd(), c = null, l = null;
76
+ for (let e of t) if ((!e.when || o[e.when]) && (c ??= r(n(o, e.branch)), l ??= i(n(o, e.commit)), c && l)) break;
77
+ return e.git === !1 || c && l || (c ??= r(a([
78
+ "rev-parse",
79
+ "--abbrev-ref",
80
+ "HEAD"
81
+ ], s)), l ??= i(a(["rev-parse", "HEAD"], s))), {
82
+ branch: c,
83
+ commit: l
84
+ };
85
+ }
86
+ function s(e) {
87
+ return { __COMMENTKIT_BUILD__: JSON.stringify({
88
+ branch: e.branch,
89
+ commit: e.commit
90
+ }) };
91
+ }
92
+ export { o as n, s as t };