@fangyb/ahchat-bridge 0.1.20 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +194 -164
- package/dist/cli.js +0 -0
- package/dist/index.js +161 -132
- package/package.json +11 -11
package/dist/cli.cjs
CHANGED
|
@@ -3680,7 +3680,7 @@ var require_websocket_server = __commonJS({
|
|
|
3680
3680
|
// src/cli.ts
|
|
3681
3681
|
init_cjs_shims();
|
|
3682
3682
|
var import_node_os13 = __toESM(require("os"), 1);
|
|
3683
|
-
var
|
|
3683
|
+
var import_node_path22 = __toESM(require("path"), 1);
|
|
3684
3684
|
var import_node_fs10 = __toESM(require("fs"), 1);
|
|
3685
3685
|
|
|
3686
3686
|
// ../../node_modules/.pnpm/cac@6.7.14/node_modules/cac/dist/index.mjs
|
|
@@ -5097,11 +5097,11 @@ var RotatingFileStream = class extends import_stream.Writable {
|
|
|
5097
5097
|
timeout;
|
|
5098
5098
|
timeoutPromise;
|
|
5099
5099
|
constructor(generator, options) {
|
|
5100
|
-
const { encoding, history, maxFiles, maxSize, path:
|
|
5100
|
+
const { encoding, history, maxFiles, maxSize, path: path23 } = options;
|
|
5101
5101
|
super({ decodeStrings: true, defaultEncoding: encoding });
|
|
5102
5102
|
this.createGzip = import_zlib.createGzip;
|
|
5103
5103
|
this.exec = import_child_process.exec;
|
|
5104
|
-
this.filename =
|
|
5104
|
+
this.filename = path23 + generator(null);
|
|
5105
5105
|
this.fsCreateReadStream = import_fs.createReadStream;
|
|
5106
5106
|
this.fsCreateWriteStream = import_fs.createWriteStream;
|
|
5107
5107
|
this.fsOpen = import_promises.open;
|
|
@@ -5113,7 +5113,7 @@ var RotatingFileStream = class extends import_stream.Writable {
|
|
|
5113
5113
|
this.options = options;
|
|
5114
5114
|
this.stdout = process.stdout;
|
|
5115
5115
|
if (maxFiles || maxSize)
|
|
5116
|
-
options.history =
|
|
5116
|
+
options.history = path23 + (history ? history : this.generator(null) + ".txt");
|
|
5117
5117
|
this.on("close", () => this.finished ? null : this.emit("finish"));
|
|
5118
5118
|
this.on("finish", () => this.finished = this.clear());
|
|
5119
5119
|
(async () => {
|
|
@@ -5241,9 +5241,9 @@ var RotatingFileStream = class extends import_stream.Writable {
|
|
|
5241
5241
|
return this.move();
|
|
5242
5242
|
}
|
|
5243
5243
|
async findName() {
|
|
5244
|
-
const { interval, path:
|
|
5244
|
+
const { interval, path: path23, intervalBoundary } = this.options;
|
|
5245
5245
|
for (let index = 1; index < 1e3; ++index) {
|
|
5246
|
-
const filename =
|
|
5246
|
+
const filename = path23 + this.generator(interval && intervalBoundary ? new Date(this.prev) : this.rotation, index);
|
|
5247
5247
|
if (!await exists(filename))
|
|
5248
5248
|
return filename;
|
|
5249
5249
|
}
|
|
@@ -5273,11 +5273,11 @@ var RotatingFileStream = class extends import_stream.Writable {
|
|
|
5273
5273
|
return this.unlink(filename);
|
|
5274
5274
|
}
|
|
5275
5275
|
async classical() {
|
|
5276
|
-
const { compress, path:
|
|
5276
|
+
const { compress, path: path23, rotate } = this.options;
|
|
5277
5277
|
let rotatedName = "";
|
|
5278
5278
|
for (let count = rotate; count > 0; --count) {
|
|
5279
|
-
const currName =
|
|
5280
|
-
const prevName = count === 1 ? this.filename :
|
|
5279
|
+
const currName = path23 + this.generator(count);
|
|
5280
|
+
const prevName = count === 1 ? this.filename : path23 + this.generator(count - 1);
|
|
5281
5281
|
if (!await exists(prevName))
|
|
5282
5282
|
continue;
|
|
5283
5283
|
if (!rotatedName)
|
|
@@ -5715,7 +5715,7 @@ function createModuleLogger(module2) {
|
|
|
5715
5715
|
|
|
5716
5716
|
// src/start.ts
|
|
5717
5717
|
init_cjs_shims();
|
|
5718
|
-
var
|
|
5718
|
+
var import_node_path20 = __toESM(require("path"), 1);
|
|
5719
5719
|
|
|
5720
5720
|
// ../shared/src/index.ts
|
|
5721
5721
|
init_cjs_shims();
|
|
@@ -6928,7 +6928,7 @@ var import_node_crypto3 = require("crypto");
|
|
|
6928
6928
|
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
6929
6929
|
var import_promises8 = __toESM(require("fs/promises"), 1);
|
|
6930
6930
|
var import_node_os5 = __toESM(require("os"), 1);
|
|
6931
|
-
var
|
|
6931
|
+
var import_node_path9 = __toESM(require("path"), 1);
|
|
6932
6932
|
|
|
6933
6933
|
// ../../node_modules/.pnpm/@anthropic-ai+claude-agent-sdk@0.2.141_zod@4.4.3/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs
|
|
6934
6934
|
init_cjs_shims();
|
|
@@ -29753,10 +29753,10 @@ function mergeDefs(...defs) {
|
|
|
29753
29753
|
function cloneDef(schema) {
|
|
29754
29754
|
return mergeDefs(schema._zod.def);
|
|
29755
29755
|
}
|
|
29756
|
-
function getElementAtPath(obj,
|
|
29757
|
-
if (!
|
|
29756
|
+
function getElementAtPath(obj, path23) {
|
|
29757
|
+
if (!path23)
|
|
29758
29758
|
return obj;
|
|
29759
|
-
return
|
|
29759
|
+
return path23.reduce((acc, key) => acc?.[key], obj);
|
|
29760
29760
|
}
|
|
29761
29761
|
function promiseAllObject(promisesObj) {
|
|
29762
29762
|
const keys = Object.keys(promisesObj);
|
|
@@ -30165,11 +30165,11 @@ function explicitlyAborted(x2, startIndex = 0) {
|
|
|
30165
30165
|
}
|
|
30166
30166
|
return false;
|
|
30167
30167
|
}
|
|
30168
|
-
function prefixIssues(
|
|
30168
|
+
function prefixIssues(path23, issues) {
|
|
30169
30169
|
return issues.map((iss) => {
|
|
30170
30170
|
var _a3;
|
|
30171
30171
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
30172
|
-
iss.path.unshift(
|
|
30172
|
+
iss.path.unshift(path23);
|
|
30173
30173
|
return iss;
|
|
30174
30174
|
});
|
|
30175
30175
|
}
|
|
@@ -30316,16 +30316,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
30316
30316
|
}
|
|
30317
30317
|
function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
30318
30318
|
const fieldErrors = { _errors: [] };
|
|
30319
|
-
const processError = (error52,
|
|
30319
|
+
const processError = (error52, path23 = []) => {
|
|
30320
30320
|
for (const issue2 of error52.issues) {
|
|
30321
30321
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
30322
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
30322
|
+
issue2.errors.map((issues) => processError({ issues }, [...path23, ...issue2.path]));
|
|
30323
30323
|
} else if (issue2.code === "invalid_key") {
|
|
30324
|
-
processError({ issues: issue2.issues }, [...
|
|
30324
|
+
processError({ issues: issue2.issues }, [...path23, ...issue2.path]);
|
|
30325
30325
|
} else if (issue2.code === "invalid_element") {
|
|
30326
|
-
processError({ issues: issue2.issues }, [...
|
|
30326
|
+
processError({ issues: issue2.issues }, [...path23, ...issue2.path]);
|
|
30327
30327
|
} else {
|
|
30328
|
-
const fullpath = [...
|
|
30328
|
+
const fullpath = [...path23, ...issue2.path];
|
|
30329
30329
|
if (fullpath.length === 0) {
|
|
30330
30330
|
fieldErrors._errors.push(mapper(issue2));
|
|
30331
30331
|
} else {
|
|
@@ -30352,17 +30352,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
30352
30352
|
}
|
|
30353
30353
|
function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
30354
30354
|
const result = { errors: [] };
|
|
30355
|
-
const processError = (error52,
|
|
30355
|
+
const processError = (error52, path23 = []) => {
|
|
30356
30356
|
var _a3, _b2;
|
|
30357
30357
|
for (const issue2 of error52.issues) {
|
|
30358
30358
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
30359
|
-
issue2.errors.map((issues) => processError({ issues }, [...
|
|
30359
|
+
issue2.errors.map((issues) => processError({ issues }, [...path23, ...issue2.path]));
|
|
30360
30360
|
} else if (issue2.code === "invalid_key") {
|
|
30361
|
-
processError({ issues: issue2.issues }, [...
|
|
30361
|
+
processError({ issues: issue2.issues }, [...path23, ...issue2.path]);
|
|
30362
30362
|
} else if (issue2.code === "invalid_element") {
|
|
30363
|
-
processError({ issues: issue2.issues }, [...
|
|
30363
|
+
processError({ issues: issue2.issues }, [...path23, ...issue2.path]);
|
|
30364
30364
|
} else {
|
|
30365
|
-
const fullpath = [...
|
|
30365
|
+
const fullpath = [...path23, ...issue2.path];
|
|
30366
30366
|
if (fullpath.length === 0) {
|
|
30367
30367
|
result.errors.push(mapper(issue2));
|
|
30368
30368
|
continue;
|
|
@@ -30394,8 +30394,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
30394
30394
|
}
|
|
30395
30395
|
function toDotPath(_path) {
|
|
30396
30396
|
const segs = [];
|
|
30397
|
-
const
|
|
30398
|
-
for (const seg of
|
|
30397
|
+
const path23 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
30398
|
+
for (const seg of path23) {
|
|
30399
30399
|
if (typeof seg === "number")
|
|
30400
30400
|
segs.push(`[${seg}]`);
|
|
30401
30401
|
else if (typeof seg === "symbol")
|
|
@@ -43168,13 +43168,13 @@ function resolveRef(ref, ctx) {
|
|
|
43168
43168
|
if (!ref.startsWith("#")) {
|
|
43169
43169
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
43170
43170
|
}
|
|
43171
|
-
const
|
|
43172
|
-
if (
|
|
43171
|
+
const path23 = ref.slice(1).split("/").filter(Boolean);
|
|
43172
|
+
if (path23.length === 0) {
|
|
43173
43173
|
return ctx.rootSchema;
|
|
43174
43174
|
}
|
|
43175
43175
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
43176
|
-
if (
|
|
43177
|
-
const key =
|
|
43176
|
+
if (path23[0] === defsKey) {
|
|
43177
|
+
const key = path23[1];
|
|
43178
43178
|
if (!key || !ctx.defs[key]) {
|
|
43179
43179
|
throw new Error(`Reference not found: ${ref}`);
|
|
43180
43180
|
}
|
|
@@ -46979,6 +46979,53 @@ function buildForkHistorySection(messages) {
|
|
|
46979
46979
|
return lines.join("\n");
|
|
46980
46980
|
}
|
|
46981
46981
|
|
|
46982
|
+
// src/workdirMapper.ts
|
|
46983
|
+
init_cjs_shims();
|
|
46984
|
+
var import_node_path8 = __toESM(require("path"), 1);
|
|
46985
|
+
function extractAhchatWorkspaceParts(requestedPath) {
|
|
46986
|
+
const normalized = requestedPath.trim().replace(/\\/g, "/");
|
|
46987
|
+
const marker = "/.ahchat/users/";
|
|
46988
|
+
const markerIndex = normalized.indexOf(marker);
|
|
46989
|
+
if (markerIndex >= 0) {
|
|
46990
|
+
const afterUsers = normalized.slice(markerIndex + marker.length);
|
|
46991
|
+
const workspaceMarker = "/workspaces/";
|
|
46992
|
+
const workspaceIndex = afterUsers.indexOf(workspaceMarker);
|
|
46993
|
+
if (workspaceIndex >= 0) {
|
|
46994
|
+
const suffix = afterUsers.slice(workspaceIndex + workspaceMarker.length);
|
|
46995
|
+
const parts = suffix.split("/").filter((part) => part && part !== "." && part !== "..");
|
|
46996
|
+
return parts;
|
|
46997
|
+
}
|
|
46998
|
+
const workspacesRootMarker = "/workspaces";
|
|
46999
|
+
const rootIndex = afterUsers.indexOf(workspacesRootMarker);
|
|
47000
|
+
if (rootIndex >= 0 && afterUsers.slice(rootIndex + workspacesRootMarker.length).length === 0) {
|
|
47001
|
+
return [];
|
|
47002
|
+
}
|
|
47003
|
+
}
|
|
47004
|
+
const legacyMarker = "/.ahchat/";
|
|
47005
|
+
const legacyIndex = normalized.indexOf(legacyMarker);
|
|
47006
|
+
if (legacyIndex >= 0) {
|
|
47007
|
+
const firstSegment = normalized.slice(legacyIndex + legacyMarker.length).split("/").find(Boolean);
|
|
47008
|
+
if (firstSegment && /^(Agent|Group)-/.test(firstSegment)) {
|
|
47009
|
+
return [firstSegment];
|
|
47010
|
+
}
|
|
47011
|
+
}
|
|
47012
|
+
return null;
|
|
47013
|
+
}
|
|
47014
|
+
function extractAhchatWorkspaceSuffix(requestedPath) {
|
|
47015
|
+
const parts = extractAhchatWorkspaceParts(requestedPath);
|
|
47016
|
+
if (!parts || parts.length === 0) return null;
|
|
47017
|
+
return import_node_path8.default.join(...parts);
|
|
47018
|
+
}
|
|
47019
|
+
function remapServerWorkspacePath(requestedPath, workspacesDir) {
|
|
47020
|
+
const parts = extractAhchatWorkspaceParts(requestedPath);
|
|
47021
|
+
if (!parts) return { path: requestedPath, remapped: false };
|
|
47022
|
+
const remappedPath = parts.length > 0 ? import_node_path8.default.join(workspacesDir, ...parts) : workspacesDir;
|
|
47023
|
+
return {
|
|
47024
|
+
path: remappedPath,
|
|
47025
|
+
remapped: import_node_path8.default.normalize(requestedPath) !== import_node_path8.default.normalize(remappedPath)
|
|
47026
|
+
};
|
|
47027
|
+
}
|
|
47028
|
+
|
|
46982
47029
|
// src/wsMetrics.ts
|
|
46983
47030
|
init_cjs_shims();
|
|
46984
47031
|
var import_node_perf_hooks = require("perf_hooks");
|
|
@@ -47073,7 +47120,7 @@ async function chownForRootSpawn(targetPath, target) {
|
|
|
47073
47120
|
}
|
|
47074
47121
|
function readCronLockSnapshot() {
|
|
47075
47122
|
try {
|
|
47076
|
-
const lockPath2 =
|
|
47123
|
+
const lockPath2 = import_node_path9.default.join(import_node_os5.default.homedir(), ".claude", "scheduled_tasks.lock");
|
|
47077
47124
|
if (!import_node_fs3.default.existsSync(lockPath2)) {
|
|
47078
47125
|
return { exists: false, sessionId: null, pid: null };
|
|
47079
47126
|
}
|
|
@@ -47141,8 +47188,8 @@ var AgentManager = class {
|
|
|
47141
47188
|
this.emit = emit;
|
|
47142
47189
|
if (typeof options === "function") {
|
|
47143
47190
|
this.queryFn = options;
|
|
47144
|
-
this.workspacesDir =
|
|
47145
|
-
this.agentConfigDir =
|
|
47191
|
+
this.workspacesDir = import_node_path9.default.join(import_node_os5.default.homedir(), ".ahchat", "workspaces");
|
|
47192
|
+
this.agentConfigDir = import_node_path9.default.join(import_node_os5.default.homedir(), ".ahchat", "agent-config");
|
|
47146
47193
|
this.queryConfig = DEFAULT_QUERY_CONFIG;
|
|
47147
47194
|
this.askQuestionRegistry = new AskQuestionRegistry();
|
|
47148
47195
|
this.groupRegistry = null;
|
|
@@ -47153,11 +47200,11 @@ var AgentManager = class {
|
|
|
47153
47200
|
this.serverApiUrl = null;
|
|
47154
47201
|
this.bridgeToken = null;
|
|
47155
47202
|
this.defaultModel = null;
|
|
47156
|
-
this.dataDir =
|
|
47203
|
+
this.dataDir = import_node_path9.default.join(import_node_os5.default.homedir(), ".ahchat");
|
|
47157
47204
|
} else {
|
|
47158
47205
|
this.queryFn = options?.queryFn ?? null;
|
|
47159
|
-
this.workspacesDir = options?.workspacesDir ??
|
|
47160
|
-
this.agentConfigDir = options?.agentConfigDir ??
|
|
47206
|
+
this.workspacesDir = options?.workspacesDir ?? import_node_path9.default.join(import_node_os5.default.homedir(), ".ahchat", "workspaces");
|
|
47207
|
+
this.agentConfigDir = options?.agentConfigDir ?? import_node_path9.default.join(import_node_os5.default.homedir(), ".ahchat", "agent-config");
|
|
47161
47208
|
this.queryConfig = options?.queryConfig ?? DEFAULT_QUERY_CONFIG;
|
|
47162
47209
|
this.askQuestionRegistry = options?.askQuestionRegistry ?? new AskQuestionRegistry();
|
|
47163
47210
|
this.groupRegistry = options?.groupRegistry ?? null;
|
|
@@ -47168,7 +47215,7 @@ var AgentManager = class {
|
|
|
47168
47215
|
this.serverApiUrl = options?.serverApiUrl ?? null;
|
|
47169
47216
|
this.bridgeToken = options?.bridgeToken ?? null;
|
|
47170
47217
|
this.defaultModel = options?.defaultModel ?? null;
|
|
47171
|
-
this.dataDir = options?.dataDir ??
|
|
47218
|
+
this.dataDir = options?.dataDir ?? import_node_path9.default.join(import_node_os5.default.homedir(), ".ahchat");
|
|
47172
47219
|
}
|
|
47173
47220
|
this.evictionTimer = setInterval(() => {
|
|
47174
47221
|
void this.evictIdle();
|
|
@@ -47179,52 +47226,26 @@ var AgentManager = class {
|
|
|
47179
47226
|
this.queryFn = QA$;
|
|
47180
47227
|
return this.queryFn;
|
|
47181
47228
|
}
|
|
47182
|
-
extractAhchatWorkspaceSuffix(requestedCwd) {
|
|
47183
|
-
const normalized = requestedCwd.trim().replace(/\\/g, "/");
|
|
47184
|
-
const marker = "/.ahchat/users/";
|
|
47185
|
-
const markerIndex = normalized.indexOf(marker);
|
|
47186
|
-
if (markerIndex >= 0) {
|
|
47187
|
-
const afterUsers = normalized.slice(markerIndex + marker.length);
|
|
47188
|
-
const workspaceMarker = "/workspaces/";
|
|
47189
|
-
const workspaceIndex = afterUsers.indexOf(workspaceMarker);
|
|
47190
|
-
if (workspaceIndex >= 0) {
|
|
47191
|
-
const suffix = afterUsers.slice(workspaceIndex + workspaceMarker.length);
|
|
47192
|
-
const parts = suffix.split("/").filter((part) => part && part !== "." && part !== "..");
|
|
47193
|
-
return parts.length > 0 ? parts.join(import_node_path8.default.sep) : null;
|
|
47194
|
-
}
|
|
47195
|
-
}
|
|
47196
|
-
const legacyMarker = "/.ahchat/";
|
|
47197
|
-
const legacyIndex = normalized.indexOf(legacyMarker);
|
|
47198
|
-
if (legacyIndex >= 0) {
|
|
47199
|
-
const firstSegment = normalized.slice(legacyIndex + legacyMarker.length).split("/").find(Boolean);
|
|
47200
|
-
if (firstSegment && /^(Agent|Group)-/.test(firstSegment)) {
|
|
47201
|
-
return firstSegment;
|
|
47202
|
-
}
|
|
47203
|
-
}
|
|
47204
|
-
return null;
|
|
47205
|
-
}
|
|
47206
47229
|
fallbackCwd(agentConfig, scope, requestedCwd) {
|
|
47207
47230
|
const normalized = requestedCwd.trim();
|
|
47208
|
-
const ahchatSuffix =
|
|
47231
|
+
const ahchatSuffix = extractAhchatWorkspaceSuffix(normalized);
|
|
47209
47232
|
if (ahchatSuffix) {
|
|
47210
|
-
return
|
|
47233
|
+
return import_node_path9.default.join(this.workspacesDir, ahchatSuffix);
|
|
47211
47234
|
}
|
|
47212
|
-
const basename = normalized ?
|
|
47213
|
-
const suffix = basename && basename !== "." && basename !==
|
|
47214
|
-
return
|
|
47235
|
+
const basename = normalized ? import_node_path9.default.basename(import_node_path9.default.normalize(normalized)) : "";
|
|
47236
|
+
const suffix = basename && basename !== "." && basename !== import_node_path9.default.sep ? basename : scope.kind === "group" ? `Group-${scope.groupId}` : agentConfig.id;
|
|
47237
|
+
return import_node_path9.default.join(this.workspacesDir, suffix);
|
|
47215
47238
|
}
|
|
47216
47239
|
remapServerWorkspaceCwd(agentConfig, scope, requestedCwd) {
|
|
47217
|
-
const remapped =
|
|
47218
|
-
|
|
47219
|
-
const normalizedRemapped = import_node_path8.default.normalize(remapped);
|
|
47220
|
-
if (this.extractAhchatWorkspaceSuffix(requestedCwd) && normalizedRequested !== normalizedRemapped) {
|
|
47240
|
+
const remapped = remapServerWorkspacePath(requestedCwd, this.workspacesDir);
|
|
47241
|
+
if (remapped.remapped) {
|
|
47221
47242
|
logger10.info("Server working directory remapped to local Bridge workspace", {
|
|
47222
47243
|
agentId: agentConfig.id,
|
|
47223
47244
|
scope: scopeKey(scope),
|
|
47224
47245
|
requested: requestedCwd,
|
|
47225
|
-
remapped
|
|
47246
|
+
remapped: remapped.path
|
|
47226
47247
|
});
|
|
47227
|
-
return remapped;
|
|
47248
|
+
return remapped.path;
|
|
47228
47249
|
}
|
|
47229
47250
|
return requestedCwd;
|
|
47230
47251
|
}
|
|
@@ -47465,12 +47486,12 @@ var AgentManager = class {
|
|
|
47465
47486
|
const agentCwd = await this.resolveRuntimeCwd(agentConfig, scope, cwd);
|
|
47466
47487
|
const cfg = await this.resolveAgentConfig(agentConfig);
|
|
47467
47488
|
if (cfg.instructions?.trim()) {
|
|
47468
|
-
await import_promises8.default.writeFile(
|
|
47489
|
+
await import_promises8.default.writeFile(import_node_path9.default.join(agentCwd, "CLAUDE.md"), cfg.instructions.trim(), "utf-8");
|
|
47469
47490
|
logger10.info("CLAUDE.md written", { agentId: agentConfig.id, bytes: cfg.instructions.trim().length });
|
|
47470
47491
|
}
|
|
47471
47492
|
let effectiveConfigDir = this.agentConfigDir;
|
|
47472
47493
|
if (cfg.subscriptionType !== "system" && cfg.apiKey) {
|
|
47473
|
-
effectiveConfigDir =
|
|
47494
|
+
effectiveConfigDir = import_node_path9.default.join(this.agentConfigDir, "api-key-agents", agentConfig.id);
|
|
47474
47495
|
let isNew = false;
|
|
47475
47496
|
try {
|
|
47476
47497
|
await import_promises8.default.access(effectiveConfigDir);
|
|
@@ -47483,7 +47504,7 @@ var AgentManager = class {
|
|
|
47483
47504
|
this.dispatchMemory.deleteScope(agentConfig.id, scope);
|
|
47484
47505
|
logger10.info("New API-key agent config dir; cleared stale session", { agentId: agentConfig.id });
|
|
47485
47506
|
}
|
|
47486
|
-
const settingsPath =
|
|
47507
|
+
const settingsPath = import_node_path9.default.join(effectiveConfigDir, "settings.json");
|
|
47487
47508
|
const envEntries = {};
|
|
47488
47509
|
if (cfg.apiKey) envEntries.ANTHROPIC_API_KEY = cfg.apiKey;
|
|
47489
47510
|
if (cfg.apiBaseUrl) envEntries.ANTHROPIC_BASE_URL = cfg.apiBaseUrl;
|
|
@@ -47790,7 +47811,7 @@ Do NOT use "..." as content \u2014 write specific, project-relevant content.`;
|
|
|
47790
47811
|
settings: (() => {
|
|
47791
47812
|
const isolated = cfg.subscriptionType === "project" && Boolean(cfg.apiKey ?? cfg.apiBaseUrl);
|
|
47792
47813
|
if (!isolated) return void 0;
|
|
47793
|
-
return
|
|
47814
|
+
return import_node_path9.default.join(effectiveConfigDir, "settings.json");
|
|
47794
47815
|
})(),
|
|
47795
47816
|
canUseTool: async (toolName, input) => {
|
|
47796
47817
|
if (toolName === "AskUserQuestion") {
|
|
@@ -47864,7 +47885,7 @@ Do NOT use "..." as content \u2014 write specific, project-relevant content.`;
|
|
|
47864
47885
|
if (isRunningAsRoot()) {
|
|
47865
47886
|
await chownForRootSpawn(effectiveConfigDir, "configDir");
|
|
47866
47887
|
await chownForRootSpawn(agentCwd, "agentCwd");
|
|
47867
|
-
const settingsFilePath =
|
|
47888
|
+
const settingsFilePath = import_node_path9.default.join(effectiveConfigDir, "settings.json");
|
|
47868
47889
|
await chownForRootSpawn(settingsFilePath, "settingsFile");
|
|
47869
47890
|
options.spawnClaudeCodeProcess = (spawnOptions) => {
|
|
47870
47891
|
const env2 = { ...spawnOptions.env, HOME: "/home/node" };
|
|
@@ -48031,7 +48052,7 @@ ${trimmed}`;
|
|
|
48031
48052
|
lines.push(` workdir: ${currentCwd}`);
|
|
48032
48053
|
} else {
|
|
48033
48054
|
const a = this.agentRegistry?.getById(agentId);
|
|
48034
|
-
const singleCwd = a?.workingDirectory ||
|
|
48055
|
+
const singleCwd = a?.workingDirectory || import_node_path9.default.join(this.workspacesDir, agentId);
|
|
48035
48056
|
lines.push(` workdir: ${singleCwd}`);
|
|
48036
48057
|
}
|
|
48037
48058
|
let rosterCount = 0;
|
|
@@ -48043,7 +48064,7 @@ ${trimmed}`;
|
|
|
48043
48064
|
if (key === curKey) {
|
|
48044
48065
|
lines.push(` workdir: ${currentCwd}`);
|
|
48045
48066
|
} else {
|
|
48046
|
-
const groupCwd = g2.workingDirectory ||
|
|
48067
|
+
const groupCwd = g2.workingDirectory || import_node_path9.default.join(this.workspacesDir, g2.groupId);
|
|
48047
48068
|
lines.push(` workdir: ${groupCwd}`);
|
|
48048
48069
|
}
|
|
48049
48070
|
const others = g2.members.filter((id) => id !== agentId).map((id) => {
|
|
@@ -48494,14 +48515,14 @@ ${lines.join("\n")}`;
|
|
|
48494
48515
|
}
|
|
48495
48516
|
async materializeAttachment(runtime, attachment, buffer) {
|
|
48496
48517
|
const safeFileName = this.safeAttachmentFileName(attachment.fileName);
|
|
48497
|
-
const dir =
|
|
48518
|
+
const dir = import_node_path9.default.join(runtime.cwd, ".ahchat-attachments", attachment.id);
|
|
48498
48519
|
await import_promises8.default.mkdir(dir, { recursive: true });
|
|
48499
|
-
const filePath =
|
|
48520
|
+
const filePath = import_node_path9.default.join(dir, safeFileName);
|
|
48500
48521
|
await import_promises8.default.writeFile(filePath, buffer);
|
|
48501
48522
|
return filePath;
|
|
48502
48523
|
}
|
|
48503
48524
|
safeAttachmentFileName(fileName) {
|
|
48504
|
-
const baseName =
|
|
48525
|
+
const baseName = import_node_path9.default.basename(fileName).replace(/[\0/:\\]/g, "_").trim();
|
|
48505
48526
|
return baseName || "attachment";
|
|
48506
48527
|
}
|
|
48507
48528
|
/**
|
|
@@ -48516,7 +48537,7 @@ ${lines.join("\n")}`;
|
|
|
48516
48537
|
async detectVisionSupport() {
|
|
48517
48538
|
if (process.env.ANTHROPIC_BASE_URL) return false;
|
|
48518
48539
|
try {
|
|
48519
|
-
const settingsPath =
|
|
48540
|
+
const settingsPath = import_node_path9.default.join(import_node_os5.default.homedir(), ".claude", "settings.json");
|
|
48520
48541
|
const raw = await import_promises8.default.readFile(settingsPath, "utf-8");
|
|
48521
48542
|
const parsed = JSON.parse(raw);
|
|
48522
48543
|
if (parsed.env?.ANTHROPIC_BASE_URL) return false;
|
|
@@ -48882,7 +48903,7 @@ ${lines.join("\n")}`;
|
|
|
48882
48903
|
}
|
|
48883
48904
|
cwd = payload.targetCwd;
|
|
48884
48905
|
} else {
|
|
48885
|
-
cwd = agentConfig.workingDirectory ||
|
|
48906
|
+
cwd = agentConfig.workingDirectory || import_node_path9.default.join(this.workspacesDir, agentConfig.id);
|
|
48886
48907
|
}
|
|
48887
48908
|
void this.acquire(agentConfig, targetScope, cwd).then(() => {
|
|
48888
48909
|
logger10.info("Neural send new runtime acquired", {
|
|
@@ -48988,7 +49009,7 @@ ${lines.join("\n")}`;
|
|
|
48988
49009
|
conversationId,
|
|
48989
49010
|
traceId
|
|
48990
49011
|
});
|
|
48991
|
-
const cwd = newAgent.workingDirectory ||
|
|
49012
|
+
const cwd = newAgent.workingDirectory || import_node_path9.default.join(this.workspacesDir, newAgent.id);
|
|
48992
49013
|
const scope = { kind: "single" };
|
|
48993
49014
|
try {
|
|
48994
49015
|
await this.acquire(newAgent, scope, cwd);
|
|
@@ -49270,12 +49291,12 @@ ${lines.join("\n")}`;
|
|
|
49270
49291
|
break;
|
|
49271
49292
|
}
|
|
49272
49293
|
try {
|
|
49273
|
-
let cwd = agent.workingDirectory ||
|
|
49294
|
+
let cwd = agent.workingDirectory || import_node_path9.default.join(this.workspacesDir, agent.id);
|
|
49274
49295
|
if (agent.workingDirectory) {
|
|
49275
49296
|
try {
|
|
49276
49297
|
await import_promises8.default.mkdir(cwd, { recursive: true });
|
|
49277
49298
|
} catch {
|
|
49278
|
-
cwd =
|
|
49299
|
+
cwd = import_node_path9.default.join(this.workspacesDir, agent.id);
|
|
49279
49300
|
logger10.warn("Stored workingDirectory inaccessible, falling back", {
|
|
49280
49301
|
agentId: agent.id,
|
|
49281
49302
|
stored: agent.workingDirectory,
|
|
@@ -49750,8 +49771,8 @@ var HttpAgentRegistry = class {
|
|
|
49750
49771
|
agents = /* @__PURE__ */ new Map();
|
|
49751
49772
|
apiUrl(suffix) {
|
|
49752
49773
|
const base = this.serverApiUrl.replace(/\/$/, "");
|
|
49753
|
-
const
|
|
49754
|
-
return `${base}${
|
|
49774
|
+
const path23 = suffix.startsWith("/") ? suffix : `/${suffix}`;
|
|
49775
|
+
return `${base}${path23}`;
|
|
49755
49776
|
}
|
|
49756
49777
|
async refresh() {
|
|
49757
49778
|
const attempt = async () => {
|
|
@@ -49843,8 +49864,8 @@ var HttpSubscriptionRegistry = class {
|
|
|
49843
49864
|
subscriptions = /* @__PURE__ */ new Map();
|
|
49844
49865
|
apiUrl(suffix) {
|
|
49845
49866
|
const base = this.serverApiUrl.replace(/\/$/, "");
|
|
49846
|
-
const
|
|
49847
|
-
return `${base}${
|
|
49867
|
+
const path23 = suffix.startsWith("/") ? suffix : `/${suffix}`;
|
|
49868
|
+
return `${base}${path23}`;
|
|
49848
49869
|
}
|
|
49849
49870
|
async refresh() {
|
|
49850
49871
|
const attempt = async () => {
|
|
@@ -50331,7 +50352,7 @@ var ServerConnector = class {
|
|
|
50331
50352
|
init_cjs_shims();
|
|
50332
50353
|
var import_promises9 = __toESM(require("fs/promises"), 1);
|
|
50333
50354
|
var import_node_os7 = __toESM(require("os"), 1);
|
|
50334
|
-
var
|
|
50355
|
+
var import_node_path10 = __toESM(require("path"), 1);
|
|
50335
50356
|
var logger16 = createModuleLogger("bridge.contextDumper");
|
|
50336
50357
|
var TRUNCATE_THRESHOLD = 5e4;
|
|
50337
50358
|
var TRUNCATE_HEAD = 8e3;
|
|
@@ -50360,7 +50381,7 @@ function cwdToProjectSlug(cwd) {
|
|
|
50360
50381
|
}
|
|
50361
50382
|
function resolveJsonlPath(sessionId, cwd) {
|
|
50362
50383
|
const slug = cwdToProjectSlug(cwd);
|
|
50363
|
-
return
|
|
50384
|
+
return import_node_path10.default.join(import_node_os7.default.homedir(), ".claude", "projects", slug, `${sessionId}.jsonl`);
|
|
50364
50385
|
}
|
|
50365
50386
|
var RENDERABLE_TYPES = /* @__PURE__ */ new Set(["user", "assistant", "system", "attachment"]);
|
|
50366
50387
|
async function readJsonlEntries(filePath) {
|
|
@@ -50620,7 +50641,7 @@ async function dumpAgentContext(agentId, deps) {
|
|
|
50620
50641
|
if (!workdir) {
|
|
50621
50642
|
return { ok: false, files: [], scopeErrors: [], error: "agent has no working directory" };
|
|
50622
50643
|
}
|
|
50623
|
-
const dumpDir =
|
|
50644
|
+
const dumpDir = import_node_path10.default.join(workdir, "sessioninfo");
|
|
50624
50645
|
await import_promises9.default.mkdir(dumpDir, { recursive: true });
|
|
50625
50646
|
const prefix = `${agentId}::`;
|
|
50626
50647
|
const scopeEntries = [];
|
|
@@ -50690,7 +50711,7 @@ async function dumpAgentContext(agentId, deps) {
|
|
|
50690
50711
|
jsonlPath
|
|
50691
50712
|
});
|
|
50692
50713
|
const filename = scopeFilename(agent.name, scopeKey2, groupName);
|
|
50693
|
-
const filePath =
|
|
50714
|
+
const filePath = import_node_path10.default.join(dumpDir, filename);
|
|
50694
50715
|
await import_promises9.default.writeFile(filePath, html, "utf-8");
|
|
50695
50716
|
dumpedFiles.push(filename);
|
|
50696
50717
|
const stat3 = await import_promises9.default.stat(filePath);
|
|
@@ -50732,7 +50753,7 @@ async function dumpAgentContext(agentId, deps) {
|
|
|
50732
50753
|
// src/listDir.ts
|
|
50733
50754
|
init_cjs_shims();
|
|
50734
50755
|
var import_promises10 = __toESM(require("fs/promises"), 1);
|
|
50735
|
-
var
|
|
50756
|
+
var import_node_path11 = __toESM(require("path"), 1);
|
|
50736
50757
|
var logger17 = createModuleLogger("bridge.listDir");
|
|
50737
50758
|
function shouldIncludeEntry(name) {
|
|
50738
50759
|
if (!name.startsWith(".")) return true;
|
|
@@ -50744,7 +50765,7 @@ async function listDirectoryEntries(dirPath) {
|
|
|
50744
50765
|
const entries = [];
|
|
50745
50766
|
for (const entry of raw) {
|
|
50746
50767
|
if (!shouldIncludeEntry(entry.name)) continue;
|
|
50747
|
-
const fullPath =
|
|
50768
|
+
const fullPath = import_node_path11.default.join(dirPath, entry.name);
|
|
50748
50769
|
const isDir = entry.isDirectory();
|
|
50749
50770
|
let size;
|
|
50750
50771
|
let mtime;
|
|
@@ -50773,7 +50794,7 @@ async function listDirectoryEntries(dirPath) {
|
|
|
50773
50794
|
// src/logScanner.ts
|
|
50774
50795
|
init_cjs_shims();
|
|
50775
50796
|
var import_node_fs4 = __toESM(require("fs"), 1);
|
|
50776
|
-
var
|
|
50797
|
+
var import_node_path12 = __toESM(require("path"), 1);
|
|
50777
50798
|
var import_node_os8 = __toESM(require("os"), 1);
|
|
50778
50799
|
var import_node_readline = __toESM(require("readline"), 1);
|
|
50779
50800
|
var logger18 = createModuleLogger("bridge.logScanner");
|
|
@@ -50788,10 +50809,10 @@ function listLogFiles(logsDir, baseName) {
|
|
|
50788
50809
|
return [];
|
|
50789
50810
|
}
|
|
50790
50811
|
const pattern = new RegExp(`^${baseName.replace(".", "\\.")}(\\.\\d+)?$`);
|
|
50791
|
-
return names.filter((n2) => pattern.test(n2)).map((n2) =>
|
|
50812
|
+
return names.filter((n2) => pattern.test(n2)).map((n2) => import_node_path12.default.join(logsDir, n2));
|
|
50792
50813
|
}
|
|
50793
50814
|
async function scanFile(filePath, source, filter, limit, state) {
|
|
50794
|
-
const file2 =
|
|
50815
|
+
const file2 = import_node_path12.default.basename(filePath);
|
|
50795
50816
|
const stream = import_node_fs4.default.createReadStream(filePath, { encoding: "utf-8" });
|
|
50796
50817
|
const rl2 = import_node_readline.default.createInterface({ input: stream, crlfDelay: Infinity });
|
|
50797
50818
|
let lineNum = 0;
|
|
@@ -50830,7 +50851,7 @@ async function scanLocalLogs(logsDir, baseName, filter) {
|
|
|
50830
50851
|
};
|
|
50831
50852
|
}
|
|
50832
50853
|
async function scanBridgeLogs(filter) {
|
|
50833
|
-
const logDir =
|
|
50854
|
+
const logDir = import_node_path12.default.join(import_node_os8.default.homedir(), ".ahchat", "logs");
|
|
50834
50855
|
logger18.info("scanBridgeLogs start", {
|
|
50835
50856
|
logDir,
|
|
50836
50857
|
startIso: filter.startIso,
|
|
@@ -50849,13 +50870,13 @@ async function scanBridgeLogs(filter) {
|
|
|
50849
50870
|
// src/skillStore.ts
|
|
50850
50871
|
init_cjs_shims();
|
|
50851
50872
|
var import_node_fs5 = __toESM(require("fs"), 1);
|
|
50852
|
-
var
|
|
50873
|
+
var import_node_path13 = __toESM(require("path"), 1);
|
|
50853
50874
|
var logger19 = createModuleLogger("bridge.skillStore");
|
|
50854
50875
|
var ALLOWED_NAMES = /* @__PURE__ */ new Set(["log-analysis"]);
|
|
50855
50876
|
var SkillStore = class {
|
|
50856
50877
|
skillsDir;
|
|
50857
50878
|
constructor(dataDir) {
|
|
50858
|
-
this.skillsDir =
|
|
50879
|
+
this.skillsDir = import_node_path13.default.join(dataDir, "skills");
|
|
50859
50880
|
import_node_fs5.default.mkdirSync(this.skillsDir, { recursive: true });
|
|
50860
50881
|
logger19.info("SkillStore initialized", { skillsDir: this.skillsDir });
|
|
50861
50882
|
}
|
|
@@ -50864,7 +50885,7 @@ var SkillStore = class {
|
|
|
50864
50885
|
logger19.warn("Skill read: unknown name", { name, allowed: [...ALLOWED_NAMES] });
|
|
50865
50886
|
return "";
|
|
50866
50887
|
}
|
|
50867
|
-
const filePath =
|
|
50888
|
+
const filePath = import_node_path13.default.join(this.skillsDir, `${name}.md`);
|
|
50868
50889
|
try {
|
|
50869
50890
|
const content = import_node_fs5.default.readFileSync(filePath, "utf-8");
|
|
50870
50891
|
logger19.info("Skill read", { name, bytes: content.length });
|
|
@@ -50879,7 +50900,7 @@ var SkillStore = class {
|
|
|
50879
50900
|
if (!ALLOWED_NAMES.has(name)) {
|
|
50880
50901
|
throw new Error(`Unknown skill name: ${name}`);
|
|
50881
50902
|
}
|
|
50882
|
-
const filePath =
|
|
50903
|
+
const filePath = import_node_path13.default.join(this.skillsDir, `${name}.md`);
|
|
50883
50904
|
const tmpPath = `${filePath}.tmp`;
|
|
50884
50905
|
let existing = "";
|
|
50885
50906
|
try {
|
|
@@ -50903,7 +50924,7 @@ var SkillStore = class {
|
|
|
50903
50924
|
// src/lockfile.ts
|
|
50904
50925
|
init_cjs_shims();
|
|
50905
50926
|
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
50906
|
-
var
|
|
50927
|
+
var import_node_path14 = __toESM(require("path"), 1);
|
|
50907
50928
|
var logger20 = createModuleLogger("bridge.lockfile");
|
|
50908
50929
|
var lockPath = null;
|
|
50909
50930
|
function isProcessAlive(pid) {
|
|
@@ -50917,7 +50938,7 @@ function isProcessAlive(pid) {
|
|
|
50917
50938
|
}
|
|
50918
50939
|
}
|
|
50919
50940
|
function acquireLock(dataDir) {
|
|
50920
|
-
const file2 =
|
|
50941
|
+
const file2 = import_node_path14.default.join(dataDir, "bridge.lock");
|
|
50921
50942
|
lockPath = file2;
|
|
50922
50943
|
if (import_node_fs6.default.existsSync(file2)) {
|
|
50923
50944
|
const raw = import_node_fs6.default.readFileSync(file2, "utf-8").trim();
|
|
@@ -50929,7 +50950,7 @@ function acquireLock(dataDir) {
|
|
|
50929
50950
|
logger20.warn("Removing stale bridge.lock (process not found)", { pid, path: file2 });
|
|
50930
50951
|
}
|
|
50931
50952
|
}
|
|
50932
|
-
import_node_fs6.default.mkdirSync(
|
|
50953
|
+
import_node_fs6.default.mkdirSync(import_node_path14.default.dirname(file2), { recursive: true });
|
|
50933
50954
|
import_node_fs6.default.writeFileSync(file2, String(process.pid), "utf-8");
|
|
50934
50955
|
logger20.info("Acquired bridge lock", { path: file2, pid: process.pid });
|
|
50935
50956
|
const release = () => {
|
|
@@ -51299,13 +51320,13 @@ async function handleGroupArchivedPush(deps, payload) {
|
|
|
51299
51320
|
// src/sessionStore.ts
|
|
51300
51321
|
init_cjs_shims();
|
|
51301
51322
|
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
51302
|
-
var
|
|
51323
|
+
var import_node_path15 = __toESM(require("path"), 1);
|
|
51303
51324
|
var logger23 = createModuleLogger("session.store");
|
|
51304
51325
|
var SessionStore = class {
|
|
51305
51326
|
filePath;
|
|
51306
51327
|
cache;
|
|
51307
51328
|
constructor(dataDir) {
|
|
51308
|
-
this.filePath =
|
|
51329
|
+
this.filePath = import_node_path15.default.join(dataDir, "sessions.json");
|
|
51309
51330
|
this.cache = this.loadFromDisk();
|
|
51310
51331
|
}
|
|
51311
51332
|
cacheKey(agentId, scope) {
|
|
@@ -51365,7 +51386,7 @@ var SessionStore = class {
|
|
|
51365
51386
|
}
|
|
51366
51387
|
saveToDisk() {
|
|
51367
51388
|
try {
|
|
51368
|
-
const dir =
|
|
51389
|
+
const dir = import_node_path15.default.dirname(this.filePath);
|
|
51369
51390
|
import_node_fs7.default.mkdirSync(dir, { recursive: true });
|
|
51370
51391
|
import_node_fs7.default.writeFileSync(this.filePath, JSON.stringify(this.cache, null, 2), "utf-8");
|
|
51371
51392
|
} catch (e7) {
|
|
@@ -51378,7 +51399,7 @@ var SessionStore = class {
|
|
|
51378
51399
|
init_cjs_shims();
|
|
51379
51400
|
var import_node_child_process2 = require("child_process");
|
|
51380
51401
|
var import_node_fs8 = require("fs");
|
|
51381
|
-
var
|
|
51402
|
+
var import_node_path16 = require("path");
|
|
51382
51403
|
var logger24 = createModuleLogger("bridge.ensureCli");
|
|
51383
51404
|
var DEFAULT_INSTALL_TIMEOUT_MS = 6e5;
|
|
51384
51405
|
function getInstallTimeoutMs() {
|
|
@@ -51402,7 +51423,7 @@ function getNpmGlobalBin() {
|
|
|
51402
51423
|
}
|
|
51403
51424
|
try {
|
|
51404
51425
|
const prefix = (0, import_node_child_process2.execSync)("npm prefix -g", { timeout: 5e3 }).toString().trim();
|
|
51405
|
-
if (prefix) return (0,
|
|
51426
|
+
if (prefix) return (0, import_node_path16.join)(prefix, "bin");
|
|
51406
51427
|
} catch {
|
|
51407
51428
|
}
|
|
51408
51429
|
return void 0;
|
|
@@ -51419,9 +51440,9 @@ function resolveClaudeBinary() {
|
|
|
51419
51440
|
}
|
|
51420
51441
|
function getNpmClaudeCandidates(bin) {
|
|
51421
51442
|
if (process.platform === "win32") {
|
|
51422
|
-
return ["claude.cmd", "claude.exe", "claude", "anthropic-cli.cmd", "anthropic-cli.exe", "anthropic-cli"].map((name) => (0,
|
|
51443
|
+
return ["claude.cmd", "claude.exe", "claude", "anthropic-cli.cmd", "anthropic-cli.exe", "anthropic-cli"].map((name) => (0, import_node_path16.join)(bin, name));
|
|
51423
51444
|
}
|
|
51424
|
-
return [(0,
|
|
51445
|
+
return [(0, import_node_path16.join)(bin, "claude"), (0, import_node_path16.join)(bin, "anthropic-cli")];
|
|
51425
51446
|
}
|
|
51426
51447
|
function resolveViaNpmBin() {
|
|
51427
51448
|
const bin = getNpmGlobalBin();
|
|
@@ -51533,21 +51554,21 @@ async function ensureClaudeCli() {
|
|
|
51533
51554
|
// src/forkAgentFiles.ts
|
|
51534
51555
|
init_cjs_shims();
|
|
51535
51556
|
var fs11 = __toESM(require("fs/promises"), 1);
|
|
51536
|
-
var
|
|
51557
|
+
var path17 = __toESM(require("path"), 1);
|
|
51537
51558
|
|
|
51538
51559
|
// src/sessionSlug.ts
|
|
51539
51560
|
init_cjs_shims();
|
|
51540
51561
|
var import_node_os9 = __toESM(require("os"), 1);
|
|
51541
|
-
var
|
|
51542
|
-
var CLAUDE_PROJECTS_DIR =
|
|
51562
|
+
var import_node_path17 = __toESM(require("path"), 1);
|
|
51563
|
+
var CLAUDE_PROJECTS_DIR = import_node_path17.default.join(import_node_os9.default.homedir(), ".claude", "projects");
|
|
51543
51564
|
function cwdToSlug(cwd) {
|
|
51544
51565
|
return cwd.replace(/[^a-zA-Z0-9-]/g, "-");
|
|
51545
51566
|
}
|
|
51546
51567
|
function sessionDirForCwd(cwd) {
|
|
51547
|
-
return
|
|
51568
|
+
return import_node_path17.default.join(CLAUDE_PROJECTS_DIR, cwdToSlug(cwd));
|
|
51548
51569
|
}
|
|
51549
51570
|
function sessionFilePath(cwd, sessionId) {
|
|
51550
|
-
return
|
|
51571
|
+
return import_node_path17.default.join(sessionDirForCwd(cwd), `${sessionId}.jsonl`);
|
|
51551
51572
|
}
|
|
51552
51573
|
|
|
51553
51574
|
// src/forkAgentFiles.ts
|
|
@@ -51579,9 +51600,9 @@ async function forkAgentFiles(sourceAgentId, newAgentId, sourceWorkdir, newWorkd
|
|
|
51579
51600
|
logger25.error("Workdir copy failed", { error: e7 });
|
|
51580
51601
|
throw e7;
|
|
51581
51602
|
}
|
|
51582
|
-
const srcNotebook =
|
|
51583
|
-
const dstNotebookDir =
|
|
51584
|
-
const dstNotebook =
|
|
51603
|
+
const srcNotebook = path17.join(dataDir, "agent-memory", sourceAgentId, "notebook.md");
|
|
51604
|
+
const dstNotebookDir = path17.join(dataDir, "agent-memory", newAgentId);
|
|
51605
|
+
const dstNotebook = path17.join(dstNotebookDir, "notebook.md");
|
|
51585
51606
|
try {
|
|
51586
51607
|
const nbStat = await fs11.stat(srcNotebook).catch(() => null);
|
|
51587
51608
|
if (nbStat?.isFile()) {
|
|
@@ -51608,7 +51629,7 @@ async function forkAgentFiles(sourceAgentId, newAgentId, sourceWorkdir, newWorkd
|
|
|
51608
51629
|
if (srcStat?.isFile()) {
|
|
51609
51630
|
const dstDir = sessionDirForCwd(newWorkdir);
|
|
51610
51631
|
await fs11.mkdir(dstDir, { recursive: true });
|
|
51611
|
-
const dstPath =
|
|
51632
|
+
const dstPath = path17.join(dstDir, `${sourceSessionId}.jsonl`);
|
|
51612
51633
|
await fs11.copyFile(srcPath, dstPath);
|
|
51613
51634
|
sessionStore.set(newAgentId, { kind: "single" }, sourceSessionId);
|
|
51614
51635
|
sessionCopied = true;
|
|
@@ -51657,11 +51678,11 @@ async function forkAgentFiles(sourceAgentId, newAgentId, sourceWorkdir, newWorkd
|
|
|
51657
51678
|
init_cjs_shims();
|
|
51658
51679
|
var import_promises11 = __toESM(require("fs/promises"), 1);
|
|
51659
51680
|
var import_node_os10 = __toESM(require("os"), 1);
|
|
51660
|
-
var
|
|
51681
|
+
var import_node_path18 = __toESM(require("path"), 1);
|
|
51661
51682
|
var logger26 = createModuleLogger("bridge.modelQuerier");
|
|
51662
51683
|
async function listModels(queryFn, opts = {}) {
|
|
51663
51684
|
const t0 = Date.now();
|
|
51664
|
-
const cwd = opts.cwd ??
|
|
51685
|
+
const cwd = opts.cwd ?? import_node_path18.default.join(import_node_os10.default.homedir(), ".ahchat", "workspaces", "_list_models");
|
|
51665
51686
|
await import_promises11.default.mkdir(cwd, { recursive: true });
|
|
51666
51687
|
const fn = queryFn ?? QA$;
|
|
51667
51688
|
const ic2 = new InputController();
|
|
@@ -51725,7 +51746,7 @@ async function listModels(queryFn, opts = {}) {
|
|
|
51725
51746
|
init_cjs_shims();
|
|
51726
51747
|
var import_promises12 = __toESM(require("fs/promises"), 1);
|
|
51727
51748
|
var import_node_os11 = __toESM(require("os"), 1);
|
|
51728
|
-
var
|
|
51749
|
+
var import_node_path19 = __toESM(require("path"), 1);
|
|
51729
51750
|
var logger27 = createModuleLogger("bridge.promptOptimizer");
|
|
51730
51751
|
var OPTIMIZER_SYSTEM_PROMPT = `You are an expert prompt editor for AHChat Agent creation.
|
|
51731
51752
|
|
|
@@ -51768,7 +51789,7 @@ async function optimizePrompt(queryFn, opts) {
|
|
|
51768
51789
|
const prompt = opts.systemPrompt.trim();
|
|
51769
51790
|
if (!prompt) throw new Error("systemPrompt is required");
|
|
51770
51791
|
const t0 = Date.now();
|
|
51771
|
-
const cwd = opts.cwd ??
|
|
51792
|
+
const cwd = opts.cwd ?? import_node_path19.default.join(import_node_os11.default.homedir(), ".ahchat", "workspaces", "_prompt_optimizer");
|
|
51772
51793
|
await import_promises12.default.mkdir(cwd, { recursive: true });
|
|
51773
51794
|
const fn = queryFn ?? QA$;
|
|
51774
51795
|
const ic2 = new InputController();
|
|
@@ -51856,7 +51877,7 @@ function isRunningAsRoot2() {
|
|
|
51856
51877
|
}
|
|
51857
51878
|
}
|
|
51858
51879
|
async function syncClaudeCredentialsToNodeAccessibleDir(agentConfigDir) {
|
|
51859
|
-
const rootClaudeDir =
|
|
51880
|
+
const rootClaudeDir = import_node_path20.default.join(process.env.HOME ?? "/root", ".claude");
|
|
51860
51881
|
const fs16 = await import("fs/promises");
|
|
51861
51882
|
try {
|
|
51862
51883
|
await fs16.access(rootClaudeDir);
|
|
@@ -51866,8 +51887,8 @@ async function syncClaudeCredentialsToNodeAccessibleDir(agentConfigDir) {
|
|
|
51866
51887
|
}
|
|
51867
51888
|
const filesToSync = [".credentials.json", "settings.json", ".credentials.backup.json"];
|
|
51868
51889
|
for (const file2 of filesToSync) {
|
|
51869
|
-
const src =
|
|
51870
|
-
const dest =
|
|
51890
|
+
const src = import_node_path20.default.join(rootClaudeDir, file2);
|
|
51891
|
+
const dest = import_node_path20.default.join(agentConfigDir, file2);
|
|
51871
51892
|
try {
|
|
51872
51893
|
await fs16.copyFile(src, dest);
|
|
51873
51894
|
logger28.info("Synced credential file", { file: file2, from: src, to: dest });
|
|
@@ -51890,7 +51911,7 @@ async function chownRecursive(dirPath, uid, gid) {
|
|
|
51890
51911
|
return;
|
|
51891
51912
|
}
|
|
51892
51913
|
for (const entry of entries) {
|
|
51893
|
-
const fullPath =
|
|
51914
|
+
const fullPath = import_node_path20.default.join(dirPath, entry.name);
|
|
51894
51915
|
if (entry.isDirectory()) {
|
|
51895
51916
|
await chownRecursive(fullPath, uid, gid);
|
|
51896
51917
|
} else {
|
|
@@ -51905,7 +51926,7 @@ async function chownRecursive(dirPath, uid, gid) {
|
|
|
51905
51926
|
async function startBridge(config2) {
|
|
51906
51927
|
ensureDir(config2.dataDir);
|
|
51907
51928
|
ensureDir(config2.agentConfigDir);
|
|
51908
|
-
const workspacesDir =
|
|
51929
|
+
const workspacesDir = import_node_path20.default.join(config2.dataDir, "workspaces");
|
|
51909
51930
|
ensureDir(workspacesDir);
|
|
51910
51931
|
process.env.CLAUDE_CONFIG_DIR = config2.agentConfigDir;
|
|
51911
51932
|
installBridgeFetchAuth(config2.serverApiUrl, config2.bridgeToken);
|
|
@@ -51934,7 +51955,7 @@ Bridge token (register this machine at Settings \u2192 \u5DF2\u8FDE\u63A5\u7684\
|
|
|
51934
51955
|
`);
|
|
51935
51956
|
wsMetrics.start(5e3);
|
|
51936
51957
|
const sessionStore = new SessionStore(config2.dataDir);
|
|
51937
|
-
const memoryRoot =
|
|
51958
|
+
const memoryRoot = import_node_path20.default.join(config2.dataDir, "agent-memory");
|
|
51938
51959
|
const memoryStore = new AgentMemoryStore(memoryRoot);
|
|
51939
51960
|
logger28.info("Agent memory store initialized", { rootDir: memoryRoot });
|
|
51940
51961
|
const smithNotebook = memoryStore.read(SMITH_AGENT_ID);
|
|
@@ -52111,7 +52132,16 @@ Bridge token (register this machine at Settings \u2192 \u5DF2\u8FDE\u63A5\u7684\
|
|
|
52111
52132
|
const { requestId, path: dirPath } = msg.payload;
|
|
52112
52133
|
logger28.info("list_dir request received", { requestId, path: dirPath });
|
|
52113
52134
|
try {
|
|
52114
|
-
const
|
|
52135
|
+
const resolved = remapServerWorkspacePath(dirPath, workspacesDir);
|
|
52136
|
+
if (resolved.remapped) {
|
|
52137
|
+
ensureDir(resolved.path);
|
|
52138
|
+
logger28.info("list_dir path remapped to local Bridge workspace", {
|
|
52139
|
+
requestId,
|
|
52140
|
+
requested: dirPath,
|
|
52141
|
+
remapped: resolved.path
|
|
52142
|
+
});
|
|
52143
|
+
}
|
|
52144
|
+
const entries = await listDirectoryEntries(resolved.path);
|
|
52115
52145
|
connector?.send({
|
|
52116
52146
|
type: "bridge:list_dir_response",
|
|
52117
52147
|
payload: { requestId, entries }
|
|
@@ -52357,12 +52387,12 @@ init_cjs_shims();
|
|
|
52357
52387
|
var import_node_child_process3 = require("child_process");
|
|
52358
52388
|
var import_node_fs9 = __toESM(require("fs"), 1);
|
|
52359
52389
|
var import_node_os12 = __toESM(require("os"), 1);
|
|
52360
|
-
var
|
|
52390
|
+
var import_node_path21 = __toESM(require("path"), 1);
|
|
52361
52391
|
var logger29 = createModuleLogger("bridge.protocol");
|
|
52362
52392
|
function getStableExePath() {
|
|
52363
|
-
const bridgeDir =
|
|
52393
|
+
const bridgeDir = import_node_path21.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
|
|
52364
52394
|
import_node_fs9.default.mkdirSync(bridgeDir, { recursive: true });
|
|
52365
|
-
const stablePath =
|
|
52395
|
+
const stablePath = import_node_path21.default.join(bridgeDir, "cli.cjs");
|
|
52366
52396
|
import_node_fs9.default.copyFileSync(__filename, stablePath);
|
|
52367
52397
|
if (process.platform !== "win32") import_node_fs9.default.chmodSync(stablePath, 493);
|
|
52368
52398
|
return stablePath;
|
|
@@ -52381,8 +52411,8 @@ function registerProtocolHandler() {
|
|
|
52381
52411
|
function registerWindows() {
|
|
52382
52412
|
const nodeExe = process.execPath;
|
|
52383
52413
|
const stableExePath = getStableExePath();
|
|
52384
|
-
const bridgeDir =
|
|
52385
|
-
const psLauncherPath =
|
|
52414
|
+
const bridgeDir = import_node_path21.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
|
|
52415
|
+
const psLauncherPath = import_node_path21.default.join(bridgeDir, "launch-bridge.ps1");
|
|
52386
52416
|
import_node_fs9.default.writeFileSync(
|
|
52387
52417
|
psLauncherPath,
|
|
52388
52418
|
[
|
|
@@ -52391,7 +52421,7 @@ function registerWindows() {
|
|
|
52391
52421
|
].join("\r\n")
|
|
52392
52422
|
);
|
|
52393
52423
|
const handlerValue = `powershell -ExecutionPolicy Bypass -File "${psLauncherPath}" -url "%1"`;
|
|
52394
|
-
const psRegisterPath =
|
|
52424
|
+
const psRegisterPath = import_node_path21.default.join(bridgeDir, "register-protocol.ps1");
|
|
52395
52425
|
import_node_fs9.default.writeFileSync(
|
|
52396
52426
|
psRegisterPath,
|
|
52397
52427
|
[
|
|
@@ -52415,11 +52445,11 @@ function registerWindows() {
|
|
|
52415
52445
|
logger29.info("Windows protocol handler registered", { psLauncherPath });
|
|
52416
52446
|
}
|
|
52417
52447
|
function registerMacOS() {
|
|
52418
|
-
const appDir =
|
|
52448
|
+
const appDir = import_node_path21.default.join(import_node_os12.default.homedir(), "Applications", "AHChatBridge.app");
|
|
52419
52449
|
const nodeExe = process.execPath;
|
|
52420
52450
|
const stableExePath = getStableExePath();
|
|
52421
|
-
const bridgeDir =
|
|
52422
|
-
const launchScriptPath =
|
|
52451
|
+
const bridgeDir = import_node_path21.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
|
|
52452
|
+
const launchScriptPath = import_node_path21.default.join(bridgeDir, "launch-bridge.sh");
|
|
52423
52453
|
import_node_fs9.default.writeFileSync(
|
|
52424
52454
|
launchScriptPath,
|
|
52425
52455
|
`#!/bin/bash
|
|
@@ -52434,7 +52464,7 @@ exec ${JSON.stringify(nodeExe)} ${JSON.stringify(stableExePath)} launch --url "$
|
|
|
52434
52464
|
` do shell script "/bin/bash " & (quoted form of launchScript) & " " & (quoted form of thisURL) & " >/tmp/ahchat-bridge.log 2>&1 &"`,
|
|
52435
52465
|
`end open location`
|
|
52436
52466
|
].join("\n");
|
|
52437
|
-
const tmpScript =
|
|
52467
|
+
const tmpScript = import_node_path21.default.join(import_node_os12.default.tmpdir(), "AHChatBridge.applescript");
|
|
52438
52468
|
import_node_fs9.default.writeFileSync(tmpScript, appleScript);
|
|
52439
52469
|
try {
|
|
52440
52470
|
import_node_fs9.default.rmSync(appDir, { recursive: true, force: true });
|
|
@@ -52448,7 +52478,7 @@ exec ${JSON.stringify(nodeExe)} ${JSON.stringify(stableExePath)} launch --url "$
|
|
|
52448
52478
|
} catch {
|
|
52449
52479
|
}
|
|
52450
52480
|
}
|
|
52451
|
-
const plistPath =
|
|
52481
|
+
const plistPath = import_node_path21.default.join(appDir, "Contents", "Info.plist");
|
|
52452
52482
|
const urlTypes = JSON.stringify([{ CFBundleURLName: "AHChat Bridge", CFBundleURLSchemes: ["ahchat"] }]);
|
|
52453
52483
|
(0, import_node_child_process3.execSync)(
|
|
52454
52484
|
`/usr/bin/plutil -insert CFBundleURLTypes -json ${JSON.stringify(urlTypes)} ${JSON.stringify(plistPath)}`,
|
|
@@ -52472,8 +52502,8 @@ function registerLinux() {
|
|
|
52472
52502
|
`NoDisplay=true`,
|
|
52473
52503
|
`MimeType=x-scheme-handler/ahchat;`
|
|
52474
52504
|
].join("\n");
|
|
52475
|
-
const desktopPath =
|
|
52476
|
-
import_node_fs9.default.mkdirSync(
|
|
52505
|
+
const desktopPath = import_node_path21.default.join(import_node_os12.default.homedir(), ".local", "share", "applications", "ahchat-bridge.desktop");
|
|
52506
|
+
import_node_fs9.default.mkdirSync(import_node_path21.default.dirname(desktopPath), { recursive: true });
|
|
52477
52507
|
import_node_fs9.default.writeFileSync(desktopPath, desktopFile);
|
|
52478
52508
|
try {
|
|
52479
52509
|
(0, import_node_child_process3.execSync)("update-desktop-database ~/.local/share/applications/", { stdio: "pipe" });
|
|
@@ -52490,10 +52520,10 @@ function unregisterProtocolHandler() {
|
|
|
52490
52520
|
`powershell -ExecutionPolicy Bypass -Command "Remove-Item -Path 'HKCU:\\Software\\Classes\\ahchat' -Recurse -Force -ErrorAction SilentlyContinue"`,
|
|
52491
52521
|
{ stdio: "pipe" }
|
|
52492
52522
|
);
|
|
52493
|
-
const bridgeDir =
|
|
52523
|
+
const bridgeDir = import_node_path21.default.join(import_node_os12.default.homedir(), ".ahchat", "bridge");
|
|
52494
52524
|
for (const f7 of ["launch-bridge.ps1", "register-protocol.ps1"]) {
|
|
52495
52525
|
try {
|
|
52496
|
-
import_node_fs9.default.unlinkSync(
|
|
52526
|
+
import_node_fs9.default.unlinkSync(import_node_path21.default.join(bridgeDir, f7));
|
|
52497
52527
|
} catch {
|
|
52498
52528
|
}
|
|
52499
52529
|
}
|
|
@@ -52502,7 +52532,7 @@ function unregisterProtocolHandler() {
|
|
|
52502
52532
|
logger29.warn("Failed to unregister Windows protocol handler", { error: e7 });
|
|
52503
52533
|
}
|
|
52504
52534
|
} else if (platform === "darwin") {
|
|
52505
|
-
const appDir =
|
|
52535
|
+
const appDir = import_node_path21.default.join(import_node_os12.default.homedir(), "Applications", "AHChatBridge.app");
|
|
52506
52536
|
try {
|
|
52507
52537
|
import_node_fs9.default.rmSync(appDir, { recursive: true, force: true });
|
|
52508
52538
|
logger29.info("macOS protocol handler unregistered");
|
|
@@ -52510,7 +52540,7 @@ function unregisterProtocolHandler() {
|
|
|
52510
52540
|
logger29.warn("Failed to unregister macOS protocol handler", { error: e7 });
|
|
52511
52541
|
}
|
|
52512
52542
|
} else {
|
|
52513
|
-
const desktopPath =
|
|
52543
|
+
const desktopPath = import_node_path21.default.join(import_node_os12.default.homedir(), ".local", "share", "applications", "ahchat-bridge.desktop");
|
|
52514
52544
|
try {
|
|
52515
52545
|
import_node_fs9.default.unlinkSync(desktopPath);
|
|
52516
52546
|
logger29.info("Linux protocol handler unregistered");
|
|
@@ -52529,10 +52559,10 @@ function isProtocolRegistered() {
|
|
|
52529
52559
|
return false;
|
|
52530
52560
|
}
|
|
52531
52561
|
} else if (platform === "darwin") {
|
|
52532
|
-
const appDir =
|
|
52533
|
-
return import_node_fs9.default.existsSync(
|
|
52562
|
+
const appDir = import_node_path21.default.join(import_node_os12.default.homedir(), "Applications", "AHChatBridge.app");
|
|
52563
|
+
return import_node_fs9.default.existsSync(import_node_path21.default.join(appDir, "Contents", "Info.plist"));
|
|
52534
52564
|
} else {
|
|
52535
|
-
const desktopPath =
|
|
52565
|
+
const desktopPath = import_node_path21.default.join(import_node_os12.default.homedir(), ".local", "share", "applications", "ahchat-bridge.desktop");
|
|
52536
52566
|
return import_node_fs9.default.existsSync(desktopPath);
|
|
52537
52567
|
}
|
|
52538
52568
|
}
|
|
@@ -52541,9 +52571,9 @@ function isProtocolRegistered() {
|
|
|
52541
52571
|
var logger30 = createModuleLogger("bridge");
|
|
52542
52572
|
function readCliVersion() {
|
|
52543
52573
|
const candidates = [
|
|
52544
|
-
|
|
52545
|
-
|
|
52546
|
-
|
|
52574
|
+
import_node_path22.default.resolve(__dirname, "../package.json"),
|
|
52575
|
+
import_node_path22.default.resolve(__dirname, "../../package.json"),
|
|
52576
|
+
import_node_path22.default.resolve(process.cwd(), "packages/bridge/package.json")
|
|
52547
52577
|
];
|
|
52548
52578
|
for (const candidate of candidates) {
|
|
52549
52579
|
if (!import_node_fs10.default.existsSync(candidate)) continue;
|
|
@@ -52556,24 +52586,24 @@ function readCliVersion() {
|
|
|
52556
52586
|
logger30.warn("Unable to read CLI package version candidate", { error: e7, candidate });
|
|
52557
52587
|
}
|
|
52558
52588
|
}
|
|
52559
|
-
return "0.1.
|
|
52589
|
+
return "0.1.21";
|
|
52560
52590
|
}
|
|
52561
52591
|
function resolveDataDir(dataDir) {
|
|
52562
52592
|
const userHome = process.env.USERPROFILE || import_node_os13.default.homedir();
|
|
52563
52593
|
if (/^~[/\\]/.test(dataDir)) {
|
|
52564
|
-
return
|
|
52594
|
+
return import_node_path22.default.join(import_node_os13.default.homedir(), dataDir.slice(2));
|
|
52565
52595
|
}
|
|
52566
52596
|
if (dataDir === "$env:USERPROFILE") {
|
|
52567
52597
|
return userHome;
|
|
52568
52598
|
}
|
|
52569
52599
|
if (dataDir.startsWith("$env:USERPROFILE\\") || dataDir.startsWith("$env:USERPROFILE/")) {
|
|
52570
|
-
return
|
|
52600
|
+
return import_node_path22.default.join(userHome, dataDir.slice("$env:USERPROFILE".length + 1));
|
|
52571
52601
|
}
|
|
52572
52602
|
if (dataDir === "%USERPROFILE%") {
|
|
52573
52603
|
return userHome;
|
|
52574
52604
|
}
|
|
52575
52605
|
if (dataDir.startsWith("%USERPROFILE%\\") || dataDir.startsWith("%USERPROFILE%/")) {
|
|
52576
|
-
return
|
|
52606
|
+
return import_node_path22.default.join(userHome, dataDir.slice("%USERPROFILE%".length + 1));
|
|
52577
52607
|
}
|
|
52578
52608
|
return dataDir;
|
|
52579
52609
|
}
|