agentapprove 0.2.0 → 0.2.2
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 +1073 -556
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1842,6 +1842,368 @@ 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/pair-key-plan.ts
|
|
2148
|
+
import { createHash } from "crypto";
|
|
2149
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, renameSync as renameSync2 } from "fs";
|
|
2150
|
+
import { join as join2 } from "path";
|
|
2151
|
+
var PAIR_KEY_GENERATE = "__generate__";
|
|
2152
|
+
var PAIR_KEY_DISABLE = "__disable__";
|
|
2153
|
+
function e2eKeyId(keyHex) {
|
|
2154
|
+
return createHash("sha256").update(Buffer.from(keyHex, "hex")).digest("hex").slice(0, 8);
|
|
2155
|
+
}
|
|
2156
|
+
function planPairKey(selection, keys, agentApproveDir, generateKeyHex) {
|
|
2157
|
+
if (selection === PAIR_KEY_DISABLE) {
|
|
2158
|
+
return { kind: "disable", e2eUserKey: null };
|
|
2159
|
+
}
|
|
2160
|
+
if (selection === PAIR_KEY_GENERATE) {
|
|
2161
|
+
const keyHex = generateKeyHex();
|
|
2162
|
+
const current = keys.find((key) => key.isCurrent);
|
|
2163
|
+
return {
|
|
2164
|
+
kind: "generate",
|
|
2165
|
+
e2eUserKey: keyHex,
|
|
2166
|
+
e2eKeyId: e2eKeyId(keyHex),
|
|
2167
|
+
...current ? { backup: { from: current.path, to: join2(agentApproveDir, `e2e-key.${current.keyId}.bak`), keyId: current.keyId } } : {}
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
const selected = keys.find((key) => key.keyId === selection);
|
|
2171
|
+
if (!selected)
|
|
2172
|
+
return { kind: "not_found" };
|
|
2173
|
+
return { kind: "existing", e2eUserKey: selected.keyHex, e2eKeyId: selected.keyId };
|
|
2174
|
+
}
|
|
2175
|
+
function applyPairKeyPlan(plan, agentApproveDir, deps) {
|
|
2176
|
+
if (plan.kind === "disable") {
|
|
2177
|
+
return { backedUp: null };
|
|
2178
|
+
}
|
|
2179
|
+
const rootKeyPath = join2(agentApproveDir, "e2e-root-key");
|
|
2180
|
+
const userKeyPath = join2(agentApproveDir, "e2e-key");
|
|
2181
|
+
let backedUp = null;
|
|
2182
|
+
if (plan.kind === "generate") {
|
|
2183
|
+
if (plan.backup && existsSync3(plan.backup.from)) {
|
|
2184
|
+
renameSync2(plan.backup.from, plan.backup.to);
|
|
2185
|
+
backedUp = plan.backup.keyId;
|
|
2186
|
+
}
|
|
2187
|
+
writePrivateFile(rootKeyPath, plan.e2eUserKey);
|
|
2188
|
+
writePrivateFile(userKeyPath, plan.e2eUserKey);
|
|
2189
|
+
deps.rotation.write({ rootKeyId: plan.e2eKeyId, epoch: 0, periodSeconds: 0, startedAt: deps.now() });
|
|
2190
|
+
} else {
|
|
2191
|
+
if (!existsSync3(rootKeyPath) || readFileSync2(rootKeyPath, "utf-8").trim() !== plan.e2eUserKey) {
|
|
2192
|
+
writePrivateFile(rootKeyPath, plan.e2eUserKey);
|
|
2193
|
+
} else {
|
|
2194
|
+
restrictToOwner(rootKeyPath);
|
|
2195
|
+
}
|
|
2196
|
+
restrictToOwner(userKeyPath);
|
|
2197
|
+
if (!deps.rotation.read()) {
|
|
2198
|
+
deps.rotation.write({ rootKeyId: plan.e2eKeyId, epoch: 0, periodSeconds: 0, startedAt: deps.now() });
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
if (deps.serverKey) {
|
|
2202
|
+
writePrivateFile(join2(agentApproveDir, "e2e-server-key"), deps.serverKey);
|
|
2203
|
+
}
|
|
2204
|
+
return { backedUp };
|
|
2205
|
+
}
|
|
2206
|
+
|
|
1845
2207
|
// src/openclaw-install.ts
|
|
1846
2208
|
import { spawnSync } from "node:child_process";
|
|
1847
2209
|
import { isDeepStrictEqual } from "node:util";
|
|
@@ -2491,15 +2853,15 @@ var source_default = chalk;
|
|
|
2491
2853
|
|
|
2492
2854
|
// src/cli.ts
|
|
2493
2855
|
var import_qrcode_terminal = __toESM(require_main(), 1);
|
|
2494
|
-
import { existsSync as
|
|
2856
|
+
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";
|
|
2495
2857
|
import { homedir, hostname, platform, tmpdir } from "os";
|
|
2496
|
-
import { join, dirname as
|
|
2858
|
+
import { join as join3, dirname as dirname4, sep as sep2 } from "path";
|
|
2497
2859
|
import { execSync, spawnSync as spawnSync2 } from "child_process";
|
|
2498
|
-
import { randomBytes, createHash } from "crypto";
|
|
2860
|
+
import { randomBytes as randomBytes2, createHash as createHash3 } from "crypto";
|
|
2499
2861
|
|
|
2500
2862
|
// src/uninstall-utils.ts
|
|
2501
|
-
import { existsSync, readdirSync, realpathSync, rmSync } from "fs";
|
|
2502
|
-
import { basename, dirname, sep } from "path";
|
|
2863
|
+
import { existsSync as existsSync4, readdirSync, realpathSync, rmSync as rmSync2 } from "fs";
|
|
2864
|
+
import { basename as basename2, dirname as dirname3, sep } from "path";
|
|
2503
2865
|
var INSTALLER_COMMAND_DESCRIPTIONS = {
|
|
2504
2866
|
uninstall: "Remove hooks/plugins from agent configs and keep local Agent Approve state",
|
|
2505
2867
|
purge: "Remove hooks/plugins and delete local Agent Approve state"
|
|
@@ -2572,7 +2934,7 @@ function appendPathSegments(basePath, childSegments) {
|
|
|
2572
2934
|
return basePath.endsWith(sep) ? `${basePath}${childSegments.join(sep)}` : `${basePath}${sep}${childSegments.join(sep)}`;
|
|
2573
2935
|
}
|
|
2574
2936
|
function createRemovalTarget(path, kind, recursive = false) {
|
|
2575
|
-
if (!
|
|
2937
|
+
if (!existsSync4(path)) {
|
|
2576
2938
|
return null;
|
|
2577
2939
|
}
|
|
2578
2940
|
let actualPath = path;
|
|
@@ -2586,13 +2948,13 @@ function createRemovalTarget(path, kind, recursive = false) {
|
|
|
2586
2948
|
return { path, actualPath, displayPath, kind, recursive };
|
|
2587
2949
|
}
|
|
2588
2950
|
function removeRemovalTarget(target) {
|
|
2589
|
-
if (!
|
|
2951
|
+
if (!existsSync4(target.path) && !existsSync4(target.actualPath)) {
|
|
2590
2952
|
return false;
|
|
2591
2953
|
}
|
|
2592
2954
|
try {
|
|
2593
|
-
|
|
2955
|
+
rmSync2(target.actualPath, { recursive: target.recursive, force: true });
|
|
2594
2956
|
if (target.path !== target.actualPath) {
|
|
2595
|
-
|
|
2957
|
+
rmSync2(target.path, { recursive: false, force: true });
|
|
2596
2958
|
}
|
|
2597
2959
|
return true;
|
|
2598
2960
|
} catch {
|
|
@@ -2600,7 +2962,7 @@ function removeRemovalTarget(target) {
|
|
|
2600
2962
|
}
|
|
2601
2963
|
}
|
|
2602
2964
|
function getOpenClawPluginTargets(openclawConfigPath) {
|
|
2603
|
-
const configDir =
|
|
2965
|
+
const configDir = dirname3(openclawConfigPath);
|
|
2604
2966
|
const npmPath = safeJoinWithinBase(configDir, "npm", "node_modules", "@agentapprove", "openclaw");
|
|
2605
2967
|
const openclawPath = safeJoinWithinBase(configDir, "extensions", "openclaw");
|
|
2606
2968
|
const legacyPath = safeJoinWithinBase(configDir, "extensions", "agentapprove");
|
|
@@ -2616,7 +2978,7 @@ function getOpenCodePluginTargets(opencodeConfigDir, opencodeCacheDir) {
|
|
|
2616
2978
|
const packageCacheTargets = [];
|
|
2617
2979
|
if (opencodeCacheDir) {
|
|
2618
2980
|
const scopedPackageCacheDir = safeJoinWithinBase(opencodeCacheDir, "packages", "@agentapprove");
|
|
2619
|
-
if (scopedPackageCacheDir &&
|
|
2981
|
+
if (scopedPackageCacheDir && existsSync4(scopedPackageCacheDir)) {
|
|
2620
2982
|
for (const entry of readdirSync(scopedPackageCacheDir)) {
|
|
2621
2983
|
if (!entry.startsWith("opencode@")) {
|
|
2622
2984
|
continue;
|
|
@@ -2645,11 +3007,11 @@ function getAntigravityPluginTargets(geminiDir) {
|
|
|
2645
3007
|
function collectBackupTargets(configPaths) {
|
|
2646
3008
|
const targets = [];
|
|
2647
3009
|
for (const configPath of configPaths) {
|
|
2648
|
-
const configDir =
|
|
2649
|
-
if (!
|
|
3010
|
+
const configDir = dirname3(configPath);
|
|
3011
|
+
if (!existsSync4(configDir)) {
|
|
2650
3012
|
continue;
|
|
2651
3013
|
}
|
|
2652
|
-
const configBase =
|
|
3014
|
+
const configBase = basename2(configPath);
|
|
2653
3015
|
for (const entry of readdirSync(configDir)) {
|
|
2654
3016
|
if (!entry.startsWith(`${configBase}.backup.`)) {
|
|
2655
3017
|
continue;
|
|
@@ -2679,7 +3041,7 @@ function getManagedStateTargets(agentApproveDir) {
|
|
|
2679
3041
|
safeJoinWithinBase(agentApproveDir, "e2e-server-key"),
|
|
2680
3042
|
safeJoinWithinBase(agentApproveDir, "e2e-rotation.json")
|
|
2681
3043
|
].map((path) => path ? createRemovalTarget(path, "crypto_material") : null).filter((target) => target !== null);
|
|
2682
|
-
if (
|
|
3044
|
+
if (existsSync4(agentApproveDir)) {
|
|
2683
3045
|
for (const entry of readdirSync(agentApproveDir)) {
|
|
2684
3046
|
if (!/^e2e-key\.[^.]+\.bak$/.test(entry)) {
|
|
2685
3047
|
continue;
|
|
@@ -3177,8 +3539,8 @@ function classifyHookDownloadFailure(status, body) {
|
|
|
3177
3539
|
|
|
3178
3540
|
// src/copy-hook-scripts.ts
|
|
3179
3541
|
import { writeFileSync as fsWriteFileSync } from "fs";
|
|
3180
|
-
import { renameSync } from "fs";
|
|
3181
|
-
import { randomUUID } from "crypto";
|
|
3542
|
+
import { renameSync as renameSync3 } from "fs";
|
|
3543
|
+
import { createHash as createHash2, randomUUID } from "crypto";
|
|
3182
3544
|
|
|
3183
3545
|
// src/background-filters.ts
|
|
3184
3546
|
var BACKGROUND_FILTER_FILES = ["background-filter.js", "background-filters.json"];
|
|
@@ -3195,6 +3557,7 @@ function validBackgroundFilters(content) {
|
|
|
3195
3557
|
|
|
3196
3558
|
// src/copy-hook-scripts.ts
|
|
3197
3559
|
import { join as pathJoin } from "path";
|
|
3560
|
+
var HOOK_INTEGRITY_FAILURE = "integrity check failed; run the latest installer: npx agentapprove@latest";
|
|
3198
3561
|
function retryDelay(response) {
|
|
3199
3562
|
const value = response.headers.get("Retry-After")?.trim();
|
|
3200
3563
|
if (!value)
|
|
@@ -3240,7 +3603,8 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3240
3603
|
response = await download();
|
|
3241
3604
|
}
|
|
3242
3605
|
if (response.ok) {
|
|
3243
|
-
const
|
|
3606
|
+
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
3607
|
+
const content = new TextDecoder("utf-8").decode(bytes);
|
|
3244
3608
|
if (file === "background-filters.json") {
|
|
3245
3609
|
if (!validBackgroundFilters(content)) {
|
|
3246
3610
|
recordFailure(file, "invalid catalog; previous copy retained");
|
|
@@ -3252,6 +3616,14 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3252
3616
|
}
|
|
3253
3617
|
const isShellScript = content.startsWith("#!/") || content.startsWith("# ");
|
|
3254
3618
|
const isJsBundle = file.endsWith(".js") && (content.startsWith("//") || content.startsWith("import ") || content.startsWith("var ") || content.startsWith("const ") || content.startsWith("export "));
|
|
3619
|
+
if (options.expectedHashes) {
|
|
3620
|
+
const pinned = Object.prototype.hasOwnProperty.call(options.expectedHashes, file) ? options.expectedHashes[file] : undefined;
|
|
3621
|
+
const actual = createHash2("sha256").update(Buffer.from(bytes)).digest("hex");
|
|
3622
|
+
if (!pinned || !pinned.includes(actual)) {
|
|
3623
|
+
recordFailure(file, HOOK_INTEGRITY_FAILURE);
|
|
3624
|
+
continue;
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3255
3627
|
if (isShellScript || isJsBundle) {
|
|
3256
3628
|
staged.push({ file, content, mode: isShellScript ? 493 : 420 });
|
|
3257
3629
|
downloaded++;
|
|
@@ -3305,7 +3677,7 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3305
3677
|
if (failed.length === 0) {
|
|
3306
3678
|
for (const { temporary, filePath, file } of replacements) {
|
|
3307
3679
|
try {
|
|
3308
|
-
|
|
3680
|
+
renameSync3(temporary, filePath);
|
|
3309
3681
|
} catch {
|
|
3310
3682
|
failed.push(`${file} (could not replace hook file)`);
|
|
3311
3683
|
break;
|
|
@@ -3316,6 +3688,202 @@ async function copyHookScripts(hooksDir, token, files, options) {
|
|
|
3316
3688
|
return { downloaded, failed, optionalFailed };
|
|
3317
3689
|
}
|
|
3318
3690
|
|
|
3691
|
+
// src/hook-manifest.generated.ts
|
|
3692
|
+
var HOOK_SCRIPT_SHA256 = {
|
|
3693
|
+
"antigravity-hook.sh": [
|
|
3694
|
+
"1f096235ba308087ad578aabdf2217f3e4f8ba336626ef2b70188f8dd2f24ac9",
|
|
3695
|
+
"1ed82442099b7216b9dd3fd6b1e9f2648b5230b528778a374ba7f1d570603d8a"
|
|
3696
|
+
],
|
|
3697
|
+
"background-filter.js": [
|
|
3698
|
+
"5850ec58a56474891627e54b4e34255a878b7d21037382296c5512ee6d250d54"
|
|
3699
|
+
],
|
|
3700
|
+
"claude-notification.sh": [
|
|
3701
|
+
"f699c4ac0d47ad66ab7c5dca549d8413b344dd20c6317f0ed278aed933306583"
|
|
3702
|
+
],
|
|
3703
|
+
"claude-post-tool-failure.sh": [
|
|
3704
|
+
"a14693c771609d63d42c2a84fcb6c6a09edfd5e7977ef37d193af7379db85907"
|
|
3705
|
+
],
|
|
3706
|
+
"claude-post-tool.sh": [
|
|
3707
|
+
"8a61253504c99ecdf101b4fa8681a09489f128ef4ba6dcfb47450c881011654e"
|
|
3708
|
+
],
|
|
3709
|
+
"claude-pre-tool.sh": [
|
|
3710
|
+
"5a317ed1eb620bf5751fbe50ac266295f9a9436a5b5368ff4d5f3ae1e0202f33",
|
|
3711
|
+
"a4bae2a689b075762a11df659b10ca783c1c780af93277efe37a398243fbc8ed"
|
|
3712
|
+
],
|
|
3713
|
+
"claude-prompt.sh": [
|
|
3714
|
+
"449cffbd8efb1f04f51d67aedb817883cffd20ab99ddff4eb32acfb4d3692080"
|
|
3715
|
+
],
|
|
3716
|
+
"claude-session-end.sh": [
|
|
3717
|
+
"f27ff70502327886d28f234631bbe01cf1b02369f0491b956c8cdb1aaf07c4b6"
|
|
3718
|
+
],
|
|
3719
|
+
"claude-session-start.sh": [
|
|
3720
|
+
"dc2d906e448d277be0f9b5e1cd1b0bddadd9d5d86f6a0012ffa6e63cb38fb906"
|
|
3721
|
+
],
|
|
3722
|
+
"claude-stop.sh": [
|
|
3723
|
+
"158629503c11d44d3864c6a4ea5448e5743b4cacc11f0246ef604ce5a4c27830"
|
|
3724
|
+
],
|
|
3725
|
+
"claude-subagent-start.sh": [
|
|
3726
|
+
"93738cd3c3667feae235fd08a44be6381f7e7d6291c102257ae1913917a58d17"
|
|
3727
|
+
],
|
|
3728
|
+
"claude-subagent-stop.sh": [
|
|
3729
|
+
"3cacc15624672dc10109fc01456540027293c30b3e581d9376311c35cd937dd2"
|
|
3730
|
+
],
|
|
3731
|
+
"claude-user-prompt.sh": [
|
|
3732
|
+
"62dc6f72c856ed70e2bd2812471d9a825c5004948db309eff996ff9c78be9be4"
|
|
3733
|
+
],
|
|
3734
|
+
"codex-post-tool.sh": [
|
|
3735
|
+
"b2d6a3352198a79780ace8303b476b37250d020d066d3be0b32719be34cb1198"
|
|
3736
|
+
],
|
|
3737
|
+
"codex-pre-tool.sh": [
|
|
3738
|
+
"6c44eb3f3774024d26a2d9162b9a91f1ac8c15559a164823f122aa0f423b454f",
|
|
3739
|
+
"3d1c6b7f8717f7b043d54f79af6225bebffb2baa4f0badde759182c415bcc343"
|
|
3740
|
+
],
|
|
3741
|
+
"codex-session-start.sh": [
|
|
3742
|
+
"b14351394abeab95d047d6843e34d52e33758eef1f4f129a31efe6334858db53"
|
|
3743
|
+
],
|
|
3744
|
+
"codex-stop.sh": [
|
|
3745
|
+
"6c46b605b482a474205d850cec28f35ced74796beedf1f2647a1268fcfa7d45e"
|
|
3746
|
+
],
|
|
3747
|
+
"codex-subagent-start.sh": [
|
|
3748
|
+
"053caf81244b7510057c307d7dbc35f2190b0c5665dfdae252ae29e98744de4e"
|
|
3749
|
+
],
|
|
3750
|
+
"codex-subagent-stop.sh": [
|
|
3751
|
+
"0876893314ccf0ebbb8e07dd879c0e751ab24a6b195008d8d1ccf29ee86f581d"
|
|
3752
|
+
],
|
|
3753
|
+
"codex-user-prompt.sh": [
|
|
3754
|
+
"0e8886fa08e6c5529721f6e94907c9bad6c32e97c1f4827e2ef5270f349cce4f"
|
|
3755
|
+
],
|
|
3756
|
+
"common.sh": [
|
|
3757
|
+
"e9878d93113337bd49ccfbc34f57aed38f0f93dad77eebe5b981adfe10ef82f2",
|
|
3758
|
+
"626da6d015a3686cc4ba9b578ec19e378f18156c5fa0b11fdd10250908ba47da"
|
|
3759
|
+
],
|
|
3760
|
+
"completion-hook.sh": [
|
|
3761
|
+
"ec94b799c35cd650b79d50f223bd57e817fed5d7e379aac5948e06f14ad7b31a"
|
|
3762
|
+
],
|
|
3763
|
+
"cursor-approval.sh": [
|
|
3764
|
+
"66321a6409dbc77bbd9c83781b5112c4eb8e9139c62ce6e7952cb886d33ee996",
|
|
3765
|
+
"547e056485093ff9071a5c45326dfaf1320918495c54908f7413d7f6c7a9422f"
|
|
3766
|
+
],
|
|
3767
|
+
"cursor-mcp-approval.sh": [
|
|
3768
|
+
"1d54625606519a8d1f763631aee8d2e9a92aede7b9619a9882174c0bc1059bb9",
|
|
3769
|
+
"e5638dde8b7767ff4e3c0a361dec27fe49fa63048ea06952bb602b98e8abb80d"
|
|
3770
|
+
],
|
|
3771
|
+
"cursor-mcp-complete.sh": [
|
|
3772
|
+
"0c7131db3e9007dc1e614cd5a132f08f4ee60030d48c0ee3fcb48074ae37c37b"
|
|
3773
|
+
],
|
|
3774
|
+
"cursor-post-tool.sh": [
|
|
3775
|
+
"44971e10d711667a659a493f062cadb4d44545c42aec0bbd24ad3821cfb27594"
|
|
3776
|
+
],
|
|
3777
|
+
"cursor-pre-tool.sh": [
|
|
3778
|
+
"41e804015779822adec39cf62efb0a71e055f83e56622612e6f39f0a80422906",
|
|
3779
|
+
"87ed62e2d5976b1c04337b2407f73f86d039751a12a3803ca2f8db1ca3a10446"
|
|
3780
|
+
],
|
|
3781
|
+
"cursor-precompact.sh": [
|
|
3782
|
+
"33faedfd07999296911aa9080a2799938493114ad29878db025d6c42db418f83"
|
|
3783
|
+
],
|
|
3784
|
+
"cursor-response.sh": [
|
|
3785
|
+
"913e2ef96526b092589ac3e744872e8ede47c3a3d280590e356fa406749c5c0c"
|
|
3786
|
+
],
|
|
3787
|
+
"cursor-session-end.sh": [
|
|
3788
|
+
"ce2e29ccab8396b4537ac1217f1152cf4b20f0f8261394742c77ff83572112b0"
|
|
3789
|
+
],
|
|
3790
|
+
"cursor-session-start.sh": [
|
|
3791
|
+
"512047dab51b1ef69338bc8ef6d205d7605f128523bd47a3e296992b720faed5"
|
|
3792
|
+
],
|
|
3793
|
+
"cursor-shell-complete.sh": [
|
|
3794
|
+
"3e1976d565f82b0768f6a76f2aed3636123cf69195854a5b3d574de2035f4879"
|
|
3795
|
+
],
|
|
3796
|
+
"cursor-start.sh": [
|
|
3797
|
+
"23895ab6d2ecaa9fe278b3fb9d53b21418edd7cfac5116d53bd659d4ecbabae3"
|
|
3798
|
+
],
|
|
3799
|
+
"cursor-stop.sh": [
|
|
3800
|
+
"052c9de32572aeb8b5c9d27313cd20a27790a2250ce3c9aeb8e7356a755c5de3"
|
|
3801
|
+
],
|
|
3802
|
+
"cursor-subagent-start.sh": [
|
|
3803
|
+
"b614d1619331b2a900046efdf65eb5d759fb301d2aa7a115f0b107b1b41b3eb9"
|
|
3804
|
+
],
|
|
3805
|
+
"cursor-subagent-stop.sh": [
|
|
3806
|
+
"96d68c3ce020ad8ded49088e5665c3813c89539a0f15e6fda37a50beba08e7ca"
|
|
3807
|
+
],
|
|
3808
|
+
"cursor-thought.sh": [
|
|
3809
|
+
"79b5e73597df5eeec14c3327371f177eabc825edd593aea3c1012e7ae1ea4139"
|
|
3810
|
+
],
|
|
3811
|
+
"gemini-after-agent.sh": [
|
|
3812
|
+
"3c974a52bad64246a40a9cb58f1efa0ec3530be49b1e4a6e980f8469127ce70f"
|
|
3813
|
+
],
|
|
3814
|
+
"gemini-after-model.sh": [
|
|
3815
|
+
"ee5421957f1a9c31bd333df1b012a3ba56ac1e2b2bd7cad9c8fb300bb2c0faf2"
|
|
3816
|
+
],
|
|
3817
|
+
"gemini-after-tool.sh": [
|
|
3818
|
+
"46a3b655e295562301ebf54fce0fb271fbfa61679a8deb3fbab6affc7433d57e"
|
|
3819
|
+
],
|
|
3820
|
+
"gemini-before-agent.sh": [
|
|
3821
|
+
"4e3f6e8b04e1027562e55d13faa4c9521b665ef0299155a6da320a2c96d38f78"
|
|
3822
|
+
],
|
|
3823
|
+
"gemini-before-model.sh": [
|
|
3824
|
+
"b074d767fe5e211a7f6434db1d2b02c6761df73b01f8defa703691cd1d986485"
|
|
3825
|
+
],
|
|
3826
|
+
"gemini-before-tool.sh": [
|
|
3827
|
+
"222623ee4dd6ddd592d8aa0bcf3553d1acda3a2543cf6528bb3cabb50d2cb593",
|
|
3828
|
+
"65c12342fd73cd200c6b6934b3742390e2f2d16524f9d643889c6b1107762ca9"
|
|
3829
|
+
],
|
|
3830
|
+
"gemini-notification.sh": [
|
|
3831
|
+
"5978c5d4b689f2e87131d9950b50588a4aa74390b548a43c3ea6e607fe407e16"
|
|
3832
|
+
],
|
|
3833
|
+
"gemini-session-end.sh": [
|
|
3834
|
+
"326b0db81850cbc63008815c27f8b0b6ab5af0e6d7692a7e9a9bc5b7cca79f9e"
|
|
3835
|
+
],
|
|
3836
|
+
"gemini-session-start.sh": [
|
|
3837
|
+
"5d1113f25accd644c82e21bbc7efc56739f549b6b8227bd8874afc6500112b46"
|
|
3838
|
+
],
|
|
3839
|
+
"gemini-stop.sh": [
|
|
3840
|
+
"da82707cd945b2307efa0a137e54f3dc9a630b2d02a5056d676ad49712f8534f"
|
|
3841
|
+
],
|
|
3842
|
+
"github-error.sh": [
|
|
3843
|
+
"e4dd8874cb837727c795a095ea5829eaa9d350ef65ab4c9fb802334558c44859"
|
|
3844
|
+
],
|
|
3845
|
+
"github-post-tool.sh": [
|
|
3846
|
+
"e057c5f624d7d4998ea59ef524b97b2364f860477a6aadd2512d562cdecfc6c2"
|
|
3847
|
+
],
|
|
3848
|
+
"github-pre-tool.sh": [
|
|
3849
|
+
"a331d5980824db7ca38a586f5f6398627b6653397eb4d5bcd19b18a293479c38",
|
|
3850
|
+
"1066e08beb1ff864a8075cf9cd77ab1b64e5913f30675edd97cbb58e5fa05a7b"
|
|
3851
|
+
],
|
|
3852
|
+
"github-precompact.sh": [
|
|
3853
|
+
"f34011aa926611fe8691ef24250ab22561ff6c0387d3e3527e52d44c7aac6f44"
|
|
3854
|
+
],
|
|
3855
|
+
"github-session-end.sh": [
|
|
3856
|
+
"370fa14d68739b398233d60982cefd6dc946e3be6f4c3560b0a6e8652928f2d9"
|
|
3857
|
+
],
|
|
3858
|
+
"github-session-start.sh": [
|
|
3859
|
+
"505f44ed4ca6345b8e9ff8a328198ed6141d4774a630821b984ab5cf4c3954ff"
|
|
3860
|
+
],
|
|
3861
|
+
"github-stop.sh": [
|
|
3862
|
+
"07f2d802700cf7ace009207aaa3f9c96e4e5943c022faa9601d9b85277e50fa4"
|
|
3863
|
+
],
|
|
3864
|
+
"github-subagent-start.sh": [
|
|
3865
|
+
"506e39c02806ca20e8a3605a0de3eb089d9ef98d3556ceb675a70433ea313889"
|
|
3866
|
+
],
|
|
3867
|
+
"github-subagent-stop.sh": [
|
|
3868
|
+
"27cab61bdad7c7efddb8be43bcc8cedb03d0789d1288db933386c185b02c0027"
|
|
3869
|
+
],
|
|
3870
|
+
"github-user-prompt.sh": [
|
|
3871
|
+
"67ac8e7c33991402cc2dfcaf6b3380ba50b92cf224fcb447c2bb39cbd7c7a1a8"
|
|
3872
|
+
],
|
|
3873
|
+
"notify-hook.sh": [
|
|
3874
|
+
"a222c9f656da5c9b0c6cb9998ddb6dd07608cabacef2931d542d68b04075632b",
|
|
3875
|
+
"0892b3f3b71b8f7df08917ad4f38baac1655093a38f5d43238aca49b9f0554a1"
|
|
3876
|
+
],
|
|
3877
|
+
"openhands-hook.sh": [
|
|
3878
|
+
"28cacd77360c53fdb7b095403dfc43c7b7cf83ff718ac85f7f1a9042652bd8c0",
|
|
3879
|
+
"ebdb17e34918e6e58e9ab70e2db9521f25b1907f9cd96d78d217074db64fc566"
|
|
3880
|
+
],
|
|
3881
|
+
"windsurf-hook.sh": [
|
|
3882
|
+
"b7e85df3b6188cd1dfd6b2eb904185e41b627e077a265eaa6bb88a804323b47d",
|
|
3883
|
+
"16a73925f6a2b2fb3a9e29166316519bb5f5afd05bbed0df80513b004434ebd8"
|
|
3884
|
+
]
|
|
3885
|
+
};
|
|
3886
|
+
|
|
3319
3887
|
// src/host-command.ts
|
|
3320
3888
|
import { execFileSync } from "node:child_process";
|
|
3321
3889
|
var HOST_COMMAND_TIMEOUT_MS = 30000;
|
|
@@ -3353,6 +3921,32 @@ function enableHermesFollowUp(profile, run = (file, args) => runHostCommand(file
|
|
|
3353
3921
|
]);
|
|
3354
3922
|
}
|
|
3355
3923
|
|
|
3924
|
+
// src/hermes-hook-timeout.ts
|
|
3925
|
+
var HERMES_HOST_HOOK_TIMEOUT_SECONDS = 600;
|
|
3926
|
+
var TIMEOUT_KEY = "plugins.hook_callback_timeout";
|
|
3927
|
+
function ensureHermesHookTimeout(profile, run = runHostCommand) {
|
|
3928
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(profile)) {
|
|
3929
|
+
throw new Error("Invalid Hermes profile name");
|
|
3930
|
+
}
|
|
3931
|
+
const prefix = profile === "default" ? [] : ["-p", profile];
|
|
3932
|
+
let current;
|
|
3933
|
+
try {
|
|
3934
|
+
current = JSON.parse(run("hermes", [...prefix, "config", "get", TIMEOUT_KEY, "--json"]));
|
|
3935
|
+
} catch (error) {
|
|
3936
|
+
const failure = error;
|
|
3937
|
+
const stderr = typeof failure?.stderr === "string" ? failure.stderr : Buffer.isBuffer(failure?.stderr) ? failure.stderr.toString("utf8") : "";
|
|
3938
|
+
if (failure?.status === 1 && stderr.split(/\r?\n/).some((line) => line.trim() === `Config key not set: ${TIMEOUT_KEY}`))
|
|
3939
|
+
return;
|
|
3940
|
+
if (failure?.status === 2 && stderr.includes("argument config_command: invalid choice: 'get'"))
|
|
3941
|
+
return;
|
|
3942
|
+
throw new Error(`Could not read Hermes hook timeout for profile ${profile}. Check hermes ${profile === "default" ? "" : `-p ${profile} `}config get ${TIMEOUT_KEY} --json before retrying setup.`);
|
|
3943
|
+
}
|
|
3944
|
+
const value = typeof current === "number" ? current : typeof current === "string" && current.trim() !== "" ? Number(current) : NaN;
|
|
3945
|
+
if (Number.isFinite(value) && (value === 0 || value >= HERMES_HOST_HOOK_TIMEOUT_SECONDS))
|
|
3946
|
+
return;
|
|
3947
|
+
run("hermes", [...prefix, "config", "set", TIMEOUT_KEY, String(HERMES_HOST_HOOK_TIMEOUT_SECONDS)]);
|
|
3948
|
+
}
|
|
3949
|
+
|
|
3356
3950
|
// src/pairing-api-url.ts
|
|
3357
3951
|
function looksLikeHostedAgentApproveApi(baseUrl) {
|
|
3358
3952
|
try {
|
|
@@ -3434,63 +4028,30 @@ Configured on this computer: ${ready.join(", ")}. Nothing was changed.`);
|
|
|
3434
4028
|
}
|
|
3435
4029
|
|
|
3436
4030
|
// src/cli.ts
|
|
3437
|
-
var VERSION = "0.2.
|
|
4031
|
+
var VERSION = "0.2.2";
|
|
3438
4032
|
function getApiUrl() {
|
|
3439
4033
|
return process.env.AGENTAPPROVE_API || "https://api.agentapprove.com";
|
|
3440
4034
|
}
|
|
3441
4035
|
function getXdgConfigHome() {
|
|
3442
|
-
return process.env.XDG_CONFIG_HOME ||
|
|
4036
|
+
return process.env.XDG_CONFIG_HOME || join3(homedir(), ".config");
|
|
3443
4037
|
}
|
|
3444
4038
|
function getOpenCodeConfigDir() {
|
|
3445
|
-
return
|
|
4039
|
+
return join3(getXdgConfigHome(), "opencode");
|
|
3446
4040
|
}
|
|
3447
4041
|
function getOpenCodeConfigPath() {
|
|
3448
|
-
return
|
|
4042
|
+
return join3(getOpenCodeConfigDir(), "opencode.json");
|
|
3449
4043
|
}
|
|
3450
4044
|
function getXdgCacheHome() {
|
|
3451
|
-
return process.env.XDG_CACHE_HOME ||
|
|
4045
|
+
return process.env.XDG_CACHE_HOME || join3(homedir(), ".cache");
|
|
3452
4046
|
}
|
|
3453
4047
|
function getOpenCodeCacheDir() {
|
|
3454
|
-
return
|
|
4048
|
+
return join3(getXdgCacheHome(), "opencode");
|
|
3455
4049
|
}
|
|
3456
4050
|
var API_URL = getApiUrl();
|
|
3457
4051
|
var API_VERSION = process.env.AGENTAPPROVE_API_VERSION || "v001";
|
|
3458
4052
|
function hasFlag2(flag) {
|
|
3459
4053
|
return process.argv.slice(2).includes(flag);
|
|
3460
4054
|
}
|
|
3461
|
-
function updateEnvValue(key, value) {
|
|
3462
|
-
const envPath = join(getAgentApproveDir(), "env");
|
|
3463
|
-
let content;
|
|
3464
|
-
try {
|
|
3465
|
-
content = readFileSync(envPath, "utf-8");
|
|
3466
|
-
} catch (err) {
|
|
3467
|
-
if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
3468
|
-
return;
|
|
3469
|
-
}
|
|
3470
|
-
throw err;
|
|
3471
|
-
}
|
|
3472
|
-
const lines = content.endsWith(`
|
|
3473
|
-
`) ? content.slice(0, -1).split(`
|
|
3474
|
-
`) : content.split(`
|
|
3475
|
-
`);
|
|
3476
|
-
let seenKey = false;
|
|
3477
|
-
const updatedLines = lines.flatMap((line) => {
|
|
3478
|
-
const trimmed = line.replace(/^export\s+/, "").trim();
|
|
3479
|
-
const eqIdx = trimmed.indexOf("=");
|
|
3480
|
-
if (eqIdx <= 0 || trimmed.slice(0, eqIdx) !== key)
|
|
3481
|
-
return [line];
|
|
3482
|
-
if (seenKey)
|
|
3483
|
-
return [];
|
|
3484
|
-
seenKey = true;
|
|
3485
|
-
return [`${key}=${value}`];
|
|
3486
|
-
});
|
|
3487
|
-
if (!seenKey) {
|
|
3488
|
-
updatedLines.push(`${key}=${value}`);
|
|
3489
|
-
}
|
|
3490
|
-
writeFileSync(envPath, `${updatedLines.join(`
|
|
3491
|
-
`)}
|
|
3492
|
-
`, { mode: 384 });
|
|
3493
|
-
}
|
|
3494
4055
|
function getCommand() {
|
|
3495
4056
|
const args = process.argv.slice(2);
|
|
3496
4057
|
const filtered = [];
|
|
@@ -3506,19 +4067,19 @@ function getCommand() {
|
|
|
3506
4067
|
}
|
|
3507
4068
|
return filtered[0] || "install";
|
|
3508
4069
|
}
|
|
3509
|
-
var OPENCODE_PLUGIN_VERSION = "0.1.
|
|
4070
|
+
var OPENCODE_PLUGIN_VERSION = "0.1.28";
|
|
3510
4071
|
var OPENCODE_PLUGIN_SPEC = `@agentapprove/opencode@${OPENCODE_PLUGIN_VERSION}`;
|
|
3511
|
-
var OPENCLAW_PLUGIN_VERSION = "0.2.
|
|
4072
|
+
var OPENCLAW_PLUGIN_VERSION = "0.2.23";
|
|
3512
4073
|
var OPENCLAW_PLUGIN_SPEC = `@agentapprove/openclaw@${OPENCLAW_PLUGIN_VERSION}`;
|
|
3513
|
-
var PI_PLUGIN_VERSION = "0.1.
|
|
4074
|
+
var PI_PLUGIN_VERSION = "0.1.16";
|
|
3514
4075
|
var PI_PLUGIN_SPEC = `npm:@agentapprove/pi@${PI_PLUGIN_VERSION}`;
|
|
3515
4076
|
var PI_STATUS_TIMEOUT_MS = 5000;
|
|
3516
|
-
var HERMES_PLUGIN_VERSION = "0.1.
|
|
4077
|
+
var HERMES_PLUGIN_VERSION = "0.1.18";
|
|
3517
4078
|
var HERMES_PIP_DEPS = ["cryptography>=44.0,<46", "httpx>=0.27,<0.29"];
|
|
3518
4079
|
var AGENTS = {
|
|
3519
4080
|
"claude-code": {
|
|
3520
4081
|
name: "Claude Code",
|
|
3521
|
-
configPath:
|
|
4082
|
+
configPath: join3(homedir(), ".claude", "settings.json"),
|
|
3522
4083
|
hooksKey: "hooks",
|
|
3523
4084
|
hooks: [
|
|
3524
4085
|
{ name: "PreToolUse", file: "claude-pre-tool.sh", description: "Before tool execution (approval)", hasMatcher: true, isApprovalHook: true, timeout: 300 },
|
|
@@ -3535,7 +4096,7 @@ var AGENTS = {
|
|
|
3535
4096
|
},
|
|
3536
4097
|
cursor: {
|
|
3537
4098
|
name: "Cursor",
|
|
3538
|
-
configPath:
|
|
4099
|
+
configPath: join3(homedir(), ".cursor", "hooks.json"),
|
|
3539
4100
|
hooksKey: "hooks",
|
|
3540
4101
|
hooks: [
|
|
3541
4102
|
{ name: "sessionStart", file: "cursor-session-start.sh", description: "Session started" },
|
|
@@ -3557,7 +4118,7 @@ var AGENTS = {
|
|
|
3557
4118
|
},
|
|
3558
4119
|
windsurf: {
|
|
3559
4120
|
name: "Windsurf",
|
|
3560
|
-
configPath:
|
|
4121
|
+
configPath: join3(homedir(), ".codeium", "windsurf", "hooks.json"),
|
|
3561
4122
|
hooksKey: "hooks",
|
|
3562
4123
|
hooks: [
|
|
3563
4124
|
{ name: "pre_user_prompt", file: "windsurf-hook.sh", description: "User prompt (logging only)" },
|
|
@@ -3574,7 +4135,7 @@ var AGENTS = {
|
|
|
3574
4135
|
},
|
|
3575
4136
|
antigravity: {
|
|
3576
4137
|
name: "Antigravity",
|
|
3577
|
-
configPath:
|
|
4138
|
+
configPath: join3(homedir(), ".gemini", "config", "plugins", "agentapprove", "hooks.json"),
|
|
3578
4139
|
hooksKey: "antigravityPlugin",
|
|
3579
4140
|
hooks: [
|
|
3580
4141
|
{ name: "PreToolUse", file: "antigravity-hook.sh", description: "Tool approval", isApprovalHook: true, timeout: 300 },
|
|
@@ -3586,7 +4147,7 @@ var AGENTS = {
|
|
|
3586
4147
|
},
|
|
3587
4148
|
"gemini-cli": {
|
|
3588
4149
|
name: "Gemini CLI (legacy)",
|
|
3589
|
-
configPath:
|
|
4150
|
+
configPath: join3(homedir(), ".gemini", "settings.json"),
|
|
3590
4151
|
hooksKey: "hooks",
|
|
3591
4152
|
hooks: [
|
|
3592
4153
|
{ name: "SessionStart", file: "gemini-session-start.sh", description: "Session started" },
|
|
@@ -3602,7 +4163,7 @@ var AGENTS = {
|
|
|
3602
4163
|
},
|
|
3603
4164
|
"antigravity-cli": {
|
|
3604
4165
|
name: "Antigravity CLI",
|
|
3605
|
-
configPath:
|
|
4166
|
+
configPath: join3(homedir(), ".gemini", "antigravity-cli", "plugins", "agentapprove", "hooks.json"),
|
|
3606
4167
|
hooksKey: "antigravityPlugin",
|
|
3607
4168
|
hooks: [
|
|
3608
4169
|
{ name: "PreToolUse", file: "antigravity-hook.sh", description: "Tool approval", isApprovalHook: true, timeout: 300 },
|
|
@@ -3614,7 +4175,7 @@ var AGENTS = {
|
|
|
3614
4175
|
},
|
|
3615
4176
|
"vscode-agent": {
|
|
3616
4177
|
name: "VS Code GitHub Copilot",
|
|
3617
|
-
configPath:
|
|
4178
|
+
configPath: join3(homedir(), ".agentapprove", "hooks", "vscode-hooks.json"),
|
|
3618
4179
|
hooksKey: "hooks",
|
|
3619
4180
|
hooks: [
|
|
3620
4181
|
{ name: "SessionStart", file: "github-session-start.sh", description: "Session started" },
|
|
@@ -3629,7 +4190,7 @@ var AGENTS = {
|
|
|
3629
4190
|
},
|
|
3630
4191
|
"copilot-cli": {
|
|
3631
4192
|
name: "GitHub Copilot CLI",
|
|
3632
|
-
configPath:
|
|
4193
|
+
configPath: join3(homedir(), ".agentapprove", "copilot-cli-hooks.json"),
|
|
3633
4194
|
hooksKey: "hooks",
|
|
3634
4195
|
hooks: [
|
|
3635
4196
|
{ name: "sessionStart", file: "github-session-start.sh", description: "Session started" },
|
|
@@ -3642,7 +4203,7 @@ var AGENTS = {
|
|
|
3642
4203
|
},
|
|
3643
4204
|
openclaw: {
|
|
3644
4205
|
name: "OpenClaw",
|
|
3645
|
-
configPath:
|
|
4206
|
+
configPath: join3(homedir(), ".openclaw", "openclaw.json"),
|
|
3646
4207
|
hooksKey: "plugins",
|
|
3647
4208
|
hooks: [
|
|
3648
4209
|
{ name: "agentapprove", file: "@agentapprove/openclaw", description: "Tool approval + event monitoring", isApprovalHook: true, isPlugin: true }
|
|
@@ -3650,7 +4211,7 @@ var AGENTS = {
|
|
|
3650
4211
|
},
|
|
3651
4212
|
codex: {
|
|
3652
4213
|
name: "OpenAI Codex",
|
|
3653
|
-
configPath:
|
|
4214
|
+
configPath: join3(homedir(), ".codex", "hooks.json"),
|
|
3654
4215
|
hooksKey: "hooks",
|
|
3655
4216
|
hooks: [
|
|
3656
4217
|
{ name: "SubagentStart", file: "codex-subagent-start.sh", description: "Subagent started", hasMatcher: true },
|
|
@@ -3672,7 +4233,7 @@ var AGENTS = {
|
|
|
3672
4233
|
},
|
|
3673
4234
|
pi: {
|
|
3674
4235
|
name: "Pi",
|
|
3675
|
-
configPath:
|
|
4236
|
+
configPath: join3(homedir(), ".pi", "agent", "settings.json"),
|
|
3676
4237
|
hooksKey: "packages",
|
|
3677
4238
|
hooks: [
|
|
3678
4239
|
{ name: "agentapprove", file: "@agentapprove/pi", description: "Tool approval + event monitoring", isApprovalHook: true, isPlugin: true }
|
|
@@ -3680,7 +4241,7 @@ var AGENTS = {
|
|
|
3680
4241
|
},
|
|
3681
4242
|
hermes: {
|
|
3682
4243
|
name: "Hermes",
|
|
3683
|
-
configPath:
|
|
4244
|
+
configPath: join3(homedir(), ".hermes", "config.yaml"),
|
|
3684
4245
|
hooksKey: "plugins",
|
|
3685
4246
|
hooks: [
|
|
3686
4247
|
{ name: "agentapprove", file: "agentapprove", description: "Tool approval + event monitoring + follow-up input", isApprovalHook: true, isPlugin: true }
|
|
@@ -3688,7 +4249,7 @@ var AGENTS = {
|
|
|
3688
4249
|
},
|
|
3689
4250
|
openhands: {
|
|
3690
4251
|
name: "OpenHands",
|
|
3691
|
-
configPath:
|
|
4252
|
+
configPath: join3(homedir(), ".openhands", "hooks.json"),
|
|
3692
4253
|
hooksKey: "",
|
|
3693
4254
|
hooks: [
|
|
3694
4255
|
{ name: "session_start", file: "openhands-hook.sh", description: "Session started" },
|
|
@@ -3806,11 +4367,11 @@ function findGitBash() {
|
|
|
3806
4367
|
process.env.CLAUDE_CODE_GIT_BASH_PATH,
|
|
3807
4368
|
"C:\\Program Files\\Git\\bin\\bash.exe",
|
|
3808
4369
|
"C:\\Program Files (x86)\\Git\\bin\\bash.exe",
|
|
3809
|
-
|
|
3810
|
-
|
|
4370
|
+
join3(process.env.LOCALAPPDATA || "", "Programs", "Git", "bin", "bash.exe"),
|
|
4371
|
+
join3(process.env.ProgramW6432 || "", "Git", "bin", "bash.exe")
|
|
3811
4372
|
].filter(Boolean);
|
|
3812
4373
|
for (const candidate of candidates) {
|
|
3813
|
-
if (
|
|
4374
|
+
if (existsSync5(candidate)) {
|
|
3814
4375
|
return candidate;
|
|
3815
4376
|
}
|
|
3816
4377
|
}
|
|
@@ -3818,7 +4379,7 @@ function findGitBash() {
|
|
|
3818
4379
|
const result = execSync("where bash", { encoding: "utf-8", stdio: ["pipe", "pipe", "ignore"] });
|
|
3819
4380
|
const firstLine = result.trim().split(`
|
|
3820
4381
|
`)[0];
|
|
3821
|
-
if (firstLine &&
|
|
4382
|
+
if (firstLine && existsSync5(firstLine)) {
|
|
3822
4383
|
return firstLine;
|
|
3823
4384
|
}
|
|
3824
4385
|
} catch {}
|
|
@@ -3847,9 +4408,9 @@ function buildAntigravityHookCommand(hookScriptPath, agentId, hookName, mode) {
|
|
|
3847
4408
|
}
|
|
3848
4409
|
function getAntigravityPluginRoot(agentId) {
|
|
3849
4410
|
if (agentId === "antigravity-cli") {
|
|
3850
|
-
return
|
|
4411
|
+
return join3(homedir(), ".gemini", "antigravity-cli", "plugins", "agentapprove");
|
|
3851
4412
|
}
|
|
3852
|
-
return
|
|
4413
|
+
return join3(homedir(), ".gemini", "config", "plugins", "agentapprove");
|
|
3853
4414
|
}
|
|
3854
4415
|
function getAntigravityPluginManifest() {
|
|
3855
4416
|
return {
|
|
@@ -3863,7 +4424,7 @@ function buildAntigravityHooksJson(agentId, hooksDir, mode) {
|
|
|
3863
4424
|
const hooksToInstall = mode === "observe" ? agent.hooks.filter((h) => h.name !== "Stop") : agent.hooks;
|
|
3864
4425
|
const bundle = { enabled: true };
|
|
3865
4426
|
for (const hook of hooksToInstall) {
|
|
3866
|
-
const hookPath =
|
|
4427
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
3867
4428
|
const hookCommand = buildAntigravityHookCommand(hookPath, agentId, hook.name, mode);
|
|
3868
4429
|
const hookTimeout = hook.timeout ?? 30;
|
|
3869
4430
|
const commandHook = {
|
|
@@ -3887,11 +4448,11 @@ function buildAntigravityHooksJson(agentId, hooksDir, mode) {
|
|
|
3887
4448
|
function installAntigravityPluginBundle(agentId, hooksDir, mode) {
|
|
3888
4449
|
const agent = AGENTS[agentId];
|
|
3889
4450
|
const pluginRoot = getAntigravityPluginRoot(agentId);
|
|
3890
|
-
const hooksPath =
|
|
3891
|
-
const manifestPath =
|
|
4451
|
+
const hooksPath = join3(pluginRoot, "hooks.json");
|
|
4452
|
+
const manifestPath = join3(pluginRoot, "plugin.json");
|
|
3892
4453
|
const backupPath = backupConfig(hooksPath);
|
|
3893
4454
|
try {
|
|
3894
|
-
|
|
4455
|
+
mkdirSync3(pluginRoot, { recursive: true });
|
|
3895
4456
|
writeJsonConfig(manifestPath, getAntigravityPluginManifest());
|
|
3896
4457
|
writeJsonConfig(hooksPath, buildAntigravityHooksJson(agentId, hooksDir, mode));
|
|
3897
4458
|
} catch (err) {
|
|
@@ -3908,77 +4469,20 @@ function installAntigravityPluginBundle(agentId, hooksDir, mode) {
|
|
|
3908
4469
|
function getVSCodeSettingsPaths() {
|
|
3909
4470
|
const paths = [];
|
|
3910
4471
|
if (process.platform === "darwin") {
|
|
3911
|
-
paths.push({ path:
|
|
3912
|
-
paths.push({ path:
|
|
4472
|
+
paths.push({ path: join3(homedir(), "Library", "Application Support", "Code", "User", "settings.json"), variant: "VS Code" });
|
|
4473
|
+
paths.push({ path: join3(homedir(), "Library", "Application Support", "Code - Insiders", "User", "settings.json"), variant: "VS Code Insiders" });
|
|
3913
4474
|
} else if (process.platform === "win32") {
|
|
3914
|
-
const appdata = process.env.APPDATA ||
|
|
3915
|
-
paths.push({ path:
|
|
3916
|
-
paths.push({ path:
|
|
4475
|
+
const appdata = process.env.APPDATA || join3(homedir(), "AppData", "Roaming");
|
|
4476
|
+
paths.push({ path: join3(appdata, "Code", "User", "settings.json"), variant: "VS Code" });
|
|
4477
|
+
paths.push({ path: join3(appdata, "Code - Insiders", "User", "settings.json"), variant: "VS Code Insiders" });
|
|
3917
4478
|
} else {
|
|
3918
|
-
paths.push({ path:
|
|
3919
|
-
paths.push({ path:
|
|
4479
|
+
paths.push({ path: join3(homedir(), ".config", "Code", "User", "settings.json"), variant: "VS Code" });
|
|
4480
|
+
paths.push({ path: join3(homedir(), ".config", "Code - Insiders", "User", "settings.json"), variant: "VS Code Insiders" });
|
|
3920
4481
|
}
|
|
3921
4482
|
return paths;
|
|
3922
4483
|
}
|
|
3923
4484
|
function findInstalledVSCodeVariants() {
|
|
3924
|
-
return getVSCodeSettingsPaths().filter(({ path }) =>
|
|
3925
|
-
}
|
|
3926
|
-
function stripJsonComments(content) {
|
|
3927
|
-
let result = "";
|
|
3928
|
-
let inString = false;
|
|
3929
|
-
let escaped = false;
|
|
3930
|
-
let i = 0;
|
|
3931
|
-
while (i < content.length) {
|
|
3932
|
-
const ch = content[i];
|
|
3933
|
-
if (escaped) {
|
|
3934
|
-
result += ch;
|
|
3935
|
-
escaped = false;
|
|
3936
|
-
i++;
|
|
3937
|
-
continue;
|
|
3938
|
-
}
|
|
3939
|
-
if (ch === "\\" && inString) {
|
|
3940
|
-
result += ch;
|
|
3941
|
-
escaped = true;
|
|
3942
|
-
i++;
|
|
3943
|
-
continue;
|
|
3944
|
-
}
|
|
3945
|
-
if (ch === '"') {
|
|
3946
|
-
inString = !inString;
|
|
3947
|
-
result += ch;
|
|
3948
|
-
i++;
|
|
3949
|
-
continue;
|
|
3950
|
-
}
|
|
3951
|
-
if (!inString) {
|
|
3952
|
-
if (ch === "/" && content[i + 1] === "/") {
|
|
3953
|
-
while (i < content.length && content[i] !== `
|
|
3954
|
-
`)
|
|
3955
|
-
i++;
|
|
3956
|
-
continue;
|
|
3957
|
-
}
|
|
3958
|
-
if (ch === "/" && content[i + 1] === "*") {
|
|
3959
|
-
i += 2;
|
|
3960
|
-
while (i < content.length && !(content[i] === "*" && content[i + 1] === "/"))
|
|
3961
|
-
i++;
|
|
3962
|
-
i += 2;
|
|
3963
|
-
continue;
|
|
3964
|
-
}
|
|
3965
|
-
}
|
|
3966
|
-
result += ch;
|
|
3967
|
-
i++;
|
|
3968
|
-
}
|
|
3969
|
-
result = result.replace(/,(\s*[}\]])/g, "$1");
|
|
3970
|
-
return result;
|
|
3971
|
-
}
|
|
3972
|
-
function readJsoncConfig(configPath) {
|
|
3973
|
-
if (!existsSync2(configPath))
|
|
3974
|
-
return {};
|
|
3975
|
-
try {
|
|
3976
|
-
const content = readFileSync(configPath, "utf-8");
|
|
3977
|
-
const stripped = stripJsonComments(content);
|
|
3978
|
-
return JSON.parse(stripped);
|
|
3979
|
-
} catch {
|
|
3980
|
-
return {};
|
|
3981
|
-
}
|
|
4485
|
+
return getVSCodeSettingsPaths().filter(({ path }) => existsSync5(dirname4(path)));
|
|
3982
4486
|
}
|
|
3983
4487
|
function getGithubHookEnv(agentId) {
|
|
3984
4488
|
if (agentId === "vscode-agent") {
|
|
@@ -3989,9 +4493,20 @@ function getGithubHookEnv(agentId) {
|
|
|
3989
4493
|
}
|
|
3990
4494
|
return;
|
|
3991
4495
|
}
|
|
4496
|
+
var JSONC_CONFIG_AGENTS = new Set(["gemini-cli"]);
|
|
4497
|
+
function readAgentConfig(agentId, configPath) {
|
|
4498
|
+
return JSONC_CONFIG_AGENTS.has(agentId) ? readJsoncConfig(configPath) : readJsonConfig(configPath);
|
|
4499
|
+
}
|
|
4500
|
+
function keepCommentedConfig(agentId, configPath, existingBackup = null) {
|
|
4501
|
+
if (!JSONC_CONFIG_AGENTS.has(agentId) || !configUsesJsoncSyntax(configPath))
|
|
4502
|
+
return null;
|
|
4503
|
+
const backupPath = existingBackup ?? backupConfig(configPath);
|
|
4504
|
+
return `Comments in ${configPath} are not preserved. The original, with its comments, is in ${backupPath}`;
|
|
4505
|
+
}
|
|
3992
4506
|
function addToVSCodeHookLocations() {
|
|
3993
4507
|
const hookLocation = "~/.agentapprove/hooks";
|
|
3994
4508
|
const modified = [];
|
|
4509
|
+
const failed = [];
|
|
3995
4510
|
for (const { path: settingsPath, variant } of findInstalledVSCodeVariants()) {
|
|
3996
4511
|
try {
|
|
3997
4512
|
const config = readJsoncConfig(settingsPath);
|
|
@@ -4001,17 +4516,20 @@ function addToVSCodeHookLocations() {
|
|
|
4001
4516
|
}
|
|
4002
4517
|
locations[hookLocation] = true;
|
|
4003
4518
|
config["chat.hookFilesLocations"] = locations;
|
|
4519
|
+
backupConfig(settingsPath);
|
|
4004
4520
|
writeJsonConfig(settingsPath, config);
|
|
4005
4521
|
modified.push(`${variant}: ${settingsPath}`);
|
|
4006
|
-
} catch {
|
|
4522
|
+
} catch (error) {
|
|
4523
|
+
failed.push({ variant, path: settingsPath, error: configErrorMessage(error) });
|
|
4524
|
+
}
|
|
4007
4525
|
}
|
|
4008
|
-
return modified;
|
|
4526
|
+
return { modified, failed };
|
|
4009
4527
|
}
|
|
4010
|
-
function removeFromVSCodeHookLocations() {
|
|
4528
|
+
function removeFromVSCodeHookLocations(onFailure) {
|
|
4011
4529
|
const hookLocation = "~/.agentapprove/hooks";
|
|
4012
4530
|
const modified = [];
|
|
4013
4531
|
for (const { path: settingsPath, variant } of getVSCodeSettingsPaths()) {
|
|
4014
|
-
if (!
|
|
4532
|
+
if (!existsSync5(settingsPath))
|
|
4015
4533
|
continue;
|
|
4016
4534
|
try {
|
|
4017
4535
|
const config = readJsoncConfig(settingsPath);
|
|
@@ -4024,9 +4542,12 @@ function removeFromVSCodeHookLocations() {
|
|
|
4024
4542
|
} else {
|
|
4025
4543
|
config["chat.hookFilesLocations"] = locations;
|
|
4026
4544
|
}
|
|
4545
|
+
backupConfig(settingsPath);
|
|
4027
4546
|
writeJsonConfig(settingsPath, config);
|
|
4028
4547
|
modified.push(`${variant}: ${settingsPath}`);
|
|
4029
|
-
} catch {
|
|
4548
|
+
} catch (error) {
|
|
4549
|
+
onFailure?.({ variant, path: settingsPath, error: configErrorMessage(error) });
|
|
4550
|
+
}
|
|
4030
4551
|
}
|
|
4031
4552
|
return modified;
|
|
4032
4553
|
}
|
|
@@ -4038,23 +4559,23 @@ function detectInstalledAgents() {
|
|
|
4038
4559
|
installed.push(id);
|
|
4039
4560
|
}
|
|
4040
4561
|
} else if (id === "copilot-cli") {
|
|
4041
|
-
if (
|
|
4562
|
+
if (existsSync5(join3(homedir(), ".copilot"))) {
|
|
4042
4563
|
installed.push(id);
|
|
4043
4564
|
}
|
|
4044
4565
|
} else if (id === "openclaw") {
|
|
4045
|
-
if (
|
|
4566
|
+
if (existsSync5(join3(homedir(), ".openclaw"))) {
|
|
4046
4567
|
installed.push(id);
|
|
4047
4568
|
}
|
|
4048
4569
|
} else if (id === "codex") {
|
|
4049
|
-
if (
|
|
4570
|
+
if (existsSync5(join3(homedir(), ".codex"))) {
|
|
4050
4571
|
installed.push(id);
|
|
4051
4572
|
}
|
|
4052
4573
|
} else if (id === "opencode") {
|
|
4053
|
-
if (
|
|
4574
|
+
if (existsSync5(getOpenCodeConfigDir())) {
|
|
4054
4575
|
installed.push(id);
|
|
4055
4576
|
}
|
|
4056
4577
|
} else if (id === "pi") {
|
|
4057
|
-
if (
|
|
4578
|
+
if (existsSync5(join3(homedir(), ".pi", "agent"))) {
|
|
4058
4579
|
installed.push(id);
|
|
4059
4580
|
} else {
|
|
4060
4581
|
try {
|
|
@@ -4063,7 +4584,7 @@ function detectInstalledAgents() {
|
|
|
4063
4584
|
} catch {}
|
|
4064
4585
|
}
|
|
4065
4586
|
} else if (id === "hermes") {
|
|
4066
|
-
if (
|
|
4587
|
+
if (existsSync5(join3(homedir(), ".hermes"))) {
|
|
4067
4588
|
installed.push(id);
|
|
4068
4589
|
} else {
|
|
4069
4590
|
try {
|
|
@@ -4072,11 +4593,11 @@ function detectInstalledAgents() {
|
|
|
4072
4593
|
} catch {}
|
|
4073
4594
|
}
|
|
4074
4595
|
} else if (id === "antigravity") {
|
|
4075
|
-
if (
|
|
4596
|
+
if (existsSync5(getAntigravityPluginRoot(id)) || existsSync5(join3(homedir(), ".gemini", "antigravity")) || existsSync5(join3(homedir(), ".gemini", "antigravity-ide")) || existsSync5("/Applications/Antigravity.app")) {
|
|
4076
4597
|
installed.push(id);
|
|
4077
4598
|
}
|
|
4078
4599
|
} else if (id === "antigravity-cli") {
|
|
4079
|
-
if (
|
|
4600
|
+
if (existsSync5(join3(homedir(), ".gemini", "antigravity-cli"))) {
|
|
4080
4601
|
installed.push(id);
|
|
4081
4602
|
} else {
|
|
4082
4603
|
try {
|
|
@@ -4085,8 +4606,8 @@ function detectInstalledAgents() {
|
|
|
4085
4606
|
} catch {}
|
|
4086
4607
|
}
|
|
4087
4608
|
} else {
|
|
4088
|
-
const configDir =
|
|
4089
|
-
if (
|
|
4609
|
+
const configDir = dirname4(agent.configPath);
|
|
4610
|
+
if (existsSync5(configDir)) {
|
|
4090
4611
|
installed.push(id);
|
|
4091
4612
|
}
|
|
4092
4613
|
}
|
|
@@ -4246,7 +4767,7 @@ function formatHookStatusLabel(name) {
|
|
|
4246
4767
|
return name.replace(/\*/g, "events").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]/g, " ").replace(/\s+/g, " ").trim().replace(/^./, (letter) => letter.toUpperCase());
|
|
4247
4768
|
}
|
|
4248
4769
|
function getAgentApproveDir() {
|
|
4249
|
-
return
|
|
4770
|
+
return join3(homedir(), ".agentapprove");
|
|
4250
4771
|
}
|
|
4251
4772
|
function uniqueRemovalTargets(targets) {
|
|
4252
4773
|
const seen = new Set;
|
|
@@ -4266,7 +4787,7 @@ function buildUninstallPlan() {
|
|
|
4266
4787
|
const pluginArtifactTargets = uniqueRemovalTargets([
|
|
4267
4788
|
...getOpenClawPluginTargets(AGENTS.openclaw.configPath),
|
|
4268
4789
|
...getOpenCodePluginTargets(getOpenCodeConfigDir(), getOpenCodeCacheDir()),
|
|
4269
|
-
...getAntigravityPluginTargets(
|
|
4790
|
+
...getAntigravityPluginTargets(join3(homedir(), ".gemini"))
|
|
4270
4791
|
]);
|
|
4271
4792
|
return {
|
|
4272
4793
|
configuredAgents,
|
|
@@ -4338,39 +4859,39 @@ async function confirmUninstallPlan(mode, plan) {
|
|
|
4338
4859
|
return true;
|
|
4339
4860
|
}
|
|
4340
4861
|
function pruneEmptyDir(path) {
|
|
4341
|
-
if (!
|
|
4862
|
+
if (!existsSync5(path)) {
|
|
4342
4863
|
return;
|
|
4343
4864
|
}
|
|
4344
4865
|
try {
|
|
4345
4866
|
if (readdirSync2(path).length === 0) {
|
|
4346
|
-
|
|
4867
|
+
rmSync3(path, { recursive: false, force: true });
|
|
4347
4868
|
}
|
|
4348
4869
|
} catch {}
|
|
4349
4870
|
}
|
|
4350
4871
|
function finalizeAgentApproveDirPurge(agentApproveDir) {
|
|
4351
|
-
if (!
|
|
4872
|
+
if (!existsSync5(agentApproveDir)) {
|
|
4352
4873
|
return;
|
|
4353
4874
|
}
|
|
4354
4875
|
try {
|
|
4355
|
-
const stat =
|
|
4876
|
+
const stat = lstatSync2(agentApproveDir);
|
|
4356
4877
|
if (stat.isSymbolicLink()) {
|
|
4357
4878
|
const actualDir = realpathSync2(agentApproveDir);
|
|
4358
|
-
if (
|
|
4359
|
-
|
|
4879
|
+
if (existsSync5(actualDir) && readdirSync2(actualDir).length === 0) {
|
|
4880
|
+
rmSync3(actualDir, { recursive: false, force: true });
|
|
4360
4881
|
}
|
|
4361
|
-
|
|
4882
|
+
rmSync3(agentApproveDir, { recursive: false, force: true });
|
|
4362
4883
|
return;
|
|
4363
4884
|
}
|
|
4364
4885
|
} catch {}
|
|
4365
4886
|
pruneEmptyDir(agentApproveDir);
|
|
4366
4887
|
}
|
|
4367
4888
|
function readExistingConfig() {
|
|
4368
|
-
const envPath =
|
|
4369
|
-
if (!
|
|
4889
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
4890
|
+
if (!existsSync5(envPath)) {
|
|
4370
4891
|
return null;
|
|
4371
4892
|
}
|
|
4372
4893
|
try {
|
|
4373
|
-
const content =
|
|
4894
|
+
const content = readFileSync3(envPath, "utf-8");
|
|
4374
4895
|
const config = {};
|
|
4375
4896
|
for (const line of content.split(`
|
|
4376
4897
|
`)) {
|
|
@@ -4426,28 +4947,28 @@ function readExistingConfig() {
|
|
|
4426
4947
|
}
|
|
4427
4948
|
function discoverE2EKeys() {
|
|
4428
4949
|
const dir = getAgentApproveDir();
|
|
4429
|
-
if (!
|
|
4950
|
+
if (!existsSync5(dir))
|
|
4430
4951
|
return [];
|
|
4431
4952
|
const keys = [];
|
|
4432
|
-
const currentPath =
|
|
4433
|
-
if (
|
|
4953
|
+
const currentPath = join3(dir, "e2e-key");
|
|
4954
|
+
if (existsSync5(currentPath)) {
|
|
4434
4955
|
try {
|
|
4435
|
-
const hex =
|
|
4956
|
+
const hex = readFileSync3(currentPath, "utf-8").trim();
|
|
4436
4957
|
if (hex.length === 64) {
|
|
4437
|
-
const keyId =
|
|
4438
|
-
keys.push({ keyId, keyHex: hex, path: currentPath, isCurrent: true, modifiedAt:
|
|
4958
|
+
const keyId = createHash3("sha256").update(Buffer.from(hex, "hex")).digest("hex").slice(0, 8);
|
|
4959
|
+
keys.push({ keyId, keyHex: hex, path: currentPath, isCurrent: true, modifiedAt: statSync2(currentPath).mtime });
|
|
4439
4960
|
}
|
|
4440
4961
|
} catch {}
|
|
4441
4962
|
}
|
|
4442
4963
|
try {
|
|
4443
4964
|
const files = readdirSync2(dir).filter((f) => f.startsWith("e2e-key.") && f.endsWith(".bak"));
|
|
4444
4965
|
for (const file of files) {
|
|
4445
|
-
const fullPath =
|
|
4966
|
+
const fullPath = join3(dir, file);
|
|
4446
4967
|
try {
|
|
4447
|
-
const hex =
|
|
4968
|
+
const hex = readFileSync3(fullPath, "utf-8").trim();
|
|
4448
4969
|
if (hex.length === 64) {
|
|
4449
|
-
const keyId =
|
|
4450
|
-
keys.push({ keyId, keyHex: hex, path: fullPath, isCurrent: false, modifiedAt:
|
|
4970
|
+
const keyId = createHash3("sha256").update(Buffer.from(hex, "hex")).digest("hex").slice(0, 8);
|
|
4971
|
+
keys.push({ keyId, keyHex: hex, path: fullPath, isCurrent: false, modifiedAt: statSync2(fullPath).mtime });
|
|
4451
4972
|
}
|
|
4452
4973
|
} catch {}
|
|
4453
4974
|
}
|
|
@@ -4455,43 +4976,38 @@ function discoverE2EKeys() {
|
|
|
4455
4976
|
return keys;
|
|
4456
4977
|
}
|
|
4457
4978
|
function readRotationConfig() {
|
|
4458
|
-
const configPath =
|
|
4459
|
-
if (!
|
|
4979
|
+
const configPath = join3(getAgentApproveDir(), "e2e-rotation.json");
|
|
4980
|
+
if (!existsSync5(configPath))
|
|
4460
4981
|
return null;
|
|
4461
4982
|
try {
|
|
4462
|
-
return JSON.parse(
|
|
4983
|
+
return JSON.parse(readFileSync3(configPath, "utf-8"));
|
|
4463
4984
|
} catch {
|
|
4464
4985
|
return null;
|
|
4465
4986
|
}
|
|
4466
4987
|
}
|
|
4467
4988
|
function writeRotationConfig(config) {
|
|
4468
|
-
const configPath =
|
|
4469
|
-
|
|
4989
|
+
const configPath = join3(getAgentApproveDir(), "e2e-rotation.json");
|
|
4990
|
+
writePrivateFile(configPath, JSON.stringify(config, null, 2));
|
|
4470
4991
|
}
|
|
4471
4992
|
function ensureAgentApproveDir() {
|
|
4472
4993
|
const dir = getAgentApproveDir();
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
}
|
|
4476
|
-
const hooksDir = join(dir, "hooks");
|
|
4477
|
-
if (!existsSync2(hooksDir)) {
|
|
4478
|
-
mkdirSync(hooksDir, { recursive: true, mode: 448 });
|
|
4479
|
-
}
|
|
4994
|
+
ensurePrivateDir(dir);
|
|
4995
|
+
ensurePrivateDir(join3(dir, "hooks"));
|
|
4480
4996
|
}
|
|
4481
4997
|
function migrateE2ERootKey() {
|
|
4482
4998
|
const dir = getAgentApproveDir();
|
|
4483
|
-
const keyPath =
|
|
4484
|
-
const rootKeyPath =
|
|
4485
|
-
const rotationPath =
|
|
4486
|
-
if (!
|
|
4999
|
+
const keyPath = join3(dir, "e2e-key");
|
|
5000
|
+
const rootKeyPath = join3(dir, "e2e-root-key");
|
|
5001
|
+
const rotationPath = join3(dir, "e2e-rotation.json");
|
|
5002
|
+
if (!existsSync5(keyPath) || existsSync5(rootKeyPath))
|
|
4487
5003
|
return;
|
|
4488
5004
|
try {
|
|
4489
|
-
const keyHex =
|
|
5005
|
+
const keyHex = readFileSync3(keyPath, "utf-8").trim();
|
|
4490
5006
|
if (keyHex.length !== 64)
|
|
4491
5007
|
return;
|
|
4492
|
-
|
|
4493
|
-
if (!
|
|
4494
|
-
const keyId =
|
|
5008
|
+
writePrivateFile(rootKeyPath, keyHex);
|
|
5009
|
+
if (!existsSync5(rotationPath)) {
|
|
5010
|
+
const keyId = createHash3("sha256").update(Buffer.from(keyHex, "hex")).digest("hex").slice(0, 8);
|
|
4495
5011
|
writeRotationConfig({
|
|
4496
5012
|
rootKeyId: keyId,
|
|
4497
5013
|
epoch: 0,
|
|
@@ -4501,48 +5017,20 @@ function migrateE2ERootKey() {
|
|
|
4501
5017
|
}
|
|
4502
5018
|
} catch {}
|
|
4503
5019
|
}
|
|
4504
|
-
function
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
4509
|
-
const backupPath = `${configPath}.backup.${timestamp}`;
|
|
4510
|
-
copyFileSync(configPath, backupPath);
|
|
4511
|
-
return backupPath;
|
|
4512
|
-
}
|
|
4513
|
-
function readJsonConfig(configPath) {
|
|
4514
|
-
if (!existsSync2(configPath)) {
|
|
4515
|
-
return {};
|
|
4516
|
-
}
|
|
4517
|
-
try {
|
|
4518
|
-
const content = readFileSync(configPath, "utf-8");
|
|
4519
|
-
return JSON.parse(content);
|
|
4520
|
-
} catch {
|
|
4521
|
-
return {};
|
|
4522
|
-
}
|
|
4523
|
-
}
|
|
4524
|
-
function writeJsonConfig(configPath, config) {
|
|
4525
|
-
const dir = dirname2(configPath);
|
|
4526
|
-
if (!existsSync2(dir)) {
|
|
4527
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
4528
|
-
}
|
|
4529
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2) + `
|
|
4530
|
-
`);
|
|
4531
|
-
}
|
|
4532
|
-
function ensureCodexFeatureFlag(configPath = join(homedir(), ".codex", "config.toml")) {
|
|
4533
|
-
const dir = dirname2(configPath);
|
|
4534
|
-
if (!existsSync2(dir)) {
|
|
4535
|
-
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
5020
|
+
function ensureCodexFeatureFlag(configPath = join3(homedir(), ".codex", "config.toml")) {
|
|
5021
|
+
const dir = dirname4(configPath);
|
|
5022
|
+
if (!existsSync5(dir)) {
|
|
5023
|
+
mkdirSync3(dir, { recursive: true, mode: 448 });
|
|
4536
5024
|
}
|
|
4537
5025
|
const sectionHeader = "[features]";
|
|
4538
5026
|
const desiredLine = "codex_hooks = true";
|
|
4539
|
-
if (!
|
|
4540
|
-
|
|
5027
|
+
if (!existsSync5(configPath)) {
|
|
5028
|
+
writeFileSync2(configPath, `${sectionHeader}
|
|
4541
5029
|
${desiredLine}
|
|
4542
5030
|
`, { mode: 384 });
|
|
4543
5031
|
return { updated: true, backupPath: null };
|
|
4544
5032
|
}
|
|
4545
|
-
const original =
|
|
5033
|
+
const original = readFileSync3(configPath, "utf-8");
|
|
4546
5034
|
const lines = original.split(/\r?\n/);
|
|
4547
5035
|
const updatedLines = [];
|
|
4548
5036
|
let inFeatures = false;
|
|
@@ -4590,16 +5078,16 @@ ${desiredLine}
|
|
|
4590
5078
|
return { updated: false, backupPath: null };
|
|
4591
5079
|
}
|
|
4592
5080
|
const backupPath = backupConfig(configPath);
|
|
4593
|
-
|
|
5081
|
+
writeFileSync2(configPath, `${updatedLines.join(`
|
|
4594
5082
|
`).replace(/\n*$/, `
|
|
4595
5083
|
`)}`, { mode: 384 });
|
|
4596
5084
|
return { updated: true, backupPath };
|
|
4597
5085
|
}
|
|
4598
|
-
function disableCodexFeatureFlag(configPath =
|
|
4599
|
-
if (!
|
|
5086
|
+
function disableCodexFeatureFlag(configPath = join3(homedir(), ".codex", "config.toml")) {
|
|
5087
|
+
if (!existsSync5(configPath)) {
|
|
4600
5088
|
return { updated: false, backupPath: null };
|
|
4601
5089
|
}
|
|
4602
|
-
const original =
|
|
5090
|
+
const original = readFileSync3(configPath, "utf-8");
|
|
4603
5091
|
const updated = original.split(/\r?\n/).filter((line) => !/^\s*codex_hooks\s*=/.test(line)).join(`
|
|
4604
5092
|
`).replace(/\n*$/, `
|
|
4605
5093
|
`);
|
|
@@ -4607,7 +5095,7 @@ function disableCodexFeatureFlag(configPath = join(homedir(), ".codex", "config.
|
|
|
4607
5095
|
return { updated: false, backupPath: null };
|
|
4608
5096
|
}
|
|
4609
5097
|
const backupPath = backupConfig(configPath);
|
|
4610
|
-
|
|
5098
|
+
writeFileSync2(configPath, updated, { mode: 384 });
|
|
4611
5099
|
return { updated: true, backupPath };
|
|
4612
5100
|
}
|
|
4613
5101
|
async function createPairingSession(configuredAgents, e2eKeyId, apiBaseUrl = API_URL) {
|
|
@@ -4789,7 +5277,7 @@ async function showPairingPresentation(params) {
|
|
|
4789
5277
|
`);
|
|
4790
5278
|
}
|
|
4791
5279
|
function saveEnvConfig(config) {
|
|
4792
|
-
const envPath =
|
|
5280
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
4793
5281
|
const configSetAt = config.configSetAt ?? Math.floor(Date.now() / 1000);
|
|
4794
5282
|
const hasBackgroundPreference = config.preserved?.AGENTAPPROVE_FILTER_BACKGROUND_ACTIVITY !== undefined;
|
|
4795
5283
|
const preserved = {
|
|
@@ -4831,7 +5319,7 @@ ${renderPreservedEnvSection(preserved)}
|
|
|
4831
5319
|
# manual edits here are overwritten on the next config sync.
|
|
4832
5320
|
# To change settings, run: npx agentapprove install
|
|
4833
5321
|
`;
|
|
4834
|
-
|
|
5322
|
+
writePrivateFile(envPath, content);
|
|
4835
5323
|
}
|
|
4836
5324
|
var KEYCHAIN_SERVICE = "com.agentapprove";
|
|
4837
5325
|
var KEYCHAIN_ACCOUNT = "api-token";
|
|
@@ -4984,8 +5472,14 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4984
5472
|
if (isAntigravityAgent(agentId)) {
|
|
4985
5473
|
return installAntigravityPluginBundle(agentId, hooksDir, mode);
|
|
4986
5474
|
}
|
|
5475
|
+
let config;
|
|
5476
|
+
try {
|
|
5477
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
5478
|
+
} catch (error) {
|
|
5479
|
+
return { success: false, backupPath: null, hooks: [], error: configErrorMessage(error) };
|
|
5480
|
+
}
|
|
4987
5481
|
const backupPath = backupConfig(agent.configPath);
|
|
4988
|
-
const
|
|
5482
|
+
const commentsNote = keepCommentedConfig(agentId, agent.configPath, backupPath);
|
|
4989
5483
|
const useTopLevelHooks = agent.hooksKey === "";
|
|
4990
5484
|
if (!useTopLevelHooks && !config[agent.hooksKey]) {
|
|
4991
5485
|
config[agent.hooksKey] = {};
|
|
@@ -4999,9 +5493,9 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
4999
5493
|
mode,
|
|
5000
5494
|
readVersion: readOpenClawInstalledVersion,
|
|
5001
5495
|
readConfig: () => {
|
|
5002
|
-
if (!
|
|
5496
|
+
if (!existsSync5(agent.configPath))
|
|
5003
5497
|
return {};
|
|
5004
|
-
const current = JSON.parse(
|
|
5498
|
+
const current = JSON.parse(readFileSync3(agent.configPath, "utf8"));
|
|
5005
5499
|
if (!current || typeof current !== "object" || Array.isArray(current)) {
|
|
5006
5500
|
throw new Error("OpenClaw configuration must be a JSON object; no settings were overwritten.");
|
|
5007
5501
|
}
|
|
@@ -5020,7 +5514,12 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5020
5514
|
if (!installResult.success) {
|
|
5021
5515
|
return { success: false, backupPath, hooks: [], error: installResult.error };
|
|
5022
5516
|
}
|
|
5023
|
-
|
|
5517
|
+
let opencodeConfig;
|
|
5518
|
+
try {
|
|
5519
|
+
opencodeConfig = readJsonConfig(agent.configPath);
|
|
5520
|
+
} catch (error) {
|
|
5521
|
+
return { success: false, backupPath, hooks: [], error: configErrorMessage(error) };
|
|
5522
|
+
}
|
|
5024
5523
|
if (!Array.isArray(opencodeConfig.plugin)) {
|
|
5025
5524
|
opencodeConfig.plugin = [];
|
|
5026
5525
|
}
|
|
@@ -5030,16 +5529,16 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5030
5529
|
}
|
|
5031
5530
|
opencodeConfig.plugin = pluginArray;
|
|
5032
5531
|
writeJsonConfig(agent.configPath, opencodeConfig);
|
|
5033
|
-
const opencodePkgPath =
|
|
5532
|
+
const opencodePkgPath = join3(getOpenCodeConfigDir(), "package.json");
|
|
5034
5533
|
try {
|
|
5035
|
-
const pkgJson = JSON.parse(
|
|
5534
|
+
const pkgJson = JSON.parse(readFileSync3(opencodePkgPath, "utf-8"));
|
|
5036
5535
|
const deps = pkgJson.dependencies;
|
|
5037
5536
|
if (deps?.["@agentapprove/opencode"]) {
|
|
5038
5537
|
delete deps["@agentapprove/opencode"];
|
|
5039
5538
|
if (Object.keys(deps).length === 0) {
|
|
5040
5539
|
delete pkgJson.dependencies;
|
|
5041
5540
|
}
|
|
5042
|
-
|
|
5541
|
+
writeFileSync2(opencodePkgPath, JSON.stringify(pkgJson, null, 2) + `
|
|
5043
5542
|
`);
|
|
5044
5543
|
}
|
|
5045
5544
|
} catch (err) {
|
|
@@ -5055,7 +5554,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5055
5554
|
}
|
|
5056
5555
|
const hooksToInstall = mode === "observe" ? agent.hooks.filter((h) => !h.isApprovalHook) : agent.hooks;
|
|
5057
5556
|
for (const hook of hooksToInstall) {
|
|
5058
|
-
const hookPath =
|
|
5557
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5059
5558
|
const hookCommand = buildHookCommand(hookPath, agentId);
|
|
5060
5559
|
if (agentId === "claude-code") {
|
|
5061
5560
|
if (!hooksConfig[hook.name]) {
|
|
@@ -5343,7 +5842,7 @@ async function installHooksForAgent(agentId, hooksDir, mode = "approval") {
|
|
|
5343
5842
|
if (agentId === "codex") {
|
|
5344
5843
|
ensureCodexFeatureFlag();
|
|
5345
5844
|
}
|
|
5346
|
-
return { success: true, backupPath, hooks: installedHooks };
|
|
5845
|
+
return { success: true, backupPath, hooks: installedHooks, ...commentsNote ? { note: commentsNote } : {} };
|
|
5347
5846
|
}
|
|
5348
5847
|
function getManualInstructions(agentId, hooksDir) {
|
|
5349
5848
|
const agent = AGENTS[agentId];
|
|
@@ -5354,7 +5853,7 @@ function getManualInstructions(agentId, hooksDir) {
|
|
|
5354
5853
|
for (const hook of agent.hooks) {
|
|
5355
5854
|
const hasMatcher = hook.hasMatcher ?? true;
|
|
5356
5855
|
const hookTimeout = hook.timeout;
|
|
5357
|
-
const hookPath =
|
|
5856
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5358
5857
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5359
5858
|
const hookObject = {
|
|
5360
5859
|
type: "command",
|
|
@@ -5372,7 +5871,7 @@ function getManualInstructions(agentId, hooksDir) {
|
|
|
5372
5871
|
for (const hook of agent.hooks) {
|
|
5373
5872
|
const hasMatcher = hook.hasMatcher ?? true;
|
|
5374
5873
|
const hookTimeout = hook.timeout;
|
|
5375
|
-
const hookPath =
|
|
5874
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5376
5875
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5377
5876
|
const hookObject = {
|
|
5378
5877
|
type: "command",
|
|
@@ -5392,7 +5891,7 @@ codex_hooks = true`;
|
|
|
5392
5891
|
} else if (agentId === "cursor") {
|
|
5393
5892
|
const hooksObj = {};
|
|
5394
5893
|
for (const hook of agent.hooks) {
|
|
5395
|
-
const hookPath =
|
|
5894
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5396
5895
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5397
5896
|
const entry = cursorHookEntry(hook.name, hookCmd, hook.isApprovalHook);
|
|
5398
5897
|
hooksObj[hook.name] = [entry];
|
|
@@ -5401,7 +5900,7 @@ codex_hooks = true`;
|
|
|
5401
5900
|
} else if (agentId === "windsurf") {
|
|
5402
5901
|
const hooksObj = {};
|
|
5403
5902
|
for (const hook of agent.hooks) {
|
|
5404
|
-
const hookPath =
|
|
5903
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5405
5904
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5406
5905
|
hooksObj[hook.name] = [{ command: hookCmd, show_output: false }];
|
|
5407
5906
|
}
|
|
@@ -5410,7 +5909,7 @@ codex_hooks = true`;
|
|
|
5410
5909
|
const hooksObj = {};
|
|
5411
5910
|
for (const hook of agent.hooks) {
|
|
5412
5911
|
const hookTimeout = hook.timeout;
|
|
5413
|
-
const hookCmd = buildHookCommand(
|
|
5912
|
+
const hookCmd = buildHookCommand(join3(hooksDir, hook.file), agentId);
|
|
5414
5913
|
const hookObject = hookTimeout ? { type: "command", command: hookCmd, timeout: hookTimeout * 1000 } : { type: "command", command: hookCmd };
|
|
5415
5914
|
hooksObj[hook.name] = [{ hooks: [hookObject] }];
|
|
5416
5915
|
}
|
|
@@ -5430,7 +5929,7 @@ codex_hooks = true`;
|
|
|
5430
5929
|
} else if (agentId === "vscode-agent") {
|
|
5431
5930
|
const hooksObj = {};
|
|
5432
5931
|
for (const hook of agent.hooks) {
|
|
5433
|
-
const hookPath =
|
|
5932
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5434
5933
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5435
5934
|
const isApproval = hook.isApprovalHook;
|
|
5436
5935
|
const hookTimeout = hook.timeout;
|
|
@@ -5451,7 +5950,7 @@ codex_hooks = true`;
|
|
|
5451
5950
|
} else if (agentId === "copilot-cli") {
|
|
5452
5951
|
const hooksObj = {};
|
|
5453
5952
|
for (const hook of agent.hooks) {
|
|
5454
|
-
const hookPath =
|
|
5953
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5455
5954
|
const isApproval = hook.isApprovalHook;
|
|
5456
5955
|
const entry = {
|
|
5457
5956
|
type: "command",
|
|
@@ -5468,7 +5967,7 @@ codex_hooks = true`;
|
|
|
5468
5967
|
} else if (agentId === "openhands") {
|
|
5469
5968
|
const hooksObj = {};
|
|
5470
5969
|
for (const hook of agent.hooks) {
|
|
5471
|
-
const hookPath =
|
|
5970
|
+
const hookPath = join3(hooksDir, hook.file);
|
|
5472
5971
|
const hookCmd = buildHookCommand(hookPath, agentId);
|
|
5473
5972
|
const hookTimeout = hook.timeout;
|
|
5474
5973
|
const isApproval = hook.isApprovalHook;
|
|
@@ -5593,7 +6092,8 @@ async function copyHookScripts2(hooksDir, token, files, options = {}) {
|
|
|
5593
6092
|
apiUrl: options.apiUrl || API_URL,
|
|
5594
6093
|
apiVersion: API_VERSION,
|
|
5595
6094
|
onRateLimit: options.onRateLimit,
|
|
5596
|
-
optionalFiles: options.optionalFiles
|
|
6095
|
+
optionalFiles: options.optionalFiles,
|
|
6096
|
+
expectedHashes: HOOK_SCRIPT_SHA256
|
|
5597
6097
|
});
|
|
5598
6098
|
}
|
|
5599
6099
|
function readOpenClawInstalledVersion() {
|
|
@@ -5607,14 +6107,14 @@ function readOpenClawInstalledVersion() {
|
|
|
5607
6107
|
if (result.status === 0) {
|
|
5608
6108
|
const metadata = JSON.parse(result.stdout);
|
|
5609
6109
|
if (metadata.plugin?.packageName === "@agentapprove/openclaw" && typeof metadata.plugin.rootDir === "string") {
|
|
5610
|
-
return readJsonPackageVersion(
|
|
6110
|
+
return readJsonPackageVersion(join3(metadata.plugin.rootDir, "package.json"));
|
|
5611
6111
|
}
|
|
5612
6112
|
return null;
|
|
5613
6113
|
}
|
|
5614
6114
|
} catch {}
|
|
5615
6115
|
for (const packagePath of [
|
|
5616
|
-
|
|
5617
|
-
|
|
6116
|
+
join3(homedir(), ".openclaw", "npm", "node_modules", "@agentapprove", "openclaw", "package.json"),
|
|
6117
|
+
join3(homedir(), ".openclaw", "extensions", "openclaw", "package.json")
|
|
5618
6118
|
]) {
|
|
5619
6119
|
const version = readJsonPackageVersion(packagePath);
|
|
5620
6120
|
if (version)
|
|
@@ -5623,11 +6123,11 @@ function readOpenClawInstalledVersion() {
|
|
|
5623
6123
|
return null;
|
|
5624
6124
|
}
|
|
5625
6125
|
function readJsonPackageVersion(packagePath) {
|
|
5626
|
-
if (!
|
|
6126
|
+
if (!existsSync5(packagePath)) {
|
|
5627
6127
|
return null;
|
|
5628
6128
|
}
|
|
5629
6129
|
try {
|
|
5630
|
-
const pkg = JSON.parse(
|
|
6130
|
+
const pkg = JSON.parse(readFileSync3(packagePath, "utf-8"));
|
|
5631
6131
|
return typeof pkg.version === "string" ? pkg.version : null;
|
|
5632
6132
|
} catch {
|
|
5633
6133
|
return null;
|
|
@@ -5636,10 +6136,10 @@ function readJsonPackageVersion(packagePath) {
|
|
|
5636
6136
|
function readOpenCodeInstalledVersion() {
|
|
5637
6137
|
const cacheDir = getOpenCodeCacheDir();
|
|
5638
6138
|
const candidates = [
|
|
5639
|
-
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
|
|
6139
|
+
join3(cacheDir, "packages", "@agentapprove", `opencode@${OPENCODE_PLUGIN_VERSION}`, "node_modules", "@agentapprove", "opencode", "package.json"),
|
|
6140
|
+
join3(cacheDir, "packages", "@agentapprove", "opencode@latest", "node_modules", "@agentapprove", "opencode", "package.json"),
|
|
6141
|
+
join3(cacheDir, "node_modules", "@agentapprove", "opencode", "package.json"),
|
|
6142
|
+
join3(getOpenCodeConfigDir(), "node_modules", "@agentapprove", "opencode", "package.json")
|
|
5643
6143
|
];
|
|
5644
6144
|
for (const candidate of candidates) {
|
|
5645
6145
|
const version = readJsonPackageVersion(candidate);
|
|
@@ -5707,10 +6207,10 @@ function installOpenCodePluginViaCli() {
|
|
|
5707
6207
|
}
|
|
5708
6208
|
function readPiPinnedSpec() {
|
|
5709
6209
|
try {
|
|
5710
|
-
const settingsPath =
|
|
5711
|
-
if (!
|
|
6210
|
+
const settingsPath = join3(homedir(), ".pi", "agent", "settings.json");
|
|
6211
|
+
if (!existsSync5(settingsPath))
|
|
5712
6212
|
return null;
|
|
5713
|
-
const settings = JSON.parse(
|
|
6213
|
+
const settings = JSON.parse(readFileSync3(settingsPath, "utf8"));
|
|
5714
6214
|
if (!Array.isArray(settings.packages))
|
|
5715
6215
|
return null;
|
|
5716
6216
|
const spec = settings.packages.find((entry) => typeof entry === "string" && entry.startsWith("npm:@agentapprove/pi"));
|
|
@@ -5764,9 +6264,9 @@ function removePiPluginViaCli() {
|
|
|
5764
6264
|
};
|
|
5765
6265
|
}
|
|
5766
6266
|
}
|
|
5767
|
-
var HERMES_BUNDLE_SHA256 = "
|
|
6267
|
+
var HERMES_BUNDLE_SHA256 = "f0013d5a39281e9faa8ffe9ebfac0f40eb1777ef971f0cd0e55d6ebf9cf44244";
|
|
5768
6268
|
var HERMES_BUNDLE_FILENAME = `agentapprove-hermes-${HERMES_PLUGIN_VERSION}.tar.gz`;
|
|
5769
|
-
var HERMES_PLUGIN_DIR =
|
|
6269
|
+
var HERMES_PLUGIN_DIR = join3(homedir(), ".hermes", "plugins", "agentapprove");
|
|
5770
6270
|
function findPython() {
|
|
5771
6271
|
for (const candidate of ["python3.12", "python3.11", "python3.10", "python3"]) {
|
|
5772
6272
|
try {
|
|
@@ -5797,13 +6297,13 @@ function isSafeApiVersion(candidate) {
|
|
|
5797
6297
|
return /^[a-z0-9-]+$/i.test(candidate);
|
|
5798
6298
|
}
|
|
5799
6299
|
function readInstallerConfig() {
|
|
5800
|
-
const envPath =
|
|
6300
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
5801
6301
|
let apiUrl = API_URL;
|
|
5802
6302
|
let apiVersion = "v001";
|
|
5803
6303
|
let token = "";
|
|
5804
|
-
if (
|
|
6304
|
+
if (existsSync5(envPath)) {
|
|
5805
6305
|
try {
|
|
5806
|
-
const content =
|
|
6306
|
+
const content = readFileSync3(envPath, "utf-8");
|
|
5807
6307
|
for (const line of content.split(`
|
|
5808
6308
|
`)) {
|
|
5809
6309
|
if (line.startsWith("#"))
|
|
@@ -5870,7 +6370,7 @@ async function downloadHermesBundle(apiUrl, apiVersion, token) {
|
|
|
5870
6370
|
}
|
|
5871
6371
|
}
|
|
5872
6372
|
function verifyBundleHash(bytes) {
|
|
5873
|
-
return
|
|
6373
|
+
return createHash3("sha256").update(bytes).digest("hex");
|
|
5874
6374
|
}
|
|
5875
6375
|
function validateExtractedTree(root) {
|
|
5876
6376
|
const realRoot = realpathSync2(root);
|
|
@@ -5884,7 +6384,7 @@ function validateExtractedTree(root) {
|
|
|
5884
6384
|
return { ok: false, error: `Cannot read staged dir ${dir}: ${err instanceof Error ? err.message : String(err)}` };
|
|
5885
6385
|
}
|
|
5886
6386
|
for (const entry of entries) {
|
|
5887
|
-
const fullPath =
|
|
6387
|
+
const fullPath = join3(dir, String(entry.name));
|
|
5888
6388
|
let resolved;
|
|
5889
6389
|
try {
|
|
5890
6390
|
resolved = realpathSync2(fullPath);
|
|
@@ -5968,7 +6468,7 @@ function isValidHermesProfileName(name) {
|
|
|
5968
6468
|
return name === HERMES_DEFAULT_PROFILE || HERMES_PROFILE_ID_RE.test(name);
|
|
5969
6469
|
}
|
|
5970
6470
|
function hermesProfilePluginDir(profile) {
|
|
5971
|
-
return profile === HERMES_DEFAULT_PROFILE ? HERMES_PLUGIN_DIR :
|
|
6471
|
+
return profile === HERMES_DEFAULT_PROFILE ? HERMES_PLUGIN_DIR : join3(homedir(), ".hermes", "profiles", profile, "plugins", "agentapprove");
|
|
5972
6472
|
}
|
|
5973
6473
|
function hermesEnableCmd(profile) {
|
|
5974
6474
|
return profile === HERMES_DEFAULT_PROFILE ? "hermes plugins enable agentapprove" : `hermes -p ${profile} plugins enable agentapprove`;
|
|
@@ -5979,54 +6479,54 @@ function hermesDisableCmd(profile) {
|
|
|
5979
6479
|
function stageHermesBundle(bytes, targetDir) {
|
|
5980
6480
|
let tmpDir;
|
|
5981
6481
|
try {
|
|
5982
|
-
tmpDir = mkdtempSync(
|
|
6482
|
+
tmpDir = mkdtempSync(join3(tmpdir(), "aa-hermes-"));
|
|
5983
6483
|
} catch (err) {
|
|
5984
6484
|
return { success: false, error: `Could not create temp directory for bundle staging: ${err instanceof Error ? err.message : String(err)}` };
|
|
5985
6485
|
}
|
|
5986
|
-
const tarballPath =
|
|
6486
|
+
const tarballPath = join3(tmpDir, HERMES_BUNDLE_FILENAME);
|
|
5987
6487
|
let backupPath = null;
|
|
5988
6488
|
try {
|
|
5989
|
-
|
|
6489
|
+
writeFileSync2(tarballPath, bytes);
|
|
5990
6490
|
try {
|
|
5991
6491
|
runHostCommand("tar", ["-xzf", tarballPath, "-C", tmpDir, "--no-same-owner", "--no-same-permissions"]);
|
|
5992
6492
|
} catch (err) {
|
|
5993
6493
|
return { success: false, error: `tar extract failed: ${err instanceof Error ? err.message : String(err)}` };
|
|
5994
6494
|
}
|
|
5995
|
-
const stagedDir =
|
|
5996
|
-
if (!
|
|
6495
|
+
const stagedDir = join3(tmpDir, "agentapprove");
|
|
6496
|
+
if (!existsSync5(stagedDir)) {
|
|
5997
6497
|
return { success: false, error: "Bundle did not contain expected `agentapprove/` directory." };
|
|
5998
6498
|
}
|
|
5999
6499
|
const validation = validateExtractedTree(stagedDir);
|
|
6000
6500
|
if (!validation.ok) {
|
|
6001
6501
|
return { success: false, error: `Bundle integrity violation: ${validation.error}` };
|
|
6002
6502
|
}
|
|
6003
|
-
|
|
6004
|
-
if (
|
|
6503
|
+
mkdirSync3(dirname4(targetDir), { recursive: true });
|
|
6504
|
+
if (existsSync5(targetDir)) {
|
|
6005
6505
|
backupPath = `${targetDir}.bak-${Date.now()}`;
|
|
6006
|
-
|
|
6506
|
+
renameSync4(targetDir, backupPath);
|
|
6007
6507
|
}
|
|
6008
6508
|
try {
|
|
6009
|
-
|
|
6509
|
+
renameSync4(stagedDir, targetDir);
|
|
6010
6510
|
} catch (err) {
|
|
6011
6511
|
if (backupPath) {
|
|
6012
6512
|
try {
|
|
6013
|
-
|
|
6513
|
+
renameSync4(backupPath, targetDir);
|
|
6014
6514
|
backupPath = null;
|
|
6015
6515
|
} catch {}
|
|
6016
6516
|
}
|
|
6017
6517
|
const restoreNote = backupPath ? ` Your previous install was preserved at ${backupPath} — recover with: mv "${backupPath}" "${targetDir}"` : "";
|
|
6018
6518
|
return { success: false, error: `Could not install bundle to ${targetDir}: ${err instanceof Error ? err.message : String(err)}.${restoreNote}` };
|
|
6019
6519
|
}
|
|
6020
|
-
|
|
6520
|
+
writeFileSync2(join3(targetDir, ".bundle-hash"), HERMES_BUNDLE_SHA256, { mode: 420 });
|
|
6021
6521
|
if (backupPath) {
|
|
6022
|
-
|
|
6522
|
+
rmSync3(backupPath, { recursive: true, force: true });
|
|
6023
6523
|
backupPath = null;
|
|
6024
6524
|
}
|
|
6025
6525
|
} catch (err) {
|
|
6026
6526
|
if (backupPath) {
|
|
6027
6527
|
try {
|
|
6028
|
-
|
|
6029
|
-
|
|
6528
|
+
rmSync3(targetDir, { recursive: true, force: true });
|
|
6529
|
+
renameSync4(backupPath, targetDir);
|
|
6030
6530
|
backupPath = null;
|
|
6031
6531
|
} catch {}
|
|
6032
6532
|
}
|
|
@@ -6034,13 +6534,14 @@ function stageHermesBundle(bytes, targetDir) {
|
|
|
6034
6534
|
return { success: false, error: `Bundle install failed: ${err instanceof Error ? err.message : String(err)}.${restoreNote}` };
|
|
6035
6535
|
} finally {
|
|
6036
6536
|
try {
|
|
6037
|
-
|
|
6537
|
+
rmSync3(tmpDir, { recursive: true, force: true });
|
|
6038
6538
|
} catch {}
|
|
6039
6539
|
}
|
|
6040
6540
|
return { success: true };
|
|
6041
6541
|
}
|
|
6042
6542
|
function enableHermesPluginForProfile(profile) {
|
|
6043
6543
|
try {
|
|
6544
|
+
ensureHermesHookTimeout(profile);
|
|
6044
6545
|
enableHermesFollowUp(profile);
|
|
6045
6546
|
runHostCommand("hermes", [...profile === HERMES_DEFAULT_PROFILE ? [] : ["-p", profile], "plugins", "enable", "agentapprove"], { interactive: true, timeoutMs: PACKAGE_INSTALL_TIMEOUT_MS });
|
|
6046
6547
|
return { success: true };
|
|
@@ -6146,7 +6647,7 @@ function disableHermesPluginViaCli() {
|
|
|
6146
6647
|
function removeHermesPluginFromProfile(profile) {
|
|
6147
6648
|
const disabled = disableHermesPluginForProfile(profile);
|
|
6148
6649
|
try {
|
|
6149
|
-
|
|
6650
|
+
rmSync3(hermesProfilePluginDir(profile), { recursive: true, force: true });
|
|
6150
6651
|
return disabled.success ? { success: true } : { success: false, error: `disable failed: ${disabled.error || "unknown"}` };
|
|
6151
6652
|
} catch (err) {
|
|
6152
6653
|
return {
|
|
@@ -6157,11 +6658,11 @@ function removeHermesPluginFromProfile(profile) {
|
|
|
6157
6658
|
}
|
|
6158
6659
|
function hermesProfilePluginStatus(profile) {
|
|
6159
6660
|
const dir = hermesProfilePluginDir(profile);
|
|
6160
|
-
const installed =
|
|
6661
|
+
const installed = existsSync5(join3(dir, ".bundle-hash"));
|
|
6161
6662
|
let version = null;
|
|
6162
6663
|
if (installed) {
|
|
6163
6664
|
try {
|
|
6164
|
-
const configPy =
|
|
6665
|
+
const configPy = readFileSync3(join3(dir, "config.py"), "utf-8");
|
|
6165
6666
|
const m = configPy.match(/^PLUGIN_VERSION\s*=\s*["']([^"']+)["']/m);
|
|
6166
6667
|
version = m ? m[1] : null;
|
|
6167
6668
|
} catch {}
|
|
@@ -6171,8 +6672,8 @@ function hermesProfilePluginStatus(profile) {
|
|
|
6171
6672
|
function listHermesProfiles() {
|
|
6172
6673
|
const names = new Set([HERMES_DEFAULT_PROFILE]);
|
|
6173
6674
|
try {
|
|
6174
|
-
const profilesRoot =
|
|
6175
|
-
if (
|
|
6675
|
+
const profilesRoot = join3(homedir(), ".hermes", "profiles");
|
|
6676
|
+
if (existsSync5(profilesRoot)) {
|
|
6176
6677
|
for (const entry of readdirSync2(profilesRoot, { withFileTypes: true })) {
|
|
6177
6678
|
if (entry.isDirectory() && isValidHermesProfileName(entry.name)) {
|
|
6178
6679
|
names.add(entry.name);
|
|
@@ -6298,8 +6799,8 @@ function checkCommand(name) {
|
|
|
6298
6799
|
if (isWindows()) {
|
|
6299
6800
|
const gitBashPath = findGitBash();
|
|
6300
6801
|
if (gitBashPath) {
|
|
6301
|
-
|
|
6302
|
-
return
|
|
6802
|
+
const result = spawnSync2(gitBashPath, ["-c", 'command -v "$1"', "agentapprove", name], { stdio: "ignore" });
|
|
6803
|
+
return result.status === 0;
|
|
6303
6804
|
}
|
|
6304
6805
|
execSync(`where ${name}`, { stdio: "ignore" });
|
|
6305
6806
|
return true;
|
|
@@ -6544,10 +7045,10 @@ async function installCommand() {
|
|
|
6544
7045
|
let existingKeyId = null;
|
|
6545
7046
|
if (existingConfig) {
|
|
6546
7047
|
existingTokenPreview = hasExistingToken ? existingConfig.token.slice(0, 15) + "..." : "Not set";
|
|
6547
|
-
const e2eKeyPath =
|
|
6548
|
-
if (
|
|
6549
|
-
const keyHex =
|
|
6550
|
-
existingKeyId =
|
|
7048
|
+
const e2eKeyPath = join3(getAgentApproveDir(), "e2e-key");
|
|
7049
|
+
if (existsSync5(e2eKeyPath)) {
|
|
7050
|
+
const keyHex = readFileSync3(e2eKeyPath, "utf-8").trim();
|
|
7051
|
+
existingKeyId = createHash3("sha256").update(Buffer.from(keyHex, "hex")).digest("hex").slice(0, 8);
|
|
6551
7052
|
}
|
|
6552
7053
|
}
|
|
6553
7054
|
const existingTokenPreflight = hasExistingToken ? await runExistingTokenPreflight(existingConfig.token, pairingApiBase) : null;
|
|
@@ -6601,7 +7102,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6601
7102
|
const requiresFreshPair = pendingRecoveryAction !== null;
|
|
6602
7103
|
const forceKeyReuseForRecovery = pendingRecoveryAction === "refresh";
|
|
6603
7104
|
ensureAgentApproveDir();
|
|
6604
|
-
const hooksDir =
|
|
7105
|
+
const hooksDir = join3(getAgentApproveDir(), "hooks");
|
|
6605
7106
|
const selectedInstallConfig = getInitialInstallConfig(setupProfile, existingConfig);
|
|
6606
7107
|
let token = null;
|
|
6607
7108
|
let finalPrivacy = selectedInstallConfig.privacy;
|
|
@@ -6683,7 +7184,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6683
7184
|
}
|
|
6684
7185
|
ensureAgentApproveDir();
|
|
6685
7186
|
const agentApproveDir = getAgentApproveDir();
|
|
6686
|
-
const existingKeyPath =
|
|
7187
|
+
const existingKeyPath = join3(agentApproveDir, "e2e-key");
|
|
6687
7188
|
let e2eUserKey = null;
|
|
6688
7189
|
let backupOldKeyTo = null;
|
|
6689
7190
|
if (setupProfile === "customize" && !e2eRequired && !skipE2E) {
|
|
@@ -6698,9 +7199,9 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6698
7199
|
useE2E = e2eChoice;
|
|
6699
7200
|
}
|
|
6700
7201
|
if (useE2E) {
|
|
6701
|
-
if (
|
|
6702
|
-
const oldKeyHex =
|
|
6703
|
-
const oldKeyId =
|
|
7202
|
+
if (existsSync5(existingKeyPath)) {
|
|
7203
|
+
const oldKeyHex = readFileSync3(existingKeyPath, "utf-8").trim();
|
|
7204
|
+
const oldKeyId = createHash3("sha256").update(Buffer.from(oldKeyHex, "hex")).digest("hex").slice(0, 8);
|
|
6704
7205
|
const autoReuseKey = forceKeyReuseForRecovery || setupProfile === "existing-config" && !requiresFreshPair;
|
|
6705
7206
|
if (autoReuseKey) {
|
|
6706
7207
|
e2eUserKey = oldKeyHex;
|
|
@@ -6720,19 +7221,19 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6720
7221
|
e2eUserKey = oldKeyHex;
|
|
6721
7222
|
} else {
|
|
6722
7223
|
if (keyAction === "backup") {
|
|
6723
|
-
backupOldKeyTo =
|
|
7224
|
+
backupOldKeyTo = join3(agentApproveDir, `e2e-key.${oldKeyId}.bak`);
|
|
6724
7225
|
}
|
|
6725
|
-
e2eUserKey =
|
|
7226
|
+
e2eUserKey = randomBytes2(32).toString("hex");
|
|
6726
7227
|
}
|
|
6727
7228
|
}
|
|
6728
7229
|
} else {
|
|
6729
|
-
e2eUserKey =
|
|
7230
|
+
e2eUserKey = randomBytes2(32).toString("hex");
|
|
6730
7231
|
}
|
|
6731
7232
|
}
|
|
6732
7233
|
if (!useE2E) {
|
|
6733
7234
|
v2.info("E2E encryption disabled — event content will be visible on the web dashboard");
|
|
6734
7235
|
}
|
|
6735
|
-
const e2eKeyId = e2eUserKey ?
|
|
7236
|
+
const e2eKeyId = e2eUserKey ? createHash3("sha256").update(Buffer.from(e2eUserKey, "hex")).digest("hex").slice(0, 8) : undefined;
|
|
6736
7237
|
if (setupProfile === "customize") {
|
|
6737
7238
|
const retentionChoice = await le({
|
|
6738
7239
|
message: "Data retention - how long to keep event history",
|
|
@@ -6802,7 +7303,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6802
7303
|
if (setupProfile === "existing-config" && existingConfig?.configSetAt) {
|
|
6803
7304
|
configSetAt = existingConfig.configSetAt;
|
|
6804
7305
|
}
|
|
6805
|
-
const e2eKeyExists =
|
|
7306
|
+
const e2eKeyExists = existsSync5(existingKeyPath);
|
|
6806
7307
|
useE2E = e2eKeyExists;
|
|
6807
7308
|
e2eUserKey = null;
|
|
6808
7309
|
backupOldKeyTo = null;
|
|
@@ -6811,11 +7312,6 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6811
7312
|
}
|
|
6812
7313
|
} else if (shouldCreateFreshPairing(connectionMethod)) {
|
|
6813
7314
|
const pairingMethod = connectionMethod;
|
|
6814
|
-
if (backupOldKeyTo) {
|
|
6815
|
-
renameSync2(existingKeyPath, backupOldKeyTo);
|
|
6816
|
-
v2.success(`Old key backed up to ${backupOldKeyTo}`);
|
|
6817
|
-
backupOldKeyTo = null;
|
|
6818
|
-
}
|
|
6819
7315
|
configSetAt = Math.floor(Date.now() / 1000);
|
|
6820
7316
|
const pairingConfig = {
|
|
6821
7317
|
privacyTier: finalPrivacy,
|
|
@@ -6862,11 +7358,16 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6862
7358
|
}
|
|
6863
7359
|
email = result.email;
|
|
6864
7360
|
apiUrl = result.apiUrl || pairingApiBase;
|
|
7361
|
+
if (backupOldKeyTo) {
|
|
7362
|
+
renameSync4(existingKeyPath, backupOldKeyTo);
|
|
7363
|
+
v2.success(`Old key backed up to ${backupOldKeyTo}`);
|
|
7364
|
+
backupOldKeyTo = null;
|
|
7365
|
+
}
|
|
6865
7366
|
if (e2eUserKey && e2eKeyId) {
|
|
6866
|
-
const rootKeyPath =
|
|
6867
|
-
|
|
6868
|
-
const userKeyPath =
|
|
6869
|
-
|
|
7367
|
+
const rootKeyPath = join3(agentApproveDir, "e2e-root-key");
|
|
7368
|
+
writePrivateFile(rootKeyPath, e2eUserKey);
|
|
7369
|
+
const userKeyPath = join3(agentApproveDir, "e2e-key");
|
|
7370
|
+
writePrivateFile(userKeyPath, e2eUserKey);
|
|
6870
7371
|
writeRotationConfig({
|
|
6871
7372
|
rootKeyId: e2eKeyId,
|
|
6872
7373
|
epoch: 0,
|
|
@@ -6874,8 +7375,8 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6874
7375
|
startedAt: new Date().toISOString()
|
|
6875
7376
|
});
|
|
6876
7377
|
if (result.e2eServerKey) {
|
|
6877
|
-
const serverKeyPath =
|
|
6878
|
-
|
|
7378
|
+
const serverKeyPath = join3(agentApproveDir, "e2e-server-key");
|
|
7379
|
+
writePrivateFile(serverKeyPath, result.e2eServerKey);
|
|
6879
7380
|
}
|
|
6880
7381
|
}
|
|
6881
7382
|
if (e2eKeyId) {
|
|
@@ -6945,8 +7446,8 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6945
7446
|
} else {
|
|
6946
7447
|
v2.success("No hook scripts needed for the selected agents");
|
|
6947
7448
|
}
|
|
6948
|
-
const e2eKeyPath =
|
|
6949
|
-
const hasE2EKey =
|
|
7449
|
+
const e2eKeyPath = join3(agentApproveDir, "e2e-key");
|
|
7450
|
+
const hasE2EKey = existsSync5(e2eKeyPath);
|
|
6950
7451
|
if (hasE2EKey) {
|
|
6951
7452
|
if (!silentlyReuseExistingToken) {
|
|
6952
7453
|
if (installMode === "observe") {
|
|
@@ -6955,9 +7456,9 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6955
7456
|
v2.info("Approval mode: Commands are sent via encrypted channel for policy evaluation.");
|
|
6956
7457
|
}
|
|
6957
7458
|
}
|
|
6958
|
-
const envPath =
|
|
6959
|
-
if (
|
|
6960
|
-
let envContent =
|
|
7459
|
+
const envPath = join3(agentApproveDir, "env");
|
|
7460
|
+
if (existsSync5(envPath)) {
|
|
7461
|
+
let envContent = readFileSync3(envPath, "utf-8");
|
|
6961
7462
|
if (envContent.includes("AGENTAPPROVE_E2E_MODE=")) {
|
|
6962
7463
|
envContent = envContent.replace(/AGENTAPPROVE_E2E_MODE=\w+/, `AGENTAPPROVE_E2E_MODE=${installMode}`);
|
|
6963
7464
|
} else {
|
|
@@ -6966,7 +7467,7 @@ Monitor activity, enforce policy, and approve with a tap.`, "About");
|
|
|
6966
7467
|
AGENTAPPROVE_E2E_MODE=${installMode}
|
|
6967
7468
|
`;
|
|
6968
7469
|
}
|
|
6969
|
-
|
|
7470
|
+
writePrivateFile(envPath, envContent);
|
|
6970
7471
|
}
|
|
6971
7472
|
}
|
|
6972
7473
|
const installMethod = await le({
|
|
@@ -6990,7 +7491,7 @@ AGENTAPPROVE_E2E_MODE=${installMode}
|
|
|
6990
7491
|
filesToModify.push(agent.configPath);
|
|
6991
7492
|
}
|
|
6992
7493
|
if (agentId === "codex") {
|
|
6993
|
-
filesToModify.push(
|
|
7494
|
+
filesToModify.push(join3(homedir(), ".codex", "config.toml"));
|
|
6994
7495
|
}
|
|
6995
7496
|
if (agentId === "opencode") {
|
|
6996
7497
|
filesToModify.push("OpenCode plugin cache");
|
|
@@ -7043,11 +7544,21 @@ Timestamped backups will be created.`);
|
|
|
7043
7544
|
v2.success(`${agentName}: ${installedHookNames}${backupMsg}`);
|
|
7044
7545
|
else
|
|
7045
7546
|
spinner.stop(`${agentName}: ${installedHookNames}${backupMsg}`);
|
|
7547
|
+
if (result.note)
|
|
7548
|
+
v2.info(result.note);
|
|
7046
7549
|
if (agentId === "vscode-agent") {
|
|
7047
7550
|
const vsCodeSpinner = _2();
|
|
7048
7551
|
vsCodeSpinner.start("Registering hook path in VS Code settings");
|
|
7049
|
-
const modifiedPaths = addToVSCodeHookLocations();
|
|
7050
|
-
if (
|
|
7552
|
+
const { modified: modifiedPaths, failed: failedSettings } = addToVSCodeHookLocations();
|
|
7553
|
+
if (failedSettings.length > 0) {
|
|
7554
|
+
failedSetupAgents.add(agentId);
|
|
7555
|
+
vsCodeSpinner.stop(modifiedPaths.length > 0 ? `Registered in: ${modifiedPaths.join(", ")}` : source_default.yellow("VS Code settings were not updated"));
|
|
7556
|
+
for (const failure of failedSettings) {
|
|
7557
|
+
v2.warn(`${failure.variant} settings were not changed.
|
|
7558
|
+
` + ` ${failure.error}
|
|
7559
|
+
` + ` Or add "~/.agentapprove/hooks": true under "chat.hookFilesLocations" yourself.`);
|
|
7560
|
+
}
|
|
7561
|
+
} else if (modifiedPaths.length > 0) {
|
|
7051
7562
|
vsCodeSpinner.stop(`Registered in: ${modifiedPaths.join(", ")}`);
|
|
7052
7563
|
} else {
|
|
7053
7564
|
const variants = findInstalledVSCodeVariants();
|
|
@@ -7107,8 +7618,13 @@ Timestamped backups will be created.`);
|
|
|
7107
7618
|
` + ` 5. pip install --user cryptography httpx
|
|
7108
7619
|
` + ` (uv-managed Python: uv pip install --system --break-system-packages --python $(which python3.12) cryptography httpx)
|
|
7109
7620
|
` + ` 6. hermes config set plugins.entries.agentapprove.allow_gateway_injection true
|
|
7110
|
-
` + ` 7. hermes plugins
|
|
7621
|
+
` + ` 7. hermes config set plugins.hook_callback_timeout 600
|
|
7622
|
+
` + ` (For a named profile add -p <profile> after hermes; skip if already 0/unlimited.)
|
|
7623
|
+
` + ` 8. hermes plugins enable agentapprove
|
|
7111
7624
|
` + ` Then re-run: npx agentapprove`);
|
|
7625
|
+
} else if (result.error) {
|
|
7626
|
+
v2.warn(`${agent.name} was not set up.
|
|
7627
|
+
` + ` ${result.error}`);
|
|
7112
7628
|
}
|
|
7113
7629
|
}
|
|
7114
7630
|
}
|
|
@@ -7123,7 +7639,7 @@ Timestamped backups will be created.`);
|
|
|
7123
7639
|
});
|
|
7124
7640
|
}
|
|
7125
7641
|
const integrationChecks = inspectSetup(selectedAgents).map((item) => failedSetupAgents.has(item.agent) ? { ...item, status: "failed", reason: "invalid_config" } : item);
|
|
7126
|
-
|
|
7642
|
+
writePrivateFile(join3(getAgentApproveDir(), "setup-agents.json"), JSON.stringify(selectedAgents));
|
|
7127
7643
|
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)";
|
|
7128
7644
|
me(`Mode: ${modeDesc}
|
|
7129
7645
|
|
|
@@ -7149,14 +7665,14 @@ function inspectSetup(agentIds) {
|
|
|
7149
7665
|
return result("manual", "manual_step");
|
|
7150
7666
|
if (!existing?.token)
|
|
7151
7667
|
return result("failed", "not_configured");
|
|
7152
|
-
if (
|
|
7668
|
+
if (existsSync5(join3(getAgentApproveDir(), DISABLED_STATE_FILENAME)))
|
|
7153
7669
|
return result("failed", "disabled");
|
|
7154
7670
|
try {
|
|
7155
7671
|
if (existing.e2eEnabled !== false) {
|
|
7156
|
-
const keyPath =
|
|
7157
|
-
if (!
|
|
7672
|
+
const keyPath = join3(getAgentApproveDir(), "e2e-key");
|
|
7673
|
+
if (!existsSync5(keyPath))
|
|
7158
7674
|
return result("failed", "missing_files");
|
|
7159
|
-
if (!/^[a-fA-F0-9]{64}$/.test(
|
|
7675
|
+
if (!/^[a-fA-F0-9]{64}$/.test(readFileSync3(keyPath, "utf8").trim()))
|
|
7160
7676
|
return result("failed", "invalid_config");
|
|
7161
7677
|
}
|
|
7162
7678
|
if (agentId === "pi" || agentId === "hermes") {
|
|
@@ -7164,10 +7680,10 @@ function inspectSetup(agentIds) {
|
|
|
7164
7680
|
const ready = agentId === "pi" ? output.includes("@agentapprove/pi") : /^.*agentapprove.*enabled/im.test(output);
|
|
7165
7681
|
return result(ready ? "ready" : "failed", ready ? "verified" : "not_configured");
|
|
7166
7682
|
}
|
|
7167
|
-
const configPath = agentId === "copilot-cli" ?
|
|
7168
|
-
if (agentId === "copilot-cli" && !
|
|
7683
|
+
const configPath = agentId === "copilot-cli" ? join3(process.cwd(), ".github/hooks/agentapprove.json") : agent.configPath;
|
|
7684
|
+
if (agentId === "copilot-cli" && !existsSync5(configPath))
|
|
7169
7685
|
return result("manual", "manual_step");
|
|
7170
|
-
const config =
|
|
7686
|
+
const config = readAgentConfig(agentId, configPath);
|
|
7171
7687
|
if (agentId === "opencode") {
|
|
7172
7688
|
const ready = Array.isArray(config.plugin) && config.plugin.some((p) => typeof p === "string" && p.includes("@agentapprove/opencode"));
|
|
7173
7689
|
return result(ready ? "ready" : "failed", ready ? "verified" : "not_configured");
|
|
@@ -7179,40 +7695,45 @@ function inspectSetup(agentIds) {
|
|
|
7179
7695
|
}
|
|
7180
7696
|
if (agentId === "vscode-agent") {
|
|
7181
7697
|
const registered = findInstalledVSCodeVariants().some(({ path }) => {
|
|
7182
|
-
|
|
7183
|
-
|
|
7698
|
+
let locations;
|
|
7699
|
+
try {
|
|
7700
|
+
locations = readJsoncConfig(path)["chat.hookFilesLocations"];
|
|
7701
|
+
} catch {
|
|
7702
|
+
return false;
|
|
7703
|
+
}
|
|
7704
|
+
return locations?.["~/.agentapprove/hooks"] === true || locations?.[join3(getAgentApproveDir(), "hooks")] === true;
|
|
7184
7705
|
});
|
|
7185
7706
|
if (!registered)
|
|
7186
7707
|
return result("manual", "manual_step");
|
|
7187
7708
|
}
|
|
7188
|
-
if (agentId === "codex" && !/codex_hooks\s*=\s*true/.test(
|
|
7709
|
+
if (agentId === "codex" && !/codex_hooks\s*=\s*true/.test(readFileSync3(join3(homedir(), ".codex/config.toml"), "utf8")))
|
|
7189
7710
|
return result("failed", "not_configured");
|
|
7190
7711
|
const filesReady = (file) => {
|
|
7191
|
-
const path =
|
|
7192
|
-
return
|
|
7712
|
+
const path = join3(getAgentApproveDir(), "hooks", file);
|
|
7713
|
+
return existsSync5(path) && statSync2(path).size > 0 && (!file.endsWith(".sh") || (statSync2(path).mode & 73) !== 0);
|
|
7193
7714
|
};
|
|
7194
7715
|
if (!SHARED_HOOK_FILES.filter((file) => !BACKGROUND_FILTER_FILES.includes(file)).every(filesReady))
|
|
7195
7716
|
return result("failed", "missing_files");
|
|
7196
7717
|
if (spawnSync2("bash", ["-c", "command -v curl >/dev/null && command -v jq >/dev/null && command -v openssl >/dev/null"], { timeout: 5000 }).status !== 0)
|
|
7197
7718
|
return result("failed", "missing_dependency");
|
|
7198
7719
|
if (isAntigravityAgent(agentId)) {
|
|
7199
|
-
if (!
|
|
7720
|
+
if (!existsSync5(join3(getAntigravityPluginRoot(agentId), "plugin.json")))
|
|
7200
7721
|
return result("failed", "missing_files");
|
|
7201
7722
|
const mode = existing.e2eMode ?? "approval";
|
|
7202
7723
|
const hooks = mode === "observe" ? agent.hooks.filter((h) => h.name !== "Stop") : agent.hooks;
|
|
7203
|
-
return checkHookConfiguration(agentId, config, "agentapprove", hooks, "approval", filesReady, (file, name) => buildAntigravityHookCommand(
|
|
7724
|
+
return checkHookConfiguration(agentId, config, "agentapprove", hooks, "approval", filesReady, (file, name) => buildAntigravityHookCommand(join3(getAgentApproveDir(), "hooks", file), agentId, name, mode));
|
|
7204
7725
|
}
|
|
7205
|
-
return checkHookConfiguration(agentId, config, agent.hooksKey, agent.hooks, existing.e2eMode ?? "approval", filesReady, (file) => buildHookCommand(
|
|
7726
|
+
return checkHookConfiguration(agentId, config, agent.hooksKey, agent.hooks, existing.e2eMode ?? "approval", filesReady, (file) => buildHookCommand(join3(getAgentApproveDir(), "hooks", file), agentId));
|
|
7206
7727
|
} catch {
|
|
7207
7728
|
return result("failed", "invalid_config");
|
|
7208
7729
|
}
|
|
7209
7730
|
});
|
|
7210
7731
|
}
|
|
7211
7732
|
async function checkSetupCommand() {
|
|
7212
|
-
const selectionFile =
|
|
7733
|
+
const selectionFile = join3(getAgentApproveDir(), "setup-agents.json");
|
|
7213
7734
|
let agents;
|
|
7214
7735
|
try {
|
|
7215
|
-
agents = JSON.parse(
|
|
7736
|
+
agents = JSON.parse(readFileSync3(selectionFile, "utf8")).filter((id) => typeof id === "string" && (id in AGENTS));
|
|
7216
7737
|
} catch {
|
|
7217
7738
|
agents = detectInstalledAgents();
|
|
7218
7739
|
}
|
|
@@ -7322,16 +7843,16 @@ async function statusCommand() {
|
|
|
7322
7843
|
console.log(source_default.cyan(`
|
|
7323
7844
|
Agent Approve Status
|
|
7324
7845
|
`));
|
|
7325
|
-
if (
|
|
7846
|
+
if (existsSync5(join3(getAgentApproveDir(), DISABLED_STATE_FILENAME))) {
|
|
7326
7847
|
console.log(source_default.yellow(" Disabled: hooks and plugins are deregistered from your agents."));
|
|
7327
7848
|
console.log(source_default.dim(" Run `npx agentapprove enable` to restore them.\n"));
|
|
7328
7849
|
}
|
|
7329
|
-
const envPath =
|
|
7330
|
-
if (!
|
|
7850
|
+
const envPath = join3(getAgentApproveDir(), "env");
|
|
7851
|
+
if (!existsSync5(envPath)) {
|
|
7331
7852
|
console.log(source_default.yellow(" Not configured. Run `npx agentapprove` to set up.\n"));
|
|
7332
7853
|
return;
|
|
7333
7854
|
}
|
|
7334
|
-
const envContent =
|
|
7855
|
+
const envContent = readFileSync3(envPath, "utf-8");
|
|
7335
7856
|
const lines = envContent.split(`
|
|
7336
7857
|
`);
|
|
7337
7858
|
let envToken = "";
|
|
@@ -7351,15 +7872,15 @@ async function statusCommand() {
|
|
|
7351
7872
|
}
|
|
7352
7873
|
}
|
|
7353
7874
|
await syncKeychainTokenWithEnv(envToken);
|
|
7354
|
-
const e2eKeyFile =
|
|
7355
|
-
const e2eServerKeyFile =
|
|
7356
|
-
if (
|
|
7875
|
+
const e2eKeyFile = join3(getAgentApproveDir(), "e2e-key");
|
|
7876
|
+
const e2eServerKeyFile = join3(getAgentApproveDir(), "e2e-server-key");
|
|
7877
|
+
if (existsSync5(e2eKeyFile)) {
|
|
7357
7878
|
console.log(` ${source_default.green("✓")} E2E user key: installed`);
|
|
7358
7879
|
}
|
|
7359
|
-
if (
|
|
7880
|
+
if (existsSync5(e2eServerKeyFile)) {
|
|
7360
7881
|
console.log(` ${source_default.green("✓")} E2E server key: installed`);
|
|
7361
7882
|
}
|
|
7362
|
-
if (!
|
|
7883
|
+
if (!existsSync5(e2eKeyFile) && !existsSync5(e2eServerKeyFile)) {
|
|
7363
7884
|
console.log(` ${source_default.dim(" E2E encryption: not configured")}`);
|
|
7364
7885
|
}
|
|
7365
7886
|
console.log();
|
|
@@ -7394,8 +7915,14 @@ async function statusCommand() {
|
|
|
7394
7915
|
} catch {}
|
|
7395
7916
|
continue;
|
|
7396
7917
|
}
|
|
7397
|
-
if (
|
|
7398
|
-
|
|
7918
|
+
if (existsSync5(agent.configPath)) {
|
|
7919
|
+
let config;
|
|
7920
|
+
try {
|
|
7921
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
7922
|
+
} catch (error) {
|
|
7923
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name}: ${configErrorMessage(error)}`);
|
|
7924
|
+
continue;
|
|
7925
|
+
}
|
|
7399
7926
|
if (agentId === "opencode") {
|
|
7400
7927
|
const pluginConfig = config.plugin;
|
|
7401
7928
|
if (Array.isArray(pluginConfig) && pluginConfig.some((entry) => typeof entry === "string" && entry.includes("@agentapprove/opencode"))) {
|
|
@@ -7446,12 +7973,12 @@ function sleepMsSync(ms) {
|
|
|
7446
7973
|
function acquireDisabledStateMergeLock(lockPath) {
|
|
7447
7974
|
for (let attempt = 0;attempt < 40; attempt++) {
|
|
7448
7975
|
try {
|
|
7449
|
-
|
|
7976
|
+
mkdirSync3(lockPath);
|
|
7450
7977
|
return true;
|
|
7451
7978
|
} catch {
|
|
7452
7979
|
try {
|
|
7453
|
-
if (Date.now() -
|
|
7454
|
-
|
|
7980
|
+
if (Date.now() - statSync2(lockPath).mtimeMs > 1e4) {
|
|
7981
|
+
rmSync3(lockPath, { recursive: true, force: true });
|
|
7455
7982
|
continue;
|
|
7456
7983
|
}
|
|
7457
7984
|
} catch {
|
|
@@ -7464,10 +7991,10 @@ function acquireDisabledStateMergeLock(lockPath) {
|
|
|
7464
7991
|
}
|
|
7465
7992
|
async function disableCommand() {
|
|
7466
7993
|
const aaDir = getAgentApproveDir();
|
|
7467
|
-
const statePath =
|
|
7994
|
+
const statePath = join3(aaDir, DISABLED_STATE_FILENAME);
|
|
7468
7995
|
let hasExistingRecord = false;
|
|
7469
7996
|
try {
|
|
7470
|
-
|
|
7997
|
+
readFileSync3(statePath);
|
|
7471
7998
|
hasExistingRecord = true;
|
|
7472
7999
|
} catch {
|
|
7473
8000
|
hasExistingRecord = false;
|
|
@@ -7479,7 +8006,7 @@ async function disableCommand() {
|
|
|
7479
8006
|
return;
|
|
7480
8007
|
}
|
|
7481
8008
|
const existingConfig = readExistingConfig();
|
|
7482
|
-
const legacyDisabledEnv =
|
|
8009
|
+
const legacyDisabledEnv = existsSync5(join3(aaDir, "env.disabled"));
|
|
7483
8010
|
console.log(source_default.cyan(`
|
|
7484
8011
|
Disabling Agent Approve...
|
|
7485
8012
|
`));
|
|
@@ -7514,7 +8041,7 @@ async function disableCommand() {
|
|
|
7514
8041
|
agents: records
|
|
7515
8042
|
};
|
|
7516
8043
|
try {
|
|
7517
|
-
|
|
8044
|
+
writeFileSync2(statePath, JSON.stringify(state, null, 2) + `
|
|
7518
8045
|
`, { mode: 384, flag: "wx" });
|
|
7519
8046
|
} catch (err) {
|
|
7520
8047
|
let failed = true;
|
|
@@ -7522,18 +8049,18 @@ async function disableCommand() {
|
|
|
7522
8049
|
const lockPath = `${statePath}.lock`;
|
|
7523
8050
|
if (acquireDisabledStateMergeLock(lockPath)) {
|
|
7524
8051
|
try {
|
|
7525
|
-
const existing = parseDisabledState(
|
|
8052
|
+
const existing = parseDisabledState(readFileSync3(statePath, "utf-8"));
|
|
7526
8053
|
const merged = existing ? mergeDisabledStates(existing, state) : state;
|
|
7527
8054
|
const tmpPath = `${statePath}.tmp-${process.pid}`;
|
|
7528
|
-
|
|
8055
|
+
writeFileSync2(tmpPath, JSON.stringify(merged, null, 2) + `
|
|
7529
8056
|
`, { mode: 384 });
|
|
7530
|
-
|
|
8057
|
+
renameSync4(tmpPath, statePath);
|
|
7531
8058
|
failed = false;
|
|
7532
8059
|
} catch {
|
|
7533
8060
|
failed = true;
|
|
7534
8061
|
} finally {
|
|
7535
8062
|
try {
|
|
7536
|
-
|
|
8063
|
+
rmSync3(lockPath, { recursive: true, force: true });
|
|
7537
8064
|
} catch {}
|
|
7538
8065
|
}
|
|
7539
8066
|
}
|
|
@@ -7551,7 +8078,7 @@ async function disableCommand() {
|
|
|
7551
8078
|
✓ Agent Approve disabled.`));
|
|
7552
8079
|
console.log(source_default.dim(" Hooks and plugins are deregistered from your agents, so Agent Approve no longer runs."));
|
|
7553
8080
|
console.log(source_default.dim(" Local state (pairing, settings, E2E keys, hook scripts) is kept in ~/.agentapprove."));
|
|
7554
|
-
if (
|
|
8081
|
+
if (existsSync5(join3(aaDir, "copilot-cli-hooks.json"))) {
|
|
7555
8082
|
console.log(source_default.yellow(" Note: per-repo GitHub Copilot hooks (.github/hooks/agentapprove.json, added with `init-repo`)"));
|
|
7556
8083
|
console.log(source_default.yellow(" cannot be reached from here and stay active until you remove them in each repo."));
|
|
7557
8084
|
}
|
|
@@ -7562,9 +8089,15 @@ async function disableCommand() {
|
|
|
7562
8089
|
}
|
|
7563
8090
|
function disableAgent(agentId, agent, records, warnings) {
|
|
7564
8091
|
if (agentId === "pi") {
|
|
7565
|
-
if (!
|
|
8092
|
+
if (!existsSync5(agent.configPath))
|
|
8093
|
+
return;
|
|
8094
|
+
let settings;
|
|
8095
|
+
try {
|
|
8096
|
+
settings = readJsonConfig(agent.configPath);
|
|
8097
|
+
} catch (error) {
|
|
8098
|
+
warnings.push(`${agent.name}: ${configErrorMessage(error)}`);
|
|
7566
8099
|
return;
|
|
7567
|
-
|
|
8100
|
+
}
|
|
7568
8101
|
const removal = removePiPackageEntries(settings);
|
|
7569
8102
|
if (removal.modified) {
|
|
7570
8103
|
writeJsonConfig(agent.configPath, settings);
|
|
@@ -7593,10 +8126,10 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7593
8126
|
}
|
|
7594
8127
|
if (isAntigravityAgent(agentId)) {
|
|
7595
8128
|
const pluginRoot = getAntigravityPluginRoot(agentId);
|
|
7596
|
-
if (!
|
|
8129
|
+
if (!existsSync5(pluginRoot))
|
|
7597
8130
|
return;
|
|
7598
8131
|
try {
|
|
7599
|
-
|
|
8132
|
+
rmSync3(pluginRoot, { recursive: true, force: true });
|
|
7600
8133
|
records.push({ agentId, kind: "hooks" });
|
|
7601
8134
|
console.log(` ${source_default.green("✓")} ${agent.name}: plugin deregistered`);
|
|
7602
8135
|
} catch (err) {
|
|
@@ -7605,7 +8138,9 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7605
8138
|
return;
|
|
7606
8139
|
}
|
|
7607
8140
|
if (agentId === "vscode-agent") {
|
|
7608
|
-
const removedVSCode = removeFromVSCodeHookLocations()
|
|
8141
|
+
const removedVSCode = removeFromVSCodeHookLocations((failure) => {
|
|
8142
|
+
warnings.push(`${agent.name} (${failure.variant}): ${failure.error}`);
|
|
8143
|
+
});
|
|
7609
8144
|
if (removedVSCode.length > 0) {
|
|
7610
8145
|
records.push({ agentId, kind: "vscode_hook_location" });
|
|
7611
8146
|
for (const path of removedVSCode) {
|
|
@@ -7617,9 +8152,15 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7617
8152
|
if (agentId === "copilot-cli") {
|
|
7618
8153
|
return;
|
|
7619
8154
|
}
|
|
7620
|
-
if (!
|
|
8155
|
+
if (!existsSync5(agent.configPath))
|
|
8156
|
+
return;
|
|
8157
|
+
let config;
|
|
8158
|
+
try {
|
|
8159
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
8160
|
+
} catch (error) {
|
|
8161
|
+
warnings.push(`${agent.name}: ${configErrorMessage(error)}`);
|
|
7621
8162
|
return;
|
|
7622
|
-
|
|
8163
|
+
}
|
|
7623
8164
|
if (agentId === "openclaw") {
|
|
7624
8165
|
const flip = disableOpenClawEntries(config);
|
|
7625
8166
|
if (flip.modified) {
|
|
@@ -7650,9 +8191,12 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7650
8191
|
const hooksConfig = useTopLevelHooks ? config : config[agent.hooksKey] ?? {};
|
|
7651
8192
|
const modified = removeAgentApproveHookEntries(hooksConfig, agent.hooks.map((hook) => hook.name));
|
|
7652
8193
|
if (modified) {
|
|
8194
|
+
const commentsNote = keepCommentedConfig(agentId, agent.configPath);
|
|
7653
8195
|
writeJsonConfig(agent.configPath, config);
|
|
7654
8196
|
records.push({ agentId, kind: "hooks" });
|
|
7655
8197
|
console.log(` ${source_default.green("✓")} ${agent.name}: hooks deregistered`);
|
|
8198
|
+
if (commentsNote)
|
|
8199
|
+
console.log(source_default.dim(` ${commentsNote}`));
|
|
7656
8200
|
if (agentId === "codex" && Object.keys(hooksConfig).length === 0) {
|
|
7657
8201
|
const codexFlag = disableCodexFeatureFlag();
|
|
7658
8202
|
if (codexFlag.updated) {
|
|
@@ -7661,24 +8205,33 @@ function disableAgent(agentId, agent, records, warnings) {
|
|
|
7661
8205
|
}
|
|
7662
8206
|
}
|
|
7663
8207
|
}
|
|
8208
|
+
function readRestorableConfig(agent, record, failures) {
|
|
8209
|
+
try {
|
|
8210
|
+
return readJsonConfig(agent.configPath);
|
|
8211
|
+
} catch (error) {
|
|
8212
|
+
failures.push(record);
|
|
8213
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name}: could not restore the registration. ${configErrorMessage(error)}`);
|
|
8214
|
+
return null;
|
|
8215
|
+
}
|
|
8216
|
+
}
|
|
7664
8217
|
async function enableCommand() {
|
|
7665
8218
|
const aaDir = getAgentApproveDir();
|
|
7666
|
-
const envPath =
|
|
7667
|
-
const legacyDisabledPath =
|
|
7668
|
-
const statePath =
|
|
7669
|
-
if (!
|
|
7670
|
-
|
|
8219
|
+
const envPath = join3(aaDir, "env");
|
|
8220
|
+
const legacyDisabledPath = join3(aaDir, "env.disabled");
|
|
8221
|
+
const statePath = join3(aaDir, DISABLED_STATE_FILENAME);
|
|
8222
|
+
if (!existsSync5(envPath) && existsSync5(legacyDisabledPath)) {
|
|
8223
|
+
renameSync4(legacyDisabledPath, envPath);
|
|
7671
8224
|
console.log(source_default.green(`
|
|
7672
8225
|
✓ Restored ~/.agentapprove/env (legacy disable).`));
|
|
7673
8226
|
}
|
|
7674
8227
|
let stateRaw = null;
|
|
7675
8228
|
try {
|
|
7676
|
-
stateRaw =
|
|
8229
|
+
stateRaw = readFileSync3(statePath, "utf-8");
|
|
7677
8230
|
} catch {
|
|
7678
8231
|
stateRaw = null;
|
|
7679
8232
|
}
|
|
7680
8233
|
if (stateRaw === null) {
|
|
7681
|
-
if (
|
|
8234
|
+
if (existsSync5(envPath)) {
|
|
7682
8235
|
console.log(source_default.yellow(`
|
|
7683
8236
|
Already enabled.
|
|
7684
8237
|
`));
|
|
@@ -7689,7 +8242,7 @@ async function enableCommand() {
|
|
|
7689
8242
|
}
|
|
7690
8243
|
const state = parseDisabledState(stateRaw);
|
|
7691
8244
|
if (!state) {
|
|
7692
|
-
|
|
8245
|
+
rmSync3(statePath, { force: true });
|
|
7693
8246
|
console.log(source_default.yellow(`
|
|
7694
8247
|
The disable record was unreadable, so registrations were not restored automatically.`));
|
|
7695
8248
|
console.log(source_default.dim(" Run `npx agentapprove install` to re-register hooks and plugins (your pairing is kept).\n"));
|
|
@@ -7698,7 +8251,7 @@ async function enableCommand() {
|
|
|
7698
8251
|
console.log(source_default.cyan(`
|
|
7699
8252
|
Re-enabling Agent Approve...
|
|
7700
8253
|
`));
|
|
7701
|
-
const hooksDir =
|
|
8254
|
+
const hooksDir = join3(aaDir, "hooks");
|
|
7702
8255
|
const failures = [];
|
|
7703
8256
|
for (const record of state.agents) {
|
|
7704
8257
|
const agent = AGENTS[record.agentId];
|
|
@@ -7709,7 +8262,7 @@ async function enableCommand() {
|
|
|
7709
8262
|
}
|
|
7710
8263
|
switch (record.kind) {
|
|
7711
8264
|
case "hooks": {
|
|
7712
|
-
if (!
|
|
8265
|
+
if (!existsSync5(hooksDir)) {
|
|
7713
8266
|
failures.push(record);
|
|
7714
8267
|
console.log(` ${source_default.yellow("⚠")} ${agent.name}: ~/.agentapprove/hooks is missing. Run \`npx agentapprove install\` to re-download hook scripts.`);
|
|
7715
8268
|
break;
|
|
@@ -7717,6 +8270,8 @@ async function enableCommand() {
|
|
|
7717
8270
|
const result = await installHooksForAgent(record.agentId, hooksDir, state.mode);
|
|
7718
8271
|
if (result.success) {
|
|
7719
8272
|
console.log(` ${source_default.green("✓")} ${agent.name}: hooks re-registered`);
|
|
8273
|
+
if (result.note)
|
|
8274
|
+
console.log(source_default.dim(` ${result.note}`));
|
|
7720
8275
|
} else {
|
|
7721
8276
|
failures.push(record);
|
|
7722
8277
|
console.log(` ${source_default.yellow("⚠")} ${agent.name}: could not re-register hooks (${result.error || "unknown error"})`);
|
|
@@ -7724,20 +8279,28 @@ async function enableCommand() {
|
|
|
7724
8279
|
break;
|
|
7725
8280
|
}
|
|
7726
8281
|
case "vscode_hook_location": {
|
|
7727
|
-
const modifiedPaths = addToVSCodeHookLocations();
|
|
8282
|
+
const { modified: modifiedPaths, failed: failedSettings } = addToVSCodeHookLocations();
|
|
7728
8283
|
if (modifiedPaths.length > 0) {
|
|
7729
8284
|
console.log(` ${source_default.green("✓")} ${agent.name}: hook path re-registered in ${modifiedPaths.join(", ")}`);
|
|
7730
|
-
} else {
|
|
8285
|
+
} else if (failedSettings.length === 0) {
|
|
7731
8286
|
console.log(` ${source_default.green("✓")} ${agent.name}: hook path already registered`);
|
|
7732
8287
|
}
|
|
8288
|
+
if (failedSettings.length > 0) {
|
|
8289
|
+
failures.push(record);
|
|
8290
|
+
for (const failure of failedSettings) {
|
|
8291
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name} (${failure.variant}): could not re-register the hook path. ${failure.error}`);
|
|
8292
|
+
}
|
|
8293
|
+
}
|
|
7733
8294
|
break;
|
|
7734
8295
|
}
|
|
7735
8296
|
case "openclaw_entries": {
|
|
7736
|
-
if (!
|
|
8297
|
+
if (!existsSync5(agent.configPath)) {
|
|
7737
8298
|
console.log(` ${source_default.yellow("⚠")} ${agent.name}: config not found; skipping`);
|
|
7738
8299
|
break;
|
|
7739
8300
|
}
|
|
7740
|
-
const config =
|
|
8301
|
+
const config = readRestorableConfig(agent, record, failures);
|
|
8302
|
+
if (!config)
|
|
8303
|
+
break;
|
|
7741
8304
|
if (enableOpenClawEntries(config, record.entryKeys ?? [])) {
|
|
7742
8305
|
writeJsonConfig(agent.configPath, config);
|
|
7743
8306
|
}
|
|
@@ -7745,7 +8308,9 @@ async function enableCommand() {
|
|
|
7745
8308
|
break;
|
|
7746
8309
|
}
|
|
7747
8310
|
case "opencode_plugin": {
|
|
7748
|
-
const config =
|
|
8311
|
+
const config = readRestorableConfig(agent, record, failures);
|
|
8312
|
+
if (!config)
|
|
8313
|
+
break;
|
|
7749
8314
|
if (addOpenCodePluginEntries(config, record.specs ?? [])) {
|
|
7750
8315
|
writeJsonConfig(agent.configPath, config);
|
|
7751
8316
|
}
|
|
@@ -7756,7 +8321,9 @@ async function enableCommand() {
|
|
|
7756
8321
|
break;
|
|
7757
8322
|
}
|
|
7758
8323
|
case "pi_packages": {
|
|
7759
|
-
const settings =
|
|
8324
|
+
const settings = readRestorableConfig(agent, record, failures);
|
|
8325
|
+
if (!settings)
|
|
8326
|
+
break;
|
|
7760
8327
|
if (addPiPackageEntries(settings, record.specs ?? [])) {
|
|
7761
8328
|
writeJsonConfig(agent.configPath, settings);
|
|
7762
8329
|
}
|
|
@@ -7789,25 +8356,25 @@ async function enableCommand() {
|
|
|
7789
8356
|
}
|
|
7790
8357
|
if (failures.length > 0) {
|
|
7791
8358
|
const remaining = { ...state, agents: failures };
|
|
7792
|
-
|
|
7793
|
-
|
|
8359
|
+
writePrivateFile(statePath, JSON.stringify(remaining, null, 2) + `
|
|
8360
|
+
`);
|
|
7794
8361
|
console.log(source_default.yellow("\n Agent Approve is partially re-enabled. Fix the warnings above and re-run `npx agentapprove enable`.\n"));
|
|
7795
8362
|
return;
|
|
7796
8363
|
}
|
|
7797
|
-
|
|
8364
|
+
rmSync3(statePath, { force: true });
|
|
7798
8365
|
console.log(source_default.green(`
|
|
7799
8366
|
✓ Agent Approve enabled.
|
|
7800
8367
|
`));
|
|
7801
8368
|
}
|
|
7802
8369
|
function removeOpenCodeLegacyDependency() {
|
|
7803
|
-
const opencodePkgPath =
|
|
8370
|
+
const opencodePkgPath = join3(getOpenCodeConfigDir(), "package.json");
|
|
7804
8371
|
try {
|
|
7805
|
-
const pkgJson = JSON.parse(
|
|
8372
|
+
const pkgJson = JSON.parse(readFileSync3(opencodePkgPath, "utf-8"));
|
|
7806
8373
|
const deps = pkgJson.dependencies;
|
|
7807
8374
|
const version = deps?.["@agentapprove/opencode"];
|
|
7808
8375
|
if (deps && version) {
|
|
7809
8376
|
delete deps["@agentapprove/opencode"];
|
|
7810
|
-
|
|
8377
|
+
writeFileSync2(opencodePkgPath, JSON.stringify(pkgJson, null, 2) + `
|
|
7811
8378
|
`);
|
|
7812
8379
|
return version;
|
|
7813
8380
|
}
|
|
@@ -7815,17 +8382,18 @@ function removeOpenCodeLegacyDependency() {
|
|
|
7815
8382
|
return null;
|
|
7816
8383
|
}
|
|
7817
8384
|
function restoreOpenCodeLegacyDependency(version) {
|
|
7818
|
-
const opencodePkgPath =
|
|
7819
|
-
let pkgJson
|
|
8385
|
+
const opencodePkgPath = join3(getOpenCodeConfigDir(), "package.json");
|
|
8386
|
+
let pkgJson;
|
|
7820
8387
|
try {
|
|
7821
|
-
pkgJson =
|
|
7822
|
-
} catch {
|
|
7823
|
-
|
|
8388
|
+
pkgJson = readJsonConfig(opencodePkgPath);
|
|
8389
|
+
} catch (error) {
|
|
8390
|
+
console.log(` ${source_default.yellow("⚠")} OpenCode: the legacy plugin dependency was not restored. ${configErrorMessage(error)}`);
|
|
8391
|
+
return;
|
|
7824
8392
|
}
|
|
7825
8393
|
const deps = pkgJson.dependencies ?? {};
|
|
7826
8394
|
deps["@agentapprove/opencode"] = version;
|
|
7827
8395
|
pkgJson.dependencies = deps;
|
|
7828
|
-
|
|
8396
|
+
writeFileSync2(opencodePkgPath, JSON.stringify(pkgJson, null, 2) + `
|
|
7829
8397
|
`);
|
|
7830
8398
|
}
|
|
7831
8399
|
async function performUninstall(mode) {
|
|
@@ -7847,7 +8415,7 @@ async function performUninstall(mode) {
|
|
|
7847
8415
|
const result = removePiPluginViaCli();
|
|
7848
8416
|
if (result.success) {
|
|
7849
8417
|
console.log(` ${source_default.green("✓")} Pi extension removed`);
|
|
7850
|
-
} else if (
|
|
8418
|
+
} else if (existsSync5(agent.configPath)) {
|
|
7851
8419
|
console.log(` ${source_default.yellow("⚠")} Pi extension removal skipped or failed (${result.error || "Pi CLI unavailable"})`);
|
|
7852
8420
|
}
|
|
7853
8421
|
continue;
|
|
@@ -7864,9 +8432,15 @@ async function performUninstall(mode) {
|
|
|
7864
8432
|
}
|
|
7865
8433
|
continue;
|
|
7866
8434
|
}
|
|
7867
|
-
if (!
|
|
8435
|
+
if (!existsSync5(agent.configPath))
|
|
8436
|
+
continue;
|
|
8437
|
+
let config;
|
|
8438
|
+
try {
|
|
8439
|
+
config = readAgentConfig(agentId, agent.configPath);
|
|
8440
|
+
} catch (error) {
|
|
8441
|
+
console.log(` ${source_default.yellow("⚠")} ${agent.name}: ${configErrorMessage(error)}`);
|
|
7868
8442
|
continue;
|
|
7869
|
-
|
|
8443
|
+
}
|
|
7870
8444
|
const hooksConfig = agent.hooksKey === "" ? config : config[agent.hooksKey] ?? {};
|
|
7871
8445
|
let modified = false;
|
|
7872
8446
|
if (agentId === "opencode") {
|
|
@@ -7879,8 +8453,11 @@ async function performUninstall(mode) {
|
|
|
7879
8453
|
modified = removeAgentApproveHookEntries(hooksConfig, agent.hooks.map((hook) => hook.name));
|
|
7880
8454
|
}
|
|
7881
8455
|
if (modified) {
|
|
8456
|
+
const commentsNote = keepCommentedConfig(agentId, agent.configPath);
|
|
7882
8457
|
writeJsonConfig(agent.configPath, config);
|
|
7883
8458
|
console.log(` ${source_default.green("✓")} Removed hooks from ${agent.name}`);
|
|
8459
|
+
if (commentsNote)
|
|
8460
|
+
console.log(source_default.dim(` ${commentsNote}`));
|
|
7884
8461
|
}
|
|
7885
8462
|
if (agentId === "codex" && modified && Object.keys(hooksConfig).length === 0) {
|
|
7886
8463
|
const codexFlag = disableCodexFeatureFlag();
|
|
@@ -7889,7 +8466,9 @@ async function performUninstall(mode) {
|
|
|
7889
8466
|
}
|
|
7890
8467
|
}
|
|
7891
8468
|
}
|
|
7892
|
-
const removedVSCode = removeFromVSCodeHookLocations()
|
|
8469
|
+
const removedVSCode = removeFromVSCodeHookLocations((failure) => {
|
|
8470
|
+
console.log(` ${source_default.yellow("⚠")} ${failure.variant}: ${failure.error}`);
|
|
8471
|
+
});
|
|
7893
8472
|
if (removedVSCode.length > 0) {
|
|
7894
8473
|
for (const path of removedVSCode) {
|
|
7895
8474
|
console.log(` ${source_default.green("✓")} Removed hook path from ${path}`);
|
|
@@ -7901,16 +8480,16 @@ async function performUninstall(mode) {
|
|
|
7901
8480
|
}
|
|
7902
8481
|
console.log(` ${source_default.green("✓")} Removed plugin files at ${target.displayPath}`);
|
|
7903
8482
|
if (target.actualPath.endsWith("/node_modules/@agentapprove/opencode")) {
|
|
7904
|
-
pruneEmptyDir(
|
|
7905
|
-
pruneEmptyDir(
|
|
8483
|
+
pruneEmptyDir(dirname4(target.actualPath));
|
|
8484
|
+
pruneEmptyDir(dirname4(dirname4(target.actualPath)));
|
|
7906
8485
|
}
|
|
7907
8486
|
if (target.actualPath.includes("/extensions/")) {
|
|
7908
|
-
pruneEmptyDir(
|
|
8487
|
+
pruneEmptyDir(dirname4(target.actualPath));
|
|
7909
8488
|
}
|
|
7910
8489
|
}
|
|
7911
|
-
const disabledStatePath =
|
|
7912
|
-
if (
|
|
7913
|
-
|
|
8490
|
+
const disabledStatePath = join3(getAgentApproveDir(), DISABLED_STATE_FILENAME);
|
|
8491
|
+
if (existsSync5(disabledStatePath)) {
|
|
8492
|
+
rmSync3(disabledStatePath, { force: true });
|
|
7914
8493
|
console.log(` ${source_default.green("✓")} Removed the disable restore record (superseded by ${mode})`);
|
|
7915
8494
|
}
|
|
7916
8495
|
if (mode === "purge") {
|
|
@@ -7956,13 +8535,13 @@ async function restoreCommand() {
|
|
|
7956
8535
|
`));
|
|
7957
8536
|
const { readdirSync, copyFileSync } = await import("fs");
|
|
7958
8537
|
for (const [agentId, agent] of Object.entries(AGENTS)) {
|
|
7959
|
-
const configDir =
|
|
7960
|
-
if (!
|
|
8538
|
+
const configDir = dirname4(agent.configPath);
|
|
8539
|
+
if (!existsSync5(configDir))
|
|
7961
8540
|
continue;
|
|
7962
8541
|
const files = readdirSync(configDir);
|
|
7963
8542
|
const backups = files.filter((f) => f.startsWith(agent.configPath.split("/").pop()) && f.includes(".backup.")).sort().reverse();
|
|
7964
8543
|
if (backups.length > 0) {
|
|
7965
|
-
const latestBackup =
|
|
8544
|
+
const latestBackup = join3(configDir, backups[0]);
|
|
7966
8545
|
copyFileSync(latestBackup, agent.configPath);
|
|
7967
8546
|
console.log(` ${source_default.green("✓")} ${agent.name} restored from ${backups[0]}`);
|
|
7968
8547
|
}
|
|
@@ -7970,13 +8549,13 @@ async function restoreCommand() {
|
|
|
7970
8549
|
console.log();
|
|
7971
8550
|
}
|
|
7972
8551
|
async function initRepoCommand() {
|
|
7973
|
-
const cliHooksPath =
|
|
7974
|
-
if (
|
|
8552
|
+
const cliHooksPath = join3(getAgentApproveDir(), "copilot-cli-hooks.json");
|
|
8553
|
+
if (existsSync5(join3(getAgentApproveDir(), DISABLED_STATE_FILENAME))) {
|
|
7975
8554
|
console.log(source_default.yellow(`
|
|
7976
8555
|
Agent Approve is currently disabled. Hooks copied into this repo will be active.`));
|
|
7977
8556
|
console.log(source_default.dim(" Run `npx agentapprove enable` first if that is not what you want."));
|
|
7978
8557
|
}
|
|
7979
|
-
if (!
|
|
8558
|
+
if (!existsSync5(cliHooksPath)) {
|
|
7980
8559
|
console.log(source_default.yellow(`
|
|
7981
8560
|
GitHub Copilot CLI hooks not found. Run the installer first with GitHub Copilot CLI selected.`));
|
|
7982
8561
|
console.log(source_default.dim(` npx agentapprove install
|
|
@@ -7985,12 +8564,12 @@ async function initRepoCommand() {
|
|
|
7985
8564
|
}
|
|
7986
8565
|
let repoRoot = process.cwd();
|
|
7987
8566
|
let found = false;
|
|
7988
|
-
while (repoRoot !==
|
|
7989
|
-
if (
|
|
8567
|
+
while (repoRoot !== dirname4(repoRoot)) {
|
|
8568
|
+
if (existsSync5(join3(repoRoot, ".git"))) {
|
|
7990
8569
|
found = true;
|
|
7991
8570
|
break;
|
|
7992
8571
|
}
|
|
7993
|
-
repoRoot =
|
|
8572
|
+
repoRoot = dirname4(repoRoot);
|
|
7994
8573
|
}
|
|
7995
8574
|
if (!found) {
|
|
7996
8575
|
console.log(source_default.yellow(`
|
|
@@ -7998,12 +8577,12 @@ async function initRepoCommand() {
|
|
|
7998
8577
|
`));
|
|
7999
8578
|
process.exit(1);
|
|
8000
8579
|
}
|
|
8001
|
-
const targetDir =
|
|
8002
|
-
const targetFile =
|
|
8580
|
+
const targetDir = join3(repoRoot, ".github", "hooks");
|
|
8581
|
+
const targetFile = join3(targetDir, "agentapprove.json");
|
|
8003
8582
|
console.log(source_default.cyan(`
|
|
8004
8583
|
Installing GitHub Copilot CLI hooks to ${targetFile}
|
|
8005
8584
|
`));
|
|
8006
|
-
if (
|
|
8585
|
+
if (existsSync5(targetFile)) {
|
|
8007
8586
|
console.log(source_default.yellow(" agentapprove.json already exists in .github/hooks/"));
|
|
8008
8587
|
const overwrite = await ce({
|
|
8009
8588
|
message: "Overwrite existing file?"
|
|
@@ -8014,10 +8593,10 @@ async function initRepoCommand() {
|
|
|
8014
8593
|
process.exit(0);
|
|
8015
8594
|
}
|
|
8016
8595
|
}
|
|
8017
|
-
if (!
|
|
8018
|
-
|
|
8596
|
+
if (!existsSync5(targetDir)) {
|
|
8597
|
+
mkdirSync3(targetDir, { recursive: true });
|
|
8019
8598
|
}
|
|
8020
|
-
|
|
8599
|
+
copyFileSync2(cliHooksPath, targetFile);
|
|
8021
8600
|
console.log(source_default.green(` ✓ Copied GitHub Copilot CLI hooks to .github/hooks/agentapprove.json`));
|
|
8022
8601
|
console.log(source_default.dim(` Commit this file so Copilot coding agent uses your hooks.
|
|
8023
8602
|
`));
|
|
@@ -8079,14 +8658,14 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
|
|
|
8079
8658
|
let apiUrl = pairingApiBase;
|
|
8080
8659
|
const installedAgents = detectInstalledAgents();
|
|
8081
8660
|
const e2eEnabled = existingConfig.e2eEnabled !== false;
|
|
8082
|
-
const e2eKeyPath =
|
|
8661
|
+
const e2eKeyPath = join3(getAgentApproveDir(), "e2e-key");
|
|
8083
8662
|
let e2eUserKey = null;
|
|
8084
8663
|
let e2eKeyId;
|
|
8085
|
-
if (e2eEnabled &&
|
|
8086
|
-
const existingKey =
|
|
8664
|
+
if (e2eEnabled && existsSync5(e2eKeyPath)) {
|
|
8665
|
+
const existingKey = readFileSync3(e2eKeyPath, "utf-8").trim();
|
|
8087
8666
|
if (existingKey.length === 64) {
|
|
8088
8667
|
e2eUserKey = existingKey;
|
|
8089
|
-
e2eKeyId =
|
|
8668
|
+
e2eKeyId = createHash3("sha256").update(Buffer.from(existingKey, "hex")).digest("hex").slice(0, 8);
|
|
8090
8669
|
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.`);
|
|
8091
8670
|
}
|
|
8092
8671
|
} else {
|
|
@@ -8162,16 +8741,16 @@ but if unused for 30 days they expire. Get a new one below.`, "Token Expired");
|
|
|
8162
8741
|
});
|
|
8163
8742
|
await storeTokenInKeychain(token);
|
|
8164
8743
|
if (e2eEnabled && result.e2eServerKey) {
|
|
8165
|
-
const serverKeyPath =
|
|
8166
|
-
|
|
8744
|
+
const serverKeyPath = join3(getAgentApproveDir(), "e2e-server-key");
|
|
8745
|
+
writePrivateFile(serverKeyPath, result.e2eServerKey);
|
|
8167
8746
|
}
|
|
8168
8747
|
const updateSpinner = _2();
|
|
8169
|
-
updateSpinner.start("
|
|
8748
|
+
updateSpinner.start("Refreshing background activity filters");
|
|
8170
8749
|
try {
|
|
8171
|
-
await
|
|
8172
|
-
updateSpinner.stop("
|
|
8750
|
+
await refreshInstalledHooks(token, apiUrl);
|
|
8751
|
+
updateSpinner.stop("Hooks will use the new token on their next run");
|
|
8173
8752
|
} catch (error) {
|
|
8174
|
-
updateSpinner.stop("Warning: Could not
|
|
8753
|
+
updateSpinner.stop("Warning: Could not refresh the installed hooks");
|
|
8175
8754
|
v2.warn('You may need to run "npx agentapprove install" to reconfigure hooks.');
|
|
8176
8755
|
}
|
|
8177
8756
|
ge(source_default.green("Token refreshed successfully!"));
|
|
@@ -8209,17 +8788,17 @@ async function pairCommand() {
|
|
|
8209
8788
|
}
|
|
8210
8789
|
}
|
|
8211
8790
|
keyOptions.push({
|
|
8212
|
-
value:
|
|
8791
|
+
value: PAIR_KEY_GENERATE,
|
|
8213
8792
|
label: "Generate a new key",
|
|
8214
8793
|
hint: "creates a fresh key for this pairing"
|
|
8215
8794
|
});
|
|
8216
8795
|
keyOptions.push({
|
|
8217
|
-
value:
|
|
8796
|
+
value: PAIR_KEY_DISABLE,
|
|
8218
8797
|
label: "Disable E2E encryption",
|
|
8219
8798
|
hint: "events visible on web dashboard"
|
|
8220
8799
|
});
|
|
8221
8800
|
const skipE2E = hasFlag2("--no-e2e");
|
|
8222
|
-
const selectedKeyId = skipE2E ?
|
|
8801
|
+
const selectedKeyId = skipE2E ? PAIR_KEY_DISABLE : await le({
|
|
8223
8802
|
message: "Select an E2E key to pair with your iOS device",
|
|
8224
8803
|
options: keyOptions
|
|
8225
8804
|
});
|
|
@@ -8227,44 +8806,20 @@ async function pairCommand() {
|
|
|
8227
8806
|
he("Pairing cancelled");
|
|
8228
8807
|
process.exit(0);
|
|
8229
8808
|
}
|
|
8230
|
-
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
updateEnvValue("AGENTAPPROVE_E2E_ENABLED", "false");
|
|
8235
|
-
} else if (selectedKeyId === "__generate__") {
|
|
8236
|
-
const currentKey = keys.find((k) => k.isCurrent);
|
|
8237
|
-
if (currentKey) {
|
|
8238
|
-
const agentApproveDir = getAgentApproveDir();
|
|
8239
|
-
const backupPath = join(agentApproveDir, `e2e-key.${currentKey.keyId}.bak`);
|
|
8240
|
-
renameSync2(currentKey.path, backupPath);
|
|
8241
|
-
v2.info(`Previous key backed up (${currentKey.keyId})`);
|
|
8242
|
-
}
|
|
8243
|
-
e2eUserKey = randomBytes(32).toString("hex");
|
|
8244
|
-
e2eKeyId = createHash("sha256").update(Buffer.from(e2eUserKey, "hex")).digest("hex").slice(0, 8);
|
|
8245
|
-
const agentApproveDir = getAgentApproveDir();
|
|
8246
|
-
ensureAgentApproveDir();
|
|
8247
|
-
writeFileSync(join(agentApproveDir, "e2e-root-key"), e2eUserKey, { mode: 384 });
|
|
8248
|
-
writeFileSync(join(agentApproveDir, "e2e-key"), e2eUserKey, { mode: 384 });
|
|
8249
|
-
writeRotationConfig({
|
|
8250
|
-
rootKeyId: e2eKeyId,
|
|
8251
|
-
epoch: 0,
|
|
8252
|
-
periodSeconds: 0,
|
|
8253
|
-
startedAt: new Date().toISOString()
|
|
8254
|
-
});
|
|
8255
|
-
v2.success(`New key generated (${e2eKeyId})`);
|
|
8256
|
-
} else {
|
|
8257
|
-
const selectedKey = keys.find((k) => k.keyId === selectedKeyId);
|
|
8258
|
-
if (!selectedKey) {
|
|
8259
|
-
v2.error("Selected key not found.");
|
|
8260
|
-
process.exit(1);
|
|
8261
|
-
}
|
|
8262
|
-
e2eUserKey = selectedKey.keyHex;
|
|
8263
|
-
e2eKeyId = selectedKey.keyId;
|
|
8264
|
-
v2.info(`Using key ${e2eKeyId}${selectedKey.isCurrent ? " (current)" : " (backup)"}`);
|
|
8809
|
+
const keyPlan = planPairKey(selectedKeyId, keys, getAgentApproveDir(), () => randomBytes2(32).toString("hex"));
|
|
8810
|
+
if (keyPlan.kind === "not_found") {
|
|
8811
|
+
v2.error("Selected key not found.");
|
|
8812
|
+
process.exit(1);
|
|
8265
8813
|
}
|
|
8266
|
-
|
|
8267
|
-
|
|
8814
|
+
const e2eUserKey = keyPlan.e2eUserKey;
|
|
8815
|
+
const e2eKeyId = keyPlan.kind === "disable" ? undefined : keyPlan.e2eKeyId;
|
|
8816
|
+
if (keyPlan.kind === "disable") {
|
|
8817
|
+
v2.info("E2E encryption will be disabled when pairing completes. Event content will be visible on the web dashboard.");
|
|
8818
|
+
} else if (keyPlan.kind === "generate") {
|
|
8819
|
+
v2.info(`A new key (${e2eKeyId}) will be saved when pairing completes.`);
|
|
8820
|
+
} else {
|
|
8821
|
+
const selectedKey = keys.find((k) => k.keyId === keyPlan.e2eKeyId);
|
|
8822
|
+
v2.info(`Using key ${e2eKeyId}${selectedKey?.isCurrent ? " (current)" : " (backup)"}`);
|
|
8268
8823
|
}
|
|
8269
8824
|
const installedAgents = detectInstalledAgents();
|
|
8270
8825
|
const pairingConfigSetAt = Math.floor(Date.now() / 1000);
|
|
@@ -8313,24 +8868,17 @@ async function pairCommand() {
|
|
|
8313
8868
|
process.exit(1);
|
|
8314
8869
|
}
|
|
8315
8870
|
pairingSpinner.stop(`Paired! ${result.email ? `Account: ${result.email}` : ""}`);
|
|
8316
|
-
if (
|
|
8317
|
-
|
|
8318
|
-
|
|
8319
|
-
|
|
8320
|
-
}
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8324
|
-
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
});
|
|
8328
|
-
}
|
|
8329
|
-
if (result.e2eServerKey) {
|
|
8330
|
-
const serverKeyPath = join(getAgentApproveDir(), "e2e-server-key");
|
|
8331
|
-
writeFileSync(serverKeyPath, result.e2eServerKey, { mode: 384 });
|
|
8332
|
-
}
|
|
8333
|
-
}
|
|
8871
|
+
if (keyPlan.kind === "generate")
|
|
8872
|
+
ensureAgentApproveDir();
|
|
8873
|
+
const keyResult = applyPairKeyPlan(keyPlan, getAgentApproveDir(), {
|
|
8874
|
+
serverKey: result.e2eServerKey,
|
|
8875
|
+
rotation: { read: readRotationConfig, write: writeRotationConfig },
|
|
8876
|
+
now: () => new Date().toISOString()
|
|
8877
|
+
});
|
|
8878
|
+
if (keyResult.backedUp)
|
|
8879
|
+
v2.info(`Previous key backed up (${keyResult.backedUp})`);
|
|
8880
|
+
if (keyPlan.kind === "generate")
|
|
8881
|
+
v2.success(`New key saved (${e2eKeyId})`);
|
|
8334
8882
|
const apiUrl = result.apiUrl || pairingApiBase;
|
|
8335
8883
|
const configSetAt = Math.floor(Date.now() / 1000);
|
|
8336
8884
|
const pairPreservation = resolvePreservation({
|
|
@@ -8351,59 +8899,28 @@ async function pairCommand() {
|
|
|
8351
8899
|
preserved: pairPreservation.preserved
|
|
8352
8900
|
});
|
|
8353
8901
|
await storeTokenInKeychain(result.token);
|
|
8354
|
-
const hooksDir =
|
|
8355
|
-
if (
|
|
8902
|
+
const hooksDir = join3(getAgentApproveDir(), "hooks");
|
|
8903
|
+
if (existsSync5(hooksDir)) {
|
|
8356
8904
|
const updateSpinner = _2();
|
|
8357
|
-
updateSpinner.start("
|
|
8905
|
+
updateSpinner.start("Refreshing background activity filters");
|
|
8358
8906
|
try {
|
|
8359
|
-
await
|
|
8360
|
-
updateSpinner.stop("
|
|
8907
|
+
await refreshInstalledHooks(result.token, apiUrl);
|
|
8908
|
+
updateSpinner.stop("Hooks will use the new token on their next run");
|
|
8361
8909
|
} catch {
|
|
8362
|
-
updateSpinner.stop("Warning: Could not
|
|
8910
|
+
updateSpinner.stop("Warning: Could not refresh the installed hooks");
|
|
8363
8911
|
v2.warn('You may need to run "npx agentapprove install" to reconfigure hooks.');
|
|
8364
8912
|
}
|
|
8365
8913
|
}
|
|
8366
8914
|
ge(source_default.green(`Device paired with key ${e2eKeyId}`));
|
|
8367
8915
|
}
|
|
8368
|
-
async function
|
|
8369
|
-
const
|
|
8370
|
-
|
|
8371
|
-
|
|
8372
|
-
}
|
|
8373
|
-
|
|
8374
|
-
if (filters.failed.length || filters.terminalFailure) {
|
|
8916
|
+
async function refreshInstalledHooks(token, apiUrl) {
|
|
8917
|
+
const result = await refreshHooksAfterPairing(join3(getAgentApproveDir(), "hooks"), token, apiUrl, {
|
|
8918
|
+
filterFiles: BACKGROUND_FILTER_FILES,
|
|
8919
|
+
copyHookScripts: copyHookScripts2
|
|
8920
|
+
});
|
|
8921
|
+
if (!result.filtersRefreshed) {
|
|
8375
8922
|
v2.warn("Background activity filters could not be refreshed. The previous copy is retained.");
|
|
8376
8923
|
}
|
|
8377
|
-
const hookFiles = [
|
|
8378
|
-
"claude-pre-tool.sh",
|
|
8379
|
-
"claude-post-tool.sh",
|
|
8380
|
-
"claude-prompt.sh",
|
|
8381
|
-
"claude-session-start.sh",
|
|
8382
|
-
"claude-session-end.sh",
|
|
8383
|
-
"completion-hook.sh",
|
|
8384
|
-
"notify-hook.sh",
|
|
8385
|
-
"cursor-approval.sh",
|
|
8386
|
-
"cursor-mcp-approval.sh",
|
|
8387
|
-
"cursor-shell-complete.sh",
|
|
8388
|
-
"cursor-start.sh",
|
|
8389
|
-
"cursor-stop.sh",
|
|
8390
|
-
"cursor-thought.sh",
|
|
8391
|
-
"cursor-response.sh",
|
|
8392
|
-
"gemini-approval.sh",
|
|
8393
|
-
"gemini-complete.sh",
|
|
8394
|
-
"windsurf-hook.sh",
|
|
8395
|
-
"openhands-hook.sh",
|
|
8396
|
-
"antigravity-hook.sh"
|
|
8397
|
-
];
|
|
8398
|
-
for (const file of hookFiles) {
|
|
8399
|
-
const filePath = join(hooksDir, file);
|
|
8400
|
-
if (existsSync2(filePath)) {
|
|
8401
|
-
let content = readFileSync(filePath, "utf-8");
|
|
8402
|
-
content = content.replace(/export AGENTAPPROVE_TOKEN=".*"/, `export AGENTAPPROVE_TOKEN="${token}"`);
|
|
8403
|
-
content = content.replace(/export AGENTAPPROVE_API=".*"/, `export AGENTAPPROVE_API="${apiUrl}"`);
|
|
8404
|
-
writeFileSync(filePath, content, "utf-8");
|
|
8405
|
-
}
|
|
8406
|
-
}
|
|
8407
8924
|
}
|
|
8408
8925
|
async function main() {
|
|
8409
8926
|
const command = getCommand();
|