@wbcode/avron 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +142 -2
- package/SECURITY.md +78 -0
- package/avron.cjs +2741 -0
- package/bin/avron-antigravity-hook.cjs +332 -0
- package/bin/avron-antigravity-statusline.cjs +593 -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 +1843 -0
- package/bin/avron-hook.cjs +532 -0
- package/bin/avron-opencode-core.mjs +467 -0
- package/bin/avron-opencode.tsx +77 -0
- package/bin/avron-statusline.cjs +583 -0
- package/package.json +27 -4
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// packages/adapter-antigravity/src/statusline.ts
|
|
4
|
+
var import_node_child_process = require("node:child_process");
|
|
5
|
+
var import_node_fs2 = require("node:fs");
|
|
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
|
+
function renderArt(art, color) {
|
|
30
|
+
if (color !== "truecolor" || !art.color) return [...art.rows];
|
|
31
|
+
const n = Number.parseInt(art.color.slice(1), 16);
|
|
32
|
+
const on = `\x1B[38;2;${n >> 16 & 255};${n >> 8 & 255};${n & 255}m`;
|
|
33
|
+
return art.rows.map((row) => row ? `${on}${row}\x1B[0m` : row);
|
|
34
|
+
}
|
|
35
|
+
var BLANK = String.fromCodePoint(10240);
|
|
36
|
+
|
|
37
|
+
// packages/protocol/src/constants.ts
|
|
38
|
+
var PROTOCOL_VERSION = "2.0.0";
|
|
39
|
+
var ADAPTER_TIMEOUT_MS = 15;
|
|
40
|
+
var MANIFEST_SYNC_INTERVAL_MS = 30 * 6e4;
|
|
41
|
+
var BATCH_FLUSH_INTERVAL_MS = 60 * 6e4;
|
|
42
|
+
var DAEMON_IDLE_EXIT_MS = 3 * 60 * 6e4;
|
|
43
|
+
var OFFLINE_QUEUE_MAX_BYTES = 5 * 1024 * 1024;
|
|
44
|
+
var MAX_LINE_BYTES = 8 * 1024;
|
|
45
|
+
var ALLOWED_LINK_PREFIX = "https://avron.dev/go/";
|
|
46
|
+
var SPONSOR_LABEL = "Sponsored";
|
|
47
|
+
var SPONSOR_LABELS = {
|
|
48
|
+
ko: "\uAD11\uACE0",
|
|
49
|
+
ja: "\u5E83\u544A",
|
|
50
|
+
"zh-CN": "\u5E7F\u544A",
|
|
51
|
+
"zh-TW": "\u5EE3\u544A",
|
|
52
|
+
es: "Patrocinado",
|
|
53
|
+
pt: "Patrocinado",
|
|
54
|
+
de: "Anzeige",
|
|
55
|
+
fr: "Sponsoris\xE9"
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// packages/protocol/src/validate.ts
|
|
59
|
+
function isObject(v) {
|
|
60
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
61
|
+
}
|
|
62
|
+
function parsePayloadResponse(line) {
|
|
63
|
+
if (line.length === 0 || Buffer.byteLength(line, "utf8") > MAX_LINE_BYTES) return null;
|
|
64
|
+
let raw;
|
|
65
|
+
try {
|
|
66
|
+
raw = JSON.parse(line);
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (!isObject(raw) || raw.eventType !== "PAYLOAD_RESPONSE") return null;
|
|
71
|
+
if (!isObject(raw.payload) || typeof raw.payload.active !== "boolean") return null;
|
|
72
|
+
if (typeof raw.sessionId !== "string") return null;
|
|
73
|
+
return raw;
|
|
74
|
+
}
|
|
75
|
+
function serialize(msg) {
|
|
76
|
+
return `${JSON.stringify(msg)}
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// packages/protocol/src/endpoint.ts
|
|
81
|
+
var import_node_crypto = require("node:crypto");
|
|
82
|
+
var import_node_os = require("node:os");
|
|
83
|
+
var import_node_path = require("node:path");
|
|
84
|
+
function avronHome(env = process.env) {
|
|
85
|
+
return env.AVRON_HOME && env.AVRON_HOME.length > 0 ? env.AVRON_HOME : (0, import_node_path.join)((0, import_node_os.homedir)(), ".avron");
|
|
86
|
+
}
|
|
87
|
+
var UDS_MAX = 100;
|
|
88
|
+
function ipcEndpoint(env = process.env, platform = process.platform) {
|
|
89
|
+
const home = avronHome(env);
|
|
90
|
+
const tag = (0, import_node_crypto.createHash)("sha256").update(home).digest("hex").slice(0, 12);
|
|
91
|
+
if (platform === "win32") return `\\\\.\\pipe\\avron-uasp-${tag}.sock`;
|
|
92
|
+
const preferred = (0, import_node_path.join)(home, "run", "avron-uasp.sock");
|
|
93
|
+
if (Buffer.byteLength(preferred) <= UDS_MAX) return preferred;
|
|
94
|
+
return (0, import_node_path.join)((0, import_node_os.tmpdir)(), `avron-uasp-${tag}.sock`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// packages/protocol/src/client.ts
|
|
98
|
+
var import_node_net = require("node:net");
|
|
99
|
+
|
|
100
|
+
// packages/protocol/src/quiet.ts
|
|
101
|
+
function quietHere(env = process.env) {
|
|
102
|
+
if (env.AVRON_ALLOW_CI === "1") return false;
|
|
103
|
+
const ci = (env.CI ?? "").trim().toLowerCase();
|
|
104
|
+
return ci !== "" && ci !== "0" && ci !== "false";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// packages/protocol/src/client.ts
|
|
108
|
+
function request(msg, opts = {}) {
|
|
109
|
+
if (quietHere()) return Promise.resolve(null);
|
|
110
|
+
const endpoint = opts.endpoint ?? ipcEndpoint();
|
|
111
|
+
const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
|
|
112
|
+
return new Promise((resolve4) => {
|
|
113
|
+
let done = false;
|
|
114
|
+
let buf = "";
|
|
115
|
+
const finish = (value) => {
|
|
116
|
+
if (done) return;
|
|
117
|
+
done = true;
|
|
118
|
+
clearTimeout(timer);
|
|
119
|
+
socket.destroy();
|
|
120
|
+
resolve4(value);
|
|
121
|
+
};
|
|
122
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
123
|
+
const socket = (0, import_node_net.connect)(endpoint);
|
|
124
|
+
socket.setEncoding("utf8");
|
|
125
|
+
socket.on("connect", () => {
|
|
126
|
+
socket.write(serialize(msg));
|
|
127
|
+
});
|
|
128
|
+
socket.on("data", (chunk) => {
|
|
129
|
+
buf += chunk;
|
|
130
|
+
const nl = buf.indexOf("\n");
|
|
131
|
+
if (nl >= 0) finish(parsePayloadResponse(buf.slice(0, nl)));
|
|
132
|
+
else if (buf.length > MAX_LINE_BYTES) finish(null);
|
|
133
|
+
});
|
|
134
|
+
socket.on("error", () => finish(null));
|
|
135
|
+
socket.on("close", () => finish(null));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function send(msg, opts = {}) {
|
|
139
|
+
if (quietHere()) return Promise.resolve(false);
|
|
140
|
+
const endpoint = opts.endpoint ?? ipcEndpoint();
|
|
141
|
+
const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
|
|
142
|
+
return new Promise((resolve4) => {
|
|
143
|
+
let done = false;
|
|
144
|
+
const finish = (ok) => {
|
|
145
|
+
if (done) return;
|
|
146
|
+
done = true;
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
if (!ok) socket.destroy();
|
|
149
|
+
resolve4(ok);
|
|
150
|
+
};
|
|
151
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
152
|
+
const socket = (0, import_node_net.connect)(endpoint);
|
|
153
|
+
socket.on("connect", () => {
|
|
154
|
+
socket.end(serialize(msg), () => finish(true));
|
|
155
|
+
});
|
|
156
|
+
socket.on("error", () => finish(false));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// packages/adapter-kit/src/render.ts
|
|
161
|
+
var ESC = "\x1B";
|
|
162
|
+
var RESET = `${ESC}[0m`;
|
|
163
|
+
function sanitizeText(input, maxChars = 120) {
|
|
164
|
+
if (typeof input !== "string") return "";
|
|
165
|
+
let out = "";
|
|
166
|
+
for (const ch of input) {
|
|
167
|
+
const cp = ch.codePointAt(0);
|
|
168
|
+
if (cp < 32 || cp >= 127 && cp <= 159) {
|
|
169
|
+
out += " ";
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
if (cp >= 8203 && cp <= 8207 || cp >= 8234 && cp <= 8238 || cp >= 8294 && cp <= 8297)
|
|
173
|
+
continue;
|
|
174
|
+
if (cp === 65279 || cp === 8232 || cp === 8233) continue;
|
|
175
|
+
out += ch;
|
|
176
|
+
}
|
|
177
|
+
out = out.replace(/\s+/g, " ").trim();
|
|
178
|
+
return [...out].slice(0, maxChars).join("");
|
|
179
|
+
}
|
|
180
|
+
function snippetLines(input, max = 3) {
|
|
181
|
+
if (typeof input !== "string") return [];
|
|
182
|
+
return input.split(String.fromCharCode(10)).map((l) => sanitizeText(l, 65)).filter((l) => l.length > 0 && [...l].length <= 64).slice(0, max);
|
|
183
|
+
}
|
|
184
|
+
function safeLink(url) {
|
|
185
|
+
if (typeof url !== "string" || !url.startsWith(ALLOWED_LINK_PREFIX)) return null;
|
|
186
|
+
if (!/^https:\/\/avron\.dev\/go\/[A-Za-z0-9._~\-/?=&%]*$/.test(url)) return null;
|
|
187
|
+
return url;
|
|
188
|
+
}
|
|
189
|
+
function isWide(cp) {
|
|
190
|
+
return cp >= 4352 && cp <= 4447 || // Hangul Jamo
|
|
191
|
+
cp >= 11904 && cp <= 42191 || // CJK radicals .. Yi
|
|
192
|
+
cp >= 44032 && cp <= 55203 || // Hangul syllables
|
|
193
|
+
cp >= 63744 && cp <= 64255 || // CJK compatibility ideographs
|
|
194
|
+
cp >= 65072 && cp <= 65103 || // CJK compatibility forms
|
|
195
|
+
cp >= 65280 && cp <= 65376 || // Fullwidth forms
|
|
196
|
+
cp >= 65504 && cp <= 65510 || cp >= 127744 && cp <= 129791 || // pictographs
|
|
197
|
+
cp >= 131072 && cp <= 262141;
|
|
198
|
+
}
|
|
199
|
+
function isZeroWidth(cp) {
|
|
200
|
+
return cp >= 768 && cp <= 879 || cp >= 65024 && cp <= 65039 || cp === 8205;
|
|
201
|
+
}
|
|
202
|
+
function displayWidth(text) {
|
|
203
|
+
let w = 0;
|
|
204
|
+
for (const ch of stripAnsi(text)) {
|
|
205
|
+
const cp = ch.codePointAt(0);
|
|
206
|
+
if (isZeroWidth(cp)) continue;
|
|
207
|
+
w += isWide(cp) ? 2 : 1;
|
|
208
|
+
}
|
|
209
|
+
return w;
|
|
210
|
+
}
|
|
211
|
+
var ANSI_RE = /\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\u001b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
212
|
+
function stripAnsi(text) {
|
|
213
|
+
return text.replace(ANSI_RE, "");
|
|
214
|
+
}
|
|
215
|
+
function truncate(text, columns) {
|
|
216
|
+
if (displayWidth(text) <= columns) return text;
|
|
217
|
+
if (columns <= 1) return "";
|
|
218
|
+
let out = "";
|
|
219
|
+
let w = 0;
|
|
220
|
+
for (const ch of text) {
|
|
221
|
+
const cw = displayWidth(ch);
|
|
222
|
+
if (w + cw > columns - 1) break;
|
|
223
|
+
out += ch;
|
|
224
|
+
w += cw;
|
|
225
|
+
}
|
|
226
|
+
return `${out.trimEnd()}\u2026`;
|
|
227
|
+
}
|
|
228
|
+
var SEP = "\u2502";
|
|
229
|
+
var KNOWN_LABELS = /* @__PURE__ */ new Set([SPONSOR_LABEL, ...Object.values(SPONSOR_LABELS)]);
|
|
230
|
+
function layout(c, width) {
|
|
231
|
+
const label = KNOWN_LABELS.has(c.label ?? "") ? c.label : SPONSOR_LABEL;
|
|
232
|
+
const badge = sanitizeText(c.sponsorName, 24).toUpperCase();
|
|
233
|
+
const copyFull = sanitizeText(c.headline, 80);
|
|
234
|
+
const ctaRaw = sanitizeText(c.ctaText, 28);
|
|
235
|
+
const cta = ctaRaw ? `${ctaRaw.replace(/\s*↗$/, "")} \u2197` : "";
|
|
236
|
+
if (!badge) return null;
|
|
237
|
+
const fits = (p) => displayWidth(plain(p)) <= width;
|
|
238
|
+
const wide = { label, badge, copy: copyFull, cta };
|
|
239
|
+
if (copyFull && fits(wide)) return wide;
|
|
240
|
+
if (copyFull) {
|
|
241
|
+
const fixed = displayWidth(plain({ label, badge, copy: "", cta })) + 3;
|
|
242
|
+
const room = width - fixed;
|
|
243
|
+
if (room >= 16) {
|
|
244
|
+
const standard = { label, badge, copy: truncate(copyFull, room), cta };
|
|
245
|
+
if (fits(standard)) return standard;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const compact = { label, badge, copy: "", cta };
|
|
249
|
+
if (cta && fits(compact)) return compact;
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
function plain(p) {
|
|
253
|
+
const left = `${p.label} ${p.badge} `;
|
|
254
|
+
if (p.copy && p.cta) return `${left}${SEP} ${p.copy} \xB7 ${p.cta}`;
|
|
255
|
+
if (p.copy) return `${left}${SEP} ${p.copy}`;
|
|
256
|
+
if (p.cta) return `${left}\xB7 ${p.cta}`;
|
|
257
|
+
return left;
|
|
258
|
+
}
|
|
259
|
+
var style = {
|
|
260
|
+
truecolor: {
|
|
261
|
+
badge: `${ESC}[48;2;39;39;42m${ESC}[38;2;244;244;245m`,
|
|
262
|
+
dim: `${ESC}[38;2;113;113;122m`,
|
|
263
|
+
copy: `${ESC}[38;2;161;161;170m`,
|
|
264
|
+
cta: `${ESC}[38;2;52;211;153m`
|
|
265
|
+
},
|
|
266
|
+
basic: { badge: `${ESC}[7m`, dim: `${ESC}[2m`, copy: `${ESC}[2m`, cta: `${ESC}[32m` }
|
|
267
|
+
};
|
|
268
|
+
function link(text, url, enabled) {
|
|
269
|
+
if (!enabled || !url) return text;
|
|
270
|
+
return `${ESC}]8;;${url}${ESC}\\${text}${ESC}]8;;${ESC}\\`;
|
|
271
|
+
}
|
|
272
|
+
function renderLine(content2, opts) {
|
|
273
|
+
const p = layout(content2, opts.width);
|
|
274
|
+
if (!p) return "";
|
|
275
|
+
const url = safeLink(content2.actionUrl);
|
|
276
|
+
if (opts.color === "none") {
|
|
277
|
+
const text = plain(p);
|
|
278
|
+
if (!p.cta) return text;
|
|
279
|
+
return text.slice(0, text.length - p.cta.length) + link(p.cta, url, opts.hyperlinks);
|
|
280
|
+
}
|
|
281
|
+
const s = style[opts.color];
|
|
282
|
+
let out = `${s.dim}${p.label}${RESET} ${s.badge} ${p.badge} ${RESET}`;
|
|
283
|
+
if (p.copy) out += `${s.dim}${SEP}${RESET} ${s.copy}${p.copy}${RESET}`;
|
|
284
|
+
if (p.cta)
|
|
285
|
+
out += `${s.dim}${p.copy ? " \xB7 " : "\xB7 "}${RESET}${link(`${s.cta}${p.cta}${RESET}`, url, opts.hyperlinks)}`;
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
function safePromo(code) {
|
|
289
|
+
return typeof code === "string" && /^[A-Za-z0-9_-]{1,40}$/.test(code) ? code : "";
|
|
290
|
+
}
|
|
291
|
+
var DETAIL_INDENT = " ";
|
|
292
|
+
function detailText(d) {
|
|
293
|
+
const parts = [];
|
|
294
|
+
if (d.snippet) parts.push(`$ ${d.snippet}`);
|
|
295
|
+
if (d.promo) parts.push(`code ${d.promo}`);
|
|
296
|
+
return parts.length ? `${DETAIL_INDENT}${parts.join(" \xB7 ")}` : "";
|
|
297
|
+
}
|
|
298
|
+
function detailLayout(c, width) {
|
|
299
|
+
const snippet = snippetLines(c.snippet, 1)[0] ?? "";
|
|
300
|
+
const promo = safePromo(c.promoCode);
|
|
301
|
+
for (const d of [
|
|
302
|
+
{ snippet, promo },
|
|
303
|
+
{ snippet, promo: "" },
|
|
304
|
+
{ snippet: "", promo }
|
|
305
|
+
]) {
|
|
306
|
+
const text = detailText(d);
|
|
307
|
+
if (text && displayWidth(text) <= width) return d;
|
|
308
|
+
}
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
function renderDetail(content2, opts) {
|
|
312
|
+
const d = detailLayout(content2, opts.width);
|
|
313
|
+
if (!d) return "";
|
|
314
|
+
if (opts.color === "none") return detailText(d);
|
|
315
|
+
const s = style[opts.color];
|
|
316
|
+
const parts = [];
|
|
317
|
+
if (d.snippet) parts.push(`${s.dim}$${RESET} ${s.copy}${d.snippet}${RESET}`);
|
|
318
|
+
if (d.promo) parts.push(`${s.dim}code${RESET} ${s.cta}${d.promo}${RESET}`);
|
|
319
|
+
return `${DETAIL_INDENT}${parts.join(`${s.dim} \xB7 ${RESET}`)}`;
|
|
320
|
+
}
|
|
321
|
+
function detectTerminal(env) {
|
|
322
|
+
if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "") return { color: "none", hyperlinks: false };
|
|
323
|
+
const truecolor = /truecolor|24bit/i.test(env.COLORTERM ?? "") || env.WT_SESSION !== void 0;
|
|
324
|
+
const dumb = env.TERM === "dumb";
|
|
325
|
+
return { color: dumb ? "none" : truecolor ? "truecolor" : "basic", hyperlinks: !dumb };
|
|
326
|
+
}
|
|
327
|
+
function chain(content2, original, columns, term) {
|
|
328
|
+
if (!content2) return original;
|
|
329
|
+
const lines = original.split(/\r?\n/);
|
|
330
|
+
const first = lines[0] ?? "";
|
|
331
|
+
const firstWidth = displayWidth(first);
|
|
332
|
+
const margin = 4;
|
|
333
|
+
const joiner = firstWidth > 0 ? ` ${SEP} ` : "";
|
|
334
|
+
const budget = columns - firstWidth - displayWidth(joiner) - margin;
|
|
335
|
+
const sponsor = budget >= 12 ? renderLine(content2, { width: budget, ...term }) : "";
|
|
336
|
+
if (!sponsor) return original;
|
|
337
|
+
const dimSep = term.color === "none" ? joiner : firstWidth > 0 ? ` ${style[term.color].dim}${SEP}${RESET} ` : "";
|
|
338
|
+
lines[0] = `${sponsor}${dimSep}${first}`;
|
|
339
|
+
const detail = renderDetail(content2, { width: columns - margin, ...term });
|
|
340
|
+
if (detail) lines.splice(1, 0, detail);
|
|
341
|
+
const art = bannerFits(content2, columns);
|
|
342
|
+
if (art) lines.unshift(...renderArt(art, term.color).map((r) => r ? `${DETAIL_INDENT}${r}` : r));
|
|
343
|
+
return lines.join("\n");
|
|
344
|
+
}
|
|
345
|
+
function bannerFits(content2, columns) {
|
|
346
|
+
const art = cleanArt(content2.art);
|
|
347
|
+
return art && artWidth(art) + DETAIL_INDENT.length + 4 <= columns ? art : null;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// packages/adapter-kit/src/stdin.ts
|
|
351
|
+
function readStdin(limitBytes = 1024 * 1024) {
|
|
352
|
+
return new Promise((resolve4) => {
|
|
353
|
+
const chunks = [];
|
|
354
|
+
let size = 0;
|
|
355
|
+
const done = () => resolve4(Buffer.concat(chunks));
|
|
356
|
+
process.stdin.on("data", (c) => {
|
|
357
|
+
size += c.length;
|
|
358
|
+
if (size <= limitBytes) chunks.push(c);
|
|
359
|
+
});
|
|
360
|
+
process.stdin.on("end", done);
|
|
361
|
+
process.stdin.on("error", done);
|
|
362
|
+
if (process.stdin.isTTY) done();
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
var ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
366
|
+
function pickIds(stdin, fields) {
|
|
367
|
+
try {
|
|
368
|
+
const j = JSON.parse(stdin.toString("utf8"));
|
|
369
|
+
const sessionId = j[fields.session];
|
|
370
|
+
if (typeof sessionId !== "string" || !ID_RE.test(sessionId)) return null;
|
|
371
|
+
const turn = fields.turn ? j[fields.turn] : void 0;
|
|
372
|
+
const event = fields.event ? j[fields.event] : void 0;
|
|
373
|
+
return {
|
|
374
|
+
sessionId,
|
|
375
|
+
...typeof turn === "string" && ID_RE.test(turn) ? { turnId: turn } : {},
|
|
376
|
+
...typeof event === "string" ? { event: event.slice(0, 40) } : {}
|
|
377
|
+
};
|
|
378
|
+
} catch {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// packages/adapter-kit/src/turn.ts
|
|
384
|
+
function envelope(agent, sessionId, turnId) {
|
|
385
|
+
return {
|
|
386
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
387
|
+
agentName: agent.name,
|
|
388
|
+
agentTier: agent.tier,
|
|
389
|
+
sessionId,
|
|
390
|
+
turnId,
|
|
391
|
+
timestamp: Date.now()
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function idleMessage(agent, sessionId, turnId, reason = "completed") {
|
|
395
|
+
return {
|
|
396
|
+
...envelope(agent, sessionId, turnId),
|
|
397
|
+
eventType: "AGENT_IDLE",
|
|
398
|
+
payload: { terminationReason: reason }
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function requestMessage(agent, sessionId, turnId, slot, maxLength, drawn) {
|
|
402
|
+
return {
|
|
403
|
+
...envelope(agent, sessionId, turnId),
|
|
404
|
+
eventType: "PAYLOAD_REQUEST",
|
|
405
|
+
payload: { slot, ...maxLength !== void 0 ? { maxLength } : {}, ...drawn ? { drawn } : {} }
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// packages/adapter-kit/src/reversible.ts
|
|
410
|
+
var import_node_fs = require("node:fs");
|
|
411
|
+
var import_node_path2 = require("node:path");
|
|
412
|
+
function readEditState(statePath) {
|
|
413
|
+
try {
|
|
414
|
+
return JSON.parse((0, import_node_fs.readFileSync)(statePath, "utf8"));
|
|
415
|
+
} catch {
|
|
416
|
+
return null;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
var PROTECTED_DIRS = [
|
|
420
|
+
".claude",
|
|
421
|
+
".cursor",
|
|
422
|
+
".codex",
|
|
423
|
+
".copilot",
|
|
424
|
+
".kiro",
|
|
425
|
+
".codeium",
|
|
426
|
+
".gemini",
|
|
427
|
+
".orca",
|
|
428
|
+
(0, import_node_path2.join)(".config", "opencode"),
|
|
429
|
+
(0, import_node_path2.join)("AppData", "Roaming", "orca"),
|
|
430
|
+
(0, import_node_path2.join)("Library", "Application Support", "orca")
|
|
431
|
+
];
|
|
432
|
+
|
|
433
|
+
// packages/adapter-kit/src/json.ts
|
|
434
|
+
var isObject2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
435
|
+
|
|
436
|
+
// packages/adapter-antigravity/src/install.ts
|
|
437
|
+
var import_node_os2 = require("node:os");
|
|
438
|
+
var import_node_path3 = require("node:path");
|
|
439
|
+
var HOOK_SCRIPT = "avron-antigravity-hook.cjs";
|
|
440
|
+
var STATUSLINE_SCRIPT = "avron-antigravity-statusline.cjs";
|
|
441
|
+
function geminiDir(env = process.env) {
|
|
442
|
+
return env.AVRON_ANTIGRAVITY_DIR || (0, import_node_path3.join)((0, import_node_os2.homedir)(), ".gemini");
|
|
443
|
+
}
|
|
444
|
+
function antigravityPaths(env = process.env) {
|
|
445
|
+
const dir = geminiDir(env);
|
|
446
|
+
const home = avronHome(env);
|
|
447
|
+
return {
|
|
448
|
+
geminiDir: dir,
|
|
449
|
+
hooksFile: (0, import_node_path3.join)(dir, "config", "hooks.json"),
|
|
450
|
+
settingsFile: (0, import_node_path3.join)(dir, "antigravity-cli", "settings.json"),
|
|
451
|
+
hooksState: (0, import_node_path3.join)(home, "adapters", "antigravity-hooks.json"),
|
|
452
|
+
settingsState: (0, import_node_path3.join)(home, "adapters", "antigravity-cli.json"),
|
|
453
|
+
binDir: (0, import_node_path3.join)(home, "bin")
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
var isOurCommand = (command) => typeof command === "string" && (command.includes(HOOK_SCRIPT) || command.includes(STATUSLINE_SCRIPT));
|
|
457
|
+
function originalStatusCommand(env = process.env) {
|
|
458
|
+
const state = readEditState(antigravityPaths(env).settingsState);
|
|
459
|
+
const original = state?.originalStatusLine;
|
|
460
|
+
const cmd = isObject2(original) ? original.command : void 0;
|
|
461
|
+
return typeof cmd === "string" && cmd.length > 0 && !isOurCommand(cmd) ? cmd : null;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// packages/adapter-antigravity/src/message.ts
|
|
465
|
+
var AGENT = { name: "antigravity", tier: "cli" };
|
|
466
|
+
var THINKING = /* @__PURE__ */ new Set(["working", "tool_use"]);
|
|
467
|
+
var STOPPED = /* @__PURE__ */ new Set(["idle", "error"]);
|
|
468
|
+
function numberField(stdin, field) {
|
|
469
|
+
try {
|
|
470
|
+
const v = JSON.parse(stdin.toString("utf8"))[field];
|
|
471
|
+
return typeof v === "number" && Number.isInteger(v) && v >= 0 ? v : void 0;
|
|
472
|
+
} catch {
|
|
473
|
+
return void 0;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
function stringField(stdin, field, max = 40) {
|
|
477
|
+
try {
|
|
478
|
+
const v = JSON.parse(stdin.toString("utf8"))[field];
|
|
479
|
+
return typeof v === "string" && v.length <= max ? v : void 0;
|
|
480
|
+
} catch {
|
|
481
|
+
return void 0;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
function statusInput(stdin) {
|
|
485
|
+
const ids = pickIds(stdin, { session: "conversation_id" });
|
|
486
|
+
if (!ids) return null;
|
|
487
|
+
const s = stringField(stdin, "agent_state") ?? "";
|
|
488
|
+
const width = numberField(stdin, "terminal_width");
|
|
489
|
+
return {
|
|
490
|
+
sessionId: ids.sessionId,
|
|
491
|
+
state: THINKING.has(s) ? "thinking" : STOPPED.has(s) ? "stopped" : "other",
|
|
492
|
+
...width !== void 0 && width > 0 && width < 1e4 ? { width } : {}
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function stoppedMessage(sessionId, observedAt, reason = "aborted") {
|
|
496
|
+
const { turnId: _none, ...rest } = idleMessage(AGENT, sessionId, "", reason);
|
|
497
|
+
return { ...rest, payload: { terminationReason: reason, observedAt } };
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// packages/adapter-antigravity/src/status.ts
|
|
501
|
+
var MAX_RETRY_MS = 2e3;
|
|
502
|
+
function content(res) {
|
|
503
|
+
const p = res?.payload;
|
|
504
|
+
if (!p?.active || !p.sponsorName || !p.headline) return null;
|
|
505
|
+
return {
|
|
506
|
+
label: p.label,
|
|
507
|
+
sponsorName: p.sponsorName,
|
|
508
|
+
headline: p.headline,
|
|
509
|
+
ctaText: p.ctaText,
|
|
510
|
+
actionUrl: p.actionUrl
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
async function statusOutput(stdin, deps) {
|
|
514
|
+
const input = statusInput(stdin);
|
|
515
|
+
const columns = input?.width ?? 80;
|
|
516
|
+
let res = null;
|
|
517
|
+
if (input?.state === "thinking") {
|
|
518
|
+
res = await deps.ask(input.sessionId, columns);
|
|
519
|
+
const retry = res?.payload.active === false ? res.payload.retryInMs : void 0;
|
|
520
|
+
if (typeof retry === "number" && retry > 0 && retry <= MAX_RETRY_MS) {
|
|
521
|
+
await deps.sleep(retry + 50);
|
|
522
|
+
res = await deps.ask(input.sessionId, columns);
|
|
523
|
+
}
|
|
524
|
+
} else if (input?.state === "stopped") {
|
|
525
|
+
await deps.send(stoppedMessage(input.sessionId, deps.startedAt));
|
|
526
|
+
}
|
|
527
|
+
const original = await deps.runOriginal(stdin);
|
|
528
|
+
return chain(content(res), original.replace(/\r?\n$/, ""), columns, deps.term);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// packages/adapter-antigravity/src/statusline.ts
|
|
532
|
+
var startedAt = Date.now();
|
|
533
|
+
var ORIGINAL_TIMEOUT_MS = 4e3;
|
|
534
|
+
function runOriginal(stdin) {
|
|
535
|
+
const command = originalStatusCommand();
|
|
536
|
+
if (!command) return Promise.resolve("");
|
|
537
|
+
return new Promise((resolve4) => {
|
|
538
|
+
let out = "";
|
|
539
|
+
let settled = false;
|
|
540
|
+
const finish = (value) => {
|
|
541
|
+
if (settled) return;
|
|
542
|
+
settled = true;
|
|
543
|
+
clearTimeout(timer);
|
|
544
|
+
resolve4(value);
|
|
545
|
+
};
|
|
546
|
+
const child = (0, import_node_child_process.spawn)(command, {
|
|
547
|
+
shell: true,
|
|
548
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
549
|
+
windowsHide: true,
|
|
550
|
+
...workDir(stdin) ? { cwd: workDir(stdin) } : {}
|
|
551
|
+
});
|
|
552
|
+
const timer = setTimeout(() => {
|
|
553
|
+
child.kill();
|
|
554
|
+
finish("");
|
|
555
|
+
}, ORIGINAL_TIMEOUT_MS);
|
|
556
|
+
child.stdout.setEncoding("utf8");
|
|
557
|
+
child.stdout.on("data", (d) => {
|
|
558
|
+
out += d;
|
|
559
|
+
});
|
|
560
|
+
child.on("error", () => finish(""));
|
|
561
|
+
child.on("close", () => finish(out));
|
|
562
|
+
child.stdin.on("error", () => {
|
|
563
|
+
});
|
|
564
|
+
child.stdin.end(stdin);
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
function workDir(stdin) {
|
|
568
|
+
try {
|
|
569
|
+
const cwd = JSON.parse(stdin.toString("utf8")).cwd;
|
|
570
|
+
return typeof cwd === "string" && cwd.length < 4096 && (0, import_node_fs2.statSync)(cwd).isDirectory() ? cwd : void 0;
|
|
571
|
+
} catch {
|
|
572
|
+
return void 0;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
async function main() {
|
|
576
|
+
const stdin = await readStdin();
|
|
577
|
+
const out = await statusOutput(stdin, {
|
|
578
|
+
ask: (sessionId, maxLength) => (
|
|
579
|
+
// No turn id: the daemon answers for the conversation's open turn.
|
|
580
|
+
request({ ...requestMessage(AGENT, sessionId, "", "statusline", maxLength), turnId: void 0 })
|
|
581
|
+
),
|
|
582
|
+
send: (msg) => send(msg),
|
|
583
|
+
runOriginal,
|
|
584
|
+
sleep: (ms) => new Promise((r) => setTimeout(r, ms)),
|
|
585
|
+
startedAt,
|
|
586
|
+
term: detectTerminal(process.env)
|
|
587
|
+
});
|
|
588
|
+
process.stdout.write(out);
|
|
589
|
+
}
|
|
590
|
+
main().catch(() => {
|
|
591
|
+
}).finally(() => {
|
|
592
|
+
process.exitCode = 0;
|
|
593
|
+
});
|