@commentkit/comment-kit 1.6.0 → 2.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 (136) hide show
  1. package/CHANGELOG.md +281 -597
  2. package/README.md +334 -154
  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 +725 -0
  10. package/dist/node/cli/format.js +54 -0
  11. package/dist/node/cli/init.js +372 -0
  12. package/dist/node/cli/main.js +519 -0
  13. package/dist/node/cli/mcp.js +114 -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/endpoint.js +26 -0
  29. package/dist/node/shared/format.js +63 -0
  30. package/dist/node/types/astro.d.ts +11 -0
  31. package/dist/node/types/next.d.ts +34 -0
  32. package/dist/node/types/options.d.ts +59 -0
  33. package/dist/node/types/vite.d.ts +11 -0
  34. package/dist/node/types/webpack-loader.d.ts +22 -0
  35. package/dist/node/types/webpack.d.ts +27 -0
  36. package/dist/npm/THIRD_PARTY_NOTICES.txt +6 -6
  37. package/dist/npm/chunks/AgentSend-DxRJIYiz.js +68 -0
  38. package/dist/npm/chunks/Checklist-CnlfeSbc.js +282 -0
  39. package/dist/npm/chunks/Composer-B1bBVszY.js +725 -0
  40. package/dist/npm/chunks/Guest-vvNPz8h-.js +267 -0
  41. package/dist/npm/chunks/MarkupEditor-VCOXh9d2.js +338 -0
  42. package/dist/npm/chunks/Panel-F37vIL1K.js +1206 -0
  43. package/dist/npm/chunks/Settings-BGoZS2iV.js +231 -0
  44. package/dist/npm/chunks/Shortcuts-B2OMvczr.js +62 -0
  45. package/dist/npm/chunks/StyleEditor-CJ_d8Huf.js +46 -0
  46. package/dist/npm/chunks/StylePanel-yQzHHlY7.js +199 -0
  47. package/dist/npm/chunks/TaskFields-fmy6_HtK.js +289 -0
  48. package/dist/npm/chunks/ThreadCard-D51slKST.js +1113 -0
  49. package/dist/npm/chunks/Viewer-BOBadqmC.js +111 -0
  50. package/dist/npm/chunks/{agent-BDMQtOzH.js → agent-C1OQzBAm.js} +9 -9
  51. package/dist/npm/chunks/{anchor-BsradQhn.js → anchor-BsQNVkHj.js} +108 -85
  52. package/dist/npm/chunks/{ar-8tPch6W4.js → ar-CAJ3XT8e.js} +69 -19
  53. package/dist/npm/chunks/card-bits-CAnzrqx3.js +53 -0
  54. package/dist/npm/chunks/{client-EFTWxHbJ.js → client-kNAo2TTG.js} +282 -290
  55. package/dist/npm/chunks/confetti-CkBdSu19.js +49 -0
  56. package/dist/npm/chunks/context-B8UAzve0.js +20 -0
  57. package/dist/npm/chunks/context-BuMl7A07.js +48 -0
  58. package/dist/npm/chunks/{de-C63897uD.js → de-Dl18G48t.js} +60 -18
  59. package/dist/npm/chunks/dialog-GO04oC3D.js +3 -0
  60. package/dist/npm/chunks/dpop-U48QIQd7.js +96 -0
  61. package/dist/npm/chunks/drafts-B0ctr1g9.js +21 -0
  62. package/dist/npm/chunks/{es-CI2bSpvB.js → es-Dxk79lS9.js} +60 -18
  63. package/dist/npm/chunks/extension-CKFpPWmi.js +62 -0
  64. package/dist/npm/chunks/{extension-BST6LH1q.js → extension-E81hWyiT.js} +20 -12
  65. package/dist/npm/chunks/files-DyD5BZgp.js +114 -0
  66. package/dist/npm/chunks/{fr-rsVe-Lqk.js → fr-8BebGKYD.js} +118 -76
  67. package/dist/npm/chunks/{hi-cvwbSaWP.js → hi-BIN6Yy_p.js} +61 -19
  68. package/dist/npm/chunks/{i18n-C4v0M-6z.js → i18n-DOBt8e9U.js} +91 -56
  69. package/dist/npm/chunks/identify-CN-3xzqL.js +106 -0
  70. package/dist/npm/chunks/{it-C8tnV0BF.js → it-Cr6EwpPQ.js} +79 -37
  71. package/dist/npm/chunks/{ja-BWxDfC2f.js → ja-Iy3s5aur.js} +58 -16
  72. package/dist/npm/chunks/late-words-B2bmZceJ.js +12 -0
  73. package/dist/npm/chunks/live-CelVeZfP.js +85 -0
  74. package/dist/npm/chunks/locale-D8Q4Q2Nt.js +26 -0
  75. package/dist/npm/chunks/{nl-DNQ6eCht.js → nl-B84WHqqe.js} +61 -19
  76. package/dist/npm/chunks/page-key-DepmJzC1.js +62 -0
  77. package/dist/npm/chunks/{pick-CLyOdjnD.js → pick-yTyqtxN0.js} +45 -44
  78. package/dist/npm/chunks/pkce-ChKGSW_4.js +8 -0
  79. package/dist/npm/chunks/placement-BF_HOUDD.js +74 -0
  80. package/dist/npm/chunks/privacy-BWUGlHw5.js +57 -0
  81. package/dist/npm/chunks/{pt-BR-CkG7vpU2.js → pt-BR-DOkdlfoe.js} +60 -18
  82. package/dist/npm/chunks/{realtime-DIo-Wth4.js → realtime-C79zF50C.js} +14 -12
  83. package/dist/npm/chunks/report-CrIqQZDI.js +44 -0
  84. package/dist/npm/chunks/show-BgVC8gWY.js +97 -0
  85. package/dist/npm/chunks/signin-Dd1rb2BP.js +75 -0
  86. package/dist/npm/chunks/{source-CS7C6wJA.js → source-pXVve2Cx.js} +1 -1
  87. package/dist/npm/chunks/src-BTMy4Gyc.js +208 -0
  88. package/dist/npm/chunks/start-DtVlpt7p.js +1878 -0
  89. package/dist/npm/chunks/states-sfTbjZz8.js +3 -0
  90. package/dist/npm/chunks/upload-MgPYqPyE.js +42 -0
  91. package/dist/npm/chunks/uploads-D49mywwz.js +1146 -0
  92. package/dist/npm/chunks/wrap-Bl0gbnFa.js +69 -0
  93. package/dist/npm/chunks/{zh-CN-BKuZOLBE.js → zh-CN-Z5fQCb7G.js} +59 -17
  94. package/dist/npm/element.js +58 -21
  95. package/dist/npm/headless.js +7 -3
  96. package/dist/npm/index.js +3 -3
  97. package/dist/npm/react.js +18 -11
  98. package/dist/npm/svelte.js +28 -12
  99. package/dist/npm/types/adapters/react.d.ts +4 -1
  100. package/dist/npm/types/adapters/svelte.d.ts +4 -1
  101. package/dist/npm/types/adapters/vue.d.ts +35 -2
  102. package/dist/npm/types/anchor/index.d.ts +19 -0
  103. package/dist/npm/types/capture/privacy.d.ts +14 -0
  104. package/dist/npm/types/core/api.d.ts +20 -1
  105. package/dist/npm/types/core/auth.d.ts +40 -21
  106. package/dist/npm/types/core/client.d.ts +60 -4
  107. package/dist/npm/types/core/page-key.d.ts +42 -0
  108. package/dist/npm/types/core/types.d.ts +87 -4
  109. package/dist/npm/types/element.d.ts +17 -7
  110. package/dist/npm/types/headless.d.ts +2 -1
  111. package/dist/npm/types/index.d.ts +16 -6
  112. package/dist/npm/vue.js +44 -9
  113. package/package.json +88 -14
  114. package/dist/npm/chunks/AgentSend-2JPDseOo.js +0 -63
  115. package/dist/npm/chunks/Checklist-BpDXQebo.js +0 -257
  116. package/dist/npm/chunks/Composer-CAyj-c8e.js +0 -677
  117. package/dist/npm/chunks/Guest-ZdFmTcXI.js +0 -187
  118. package/dist/npm/chunks/MarkupEditor-BFplZwFy.js +0 -332
  119. package/dist/npm/chunks/Panel-BhZ4XRDR.js +0 -861
  120. package/dist/npm/chunks/Settings-SPG9EHUZ.js +0 -204
  121. package/dist/npm/chunks/Shortcuts-C28HVDw6.js +0 -58
  122. package/dist/npm/chunks/StyleEditor-ByZMtq10.js +0 -43
  123. package/dist/npm/chunks/StylePanel-Iwhce2tE.js +0 -197
  124. package/dist/npm/chunks/TaskFields-BsP_fVJg.js +0 -273
  125. package/dist/npm/chunks/ThreadCard-BzVZdDCb.js +0 -1030
  126. package/dist/npm/chunks/Viewer-CqtGrdD8.js +0 -108
  127. package/dist/npm/chunks/card-bits-Bna-g3Py.js +0 -124
  128. package/dist/npm/chunks/confetti-DTKpwF3O.js +0 -40
  129. package/dist/npm/chunks/drafts-akdBsOd0.js +0 -50
  130. package/dist/npm/chunks/extension-D-V3utTm.js +0 -53
  131. package/dist/npm/chunks/live-BCpJVBeN.js +0 -33
  132. package/dist/npm/chunks/report-BBrT3r89.js +0 -27
  133. package/dist/npm/chunks/src-C4FsVoUp.js +0 -148
  134. package/dist/npm/chunks/start-i9M-r3aH.js +0 -1800
  135. package/dist/npm/chunks/upload-DSv7EyBD.js +0 -41
  136. package/dist/npm/chunks/uploads-I01kdqQF.js +0 -1103
@@ -0,0 +1,268 @@
1
+ // Where a terminal sign-in is kept: one file, readable only by you.
2
+ //
3
+ // Several `commentkit` runs can share the file at once (two terminals, an editor task and a shell).
4
+ // The refresh token rotates on every use, so a refresh, and every read-modify-write of the file, runs
5
+ // while holding a lock file next to it. A lock left behind by a run that crashed is taken over once its
6
+ // process is gone, or after LOCK_STALE_MS.
7
+ import { createHash, randomBytes } from "node:crypto";
8
+ import { chmodSync, closeSync, copyFileSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
9
+ import { homedir, hostname } from "node:os";
10
+ import { dirname, join } from "node:path";
11
+ /** A lock older than this is from a run that died; nothing holding it takes longer (a request times out at 30 s). */
12
+ export const LOCK_STALE_MS = 60_000;
13
+ /** How long to wait for another run to finish with the file. */
14
+ export const LOCK_WAIT_MS = 75_000;
15
+ export class CredentialsError extends Error {
16
+ code;
17
+ constructor(message, code) {
18
+ super(message);
19
+ this.code = code;
20
+ }
21
+ }
22
+ export function credentialsPath(env = process.env) {
23
+ if (env.COMMENTKIT_CONFIG_DIR)
24
+ return join(env.COMMENTKIT_CONFIG_DIR, "credentials.json");
25
+ if (process.platform === "win32" && env.APPDATA)
26
+ return join(env.APPDATA, "commentkit", "credentials.json");
27
+ return join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "commentkit", "credentials.json");
28
+ }
29
+ /**
30
+ * The saved sign-ins. A file that is not a JSON object is never read as empty: that would make the next
31
+ * save drop every other server's sign-in. It is copied aside and the run stops with where the copy is.
32
+ */
33
+ function read(path) {
34
+ if (!existsSync(path))
35
+ return {};
36
+ const text = readFileSync(path, "utf8");
37
+ let data;
38
+ try {
39
+ data = JSON.parse(text);
40
+ }
41
+ catch {
42
+ data = undefined;
43
+ }
44
+ if (data && typeof data === "object" && !Array.isArray(data))
45
+ return data;
46
+ // Named by content, so running again does not pile up copies of the same damaged file.
47
+ const copy = `${path}.corrupt-${createHash("sha256").update(text).digest("hex").slice(0, 12)}`;
48
+ try {
49
+ if (!existsSync(copy))
50
+ copyFileSync(path, copy);
51
+ chmodSafe(copy);
52
+ }
53
+ catch {
54
+ throw new CredentialsError(`The saved sign-in file ${path} is damaged and could not be backed up. Move it away, then run \`npx @commentkit/comment-kit login\`.`, "credentials_corrupt");
55
+ }
56
+ throw new CredentialsError(`The saved sign-in file ${path} is damaged (not valid JSON), so it was left unchanged. A copy is at ${copy}. Delete or fix ${path}, then run \`npx @commentkit/comment-kit login\`.`, "credentials_corrupt");
57
+ }
58
+ function chmodSafe(path) {
59
+ try {
60
+ chmodSync(path, 0o600);
61
+ }
62
+ catch {
63
+ // Windows: permissions come from the user profile folder.
64
+ }
65
+ }
66
+ function write(path, store) {
67
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
68
+ const tmp = `${path}.${process.pid}.tmp`;
69
+ writeFileSync(tmp, `${JSON.stringify(store, null, 2)}\n`, { mode: 0o600 });
70
+ renameSync(tmp, path);
71
+ chmodSafe(path);
72
+ }
73
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
74
+ const sleepSync = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
75
+ /** A guard older than this was left by a run that died in the middle of a takeover or release. */
76
+ const GUARD_STALE_MS = 5_000;
77
+ /**
78
+ * True when creating `path` failed because something is already there. On Windows a file that is being
79
+ * deleted (delete-pending) refuses a new open with EPERM or EACCES instead of EEXIST: wait, do not crash.
80
+ */
81
+ function taken(error) {
82
+ const code = error.code;
83
+ return code === "EEXIST" || (process.platform === "win32" && (code === "EPERM" || code === "EACCES"));
84
+ }
85
+ /** Creates `path` only if it does not exist, holding `content`. False when it exists. */
86
+ function create(path, content) {
87
+ let fd;
88
+ try {
89
+ fd = openSync(path, "wx", 0o600);
90
+ }
91
+ catch (error) {
92
+ if (taken(error))
93
+ return false;
94
+ throw error;
95
+ }
96
+ try {
97
+ writeSync(fd, content);
98
+ }
99
+ finally {
100
+ closeSync(fd);
101
+ }
102
+ return true;
103
+ }
104
+ function readOrNull(path) {
105
+ try {
106
+ return readFileSync(path, "utf8");
107
+ }
108
+ catch {
109
+ return null;
110
+ }
111
+ }
112
+ function unlinkQuiet(path) {
113
+ try {
114
+ unlinkSync(path);
115
+ }
116
+ catch {
117
+ // Already gone.
118
+ }
119
+ }
120
+ /**
121
+ * Removes the lock only if it still holds `expected`, the content this run saw (its own, or a stale
122
+ * owner's). Every removal of the lock goes through here under a short guard file, so reading and
123
+ * removing cannot interleave with another run's: nobody removes a lock that was replaced meanwhile.
124
+ * Creation never replaces an existing lock (exclusive create), so it needs no guard.
125
+ */
126
+ function removeIf(lock, expected) {
127
+ const guard = `${lock}.guard`;
128
+ const mark = `${process.pid} ${hostname()} ${Date.now()}\n`;
129
+ let guarded = false;
130
+ for (let i = 0; i < 200 && !guarded; i++) {
131
+ guarded = create(guard, mark);
132
+ if (guarded)
133
+ break;
134
+ try {
135
+ if (Date.now() - statSync(guard).mtimeMs > GUARD_STALE_MS)
136
+ unlinkQuiet(guard);
137
+ }
138
+ catch {
139
+ // Released meanwhile.
140
+ }
141
+ sleepSync(5);
142
+ }
143
+ try {
144
+ // Without the guard (a run that died holding it, and not yet stale) still compare first: best effort.
145
+ if (readOrNull(lock) !== expected)
146
+ return false;
147
+ unlinkQuiet(lock);
148
+ return true;
149
+ }
150
+ finally {
151
+ if (guarded && readOrNull(guard) === mark)
152
+ unlinkQuiet(guard);
153
+ }
154
+ }
155
+ /** The lock's owner is a process on this computer that has exited. */
156
+ function ownerGone(content) {
157
+ try {
158
+ const [pid, host] = content.split(/\s+/);
159
+ if (host !== hostname() || !/^\d+$/.test(pid ?? ""))
160
+ return false;
161
+ process.kill(Number(pid), 0);
162
+ return false;
163
+ }
164
+ catch (error) {
165
+ return error.code === "ESRCH";
166
+ }
167
+ }
168
+ /** Locks this process holds (lock path → content), removed if the process is interrupted or exits. */
169
+ const held = new Map();
170
+ function releaseAllHeld() {
171
+ for (const [lock, content] of held)
172
+ removeIf(lock, content);
173
+ held.clear();
174
+ }
175
+ function onSignal(signal) {
176
+ releaseAllHeld();
177
+ unwatch();
178
+ // Nobody else handles this signal: end the process the way it would have ended without us.
179
+ if (process.listenerCount(signal) === 0)
180
+ process.kill(process.pid, signal);
181
+ }
182
+ function watch() {
183
+ if (held.size !== 1)
184
+ return;
185
+ process.on("exit", releaseAllHeld);
186
+ process.on("SIGINT", onSignal);
187
+ process.on("SIGTERM", onSignal);
188
+ }
189
+ function unwatch() {
190
+ process.off("exit", releaseAllHeld);
191
+ process.off("SIGINT", onSignal);
192
+ process.off("SIGTERM", onSignal);
193
+ }
194
+ /** @internal For tests: the lock steps a run takes, so races can be played one step at a time. */
195
+ export const lockSteps = {
196
+ /** This run's lock content: pid and host first (what ownerGone and older CLIs read), then a unique token. */
197
+ content: () => `${process.pid} ${hostname()} ${Date.now()} ${process.pid}-${randomBytes(8).toString("hex")}\n`,
198
+ create,
199
+ /** Takes over a lock judged stale when it held `seen`. False when it has changed since. */
200
+ takeOver: (lock, seen) => removeIf(lock, seen),
201
+ /** Releases this run's lock: removed only while it still holds `mine`. */
202
+ release: (lock, mine) => removeIf(lock, mine),
203
+ };
204
+ /**
205
+ * Run `fn` while no other `commentkit` run is changing the credentials file. Re-read the file inside
206
+ * `fn`: what was read before the lock may already be out of date.
207
+ */
208
+ export async function withLock(fn, path = credentialsPath(), { staleMs = LOCK_STALE_MS, waitMs = LOCK_WAIT_MS } = {}) {
209
+ const lock = `${path}.lock`;
210
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
211
+ const deadline = Date.now() + waitMs;
212
+ const mine = lockSteps.content();
213
+ for (;;) {
214
+ if (create(lock, mine))
215
+ break;
216
+ const seen = readOrNull(lock);
217
+ let age = null;
218
+ try {
219
+ age = Date.now() - statSync(lock).mtimeMs;
220
+ }
221
+ catch {
222
+ // Released meanwhile, or (Windows) still being deleted: try again shortly.
223
+ }
224
+ // Taken over only if it still holds what was judged stale: another run may have replaced it already.
225
+ if (seen !== null && age !== null && (age > staleMs || ownerGone(seen)) && lockSteps.takeOver(lock, seen))
226
+ continue;
227
+ if (Date.now() > deadline) {
228
+ throw new CredentialsError(`Another commentkit command is still using ${path}. Wait for it to finish, or delete ${lock} if none is running.`, "credentials_locked");
229
+ }
230
+ await sleep(25 + Math.floor(Math.random() * 50));
231
+ }
232
+ held.set(lock, mine);
233
+ watch();
234
+ try {
235
+ return await fn();
236
+ }
237
+ finally {
238
+ held.delete(lock);
239
+ if (held.size === 0)
240
+ unwatch();
241
+ // A run that outlived its lease may find its lock taken over: the successor's lock stays.
242
+ lockSteps.release(lock, mine);
243
+ }
244
+ }
245
+ export function load(endpoint, path = credentialsPath()) {
246
+ return read(path)[endpoint] ?? {};
247
+ }
248
+ /** Merge `value` into one server's sign-in. The caller must hold the lock (see withLock). */
249
+ export function saveLocked(endpoint, value, path = credentialsPath()) {
250
+ const store = read(path);
251
+ store[endpoint] = { ...store[endpoint], ...value };
252
+ write(path, store);
253
+ }
254
+ export function save(endpoint, value, path = credentialsPath()) {
255
+ return withLock(() => saveLocked(endpoint, value, path), path);
256
+ }
257
+ /** Forget the sign-in but keep the registered client id, so the next login is quicker. */
258
+ export function forget(endpoint, path = credentialsPath()) {
259
+ return withLock(() => {
260
+ const store = read(path);
261
+ const had = Boolean(store[endpoint]?.access_token);
262
+ if (!store[endpoint])
263
+ return had;
264
+ store[endpoint] = { client_id: store[endpoint].client_id };
265
+ write(path, store);
266
+ return had;
267
+ }, path);
268
+ }