@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,332 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// packages/adapter-antigravity/src/hook.ts
|
|
4
|
+
var import_node_path4 = require("node:path");
|
|
5
|
+
|
|
6
|
+
// packages/protocol/src/art.ts
|
|
7
|
+
var BLANK = String.fromCodePoint(10240);
|
|
8
|
+
|
|
9
|
+
// packages/protocol/src/constants.ts
|
|
10
|
+
var PROTOCOL_VERSION = "2.0.0";
|
|
11
|
+
var ADAPTER_TIMEOUT_MS = 15;
|
|
12
|
+
var MANIFEST_SYNC_INTERVAL_MS = 30 * 6e4;
|
|
13
|
+
var BATCH_FLUSH_INTERVAL_MS = 60 * 6e4;
|
|
14
|
+
var DAEMON_IDLE_EXIT_MS = 3 * 60 * 6e4;
|
|
15
|
+
var OFFLINE_QUEUE_MAX_BYTES = 5 * 1024 * 1024;
|
|
16
|
+
var MAX_LINE_BYTES = 8 * 1024;
|
|
17
|
+
var SPONSOR_LABEL = "Sponsored";
|
|
18
|
+
var SPONSOR_LABELS = {
|
|
19
|
+
ko: "\uAD11\uACE0",
|
|
20
|
+
ja: "\u5E83\u544A",
|
|
21
|
+
"zh-CN": "\u5E7F\u544A",
|
|
22
|
+
"zh-TW": "\u5EE3\u544A",
|
|
23
|
+
es: "Patrocinado",
|
|
24
|
+
pt: "Patrocinado",
|
|
25
|
+
de: "Anzeige",
|
|
26
|
+
fr: "Sponsoris\xE9"
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// packages/protocol/src/validate.ts
|
|
30
|
+
function serialize(msg) {
|
|
31
|
+
return `${JSON.stringify(msg)}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// packages/protocol/src/endpoint.ts
|
|
36
|
+
var import_node_crypto = require("node:crypto");
|
|
37
|
+
var import_node_os = require("node:os");
|
|
38
|
+
var import_node_path = require("node:path");
|
|
39
|
+
function hostPaneOf(paneKey) {
|
|
40
|
+
if (!paneKey) return void 0;
|
|
41
|
+
return (0, import_node_crypto.createHash)("sha256").update(paneKey).digest("hex").slice(0, 16);
|
|
42
|
+
}
|
|
43
|
+
function placeOf(key) {
|
|
44
|
+
return (0, import_node_crypto.createHash)("sha256").update(`avron-place:${key}`).digest("hex").slice(0, 16);
|
|
45
|
+
}
|
|
46
|
+
var PLACE_ENV = "AVRON_PLACE_KEY";
|
|
47
|
+
function placeOfDir(dir, platform = process.platform) {
|
|
48
|
+
const plain = platform === "win32" && /^\/[A-Za-z]:[\\/]/.test(dir) ? dir.slice(1) : dir;
|
|
49
|
+
let p = (0, import_node_path.resolve)(plain).replace(/\\/g, "/");
|
|
50
|
+
while (p.length > 1 && p.endsWith("/") && !/^[A-Za-z]:\/$/.test(p)) p = p.slice(0, -1);
|
|
51
|
+
if (platform === "win32" || platform === "darwin") p = p.toLowerCase();
|
|
52
|
+
return placeOf(`dir:${p}`);
|
|
53
|
+
}
|
|
54
|
+
var placeOfWindow = (key) => placeOf(`window:${key}`);
|
|
55
|
+
function avronHome(env = process.env) {
|
|
56
|
+
return env.AVRON_HOME && env.AVRON_HOME.length > 0 ? env.AVRON_HOME : (0, import_node_path.join)((0, import_node_os.homedir)(), ".avron");
|
|
57
|
+
}
|
|
58
|
+
function avronPaths(env = process.env) {
|
|
59
|
+
const home = avronHome(env);
|
|
60
|
+
return {
|
|
61
|
+
home,
|
|
62
|
+
runDir: (0, import_node_path.join)(home, "run"),
|
|
63
|
+
logDir: (0, import_node_path.join)(home, "logs"),
|
|
64
|
+
dataDir: (0, import_node_path.join)(home, "data"),
|
|
65
|
+
cacheDir: (0, import_node_path.join)(home, "cache"),
|
|
66
|
+
keyDir: (0, import_node_path.join)(home, "keys"),
|
|
67
|
+
daemonLog: (0, import_node_path.join)(home, "logs", "daemon.log"),
|
|
68
|
+
impressionsLog: (0, import_node_path.join)(home, "logs", "impressions.ndjson"),
|
|
69
|
+
ledgerSnapshot: (0, import_node_path.join)(home, "data", "ledger.json"),
|
|
70
|
+
manifestCache: (0, import_node_path.join)(home, "cache", "manifest.json"),
|
|
71
|
+
eventQueue: (0, import_node_path.join)(home, "data", "queue.ndjson")
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var UDS_MAX = 100;
|
|
75
|
+
function ipcEndpoint(env = process.env, platform = process.platform) {
|
|
76
|
+
const home = avronHome(env);
|
|
77
|
+
const tag = (0, import_node_crypto.createHash)("sha256").update(home).digest("hex").slice(0, 12);
|
|
78
|
+
if (platform === "win32") return `\\\\.\\pipe\\avron-uasp-${tag}.sock`;
|
|
79
|
+
const preferred = (0, import_node_path.join)(home, "run", "avron-uasp.sock");
|
|
80
|
+
if (Buffer.byteLength(preferred) <= UDS_MAX) return preferred;
|
|
81
|
+
return (0, import_node_path.join)((0, import_node_os.tmpdir)(), `avron-uasp-${tag}.sock`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// packages/protocol/src/client.ts
|
|
85
|
+
var import_node_net = require("node:net");
|
|
86
|
+
|
|
87
|
+
// packages/protocol/src/quiet.ts
|
|
88
|
+
function quietHere(env = process.env) {
|
|
89
|
+
if (env.AVRON_ALLOW_CI === "1") return false;
|
|
90
|
+
const ci = (env.CI ?? "").trim().toLowerCase();
|
|
91
|
+
return ci !== "" && ci !== "0" && ci !== "false";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// packages/protocol/src/client.ts
|
|
95
|
+
function send(msg, opts = {}) {
|
|
96
|
+
if (quietHere()) return Promise.resolve(false);
|
|
97
|
+
const endpoint = opts.endpoint ?? ipcEndpoint();
|
|
98
|
+
const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
|
|
99
|
+
return new Promise((resolve3) => {
|
|
100
|
+
let done = false;
|
|
101
|
+
const finish = (ok) => {
|
|
102
|
+
if (done) return;
|
|
103
|
+
done = true;
|
|
104
|
+
clearTimeout(timer);
|
|
105
|
+
if (!ok) socket.destroy();
|
|
106
|
+
resolve3(ok);
|
|
107
|
+
};
|
|
108
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
109
|
+
const socket = (0, import_node_net.connect)(endpoint);
|
|
110
|
+
socket.on("connect", () => {
|
|
111
|
+
socket.end(serialize(msg), () => finish(true));
|
|
112
|
+
});
|
|
113
|
+
socket.on("error", () => finish(false));
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// packages/protocol/src/spawn.ts
|
|
118
|
+
var import_node_child_process = require("node:child_process");
|
|
119
|
+
var import_node_fs = require("node:fs");
|
|
120
|
+
var import_node_path2 = require("node:path");
|
|
121
|
+
var FIRST_MESSAGE_ENV = "AVRON_FIRST_MESSAGE";
|
|
122
|
+
var runtimeFile = (env = process.env) => (0, import_node_path2.join)(avronHome(env), "runtime.json");
|
|
123
|
+
function chooseNode(opts = {}) {
|
|
124
|
+
const execPath = opts.execPath ?? process.execPath;
|
|
125
|
+
const electron = "electron" in opts ? opts.electron : process.versions.electron;
|
|
126
|
+
if (!electron && /^node(\.exe)?$/i.test((0, import_node_path2.basename)(execPath))) return execPath;
|
|
127
|
+
try {
|
|
128
|
+
const node = JSON.parse((0, import_node_fs.readFileSync)(opts.runtime ?? runtimeFile(), "utf8")).node;
|
|
129
|
+
if (typeof node === "string" && node.length > 0 && (0, import_node_fs.existsSync)(node)) return node;
|
|
130
|
+
} catch {
|
|
131
|
+
}
|
|
132
|
+
return "node";
|
|
133
|
+
}
|
|
134
|
+
function spawnDaemon(entry, env = process.env) {
|
|
135
|
+
try {
|
|
136
|
+
const child = (0, import_node_child_process.spawn)(chooseNode({ runtime: runtimeFile(env) }), [entry], {
|
|
137
|
+
detached: true,
|
|
138
|
+
stdio: "ignore",
|
|
139
|
+
windowsHide: true,
|
|
140
|
+
env
|
|
141
|
+
});
|
|
142
|
+
child.on("error", () => {
|
|
143
|
+
});
|
|
144
|
+
child.unref();
|
|
145
|
+
return true;
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function ensureDaemon(entry, env = process.env, firstMessage) {
|
|
151
|
+
if (quietHere(env)) return;
|
|
152
|
+
try {
|
|
153
|
+
const marker = (0, import_node_path2.join)(avronPaths(env).runDir, "spawn.marker");
|
|
154
|
+
try {
|
|
155
|
+
if (Date.now() - (0, import_node_fs.statSync)(marker).mtimeMs < 1e4) return;
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path2.dirname)(marker), { recursive: true });
|
|
159
|
+
(0, import_node_fs.closeSync)((0, import_node_fs.openSync)(marker, "a"));
|
|
160
|
+
(0, import_node_fs.utimesSync)(marker, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
|
|
161
|
+
spawnDaemon(entry, firstMessage ? { ...env, [FIRST_MESSAGE_ENV]: firstMessage } : env);
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// packages/adapter-kit/src/render.ts
|
|
167
|
+
var ESC = "\x1B";
|
|
168
|
+
var RESET = `${ESC}[0m`;
|
|
169
|
+
var KNOWN_LABELS = /* @__PURE__ */ new Set([SPONSOR_LABEL, ...Object.values(SPONSOR_LABELS)]);
|
|
170
|
+
var style = {
|
|
171
|
+
truecolor: {
|
|
172
|
+
badge: `${ESC}[48;2;39;39;42m${ESC}[38;2;244;244;245m`,
|
|
173
|
+
dim: `${ESC}[38;2;113;113;122m`,
|
|
174
|
+
copy: `${ESC}[38;2;161;161;170m`,
|
|
175
|
+
cta: `${ESC}[38;2;52;211;153m`
|
|
176
|
+
},
|
|
177
|
+
basic: { badge: `${ESC}[7m`, dim: `${ESC}[2m`, copy: `${ESC}[2m`, cta: `${ESC}[32m` }
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
// packages/adapter-kit/src/stdin.ts
|
|
181
|
+
function readStdin(limitBytes = 1024 * 1024) {
|
|
182
|
+
return new Promise((resolve3) => {
|
|
183
|
+
const chunks = [];
|
|
184
|
+
let size = 0;
|
|
185
|
+
const done = () => resolve3(Buffer.concat(chunks));
|
|
186
|
+
process.stdin.on("data", (c) => {
|
|
187
|
+
size += c.length;
|
|
188
|
+
if (size <= limitBytes) chunks.push(c);
|
|
189
|
+
});
|
|
190
|
+
process.stdin.on("end", done);
|
|
191
|
+
process.stdin.on("error", done);
|
|
192
|
+
if (process.stdin.isTTY) done();
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
var ID_RE = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
196
|
+
function pickIds(stdin, fields) {
|
|
197
|
+
try {
|
|
198
|
+
const j = JSON.parse(stdin.toString("utf8"));
|
|
199
|
+
const sessionId = j[fields.session];
|
|
200
|
+
if (typeof sessionId !== "string" || !ID_RE.test(sessionId)) return null;
|
|
201
|
+
const turn = fields.turn ? j[fields.turn] : void 0;
|
|
202
|
+
const event = fields.event ? j[fields.event] : void 0;
|
|
203
|
+
return {
|
|
204
|
+
sessionId,
|
|
205
|
+
...typeof turn === "string" && ID_RE.test(turn) ? { turnId: turn } : {},
|
|
206
|
+
...typeof event === "string" ? { event: event.slice(0, 40) } : {}
|
|
207
|
+
};
|
|
208
|
+
} catch {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function pickPlace(stdin, field, env = process.env) {
|
|
213
|
+
const key = env[PLACE_ENV];
|
|
214
|
+
if (key && ID_RE.test(key)) return placeOfWindow(key);
|
|
215
|
+
try {
|
|
216
|
+
const value = JSON.parse(stdin.toString("utf8"))[field];
|
|
217
|
+
const dir = Array.isArray(value) ? value[0] : value;
|
|
218
|
+
return typeof dir === "string" && dir.length > 0 && dir.length < 4096 ? placeOfDir(dir) : void 0;
|
|
219
|
+
} catch {
|
|
220
|
+
return void 0;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// packages/adapter-kit/src/turn.ts
|
|
225
|
+
function envelope(agent, sessionId, turnId) {
|
|
226
|
+
return {
|
|
227
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
228
|
+
agentName: agent.name,
|
|
229
|
+
agentTier: agent.tier,
|
|
230
|
+
sessionId,
|
|
231
|
+
turnId,
|
|
232
|
+
timestamp: Date.now()
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function busyMessage(agent, sessionId, turnId, slots, where = {}) {
|
|
236
|
+
return {
|
|
237
|
+
...envelope(agent, sessionId, turnId),
|
|
238
|
+
eventType: "AGENT_BUSY",
|
|
239
|
+
payload: {
|
|
240
|
+
declaredSlots: slots,
|
|
241
|
+
...where.hostPane ? { hostPane: where.hostPane } : {},
|
|
242
|
+
...where.place ? { place: where.place } : {}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function idleMessage(agent, sessionId, turnId, reason = "completed") {
|
|
247
|
+
return {
|
|
248
|
+
...envelope(agent, sessionId, turnId),
|
|
249
|
+
eventType: "AGENT_IDLE",
|
|
250
|
+
payload: { terminationReason: reason }
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// packages/adapter-kit/src/reversible.ts
|
|
255
|
+
var import_node_path3 = require("node:path");
|
|
256
|
+
var PROTECTED_DIRS = [
|
|
257
|
+
".claude",
|
|
258
|
+
".cursor",
|
|
259
|
+
".codex",
|
|
260
|
+
".copilot",
|
|
261
|
+
".kiro",
|
|
262
|
+
".codeium",
|
|
263
|
+
".gemini",
|
|
264
|
+
".orca",
|
|
265
|
+
(0, import_node_path3.join)(".config", "opencode"),
|
|
266
|
+
(0, import_node_path3.join)("AppData", "Roaming", "orca"),
|
|
267
|
+
(0, import_node_path3.join)("Library", "Application Support", "orca")
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
// packages/adapter-antigravity/src/message.ts
|
|
271
|
+
var AGENT = { name: "antigravity", tier: "cli" };
|
|
272
|
+
var IDE_AGENT = { name: "antigravity", tier: "ide" };
|
|
273
|
+
var isIdeAgent = (env) => Boolean(env.VSCODE_PID || env.ANTIGRAVITY_VSCODE_HOST || env.ANTIGRAVITY_EDITOR_APP_ROOT) && !env.TERM_PROGRAM && !env.ORCA_PANE_KEY;
|
|
274
|
+
function numberField(stdin, field) {
|
|
275
|
+
try {
|
|
276
|
+
const v = JSON.parse(stdin.toString("utf8"))[field];
|
|
277
|
+
return typeof v === "number" && Number.isInteger(v) && v >= 0 ? v : void 0;
|
|
278
|
+
} catch {
|
|
279
|
+
return void 0;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function stringField(stdin, field, max = 40) {
|
|
283
|
+
try {
|
|
284
|
+
const v = JSON.parse(stdin.toString("utf8"))[field];
|
|
285
|
+
return typeof v === "string" && v.length <= max ? v : void 0;
|
|
286
|
+
} catch {
|
|
287
|
+
return void 0;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function booleanField(stdin, field) {
|
|
291
|
+
try {
|
|
292
|
+
const v = JSON.parse(stdin.toString("utf8"))[field];
|
|
293
|
+
return typeof v === "boolean" ? v : void 0;
|
|
294
|
+
} catch {
|
|
295
|
+
return void 0;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function hookMessage(kind, stdin, env) {
|
|
299
|
+
const ids = pickIds(stdin, { session: "conversationId" });
|
|
300
|
+
if (!ids) return null;
|
|
301
|
+
if (kind === "busy") {
|
|
302
|
+
if (numberField(stdin, "invocationNum") !== 0) return null;
|
|
303
|
+
const steps = numberField(stdin, "initialNumSteps");
|
|
304
|
+
if (steps === void 0) return null;
|
|
305
|
+
const turnId = `i${steps}`;
|
|
306
|
+
if (isIdeAgent(env))
|
|
307
|
+
return busyMessage(IDE_AGENT, ids.sessionId, turnId, ["ide_statusbar"], {
|
|
308
|
+
place: pickPlace(stdin, "workspacePaths", env)
|
|
309
|
+
});
|
|
310
|
+
const hostPane = hostPaneOf(env.ORCA_PANE_KEY);
|
|
311
|
+
return busyMessage(AGENT, ids.sessionId, turnId, ["statusline"], hostPane ? { hostPane } : {});
|
|
312
|
+
}
|
|
313
|
+
if (kind !== "idle") return null;
|
|
314
|
+
if (booleanField(stdin, "fullyIdle") === false) return null;
|
|
315
|
+
const reason = stringField(stdin, "terminationReason") ?? "";
|
|
316
|
+
const msg = idleMessage(AGENT, ids.sessionId, "", /error/i.test(reason) ? "error" : "completed");
|
|
317
|
+
const { turnId: _none, ...rest } = msg;
|
|
318
|
+
return rest;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// packages/adapter-antigravity/src/hook.ts
|
|
322
|
+
async function main() {
|
|
323
|
+
const msg = hookMessage(process.argv[2] ?? "", await readStdin(), process.env);
|
|
324
|
+
if (!msg) return;
|
|
325
|
+
if (await send(msg)) return;
|
|
326
|
+
if (msg.eventType !== "AGENT_BUSY") return;
|
|
327
|
+
ensureDaemon((0, import_node_path4.join)(__dirname, "avron-daemon.cjs"), process.env, JSON.stringify(msg));
|
|
328
|
+
}
|
|
329
|
+
main().catch(() => {
|
|
330
|
+
}).finally(() => {
|
|
331
|
+
process.stdout.write("{}", () => process.exit(0));
|
|
332
|
+
});
|