@wbcode/avron 0.0.0-stage → 0.1.1

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