@integrity-labs/agt-cli 0.10.12 → 0.10.14

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/dist/bin/agt.js CHANGED
@@ -2934,9 +2934,26 @@ function detectShellProfile() {
2934
2934
  if (existsSync4(bashrc)) return bashrc;
2935
2935
  return join10(home, ".bash_profile");
2936
2936
  }
2937
- function maybeWriteEtcEnvironment(apiUrl, apiKey) {
2938
- if (process.platform === "win32") return false;
2939
- if (typeof process.getuid !== "function" || process.getuid() !== 0) return false;
2937
+ function maybeWriteSystemWideEnv(apiUrl, apiKey) {
2938
+ const empty = { etcEnvironment: false, profileD: false, bashrc: false };
2939
+ if (process.platform === "win32") return empty;
2940
+ if (typeof process.getuid !== "function" || process.getuid() !== 0) return empty;
2941
+ return {
2942
+ etcEnvironment: writeEtcEnvironment(apiUrl, apiKey),
2943
+ profileD: writeProfileDScript(apiUrl, apiKey),
2944
+ // Run for its side-effect (wiring /etc/bashrc to source agt.sh) but
2945
+ // treat it as a supporting channel, not proof that env values were
2946
+ // persisted. Success reporting should reflect actual value writes.
2947
+ bashrc: ensureBashrcSourcesProfileD()
2948
+ };
2949
+ }
2950
+ function quoteForEtcEnvironment(value) {
2951
+ return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\r?\n/g, "\\n")}"`;
2952
+ }
2953
+ function quoteForPosixShell(value) {
2954
+ return `'${value.replace(/'/g, `'\\''`)}'`;
2955
+ }
2956
+ function writeEtcEnvironment(apiUrl, apiKey) {
2940
2957
  const envPath = "/etc/environment";
2941
2958
  if (!existsSync4(envPath)) return false;
2942
2959
  try {
@@ -2949,8 +2966,8 @@ function maybeWriteEtcEnvironment(apiUrl, apiKey) {
2949
2966
  const stripped = current.split(/\r?\n/).filter((line) => !/^\s*(?:export\s+)?AGT_(?:HOST|API_KEY)=/.test(line)).join("\n");
2950
2967
  const base = stripped.endsWith("\n") || stripped.length === 0 ? stripped : `${stripped}
2951
2968
  `;
2952
- const appended = `${base}AGT_HOST="${apiUrl}"
2953
- AGT_API_KEY="${apiKey}"
2969
+ const appended = `${base}AGT_HOST=${quoteForEtcEnvironment(apiUrl)}
2970
+ AGT_API_KEY=${quoteForEtcEnvironment(apiKey)}
2954
2971
  `;
2955
2972
  writeFileSync5(envPath, appended, { mode: 420 });
2956
2973
  return true;
@@ -2958,6 +2975,54 @@ AGT_API_KEY="${apiKey}"
2958
2975
  return false;
2959
2976
  }
2960
2977
  }
2978
+ function writeProfileDScript(apiUrl, apiKey) {
2979
+ const profileD = "/etc/profile.d";
2980
+ if (!existsSync4(profileD)) return false;
2981
+ try {
2982
+ accessSync(profileD, fsConstants.W_OK);
2983
+ } catch {
2984
+ return false;
2985
+ }
2986
+ try {
2987
+ const scriptPath = `${profileD}/agt.sh`;
2988
+ const content = [
2989
+ "# Augmented \u2014 auto-generated by `agt setup`. Do not edit.",
2990
+ `export AGT_HOST=${quoteForPosixShell(apiUrl)}`,
2991
+ `export AGT_API_KEY=${quoteForPosixShell(apiKey)}`,
2992
+ ""
2993
+ ].join("\n");
2994
+ writeFileSync5(scriptPath, content, { mode: 420 });
2995
+ return true;
2996
+ } catch {
2997
+ return false;
2998
+ }
2999
+ }
3000
+ function ensureBashrcSourcesProfileD() {
3001
+ const bashrc = "/etc/bashrc";
3002
+ if (!existsSync4(bashrc)) return false;
3003
+ try {
3004
+ accessSync(bashrc, fsConstants.W_OK);
3005
+ } catch {
3006
+ return false;
3007
+ }
3008
+ try {
3009
+ const current = readFileSync4(bashrc, "utf-8");
3010
+ const marker = "# Augmented (agt) \u2014 source system-wide AGT env";
3011
+ if (current.includes(marker)) return true;
3012
+ const snippet = [
3013
+ "",
3014
+ marker,
3015
+ "if [ -r /etc/profile.d/agt.sh ]; then",
3016
+ " . /etc/profile.d/agt.sh",
3017
+ "fi",
3018
+ ""
3019
+ ].join("\n");
3020
+ writeFileSync5(bashrc, current + snippet);
3021
+ return true;
3022
+ } catch {
3023
+ return false;
3024
+ }
3025
+ }
2961
3026
  function buildExportLines(shell, apiUrl, apiKey) {
2962
3027
  if (shell.includes("fish")) {
2963
3028
  return [
@@ -3077,9 +3142,15 @@ async function setupCommand(token) {
3077
3142
  if (!json) {
3078
3143
  success(`Environment variables written to ${chalk18.bold(profilePath)}`);
3079
3144
  }
3080
- const envWritten = maybeWriteEtcEnvironment(finalApiUrl, setupResult.api_key);
3081
- if (!json && envWritten) {
3082
- success(`System-wide env written to ${chalk18.bold("/etc/environment")}`);
3145
+ const sys = maybeWriteSystemWideEnv(finalApiUrl, setupResult.api_key);
3146
+ const valueChannelsWritten = sys.etcEnvironment || sys.profileD;
3147
+ if (!json && valueChannelsWritten) {
3148
+ const channels2 = [
3149
+ sys.etcEnvironment ? "/etc/environment" : null,
3150
+ sys.profileD ? "/etc/profile.d/agt.sh" : null,
3151
+ sys.bashrc ? "/etc/bashrc" : null
3152
+ ].filter(Boolean).join(" + ");
3153
+ success(`System-wide env updated: ${channels2}`);
3083
3154
  }
3084
3155
  const managerSpinner = ora13({ text: "Starting manager daemon\u2026", isSilent: json });
3085
3156
  managerSpinner.start();
@@ -3634,7 +3705,7 @@ async function acpxCloseCommand(agent2, _opts, cmd) {
3634
3705
  import { execSync } from "child_process";
3635
3706
  import chalk20 from "chalk";
3636
3707
  import ora15 from "ora";
3637
- var cliVersion = true ? "0.10.12" : "dev";
3708
+ var cliVersion = true ? "0.10.14" : "dev";
3638
3709
  async function fetchLatestVersion() {
3639
3710
  const host2 = getHost();
3640
3711
  if (!host2) return null;
@@ -4033,7 +4104,7 @@ function handleError(err) {
4033
4104
  }
4034
4105
 
4035
4106
  // src/bin/agt.ts
4036
- var cliVersion2 = true ? "0.10.12" : "dev";
4107
+ var cliVersion2 = true ? "0.10.14" : "dev";
4037
4108
  var program = new Command();
4038
4109
  program.name("agt").description("Augmented CLI \u2014 agent provisioning and management").version(cliVersion2).option("--json", "Emit machine-readable JSON output (suppress spinners and colors)").option("--skip-update-check", "Skip the automatic update check on startup");
4039
4110
  program.hook("preAction", (thisCommand) => {