mu-agent 0.2.11 → 0.2.13
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/CHANGELOG.md +16 -0
- package/judge/mu/index.js +355 -259
- package/package.json +2 -2
package/judge/mu/index.js
CHANGED
|
@@ -15046,7 +15046,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
15046
15046
|
"node_modules/undici/lib/mock/snapshot-recorder.js"(exports, module) {
|
|
15047
15047
|
"use strict";
|
|
15048
15048
|
var { writeFile: writeFile7, readFile: readFile8, mkdir: mkdir2 } = __require("node:fs/promises");
|
|
15049
|
-
var { dirname:
|
|
15049
|
+
var { dirname: dirname14, resolve: resolve16 } = __require("node:path");
|
|
15050
15050
|
var { setTimeout: setTimeout2, clearTimeout: clearTimeout2 } = __require("node:timers");
|
|
15051
15051
|
var { InvalidArgumentError, UndiciError } = require_errors();
|
|
15052
15052
|
var { hashId, isUrlExcludedFactory, normalizeHeaders, createHeaderFilters } = require_snapshot_utils();
|
|
@@ -15292,7 +15292,7 @@ var require_snapshot_recorder = __commonJS({
|
|
|
15292
15292
|
throw new InvalidArgumentError("Snapshot path is required");
|
|
15293
15293
|
}
|
|
15294
15294
|
const resolvedPath = resolve16(path);
|
|
15295
|
-
await mkdir2(
|
|
15295
|
+
await mkdir2(dirname14(resolvedPath), { recursive: true });
|
|
15296
15296
|
const data = Array.from(this.#snapshots.entries()).map(([hash, snapshot2]) => ({
|
|
15297
15297
|
hash,
|
|
15298
15298
|
snapshot: snapshot2
|
|
@@ -27414,7 +27414,7 @@ var require_pi_tui = __commonJS({
|
|
|
27414
27414
|
// packages/kyrn-judge/src/extension/kyrn-judge.ts
|
|
27415
27415
|
var import_pi_coding_agent18 = __toESM(require_pi_coding_agent(), 1);
|
|
27416
27416
|
import { homedir as homedir12 } from "node:os";
|
|
27417
|
-
import { join as
|
|
27417
|
+
import { join as join54 } from "node:path";
|
|
27418
27418
|
|
|
27419
27419
|
// packages/kyrn-judge/src/config.ts
|
|
27420
27420
|
import { readFileSync } from "node:fs";
|
|
@@ -32461,7 +32461,7 @@ ${result.text}` : "(no new output)"
|
|
|
32461
32461
|
}
|
|
32462
32462
|
|
|
32463
32463
|
// packages/kyrn-judge/src/extension/features/board.ts
|
|
32464
|
-
import { join as
|
|
32464
|
+
import { join as join13 } from "node:path";
|
|
32465
32465
|
|
|
32466
32466
|
// packages/kyrn-judge/src/board/model.ts
|
|
32467
32467
|
var pick = (texts, wording) => wording === "zh" ? texts.zh : texts.en;
|
|
@@ -33001,8 +33001,8 @@ var BoardProjects = class {
|
|
|
33001
33001
|
};
|
|
33002
33002
|
|
|
33003
33003
|
// packages/kyrn-judge/src/checkpoint/mutating.ts
|
|
33004
|
-
import { realpathSync } from "node:fs";
|
|
33005
|
-
import { isAbsolute as isAbsolute2, resolve as resolve3 } from "node:path";
|
|
33004
|
+
import { existsSync as existsSync5, realpathSync } from "node:fs";
|
|
33005
|
+
import { dirname as dirname3, isAbsolute as isAbsolute2, join as join11, resolve as resolve3, sep } from "node:path";
|
|
33006
33006
|
|
|
33007
33007
|
// packages/kyrn-judge/src/extension/shell-tools.ts
|
|
33008
33008
|
var SHELL_TOOLS = /* @__PURE__ */ new Set(["bash", "powershell"]);
|
|
@@ -33205,7 +33205,16 @@ function harmlessRedirect(text9, at, both) {
|
|
|
33205
33205
|
if (!text9.startsWith("/dev/null", index) || !/^(?:[\s;&|]|$)/.test(text9.slice(end, end + 1))) return void 0;
|
|
33206
33206
|
return end - 1;
|
|
33207
33207
|
}
|
|
33208
|
-
function
|
|
33208
|
+
function fileRedirect(text9, at, writes) {
|
|
33209
|
+
let index = at + 1;
|
|
33210
|
+
if (text9[index] === ">") index++;
|
|
33211
|
+
while (text9[index] === " " || text9[index] === " ") index++;
|
|
33212
|
+
const name = /^[\w./@%+,:=-]+/.exec(text9.slice(index))?.[0];
|
|
33213
|
+
if (!name || !/^(?:[\s;&|]|$)/.test(text9.slice(index + name.length, index + name.length + 1))) return void 0;
|
|
33214
|
+
writes.push(name);
|
|
33215
|
+
return index + name.length - 1;
|
|
33216
|
+
}
|
|
33217
|
+
function simpleCommands(text9, writes) {
|
|
33209
33218
|
if (text9.includes("\r")) return void 0;
|
|
33210
33219
|
const commands = [];
|
|
33211
33220
|
let words2 = [];
|
|
@@ -33238,7 +33247,7 @@ function simpleCommands(text9) {
|
|
|
33238
33247
|
endCommand();
|
|
33239
33248
|
} else if (next === ">") {
|
|
33240
33249
|
endWord();
|
|
33241
|
-
const end = harmlessRedirect(text9, index + 1, true);
|
|
33250
|
+
const end = harmlessRedirect(text9, index + 1, true) ?? (writes ? fileRedirect(text9, index + 1, writes) : void 0);
|
|
33242
33251
|
if (end === void 0) return void 0;
|
|
33243
33252
|
index = end;
|
|
33244
33253
|
} else return void 0;
|
|
@@ -33247,7 +33256,7 @@ function simpleCommands(text9) {
|
|
|
33247
33256
|
word = "";
|
|
33248
33257
|
started = false;
|
|
33249
33258
|
} else endWord();
|
|
33250
|
-
const end = harmlessRedirect(text9, index, false);
|
|
33259
|
+
const end = harmlessRedirect(text9, index, false) ?? (writes ? fileRedirect(text9, index, writes) : void 0);
|
|
33251
33260
|
if (end === void 0) return void 0;
|
|
33252
33261
|
index = end;
|
|
33253
33262
|
} else if (char === "'") {
|
|
@@ -33260,6 +33269,11 @@ function simpleCommands(text9) {
|
|
|
33260
33269
|
let end = index + 1;
|
|
33261
33270
|
for (; end < text9.length && text9[end] !== '"'; end++) {
|
|
33262
33271
|
const inner = text9[end];
|
|
33272
|
+
if (writes && text9.startsWith(TOP_SUBSTITUTION, end)) {
|
|
33273
|
+
word += TOP;
|
|
33274
|
+
end += TOP_SUBSTITUTION.length - 1;
|
|
33275
|
+
continue;
|
|
33276
|
+
}
|
|
33263
33277
|
if (inner === "`" || inner === "$" && /[({[]/.test(text9[end + 1] ?? "")) return void 0;
|
|
33264
33278
|
if (inner === "\\" && /[$`"\\\n]/.test(text9[end + 1] ?? "")) {
|
|
33265
33279
|
end++;
|
|
@@ -33292,17 +33306,26 @@ function isReadOnlyChain(command, powershell = false, cwd, start = cwd) {
|
|
|
33292
33306
|
if (!commands?.some((words2) => words2.length > 0)) return false;
|
|
33293
33307
|
let elsewhere = startsElsewhere(cwd, start);
|
|
33294
33308
|
return commands.every((words2) => {
|
|
33295
|
-
|
|
33296
|
-
|
|
33297
|
-
|
|
33298
|
-
const [, to, ...more] = words2;
|
|
33299
|
-
elsewhere = cwd === void 0 || to === void 0 || more.length > 0 || !isAbsolute2(to) || /[$*?[~]/.test(to) || to.split(/[\\/]/).includes("..") || !samePlace(to, cwd);
|
|
33300
|
-
return true;
|
|
33301
|
-
}
|
|
33302
|
-
if (program === "find") return !words2.some((word) => FIND_ACTS.test(word));
|
|
33303
|
-
return readOnlyProgram(words2.join(" "), elsewhere);
|
|
33309
|
+
if (words2[0] !== "cd") return readOnlyPart(words2, elsewhere);
|
|
33310
|
+
elsewhere = !cdHome(words2, cwd);
|
|
33311
|
+
return true;
|
|
33304
33312
|
});
|
|
33305
33313
|
}
|
|
33314
|
+
function cdTarget(words2) {
|
|
33315
|
+
const [, to, ...more] = words2;
|
|
33316
|
+
if (to === void 0 || more.length > 0 || !isAbsolute2(to) || /[$*?[~]/.test(to)) return void 0;
|
|
33317
|
+
return to.split(/[\\/]/).includes("..") ? void 0 : to;
|
|
33318
|
+
}
|
|
33319
|
+
function cdHome(words2, cwd) {
|
|
33320
|
+
const to = cdTarget(words2);
|
|
33321
|
+
return cwd !== void 0 && to !== void 0 && samePlace(to, cwd);
|
|
33322
|
+
}
|
|
33323
|
+
function readOnlyPart(words2, elsewhere) {
|
|
33324
|
+
const [program] = words2;
|
|
33325
|
+
if (program === void 0 || program === "true" || program === "false" || program === ":") return true;
|
|
33326
|
+
if (program === "find") return !words2.some((word) => FIND_ACTS.test(word));
|
|
33327
|
+
return readOnlyProgram(words2.join(" "), elsewhere);
|
|
33328
|
+
}
|
|
33306
33329
|
function isMutatingCall(toolName, input, cwd) {
|
|
33307
33330
|
if (READ_ONLY_TOOLS.has(toolName)) return false;
|
|
33308
33331
|
if (isShellTool(toolName)) return !isReadOnlyChain(String(input.command ?? ""), toolName === "powershell", cwd);
|
|
@@ -33315,6 +33338,73 @@ var CHECK_COMMAND = /\b(?:vitest|jest|pytest|mocha|ava|tsc|eslint|biome|ruff|myp
|
|
|
33315
33338
|
function isCheckCommand(command) {
|
|
33316
33339
|
return CHECK_COMMAND.test(command);
|
|
33317
33340
|
}
|
|
33341
|
+
var CHECK_RUN = /^(?:(?:(?:npx|bunx)\s+|(?:pnpm|yarn)\s+(?:exec\s+)?|python3?\s+-m\s+)?(?:vitest|jest|pytest|mocha|ava|tsc|eslint|biome|ruff|mypy|rspec|phpunit|ctest|tox|nox)|(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|build|check|lint|typecheck)|(?:cargo|go|dotnet|swift|make|deno)\s+(?:test|build|check|vet|clippy)|node\s+--test|(?:(?:ba)?sh\s+(?:\.\/)?|\.\/)(?:[\w-][\w.-]*\/)*test\.sh|(?:[\w-][\w.-]*\/)+test\.sh)(?:\s|$)/;
|
|
33342
|
+
var CHECK_SETTING = /^(?:PYTHONPATH|CI|NODE_ENV|FORCE_COLOR|NO_COLOR|RUST_BACKTRACE)=[^$]*$/;
|
|
33343
|
+
var TOP_SUBSTITUTION = "$(git rev-parse --show-toplevel)";
|
|
33344
|
+
var TOP = "\0top\0";
|
|
33345
|
+
var LOCAL_VITEST = /(?:^|\/)node_modules\/vitest\/(?:dist\/cli\.js|vitest\.mjs)$/;
|
|
33346
|
+
var LOCAL_BIN = /(?:^|\/)node_modules\/\.bin\/(?:vitest|jest|mocha|ava|tsc|eslint|biome)$/;
|
|
33347
|
+
function localCheck(run2, dir, home) {
|
|
33348
|
+
const [program, script] = run2;
|
|
33349
|
+
const path = program === "node" ? script : program;
|
|
33350
|
+
if (path === void 0 || !(program === "node" ? LOCAL_VITEST : LOCAL_BIN).test(path) || /[$*?[~]/.test(path))
|
|
33351
|
+
return false;
|
|
33352
|
+
const parts = path.split("/");
|
|
33353
|
+
if (parts.slice(parts.findIndex((part) => part !== "..")).includes("..")) return false;
|
|
33354
|
+
return resolve3(dir, path).startsWith(`${home}${sep}`);
|
|
33355
|
+
}
|
|
33356
|
+
function repositoryTop(dir) {
|
|
33357
|
+
for (let at = dir; ; at = dirname3(at)) {
|
|
33358
|
+
if (existsSync5(join11(at, ".git"))) return at;
|
|
33359
|
+
if (dirname3(at) === at) return void 0;
|
|
33360
|
+
}
|
|
33361
|
+
}
|
|
33362
|
+
function tempFile(name) {
|
|
33363
|
+
return /^\/(?:private\/)?tmp\//.test(name) && !name.split("/").includes("..");
|
|
33364
|
+
}
|
|
33365
|
+
function isCheckChain(command, powershell = false, cwd, start = cwd) {
|
|
33366
|
+
if (powershell || cwd === void 0) return false;
|
|
33367
|
+
const writes = [];
|
|
33368
|
+
const commands = simpleCommands(command.trim(), writes);
|
|
33369
|
+
if (!commands || !writes.every(tempFile)) return false;
|
|
33370
|
+
let home = resolve3(cwd);
|
|
33371
|
+
try {
|
|
33372
|
+
home = realpathSync.native(cwd);
|
|
33373
|
+
} catch {
|
|
33374
|
+
}
|
|
33375
|
+
const inProject2 = (to) => {
|
|
33376
|
+
if (samePlace(to, cwd)) return home;
|
|
33377
|
+
try {
|
|
33378
|
+
const real2 = realpathSync.native(to);
|
|
33379
|
+
return real2.startsWith(`${home}${sep}`) ? real2 : void 0;
|
|
33380
|
+
} catch {
|
|
33381
|
+
return void 0;
|
|
33382
|
+
}
|
|
33383
|
+
};
|
|
33384
|
+
let dir = start === void 0 ? home : inProject2(start);
|
|
33385
|
+
let checks = 0;
|
|
33386
|
+
const parts = commands.every((said) => {
|
|
33387
|
+
let words2 = said;
|
|
33388
|
+
if (said.some((word) => word.includes(TOP))) {
|
|
33389
|
+
if (dir === void 0 || repositoryTop(dir) !== home) return false;
|
|
33390
|
+
words2 = said.map((word) => word.replaceAll(TOP, home));
|
|
33391
|
+
}
|
|
33392
|
+
if (words2[0] === "cd") {
|
|
33393
|
+
const to = cdTarget(words2);
|
|
33394
|
+
dir = to === void 0 ? void 0 : inProject2(to);
|
|
33395
|
+
return true;
|
|
33396
|
+
}
|
|
33397
|
+
let at = words2[0] === "env" ? 1 : 0;
|
|
33398
|
+
while (at < words2.length && CHECK_SETTING.test(words2[at])) at++;
|
|
33399
|
+
const run2 = words2.slice(at);
|
|
33400
|
+
if (CHECK_RUN.test(run2.join(" ")) || dir !== void 0 && localCheck(run2, dir, home)) {
|
|
33401
|
+
checks++;
|
|
33402
|
+
return dir !== void 0;
|
|
33403
|
+
}
|
|
33404
|
+
return at === 0 && readOnlyPart(words2, dir !== home);
|
|
33405
|
+
});
|
|
33406
|
+
return parts && checks > 0;
|
|
33407
|
+
}
|
|
33318
33408
|
|
|
33319
33409
|
// packages/kyrn-judge/src/decisions/board-read.ts
|
|
33320
33410
|
var MAX_EVENTS = 16;
|
|
@@ -33465,7 +33555,7 @@ var boardRead = defineDecision({
|
|
|
33465
33555
|
|
|
33466
33556
|
// packages/kyrn-judge/src/swarm/run.ts
|
|
33467
33557
|
import { appendFileSync, mkdirSync as mkdirSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
33468
|
-
import { join as
|
|
33558
|
+
import { join as join12 } from "node:path";
|
|
33469
33559
|
|
|
33470
33560
|
// packages/kyrn-judge/src/decisions/tool-injection.ts
|
|
33471
33561
|
var INJECTION_THRESHOLD = 0.5;
|
|
@@ -33941,7 +34031,7 @@ function subagentUsage(kind, bee) {
|
|
|
33941
34031
|
};
|
|
33942
34032
|
}
|
|
33943
34033
|
function controlPath(dir, index) {
|
|
33944
|
-
return
|
|
34034
|
+
return join12(dir, "control", `bee-${index}.json`);
|
|
33945
34035
|
}
|
|
33946
34036
|
var active = /* @__PURE__ */ new Set();
|
|
33947
34037
|
function activeRuns() {
|
|
@@ -33983,8 +34073,8 @@ var SwarmRun = class {
|
|
|
33983
34073
|
this.now = options.now ?? Date.now;
|
|
33984
34074
|
this.startedAt = this.now();
|
|
33985
34075
|
this.controllers = options.bees.map(() => void 0);
|
|
33986
|
-
mkdirSync6(
|
|
33987
|
-
mkdirSync6(
|
|
34076
|
+
mkdirSync6(join12(this.dir, "control"), { recursive: true });
|
|
34077
|
+
mkdirSync6(join12(this.dir, "transcripts"), { recursive: true });
|
|
33988
34078
|
this.bees = options.bees.map((bee, index) => this.stateFor(bee, index, this.startedAt));
|
|
33989
34079
|
}
|
|
33990
34080
|
stateFor(bee, index, now) {
|
|
@@ -33992,7 +34082,7 @@ var SwarmRun = class {
|
|
|
33992
34082
|
role: bee.role,
|
|
33993
34083
|
model: bee.model,
|
|
33994
34084
|
thinking: bee.thinking,
|
|
33995
|
-
transcript:
|
|
34085
|
+
transcript: join12(this.dir, "transcripts", `${index}-${bee.name.replace(/[^\w.-]+/g, "_")}.jsonl`)
|
|
33996
34086
|
});
|
|
33997
34087
|
}
|
|
33998
34088
|
/**
|
|
@@ -34658,7 +34748,7 @@ function registerBoard(runtime, roots) {
|
|
|
34658
34748
|
});
|
|
34659
34749
|
if (!options.enabled || process.env.KYRN_SWARM_CONTROL) return;
|
|
34660
34750
|
const { pi } = runtime;
|
|
34661
|
-
const projects = new BoardProjects(roots ?
|
|
34751
|
+
const projects = new BoardProjects(roots ? join13(roots.agentDir, "mu") : void 0);
|
|
34662
34752
|
const calls = /* @__PURE__ */ new Map();
|
|
34663
34753
|
let steps = [];
|
|
34664
34754
|
let latest = "";
|
|
@@ -35633,9 +35723,9 @@ ${addModelHelp(language())}`,
|
|
|
35633
35723
|
|
|
35634
35724
|
// packages/kyrn-judge/src/extension/features/browser.ts
|
|
35635
35725
|
var import_typebox2 = __toESM(require_typebox(), 1);
|
|
35636
|
-
import { existsSync as
|
|
35726
|
+
import { existsSync as existsSync7, rmSync as rmSync4 } from "node:fs";
|
|
35637
35727
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
35638
|
-
import { join as
|
|
35728
|
+
import { join as join16 } from "node:path";
|
|
35639
35729
|
import { fileURLToPath } from "node:url";
|
|
35640
35730
|
|
|
35641
35731
|
// packages/kyrn-judge/src/decisions/browser-step.ts
|
|
@@ -36516,9 +36606,9 @@ var CdpConnection = class _CdpConnection {
|
|
|
36516
36606
|
|
|
36517
36607
|
// packages/kyrn-judge/src/browser/chrome.ts
|
|
36518
36608
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
36519
|
-
import { existsSync as
|
|
36609
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync7, readFileSync as readFileSync7, rmSync as rmSync3 } from "node:fs";
|
|
36520
36610
|
import { homedir as homedir2 } from "node:os";
|
|
36521
|
-
import { basename as basename2, dirname as
|
|
36611
|
+
import { basename as basename2, dirname as dirname4, join as join14, posix, win32 } from "node:path";
|
|
36522
36612
|
|
|
36523
36613
|
// packages/kyrn-judge/src/platform.ts
|
|
36524
36614
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
@@ -36712,7 +36802,7 @@ ${browserAdvice(host2)}`, {
|
|
|
36712
36802
|
params: { profileDir }
|
|
36713
36803
|
});
|
|
36714
36804
|
spelled = translated;
|
|
36715
|
-
cwd =
|
|
36805
|
+
cwd = dirname4(browser.executable);
|
|
36716
36806
|
} else {
|
|
36717
36807
|
const base = confinedProfileBase(browser.executable, host2);
|
|
36718
36808
|
if (base) profileDir = posix.join(base, `mu-${basename2(profileDir)}`);
|
|
@@ -36746,11 +36836,11 @@ function thisBrowserHost(env = process.env) {
|
|
|
36746
36836
|
}
|
|
36747
36837
|
};
|
|
36748
36838
|
}
|
|
36749
|
-
return { platform: process.platform, env, home: homedir2(), exists:
|
|
36839
|
+
return { platform: process.platform, env, home: homedir2(), exists: existsSync6, wsl };
|
|
36750
36840
|
}
|
|
36751
36841
|
function readEndpoint(profileDir) {
|
|
36752
36842
|
try {
|
|
36753
|
-
const [port, path] = readFileSync7(
|
|
36843
|
+
const [port, path] = readFileSync7(join14(profileDir, "DevToolsActivePort"), "utf8").trim().split("\n");
|
|
36754
36844
|
return port && path ? `ws://127.0.0.1:${port}${path}` : void 0;
|
|
36755
36845
|
} catch {
|
|
36756
36846
|
return void 0;
|
|
@@ -36787,14 +36877,14 @@ async function launchChrome(options = {}) {
|
|
|
36787
36877
|
const plan2 = planBrowserLaunch({
|
|
36788
36878
|
host: host2,
|
|
36789
36879
|
browser,
|
|
36790
|
-
profileDir: options.profileDir ??
|
|
36880
|
+
profileDir: options.profileDir ?? join14(muHome(), "browser-profile"),
|
|
36791
36881
|
headless: options.headless !== false
|
|
36792
36882
|
});
|
|
36793
36883
|
const { profileDir } = plan2;
|
|
36794
36884
|
const running = readEndpoint(profileDir);
|
|
36795
36885
|
if (running && await isAlive(running)) return { endpoint: running, profileDir };
|
|
36796
36886
|
mkdirSync7(profileDir, { recursive: true });
|
|
36797
|
-
rmSync3(
|
|
36887
|
+
rmSync3(join14(profileDir, "DevToolsActivePort"), { force: true });
|
|
36798
36888
|
const child = spawn3(plan2.command, plan2.args, { stdio: "ignore", detached: false, cwd: plan2.cwd });
|
|
36799
36889
|
let failure;
|
|
36800
36890
|
child.on("error", (error) => {
|
|
@@ -36823,7 +36913,7 @@ async function launchChrome(options = {}) {
|
|
|
36823
36913
|
|
|
36824
36914
|
// packages/kyrn-judge/src/browser/embedded.ts
|
|
36825
36915
|
import { readFileSync as readFileSync8 } from "node:fs";
|
|
36826
|
-
import { join as
|
|
36916
|
+
import { join as join15 } from "node:path";
|
|
36827
36917
|
var ADVERT_FILE = "desktop-browser.json";
|
|
36828
36918
|
var PROTOCOL_VERSION = 1;
|
|
36829
36919
|
function processRuns(pid) {
|
|
@@ -36848,7 +36938,7 @@ function findEmbeddedEndpoint(host2 = {}) {
|
|
|
36848
36938
|
if (fromEnv) return loopbackSocket(fromEnv) ? { url: fromEnv } : void 0;
|
|
36849
36939
|
try {
|
|
36850
36940
|
const read2 = host2.readFile ?? ((path) => readFileSync8(path, "utf8"));
|
|
36851
|
-
const advert = JSON.parse(read2(
|
|
36941
|
+
const advert = JSON.parse(read2(join15(host2.home ?? muHome(), ADVERT_FILE)));
|
|
36852
36942
|
if (typeof advert.url !== "string" || !loopbackSocket(advert.url)) return void 0;
|
|
36853
36943
|
const pid = typeof advert.pid === "number" ? advert.pid : void 0;
|
|
36854
36944
|
if (pid !== void 0 && !(host2.isRunning ?? processRuns)(pid)) return void 0;
|
|
@@ -36947,7 +37037,7 @@ function registerBrowser(runtime) {
|
|
|
36947
37037
|
let chrome;
|
|
36948
37038
|
let cdp;
|
|
36949
37039
|
let embedded;
|
|
36950
|
-
const ownProfile = !options.profileDir && process.env.KYRN_SWARM_DEPTH ?
|
|
37040
|
+
const ownProfile = !options.profileDir && process.env.KYRN_SWARM_DEPTH ? join16(tmpdir2(), `kyrn-browser-${process.pid}`) : void 0;
|
|
36951
37041
|
const connect2 = async () => {
|
|
36952
37042
|
if (cdp && !cdp.isClosed) return cdp;
|
|
36953
37043
|
cdp = void 0;
|
|
@@ -37199,7 +37289,7 @@ ${result.page.text.slice(0, textChars)}`
|
|
|
37199
37289
|
});
|
|
37200
37290
|
pi.on(
|
|
37201
37291
|
"resources_discover",
|
|
37202
|
-
failOpen(() =>
|
|
37292
|
+
failOpen(() => existsSync7(SKILL_PATH) ? { skillPaths: [SKILL_PATH] } : void 0)
|
|
37203
37293
|
);
|
|
37204
37294
|
pi.on(
|
|
37205
37295
|
"session_shutdown",
|
|
@@ -37577,12 +37667,12 @@ Open one with find_capability({ open: "<id>" }).`;
|
|
|
37577
37667
|
// packages/kyrn-judge/src/extension/features/checkpoint.ts
|
|
37578
37668
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
37579
37669
|
import { homedir as homedir3 } from "node:os";
|
|
37580
|
-
import { join as
|
|
37670
|
+
import { join as join19 } from "node:path";
|
|
37581
37671
|
|
|
37582
37672
|
// packages/kyrn-judge/src/checkpoint/git.ts
|
|
37583
37673
|
import { execFile, spawn as spawn4 } from "node:child_process";
|
|
37584
|
-
import { accessSync, constants, existsSync as
|
|
37585
|
-
import { delimiter, join as
|
|
37674
|
+
import { accessSync, constants, existsSync as existsSync8, statSync as statSync5 } from "node:fs";
|
|
37675
|
+
import { delimiter, join as join17 } from "node:path";
|
|
37586
37676
|
var TIMED_OUT = 124;
|
|
37587
37677
|
var GitMissing = class extends Error {
|
|
37588
37678
|
constructor(binary, cause) {
|
|
@@ -37607,7 +37697,7 @@ var GitFailed = class extends Error {
|
|
|
37607
37697
|
}
|
|
37608
37698
|
};
|
|
37609
37699
|
function findOnPath(binary, path) {
|
|
37610
|
-
const candidates = binary.includes("/") ? [binary] : (path ?? "").split(delimiter).filter(Boolean).map((folder) =>
|
|
37700
|
+
const candidates = binary.includes("/") ? [binary] : (path ?? "").split(delimiter).filter(Boolean).map((folder) => join17(folder, binary));
|
|
37611
37701
|
return candidates.find((candidate) => {
|
|
37612
37702
|
try {
|
|
37613
37703
|
accessSync(candidate, constants.X_OK);
|
|
@@ -37625,7 +37715,7 @@ var hostProbe = {
|
|
|
37625
37715
|
"/usr/bin/xcode-select",
|
|
37626
37716
|
["-p"],
|
|
37627
37717
|
{ timeout: 5e3 },
|
|
37628
|
-
(error, stdout) => done(!error &&
|
|
37718
|
+
(error, stdout) => done(!error && existsSync8(stdout.trim()))
|
|
37629
37719
|
);
|
|
37630
37720
|
})
|
|
37631
37721
|
};
|
|
@@ -37707,7 +37797,7 @@ function spawnOnce(binary, timeoutMs, args, env, input, limit) {
|
|
|
37707
37797
|
child.stdin?.end(input ?? "");
|
|
37708
37798
|
});
|
|
37709
37799
|
}
|
|
37710
|
-
function shadowEnv(base, gitDir, workTree, indexFile =
|
|
37800
|
+
function shadowEnv(base, gitDir, workTree, indexFile = join17(gitDir, "index")) {
|
|
37711
37801
|
const env = {};
|
|
37712
37802
|
for (const [key, value] of Object.entries(base)) {
|
|
37713
37803
|
if (value !== void 0 && !key.toUpperCase().startsWith("GIT_")) env[key] = value;
|
|
@@ -37736,7 +37826,7 @@ import {
|
|
|
37736
37826
|
appendFileSync as appendFileSync2,
|
|
37737
37827
|
chmodSync as chmodSync2,
|
|
37738
37828
|
constants as constants2,
|
|
37739
|
-
existsSync as
|
|
37829
|
+
existsSync as existsSync9,
|
|
37740
37830
|
lstatSync,
|
|
37741
37831
|
mkdirSync as mkdirSync8,
|
|
37742
37832
|
readdirSync as readdirSync2,
|
|
@@ -37748,7 +37838,7 @@ import {
|
|
|
37748
37838
|
unlinkSync as unlinkSync2,
|
|
37749
37839
|
writeFileSync as writeFileSync6
|
|
37750
37840
|
} from "node:fs";
|
|
37751
|
-
import { basename as basename3, dirname as
|
|
37841
|
+
import { basename as basename3, dirname as dirname5, isAbsolute as isAbsolute3, join as join18, relative, resolve as resolve4, sep as sep2 } from "node:path";
|
|
37752
37842
|
var BUILT_IN_IGNORES = [
|
|
37753
37843
|
"node_modules/",
|
|
37754
37844
|
"bower_components/",
|
|
@@ -37802,7 +37892,7 @@ var shadowConfig = (gitDir) => `${CONFIG_MARKER}
|
|
|
37802
37892
|
longpaths = true
|
|
37803
37893
|
quotepath = false
|
|
37804
37894
|
fsmonitor = false
|
|
37805
|
-
hooksPath = "${
|
|
37895
|
+
hooksPath = "${join18(gitDir, "mu-no-hooks").replaceAll("\\", "/").replaceAll('"', '\\"')}"
|
|
37806
37896
|
[gc]
|
|
37807
37897
|
auto = 0
|
|
37808
37898
|
[commit]
|
|
@@ -37843,19 +37933,19 @@ function isSafePath(path) {
|
|
|
37843
37933
|
if (!path || path.startsWith("/") || /^[a-zA-Z]:/.test(path) || path.includes("\\")) return false;
|
|
37844
37934
|
return path.split("/").every((part) => part !== "" && part !== "." && part !== ".." && !/^\.git$|^git~\d+$/i.test(part));
|
|
37845
37935
|
}
|
|
37846
|
-
var onDisk = (store, path) =>
|
|
37936
|
+
var onDisk = (store, path) => join18(store.root, ...path.split("/"));
|
|
37847
37937
|
function realPath(path) {
|
|
37848
37938
|
const absolute3 = resolve4(path);
|
|
37849
37939
|
try {
|
|
37850
37940
|
return realpathSync2.native(absolute3);
|
|
37851
37941
|
} catch {
|
|
37852
|
-
const parent =
|
|
37853
|
-
return parent === absolute3 ? absolute3 :
|
|
37942
|
+
const parent = dirname5(absolute3);
|
|
37943
|
+
return parent === absolute3 ? absolute3 : join18(realPath(parent), basename3(absolute3));
|
|
37854
37944
|
}
|
|
37855
37945
|
}
|
|
37856
37946
|
function inside(outer, inner) {
|
|
37857
37947
|
const rel = relative(realPath(outer), realPath(inner));
|
|
37858
|
-
return rel === ".." || rel.startsWith(`..${
|
|
37948
|
+
return rel === ".." || rel.startsWith(`..${sep2}`) || isAbsolute3(rel) ? void 0 : rel;
|
|
37859
37949
|
}
|
|
37860
37950
|
function isWithin(outer, inner) {
|
|
37861
37951
|
return inside(outer, inner) !== void 0;
|
|
@@ -37866,13 +37956,13 @@ function ownFolderPatterns(root, folders) {
|
|
|
37866
37956
|
const rel = inside(root, folder);
|
|
37867
37957
|
if (!rel) continue;
|
|
37868
37958
|
patterns.add(
|
|
37869
|
-
`/${rel.split(
|
|
37959
|
+
`/${rel.split(sep2).map((part) => part.replace(/[\\*?[\]!#]/g, "\\$&")).join("/")}/`
|
|
37870
37960
|
);
|
|
37871
37961
|
}
|
|
37872
37962
|
return [...patterns];
|
|
37873
37963
|
}
|
|
37874
37964
|
async function openStore(options) {
|
|
37875
|
-
const gitDir =
|
|
37965
|
+
const gitDir = join18(options.baseDir, projectKey(options.root));
|
|
37876
37966
|
const store = {
|
|
37877
37967
|
gitDir,
|
|
37878
37968
|
root: options.root,
|
|
@@ -37880,7 +37970,7 @@ async function openStore(options) {
|
|
|
37880
37970
|
env: shadowEnv(options.env ?? process.env, gitDir, options.root),
|
|
37881
37971
|
maxFileBytes: options.maxFileBytes ?? 5 * 1024 * 1024
|
|
37882
37972
|
};
|
|
37883
|
-
if (!
|
|
37973
|
+
if (!existsSync9(join18(gitDir, "HEAD"))) {
|
|
37884
37974
|
mkdirSync8(gitDir, { recursive: true, mode: 448 });
|
|
37885
37975
|
const { GIT_WORK_TREE: _tree, GIT_INDEX_FILE: _index, GIT_DIR: _dir, ...bare } = store.env;
|
|
37886
37976
|
const result = await options.run(["-c", "init.defaultBranch=mu", "init", "--bare", "--quiet", gitDir], bare);
|
|
@@ -37890,15 +37980,15 @@ async function openStore(options) {
|
|
|
37890
37980
|
chmodSync2(gitDir, 448);
|
|
37891
37981
|
} catch {
|
|
37892
37982
|
}
|
|
37893
|
-
const config =
|
|
37983
|
+
const config = join18(gitDir, "config");
|
|
37894
37984
|
if (!readFileSync9(config, "utf8").includes(CONFIG_MARKER)) appendFileSync2(config, `
|
|
37895
37985
|
${shadowConfig(gitDir)}`);
|
|
37896
|
-
mkdirSync8(
|
|
37986
|
+
mkdirSync8(join18(gitDir, "info"), { recursive: true });
|
|
37897
37987
|
const own = ownFolderPatterns(options.root, [options.baseDir, ...options.ownFolders ?? []]);
|
|
37898
|
-
writeFileSync6(
|
|
37988
|
+
writeFileSync6(join18(gitDir, "info", "exclude"), `${[...options.ignore ?? BUILT_IN_IGNORES, ...own].join("\n")}
|
|
37899
37989
|
`);
|
|
37900
|
-
writeFileSync6(
|
|
37901
|
-
writeFileSync6(
|
|
37990
|
+
writeFileSync6(join18(gitDir, "info", "attributes"), SHADOW_ATTRIBUTES);
|
|
37991
|
+
writeFileSync6(join18(gitDir, PROJECT_FILE), `${JSON.stringify({ root: options.root, lastUsed: Date.now() })}
|
|
37902
37992
|
`);
|
|
37903
37993
|
releaseLocks(store, STALE_LOCK_MS);
|
|
37904
37994
|
const stale = zList(await git(store, ["ls-files", "-z", "--cached", "--ignored", "--exclude-standard"]));
|
|
@@ -37914,7 +38004,7 @@ function releaseLocks(store, olderThanMs) {
|
|
|
37914
38004
|
}
|
|
37915
38005
|
for (const name of names) {
|
|
37916
38006
|
if (!name.endsWith(".lock") && !/^restore-.*\.index$/.test(name)) continue;
|
|
37917
|
-
const path =
|
|
38007
|
+
const path = join18(store.gitDir, name);
|
|
37918
38008
|
try {
|
|
37919
38009
|
if (Date.now() - statSync6(path).mtimeMs >= olderThanMs) rmSync5(path, { force: true });
|
|
37920
38010
|
} catch {
|
|
@@ -38030,7 +38120,7 @@ function obstacle(store, path, mustBeAbsent) {
|
|
|
38030
38120
|
const parts = path.split("/");
|
|
38031
38121
|
for (let depth = 1; depth < parts.length; depth++) {
|
|
38032
38122
|
try {
|
|
38033
|
-
if (!lstatSync(
|
|
38123
|
+
if (!lstatSync(join18(store.root, ...parts.slice(0, depth))).isDirectory())
|
|
38034
38124
|
return "a file is where its folder should be";
|
|
38035
38125
|
} catch {
|
|
38036
38126
|
break;
|
|
@@ -38067,7 +38157,7 @@ async function applyRestore(store, plan2, keep = /* @__PURE__ */ new Set()) {
|
|
|
38067
38157
|
const parts = path.split("/");
|
|
38068
38158
|
for (let depth = parts.length - 1; depth >= 1; depth--) {
|
|
38069
38159
|
try {
|
|
38070
|
-
rmdirSync(
|
|
38160
|
+
rmdirSync(join18(store.root, ...parts.slice(0, depth)));
|
|
38071
38161
|
} catch {
|
|
38072
38162
|
break;
|
|
38073
38163
|
}
|
|
@@ -38091,7 +38181,7 @@ async function applyRestore(store, plan2, keep = /* @__PURE__ */ new Set()) {
|
|
|
38091
38181
|
}
|
|
38092
38182
|
}
|
|
38093
38183
|
if (write.length > 0) {
|
|
38094
|
-
const index =
|
|
38184
|
+
const index = join18(store.gitDir, `restore-${randomUUID3()}.index`);
|
|
38095
38185
|
const env = { ...store.env, GIT_INDEX_FILE: index };
|
|
38096
38186
|
try {
|
|
38097
38187
|
await git(store, ["read-tree", plan2.commit], void 0, env);
|
|
@@ -38133,11 +38223,11 @@ function sweepProjects(baseDir, maxAgeDays, now = Date.now(), offLimits = () =>
|
|
|
38133
38223
|
}
|
|
38134
38224
|
for (const name of names) {
|
|
38135
38225
|
try {
|
|
38136
|
-
const project = JSON.parse(readFileSync9(
|
|
38226
|
+
const project = JSON.parse(readFileSync9(join18(baseDir, name, PROJECT_FILE), "utf8"));
|
|
38137
38227
|
const unusable = typeof project.root === "string" && offLimits(project.root);
|
|
38138
38228
|
const stale = typeof project.lastUsed === "number" && now - project.lastUsed >= maxAgeDays * 864e5;
|
|
38139
38229
|
if (!unusable && !stale) continue;
|
|
38140
|
-
rmSync5(
|
|
38230
|
+
rmSync5(join18(baseDir, name), { recursive: true, force: true });
|
|
38141
38231
|
removed.push(name);
|
|
38142
38232
|
} catch {
|
|
38143
38233
|
}
|
|
@@ -38321,7 +38411,7 @@ function registerCheckpoint(runtime, roots, deps = {}) {
|
|
|
38321
38411
|
unattended: false
|
|
38322
38412
|
});
|
|
38323
38413
|
if (!options.enabled || process.env.KYRN_SWARM_DEPTH) return;
|
|
38324
|
-
const baseDir = options.dir || (roots ?
|
|
38414
|
+
const baseDir = options.dir || (roots ? join19(roots.agentDir, "mu", "checkpoints") : "");
|
|
38325
38415
|
if (!baseDir) return;
|
|
38326
38416
|
const { pi } = runtime;
|
|
38327
38417
|
const home = () => roots?.home ?? homedir3();
|
|
@@ -38894,14 +38984,14 @@ The agent will then start over from your request, with a note about what didn't
|
|
|
38894
38984
|
|
|
38895
38985
|
// packages/kyrn-judge/src/extension/features/commands.ts
|
|
38896
38986
|
var import_pi_coding_agent5 = __toESM(require_pi_coding_agent(), 1);
|
|
38897
|
-
import { existsSync as
|
|
38898
|
-
import { join as
|
|
38987
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
38988
|
+
import { join as join22 } from "node:path";
|
|
38899
38989
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
38900
38990
|
|
|
38901
38991
|
// packages/kyrn-judge/src/extension/agents.ts
|
|
38902
38992
|
var import_pi_coding_agent3 = __toESM(require_pi_coding_agent(), 1);
|
|
38903
38993
|
import { readdirSync as readdirSync3, readFileSync as readFileSync10 } from "node:fs";
|
|
38904
|
-
import { join as
|
|
38994
|
+
import { join as join20 } from "node:path";
|
|
38905
38995
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
38906
38996
|
var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
38907
38997
|
function parseToolList(value) {
|
|
@@ -38935,7 +39025,7 @@ function loadDir(dir, source) {
|
|
|
38935
39025
|
}
|
|
38936
39026
|
const agents = [];
|
|
38937
39027
|
for (const name of names) {
|
|
38938
|
-
const filePath =
|
|
39028
|
+
const filePath = join20(dir, name);
|
|
38939
39029
|
try {
|
|
38940
39030
|
const agent = parseAgent(readFileSync10(filePath, "utf8"), source, filePath);
|
|
38941
39031
|
if (agent) agents.push(agent);
|
|
@@ -38954,8 +39044,8 @@ function loadAgents(userDir, builtInDir = BUILT_IN_AGENTS_DIR) {
|
|
|
38954
39044
|
|
|
38955
39045
|
// packages/kyrn-judge/src/extension/localized-prompts.ts
|
|
38956
39046
|
import { createHash as createHash4 } from "node:crypto";
|
|
38957
|
-
import { existsSync as
|
|
38958
|
-
import { join as
|
|
39047
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync9, readdirSync as readdirSync4, readFileSync as readFileSync11, renameSync as renameSync4, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
39048
|
+
import { join as join21 } from "node:path";
|
|
38959
39049
|
var FORMAT = 1;
|
|
38960
39050
|
var LANGUAGE_KEY = /^([A-Za-z]+(?:-[A-Za-z]+)*)-(zh|en):/;
|
|
38961
39051
|
function localizeTemplate(text9, wording) {
|
|
@@ -38993,19 +39083,19 @@ var oneLineAt = (lines2, index) => {
|
|
|
38993
39083
|
function promptsFor(dir, wording, root) {
|
|
38994
39084
|
if (wording !== "zh") return dir;
|
|
38995
39085
|
try {
|
|
38996
|
-
const sources = readdirSync4(dir).filter((name) => name.endsWith(".md")).sort().map((name) => [name, readFileSync11(
|
|
39086
|
+
const sources = readdirSync4(dir).filter((name) => name.endsWith(".md")).sort().map((name) => [name, readFileSync11(join21(dir, name), "utf8")]);
|
|
38997
39087
|
const hash = createHash4("sha256").update(JSON.stringify([FORMAT, wording, sources])).digest("hex").slice(0, 12);
|
|
38998
|
-
const target =
|
|
38999
|
-
if (
|
|
39088
|
+
const target = join21(root, `${wording}-${hash}`);
|
|
39089
|
+
if (existsSync10(target)) return target;
|
|
39000
39090
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
39001
39091
|
mkdirSync9(temporary, { recursive: true, mode: 448 });
|
|
39002
|
-
for (const [name, text9] of sources) writeFileSync7(
|
|
39092
|
+
for (const [name, text9] of sources) writeFileSync7(join21(temporary, name), localizeTemplate(text9, wording));
|
|
39003
39093
|
try {
|
|
39004
39094
|
renameSync4(temporary, target);
|
|
39005
39095
|
} catch {
|
|
39006
39096
|
rmSync6(temporary, { recursive: true, force: true });
|
|
39007
39097
|
}
|
|
39008
|
-
return
|
|
39098
|
+
return existsSync10(target) ? target : dir;
|
|
39009
39099
|
} catch {
|
|
39010
39100
|
return dir;
|
|
39011
39101
|
}
|
|
@@ -39564,7 +39654,7 @@ function registerCommands(runtime, roots) {
|
|
|
39564
39654
|
const chrome = findBrowser(browserHost)?.executable;
|
|
39565
39655
|
const available = ctx.modelRegistry.getAvailable();
|
|
39566
39656
|
const providers = [...new Set(available.map((model) => model.provider))];
|
|
39567
|
-
const agentsDir =
|
|
39657
|
+
const agentsDir = join22((0, import_pi_coding_agent5.getAgentDir)(), "agents");
|
|
39568
39658
|
const roles = loadAgents(agentsDir);
|
|
39569
39659
|
const ladder = runtime.options("swarm", { enabled: true, models: [] }).models;
|
|
39570
39660
|
const missing = ladder.filter((ref) => {
|
|
@@ -39627,10 +39717,10 @@ function registerCommands(runtime, roots) {
|
|
|
39627
39717
|
pi.on(
|
|
39628
39718
|
"resources_discover",
|
|
39629
39719
|
failOpen(
|
|
39630
|
-
() =>
|
|
39720
|
+
() => existsSync11(PROMPTS_DIR) ? {
|
|
39631
39721
|
promptPaths: [
|
|
39632
39722
|
// In mu's own folder, which is the user's alone: a template is text the model follows.
|
|
39633
|
-
roots ? promptsFor(PROMPTS_DIR, appLanguage()?.wording,
|
|
39723
|
+
roots ? promptsFor(PROMPTS_DIR, appLanguage()?.wording, join22(roots.agentDir, "mu", "prompts")) : PROMPTS_DIR
|
|
39634
39724
|
]
|
|
39635
39725
|
} : void 0
|
|
39636
39726
|
)
|
|
@@ -39641,7 +39731,7 @@ function registerCommands(runtime, roots) {
|
|
|
39641
39731
|
var import_pi_coding_agent6 = __toESM(require_pi_coding_agent(), 1);
|
|
39642
39732
|
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync8 } from "node:fs";
|
|
39643
39733
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
39644
|
-
import { join as
|
|
39734
|
+
import { join as join23 } from "node:path";
|
|
39645
39735
|
|
|
39646
39736
|
// packages/kyrn-judge/src/compaction/history.ts
|
|
39647
39737
|
function blocks(content) {
|
|
@@ -40080,11 +40170,11 @@ ${liveText}`, calls: liveCalls });
|
|
|
40080
40170
|
);
|
|
40081
40171
|
return void 0;
|
|
40082
40172
|
}
|
|
40083
|
-
const archiveDir =
|
|
40173
|
+
const archiveDir = join23(tmpdir3(), `kyrn-${runtime.sessionId}`, "compacted");
|
|
40084
40174
|
const pruned = apply(items, planned.plans, options, (call) => {
|
|
40085
40175
|
try {
|
|
40086
40176
|
mkdirSync10(archiveDir, { recursive: true });
|
|
40087
|
-
const path =
|
|
40177
|
+
const path = join23(archiveDir, `${call.id.replace(/[^\w.-]/g, "_")}.txt`);
|
|
40088
40178
|
writeFileSync8(path, call.result, { mode: 384 });
|
|
40089
40179
|
return path;
|
|
40090
40180
|
} catch {
|
|
@@ -41304,9 +41394,9 @@ last update failed: ${lastFailure}` : text9, "info");
|
|
|
41304
41394
|
|
|
41305
41395
|
// packages/kyrn-judge/src/extension/features/notices.ts
|
|
41306
41396
|
import { readFileSync as readFileSync13 } from "node:fs";
|
|
41307
|
-
import { join as
|
|
41397
|
+
import { join as join24 } from "node:path";
|
|
41308
41398
|
function noticesFile(agentDir) {
|
|
41309
|
-
return
|
|
41399
|
+
return join24(agentDir, "mu", "notices.json");
|
|
41310
41400
|
}
|
|
41311
41401
|
function readNotices(file) {
|
|
41312
41402
|
if (!file) return {};
|
|
@@ -42679,7 +42769,7 @@ var import_pi_coding_agent8 = __toESM(require_pi_coding_agent(), 1);
|
|
|
42679
42769
|
var import_typebox7 = __toESM(require_typebox(), 1);
|
|
42680
42770
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
42681
42771
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
42682
|
-
import { join as
|
|
42772
|
+
import { join as join30 } from "node:path";
|
|
42683
42773
|
|
|
42684
42774
|
// packages/kyrn-judge/src/decisions/hive.ts
|
|
42685
42775
|
var hivePublish = defineDecision({
|
|
@@ -42784,7 +42874,7 @@ var hiveRelate = defineDecision({
|
|
|
42784
42874
|
|
|
42785
42875
|
// packages/kyrn-judge/src/hive/board.ts
|
|
42786
42876
|
import { appendFileSync as appendFileSync3, closeSync as closeSync2, fstatSync, mkdirSync as mkdirSync11, openSync as openSync2, readSync as readSync2 } from "node:fs";
|
|
42787
|
-
import { join as
|
|
42877
|
+
import { join as join25 } from "node:path";
|
|
42788
42878
|
var BOARD = "board.jsonl";
|
|
42789
42879
|
var DELIVERIES = "deliveries.jsonl";
|
|
42790
42880
|
var RELATIONS = "relations.jsonl";
|
|
@@ -42829,41 +42919,41 @@ var Board = class {
|
|
|
42829
42919
|
mkdirSync11(dir, { recursive: true });
|
|
42830
42920
|
}
|
|
42831
42921
|
post(note2) {
|
|
42832
|
-
appendFileSync3(
|
|
42922
|
+
appendFileSync3(join25(this.dir, BOARD), `${JSON.stringify(note2)}
|
|
42833
42923
|
`);
|
|
42834
42924
|
}
|
|
42835
42925
|
/** Notes appended since the last call on this instance. */
|
|
42836
42926
|
fresh() {
|
|
42837
|
-
const read2 = readFrom(
|
|
42927
|
+
const read2 = readFrom(join25(this.dir, BOARD), this.offset);
|
|
42838
42928
|
this.offset = read2.offset;
|
|
42839
42929
|
return read2.rows;
|
|
42840
42930
|
}
|
|
42841
42931
|
all() {
|
|
42842
|
-
return readFrom(
|
|
42932
|
+
return readFrom(join25(this.dir, BOARD), 0).rows;
|
|
42843
42933
|
}
|
|
42844
42934
|
delivered(delivery) {
|
|
42845
|
-
appendFileSync3(
|
|
42935
|
+
appendFileSync3(join25(this.dir, DELIVERIES), `${JSON.stringify(delivery)}
|
|
42846
42936
|
`);
|
|
42847
42937
|
}
|
|
42848
42938
|
/** Every verdict of the gates, passed or not: the answer to "why did nobody hear about this?". */
|
|
42849
42939
|
log(entry) {
|
|
42850
|
-
appendFileSync3(
|
|
42940
|
+
appendFileSync3(join25(this.dir, "gate.jsonl"), `${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), ...entry })}
|
|
42851
42941
|
`);
|
|
42852
42942
|
}
|
|
42853
42943
|
deliveries() {
|
|
42854
|
-
return readFrom(
|
|
42944
|
+
return readFrom(join25(this.dir, DELIVERIES), 0).rows;
|
|
42855
42945
|
}
|
|
42856
42946
|
relate(row) {
|
|
42857
|
-
appendFileSync3(
|
|
42947
|
+
appendFileSync3(join25(this.dir, RELATIONS), `${JSON.stringify(row)}
|
|
42858
42948
|
`);
|
|
42859
42949
|
}
|
|
42860
42950
|
relations() {
|
|
42861
|
-
return readFrom(
|
|
42951
|
+
return readFrom(join25(this.dir, RELATIONS), 0).rows;
|
|
42862
42952
|
}
|
|
42863
42953
|
relationOffset = 0;
|
|
42864
42954
|
/** Relations appended since the last call on this instance. */
|
|
42865
42955
|
freshRelations() {
|
|
42866
|
-
const read2 = readFrom(
|
|
42956
|
+
const read2 = readFrom(join25(this.dir, RELATIONS), this.relationOffset);
|
|
42867
42957
|
this.relationOffset = read2.offset;
|
|
42868
42958
|
return read2.rows;
|
|
42869
42959
|
}
|
|
@@ -42871,7 +42961,7 @@ var Board = class {
|
|
|
42871
42961
|
gateRows = 0;
|
|
42872
42962
|
/** How many verdicts the gates have given so far. Counted incrementally: the log only grows. */
|
|
42873
42963
|
judged() {
|
|
42874
|
-
const read2 = readFrom(
|
|
42964
|
+
const read2 = readFrom(join25(this.dir, "gate.jsonl"), this.gateOffset);
|
|
42875
42965
|
this.gateOffset = read2.offset;
|
|
42876
42966
|
this.gateRows += read2.rows.length;
|
|
42877
42967
|
return this.gateRows;
|
|
@@ -42953,10 +43043,10 @@ var import_pi_tui3 = __toESM(require_pi_tui(), 1);
|
|
|
42953
43043
|
var import_typebox6 = __toESM(require_typebox(), 1);
|
|
42954
43044
|
import { spawn as spawn6 } from "node:child_process";
|
|
42955
43045
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
42956
|
-
import { existsSync as
|
|
43046
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
42957
43047
|
import { mkdtemp, readFile as readFile2, rm as rm4, writeFile as writeFile2 } from "node:fs/promises";
|
|
42958
43048
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
42959
|
-
import { basename as basename6, join as
|
|
43049
|
+
import { basename as basename6, join as join29 } from "node:path";
|
|
42960
43050
|
|
|
42961
43051
|
// packages/kyrn-judge/src/decisions/swarm-routing.ts
|
|
42962
43052
|
var SCORES = {
|
|
@@ -43021,13 +43111,13 @@ var swarmRouting = defineDecision({
|
|
|
43021
43111
|
import { randomBytes } from "node:crypto";
|
|
43022
43112
|
import { mkdirSync as mkdirSync12, readFileSync as readFileSync14, writeFileSync as writeFileSync9 } from "node:fs";
|
|
43023
43113
|
import { rm as rm2 } from "node:fs/promises";
|
|
43024
|
-
import { join as
|
|
43114
|
+
import { join as join27 } from "node:path";
|
|
43025
43115
|
|
|
43026
43116
|
// packages/kyrn-judge/src/swarm/worktree.ts
|
|
43027
43117
|
import { spawn as spawn5 } from "node:child_process";
|
|
43028
|
-
import { existsSync as
|
|
43118
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
43029
43119
|
import { chmod, copyFile, lstat, mkdir, readdir, readFile, readlink, rm, symlink, writeFile } from "node:fs/promises";
|
|
43030
|
-
import { dirname as
|
|
43120
|
+
import { dirname as dirname6, join as join26 } from "node:path";
|
|
43031
43121
|
function gitArgs(args, platform = process.platform) {
|
|
43032
43122
|
return [
|
|
43033
43123
|
"-c",
|
|
@@ -43109,7 +43199,7 @@ async function checkRepo(run2, cwd) {
|
|
|
43109
43199
|
if (where2.code !== 0) return { ok: false, problem: "not-a-repo", message: lastLine(where2.stderr) };
|
|
43110
43200
|
if (head.code !== 0) return { ok: false, problem: "no-commit", message: "the repository has no commits yet" };
|
|
43111
43201
|
const [root, gitDir, prefix = ""] = text5(where2).replace(/\n$/, "").split("\n");
|
|
43112
|
-
const busy = BUSY.find(([name]) =>
|
|
43202
|
+
const busy = BUSY.find(([name]) => existsSync12(join26(gitDir, name)));
|
|
43113
43203
|
if (busy) return { ok: false, problem: "busy", message: `${busy[1]} is in progress in this repository` };
|
|
43114
43204
|
return { ok: true, repo: { root, gitDir, prefix, head: text5(head).trim() } };
|
|
43115
43205
|
}
|
|
@@ -43132,14 +43222,14 @@ async function copyUntracked(from, to, paths, maxBytes) {
|
|
|
43132
43222
|
for (const path of paths) {
|
|
43133
43223
|
if (path.endsWith("/")) continue;
|
|
43134
43224
|
try {
|
|
43135
|
-
const stat = await lstat(
|
|
43136
|
-
await mkdir(
|
|
43137
|
-
if (stat.isSymbolicLink()) await symlink(await readlink(
|
|
43225
|
+
const stat = await lstat(join26(from, path));
|
|
43226
|
+
await mkdir(dirname6(join26(to, path)), { recursive: true });
|
|
43227
|
+
if (stat.isSymbolicLink()) await symlink(await readlink(join26(from, path)), join26(to, path));
|
|
43138
43228
|
else if (!stat.isFile()) continue;
|
|
43139
43229
|
else if (stat.size > maxBytes) {
|
|
43140
43230
|
report3.skipped.push(path);
|
|
43141
43231
|
continue;
|
|
43142
|
-
} else await copyFile(
|
|
43232
|
+
} else await copyFile(join26(from, path), join26(to, path));
|
|
43143
43233
|
report3.untracked++;
|
|
43144
43234
|
} catch {
|
|
43145
43235
|
report3.skipped.push(path);
|
|
@@ -43151,7 +43241,7 @@ async function createWorktree(run2, options) {
|
|
|
43151
43241
|
const { repo, dir, branch, signal } = options;
|
|
43152
43242
|
const added = await run2(["worktree", "add", "-b", branch, dir, repo.head], { cwd: repo.root, signal });
|
|
43153
43243
|
if (added.code !== 0) return { ok: false, message: `git worktree add failed: ${lastLine(added.stderr)}` };
|
|
43154
|
-
const worktree = { repoRoot: repo.root, dir, branch, base: "", cwd:
|
|
43244
|
+
const worktree = { repoRoot: repo.root, dir, branch, base: "", cwd: join26(dir, repo.prefix) };
|
|
43155
43245
|
const fail = async (message) => {
|
|
43156
43246
|
await removeWorktree(run2, worktree);
|
|
43157
43247
|
return { ok: false, message };
|
|
@@ -43256,11 +43346,11 @@ async function removeWorktree(run2, worktree) {
|
|
|
43256
43346
|
const problems = [];
|
|
43257
43347
|
const cwd = worktree.repoRoot;
|
|
43258
43348
|
let removed = await run2(["worktree", "remove", "--force", worktree.dir], { cwd });
|
|
43259
|
-
if (removed.code !== 0 ||
|
|
43349
|
+
if (removed.code !== 0 || existsSync12(worktree.dir)) {
|
|
43260
43350
|
await rm(worktree.dir, { recursive: true, force: true, maxRetries: 8, retryDelay: 250 }).catch(() => void 0);
|
|
43261
43351
|
removed = await run2(["worktree", "remove", "--force", worktree.dir], { cwd });
|
|
43262
43352
|
if (removed.code !== 0) await run2(["worktree", "prune"], { cwd });
|
|
43263
|
-
if (
|
|
43353
|
+
if (existsSync12(worktree.dir)) problems.push(`could not delete ${worktree.dir}`);
|
|
43264
43354
|
}
|
|
43265
43355
|
const listed2 = await run2(["branch", "--list", worktree.branch], { cwd });
|
|
43266
43356
|
if (text5(listed2).trim()) {
|
|
@@ -43271,8 +43361,8 @@ async function removeWorktree(run2, worktree) {
|
|
|
43271
43361
|
}
|
|
43272
43362
|
var markerPath = (dir) => `${dir}.json`;
|
|
43273
43363
|
async function writeMarker(marker) {
|
|
43274
|
-
await mkdir(
|
|
43275
|
-
await chmod(
|
|
43364
|
+
await mkdir(dirname6(marker.dir), { recursive: true });
|
|
43365
|
+
await chmod(dirname6(marker.dir), 448).catch(() => void 0);
|
|
43276
43366
|
await writeFile(markerPath(marker.dir), JSON.stringify(marker), { mode: 384 });
|
|
43277
43367
|
}
|
|
43278
43368
|
var RUN_DIR = /^kyrn-swarm-[\w-]+$/;
|
|
@@ -43292,9 +43382,9 @@ async function sweepStaleWorktrees(run2, options) {
|
|
|
43292
43382
|
const swept = [];
|
|
43293
43383
|
const runs = await readdir(options.area).catch(() => []);
|
|
43294
43384
|
for (const name of runs.filter((entry) => RUN_DIR.test(entry))) {
|
|
43295
|
-
const entries = await readdir(
|
|
43385
|
+
const entries = await readdir(join26(options.area, name)).catch(() => []);
|
|
43296
43386
|
for (const file of entries.filter((entry) => MARKER.test(entry))) {
|
|
43297
|
-
const path =
|
|
43387
|
+
const path = join26(options.area, name, file);
|
|
43298
43388
|
let marker;
|
|
43299
43389
|
try {
|
|
43300
43390
|
marker = JSON.parse(await readFile(path, "utf8"));
|
|
@@ -43304,9 +43394,9 @@ async function sweepStaleWorktrees(run2, options) {
|
|
|
43304
43394
|
if (markerPath(marker.dir) !== path || typeof marker.repoRoot !== "string") continue;
|
|
43305
43395
|
const stale = marker.released || !alive(marker.pid) || now - marker.createdAt > maxAge;
|
|
43306
43396
|
if (!stale) continue;
|
|
43307
|
-
if (
|
|
43397
|
+
if (existsSync12(marker.repoRoot)) await removeWorktree(run2, marker);
|
|
43308
43398
|
else await rm(marker.dir, { recursive: true, force: true }).catch(() => void 0);
|
|
43309
|
-
if (!
|
|
43399
|
+
if (!existsSync12(marker.dir)) {
|
|
43310
43400
|
await rm(path, { force: true }).catch(() => void 0);
|
|
43311
43401
|
swept.push(marker);
|
|
43312
43402
|
}
|
|
@@ -43327,7 +43417,7 @@ var PatchStore = class {
|
|
|
43327
43417
|
const record4 = {
|
|
43328
43418
|
...details,
|
|
43329
43419
|
id,
|
|
43330
|
-
path:
|
|
43420
|
+
path: join27(dir, `${id}.patch`),
|
|
43331
43421
|
createdAt: Date.now(),
|
|
43332
43422
|
status: "ready"
|
|
43333
43423
|
};
|
|
@@ -43423,7 +43513,7 @@ async function applyPatch(run2, options) {
|
|
|
43423
43513
|
const touched = [...new Set(options.files.flatMap((file) => file.from ? [file.from, file.path] : [file.path]))];
|
|
43424
43514
|
const scratch = [];
|
|
43425
43515
|
const attempt = async (cached) => {
|
|
43426
|
-
const index =
|
|
43516
|
+
const index = join27(options.scratchDir, `index-${randomBytes(4).toString("hex")}`);
|
|
43427
43517
|
scratch.push(index, `${index}.lock`);
|
|
43428
43518
|
const env = { GIT_INDEX_FILE: index };
|
|
43429
43519
|
const input = Buffer.from(touched.map((path) => `${path}\0`).join(""), "utf8");
|
|
@@ -43617,7 +43707,7 @@ function swarmText(snapshot2, options) {
|
|
|
43617
43707
|
var import_typebox5 = __toESM(require_typebox(), 1);
|
|
43618
43708
|
import { rm as rm3 } from "node:fs/promises";
|
|
43619
43709
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
43620
|
-
import { basename as basename5, dirname as
|
|
43710
|
+
import { basename as basename5, dirname as dirname7, join as join28 } from "node:path";
|
|
43621
43711
|
|
|
43622
43712
|
// packages/kyrn-judge/src/decisions/swarm-patch.ts
|
|
43623
43713
|
var MAX_JUDGED_FILES = 12;
|
|
@@ -43724,7 +43814,7 @@ var Isolation = class {
|
|
|
43724
43814
|
if (index === void 0) return runner(task, assignment, signal, env, observer);
|
|
43725
43815
|
const outcome = { isolated: false, notes: [] };
|
|
43726
43816
|
outcomes.set(task, outcome);
|
|
43727
|
-
const dir =
|
|
43817
|
+
const dir = join28(context.runDir, `w${index}`);
|
|
43728
43818
|
const marker = {
|
|
43729
43819
|
repoRoot: context.repo.root,
|
|
43730
43820
|
dir,
|
|
@@ -43777,7 +43867,7 @@ You work in an isolated copy of the repository (${worktree.dir}). Use paths rela
|
|
|
43777
43867
|
}));
|
|
43778
43868
|
if (!collected.ok) outcome.notes.push(`Its changes could not be collected: ${collected.message}`);
|
|
43779
43869
|
else if (collected.summary.files.length > 0) {
|
|
43780
|
-
outcome.patch = this.store.save(
|
|
43870
|
+
outcome.patch = this.store.save(join28(context.runDir, "patches"), collected.patch, {
|
|
43781
43871
|
task: task.title,
|
|
43782
43872
|
role: assignment.agent?.name,
|
|
43783
43873
|
repoRoot: context.repo.root,
|
|
@@ -43914,7 +44004,7 @@ ${statLines(record4.summary, 200).join("\n")}`);
|
|
|
43914
44004
|
patchPath: record4.path,
|
|
43915
44005
|
files: record4.summary.files,
|
|
43916
44006
|
onConflict: params.conflicts ?? "abort",
|
|
43917
|
-
scratchDir:
|
|
44007
|
+
scratchDir: join28(dirname7(record4.path), "scratch"),
|
|
43918
44008
|
signal
|
|
43919
44009
|
});
|
|
43920
44010
|
const details = { id: record4.id, result };
|
|
@@ -44030,7 +44120,7 @@ async function routeTasks(runtime, inputs, signal) {
|
|
|
44030
44120
|
}
|
|
44031
44121
|
function piInvocation(args) {
|
|
44032
44122
|
const script = process.argv[1];
|
|
44033
|
-
if (script &&
|
|
44123
|
+
if (script && existsSync13(script)) return { command: process.execPath, args: [...process.execArgv, script, ...args] };
|
|
44034
44124
|
const generic = /^(node|bun)(\.exe)?$/.test(basename6(process.execPath).toLowerCase());
|
|
44035
44125
|
return generic ? { command: "pi", args } : { command: process.execPath, args };
|
|
44036
44126
|
}
|
|
@@ -44088,7 +44178,7 @@ function settledEnv(runtime) {
|
|
|
44088
44178
|
return env;
|
|
44089
44179
|
}
|
|
44090
44180
|
function frameOutPath(dir, index) {
|
|
44091
|
-
return
|
|
44181
|
+
return join29(dir, "control", `frame-${index}.json`);
|
|
44092
44182
|
}
|
|
44093
44183
|
async function readFrameOut(path) {
|
|
44094
44184
|
try {
|
|
@@ -44107,8 +44197,8 @@ var spawnRunner = async (task, assignment, signal, env, observer) => {
|
|
|
44107
44197
|
let promptDir;
|
|
44108
44198
|
let promptPath;
|
|
44109
44199
|
if (assignment.agent?.systemPrompt) {
|
|
44110
|
-
promptDir = await mkdtemp(
|
|
44111
|
-
promptPath =
|
|
44200
|
+
promptDir = await mkdtemp(join29(tmpdir5(), "kyrn-agent-"));
|
|
44201
|
+
promptPath = join29(promptDir, `${assignment.agent.name}.md`);
|
|
44112
44202
|
await writeFile2(promptPath, assignment.agent.systemPrompt, { encoding: "utf8", mode: 384 });
|
|
44113
44203
|
}
|
|
44114
44204
|
try {
|
|
@@ -44319,7 +44409,7 @@ function registerSwarm(runtime, runner = spawnRunner) {
|
|
|
44319
44409
|
const { pi } = runtime;
|
|
44320
44410
|
const isolation = new Isolation(runtime, options);
|
|
44321
44411
|
isolation.registerTool();
|
|
44322
|
-
const agents = () => loadAgents(options.agentsDir ||
|
|
44412
|
+
const agents = () => loadAgents(options.agentsDir || join29((0, import_pi_coding_agent7.getAgentDir)(), "agents"));
|
|
44323
44413
|
const usable = () => {
|
|
44324
44414
|
const known = new Set(pi.getAllTools().map((tool) => tool.name));
|
|
44325
44415
|
return agents().filter((agent) => !agent.tools || agent.tools.some((tool) => known.has(tool)));
|
|
@@ -44422,7 +44512,7 @@ function registerSwarm(runtime, runner = spawnRunner) {
|
|
|
44422
44512
|
routedBy: named ? "caller" : judged ? "judge" : "default"
|
|
44423
44513
|
};
|
|
44424
44514
|
});
|
|
44425
|
-
const runDir =
|
|
44515
|
+
const runDir = join29(tmpdir5(), `kyrn-swarm-${randomUUID5().slice(0, 8)}`);
|
|
44426
44516
|
const isolated = /* @__PURE__ */ new Map();
|
|
44427
44517
|
tasks.forEach((task, index) => {
|
|
44428
44518
|
const asked = params.tasks[index].isolation ?? (params.chain ? "none" : void 0);
|
|
@@ -44512,7 +44602,7 @@ ${checklist}` : ""}${isolation.describe(outcomesOfIsolation.get(task))}`;
|
|
|
44512
44602
|
en: "List the subagent roles the delegate tool can use, and where to add your own"
|
|
44513
44603
|
}),
|
|
44514
44604
|
handler: async (_args, ctx) => {
|
|
44515
|
-
const dir = options.agentsDir ||
|
|
44605
|
+
const dir = options.agentsDir || join29((0, import_pi_coding_agent7.getAgentDir)(), "agents");
|
|
44516
44606
|
const ladder = options.models.length > 0 ? options.models.join(" < ") : "the session's current model";
|
|
44517
44607
|
ctx.ui.notify(
|
|
44518
44608
|
[
|
|
@@ -44958,9 +45048,9 @@ function registerHive(runtime, runner = spawnRunner) {
|
|
|
44958
45048
|
const names = uniqueNames(asked.map((bee) => bee.name));
|
|
44959
45049
|
const bees = asked.map((bee, at) => ({ ...bee, name: names[at] }));
|
|
44960
45050
|
announceRouting(onUpdate, bees.length);
|
|
44961
|
-
const dir =
|
|
45051
|
+
const dir = join30(tmpdir6(), `kyrn-hive-${randomUUID6().slice(0, 8)}`);
|
|
44962
45052
|
const board = new Board(dir);
|
|
44963
|
-
const roles = new Map(loadAgents(
|
|
45053
|
+
const roles = new Map(loadAgents(join30((0, import_pi_coding_agent8.getAgentDir)(), "agents")).map((agent) => [agent.name, agent]));
|
|
44964
45054
|
const swarm = runtime.options("swarm", { enabled: true, models: [] });
|
|
44965
45055
|
const ladder = options.models.length > 0 ? options.models : swarm.models;
|
|
44966
45056
|
const current = ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : void 0;
|
|
@@ -45158,7 +45248,7 @@ ${reports[at]}`;
|
|
|
45158
45248
|
}),
|
|
45159
45249
|
`## Hive board: ${counts}
|
|
45160
45250
|
${sections.join("\n")}
|
|
45161
|
-
(every verdict of the gates: ${
|
|
45251
|
+
(every verdict of the gates: ${join30(dir, "gate.jsonl")})`
|
|
45162
45252
|
].join("\n\n");
|
|
45163
45253
|
return {
|
|
45164
45254
|
content: [{ type: "text", text: text9 }],
|
|
@@ -45306,7 +45396,7 @@ var import_pi_tui4 = __toESM(require_pi_tui(), 1);
|
|
|
45306
45396
|
// packages/kyrn-judge/src/import/index.ts
|
|
45307
45397
|
import { mkdirSync as mkdirSync13, readdirSync as readdirSync6, readFileSync as readFileSync16, realpathSync as realpathSync3, renameSync as renameSync7, statSync as statSync11, writeFileSync as writeFileSync11 } from "node:fs";
|
|
45308
45398
|
import { homedir as homedir7 } from "node:os";
|
|
45309
|
-
import { join as
|
|
45399
|
+
import { join as join33 } from "node:path";
|
|
45310
45400
|
|
|
45311
45401
|
// packages/kyrn-judge/src/import/claude-code.ts
|
|
45312
45402
|
import { statSync as statSync8 } from "node:fs";
|
|
@@ -45430,7 +45520,7 @@ function list2(value) {
|
|
|
45430
45520
|
import { createHash as createHash5, randomBytes as randomBytes2, randomUUID as randomUUID7 } from "node:crypto";
|
|
45431
45521
|
import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync5, renameSync as renameSync6, rmSync as rmSync7, statSync as statSync7, writeSync } from "node:fs";
|
|
45432
45522
|
import { homedir as homedir5 } from "node:os";
|
|
45433
|
-
import { isAbsolute as isAbsolute4, join as
|
|
45523
|
+
import { isAbsolute as isAbsolute4, join as join31, resolve as resolve5 } from "node:path";
|
|
45434
45524
|
var TOOL_NAMES = {
|
|
45435
45525
|
"claude-code": "Claude Code",
|
|
45436
45526
|
codex: "Codex",
|
|
@@ -45478,7 +45568,7 @@ function uuidv7(ms = Date.now()) {
|
|
|
45478
45568
|
}
|
|
45479
45569
|
function expand(path) {
|
|
45480
45570
|
if (path === "~") return homedir5();
|
|
45481
|
-
if (path.startsWith("~/")) return
|
|
45571
|
+
if (path.startsWith("~/")) return join31(homedir5(), path.slice(2));
|
|
45482
45572
|
return path;
|
|
45483
45573
|
}
|
|
45484
45574
|
function absolute(path, base = process.cwd()) {
|
|
@@ -45487,13 +45577,13 @@ function absolute(path, base = process.cwd()) {
|
|
|
45487
45577
|
}
|
|
45488
45578
|
function defaultSessionDir(cwd, agentDir) {
|
|
45489
45579
|
const safe = `--${absolute(cwd).replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
45490
|
-
return
|
|
45580
|
+
return join31(absolute(agentDir), "sessions", safe);
|
|
45491
45581
|
}
|
|
45492
45582
|
function sessionDirFor(cwd, store) {
|
|
45493
45583
|
return store.sessionDir ? absolute(store.sessionDir) : defaultSessionDir(cwd, store.agentDir);
|
|
45494
45584
|
}
|
|
45495
45585
|
function sessionsRoot(store) {
|
|
45496
|
-
return store.sessionDir ? absolute(store.sessionDir) :
|
|
45586
|
+
return store.sessionDir ? absolute(store.sessionDir) : join31(absolute(store.agentDir), "sessions");
|
|
45497
45587
|
}
|
|
45498
45588
|
function sessionFileName(started, id) {
|
|
45499
45589
|
return `${started.replace(/[:.]/g, "-")}_${id}.jsonl`;
|
|
@@ -45533,7 +45623,7 @@ function findImports(store) {
|
|
|
45533
45623
|
return;
|
|
45534
45624
|
}
|
|
45535
45625
|
for (const name of names) {
|
|
45536
|
-
const path =
|
|
45626
|
+
const path = join31(dir, name);
|
|
45537
45627
|
if (name.endsWith(".jsonl")) files.push(path);
|
|
45538
45628
|
else if (depth > 0) {
|
|
45539
45629
|
try {
|
|
@@ -46800,9 +46890,9 @@ import { execFileSync } from "node:child_process";
|
|
|
46800
46890
|
import { statSync as statSync10 } from "node:fs";
|
|
46801
46891
|
import { createRequire } from "node:module";
|
|
46802
46892
|
import { homedir as homedir6 } from "node:os";
|
|
46803
|
-
import { join as
|
|
46893
|
+
import { join as join32 } from "node:path";
|
|
46804
46894
|
function zcodeDatabase(home = homedir6()) {
|
|
46805
|
-
return
|
|
46895
|
+
return join32(home, ".zcode", "cli", "db", "db.sqlite");
|
|
46806
46896
|
}
|
|
46807
46897
|
function zcodeSource(database, id) {
|
|
46808
46898
|
return `${database}#${id}`;
|
|
@@ -47301,10 +47391,10 @@ function describeCodex(path) {
|
|
|
47301
47391
|
return { id: id ?? fromName ?? "", cwd, title: title ?? command ?? "", started, subAgent };
|
|
47302
47392
|
}
|
|
47303
47393
|
function claudeProjectsDir(env = process.env, home = homedir7()) {
|
|
47304
|
-
return
|
|
47394
|
+
return join33(env.CLAUDE_CONFIG_DIR ? absolute(env.CLAUDE_CONFIG_DIR) : join33(home, ".claude"), "projects");
|
|
47305
47395
|
}
|
|
47306
47396
|
function codexSessionsDir(env = process.env, home = homedir7()) {
|
|
47307
|
-
return
|
|
47397
|
+
return join33(env.CODEX_HOME ? absolute(env.CODEX_HOME) : join33(home, ".codex"), "sessions");
|
|
47308
47398
|
}
|
|
47309
47399
|
function sameFolder(a, b) {
|
|
47310
47400
|
const canonical2 = (dir) => {
|
|
@@ -47326,7 +47416,7 @@ function jsonlFiles(dir, depth) {
|
|
|
47326
47416
|
}
|
|
47327
47417
|
const files = [];
|
|
47328
47418
|
for (const name of names.sort()) {
|
|
47329
|
-
const path =
|
|
47419
|
+
const path = join33(dir, name);
|
|
47330
47420
|
if (name.endsWith(".jsonl")) files.push(path);
|
|
47331
47421
|
else if (depth > 0 && !name.startsWith(".")) {
|
|
47332
47422
|
try {
|
|
@@ -47337,7 +47427,7 @@ function jsonlFiles(dir, depth) {
|
|
|
47337
47427
|
}
|
|
47338
47428
|
return files;
|
|
47339
47429
|
}
|
|
47340
|
-
var checksFile = (store) =>
|
|
47430
|
+
var checksFile = (store) => join33(absolute(store.agentDir), "import-checks.json");
|
|
47341
47431
|
function readChecks(store) {
|
|
47342
47432
|
try {
|
|
47343
47433
|
const checks = record(JSON.parse(readFileSync16(checksFile(store), "utf8"))) ?? {};
|
|
@@ -47373,7 +47463,7 @@ function listConversations(options = {}) {
|
|
|
47373
47463
|
} catch {
|
|
47374
47464
|
}
|
|
47375
47465
|
for (const project of projects) {
|
|
47376
|
-
for (const path of jsonlFiles(
|
|
47466
|
+
for (const path of jsonlFiles(join33(claudeProjects, project), 0)) candidates.push({ tool: "claude-code", path });
|
|
47377
47467
|
}
|
|
47378
47468
|
for (const path of jsonlFiles(codexSessions, 4)) candidates.push({ tool: "codex", path });
|
|
47379
47469
|
const imports = options.store ? findImports(options.store) : [];
|
|
@@ -47525,7 +47615,7 @@ async function importOne(path, options, imports, checks) {
|
|
|
47525
47615
|
if (earlier) converted = await read(tool, source, readOptions());
|
|
47526
47616
|
const dir = sessionDirFor(converted.cwd, options);
|
|
47527
47617
|
mkdirSync13(dir, { recursive: true });
|
|
47528
|
-
const sessionFile =
|
|
47618
|
+
const sessionFile = join33(dir, sessionFileName(converted.started, converted.sessionId));
|
|
47529
47619
|
writeSessionFile(sessionFile, converted.entries);
|
|
47530
47620
|
imports.push({
|
|
47531
47621
|
sessionFile,
|
|
@@ -47729,11 +47819,11 @@ ${theme.fg("dim", detail)}`, 0, 0));
|
|
|
47729
47819
|
}
|
|
47730
47820
|
|
|
47731
47821
|
// packages/kyrn-judge/src/extension/features/inherit.ts
|
|
47732
|
-
import { isAbsolute as isAbsolute5, join as
|
|
47822
|
+
import { isAbsolute as isAbsolute5, join as join39, resolve as resolve8 } from "node:path";
|
|
47733
47823
|
|
|
47734
47824
|
// packages/kyrn-judge/src/inherit/files.ts
|
|
47735
|
-
import { existsSync as
|
|
47736
|
-
import { dirname as
|
|
47825
|
+
import { existsSync as existsSync14, readdirSync as readdirSync7, readFileSync as readFileSync17, realpathSync as realpathSync4, statSync as statSync12 } from "node:fs";
|
|
47826
|
+
import { dirname as dirname8, join as join34, resolve as resolve6 } from "node:path";
|
|
47737
47827
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
47738
47828
|
function projectChain(projectDir, home) {
|
|
47739
47829
|
const start = resolve6(projectDir);
|
|
@@ -47743,8 +47833,8 @@ function projectChain(projectDir, home) {
|
|
|
47743
47833
|
for (let depth = 0; depth < 32; depth++) {
|
|
47744
47834
|
if (current === homeDir) break;
|
|
47745
47835
|
chain.push(current);
|
|
47746
|
-
if (
|
|
47747
|
-
const parent =
|
|
47836
|
+
if (existsSync14(join34(current, ".git"))) return chain;
|
|
47837
|
+
const parent = dirname8(current);
|
|
47748
47838
|
if (parent === current) break;
|
|
47749
47839
|
current = parent;
|
|
47750
47840
|
}
|
|
@@ -47779,7 +47869,7 @@ function listFiles(dir, extensions, depth = 4) {
|
|
|
47779
47869
|
}
|
|
47780
47870
|
for (const name of names) {
|
|
47781
47871
|
if (name.startsWith(".") || name === "node_modules") continue;
|
|
47782
|
-
const path =
|
|
47872
|
+
const path = join34(dir, name);
|
|
47783
47873
|
let stats;
|
|
47784
47874
|
try {
|
|
47785
47875
|
stats = statSync12(path);
|
|
@@ -47803,7 +47893,7 @@ function canonical(path) {
|
|
|
47803
47893
|
}
|
|
47804
47894
|
|
|
47805
47895
|
// packages/kyrn-judge/src/inherit/rules.ts
|
|
47806
|
-
import { basename as basename9, join as
|
|
47896
|
+
import { basename as basename9, join as join35, relative as relative2 } from "node:path";
|
|
47807
47897
|
|
|
47808
47898
|
// packages/kyrn-judge/src/inherit/frontmatter.ts
|
|
47809
47899
|
function unquote(value) {
|
|
@@ -47963,15 +48053,15 @@ function discoverRules(roots, switches, problems) {
|
|
|
47963
48053
|
const files = [];
|
|
47964
48054
|
const projectDirs = roots.projectTrusted ? projectChain(roots.projectDir, roots.home) : [];
|
|
47965
48055
|
if (switches.claude) {
|
|
47966
|
-
const userDir =
|
|
48056
|
+
const userDir = join35(roots.home, ".claude");
|
|
47967
48057
|
files.push({
|
|
47968
|
-
path:
|
|
48058
|
+
path: join35(userDir, "CLAUDE.md"),
|
|
47969
48059
|
tool: "claude",
|
|
47970
48060
|
scope: "user",
|
|
47971
48061
|
baseDir: roots.projectDir,
|
|
47972
48062
|
alwaysByDefault: true
|
|
47973
48063
|
});
|
|
47974
|
-
for (const path of listFiles(
|
|
48064
|
+
for (const path of listFiles(join35(userDir, "rules"), [".md"])) {
|
|
47975
48065
|
files.push({
|
|
47976
48066
|
path,
|
|
47977
48067
|
tool: "claude",
|
|
@@ -47983,10 +48073,10 @@ function discoverRules(roots, switches, problems) {
|
|
|
47983
48073
|
}
|
|
47984
48074
|
}
|
|
47985
48075
|
if (switches.codex) {
|
|
47986
|
-
const override =
|
|
48076
|
+
const override = join35(roots.home, ".codex", "AGENTS.override.md");
|
|
47987
48077
|
const hasOverride = readText(override, []) !== void 0;
|
|
47988
48078
|
files.push({
|
|
47989
|
-
path: hasOverride ? override :
|
|
48079
|
+
path: hasOverride ? override : join35(roots.home, ".codex", "AGENTS.md"),
|
|
47990
48080
|
tool: "codex",
|
|
47991
48081
|
scope: "user",
|
|
47992
48082
|
baseDir: roots.projectDir,
|
|
@@ -47996,13 +48086,13 @@ function discoverRules(roots, switches, problems) {
|
|
|
47996
48086
|
for (const dir of [...projectDirs].reverse()) {
|
|
47997
48087
|
if (switches.claude) {
|
|
47998
48088
|
files.push({
|
|
47999
|
-
path:
|
|
48089
|
+
path: join35(dir, ".claude", "CLAUDE.md"),
|
|
48000
48090
|
tool: "claude",
|
|
48001
48091
|
scope: "project",
|
|
48002
48092
|
baseDir: dir,
|
|
48003
48093
|
alwaysByDefault: true
|
|
48004
48094
|
});
|
|
48005
|
-
for (const path of listFiles(
|
|
48095
|
+
for (const path of listFiles(join35(dir, ".claude", "rules"), [".md"])) {
|
|
48006
48096
|
files.push({
|
|
48007
48097
|
path,
|
|
48008
48098
|
tool: "claude",
|
|
@@ -48015,13 +48105,13 @@ function discoverRules(roots, switches, problems) {
|
|
|
48015
48105
|
}
|
|
48016
48106
|
if (switches.cursor) {
|
|
48017
48107
|
files.push({
|
|
48018
|
-
path:
|
|
48108
|
+
path: join35(dir, ".cursorrules"),
|
|
48019
48109
|
tool: "cursor",
|
|
48020
48110
|
scope: "project",
|
|
48021
48111
|
baseDir: dir,
|
|
48022
48112
|
alwaysByDefault: true
|
|
48023
48113
|
});
|
|
48024
|
-
for (const path of listFiles(
|
|
48114
|
+
for (const path of listFiles(join35(dir, ".cursor", "rules"), [".mdc", ".md"])) {
|
|
48025
48115
|
files.push({
|
|
48026
48116
|
path,
|
|
48027
48117
|
tool: "cursor",
|
|
@@ -48058,10 +48148,10 @@ function rulesForFile(rules, filePath) {
|
|
|
48058
48148
|
|
|
48059
48149
|
// packages/kyrn-judge/src/inherit/scan.ts
|
|
48060
48150
|
import { mkdirSync as mkdirSync14, readFileSync as readFileSync18, writeFileSync as writeFileSync12 } from "node:fs";
|
|
48061
|
-
import { dirname as
|
|
48151
|
+
import { dirname as dirname9, join as join38 } from "node:path";
|
|
48062
48152
|
|
|
48063
48153
|
// packages/kyrn-judge/src/inherit/mcp-config.ts
|
|
48064
|
-
import { join as
|
|
48154
|
+
import { join as join36, resolve as resolve7 } from "node:path";
|
|
48065
48155
|
|
|
48066
48156
|
// packages/kyrn-judge/src/inherit/json-members.ts
|
|
48067
48157
|
var QUOTE = 34;
|
|
@@ -48503,7 +48593,7 @@ function discoverMcpServers(options, problems) {
|
|
|
48503
48593
|
const inherit = switches.mcp;
|
|
48504
48594
|
let disabledInClaude = /* @__PURE__ */ new Set();
|
|
48505
48595
|
if (inherit && switches.claude) {
|
|
48506
|
-
const path =
|
|
48596
|
+
const path = join36(roots.home, ".claude.json");
|
|
48507
48597
|
const dirs = [resolve7(roots.projectDir), ...chain.slice(1)];
|
|
48508
48598
|
const wanted = new Set(dirs.map((dir) => pathKey(dir, platform)));
|
|
48509
48599
|
const config = parseJson(path, problems, {
|
|
@@ -48528,11 +48618,11 @@ function discoverMcpServers(options, problems) {
|
|
|
48528
48618
|
}
|
|
48529
48619
|
}
|
|
48530
48620
|
if (inherit && switches.cursor) {
|
|
48531
|
-
const path =
|
|
48621
|
+
const path = join36(roots.home, ".cursor", "mcp.json");
|
|
48532
48622
|
add(parseJson(path, problems, { mcpServers: true })?.mcpServers, { source: path, tool: "cursor", scope: "user" });
|
|
48533
48623
|
}
|
|
48534
48624
|
if (inherit && switches.codex) {
|
|
48535
|
-
const path =
|
|
48625
|
+
const path = join36(roots.home, ".codex", "config.toml");
|
|
48536
48626
|
const text9 = readText(path, problems);
|
|
48537
48627
|
if (text9 !== void 0) {
|
|
48538
48628
|
try {
|
|
@@ -48544,11 +48634,11 @@ function discoverMcpServers(options, problems) {
|
|
|
48544
48634
|
}
|
|
48545
48635
|
}
|
|
48546
48636
|
if (inherit) {
|
|
48547
|
-
const userFiles = /* @__PURE__ */ new Set([resolve7(
|
|
48637
|
+
const userFiles = /* @__PURE__ */ new Set([resolve7(join36(roots.home, ".cursor", "mcp.json"))]);
|
|
48548
48638
|
for (const dir of chain) {
|
|
48549
48639
|
const files = [
|
|
48550
|
-
{ path:
|
|
48551
|
-
{ path:
|
|
48640
|
+
{ path: join36(dir, ".mcp.json"), tool: "claude", on: switches.claude },
|
|
48641
|
+
{ path: join36(dir, ".cursor", "mcp.json"), tool: "cursor", on: switches.cursor }
|
|
48552
48642
|
];
|
|
48553
48643
|
for (const file of files) {
|
|
48554
48644
|
if (!file.on || userFiles.has(resolve7(file.path))) continue;
|
|
@@ -48595,9 +48685,9 @@ function expandPlaceholders(value, context) {
|
|
|
48595
48685
|
// packages/kyrn-judge/src/inherit/skills.ts
|
|
48596
48686
|
var import_pi_coding_agent10 = __toESM(require_pi_coding_agent(), 1);
|
|
48597
48687
|
import { readdirSync as readdirSync8, statSync as statSync13 } from "node:fs";
|
|
48598
|
-
import { basename as basename10, join as
|
|
48688
|
+
import { basename as basename10, join as join37 } from "node:path";
|
|
48599
48689
|
function readSkill(dir, problems) {
|
|
48600
|
-
const file =
|
|
48690
|
+
const file = join37(dir, "SKILL.md");
|
|
48601
48691
|
const text9 = readText(file, problems, 512 * 1024);
|
|
48602
48692
|
if (text9 === void 0) return void 0;
|
|
48603
48693
|
let frontmatter;
|
|
@@ -48621,7 +48711,7 @@ function skillsBelow(root, problems, depth = 3) {
|
|
|
48621
48711
|
const skills = [];
|
|
48622
48712
|
for (const name of names) {
|
|
48623
48713
|
if (name.startsWith(".") || name === "node_modules") continue;
|
|
48624
|
-
const dir =
|
|
48714
|
+
const dir = join37(root, name);
|
|
48625
48715
|
try {
|
|
48626
48716
|
if (!statSync13(dir).isDirectory()) continue;
|
|
48627
48717
|
} catch {
|
|
@@ -48638,11 +48728,11 @@ function discoverSkills(roots, switches, problems, piSkillDirs = []) {
|
|
|
48638
48728
|
const sources = [];
|
|
48639
48729
|
if (switches.claude && roots.projectTrusted) {
|
|
48640
48730
|
for (const dir of projectChain(roots.projectDir, roots.home)) {
|
|
48641
|
-
sources.push({ dir:
|
|
48731
|
+
sources.push({ dir: join37(dir, ".claude", "skills"), tool: "claude", scope: "project" });
|
|
48642
48732
|
}
|
|
48643
48733
|
}
|
|
48644
|
-
if (switches.claude) sources.push({ dir:
|
|
48645
|
-
if (switches.codex) sources.push({ dir:
|
|
48734
|
+
if (switches.claude) sources.push({ dir: join37(roots.home, ".claude", "skills"), tool: "claude", scope: "user" });
|
|
48735
|
+
if (switches.codex) sources.push({ dir: join37(roots.home, ".codex", "skills"), tool: "codex", scope: "user" });
|
|
48646
48736
|
const names = /* @__PURE__ */ new Set();
|
|
48647
48737
|
const files = /* @__PURE__ */ new Set();
|
|
48648
48738
|
const quiet = [];
|
|
@@ -48731,7 +48821,7 @@ function inheritanceSummary(scan2) {
|
|
|
48731
48821
|
return `Inherited ${list4(parts)} from ${list4(from)}.`;
|
|
48732
48822
|
}
|
|
48733
48823
|
function inheritStatePath(agentDir) {
|
|
48734
|
-
return
|
|
48824
|
+
return join38(agentDir, "mu", "inherit.json");
|
|
48735
48825
|
}
|
|
48736
48826
|
function readInheritState(agentDir) {
|
|
48737
48827
|
try {
|
|
@@ -48746,7 +48836,7 @@ function readInheritState(agentDir) {
|
|
|
48746
48836
|
}
|
|
48747
48837
|
function writeInheritState(agentDir, state) {
|
|
48748
48838
|
const path = inheritStatePath(agentDir);
|
|
48749
|
-
mkdirSync14(
|
|
48839
|
+
mkdirSync14(dirname9(path), { recursive: true });
|
|
48750
48840
|
writeFileSync12(path, `${JSON.stringify(state, null, " ")}
|
|
48751
48841
|
`);
|
|
48752
48842
|
}
|
|
@@ -48791,9 +48881,9 @@ function inheritedFor(runtime, roots, ctx, own) {
|
|
|
48791
48881
|
mcp: !off && options.mcp
|
|
48792
48882
|
},
|
|
48793
48883
|
own,
|
|
48794
|
-
ownSource:
|
|
48884
|
+
ownSource: join39(roots.agentDir, "mu.json"),
|
|
48795
48885
|
// What pi loads by itself, so that no skill is offered twice.
|
|
48796
|
-
piSkillDirs: [
|
|
48886
|
+
piSkillDirs: [join39(roots.agentDir, "skills"), join39(roots.home, ".agents", "skills")],
|
|
48797
48887
|
env: process.env
|
|
48798
48888
|
});
|
|
48799
48889
|
}
|
|
@@ -49001,12 +49091,12 @@ function looksPoisoned(text9) {
|
|
|
49001
49091
|
var import_pi_coding_agent11 = __toESM(require_pi_coding_agent(), 1);
|
|
49002
49092
|
import { createHash as createHash6 } from "node:crypto";
|
|
49003
49093
|
import { mkdirSync as mkdirSync15, readFileSync as readFileSync19, renameSync as renameSync8, writeFileSync as writeFileSync13 } from "node:fs";
|
|
49004
|
-
import { dirname as
|
|
49094
|
+
import { dirname as dirname10, join as join40 } from "node:path";
|
|
49005
49095
|
var STORE_LIMIT = 2e3;
|
|
49006
49096
|
var VerdictStore = class {
|
|
49007
49097
|
file;
|
|
49008
49098
|
constructor(dir) {
|
|
49009
|
-
this.file =
|
|
49099
|
+
this.file = join40(dir, "tool-descriptions.json");
|
|
49010
49100
|
}
|
|
49011
49101
|
/** By key: the verdict, and when it was kept. */
|
|
49012
49102
|
read() {
|
|
@@ -49036,7 +49126,7 @@ var VerdictStore = class {
|
|
|
49036
49126
|
const newest = [...all].sort(([, a], [, b]) => b.at - a.at).slice(0, STORE_LIMIT);
|
|
49037
49127
|
const flat4 = Object.fromEntries(newest.map(([key, entry]) => [key, { ...entry.verdict, at: entry.at }]));
|
|
49038
49128
|
try {
|
|
49039
|
-
mkdirSync15(
|
|
49129
|
+
mkdirSync15(dirname10(this.file), { recursive: true });
|
|
49040
49130
|
const temp = `${this.file}.${process.pid}.tmp`;
|
|
49041
49131
|
writeFileSync13(temp, `${JSON.stringify({ version: 1, verdicts: flat4 })}
|
|
49042
49132
|
`, { mode: 384 });
|
|
@@ -50812,7 +50902,7 @@ function registerLayaNotice(runtime, skipped, roots, muHome2) {
|
|
|
50812
50902
|
var import_pi_coding_agent12 = __toESM(require_pi_coding_agent(), 1);
|
|
50813
50903
|
import { readFileSync as readFileSync20, statSync as statSync15 } from "node:fs";
|
|
50814
50904
|
import { homedir as homedir8 } from "node:os";
|
|
50815
|
-
import { join as
|
|
50905
|
+
import { join as join41, relative as relative4, resolve as resolve9 } from "node:path";
|
|
50816
50906
|
|
|
50817
50907
|
// packages/kyrn-judge/src/decisions/diagnostics-delivery.ts
|
|
50818
50908
|
var diagnosticsDelivery = defineDecision({
|
|
@@ -50996,7 +51086,7 @@ function formatReport(items, options) {
|
|
|
50996
51086
|
}
|
|
50997
51087
|
|
|
50998
51088
|
// packages/kyrn-judge/src/lsp/manager.ts
|
|
50999
|
-
import { accessSync as accessSync3, constants as constants3, existsSync as
|
|
51089
|
+
import { accessSync as accessSync3, constants as constants3, existsSync as existsSync15, statSync as statSync14 } from "node:fs";
|
|
51000
51090
|
|
|
51001
51091
|
// packages/kyrn-judge/src/lsp/client.ts
|
|
51002
51092
|
import { spawn as spawn7 } from "node:child_process";
|
|
@@ -51971,7 +52061,7 @@ var LspManager = class {
|
|
|
51971
52061
|
}
|
|
51972
52062
|
instanceFor(server, file, cwd) {
|
|
51973
52063
|
if (!server.executable) return void 0;
|
|
51974
|
-
const root = findRoot(file, server.spec.rootMarkers, cwd,
|
|
52064
|
+
const root = findRoot(file, server.spec.rootMarkers, cwd, existsSync15, this.platform);
|
|
51975
52065
|
const key = `${server.spec.id}
|
|
51976
52066
|
${root}`;
|
|
51977
52067
|
let instance = this.instances.get(key);
|
|
@@ -52176,7 +52266,7 @@ function registerLsp(runtime) {
|
|
|
52176
52266
|
if (table && table.cwd === ctx.cwd && !refresh2) return table;
|
|
52177
52267
|
let project;
|
|
52178
52268
|
try {
|
|
52179
|
-
const file =
|
|
52269
|
+
const file = join41(ctx.cwd, import_pi_coding_agent12.CONFIG_DIR_NAME, PROJECT_SERVERS_FILE);
|
|
52180
52270
|
project = JSON.parse(readFileSync20(file, "utf8")).servers;
|
|
52181
52271
|
} catch {
|
|
52182
52272
|
project = void 0;
|
|
@@ -52281,7 +52371,7 @@ function registerLsp(runtime) {
|
|
|
52281
52371
|
const named = raw.startsWith("@") ? raw.slice(1) : raw;
|
|
52282
52372
|
const file = resolve9(
|
|
52283
52373
|
ctx.cwd,
|
|
52284
|
-
named === "~" || named.startsWith("~/") ?
|
|
52374
|
+
named === "~" || named.startsWith("~/") ? join41(homedir8(), named.slice(1)) : named
|
|
52285
52375
|
);
|
|
52286
52376
|
const { servers: specs, trusted } = servers(ctx);
|
|
52287
52377
|
const serving = manager.serving(file, specs, trusted);
|
|
@@ -52434,7 +52524,7 @@ ${report3.text}`,
|
|
|
52434
52524
|
});
|
|
52435
52525
|
if (known.ignoredProjectFile) {
|
|
52436
52526
|
lines2.push(
|
|
52437
|
-
`${
|
|
52527
|
+
`${join41(import_pi_coding_agent12.CONFIG_DIR_NAME, PROJECT_SERVERS_FILE)} configures servers for this project. It's ignored until you trust the project (/trust).`
|
|
52438
52528
|
);
|
|
52439
52529
|
}
|
|
52440
52530
|
for (const problem of known.problems) lines2.push(`problem: ${problem}`);
|
|
@@ -52450,7 +52540,7 @@ ${report3.text}`,
|
|
|
52450
52540
|
// packages/kyrn-judge/src/extension/features/mcp.ts
|
|
52451
52541
|
var import_pi_coding_agent13 = __toESM(require_pi_coding_agent(), 1);
|
|
52452
52542
|
import { homedir as homedir9 } from "node:os";
|
|
52453
|
-
import { join as
|
|
52543
|
+
import { join as join43 } from "node:path";
|
|
52454
52544
|
|
|
52455
52545
|
// packages/kyrn-judge/src/mcp/environment.ts
|
|
52456
52546
|
var INHERITED2 = [
|
|
@@ -52525,7 +52615,7 @@ function capabilityId(serverName) {
|
|
|
52525
52615
|
// packages/kyrn-judge/src/mcp/store.ts
|
|
52526
52616
|
import { createHash as createHash7 } from "node:crypto";
|
|
52527
52617
|
import { mkdirSync as mkdirSync16, readFileSync as readFileSync21, renameSync as renameSync9, writeFileSync as writeFileSync14 } from "node:fs";
|
|
52528
|
-
import { join as
|
|
52618
|
+
import { join as join42, resolve as resolve10 } from "node:path";
|
|
52529
52619
|
var DESCRIPTION_LENGTH2 = 200;
|
|
52530
52620
|
function sorted(map) {
|
|
52531
52621
|
return Object.entries(map).sort(([left], [right]) => left.localeCompare(right));
|
|
@@ -52570,8 +52660,8 @@ var McpStore = class {
|
|
|
52570
52660
|
cache;
|
|
52571
52661
|
approvals;
|
|
52572
52662
|
constructor(dir) {
|
|
52573
|
-
this.cachePath = dir ?
|
|
52574
|
-
this.approvalPath = dir ?
|
|
52663
|
+
this.cachePath = dir ? join42(dir, "mcp-cache.json") : void 0;
|
|
52664
|
+
this.approvalPath = dir ? join42(dir, "mcp-approvals.json") : void 0;
|
|
52575
52665
|
this.cache = readJson(this.cachePath, { version: 1, servers: {} });
|
|
52576
52666
|
this.approvals = readJson(this.approvalPath, { version: 1, projects: {} });
|
|
52577
52667
|
}
|
|
@@ -52651,7 +52741,7 @@ function registerMcp(runtime, roots) {
|
|
|
52651
52741
|
if (!options.enabled) return;
|
|
52652
52742
|
const { pi, catalog } = runtime;
|
|
52653
52743
|
const entries = /* @__PURE__ */ new Map();
|
|
52654
|
-
const store = new McpStore(roots ?
|
|
52744
|
+
const store = new McpStore(roots ? join43(roots.agentDir, "mu") : void 0);
|
|
52655
52745
|
let scan2;
|
|
52656
52746
|
const capabilityOf2 = (entry) => ({
|
|
52657
52747
|
id: entry.id,
|
|
@@ -52923,7 +53013,7 @@ ${block.text}` };
|
|
|
52923
53013
|
// packages/kyrn-judge/src/extension/features/memory.ts
|
|
52924
53014
|
var import_typebox10 = __toESM(require_typebox(), 1);
|
|
52925
53015
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
52926
|
-
import { basename as basename12, join as
|
|
53016
|
+
import { basename as basename12, join as join44 } from "node:path";
|
|
52927
53017
|
|
|
52928
53018
|
// packages/kyrn-judge/src/decisions/memory.ts
|
|
52929
53019
|
function describeLesson(lesson) {
|
|
@@ -53222,7 +53312,7 @@ function turnDigest(turn) {
|
|
|
53222
53312
|
|
|
53223
53313
|
// packages/kyrn-judge/src/memory/store.ts
|
|
53224
53314
|
import { appendFileSync as appendFileSync4, closeSync as closeSync5, fstatSync as fstatSync3, mkdirSync as mkdirSync17, openSync as openSync5, readFileSync as readFileSync22, readSync as readSync4 } from "node:fs";
|
|
53225
|
-
import { dirname as
|
|
53315
|
+
import { dirname as dirname11 } from "node:path";
|
|
53226
53316
|
var KINDS4 = ["correction", "preference", "pitfall", "workaround", "fact"];
|
|
53227
53317
|
var ORIGINS = ["user", "outcome", "model", "subagent", "command"];
|
|
53228
53318
|
var STATUSES = ["active", "retired", "superseded"];
|
|
@@ -53326,7 +53416,7 @@ function endsOpen(path) {
|
|
|
53326
53416
|
}
|
|
53327
53417
|
}
|
|
53328
53418
|
function writeLesson(path, line2) {
|
|
53329
|
-
mkdirSync17(
|
|
53419
|
+
mkdirSync17(dirname11(path), { recursive: true });
|
|
53330
53420
|
appendFileSync4(path, `${endsOpen(path) ? "\n" : ""}${JSON.stringify(line2)}
|
|
53331
53421
|
`);
|
|
53332
53422
|
}
|
|
@@ -53521,7 +53611,7 @@ function registerMemory(runtime, roots) {
|
|
|
53521
53611
|
if (!options.enabled || process.env.KYRN_SWARM_DEPTH) return;
|
|
53522
53612
|
const { pi } = runtime;
|
|
53523
53613
|
const learns = (ctx) => options.unattendedWrites || !isUnattended(ctx);
|
|
53524
|
-
const store = new LessonStore(options.path || (roots ?
|
|
53614
|
+
const store = new LessonStore(options.path || (roots ? join44(roots.agentDir, "mu", "lessons.jsonl") : void 0));
|
|
53525
53615
|
const now = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
53526
53616
|
const placeOf = (ctx) => ({
|
|
53527
53617
|
cwd: ctx.cwd,
|
|
@@ -55065,7 +55155,7 @@ ${outcome.diff}`),
|
|
|
55065
55155
|
|
|
55066
55156
|
// packages/kyrn-judge/src/packs/commit.ts
|
|
55067
55157
|
import { readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
|
|
55068
|
-
import { join as
|
|
55158
|
+
import { join as join45 } from "node:path";
|
|
55069
55159
|
|
|
55070
55160
|
// packages/kyrn-judge/src/packs/git.ts
|
|
55071
55161
|
var INHERITED3 = ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR", "GIT_PREFIX"];
|
|
@@ -55551,7 +55641,7 @@ async function applyPlan(git2, repo, change, plan2, signal) {
|
|
|
55551
55641
|
undone: []
|
|
55552
55642
|
};
|
|
55553
55643
|
}
|
|
55554
|
-
const indexPath =
|
|
55644
|
+
const indexPath = join45(repo.gitDir, "index");
|
|
55555
55645
|
const savedIndex = await readFile4(indexPath).catch(() => void 0);
|
|
55556
55646
|
const made = [];
|
|
55557
55647
|
const applied = /* @__PURE__ */ new Map();
|
|
@@ -55734,12 +55824,12 @@ function report2(outcome) {
|
|
|
55734
55824
|
var import_typebox12 = __toESM(require_typebox(), 1);
|
|
55735
55825
|
import { realpathSync as realpathSync5 } from "node:fs";
|
|
55736
55826
|
import { readFile as readFile5, writeFile as writeFile6 } from "node:fs/promises";
|
|
55737
|
-
import { basename as basename13, dirname as
|
|
55827
|
+
import { basename as basename13, dirname as dirname12, isAbsolute as isAbsolute6, join as join47, relative as relative5 } from "node:path";
|
|
55738
55828
|
|
|
55739
55829
|
// packages/kyrn-judge/src/packs/conflicts.ts
|
|
55740
55830
|
import { mkdtemp as mkdtemp2, rm as rm5, writeFile as writeFile5 } from "node:fs/promises";
|
|
55741
55831
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
55742
|
-
import { join as
|
|
55832
|
+
import { join as join46 } from "node:path";
|
|
55743
55833
|
var START = /^<{7}(?: (.*))?$/;
|
|
55744
55834
|
var BASE = /^\|{7}(?: .*)?$/;
|
|
55745
55835
|
var MIDDLE = /^={7}$/;
|
|
@@ -55849,9 +55939,9 @@ async function diff3Of(git2, cwd, path) {
|
|
|
55849
55939
|
if (shown2.code !== 0) return void 0;
|
|
55850
55940
|
sides.push(shown2.stdout);
|
|
55851
55941
|
}
|
|
55852
|
-
const dir = await mkdtemp2(
|
|
55942
|
+
const dir = await mkdtemp2(join46(tmpdir7(), "mu-conflict-"));
|
|
55853
55943
|
try {
|
|
55854
|
-
const files = ["ours", "base", "theirs"].map((name) =>
|
|
55944
|
+
const files = ["ours", "base", "theirs"].map((name) => join46(dir, name));
|
|
55855
55945
|
await Promise.all(files.map((file, index) => writeFile5(file, sides[index])));
|
|
55856
55946
|
const merged = await git2(["merge-file", "-p", "--diff3", "-L", "ours", "-L", "base", "-L", "theirs", ...files], {
|
|
55857
55947
|
cwd
|
|
@@ -55871,8 +55961,8 @@ function real(path) {
|
|
|
55871
55961
|
try {
|
|
55872
55962
|
return realpathSync5.native(path);
|
|
55873
55963
|
} catch {
|
|
55874
|
-
const parent =
|
|
55875
|
-
return parent === path ? path :
|
|
55964
|
+
const parent = dirname12(path);
|
|
55965
|
+
return parent === path ? path : join47(real(parent), basename13(path));
|
|
55876
55966
|
}
|
|
55877
55967
|
}
|
|
55878
55968
|
var NEXT = "Committing, and `git merge --continue` / `git rebase --continue`, are the user's to run: tell them, do not run them.";
|
|
@@ -55889,7 +55979,7 @@ function conflictsPack(shared, options) {
|
|
|
55889
55979
|
return { repo, files };
|
|
55890
55980
|
};
|
|
55891
55981
|
const inRepo = (root, cwd, path) => {
|
|
55892
|
-
const inside2 = relative5(real(root), real(isAbsolute6(path) ? path :
|
|
55982
|
+
const inside2 = relative5(real(root), real(isAbsolute6(path) ? path : join47(cwd, path))).replaceAll("\\", "/");
|
|
55893
55983
|
if (inside2.startsWith("../") || inside2 === "..") throw new Error(`${path} is outside the repository`);
|
|
55894
55984
|
return inside2;
|
|
55895
55985
|
};
|
|
@@ -55926,7 +56016,7 @@ function conflictsPack(shared, options) {
|
|
|
55926
56016
|
for (const file of files) {
|
|
55927
56017
|
let detail = file.kind;
|
|
55928
56018
|
if (file.kind === "both modified" || file.kind === "both added") {
|
|
55929
|
-
const content = await readFile5(
|
|
56019
|
+
const content = await readFile5(join47(repo.root, file.path)).catch(() => void 0);
|
|
55930
56020
|
if (content && looksBinary(content)) detail += " (binary: take ours or theirs)";
|
|
55931
56021
|
else if (content) {
|
|
55932
56022
|
const count3 = parseConflicts(content.toString("utf8")).blocks.length;
|
|
@@ -55958,7 +56048,7 @@ function conflictsPack(shared, options) {
|
|
|
55958
56048
|
details: { path, kind: file.kind }
|
|
55959
56049
|
};
|
|
55960
56050
|
}
|
|
55961
|
-
const content = await readFile5(
|
|
56051
|
+
const content = await readFile5(join47(repo.root, path));
|
|
55962
56052
|
if (looksBinary(content)) {
|
|
55963
56053
|
return {
|
|
55964
56054
|
content: text6(`${path} is binary: resolve it with take: "ours" or "theirs".`),
|
|
@@ -56032,7 +56122,7 @@ function conflictsPack(shared, options) {
|
|
|
56032
56122
|
details: { path, resolved: true, left: left2.length }
|
|
56033
56123
|
};
|
|
56034
56124
|
}
|
|
56035
|
-
const content = await readFile5(
|
|
56125
|
+
const content = await readFile5(join47(cwd, path));
|
|
56036
56126
|
if (looksBinary(content)) throw new Error(`${path} is binary: use take: "ours" or "theirs".`);
|
|
56037
56127
|
const parsed = parseConflicts(content.toString("utf8"));
|
|
56038
56128
|
if (parsed.problem)
|
|
@@ -56049,7 +56139,7 @@ function conflictsPack(shared, options) {
|
|
|
56049
56139
|
if (resolutions.size === 0)
|
|
56050
56140
|
throw new Error("Give the resolution of at least one block, or take a side.");
|
|
56051
56141
|
const written = replaceBlocks(parsed, resolutions);
|
|
56052
|
-
await writeFile6(
|
|
56142
|
+
await writeFile6(join47(cwd, path), written);
|
|
56053
56143
|
const remaining = parseConflicts(written).blocks.length;
|
|
56054
56144
|
if (remaining > 0) {
|
|
56055
56145
|
return {
|
|
@@ -56969,7 +57059,7 @@ ${tail2}` : "Ended the debugging run."
|
|
|
56969
57059
|
}
|
|
56970
57060
|
|
|
56971
57061
|
// packages/kyrn-judge/src/extension/features/packs/github.ts
|
|
56972
|
-
import { existsSync as
|
|
57062
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
56973
57063
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
56974
57064
|
var GITHUB_SKILL_PATH = fileURLToPath4(new URL("../../../../skills/mu-github/SKILL.md", new URL("src/extension/features/packs/github.ts", new URL("../", import.meta.url)).href));
|
|
56975
57065
|
function githubPack(shared, options) {
|
|
@@ -56978,7 +57068,7 @@ function githubPack(shared, options) {
|
|
|
56978
57068
|
title: "GitHub through gh",
|
|
56979
57069
|
description: "For work on GitHub: pull requests, issues, CI checks and their logs, reviews, releases, the API. Adds no tools; the mu-github skill says how to use gh.",
|
|
56980
57070
|
tools: [],
|
|
56981
|
-
skills:
|
|
57071
|
+
skills: existsSync16(GITHUB_SKILL_PATH) ? [GITHUB_SKILL_PATH] : [],
|
|
56982
57072
|
async start() {
|
|
56983
57073
|
const result = await shared.run(options.command || "gh", ["--version"], {
|
|
56984
57074
|
cwd: shared.cwd(),
|
|
@@ -57277,13 +57367,14 @@ function registerPacks(runtime) {
|
|
|
57277
57367
|
// packages/kyrn-judge/src/extension/features/permissions.ts
|
|
57278
57368
|
var import_pi_coding_agent15 = __toESM(require_pi_coding_agent(), 1);
|
|
57279
57369
|
import { homedir as homedir11 } from "node:os";
|
|
57280
|
-
import { join as
|
|
57370
|
+
import { join as join49, resolve as resolve14, sep as sep4 } from "node:path";
|
|
57281
57371
|
|
|
57282
57372
|
// packages/kyrn-judge/src/decisions/tool-approval.ts
|
|
57283
57373
|
var APPROVE_AT = 0.8;
|
|
57374
|
+
var CHECK_APPROVE_AT = 0.7;
|
|
57284
57375
|
var toolApproval = defineDecision({
|
|
57285
57376
|
id: "tool.approval",
|
|
57286
|
-
version:
|
|
57377
|
+
version: 2,
|
|
57287
57378
|
cacheImpact: "none",
|
|
57288
57379
|
latency: "inline",
|
|
57289
57380
|
capabilities: "relate",
|
|
@@ -57303,11 +57394,12 @@ var toolApproval = defineDecision({
|
|
|
57303
57394
|
buildState(input) {
|
|
57304
57395
|
return { tool_call: input.call, where: input.where, task: input.task, user_message: input.userMessage };
|
|
57305
57396
|
},
|
|
57306
|
-
policy(answers) {
|
|
57397
|
+
policy(answers, input) {
|
|
57307
57398
|
const { choice, probabilities } = answers.verdict;
|
|
57308
57399
|
if (isEscapeOption(choice)) return "unsure";
|
|
57309
57400
|
const p = probabilities?.[choice];
|
|
57310
|
-
|
|
57401
|
+
const line2 = input.check ? CHECK_APPROVE_AT : APPROVE_AT;
|
|
57402
|
+
if (choice === "needed") return p === void 0 || p >= line2 ? "approve" : "unsure";
|
|
57311
57403
|
return choice === "beyond" || choice === "unrelated" ? choice : "unsure";
|
|
57312
57404
|
},
|
|
57313
57405
|
// Nobody could look at it: the user decides.
|
|
@@ -57319,7 +57411,7 @@ var toolApproval = defineDecision({
|
|
|
57319
57411
|
// packages/kyrn-judge/src/permissions/modes.ts
|
|
57320
57412
|
import { lstatSync as lstatSync2, mkdirSync as mkdirSync18, readFileSync as readFileSync23, readlinkSync, realpathSync as realpathSync6, renameSync as renameSync10, writeFileSync as writeFileSync15 } from "node:fs";
|
|
57321
57413
|
import { homedir as homedir10 } from "node:os";
|
|
57322
|
-
import { basename as basename14, dirname as
|
|
57414
|
+
import { basename as basename14, dirname as dirname13, isAbsolute as isAbsolute8, join as join48, relative as relative7, resolve as resolve13, sep as sep3 } from "node:path";
|
|
57323
57415
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
57324
57416
|
var PERMISSION_MODES = ["full", "judge", "ask"];
|
|
57325
57417
|
var MODE_TEXT = {
|
|
@@ -57407,12 +57499,12 @@ function realPath2(path, depth = 0) {
|
|
|
57407
57499
|
if (depth < 40) {
|
|
57408
57500
|
try {
|
|
57409
57501
|
if (lstatSync2(path).isSymbolicLink())
|
|
57410
|
-
return realPath2(resolve13(
|
|
57502
|
+
return realPath2(resolve13(dirname13(path), readlinkSync(path)), depth + 1);
|
|
57411
57503
|
} catch {
|
|
57412
57504
|
}
|
|
57413
57505
|
}
|
|
57414
|
-
const parent =
|
|
57415
|
-
return parent === path ? path :
|
|
57506
|
+
const parent = dirname13(path);
|
|
57507
|
+
return parent === path ? path : join48(realPath2(parent, depth + 1), basename14(path));
|
|
57416
57508
|
}
|
|
57417
57509
|
}
|
|
57418
57510
|
var UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
|
@@ -57427,7 +57519,7 @@ function toolPath(cwd, raw, home = homedir10()) {
|
|
|
57427
57519
|
if (process.platform === "win32") path = windowsDrive(path);
|
|
57428
57520
|
if (path === "~") path = home;
|
|
57429
57521
|
else if (path.startsWith("~/") || process.platform === "win32" && path.startsWith("~\\"))
|
|
57430
|
-
path =
|
|
57522
|
+
path = join48(home, path.slice(2));
|
|
57431
57523
|
else if (/^file:\/\//.test(path)) {
|
|
57432
57524
|
try {
|
|
57433
57525
|
path = fileURLToPath5(path);
|
|
@@ -57440,7 +57532,7 @@ function toolPath(cwd, raw, home = homedir10()) {
|
|
|
57440
57532
|
function inProject(cwd, target) {
|
|
57441
57533
|
if (target === void 0) return void 0;
|
|
57442
57534
|
const rel = relative7(realPath2(resolve13(cwd)), target);
|
|
57443
|
-
return rel === ".." || rel.startsWith(`..${
|
|
57535
|
+
return rel === ".." || rel.startsWith(`..${sep3}`) || isAbsolute8(rel) ? void 0 : rel;
|
|
57444
57536
|
}
|
|
57445
57537
|
function projectFile(cwd, target) {
|
|
57446
57538
|
const rel = inProject(cwd, target);
|
|
@@ -57538,7 +57630,7 @@ var PermissionDefaults = class {
|
|
|
57538
57630
|
file;
|
|
57539
57631
|
memory;
|
|
57540
57632
|
constructor(dir) {
|
|
57541
|
-
this.file = dir ?
|
|
57633
|
+
this.file = dir ? join48(dir, "permissions.json") : void 0;
|
|
57542
57634
|
}
|
|
57543
57635
|
get() {
|
|
57544
57636
|
if (!this.file) return this.memory;
|
|
@@ -57554,7 +57646,7 @@ var PermissionDefaults = class {
|
|
|
57554
57646
|
this.memory = mode;
|
|
57555
57647
|
return;
|
|
57556
57648
|
}
|
|
57557
|
-
mkdirSync18(
|
|
57649
|
+
mkdirSync18(join48(this.file, ".."), { recursive: true });
|
|
57558
57650
|
const temp = `${this.file}.${process.pid}.tmp`;
|
|
57559
57651
|
writeFileSync15(temp, `${JSON.stringify({ version: 1, mode }, null, " ")}
|
|
57560
57652
|
`, { mode: 384 });
|
|
@@ -57614,9 +57706,9 @@ function protectedPaths(roots) {
|
|
|
57614
57706
|
return real2 && real2 !== roots.agentDir ? [...spelled, real2] : spelled;
|
|
57615
57707
|
}
|
|
57616
57708
|
function projectSettings(cwd) {
|
|
57617
|
-
const spelled =
|
|
57709
|
+
const spelled = join49(resolve14(cwd), import_pi_coding_agent15.CONFIG_DIR_NAME);
|
|
57618
57710
|
const real2 = toolPath(cwd, import_pi_coding_agent15.CONFIG_DIR_NAME) ?? spelled;
|
|
57619
|
-
return [.../* @__PURE__ */ new Set([spelled, real2])].map((path) => `${path}${
|
|
57711
|
+
return [.../* @__PURE__ */ new Set([spelled, real2])].map((path) => `${path}${sep4}`);
|
|
57620
57712
|
}
|
|
57621
57713
|
function registerPermissions(runtime, roots) {
|
|
57622
57714
|
const options = runtime.options("permissions", {
|
|
@@ -57628,7 +57720,7 @@ function registerPermissions(runtime, roots) {
|
|
|
57628
57720
|
});
|
|
57629
57721
|
if (!options.enabled) return;
|
|
57630
57722
|
const { pi } = runtime;
|
|
57631
|
-
const defaults = new PermissionDefaults(roots ?
|
|
57723
|
+
const defaults = new PermissionDefaults(roots ? join49(roots.agentDir, "mu") : void 0);
|
|
57632
57724
|
const guarded = protectedPaths(roots);
|
|
57633
57725
|
const initial = () => parseMode(muEnv("PERMISSIONS")) ?? defaults.get() ?? parseMode(options.mode) ?? "judge";
|
|
57634
57726
|
let mode = initial();
|
|
@@ -57707,6 +57799,9 @@ function registerPermissions(runtime, roots) {
|
|
|
57707
57799
|
return { approved: asked2 && (decision2.judged ?? decision2.outcome) === "allow", reason: "flagged" };
|
|
57708
57800
|
}
|
|
57709
57801
|
const frame = runtime.frame;
|
|
57802
|
+
const input = event.input;
|
|
57803
|
+
const powershell = event.toolName === "powershell" || event.toolName === "bg_start" && process.platform === "win32";
|
|
57804
|
+
const check = need.kind === "shell" && isCheckChain(String(input.command ?? ""), powershell, ctx.cwd, shellStart(event.toolName, input, ctx.cwd));
|
|
57710
57805
|
const decision = await runtime.engine.decide(
|
|
57711
57806
|
toolApproval,
|
|
57712
57807
|
{
|
|
@@ -57716,7 +57811,8 @@ function registerPermissions(runtime, roots) {
|
|
|
57716
57811
|
),
|
|
57717
57812
|
userMessage,
|
|
57718
57813
|
call,
|
|
57719
|
-
where: need.kind === "outside" ? "outside the project folder" : need.kind === "shell" || need.kind === "run" ? "a program run in the project folder" : need.kind === "delegate" ? "subagents working on the project" : "an action outside this computer or program, such as a web page or a connected service"
|
|
57814
|
+
where: need.kind === "outside" ? "outside the project folder" : need.kind === "shell" || need.kind === "run" ? "a program run in the project folder" : need.kind === "delegate" ? "subagents working on the project" : "an action outside this computer or program, such as a web page or a connected service",
|
|
57815
|
+
check
|
|
57720
57816
|
},
|
|
57721
57817
|
{ signal: ctx.signal }
|
|
57722
57818
|
);
|
|
@@ -58512,7 +58608,7 @@ function registerPreflight(runtime) {
|
|
|
58512
58608
|
|
|
58513
58609
|
// packages/kyrn-judge/src/extension/features/procedures.ts
|
|
58514
58610
|
var import_pi_coding_agent16 = __toESM(require_pi_coding_agent(), 1);
|
|
58515
|
-
import { basename as basename15, join as
|
|
58611
|
+
import { basename as basename15, join as join51 } from "node:path";
|
|
58516
58612
|
|
|
58517
58613
|
// packages/kyrn-judge/src/decisions/skill-capture.ts
|
|
58518
58614
|
var DRAFT_AT = 0.9;
|
|
@@ -58551,8 +58647,8 @@ var skillCapture = defineDecision({
|
|
|
58551
58647
|
});
|
|
58552
58648
|
|
|
58553
58649
|
// packages/kyrn-judge/src/memory/skill-drafts.ts
|
|
58554
|
-
import { existsSync as
|
|
58555
|
-
import { join as
|
|
58650
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync19, readdirSync as readdirSync9, readFileSync as readFileSync24, rmSync as rmSync8, writeFileSync as writeFileSync16 } from "node:fs";
|
|
58651
|
+
import { join as join50 } from "node:path";
|
|
58556
58652
|
var MAX_NAME = 64;
|
|
58557
58653
|
var MAX_DESCRIPTION = 300;
|
|
58558
58654
|
var MAX_LINES = 120;
|
|
@@ -58584,7 +58680,7 @@ var SkillDrafts = class {
|
|
|
58584
58680
|
this.dir = dir;
|
|
58585
58681
|
}
|
|
58586
58682
|
list() {
|
|
58587
|
-
if (!
|
|
58683
|
+
if (!existsSync17(this.dir)) return [];
|
|
58588
58684
|
const drafts = [];
|
|
58589
58685
|
for (const entry of readdirSync9(this.dir, { withFileTypes: true })) {
|
|
58590
58686
|
if (!entry.isDirectory()) continue;
|
|
@@ -58594,10 +58690,10 @@ var SkillDrafts = class {
|
|
|
58594
58690
|
return drafts.sort((a, b) => a.created.localeCompare(b.created));
|
|
58595
58691
|
}
|
|
58596
58692
|
get(name) {
|
|
58597
|
-
const folder =
|
|
58693
|
+
const folder = join50(this.dir, skillName(name));
|
|
58598
58694
|
try {
|
|
58599
|
-
const meta = JSON.parse(readFileSync24(
|
|
58600
|
-
return { ...meta, markdown: readFileSync24(
|
|
58695
|
+
const meta = JSON.parse(readFileSync24(join50(folder, "draft.json"), "utf8"));
|
|
58696
|
+
return { ...meta, markdown: readFileSync24(join50(folder, "SKILL.md"), "utf8") };
|
|
58601
58697
|
} catch {
|
|
58602
58698
|
return void 0;
|
|
58603
58699
|
}
|
|
@@ -58615,16 +58711,16 @@ var SkillDrafts = class {
|
|
|
58615
58711
|
request: origin.request.slice(0, 400),
|
|
58616
58712
|
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
58617
58713
|
};
|
|
58618
|
-
const folder =
|
|
58714
|
+
const folder = join50(this.dir, name);
|
|
58619
58715
|
mkdirSync19(folder, { recursive: true });
|
|
58620
|
-
writeFileSync16(
|
|
58621
|
-
writeFileSync16(
|
|
58716
|
+
writeFileSync16(join50(folder, "SKILL.md"), markdown);
|
|
58717
|
+
writeFileSync16(join50(folder, "draft.json"), `${JSON.stringify(meta, null, " ")}
|
|
58622
58718
|
`);
|
|
58623
58719
|
return { ...meta, markdown };
|
|
58624
58720
|
}
|
|
58625
58721
|
remove(name) {
|
|
58626
|
-
const folder =
|
|
58627
|
-
if (!
|
|
58722
|
+
const folder = join50(this.dir, skillName(name));
|
|
58723
|
+
if (!existsSync17(folder)) return false;
|
|
58628
58724
|
rmSync8(folder, { recursive: true, force: true });
|
|
58629
58725
|
return true;
|
|
58630
58726
|
}
|
|
@@ -58635,9 +58731,9 @@ var SkillDrafts = class {
|
|
|
58635
58731
|
accept(name, skillsDir) {
|
|
58636
58732
|
const draft = this.get(name);
|
|
58637
58733
|
if (!draft) return { error: "missing" };
|
|
58638
|
-
const folder =
|
|
58639
|
-
const path =
|
|
58640
|
-
if (
|
|
58734
|
+
const folder = join50(skillsDir, draft.name);
|
|
58735
|
+
const path = join50(folder, "SKILL.md");
|
|
58736
|
+
if (existsSync17(path)) return { error: "exists" };
|
|
58641
58737
|
mkdirSync19(folder, { recursive: true });
|
|
58642
58738
|
writeFileSync16(path, draft.markdown);
|
|
58643
58739
|
this.remove(draft.name);
|
|
@@ -58675,10 +58771,10 @@ function registerProcedures(runtime, roots) {
|
|
|
58675
58771
|
});
|
|
58676
58772
|
if (!options.enabled || process.env.KYRN_SWARM_DEPTH) return;
|
|
58677
58773
|
const { pi } = runtime;
|
|
58678
|
-
const dir = options.path || (roots ?
|
|
58774
|
+
const dir = options.path || (roots ? join51(roots.agentDir, "mu", "skill-drafts") : void 0);
|
|
58679
58775
|
if (!dir) return;
|
|
58680
58776
|
const drafts = new SkillDrafts(dir);
|
|
58681
|
-
const userSkillsDir = roots ?
|
|
58777
|
+
const userSkillsDir = roots ? join51(roots.agentDir, "skills") : void 0;
|
|
58682
58778
|
let turnOf = -1;
|
|
58683
58779
|
let request = "";
|
|
58684
58780
|
let steps = [];
|
|
@@ -58837,7 +58933,7 @@ ${say({
|
|
|
58837
58933
|
return;
|
|
58838
58934
|
}
|
|
58839
58935
|
if (verb === "accept") {
|
|
58840
|
-
const target = project ?
|
|
58936
|
+
const target = project ? join51(ctx.cwd, import_pi_coding_agent16.CONFIG_DIR_NAME, "skills") : userSkillsDir;
|
|
58841
58937
|
if (!target) return;
|
|
58842
58938
|
const result = drafts.accept(draft.name, target);
|
|
58843
58939
|
if ("error" in result) {
|
|
@@ -59132,7 +59228,7 @@ function errorDetail(text9) {
|
|
|
59132
59228
|
|
|
59133
59229
|
// packages/kyrn-judge/src/sandbox/operations.ts
|
|
59134
59230
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
59135
|
-
import { extname as extname2, isAbsolute as isAbsolute9, posix as posix6, relative as relative9, sep as
|
|
59231
|
+
import { extname as extname2, isAbsolute as isAbsolute9, posix as posix6, relative as relative9, sep as sep6 } from "node:path";
|
|
59136
59232
|
|
|
59137
59233
|
// packages/kyrn-judge/src/sandbox/session.ts
|
|
59138
59234
|
import { posix as posix5 } from "node:path";
|
|
@@ -59140,7 +59236,7 @@ import { posix as posix5 } from "node:path";
|
|
|
59140
59236
|
// packages/kyrn-judge/src/sandbox/project.ts
|
|
59141
59237
|
import { spawn as spawn10 } from "node:child_process";
|
|
59142
59238
|
import { lstat as lstat2, readdir as readdir2, readFile as readFile6, readlink as readlink2 } from "node:fs/promises";
|
|
59143
|
-
import { join as
|
|
59239
|
+
import { join as join52, relative as relative8, sep as sep5 } from "node:path";
|
|
59144
59240
|
import { promisify } from "node:util";
|
|
59145
59241
|
import { gzip } from "node:zlib";
|
|
59146
59242
|
|
|
@@ -59249,9 +59345,9 @@ var WALK_SKIP = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
|
59249
59345
|
async function walk(root, dir, found) {
|
|
59250
59346
|
for (const entry of await readdir2(dir, { withFileTypes: true })) {
|
|
59251
59347
|
if (entry.isDirectory()) {
|
|
59252
|
-
if (!WALK_SKIP.has(entry.name)) await walk(root,
|
|
59348
|
+
if (!WALK_SKIP.has(entry.name)) await walk(root, join52(dir, entry.name), found);
|
|
59253
59349
|
} else if (entry.isFile() || entry.isSymbolicLink()) {
|
|
59254
|
-
found.push(relative8(root,
|
|
59350
|
+
found.push(relative8(root, join52(dir, entry.name)).split(sep5).join("/"));
|
|
59255
59351
|
}
|
|
59256
59352
|
}
|
|
59257
59353
|
}
|
|
@@ -59279,13 +59375,13 @@ async function seedArchive(cwd, maxBytes) {
|
|
|
59279
59375
|
const entries = [];
|
|
59280
59376
|
let bytes = 0;
|
|
59281
59377
|
for (const path of files) {
|
|
59282
|
-
const absolute3 =
|
|
59378
|
+
const absolute3 = join52(cwd, path);
|
|
59283
59379
|
const stat = await lstat2(absolute3).catch(() => void 0);
|
|
59284
59380
|
if (!stat) continue;
|
|
59285
59381
|
const mtime = Math.floor(stat.mtimeMs / 1e3);
|
|
59286
59382
|
if (stat.isSymbolicLink()) {
|
|
59287
59383
|
const target = await readlink2(absolute3);
|
|
59288
|
-
entries.push({ path, mode: 511, mtime, linkTarget:
|
|
59384
|
+
entries.push({ path, mode: 511, mtime, linkTarget: sep5 === "\\" ? target.split(sep5).join("/") : target });
|
|
59289
59385
|
} else if (stat.isFile()) {
|
|
59290
59386
|
bytes += stat.size;
|
|
59291
59387
|
if (bytes > maxBytes) throw new ProjectTooLarge(bytes, maxBytes);
|
|
@@ -59665,14 +59761,14 @@ var SandboxSession = class {
|
|
|
59665
59761
|
function toSandboxPath(localPath, root, workdir) {
|
|
59666
59762
|
const inside2 = relative9(root, localPath);
|
|
59667
59763
|
if (inside2 === "") return workdir;
|
|
59668
|
-
if (inside2 !== ".." && !inside2.startsWith(`..${
|
|
59669
|
-
return posix6.join(workdir, inside2.split(
|
|
59764
|
+
if (inside2 !== ".." && !inside2.startsWith(`..${sep6}`) && !isAbsolute9(inside2)) {
|
|
59765
|
+
return posix6.join(workdir, inside2.split(sep6).join("/"));
|
|
59670
59766
|
}
|
|
59671
|
-
return localPath.split(
|
|
59767
|
+
return localPath.split(sep6).join("/");
|
|
59672
59768
|
}
|
|
59673
59769
|
function insideProject(localPath, root) {
|
|
59674
59770
|
const inside2 = relative9(root, localPath);
|
|
59675
|
-
return inside2 === "" || inside2 !== ".." && !inside2.startsWith(`..${
|
|
59771
|
+
return inside2 === "" || inside2 !== ".." && !inside2.startsWith(`..${sep6}`) && !isAbsolute9(inside2);
|
|
59676
59772
|
}
|
|
59677
59773
|
var IMAGE_TYPES2 = {
|
|
59678
59774
|
".png": "image/png",
|
|
@@ -60718,7 +60814,7 @@ function registerWatchdog(runtime) {
|
|
|
60718
60814
|
}
|
|
60719
60815
|
|
|
60720
60816
|
// packages/kyrn-judge/src/extension/quit.ts
|
|
60721
|
-
import { join as
|
|
60817
|
+
import { join as join53 } from "node:path";
|
|
60722
60818
|
|
|
60723
60819
|
// packages/kyrn-judge/src/auth/exit.ts
|
|
60724
60820
|
import { mkdirSync as mkdirSync20, rmdirSync as rmdirSync2 } from "node:fs";
|
|
@@ -60774,7 +60870,7 @@ function drop(lock) {
|
|
|
60774
60870
|
|
|
60775
60871
|
// packages/kyrn-judge/src/extension/quit.ts
|
|
60776
60872
|
function registerLockSafeQuit(pi, agentDir) {
|
|
60777
|
-
const stores2 = [
|
|
60873
|
+
const stores2 = [join53(agentDir, "auth.json"), join53(agentDir, "models-store.json")];
|
|
60778
60874
|
pi.on("session_shutdown", async (event) => {
|
|
60779
60875
|
if (event.reason === "quit") await holdLocksUntilExit(stores2);
|
|
60780
60876
|
});
|
|
@@ -60833,7 +60929,7 @@ function registerKyrn(pi, options) {
|
|
|
60833
60929
|
for (const capability of options.capabilities ?? []) runtime.catalog.register(capability);
|
|
60834
60930
|
registerWelcome(runtime);
|
|
60835
60931
|
const roots = options.roots ?? (options.config || options.provider ? void 0 : { home: homedir12(), agentDir: (0, import_pi_coding_agent18.getAgentDir)() });
|
|
60836
|
-
runtime.stateDir = roots ?
|
|
60932
|
+
runtime.stateDir = roots ? join54(roots.agentDir, "mu") : void 0;
|
|
60837
60933
|
registerLayaNotice(runtime, loaded.laya, roots, home);
|
|
60838
60934
|
if (loaded.disabled) {
|
|
60839
60935
|
if (!options.only || options.only.includes("permissions")) registerPermissions(runtime, roots);
|