@wbcode/avron 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/SECURITY.md +3 -0
- package/avron.cjs +411 -167
- package/bin/avron-claude-plugin.cjs +418 -0
- package/bin/avron-daemon.cjs +6 -3
- package/bin/avron-hook.cjs +10 -1
- package/claude-plugin/.claude-plugin/marketplace.json +14 -0
- package/claude-plugin/avron/.claude-plugin/plugin.json +10 -0
- package/claude-plugin/avron/LICENSE +21 -0
- package/claude-plugin/avron/hooks/hooks.json +1 -0
- package/claude-plugin/avron/hooks/register.tsx +254 -0
- package/claude-plugin/avron/types/index.d.ts +23 -0
- package/package.json +2 -1
package/avron.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
// packages/cli/src/bin.ts
|
|
5
|
-
var
|
|
5
|
+
var import_node_path17 = require("node:path");
|
|
6
6
|
var import_node_readline = require("node:readline");
|
|
7
7
|
|
|
8
8
|
// packages/cli/src/index.ts
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
9
|
+
var import_node_child_process4 = require("node:child_process");
|
|
10
|
+
var import_node_fs13 = require("node:fs");
|
|
11
|
+
var import_node_path16 = require("node:path");
|
|
12
12
|
|
|
13
13
|
// packages/adapter-claude-code/src/settings.ts
|
|
14
14
|
var HOOK_EVENTS = {
|
|
@@ -529,6 +529,203 @@ function uninstallClaudeCode(env = process.env) {
|
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
|
|
532
|
+
// packages/adapter-claude-code/src/plugin.ts
|
|
533
|
+
var import_node_child_process2 = require("node:child_process");
|
|
534
|
+
var import_node_fs3 = require("node:fs");
|
|
535
|
+
var import_node_os4 = require("node:os");
|
|
536
|
+
var import_node_path5 = require("node:path");
|
|
537
|
+
var PLUGIN_NAME = "avron";
|
|
538
|
+
var MARKETPLACE_NAME = "avron-local";
|
|
539
|
+
var PLUGIN_ID = `${PLUGIN_NAME}@${MARKETPLACE_NAME}`;
|
|
540
|
+
var PLUGIN_SCRIPT = "avron-claude-plugin.cjs";
|
|
541
|
+
var CONFIG_FILE = "avron-plugin.json";
|
|
542
|
+
var SECTIONS = [
|
|
543
|
+
["enabledPlugins", PLUGIN_ID],
|
|
544
|
+
["extraKnownMarketplaces", MARKETPLACE_NAME]
|
|
545
|
+
];
|
|
546
|
+
function pluginPaths(env = process.env) {
|
|
547
|
+
const home = avronHome(env);
|
|
548
|
+
const marketplaceDir = (0, import_node_path5.join)(home, "claude-plugin");
|
|
549
|
+
return {
|
|
550
|
+
marketplaceDir,
|
|
551
|
+
pluginDir: (0, import_node_path5.join)(marketplaceDir, PLUGIN_NAME),
|
|
552
|
+
statePath: (0, import_node_path5.join)(home, "adapters", "claude-desktop-plugin.json"),
|
|
553
|
+
backupPath: `${claudePaths(env).settingsPath}.avron-plugin-backup`
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
function readPluginState(env = process.env) {
|
|
557
|
+
try {
|
|
558
|
+
return JSON.parse((0, import_node_fs3.readFileSync)(pluginPaths(env).statePath, "utf8"));
|
|
559
|
+
} catch {
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
function desktopAppPresent(env = process.env, platform = process.platform, home = (0, import_node_os4.homedir)()) {
|
|
564
|
+
if (env.AVRON_CLAUDE_DESKTOP === "1") return true;
|
|
565
|
+
if (env.AVRON_CLAUDE_DESKTOP === "0") return false;
|
|
566
|
+
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) return false;
|
|
567
|
+
if (platform === "win32") {
|
|
568
|
+
const local = env.LOCALAPPDATA || (0, import_node_path5.join)(home, "AppData", "Local");
|
|
569
|
+
if ((0, import_node_fs3.existsSync)((0, import_node_path5.join)(local, "AnthropicClaude")) || (0, import_node_fs3.existsSync)((0, import_node_path5.join)(local, "Claude"))) return true;
|
|
570
|
+
try {
|
|
571
|
+
return (0, import_node_fs3.readdirSync)((0, import_node_path5.join)(local, "Packages")).some((name) => /^Claude_/i.test(name));
|
|
572
|
+
} catch {
|
|
573
|
+
return false;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (platform === "darwin")
|
|
577
|
+
return (0, import_node_fs3.existsSync)("/Applications/Claude.app") || (0, import_node_fs3.existsSync)((0, import_node_path5.join)(home, "Applications", "Claude.app"));
|
|
578
|
+
return false;
|
|
579
|
+
}
|
|
580
|
+
var quoteArg = (arg) => /^[A-Za-z0-9_.:@=/\\-]+$/.test(arg) ? arg : `"${arg.replace(/"/g, "")}"`;
|
|
581
|
+
var claudeRunner = (args, env) => {
|
|
582
|
+
const r = process.platform === "win32" ? (0, import_node_child_process2.spawnSync)(`claude ${args.map(quoteArg).join(" ")}`, {
|
|
583
|
+
env,
|
|
584
|
+
encoding: "utf8",
|
|
585
|
+
timeout: 9e4,
|
|
586
|
+
windowsHide: true,
|
|
587
|
+
shell: true
|
|
588
|
+
}) : (0, import_node_child_process2.spawnSync)("claude", args, { env, encoding: "utf8", timeout: 9e4 });
|
|
589
|
+
return { ok: r.status === 0 && !r.error, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
590
|
+
};
|
|
591
|
+
function claudeEnv(env) {
|
|
592
|
+
return env.AVRON_CLAUDE_DIR ? { ...env, CLAUDE_CONFIG_DIR: env.AVRON_CLAUDE_DIR } : env;
|
|
593
|
+
}
|
|
594
|
+
function canonical(value) {
|
|
595
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
596
|
+
if (value !== null && typeof value === "object") {
|
|
597
|
+
const entries = Object.entries(value).sort(([a], [b]) => a < b ? -1 : 1);
|
|
598
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
599
|
+
}
|
|
600
|
+
return JSON.stringify(value) ?? "null";
|
|
601
|
+
}
|
|
602
|
+
function parseObject2(text) {
|
|
603
|
+
try {
|
|
604
|
+
const value = JSON.parse(text);
|
|
605
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
606
|
+
} catch {
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
var isObject4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
611
|
+
function withoutOurs(settings, ours) {
|
|
612
|
+
const out = { ...settings };
|
|
613
|
+
for (const [key, name] of SECTIONS) {
|
|
614
|
+
const section = settings[key];
|
|
615
|
+
if (!isObject4(section)) continue;
|
|
616
|
+
const rest = Object.fromEntries(Object.entries(section).filter(([k]) => !ours || k !== name));
|
|
617
|
+
if (Object.keys(rest).length > 0) out[key] = rest;
|
|
618
|
+
else delete out[key];
|
|
619
|
+
}
|
|
620
|
+
return out;
|
|
621
|
+
}
|
|
622
|
+
function pluginRegistered(env = process.env) {
|
|
623
|
+
try {
|
|
624
|
+
const settings = parseObject2((0, import_node_fs3.readFileSync)(claudePaths(env).settingsPath, "utf8"));
|
|
625
|
+
const enabled = settings?.enabledPlugins;
|
|
626
|
+
return isObject4(enabled) && enabled[PLUGIN_ID] === true;
|
|
627
|
+
} catch {
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
function installPlugin(env, source, runner = claudeRunner) {
|
|
632
|
+
if (!desktopAppPresent(env)) return { status: "skipped", reason: "no-desktop-app" };
|
|
633
|
+
if (!(0, import_node_fs3.existsSync)((0, import_node_path5.join)(source, ".claude-plugin", "marketplace.json")))
|
|
634
|
+
return { status: "skipped", reason: "no-package" };
|
|
635
|
+
const cp = claudePaths(env);
|
|
636
|
+
const p = pluginPaths(env);
|
|
637
|
+
const cenv = claudeEnv(env);
|
|
638
|
+
if (!runner(["--version"], cenv).ok) return { status: "skipped", reason: "no-claude-command" };
|
|
639
|
+
const failed = (reason) => {
|
|
640
|
+
uninstallPlugin(env, runner);
|
|
641
|
+
return { status: "error", reason };
|
|
642
|
+
};
|
|
643
|
+
try {
|
|
644
|
+
assertSafeTarget(cp.settingsPath, env);
|
|
645
|
+
(0, import_node_fs3.rmSync)(p.marketplaceDir, { recursive: true, force: true });
|
|
646
|
+
(0, import_node_fs3.cpSync)(source, p.marketplaceDir, { recursive: true });
|
|
647
|
+
(0, import_node_fs3.writeFileSync)(
|
|
648
|
+
(0, import_node_path5.join)(p.pluginDir, CONFIG_FILE),
|
|
649
|
+
`${JSON.stringify({ node: process.execPath, script: (0, import_node_path5.join)(cp.binDir, PLUGIN_SCRIPT) }, null, 2)}
|
|
650
|
+
`
|
|
651
|
+
);
|
|
652
|
+
const already = readPluginState(env) !== null && pluginRegistered(env);
|
|
653
|
+
if (already) return { status: "already-installed" };
|
|
654
|
+
const existed = (0, import_node_fs3.existsSync)(cp.settingsPath);
|
|
655
|
+
const original = existed ? (0, import_node_fs3.readFileSync)(cp.settingsPath) : Buffer.alloc(0);
|
|
656
|
+
if (existed) writeAtomic(p.backupPath, original);
|
|
657
|
+
const state = {
|
|
658
|
+
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
659
|
+
settingsPath: cp.settingsPath,
|
|
660
|
+
existed,
|
|
661
|
+
originalSha256: existed ? sha256(original) : null
|
|
662
|
+
};
|
|
663
|
+
writeAtomic(p.statePath, JSON.stringify(state, null, 2));
|
|
664
|
+
runner(["plugin", "marketplace", "remove", MARKETPLACE_NAME], cenv);
|
|
665
|
+
const added = runner(["plugin", "marketplace", "add", p.marketplaceDir], cenv);
|
|
666
|
+
if (!added.ok)
|
|
667
|
+
return failed(`claude plugin marketplace add failed: ${added.stderr.trim() || added.stdout.trim()}`);
|
|
668
|
+
const installed = runner(["plugin", "install", PLUGIN_ID, "--scope", "user"], cenv);
|
|
669
|
+
if (!installed.ok)
|
|
670
|
+
return failed(`claude plugin install failed: ${installed.stderr.trim() || installed.stdout.trim()}`);
|
|
671
|
+
return { status: "installed" };
|
|
672
|
+
} catch (err) {
|
|
673
|
+
return failed(err instanceof Error ? err.message : String(err));
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
function uninstallPlugin(env, runner = claudeRunner) {
|
|
677
|
+
const p = pluginPaths(env);
|
|
678
|
+
const state = readPluginState(env);
|
|
679
|
+
if (!state) return { status: "not-installed" };
|
|
680
|
+
try {
|
|
681
|
+
const target = state.settingsPath;
|
|
682
|
+
assertSafeTarget(target, env);
|
|
683
|
+
const cenv = claudeEnv(env);
|
|
684
|
+
const viaClaude = runner(["--version"], cenv).ok && runner(["plugin", "uninstall", PLUGIN_ID, "--scope", "user"], cenv).ok && runner(["plugin", "marketplace", "remove", MARKETPLACE_NAME], cenv).ok;
|
|
685
|
+
let status = viaClaude ? "restored-merged" : "removed";
|
|
686
|
+
const settings = (0, import_node_fs3.existsSync)(target) ? parseObject2((0, import_node_fs3.readFileSync)(target, "utf8")) : null;
|
|
687
|
+
if (settings) {
|
|
688
|
+
const cleaned = withoutOurs(settings, true);
|
|
689
|
+
const original = (0, import_node_fs3.existsSync)(p.backupPath) ? (0, import_node_fs3.readFileSync)(p.backupPath) : null;
|
|
690
|
+
const originalJson = original ? parseObject2(original.toString("utf8")) : null;
|
|
691
|
+
if (original && originalJson && sha256(original) === state.originalSha256 && canonical(withoutOurs(originalJson, false)) === canonical(cleaned)) {
|
|
692
|
+
writeAtomic(target, original);
|
|
693
|
+
status = "restored-exact";
|
|
694
|
+
} else if (!state.existed && Object.keys(cleaned).length === 0) {
|
|
695
|
+
(0, import_node_fs3.rmSync)(target);
|
|
696
|
+
status = "restored-exact";
|
|
697
|
+
} else if (canonical(cleaned) !== canonical(settings)) {
|
|
698
|
+
writeAtomic(target, `${JSON.stringify(cleaned, null, 2)}
|
|
699
|
+
`);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
(0, import_node_fs3.rmSync)(p.marketplaceDir, { recursive: true, force: true });
|
|
703
|
+
(0, import_node_fs3.rmSync)((0, import_node_path5.join)(claudePaths(env).claudeDir, "plugins", "cache", MARKETPLACE_NAME), {
|
|
704
|
+
recursive: true,
|
|
705
|
+
force: true
|
|
706
|
+
});
|
|
707
|
+
(0, import_node_fs3.rmSync)(p.backupPath, { force: true });
|
|
708
|
+
(0, import_node_fs3.rmSync)(p.statePath, { force: true });
|
|
709
|
+
return { status };
|
|
710
|
+
} catch (err) {
|
|
711
|
+
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
function pluginHealth(env = process.env) {
|
|
715
|
+
const p = pluginPaths(env);
|
|
716
|
+
let node = false;
|
|
717
|
+
try {
|
|
718
|
+
const config = JSON.parse((0, import_node_fs3.readFileSync)((0, import_node_path5.join)(p.pluginDir, CONFIG_FILE), "utf8"));
|
|
719
|
+
node = typeof config.node === "string" && (0, import_node_fs3.existsSync)(config.node) && typeof config.script === "string" && (0, import_node_fs3.existsSync)(config.script);
|
|
720
|
+
} catch {
|
|
721
|
+
}
|
|
722
|
+
return {
|
|
723
|
+
files: (0, import_node_fs3.existsSync)((0, import_node_path5.join)(p.pluginDir, "hooks", "register.tsx")) && (0, import_node_fs3.existsSync)((0, import_node_path5.join)(p.marketplaceDir, ".claude-plugin", "marketplace.json")),
|
|
724
|
+
registered: pluginRegistered(env),
|
|
725
|
+
node
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
532
729
|
// packages/core/src/engine.ts
|
|
533
730
|
var SESSION_STALE_MS = 6 * 60 * 6e4;
|
|
534
731
|
|
|
@@ -555,8 +752,8 @@ function isAlive(endpoint, timeoutMs = 300) {
|
|
|
555
752
|
}
|
|
556
753
|
|
|
557
754
|
// packages/core/src/manifest.ts
|
|
558
|
-
var
|
|
559
|
-
var
|
|
755
|
+
var import_node_fs4 = require("node:fs");
|
|
756
|
+
var import_node_path6 = require("node:path");
|
|
560
757
|
|
|
561
758
|
// packages/core/src/default-manifest.json
|
|
562
759
|
var default_manifest_default = {
|
|
@@ -624,11 +821,11 @@ var DEFAULT_DAILY_CAP = 60;
|
|
|
624
821
|
function str(v, max) {
|
|
625
822
|
return typeof v === "string" && v.length > 0 && v.length <= max ? v : void 0;
|
|
626
823
|
}
|
|
627
|
-
function
|
|
824
|
+
function isObject5(v) {
|
|
628
825
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
629
826
|
}
|
|
630
827
|
function parseCard(raw) {
|
|
631
|
-
if (!
|
|
828
|
+
if (!isObject5(raw)) return void 0;
|
|
632
829
|
const snippet = codeLines(raw.snippet);
|
|
633
830
|
const body = str(raw.body, 160);
|
|
634
831
|
const logo = str(raw.logoUrl, 300);
|
|
@@ -655,28 +852,28 @@ function idList(raw, re) {
|
|
|
655
852
|
return out.length ? out : void 0;
|
|
656
853
|
}
|
|
657
854
|
function parseTargets(raw) {
|
|
658
|
-
if (!
|
|
855
|
+
if (!isObject5(raw)) return void 0;
|
|
659
856
|
const agents = idList(raw.agents, /^[a-z0-9-]{1,32}$/);
|
|
660
857
|
const locales = idList(raw.locales, /^[a-z]{2}(-[A-Za-z]{2,4})?$/);
|
|
661
858
|
if (!agents && !locales) return void 0;
|
|
662
859
|
return { ...agents ? { agents } : {}, ...locales ? { locales } : {} };
|
|
663
860
|
}
|
|
664
861
|
function parseManifest(raw) {
|
|
665
|
-
if (!
|
|
862
|
+
if (!isObject5(raw) || !Array.isArray(raw.campaigns)) return null;
|
|
666
863
|
const campaigns = [];
|
|
667
864
|
for (const c of raw.campaigns) {
|
|
668
|
-
if (!
|
|
865
|
+
if (!isObject5(c) || !isObject5(c.creatives)) continue;
|
|
669
866
|
const id = str(c.id, 64);
|
|
670
867
|
const sponsorName = str(c.sponsorName, 40);
|
|
671
868
|
const pill = c.creatives.pillStatusline;
|
|
672
|
-
if (!id || !/^[A-Za-z0-9._-]+$/.test(id) || !sponsorName || !
|
|
869
|
+
if (!id || !/^[A-Za-z0-9._-]+$/.test(id) || !sponsorName || !isObject5(pill)) continue;
|
|
673
870
|
const copy = str(pill.copy, 120);
|
|
674
871
|
if (!copy) continue;
|
|
675
872
|
const actionUrl = str(pill.actionUrl, 300);
|
|
676
873
|
const locales = {};
|
|
677
|
-
if (
|
|
874
|
+
if (isObject5(c.creatives.locales)) {
|
|
678
875
|
for (const [lang, v] of Object.entries(c.creatives.locales)) {
|
|
679
|
-
if (!
|
|
876
|
+
if (!isObject5(v) || !/^[a-z]{2}(-[A-Z]{2})?$/.test(lang)) continue;
|
|
680
877
|
locales[lang] = { copy: str(v.copy, 120), ctaButton: str(v.ctaButton, 28) };
|
|
681
878
|
}
|
|
682
879
|
}
|
|
@@ -717,7 +914,7 @@ function parseManifest(raw) {
|
|
|
717
914
|
}
|
|
718
915
|
function readJson(file) {
|
|
719
916
|
try {
|
|
720
|
-
return JSON.parse((0,
|
|
917
|
+
return JSON.parse((0, import_node_fs4.readFileSync)(file, "utf8"));
|
|
721
918
|
} catch {
|
|
722
919
|
return null;
|
|
723
920
|
}
|
|
@@ -741,8 +938,8 @@ var ManifestStore = class {
|
|
|
741
938
|
/** Re-read from disk. Keeps the previous manifest if nothing valid is found. */
|
|
742
939
|
reload() {
|
|
743
940
|
const paths = avronPaths(this.env);
|
|
744
|
-
const dropIn = (0,
|
|
745
|
-
const override = this.env.AVRON_MANIFEST_FILE || ((0,
|
|
941
|
+
const dropIn = (0, import_node_path6.join)(paths.home, "manifest.override.json");
|
|
942
|
+
const override = this.env.AVRON_MANIFEST_FILE || ((0, import_node_fs4.existsSync)(dropIn) ? dropIn : void 0);
|
|
746
943
|
const sources = override ? [override] : [paths.manifestCache];
|
|
747
944
|
for (const file of sources) {
|
|
748
945
|
const parsed = parseManifest(readJson(file));
|
|
@@ -757,11 +954,11 @@ var ManifestStore = class {
|
|
|
757
954
|
|
|
758
955
|
// packages/core/src/identity.ts
|
|
759
956
|
var import_node_crypto3 = require("node:crypto");
|
|
760
|
-
var
|
|
761
|
-
var
|
|
957
|
+
var import_node_fs5 = require("node:fs");
|
|
958
|
+
var import_node_path7 = require("node:path");
|
|
762
959
|
var files = (paths) => ({
|
|
763
|
-
priv: (0,
|
|
764
|
-
pub: (0,
|
|
960
|
+
priv: (0, import_node_path7.join)(paths.keyDir, "private.key"),
|
|
961
|
+
pub: (0, import_node_path7.join)(paths.keyDir, "public.key")
|
|
765
962
|
});
|
|
766
963
|
function describe(publicKeyPem) {
|
|
767
964
|
const der = (0, import_node_crypto3.createPublicKey)(publicKeyPem).export({ type: "spki", format: "der" });
|
|
@@ -770,31 +967,31 @@ function describe(publicKeyPem) {
|
|
|
770
967
|
}
|
|
771
968
|
function loadIdentity(paths) {
|
|
772
969
|
try {
|
|
773
|
-
return describe((0,
|
|
970
|
+
return describe((0, import_node_fs5.readFileSync)(files(paths).pub, "utf8"));
|
|
774
971
|
} catch {
|
|
775
972
|
return null;
|
|
776
973
|
}
|
|
777
974
|
}
|
|
778
975
|
function ensureIdentity(paths) {
|
|
779
976
|
const f = files(paths);
|
|
780
|
-
if ((0,
|
|
977
|
+
if ((0, import_node_fs5.existsSync)(f.priv) && (0, import_node_fs5.existsSync)(f.pub)) {
|
|
781
978
|
const existing = loadIdentity(paths);
|
|
782
979
|
if (existing) return existing;
|
|
783
980
|
}
|
|
784
|
-
(0,
|
|
981
|
+
(0, import_node_fs5.mkdirSync)(paths.keyDir, { recursive: true });
|
|
785
982
|
const { privateKey, publicKey } = (0, import_node_crypto3.generateKeyPairSync)("ed25519");
|
|
786
983
|
const pub = publicKey.export({ type: "spki", format: "pem" }).toString();
|
|
787
|
-
(0,
|
|
788
|
-
(0,
|
|
984
|
+
(0, import_node_fs5.writeFileSync)(f.priv, privateKey.export({ type: "pkcs8", format: "pem" }).toString(), { mode: 384 });
|
|
985
|
+
(0, import_node_fs5.writeFileSync)(f.pub, pub);
|
|
789
986
|
if (process.platform !== "win32") {
|
|
790
|
-
(0,
|
|
791
|
-
(0,
|
|
987
|
+
(0, import_node_fs5.chmodSync)(paths.keyDir, 448);
|
|
988
|
+
(0, import_node_fs5.chmodSync)(f.priv, 384);
|
|
792
989
|
}
|
|
793
990
|
return describe(pub);
|
|
794
991
|
}
|
|
795
992
|
function signPayload(paths, payload) {
|
|
796
993
|
try {
|
|
797
|
-
const key = (0, import_node_crypto3.createPrivateKey)((0,
|
|
994
|
+
const key = (0, import_node_crypto3.createPrivateKey)((0, import_node_fs5.readFileSync)(files(paths).priv, "utf8"));
|
|
798
995
|
return (0, import_node_crypto3.sign)(null, Buffer.from(payload, "utf8"), key).toString("base64");
|
|
799
996
|
} catch {
|
|
800
997
|
return null;
|
|
@@ -808,7 +1005,7 @@ function exportIdentity(paths) {
|
|
|
808
1005
|
return {
|
|
809
1006
|
v: 1,
|
|
810
1007
|
installId: id.installId,
|
|
811
|
-
privateKeyPem: (0,
|
|
1008
|
+
privateKeyPem: (0, import_node_fs5.readFileSync)(f.priv, "utf8"),
|
|
812
1009
|
publicKeyPem: id.publicKeyPem
|
|
813
1010
|
};
|
|
814
1011
|
} catch {
|
|
@@ -831,19 +1028,19 @@ function importIdentity(paths, backup, force) {
|
|
|
831
1028
|
const incoming = describe(b.publicKeyPem);
|
|
832
1029
|
if (current && current.installId !== incoming.installId && !force) return { ok: false, reason: "exists" };
|
|
833
1030
|
const f = files(paths);
|
|
834
|
-
(0,
|
|
835
|
-
(0,
|
|
836
|
-
(0,
|
|
1031
|
+
(0, import_node_fs5.mkdirSync)(paths.keyDir, { recursive: true });
|
|
1032
|
+
(0, import_node_fs5.writeFileSync)(f.priv, b.privateKeyPem, { mode: 384 });
|
|
1033
|
+
(0, import_node_fs5.writeFileSync)(f.pub, b.publicKeyPem);
|
|
837
1034
|
if (process.platform !== "win32") {
|
|
838
|
-
(0,
|
|
839
|
-
(0,
|
|
1035
|
+
(0, import_node_fs5.chmodSync)(paths.keyDir, 448);
|
|
1036
|
+
(0, import_node_fs5.chmodSync)(f.priv, 384);
|
|
840
1037
|
}
|
|
841
1038
|
return { ok: true, identity: incoming };
|
|
842
1039
|
}
|
|
843
1040
|
|
|
844
1041
|
// packages/core/src/config.ts
|
|
845
|
-
var
|
|
846
|
-
var
|
|
1042
|
+
var import_node_fs6 = require("node:fs");
|
|
1043
|
+
var import_node_path8 = require("node:path");
|
|
847
1044
|
var DEFAULT_FORMATS = {
|
|
848
1045
|
card: true,
|
|
849
1046
|
codeLines: 3,
|
|
@@ -873,11 +1070,11 @@ function readFormats(raw) {
|
|
|
873
1070
|
};
|
|
874
1071
|
}
|
|
875
1072
|
function configPath(env = process.env) {
|
|
876
|
-
return (0,
|
|
1073
|
+
return (0, import_node_path8.join)(avronHome(env), "config.json");
|
|
877
1074
|
}
|
|
878
1075
|
function readConfig(env = process.env) {
|
|
879
1076
|
try {
|
|
880
|
-
const raw = JSON.parse((0,
|
|
1077
|
+
const raw = JSON.parse((0, import_node_fs6.readFileSync)(configPath(env), "utf8"));
|
|
881
1078
|
return {
|
|
882
1079
|
mode: raw.mode === "pill-statusline" ? raw.mode : DEFAULT_CONFIG.mode,
|
|
883
1080
|
paused: raw.paused === true,
|
|
@@ -890,18 +1087,18 @@ function readConfig(env = process.env) {
|
|
|
890
1087
|
function writeConfig(patch, env = process.env) {
|
|
891
1088
|
const next = { ...readConfig(env), ...patch };
|
|
892
1089
|
const file = configPath(env);
|
|
893
|
-
(0,
|
|
1090
|
+
(0, import_node_fs6.mkdirSync)((0, import_node_path8.dirname)(file), { recursive: true });
|
|
894
1091
|
const tmp = `${file}.tmp`;
|
|
895
|
-
(0,
|
|
1092
|
+
(0, import_node_fs6.writeFileSync)(tmp, `${JSON.stringify(next, null, 2)}
|
|
896
1093
|
`);
|
|
897
|
-
(0,
|
|
1094
|
+
(0, import_node_fs6.renameSync)(tmp, file);
|
|
898
1095
|
return next;
|
|
899
1096
|
}
|
|
900
1097
|
|
|
901
1098
|
// packages/core/src/sync.ts
|
|
902
1099
|
var import_node_crypto4 = require("node:crypto");
|
|
903
|
-
var
|
|
904
|
-
var
|
|
1100
|
+
var import_node_fs7 = require("node:fs");
|
|
1101
|
+
var import_node_path9 = require("node:path");
|
|
905
1102
|
var DEFAULT_API_BASE = "https://avron.dev";
|
|
906
1103
|
var MAX_EVENTS_PER_BATCH = 500;
|
|
907
1104
|
var HTTP_TIMEOUT_MS = 8e3;
|
|
@@ -918,11 +1115,11 @@ async function http(fetchImpl, url, timeoutMs, init) {
|
|
|
918
1115
|
clearTimeout(timer);
|
|
919
1116
|
}
|
|
920
1117
|
}
|
|
921
|
-
var statePath = (paths) => (0,
|
|
1118
|
+
var statePath = (paths) => (0, import_node_path9.join)(paths.dataDir, "sync-state.json");
|
|
922
1119
|
var count = (v) => typeof v === "number" && Number.isInteger(v) && v >= 0 ? v : void 0;
|
|
923
1120
|
function readState(paths) {
|
|
924
1121
|
try {
|
|
925
|
-
const s = JSON.parse((0,
|
|
1122
|
+
const s = JSON.parse((0, import_node_fs7.readFileSync)(statePath(paths), "utf8"));
|
|
926
1123
|
const accepted = count(s.accepted);
|
|
927
1124
|
const acceptedAt = count(s.acceptedAt);
|
|
928
1125
|
return {
|
|
@@ -941,23 +1138,23 @@ function serverCounted(paths) {
|
|
|
941
1138
|
function readPending(paths) {
|
|
942
1139
|
let size = 0;
|
|
943
1140
|
try {
|
|
944
|
-
size = (0,
|
|
1141
|
+
size = (0, import_node_fs7.statSync)(paths.impressionsLog).size;
|
|
945
1142
|
} catch {
|
|
946
1143
|
return { events: [], nextOffset: 0, size: 0 };
|
|
947
1144
|
}
|
|
948
1145
|
let offset = Math.min(readState(paths).offset, size);
|
|
949
|
-
const fd = (0,
|
|
1146
|
+
const fd = (0, import_node_fs7.openSync)(paths.impressionsLog, "r");
|
|
950
1147
|
try {
|
|
951
1148
|
if (size - offset > OFFLINE_QUEUE_MAX_BYTES) {
|
|
952
1149
|
offset = size - OFFLINE_QUEUE_MAX_BYTES;
|
|
953
1150
|
const probe = Buffer.alloc(4096);
|
|
954
|
-
const n = (0,
|
|
1151
|
+
const n = (0, import_node_fs7.readSync)(fd, probe, 0, probe.length, offset);
|
|
955
1152
|
const nl = probe.subarray(0, n).indexOf(10);
|
|
956
1153
|
offset += nl >= 0 ? nl + 1 : n;
|
|
957
1154
|
}
|
|
958
1155
|
const want = Math.min(size - offset, 512 * 1024);
|
|
959
1156
|
const buf = Buffer.alloc(want);
|
|
960
|
-
const got = (0,
|
|
1157
|
+
const got = (0, import_node_fs7.readSync)(fd, buf, 0, want, offset);
|
|
961
1158
|
const chunk = buf.subarray(0, got);
|
|
962
1159
|
const events = [];
|
|
963
1160
|
let consumed = 0;
|
|
@@ -985,7 +1182,7 @@ function readPending(paths) {
|
|
|
985
1182
|
}
|
|
986
1183
|
return { events, nextOffset: offset + consumed, size };
|
|
987
1184
|
} finally {
|
|
988
|
-
(0,
|
|
1185
|
+
(0, import_node_fs7.closeSync)(fd);
|
|
989
1186
|
}
|
|
990
1187
|
}
|
|
991
1188
|
function buildBatch(paths, nonce, now) {
|
|
@@ -1037,7 +1234,7 @@ async function postSigned(env, paths, path, purpose, extra = {}, fetchImpl = fet
|
|
|
1037
1234
|
}
|
|
1038
1235
|
|
|
1039
1236
|
// packages/core/src/toast.ts
|
|
1040
|
-
var
|
|
1237
|
+
var import_node_child_process3 = require("node:child_process");
|
|
1041
1238
|
var WINDOWS_APP_ID = "Avron.Notifier";
|
|
1042
1239
|
var WINDOWS_APP_KEY = `HKCU:\\Software\\Classes\\AppUserModelId\\${WINDOWS_APP_ID}`;
|
|
1043
1240
|
var WINDOWS_SCRIPT = [
|
|
@@ -1067,7 +1264,7 @@ var WINDOWS_SCRIPT = [
|
|
|
1067
1264
|
function removeToastRegistration(env = process.env) {
|
|
1068
1265
|
if (process.platform !== "win32" || env.AVRON_TEST) return;
|
|
1069
1266
|
try {
|
|
1070
|
-
(0,
|
|
1267
|
+
(0, import_node_child_process3.spawn)(
|
|
1071
1268
|
"powershell.exe",
|
|
1072
1269
|
[
|
|
1073
1270
|
"-NoProfile",
|
|
@@ -1094,6 +1291,7 @@ var bin_copies_default = {
|
|
|
1094
1291
|
var bin_entries_default = {
|
|
1095
1292
|
"avron-statusline": "packages/adapter-claude-code/src/statusline.ts",
|
|
1096
1293
|
"avron-hook": "packages/adapter-claude-code/src/hook.ts",
|
|
1294
|
+
"avron-claude-plugin": "packages/adapter-claude-code/src/plugin-bin.ts",
|
|
1097
1295
|
"avron-antigravity-hook": "packages/adapter-antigravity/src/hook.ts",
|
|
1098
1296
|
"avron-antigravity-statusline": "packages/adapter-antigravity/src/statusline.ts",
|
|
1099
1297
|
"avron-codex-hook": "packages/adapter-codex/src/hook.ts",
|
|
@@ -1109,38 +1307,38 @@ var bin_esm_entries_default = {
|
|
|
1109
1307
|
};
|
|
1110
1308
|
|
|
1111
1309
|
// packages/cli/src/adapters.ts
|
|
1112
|
-
var
|
|
1113
|
-
var
|
|
1114
|
-
var
|
|
1310
|
+
var import_node_fs12 = require("node:fs");
|
|
1311
|
+
var import_node_os10 = require("node:os");
|
|
1312
|
+
var import_node_path15 = require("node:path");
|
|
1115
1313
|
|
|
1116
1314
|
// packages/adapter-antigravity/src/install.ts
|
|
1117
|
-
var
|
|
1118
|
-
var
|
|
1119
|
-
var
|
|
1315
|
+
var import_node_fs8 = require("node:fs");
|
|
1316
|
+
var import_node_os5 = require("node:os");
|
|
1317
|
+
var import_node_path10 = require("node:path");
|
|
1120
1318
|
var HOOK_SCRIPT2 = "avron-antigravity-hook.cjs";
|
|
1121
1319
|
var STATUSLINE_SCRIPT2 = "avron-antigravity-statusline.cjs";
|
|
1122
1320
|
var GROUP = "avron";
|
|
1123
1321
|
var HOOK_EVENTS2 = { PreInvocation: "busy", Stop: "idle" };
|
|
1124
1322
|
var TIMEOUT_SEC = 3;
|
|
1125
1323
|
function geminiDir(env = process.env) {
|
|
1126
|
-
return env.AVRON_ANTIGRAVITY_DIR || (0,
|
|
1324
|
+
return env.AVRON_ANTIGRAVITY_DIR || (0, import_node_path10.join)((0, import_node_os5.homedir)(), ".gemini");
|
|
1127
1325
|
}
|
|
1128
1326
|
function antigravityPaths(env = process.env) {
|
|
1129
1327
|
const dir = geminiDir(env);
|
|
1130
1328
|
const home = avronHome(env);
|
|
1131
1329
|
return {
|
|
1132
1330
|
geminiDir: dir,
|
|
1133
|
-
hooksFile: (0,
|
|
1134
|
-
settingsFile: (0,
|
|
1135
|
-
hooksState: (0,
|
|
1136
|
-
settingsState: (0,
|
|
1137
|
-
binDir: (0,
|
|
1331
|
+
hooksFile: (0, import_node_path10.join)(dir, "config", "hooks.json"),
|
|
1332
|
+
settingsFile: (0, import_node_path10.join)(dir, "antigravity-cli", "settings.json"),
|
|
1333
|
+
hooksState: (0, import_node_path10.join)(home, "adapters", "antigravity-hooks.json"),
|
|
1334
|
+
settingsState: (0, import_node_path10.join)(home, "adapters", "antigravity-cli.json"),
|
|
1335
|
+
binDir: (0, import_node_path10.join)(home, "bin")
|
|
1138
1336
|
};
|
|
1139
1337
|
}
|
|
1140
1338
|
var isOurCommand2 = (command) => typeof command === "string" && (command.includes(HOOK_SCRIPT2) || command.includes(STATUSLINE_SCRIPT2));
|
|
1141
1339
|
function scriptCommand(binDir, script, args = "", platform = process.platform) {
|
|
1142
1340
|
const tail = args ? ` ${args}` : "";
|
|
1143
|
-
const path = (0,
|
|
1341
|
+
const path = (0, import_node_path10.join)(binDir, script).replace(/\\/g, "/");
|
|
1144
1342
|
if (platform !== "win32") return `node "${path}"${tail}`;
|
|
1145
1343
|
if (!/[\s"&|<>^%()]/.test(path)) return `node ${path}${tail}`;
|
|
1146
1344
|
return `cd /d ${binDir.replace(/\//g, "\\")} && node ${script}${tail}`;
|
|
@@ -1198,8 +1396,8 @@ function removeStatusLine(text, extra) {
|
|
|
1198
1396
|
function guard2(target, env) {
|
|
1199
1397
|
assertSafeTarget(target, env);
|
|
1200
1398
|
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1201
|
-
const real = (0,
|
|
1202
|
-
if ((0,
|
|
1399
|
+
const real = (0, import_node_path10.resolve)((0, import_node_path10.join)((0, import_node_os5.homedir)(), ".gemini")).toLowerCase();
|
|
1400
|
+
if ((0, import_node_path10.resolve)(target).toLowerCase().startsWith(real))
|
|
1203
1401
|
throw new Error("refusing to modify the real ~/.gemini directory from a test");
|
|
1204
1402
|
}
|
|
1205
1403
|
}
|
|
@@ -1214,7 +1412,7 @@ function installAntigravity(env = process.env) {
|
|
|
1214
1412
|
guard2(p.settingsFile, env);
|
|
1215
1413
|
injectHooks(readOr(p.hooksFile), p.binDir);
|
|
1216
1414
|
injectStatusLine(readOr(p.settingsFile), p.binDir);
|
|
1217
|
-
const createdDir = !(0,
|
|
1415
|
+
const createdDir = !(0, import_node_fs8.existsSync)((0, import_node_path10.dirname)(p.hooksFile));
|
|
1218
1416
|
const hooks = applyEdit({ target: p.hooksFile, statePath: p.hooksState }, (text) => ({
|
|
1219
1417
|
...injectHooks(text, p.binDir),
|
|
1220
1418
|
extra: { createdDir }
|
|
@@ -1245,7 +1443,7 @@ function uninstallAntigravity(env = process.env) {
|
|
|
1245
1443
|
(text) => removeHooks(text),
|
|
1246
1444
|
(target) => guard2(target, env)
|
|
1247
1445
|
);
|
|
1248
|
-
if (createdDir) rmEmptyDir((0,
|
|
1446
|
+
if (createdDir) rmEmptyDir((0, import_node_path10.dirname)(hooks.target));
|
|
1249
1447
|
const all = [hooks.status, settings.status];
|
|
1250
1448
|
const status = all.every((s) => s === "not-installed") ? "not-installed" : all.includes("restored-merged") ? "restored-merged" : "restored-exact";
|
|
1251
1449
|
return { status, files: [hooks.target, settings.target] };
|
|
@@ -1255,21 +1453,21 @@ function uninstallAntigravity(env = process.env) {
|
|
|
1255
1453
|
}
|
|
1256
1454
|
function readOr(file) {
|
|
1257
1455
|
try {
|
|
1258
|
-
return (0,
|
|
1456
|
+
return (0, import_node_fs8.readFileSync)(file, "utf8");
|
|
1259
1457
|
} catch {
|
|
1260
1458
|
return "";
|
|
1261
1459
|
}
|
|
1262
1460
|
}
|
|
1263
1461
|
function rmEmptyDir(dir) {
|
|
1264
1462
|
try {
|
|
1265
|
-
if ((0,
|
|
1463
|
+
if ((0, import_node_fs8.readdirSync)(dir).length === 0) (0, import_node_fs8.rmdirSync)(dir);
|
|
1266
1464
|
} catch {
|
|
1267
1465
|
}
|
|
1268
1466
|
}
|
|
1269
1467
|
|
|
1270
1468
|
// packages/adapter-codex/src/install.ts
|
|
1271
|
-
var
|
|
1272
|
-
var
|
|
1469
|
+
var import_node_os6 = require("node:os");
|
|
1470
|
+
var import_node_path11 = require("node:path");
|
|
1273
1471
|
var HOOK_SCRIPT3 = "avron-codex-hook.cjs";
|
|
1274
1472
|
var HOOK_EVENTS3 = {
|
|
1275
1473
|
UserPromptSubmit: "busy",
|
|
@@ -1282,21 +1480,21 @@ var HOOK_EVENTS3 = {
|
|
|
1282
1480
|
};
|
|
1283
1481
|
var TIMEOUT_SEC2 = 3;
|
|
1284
1482
|
function codexDir(env = process.env) {
|
|
1285
|
-
return env.AVRON_CODEX_DIR || env.CODEX_HOME || (0,
|
|
1483
|
+
return env.AVRON_CODEX_DIR || env.CODEX_HOME || (0, import_node_path11.join)((0, import_node_os6.homedir)(), ".codex");
|
|
1286
1484
|
}
|
|
1287
1485
|
function codexPaths(env = process.env) {
|
|
1288
1486
|
const dir = codexDir(env);
|
|
1289
1487
|
const home = avronHome(env);
|
|
1290
1488
|
return {
|
|
1291
1489
|
codexDir: dir,
|
|
1292
|
-
hooksFile: (0,
|
|
1293
|
-
statePath: (0,
|
|
1294
|
-
binDir: (0,
|
|
1490
|
+
hooksFile: (0, import_node_path11.join)(dir, "hooks.json"),
|
|
1491
|
+
statePath: (0, import_node_path11.join)(home, "adapters", "codex.json"),
|
|
1492
|
+
binDir: (0, import_node_path11.join)(home, "bin")
|
|
1295
1493
|
};
|
|
1296
1494
|
}
|
|
1297
1495
|
var isOurCommand3 = (command) => typeof command === "string" && command.includes(HOOK_SCRIPT3);
|
|
1298
1496
|
function hookCommand3(binDir, arg) {
|
|
1299
|
-
return `node "${(0,
|
|
1497
|
+
return `node "${(0, import_node_path11.join)(binDir, HOOK_SCRIPT3).replace(/\\/g, "/")}" ${arg}`;
|
|
1300
1498
|
}
|
|
1301
1499
|
function groupIsOurs2(group) {
|
|
1302
1500
|
if (!isObject3(group) || !Array.isArray(group.hooks) || group.hooks.length === 0) return false;
|
|
@@ -1340,8 +1538,8 @@ function remove2(text) {
|
|
|
1340
1538
|
function guard3(target, env) {
|
|
1341
1539
|
assertSafeTarget(target, env);
|
|
1342
1540
|
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1343
|
-
const real = (0,
|
|
1344
|
-
if ((0,
|
|
1541
|
+
const real = (0, import_node_path11.resolve)((0, import_node_path11.join)((0, import_node_os6.homedir)(), ".codex")).toLowerCase();
|
|
1542
|
+
if ((0, import_node_path11.resolve)(target).toLowerCase().startsWith(real))
|
|
1345
1543
|
throw new Error("refusing to modify the real ~/.codex directory from a test");
|
|
1346
1544
|
}
|
|
1347
1545
|
}
|
|
@@ -1377,9 +1575,9 @@ function uninstallCodex(env = process.env) {
|
|
|
1377
1575
|
}
|
|
1378
1576
|
|
|
1379
1577
|
// packages/adapter-copilot/src/install.ts
|
|
1380
|
-
var
|
|
1381
|
-
var
|
|
1382
|
-
var
|
|
1578
|
+
var import_node_fs9 = require("node:fs");
|
|
1579
|
+
var import_node_os7 = require("node:os");
|
|
1580
|
+
var import_node_path12 = require("node:path");
|
|
1383
1581
|
var HOOK_SCRIPT4 = "avron-copilot-hook.cjs";
|
|
1384
1582
|
var HOOKS_FILE = "avron.json";
|
|
1385
1583
|
var HOOK_EVENTS4 = {
|
|
@@ -1389,25 +1587,25 @@ var HOOK_EVENTS4 = {
|
|
|
1389
1587
|
};
|
|
1390
1588
|
var TIMEOUT_SEC3 = 5;
|
|
1391
1589
|
function copilotDir(env = process.env) {
|
|
1392
|
-
return env.AVRON_COPILOT_DIR || env.COPILOT_HOME || (0,
|
|
1590
|
+
return env.AVRON_COPILOT_DIR || env.COPILOT_HOME || (0, import_node_path12.join)((0, import_node_os7.homedir)(), ".copilot");
|
|
1393
1591
|
}
|
|
1394
1592
|
function copilotPaths(env = process.env) {
|
|
1395
1593
|
const dir = copilotDir(env);
|
|
1396
1594
|
const home = avronHome(env);
|
|
1397
1595
|
return {
|
|
1398
1596
|
copilotDir: dir,
|
|
1399
|
-
hooksDir: (0,
|
|
1400
|
-
hooksFile: (0,
|
|
1401
|
-
statePath: (0,
|
|
1402
|
-
settingsFile: (0,
|
|
1403
|
-
settingsState: (0,
|
|
1404
|
-
binDir: (0,
|
|
1597
|
+
hooksDir: (0, import_node_path12.join)(dir, "hooks"),
|
|
1598
|
+
hooksFile: (0, import_node_path12.join)(dir, "hooks", HOOKS_FILE),
|
|
1599
|
+
statePath: (0, import_node_path12.join)(home, "adapters", "copilot.json"),
|
|
1600
|
+
settingsFile: (0, import_node_path12.join)(dir, "settings.json"),
|
|
1601
|
+
settingsState: (0, import_node_path12.join)(home, "adapters", "copilot-cli.json"),
|
|
1602
|
+
binDir: (0, import_node_path12.join)(home, "bin")
|
|
1405
1603
|
};
|
|
1406
1604
|
}
|
|
1407
1605
|
var STATUSLINE_SCRIPT3 = "avron-copilot-statusline.cjs";
|
|
1408
1606
|
var REFRESH_SEC = 1;
|
|
1409
1607
|
var isOurCommand4 = (command) => typeof command === "string" && (command.includes(HOOK_SCRIPT4) || command.includes(STATUSLINE_SCRIPT3));
|
|
1410
|
-
var statuslineCommand3 = (binDir) => `node "${(0,
|
|
1608
|
+
var statuslineCommand3 = (binDir) => `node "${(0, import_node_path12.join)(binDir, STATUSLINE_SCRIPT3).replace(/\\/g, "/")}"`;
|
|
1411
1609
|
function injectStatusLine2(text, binDir) {
|
|
1412
1610
|
const file = parseObject(text, "settings.json");
|
|
1413
1611
|
const current = file.statusLine;
|
|
@@ -1434,7 +1632,7 @@ function removeStatusLine2(text, extra) {
|
|
|
1434
1632
|
return { text: stringifyStyled(file, detectStyle2(text)), changed: true };
|
|
1435
1633
|
}
|
|
1436
1634
|
function hooksFileText(binDir) {
|
|
1437
|
-
const script = (0,
|
|
1635
|
+
const script = (0, import_node_path12.join)(binDir, HOOK_SCRIPT4).replace(/\\/g, "/");
|
|
1438
1636
|
const hooks = {};
|
|
1439
1637
|
for (const [event, arg] of Object.entries(HOOK_EVENTS4)) {
|
|
1440
1638
|
const command = `node "${script}" ${arg}`;
|
|
@@ -1446,8 +1644,8 @@ function hooksFileText(binDir) {
|
|
|
1446
1644
|
function guard4(target, env) {
|
|
1447
1645
|
assertSafeTarget(target, env);
|
|
1448
1646
|
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1449
|
-
const real = (0,
|
|
1450
|
-
if ((0,
|
|
1647
|
+
const real = (0, import_node_path12.resolve)((0, import_node_path12.join)((0, import_node_os7.homedir)(), ".copilot")).toLowerCase();
|
|
1648
|
+
if ((0, import_node_path12.resolve)(target).toLowerCase().startsWith(real))
|
|
1451
1649
|
throw new Error("refusing to modify the real ~/.copilot directory from a test");
|
|
1452
1650
|
}
|
|
1453
1651
|
}
|
|
@@ -1456,7 +1654,7 @@ function readInstallState4(env = process.env) {
|
|
|
1456
1654
|
}
|
|
1457
1655
|
function readOr2(file) {
|
|
1458
1656
|
try {
|
|
1459
|
-
return (0,
|
|
1657
|
+
return (0, import_node_fs9.readFileSync)(file, "utf8");
|
|
1460
1658
|
} catch {
|
|
1461
1659
|
return "";
|
|
1462
1660
|
}
|
|
@@ -1467,7 +1665,7 @@ function installCopilot(env = process.env) {
|
|
|
1467
1665
|
guard4(p.hooksFile, env);
|
|
1468
1666
|
guard4(p.settingsFile, env);
|
|
1469
1667
|
injectStatusLine2(readOr2(p.settingsFile), p.binDir);
|
|
1470
|
-
const createdDirs = [p.hooksDir, p.copilotDir].filter((d) => !(0,
|
|
1668
|
+
const createdDirs = [p.hooksDir, p.copilotDir].filter((d) => !(0, import_node_fs9.existsSync)(d));
|
|
1471
1669
|
const wanted = hooksFileText(p.binDir);
|
|
1472
1670
|
const res = applyEdit({ target: p.hooksFile, statePath: p.statePath }, (text) => ({
|
|
1473
1671
|
changed: text !== wanted,
|
|
@@ -1500,7 +1698,7 @@ function uninstallCopilot(env = process.env) {
|
|
|
1500
1698
|
() => ({ changed: false, text: "" }),
|
|
1501
1699
|
(target) => guard4(target, env)
|
|
1502
1700
|
);
|
|
1503
|
-
if (res.status === "restored-merged" && (0,
|
|
1701
|
+
if (res.status === "restored-merged" && (0, import_node_fs9.existsSync)(res.target) && state && !state.existed)
|
|
1504
1702
|
removeIfOurs(res.target);
|
|
1505
1703
|
for (const dir of state?.createdDirs ?? []) removeIfEmpty(dir);
|
|
1506
1704
|
const all = [res.status, settings.status];
|
|
@@ -1512,21 +1710,21 @@ function uninstallCopilot(env = process.env) {
|
|
|
1512
1710
|
}
|
|
1513
1711
|
function removeIfOurs(file) {
|
|
1514
1712
|
try {
|
|
1515
|
-
if (isOurCommand4((0,
|
|
1713
|
+
if (isOurCommand4((0, import_node_fs9.readFileSync)(file, "utf8"))) (0, import_node_fs9.rmSync)(file);
|
|
1516
1714
|
} catch {
|
|
1517
1715
|
}
|
|
1518
1716
|
}
|
|
1519
1717
|
function removeIfEmpty(dir) {
|
|
1520
1718
|
try {
|
|
1521
|
-
if ((0,
|
|
1719
|
+
if ((0, import_node_fs9.existsSync)(dir) && (0, import_node_fs9.readdirSync)(dir).length === 0) (0, import_node_fs9.rmdirSync)(dir);
|
|
1522
1720
|
} catch {
|
|
1523
1721
|
}
|
|
1524
1722
|
}
|
|
1525
1723
|
|
|
1526
1724
|
// packages/adapter-cursor/src/install.ts
|
|
1527
|
-
var
|
|
1528
|
-
var
|
|
1529
|
-
var
|
|
1725
|
+
var import_node_fs10 = require("node:fs");
|
|
1726
|
+
var import_node_os8 = require("node:os");
|
|
1727
|
+
var import_node_path13 = require("node:path");
|
|
1530
1728
|
var HOOK_SCRIPT5 = "avron-cursor-hook.cjs";
|
|
1531
1729
|
var HOOK_EVENTS5 = {
|
|
1532
1730
|
beforeSubmitPrompt: "busy",
|
|
@@ -1535,21 +1733,21 @@ var HOOK_EVENTS5 = {
|
|
|
1535
1733
|
};
|
|
1536
1734
|
var TIMEOUT_SEC4 = 5;
|
|
1537
1735
|
function cursorDir(env = process.env) {
|
|
1538
|
-
return env.AVRON_CURSOR_DIR || (0,
|
|
1736
|
+
return env.AVRON_CURSOR_DIR || (0, import_node_path13.join)((0, import_node_os8.homedir)(), ".cursor");
|
|
1539
1737
|
}
|
|
1540
1738
|
function cursorPaths(env = process.env) {
|
|
1541
1739
|
const dir = cursorDir(env);
|
|
1542
1740
|
const home = avronHome(env);
|
|
1543
1741
|
return {
|
|
1544
1742
|
cursorDir: dir,
|
|
1545
|
-
hooksFile: (0,
|
|
1546
|
-
statePath: (0,
|
|
1547
|
-
binDir: (0,
|
|
1743
|
+
hooksFile: (0, import_node_path13.join)(dir, "hooks.json"),
|
|
1744
|
+
statePath: (0, import_node_path13.join)(home, "adapters", "cursor.json"),
|
|
1745
|
+
binDir: (0, import_node_path13.join)(home, "bin")
|
|
1548
1746
|
};
|
|
1549
1747
|
}
|
|
1550
1748
|
var isOurCommand5 = (command) => typeof command === "string" && command.includes(HOOK_SCRIPT5);
|
|
1551
1749
|
function hookCommand4(binDir, arg) {
|
|
1552
|
-
return `node "${(0,
|
|
1750
|
+
return `node "${(0, import_node_path13.join)(binDir, HOOK_SCRIPT5).replace(/\\/g, "/")}" ${arg}`;
|
|
1553
1751
|
}
|
|
1554
1752
|
function inject3(text, binDir) {
|
|
1555
1753
|
const file = parseObject(text, "hooks.json");
|
|
@@ -1588,8 +1786,8 @@ function remove3(text) {
|
|
|
1588
1786
|
function guard5(target, env) {
|
|
1589
1787
|
assertSafeTarget(target, env);
|
|
1590
1788
|
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1591
|
-
const real = (0,
|
|
1592
|
-
if ((0,
|
|
1789
|
+
const real = (0, import_node_path13.resolve)((0, import_node_path13.join)((0, import_node_os8.homedir)(), ".cursor")).toLowerCase();
|
|
1790
|
+
if ((0, import_node_path13.resolve)(target).toLowerCase().startsWith(real))
|
|
1593
1791
|
throw new Error("refusing to modify the real ~/.cursor directory from a test");
|
|
1594
1792
|
}
|
|
1595
1793
|
}
|
|
@@ -1600,7 +1798,7 @@ function installCursor(env = process.env) {
|
|
|
1600
1798
|
const p = cursorPaths(env);
|
|
1601
1799
|
try {
|
|
1602
1800
|
guard5(p.hooksFile, env);
|
|
1603
|
-
const createdDirs = [p.cursorDir].filter((d) => !(0,
|
|
1801
|
+
const createdDirs = [p.cursorDir].filter((d) => !(0, import_node_fs10.existsSync)(d));
|
|
1604
1802
|
const res = applyEdit({ target: p.hooksFile, statePath: p.statePath }, (text) => ({
|
|
1605
1803
|
...inject3(text, p.binDir),
|
|
1606
1804
|
extra: { createdDirs }
|
|
@@ -1622,7 +1820,7 @@ function uninstallCursor(env = process.env) {
|
|
|
1622
1820
|
);
|
|
1623
1821
|
for (const dir of state?.createdDirs ?? []) {
|
|
1624
1822
|
try {
|
|
1625
|
-
if ((0,
|
|
1823
|
+
if ((0, import_node_fs10.existsSync)(dir) && (0, import_node_fs10.readdirSync)(dir).length === 0) (0, import_node_fs10.rmdirSync)(dir);
|
|
1626
1824
|
} catch {
|
|
1627
1825
|
}
|
|
1628
1826
|
}
|
|
@@ -1633,26 +1831,26 @@ function uninstallCursor(env = process.env) {
|
|
|
1633
1831
|
}
|
|
1634
1832
|
|
|
1635
1833
|
// packages/adapter-opencode/src/install.ts
|
|
1636
|
-
var
|
|
1637
|
-
var
|
|
1638
|
-
var
|
|
1834
|
+
var import_node_fs11 = require("node:fs");
|
|
1835
|
+
var import_node_os9 = require("node:os");
|
|
1836
|
+
var import_node_path14 = require("node:path");
|
|
1639
1837
|
var import_node_url = require("node:url");
|
|
1640
1838
|
var PLUGIN_FILE = "avron-opencode.tsx";
|
|
1641
1839
|
function opencodeDir(env = process.env) {
|
|
1642
1840
|
if (env.AVRON_OPENCODE_DIR) return env.AVRON_OPENCODE_DIR;
|
|
1643
|
-
return (0,
|
|
1841
|
+
return (0, import_node_path14.join)(env.XDG_CONFIG_HOME || (0, import_node_path14.join)((0, import_node_os9.homedir)(), ".config"), "opencode");
|
|
1644
1842
|
}
|
|
1645
1843
|
function opencodePaths(env = process.env) {
|
|
1646
1844
|
const dir = opencodeDir(env);
|
|
1647
1845
|
const home = avronHome(env);
|
|
1648
1846
|
return {
|
|
1649
1847
|
configDir: dir,
|
|
1650
|
-
tuiFile: (0,
|
|
1651
|
-
statePath: (0,
|
|
1652
|
-
binDir: (0,
|
|
1848
|
+
tuiFile: (0, import_node_path14.join)(dir, "tui.json"),
|
|
1849
|
+
statePath: (0, import_node_path14.join)(home, "adapters", "opencode.json"),
|
|
1850
|
+
binDir: (0, import_node_path14.join)(home, "bin")
|
|
1653
1851
|
};
|
|
1654
1852
|
}
|
|
1655
|
-
var pluginEntry = (binDir) => (0, import_node_url.pathToFileURL)((0,
|
|
1853
|
+
var pluginEntry = (binDir) => (0, import_node_url.pathToFileURL)((0, import_node_path14.join)(binDir, PLUGIN_FILE)).href;
|
|
1656
1854
|
var isOurEntry = (entry) => typeof entry === "string" && entry.replace(/\\/g, "/").endsWith(`/${PLUGIN_FILE}`);
|
|
1657
1855
|
function inject4(text, binDir) {
|
|
1658
1856
|
const file = parseObject(text, "tui.json");
|
|
@@ -1673,8 +1871,8 @@ function remove4(text) {
|
|
|
1673
1871
|
function guard6(target, env) {
|
|
1674
1872
|
assertSafeTarget(target, env);
|
|
1675
1873
|
if (env.AVRON_TEST === "1" || env.VITEST !== void 0) {
|
|
1676
|
-
const real = (0,
|
|
1677
|
-
if ((0,
|
|
1874
|
+
const real = (0, import_node_path14.resolve)((0, import_node_path14.join)((0, import_node_os9.homedir)(), ".config", "opencode")).toLowerCase();
|
|
1875
|
+
if ((0, import_node_path14.resolve)(target).toLowerCase().startsWith(real))
|
|
1678
1876
|
throw new Error("refusing to modify the real ~/.config/opencode directory from a test");
|
|
1679
1877
|
}
|
|
1680
1878
|
}
|
|
@@ -1685,7 +1883,7 @@ function installOpencode(env = process.env) {
|
|
|
1685
1883
|
const p = opencodePaths(env);
|
|
1686
1884
|
try {
|
|
1687
1885
|
guard6(p.tuiFile, env);
|
|
1688
|
-
const createdDir = !(0,
|
|
1886
|
+
const createdDir = !(0, import_node_fs11.existsSync)(p.configDir);
|
|
1689
1887
|
const res = applyEdit({ target: p.tuiFile, statePath: p.statePath }, (text) => ({
|
|
1690
1888
|
...inject4(text, p.binDir),
|
|
1691
1889
|
extra: { createdDir }
|
|
@@ -1705,7 +1903,7 @@ function uninstallOpencode(env = process.env) {
|
|
|
1705
1903
|
(text) => remove4(text),
|
|
1706
1904
|
(target) => guard6(target, env)
|
|
1707
1905
|
);
|
|
1708
|
-
if (createdDir) rmEmptyDir2((0,
|
|
1906
|
+
if (createdDir) rmEmptyDir2((0, import_node_path14.dirname)(res.target));
|
|
1709
1907
|
return { status: res.status, tuiFile: res.target };
|
|
1710
1908
|
} catch (err) {
|
|
1711
1909
|
return { status: "error", reason: err instanceof Error ? err.message : String(err) };
|
|
@@ -1713,13 +1911,13 @@ function uninstallOpencode(env = process.env) {
|
|
|
1713
1911
|
}
|
|
1714
1912
|
function rmEmptyDir2(dir) {
|
|
1715
1913
|
try {
|
|
1716
|
-
if ((0,
|
|
1914
|
+
if ((0, import_node_fs11.readdirSync)(dir).length === 0) (0, import_node_fs11.rmdirSync)(dir);
|
|
1717
1915
|
} catch {
|
|
1718
1916
|
}
|
|
1719
1917
|
}
|
|
1720
1918
|
function pluginListed(env = process.env) {
|
|
1721
1919
|
try {
|
|
1722
|
-
const file = JSON.parse((0,
|
|
1920
|
+
const file = JSON.parse((0, import_node_fs11.readFileSync)(opencodePaths(env).tuiFile, "utf8"));
|
|
1723
1921
|
return Array.isArray(file.plugin) && file.plugin.some(isOurEntry);
|
|
1724
1922
|
} catch {
|
|
1725
1923
|
return false;
|
|
@@ -1733,9 +1931,9 @@ var claudeCode = {
|
|
|
1733
1931
|
name: "Claude Code",
|
|
1734
1932
|
detect(env) {
|
|
1735
1933
|
const cp = claudePaths(env);
|
|
1736
|
-
return (0,
|
|
1934
|
+
return (0, import_node_fs12.existsSync)(cp.claudeDir) ? cp.settingsPath : null;
|
|
1737
1935
|
},
|
|
1738
|
-
install(env, out) {
|
|
1936
|
+
install(env, out, ctx) {
|
|
1739
1937
|
out("\u25B8 Backing up configuration:");
|
|
1740
1938
|
const res = installClaudeCode(env);
|
|
1741
1939
|
if (res.status === "error") {
|
|
@@ -1750,9 +1948,40 @@ var claudeCode = {
|
|
|
1750
1948
|
out(
|
|
1751
1949
|
res.status === "installed" ? " [OK] Claude Code adapter injected" : " [OK] Claude Code adapter already present"
|
|
1752
1950
|
);
|
|
1951
|
+
if (ctx) {
|
|
1952
|
+
const plugin = installPlugin(env, (0, import_node_path15.join)((0, import_node_path15.dirname)(ctx.binSource), "claude-plugin"));
|
|
1953
|
+
if (plugin.status === "installed" || plugin.status === "already-installed") {
|
|
1954
|
+
out("\u25B8 Adding the Claude desktop app plugin:");
|
|
1955
|
+
out(
|
|
1956
|
+
plugin.status === "installed" ? " [OK] Avron plugin registered with `claude plugin` (the desktop app shows the line through it)" : " [OK] Avron plugin already present"
|
|
1957
|
+
);
|
|
1958
|
+
} else if (plugin.status === "skipped" && plugin.reason === "no-claude-command") {
|
|
1959
|
+
out("\u25B8 Claude desktop app:");
|
|
1960
|
+
out(" [--] Found, but the 'claude' command is not on your PATH, so its plugin was not added");
|
|
1961
|
+
} else if (plugin.status === "error") {
|
|
1962
|
+
out("\u25B8 Adding the Claude desktop app plugin:");
|
|
1963
|
+
out(` [!!] Could not add it: ${plugin.reason}`);
|
|
1964
|
+
out(" Nothing of the plugin was left behind. Claude Code itself is set up.");
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1753
1967
|
return true;
|
|
1754
1968
|
},
|
|
1755
1969
|
uninstall(env, out) {
|
|
1970
|
+
const plugin = uninstallPlugin(env);
|
|
1971
|
+
if (plugin.status === "error") {
|
|
1972
|
+
out(` [!!] Could not remove the Claude desktop app plugin: ${plugin.reason}`);
|
|
1973
|
+
return false;
|
|
1974
|
+
}
|
|
1975
|
+
if (plugin.status !== "not-installed") {
|
|
1976
|
+
out("\u25B8 Removing the Claude desktop app plugin:");
|
|
1977
|
+
out(
|
|
1978
|
+
{
|
|
1979
|
+
"restored-exact": " [OK] Avron plugin removed; settings.json is as the hooks left it",
|
|
1980
|
+
"restored-merged": " [OK] Avron plugin removed; other edits to settings.json were kept",
|
|
1981
|
+
removed: " [OK] Avron plugin removed (the 'claude' command was not available)"
|
|
1982
|
+
}[plugin.status]
|
|
1983
|
+
);
|
|
1984
|
+
}
|
|
1756
1985
|
out("\u25B8 Restoring Claude Code settings:");
|
|
1757
1986
|
const res = uninstallClaudeCode(env);
|
|
1758
1987
|
if (res.status === "error") {
|
|
@@ -1772,7 +2001,7 @@ var claudeCode = {
|
|
|
1772
2001
|
let wrapped = false;
|
|
1773
2002
|
let hooks = 0;
|
|
1774
2003
|
try {
|
|
1775
|
-
const s = parseSettings((0,
|
|
2004
|
+
const s = parseSettings((0, import_node_fs12.readFileSync)(claudePaths(env).settingsPath, "utf8"));
|
|
1776
2005
|
wrapped = isOurCommand(s.statusLine?.command);
|
|
1777
2006
|
const h = s.hooks ?? {};
|
|
1778
2007
|
for (const ev of Object.keys(HOOK_EVENTS)) {
|
|
@@ -1792,6 +2021,19 @@ var claudeCode = {
|
|
|
1792
2021
|
);
|
|
1793
2022
|
if (readInstallState(env)?.hadStatusLine)
|
|
1794
2023
|
out(" [OK] Your original status line is preserved and still runs");
|
|
2024
|
+
if (readPluginState(env)) {
|
|
2025
|
+
const h = pluginHealth(env);
|
|
2026
|
+
check(
|
|
2027
|
+
h.files && h.registered,
|
|
2028
|
+
"Claude desktop app plugin is registered",
|
|
2029
|
+
"Claude desktop app plugin is not registered (run 'npx @wbcode/avron install')"
|
|
2030
|
+
);
|
|
2031
|
+
check(
|
|
2032
|
+
h.node,
|
|
2033
|
+
"Claude desktop app plugin finds Node.js and its helper script",
|
|
2034
|
+
"Claude desktop app plugin cannot find Node.js or its helper (run 'npx @wbcode/avron install' again)"
|
|
2035
|
+
);
|
|
2036
|
+
}
|
|
1795
2037
|
},
|
|
1796
2038
|
installed: (env) => readInstallState(env) !== null
|
|
1797
2039
|
};
|
|
@@ -1800,7 +2042,7 @@ var copilot = {
|
|
|
1800
2042
|
name: "GitHub Copilot",
|
|
1801
2043
|
detect(env) {
|
|
1802
2044
|
const p = copilotPaths(env);
|
|
1803
|
-
return (0,
|
|
2045
|
+
return (0, import_node_fs12.existsSync)(p.copilotDir) ? p.hooksFile : null;
|
|
1804
2046
|
},
|
|
1805
2047
|
install(env, out) {
|
|
1806
2048
|
out("\u25B8 Adding the Copilot hooks and the Copilot CLI status line:");
|
|
@@ -1829,7 +2071,7 @@ var copilot = {
|
|
|
1829
2071
|
doctor(env, check) {
|
|
1830
2072
|
let hooks = 0;
|
|
1831
2073
|
try {
|
|
1832
|
-
const f = JSON.parse((0,
|
|
2074
|
+
const f = JSON.parse((0, import_node_fs12.readFileSync)(copilotPaths(env).hooksFile, "utf8"));
|
|
1833
2075
|
for (const ev of Object.keys(HOOK_EVENTS4))
|
|
1834
2076
|
if ((f.hooks?.[ev] ?? []).some((h) => isOurCommand4(h.powershell) && isOurCommand4(h.bash)))
|
|
1835
2077
|
hooks++;
|
|
@@ -1842,7 +2084,7 @@ var copilot = {
|
|
|
1842
2084
|
);
|
|
1843
2085
|
let line = false;
|
|
1844
2086
|
try {
|
|
1845
|
-
const s = JSON.parse((0,
|
|
2087
|
+
const s = JSON.parse((0, import_node_fs12.readFileSync)(copilotPaths(env).settingsFile, "utf8"));
|
|
1846
2088
|
line = isOurCommand4(s.statusLine?.command);
|
|
1847
2089
|
} catch {
|
|
1848
2090
|
}
|
|
@@ -1859,7 +2101,7 @@ var cursor = {
|
|
|
1859
2101
|
name: "Cursor",
|
|
1860
2102
|
detect(env) {
|
|
1861
2103
|
const p = cursorPaths(env);
|
|
1862
|
-
return (0,
|
|
2104
|
+
return (0, import_node_fs12.existsSync)(p.cursorDir) ? p.hooksFile : null;
|
|
1863
2105
|
},
|
|
1864
2106
|
install(env, out) {
|
|
1865
2107
|
out("\u25B8 Adding Cursor hooks:");
|
|
@@ -1895,7 +2137,7 @@ var cursor = {
|
|
|
1895
2137
|
doctor(env, check) {
|
|
1896
2138
|
let hooks = 0;
|
|
1897
2139
|
try {
|
|
1898
|
-
const f = JSON.parse((0,
|
|
2140
|
+
const f = JSON.parse((0, import_node_fs12.readFileSync)(cursorPaths(env).hooksFile, "utf8"));
|
|
1899
2141
|
for (const ev of Object.keys(HOOK_EVENTS5))
|
|
1900
2142
|
if ((f.hooks?.[ev] ?? []).some((h) => isOurCommand5(h.command))) hooks++;
|
|
1901
2143
|
} catch {
|
|
@@ -1913,7 +2155,7 @@ var codex = {
|
|
|
1913
2155
|
name: "Codex CLI",
|
|
1914
2156
|
detect(env) {
|
|
1915
2157
|
const p = codexPaths(env);
|
|
1916
|
-
return (0,
|
|
2158
|
+
return (0, import_node_fs12.existsSync)(p.codexDir) ? p.hooksFile : null;
|
|
1917
2159
|
},
|
|
1918
2160
|
install(env, out) {
|
|
1919
2161
|
out("\u25B8 Adding Codex hooks:");
|
|
@@ -1949,7 +2191,7 @@ var codex = {
|
|
|
1949
2191
|
doctor(env, check) {
|
|
1950
2192
|
let hooks = 0;
|
|
1951
2193
|
try {
|
|
1952
|
-
const f = JSON.parse((0,
|
|
2194
|
+
const f = JSON.parse((0, import_node_fs12.readFileSync)(codexPaths(env).hooksFile, "utf8"));
|
|
1953
2195
|
for (const ev of Object.keys(HOOK_EVENTS3))
|
|
1954
2196
|
if ((f.hooks?.[ev] ?? []).some((g) => (g.hooks ?? []).some((h) => isOurCommand3(h.command))))
|
|
1955
2197
|
hooks++;
|
|
@@ -1968,7 +2210,7 @@ var antigravity = {
|
|
|
1968
2210
|
name: "Antigravity CLI",
|
|
1969
2211
|
detect(env) {
|
|
1970
2212
|
const p = antigravityPaths(env);
|
|
1971
|
-
return (0,
|
|
2213
|
+
return (0, import_node_fs12.existsSync)((0, import_node_path15.dirname)(p.settingsFile)) ? p.settingsFile : null;
|
|
1972
2214
|
},
|
|
1973
2215
|
install(env, out) {
|
|
1974
2216
|
out("\u25B8 Adding Antigravity CLI hooks and status line:");
|
|
@@ -2005,7 +2247,7 @@ var antigravity = {
|
|
|
2005
2247
|
let hooks = false;
|
|
2006
2248
|
let line = false;
|
|
2007
2249
|
try {
|
|
2008
|
-
const f = JSON.parse((0,
|
|
2250
|
+
const f = JSON.parse((0, import_node_fs12.readFileSync)(p.hooksFile, "utf8"));
|
|
2009
2251
|
const g = f[GROUP] ?? {};
|
|
2010
2252
|
hooks = ["PreInvocation", "Stop"].every(
|
|
2011
2253
|
(ev) => (g[ev] ?? []).some((h) => isOurCommand2(h.command))
|
|
@@ -2013,7 +2255,7 @@ var antigravity = {
|
|
|
2013
2255
|
} catch {
|
|
2014
2256
|
}
|
|
2015
2257
|
try {
|
|
2016
|
-
const s = JSON.parse((0,
|
|
2258
|
+
const s = JSON.parse((0, import_node_fs12.readFileSync)(p.settingsFile, "utf8"));
|
|
2017
2259
|
line = isOurCommand2(s.statusLine?.command);
|
|
2018
2260
|
} catch {
|
|
2019
2261
|
}
|
|
@@ -2032,14 +2274,14 @@ var antigravity = {
|
|
|
2032
2274
|
};
|
|
2033
2275
|
function opencodeUsed(env) {
|
|
2034
2276
|
if (env.AVRON_OPENCODE_DIR) return true;
|
|
2035
|
-
return (0,
|
|
2277
|
+
return (0, import_node_fs12.existsSync)((0, import_node_path15.join)(env.XDG_DATA_HOME || (0, import_node_path15.join)((0, import_node_os10.homedir)(), ".local", "share"), "opencode"));
|
|
2036
2278
|
}
|
|
2037
2279
|
var opencode = {
|
|
2038
2280
|
id: "opencode",
|
|
2039
2281
|
name: "OpenCode",
|
|
2040
2282
|
detect(env) {
|
|
2041
2283
|
const p = opencodePaths(env);
|
|
2042
|
-
return (0,
|
|
2284
|
+
return (0, import_node_fs12.existsSync)(p.configDir) && opencodeUsed(env) ? p.tuiFile : null;
|
|
2043
2285
|
},
|
|
2044
2286
|
install(env, out) {
|
|
2045
2287
|
out("\u25B8 Adding the OpenCode plugin:");
|
|
@@ -2091,7 +2333,7 @@ function selectAdapters(args) {
|
|
|
2091
2333
|
var supportedNames = () => ADAPTERS.map((a) => a.name).join(", ");
|
|
2092
2334
|
|
|
2093
2335
|
// packages/cli/src/operator.ts
|
|
2094
|
-
var VERSION = "0.1.
|
|
2336
|
+
var VERSION = "0.1.1";
|
|
2095
2337
|
var PRODUCT_LINE = `Avron CLI v${VERSION} (UASP Core \u2014 https://avron.dev)`;
|
|
2096
2338
|
var OPERATOR_LINE = "Operator: WBCode (Business Reg No: 215-31-01906, Rep: Taehwan Kim, Republic of Korea)";
|
|
2097
2339
|
var SUPPORT_LINE = "Support: contact@avron.dev";
|
|
@@ -2134,7 +2376,7 @@ async function waitAlive(endpoint, want, timeoutMs) {
|
|
|
2134
2376
|
}
|
|
2135
2377
|
}
|
|
2136
2378
|
function startDaemonProcess(io2) {
|
|
2137
|
-
spawnDaemon((0,
|
|
2379
|
+
spawnDaemon((0, import_node_path16.join)(avronPaths(io2.env).home, "bin", DAEMON_SCRIPT), io2.env);
|
|
2138
2380
|
}
|
|
2139
2381
|
async function stopDaemonProcess(io2) {
|
|
2140
2382
|
const paths = avronPaths(io2.env);
|
|
@@ -2143,7 +2385,7 @@ async function stopDaemonProcess(io2) {
|
|
|
2143
2385
|
if (await waitAlive(endpoint, false, 3e3)) return;
|
|
2144
2386
|
}
|
|
2145
2387
|
try {
|
|
2146
|
-
const pid = Number((0,
|
|
2388
|
+
const pid = Number((0, import_node_fs13.readFileSync)((0, import_node_path16.join)(paths.runDir, "daemon.pid"), "utf8"));
|
|
2147
2389
|
if (Number.isInteger(pid) && pid > 0) process.kill(pid);
|
|
2148
2390
|
} catch {
|
|
2149
2391
|
}
|
|
@@ -2151,7 +2393,7 @@ async function stopDaemonProcess(io2) {
|
|
|
2151
2393
|
}
|
|
2152
2394
|
function readSnapshot(io2) {
|
|
2153
2395
|
try {
|
|
2154
|
-
return JSON.parse((0,
|
|
2396
|
+
return JSON.parse((0, import_node_fs13.readFileSync)(avronPaths(io2.env).ledgerSnapshot, "utf8"));
|
|
2155
2397
|
} catch {
|
|
2156
2398
|
return null;
|
|
2157
2399
|
}
|
|
@@ -2191,6 +2433,8 @@ async function cmdInstall(io2, args) {
|
|
|
2191
2433
|
io2.out("- Only while thinking: one sponsor line shows while the agent thinks and clears when it stops.");
|
|
2192
2434
|
io2.out("- Non-destructive: your settings.json is backed up, your status line and hooks are kept.");
|
|
2193
2435
|
io2.out("- Reversible: `npx @wbcode/avron uninstall` restores the file exactly as it was.");
|
|
2436
|
+
if (found.some((a) => a.id === "claude-code") && desktopAppPresent(io2.env))
|
|
2437
|
+
io2.out("- Claude desktop app: a small plugin is added with `claude plugin` so the line can show there.");
|
|
2194
2438
|
io2.out('- Labelled: every line starts with "Sponsored" (or the same word in its language).');
|
|
2195
2439
|
io2.out("- Sends: about once an hour, a signed batch of valid impressions with an anonymous");
|
|
2196
2440
|
io2.out(" install ID; the server adds your country code. `npx @wbcode/avron audit` shows the next batch.");
|
|
@@ -2211,18 +2455,18 @@ async function cmdInstall(io2, args) {
|
|
|
2211
2455
|
}
|
|
2212
2456
|
}
|
|
2213
2457
|
for (const f of BIN_FILES) {
|
|
2214
|
-
if (!(0,
|
|
2458
|
+
if (!(0, import_node_fs13.existsSync)((0, import_node_path16.join)(io2.binSource, f))) {
|
|
2215
2459
|
io2.out(` [!!] Package is incomplete (missing ${f}). Nothing was changed.`);
|
|
2216
2460
|
return 1;
|
|
2217
2461
|
}
|
|
2218
2462
|
}
|
|
2219
|
-
const binDir = (0,
|
|
2220
|
-
(0,
|
|
2221
|
-
for (const f of BIN_FILES) (0,
|
|
2222
|
-
if (/^node(\.exe)?$/i.test((0,
|
|
2223
|
-
(0,
|
|
2463
|
+
const binDir = (0, import_node_path16.join)(paths.home, "bin");
|
|
2464
|
+
(0, import_node_fs13.mkdirSync)(binDir, { recursive: true });
|
|
2465
|
+
for (const f of BIN_FILES) (0, import_node_fs13.copyFileSync)((0, import_node_path16.join)(io2.binSource, f), (0, import_node_path16.join)(binDir, f));
|
|
2466
|
+
if (/^node(\.exe)?$/i.test((0, import_node_path16.basename)(process.execPath)) && !process.versions.electron)
|
|
2467
|
+
(0, import_node_fs13.writeFileSync)(runtimeFile(io2.env), JSON.stringify({ node: process.execPath }));
|
|
2224
2468
|
ensureIdentity(paths);
|
|
2225
|
-
for (const a of found) if (!a.install(io2.env, io2.out)) return 1;
|
|
2469
|
+
for (const a of found) if (!a.install(io2.env, io2.out, { binSource: io2.binSource })) return 1;
|
|
2226
2470
|
io2.out("\u25B8 Launching background core daemon:");
|
|
2227
2471
|
const endpoint = ipcEndpoint(io2.env);
|
|
2228
2472
|
if (await isAlive(endpoint)) await stopDaemonProcess(io2);
|
|
@@ -2279,15 +2523,15 @@ async function cmdUninstall(io2, args) {
|
|
|
2279
2523
|
}
|
|
2280
2524
|
io2.out("\u25B8 Removing Avron files:");
|
|
2281
2525
|
if (keep) {
|
|
2282
|
-
for (const name of (0,
|
|
2526
|
+
for (const name of (0, import_node_fs13.readdirSync)(paths.home)) {
|
|
2283
2527
|
if (name === "keys" || name === "logs" || name === "data") continue;
|
|
2284
|
-
(0,
|
|
2528
|
+
(0, import_node_fs13.rmSync)((0, import_node_path16.join)(paths.home, name), { recursive: true, force: true });
|
|
2285
2529
|
}
|
|
2286
|
-
(0,
|
|
2530
|
+
(0, import_node_fs13.rmSync)(paths.daemonLog, { force: true });
|
|
2287
2531
|
io2.out(` [OK] Kept your key and ledger in ${paths.home.replace(/\\/g, "/")} (${turns} turn(s))`);
|
|
2288
2532
|
io2.out(" Remove them too with 'npx @wbcode/avron uninstall --purge'.");
|
|
2289
2533
|
} else {
|
|
2290
|
-
(0,
|
|
2534
|
+
(0, import_node_fs13.rmSync)(paths.home, { recursive: true, force: true });
|
|
2291
2535
|
io2.out(" [OK] Removed");
|
|
2292
2536
|
}
|
|
2293
2537
|
io2.out("");
|
|
@@ -2313,7 +2557,7 @@ async function cmdDoctor(io2) {
|
|
|
2313
2557
|
);
|
|
2314
2558
|
for (const a of ADAPTERS) if (a.detect(io2.env)) a.doctor(io2.env, check, io2.out);
|
|
2315
2559
|
check(
|
|
2316
|
-
BIN_FILES.every((f) => (0,
|
|
2560
|
+
BIN_FILES.every((f) => (0, import_node_fs13.existsSync)((0, import_node_path16.join)(paths.home, "bin", f))),
|
|
2317
2561
|
"Runtime scripts are in place",
|
|
2318
2562
|
"Runtime scripts are missing"
|
|
2319
2563
|
);
|
|
@@ -2323,7 +2567,7 @@ async function cmdDoctor(io2) {
|
|
|
2323
2567
|
"Install key is missing"
|
|
2324
2568
|
);
|
|
2325
2569
|
const endpoint = ipcEndpoint(io2.env);
|
|
2326
|
-
if (!await isAlive(endpoint) && (0,
|
|
2570
|
+
if (!await isAlive(endpoint) && (0, import_node_fs13.existsSync)((0, import_node_path16.join)(paths.home, "bin", DAEMON_SCRIPT))) {
|
|
2327
2571
|
startDaemonProcess(io2);
|
|
2328
2572
|
await waitAlive(endpoint, true, 1e4);
|
|
2329
2573
|
}
|
|
@@ -2444,11 +2688,11 @@ function cmdKey(io2, args) {
|
|
|
2444
2688
|
io2.out("This machine has no Avron key.");
|
|
2445
2689
|
return 1;
|
|
2446
2690
|
}
|
|
2447
|
-
if ((0,
|
|
2691
|
+
if ((0, import_node_fs13.existsSync)(file) && !rest.includes("--force")) {
|
|
2448
2692
|
io2.out(`${file} already exists. Add --force to overwrite it.`);
|
|
2449
2693
|
return 1;
|
|
2450
2694
|
}
|
|
2451
|
-
(0,
|
|
2695
|
+
(0, import_node_fs13.writeFileSync)(file, `${JSON.stringify(backup, null, 2)}
|
|
2452
2696
|
`, { mode: 384 });
|
|
2453
2697
|
io2.out(`[OK] Key saved to ${file}`);
|
|
2454
2698
|
io2.out(" Keep it private: it is what proves this machine's share is yours.");
|
|
@@ -2457,7 +2701,7 @@ function cmdKey(io2, args) {
|
|
|
2457
2701
|
if (verb === "import" && file) {
|
|
2458
2702
|
let data;
|
|
2459
2703
|
try {
|
|
2460
|
-
data = JSON.parse((0,
|
|
2704
|
+
data = JSON.parse((0, import_node_fs13.readFileSync)(file, "utf8"));
|
|
2461
2705
|
} catch {
|
|
2462
2706
|
io2.out(`Could not read ${file}.`);
|
|
2463
2707
|
return 1;
|
|
@@ -2477,7 +2721,7 @@ function cmdKey(io2, args) {
|
|
|
2477
2721
|
}
|
|
2478
2722
|
function runDetached(cmd, args, input) {
|
|
2479
2723
|
try {
|
|
2480
|
-
const child = (0,
|
|
2724
|
+
const child = (0, import_node_child_process4.spawn)(cmd, args, {
|
|
2481
2725
|
stdio: [input === void 0 ? "ignore" : "pipe", "ignore", "ignore"],
|
|
2482
2726
|
windowsHide: true,
|
|
2483
2727
|
detached: true
|
|
@@ -2492,7 +2736,7 @@ function runDetached(cmd, args, input) {
|
|
|
2492
2736
|
function cmdOpen(io2, args) {
|
|
2493
2737
|
let last = {};
|
|
2494
2738
|
try {
|
|
2495
|
-
last = JSON.parse((0,
|
|
2739
|
+
last = JSON.parse((0, import_node_fs13.readFileSync)((0, import_node_path16.join)(avronPaths(io2.env).runDir, "last-shown.json"), "utf8"));
|
|
2496
2740
|
} catch {
|
|
2497
2741
|
io2.out("No sponsor line has been shown yet.");
|
|
2498
2742
|
return 1;
|
|
@@ -2528,7 +2772,7 @@ function cmdAudit(io2) {
|
|
|
2528
2772
|
const show = (label, file) => {
|
|
2529
2773
|
let size = "none";
|
|
2530
2774
|
try {
|
|
2531
|
-
size = `${(0,
|
|
2775
|
+
size = `${(0, import_node_fs13.statSync)(file).size} bytes`;
|
|
2532
2776
|
} catch {
|
|
2533
2777
|
}
|
|
2534
2778
|
io2.out(` ${label.padEnd(26)} ${file.replace(/\\/g, "/")} (${size})`);
|
|
@@ -2537,8 +2781,8 @@ function cmdAudit(io2) {
|
|
|
2537
2781
|
show("totals", paths.ledgerSnapshot);
|
|
2538
2782
|
show("daemon diagnostics", paths.daemonLog);
|
|
2539
2783
|
show("cached manifest", paths.manifestCache);
|
|
2540
|
-
show("sponsor pictures for notifications", (0,
|
|
2541
|
-
show("install key (private)", (0,
|
|
2784
|
+
show("sponsor pictures for notifications", (0, import_node_path16.join)(paths.runDir, "toast-pictures"));
|
|
2785
|
+
show("install key (private)", (0, import_node_path16.join)(paths.keyDir, "private.key"));
|
|
2542
2786
|
io2.out("");
|
|
2543
2787
|
io2.out("[Sent to the server]");
|
|
2544
2788
|
io2.out(` Endpoint: ${apiBase(io2.env)}/v1/events/batch (at most once an hour)`);
|
|
@@ -2717,7 +2961,7 @@ var io = {
|
|
|
2717
2961
|
out: (line) => process.stdout.write(`${line}
|
|
2718
2962
|
`),
|
|
2719
2963
|
interactive,
|
|
2720
|
-
binSource: (0,
|
|
2964
|
+
binSource: (0, import_node_path17.join)(__dirname, "bin"),
|
|
2721
2965
|
fetch,
|
|
2722
2966
|
confirm: (question, defaultYes) => new Promise((resolve9) => {
|
|
2723
2967
|
if (!interactive) return resolve9(defaultYes);
|