@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.
- package/LICENSE +21 -0
- package/README.md +144 -2
- package/SECURITY.md +81 -0
- package/avron.cjs +2985 -0
- package/bin/avron-antigravity-hook.cjs +332 -0
- package/bin/avron-antigravity-statusline.cjs +593 -0
- package/bin/avron-claude-plugin.cjs +418 -0
- package/bin/avron-codex-hook.cjs +555 -0
- package/bin/avron-copilot-hook.cjs +294 -0
- package/bin/avron-copilot-statusline.cjs +510 -0
- package/bin/avron-cursor-hook.cjs +319 -0
- package/bin/avron-daemon.cjs +1846 -0
- package/bin/avron-hook.cjs +541 -0
- package/bin/avron-opencode-core.mjs +467 -0
- package/bin/avron-opencode.tsx +77 -0
- package/bin/avron-statusline.cjs +583 -0
- package/claude-plugin/.claude-plugin/marketplace.json +14 -0
- package/claude-plugin/avron/.claude-plugin/plugin.json +10 -0
- package/claude-plugin/avron/LICENSE +21 -0
- package/claude-plugin/avron/hooks/hooks.json +1 -0
- package/claude-plugin/avron/hooks/register.tsx +254 -0
- package/claude-plugin/avron/types/index.d.ts +23 -0
- package/package.json +28 -4
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// packages/adapter-claude-code/src/hook.ts
|
|
4
|
+
var import_node_fs2 = require("node:fs");
|
|
5
|
+
var import_node_path4 = require("node:path");
|
|
6
|
+
|
|
7
|
+
// packages/protocol/src/art.ts
|
|
8
|
+
var ART_LIMITS = { rows: 6, cols: 60 };
|
|
9
|
+
var ART_CHAR = /^[⠀-⣿▀-▟ ]*$/;
|
|
10
|
+
var COLOR = /^#[0-9a-f]{6}$/i;
|
|
11
|
+
function cleanArt(raw) {
|
|
12
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
13
|
+
const r = raw;
|
|
14
|
+
if (!Array.isArray(r.rows) || r.rows.length === 0 || r.rows.length > ART_LIMITS.rows) return null;
|
|
15
|
+
const rows = [];
|
|
16
|
+
for (const row of r.rows) {
|
|
17
|
+
if (typeof row !== "string" || !ART_CHAR.test(row) || [...row].length > ART_LIMITS.cols) return null;
|
|
18
|
+
rows.push(row.replace(/ +$/, ""));
|
|
19
|
+
}
|
|
20
|
+
while (rows.length && !rows[0]) rows.shift();
|
|
21
|
+
while (rows.length && !rows[rows.length - 1]) rows.pop();
|
|
22
|
+
if (!rows.length) return null;
|
|
23
|
+
const color = typeof r.color === "string" && COLOR.test(r.color) ? r.color.toLowerCase() : void 0;
|
|
24
|
+
return { rows, ...color ? { color } : {} };
|
|
25
|
+
}
|
|
26
|
+
function artWidth(art) {
|
|
27
|
+
return Math.max(0, ...art.rows.map((r) => [...r].length));
|
|
28
|
+
}
|
|
29
|
+
var BLANK = String.fromCodePoint(10240);
|
|
30
|
+
|
|
31
|
+
// packages/protocol/src/constants.ts
|
|
32
|
+
var PROTOCOL_VERSION = "2.0.0";
|
|
33
|
+
var ADAPTER_TIMEOUT_MS = 15;
|
|
34
|
+
var MANIFEST_SYNC_INTERVAL_MS = 30 * 6e4;
|
|
35
|
+
var BATCH_FLUSH_INTERVAL_MS = 60 * 6e4;
|
|
36
|
+
var DAEMON_IDLE_EXIT_MS = 3 * 60 * 6e4;
|
|
37
|
+
var OFFLINE_QUEUE_MAX_BYTES = 5 * 1024 * 1024;
|
|
38
|
+
var MAX_LINE_BYTES = 8 * 1024;
|
|
39
|
+
var ALLOWED_LINK_PREFIX = "https://avron.dev/go/";
|
|
40
|
+
var SPONSOR_LABEL = "Sponsored";
|
|
41
|
+
var SPONSOR_LABELS = {
|
|
42
|
+
ko: "\uAD11\uACE0",
|
|
43
|
+
ja: "\u5E83\u544A",
|
|
44
|
+
"zh-CN": "\u5E7F\u544A",
|
|
45
|
+
"zh-TW": "\u5EE3\u544A",
|
|
46
|
+
es: "Patrocinado",
|
|
47
|
+
pt: "Patrocinado",
|
|
48
|
+
de: "Anzeige",
|
|
49
|
+
fr: "Sponsoris\xE9"
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// packages/protocol/src/validate.ts
|
|
53
|
+
function isObject(v) {
|
|
54
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
55
|
+
}
|
|
56
|
+
function parsePayloadResponse(line) {
|
|
57
|
+
if (line.length === 0 || Buffer.byteLength(line, "utf8") > MAX_LINE_BYTES) return null;
|
|
58
|
+
let raw;
|
|
59
|
+
try {
|
|
60
|
+
raw = JSON.parse(line);
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (!isObject(raw) || raw.eventType !== "PAYLOAD_RESPONSE") return null;
|
|
65
|
+
if (!isObject(raw.payload) || typeof raw.payload.active !== "boolean") return null;
|
|
66
|
+
if (typeof raw.sessionId !== "string") return null;
|
|
67
|
+
return raw;
|
|
68
|
+
}
|
|
69
|
+
function serialize(msg) {
|
|
70
|
+
return `${JSON.stringify(msg)}
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// packages/protocol/src/endpoint.ts
|
|
75
|
+
var import_node_crypto = require("node:crypto");
|
|
76
|
+
var import_node_os = require("node:os");
|
|
77
|
+
var import_node_path = require("node:path");
|
|
78
|
+
function hostPaneOf(paneKey) {
|
|
79
|
+
if (!paneKey) return void 0;
|
|
80
|
+
return (0, import_node_crypto.createHash)("sha256").update(paneKey).digest("hex").slice(0, 16);
|
|
81
|
+
}
|
|
82
|
+
function placeOf(key) {
|
|
83
|
+
return (0, import_node_crypto.createHash)("sha256").update(`avron-place:${key}`).digest("hex").slice(0, 16);
|
|
84
|
+
}
|
|
85
|
+
var placeOfSession = (sessionId) => placeOf(`session:${sessionId}`);
|
|
86
|
+
function avronHome(env = process.env) {
|
|
87
|
+
return env.AVRON_HOME && env.AVRON_HOME.length > 0 ? env.AVRON_HOME : (0, import_node_path.join)((0, import_node_os.homedir)(), ".avron");
|
|
88
|
+
}
|
|
89
|
+
function avronPaths(env = process.env) {
|
|
90
|
+
const home = avronHome(env);
|
|
91
|
+
return {
|
|
92
|
+
home,
|
|
93
|
+
runDir: (0, import_node_path.join)(home, "run"),
|
|
94
|
+
logDir: (0, import_node_path.join)(home, "logs"),
|
|
95
|
+
dataDir: (0, import_node_path.join)(home, "data"),
|
|
96
|
+
cacheDir: (0, import_node_path.join)(home, "cache"),
|
|
97
|
+
keyDir: (0, import_node_path.join)(home, "keys"),
|
|
98
|
+
daemonLog: (0, import_node_path.join)(home, "logs", "daemon.log"),
|
|
99
|
+
impressionsLog: (0, import_node_path.join)(home, "logs", "impressions.ndjson"),
|
|
100
|
+
ledgerSnapshot: (0, import_node_path.join)(home, "data", "ledger.json"),
|
|
101
|
+
manifestCache: (0, import_node_path.join)(home, "cache", "manifest.json"),
|
|
102
|
+
eventQueue: (0, import_node_path.join)(home, "data", "queue.ndjson")
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
var UDS_MAX = 100;
|
|
106
|
+
function ipcEndpoint(env = process.env, platform = process.platform) {
|
|
107
|
+
const home = avronHome(env);
|
|
108
|
+
const tag = (0, import_node_crypto.createHash)("sha256").update(home).digest("hex").slice(0, 12);
|
|
109
|
+
if (platform === "win32") return `\\\\.\\pipe\\avron-uasp-${tag}.sock`;
|
|
110
|
+
const preferred = (0, import_node_path.join)(home, "run", "avron-uasp.sock");
|
|
111
|
+
if (Buffer.byteLength(preferred) <= UDS_MAX) return preferred;
|
|
112
|
+
return (0, import_node_path.join)((0, import_node_os.tmpdir)(), `avron-uasp-${tag}.sock`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// packages/protocol/src/client.ts
|
|
116
|
+
var import_node_net = require("node:net");
|
|
117
|
+
|
|
118
|
+
// packages/protocol/src/quiet.ts
|
|
119
|
+
function quietHere(env = process.env) {
|
|
120
|
+
if (env.AVRON_ALLOW_CI === "1") return false;
|
|
121
|
+
const ci = (env.CI ?? "").trim().toLowerCase();
|
|
122
|
+
return ci !== "" && ci !== "0" && ci !== "false";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// packages/protocol/src/client.ts
|
|
126
|
+
function request(msg, opts = {}) {
|
|
127
|
+
if (quietHere()) return Promise.resolve(null);
|
|
128
|
+
const endpoint = opts.endpoint ?? ipcEndpoint();
|
|
129
|
+
const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
|
|
130
|
+
return new Promise((resolve3) => {
|
|
131
|
+
let done = false;
|
|
132
|
+
let buf = "";
|
|
133
|
+
const finish = (value) => {
|
|
134
|
+
if (done) return;
|
|
135
|
+
done = true;
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
socket.destroy();
|
|
138
|
+
resolve3(value);
|
|
139
|
+
};
|
|
140
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
141
|
+
const socket = (0, import_node_net.connect)(endpoint);
|
|
142
|
+
socket.setEncoding("utf8");
|
|
143
|
+
socket.on("connect", () => {
|
|
144
|
+
socket.write(serialize(msg));
|
|
145
|
+
});
|
|
146
|
+
socket.on("data", (chunk) => {
|
|
147
|
+
buf += chunk;
|
|
148
|
+
const nl = buf.indexOf("\n");
|
|
149
|
+
if (nl >= 0) finish(parsePayloadResponse(buf.slice(0, nl)));
|
|
150
|
+
else if (buf.length > MAX_LINE_BYTES) finish(null);
|
|
151
|
+
});
|
|
152
|
+
socket.on("error", () => finish(null));
|
|
153
|
+
socket.on("close", () => finish(null));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function send(msg, opts = {}) {
|
|
157
|
+
if (quietHere()) return Promise.resolve(false);
|
|
158
|
+
const endpoint = opts.endpoint ?? ipcEndpoint();
|
|
159
|
+
const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
|
|
160
|
+
return new Promise((resolve3) => {
|
|
161
|
+
let done = false;
|
|
162
|
+
const finish = (ok) => {
|
|
163
|
+
if (done) return;
|
|
164
|
+
done = true;
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
if (!ok) socket.destroy();
|
|
167
|
+
resolve3(ok);
|
|
168
|
+
};
|
|
169
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
170
|
+
const socket = (0, import_node_net.connect)(endpoint);
|
|
171
|
+
socket.on("connect", () => {
|
|
172
|
+
socket.end(serialize(msg), () => finish(true));
|
|
173
|
+
});
|
|
174
|
+
socket.on("error", () => finish(false));
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// packages/protocol/src/spawn.ts
|
|
179
|
+
var import_node_child_process = require("node:child_process");
|
|
180
|
+
var import_node_fs = require("node:fs");
|
|
181
|
+
var import_node_path2 = require("node:path");
|
|
182
|
+
var FIRST_MESSAGE_ENV = "AVRON_FIRST_MESSAGE";
|
|
183
|
+
var runtimeFile = (env = process.env) => (0, import_node_path2.join)(avronHome(env), "runtime.json");
|
|
184
|
+
function chooseNode(opts = {}) {
|
|
185
|
+
const execPath = opts.execPath ?? process.execPath;
|
|
186
|
+
const electron = "electron" in opts ? opts.electron : process.versions.electron;
|
|
187
|
+
if (!electron && /^node(\.exe)?$/i.test((0, import_node_path2.basename)(execPath))) return execPath;
|
|
188
|
+
try {
|
|
189
|
+
const node = JSON.parse((0, import_node_fs.readFileSync)(opts.runtime ?? runtimeFile(), "utf8")).node;
|
|
190
|
+
if (typeof node === "string" && node.length > 0 && (0, import_node_fs.existsSync)(node)) return node;
|
|
191
|
+
} catch {
|
|
192
|
+
}
|
|
193
|
+
return "node";
|
|
194
|
+
}
|
|
195
|
+
function spawnDaemon(entry, env = process.env) {
|
|
196
|
+
try {
|
|
197
|
+
const child = (0, import_node_child_process.spawn)(chooseNode({ runtime: runtimeFile(env) }), [entry], {
|
|
198
|
+
detached: true,
|
|
199
|
+
stdio: "ignore",
|
|
200
|
+
windowsHide: true,
|
|
201
|
+
env
|
|
202
|
+
});
|
|
203
|
+
child.on("error", () => {
|
|
204
|
+
});
|
|
205
|
+
child.unref();
|
|
206
|
+
return true;
|
|
207
|
+
} catch {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function ensureDaemon(entry, env = process.env, firstMessage) {
|
|
212
|
+
if (quietHere(env)) return;
|
|
213
|
+
try {
|
|
214
|
+
const marker = (0, import_node_path2.join)(avronPaths(env).runDir, "spawn.marker");
|
|
215
|
+
try {
|
|
216
|
+
if (Date.now() - (0, import_node_fs.statSync)(marker).mtimeMs < 1e4) return;
|
|
217
|
+
} catch {
|
|
218
|
+
}
|
|
219
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path2.dirname)(marker), { recursive: true });
|
|
220
|
+
(0, import_node_fs.closeSync)((0, import_node_fs.openSync)(marker, "a"));
|
|
221
|
+
(0, import_node_fs.utimesSync)(marker, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
|
|
222
|
+
spawnDaemon(entry, firstMessage ? { ...env, [FIRST_MESSAGE_ENV]: firstMessage } : env);
|
|
223
|
+
} catch {
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// packages/adapter-kit/src/render.ts
|
|
228
|
+
var ESC = "\x1B";
|
|
229
|
+
var RESET = `${ESC}[0m`;
|
|
230
|
+
function sanitizeText(input, maxChars = 120) {
|
|
231
|
+
if (typeof input !== "string") return "";
|
|
232
|
+
let out = "";
|
|
233
|
+
for (const ch of input) {
|
|
234
|
+
const cp = ch.codePointAt(0);
|
|
235
|
+
if (cp < 32 || cp >= 127 && cp <= 159) {
|
|
236
|
+
out += " ";
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
if (cp >= 8203 && cp <= 8207 || cp >= 8234 && cp <= 8238 || cp >= 8294 && cp <= 8297)
|
|
240
|
+
continue;
|
|
241
|
+
if (cp === 65279 || cp === 8232 || cp === 8233) continue;
|
|
242
|
+
out += ch;
|
|
243
|
+
}
|
|
244
|
+
out = out.replace(/\s+/g, " ").trim();
|
|
245
|
+
return [...out].slice(0, maxChars).join("");
|
|
246
|
+
}
|
|
247
|
+
function snippetLines(input, max = 3) {
|
|
248
|
+
if (typeof input !== "string") return [];
|
|
249
|
+
return input.split(String.fromCharCode(10)).map((l) => sanitizeText(l, 65)).filter((l) => l.length > 0 && [...l].length <= 64).slice(0, max);
|
|
250
|
+
}
|
|
251
|
+
function safeLink(url) {
|
|
252
|
+
if (typeof url !== "string" || !url.startsWith(ALLOWED_LINK_PREFIX)) return null;
|
|
253
|
+
if (!/^https:\/\/avron\.dev\/go\/[A-Za-z0-9._~\-/?=&%]*$/.test(url)) return null;
|
|
254
|
+
return url;
|
|
255
|
+
}
|
|
256
|
+
function isWide(cp) {
|
|
257
|
+
return cp >= 4352 && cp <= 4447 || // Hangul Jamo
|
|
258
|
+
cp >= 11904 && cp <= 42191 || // CJK radicals .. Yi
|
|
259
|
+
cp >= 44032 && cp <= 55203 || // Hangul syllables
|
|
260
|
+
cp >= 63744 && cp <= 64255 || // CJK compatibility ideographs
|
|
261
|
+
cp >= 65072 && cp <= 65103 || // CJK compatibility forms
|
|
262
|
+
cp >= 65280 && cp <= 65376 || // Fullwidth forms
|
|
263
|
+
cp >= 65504 && cp <= 65510 || cp >= 127744 && cp <= 129791 || // pictographs
|
|
264
|
+
cp >= 131072 && cp <= 262141;
|
|
265
|
+
}
|
|
266
|
+
function isZeroWidth(cp) {
|
|
267
|
+
return cp >= 768 && cp <= 879 || cp >= 65024 && cp <= 65039 || cp === 8205;
|
|
268
|
+
}
|
|
269
|
+
function displayWidth(text) {
|
|
270
|
+
let w = 0;
|
|
271
|
+
for (const ch of stripAnsi(text)) {
|
|
272
|
+
const cp = ch.codePointAt(0);
|
|
273
|
+
if (isZeroWidth(cp)) continue;
|
|
274
|
+
w += isWide(cp) ? 2 : 1;
|
|
275
|
+
}
|
|
276
|
+
return w;
|
|
277
|
+
}
|
|
278
|
+
var ANSI_RE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
279
|
+
function stripAnsi(text) {
|
|
280
|
+
return text.replace(ANSI_RE, "");
|
|
281
|
+
}
|
|
282
|
+
function truncate(text, columns) {
|
|
283
|
+
if (displayWidth(text) <= columns) return text;
|
|
284
|
+
if (columns <= 1) return "";
|
|
285
|
+
let out = "";
|
|
286
|
+
let w = 0;
|
|
287
|
+
for (const ch of text) {
|
|
288
|
+
const cw = displayWidth(ch);
|
|
289
|
+
if (w + cw > columns - 1) break;
|
|
290
|
+
out += ch;
|
|
291
|
+
w += cw;
|
|
292
|
+
}
|
|
293
|
+
return `${out.trimEnd()}\u2026`;
|
|
294
|
+
}
|
|
295
|
+
var SEP = "\u2502";
|
|
296
|
+
var KNOWN_LABELS = /* @__PURE__ */ new Set([SPONSOR_LABEL, ...Object.values(SPONSOR_LABELS)]);
|
|
297
|
+
function layout(c, width) {
|
|
298
|
+
const label = KNOWN_LABELS.has(c.label ?? "") ? c.label : SPONSOR_LABEL;
|
|
299
|
+
const badge = sanitizeText(c.sponsorName, 24).toUpperCase();
|
|
300
|
+
const copyFull = sanitizeText(c.headline, 80);
|
|
301
|
+
const ctaRaw = sanitizeText(c.ctaText, 28);
|
|
302
|
+
const cta = ctaRaw ? `${ctaRaw.replace(/\s*↗$/, "")} \u2197` : "";
|
|
303
|
+
if (!badge) return null;
|
|
304
|
+
const fits = (p) => displayWidth(plain(p)) <= width;
|
|
305
|
+
const wide = { label, badge, copy: copyFull, cta };
|
|
306
|
+
if (copyFull && fits(wide)) return wide;
|
|
307
|
+
if (copyFull) {
|
|
308
|
+
const fixed = displayWidth(plain({ label, badge, copy: "", cta })) + 3;
|
|
309
|
+
const room = width - fixed;
|
|
310
|
+
if (room >= 16) {
|
|
311
|
+
const standard = { label, badge, copy: truncate(copyFull, room), cta };
|
|
312
|
+
if (fits(standard)) return standard;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
const compact = { label, badge, copy: "", cta };
|
|
316
|
+
if (cta && fits(compact)) return compact;
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
function plainLine(content, maxLength) {
|
|
320
|
+
const p = layout(content, maxLength);
|
|
321
|
+
return p ? plain(p) : "";
|
|
322
|
+
}
|
|
323
|
+
function plain(p) {
|
|
324
|
+
const left = `${p.label} ${p.badge} `;
|
|
325
|
+
if (p.copy && p.cta) return `${left}${SEP} ${p.copy} \xB7 ${p.cta}`;
|
|
326
|
+
if (p.copy) return `${left}${SEP} ${p.copy}`;
|
|
327
|
+
if (p.cta) return `${left}\xB7 ${p.cta}`;
|
|
328
|
+
return left;
|
|
329
|
+
}
|
|
330
|
+
var style = {
|
|
331
|
+
truecolor: {
|
|
332
|
+
badge: `${ESC}[48;2;39;39;42m${ESC}[38;2;244;244;245m`,
|
|
333
|
+
dim: `${ESC}[38;2;113;113;122m`,
|
|
334
|
+
copy: `${ESC}[38;2;161;161;170m`,
|
|
335
|
+
cta: `${ESC}[38;2;52;211;153m`
|
|
336
|
+
},
|
|
337
|
+
basic: { badge: `${ESC}[7m`, dim: `${ESC}[2m`, copy: `${ESC}[2m`, cta: `${ESC}[32m` }
|
|
338
|
+
};
|
|
339
|
+
function safePromo(code) {
|
|
340
|
+
return typeof code === "string" && /^[A-Za-z0-9_-]{1,40}$/.test(code) ? code : "";
|
|
341
|
+
}
|
|
342
|
+
var DETAIL_INDENT = " ";
|
|
343
|
+
function detailText(d) {
|
|
344
|
+
const parts = [];
|
|
345
|
+
if (d.snippet) parts.push(`$ ${d.snippet}`);
|
|
346
|
+
if (d.promo) parts.push(`code ${d.promo}`);
|
|
347
|
+
return parts.length ? `${DETAIL_INDENT}${parts.join(" \xB7 ")}` : "";
|
|
348
|
+
}
|
|
349
|
+
function detailLayout(c, width) {
|
|
350
|
+
const snippet = snippetLines(c.snippet, 1)[0] ?? "";
|
|
351
|
+
const promo = safePromo(c.promoCode);
|
|
352
|
+
for (const d of [
|
|
353
|
+
{ snippet, promo },
|
|
354
|
+
{ snippet, promo: "" },
|
|
355
|
+
{ snippet: "", promo }
|
|
356
|
+
]) {
|
|
357
|
+
const text = detailText(d);
|
|
358
|
+
if (text && displayWidth(text) <= width) return d;
|
|
359
|
+
}
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
function detailPlain(content, width) {
|
|
363
|
+
const d = detailLayout(content, width);
|
|
364
|
+
return d ? detailText(d) : "";
|
|
365
|
+
}
|
|
366
|
+
function bannerFits(content, columns) {
|
|
367
|
+
const art = cleanArt(content.art);
|
|
368
|
+
return art && artWidth(art) + DETAIL_INDENT.length + 4 <= columns ? art : null;
|
|
369
|
+
}
|
|
370
|
+
function posterText(content, todayTurns, width = 78) {
|
|
371
|
+
const line = plainLine(content, width);
|
|
372
|
+
if (!line) return "";
|
|
373
|
+
const rows = [];
|
|
374
|
+
const art = bannerFits(content, width);
|
|
375
|
+
if (art) rows.push(...art.rows.map((r) => r ? `${DETAIL_INDENT}${r}` : r), "");
|
|
376
|
+
rows.push(line);
|
|
377
|
+
const detail = detailPlain(content, width);
|
|
378
|
+
if (detail) rows.push(detail);
|
|
379
|
+
const url = safeLink(content.actionUrl);
|
|
380
|
+
if (url && displayWidth(url) + DETAIL_INDENT.length <= width) rows.push(`${DETAIL_INDENT}${url}`);
|
|
381
|
+
rows.push("");
|
|
382
|
+
rows.push(
|
|
383
|
+
todayTurns !== void 0 ? `Avron today: ${todayTurns} ${todayTurns === 1 ? "turn" : "turns"} counted on this computer. Numbers: npx @wbcode/avron status` : "Avron: npx @wbcode/avron status shows your numbers."
|
|
384
|
+
);
|
|
385
|
+
return rows.join("\n");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// packages/adapter-kit/src/poster.ts
|
|
389
|
+
var POSTER_WAIT_MS = 400;
|
|
390
|
+
async function startPoster(agent, sessionId) {
|
|
391
|
+
const res = await request(
|
|
392
|
+
{
|
|
393
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
394
|
+
eventType: "PAYLOAD_REQUEST",
|
|
395
|
+
agentName: agent.name,
|
|
396
|
+
agentTier: agent.tier,
|
|
397
|
+
sessionId,
|
|
398
|
+
timestamp: Date.now(),
|
|
399
|
+
payload: { slot: "statusline", poster: true }
|
|
400
|
+
},
|
|
401
|
+
{ timeoutMs: POSTER_WAIT_MS }
|
|
402
|
+
);
|
|
403
|
+
if (res === null) return null;
|
|
404
|
+
const p = res.payload;
|
|
405
|
+
if (!p.active || !p.sponsorName || !p.headline) return "";
|
|
406
|
+
return posterText(
|
|
407
|
+
{
|
|
408
|
+
label: p.label,
|
|
409
|
+
sponsorName: p.sponsorName,
|
|
410
|
+
headline: p.headline,
|
|
411
|
+
ctaText: p.ctaText,
|
|
412
|
+
actionUrl: p.actionUrl,
|
|
413
|
+
snippet: p.snippet,
|
|
414
|
+
promoCode: p.promoCode,
|
|
415
|
+
art: p.art
|
|
416
|
+
},
|
|
417
|
+
p.todayTurns
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
function posterOutput(text) {
|
|
421
|
+
return text ? JSON.stringify({ systemMessage: text }) : "";
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// packages/adapter-kit/src/stdin.ts
|
|
425
|
+
function readStdin(limitBytes = 1024 * 1024) {
|
|
426
|
+
return new Promise((resolve3) => {
|
|
427
|
+
const chunks = [];
|
|
428
|
+
let size = 0;
|
|
429
|
+
const done = () => resolve3(Buffer.concat(chunks));
|
|
430
|
+
process.stdin.on("data", (c) => {
|
|
431
|
+
size += c.length;
|
|
432
|
+
if (size <= limitBytes) chunks.push(c);
|
|
433
|
+
});
|
|
434
|
+
process.stdin.on("end", done);
|
|
435
|
+
process.stdin.on("error", done);
|
|
436
|
+
if (process.stdin.isTTY) done();
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
var ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
440
|
+
function pickIds(stdin, fields) {
|
|
441
|
+
try {
|
|
442
|
+
const j = JSON.parse(stdin.toString("utf8"));
|
|
443
|
+
const sessionId = j[fields.session];
|
|
444
|
+
if (typeof sessionId !== "string" || !ID_RE.test(sessionId)) return null;
|
|
445
|
+
const turn = fields.turn ? j[fields.turn] : void 0;
|
|
446
|
+
const event = fields.event ? j[fields.event] : void 0;
|
|
447
|
+
return {
|
|
448
|
+
sessionId,
|
|
449
|
+
...typeof turn === "string" && ID_RE.test(turn) ? { turnId: turn } : {},
|
|
450
|
+
...typeof event === "string" ? { event: event.slice(0, 40) } : {}
|
|
451
|
+
};
|
|
452
|
+
} catch {
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// packages/adapter-kit/src/reversible.ts
|
|
458
|
+
var import_node_path3 = require("node:path");
|
|
459
|
+
var PROTECTED_DIRS = [
|
|
460
|
+
".claude",
|
|
461
|
+
".cursor",
|
|
462
|
+
".codex",
|
|
463
|
+
".copilot",
|
|
464
|
+
".kiro",
|
|
465
|
+
".codeium",
|
|
466
|
+
".gemini",
|
|
467
|
+
".orca",
|
|
468
|
+
(0, import_node_path3.join)(".config", "opencode"),
|
|
469
|
+
(0, import_node_path3.join)("AppData", "Roaming", "orca"),
|
|
470
|
+
(0, import_node_path3.join)("Library", "Application Support", "orca")
|
|
471
|
+
];
|
|
472
|
+
|
|
473
|
+
// packages/adapter-claude-code/src/io.ts
|
|
474
|
+
function extractIds(stdin) {
|
|
475
|
+
const ids = pickIds(stdin, { session: "session_id", turn: "prompt_id", event: "hook_event_name" });
|
|
476
|
+
if (!ids) return null;
|
|
477
|
+
return { sessionId: ids.sessionId, promptId: ids.turnId, hookEventName: ids.event };
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// packages/adapter-claude-code/src/hook.ts
|
|
481
|
+
var REASONS = {
|
|
482
|
+
Stop: "completed",
|
|
483
|
+
StopFailure: "error",
|
|
484
|
+
SessionEnd: "aborted"
|
|
485
|
+
};
|
|
486
|
+
async function main() {
|
|
487
|
+
const arg = process.argv[2];
|
|
488
|
+
const kind = arg === "busy" || arg === "start" ? arg : "idle";
|
|
489
|
+
const ids = extractIds(await readStdin());
|
|
490
|
+
if (!ids) return;
|
|
491
|
+
if (kind === "start") return poster(ids.sessionId);
|
|
492
|
+
const env = {
|
|
493
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
494
|
+
agentName: "claude-code",
|
|
495
|
+
agentTier: "cli",
|
|
496
|
+
sessionId: ids.sessionId,
|
|
497
|
+
timestamp: Date.now()
|
|
498
|
+
};
|
|
499
|
+
const turnId = ids.hookEventName === "SessionEnd" ? void 0 : ids.promptId;
|
|
500
|
+
const desktop = isDesktop();
|
|
501
|
+
const msg = kind === "busy" ? {
|
|
502
|
+
...env,
|
|
503
|
+
...turnId ? { turnId } : {},
|
|
504
|
+
eventType: "AGENT_BUSY",
|
|
505
|
+
// Inside an Orca terminal the pane is named, so Orca's own status bar can stay empty
|
|
506
|
+
// while this status line shows the turn (only a hash of the pane key is sent).
|
|
507
|
+
payload: desktop ? { declaredSlots: ["ide_statusbar"], ...sessionPlacePart(ids.sessionId) } : { declaredSlots: ["statusline"], ...hostPanePart() }
|
|
508
|
+
} : {
|
|
509
|
+
...env,
|
|
510
|
+
...turnId ? { turnId } : {},
|
|
511
|
+
eventType: "AGENT_IDLE",
|
|
512
|
+
payload: { terminationReason: REASONS[ids.hookEventName ?? ""] ?? "completed" }
|
|
513
|
+
};
|
|
514
|
+
if (await send(msg)) return;
|
|
515
|
+
if (kind !== "busy") return;
|
|
516
|
+
ensureDaemon((0, import_node_path4.join)(__dirname, "avron-daemon.cjs"));
|
|
517
|
+
for (let i = 0; i < 60; i++) {
|
|
518
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
519
|
+
if (await send({ ...msg, timestamp: Date.now() }, { timeoutMs: 50 })) return;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async function poster(sessionId) {
|
|
523
|
+
if (isDesktop()) return;
|
|
524
|
+
const text = await startPoster({ name: "claude-code", tier: "cli" }, sessionId);
|
|
525
|
+
if (text === null) ensureDaemon((0, import_node_path4.join)(__dirname, "avron-daemon.cjs"));
|
|
526
|
+
const out = posterOutput(text);
|
|
527
|
+
if (out) process.stdout.write(out);
|
|
528
|
+
}
|
|
529
|
+
function isDesktop() {
|
|
530
|
+
return process.env.CLAUDE_CODE_ENTRYPOINT === "claude-desktop";
|
|
531
|
+
}
|
|
532
|
+
function sessionPlacePart(sessionId) {
|
|
533
|
+
const config = (0, import_node_path4.join)(avronHome(), "claude-plugin", "avron", "avron-plugin.json");
|
|
534
|
+
return (0, import_node_fs2.existsSync)(config) ? { place: placeOfSession(sessionId) } : {};
|
|
535
|
+
}
|
|
536
|
+
function hostPanePart() {
|
|
537
|
+
const hostPane = hostPaneOf(process.env.ORCA_PANE_KEY);
|
|
538
|
+
return hostPane ? { hostPane } : {};
|
|
539
|
+
}
|
|
540
|
+
main().catch(() => {
|
|
541
|
+
}).finally(() => process.exit(0));
|