@wbcode/avron 0.0.0-stage → 0.1.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.
@@ -0,0 +1,583 @@
1
+ "use strict";
2
+
3
+ // packages/adapter-claude-code/src/statusline.ts
4
+ var import_node_child_process2 = require("node:child_process");
5
+ var import_node_fs2 = require("node:fs");
6
+ var import_node_path4 = require("node:path");
7
+
8
+ // packages/protocol/src/art.ts
9
+ var ART_LIMITS = { rows: 6, cols: 60 };
10
+ var ART_CHAR = /^[⠀-⣿▀-▟ ]*$/;
11
+ var COLOR = /^#[0-9a-f]{6}$/i;
12
+ function cleanArt(raw) {
13
+ if (typeof raw !== "object" || raw === null) return null;
14
+ const r = raw;
15
+ if (!Array.isArray(r.rows) || r.rows.length === 0 || r.rows.length > ART_LIMITS.rows) return null;
16
+ const rows = [];
17
+ for (const row of r.rows) {
18
+ if (typeof row !== "string" || !ART_CHAR.test(row) || [...row].length > ART_LIMITS.cols) return null;
19
+ rows.push(row.replace(/ +$/, ""));
20
+ }
21
+ while (rows.length && !rows[0]) rows.shift();
22
+ while (rows.length && !rows[rows.length - 1]) rows.pop();
23
+ if (!rows.length) return null;
24
+ const color = typeof r.color === "string" && COLOR.test(r.color) ? r.color.toLowerCase() : void 0;
25
+ return { rows, ...color ? { color } : {} };
26
+ }
27
+ function artWidth(art) {
28
+ return Math.max(0, ...art.rows.map((r) => [...r].length));
29
+ }
30
+ function renderArt(art, color) {
31
+ if (color !== "truecolor" || !art.color) return [...art.rows];
32
+ const n = Number.parseInt(art.color.slice(1), 16);
33
+ const on = `\x1B[38;2;${n >> 16 & 255};${n >> 8 & 255};${n & 255}m`;
34
+ return art.rows.map((row) => row ? `${on}${row}\x1B[0m` : row);
35
+ }
36
+ var BLANK = String.fromCodePoint(10240);
37
+ function motionFrame(art, motion, t, stepMs = 2e3) {
38
+ const step = Math.max(0, Math.floor(t / stepMs));
39
+ if (motion === "reveal") {
40
+ const shown = Math.min(art.rows.length, step + 1);
41
+ return {
42
+ ...art,
43
+ rows: art.rows.map((r, i) => i < shown ? r : BLANK.repeat(Math.max(1, [...r].length)))
44
+ };
45
+ }
46
+ const width = artWidth(art);
47
+ const cols = Math.min(width, Math.ceil((step + 1) * width / 4));
48
+ return {
49
+ ...art,
50
+ rows: art.rows.map((r) => [...r.padEnd(width, " ")].map((ch, i) => i < cols ? ch : BLANK).join(""))
51
+ };
52
+ }
53
+
54
+ // packages/protocol/src/constants.ts
55
+ var PROTOCOL_VERSION = "2.0.0";
56
+ var ADAPTER_TIMEOUT_MS = 15;
57
+ var MANIFEST_SYNC_INTERVAL_MS = 30 * 6e4;
58
+ var BATCH_FLUSH_INTERVAL_MS = 60 * 6e4;
59
+ var DAEMON_IDLE_EXIT_MS = 3 * 60 * 6e4;
60
+ var OFFLINE_QUEUE_MAX_BYTES = 5 * 1024 * 1024;
61
+ var MAX_LINE_BYTES = 8 * 1024;
62
+ var ALLOWED_LINK_PREFIX = "https://avron.dev/go/";
63
+ var SPONSOR_LABEL = "Sponsored";
64
+ var SPONSOR_LABELS = {
65
+ ko: "\uAD11\uACE0",
66
+ ja: "\u5E83\u544A",
67
+ "zh-CN": "\u5E7F\u544A",
68
+ "zh-TW": "\u5EE3\u544A",
69
+ es: "Patrocinado",
70
+ pt: "Patrocinado",
71
+ de: "Anzeige",
72
+ fr: "Sponsoris\xE9"
73
+ };
74
+
75
+ // packages/protocol/src/validate.ts
76
+ function isObject(v) {
77
+ return typeof v === "object" && v !== null && !Array.isArray(v);
78
+ }
79
+ function parsePayloadResponse(line) {
80
+ if (line.length === 0 || Buffer.byteLength(line, "utf8") > MAX_LINE_BYTES) return null;
81
+ let raw;
82
+ try {
83
+ raw = JSON.parse(line);
84
+ } catch {
85
+ return null;
86
+ }
87
+ if (!isObject(raw) || raw.eventType !== "PAYLOAD_RESPONSE") return null;
88
+ if (!isObject(raw.payload) || typeof raw.payload.active !== "boolean") return null;
89
+ if (typeof raw.sessionId !== "string") return null;
90
+ return raw;
91
+ }
92
+ function serialize(msg) {
93
+ return `${JSON.stringify(msg)}
94
+ `;
95
+ }
96
+
97
+ // packages/protocol/src/endpoint.ts
98
+ var import_node_crypto = require("node:crypto");
99
+ var import_node_os = require("node:os");
100
+ var import_node_path = require("node:path");
101
+ function avronHome(env = process.env) {
102
+ return env.AVRON_HOME && env.AVRON_HOME.length > 0 ? env.AVRON_HOME : (0, import_node_path.join)((0, import_node_os.homedir)(), ".avron");
103
+ }
104
+ function avronPaths(env = process.env) {
105
+ const home = avronHome(env);
106
+ return {
107
+ home,
108
+ runDir: (0, import_node_path.join)(home, "run"),
109
+ logDir: (0, import_node_path.join)(home, "logs"),
110
+ dataDir: (0, import_node_path.join)(home, "data"),
111
+ cacheDir: (0, import_node_path.join)(home, "cache"),
112
+ keyDir: (0, import_node_path.join)(home, "keys"),
113
+ daemonLog: (0, import_node_path.join)(home, "logs", "daemon.log"),
114
+ impressionsLog: (0, import_node_path.join)(home, "logs", "impressions.ndjson"),
115
+ ledgerSnapshot: (0, import_node_path.join)(home, "data", "ledger.json"),
116
+ manifestCache: (0, import_node_path.join)(home, "cache", "manifest.json"),
117
+ eventQueue: (0, import_node_path.join)(home, "data", "queue.ndjson")
118
+ };
119
+ }
120
+ var UDS_MAX = 100;
121
+ function ipcEndpoint(env = process.env, platform = process.platform) {
122
+ const home = avronHome(env);
123
+ const tag = (0, import_node_crypto.createHash)("sha256").update(home).digest("hex").slice(0, 12);
124
+ if (platform === "win32") return `\\\\.\\pipe\\avron-uasp-${tag}.sock`;
125
+ const preferred = (0, import_node_path.join)(home, "run", "avron-uasp.sock");
126
+ if (Buffer.byteLength(preferred) <= UDS_MAX) return preferred;
127
+ return (0, import_node_path.join)((0, import_node_os.tmpdir)(), `avron-uasp-${tag}.sock`);
128
+ }
129
+
130
+ // packages/protocol/src/client.ts
131
+ var import_node_net = require("node:net");
132
+
133
+ // packages/protocol/src/quiet.ts
134
+ function quietHere(env = process.env) {
135
+ if (env.AVRON_ALLOW_CI === "1") return false;
136
+ const ci = (env.CI ?? "").trim().toLowerCase();
137
+ return ci !== "" && ci !== "0" && ci !== "false";
138
+ }
139
+
140
+ // packages/protocol/src/client.ts
141
+ function request(msg, opts = {}) {
142
+ if (quietHere()) return Promise.resolve(null);
143
+ const endpoint = opts.endpoint ?? ipcEndpoint();
144
+ const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
145
+ return new Promise((resolve3) => {
146
+ let done = false;
147
+ let buf = "";
148
+ const finish = (value) => {
149
+ if (done) return;
150
+ done = true;
151
+ clearTimeout(timer);
152
+ socket.destroy();
153
+ resolve3(value);
154
+ };
155
+ const timer = setTimeout(() => finish(null), timeoutMs);
156
+ const socket = (0, import_node_net.connect)(endpoint);
157
+ socket.setEncoding("utf8");
158
+ socket.on("connect", () => {
159
+ socket.write(serialize(msg));
160
+ });
161
+ socket.on("data", (chunk) => {
162
+ buf += chunk;
163
+ const nl = buf.indexOf("\n");
164
+ if (nl >= 0) finish(parsePayloadResponse(buf.slice(0, nl)));
165
+ else if (buf.length > MAX_LINE_BYTES) finish(null);
166
+ });
167
+ socket.on("error", () => finish(null));
168
+ socket.on("close", () => finish(null));
169
+ });
170
+ }
171
+ function send(msg, opts = {}) {
172
+ if (quietHere()) return Promise.resolve(false);
173
+ const endpoint = opts.endpoint ?? ipcEndpoint();
174
+ const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
175
+ return new Promise((resolve3) => {
176
+ let done = false;
177
+ const finish = (ok) => {
178
+ if (done) return;
179
+ done = true;
180
+ clearTimeout(timer);
181
+ if (!ok) socket.destroy();
182
+ resolve3(ok);
183
+ };
184
+ const timer = setTimeout(() => finish(false), timeoutMs);
185
+ const socket = (0, import_node_net.connect)(endpoint);
186
+ socket.on("connect", () => {
187
+ socket.end(serialize(msg), () => finish(true));
188
+ });
189
+ socket.on("error", () => finish(false));
190
+ });
191
+ }
192
+
193
+ // packages/protocol/src/spawn.ts
194
+ var import_node_child_process = require("node:child_process");
195
+ var import_node_fs = require("node:fs");
196
+ var import_node_path2 = require("node:path");
197
+ var FIRST_MESSAGE_ENV = "AVRON_FIRST_MESSAGE";
198
+ var runtimeFile = (env = process.env) => (0, import_node_path2.join)(avronHome(env), "runtime.json");
199
+ function chooseNode(opts = {}) {
200
+ const execPath = opts.execPath ?? process.execPath;
201
+ const electron = "electron" in opts ? opts.electron : process.versions.electron;
202
+ if (!electron && /^node(\.exe)?$/i.test((0, import_node_path2.basename)(execPath))) return execPath;
203
+ try {
204
+ const node = JSON.parse((0, import_node_fs.readFileSync)(opts.runtime ?? runtimeFile(), "utf8")).node;
205
+ if (typeof node === "string" && node.length > 0 && (0, import_node_fs.existsSync)(node)) return node;
206
+ } catch {
207
+ }
208
+ return "node";
209
+ }
210
+ function spawnDaemon(entry, env = process.env) {
211
+ try {
212
+ const child = (0, import_node_child_process.spawn)(chooseNode({ runtime: runtimeFile(env) }), [entry], {
213
+ detached: true,
214
+ stdio: "ignore",
215
+ windowsHide: true,
216
+ env
217
+ });
218
+ child.on("error", () => {
219
+ });
220
+ child.unref();
221
+ return true;
222
+ } catch {
223
+ return false;
224
+ }
225
+ }
226
+ function ensureDaemon(entry, env = process.env, firstMessage) {
227
+ if (quietHere(env)) return;
228
+ try {
229
+ const marker = (0, import_node_path2.join)(avronPaths(env).runDir, "spawn.marker");
230
+ try {
231
+ if (Date.now() - (0, import_node_fs.statSync)(marker).mtimeMs < 1e4) return;
232
+ } catch {
233
+ }
234
+ (0, import_node_fs.mkdirSync)((0, import_node_path2.dirname)(marker), { recursive: true });
235
+ (0, import_node_fs.closeSync)((0, import_node_fs.openSync)(marker, "a"));
236
+ (0, import_node_fs.utimesSync)(marker, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
237
+ spawnDaemon(entry, firstMessage ? { ...env, [FIRST_MESSAGE_ENV]: firstMessage } : env);
238
+ } catch {
239
+ }
240
+ }
241
+
242
+ // packages/adapter-kit/src/render.ts
243
+ var ESC = "\x1B";
244
+ var RESET = `${ESC}[0m`;
245
+ function sanitizeText(input, maxChars = 120) {
246
+ if (typeof input !== "string") return "";
247
+ let out = "";
248
+ for (const ch of input) {
249
+ const cp = ch.codePointAt(0);
250
+ if (cp < 32 || cp >= 127 && cp <= 159) {
251
+ out += " ";
252
+ continue;
253
+ }
254
+ if (cp >= 8203 && cp <= 8207 || cp >= 8234 && cp <= 8238 || cp >= 8294 && cp <= 8297)
255
+ continue;
256
+ if (cp === 65279 || cp === 8232 || cp === 8233) continue;
257
+ out += ch;
258
+ }
259
+ out = out.replace(/\s+/g, " ").trim();
260
+ return [...out].slice(0, maxChars).join("");
261
+ }
262
+ function snippetLines(input, max = 3) {
263
+ if (typeof input !== "string") return [];
264
+ return input.split(String.fromCharCode(10)).map((l) => sanitizeText(l, 65)).filter((l) => l.length > 0 && [...l].length <= 64).slice(0, max);
265
+ }
266
+ function safeLink(url) {
267
+ if (typeof url !== "string" || !url.startsWith(ALLOWED_LINK_PREFIX)) return null;
268
+ if (!/^https:\/\/avron\.dev\/go\/[A-Za-z0-9._~\-/?=&%]*$/.test(url)) return null;
269
+ return url;
270
+ }
271
+ function isWide(cp) {
272
+ return cp >= 4352 && cp <= 4447 || // Hangul Jamo
273
+ cp >= 11904 && cp <= 42191 || // CJK radicals .. Yi
274
+ cp >= 44032 && cp <= 55203 || // Hangul syllables
275
+ cp >= 63744 && cp <= 64255 || // CJK compatibility ideographs
276
+ cp >= 65072 && cp <= 65103 || // CJK compatibility forms
277
+ cp >= 65280 && cp <= 65376 || // Fullwidth forms
278
+ cp >= 65504 && cp <= 65510 || cp >= 127744 && cp <= 129791 || // pictographs
279
+ cp >= 131072 && cp <= 262141;
280
+ }
281
+ function isZeroWidth(cp) {
282
+ return cp >= 768 && cp <= 879 || cp >= 65024 && cp <= 65039 || cp === 8205;
283
+ }
284
+ function displayWidth(text) {
285
+ let w = 0;
286
+ for (const ch of stripAnsi(text)) {
287
+ const cp = ch.codePointAt(0);
288
+ if (isZeroWidth(cp)) continue;
289
+ w += isWide(cp) ? 2 : 1;
290
+ }
291
+ return w;
292
+ }
293
+ var ANSI_RE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-9;?]*[ -/]*[@-~]/g;
294
+ function stripAnsi(text) {
295
+ return text.replace(ANSI_RE, "");
296
+ }
297
+ function truncate(text, columns) {
298
+ if (displayWidth(text) <= columns) return text;
299
+ if (columns <= 1) return "";
300
+ let out = "";
301
+ let w = 0;
302
+ for (const ch of text) {
303
+ const cw = displayWidth(ch);
304
+ if (w + cw > columns - 1) break;
305
+ out += ch;
306
+ w += cw;
307
+ }
308
+ return `${out.trimEnd()}\u2026`;
309
+ }
310
+ var SEP = "\u2502";
311
+ var KNOWN_LABELS = /* @__PURE__ */ new Set([SPONSOR_LABEL, ...Object.values(SPONSOR_LABELS)]);
312
+ function layout(c, width) {
313
+ const label = KNOWN_LABELS.has(c.label ?? "") ? c.label : SPONSOR_LABEL;
314
+ const badge = sanitizeText(c.sponsorName, 24).toUpperCase();
315
+ const copyFull = sanitizeText(c.headline, 80);
316
+ const ctaRaw = sanitizeText(c.ctaText, 28);
317
+ const cta = ctaRaw ? `${ctaRaw.replace(/\s*↗$/, "")} \u2197` : "";
318
+ if (!badge) return null;
319
+ const fits = (p) => displayWidth(plain(p)) <= width;
320
+ const wide = { label, badge, copy: copyFull, cta };
321
+ if (copyFull && fits(wide)) return wide;
322
+ if (copyFull) {
323
+ const fixed = displayWidth(plain({ label, badge, copy: "", cta })) + 3;
324
+ const room = width - fixed;
325
+ if (room >= 16) {
326
+ const standard = { label, badge, copy: truncate(copyFull, room), cta };
327
+ if (fits(standard)) return standard;
328
+ }
329
+ }
330
+ const compact = { label, badge, copy: "", cta };
331
+ if (cta && fits(compact)) return compact;
332
+ return null;
333
+ }
334
+ function plain(p) {
335
+ const left = `${p.label} ${p.badge} `;
336
+ if (p.copy && p.cta) return `${left}${SEP} ${p.copy} \xB7 ${p.cta}`;
337
+ if (p.copy) return `${left}${SEP} ${p.copy}`;
338
+ if (p.cta) return `${left}\xB7 ${p.cta}`;
339
+ return left;
340
+ }
341
+ var style = {
342
+ truecolor: {
343
+ badge: `${ESC}[48;2;39;39;42m${ESC}[38;2;244;244;245m`,
344
+ dim: `${ESC}[38;2;113;113;122m`,
345
+ copy: `${ESC}[38;2;161;161;170m`,
346
+ cta: `${ESC}[38;2;52;211;153m`
347
+ },
348
+ basic: { badge: `${ESC}[7m`, dim: `${ESC}[2m`, copy: `${ESC}[2m`, cta: `${ESC}[32m` }
349
+ };
350
+ function link(text, url, enabled) {
351
+ if (!enabled || !url) return text;
352
+ return `${ESC}]8;;${url}${ESC}\\${text}${ESC}]8;;${ESC}\\`;
353
+ }
354
+ function renderLine(content, opts) {
355
+ const p = layout(content, opts.width);
356
+ if (!p) return "";
357
+ const url = safeLink(content.actionUrl);
358
+ if (opts.color === "none") {
359
+ const text = plain(p);
360
+ if (!p.cta) return text;
361
+ return text.slice(0, text.length - p.cta.length) + link(p.cta, url, opts.hyperlinks);
362
+ }
363
+ const s = style[opts.color];
364
+ let out = `${s.dim}${p.label}${RESET} ${s.badge} ${p.badge} ${RESET}`;
365
+ if (p.copy) out += `${s.dim}${SEP}${RESET} ${s.copy}${p.copy}${RESET}`;
366
+ if (p.cta)
367
+ out += `${s.dim}${p.copy ? " \xB7 " : "\xB7 "}${RESET}${link(`${s.cta}${p.cta}${RESET}`, url, opts.hyperlinks)}`;
368
+ return out;
369
+ }
370
+ function safePromo(code) {
371
+ return typeof code === "string" && /^[A-Za-z0-9_-]{1,40}$/.test(code) ? code : "";
372
+ }
373
+ var DETAIL_INDENT = " ";
374
+ function detailText(d) {
375
+ const parts = [];
376
+ if (d.snippet) parts.push(`$ ${d.snippet}`);
377
+ if (d.promo) parts.push(`code ${d.promo}`);
378
+ return parts.length ? `${DETAIL_INDENT}${parts.join(" \xB7 ")}` : "";
379
+ }
380
+ function detailLayout(c, width) {
381
+ const snippet = snippetLines(c.snippet, 1)[0] ?? "";
382
+ const promo = safePromo(c.promoCode);
383
+ for (const d of [
384
+ { snippet, promo },
385
+ { snippet, promo: "" },
386
+ { snippet: "", promo }
387
+ ]) {
388
+ const text = detailText(d);
389
+ if (text && displayWidth(text) <= width) return d;
390
+ }
391
+ return null;
392
+ }
393
+ function renderDetail(content, opts) {
394
+ const d = detailLayout(content, opts.width);
395
+ if (!d) return "";
396
+ if (opts.color === "none") return detailText(d);
397
+ const s = style[opts.color];
398
+ const parts = [];
399
+ if (d.snippet) parts.push(`${s.dim}$${RESET} ${s.copy}${d.snippet}${RESET}`);
400
+ if (d.promo) parts.push(`${s.dim}code${RESET} ${s.cta}${d.promo}${RESET}`);
401
+ return `${DETAIL_INDENT}${parts.join(`${s.dim} \xB7 ${RESET}`)}`;
402
+ }
403
+ function detectTerminal(env) {
404
+ if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "") return { color: "none", hyperlinks: false };
405
+ const truecolor = /truecolor|24bit/i.test(env.COLORTERM ?? "") || env.WT_SESSION !== void 0;
406
+ const dumb = env.TERM === "dumb";
407
+ return { color: dumb ? "none" : truecolor ? "truecolor" : "basic", hyperlinks: !dumb };
408
+ }
409
+ function chain(content, original, columns, term) {
410
+ if (!content) return original;
411
+ const lines = original.split(/\r?\n/);
412
+ const first = lines[0] ?? "";
413
+ const firstWidth = displayWidth(first);
414
+ const margin = 4;
415
+ const joiner = firstWidth > 0 ? ` ${SEP} ` : "";
416
+ const budget = columns - firstWidth - displayWidth(joiner) - margin;
417
+ const sponsor = budget >= 12 ? renderLine(content, { width: budget, ...term }) : "";
418
+ if (!sponsor) return original;
419
+ const dimSep = term.color === "none" ? joiner : firstWidth > 0 ? ` ${style[term.color].dim}${SEP}${RESET} ` : "";
420
+ lines[0] = `${sponsor}${dimSep}${first}`;
421
+ const detail = renderDetail(content, { width: columns - margin, ...term });
422
+ if (detail) lines.splice(1, 0, detail);
423
+ const art = bannerFits(content, columns);
424
+ if (art) lines.unshift(...renderArt(art, term.color).map((r) => r ? `${DETAIL_INDENT}${r}` : r));
425
+ return lines.join("\n");
426
+ }
427
+ function bannerFits(content, columns) {
428
+ const art = cleanArt(content.art);
429
+ return art && artWidth(art) + DETAIL_INDENT.length + 4 <= columns ? art : null;
430
+ }
431
+
432
+ // packages/adapter-kit/src/stdin.ts
433
+ function readStdin(limitBytes = 1024 * 1024) {
434
+ return new Promise((resolve3) => {
435
+ const chunks = [];
436
+ let size = 0;
437
+ const done = () => resolve3(Buffer.concat(chunks));
438
+ process.stdin.on("data", (c) => {
439
+ size += c.length;
440
+ if (size <= limitBytes) chunks.push(c);
441
+ });
442
+ process.stdin.on("end", done);
443
+ process.stdin.on("error", done);
444
+ if (process.stdin.isTTY) done();
445
+ });
446
+ }
447
+ var ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
448
+ function pickIds(stdin, fields) {
449
+ try {
450
+ const j = JSON.parse(stdin.toString("utf8"));
451
+ const sessionId = j[fields.session];
452
+ if (typeof sessionId !== "string" || !ID_RE.test(sessionId)) return null;
453
+ const turn = fields.turn ? j[fields.turn] : void 0;
454
+ const event = fields.event ? j[fields.event] : void 0;
455
+ return {
456
+ sessionId,
457
+ ...typeof turn === "string" && ID_RE.test(turn) ? { turnId: turn } : {},
458
+ ...typeof event === "string" ? { event: event.slice(0, 40) } : {}
459
+ };
460
+ } catch {
461
+ return null;
462
+ }
463
+ }
464
+
465
+ // packages/adapter-kit/src/reversible.ts
466
+ var import_node_path3 = require("node:path");
467
+ var PROTECTED_DIRS = [
468
+ ".claude",
469
+ ".cursor",
470
+ ".codex",
471
+ ".copilot",
472
+ ".kiro",
473
+ ".codeium",
474
+ ".gemini",
475
+ ".orca",
476
+ (0, import_node_path3.join)(".config", "opencode"),
477
+ (0, import_node_path3.join)("AppData", "Roaming", "orca"),
478
+ (0, import_node_path3.join)("Library", "Application Support", "orca")
479
+ ];
480
+
481
+ // packages/adapter-claude-code/src/io.ts
482
+ function extractIds(stdin) {
483
+ const ids = pickIds(stdin, { session: "session_id", turn: "prompt_id", event: "hook_event_name" });
484
+ if (!ids) return null;
485
+ return { sessionId: ids.sessionId, promptId: ids.turnId, hookEventName: ids.event };
486
+ }
487
+
488
+ // packages/adapter-claude-code/src/settings.ts
489
+ var OURS_RE = /avron-(statusline|hook)\.cjs/;
490
+ function isOurCommand(command) {
491
+ return typeof command === "string" && OURS_RE.test(command);
492
+ }
493
+
494
+ // packages/adapter-claude-code/src/statusline.ts
495
+ var ORIGINAL_TIMEOUT_MS = 5e3;
496
+ function originalCommand() {
497
+ try {
498
+ const file = (0, import_node_path4.join)(avronPaths().home, "adapters", "claude-code.json");
499
+ const state = JSON.parse((0, import_node_fs2.readFileSync)(file, "utf8"));
500
+ const cmd = state.originalStatusLine?.command;
501
+ return typeof cmd === "string" && cmd.length > 0 && !isOurCommand(cmd) ? cmd : null;
502
+ } catch {
503
+ return null;
504
+ }
505
+ }
506
+ function runOriginal(command, stdin) {
507
+ return new Promise((resolve3) => {
508
+ let out = "";
509
+ let settled = false;
510
+ const finish = (value) => {
511
+ if (settled) return;
512
+ settled = true;
513
+ clearTimeout(timer);
514
+ resolve3(value);
515
+ };
516
+ const shell = process.env.SHELL || (process.platform === "win32" ? "powershell.exe" : "/bin/sh");
517
+ const child = (0, import_node_child_process2.spawn)(command, { shell, stdio: ["pipe", "pipe", "ignore"], windowsHide: true });
518
+ const timer = setTimeout(() => {
519
+ child.kill();
520
+ finish("");
521
+ }, ORIGINAL_TIMEOUT_MS);
522
+ child.stdout.setEncoding("utf8");
523
+ child.stdout.on("data", (d) => {
524
+ out += d;
525
+ });
526
+ child.on("error", () => finish(""));
527
+ child.on("close", () => finish(out));
528
+ child.stdin.on("error", () => {
529
+ });
530
+ child.stdin.end(stdin);
531
+ });
532
+ }
533
+ async function main() {
534
+ const stdin = await readStdin();
535
+ const ids = extractIds(stdin);
536
+ const original = originalCommand();
537
+ const res = ids ? await request({
538
+ protocolVersion: PROTOCOL_VERSION,
539
+ eventType: "PAYLOAD_REQUEST",
540
+ agentName: "claude-code",
541
+ agentTier: "cli",
542
+ sessionId: ids.sessionId,
543
+ ...ids.promptId ? { turnId: ids.promptId } : {},
544
+ timestamp: Date.now(),
545
+ payload: { slot: "statusline" }
546
+ }) : null;
547
+ const originalOut = original ? await runOriginal(original, stdin) : "";
548
+ if (ids && res === null) ensureDaemon((0, import_node_path4.join)(__dirname, "avron-daemon.cjs"));
549
+ const p = res?.payload;
550
+ const content = p?.active && p.sponsorName && p.headline ? {
551
+ label: p.label,
552
+ sponsorName: p.sponsorName,
553
+ headline: p.headline,
554
+ ctaText: p.ctaText,
555
+ actionUrl: p.actionUrl,
556
+ snippet: p.snippet,
557
+ promoCode: p.promoCode,
558
+ // An animated banner shows the frame for how long the line has been up.
559
+ art: p.art && p.motion ? motionFrame(p.art, p.motion, p.motionMs ?? 0) : p.art
560
+ } : null;
561
+ const columns = Number.parseInt(process.env.COLUMNS ?? "", 10) || 80;
562
+ const out = chain(content, originalOut, columns, detectTerminal(process.env));
563
+ process.stdout.write(out);
564
+ const rows = (text) => text ? text.split(String.fromCharCode(10)).length : 0;
565
+ if (ids && content && rows(out) > Math.max(rows(originalOut), 1))
566
+ await send({
567
+ protocolVersion: PROTOCOL_VERSION,
568
+ eventType: "PAYLOAD_REQUEST",
569
+ agentName: "claude-code",
570
+ agentTier: "cli",
571
+ sessionId: ids.sessionId,
572
+ ...ids.promptId ? { turnId: ids.promptId } : {},
573
+ timestamp: Date.now(),
574
+ payload: {
575
+ slot: "statusline",
576
+ drawn: bannerFits(content, columns) ? p?.motion ? "motion" : "banner" : "card"
577
+ }
578
+ });
579
+ }
580
+ main().catch(() => {
581
+ }).finally(() => {
582
+ process.exitCode = 0;
583
+ });
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "avron-local",
3
+ "description": "Avron for the Claude desktop app, installed from this computer.",
4
+ "owner": {
5
+ "name": "WBCode"
6
+ },
7
+ "plugins": [
8
+ {
9
+ "name": "avron",
10
+ "source": "./avron",
11
+ "description": "Shows Avron's sponsor line in the Claude desktop app while the agent is thinking."
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "avron",
3
+ "version": "0.1.1",
4
+ "description": "Avron for the Claude desktop app: one clearly labelled sponsor line while the agent is thinking, gone the moment it stops.",
5
+ "author": {
6
+ "name": "WBCode"
7
+ },
8
+ "license": "MIT",
9
+ "types": "./types/index.d.ts"
10
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 WBCode (더블유비코드 김태환)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ { "modules": ["./register.tsx"] }