agentapprove 0.1.56 → 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/dist/cli.js +1282 -610
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1842,8 +1842,487 @@ function upsertCursorHook(existing, entry) {
|
|
|
1842
1842
|
return entries;
|
|
1843
1843
|
}
|
|
1844
1844
|
|
|
1845
|
+
// src/json-config.ts
|
|
1846
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
1847
|
+
import { dirname } from "path";
|
|
1848
|
+
var UTF8_BOM = "\uFEFF";
|
|
1849
|
+
var UTF8_BOM_BYTES = [239, 187, 191];
|
|
1850
|
+
|
|
1851
|
+
class ConfigParseError extends Error {
|
|
1852
|
+
configPath;
|
|
1853
|
+
detail;
|
|
1854
|
+
constructor(configPath, detail) {
|
|
1855
|
+
super(`Could not read ${configPath}: ${detail}. ` + "The file was left unchanged. Fix it (or move it aside), then run the installer again.");
|
|
1856
|
+
this.name = "ConfigParseError";
|
|
1857
|
+
this.configPath = configPath;
|
|
1858
|
+
this.detail = detail;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
function errorDetail(error) {
|
|
1862
|
+
return error instanceof Error ? error.message : String(error);
|
|
1863
|
+
}
|
|
1864
|
+
function configErrorMessage(error) {
|
|
1865
|
+
return errorDetail(error);
|
|
1866
|
+
}
|
|
1867
|
+
function stripBom(content) {
|
|
1868
|
+
return content.startsWith(UTF8_BOM) ? { content: content.slice(1), hadBom: true } : { content, hadBom: false };
|
|
1869
|
+
}
|
|
1870
|
+
function stripJsonComments(content) {
|
|
1871
|
+
let withoutComments = "";
|
|
1872
|
+
let inString = false;
|
|
1873
|
+
let i = 0;
|
|
1874
|
+
while (i < content.length) {
|
|
1875
|
+
const ch = content[i];
|
|
1876
|
+
if (inString) {
|
|
1877
|
+
withoutComments += ch;
|
|
1878
|
+
if (ch === "\\" && i + 1 < content.length) {
|
|
1879
|
+
withoutComments += content[i + 1];
|
|
1880
|
+
i += 2;
|
|
1881
|
+
continue;
|
|
1882
|
+
}
|
|
1883
|
+
if (ch === '"')
|
|
1884
|
+
inString = false;
|
|
1885
|
+
i++;
|
|
1886
|
+
continue;
|
|
1887
|
+
}
|
|
1888
|
+
if (ch === '"') {
|
|
1889
|
+
inString = true;
|
|
1890
|
+
withoutComments += ch;
|
|
1891
|
+
i++;
|
|
1892
|
+
continue;
|
|
1893
|
+
}
|
|
1894
|
+
if (ch === "/" && content[i + 1] === "/") {
|
|
1895
|
+
while (i < content.length && content[i] !== `
|
|
1896
|
+
` && content[i] !== "\r")
|
|
1897
|
+
i++;
|
|
1898
|
+
withoutComments += " ";
|
|
1899
|
+
continue;
|
|
1900
|
+
}
|
|
1901
|
+
if (ch === "/" && content[i + 1] === "*") {
|
|
1902
|
+
i += 2;
|
|
1903
|
+
while (i < content.length && !(content[i] === "*" && content[i + 1] === "/")) {
|
|
1904
|
+
if (content[i] === `
|
|
1905
|
+
`)
|
|
1906
|
+
withoutComments += `
|
|
1907
|
+
`;
|
|
1908
|
+
i++;
|
|
1909
|
+
}
|
|
1910
|
+
i += 2;
|
|
1911
|
+
withoutComments += " ";
|
|
1912
|
+
continue;
|
|
1913
|
+
}
|
|
1914
|
+
withoutComments += ch;
|
|
1915
|
+
i++;
|
|
1916
|
+
}
|
|
1917
|
+
let result = "";
|
|
1918
|
+
inString = false;
|
|
1919
|
+
i = 0;
|
|
1920
|
+
while (i < withoutComments.length) {
|
|
1921
|
+
const ch = withoutComments[i];
|
|
1922
|
+
if (inString) {
|
|
1923
|
+
result += ch;
|
|
1924
|
+
if (ch === "\\" && i + 1 < withoutComments.length) {
|
|
1925
|
+
result += withoutComments[i + 1];
|
|
1926
|
+
i += 2;
|
|
1927
|
+
continue;
|
|
1928
|
+
}
|
|
1929
|
+
if (ch === '"')
|
|
1930
|
+
inString = false;
|
|
1931
|
+
i++;
|
|
1932
|
+
continue;
|
|
1933
|
+
}
|
|
1934
|
+
if (ch === '"') {
|
|
1935
|
+
inString = true;
|
|
1936
|
+
result += ch;
|
|
1937
|
+
i++;
|
|
1938
|
+
continue;
|
|
1939
|
+
}
|
|
1940
|
+
if (ch === ",") {
|
|
1941
|
+
let j = i + 1;
|
|
1942
|
+
while (j < withoutComments.length && /\s/.test(withoutComments[j]))
|
|
1943
|
+
j++;
|
|
1944
|
+
if (withoutComments[j] === "}" || withoutComments[j] === "]") {
|
|
1945
|
+
i++;
|
|
1946
|
+
continue;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
result += ch;
|
|
1950
|
+
i++;
|
|
1951
|
+
}
|
|
1952
|
+
return result;
|
|
1953
|
+
}
|
|
1954
|
+
function parseConfigText(text, configPath, options = {}) {
|
|
1955
|
+
const { content } = stripBom(text);
|
|
1956
|
+
const source = options.jsonc ? stripJsonComments(content) : content;
|
|
1957
|
+
if (source.trim() === "") {
|
|
1958
|
+
return {};
|
|
1959
|
+
}
|
|
1960
|
+
let parsed;
|
|
1961
|
+
try {
|
|
1962
|
+
parsed = JSON.parse(source);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
throw new ConfigParseError(configPath, `it is not valid ${options.jsonc ? "JSON (comments and trailing commas are allowed)" : "JSON"} (${errorDetail(error)})`);
|
|
1965
|
+
}
|
|
1966
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
1967
|
+
throw new ConfigParseError(configPath, "its top level is not a JSON object");
|
|
1968
|
+
}
|
|
1969
|
+
return parsed;
|
|
1970
|
+
}
|
|
1971
|
+
function readConfigFile(configPath, jsonc) {
|
|
1972
|
+
if (!existsSync(configPath)) {
|
|
1973
|
+
return {};
|
|
1974
|
+
}
|
|
1975
|
+
let text;
|
|
1976
|
+
try {
|
|
1977
|
+
text = readFileSync(configPath, "utf-8");
|
|
1978
|
+
} catch (error) {
|
|
1979
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
1980
|
+
return {};
|
|
1981
|
+
}
|
|
1982
|
+
throw new ConfigParseError(configPath, `it could not be opened (${errorDetail(error)})`);
|
|
1983
|
+
}
|
|
1984
|
+
return parseConfigText(text, configPath, { jsonc });
|
|
1985
|
+
}
|
|
1986
|
+
function readJsonConfig(configPath) {
|
|
1987
|
+
return readConfigFile(configPath, false);
|
|
1988
|
+
}
|
|
1989
|
+
function readJsoncConfig(configPath) {
|
|
1990
|
+
return readConfigFile(configPath, true);
|
|
1991
|
+
}
|
|
1992
|
+
function configUsesJsoncSyntax(configPath) {
|
|
1993
|
+
let text;
|
|
1994
|
+
try {
|
|
1995
|
+
text = readFileSync(configPath, "utf-8");
|
|
1996
|
+
} catch {
|
|
1997
|
+
return false;
|
|
1998
|
+
}
|
|
1999
|
+
const { content } = stripBom(text);
|
|
2000
|
+
if (content.trim() === "")
|
|
2001
|
+
return false;
|
|
2002
|
+
try {
|
|
2003
|
+
JSON.parse(content);
|
|
2004
|
+
return false;
|
|
2005
|
+
} catch {}
|
|
2006
|
+
try {
|
|
2007
|
+
parseConfigText(text, configPath, { jsonc: true });
|
|
2008
|
+
return true;
|
|
2009
|
+
} catch {
|
|
2010
|
+
return false;
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
function fileHasBom(configPath) {
|
|
2014
|
+
try {
|
|
2015
|
+
const bytes = readFileSync(configPath);
|
|
2016
|
+
return UTF8_BOM_BYTES.every((byte, index) => bytes[index] === byte);
|
|
2017
|
+
} catch {
|
|
2018
|
+
return false;
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
function writeJsonConfig(configPath, config) {
|
|
2022
|
+
const dir = dirname(configPath);
|
|
2023
|
+
if (!existsSync(dir)) {
|
|
2024
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
2025
|
+
}
|
|
2026
|
+
const bom = fileHasBom(configPath) ? UTF8_BOM : "";
|
|
2027
|
+
writeFileSync(configPath, bom + JSON.stringify(config, null, 2) + `
|
|
2028
|
+
`);
|
|
2029
|
+
}
|
|
2030
|
+
function backupConfig(configPath) {
|
|
2031
|
+
if (!existsSync(configPath)) {
|
|
2032
|
+
return null;
|
|
2033
|
+
}
|
|
2034
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
2035
|
+
const backupPath = `${configPath}.backup.${timestamp}`;
|
|
2036
|
+
copyFileSync(configPath, backupPath);
|
|
2037
|
+
return backupPath;
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
// src/private-file.ts
|
|
2041
|
+
import { chmodSync, closeSync, fsyncSync, lstatSync, mkdirSync as mkdirSync2, openSync, renameSync, rmSync, statSync, writeSync } from "fs";
|
|
2042
|
+
import { randomBytes } from "crypto";
|
|
2043
|
+
import { basename, dirname as dirname2, join } from "path";
|
|
2044
|
+
var PRIVATE_FILE_MODE = 384;
|
|
2045
|
+
var PRIVATE_DIR_MODE = 448;
|
|
2046
|
+
function modesApply(platform) {
|
|
2047
|
+
return platform !== "win32";
|
|
2048
|
+
}
|
|
2049
|
+
function currentUid(options) {
|
|
2050
|
+
if (options.uid !== undefined)
|
|
2051
|
+
return options.uid;
|
|
2052
|
+
return typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
2053
|
+
}
|
|
2054
|
+
function lstatOrNull(path) {
|
|
2055
|
+
try {
|
|
2056
|
+
return lstatSync(path);
|
|
2057
|
+
} catch (error) {
|
|
2058
|
+
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
2059
|
+
return null;
|
|
2060
|
+
throw error;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
function assertWritableDestination(path) {
|
|
2064
|
+
const stat = lstatOrNull(path);
|
|
2065
|
+
if (!stat)
|
|
2066
|
+
return;
|
|
2067
|
+
if (stat.isSymbolicLink()) {
|
|
2068
|
+
throw new Error(`Refusing to write ${path}: it is a symbolic link. Agent Approve stores a secret in this file and will not write it ` + "through a link. Replace the link with a regular file (or remove it), then run the installer again.");
|
|
2069
|
+
}
|
|
2070
|
+
if (!stat.isFile()) {
|
|
2071
|
+
throw new Error(`Refusing to write ${path}: it is not a regular file. Remove or rename it, then run the installer again.`);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
function restrictToOwner(path, options = {}) {
|
|
2075
|
+
const platform = (typeof options === "string" ? options : options.platform) ?? process.platform;
|
|
2076
|
+
if (!modesApply(platform))
|
|
2077
|
+
return;
|
|
2078
|
+
const stat = lstatOrNull(path);
|
|
2079
|
+
if (!stat || stat.isSymbolicLink() || !stat.isFile())
|
|
2080
|
+
return;
|
|
2081
|
+
chmodSync(path, PRIVATE_FILE_MODE);
|
|
2082
|
+
}
|
|
2083
|
+
function writePrivateFile(path, content, options = {}) {
|
|
2084
|
+
const platform = (typeof options === "string" ? options : options.platform) ?? process.platform;
|
|
2085
|
+
assertWritableDestination(path);
|
|
2086
|
+
const tempPath = join(dirname2(path), `.${basename(path)}.${randomBytes(8).toString("hex")}.tmp`);
|
|
2087
|
+
let fd = null;
|
|
2088
|
+
try {
|
|
2089
|
+
fd = openSync(tempPath, "wx", PRIVATE_FILE_MODE);
|
|
2090
|
+
writeSync(fd, content);
|
|
2091
|
+
fsyncSync(fd);
|
|
2092
|
+
closeSync(fd);
|
|
2093
|
+
fd = null;
|
|
2094
|
+
if (modesApply(platform))
|
|
2095
|
+
chmodSync(tempPath, PRIVATE_FILE_MODE);
|
|
2096
|
+
assertWritableDestination(path);
|
|
2097
|
+
renameSync(tempPath, path);
|
|
2098
|
+
} catch (error) {
|
|
2099
|
+
if (fd !== null) {
|
|
2100
|
+
try {
|
|
2101
|
+
closeSync(fd);
|
|
2102
|
+
} catch {}
|
|
2103
|
+
}
|
|
2104
|
+
rmSync(tempPath, { force: true });
|
|
2105
|
+
throw error;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
function ensurePrivateDir(dir, options = {}) {
|
|
2109
|
+
const resolved = typeof options === "string" ? { platform: options } : options;
|
|
2110
|
+
const platform = resolved.platform ?? process.platform;
|
|
2111
|
+
let stat;
|
|
2112
|
+
try {
|
|
2113
|
+
stat = statSync(dir);
|
|
2114
|
+
} catch (error) {
|
|
2115
|
+
if (!(error && typeof error === "object" && ("code" in error) && error.code === "ENOENT"))
|
|
2116
|
+
throw error;
|
|
2117
|
+
mkdirSync2(dir, { recursive: true, mode: PRIVATE_DIR_MODE });
|
|
2118
|
+
if (modesApply(platform))
|
|
2119
|
+
chmodSync(dir, PRIVATE_DIR_MODE);
|
|
2120
|
+
return true;
|
|
2121
|
+
}
|
|
2122
|
+
if (!stat.isDirectory()) {
|
|
2123
|
+
throw new Error(`${dir} exists and is not a directory. Remove or rename it, then run the installer again.`);
|
|
2124
|
+
}
|
|
2125
|
+
if (!modesApply(platform))
|
|
2126
|
+
return false;
|
|
2127
|
+
if ((stat.mode & 63) === 0)
|
|
2128
|
+
return false;
|
|
2129
|
+
const uid = currentUid(resolved);
|
|
2130
|
+
if (uid !== undefined && stat.uid !== uid) {
|
|
2131
|
+
throw new Error(`${dir} is accessible to other users and is owned by a different account, so Agent Approve will not store its token or keys there. ` + `Fix the ownership and run: chmod 700 ${dir}`);
|
|
2132
|
+
}
|
|
2133
|
+
chmodSync(dir, PRIVATE_DIR_MODE);
|
|
2134
|
+
return false;
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
// src/post-pair-hooks.ts
|
|
2138
|
+
import { existsSync as existsSync2 } from "fs";
|
|
2139
|
+
async function refreshHooksAfterPairing(hooksDir, token, apiUrl, deps) {
|
|
2140
|
+
if (!existsSync2(hooksDir)) {
|
|
2141
|
+
throw new Error("Hooks directory not found");
|
|
2142
|
+
}
|
|
2143
|
+
const filters = await deps.copyHookScripts(hooksDir, token, deps.filterFiles, { apiUrl });
|
|
2144
|
+
return { filtersRefreshed: !(filters.failed.length || filters.terminalFailure) };
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
// src/pairing-effective-config.ts
|
|
2148
|
+
var PRIVACY_RANK = { minimal: 0, summary: 1, full: 2 };
|
|
2149
|
+
var FAIL_RANK = { allow: 0, ask: 1, deny: 2 };
|
|
2150
|
+
var SETTING_LABEL = {
|
|
2151
|
+
privacyTier: "Privacy level",
|
|
2152
|
+
retentionDays: "Data retention",
|
|
2153
|
+
failBehavior: "If Agent Approve cannot be reached",
|
|
2154
|
+
e2eEnabled: "End-to-end encryption"
|
|
2155
|
+
};
|
|
2156
|
+
function isPrivacyTier(value) {
|
|
2157
|
+
return value === "minimal" || value === "summary" || value === "full";
|
|
2158
|
+
}
|
|
2159
|
+
function isFailBehavior(value) {
|
|
2160
|
+
return value === "allow" || value === "ask" || value === "deny";
|
|
2161
|
+
}
|
|
2162
|
+
function describeRetention(days) {
|
|
2163
|
+
if (days === null)
|
|
2164
|
+
return "keep forever";
|
|
2165
|
+
return days === 1 ? "1 day" : `${days} days`;
|
|
2166
|
+
}
|
|
2167
|
+
var DEFAULT_FAIL_BEHAVIOR = "ask";
|
|
2168
|
+
var DEFAULT_PRIVACY_TIER = "full";
|
|
2169
|
+
function parseEffectivePairingConfig(value) {
|
|
2170
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
2171
|
+
return null;
|
|
2172
|
+
const candidate = value;
|
|
2173
|
+
const parsed = {};
|
|
2174
|
+
if (isPrivacyTier(candidate.privacyTier))
|
|
2175
|
+
parsed.privacyTier = candidate.privacyTier;
|
|
2176
|
+
const retention = candidate.retentionDays;
|
|
2177
|
+
if (retention === null || typeof retention === "number" && Number.isFinite(retention) && retention >= 0) {
|
|
2178
|
+
parsed.retentionDays = retention;
|
|
2179
|
+
}
|
|
2180
|
+
if (isFailBehavior(candidate.failBehavior))
|
|
2181
|
+
parsed.failBehavior = candidate.failBehavior;
|
|
2182
|
+
if (typeof candidate.e2eEnabled === "boolean")
|
|
2183
|
+
parsed.e2eEnabled = candidate.e2eEnabled;
|
|
2184
|
+
return parsed;
|
|
2185
|
+
}
|
|
2186
|
+
function reconcilePairingConfig(picks, effective, options = {}) {
|
|
2187
|
+
const local = {
|
|
2188
|
+
privacyTier: picks.privacyTier,
|
|
2189
|
+
retentionDays: picks.retentionDays,
|
|
2190
|
+
failBehavior: picks.failBehavior,
|
|
2191
|
+
e2eEnabled: picks.e2eEnabled
|
|
2192
|
+
};
|
|
2193
|
+
const accountKept = [];
|
|
2194
|
+
const unknown = [];
|
|
2195
|
+
const account = effective ?? {};
|
|
2196
|
+
const accountPrivacy = account.privacyTier ?? (isPrivacyTier(options.reportedPrivacy) ? options.reportedPrivacy : undefined);
|
|
2197
|
+
if (accountPrivacy === undefined) {
|
|
2198
|
+
unknown.push("privacyTier");
|
|
2199
|
+
if (PRIVACY_RANK[DEFAULT_PRIVACY_TIER] < PRIVACY_RANK[local.privacyTier])
|
|
2200
|
+
local.privacyTier = DEFAULT_PRIVACY_TIER;
|
|
2201
|
+
} else if (PRIVACY_RANK[accountPrivacy] < PRIVACY_RANK[picks.privacyTier]) {
|
|
2202
|
+
local.privacyTier = accountPrivacy;
|
|
2203
|
+
accountKept.push({ setting: "privacyTier", picked: picks.privacyTier, kept: accountPrivacy });
|
|
2204
|
+
}
|
|
2205
|
+
if (account.retentionDays === undefined) {
|
|
2206
|
+
unknown.push("retentionDays");
|
|
2207
|
+
} else if (account.retentionDays !== null && account.retentionDays < picks.retentionDays) {
|
|
2208
|
+
local.retentionDays = account.retentionDays;
|
|
2209
|
+
accountKept.push({
|
|
2210
|
+
setting: "retentionDays",
|
|
2211
|
+
picked: describeRetention(picks.retentionDays),
|
|
2212
|
+
kept: describeRetention(account.retentionDays)
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
if (account.failBehavior === undefined) {
|
|
2216
|
+
unknown.push("failBehavior");
|
|
2217
|
+
if (FAIL_RANK[DEFAULT_FAIL_BEHAVIOR] > FAIL_RANK[local.failBehavior])
|
|
2218
|
+
local.failBehavior = DEFAULT_FAIL_BEHAVIOR;
|
|
2219
|
+
} else if (FAIL_RANK[account.failBehavior] > FAIL_RANK[picks.failBehavior]) {
|
|
2220
|
+
local.failBehavior = account.failBehavior;
|
|
2221
|
+
accountKept.push({ setting: "failBehavior", picked: picks.failBehavior, kept: account.failBehavior });
|
|
2222
|
+
}
|
|
2223
|
+
let encryptionRequired = false;
|
|
2224
|
+
if (account.e2eEnabled === undefined) {
|
|
2225
|
+
unknown.push("e2eEnabled");
|
|
2226
|
+
if (!picks.e2eEnabled && options.localE2eOn === true)
|
|
2227
|
+
local.e2eEnabled = true;
|
|
2228
|
+
} else if (account.e2eEnabled && !picks.e2eEnabled) {
|
|
2229
|
+
encryptionRequired = true;
|
|
2230
|
+
accountKept.push({ setting: "e2eEnabled", picked: "off", kept: "on" });
|
|
2231
|
+
}
|
|
2232
|
+
return { local, accountKept, unknown, encryptionRequired, letAccountWin: unknown.length > 0 };
|
|
2233
|
+
}
|
|
2234
|
+
function formatAccountKeptWarning(reconciliation) {
|
|
2235
|
+
const kept = reconciliation.accountKept.filter((entry) => entry.setting !== "e2eEnabled");
|
|
2236
|
+
if (kept.length === 0)
|
|
2237
|
+
return null;
|
|
2238
|
+
return [
|
|
2239
|
+
"Your Agent Approve account kept its stricter settings. This computer now uses them:",
|
|
2240
|
+
...kept.map((entry) => ` ${SETTING_LABEL[entry.setting]}: ${entry.kept} (you chose ${entry.picked})`),
|
|
2241
|
+
"You can change account settings in the Agent Approve app."
|
|
2242
|
+
].join(`
|
|
2243
|
+
`);
|
|
2244
|
+
}
|
|
2245
|
+
function formatAccountUnknownNote(reconciliation) {
|
|
2246
|
+
if (reconciliation.unknown.length === 0)
|
|
2247
|
+
return null;
|
|
2248
|
+
const names = reconciliation.unknown.map((setting) => SETTING_LABEL[setting]).join(", ");
|
|
2249
|
+
return `This pairing could not confirm your account's value for: ${names}. ` + "This computer uses the safer value for now and picks up your account settings on the next agent event.";
|
|
2250
|
+
}
|
|
2251
|
+
function formatEncryptionRequiredMessage(rerun) {
|
|
2252
|
+
const again = rerun === "pair" ? 'Run "npx agentapprove pair" again and choose an encryption key instead of disabling encryption.' : 'Run "npx agentapprove" again and keep end-to-end encryption on (choose Customize if you are not asked, and do not pass --no-e2e).';
|
|
2253
|
+
return [
|
|
2254
|
+
"This computer is not set up yet.",
|
|
2255
|
+
"Your Agent Approve account has end-to-end encryption turned on, and this setup chose to leave it off.",
|
|
2256
|
+
"Pairing a computer cannot turn encryption off for the account, and the encryption key can only be created during setup, so this computer has no key to use.",
|
|
2257
|
+
"Nothing from this pairing was saved on this computer. If it was set up before, its earlier pairing has been replaced and will not work until you set it up again.",
|
|
2258
|
+
again
|
|
2259
|
+
].join(`
|
|
2260
|
+
`);
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
// src/pair-key-plan.ts
|
|
2264
|
+
import { createHash } from "crypto";
|
|
2265
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, renameSync as renameSync2 } from "fs";
|
|
2266
|
+
import { join as join2 } from "path";
|
|
2267
|
+
var PAIR_KEY_GENERATE = "__generate__";
|
|
2268
|
+
var PAIR_KEY_DISABLE = "__disable__";
|
|
2269
|
+
function e2eKeyId(keyHex) {
|
|
2270
|
+
return createHash("sha256").update(Buffer.from(keyHex, "hex")).digest("hex").slice(0, 8);
|
|
2271
|
+
}
|
|
2272
|
+
function planPairKey(selection, keys, agentApproveDir, generateKeyHex) {
|
|
2273
|
+
if (selection === PAIR_KEY_DISABLE) {
|
|
2274
|
+
return { kind: "disable", e2eUserKey: null };
|
|
2275
|
+
}
|
|
2276
|
+
if (selection === PAIR_KEY_GENERATE) {
|
|
2277
|
+
const keyHex = generateKeyHex();
|
|
2278
|
+
const current = keys.find((key) => key.isCurrent);
|
|
2279
|
+
return {
|
|
2280
|
+
kind: "generate",
|
|
2281
|
+
e2eUserKey: keyHex,
|
|
2282
|
+
e2eKeyId: e2eKeyId(keyHex),
|
|
2283
|
+
...current ? { backup: { from: current.path, to: join2(agentApproveDir, `e2e-key.${current.keyId}.bak`), keyId: current.keyId } } : {}
|
|
2284
|
+
};
|
|
2285
|
+
}
|
|
2286
|
+
const selected = keys.find((key) => key.keyId === selection);
|
|
2287
|
+
if (!selected)
|
|
2288
|
+
return { kind: "not_found" };
|
|
2289
|
+
return { kind: "existing", e2eUserKey: selected.keyHex, e2eKeyId: selected.keyId };
|
|
2290
|
+
}
|
|
2291
|
+
function applyPairKeyPlan(plan, agentApproveDir, deps) {
|
|
2292
|
+
if (plan.kind === "disable") {
|
|
2293
|
+
return { backedUp: null };
|
|
2294
|
+
}
|
|
2295
|
+
const rootKeyPath = join2(agentApproveDir, "e2e-root-key");
|
|
2296
|
+
const userKeyPath = join2(agentApproveDir, "e2e-key");
|
|
2297
|
+
let backedUp = null;
|
|
2298
|
+
if (plan.kind === "generate") {
|
|
2299
|
+
if (plan.backup && existsSync3(plan.backup.from)) {
|
|
2300
|
+
renameSync2(plan.backup.from, plan.backup.to);
|
|
2301
|
+
backedUp = plan.backup.keyId;
|
|
2302
|
+
}
|
|
2303
|
+
writePrivateFile(rootKeyPath, plan.e2eUserKey);
|
|
2304
|
+
writePrivateFile(userKeyPath, plan.e2eUserKey);
|
|
2305
|
+
deps.rotation.write({ rootKeyId: plan.e2eKeyId, epoch: 0, periodSeconds: 0, startedAt: deps.now() });
|
|
2306
|
+
} else {
|
|
2307
|
+
if (!existsSync3(rootKeyPath) || readFileSync2(rootKeyPath, "utf-8").trim() !== plan.e2eUserKey) {
|
|
2308
|
+
writePrivateFile(rootKeyPath, plan.e2eUserKey);
|
|
2309
|
+
} else {
|
|
2310
|
+
restrictToOwner(rootKeyPath);
|
|
2311
|
+
}
|
|
2312
|
+
restrictToOwner(userKeyPath);
|
|
2313
|
+
if (!deps.rotation.read()) {
|
|
2314
|
+
deps.rotation.write({ rootKeyId: plan.e2eKeyId, epoch: 0, periodSeconds: 0, startedAt: deps.now() });
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
if (deps.serverKey) {
|
|
2318
|
+
writePrivateFile(join2(agentApproveDir, "e2e-server-key"), deps.serverKey);
|
|
2319
|
+
}
|
|
2320
|
+
return { backedUp };
|
|
2321
|
+
}
|
|
2322
|
+
|
|
1845
2323
|
// src/openclaw-install.ts
|
|
1846
2324
|
import { spawnSync } from "node:child_process";
|
|
2325
|
+
import { isDeepStrictEqual } from "node:util";
|
|
1847
2326
|
var CONVERSATION_ACCESS_NOTICE = "OpenClaw setup includes access to prompts, responses, and completed conversations for monitoring and mobile follow-up. Your privacy and encryption settings still apply. OpenClaw will review any required plugin permissions during installation.";
|
|
1848
2327
|
function runOpenClaw(args) {
|
|
1849
2328
|
const result = spawnSync("openclaw", args, { stdio: "inherit", shell: process.platform === "win32" });
|
|
@@ -1862,7 +2341,7 @@ function mergeOpenClawConfig(config, conversationAccess) {
|
|
|
1862
2341
|
openclaw: {
|
|
1863
2342
|
...entry,
|
|
1864
2343
|
hooks: { ...entry.hooks, allowConversationAccess: conversationAccess },
|
|
1865
|
-
config: { ...entry.config }
|
|
2344
|
+
...entry.config === undefined ? {} : { config: { ...entry.config } }
|
|
1866
2345
|
}
|
|
1867
2346
|
}
|
|
1868
2347
|
},
|
|
@@ -1893,13 +2372,16 @@ async function installOpenClaw(options) {
|
|
|
1893
2372
|
return fail(`OpenClaw installed ${actual ?? "an unverified version"}, expected ${options.version}.`);
|
|
1894
2373
|
}
|
|
1895
2374
|
try {
|
|
1896
|
-
options.
|
|
2375
|
+
const current = options.readConfig();
|
|
2376
|
+
const updated = mergeOpenClawConfig(current, true);
|
|
2377
|
+
if (!isDeepStrictEqual(current, updated))
|
|
2378
|
+
options.writeConfig(updated);
|
|
1897
2379
|
} catch {
|
|
1898
2380
|
return fail("Could not read or save OpenClaw configuration. The plugin package is present; check the config and retry setup before using it.");
|
|
1899
2381
|
}
|
|
1900
2382
|
const action = options.mode === "approval" ? "enable" : "disable";
|
|
1901
2383
|
if (!run(["plugins", action, "openclaw"]))
|
|
1902
|
-
return fail(`OpenClaw ${action}
|
|
2384
|
+
return fail(`Agent Approve v${options.version} is installed, but OpenClaw ${action} did not complete. Review the host output above. If the Gateway is still reloading, wait for it to finish, then run: openclaw plugins ${action} openclaw. Activation remains controlled by OpenClaw.`);
|
|
1903
2385
|
return {
|
|
1904
2386
|
success: true,
|
|
1905
2387
|
label: `Agent Approve plugin v${options.version} (conversation access included)`
|
|
@@ -2487,15 +2969,15 @@ var source_default = chalk;
|
|
|
2487
2969
|
|
|
2488
2970
|
// src/cli.ts
|
|
2489
2971
|
var import_qrcode_terminal = __toESM(require_main(), 1);
|
|
2490
|
-
import { existsSync as
|
|
2972
|
+
import { existsSync as existsSync5, readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync3, mkdtempSync, copyFileSync as copyFileSync2, renameSync as renameSync4, readdirSync as readdirSync2, statSync as statSync2, lstatSync as lstatSync2, realpathSync as realpathSync2, rmSync as rmSync3 } from "fs";
|
|
2491
2973
|
import { homedir, hostname, platform, tmpdir } from "os";
|
|
2492
|
-
import { join, dirname as
|
|
2974
|
+
import { join as join3, dirname as dirname4, sep as sep2 } from "path";
|
|
2493
2975
|
import { execSync, spawnSync as spawnSync2 } from "child_process";
|
|
2494
|
-
import { randomBytes, createHash } from "crypto";
|
|
2976
|
+
import { randomBytes as randomBytes2, createHash as createHash3 } from "crypto";
|
|
2495
2977
|
|
|
2496
2978
|
// src/uninstall-utils.ts
|
|
2497
|
-
import { existsSync, readdirSync, realpathSync, rmSync } from "fs";
|
|
2498
|
-
import { basename, dirname, sep } from "path";
|
|
2979
|
+
import { existsSync as existsSync4, readdirSync, realpathSync, rmSync as rmSync2 } from "fs";
|
|
2980
|
+
import { basename as basename2, dirname as dirname3, sep } from "path";
|
|
2499
2981
|
var INSTALLER_COMMAND_DESCRIPTIONS = {
|
|
2500
2982
|
uninstall: "Remove hooks/plugins from agent configs and keep local Agent Approve state",
|
|
2501
2983
|
purge: "Remove hooks/plugins and delete local Agent Approve state"
|
|
@@ -2568,7 +3050,7 @@ function appendPathSegments(basePath, childSegments) {
|
|
|
2568
3050
|
return basePath.endsWith(sep) ? `${basePath}${childSegments.join(sep)}` : `${basePath}${sep}${childSegments.join(sep)}`;
|
|
2569
3051
|
}
|
|
2570
3052
|
function createRemovalTarget(path, kind, recursive = false) {
|
|
2571
|
-
if (!
|
|
3053
|
+
if (!existsSync4(path)) {
|
|
2572
3054
|
return null;
|
|
2573
3055
|
}
|
|
2574
3056
|
let actualPath = path;
|
|
@@ -2582,13 +3064,13 @@ function createRemovalTarget(path, kind, recursive = false) {
|
|
|
2582
3064
|
return { path, actualPath, displayPath, kind, recursive };
|
|
2583
3065
|
}
|
|
2584
3066
|
function removeRemovalTarget(target) {
|
|
2585
|
-
if (!
|
|
3067
|
+
if (!existsSync4(target.path) && !existsSync4(target.actualPath)) {
|
|
2586
3068
|
return false;
|
|
2587
3069
|
}
|
|
2588
3070
|
try {
|
|
2589
|
-
|
|
3071
|
+
rmSync2(target.actualPath, { recursive: target.recursive, force: true });
|
|
2590
3072
|
if (target.path !== target.actualPath) {
|
|
2591
|
-
|
|
3073
|
+
rmSync2(target.path, { recursive: false, force: true });
|
|
2592
3074
|
}
|
|
2593
3075
|
return true;
|
|
2594
3076
|
} catch {
|
|
@@ -2596,7 +3078,7 @@ function removeRemovalTarget(target) {
|
|
|
2596
3078
|
}
|
|
2597
3079
|
}
|
|
2598
3080
|
function getOpenClawPluginTargets(openclawConfigPath) {
|
|
2599
|
-
const configDir =
|
|
3081
|
+
const configDir = dirname3(openclawConfigPath);
|
|
2600
3082
|
const npmPath = safeJoinWithinBase(configDir, "npm", "node_modules", "@agentapprove", "openclaw");
|
|
2601
3083
|
const openclawPath = safeJoinWithinBase(configDir, "extensions", "openclaw");
|
|
2602
3084
|
const legacyPath = safeJoinWithinBase(configDir, "extensions", "agentapprove");
|
|
@@ -2612,7 +3094,7 @@ function getOpenCodePluginTargets(opencodeConfigDir, opencodeCacheDir) {
|
|
|
2612
3094
|
const packageCacheTargets = [];
|
|
2613
3095
|
if (opencodeCacheDir) {
|
|
2614
3096
|
const scopedPackageCacheDir = safeJoinWithinBase(opencodeCacheDir, "packages", "@agentapprove");
|
|
2615
|
-
if (scopedPackageCacheDir &&
|
|
3097
|
+
if (scopedPackageCacheDir && existsSync4(scopedPackageCacheDir)) {
|
|
2616
3098
|
for (const entry of readdirSync(scopedPackageCacheDir)) {
|
|
2617
3099
|
if (!entry.startsWith("opencode@")) {
|
|
2618
3100
|
continue;
|
|
@@ -2641,11 +3123,11 @@ function getAntigravityPluginTargets(geminiDir) {
|
|
|
2641
3123
|
function collectBackupTargets(configPaths) {
|
|
2642
3124
|
const targets = [];
|
|
2643
3125
|
for (const configPath of configPaths) {
|
|
2644
|
-
const configDir =
|
|
2645
|
-
if (!
|
|
3126
|
+
const configDir = dirname3(configPath);
|
|
3127
|
+
if (!existsSync4(configDir)) {
|
|
2646
3128
|
continue;
|
|
2647
3129
|
}
|
|
2648
|
-
const configBase =
|
|
3130
|
+
const configBase = basename2(configPath);
|
|
2649
3131
|
for (const entry of readdirSync(configDir)) {
|
|
2650
3132
|
if (!entry.startsWith(`${configBase}.backup.`)) {
|
|
2651
3133
|
continue;
|
|
@@ -2675,7 +3157,7 @@ function getManagedStateTargets(agentApproveDir) {
|
|
|
2675
3157
|
safeJoinWithinBase(agentApproveDir, "e2e-server-key"),
|
|
2676
3158
|
safeJoinWithinBase(agentApproveDir, "e2e-rotation.json")
|
|
2677
3159
|
].map((path) => path ? createRemovalTarget(path, "crypto_material") : null).filter((target) => target !== null);
|
|
2678
|
-
if (
|
|
3160
|
+
if (existsSync4(agentApproveDir)) {
|
|
2679
3161
|
for (const entry of readdirSync(agentApproveDir)) {
|
|
2680
3162
|
if (!/^e2e-key\.[^.]+\.bak$/.test(entry)) {
|
|
2681
3163
|
continue;
|
|
@@ -3173,8 +3655,8 @@ function classifyHookDownloadFailure(status, body) {
|
|
|
3173
3655
|
|
|
3174
3656
|
// src/copy-hook-scripts.ts
|
|
3175
3657
|
import { writeFileSync as fsWriteFileSync } from "fs";
|
|
3176
|
-
import { renameSync } from "fs";
|
|
3177
|
-
import { randomUUID } from "crypto";
|
|
3658
|
+
import { renameSync as renameSync3 } from "fs";
|
|
3659
|
+
import { createHash as createHash2, randomUUID } from "crypto";
|
|
3178
3660
|
|
|
3179
3661
|
// src/background-filters.ts
|
|
3180
3662
|
var BACKGROUND_FILTER_FILES = ["background-filter.js", "background-filters.json"];
|
|
@@ -3191,6 +3673,7 @@ function validBackgroundFilters(content) {
|
|
|
3191
3673
|
|
|
3192
3674
|
// src/copy-hook-scripts.ts
|
|
3193
3675
|
import { join as pathJoin } from "path";
|
|
3676
|
+
var HOOK_INTEGRITY_FAILURE = "integrity check failed; run the latest installer: npx agentapprove@latest";
|
|
3194
3677
|
function retryDelay(response) {
|
|
3195
3678
|
const value = response.headers.get("Retry-After")?.trim();
|
|
3196
3679
|
if (!value)
|
|
@@ -3236,7 +3719,8 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3236
3719
|
response = await download();
|
|
3237
3720
|
}
|
|
3238
3721
|
if (response.ok) {
|
|
3239
|
-
const
|
|
3722
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
3723
|
+
const content = new TextDecoder("utf-8").decode(bytes);
|
|
3240
3724
|
if (file === "background-filters.json") {
|
|
3241
3725
|
if (!validBackgroundFilters(content)) {
|
|
3242
3726
|
recordFailure(file, "invalid catalog; previous copy retained");
|
|
@@ -3248,6 +3732,14 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3248
3732
|
}
|
|
3249
3733
|
const isShellScript = content.startsWith("#!/") || content.startsWith("# ");
|
|
3250
3734
|
const isJsBundle = file.endsWith(".js") && (content.startsWith("//") || content.startsWith("import ") || content.startsWith("var ") || content.startsWith("const ") || content.startsWith("export "));
|
|
3735
|
+
if (options.expectedHashes) {
|
|
3736
|
+
const pinned = Object.prototype.hasOwnProperty.call(options.expectedHashes, file) ? options.expectedHashes[file] : undefined;
|
|
3737
|
+
const actual = createHash2("sha256").update(Buffer.from(bytes)).digest("hex");
|
|
3738
|
+
if (!pinned || !pinned.includes(actual)) {
|
|
3739
|
+
recordFailure(file, HOOK_INTEGRITY_FAILURE);
|
|
3740
|
+
continue;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3251
3743
|
if (isShellScript || isJsBundle) {
|
|
3252
3744
|
staged.push({ file, content, mode: isShellScript ? 493 : 420 });
|
|
3253
3745
|
downloaded++;
|
|
@@ -3301,7 +3793,7 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3301
3793
|
if (failed.length === 0) {
|
|
3302
3794
|
for (const { temporary, filePath, file } of replacements) {
|
|
3303
3795
|
try {
|
|
3304
|
-
|
|
3796
|
+
renameSync3(temporary, filePath);
|
|
3305
3797
|
} catch {
|
|
3306
3798
|
failed.push(`${file} (could not replace hook file)`);
|
|
3307
3799
|
break;
|
|
@@ -3312,9 +3804,232 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3312
3804
|
return { downloaded, failed, optionalFailed };
|
|
3313
3805
|
}
|
|
3314
3806
|
|
|
3807
|
+
// src/hook-manifest.generated.ts
|
|
3808
|
+
var HOOK_SCRIPT_SHA256 = {
|
|
3809
|
+
"antigravity-hook.sh": [
|
|
3810
|
+
"1ed82442099b7216b9dd3fd6b1e9f2648b5230b528778a374ba7f1d570603d8a",
|
|
3811
|
+
"0cfac7fdab920af8b243dc8f0cffcc5355d06cec13a71060f1e77a22487379cf"
|
|
3812
|
+
],
|
|
3813
|
+
"background-filter.js": [
|
|
3814
|
+
"5850ec58a56474891627e54b4e34255a878b7d21037382296c5512ee6d250d54"
|
|
3815
|
+
],
|
|
3816
|
+
"claude-notification.sh": [
|
|
3817
|
+
"f699c4ac0d47ad66ab7c5dca549d8413b344dd20c6317f0ed278aed933306583"
|
|
3818
|
+
],
|
|
3819
|
+
"claude-post-tool-failure.sh": [
|
|
3820
|
+
"a14693c771609d63d42c2a84fcb6c6a09edfd5e7977ef37d193af7379db85907"
|
|
3821
|
+
],
|
|
3822
|
+
"claude-post-tool.sh": [
|
|
3823
|
+
"8a61253504c99ecdf101b4fa8681a09489f128ef4ba6dcfb47450c881011654e"
|
|
3824
|
+
],
|
|
3825
|
+
"claude-pre-tool.sh": [
|
|
3826
|
+
"a4bae2a689b075762a11df659b10ca783c1c780af93277efe37a398243fbc8ed",
|
|
3827
|
+
"5a317ed1eb620bf5751fbe50ac266295f9a9436a5b5368ff4d5f3ae1e0202f33"
|
|
3828
|
+
],
|
|
3829
|
+
"claude-prompt.sh": [
|
|
3830
|
+
"449cffbd8efb1f04f51d67aedb817883cffd20ab99ddff4eb32acfb4d3692080"
|
|
3831
|
+
],
|
|
3832
|
+
"claude-session-end.sh": [
|
|
3833
|
+
"f27ff70502327886d28f234631bbe01cf1b02369f0491b956c8cdb1aaf07c4b6"
|
|
3834
|
+
],
|
|
3835
|
+
"claude-session-start.sh": [
|
|
3836
|
+
"dc2d906e448d277be0f9b5e1cd1b0bddadd9d5d86f6a0012ffa6e63cb38fb906"
|
|
3837
|
+
],
|
|
3838
|
+
"claude-stop.sh": [
|
|
3839
|
+
"158629503c11d44d3864c6a4ea5448e5743b4cacc11f0246ef604ce5a4c27830",
|
|
3840
|
+
"5dd2f71fb534dda5599af3bdaf44092134460ab46195254a830715d3cdf0936a"
|
|
3841
|
+
],
|
|
3842
|
+
"claude-subagent-start.sh": [
|
|
3843
|
+
"93738cd3c3667feae235fd08a44be6381f7e7d6291c102257ae1913917a58d17"
|
|
3844
|
+
],
|
|
3845
|
+
"claude-subagent-stop.sh": [
|
|
3846
|
+
"3cacc15624672dc10109fc01456540027293c30b3e581d9376311c35cd937dd2"
|
|
3847
|
+
],
|
|
3848
|
+
"claude-user-prompt.sh": [
|
|
3849
|
+
"62dc6f72c856ed70e2bd2812471d9a825c5004948db309eff996ff9c78be9be4"
|
|
3850
|
+
],
|
|
3851
|
+
"codex-post-tool.sh": [
|
|
3852
|
+
"b2d6a3352198a79780ace8303b476b37250d020d066d3be0b32719be34cb1198"
|
|
3853
|
+
],
|
|
3854
|
+
"codex-pre-tool.sh": [
|
|
3855
|
+
"3d1c6b7f8717f7b043d54f79af6225bebffb2baa4f0badde759182c415bcc343",
|
|
3856
|
+
"6c44eb3f3774024d26a2d9162b9a91f1ac8c15559a164823f122aa0f423b454f"
|
|
3857
|
+
],
|
|
3858
|
+
"codex-session-start.sh": [
|
|
3859
|
+
"b14351394abeab95d047d6843e34d52e33758eef1f4f129a31efe6334858db53"
|
|
3860
|
+
],
|
|
3861
|
+
"codex-stop.sh": [
|
|
3862
|
+
"6c46b605b482a474205d850cec28f35ced74796beedf1f2647a1268fcfa7d45e",
|
|
3863
|
+
"e0c3c95605c6f04004c4cb350ee7d997f471a7d07546e2e0b0fec9b9de845cd5"
|
|
3864
|
+
],
|
|
3865
|
+
"codex-subagent-start.sh": [
|
|
3866
|
+
"053caf81244b7510057c307d7dbc35f2190b0c5665dfdae252ae29e98744de4e"
|
|
3867
|
+
],
|
|
3868
|
+
"codex-subagent-stop.sh": [
|
|
3869
|
+
"0876893314ccf0ebbb8e07dd879c0e751ab24a6b195008d8d1ccf29ee86f581d"
|
|
3870
|
+
],
|
|
3871
|
+
"codex-user-prompt.sh": [
|
|
3872
|
+
"0e8886fa08e6c5529721f6e94907c9bad6c32e97c1f4827e2ef5270f349cce4f"
|
|
3873
|
+
],
|
|
3874
|
+
"common.sh": [
|
|
3875
|
+
"626da6d015a3686cc4ba9b578ec19e378f18156c5fa0b11fdd10250908ba47da",
|
|
3876
|
+
"dba7e22eb923e22054a776eb2a5cbf958acf5b55f83d49b685eef3cac1ce30e6"
|
|
3877
|
+
],
|
|
3878
|
+
"completion-hook.sh": [
|
|
3879
|
+
"ec94b799c35cd650b79d50f223bd57e817fed5d7e379aac5948e06f14ad7b31a"
|
|
3880
|
+
],
|
|
3881
|
+
"cursor-approval.sh": [
|
|
3882
|
+
"547e056485093ff9071a5c45326dfaf1320918495c54908f7413d7f6c7a9422f",
|
|
3883
|
+
"cd831b97a0631202275d98925be1401b0b8915d4cf90783e158d05fea813cdfd"
|
|
3884
|
+
],
|
|
3885
|
+
"cursor-mcp-approval.sh": [
|
|
3886
|
+
"e5638dde8b7767ff4e3c0a361dec27fe49fa63048ea06952bb602b98e8abb80d",
|
|
3887
|
+
"801cff771a4640a77d5c07e1d0c45038333650ceb3e169cf0b8c0d1eda22add9"
|
|
3888
|
+
],
|
|
3889
|
+
"cursor-mcp-complete.sh": [
|
|
3890
|
+
"0c7131db3e9007dc1e614cd5a132f08f4ee60030d48c0ee3fcb48074ae37c37b"
|
|
3891
|
+
],
|
|
3892
|
+
"cursor-post-tool.sh": [
|
|
3893
|
+
"44971e10d711667a659a493f062cadb4d44545c42aec0bbd24ad3821cfb27594"
|
|
3894
|
+
],
|
|
3895
|
+
"cursor-pre-tool.sh": [
|
|
3896
|
+
"87ed62e2d5976b1c04337b2407f73f86d039751a12a3803ca2f8db1ca3a10446",
|
|
3897
|
+
"d5e397a1a33d300c61ef1afea4208927b3d1cfc292a67bd2b8084dbf718acc52"
|
|
3898
|
+
],
|
|
3899
|
+
"cursor-precompact.sh": [
|
|
3900
|
+
"33faedfd07999296911aa9080a2799938493114ad29878db025d6c42db418f83"
|
|
3901
|
+
],
|
|
3902
|
+
"cursor-response.sh": [
|
|
3903
|
+
"913e2ef96526b092589ac3e744872e8ede47c3a3d280590e356fa406749c5c0c"
|
|
3904
|
+
],
|
|
3905
|
+
"cursor-session-end.sh": [
|
|
3906
|
+
"ce2e29ccab8396b4537ac1217f1152cf4b20f0f8261394742c77ff83572112b0"
|
|
3907
|
+
],
|
|
3908
|
+
"cursor-session-start.sh": [
|
|
3909
|
+
"512047dab51b1ef69338bc8ef6d205d7605f128523bd47a3e296992b720faed5"
|
|
3910
|
+
],
|
|
3911
|
+
"cursor-shell-complete.sh": [
|
|
3912
|
+
"3e1976d565f82b0768f6a76f2aed3636123cf69195854a5b3d574de2035f4879"
|
|
3913
|
+
],
|
|
3914
|
+
"cursor-start.sh": [
|
|
3915
|
+
"23895ab6d2ecaa9fe278b3fb9d53b21418edd7cfac5116d53bd659d4ecbabae3"
|
|
3916
|
+
],
|
|
3917
|
+
"cursor-stop.sh": [
|
|
3918
|
+
"052c9de32572aeb8b5c9d27313cd20a27790a2250ce3c9aeb8e7356a755c5de3",
|
|
3919
|
+
"9fdb148a495a80173a5c8a627cd5f22e02d824ee5cc5e955e13bb5f0dce53d82"
|
|
3920
|
+
],
|
|
3921
|
+
"cursor-subagent-start.sh": [
|
|
3922
|
+
"b614d1619331b2a900046efdf65eb5d759fb301d2aa7a115f0b107b1b41b3eb9"
|
|
3923
|
+
],
|
|
3924
|
+
"cursor-subagent-stop.sh": [
|
|
3925
|
+
"96d68c3ce020ad8ded49088e5665c3813c89539a0f15e6fda37a50beba08e7ca"
|
|
3926
|
+
],
|
|
3927
|
+
"cursor-thought.sh": [
|
|
3928
|
+
"79b5e73597df5eeec14c3327371f177eabc825edd593aea3c1012e7ae1ea4139"
|
|
3929
|
+
],
|
|
3930
|
+
"gemini-after-agent.sh": [
|
|
3931
|
+
"3c974a52bad64246a40a9cb58f1efa0ec3530be49b1e4a6e980f8469127ce70f"
|
|
3932
|
+
],
|
|
3933
|
+
"gemini-after-model.sh": [
|
|
3934
|
+
"ee5421957f1a9c31bd333df1b012a3ba56ac1e2b2bd7cad9c8fb300bb2c0faf2"
|
|
3935
|
+
],
|
|
3936
|
+
"gemini-after-tool.sh": [
|
|
3937
|
+
"46a3b655e295562301ebf54fce0fb271fbfa61679a8deb3fbab6affc7433d57e"
|
|
3938
|
+
],
|
|
3939
|
+
"gemini-before-agent.sh": [
|
|
3940
|
+
"4e3f6e8b04e1027562e55d13faa4c9521b665ef0299155a6da320a2c96d38f78"
|
|
3941
|
+
],
|
|
3942
|
+
"gemini-before-model.sh": [
|
|
3943
|
+
"b074d767fe5e211a7f6434db1d2b02c6761df73b01f8defa703691cd1d986485"
|
|
3944
|
+
],
|
|
3945
|
+
"gemini-before-tool.sh": [
|
|
3946
|
+
"65c12342fd73cd200c6b6934b3742390e2f2d16524f9d643889c6b1107762ca9",
|
|
3947
|
+
"222623ee4dd6ddd592d8aa0bcf3553d1acda3a2543cf6528bb3cabb50d2cb593"
|
|
3948
|
+
],
|
|
3949
|
+
"gemini-notification.sh": [
|
|
3950
|
+
"5978c5d4b689f2e87131d9950b50588a4aa74390b548a43c3ea6e607fe407e16"
|
|
3951
|
+
],
|
|
3952
|
+
"gemini-session-end.sh": [
|
|
3953
|
+
"326b0db81850cbc63008815c27f8b0b6ab5af0e6d7692a7e9a9bc5b7cca79f9e"
|
|
3954
|
+
],
|
|
3955
|
+
"gemini-session-start.sh": [
|
|
3956
|
+
"5d1113f25accd644c82e21bbc7efc56739f549b6b8227bd8874afc6500112b46"
|
|
3957
|
+
],
|
|
3958
|
+
"gemini-stop.sh": [
|
|
3959
|
+
"da82707cd945b2307efa0a137e54f3dc9a630b2d02a5056d676ad49712f8534f",
|
|
3960
|
+
"dbf663489b778e8be2665f48ad601b99d43ae2462c43936276cb354505870ad8"
|
|
3961
|
+
],
|
|
3962
|
+
"github-error.sh": [
|
|
3963
|
+
"e4dd8874cb837727c795a095ea5829eaa9d350ef65ab4c9fb802334558c44859"
|
|
3964
|
+
],
|
|
3965
|
+
"github-post-tool.sh": [
|
|
3966
|
+
"e057c5f624d7d4998ea59ef524b97b2364f860477a6aadd2512d562cdecfc6c2"
|
|
3967
|
+
],
|
|
3968
|
+
"github-pre-tool.sh": [
|
|
3969
|
+
"1066e08beb1ff864a8075cf9cd77ab1b64e5913f30675edd97cbb58e5fa05a7b",
|
|
3970
|
+
"a331d5980824db7ca38a586f5f6398627b6653397eb4d5bcd19b18a293479c38"
|
|
3971
|
+
],
|
|
3972
|
+
"github-precompact.sh": [
|
|
3973
|
+
"f34011aa926611fe8691ef24250ab22561ff6c0387d3e3527e52d44c7aac6f44"
|
|
3974
|
+
],
|
|
3975
|
+
"github-session-end.sh": [
|
|
3976
|
+
"370fa14d68739b398233d60982cefd6dc946e3be6f4c3560b0a6e8652928f2d9"
|
|
3977
|
+
],
|
|
3978
|
+
"github-session-start.sh": [
|
|
3979
|
+
"505f44ed4ca6345b8e9ff8a328198ed6141d4774a630821b984ab5cf4c3954ff"
|
|
3980
|
+
],
|
|
3981
|
+
"github-stop.sh": [
|
|
3982
|
+
"07f2d802700cf7ace009207aaa3f9c96e4e5943c022faa9601d9b85277e50fa4",
|
|
3983
|
+
"3f4d12832b22be48d708eb70f1bcb00d4c437a19c898e17a0989ab29d3efe4b4"
|
|
3984
|
+
],
|
|
3985
|
+
"github-subagent-start.sh": [
|
|
3986
|
+
"506e39c02806ca20e8a3605a0de3eb089d9ef98d3556ceb675a70433ea313889"
|
|
3987
|
+
],
|
|
3988
|
+
"github-subagent-stop.sh": [
|
|
3989
|
+
"27cab61bdad7c7efddb8be43bcc8cedb03d0789d1288db933386c185b02c0027"
|
|
3990
|
+
],
|
|
3991
|
+
"github-user-prompt.sh": [
|
|
3992
|
+
"67ac8e7c33991402cc2dfcaf6b3380ba50b92cf224fcb447c2bb39cbd7c7a1a8"
|
|
3993
|
+
],
|
|
3994
|
+
"notify-hook.sh": [
|
|
3995
|
+
"0892b3f3b71b8f7df08917ad4f38baac1655093a38f5d43238aca49b9f0554a1",
|
|
3996
|
+
"04013b4988d2d663279f6e75838244aad16247ccec7c37df1c4b5c4413505a05"
|
|
3997
|
+
],
|
|
3998
|
+
"openhands-hook.sh": [
|
|
3999
|
+
"ebdb17e34918e6e58e9ab70e2db9521f25b1907f9cd96d78d217074db64fc566",
|
|
4000
|
+
"f1c09c383891d2dd0048f74ab5c71a3d1a027d2a50a75ac1dc0cdee72c9772f2"
|
|
4001
|
+
],
|
|
4002
|
+
"windsurf-hook.sh": [
|
|
4003
|
+
"16a73925f6a2b2fb3a9e29166316519bb5f5afd05bbed0df80513b004434ebd8",
|
|
4004
|
+
"94753235d4de704a9a0399f734912000e23f9cd15ee1e494f584a0b49ebfda24"
|
|
4005
|
+
]
|
|
4006
|
+
};
|
|
4007
|
+
|
|
4008
|
+
// src/host-command.ts
|
|
4009
|
+
import { execFileSync } from "node:child_process";
|
|
4010
|
+
var HOST_COMMAND_TIMEOUT_MS = 30000;
|
|
4011
|
+
var PACKAGE_INSTALL_TIMEOUT_MS = 180000;
|
|
4012
|
+
function runHostCommand(file, args, options = {}) {
|
|
4013
|
+
const timeout = options.timeoutMs ?? HOST_COMMAND_TIMEOUT_MS;
|
|
4014
|
+
const interactive = options.interactive === true && process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
4015
|
+
try {
|
|
4016
|
+
return execFileSync(file, args, {
|
|
4017
|
+
encoding: "utf8",
|
|
4018
|
+
stdio: interactive ? "inherit" : ["ignore", "pipe", "pipe"],
|
|
4019
|
+
timeout: interactive ? undefined : timeout,
|
|
4020
|
+
killSignal: "SIGTERM",
|
|
4021
|
+
shell: process.platform === "win32" && file === "pi"
|
|
4022
|
+
}) ?? "";
|
|
4023
|
+
} catch (error) {
|
|
4024
|
+
if (error.code === "ETIMEDOUT") {
|
|
4025
|
+
throw new Error(`${file} ${args.slice(0, 3).join(" ")} timed out after ${timeout / 1000}s. Setup may be partial; check the host before retrying.`);
|
|
4026
|
+
}
|
|
4027
|
+
throw error;
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
|
|
3315
4031
|
// src/hermes-follow-up.ts
|
|
3316
|
-
|
|
3317
|
-
function enableHermesFollowUp(profile, run = (file, args) => execFileSync(file, args, { stdio: "pipe", timeout: 30000 })) {
|
|
4032
|
+
function enableHermesFollowUp(profile, run = (file, args) => runHostCommand(file, args)) {
|
|
3318
4033
|
if (!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(profile)) {
|
|
3319
4034
|
throw new Error("Invalid Hermes profile name");
|
|
3320
4035
|
}
|
|
@@ -3408,63 +4123,30 @@ Configured on this computer: ${ready.join(", ")}. Nothing was changed.`);
|
|
|
3408
4123
|
}
|
|
3409
4124
|
|
|
3410
4125
|
// src/cli.ts
|
|
3411
|
-
var VERSION = "0.1
|
|
4126
|
+
var VERSION = "0.2.1";
|
|
3412
4127
|
function getApiUrl() {
|
|
3413
4128
|
return process.env.AGENTAPPROVE_API || "https://api.agentapprove.com";
|
|
3414
4129
|
}
|
|
3415
4130
|
function getXdgConfigHome() {
|
|
3416
|
-
return process.env.XDG_CONFIG_HOME ||
|
|
4131
|
+
return process.env.XDG_CONFIG_HOME || join3(homedir(), ".config");
|
|
3417
4132
|
}
|
|
3418
4133
|
function getOpenCodeConfigDir() {
|
|
3419
|
-
return
|
|
4134
|
+
return join3(getXdgConfigHome(), "opencode");
|
|
3420
4135
|
}
|
|
3421
4136
|
function getOpenCodeConfigPath() {
|
|
3422
|
-
return
|
|
4137
|
+
return join3(getOpenCodeConfigDir(), "opencode.json");
|
|
3423
4138
|
}
|
|
3424
4139
|
function getXdgCacheHome() {
|
|
3425
|
-
return process.env.XDG_CACHE_HOME ||
|
|
4140
|
+
return process.env.XDG_CACHE_HOME || join3(homedir(), ".cache");
|
|
3426
4141
|
}
|
|
3427
4142
|
function getOpenCodeCacheDir() {
|
|
3428
|
-
return
|
|
4143
|
+
return join3(getXdgCacheHome(), "opencode");
|
|
3429
4144
|
}
|
|
3430
4145
|
var API_URL = getApiUrl();
|
|
3431
4146
|
var API_VERSION = process.env.AGENTAPPROVE_API_VERSION || "v001";
|
|
3432
4147
|
function hasFlag2(flag) {
|
|
3433
4148
|
return process.argv.slice(2).includes(flag);
|
|
3434
4149
|
}
|
|
3435
|
-
function updateEnvValue(key, value) {
|
|
3436
|
-
const envPath = join(getAgentApproveDir(), "env");
|
|
3437
|
-
let content;
|
|
3438
|
-
try {
|
|
3439
|
-
content = readFileSync(envPath, "utf-8");
|
|
3440
|
-
} catch (err) {
|
|
3441
|
-
if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
3442
|
-
return;
|
|
3443
|
-
}
|
|
3444
|
-
throw err;
|
|
3445
|
-
}
|
|
3446
|
-
const lines = content.endsWith(`
|
|
3447
|
-
`) ? content.slice(0, -1).split(`
|
|
3448
|
-
`) : content.split(`
|
|
3449
|
-
`);
|
|
3450
|
-
let seenKey = false;
|
|
3451
|
-
const updatedLines = lines.flatMap((line) => {
|
|
3452
|
-
const trimmed = line.replace(/^export\s+/, "").trim();
|
|
3453
|
-
const eqIdx = trimmed.indexOf("=");
|
|
3454
|
-
if (eqIdx <= 0 || trimmed.slice(0, eqIdx) !== key)
|
|
3455
|
-
return [line];
|
|
3456
|
-
if (seenKey)
|
|
3457
|
-
return [];
|
|
3458
|
-
seenKey = true;
|
|
3459
|
-
return [`${key}=${value}`];
|
|
3460
|
-
});
|
|
3461
|
-
if (!seenKey) {
|
|
3462
|
-
updatedLines.push(`${key}=${value}`);
|
|
3463
|
-
}
|
|
3464
|
-
writeFileSync(envPath, `${updatedLines.join(`
|
|
3465
|
-
`)}
|
|
3466
|
-
`, { mode: 384 });
|
|
3467
|
-
}
|
|
3468
4150
|
function getCommand() {
|
|
3469
4151
|
const args = process.argv.slice(2);
|
|
3470
4152
|
const filtered = [];
|
|
@@ -3480,19 +4162,19 @@ function getCommand() {
|
|
|
3480
4162
|
}
|
|
3481
4163
|
return filtered[0] || "install";
|
|
3482
4164
|
}
|
|
3483
|
-
var OPENCODE_PLUGIN_VERSION = "0.1.
|
|
4165
|
+
var OPENCODE_PLUGIN_VERSION = "0.1.27";
|
|
3484
4166
|
var OPENCODE_PLUGIN_SPEC = `@agentapprove/opencode@${OPENCODE_PLUGIN_VERSION}`;
|
|
3485
|
-
var OPENCLAW_PLUGIN_VERSION = "0.2.
|
|
4167
|
+
var OPENCLAW_PLUGIN_VERSION = "0.2.22";
|
|
3486
4168
|
var OPENCLAW_PLUGIN_SPEC = `@agentapprove/openclaw@${OPENCLAW_PLUGIN_VERSION}`;
|
|
3487
|
-
var PI_PLUGIN_VERSION = "0.1.
|
|
4169
|
+
var PI_PLUGIN_VERSION = "0.1.15";
|
|
3488
4170
|
var PI_PLUGIN_SPEC = `npm:@agentapprove/pi@${PI_PLUGIN_VERSION}`;
|
|
3489
4171
|
var PI_STATUS_TIMEOUT_MS = 5000;
|
|
3490
|
-
var HERMES_PLUGIN_VERSION = "0.1.
|
|
4172
|
+
var HERMES_PLUGIN_VERSION = "0.1.17";
|
|
3491
4173
|
var HERMES_PIP_DEPS = ["cryptography>=44.0,<46", "httpx>=0.27,<0.29"];
|
|
3492
4174
|
var AGENTS = {
|
|
3493
4175
|
"claude-code": {
|
|
3494
4176
|
name: "Claude Code",
|
|
3495
|
-
configPath:
|
|
4177
|
+
configPath: join3(homedir(), ".claude", "settings.json"),
|
|
3496
4178
|
hooksKey: "hooks",
|
|
3497
4179
|
hooks: [
|
|
3498
4180
|
{ name: "PreToolUse", file: "claude-pre-tool.sh", description: "Before tool execution (approval)", hasMatcher: true, isApprovalHook: true, timeout: 300 },
|
|
@@ -3509,7 +4191,7 @@ var AGENTS = {
|
|
|
3509
4191
|
},
|
|
3510
4192
|
cursor: {
|
|
3511
4193
|
name: "Cursor",
|
|
3512
|
-
configPath:
|
|
4194
|
+
configPath: join3(homedir(), ".cursor", "hooks.json"),
|
|
3513
4195
|
hooksKey: "hooks",
|
|
3514
4196
|
hooks: [
|
|
3515
4197
|
{ name: "sessionStart", file: "cursor-session-start.sh", description: "Session started" },
|
|
@@ -3531,7 +4213,7 @@ var AGENTS = {
|
|
|
3531
4213
|
},
|
|
3532
4214
|
windsurf: {
|
|
3533
4215
|
name: "Windsurf",
|
|
3534
|
-
configPath:
|
|
4216
|
+
configPath: join3(homedir(), ".codeium", "windsurf", "hooks.json"),
|
|
3535
4217
|
hooksKey: "hooks",
|
|
3536
4218
|
hooks: [
|
|
3537
4219
|
{ name: "pre_user_prompt", file: "windsurf-hook.sh", description: "User prompt (logging only)" },
|
|
@@ -3548,7 +4230,7 @@ var AGENTS = {
|
|
|
3548
4230
|
},
|
|
3549
4231
|
antigravity: {
|
|
3550
4232
|
name: "Antigravity",
|
|
3551
|
-
configPath:
|
|
4233
|
+
configPath: join3(homedir(), ".gemini", "config", "plugins", "agentapprove", "hooks.json"),
|
|
3552
4234
|
hooksKey: "antigravityPlugin",
|
|
3553
4235
|
hooks: [
|
|
3554
4236
|
{ name: "PreToolUse", file: "antigravity-hook.sh", description: "Tool approval", isApprovalHook: true, timeout: 300 },
|
|
@@ -3560,7 +4242,7 @@ var AGENTS = {
|
|
|
3560
4242
|
},
|
|
3561
4243
|
"gemini-cli": {
|
|
3562
4244
|
name: "Gemini CLI (legacy)",
|
|
3563
|
-
configPath:
|
|
4245
|
+
configPath: join3(homedir(), ".gemini", "settings.json"),
|
|
3564
4246
|
hooksKey: "hooks",
|
|
3565
4247
|
hooks: [
|
|
3566
4248
|
{ name: "SessionStart", file: "gemini-session-start.sh", description: "Session started" },
|
|
@@ -3576,7 +4258,7 @@ var AGENTS = {
|
|
|
3576
4258
|
},
|
|
3577
4259
|
"antigravity-cli": {
|
|
3578
4260
|
name: "Antigravity CLI",
|
|
3579
|
-
configPath:
|
|
4261
|
+
configPath: join3(homedir(), ".gemini", "antigravity-cli", "plugins", "agentapprove", "hooks.json"),
|
|
3580
4262
|
hooksKey: "antigravityPlugin",
|
|
3581
4263
|
hooks: [
|
|
3582
4264
|
{ name: "PreToolUse", file: "antigravity-hook.sh", description: "Tool approval", isApprovalHook: true, timeout: 300 },
|
|
@@ -3588,7 +4270,7 @@ var AGENTS = {
|
|
|
3588
4270
|
},
|
|
3589
4271
|
"vscode-agent": {
|
|
3590
4272
|
name: "VS Code GitHub Copilot",
|
|
3591
|
-
configPath:
|
|
4273
|
+
configPath: join3(homedir(), ".agentapprove", "hooks", "vscode-hooks.json"),
|
|
3592
4274
|
hooksKey: "hooks",
|
|
3593
4275
|
hooks: [
|
|
3594
4276
|
{ name: "SessionStart", file: "github-session-start.sh", description: "Session started" },
|
|
@@ -3603,7 +4285,7 @@ var AGENTS = {
|
|
|
3603
4285
|
},
|
|
3604
4286
|
"copilot-cli": {
|
|
3605
4287
|
name: "GitHub Copilot CLI",
|
|
3606
|
-
configPath:
|
|
4288
|
+
configPath: join3(homedir(), ".agentapprove", "copilot-cli-hooks.json"),
|
|
3607
4289
|
hooksKey: "hooks",
|
|
3608
4290
|
hooks: [
|
|
3609
4291
|
{ name: "sessionStart", file: "github-session-start.sh", description: "Session started" },
|
|
@@ -3616,7 +4298,7 @@ var AGENTS = {
|
|
|
3616
4298
|
},
|
|
3617
4299
|
openclaw: {
|
|
3618
4300
|
name: "OpenClaw",
|
|
3619
|
-
configPath:
|
|
4301
|
+
configPath: join3(homedir(), ".openclaw", "openclaw.json"),
|
|
3620
4302
|
hooksKey: "plugins",
|
|
3621
4303
|
hooks: [
|
|
3622
4304
|
{ name: "agentapprove", file: "@agentapprove/openclaw", description: "Tool approval + event monitoring", isApprovalHook: true, isPlugin: true }
|
|
@@ -3624,7 +4306,7 @@ var AGENTS = {
|
|
|
3624
4306
|
},
|
|
3625
4307
|
codex: {
|
|
3626
4308
|
name: "OpenAI Codex",
|
|
3627
|
-
configPath:
|
|
4309
|
+
configPath: join3(homedir(), ".codex", "hooks.json"),
|
|
3628
4310
|
hooksKey: "hooks",
|
|
3629
4311
|
hooks: [
|
|
3630
4312
|
{ name: "SubagentStart", file: "codex-subagent-start.sh", description: "Subagent started", hasMatcher: true },
|
|
@@ -3646,7 +4328,7 @@ var AGENTS = {
|
|
|
3646
4328
|
},
|
|
3647
4329
|
pi: {
|
|
3648
4330
|
name: "Pi",
|
|
3649
|
-
configPath:
|
|
4331
|
+
configPath: join3(homedir(), ".pi", "agent", "settings.json"),
|
|
3650
4332
|
hooksKey: "packages",
|
|
3651
4333
|
hooks: [
|
|
3652
4334
|
{ name: "agentapprove", file: "@agentapprove/pi", description: "Tool approval + event monitoring", isApprovalHook: true, isPlugin: true }
|
|
@@ -3654,7 +4336,7 @@ var AGENTS = {
|
|
|
3654
4336
|
},
|
|
3655
4337
|
hermes: {
|
|
3656
4338
|
name: "Hermes",
|
|
3657
|
-
configPath:
|
|
4339
|
+
configPath: join3(homedir(), ".hermes", "config.yaml"),
|
|
3658
4340
|
hooksKey: "plugins",
|
|
3659
4341
|
hooks: [
|
|
3660
4342
|
{ name: "agentapprove", file: "agentapprove", description: "Tool approval + event monitoring + follow-up input", isApprovalHook: true, isPlugin: true }
|
|
@@ -3662,7 +4344,7 @@ var AGENTS = {
|
|
|
3662
4344
|
},
|
|
3663
4345
|
openhands: {
|
|
3664
4346
|
name: "OpenHands",
|
|
3665
|
-
configPath:
|
|
4347
|
+
configPath: join3(homedir(), ".openhands", "hooks.json"),
|
|
3666
4348
|
hooksKey: "",
|
|
3667
4349
|
hooks: [
|
|
3668
4350
|
{ name: "session_start", file: "openhands-hook.sh", description: "Session started" },
|
|
@@ -3780,11 +4462,11 @@ function findGitBash() {
|
|
|
3780
4462
|
process.env.CLAUDE_CODE_GIT_BASH_PATH,
|
|
3781
4463
|
"C:\\Program Files\\Git\\bin\\bash.exe",
|
|
3782
4464
|
"C:\\Program Files (x86)\\Git\\bin\\bash.exe",
|
|
3783
|
-
|
|
3784
|
-
|
|
4465
|
+
join3(process.env.LOCALAPPDATA || "", "Programs", "Git", "bin", "bash.exe"),
|
|
4466
|
+
join3(process.env.ProgramW6432 || "", "Git", "bin", "bash.exe")
|
|
3785
4467
|
].filter(Boolean);
|
|
3786
4468
|
for (const candidate of candidates) {
|
|
3787
|
-
if (
|
|
4469
|
+
if (existsSync5(candidate)) {
|
|
3788
4470
|
return candidate;
|
|
3789
4471
|
}
|
|
3790
4472
|
}
|
|
@@ -3792,7 +4474,7 @@ function findGitBash() {
|
|
|
3792
4474
|
const result = execSync("where bash", { encoding: "utf-8", stdio: ["pipe", "pipe", "ignore"] });
|
|
3793
4475
|
const firstLine = result.trim().split(`
|
|
3794
4476
|
`)[0];
|
|
3795
|
-
if (firstLine &&
|
|
4477
|
+
if (firstLine && existsSync5(firstLine)) {
|
|
3796
4478
|
return firstLine;
|
|
3797
4479
|
}
|
|
3798
4480
|
} catch {}
|
|
@@ -3821,9 +4503,9 @@ function buildAntigravityHookCommand(hookScriptPath, agentId, hookName, mode) {
|
|
|
3821
4503
|
}
|
|
3822
4504
|
function getAntigravityPluginRoot(agentId) {
|
|
3823
4505
|
if (agentId === "antigravity-cli") {
|
|
3824
|
-
return
|
|
4506
|
+
return join3(homedir(), ".gemini", "antigravity-cli", "plugins", "agentapprove");
|
|
3825
4507
|
}
|
|
3826
|
-
return
|
|
4508
|
+
return join3(homedir(), ".gemini", "config", "plugins", "agentapprove");
|
|
3827
4509
|
}
|
|
3828
4510
|
function getAntigravityPluginManifest() {
|
|
3829
4511
|
return {
|
|
@@ -3837,7 +4519,7 @@ function buildAntigravityHooksJson(agentId, hooksDir, mode) {
|
|
|
3837
4519
|
const hooksToInstall = mode === "observe" ? agent.hooks.filter((h) => h.name !== "Stop") : agent.hooks;
|
|
3838
4520
|
const bundle = { enabled: true };
|
|
3839
4521
|
for (const hook of hooksToInstall) {
|
|
3840
|
-
const hookPath =
|
|
4522
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
3841
4523
|
const hookCommand = buildAntigravityHookCommand(hookPath, agentId, hook.name, mode);
|
|
3842
4524
|
const hookTimeout = hook.timeout ?? 30;
|
|
3843
4525
|
const commandHook = {
|
|
@@ -3861,11 +4543,11 @@ function buildAntigravityHooksJson(agentId, hooksDir, mode) {
|
|
|
3861
4543
|
function installAntigravityPluginBundle(agentId, hooksDir, mode) {
|
|
3862
4544
|
const agent = AGENTS[agentId];
|
|
3863
4545
|
const pluginRoot = getAntigravityPluginRoot(agentId);
|
|
3864
|
-
const hooksPath =
|
|
3865
|
-
const manifestPath =
|
|
4546
|
+
const hooksPath = join3(pluginRoot, "hooks.json");
|
|
4547
|
+
const manifestPath = join3(pluginRoot, "plugin.json");
|
|
3866
4548
|
const backupPath = backupConfig(hooksPath);
|
|
3867
4549
|
try {
|
|
3868
|
-
|
|
4550
|
+
mkdirSync3(pluginRoot, { recursive: true });
|
|
3869
4551
|
writeJsonConfig(manifestPath, getAntigravityPluginManifest());
|
|
3870
4552
|
writeJsonConfig(hooksPath, buildAntigravityHooksJson(agentId, hooksDir, mode));
|
|
3871
4553
|
} catch (err) {
|
|
@@ -3882,77 +4564,20 @@ function installAntigravityPluginBundle(agentId, hooksDir, mode) {
|
|
|
3882
4564
|
function getVSCodeSettingsPaths() {
|
|
3883
4565
|
const paths = [];
|
|
3884
4566
|
if (process.platform === "darwin") {
|
|
3885
|
-
paths.push({ path:
|
|
3886
|
-
paths.push({ path:
|
|
4567
|
+
paths.push({ path: join3(homedir(), "Library", "Application Support", "Code", "User", "settings.json"), variant: "VS Code" });
|
|
4568
|
+
paths.push({ path: join3(homedir(), "Library", "Application Support", "Code - Insiders", "User", "settings.json"), variant: "VS Code Insiders" });
|
|
3887
4569
|
} else if (process.platform === "win32") {
|
|
3888
|
-
const appdata = process.env.APPDATA ||
|
|
3889
|
-
paths.push({ path:
|
|
3890
|
-
paths.push({ path:
|
|
4570
|
+
const appdata = process.env.APPDATA || join3(homedir(), "AppData", "Roaming");
|
|
4571
|
+
paths.push({ path: join3(appdata, "Code", "User", "settings.json"), variant: "VS Code" });
|
|
4572
|
+
paths.push({ path: join3(appdata, "Code - Insiders", "User", "settings.json"), variant: "VS Code Insiders" });
|
|
3891
4573
|
} else {
|
|
3892
|
-
paths.push({ path:
|
|
3893
|
-
paths.push({ path:
|
|
4574
|
+
paths.push({ path: join3(homedir(), ".config", "Code", "User", "settings.json"), variant: "VS Code" });
|
|
4575
|
+
paths.push({ path: join3(homedir(), ".config", "Code - Insiders", "User", "settings.json"), variant: "VS Code Insiders" });
|
|
3894
4576
|
}
|
|
3895
4577
|
return paths;
|
|
3896
4578
|
}
|
|
3897
4579
|
function findInstalledVSCodeVariants() {
|
|
3898
|
-
return getVSCodeSettingsPaths().filter(({ path }) =>
|
|
3899
|
-
}
|
|
3900
|
-
function stripJsonComments(content) {
|
|
3901
|
-
let result = "";
|
|
3902
|
-
let inString = false;
|
|
3903
|
-
let escaped = false;
|
|
3904
|
-
let i = 0;
|
|
3905
|
-
while (i < content.length) {
|
|
3906
|
-
const ch = content[i];
|
|
3907
|
-
if (escaped) {
|
|
3908
|
-
result += ch;
|
|
3909
|
-
escaped = false;
|
|
3910
|
-
i++;
|
|
3911
|
-
continue;
|
|
3912
|
-
}
|
|
3913
|
-
if (ch === "\\" && inString) {
|
|
3914
|
-
result += ch;
|
|
3915
|
-
escaped = true;
|
|
3916
|
-
i++;
|
|
3917
|
-
continue;
|
|
3918
|
-
}
|
|
3919
|
-
if (ch === '"') {
|
|
3920
|
-
inString = !inString;
|
|
3921
|
-
result += ch;
|
|
3922
|
-
i++;
|
|
3923
|
-
continue;
|
|
3924
|
-
}
|
|
3925
|
-
if (!inString) {
|
|
3926
|
-
if (ch === "/" && content[i + 1] === "/") {
|
|
3927
|
-
while (i < content.length && content[i] !== `
|
|
3928
|
-
`)
|
|
3929
|
-
i++;
|
|
3930
|
-
continue;
|
|
3931
|
-
}
|
|
3932
|
-
if (ch === "/" && content[i + 1] === "*") {
|
|
3933
|
-
i += 2;
|
|
3934
|
-
while (i < content.length && !(content[i] === "*" && content[i + 1] === "/"))
|
|
3935
|
-
i++;
|
|
3936
|
-
i += 2;
|
|
3937
|
-
continue;
|
|
3938
|
-
}
|
|
3939
|
-
}
|
|
3940
|
-
result += ch;
|
|
3941
|
-
i++;
|
|
3942
|
-
}
|
|
3943
|
-
result = result.replace(/,(\s*[}\]])/g, "$1");
|
|
3944
|
-
return result;
|
|
3945
|
-
}
|
|
3946
|
-
function readJsoncConfig(configPath) {
|
|
3947
|
-
if (!existsSync2(configPath))
|
|
3948
|
-
return {};
|
|
3949
|
-
try {
|
|
3950
|
-
const content = readFileSync(configPath, "utf-8");
|
|
3951
|
-
const stripped = stripJsonComments(content);
|
|
3952
|
-
return JSON.parse(stripped);
|
|
3953
|
-
} catch {
|
|
3954
|
-
return {};
|
|
3955
|
-
}
|
|
4580
|
+
return getVSCodeSettingsPaths().filter(({ path }) => existsSync5(dirname4(path)));
|
|
3956
4581
|
}
|
|
3957
4582
|
function getGithubHookEnv(agentId) {
|
|
3958
4583
|
if (agentId === "vscode-agent") {
|
|
@@ -3963,9 +4588,20 @@ function getGithubHookEnv(agentId) {
|
|
|
3963
4588
|
}
|
|
3964
4589
|
return;
|
|
3965
4590
|
}
|
|
4591
|
+
var JSONC_CONFIG_AGENTS = new Set(["gemini-cli"]);
|
|
4592
|
+
function readAgentConfig(agentId, configPath) {
|
|
4593
|
+
return JSONC_CONFIG_AGENTS.has(agentId) ? readJsoncConfig(configPath) : readJsonConfig(configPath);
|
|
4594
|
+
}
|
|
4595
|
+
function keepCommentedConfig(agentId, configPath, existingBackup = null) {
|
|
4596
|
+
if (!JSONC_CONFIG_AGENTS.has(agentId) || !configUsesJsoncSyntax(configPath))
|
|
4597
|
+
return null;
|
|
4598
|
+
const backupPath = existingBackup ?? backupConfig(configPath);
|
|
4599
|
+
return `Comments in ${configPath} are not preserved. The original, with its comments, is in ${backupPath}`;
|
|
4600
|
+
}
|
|
3966
4601
|
function addToVSCodeHookLocations() {
|
|
3967
4602
|
const hookLocation = "~/.agentapprove/hooks";
|
|
3968
4603
|
const modified = [];
|
|
4604
|
+
const failed = [];
|
|
3969
4605
|
for (const { path: settingsPath, variant } of findInstalledVSCodeVariants()) {
|
|
3970
4606
|
try {
|
|
3971
4607
|
const config = readJsoncConfig(settingsPath);
|
|
@@ -3975,17 +4611,20 @@ function addToVSCodeHookLocations() {
|
|
|
3975
4611
|
}
|
|
3976
4612
|
locations[hookLocation] = true;
|
|
3977
4613
|
config["chat.hookFilesLocations"] = locations;
|
|
4614
|
+
backupConfig(settingsPath);
|
|
3978
4615
|
writeJsonConfig(settingsPath, config);
|
|
3979
4616
|
modified.push(`${variant}: ${settingsPath}`);
|
|
3980
|
-
} catch {
|
|
4617
|
+
} catch (error) {
|
|
4618
|
+
failed.push({ variant, path: settingsPath, error: configErrorMessage(error) });
|
|
4619
|
+
}
|
|
3981
4620
|
}
|
|
3982
|
-
return modified;
|
|
4621
|
+
return { modified, failed };
|
|
3983
4622
|
}
|
|
3984
|
-
function removeFromVSCodeHookLocations() {
|
|
4623
|
+
function removeFromVSCodeHookLocations(onFailure) {
|
|
3985
4624
|
const hookLocation = "~/.agentapprove/hooks";
|
|
3986
4625
|
const modified = [];
|
|
3987
4626
|
for (const { path: settingsPath, variant } of getVSCodeSettingsPaths()) {
|
|
3988
|
-
if (!
|
|
4627
|
+
if (!existsSync5(settingsPath))
|
|
3989
4628
|
continue;
|
|
3990
4629
|
try {
|
|
3991
4630
|
const config = readJsoncConfig(settingsPath);
|
|
@@ -3998,9 +4637,12 @@ function removeFromVSCodeHookLocations() {
|
|
|
3998
4637
|
} else {
|
|
3999
4638
|
config["chat.hookFilesLocations"] = locations;
|
|
4000
4639
|
}
|
|
4640
|
+
backupConfig(settingsPath);
|
|
4001
4641
|
writeJsonConfig(settingsPath, config);
|
|
4002
4642
|
modified.push(`${variant}: ${settingsPath}`);
|
|
4003
|
-
} catch {
|
|
4643
|
+
} catch (error) {
|
|
4644
|
+
onFailure?.({ variant, path: settingsPath, error: configErrorMessage(error) });
|
|
4645
|
+
}
|
|
4004
4646
|
}
|
|
4005
4647
|
return modified;
|
|
4006
4648
|
}
|
|
@@ -4012,45 +4654,45 @@ function detectInstalledAgents() {
|
|
|
4012
4654
|
installed.push(id);
|
|
4013
4655
|
}
|
|
4014
4656
|
} else if (id === "copilot-cli") {
|
|
4015
|
-
if (
|
|
4657
|
+
if (existsSync5(join3(homedir(), ".copilot"))) {
|
|
4016
4658
|
installed.push(id);
|
|
4017
4659
|
}
|
|
4018
4660
|
} else if (id === "openclaw") {
|
|
4019
|
-
if (
|
|
4661
|
+
if (existsSync5(join3(homedir(), ".openclaw"))) {
|
|
4020
4662
|
installed.push(id);
|
|
4021
4663
|
}
|
|
4022
4664
|
} else if (id === "codex") {
|
|
4023
|
-
if (
|
|
4665
|
+
if (existsSync5(join3(homedir(), ".codex"))) {
|
|
4024
4666
|
installed.push(id);
|
|
4025
4667
|
}
|
|
4026
4668
|
} else if (id === "opencode") {
|
|
4027
|
-
if (
|
|
4669
|
+
if (existsSync5(getOpenCodeConfigDir())) {
|
|
4028
4670
|
installed.push(id);
|
|
4029
4671
|
}
|
|
4030
4672
|
} else if (id === "pi") {
|
|
4031
|
-
if (
|
|
4673
|
+
if (existsSync5(join3(homedir(), ".pi", "agent"))) {
|
|
4032
4674
|
installed.push(id);
|
|
4033
4675
|
} else {
|
|
4034
4676
|
try {
|
|
4035
|
-
|
|
4677
|
+
runHostCommand("pi", ["--version"], { timeoutMs: 5000 });
|
|
4036
4678
|
installed.push(id);
|
|
4037
4679
|
} catch {}
|
|
4038
4680
|
}
|
|
4039
4681
|
} else if (id === "hermes") {
|
|
4040
|
-
if (
|
|
4682
|
+
if (existsSync5(join3(homedir(), ".hermes"))) {
|
|
4041
4683
|
installed.push(id);
|
|
4042
4684
|
} else {
|
|
4043
4685
|
try {
|
|
4044
|
-
|
|
4686
|
+
runHostCommand("hermes", ["--version"], { timeoutMs: 5000 });
|
|
4045
4687
|
installed.push(id);
|
|
4046
4688
|
} catch {}
|
|
4047
4689
|
}
|
|
4048
4690
|
} else if (id === "antigravity") {
|
|
4049
|
-
if (
|
|
4691
|
+
if (existsSync5(getAntigravityPluginRoot(id)) || existsSync5(join3(homedir(), ".gemini", "antigravity")) || existsSync5(join3(homedir(), ".gemini", "antigravity-ide")) || existsSync5("/Applications/Antigravity.app")) {
|
|
4050
4692
|
installed.push(id);
|
|
4051
4693
|
}
|
|
4052
4694
|
} else if (id === "antigravity-cli") {
|
|
4053
|
-
if (
|
|
4695
|
+
if (existsSync5(join3(homedir(), ".gemini", "antigravity-cli"))) {
|
|
4054
4696
|
installed.push(id);
|
|
4055
4697
|
} else {
|
|
4056
4698
|
try {
|
|
@@ -4059,8 +4701,8 @@ function detectInstalledAgents() {
|
|
|
4059
4701
|
} catch {}
|
|
4060
4702
|
}
|
|
4061
4703
|
} else {
|
|
4062
|
-
const configDir =
|
|
4063
|
-
if (
|
|
4704
|
+
const configDir = dirname4(agent.configPath);
|
|
4705
|
+
if (existsSync5(configDir)) {
|
|
4064
4706
|
installed.push(id);
|
|
4065
4707
|
}
|
|
4066
4708
|
}
|
|
@@ -4220,7 +4862,7 @@ function formatHookStatusLabel(name) {
|
|
|
4220
4862
|
return name.replace(/\*/g, "events").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]/g, " ").replace(/\s+/g, " ").trim().replace(/^./, (letter) => letter.toUpperCase());
|
|
4221
4863
|
}
|
|
4222
4864
|
function getAgentApproveDir() {
|
|
4223
|
-
return
|
|
4865
|
+
return join3(homedir(), ".agentapprove");
|
|
4224
4866
|
}
|
|
4225
4867
|
function uniqueRemovalTargets(targets) {
|
|
4226
4868
|
const seen = new Set;
|
|
@@ -4240,7 +4882,7 @@ function buildUninstallPlan() {
|
|
|
4240
4882
|
const pluginArtifactTargets = uniqueRemovalTargets([
|
|
4241
4883
|
...getOpenClawPluginTargets(AGENTS.openclaw.configPath),
|
|
4242
4884
|
...getOpenCodePluginTargets(getOpenCodeConfigDir(), getOpenCodeCacheDir()),
|
|
4243
|
-
...getAntigravityPluginTargets(
|
|
4885
|
+
...getAntigravityPluginTargets(join3(homedir(), ".gemini"))
|
|
4244
4886
|
]);
|
|
4245
4887
|
return {
|
|
4246
4888
|
configuredAgents,
|
|
@@ -4312,39 +4954,39 @@ async function confirmUninstallPlan(mode, plan) {
|
|
|
4312
4954
|
return true;
|
|
4313
4955
|
}
|
|
4314
4956
|
function pruneEmptyDir(path) {
|
|
4315
|
-
if (!
|
|
4957
|
+
if (!existsSync5(path)) {
|
|
4316
4958
|
return;
|
|
4317
4959
|
}
|
|
4318
4960
|
try {
|
|
4319
4961
|
if (readdirSync2(path).length === 0) {
|
|
4320
|
-
|
|
4962
|
+
rmSync3(path, { recursive: false, force: true });
|
|
4321
4963
|
}
|
|
4322
4964
|
} catch {}
|
|
4323
4965
|
}
|
|
4324
4966
|
function finalizeAgentApproveDirPurge(agentApproveDir) {
|
|
4325
|
-
if (!
|
|
4967
|
+
if (!existsSync5(agentApproveDir)) {
|
|
4326
4968
|
return;
|
|
4327
4969
|
}
|
|
4328
4970
|
try {
|
|
4329
|
-
const stat =
|
|
4971
|
+
const stat = lstatSync2(agentApproveDir);
|
|
4330
4972
|
if (stat.isSymbolicLink()) {
|
|
4331
4973
|
const actualDir = realpathSync2(agentApproveDir);
|
|
4332
|
-
if (
|
|
4333
|
-
|
|
4974
|
+
if (existsSync5(actualDir) && readdirSync2(actualDir).length === 0) {
|
|
4975
|
+
rmSync3(actualDir, { recursive: false, force: true });
|
|
4334
4976
|
}
|
|
4335
|
-
|
|
4977
|
+
rmSync3(agentApproveDir, { recursive: false, force: true });
|
|
4336
4978
|
return;
|
|
4337
4979
|
}
|
|
4338
4980
|
} catch {}
|
|
4339
4981
|
pruneEmptyDir(agentApproveDir);
|
|
4340
4982
|
}
|
|
4341
4983
|
function readExistingConfig() {
|
|
4342
|
-
const envPath =
|
|
4343
|
-
if (!
|
|
4984
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
4985
|
+
if (!existsSync5(envPath)) {
|
|
4344
4986
|
return null;
|
|
4345
4987
|
}
|
|
4346
4988
|
try {
|
|
4347
|
-
const content =
|
|
4989
|
+
const content = readFileSync3(envPath, "utf-8");
|
|
4348
4990
|
const config = {};
|
|
4349
4991
|
for (const line of content.split(`
|
|
4350
4992
|
`)) {
|
|
@@ -4400,28 +5042,28 @@ function readExistingConfig() {
|
|
|
4400
5042
|
}
|
|
4401
5043
|
function discoverE2EKeys() {
|
|
4402
5044
|
const dir = getAgentApproveDir();
|
|
4403
|
-
if (!
|
|
5045
|
+
if (!existsSync5(dir))
|
|
4404
5046
|
return [];
|
|
4405
5047
|
const keys = [];
|
|
4406
|
-
const currentPath =
|
|
4407
|
-
if (
|
|
5048
|
+
const currentPath = join3(dir, "e2e-key");
|
|
5049
|
+
if (existsSync5(currentPath)) {
|
|
4408
5050
|
try {
|
|
4409
|
-
const hex =
|
|
5051
|
+
const hex = readFileSync3(currentPath, "utf-8").trim();
|
|
4410
5052
|
if (hex.length === 64) {
|
|
4411
|
-
const keyId =
|
|
4412
|
-
keys.push({ keyId, keyHex: hex, path: currentPath, isCurrent: true, modifiedAt:
|
|
5053
|
+
const keyId = createHash3("sha256").update(Buffer.from(hex, "hex")).digest("hex").slice(0, 8);
|
|
5054
|
+
keys.push({ keyId, keyHex: hex, path: currentPath, isCurrent: true, modifiedAt: statSync2(currentPath).mtime });
|
|
4413
5055
|
}
|
|
4414
5056
|
} catch {}
|
|
4415
5057
|
}
|
|
4416
5058
|
try {
|
|
4417
5059
|
const files = readdirSync2(dir).filter((f) => f.startsWith("e2e-key.") && f.endsWith(".bak"));
|
|
4418
5060
|
for (const file of files) {
|
|
4419
|
-
const fullPath =
|
|
5061
|
+
const fullPath = join3(dir, file);
|
|
4420
5062
|
try {
|
|
4421
|
-
const hex =
|
|
5063
|
+
const hex = readFileSync3(fullPath, "utf-8").trim();
|
|
4422
5064
|
if (hex.length === 64) {
|
|
4423
|
-
const keyId =
|
|
4424
|
-
keys.push({ keyId, keyHex: hex, path: fullPath, isCurrent: false, modifiedAt:
|
|
5065
|
+
const keyId = createHash3("sha256").update(Buffer.from(hex, "hex")).digest("hex").slice(0, 8);
|
|
5066
|
+
keys.push({ keyId, keyHex: hex, path: fullPath, isCurrent: false, modifiedAt: statSync2(fullPath).mtime });
|
|
4425
5067
|
}
|
|
4426
5068
|
} catch {}
|
|
4427
5069
|
}
|
|
@@ -4429,43 +5071,38 @@ function discoverE2EKeys() {
|
|
|
4429
5071
|
return keys;
|
|
4430
5072
|
}
|
|
4431
5073
|
function readRotationConfig() {
|
|
4432
|
-
const configPath =
|
|
4433
|
-
if (!
|
|
5074
|
+
const configPath = join3(getAgentApproveDir(), "e2e-rotation.json");
|
|
5075
|
+
if (!existsSync5(configPath))
|
|
4434
5076
|
return null;
|
|
4435
5077
|
try {
|
|
4436
|
-
return JSON.parse(
|
|
5078
|
+
return JSON.parse(readFileSync3(configPath, "utf-8"));
|
|
4437
5079
|
} catch {
|
|
4438
5080
|
return null;
|
|
4439
5081
|
}
|
|
4440
5082
|
}
|
|
4441
5083
|
function writeRotationConfig(config) {
|
|
4442
|
-
const configPath =
|
|
4443
|
-
|
|
5084
|
+
const configPath = join3(getAgentApproveDir(), "e2e-rotation.json");
|
|
5085
|
+
writePrivateFile(configPath, JSON.stringify(config, null, 2));
|
|
4444
5086
|
}
|
|
4445
5087
|
function ensureAgentApproveDir() {
|
|
4446
5088
|
const dir = getAgentApproveDir();
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
}
|
|
4450
|
-
const hooksDir = join(dir, "hooks");
|
|
4451
|
-
if (!existsSync2(hooksDir)) {
|
|
4452
|
-
mkdirSync(hooksDir, { recursive: true, mode: 448 });
|
|
4453
|
-
}
|
|
5089
|
+
ensurePrivateDir(dir);
|
|
5090
|
+
ensurePrivateDir(join3(dir, "hooks"));
|
|
4454
5091
|
}
|
|
4455
5092
|
function migrateE2ERootKey() {
|
|
4456
5093
|
const dir = getAgentApproveDir();
|
|
4457
|
-
const keyPath =
|
|
4458
|
-
const rootKeyPath =
|
|
4459
|
-
const rotationPath =
|
|
4460
|
-
if (!
|
|
5094
|
+
const keyPath = join3(dir, "e2e-key");
|
|
5095
|
+
const rootKeyPath = join3(dir, "e2e-root-key");
|
|
5096
|
+
const rotationPath = join3(dir, "e2e-rotation.json");
|
|
5097
|
+
if (!existsSync5(keyPath) || existsSync5(rootKeyPath))
|
|
4461
5098
|
return;
|
|
4462
5099
|
try {
|
|
4463
|
-
const keyHex =
|
|
5100
|
+
const keyHex = readFileSync3(keyPath, "utf-8").trim();
|
|
4464
5101
|
if (keyHex.length !== 64)
|
|
4465
5102
|
return;
|
|
4466
|
-
|
|
4467
|
-
if (!
|
|
4468
|
-
const keyId =
|
|
5103
|
+
writePrivateFile(rootKeyPath, keyHex);
|
|
5104
|
+
if (!existsSync5(rotationPath)) {
|
|
5105
|
+
const keyId = createHash3("sha256").update(Buffer.from(keyHex, "hex")).digest("hex").slice(0, 8);
|
|
4469
5106
|
writeRotationConfig({
|
|
4470
5107
|
rootKeyId: keyId,
|
|
4471
5108
|
epoch: 0,
|
|
@@ -4475,48 +5112,20 @@ function migrateE2ERootKey() {
|
|
|
4475
5112
|
}
|
|
4476
5113
|
} catch {}
|
|
4477
5114
|
}
|
|
4478
|
-
function
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
4483
|
-
const backupPath = `${configPath}.backup.${timestamp}`;
|
|
4484
|
-
copyFileSync(configPath, backupPath);
|
|
4485
|
-
return backupPath;
|
|
4486
|
-
}
|
|
4487
|
-
function readJsonConfig(configPath) {
|
|
4488
|
-
if (!existsSync2(configPath)) {
|
|
4489
|
-
return {};
|
|
4490
|
-
}
|
|
4491
|
-
try {
|
|
4492
|
-
const content = readFileSync(configPath, "utf-8");
|
|
4493
|
-
return JSON.parse(content);
|
|
4494
|
-
} catch {
|
|
4495
|
-
return {};
|
|
4496
|
-
}
|
|
4497
|
-
}
|
|
4498
|
-
function writeJsonConfig(configPath, config) {
|
|
4499
|
-
const dir = dirname2(configPath);
|
|
4500
|
-
if (!existsSync2(dir)) {
|
|
4501
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
4502
|
-
}
|
|
4503
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2) + `
|
|
4504
|
-
`);
|
|
4505
|
-
}
|
|
4506
|
-
function ensureCodexFeatureFlag(configPath = join(homedir(), ".codex", "config.toml")) {
|
|
4507
|
-
const dir = dirname2(configPath);
|
|
4508
|
-
if (!existsSync2(dir)) {
|
|
4509
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
5115
|
+
function ensureCodexFeatureFlag(configPath = join3(homedir(), ".codex", "config.toml")) {
|
|
5116
|
+
const dir = dirname4(configPath);
|
|
5117
|
+
if (!existsSync5(dir)) {
|
|
5118
|
+
mkdirSync3(dir, { recursive: true, mode: 448 });
|
|
4510
5119
|
}
|
|
4511
5120
|
const sectionHeader = "[features]";
|
|
4512
5121
|
const desiredLine = "codex_hooks = true";
|
|
4513
|
-
if (!
|
|
4514
|
-
|
|
5122
|
+
if (!existsSync5(configPath)) {
|
|
5123
|
+
writeFileSync2(configPath, `${sectionHeader}
|
|
4515
5124
|
${desiredLine}
|
|
4516
5125
|
`, { mode: 384 });
|
|
4517
5126
|
return { updated: true, backupPath: null };
|
|
4518
5127
|
}
|
|
4519
|
-
const original =
|
|
5128
|
+
const original = readFileSync3(configPath, "utf-8");
|
|
4520
5129
|
const lines = original.split(/\r?\n/);
|
|
4521
5130
|
const updatedLines = [];
|
|
4522
5131
|
let inFeatures = false;
|
|
@@ -4564,16 +5173,16 @@ ${desiredLine}
|
|
|
4564
5173
|
return { updated: false, backupPath: null };
|
|
4565
5174
|
}
|
|
4566
5175
|
const backupPath = backupConfig(configPath);
|
|
4567
|
-
|
|
5176
|
+
writeFileSync2(configPath, `${updatedLines.join(`
|
|
4568
5177
|
`).replace(/\n*$/, `
|
|
4569
5178
|
`)}`, { mode: 384 });
|
|
4570
5179
|
return { updated: true, backupPath };
|
|
4571
5180
|
}
|
|
4572
|
-
function disableCodexFeatureFlag(configPath =
|
|
4573
|
-
if (!
|
|
5181
|
+
function disableCodexFeatureFlag(configPath = join3(homedir(), ".codex", "config.toml")) {
|
|
5182
|
+
if (!existsSync5(configPath)) {
|
|
4574
5183
|
return { updated: false, backupPath: null };
|
|
4575
5184
|
}
|
|
4576
|
-
const original =
|
|
5185
|
+
const original = readFileSync3(configPath, "utf-8");
|
|
4577
5186
|
const updated = original.split(/\r?\n/).filter((line) => !/^\s*codex_hooks\s*=/.test(line)).join(`
|
|
4578
5187
|
`).replace(/\n*$/, `
|
|
4579
5188
|
`);
|
|
@@ -4581,7 +5190,7 @@ function disableCodexFeatureFlag(configPath = join(homedir(), ".codex", "config.
|
|
|
4581
5190
|
return { updated: false, backupPath: null };
|
|
4582
5191
|
}
|
|
4583
5192
|
const backupPath = backupConfig(configPath);
|
|
4584
|
-
|
|
5193
|
+
writeFileSync2(configPath, updated, { mode: 384 });
|
|
4585
5194
|
return { updated: true, backupPath };
|
|
4586
5195
|
}
|
|
4587
5196
|
async function createPairingSession(configuredAgents, e2eKeyId, apiBaseUrl = API_URL) {
|
|
@@ -4652,7 +5261,8 @@ async function waitForPairing(sessionCode, onProgress, onCancel, apiBaseUrl = AP
|
|
|
4652
5261
|
privacy: result.privacy || "full",
|
|
4653
5262
|
email: result.email || "",
|
|
4654
5263
|
apiUrl: result.apiUrl || apiBaseUrl,
|
|
4655
|
-
e2eServerKey: result.e2eServerKey
|
|
5264
|
+
e2eServerKey: result.e2eServerKey,
|
|
5265
|
+
effectiveConfig: parseEffectivePairingConfig(result.effectiveConfig)
|
|
4656
5266
|
};
|
|
4657
5267
|
}
|
|
4658
5268
|
if (result.status === "expired") {
|
|
@@ -4763,7 +5373,7 @@ async function showPairingPresentation(params) {
|
|
|
4763
5373
|
`);
|
|
4764
5374
|
}
|
|
4765
5375
|
function saveEnvConfig(config) {
|
|
4766
|
-
const envPath =
|
|
5376
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
4767
5377
|
const configSetAt = config.configSetAt ?? Math.floor(Date.now() / 1000);
|
|
4768
5378
|
const hasBackgroundPreference = config.preserved?.AGENTAPPROVE_FILTER_BACKGROUND_ACTIVITY !== undefined;
|
|
4769
5379
|
const preserved = {
|
|
@@ -4805,7 +5415,7 @@ ${renderPreservedEnvSection(preserved)}
|
|
|
4805
5415
|
# manual edits here are overwritten on the next config sync.
|
|
4806
5416
|
# To change settings, run: npx agentapprove install
|
|
4807
5417
|
`;
|
|
4808
|
-
|
|
5418
|
+
writePrivateFile(envPath, content);
|
|
4809
5419
|
}
|
|
4810
5420
|
var KEYCHAIN_SERVICE = "com.agentapprove";
|
|
4811
5421
|
var KEYCHAIN_ACCOUNT = "api-token";
|
|
@@ -4958,8 +5568,14 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4958
5568
|
if (isAntigravityAgent(agentId)) {
|
|
4959
5569
|
return installAntigravityPluginBundle(agentId, hooksDir, mode);
|
|
4960
5570
|
}
|
|
5571
|
+
let config;
|
|
5572
|
+
try {
|
|
5573
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
5574
|
+
} catch (error) {
|
|
5575
|
+
return { success: false, backupPath: null, hooks: [], error: configErrorMessage(error) };
|
|
5576
|
+
}
|
|
4961
5577
|
const backupPath = backupConfig(agent.configPath);
|
|
4962
|
-
const
|
|
5578
|
+
const commentsNote = keepCommentedConfig(agentId, agent.configPath, backupPath);
|
|
4963
5579
|
const useTopLevelHooks = agent.hooksKey === "";
|
|
4964
5580
|
if (!useTopLevelHooks && !config[agent.hooksKey]) {
|
|
4965
5581
|
config[agent.hooksKey] = {};
|
|
@@ -4973,9 +5589,9 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4973
5589
|
mode,
|
|
4974
5590
|
readVersion: readOpenClawInstalledVersion,
|
|
4975
5591
|
readConfig: () => {
|
|
4976
|
-
if (!
|
|
5592
|
+
if (!existsSync5(agent.configPath))
|
|
4977
5593
|
return {};
|
|
4978
|
-
const current = JSON.parse(
|
|
5594
|
+
const current = JSON.parse(readFileSync3(agent.configPath, "utf8"));
|
|
4979
5595
|
if (!current || typeof current !== "object" || Array.isArray(current)) {
|
|
4980
5596
|
throw new Error("OpenClaw configuration must be a JSON object; no settings were overwritten.");
|
|
4981
5597
|
}
|
|
@@ -4994,7 +5610,12 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4994
5610
|
if (!installResult.success) {
|
|
4995
5611
|
return { success: false, backupPath, hooks: [], error: installResult.error };
|
|
4996
5612
|
}
|
|
4997
|
-
|
|
5613
|
+
let opencodeConfig;
|
|
5614
|
+
try {
|
|
5615
|
+
opencodeConfig = readJsonConfig(agent.configPath);
|
|
5616
|
+
} catch (error) {
|
|
5617
|
+
return { success: false, backupPath, hooks: [], error: configErrorMessage(error) };
|
|
5618
|
+
}
|
|
4998
5619
|
if (!Array.isArray(opencodeConfig.plugin)) {
|
|
4999
5620
|
opencodeConfig.plugin = [];
|
|
5000
5621
|
}
|
|
@@ -5004,16 +5625,16 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5004
5625
|
}
|
|
5005
5626
|
opencodeConfig.plugin = pluginArray;
|
|
5006
5627
|
writeJsonConfig(agent.configPath, opencodeConfig);
|
|
5007
|
-
const opencodePkgPath =
|
|
5628
|
+
const opencodePkgPath = join3(getOpenCodeConfigDir(), "package.json");
|
|
5008
5629
|
try {
|
|
5009
|
-
const pkgJson = JSON.parse(
|
|
5630
|
+
const pkgJson = JSON.parse(readFileSync3(opencodePkgPath, "utf-8"));
|
|
5010
5631
|
const deps = pkgJson.dependencies;
|
|
5011
5632
|
if (deps?.["@agentapprove/opencode"]) {
|
|
5012
5633
|
delete deps["@agentapprove/opencode"];
|
|
5013
5634
|
if (Object.keys(deps).length === 0) {
|
|
5014
5635
|
delete pkgJson.dependencies;
|
|
5015
5636
|
}
|
|
5016
|
-
|
|
5637
|
+
writeFileSync2(opencodePkgPath, JSON.stringify(pkgJson, null, 2) + `
|
|
5017
5638
|
`);
|
|
5018
5639
|
}
|
|
5019
5640
|
} catch (err) {
|
|
@@ -5029,7 +5650,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5029
5650
|
}
|
|
5030
5651
|
const hooksToInstall = mode === "observe" ? agent.hooks.filter((h) => !h.isApprovalHook) : agent.hooks;
|
|
5031
5652
|
for (const hook of hooksToInstall) {
|
|
5032
|
-
const hookPath =
|
|
5653
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5033
5654
|
const hookCommand = buildHookCommand(hookPath, agentId);
|
|
5034
5655
|
if (agentId === "claude-code") {
|
|
5035
5656
|
if (!hooksConfig[hook.name]) {
|
|
@@ -5317,7 +5938,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5317
5938
|
if (agentId === "codex") {
|
|
5318
5939
|
ensureCodexFeatureFlag();
|
|
5319
5940
|
}
|
|
5320
|
-
return { success: true, backupPath, hooks: installedHooks };
|
|
5941
|
+
return { success: true, backupPath, hooks: installedHooks, ...commentsNote ? { note: commentsNote } : {} };
|
|
5321
5942
|
}
|
|
5322
5943
|
function getManualInstructions(agentId, hooksDir) {
|
|
5323
5944
|
const agent = AGENTS[agentId];
|
|
@@ -5328,7 +5949,7 @@ function getManualInstructions(agentId, hooksDir) {
|
|
|
5328
5949
|
for (const hook of agent.hooks) {
|
|
5329
5950
|
const hasMatcher = hook.hasMatcher ?? true;
|
|
5330
5951
|
const hookTimeout = hook.timeout;
|
|
5331
|
-
const hookPath =
|
|
5952
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5332
5953
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5333
5954
|
const hookObject = {
|
|
5334
5955
|
type: "command",
|
|
@@ -5346,7 +5967,7 @@ function getManualInstructions(agentId, hooksDir) {
|
|
|
5346
5967
|
for (const hook of agent.hooks) {
|
|
5347
5968
|
const hasMatcher = hook.hasMatcher ?? true;
|
|
5348
5969
|
const hookTimeout = hook.timeout;
|
|
5349
|
-
const hookPath =
|
|
5970
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5350
5971
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5351
5972
|
const hookObject = {
|
|
5352
5973
|
type: "command",
|
|
@@ -5366,7 +5987,7 @@ codex_hooks = true`;
|
|
|
5366
5987
|
} else if (agentId === "cursor") {
|
|
5367
5988
|
const hooksObj = {};
|
|
5368
5989
|
for (const hook of agent.hooks) {
|
|
5369
|
-
const hookPath =
|
|
5990
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5370
5991
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5371
5992
|
const entry = cursorHookEntry(hook.name, hookCmd, hook.isApprovalHook);
|
|
5372
5993
|
hooksObj[hook.name] = [entry];
|
|
@@ -5375,7 +5996,7 @@ codex_hooks = true`;
|
|
|
5375
5996
|
} else if (agentId === "windsurf") {
|
|
5376
5997
|
const hooksObj = {};
|
|
5377
5998
|
for (const hook of agent.hooks) {
|
|
5378
|
-
const hookPath =
|
|
5999
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5379
6000
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5380
6001
|
hooksObj[hook.name] = [{ command: hookCmd, show_output: false }];
|
|
5381
6002
|
}
|
|
@@ -5384,7 +6005,7 @@ codex_hooks = true`;
|
|
|
5384
6005
|
const hooksObj = {};
|
|
5385
6006
|
for (const hook of agent.hooks) {
|
|
5386
6007
|
const hookTimeout = hook.timeout;
|
|
5387
|
-
const hookCmd = buildHookCommand(
|
|
6008
|
+
const hookCmd = buildHookCommand(join3(hooksDir, hook.file), agentId);
|
|
5388
6009
|
const hookObject = hookTimeout ? { type: "command", command: hookCmd, timeout: hookTimeout * 1000 } : { type: "command", command: hookCmd };
|
|
5389
6010
|
hooksObj[hook.name] = [{ hooks: [hookObject] }];
|
|
5390
6011
|
}
|
|
@@ -5404,7 +6025,7 @@ codex_hooks = true`;
|
|
|
5404
6025
|
} else if (agentId === "vscode-agent") {
|
|
5405
6026
|
const hooksObj = {};
|
|
5406
6027
|
for (const hook of agent.hooks) {
|
|
5407
|
-
const hookPath =
|
|
6028
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5408
6029
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5409
6030
|
const isApproval = hook.isApprovalHook;
|
|
5410
6031
|
const hookTimeout = hook.timeout;
|
|
@@ -5425,7 +6046,7 @@ codex_hooks = true`;
|
|
|
5425
6046
|
} else if (agentId === "copilot-cli") {
|
|
5426
6047
|
const hooksObj = {};
|
|
5427
6048
|
for (const hook of agent.hooks) {
|
|
5428
|
-
const hookPath =
|
|
6049
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5429
6050
|
const isApproval = hook.isApprovalHook;
|
|
5430
6051
|
const entry = {
|
|
5431
6052
|
type: "command",
|
|
@@ -5442,7 +6063,7 @@ codex_hooks = true`;
|
|
|
5442
6063
|
} else if (agentId === "openhands") {
|
|
5443
6064
|
const hooksObj = {};
|
|
5444
6065
|
for (const hook of agent.hooks) {
|
|
5445
|
-
const hookPath =
|
|
6066
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5446
6067
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5447
6068
|
const hookTimeout = hook.timeout;
|
|
5448
6069
|
const isApproval = hook.isApprovalHook;
|
|
@@ -5567,7 +6188,8 @@ async function copyHookScripts2(hooksDir, token, files, options = {}) {
|
|
|
5567
6188
|
apiUrl: options.apiUrl || API_URL,
|
|
5568
6189
|
apiVersion: API_VERSION,
|
|
5569
6190
|
onRateLimit: options.onRateLimit,
|
|
5570
|
-
optionalFiles: options.optionalFiles
|
|
6191
|
+
optionalFiles: options.optionalFiles,
|
|
6192
|
+
expectedHashes: HOOK_SCRIPT_SHA256
|
|
5571
6193
|
});
|
|
5572
6194
|
}
|
|
5573
6195
|
function readOpenClawInstalledVersion() {
|
|
@@ -5581,14 +6203,14 @@ function readOpenClawInstalledVersion() {
|
|
|
5581
6203
|
if (result.status === 0) {
|
|
5582
6204
|
const metadata = JSON.parse(result.stdout);
|
|
5583
6205
|
if (metadata.plugin?.packageName === "@agentapprove/openclaw" && typeof metadata.plugin.rootDir === "string") {
|
|
5584
|
-
return readJsonPackageVersion(
|
|
6206
|
+
return readJsonPackageVersion(join3(metadata.plugin.rootDir, "package.json"));
|
|
5585
6207
|
}
|
|
5586
6208
|
return null;
|
|
5587
6209
|
}
|
|
5588
6210
|
} catch {}
|
|
5589
6211
|
for (const packagePath of [
|
|
5590
|
-
|
|
5591
|
-
|
|
6212
|
+
join3(homedir(), ".openclaw", "npm", "node_modules", "@agentapprove", "openclaw", "package.json"),
|
|
6213
|
+
join3(homedir(), ".openclaw", "extensions", "openclaw", "package.json")
|
|
5592
6214
|
]) {
|
|
5593
6215
|
const version = readJsonPackageVersion(packagePath);
|
|
5594
6216
|
if (version)
|
|
@@ -5597,11 +6219,11 @@ function readOpenClawInstalledVersion() {
|
|
|
5597
6219
|
return null;
|
|
5598
6220
|
}
|
|
5599
6221
|
function readJsonPackageVersion(packagePath) {
|
|
5600
|
-
if (!
|
|
6222
|
+
if (!existsSync5(packagePath)) {
|
|
5601
6223
|
return null;
|
|
5602
6224
|
}
|
|
5603
6225
|
try {
|
|
5604
|
-
const pkg = JSON.parse(
|
|
6226
|
+
const pkg = JSON.parse(readFileSync3(packagePath, "utf-8"));
|
|
5605
6227
|
return typeof pkg.version === "string" ? pkg.version : null;
|
|
5606
6228
|
} catch {
|
|
5607
6229
|
return null;
|
|
@@ -5610,10 +6232,10 @@ function readJsonPackageVersion(packagePath) {
|
|
|
5610
6232
|
function readOpenCodeInstalledVersion() {
|
|
5611
6233
|
const cacheDir = getOpenCodeCacheDir();
|
|
5612
6234
|
const candidates = [
|
|
5613
|
-
|
|
5614
|
-
|
|
5615
|
-
|
|
5616
|
-
|
|
6235
|
+
join3(cacheDir, "packages", "@agentapprove", `opencode@${OPENCODE_PLUGIN_VERSION}`, "node_modules", "@agentapprove", "opencode", "package.json"),
|
|
6236
|
+
join3(cacheDir, "packages", "@agentapprove", "opencode@latest", "node_modules", "@agentapprove", "opencode", "package.json"),
|
|
6237
|
+
join3(cacheDir, "node_modules", "@agentapprove", "opencode", "package.json"),
|
|
6238
|
+
join3(getOpenCodeConfigDir(), "node_modules", "@agentapprove", "opencode", "package.json")
|
|
5617
6239
|
];
|
|
5618
6240
|
for (const candidate of candidates) {
|
|
5619
6241
|
const version = readJsonPackageVersion(candidate);
|
|
@@ -5681,10 +6303,10 @@ function installOpenCodePluginViaCli() {
|
|
|
5681
6303
|
}
|
|
5682
6304
|
function readPiPinnedSpec() {
|
|
5683
6305
|
try {
|
|
5684
|
-
const settingsPath =
|
|
5685
|
-
if (!
|
|
6306
|
+
const settingsPath = join3(homedir(), ".pi", "agent", "settings.json");
|
|
6307
|
+
if (!existsSync5(settingsPath))
|
|
5686
6308
|
return null;
|
|
5687
|
-
const settings = JSON.parse(
|
|
6309
|
+
const settings = JSON.parse(readFileSync3(settingsPath, "utf8"));
|
|
5688
6310
|
if (!Array.isArray(settings.packages))
|
|
5689
6311
|
return null;
|
|
5690
6312
|
const spec = settings.packages.find((entry) => typeof entry === "string" && entry.startsWith("npm:@agentapprove/pi"));
|
|
@@ -5695,13 +6317,13 @@ function readPiPinnedSpec() {
|
|
|
5695
6317
|
}
|
|
5696
6318
|
function installPiPluginViaCli() {
|
|
5697
6319
|
try {
|
|
5698
|
-
|
|
6320
|
+
runHostCommand("pi", ["install", PI_PLUGIN_SPEC], { timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS });
|
|
5699
6321
|
const pinnedSpec = readPiPinnedSpec();
|
|
5700
6322
|
if (pinnedSpec !== null && pinnedSpec !== PI_PLUGIN_SPEC) {
|
|
5701
6323
|
const manualFix = `Fix manually with: pi remove npm:@agentapprove/pi && pi install ${PI_PLUGIN_SPEC}`;
|
|
5702
6324
|
try {
|
|
5703
|
-
|
|
5704
|
-
|
|
6325
|
+
runHostCommand("pi", ["remove", "npm:@agentapprove/pi"]);
|
|
6326
|
+
runHostCommand("pi", ["install", PI_PLUGIN_SPEC], { timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS });
|
|
5705
6327
|
} catch (err) {
|
|
5706
6328
|
return {
|
|
5707
6329
|
success: false,
|
|
@@ -5729,7 +6351,7 @@ function installPiPluginViaCli() {
|
|
|
5729
6351
|
}
|
|
5730
6352
|
function removePiPluginViaCli() {
|
|
5731
6353
|
try {
|
|
5732
|
-
|
|
6354
|
+
runHostCommand("pi", ["remove", "npm:@agentapprove/pi"]);
|
|
5733
6355
|
return { success: true };
|
|
5734
6356
|
} catch (err) {
|
|
5735
6357
|
return {
|
|
@@ -5738,16 +6360,13 @@ function removePiPluginViaCli() {
|
|
|
5738
6360
|
};
|
|
5739
6361
|
}
|
|
5740
6362
|
}
|
|
5741
|
-
var HERMES_BUNDLE_SHA256 = "
|
|
6363
|
+
var HERMES_BUNDLE_SHA256 = "e17bf4464d2f1d20c9153596a62409a88c9e5ce79312c5313d6b9e8ea721054a";
|
|
5742
6364
|
var HERMES_BUNDLE_FILENAME = `agentapprove-hermes-${HERMES_PLUGIN_VERSION}.tar.gz`;
|
|
5743
|
-
var HERMES_PLUGIN_DIR =
|
|
6365
|
+
var HERMES_PLUGIN_DIR = join3(homedir(), ".hermes", "plugins", "agentapprove");
|
|
5744
6366
|
function findPython() {
|
|
5745
6367
|
for (const candidate of ["python3.12", "python3.11", "python3.10", "python3"]) {
|
|
5746
6368
|
try {
|
|
5747
|
-
const out =
|
|
5748
|
-
encoding: "utf-8",
|
|
5749
|
-
stdio: ["pipe", "pipe", "ignore"]
|
|
5750
|
-
}).trim();
|
|
6369
|
+
const out = runHostCommand(candidate, ["-c", "import sys; print('%d.%d' % sys.version_info[:2])"], { timeoutMs: 5000 }).trim();
|
|
5751
6370
|
const [major, minor] = out.split(".").map(Number);
|
|
5752
6371
|
if (major === 3 && minor >= 10) {
|
|
5753
6372
|
return { command: candidate, version: out };
|
|
@@ -5774,13 +6393,13 @@ function isSafeApiVersion(candidate) {
|
|
|
5774
6393
|
return /^[a-z0-9-]+$/i.test(candidate);
|
|
5775
6394
|
}
|
|
5776
6395
|
function readInstallerConfig() {
|
|
5777
|
-
const envPath =
|
|
6396
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
5778
6397
|
let apiUrl = API_URL;
|
|
5779
6398
|
let apiVersion = "v001";
|
|
5780
6399
|
let token = "";
|
|
5781
|
-
if (
|
|
6400
|
+
if (existsSync5(envPath)) {
|
|
5782
6401
|
try {
|
|
5783
|
-
const content =
|
|
6402
|
+
const content = readFileSync3(envPath, "utf-8");
|
|
5784
6403
|
for (const line of content.split(`
|
|
5785
6404
|
`)) {
|
|
5786
6405
|
if (line.startsWith("#"))
|
|
@@ -5823,7 +6442,8 @@ async function downloadHermesBundle(apiUrl, apiVersion, token) {
|
|
|
5823
6442
|
let response;
|
|
5824
6443
|
try {
|
|
5825
6444
|
response = await fetch(url.toString(), {
|
|
5826
|
-
headers: { Authorization: `Bearer ${token}` }
|
|
6445
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
6446
|
+
signal: AbortSignal.timeout(90000)
|
|
5827
6447
|
});
|
|
5828
6448
|
} catch (err) {
|
|
5829
6449
|
return { ok: false, error: `Network error downloading ${HERMES_BUNDLE_FILENAME}: ${err instanceof Error ? err.message : String(err)}` };
|
|
@@ -5846,7 +6466,7 @@ async function downloadHermesBundle(apiUrl, apiVersion, token) {
|
|
|
5846
6466
|
}
|
|
5847
6467
|
}
|
|
5848
6468
|
function verifyBundleHash(bytes) {
|
|
5849
|
-
return
|
|
6469
|
+
return createHash3("sha256").update(bytes).digest("hex");
|
|
5850
6470
|
}
|
|
5851
6471
|
function validateExtractedTree(root) {
|
|
5852
6472
|
const realRoot = realpathSync2(root);
|
|
@@ -5860,7 +6480,7 @@ function validateExtractedTree(root) {
|
|
|
5860
6480
|
return { ok: false, error: `Cannot read staged dir ${dir}: ${err instanceof Error ? err.message : String(err)}` };
|
|
5861
6481
|
}
|
|
5862
6482
|
for (const entry of entries) {
|
|
5863
|
-
const fullPath =
|
|
6483
|
+
const fullPath = join3(dir, String(entry.name));
|
|
5864
6484
|
let resolved;
|
|
5865
6485
|
try {
|
|
5866
6486
|
resolved = realpathSync2(fullPath);
|
|
@@ -5882,10 +6502,7 @@ function validateExtractedTree(root) {
|
|
|
5882
6502
|
}
|
|
5883
6503
|
function hermesDepsAlreadyInstalled(pythonCommand) {
|
|
5884
6504
|
try {
|
|
5885
|
-
|
|
5886
|
-
stdio: "pipe",
|
|
5887
|
-
timeout: 5000
|
|
5888
|
-
});
|
|
6505
|
+
runHostCommand(pythonCommand, ["-c", "import cryptography, httpx"], { timeoutMs: 5000 });
|
|
5889
6506
|
return true;
|
|
5890
6507
|
} catch {
|
|
5891
6508
|
return false;
|
|
@@ -5893,7 +6510,7 @@ function hermesDepsAlreadyInstalled(pythonCommand) {
|
|
|
5893
6510
|
}
|
|
5894
6511
|
function uvAvailable() {
|
|
5895
6512
|
try {
|
|
5896
|
-
|
|
6513
|
+
runHostCommand("uv", ["--version"], { timeoutMs: 5000 });
|
|
5897
6514
|
return true;
|
|
5898
6515
|
} catch {
|
|
5899
6516
|
return false;
|
|
@@ -5914,7 +6531,7 @@ ${message}`;
|
|
|
5914
6531
|
function installHermesDepsAdaptive(pythonCommand, deps) {
|
|
5915
6532
|
const depsArg = deps.map((d) => `"${d}"`).join(" ");
|
|
5916
6533
|
try {
|
|
5917
|
-
|
|
6534
|
+
runHostCommand(pythonCommand, ["-m", "pip", "install", "--user", "--quiet", ...deps], { timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS });
|
|
5918
6535
|
return { ok: true };
|
|
5919
6536
|
} catch (pipErr) {
|
|
5920
6537
|
if (!isExternallyManagedError(pipErr)) {
|
|
@@ -5931,7 +6548,7 @@ function installHermesDepsAdaptive(pythonCommand, deps) {
|
|
|
5931
6548
|
}
|
|
5932
6549
|
const uvCmd = `uv pip install --system --break-system-packages --python ${pythonCommand} --quiet ${depsArg}`;
|
|
5933
6550
|
try {
|
|
5934
|
-
|
|
6551
|
+
runHostCommand("uv", ["pip", "install", "--system", "--break-system-packages", "--python", pythonCommand, "--quiet", ...deps], { timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS });
|
|
5935
6552
|
return { ok: true };
|
|
5936
6553
|
} catch (uvErr) {
|
|
5937
6554
|
return {
|
|
@@ -5947,7 +6564,7 @@ function isValidHermesProfileName(name) {
|
|
|
5947
6564
|
return name === HERMES_DEFAULT_PROFILE || HERMES_PROFILE_ID_RE.test(name);
|
|
5948
6565
|
}
|
|
5949
6566
|
function hermesProfilePluginDir(profile) {
|
|
5950
|
-
return profile === HERMES_DEFAULT_PROFILE ? HERMES_PLUGIN_DIR :
|
|
6567
|
+
return profile === HERMES_DEFAULT_PROFILE ? HERMES_PLUGIN_DIR : join3(homedir(), ".hermes", "profiles", profile, "plugins", "agentapprove");
|
|
5951
6568
|
}
|
|
5952
6569
|
function hermesEnableCmd(profile) {
|
|
5953
6570
|
return profile === HERMES_DEFAULT_PROFILE ? "hermes plugins enable agentapprove" : `hermes -p ${profile} plugins enable agentapprove`;
|
|
@@ -5958,54 +6575,54 @@ function hermesDisableCmd(profile) {
|
|
|
5958
6575
|
function stageHermesBundle(bytes, targetDir) {
|
|
5959
6576
|
let tmpDir;
|
|
5960
6577
|
try {
|
|
5961
|
-
tmpDir = mkdtempSync(
|
|
6578
|
+
tmpDir = mkdtempSync(join3(tmpdir(), "aa-hermes-"));
|
|
5962
6579
|
} catch (err) {
|
|
5963
6580
|
return { success: false, error: `Could not create temp directory for bundle staging: ${err instanceof Error ? err.message : String(err)}` };
|
|
5964
6581
|
}
|
|
5965
|
-
const tarballPath =
|
|
6582
|
+
const tarballPath = join3(tmpDir, HERMES_BUNDLE_FILENAME);
|
|
5966
6583
|
let backupPath = null;
|
|
5967
6584
|
try {
|
|
5968
|
-
|
|
6585
|
+
writeFileSync2(tarballPath, bytes);
|
|
5969
6586
|
try {
|
|
5970
|
-
|
|
6587
|
+
runHostCommand("tar", ["-xzf", tarballPath, "-C", tmpDir, "--no-same-owner", "--no-same-permissions"]);
|
|
5971
6588
|
} catch (err) {
|
|
5972
6589
|
return { success: false, error: `tar extract failed: ${err instanceof Error ? err.message : String(err)}` };
|
|
5973
6590
|
}
|
|
5974
|
-
const stagedDir =
|
|
5975
|
-
if (!
|
|
6591
|
+
const stagedDir = join3(tmpDir, "agentapprove");
|
|
6592
|
+
if (!existsSync5(stagedDir)) {
|
|
5976
6593
|
return { success: false, error: "Bundle did not contain expected `agentapprove/` directory." };
|
|
5977
6594
|
}
|
|
5978
6595
|
const validation = validateExtractedTree(stagedDir);
|
|
5979
6596
|
if (!validation.ok) {
|
|
5980
6597
|
return { success: false, error: `Bundle integrity violation: ${validation.error}` };
|
|
5981
6598
|
}
|
|
5982
|
-
|
|
5983
|
-
if (
|
|
6599
|
+
mkdirSync3(dirname4(targetDir), { recursive: true });
|
|
6600
|
+
if (existsSync5(targetDir)) {
|
|
5984
6601
|
backupPath = `${targetDir}.bak-${Date.now()}`;
|
|
5985
|
-
|
|
6602
|
+
renameSync4(targetDir, backupPath);
|
|
5986
6603
|
}
|
|
5987
6604
|
try {
|
|
5988
|
-
|
|
6605
|
+
renameSync4(stagedDir, targetDir);
|
|
5989
6606
|
} catch (err) {
|
|
5990
6607
|
if (backupPath) {
|
|
5991
6608
|
try {
|
|
5992
|
-
|
|
6609
|
+
renameSync4(backupPath, targetDir);
|
|
5993
6610
|
backupPath = null;
|
|
5994
6611
|
} catch {}
|
|
5995
6612
|
}
|
|
5996
6613
|
const restoreNote = backupPath ? ` Your previous install was preserved at ${backupPath} — recover with: mv "${backupPath}" "${targetDir}"` : "";
|
|
5997
6614
|
return { success: false, error: `Could not install bundle to ${targetDir}: ${err instanceof Error ? err.message : String(err)}.${restoreNote}` };
|
|
5998
6615
|
}
|
|
5999
|
-
|
|
6616
|
+
writeFileSync2(join3(targetDir, ".bundle-hash"), HERMES_BUNDLE_SHA256, { mode: 420 });
|
|
6000
6617
|
if (backupPath) {
|
|
6001
|
-
|
|
6618
|
+
rmSync3(backupPath, { recursive: true, force: true });
|
|
6002
6619
|
backupPath = null;
|
|
6003
6620
|
}
|
|
6004
6621
|
} catch (err) {
|
|
6005
6622
|
if (backupPath) {
|
|
6006
6623
|
try {
|
|
6007
|
-
|
|
6008
|
-
|
|
6624
|
+
rmSync3(targetDir, { recursive: true, force: true });
|
|
6625
|
+
renameSync4(backupPath, targetDir);
|
|
6009
6626
|
backupPath = null;
|
|
6010
6627
|
} catch {}
|
|
6011
6628
|
}
|
|
@@ -6013,7 +6630,7 @@ function stageHermesBundle(bytes, targetDir) {
|
|
|
6013
6630
|
return { success: false, error: `Bundle install failed: ${err instanceof Error ? err.message : String(err)}.${restoreNote}` };
|
|
6014
6631
|
} finally {
|
|
6015
6632
|
try {
|
|
6016
|
-
|
|
6633
|
+
rmSync3(tmpDir, { recursive: true, force: true });
|
|
6017
6634
|
} catch {}
|
|
6018
6635
|
}
|
|
6019
6636
|
return { success: true };
|
|
@@ -6021,20 +6638,21 @@ function stageHermesBundle(bytes, targetDir) {
|
|
|
6021
6638
|
function enableHermesPluginForProfile(profile) {
|
|
6022
6639
|
try {
|
|
6023
6640
|
enableHermesFollowUp(profile);
|
|
6024
|
-
|
|
6641
|
+
runHostCommand("hermes", [...profile === HERMES_DEFAULT_PROFILE ? [] : ["-p", profile], "plugins", "enable", "agentapprove"], { interactive: true, timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS });
|
|
6025
6642
|
return { success: true };
|
|
6026
6643
|
} catch (err) {
|
|
6027
6644
|
return { success: false, error: err instanceof Error ? err.message : String(err) };
|
|
6028
6645
|
}
|
|
6029
6646
|
}
|
|
6030
6647
|
async function installHermesPluginViaCli() {
|
|
6648
|
+
v2.info("Hermes: checking CLI and Python");
|
|
6031
6649
|
try {
|
|
6032
|
-
|
|
6033
|
-
} catch {
|
|
6650
|
+
runHostCommand("hermes", ["--version"]);
|
|
6651
|
+
} catch (err) {
|
|
6034
6652
|
return {
|
|
6035
6653
|
success: false,
|
|
6036
6654
|
label: "Agent Approve plugin",
|
|
6037
|
-
error:
|
|
6655
|
+
error: `Could not check Hermes CLI: ${err instanceof Error ? err.message : String(err)}. Run hermes --version to diagnose, then retry setup.`
|
|
6038
6656
|
};
|
|
6039
6657
|
}
|
|
6040
6658
|
const python = findPython();
|
|
@@ -6053,6 +6671,7 @@ async function installHermesPluginViaCli() {
|
|
|
6053
6671
|
error: "Missing API token. Pair your phone first by running `npx agentapprove` and completing the QR scan."
|
|
6054
6672
|
};
|
|
6055
6673
|
}
|
|
6674
|
+
v2.info("Hermes: downloading and verifying the plugin (up to 90 seconds)");
|
|
6056
6675
|
const download = await downloadHermesBundle(cfg.apiUrl, cfg.apiVersion, cfg.token);
|
|
6057
6676
|
if (!download.ok) {
|
|
6058
6677
|
return { success: false, label: "Agent Approve plugin", error: download.error };
|
|
@@ -6069,7 +6688,9 @@ async function installHermesPluginViaCli() {
|
|
|
6069
6688
|
if (!staged.success) {
|
|
6070
6689
|
return { success: false, label: "Agent Approve plugin", error: staged.error };
|
|
6071
6690
|
}
|
|
6691
|
+
v2.info("Hermes: checking Python dependencies");
|
|
6072
6692
|
if (!hermesDepsAlreadyInstalled(python.command)) {
|
|
6693
|
+
v2.info("Hermes: installing Python dependencies (up to 3 minutes per attempt)");
|
|
6073
6694
|
const depsResult = installHermesDepsAdaptive(python.command, HERMES_PIP_DEPS);
|
|
6074
6695
|
if (!depsResult.ok) {
|
|
6075
6696
|
return {
|
|
@@ -6079,6 +6700,7 @@ async function installHermesPluginViaCli() {
|
|
|
6079
6700
|
};
|
|
6080
6701
|
}
|
|
6081
6702
|
}
|
|
6703
|
+
v2.info("Hermes: enabling the plugin; review any permissions requested by Hermes");
|
|
6082
6704
|
const enabled = enableHermesPluginForProfile(HERMES_DEFAULT_PROFILE);
|
|
6083
6705
|
if (!enabled.success) {
|
|
6084
6706
|
return {
|
|
@@ -6102,7 +6724,7 @@ ${stdout}`.toLowerCase();
|
|
|
6102
6724
|
}
|
|
6103
6725
|
function disableHermesPluginForProfile(profile) {
|
|
6104
6726
|
try {
|
|
6105
|
-
|
|
6727
|
+
runHostCommand("hermes", [...profile === HERMES_DEFAULT_PROFILE ? [] : ["-p", profile], "plugins", "disable", "agentapprove"]);
|
|
6106
6728
|
return { success: true };
|
|
6107
6729
|
} catch (err) {
|
|
6108
6730
|
if (isHermesDisableNoOp(err)) {
|
|
@@ -6120,7 +6742,7 @@ function disableHermesPluginViaCli() {
|
|
|
6120
6742
|
function removeHermesPluginFromProfile(profile) {
|
|
6121
6743
|
const disabled = disableHermesPluginForProfile(profile);
|
|
6122
6744
|
try {
|
|
6123
|
-
|
|
6745
|
+
rmSync3(hermesProfilePluginDir(profile), { recursive: true, force: true });
|
|
6124
6746
|
return disabled.success ? { success: true } : { success: false, error: `disable failed: ${disabled.error || "unknown"}` };
|
|
6125
6747
|
} catch (err) {
|
|
6126
6748
|
return {
|
|
@@ -6131,11 +6753,11 @@ function removeHermesPluginFromProfile(profile) {
|
|
|
6131
6753
|
}
|
|
6132
6754
|
function hermesProfilePluginStatus(profile) {
|
|
6133
6755
|
const dir = hermesProfilePluginDir(profile);
|
|
6134
|
-
const installed =
|
|
6756
|
+
const installed = existsSync5(join3(dir, ".bundle-hash"));
|
|
6135
6757
|
let version = null;
|
|
6136
6758
|
if (installed) {
|
|
6137
6759
|
try {
|
|
6138
|
-
const configPy =
|
|
6760
|
+
const configPy = readFileSync3(join3(dir, "config.py"), "utf-8");
|
|
6139
6761
|
const m = configPy.match(/^PLUGIN_VERSION\s*=\s*["']([^"']+)["']/m);
|
|
6140
6762
|
version = m ? m[1] : null;
|
|
6141
6763
|
} catch {}
|
|
@@ -6145,8 +6767,8 @@ function hermesProfilePluginStatus(profile) {
|
|
|
6145
6767
|
function listHermesProfiles() {
|
|
6146
6768
|
const names = new Set([HERMES_DEFAULT_PROFILE]);
|
|
6147
6769
|
try {
|
|
6148
|
-
const profilesRoot =
|
|
6149
|
-
if (
|
|
6770
|
+
const profilesRoot = join3(homedir(), ".hermes", "profiles");
|
|
6771
|
+
if (existsSync5(profilesRoot)) {
|
|
6150
6772
|
for (const entry of readdirSync2(profilesRoot, { withFileTypes: true })) {
|
|
6151
6773
|
if (entry.isDirectory() && isValidHermesProfileName(entry.name)) {
|
|
6152
6774
|
names.add(entry.name);
|
|
@@ -6158,9 +6780,9 @@ function listHermesProfiles() {
|
|
|
6158
6780
|
}
|
|
6159
6781
|
async function syncHermesProfiles(targetProfiles) {
|
|
6160
6782
|
try {
|
|
6161
|
-
|
|
6162
|
-
} catch {
|
|
6163
|
-
return { ok: false, results: [], error:
|
|
6783
|
+
runHostCommand("hermes", ["--version"]);
|
|
6784
|
+
} catch (err) {
|
|
6785
|
+
return { ok: false, results: [], error: `Could not check Hermes CLI: ${err instanceof Error ? err.message : String(err)}. Run hermes --version to diagnose, then retry setup.` };
|
|
6164
6786
|
}
|
|
6165
6787
|
const python = findPython();
|
|
6166
6788
|
if (!python) {
|
|
@@ -6183,6 +6805,7 @@ async function syncHermesProfiles(targetProfiles) {
|
|
|
6183
6805
|
};
|
|
6184
6806
|
}
|
|
6185
6807
|
if (!hermesDepsAlreadyInstalled(python.command)) {
|
|
6808
|
+
v2.info("Hermes: installing Python dependencies (up to 3 minutes per attempt)");
|
|
6186
6809
|
const depsResult = installHermesDepsAdaptive(python.command, HERMES_PIP_DEPS);
|
|
6187
6810
|
if (!depsResult.ok) {
|
|
6188
6811
|
return { ok: false, results: [], error: `Could not install Python runtime deps: ${depsResult.error}` };
|
|
@@ -6271,8 +6894,8 @@ function checkCommand(name) {
|
|
|
6271
6894
|
if (isWindows()) {
|
|
6272
6895
|
const gitBashPath = findGitBash();
|
|
6273
6896
|
if (gitBashPath) {
|
|
6274
|
-
|
|
6275
|
-
return
|
|
6897
|
+
const result = spawnSync2(gitBashPath, ["-c", 'command -v "$1"', "agentapprove", name], { stdio: "ignore" });
|
|
6898
|
+
return result.status === 0;
|
|
6276
6899
|
}
|
|
6277
6900
|
execSync(`where ${name}`, { stdio: "ignore" });
|
|
6278
6901
|
return true;
|
|
@@ -6517,10 +7140,10 @@ async function installCommand() {
|
|
|
6517
7140
|
let existingKeyId = null;
|
|
6518
7141
|
if (existingConfig) {
|
|
6519
7142
|
existingTokenPreview = hasExistingToken ? existingConfig.token.slice(0, 15) + "..." : "Not set";
|
|
6520
|
-
const e2eKeyPath =
|
|
6521
|
-
if (
|
|
6522
|
-
const keyHex =
|
|
6523
|
-
existingKeyId =
|
|
7143
|
+
const e2eKeyPath = join3(getAgentApproveDir(), "e2e-key");
|
|
7144
|
+
if (existsSync5(e2eKeyPath)) {
|
|
7145
|
+
const keyHex = readFileSync3(e2eKeyPath, "utf-8").trim();
|
|
7146
|
+
existingKeyId = createHash3("sha256").update(Buffer.from(keyHex, "hex")).digest("hex").slice(0, 8);
|
|
6524
7147
|
}
|
|
6525
7148
|
}
|
|
6526
7149
|
const existingTokenPreflight = hasExistingToken ? await runExistingTokenPreflight(existingConfig.token, pairingApiBase) : null;
|
|
@@ -6574,9 +7197,10 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6574
7197
|
const requiresFreshPair = pendingRecoveryAction !== null;
|
|
6575
7198
|
const forceKeyReuseForRecovery = pendingRecoveryAction === "refresh";
|
|
6576
7199
|
ensureAgentApproveDir();
|
|
6577
|
-
const hooksDir =
|
|
7200
|
+
const hooksDir = join3(getAgentApproveDir(), "hooks");
|
|
6578
7201
|
const selectedInstallConfig = getInitialInstallConfig(setupProfile, existingConfig);
|
|
6579
7202
|
let token = null;
|
|
7203
|
+
let pairingOutcome = null;
|
|
6580
7204
|
let finalPrivacy = selectedInstallConfig.privacy;
|
|
6581
7205
|
let email = "";
|
|
6582
7206
|
let apiUrl = pairingApiBase;
|
|
@@ -6656,7 +7280,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6656
7280
|
}
|
|
6657
7281
|
ensureAgentApproveDir();
|
|
6658
7282
|
const agentApproveDir = getAgentApproveDir();
|
|
6659
|
-
const existingKeyPath =
|
|
7283
|
+
const existingKeyPath = join3(agentApproveDir, "e2e-key");
|
|
6660
7284
|
let e2eUserKey = null;
|
|
6661
7285
|
let backupOldKeyTo = null;
|
|
6662
7286
|
if (setupProfile === "customize" && !e2eRequired && !skipE2E) {
|
|
@@ -6671,9 +7295,9 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6671
7295
|
useE2E = e2eChoice;
|
|
6672
7296
|
}
|
|
6673
7297
|
if (useE2E) {
|
|
6674
|
-
if (
|
|
6675
|
-
const oldKeyHex =
|
|
6676
|
-
const oldKeyId =
|
|
7298
|
+
if (existsSync5(existingKeyPath)) {
|
|
7299
|
+
const oldKeyHex = readFileSync3(existingKeyPath, "utf-8").trim();
|
|
7300
|
+
const oldKeyId = createHash3("sha256").update(Buffer.from(oldKeyHex, "hex")).digest("hex").slice(0, 8);
|
|
6677
7301
|
const autoReuseKey = forceKeyReuseForRecovery || setupProfile === "existing-config" && !requiresFreshPair;
|
|
6678
7302
|
if (autoReuseKey) {
|
|
6679
7303
|
e2eUserKey = oldKeyHex;
|
|
@@ -6693,19 +7317,19 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6693
7317
|
e2eUserKey = oldKeyHex;
|
|
6694
7318
|
} else {
|
|
6695
7319
|
if (keyAction === "backup") {
|
|
6696
|
-
backupOldKeyTo =
|
|
7320
|
+
backupOldKeyTo = join3(agentApproveDir, `e2e-key.${oldKeyId}.bak`);
|
|
6697
7321
|
}
|
|
6698
|
-
e2eUserKey =
|
|
7322
|
+
e2eUserKey = randomBytes2(32).toString("hex");
|
|
6699
7323
|
}
|
|
6700
7324
|
}
|
|
6701
7325
|
} else {
|
|
6702
|
-
e2eUserKey =
|
|
7326
|
+
e2eUserKey = randomBytes2(32).toString("hex");
|
|
6703
7327
|
}
|
|
6704
7328
|
}
|
|
6705
7329
|
if (!useE2E) {
|
|
6706
7330
|
v2.info("E2E encryption disabled — event content will be visible on the web dashboard");
|
|
6707
7331
|
}
|
|
6708
|
-
const e2eKeyId = e2eUserKey ?
|
|
7332
|
+
const e2eKeyId = e2eUserKey ? createHash3("sha256").update(Buffer.from(e2eUserKey, "hex")).digest("hex").slice(0, 8) : undefined;
|
|
6709
7333
|
if (setupProfile === "customize") {
|
|
6710
7334
|
const retentionChoice = await le({
|
|
6711
7335
|
message: "Data retention - how long to keep event history",
|
|
@@ -6775,7 +7399,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6775
7399
|
if (setupProfile === "existing-config" && existingConfig?.configSetAt) {
|
|
6776
7400
|
configSetAt = existingConfig.configSetAt;
|
|
6777
7401
|
}
|
|
6778
|
-
const e2eKeyExists =
|
|
7402
|
+
const e2eKeyExists = existsSync5(existingKeyPath);
|
|
6779
7403
|
useE2E = e2eKeyExists;
|
|
6780
7404
|
e2eUserKey = null;
|
|
6781
7405
|
backupOldKeyTo = null;
|
|
@@ -6784,11 +7408,6 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6784
7408
|
}
|
|
6785
7409
|
} else if (shouldCreateFreshPairing(connectionMethod)) {
|
|
6786
7410
|
const pairingMethod = connectionMethod;
|
|
6787
|
-
if (backupOldKeyTo) {
|
|
6788
|
-
renameSync2(existingKeyPath, backupOldKeyTo);
|
|
6789
|
-
v2.success(`Old key backed up to ${backupOldKeyTo}`);
|
|
6790
|
-
backupOldKeyTo = null;
|
|
6791
|
-
}
|
|
6792
7411
|
configSetAt = Math.floor(Date.now() / 1000);
|
|
6793
7412
|
const pairingConfig = {
|
|
6794
7413
|
privacyTier: finalPrivacy,
|
|
@@ -6829,17 +7448,32 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6829
7448
|
he("Installation cancelled");
|
|
6830
7449
|
process.exit(0);
|
|
6831
7450
|
} else if (result) {
|
|
6832
|
-
|
|
6833
|
-
|
|
6834
|
-
|
|
7451
|
+
pairingOutcome = reconcilePairingConfig(pairingConfig, result.effectiveConfig, {
|
|
7452
|
+
reportedPrivacy: result.privacy,
|
|
7453
|
+
localE2eOn: existingConfig?.e2eEnabled !== false && existsSync5(existingKeyPath)
|
|
7454
|
+
});
|
|
7455
|
+
if (pairingOutcome.encryptionRequired) {
|
|
7456
|
+
pairingSpinner.stop("Paired, but this computer is not set up");
|
|
7457
|
+
v2.error(formatEncryptionRequiredMessage("install"));
|
|
7458
|
+
he("Setup is not finished.");
|
|
7459
|
+
process.exit(1);
|
|
6835
7460
|
}
|
|
7461
|
+
token = result.token;
|
|
7462
|
+
finalPrivacy = pairingOutcome.local.privacyTier;
|
|
7463
|
+
retentionDays = pairingOutcome.local.retentionDays;
|
|
7464
|
+
failBehavior = pairingOutcome.local.failBehavior;
|
|
6836
7465
|
email = result.email;
|
|
6837
7466
|
apiUrl = result.apiUrl || pairingApiBase;
|
|
7467
|
+
if (backupOldKeyTo) {
|
|
7468
|
+
renameSync4(existingKeyPath, backupOldKeyTo);
|
|
7469
|
+
v2.success(`Old key backed up to ${backupOldKeyTo}`);
|
|
7470
|
+
backupOldKeyTo = null;
|
|
7471
|
+
}
|
|
6838
7472
|
if (e2eUserKey && e2eKeyId) {
|
|
6839
|
-
const rootKeyPath =
|
|
6840
|
-
|
|
6841
|
-
const userKeyPath =
|
|
6842
|
-
|
|
7473
|
+
const rootKeyPath = join3(agentApproveDir, "e2e-root-key");
|
|
7474
|
+
writePrivateFile(rootKeyPath, e2eUserKey);
|
|
7475
|
+
const userKeyPath = join3(agentApproveDir, "e2e-key");
|
|
7476
|
+
writePrivateFile(userKeyPath, e2eUserKey);
|
|
6843
7477
|
writeRotationConfig({
|
|
6844
7478
|
rootKeyId: e2eKeyId,
|
|
6845
7479
|
epoch: 0,
|
|
@@ -6847,8 +7481,8 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6847
7481
|
startedAt: new Date().toISOString()
|
|
6848
7482
|
});
|
|
6849
7483
|
if (result.e2eServerKey) {
|
|
6850
|
-
const serverKeyPath =
|
|
6851
|
-
|
|
7484
|
+
const serverKeyPath = join3(agentApproveDir, "e2e-server-key");
|
|
7485
|
+
writePrivateFile(serverKeyPath, result.e2eServerKey);
|
|
6852
7486
|
}
|
|
6853
7487
|
}
|
|
6854
7488
|
if (e2eKeyId) {
|
|
@@ -6856,6 +7490,12 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6856
7490
|
}
|
|
6857
7491
|
const connectedMsg = email ? `Connected! Account: ${email}, Privacy: ${finalPrivacy}` : `Connected! Privacy: ${finalPrivacy}`;
|
|
6858
7492
|
pairingSpinner.stop(connectedMsg);
|
|
7493
|
+
const keptWarning = formatAccountKeptWarning(pairingOutcome);
|
|
7494
|
+
if (keptWarning)
|
|
7495
|
+
v2.warn(keptWarning);
|
|
7496
|
+
const unknownNote = formatAccountUnknownNote(pairingOutcome);
|
|
7497
|
+
if (unknownNote)
|
|
7498
|
+
v2.info(unknownNote);
|
|
6859
7499
|
} else {
|
|
6860
7500
|
pairingSpinner.stop("Session expired");
|
|
6861
7501
|
he("Session expired. Please try again.");
|
|
@@ -6879,8 +7519,8 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6879
7519
|
privacy: finalPrivacy,
|
|
6880
7520
|
retentionDays,
|
|
6881
7521
|
debugLog,
|
|
6882
|
-
configSetAt: installPreservation.letAccountWin ? 0 : configSetAt,
|
|
6883
|
-
e2eEnabled: useE2E,
|
|
7522
|
+
configSetAt: installPreservation.letAccountWin || pairingOutcome?.letAccountWin ? 0 : configSetAt,
|
|
7523
|
+
e2eEnabled: pairingOutcome ? pairingOutcome.local.e2eEnabled : useE2E,
|
|
6884
7524
|
failBehavior,
|
|
6885
7525
|
preserved: installPreservation.preserved
|
|
6886
7526
|
});
|
|
@@ -6918,8 +7558,8 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6918
7558
|
} else {
|
|
6919
7559
|
v2.success("No hook scripts needed for the selected agents");
|
|
6920
7560
|
}
|
|
6921
|
-
const e2eKeyPath =
|
|
6922
|
-
const hasE2EKey =
|
|
7561
|
+
const e2eKeyPath = join3(agentApproveDir, "e2e-key");
|
|
7562
|
+
const hasE2EKey = existsSync5(e2eKeyPath);
|
|
6923
7563
|
if (hasE2EKey) {
|
|
6924
7564
|
if (!silentlyReuseExistingToken) {
|
|
6925
7565
|
if (installMode === "observe") {
|
|
@@ -6928,9 +7568,9 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6928
7568
|
v2.info("Approval mode: Commands are sent via encrypted channel for policy evaluation.");
|
|
6929
7569
|
}
|
|
6930
7570
|
}
|
|
6931
|
-
const envPath =
|
|
6932
|
-
if (
|
|
6933
|
-
let envContent =
|
|
7571
|
+
const envPath = join3(agentApproveDir, "env");
|
|
7572
|
+
if (existsSync5(envPath)) {
|
|
7573
|
+
let envContent = readFileSync3(envPath, "utf-8");
|
|
6934
7574
|
if (envContent.includes("AGENTAPPROVE_E2E_MODE=")) {
|
|
6935
7575
|
envContent = envContent.replace(/AGENTAPPROVE_E2E_MODE=\w+/, `AGENTAPPROVE_E2E_MODE=${installMode}`);
|
|
6936
7576
|
} else {
|
|
@@ -6939,7 +7579,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6939
7579
|
AGENTAPPROVE_E2E_MODE=${installMode}
|
|
6940
7580
|
`;
|
|
6941
7581
|
}
|
|
6942
|
-
|
|
7582
|
+
writePrivateFile(envPath, envContent);
|
|
6943
7583
|
}
|
|
6944
7584
|
}
|
|
6945
7585
|
const installMethod = await le({
|
|
@@ -6963,7 +7603,7 @@ AGENTAPPROVE_E2E_MODE=${installMode}
|
|
|
6963
7603
|
filesToModify.push(agent.configPath);
|
|
6964
7604
|
}
|
|
6965
7605
|
if (agentId === "codex") {
|
|
6966
|
-
filesToModify.push(
|
|
7606
|
+
filesToModify.push(join3(homedir(), ".codex", "config.toml"));
|
|
6967
7607
|
}
|
|
6968
7608
|
if (agentId === "opencode") {
|
|
6969
7609
|
filesToModify.push("OpenCode plugin cache");
|
|
@@ -7002,22 +7642,35 @@ Timestamped backups will be created.`);
|
|
|
7002
7642
|
const agent = AGENTS[agentId];
|
|
7003
7643
|
const spinner = _2();
|
|
7004
7644
|
const spinnerMsg = agentId === "pi" ? `Installing ${agent.name} extension` : agentId === "openclaw" || agentId === "hermes" ? `Installing ${agent.name} plugin` : `Configuring ${agent.name}`;
|
|
7005
|
-
|
|
7645
|
+
const hostSetup = ["openclaw", "pi", "hermes"].includes(agentId);
|
|
7646
|
+
if (hostSetup)
|
|
7647
|
+
v2.step(spinnerMsg);
|
|
7648
|
+
else
|
|
7006
7649
|
spinner.start(spinnerMsg);
|
|
7007
7650
|
const result = await installHooksForAgent(agentId, hooksDir, installMode);
|
|
7008
7651
|
if (result.success) {
|
|
7009
7652
|
const installedHookNames = result.hooks.join(", ");
|
|
7010
7653
|
const backupMsg = result.backupPath ? source_default.dim(` (backup created)`) : "";
|
|
7011
7654
|
const agentName = source_default.cyan(agent.name);
|
|
7012
|
-
if (
|
|
7655
|
+
if (hostSetup)
|
|
7013
7656
|
v2.success(`${agentName}: ${installedHookNames}${backupMsg}`);
|
|
7014
7657
|
else
|
|
7015
7658
|
spinner.stop(`${agentName}: ${installedHookNames}${backupMsg}`);
|
|
7659
|
+
if (result.note)
|
|
7660
|
+
v2.info(result.note);
|
|
7016
7661
|
if (agentId === "vscode-agent") {
|
|
7017
7662
|
const vsCodeSpinner = _2();
|
|
7018
7663
|
vsCodeSpinner.start("Registering hook path in VS Code settings");
|
|
7019
|
-
const modifiedPaths = addToVSCodeHookLocations();
|
|
7020
|
-
if (
|
|
7664
|
+
const { modified: modifiedPaths, failed: failedSettings } = addToVSCodeHookLocations();
|
|
7665
|
+
if (failedSettings.length > 0) {
|
|
7666
|
+
failedSetupAgents.add(agentId);
|
|
7667
|
+
vsCodeSpinner.stop(modifiedPaths.length > 0 ? `Registered in: ${modifiedPaths.join(", ")}` : source_default.yellow("VS Code settings were not updated"));
|
|
7668
|
+
for (const failure of failedSettings) {
|
|
7669
|
+
v2.warn(`${failure.variant} settings were not changed.
|
|
7670
|
+
` + ` ${failure.error}
|
|
7671
|
+
` + ` Or add "~/.agentapprove/hooks": true under "chat.hookFilesLocations" yourself.`);
|
|
7672
|
+
}
|
|
7673
|
+
} else if (modifiedPaths.length > 0) {
|
|
7021
7674
|
vsCodeSpinner.stop(`Registered in: ${modifiedPaths.join(", ")}`);
|
|
7022
7675
|
} else {
|
|
7023
7676
|
const variants = findInstalledVSCodeVariants();
|
|
@@ -7051,14 +7704,15 @@ Timestamped backups will be created.`);
|
|
|
7051
7704
|
}
|
|
7052
7705
|
} else {
|
|
7053
7706
|
failedSetupAgents.add(agentId);
|
|
7054
|
-
if (
|
|
7707
|
+
if (hostSetup)
|
|
7055
7708
|
v2.error(`${agent.name} configuration failed`);
|
|
7056
7709
|
else
|
|
7057
7710
|
spinner.stop(`${agent.name} configuration failed`);
|
|
7058
7711
|
if (agentId === "openclaw") {
|
|
7059
|
-
v2.warn(`
|
|
7712
|
+
v2.warn(`OpenClaw setup did not finish.
|
|
7060
7713
|
` + ` Error: ${result.error || "unknown"}
|
|
7061
|
-
` + `
|
|
7714
|
+
` + ` Check plugin status: openclaw plugins inspect openclaw
|
|
7715
|
+
` + ` If the package is missing: openclaw plugins install ${OPENCLAW_PLUGIN_SPEC}
|
|
7062
7716
|
` + ` Then re-run: npx agentapprove`);
|
|
7063
7717
|
} else if (agentId === "pi") {
|
|
7064
7718
|
v2.warn(`Could not install ${PI_PLUGIN_SPEC} via Pi.
|
|
@@ -7078,6 +7732,9 @@ Timestamped backups will be created.`);
|
|
|
7078
7732
|
` + ` 6. hermes config set plugins.entries.agentapprove.allow_gateway_injection true
|
|
7079
7733
|
` + ` 7. hermes plugins enable agentapprove
|
|
7080
7734
|
` + ` Then re-run: npx agentapprove`);
|
|
7735
|
+
} else if (result.error) {
|
|
7736
|
+
v2.warn(`${agent.name} was not set up.
|
|
7737
|
+
` + ` ${result.error}`);
|
|
7081
7738
|
}
|
|
7082
7739
|
}
|
|
7083
7740
|
}
|
|
@@ -7092,7 +7749,7 @@ Timestamped backups will be created.`);
|
|
|
7092
7749
|
});
|
|
7093
7750
|
}
|
|
7094
7751
|
const integrationChecks = inspectSetup(selectedAgents).map((item) => failedSetupAgents.has(item.agent) ? { ...item, status: "failed", reason: "invalid_config" } : item);
|
|
7095
|
-
|
|
7752
|
+
writePrivateFile(join3(getAgentApproveDir(), "setup-agents.json"), JSON.stringify(selectedAgents));
|
|
7096
7753
|
const modeDesc = hasE2EKey ? installMode === "observe" ? source_default.cyan("E2E Observe Mode") + " - All events encrypted, no approval hooks" : source_default.green("E2E Approval Mode") + " - Commands sent via encrypted channel for policy evaluation" : "Standard mode (no E2E keys found)";
|
|
7097
7754
|
me(`Mode: ${modeDesc}
|
|
7098
7755
|
|
|
@@ -7118,14 +7775,14 @@ function inspectSetup(agentIds) {
|
|
|
7118
7775
|
return result("manual", "manual_step");
|
|
7119
7776
|
if (!existing?.token)
|
|
7120
7777
|
return result("failed", "not_configured");
|
|
7121
|
-
if (
|
|
7778
|
+
if (existsSync5(join3(getAgentApproveDir(), DISABLED_STATE_FILENAME)))
|
|
7122
7779
|
return result("failed", "disabled");
|
|
7123
7780
|
try {
|
|
7124
7781
|
if (existing.e2eEnabled !== false) {
|
|
7125
|
-
const keyPath =
|
|
7126
|
-
if (!
|
|
7782
|
+
const keyPath = join3(getAgentApproveDir(), "e2e-key");
|
|
7783
|
+
if (!existsSync5(keyPath))
|
|
7127
7784
|
return result("failed", "missing_files");
|
|
7128
|
-
if (!/^[a-fA-F0-9]{64}$/.test(
|
|
7785
|
+
if (!/^[a-fA-F0-9]{64}$/.test(readFileSync3(keyPath, "utf8").trim()))
|
|
7129
7786
|
return result("failed", "invalid_config");
|
|
7130
7787
|
}
|
|
7131
7788
|
if (agentId === "pi" || agentId === "hermes") {
|
|
@@ -7133,10 +7790,10 @@ function inspectSetup(agentIds) {
|
|
|
7133
7790
|
const ready = agentId === "pi" ? output.includes("@agentapprove/pi") : /^.*agentapprove.*enabled/im.test(output);
|
|
7134
7791
|
return result(ready ? "ready" : "failed", ready ? "verified" : "not_configured");
|
|
7135
7792
|
}
|
|
7136
|
-
const configPath = agentId === "copilot-cli" ?
|
|
7137
|
-
if (agentId === "copilot-cli" && !
|
|
7793
|
+
const configPath = agentId === "copilot-cli" ? join3(process.cwd(), ".github/hooks/agentapprove.json") : agent.configPath;
|
|
7794
|
+
if (agentId === "copilot-cli" && !existsSync5(configPath))
|
|
7138
7795
|
return result("manual", "manual_step");
|
|
7139
|
-
const config =
|
|
7796
|
+
const config = readAgentConfig(agentId, configPath);
|
|
7140
7797
|
if (agentId === "opencode") {
|
|
7141
7798
|
const ready = Array.isArray(config.plugin) && config.plugin.some((p) => typeof p === "string" && p.includes("@agentapprove/opencode"));
|
|
7142
7799
|
return result(ready ? "ready" : "failed", ready ? "verified" : "not_configured");
|
|
@@ -7148,40 +7805,45 @@ function inspectSetup(agentIds) {
|
|
|
7148
7805
|
}
|
|
7149
7806
|
if (agentId === "vscode-agent") {
|
|
7150
7807
|
const registered = findInstalledVSCodeVariants().some(({ path }) => {
|
|
7151
|
-
|
|
7152
|
-
|
|
7808
|
+
let locations;
|
|
7809
|
+
try {
|
|
7810
|
+
locations = readJsoncConfig(path)["chat.hookFilesLocations"];
|
|
7811
|
+
} catch {
|
|
7812
|
+
return false;
|
|
7813
|
+
}
|
|
7814
|
+
return locations?.["~/.agentapprove/hooks"] === true || locations?.[join3(getAgentApproveDir(), "hooks")] === true;
|
|
7153
7815
|
});
|
|
7154
7816
|
if (!registered)
|
|
7155
7817
|
return result("manual", "manual_step");
|
|
7156
7818
|
}
|
|
7157
|
-
if (agentId === "codex" && !/codex_hooks\s*=\s*true/.test(
|
|
7819
|
+
if (agentId === "codex" && !/codex_hooks\s*=\s*true/.test(readFileSync3(join3(homedir(), ".codex/config.toml"), "utf8")))
|
|
7158
7820
|
return result("failed", "not_configured");
|
|
7159
7821
|
const filesReady = (file) => {
|
|
7160
|
-
const path =
|
|
7161
|
-
return
|
|
7822
|
+
const path = join3(getAgentApproveDir(), "hooks", file);
|
|
7823
|
+
return existsSync5(path) && statSync2(path).size > 0 && (!file.endsWith(".sh") || (statSync2(path).mode & 73) !== 0);
|
|
7162
7824
|
};
|
|
7163
7825
|
if (!SHARED_HOOK_FILES.filter((file) => !BACKGROUND_FILTER_FILES.includes(file)).every(filesReady))
|
|
7164
7826
|
return result("failed", "missing_files");
|
|
7165
7827
|
if (spawnSync2("bash", ["-c", "command -v curl >/dev/null && command -v jq >/dev/null && command -v openssl >/dev/null"], { timeout: 5000 }).status !== 0)
|
|
7166
7828
|
return result("failed", "missing_dependency");
|
|
7167
7829
|
if (isAntigravityAgent(agentId)) {
|
|
7168
|
-
if (!
|
|
7830
|
+
if (!existsSync5(join3(getAntigravityPluginRoot(agentId), "plugin.json")))
|
|
7169
7831
|
return result("failed", "missing_files");
|
|
7170
7832
|
const mode = existing.e2eMode ?? "approval";
|
|
7171
7833
|
const hooks = mode === "observe" ? agent.hooks.filter((h) => h.name !== "Stop") : agent.hooks;
|
|
7172
|
-
return checkHookConfiguration(agentId, config, "agentapprove", hooks, "approval", filesReady, (file, name) => buildAntigravityHookCommand(
|
|
7834
|
+
return checkHookConfiguration(agentId, config, "agentapprove", hooks, "approval", filesReady, (file, name) => buildAntigravityHookCommand(join3(getAgentApproveDir(), "hooks", file), agentId, name, mode));
|
|
7173
7835
|
}
|
|
7174
|
-
return checkHookConfiguration(agentId, config, agent.hooksKey, agent.hooks, existing.e2eMode ?? "approval", filesReady, (file) => buildHookCommand(
|
|
7836
|
+
return checkHookConfiguration(agentId, config, agent.hooksKey, agent.hooks, existing.e2eMode ?? "approval", filesReady, (file) => buildHookCommand(join3(getAgentApproveDir(), "hooks", file), agentId));
|
|
7175
7837
|
} catch {
|
|
7176
7838
|
return result("failed", "invalid_config");
|
|
7177
7839
|
}
|
|
7178
7840
|
});
|
|
7179
7841
|
}
|
|
7180
7842
|
async function checkSetupCommand() {
|
|
7181
|
-
const selectionFile =
|
|
7843
|
+
const selectionFile = join3(getAgentApproveDir(), "setup-agents.json");
|
|
7182
7844
|
let agents;
|
|
7183
7845
|
try {
|
|
7184
|
-
agents = JSON.parse(
|
|
7846
|
+
agents = JSON.parse(readFileSync3(selectionFile, "utf8")).filter((id) => typeof id === "string" && (id in AGENTS));
|
|
7185
7847
|
} catch {
|
|
7186
7848
|
agents = detectInstalledAgents();
|
|
7187
7849
|
}
|
|
@@ -7195,9 +7857,9 @@ async function profilesCommand() {
|
|
|
7195
7857
|
console.clear();
|
|
7196
7858
|
pe(source_default.bgCyan.black(" Agent Approve ") + source_default.gray(" Hermes Profiles"));
|
|
7197
7859
|
try {
|
|
7198
|
-
|
|
7199
|
-
} catch {
|
|
7200
|
-
v2.error(
|
|
7860
|
+
runHostCommand("hermes", ["--version"]);
|
|
7861
|
+
} catch (err) {
|
|
7862
|
+
v2.error(`Could not check Hermes CLI: ${err instanceof Error ? err.message : String(err)}. Run hermes --version to diagnose, then retry setup.`);
|
|
7201
7863
|
ge("No changes made.");
|
|
7202
7864
|
process.exit(1);
|
|
7203
7865
|
}
|
|
@@ -7261,16 +7923,15 @@ async function profilesCommand() {
|
|
|
7261
7923
|
process.exit(0);
|
|
7262
7924
|
}
|
|
7263
7925
|
if (toSync.length > 0) {
|
|
7264
|
-
const s = _2();
|
|
7265
7926
|
const verb = toInstall.length && toUpdate.length ? "Installing/updating" : toUpdate.length ? "Updating" : "Installing";
|
|
7266
|
-
|
|
7927
|
+
v2.step(`${verb} Agent Approve in ${toSync.length} profile(s)…`);
|
|
7267
7928
|
const sync = await syncHermesProfiles(toSync);
|
|
7268
7929
|
if (sync.results.length === 0) {
|
|
7269
|
-
|
|
7930
|
+
v2.error(`Failed: ${sync.error ?? "unknown error"}`);
|
|
7270
7931
|
ge("No changes made.");
|
|
7271
7932
|
process.exit(1);
|
|
7272
7933
|
}
|
|
7273
|
-
|
|
7934
|
+
v2.info(sync.ok ? "Done" : "Done (some profiles failed)");
|
|
7274
7935
|
for (const r of sync.results) {
|
|
7275
7936
|
const action = toUpdate.includes(r.profile) ? "updated to" : "installed";
|
|
7276
7937
|
if (r.success)
|
|
@@ -7292,16 +7953,16 @@ async function statusCommand() {
|
|
|
7292
7953
|
console.log(source_default.cyan(`
|
|
7293
7954
|
Agent Approve Status
|
|
7294
7955
|
`));
|
|
7295
|
-
if (
|
|
7956
|
+
if (existsSync5(join3(getAgentApproveDir(), DISABLED_STATE_FILENAME))) {
|
|
7296
7957
|
console.log(source_default.yellow(" Disabled: hooks and plugins are deregistered from your agents."));
|
|
7297
7958
|
console.log(source_default.dim(" Run `npx agentapprove enable` to restore them.\n"));
|
|
7298
7959
|
}
|
|
7299
|
-
const envPath =
|
|
7300
|
-
if (!
|
|
7960
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
7961
|
+
if (!existsSync5(envPath)) {
|
|
7301
7962
|
console.log(source_default.yellow(" Not configured. Run `npx agentapprove` to set up.\n"));
|
|
7302
7963
|
return;
|
|
7303
7964
|
}
|
|
7304
|
-
const envContent =
|
|
7965
|
+
const envContent = readFileSync3(envPath, "utf-8");
|
|
7305
7966
|
const lines = envContent.split(`
|
|
7306
7967
|
`);
|
|
7307
7968
|
let envToken = "";
|
|
@@ -7321,15 +7982,15 @@ async function statusCommand() {
|
|
|
7321
7982
|
}
|
|
7322
7983
|
}
|
|
7323
7984
|
await syncKeychainTokenWithEnv(envToken);
|
|
7324
|
-
const e2eKeyFile =
|
|
7325
|
-
const e2eServerKeyFile =
|
|
7326
|
-
if (
|
|
7985
|
+
const e2eKeyFile = join3(getAgentApproveDir(), "e2e-key");
|
|
7986
|
+
const e2eServerKeyFile = join3(getAgentApproveDir(), "e2e-server-key");
|
|
7987
|
+
if (existsSync5(e2eKeyFile)) {
|
|
7327
7988
|
console.log(` ${source_default.green("✓")} E2E user key: installed`);
|
|
7328
7989
|
}
|
|
7329
|
-
if (
|
|
7990
|
+
if (existsSync5(e2eServerKeyFile)) {
|
|
7330
7991
|
console.log(` ${source_default.green("✓")} E2E server key: installed`);
|
|
7331
7992
|
}
|
|
7332
|
-
if (!
|
|
7993
|
+
if (!existsSync5(e2eKeyFile) && !existsSync5(e2eServerKeyFile)) {
|
|
7333
7994
|
console.log(` ${source_default.dim(" E2E encryption: not configured")}`);
|
|
7334
7995
|
}
|
|
7335
7996
|
console.log();
|
|
@@ -7364,8 +8025,14 @@ async function statusCommand() {
|
|
|
7364
8025
|
} catch {}
|
|
7365
8026
|
continue;
|
|
7366
8027
|
}
|
|
7367
|
-
if (
|
|
7368
|
-
|
|
8028
|
+
if (existsSync5(agent.configPath)) {
|
|
8029
|
+
let config;
|
|
8030
|
+
try {
|
|
8031
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
8032
|
+
} catch (error) {
|
|
8033
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name}: ${configErrorMessage(error)}`);
|
|
8034
|
+
continue;
|
|
8035
|
+
}
|
|
7369
8036
|
if (agentId === "opencode") {
|
|
7370
8037
|
const pluginConfig = config.plugin;
|
|
7371
8038
|
if (Array.isArray(pluginConfig) && pluginConfig.some((entry) => typeof entry === "string" && entry.includes("@agentapprove/opencode"))) {
|
|
@@ -7416,12 +8083,12 @@ function sleepMsSync(ms) {
|
|
|
7416
8083
|
function acquireDisabledStateMergeLock(lockPath) {
|
|
7417
8084
|
for (let attempt = 0;attempt < 40; attempt++) {
|
|
7418
8085
|
try {
|
|
7419
|
-
|
|
8086
|
+
mkdirSync3(lockPath);
|
|
7420
8087
|
return true;
|
|
7421
8088
|
} catch {
|
|
7422
8089
|
try {
|
|
7423
|
-
if (Date.now() -
|
|
7424
|
-
|
|
8090
|
+
if (Date.now() - statSync2(lockPath).mtimeMs > 1e4) {
|
|
8091
|
+
rmSync3(lockPath, { recursive: true, force: true });
|
|
7425
8092
|
continue;
|
|
7426
8093
|
}
|
|
7427
8094
|
} catch {
|
|
@@ -7434,10 +8101,10 @@ function acquireDisabledStateMergeLock(lockPath) {
|
|
|
7434
8101
|
}
|
|
7435
8102
|
async function disableCommand() {
|
|
7436
8103
|
const aaDir = getAgentApproveDir();
|
|
7437
|
-
const statePath =
|
|
8104
|
+
const statePath = join3(aaDir, DISABLED_STATE_FILENAME);
|
|
7438
8105
|
let hasExistingRecord = false;
|
|
7439
8106
|
try {
|
|
7440
|
-
|
|
8107
|
+
readFileSync3(statePath);
|
|
7441
8108
|
hasExistingRecord = true;
|
|
7442
8109
|
} catch {
|
|
7443
8110
|
hasExistingRecord = false;
|
|
@@ -7449,7 +8116,7 @@ async function disableCommand() {
|
|
|
7449
8116
|
return;
|
|
7450
8117
|
}
|
|
7451
8118
|
const existingConfig = readExistingConfig();
|
|
7452
|
-
const legacyDisabledEnv =
|
|
8119
|
+
const legacyDisabledEnv = existsSync5(join3(aaDir, "env.disabled"));
|
|
7453
8120
|
console.log(source_default.cyan(`
|
|
7454
8121
|
Disabling Agent Approve...
|
|
7455
8122
|
`));
|
|
@@ -7484,7 +8151,7 @@ async function disableCommand() {
|
|
|
7484
8151
|
agents: records
|
|
7485
8152
|
};
|
|
7486
8153
|
try {
|
|
7487
|
-
|
|
8154
|
+
writeFileSync2(statePath, JSON.stringify(state, null, 2) + `
|
|
7488
8155
|
`, { mode: 384, flag: "wx" });
|
|
7489
8156
|
} catch (err) {
|
|
7490
8157
|
let failed = true;
|
|
@@ -7492,18 +8159,18 @@ async function disableCommand() {
|
|
|
7492
8159
|
const lockPath = `${statePath}.lock`;
|
|
7493
8160
|
if (acquireDisabledStateMergeLock(lockPath)) {
|
|
7494
8161
|
try {
|
|
7495
|
-
const existing = parseDisabledState(
|
|
8162
|
+
const existing = parseDisabledState(readFileSync3(statePath, "utf-8"));
|
|
7496
8163
|
const merged = existing ? mergeDisabledStates(existing, state) : state;
|
|
7497
8164
|
const tmpPath = `${statePath}.tmp-${process.pid}`;
|
|
7498
|
-
|
|
8165
|
+
writeFileSync2(tmpPath, JSON.stringify(merged, null, 2) + `
|
|
7499
8166
|
`, { mode: 384 });
|
|
7500
|
-
|
|
8167
|
+
renameSync4(tmpPath, statePath);
|
|
7501
8168
|
failed = false;
|
|
7502
8169
|
} catch {
|
|
7503
8170
|
failed = true;
|
|
7504
8171
|
} finally {
|
|
7505
8172
|
try {
|
|
7506
|
-
|
|
8173
|
+
rmSync3(lockPath, { recursive: true, force: true });
|
|
7507
8174
|
} catch {}
|
|
7508
8175
|
}
|
|
7509
8176
|
}
|
|
@@ -7521,7 +8188,7 @@ async function disableCommand() {
|
|
|
7521
8188
|
✓ Agent Approve disabled.`));
|
|
7522
8189
|
console.log(source_default.dim(" Hooks and plugins are deregistered from your agents, so Agent Approve no longer runs."));
|
|
7523
8190
|
console.log(source_default.dim(" Local state (pairing, settings, E2E keys, hook scripts) is kept in ~/.agentapprove."));
|
|
7524
|
-
if (
|
|
8191
|
+
if (existsSync5(join3(aaDir, "copilot-cli-hooks.json"))) {
|
|
7525
8192
|
console.log(source_default.yellow(" Note: per-repo GitHub Copilot hooks (.github/hooks/agentapprove.json, added with `init-repo`)"));
|
|
7526
8193
|
console.log(source_default.yellow(" cannot be reached from here and stay active until you remove them in each repo."));
|
|
7527
8194
|
}
|
|
@@ -7532,9 +8199,15 @@ async function disableCommand() {
|
|
|
7532
8199
|
}
|
|
7533
8200
|
function disableAgent(agentId, agent, records, warnings) {
|
|
7534
8201
|
if (agentId === "pi") {
|
|
7535
|
-
if (!
|
|
8202
|
+
if (!existsSync5(agent.configPath))
|
|
7536
8203
|
return;
|
|
7537
|
-
|
|
8204
|
+
let settings;
|
|
8205
|
+
try {
|
|
8206
|
+
settings = readJsonConfig(agent.configPath);
|
|
8207
|
+
} catch (error) {
|
|
8208
|
+
warnings.push(`${agent.name}: ${configErrorMessage(error)}`);
|
|
8209
|
+
return;
|
|
8210
|
+
}
|
|
7538
8211
|
const removal = removePiPackageEntries(settings);
|
|
7539
8212
|
if (removal.modified) {
|
|
7540
8213
|
writeJsonConfig(agent.configPath, settings);
|
|
@@ -7563,10 +8236,10 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7563
8236
|
}
|
|
7564
8237
|
if (isAntigravityAgent(agentId)) {
|
|
7565
8238
|
const pluginRoot = getAntigravityPluginRoot(agentId);
|
|
7566
|
-
if (!
|
|
8239
|
+
if (!existsSync5(pluginRoot))
|
|
7567
8240
|
return;
|
|
7568
8241
|
try {
|
|
7569
|
-
|
|
8242
|
+
rmSync3(pluginRoot, { recursive: true, force: true });
|
|
7570
8243
|
records.push({ agentId, kind: "hooks" });
|
|
7571
8244
|
console.log(` ${source_default.green("✓")} ${agent.name}: plugin deregistered`);
|
|
7572
8245
|
} catch (err) {
|
|
@@ -7575,7 +8248,9 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7575
8248
|
return;
|
|
7576
8249
|
}
|
|
7577
8250
|
if (agentId === "vscode-agent") {
|
|
7578
|
-
const removedVSCode = removeFromVSCodeHookLocations()
|
|
8251
|
+
const removedVSCode = removeFromVSCodeHookLocations((failure) => {
|
|
8252
|
+
warnings.push(`${agent.name} (${failure.variant}): ${failure.error}`);
|
|
8253
|
+
});
|
|
7579
8254
|
if (removedVSCode.length > 0) {
|
|
7580
8255
|
records.push({ agentId, kind: "vscode_hook_location" });
|
|
7581
8256
|
for (const path of removedVSCode) {
|
|
@@ -7587,9 +8262,15 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7587
8262
|
if (agentId === "copilot-cli") {
|
|
7588
8263
|
return;
|
|
7589
8264
|
}
|
|
7590
|
-
if (!
|
|
8265
|
+
if (!existsSync5(agent.configPath))
|
|
8266
|
+
return;
|
|
8267
|
+
let config;
|
|
8268
|
+
try {
|
|
8269
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
8270
|
+
} catch (error) {
|
|
8271
|
+
warnings.push(`${agent.name}: ${configErrorMessage(error)}`);
|
|
7591
8272
|
return;
|
|
7592
|
-
|
|
8273
|
+
}
|
|
7593
8274
|
if (agentId === "openclaw") {
|
|
7594
8275
|
const flip = disableOpenClawEntries(config);
|
|
7595
8276
|
if (flip.modified) {
|
|
@@ -7620,9 +8301,12 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7620
8301
|
const hooksConfig = useTopLevelHooks ? config : config[agent.hooksKey] ?? {};
|
|
7621
8302
|
const modified = removeAgentApproveHookEntries(hooksConfig, agent.hooks.map((hook) => hook.name));
|
|
7622
8303
|
if (modified) {
|
|
8304
|
+
const commentsNote = keepCommentedConfig(agentId, agent.configPath);
|
|
7623
8305
|
writeJsonConfig(agent.configPath, config);
|
|
7624
8306
|
records.push({ agentId, kind: "hooks" });
|
|
7625
8307
|
console.log(` ${source_default.green("✓")} ${agent.name}: hooks deregistered`);
|
|
8308
|
+
if (commentsNote)
|
|
8309
|
+
console.log(source_default.dim(` ${commentsNote}`));
|
|
7626
8310
|
if (agentId === "codex" && Object.keys(hooksConfig).length === 0) {
|
|
7627
8311
|
const codexFlag = disableCodexFeatureFlag();
|
|
7628
8312
|
if (codexFlag.updated) {
|
|
@@ -7631,24 +8315,33 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7631
8315
|
}
|
|
7632
8316
|
}
|
|
7633
8317
|
}
|
|
8318
|
+
function readRestorableConfig(agent, record, failures) {
|
|
8319
|
+
try {
|
|
8320
|
+
return readJsonConfig(agent.configPath);
|
|
8321
|
+
} catch (error) {
|
|
8322
|
+
failures.push(record);
|
|
8323
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name}: could not restore the registration. ${configErrorMessage(error)}`);
|
|
8324
|
+
return null;
|
|
8325
|
+
}
|
|
8326
|
+
}
|
|
7634
8327
|
async function enableCommand() {
|
|
7635
8328
|
const aaDir = getAgentApproveDir();
|
|
7636
|
-
const envPath =
|
|
7637
|
-
const legacyDisabledPath =
|
|
7638
|
-
const statePath =
|
|
7639
|
-
if (!
|
|
7640
|
-
|
|
8329
|
+
const envPath = join3(aaDir, "env");
|
|
8330
|
+
const legacyDisabledPath = join3(aaDir, "env.disabled");
|
|
8331
|
+
const statePath = join3(aaDir, DISABLED_STATE_FILENAME);
|
|
8332
|
+
if (!existsSync5(envPath) && existsSync5(legacyDisabledPath)) {
|
|
8333
|
+
renameSync4(legacyDisabledPath, envPath);
|
|
7641
8334
|
console.log(source_default.green(`
|
|
7642
8335
|
✓ Restored ~/.agentapprove/env (legacy disable).`));
|
|
7643
8336
|
}
|
|
7644
8337
|
let stateRaw = null;
|
|
7645
8338
|
try {
|
|
7646
|
-
stateRaw =
|
|
8339
|
+
stateRaw = readFileSync3(statePath, "utf-8");
|
|
7647
8340
|
} catch {
|
|
7648
8341
|
stateRaw = null;
|
|
7649
8342
|
}
|
|
7650
8343
|
if (stateRaw === null) {
|
|
7651
|
-
if (
|
|
8344
|
+
if (existsSync5(envPath)) {
|
|
7652
8345
|
console.log(source_default.yellow(`
|
|
7653
8346
|
Already enabled.
|
|
7654
8347
|
`));
|
|
@@ -7659,7 +8352,7 @@ async function enableCommand() {
|
|
|
7659
8352
|
}
|
|
7660
8353
|
const state = parseDisabledState(stateRaw);
|
|
7661
8354
|
if (!state) {
|
|
7662
|
-
|
|
8355
|
+
rmSync3(statePath, { force: true });
|
|
7663
8356
|
console.log(source_default.yellow(`
|
|
7664
8357
|
The disable record was unreadable, so registrations were not restored automatically.`));
|
|
7665
8358
|
console.log(source_default.dim(" Run `npx agentapprove install` to re-register hooks and plugins (your pairing is kept).\n"));
|
|
@@ -7668,7 +8361,7 @@ async function enableCommand() {
|
|
|
7668
8361
|
console.log(source_default.cyan(`
|
|
7669
8362
|
Re-enabling Agent Approve...
|
|
7670
8363
|
`));
|
|
7671
|
-
const hooksDir =
|
|
8364
|
+
const hooksDir = join3(aaDir, "hooks");
|
|
7672
8365
|
const failures = [];
|
|
7673
8366
|
for (const record of state.agents) {
|
|
7674
8367
|
const agent = AGENTS[record.agentId];
|
|
@@ -7679,7 +8372,7 @@ async function enableCommand() {
|
|
|
7679
8372
|
}
|
|
7680
8373
|
switch (record.kind) {
|
|
7681
8374
|
case "hooks": {
|
|
7682
|
-
if (!
|
|
8375
|
+
if (!existsSync5(hooksDir)) {
|
|
7683
8376
|
failures.push(record);
|
|
7684
8377
|
console.log(` ${source_default.yellow("⚠")} ${agent.name}: ~/.agentapprove/hooks is missing. Run \`npx agentapprove install\` to re-download hook scripts.`);
|
|
7685
8378
|
break;
|
|
@@ -7687,6 +8380,8 @@ async function enableCommand() {
|
|
|
7687
8380
|
const result = await installHooksForAgent(record.agentId, hooksDir, state.mode);
|
|
7688
8381
|
if (result.success) {
|
|
7689
8382
|
console.log(` ${source_default.green("✓")} ${agent.name}: hooks re-registered`);
|
|
8383
|
+
if (result.note)
|
|
8384
|
+
console.log(source_default.dim(` ${result.note}`));
|
|
7690
8385
|
} else {
|
|
7691
8386
|
failures.push(record);
|
|
7692
8387
|
console.log(` ${source_default.yellow("⚠")} ${agent.name}: could not re-register hooks (${result.error || "unknown error"})`);
|
|
@@ -7694,20 +8389,28 @@ async function enableCommand() {
|
|
|
7694
8389
|
break;
|
|
7695
8390
|
}
|
|
7696
8391
|
case "vscode_hook_location": {
|
|
7697
|
-
const modifiedPaths = addToVSCodeHookLocations();
|
|
8392
|
+
const { modified: modifiedPaths, failed: failedSettings } = addToVSCodeHookLocations();
|
|
7698
8393
|
if (modifiedPaths.length > 0) {
|
|
7699
8394
|
console.log(` ${source_default.green("✓")} ${agent.name}: hook path re-registered in ${modifiedPaths.join(", ")}`);
|
|
7700
|
-
} else {
|
|
8395
|
+
} else if (failedSettings.length === 0) {
|
|
7701
8396
|
console.log(` ${source_default.green("✓")} ${agent.name}: hook path already registered`);
|
|
7702
8397
|
}
|
|
8398
|
+
if (failedSettings.length > 0) {
|
|
8399
|
+
failures.push(record);
|
|
8400
|
+
for (const failure of failedSettings) {
|
|
8401
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name} (${failure.variant}): could not re-register the hook path. ${failure.error}`);
|
|
8402
|
+
}
|
|
8403
|
+
}
|
|
7703
8404
|
break;
|
|
7704
8405
|
}
|
|
7705
8406
|
case "openclaw_entries": {
|
|
7706
|
-
if (!
|
|
8407
|
+
if (!existsSync5(agent.configPath)) {
|
|
7707
8408
|
console.log(` ${source_default.yellow("⚠")} ${agent.name}: config not found; skipping`);
|
|
7708
8409
|
break;
|
|
7709
8410
|
}
|
|
7710
|
-
const config =
|
|
8411
|
+
const config = readRestorableConfig(agent, record, failures);
|
|
8412
|
+
if (!config)
|
|
8413
|
+
break;
|
|
7711
8414
|
if (enableOpenClawEntries(config, record.entryKeys ?? [])) {
|
|
7712
8415
|
writeJsonConfig(agent.configPath, config);
|
|
7713
8416
|
}
|
|
@@ -7715,7 +8418,9 @@ async function enableCommand() {
|
|
|
7715
8418
|
break;
|
|
7716
8419
|
}
|
|
7717
8420
|
case "opencode_plugin": {
|
|
7718
|
-
const config =
|
|
8421
|
+
const config = readRestorableConfig(agent, record, failures);
|
|
8422
|
+
if (!config)
|
|
8423
|
+
break;
|
|
7719
8424
|
if (addOpenCodePluginEntries(config, record.specs ?? [])) {
|
|
7720
8425
|
writeJsonConfig(agent.configPath, config);
|
|
7721
8426
|
}
|
|
@@ -7726,7 +8431,9 @@ async function enableCommand() {
|
|
|
7726
8431
|
break;
|
|
7727
8432
|
}
|
|
7728
8433
|
case "pi_packages": {
|
|
7729
|
-
const settings =
|
|
8434
|
+
const settings = readRestorableConfig(agent, record, failures);
|
|
8435
|
+
if (!settings)
|
|
8436
|
+
break;
|
|
7730
8437
|
if (addPiPackageEntries(settings, record.specs ?? [])) {
|
|
7731
8438
|
writeJsonConfig(agent.configPath, settings);
|
|
7732
8439
|
}
|
|
@@ -7759,25 +8466,25 @@ async function enableCommand() {
|
|
|
7759
8466
|
}
|
|
7760
8467
|
if (failures.length > 0) {
|
|
7761
8468
|
const remaining = { ...state, agents: failures };
|
|
7762
|
-
|
|
7763
|
-
|
|
8469
|
+
writePrivateFile(statePath, JSON.stringify(remaining, null, 2) + `
|
|
8470
|
+
`);
|
|
7764
8471
|
console.log(source_default.yellow("\n Agent Approve is partially re-enabled. Fix the warnings above and re-run `npx agentapprove enable`.\n"));
|
|
7765
8472
|
return;
|
|
7766
8473
|
}
|
|
7767
|
-
|
|
8474
|
+
rmSync3(statePath, { force: true });
|
|
7768
8475
|
console.log(source_default.green(`
|
|
7769
8476
|
✓ Agent Approve enabled.
|
|
7770
8477
|
`));
|
|
7771
8478
|
}
|
|
7772
8479
|
function removeOpenCodeLegacyDependency() {
|
|
7773
|
-
const opencodePkgPath =
|
|
8480
|
+
const opencodePkgPath = join3(getOpenCodeConfigDir(), "package.json");
|
|
7774
8481
|
try {
|
|
7775
|
-
const pkgJson = JSON.parse(
|
|
8482
|
+
const pkgJson = JSON.parse(readFileSync3(opencodePkgPath, "utf-8"));
|
|
7776
8483
|
const deps = pkgJson.dependencies;
|
|
7777
8484
|
const version = deps?.["@agentapprove/opencode"];
|
|
7778
8485
|
if (deps && version) {
|
|
7779
8486
|
delete deps["@agentapprove/opencode"];
|
|
7780
|
-
|
|
8487
|
+
writeFileSync2(opencodePkgPath, JSON.stringify(pkgJson, null, 2) + `
|
|
7781
8488
|
`);
|
|
7782
8489
|
return version;
|
|
7783
8490
|
}
|
|
@@ -7785,17 +8492,18 @@ function removeOpenCodeLegacyDependency() {
|
|
|
7785
8492
|
return null;
|
|
7786
8493
|
}
|
|
7787
8494
|
function restoreOpenCodeLegacyDependency(version) {
|
|
7788
|
-
const opencodePkgPath =
|
|
7789
|
-
let pkgJson
|
|
8495
|
+
const opencodePkgPath = join3(getOpenCodeConfigDir(), "package.json");
|
|
8496
|
+
let pkgJson;
|
|
7790
8497
|
try {
|
|
7791
|
-
pkgJson =
|
|
7792
|
-
} catch {
|
|
7793
|
-
|
|
8498
|
+
pkgJson = readJsonConfig(opencodePkgPath);
|
|
8499
|
+
} catch (error) {
|
|
8500
|
+
console.log(` ${source_default.yellow("⚠")} OpenCode: the legacy plugin dependency was not restored. ${configErrorMessage(error)}`);
|
|
8501
|
+
return;
|
|
7794
8502
|
}
|
|
7795
8503
|
const deps = pkgJson.dependencies ?? {};
|
|
7796
8504
|
deps["@agentapprove/opencode"] = version;
|
|
7797
8505
|
pkgJson.dependencies = deps;
|
|
7798
|
-
|
|
8506
|
+
writeFileSync2(opencodePkgPath, JSON.stringify(pkgJson, null, 2) + `
|
|
7799
8507
|
`);
|
|
7800
8508
|
}
|
|
7801
8509
|
async function performUninstall(mode) {
|
|
@@ -7817,7 +8525,7 @@ async function performUninstall(mode) {
|
|
|
7817
8525
|
const result = removePiPluginViaCli();
|
|
7818
8526
|
if (result.success) {
|
|
7819
8527
|
console.log(` ${source_default.green("✓")} Pi extension removed`);
|
|
7820
|
-
} else if (
|
|
8528
|
+
} else if (existsSync5(agent.configPath)) {
|
|
7821
8529
|
console.log(` ${source_default.yellow("⚠")} Pi extension removal skipped or failed (${result.error || "Pi CLI unavailable"})`);
|
|
7822
8530
|
}
|
|
7823
8531
|
continue;
|
|
@@ -7834,9 +8542,15 @@ async function performUninstall(mode) {
|
|
|
7834
8542
|
}
|
|
7835
8543
|
continue;
|
|
7836
8544
|
}
|
|
7837
|
-
if (!
|
|
8545
|
+
if (!existsSync5(agent.configPath))
|
|
7838
8546
|
continue;
|
|
7839
|
-
|
|
8547
|
+
let config;
|
|
8548
|
+
try {
|
|
8549
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
8550
|
+
} catch (error) {
|
|
8551
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name}: ${configErrorMessage(error)}`);
|
|
8552
|
+
continue;
|
|
8553
|
+
}
|
|
7840
8554
|
const hooksConfig = agent.hooksKey === "" ? config : config[agent.hooksKey] ?? {};
|
|
7841
8555
|
let modified = false;
|
|
7842
8556
|
if (agentId === "opencode") {
|
|
@@ -7849,8 +8563,11 @@ async function performUninstall(mode) {
|
|
|
7849
8563
|
modified = removeAgentApproveHookEntries(hooksConfig, agent.hooks.map((hook) => hook.name));
|
|
7850
8564
|
}
|
|
7851
8565
|
if (modified) {
|
|
8566
|
+
const commentsNote = keepCommentedConfig(agentId, agent.configPath);
|
|
7852
8567
|
writeJsonConfig(agent.configPath, config);
|
|
7853
8568
|
console.log(` ${source_default.green("✓")} Removed hooks from ${agent.name}`);
|
|
8569
|
+
if (commentsNote)
|
|
8570
|
+
console.log(source_default.dim(` ${commentsNote}`));
|
|
7854
8571
|
}
|
|
7855
8572
|
if (agentId === "codex" && modified && Object.keys(hooksConfig).length === 0) {
|
|
7856
8573
|
const codexFlag = disableCodexFeatureFlag();
|
|
@@ -7859,7 +8576,9 @@ async function performUninstall(mode) {
|
|
|
7859
8576
|
}
|
|
7860
8577
|
}
|
|
7861
8578
|
}
|
|
7862
|
-
const removedVSCode = removeFromVSCodeHookLocations()
|
|
8579
|
+
const removedVSCode = removeFromVSCodeHookLocations((failure) => {
|
|
8580
|
+
console.log(` ${source_default.yellow("⚠")} ${failure.variant}: ${failure.error}`);
|
|
8581
|
+
});
|
|
7863
8582
|
if (removedVSCode.length > 0) {
|
|
7864
8583
|
for (const path of removedVSCode) {
|
|
7865
8584
|
console.log(` ${source_default.green("✓")} Removed hook path from ${path}`);
|
|
@@ -7871,16 +8590,16 @@ async function performUninstall(mode) {
|
|
|
7871
8590
|
}
|
|
7872
8591
|
console.log(` ${source_default.green("✓")} Removed plugin files at ${target.displayPath}`);
|
|
7873
8592
|
if (target.actualPath.endsWith("/node_modules/@agentapprove/opencode")) {
|
|
7874
|
-
pruneEmptyDir(
|
|
7875
|
-
pruneEmptyDir(
|
|
8593
|
+
pruneEmptyDir(dirname4(target.actualPath));
|
|
8594
|
+
pruneEmptyDir(dirname4(dirname4(target.actualPath)));
|
|
7876
8595
|
}
|
|
7877
8596
|
if (target.actualPath.includes("/extensions/")) {
|
|
7878
|
-
pruneEmptyDir(
|
|
8597
|
+
pruneEmptyDir(dirname4(target.actualPath));
|
|
7879
8598
|
}
|
|
7880
8599
|
}
|
|
7881
|
-
const disabledStatePath =
|
|
7882
|
-
if (
|
|
7883
|
-
|
|
8600
|
+
const disabledStatePath = join3(getAgentApproveDir(), DISABLED_STATE_FILENAME);
|
|
8601
|
+
if (existsSync5(disabledStatePath)) {
|
|
8602
|
+
rmSync3(disabledStatePath, { force: true });
|
|
7884
8603
|
console.log(` ${source_default.green("✓")} Removed the disable restore record (superseded by ${mode})`);
|
|
7885
8604
|
}
|
|
7886
8605
|
if (mode === "purge") {
|
|
@@ -7926,13 +8645,13 @@ async function restoreCommand() {
|
|
|
7926
8645
|
`));
|
|
7927
8646
|
const { readdirSync, copyFileSync } = await import("fs");
|
|
7928
8647
|
for (const [agentId, agent] of Object.entries(AGENTS)) {
|
|
7929
|
-
const configDir =
|
|
7930
|
-
if (!
|
|
8648
|
+
const configDir = dirname4(agent.configPath);
|
|
8649
|
+
if (!existsSync5(configDir))
|
|
7931
8650
|
continue;
|
|
7932
8651
|
const files = readdirSync(configDir);
|
|
7933
8652
|
const backups = files.filter((f) => f.startsWith(agent.configPath.split("/").pop()) && f.includes(".backup.")).sort().reverse();
|
|
7934
8653
|
if (backups.length > 0) {
|
|
7935
|
-
const latestBackup =
|
|
8654
|
+
const latestBackup = join3(configDir, backups[0]);
|
|
7936
8655
|
copyFileSync(latestBackup, agent.configPath);
|
|
7937
8656
|
console.log(` ${source_default.green("✓")} ${agent.name} restored from ${backups[0]}`);
|
|
7938
8657
|
}
|
|
@@ -7940,13 +8659,13 @@ async function restoreCommand() {
|
|
|
7940
8659
|
console.log();
|
|
7941
8660
|
}
|
|
7942
8661
|
async function initRepoCommand() {
|
|
7943
|
-
const cliHooksPath =
|
|
7944
|
-
if (
|
|
8662
|
+
const cliHooksPath = join3(getAgentApproveDir(), "copilot-cli-hooks.json");
|
|
8663
|
+
if (existsSync5(join3(getAgentApproveDir(), DISABLED_STATE_FILENAME))) {
|
|
7945
8664
|
console.log(source_default.yellow(`
|
|
7946
8665
|
Agent Approve is currently disabled. Hooks copied into this repo will be active.`));
|
|
7947
8666
|
console.log(source_default.dim(" Run `npx agentapprove enable` first if that is not what you want."));
|
|
7948
8667
|
}
|
|
7949
|
-
if (!
|
|
8668
|
+
if (!existsSync5(cliHooksPath)) {
|
|
7950
8669
|
console.log(source_default.yellow(`
|
|
7951
8670
|
GitHub Copilot CLI hooks not found. Run the installer first with GitHub Copilot CLI selected.`));
|
|
7952
8671
|
console.log(source_default.dim(` npx agentapprove install
|
|
@@ -7955,12 +8674,12 @@ async function initRepoCommand() {
|
|
|
7955
8674
|
}
|
|
7956
8675
|
let repoRoot = process.cwd();
|
|
7957
8676
|
let found = false;
|
|
7958
|
-
while (repoRoot !==
|
|
7959
|
-
if (
|
|
8677
|
+
while (repoRoot !== dirname4(repoRoot)) {
|
|
8678
|
+
if (existsSync5(join3(repoRoot, ".git"))) {
|
|
7960
8679
|
found = true;
|
|
7961
8680
|
break;
|
|
7962
8681
|
}
|
|
7963
|
-
repoRoot =
|
|
8682
|
+
repoRoot = dirname4(repoRoot);
|
|
7964
8683
|
}
|
|
7965
8684
|
if (!found) {
|
|
7966
8685
|
console.log(source_default.yellow(`
|
|
@@ -7968,12 +8687,12 @@ async function initRepoCommand() {
|
|
|
7968
8687
|
`));
|
|
7969
8688
|
process.exit(1);
|
|
7970
8689
|
}
|
|
7971
|
-
const targetDir =
|
|
7972
|
-
const targetFile =
|
|
8690
|
+
const targetDir = join3(repoRoot, ".github", "hooks");
|
|
8691
|
+
const targetFile = join3(targetDir, "agentapprove.json");
|
|
7973
8692
|
console.log(source_default.cyan(`
|
|
7974
8693
|
Installing GitHub Copilot CLI hooks to ${targetFile}
|
|
7975
8694
|
`));
|
|
7976
|
-
if (
|
|
8695
|
+
if (existsSync5(targetFile)) {
|
|
7977
8696
|
console.log(source_default.yellow(" agentapprove.json already exists in .github/hooks/"));
|
|
7978
8697
|
const overwrite = await ce({
|
|
7979
8698
|
message: "Overwrite existing file?"
|
|
@@ -7984,10 +8703,10 @@ async function initRepoCommand() {
|
|
|
7984
8703
|
process.exit(0);
|
|
7985
8704
|
}
|
|
7986
8705
|
}
|
|
7987
|
-
if (!
|
|
7988
|
-
|
|
8706
|
+
if (!existsSync5(targetDir)) {
|
|
8707
|
+
mkdirSync3(targetDir, { recursive: true });
|
|
7989
8708
|
}
|
|
7990
|
-
|
|
8709
|
+
copyFileSync2(cliHooksPath, targetFile);
|
|
7991
8710
|
console.log(source_default.green(` ✓ Copied GitHub Copilot CLI hooks to .github/hooks/agentapprove.json`));
|
|
7992
8711
|
console.log(source_default.dim(` Commit this file so Copilot coding agent uses your hooks.
|
|
7993
8712
|
`));
|
|
@@ -8049,14 +8768,14 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
|
|
|
8049
8768
|
let apiUrl = pairingApiBase;
|
|
8050
8769
|
const installedAgents = detectInstalledAgents();
|
|
8051
8770
|
const e2eEnabled = existingConfig.e2eEnabled !== false;
|
|
8052
|
-
const e2eKeyPath =
|
|
8771
|
+
const e2eKeyPath = join3(getAgentApproveDir(), "e2e-key");
|
|
8053
8772
|
let e2eUserKey = null;
|
|
8054
8773
|
let e2eKeyId;
|
|
8055
|
-
if (e2eEnabled &&
|
|
8056
|
-
const existingKey =
|
|
8774
|
+
if (e2eEnabled && existsSync5(e2eKeyPath)) {
|
|
8775
|
+
const existingKey = readFileSync3(e2eKeyPath, "utf-8").trim();
|
|
8057
8776
|
if (existingKey.length === 64) {
|
|
8058
8777
|
e2eUserKey = existingKey;
|
|
8059
|
-
e2eKeyId =
|
|
8778
|
+
e2eKeyId = createHash3("sha256").update(Buffer.from(existingKey, "hex")).digest("hex").slice(0, 8);
|
|
8060
8779
|
v2.info(`Refresh will reuse E2E key ${e2eKeyId}. Use "npx agentapprove pair" if you need to choose a different key or repair pairing on another device.`);
|
|
8061
8780
|
}
|
|
8062
8781
|
} else {
|
|
@@ -8132,16 +8851,16 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
|
|
|
8132
8851
|
});
|
|
8133
8852
|
await storeTokenInKeychain(token);
|
|
8134
8853
|
if (e2eEnabled && result.e2eServerKey) {
|
|
8135
|
-
const serverKeyPath =
|
|
8136
|
-
|
|
8854
|
+
const serverKeyPath = join3(getAgentApproveDir(), "e2e-server-key");
|
|
8855
|
+
writePrivateFile(serverKeyPath, result.e2eServerKey);
|
|
8137
8856
|
}
|
|
8138
8857
|
const updateSpinner = _2();
|
|
8139
|
-
updateSpinner.start("
|
|
8858
|
+
updateSpinner.start("Refreshing background activity filters");
|
|
8140
8859
|
try {
|
|
8141
|
-
await
|
|
8142
|
-
updateSpinner.stop("
|
|
8860
|
+
await refreshInstalledHooks(token, apiUrl);
|
|
8861
|
+
updateSpinner.stop("Hooks will use the new token on their next run");
|
|
8143
8862
|
} catch (error) {
|
|
8144
|
-
updateSpinner.stop("Warning: Could not
|
|
8863
|
+
updateSpinner.stop("Warning: Could not refresh the installed hooks");
|
|
8145
8864
|
v2.warn('You may need to run "npx agentapprove install" to reconfigure hooks.');
|
|
8146
8865
|
}
|
|
8147
8866
|
ge(source_default.green("Token refreshed successfully!"));
|
|
@@ -8179,17 +8898,17 @@ async function pairCommand() {
|
|
|
8179
8898
|
}
|
|
8180
8899
|
}
|
|
8181
8900
|
keyOptions.push({
|
|
8182
|
-
value:
|
|
8901
|
+
value: PAIR_KEY_GENERATE,
|
|
8183
8902
|
label: "Generate a new key",
|
|
8184
8903
|
hint: "creates a fresh key for this pairing"
|
|
8185
8904
|
});
|
|
8186
8905
|
keyOptions.push({
|
|
8187
|
-
value:
|
|
8906
|
+
value: PAIR_KEY_DISABLE,
|
|
8188
8907
|
label: "Disable E2E encryption",
|
|
8189
8908
|
hint: "events visible on web dashboard"
|
|
8190
8909
|
});
|
|
8191
8910
|
const skipE2E = hasFlag2("--no-e2e");
|
|
8192
|
-
const selectedKeyId = skipE2E ?
|
|
8911
|
+
const selectedKeyId = skipE2E ? PAIR_KEY_DISABLE : await le({
|
|
8193
8912
|
message: "Select an E2E key to pair with your iOS device",
|
|
8194
8913
|
options: keyOptions
|
|
8195
8914
|
});
|
|
@@ -8197,44 +8916,20 @@ async function pairCommand() {
|
|
|
8197
8916
|
he("Pairing cancelled");
|
|
8198
8917
|
process.exit(0);
|
|
8199
8918
|
}
|
|
8200
|
-
|
|
8201
|
-
|
|
8202
|
-
|
|
8203
|
-
|
|
8204
|
-
updateEnvValue("AGENTAPPROVE_E2E_ENABLED", "false");
|
|
8205
|
-
} else if (selectedKeyId === "__generate__") {
|
|
8206
|
-
const currentKey = keys.find((k) => k.isCurrent);
|
|
8207
|
-
if (currentKey) {
|
|
8208
|
-
const agentApproveDir = getAgentApproveDir();
|
|
8209
|
-
const backupPath = join(agentApproveDir, `e2e-key.${currentKey.keyId}.bak`);
|
|
8210
|
-
renameSync2(currentKey.path, backupPath);
|
|
8211
|
-
v2.info(`Previous key backed up (${currentKey.keyId})`);
|
|
8212
|
-
}
|
|
8213
|
-
e2eUserKey = randomBytes(32).toString("hex");
|
|
8214
|
-
e2eKeyId = createHash("sha256").update(Buffer.from(e2eUserKey, "hex")).digest("hex").slice(0, 8);
|
|
8215
|
-
const agentApproveDir = getAgentApproveDir();
|
|
8216
|
-
ensureAgentApproveDir();
|
|
8217
|
-
writeFileSync(join(agentApproveDir, "e2e-root-key"), e2eUserKey, { mode: 384 });
|
|
8218
|
-
writeFileSync(join(agentApproveDir, "e2e-key"), e2eUserKey, { mode: 384 });
|
|
8219
|
-
writeRotationConfig({
|
|
8220
|
-
rootKeyId: e2eKeyId,
|
|
8221
|
-
epoch: 0,
|
|
8222
|
-
periodSeconds: 0,
|
|
8223
|
-
startedAt: new Date().toISOString()
|
|
8224
|
-
});
|
|
8225
|
-
v2.success(`New key generated (${e2eKeyId})`);
|
|
8226
|
-
} else {
|
|
8227
|
-
const selectedKey = keys.find((k) => k.keyId === selectedKeyId);
|
|
8228
|
-
if (!selectedKey) {
|
|
8229
|
-
v2.error("Selected key not found.");
|
|
8230
|
-
process.exit(1);
|
|
8231
|
-
}
|
|
8232
|
-
e2eUserKey = selectedKey.keyHex;
|
|
8233
|
-
e2eKeyId = selectedKey.keyId;
|
|
8234
|
-
v2.info(`Using key ${e2eKeyId}${selectedKey.isCurrent ? " (current)" : " (backup)"}`);
|
|
8919
|
+
const keyPlan = planPairKey(selectedKeyId, keys, getAgentApproveDir(), () => randomBytes2(32).toString("hex"));
|
|
8920
|
+
if (keyPlan.kind === "not_found") {
|
|
8921
|
+
v2.error("Selected key not found.");
|
|
8922
|
+
process.exit(1);
|
|
8235
8923
|
}
|
|
8236
|
-
|
|
8237
|
-
|
|
8924
|
+
const e2eUserKey = keyPlan.e2eUserKey;
|
|
8925
|
+
const e2eKeyId = keyPlan.kind === "disable" ? undefined : keyPlan.e2eKeyId;
|
|
8926
|
+
if (keyPlan.kind === "disable") {
|
|
8927
|
+
v2.info("E2E encryption will be disabled when pairing completes. Event content will be visible on the web dashboard.");
|
|
8928
|
+
} else if (keyPlan.kind === "generate") {
|
|
8929
|
+
v2.info(`A new key (${e2eKeyId}) will be saved when pairing completes.`);
|
|
8930
|
+
} else {
|
|
8931
|
+
const selectedKey = keys.find((k) => k.keyId === keyPlan.e2eKeyId);
|
|
8932
|
+
v2.info(`Using key ${e2eKeyId}${selectedKey?.isCurrent ? " (current)" : " (backup)"}`);
|
|
8238
8933
|
}
|
|
8239
8934
|
const installedAgents = detectInstalledAgents();
|
|
8240
8935
|
const pairingConfigSetAt = Math.floor(Date.now() / 1000);
|
|
@@ -8282,25 +8977,27 @@ async function pairCommand() {
|
|
|
8282
8977
|
v2.error('Session expired. Run "npx agentapprove pair" to try again.');
|
|
8283
8978
|
process.exit(1);
|
|
8284
8979
|
}
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8291
|
-
|
|
8292
|
-
|
|
8293
|
-
|
|
8294
|
-
epoch: 0,
|
|
8295
|
-
periodSeconds: 0,
|
|
8296
|
-
startedAt: new Date().toISOString()
|
|
8297
|
-
});
|
|
8298
|
-
}
|
|
8299
|
-
if (result.e2eServerKey) {
|
|
8300
|
-
const serverKeyPath = join(getAgentApproveDir(), "e2e-server-key");
|
|
8301
|
-
writeFileSync(serverKeyPath, result.e2eServerKey, { mode: 384 });
|
|
8302
|
-
}
|
|
8980
|
+
const pairOutcome = reconcilePairingConfig(pairingConfig, result.effectiveConfig, {
|
|
8981
|
+
reportedPrivacy: result.privacy,
|
|
8982
|
+
localE2eOn: existingConfig?.e2eEnabled !== false && keys.some((k) => k.isCurrent)
|
|
8983
|
+
});
|
|
8984
|
+
if (pairOutcome.encryptionRequired) {
|
|
8985
|
+
pairingSpinner.stop("Paired, but this computer is not set up");
|
|
8986
|
+
v2.error(formatEncryptionRequiredMessage("pair"));
|
|
8987
|
+
he("Pairing is not finished.");
|
|
8988
|
+
process.exit(1);
|
|
8303
8989
|
}
|
|
8990
|
+
pairingSpinner.stop(`Paired! ${result.email ? `Account: ${result.email}` : ""}`);
|
|
8991
|
+
ensureAgentApproveDir();
|
|
8992
|
+
const keyResult = applyPairKeyPlan(keyPlan, getAgentApproveDir(), {
|
|
8993
|
+
serverKey: result.e2eServerKey,
|
|
8994
|
+
rotation: { read: readRotationConfig, write: writeRotationConfig },
|
|
8995
|
+
now: () => new Date().toISOString()
|
|
8996
|
+
});
|
|
8997
|
+
if (keyResult.backedUp)
|
|
8998
|
+
v2.info(`Previous key backed up (${keyResult.backedUp})`);
|
|
8999
|
+
if (keyPlan.kind === "generate")
|
|
9000
|
+
v2.success(`New key saved (${e2eKeyId})`);
|
|
8304
9001
|
const apiUrl = result.apiUrl || pairingApiBase;
|
|
8305
9002
|
const configSetAt = Math.floor(Date.now() / 1000);
|
|
8306
9003
|
const pairPreservation = resolvePreservation({
|
|
@@ -8311,69 +9008,44 @@ async function pairCommand() {
|
|
|
8311
9008
|
saveEnvConfig({
|
|
8312
9009
|
apiUrl,
|
|
8313
9010
|
token: result.token,
|
|
8314
|
-
privacy:
|
|
8315
|
-
retentionDays:
|
|
9011
|
+
privacy: pairOutcome.local.privacyTier,
|
|
9012
|
+
retentionDays: pairOutcome.local.retentionDays,
|
|
8316
9013
|
debugLog: existingConfig?.debugLog,
|
|
8317
9014
|
e2eMode: existingConfig?.e2eMode,
|
|
8318
|
-
e2eEnabled:
|
|
8319
|
-
failBehavior:
|
|
8320
|
-
configSetAt: pairPreservation.letAccountWin ? 0 : configSetAt,
|
|
9015
|
+
e2eEnabled: pairOutcome.local.e2eEnabled,
|
|
9016
|
+
failBehavior: pairOutcome.local.failBehavior,
|
|
9017
|
+
configSetAt: pairPreservation.letAccountWin || pairOutcome.letAccountWin ? 0 : configSetAt,
|
|
8321
9018
|
preserved: pairPreservation.preserved
|
|
8322
9019
|
});
|
|
8323
9020
|
await storeTokenInKeychain(result.token);
|
|
8324
|
-
const
|
|
8325
|
-
if (
|
|
9021
|
+
const pairKeptWarning = formatAccountKeptWarning(pairOutcome);
|
|
9022
|
+
if (pairKeptWarning)
|
|
9023
|
+
v2.warn(pairKeptWarning);
|
|
9024
|
+
const pairUnknownNote = formatAccountUnknownNote(pairOutcome);
|
|
9025
|
+
if (pairUnknownNote)
|
|
9026
|
+
v2.info(pairUnknownNote);
|
|
9027
|
+
const hooksDir = join3(getAgentApproveDir(), "hooks");
|
|
9028
|
+
if (existsSync5(hooksDir)) {
|
|
8326
9029
|
const updateSpinner = _2();
|
|
8327
|
-
updateSpinner.start("
|
|
9030
|
+
updateSpinner.start("Refreshing background activity filters");
|
|
8328
9031
|
try {
|
|
8329
|
-
await
|
|
8330
|
-
updateSpinner.stop("
|
|
9032
|
+
await refreshInstalledHooks(result.token, apiUrl);
|
|
9033
|
+
updateSpinner.stop("Hooks will use the new token on their next run");
|
|
8331
9034
|
} catch {
|
|
8332
|
-
updateSpinner.stop("Warning: Could not
|
|
9035
|
+
updateSpinner.stop("Warning: Could not refresh the installed hooks");
|
|
8333
9036
|
v2.warn('You may need to run "npx agentapprove install" to reconfigure hooks.');
|
|
8334
9037
|
}
|
|
8335
9038
|
}
|
|
8336
9039
|
ge(source_default.green(`Device paired with key ${e2eKeyId}`));
|
|
8337
9040
|
}
|
|
8338
|
-
async function
|
|
8339
|
-
const
|
|
8340
|
-
|
|
8341
|
-
|
|
8342
|
-
}
|
|
8343
|
-
|
|
8344
|
-
if (filters.failed.length || filters.terminalFailure) {
|
|
9041
|
+
async function refreshInstalledHooks(token, apiUrl) {
|
|
9042
|
+
const result = await refreshHooksAfterPairing(join3(getAgentApproveDir(), "hooks"), token, apiUrl, {
|
|
9043
|
+
filterFiles: BACKGROUND_FILTER_FILES,
|
|
9044
|
+
copyHookScripts: copyHookScripts2
|
|
9045
|
+
});
|
|
9046
|
+
if (!result.filtersRefreshed) {
|
|
8345
9047
|
v2.warn("Background activity filters could not be refreshed. The previous copy is retained.");
|
|
8346
9048
|
}
|
|
8347
|
-
const hookFiles = [
|
|
8348
|
-
"claude-pre-tool.sh",
|
|
8349
|
-
"claude-post-tool.sh",
|
|
8350
|
-
"claude-prompt.sh",
|
|
8351
|
-
"claude-session-start.sh",
|
|
8352
|
-
"claude-session-end.sh",
|
|
8353
|
-
"completion-hook.sh",
|
|
8354
|
-
"notify-hook.sh",
|
|
8355
|
-
"cursor-approval.sh",
|
|
8356
|
-
"cursor-mcp-approval.sh",
|
|
8357
|
-
"cursor-shell-complete.sh",
|
|
8358
|
-
"cursor-start.sh",
|
|
8359
|
-
"cursor-stop.sh",
|
|
8360
|
-
"cursor-thought.sh",
|
|
8361
|
-
"cursor-response.sh",
|
|
8362
|
-
"gemini-approval.sh",
|
|
8363
|
-
"gemini-complete.sh",
|
|
8364
|
-
"windsurf-hook.sh",
|
|
8365
|
-
"openhands-hook.sh",
|
|
8366
|
-
"antigravity-hook.sh"
|
|
8367
|
-
];
|
|
8368
|
-
for (const file of hookFiles) {
|
|
8369
|
-
const filePath = join(hooksDir, file);
|
|
8370
|
-
if (existsSync2(filePath)) {
|
|
8371
|
-
let content = readFileSync(filePath, "utf-8");
|
|
8372
|
-
content = content.replace(/export AGENTAPPROVE_TOKEN=".*"/, `export AGENTAPPROVE_TOKEN="${token}"`);
|
|
8373
|
-
content = content.replace(/export AGENTAPPROVE_API=".*"/, `export AGENTAPPROVE_API="${apiUrl}"`);
|
|
8374
|
-
writeFileSync(filePath, content, "utf-8");
|
|
8375
|
-
}
|
|
8376
|
-
}
|
|
8377
9049
|
}
|
|
8378
9050
|
async function main() {
|
|
8379
9051
|
const command = getCommand();
|