@letterblack/lbe-exec 1.2.14 → 1.2.15

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.
Files changed (2) hide show
  1. package/dist/cli.js +140 -0
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -2735,6 +2735,19 @@ switch (cmd) {
2735
2735
  console.log(" " + (active ? "\u2713" : "\u2013") + " " + fn);
2736
2736
  }
2737
2737
  }
2738
+ const activationFile = path15.join(process.cwd(), ".lbe", "activation.json");
2739
+ const sessionActive = (process.env.NODE_OPTIONS || "").includes("register.cjs");
2740
+ if (fs14.existsSync(activationFile)) {
2741
+ try {
2742
+ const act = JSON.parse(fs14.readFileSync(activationFile, "utf8"));
2743
+ console.log("\nactivation: " + (act.permanent ? "permanent" : "session") + " (" + act.mode + ")" + (sessionActive ? " NODE_OPTIONS \u2713" : " restart terminal to apply"));
2744
+ } catch (_) {
2745
+ }
2746
+ } else if (sessionActive) {
2747
+ console.log("\nactivation: session active NODE_OPTIONS \u2713");
2748
+ } else {
2749
+ console.log("\nactivation: none \u2014 run: lbe-exec activate");
2750
+ }
2738
2751
  console.log("\nevents log: .lbe/events.jsonl");
2739
2752
  break;
2740
2753
  }
@@ -2777,6 +2790,129 @@ switch (cmd) {
2777
2790
  process.exit(1);
2778
2791
  });
2779
2792
  break;
2793
+ case "activate": {
2794
+ const hookPath = findHookPath();
2795
+ if (!fs14.existsSync(hookPath)) {
2796
+ console.error("Hook not found: " + hookPath + "\nRun: npm install @letterblack/lbe-exec");
2797
+ process.exit(1);
2798
+ }
2799
+ const mode = opts.mode || "observe";
2800
+ const root = process.cwd();
2801
+ const reqFlag = '--require "' + hookPath + '"';
2802
+ const lbeDir = path15.join(root, ".lbe");
2803
+ fs14.mkdirSync(lbeDir, { recursive: true });
2804
+ fs14.writeFileSync(path15.join(lbeDir, "activation.json"), JSON.stringify({
2805
+ activated: true,
2806
+ activatedAt: (/* @__PURE__ */ new Date()).toISOString(),
2807
+ hookPath,
2808
+ mode,
2809
+ root,
2810
+ permanent: !!opts.permanent
2811
+ }, null, 2) + "\n");
2812
+ if (opts.permanent) {
2813
+ if (process.platform === "win32") {
2814
+ const psRead = spawnSync2("powershell.exe", [
2815
+ "-NoProfile",
2816
+ "-NonInteractive",
2817
+ "-Command",
2818
+ '[System.Environment]::GetEnvironmentVariable("NODE_OPTIONS","User")'
2819
+ ], { encoding: "utf8" });
2820
+ const current = (psRead.stdout || "").trim();
2821
+ const merged = current.includes(hookPath) ? current : (current + " " + reqFlag).trim();
2822
+ spawnSync2("powershell.exe", [
2823
+ "-NoProfile",
2824
+ "-NonInteractive",
2825
+ "-Command",
2826
+ `[System.Environment]::SetEnvironmentVariable('NODE_OPTIONS','${merged}','User');[System.Environment]::SetEnvironmentVariable('LBE_ROOT','${root}','User');[System.Environment]::SetEnvironmentVariable('LBE_MODE','${mode}','User')`
2827
+ ], { stdio: "inherit" });
2828
+ console.log("\n\u2713 LBE permanently activated \u2014 Windows user environment updated.");
2829
+ console.log(" Restart your terminal or IDE to apply.\n");
2830
+ console.log(" Every node / npm / npx process will be governed automatically.");
2831
+ } else {
2832
+ const home = process.env.HOME || "";
2833
+ const rcFiles = [".bashrc", ".zshrc"].map((f) => path15.join(home, f)).filter((f) => fs14.existsSync(f));
2834
+ const block = `
2835
+ # LBE Agent Governance
2836
+ export NODE_OPTIONS='${reqFlag}'
2837
+ export LBE_ROOT="${root}"
2838
+ export LBE_MODE="${mode}"
2839
+ `;
2840
+ for (const rc of rcFiles) {
2841
+ fs14.appendFileSync(rc, block);
2842
+ console.log("\u2713 Appended to " + rc);
2843
+ }
2844
+ if (!rcFiles.length) console.log("No .bashrc/.zshrc found \u2014 add these manually:\n" + block);
2845
+ console.log(" Run: source ~/.bashrc (or restart terminal)");
2846
+ }
2847
+ } else {
2848
+ console.log("\u2500\u2500 LBE Workspace Activation \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500");
2849
+ console.log("workspace: " + root);
2850
+ console.log("hook: " + hookPath);
2851
+ console.log("mode: " + mode);
2852
+ console.log("\nCopy and run in your terminal to arm this session:\n");
2853
+ if (process.platform === "win32") {
2854
+ console.log("# PowerShell:");
2855
+ console.log(`$env:NODE_OPTIONS='--require "` + hookPath + `"'`);
2856
+ console.log('$env:LBE_ROOT="' + root + '"');
2857
+ console.log('$env:LBE_MODE="' + mode + '"');
2858
+ console.log("\n# cmd.exe:");
2859
+ console.log('set NODE_OPTIONS=--require "' + hookPath + '"');
2860
+ console.log("set LBE_ROOT=" + root);
2861
+ console.log("set LBE_MODE=" + mode);
2862
+ } else {
2863
+ console.log(`export NODE_OPTIONS='--require "` + hookPath + `"'`);
2864
+ console.log('export LBE_ROOT="' + root + '"');
2865
+ console.log('export LBE_MODE="' + mode + '"');
2866
+ }
2867
+ console.log("\nAfter running: every node / npm / npx command in this session is governed.");
2868
+ console.log("To persist across all terminals: lbe-exec activate --permanent");
2869
+ }
2870
+ break;
2871
+ }
2872
+ case "deactivate": {
2873
+ const activationFile = path15.join(process.cwd(), ".lbe", "activation.json");
2874
+ if (fs14.existsSync(activationFile)) fs14.unlinkSync(activationFile);
2875
+ if (opts.permanent) {
2876
+ if (process.platform === "win32") {
2877
+ const hookPath = findHookPath();
2878
+ const psRead = spawnSync2("powershell.exe", [
2879
+ "-NoProfile",
2880
+ "-NonInteractive",
2881
+ "-Command",
2882
+ '[System.Environment]::GetEnvironmentVariable("NODE_OPTIONS","User")'
2883
+ ], { encoding: "utf8" });
2884
+ const current = (psRead.stdout || "").trim();
2885
+ const cleaned = current.replace('--require "' + hookPath + '"', "").replace("--require " + hookPath, "").trim();
2886
+ spawnSync2("powershell.exe", [
2887
+ "-NoProfile",
2888
+ "-NonInteractive",
2889
+ "-Command",
2890
+ (cleaned ? `[System.Environment]::SetEnvironmentVariable('NODE_OPTIONS','${cleaned}','User');` : `[System.Environment]::SetEnvironmentVariable('NODE_OPTIONS',$null,'User');`) + `[System.Environment]::SetEnvironmentVariable('LBE_ROOT',$null,'User');[System.Environment]::SetEnvironmentVariable('LBE_MODE',$null,'User')`
2891
+ ], { stdio: "inherit" });
2892
+ console.log("\u2713 LBE deactivated \u2014 user environment cleared. Restart terminal to apply.");
2893
+ } else {
2894
+ console.log("Remove these lines from your shell RC file (.bashrc / .zshrc):");
2895
+ console.log(" export NODE_OPTIONS=... (the --require lbe line)");
2896
+ console.log(" export LBE_ROOT=...");
2897
+ console.log(" export LBE_MODE=...");
2898
+ }
2899
+ } else {
2900
+ console.log("Run these commands to disarm this session:\n");
2901
+ if (process.platform === "win32") {
2902
+ console.log("# PowerShell:");
2903
+ console.log("Remove-Item Env:NODE_OPTIONS -ErrorAction SilentlyContinue");
2904
+ console.log("Remove-Item Env:LBE_ROOT -ErrorAction SilentlyContinue");
2905
+ console.log("Remove-Item Env:LBE_MODE -ErrorAction SilentlyContinue");
2906
+ console.log("\n# cmd.exe:");
2907
+ console.log("set NODE_OPTIONS=");
2908
+ console.log("set LBE_ROOT=");
2909
+ console.log("set LBE_MODE=");
2910
+ } else {
2911
+ console.log("unset NODE_OPTIONS LBE_ROOT LBE_MODE");
2912
+ }
2913
+ }
2914
+ break;
2915
+ }
2780
2916
  case "observe":
2781
2917
  case "enforce":
2782
2918
  policyModeCommand(cmd, opts).catch((e) => {
@@ -2828,6 +2964,10 @@ switch (cmd) {
2828
2964
  console.log(" status Show workspace, mode, hook state, patched functions");
2829
2965
  console.log(" audit Show unified event log (.lbe/events.jsonl)");
2830
2966
  console.log(" policy List active policy rules");
2967
+ console.log(" activate Arm workspace \u2014 every node/npm/npx is governed");
2968
+ console.log(" [--mode observe|enforce] [--permanent]");
2969
+ console.log(" deactivate Disarm workspace");
2970
+ console.log(" [--permanent]");
2831
2971
  console.log(" observe Switch to observer mode (log only, nothing blocked)");
2832
2972
  console.log(" enforce Switch to enforcement mode (violations blocked)");
2833
2973
  console.log(" execute Send a JSON request from stdin or --input file");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letterblack/lbe-exec",
3
- "version": "1.2.14",
3
+ "version": "1.2.15",
4
4
  "description": "Local host-signed execution layer for LetterBlack LBE.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",