@alan-ai-hq/agent-manager 0.1.111 → 0.1.113
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/index.cjs +267 -254
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15243,13 +15243,13 @@ Usage:
|
|
|
15243
15243
|
alan-agent <command> [options]
|
|
15244
15244
|
|
|
15245
15245
|
Commands:
|
|
15246
|
-
install Login/setup
|
|
15246
|
+
install Login/setup and install the daemon service (MCP + session sync are opt-in)
|
|
15247
15247
|
setup Register this computer with a setup token from Alan
|
|
15248
15248
|
login Register this computer through browser authorization
|
|
15249
15249
|
daemon Start the durable runtime daemon
|
|
15250
15250
|
service Install, uninstall, or inspect the per-user daemon service
|
|
15251
|
-
integrations Reconcile, inspect, or uninstall Alan
|
|
15252
|
-
hook Internal: durably spool a native CLI
|
|
15251
|
+
integrations Reconcile, inspect, or uninstall Alan MCP and session sync
|
|
15252
|
+
hook Internal: durably spool a native CLI session-sync event (fail-open)
|
|
15253
15253
|
stop Stop the local daemon (or active runs only via the local API /stop)
|
|
15254
15254
|
recover Redial and safely restart a stuck local daemon connection
|
|
15255
15255
|
status Show local runtime configuration without secrets
|
|
@@ -15263,6 +15263,7 @@ Commands:
|
|
|
15263
15263
|
Common flows:
|
|
15264
15264
|
alan-agent install
|
|
15265
15265
|
alan-agent install --setup-token <token>
|
|
15266
|
+
alan-agent install --with-integrations
|
|
15266
15267
|
alan-agent login
|
|
15267
15268
|
alan-agent login --cancel
|
|
15268
15269
|
alan-agent setup --setup-token <token>
|
|
@@ -15546,7 +15547,7 @@ function describeError(error61) {
|
|
|
15546
15547
|
}
|
|
15547
15548
|
|
|
15548
15549
|
// src/version.ts
|
|
15549
|
-
var AGENT_VERSION = "0.1.
|
|
15550
|
+
var AGENT_VERSION = "0.1.113";
|
|
15550
15551
|
|
|
15551
15552
|
// src/daemon-workspace.ts
|
|
15552
15553
|
var import_node_child_process3 = require("child_process");
|
|
@@ -15790,13 +15791,13 @@ function resolveRuntimeCwd(payload) {
|
|
|
15790
15791
|
|
|
15791
15792
|
// src/daemon-local-control.ts
|
|
15792
15793
|
var import_node_crypto5 = require("crypto");
|
|
15793
|
-
var
|
|
15794
|
-
var
|
|
15794
|
+
var import_node_fs9 = require("fs");
|
|
15795
|
+
var import_node_path10 = require("path");
|
|
15795
15796
|
|
|
15796
15797
|
// src/daemon-runner-status.ts
|
|
15797
|
-
var
|
|
15798
|
+
var import_node_fs8 = require("fs");
|
|
15798
15799
|
var import_node_os5 = require("os");
|
|
15799
|
-
var
|
|
15800
|
+
var import_node_path9 = require("path");
|
|
15800
15801
|
|
|
15801
15802
|
// ../shared/dist/node/provider-limits.js
|
|
15802
15803
|
var import_node_child_process4 = require("child_process");
|
|
@@ -37968,6 +37969,7 @@ function mapProviderApiError(errorCode2, apiStatus) {
|
|
|
37968
37969
|
return "model_mismatch";
|
|
37969
37970
|
}
|
|
37970
37971
|
if (code.includes("authentication") || code.includes("permission_error")) return "auth_invalid";
|
|
37972
|
+
if (code.includes("quota_exceeded")) return "quota_exceeded";
|
|
37971
37973
|
if (code.includes("rate_limit") || code.includes("resource_exhausted")) {
|
|
37972
37974
|
return "rate_limited";
|
|
37973
37975
|
}
|
|
@@ -47990,80 +47992,9 @@ ${result.stderr}`.trim();
|
|
|
47990
47992
|
}
|
|
47991
47993
|
|
|
47992
47994
|
// src/workspace-run-lease.ts
|
|
47993
|
-
var import_node_child_process6 = require("child_process");
|
|
47994
|
-
var import_promises5 = require("fs/promises");
|
|
47995
|
-
var import_node_path9 = require("path");
|
|
47996
|
-
|
|
47997
|
-
// src/workspace-relocation.ts
|
|
47998
47995
|
var import_node_child_process5 = require("child_process");
|
|
47999
|
-
var
|
|
47996
|
+
var import_promises5 = require("fs/promises");
|
|
48000
47997
|
var import_node_path8 = require("path");
|
|
48001
|
-
var MAX_RELOCATION_CANDIDATES = 200;
|
|
48002
|
-
var DEFAULT_PROBE = {
|
|
48003
|
-
childDirectories: (parentPath, limit) => (0, import_node_fs8.readdirSync)(parentPath, { withFileTypes: true }).filter((entry) => entry.isDirectory()).slice(0, limit).map((entry) => (0, import_node_path8.join)(parentPath, entry.name)),
|
|
48004
|
-
gitRemoteUrl: (candidatePath) => {
|
|
48005
|
-
const result = (0, import_node_child_process5.spawnSync)("git", ["-C", candidatePath, "config", "--get", "remote.origin.url"], {
|
|
48006
|
-
encoding: "utf8",
|
|
48007
|
-
env: getDaemonCliEnvironment(),
|
|
48008
|
-
timeout: 2e3
|
|
48009
|
-
});
|
|
48010
|
-
if (result.status !== 0) return null;
|
|
48011
|
-
const url3 = result.stdout.trim();
|
|
48012
|
-
return url3 || null;
|
|
48013
|
-
}
|
|
48014
|
-
};
|
|
48015
|
-
function normalizeRepositoryIdentity(value2) {
|
|
48016
|
-
const trimmed = value2.trim().replace(/\/+$/, "").replace(/\.git$/i, "");
|
|
48017
|
-
if (!trimmed) return null;
|
|
48018
|
-
const scp = trimmed.match(/^(?:[^@/]+@)?([^:/]+):(.+)$/);
|
|
48019
|
-
if (scp && !trimmed.includes("://")) {
|
|
48020
|
-
return `${scp[1]}/${scp[2]}`.toLowerCase();
|
|
48021
|
-
}
|
|
48022
|
-
try {
|
|
48023
|
-
const url3 = new URL(trimmed);
|
|
48024
|
-
return `${url3.hostname}${url3.pathname}`.replace(/\/+$/, "").toLowerCase();
|
|
48025
|
-
} catch {
|
|
48026
|
-
return null;
|
|
48027
|
-
}
|
|
48028
|
-
}
|
|
48029
|
-
function workspaceMatchesExpectedRepositories(input2) {
|
|
48030
|
-
const identities = new Set(
|
|
48031
|
-
input2.expectedRepoUrls.map(normalizeRepositoryIdentity).filter((identity3) => Boolean(identity3))
|
|
48032
|
-
);
|
|
48033
|
-
if (identities.size === 0) return false;
|
|
48034
|
-
const remote = (input2.probe ?? DEFAULT_PROBE).gitRemoteUrl((0, import_node_path8.resolve)(input2.workspacePath));
|
|
48035
|
-
const identity2 = remote ? normalizeRepositoryIdentity(remote) : null;
|
|
48036
|
-
return Boolean(identity2 && identities.has(identity2));
|
|
48037
|
-
}
|
|
48038
|
-
function discoverRelocatedWorkspace(input2) {
|
|
48039
|
-
const identities = new Set(
|
|
48040
|
-
input2.expectedRepoUrls.map(normalizeRepositoryIdentity).filter((identity2) => Boolean(identity2))
|
|
48041
|
-
);
|
|
48042
|
-
if (identities.size === 0) return null;
|
|
48043
|
-
const searchRoots = [
|
|
48044
|
-
(0, import_node_path8.dirname)((0, import_node_path8.resolve)(input2.missingPath)),
|
|
48045
|
-
...(input2.approvedWorkspacePaths ?? []).map((path2) => (0, import_node_path8.dirname)((0, import_node_path8.resolve)(path2)))
|
|
48046
|
-
].filter((path2, index, paths) => paths.indexOf(path2) === index);
|
|
48047
|
-
const candidates = [];
|
|
48048
|
-
for (const root of searchRoots) {
|
|
48049
|
-
const remaining = MAX_RELOCATION_CANDIDATES - candidates.length;
|
|
48050
|
-
if (remaining <= 0) break;
|
|
48051
|
-
try {
|
|
48052
|
-
candidates.push(...(input2.probe ?? DEFAULT_PROBE).childDirectories(root, remaining));
|
|
48053
|
-
} catch {
|
|
48054
|
-
}
|
|
48055
|
-
}
|
|
48056
|
-
const matches = [];
|
|
48057
|
-
for (const candidate of new Set(candidates.map((path2) => (0, import_node_path8.resolve)(path2)))) {
|
|
48058
|
-
const remote = (input2.probe ?? DEFAULT_PROBE).gitRemoteUrl(candidate);
|
|
48059
|
-
const identity2 = remote ? normalizeRepositoryIdentity(remote) : null;
|
|
48060
|
-
if (identity2 && identities.has(identity2)) matches.push((0, import_node_path8.resolve)(candidate));
|
|
48061
|
-
if (matches.length > 1) return null;
|
|
48062
|
-
}
|
|
48063
|
-
return matches[0] ?? null;
|
|
48064
|
-
}
|
|
48065
|
-
|
|
48066
|
-
// src/workspace-run-lease.ts
|
|
48067
47998
|
var WORKSPACE_LEASE_CHECK_INTERVAL_MS = 1e3;
|
|
48068
47999
|
function parsePositiveMs(value2, fallback) {
|
|
48069
48000
|
const parsed = value2 ? Number(value2) : Number.NaN;
|
|
@@ -48079,19 +48010,19 @@ function applicationCodeForWorkspaceLeaseFailure(code) {
|
|
|
48079
48010
|
async function hasGitWorkspaceMarker(workspacePath) {
|
|
48080
48011
|
let directory;
|
|
48081
48012
|
try {
|
|
48082
|
-
directory = await (0, import_promises5.realpath)((0,
|
|
48013
|
+
directory = await (0, import_promises5.realpath)((0, import_node_path8.resolve)(workspacePath));
|
|
48083
48014
|
} catch {
|
|
48084
48015
|
return true;
|
|
48085
48016
|
}
|
|
48086
48017
|
while (true) {
|
|
48087
48018
|
try {
|
|
48088
|
-
await (0, import_promises5.stat)((0,
|
|
48019
|
+
await (0, import_promises5.stat)((0, import_node_path8.join)(directory, ".git"));
|
|
48089
48020
|
return true;
|
|
48090
48021
|
} catch (error61) {
|
|
48091
48022
|
const code = error61.code;
|
|
48092
48023
|
if (code !== "ENOENT" && code !== "ENOTDIR") return true;
|
|
48093
48024
|
}
|
|
48094
|
-
const parent = (0,
|
|
48025
|
+
const parent = (0, import_node_path8.dirname)(directory);
|
|
48095
48026
|
if (parent === directory) return false;
|
|
48096
48027
|
directory = parent;
|
|
48097
48028
|
}
|
|
@@ -48103,7 +48034,7 @@ async function gitValue(cwd, args) {
|
|
|
48103
48034
|
else runningGitProbes++;
|
|
48104
48035
|
try {
|
|
48105
48036
|
return await new Promise((resolve16) => {
|
|
48106
|
-
(0,
|
|
48037
|
+
(0, import_node_child_process5.execFile)(
|
|
48107
48038
|
"git",
|
|
48108
48039
|
["-C", cwd, ...args],
|
|
48109
48040
|
{
|
|
@@ -48129,7 +48060,7 @@ async function filesystemIdentity(path2) {
|
|
|
48129
48060
|
return `${canonicalPath}:${metadata.dev}:${metadata.ino}`;
|
|
48130
48061
|
}
|
|
48131
48062
|
function resolveGitPath(workspacePath, value2) {
|
|
48132
|
-
return (0,
|
|
48063
|
+
return (0, import_node_path8.isAbsolute)(value2) ? value2 : (0, import_node_path8.resolve)(workspacePath, value2);
|
|
48133
48064
|
}
|
|
48134
48065
|
function createWorkspaceRunLeaseSnapshotProbe(loadSnapshot) {
|
|
48135
48066
|
const snapshots = /* @__PURE__ */ new Map();
|
|
@@ -48151,7 +48082,7 @@ function createWorkspaceRunLeaseSnapshotProbe(loadSnapshot) {
|
|
|
48151
48082
|
return pending.promise;
|
|
48152
48083
|
};
|
|
48153
48084
|
return (workspacePath, options) => {
|
|
48154
|
-
const key = process.platform === "win32" ? (0,
|
|
48085
|
+
const key = process.platform === "win32" ? (0, import_node_path8.resolve)(workspacePath).toLowerCase() : (0, import_node_path8.resolve)(workspacePath);
|
|
48155
48086
|
const existing = snapshots.get(key);
|
|
48156
48087
|
if (!existing) return startSnapshot(key, options?.coalescePending === true);
|
|
48157
48088
|
if (!options?.fresh) return existing.promise;
|
|
@@ -48164,11 +48095,11 @@ function createWorkspaceRunLeaseSnapshotProbe(loadSnapshot) {
|
|
|
48164
48095
|
return existing.freshAfterPending;
|
|
48165
48096
|
};
|
|
48166
48097
|
}
|
|
48167
|
-
var
|
|
48098
|
+
var DEFAULT_PROBE = {
|
|
48168
48099
|
snapshot: createWorkspaceRunLeaseSnapshotProbe(snapshotWorkspace),
|
|
48169
48100
|
pathExists: async (workspacePath) => {
|
|
48170
48101
|
try {
|
|
48171
|
-
await (0, import_promises5.access)((0,
|
|
48102
|
+
await (0, import_promises5.access)((0, import_node_path8.resolve)(workspacePath));
|
|
48172
48103
|
return true;
|
|
48173
48104
|
} catch (error61) {
|
|
48174
48105
|
return error61.code !== "ENOENT";
|
|
@@ -48177,7 +48108,7 @@ var DEFAULT_PROBE2 = {
|
|
|
48177
48108
|
};
|
|
48178
48109
|
async function snapshotWorkspace(workspacePath) {
|
|
48179
48110
|
try {
|
|
48180
|
-
const canonicalWorkspacePath = await (0, import_promises5.realpath)((0,
|
|
48111
|
+
const canonicalWorkspacePath = await (0, import_promises5.realpath)((0, import_node_path8.resolve)(workspacePath));
|
|
48181
48112
|
const repositoryRoot = await gitValue(canonicalWorkspacePath, ["rev-parse", "--show-toplevel"]);
|
|
48182
48113
|
const gitDirectory = await gitValue(canonicalWorkspacePath, ["rev-parse", "--git-dir"]);
|
|
48183
48114
|
const commonDirectory = await gitValue(canonicalWorkspacePath, [
|
|
@@ -48186,14 +48117,15 @@ async function snapshotWorkspace(workspacePath) {
|
|
|
48186
48117
|
]);
|
|
48187
48118
|
const branch = await gitValue(canonicalWorkspacePath, ["branch", "--show-current"]) ?? "";
|
|
48188
48119
|
if (!repositoryRoot || !gitDirectory || !commonDirectory) return null;
|
|
48189
|
-
const remote = await gitValue(canonicalWorkspacePath, ["config", "--get", "remote.origin.url"]);
|
|
48190
|
-
const remoteIdentity = remote ? normalizeRepositoryIdentity(remote) : null;
|
|
48191
48120
|
return {
|
|
48192
|
-
workspacePath: (0,
|
|
48121
|
+
workspacePath: (0, import_node_path8.resolve)(workspacePath),
|
|
48193
48122
|
workspaceIdentity: await filesystemIdentity(canonicalWorkspacePath),
|
|
48194
|
-
|
|
48123
|
+
// The common Git directory identifies the checkout. A coding agent may
|
|
48124
|
+
// legitimately add or update origin without replacing that directory;
|
|
48125
|
+
// treating remote configuration as filesystem identity stops its run.
|
|
48126
|
+
repositoryIdentity: await filesystemIdentity(
|
|
48195
48127
|
resolveGitPath(canonicalWorkspacePath, commonDirectory)
|
|
48196
|
-
)
|
|
48128
|
+
),
|
|
48197
48129
|
worktreeIdentity: await filesystemIdentity(
|
|
48198
48130
|
resolveGitPath(canonicalWorkspacePath, gitDirectory)
|
|
48199
48131
|
),
|
|
@@ -48229,10 +48161,10 @@ var WorkspaceRunLease = class _WorkspaceRunLease {
|
|
|
48229
48161
|
this.captured = captured;
|
|
48230
48162
|
this.probe = probe;
|
|
48231
48163
|
}
|
|
48232
|
-
static async capture(targets, probe =
|
|
48164
|
+
static async capture(targets, probe = DEFAULT_PROBE) {
|
|
48233
48165
|
const captured = [];
|
|
48234
48166
|
for (const target of targets) {
|
|
48235
|
-
const normalizedTarget = { ...target, workspacePath: (0,
|
|
48167
|
+
const normalizedTarget = { ...target, workspacePath: (0, import_node_path8.resolve)(target.workspacePath) };
|
|
48236
48168
|
const identity2 = await probe.snapshot(normalizedTarget.workspacePath, {
|
|
48237
48169
|
fresh: true,
|
|
48238
48170
|
coalescePending: true
|
|
@@ -48775,13 +48707,13 @@ var DurablePendingRunStarts = class extends Map {
|
|
|
48775
48707
|
}
|
|
48776
48708
|
persist() {
|
|
48777
48709
|
if (this.size === 0) {
|
|
48778
|
-
(0,
|
|
48710
|
+
(0, import_node_fs8.rmSync)(this.path, { force: true });
|
|
48779
48711
|
return;
|
|
48780
48712
|
}
|
|
48781
48713
|
const pendingPath = `${this.path}.pending`;
|
|
48782
|
-
(0,
|
|
48714
|
+
(0, import_node_fs8.mkdirSync)((0, import_node_path9.dirname)(this.path), { recursive: true, mode: 448 });
|
|
48783
48715
|
try {
|
|
48784
|
-
(0,
|
|
48716
|
+
(0, import_node_fs8.writeFileSync)(
|
|
48785
48717
|
pendingPath,
|
|
48786
48718
|
JSON.stringify({
|
|
48787
48719
|
version: 1,
|
|
@@ -48794,10 +48726,10 @@ var DurablePendingRunStarts = class extends Map {
|
|
|
48794
48726
|
}),
|
|
48795
48727
|
{ mode: 384 }
|
|
48796
48728
|
);
|
|
48797
|
-
(0,
|
|
48798
|
-
(0,
|
|
48729
|
+
(0, import_node_fs8.chmodSync)(pendingPath, 384);
|
|
48730
|
+
(0, import_node_fs8.renameSync)(pendingPath, this.path);
|
|
48799
48731
|
} finally {
|
|
48800
|
-
(0,
|
|
48732
|
+
(0, import_node_fs8.rmSync)(pendingPath, { force: true });
|
|
48801
48733
|
}
|
|
48802
48734
|
}
|
|
48803
48735
|
};
|
|
@@ -49041,7 +48973,7 @@ function collectRuntimeMetadata() {
|
|
|
49041
48973
|
metadata.cpuCores = cpuList.length;
|
|
49042
48974
|
}
|
|
49043
48975
|
try {
|
|
49044
|
-
const disk = (0,
|
|
48976
|
+
const disk = (0, import_node_fs8.statfsSync)((0, import_node_os5.homedir)());
|
|
49045
48977
|
metadata.diskFreeBytes = disk.bavail * disk.bsize;
|
|
49046
48978
|
metadata.diskTotalBytes = disk.blocks * disk.bsize;
|
|
49047
48979
|
} catch {
|
|
@@ -49248,12 +49180,12 @@ function getConfigPath() {
|
|
|
49248
49180
|
return boundAgentConfigPath ?? process.env.ALAN_AGENT_CONFIG_PATH ?? resolveAgentConfigPath({ profile: "production" });
|
|
49249
49181
|
}
|
|
49250
49182
|
function getEndpointDefaultsPath() {
|
|
49251
|
-
return process.env.ALAN_AGENT_ENDPOINTS_PATH ?? (0,
|
|
49183
|
+
return process.env.ALAN_AGENT_ENDPOINTS_PATH ?? (0, import_node_path10.join)((0, import_node_path10.dirname)(getConfigPath()), "endpoints.json");
|
|
49252
49184
|
}
|
|
49253
49185
|
function readConfig() {
|
|
49254
49186
|
const configPath = getConfigPath();
|
|
49255
|
-
if (!(0,
|
|
49256
|
-
const parsed = JSON.parse((0,
|
|
49187
|
+
if (!(0, import_node_fs9.existsSync)(configPath)) return {};
|
|
49188
|
+
const parsed = JSON.parse((0, import_node_fs9.readFileSync)(configPath, "utf8"));
|
|
49257
49189
|
const sanitized = sanitizeAgentConfig(parsed);
|
|
49258
49190
|
if (Object.keys(parsed).some((key) => !Object.hasOwn(sanitized, key))) {
|
|
49259
49191
|
writeConfig(sanitized);
|
|
@@ -49269,27 +49201,27 @@ function readConfigForRegistration() {
|
|
|
49269
49201
|
}
|
|
49270
49202
|
function readEndpointDefaults() {
|
|
49271
49203
|
const endpointsPath = getEndpointDefaultsPath();
|
|
49272
|
-
if (!(0,
|
|
49204
|
+
if (!(0, import_node_fs9.existsSync)(endpointsPath)) return {};
|
|
49273
49205
|
try {
|
|
49274
|
-
return JSON.parse((0,
|
|
49206
|
+
return JSON.parse((0, import_node_fs9.readFileSync)(endpointsPath, "utf8"));
|
|
49275
49207
|
} catch {
|
|
49276
49208
|
return {};
|
|
49277
49209
|
}
|
|
49278
49210
|
}
|
|
49279
49211
|
function writeConfig(config2) {
|
|
49280
49212
|
const configPath = getConfigPath();
|
|
49281
|
-
(0,
|
|
49213
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(configPath), { recursive: true, mode: 448 });
|
|
49282
49214
|
const pendingPath = `${configPath}.pending-${process.pid}-${(0, import_node_crypto5.randomBytes)(6).toString("hex")}`;
|
|
49283
49215
|
try {
|
|
49284
|
-
(0,
|
|
49216
|
+
(0, import_node_fs9.writeFileSync)(
|
|
49285
49217
|
pendingPath,
|
|
49286
49218
|
JSON.stringify(sanitizeAgentConfig(config2), null, 2),
|
|
49287
49219
|
{ mode: 384 }
|
|
49288
49220
|
);
|
|
49289
|
-
(0,
|
|
49290
|
-
(0,
|
|
49221
|
+
(0, import_node_fs9.chmodSync)(pendingPath, 384);
|
|
49222
|
+
(0, import_node_fs9.renameSync)(pendingPath, configPath);
|
|
49291
49223
|
} finally {
|
|
49292
|
-
(0,
|
|
49224
|
+
(0, import_node_fs9.rmSync)(pendingPath, { force: true });
|
|
49293
49225
|
}
|
|
49294
49226
|
}
|
|
49295
49227
|
function maintenanceLeasePath(configPath) {
|
|
@@ -49297,9 +49229,9 @@ function maintenanceLeasePath(configPath) {
|
|
|
49297
49229
|
}
|
|
49298
49230
|
function readLocalDaemonMaintenanceLease(configPath, nowMs = Date.now()) {
|
|
49299
49231
|
const path2 = maintenanceLeasePath(configPath);
|
|
49300
|
-
if (!(0,
|
|
49232
|
+
if (!(0, import_node_fs9.existsSync)(path2)) return null;
|
|
49301
49233
|
try {
|
|
49302
|
-
const lease = JSON.parse((0,
|
|
49234
|
+
const lease = JSON.parse((0, import_node_fs9.readFileSync)(path2, "utf8"));
|
|
49303
49235
|
if (lease.version !== 1 || typeof lease.id !== "string" || lease.reason !== "credential_cleanup" && lease.reason !== "credential_swap" && lease.reason !== "daemon_startup" && lease.reason !== "watchdog" || !(lease.reason === "credential_cleanup" && lease.expiresAtMs === null || typeof lease.expiresAtMs === "number" && Number.isFinite(lease.expiresAtMs))) {
|
|
49304
49236
|
throw new Error("invalid maintenance lease");
|
|
49305
49237
|
}
|
|
@@ -49316,8 +49248,8 @@ function readLocalDaemonMaintenanceLease(configPath, nowMs = Date.now()) {
|
|
|
49316
49248
|
expiresAtMs: nowMs + 5e3
|
|
49317
49249
|
};
|
|
49318
49250
|
try {
|
|
49319
|
-
(0,
|
|
49320
|
-
(0,
|
|
49251
|
+
(0, import_node_fs9.writeFileSync)(path2, JSON.stringify(fallback), { mode: 384 });
|
|
49252
|
+
(0, import_node_fs9.chmodSync)(path2, 384);
|
|
49321
49253
|
} catch {
|
|
49322
49254
|
}
|
|
49323
49255
|
return fallback;
|
|
@@ -49333,10 +49265,10 @@ function acquireLocalDaemonMaintenanceLease(configPath, reason, ttlMs = 5e3) {
|
|
|
49333
49265
|
expiresAtMs: reason === "credential_cleanup" ? null : Date.now() + Math.max(1e3, Math.min(ttlMs, 6e4))
|
|
49334
49266
|
};
|
|
49335
49267
|
const path2 = maintenanceLeasePath(configPath);
|
|
49336
|
-
(0,
|
|
49268
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(path2), { recursive: true, mode: 448 });
|
|
49337
49269
|
try {
|
|
49338
|
-
(0,
|
|
49339
|
-
(0,
|
|
49270
|
+
(0, import_node_fs9.writeFileSync)(path2, JSON.stringify(lease), { mode: 384, flag: "wx" });
|
|
49271
|
+
(0, import_node_fs9.chmodSync)(path2, 384);
|
|
49340
49272
|
return { acquired: true, lease };
|
|
49341
49273
|
} catch (error61) {
|
|
49342
49274
|
const raced = readLocalDaemonMaintenanceLease(configPath);
|
|
@@ -49352,9 +49284,9 @@ function daemonOwnerLeasePath(configPath) {
|
|
|
49352
49284
|
}
|
|
49353
49285
|
function readLocalDaemonOwnerLease(configPath) {
|
|
49354
49286
|
const path2 = daemonOwnerLeasePath(configPath);
|
|
49355
|
-
if (!(0,
|
|
49287
|
+
if (!(0, import_node_fs9.existsSync)(path2)) return null;
|
|
49356
49288
|
try {
|
|
49357
|
-
const lease = JSON.parse((0,
|
|
49289
|
+
const lease = JSON.parse((0, import_node_fs9.readFileSync)(path2, "utf8"));
|
|
49358
49290
|
if (lease.version !== 1 || typeof lease.id !== "string" || typeof lease.daemonSessionId !== "string" || !Number.isSafeInteger(lease.pid) || lease.pid <= 0 || typeof lease.startedAtMs !== "number" || !Number.isFinite(lease.startedAtMs) || typeof lease.runtimeId !== "string" || typeof lease.localServiceId !== "string" || !Number.isSafeInteger(lease.localApiPort) || lease.localApiPort < 0 || lease.localApiPort > 65535 || typeof lease.localApiToken !== "string" || lease.localApiToken.length === 0) {
|
|
49359
49291
|
throw new Error("invalid daemon owner lease");
|
|
49360
49292
|
}
|
|
@@ -49409,10 +49341,10 @@ async function acquireLocalDaemonOwnerLease(input2) {
|
|
|
49409
49341
|
localApiToken: input2.localApiToken
|
|
49410
49342
|
};
|
|
49411
49343
|
const path2 = daemonOwnerLeasePath(input2.configPath);
|
|
49412
|
-
(0,
|
|
49344
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(path2), { recursive: true, mode: 448 });
|
|
49413
49345
|
try {
|
|
49414
|
-
(0,
|
|
49415
|
-
(0,
|
|
49346
|
+
(0, import_node_fs9.writeFileSync)(path2, JSON.stringify(lease), { mode: 384, flag: "wx" });
|
|
49347
|
+
(0, import_node_fs9.chmodSync)(path2, 384);
|
|
49416
49348
|
return { acquired: true, lease };
|
|
49417
49349
|
} catch (error61) {
|
|
49418
49350
|
const raced = readLocalDaemonOwnerLease(input2.configPath);
|
|
@@ -49427,12 +49359,12 @@ function updateLocalDaemonOwnerEndpoint(configPath, lease, localApiPort) {
|
|
|
49427
49359
|
const path2 = daemonOwnerLeasePath(configPath);
|
|
49428
49360
|
const pendingPath = `${path2}.pending-${lease.id}`;
|
|
49429
49361
|
try {
|
|
49430
|
-
(0,
|
|
49431
|
-
(0,
|
|
49432
|
-
(0,
|
|
49362
|
+
(0, import_node_fs9.writeFileSync)(pendingPath, JSON.stringify(updated), { mode: 384 });
|
|
49363
|
+
(0, import_node_fs9.chmodSync)(pendingPath, 384);
|
|
49364
|
+
(0, import_node_fs9.renameSync)(pendingPath, path2);
|
|
49433
49365
|
return updated;
|
|
49434
49366
|
} finally {
|
|
49435
|
-
(0,
|
|
49367
|
+
(0, import_node_fs9.rmSync)(pendingPath, { force: true });
|
|
49436
49368
|
}
|
|
49437
49369
|
}
|
|
49438
49370
|
function releaseLocalDaemonOwnerLease(configPath, leaseId) {
|
|
@@ -49441,13 +49373,13 @@ function releaseLocalDaemonOwnerLease(configPath, leaseId) {
|
|
|
49441
49373
|
function releaseOwnedJsonFile(path2, ownerId, ownerField = "id") {
|
|
49442
49374
|
const releasePath = `${path2}.release-${process.pid}-${(0, import_node_crypto5.randomBytes)(6).toString("hex")}`;
|
|
49443
49375
|
try {
|
|
49444
|
-
(0,
|
|
49376
|
+
(0, import_node_fs9.renameSync)(path2, releasePath);
|
|
49445
49377
|
} catch (error61) {
|
|
49446
49378
|
if (error61.code === "ENOENT") return;
|
|
49447
49379
|
throw error61;
|
|
49448
49380
|
}
|
|
49449
49381
|
try {
|
|
49450
|
-
const content = (0,
|
|
49382
|
+
const content = (0, import_node_fs9.readFileSync)(releasePath, "utf8");
|
|
49451
49383
|
let capturedOwnerId = null;
|
|
49452
49384
|
try {
|
|
49453
49385
|
const captured = JSON.parse(content);
|
|
@@ -49456,13 +49388,13 @@ function releaseOwnedJsonFile(path2, ownerId, ownerField = "id") {
|
|
|
49456
49388
|
}
|
|
49457
49389
|
if (capturedOwnerId === ownerId) return;
|
|
49458
49390
|
try {
|
|
49459
|
-
(0,
|
|
49460
|
-
(0,
|
|
49391
|
+
(0, import_node_fs9.writeFileSync)(path2, content, { mode: 384, flag: "wx" });
|
|
49392
|
+
(0, import_node_fs9.chmodSync)(path2, 384);
|
|
49461
49393
|
} catch (error61) {
|
|
49462
49394
|
if (error61.code !== "EEXIST") throw error61;
|
|
49463
49395
|
}
|
|
49464
49396
|
} finally {
|
|
49465
|
-
(0,
|
|
49397
|
+
(0, import_node_fs9.rmSync)(releasePath, { force: true });
|
|
49466
49398
|
}
|
|
49467
49399
|
}
|
|
49468
49400
|
function inspectLocalDaemonRunJournal(configPath) {
|
|
@@ -49472,8 +49404,8 @@ function inspectLocalDaemonRunJournal(configPath) {
|
|
|
49472
49404
|
try {
|
|
49473
49405
|
let activeRunCount = 0;
|
|
49474
49406
|
for (const artifact of [path2, pendingPath]) {
|
|
49475
|
-
if (!(0,
|
|
49476
|
-
const parsed = JSON.parse((0,
|
|
49407
|
+
if (!(0, import_node_fs9.existsSync)(artifact)) continue;
|
|
49408
|
+
const parsed = JSON.parse((0, import_node_fs9.readFileSync)(artifact, "utf8"));
|
|
49477
49409
|
if (parsed.version !== 1 || !Array.isArray(parsed.entries))
|
|
49478
49410
|
throw new Error("invalid journal");
|
|
49479
49411
|
if (artifact === path2) {
|
|
@@ -49492,7 +49424,7 @@ function inspectLocalDaemonRunJournal(configPath) {
|
|
|
49492
49424
|
}).length;
|
|
49493
49425
|
continue;
|
|
49494
49426
|
}
|
|
49495
|
-
const legacyStartedAtMs = (0,
|
|
49427
|
+
const legacyStartedAtMs = (0, import_node_fs9.statSync)(pendingPath).mtimeMs;
|
|
49496
49428
|
activeRunCount += parsed.entries.filter((entry) => {
|
|
49497
49429
|
if (!entry || typeof entry !== "object") throw new Error("invalid pending run entry");
|
|
49498
49430
|
const startedAtMs = entry.startedAtMs;
|
|
@@ -49519,9 +49451,9 @@ function setupTokenHash(setupToken) {
|
|
|
49519
49451
|
function getOrCreateSetupAttemptId(setupToken) {
|
|
49520
49452
|
const intentPath = pendingSetupIntentPath();
|
|
49521
49453
|
const tokenHash = setupTokenHash(setupToken);
|
|
49522
|
-
if ((0,
|
|
49454
|
+
if ((0, import_node_fs9.existsSync)(intentPath)) {
|
|
49523
49455
|
try {
|
|
49524
|
-
const stored = JSON.parse((0,
|
|
49456
|
+
const stored = JSON.parse((0, import_node_fs9.readFileSync)(intentPath, "utf8"));
|
|
49525
49457
|
if (stored.setupTokenHash === tokenHash && typeof stored.registrationAttemptId === "string" && stored.registrationAttemptId.length > 0) {
|
|
49526
49458
|
return stored.registrationAttemptId;
|
|
49527
49459
|
}
|
|
@@ -49529,23 +49461,23 @@ function getOrCreateSetupAttemptId(setupToken) {
|
|
|
49529
49461
|
}
|
|
49530
49462
|
}
|
|
49531
49463
|
const registrationAttemptId = (0, import_node_crypto5.randomUUID)();
|
|
49532
|
-
(0,
|
|
49464
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(intentPath), { recursive: true, mode: 448 });
|
|
49533
49465
|
const writePath = `${intentPath}.pending-${process.pid}-${(0, import_node_crypto5.randomBytes)(6).toString("hex")}`;
|
|
49534
49466
|
try {
|
|
49535
|
-
(0,
|
|
49467
|
+
(0, import_node_fs9.writeFileSync)(
|
|
49536
49468
|
writePath,
|
|
49537
49469
|
JSON.stringify({ setupTokenHash: tokenHash, registrationAttemptId }, null, 2),
|
|
49538
49470
|
{ mode: 384 }
|
|
49539
49471
|
);
|
|
49540
|
-
(0,
|
|
49541
|
-
(0,
|
|
49472
|
+
(0, import_node_fs9.chmodSync)(writePath, 384);
|
|
49473
|
+
(0, import_node_fs9.renameSync)(writePath, intentPath);
|
|
49542
49474
|
} finally {
|
|
49543
|
-
(0,
|
|
49475
|
+
(0, import_node_fs9.rmSync)(writePath, { force: true });
|
|
49544
49476
|
}
|
|
49545
49477
|
return registrationAttemptId;
|
|
49546
49478
|
}
|
|
49547
49479
|
function clearPendingSetupIntent() {
|
|
49548
|
-
(0,
|
|
49480
|
+
(0, import_node_fs9.rmSync)(pendingSetupIntentPath(), { force: true });
|
|
49549
49481
|
}
|
|
49550
49482
|
function pendingDeviceAuthorizationPath() {
|
|
49551
49483
|
return `${getConfigPath()}.device-auth-pending`;
|
|
@@ -49566,8 +49498,8 @@ function parseDeviceAuthorizationOperationContent(content) {
|
|
|
49566
49498
|
}
|
|
49567
49499
|
function restoreCapturedFileUnlessReplaced(path2, content) {
|
|
49568
49500
|
try {
|
|
49569
|
-
(0,
|
|
49570
|
-
(0,
|
|
49501
|
+
(0, import_node_fs9.writeFileSync)(path2, content, { mode: 384, flag: "wx" });
|
|
49502
|
+
(0, import_node_fs9.chmodSync)(path2, 384);
|
|
49571
49503
|
} catch (error61) {
|
|
49572
49504
|
if (error61.code !== "EEXIST") throw error61;
|
|
49573
49505
|
}
|
|
@@ -49575,26 +49507,26 @@ function restoreCapturedFileUnlessReplaced(path2, content) {
|
|
|
49575
49507
|
function quarantineCorruptDeviceAuthorizationOperation(path2) {
|
|
49576
49508
|
const quarantinePath = `${path2}.corrupt-${process.pid}-${(0, import_node_crypto5.randomBytes)(6).toString("hex")}`;
|
|
49577
49509
|
try {
|
|
49578
|
-
(0,
|
|
49510
|
+
(0, import_node_fs9.renameSync)(path2, quarantinePath);
|
|
49579
49511
|
} catch (error61) {
|
|
49580
49512
|
if (error61.code === "ENOENT") return null;
|
|
49581
49513
|
throw error61;
|
|
49582
49514
|
}
|
|
49583
49515
|
try {
|
|
49584
|
-
const capturedContent = (0,
|
|
49516
|
+
const capturedContent = (0, import_node_fs9.readFileSync)(quarantinePath, "utf8");
|
|
49585
49517
|
if (parseDeviceAuthorizationOperationContent(capturedContent)) {
|
|
49586
49518
|
restoreCapturedFileUnlessReplaced(path2, capturedContent);
|
|
49587
49519
|
}
|
|
49588
49520
|
} finally {
|
|
49589
|
-
(0,
|
|
49521
|
+
(0, import_node_fs9.rmSync)(quarantinePath, { force: true });
|
|
49590
49522
|
}
|
|
49591
|
-
if (!(0,
|
|
49592
|
-
return parseDeviceAuthorizationOperationContent((0,
|
|
49523
|
+
if (!(0, import_node_fs9.existsSync)(path2)) return null;
|
|
49524
|
+
return parseDeviceAuthorizationOperationContent((0, import_node_fs9.readFileSync)(path2, "utf8"));
|
|
49593
49525
|
}
|
|
49594
49526
|
function readDeviceAuthorizationOperation() {
|
|
49595
49527
|
const path2 = deviceAuthorizationOperationPath();
|
|
49596
|
-
if (!(0,
|
|
49597
|
-
const parsed = parseDeviceAuthorizationOperationContent((0,
|
|
49528
|
+
if (!(0, import_node_fs9.existsSync)(path2)) return null;
|
|
49529
|
+
const parsed = parseDeviceAuthorizationOperationContent((0, import_node_fs9.readFileSync)(path2, "utf8"));
|
|
49598
49530
|
const lease = parsed ?? quarantineCorruptDeviceAuthorizationOperation(path2);
|
|
49599
49531
|
if (!lease) return null;
|
|
49600
49532
|
if (lease.expiresAtMs <= Date.now()) {
|
|
@@ -49612,10 +49544,10 @@ function acquireDeviceAuthorizationOperation() {
|
|
|
49612
49544
|
expiresAtMs: Date.now() + 6e4
|
|
49613
49545
|
};
|
|
49614
49546
|
const path2 = deviceAuthorizationOperationPath();
|
|
49615
|
-
(0,
|
|
49547
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(path2), { recursive: true, mode: 448 });
|
|
49616
49548
|
try {
|
|
49617
|
-
(0,
|
|
49618
|
-
(0,
|
|
49549
|
+
(0, import_node_fs9.writeFileSync)(path2, JSON.stringify(lease), { mode: 384, flag: "wx" });
|
|
49550
|
+
(0, import_node_fs9.chmodSync)(path2, 384);
|
|
49619
49551
|
return lease;
|
|
49620
49552
|
} catch (error61) {
|
|
49621
49553
|
if (error61.code === "EEXIST") return null;
|
|
@@ -49630,15 +49562,15 @@ function extendDeviceAuthorizationOperation(operationId, expiresAtMs) {
|
|
|
49630
49562
|
const path2 = deviceAuthorizationOperationPath();
|
|
49631
49563
|
const pendingPath = `${path2}.pending-${process.pid}-${(0, import_node_crypto5.randomBytes)(6).toString("hex")}`;
|
|
49632
49564
|
try {
|
|
49633
|
-
(0,
|
|
49565
|
+
(0, import_node_fs9.writeFileSync)(
|
|
49634
49566
|
pendingPath,
|
|
49635
49567
|
JSON.stringify({ ...current, expiresAtMs: Math.max(expiresAtMs, Date.now() + 6e4) }),
|
|
49636
49568
|
{ mode: 384 }
|
|
49637
49569
|
);
|
|
49638
|
-
(0,
|
|
49639
|
-
(0,
|
|
49570
|
+
(0, import_node_fs9.chmodSync)(pendingPath, 384);
|
|
49571
|
+
(0, import_node_fs9.renameSync)(pendingPath, path2);
|
|
49640
49572
|
} finally {
|
|
49641
|
-
(0,
|
|
49573
|
+
(0, import_node_fs9.rmSync)(pendingPath, { force: true });
|
|
49642
49574
|
}
|
|
49643
49575
|
}
|
|
49644
49576
|
function assertDeviceAuthorizationOperationOwner(operationId) {
|
|
@@ -49649,12 +49581,12 @@ function assertDeviceAuthorizationOperationOwner(operationId) {
|
|
|
49649
49581
|
function clearPendingDeviceAuthorization(operationId) {
|
|
49650
49582
|
const path2 = pendingDeviceAuthorizationPath();
|
|
49651
49583
|
if (!operationId) {
|
|
49652
|
-
(0,
|
|
49584
|
+
(0, import_node_fs9.rmSync)(path2, { force: true });
|
|
49653
49585
|
return;
|
|
49654
49586
|
}
|
|
49655
|
-
if (!(0,
|
|
49587
|
+
if (!(0, import_node_fs9.existsSync)(path2)) return;
|
|
49656
49588
|
try {
|
|
49657
|
-
const pending = JSON.parse((0,
|
|
49589
|
+
const pending = JSON.parse((0, import_node_fs9.readFileSync)(path2, "utf8"));
|
|
49658
49590
|
if (pending.operationId !== operationId) return;
|
|
49659
49591
|
} catch {
|
|
49660
49592
|
return;
|
|
@@ -49663,9 +49595,9 @@ function clearPendingDeviceAuthorization(operationId) {
|
|
|
49663
49595
|
}
|
|
49664
49596
|
function readPendingDeviceAuthorization(apiUrl) {
|
|
49665
49597
|
const path2 = pendingDeviceAuthorizationPath();
|
|
49666
|
-
if (!(0,
|
|
49598
|
+
if (!(0, import_node_fs9.existsSync)(path2)) return null;
|
|
49667
49599
|
try {
|
|
49668
|
-
const pending = JSON.parse((0,
|
|
49600
|
+
const pending = JSON.parse((0, import_node_fs9.readFileSync)(path2, "utf8"));
|
|
49669
49601
|
const expiresAtMs = Date.parse(pending.expiresAt ?? "");
|
|
49670
49602
|
if (pending.apiUrl !== apiUrl || typeof pending.deviceCode !== "string" || typeof pending.userCode !== "string" || typeof pending.verificationUri !== "string" || typeof pending.installationId !== "string" || pending.operationId !== void 0 && typeof pending.operationId !== "string" || !Number.isFinite(pending.intervalSeconds) || !Number.isFinite(expiresAtMs) || expiresAtMs <= Date.now()) {
|
|
49671
49603
|
return null;
|
|
@@ -49677,20 +49609,20 @@ function readPendingDeviceAuthorization(apiUrl) {
|
|
|
49677
49609
|
}
|
|
49678
49610
|
function writePendingDeviceAuthorization(pending) {
|
|
49679
49611
|
const path2 = pendingDeviceAuthorizationPath();
|
|
49680
|
-
(0,
|
|
49612
|
+
(0, import_node_fs9.mkdirSync)((0, import_node_path10.dirname)(path2), { recursive: true, mode: 448 });
|
|
49681
49613
|
const writePath = `${path2}.pending-${process.pid}-${(0, import_node_crypto5.randomBytes)(6).toString("hex")}`;
|
|
49682
49614
|
try {
|
|
49683
|
-
(0,
|
|
49684
|
-
(0,
|
|
49685
|
-
(0,
|
|
49615
|
+
(0, import_node_fs9.writeFileSync)(writePath, JSON.stringify(pending, null, 2), { mode: 384 });
|
|
49616
|
+
(0, import_node_fs9.chmodSync)(writePath, 384);
|
|
49617
|
+
(0, import_node_fs9.renameSync)(writePath, path2);
|
|
49686
49618
|
} finally {
|
|
49687
|
-
(0,
|
|
49619
|
+
(0, import_node_fs9.rmSync)(writePath, { force: true });
|
|
49688
49620
|
}
|
|
49689
49621
|
}
|
|
49690
49622
|
function removeAlanOwnedLocalArtifacts() {
|
|
49691
49623
|
const configPath = getConfigPath();
|
|
49692
|
-
const directory = (0,
|
|
49693
|
-
const configName = (0,
|
|
49624
|
+
const directory = (0, import_node_path10.dirname)(configPath);
|
|
49625
|
+
const configName = (0, import_node_path10.basename)(configPath).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
49694
49626
|
const alanAtomicSidecarPattern = new RegExp(
|
|
49695
49627
|
`^${configName}(?:|\\.setup-pending|\\.device-auth-pending|\\.device-auth-operation\\.json|\\.maintenance-lease\\.json|\\.event-outbox\\.enc)\\.(?:pending|release|corrupt)-\\d+-[a-f0-9]{12}$`
|
|
49696
49628
|
);
|
|
@@ -49707,19 +49639,26 @@ function removeAlanOwnedLocalArtifacts() {
|
|
|
49707
49639
|
`${configPath}.pending-runs.json.pending`,
|
|
49708
49640
|
maintenanceLeasePath(configPath)
|
|
49709
49641
|
]);
|
|
49710
|
-
if ((0,
|
|
49711
|
-
for (const entry of (0,
|
|
49712
|
-
if (alanAtomicSidecarPattern.test(entry)) artifacts.add((0,
|
|
49642
|
+
if ((0, import_node_fs9.existsSync)(directory)) {
|
|
49643
|
+
for (const entry of (0, import_node_fs9.readdirSync)(directory)) {
|
|
49644
|
+
if (alanAtomicSidecarPattern.test(entry)) artifacts.add((0, import_node_path10.join)(directory, entry));
|
|
49713
49645
|
}
|
|
49714
49646
|
}
|
|
49715
|
-
for (const artifact of artifacts) (0,
|
|
49716
|
-
|
|
49647
|
+
for (const artifact of artifacts) (0, import_node_fs9.rmSync)(artifact, { force: true });
|
|
49648
|
+
for (const encryptedDirectory of [
|
|
49649
|
+
`${configPath}.event-outbox.enc.journal`,
|
|
49650
|
+
`${configPath}.native-streams`,
|
|
49651
|
+
(0, import_node_path10.join)(directory, "native-hook-inbox")
|
|
49652
|
+
]) {
|
|
49653
|
+
(0, import_node_fs9.rmSync)(encryptedDirectory, { recursive: true, force: true });
|
|
49654
|
+
}
|
|
49655
|
+
(0, import_node_fs9.rmSync)(configPath, { force: true });
|
|
49717
49656
|
}
|
|
49718
49657
|
|
|
49719
49658
|
// src/provider-model-discovery.ts
|
|
49720
|
-
var
|
|
49659
|
+
var import_node_fs10 = require("fs");
|
|
49721
49660
|
var import_node_os6 = require("os");
|
|
49722
|
-
var
|
|
49661
|
+
var import_node_path11 = require("path");
|
|
49723
49662
|
var MODEL_DISCOVERY_TIMEOUT_MS = 8e3;
|
|
49724
49663
|
var ANTIGRAVITY_MODEL_DISCOVERY_TIMEOUT_MS = 12e3;
|
|
49725
49664
|
var OPENCODE_ZEN_MODEL_IDS = OPENCODE_ZEN_MODELS.map((model) => model.id);
|
|
@@ -49931,7 +49870,7 @@ function filterClaudeDatedModelIds(ids) {
|
|
|
49931
49870
|
}
|
|
49932
49871
|
function resolveExecutableForModelScan(executable) {
|
|
49933
49872
|
try {
|
|
49934
|
-
return (0,
|
|
49873
|
+
return (0, import_node_fs10.realpathSync)(executable);
|
|
49935
49874
|
} catch {
|
|
49936
49875
|
return executable;
|
|
49937
49876
|
}
|
|
@@ -49939,7 +49878,7 @@ function resolveExecutableForModelScan(executable) {
|
|
|
49939
49878
|
function extractClaudeModelIdsFromExecutable(executable) {
|
|
49940
49879
|
try {
|
|
49941
49880
|
const resolved = resolveExecutableForModelScan(executable);
|
|
49942
|
-
const text = (0,
|
|
49881
|
+
const text = (0, import_node_fs10.readFileSync)(resolved).toString("latin1");
|
|
49943
49882
|
const matches = text.match(CLAUDE_MODEL_ID_PATTERN) ?? [];
|
|
49944
49883
|
const unique2 = [
|
|
49945
49884
|
...new Set(matches.map((id) => id.trim()).filter((id) => isValidClaudeModelId(id))),
|
|
@@ -49998,9 +49937,9 @@ function readOpenCodeZenCredential(env) {
|
|
|
49998
49937
|
function readOpenCodeAuthDocument(env) {
|
|
49999
49938
|
const injected = env.OPENCODE_AUTH_CONTENT?.trim();
|
|
50000
49939
|
if (injected) return injected;
|
|
50001
|
-
const dataHome = env.XDG_DATA_HOME?.trim() || (0,
|
|
49940
|
+
const dataHome = env.XDG_DATA_HOME?.trim() || (0, import_node_path11.join)((0, import_node_os6.homedir)(), ".local", "share");
|
|
50002
49941
|
try {
|
|
50003
|
-
return (0,
|
|
49942
|
+
return (0, import_node_fs10.readFileSync)((0, import_node_path11.join)(dataHome, "opencode", "auth.json"), "utf8");
|
|
50004
49943
|
} catch {
|
|
50005
49944
|
return null;
|
|
50006
49945
|
}
|
|
@@ -50083,11 +50022,11 @@ function applyZenEntitlement(discovery, entitled) {
|
|
|
50083
50022
|
var OPENCODE_CATALOGUE_CACHE_SEGMENTS = ["opencode", "models.json"];
|
|
50084
50023
|
var OPENCODE_CACHE_PROVIDER_KEYS = ["opencode", "opencode-go"];
|
|
50085
50024
|
function readOpenCodeCatalogueCache(env) {
|
|
50086
|
-
const cacheHome = env.XDG_CACHE_HOME?.trim() || (0,
|
|
50025
|
+
const cacheHome = env.XDG_CACHE_HOME?.trim() || (0, import_node_path11.join)((0, import_node_os6.homedir)(), ".cache");
|
|
50087
50026
|
let parsed;
|
|
50088
50027
|
try {
|
|
50089
50028
|
parsed = JSON.parse(
|
|
50090
|
-
(0,
|
|
50029
|
+
(0, import_node_fs10.readFileSync)((0, import_node_path11.join)(cacheHome, ...OPENCODE_CATALOGUE_CACHE_SEGMENTS), "utf8")
|
|
50091
50030
|
);
|
|
50092
50031
|
} catch {
|
|
50093
50032
|
return null;
|
|
@@ -54250,11 +54189,11 @@ Object.assign(lookup, {
|
|
|
54250
54189
|
});
|
|
54251
54190
|
|
|
54252
54191
|
// src/binding-switch-git.ts
|
|
54253
|
-
var
|
|
54192
|
+
var import_node_child_process6 = require("child_process");
|
|
54254
54193
|
var import_node_crypto6 = require("crypto");
|
|
54255
|
-
var
|
|
54194
|
+
var import_node_fs11 = require("fs");
|
|
54256
54195
|
var import_node_os7 = require("os");
|
|
54257
|
-
var
|
|
54196
|
+
var import_node_path12 = require("path");
|
|
54258
54197
|
var import_node_url = require("url");
|
|
54259
54198
|
var BINDING_SWITCH_GIT_METHODS = [
|
|
54260
54199
|
"git.status",
|
|
@@ -54279,7 +54218,7 @@ var LOCAL_GIT_TIMEOUT_MS = 1e4;
|
|
|
54279
54218
|
var NETWORK_GIT_TIMEOUT_MS = 3e4;
|
|
54280
54219
|
var MAX_GIT_OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
54281
54220
|
function runGitResult(cwd, args, options = {}) {
|
|
54282
|
-
const result = (0,
|
|
54221
|
+
const result = (0, import_node_child_process6.spawnSync)("git", args, {
|
|
54283
54222
|
cwd,
|
|
54284
54223
|
env: { ...getDaemonCliEnvironment(), ...options.env },
|
|
54285
54224
|
encoding: "utf8",
|
|
@@ -54304,12 +54243,12 @@ function networkGitTimeoutMs() {
|
|
|
54304
54243
|
async function waitForCheckpointTestBarrier() {
|
|
54305
54244
|
const barrierDir = process.env.NODE_ENV === "test" ? process.env.ALAN_TEST_GIT_CHECKPOINT_BARRIER_DIR : void 0;
|
|
54306
54245
|
if (!barrierDir) return;
|
|
54307
|
-
(0,
|
|
54308
|
-
const readyPath = (0,
|
|
54309
|
-
const releasePath = (0,
|
|
54310
|
-
(0,
|
|
54246
|
+
(0, import_node_fs11.mkdirSync)(barrierDir, { recursive: true });
|
|
54247
|
+
const readyPath = (0, import_node_path12.join)(barrierDir, "ready");
|
|
54248
|
+
const releasePath = (0, import_node_path12.join)(barrierDir, "release");
|
|
54249
|
+
(0, import_node_fs11.writeFileSync)(readyPath, "ready\n");
|
|
54311
54250
|
const deadline = Date.now() + 5e3;
|
|
54312
|
-
while (!(0,
|
|
54251
|
+
while (!(0, import_node_fs11.existsSync)(releasePath)) {
|
|
54313
54252
|
if (Date.now() >= deadline) {
|
|
54314
54253
|
throw new BindingSwitchGitError(
|
|
54315
54254
|
"checkpoint_prepare_timeout",
|
|
@@ -54322,12 +54261,12 @@ async function waitForCheckpointTestBarrier() {
|
|
|
54322
54261
|
async function waitForCheckpointFinalizeTestBarrier() {
|
|
54323
54262
|
const barrierDir = process.env.NODE_ENV === "test" ? process.env.ALAN_TEST_GIT_CHECKPOINT_FINALIZE_BARRIER_DIR : void 0;
|
|
54324
54263
|
if (!barrierDir) return;
|
|
54325
|
-
(0,
|
|
54326
|
-
const readyPath = (0,
|
|
54327
|
-
const releasePath = (0,
|
|
54328
|
-
(0,
|
|
54264
|
+
(0, import_node_fs11.mkdirSync)(barrierDir, { recursive: true });
|
|
54265
|
+
const readyPath = (0, import_node_path12.join)(barrierDir, "ready");
|
|
54266
|
+
const releasePath = (0, import_node_path12.join)(barrierDir, "release");
|
|
54267
|
+
(0, import_node_fs11.writeFileSync)(readyPath, "ready\n");
|
|
54329
54268
|
const deadline = Date.now() + 5e3;
|
|
54330
|
-
while (!(0,
|
|
54269
|
+
while (!(0, import_node_fs11.existsSync)(releasePath)) {
|
|
54331
54270
|
if (Date.now() >= deadline) {
|
|
54332
54271
|
throw new BindingSwitchGitError(
|
|
54333
54272
|
"checkpoint_finalize_timeout",
|
|
@@ -54339,7 +54278,7 @@ async function waitForCheckpointFinalizeTestBarrier() {
|
|
|
54339
54278
|
}
|
|
54340
54279
|
async function runNetworkGit(cwd, args, code) {
|
|
54341
54280
|
return new Promise((resolvePromise, rejectPromise) => {
|
|
54342
|
-
const child = (0,
|
|
54281
|
+
const child = (0, import_node_child_process6.spawn)("git", args, {
|
|
54343
54282
|
cwd,
|
|
54344
54283
|
env: {
|
|
54345
54284
|
...getDaemonCliEnvironment(),
|
|
@@ -54440,7 +54379,7 @@ function sourceChangedDuringCheckpoint(message) {
|
|
|
54440
54379
|
}
|
|
54441
54380
|
function acquireCheckpointHeadLock(locks) {
|
|
54442
54381
|
try {
|
|
54443
|
-
(0,
|
|
54382
|
+
(0, import_node_fs11.writeFileSync)(locks.headLockPath, "", { flag: "wx" });
|
|
54444
54383
|
locks.headLockHeld = true;
|
|
54445
54384
|
} catch {
|
|
54446
54385
|
throw sourceChangedDuringCheckpoint(
|
|
@@ -54450,7 +54389,7 @@ function acquireCheckpointHeadLock(locks) {
|
|
|
54450
54389
|
}
|
|
54451
54390
|
function releaseCheckpointHeadLock(locks) {
|
|
54452
54391
|
if (!locks.headLockHeld) return;
|
|
54453
|
-
(0,
|
|
54392
|
+
(0, import_node_fs11.rmSync)(locks.headLockPath, { force: true });
|
|
54454
54393
|
locks.headLockHeld = false;
|
|
54455
54394
|
}
|
|
54456
54395
|
function acquireCheckpointRepositoryLocks(repoRoot) {
|
|
@@ -54465,20 +54404,20 @@ function acquireCheckpointRepositoryLocks(repoRoot) {
|
|
|
54465
54404
|
"checkpoint_lock_unavailable"
|
|
54466
54405
|
);
|
|
54467
54406
|
const locks = {
|
|
54468
|
-
headLockPath: (0,
|
|
54407
|
+
headLockPath: (0, import_node_path12.join)(gitDir, "HEAD.lock"),
|
|
54469
54408
|
headLockHeld: false,
|
|
54470
54409
|
indexLockPath: `${indexPath}.lock`,
|
|
54471
54410
|
indexLockHeld: false,
|
|
54472
54411
|
indexPath
|
|
54473
54412
|
};
|
|
54474
54413
|
try {
|
|
54475
|
-
(0,
|
|
54414
|
+
(0, import_node_fs11.writeFileSync)(locks.indexLockPath, "", { flag: "wx" });
|
|
54476
54415
|
locks.indexLockHeld = true;
|
|
54477
54416
|
acquireCheckpointHeadLock(locks);
|
|
54478
54417
|
return locks;
|
|
54479
54418
|
} catch {
|
|
54480
54419
|
if (locks.indexLockHeld) {
|
|
54481
|
-
(0,
|
|
54420
|
+
(0, import_node_fs11.rmSync)(locks.indexLockPath, { force: true });
|
|
54482
54421
|
locks.indexLockHeld = false;
|
|
54483
54422
|
}
|
|
54484
54423
|
throw sourceChangedDuringCheckpoint(
|
|
@@ -54489,7 +54428,7 @@ function acquireCheckpointRepositoryLocks(repoRoot) {
|
|
|
54489
54428
|
function releaseCheckpointRepositoryLocks(locks) {
|
|
54490
54429
|
releaseCheckpointHeadLock(locks);
|
|
54491
54430
|
if (locks.indexLockHeld) {
|
|
54492
|
-
(0,
|
|
54431
|
+
(0, import_node_fs11.rmSync)(locks.indexLockPath, { force: true });
|
|
54493
54432
|
locks.indexLockHeld = false;
|
|
54494
54433
|
}
|
|
54495
54434
|
}
|
|
@@ -54507,8 +54446,8 @@ function assertCheckpointHead(repoRoot, expectedRef, expectedHeadSha) {
|
|
|
54507
54446
|
}
|
|
54508
54447
|
}
|
|
54509
54448
|
function createCheckpointIndexBaseline(repoRoot, checkpointSha) {
|
|
54510
|
-
const tempDir = (0,
|
|
54511
|
-
const indexPath = (0,
|
|
54449
|
+
const tempDir = (0, import_node_fs11.mkdtempSync)((0, import_node_path12.join)((0, import_node_os7.tmpdir)(), "alan-checkpoint-index-"));
|
|
54450
|
+
const indexPath = (0, import_node_path12.join)(tempDir, "index");
|
|
54512
54451
|
try {
|
|
54513
54452
|
runGitWithOptions(
|
|
54514
54453
|
repoRoot,
|
|
@@ -54518,14 +54457,14 @@ function createCheckpointIndexBaseline(repoRoot, checkpointSha) {
|
|
|
54518
54457
|
);
|
|
54519
54458
|
return { indexPath, tempDir };
|
|
54520
54459
|
} catch (error61) {
|
|
54521
|
-
(0,
|
|
54460
|
+
(0, import_node_fs11.rmSync)(tempDir, { recursive: true, force: true });
|
|
54522
54461
|
throw error61;
|
|
54523
54462
|
}
|
|
54524
54463
|
}
|
|
54525
54464
|
function installCheckpointIndexBaseline(locks, baselineIndexPath) {
|
|
54526
54465
|
try {
|
|
54527
|
-
(0,
|
|
54528
|
-
(0,
|
|
54466
|
+
(0, import_node_fs11.copyFileSync)(baselineIndexPath, locks.indexLockPath);
|
|
54467
|
+
(0, import_node_fs11.renameSync)(locks.indexLockPath, locks.indexPath);
|
|
54529
54468
|
locks.indexLockHeld = false;
|
|
54530
54469
|
} catch (error61) {
|
|
54531
54470
|
throw new BindingSwitchGitError(
|
|
@@ -54569,7 +54508,7 @@ function commonRequest(params) {
|
|
|
54569
54508
|
return {
|
|
54570
54509
|
switchId: requiredString2(params, "switchId"),
|
|
54571
54510
|
repoKey: requiredString2(params, "repoKey"),
|
|
54572
|
-
repoPath: (0,
|
|
54511
|
+
repoPath: (0, import_node_path12.resolve)(requiredString2(params, "repoPath"))
|
|
54573
54512
|
};
|
|
54574
54513
|
}
|
|
54575
54514
|
function assertCommitSha(sha, key) {
|
|
@@ -54581,7 +54520,7 @@ function assertValidBranch(branch) {
|
|
|
54581
54520
|
if (branch.startsWith("-")) {
|
|
54582
54521
|
throw new BindingSwitchGitError("invalid_git_request", "branch is not a safe Git ref");
|
|
54583
54522
|
}
|
|
54584
|
-
const result = (0,
|
|
54523
|
+
const result = (0, import_node_child_process6.spawnSync)("git", ["check-ref-format", "--branch", branch], {
|
|
54585
54524
|
env: getDaemonCliEnvironment(),
|
|
54586
54525
|
encoding: "utf8"
|
|
54587
54526
|
});
|
|
@@ -54603,8 +54542,8 @@ function canonicalRemoteUrl(repoRoot, value2) {
|
|
|
54603
54542
|
}
|
|
54604
54543
|
const scpStyle = trimmed.match(/^([^/@:\s]+)@([^/:\s]+):(.+)$/);
|
|
54605
54544
|
const urlValue = scpStyle ? `ssh://${scpStyle[1]}@${scpStyle[2]}/${scpStyle[3]}` : trimmed;
|
|
54606
|
-
if ((0,
|
|
54607
|
-
const absolute = (0,
|
|
54545
|
+
if ((0, import_node_path12.isAbsolute)(urlValue) || urlValue.startsWith("./") || urlValue.startsWith("../")) {
|
|
54546
|
+
const absolute = (0, import_node_path12.isAbsolute)(urlValue) ? urlValue : (0, import_node_path12.resolve)(repoRoot, urlValue);
|
|
54608
54547
|
return `file://${canonicalPathWithMissingTail(absolute).replace(/\/+$/, "").replace(/\.git$/, "")}`;
|
|
54609
54548
|
}
|
|
54610
54549
|
let parsed;
|
|
@@ -54671,22 +54610,22 @@ function inspectedRemoteUrl(repoRoot, params) {
|
|
|
54671
54610
|
}
|
|
54672
54611
|
function canonicalPathWithMissingTail(path2) {
|
|
54673
54612
|
const missingSegments = [];
|
|
54674
|
-
let cursor2 = (0,
|
|
54675
|
-
while (!(0,
|
|
54676
|
-
const parent = (0,
|
|
54613
|
+
let cursor2 = (0, import_node_path12.resolve)(path2);
|
|
54614
|
+
while (!(0, import_node_fs11.existsSync)(cursor2)) {
|
|
54615
|
+
const parent = (0, import_node_path12.dirname)(cursor2);
|
|
54677
54616
|
if (parent === cursor2) {
|
|
54678
54617
|
throw new BindingSwitchGitError(
|
|
54679
54618
|
"path_canonicalization_failed",
|
|
54680
54619
|
"The selected path has no existing canonical ancestor"
|
|
54681
54620
|
);
|
|
54682
54621
|
}
|
|
54683
|
-
missingSegments.unshift((0,
|
|
54622
|
+
missingSegments.unshift((0, import_node_path12.basename)(cursor2));
|
|
54684
54623
|
cursor2 = parent;
|
|
54685
54624
|
}
|
|
54686
|
-
return (0,
|
|
54625
|
+
return (0, import_node_path12.join)(import_node_fs11.realpathSync.native(cursor2), ...missingSegments);
|
|
54687
54626
|
}
|
|
54688
54627
|
function resolveRepositoryRoot(requestedPath) {
|
|
54689
|
-
if (!(0,
|
|
54628
|
+
if (!(0, import_node_fs11.existsSync)(requestedPath)) {
|
|
54690
54629
|
throw new BindingSwitchGitError(
|
|
54691
54630
|
"repository_not_found",
|
|
54692
54631
|
`The selected repository path does not exist: ${requestedPath}`
|
|
@@ -54699,7 +54638,7 @@ function resolveRepositoryRoot(requestedPath) {
|
|
|
54699
54638
|
"The selected folder is not inside a Git repository"
|
|
54700
54639
|
);
|
|
54701
54640
|
}
|
|
54702
|
-
return
|
|
54641
|
+
return import_node_fs11.realpathSync.native((0, import_node_path12.resolve)(root.stdout.trim()));
|
|
54703
54642
|
}
|
|
54704
54643
|
function listWorktrees(repoRoot) {
|
|
54705
54644
|
return runGit(repoRoot, ["worktree", "list", "--porcelain"]).split("\n\n").flatMap((entry) => {
|
|
@@ -54718,7 +54657,7 @@ function resolveAuthorizedRepository(params, requireTrustedContext = false) {
|
|
|
54718
54657
|
const { repoPath } = commonRequest(params);
|
|
54719
54658
|
const repoRoot = resolveRepositoryRoot(repoPath);
|
|
54720
54659
|
const expectedRepoRoot = requireTrustedContext ? requiredString2(params, "expectedRepoRoot") : optionalString(params, "expectedRepoRoot");
|
|
54721
|
-
if (expectedRepoRoot && resolveRepositoryRoot((0,
|
|
54660
|
+
if (expectedRepoRoot && resolveRepositoryRoot((0, import_node_path12.resolve)(expectedRepoRoot)) !== repoRoot) {
|
|
54722
54661
|
throw new BindingSwitchGitError(
|
|
54723
54662
|
"repository_path_changed",
|
|
54724
54663
|
"The selected path now resolves to a different Git repository"
|
|
@@ -54726,7 +54665,7 @@ function resolveAuthorizedRepository(params, requireTrustedContext = false) {
|
|
|
54726
54665
|
}
|
|
54727
54666
|
const projectPath = requireTrustedContext ? requiredString2(params, "projectPath") : optionalString(params, "projectPath");
|
|
54728
54667
|
if (!projectPath) return repoRoot;
|
|
54729
|
-
const projectRoot = resolveRepositoryRoot((0,
|
|
54668
|
+
const projectRoot = resolveRepositoryRoot((0, import_node_path12.resolve)(projectPath));
|
|
54730
54669
|
const registrations = listWorktrees(projectRoot);
|
|
54731
54670
|
const registered = registrations.find(({ path: path2 }) => path2 === repoRoot);
|
|
54732
54671
|
if (!registered) {
|
|
@@ -54755,8 +54694,8 @@ function updateLengthPrefixed(hash2, value2) {
|
|
|
54755
54694
|
hash2.update("\0");
|
|
54756
54695
|
}
|
|
54757
54696
|
function proposedTreeSha(repoRoot, headSha) {
|
|
54758
|
-
const tempDir = (0,
|
|
54759
|
-
const indexPath = (0,
|
|
54697
|
+
const tempDir = (0, import_node_fs11.mkdtempSync)((0, import_node_path12.join)((0, import_node_os7.tmpdir)(), "alan-switch-index-"));
|
|
54698
|
+
const indexPath = (0, import_node_path12.join)(tempDir, "index");
|
|
54760
54699
|
const options = { env: { GIT_INDEX_FILE: indexPath } };
|
|
54761
54700
|
try {
|
|
54762
54701
|
if (headSha) {
|
|
@@ -54769,7 +54708,7 @@ function proposedTreeSha(repoRoot, headSha) {
|
|
|
54769
54708
|
assertCommitSha(treeSha, "proposedTreeSha");
|
|
54770
54709
|
return treeSha;
|
|
54771
54710
|
} finally {
|
|
54772
|
-
(0,
|
|
54711
|
+
(0, import_node_fs11.rmSync)(tempDir, { recursive: true, force: true });
|
|
54773
54712
|
}
|
|
54774
54713
|
}
|
|
54775
54714
|
function statusFingerprint(repoRoot, porcelain, proposedTree) {
|
|
@@ -54905,7 +54844,7 @@ async function checkpoint(params) {
|
|
|
54905
54844
|
return { repoRoot, sha: status.headSha, replayed: true };
|
|
54906
54845
|
} finally {
|
|
54907
54846
|
if (locks2) releaseCheckpointRepositoryLocks(locks2);
|
|
54908
|
-
(0,
|
|
54847
|
+
(0, import_node_fs11.rmSync)(baseline2.tempDir, { recursive: true, force: true });
|
|
54909
54848
|
}
|
|
54910
54849
|
}
|
|
54911
54850
|
assertSourcePreconditions(status, expectedHeadSha, expectedStatusFingerprint, expectedBranch);
|
|
@@ -55013,7 +54952,7 @@ Alan-Repository-Id: ${repoKey}`;
|
|
|
55013
54952
|
runGitResult(repoRoot, ["update-ref", expectedRef, expectedHeadSha, sha]);
|
|
55014
54953
|
}
|
|
55015
54954
|
if (locks) releaseCheckpointRepositoryLocks(locks);
|
|
55016
|
-
(0,
|
|
54955
|
+
(0, import_node_fs11.rmSync)(baseline.tempDir, { recursive: true, force: true });
|
|
55017
54956
|
}
|
|
55018
54957
|
}
|
|
55019
54958
|
function resolveRemoteBranch(repoRoot, params) {
|
|
@@ -55251,10 +55190,10 @@ var import_node_fs15 = require("fs");
|
|
|
55251
55190
|
var import_node_path16 = require("path");
|
|
55252
55191
|
|
|
55253
55192
|
// src/cli-ensure-install.ts
|
|
55254
|
-
var
|
|
55255
|
-
var
|
|
55193
|
+
var import_node_child_process7 = require("child_process");
|
|
55194
|
+
var import_node_fs12 = require("fs");
|
|
55256
55195
|
var import_node_os8 = require("os");
|
|
55257
|
-
var
|
|
55196
|
+
var import_node_path13 = require("path");
|
|
55258
55197
|
var CLI_RUNTIME_VERSIONS_ENV = "ALAN_CLI_RUNTIME_VERSIONS";
|
|
55259
55198
|
var installOutcomes = /* @__PURE__ */ new Map();
|
|
55260
55199
|
function canInstallProviderCli(backendKind) {
|
|
@@ -55271,14 +55210,14 @@ function currentRuntimePlatform() {
|
|
|
55271
55210
|
}
|
|
55272
55211
|
function resolveWindowsNpmInvocation(env, npmArgs) {
|
|
55273
55212
|
const searchPath = env.PATH ?? env.Path ?? "";
|
|
55274
|
-
for (const rawDirectory of searchPath.split(
|
|
55213
|
+
for (const rawDirectory of searchPath.split(import_node_path13.delimiter)) {
|
|
55275
55214
|
const directory = rawDirectory.trim().replace(/^"|"$/g, "");
|
|
55276
55215
|
if (!directory) continue;
|
|
55277
|
-
const executable = (0,
|
|
55278
|
-
if ((0,
|
|
55279
|
-
const commandShim = (0,
|
|
55280
|
-
const cliScript = (0,
|
|
55281
|
-
if ((0,
|
|
55216
|
+
const executable = (0, import_node_path13.join)(directory, "npm.exe");
|
|
55217
|
+
if ((0, import_node_fs12.existsSync)(executable)) return { command: executable, args: npmArgs };
|
|
55218
|
+
const commandShim = (0, import_node_path13.join)(directory, "npm.cmd");
|
|
55219
|
+
const cliScript = (0, import_node_path13.join)(directory, "node_modules", "npm", "bin", "npm-cli.js");
|
|
55220
|
+
if ((0, import_node_fs12.existsSync)(commandShim) && (0, import_node_fs12.existsSync)(cliScript)) {
|
|
55282
55221
|
return { command: process.execPath, args: [cliScript, ...npmArgs] };
|
|
55283
55222
|
}
|
|
55284
55223
|
}
|
|
@@ -55300,7 +55239,7 @@ function runNpmInstall(installSpec, env, timeoutMs) {
|
|
|
55300
55239
|
});
|
|
55301
55240
|
return;
|
|
55302
55241
|
}
|
|
55303
|
-
child = (0,
|
|
55242
|
+
child = (0, import_node_child_process7.spawn)(invocation.command, invocation.args, {
|
|
55304
55243
|
env,
|
|
55305
55244
|
windowsHide: isWin ? true : void 0,
|
|
55306
55245
|
timeout: timeoutMs,
|
|
@@ -55383,25 +55322,25 @@ var import_node_os10 = require("os");
|
|
|
55383
55322
|
|
|
55384
55323
|
// src/antigravity-api-key-config.ts
|
|
55385
55324
|
var import_node_crypto7 = require("crypto");
|
|
55386
|
-
var
|
|
55325
|
+
var import_node_fs13 = require("fs");
|
|
55387
55326
|
var import_node_os9 = require("os");
|
|
55388
|
-
var
|
|
55327
|
+
var import_node_path14 = require("path");
|
|
55389
55328
|
var CONFIG_LOCK_STALE_MS = 3e4;
|
|
55390
55329
|
var CONFIG_LOCK_WAIT_MS = 2e3;
|
|
55391
55330
|
var CONFIG_LOCK_POLL_MS = 20;
|
|
55392
55331
|
async function waitForConfigLock(lockPath) {
|
|
55393
|
-
(0,
|
|
55332
|
+
(0, import_node_fs13.mkdirSync)((0, import_node_path14.dirname)(lockPath), { recursive: true });
|
|
55394
55333
|
const startedAt = Date.now();
|
|
55395
55334
|
while (true) {
|
|
55396
55335
|
try {
|
|
55397
|
-
(0,
|
|
55398
|
-
return () => (0,
|
|
55336
|
+
(0, import_node_fs13.mkdirSync)(lockPath);
|
|
55337
|
+
return () => (0, import_node_fs13.rmSync)(lockPath, { recursive: true, force: true });
|
|
55399
55338
|
} catch (error61) {
|
|
55400
55339
|
const code = error61 && typeof error61 === "object" && "code" in error61 ? error61.code : void 0;
|
|
55401
55340
|
if (code !== "EEXIST") throw error61;
|
|
55402
55341
|
try {
|
|
55403
|
-
if (Date.now() - (0,
|
|
55404
|
-
(0,
|
|
55342
|
+
if (Date.now() - (0, import_node_fs13.statSync)(lockPath).mtimeMs > CONFIG_LOCK_STALE_MS) {
|
|
55343
|
+
(0, import_node_fs13.rmSync)(lockPath, { recursive: true, force: true });
|
|
55405
55344
|
continue;
|
|
55406
55345
|
}
|
|
55407
55346
|
} catch {
|
|
@@ -55424,29 +55363,29 @@ function parseJsonObject2(path2, content) {
|
|
|
55424
55363
|
}
|
|
55425
55364
|
const hash2 = (0, import_node_crypto7.createHash)("sha256").update(content).digest("hex").slice(0, 12);
|
|
55426
55365
|
const backupPath = `${path2}.alan-backup-${hash2}`;
|
|
55427
|
-
if (!(0,
|
|
55366
|
+
if (!(0, import_node_fs13.existsSync)(backupPath)) (0, import_node_fs13.copyFileSync)(path2, backupPath);
|
|
55428
55367
|
throw new Error(
|
|
55429
55368
|
`Existing config is malformed; no changes were applied. Review the backup at ${backupPath}`
|
|
55430
55369
|
);
|
|
55431
55370
|
}
|
|
55432
55371
|
async function configureAntigravityApiKeyMode(home = (0, import_node_os9.homedir)()) {
|
|
55433
|
-
const path2 = (0,
|
|
55372
|
+
const path2 = (0, import_node_path14.join)(home, ".gemini", "antigravity-cli", "settings.json");
|
|
55434
55373
|
const releaseLock = await waitForConfigLock(`${path2}.alan-lock`);
|
|
55435
55374
|
try {
|
|
55436
|
-
const existing = (0,
|
|
55375
|
+
const existing = (0, import_node_fs13.existsSync)(path2) ? (0, import_node_fs13.readFileSync)(path2, "utf8") : "";
|
|
55437
55376
|
const settings = existing.trim() ? parseJsonObject2(path2, existing) : {};
|
|
55438
55377
|
if (settings.modelProvider === "gemini") return false;
|
|
55439
55378
|
settings.modelProvider = "gemini";
|
|
55440
55379
|
const pending = `${path2}.alan-pending-${process.pid}-${(0, import_node_crypto7.randomBytes)(6).toString("hex")}`;
|
|
55441
55380
|
try {
|
|
55442
|
-
(0,
|
|
55381
|
+
(0, import_node_fs13.writeFileSync)(pending, JSON.stringify(settings), {
|
|
55443
55382
|
encoding: "utf8",
|
|
55444
55383
|
mode: 384,
|
|
55445
55384
|
flag: "wx"
|
|
55446
55385
|
});
|
|
55447
|
-
(0,
|
|
55386
|
+
(0, import_node_fs13.renameSync)(pending, path2);
|
|
55448
55387
|
} finally {
|
|
55449
|
-
(0,
|
|
55388
|
+
(0, import_node_fs13.rmSync)(pending, { force: true });
|
|
55450
55389
|
}
|
|
55451
55390
|
return true;
|
|
55452
55391
|
} finally {
|
|
@@ -56286,6 +56225,75 @@ ${input2.userRequest}
|
|
|
56286
56225
|
</user-request>` : instruction;
|
|
56287
56226
|
}
|
|
56288
56227
|
|
|
56228
|
+
// src/workspace-relocation.ts
|
|
56229
|
+
var import_node_child_process8 = require("child_process");
|
|
56230
|
+
var import_node_fs14 = require("fs");
|
|
56231
|
+
var import_node_path15 = require("path");
|
|
56232
|
+
var MAX_RELOCATION_CANDIDATES = 200;
|
|
56233
|
+
var DEFAULT_PROBE2 = {
|
|
56234
|
+
childDirectories: (parentPath, limit) => (0, import_node_fs14.readdirSync)(parentPath, { withFileTypes: true }).filter((entry) => entry.isDirectory()).slice(0, limit).map((entry) => (0, import_node_path15.join)(parentPath, entry.name)),
|
|
56235
|
+
gitRemoteUrl: (candidatePath) => {
|
|
56236
|
+
const result = (0, import_node_child_process8.spawnSync)("git", ["-C", candidatePath, "config", "--get", "remote.origin.url"], {
|
|
56237
|
+
encoding: "utf8",
|
|
56238
|
+
env: getDaemonCliEnvironment(),
|
|
56239
|
+
timeout: 2e3
|
|
56240
|
+
});
|
|
56241
|
+
if (result.status !== 0) return null;
|
|
56242
|
+
const url3 = result.stdout.trim();
|
|
56243
|
+
return url3 || null;
|
|
56244
|
+
}
|
|
56245
|
+
};
|
|
56246
|
+
function normalizeRepositoryIdentity(value2) {
|
|
56247
|
+
const trimmed = value2.trim().replace(/\/+$/, "").replace(/\.git$/i, "");
|
|
56248
|
+
if (!trimmed) return null;
|
|
56249
|
+
const scp = trimmed.match(/^(?:[^@/]+@)?([^:/]+):(.+)$/);
|
|
56250
|
+
if (scp && !trimmed.includes("://")) {
|
|
56251
|
+
return `${scp[1]}/${scp[2]}`.toLowerCase();
|
|
56252
|
+
}
|
|
56253
|
+
try {
|
|
56254
|
+
const url3 = new URL(trimmed);
|
|
56255
|
+
return `${url3.hostname}${url3.pathname}`.replace(/\/+$/, "").toLowerCase();
|
|
56256
|
+
} catch {
|
|
56257
|
+
return null;
|
|
56258
|
+
}
|
|
56259
|
+
}
|
|
56260
|
+
function workspaceMatchesExpectedRepositories(input2) {
|
|
56261
|
+
const identities = new Set(
|
|
56262
|
+
input2.expectedRepoUrls.map(normalizeRepositoryIdentity).filter((identity3) => Boolean(identity3))
|
|
56263
|
+
);
|
|
56264
|
+
if (identities.size === 0) return false;
|
|
56265
|
+
const remote = (input2.probe ?? DEFAULT_PROBE2).gitRemoteUrl((0, import_node_path15.resolve)(input2.workspacePath));
|
|
56266
|
+
const identity2 = remote ? normalizeRepositoryIdentity(remote) : null;
|
|
56267
|
+
return Boolean(identity2 && identities.has(identity2));
|
|
56268
|
+
}
|
|
56269
|
+
function discoverRelocatedWorkspace(input2) {
|
|
56270
|
+
const identities = new Set(
|
|
56271
|
+
input2.expectedRepoUrls.map(normalizeRepositoryIdentity).filter((identity2) => Boolean(identity2))
|
|
56272
|
+
);
|
|
56273
|
+
if (identities.size === 0) return null;
|
|
56274
|
+
const searchRoots = [
|
|
56275
|
+
(0, import_node_path15.dirname)((0, import_node_path15.resolve)(input2.missingPath)),
|
|
56276
|
+
...(input2.approvedWorkspacePaths ?? []).map((path2) => (0, import_node_path15.dirname)((0, import_node_path15.resolve)(path2)))
|
|
56277
|
+
].filter((path2, index, paths) => paths.indexOf(path2) === index);
|
|
56278
|
+
const candidates = [];
|
|
56279
|
+
for (const root of searchRoots) {
|
|
56280
|
+
const remaining = MAX_RELOCATION_CANDIDATES - candidates.length;
|
|
56281
|
+
if (remaining <= 0) break;
|
|
56282
|
+
try {
|
|
56283
|
+
candidates.push(...(input2.probe ?? DEFAULT_PROBE2).childDirectories(root, remaining));
|
|
56284
|
+
} catch {
|
|
56285
|
+
}
|
|
56286
|
+
}
|
|
56287
|
+
const matches = [];
|
|
56288
|
+
for (const candidate of new Set(candidates.map((path2) => (0, import_node_path15.resolve)(path2)))) {
|
|
56289
|
+
const remote = (input2.probe ?? DEFAULT_PROBE2).gitRemoteUrl(candidate);
|
|
56290
|
+
const identity2 = remote ? normalizeRepositoryIdentity(remote) : null;
|
|
56291
|
+
if (identity2 && identities.has(identity2)) matches.push((0, import_node_path15.resolve)(candidate));
|
|
56292
|
+
if (matches.length > 1) return null;
|
|
56293
|
+
}
|
|
56294
|
+
return matches[0] ?? null;
|
|
56295
|
+
}
|
|
56296
|
+
|
|
56289
56297
|
// src/daemon-execute.ts
|
|
56290
56298
|
async function handleAgentExecute(ctx, payload) {
|
|
56291
56299
|
const {
|
|
@@ -64888,6 +64896,9 @@ var McpSyncService = class {
|
|
|
64888
64896
|
cleanup(previousServers = []) {
|
|
64889
64897
|
removeMcpFromAllClis(previousServers);
|
|
64890
64898
|
}
|
|
64899
|
+
uninstall(apiUrl) {
|
|
64900
|
+
this.cleanup(toManagedMcpServers(buildAlanMcpServers(apiUrl)));
|
|
64901
|
+
}
|
|
64891
64902
|
};
|
|
64892
64903
|
|
|
64893
64904
|
// src/native-hook-config.ts
|
|
@@ -66548,7 +66559,9 @@ async function runInstallCommand(commandArgs, currentPlatform = process.platform
|
|
|
66548
66559
|
if (configurationMode === "login") await loginWithDeviceCode(commandArgs);
|
|
66549
66560
|
await installDaemonService(commandArgs);
|
|
66550
66561
|
}
|
|
66551
|
-
|
|
66562
|
+
if (commandArgs.includes("--with-integrations")) {
|
|
66563
|
+
runMcpIntegrationCommand(["reconcile", ...commandArgs]);
|
|
66564
|
+
}
|
|
66552
66565
|
}
|
|
66553
66566
|
|
|
66554
66567
|
// src/lifecycle-logger.ts
|