@maind-dev/mcp-bridge 0.33.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 +193 -138
- 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));
|
|
@@ -3644,8 +3644,10 @@ var init_session_analysis = __esm({
|
|
|
3644
3644
|
});
|
|
3645
3645
|
|
|
3646
3646
|
// ../../packages/claude-code-telemetry/dist/ingest.js
|
|
3647
|
-
function ingestBody(analytics, span, ctx) {
|
|
3648
|
-
const body = {
|
|
3647
|
+
function ingestBody(analytics, span, ctx, source = "unknown") {
|
|
3648
|
+
const body = {
|
|
3649
|
+
session_analytics: { ...analytics, ingest_source: source }
|
|
3650
|
+
};
|
|
3649
3651
|
if (span && span.started_at) {
|
|
3650
3652
|
body.session_span = ctx ? { ...span, ...ctx } : span;
|
|
3651
3653
|
}
|
|
@@ -3658,7 +3660,7 @@ var init_ingest = __esm({
|
|
|
3658
3660
|
});
|
|
3659
3661
|
|
|
3660
3662
|
// ../../packages/claude-code-telemetry/dist/session-span.js
|
|
3661
|
-
import { createReadStream as createReadStream3, existsSync as
|
|
3663
|
+
import { createReadStream as createReadStream3, existsSync as existsSync9 } from "node:fs";
|
|
3662
3664
|
import { createInterface as createInterface7 } from "node:readline";
|
|
3663
3665
|
function asBlocks2(content) {
|
|
3664
3666
|
if (typeof content === "string")
|
|
@@ -3710,7 +3712,7 @@ function classify2(parsed) {
|
|
|
3710
3712
|
}
|
|
3711
3713
|
async function analyzeSpan(path8) {
|
|
3712
3714
|
const s = emptySpan("");
|
|
3713
|
-
if (!path8 || !
|
|
3715
|
+
if (!path8 || !existsSync9(path8))
|
|
3714
3716
|
return s;
|
|
3715
3717
|
let firstMs = null;
|
|
3716
3718
|
let lastMs = 0;
|
|
@@ -3718,7 +3720,7 @@ async function analyzeSpan(path8) {
|
|
|
3718
3720
|
let prevMs = null;
|
|
3719
3721
|
let prevHolder = "human";
|
|
3720
3722
|
const pauses = [];
|
|
3721
|
-
await new Promise((
|
|
3723
|
+
await new Promise((resolve4) => {
|
|
3722
3724
|
const stream = createReadStream3(path8, { encoding: "utf-8" });
|
|
3723
3725
|
const rl = createInterface7({ input: stream });
|
|
3724
3726
|
const processLine = (line) => {
|
|
@@ -3776,9 +3778,9 @@ async function analyzeSpan(path8) {
|
|
|
3776
3778
|
} catch {
|
|
3777
3779
|
}
|
|
3778
3780
|
});
|
|
3779
|
-
rl.on("close", () =>
|
|
3780
|
-
rl.on("error", () =>
|
|
3781
|
-
stream.on("error", () =>
|
|
3781
|
+
rl.on("close", () => resolve4());
|
|
3782
|
+
rl.on("error", () => resolve4());
|
|
3783
|
+
stream.on("error", () => resolve4());
|
|
3782
3784
|
});
|
|
3783
3785
|
if (firstMs === null)
|
|
3784
3786
|
return s;
|
|
@@ -3823,13 +3825,13 @@ var init_windows = __esm({
|
|
|
3823
3825
|
|
|
3824
3826
|
// ../../packages/claude-code-telemetry/dist/projects.js
|
|
3825
3827
|
import { homedir as homedir4 } from "node:os";
|
|
3826
|
-
import { join as
|
|
3828
|
+
import { join as join15 } from "node:path";
|
|
3827
3829
|
var HOME, DEFAULT_PROJECTS_DIR;
|
|
3828
3830
|
var init_projects = __esm({
|
|
3829
3831
|
"../../packages/claude-code-telemetry/dist/projects.js"() {
|
|
3830
3832
|
"use strict";
|
|
3831
3833
|
HOME = homedir4();
|
|
3832
|
-
DEFAULT_PROJECTS_DIR =
|
|
3834
|
+
DEFAULT_PROJECTS_DIR = join15(HOME, ".claude", "projects");
|
|
3833
3835
|
}
|
|
3834
3836
|
});
|
|
3835
3837
|
|
|
@@ -4013,13 +4015,13 @@ var init_edit_guard = __esm({
|
|
|
4013
4015
|
async function readHookInput() {
|
|
4014
4016
|
if (process.stdin.isTTY) return {};
|
|
4015
4017
|
const chunks = [];
|
|
4016
|
-
return await new Promise((
|
|
4018
|
+
return await new Promise((resolve4) => {
|
|
4017
4019
|
let settled = false;
|
|
4018
4020
|
const settle = (value) => {
|
|
4019
4021
|
if (settled) return;
|
|
4020
4022
|
settled = true;
|
|
4021
4023
|
clearTimeout(timer);
|
|
4022
|
-
|
|
4024
|
+
resolve4(value);
|
|
4023
4025
|
};
|
|
4024
4026
|
const timer = setTimeout(() => settle({}), STDIN_TIMEOUT_MS);
|
|
4025
4027
|
process.stdin.on("data", (c) => chunks.push(c));
|
|
@@ -4077,14 +4079,14 @@ var init_payloads = __esm({
|
|
|
4077
4079
|
|
|
4078
4080
|
// src/hooks/state.ts
|
|
4079
4081
|
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2, rename as rename2 } from "node:fs/promises";
|
|
4080
|
-
import { existsSync as
|
|
4082
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
4081
4083
|
import { homedir as homedir5 } from "node:os";
|
|
4082
|
-
import { join as
|
|
4084
|
+
import { join as join16 } from "node:path";
|
|
4083
4085
|
function emptyState() {
|
|
4084
4086
|
return { config: null, sessions: {}, pending_metrics: [] };
|
|
4085
4087
|
}
|
|
4086
4088
|
async function loadState() {
|
|
4087
|
-
if (!
|
|
4089
|
+
if (!existsSync10(STATE_FILE)) return emptyState();
|
|
4088
4090
|
try {
|
|
4089
4091
|
const raw = await readFile2(STATE_FILE, "utf-8");
|
|
4090
4092
|
const parsed = JSON.parse(raw);
|
|
@@ -4105,7 +4107,7 @@ async function loadState() {
|
|
|
4105
4107
|
}
|
|
4106
4108
|
}
|
|
4107
4109
|
async function saveState(state) {
|
|
4108
|
-
if (!
|
|
4110
|
+
if (!existsSync10(STATE_DIR)) {
|
|
4109
4111
|
await mkdir2(STATE_DIR, { recursive: true, mode: 448 });
|
|
4110
4112
|
}
|
|
4111
4113
|
const tmp = `${STATE_FILE}.tmp`;
|
|
@@ -4119,8 +4121,8 @@ var STATE_DIR, STATE_FILE, DEFAULT_THRESHOLDS;
|
|
|
4119
4121
|
var init_state = __esm({
|
|
4120
4122
|
"src/hooks/state.ts"() {
|
|
4121
4123
|
"use strict";
|
|
4122
|
-
STATE_DIR =
|
|
4123
|
-
STATE_FILE =
|
|
4124
|
+
STATE_DIR = join16(homedir5(), ".maind");
|
|
4125
|
+
STATE_FILE = join16(STATE_DIR, "state.json");
|
|
4124
4126
|
DEFAULT_THRESHOLDS = {
|
|
4125
4127
|
warn_at_pct: 60,
|
|
4126
4128
|
handoff_at_pct: 85,
|
|
@@ -4146,10 +4148,10 @@ __export(hooks_exports, {
|
|
|
4146
4148
|
runSyncConfig: () => runSyncConfig
|
|
4147
4149
|
});
|
|
4148
4150
|
import { execFileSync as execFileSync7 } from "node:child_process";
|
|
4149
|
-
import { existsSync as
|
|
4151
|
+
import { existsSync as existsSync11, readFileSync as readFileSync8, realpathSync as realpathSync2 } from "node:fs";
|
|
4150
4152
|
import { writeFile as writeFile3 } from "node:fs/promises";
|
|
4151
4153
|
import { homedir as homedir6 } from "node:os";
|
|
4152
|
-
import { basename, dirname as
|
|
4154
|
+
import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute4, join as join17, relative as relative3 } from "node:path";
|
|
4153
4155
|
function recordGuardSignals(state, sessionId, toolName, nowMs = Date.now()) {
|
|
4154
4156
|
if (!toolName.includes("maind")) return;
|
|
4155
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");
|
|
@@ -4265,8 +4267,8 @@ async function runOnSessionStart() {
|
|
|
4265
4267
|
}
|
|
4266
4268
|
function readSettingsRaw() {
|
|
4267
4269
|
try {
|
|
4268
|
-
const p =
|
|
4269
|
-
return
|
|
4270
|
+
const p = join17(homedir6(), ".claude", "settings.json");
|
|
4271
|
+
return existsSync11(p) ? readFileSync8(p, "utf8") : null;
|
|
4270
4272
|
} catch {
|
|
4271
4273
|
return null;
|
|
4272
4274
|
}
|
|
@@ -4311,16 +4313,16 @@ async function runOnToolUse() {
|
|
|
4311
4313
|
return 0;
|
|
4312
4314
|
}
|
|
4313
4315
|
function realpathOfUnwritten(p) {
|
|
4314
|
-
let head =
|
|
4315
|
-
const tail = [
|
|
4316
|
+
let head = dirname6(p);
|
|
4317
|
+
const tail = [basename2(p)];
|
|
4316
4318
|
for (; ; ) {
|
|
4317
4319
|
try {
|
|
4318
|
-
const real =
|
|
4319
|
-
return
|
|
4320
|
+
const real = realpathSync2(head);
|
|
4321
|
+
return join17(real, ...tail.reverse());
|
|
4320
4322
|
} catch {
|
|
4321
|
-
const parent =
|
|
4323
|
+
const parent = dirname6(head);
|
|
4322
4324
|
if (parent === head) return p;
|
|
4323
|
-
tail.push(
|
|
4325
|
+
tail.push(basename2(head));
|
|
4324
4326
|
head = parent;
|
|
4325
4327
|
}
|
|
4326
4328
|
}
|
|
@@ -4341,11 +4343,11 @@ async function runOnFileWrite() {
|
|
|
4341
4343
|
const filePath = toolFilePathOf(input);
|
|
4342
4344
|
if (!filePath) return 0;
|
|
4343
4345
|
const cwd = typeof input.cwd === "string" && input.cwd.length > 0 ? input.cwd : process.cwd();
|
|
4344
|
-
const abs =
|
|
4345
|
-
if (
|
|
4346
|
+
const abs = isAbsolute4(filePath) ? filePath : join17(cwd, filePath);
|
|
4347
|
+
if (existsSync11(abs)) return 0;
|
|
4346
4348
|
const repoRoot = resolveRepoRoot(cwd);
|
|
4347
|
-
const rel =
|
|
4348
|
-
if (rel.length === 0 || rel.startsWith("..") ||
|
|
4349
|
+
const rel = relative3(repoRoot, realpathOfUnwritten(abs));
|
|
4350
|
+
if (rel.length === 0 || rel.startsWith("..") || isAbsolute4(rel)) return 0;
|
|
4349
4351
|
const verdict = await checkNumberForPath(repoRoot, rel);
|
|
4350
4352
|
if (!verdict.taken || verdict.namespace === null) return 0;
|
|
4351
4353
|
process.stdout.write(denyPayload(denyReason(verdict, verdict.namespace)));
|
|
@@ -4362,7 +4364,7 @@ async function runOnFileEdit() {
|
|
|
4362
4364
|
const filePath = toolFilePathOf(input);
|
|
4363
4365
|
if (!filePath) return 0;
|
|
4364
4366
|
const cwd = typeof input.cwd === "string" && input.cwd.length > 0 ? input.cwd : process.cwd();
|
|
4365
|
-
const abs =
|
|
4367
|
+
const abs = isAbsolute4(filePath) ? filePath : join17(cwd, filePath);
|
|
4366
4368
|
const projectKey = computeProjectKey();
|
|
4367
4369
|
if (projectKey === null) return 0;
|
|
4368
4370
|
const snaps = readSnapshots(projectKey);
|
|
@@ -4373,9 +4375,9 @@ async function runOnFileEdit() {
|
|
|
4373
4375
|
});
|
|
4374
4376
|
if (own === null) return 0;
|
|
4375
4377
|
const repoRoot = resolveRepoRoot(cwd);
|
|
4376
|
-
const real =
|
|
4377
|
-
const rel =
|
|
4378
|
-
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;
|
|
4379
4381
|
const advice = adviseOnPath(own.snap, rel, {
|
|
4380
4382
|
via: own.via,
|
|
4381
4383
|
currentBranch: own.via === "cwd" ? currentGitBranch(cwd) : null,
|
|
@@ -4425,7 +4427,7 @@ async function maybeEmitAdvisory(state, session) {
|
|
|
4425
4427
|
};
|
|
4426
4428
|
try {
|
|
4427
4429
|
await writeFile3(
|
|
4428
|
-
|
|
4430
|
+
join17(STATE_DIR, `handoff_advisory_${session.session_id}.json`),
|
|
4429
4431
|
JSON.stringify(payload, null, 2)
|
|
4430
4432
|
);
|
|
4431
4433
|
} catch (err) {
|
|
@@ -4485,7 +4487,7 @@ async function flushPending(config, timeoutMs) {
|
|
|
4485
4487
|
const batch = state.pending_metrics.slice(0, 100);
|
|
4486
4488
|
const post = postMetrics(config.endpoint, config.api_key, batch);
|
|
4487
4489
|
const timeout = new Promise(
|
|
4488
|
-
(
|
|
4490
|
+
(resolve4) => setTimeout(() => resolve4({ ok: false, inserted: 0, error: "timeout" }), timeoutMs)
|
|
4489
4491
|
);
|
|
4490
4492
|
const result = await Promise.race([post, timeout]);
|
|
4491
4493
|
if (result.ok) {
|
|
@@ -4545,10 +4547,10 @@ async function runHookStatus() {
|
|
|
4545
4547
|
return 0;
|
|
4546
4548
|
}
|
|
4547
4549
|
function readHookWiring() {
|
|
4548
|
-
const settingsPath =
|
|
4550
|
+
const settingsPath = join17(homedir6(), ".claude", "settings.json");
|
|
4549
4551
|
let raw = null;
|
|
4550
4552
|
try {
|
|
4551
|
-
if (
|
|
4553
|
+
if (existsSync11(settingsPath)) raw = readFileSync8(settingsPath, "utf8");
|
|
4552
4554
|
} catch {
|
|
4553
4555
|
}
|
|
4554
4556
|
return { settingsPath, findings: inspectHookWiring(raw) };
|
|
@@ -4703,7 +4705,7 @@ async function postWithTimeout(apiKey, deviceId, body, timeoutMs) {
|
|
|
4703
4705
|
},
|
|
4704
4706
|
body: JSON.stringify(body)
|
|
4705
4707
|
}).then(() => void 0).catch(() => void 0);
|
|
4706
|
-
const timeout = new Promise((
|
|
4708
|
+
const timeout = new Promise((resolve4) => setTimeout(resolve4, timeoutMs));
|
|
4707
4709
|
await Promise.race([post, timeout]);
|
|
4708
4710
|
}
|
|
4709
4711
|
async function runOnSessionEnd() {
|
|
@@ -4727,10 +4729,15 @@ async function runOnSessionEnd() {
|
|
|
4727
4729
|
Date.now()
|
|
4728
4730
|
);
|
|
4729
4731
|
if (analytics.session_id) {
|
|
4730
|
-
const body = ingestBody(
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
|
|
4732
|
+
const body = ingestBody(
|
|
4733
|
+
analytics,
|
|
4734
|
+
span,
|
|
4735
|
+
{
|
|
4736
|
+
client_session_id: presenceSessionId(),
|
|
4737
|
+
client: "claude-code"
|
|
4738
|
+
},
|
|
4739
|
+
"live_bridge"
|
|
4740
|
+
);
|
|
4734
4741
|
await postWithTimeout(apiKey, ensureDeviceId(), body, 1500);
|
|
4735
4742
|
}
|
|
4736
4743
|
} catch (err) {
|
|
@@ -4884,16 +4891,16 @@ var init_install = __esm({
|
|
|
4884
4891
|
});
|
|
4885
4892
|
|
|
4886
4893
|
// src/guard/session-file.ts
|
|
4887
|
-
import { existsSync as
|
|
4894
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
4888
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";
|
|
4889
|
-
import { join as
|
|
4896
|
+
import { join as join18 } from "node:path";
|
|
4890
4897
|
function sessionFile(sessionId) {
|
|
4891
|
-
return
|
|
4898
|
+
return join18(GUARD_SESSIONS_DIR, sessionId.replace(/[^a-zA-Z0-9._-]/g, "_") + ".json");
|
|
4892
4899
|
}
|
|
4893
4900
|
async function loadGuardSession(sessionId) {
|
|
4894
4901
|
try {
|
|
4895
4902
|
const file = sessionFile(sessionId);
|
|
4896
|
-
if (!
|
|
4903
|
+
if (!existsSync12(file)) return {};
|
|
4897
4904
|
const parsed = JSON.parse(await readFile3(file, "utf8"));
|
|
4898
4905
|
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
4899
4906
|
return parsed;
|
|
@@ -4914,10 +4921,10 @@ async function saveGuardSession(sessionId, state) {
|
|
|
4914
4921
|
}
|
|
4915
4922
|
async function sweepOldGuardSessions(maxAgeMs = 7 * 24 * 60 * 60 * 1e3, nowMs = Date.now()) {
|
|
4916
4923
|
try {
|
|
4917
|
-
if (!
|
|
4924
|
+
if (!existsSync12(GUARD_SESSIONS_DIR)) return;
|
|
4918
4925
|
for (const name of await readdir(GUARD_SESSIONS_DIR)) {
|
|
4919
4926
|
if (!name.endsWith(".json")) continue;
|
|
4920
|
-
const file =
|
|
4927
|
+
const file = join18(GUARD_SESSIONS_DIR, name);
|
|
4921
4928
|
try {
|
|
4922
4929
|
const s = await stat2(file);
|
|
4923
4930
|
if (nowMs - s.mtimeMs > maxAgeMs) await unlink2(file);
|
|
@@ -4932,15 +4939,15 @@ var init_session_file = __esm({
|
|
|
4932
4939
|
"src/guard/session-file.ts"() {
|
|
4933
4940
|
"use strict";
|
|
4934
4941
|
init_state();
|
|
4935
|
-
GUARD_DIR =
|
|
4936
|
-
GUARD_SESSIONS_DIR =
|
|
4942
|
+
GUARD_DIR = join18(STATE_DIR, "guard");
|
|
4943
|
+
GUARD_SESSIONS_DIR = join18(GUARD_DIR, "sessions");
|
|
4937
4944
|
}
|
|
4938
4945
|
});
|
|
4939
4946
|
|
|
4940
4947
|
// src/guard/log.ts
|
|
4941
|
-
import { existsSync as
|
|
4948
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
4942
4949
|
import { appendFile, mkdir as mkdir4, open } from "node:fs/promises";
|
|
4943
|
-
import { join as
|
|
4950
|
+
import { join as join19 } from "node:path";
|
|
4944
4951
|
async function appendGuardEvent(event) {
|
|
4945
4952
|
try {
|
|
4946
4953
|
await mkdir4(GUARD_DIR, { recursive: true, mode: 448 });
|
|
@@ -4962,7 +4969,7 @@ async function readGuardEventCounts(tailBytes = 256 * 1024) {
|
|
|
4962
4969
|
cross_session_deny: 0
|
|
4963
4970
|
};
|
|
4964
4971
|
try {
|
|
4965
|
-
if (!
|
|
4972
|
+
if (!existsSync13(GUARD_EVENTS_FILE)) return counts;
|
|
4966
4973
|
const fh = await open(GUARD_EVENTS_FILE, "r");
|
|
4967
4974
|
try {
|
|
4968
4975
|
const size = (await fh.stat()).size;
|
|
@@ -4993,7 +5000,7 @@ var init_log = __esm({
|
|
|
4993
5000
|
"src/guard/log.ts"() {
|
|
4994
5001
|
"use strict";
|
|
4995
5002
|
init_session_file();
|
|
4996
|
-
GUARD_EVENTS_FILE =
|
|
5003
|
+
GUARD_EVENTS_FILE = join19(GUARD_DIR, "events.jsonl");
|
|
4997
5004
|
}
|
|
4998
5005
|
});
|
|
4999
5006
|
|
|
@@ -5002,9 +5009,9 @@ var cli_exports = {};
|
|
|
5002
5009
|
__export(cli_exports, {
|
|
5003
5010
|
runGuard: () => runGuard
|
|
5004
5011
|
});
|
|
5005
|
-
import { existsSync as
|
|
5012
|
+
import { existsSync as existsSync14, readFileSync as readFileSync9 } from "node:fs";
|
|
5006
5013
|
import { homedir as homedir7 } from "node:os";
|
|
5007
|
-
import { join as
|
|
5014
|
+
import { join as join20 } from "node:path";
|
|
5008
5015
|
async function runGuard(argv) {
|
|
5009
5016
|
const verb = argv[0];
|
|
5010
5017
|
const rest = argv.slice(1);
|
|
@@ -5081,10 +5088,10 @@ logged (auditable) in ${GUARD_EVENTS_FILE}
|
|
|
5081
5088
|
}
|
|
5082
5089
|
async function runGuardStatus() {
|
|
5083
5090
|
const config = resolveGuardConfig();
|
|
5084
|
-
const settingsPath =
|
|
5091
|
+
const settingsPath = join20(homedir7(), ".claude", "settings.json");
|
|
5085
5092
|
let raw = null;
|
|
5086
5093
|
try {
|
|
5087
|
-
if (
|
|
5094
|
+
if (existsSync14(settingsPath)) raw = readFileSync9(settingsPath, "utf8");
|
|
5088
5095
|
} catch {
|
|
5089
5096
|
}
|
|
5090
5097
|
const wiring = inspectHookWiring(raw, {}, GUARD_SUBCOMMAND_HOOKS);
|
|
@@ -5276,9 +5283,9 @@ __export(inject_exports, {
|
|
|
5276
5283
|
resolveBriefingInjection: () => resolveBriefingInjection,
|
|
5277
5284
|
runGuardInject: () => runGuardInject
|
|
5278
5285
|
});
|
|
5279
|
-
import { existsSync as
|
|
5286
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
5280
5287
|
import { mkdir as mkdir5, readFile as readFile4, rename as rename4, writeFile as writeFile5 } from "node:fs/promises";
|
|
5281
|
-
import { dirname as
|
|
5288
|
+
import { dirname as dirname7, join as join21 } from "node:path";
|
|
5282
5289
|
async function resolveBriefingInjection(projectKey, apiKey, deps = {}) {
|
|
5283
5290
|
const nowMs = deps.nowMs ?? Date.now();
|
|
5284
5291
|
const cacheFile = deps.cacheFile ?? BRIEFING_CACHE_FILE;
|
|
@@ -5363,7 +5370,7 @@ function formatInjection(text, via) {
|
|
|
5363
5370
|
}
|
|
5364
5371
|
async function readCache(file) {
|
|
5365
5372
|
try {
|
|
5366
|
-
if (!
|
|
5373
|
+
if (!existsSync15(file)) return null;
|
|
5367
5374
|
const parsed = JSON.parse(await readFile4(file, "utf8"));
|
|
5368
5375
|
if (typeof parsed.fetched_at !== "string" || typeof parsed.text !== "string") return null;
|
|
5369
5376
|
if (Number.isNaN(Date.parse(parsed.fetched_at))) return null;
|
|
@@ -5378,7 +5385,7 @@ async function readCache(file) {
|
|
|
5378
5385
|
}
|
|
5379
5386
|
async function writeCache(file, cache) {
|
|
5380
5387
|
try {
|
|
5381
|
-
await mkdir5(
|
|
5388
|
+
await mkdir5(dirname7(file), { recursive: true, mode: 448 });
|
|
5382
5389
|
const tmp = `${file}.tmp`;
|
|
5383
5390
|
await writeFile5(tmp, JSON.stringify(cache, null, 2), { mode: 384 });
|
|
5384
5391
|
await rename4(tmp, file);
|
|
@@ -5404,7 +5411,7 @@ var init_inject = __esm({
|
|
|
5404
5411
|
init_log();
|
|
5405
5412
|
init_session_file();
|
|
5406
5413
|
init_mcp_client();
|
|
5407
|
-
BRIEFING_CACHE_FILE =
|
|
5414
|
+
BRIEFING_CACHE_FILE = join21(GUARD_DIR, "briefing-cache.json");
|
|
5408
5415
|
CACHE_TTL_MS = 12 * 60 * 60 * 1e3;
|
|
5409
5416
|
FETCH_BUDGET_MS = 3e3;
|
|
5410
5417
|
MAX_INJECT_BYTES = 10 * 1024;
|
|
@@ -5634,7 +5641,7 @@ var init_frames = __esm({
|
|
|
5634
5641
|
// src/gateway/attest.ts
|
|
5635
5642
|
import { appendFile as appendFile2, mkdir as mkdir6, readFile as readFile5, rename as rename5, writeFile as writeFile6 } from "node:fs/promises";
|
|
5636
5643
|
import { homedir as homedir8 } from "node:os";
|
|
5637
|
-
import { join as
|
|
5644
|
+
import { join as join22 } from "node:path";
|
|
5638
5645
|
function aggregateWindow(events, mode, serverLabel, projectKey) {
|
|
5639
5646
|
if (mode === "off" || events.length === 0) return null;
|
|
5640
5647
|
const counts = {};
|
|
@@ -5668,7 +5675,7 @@ function aggregateWindow(events, mode, serverLabel, projectKey) {
|
|
|
5668
5675
|
};
|
|
5669
5676
|
}
|
|
5670
5677
|
function attestSpoolPath() {
|
|
5671
|
-
return
|
|
5678
|
+
return join22(homedir8(), ".maind", "gateway", "attest-spool.jsonl");
|
|
5672
5679
|
}
|
|
5673
5680
|
async function postAttestation(payload) {
|
|
5674
5681
|
const apiKey = readApiKey();
|
|
@@ -5691,7 +5698,7 @@ async function postAttestation(payload) {
|
|
|
5691
5698
|
}
|
|
5692
5699
|
async function spoolAttestation(payload) {
|
|
5693
5700
|
try {
|
|
5694
|
-
await mkdir6(
|
|
5701
|
+
await mkdir6(join22(homedir8(), ".maind", "gateway"), { recursive: true });
|
|
5695
5702
|
await appendFile2(attestSpoolPath(), JSON.stringify(payload) + "\n", { mode: 384 });
|
|
5696
5703
|
await capSpool();
|
|
5697
5704
|
} catch {
|
|
@@ -5858,9 +5865,9 @@ var init_policy = __esm({
|
|
|
5858
5865
|
// src/gateway/policy-cache.ts
|
|
5859
5866
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync10, renameSync as renameSync3, writeFileSync as writeFileSync4 } from "node:fs";
|
|
5860
5867
|
import { homedir as homedir9 } from "node:os";
|
|
5861
|
-
import { dirname as
|
|
5868
|
+
import { dirname as dirname8, join as join23 } from "node:path";
|
|
5862
5869
|
function policyCachePath() {
|
|
5863
|
-
return
|
|
5870
|
+
return join23(homedir9(), ".maind", "gateway", "policy-cache.json");
|
|
5864
5871
|
}
|
|
5865
5872
|
function writePolicyCache(identity, rules, nowIso = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
5866
5873
|
try {
|
|
@@ -5872,7 +5879,7 @@ function writePolicyCache(identity, rules, nowIso = (/* @__PURE__ */ new Date())
|
|
|
5872
5879
|
rules
|
|
5873
5880
|
};
|
|
5874
5881
|
const target = policyCachePath();
|
|
5875
|
-
mkdirSync5(
|
|
5882
|
+
mkdirSync5(dirname8(target), { recursive: true });
|
|
5876
5883
|
const tmp = `${target}.${process.pid}.tmp`;
|
|
5877
5884
|
writeFileSync4(tmp, JSON.stringify(payload, null, 2), { encoding: "utf8", mode: 384 });
|
|
5878
5885
|
renameSync3(tmp, target);
|
|
@@ -6001,12 +6008,12 @@ function wrapServerEntry(entry, launch, label) {
|
|
|
6001
6008
|
function unwrapServerEntry(entry) {
|
|
6002
6009
|
if (!isGatewayWrapped(entry)) return null;
|
|
6003
6010
|
const args = entry.args.map(String);
|
|
6004
|
-
const
|
|
6005
|
-
if (
|
|
6011
|
+
const sep3 = args.indexOf("--", args.indexOf("gateway") + 1);
|
|
6012
|
+
if (sep3 === -1 || sep3 + 1 >= args.length) return null;
|
|
6006
6013
|
const out2 = {
|
|
6007
6014
|
...entry,
|
|
6008
|
-
command: args[
|
|
6009
|
-
args: args.slice(
|
|
6015
|
+
command: args[sep3 + 1],
|
|
6016
|
+
args: args.slice(sep3 + 2)
|
|
6010
6017
|
};
|
|
6011
6018
|
return out2;
|
|
6012
6019
|
}
|
|
@@ -6028,9 +6035,9 @@ __export(install_exports, {
|
|
|
6028
6035
|
runGatewayInstall: () => runGatewayInstall,
|
|
6029
6036
|
runGatewayUninstall: () => runGatewayUninstall
|
|
6030
6037
|
});
|
|
6031
|
-
import { existsSync as
|
|
6038
|
+
import { existsSync as existsSync16, readFileSync as readFileSync11 } from "node:fs";
|
|
6032
6039
|
import { homedir as homedir10 } from "node:os";
|
|
6033
|
-
import { join as
|
|
6040
|
+
import { join as join24 } from "node:path";
|
|
6034
6041
|
import { createInterface as createInterface8 } from "node:readline";
|
|
6035
6042
|
function parseFlags(argv) {
|
|
6036
6043
|
const f = { yes: false, dryRun: false };
|
|
@@ -6043,15 +6050,15 @@ function parseFlags(argv) {
|
|
|
6043
6050
|
}
|
|
6044
6051
|
function targets() {
|
|
6045
6052
|
return [
|
|
6046
|
-
{ label: "Claude Code (project .mcp.json)", path:
|
|
6047
|
-
{ 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") }
|
|
6048
6055
|
];
|
|
6049
6056
|
}
|
|
6050
6057
|
async function confirm(question) {
|
|
6051
6058
|
const rl = createInterface8({ input: process.stdin, output: process.stderr });
|
|
6052
6059
|
try {
|
|
6053
6060
|
const answer = await new Promise(
|
|
6054
|
-
(
|
|
6061
|
+
(resolve4) => rl.question(`${question} [y/N] `, resolve4)
|
|
6055
6062
|
);
|
|
6056
6063
|
return answer.trim().toLowerCase() === "y" || answer.trim().toLowerCase() === "yes";
|
|
6057
6064
|
} finally {
|
|
@@ -6074,7 +6081,7 @@ function loadConfig(path8) {
|
|
|
6074
6081
|
}
|
|
6075
6082
|
function readFileSafeSync(path8) {
|
|
6076
6083
|
try {
|
|
6077
|
-
if (!
|
|
6084
|
+
if (!existsSync16(path8)) return null;
|
|
6078
6085
|
return readFileSync11(path8, "utf8");
|
|
6079
6086
|
} catch {
|
|
6080
6087
|
return null;
|
|
@@ -6305,15 +6312,15 @@ __export(run_exports, {
|
|
|
6305
6312
|
import { spawn as spawn2 } from "node:child_process";
|
|
6306
6313
|
import { appendFile as appendFile3, mkdir as mkdir7 } from "node:fs/promises";
|
|
6307
6314
|
import { homedir as homedir11 } from "node:os";
|
|
6308
|
-
import { basename as
|
|
6315
|
+
import { basename as basename3, join as join25 } from "node:path";
|
|
6309
6316
|
import { createInterface as createInterface9 } from "node:readline";
|
|
6310
6317
|
function gatewayEventsFile() {
|
|
6311
|
-
return
|
|
6318
|
+
return join25(homedir11(), ".maind", "gateway", "events.jsonl");
|
|
6312
6319
|
}
|
|
6313
6320
|
async function logEvent(e) {
|
|
6314
6321
|
try {
|
|
6315
6322
|
const file = gatewayEventsFile();
|
|
6316
|
-
await mkdir7(
|
|
6323
|
+
await mkdir7(join25(homedir11(), ".maind", "gateway"), { recursive: true });
|
|
6317
6324
|
await appendFile3(file, JSON.stringify(e) + "\n", { mode: 384 });
|
|
6318
6325
|
} catch {
|
|
6319
6326
|
}
|
|
@@ -6366,7 +6373,7 @@ async function runGateway(argv) {
|
|
|
6366
6373
|
return 2;
|
|
6367
6374
|
}
|
|
6368
6375
|
const { denyTools, label, command, args } = parsed;
|
|
6369
|
-
const serverLabel = label ??
|
|
6376
|
+
const serverLabel = label ?? basename3(command);
|
|
6370
6377
|
const mode = resolveGatewayMode();
|
|
6371
6378
|
let policyRules = mode === "off" ? [] : readPolicyCache(policyIdentity())?.rules ?? [];
|
|
6372
6379
|
if (mode !== "off") {
|
|
@@ -6463,9 +6470,9 @@ async function runGateway(argv) {
|
|
|
6463
6470
|
rl.on("close", () => {
|
|
6464
6471
|
child.stdin.end();
|
|
6465
6472
|
});
|
|
6466
|
-
const exitCode = await new Promise((
|
|
6473
|
+
const exitCode = await new Promise((resolve4) => {
|
|
6467
6474
|
child.on("exit", (code, signal) => {
|
|
6468
|
-
|
|
6475
|
+
resolve4(code ?? (signal ? 1 : 0));
|
|
6469
6476
|
});
|
|
6470
6477
|
});
|
|
6471
6478
|
clearInterval(attestTimer);
|
|
@@ -6501,9 +6508,9 @@ __export(cross_session_exports, {
|
|
|
6501
6508
|
});
|
|
6502
6509
|
import { mkdir as mkdir8, readFile as readFile6, readdir as readdir2, stat as stat3, unlink as unlink3, writeFile as writeFile7 } from "node:fs/promises";
|
|
6503
6510
|
import { homedir as homedir12 } from "node:os";
|
|
6504
|
-
import { join as
|
|
6511
|
+
import { join as join26 } from "node:path";
|
|
6505
6512
|
function crossSessionDir() {
|
|
6506
|
-
return
|
|
6513
|
+
return join26(homedir12(), ".maind", "cross-session");
|
|
6507
6514
|
}
|
|
6508
6515
|
function parseSessionDb(raw) {
|
|
6509
6516
|
const empty = { files: {}, warned: {} };
|
|
@@ -6545,7 +6552,7 @@ function staleReason(path8, v) {
|
|
|
6545
6552
|
async function dbPath(sessionId) {
|
|
6546
6553
|
const dir = crossSessionDir();
|
|
6547
6554
|
await mkdir8(dir, { recursive: true });
|
|
6548
|
-
return
|
|
6555
|
+
return join26(dir, `${sessionId}.json`);
|
|
6549
6556
|
}
|
|
6550
6557
|
async function loadDb(sessionId, now) {
|
|
6551
6558
|
try {
|
|
@@ -6566,7 +6573,7 @@ async function sweepStaleSessionFiles(now) {
|
|
|
6566
6573
|
const dir = crossSessionDir();
|
|
6567
6574
|
for (const name of await readdir2(dir)) {
|
|
6568
6575
|
if (!name.endsWith(".json")) continue;
|
|
6569
|
-
const p =
|
|
6576
|
+
const p = join26(dir, name);
|
|
6570
6577
|
const s = await stat3(p).catch(() => null);
|
|
6571
6578
|
if (s && now - s.mtimeMs > TTL_MS) await unlink3(p).catch(() => {
|
|
6572
6579
|
});
|
|
@@ -7321,7 +7328,7 @@ async function pollOnce(url, deviceCode) {
|
|
|
7321
7328
|
return await res.json();
|
|
7322
7329
|
}
|
|
7323
7330
|
function sleep(ms) {
|
|
7324
|
-
return new Promise((
|
|
7331
|
+
return new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
7325
7332
|
}
|
|
7326
7333
|
function printAuthInstructions(start, out2) {
|
|
7327
7334
|
const lines2 = [
|
|
@@ -7363,7 +7370,7 @@ async function openExternalBrowser(url) {
|
|
|
7363
7370
|
args = [url];
|
|
7364
7371
|
break;
|
|
7365
7372
|
}
|
|
7366
|
-
return new Promise((
|
|
7373
|
+
return new Promise((resolve4, reject) => {
|
|
7367
7374
|
try {
|
|
7368
7375
|
const child = spawn(cmd, args, {
|
|
7369
7376
|
stdio: "ignore",
|
|
@@ -7371,7 +7378,7 @@ async function openExternalBrowser(url) {
|
|
|
7371
7378
|
});
|
|
7372
7379
|
child.on("error", reject);
|
|
7373
7380
|
child.unref();
|
|
7374
|
-
|
|
7381
|
+
resolve4();
|
|
7375
7382
|
} catch (err) {
|
|
7376
7383
|
reject(err);
|
|
7377
7384
|
}
|
|
@@ -7599,12 +7606,12 @@ var InstallReport = class {
|
|
|
7599
7606
|
...this.results.map((r) => (r.detail ?? "").length)
|
|
7600
7607
|
);
|
|
7601
7608
|
const pad2 = (s, w) => s + " ".repeat(Math.max(0, w - s.length));
|
|
7602
|
-
const
|
|
7609
|
+
const sep3 = `| ${"-".repeat(targetWidth)} | ${"-".repeat(actionWidth)} | ${"-".repeat(statusWidth)} | ${"-".repeat(detailWidth)} |`;
|
|
7603
7610
|
const lines2 = [];
|
|
7604
7611
|
lines2.push(
|
|
7605
7612
|
`| ${pad2(headers[0], targetWidth)} | ${pad2(headers[1], actionWidth)} | ${pad2(headers[2], statusWidth)} | ${pad2(headers[3], detailWidth)} |`
|
|
7606
7613
|
);
|
|
7607
|
-
lines2.push(
|
|
7614
|
+
lines2.push(sep3);
|
|
7608
7615
|
for (const r of this.results) {
|
|
7609
7616
|
lines2.push(
|
|
7610
7617
|
`| ${pad2(r.target, targetWidth)} | ${pad2(r.action, actionWidth)} | ${pad2(r.status, statusWidth)} | ${pad2(r.detail ?? "", detailWidth)} |`
|
|
@@ -7700,8 +7707,8 @@ Which one should receive the MCP config and preamble files? [1-${candidates.leng
|
|
|
7700
7707
|
output: process.stdout,
|
|
7701
7708
|
terminal: true
|
|
7702
7709
|
});
|
|
7703
|
-
const answer = await new Promise((
|
|
7704
|
-
rl.question("", (input) =>
|
|
7710
|
+
const answer = await new Promise((resolve4) => {
|
|
7711
|
+
rl.question("", (input) => resolve4(input.trim()));
|
|
7705
7712
|
});
|
|
7706
7713
|
rl.close();
|
|
7707
7714
|
if (answer === "") return candidates[0];
|
|
@@ -8971,8 +8978,8 @@ async function promptYesNoDefaultNo(out2, prompt) {
|
|
|
8971
8978
|
output: out2,
|
|
8972
8979
|
terminal: true
|
|
8973
8980
|
});
|
|
8974
|
-
const answer = await new Promise((
|
|
8975
|
-
rl.question("", (input) =>
|
|
8981
|
+
const answer = await new Promise((resolve4) => {
|
|
8982
|
+
rl.question("", (input) => resolve4(input.trim().toLowerCase()));
|
|
8976
8983
|
});
|
|
8977
8984
|
rl.close();
|
|
8978
8985
|
return answer === "y" || answer === "yes";
|
|
@@ -9239,7 +9246,9 @@ function parseNodeMajor(version) {
|
|
|
9239
9246
|
|
|
9240
9247
|
// src/local-tools/engine.ts
|
|
9241
9248
|
import { execFileSync as execFileSync6 } from "node:child_process";
|
|
9249
|
+
import { existsSync as existsSync6, realpathSync } from "node:fs";
|
|
9242
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";
|
|
9243
9252
|
|
|
9244
9253
|
// ../../packages/code-index/build/node.js
|
|
9245
9254
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
@@ -10064,6 +10073,30 @@ function resolveRepoRoot2(cwd = process.cwd()) {
|
|
|
10064
10073
|
return cwd;
|
|
10065
10074
|
}
|
|
10066
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
|
+
}
|
|
10067
10100
|
function defaultEngineFactory() {
|
|
10068
10101
|
return createNodeCodeIndex({ repoRoot: resolveRepoRoot2() });
|
|
10069
10102
|
}
|
|
@@ -10270,7 +10303,7 @@ Finished in ${wallClockSec}s. Restart your MCP client so it picks up the new ser
|
|
|
10270
10303
|
|
|
10271
10304
|
// src/local-tools/savings.ts
|
|
10272
10305
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
10273
|
-
import { join as
|
|
10306
|
+
import { join as join13 } from "node:path";
|
|
10274
10307
|
|
|
10275
10308
|
// src/local-tools/token-estimate.ts
|
|
10276
10309
|
var CHARS_PER_TOKEN = 4;
|
|
@@ -10325,14 +10358,14 @@ function measureLocalToolSaved(name, result, serialized, repoRoot) {
|
|
|
10325
10358
|
if (files.length === 0) return 0;
|
|
10326
10359
|
let wholeTokens = 0;
|
|
10327
10360
|
for (const fp of files) {
|
|
10328
|
-
wholeTokens += estimateTokens(readFileCapped(
|
|
10361
|
+
wholeTokens += estimateTokens(readFileCapped(join13(repoRoot, fp)));
|
|
10329
10362
|
}
|
|
10330
10363
|
return Math.max(0, wholeTokens - resultTokens);
|
|
10331
10364
|
}
|
|
10332
10365
|
if (name === "codebase_snippet") {
|
|
10333
10366
|
const fp = result?.filePath;
|
|
10334
10367
|
if (typeof fp !== "string" || fp.length === 0) return 0;
|
|
10335
|
-
const wholeTokens = estimateTokens(readFileCapped(
|
|
10368
|
+
const wholeTokens = estimateTokens(readFileCapped(join13(repoRoot, fp)));
|
|
10336
10369
|
return Math.max(0, wholeTokens - resultTokens);
|
|
10337
10370
|
}
|
|
10338
10371
|
return 0;
|
|
@@ -10522,7 +10555,7 @@ var LOCAL_TOOLS = [
|
|
|
10522
10555
|
},
|
|
10523
10556
|
for_path: {
|
|
10524
10557
|
type: "string",
|
|
10525
|
-
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.'
|
|
10526
10559
|
}
|
|
10527
10560
|
}
|
|
10528
10561
|
}
|
|
@@ -10590,23 +10623,45 @@ async function dispatchLocalTool(engine, name, args) {
|
|
|
10590
10623
|
const minFiles = typeof args.min_files === "number" ? args.min_files : void 0;
|
|
10591
10624
|
const forPath = str(args.for_path);
|
|
10592
10625
|
if (forPath !== void 0) {
|
|
10593
|
-
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
|
+
});
|
|
10594
10645
|
const ns = v.namespace;
|
|
10595
10646
|
const full = (n) => n === null ? null : `${ns?.prefix ?? ""}${n}`;
|
|
10647
|
+
const verdict = ns === null ? "no_opinion" : v.taken ? "taken" : "free";
|
|
10596
10648
|
return {
|
|
10597
|
-
ok:
|
|
10649
|
+
ok: verdict === "free",
|
|
10598
10650
|
mode: "proposed_path",
|
|
10651
|
+
verdict,
|
|
10652
|
+
reason: verdict === "no_opinion" ? "no_namespace" : void 0,
|
|
10599
10653
|
path: v.path,
|
|
10654
|
+
repo_root: anchored.repoRoot,
|
|
10600
10655
|
namespace: ns === null ? null : { dir: ns.dir, prefix: ns.prefix, file_count: ns.fileCount },
|
|
10601
10656
|
number: full(v.number),
|
|
10602
|
-
taken: v.taken,
|
|
10657
|
+
taken: verdict === "no_opinion" ? null : v.taken,
|
|
10603
10658
|
suggestion: full(v.suggestion),
|
|
10604
10659
|
held_by: v.sightings.map((s) => ({
|
|
10605
10660
|
kind: s.kind,
|
|
10606
10661
|
where: s.where,
|
|
10607
10662
|
path: s.path
|
|
10608
10663
|
})),
|
|
10609
|
-
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.`
|
|
10610
10665
|
};
|
|
10611
10666
|
}
|
|
10612
10667
|
const report = await engine.checkNumberCollisions({
|
|
@@ -10995,12 +11050,12 @@ async function deriveWorkingPaths(runGitStatus = defaultGitStatus) {
|
|
|
10995
11050
|
return dirs.length > 0 ? dirs : null;
|
|
10996
11051
|
}
|
|
10997
11052
|
async function defaultGitStatus() {
|
|
10998
|
-
return await new Promise((
|
|
11053
|
+
return await new Promise((resolve4) => {
|
|
10999
11054
|
execFile2(
|
|
11000
11055
|
"git",
|
|
11001
11056
|
["status", "--porcelain"],
|
|
11002
11057
|
{ timeout: 2e3, encoding: "utf8", maxBuffer: 1024 * 1024 },
|
|
11003
|
-
(err, stdout) =>
|
|
11058
|
+
(err, stdout) => resolve4(err ? null : stdout)
|
|
11004
11059
|
);
|
|
11005
11060
|
});
|
|
11006
11061
|
}
|