@maind-dev/mcp-bridge 0.34.0 → 0.35.0
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/build/index.js +180 -132
- package/build/meta.json +1 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -202,7 +202,7 @@ var BRIDGE_VERSION;
|
|
|
202
202
|
var init_version = __esm({
|
|
203
203
|
"src/version.ts"() {
|
|
204
204
|
"use strict";
|
|
205
|
-
BRIDGE_VERSION = "0.
|
|
205
|
+
BRIDGE_VERSION = "0.35.0";
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
|
|
@@ -259,8 +259,8 @@ var init_project_key = __esm({
|
|
|
259
259
|
// src/install/bridge-entry.ts
|
|
260
260
|
import path2 from "node:path";
|
|
261
261
|
import { fileURLToPath } from "node:url";
|
|
262
|
-
function isEphemeralEntry(entryPath,
|
|
263
|
-
return entryPath.split(
|
|
262
|
+
function isEphemeralEntry(entryPath, sep3 = path2.sep) {
|
|
263
|
+
return entryPath.split(sep3).includes("_npx");
|
|
264
264
|
}
|
|
265
265
|
function resolveBridgeLaunch(opts) {
|
|
266
266
|
const extra = opts.extraArgs ?? [];
|
|
@@ -786,8 +786,8 @@ async function promptYesNo(out2, prompt) {
|
|
|
786
786
|
output: out2,
|
|
787
787
|
terminal: true
|
|
788
788
|
});
|
|
789
|
-
const answer = await new Promise((
|
|
790
|
-
rl.question("", (input) =>
|
|
789
|
+
const answer = await new Promise((resolve4) => {
|
|
790
|
+
rl.question("", (input) => resolve4(input.trim().toLowerCase()));
|
|
791
791
|
});
|
|
792
792
|
rl.close();
|
|
793
793
|
if (answer === "" || answer === "y" || answer === "yes") return true;
|
|
@@ -2952,15 +2952,15 @@ function autoWorkingPathsEnabled(env, config) {
|
|
|
2952
2952
|
return config?.auto_working_paths === true;
|
|
2953
2953
|
}
|
|
2954
2954
|
async function defaultGitBranch() {
|
|
2955
|
-
return await new Promise((
|
|
2955
|
+
return await new Promise((resolve4) => {
|
|
2956
2956
|
execFile(
|
|
2957
2957
|
"git",
|
|
2958
2958
|
["rev-parse", "--abbrev-ref", "HEAD"],
|
|
2959
2959
|
{ timeout: 2e3, encoding: "utf8" },
|
|
2960
2960
|
(err, stdout) => {
|
|
2961
|
-
if (err) return
|
|
2961
|
+
if (err) return resolve4(null);
|
|
2962
2962
|
const branch = stdout.trim();
|
|
2963
|
-
|
|
2963
|
+
resolve4(branch.length > 0 && branch !== "HEAD" ? branch : null);
|
|
2964
2964
|
}
|
|
2965
2965
|
);
|
|
2966
2966
|
});
|
|
@@ -3048,7 +3048,7 @@ var init_presence = __esm({
|
|
|
3048
3048
|
this.ended = true;
|
|
3049
3049
|
if (this.lastAnnounceAt === 0) return;
|
|
3050
3050
|
const timeout = new Promise(
|
|
3051
|
-
(
|
|
3051
|
+
(resolve4) => setTimeout(resolve4, END_TIMEOUT_MS).unref()
|
|
3052
3052
|
);
|
|
3053
3053
|
await Promise.race([this.send("ended"), timeout]);
|
|
3054
3054
|
}
|
|
@@ -3142,12 +3142,12 @@ import {
|
|
|
3142
3142
|
writeFileSync as writeFileSync3
|
|
3143
3143
|
} from "node:fs";
|
|
3144
3144
|
import { homedir as homedir3 } from "node:os";
|
|
3145
|
-
import { join as
|
|
3145
|
+
import { join as join14 } from "node:path";
|
|
3146
3146
|
function presenceSnapshotBaseDir() {
|
|
3147
|
-
return
|
|
3147
|
+
return join14(homedir3(), ".maind", "presence");
|
|
3148
3148
|
}
|
|
3149
3149
|
function projectDir(baseDir, projectKey) {
|
|
3150
|
-
return
|
|
3150
|
+
return join14(baseDir, projectKey);
|
|
3151
3151
|
}
|
|
3152
3152
|
function createSnapshotStore(opts) {
|
|
3153
3153
|
const baseDir = opts.baseDir ?? presenceSnapshotBaseDir();
|
|
@@ -3176,7 +3176,7 @@ function createSnapshotStore(opts) {
|
|
|
3176
3176
|
conflicts: Array.isArray(p.conflicts) ? p.conflicts : []
|
|
3177
3177
|
};
|
|
3178
3178
|
mkdirSync4(dir, { recursive: true, mode: 448 });
|
|
3179
|
-
ownFile =
|
|
3179
|
+
ownFile = join14(dir, `${meta.sessionId}.json`);
|
|
3180
3180
|
const tmp = `${ownFile}.tmp-${pid}`;
|
|
3181
3181
|
writeFileSync3(tmp, JSON.stringify(snapshot), { mode: 384 });
|
|
3182
3182
|
renameSync2(tmp, ownFile);
|
|
@@ -3196,7 +3196,7 @@ function pruneStale(dir, nowMs, keep) {
|
|
|
3196
3196
|
try {
|
|
3197
3197
|
for (const name of readdirSync4(dir)) {
|
|
3198
3198
|
if (!name.endsWith(".json")) continue;
|
|
3199
|
-
const file =
|
|
3199
|
+
const file = join14(dir, name);
|
|
3200
3200
|
if (file === keep) continue;
|
|
3201
3201
|
try {
|
|
3202
3202
|
const age = nowMs - statSync3(file).mtimeMs;
|
|
@@ -3215,7 +3215,7 @@ function readSnapshots(projectKey, baseDir = presenceSnapshotBaseDir()) {
|
|
|
3215
3215
|
if (!name.endsWith(".json")) continue;
|
|
3216
3216
|
try {
|
|
3217
3217
|
const raw = JSON.parse(
|
|
3218
|
-
readFileSync7(
|
|
3218
|
+
readFileSync7(join14(dir, name), "utf8")
|
|
3219
3219
|
);
|
|
3220
3220
|
const snap = parseSnapshot(raw);
|
|
3221
3221
|
if (snap) out2.push(snap);
|
|
@@ -3268,11 +3268,11 @@ var init_types4 = __esm({
|
|
|
3268
3268
|
});
|
|
3269
3269
|
|
|
3270
3270
|
// ../../packages/claude-code-telemetry/dist/transcript.js
|
|
3271
|
-
import { createReadStream, existsSync as
|
|
3271
|
+
import { createReadStream, existsSync as existsSync7 } from "node:fs";
|
|
3272
3272
|
import { stat } from "node:fs/promises";
|
|
3273
3273
|
import { createInterface as createInterface5 } from "node:readline";
|
|
3274
3274
|
async function summariseTranscript(path8) {
|
|
3275
|
-
if (!path8 || !
|
|
3275
|
+
if (!path8 || !existsSync7(path8))
|
|
3276
3276
|
return null;
|
|
3277
3277
|
let stats;
|
|
3278
3278
|
try {
|
|
@@ -3283,7 +3283,7 @@ async function summariseTranscript(path8) {
|
|
|
3283
3283
|
let input = 0;
|
|
3284
3284
|
let output = 0;
|
|
3285
3285
|
let lines2 = 0;
|
|
3286
|
-
return await new Promise((
|
|
3286
|
+
return await new Promise((resolve4) => {
|
|
3287
3287
|
const stream = createReadStream(path8, { encoding: "utf-8" });
|
|
3288
3288
|
const rl = createInterface5({ input: stream });
|
|
3289
3289
|
rl.on("line", (line) => {
|
|
@@ -3304,7 +3304,7 @@ async function summariseTranscript(path8) {
|
|
|
3304
3304
|
}
|
|
3305
3305
|
});
|
|
3306
3306
|
rl.on("close", () => {
|
|
3307
|
-
|
|
3307
|
+
resolve4({
|
|
3308
3308
|
input_tokens: input,
|
|
3309
3309
|
output_tokens: output,
|
|
3310
3310
|
total_tokens: input + output,
|
|
@@ -3312,8 +3312,8 @@ async function summariseTranscript(path8) {
|
|
|
3312
3312
|
last_modified_ms: stats.mtimeMs
|
|
3313
3313
|
});
|
|
3314
3314
|
});
|
|
3315
|
-
rl.on("error", () =>
|
|
3316
|
-
stream.on("error", () =>
|
|
3315
|
+
rl.on("error", () => resolve4(null));
|
|
3316
|
+
stream.on("error", () => resolve4(null));
|
|
3317
3317
|
});
|
|
3318
3318
|
}
|
|
3319
3319
|
var init_transcript = __esm({
|
|
@@ -3357,7 +3357,7 @@ var init_effort = __esm({
|
|
|
3357
3357
|
});
|
|
3358
3358
|
|
|
3359
3359
|
// ../../packages/claude-code-telemetry/dist/session-analysis.js
|
|
3360
|
-
import { createReadStream as createReadStream2, existsSync as
|
|
3360
|
+
import { createReadStream as createReadStream2, existsSync as existsSync8 } from "node:fs";
|
|
3361
3361
|
import { createInterface as createInterface6 } from "node:readline";
|
|
3362
3362
|
function num2(v) {
|
|
3363
3363
|
return typeof v === "number" && Number.isFinite(v) ? v : 0;
|
|
@@ -3464,14 +3464,14 @@ function emptyAnalysis(sessionId) {
|
|
|
3464
3464
|
}
|
|
3465
3465
|
async function analyzeSession(path8) {
|
|
3466
3466
|
const a = emptyAnalysis("");
|
|
3467
|
-
if (!path8 || !
|
|
3467
|
+
if (!path8 || !existsSync8(path8))
|
|
3468
3468
|
return a;
|
|
3469
3469
|
const reactions = [];
|
|
3470
3470
|
const modelMix = /* @__PURE__ */ new Map();
|
|
3471
3471
|
let effort = null;
|
|
3472
3472
|
let priorAssistantWorked = false;
|
|
3473
3473
|
let prevUserText = null;
|
|
3474
|
-
await new Promise((
|
|
3474
|
+
await new Promise((resolve4) => {
|
|
3475
3475
|
const stream = createReadStream2(path8, { encoding: "utf-8" });
|
|
3476
3476
|
const rl = createInterface6({ input: stream });
|
|
3477
3477
|
const processLine = (line) => {
|
|
@@ -3581,9 +3581,9 @@ async function analyzeSession(path8) {
|
|
|
3581
3581
|
} catch {
|
|
3582
3582
|
}
|
|
3583
3583
|
});
|
|
3584
|
-
rl.on("close", () =>
|
|
3585
|
-
rl.on("error", () =>
|
|
3586
|
-
stream.on("error", () =>
|
|
3584
|
+
rl.on("close", () => resolve4());
|
|
3585
|
+
rl.on("error", () => resolve4());
|
|
3586
|
+
stream.on("error", () => resolve4());
|
|
3587
3587
|
});
|
|
3588
3588
|
a.effort_at_end = effort;
|
|
3589
3589
|
a.model_mix = [...modelMix.values()].sort((x, y) => x.first_ts - y.first_ts || x.model.localeCompare(y.model));
|
|
@@ -3660,7 +3660,7 @@ var init_ingest = __esm({
|
|
|
3660
3660
|
});
|
|
3661
3661
|
|
|
3662
3662
|
// ../../packages/claude-code-telemetry/dist/session-span.js
|
|
3663
|
-
import { createReadStream as createReadStream3, existsSync as
|
|
3663
|
+
import { createReadStream as createReadStream3, existsSync as existsSync9 } from "node:fs";
|
|
3664
3664
|
import { createInterface as createInterface7 } from "node:readline";
|
|
3665
3665
|
function asBlocks2(content) {
|
|
3666
3666
|
if (typeof content === "string")
|
|
@@ -3712,7 +3712,7 @@ function classify2(parsed) {
|
|
|
3712
3712
|
}
|
|
3713
3713
|
async function analyzeSpan(path8) {
|
|
3714
3714
|
const s = emptySpan("");
|
|
3715
|
-
if (!path8 || !
|
|
3715
|
+
if (!path8 || !existsSync9(path8))
|
|
3716
3716
|
return s;
|
|
3717
3717
|
let firstMs = null;
|
|
3718
3718
|
let lastMs = 0;
|
|
@@ -3720,7 +3720,7 @@ async function analyzeSpan(path8) {
|
|
|
3720
3720
|
let prevMs = null;
|
|
3721
3721
|
let prevHolder = "human";
|
|
3722
3722
|
const pauses = [];
|
|
3723
|
-
await new Promise((
|
|
3723
|
+
await new Promise((resolve4) => {
|
|
3724
3724
|
const stream = createReadStream3(path8, { encoding: "utf-8" });
|
|
3725
3725
|
const rl = createInterface7({ input: stream });
|
|
3726
3726
|
const processLine = (line) => {
|
|
@@ -3778,9 +3778,9 @@ async function analyzeSpan(path8) {
|
|
|
3778
3778
|
} catch {
|
|
3779
3779
|
}
|
|
3780
3780
|
});
|
|
3781
|
-
rl.on("close", () =>
|
|
3782
|
-
rl.on("error", () =>
|
|
3783
|
-
stream.on("error", () =>
|
|
3781
|
+
rl.on("close", () => resolve4());
|
|
3782
|
+
rl.on("error", () => resolve4());
|
|
3783
|
+
stream.on("error", () => resolve4());
|
|
3784
3784
|
});
|
|
3785
3785
|
if (firstMs === null)
|
|
3786
3786
|
return s;
|
|
@@ -3825,13 +3825,13 @@ var init_windows = __esm({
|
|
|
3825
3825
|
|
|
3826
3826
|
// ../../packages/claude-code-telemetry/dist/projects.js
|
|
3827
3827
|
import { homedir as homedir4 } from "node:os";
|
|
3828
|
-
import { join as
|
|
3828
|
+
import { join as join15 } from "node:path";
|
|
3829
3829
|
var HOME, DEFAULT_PROJECTS_DIR;
|
|
3830
3830
|
var init_projects = __esm({
|
|
3831
3831
|
"../../packages/claude-code-telemetry/dist/projects.js"() {
|
|
3832
3832
|
"use strict";
|
|
3833
3833
|
HOME = homedir4();
|
|
3834
|
-
DEFAULT_PROJECTS_DIR =
|
|
3834
|
+
DEFAULT_PROJECTS_DIR = join15(HOME, ".claude", "projects");
|
|
3835
3835
|
}
|
|
3836
3836
|
});
|
|
3837
3837
|
|
|
@@ -4015,13 +4015,13 @@ var init_edit_guard = __esm({
|
|
|
4015
4015
|
async function readHookInput() {
|
|
4016
4016
|
if (process.stdin.isTTY) return {};
|
|
4017
4017
|
const chunks = [];
|
|
4018
|
-
return await new Promise((
|
|
4018
|
+
return await new Promise((resolve4) => {
|
|
4019
4019
|
let settled = false;
|
|
4020
4020
|
const settle = (value) => {
|
|
4021
4021
|
if (settled) return;
|
|
4022
4022
|
settled = true;
|
|
4023
4023
|
clearTimeout(timer);
|
|
4024
|
-
|
|
4024
|
+
resolve4(value);
|
|
4025
4025
|
};
|
|
4026
4026
|
const timer = setTimeout(() => settle({}), STDIN_TIMEOUT_MS);
|
|
4027
4027
|
process.stdin.on("data", (c) => chunks.push(c));
|
|
@@ -4079,14 +4079,14 @@ var init_payloads = __esm({
|
|
|
4079
4079
|
|
|
4080
4080
|
// src/hooks/state.ts
|
|
4081
4081
|
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2, rename as rename2 } from "node:fs/promises";
|
|
4082
|
-
import { existsSync as
|
|
4082
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
4083
4083
|
import { homedir as homedir5 } from "node:os";
|
|
4084
|
-
import { join as
|
|
4084
|
+
import { join as join16 } from "node:path";
|
|
4085
4085
|
function emptyState() {
|
|
4086
4086
|
return { config: null, sessions: {}, pending_metrics: [] };
|
|
4087
4087
|
}
|
|
4088
4088
|
async function loadState() {
|
|
4089
|
-
if (!
|
|
4089
|
+
if (!existsSync10(STATE_FILE)) return emptyState();
|
|
4090
4090
|
try {
|
|
4091
4091
|
const raw = await readFile2(STATE_FILE, "utf-8");
|
|
4092
4092
|
const parsed = JSON.parse(raw);
|
|
@@ -4107,7 +4107,7 @@ async function loadState() {
|
|
|
4107
4107
|
}
|
|
4108
4108
|
}
|
|
4109
4109
|
async function saveState(state) {
|
|
4110
|
-
if (!
|
|
4110
|
+
if (!existsSync10(STATE_DIR)) {
|
|
4111
4111
|
await mkdir2(STATE_DIR, { recursive: true, mode: 448 });
|
|
4112
4112
|
}
|
|
4113
4113
|
const tmp = `${STATE_FILE}.tmp`;
|
|
@@ -4121,8 +4121,8 @@ var STATE_DIR, STATE_FILE, DEFAULT_THRESHOLDS;
|
|
|
4121
4121
|
var init_state = __esm({
|
|
4122
4122
|
"src/hooks/state.ts"() {
|
|
4123
4123
|
"use strict";
|
|
4124
|
-
STATE_DIR =
|
|
4125
|
-
STATE_FILE =
|
|
4124
|
+
STATE_DIR = join16(homedir5(), ".maind");
|
|
4125
|
+
STATE_FILE = join16(STATE_DIR, "state.json");
|
|
4126
4126
|
DEFAULT_THRESHOLDS = {
|
|
4127
4127
|
warn_at_pct: 60,
|
|
4128
4128
|
handoff_at_pct: 85,
|
|
@@ -4148,10 +4148,10 @@ __export(hooks_exports, {
|
|
|
4148
4148
|
runSyncConfig: () => runSyncConfig
|
|
4149
4149
|
});
|
|
4150
4150
|
import { execFileSync as execFileSync7 } from "node:child_process";
|
|
4151
|
-
import { existsSync as
|
|
4151
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync2 } from "node:fs";
|
|
4152
4152
|
import { writeFile as writeFile3 } from "node:fs/promises";
|
|
4153
4153
|
import { homedir as homedir6 } from "node:os";
|
|
4154
|
-
import { basename, dirname as
|
|
4154
|
+
import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute4, join as join17, relative as relative3 } from "node:path";
|
|
4155
4155
|
function recordGuardSignals(state, sessionId, toolName, nowMs = Date.now()) {
|
|
4156
4156
|
if (!toolName.includes("maind")) return;
|
|
4157
4157
|
const consulted = toolName.includes("search_lessons") || toolName.includes("get_session_briefing") || toolName.includes("get_lesson") || toolName.includes("get_conventions") || toolName.includes("activate_skill") || toolName.includes("suggest_skills") || toolName.includes("codebase_change_briefing");
|
|
@@ -4267,8 +4267,8 @@ async function runOnSessionStart() {
|
|
|
4267
4267
|
}
|
|
4268
4268
|
function readSettingsRaw() {
|
|
4269
4269
|
try {
|
|
4270
|
-
const p =
|
|
4271
|
-
return
|
|
4270
|
+
const p = join17(homedir6(), ".claude", "settings.json");
|
|
4271
|
+
return existsSync11(p) ? readFileSync8(p, "utf8") : null;
|
|
4272
4272
|
} catch {
|
|
4273
4273
|
return null;
|
|
4274
4274
|
}
|
|
@@ -4313,16 +4313,16 @@ async function runOnToolUse() {
|
|
|
4313
4313
|
return 0;
|
|
4314
4314
|
}
|
|
4315
4315
|
function realpathOfUnwritten(p) {
|
|
4316
|
-
let head =
|
|
4317
|
-
const tail = [
|
|
4316
|
+
let head = dirname6(p);
|
|
4317
|
+
const tail = [basename2(p)];
|
|
4318
4318
|
for (; ; ) {
|
|
4319
4319
|
try {
|
|
4320
|
-
const real =
|
|
4321
|
-
return
|
|
4320
|
+
const real = realpathSync2(head);
|
|
4321
|
+
return join17(real, ...tail.reverse());
|
|
4322
4322
|
} catch {
|
|
4323
|
-
const parent =
|
|
4323
|
+
const parent = dirname6(head);
|
|
4324
4324
|
if (parent === head) return p;
|
|
4325
|
-
tail.push(
|
|
4325
|
+
tail.push(basename2(head));
|
|
4326
4326
|
head = parent;
|
|
4327
4327
|
}
|
|
4328
4328
|
}
|
|
@@ -4343,11 +4343,11 @@ async function runOnFileWrite() {
|
|
|
4343
4343
|
const filePath = toolFilePathOf(input);
|
|
4344
4344
|
if (!filePath) return 0;
|
|
4345
4345
|
const cwd = typeof input.cwd === "string" && input.cwd.length > 0 ? input.cwd : process.cwd();
|
|
4346
|
-
const abs =
|
|
4347
|
-
if (
|
|
4346
|
+
const abs = isAbsolute4(filePath) ? filePath : join17(cwd, filePath);
|
|
4347
|
+
if (existsSync11(abs)) return 0;
|
|
4348
4348
|
const repoRoot = resolveRepoRoot(cwd);
|
|
4349
|
-
const rel =
|
|
4350
|
-
if (rel.length === 0 || rel.startsWith("..") ||
|
|
4349
|
+
const rel = relative3(repoRoot, realpathOfUnwritten(abs));
|
|
4350
|
+
if (rel.length === 0 || rel.startsWith("..") || isAbsolute4(rel)) return 0;
|
|
4351
4351
|
const verdict = await checkNumberForPath(repoRoot, rel);
|
|
4352
4352
|
if (!verdict.taken || verdict.namespace === null) return 0;
|
|
4353
4353
|
process.stdout.write(denyPayload(denyReason(verdict, verdict.namespace)));
|
|
@@ -4364,7 +4364,7 @@ async function runOnFileEdit() {
|
|
|
4364
4364
|
const filePath = toolFilePathOf(input);
|
|
4365
4365
|
if (!filePath) return 0;
|
|
4366
4366
|
const cwd = typeof input.cwd === "string" && input.cwd.length > 0 ? input.cwd : process.cwd();
|
|
4367
|
-
const abs =
|
|
4367
|
+
const abs = isAbsolute4(filePath) ? filePath : join17(cwd, filePath);
|
|
4368
4368
|
const projectKey = computeProjectKey();
|
|
4369
4369
|
if (projectKey === null) return 0;
|
|
4370
4370
|
const snaps = readSnapshots(projectKey);
|
|
@@ -4375,9 +4375,9 @@ async function runOnFileEdit() {
|
|
|
4375
4375
|
});
|
|
4376
4376
|
if (own === null) return 0;
|
|
4377
4377
|
const repoRoot = resolveRepoRoot(cwd);
|
|
4378
|
-
const real =
|
|
4379
|
-
const rel =
|
|
4380
|
-
if (rel.length === 0 || rel.startsWith("..") ||
|
|
4378
|
+
const real = existsSync11(abs) ? realpathSync2(abs) : realpathOfUnwritten(abs);
|
|
4379
|
+
const rel = relative3(repoRoot, real).replace(/\\/g, "/");
|
|
4380
|
+
if (rel.length === 0 || rel.startsWith("..") || isAbsolute4(rel)) return 0;
|
|
4381
4381
|
const advice = adviseOnPath(own.snap, rel, {
|
|
4382
4382
|
via: own.via,
|
|
4383
4383
|
currentBranch: own.via === "cwd" ? currentGitBranch(cwd) : null,
|
|
@@ -4427,7 +4427,7 @@ async function maybeEmitAdvisory(state, session) {
|
|
|
4427
4427
|
};
|
|
4428
4428
|
try {
|
|
4429
4429
|
await writeFile3(
|
|
4430
|
-
|
|
4430
|
+
join17(STATE_DIR, `handoff_advisory_${session.session_id}.json`),
|
|
4431
4431
|
JSON.stringify(payload, null, 2)
|
|
4432
4432
|
);
|
|
4433
4433
|
} catch (err) {
|
|
@@ -4487,7 +4487,7 @@ async function flushPending(config, timeoutMs) {
|
|
|
4487
4487
|
const batch = state.pending_metrics.slice(0, 100);
|
|
4488
4488
|
const post = postMetrics(config.endpoint, config.api_key, batch);
|
|
4489
4489
|
const timeout = new Promise(
|
|
4490
|
-
(
|
|
4490
|
+
(resolve4) => setTimeout(() => resolve4({ ok: false, inserted: 0, error: "timeout" }), timeoutMs)
|
|
4491
4491
|
);
|
|
4492
4492
|
const result = await Promise.race([post, timeout]);
|
|
4493
4493
|
if (result.ok) {
|
|
@@ -4547,10 +4547,10 @@ async function runHookStatus() {
|
|
|
4547
4547
|
return 0;
|
|
4548
4548
|
}
|
|
4549
4549
|
function readHookWiring() {
|
|
4550
|
-
const settingsPath =
|
|
4550
|
+
const settingsPath = join17(homedir6(), ".claude", "settings.json");
|
|
4551
4551
|
let raw = null;
|
|
4552
4552
|
try {
|
|
4553
|
-
if (
|
|
4553
|
+
if (existsSync11(settingsPath)) raw = readFileSync8(settingsPath, "utf8");
|
|
4554
4554
|
} catch {
|
|
4555
4555
|
}
|
|
4556
4556
|
return { settingsPath, findings: inspectHookWiring(raw) };
|
|
@@ -4705,7 +4705,7 @@ async function postWithTimeout(apiKey, deviceId, body, timeoutMs) {
|
|
|
4705
4705
|
},
|
|
4706
4706
|
body: JSON.stringify(body)
|
|
4707
4707
|
}).then(() => void 0).catch(() => void 0);
|
|
4708
|
-
const timeout = new Promise((
|
|
4708
|
+
const timeout = new Promise((resolve4) => setTimeout(resolve4, timeoutMs));
|
|
4709
4709
|
await Promise.race([post, timeout]);
|
|
4710
4710
|
}
|
|
4711
4711
|
async function runOnSessionEnd() {
|
|
@@ -4891,16 +4891,16 @@ var init_install = __esm({
|
|
|
4891
4891
|
});
|
|
4892
4892
|
|
|
4893
4893
|
// src/guard/session-file.ts
|
|
4894
|
-
import { existsSync as
|
|
4894
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
4895
4895
|
import { mkdir as mkdir3, readFile as readFile3, readdir, rename as rename3, stat as stat2, unlink as unlink2, writeFile as writeFile4 } from "node:fs/promises";
|
|
4896
|
-
import { join as
|
|
4896
|
+
import { join as join18 } from "node:path";
|
|
4897
4897
|
function sessionFile(sessionId) {
|
|
4898
|
-
return
|
|
4898
|
+
return join18(GUARD_SESSIONS_DIR, sessionId.replace(/[^a-zA-Z0-9._-]/g, "_") + ".json");
|
|
4899
4899
|
}
|
|
4900
4900
|
async function loadGuardSession(sessionId) {
|
|
4901
4901
|
try {
|
|
4902
4902
|
const file = sessionFile(sessionId);
|
|
4903
|
-
if (!
|
|
4903
|
+
if (!existsSync12(file)) return {};
|
|
4904
4904
|
const parsed = JSON.parse(await readFile3(file, "utf8"));
|
|
4905
4905
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
4906
4906
|
return parsed;
|
|
@@ -4921,10 +4921,10 @@ async function saveGuardSession(sessionId, state) {
|
|
|
4921
4921
|
}
|
|
4922
4922
|
async function sweepOldGuardSessions(maxAgeMs = 7 * 24 * 60 * 60 * 1e3, nowMs = Date.now()) {
|
|
4923
4923
|
try {
|
|
4924
|
-
if (!
|
|
4924
|
+
if (!existsSync12(GUARD_SESSIONS_DIR)) return;
|
|
4925
4925
|
for (const name of await readdir(GUARD_SESSIONS_DIR)) {
|
|
4926
4926
|
if (!name.endsWith(".json")) continue;
|
|
4927
|
-
const file =
|
|
4927
|
+
const file = join18(GUARD_SESSIONS_DIR, name);
|
|
4928
4928
|
try {
|
|
4929
4929
|
const s = await stat2(file);
|
|
4930
4930
|
if (nowMs - s.mtimeMs > maxAgeMs) await unlink2(file);
|
|
@@ -4939,15 +4939,15 @@ var init_session_file = __esm({
|
|
|
4939
4939
|
"src/guard/session-file.ts"() {
|
|
4940
4940
|
"use strict";
|
|
4941
4941
|
init_state();
|
|
4942
|
-
GUARD_DIR =
|
|
4943
|
-
GUARD_SESSIONS_DIR =
|
|
4942
|
+
GUARD_DIR = join18(STATE_DIR, "guard");
|
|
4943
|
+
GUARD_SESSIONS_DIR = join18(GUARD_DIR, "sessions");
|
|
4944
4944
|
}
|
|
4945
4945
|
});
|
|
4946
4946
|
|
|
4947
4947
|
// src/guard/log.ts
|
|
4948
|
-
import { existsSync as
|
|
4948
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
4949
4949
|
import { appendFile, mkdir as mkdir4, open } from "node:fs/promises";
|
|
4950
|
-
import { join as
|
|
4950
|
+
import { join as join19 } from "node:path";
|
|
4951
4951
|
async function appendGuardEvent(event) {
|
|
4952
4952
|
try {
|
|
4953
4953
|
await mkdir4(GUARD_DIR, { recursive: true, mode: 448 });
|
|
@@ -4969,7 +4969,7 @@ async function readGuardEventCounts(tailBytes = 256 * 1024) {
|
|
|
4969
4969
|
cross_session_deny: 0
|
|
4970
4970
|
};
|
|
4971
4971
|
try {
|
|
4972
|
-
if (!
|
|
4972
|
+
if (!existsSync13(GUARD_EVENTS_FILE)) return counts;
|
|
4973
4973
|
const fh = await open(GUARD_EVENTS_FILE, "r");
|
|
4974
4974
|
try {
|
|
4975
4975
|
const size = (await fh.stat()).size;
|
|
@@ -5000,7 +5000,7 @@ var init_log = __esm({
|
|
|
5000
5000
|
"src/guard/log.ts"() {
|
|
5001
5001
|
"use strict";
|
|
5002
5002
|
init_session_file();
|
|
5003
|
-
GUARD_EVENTS_FILE =
|
|
5003
|
+
GUARD_EVENTS_FILE = join19(GUARD_DIR, "events.jsonl");
|
|
5004
5004
|
}
|
|
5005
5005
|
});
|
|
5006
5006
|
|
|
@@ -5009,9 +5009,9 @@ var cli_exports = {};
|
|
|
5009
5009
|
__export(cli_exports, {
|
|
5010
5010
|
runGuard: () => runGuard
|
|
5011
5011
|
});
|
|
5012
|
-
import { existsSync as
|
|
5012
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
5013
5013
|
import { homedir as homedir7 } from "node:os";
|
|
5014
|
-
import { join as
|
|
5014
|
+
import { join as join20 } from "node:path";
|
|
5015
5015
|
async function runGuard(argv) {
|
|
5016
5016
|
const verb = argv[0];
|
|
5017
5017
|
const rest = argv.slice(1);
|
|
@@ -5088,10 +5088,10 @@ logged (auditable) in ${GUARD_EVENTS_FILE}
|
|
|
5088
5088
|
}
|
|
5089
5089
|
async function runGuardStatus() {
|
|
5090
5090
|
const config = resolveGuardConfig();
|
|
5091
|
-
const settingsPath =
|
|
5091
|
+
const settingsPath = join20(homedir7(), ".claude", "settings.json");
|
|
5092
5092
|
let raw = null;
|
|
5093
5093
|
try {
|
|
5094
|
-
if (
|
|
5094
|
+
if (existsSync14(settingsPath)) raw = readFileSync9(settingsPath, "utf8");
|
|
5095
5095
|
} catch {
|
|
5096
5096
|
}
|
|
5097
5097
|
const wiring = inspectHookWiring(raw, {}, GUARD_SUBCOMMAND_HOOKS);
|
|
@@ -5283,9 +5283,9 @@ __export(inject_exports, {
|
|
|
5283
5283
|
resolveBriefingInjection: () => resolveBriefingInjection,
|
|
5284
5284
|
runGuardInject: () => runGuardInject
|
|
5285
5285
|
});
|
|
5286
|
-
import { existsSync as
|
|
5286
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
5287
5287
|
import { mkdir as mkdir5, readFile as readFile4, rename as rename4, writeFile as writeFile5 } from "node:fs/promises";
|
|
5288
|
-
import { dirname as
|
|
5288
|
+
import { dirname as dirname7, join as join21 } from "node:path";
|
|
5289
5289
|
async function resolveBriefingInjection(projectKey, apiKey, deps = {}) {
|
|
5290
5290
|
const nowMs = deps.nowMs ?? Date.now();
|
|
5291
5291
|
const cacheFile = deps.cacheFile ?? BRIEFING_CACHE_FILE;
|
|
@@ -5370,7 +5370,7 @@ function formatInjection(text, via) {
|
|
|
5370
5370
|
}
|
|
5371
5371
|
async function readCache(file) {
|
|
5372
5372
|
try {
|
|
5373
|
-
if (!
|
|
5373
|
+
if (!existsSync15(file)) return null;
|
|
5374
5374
|
const parsed = JSON.parse(await readFile4(file, "utf8"));
|
|
5375
5375
|
if (typeof parsed.fetched_at !== "string" || typeof parsed.text !== "string") return null;
|
|
5376
5376
|
if (Number.isNaN(Date.parse(parsed.fetched_at))) return null;
|
|
@@ -5385,7 +5385,7 @@ async function readCache(file) {
|
|
|
5385
5385
|
}
|
|
5386
5386
|
async function writeCache(file, cache) {
|
|
5387
5387
|
try {
|
|
5388
|
-
await mkdir5(
|
|
5388
|
+
await mkdir5(dirname7(file), { recursive: true, mode: 448 });
|
|
5389
5389
|
const tmp = `${file}.tmp`;
|
|
5390
5390
|
await writeFile5(tmp, JSON.stringify(cache, null, 2), { mode: 384 });
|
|
5391
5391
|
await rename4(tmp, file);
|
|
@@ -5411,7 +5411,7 @@ var init_inject = __esm({
|
|
|
5411
5411
|
init_log();
|
|
5412
5412
|
init_session_file();
|
|
5413
5413
|
init_mcp_client();
|
|
5414
|
-
BRIEFING_CACHE_FILE =
|
|
5414
|
+
BRIEFING_CACHE_FILE = join21(GUARD_DIR, "briefing-cache.json");
|
|
5415
5415
|
CACHE_TTL_MS = 12 * 60 * 60 * 1e3;
|
|
5416
5416
|
FETCH_BUDGET_MS = 3e3;
|
|
5417
5417
|
MAX_INJECT_BYTES = 10 * 1024;
|
|
@@ -5641,7 +5641,7 @@ var init_frames = __esm({
|
|
|
5641
5641
|
// src/gateway/attest.ts
|
|
5642
5642
|
import { appendFile as appendFile2, mkdir as mkdir6, readFile as readFile5, rename as rename5, writeFile as writeFile6 } from "node:fs/promises";
|
|
5643
5643
|
import { homedir as homedir8 } from "node:os";
|
|
5644
|
-
import { join as
|
|
5644
|
+
import { join as join22 } from "node:path";
|
|
5645
5645
|
function aggregateWindow(events, mode, serverLabel, projectKey) {
|
|
5646
5646
|
if (mode === "off" || events.length === 0) return null;
|
|
5647
5647
|
const counts = {};
|
|
@@ -5675,7 +5675,7 @@ function aggregateWindow(events, mode, serverLabel, projectKey) {
|
|
|
5675
5675
|
};
|
|
5676
5676
|
}
|
|
5677
5677
|
function attestSpoolPath() {
|
|
5678
|
-
return
|
|
5678
|
+
return join22(homedir8(), ".maind", "gateway", "attest-spool.jsonl");
|
|
5679
5679
|
}
|
|
5680
5680
|
async function postAttestation(payload) {
|
|
5681
5681
|
const apiKey = readApiKey();
|
|
@@ -5698,7 +5698,7 @@ async function postAttestation(payload) {
|
|
|
5698
5698
|
}
|
|
5699
5699
|
async function spoolAttestation(payload) {
|
|
5700
5700
|
try {
|
|
5701
|
-
await mkdir6(
|
|
5701
|
+
await mkdir6(join22(homedir8(), ".maind", "gateway"), { recursive: true });
|
|
5702
5702
|
await appendFile2(attestSpoolPath(), JSON.stringify(payload) + "\n", { mode: 384 });
|
|
5703
5703
|
await capSpool();
|
|
5704
5704
|
} catch {
|
|
@@ -5865,9 +5865,9 @@ var init_policy = __esm({
|
|
|
5865
5865
|
// src/gateway/policy-cache.ts
|
|
5866
5866
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync10, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
5867
5867
|
import { homedir as homedir9 } from "node:os";
|
|
5868
|
-
import { dirname as
|
|
5868
|
+
import { dirname as dirname8, join as join23 } from "node:path";
|
|
5869
5869
|
function policyCachePath() {
|
|
5870
|
-
return
|
|
5870
|
+
return join23(homedir9(), ".maind", "gateway", "policy-cache.json");
|
|
5871
5871
|
}
|
|
5872
5872
|
function writePolicyCache(identity, rules, nowIso = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
5873
5873
|
try {
|
|
@@ -5879,7 +5879,7 @@ function writePolicyCache(identity, rules, nowIso = (/* @__PURE__ */ new Date())
|
|
|
5879
5879
|
rules
|
|
5880
5880
|
};
|
|
5881
5881
|
const target = policyCachePath();
|
|
5882
|
-
mkdirSync5(
|
|
5882
|
+
mkdirSync5(dirname8(target), { recursive: true });
|
|
5883
5883
|
const tmp = `${target}.${process.pid}.tmp`;
|
|
5884
5884
|
writeFileSync4(tmp, JSON.stringify(payload, null, 2), { encoding: "utf8", mode: 384 });
|
|
5885
5885
|
renameSync3(tmp, target);
|
|
@@ -6008,12 +6008,12 @@ function wrapServerEntry(entry, launch, label) {
|
|
|
6008
6008
|
function unwrapServerEntry(entry) {
|
|
6009
6009
|
if (!isGatewayWrapped(entry)) return null;
|
|
6010
6010
|
const args = entry.args.map(String);
|
|
6011
|
-
const
|
|
6012
|
-
if (
|
|
6011
|
+
const sep3 = args.indexOf("--", args.indexOf("gateway") + 1);
|
|
6012
|
+
if (sep3 === -1 || sep3 + 1 >= args.length) return null;
|
|
6013
6013
|
const out2 = {
|
|
6014
6014
|
...entry,
|
|
6015
|
-
command: args[
|
|
6016
|
-
args: args.slice(
|
|
6015
|
+
command: args[sep3 + 1],
|
|
6016
|
+
args: args.slice(sep3 + 2)
|
|
6017
6017
|
};
|
|
6018
6018
|
return out2;
|
|
6019
6019
|
}
|
|
@@ -6035,9 +6035,9 @@ __export(install_exports, {
|
|
|
6035
6035
|
runGatewayInstall: () => runGatewayInstall,
|
|
6036
6036
|
runGatewayUninstall: () => runGatewayUninstall
|
|
6037
6037
|
});
|
|
6038
|
-
import { existsSync as
|
|
6038
|
+
import { existsSync as existsSync16, readFileSync as readFileSync11 } from "node:fs";
|
|
6039
6039
|
import { homedir as homedir10 } from "node:os";
|
|
6040
|
-
import { join as
|
|
6040
|
+
import { join as join24 } from "node:path";
|
|
6041
6041
|
import { createInterface as createInterface8 } from "node:readline";
|
|
6042
6042
|
function parseFlags(argv) {
|
|
6043
6043
|
const f = { yes: false, dryRun: false };
|
|
@@ -6050,15 +6050,15 @@ function parseFlags(argv) {
|
|
|
6050
6050
|
}
|
|
6051
6051
|
function targets() {
|
|
6052
6052
|
return [
|
|
6053
|
-
{ label: "Claude Code (project .mcp.json)", path:
|
|
6054
|
-
{ label: "Claude Code (user ~/.claude.json)", path:
|
|
6053
|
+
{ label: "Claude Code (project .mcp.json)", path: join24(process.cwd(), ".mcp.json") },
|
|
6054
|
+
{ label: "Claude Code (user ~/.claude.json)", path: join24(homedir10(), ".claude.json") }
|
|
6055
6055
|
];
|
|
6056
6056
|
}
|
|
6057
6057
|
async function confirm(question) {
|
|
6058
6058
|
const rl = createInterface8({ input: process.stdin, output: process.stderr });
|
|
6059
6059
|
try {
|
|
6060
6060
|
const answer = await new Promise(
|
|
6061
|
-
(
|
|
6061
|
+
(resolve4) => rl.question(`${question} [y/N] `, resolve4)
|
|
6062
6062
|
);
|
|
6063
6063
|
return answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes";
|
|
6064
6064
|
} finally {
|
|
@@ -6081,7 +6081,7 @@ function loadConfig(path8) {
|
|
|
6081
6081
|
}
|
|
6082
6082
|
function readFileSafeSync(path8) {
|
|
6083
6083
|
try {
|
|
6084
|
-
if (!
|
|
6084
|
+
if (!existsSync16(path8)) return null;
|
|
6085
6085
|
return readFileSync11(path8, "utf8");
|
|
6086
6086
|
} catch {
|
|
6087
6087
|
return null;
|
|
@@ -6312,15 +6312,15 @@ __export(run_exports, {
|
|
|
6312
6312
|
import { spawn as spawn2 } from "node:child_process";
|
|
6313
6313
|
import { appendFile as appendFile3, mkdir as mkdir7 } from "node:fs/promises";
|
|
6314
6314
|
import { homedir as homedir11 } from "node:os";
|
|
6315
|
-
import { basename as
|
|
6315
|
+
import { basename as basename3, join as join25 } from "node:path";
|
|
6316
6316
|
import { createInterface as createInterface9 } from "node:readline";
|
|
6317
6317
|
function gatewayEventsFile() {
|
|
6318
|
-
return
|
|
6318
|
+
return join25(homedir11(), ".maind", "gateway", "events.jsonl");
|
|
6319
6319
|
}
|
|
6320
6320
|
async function logEvent(e) {
|
|
6321
6321
|
try {
|
|
6322
6322
|
const file = gatewayEventsFile();
|
|
6323
|
-
await mkdir7(
|
|
6323
|
+
await mkdir7(join25(homedir11(), ".maind", "gateway"), { recursive: true });
|
|
6324
6324
|
await appendFile3(file, JSON.stringify(e) + "\n", { mode: 384 });
|
|
6325
6325
|
} catch {
|
|
6326
6326
|
}
|
|
@@ -6373,7 +6373,7 @@ async function runGateway(argv) {
|
|
|
6373
6373
|
return 2;
|
|
6374
6374
|
}
|
|
6375
6375
|
const { denyTools, label, command, args } = parsed;
|
|
6376
|
-
const serverLabel = label ??
|
|
6376
|
+
const serverLabel = label ?? basename3(command);
|
|
6377
6377
|
const mode = resolveGatewayMode();
|
|
6378
6378
|
let policyRules = mode === "off" ? [] : readPolicyCache(policyIdentity())?.rules ?? [];
|
|
6379
6379
|
if (mode !== "off") {
|
|
@@ -6470,9 +6470,9 @@ async function runGateway(argv) {
|
|
|
6470
6470
|
rl.on("close", () => {
|
|
6471
6471
|
child.stdin.end();
|
|
6472
6472
|
});
|
|
6473
|
-
const exitCode = await new Promise((
|
|
6473
|
+
const exitCode = await new Promise((resolve4) => {
|
|
6474
6474
|
child.on("exit", (code, signal) => {
|
|
6475
|
-
|
|
6475
|
+
resolve4(code ?? (signal ? 1 : 0));
|
|
6476
6476
|
});
|
|
6477
6477
|
});
|
|
6478
6478
|
clearInterval(attestTimer);
|
|
@@ -6508,9 +6508,9 @@ __export(cross_session_exports, {
|
|
|
6508
6508
|
});
|
|
6509
6509
|
import { mkdir as mkdir8, readFile as readFile6, readdir as readdir2, stat as stat3, unlink as unlink3, writeFile as writeFile7 } from "node:fs/promises";
|
|
6510
6510
|
import { homedir as homedir12 } from "node:os";
|
|
6511
|
-
import { join as
|
|
6511
|
+
import { join as join26 } from "node:path";
|
|
6512
6512
|
function crossSessionDir() {
|
|
6513
|
-
return
|
|
6513
|
+
return join26(homedir12(), ".maind", "cross-session");
|
|
6514
6514
|
}
|
|
6515
6515
|
function parseSessionDb(raw) {
|
|
6516
6516
|
const empty = { files: {}, warned: {} };
|
|
@@ -6552,7 +6552,7 @@ function staleReason(path8, v) {
|
|
|
6552
6552
|
async function dbPath(sessionId) {
|
|
6553
6553
|
const dir = crossSessionDir();
|
|
6554
6554
|
await mkdir8(dir, { recursive: true });
|
|
6555
|
-
return
|
|
6555
|
+
return join26(dir, `${sessionId}.json`);
|
|
6556
6556
|
}
|
|
6557
6557
|
async function loadDb(sessionId, now) {
|
|
6558
6558
|
try {
|
|
@@ -6573,7 +6573,7 @@ async function sweepStaleSessionFiles(now) {
|
|
|
6573
6573
|
const dir = crossSessionDir();
|
|
6574
6574
|
for (const name of await readdir2(dir)) {
|
|
6575
6575
|
if (!name.endsWith(".json")) continue;
|
|
6576
|
-
const p =
|
|
6576
|
+
const p = join26(dir, name);
|
|
6577
6577
|
const s = await stat3(p).catch(() => null);
|
|
6578
6578
|
if (s && now - s.mtimeMs > TTL_MS) await unlink3(p).catch(() => {
|
|
6579
6579
|
});
|
|
@@ -7328,7 +7328,7 @@ async function pollOnce(url, deviceCode) {
|
|
|
7328
7328
|
return await res.json();
|
|
7329
7329
|
}
|
|
7330
7330
|
function sleep(ms) {
|
|
7331
|
-
return new Promise((
|
|
7331
|
+
return new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
7332
7332
|
}
|
|
7333
7333
|
function printAuthInstructions(start, out2) {
|
|
7334
7334
|
const lines2 = [
|
|
@@ -7370,7 +7370,7 @@ async function openExternalBrowser(url) {
|
|
|
7370
7370
|
args = [url];
|
|
7371
7371
|
break;
|
|
7372
7372
|
}
|
|
7373
|
-
return new Promise((
|
|
7373
|
+
return new Promise((resolve4, reject) => {
|
|
7374
7374
|
try {
|
|
7375
7375
|
const child = spawn(cmd, args, {
|
|
7376
7376
|
stdio: "ignore",
|
|
@@ -7378,7 +7378,7 @@ async function openExternalBrowser(url) {
|
|
|
7378
7378
|
});
|
|
7379
7379
|
child.on("error", reject);
|
|
7380
7380
|
child.unref();
|
|
7381
|
-
|
|
7381
|
+
resolve4();
|
|
7382
7382
|
} catch (err) {
|
|
7383
7383
|
reject(err);
|
|
7384
7384
|
}
|
|
@@ -7606,12 +7606,12 @@ var InstallReport = class {
|
|
|
7606
7606
|
...this.results.map((r) => (r.detail ?? "").length)
|
|
7607
7607
|
);
|
|
7608
7608
|
const pad2 = (s, w) => s + " ".repeat(Math.max(0, w - s.length));
|
|
7609
|
-
const
|
|
7609
|
+
const sep3 = `| ${"-".repeat(targetWidth)} | ${"-".repeat(actionWidth)} | ${"-".repeat(statusWidth)} | ${"-".repeat(detailWidth)} |`;
|
|
7610
7610
|
const lines2 = [];
|
|
7611
7611
|
lines2.push(
|
|
7612
7612
|
`| ${pad2(headers[0], targetWidth)} | ${pad2(headers[1], actionWidth)} | ${pad2(headers[2], statusWidth)} | ${pad2(headers[3], detailWidth)} |`
|
|
7613
7613
|
);
|
|
7614
|
-
lines2.push(
|
|
7614
|
+
lines2.push(sep3);
|
|
7615
7615
|
for (const r of this.results) {
|
|
7616
7616
|
lines2.push(
|
|
7617
7617
|
`| ${pad2(r.target, targetWidth)} | ${pad2(r.action, actionWidth)} | ${pad2(r.status, statusWidth)} | ${pad2(r.detail ?? "", detailWidth)} |`
|
|
@@ -7707,8 +7707,8 @@ Which one should receive the MCP config and preamble files? [1-${candidates.leng
|
|
|
7707
7707
|
output: process.stdout,
|
|
7708
7708
|
terminal: true
|
|
7709
7709
|
});
|
|
7710
|
-
const answer = await new Promise((
|
|
7711
|
-
rl.question("", (input) =>
|
|
7710
|
+
const answer = await new Promise((resolve4) => {
|
|
7711
|
+
rl.question("", (input) => resolve4(input.trim()));
|
|
7712
7712
|
});
|
|
7713
7713
|
rl.close();
|
|
7714
7714
|
if (answer === "") return candidates[0];
|
|
@@ -8978,8 +8978,8 @@ async function promptYesNoDefaultNo(out2, prompt) {
|
|
|
8978
8978
|
output: out2,
|
|
8979
8979
|
terminal: true
|
|
8980
8980
|
});
|
|
8981
|
-
const answer = await new Promise((
|
|
8982
|
-
rl.question("", (input) =>
|
|
8981
|
+
const answer = await new Promise((resolve4) => {
|
|
8982
|
+
rl.question("", (input) => resolve4(input.trim().toLowerCase()));
|
|
8983
8983
|
});
|
|
8984
8984
|
rl.close();
|
|
8985
8985
|
return answer === "y" || answer === "yes";
|
|
@@ -9246,7 +9246,9 @@ function parseNodeMajor(version) {
|
|
|
9246
9246
|
|
|
9247
9247
|
// src/local-tools/engine.ts
|
|
9248
9248
|
import { execFileSync as execFileSync6 } from "node:child_process";
|
|
9249
|
+
import { existsSync as existsSync6, realpathSync } from "node:fs";
|
|
9249
9250
|
import { createRequire as createRequire3 } from "node:module";
|
|
9251
|
+
import { basename, dirname as dirname5, isAbsolute as isAbsolute3, join as join12, relative as relative2, resolve as resolve3, sep as sep2 } from "node:path";
|
|
9250
9252
|
|
|
9251
9253
|
// ../../packages/code-index/build/node.js
|
|
9252
9254
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
@@ -10071,6 +10073,30 @@ function resolveRepoRoot2(cwd = process.cwd()) {
|
|
|
10071
10073
|
return cwd;
|
|
10072
10074
|
}
|
|
10073
10075
|
}
|
|
10076
|
+
function resolveRepoRootForPath(proposedPath, fallbackRoot = resolveRepoRoot2(), cwd = process.cwd()) {
|
|
10077
|
+
const candidates = isAbsolute3(proposedPath) ? [proposedPath] : [resolve3(fallbackRoot, proposedPath), resolve3(cwd, proposedPath)];
|
|
10078
|
+
for (const candidate of candidates) {
|
|
10079
|
+
const dir = dirname5(candidate);
|
|
10080
|
+
if (!existsSync6(dir)) continue;
|
|
10081
|
+
try {
|
|
10082
|
+
const realDir = realpathSync(dir);
|
|
10083
|
+
const realCandidate = join12(realDir, basename(candidate));
|
|
10084
|
+
const top = execFileSync6("git", ["rev-parse", "--show-toplevel"], {
|
|
10085
|
+
cwd: realDir,
|
|
10086
|
+
encoding: "utf8",
|
|
10087
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
10088
|
+
timeout: 5e3
|
|
10089
|
+
}).trim();
|
|
10090
|
+
if (top.length === 0) continue;
|
|
10091
|
+
const rel = relative2(top, realCandidate);
|
|
10092
|
+
if (rel.startsWith("..")) continue;
|
|
10093
|
+
return { repoRoot: top, repoRelPath: rel.split(sep2).join("/") };
|
|
10094
|
+
} catch {
|
|
10095
|
+
continue;
|
|
10096
|
+
}
|
|
10097
|
+
}
|
|
10098
|
+
return null;
|
|
10099
|
+
}
|
|
10074
10100
|
function defaultEngineFactory() {
|
|
10075
10101
|
return createNodeCodeIndex({ repoRoot: resolveRepoRoot2() });
|
|
10076
10102
|
}
|
|
@@ -10277,7 +10303,7 @@ Finished in ${wallClockSec}s. Restart your MCP client so it picks up the new ser
|
|
|
10277
10303
|
|
|
10278
10304
|
// src/local-tools/savings.ts
|
|
10279
10305
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
10280
|
-
import { join as
|
|
10306
|
+
import { join as join13 } from "node:path";
|
|
10281
10307
|
|
|
10282
10308
|
// src/local-tools/token-estimate.ts
|
|
10283
10309
|
var CHARS_PER_TOKEN = 4;
|
|
@@ -10332,14 +10358,14 @@ function measureLocalToolSaved(name, result, serialized, repoRoot) {
|
|
|
10332
10358
|
if (files.length === 0) return 0;
|
|
10333
10359
|
let wholeTokens = 0;
|
|
10334
10360
|
for (const fp of files) {
|
|
10335
|
-
wholeTokens += estimateTokens(readFileCapped(
|
|
10361
|
+
wholeTokens += estimateTokens(readFileCapped(join13(repoRoot, fp)));
|
|
10336
10362
|
}
|
|
10337
10363
|
return Math.max(0, wholeTokens - resultTokens);
|
|
10338
10364
|
}
|
|
10339
10365
|
if (name === "codebase_snippet") {
|
|
10340
10366
|
const fp = result?.filePath;
|
|
10341
10367
|
if (typeof fp !== "string" || fp.length === 0) return 0;
|
|
10342
|
-
const wholeTokens = estimateTokens(readFileCapped(
|
|
10368
|
+
const wholeTokens = estimateTokens(readFileCapped(join13(repoRoot, fp)));
|
|
10343
10369
|
return Math.max(0, wholeTokens - resultTokens);
|
|
10344
10370
|
}
|
|
10345
10371
|
return 0;
|
|
@@ -10529,7 +10555,7 @@ var LOCAL_TOOLS = [
|
|
|
10529
10555
|
},
|
|
10530
10556
|
for_path: {
|
|
10531
10557
|
type: "string",
|
|
10532
|
-
description:
|
|
10558
|
+
description: 'A path you are ABOUT to create, e.g. "docs/adr/ADR-263-retry-policy.md". Switches the tool from auditing what exists to answering the allocator question for a file that does not exist yet: is that number already held, and which is the next free one. Scoped to that file\'s own directory, so it is the cheap call. The repository is resolved FROM THIS PATH (absolute, or relative to the workspace / cwd), so nested checkouts work \u2014 give the prefix that locates the file, e.g. "Asgard/docs/adr/\u2026". Read `verdict` ("free" | "taken" | "no_opinion"), never `taken` alone: when the path cannot be located or its directory is no counter namespace, the answer is `no_opinion` \u2014 that is an abstention, NOT a free number.'
|
|
10533
10559
|
}
|
|
10534
10560
|
}
|
|
10535
10561
|
}
|
|
@@ -10597,23 +10623,45 @@ async function dispatchLocalTool(engine, name, args) {
|
|
|
10597
10623
|
const minFiles = typeof args.min_files === "number" ? args.min_files : void 0;
|
|
10598
10624
|
const forPath = str(args.for_path);
|
|
10599
10625
|
if (forPath !== void 0) {
|
|
10600
|
-
const
|
|
10626
|
+
const anchored = resolveRepoRootForPath(forPath);
|
|
10627
|
+
if (anchored === null) {
|
|
10628
|
+
return {
|
|
10629
|
+
ok: false,
|
|
10630
|
+
mode: "proposed_path",
|
|
10631
|
+
verdict: "no_opinion",
|
|
10632
|
+
reason: "path_not_found",
|
|
10633
|
+
path: forPath,
|
|
10634
|
+
namespace: null,
|
|
10635
|
+
number: null,
|
|
10636
|
+
taken: null,
|
|
10637
|
+
suggestion: null,
|
|
10638
|
+
held_by: [],
|
|
10639
|
+
hint: "No opinion \u2014 this path could not be located on disk, so no repository was scanned. Do NOT read this as free. Pass a path that exists relative to the repo you mean (nested checkouts need their own prefix, e.g. `Asgard/docs/adr/\u2026`) or an absolute path."
|
|
10640
|
+
};
|
|
10641
|
+
}
|
|
10642
|
+
const v = await checkNumberForPath(anchored.repoRoot, anchored.repoRelPath, {
|
|
10643
|
+
minFiles
|
|
10644
|
+
});
|
|
10601
10645
|
const ns = v.namespace;
|
|
10602
10646
|
const full = (n) => n === null ? null : `${ns?.prefix ?? ""}${n}`;
|
|
10647
|
+
const verdict = ns === null ? "no_opinion" : v.taken ? "taken" : "free";
|
|
10603
10648
|
return {
|
|
10604
|
-
ok:
|
|
10649
|
+
ok: verdict === "free",
|
|
10605
10650
|
mode: "proposed_path",
|
|
10651
|
+
verdict,
|
|
10652
|
+
reason: verdict === "no_opinion" ? "no_namespace" : void 0,
|
|
10606
10653
|
path: v.path,
|
|
10654
|
+
repo_root: anchored.repoRoot,
|
|
10607
10655
|
namespace: ns === null ? null : { dir: ns.dir, prefix: ns.prefix, file_count: ns.fileCount },
|
|
10608
10656
|
number: full(v.number),
|
|
10609
|
-
taken: v.taken,
|
|
10657
|
+
taken: verdict === "no_opinion" ? null : v.taken,
|
|
10610
10658
|
suggestion: full(v.suggestion),
|
|
10611
10659
|
held_by: v.sightings.map((s) => ({
|
|
10612
10660
|
kind: s.kind,
|
|
10613
10661
|
where: s.where,
|
|
10614
10662
|
path: s.path
|
|
10615
10663
|
})),
|
|
10616
|
-
hint:
|
|
10664
|
+
hint: verdict === "no_opinion" ? "No opinion: that filename carries no number, or its directory is not a detected counter namespace. Do NOT read this as free \u2014 nothing was compared. Pass min_files to cover a series below the detection threshold." : v.taken ? `${full(v.number)} is already held (see held_by). Create the file as ${full(v.suggestion)} instead \u2014 right now it costs one filename; after the index entry, the links and the commit message name it, it costs all of them.` : `${full(v.number)} is free across the default branch, sibling branches and sibling worktrees. Advisory, not a reservation: nothing stops a parallel session from taking it a second from now, so write the file rather than noting the number for later.`
|
|
10617
10665
|
};
|
|
10618
10666
|
}
|
|
10619
10667
|
const report = await engine.checkNumberCollisions({
|
|
@@ -11002,12 +11050,12 @@ async function deriveWorkingPaths(runGitStatus = defaultGitStatus) {
|
|
|
11002
11050
|
return dirs.length > 0 ? dirs : null;
|
|
11003
11051
|
}
|
|
11004
11052
|
async function defaultGitStatus() {
|
|
11005
|
-
return await new Promise((
|
|
11053
|
+
return await new Promise((resolve4) => {
|
|
11006
11054
|
execFile2(
|
|
11007
11055
|
"git",
|
|
11008
11056
|
["status", "--porcelain"],
|
|
11009
11057
|
{ timeout: 2e3, encoding: "utf8", maxBuffer: 1024 * 1024 },
|
|
11010
|
-
(err, stdout) =>
|
|
11058
|
+
(err, stdout) => resolve4(err ? null : stdout)
|
|
11011
11059
|
);
|
|
11012
11060
|
});
|
|
11013
11061
|
}
|