@integrity-labs/agt-cli 0.28.1250 → 0.28.1252
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/api-client-6A36YH3M.js +39 -0
- package/dist/bin/agt.js +17 -15
- package/dist/bin/agt.js.map +1 -1
- package/dist/{chunk-IUMFAYZO.js → chunk-3HRBU4H6.js} +3 -3
- package/dist/{chunk-SMD577FW.js → chunk-4VOQ6D7X.js} +2 -2
- package/dist/chunk-5ZNYCNMI.js +471 -0
- package/dist/chunk-5ZNYCNMI.js.map +1 -0
- package/dist/{chunk-DFJ5E5EW.js → chunk-RUKGOBVA.js} +214 -1
- package/dist/chunk-RUKGOBVA.js.map +1 -0
- package/dist/{chunk-5ALBA7KT.js → chunk-S3DUSCWR.js} +94 -552
- package/dist/chunk-S3DUSCWR.js.map +1 -0
- package/dist/{chunk-JOBL3ZF4.js → chunk-XTFVVZIR.js} +2 -2
- package/dist/{claude-code-updater-5MPOBIWN.js → claude-code-updater-WSQTK6TQ.js} +3 -3
- package/dist/{claude-pair-runtime-SNU3CU3K.js → claude-pair-runtime-WWF5BCK3.js} +3 -3
- package/dist/lib/manager-worker.js +172 -61
- package/dist/lib/manager-worker.js.map +1 -1
- package/dist/mcp/direct-chat-channel.js +92 -4
- package/dist/mcp/index.js +27 -0
- package/dist/mcp/origami.js +27 -0
- package/dist/mcp/slack-channel.js +27 -0
- package/dist/mcp/telegram-channel.js +389 -186
- package/dist/{persistent-session-SYCA6MW2.js → persistent-session-HS33PGZZ.js} +4 -4
- package/dist/persistent-session-HS33PGZZ.js.map +1 -0
- package/dist/{responsiveness-probe-BUXWVOSA.js → responsiveness-probe-32AWSVSL.js} +4 -4
- package/dist/{session-auth-dead-G5NHWSRP.js → session-auth-dead-2L2NLMMB.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-5ALBA7KT.js.map +0 -1
- package/dist/chunk-DFJ5E5EW.js.map +0 -1
- /package/dist/{claude-code-updater-5MPOBIWN.js.map → api-client-6A36YH3M.js.map} +0 -0
- /package/dist/{chunk-IUMFAYZO.js.map → chunk-3HRBU4H6.js.map} +0 -0
- /package/dist/{chunk-SMD577FW.js.map → chunk-4VOQ6D7X.js.map} +0 -0
- /package/dist/{chunk-JOBL3ZF4.js.map → chunk-XTFVVZIR.js.map} +0 -0
- /package/dist/{persistent-session-SYCA6MW2.js.map → claude-code-updater-WSQTK6TQ.js.map} +0 -0
- /package/dist/{claude-pair-runtime-SNU3CU3K.js.map → claude-pair-runtime-WWF5BCK3.js.map} +0 -0
- /package/dist/{responsiveness-probe-BUXWVOSA.js.map → responsiveness-probe-32AWSVSL.js.map} +0 -0
- /package/dist/{session-auth-dead-G5NHWSRP.js.map → session-auth-dead-2L2NLMMB.js.map} +0 -0
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
exchangeApiKey,
|
|
3
|
+
getApiKey,
|
|
4
|
+
getHost
|
|
5
|
+
} from "./chunk-5ZNYCNMI.js";
|
|
1
6
|
import {
|
|
2
7
|
LATE_BOUND_VARS,
|
|
3
8
|
PLATFORM_DENY_PERMISSIONS,
|
|
@@ -18,11 +23,11 @@ import {
|
|
|
18
23
|
requiresRemoteMcpToolGate,
|
|
19
24
|
shellQuote,
|
|
20
25
|
withheldRemoteMcpMessage
|
|
21
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-3HRBU4H6.js";
|
|
22
27
|
import {
|
|
23
28
|
readDailySessionPin,
|
|
24
29
|
sessionTranscriptDir
|
|
25
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-4VOQ6D7X.js";
|
|
26
31
|
import {
|
|
27
32
|
classifyUnanswerablePane,
|
|
28
33
|
isConsumerTermsDialogVisible,
|
|
@@ -34,7 +39,6 @@ import {
|
|
|
34
39
|
} from "./chunk-XWVM4KPK.js";
|
|
35
40
|
import {
|
|
36
41
|
BIND_FAILURE_QUARANTINE_THRESHOLD,
|
|
37
|
-
HOST_ROTATE_KEY_CONFLICT,
|
|
38
42
|
INTEGRATIONS_SECTION_END,
|
|
39
43
|
INTEGRATIONS_SECTION_START,
|
|
40
44
|
INTEGRATION_REGISTRY,
|
|
@@ -95,7 +99,7 @@ import {
|
|
|
95
99
|
scanConfigForLiteralSecrets,
|
|
96
100
|
worseConnectivityOutcome,
|
|
97
101
|
wrapScheduledTaskPrompt
|
|
98
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-RUKGOBVA.js";
|
|
99
103
|
import {
|
|
100
104
|
claudeJsonPathFor,
|
|
101
105
|
effectiveClaudeJsonPath,
|
|
@@ -8049,462 +8053,20 @@ function jsonOutput(data) {
|
|
|
8049
8053
|
console.log(JSON.stringify(data, null, 2));
|
|
8050
8054
|
}
|
|
8051
8055
|
|
|
8052
|
-
// src/lib/config.ts
|
|
8053
|
-
import { readFileSync as readFileSync6, writeFileSync as writeFileSync6, mkdirSync as mkdirSync5, existsSync as existsSync5 } from "fs";
|
|
8054
|
-
import { join as join6 } from "path";
|
|
8055
|
-
import { homedir as homedir4 } from "os";
|
|
8056
|
-
var AUGMENTED_DIR = join6(homedir4(), ".augmented");
|
|
8057
|
-
var CONFIG_PATH = join6(AUGMENTED_DIR, "config.json");
|
|
8058
|
-
function ensureAugmentedDir() {
|
|
8059
|
-
if (!existsSync5(AUGMENTED_DIR)) {
|
|
8060
|
-
mkdirSync5(AUGMENTED_DIR, { recursive: true });
|
|
8061
|
-
}
|
|
8062
|
-
}
|
|
8063
|
-
function reloadFromShellProfile() {
|
|
8064
|
-
return loadFromShellProfile(true);
|
|
8065
|
-
}
|
|
8066
|
-
function loadFromShellProfile(force = false) {
|
|
8067
|
-
if (!force && process.env["AGT_HOST"] && process.env["AGT_API_KEY"]) return;
|
|
8068
|
-
const shell = process.env["SHELL"] ?? "";
|
|
8069
|
-
const home = homedir4();
|
|
8070
|
-
const candidates = shell.includes("zsh") ? [join6(home, ".zshrc"), join6(home, ".zprofile")] : shell.includes("fish") ? [join6(home, ".config", "fish", "config.fish")] : [join6(home, ".bashrc"), join6(home, ".bash_profile")];
|
|
8071
|
-
for (const profile of candidates) {
|
|
8072
|
-
try {
|
|
8073
|
-
const content = readFileSync6(profile, "utf-8");
|
|
8074
|
-
for (const key of ["AGT_HOST", "AGT_API_KEY", "AGT_TEAM"]) {
|
|
8075
|
-
if (!force && process.env[key]) continue;
|
|
8076
|
-
const match = content.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#")).map(
|
|
8077
|
-
(line) => line.match(
|
|
8078
|
-
new RegExp(
|
|
8079
|
-
`^(?:export\\s+${key}\\s*=\\s*["']([^"']+)["']|set\\s+-gx\\s+${key}\\s+["']([^"']+)["'])$`
|
|
8080
|
-
)
|
|
8081
|
-
)
|
|
8082
|
-
).find(Boolean);
|
|
8083
|
-
if (match) {
|
|
8084
|
-
process.env[key] = match[1] ?? match[2];
|
|
8085
|
-
}
|
|
8086
|
-
}
|
|
8087
|
-
} catch {
|
|
8088
|
-
}
|
|
8089
|
-
if (process.env["AGT_HOST"] && process.env["AGT_API_KEY"]) break;
|
|
8090
|
-
}
|
|
8091
|
-
}
|
|
8092
|
-
loadFromShellProfile();
|
|
8093
|
-
function getApiKey() {
|
|
8094
|
-
return process.env["AGT_API_KEY"] ?? null;
|
|
8095
|
-
}
|
|
8096
|
-
function getConfig() {
|
|
8097
|
-
try {
|
|
8098
|
-
const raw = readFileSync6(CONFIG_PATH, "utf-8");
|
|
8099
|
-
return JSON.parse(raw);
|
|
8100
|
-
} catch {
|
|
8101
|
-
return {};
|
|
8102
|
-
}
|
|
8103
|
-
}
|
|
8104
|
-
function saveConfig(config) {
|
|
8105
|
-
ensureAugmentedDir();
|
|
8106
|
-
writeFileSync6(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
8107
|
-
}
|
|
8108
|
-
function getActiveTeam() {
|
|
8109
|
-
const envTeam = process.env["AGT_TEAM"];
|
|
8110
|
-
if (envTeam) return envTeam;
|
|
8111
|
-
return getConfig().active_team;
|
|
8112
|
-
}
|
|
8113
|
-
function setActiveTeam(slug) {
|
|
8114
|
-
const config = getConfig();
|
|
8115
|
-
config.active_team = slug;
|
|
8116
|
-
saveConfig(config);
|
|
8117
|
-
}
|
|
8118
|
-
var PROD_AGT_HOST = "https://api.augmented.team";
|
|
8119
|
-
var AGT_HOST_UNSET_MESSAGE = "AGT_HOST is not set. Set it to the API URL for your stage before running this command:\n Production: export AGT_HOST=https://api.augmented.team\n Non-prod stage: export AGT_HOST=https://<stage>.api.staging.augmented.team\n Local development: export AGT_HOST=http://api.agt.localhost:1355\n\nFor first-time host setup, pass --api-host <url> to `agt setup` instead \u2014 the setup command does NOT silently default to prod (ENG-5831).";
|
|
8120
|
-
function getHost() {
|
|
8121
|
-
const envHost = process.env["AGT_HOST"]?.trim();
|
|
8122
|
-
if (!envHost) {
|
|
8123
|
-
throw new Error(AGT_HOST_UNSET_MESSAGE);
|
|
8124
|
-
}
|
|
8125
|
-
return envHost;
|
|
8126
|
-
}
|
|
8127
|
-
function requireHost() {
|
|
8128
|
-
return getHost();
|
|
8129
|
-
}
|
|
8130
|
-
|
|
8131
|
-
// src/lib/auth-exchange-error.ts
|
|
8132
|
-
var ApiKeyExchangeError = class extends Error {
|
|
8133
|
-
constructor(message, status, transient) {
|
|
8134
|
-
super(message);
|
|
8135
|
-
this.status = status;
|
|
8136
|
-
this.transient = transient;
|
|
8137
|
-
this.name = "ApiKeyExchangeError";
|
|
8138
|
-
}
|
|
8139
|
-
};
|
|
8140
|
-
function isTransientExchangeStatus(status) {
|
|
8141
|
-
return status >= 500 || status === 429;
|
|
8142
|
-
}
|
|
8143
|
-
function isTransientAuthFailure(err) {
|
|
8144
|
-
return err instanceof ApiKeyExchangeError && err.transient;
|
|
8145
|
-
}
|
|
8146
|
-
function exchangeFailureKind(err) {
|
|
8147
|
-
if (!(err instanceof ApiKeyExchangeError)) return "unclassified";
|
|
8148
|
-
const status = err.status === null ? "transport" : String(err.status);
|
|
8149
|
-
return err.transient ? `transient-${status}` : `verdict-${status}`;
|
|
8150
|
-
}
|
|
8151
|
-
|
|
8152
|
-
// src/lib/api-client.ts
|
|
8153
|
-
var agtCliVersion = true ? "0.28.1250" : "dev";
|
|
8154
|
-
var lastConfigHash = null;
|
|
8155
|
-
function setConfigHash(hash) {
|
|
8156
|
-
lastConfigHash = hash && hash.length > 0 ? hash : null;
|
|
8157
|
-
}
|
|
8158
|
-
var cachedExchange = null;
|
|
8159
|
-
var exchangeInFlight = null;
|
|
8160
|
-
var exchangeForceCount = 0;
|
|
8161
|
-
var consumedExchangeForceCount = 0;
|
|
8162
|
-
function forceNextExchange() {
|
|
8163
|
-
exchangeForceCount += 1;
|
|
8164
|
-
}
|
|
8165
|
-
function getCachedClaudeAuthMode() {
|
|
8166
|
-
return cachedExchange?.claudeAuthMode ?? null;
|
|
8167
|
-
}
|
|
8168
|
-
function getCachedClaudeAuthModeRaw() {
|
|
8169
|
-
return cachedExchange?.claudeAuthModeRaw ?? null;
|
|
8170
|
-
}
|
|
8171
|
-
function invalidateExchange() {
|
|
8172
|
-
cachedExchange = null;
|
|
8173
|
-
lastConfigHash = null;
|
|
8174
|
-
}
|
|
8175
|
-
async function exchangeApiKey(rawKey, retried = false, opts = {}) {
|
|
8176
|
-
const withinMaxAge = opts.maxAgeMs === void 0 || cachedExchange !== null && Date.now() - cachedExchange.fetchedAt < opts.maxAgeMs;
|
|
8177
|
-
const forcePending = exchangeForceCount > consumedExchangeForceCount;
|
|
8178
|
-
if (!opts.forceRefresh && !forcePending && withinMaxAge && cachedExchange && Date.now() < cachedExchange.expiresAt - 6e4) {
|
|
8179
|
-
return {
|
|
8180
|
-
token: cachedExchange.token,
|
|
8181
|
-
hostId: cachedExchange.hostId,
|
|
8182
|
-
teamId: cachedExchange.teamId,
|
|
8183
|
-
teamSlug: cachedExchange.teamSlug,
|
|
8184
|
-
framework: cachedExchange.framework,
|
|
8185
|
-
hostKind: cachedExchange.hostKind,
|
|
8186
|
-
claudeAuthMode: cachedExchange.claudeAuthMode,
|
|
8187
|
-
claudeAuthModeRaw: cachedExchange.claudeAuthModeRaw,
|
|
8188
|
-
anthropicApiKeyFingerprint: cachedExchange.anthropicApiKeyFingerprint,
|
|
8189
|
-
anthropicApiKey: cachedExchange.anthropicApiKey,
|
|
8190
|
-
userEmail: cachedExchange.userEmail,
|
|
8191
|
-
supabaseUrl: cachedExchange.supabaseUrl,
|
|
8192
|
-
supabaseAnonKey: cachedExchange.supabaseAnonKey
|
|
8193
|
-
};
|
|
8194
|
-
}
|
|
8195
|
-
const observedForceCount = exchangeForceCount;
|
|
8196
|
-
if (exchangeInFlight) {
|
|
8197
|
-
return exchangeInFlight;
|
|
8198
|
-
}
|
|
8199
|
-
exchangeInFlight = doExchange(rawKey, retried);
|
|
8200
|
-
try {
|
|
8201
|
-
const result = await exchangeInFlight;
|
|
8202
|
-
consumedExchangeForceCount = observedForceCount;
|
|
8203
|
-
return result;
|
|
8204
|
-
} finally {
|
|
8205
|
-
exchangeInFlight = null;
|
|
8206
|
-
}
|
|
8207
|
-
}
|
|
8208
|
-
var DEFAULT_EXCHANGE_RETRY_ATTEMPTS = 2;
|
|
8209
|
-
var DEFAULT_EXCHANGE_RETRY_BASE_MS = 500;
|
|
8210
|
-
function exchangeRetryAttempts() {
|
|
8211
|
-
const raw = process.env["AGT_AUTH_EXCHANGE_RETRY_ATTEMPTS"];
|
|
8212
|
-
const parsed = raw ? parseInt(raw, 10) : NaN;
|
|
8213
|
-
if (Number.isFinite(parsed) && parsed >= 0) return Math.min(parsed, 5);
|
|
8214
|
-
return DEFAULT_EXCHANGE_RETRY_ATTEMPTS;
|
|
8215
|
-
}
|
|
8216
|
-
function exchangeRetryBaseMs() {
|
|
8217
|
-
const raw = process.env["AGT_AUTH_EXCHANGE_RETRY_BASE_MS"];
|
|
8218
|
-
const parsed = raw ? parseInt(raw, 10) : NaN;
|
|
8219
|
-
if (Number.isFinite(parsed) && parsed > 0) return Math.min(parsed, 5e3);
|
|
8220
|
-
return DEFAULT_EXCHANGE_RETRY_BASE_MS;
|
|
8221
|
-
}
|
|
8222
|
-
function asExchangeError(err) {
|
|
8223
|
-
if (err instanceof ApiKeyExchangeError) return err;
|
|
8224
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
8225
|
-
return new ApiKeyExchangeError(message, null, true);
|
|
8226
|
-
}
|
|
8227
|
-
async function doExchange(rawKey, retried) {
|
|
8228
|
-
const maxRetries = exchangeRetryAttempts();
|
|
8229
|
-
const baseMs = exchangeRetryBaseMs();
|
|
8230
|
-
let lastErr;
|
|
8231
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
8232
|
-
try {
|
|
8233
|
-
return await attemptExchange(rawKey, retried);
|
|
8234
|
-
} catch (err) {
|
|
8235
|
-
const exchangeErr = asExchangeError(err);
|
|
8236
|
-
if (!exchangeErr.transient || attempt === maxRetries) throw exchangeErr;
|
|
8237
|
-
lastErr = exchangeErr;
|
|
8238
|
-
await new Promise((resolve) => setTimeout(resolve, baseMs * 2 ** attempt));
|
|
8239
|
-
}
|
|
8240
|
-
}
|
|
8241
|
-
throw lastErr ?? new ApiKeyExchangeError("API key exchange failed", null, true);
|
|
8242
|
-
}
|
|
8243
|
-
async function attemptExchange(rawKey, retried) {
|
|
8244
|
-
const res = await fetch(`${requireHost()}/host/exchange`, {
|
|
8245
|
-
method: "POST",
|
|
8246
|
-
headers: { "Content-Type": "application/json" },
|
|
8247
|
-
body: JSON.stringify({ host_key: rawKey })
|
|
8248
|
-
});
|
|
8249
|
-
if (!res.ok) {
|
|
8250
|
-
const body = await res.json().catch(() => ({}));
|
|
8251
|
-
const errorMsg = String(body["error"] ?? res.statusText);
|
|
8252
|
-
const host = requireHost();
|
|
8253
|
-
const obfuscated = rawKey.length > 12 ? `${rawKey.slice(0, 8)}${"*".repeat(rawKey.length - 12)}${rawKey.slice(-4)}` : rawKey.slice(0, 4) + "****";
|
|
8254
|
-
if (res.status >= 502 && res.status <= 504) {
|
|
8255
|
-
throw new ApiKeyExchangeError(
|
|
8256
|
-
`API unreachable (${res.status}): ${host} \u2014 is the API server running?`,
|
|
8257
|
-
res.status,
|
|
8258
|
-
true
|
|
8259
|
-
);
|
|
8260
|
-
}
|
|
8261
|
-
if (errorMsg.includes("revoked") && !retried) {
|
|
8262
|
-
reloadFromShellProfile();
|
|
8263
|
-
const freshKey = getApiKey();
|
|
8264
|
-
if (freshKey && freshKey !== rawKey) {
|
|
8265
|
-
return attemptExchange(freshKey, true);
|
|
8266
|
-
}
|
|
8267
|
-
}
|
|
8268
|
-
throw new ApiKeyExchangeError(
|
|
8269
|
-
`API key exchange failed: ${errorMsg} (host=${host}, key=${obfuscated})`,
|
|
8270
|
-
res.status,
|
|
8271
|
-
isTransientExchangeStatus(res.status)
|
|
8272
|
-
);
|
|
8273
|
-
}
|
|
8274
|
-
const data = await res.json();
|
|
8275
|
-
if (!data.token) {
|
|
8276
|
-
throw new ApiKeyExchangeError("API key exchange returned no token", null, true);
|
|
8277
|
-
}
|
|
8278
|
-
const claudeAuthMode = data.claude_auth_mode === "api_key" ? "api_key" : data.claude_auth_mode === "openrouter" ? "openrouter" : "subscription";
|
|
8279
|
-
const claudeAuthModeRaw = data.claude_auth_mode ?? null;
|
|
8280
|
-
cachedExchange = {
|
|
8281
|
-
token: data.token,
|
|
8282
|
-
hostId: data.host_id,
|
|
8283
|
-
teamId: data.team_id,
|
|
8284
|
-
teamSlug: data.team_slug,
|
|
8285
|
-
framework: data.framework ?? null,
|
|
8286
|
-
hostKind: data.host_kind ?? null,
|
|
8287
|
-
claudeAuthMode,
|
|
8288
|
-
claudeAuthModeRaw,
|
|
8289
|
-
anthropicApiKeyFingerprint: data.anthropic_api_key_fingerprint ?? null,
|
|
8290
|
-
anthropicApiKey: data.anthropic_api_key ?? null,
|
|
8291
|
-
userEmail: data.user_email,
|
|
8292
|
-
supabaseUrl: data.supabase_url,
|
|
8293
|
-
supabaseAnonKey: data.supabase_anon_key,
|
|
8294
|
-
expiresAt: new Date(data.expires_at).getTime(),
|
|
8295
|
-
fetchedAt: Date.now()
|
|
8296
|
-
};
|
|
8297
|
-
return {
|
|
8298
|
-
token: data.token,
|
|
8299
|
-
hostId: data.host_id,
|
|
8300
|
-
teamId: data.team_id,
|
|
8301
|
-
teamSlug: data.team_slug,
|
|
8302
|
-
framework: data.framework ?? null,
|
|
8303
|
-
hostKind: data.host_kind ?? null,
|
|
8304
|
-
claudeAuthMode,
|
|
8305
|
-
claudeAuthModeRaw,
|
|
8306
|
-
anthropicApiKeyFingerprint: data.anthropic_api_key_fingerprint ?? null,
|
|
8307
|
-
anthropicApiKey: data.anthropic_api_key ?? null,
|
|
8308
|
-
userEmail: data.user_email,
|
|
8309
|
-
supabaseUrl: data.supabase_url,
|
|
8310
|
-
supabaseAnonKey: data.supabase_anon_key
|
|
8311
|
-
};
|
|
8312
|
-
}
|
|
8313
|
-
async function mintAgentKey(rawHostKey, agentId) {
|
|
8314
|
-
const res = await fetch(`${requireHost()}/host/agent-key`, {
|
|
8315
|
-
method: "POST",
|
|
8316
|
-
headers: { "Content-Type": "application/json" },
|
|
8317
|
-
body: JSON.stringify({ host_key: rawHostKey, agent_id: agentId })
|
|
8318
|
-
});
|
|
8319
|
-
if (!res.ok) {
|
|
8320
|
-
const body = await res.json().catch(() => ({}));
|
|
8321
|
-
const errorMsg = String(body["error"] ?? res.statusText);
|
|
8322
|
-
throw new Error(`Per-agent key mint failed (${res.status}) for agent=${agentId}: ${errorMsg}`);
|
|
8323
|
-
}
|
|
8324
|
-
const data = await res.json();
|
|
8325
|
-
if (!data.agent_key) {
|
|
8326
|
-
throw new Error(`Per-agent key mint returned no key for agent=${agentId}`);
|
|
8327
|
-
}
|
|
8328
|
-
return data.agent_key;
|
|
8329
|
-
}
|
|
8330
|
-
async function mintRotatedHostKey(rawHostKey) {
|
|
8331
|
-
const res = await fetch(`${requireHost()}/host/rotate-key`, {
|
|
8332
|
-
method: "POST",
|
|
8333
|
-
headers: { "Content-Type": "application/json" },
|
|
8334
|
-
body: JSON.stringify({ host_key: rawHostKey }),
|
|
8335
|
-
// BOUNDED, because this await is now on the poll cycle's critical path
|
|
8336
|
-
// (CodeRabbit on #7114). The rotation moved onto the heartbeat handler,
|
|
8337
|
-
// which `pollCycleInner` awaits, so an unanswered mint blocks the Claude
|
|
8338
|
-
// Code updater, the responsiveness probe, the wedge and pane-fatal checks,
|
|
8339
|
-
// the /host/agents fetch and every per-agent `processAgent` for as long as
|
|
8340
|
-
// it hangs — and Node's built-in fetch waits 300s by default. The
|
|
8341
|
-
// 5-minute retry backoff would then re-arm the same stall. 10s matches the
|
|
8342
|
-
// other short calls in this process (`telegram-ingest.ts`). A timeout
|
|
8343
|
-
// surfaces as a thrown error, which `adoptRotatedHostKey` reports as
|
|
8344
|
-
// `error` and the manager retries after the backoff. The abort cancels the
|
|
8345
|
-
// client, not the route, so the key may already be minted and recorded;
|
|
8346
|
-
// a lost response after the commit is the same case. The retry still
|
|
8347
|
-
// works: the server discards a minted key nobody has ever authenticated
|
|
8348
|
-
// with once it is older than HOST_SELF_ROTATION_STALE_MINT_MS, which is
|
|
8349
|
-
// shorter than the backoff, and mints again (ENG-11826; it used to need a
|
|
8350
|
-
// `compromised` rotation, Obi Wan `9b564171021b` on #7114). That covers
|
|
8351
|
-
// the backoff retry; a manager that restarts inside the window gets
|
|
8352
|
-
// `mint_pending`, which this version retries and older versions do not.
|
|
8353
|
-
signal: AbortSignal.timeout(1e4)
|
|
8354
|
-
});
|
|
8355
|
-
if (res.status === 403) {
|
|
8356
|
-
return null;
|
|
8357
|
-
}
|
|
8358
|
-
if (res.status === 409) {
|
|
8359
|
-
const body = await res.json().catch(() => ({}));
|
|
8360
|
-
if (body["code"] === HOST_ROTATE_KEY_CONFLICT.mintPending) {
|
|
8361
|
-
throw new Error(`Host key rotation mint deferred: ${String(body["error"] ?? "a mint is in flight")}`);
|
|
8362
|
-
}
|
|
8363
|
-
if (body["code"] === HOST_ROTATE_KEY_CONFLICT.alreadyHoldsMintedKey && typeof body["prefix"] === "string" && body["prefix"]) {
|
|
8364
|
-
return { alreadyHolds: body["prefix"] };
|
|
8365
|
-
}
|
|
8366
|
-
return { refused: String(body["error"] ?? "conflict") };
|
|
8367
|
-
}
|
|
8368
|
-
if (!res.ok) {
|
|
8369
|
-
const body = await res.json().catch(() => ({}));
|
|
8370
|
-
throw new Error(`Host key rotation mint failed (${res.status}): ${String(body["error"] ?? res.statusText)}`);
|
|
8371
|
-
}
|
|
8372
|
-
const data = await res.json();
|
|
8373
|
-
const prefix = data.key?.prefix;
|
|
8374
|
-
const rawKey = data.key?.raw_key;
|
|
8375
|
-
if (!prefix || !rawKey) return null;
|
|
8376
|
-
return { prefix, rawKey };
|
|
8377
|
-
}
|
|
8378
|
-
async function probeHostKey(rawKey) {
|
|
8379
|
-
let res;
|
|
8380
|
-
try {
|
|
8381
|
-
res = await fetch(`${requireHost()}/host/exchange`, {
|
|
8382
|
-
method: "POST",
|
|
8383
|
-
headers: { "Content-Type": "application/json" },
|
|
8384
|
-
body: JSON.stringify({ host_key: rawKey }),
|
|
8385
|
-
// Same bound as the mint, for the same reason: it runs on the poll cycle.
|
|
8386
|
-
signal: AbortSignal.timeout(1e4)
|
|
8387
|
-
});
|
|
8388
|
-
} catch {
|
|
8389
|
-
return "unknown";
|
|
8390
|
-
}
|
|
8391
|
-
if (res.ok) return "live";
|
|
8392
|
-
if (res.status === 401) {
|
|
8393
|
-
const body = await res.json().catch(() => ({}));
|
|
8394
|
-
if (body["code"] === "key_revoked" || body["code"] === "invalid_key" || body["code"] === "key_expired") {
|
|
8395
|
-
return "unusable";
|
|
8396
|
-
}
|
|
8397
|
-
}
|
|
8398
|
-
return "unknown";
|
|
8399
|
-
}
|
|
8400
|
-
function adoptHostKeyInProcess(rawKey) {
|
|
8401
|
-
process.env["AGT_API_KEY"] = rawKey;
|
|
8402
|
-
forceNextExchange();
|
|
8403
|
-
}
|
|
8404
|
-
async function resolveAuth() {
|
|
8405
|
-
const apiKey = getApiKey();
|
|
8406
|
-
if (!apiKey) {
|
|
8407
|
-
throw new Error("AGT_API_KEY is not set. Export it with your host API key (tlk_...)");
|
|
8408
|
-
}
|
|
8409
|
-
const exchange = await exchangeApiKey(apiKey);
|
|
8410
|
-
return { token: exchange.token, hostId: exchange.hostId };
|
|
8411
|
-
}
|
|
8412
|
-
async function buildHeaders() {
|
|
8413
|
-
const apiKey = getApiKey();
|
|
8414
|
-
if (!apiKey) {
|
|
8415
|
-
throw new Error("AGT_API_KEY is not set. Export it with your host API key (tlk_...)");
|
|
8416
|
-
}
|
|
8417
|
-
const exchange = await exchangeApiKey(apiKey);
|
|
8418
|
-
const headers = {
|
|
8419
|
-
"Authorization": `Bearer ${exchange.token}`,
|
|
8420
|
-
"Content-Type": "application/json",
|
|
8421
|
-
// ENG-6410: lets the API stamp audit_log.agt_cli_version for host-runtime
|
|
8422
|
-
// actions so bug rates can be tracked per CLI version.
|
|
8423
|
-
"X-Agt-Cli-Version": agtCliVersion
|
|
8424
|
-
};
|
|
8425
|
-
if (lastConfigHash) {
|
|
8426
|
-
headers["X-Config-Hash"] = lastConfigHash;
|
|
8427
|
-
}
|
|
8428
|
-
const team = getActiveTeam() ?? exchange.teamSlug;
|
|
8429
|
-
if (team) {
|
|
8430
|
-
headers["X-Team-Slug"] = team;
|
|
8431
|
-
}
|
|
8432
|
-
return headers;
|
|
8433
|
-
}
|
|
8434
|
-
var ApiError = class extends Error {
|
|
8435
|
-
constructor(status, body) {
|
|
8436
|
-
super(body["error"] ?? `HTTP ${status}`);
|
|
8437
|
-
this.status = status;
|
|
8438
|
-
this.body = body;
|
|
8439
|
-
this.name = "ApiError";
|
|
8440
|
-
}
|
|
8441
|
-
};
|
|
8442
|
-
async function fetchWithRetry(path, method, body, extraHeaders) {
|
|
8443
|
-
const baseHeaders = await buildHeaders();
|
|
8444
|
-
const headers = extraHeaders ? { ...baseHeaders, ...extraHeaders } : baseHeaders;
|
|
8445
|
-
const url = `${requireHost()}${path}`;
|
|
8446
|
-
const init = {
|
|
8447
|
-
method,
|
|
8448
|
-
headers,
|
|
8449
|
-
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
8450
|
-
};
|
|
8451
|
-
const res = await fetch(url, init);
|
|
8452
|
-
if (res.status === 401) {
|
|
8453
|
-
invalidateExchange();
|
|
8454
|
-
const freshBase = await buildHeaders();
|
|
8455
|
-
const freshHeaders = extraHeaders ? { ...freshBase, ...extraHeaders } : freshBase;
|
|
8456
|
-
return fetch(url, { ...init, headers: freshHeaders });
|
|
8457
|
-
}
|
|
8458
|
-
return res;
|
|
8459
|
-
}
|
|
8460
|
-
async function handleResponse(res) {
|
|
8461
|
-
const body = await res.json().catch(() => ({}));
|
|
8462
|
-
if (!res.ok) {
|
|
8463
|
-
throw new ApiError(res.status, body);
|
|
8464
|
-
}
|
|
8465
|
-
return body;
|
|
8466
|
-
}
|
|
8467
|
-
var api = {
|
|
8468
|
-
async get(path) {
|
|
8469
|
-
const res = await fetchWithRetry(path, "GET");
|
|
8470
|
-
return handleResponse(res);
|
|
8471
|
-
},
|
|
8472
|
-
async post(path, body, extraHeaders) {
|
|
8473
|
-
const res = await fetchWithRetry(path, "POST", body, extraHeaders);
|
|
8474
|
-
return handleResponse(res);
|
|
8475
|
-
},
|
|
8476
|
-
async patch(path, body) {
|
|
8477
|
-
const res = await fetchWithRetry(path, "PATCH", body);
|
|
8478
|
-
return handleResponse(res);
|
|
8479
|
-
},
|
|
8480
|
-
async put(path, body) {
|
|
8481
|
-
const res = await fetchWithRetry(path, "PUT", body);
|
|
8482
|
-
return handleResponse(res);
|
|
8483
|
-
},
|
|
8484
|
-
async del(path) {
|
|
8485
|
-
const res = await fetchWithRetry(path, "DELETE");
|
|
8486
|
-
return handleResponse(res);
|
|
8487
|
-
}
|
|
8488
|
-
};
|
|
8489
|
-
async function getHostId() {
|
|
8490
|
-
const { hostId } = await resolveAuth();
|
|
8491
|
-
return hostId;
|
|
8492
|
-
}
|
|
8493
|
-
|
|
8494
8056
|
// src/lib/atomic-write.ts
|
|
8495
|
-
import { closeSync, fchmodSync, fchownSync, fsyncSync, openSync,
|
|
8057
|
+
import { closeSync, fchmodSync, fchownSync, fsyncSync, openSync, writeFileSync as writeFileSync6, renameSync as renameSync5, mkdirSync as mkdirSync5, unlinkSync as unlinkSync4 } from "fs";
|
|
8496
8058
|
import { dirname as dirname4 } from "path";
|
|
8497
8059
|
function atomicWriteFileSync(path, data, own) {
|
|
8498
8060
|
const dirPath = dirname4(path);
|
|
8499
8061
|
const tmpPath = `${path}.tmp.${process.pid}.${Math.random().toString(36).slice(2, 8)}`;
|
|
8500
8062
|
try {
|
|
8501
|
-
|
|
8063
|
+
mkdirSync5(dirPath, { recursive: true });
|
|
8502
8064
|
} catch {
|
|
8503
8065
|
}
|
|
8504
8066
|
const fd = openSync(tmpPath, "w", 420);
|
|
8505
8067
|
try {
|
|
8506
8068
|
try {
|
|
8507
|
-
|
|
8069
|
+
writeFileSync6(fd, data);
|
|
8508
8070
|
if (own?.mode !== void 0) fchmodSync(fd, own.mode);
|
|
8509
8071
|
if (own?.uid !== void 0 && own.gid !== void 0) {
|
|
8510
8072
|
try {
|
|
@@ -8539,16 +8101,16 @@ function atomicWriteFileSync(path, data, own) {
|
|
|
8539
8101
|
}
|
|
8540
8102
|
|
|
8541
8103
|
// src/lib/feature-flags-host.ts
|
|
8542
|
-
import { existsSync as
|
|
8543
|
-
import { homedir as
|
|
8544
|
-
import { join as
|
|
8104
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6, rmSync as rmSync3, statSync as statSync2 } from "fs";
|
|
8105
|
+
import { homedir as homedir4 } from "os";
|
|
8106
|
+
import { join as join6 } from "path";
|
|
8545
8107
|
function defaultFlagsCachePath(configDir) {
|
|
8546
|
-
return
|
|
8108
|
+
return join6(configDir, "flags-cache.json");
|
|
8547
8109
|
}
|
|
8548
8110
|
function readFlagsCache(path) {
|
|
8549
8111
|
try {
|
|
8550
|
-
if (!
|
|
8551
|
-
const parsed = JSON.parse(
|
|
8112
|
+
if (!existsSync5(path)) return null;
|
|
8113
|
+
const parsed = JSON.parse(readFileSync6(path, "utf8"));
|
|
8552
8114
|
if (!parsed || typeof parsed !== "object") return null;
|
|
8553
8115
|
const obj = parsed;
|
|
8554
8116
|
const flags = obj["flags"];
|
|
@@ -8818,12 +8380,12 @@ var HostFlagStore = class {
|
|
|
8818
8380
|
* The in-memory state stays authoritative and the next heartbeat retries.
|
|
8819
8381
|
*/
|
|
8820
8382
|
persistPerAgentCaches(updatedAt) {
|
|
8821
|
-
const root =
|
|
8383
|
+
const root = join6(homedir4(), ".augmented");
|
|
8822
8384
|
for (const agentId of this.mirrorAgentIds) {
|
|
8823
8385
|
try {
|
|
8824
|
-
const dir =
|
|
8825
|
-
if (!
|
|
8826
|
-
writeFlagsCache(
|
|
8386
|
+
const dir = join6(root, agentId);
|
|
8387
|
+
if (!existsSync5(dir)) continue;
|
|
8388
|
+
writeFlagsCache(join6(dir, "flags-cache.json"), {
|
|
8827
8389
|
schema_version: this.lastSchemaVersion,
|
|
8828
8390
|
updated_at: updatedAt,
|
|
8829
8391
|
flags: this.flagsForAgent(agentId),
|
|
@@ -8837,7 +8399,7 @@ var HostFlagStore = class {
|
|
|
8837
8399
|
} catch (err) {
|
|
8838
8400
|
let removed = "left in place";
|
|
8839
8401
|
try {
|
|
8840
|
-
rmSync3(
|
|
8402
|
+
rmSync3(join6(root, agentId, "flags-cache.json"), { force: true, recursive: true });
|
|
8841
8403
|
removed = "stale mirror removed";
|
|
8842
8404
|
} catch (rmErr) {
|
|
8843
8405
|
removed = `stale mirror could NOT be removed: ${rmErr.message}`;
|
|
@@ -10736,9 +10298,9 @@ function verdictForUnavailableMcpConfig(cause, ctx) {
|
|
|
10736
10298
|
}
|
|
10737
10299
|
|
|
10738
10300
|
// src/lib/connectivity-probe-context.ts
|
|
10739
|
-
import { delimiter as pathDelimiter, join as
|
|
10740
|
-
import { existsSync as
|
|
10741
|
-
import { homedir as
|
|
10301
|
+
import { delimiter as pathDelimiter, join as join7 } from "path";
|
|
10302
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
10303
|
+
import { homedir as homedir5 } from "os";
|
|
10742
10304
|
|
|
10743
10305
|
// src/lib/probe-message-redact.ts
|
|
10744
10306
|
var MIN_SECRET_LENGTH = 8;
|
|
@@ -11524,7 +11086,7 @@ function resolveHttpServerEntry(entry, env) {
|
|
|
11524
11086
|
function readMcpHttpServerConfig(projectDir, serverKey, env) {
|
|
11525
11087
|
let servers;
|
|
11526
11088
|
try {
|
|
11527
|
-
const raw =
|
|
11089
|
+
const raw = readFileSync7(join7(projectDir, ".mcp.json"), "utf-8");
|
|
11528
11090
|
servers = JSON.parse(raw).mcpServers ?? {};
|
|
11529
11091
|
} catch {
|
|
11530
11092
|
return { ok: false, cause: "file-unreadable" };
|
|
@@ -11536,7 +11098,7 @@ function readMcpHttpServerConfig(projectDir, serverKey, env) {
|
|
|
11536
11098
|
}
|
|
11537
11099
|
function resolveDeclaredServerKey(projectDir, definitionId, derivedKey) {
|
|
11538
11100
|
try {
|
|
11539
|
-
const raw =
|
|
11101
|
+
const raw = readFileSync7(join7(projectDir, ".mcp.json"), "utf-8");
|
|
11540
11102
|
const servers = JSON.parse(raw).mcpServers ?? {};
|
|
11541
11103
|
const declared = Object.keys(servers);
|
|
11542
11104
|
if (derivedKey !== definitionId && derivedKey !== sanitizeServerKey(definitionId)) {
|
|
@@ -11578,7 +11140,7 @@ function resolveStdioServerEntry(entry, env) {
|
|
|
11578
11140
|
function readMcpStdioServerConfig(projectDir, serverKey, env) {
|
|
11579
11141
|
let servers;
|
|
11580
11142
|
try {
|
|
11581
|
-
const raw =
|
|
11143
|
+
const raw = readFileSync7(join7(projectDir, ".mcp.json"), "utf-8");
|
|
11582
11144
|
servers = JSON.parse(raw).mcpServers ?? {};
|
|
11583
11145
|
} catch {
|
|
11584
11146
|
return { ok: false, cause: "file-unreadable" };
|
|
@@ -11603,18 +11165,18 @@ function deriveMcpServerKey(input) {
|
|
|
11603
11165
|
}
|
|
11604
11166
|
var SYSTEM_PATH_FLOOR = PROBE_SYSTEM_PATH_FLOOR;
|
|
11605
11167
|
function toolkitPathDirs() {
|
|
11606
|
-
const home = process.env.HOME?.trim() ||
|
|
11168
|
+
const home = process.env.HOME?.trim() || homedir5();
|
|
11607
11169
|
return [
|
|
11608
11170
|
...PROBE_TOOLKIT_PATH_DIRS,
|
|
11609
|
-
...PROBE_HOME_RELATIVE_PATH_SEGMENTS.map((seg) =>
|
|
11171
|
+
...PROBE_HOME_RELATIVE_PATH_SEGMENTS.map((seg) => join7(home, seg))
|
|
11610
11172
|
];
|
|
11611
11173
|
}
|
|
11612
11174
|
function buildProbeEnv(projectDir, agentId) {
|
|
11613
11175
|
const probeEnv = { ...process.env };
|
|
11614
11176
|
try {
|
|
11615
|
-
const envIntPath =
|
|
11616
|
-
if (
|
|
11617
|
-
Object.assign(probeEnv, parseEnvIntegrations(
|
|
11177
|
+
const envIntPath = join7(projectDir, ".env.integrations");
|
|
11178
|
+
if (existsSync6(envIntPath)) {
|
|
11179
|
+
Object.assign(probeEnv, parseEnvIntegrations(readFileSync7(envIntPath, "utf-8")));
|
|
11618
11180
|
}
|
|
11619
11181
|
} catch {
|
|
11620
11182
|
}
|
|
@@ -11622,14 +11184,14 @@ function buildProbeEnv(projectDir, agentId) {
|
|
|
11622
11184
|
probeEnv.AGT_AGENT_ID = agentId.trim();
|
|
11623
11185
|
}
|
|
11624
11186
|
try {
|
|
11625
|
-
const agentBinDir =
|
|
11626
|
-
if (
|
|
11187
|
+
const agentBinDir = join7(projectDir, ".claude", "agt-bin");
|
|
11188
|
+
if (existsSync6(agentBinDir)) {
|
|
11627
11189
|
const parts = probeEnv.PATH ? probeEnv.PATH.split(pathDelimiter) : [];
|
|
11628
11190
|
parts.unshift(agentBinDir);
|
|
11629
11191
|
if (process.platform !== "win32") {
|
|
11630
11192
|
let insertAt = 1;
|
|
11631
11193
|
for (const dir of toolkitPathDirs()) {
|
|
11632
|
-
if (!
|
|
11194
|
+
if (!existsSync6(dir)) continue;
|
|
11633
11195
|
parts.splice(insertAt, 0, dir);
|
|
11634
11196
|
insertAt += 1;
|
|
11635
11197
|
}
|
|
@@ -12016,8 +11578,8 @@ var TunnelWatcher = class {
|
|
|
12016
11578
|
|
|
12017
11579
|
// src/lib/session-tool-bind-probe-host.ts
|
|
12018
11580
|
import { execFileSync as syncExecFile } from "child_process";
|
|
12019
|
-
import { readFileSync as
|
|
12020
|
-
import { join as
|
|
11581
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
11582
|
+
import { join as join8 } from "path";
|
|
12021
11583
|
import { dirname as dirname5 } from "path";
|
|
12022
11584
|
function termsRestrictedServerKeys(integrations, isRestricted = isProbeRestrictedByProviderTerms) {
|
|
12023
11585
|
const keys = /* @__PURE__ */ new Set();
|
|
@@ -12061,7 +11623,7 @@ async function gatherSessionToolBindProbe(agent, integrations, projectDir, opts)
|
|
|
12061
11623
|
if (integrations.length === 0) return null;
|
|
12062
11624
|
let mcpRaw = null;
|
|
12063
11625
|
try {
|
|
12064
|
-
mcpRaw =
|
|
11626
|
+
mcpRaw = readFileSync8(join8(projectDir, ".mcp.json"), "utf-8");
|
|
12065
11627
|
} catch {
|
|
12066
11628
|
mcpRaw = null;
|
|
12067
11629
|
}
|
|
@@ -12165,7 +11727,7 @@ var SLACK_MCP_SERVER_KEY = "slack";
|
|
|
12165
11727
|
function readSlackTransportDownKeys(projectDir) {
|
|
12166
11728
|
const none = /* @__PURE__ */ new Set();
|
|
12167
11729
|
try {
|
|
12168
|
-
const raw =
|
|
11730
|
+
const raw = readFileSync8(join8(dirname5(projectDir), SLACK_SOCKET_STATE_FILENAME), "utf-8");
|
|
12169
11731
|
const state = parseSlackSocketState(raw, Date.now());
|
|
12170
11732
|
return isSlackInboundTransportDown(state, SLACK_TRANSPORT_DOWN_AFTER_MS) ? /* @__PURE__ */ new Set([SLACK_MCP_SERVER_KEY]) : none;
|
|
12171
11733
|
} catch {
|
|
@@ -12250,13 +11812,13 @@ function describeWorkerModuleFailure(err) {
|
|
|
12250
11812
|
}
|
|
12251
11813
|
|
|
12252
11814
|
// src/lib/drain-transcript-flush.ts
|
|
12253
|
-
import { existsSync as
|
|
12254
|
-
import { homedir as
|
|
12255
|
-
import { dirname as dirname6, join as
|
|
11815
|
+
import { existsSync as existsSync7, readdirSync as readdirSync2 } from "fs";
|
|
11816
|
+
import { homedir as homedir6 } from "os";
|
|
11817
|
+
import { dirname as dirname6, join as join9, relative as relative2, sep } from "path";
|
|
12256
11818
|
import { spawn as spawn2 } from "child_process";
|
|
12257
11819
|
|
|
12258
11820
|
// src/lib/host-archive-address.ts
|
|
12259
|
-
import { readFileSync as
|
|
11821
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
12260
11822
|
var DEFAULT_ARCHIVE_ADDRESS_PATH = "/var/lib/augmented/session-archive-address.json";
|
|
12261
11823
|
var CACHE_TTL_MS = 5 * 60 * 1e3;
|
|
12262
11824
|
var cache2 = /* @__PURE__ */ new Map();
|
|
@@ -12272,7 +11834,7 @@ function readHostArchiveAddress(path) {
|
|
|
12272
11834
|
if (hit && now - hit.at < CACHE_TTL_MS) return hit.value;
|
|
12273
11835
|
let value = null;
|
|
12274
11836
|
try {
|
|
12275
|
-
const raw =
|
|
11837
|
+
const raw = readFileSync9(file, "utf-8");
|
|
12276
11838
|
const parsed = JSON.parse(raw);
|
|
12277
11839
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
12278
11840
|
const obj = parsed;
|
|
@@ -12296,18 +11858,18 @@ function readHostArchiveAddress(path) {
|
|
|
12296
11858
|
|
|
12297
11859
|
// src/lib/drain-transcript-flush.ts
|
|
12298
11860
|
function sessionsBaseDir() {
|
|
12299
|
-
return
|
|
11861
|
+
return join9(homedir6(), ".claude", "projects");
|
|
12300
11862
|
}
|
|
12301
11863
|
var PER_FILE_UPLOAD_TIMEOUT_MS = 3e4;
|
|
12302
11864
|
var UPLOAD_CONCURRENCY = 4;
|
|
12303
11865
|
var DRAIN_MANIFEST_VERSION = 1;
|
|
12304
11866
|
var DRAIN_MANIFEST_FILENAME = "_augmented-drain-manifest.json";
|
|
12305
11867
|
function listJsonlFiles(dir) {
|
|
12306
|
-
if (!
|
|
11868
|
+
if (!existsSync7(dir)) return [];
|
|
12307
11869
|
const out = [];
|
|
12308
11870
|
const walk = (d) => {
|
|
12309
11871
|
for (const entry of readdirSync2(d, { withFileTypes: true })) {
|
|
12310
|
-
const full =
|
|
11872
|
+
const full = join9(d, entry.name);
|
|
12311
11873
|
if (entry.isDirectory()) walk(full);
|
|
12312
11874
|
else if (entry.isFile() && entry.name.endsWith(".jsonl")) out.push(full);
|
|
12313
11875
|
}
|
|
@@ -12324,7 +11886,7 @@ function transcriptObjectKey(keyPrefix, baseDir, file) {
|
|
|
12324
11886
|
return `${keyPrefix.replace(/\/+$/, "")}/${rel}`;
|
|
12325
11887
|
}
|
|
12326
11888
|
function drainManifestObjectKey(keyPrefix, baseDir, transcriptDir) {
|
|
12327
|
-
return transcriptObjectKey(keyPrefix, baseDir,
|
|
11889
|
+
return transcriptObjectKey(keyPrefix, baseDir, join9(transcriptDir, DRAIN_MANIFEST_FILENAME));
|
|
12328
11890
|
}
|
|
12329
11891
|
async function flushAgentTranscriptsOnDrain(codeName, deps) {
|
|
12330
11892
|
const dir = deps.resolveTranscriptDir(codeName);
|
|
@@ -12476,7 +12038,7 @@ function drainTranscriptFlushDeps(log2) {
|
|
|
12476
12038
|
// tree — the thing host-archive-address.ts's header warns about.
|
|
12477
12039
|
readSourceLayout: (codeName) => {
|
|
12478
12040
|
const agentDir = dirname6(getProjectDir(codeName));
|
|
12479
|
-
const codeNameDir =
|
|
12041
|
+
const codeNameDir = join9(homedir6(), ".augmented", codeName);
|
|
12480
12042
|
return { layout: agentDir === codeNameDir ? "codename-keyed" : "id-keyed", agentDir };
|
|
12481
12043
|
},
|
|
12482
12044
|
readSessionPin: (codeName) => readDailySessionPin(codeName),
|
|
@@ -12562,9 +12124,9 @@ function decidePin(opts) {
|
|
|
12562
12124
|
}
|
|
12563
12125
|
|
|
12564
12126
|
// src/commands/setup.ts
|
|
12565
|
-
import { existsSync as
|
|
12566
|
-
import { join as
|
|
12567
|
-
import { homedir as
|
|
12127
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11, writeFileSync as writeFileSync8, mkdirSync as mkdirSync7, accessSync, constants as fsConstants } from "fs";
|
|
12128
|
+
import { join as join11, dirname as dirname7 } from "path";
|
|
12129
|
+
import { homedir as homedir7 } from "os";
|
|
12568
12130
|
import chalk3 from "chalk";
|
|
12569
12131
|
import ora from "ora";
|
|
12570
12132
|
|
|
@@ -12595,20 +12157,20 @@ function table(headers, rows) {
|
|
|
12595
12157
|
}
|
|
12596
12158
|
|
|
12597
12159
|
// src/lib/watchdog.ts
|
|
12598
|
-
import { readFileSync as
|
|
12599
|
-
import { join as
|
|
12160
|
+
import { readFileSync as readFileSync10, writeFileSync as writeFileSync7, unlinkSync as unlinkSync5, existsSync as existsSync8, mkdirSync as mkdirSync6, openSync as openSync2, closeSync as closeSync2, chmodSync as chmodSync5 } from "fs";
|
|
12161
|
+
import { join as join10 } from "path";
|
|
12600
12162
|
import { spawn as spawn3, execFileSync as execFileSync3 } from "child_process";
|
|
12601
|
-
var DEFAULT_CONFIG_DIR =
|
|
12163
|
+
var DEFAULT_CONFIG_DIR = join10(process.env["HOME"] ?? "/tmp", ".augmented");
|
|
12602
12164
|
function getManagerPaths(configDir) {
|
|
12603
12165
|
return {
|
|
12604
|
-
pidFile:
|
|
12605
|
-
stateFile:
|
|
12606
|
-
logFile:
|
|
12166
|
+
pidFile: join10(configDir, "manager.pid"),
|
|
12167
|
+
stateFile: join10(configDir, "manager-state.json"),
|
|
12168
|
+
logFile: join10(configDir, "manager.log")
|
|
12607
12169
|
};
|
|
12608
12170
|
}
|
|
12609
12171
|
function ensureDir(configDir) {
|
|
12610
|
-
if (!
|
|
12611
|
-
|
|
12172
|
+
if (!existsSync8(configDir)) {
|
|
12173
|
+
mkdirSync6(configDir, { recursive: true });
|
|
12612
12174
|
}
|
|
12613
12175
|
}
|
|
12614
12176
|
function writePidFile(configDir, pid) {
|
|
@@ -12617,7 +12179,7 @@ function writePidFile(configDir, pid) {
|
|
|
12617
12179
|
}
|
|
12618
12180
|
function readPidFile(configDir) {
|
|
12619
12181
|
try {
|
|
12620
|
-
const raw =
|
|
12182
|
+
const raw = readFileSync10(getManagerPaths(configDir).pidFile, "utf-8").trim();
|
|
12621
12183
|
const pid = parseInt(raw, 10);
|
|
12622
12184
|
return isNaN(pid) ? null : pid;
|
|
12623
12185
|
} catch {
|
|
@@ -12663,7 +12225,7 @@ function defaultPgrep() {
|
|
|
12663
12225
|
}
|
|
12664
12226
|
function readStateFile(configDir) {
|
|
12665
12227
|
try {
|
|
12666
|
-
const raw =
|
|
12228
|
+
const raw = readFileSync10(getManagerPaths(configDir).stateFile, "utf-8");
|
|
12667
12229
|
return JSON.parse(raw);
|
|
12668
12230
|
} catch {
|
|
12669
12231
|
return null;
|
|
@@ -12719,7 +12281,7 @@ function startWatchdog(opts) {
|
|
|
12719
12281
|
const deadline = Date.now() + 5e3;
|
|
12720
12282
|
const sleepBuf = new Int32Array(new SharedArrayBuffer(4));
|
|
12721
12283
|
while (Date.now() < deadline) {
|
|
12722
|
-
if (
|
|
12284
|
+
if (existsSync8(pidFile)) {
|
|
12723
12285
|
return { pid: child.pid };
|
|
12724
12286
|
}
|
|
12725
12287
|
if (child.exitCode !== null) {
|
|
@@ -12793,17 +12355,17 @@ function getManagerStatus(configDir = DEFAULT_CONFIG_DIR) {
|
|
|
12793
12355
|
// src/commands/setup.ts
|
|
12794
12356
|
function detectShellProfile() {
|
|
12795
12357
|
const shell = process.env["SHELL"] ?? "";
|
|
12796
|
-
const home =
|
|
12358
|
+
const home = homedir7();
|
|
12797
12359
|
if (shell.includes("zsh")) {
|
|
12798
|
-
return
|
|
12360
|
+
return join11(home, ".zshrc");
|
|
12799
12361
|
}
|
|
12800
12362
|
if (shell.includes("fish")) {
|
|
12801
|
-
const fishConfig =
|
|
12363
|
+
const fishConfig = join11(home, ".config", "fish", "config.fish");
|
|
12802
12364
|
return fishConfig;
|
|
12803
12365
|
}
|
|
12804
|
-
const bashrc =
|
|
12805
|
-
if (
|
|
12806
|
-
return
|
|
12366
|
+
const bashrc = join11(home, ".bashrc");
|
|
12367
|
+
if (existsSync9(bashrc)) return bashrc;
|
|
12368
|
+
return join11(home, ".bash_profile");
|
|
12807
12369
|
}
|
|
12808
12370
|
function maybeWriteSystemWideEnv(apiUrl, apiKey, consoleUrl) {
|
|
12809
12371
|
const empty = { etcEnvironment: false, profileD: false, bashrc: false };
|
|
@@ -12834,7 +12396,7 @@ function parseEtcEnvironmentValue(text, key) {
|
|
|
12834
12396
|
}
|
|
12835
12397
|
function readEtcEnvironmentValue(key) {
|
|
12836
12398
|
try {
|
|
12837
|
-
return parseEtcEnvironmentValue(
|
|
12399
|
+
return parseEtcEnvironmentValue(readFileSync11("/etc/environment", "utf-8"), key);
|
|
12838
12400
|
} catch {
|
|
12839
12401
|
return null;
|
|
12840
12402
|
}
|
|
@@ -12847,14 +12409,14 @@ function quoteForFishShell(value) {
|
|
|
12847
12409
|
}
|
|
12848
12410
|
function writeEtcEnvironment(apiUrl, apiKey, consoleUrl) {
|
|
12849
12411
|
const envPath = "/etc/environment";
|
|
12850
|
-
if (!
|
|
12412
|
+
if (!existsSync9(envPath)) return false;
|
|
12851
12413
|
try {
|
|
12852
12414
|
accessSync(envPath, fsConstants.W_OK);
|
|
12853
12415
|
} catch {
|
|
12854
12416
|
return false;
|
|
12855
12417
|
}
|
|
12856
12418
|
try {
|
|
12857
|
-
const current =
|
|
12419
|
+
const current = readFileSync11(envPath, "utf-8");
|
|
12858
12420
|
const stripped = current.split(/\r?\n/).filter((line) => !/^\s*(?:export\s+)?AGT_(?:HOST|API_KEY|CONSOLE_URL)=/.test(line)).join("\n");
|
|
12859
12421
|
const base = stripped.endsWith("\n") || stripped.length === 0 ? stripped : `${stripped}
|
|
12860
12422
|
`;
|
|
@@ -12873,7 +12435,7 @@ function writeEtcEnvironment(apiUrl, apiKey, consoleUrl) {
|
|
|
12873
12435
|
}
|
|
12874
12436
|
function writeProfileDScript(apiUrl, apiKey, consoleUrl) {
|
|
12875
12437
|
const profileD = "/etc/profile.d";
|
|
12876
|
-
if (!
|
|
12438
|
+
if (!existsSync9(profileD)) return false;
|
|
12877
12439
|
try {
|
|
12878
12440
|
accessSync(profileD, fsConstants.W_OK);
|
|
12879
12441
|
} catch {
|
|
@@ -12896,14 +12458,14 @@ function writeProfileDScript(apiUrl, apiKey, consoleUrl) {
|
|
|
12896
12458
|
}
|
|
12897
12459
|
function ensureBashrcSourcesProfileD() {
|
|
12898
12460
|
const bashrc = "/etc/bashrc";
|
|
12899
|
-
if (!
|
|
12461
|
+
if (!existsSync9(bashrc)) return false;
|
|
12900
12462
|
try {
|
|
12901
12463
|
accessSync(bashrc, fsConstants.W_OK);
|
|
12902
12464
|
} catch {
|
|
12903
12465
|
return false;
|
|
12904
12466
|
}
|
|
12905
12467
|
try {
|
|
12906
|
-
const current =
|
|
12468
|
+
const current = readFileSync11(bashrc, "utf-8");
|
|
12907
12469
|
const marker = "# Augmented (agt) \u2014 source system-wide AGT env";
|
|
12908
12470
|
if (current.includes(marker)) return true;
|
|
12909
12471
|
const snippet = [
|
|
@@ -13043,11 +12605,11 @@ async function setupCommand(token, options = {}) {
|
|
|
13043
12605
|
}
|
|
13044
12606
|
const exportLines = buildExportLines(shell, finalApiUrl, setupResult.api_key, consoleUrl);
|
|
13045
12607
|
const profileDir = dirname7(profilePath);
|
|
13046
|
-
if (!
|
|
13047
|
-
|
|
12608
|
+
if (!existsSync9(profileDir)) {
|
|
12609
|
+
mkdirSync7(profileDir, { recursive: true });
|
|
13048
12610
|
}
|
|
13049
12611
|
const marker = "# Augmented (agt) host configuration";
|
|
13050
|
-
const current =
|
|
12612
|
+
const current = existsSync9(profilePath) ? readFileSync11(profilePath, "utf-8") : "";
|
|
13051
12613
|
let updated;
|
|
13052
12614
|
if (current.includes(marker)) {
|
|
13053
12615
|
updated = current.replace(
|
|
@@ -13078,7 +12640,7 @@ async function setupCommand(token, options = {}) {
|
|
|
13078
12640
|
const managerSpinner = ora({ text: "Starting manager daemon\u2026", isSilent: json });
|
|
13079
12641
|
managerSpinner.start();
|
|
13080
12642
|
try {
|
|
13081
|
-
const configDir =
|
|
12643
|
+
const configDir = join11(homedir7(), ".augmented");
|
|
13082
12644
|
const { pid } = startWatchdog({ intervalMs: 1e4, configDir, detached: true });
|
|
13083
12645
|
managerSpinner.succeed(`Manager started (PID ${pid})`);
|
|
13084
12646
|
} catch (err) {
|
|
@@ -13117,9 +12679,9 @@ async function setupCommand(token, options = {}) {
|
|
|
13117
12679
|
|
|
13118
12680
|
// src/commands/manager.ts
|
|
13119
12681
|
import chalk4 from "chalk";
|
|
13120
|
-
import { existsSync as
|
|
13121
|
-
import { join as
|
|
13122
|
-
import { homedir as
|
|
12682
|
+
import { existsSync as existsSync10, realpathSync as realpathSync2 } from "fs";
|
|
12683
|
+
import { join as join12 } from "path";
|
|
12684
|
+
import { homedir as homedir8, userInfo } from "os";
|
|
13123
12685
|
import { spawn as spawn4 } from "child_process";
|
|
13124
12686
|
function normalizePinInEnv(env) {
|
|
13125
12687
|
const normalized = normalizePinVersion(env.AGT_CLI_PIN_VERSION);
|
|
@@ -13129,7 +12691,7 @@ function normalizePinInEnv(env) {
|
|
|
13129
12691
|
function managerStartCommand(opts) {
|
|
13130
12692
|
const json = isJsonMode();
|
|
13131
12693
|
if (!process.env.HOME || !process.env.HOME.trim()) {
|
|
13132
|
-
const fallback =
|
|
12694
|
+
const fallback = homedir8();
|
|
13133
12695
|
process.env.HOME = fallback;
|
|
13134
12696
|
if (!json) {
|
|
13135
12697
|
info(`HOME was not set in the manager env \u2014 defaulting to ${fallback}.`);
|
|
@@ -13163,7 +12725,7 @@ function managerStartCommand(opts) {
|
|
|
13163
12725
|
process.exitCode = 1;
|
|
13164
12726
|
return;
|
|
13165
12727
|
}
|
|
13166
|
-
const configDir = opts.configDir ??
|
|
12728
|
+
const configDir = opts.configDir ?? join12(homedir8(), ".augmented");
|
|
13167
12729
|
if (opts.supervise) {
|
|
13168
12730
|
if (json) {
|
|
13169
12731
|
jsonOutput({ ok: false, error: "--supervise is not supported with --json" });
|
|
@@ -13259,7 +12821,7 @@ function runSupervisorLoop(intervalSec, configDir) {
|
|
|
13259
12821
|
}
|
|
13260
12822
|
async function managerStopCommand(opts = {}) {
|
|
13261
12823
|
const json = isJsonMode();
|
|
13262
|
-
const configDir = opts.configDir ??
|
|
12824
|
+
const configDir = opts.configDir ?? join12(homedir8(), ".augmented");
|
|
13263
12825
|
try {
|
|
13264
12826
|
const result = await stopWatchdog(configDir);
|
|
13265
12827
|
if (!result.stopped && !result.pid) {
|
|
@@ -13287,7 +12849,7 @@ async function managerStopCommand(opts = {}) {
|
|
|
13287
12849
|
}
|
|
13288
12850
|
function managerStatusCommand(opts = {}) {
|
|
13289
12851
|
const json = isJsonMode();
|
|
13290
|
-
const configDir = opts.configDir ??
|
|
12852
|
+
const configDir = opts.configDir ?? join12(homedir8(), ".augmented");
|
|
13291
12853
|
const status = getManagerStatus(configDir);
|
|
13292
12854
|
if (!status) {
|
|
13293
12855
|
if (json) {
|
|
@@ -13377,7 +12939,7 @@ function resolveStableAgtBin(rawPath) {
|
|
|
13377
12939
|
if (!prefix || !formula) return rawPath;
|
|
13378
12940
|
const candidates = [`${prefix}/bin/${formula}`, `${prefix}/bin/agt`];
|
|
13379
12941
|
for (const candidate of candidates) {
|
|
13380
|
-
if (!
|
|
12942
|
+
if (!existsSync10(candidate)) continue;
|
|
13381
12943
|
try {
|
|
13382
12944
|
realpathSync2(candidate);
|
|
13383
12945
|
return candidate;
|
|
@@ -13397,7 +12959,7 @@ async function managerInstallCommand(opts = {}) {
|
|
|
13397
12959
|
process.exitCode = 1;
|
|
13398
12960
|
return;
|
|
13399
12961
|
}
|
|
13400
|
-
const configDir = opts.configDir ??
|
|
12962
|
+
const configDir = opts.configDir ?? join12(homedir8(), ".augmented");
|
|
13401
12963
|
const rawAgtBin = process.argv[1];
|
|
13402
12964
|
if (!rawAgtBin) {
|
|
13403
12965
|
const msg = "Could not resolve the agt binary path from argv. Re-run via the installed `agt` command.";
|
|
@@ -13408,9 +12970,9 @@ async function managerInstallCommand(opts = {}) {
|
|
|
13408
12970
|
}
|
|
13409
12971
|
const agtBin = resolveStableAgtBin(rawAgtBin);
|
|
13410
12972
|
if (process.platform === "darwin") {
|
|
13411
|
-
const home =
|
|
12973
|
+
const home = homedir8();
|
|
13412
12974
|
const protectedRoots = ["Documents", "Downloads", "Desktop", "Movies", "Music", "Pictures"];
|
|
13413
|
-
const offending = protectedRoots.map((r) =>
|
|
12975
|
+
const offending = protectedRoots.map((r) => join12(home, r)).find((p) => agtBin === p || agtBin.startsWith(`${p}/`));
|
|
13414
12976
|
if (offending) {
|
|
13415
12977
|
const msg = `agt binary at ${agtBin} sits inside a macOS TCC-protected folder (${offending}). launchd-spawned processes cannot read files there and the manager would EPERM on startup. Either install agt globally (\`npm install -g @integrity-labs/agt-cli\`) or copy the dist outside protected folders before running this command.`;
|
|
13416
12978
|
if (json) jsonOutput({ ok: false, error: msg });
|
|
@@ -13423,7 +12985,7 @@ async function managerInstallCommand(opts = {}) {
|
|
|
13423
12985
|
AGT_HOST: getHost(),
|
|
13424
12986
|
// ?? alone wouldn't catch `HOME=""` from a stripped systemd env.
|
|
13425
12987
|
// Treat empty / whitespace-only as missing.
|
|
13426
|
-
HOME: process.env.HOME?.trim() ||
|
|
12988
|
+
HOME: process.env.HOME?.trim() || homedir8(),
|
|
13427
12989
|
USER: process.env.USER?.trim() || userInfo().username
|
|
13428
12990
|
};
|
|
13429
12991
|
const apiKey = getApiKey();
|
|
@@ -13476,7 +13038,7 @@ async function managerInstallSystemUnitCommand(opts = {}) {
|
|
|
13476
13038
|
return;
|
|
13477
13039
|
}
|
|
13478
13040
|
const user = opts.user ?? "root";
|
|
13479
|
-
const configDir = opts.configDir ?? (user === "root" ? "/root/.augmented" :
|
|
13041
|
+
const configDir = opts.configDir ?? (user === "root" ? "/root/.augmented" : join12("/home", user, ".augmented"));
|
|
13480
13042
|
const rawAgtBin = process.argv[1];
|
|
13481
13043
|
if (!rawAgtBin) {
|
|
13482
13044
|
const msg = "Could not resolve the agt binary path from argv. Re-run via the installed `agt` command.";
|
|
@@ -13716,26 +13278,6 @@ export {
|
|
|
13716
13278
|
setJsonMode,
|
|
13717
13279
|
isJsonMode,
|
|
13718
13280
|
jsonOutput,
|
|
13719
|
-
getApiKey,
|
|
13720
|
-
getActiveTeam,
|
|
13721
|
-
setActiveTeam,
|
|
13722
|
-
PROD_AGT_HOST,
|
|
13723
|
-
getHost,
|
|
13724
|
-
requireHost,
|
|
13725
|
-
isTransientAuthFailure,
|
|
13726
|
-
exchangeFailureKind,
|
|
13727
|
-
setConfigHash,
|
|
13728
|
-
forceNextExchange,
|
|
13729
|
-
getCachedClaudeAuthMode,
|
|
13730
|
-
getCachedClaudeAuthModeRaw,
|
|
13731
|
-
exchangeApiKey,
|
|
13732
|
-
mintAgentKey,
|
|
13733
|
-
mintRotatedHostKey,
|
|
13734
|
-
probeHostKey,
|
|
13735
|
-
adoptHostKeyInProcess,
|
|
13736
|
-
ApiError,
|
|
13737
|
-
api,
|
|
13738
|
-
getHostId,
|
|
13739
13281
|
success,
|
|
13740
13282
|
error,
|
|
13741
13283
|
warn,
|
|
@@ -13805,4 +13347,4 @@ export {
|
|
|
13805
13347
|
managerInstallSystemUnitCommand,
|
|
13806
13348
|
managerUninstallSystemUnitCommand
|
|
13807
13349
|
};
|
|
13808
|
-
//# sourceMappingURL=chunk-
|
|
13350
|
+
//# sourceMappingURL=chunk-S3DUSCWR.js.map
|