@mylasecurity/gate 0.1.0 → 0.2.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 +2 -2
- package/bin/gate.mjs +169 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,9 +13,9 @@ npx @mylasecurity/gate install <claim-code>
|
|
|
13
13
|
|
|
14
14
|
| Command | What it does |
|
|
15
15
|
| --- | --- |
|
|
16
|
-
| `install <code>` | The whole job: fetch → validate → back up → merge → write → report. |
|
|
16
|
+
| `install <code>` | The whole job: fetch → validate → back up → merge → write → report. Also reports any **other** Myla configs it finds in the places the client reads (project/ancestor/managed), without touching them. |
|
|
17
17
|
| `install <code> --dry-run` | Fetch, validate, print exactly what *would* be written and where. Writes nothing. The config is printed with the credential **masked**. |
|
|
18
|
-
| `doctor` |
|
|
18
|
+
| `doctor` | Check the hook is installed, which host it points at, and — with one **read-only** authenticated call to the Gate — whether the token is actually **recognised** (a reissue/revoke leaves a config pointing at a dead token while calls still return 200). Also reports any other Myla configs on the machine. Writes nothing; the token is sent only in the auth header, never printed. |
|
|
19
19
|
| `uninstall` | Remove **only** Myla's hook entries, keep everything else, back up first. |
|
|
20
20
|
|
|
21
21
|
### Flags
|
package/bin/gate.mjs
CHANGED
|
@@ -64,7 +64,7 @@ function hookVersion(client) {
|
|
|
64
64
|
${watchTokens(client).join("|")}
|
|
65
65
|
${hookConfigJson(client, "ORIGIN", "TOKEN", "VERSION")}`);
|
|
66
66
|
}
|
|
67
|
-
var curl = (origin, token,
|
|
67
|
+
var curl = (origin, token, path5, fallback, version) => `curl -sS -f --max-time 10 -X POST ${origin}${path5} -H "Authorization: Bearer ${token}" -H "Content-Type: application/json" -H "X-Myla-Hook-Version: ${version}" --data-binary @- || printf '${fallback}'`;
|
|
68
68
|
var CURSOR_ALLOW = '{"permission":"allow"}';
|
|
69
69
|
var CODEX_ALLOW = "{}";
|
|
70
70
|
function hookConfigJson(client, origin, token, version) {
|
|
@@ -90,9 +90,9 @@ function hookConfigJson(client, origin, token, version) {
|
|
|
90
90
|
}
|
|
91
91
|
}, null, 2);
|
|
92
92
|
}
|
|
93
|
-
const httpHook = (
|
|
93
|
+
const httpHook = (path5, timeout) => [{
|
|
94
94
|
type: "http",
|
|
95
|
-
url: `${origin}${
|
|
95
|
+
url: `${origin}${path5}`,
|
|
96
96
|
timeout,
|
|
97
97
|
headers: { Authorization: `Bearer ${token}`, "X-Myla-Hook-Version": version }
|
|
98
98
|
}];
|
|
@@ -160,8 +160,8 @@ var MIN_NODE_MAJOR = 18;
|
|
|
160
160
|
var MYLA_HOOK_PATH = "/api/security/gate/hook";
|
|
161
161
|
|
|
162
162
|
// src/install.ts
|
|
163
|
-
import
|
|
164
|
-
import
|
|
163
|
+
import fs3 from "node:fs";
|
|
164
|
+
import path3 from "node:path";
|
|
165
165
|
import os2 from "node:os";
|
|
166
166
|
|
|
167
167
|
// src/paths.ts
|
|
@@ -465,6 +465,67 @@ function printDryRun(io, args) {
|
|
|
465
465
|
io.out("");
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
// src/scan.ts
|
|
469
|
+
import fs2 from "node:fs";
|
|
470
|
+
import path2 from "node:path";
|
|
471
|
+
function clientLayout(client) {
|
|
472
|
+
if (client === "cursor") return { folder: ".cursor", files: ["hooks.json"], managed: ["/Library/Application Support/Cursor/hooks.json", "/etc/cursor/hooks.json", "C:\\ProgramData\\Cursor\\hooks.json"] };
|
|
473
|
+
if (client === "codex") return { folder: ".codex", files: ["hooks.json"], managed: [] };
|
|
474
|
+
return {
|
|
475
|
+
folder: ".claude",
|
|
476
|
+
files: ["settings.json", "settings.local.json"],
|
|
477
|
+
managed: ["/Library/Application Support/ClaudeCode/managed-settings.json", "/etc/claude-code/managed-settings.json", "C:\\ProgramData\\ClaudeCode\\managed-settings.json"]
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function ancestors(cwd) {
|
|
481
|
+
const out = [];
|
|
482
|
+
let dir = path2.resolve(cwd);
|
|
483
|
+
for (; ; ) {
|
|
484
|
+
out.push(dir);
|
|
485
|
+
const parent = path2.dirname(dir);
|
|
486
|
+
if (parent === dir) break;
|
|
487
|
+
dir = parent;
|
|
488
|
+
}
|
|
489
|
+
return out;
|
|
490
|
+
}
|
|
491
|
+
function scanForOtherMylaHooks(opts) {
|
|
492
|
+
const { client, cwd, perUserAbsolute } = opts;
|
|
493
|
+
const layout = clientLayout(client);
|
|
494
|
+
const perUser = path2.resolve(perUserAbsolute);
|
|
495
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
496
|
+
for (const dir of ancestors(cwd)) {
|
|
497
|
+
for (const f of layout.files) candidates.add(path2.resolve(dir, layout.folder, f));
|
|
498
|
+
}
|
|
499
|
+
for (const m of layout.managed) candidates.add(m);
|
|
500
|
+
const found = [];
|
|
501
|
+
for (const file of candidates) {
|
|
502
|
+
if (path2.resolve(file) === perUser) continue;
|
|
503
|
+
let raw;
|
|
504
|
+
try {
|
|
505
|
+
if (!fs2.existsSync(file)) continue;
|
|
506
|
+
raw = fs2.readFileSync(file, "utf8");
|
|
507
|
+
} catch {
|
|
508
|
+
continue;
|
|
509
|
+
}
|
|
510
|
+
const { count, hosts } = findMylaHooks(raw, MYLA_HOOK_PATH);
|
|
511
|
+
if (count > 0) found.push({ path: file, count, hosts });
|
|
512
|
+
}
|
|
513
|
+
return found;
|
|
514
|
+
}
|
|
515
|
+
function describeOtherConfigs(found) {
|
|
516
|
+
if (found.length === 0) return [];
|
|
517
|
+
const lines = [""];
|
|
518
|
+
lines.push(` \u26A0 You have ${found.length === 1 ? "another Myla config" : `${found.length} other Myla configs`} on this machine, outside your per-user file:`);
|
|
519
|
+
for (const f of found) {
|
|
520
|
+
const host = f.hosts.length ? f.hosts.join(", ") : "an unreadable host";
|
|
521
|
+
lines.push(` \u2022 ${f.path}`);
|
|
522
|
+
lines.push(` points at ${host} \u2014 this is a different install and may use a different agent's token.`);
|
|
523
|
+
}
|
|
524
|
+
lines.push(" Claude Code reads these too, so this one keeps firing even after you reinstall the per-user one.");
|
|
525
|
+
lines.push(" Nothing here was changed \u2014 open or delete the file(s) above yourself if they shouldn\u2019t be running.");
|
|
526
|
+
return lines;
|
|
527
|
+
}
|
|
528
|
+
|
|
468
529
|
// src/install.ts
|
|
469
530
|
var realFetch = async (url) => {
|
|
470
531
|
const res = await fetch(url, { headers: { accept: "application/json" } });
|
|
@@ -504,7 +565,7 @@ async function runInstall(io, opts) {
|
|
|
504
565
|
const mio = masking(io, v.token);
|
|
505
566
|
let existingRaw = null;
|
|
506
567
|
try {
|
|
507
|
-
existingRaw =
|
|
568
|
+
existingRaw = fs3.existsSync(file) ? fs3.readFileSync(file, "utf8") : null;
|
|
508
569
|
} catch (e) {
|
|
509
570
|
mio.err(`Couldn\u2019t read ${file} (${e.message}). Nothing was written.`);
|
|
510
571
|
return 1;
|
|
@@ -525,7 +586,7 @@ async function runInstall(io, opts) {
|
|
|
525
586
|
}
|
|
526
587
|
if (existingRaw !== null) {
|
|
527
588
|
try {
|
|
528
|
-
|
|
589
|
+
fs3.accessSync(file, fs3.constants.W_OK);
|
|
529
590
|
} catch {
|
|
530
591
|
mio.err(`${file} is read-only, so it was left untouched. Make it writable (chmod +w) and run this again, or install by hand. Nothing was written.`);
|
|
531
592
|
return 1;
|
|
@@ -535,32 +596,34 @@ async function runInstall(io, opts) {
|
|
|
535
596
|
if (existingRaw !== null) {
|
|
536
597
|
backupPath = nextBackupPath(file);
|
|
537
598
|
try {
|
|
538
|
-
|
|
599
|
+
fs3.copyFileSync(file, backupPath);
|
|
539
600
|
} catch (e) {
|
|
540
601
|
mio.err(`Couldn\u2019t write a backup next to ${file} (${e.message}), so nothing was changed. The original is exactly as it was.`);
|
|
541
602
|
return 1;
|
|
542
603
|
}
|
|
543
604
|
}
|
|
544
|
-
const dir =
|
|
605
|
+
const dir = path3.dirname(file);
|
|
545
606
|
try {
|
|
546
|
-
|
|
607
|
+
fs3.mkdirSync(dir, { recursive: true });
|
|
547
608
|
} catch (e) {
|
|
548
609
|
mio.err(`Couldn\u2019t create the folder ${dir} (${e.message}). Nothing was written.`);
|
|
549
610
|
return 1;
|
|
550
611
|
}
|
|
551
|
-
const tmp =
|
|
612
|
+
const tmp = path3.join(dir, `.gate-install-${process.pid}-${Date.now()}.tmp`);
|
|
552
613
|
try {
|
|
553
|
-
|
|
554
|
-
|
|
614
|
+
fs3.writeFileSync(tmp, merge.text, { encoding: "utf8", mode: 384 });
|
|
615
|
+
fs3.renameSync(tmp, file);
|
|
555
616
|
} catch (e) {
|
|
556
617
|
try {
|
|
557
|
-
if (
|
|
618
|
+
if (fs3.existsSync(tmp)) fs3.unlinkSync(tmp);
|
|
558
619
|
} catch {
|
|
559
620
|
}
|
|
560
621
|
mio.err(`Couldn\u2019t write ${file} (${e.message}). Your original file is unchanged${backupPath ? ` and a backup is at ${backupPath}` : ""}. Nothing was lost.`);
|
|
561
622
|
return 1;
|
|
562
623
|
}
|
|
563
624
|
printInstalled(mio, { label: inst.label, client, file, backupPath, merge });
|
|
625
|
+
const others = scanForOtherMylaHooks({ client, cwd: opts.cwd ?? process.cwd(), perUserAbsolute: file });
|
|
626
|
+
for (const line of describeOtherConfigs(others)) mio.out(line);
|
|
564
627
|
return 0;
|
|
565
628
|
}
|
|
566
629
|
function homeShorten(file) {
|
|
@@ -569,15 +632,24 @@ function homeShorten(file) {
|
|
|
569
632
|
}
|
|
570
633
|
|
|
571
634
|
// src/doctor.ts
|
|
572
|
-
import
|
|
573
|
-
|
|
635
|
+
import fs4 from "node:fs";
|
|
636
|
+
var realVerify = async (url, token) => {
|
|
637
|
+
const res = await fetch(url, {
|
|
638
|
+
method: "POST",
|
|
639
|
+
headers: { Authorization: `Bearer ${token}`, "content-type": "application/json" }
|
|
640
|
+
});
|
|
641
|
+
return { status: res.status, body: await res.text() };
|
|
642
|
+
};
|
|
643
|
+
var TOKEN_RE = /^[A-Za-z0-9_-]{32,128}$/;
|
|
644
|
+
async function runDoctor(io, opts) {
|
|
574
645
|
const inst = hookInstall(opts.client, opts.origin, "PLACEHOLDER");
|
|
575
646
|
const file = opts.filePathOverride ?? resolveUserPath(inst.perUserPath);
|
|
576
647
|
const shown = homeShorten(file);
|
|
648
|
+
const verifyFetch = opts.verifyFetch ?? realVerify;
|
|
577
649
|
io.out("");
|
|
578
650
|
io.out(` Myla Gate \xB7 ${inst.label} \xB7 doctor`);
|
|
579
651
|
io.out("");
|
|
580
|
-
if (!
|
|
652
|
+
if (!fs4.existsSync(file)) {
|
|
581
653
|
io.out(row2("\u2022", "Settings file", `${shown} \u2014 not found`));
|
|
582
654
|
io.out("");
|
|
583
655
|
io.out(` No ${inst.label} settings file exists yet, so no Myla hook is installed.`);
|
|
@@ -587,7 +659,7 @@ function runDoctor(io, opts) {
|
|
|
587
659
|
}
|
|
588
660
|
let raw;
|
|
589
661
|
try {
|
|
590
|
-
raw =
|
|
662
|
+
raw = fs4.readFileSync(file, "utf8");
|
|
591
663
|
} catch (e) {
|
|
592
664
|
io.err(` Couldn\u2019t read ${shown} (${e.message}).`);
|
|
593
665
|
return 1;
|
|
@@ -603,10 +675,75 @@ function runDoctor(io, opts) {
|
|
|
603
675
|
}
|
|
604
676
|
io.out(row2("\u2713", "Myla hook", `installed (${count} ${count === 1 ? "entry" : "entries"})`));
|
|
605
677
|
io.out(row2("\u2022", "Points at", hosts.length ? hosts.join(", ") : "an unreadable host"));
|
|
678
|
+
const others = scanForOtherMylaHooks({ client: opts.client, cwd: opts.cwd ?? process.cwd(), perUserAbsolute: file });
|
|
679
|
+
for (const line of describeOtherConfigs(others)) io.out(line);
|
|
680
|
+
const m = raw.match(/Bearer\s+([^\s"'\\]+)/);
|
|
681
|
+
const token = m ? m[1] : "";
|
|
682
|
+
if (!token || !TOKEN_RE.test(token)) {
|
|
683
|
+
io.out(row2("\u2717", "Gate check", "the token in this config is not a real token"));
|
|
684
|
+
io.out("");
|
|
685
|
+
io.out(" The hook is here, but the credential in it isn\u2019t a usable token \u2014 most often the masked");
|
|
686
|
+
io.out(" preview (the row of dots) was copied off the screen instead of the real one. Re-run the");
|
|
687
|
+
io.out(" install command (it writes the real token), or use COPY CONFIG on the install sheet.");
|
|
688
|
+
io.out("");
|
|
689
|
+
return 1;
|
|
690
|
+
}
|
|
691
|
+
const verifyUrl = `${opts.origin.replace(/\/+$/, "")}/api/security/gate/verify`;
|
|
692
|
+
let res;
|
|
693
|
+
try {
|
|
694
|
+
res = await verifyFetch(verifyUrl, token);
|
|
695
|
+
} catch (e) {
|
|
696
|
+
io.out(row2("\u2022", "Gate check", "couldn\u2019t reach the Gate"));
|
|
697
|
+
io.out("");
|
|
698
|
+
io.out(` The hook is written, but I couldn\u2019t reach ${opts.origin} to confirm it (${e.message}).`);
|
|
699
|
+
io.out(" Check your connection and the --origin, then run doctor again.");
|
|
700
|
+
io.out("");
|
|
701
|
+
return 1;
|
|
702
|
+
}
|
|
703
|
+
let d;
|
|
704
|
+
try {
|
|
705
|
+
d = JSON.parse(res.body);
|
|
706
|
+
} catch {
|
|
707
|
+
d = null;
|
|
708
|
+
}
|
|
709
|
+
if (res.status !== 200 || !d) {
|
|
710
|
+
io.out(row2("\u2022", "Gate check", "couldn\u2019t check"));
|
|
711
|
+
io.out("");
|
|
712
|
+
io.out(` The Gate answered unexpectedly (HTTP ${res.status}). The hook is written; try doctor again in a moment.`);
|
|
713
|
+
io.out("");
|
|
714
|
+
return 1;
|
|
715
|
+
}
|
|
716
|
+
if (d.recognized === true) {
|
|
717
|
+
io.out(row2("\u2713", "Gate check", d.agent?.name ? `recognised as \u201C${d.agent.name}\u201D` : "recognised"));
|
|
718
|
+
if (d.gateEnabled === false) {
|
|
719
|
+
io.out(row2("\u2022", "Gate status", "switched off on this deployment"));
|
|
720
|
+
}
|
|
721
|
+
io.out("");
|
|
722
|
+
if (typeof d.lastSeenAt === "string") {
|
|
723
|
+
io.out(" Recognised, and the Gate has heard from this agent \u2014 you\u2019re being watched.");
|
|
724
|
+
} else if (d.lastSeenAt === null) {
|
|
725
|
+
io.out(" The token is recognised, but no call has reached the Gate yet. Fully quit and reopen");
|
|
726
|
+
io.out(` ${inst.label} (closing the window isn\u2019t enough \u2014 hooks load at startup), then use it once.`);
|
|
727
|
+
} else {
|
|
728
|
+
io.out(" The token is recognised. (Couldn\u2019t read recent activity just now.)");
|
|
729
|
+
}
|
|
730
|
+
io.out("");
|
|
731
|
+
return 0;
|
|
732
|
+
}
|
|
733
|
+
if (d.recognized === false) {
|
|
734
|
+
io.out(row2("\u2717", "Gate check", "NOT recognised"));
|
|
735
|
+
io.out("");
|
|
736
|
+
io.out(" The hook is installed and calls to the Gate return 200 \u2014 but the Gate does NOT recognise");
|
|
737
|
+
io.out(" this token, so nothing is being recorded. The usual cause is that the agent was reissued");
|
|
738
|
+
io.out(" or revoked, which rotates the token and leaves this config pointing at a dead one.");
|
|
739
|
+
io.out(" Reissue the agent in Myla if needed, then re-run the install command to write the new token.");
|
|
740
|
+
io.out("");
|
|
741
|
+
return 1;
|
|
742
|
+
}
|
|
743
|
+
io.out(row2("\u2022", "Gate check", "couldn\u2019t check"));
|
|
606
744
|
io.out("");
|
|
607
|
-
io.out(
|
|
608
|
-
io.out(
|
|
609
|
-
io.out(" Whether a call has actually reached the Gate shows on the agent\u2019s row in Myla.");
|
|
745
|
+
io.out(" Couldn\u2019t confirm the token just now \u2014 that\u2019s a Myla hiccup, not a sign your setup is wrong.");
|
|
746
|
+
io.out(" Try doctor again in a moment.");
|
|
610
747
|
io.out("");
|
|
611
748
|
return 0;
|
|
612
749
|
}
|
|
@@ -616,19 +753,19 @@ function row2(mark, label, value) {
|
|
|
616
753
|
}
|
|
617
754
|
|
|
618
755
|
// src/uninstall.ts
|
|
619
|
-
import
|
|
620
|
-
import
|
|
756
|
+
import fs5 from "node:fs";
|
|
757
|
+
import path4 from "node:path";
|
|
621
758
|
function runUninstall(io, opts) {
|
|
622
759
|
const inst = hookInstall(opts.client, opts.origin, "PLACEHOLDER");
|
|
623
760
|
const file = opts.filePathOverride ?? resolveUserPath(inst.perUserPath);
|
|
624
761
|
const shown = homeShorten(file);
|
|
625
|
-
if (!
|
|
762
|
+
if (!fs5.existsSync(file)) {
|
|
626
763
|
io.out(`No ${inst.label} settings file at ${shown}, so there\u2019s no Myla hook to remove. Nothing was changed.`);
|
|
627
764
|
return 0;
|
|
628
765
|
}
|
|
629
766
|
let raw;
|
|
630
767
|
try {
|
|
631
|
-
raw =
|
|
768
|
+
raw = fs5.readFileSync(file, "utf8");
|
|
632
769
|
} catch (e) {
|
|
633
770
|
io.err(`Couldn\u2019t read ${shown} (${e.message}). Nothing was changed.`);
|
|
634
771
|
return 1;
|
|
@@ -654,18 +791,18 @@ function runUninstall(io, opts) {
|
|
|
654
791
|
if (existingWritableRefused(io, file, shown)) return 1;
|
|
655
792
|
const backupPath = nextBackupPath(file);
|
|
656
793
|
try {
|
|
657
|
-
|
|
794
|
+
fs5.copyFileSync(file, backupPath);
|
|
658
795
|
} catch (e) {
|
|
659
796
|
io.err(`Couldn\u2019t write a backup next to ${shown} (${e.message}), so nothing was changed.`);
|
|
660
797
|
return 1;
|
|
661
798
|
}
|
|
662
|
-
const tmp =
|
|
799
|
+
const tmp = path4.join(path4.dirname(file), `.gate-uninstall-${process.pid}-${Date.now()}.tmp`);
|
|
663
800
|
try {
|
|
664
|
-
|
|
665
|
-
|
|
801
|
+
fs5.writeFileSync(tmp, result.text, { encoding: "utf8", mode: 384 });
|
|
802
|
+
fs5.renameSync(tmp, file);
|
|
666
803
|
} catch (e) {
|
|
667
804
|
try {
|
|
668
|
-
if (
|
|
805
|
+
if (fs5.existsSync(tmp)) fs5.unlinkSync(tmp);
|
|
669
806
|
} catch {
|
|
670
807
|
}
|
|
671
808
|
io.err(`Couldn\u2019t write ${shown} (${e.message}). Your original file is unchanged and a backup is at ${homeShorten(backupPath)}.`);
|
|
@@ -677,7 +814,7 @@ function runUninstall(io, opts) {
|
|
|
677
814
|
}
|
|
678
815
|
function existingWritableRefused(io, file, shown) {
|
|
679
816
|
try {
|
|
680
|
-
|
|
817
|
+
fs5.accessSync(file, fs5.constants.W_OK);
|
|
681
818
|
return false;
|
|
682
819
|
} catch {
|
|
683
820
|
io.err(`${shown} is read-only, so it was left untouched. Make it writable (chmod +w) and run this again. Nothing was changed.`);
|
|
@@ -745,7 +882,7 @@ var HELP = `Myla Gate installer
|
|
|
745
882
|
Usage
|
|
746
883
|
npx @mylasecurity/gate install <claim-code> Install (the whole job)
|
|
747
884
|
npx @mylasecurity/gate install <claim-code> --dry-run Show what would be written, write nothing
|
|
748
|
-
npx @mylasecurity/gate doctor
|
|
885
|
+
npx @mylasecurity/gate doctor Check the hook is installed AND the Gate recognises the token (read-only)
|
|
749
886
|
npx @mylasecurity/gate uninstall Remove only Myla's hooks, back up first
|
|
750
887
|
|
|
751
888
|
Options
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mylasecurity/gate",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "One command to put the Myla Gate in front of your coding agent — fetches a one-time claim, merges the hooks into your per-user settings, backs up first, prints exactly what it changed.",
|
|
6
6
|
"type": "module",
|