agentapprove 0.1.43 → 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.
- package/dist/cli.js +97 -15
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1834,6 +1834,10 @@ var MANAGED_ENV_KEYS = new Set([
|
|
|
1834
1834
|
"AGENTAPPROVE_E2E_ENABLED",
|
|
1835
1835
|
"AGENTAPPROVE_FAIL_BEHAVIOR"
|
|
1836
1836
|
]);
|
|
1837
|
+
var ACCOUNT_SYNCED_UNMANAGED_KEYS = new Set([
|
|
1838
|
+
"AGENTAPPROVE_QUESTION_INPUT_MODE",
|
|
1839
|
+
"AGENTAPPROVE_TIMEOUT"
|
|
1840
|
+
]);
|
|
1837
1841
|
var ENV_KEY_PATTERN = /^AGENTAPPROVE_[A-Z0-9_]+$/;
|
|
1838
1842
|
function isPreservedEnvKey(key) {
|
|
1839
1843
|
const k3 = key.trim();
|
|
@@ -1853,6 +1857,58 @@ ${lines.join(`
|
|
|
1853
1857
|
`)}
|
|
1854
1858
|
`;
|
|
1855
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
|
+
}
|
|
1856
1912
|
|
|
1857
1913
|
// ../../node_modules/.bun/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
1858
1914
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
@@ -3102,7 +3158,7 @@ function resolvePairingApiBaseUrl(options) {
|
|
|
3102
3158
|
}
|
|
3103
3159
|
|
|
3104
3160
|
// src/cli.ts
|
|
3105
|
-
var VERSION = "0.1.
|
|
3161
|
+
var VERSION = "0.1.44";
|
|
3106
3162
|
function getApiUrl() {
|
|
3107
3163
|
return process.env.AGENTAPPROVE_API || "https://api.agentapprove.com";
|
|
3108
3164
|
}
|
|
@@ -3819,8 +3875,11 @@ function formatStatusValue(key, value) {
|
|
|
3819
3875
|
case "AGENTAPPROVE_RETENTION_DAYS":
|
|
3820
3876
|
return `${value} days`;
|
|
3821
3877
|
case "AGENTAPPROVE_CONFIG_SET_AT": {
|
|
3822
|
-
const timestamp =
|
|
3823
|
-
if (
|
|
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) {
|
|
3824
3883
|
return new Date(timestamp * 1000).toLocaleString();
|
|
3825
3884
|
}
|
|
3826
3885
|
return value;
|
|
@@ -4055,8 +4114,8 @@ function readExistingConfig() {
|
|
|
4055
4114
|
config.retentionDays = value === "forever" ? 365 : parseInt(value, 10);
|
|
4056
4115
|
break;
|
|
4057
4116
|
case "AGENTAPPROVE_CONFIG_SET_AT": {
|
|
4058
|
-
const parsed =
|
|
4059
|
-
if (
|
|
4117
|
+
const parsed = parseConfigSetAt(value);
|
|
4118
|
+
if (parsed !== undefined) {
|
|
4060
4119
|
config.configSetAt = parsed;
|
|
4061
4120
|
}
|
|
4062
4121
|
break;
|
|
@@ -4451,7 +4510,7 @@ async function showPairingPresentation(params) {
|
|
|
4451
4510
|
}
|
|
4452
4511
|
function saveEnvConfig(config) {
|
|
4453
4512
|
const envPath = join(getAgentApproveDir(), "env");
|
|
4454
|
-
const configSetAt = config.configSetAt
|
|
4513
|
+
const configSetAt = config.configSetAt ?? Math.floor(Date.now() / 1000);
|
|
4455
4514
|
const retentionDisplay = `${config.retentionDays ?? 30}`;
|
|
4456
4515
|
const e2eEnabled = config.e2eEnabled !== false;
|
|
4457
4516
|
const content = `# Agent Approve Configuration
|
|
@@ -6276,7 +6335,7 @@ async function promptTokenRecoveryAction(preflight) {
|
|
|
6276
6335
|
const choice2 = await le({
|
|
6277
6336
|
message: "Your saved token has expired. How would you like to continue?",
|
|
6278
6337
|
options: [
|
|
6279
|
-
{ value: "refresh", label: "Refresh token", hint: "Keeps the existing encryption key
|
|
6338
|
+
{ value: "refresh", label: "Refresh token", hint: "Keeps the existing encryption key; settings resync from your account on the next event" },
|
|
6280
6339
|
{ value: "repair", label: "Pair this computer again", hint: "You can rotate the encryption key" },
|
|
6281
6340
|
{ value: "cancel", label: "Cancel", hint: "Exit the installer" }
|
|
6282
6341
|
]
|
|
@@ -6381,7 +6440,14 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6381
6440
|
let failBehavior = selectedInstallConfig.failBehavior;
|
|
6382
6441
|
let installMode = selectedInstallConfig.installMode;
|
|
6383
6442
|
let useE2E = selectedInstallConfig.e2eEnabled;
|
|
6384
|
-
let configSetAt =
|
|
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
|
+
}
|
|
6385
6451
|
if (setupProfile === "customize") {
|
|
6386
6452
|
const modeChoice = await le({
|
|
6387
6453
|
message: "Choose your security mode:",
|
|
@@ -6654,16 +6720,22 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6654
6720
|
he("Cannot continue without token");
|
|
6655
6721
|
process.exit(1);
|
|
6656
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
|
+
});
|
|
6657
6729
|
saveEnvConfig({
|
|
6658
6730
|
apiUrl,
|
|
6659
6731
|
token,
|
|
6660
6732
|
privacy: finalPrivacy,
|
|
6661
6733
|
retentionDays,
|
|
6662
6734
|
debugLog,
|
|
6663
|
-
configSetAt,
|
|
6735
|
+
configSetAt: installPreservation.letAccountWin ? 0 : configSetAt,
|
|
6664
6736
|
e2eEnabled: useE2E,
|
|
6665
6737
|
failBehavior,
|
|
6666
|
-
preserved:
|
|
6738
|
+
preserved: installPreservation.preserved
|
|
6667
6739
|
});
|
|
6668
6740
|
if (!silentlyReuseExistingToken) {
|
|
6669
6741
|
v2.success("Configuration saved to ~/.agentapprove/env");
|
|
@@ -7727,7 +7799,7 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
|
|
|
7727
7799
|
} else {
|
|
7728
7800
|
v2.info('Refresh updates the token only. Use "npx agentapprove pair" if you need to repair or change E2E pairing.');
|
|
7729
7801
|
}
|
|
7730
|
-
const configSetAt = existingConfig.configSetAt
|
|
7802
|
+
const configSetAt = carryConfigSetAt(existingConfig.configSetAt, Math.floor(Date.now() / 1000));
|
|
7731
7803
|
const privacy = existingConfig.privacy || "full";
|
|
7732
7804
|
const retentionDays = existingConfig.retentionDays ?? 30;
|
|
7733
7805
|
const failBehavior = existingConfig.failBehavior || "ask";
|
|
@@ -7778,6 +7850,11 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
|
|
|
7778
7850
|
v2.error('Session expired. Run "npx agentapprove refresh" to try again.');
|
|
7779
7851
|
process.exit(1);
|
|
7780
7852
|
}
|
|
7853
|
+
const refreshPreservation = resolvePreservation({
|
|
7854
|
+
continuity: "refresh",
|
|
7855
|
+
existing: existingConfig,
|
|
7856
|
+
pairedEmail: result.email || undefined
|
|
7857
|
+
});
|
|
7781
7858
|
saveEnvConfig({
|
|
7782
7859
|
apiUrl,
|
|
7783
7860
|
token,
|
|
@@ -7787,8 +7864,8 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
|
|
|
7787
7864
|
e2eMode: existingConfig.e2eMode,
|
|
7788
7865
|
e2eEnabled,
|
|
7789
7866
|
failBehavior,
|
|
7790
|
-
configSetAt,
|
|
7791
|
-
preserved:
|
|
7867
|
+
configSetAt: refreshPreservation.letAccountWin ? 0 : configSetAt,
|
|
7868
|
+
preserved: refreshPreservation.preserved
|
|
7792
7869
|
});
|
|
7793
7870
|
await storeTokenInKeychain(token);
|
|
7794
7871
|
if (e2eEnabled && result.e2eServerKey) {
|
|
@@ -7963,6 +8040,11 @@ async function pairCommand() {
|
|
|
7963
8040
|
}
|
|
7964
8041
|
const apiUrl = result.apiUrl || pairingApiBase;
|
|
7965
8042
|
const configSetAt = Math.floor(Date.now() / 1000);
|
|
8043
|
+
const pairPreservation = resolvePreservation({
|
|
8044
|
+
continuity: "pair",
|
|
8045
|
+
existing: existingConfig,
|
|
8046
|
+
pairedEmail: result.email || undefined
|
|
8047
|
+
});
|
|
7966
8048
|
saveEnvConfig({
|
|
7967
8049
|
apiUrl,
|
|
7968
8050
|
token: result.token,
|
|
@@ -7972,8 +8054,8 @@ async function pairCommand() {
|
|
|
7972
8054
|
e2eMode: existingConfig?.e2eMode,
|
|
7973
8055
|
e2eEnabled: !!e2eUserKey,
|
|
7974
8056
|
failBehavior: existingConfig?.failBehavior || "ask",
|
|
7975
|
-
configSetAt,
|
|
7976
|
-
preserved:
|
|
8057
|
+
configSetAt: pairPreservation.letAccountWin ? 0 : configSetAt,
|
|
8058
|
+
preserved: pairPreservation.preserved
|
|
7977
8059
|
});
|
|
7978
8060
|
await storeTokenInKeychain(result.token);
|
|
7979
8061
|
const hooksDir = join(getAgentApproveDir(), "hooks");
|