agentapprove 0.1.42 → 0.1.44

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 +136 -14
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1822,6 +1822,94 @@ function ye() {
1822
1822
  return new RegExp(s, "g");
1823
1823
  }
1824
1824
 
1825
+ // src/env-preserve.ts
1826
+ var MANAGED_ENV_KEYS = new Set([
1827
+ "AGENTAPPROVE_API",
1828
+ "AGENTAPPROVE_TOKEN",
1829
+ "AGENTAPPROVE_PRIVACY",
1830
+ "AGENTAPPROVE_RETENTION_DAYS",
1831
+ "AGENTAPPROVE_CONFIG_SET_AT",
1832
+ "AGENTAPPROVE_DEBUG_LOG",
1833
+ "AGENTAPPROVE_E2E_MODE",
1834
+ "AGENTAPPROVE_E2E_ENABLED",
1835
+ "AGENTAPPROVE_FAIL_BEHAVIOR"
1836
+ ]);
1837
+ var ACCOUNT_SYNCED_UNMANAGED_KEYS = new Set([
1838
+ "AGENTAPPROVE_QUESTION_INPUT_MODE",
1839
+ "AGENTAPPROVE_TIMEOUT"
1840
+ ]);
1841
+ var ENV_KEY_PATTERN = /^AGENTAPPROVE_[A-Z0-9_]+$/;
1842
+ function isPreservedEnvKey(key) {
1843
+ const k3 = key.trim();
1844
+ return ENV_KEY_PATTERN.test(k3) && !MANAGED_ENV_KEYS.has(k3);
1845
+ }
1846
+ function renderPreservedEnvSection(preserved) {
1847
+ if (!preserved)
1848
+ return "";
1849
+ const lines = Object.keys(preserved).filter((key) => isPreservedEnvKey(key) && !/[\r\n]/.test(preserved[key] ?? "")).sort().map((key) => `${key.trim()}=${preserved[key]}`);
1850
+ if (lines.length === 0)
1851
+ return "";
1852
+ return `
1853
+ # Settings synced from your Agent Approve account that the installer does not
1854
+ # manage (question input mode, timeout, agent display names, ...). Preserved
1855
+ # across reinstall so your hooks keep behaving the same.
1856
+ ${lines.join(`
1857
+ `)}
1858
+ `;
1859
+ }
1860
+ function normalizeEmail(value) {
1861
+ const v3 = value?.trim().toLowerCase();
1862
+ return v3 ? v3 : undefined;
1863
+ }
1864
+ function resolvePreservation(input) {
1865
+ const existing = input.existing ?? undefined;
1866
+ if (input.continuity === "fresh" || !existing) {
1867
+ return { preserved: undefined, letAccountWin: false };
1868
+ }
1869
+ switch (input.continuity) {
1870
+ case "same-token":
1871
+ return { preserved: existing.preserved, letAccountWin: false };
1872
+ case "refresh":
1873
+ case "repair":
1874
+ case "pair": {
1875
+ const a3 = normalizeEmail(input.verifiedEmail);
1876
+ const b3 = normalizeEmail(input.pairedEmail);
1877
+ if (a3 && b3 && a3 === b3) {
1878
+ return { preserved: existing.preserved, letAccountWin: false };
1879
+ }
1880
+ return { preserved: machineLocalOnly(existing.preserved), letAccountWin: true };
1881
+ }
1882
+ }
1883
+ }
1884
+ function machineLocalOnly(preserved) {
1885
+ if (!preserved)
1886
+ return;
1887
+ const out = {};
1888
+ for (const [key, value] of Object.entries(preserved)) {
1889
+ if (!ACCOUNT_SYNCED_UNMANAGED_KEYS.has(key.trim()))
1890
+ out[key] = value;
1891
+ }
1892
+ return Object.keys(out).length > 0 ? out : undefined;
1893
+ }
1894
+ function parseConfigSetAt(value) {
1895
+ if (value === undefined)
1896
+ return;
1897
+ const n = Number.parseInt(value.trim(), 10);
1898
+ if (!Number.isFinite(n) || n < 0)
1899
+ return;
1900
+ return n;
1901
+ }
1902
+ function carryConfigSetAt(existing, now) {
1903
+ return existing === undefined ? now : existing;
1904
+ }
1905
+ function nextConfigSetAt(input) {
1906
+ if (input.existing === 0)
1907
+ return 0;
1908
+ if (input.profile === "existing-config")
1909
+ return carryConfigSetAt(input.existing, input.now);
1910
+ return input.now;
1911
+ }
1912
+
1825
1913
  // ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
1826
1914
  var ANSI_BACKGROUND_OFFSET = 10;
1827
1915
  var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`;
@@ -3070,7 +3158,7 @@ function resolvePairingApiBaseUrl(options) {
3070
3158
  }
3071
3159
 
3072
3160
  // src/cli.ts
3073
- var VERSION = "0.1.42";
3161
+ var VERSION = "0.1.44";
3074
3162
  function getApiUrl() {
3075
3163
  return process.env.AGENTAPPROVE_API || "https://api.agentapprove.com";
3076
3164
  }
@@ -3787,8 +3875,11 @@ function formatStatusValue(key, value) {
3787
3875
  case "AGENTAPPROVE_RETENTION_DAYS":
3788
3876
  return `${value} days`;
3789
3877
  case "AGENTAPPROVE_CONFIG_SET_AT": {
3790
- const timestamp = Number.parseInt(value, 10);
3791
- if (Number.isFinite(timestamp)) {
3878
+ const timestamp = parseConfigSetAt(value);
3879
+ if (timestamp === 0) {
3880
+ return "pending account sync (applies on the next agent event)";
3881
+ }
3882
+ if (timestamp !== undefined) {
3792
3883
  return new Date(timestamp * 1000).toLocaleString();
3793
3884
  }
3794
3885
  return value;
@@ -4023,8 +4114,8 @@ function readExistingConfig() {
4023
4114
  config.retentionDays = value === "forever" ? 365 : parseInt(value, 10);
4024
4115
  break;
4025
4116
  case "AGENTAPPROVE_CONFIG_SET_AT": {
4026
- const parsed = parseInt(value, 10);
4027
- if (Number.isFinite(parsed) && parsed > 0) {
4117
+ const parsed = parseConfigSetAt(value);
4118
+ if (parsed !== undefined) {
4028
4119
  config.configSetAt = parsed;
4029
4120
  }
4030
4121
  break;
@@ -4041,6 +4132,11 @@ function readExistingConfig() {
4041
4132
  case "AGENTAPPROVE_FAIL_BEHAVIOR":
4042
4133
  config.failBehavior = value;
4043
4134
  break;
4135
+ default:
4136
+ if (isPreservedEnvKey(key)) {
4137
+ config.preserved = { ...config.preserved ?? {}, [key.trim()]: value };
4138
+ }
4139
+ break;
4044
4140
  }
4045
4141
  }
4046
4142
  return config;
@@ -4414,7 +4510,7 @@ async function showPairingPresentation(params) {
4414
4510
  }
4415
4511
  function saveEnvConfig(config) {
4416
4512
  const envPath = join(getAgentApproveDir(), "env");
4417
- const configSetAt = config.configSetAt || Math.floor(Date.now() / 1000);
4513
+ const configSetAt = config.configSetAt ?? Math.floor(Date.now() / 1000);
4418
4514
  const retentionDisplay = `${config.retentionDays ?? 30}`;
4419
4515
  const e2eEnabled = config.e2eEnabled !== false;
4420
4516
  const content = `# Agent Approve Configuration
@@ -4444,7 +4540,7 @@ AGENTAPPROVE_E2E_ENABLED=${e2eEnabled ? "true" : "false"}
4444
4540
 
4445
4541
  # Hook behavior when API is unreachable: "allow" | "deny" | "ask"
4446
4542
  AGENTAPPROVE_FAIL_BEHAVIOR=${config.failBehavior || "ask"}
4447
-
4543
+ ${renderPreservedEnvSection(config.preserved)}
4448
4544
  # Settings in this file sync from your Agent Approve account settings, so
4449
4545
  # manual edits here are overwritten on the next config sync.
4450
4546
  # To change settings, run: npx agentapprove install
@@ -6239,7 +6335,7 @@ async function promptTokenRecoveryAction(preflight) {
6239
6335
  const choice2 = await le({
6240
6336
  message: "Your saved token has expired. How would you like to continue?",
6241
6337
  options: [
6242
- { value: "refresh", label: "Refresh token", hint: "Keeps the existing encryption key and current settings" },
6338
+ { value: "refresh", label: "Refresh token", hint: "Keeps the existing encryption key; settings resync from your account on the next event" },
6243
6339
  { value: "repair", label: "Pair this computer again", hint: "You can rotate the encryption key" },
6244
6340
  { value: "cancel", label: "Cancel", hint: "Exit the installer" }
6245
6341
  ]
@@ -6344,7 +6440,14 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
6344
6440
  let failBehavior = selectedInstallConfig.failBehavior;
6345
6441
  let installMode = selectedInstallConfig.installMode;
6346
6442
  let useE2E = selectedInstallConfig.e2eEnabled;
6347
- let configSetAt = setupProfile === "existing-config" && existingConfig?.configSetAt ? existingConfig.configSetAt : Math.floor(Date.now() / 1000);
6443
+ let configSetAt = nextConfigSetAt({
6444
+ existing: existingConfig?.configSetAt,
6445
+ profile: setupProfile,
6446
+ now: Math.floor(Date.now() / 1000)
6447
+ });
6448
+ if (configSetAt === 0 && setupProfile !== "existing-config") {
6449
+ v2.info("Settings from your last pairing are still pending and will apply on the next agent event; they may replace the values chosen here.");
6450
+ }
6348
6451
  if (setupProfile === "customize") {
6349
6452
  const modeChoice = await le({
6350
6453
  message: "Choose your security mode:",
@@ -6617,15 +6720,22 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
6617
6720
  he("Cannot continue without token");
6618
6721
  process.exit(1);
6619
6722
  }
6723
+ const installPreservation = resolvePreservation({
6724
+ continuity: !existingConfig ? "fresh" : pendingRecoveryAction === "refresh" ? "refresh" : pendingRecoveryAction === "repair" ? "repair" : token === existingConfig.token ? "same-token" : "pair",
6725
+ existing: existingConfig,
6726
+ verifiedEmail: undefined,
6727
+ pairedEmail: email || undefined
6728
+ });
6620
6729
  saveEnvConfig({
6621
6730
  apiUrl,
6622
6731
  token,
6623
6732
  privacy: finalPrivacy,
6624
6733
  retentionDays,
6625
6734
  debugLog,
6626
- configSetAt,
6735
+ configSetAt: installPreservation.letAccountWin ? 0 : configSetAt,
6627
6736
  e2eEnabled: useE2E,
6628
- failBehavior
6737
+ failBehavior,
6738
+ preserved: installPreservation.preserved
6629
6739
  });
6630
6740
  if (!silentlyReuseExistingToken) {
6631
6741
  v2.success("Configuration saved to ~/.agentapprove/env");
@@ -7689,7 +7799,7 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
7689
7799
  } else {
7690
7800
  v2.info('Refresh updates the token only. Use "npx agentapprove pair" if you need to repair or change E2E pairing.');
7691
7801
  }
7692
- const configSetAt = existingConfig.configSetAt || Math.floor(Date.now() / 1000);
7802
+ const configSetAt = carryConfigSetAt(existingConfig.configSetAt, Math.floor(Date.now() / 1000));
7693
7803
  const privacy = existingConfig.privacy || "full";
7694
7804
  const retentionDays = existingConfig.retentionDays ?? 30;
7695
7805
  const failBehavior = existingConfig.failBehavior || "ask";
@@ -7740,6 +7850,11 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
7740
7850
  v2.error('Session expired. Run "npx agentapprove refresh" to try again.');
7741
7851
  process.exit(1);
7742
7852
  }
7853
+ const refreshPreservation = resolvePreservation({
7854
+ continuity: "refresh",
7855
+ existing: existingConfig,
7856
+ pairedEmail: result.email || undefined
7857
+ });
7743
7858
  saveEnvConfig({
7744
7859
  apiUrl,
7745
7860
  token,
@@ -7749,7 +7864,8 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
7749
7864
  e2eMode: existingConfig.e2eMode,
7750
7865
  e2eEnabled,
7751
7866
  failBehavior,
7752
- configSetAt
7867
+ configSetAt: refreshPreservation.letAccountWin ? 0 : configSetAt,
7868
+ preserved: refreshPreservation.preserved
7753
7869
  });
7754
7870
  await storeTokenInKeychain(token);
7755
7871
  if (e2eEnabled && result.e2eServerKey) {
@@ -7924,6 +8040,11 @@ async function pairCommand() {
7924
8040
  }
7925
8041
  const apiUrl = result.apiUrl || pairingApiBase;
7926
8042
  const configSetAt = Math.floor(Date.now() / 1000);
8043
+ const pairPreservation = resolvePreservation({
8044
+ continuity: "pair",
8045
+ existing: existingConfig,
8046
+ pairedEmail: result.email || undefined
8047
+ });
7927
8048
  saveEnvConfig({
7928
8049
  apiUrl,
7929
8050
  token: result.token,
@@ -7933,7 +8054,8 @@ async function pairCommand() {
7933
8054
  e2eMode: existingConfig?.e2eMode,
7934
8055
  e2eEnabled: !!e2eUserKey,
7935
8056
  failBehavior: existingConfig?.failBehavior || "ask",
7936
- configSetAt
8057
+ configSetAt: pairPreservation.letAccountWin ? 0 : configSetAt,
8058
+ preserved: pairPreservation.preserved
7937
8059
  });
7938
8060
  await storeTokenInKeychain(result.token);
7939
8061
  const hooksDir = join(getAgentApproveDir(), "hooks");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentapprove",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
4
4
  "description": "AI agent observability and control from your iPhone or Apple Watch",
5
5
  "type": "module",
6
6
  "bin": {