@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
package/avron.cjs
ADDED
|
@@ -0,0 +1,2741 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// packages/cli/src/bin.ts
|
|
5
|
+
var import_node_path16 = require("node:path");
|
|
6
|
+
var import_node_readline = require("node:readline");
|
|
7
|
+
|
|
8
|
+
// packages/cli/src/index.ts
|
|
9
|
+
var import_node_child_process3 = require("node:child_process");
|
|
10
|
+
var import_node_fs12 = require("node:fs");
|
|
11
|
+
var import_node_path15 = require("node:path");
|
|
12
|
+
|
|
13
|
+
// packages/adapter-claude-code/src/settings.ts
|
|
14
|
+
var HOOK_EVENTS = {
|
|
15
|
+
UserPromptSubmit: "busy",
|
|
16
|
+
Stop: "idle",
|
|
17
|
+
StopFailure: "idle",
|
|
18
|
+
SessionEnd: "idle",
|
|
19
|
+
// The start poster (formats.poster): its message is shown to the person only (systemMessage).
|
|
20
|
+
SessionStart: "start"
|
|
21
|
+
};
|
|
22
|
+
var STATUSLINE_SCRIPT = "avron-statusline.cjs";
|
|
23
|
+
var HOOK_SCRIPT = "avron-hook.cjs";
|
|
24
|
+
var OURS_RE = /avron-(statusline|hook)\.cjs/;
|
|
25
|
+
function isOurCommand(command) {
|
|
26
|
+
return typeof command === "string" && OURS_RE.test(command);
|
|
27
|
+
}
|
|
28
|
+
function isObject(v) {
|
|
29
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
30
|
+
}
|
|
31
|
+
function detectStyle(text) {
|
|
32
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
33
|
+
const m = /\n([ \t]+)"/.exec(text);
|
|
34
|
+
return { indent: m?.[1] ?? " ", eol, trailingNewline: text.length === 0 || /\n$/.test(text) };
|
|
35
|
+
}
|
|
36
|
+
function stringify(obj, style2) {
|
|
37
|
+
let out = JSON.stringify(obj, null, style2.indent);
|
|
38
|
+
if (style2.eol === "\r\n") out = out.replace(/\n/g, "\r\n");
|
|
39
|
+
return style2.trailingNewline ? out + style2.eol : out;
|
|
40
|
+
}
|
|
41
|
+
function parseSettings(text) {
|
|
42
|
+
const body = text.replace(/^/, "");
|
|
43
|
+
if (body.trim() === "") return {};
|
|
44
|
+
const parsed = JSON.parse(body);
|
|
45
|
+
if (!isObject(parsed)) throw new Error("settings.json is not a JSON object");
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
function entryIsOurs(entry) {
|
|
49
|
+
if (!isObject(entry) || !Array.isArray(entry.hooks) || entry.hooks.length === 0) return false;
|
|
50
|
+
return entry.hooks.every((h) => isObject(h) && isOurCommand(h.command));
|
|
51
|
+
}
|
|
52
|
+
function inject(text, opts) {
|
|
53
|
+
const settings = parseSettings(text);
|
|
54
|
+
const style2 = detectStyle(text);
|
|
55
|
+
const current = settings.statusLine;
|
|
56
|
+
const alreadyWrapped = isObject(current) && isOurCommand(current.command);
|
|
57
|
+
let changed = false;
|
|
58
|
+
const hadStatusLine = !alreadyWrapped && current !== void 0;
|
|
59
|
+
if (!alreadyWrapped) {
|
|
60
|
+
const next = { type: "command", command: opts.statuslineCommand };
|
|
61
|
+
if (isObject(current)) {
|
|
62
|
+
if (typeof current.padding === "number") next.padding = current.padding;
|
|
63
|
+
if (current.hideVimModeIndicator !== void 0)
|
|
64
|
+
next.hideVimModeIndicator = current.hideVimModeIndicator;
|
|
65
|
+
}
|
|
66
|
+
const theirs = isObject(current) && typeof current.refreshInterval === "number" ? current.refreshInterval : 0;
|
|
67
|
+
next.refreshInterval = theirs > 0 ? Math.min(theirs, opts.refreshInterval) : opts.refreshInterval;
|
|
68
|
+
settings.statusLine = next;
|
|
69
|
+
changed = true;
|
|
70
|
+
}
|
|
71
|
+
const hooks = isObject(settings.hooks) ? settings.hooks : {};
|
|
72
|
+
for (const event of Object.keys(HOOK_EVENTS)) {
|
|
73
|
+
const list = Array.isArray(hooks[event]) ? hooks[event] : [];
|
|
74
|
+
if (list.some(entryIsOurs)) continue;
|
|
75
|
+
list.push({
|
|
76
|
+
hooks: [
|
|
77
|
+
event === "SessionStart" ? { type: "command", command: opts.hookCommand(event), timeout: 5 } : { type: "command", command: opts.hookCommand(event), async: true, timeout: 10 }
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
hooks[event] = list;
|
|
81
|
+
changed = true;
|
|
82
|
+
}
|
|
83
|
+
if (changed) settings.hooks = hooks;
|
|
84
|
+
return {
|
|
85
|
+
text: changed ? stringify(settings, style2) : text,
|
|
86
|
+
changed,
|
|
87
|
+
hadStatusLine,
|
|
88
|
+
...hadStatusLine ? { originalStatusLine: current } : {}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function remove(text, opts) {
|
|
92
|
+
const settings = parseSettings(text);
|
|
93
|
+
const style2 = detectStyle(text);
|
|
94
|
+
let changed = false;
|
|
95
|
+
if (isObject(settings.statusLine) && isOurCommand(settings.statusLine.command)) {
|
|
96
|
+
if (opts.hadStatusLine) settings.statusLine = opts.originalStatusLine;
|
|
97
|
+
else settings.statusLine = void 0;
|
|
98
|
+
changed = true;
|
|
99
|
+
}
|
|
100
|
+
if (isObject(settings.hooks)) {
|
|
101
|
+
const hooks = settings.hooks;
|
|
102
|
+
for (const event of Object.keys(hooks)) {
|
|
103
|
+
const list = hooks[event];
|
|
104
|
+
if (!Array.isArray(list)) continue;
|
|
105
|
+
const kept = list.filter((entry) => !entryIsOurs(entry));
|
|
106
|
+
if (kept.length === list.length) continue;
|
|
107
|
+
changed = true;
|
|
108
|
+
if (kept.length > 0) hooks[event] = kept;
|
|
109
|
+
else delete hooks[event];
|
|
110
|
+
}
|
|
111
|
+
if (changed && Object.keys(hooks).length === 0) settings.hooks = void 0;
|
|
112
|
+
}
|
|
113
|
+
return { text: changed ? stringify(settings, style2) : text, changed };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// packages/adapter-claude-code/src/install.ts
|
|
117
|
+
var import_node_os3 = require("node:os");
|
|
118
|
+
var import_node_path4 = require("node:path");
|
|
119
|
+
|
|
120
|
+
// packages/protocol/src/art.ts
|
|
121
|
+
var ART_LIMITS = { rows: 6, cols: 60 };
|
|
122
|
+
var ART_CHAR = /^[⠀-⣿▀-▟ ]*$/;
|
|
123
|
+
var COLOR = /^#[0-9a-f]{6}$/i;
|
|
124
|
+
function cleanArt(raw) {
|
|
125
|
+
if (typeof raw !== "object" || raw === null) return null;
|
|
126
|
+
const r = raw;
|
|
127
|
+
if (!Array.isArray(r.rows) || r.rows.length === 0 || r.rows.length > ART_LIMITS.rows) return null;
|
|
128
|
+
const rows = [];
|
|
129
|
+
for (const row of r.rows) {
|
|
130
|
+
if (typeof row !== "string" || !ART_CHAR.test(row) || [...row].length > ART_LIMITS.cols) return null;
|
|
131
|
+
rows.push(row.replace(/ +$/, ""));
|
|
132
|
+
}
|
|
133
|
+
while (rows.length && !rows[0]) rows.shift();
|
|
134
|
+
while (rows.length && !rows[rows.length - 1]) rows.pop();
|
|
135
|
+
if (!rows.length) return null;
|
|
136
|
+
const color = typeof r.color === "string" && COLOR.test(r.color) ? r.color.toLowerCase() : void 0;
|
|
137
|
+
return { rows, ...color ? { color } : {} };
|
|
138
|
+
}
|
|
139
|
+
var BLANK = String.fromCodePoint(10240);
|
|
140
|
+
var MOTIONS = ["reveal", "wipe"];
|
|
141
|
+
|
|
142
|
+
// packages/protocol/src/constants.ts
|
|
143
|
+
var PROTOCOL_VERSION = "2.0.0";
|
|
144
|
+
var ADAPTER_TIMEOUT_MS = 15;
|
|
145
|
+
var MANIFEST_SYNC_INTERVAL_MS = 30 * 6e4;
|
|
146
|
+
var BATCH_FLUSH_INTERVAL_MS = 60 * 6e4;
|
|
147
|
+
var DAEMON_IDLE_EXIT_MS = 3 * 60 * 6e4;
|
|
148
|
+
var OFFLINE_QUEUE_MAX_BYTES = 5 * 1024 * 1024;
|
|
149
|
+
var MICRO_TAG_MAX_CHARS = 15;
|
|
150
|
+
var MAX_LINE_BYTES = 8 * 1024;
|
|
151
|
+
var ALLOWED_LINK_PREFIX = "https://avron.dev/go/";
|
|
152
|
+
function isAdTier(v) {
|
|
153
|
+
return v === "line" || v === "card" || v === "spot";
|
|
154
|
+
}
|
|
155
|
+
var SPONSOR_LABEL = "Sponsored";
|
|
156
|
+
var SPONSOR_LABELS = {
|
|
157
|
+
ko: "\uAD11\uACE0",
|
|
158
|
+
ja: "\u5E83\u544A",
|
|
159
|
+
"zh-CN": "\u5E7F\u544A",
|
|
160
|
+
"zh-TW": "\u5EE3\u544A",
|
|
161
|
+
es: "Patrocinado",
|
|
162
|
+
pt: "Patrocinado",
|
|
163
|
+
de: "Anzeige",
|
|
164
|
+
fr: "Sponsoris\xE9"
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// packages/protocol/src/validate.ts
|
|
168
|
+
function isObject2(v) {
|
|
169
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
170
|
+
}
|
|
171
|
+
function parsePayloadResponse(line) {
|
|
172
|
+
if (line.length === 0 || Buffer.byteLength(line, "utf8") > MAX_LINE_BYTES) return null;
|
|
173
|
+
let raw;
|
|
174
|
+
try {
|
|
175
|
+
raw = JSON.parse(line);
|
|
176
|
+
} catch {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
if (!isObject2(raw) || raw.eventType !== "PAYLOAD_RESPONSE") return null;
|
|
180
|
+
if (!isObject2(raw.payload) || typeof raw.payload.active !== "boolean") return null;
|
|
181
|
+
if (typeof raw.sessionId !== "string") return null;
|
|
182
|
+
return raw;
|
|
183
|
+
}
|
|
184
|
+
function serialize(msg) {
|
|
185
|
+
return `${JSON.stringify(msg)}
|
|
186
|
+
`;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// packages/protocol/src/endpoint.ts
|
|
190
|
+
var import_node_crypto = require("node:crypto");
|
|
191
|
+
var import_node_os = require("node:os");
|
|
192
|
+
var import_node_path = require("node:path");
|
|
193
|
+
function avronHome(env = process.env) {
|
|
194
|
+
return env.AVRON_HOME && env.AVRON_HOME.length > 0 ? env.AVRON_HOME : (0, import_node_path.join)((0, import_node_os.homedir)(), ".avron");
|
|
195
|
+
}
|
|
196
|
+
function avronPaths(env = process.env) {
|
|
197
|
+
const home = avronHome(env);
|
|
198
|
+
return {
|
|
199
|
+
home,
|
|
200
|
+
runDir: (0, import_node_path.join)(home, "run"),
|
|
201
|
+
logDir: (0, import_node_path.join)(home, "logs"),
|
|
202
|
+
dataDir: (0, import_node_path.join)(home, "data"),
|
|
203
|
+
cacheDir: (0, import_node_path.join)(home, "cache"),
|
|
204
|
+
keyDir: (0, import_node_path.join)(home, "keys"),
|
|
205
|
+
daemonLog: (0, import_node_path.join)(home, "logs", "daemon.log"),
|
|
206
|
+
impressionsLog: (0, import_node_path.join)(home, "logs", "impressions.ndjson"),
|
|
207
|
+
ledgerSnapshot: (0, import_node_path.join)(home, "data", "ledger.json"),
|
|
208
|
+
manifestCache: (0, import_node_path.join)(home, "cache", "manifest.json"),
|
|
209
|
+
eventQueue: (0, import_node_path.join)(home, "data", "queue.ndjson")
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
var UDS_MAX = 100;
|
|
213
|
+
function ipcEndpoint(env = process.env, platform = process.platform) {
|
|
214
|
+
const home = avronHome(env);
|
|
215
|
+
const tag = (0, import_node_crypto.createHash)("sha256").update(home).digest("hex").slice(0, 12);
|
|
216
|
+
if (platform === "win32") return `\\\\.\\pipe\\avron-uasp-${tag}.sock`;
|
|
217
|
+
const preferred = (0, import_node_path.join)(home, "run", "avron-uasp.sock");
|
|
218
|
+
if (Buffer.byteLength(preferred) <= UDS_MAX) return preferred;
|
|
219
|
+
return (0, import_node_path.join)((0, import_node_os.tmpdir)(), `avron-uasp-${tag}.sock`);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// packages/protocol/src/client.ts
|
|
223
|
+
var import_node_net = require("node:net");
|
|
224
|
+
|
|
225
|
+
// packages/protocol/src/quiet.ts
|
|
226
|
+
function quietHere(env = process.env) {
|
|
227
|
+
if (env.AVRON_ALLOW_CI === "1") return false;
|
|
228
|
+
const ci = (env.CI ?? "").trim().toLowerCase();
|
|
229
|
+
return ci !== "" && ci !== "0" && ci !== "false";
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// packages/protocol/src/client.ts
|
|
233
|
+
function request(msg, opts = {}) {
|
|
234
|
+
if (quietHere()) return Promise.resolve(null);
|
|
235
|
+
const endpoint = opts.endpoint ?? ipcEndpoint();
|
|
236
|
+
const timeoutMs = opts.timeoutMs ?? ADAPTER_TIMEOUT_MS;
|
|
237
|
+
return new Promise((resolve9) => {
|
|
238
|
+
let done = false;
|
|
239
|
+
let buf = "";
|
|
240
|
+
const finish = (value) => {
|
|
241
|
+
if (done) return;
|
|
242
|
+
done = true;
|
|
243
|
+
clearTimeout(timer);
|
|
244
|
+
socket.destroy();
|
|
245
|
+
resolve9(value);
|
|
246
|
+
};
|
|
247
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
248
|
+
const socket = (0, import_node_net.connect)(endpoint);
|
|
249
|
+
socket.setEncoding("utf8");
|
|
250
|
+
socket.on("connect", () => {
|
|
251
|
+
socket.write(serialize(msg));
|
|
252
|
+
});
|
|
253
|
+
socket.on("data", (chunk) => {
|
|
254
|
+
buf += chunk;
|
|
255
|
+
const nl = buf.indexOf("\n");
|
|
256
|
+
if (nl >= 0) finish(parsePayloadResponse(buf.slice(0, nl)));
|
|
257
|
+
else if (buf.length > MAX_LINE_BYTES) finish(null);
|
|
258
|
+
});
|
|
259
|
+
socket.on("error", () => finish(null));
|
|
260
|
+
socket.on("close", () => finish(null));
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
var DAEMON_STOP_LINE = '{"eventType":"DAEMON_CONTROL","action":"stop"}';
|
|
264
|
+
var DAEMON_STOP_ACK = '{"ok":true,"stopping":true}';
|
|
265
|
+
function stopDaemon(opts = {}) {
|
|
266
|
+
const endpoint = opts.endpoint ?? ipcEndpoint();
|
|
267
|
+
return new Promise((resolve9) => {
|
|
268
|
+
let done = false;
|
|
269
|
+
let buf = "";
|
|
270
|
+
const finish = (ok) => {
|
|
271
|
+
if (done) return;
|
|
272
|
+
done = true;
|
|
273
|
+
clearTimeout(timer);
|
|
274
|
+
socket.destroy();
|
|
275
|
+
resolve9(ok);
|
|
276
|
+
};
|
|
277
|
+
const timer = setTimeout(() => finish(false), opts.timeoutMs ?? 3e3);
|
|
278
|
+
const socket = (0, import_node_net.connect)(endpoint);
|
|
279
|
+
socket.setEncoding("utf8");
|
|
280
|
+
socket.on("connect", () => socket.write(`${DAEMON_STOP_LINE}
|
|
281
|
+
`));
|
|
282
|
+
socket.on("data", (chunk) => {
|
|
283
|
+
buf += chunk;
|
|
284
|
+
if (buf.includes(DAEMON_STOP_ACK)) finish(true);
|
|
285
|
+
else if (buf.length > MAX_LINE_BYTES) finish(false);
|
|
286
|
+
});
|
|
287
|
+
socket.on("error", () => finish(false));
|
|
288
|
+
socket.on("close", () => finish(false));
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// packages/protocol/src/spawn.ts
|
|
293
|
+
var import_node_child_process = require("node:child_process");
|
|
294
|
+
var import_node_fs = require("node:fs");
|
|
295
|
+
var import_node_path2 = require("node:path");
|
|
296
|
+
var runtimeFile = (env = process.env) => (0, import_node_path2.join)(avronHome(env), "runtime.json");
|
|
297
|
+
function chooseNode(opts = {}) {
|
|
298
|
+
const execPath = opts.execPath ?? process.execPath;
|
|
299
|
+
const electron = "electron" in opts ? opts.electron : process.versions.electron;
|
|
300
|
+
if (!electron && /^node(\.exe)?$/i.test((0, import_node_path2.basename)(execPath))) return execPath;
|
|
301
|
+
try {
|
|
302
|
+
const node = JSON.parse((0, import_node_fs.readFileSync)(opts.runtime ?? runtimeFile(), "utf8")).node;
|
|
303
|
+
if (typeof node === "string" && node.length > 0 && (0, import_node_fs.existsSync)(node)) return node;
|
|
304
|
+
} catch {
|
|
305
|
+
}
|
|
306
|
+
return "node";
|
|
307
|
+
}
|
|
308
|
+
function spawnDaemon(entry, env = process.env) {
|
|
309
|
+
try {
|
|
310
|
+
const child = (0, import_node_child_process.spawn)(chooseNode({ runtime: runtimeFile(env) }), [entry], {
|
|
311
|
+
detached: true,
|
|
312
|
+
stdio: "ignore",
|
|
313
|
+
windowsHide: true,
|
|
314
|
+
env
|
|
315
|
+
});
|
|
316
|
+
child.on("error", () => {
|
|
317
|
+
});
|
|
318
|
+
child.unref();
|
|
319
|
+
return true;
|
|
320
|
+
} catch {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// packages/adapter-kit/src/render.ts
|
|
326
|
+
var ESC = "\x1B";
|
|
327
|
+
var RESET = `${ESC}[0m`;
|
|
328
|
+
function safeLink(url) {
|
|
329
|
+
if (typeof url !== "string" || !url.startsWith(ALLOWED_LINK_PREFIX)) return null;
|
|
330
|
+
if (!/^https:\/\/avron\.dev\/go\/[A-Za-z0-9._~\-/?=&%]*$/.test(url)) return null;
|
|
331
|
+
return url;
|
|
332
|
+
}
|
|
333
|
+
var KNOWN_LABELS = /* @__PURE__ */ new Set([SPONSOR_LABEL, ...Object.values(SPONSOR_LABELS)]);
|
|
334
|
+
var style = {
|
|
335
|
+
truecolor: {
|
|
336
|
+
badge: `${ESC}[48;2;39;39;42m${ESC}[38;2;244;244;245m`,
|
|
337
|
+
dim: `${ESC}[38;2;113;113;122m`,
|
|
338
|
+
copy: `${ESC}[38;2;161;161;170m`,
|
|
339
|
+
cta: `${ESC}[38;2;52;211;153m`
|
|
340
|
+
},
|
|
341
|
+
basic: { badge: `${ESC}[7m`, dim: `${ESC}[2m`, copy: `${ESC}[2m`, cta: `${ESC}[32m` }
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// packages/adapter-kit/src/reversible.ts
|
|
345
|
+
var import_node_crypto2 = require("node:crypto");
|
|
346
|
+
var import_node_fs2 = require("node:fs");
|
|
347
|
+
var import_node_os2 = require("node:os");
|
|
348
|
+
var import_node_path3 = require("node:path");
|
|
349
|
+
var sha256 = (buf) => (0, import_node_crypto2.createHash)("sha256").update(buf).digest("hex");
|
|
350
|
+
function writeAtomic(file, data) {
|
|
351
|
+
(0, import_node_fs2.mkdirSync)((0, import_node_path3.dirname)(file), { recursive: true });
|
|
352
|
+
const tmp = `${file}.avron-tmp-${(0, import_node_crypto2.randomBytes)(4).toString("hex")}`;
|
|
353
|
+
(0, import_node_fs2.writeFileSync)(tmp, data);
|
|
354
|
+
(0, import_node_fs2.renameSync)(tmp, file);
|
|
355
|
+
}
|
|
356
|
+
var backupOf = (target) => `${target}.avron-backup`;
|
|
357
|
+
function readEditState(statePath2) {
|
|
358
|
+
try {
|
|
359
|
+
return JSON.parse((0, import_node_fs2.readFileSync)(statePath2, "utf8"));
|
|
360
|
+
} catch {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
function applyEdit(files2, transform) {
|
|
365
|
+
const { target, statePath: statePath2 } = files2;
|
|
366
|
+
const backup = backupOf(target);
|
|
367
|
+
const existed = (0, import_node_fs2.existsSync)(target);
|
|
368
|
+
const originalBytes = existed ? (0, import_node_fs2.readFileSync)(target) : Buffer.alloc(0);
|
|
369
|
+
const result = transform(originalBytes.toString("utf8"));
|
|
370
|
+
if (!result.changed) return { status: "already-installed", backupPath: existed ? backup : null };
|
|
371
|
+
const previous = readEditState(statePath2);
|
|
372
|
+
const keepPrevious = previous !== null && previous.settingsPath === target && (0, import_node_fs2.existsSync)(backup);
|
|
373
|
+
if (existed && !keepPrevious) writeAtomic(backup, originalBytes);
|
|
374
|
+
const installedBytes = Buffer.from(result.text, "utf8");
|
|
375
|
+
const state = keepPrevious ? { ...previous, installedSha256: sha256(installedBytes) } : {
|
|
376
|
+
settingsPath: target,
|
|
377
|
+
existed,
|
|
378
|
+
originalSha256: existed ? sha256(originalBytes) : null,
|
|
379
|
+
installedSha256: sha256(installedBytes),
|
|
380
|
+
...result.extra,
|
|
381
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
382
|
+
};
|
|
383
|
+
writeAtomic(statePath2, JSON.stringify(state, null, 2));
|
|
384
|
+
writeAtomic(target, installedBytes);
|
|
385
|
+
return { status: "installed", backupPath: existed ? backup : null };
|
|
386
|
+
}
|
|
387
|
+
function revertEdit(files2, merge, guard7 = () => {
|
|
388
|
+
}) {
|
|
389
|
+
const state = readEditState(files2.statePath);
|
|
390
|
+
if (!state) return { status: "not-installed", target: files2.target };
|
|
391
|
+
const target = state.settingsPath;
|
|
392
|
+
guard7(target);
|
|
393
|
+
const backup = backupOf(target);
|
|
394
|
+
let status = "restored-merged";
|
|
395
|
+
if ((0, import_node_fs2.existsSync)(target)) {
|
|
396
|
+
const current = (0, import_node_fs2.readFileSync)(target);
|
|
397
|
+
const untouched = sha256(current) === state.installedSha256;
|
|
398
|
+
if (untouched && !state.existed) {
|
|
399
|
+
(0, import_node_fs2.rmSync)(target);
|
|
400
|
+
status = "restored-exact";
|
|
401
|
+
} else if (untouched && (0, import_node_fs2.existsSync)(backup) && sha256((0, import_node_fs2.readFileSync)(backup)) === state.originalSha256) {
|
|
402
|
+
writeAtomic(target, (0, import_node_fs2.readFileSync)(backup));
|
|
403
|
+
status = "restored-exact";
|
|
404
|
+
} else {
|
|
405
|
+
const cleaned = merge(current.toString("utf8"), state);
|
|
406
|
+
if (cleaned.changed) writeAtomic(target, cleaned.text);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
(0, import_node_fs2.rmSync)(backup, { force: true });
|
|
410
|
+
(0, import_node_fs2.rmSync)(files2.statePath, { force: true });
|
|
411
|
+
return { status, target };
|
|
412
|
+
}
|
|
413
|
+
var PROTECTED_DIRS = [
|
|
414
|
+
".claude",
|
|
415
|
+
".cursor",
|
|
416
|
+
".codex",
|
|
417
|
+
".copilot",
|
|
418
|
+
".kiro",
|
|
419
|
+
".codeium",
|
|
420
|
+
".gemini",
|
|
421
|
+
".orca",
|
|
422
|
+
(0, import_node_path3.join)(".config", "opencode"),
|
|
423
|
+
(0, import_node_path3.join)("AppData", "Roaming", "orca"),
|
|
424
|
+
(0, import_node_path3.join)("Library", "Application Support", "orca")
|
|
425
|
+
];
|
|
426
|
+
function assertSafeTarget(target, env, home = (0, import_node_os2.homedir)()) {
|
|
427
|
+
if (env.AVRON_TEST !== "1" && env.VITEST === void 0) return;
|
|
428
|
+
const file = (0, import_node_path3.resolve)(target);
|
|
429
|
+
for (const dir of PROTECTED_DIRS) {
|
|
430
|
+
const rel = (0, import_node_path3.relative)((0, import_node_path3.resolve)(home, dir), file);
|
|
431
|
+
if (rel === "" || !rel.startsWith("..") && !(0, import_node_path3.isAbsolute)(rel)) {
|
|
432
|
+
throw new Error(`refusing to modify a real agent configuration folder (~/${dir}) from a test`);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// packages/adapter-kit/src/json.ts
|
|
438
|
+
var isObject3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
439
|
+
function detectStyle2(text) {
|
|
440
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
441
|
+
const m = /\n([ \t]+)"/.exec(text);
|
|
442
|
+
return { indent: m?.[1] ?? " ", eol, trailingNewline: text.length === 0 || /\n$/.test(text) };
|
|
443
|
+
}
|
|
444
|
+
function parseObject(text, what = "the file") {
|
|
445
|
+
const body = text.replace(/^/, "");
|
|
446
|
+
if (body.trim() === "") return {};
|
|
447
|
+
const parsed = JSON.parse(body);
|
|
448
|
+
if (!isObject3(parsed)) throw new Error(`${what} is not a JSON object`);
|
|
449
|
+
return parsed;
|
|
450
|
+
}
|
|
451
|
+
function stringifyStyled(obj, style2) {
|
|
452
|
+
let out = JSON.stringify(obj, null, style2.indent);
|
|
453
|
+
if (style2.eol === "\r\n") out = out.replace(/\n/g, "\r\n");
|
|
454
|
+
return style2.trailingNewline ? out + style2.eol : out;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// packages/adapter-claude-code/src/install.ts
|
|
458
|
+
var REFRESH_INTERVAL_SEC = 2;
|
|
459
|
+
function claudeDir(env = process.env) {
|
|
460
|
+
return env.AVRON_CLAUDE_DIR || env.CLAUDE_CONFIG_DIR || (0, import_node_path4.join)((0, import_node_os3.homedir)(), ".claude");
|
|
461
|
+
}
|
|
462
|
+
function claudePaths(env = process.env) {
|
|
463
|
+
const dir = claudeDir(env);
|
|
464
|
+
const home = avronHome(env);
|
|
465
|
+
const settingsPath = (0, import_node_path4.join)(dir, "settings.json");
|
|
466
|
+
return {
|
|
467
|
+
claudeDir: dir,
|
|
468
|
+
settingsPath,
|
|
469
|
+
backupPath: `${settingsPath}.avron-backup`,
|
|
470
|
+
statePath: (0, import_node_path4.join)(home, "adapters", "claude-code.json"),
|
|
471
|
+
binDir: (0, import_node_path4.join)(home, "bin")
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function guard(target, env) {
|
|
475
|
+
assertSafeTarget(target, env);
|
|
476
|
+
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
477
|
+
if ((0, import_node_path4.resolve)(target).toLowerCase() === (0, import_node_path4.resolve)((0, import_node_path4.join)((0, import_node_os3.homedir)(), ".claude", "settings.json")).toLowerCase())
|
|
478
|
+
throw new Error("refusing to modify the real ~/.claude directory from a test");
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function shellQuote(path) {
|
|
482
|
+
return `"${path.replace(/\\/g, "/")}"`;
|
|
483
|
+
}
|
|
484
|
+
function statuslineCommand(binDir) {
|
|
485
|
+
return `node ${shellQuote((0, import_node_path4.join)(binDir, STATUSLINE_SCRIPT))}`;
|
|
486
|
+
}
|
|
487
|
+
function hookCommand(binDir, event) {
|
|
488
|
+
return `node ${shellQuote((0, import_node_path4.join)(binDir, HOOK_SCRIPT))} ${HOOK_EVENTS[event]}`;
|
|
489
|
+
}
|
|
490
|
+
function readInstallState(env = process.env) {
|
|
491
|
+
return readEditState(claudePaths(env).statePath);
|
|
492
|
+
}
|
|
493
|
+
function installClaudeCode(env = process.env) {
|
|
494
|
+
const p = claudePaths(env);
|
|
495
|
+
try {
|
|
496
|
+
guard(p.settingsPath, env);
|
|
497
|
+
const res = applyEdit({ target: p.settingsPath, statePath: p.statePath }, (text) => {
|
|
498
|
+
const r = inject(text, {
|
|
499
|
+
statuslineCommand: statuslineCommand(p.binDir),
|
|
500
|
+
hookCommand: (event) => hookCommand(p.binDir, event),
|
|
501
|
+
refreshInterval: REFRESH_INTERVAL_SEC
|
|
502
|
+
});
|
|
503
|
+
return {
|
|
504
|
+
changed: r.changed,
|
|
505
|
+
text: r.text,
|
|
506
|
+
extra: {
|
|
507
|
+
hadStatusLine: r.hadStatusLine,
|
|
508
|
+
...r.hadStatusLine ? { originalStatusLine: r.originalStatusLine } : {}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
});
|
|
512
|
+
return { status: res.status, settingsPath: p.settingsPath, backupPath: res.backupPath };
|
|
513
|
+
} catch (err) {
|
|
514
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function uninstallClaudeCode(env = process.env) {
|
|
518
|
+
const p = claudePaths(env);
|
|
519
|
+
try {
|
|
520
|
+
guard(p.settingsPath, env);
|
|
521
|
+
const res = revertEdit(
|
|
522
|
+
{ target: p.settingsPath, statePath: p.statePath },
|
|
523
|
+
(text, state) => remove(text, { hadStatusLine: state.hadStatusLine, originalStatusLine: state.originalStatusLine }),
|
|
524
|
+
(target) => guard(target, env)
|
|
525
|
+
);
|
|
526
|
+
return { status: res.status, settingsPath: res.target };
|
|
527
|
+
} catch (err) {
|
|
528
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// packages/core/src/engine.ts
|
|
533
|
+
var SESSION_STALE_MS = 6 * 60 * 6e4;
|
|
534
|
+
|
|
535
|
+
// packages/core/src/logger.ts
|
|
536
|
+
var MAX_LOG_BYTES = 1024 * 1024;
|
|
537
|
+
var nullLogger = { info: () => {
|
|
538
|
+
}, error: () => {
|
|
539
|
+
} };
|
|
540
|
+
|
|
541
|
+
// packages/core/src/server.ts
|
|
542
|
+
var import_node_net2 = require("node:net");
|
|
543
|
+
function isAlive(endpoint, timeoutMs = 300) {
|
|
544
|
+
return new Promise((resolve9) => {
|
|
545
|
+
const socket = (0, import_node_net2.connect)(endpoint);
|
|
546
|
+
const done = (alive) => {
|
|
547
|
+
clearTimeout(timer);
|
|
548
|
+
socket.destroy();
|
|
549
|
+
resolve9(alive);
|
|
550
|
+
};
|
|
551
|
+
const timer = setTimeout(() => done(false), timeoutMs);
|
|
552
|
+
socket.once("connect", () => done(true));
|
|
553
|
+
socket.once("error", () => done(false));
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// packages/core/src/manifest.ts
|
|
558
|
+
var import_node_fs3 = require("node:fs");
|
|
559
|
+
var import_node_path5 = require("node:path");
|
|
560
|
+
|
|
561
|
+
// packages/core/src/default-manifest.json
|
|
562
|
+
var default_manifest_default = {
|
|
563
|
+
version: "2.0.0",
|
|
564
|
+
enabled: true,
|
|
565
|
+
ttlSeconds: 1800,
|
|
566
|
+
defaultLocale: "en",
|
|
567
|
+
campaigns: [
|
|
568
|
+
{
|
|
569
|
+
id: "house-how-it-works",
|
|
570
|
+
sponsorName: "Avron",
|
|
571
|
+
weight: 3,
|
|
572
|
+
creatives: {
|
|
573
|
+
pillStatusline: {
|
|
574
|
+
badge: "AVRON",
|
|
575
|
+
copy: "This line shows only while your agent thinks",
|
|
576
|
+
ctaButton: "How it works",
|
|
577
|
+
actionUrl: "https://avron.dev/go/how"
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
id: "house-privacy",
|
|
583
|
+
sponsorName: "Avron",
|
|
584
|
+
weight: 2,
|
|
585
|
+
creatives: {
|
|
586
|
+
pillStatusline: {
|
|
587
|
+
badge: "AVRON",
|
|
588
|
+
copy: "Reads no prompts, code or file paths",
|
|
589
|
+
ctaButton: "Verify it",
|
|
590
|
+
actionUrl: "https://avron.dev/go/audit"
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
id: "house-sponsor",
|
|
596
|
+
sponsorName: "Avron",
|
|
597
|
+
weight: 2,
|
|
598
|
+
creatives: {
|
|
599
|
+
pillStatusline: {
|
|
600
|
+
badge: "AVRON",
|
|
601
|
+
copy: "Dev-tool team? Put one line here",
|
|
602
|
+
ctaButton: "Sponsor",
|
|
603
|
+
actionUrl: "https://avron.dev/go/sponsor"
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
id: "house-uninstall",
|
|
609
|
+
sponsorName: "Avron",
|
|
610
|
+
weight: 1,
|
|
611
|
+
creatives: {
|
|
612
|
+
pillStatusline: {
|
|
613
|
+
badge: "AVRON",
|
|
614
|
+
copy: "Remove anytime with: npx @wbcode/avron uninstall"
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
]
|
|
619
|
+
};
|
|
620
|
+
|
|
621
|
+
// packages/core/src/manifest.ts
|
|
622
|
+
var LOGO_PREFIX = "https://avron.dev/";
|
|
623
|
+
var DEFAULT_DAILY_CAP = 60;
|
|
624
|
+
function str(v, max) {
|
|
625
|
+
return typeof v === "string" && v.length > 0 && v.length <= max ? v : void 0;
|
|
626
|
+
}
|
|
627
|
+
function isObject4(v) {
|
|
628
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
629
|
+
}
|
|
630
|
+
function parseCard(raw) {
|
|
631
|
+
if (!isObject4(raw)) return void 0;
|
|
632
|
+
const snippet = codeLines(raw.snippet);
|
|
633
|
+
const body = str(raw.body, 160);
|
|
634
|
+
const logo = str(raw.logoUrl, 300);
|
|
635
|
+
const logoUrl = logo?.startsWith(LOGO_PREFIX) && /^[A-Za-z0-9._~\-/:%]+$/.test(logo) ? logo : void 0;
|
|
636
|
+
const image = str(raw.imageUrl, 300);
|
|
637
|
+
const imageUrl = image?.startsWith(LOGO_PREFIX) && /^[A-Za-z0-9._~\-/:%]+\.(png|webp)$/.test(image) ? image : void 0;
|
|
638
|
+
if (!snippet && !body && !logoUrl && !imageUrl) return void 0;
|
|
639
|
+
return {
|
|
640
|
+
...snippet ? { snippet } : {},
|
|
641
|
+
...body ? { body } : {},
|
|
642
|
+
...logoUrl ? { logoUrl } : {},
|
|
643
|
+
...imageUrl ? { imageUrl } : {}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
function codeLines(raw) {
|
|
647
|
+
if (typeof raw !== "string" || raw.length === 0 || raw.length > 200) return void 0;
|
|
648
|
+
const lines = raw.split(String.fromCharCode(10));
|
|
649
|
+
if (lines.length > 3 || lines.some((l) => l.length === 0 || l.length > 64)) return void 0;
|
|
650
|
+
return raw;
|
|
651
|
+
}
|
|
652
|
+
function idList(raw, re) {
|
|
653
|
+
if (!Array.isArray(raw)) return void 0;
|
|
654
|
+
const out = raw.filter((v) => typeof v === "string" && re.test(v)).slice(0, 20);
|
|
655
|
+
return out.length ? out : void 0;
|
|
656
|
+
}
|
|
657
|
+
function parseTargets(raw) {
|
|
658
|
+
if (!isObject4(raw)) return void 0;
|
|
659
|
+
const agents = idList(raw.agents, /^[a-z0-9-]{1,32}$/);
|
|
660
|
+
const locales = idList(raw.locales, /^[a-z]{2}(-[A-Za-z]{2,4})?$/);
|
|
661
|
+
if (!agents && !locales) return void 0;
|
|
662
|
+
return { ...agents ? { agents } : {}, ...locales ? { locales } : {} };
|
|
663
|
+
}
|
|
664
|
+
function parseManifest(raw) {
|
|
665
|
+
if (!isObject4(raw) || !Array.isArray(raw.campaigns)) return null;
|
|
666
|
+
const campaigns = [];
|
|
667
|
+
for (const c of raw.campaigns) {
|
|
668
|
+
if (!isObject4(c) || !isObject4(c.creatives)) continue;
|
|
669
|
+
const id = str(c.id, 64);
|
|
670
|
+
const sponsorName = str(c.sponsorName, 40);
|
|
671
|
+
const pill = c.creatives.pillStatusline;
|
|
672
|
+
if (!id || !/^[A-Za-z0-9._-]+$/.test(id) || !sponsorName || !isObject4(pill)) continue;
|
|
673
|
+
const copy = str(pill.copy, 120);
|
|
674
|
+
if (!copy) continue;
|
|
675
|
+
const actionUrl = str(pill.actionUrl, 300);
|
|
676
|
+
const locales = {};
|
|
677
|
+
if (isObject4(c.creatives.locales)) {
|
|
678
|
+
for (const [lang, v] of Object.entries(c.creatives.locales)) {
|
|
679
|
+
if (!isObject4(v) || !/^[a-z]{2}(-[A-Z]{2})?$/.test(lang)) continue;
|
|
680
|
+
locales[lang] = { copy: str(v.copy, 120), ctaButton: str(v.ctaButton, 28) };
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
const microTag = str(c.creatives.microTag, 40);
|
|
684
|
+
const card = parseCard(c.creatives.card);
|
|
685
|
+
const art = cleanArt(c.creatives.art);
|
|
686
|
+
const motion = MOTIONS.includes(c.creatives.motion) ? c.creatives.motion : void 0;
|
|
687
|
+
const targets = parseTargets(c.targets);
|
|
688
|
+
campaigns.push({
|
|
689
|
+
id,
|
|
690
|
+
sponsorName,
|
|
691
|
+
weight: typeof c.weight === "number" && c.weight > 0 ? Math.min(c.weight, 1e3) : 1,
|
|
692
|
+
dailyCap: typeof c.dailyCap === "number" && c.dailyCap > 0 ? Math.floor(c.dailyCap) : DEFAULT_DAILY_CAP,
|
|
693
|
+
promoCode: str(c.promoCode, 40),
|
|
694
|
+
...microTag && [...microTag].length <= MICRO_TAG_MAX_CHARS ? { microTag } : {},
|
|
695
|
+
pill: {
|
|
696
|
+
badge: str(pill.badge, 24) ?? sponsorName,
|
|
697
|
+
copy,
|
|
698
|
+
ctaButton: str(pill.ctaButton, 28),
|
|
699
|
+
// Anything that is not an avron.dev/go link is dropped here and again at render time.
|
|
700
|
+
...actionUrl?.startsWith(ALLOWED_LINK_PREFIX) ? { actionUrl } : {}
|
|
701
|
+
},
|
|
702
|
+
locales,
|
|
703
|
+
...card ? { card } : {},
|
|
704
|
+
...art ? { art } : {},
|
|
705
|
+
...art && motion ? { motion } : {},
|
|
706
|
+
...targets ? { targets } : {},
|
|
707
|
+
...isAdTier(c.tier) && c.tier !== "line" ? { tier: c.tier } : {}
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
version: str(raw.version, 20) ?? "0",
|
|
712
|
+
enabled: raw.enabled !== false,
|
|
713
|
+
serverNonce: str(raw.serverNonce, 300),
|
|
714
|
+
ttlSeconds: typeof raw.ttlSeconds === "number" && raw.ttlSeconds > 0 ? raw.ttlSeconds : 1800,
|
|
715
|
+
campaigns
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
function readJson(file) {
|
|
719
|
+
try {
|
|
720
|
+
return JSON.parse((0, import_node_fs3.readFileSync)(file, "utf8"));
|
|
721
|
+
} catch {
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
var ManifestStore = class {
|
|
726
|
+
constructor(env, log) {
|
|
727
|
+
this.env = env;
|
|
728
|
+
this.log = log;
|
|
729
|
+
this.manifest = parseManifest(default_manifest_default) ?? {
|
|
730
|
+
version: "0",
|
|
731
|
+
enabled: true,
|
|
732
|
+
ttlSeconds: 1800,
|
|
733
|
+
campaigns: []
|
|
734
|
+
};
|
|
735
|
+
this.reload();
|
|
736
|
+
}
|
|
737
|
+
manifest;
|
|
738
|
+
current() {
|
|
739
|
+
return this.manifest;
|
|
740
|
+
}
|
|
741
|
+
/** Re-read from disk. Keeps the previous manifest if nothing valid is found. */
|
|
742
|
+
reload() {
|
|
743
|
+
const paths = avronPaths(this.env);
|
|
744
|
+
const dropIn = (0, import_node_path5.join)(paths.home, "manifest.override.json");
|
|
745
|
+
const override = this.env.AVRON_MANIFEST_FILE || ((0, import_node_fs3.existsSync)(dropIn) ? dropIn : void 0);
|
|
746
|
+
const sources = override ? [override] : [paths.manifestCache];
|
|
747
|
+
for (const file of sources) {
|
|
748
|
+
const parsed = parseManifest(readJson(file));
|
|
749
|
+
if (parsed) {
|
|
750
|
+
this.manifest = parsed;
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (override) this.log.error(`manifest override is not usable: ${file}`);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
// packages/core/src/identity.ts
|
|
759
|
+
var import_node_crypto3 = require("node:crypto");
|
|
760
|
+
var import_node_fs4 = require("node:fs");
|
|
761
|
+
var import_node_path6 = require("node:path");
|
|
762
|
+
var files = (paths) => ({
|
|
763
|
+
priv: (0, import_node_path6.join)(paths.keyDir, "private.key"),
|
|
764
|
+
pub: (0, import_node_path6.join)(paths.keyDir, "public.key")
|
|
765
|
+
});
|
|
766
|
+
function describe(publicKeyPem) {
|
|
767
|
+
const der = (0, import_node_crypto3.createPublicKey)(publicKeyPem).export({ type: "spki", format: "der" });
|
|
768
|
+
const installId = (0, import_node_crypto3.createHash)("sha256").update(der).digest("hex");
|
|
769
|
+
return { installId, ref: installId.slice(0, 6), publicKeyPem };
|
|
770
|
+
}
|
|
771
|
+
function loadIdentity(paths) {
|
|
772
|
+
try {
|
|
773
|
+
return describe((0, import_node_fs4.readFileSync)(files(paths).pub, "utf8"));
|
|
774
|
+
} catch {
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
function ensureIdentity(paths) {
|
|
779
|
+
const f = files(paths);
|
|
780
|
+
if ((0, import_node_fs4.existsSync)(f.priv) && (0, import_node_fs4.existsSync)(f.pub)) {
|
|
781
|
+
const existing = loadIdentity(paths);
|
|
782
|
+
if (existing) return existing;
|
|
783
|
+
}
|
|
784
|
+
(0, import_node_fs4.mkdirSync)(paths.keyDir, { recursive: true });
|
|
785
|
+
const { privateKey, publicKey } = (0, import_node_crypto3.generateKeyPairSync)("ed25519");
|
|
786
|
+
const pub = publicKey.export({ type: "spki", format: "pem" }).toString();
|
|
787
|
+
(0, import_node_fs4.writeFileSync)(f.priv, privateKey.export({ type: "pkcs8", format: "pem" }).toString(), { mode: 384 });
|
|
788
|
+
(0, import_node_fs4.writeFileSync)(f.pub, pub);
|
|
789
|
+
if (process.platform !== "win32") {
|
|
790
|
+
(0, import_node_fs4.chmodSync)(paths.keyDir, 448);
|
|
791
|
+
(0, import_node_fs4.chmodSync)(f.priv, 384);
|
|
792
|
+
}
|
|
793
|
+
return describe(pub);
|
|
794
|
+
}
|
|
795
|
+
function signPayload(paths, payload) {
|
|
796
|
+
try {
|
|
797
|
+
const key = (0, import_node_crypto3.createPrivateKey)((0, import_node_fs4.readFileSync)(files(paths).priv, "utf8"));
|
|
798
|
+
return (0, import_node_crypto3.sign)(null, Buffer.from(payload, "utf8"), key).toString("base64");
|
|
799
|
+
} catch {
|
|
800
|
+
return null;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
function exportIdentity(paths) {
|
|
804
|
+
try {
|
|
805
|
+
const f = files(paths);
|
|
806
|
+
const id = loadIdentity(paths);
|
|
807
|
+
if (!id) return null;
|
|
808
|
+
return {
|
|
809
|
+
v: 1,
|
|
810
|
+
installId: id.installId,
|
|
811
|
+
privateKeyPem: (0, import_node_fs4.readFileSync)(f.priv, "utf8"),
|
|
812
|
+
publicKeyPem: id.publicKeyPem
|
|
813
|
+
};
|
|
814
|
+
} catch {
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
function importIdentity(paths, backup, force) {
|
|
819
|
+
const b = backup;
|
|
820
|
+
if (!b || b.v !== 1 || typeof b.privateKeyPem !== "string" || typeof b.publicKeyPem !== "string")
|
|
821
|
+
return { ok: false, reason: "invalid" };
|
|
822
|
+
try {
|
|
823
|
+
const priv = (0, import_node_crypto3.createPrivateKey)(b.privateKeyPem);
|
|
824
|
+
const pub = (0, import_node_crypto3.createPublicKey)(b.publicKeyPem);
|
|
825
|
+
const probe = Buffer.from("avron-key-check");
|
|
826
|
+
if (!(0, import_node_crypto3.verify)(null, probe, pub, (0, import_node_crypto3.sign)(null, probe, priv))) return { ok: false, reason: "invalid" };
|
|
827
|
+
} catch {
|
|
828
|
+
return { ok: false, reason: "invalid" };
|
|
829
|
+
}
|
|
830
|
+
const current = loadIdentity(paths);
|
|
831
|
+
const incoming = describe(b.publicKeyPem);
|
|
832
|
+
if (current && current.installId !== incoming.installId && !force) return { ok: false, reason: "exists" };
|
|
833
|
+
const f = files(paths);
|
|
834
|
+
(0, import_node_fs4.mkdirSync)(paths.keyDir, { recursive: true });
|
|
835
|
+
(0, import_node_fs4.writeFileSync)(f.priv, b.privateKeyPem, { mode: 384 });
|
|
836
|
+
(0, import_node_fs4.writeFileSync)(f.pub, b.publicKeyPem);
|
|
837
|
+
if (process.platform !== "win32") {
|
|
838
|
+
(0, import_node_fs4.chmodSync)(paths.keyDir, 448);
|
|
839
|
+
(0, import_node_fs4.chmodSync)(f.priv, 384);
|
|
840
|
+
}
|
|
841
|
+
return { ok: true, identity: incoming };
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// packages/core/src/config.ts
|
|
845
|
+
var import_node_fs5 = require("node:fs");
|
|
846
|
+
var import_node_path7 = require("node:path");
|
|
847
|
+
var DEFAULT_FORMATS = {
|
|
848
|
+
card: true,
|
|
849
|
+
codeLines: 3,
|
|
850
|
+
banner: false,
|
|
851
|
+
motion: false,
|
|
852
|
+
poster: false,
|
|
853
|
+
image: true,
|
|
854
|
+
toast: true
|
|
855
|
+
};
|
|
856
|
+
var DEFAULT_CONFIG = {
|
|
857
|
+
mode: "pill-statusline",
|
|
858
|
+
paused: false,
|
|
859
|
+
formats: { ...DEFAULT_FORMATS }
|
|
860
|
+
};
|
|
861
|
+
function readFormats(raw) {
|
|
862
|
+
const f = typeof raw === "object" && raw !== null ? raw : {};
|
|
863
|
+
const flag = (k) => typeof f[k] === "boolean" ? f[k] : DEFAULT_FORMATS[k];
|
|
864
|
+
const lines = f.codeLines;
|
|
865
|
+
return {
|
|
866
|
+
card: flag("card"),
|
|
867
|
+
codeLines: lines === 1 || lines === 2 || lines === 3 ? lines : DEFAULT_FORMATS.codeLines,
|
|
868
|
+
banner: flag("banner"),
|
|
869
|
+
motion: flag("motion"),
|
|
870
|
+
poster: flag("poster"),
|
|
871
|
+
image: flag("image"),
|
|
872
|
+
toast: flag("toast")
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
function configPath(env = process.env) {
|
|
876
|
+
return (0, import_node_path7.join)(avronHome(env), "config.json");
|
|
877
|
+
}
|
|
878
|
+
function readConfig(env = process.env) {
|
|
879
|
+
try {
|
|
880
|
+
const raw = JSON.parse((0, import_node_fs5.readFileSync)(configPath(env), "utf8"));
|
|
881
|
+
return {
|
|
882
|
+
mode: raw.mode === "pill-statusline" ? raw.mode : DEFAULT_CONFIG.mode,
|
|
883
|
+
paused: raw.paused === true,
|
|
884
|
+
formats: readFormats(raw.formats)
|
|
885
|
+
};
|
|
886
|
+
} catch {
|
|
887
|
+
return { ...DEFAULT_CONFIG, formats: { ...DEFAULT_FORMATS } };
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
function writeConfig(patch, env = process.env) {
|
|
891
|
+
const next = { ...readConfig(env), ...patch };
|
|
892
|
+
const file = configPath(env);
|
|
893
|
+
(0, import_node_fs5.mkdirSync)((0, import_node_path7.dirname)(file), { recursive: true });
|
|
894
|
+
const tmp = `${file}.tmp`;
|
|
895
|
+
(0, import_node_fs5.writeFileSync)(tmp, `${JSON.stringify(next, null, 2)}
|
|
896
|
+
`);
|
|
897
|
+
(0, import_node_fs5.renameSync)(tmp, file);
|
|
898
|
+
return next;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
// packages/core/src/sync.ts
|
|
902
|
+
var import_node_crypto4 = require("node:crypto");
|
|
903
|
+
var import_node_fs6 = require("node:fs");
|
|
904
|
+
var import_node_path8 = require("node:path");
|
|
905
|
+
var DEFAULT_API_BASE = "https://avron.dev";
|
|
906
|
+
var MAX_EVENTS_PER_BATCH = 500;
|
|
907
|
+
var HTTP_TIMEOUT_MS = 8e3;
|
|
908
|
+
function apiBase(env) {
|
|
909
|
+
const v = env.AVRON_API_BASE;
|
|
910
|
+
return v && /^https?:\/\//.test(v) ? v.replace(/\/+$/, "") : DEFAULT_API_BASE;
|
|
911
|
+
}
|
|
912
|
+
async function http(fetchImpl, url, timeoutMs, init) {
|
|
913
|
+
const ctl = new AbortController();
|
|
914
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
915
|
+
try {
|
|
916
|
+
return await fetchImpl(url, { ...init, signal: ctl.signal });
|
|
917
|
+
} finally {
|
|
918
|
+
clearTimeout(timer);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
var statePath = (paths) => (0, import_node_path8.join)(paths.dataDir, "sync-state.json");
|
|
922
|
+
var count = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0 ? v : void 0;
|
|
923
|
+
function readState(paths) {
|
|
924
|
+
try {
|
|
925
|
+
const s = JSON.parse((0, import_node_fs6.readFileSync)(statePath(paths), "utf8"));
|
|
926
|
+
const accepted = count(s.accepted);
|
|
927
|
+
const acceptedAt = count(s.acceptedAt);
|
|
928
|
+
return {
|
|
929
|
+
offset: count(s.offset) ?? 0,
|
|
930
|
+
...accepted !== void 0 ? { accepted } : {},
|
|
931
|
+
...acceptedAt !== void 0 ? { acceptedAt } : {}
|
|
932
|
+
};
|
|
933
|
+
} catch {
|
|
934
|
+
return { offset: 0 };
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function serverCounted(paths) {
|
|
938
|
+
const s = readState(paths);
|
|
939
|
+
return s.accepted !== void 0 && s.acceptedAt !== void 0 ? { accepted: s.accepted, at: s.acceptedAt } : null;
|
|
940
|
+
}
|
|
941
|
+
function readPending(paths) {
|
|
942
|
+
let size = 0;
|
|
943
|
+
try {
|
|
944
|
+
size = (0, import_node_fs6.statSync)(paths.impressionsLog).size;
|
|
945
|
+
} catch {
|
|
946
|
+
return { events: [], nextOffset: 0, size: 0 };
|
|
947
|
+
}
|
|
948
|
+
let offset = Math.min(readState(paths).offset, size);
|
|
949
|
+
const fd = (0, import_node_fs6.openSync)(paths.impressionsLog, "r");
|
|
950
|
+
try {
|
|
951
|
+
if (size - offset > OFFLINE_QUEUE_MAX_BYTES) {
|
|
952
|
+
offset = size - OFFLINE_QUEUE_MAX_BYTES;
|
|
953
|
+
const probe = Buffer.alloc(4096);
|
|
954
|
+
const n = (0, import_node_fs6.readSync)(fd, probe, 0, probe.length, offset);
|
|
955
|
+
const nl = probe.subarray(0, n).indexOf(10);
|
|
956
|
+
offset += nl >= 0 ? nl + 1 : n;
|
|
957
|
+
}
|
|
958
|
+
const want = Math.min(size - offset, 512 * 1024);
|
|
959
|
+
const buf = Buffer.alloc(want);
|
|
960
|
+
const got = (0, import_node_fs6.readSync)(fd, buf, 0, want, offset);
|
|
961
|
+
const chunk = buf.subarray(0, got);
|
|
962
|
+
const events = [];
|
|
963
|
+
let consumed = 0;
|
|
964
|
+
while (events.length < MAX_EVENTS_PER_BATCH) {
|
|
965
|
+
const nl = chunk.indexOf(10, consumed);
|
|
966
|
+
if (nl < 0) break;
|
|
967
|
+
const line = chunk.subarray(consumed, nl).toString("utf8");
|
|
968
|
+
consumed = nl + 1;
|
|
969
|
+
try {
|
|
970
|
+
const e = JSON.parse(line);
|
|
971
|
+
if (e.mode !== "pill-statusline") continue;
|
|
972
|
+
events.push({
|
|
973
|
+
turnKey: e.turnKey,
|
|
974
|
+
timestamp: e.timestamp,
|
|
975
|
+
campaignId: e.campaignId,
|
|
976
|
+
agentName: e.agentName,
|
|
977
|
+
agentTier: e.agentTier,
|
|
978
|
+
exposureDurationSec: e.exposureDurationSec,
|
|
979
|
+
displayedDurationSec: e.displayedDurationSec,
|
|
980
|
+
mode: e.mode,
|
|
981
|
+
format: e.format ?? "line"
|
|
982
|
+
});
|
|
983
|
+
} catch {
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return { events, nextOffset: offset + consumed, size };
|
|
987
|
+
} finally {
|
|
988
|
+
(0, import_node_fs6.closeSync)(fd);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
function buildBatch(paths, nonce, now) {
|
|
992
|
+
return signBatch(paths, readPending(paths), nonce, now);
|
|
993
|
+
}
|
|
994
|
+
function signBatch(paths, pending, nonce, now) {
|
|
995
|
+
if (pending.events.length === 0) return null;
|
|
996
|
+
const identity = loadIdentity(paths);
|
|
997
|
+
if (!identity) return null;
|
|
998
|
+
const payload = JSON.stringify({
|
|
999
|
+
v: 1,
|
|
1000
|
+
installId: identity.installId,
|
|
1001
|
+
nonce: nonce ?? null,
|
|
1002
|
+
sentAt: now,
|
|
1003
|
+
events: pending.events
|
|
1004
|
+
});
|
|
1005
|
+
const signature = signPayload(paths, payload);
|
|
1006
|
+
if (!signature) return null;
|
|
1007
|
+
const publicKey = (0, import_node_crypto4.createPublicKey)(identity.publicKeyPem).export({ type: "spki", format: "der" }).toString("base64");
|
|
1008
|
+
return {
|
|
1009
|
+
envelope: { payload, publicKey, signature },
|
|
1010
|
+
events: pending.events,
|
|
1011
|
+
nextOffset: pending.nextOffset
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
function signedRequest(paths, purpose, now, extra = {}) {
|
|
1015
|
+
const identity = loadIdentity(paths);
|
|
1016
|
+
if (!identity) return null;
|
|
1017
|
+
const payload = JSON.stringify({ ...extra, installId: identity.installId, purpose, ts: now });
|
|
1018
|
+
const signature = signPayload(paths, payload);
|
|
1019
|
+
if (!signature) return null;
|
|
1020
|
+
const publicKey = (0, import_node_crypto4.createPublicKey)(identity.publicKeyPem).export({ type: "spki", format: "der" }).toString("base64");
|
|
1021
|
+
return { payload, publicKey, signature };
|
|
1022
|
+
}
|
|
1023
|
+
async function postSigned(env, paths, path, purpose, extra = {}, fetchImpl = fetch, now = Date.now(), timeoutMs = HTTP_TIMEOUT_MS) {
|
|
1024
|
+
const envelope = signedRequest(paths, purpose, now, extra);
|
|
1025
|
+
if (!envelope) return null;
|
|
1026
|
+
try {
|
|
1027
|
+
const res = await http(fetchImpl, `${apiBase(env)}${path}`, timeoutMs, {
|
|
1028
|
+
method: "POST",
|
|
1029
|
+
headers: { "content-type": "application/json" },
|
|
1030
|
+
body: JSON.stringify(envelope)
|
|
1031
|
+
});
|
|
1032
|
+
const body = JSON.parse(await res.text() || "{}");
|
|
1033
|
+
return { status: res.status, body };
|
|
1034
|
+
} catch {
|
|
1035
|
+
return null;
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// packages/core/src/toast.ts
|
|
1040
|
+
var import_node_child_process2 = require("node:child_process");
|
|
1041
|
+
var WINDOWS_APP_ID = "Avron.Notifier";
|
|
1042
|
+
var WINDOWS_APP_KEY = `HKCU:\\Software\\Classes\\AppUserModelId\\${WINDOWS_APP_ID}`;
|
|
1043
|
+
var WINDOWS_SCRIPT = [
|
|
1044
|
+
'$ErrorActionPreference = "Stop"',
|
|
1045
|
+
"[void][Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]",
|
|
1046
|
+
"[void][Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime]",
|
|
1047
|
+
`$k = '${WINDOWS_APP_KEY}'`,
|
|
1048
|
+
'if (-not (Test-Path $k)) { [void](New-Item $k -Force); [void](New-ItemProperty $k -Name DisplayName -Value "Avron" -PropertyType String -Force) }',
|
|
1049
|
+
"$t = New-Object Windows.Data.Xml.Dom.XmlDocument",
|
|
1050
|
+
`$t.LoadXml('<toast duration="long"><visual><binding template="ToastGeneric"><text/><text/><text/></binding></visual></toast>')`,
|
|
1051
|
+
'$b = $t.GetElementsByTagName("binding").Item(0)',
|
|
1052
|
+
'$n = $t.GetElementsByTagName("text")',
|
|
1053
|
+
"[void]$n.Item(0).AppendChild($t.CreateTextNode($env:AVRON_TOAST_TITLE))",
|
|
1054
|
+
"[void]$n.Item(1).AppendChild($t.CreateTextNode($env:AVRON_TOAST_BODY))",
|
|
1055
|
+
"[void]$n.Item(2).AppendChild($t.CreateTextNode($env:AVRON_TOAST_EXTRA))",
|
|
1056
|
+
'if ($env:AVRON_TOAST_HERO) { $i = $t.CreateElement("image"); $i.SetAttribute("placement", "hero"); $i.SetAttribute("src", $env:AVRON_TOAST_HERO); [void]$b.InsertBefore($i, $b.FirstChild) }',
|
|
1057
|
+
'if ($env:AVRON_TOAST_IMAGE) { $i = $t.CreateElement("image"); $i.SetAttribute("placement", "appLogoOverride"); $i.SetAttribute("src", $env:AVRON_TOAST_IMAGE); [void]$b.InsertBefore($i, $b.FirstChild) }',
|
|
1058
|
+
'if ($env:AVRON_TOAST_URL) { $t.DocumentElement.SetAttribute("activationType", "protocol"); $t.DocumentElement.SetAttribute("launch", $env:AVRON_TOAST_URL) }',
|
|
1059
|
+
"$toast = [Windows.UI.Notifications.ToastNotification]::new($t)",
|
|
1060
|
+
"$toast.ExpirationTime = [DateTimeOffset]::Now.AddSeconds(30)",
|
|
1061
|
+
'$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Avron.Notifier")',
|
|
1062
|
+
// Windows reports success even when the user (or a policy) has switched this app's notifications
|
|
1063
|
+
// off, so ask first: a notification nobody can see must not count as shown (exit code 3).
|
|
1064
|
+
'if ($notifier.Setting.ToString() -ne "Enabled") { exit 3 }',
|
|
1065
|
+
"$notifier.Show($toast)"
|
|
1066
|
+
].join("; ");
|
|
1067
|
+
function removeToastRegistration(env = process.env) {
|
|
1068
|
+
if (process.platform !== "win32" || env.AVRON_TEST) return;
|
|
1069
|
+
try {
|
|
1070
|
+
(0, import_node_child_process2.spawn)(
|
|
1071
|
+
"powershell.exe",
|
|
1072
|
+
[
|
|
1073
|
+
"-NoProfile",
|
|
1074
|
+
"-NonInteractive",
|
|
1075
|
+
"-Command",
|
|
1076
|
+
`Remove-Item '${WINDOWS_APP_KEY}' -Recurse -Force -ErrorAction SilentlyContinue`
|
|
1077
|
+
],
|
|
1078
|
+
{
|
|
1079
|
+
stdio: "ignore",
|
|
1080
|
+
windowsHide: true
|
|
1081
|
+
}
|
|
1082
|
+
).on("error", () => {
|
|
1083
|
+
});
|
|
1084
|
+
} catch {
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// scripts/bin-copies.json
|
|
1089
|
+
var bin_copies_default = {
|
|
1090
|
+
"avron-opencode.tsx": "packages/adapter-opencode/plugin/avron-opencode.tsx"
|
|
1091
|
+
};
|
|
1092
|
+
|
|
1093
|
+
// scripts/bin-entries.json
|
|
1094
|
+
var bin_entries_default = {
|
|
1095
|
+
"avron-statusline": "packages/adapter-claude-code/src/statusline.ts",
|
|
1096
|
+
"avron-hook": "packages/adapter-claude-code/src/hook.ts",
|
|
1097
|
+
"avron-antigravity-hook": "packages/adapter-antigravity/src/hook.ts",
|
|
1098
|
+
"avron-antigravity-statusline": "packages/adapter-antigravity/src/statusline.ts",
|
|
1099
|
+
"avron-codex-hook": "packages/adapter-codex/src/hook.ts",
|
|
1100
|
+
"avron-copilot-hook": "packages/adapter-copilot/src/hook.ts",
|
|
1101
|
+
"avron-copilot-statusline": "packages/adapter-copilot/src/statusline.ts",
|
|
1102
|
+
"avron-cursor-hook": "packages/adapter-cursor/src/hook.ts",
|
|
1103
|
+
"avron-daemon": "packages/core/src/daemon-main.ts"
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
// scripts/bin-esm-entries.json
|
|
1107
|
+
var bin_esm_entries_default = {
|
|
1108
|
+
"avron-opencode-core": "packages/adapter-opencode/src/core.ts"
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
// packages/cli/src/adapters.ts
|
|
1112
|
+
var import_node_fs11 = require("node:fs");
|
|
1113
|
+
var import_node_os9 = require("node:os");
|
|
1114
|
+
var import_node_path14 = require("node:path");
|
|
1115
|
+
|
|
1116
|
+
// packages/adapter-antigravity/src/install.ts
|
|
1117
|
+
var import_node_fs7 = require("node:fs");
|
|
1118
|
+
var import_node_os4 = require("node:os");
|
|
1119
|
+
var import_node_path9 = require("node:path");
|
|
1120
|
+
var HOOK_SCRIPT2 = "avron-antigravity-hook.cjs";
|
|
1121
|
+
var STATUSLINE_SCRIPT2 = "avron-antigravity-statusline.cjs";
|
|
1122
|
+
var GROUP = "avron";
|
|
1123
|
+
var HOOK_EVENTS2 = { PreInvocation: "busy", Stop: "idle" };
|
|
1124
|
+
var TIMEOUT_SEC = 3;
|
|
1125
|
+
function geminiDir(env = process.env) {
|
|
1126
|
+
return env.AVRON_ANTIGRAVITY_DIR || (0, import_node_path9.join)((0, import_node_os4.homedir)(), ".gemini");
|
|
1127
|
+
}
|
|
1128
|
+
function antigravityPaths(env = process.env) {
|
|
1129
|
+
const dir = geminiDir(env);
|
|
1130
|
+
const home = avronHome(env);
|
|
1131
|
+
return {
|
|
1132
|
+
geminiDir: dir,
|
|
1133
|
+
hooksFile: (0, import_node_path9.join)(dir, "config", "hooks.json"),
|
|
1134
|
+
settingsFile: (0, import_node_path9.join)(dir, "antigravity-cli", "settings.json"),
|
|
1135
|
+
hooksState: (0, import_node_path9.join)(home, "adapters", "antigravity-hooks.json"),
|
|
1136
|
+
settingsState: (0, import_node_path9.join)(home, "adapters", "antigravity-cli.json"),
|
|
1137
|
+
binDir: (0, import_node_path9.join)(home, "bin")
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
var isOurCommand2 = (command) => typeof command === "string" && (command.includes(HOOK_SCRIPT2) || command.includes(STATUSLINE_SCRIPT2));
|
|
1141
|
+
function scriptCommand(binDir, script, args = "", platform = process.platform) {
|
|
1142
|
+
const tail = args ? ` ${args}` : "";
|
|
1143
|
+
const path = (0, import_node_path9.join)(binDir, script).replace(/\\/g, "/");
|
|
1144
|
+
if (platform !== "win32") return `node "${path}"${tail}`;
|
|
1145
|
+
if (!/[\s"&|<>^%()]/.test(path)) return `node ${path}${tail}`;
|
|
1146
|
+
return `cd /d ${binDir.replace(/\//g, "\\")} && node ${script}${tail}`;
|
|
1147
|
+
}
|
|
1148
|
+
var hookCommand2 = (binDir, arg, platform) => scriptCommand(binDir, HOOK_SCRIPT2, arg, platform);
|
|
1149
|
+
var statuslineCommand2 = (binDir, platform) => scriptCommand(binDir, STATUSLINE_SCRIPT2, "", platform);
|
|
1150
|
+
function groupIsOurs(group) {
|
|
1151
|
+
if (!isObject3(group)) return false;
|
|
1152
|
+
const handlers = Object.values(group).flatMap((v) => Array.isArray(v) ? v : []);
|
|
1153
|
+
return handlers.length > 0 && handlers.every((h) => isObject3(h) && isOurCommand2(h.command));
|
|
1154
|
+
}
|
|
1155
|
+
function injectHooks(text, binDir) {
|
|
1156
|
+
const file = parseObject(text, "hooks.json");
|
|
1157
|
+
const current = file[GROUP];
|
|
1158
|
+
if (current !== void 0) {
|
|
1159
|
+
if (groupIsOurs(current)) return { text, changed: false };
|
|
1160
|
+
throw new Error(`hooks.json already has a group named "${GROUP}" that is not Avron's`);
|
|
1161
|
+
}
|
|
1162
|
+
file[GROUP] = Object.fromEntries(
|
|
1163
|
+
Object.entries(HOOK_EVENTS2).map(([event, arg]) => [
|
|
1164
|
+
event,
|
|
1165
|
+
[{ type: "command", command: hookCommand2(binDir, arg), timeout: TIMEOUT_SEC }]
|
|
1166
|
+
])
|
|
1167
|
+
);
|
|
1168
|
+
return { text: stringifyStyled(file, detectStyle2(text)), changed: true };
|
|
1169
|
+
}
|
|
1170
|
+
function removeHooks(text) {
|
|
1171
|
+
const file = parseObject(text, "hooks.json");
|
|
1172
|
+
if (!groupIsOurs(file[GROUP])) return { text, changed: false };
|
|
1173
|
+
delete file[GROUP];
|
|
1174
|
+
return { text: stringifyStyled(file, detectStyle2(text)), changed: true };
|
|
1175
|
+
}
|
|
1176
|
+
function injectStatusLine(text, binDir) {
|
|
1177
|
+
const file = parseObject(text, "settings.json");
|
|
1178
|
+
const current = file.statusLine;
|
|
1179
|
+
if (isObject3(current) && isOurCommand2(current.command))
|
|
1180
|
+
return { text, changed: false, extra: { hadStatusLine: false } };
|
|
1181
|
+
const command = statuslineCommand2(binDir);
|
|
1182
|
+
const had = current !== void 0;
|
|
1183
|
+
file.statusLine = isObject3(current) ? { ...current, type: "command", command } : { type: "command", command, stack_with_default: true };
|
|
1184
|
+
return {
|
|
1185
|
+
text: stringifyStyled(file, detectStyle2(text)),
|
|
1186
|
+
changed: true,
|
|
1187
|
+
extra: { hadStatusLine: had, ...had ? { originalStatusLine: current } : {} }
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
function removeStatusLine(text, extra) {
|
|
1191
|
+
const file = parseObject(text, "settings.json");
|
|
1192
|
+
const current = file.statusLine;
|
|
1193
|
+
if (!isObject3(current) || !isOurCommand2(current.command)) return { text, changed: false };
|
|
1194
|
+
if (extra.hadStatusLine) file.statusLine = extra.originalStatusLine;
|
|
1195
|
+
else file.statusLine = void 0;
|
|
1196
|
+
return { text: stringifyStyled(file, detectStyle2(text)), changed: true };
|
|
1197
|
+
}
|
|
1198
|
+
function guard2(target, env) {
|
|
1199
|
+
assertSafeTarget(target, env);
|
|
1200
|
+
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1201
|
+
const real = (0, import_node_path9.resolve)((0, import_node_path9.join)((0, import_node_os4.homedir)(), ".gemini")).toLowerCase();
|
|
1202
|
+
if ((0, import_node_path9.resolve)(target).toLowerCase().startsWith(real))
|
|
1203
|
+
throw new Error("refusing to modify the real ~/.gemini directory from a test");
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
function readInstallState2(env = process.env) {
|
|
1207
|
+
const p = antigravityPaths(env);
|
|
1208
|
+
return readEditState(p.hooksState) ?? readEditState(p.settingsState);
|
|
1209
|
+
}
|
|
1210
|
+
function installAntigravity(env = process.env) {
|
|
1211
|
+
const p = antigravityPaths(env);
|
|
1212
|
+
try {
|
|
1213
|
+
guard2(p.hooksFile, env);
|
|
1214
|
+
guard2(p.settingsFile, env);
|
|
1215
|
+
injectHooks(readOr(p.hooksFile), p.binDir);
|
|
1216
|
+
injectStatusLine(readOr(p.settingsFile), p.binDir);
|
|
1217
|
+
const createdDir = !(0, import_node_fs7.existsSync)((0, import_node_path9.dirname)(p.hooksFile));
|
|
1218
|
+
const hooks = applyEdit({ target: p.hooksFile, statePath: p.hooksState }, (text) => ({
|
|
1219
|
+
...injectHooks(text, p.binDir),
|
|
1220
|
+
extra: { createdDir }
|
|
1221
|
+
}));
|
|
1222
|
+
const settings = applyEdit(
|
|
1223
|
+
{ target: p.settingsFile, statePath: p.settingsState },
|
|
1224
|
+
(text) => injectStatusLine(text, p.binDir)
|
|
1225
|
+
);
|
|
1226
|
+
const status = hooks.status === "installed" || settings.status === "installed" ? "installed" : "already-installed";
|
|
1227
|
+
return { status, hooksBackup: hooks.backupPath, settingsBackup: settings.backupPath };
|
|
1228
|
+
} catch (err) {
|
|
1229
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
function uninstallAntigravity(env = process.env) {
|
|
1233
|
+
const p = antigravityPaths(env);
|
|
1234
|
+
try {
|
|
1235
|
+
guard2(p.hooksFile, env);
|
|
1236
|
+
guard2(p.settingsFile, env);
|
|
1237
|
+
const settings = revertEdit(
|
|
1238
|
+
{ target: p.settingsFile, statePath: p.settingsState },
|
|
1239
|
+
(text, state) => removeStatusLine(text, state),
|
|
1240
|
+
(target) => guard2(target, env)
|
|
1241
|
+
);
|
|
1242
|
+
const createdDir = readEditState(p.hooksState)?.createdDir === true;
|
|
1243
|
+
const hooks = revertEdit(
|
|
1244
|
+
{ target: p.hooksFile, statePath: p.hooksState },
|
|
1245
|
+
(text) => removeHooks(text),
|
|
1246
|
+
(target) => guard2(target, env)
|
|
1247
|
+
);
|
|
1248
|
+
if (createdDir) rmEmptyDir((0, import_node_path9.dirname)(hooks.target));
|
|
1249
|
+
const all = [hooks.status, settings.status];
|
|
1250
|
+
const status = all.every((s) => s === "not-installed") ? "not-installed" : all.includes("restored-merged") ? "restored-merged" : "restored-exact";
|
|
1251
|
+
return { status, files: [hooks.target, settings.target] };
|
|
1252
|
+
} catch (err) {
|
|
1253
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
function readOr(file) {
|
|
1257
|
+
try {
|
|
1258
|
+
return (0, import_node_fs7.readFileSync)(file, "utf8");
|
|
1259
|
+
} catch {
|
|
1260
|
+
return "";
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
function rmEmptyDir(dir) {
|
|
1264
|
+
try {
|
|
1265
|
+
if ((0, import_node_fs7.readdirSync)(dir).length === 0) (0, import_node_fs7.rmdirSync)(dir);
|
|
1266
|
+
} catch {
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// packages/adapter-codex/src/install.ts
|
|
1271
|
+
var import_node_os5 = require("node:os");
|
|
1272
|
+
var import_node_path10 = require("node:path");
|
|
1273
|
+
var HOOK_SCRIPT3 = "avron-codex-hook.cjs";
|
|
1274
|
+
var HOOK_EVENTS3 = {
|
|
1275
|
+
UserPromptSubmit: "busy",
|
|
1276
|
+
Stop: "idle",
|
|
1277
|
+
Interrupt: "abort",
|
|
1278
|
+
SessionEnd: "end",
|
|
1279
|
+
// The start poster (formats.poster). Codex runs it with the session's first prompt and shows its
|
|
1280
|
+
// JSON systemMessage as a 'Hook' note, not to the model (measured 2026-11-21, Codex 0.169).
|
|
1281
|
+
SessionStart: "start"
|
|
1282
|
+
};
|
|
1283
|
+
var TIMEOUT_SEC2 = 3;
|
|
1284
|
+
function codexDir(env = process.env) {
|
|
1285
|
+
return env.AVRON_CODEX_DIR || env.CODEX_HOME || (0, import_node_path10.join)((0, import_node_os5.homedir)(), ".codex");
|
|
1286
|
+
}
|
|
1287
|
+
function codexPaths(env = process.env) {
|
|
1288
|
+
const dir = codexDir(env);
|
|
1289
|
+
const home = avronHome(env);
|
|
1290
|
+
return {
|
|
1291
|
+
codexDir: dir,
|
|
1292
|
+
hooksFile: (0, import_node_path10.join)(dir, "hooks.json"),
|
|
1293
|
+
statePath: (0, import_node_path10.join)(home, "adapters", "codex.json"),
|
|
1294
|
+
binDir: (0, import_node_path10.join)(home, "bin")
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
var isOurCommand3 = (command) => typeof command === "string" && command.includes(HOOK_SCRIPT3);
|
|
1298
|
+
function hookCommand3(binDir, arg) {
|
|
1299
|
+
return `node "${(0, import_node_path10.join)(binDir, HOOK_SCRIPT3).replace(/\\/g, "/")}" ${arg}`;
|
|
1300
|
+
}
|
|
1301
|
+
function groupIsOurs2(group) {
|
|
1302
|
+
if (!isObject3(group) || !Array.isArray(group.hooks) || group.hooks.length === 0) return false;
|
|
1303
|
+
return group.hooks.every((h) => isObject3(h) && isOurCommand3(h.command));
|
|
1304
|
+
}
|
|
1305
|
+
function inject2(text, binDir) {
|
|
1306
|
+
const file = parseObject(text, "hooks.json");
|
|
1307
|
+
if (file.hooks !== void 0 && !isObject3(file.hooks)) throw new Error("hooks.json has no hooks object");
|
|
1308
|
+
const hooks = file.hooks ?? {};
|
|
1309
|
+
let changed = false;
|
|
1310
|
+
for (const [event, arg] of Object.entries(HOOK_EVENTS3)) {
|
|
1311
|
+
const list = hooks[event];
|
|
1312
|
+
if (list !== void 0 && !Array.isArray(list)) throw new Error(`hooks.json: ${event} is not a list`);
|
|
1313
|
+
const groups = list ?? [];
|
|
1314
|
+
if (groups.some(groupIsOurs2)) continue;
|
|
1315
|
+
hooks[event] = [
|
|
1316
|
+
...groups,
|
|
1317
|
+
{ hooks: [{ type: "command", command: hookCommand3(binDir, arg), timeout: TIMEOUT_SEC2 }] }
|
|
1318
|
+
];
|
|
1319
|
+
changed = true;
|
|
1320
|
+
}
|
|
1321
|
+
file.hooks = hooks;
|
|
1322
|
+
return { text: changed ? stringifyStyled(file, detectStyle2(text)) : text, changed };
|
|
1323
|
+
}
|
|
1324
|
+
function remove2(text) {
|
|
1325
|
+
const file = parseObject(text, "hooks.json");
|
|
1326
|
+
if (!isObject3(file.hooks)) return { text, changed: false };
|
|
1327
|
+
const hooks = file.hooks;
|
|
1328
|
+
let changed = false;
|
|
1329
|
+
for (const event of Object.keys(hooks)) {
|
|
1330
|
+
const list = hooks[event];
|
|
1331
|
+
if (!Array.isArray(list)) continue;
|
|
1332
|
+
const kept = list.filter((g) => !groupIsOurs2(g));
|
|
1333
|
+
if (kept.length === list.length) continue;
|
|
1334
|
+
changed = true;
|
|
1335
|
+
if (kept.length > 0) hooks[event] = kept;
|
|
1336
|
+
else delete hooks[event];
|
|
1337
|
+
}
|
|
1338
|
+
return { text: changed ? stringifyStyled(file, detectStyle2(text)) : text, changed };
|
|
1339
|
+
}
|
|
1340
|
+
function guard3(target, env) {
|
|
1341
|
+
assertSafeTarget(target, env);
|
|
1342
|
+
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1343
|
+
const real = (0, import_node_path10.resolve)((0, import_node_path10.join)((0, import_node_os5.homedir)(), ".codex")).toLowerCase();
|
|
1344
|
+
if ((0, import_node_path10.resolve)(target).toLowerCase().startsWith(real))
|
|
1345
|
+
throw new Error("refusing to modify the real ~/.codex directory from a test");
|
|
1346
|
+
}
|
|
1347
|
+
}
|
|
1348
|
+
function readInstallState3(env = process.env) {
|
|
1349
|
+
return readEditState(codexPaths(env).statePath);
|
|
1350
|
+
}
|
|
1351
|
+
function installCodex(env = process.env) {
|
|
1352
|
+
const p = codexPaths(env);
|
|
1353
|
+
try {
|
|
1354
|
+
guard3(p.hooksFile, env);
|
|
1355
|
+
const res = applyEdit({ target: p.hooksFile, statePath: p.statePath }, (text) => ({
|
|
1356
|
+
...inject2(text, p.binDir),
|
|
1357
|
+
extra: {}
|
|
1358
|
+
}));
|
|
1359
|
+
return { status: res.status, hooksFile: p.hooksFile, backupPath: res.backupPath };
|
|
1360
|
+
} catch (err) {
|
|
1361
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
function uninstallCodex(env = process.env) {
|
|
1365
|
+
const p = codexPaths(env);
|
|
1366
|
+
try {
|
|
1367
|
+
guard3(p.hooksFile, env);
|
|
1368
|
+
const res = revertEdit(
|
|
1369
|
+
{ target: p.hooksFile, statePath: p.statePath },
|
|
1370
|
+
(text) => remove2(text),
|
|
1371
|
+
(target) => guard3(target, env)
|
|
1372
|
+
);
|
|
1373
|
+
return { status: res.status, hooksFile: res.target };
|
|
1374
|
+
} catch (err) {
|
|
1375
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// packages/adapter-copilot/src/install.ts
|
|
1380
|
+
var import_node_fs8 = require("node:fs");
|
|
1381
|
+
var import_node_os6 = require("node:os");
|
|
1382
|
+
var import_node_path11 = require("node:path");
|
|
1383
|
+
var HOOK_SCRIPT4 = "avron-copilot-hook.cjs";
|
|
1384
|
+
var HOOKS_FILE = "avron.json";
|
|
1385
|
+
var HOOK_EVENTS4 = {
|
|
1386
|
+
userPromptSubmitted: "busy",
|
|
1387
|
+
agentStop: "idle",
|
|
1388
|
+
sessionEnd: "end"
|
|
1389
|
+
};
|
|
1390
|
+
var TIMEOUT_SEC3 = 5;
|
|
1391
|
+
function copilotDir(env = process.env) {
|
|
1392
|
+
return env.AVRON_COPILOT_DIR || env.COPILOT_HOME || (0, import_node_path11.join)((0, import_node_os6.homedir)(), ".copilot");
|
|
1393
|
+
}
|
|
1394
|
+
function copilotPaths(env = process.env) {
|
|
1395
|
+
const dir = copilotDir(env);
|
|
1396
|
+
const home = avronHome(env);
|
|
1397
|
+
return {
|
|
1398
|
+
copilotDir: dir,
|
|
1399
|
+
hooksDir: (0, import_node_path11.join)(dir, "hooks"),
|
|
1400
|
+
hooksFile: (0, import_node_path11.join)(dir, "hooks", HOOKS_FILE),
|
|
1401
|
+
statePath: (0, import_node_path11.join)(home, "adapters", "copilot.json"),
|
|
1402
|
+
settingsFile: (0, import_node_path11.join)(dir, "settings.json"),
|
|
1403
|
+
settingsState: (0, import_node_path11.join)(home, "adapters", "copilot-cli.json"),
|
|
1404
|
+
binDir: (0, import_node_path11.join)(home, "bin")
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
var STATUSLINE_SCRIPT3 = "avron-copilot-statusline.cjs";
|
|
1408
|
+
var REFRESH_SEC = 1;
|
|
1409
|
+
var isOurCommand4 = (command) => typeof command === "string" && (command.includes(HOOK_SCRIPT4) || command.includes(STATUSLINE_SCRIPT3));
|
|
1410
|
+
var statuslineCommand3 = (binDir) => `node "${(0, import_node_path11.join)(binDir, STATUSLINE_SCRIPT3).replace(/\\/g, "/")}"`;
|
|
1411
|
+
function injectStatusLine2(text, binDir) {
|
|
1412
|
+
const file = parseObject(text, "settings.json");
|
|
1413
|
+
const current = file.statusLine;
|
|
1414
|
+
if (isObject3(current) && isOurCommand4(current.command))
|
|
1415
|
+
return { text, changed: false, extra: { hadStatusLine: false } };
|
|
1416
|
+
const had = current !== void 0;
|
|
1417
|
+
file.statusLine = {
|
|
1418
|
+
...isObject3(current) ? current : {},
|
|
1419
|
+
type: "command",
|
|
1420
|
+
command: statuslineCommand3(binDir),
|
|
1421
|
+
refreshInterval: REFRESH_SEC
|
|
1422
|
+
};
|
|
1423
|
+
return {
|
|
1424
|
+
text: stringifyStyled(file, detectStyle2(text)),
|
|
1425
|
+
changed: true,
|
|
1426
|
+
extra: { hadStatusLine: had, ...had ? { originalStatusLine: current } : {} }
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
function removeStatusLine2(text, extra) {
|
|
1430
|
+
const file = parseObject(text, "settings.json");
|
|
1431
|
+
const current = file.statusLine;
|
|
1432
|
+
if (!isObject3(current) || !isOurCommand4(current.command)) return { text, changed: false };
|
|
1433
|
+
file.statusLine = extra.hadStatusLine ? extra.originalStatusLine : void 0;
|
|
1434
|
+
return { text: stringifyStyled(file, detectStyle2(text)), changed: true };
|
|
1435
|
+
}
|
|
1436
|
+
function hooksFileText(binDir) {
|
|
1437
|
+
const script = (0, import_node_path11.join)(binDir, HOOK_SCRIPT4).replace(/\\/g, "/");
|
|
1438
|
+
const hooks = {};
|
|
1439
|
+
for (const [event, arg] of Object.entries(HOOK_EVENTS4)) {
|
|
1440
|
+
const command = `node "${script}" ${arg}`;
|
|
1441
|
+
hooks[event] = [{ type: "command", bash: command, powershell: command, timeoutSec: TIMEOUT_SEC3 }];
|
|
1442
|
+
}
|
|
1443
|
+
return `${JSON.stringify({ version: 1, hooks }, null, 2)}
|
|
1444
|
+
`;
|
|
1445
|
+
}
|
|
1446
|
+
function guard4(target, env) {
|
|
1447
|
+
assertSafeTarget(target, env);
|
|
1448
|
+
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1449
|
+
const real = (0, import_node_path11.resolve)((0, import_node_path11.join)((0, import_node_os6.homedir)(), ".copilot")).toLowerCase();
|
|
1450
|
+
if ((0, import_node_path11.resolve)(target).toLowerCase().startsWith(real))
|
|
1451
|
+
throw new Error("refusing to modify the real ~/.copilot directory from a test");
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
function readInstallState4(env = process.env) {
|
|
1455
|
+
return readEditState(copilotPaths(env).statePath);
|
|
1456
|
+
}
|
|
1457
|
+
function readOr2(file) {
|
|
1458
|
+
try {
|
|
1459
|
+
return (0, import_node_fs8.readFileSync)(file, "utf8");
|
|
1460
|
+
} catch {
|
|
1461
|
+
return "";
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
function installCopilot(env = process.env) {
|
|
1465
|
+
const p = copilotPaths(env);
|
|
1466
|
+
try {
|
|
1467
|
+
guard4(p.hooksFile, env);
|
|
1468
|
+
guard4(p.settingsFile, env);
|
|
1469
|
+
injectStatusLine2(readOr2(p.settingsFile), p.binDir);
|
|
1470
|
+
const createdDirs = [p.hooksDir, p.copilotDir].filter((d) => !(0, import_node_fs8.existsSync)(d));
|
|
1471
|
+
const wanted = hooksFileText(p.binDir);
|
|
1472
|
+
const res = applyEdit({ target: p.hooksFile, statePath: p.statePath }, (text) => ({
|
|
1473
|
+
changed: text !== wanted,
|
|
1474
|
+
text: wanted,
|
|
1475
|
+
extra: { createdDirs }
|
|
1476
|
+
}));
|
|
1477
|
+
const settings = applyEdit(
|
|
1478
|
+
{ target: p.settingsFile, statePath: p.settingsState },
|
|
1479
|
+
(text) => injectStatusLine2(text, p.binDir)
|
|
1480
|
+
);
|
|
1481
|
+
const status = res.status === "installed" || settings.status === "installed" ? "installed" : "already-installed";
|
|
1482
|
+
return { status, hooksFile: p.hooksFile, settingsFile: p.settingsFile };
|
|
1483
|
+
} catch (err) {
|
|
1484
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
function uninstallCopilot(env = process.env) {
|
|
1488
|
+
const p = copilotPaths(env);
|
|
1489
|
+
try {
|
|
1490
|
+
guard4(p.hooksFile, env);
|
|
1491
|
+
guard4(p.settingsFile, env);
|
|
1492
|
+
const settings = revertEdit(
|
|
1493
|
+
{ target: p.settingsFile, statePath: p.settingsState },
|
|
1494
|
+
(text, st) => removeStatusLine2(text, st),
|
|
1495
|
+
(target) => guard4(target, env)
|
|
1496
|
+
);
|
|
1497
|
+
const state = readInstallState4(env);
|
|
1498
|
+
const res = revertEdit(
|
|
1499
|
+
{ target: p.hooksFile, statePath: p.statePath },
|
|
1500
|
+
() => ({ changed: false, text: "" }),
|
|
1501
|
+
(target) => guard4(target, env)
|
|
1502
|
+
);
|
|
1503
|
+
if (res.status === "restored-merged" && (0, import_node_fs8.existsSync)(res.target) && state && !state.existed)
|
|
1504
|
+
removeIfOurs(res.target);
|
|
1505
|
+
for (const dir of state?.createdDirs ?? []) removeIfEmpty(dir);
|
|
1506
|
+
const all = [res.status, settings.status];
|
|
1507
|
+
const status = all.every((x) => x === "not-installed") ? "not-installed" : all.includes("restored-merged") ? "restored-merged" : "restored-exact";
|
|
1508
|
+
return { status, hooksFile: res.target };
|
|
1509
|
+
} catch (err) {
|
|
1510
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function removeIfOurs(file) {
|
|
1514
|
+
try {
|
|
1515
|
+
if (isOurCommand4((0, import_node_fs8.readFileSync)(file, "utf8"))) (0, import_node_fs8.rmSync)(file);
|
|
1516
|
+
} catch {
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
function removeIfEmpty(dir) {
|
|
1520
|
+
try {
|
|
1521
|
+
if ((0, import_node_fs8.existsSync)(dir) && (0, import_node_fs8.readdirSync)(dir).length === 0) (0, import_node_fs8.rmdirSync)(dir);
|
|
1522
|
+
} catch {
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
// packages/adapter-cursor/src/install.ts
|
|
1527
|
+
var import_node_fs9 = require("node:fs");
|
|
1528
|
+
var import_node_os7 = require("node:os");
|
|
1529
|
+
var import_node_path12 = require("node:path");
|
|
1530
|
+
var HOOK_SCRIPT5 = "avron-cursor-hook.cjs";
|
|
1531
|
+
var HOOK_EVENTS5 = {
|
|
1532
|
+
beforeSubmitPrompt: "busy",
|
|
1533
|
+
stop: "idle",
|
|
1534
|
+
sessionEnd: "end"
|
|
1535
|
+
};
|
|
1536
|
+
var TIMEOUT_SEC4 = 5;
|
|
1537
|
+
function cursorDir(env = process.env) {
|
|
1538
|
+
return env.AVRON_CURSOR_DIR || (0, import_node_path12.join)((0, import_node_os7.homedir)(), ".cursor");
|
|
1539
|
+
}
|
|
1540
|
+
function cursorPaths(env = process.env) {
|
|
1541
|
+
const dir = cursorDir(env);
|
|
1542
|
+
const home = avronHome(env);
|
|
1543
|
+
return {
|
|
1544
|
+
cursorDir: dir,
|
|
1545
|
+
hooksFile: (0, import_node_path12.join)(dir, "hooks.json"),
|
|
1546
|
+
statePath: (0, import_node_path12.join)(home, "adapters", "cursor.json"),
|
|
1547
|
+
binDir: (0, import_node_path12.join)(home, "bin")
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1550
|
+
var isOurCommand5 = (command) => typeof command === "string" && command.includes(HOOK_SCRIPT5);
|
|
1551
|
+
function hookCommand4(binDir, arg) {
|
|
1552
|
+
return `node "${(0, import_node_path12.join)(binDir, HOOK_SCRIPT5).replace(/\\/g, "/")}" ${arg}`;
|
|
1553
|
+
}
|
|
1554
|
+
function inject3(text, binDir) {
|
|
1555
|
+
const file = parseObject(text, "hooks.json");
|
|
1556
|
+
const style2 = detectStyle2(text);
|
|
1557
|
+
if (file.version === void 0) file.version = 1;
|
|
1558
|
+
if (file.hooks !== void 0 && !isObject3(file.hooks)) throw new Error("hooks.json has no hooks object");
|
|
1559
|
+
const hooks = file.hooks ?? {};
|
|
1560
|
+
let changed = false;
|
|
1561
|
+
for (const [event, arg] of Object.entries(HOOK_EVENTS5)) {
|
|
1562
|
+
const list = hooks[event];
|
|
1563
|
+
if (list !== void 0 && !Array.isArray(list)) throw new Error(`hooks.json: ${event} is not a list`);
|
|
1564
|
+
const entries = list ?? [];
|
|
1565
|
+
if (entries.some((e) => isObject3(e) && isOurCommand5(e.command))) continue;
|
|
1566
|
+
hooks[event] = [...entries, { command: hookCommand4(binDir, arg), timeout: TIMEOUT_SEC4 }];
|
|
1567
|
+
changed = true;
|
|
1568
|
+
}
|
|
1569
|
+
file.hooks = hooks;
|
|
1570
|
+
return { text: changed ? stringifyStyled(file, style2) : text, changed };
|
|
1571
|
+
}
|
|
1572
|
+
function remove3(text) {
|
|
1573
|
+
const file = parseObject(text, "hooks.json");
|
|
1574
|
+
if (!isObject3(file.hooks)) return { text, changed: false };
|
|
1575
|
+
const hooks = file.hooks;
|
|
1576
|
+
let changed = false;
|
|
1577
|
+
for (const event of Object.keys(hooks)) {
|
|
1578
|
+
const list = hooks[event];
|
|
1579
|
+
if (!Array.isArray(list)) continue;
|
|
1580
|
+
const kept = list.filter((e) => !(isObject3(e) && isOurCommand5(e.command)));
|
|
1581
|
+
if (kept.length === list.length) continue;
|
|
1582
|
+
changed = true;
|
|
1583
|
+
if (kept.length > 0) hooks[event] = kept;
|
|
1584
|
+
else delete hooks[event];
|
|
1585
|
+
}
|
|
1586
|
+
return { text: changed ? stringifyStyled(file, detectStyle2(text)) : text, changed };
|
|
1587
|
+
}
|
|
1588
|
+
function guard5(target, env) {
|
|
1589
|
+
assertSafeTarget(target, env);
|
|
1590
|
+
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1591
|
+
const real = (0, import_node_path12.resolve)((0, import_node_path12.join)((0, import_node_os7.homedir)(), ".cursor")).toLowerCase();
|
|
1592
|
+
if ((0, import_node_path12.resolve)(target).toLowerCase().startsWith(real))
|
|
1593
|
+
throw new Error("refusing to modify the real ~/.cursor directory from a test");
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
function readInstallState5(env = process.env) {
|
|
1597
|
+
return readEditState(cursorPaths(env).statePath);
|
|
1598
|
+
}
|
|
1599
|
+
function installCursor(env = process.env) {
|
|
1600
|
+
const p = cursorPaths(env);
|
|
1601
|
+
try {
|
|
1602
|
+
guard5(p.hooksFile, env);
|
|
1603
|
+
const createdDirs = [p.cursorDir].filter((d) => !(0, import_node_fs9.existsSync)(d));
|
|
1604
|
+
const res = applyEdit({ target: p.hooksFile, statePath: p.statePath }, (text) => ({
|
|
1605
|
+
...inject3(text, p.binDir),
|
|
1606
|
+
extra: { createdDirs }
|
|
1607
|
+
}));
|
|
1608
|
+
return { status: res.status, hooksFile: p.hooksFile, backupPath: res.backupPath };
|
|
1609
|
+
} catch (err) {
|
|
1610
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
function uninstallCursor(env = process.env) {
|
|
1614
|
+
const p = cursorPaths(env);
|
|
1615
|
+
try {
|
|
1616
|
+
guard5(p.hooksFile, env);
|
|
1617
|
+
const state = readInstallState5(env);
|
|
1618
|
+
const res = revertEdit(
|
|
1619
|
+
{ target: p.hooksFile, statePath: p.statePath },
|
|
1620
|
+
(text) => remove3(text),
|
|
1621
|
+
(target) => guard5(target, env)
|
|
1622
|
+
);
|
|
1623
|
+
for (const dir of state?.createdDirs ?? []) {
|
|
1624
|
+
try {
|
|
1625
|
+
if ((0, import_node_fs9.existsSync)(dir) && (0, import_node_fs9.readdirSync)(dir).length === 0) (0, import_node_fs9.rmdirSync)(dir);
|
|
1626
|
+
} catch {
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
return { status: res.status, hooksFile: res.target };
|
|
1630
|
+
} catch (err) {
|
|
1631
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
// packages/adapter-opencode/src/install.ts
|
|
1636
|
+
var import_node_fs10 = require("node:fs");
|
|
1637
|
+
var import_node_os8 = require("node:os");
|
|
1638
|
+
var import_node_path13 = require("node:path");
|
|
1639
|
+
var import_node_url = require("node:url");
|
|
1640
|
+
var PLUGIN_FILE = "avron-opencode.tsx";
|
|
1641
|
+
function opencodeDir(env = process.env) {
|
|
1642
|
+
if (env.AVRON_OPENCODE_DIR) return env.AVRON_OPENCODE_DIR;
|
|
1643
|
+
return (0, import_node_path13.join)(env.XDG_CONFIG_HOME || (0, import_node_path13.join)((0, import_node_os8.homedir)(), ".config"), "opencode");
|
|
1644
|
+
}
|
|
1645
|
+
function opencodePaths(env = process.env) {
|
|
1646
|
+
const dir = opencodeDir(env);
|
|
1647
|
+
const home = avronHome(env);
|
|
1648
|
+
return {
|
|
1649
|
+
configDir: dir,
|
|
1650
|
+
tuiFile: (0, import_node_path13.join)(dir, "tui.json"),
|
|
1651
|
+
statePath: (0, import_node_path13.join)(home, "adapters", "opencode.json"),
|
|
1652
|
+
binDir: (0, import_node_path13.join)(home, "bin")
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
var pluginEntry = (binDir) => (0, import_node_url.pathToFileURL)((0, import_node_path13.join)(binDir, PLUGIN_FILE)).href;
|
|
1656
|
+
var isOurEntry = (entry) => typeof entry === "string" && entry.replace(/\\/g, "/").endsWith(`/${PLUGIN_FILE}`);
|
|
1657
|
+
function inject4(text, binDir) {
|
|
1658
|
+
const file = parseObject(text, "tui.json");
|
|
1659
|
+
const list = file.plugin;
|
|
1660
|
+
if (list !== void 0 && !Array.isArray(list)) throw new Error("tui.json: plugin is not a list");
|
|
1661
|
+
const plugins = list ?? [];
|
|
1662
|
+
if (plugins.some(isOurEntry)) return { text, changed: false };
|
|
1663
|
+
file.plugin = [...plugins, pluginEntry(binDir)];
|
|
1664
|
+
return { text: stringifyStyled(file, detectStyle2(text)), changed: true };
|
|
1665
|
+
}
|
|
1666
|
+
function remove4(text) {
|
|
1667
|
+
const file = parseObject(text, "tui.json");
|
|
1668
|
+
if (!Array.isArray(file.plugin) || !file.plugin.some(isOurEntry)) return { text, changed: false };
|
|
1669
|
+
const kept = file.plugin.filter((e) => !isOurEntry(e));
|
|
1670
|
+
file.plugin = kept.length > 0 ? kept : void 0;
|
|
1671
|
+
return { text: stringifyStyled(file, detectStyle2(text)), changed: true };
|
|
1672
|
+
}
|
|
1673
|
+
function guard6(target, env) {
|
|
1674
|
+
assertSafeTarget(target, env);
|
|
1675
|
+
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1676
|
+
const real = (0, import_node_path13.resolve)((0, import_node_path13.join)((0, import_node_os8.homedir)(), ".config", "opencode")).toLowerCase();
|
|
1677
|
+
if ((0, import_node_path13.resolve)(target).toLowerCase().startsWith(real))
|
|
1678
|
+
throw new Error("refusing to modify the real ~/.config/opencode directory from a test");
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
function readInstallState6(env = process.env) {
|
|
1682
|
+
return readEditState(opencodePaths(env).statePath);
|
|
1683
|
+
}
|
|
1684
|
+
function installOpencode(env = process.env) {
|
|
1685
|
+
const p = opencodePaths(env);
|
|
1686
|
+
try {
|
|
1687
|
+
guard6(p.tuiFile, env);
|
|
1688
|
+
const createdDir = !(0, import_node_fs10.existsSync)(p.configDir);
|
|
1689
|
+
const res = applyEdit({ target: p.tuiFile, statePath: p.statePath }, (text) => ({
|
|
1690
|
+
...inject4(text, p.binDir),
|
|
1691
|
+
extra: { createdDir }
|
|
1692
|
+
}));
|
|
1693
|
+
return { status: res.status, tuiFile: p.tuiFile, backupPath: res.backupPath };
|
|
1694
|
+
} catch (err) {
|
|
1695
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
function uninstallOpencode(env = process.env) {
|
|
1699
|
+
const p = opencodePaths(env);
|
|
1700
|
+
try {
|
|
1701
|
+
guard6(p.tuiFile, env);
|
|
1702
|
+
const createdDir = readEditState(p.statePath)?.createdDir === true;
|
|
1703
|
+
const res = revertEdit(
|
|
1704
|
+
{ target: p.tuiFile, statePath: p.statePath },
|
|
1705
|
+
(text) => remove4(text),
|
|
1706
|
+
(target) => guard6(target, env)
|
|
1707
|
+
);
|
|
1708
|
+
if (createdDir) rmEmptyDir2((0, import_node_path13.dirname)(res.target));
|
|
1709
|
+
return { status: res.status, tuiFile: res.target };
|
|
1710
|
+
} catch (err) {
|
|
1711
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
function rmEmptyDir2(dir) {
|
|
1715
|
+
try {
|
|
1716
|
+
if ((0, import_node_fs10.readdirSync)(dir).length === 0) (0, import_node_fs10.rmdirSync)(dir);
|
|
1717
|
+
} catch {
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
function pluginListed(env = process.env) {
|
|
1721
|
+
try {
|
|
1722
|
+
const file = JSON.parse((0, import_node_fs10.readFileSync)(opencodePaths(env).tuiFile, "utf8"));
|
|
1723
|
+
return Array.isArray(file.plugin) && file.plugin.some(isOurEntry);
|
|
1724
|
+
} catch {
|
|
1725
|
+
return false;
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// packages/cli/src/adapters.ts
|
|
1730
|
+
var short = (p) => p.replace(/\\/g, "/");
|
|
1731
|
+
var claudeCode = {
|
|
1732
|
+
id: "claude-code",
|
|
1733
|
+
name: "Claude Code",
|
|
1734
|
+
detect(env) {
|
|
1735
|
+
const cp = claudePaths(env);
|
|
1736
|
+
return (0, import_node_fs11.existsSync)(cp.claudeDir) ? cp.settingsPath : null;
|
|
1737
|
+
},
|
|
1738
|
+
install(env, out) {
|
|
1739
|
+
out("\u25B8 Backing up configuration:");
|
|
1740
|
+
const res = installClaudeCode(env);
|
|
1741
|
+
if (res.status === "error") {
|
|
1742
|
+
out(` [!!] Could not update settings.json: ${res.reason}`);
|
|
1743
|
+
out(" Nothing was changed in Claude Code.");
|
|
1744
|
+
return false;
|
|
1745
|
+
}
|
|
1746
|
+
out(
|
|
1747
|
+
res.backupPath ? ` [OK] Saved: ${short(res.backupPath)}` : " [OK] No settings.json existed; uninstall will remove the one created"
|
|
1748
|
+
);
|
|
1749
|
+
out("\u25B8 Injecting adapter:");
|
|
1750
|
+
out(
|
|
1751
|
+
res.status === "installed" ? " [OK] Claude Code adapter injected" : " [OK] Claude Code adapter already present"
|
|
1752
|
+
);
|
|
1753
|
+
return true;
|
|
1754
|
+
},
|
|
1755
|
+
uninstall(env, out) {
|
|
1756
|
+
out("\u25B8 Restoring Claude Code settings:");
|
|
1757
|
+
const res = uninstallClaudeCode(env);
|
|
1758
|
+
if (res.status === "error") {
|
|
1759
|
+
out(` [!!] Could not restore settings.json: ${res.reason}`);
|
|
1760
|
+
return false;
|
|
1761
|
+
}
|
|
1762
|
+
out(
|
|
1763
|
+
{
|
|
1764
|
+
"restored-exact": " [OK] settings.json restored byte for byte",
|
|
1765
|
+
"restored-merged": " [OK] Avron entries removed; edits made after install were kept",
|
|
1766
|
+
"not-installed": " [--] Nothing to restore"
|
|
1767
|
+
}[res.status]
|
|
1768
|
+
);
|
|
1769
|
+
return true;
|
|
1770
|
+
},
|
|
1771
|
+
doctor(env, check, out) {
|
|
1772
|
+
let wrapped = false;
|
|
1773
|
+
let hooks = 0;
|
|
1774
|
+
try {
|
|
1775
|
+
const s = parseSettings((0, import_node_fs11.readFileSync)(claudePaths(env).settingsPath, "utf8"));
|
|
1776
|
+
wrapped = isOurCommand(s.statusLine?.command);
|
|
1777
|
+
const h = s.hooks ?? {};
|
|
1778
|
+
for (const ev of Object.keys(HOOK_EVENTS)) {
|
|
1779
|
+
if ((h[ev] ?? []).some((e) => (e.hooks ?? []).some((x) => isOurCommand(x.command)))) hooks++;
|
|
1780
|
+
}
|
|
1781
|
+
} catch {
|
|
1782
|
+
}
|
|
1783
|
+
check(
|
|
1784
|
+
wrapped,
|
|
1785
|
+
"Claude Code status line is chained through Avron",
|
|
1786
|
+
"Claude Code status line is not set up (run 'npx @wbcode/avron install')"
|
|
1787
|
+
);
|
|
1788
|
+
check(
|
|
1789
|
+
hooks === Object.keys(HOOK_EVENTS).length,
|
|
1790
|
+
"Claude Code hooks are registered",
|
|
1791
|
+
"Claude Code hooks are missing"
|
|
1792
|
+
);
|
|
1793
|
+
if (readInstallState(env)?.hadStatusLine)
|
|
1794
|
+
out(" [OK] Your original status line is preserved and still runs");
|
|
1795
|
+
},
|
|
1796
|
+
installed: (env) => readInstallState(env) !== null
|
|
1797
|
+
};
|
|
1798
|
+
var copilot = {
|
|
1799
|
+
id: "copilot",
|
|
1800
|
+
name: "GitHub Copilot",
|
|
1801
|
+
detect(env) {
|
|
1802
|
+
const p = copilotPaths(env);
|
|
1803
|
+
return (0, import_node_fs11.existsSync)(p.copilotDir) ? p.hooksFile : null;
|
|
1804
|
+
},
|
|
1805
|
+
install(env, out) {
|
|
1806
|
+
out("\u25B8 Adding the Copilot hooks and the Copilot CLI status line:");
|
|
1807
|
+
const res = installCopilot(env);
|
|
1808
|
+
if (res.status === "error") {
|
|
1809
|
+
out(` [!!] Could not set up Copilot: ${res.reason}`);
|
|
1810
|
+
out(" Nothing was changed in Copilot.");
|
|
1811
|
+
return false;
|
|
1812
|
+
}
|
|
1813
|
+
out(
|
|
1814
|
+
res.status === "installed" ? ` [OK] Added ${short(res.hooksFile)} and the status line in ${short(res.settingsFile)} (backup kept)` : " [OK] Copilot hooks and status line already present"
|
|
1815
|
+
);
|
|
1816
|
+
out(" [--] VS Code chat shows the line with the Avron extension; Copilot CLI under its input");
|
|
1817
|
+
return true;
|
|
1818
|
+
},
|
|
1819
|
+
uninstall(env, out) {
|
|
1820
|
+
out("\u25B8 Removing the Copilot hooks and status line:");
|
|
1821
|
+
const res = uninstallCopilot(env);
|
|
1822
|
+
if (res.status === "error") {
|
|
1823
|
+
out(` [!!] Could not remove the Copilot hook file: ${res.reason}`);
|
|
1824
|
+
return false;
|
|
1825
|
+
}
|
|
1826
|
+
out(res.status === "not-installed" ? " [--] Nothing to remove" : " [OK] Copilot restored");
|
|
1827
|
+
return true;
|
|
1828
|
+
},
|
|
1829
|
+
doctor(env, check) {
|
|
1830
|
+
let hooks = 0;
|
|
1831
|
+
try {
|
|
1832
|
+
const f = JSON.parse((0, import_node_fs11.readFileSync)(copilotPaths(env).hooksFile, "utf8"));
|
|
1833
|
+
for (const ev of Object.keys(HOOK_EVENTS4))
|
|
1834
|
+
if ((f.hooks?.[ev] ?? []).some((h) => isOurCommand4(h.powershell) && isOurCommand4(h.bash)))
|
|
1835
|
+
hooks++;
|
|
1836
|
+
} catch {
|
|
1837
|
+
}
|
|
1838
|
+
check(
|
|
1839
|
+
hooks === Object.keys(HOOK_EVENTS4).length,
|
|
1840
|
+
"Copilot hooks are registered",
|
|
1841
|
+
"Copilot hooks are missing (run 'npx @wbcode/avron install')"
|
|
1842
|
+
);
|
|
1843
|
+
let line = false;
|
|
1844
|
+
try {
|
|
1845
|
+
const s = JSON.parse((0, import_node_fs11.readFileSync)(copilotPaths(env).settingsFile, "utf8"));
|
|
1846
|
+
line = isOurCommand4(s.statusLine?.command);
|
|
1847
|
+
} catch {
|
|
1848
|
+
}
|
|
1849
|
+
check(
|
|
1850
|
+
line,
|
|
1851
|
+
"Copilot CLI status line is set",
|
|
1852
|
+
"Copilot CLI status line is missing (run 'npx @wbcode/avron install')"
|
|
1853
|
+
);
|
|
1854
|
+
},
|
|
1855
|
+
installed: (env) => readInstallState4(env) !== null
|
|
1856
|
+
};
|
|
1857
|
+
var cursor = {
|
|
1858
|
+
id: "cursor",
|
|
1859
|
+
name: "Cursor",
|
|
1860
|
+
detect(env) {
|
|
1861
|
+
const p = cursorPaths(env);
|
|
1862
|
+
return (0, import_node_fs11.existsSync)(p.cursorDir) ? p.hooksFile : null;
|
|
1863
|
+
},
|
|
1864
|
+
install(env, out) {
|
|
1865
|
+
out("\u25B8 Adding Cursor hooks:");
|
|
1866
|
+
const res = installCursor(env);
|
|
1867
|
+
if (res.status === "error") {
|
|
1868
|
+
out(` [!!] Could not update hooks.json: ${res.reason}`);
|
|
1869
|
+
out(" Nothing was changed in Cursor.");
|
|
1870
|
+
return false;
|
|
1871
|
+
}
|
|
1872
|
+
out(
|
|
1873
|
+
res.backupPath ? ` [OK] Saved: ${short(res.backupPath)}` : " [OK] No hooks.json existed; uninstall will remove the one created"
|
|
1874
|
+
);
|
|
1875
|
+
out(res.status === "installed" ? " [OK] Cursor hooks added" : " [OK] Cursor hooks already present");
|
|
1876
|
+
out(" [--] The line shows in Cursor with the Avron extension");
|
|
1877
|
+
return true;
|
|
1878
|
+
},
|
|
1879
|
+
uninstall(env, out) {
|
|
1880
|
+
out("\u25B8 Restoring Cursor hooks.json:");
|
|
1881
|
+
const res = uninstallCursor(env);
|
|
1882
|
+
if (res.status === "error") {
|
|
1883
|
+
out(` [!!] Could not restore hooks.json: ${res.reason}`);
|
|
1884
|
+
return false;
|
|
1885
|
+
}
|
|
1886
|
+
out(
|
|
1887
|
+
{
|
|
1888
|
+
"restored-exact": " [OK] hooks.json restored byte for byte",
|
|
1889
|
+
"restored-merged": " [OK] Avron entries removed; edits made after install were kept",
|
|
1890
|
+
"not-installed": " [--] Nothing to restore"
|
|
1891
|
+
}[res.status]
|
|
1892
|
+
);
|
|
1893
|
+
return true;
|
|
1894
|
+
},
|
|
1895
|
+
doctor(env, check) {
|
|
1896
|
+
let hooks = 0;
|
|
1897
|
+
try {
|
|
1898
|
+
const f = JSON.parse((0, import_node_fs11.readFileSync)(cursorPaths(env).hooksFile, "utf8"));
|
|
1899
|
+
for (const ev of Object.keys(HOOK_EVENTS5))
|
|
1900
|
+
if ((f.hooks?.[ev] ?? []).some((h) => isOurCommand5(h.command))) hooks++;
|
|
1901
|
+
} catch {
|
|
1902
|
+
}
|
|
1903
|
+
check(
|
|
1904
|
+
hooks === Object.keys(HOOK_EVENTS5).length,
|
|
1905
|
+
"Cursor hooks are registered",
|
|
1906
|
+
"Cursor hooks are missing (run 'npx @wbcode/avron install')"
|
|
1907
|
+
);
|
|
1908
|
+
},
|
|
1909
|
+
installed: (env) => readInstallState5(env) !== null
|
|
1910
|
+
};
|
|
1911
|
+
var codex = {
|
|
1912
|
+
id: "codex",
|
|
1913
|
+
name: "Codex CLI",
|
|
1914
|
+
detect(env) {
|
|
1915
|
+
const p = codexPaths(env);
|
|
1916
|
+
return (0, import_node_fs11.existsSync)(p.codexDir) ? p.hooksFile : null;
|
|
1917
|
+
},
|
|
1918
|
+
install(env, out) {
|
|
1919
|
+
out("\u25B8 Adding Codex hooks:");
|
|
1920
|
+
const res = installCodex(env);
|
|
1921
|
+
if (res.status === "error") {
|
|
1922
|
+
out(` [!!] Could not update hooks.json: ${res.reason}`);
|
|
1923
|
+
out(" Nothing was changed in Codex.");
|
|
1924
|
+
return false;
|
|
1925
|
+
}
|
|
1926
|
+
out(
|
|
1927
|
+
res.backupPath ? ` [OK] Saved: ${short(res.backupPath)}` : " [OK] No hooks.json existed; uninstall will remove the one created"
|
|
1928
|
+
);
|
|
1929
|
+
out(res.status === "installed" ? " [OK] Codex hooks added" : " [OK] Codex hooks already present");
|
|
1930
|
+
out(" [--] Codex asks you to trust new hooks once: run '/hooks' in Codex and trust Avron's");
|
|
1931
|
+
return true;
|
|
1932
|
+
},
|
|
1933
|
+
uninstall(env, out) {
|
|
1934
|
+
out("\u25B8 Restoring Codex hooks.json:");
|
|
1935
|
+
const res = uninstallCodex(env);
|
|
1936
|
+
if (res.status === "error") {
|
|
1937
|
+
out(` [!!] Could not restore hooks.json: ${res.reason}`);
|
|
1938
|
+
return false;
|
|
1939
|
+
}
|
|
1940
|
+
out(
|
|
1941
|
+
{
|
|
1942
|
+
"restored-exact": " [OK] hooks.json restored byte for byte",
|
|
1943
|
+
"restored-merged": " [OK] Avron entries removed; edits made after install were kept",
|
|
1944
|
+
"not-installed": " [--] Nothing to restore"
|
|
1945
|
+
}[res.status]
|
|
1946
|
+
);
|
|
1947
|
+
return true;
|
|
1948
|
+
},
|
|
1949
|
+
doctor(env, check) {
|
|
1950
|
+
let hooks = 0;
|
|
1951
|
+
try {
|
|
1952
|
+
const f = JSON.parse((0, import_node_fs11.readFileSync)(codexPaths(env).hooksFile, "utf8"));
|
|
1953
|
+
for (const ev of Object.keys(HOOK_EVENTS3))
|
|
1954
|
+
if ((f.hooks?.[ev] ?? []).some((g) => (g.hooks ?? []).some((h) => isOurCommand3(h.command))))
|
|
1955
|
+
hooks++;
|
|
1956
|
+
} catch {
|
|
1957
|
+
}
|
|
1958
|
+
check(
|
|
1959
|
+
hooks === Object.keys(HOOK_EVENTS3).length,
|
|
1960
|
+
"Codex hooks are registered",
|
|
1961
|
+
"Codex hooks are missing (run 'npx @wbcode/avron install')"
|
|
1962
|
+
);
|
|
1963
|
+
},
|
|
1964
|
+
installed: (env) => readInstallState3(env) !== null
|
|
1965
|
+
};
|
|
1966
|
+
var antigravity = {
|
|
1967
|
+
id: "antigravity",
|
|
1968
|
+
name: "Antigravity CLI",
|
|
1969
|
+
detect(env) {
|
|
1970
|
+
const p = antigravityPaths(env);
|
|
1971
|
+
return (0, import_node_fs11.existsSync)((0, import_node_path14.dirname)(p.settingsFile)) ? p.settingsFile : null;
|
|
1972
|
+
},
|
|
1973
|
+
install(env, out) {
|
|
1974
|
+
out("\u25B8 Adding Antigravity CLI hooks and status line:");
|
|
1975
|
+
const res = installAntigravity(env);
|
|
1976
|
+
if (res.status === "error") {
|
|
1977
|
+
out(` [!!] Could not update Antigravity settings: ${res.reason}`);
|
|
1978
|
+
out(" Nothing was changed in Antigravity.");
|
|
1979
|
+
return false;
|
|
1980
|
+
}
|
|
1981
|
+
for (const b of [res.hooksBackup, res.settingsBackup]) if (b) out(` [OK] Saved: ${short(b)}`);
|
|
1982
|
+
out(
|
|
1983
|
+
res.status === "installed" ? " [OK] Antigravity hooks and status line added" : " [OK] Antigravity hooks and status line already present"
|
|
1984
|
+
);
|
|
1985
|
+
return true;
|
|
1986
|
+
},
|
|
1987
|
+
uninstall(env, out) {
|
|
1988
|
+
out("\u25B8 Restoring Antigravity settings:");
|
|
1989
|
+
const res = uninstallAntigravity(env);
|
|
1990
|
+
if (res.status === "error") {
|
|
1991
|
+
out(` [!!] Could not restore Antigravity settings: ${res.reason}`);
|
|
1992
|
+
return false;
|
|
1993
|
+
}
|
|
1994
|
+
out(
|
|
1995
|
+
{
|
|
1996
|
+
"restored-exact": " [OK] hooks.json and settings.json restored byte for byte",
|
|
1997
|
+
"restored-merged": " [OK] Avron entries removed; edits made after install were kept",
|
|
1998
|
+
"not-installed": " [--] Nothing to restore"
|
|
1999
|
+
}[res.status]
|
|
2000
|
+
);
|
|
2001
|
+
return true;
|
|
2002
|
+
},
|
|
2003
|
+
doctor(env, check) {
|
|
2004
|
+
const p = antigravityPaths(env);
|
|
2005
|
+
let hooks = false;
|
|
2006
|
+
let line = false;
|
|
2007
|
+
try {
|
|
2008
|
+
const f = JSON.parse((0, import_node_fs11.readFileSync)(p.hooksFile, "utf8"));
|
|
2009
|
+
const g = f[GROUP] ?? {};
|
|
2010
|
+
hooks = ["PreInvocation", "Stop"].every(
|
|
2011
|
+
(ev) => (g[ev] ?? []).some((h) => isOurCommand2(h.command))
|
|
2012
|
+
);
|
|
2013
|
+
} catch {
|
|
2014
|
+
}
|
|
2015
|
+
try {
|
|
2016
|
+
const s = JSON.parse((0, import_node_fs11.readFileSync)(p.settingsFile, "utf8"));
|
|
2017
|
+
line = isOurCommand2(s.statusLine?.command);
|
|
2018
|
+
} catch {
|
|
2019
|
+
}
|
|
2020
|
+
check(
|
|
2021
|
+
hooks,
|
|
2022
|
+
"Antigravity hooks are registered",
|
|
2023
|
+
"Antigravity hooks are missing (run 'npx @wbcode/avron install')"
|
|
2024
|
+
);
|
|
2025
|
+
check(
|
|
2026
|
+
line,
|
|
2027
|
+
"Antigravity status line is set",
|
|
2028
|
+
"Antigravity status line is missing (run 'npx @wbcode/avron install')"
|
|
2029
|
+
);
|
|
2030
|
+
},
|
|
2031
|
+
installed: (env) => readInstallState2(env) !== null
|
|
2032
|
+
};
|
|
2033
|
+
function opencodeUsed(env) {
|
|
2034
|
+
if (env.AVRON_OPENCODE_DIR) return true;
|
|
2035
|
+
return (0, import_node_fs11.existsSync)((0, import_node_path14.join)(env.XDG_DATA_HOME || (0, import_node_path14.join)((0, import_node_os9.homedir)(), ".local", "share"), "opencode"));
|
|
2036
|
+
}
|
|
2037
|
+
var opencode = {
|
|
2038
|
+
id: "opencode",
|
|
2039
|
+
name: "OpenCode",
|
|
2040
|
+
detect(env) {
|
|
2041
|
+
const p = opencodePaths(env);
|
|
2042
|
+
return (0, import_node_fs11.existsSync)(p.configDir) && opencodeUsed(env) ? p.tuiFile : null;
|
|
2043
|
+
},
|
|
2044
|
+
install(env, out) {
|
|
2045
|
+
out("\u25B8 Adding the OpenCode plugin:");
|
|
2046
|
+
const res = installOpencode(env);
|
|
2047
|
+
if (res.status === "error") {
|
|
2048
|
+
out(` [!!] Could not update ${short(opencodePaths(env).tuiFile)}: ${res.reason}`);
|
|
2049
|
+
out(" Nothing was changed in OpenCode.");
|
|
2050
|
+
return false;
|
|
2051
|
+
}
|
|
2052
|
+
if (res.backupPath) out(` [OK] Saved: ${short(res.backupPath)}`);
|
|
2053
|
+
out(
|
|
2054
|
+
res.status === "installed" ? ` [OK] Listed Avron's plugin in ${short(res.tuiFile)} (restart OpenCode to load it)` : " [OK] OpenCode plugin already listed"
|
|
2055
|
+
);
|
|
2056
|
+
return true;
|
|
2057
|
+
},
|
|
2058
|
+
uninstall(env, out) {
|
|
2059
|
+
out("\u25B8 Restoring OpenCode settings:");
|
|
2060
|
+
const res = uninstallOpencode(env);
|
|
2061
|
+
if (res.status === "error") {
|
|
2062
|
+
out(` [!!] Could not restore OpenCode settings: ${res.reason}`);
|
|
2063
|
+
return false;
|
|
2064
|
+
}
|
|
2065
|
+
out(
|
|
2066
|
+
{
|
|
2067
|
+
"restored-exact": " [OK] tui.json restored byte for byte",
|
|
2068
|
+
"restored-merged": " [OK] Avron's plugin removed; edits made after install were kept",
|
|
2069
|
+
"not-installed": " [--] Nothing to restore"
|
|
2070
|
+
}[res.status]
|
|
2071
|
+
);
|
|
2072
|
+
return true;
|
|
2073
|
+
},
|
|
2074
|
+
doctor(env, check) {
|
|
2075
|
+
check(
|
|
2076
|
+
pluginListed(env),
|
|
2077
|
+
"OpenCode plugin is listed",
|
|
2078
|
+
"OpenCode plugin is missing (run 'npx @wbcode/avron install')"
|
|
2079
|
+
);
|
|
2080
|
+
},
|
|
2081
|
+
installed: (env) => readInstallState6(env) !== null
|
|
2082
|
+
};
|
|
2083
|
+
var ADAPTERS = [claudeCode, copilot, cursor, codex, antigravity, opencode];
|
|
2084
|
+
function selectAdapters(args) {
|
|
2085
|
+
const i = args.indexOf("--agent");
|
|
2086
|
+
if (i < 0) return { adapters: ADAPTERS };
|
|
2087
|
+
const id = args[i + 1];
|
|
2088
|
+
const found = ADAPTERS.find((a) => a.id === id);
|
|
2089
|
+
return found ? { adapters: [found] } : { error: `Unknown agent '${id ?? ""}'. Known: ${ADAPTERS.map((a) => a.id).join(", ")}.` };
|
|
2090
|
+
}
|
|
2091
|
+
var supportedNames = () => ADAPTERS.map((a) => a.name).join(", ");
|
|
2092
|
+
|
|
2093
|
+
// packages/cli/src/operator.ts
|
|
2094
|
+
var VERSION = "0.1.0";
|
|
2095
|
+
var PRODUCT_LINE = `Avron CLI v${VERSION} (UASP Core \u2014 https://avron.dev)`;
|
|
2096
|
+
var OPERATOR_LINE = "Operator: WBCode (Business Reg No: 215-31-01906, Rep: Taehwan Kim, Republic of Korea)";
|
|
2097
|
+
var SUPPORT_LINE = "Support: contact@avron.dev";
|
|
2098
|
+
var TERMS_URL = "https://avron.dev/terms";
|
|
2099
|
+
var PRIVACY_URL = "https://avron.dev/privacy";
|
|
2100
|
+
|
|
2101
|
+
// packages/cli/src/index.ts
|
|
2102
|
+
var DAEMON_SCRIPT = "avron-daemon.cjs";
|
|
2103
|
+
var BIN_FILES = [
|
|
2104
|
+
...Object.keys(bin_entries_default).map((name) => `${name}.cjs`),
|
|
2105
|
+
...Object.keys(bin_esm_entries_default).map((name) => `${name}.mjs`),
|
|
2106
|
+
...Object.keys(bin_copies_default)
|
|
2107
|
+
];
|
|
2108
|
+
function online(io2) {
|
|
2109
|
+
return io2.env.AVRON_OFFLINE === "1" || !io2.fetch ? null : io2.fetch;
|
|
2110
|
+
}
|
|
2111
|
+
var won = (n) => `\u20A9${Math.max(0, Math.floor(n)).toLocaleString("en-US")}`;
|
|
2112
|
+
function siteLang(env) {
|
|
2113
|
+
let l = env.AVRON_LOCALE || env.LC_ALL || env.LC_MESSAGES || env.LANG || "";
|
|
2114
|
+
if (!l) {
|
|
2115
|
+
try {
|
|
2116
|
+
l = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
2117
|
+
} catch {
|
|
2118
|
+
l = "";
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
l = l.toLowerCase().replace("_", "-");
|
|
2122
|
+
if (l.startsWith("ko")) return "ko";
|
|
2123
|
+
if (/^zh-(tw|hk|mo|hant)/.test(l)) return "zh-TW";
|
|
2124
|
+
if (l.startsWith("zh")) return "zh-CN";
|
|
2125
|
+
return "en";
|
|
2126
|
+
}
|
|
2127
|
+
var wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
2128
|
+
async function waitAlive(endpoint, want, timeoutMs) {
|
|
2129
|
+
const end = Date.now() + timeoutMs;
|
|
2130
|
+
for (; ; ) {
|
|
2131
|
+
if (await isAlive(endpoint) === want) return true;
|
|
2132
|
+
if (Date.now() >= end) return false;
|
|
2133
|
+
await wait(60);
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
function startDaemonProcess(io2) {
|
|
2137
|
+
spawnDaemon((0, import_node_path15.join)(avronPaths(io2.env).home, "bin", DAEMON_SCRIPT), io2.env);
|
|
2138
|
+
}
|
|
2139
|
+
async function stopDaemonProcess(io2) {
|
|
2140
|
+
const paths = avronPaths(io2.env);
|
|
2141
|
+
const endpoint = ipcEndpoint(io2.env);
|
|
2142
|
+
if (await stopDaemon({ endpoint, timeoutMs: 3e3 })) {
|
|
2143
|
+
if (await waitAlive(endpoint, false, 3e3)) return;
|
|
2144
|
+
}
|
|
2145
|
+
try {
|
|
2146
|
+
const pid = Number((0, import_node_fs12.readFileSync)((0, import_node_path15.join)(paths.runDir, "daemon.pid"), "utf8"));
|
|
2147
|
+
if (Number.isInteger(pid) && pid > 0) process.kill(pid);
|
|
2148
|
+
} catch {
|
|
2149
|
+
}
|
|
2150
|
+
await waitAlive(endpoint, false, 3e3);
|
|
2151
|
+
}
|
|
2152
|
+
function readSnapshot(io2) {
|
|
2153
|
+
try {
|
|
2154
|
+
return JSON.parse((0, import_node_fs12.readFileSync)(avronPaths(io2.env).ledgerSnapshot, "utf8"));
|
|
2155
|
+
} catch {
|
|
2156
|
+
return null;
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
function operatorFooter(io2) {
|
|
2160
|
+
io2.out("");
|
|
2161
|
+
io2.out("[Operator Info]");
|
|
2162
|
+
io2.out(`Avron (https://avron.dev) | ${OPERATOR_LINE}`);
|
|
2163
|
+
io2.out(SUPPORT_LINE);
|
|
2164
|
+
}
|
|
2165
|
+
async function cmdInstall(io2, args) {
|
|
2166
|
+
const yes = args.includes("--yes") || args.includes("-y");
|
|
2167
|
+
const paths = avronPaths(io2.env);
|
|
2168
|
+
const shortHome = (p) => p.replace(/\\/g, "/");
|
|
2169
|
+
io2.out(`[Avron Installer v${VERSION} \u2014 Make Every Wait Worth It.]`);
|
|
2170
|
+
io2.out("\u25B8 Scanning local AI coding environments...");
|
|
2171
|
+
io2.out("");
|
|
2172
|
+
const picked = selectAdapters(args);
|
|
2173
|
+
if ("error" in picked) {
|
|
2174
|
+
io2.out(picked.error);
|
|
2175
|
+
return 1;
|
|
2176
|
+
}
|
|
2177
|
+
const found = [];
|
|
2178
|
+
for (const a of picked.adapters) {
|
|
2179
|
+
const where = a.detect(io2.env);
|
|
2180
|
+
io2.out(where ? ` [OK] ${a.name} detected at ${shortHome(where)}` : ` [--] ${a.name} (not detected)`);
|
|
2181
|
+
if (where) found.push(a);
|
|
2182
|
+
}
|
|
2183
|
+
io2.out("");
|
|
2184
|
+
if (found.length === 0) {
|
|
2185
|
+
io2.out("No supported agent found. Nothing was changed.");
|
|
2186
|
+
io2.out(`Supported today: ${supportedNames()}. More agents are added one at a time.`);
|
|
2187
|
+
return 1;
|
|
2188
|
+
}
|
|
2189
|
+
io2.out("[What Avron does and does not do]");
|
|
2190
|
+
io2.out("- Zero-Tracking: prompts, code, file paths and env vars are never collected.");
|
|
2191
|
+
io2.out("- Only while thinking: one sponsor line shows while the agent thinks and clears when it stops.");
|
|
2192
|
+
io2.out("- Non-destructive: your settings.json is backed up, your status line and hooks are kept.");
|
|
2193
|
+
io2.out("- Reversible: `npx @wbcode/avron uninstall` restores the file exactly as it was.");
|
|
2194
|
+
io2.out('- Labelled: every line starts with "Sponsored" (or the same word in its language).');
|
|
2195
|
+
io2.out("- Sends: about once an hour, a signed batch of valid impressions with an anonymous");
|
|
2196
|
+
io2.out(" install ID; the server adds your country code. `npx @wbcode/avron audit` shows the next batch.");
|
|
2197
|
+
io2.out("- Where: not offered in mainland China, Japan, the EU, the EEA or the UK.");
|
|
2198
|
+
io2.out("");
|
|
2199
|
+
io2.out(`Terms: ${TERMS_URL}`);
|
|
2200
|
+
io2.out(`Privacy: ${PRIVACY_URL}`);
|
|
2201
|
+
io2.out("");
|
|
2202
|
+
if (!yes) {
|
|
2203
|
+
if (!io2.interactive) {
|
|
2204
|
+
io2.out("Not an interactive terminal. Nothing was changed.");
|
|
2205
|
+
io2.out("To agree to the Terms and Privacy Policy and install, re-run with --yes.");
|
|
2206
|
+
return 1;
|
|
2207
|
+
}
|
|
2208
|
+
if (!await io2.confirm("Agree to the Terms and Privacy Policy and install?", true)) {
|
|
2209
|
+
io2.out("Cancelled. Nothing was changed.");
|
|
2210
|
+
return 1;
|
|
2211
|
+
}
|
|
2212
|
+
}
|
|
2213
|
+
for (const f of BIN_FILES) {
|
|
2214
|
+
if (!(0, import_node_fs12.existsSync)((0, import_node_path15.join)(io2.binSource, f))) {
|
|
2215
|
+
io2.out(` [!!] Package is incomplete (missing ${f}). Nothing was changed.`);
|
|
2216
|
+
return 1;
|
|
2217
|
+
}
|
|
2218
|
+
}
|
|
2219
|
+
const binDir = (0, import_node_path15.join)(paths.home, "bin");
|
|
2220
|
+
(0, import_node_fs12.mkdirSync)(binDir, { recursive: true });
|
|
2221
|
+
for (const f of BIN_FILES) (0, import_node_fs12.copyFileSync)((0, import_node_path15.join)(io2.binSource, f), (0, import_node_path15.join)(binDir, f));
|
|
2222
|
+
if (/^node(\.exe)?$/i.test((0, import_node_path15.basename)(process.execPath)) && !process.versions.electron)
|
|
2223
|
+
(0, import_node_fs12.writeFileSync)(runtimeFile(io2.env), JSON.stringify({ node: process.execPath }));
|
|
2224
|
+
ensureIdentity(paths);
|
|
2225
|
+
for (const a of found) if (!a.install(io2.env, io2.out)) return 1;
|
|
2226
|
+
io2.out("\u25B8 Launching background core daemon:");
|
|
2227
|
+
const endpoint = ipcEndpoint(io2.env);
|
|
2228
|
+
if (await isAlive(endpoint)) await stopDaemonProcess(io2);
|
|
2229
|
+
startDaemonProcess(io2);
|
|
2230
|
+
const up = await waitAlive(endpoint, true, 1e4);
|
|
2231
|
+
io2.out(up ? ` [OK] IPC ready: ${endpoint}` : " [--] Daemon not up yet; it starts by itself on first use");
|
|
2232
|
+
const campaigns = new ManifestStore(io2.env, nullLogger).current().campaigns.length;
|
|
2233
|
+
io2.out(` [OK] Manifest loaded: ${campaigns} line(s)`);
|
|
2234
|
+
io2.out("");
|
|
2235
|
+
io2.out(
|
|
2236
|
+
`\u25B8 Avron is active in ${found.map((a) => a.name).join(", ")}. New sessions pick it up automatically.`
|
|
2237
|
+
);
|
|
2238
|
+
io2.out(" Run 'npx @wbcode/avron doctor' to verify, or 'npx @wbcode/avron uninstall' to cleanly revert.");
|
|
2239
|
+
if (io2.interactive && !args.includes("--yes") && online(io2)) {
|
|
2240
|
+
io2.out("");
|
|
2241
|
+
if (await io2.confirm(
|
|
2242
|
+
"Sign in to avron.dev now, so this machine can receive its share? (opens your browser)",
|
|
2243
|
+
true
|
|
2244
|
+
))
|
|
2245
|
+
await claimLink(io2, false);
|
|
2246
|
+
else io2.out(" Later: 'npx @wbcode/avron login'.");
|
|
2247
|
+
}
|
|
2248
|
+
operatorFooter(io2);
|
|
2249
|
+
return 0;
|
|
2250
|
+
}
|
|
2251
|
+
async function cmdUninstall(io2, args) {
|
|
2252
|
+
const purge = args.includes("--purge");
|
|
2253
|
+
const paths = avronPaths(io2.env);
|
|
2254
|
+
const picked = selectAdapters(args);
|
|
2255
|
+
if ("error" in picked) {
|
|
2256
|
+
io2.out(picked.error);
|
|
2257
|
+
return 1;
|
|
2258
|
+
}
|
|
2259
|
+
for (const a of picked.adapters) if (!a.uninstall(io2.env, io2.out)) return 1;
|
|
2260
|
+
const others = ADAPTERS.filter((a) => !picked.adapters.includes(a) && a.installed(io2.env));
|
|
2261
|
+
if (others.length > 0) {
|
|
2262
|
+
io2.out("");
|
|
2263
|
+
io2.out(`\u25B8 Avron is removed from ${picked.adapters.map((a) => a.name).join(", ")}.`);
|
|
2264
|
+
return 0;
|
|
2265
|
+
}
|
|
2266
|
+
io2.out("\u25B8 Stopping core daemon:");
|
|
2267
|
+
await stopDaemonProcess(io2);
|
|
2268
|
+
io2.out(" [OK] Daemon stopped");
|
|
2269
|
+
removeToastRegistration(io2.env);
|
|
2270
|
+
const turns = readSnapshot(io2)?.validTurns ?? 0;
|
|
2271
|
+
let keep = false;
|
|
2272
|
+
if (turns > 0 && !purge) {
|
|
2273
|
+
io2.out(" If this machine is not linked yet, run 'npx @wbcode/avron claim' first,");
|
|
2274
|
+
io2.out(" or back up its key with 'npx @wbcode/avron key export <file>'.");
|
|
2275
|
+
keep = io2.interactive ? await io2.confirm(
|
|
2276
|
+
`This machine has ${turns} valid turn(s). Keep its key and ledger so its share can still be linked?`,
|
|
2277
|
+
true
|
|
2278
|
+
) : true;
|
|
2279
|
+
}
|
|
2280
|
+
io2.out("\u25B8 Removing Avron files:");
|
|
2281
|
+
if (keep) {
|
|
2282
|
+
for (const name of (0, import_node_fs12.readdirSync)(paths.home)) {
|
|
2283
|
+
if (name === "keys" || name === "logs" || name === "data") continue;
|
|
2284
|
+
(0, import_node_fs12.rmSync)((0, import_node_path15.join)(paths.home, name), { recursive: true, force: true });
|
|
2285
|
+
}
|
|
2286
|
+
(0, import_node_fs12.rmSync)(paths.daemonLog, { force: true });
|
|
2287
|
+
io2.out(` [OK] Kept your key and ledger in ${paths.home.replace(/\\/g, "/")} (${turns} turn(s))`);
|
|
2288
|
+
io2.out(" Remove them too with 'npx @wbcode/avron uninstall --purge'.");
|
|
2289
|
+
} else {
|
|
2290
|
+
(0, import_node_fs12.rmSync)(paths.home, { recursive: true, force: true });
|
|
2291
|
+
io2.out(" [OK] Removed");
|
|
2292
|
+
}
|
|
2293
|
+
io2.out("");
|
|
2294
|
+
io2.out("\u25B8 Avron is uninstalled.");
|
|
2295
|
+
return 0;
|
|
2296
|
+
}
|
|
2297
|
+
async function cmdDoctor(io2) {
|
|
2298
|
+
const paths = avronPaths(io2.env);
|
|
2299
|
+
let problems = 0;
|
|
2300
|
+
const check = (ok, good, bad) => {
|
|
2301
|
+
io2.out(ok ? ` [OK] ${good}` : ` [!!] ${bad}`);
|
|
2302
|
+
if (!ok) problems++;
|
|
2303
|
+
};
|
|
2304
|
+
io2.out(PRODUCT_LINE);
|
|
2305
|
+
io2.out(OPERATOR_LINE);
|
|
2306
|
+
io2.out(SUPPORT_LINE);
|
|
2307
|
+
io2.out("");
|
|
2308
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
2309
|
+
check(
|
|
2310
|
+
major >= 20,
|
|
2311
|
+
`Node.js ${process.versions.node}`,
|
|
2312
|
+
`Node.js ${process.versions.node} is too old (20 or newer needed)`
|
|
2313
|
+
);
|
|
2314
|
+
for (const a of ADAPTERS) if (a.detect(io2.env)) a.doctor(io2.env, check, io2.out);
|
|
2315
|
+
check(
|
|
2316
|
+
BIN_FILES.every((f) => (0, import_node_fs12.existsSync)((0, import_node_path15.join)(paths.home, "bin", f))),
|
|
2317
|
+
"Runtime scripts are in place",
|
|
2318
|
+
"Runtime scripts are missing"
|
|
2319
|
+
);
|
|
2320
|
+
check(
|
|
2321
|
+
loadIdentity(paths) !== null,
|
|
2322
|
+
"Anonymous install key exists (no account needed)",
|
|
2323
|
+
"Install key is missing"
|
|
2324
|
+
);
|
|
2325
|
+
const endpoint = ipcEndpoint(io2.env);
|
|
2326
|
+
if (!await isAlive(endpoint) && (0, import_node_fs12.existsSync)((0, import_node_path15.join)(paths.home, "bin", DAEMON_SCRIPT))) {
|
|
2327
|
+
startDaemonProcess(io2);
|
|
2328
|
+
await waitAlive(endpoint, true, 1e4);
|
|
2329
|
+
}
|
|
2330
|
+
const t0 = performance.now();
|
|
2331
|
+
const res = await request(
|
|
2332
|
+
{
|
|
2333
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
2334
|
+
eventType: "PAYLOAD_REQUEST",
|
|
2335
|
+
agentName: "claude-code",
|
|
2336
|
+
agentTier: "cli",
|
|
2337
|
+
sessionId: "avron-doctor",
|
|
2338
|
+
timestamp: Date.now(),
|
|
2339
|
+
payload: { slot: "statusline" }
|
|
2340
|
+
},
|
|
2341
|
+
{ timeoutMs: 500, endpoint }
|
|
2342
|
+
);
|
|
2343
|
+
const ms = performance.now() - t0;
|
|
2344
|
+
check(res !== null, `Core daemon answers in ${ms.toFixed(1)} ms`, "Core daemon is not answering");
|
|
2345
|
+
const cfg = readConfig(io2.env);
|
|
2346
|
+
const manifest = new ManifestStore(io2.env, nullLogger).current();
|
|
2347
|
+
io2.out(
|
|
2348
|
+
` [OK] Manifest: ${manifest.campaigns.length} line(s), ${manifest.enabled ? "enabled" : "DISABLED remotely"}`
|
|
2349
|
+
);
|
|
2350
|
+
io2.out(` [OK] Mode: ${cfg.mode}${cfg.paused ? " (paused)" : ""}`);
|
|
2351
|
+
io2.out("");
|
|
2352
|
+
io2.out(problems === 0 ? "\u25B8 All checks passed." : `\u25B8 ${problems} problem(s) found.`);
|
|
2353
|
+
return problems === 0 ? 0 : 1;
|
|
2354
|
+
}
|
|
2355
|
+
async function cmdStatus(io2, share) {
|
|
2356
|
+
const paths = avronPaths(io2.env);
|
|
2357
|
+
const snap = readSnapshot(io2);
|
|
2358
|
+
const id = loadIdentity(paths);
|
|
2359
|
+
const turns = snap?.validTurns ?? 0;
|
|
2360
|
+
const cfg = readConfig(io2.env);
|
|
2361
|
+
const f = online(io2);
|
|
2362
|
+
const me = f && id ? await postSigned(io2.env, paths, "/v1/me", "me", {}, f, Date.now(), 4e3) : null;
|
|
2363
|
+
io2.out("\u256D\u2500 Avron \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256E");
|
|
2364
|
+
const row = (s) => io2.out(`\u2502 ${s.padEnd(64)}\u2502`);
|
|
2365
|
+
row(`Valid thinking turns: ${turns} (today: ${snap?.today.validTurns ?? 0})`);
|
|
2366
|
+
if (me?.status === 200) {
|
|
2367
|
+
const b = me.body;
|
|
2368
|
+
const bal = b.balance ?? {};
|
|
2369
|
+
row(`Credited by avron.dev: ${b.credited?.total ?? 0} (sponsor lines: ${b.credited?.sponsored ?? 0})`);
|
|
2370
|
+
row(`Your share: ${won(bal.available ?? 0)} ready, ${won(bal.pendingEstimate ?? 0)} pending (estimate)`);
|
|
2371
|
+
if ((bal.paid ?? 0) + (bal.inProgress ?? 0) > 0)
|
|
2372
|
+
row(`Sent: ${won(bal.paid ?? 0)}, on its way: ${won(bal.inProgress ?? 0)}`);
|
|
2373
|
+
if ((bal.held ?? 0) > 0) row(`Held for review: ${won(bal.held ?? 0)}`);
|
|
2374
|
+
row(
|
|
2375
|
+
b.linked?.name ? `Linked to ${b.linked.name}. More: avron.dev/dashboard` : "Not linked yet. Run 'npx @wbcode/avron login' to receive your share."
|
|
2376
|
+
);
|
|
2377
|
+
} else {
|
|
2378
|
+
row(
|
|
2379
|
+
f && id ? "avron.dev did not answer, so your share is not shown." : "Offline: your share is not shown."
|
|
2380
|
+
);
|
|
2381
|
+
const counted = serverCounted(paths);
|
|
2382
|
+
if (counted)
|
|
2383
|
+
row(
|
|
2384
|
+
`Counted by avron.dev at last upload: ${counted.accepted} (${new Date(counted.at).toISOString().slice(0, 10)})`
|
|
2385
|
+
);
|
|
2386
|
+
}
|
|
2387
|
+
row("Paid sponsor lines earn a share; Avron house lines do not.");
|
|
2388
|
+
if (cfg.paused) row("Paused. Run 'npx @wbcode/avron resume' to show lines again.");
|
|
2389
|
+
if (share && id) row(`avron.dev/?r=${id.ref}`);
|
|
2390
|
+
io2.out("\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256F");
|
|
2391
|
+
return 0;
|
|
2392
|
+
}
|
|
2393
|
+
function openUrl(url) {
|
|
2394
|
+
if (process.platform === "win32") runDetached("cmd", ["/c", "start", "", url.replace(/&/g, "^&")]);
|
|
2395
|
+
else if (process.platform === "darwin") runDetached("open", [url]);
|
|
2396
|
+
else runDetached("xdg-open", [url]);
|
|
2397
|
+
}
|
|
2398
|
+
async function cmdClaim(io2, args) {
|
|
2399
|
+
return claimLink(io2, args.includes("--print"));
|
|
2400
|
+
}
|
|
2401
|
+
async function claimLink(io2, printOnly) {
|
|
2402
|
+
const paths = avronPaths(io2.env);
|
|
2403
|
+
if (!loadIdentity(paths)) {
|
|
2404
|
+
io2.out("Avron is not installed on this machine. Run 'npx @wbcode/avron install' first.");
|
|
2405
|
+
return 1;
|
|
2406
|
+
}
|
|
2407
|
+
const f = online(io2);
|
|
2408
|
+
if (!f) {
|
|
2409
|
+
io2.out("Linking needs a connection to avron.dev.");
|
|
2410
|
+
return 1;
|
|
2411
|
+
}
|
|
2412
|
+
const res = await postSigned(io2.env, paths, "/v1/claim/start", "claim", { lang: siteLang(io2.env) }, f);
|
|
2413
|
+
if (!res) {
|
|
2414
|
+
io2.out("Could not reach avron.dev. Try again later.");
|
|
2415
|
+
return 1;
|
|
2416
|
+
}
|
|
2417
|
+
if (res.status === 403) {
|
|
2418
|
+
io2.out("Avron is not offered in your region (Terms, section 11).");
|
|
2419
|
+
return 1;
|
|
2420
|
+
}
|
|
2421
|
+
if (res.status === 503) {
|
|
2422
|
+
io2.out("Account linking is not open yet.");
|
|
2423
|
+
return 1;
|
|
2424
|
+
}
|
|
2425
|
+
const url = typeof res.body.url === "string" ? res.body.url : "";
|
|
2426
|
+
if (res.status !== 201 || !url.startsWith(`${apiBase(io2.env)}/v1/auth/claim?t=`)) {
|
|
2427
|
+
io2.out(`avron.dev refused the request (${res.status}).`);
|
|
2428
|
+
return 1;
|
|
2429
|
+
}
|
|
2430
|
+
io2.out("\u25B8 Sign in to link this machine to your account:");
|
|
2431
|
+
io2.out(` ${url}`);
|
|
2432
|
+
io2.out(` The link works once, for ${Number(res.body.expiresInMinutes) || 10} minutes. Do not share it:`);
|
|
2433
|
+
io2.out(" whoever opens it can link this machine to their account.");
|
|
2434
|
+
io2.out(" You can sign in with an emailed code, Google or GitHub. Nothing is posted anywhere.");
|
|
2435
|
+
if (!printOnly) openUrl(url);
|
|
2436
|
+
return 0;
|
|
2437
|
+
}
|
|
2438
|
+
function cmdKey(io2, args) {
|
|
2439
|
+
const [verb, file, ...rest] = args;
|
|
2440
|
+
const paths = avronPaths(io2.env);
|
|
2441
|
+
if (verb === "export" && file) {
|
|
2442
|
+
const backup = exportIdentity(paths);
|
|
2443
|
+
if (!backup) {
|
|
2444
|
+
io2.out("This machine has no Avron key.");
|
|
2445
|
+
return 1;
|
|
2446
|
+
}
|
|
2447
|
+
if ((0, import_node_fs12.existsSync)(file) && !rest.includes("--force")) {
|
|
2448
|
+
io2.out(`${file} already exists. Add --force to overwrite it.`);
|
|
2449
|
+
return 1;
|
|
2450
|
+
}
|
|
2451
|
+
(0, import_node_fs12.writeFileSync)(file, `${JSON.stringify(backup, null, 2)}
|
|
2452
|
+
`, { mode: 384 });
|
|
2453
|
+
io2.out(`[OK] Key saved to ${file}`);
|
|
2454
|
+
io2.out(" Keep it private: it is what proves this machine's share is yours.");
|
|
2455
|
+
return 0;
|
|
2456
|
+
}
|
|
2457
|
+
if (verb === "import" && file) {
|
|
2458
|
+
let data;
|
|
2459
|
+
try {
|
|
2460
|
+
data = JSON.parse((0, import_node_fs12.readFileSync)(file, "utf8"));
|
|
2461
|
+
} catch {
|
|
2462
|
+
io2.out(`Could not read ${file}.`);
|
|
2463
|
+
return 1;
|
|
2464
|
+
}
|
|
2465
|
+
const r = importIdentity(paths, data, rest.includes("--force"));
|
|
2466
|
+
if (!r.ok) {
|
|
2467
|
+
io2.out(
|
|
2468
|
+
r.reason === "exists" ? "This machine already has a different key. Add --force to replace it (an unlinked share of the current key would be lost)." : "That is not a valid Avron key file."
|
|
2469
|
+
);
|
|
2470
|
+
return 1;
|
|
2471
|
+
}
|
|
2472
|
+
io2.out(`[OK] Key restored (install ${r.identity.installId.slice(0, 8)})`);
|
|
2473
|
+
return 0;
|
|
2474
|
+
}
|
|
2475
|
+
io2.out("Usage: avron key export <file> | avron key import <file> [--force]");
|
|
2476
|
+
return 1;
|
|
2477
|
+
}
|
|
2478
|
+
function runDetached(cmd, args, input) {
|
|
2479
|
+
try {
|
|
2480
|
+
const child = (0, import_node_child_process3.spawn)(cmd, args, {
|
|
2481
|
+
stdio: [input === void 0 ? "ignore" : "pipe", "ignore", "ignore"],
|
|
2482
|
+
windowsHide: true,
|
|
2483
|
+
detached: true
|
|
2484
|
+
});
|
|
2485
|
+
child.on("error", () => {
|
|
2486
|
+
});
|
|
2487
|
+
if (input !== void 0) child.stdin?.end(input);
|
|
2488
|
+
child.unref();
|
|
2489
|
+
} catch {
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
function cmdOpen(io2, args) {
|
|
2493
|
+
let last = {};
|
|
2494
|
+
try {
|
|
2495
|
+
last = JSON.parse((0, import_node_fs12.readFileSync)((0, import_node_path15.join)(avronPaths(io2.env).runDir, "last-shown.json"), "utf8"));
|
|
2496
|
+
} catch {
|
|
2497
|
+
io2.out("No sponsor line has been shown yet.");
|
|
2498
|
+
return 1;
|
|
2499
|
+
}
|
|
2500
|
+
const url = safeLink(last.actionUrl);
|
|
2501
|
+
if (!url) {
|
|
2502
|
+
io2.out("The last line has no link.");
|
|
2503
|
+
return 1;
|
|
2504
|
+
}
|
|
2505
|
+
const code = typeof last.promoCode === "string" && /^[A-Za-z0-9_-]{1,40}$/.test(last.promoCode) ? last.promoCode : null;
|
|
2506
|
+
io2.out(`\u25B8 ${last.sponsorName ?? "Sponsor"}: ${url}`);
|
|
2507
|
+
if (code) io2.out(` Promo code copied to clipboard: ${code}`);
|
|
2508
|
+
if (args.includes("--print")) return 0;
|
|
2509
|
+
if (code) {
|
|
2510
|
+
if (process.platform === "win32") runDetached("clip", [], code);
|
|
2511
|
+
else if (process.platform === "darwin") runDetached("pbcopy", [], code);
|
|
2512
|
+
else
|
|
2513
|
+
runDetached(
|
|
2514
|
+
"sh",
|
|
2515
|
+
["-c", "command -v wl-copy >/dev/null && wl-copy || xclip -selection clipboard"],
|
|
2516
|
+
code
|
|
2517
|
+
);
|
|
2518
|
+
}
|
|
2519
|
+
openUrl(url);
|
|
2520
|
+
return 0;
|
|
2521
|
+
}
|
|
2522
|
+
function cmdAudit(io2) {
|
|
2523
|
+
const paths = avronPaths(io2.env);
|
|
2524
|
+
io2.out("[Never collected]");
|
|
2525
|
+
io2.out(" prompts \xB7 source code \xB7 file names and paths \xB7 git URLs \xB7 environment variables \xB7 API keys");
|
|
2526
|
+
io2.out("");
|
|
2527
|
+
io2.out("[Stored on this machine only]");
|
|
2528
|
+
const show = (label, file) => {
|
|
2529
|
+
let size = "none";
|
|
2530
|
+
try {
|
|
2531
|
+
size = `${(0, import_node_fs12.statSync)(file).size} bytes`;
|
|
2532
|
+
} catch {
|
|
2533
|
+
}
|
|
2534
|
+
io2.out(` ${label.padEnd(26)} ${file.replace(/\\/g, "/")} (${size})`);
|
|
2535
|
+
};
|
|
2536
|
+
show("valid impression log", paths.impressionsLog);
|
|
2537
|
+
show("totals", paths.ledgerSnapshot);
|
|
2538
|
+
show("daemon diagnostics", paths.daemonLog);
|
|
2539
|
+
show("cached manifest", paths.manifestCache);
|
|
2540
|
+
show("sponsor pictures for notifications", (0, import_node_path15.join)(paths.runDir, "toast-pictures"));
|
|
2541
|
+
show("install key (private)", (0, import_node_path15.join)(paths.keyDir, "private.key"));
|
|
2542
|
+
io2.out("");
|
|
2543
|
+
io2.out("[Sent to the server]");
|
|
2544
|
+
io2.out(` Endpoint: ${apiBase(io2.env)}/v1/events/batch (at most once an hour)`);
|
|
2545
|
+
io2.out(" The server sees your country code. Your IP address is not stored.");
|
|
2546
|
+
const manifest = new ManifestStore(io2.env, nullLogger).current();
|
|
2547
|
+
const batch = buildBatch(paths, manifest.serverNonce, Date.now());
|
|
2548
|
+
if (!batch) {
|
|
2549
|
+
io2.out(" Next upload: nothing pending.");
|
|
2550
|
+
return 0;
|
|
2551
|
+
}
|
|
2552
|
+
io2.out(` Next upload (${batch.events.length} event(s)), exactly as it will be sent:`);
|
|
2553
|
+
io2.out("");
|
|
2554
|
+
for (const line of JSON.stringify(JSON.parse(batch.envelope.payload), null, 2).split("\n"))
|
|
2555
|
+
io2.out(` ${line}`);
|
|
2556
|
+
io2.out("");
|
|
2557
|
+
io2.out(` publicKey: ${batch.envelope.publicKey}`);
|
|
2558
|
+
io2.out(` signature: ${batch.envelope.signature}`);
|
|
2559
|
+
return 0;
|
|
2560
|
+
}
|
|
2561
|
+
var MODES = {
|
|
2562
|
+
"pill-statusline": "available",
|
|
2563
|
+
"exit-receipt": "not available yet",
|
|
2564
|
+
"native-devtip": "not available yet",
|
|
2565
|
+
"rich-gui": "not available yet",
|
|
2566
|
+
"os-menubar": "not available yet"
|
|
2567
|
+
};
|
|
2568
|
+
function cmdMode(io2, name) {
|
|
2569
|
+
if (!name) {
|
|
2570
|
+
const current = readConfig(io2.env).mode;
|
|
2571
|
+
for (const [m, state] of Object.entries(MODES))
|
|
2572
|
+
io2.out(` ${m === current ? "\u25CF" : "\u25CB"} ${m.padEnd(16)} ${state}`);
|
|
2573
|
+
return 0;
|
|
2574
|
+
}
|
|
2575
|
+
if (!(name in MODES)) {
|
|
2576
|
+
io2.out(`Unknown mode: ${name}`);
|
|
2577
|
+
return 1;
|
|
2578
|
+
}
|
|
2579
|
+
if (MODES[name] !== "available") {
|
|
2580
|
+
io2.out(`${name} is not available yet. Nothing was changed.`);
|
|
2581
|
+
return 1;
|
|
2582
|
+
}
|
|
2583
|
+
writeConfig({ mode: "pill-statusline" }, io2.env);
|
|
2584
|
+
io2.out(`Mode set to ${name}.`);
|
|
2585
|
+
return 0;
|
|
2586
|
+
}
|
|
2587
|
+
function cmdConfig(io2, args) {
|
|
2588
|
+
const modeFlag = args.indexOf("--mode");
|
|
2589
|
+
if (modeFlag >= 0) return cmdMode(io2, args[modeFlag + 1]);
|
|
2590
|
+
const [verb, key, value] = args;
|
|
2591
|
+
const cfg = readConfig(io2.env);
|
|
2592
|
+
if (!verb || verb === "list") {
|
|
2593
|
+
io2.out(`mode ${cfg.mode}`);
|
|
2594
|
+
io2.out(`paused ${cfg.paused}`);
|
|
2595
|
+
for (const [k, v] of Object.entries(cfg.formats)) io2.out(`formats.${k.padEnd(10)} ${v}`);
|
|
2596
|
+
return 0;
|
|
2597
|
+
}
|
|
2598
|
+
if (verb === "set" && key?.startsWith("formats")) return setFormat(io2, key, value, args[3]);
|
|
2599
|
+
if (verb === "set" && key === "mode") return cmdMode(io2, value);
|
|
2600
|
+
io2.out(
|
|
2601
|
+
"Usage: avron config [list] | set mode <name>\n avron config set formats all on|off | set formats.<name> true|false | set formats.codeLines 1|2|3"
|
|
2602
|
+
);
|
|
2603
|
+
return 1;
|
|
2604
|
+
}
|
|
2605
|
+
function setFormat(io2, key, value, last) {
|
|
2606
|
+
const formats = { ...readConfig(io2.env).formats };
|
|
2607
|
+
if (key === "formats" || key === "formats.all") {
|
|
2608
|
+
const word = key === "formats" ? last : value;
|
|
2609
|
+
if (word !== "on" && word !== "off") {
|
|
2610
|
+
io2.out("Usage: avron config set formats all on|off");
|
|
2611
|
+
return 1;
|
|
2612
|
+
}
|
|
2613
|
+
for (const k of Object.keys(formats))
|
|
2614
|
+
if (k !== "codeLines") formats[k] = word === "on";
|
|
2615
|
+
writeConfig({ formats }, io2.env);
|
|
2616
|
+
io2.out(word === "on" ? "Every format is on." : "Only the one line is shown now.");
|
|
2617
|
+
return 0;
|
|
2618
|
+
}
|
|
2619
|
+
const name = key.slice("formats.".length);
|
|
2620
|
+
if (!(name in formats)) {
|
|
2621
|
+
io2.out(`Unknown format: ${name}. Formats: ${Object.keys(formats).join(", ")}`);
|
|
2622
|
+
return 1;
|
|
2623
|
+
}
|
|
2624
|
+
if (name === "codeLines") {
|
|
2625
|
+
const n = Number(value);
|
|
2626
|
+
if (n !== 1 && n !== 2 && n !== 3) {
|
|
2627
|
+
io2.out("formats.codeLines is 1, 2 or 3.");
|
|
2628
|
+
return 1;
|
|
2629
|
+
}
|
|
2630
|
+
formats.codeLines = n;
|
|
2631
|
+
} else {
|
|
2632
|
+
if (value !== "true" && value !== "false") {
|
|
2633
|
+
io2.out(`Usage: avron config set formats.${name} true|false`);
|
|
2634
|
+
return 1;
|
|
2635
|
+
}
|
|
2636
|
+
formats[name] = value === "true";
|
|
2637
|
+
}
|
|
2638
|
+
writeConfig({ formats }, io2.env);
|
|
2639
|
+
io2.out(`formats.${name} set to ${formats[name]}.`);
|
|
2640
|
+
return 0;
|
|
2641
|
+
}
|
|
2642
|
+
var HELP = `Usage: npx @wbcode/avron <command>
|
|
2643
|
+
|
|
2644
|
+
install [--yes] Add Avron to your AI coding agents (backs up settings first).
|
|
2645
|
+
--yes: agree to the Terms and Privacy Policy without asking
|
|
2646
|
+
--agent <id>: only this agent (claude-code, copilot, cursor, codex, antigravity, opencode)
|
|
2647
|
+
uninstall [--purge] Remove Avron and restore settings exactly (--agent <id>: one agent)
|
|
2648
|
+
doctor Check that everything is wired correctly
|
|
2649
|
+
status Show valid turns, what avron.dev credited and your share
|
|
2650
|
+
login Sign in and link this machine to your account to receive your share
|
|
2651
|
+
claim The same as login
|
|
2652
|
+
key export|import <file> Back up or restore this machine's key
|
|
2653
|
+
open Open the last sponsor link and copy its promo code
|
|
2654
|
+
audit [--dry-run] Show what is stored locally and the next upload, byte for byte
|
|
2655
|
+
mode [name] Show or change the display mode
|
|
2656
|
+
config [list|get|set] Show or change preferences (mode, formats.<name>)
|
|
2657
|
+
pause | resume Hide or show sponsor lines on this machine
|
|
2658
|
+
--version Version and operator information`;
|
|
2659
|
+
async function main(argv, io2) {
|
|
2660
|
+
const [cmd, ...rest] = argv;
|
|
2661
|
+
switch (cmd) {
|
|
2662
|
+
case "install":
|
|
2663
|
+
case "setup":
|
|
2664
|
+
return cmdInstall(io2, rest);
|
|
2665
|
+
case "uninstall":
|
|
2666
|
+
return cmdUninstall(io2, rest);
|
|
2667
|
+
case "doctor":
|
|
2668
|
+
return cmdDoctor(io2);
|
|
2669
|
+
case "status":
|
|
2670
|
+
return cmdStatus(io2, false);
|
|
2671
|
+
case "claim":
|
|
2672
|
+
case "login":
|
|
2673
|
+
return cmdClaim(io2, rest);
|
|
2674
|
+
case "key":
|
|
2675
|
+
return cmdKey(io2, rest);
|
|
2676
|
+
case "stats":
|
|
2677
|
+
return cmdStatus(io2, rest.includes("--share"));
|
|
2678
|
+
case "share":
|
|
2679
|
+
return cmdStatus(io2, true);
|
|
2680
|
+
case "open":
|
|
2681
|
+
return cmdOpen(io2, rest);
|
|
2682
|
+
case "audit":
|
|
2683
|
+
return cmdAudit(io2);
|
|
2684
|
+
case "mode":
|
|
2685
|
+
return cmdMode(io2, rest[0]);
|
|
2686
|
+
case "config":
|
|
2687
|
+
return cmdConfig(io2, rest);
|
|
2688
|
+
case "pause":
|
|
2689
|
+
case "resume":
|
|
2690
|
+
writeConfig({ paused: cmd === "pause" }, io2.env);
|
|
2691
|
+
io2.out(cmd === "pause" ? "Paused. No sponsor lines are shown on this machine." : "Resumed.");
|
|
2692
|
+
return 0;
|
|
2693
|
+
case "--version":
|
|
2694
|
+
case "-v":
|
|
2695
|
+
case "version":
|
|
2696
|
+
io2.out(PRODUCT_LINE);
|
|
2697
|
+
io2.out(OPERATOR_LINE);
|
|
2698
|
+
io2.out(SUPPORT_LINE);
|
|
2699
|
+
return 0;
|
|
2700
|
+
case void 0:
|
|
2701
|
+
case "help":
|
|
2702
|
+
case "--help":
|
|
2703
|
+
case "-h":
|
|
2704
|
+
io2.out(HELP);
|
|
2705
|
+
return 0;
|
|
2706
|
+
default:
|
|
2707
|
+
io2.out(`Unknown command: ${cmd}`);
|
|
2708
|
+
io2.out(HELP);
|
|
2709
|
+
return 1;
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
// packages/cli/src/bin.ts
|
|
2714
|
+
var interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
2715
|
+
var io = {
|
|
2716
|
+
env: process.env,
|
|
2717
|
+
out: (line) => process.stdout.write(`${line}
|
|
2718
|
+
`),
|
|
2719
|
+
interactive,
|
|
2720
|
+
binSource: (0, import_node_path16.join)(__dirname, "bin"),
|
|
2721
|
+
fetch,
|
|
2722
|
+
confirm: (question, defaultYes) => new Promise((resolve9) => {
|
|
2723
|
+
if (!interactive) return resolve9(defaultYes);
|
|
2724
|
+
const rl = (0, import_node_readline.createInterface)({ input: process.stdin, output: process.stdout });
|
|
2725
|
+
rl.question(`? ${question} ${defaultYes ? "(Y/n)" : "(y/N)"} > `, (answer) => {
|
|
2726
|
+
rl.close();
|
|
2727
|
+
const a = answer.trim().toLowerCase();
|
|
2728
|
+
resolve9(a === "" ? defaultYes : a === "y" || a === "yes");
|
|
2729
|
+
});
|
|
2730
|
+
})
|
|
2731
|
+
};
|
|
2732
|
+
main(process.argv.slice(2), io).then(
|
|
2733
|
+
(code) => {
|
|
2734
|
+
process.exitCode = code;
|
|
2735
|
+
},
|
|
2736
|
+
(err) => {
|
|
2737
|
+
process.stdout.write(`avron: ${err instanceof Error ? err.message : String(err)}
|
|
2738
|
+
`);
|
|
2739
|
+
process.exitCode = 1;
|
|
2740
|
+
}
|
|
2741
|
+
);
|