mu-agent 0.2.12 → 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 +8 -0
- package/judge/mu/index.js +302 -252
- 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"]);
|
|
@@ -33269,6 +33269,11 @@ function simpleCommands(text9, writes) {
|
|
|
33269
33269
|
let end = index + 1;
|
|
33270
33270
|
for (; end < text9.length && text9[end] !== '"'; end++) {
|
|
33271
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
|
+
}
|
|
33272
33277
|
if (inner === "`" || inner === "$" && /[({[]/.test(text9[end + 1] ?? "")) return void 0;
|
|
33273
33278
|
if (inner === "\\" && /[$`"\\\n]/.test(text9[end + 1] ?? "")) {
|
|
33274
33279
|
end++;
|
|
@@ -33306,9 +33311,14 @@ function isReadOnlyChain(command, powershell = false, cwd, start = cwd) {
|
|
|
33306
33311
|
return true;
|
|
33307
33312
|
});
|
|
33308
33313
|
}
|
|
33309
|
-
function
|
|
33314
|
+
function cdTarget(words2) {
|
|
33310
33315
|
const [, to, ...more] = words2;
|
|
33311
|
-
|
|
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);
|
|
33312
33322
|
}
|
|
33313
33323
|
function readOnlyPart(words2, elsewhere) {
|
|
33314
33324
|
const [program] = words2;
|
|
@@ -33330,28 +33340,68 @@ function isCheckCommand(command) {
|
|
|
33330
33340
|
}
|
|
33331
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|$)/;
|
|
33332
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
|
+
}
|
|
33333
33362
|
function tempFile(name) {
|
|
33334
33363
|
return /^\/(?:private\/)?tmp\//.test(name) && !name.split("/").includes("..");
|
|
33335
33364
|
}
|
|
33336
33365
|
function isCheckChain(command, powershell = false, cwd, start = cwd) {
|
|
33337
|
-
if (powershell) return false;
|
|
33366
|
+
if (powershell || cwd === void 0) return false;
|
|
33338
33367
|
const writes = [];
|
|
33339
33368
|
const commands = simpleCommands(command.trim(), writes);
|
|
33340
33369
|
if (!commands || !writes.every(tempFile)) return false;
|
|
33341
|
-
let
|
|
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);
|
|
33342
33385
|
let checks = 0;
|
|
33343
|
-
const parts = commands.every((
|
|
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
|
+
}
|
|
33344
33392
|
if (words2[0] === "cd") {
|
|
33345
|
-
|
|
33393
|
+
const to = cdTarget(words2);
|
|
33394
|
+
dir = to === void 0 ? void 0 : inProject2(to);
|
|
33346
33395
|
return true;
|
|
33347
33396
|
}
|
|
33348
33397
|
let at = words2[0] === "env" ? 1 : 0;
|
|
33349
33398
|
while (at < words2.length && CHECK_SETTING.test(words2[at])) at++;
|
|
33350
|
-
|
|
33399
|
+
const run2 = words2.slice(at);
|
|
33400
|
+
if (CHECK_RUN.test(run2.join(" ")) || dir !== void 0 && localCheck(run2, dir, home)) {
|
|
33351
33401
|
checks++;
|
|
33352
|
-
return
|
|
33402
|
+
return dir !== void 0;
|
|
33353
33403
|
}
|
|
33354
|
-
return at === 0 && readOnlyPart(words2,
|
|
33404
|
+
return at === 0 && readOnlyPart(words2, dir !== home);
|
|
33355
33405
|
});
|
|
33356
33406
|
return parts && checks > 0;
|
|
33357
33407
|
}
|
|
@@ -33505,7 +33555,7 @@ var boardRead = defineDecision({
|
|
|
33505
33555
|
|
|
33506
33556
|
// packages/kyrn-judge/src/swarm/run.ts
|
|
33507
33557
|
import { appendFileSync, mkdirSync as mkdirSync6, writeFileSync as writeFileSync5 } from "node:fs";
|
|
33508
|
-
import { join as
|
|
33558
|
+
import { join as join12 } from "node:path";
|
|
33509
33559
|
|
|
33510
33560
|
// packages/kyrn-judge/src/decisions/tool-injection.ts
|
|
33511
33561
|
var INJECTION_THRESHOLD = 0.5;
|
|
@@ -33981,7 +34031,7 @@ function subagentUsage(kind, bee) {
|
|
|
33981
34031
|
};
|
|
33982
34032
|
}
|
|
33983
34033
|
function controlPath(dir, index) {
|
|
33984
|
-
return
|
|
34034
|
+
return join12(dir, "control", `bee-${index}.json`);
|
|
33985
34035
|
}
|
|
33986
34036
|
var active = /* @__PURE__ */ new Set();
|
|
33987
34037
|
function activeRuns() {
|
|
@@ -34023,8 +34073,8 @@ var SwarmRun = class {
|
|
|
34023
34073
|
this.now = options.now ?? Date.now;
|
|
34024
34074
|
this.startedAt = this.now();
|
|
34025
34075
|
this.controllers = options.bees.map(() => void 0);
|
|
34026
|
-
mkdirSync6(
|
|
34027
|
-
mkdirSync6(
|
|
34076
|
+
mkdirSync6(join12(this.dir, "control"), { recursive: true });
|
|
34077
|
+
mkdirSync6(join12(this.dir, "transcripts"), { recursive: true });
|
|
34028
34078
|
this.bees = options.bees.map((bee, index) => this.stateFor(bee, index, this.startedAt));
|
|
34029
34079
|
}
|
|
34030
34080
|
stateFor(bee, index, now) {
|
|
@@ -34032,7 +34082,7 @@ var SwarmRun = class {
|
|
|
34032
34082
|
role: bee.role,
|
|
34033
34083
|
model: bee.model,
|
|
34034
34084
|
thinking: bee.thinking,
|
|
34035
|
-
transcript:
|
|
34085
|
+
transcript: join12(this.dir, "transcripts", `${index}-${bee.name.replace(/[^\w.-]+/g, "_")}.jsonl`)
|
|
34036
34086
|
});
|
|
34037
34087
|
}
|
|
34038
34088
|
/**
|
|
@@ -34698,7 +34748,7 @@ function registerBoard(runtime, roots) {
|
|
|
34698
34748
|
});
|
|
34699
34749
|
if (!options.enabled || process.env.KYRN_SWARM_CONTROL) return;
|
|
34700
34750
|
const { pi } = runtime;
|
|
34701
|
-
const projects = new BoardProjects(roots ?
|
|
34751
|
+
const projects = new BoardProjects(roots ? join13(roots.agentDir, "mu") : void 0);
|
|
34702
34752
|
const calls = /* @__PURE__ */ new Map();
|
|
34703
34753
|
let steps = [];
|
|
34704
34754
|
let latest = "";
|
|
@@ -35673,9 +35723,9 @@ ${addModelHelp(language())}`,
|
|
|
35673
35723
|
|
|
35674
35724
|
// packages/kyrn-judge/src/extension/features/browser.ts
|
|
35675
35725
|
var import_typebox2 = __toESM(require_typebox(), 1);
|
|
35676
|
-
import { existsSync as
|
|
35726
|
+
import { existsSync as existsSync7, rmSync as rmSync4 } from "node:fs";
|
|
35677
35727
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
35678
|
-
import { join as
|
|
35728
|
+
import { join as join16 } from "node:path";
|
|
35679
35729
|
import { fileURLToPath } from "node:url";
|
|
35680
35730
|
|
|
35681
35731
|
// packages/kyrn-judge/src/decisions/browser-step.ts
|
|
@@ -36556,9 +36606,9 @@ var CdpConnection = class _CdpConnection {
|
|
|
36556
36606
|
|
|
36557
36607
|
// packages/kyrn-judge/src/browser/chrome.ts
|
|
36558
36608
|
import { spawn as spawn3, spawnSync } from "node:child_process";
|
|
36559
|
-
import { existsSync as
|
|
36609
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync7, readFileSync as readFileSync7, rmSync as rmSync3 } from "node:fs";
|
|
36560
36610
|
import { homedir as homedir2 } from "node:os";
|
|
36561
|
-
import { basename as basename2, dirname as
|
|
36611
|
+
import { basename as basename2, dirname as dirname4, join as join14, posix, win32 } from "node:path";
|
|
36562
36612
|
|
|
36563
36613
|
// packages/kyrn-judge/src/platform.ts
|
|
36564
36614
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
@@ -36752,7 +36802,7 @@ ${browserAdvice(host2)}`, {
|
|
|
36752
36802
|
params: { profileDir }
|
|
36753
36803
|
});
|
|
36754
36804
|
spelled = translated;
|
|
36755
|
-
cwd =
|
|
36805
|
+
cwd = dirname4(browser.executable);
|
|
36756
36806
|
} else {
|
|
36757
36807
|
const base = confinedProfileBase(browser.executable, host2);
|
|
36758
36808
|
if (base) profileDir = posix.join(base, `mu-${basename2(profileDir)}`);
|
|
@@ -36786,11 +36836,11 @@ function thisBrowserHost(env = process.env) {
|
|
|
36786
36836
|
}
|
|
36787
36837
|
};
|
|
36788
36838
|
}
|
|
36789
|
-
return { platform: process.platform, env, home: homedir2(), exists:
|
|
36839
|
+
return { platform: process.platform, env, home: homedir2(), exists: existsSync6, wsl };
|
|
36790
36840
|
}
|
|
36791
36841
|
function readEndpoint(profileDir) {
|
|
36792
36842
|
try {
|
|
36793
|
-
const [port, path] = readFileSync7(
|
|
36843
|
+
const [port, path] = readFileSync7(join14(profileDir, "DevToolsActivePort"), "utf8").trim().split("\n");
|
|
36794
36844
|
return port && path ? `ws://127.0.0.1:${port}${path}` : void 0;
|
|
36795
36845
|
} catch {
|
|
36796
36846
|
return void 0;
|
|
@@ -36827,14 +36877,14 @@ async function launchChrome(options = {}) {
|
|
|
36827
36877
|
const plan2 = planBrowserLaunch({
|
|
36828
36878
|
host: host2,
|
|
36829
36879
|
browser,
|
|
36830
|
-
profileDir: options.profileDir ??
|
|
36880
|
+
profileDir: options.profileDir ?? join14(muHome(), "browser-profile"),
|
|
36831
36881
|
headless: options.headless !== false
|
|
36832
36882
|
});
|
|
36833
36883
|
const { profileDir } = plan2;
|
|
36834
36884
|
const running = readEndpoint(profileDir);
|
|
36835
36885
|
if (running && await isAlive(running)) return { endpoint: running, profileDir };
|
|
36836
36886
|
mkdirSync7(profileDir, { recursive: true });
|
|
36837
|
-
rmSync3(
|
|
36887
|
+
rmSync3(join14(profileDir, "DevToolsActivePort"), { force: true });
|
|
36838
36888
|
const child = spawn3(plan2.command, plan2.args, { stdio: "ignore", detached: false, cwd: plan2.cwd });
|
|
36839
36889
|
let failure;
|
|
36840
36890
|
child.on("error", (error) => {
|
|
@@ -36863,7 +36913,7 @@ async function launchChrome(options = {}) {
|
|
|
36863
36913
|
|
|
36864
36914
|
// packages/kyrn-judge/src/browser/embedded.ts
|
|
36865
36915
|
import { readFileSync as readFileSync8 } from "node:fs";
|
|
36866
|
-
import { join as
|
|
36916
|
+
import { join as join15 } from "node:path";
|
|
36867
36917
|
var ADVERT_FILE = "desktop-browser.json";
|
|
36868
36918
|
var PROTOCOL_VERSION = 1;
|
|
36869
36919
|
function processRuns(pid) {
|
|
@@ -36888,7 +36938,7 @@ function findEmbeddedEndpoint(host2 = {}) {
|
|
|
36888
36938
|
if (fromEnv) return loopbackSocket(fromEnv) ? { url: fromEnv } : void 0;
|
|
36889
36939
|
try {
|
|
36890
36940
|
const read2 = host2.readFile ?? ((path) => readFileSync8(path, "utf8"));
|
|
36891
|
-
const advert = JSON.parse(read2(
|
|
36941
|
+
const advert = JSON.parse(read2(join15(host2.home ?? muHome(), ADVERT_FILE)));
|
|
36892
36942
|
if (typeof advert.url !== "string" || !loopbackSocket(advert.url)) return void 0;
|
|
36893
36943
|
const pid = typeof advert.pid === "number" ? advert.pid : void 0;
|
|
36894
36944
|
if (pid !== void 0 && !(host2.isRunning ?? processRuns)(pid)) return void 0;
|
|
@@ -36987,7 +37037,7 @@ function registerBrowser(runtime) {
|
|
|
36987
37037
|
let chrome;
|
|
36988
37038
|
let cdp;
|
|
36989
37039
|
let embedded;
|
|
36990
|
-
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;
|
|
36991
37041
|
const connect2 = async () => {
|
|
36992
37042
|
if (cdp && !cdp.isClosed) return cdp;
|
|
36993
37043
|
cdp = void 0;
|
|
@@ -37239,7 +37289,7 @@ ${result.page.text.slice(0, textChars)}`
|
|
|
37239
37289
|
});
|
|
37240
37290
|
pi.on(
|
|
37241
37291
|
"resources_discover",
|
|
37242
|
-
failOpen(() =>
|
|
37292
|
+
failOpen(() => existsSync7(SKILL_PATH) ? { skillPaths: [SKILL_PATH] } : void 0)
|
|
37243
37293
|
);
|
|
37244
37294
|
pi.on(
|
|
37245
37295
|
"session_shutdown",
|
|
@@ -37617,12 +37667,12 @@ Open one with find_capability({ open: "<id>" }).`;
|
|
|
37617
37667
|
// packages/kyrn-judge/src/extension/features/checkpoint.ts
|
|
37618
37668
|
import { randomUUID as randomUUID4 } from "node:crypto";
|
|
37619
37669
|
import { homedir as homedir3 } from "node:os";
|
|
37620
|
-
import { join as
|
|
37670
|
+
import { join as join19 } from "node:path";
|
|
37621
37671
|
|
|
37622
37672
|
// packages/kyrn-judge/src/checkpoint/git.ts
|
|
37623
37673
|
import { execFile, spawn as spawn4 } from "node:child_process";
|
|
37624
|
-
import { accessSync, constants, existsSync as
|
|
37625
|
-
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";
|
|
37626
37676
|
var TIMED_OUT = 124;
|
|
37627
37677
|
var GitMissing = class extends Error {
|
|
37628
37678
|
constructor(binary, cause) {
|
|
@@ -37647,7 +37697,7 @@ var GitFailed = class extends Error {
|
|
|
37647
37697
|
}
|
|
37648
37698
|
};
|
|
37649
37699
|
function findOnPath(binary, path) {
|
|
37650
|
-
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));
|
|
37651
37701
|
return candidates.find((candidate) => {
|
|
37652
37702
|
try {
|
|
37653
37703
|
accessSync(candidate, constants.X_OK);
|
|
@@ -37665,7 +37715,7 @@ var hostProbe = {
|
|
|
37665
37715
|
"/usr/bin/xcode-select",
|
|
37666
37716
|
["-p"],
|
|
37667
37717
|
{ timeout: 5e3 },
|
|
37668
|
-
(error, stdout) => done(!error &&
|
|
37718
|
+
(error, stdout) => done(!error && existsSync8(stdout.trim()))
|
|
37669
37719
|
);
|
|
37670
37720
|
})
|
|
37671
37721
|
};
|
|
@@ -37747,7 +37797,7 @@ function spawnOnce(binary, timeoutMs, args, env, input, limit) {
|
|
|
37747
37797
|
child.stdin?.end(input ?? "");
|
|
37748
37798
|
});
|
|
37749
37799
|
}
|
|
37750
|
-
function shadowEnv(base, gitDir, workTree, indexFile =
|
|
37800
|
+
function shadowEnv(base, gitDir, workTree, indexFile = join17(gitDir, "index")) {
|
|
37751
37801
|
const env = {};
|
|
37752
37802
|
for (const [key, value] of Object.entries(base)) {
|
|
37753
37803
|
if (value !== void 0 && !key.toUpperCase().startsWith("GIT_")) env[key] = value;
|
|
@@ -37776,7 +37826,7 @@ import {
|
|
|
37776
37826
|
appendFileSync as appendFileSync2,
|
|
37777
37827
|
chmodSync as chmodSync2,
|
|
37778
37828
|
constants as constants2,
|
|
37779
|
-
existsSync as
|
|
37829
|
+
existsSync as existsSync9,
|
|
37780
37830
|
lstatSync,
|
|
37781
37831
|
mkdirSync as mkdirSync8,
|
|
37782
37832
|
readdirSync as readdirSync2,
|
|
@@ -37788,7 +37838,7 @@ import {
|
|
|
37788
37838
|
unlinkSync as unlinkSync2,
|
|
37789
37839
|
writeFileSync as writeFileSync6
|
|
37790
37840
|
} from "node:fs";
|
|
37791
|
-
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";
|
|
37792
37842
|
var BUILT_IN_IGNORES = [
|
|
37793
37843
|
"node_modules/",
|
|
37794
37844
|
"bower_components/",
|
|
@@ -37842,7 +37892,7 @@ var shadowConfig = (gitDir) => `${CONFIG_MARKER}
|
|
|
37842
37892
|
longpaths = true
|
|
37843
37893
|
quotepath = false
|
|
37844
37894
|
fsmonitor = false
|
|
37845
|
-
hooksPath = "${
|
|
37895
|
+
hooksPath = "${join18(gitDir, "mu-no-hooks").replaceAll("\\", "/").replaceAll('"', '\\"')}"
|
|
37846
37896
|
[gc]
|
|
37847
37897
|
auto = 0
|
|
37848
37898
|
[commit]
|
|
@@ -37883,19 +37933,19 @@ function isSafePath(path) {
|
|
|
37883
37933
|
if (!path || path.startsWith("/") || /^[a-zA-Z]:/.test(path) || path.includes("\\")) return false;
|
|
37884
37934
|
return path.split("/").every((part) => part !== "" && part !== "." && part !== ".." && !/^\.git$|^git~\d+$/i.test(part));
|
|
37885
37935
|
}
|
|
37886
|
-
var onDisk = (store, path) =>
|
|
37936
|
+
var onDisk = (store, path) => join18(store.root, ...path.split("/"));
|
|
37887
37937
|
function realPath(path) {
|
|
37888
37938
|
const absolute3 = resolve4(path);
|
|
37889
37939
|
try {
|
|
37890
37940
|
return realpathSync2.native(absolute3);
|
|
37891
37941
|
} catch {
|
|
37892
|
-
const parent =
|
|
37893
|
-
return parent === absolute3 ? absolute3 :
|
|
37942
|
+
const parent = dirname5(absolute3);
|
|
37943
|
+
return parent === absolute3 ? absolute3 : join18(realPath(parent), basename3(absolute3));
|
|
37894
37944
|
}
|
|
37895
37945
|
}
|
|
37896
37946
|
function inside(outer, inner) {
|
|
37897
37947
|
const rel = relative(realPath(outer), realPath(inner));
|
|
37898
|
-
return rel === ".." || rel.startsWith(`..${
|
|
37948
|
+
return rel === ".." || rel.startsWith(`..${sep2}`) || isAbsolute3(rel) ? void 0 : rel;
|
|
37899
37949
|
}
|
|
37900
37950
|
function isWithin(outer, inner) {
|
|
37901
37951
|
return inside(outer, inner) !== void 0;
|
|
@@ -37906,13 +37956,13 @@ function ownFolderPatterns(root, folders) {
|
|
|
37906
37956
|
const rel = inside(root, folder);
|
|
37907
37957
|
if (!rel) continue;
|
|
37908
37958
|
patterns.add(
|
|
37909
|
-
`/${rel.split(
|
|
37959
|
+
`/${rel.split(sep2).map((part) => part.replace(/[\\*?[\]!#]/g, "\\$&")).join("/")}/`
|
|
37910
37960
|
);
|
|
37911
37961
|
}
|
|
37912
37962
|
return [...patterns];
|
|
37913
37963
|
}
|
|
37914
37964
|
async function openStore(options) {
|
|
37915
|
-
const gitDir =
|
|
37965
|
+
const gitDir = join18(options.baseDir, projectKey(options.root));
|
|
37916
37966
|
const store = {
|
|
37917
37967
|
gitDir,
|
|
37918
37968
|
root: options.root,
|
|
@@ -37920,7 +37970,7 @@ async function openStore(options) {
|
|
|
37920
37970
|
env: shadowEnv(options.env ?? process.env, gitDir, options.root),
|
|
37921
37971
|
maxFileBytes: options.maxFileBytes ?? 5 * 1024 * 1024
|
|
37922
37972
|
};
|
|
37923
|
-
if (!
|
|
37973
|
+
if (!existsSync9(join18(gitDir, "HEAD"))) {
|
|
37924
37974
|
mkdirSync8(gitDir, { recursive: true, mode: 448 });
|
|
37925
37975
|
const { GIT_WORK_TREE: _tree, GIT_INDEX_FILE: _index, GIT_DIR: _dir, ...bare } = store.env;
|
|
37926
37976
|
const result = await options.run(["-c", "init.defaultBranch=mu", "init", "--bare", "--quiet", gitDir], bare);
|
|
@@ -37930,15 +37980,15 @@ async function openStore(options) {
|
|
|
37930
37980
|
chmodSync2(gitDir, 448);
|
|
37931
37981
|
} catch {
|
|
37932
37982
|
}
|
|
37933
|
-
const config =
|
|
37983
|
+
const config = join18(gitDir, "config");
|
|
37934
37984
|
if (!readFileSync9(config, "utf8").includes(CONFIG_MARKER)) appendFileSync2(config, `
|
|
37935
37985
|
${shadowConfig(gitDir)}`);
|
|
37936
|
-
mkdirSync8(
|
|
37986
|
+
mkdirSync8(join18(gitDir, "info"), { recursive: true });
|
|
37937
37987
|
const own = ownFolderPatterns(options.root, [options.baseDir, ...options.ownFolders ?? []]);
|
|
37938
|
-
writeFileSync6(
|
|
37988
|
+
writeFileSync6(join18(gitDir, "info", "exclude"), `${[...options.ignore ?? BUILT_IN_IGNORES, ...own].join("\n")}
|
|
37939
37989
|
`);
|
|
37940
|
-
writeFileSync6(
|
|
37941
|
-
writeFileSync6(
|
|
37990
|
+
writeFileSync6(join18(gitDir, "info", "attributes"), SHADOW_ATTRIBUTES);
|
|
37991
|
+
writeFileSync6(join18(gitDir, PROJECT_FILE), `${JSON.stringify({ root: options.root, lastUsed: Date.now() })}
|
|
37942
37992
|
`);
|
|
37943
37993
|
releaseLocks(store, STALE_LOCK_MS);
|
|
37944
37994
|
const stale = zList(await git(store, ["ls-files", "-z", "--cached", "--ignored", "--exclude-standard"]));
|
|
@@ -37954,7 +38004,7 @@ function releaseLocks(store, olderThanMs) {
|
|
|
37954
38004
|
}
|
|
37955
38005
|
for (const name of names) {
|
|
37956
38006
|
if (!name.endsWith(".lock") && !/^restore-.*\.index$/.test(name)) continue;
|
|
37957
|
-
const path =
|
|
38007
|
+
const path = join18(store.gitDir, name);
|
|
37958
38008
|
try {
|
|
37959
38009
|
if (Date.now() - statSync6(path).mtimeMs >= olderThanMs) rmSync5(path, { force: true });
|
|
37960
38010
|
} catch {
|
|
@@ -38070,7 +38120,7 @@ function obstacle(store, path, mustBeAbsent) {
|
|
|
38070
38120
|
const parts = path.split("/");
|
|
38071
38121
|
for (let depth = 1; depth < parts.length; depth++) {
|
|
38072
38122
|
try {
|
|
38073
|
-
if (!lstatSync(
|
|
38123
|
+
if (!lstatSync(join18(store.root, ...parts.slice(0, depth))).isDirectory())
|
|
38074
38124
|
return "a file is where its folder should be";
|
|
38075
38125
|
} catch {
|
|
38076
38126
|
break;
|
|
@@ -38107,7 +38157,7 @@ async function applyRestore(store, plan2, keep = /* @__PURE__ */ new Set()) {
|
|
|
38107
38157
|
const parts = path.split("/");
|
|
38108
38158
|
for (let depth = parts.length - 1; depth >= 1; depth--) {
|
|
38109
38159
|
try {
|
|
38110
|
-
rmdirSync(
|
|
38160
|
+
rmdirSync(join18(store.root, ...parts.slice(0, depth)));
|
|
38111
38161
|
} catch {
|
|
38112
38162
|
break;
|
|
38113
38163
|
}
|
|
@@ -38131,7 +38181,7 @@ async function applyRestore(store, plan2, keep = /* @__PURE__ */ new Set()) {
|
|
|
38131
38181
|
}
|
|
38132
38182
|
}
|
|
38133
38183
|
if (write.length > 0) {
|
|
38134
|
-
const index =
|
|
38184
|
+
const index = join18(store.gitDir, `restore-${randomUUID3()}.index`);
|
|
38135
38185
|
const env = { ...store.env, GIT_INDEX_FILE: index };
|
|
38136
38186
|
try {
|
|
38137
38187
|
await git(store, ["read-tree", plan2.commit], void 0, env);
|
|
@@ -38173,11 +38223,11 @@ function sweepProjects(baseDir, maxAgeDays, now = Date.now(), offLimits = () =>
|
|
|
38173
38223
|
}
|
|
38174
38224
|
for (const name of names) {
|
|
38175
38225
|
try {
|
|
38176
|
-
const project = JSON.parse(readFileSync9(
|
|
38226
|
+
const project = JSON.parse(readFileSync9(join18(baseDir, name, PROJECT_FILE), "utf8"));
|
|
38177
38227
|
const unusable = typeof project.root === "string" && offLimits(project.root);
|
|
38178
38228
|
const stale = typeof project.lastUsed === "number" && now - project.lastUsed >= maxAgeDays * 864e5;
|
|
38179
38229
|
if (!unusable && !stale) continue;
|
|
38180
|
-
rmSync5(
|
|
38230
|
+
rmSync5(join18(baseDir, name), { recursive: true, force: true });
|
|
38181
38231
|
removed.push(name);
|
|
38182
38232
|
} catch {
|
|
38183
38233
|
}
|
|
@@ -38361,7 +38411,7 @@ function registerCheckpoint(runtime, roots, deps = {}) {
|
|
|
38361
38411
|
unattended: false
|
|
38362
38412
|
});
|
|
38363
38413
|
if (!options.enabled || process.env.KYRN_SWARM_DEPTH) return;
|
|
38364
|
-
const baseDir = options.dir || (roots ?
|
|
38414
|
+
const baseDir = options.dir || (roots ? join19(roots.agentDir, "mu", "checkpoints") : "");
|
|
38365
38415
|
if (!baseDir) return;
|
|
38366
38416
|
const { pi } = runtime;
|
|
38367
38417
|
const home = () => roots?.home ?? homedir3();
|
|
@@ -38934,14 +38984,14 @@ The agent will then start over from your request, with a note about what didn't
|
|
|
38934
38984
|
|
|
38935
38985
|
// packages/kyrn-judge/src/extension/features/commands.ts
|
|
38936
38986
|
var import_pi_coding_agent5 = __toESM(require_pi_coding_agent(), 1);
|
|
38937
|
-
import { existsSync as
|
|
38938
|
-
import { join as
|
|
38987
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
38988
|
+
import { join as join22 } from "node:path";
|
|
38939
38989
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
38940
38990
|
|
|
38941
38991
|
// packages/kyrn-judge/src/extension/agents.ts
|
|
38942
38992
|
var import_pi_coding_agent3 = __toESM(require_pi_coding_agent(), 1);
|
|
38943
38993
|
import { readdirSync as readdirSync3, readFileSync as readFileSync10 } from "node:fs";
|
|
38944
|
-
import { join as
|
|
38994
|
+
import { join as join20 } from "node:path";
|
|
38945
38995
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
38946
38996
|
var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
38947
38997
|
function parseToolList(value) {
|
|
@@ -38975,7 +39025,7 @@ function loadDir(dir, source) {
|
|
|
38975
39025
|
}
|
|
38976
39026
|
const agents = [];
|
|
38977
39027
|
for (const name of names) {
|
|
38978
|
-
const filePath =
|
|
39028
|
+
const filePath = join20(dir, name);
|
|
38979
39029
|
try {
|
|
38980
39030
|
const agent = parseAgent(readFileSync10(filePath, "utf8"), source, filePath);
|
|
38981
39031
|
if (agent) agents.push(agent);
|
|
@@ -38994,8 +39044,8 @@ function loadAgents(userDir, builtInDir = BUILT_IN_AGENTS_DIR) {
|
|
|
38994
39044
|
|
|
38995
39045
|
// packages/kyrn-judge/src/extension/localized-prompts.ts
|
|
38996
39046
|
import { createHash as createHash4 } from "node:crypto";
|
|
38997
|
-
import { existsSync as
|
|
38998
|
-
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";
|
|
38999
39049
|
var FORMAT = 1;
|
|
39000
39050
|
var LANGUAGE_KEY = /^([A-Za-z]+(?:-[A-Za-z]+)*)-(zh|en):/;
|
|
39001
39051
|
function localizeTemplate(text9, wording) {
|
|
@@ -39033,19 +39083,19 @@ var oneLineAt = (lines2, index) => {
|
|
|
39033
39083
|
function promptsFor(dir, wording, root) {
|
|
39034
39084
|
if (wording !== "zh") return dir;
|
|
39035
39085
|
try {
|
|
39036
|
-
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")]);
|
|
39037
39087
|
const hash = createHash4("sha256").update(JSON.stringify([FORMAT, wording, sources])).digest("hex").slice(0, 12);
|
|
39038
|
-
const target =
|
|
39039
|
-
if (
|
|
39088
|
+
const target = join21(root, `${wording}-${hash}`);
|
|
39089
|
+
if (existsSync10(target)) return target;
|
|
39040
39090
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
39041
39091
|
mkdirSync9(temporary, { recursive: true, mode: 448 });
|
|
39042
|
-
for (const [name, text9] of sources) writeFileSync7(
|
|
39092
|
+
for (const [name, text9] of sources) writeFileSync7(join21(temporary, name), localizeTemplate(text9, wording));
|
|
39043
39093
|
try {
|
|
39044
39094
|
renameSync4(temporary, target);
|
|
39045
39095
|
} catch {
|
|
39046
39096
|
rmSync6(temporary, { recursive: true, force: true });
|
|
39047
39097
|
}
|
|
39048
|
-
return
|
|
39098
|
+
return existsSync10(target) ? target : dir;
|
|
39049
39099
|
} catch {
|
|
39050
39100
|
return dir;
|
|
39051
39101
|
}
|
|
@@ -39604,7 +39654,7 @@ function registerCommands(runtime, roots) {
|
|
|
39604
39654
|
const chrome = findBrowser(browserHost)?.executable;
|
|
39605
39655
|
const available = ctx.modelRegistry.getAvailable();
|
|
39606
39656
|
const providers = [...new Set(available.map((model) => model.provider))];
|
|
39607
|
-
const agentsDir =
|
|
39657
|
+
const agentsDir = join22((0, import_pi_coding_agent5.getAgentDir)(), "agents");
|
|
39608
39658
|
const roles = loadAgents(agentsDir);
|
|
39609
39659
|
const ladder = runtime.options("swarm", { enabled: true, models: [] }).models;
|
|
39610
39660
|
const missing = ladder.filter((ref) => {
|
|
@@ -39667,10 +39717,10 @@ function registerCommands(runtime, roots) {
|
|
|
39667
39717
|
pi.on(
|
|
39668
39718
|
"resources_discover",
|
|
39669
39719
|
failOpen(
|
|
39670
|
-
() =>
|
|
39720
|
+
() => existsSync11(PROMPTS_DIR) ? {
|
|
39671
39721
|
promptPaths: [
|
|
39672
39722
|
// In mu's own folder, which is the user's alone: a template is text the model follows.
|
|
39673
|
-
roots ? promptsFor(PROMPTS_DIR, appLanguage()?.wording,
|
|
39723
|
+
roots ? promptsFor(PROMPTS_DIR, appLanguage()?.wording, join22(roots.agentDir, "mu", "prompts")) : PROMPTS_DIR
|
|
39674
39724
|
]
|
|
39675
39725
|
} : void 0
|
|
39676
39726
|
)
|
|
@@ -39681,7 +39731,7 @@ function registerCommands(runtime, roots) {
|
|
|
39681
39731
|
var import_pi_coding_agent6 = __toESM(require_pi_coding_agent(), 1);
|
|
39682
39732
|
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync8 } from "node:fs";
|
|
39683
39733
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
39684
|
-
import { join as
|
|
39734
|
+
import { join as join23 } from "node:path";
|
|
39685
39735
|
|
|
39686
39736
|
// packages/kyrn-judge/src/compaction/history.ts
|
|
39687
39737
|
function blocks(content) {
|
|
@@ -40120,11 +40170,11 @@ ${liveText}`, calls: liveCalls });
|
|
|
40120
40170
|
);
|
|
40121
40171
|
return void 0;
|
|
40122
40172
|
}
|
|
40123
|
-
const archiveDir =
|
|
40173
|
+
const archiveDir = join23(tmpdir3(), `kyrn-${runtime.sessionId}`, "compacted");
|
|
40124
40174
|
const pruned = apply(items, planned.plans, options, (call) => {
|
|
40125
40175
|
try {
|
|
40126
40176
|
mkdirSync10(archiveDir, { recursive: true });
|
|
40127
|
-
const path =
|
|
40177
|
+
const path = join23(archiveDir, `${call.id.replace(/[^\w.-]/g, "_")}.txt`);
|
|
40128
40178
|
writeFileSync8(path, call.result, { mode: 384 });
|
|
40129
40179
|
return path;
|
|
40130
40180
|
} catch {
|
|
@@ -41344,9 +41394,9 @@ last update failed: ${lastFailure}` : text9, "info");
|
|
|
41344
41394
|
|
|
41345
41395
|
// packages/kyrn-judge/src/extension/features/notices.ts
|
|
41346
41396
|
import { readFileSync as readFileSync13 } from "node:fs";
|
|
41347
|
-
import { join as
|
|
41397
|
+
import { join as join24 } from "node:path";
|
|
41348
41398
|
function noticesFile(agentDir) {
|
|
41349
|
-
return
|
|
41399
|
+
return join24(agentDir, "mu", "notices.json");
|
|
41350
41400
|
}
|
|
41351
41401
|
function readNotices(file) {
|
|
41352
41402
|
if (!file) return {};
|
|
@@ -42719,7 +42769,7 @@ var import_pi_coding_agent8 = __toESM(require_pi_coding_agent(), 1);
|
|
|
42719
42769
|
var import_typebox7 = __toESM(require_typebox(), 1);
|
|
42720
42770
|
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
42721
42771
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
42722
|
-
import { join as
|
|
42772
|
+
import { join as join30 } from "node:path";
|
|
42723
42773
|
|
|
42724
42774
|
// packages/kyrn-judge/src/decisions/hive.ts
|
|
42725
42775
|
var hivePublish = defineDecision({
|
|
@@ -42824,7 +42874,7 @@ var hiveRelate = defineDecision({
|
|
|
42824
42874
|
|
|
42825
42875
|
// packages/kyrn-judge/src/hive/board.ts
|
|
42826
42876
|
import { appendFileSync as appendFileSync3, closeSync as closeSync2, fstatSync, mkdirSync as mkdirSync11, openSync as openSync2, readSync as readSync2 } from "node:fs";
|
|
42827
|
-
import { join as
|
|
42877
|
+
import { join as join25 } from "node:path";
|
|
42828
42878
|
var BOARD = "board.jsonl";
|
|
42829
42879
|
var DELIVERIES = "deliveries.jsonl";
|
|
42830
42880
|
var RELATIONS = "relations.jsonl";
|
|
@@ -42869,41 +42919,41 @@ var Board = class {
|
|
|
42869
42919
|
mkdirSync11(dir, { recursive: true });
|
|
42870
42920
|
}
|
|
42871
42921
|
post(note2) {
|
|
42872
|
-
appendFileSync3(
|
|
42922
|
+
appendFileSync3(join25(this.dir, BOARD), `${JSON.stringify(note2)}
|
|
42873
42923
|
`);
|
|
42874
42924
|
}
|
|
42875
42925
|
/** Notes appended since the last call on this instance. */
|
|
42876
42926
|
fresh() {
|
|
42877
|
-
const read2 = readFrom(
|
|
42927
|
+
const read2 = readFrom(join25(this.dir, BOARD), this.offset);
|
|
42878
42928
|
this.offset = read2.offset;
|
|
42879
42929
|
return read2.rows;
|
|
42880
42930
|
}
|
|
42881
42931
|
all() {
|
|
42882
|
-
return readFrom(
|
|
42932
|
+
return readFrom(join25(this.dir, BOARD), 0).rows;
|
|
42883
42933
|
}
|
|
42884
42934
|
delivered(delivery) {
|
|
42885
|
-
appendFileSync3(
|
|
42935
|
+
appendFileSync3(join25(this.dir, DELIVERIES), `${JSON.stringify(delivery)}
|
|
42886
42936
|
`);
|
|
42887
42937
|
}
|
|
42888
42938
|
/** Every verdict of the gates, passed or not: the answer to "why did nobody hear about this?". */
|
|
42889
42939
|
log(entry) {
|
|
42890
|
-
appendFileSync3(
|
|
42940
|
+
appendFileSync3(join25(this.dir, "gate.jsonl"), `${JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), ...entry })}
|
|
42891
42941
|
`);
|
|
42892
42942
|
}
|
|
42893
42943
|
deliveries() {
|
|
42894
|
-
return readFrom(
|
|
42944
|
+
return readFrom(join25(this.dir, DELIVERIES), 0).rows;
|
|
42895
42945
|
}
|
|
42896
42946
|
relate(row) {
|
|
42897
|
-
appendFileSync3(
|
|
42947
|
+
appendFileSync3(join25(this.dir, RELATIONS), `${JSON.stringify(row)}
|
|
42898
42948
|
`);
|
|
42899
42949
|
}
|
|
42900
42950
|
relations() {
|
|
42901
|
-
return readFrom(
|
|
42951
|
+
return readFrom(join25(this.dir, RELATIONS), 0).rows;
|
|
42902
42952
|
}
|
|
42903
42953
|
relationOffset = 0;
|
|
42904
42954
|
/** Relations appended since the last call on this instance. */
|
|
42905
42955
|
freshRelations() {
|
|
42906
|
-
const read2 = readFrom(
|
|
42956
|
+
const read2 = readFrom(join25(this.dir, RELATIONS), this.relationOffset);
|
|
42907
42957
|
this.relationOffset = read2.offset;
|
|
42908
42958
|
return read2.rows;
|
|
42909
42959
|
}
|
|
@@ -42911,7 +42961,7 @@ var Board = class {
|
|
|
42911
42961
|
gateRows = 0;
|
|
42912
42962
|
/** How many verdicts the gates have given so far. Counted incrementally: the log only grows. */
|
|
42913
42963
|
judged() {
|
|
42914
|
-
const read2 = readFrom(
|
|
42964
|
+
const read2 = readFrom(join25(this.dir, "gate.jsonl"), this.gateOffset);
|
|
42915
42965
|
this.gateOffset = read2.offset;
|
|
42916
42966
|
this.gateRows += read2.rows.length;
|
|
42917
42967
|
return this.gateRows;
|
|
@@ -42993,10 +43043,10 @@ var import_pi_tui3 = __toESM(require_pi_tui(), 1);
|
|
|
42993
43043
|
var import_typebox6 = __toESM(require_typebox(), 1);
|
|
42994
43044
|
import { spawn as spawn6 } from "node:child_process";
|
|
42995
43045
|
import { randomUUID as randomUUID5 } from "node:crypto";
|
|
42996
|
-
import { existsSync as
|
|
43046
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
42997
43047
|
import { mkdtemp, readFile as readFile2, rm as rm4, writeFile as writeFile2 } from "node:fs/promises";
|
|
42998
43048
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
42999
|
-
import { basename as basename6, join as
|
|
43049
|
+
import { basename as basename6, join as join29 } from "node:path";
|
|
43000
43050
|
|
|
43001
43051
|
// packages/kyrn-judge/src/decisions/swarm-routing.ts
|
|
43002
43052
|
var SCORES = {
|
|
@@ -43061,13 +43111,13 @@ var swarmRouting = defineDecision({
|
|
|
43061
43111
|
import { randomBytes } from "node:crypto";
|
|
43062
43112
|
import { mkdirSync as mkdirSync12, readFileSync as readFileSync14, writeFileSync as writeFileSync9 } from "node:fs";
|
|
43063
43113
|
import { rm as rm2 } from "node:fs/promises";
|
|
43064
|
-
import { join as
|
|
43114
|
+
import { join as join27 } from "node:path";
|
|
43065
43115
|
|
|
43066
43116
|
// packages/kyrn-judge/src/swarm/worktree.ts
|
|
43067
43117
|
import { spawn as spawn5 } from "node:child_process";
|
|
43068
|
-
import { existsSync as
|
|
43118
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
43069
43119
|
import { chmod, copyFile, lstat, mkdir, readdir, readFile, readlink, rm, symlink, writeFile } from "node:fs/promises";
|
|
43070
|
-
import { dirname as
|
|
43120
|
+
import { dirname as dirname6, join as join26 } from "node:path";
|
|
43071
43121
|
function gitArgs(args, platform = process.platform) {
|
|
43072
43122
|
return [
|
|
43073
43123
|
"-c",
|
|
@@ -43149,7 +43199,7 @@ async function checkRepo(run2, cwd) {
|
|
|
43149
43199
|
if (where2.code !== 0) return { ok: false, problem: "not-a-repo", message: lastLine(where2.stderr) };
|
|
43150
43200
|
if (head.code !== 0) return { ok: false, problem: "no-commit", message: "the repository has no commits yet" };
|
|
43151
43201
|
const [root, gitDir, prefix = ""] = text5(where2).replace(/\n$/, "").split("\n");
|
|
43152
|
-
const busy = BUSY.find(([name]) =>
|
|
43202
|
+
const busy = BUSY.find(([name]) => existsSync12(join26(gitDir, name)));
|
|
43153
43203
|
if (busy) return { ok: false, problem: "busy", message: `${busy[1]} is in progress in this repository` };
|
|
43154
43204
|
return { ok: true, repo: { root, gitDir, prefix, head: text5(head).trim() } };
|
|
43155
43205
|
}
|
|
@@ -43172,14 +43222,14 @@ async function copyUntracked(from, to, paths, maxBytes) {
|
|
|
43172
43222
|
for (const path of paths) {
|
|
43173
43223
|
if (path.endsWith("/")) continue;
|
|
43174
43224
|
try {
|
|
43175
|
-
const stat = await lstat(
|
|
43176
|
-
await mkdir(
|
|
43177
|
-
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));
|
|
43178
43228
|
else if (!stat.isFile()) continue;
|
|
43179
43229
|
else if (stat.size > maxBytes) {
|
|
43180
43230
|
report3.skipped.push(path);
|
|
43181
43231
|
continue;
|
|
43182
|
-
} else await copyFile(
|
|
43232
|
+
} else await copyFile(join26(from, path), join26(to, path));
|
|
43183
43233
|
report3.untracked++;
|
|
43184
43234
|
} catch {
|
|
43185
43235
|
report3.skipped.push(path);
|
|
@@ -43191,7 +43241,7 @@ async function createWorktree(run2, options) {
|
|
|
43191
43241
|
const { repo, dir, branch, signal } = options;
|
|
43192
43242
|
const added = await run2(["worktree", "add", "-b", branch, dir, repo.head], { cwd: repo.root, signal });
|
|
43193
43243
|
if (added.code !== 0) return { ok: false, message: `git worktree add failed: ${lastLine(added.stderr)}` };
|
|
43194
|
-
const worktree = { repoRoot: repo.root, dir, branch, base: "", cwd:
|
|
43244
|
+
const worktree = { repoRoot: repo.root, dir, branch, base: "", cwd: join26(dir, repo.prefix) };
|
|
43195
43245
|
const fail = async (message) => {
|
|
43196
43246
|
await removeWorktree(run2, worktree);
|
|
43197
43247
|
return { ok: false, message };
|
|
@@ -43296,11 +43346,11 @@ async function removeWorktree(run2, worktree) {
|
|
|
43296
43346
|
const problems = [];
|
|
43297
43347
|
const cwd = worktree.repoRoot;
|
|
43298
43348
|
let removed = await run2(["worktree", "remove", "--force", worktree.dir], { cwd });
|
|
43299
|
-
if (removed.code !== 0 ||
|
|
43349
|
+
if (removed.code !== 0 || existsSync12(worktree.dir)) {
|
|
43300
43350
|
await rm(worktree.dir, { recursive: true, force: true, maxRetries: 8, retryDelay: 250 }).catch(() => void 0);
|
|
43301
43351
|
removed = await run2(["worktree", "remove", "--force", worktree.dir], { cwd });
|
|
43302
43352
|
if (removed.code !== 0) await run2(["worktree", "prune"], { cwd });
|
|
43303
|
-
if (
|
|
43353
|
+
if (existsSync12(worktree.dir)) problems.push(`could not delete ${worktree.dir}`);
|
|
43304
43354
|
}
|
|
43305
43355
|
const listed2 = await run2(["branch", "--list", worktree.branch], { cwd });
|
|
43306
43356
|
if (text5(listed2).trim()) {
|
|
@@ -43311,8 +43361,8 @@ async function removeWorktree(run2, worktree) {
|
|
|
43311
43361
|
}
|
|
43312
43362
|
var markerPath = (dir) => `${dir}.json`;
|
|
43313
43363
|
async function writeMarker(marker) {
|
|
43314
|
-
await mkdir(
|
|
43315
|
-
await chmod(
|
|
43364
|
+
await mkdir(dirname6(marker.dir), { recursive: true });
|
|
43365
|
+
await chmod(dirname6(marker.dir), 448).catch(() => void 0);
|
|
43316
43366
|
await writeFile(markerPath(marker.dir), JSON.stringify(marker), { mode: 384 });
|
|
43317
43367
|
}
|
|
43318
43368
|
var RUN_DIR = /^kyrn-swarm-[\w-]+$/;
|
|
@@ -43332,9 +43382,9 @@ async function sweepStaleWorktrees(run2, options) {
|
|
|
43332
43382
|
const swept = [];
|
|
43333
43383
|
const runs = await readdir(options.area).catch(() => []);
|
|
43334
43384
|
for (const name of runs.filter((entry) => RUN_DIR.test(entry))) {
|
|
43335
|
-
const entries = await readdir(
|
|
43385
|
+
const entries = await readdir(join26(options.area, name)).catch(() => []);
|
|
43336
43386
|
for (const file of entries.filter((entry) => MARKER.test(entry))) {
|
|
43337
|
-
const path =
|
|
43387
|
+
const path = join26(options.area, name, file);
|
|
43338
43388
|
let marker;
|
|
43339
43389
|
try {
|
|
43340
43390
|
marker = JSON.parse(await readFile(path, "utf8"));
|
|
@@ -43344,9 +43394,9 @@ async function sweepStaleWorktrees(run2, options) {
|
|
|
43344
43394
|
if (markerPath(marker.dir) !== path || typeof marker.repoRoot !== "string") continue;
|
|
43345
43395
|
const stale = marker.released || !alive(marker.pid) || now - marker.createdAt > maxAge;
|
|
43346
43396
|
if (!stale) continue;
|
|
43347
|
-
if (
|
|
43397
|
+
if (existsSync12(marker.repoRoot)) await removeWorktree(run2, marker);
|
|
43348
43398
|
else await rm(marker.dir, { recursive: true, force: true }).catch(() => void 0);
|
|
43349
|
-
if (!
|
|
43399
|
+
if (!existsSync12(marker.dir)) {
|
|
43350
43400
|
await rm(path, { force: true }).catch(() => void 0);
|
|
43351
43401
|
swept.push(marker);
|
|
43352
43402
|
}
|
|
@@ -43367,7 +43417,7 @@ var PatchStore = class {
|
|
|
43367
43417
|
const record4 = {
|
|
43368
43418
|
...details,
|
|
43369
43419
|
id,
|
|
43370
|
-
path:
|
|
43420
|
+
path: join27(dir, `${id}.patch`),
|
|
43371
43421
|
createdAt: Date.now(),
|
|
43372
43422
|
status: "ready"
|
|
43373
43423
|
};
|
|
@@ -43463,7 +43513,7 @@ async function applyPatch(run2, options) {
|
|
|
43463
43513
|
const touched = [...new Set(options.files.flatMap((file) => file.from ? [file.from, file.path] : [file.path]))];
|
|
43464
43514
|
const scratch = [];
|
|
43465
43515
|
const attempt = async (cached) => {
|
|
43466
|
-
const index =
|
|
43516
|
+
const index = join27(options.scratchDir, `index-${randomBytes(4).toString("hex")}`);
|
|
43467
43517
|
scratch.push(index, `${index}.lock`);
|
|
43468
43518
|
const env = { GIT_INDEX_FILE: index };
|
|
43469
43519
|
const input = Buffer.from(touched.map((path) => `${path}\0`).join(""), "utf8");
|
|
@@ -43657,7 +43707,7 @@ function swarmText(snapshot2, options) {
|
|
|
43657
43707
|
var import_typebox5 = __toESM(require_typebox(), 1);
|
|
43658
43708
|
import { rm as rm3 } from "node:fs/promises";
|
|
43659
43709
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
43660
|
-
import { basename as basename5, dirname as
|
|
43710
|
+
import { basename as basename5, dirname as dirname7, join as join28 } from "node:path";
|
|
43661
43711
|
|
|
43662
43712
|
// packages/kyrn-judge/src/decisions/swarm-patch.ts
|
|
43663
43713
|
var MAX_JUDGED_FILES = 12;
|
|
@@ -43764,7 +43814,7 @@ var Isolation = class {
|
|
|
43764
43814
|
if (index === void 0) return runner(task, assignment, signal, env, observer);
|
|
43765
43815
|
const outcome = { isolated: false, notes: [] };
|
|
43766
43816
|
outcomes.set(task, outcome);
|
|
43767
|
-
const dir =
|
|
43817
|
+
const dir = join28(context.runDir, `w${index}`);
|
|
43768
43818
|
const marker = {
|
|
43769
43819
|
repoRoot: context.repo.root,
|
|
43770
43820
|
dir,
|
|
@@ -43817,7 +43867,7 @@ You work in an isolated copy of the repository (${worktree.dir}). Use paths rela
|
|
|
43817
43867
|
}));
|
|
43818
43868
|
if (!collected.ok) outcome.notes.push(`Its changes could not be collected: ${collected.message}`);
|
|
43819
43869
|
else if (collected.summary.files.length > 0) {
|
|
43820
|
-
outcome.patch = this.store.save(
|
|
43870
|
+
outcome.patch = this.store.save(join28(context.runDir, "patches"), collected.patch, {
|
|
43821
43871
|
task: task.title,
|
|
43822
43872
|
role: assignment.agent?.name,
|
|
43823
43873
|
repoRoot: context.repo.root,
|
|
@@ -43954,7 +44004,7 @@ ${statLines(record4.summary, 200).join("\n")}`);
|
|
|
43954
44004
|
patchPath: record4.path,
|
|
43955
44005
|
files: record4.summary.files,
|
|
43956
44006
|
onConflict: params.conflicts ?? "abort",
|
|
43957
|
-
scratchDir:
|
|
44007
|
+
scratchDir: join28(dirname7(record4.path), "scratch"),
|
|
43958
44008
|
signal
|
|
43959
44009
|
});
|
|
43960
44010
|
const details = { id: record4.id, result };
|
|
@@ -44070,7 +44120,7 @@ async function routeTasks(runtime, inputs, signal) {
|
|
|
44070
44120
|
}
|
|
44071
44121
|
function piInvocation(args) {
|
|
44072
44122
|
const script = process.argv[1];
|
|
44073
|
-
if (script &&
|
|
44123
|
+
if (script && existsSync13(script)) return { command: process.execPath, args: [...process.execArgv, script, ...args] };
|
|
44074
44124
|
const generic = /^(node|bun)(\.exe)?$/.test(basename6(process.execPath).toLowerCase());
|
|
44075
44125
|
return generic ? { command: "pi", args } : { command: process.execPath, args };
|
|
44076
44126
|
}
|
|
@@ -44128,7 +44178,7 @@ function settledEnv(runtime) {
|
|
|
44128
44178
|
return env;
|
|
44129
44179
|
}
|
|
44130
44180
|
function frameOutPath(dir, index) {
|
|
44131
|
-
return
|
|
44181
|
+
return join29(dir, "control", `frame-${index}.json`);
|
|
44132
44182
|
}
|
|
44133
44183
|
async function readFrameOut(path) {
|
|
44134
44184
|
try {
|
|
@@ -44147,8 +44197,8 @@ var spawnRunner = async (task, assignment, signal, env, observer) => {
|
|
|
44147
44197
|
let promptDir;
|
|
44148
44198
|
let promptPath;
|
|
44149
44199
|
if (assignment.agent?.systemPrompt) {
|
|
44150
|
-
promptDir = await mkdtemp(
|
|
44151
|
-
promptPath =
|
|
44200
|
+
promptDir = await mkdtemp(join29(tmpdir5(), "kyrn-agent-"));
|
|
44201
|
+
promptPath = join29(promptDir, `${assignment.agent.name}.md`);
|
|
44152
44202
|
await writeFile2(promptPath, assignment.agent.systemPrompt, { encoding: "utf8", mode: 384 });
|
|
44153
44203
|
}
|
|
44154
44204
|
try {
|
|
@@ -44359,7 +44409,7 @@ function registerSwarm(runtime, runner = spawnRunner) {
|
|
|
44359
44409
|
const { pi } = runtime;
|
|
44360
44410
|
const isolation = new Isolation(runtime, options);
|
|
44361
44411
|
isolation.registerTool();
|
|
44362
|
-
const agents = () => loadAgents(options.agentsDir ||
|
|
44412
|
+
const agents = () => loadAgents(options.agentsDir || join29((0, import_pi_coding_agent7.getAgentDir)(), "agents"));
|
|
44363
44413
|
const usable = () => {
|
|
44364
44414
|
const known = new Set(pi.getAllTools().map((tool) => tool.name));
|
|
44365
44415
|
return agents().filter((agent) => !agent.tools || agent.tools.some((tool) => known.has(tool)));
|
|
@@ -44462,7 +44512,7 @@ function registerSwarm(runtime, runner = spawnRunner) {
|
|
|
44462
44512
|
routedBy: named ? "caller" : judged ? "judge" : "default"
|
|
44463
44513
|
};
|
|
44464
44514
|
});
|
|
44465
|
-
const runDir =
|
|
44515
|
+
const runDir = join29(tmpdir5(), `kyrn-swarm-${randomUUID5().slice(0, 8)}`);
|
|
44466
44516
|
const isolated = /* @__PURE__ */ new Map();
|
|
44467
44517
|
tasks.forEach((task, index) => {
|
|
44468
44518
|
const asked = params.tasks[index].isolation ?? (params.chain ? "none" : void 0);
|
|
@@ -44552,7 +44602,7 @@ ${checklist}` : ""}${isolation.describe(outcomesOfIsolation.get(task))}`;
|
|
|
44552
44602
|
en: "List the subagent roles the delegate tool can use, and where to add your own"
|
|
44553
44603
|
}),
|
|
44554
44604
|
handler: async (_args, ctx) => {
|
|
44555
|
-
const dir = options.agentsDir ||
|
|
44605
|
+
const dir = options.agentsDir || join29((0, import_pi_coding_agent7.getAgentDir)(), "agents");
|
|
44556
44606
|
const ladder = options.models.length > 0 ? options.models.join(" < ") : "the session's current model";
|
|
44557
44607
|
ctx.ui.notify(
|
|
44558
44608
|
[
|
|
@@ -44998,9 +45048,9 @@ function registerHive(runtime, runner = spawnRunner) {
|
|
|
44998
45048
|
const names = uniqueNames(asked.map((bee) => bee.name));
|
|
44999
45049
|
const bees = asked.map((bee, at) => ({ ...bee, name: names[at] }));
|
|
45000
45050
|
announceRouting(onUpdate, bees.length);
|
|
45001
|
-
const dir =
|
|
45051
|
+
const dir = join30(tmpdir6(), `kyrn-hive-${randomUUID6().slice(0, 8)}`);
|
|
45002
45052
|
const board = new Board(dir);
|
|
45003
|
-
const roles = new Map(loadAgents(
|
|
45053
|
+
const roles = new Map(loadAgents(join30((0, import_pi_coding_agent8.getAgentDir)(), "agents")).map((agent) => [agent.name, agent]));
|
|
45004
45054
|
const swarm = runtime.options("swarm", { enabled: true, models: [] });
|
|
45005
45055
|
const ladder = options.models.length > 0 ? options.models : swarm.models;
|
|
45006
45056
|
const current = ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : void 0;
|
|
@@ -45198,7 +45248,7 @@ ${reports[at]}`;
|
|
|
45198
45248
|
}),
|
|
45199
45249
|
`## Hive board: ${counts}
|
|
45200
45250
|
${sections.join("\n")}
|
|
45201
|
-
(every verdict of the gates: ${
|
|
45251
|
+
(every verdict of the gates: ${join30(dir, "gate.jsonl")})`
|
|
45202
45252
|
].join("\n\n");
|
|
45203
45253
|
return {
|
|
45204
45254
|
content: [{ type: "text", text: text9 }],
|
|
@@ -45346,7 +45396,7 @@ var import_pi_tui4 = __toESM(require_pi_tui(), 1);
|
|
|
45346
45396
|
// packages/kyrn-judge/src/import/index.ts
|
|
45347
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";
|
|
45348
45398
|
import { homedir as homedir7 } from "node:os";
|
|
45349
|
-
import { join as
|
|
45399
|
+
import { join as join33 } from "node:path";
|
|
45350
45400
|
|
|
45351
45401
|
// packages/kyrn-judge/src/import/claude-code.ts
|
|
45352
45402
|
import { statSync as statSync8 } from "node:fs";
|
|
@@ -45470,7 +45520,7 @@ function list2(value) {
|
|
|
45470
45520
|
import { createHash as createHash5, randomBytes as randomBytes2, randomUUID as randomUUID7 } from "node:crypto";
|
|
45471
45521
|
import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync5, renameSync as renameSync6, rmSync as rmSync7, statSync as statSync7, writeSync } from "node:fs";
|
|
45472
45522
|
import { homedir as homedir5 } from "node:os";
|
|
45473
|
-
import { isAbsolute as isAbsolute4, join as
|
|
45523
|
+
import { isAbsolute as isAbsolute4, join as join31, resolve as resolve5 } from "node:path";
|
|
45474
45524
|
var TOOL_NAMES = {
|
|
45475
45525
|
"claude-code": "Claude Code",
|
|
45476
45526
|
codex: "Codex",
|
|
@@ -45518,7 +45568,7 @@ function uuidv7(ms = Date.now()) {
|
|
|
45518
45568
|
}
|
|
45519
45569
|
function expand(path) {
|
|
45520
45570
|
if (path === "~") return homedir5();
|
|
45521
|
-
if (path.startsWith("~/")) return
|
|
45571
|
+
if (path.startsWith("~/")) return join31(homedir5(), path.slice(2));
|
|
45522
45572
|
return path;
|
|
45523
45573
|
}
|
|
45524
45574
|
function absolute(path, base = process.cwd()) {
|
|
@@ -45527,13 +45577,13 @@ function absolute(path, base = process.cwd()) {
|
|
|
45527
45577
|
}
|
|
45528
45578
|
function defaultSessionDir(cwd, agentDir) {
|
|
45529
45579
|
const safe = `--${absolute(cwd).replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
45530
|
-
return
|
|
45580
|
+
return join31(absolute(agentDir), "sessions", safe);
|
|
45531
45581
|
}
|
|
45532
45582
|
function sessionDirFor(cwd, store) {
|
|
45533
45583
|
return store.sessionDir ? absolute(store.sessionDir) : defaultSessionDir(cwd, store.agentDir);
|
|
45534
45584
|
}
|
|
45535
45585
|
function sessionsRoot(store) {
|
|
45536
|
-
return store.sessionDir ? absolute(store.sessionDir) :
|
|
45586
|
+
return store.sessionDir ? absolute(store.sessionDir) : join31(absolute(store.agentDir), "sessions");
|
|
45537
45587
|
}
|
|
45538
45588
|
function sessionFileName(started, id) {
|
|
45539
45589
|
return `${started.replace(/[:.]/g, "-")}_${id}.jsonl`;
|
|
@@ -45573,7 +45623,7 @@ function findImports(store) {
|
|
|
45573
45623
|
return;
|
|
45574
45624
|
}
|
|
45575
45625
|
for (const name of names) {
|
|
45576
|
-
const path =
|
|
45626
|
+
const path = join31(dir, name);
|
|
45577
45627
|
if (name.endsWith(".jsonl")) files.push(path);
|
|
45578
45628
|
else if (depth > 0) {
|
|
45579
45629
|
try {
|
|
@@ -46840,9 +46890,9 @@ import { execFileSync } from "node:child_process";
|
|
|
46840
46890
|
import { statSync as statSync10 } from "node:fs";
|
|
46841
46891
|
import { createRequire } from "node:module";
|
|
46842
46892
|
import { homedir as homedir6 } from "node:os";
|
|
46843
|
-
import { join as
|
|
46893
|
+
import { join as join32 } from "node:path";
|
|
46844
46894
|
function zcodeDatabase(home = homedir6()) {
|
|
46845
|
-
return
|
|
46895
|
+
return join32(home, ".zcode", "cli", "db", "db.sqlite");
|
|
46846
46896
|
}
|
|
46847
46897
|
function zcodeSource(database, id) {
|
|
46848
46898
|
return `${database}#${id}`;
|
|
@@ -47341,10 +47391,10 @@ function describeCodex(path) {
|
|
|
47341
47391
|
return { id: id ?? fromName ?? "", cwd, title: title ?? command ?? "", started, subAgent };
|
|
47342
47392
|
}
|
|
47343
47393
|
function claudeProjectsDir(env = process.env, home = homedir7()) {
|
|
47344
|
-
return
|
|
47394
|
+
return join33(env.CLAUDE_CONFIG_DIR ? absolute(env.CLAUDE_CONFIG_DIR) : join33(home, ".claude"), "projects");
|
|
47345
47395
|
}
|
|
47346
47396
|
function codexSessionsDir(env = process.env, home = homedir7()) {
|
|
47347
|
-
return
|
|
47397
|
+
return join33(env.CODEX_HOME ? absolute(env.CODEX_HOME) : join33(home, ".codex"), "sessions");
|
|
47348
47398
|
}
|
|
47349
47399
|
function sameFolder(a, b) {
|
|
47350
47400
|
const canonical2 = (dir) => {
|
|
@@ -47366,7 +47416,7 @@ function jsonlFiles(dir, depth) {
|
|
|
47366
47416
|
}
|
|
47367
47417
|
const files = [];
|
|
47368
47418
|
for (const name of names.sort()) {
|
|
47369
|
-
const path =
|
|
47419
|
+
const path = join33(dir, name);
|
|
47370
47420
|
if (name.endsWith(".jsonl")) files.push(path);
|
|
47371
47421
|
else if (depth > 0 && !name.startsWith(".")) {
|
|
47372
47422
|
try {
|
|
@@ -47377,7 +47427,7 @@ function jsonlFiles(dir, depth) {
|
|
|
47377
47427
|
}
|
|
47378
47428
|
return files;
|
|
47379
47429
|
}
|
|
47380
|
-
var checksFile = (store) =>
|
|
47430
|
+
var checksFile = (store) => join33(absolute(store.agentDir), "import-checks.json");
|
|
47381
47431
|
function readChecks(store) {
|
|
47382
47432
|
try {
|
|
47383
47433
|
const checks = record(JSON.parse(readFileSync16(checksFile(store), "utf8"))) ?? {};
|
|
@@ -47413,7 +47463,7 @@ function listConversations(options = {}) {
|
|
|
47413
47463
|
} catch {
|
|
47414
47464
|
}
|
|
47415
47465
|
for (const project of projects) {
|
|
47416
|
-
for (const path of jsonlFiles(
|
|
47466
|
+
for (const path of jsonlFiles(join33(claudeProjects, project), 0)) candidates.push({ tool: "claude-code", path });
|
|
47417
47467
|
}
|
|
47418
47468
|
for (const path of jsonlFiles(codexSessions, 4)) candidates.push({ tool: "codex", path });
|
|
47419
47469
|
const imports = options.store ? findImports(options.store) : [];
|
|
@@ -47565,7 +47615,7 @@ async function importOne(path, options, imports, checks) {
|
|
|
47565
47615
|
if (earlier) converted = await read(tool, source, readOptions());
|
|
47566
47616
|
const dir = sessionDirFor(converted.cwd, options);
|
|
47567
47617
|
mkdirSync13(dir, { recursive: true });
|
|
47568
|
-
const sessionFile =
|
|
47618
|
+
const sessionFile = join33(dir, sessionFileName(converted.started, converted.sessionId));
|
|
47569
47619
|
writeSessionFile(sessionFile, converted.entries);
|
|
47570
47620
|
imports.push({
|
|
47571
47621
|
sessionFile,
|
|
@@ -47769,11 +47819,11 @@ ${theme.fg("dim", detail)}`, 0, 0));
|
|
|
47769
47819
|
}
|
|
47770
47820
|
|
|
47771
47821
|
// packages/kyrn-judge/src/extension/features/inherit.ts
|
|
47772
|
-
import { isAbsolute as isAbsolute5, join as
|
|
47822
|
+
import { isAbsolute as isAbsolute5, join as join39, resolve as resolve8 } from "node:path";
|
|
47773
47823
|
|
|
47774
47824
|
// packages/kyrn-judge/src/inherit/files.ts
|
|
47775
|
-
import { existsSync as
|
|
47776
|
-
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";
|
|
47777
47827
|
var MAX_FILE_BYTES = 2 * 1024 * 1024;
|
|
47778
47828
|
function projectChain(projectDir, home) {
|
|
47779
47829
|
const start = resolve6(projectDir);
|
|
@@ -47783,8 +47833,8 @@ function projectChain(projectDir, home) {
|
|
|
47783
47833
|
for (let depth = 0; depth < 32; depth++) {
|
|
47784
47834
|
if (current === homeDir) break;
|
|
47785
47835
|
chain.push(current);
|
|
47786
|
-
if (
|
|
47787
|
-
const parent =
|
|
47836
|
+
if (existsSync14(join34(current, ".git"))) return chain;
|
|
47837
|
+
const parent = dirname8(current);
|
|
47788
47838
|
if (parent === current) break;
|
|
47789
47839
|
current = parent;
|
|
47790
47840
|
}
|
|
@@ -47819,7 +47869,7 @@ function listFiles(dir, extensions, depth = 4) {
|
|
|
47819
47869
|
}
|
|
47820
47870
|
for (const name of names) {
|
|
47821
47871
|
if (name.startsWith(".") || name === "node_modules") continue;
|
|
47822
|
-
const path =
|
|
47872
|
+
const path = join34(dir, name);
|
|
47823
47873
|
let stats;
|
|
47824
47874
|
try {
|
|
47825
47875
|
stats = statSync12(path);
|
|
@@ -47843,7 +47893,7 @@ function canonical(path) {
|
|
|
47843
47893
|
}
|
|
47844
47894
|
|
|
47845
47895
|
// packages/kyrn-judge/src/inherit/rules.ts
|
|
47846
|
-
import { basename as basename9, join as
|
|
47896
|
+
import { basename as basename9, join as join35, relative as relative2 } from "node:path";
|
|
47847
47897
|
|
|
47848
47898
|
// packages/kyrn-judge/src/inherit/frontmatter.ts
|
|
47849
47899
|
function unquote(value) {
|
|
@@ -48003,15 +48053,15 @@ function discoverRules(roots, switches, problems) {
|
|
|
48003
48053
|
const files = [];
|
|
48004
48054
|
const projectDirs = roots.projectTrusted ? projectChain(roots.projectDir, roots.home) : [];
|
|
48005
48055
|
if (switches.claude) {
|
|
48006
|
-
const userDir =
|
|
48056
|
+
const userDir = join35(roots.home, ".claude");
|
|
48007
48057
|
files.push({
|
|
48008
|
-
path:
|
|
48058
|
+
path: join35(userDir, "CLAUDE.md"),
|
|
48009
48059
|
tool: "claude",
|
|
48010
48060
|
scope: "user",
|
|
48011
48061
|
baseDir: roots.projectDir,
|
|
48012
48062
|
alwaysByDefault: true
|
|
48013
48063
|
});
|
|
48014
|
-
for (const path of listFiles(
|
|
48064
|
+
for (const path of listFiles(join35(userDir, "rules"), [".md"])) {
|
|
48015
48065
|
files.push({
|
|
48016
48066
|
path,
|
|
48017
48067
|
tool: "claude",
|
|
@@ -48023,10 +48073,10 @@ function discoverRules(roots, switches, problems) {
|
|
|
48023
48073
|
}
|
|
48024
48074
|
}
|
|
48025
48075
|
if (switches.codex) {
|
|
48026
|
-
const override =
|
|
48076
|
+
const override = join35(roots.home, ".codex", "AGENTS.override.md");
|
|
48027
48077
|
const hasOverride = readText(override, []) !== void 0;
|
|
48028
48078
|
files.push({
|
|
48029
|
-
path: hasOverride ? override :
|
|
48079
|
+
path: hasOverride ? override : join35(roots.home, ".codex", "AGENTS.md"),
|
|
48030
48080
|
tool: "codex",
|
|
48031
48081
|
scope: "user",
|
|
48032
48082
|
baseDir: roots.projectDir,
|
|
@@ -48036,13 +48086,13 @@ function discoverRules(roots, switches, problems) {
|
|
|
48036
48086
|
for (const dir of [...projectDirs].reverse()) {
|
|
48037
48087
|
if (switches.claude) {
|
|
48038
48088
|
files.push({
|
|
48039
|
-
path:
|
|
48089
|
+
path: join35(dir, ".claude", "CLAUDE.md"),
|
|
48040
48090
|
tool: "claude",
|
|
48041
48091
|
scope: "project",
|
|
48042
48092
|
baseDir: dir,
|
|
48043
48093
|
alwaysByDefault: true
|
|
48044
48094
|
});
|
|
48045
|
-
for (const path of listFiles(
|
|
48095
|
+
for (const path of listFiles(join35(dir, ".claude", "rules"), [".md"])) {
|
|
48046
48096
|
files.push({
|
|
48047
48097
|
path,
|
|
48048
48098
|
tool: "claude",
|
|
@@ -48055,13 +48105,13 @@ function discoverRules(roots, switches, problems) {
|
|
|
48055
48105
|
}
|
|
48056
48106
|
if (switches.cursor) {
|
|
48057
48107
|
files.push({
|
|
48058
|
-
path:
|
|
48108
|
+
path: join35(dir, ".cursorrules"),
|
|
48059
48109
|
tool: "cursor",
|
|
48060
48110
|
scope: "project",
|
|
48061
48111
|
baseDir: dir,
|
|
48062
48112
|
alwaysByDefault: true
|
|
48063
48113
|
});
|
|
48064
|
-
for (const path of listFiles(
|
|
48114
|
+
for (const path of listFiles(join35(dir, ".cursor", "rules"), [".mdc", ".md"])) {
|
|
48065
48115
|
files.push({
|
|
48066
48116
|
path,
|
|
48067
48117
|
tool: "cursor",
|
|
@@ -48098,10 +48148,10 @@ function rulesForFile(rules, filePath) {
|
|
|
48098
48148
|
|
|
48099
48149
|
// packages/kyrn-judge/src/inherit/scan.ts
|
|
48100
48150
|
import { mkdirSync as mkdirSync14, readFileSync as readFileSync18, writeFileSync as writeFileSync12 } from "node:fs";
|
|
48101
|
-
import { dirname as
|
|
48151
|
+
import { dirname as dirname9, join as join38 } from "node:path";
|
|
48102
48152
|
|
|
48103
48153
|
// packages/kyrn-judge/src/inherit/mcp-config.ts
|
|
48104
|
-
import { join as
|
|
48154
|
+
import { join as join36, resolve as resolve7 } from "node:path";
|
|
48105
48155
|
|
|
48106
48156
|
// packages/kyrn-judge/src/inherit/json-members.ts
|
|
48107
48157
|
var QUOTE = 34;
|
|
@@ -48543,7 +48593,7 @@ function discoverMcpServers(options, problems) {
|
|
|
48543
48593
|
const inherit = switches.mcp;
|
|
48544
48594
|
let disabledInClaude = /* @__PURE__ */ new Set();
|
|
48545
48595
|
if (inherit && switches.claude) {
|
|
48546
|
-
const path =
|
|
48596
|
+
const path = join36(roots.home, ".claude.json");
|
|
48547
48597
|
const dirs = [resolve7(roots.projectDir), ...chain.slice(1)];
|
|
48548
48598
|
const wanted = new Set(dirs.map((dir) => pathKey(dir, platform)));
|
|
48549
48599
|
const config = parseJson(path, problems, {
|
|
@@ -48568,11 +48618,11 @@ function discoverMcpServers(options, problems) {
|
|
|
48568
48618
|
}
|
|
48569
48619
|
}
|
|
48570
48620
|
if (inherit && switches.cursor) {
|
|
48571
|
-
const path =
|
|
48621
|
+
const path = join36(roots.home, ".cursor", "mcp.json");
|
|
48572
48622
|
add(parseJson(path, problems, { mcpServers: true })?.mcpServers, { source: path, tool: "cursor", scope: "user" });
|
|
48573
48623
|
}
|
|
48574
48624
|
if (inherit && switches.codex) {
|
|
48575
|
-
const path =
|
|
48625
|
+
const path = join36(roots.home, ".codex", "config.toml");
|
|
48576
48626
|
const text9 = readText(path, problems);
|
|
48577
48627
|
if (text9 !== void 0) {
|
|
48578
48628
|
try {
|
|
@@ -48584,11 +48634,11 @@ function discoverMcpServers(options, problems) {
|
|
|
48584
48634
|
}
|
|
48585
48635
|
}
|
|
48586
48636
|
if (inherit) {
|
|
48587
|
-
const userFiles = /* @__PURE__ */ new Set([resolve7(
|
|
48637
|
+
const userFiles = /* @__PURE__ */ new Set([resolve7(join36(roots.home, ".cursor", "mcp.json"))]);
|
|
48588
48638
|
for (const dir of chain) {
|
|
48589
48639
|
const files = [
|
|
48590
|
-
{ path:
|
|
48591
|
-
{ path:
|
|
48640
|
+
{ path: join36(dir, ".mcp.json"), tool: "claude", on: switches.claude },
|
|
48641
|
+
{ path: join36(dir, ".cursor", "mcp.json"), tool: "cursor", on: switches.cursor }
|
|
48592
48642
|
];
|
|
48593
48643
|
for (const file of files) {
|
|
48594
48644
|
if (!file.on || userFiles.has(resolve7(file.path))) continue;
|
|
@@ -48635,9 +48685,9 @@ function expandPlaceholders(value, context) {
|
|
|
48635
48685
|
// packages/kyrn-judge/src/inherit/skills.ts
|
|
48636
48686
|
var import_pi_coding_agent10 = __toESM(require_pi_coding_agent(), 1);
|
|
48637
48687
|
import { readdirSync as readdirSync8, statSync as statSync13 } from "node:fs";
|
|
48638
|
-
import { basename as basename10, join as
|
|
48688
|
+
import { basename as basename10, join as join37 } from "node:path";
|
|
48639
48689
|
function readSkill(dir, problems) {
|
|
48640
|
-
const file =
|
|
48690
|
+
const file = join37(dir, "SKILL.md");
|
|
48641
48691
|
const text9 = readText(file, problems, 512 * 1024);
|
|
48642
48692
|
if (text9 === void 0) return void 0;
|
|
48643
48693
|
let frontmatter;
|
|
@@ -48661,7 +48711,7 @@ function skillsBelow(root, problems, depth = 3) {
|
|
|
48661
48711
|
const skills = [];
|
|
48662
48712
|
for (const name of names) {
|
|
48663
48713
|
if (name.startsWith(".") || name === "node_modules") continue;
|
|
48664
|
-
const dir =
|
|
48714
|
+
const dir = join37(root, name);
|
|
48665
48715
|
try {
|
|
48666
48716
|
if (!statSync13(dir).isDirectory()) continue;
|
|
48667
48717
|
} catch {
|
|
@@ -48678,11 +48728,11 @@ function discoverSkills(roots, switches, problems, piSkillDirs = []) {
|
|
|
48678
48728
|
const sources = [];
|
|
48679
48729
|
if (switches.claude && roots.projectTrusted) {
|
|
48680
48730
|
for (const dir of projectChain(roots.projectDir, roots.home)) {
|
|
48681
|
-
sources.push({ dir:
|
|
48731
|
+
sources.push({ dir: join37(dir, ".claude", "skills"), tool: "claude", scope: "project" });
|
|
48682
48732
|
}
|
|
48683
48733
|
}
|
|
48684
|
-
if (switches.claude) sources.push({ dir:
|
|
48685
|
-
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" });
|
|
48686
48736
|
const names = /* @__PURE__ */ new Set();
|
|
48687
48737
|
const files = /* @__PURE__ */ new Set();
|
|
48688
48738
|
const quiet = [];
|
|
@@ -48771,7 +48821,7 @@ function inheritanceSummary(scan2) {
|
|
|
48771
48821
|
return `Inherited ${list4(parts)} from ${list4(from)}.`;
|
|
48772
48822
|
}
|
|
48773
48823
|
function inheritStatePath(agentDir) {
|
|
48774
|
-
return
|
|
48824
|
+
return join38(agentDir, "mu", "inherit.json");
|
|
48775
48825
|
}
|
|
48776
48826
|
function readInheritState(agentDir) {
|
|
48777
48827
|
try {
|
|
@@ -48786,7 +48836,7 @@ function readInheritState(agentDir) {
|
|
|
48786
48836
|
}
|
|
48787
48837
|
function writeInheritState(agentDir, state) {
|
|
48788
48838
|
const path = inheritStatePath(agentDir);
|
|
48789
|
-
mkdirSync14(
|
|
48839
|
+
mkdirSync14(dirname9(path), { recursive: true });
|
|
48790
48840
|
writeFileSync12(path, `${JSON.stringify(state, null, " ")}
|
|
48791
48841
|
`);
|
|
48792
48842
|
}
|
|
@@ -48831,9 +48881,9 @@ function inheritedFor(runtime, roots, ctx, own) {
|
|
|
48831
48881
|
mcp: !off && options.mcp
|
|
48832
48882
|
},
|
|
48833
48883
|
own,
|
|
48834
|
-
ownSource:
|
|
48884
|
+
ownSource: join39(roots.agentDir, "mu.json"),
|
|
48835
48885
|
// What pi loads by itself, so that no skill is offered twice.
|
|
48836
|
-
piSkillDirs: [
|
|
48886
|
+
piSkillDirs: [join39(roots.agentDir, "skills"), join39(roots.home, ".agents", "skills")],
|
|
48837
48887
|
env: process.env
|
|
48838
48888
|
});
|
|
48839
48889
|
}
|
|
@@ -49041,12 +49091,12 @@ function looksPoisoned(text9) {
|
|
|
49041
49091
|
var import_pi_coding_agent11 = __toESM(require_pi_coding_agent(), 1);
|
|
49042
49092
|
import { createHash as createHash6 } from "node:crypto";
|
|
49043
49093
|
import { mkdirSync as mkdirSync15, readFileSync as readFileSync19, renameSync as renameSync8, writeFileSync as writeFileSync13 } from "node:fs";
|
|
49044
|
-
import { dirname as
|
|
49094
|
+
import { dirname as dirname10, join as join40 } from "node:path";
|
|
49045
49095
|
var STORE_LIMIT = 2e3;
|
|
49046
49096
|
var VerdictStore = class {
|
|
49047
49097
|
file;
|
|
49048
49098
|
constructor(dir) {
|
|
49049
|
-
this.file =
|
|
49099
|
+
this.file = join40(dir, "tool-descriptions.json");
|
|
49050
49100
|
}
|
|
49051
49101
|
/** By key: the verdict, and when it was kept. */
|
|
49052
49102
|
read() {
|
|
@@ -49076,7 +49126,7 @@ var VerdictStore = class {
|
|
|
49076
49126
|
const newest = [...all].sort(([, a], [, b]) => b.at - a.at).slice(0, STORE_LIMIT);
|
|
49077
49127
|
const flat4 = Object.fromEntries(newest.map(([key, entry]) => [key, { ...entry.verdict, at: entry.at }]));
|
|
49078
49128
|
try {
|
|
49079
|
-
mkdirSync15(
|
|
49129
|
+
mkdirSync15(dirname10(this.file), { recursive: true });
|
|
49080
49130
|
const temp = `${this.file}.${process.pid}.tmp`;
|
|
49081
49131
|
writeFileSync13(temp, `${JSON.stringify({ version: 1, verdicts: flat4 })}
|
|
49082
49132
|
`, { mode: 384 });
|
|
@@ -50852,7 +50902,7 @@ function registerLayaNotice(runtime, skipped, roots, muHome2) {
|
|
|
50852
50902
|
var import_pi_coding_agent12 = __toESM(require_pi_coding_agent(), 1);
|
|
50853
50903
|
import { readFileSync as readFileSync20, statSync as statSync15 } from "node:fs";
|
|
50854
50904
|
import { homedir as homedir8 } from "node:os";
|
|
50855
|
-
import { join as
|
|
50905
|
+
import { join as join41, relative as relative4, resolve as resolve9 } from "node:path";
|
|
50856
50906
|
|
|
50857
50907
|
// packages/kyrn-judge/src/decisions/diagnostics-delivery.ts
|
|
50858
50908
|
var diagnosticsDelivery = defineDecision({
|
|
@@ -51036,7 +51086,7 @@ function formatReport(items, options) {
|
|
|
51036
51086
|
}
|
|
51037
51087
|
|
|
51038
51088
|
// packages/kyrn-judge/src/lsp/manager.ts
|
|
51039
|
-
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";
|
|
51040
51090
|
|
|
51041
51091
|
// packages/kyrn-judge/src/lsp/client.ts
|
|
51042
51092
|
import { spawn as spawn7 } from "node:child_process";
|
|
@@ -52011,7 +52061,7 @@ var LspManager = class {
|
|
|
52011
52061
|
}
|
|
52012
52062
|
instanceFor(server, file, cwd) {
|
|
52013
52063
|
if (!server.executable) return void 0;
|
|
52014
|
-
const root = findRoot(file, server.spec.rootMarkers, cwd,
|
|
52064
|
+
const root = findRoot(file, server.spec.rootMarkers, cwd, existsSync15, this.platform);
|
|
52015
52065
|
const key = `${server.spec.id}
|
|
52016
52066
|
${root}`;
|
|
52017
52067
|
let instance = this.instances.get(key);
|
|
@@ -52216,7 +52266,7 @@ function registerLsp(runtime) {
|
|
|
52216
52266
|
if (table && table.cwd === ctx.cwd && !refresh2) return table;
|
|
52217
52267
|
let project;
|
|
52218
52268
|
try {
|
|
52219
|
-
const file =
|
|
52269
|
+
const file = join41(ctx.cwd, import_pi_coding_agent12.CONFIG_DIR_NAME, PROJECT_SERVERS_FILE);
|
|
52220
52270
|
project = JSON.parse(readFileSync20(file, "utf8")).servers;
|
|
52221
52271
|
} catch {
|
|
52222
52272
|
project = void 0;
|
|
@@ -52321,7 +52371,7 @@ function registerLsp(runtime) {
|
|
|
52321
52371
|
const named = raw.startsWith("@") ? raw.slice(1) : raw;
|
|
52322
52372
|
const file = resolve9(
|
|
52323
52373
|
ctx.cwd,
|
|
52324
|
-
named === "~" || named.startsWith("~/") ?
|
|
52374
|
+
named === "~" || named.startsWith("~/") ? join41(homedir8(), named.slice(1)) : named
|
|
52325
52375
|
);
|
|
52326
52376
|
const { servers: specs, trusted } = servers(ctx);
|
|
52327
52377
|
const serving = manager.serving(file, specs, trusted);
|
|
@@ -52474,7 +52524,7 @@ ${report3.text}`,
|
|
|
52474
52524
|
});
|
|
52475
52525
|
if (known.ignoredProjectFile) {
|
|
52476
52526
|
lines2.push(
|
|
52477
|
-
`${
|
|
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).`
|
|
52478
52528
|
);
|
|
52479
52529
|
}
|
|
52480
52530
|
for (const problem of known.problems) lines2.push(`problem: ${problem}`);
|
|
@@ -52490,7 +52540,7 @@ ${report3.text}`,
|
|
|
52490
52540
|
// packages/kyrn-judge/src/extension/features/mcp.ts
|
|
52491
52541
|
var import_pi_coding_agent13 = __toESM(require_pi_coding_agent(), 1);
|
|
52492
52542
|
import { homedir as homedir9 } from "node:os";
|
|
52493
|
-
import { join as
|
|
52543
|
+
import { join as join43 } from "node:path";
|
|
52494
52544
|
|
|
52495
52545
|
// packages/kyrn-judge/src/mcp/environment.ts
|
|
52496
52546
|
var INHERITED2 = [
|
|
@@ -52565,7 +52615,7 @@ function capabilityId(serverName) {
|
|
|
52565
52615
|
// packages/kyrn-judge/src/mcp/store.ts
|
|
52566
52616
|
import { createHash as createHash7 } from "node:crypto";
|
|
52567
52617
|
import { mkdirSync as mkdirSync16, readFileSync as readFileSync21, renameSync as renameSync9, writeFileSync as writeFileSync14 } from "node:fs";
|
|
52568
|
-
import { join as
|
|
52618
|
+
import { join as join42, resolve as resolve10 } from "node:path";
|
|
52569
52619
|
var DESCRIPTION_LENGTH2 = 200;
|
|
52570
52620
|
function sorted(map) {
|
|
52571
52621
|
return Object.entries(map).sort(([left], [right]) => left.localeCompare(right));
|
|
@@ -52610,8 +52660,8 @@ var McpStore = class {
|
|
|
52610
52660
|
cache;
|
|
52611
52661
|
approvals;
|
|
52612
52662
|
constructor(dir) {
|
|
52613
|
-
this.cachePath = dir ?
|
|
52614
|
-
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;
|
|
52615
52665
|
this.cache = readJson(this.cachePath, { version: 1, servers: {} });
|
|
52616
52666
|
this.approvals = readJson(this.approvalPath, { version: 1, projects: {} });
|
|
52617
52667
|
}
|
|
@@ -52691,7 +52741,7 @@ function registerMcp(runtime, roots) {
|
|
|
52691
52741
|
if (!options.enabled) return;
|
|
52692
52742
|
const { pi, catalog } = runtime;
|
|
52693
52743
|
const entries = /* @__PURE__ */ new Map();
|
|
52694
|
-
const store = new McpStore(roots ?
|
|
52744
|
+
const store = new McpStore(roots ? join43(roots.agentDir, "mu") : void 0);
|
|
52695
52745
|
let scan2;
|
|
52696
52746
|
const capabilityOf2 = (entry) => ({
|
|
52697
52747
|
id: entry.id,
|
|
@@ -52963,7 +53013,7 @@ ${block.text}` };
|
|
|
52963
53013
|
// packages/kyrn-judge/src/extension/features/memory.ts
|
|
52964
53014
|
var import_typebox10 = __toESM(require_typebox(), 1);
|
|
52965
53015
|
import { randomUUID as randomUUID8 } from "node:crypto";
|
|
52966
|
-
import { basename as basename12, join as
|
|
53016
|
+
import { basename as basename12, join as join44 } from "node:path";
|
|
52967
53017
|
|
|
52968
53018
|
// packages/kyrn-judge/src/decisions/memory.ts
|
|
52969
53019
|
function describeLesson(lesson) {
|
|
@@ -53262,7 +53312,7 @@ function turnDigest(turn) {
|
|
|
53262
53312
|
|
|
53263
53313
|
// packages/kyrn-judge/src/memory/store.ts
|
|
53264
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";
|
|
53265
|
-
import { dirname as
|
|
53315
|
+
import { dirname as dirname11 } from "node:path";
|
|
53266
53316
|
var KINDS4 = ["correction", "preference", "pitfall", "workaround", "fact"];
|
|
53267
53317
|
var ORIGINS = ["user", "outcome", "model", "subagent", "command"];
|
|
53268
53318
|
var STATUSES = ["active", "retired", "superseded"];
|
|
@@ -53366,7 +53416,7 @@ function endsOpen(path) {
|
|
|
53366
53416
|
}
|
|
53367
53417
|
}
|
|
53368
53418
|
function writeLesson(path, line2) {
|
|
53369
|
-
mkdirSync17(
|
|
53419
|
+
mkdirSync17(dirname11(path), { recursive: true });
|
|
53370
53420
|
appendFileSync4(path, `${endsOpen(path) ? "\n" : ""}${JSON.stringify(line2)}
|
|
53371
53421
|
`);
|
|
53372
53422
|
}
|
|
@@ -53561,7 +53611,7 @@ function registerMemory(runtime, roots) {
|
|
|
53561
53611
|
if (!options.enabled || process.env.KYRN_SWARM_DEPTH) return;
|
|
53562
53612
|
const { pi } = runtime;
|
|
53563
53613
|
const learns = (ctx) => options.unattendedWrites || !isUnattended(ctx);
|
|
53564
|
-
const store = new LessonStore(options.path || (roots ?
|
|
53614
|
+
const store = new LessonStore(options.path || (roots ? join44(roots.agentDir, "mu", "lessons.jsonl") : void 0));
|
|
53565
53615
|
const now = () => (/* @__PURE__ */ new Date()).toISOString();
|
|
53566
53616
|
const placeOf = (ctx) => ({
|
|
53567
53617
|
cwd: ctx.cwd,
|
|
@@ -55105,7 +55155,7 @@ ${outcome.diff}`),
|
|
|
55105
55155
|
|
|
55106
55156
|
// packages/kyrn-judge/src/packs/commit.ts
|
|
55107
55157
|
import { readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
|
|
55108
|
-
import { join as
|
|
55158
|
+
import { join as join45 } from "node:path";
|
|
55109
55159
|
|
|
55110
55160
|
// packages/kyrn-judge/src/packs/git.ts
|
|
55111
55161
|
var INHERITED3 = ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_COMMON_DIR", "GIT_PREFIX"];
|
|
@@ -55591,7 +55641,7 @@ async function applyPlan(git2, repo, change, plan2, signal) {
|
|
|
55591
55641
|
undone: []
|
|
55592
55642
|
};
|
|
55593
55643
|
}
|
|
55594
|
-
const indexPath =
|
|
55644
|
+
const indexPath = join45(repo.gitDir, "index");
|
|
55595
55645
|
const savedIndex = await readFile4(indexPath).catch(() => void 0);
|
|
55596
55646
|
const made = [];
|
|
55597
55647
|
const applied = /* @__PURE__ */ new Map();
|
|
@@ -55774,12 +55824,12 @@ function report2(outcome) {
|
|
|
55774
55824
|
var import_typebox12 = __toESM(require_typebox(), 1);
|
|
55775
55825
|
import { realpathSync as realpathSync5 } from "node:fs";
|
|
55776
55826
|
import { readFile as readFile5, writeFile as writeFile6 } from "node:fs/promises";
|
|
55777
|
-
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";
|
|
55778
55828
|
|
|
55779
55829
|
// packages/kyrn-judge/src/packs/conflicts.ts
|
|
55780
55830
|
import { mkdtemp as mkdtemp2, rm as rm5, writeFile as writeFile5 } from "node:fs/promises";
|
|
55781
55831
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
55782
|
-
import { join as
|
|
55832
|
+
import { join as join46 } from "node:path";
|
|
55783
55833
|
var START = /^<{7}(?: (.*))?$/;
|
|
55784
55834
|
var BASE = /^\|{7}(?: .*)?$/;
|
|
55785
55835
|
var MIDDLE = /^={7}$/;
|
|
@@ -55889,9 +55939,9 @@ async function diff3Of(git2, cwd, path) {
|
|
|
55889
55939
|
if (shown2.code !== 0) return void 0;
|
|
55890
55940
|
sides.push(shown2.stdout);
|
|
55891
55941
|
}
|
|
55892
|
-
const dir = await mkdtemp2(
|
|
55942
|
+
const dir = await mkdtemp2(join46(tmpdir7(), "mu-conflict-"));
|
|
55893
55943
|
try {
|
|
55894
|
-
const files = ["ours", "base", "theirs"].map((name) =>
|
|
55944
|
+
const files = ["ours", "base", "theirs"].map((name) => join46(dir, name));
|
|
55895
55945
|
await Promise.all(files.map((file, index) => writeFile5(file, sides[index])));
|
|
55896
55946
|
const merged = await git2(["merge-file", "-p", "--diff3", "-L", "ours", "-L", "base", "-L", "theirs", ...files], {
|
|
55897
55947
|
cwd
|
|
@@ -55911,8 +55961,8 @@ function real(path) {
|
|
|
55911
55961
|
try {
|
|
55912
55962
|
return realpathSync5.native(path);
|
|
55913
55963
|
} catch {
|
|
55914
|
-
const parent =
|
|
55915
|
-
return parent === path ? path :
|
|
55964
|
+
const parent = dirname12(path);
|
|
55965
|
+
return parent === path ? path : join47(real(parent), basename13(path));
|
|
55916
55966
|
}
|
|
55917
55967
|
}
|
|
55918
55968
|
var NEXT = "Committing, and `git merge --continue` / `git rebase --continue`, are the user's to run: tell them, do not run them.";
|
|
@@ -55929,7 +55979,7 @@ function conflictsPack(shared, options) {
|
|
|
55929
55979
|
return { repo, files };
|
|
55930
55980
|
};
|
|
55931
55981
|
const inRepo = (root, cwd, path) => {
|
|
55932
|
-
const inside2 = relative5(real(root), real(isAbsolute6(path) ? path :
|
|
55982
|
+
const inside2 = relative5(real(root), real(isAbsolute6(path) ? path : join47(cwd, path))).replaceAll("\\", "/");
|
|
55933
55983
|
if (inside2.startsWith("../") || inside2 === "..") throw new Error(`${path} is outside the repository`);
|
|
55934
55984
|
return inside2;
|
|
55935
55985
|
};
|
|
@@ -55966,7 +56016,7 @@ function conflictsPack(shared, options) {
|
|
|
55966
56016
|
for (const file of files) {
|
|
55967
56017
|
let detail = file.kind;
|
|
55968
56018
|
if (file.kind === "both modified" || file.kind === "both added") {
|
|
55969
|
-
const content = await readFile5(
|
|
56019
|
+
const content = await readFile5(join47(repo.root, file.path)).catch(() => void 0);
|
|
55970
56020
|
if (content && looksBinary(content)) detail += " (binary: take ours or theirs)";
|
|
55971
56021
|
else if (content) {
|
|
55972
56022
|
const count3 = parseConflicts(content.toString("utf8")).blocks.length;
|
|
@@ -55998,7 +56048,7 @@ function conflictsPack(shared, options) {
|
|
|
55998
56048
|
details: { path, kind: file.kind }
|
|
55999
56049
|
};
|
|
56000
56050
|
}
|
|
56001
|
-
const content = await readFile5(
|
|
56051
|
+
const content = await readFile5(join47(repo.root, path));
|
|
56002
56052
|
if (looksBinary(content)) {
|
|
56003
56053
|
return {
|
|
56004
56054
|
content: text6(`${path} is binary: resolve it with take: "ours" or "theirs".`),
|
|
@@ -56072,7 +56122,7 @@ function conflictsPack(shared, options) {
|
|
|
56072
56122
|
details: { path, resolved: true, left: left2.length }
|
|
56073
56123
|
};
|
|
56074
56124
|
}
|
|
56075
|
-
const content = await readFile5(
|
|
56125
|
+
const content = await readFile5(join47(cwd, path));
|
|
56076
56126
|
if (looksBinary(content)) throw new Error(`${path} is binary: use take: "ours" or "theirs".`);
|
|
56077
56127
|
const parsed = parseConflicts(content.toString("utf8"));
|
|
56078
56128
|
if (parsed.problem)
|
|
@@ -56089,7 +56139,7 @@ function conflictsPack(shared, options) {
|
|
|
56089
56139
|
if (resolutions.size === 0)
|
|
56090
56140
|
throw new Error("Give the resolution of at least one block, or take a side.");
|
|
56091
56141
|
const written = replaceBlocks(parsed, resolutions);
|
|
56092
|
-
await writeFile6(
|
|
56142
|
+
await writeFile6(join47(cwd, path), written);
|
|
56093
56143
|
const remaining = parseConflicts(written).blocks.length;
|
|
56094
56144
|
if (remaining > 0) {
|
|
56095
56145
|
return {
|
|
@@ -57009,7 +57059,7 @@ ${tail2}` : "Ended the debugging run."
|
|
|
57009
57059
|
}
|
|
57010
57060
|
|
|
57011
57061
|
// packages/kyrn-judge/src/extension/features/packs/github.ts
|
|
57012
|
-
import { existsSync as
|
|
57062
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
57013
57063
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
57014
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));
|
|
57015
57065
|
function githubPack(shared, options) {
|
|
@@ -57018,7 +57068,7 @@ function githubPack(shared, options) {
|
|
|
57018
57068
|
title: "GitHub through gh",
|
|
57019
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.",
|
|
57020
57070
|
tools: [],
|
|
57021
|
-
skills:
|
|
57071
|
+
skills: existsSync16(GITHUB_SKILL_PATH) ? [GITHUB_SKILL_PATH] : [],
|
|
57022
57072
|
async start() {
|
|
57023
57073
|
const result = await shared.run(options.command || "gh", ["--version"], {
|
|
57024
57074
|
cwd: shared.cwd(),
|
|
@@ -57317,7 +57367,7 @@ function registerPacks(runtime) {
|
|
|
57317
57367
|
// packages/kyrn-judge/src/extension/features/permissions.ts
|
|
57318
57368
|
var import_pi_coding_agent15 = __toESM(require_pi_coding_agent(), 1);
|
|
57319
57369
|
import { homedir as homedir11 } from "node:os";
|
|
57320
|
-
import { join as
|
|
57370
|
+
import { join as join49, resolve as resolve14, sep as sep4 } from "node:path";
|
|
57321
57371
|
|
|
57322
57372
|
// packages/kyrn-judge/src/decisions/tool-approval.ts
|
|
57323
57373
|
var APPROVE_AT = 0.8;
|
|
@@ -57361,7 +57411,7 @@ var toolApproval = defineDecision({
|
|
|
57361
57411
|
// packages/kyrn-judge/src/permissions/modes.ts
|
|
57362
57412
|
import { lstatSync as lstatSync2, mkdirSync as mkdirSync18, readFileSync as readFileSync23, readlinkSync, realpathSync as realpathSync6, renameSync as renameSync10, writeFileSync as writeFileSync15 } from "node:fs";
|
|
57363
57413
|
import { homedir as homedir10 } from "node:os";
|
|
57364
|
-
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";
|
|
57365
57415
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
57366
57416
|
var PERMISSION_MODES = ["full", "judge", "ask"];
|
|
57367
57417
|
var MODE_TEXT = {
|
|
@@ -57449,12 +57499,12 @@ function realPath2(path, depth = 0) {
|
|
|
57449
57499
|
if (depth < 40) {
|
|
57450
57500
|
try {
|
|
57451
57501
|
if (lstatSync2(path).isSymbolicLink())
|
|
57452
|
-
return realPath2(resolve13(
|
|
57502
|
+
return realPath2(resolve13(dirname13(path), readlinkSync(path)), depth + 1);
|
|
57453
57503
|
} catch {
|
|
57454
57504
|
}
|
|
57455
57505
|
}
|
|
57456
|
-
const parent =
|
|
57457
|
-
return parent === path ? path :
|
|
57506
|
+
const parent = dirname13(path);
|
|
57507
|
+
return parent === path ? path : join48(realPath2(parent, depth + 1), basename14(path));
|
|
57458
57508
|
}
|
|
57459
57509
|
}
|
|
57460
57510
|
var UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
|
@@ -57469,7 +57519,7 @@ function toolPath(cwd, raw, home = homedir10()) {
|
|
|
57469
57519
|
if (process.platform === "win32") path = windowsDrive(path);
|
|
57470
57520
|
if (path === "~") path = home;
|
|
57471
57521
|
else if (path.startsWith("~/") || process.platform === "win32" && path.startsWith("~\\"))
|
|
57472
|
-
path =
|
|
57522
|
+
path = join48(home, path.slice(2));
|
|
57473
57523
|
else if (/^file:\/\//.test(path)) {
|
|
57474
57524
|
try {
|
|
57475
57525
|
path = fileURLToPath5(path);
|
|
@@ -57482,7 +57532,7 @@ function toolPath(cwd, raw, home = homedir10()) {
|
|
|
57482
57532
|
function inProject(cwd, target) {
|
|
57483
57533
|
if (target === void 0) return void 0;
|
|
57484
57534
|
const rel = relative7(realPath2(resolve13(cwd)), target);
|
|
57485
|
-
return rel === ".." || rel.startsWith(`..${
|
|
57535
|
+
return rel === ".." || rel.startsWith(`..${sep3}`) || isAbsolute8(rel) ? void 0 : rel;
|
|
57486
57536
|
}
|
|
57487
57537
|
function projectFile(cwd, target) {
|
|
57488
57538
|
const rel = inProject(cwd, target);
|
|
@@ -57580,7 +57630,7 @@ var PermissionDefaults = class {
|
|
|
57580
57630
|
file;
|
|
57581
57631
|
memory;
|
|
57582
57632
|
constructor(dir) {
|
|
57583
|
-
this.file = dir ?
|
|
57633
|
+
this.file = dir ? join48(dir, "permissions.json") : void 0;
|
|
57584
57634
|
}
|
|
57585
57635
|
get() {
|
|
57586
57636
|
if (!this.file) return this.memory;
|
|
@@ -57596,7 +57646,7 @@ var PermissionDefaults = class {
|
|
|
57596
57646
|
this.memory = mode;
|
|
57597
57647
|
return;
|
|
57598
57648
|
}
|
|
57599
|
-
mkdirSync18(
|
|
57649
|
+
mkdirSync18(join48(this.file, ".."), { recursive: true });
|
|
57600
57650
|
const temp = `${this.file}.${process.pid}.tmp`;
|
|
57601
57651
|
writeFileSync15(temp, `${JSON.stringify({ version: 1, mode }, null, " ")}
|
|
57602
57652
|
`, { mode: 384 });
|
|
@@ -57656,9 +57706,9 @@ function protectedPaths(roots) {
|
|
|
57656
57706
|
return real2 && real2 !== roots.agentDir ? [...spelled, real2] : spelled;
|
|
57657
57707
|
}
|
|
57658
57708
|
function projectSettings(cwd) {
|
|
57659
|
-
const spelled =
|
|
57709
|
+
const spelled = join49(resolve14(cwd), import_pi_coding_agent15.CONFIG_DIR_NAME);
|
|
57660
57710
|
const real2 = toolPath(cwd, import_pi_coding_agent15.CONFIG_DIR_NAME) ?? spelled;
|
|
57661
|
-
return [.../* @__PURE__ */ new Set([spelled, real2])].map((path) => `${path}${
|
|
57711
|
+
return [.../* @__PURE__ */ new Set([spelled, real2])].map((path) => `${path}${sep4}`);
|
|
57662
57712
|
}
|
|
57663
57713
|
function registerPermissions(runtime, roots) {
|
|
57664
57714
|
const options = runtime.options("permissions", {
|
|
@@ -57670,7 +57720,7 @@ function registerPermissions(runtime, roots) {
|
|
|
57670
57720
|
});
|
|
57671
57721
|
if (!options.enabled) return;
|
|
57672
57722
|
const { pi } = runtime;
|
|
57673
|
-
const defaults = new PermissionDefaults(roots ?
|
|
57723
|
+
const defaults = new PermissionDefaults(roots ? join49(roots.agentDir, "mu") : void 0);
|
|
57674
57724
|
const guarded = protectedPaths(roots);
|
|
57675
57725
|
const initial = () => parseMode(muEnv("PERMISSIONS")) ?? defaults.get() ?? parseMode(options.mode) ?? "judge";
|
|
57676
57726
|
let mode = initial();
|
|
@@ -58558,7 +58608,7 @@ function registerPreflight(runtime) {
|
|
|
58558
58608
|
|
|
58559
58609
|
// packages/kyrn-judge/src/extension/features/procedures.ts
|
|
58560
58610
|
var import_pi_coding_agent16 = __toESM(require_pi_coding_agent(), 1);
|
|
58561
|
-
import { basename as basename15, join as
|
|
58611
|
+
import { basename as basename15, join as join51 } from "node:path";
|
|
58562
58612
|
|
|
58563
58613
|
// packages/kyrn-judge/src/decisions/skill-capture.ts
|
|
58564
58614
|
var DRAFT_AT = 0.9;
|
|
@@ -58597,8 +58647,8 @@ var skillCapture = defineDecision({
|
|
|
58597
58647
|
});
|
|
58598
58648
|
|
|
58599
58649
|
// packages/kyrn-judge/src/memory/skill-drafts.ts
|
|
58600
|
-
import { existsSync as
|
|
58601
|
-
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";
|
|
58602
58652
|
var MAX_NAME = 64;
|
|
58603
58653
|
var MAX_DESCRIPTION = 300;
|
|
58604
58654
|
var MAX_LINES = 120;
|
|
@@ -58630,7 +58680,7 @@ var SkillDrafts = class {
|
|
|
58630
58680
|
this.dir = dir;
|
|
58631
58681
|
}
|
|
58632
58682
|
list() {
|
|
58633
|
-
if (!
|
|
58683
|
+
if (!existsSync17(this.dir)) return [];
|
|
58634
58684
|
const drafts = [];
|
|
58635
58685
|
for (const entry of readdirSync9(this.dir, { withFileTypes: true })) {
|
|
58636
58686
|
if (!entry.isDirectory()) continue;
|
|
@@ -58640,10 +58690,10 @@ var SkillDrafts = class {
|
|
|
58640
58690
|
return drafts.sort((a, b) => a.created.localeCompare(b.created));
|
|
58641
58691
|
}
|
|
58642
58692
|
get(name) {
|
|
58643
|
-
const folder =
|
|
58693
|
+
const folder = join50(this.dir, skillName(name));
|
|
58644
58694
|
try {
|
|
58645
|
-
const meta = JSON.parse(readFileSync24(
|
|
58646
|
-
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") };
|
|
58647
58697
|
} catch {
|
|
58648
58698
|
return void 0;
|
|
58649
58699
|
}
|
|
@@ -58661,16 +58711,16 @@ var SkillDrafts = class {
|
|
|
58661
58711
|
request: origin.request.slice(0, 400),
|
|
58662
58712
|
created: (/* @__PURE__ */ new Date()).toISOString()
|
|
58663
58713
|
};
|
|
58664
|
-
const folder =
|
|
58714
|
+
const folder = join50(this.dir, name);
|
|
58665
58715
|
mkdirSync19(folder, { recursive: true });
|
|
58666
|
-
writeFileSync16(
|
|
58667
|
-
writeFileSync16(
|
|
58716
|
+
writeFileSync16(join50(folder, "SKILL.md"), markdown);
|
|
58717
|
+
writeFileSync16(join50(folder, "draft.json"), `${JSON.stringify(meta, null, " ")}
|
|
58668
58718
|
`);
|
|
58669
58719
|
return { ...meta, markdown };
|
|
58670
58720
|
}
|
|
58671
58721
|
remove(name) {
|
|
58672
|
-
const folder =
|
|
58673
|
-
if (!
|
|
58722
|
+
const folder = join50(this.dir, skillName(name));
|
|
58723
|
+
if (!existsSync17(folder)) return false;
|
|
58674
58724
|
rmSync8(folder, { recursive: true, force: true });
|
|
58675
58725
|
return true;
|
|
58676
58726
|
}
|
|
@@ -58681,9 +58731,9 @@ var SkillDrafts = class {
|
|
|
58681
58731
|
accept(name, skillsDir) {
|
|
58682
58732
|
const draft = this.get(name);
|
|
58683
58733
|
if (!draft) return { error: "missing" };
|
|
58684
|
-
const folder =
|
|
58685
|
-
const path =
|
|
58686
|
-
if (
|
|
58734
|
+
const folder = join50(skillsDir, draft.name);
|
|
58735
|
+
const path = join50(folder, "SKILL.md");
|
|
58736
|
+
if (existsSync17(path)) return { error: "exists" };
|
|
58687
58737
|
mkdirSync19(folder, { recursive: true });
|
|
58688
58738
|
writeFileSync16(path, draft.markdown);
|
|
58689
58739
|
this.remove(draft.name);
|
|
@@ -58721,10 +58771,10 @@ function registerProcedures(runtime, roots) {
|
|
|
58721
58771
|
});
|
|
58722
58772
|
if (!options.enabled || process.env.KYRN_SWARM_DEPTH) return;
|
|
58723
58773
|
const { pi } = runtime;
|
|
58724
|
-
const dir = options.path || (roots ?
|
|
58774
|
+
const dir = options.path || (roots ? join51(roots.agentDir, "mu", "skill-drafts") : void 0);
|
|
58725
58775
|
if (!dir) return;
|
|
58726
58776
|
const drafts = new SkillDrafts(dir);
|
|
58727
|
-
const userSkillsDir = roots ?
|
|
58777
|
+
const userSkillsDir = roots ? join51(roots.agentDir, "skills") : void 0;
|
|
58728
58778
|
let turnOf = -1;
|
|
58729
58779
|
let request = "";
|
|
58730
58780
|
let steps = [];
|
|
@@ -58883,7 +58933,7 @@ ${say({
|
|
|
58883
58933
|
return;
|
|
58884
58934
|
}
|
|
58885
58935
|
if (verb === "accept") {
|
|
58886
|
-
const target = project ?
|
|
58936
|
+
const target = project ? join51(ctx.cwd, import_pi_coding_agent16.CONFIG_DIR_NAME, "skills") : userSkillsDir;
|
|
58887
58937
|
if (!target) return;
|
|
58888
58938
|
const result = drafts.accept(draft.name, target);
|
|
58889
58939
|
if ("error" in result) {
|
|
@@ -59178,7 +59228,7 @@ function errorDetail(text9) {
|
|
|
59178
59228
|
|
|
59179
59229
|
// packages/kyrn-judge/src/sandbox/operations.ts
|
|
59180
59230
|
import { readFile as readFile7 } from "node:fs/promises";
|
|
59181
|
-
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";
|
|
59182
59232
|
|
|
59183
59233
|
// packages/kyrn-judge/src/sandbox/session.ts
|
|
59184
59234
|
import { posix as posix5 } from "node:path";
|
|
@@ -59186,7 +59236,7 @@ import { posix as posix5 } from "node:path";
|
|
|
59186
59236
|
// packages/kyrn-judge/src/sandbox/project.ts
|
|
59187
59237
|
import { spawn as spawn10 } from "node:child_process";
|
|
59188
59238
|
import { lstat as lstat2, readdir as readdir2, readFile as readFile6, readlink as readlink2 } from "node:fs/promises";
|
|
59189
|
-
import { join as
|
|
59239
|
+
import { join as join52, relative as relative8, sep as sep5 } from "node:path";
|
|
59190
59240
|
import { promisify } from "node:util";
|
|
59191
59241
|
import { gzip } from "node:zlib";
|
|
59192
59242
|
|
|
@@ -59295,9 +59345,9 @@ var WALK_SKIP = /* @__PURE__ */ new Set([".git", "node_modules"]);
|
|
|
59295
59345
|
async function walk(root, dir, found) {
|
|
59296
59346
|
for (const entry of await readdir2(dir, { withFileTypes: true })) {
|
|
59297
59347
|
if (entry.isDirectory()) {
|
|
59298
|
-
if (!WALK_SKIP.has(entry.name)) await walk(root,
|
|
59348
|
+
if (!WALK_SKIP.has(entry.name)) await walk(root, join52(dir, entry.name), found);
|
|
59299
59349
|
} else if (entry.isFile() || entry.isSymbolicLink()) {
|
|
59300
|
-
found.push(relative8(root,
|
|
59350
|
+
found.push(relative8(root, join52(dir, entry.name)).split(sep5).join("/"));
|
|
59301
59351
|
}
|
|
59302
59352
|
}
|
|
59303
59353
|
}
|
|
@@ -59325,13 +59375,13 @@ async function seedArchive(cwd, maxBytes) {
|
|
|
59325
59375
|
const entries = [];
|
|
59326
59376
|
let bytes = 0;
|
|
59327
59377
|
for (const path of files) {
|
|
59328
|
-
const absolute3 =
|
|
59378
|
+
const absolute3 = join52(cwd, path);
|
|
59329
59379
|
const stat = await lstat2(absolute3).catch(() => void 0);
|
|
59330
59380
|
if (!stat) continue;
|
|
59331
59381
|
const mtime = Math.floor(stat.mtimeMs / 1e3);
|
|
59332
59382
|
if (stat.isSymbolicLink()) {
|
|
59333
59383
|
const target = await readlink2(absolute3);
|
|
59334
|
-
entries.push({ path, mode: 511, mtime, linkTarget:
|
|
59384
|
+
entries.push({ path, mode: 511, mtime, linkTarget: sep5 === "\\" ? target.split(sep5).join("/") : target });
|
|
59335
59385
|
} else if (stat.isFile()) {
|
|
59336
59386
|
bytes += stat.size;
|
|
59337
59387
|
if (bytes > maxBytes) throw new ProjectTooLarge(bytes, maxBytes);
|
|
@@ -59711,14 +59761,14 @@ var SandboxSession = class {
|
|
|
59711
59761
|
function toSandboxPath(localPath, root, workdir) {
|
|
59712
59762
|
const inside2 = relative9(root, localPath);
|
|
59713
59763
|
if (inside2 === "") return workdir;
|
|
59714
|
-
if (inside2 !== ".." && !inside2.startsWith(`..${
|
|
59715
|
-
return posix6.join(workdir, inside2.split(
|
|
59764
|
+
if (inside2 !== ".." && !inside2.startsWith(`..${sep6}`) && !isAbsolute9(inside2)) {
|
|
59765
|
+
return posix6.join(workdir, inside2.split(sep6).join("/"));
|
|
59716
59766
|
}
|
|
59717
|
-
return localPath.split(
|
|
59767
|
+
return localPath.split(sep6).join("/");
|
|
59718
59768
|
}
|
|
59719
59769
|
function insideProject(localPath, root) {
|
|
59720
59770
|
const inside2 = relative9(root, localPath);
|
|
59721
|
-
return inside2 === "" || inside2 !== ".." && !inside2.startsWith(`..${
|
|
59771
|
+
return inside2 === "" || inside2 !== ".." && !inside2.startsWith(`..${sep6}`) && !isAbsolute9(inside2);
|
|
59722
59772
|
}
|
|
59723
59773
|
var IMAGE_TYPES2 = {
|
|
59724
59774
|
".png": "image/png",
|
|
@@ -60764,7 +60814,7 @@ function registerWatchdog(runtime) {
|
|
|
60764
60814
|
}
|
|
60765
60815
|
|
|
60766
60816
|
// packages/kyrn-judge/src/extension/quit.ts
|
|
60767
|
-
import { join as
|
|
60817
|
+
import { join as join53 } from "node:path";
|
|
60768
60818
|
|
|
60769
60819
|
// packages/kyrn-judge/src/auth/exit.ts
|
|
60770
60820
|
import { mkdirSync as mkdirSync20, rmdirSync as rmdirSync2 } from "node:fs";
|
|
@@ -60820,7 +60870,7 @@ function drop(lock) {
|
|
|
60820
60870
|
|
|
60821
60871
|
// packages/kyrn-judge/src/extension/quit.ts
|
|
60822
60872
|
function registerLockSafeQuit(pi, agentDir) {
|
|
60823
|
-
const stores2 = [
|
|
60873
|
+
const stores2 = [join53(agentDir, "auth.json"), join53(agentDir, "models-store.json")];
|
|
60824
60874
|
pi.on("session_shutdown", async (event) => {
|
|
60825
60875
|
if (event.reason === "quit") await holdLocksUntilExit(stores2);
|
|
60826
60876
|
});
|
|
@@ -60879,7 +60929,7 @@ function registerKyrn(pi, options) {
|
|
|
60879
60929
|
for (const capability of options.capabilities ?? []) runtime.catalog.register(capability);
|
|
60880
60930
|
registerWelcome(runtime);
|
|
60881
60931
|
const roots = options.roots ?? (options.config || options.provider ? void 0 : { home: homedir12(), agentDir: (0, import_pi_coding_agent18.getAgentDir)() });
|
|
60882
|
-
runtime.stateDir = roots ?
|
|
60932
|
+
runtime.stateDir = roots ? join54(roots.agentDir, "mu") : void 0;
|
|
60883
60933
|
registerLayaNotice(runtime, loaded.laya, roots, home);
|
|
60884
60934
|
if (loaded.disabled) {
|
|
60885
60935
|
if (!options.only || options.only.includes("permissions")) registerPermissions(runtime, roots);
|