pi-herdsman 0.50.1 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +52 -0
- package/dist/agents/ship.md +65 -0
- package/dist/index.js +804 -1856
- package/dist/index.js.map +4 -4
- package/dist/peer-bridge.js +367 -112
- package/dist/peer-bridge.js.map +4 -4
- package/docs/adr/0041-allow-opt-in-working-directory-delegation.md +44 -0
- package/docs/development/documentation.md +6 -6
- package/docs/development/smoke-testing.md +12 -6
- package/docs/getting-started.md +9 -0
- package/docs/guides/agent-definitions.md +31 -0
- package/docs/guides/container-deployment.md +12 -2
- package/docs/guides/customizing-agents.md +1 -1
- package/docs/guides/project-orchestration.md +4 -4
- package/docs/reference/agent-definition-schema.md +1 -1
- package/docs/reference/agent.md +35 -1
- package/docs/reference/commands.md +36 -19
- package/docs/reference/configuration.md +46 -8
- package/docs/reference/peer.md +41 -10
- package/package.json +1 -3
- package/skills/agent-specialization-audit/SKILL.md +125 -0
- package/skills/herdsman-guide/SKILL.md +106 -0
- package/skills/machine-pairing/SKILL.md +96 -0
- package/SKILL.md +0 -581
package/dist/index.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
3
|
var __esm = (fn, res, err) => function __init() {
|
|
14
4
|
if (err) throw err[0];
|
|
15
5
|
try {
|
|
@@ -18,33 +8,10 @@ var __esm = (fn, res, err) => function __init() {
|
|
|
18
8
|
throw err = [e], e;
|
|
19
9
|
}
|
|
20
10
|
};
|
|
21
|
-
var __commonJS = (cb, mod) => function __require2() {
|
|
22
|
-
try {
|
|
23
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
24
|
-
} catch (e) {
|
|
25
|
-
throw mod = 0, e;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
11
|
var __export = (target, all) => {
|
|
29
12
|
for (var name in all)
|
|
30
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
31
14
|
};
|
|
32
|
-
var __copyProps = (to, from, except, desc) => {
|
|
33
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
34
|
-
for (let key of __getOwnPropNames(from))
|
|
35
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
36
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
37
|
-
}
|
|
38
|
-
return to;
|
|
39
|
-
};
|
|
40
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
41
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
42
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
43
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
44
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
45
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
46
|
-
mod
|
|
47
|
-
));
|
|
48
15
|
|
|
49
16
|
// extension/errors.ts
|
|
50
17
|
function markRetryAttempted(error2) {
|
|
@@ -2601,11 +2568,11 @@ function matchesToolPattern(pattern, name) {
|
|
|
2601
2568
|
}
|
|
2602
2569
|
function configuredToolPolicy(definition, requiredTools) {
|
|
2603
2570
|
const configured = normalizedToolNames(definition.frontmatter.tools);
|
|
2604
|
-
const
|
|
2605
|
-
const mode = definition.frontmatter.tools === void 0 ? "inherit" :
|
|
2571
|
+
const relative4 = definition.frontmatter.tools !== void 0 && configured.length > 0 && configured.every(isArrayModifier);
|
|
2572
|
+
const mode = definition.frontmatter.tools === void 0 ? "inherit" : relative4 ? "relative" : "explicit";
|
|
2606
2573
|
const required = new Set(requiredTools);
|
|
2607
2574
|
const terminal = /* @__PURE__ */ new Map();
|
|
2608
|
-
if (
|
|
2575
|
+
if (relative4)
|
|
2609
2576
|
for (const operation of configured) {
|
|
2610
2577
|
const name = operation.slice(1);
|
|
2611
2578
|
terminal.set(name, operation[0] === "-");
|
|
@@ -3367,9 +3334,9 @@ function agentDefinitionDelegationEnabled(definition) {
|
|
|
3367
3334
|
}
|
|
3368
3335
|
function contextInheritance(definition) {
|
|
3369
3336
|
const project = definition.frontmatter.inheritProjectContext === true || definition.frontmatter.inheritProjectContext === void 0 && definition.name === "delegate";
|
|
3370
|
-
const
|
|
3337
|
+
const global = definition.frontmatter.inheritGlobalContext === true || definition.frontmatter.inheritGlobalContext === void 0 && project;
|
|
3371
3338
|
const ancestor = definition.frontmatter.inheritAncestorContext === true || definition.frontmatter.inheritAncestorContext === void 0 && project;
|
|
3372
|
-
return { global
|
|
3339
|
+
return { global, ancestor, project };
|
|
3373
3340
|
}
|
|
3374
3341
|
function isWithinDirectory(directory2, root2) {
|
|
3375
3342
|
const rel = relative(root2, directory2);
|
|
@@ -4496,6 +4463,8 @@ async function startHerdrAgent(pi, ctx, options) {
|
|
|
4496
4463
|
if (!tab) {
|
|
4497
4464
|
if (placement.kind !== "tab")
|
|
4498
4465
|
error("start", "cannot create a tab for split placement");
|
|
4466
|
+
const authorization = options.assertLaunchAuthorized?.(cwd);
|
|
4467
|
+
if (authorization) await authorization;
|
|
4499
4468
|
const made = await runHerdr(
|
|
4500
4469
|
pi,
|
|
4501
4470
|
ctx,
|
|
@@ -4545,6 +4514,8 @@ async function startHerdrAgent(pi, ctx, options) {
|
|
|
4545
4514
|
startupDeadline,
|
|
4546
4515
|
options.signal
|
|
4547
4516
|
);
|
|
4517
|
+
const authorization = options.assertLaunchAuthorized?.(cwd);
|
|
4518
|
+
if (authorization) await authorization;
|
|
4548
4519
|
const split = await runHerdr(
|
|
4549
4520
|
pi,
|
|
4550
4521
|
ctx,
|
|
@@ -4642,6 +4613,8 @@ async function startHerdrAgent(pi, ctx, options) {
|
|
|
4642
4613
|
startupDeadline - START_DIAGNOSTIC_TIMEOUT
|
|
4643
4614
|
);
|
|
4644
4615
|
for (; ; ) {
|
|
4616
|
+
const authorization = options.assertLaunchAuthorized?.(cwd);
|
|
4617
|
+
if (authorization) await authorization;
|
|
4645
4618
|
const remaining = startupCallTimeout(startupDeadline, childTimeout);
|
|
4646
4619
|
if (remaining < HERDR_START_TIMEOUT_MIN)
|
|
4647
4620
|
error("start", "startup deadline exhausted before agent start");
|
|
@@ -5154,6 +5127,9 @@ function sameObservedSessionPath(left, right) {
|
|
|
5154
5127
|
}
|
|
5155
5128
|
}
|
|
5156
5129
|
function readPiSessionHeaderId(path) {
|
|
5130
|
+
return readPiSessionHeaderIdentity(path)?.id;
|
|
5131
|
+
}
|
|
5132
|
+
function readPiSessionHeaderIdentity(path) {
|
|
5157
5133
|
let fd;
|
|
5158
5134
|
try {
|
|
5159
5135
|
fd = openSync5(path, "r");
|
|
@@ -5194,7 +5170,10 @@ function readPiSessionHeaderId(path) {
|
|
|
5194
5170
|
const header = JSON.parse(content);
|
|
5195
5171
|
if (header?.type !== "session" || typeof header.id !== "string" || header.id.length === 0)
|
|
5196
5172
|
throw new Error("Invalid Pi session header");
|
|
5197
|
-
return
|
|
5173
|
+
return {
|
|
5174
|
+
id: header.id,
|
|
5175
|
+
...typeof header.cwd === "string" ? { cwd: header.cwd } : {}
|
|
5176
|
+
};
|
|
5198
5177
|
}
|
|
5199
5178
|
function matchesExpectedSession(observed, expected) {
|
|
5200
5179
|
if (!expected) return false;
|
|
@@ -6581,6 +6560,14 @@ function deliveredMessageContent(record, senderTarget) {
|
|
|
6581
6560
|
${record.text}` : `${prefix}${record.text}`;
|
|
6582
6561
|
return content + senderEnvironmentAnnotation(record.senderEnvironment);
|
|
6583
6562
|
}
|
|
6563
|
+
function peerDeliveryPaused(record, options) {
|
|
6564
|
+
if (record.kind !== "peer_message") return false;
|
|
6565
|
+
try {
|
|
6566
|
+
return options.isPeerDeliveryEnabled?.() === false;
|
|
6567
|
+
} catch {
|
|
6568
|
+
return true;
|
|
6569
|
+
}
|
|
6570
|
+
}
|
|
6584
6571
|
async function drainCoordinationInbox(options) {
|
|
6585
6572
|
let delivered = 0;
|
|
6586
6573
|
let examined = 0;
|
|
@@ -6611,6 +6598,7 @@ async function drainCoordinationInbox(options) {
|
|
|
6611
6598
|
}
|
|
6612
6599
|
continue;
|
|
6613
6600
|
}
|
|
6601
|
+
if (peerDeliveryPaused(record, options)) continue;
|
|
6614
6602
|
examined++;
|
|
6615
6603
|
let token;
|
|
6616
6604
|
const clearTransaction = async () => {
|
|
@@ -6656,6 +6644,10 @@ async function drainCoordinationInbox(options) {
|
|
|
6656
6644
|
record.id
|
|
6657
6645
|
);
|
|
6658
6646
|
await options.transaction?.revalidate(token, "before-rejected-remove");
|
|
6647
|
+
if (peerDeliveryPaused(record, options)) {
|
|
6648
|
+
await clearTransaction();
|
|
6649
|
+
continue;
|
|
6650
|
+
}
|
|
6659
6651
|
} catch {
|
|
6660
6652
|
await clearTransaction();
|
|
6661
6653
|
continue;
|
|
@@ -6739,6 +6731,10 @@ async function drainCoordinationInbox(options) {
|
|
|
6739
6731
|
await clearTransaction();
|
|
6740
6732
|
break;
|
|
6741
6733
|
}
|
|
6734
|
+
if (peerDeliveryPaused(record, options)) {
|
|
6735
|
+
await clearTransaction();
|
|
6736
|
+
continue;
|
|
6737
|
+
}
|
|
6742
6738
|
await options.sendMessage(
|
|
6743
6739
|
{
|
|
6744
6740
|
customType: `pi-herdsman-${record.kind}`,
|
|
@@ -10543,6 +10539,7 @@ function formatToolModelResult(action, v) {
|
|
|
10543
10539
|
}
|
|
10544
10540
|
return [
|
|
10545
10541
|
`${action[0].toUpperCase()}${action.slice(1)} agent ${value(v.agent) || "unknown"}${definition ? ` (${definition})` : ""}.`,
|
|
10542
|
+
...action === "delegate" && value(v.cwd) ? [`Cwd: ${v.cwd}`] : [],
|
|
10546
10543
|
...value(v.session_id) ? [`Session: ${v.session_id}`] : [],
|
|
10547
10544
|
...value(v.request_id) ? [`Request: ${v.request_id}`] : [],
|
|
10548
10545
|
...value(v.assignment_request_id) ? [`Assignment request: ${v.assignment_request_id}`] : [],
|
|
@@ -10676,6 +10673,8 @@ function renderExpandedCoordinationCall(tool, action, args, theme, header) {
|
|
|
10676
10673
|
if (action === "delegate") {
|
|
10677
10674
|
if (args.definition) fields.push(["definition", args.definition]);
|
|
10678
10675
|
if (args.label) fields.push(["label", args.label]);
|
|
10676
|
+
if (typeof args.cwd === "string" && args.cwd)
|
|
10677
|
+
fields.push(["cwd", displayHomePath(args.cwd)]);
|
|
10679
10678
|
} else if (action === "continue") {
|
|
10680
10679
|
if (args.session) fields.push(["session", args.session]);
|
|
10681
10680
|
} else if (args.agent) fields.push(["agent", args.agent]);
|
|
@@ -11847,6 +11846,10 @@ var init_presentation = __esm({
|
|
|
11847
11846
|
"Remote peer probe failed",
|
|
11848
11847
|
"Check Herdr machine status and the remote Pi session."
|
|
11849
11848
|
],
|
|
11849
|
+
federation_disabled: [
|
|
11850
|
+
"Peer federation is disabled",
|
|
11851
|
+
"Check the remote Herdsman communication settings."
|
|
11852
|
+
],
|
|
11850
11853
|
build_mismatch: ["Peer build mismatch", "Reload the outdated Pi session."],
|
|
11851
11854
|
build_unverified: [
|
|
11852
11855
|
"Peer build could not be verified",
|
|
@@ -12056,1583 +12059,6 @@ var init_presentation = __esm({
|
|
|
12056
12059
|
}
|
|
12057
12060
|
});
|
|
12058
12061
|
|
|
12059
|
-
// node_modules/graceful-fs/polyfills.js
|
|
12060
|
-
var require_polyfills = __commonJS({
|
|
12061
|
-
"node_modules/graceful-fs/polyfills.js"(exports, module) {
|
|
12062
|
-
var constants4 = __require("constants");
|
|
12063
|
-
var origCwd = process.cwd;
|
|
12064
|
-
var cwd = null;
|
|
12065
|
-
var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
|
|
12066
|
-
process.cwd = function() {
|
|
12067
|
-
if (!cwd)
|
|
12068
|
-
cwd = origCwd.call(process);
|
|
12069
|
-
return cwd;
|
|
12070
|
-
};
|
|
12071
|
-
try {
|
|
12072
|
-
process.cwd();
|
|
12073
|
-
} catch (er) {
|
|
12074
|
-
}
|
|
12075
|
-
if (typeof process.chdir === "function") {
|
|
12076
|
-
chdir = process.chdir;
|
|
12077
|
-
process.chdir = function(d) {
|
|
12078
|
-
cwd = null;
|
|
12079
|
-
chdir.call(process, d);
|
|
12080
|
-
};
|
|
12081
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
|
|
12082
|
-
}
|
|
12083
|
-
var chdir;
|
|
12084
|
-
module.exports = patch;
|
|
12085
|
-
function patch(fs2) {
|
|
12086
|
-
if (constants4.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
|
|
12087
|
-
patchLchmod(fs2);
|
|
12088
|
-
}
|
|
12089
|
-
if (!fs2.lutimes) {
|
|
12090
|
-
patchLutimes(fs2);
|
|
12091
|
-
}
|
|
12092
|
-
fs2.chown = chownFix(fs2.chown);
|
|
12093
|
-
fs2.fchown = chownFix(fs2.fchown);
|
|
12094
|
-
fs2.lchown = chownFix(fs2.lchown);
|
|
12095
|
-
fs2.chmod = chmodFix(fs2.chmod);
|
|
12096
|
-
fs2.fchmod = chmodFix(fs2.fchmod);
|
|
12097
|
-
fs2.lchmod = chmodFix(fs2.lchmod);
|
|
12098
|
-
fs2.chownSync = chownFixSync(fs2.chownSync);
|
|
12099
|
-
fs2.fchownSync = chownFixSync(fs2.fchownSync);
|
|
12100
|
-
fs2.lchownSync = chownFixSync(fs2.lchownSync);
|
|
12101
|
-
fs2.chmodSync = chmodFixSync(fs2.chmodSync);
|
|
12102
|
-
fs2.fchmodSync = chmodFixSync(fs2.fchmodSync);
|
|
12103
|
-
fs2.lchmodSync = chmodFixSync(fs2.lchmodSync);
|
|
12104
|
-
fs2.stat = statFix(fs2.stat);
|
|
12105
|
-
fs2.fstat = statFix(fs2.fstat);
|
|
12106
|
-
fs2.lstat = statFix(fs2.lstat);
|
|
12107
|
-
fs2.statSync = statFixSync(fs2.statSync);
|
|
12108
|
-
fs2.fstatSync = statFixSync(fs2.fstatSync);
|
|
12109
|
-
fs2.lstatSync = statFixSync(fs2.lstatSync);
|
|
12110
|
-
if (fs2.chmod && !fs2.lchmod) {
|
|
12111
|
-
fs2.lchmod = function(path, mode, cb) {
|
|
12112
|
-
if (cb) process.nextTick(cb);
|
|
12113
|
-
};
|
|
12114
|
-
fs2.lchmodSync = function() {
|
|
12115
|
-
};
|
|
12116
|
-
}
|
|
12117
|
-
if (fs2.chown && !fs2.lchown) {
|
|
12118
|
-
fs2.lchown = function(path, uid, gid, cb) {
|
|
12119
|
-
if (cb) process.nextTick(cb);
|
|
12120
|
-
};
|
|
12121
|
-
fs2.lchownSync = function() {
|
|
12122
|
-
};
|
|
12123
|
-
}
|
|
12124
|
-
if (platform === "win32") {
|
|
12125
|
-
fs2.rename = typeof fs2.rename !== "function" ? fs2.rename : (function(fs$rename) {
|
|
12126
|
-
function rename(from, to, cb) {
|
|
12127
|
-
var start = Date.now();
|
|
12128
|
-
var backoff = 0;
|
|
12129
|
-
fs$rename(from, to, function CB(er) {
|
|
12130
|
-
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
|
|
12131
|
-
setTimeout(function() {
|
|
12132
|
-
fs2.stat(to, function(stater, st) {
|
|
12133
|
-
if (stater && stater.code === "ENOENT")
|
|
12134
|
-
fs$rename(from, to, CB);
|
|
12135
|
-
else
|
|
12136
|
-
cb(er);
|
|
12137
|
-
});
|
|
12138
|
-
}, backoff);
|
|
12139
|
-
if (backoff < 100)
|
|
12140
|
-
backoff += 10;
|
|
12141
|
-
return;
|
|
12142
|
-
}
|
|
12143
|
-
if (cb) cb(er);
|
|
12144
|
-
});
|
|
12145
|
-
}
|
|
12146
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
|
|
12147
|
-
return rename;
|
|
12148
|
-
})(fs2.rename);
|
|
12149
|
-
}
|
|
12150
|
-
fs2.read = typeof fs2.read !== "function" ? fs2.read : (function(fs$read) {
|
|
12151
|
-
function read2(fd, buffer, offset, length, position, callback_) {
|
|
12152
|
-
var callback;
|
|
12153
|
-
if (callback_ && typeof callback_ === "function") {
|
|
12154
|
-
var eagCounter = 0;
|
|
12155
|
-
callback = function(er, _, __) {
|
|
12156
|
-
if (er && er.code === "EAGAIN" && eagCounter < 10) {
|
|
12157
|
-
eagCounter++;
|
|
12158
|
-
return fs$read.call(fs2, fd, buffer, offset, length, position, callback);
|
|
12159
|
-
}
|
|
12160
|
-
callback_.apply(this, arguments);
|
|
12161
|
-
};
|
|
12162
|
-
}
|
|
12163
|
-
return fs$read.call(fs2, fd, buffer, offset, length, position, callback);
|
|
12164
|
-
}
|
|
12165
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(read2, fs$read);
|
|
12166
|
-
return read2;
|
|
12167
|
-
})(fs2.read);
|
|
12168
|
-
fs2.readSync = typeof fs2.readSync !== "function" ? fs2.readSync : /* @__PURE__ */ (function(fs$readSync) {
|
|
12169
|
-
return function(fd, buffer, offset, length, position) {
|
|
12170
|
-
var eagCounter = 0;
|
|
12171
|
-
while (true) {
|
|
12172
|
-
try {
|
|
12173
|
-
return fs$readSync.call(fs2, fd, buffer, offset, length, position);
|
|
12174
|
-
} catch (er) {
|
|
12175
|
-
if (er.code === "EAGAIN" && eagCounter < 10) {
|
|
12176
|
-
eagCounter++;
|
|
12177
|
-
continue;
|
|
12178
|
-
}
|
|
12179
|
-
throw er;
|
|
12180
|
-
}
|
|
12181
|
-
}
|
|
12182
|
-
};
|
|
12183
|
-
})(fs2.readSync);
|
|
12184
|
-
function patchLchmod(fs3) {
|
|
12185
|
-
fs3.lchmod = function(path, mode, callback) {
|
|
12186
|
-
fs3.open(
|
|
12187
|
-
path,
|
|
12188
|
-
constants4.O_WRONLY | constants4.O_SYMLINK,
|
|
12189
|
-
mode,
|
|
12190
|
-
function(err, fd) {
|
|
12191
|
-
if (err) {
|
|
12192
|
-
if (callback) callback(err);
|
|
12193
|
-
return;
|
|
12194
|
-
}
|
|
12195
|
-
fs3.fchmod(fd, mode, function(err2) {
|
|
12196
|
-
fs3.close(fd, function(err22) {
|
|
12197
|
-
if (callback) callback(err2 || err22);
|
|
12198
|
-
});
|
|
12199
|
-
});
|
|
12200
|
-
}
|
|
12201
|
-
);
|
|
12202
|
-
};
|
|
12203
|
-
fs3.lchmodSync = function(path, mode) {
|
|
12204
|
-
var fd = fs3.openSync(path, constants4.O_WRONLY | constants4.O_SYMLINK, mode);
|
|
12205
|
-
var threw = true;
|
|
12206
|
-
var ret;
|
|
12207
|
-
try {
|
|
12208
|
-
ret = fs3.fchmodSync(fd, mode);
|
|
12209
|
-
threw = false;
|
|
12210
|
-
} finally {
|
|
12211
|
-
if (threw) {
|
|
12212
|
-
try {
|
|
12213
|
-
fs3.closeSync(fd);
|
|
12214
|
-
} catch (er) {
|
|
12215
|
-
}
|
|
12216
|
-
} else {
|
|
12217
|
-
fs3.closeSync(fd);
|
|
12218
|
-
}
|
|
12219
|
-
}
|
|
12220
|
-
return ret;
|
|
12221
|
-
};
|
|
12222
|
-
}
|
|
12223
|
-
function patchLutimes(fs3) {
|
|
12224
|
-
if (constants4.hasOwnProperty("O_SYMLINK") && fs3.futimes) {
|
|
12225
|
-
fs3.lutimes = function(path, at, mt, cb) {
|
|
12226
|
-
fs3.open(path, constants4.O_SYMLINK, function(er, fd) {
|
|
12227
|
-
if (er) {
|
|
12228
|
-
if (cb) cb(er);
|
|
12229
|
-
return;
|
|
12230
|
-
}
|
|
12231
|
-
fs3.futimes(fd, at, mt, function(er2) {
|
|
12232
|
-
fs3.close(fd, function(er22) {
|
|
12233
|
-
if (cb) cb(er2 || er22);
|
|
12234
|
-
});
|
|
12235
|
-
});
|
|
12236
|
-
});
|
|
12237
|
-
};
|
|
12238
|
-
fs3.lutimesSync = function(path, at, mt) {
|
|
12239
|
-
var fd = fs3.openSync(path, constants4.O_SYMLINK);
|
|
12240
|
-
var ret;
|
|
12241
|
-
var threw = true;
|
|
12242
|
-
try {
|
|
12243
|
-
ret = fs3.futimesSync(fd, at, mt);
|
|
12244
|
-
threw = false;
|
|
12245
|
-
} finally {
|
|
12246
|
-
if (threw) {
|
|
12247
|
-
try {
|
|
12248
|
-
fs3.closeSync(fd);
|
|
12249
|
-
} catch (er) {
|
|
12250
|
-
}
|
|
12251
|
-
} else {
|
|
12252
|
-
fs3.closeSync(fd);
|
|
12253
|
-
}
|
|
12254
|
-
}
|
|
12255
|
-
return ret;
|
|
12256
|
-
};
|
|
12257
|
-
} else if (fs3.futimes) {
|
|
12258
|
-
fs3.lutimes = function(_a, _b, _c, cb) {
|
|
12259
|
-
if (cb) process.nextTick(cb);
|
|
12260
|
-
};
|
|
12261
|
-
fs3.lutimesSync = function() {
|
|
12262
|
-
};
|
|
12263
|
-
}
|
|
12264
|
-
}
|
|
12265
|
-
function chmodFix(orig) {
|
|
12266
|
-
if (!orig) return orig;
|
|
12267
|
-
return function(target, mode, cb) {
|
|
12268
|
-
return orig.call(fs2, target, mode, function(er) {
|
|
12269
|
-
if (chownErOk(er)) er = null;
|
|
12270
|
-
if (cb) cb.apply(this, arguments);
|
|
12271
|
-
});
|
|
12272
|
-
};
|
|
12273
|
-
}
|
|
12274
|
-
function chmodFixSync(orig) {
|
|
12275
|
-
if (!orig) return orig;
|
|
12276
|
-
return function(target, mode) {
|
|
12277
|
-
try {
|
|
12278
|
-
return orig.call(fs2, target, mode);
|
|
12279
|
-
} catch (er) {
|
|
12280
|
-
if (!chownErOk(er)) throw er;
|
|
12281
|
-
}
|
|
12282
|
-
};
|
|
12283
|
-
}
|
|
12284
|
-
function chownFix(orig) {
|
|
12285
|
-
if (!orig) return orig;
|
|
12286
|
-
return function(target, uid, gid, cb) {
|
|
12287
|
-
return orig.call(fs2, target, uid, gid, function(er) {
|
|
12288
|
-
if (chownErOk(er)) er = null;
|
|
12289
|
-
if (cb) cb.apply(this, arguments);
|
|
12290
|
-
});
|
|
12291
|
-
};
|
|
12292
|
-
}
|
|
12293
|
-
function chownFixSync(orig) {
|
|
12294
|
-
if (!orig) return orig;
|
|
12295
|
-
return function(target, uid, gid) {
|
|
12296
|
-
try {
|
|
12297
|
-
return orig.call(fs2, target, uid, gid);
|
|
12298
|
-
} catch (er) {
|
|
12299
|
-
if (!chownErOk(er)) throw er;
|
|
12300
|
-
}
|
|
12301
|
-
};
|
|
12302
|
-
}
|
|
12303
|
-
function statFix(orig) {
|
|
12304
|
-
if (!orig) return orig;
|
|
12305
|
-
return function(target, options, cb) {
|
|
12306
|
-
if (typeof options === "function") {
|
|
12307
|
-
cb = options;
|
|
12308
|
-
options = null;
|
|
12309
|
-
}
|
|
12310
|
-
function callback(er, stats) {
|
|
12311
|
-
if (stats) {
|
|
12312
|
-
if (stats.uid < 0) stats.uid += 4294967296;
|
|
12313
|
-
if (stats.gid < 0) stats.gid += 4294967296;
|
|
12314
|
-
}
|
|
12315
|
-
if (cb) cb.apply(this, arguments);
|
|
12316
|
-
}
|
|
12317
|
-
return options ? orig.call(fs2, target, options, callback) : orig.call(fs2, target, callback);
|
|
12318
|
-
};
|
|
12319
|
-
}
|
|
12320
|
-
function statFixSync(orig) {
|
|
12321
|
-
if (!orig) return orig;
|
|
12322
|
-
return function(target, options) {
|
|
12323
|
-
var stats = options ? orig.call(fs2, target, options) : orig.call(fs2, target);
|
|
12324
|
-
if (stats) {
|
|
12325
|
-
if (stats.uid < 0) stats.uid += 4294967296;
|
|
12326
|
-
if (stats.gid < 0) stats.gid += 4294967296;
|
|
12327
|
-
}
|
|
12328
|
-
return stats;
|
|
12329
|
-
};
|
|
12330
|
-
}
|
|
12331
|
-
function chownErOk(er) {
|
|
12332
|
-
if (!er)
|
|
12333
|
-
return true;
|
|
12334
|
-
if (er.code === "ENOSYS")
|
|
12335
|
-
return true;
|
|
12336
|
-
var nonroot = !process.getuid || process.getuid() !== 0;
|
|
12337
|
-
if (nonroot) {
|
|
12338
|
-
if (er.code === "EINVAL" || er.code === "EPERM")
|
|
12339
|
-
return true;
|
|
12340
|
-
}
|
|
12341
|
-
return false;
|
|
12342
|
-
}
|
|
12343
|
-
}
|
|
12344
|
-
}
|
|
12345
|
-
});
|
|
12346
|
-
|
|
12347
|
-
// node_modules/graceful-fs/legacy-streams.js
|
|
12348
|
-
var require_legacy_streams = __commonJS({
|
|
12349
|
-
"node_modules/graceful-fs/legacy-streams.js"(exports, module) {
|
|
12350
|
-
var Stream = __require("stream").Stream;
|
|
12351
|
-
module.exports = legacy;
|
|
12352
|
-
function legacy(fs2) {
|
|
12353
|
-
return {
|
|
12354
|
-
ReadStream,
|
|
12355
|
-
WriteStream
|
|
12356
|
-
};
|
|
12357
|
-
function ReadStream(path, options) {
|
|
12358
|
-
if (!(this instanceof ReadStream)) return new ReadStream(path, options);
|
|
12359
|
-
Stream.call(this);
|
|
12360
|
-
var self = this;
|
|
12361
|
-
this.path = path;
|
|
12362
|
-
this.fd = null;
|
|
12363
|
-
this.readable = true;
|
|
12364
|
-
this.paused = false;
|
|
12365
|
-
this.flags = "r";
|
|
12366
|
-
this.mode = 438;
|
|
12367
|
-
this.bufferSize = 64 * 1024;
|
|
12368
|
-
options = options || {};
|
|
12369
|
-
var keys = Object.keys(options);
|
|
12370
|
-
for (var index = 0, length = keys.length; index < length; index++) {
|
|
12371
|
-
var key = keys[index];
|
|
12372
|
-
this[key] = options[key];
|
|
12373
|
-
}
|
|
12374
|
-
if (this.encoding) this.setEncoding(this.encoding);
|
|
12375
|
-
if (this.start !== void 0) {
|
|
12376
|
-
if ("number" !== typeof this.start) {
|
|
12377
|
-
throw TypeError("start must be a Number");
|
|
12378
|
-
}
|
|
12379
|
-
if (this.end === void 0) {
|
|
12380
|
-
this.end = Infinity;
|
|
12381
|
-
} else if ("number" !== typeof this.end) {
|
|
12382
|
-
throw TypeError("end must be a Number");
|
|
12383
|
-
}
|
|
12384
|
-
if (this.start > this.end) {
|
|
12385
|
-
throw new Error("start must be <= end");
|
|
12386
|
-
}
|
|
12387
|
-
this.pos = this.start;
|
|
12388
|
-
}
|
|
12389
|
-
if (this.fd !== null) {
|
|
12390
|
-
process.nextTick(function() {
|
|
12391
|
-
self._read();
|
|
12392
|
-
});
|
|
12393
|
-
return;
|
|
12394
|
-
}
|
|
12395
|
-
fs2.open(this.path, this.flags, this.mode, function(err, fd) {
|
|
12396
|
-
if (err) {
|
|
12397
|
-
self.emit("error", err);
|
|
12398
|
-
self.readable = false;
|
|
12399
|
-
return;
|
|
12400
|
-
}
|
|
12401
|
-
self.fd = fd;
|
|
12402
|
-
self.emit("open", fd);
|
|
12403
|
-
self._read();
|
|
12404
|
-
});
|
|
12405
|
-
}
|
|
12406
|
-
function WriteStream(path, options) {
|
|
12407
|
-
if (!(this instanceof WriteStream)) return new WriteStream(path, options);
|
|
12408
|
-
Stream.call(this);
|
|
12409
|
-
this.path = path;
|
|
12410
|
-
this.fd = null;
|
|
12411
|
-
this.writable = true;
|
|
12412
|
-
this.flags = "w";
|
|
12413
|
-
this.encoding = "binary";
|
|
12414
|
-
this.mode = 438;
|
|
12415
|
-
this.bytesWritten = 0;
|
|
12416
|
-
options = options || {};
|
|
12417
|
-
var keys = Object.keys(options);
|
|
12418
|
-
for (var index = 0, length = keys.length; index < length; index++) {
|
|
12419
|
-
var key = keys[index];
|
|
12420
|
-
this[key] = options[key];
|
|
12421
|
-
}
|
|
12422
|
-
if (this.start !== void 0) {
|
|
12423
|
-
if ("number" !== typeof this.start) {
|
|
12424
|
-
throw TypeError("start must be a Number");
|
|
12425
|
-
}
|
|
12426
|
-
if (this.start < 0) {
|
|
12427
|
-
throw new Error("start must be >= zero");
|
|
12428
|
-
}
|
|
12429
|
-
this.pos = this.start;
|
|
12430
|
-
}
|
|
12431
|
-
this.busy = false;
|
|
12432
|
-
this._queue = [];
|
|
12433
|
-
if (this.fd === null) {
|
|
12434
|
-
this._open = fs2.open;
|
|
12435
|
-
this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
|
|
12436
|
-
this.flush();
|
|
12437
|
-
}
|
|
12438
|
-
}
|
|
12439
|
-
}
|
|
12440
|
-
}
|
|
12441
|
-
});
|
|
12442
|
-
|
|
12443
|
-
// node_modules/graceful-fs/clone.js
|
|
12444
|
-
var require_clone = __commonJS({
|
|
12445
|
-
"node_modules/graceful-fs/clone.js"(exports, module) {
|
|
12446
|
-
"use strict";
|
|
12447
|
-
module.exports = clone;
|
|
12448
|
-
var getPrototypeOf = Object.getPrototypeOf || function(obj) {
|
|
12449
|
-
return obj.__proto__;
|
|
12450
|
-
};
|
|
12451
|
-
function clone(obj) {
|
|
12452
|
-
if (obj === null || typeof obj !== "object")
|
|
12453
|
-
return obj;
|
|
12454
|
-
if (obj instanceof Object)
|
|
12455
|
-
var copy = { __proto__: getPrototypeOf(obj) };
|
|
12456
|
-
else
|
|
12457
|
-
var copy = /* @__PURE__ */ Object.create(null);
|
|
12458
|
-
Object.getOwnPropertyNames(obj).forEach(function(key) {
|
|
12459
|
-
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
|
|
12460
|
-
});
|
|
12461
|
-
return copy;
|
|
12462
|
-
}
|
|
12463
|
-
}
|
|
12464
|
-
});
|
|
12465
|
-
|
|
12466
|
-
// node_modules/graceful-fs/graceful-fs.js
|
|
12467
|
-
var require_graceful_fs = __commonJS({
|
|
12468
|
-
"node_modules/graceful-fs/graceful-fs.js"(exports, module) {
|
|
12469
|
-
var fs2 = __require("fs");
|
|
12470
|
-
var polyfills = require_polyfills();
|
|
12471
|
-
var legacy = require_legacy_streams();
|
|
12472
|
-
var clone = require_clone();
|
|
12473
|
-
var util = __require("util");
|
|
12474
|
-
var gracefulQueue;
|
|
12475
|
-
var previousSymbol;
|
|
12476
|
-
if (typeof Symbol === "function" && typeof Symbol.for === "function") {
|
|
12477
|
-
gracefulQueue = /* @__PURE__ */ Symbol.for("graceful-fs.queue");
|
|
12478
|
-
previousSymbol = /* @__PURE__ */ Symbol.for("graceful-fs.previous");
|
|
12479
|
-
} else {
|
|
12480
|
-
gracefulQueue = "___graceful-fs.queue";
|
|
12481
|
-
previousSymbol = "___graceful-fs.previous";
|
|
12482
|
-
}
|
|
12483
|
-
function noop() {
|
|
12484
|
-
}
|
|
12485
|
-
function publishQueue(context, queue2) {
|
|
12486
|
-
Object.defineProperty(context, gracefulQueue, {
|
|
12487
|
-
get: function() {
|
|
12488
|
-
return queue2;
|
|
12489
|
-
}
|
|
12490
|
-
});
|
|
12491
|
-
}
|
|
12492
|
-
var debug = noop;
|
|
12493
|
-
if (util.debuglog)
|
|
12494
|
-
debug = util.debuglog("gfs4");
|
|
12495
|
-
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
|
|
12496
|
-
debug = function() {
|
|
12497
|
-
var m = util.format.apply(util, arguments);
|
|
12498
|
-
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
|
|
12499
|
-
console.error(m);
|
|
12500
|
-
};
|
|
12501
|
-
if (!fs2[gracefulQueue]) {
|
|
12502
|
-
queue = global[gracefulQueue] || [];
|
|
12503
|
-
publishQueue(fs2, queue);
|
|
12504
|
-
fs2.close = (function(fs$close) {
|
|
12505
|
-
function close(fd, cb) {
|
|
12506
|
-
return fs$close.call(fs2, fd, function(err) {
|
|
12507
|
-
if (!err) {
|
|
12508
|
-
resetQueue();
|
|
12509
|
-
}
|
|
12510
|
-
if (typeof cb === "function")
|
|
12511
|
-
cb.apply(this, arguments);
|
|
12512
|
-
});
|
|
12513
|
-
}
|
|
12514
|
-
Object.defineProperty(close, previousSymbol, {
|
|
12515
|
-
value: fs$close
|
|
12516
|
-
});
|
|
12517
|
-
return close;
|
|
12518
|
-
})(fs2.close);
|
|
12519
|
-
fs2.closeSync = (function(fs$closeSync) {
|
|
12520
|
-
function closeSync9(fd) {
|
|
12521
|
-
fs$closeSync.apply(fs2, arguments);
|
|
12522
|
-
resetQueue();
|
|
12523
|
-
}
|
|
12524
|
-
Object.defineProperty(closeSync9, previousSymbol, {
|
|
12525
|
-
value: fs$closeSync
|
|
12526
|
-
});
|
|
12527
|
-
return closeSync9;
|
|
12528
|
-
})(fs2.closeSync);
|
|
12529
|
-
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
|
|
12530
|
-
process.on("exit", function() {
|
|
12531
|
-
debug(fs2[gracefulQueue]);
|
|
12532
|
-
__require("assert").equal(fs2[gracefulQueue].length, 0);
|
|
12533
|
-
});
|
|
12534
|
-
}
|
|
12535
|
-
}
|
|
12536
|
-
var queue;
|
|
12537
|
-
if (!global[gracefulQueue]) {
|
|
12538
|
-
publishQueue(global, fs2[gracefulQueue]);
|
|
12539
|
-
}
|
|
12540
|
-
module.exports = patch(clone(fs2));
|
|
12541
|
-
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs2.__patched) {
|
|
12542
|
-
module.exports = patch(fs2);
|
|
12543
|
-
fs2.__patched = true;
|
|
12544
|
-
}
|
|
12545
|
-
function patch(fs3) {
|
|
12546
|
-
polyfills(fs3);
|
|
12547
|
-
fs3.gracefulify = patch;
|
|
12548
|
-
fs3.createReadStream = createReadStream;
|
|
12549
|
-
fs3.createWriteStream = createWriteStream;
|
|
12550
|
-
var fs$readFile = fs3.readFile;
|
|
12551
|
-
fs3.readFile = readFile;
|
|
12552
|
-
function readFile(path, options, cb) {
|
|
12553
|
-
if (typeof options === "function")
|
|
12554
|
-
cb = options, options = null;
|
|
12555
|
-
return go$readFile(path, options, cb);
|
|
12556
|
-
function go$readFile(path2, options2, cb2, startTime) {
|
|
12557
|
-
return fs$readFile(path2, options2, function(err) {
|
|
12558
|
-
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
12559
|
-
enqueue([go$readFile, [path2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
12560
|
-
else {
|
|
12561
|
-
if (typeof cb2 === "function")
|
|
12562
|
-
cb2.apply(this, arguments);
|
|
12563
|
-
}
|
|
12564
|
-
});
|
|
12565
|
-
}
|
|
12566
|
-
}
|
|
12567
|
-
var fs$writeFile = fs3.writeFile;
|
|
12568
|
-
fs3.writeFile = writeFile;
|
|
12569
|
-
function writeFile(path, data, options, cb) {
|
|
12570
|
-
if (typeof options === "function")
|
|
12571
|
-
cb = options, options = null;
|
|
12572
|
-
return go$writeFile(path, data, options, cb);
|
|
12573
|
-
function go$writeFile(path2, data2, options2, cb2, startTime) {
|
|
12574
|
-
return fs$writeFile(path2, data2, options2, function(err) {
|
|
12575
|
-
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
12576
|
-
enqueue([go$writeFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
12577
|
-
else {
|
|
12578
|
-
if (typeof cb2 === "function")
|
|
12579
|
-
cb2.apply(this, arguments);
|
|
12580
|
-
}
|
|
12581
|
-
});
|
|
12582
|
-
}
|
|
12583
|
-
}
|
|
12584
|
-
var fs$appendFile = fs3.appendFile;
|
|
12585
|
-
if (fs$appendFile)
|
|
12586
|
-
fs3.appendFile = appendFile;
|
|
12587
|
-
function appendFile(path, data, options, cb) {
|
|
12588
|
-
if (typeof options === "function")
|
|
12589
|
-
cb = options, options = null;
|
|
12590
|
-
return go$appendFile(path, data, options, cb);
|
|
12591
|
-
function go$appendFile(path2, data2, options2, cb2, startTime) {
|
|
12592
|
-
return fs$appendFile(path2, data2, options2, function(err) {
|
|
12593
|
-
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
12594
|
-
enqueue([go$appendFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
12595
|
-
else {
|
|
12596
|
-
if (typeof cb2 === "function")
|
|
12597
|
-
cb2.apply(this, arguments);
|
|
12598
|
-
}
|
|
12599
|
-
});
|
|
12600
|
-
}
|
|
12601
|
-
}
|
|
12602
|
-
var fs$copyFile = fs3.copyFile;
|
|
12603
|
-
if (fs$copyFile)
|
|
12604
|
-
fs3.copyFile = copyFile;
|
|
12605
|
-
function copyFile(src, dest, flags, cb) {
|
|
12606
|
-
if (typeof flags === "function") {
|
|
12607
|
-
cb = flags;
|
|
12608
|
-
flags = 0;
|
|
12609
|
-
}
|
|
12610
|
-
return go$copyFile(src, dest, flags, cb);
|
|
12611
|
-
function go$copyFile(src2, dest2, flags2, cb2, startTime) {
|
|
12612
|
-
return fs$copyFile(src2, dest2, flags2, function(err) {
|
|
12613
|
-
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
12614
|
-
enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
12615
|
-
else {
|
|
12616
|
-
if (typeof cb2 === "function")
|
|
12617
|
-
cb2.apply(this, arguments);
|
|
12618
|
-
}
|
|
12619
|
-
});
|
|
12620
|
-
}
|
|
12621
|
-
}
|
|
12622
|
-
var fs$readdir = fs3.readdir;
|
|
12623
|
-
fs3.readdir = readdir;
|
|
12624
|
-
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
12625
|
-
function readdir(path, options, cb) {
|
|
12626
|
-
if (typeof options === "function")
|
|
12627
|
-
cb = options, options = null;
|
|
12628
|
-
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path2, options2, cb2, startTime) {
|
|
12629
|
-
return fs$readdir(path2, fs$readdirCallback(
|
|
12630
|
-
path2,
|
|
12631
|
-
options2,
|
|
12632
|
-
cb2,
|
|
12633
|
-
startTime
|
|
12634
|
-
));
|
|
12635
|
-
} : function go$readdir2(path2, options2, cb2, startTime) {
|
|
12636
|
-
return fs$readdir(path2, options2, fs$readdirCallback(
|
|
12637
|
-
path2,
|
|
12638
|
-
options2,
|
|
12639
|
-
cb2,
|
|
12640
|
-
startTime
|
|
12641
|
-
));
|
|
12642
|
-
};
|
|
12643
|
-
return go$readdir(path, options, cb);
|
|
12644
|
-
function fs$readdirCallback(path2, options2, cb2, startTime) {
|
|
12645
|
-
return function(err, files) {
|
|
12646
|
-
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
12647
|
-
enqueue([
|
|
12648
|
-
go$readdir,
|
|
12649
|
-
[path2, options2, cb2],
|
|
12650
|
-
err,
|
|
12651
|
-
startTime || Date.now(),
|
|
12652
|
-
Date.now()
|
|
12653
|
-
]);
|
|
12654
|
-
else {
|
|
12655
|
-
if (files && files.sort)
|
|
12656
|
-
files.sort();
|
|
12657
|
-
if (typeof cb2 === "function")
|
|
12658
|
-
cb2.call(this, err, files);
|
|
12659
|
-
}
|
|
12660
|
-
};
|
|
12661
|
-
}
|
|
12662
|
-
}
|
|
12663
|
-
if (process.version.substr(0, 4) === "v0.8") {
|
|
12664
|
-
var legStreams = legacy(fs3);
|
|
12665
|
-
ReadStream = legStreams.ReadStream;
|
|
12666
|
-
WriteStream = legStreams.WriteStream;
|
|
12667
|
-
}
|
|
12668
|
-
var fs$ReadStream = fs3.ReadStream;
|
|
12669
|
-
if (fs$ReadStream) {
|
|
12670
|
-
ReadStream.prototype = Object.create(fs$ReadStream.prototype);
|
|
12671
|
-
ReadStream.prototype.open = ReadStream$open;
|
|
12672
|
-
}
|
|
12673
|
-
var fs$WriteStream = fs3.WriteStream;
|
|
12674
|
-
if (fs$WriteStream) {
|
|
12675
|
-
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
|
|
12676
|
-
WriteStream.prototype.open = WriteStream$open;
|
|
12677
|
-
}
|
|
12678
|
-
Object.defineProperty(fs3, "ReadStream", {
|
|
12679
|
-
get: function() {
|
|
12680
|
-
return ReadStream;
|
|
12681
|
-
},
|
|
12682
|
-
set: function(val) {
|
|
12683
|
-
ReadStream = val;
|
|
12684
|
-
},
|
|
12685
|
-
enumerable: true,
|
|
12686
|
-
configurable: true
|
|
12687
|
-
});
|
|
12688
|
-
Object.defineProperty(fs3, "WriteStream", {
|
|
12689
|
-
get: function() {
|
|
12690
|
-
return WriteStream;
|
|
12691
|
-
},
|
|
12692
|
-
set: function(val) {
|
|
12693
|
-
WriteStream = val;
|
|
12694
|
-
},
|
|
12695
|
-
enumerable: true,
|
|
12696
|
-
configurable: true
|
|
12697
|
-
});
|
|
12698
|
-
var FileReadStream = ReadStream;
|
|
12699
|
-
Object.defineProperty(fs3, "FileReadStream", {
|
|
12700
|
-
get: function() {
|
|
12701
|
-
return FileReadStream;
|
|
12702
|
-
},
|
|
12703
|
-
set: function(val) {
|
|
12704
|
-
FileReadStream = val;
|
|
12705
|
-
},
|
|
12706
|
-
enumerable: true,
|
|
12707
|
-
configurable: true
|
|
12708
|
-
});
|
|
12709
|
-
var FileWriteStream = WriteStream;
|
|
12710
|
-
Object.defineProperty(fs3, "FileWriteStream", {
|
|
12711
|
-
get: function() {
|
|
12712
|
-
return FileWriteStream;
|
|
12713
|
-
},
|
|
12714
|
-
set: function(val) {
|
|
12715
|
-
FileWriteStream = val;
|
|
12716
|
-
},
|
|
12717
|
-
enumerable: true,
|
|
12718
|
-
configurable: true
|
|
12719
|
-
});
|
|
12720
|
-
function ReadStream(path, options) {
|
|
12721
|
-
if (this instanceof ReadStream)
|
|
12722
|
-
return fs$ReadStream.apply(this, arguments), this;
|
|
12723
|
-
else
|
|
12724
|
-
return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
|
|
12725
|
-
}
|
|
12726
|
-
function ReadStream$open() {
|
|
12727
|
-
var that = this;
|
|
12728
|
-
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
12729
|
-
if (err) {
|
|
12730
|
-
if (that.autoClose)
|
|
12731
|
-
that.destroy();
|
|
12732
|
-
that.emit("error", err);
|
|
12733
|
-
} else {
|
|
12734
|
-
that.fd = fd;
|
|
12735
|
-
that.emit("open", fd);
|
|
12736
|
-
that.read();
|
|
12737
|
-
}
|
|
12738
|
-
});
|
|
12739
|
-
}
|
|
12740
|
-
function WriteStream(path, options) {
|
|
12741
|
-
if (this instanceof WriteStream)
|
|
12742
|
-
return fs$WriteStream.apply(this, arguments), this;
|
|
12743
|
-
else
|
|
12744
|
-
return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
|
|
12745
|
-
}
|
|
12746
|
-
function WriteStream$open() {
|
|
12747
|
-
var that = this;
|
|
12748
|
-
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
12749
|
-
if (err) {
|
|
12750
|
-
that.destroy();
|
|
12751
|
-
that.emit("error", err);
|
|
12752
|
-
} else {
|
|
12753
|
-
that.fd = fd;
|
|
12754
|
-
that.emit("open", fd);
|
|
12755
|
-
}
|
|
12756
|
-
});
|
|
12757
|
-
}
|
|
12758
|
-
function createReadStream(path, options) {
|
|
12759
|
-
return new fs3.ReadStream(path, options);
|
|
12760
|
-
}
|
|
12761
|
-
function createWriteStream(path, options) {
|
|
12762
|
-
return new fs3.WriteStream(path, options);
|
|
12763
|
-
}
|
|
12764
|
-
var fs$open = fs3.open;
|
|
12765
|
-
fs3.open = open;
|
|
12766
|
-
function open(path, flags, mode, cb) {
|
|
12767
|
-
if (typeof mode === "function")
|
|
12768
|
-
cb = mode, mode = null;
|
|
12769
|
-
return go$open(path, flags, mode, cb);
|
|
12770
|
-
function go$open(path2, flags2, mode2, cb2, startTime) {
|
|
12771
|
-
return fs$open(path2, flags2, mode2, function(err, fd) {
|
|
12772
|
-
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
12773
|
-
enqueue([go$open, [path2, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
12774
|
-
else {
|
|
12775
|
-
if (typeof cb2 === "function")
|
|
12776
|
-
cb2.apply(this, arguments);
|
|
12777
|
-
}
|
|
12778
|
-
});
|
|
12779
|
-
}
|
|
12780
|
-
}
|
|
12781
|
-
return fs3;
|
|
12782
|
-
}
|
|
12783
|
-
function enqueue(elem) {
|
|
12784
|
-
debug("ENQUEUE", elem[0].name, elem[1]);
|
|
12785
|
-
fs2[gracefulQueue].push(elem);
|
|
12786
|
-
retry();
|
|
12787
|
-
}
|
|
12788
|
-
var retryTimer;
|
|
12789
|
-
function resetQueue() {
|
|
12790
|
-
var now = Date.now();
|
|
12791
|
-
for (var i = 0; i < fs2[gracefulQueue].length; ++i) {
|
|
12792
|
-
if (fs2[gracefulQueue][i].length > 2) {
|
|
12793
|
-
fs2[gracefulQueue][i][3] = now;
|
|
12794
|
-
fs2[gracefulQueue][i][4] = now;
|
|
12795
|
-
}
|
|
12796
|
-
}
|
|
12797
|
-
retry();
|
|
12798
|
-
}
|
|
12799
|
-
function retry() {
|
|
12800
|
-
clearTimeout(retryTimer);
|
|
12801
|
-
retryTimer = void 0;
|
|
12802
|
-
if (fs2[gracefulQueue].length === 0)
|
|
12803
|
-
return;
|
|
12804
|
-
var elem = fs2[gracefulQueue].shift();
|
|
12805
|
-
var fn = elem[0];
|
|
12806
|
-
var args = elem[1];
|
|
12807
|
-
var err = elem[2];
|
|
12808
|
-
var startTime = elem[3];
|
|
12809
|
-
var lastTime = elem[4];
|
|
12810
|
-
if (startTime === void 0) {
|
|
12811
|
-
debug("RETRY", fn.name, args);
|
|
12812
|
-
fn.apply(null, args);
|
|
12813
|
-
} else if (Date.now() - startTime >= 6e4) {
|
|
12814
|
-
debug("TIMEOUT", fn.name, args);
|
|
12815
|
-
var cb = args.pop();
|
|
12816
|
-
if (typeof cb === "function")
|
|
12817
|
-
cb.call(null, err);
|
|
12818
|
-
} else {
|
|
12819
|
-
var sinceAttempt = Date.now() - lastTime;
|
|
12820
|
-
var sinceStart = Math.max(lastTime - startTime, 1);
|
|
12821
|
-
var desiredDelay = Math.min(sinceStart * 1.2, 100);
|
|
12822
|
-
if (sinceAttempt >= desiredDelay) {
|
|
12823
|
-
debug("RETRY", fn.name, args);
|
|
12824
|
-
fn.apply(null, args.concat([startTime]));
|
|
12825
|
-
} else {
|
|
12826
|
-
fs2[gracefulQueue].push(elem);
|
|
12827
|
-
}
|
|
12828
|
-
}
|
|
12829
|
-
if (retryTimer === void 0) {
|
|
12830
|
-
retryTimer = setTimeout(retry, 0);
|
|
12831
|
-
}
|
|
12832
|
-
}
|
|
12833
|
-
}
|
|
12834
|
-
});
|
|
12835
|
-
|
|
12836
|
-
// node_modules/proper-lockfile/node_modules/retry/lib/retry_operation.js
|
|
12837
|
-
var require_retry_operation = __commonJS({
|
|
12838
|
-
"node_modules/proper-lockfile/node_modules/retry/lib/retry_operation.js"(exports, module) {
|
|
12839
|
-
function RetryOperation(timeouts, options) {
|
|
12840
|
-
if (typeof options === "boolean") {
|
|
12841
|
-
options = { forever: options };
|
|
12842
|
-
}
|
|
12843
|
-
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
12844
|
-
this._timeouts = timeouts;
|
|
12845
|
-
this._options = options || {};
|
|
12846
|
-
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
12847
|
-
this._fn = null;
|
|
12848
|
-
this._errors = [];
|
|
12849
|
-
this._attempts = 1;
|
|
12850
|
-
this._operationTimeout = null;
|
|
12851
|
-
this._operationTimeoutCb = null;
|
|
12852
|
-
this._timeout = null;
|
|
12853
|
-
this._operationStart = null;
|
|
12854
|
-
if (this._options.forever) {
|
|
12855
|
-
this._cachedTimeouts = this._timeouts.slice(0);
|
|
12856
|
-
}
|
|
12857
|
-
}
|
|
12858
|
-
module.exports = RetryOperation;
|
|
12859
|
-
RetryOperation.prototype.reset = function() {
|
|
12860
|
-
this._attempts = 1;
|
|
12861
|
-
this._timeouts = this._originalTimeouts;
|
|
12862
|
-
};
|
|
12863
|
-
RetryOperation.prototype.stop = function() {
|
|
12864
|
-
if (this._timeout) {
|
|
12865
|
-
clearTimeout(this._timeout);
|
|
12866
|
-
}
|
|
12867
|
-
this._timeouts = [];
|
|
12868
|
-
this._cachedTimeouts = null;
|
|
12869
|
-
};
|
|
12870
|
-
RetryOperation.prototype.retry = function(err) {
|
|
12871
|
-
if (this._timeout) {
|
|
12872
|
-
clearTimeout(this._timeout);
|
|
12873
|
-
}
|
|
12874
|
-
if (!err) {
|
|
12875
|
-
return false;
|
|
12876
|
-
}
|
|
12877
|
-
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
12878
|
-
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
12879
|
-
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
12880
|
-
return false;
|
|
12881
|
-
}
|
|
12882
|
-
this._errors.push(err);
|
|
12883
|
-
var timeout = this._timeouts.shift();
|
|
12884
|
-
if (timeout === void 0) {
|
|
12885
|
-
if (this._cachedTimeouts) {
|
|
12886
|
-
this._errors.splice(this._errors.length - 1, this._errors.length);
|
|
12887
|
-
this._timeouts = this._cachedTimeouts.slice(0);
|
|
12888
|
-
timeout = this._timeouts.shift();
|
|
12889
|
-
} else {
|
|
12890
|
-
return false;
|
|
12891
|
-
}
|
|
12892
|
-
}
|
|
12893
|
-
var self = this;
|
|
12894
|
-
var timer = setTimeout(function() {
|
|
12895
|
-
self._attempts++;
|
|
12896
|
-
if (self._operationTimeoutCb) {
|
|
12897
|
-
self._timeout = setTimeout(function() {
|
|
12898
|
-
self._operationTimeoutCb(self._attempts);
|
|
12899
|
-
}, self._operationTimeout);
|
|
12900
|
-
if (self._options.unref) {
|
|
12901
|
-
self._timeout.unref();
|
|
12902
|
-
}
|
|
12903
|
-
}
|
|
12904
|
-
self._fn(self._attempts);
|
|
12905
|
-
}, timeout);
|
|
12906
|
-
if (this._options.unref) {
|
|
12907
|
-
timer.unref();
|
|
12908
|
-
}
|
|
12909
|
-
return true;
|
|
12910
|
-
};
|
|
12911
|
-
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
12912
|
-
this._fn = fn;
|
|
12913
|
-
if (timeoutOps) {
|
|
12914
|
-
if (timeoutOps.timeout) {
|
|
12915
|
-
this._operationTimeout = timeoutOps.timeout;
|
|
12916
|
-
}
|
|
12917
|
-
if (timeoutOps.cb) {
|
|
12918
|
-
this._operationTimeoutCb = timeoutOps.cb;
|
|
12919
|
-
}
|
|
12920
|
-
}
|
|
12921
|
-
var self = this;
|
|
12922
|
-
if (this._operationTimeoutCb) {
|
|
12923
|
-
this._timeout = setTimeout(function() {
|
|
12924
|
-
self._operationTimeoutCb();
|
|
12925
|
-
}, self._operationTimeout);
|
|
12926
|
-
}
|
|
12927
|
-
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
12928
|
-
this._fn(this._attempts);
|
|
12929
|
-
};
|
|
12930
|
-
RetryOperation.prototype.try = function(fn) {
|
|
12931
|
-
console.log("Using RetryOperation.try() is deprecated");
|
|
12932
|
-
this.attempt(fn);
|
|
12933
|
-
};
|
|
12934
|
-
RetryOperation.prototype.start = function(fn) {
|
|
12935
|
-
console.log("Using RetryOperation.start() is deprecated");
|
|
12936
|
-
this.attempt(fn);
|
|
12937
|
-
};
|
|
12938
|
-
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
12939
|
-
RetryOperation.prototype.errors = function() {
|
|
12940
|
-
return this._errors;
|
|
12941
|
-
};
|
|
12942
|
-
RetryOperation.prototype.attempts = function() {
|
|
12943
|
-
return this._attempts;
|
|
12944
|
-
};
|
|
12945
|
-
RetryOperation.prototype.mainError = function() {
|
|
12946
|
-
if (this._errors.length === 0) {
|
|
12947
|
-
return null;
|
|
12948
|
-
}
|
|
12949
|
-
var counts = {};
|
|
12950
|
-
var mainError = null;
|
|
12951
|
-
var mainErrorCount = 0;
|
|
12952
|
-
for (var i = 0; i < this._errors.length; i++) {
|
|
12953
|
-
var error2 = this._errors[i];
|
|
12954
|
-
var message = error2.message;
|
|
12955
|
-
var count = (counts[message] || 0) + 1;
|
|
12956
|
-
counts[message] = count;
|
|
12957
|
-
if (count >= mainErrorCount) {
|
|
12958
|
-
mainError = error2;
|
|
12959
|
-
mainErrorCount = count;
|
|
12960
|
-
}
|
|
12961
|
-
}
|
|
12962
|
-
return mainError;
|
|
12963
|
-
};
|
|
12964
|
-
}
|
|
12965
|
-
});
|
|
12966
|
-
|
|
12967
|
-
// node_modules/proper-lockfile/node_modules/retry/lib/retry.js
|
|
12968
|
-
var require_retry = __commonJS({
|
|
12969
|
-
"node_modules/proper-lockfile/node_modules/retry/lib/retry.js"(exports) {
|
|
12970
|
-
var RetryOperation = require_retry_operation();
|
|
12971
|
-
exports.operation = function(options) {
|
|
12972
|
-
var timeouts = exports.timeouts(options);
|
|
12973
|
-
return new RetryOperation(timeouts, {
|
|
12974
|
-
forever: options && options.forever,
|
|
12975
|
-
unref: options && options.unref,
|
|
12976
|
-
maxRetryTime: options && options.maxRetryTime
|
|
12977
|
-
});
|
|
12978
|
-
};
|
|
12979
|
-
exports.timeouts = function(options) {
|
|
12980
|
-
if (options instanceof Array) {
|
|
12981
|
-
return [].concat(options);
|
|
12982
|
-
}
|
|
12983
|
-
var opts = {
|
|
12984
|
-
retries: 10,
|
|
12985
|
-
factor: 2,
|
|
12986
|
-
minTimeout: 1 * 1e3,
|
|
12987
|
-
maxTimeout: Infinity,
|
|
12988
|
-
randomize: false
|
|
12989
|
-
};
|
|
12990
|
-
for (var key in options) {
|
|
12991
|
-
opts[key] = options[key];
|
|
12992
|
-
}
|
|
12993
|
-
if (opts.minTimeout > opts.maxTimeout) {
|
|
12994
|
-
throw new Error("minTimeout is greater than maxTimeout");
|
|
12995
|
-
}
|
|
12996
|
-
var timeouts = [];
|
|
12997
|
-
for (var i = 0; i < opts.retries; i++) {
|
|
12998
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
12999
|
-
}
|
|
13000
|
-
if (options && options.forever && !timeouts.length) {
|
|
13001
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
13002
|
-
}
|
|
13003
|
-
timeouts.sort(function(a, b) {
|
|
13004
|
-
return a - b;
|
|
13005
|
-
});
|
|
13006
|
-
return timeouts;
|
|
13007
|
-
};
|
|
13008
|
-
exports.createTimeout = function(attempt, opts) {
|
|
13009
|
-
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
13010
|
-
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
|
|
13011
|
-
timeout = Math.min(timeout, opts.maxTimeout);
|
|
13012
|
-
return timeout;
|
|
13013
|
-
};
|
|
13014
|
-
exports.wrap = function(obj, options, methods) {
|
|
13015
|
-
if (options instanceof Array) {
|
|
13016
|
-
methods = options;
|
|
13017
|
-
options = null;
|
|
13018
|
-
}
|
|
13019
|
-
if (!methods) {
|
|
13020
|
-
methods = [];
|
|
13021
|
-
for (var key in obj) {
|
|
13022
|
-
if (typeof obj[key] === "function") {
|
|
13023
|
-
methods.push(key);
|
|
13024
|
-
}
|
|
13025
|
-
}
|
|
13026
|
-
}
|
|
13027
|
-
for (var i = 0; i < methods.length; i++) {
|
|
13028
|
-
var method = methods[i];
|
|
13029
|
-
var original = obj[method];
|
|
13030
|
-
obj[method] = function retryWrapper(original2) {
|
|
13031
|
-
var op = exports.operation(options);
|
|
13032
|
-
var args = Array.prototype.slice.call(arguments, 1);
|
|
13033
|
-
var callback = args.pop();
|
|
13034
|
-
args.push(function(err) {
|
|
13035
|
-
if (op.retry(err)) {
|
|
13036
|
-
return;
|
|
13037
|
-
}
|
|
13038
|
-
if (err) {
|
|
13039
|
-
arguments[0] = op.mainError();
|
|
13040
|
-
}
|
|
13041
|
-
callback.apply(this, arguments);
|
|
13042
|
-
});
|
|
13043
|
-
op.attempt(function() {
|
|
13044
|
-
original2.apply(obj, args);
|
|
13045
|
-
});
|
|
13046
|
-
}.bind(obj, original);
|
|
13047
|
-
obj[method].options = options;
|
|
13048
|
-
}
|
|
13049
|
-
};
|
|
13050
|
-
}
|
|
13051
|
-
});
|
|
13052
|
-
|
|
13053
|
-
// node_modules/proper-lockfile/node_modules/retry/index.js
|
|
13054
|
-
var require_retry2 = __commonJS({
|
|
13055
|
-
"node_modules/proper-lockfile/node_modules/retry/index.js"(exports, module) {
|
|
13056
|
-
module.exports = require_retry();
|
|
13057
|
-
}
|
|
13058
|
-
});
|
|
13059
|
-
|
|
13060
|
-
// node_modules/signal-exit/signals.js
|
|
13061
|
-
var require_signals = __commonJS({
|
|
13062
|
-
"node_modules/signal-exit/signals.js"(exports, module) {
|
|
13063
|
-
module.exports = [
|
|
13064
|
-
"SIGABRT",
|
|
13065
|
-
"SIGALRM",
|
|
13066
|
-
"SIGHUP",
|
|
13067
|
-
"SIGINT",
|
|
13068
|
-
"SIGTERM"
|
|
13069
|
-
];
|
|
13070
|
-
if (process.platform !== "win32") {
|
|
13071
|
-
module.exports.push(
|
|
13072
|
-
"SIGVTALRM",
|
|
13073
|
-
"SIGXCPU",
|
|
13074
|
-
"SIGXFSZ",
|
|
13075
|
-
"SIGUSR2",
|
|
13076
|
-
"SIGTRAP",
|
|
13077
|
-
"SIGSYS",
|
|
13078
|
-
"SIGQUIT",
|
|
13079
|
-
"SIGIOT"
|
|
13080
|
-
// should detect profiler and enable/disable accordingly.
|
|
13081
|
-
// see #21
|
|
13082
|
-
// 'SIGPROF'
|
|
13083
|
-
);
|
|
13084
|
-
}
|
|
13085
|
-
if (process.platform === "linux") {
|
|
13086
|
-
module.exports.push(
|
|
13087
|
-
"SIGIO",
|
|
13088
|
-
"SIGPOLL",
|
|
13089
|
-
"SIGPWR",
|
|
13090
|
-
"SIGSTKFLT",
|
|
13091
|
-
"SIGUNUSED"
|
|
13092
|
-
);
|
|
13093
|
-
}
|
|
13094
|
-
}
|
|
13095
|
-
});
|
|
13096
|
-
|
|
13097
|
-
// node_modules/signal-exit/index.js
|
|
13098
|
-
var require_signal_exit = __commonJS({
|
|
13099
|
-
"node_modules/signal-exit/index.js"(exports, module) {
|
|
13100
|
-
var process2 = global.process;
|
|
13101
|
-
var processOk = function(process3) {
|
|
13102
|
-
return process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
|
|
13103
|
-
};
|
|
13104
|
-
if (!processOk(process2)) {
|
|
13105
|
-
module.exports = function() {
|
|
13106
|
-
return function() {
|
|
13107
|
-
};
|
|
13108
|
-
};
|
|
13109
|
-
} else {
|
|
13110
|
-
assert = __require("assert");
|
|
13111
|
-
signals = require_signals();
|
|
13112
|
-
isWin = /^win/i.test(process2.platform);
|
|
13113
|
-
EE = __require("events");
|
|
13114
|
-
if (typeof EE !== "function") {
|
|
13115
|
-
EE = EE.EventEmitter;
|
|
13116
|
-
}
|
|
13117
|
-
if (process2.__signal_exit_emitter__) {
|
|
13118
|
-
emitter = process2.__signal_exit_emitter__;
|
|
13119
|
-
} else {
|
|
13120
|
-
emitter = process2.__signal_exit_emitter__ = new EE();
|
|
13121
|
-
emitter.count = 0;
|
|
13122
|
-
emitter.emitted = {};
|
|
13123
|
-
}
|
|
13124
|
-
if (!emitter.infinite) {
|
|
13125
|
-
emitter.setMaxListeners(Infinity);
|
|
13126
|
-
emitter.infinite = true;
|
|
13127
|
-
}
|
|
13128
|
-
module.exports = function(cb, opts) {
|
|
13129
|
-
if (!processOk(global.process)) {
|
|
13130
|
-
return function() {
|
|
13131
|
-
};
|
|
13132
|
-
}
|
|
13133
|
-
assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
|
|
13134
|
-
if (loaded === false) {
|
|
13135
|
-
load();
|
|
13136
|
-
}
|
|
13137
|
-
var ev = "exit";
|
|
13138
|
-
if (opts && opts.alwaysLast) {
|
|
13139
|
-
ev = "afterexit";
|
|
13140
|
-
}
|
|
13141
|
-
var remove = function() {
|
|
13142
|
-
emitter.removeListener(ev, cb);
|
|
13143
|
-
if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) {
|
|
13144
|
-
unload();
|
|
13145
|
-
}
|
|
13146
|
-
};
|
|
13147
|
-
emitter.on(ev, cb);
|
|
13148
|
-
return remove;
|
|
13149
|
-
};
|
|
13150
|
-
unload = function unload2() {
|
|
13151
|
-
if (!loaded || !processOk(global.process)) {
|
|
13152
|
-
return;
|
|
13153
|
-
}
|
|
13154
|
-
loaded = false;
|
|
13155
|
-
signals.forEach(function(sig) {
|
|
13156
|
-
try {
|
|
13157
|
-
process2.removeListener(sig, sigListeners[sig]);
|
|
13158
|
-
} catch (er) {
|
|
13159
|
-
}
|
|
13160
|
-
});
|
|
13161
|
-
process2.emit = originalProcessEmit;
|
|
13162
|
-
process2.reallyExit = originalProcessReallyExit;
|
|
13163
|
-
emitter.count -= 1;
|
|
13164
|
-
};
|
|
13165
|
-
module.exports.unload = unload;
|
|
13166
|
-
emit = function emit2(event, code, signal) {
|
|
13167
|
-
if (emitter.emitted[event]) {
|
|
13168
|
-
return;
|
|
13169
|
-
}
|
|
13170
|
-
emitter.emitted[event] = true;
|
|
13171
|
-
emitter.emit(event, code, signal);
|
|
13172
|
-
};
|
|
13173
|
-
sigListeners = {};
|
|
13174
|
-
signals.forEach(function(sig) {
|
|
13175
|
-
sigListeners[sig] = function listener() {
|
|
13176
|
-
if (!processOk(global.process)) {
|
|
13177
|
-
return;
|
|
13178
|
-
}
|
|
13179
|
-
var listeners = process2.listeners(sig);
|
|
13180
|
-
if (listeners.length === emitter.count) {
|
|
13181
|
-
unload();
|
|
13182
|
-
emit("exit", null, sig);
|
|
13183
|
-
emit("afterexit", null, sig);
|
|
13184
|
-
if (isWin && sig === "SIGHUP") {
|
|
13185
|
-
sig = "SIGINT";
|
|
13186
|
-
}
|
|
13187
|
-
process2.kill(process2.pid, sig);
|
|
13188
|
-
}
|
|
13189
|
-
};
|
|
13190
|
-
});
|
|
13191
|
-
module.exports.signals = function() {
|
|
13192
|
-
return signals;
|
|
13193
|
-
};
|
|
13194
|
-
loaded = false;
|
|
13195
|
-
load = function load2() {
|
|
13196
|
-
if (loaded || !processOk(global.process)) {
|
|
13197
|
-
return;
|
|
13198
|
-
}
|
|
13199
|
-
loaded = true;
|
|
13200
|
-
emitter.count += 1;
|
|
13201
|
-
signals = signals.filter(function(sig) {
|
|
13202
|
-
try {
|
|
13203
|
-
process2.on(sig, sigListeners[sig]);
|
|
13204
|
-
return true;
|
|
13205
|
-
} catch (er) {
|
|
13206
|
-
return false;
|
|
13207
|
-
}
|
|
13208
|
-
});
|
|
13209
|
-
process2.emit = processEmit;
|
|
13210
|
-
process2.reallyExit = processReallyExit;
|
|
13211
|
-
};
|
|
13212
|
-
module.exports.load = load;
|
|
13213
|
-
originalProcessReallyExit = process2.reallyExit;
|
|
13214
|
-
processReallyExit = function processReallyExit2(code) {
|
|
13215
|
-
if (!processOk(global.process)) {
|
|
13216
|
-
return;
|
|
13217
|
-
}
|
|
13218
|
-
process2.exitCode = code || /* istanbul ignore next */
|
|
13219
|
-
0;
|
|
13220
|
-
emit("exit", process2.exitCode, null);
|
|
13221
|
-
emit("afterexit", process2.exitCode, null);
|
|
13222
|
-
originalProcessReallyExit.call(process2, process2.exitCode);
|
|
13223
|
-
};
|
|
13224
|
-
originalProcessEmit = process2.emit;
|
|
13225
|
-
processEmit = function processEmit2(ev, arg) {
|
|
13226
|
-
if (ev === "exit" && processOk(global.process)) {
|
|
13227
|
-
if (arg !== void 0) {
|
|
13228
|
-
process2.exitCode = arg;
|
|
13229
|
-
}
|
|
13230
|
-
var ret = originalProcessEmit.apply(this, arguments);
|
|
13231
|
-
emit("exit", process2.exitCode, null);
|
|
13232
|
-
emit("afterexit", process2.exitCode, null);
|
|
13233
|
-
return ret;
|
|
13234
|
-
} else {
|
|
13235
|
-
return originalProcessEmit.apply(this, arguments);
|
|
13236
|
-
}
|
|
13237
|
-
};
|
|
13238
|
-
}
|
|
13239
|
-
var assert;
|
|
13240
|
-
var signals;
|
|
13241
|
-
var isWin;
|
|
13242
|
-
var EE;
|
|
13243
|
-
var emitter;
|
|
13244
|
-
var unload;
|
|
13245
|
-
var emit;
|
|
13246
|
-
var sigListeners;
|
|
13247
|
-
var loaded;
|
|
13248
|
-
var load;
|
|
13249
|
-
var originalProcessReallyExit;
|
|
13250
|
-
var processReallyExit;
|
|
13251
|
-
var originalProcessEmit;
|
|
13252
|
-
var processEmit;
|
|
13253
|
-
}
|
|
13254
|
-
});
|
|
13255
|
-
|
|
13256
|
-
// node_modules/proper-lockfile/lib/mtime-precision.js
|
|
13257
|
-
var require_mtime_precision = __commonJS({
|
|
13258
|
-
"node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module) {
|
|
13259
|
-
"use strict";
|
|
13260
|
-
var cacheSymbol = /* @__PURE__ */ Symbol();
|
|
13261
|
-
function probe(file2, fs2, callback) {
|
|
13262
|
-
const cachedPrecision = fs2[cacheSymbol];
|
|
13263
|
-
if (cachedPrecision) {
|
|
13264
|
-
return fs2.stat(file2, (err, stat) => {
|
|
13265
|
-
if (err) {
|
|
13266
|
-
return callback(err);
|
|
13267
|
-
}
|
|
13268
|
-
callback(null, stat.mtime, cachedPrecision);
|
|
13269
|
-
});
|
|
13270
|
-
}
|
|
13271
|
-
const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
|
|
13272
|
-
fs2.utimes(file2, mtime, mtime, (err) => {
|
|
13273
|
-
if (err) {
|
|
13274
|
-
return callback(err);
|
|
13275
|
-
}
|
|
13276
|
-
fs2.stat(file2, (err2, stat) => {
|
|
13277
|
-
if (err2) {
|
|
13278
|
-
return callback(err2);
|
|
13279
|
-
}
|
|
13280
|
-
const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
|
|
13281
|
-
Object.defineProperty(fs2, cacheSymbol, { value: precision });
|
|
13282
|
-
callback(null, stat.mtime, precision);
|
|
13283
|
-
});
|
|
13284
|
-
});
|
|
13285
|
-
}
|
|
13286
|
-
function getMtime(precision) {
|
|
13287
|
-
let now = Date.now();
|
|
13288
|
-
if (precision === "s") {
|
|
13289
|
-
now = Math.ceil(now / 1e3) * 1e3;
|
|
13290
|
-
}
|
|
13291
|
-
return new Date(now);
|
|
13292
|
-
}
|
|
13293
|
-
module.exports.probe = probe;
|
|
13294
|
-
module.exports.getMtime = getMtime;
|
|
13295
|
-
}
|
|
13296
|
-
});
|
|
13297
|
-
|
|
13298
|
-
// node_modules/proper-lockfile/lib/lockfile.js
|
|
13299
|
-
var require_lockfile = __commonJS({
|
|
13300
|
-
"node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
|
|
13301
|
-
"use strict";
|
|
13302
|
-
var path = __require("path");
|
|
13303
|
-
var fs2 = require_graceful_fs();
|
|
13304
|
-
var retry = require_retry2();
|
|
13305
|
-
var onExit = require_signal_exit();
|
|
13306
|
-
var mtimePrecision = require_mtime_precision();
|
|
13307
|
-
var locks = {};
|
|
13308
|
-
function getLockFile(file2, options) {
|
|
13309
|
-
return options.lockfilePath || `${file2}.lock`;
|
|
13310
|
-
}
|
|
13311
|
-
function resolveCanonicalPath(file2, options, callback) {
|
|
13312
|
-
if (!options.realpath) {
|
|
13313
|
-
return callback(null, path.resolve(file2));
|
|
13314
|
-
}
|
|
13315
|
-
options.fs.realpath(file2, callback);
|
|
13316
|
-
}
|
|
13317
|
-
function acquireLock(file2, options, callback) {
|
|
13318
|
-
const lockfilePath = getLockFile(file2, options);
|
|
13319
|
-
options.fs.mkdir(lockfilePath, (err) => {
|
|
13320
|
-
if (!err) {
|
|
13321
|
-
return mtimePrecision.probe(lockfilePath, options.fs, (err2, mtime, mtimePrecision2) => {
|
|
13322
|
-
if (err2) {
|
|
13323
|
-
options.fs.rmdir(lockfilePath, () => {
|
|
13324
|
-
});
|
|
13325
|
-
return callback(err2);
|
|
13326
|
-
}
|
|
13327
|
-
callback(null, mtime, mtimePrecision2);
|
|
13328
|
-
});
|
|
13329
|
-
}
|
|
13330
|
-
if (err.code !== "EEXIST") {
|
|
13331
|
-
return callback(err);
|
|
13332
|
-
}
|
|
13333
|
-
if (options.stale <= 0) {
|
|
13334
|
-
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file: file2 }));
|
|
13335
|
-
}
|
|
13336
|
-
options.fs.stat(lockfilePath, (err2, stat) => {
|
|
13337
|
-
if (err2) {
|
|
13338
|
-
if (err2.code === "ENOENT") {
|
|
13339
|
-
return acquireLock(file2, { ...options, stale: 0 }, callback);
|
|
13340
|
-
}
|
|
13341
|
-
return callback(err2);
|
|
13342
|
-
}
|
|
13343
|
-
if (!isLockStale(stat, options)) {
|
|
13344
|
-
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file: file2 }));
|
|
13345
|
-
}
|
|
13346
|
-
removeLock(file2, options, (err3) => {
|
|
13347
|
-
if (err3) {
|
|
13348
|
-
return callback(err3);
|
|
13349
|
-
}
|
|
13350
|
-
acquireLock(file2, { ...options, stale: 0 }, callback);
|
|
13351
|
-
});
|
|
13352
|
-
});
|
|
13353
|
-
});
|
|
13354
|
-
}
|
|
13355
|
-
function isLockStale(stat, options) {
|
|
13356
|
-
return stat.mtime.getTime() < Date.now() - options.stale;
|
|
13357
|
-
}
|
|
13358
|
-
function removeLock(file2, options, callback) {
|
|
13359
|
-
options.fs.rmdir(getLockFile(file2, options), (err) => {
|
|
13360
|
-
if (err && err.code !== "ENOENT") {
|
|
13361
|
-
return callback(err);
|
|
13362
|
-
}
|
|
13363
|
-
callback();
|
|
13364
|
-
});
|
|
13365
|
-
}
|
|
13366
|
-
function updateLock(file2, options) {
|
|
13367
|
-
const lock2 = locks[file2];
|
|
13368
|
-
if (lock2.updateTimeout) {
|
|
13369
|
-
return;
|
|
13370
|
-
}
|
|
13371
|
-
lock2.updateDelay = lock2.updateDelay || options.update;
|
|
13372
|
-
lock2.updateTimeout = setTimeout(() => {
|
|
13373
|
-
lock2.updateTimeout = null;
|
|
13374
|
-
options.fs.stat(lock2.lockfilePath, (err, stat) => {
|
|
13375
|
-
const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
|
|
13376
|
-
if (err) {
|
|
13377
|
-
if (err.code === "ENOENT" || isOverThreshold) {
|
|
13378
|
-
return setLockAsCompromised(file2, lock2, Object.assign(err, { code: "ECOMPROMISED" }));
|
|
13379
|
-
}
|
|
13380
|
-
lock2.updateDelay = 1e3;
|
|
13381
|
-
return updateLock(file2, options);
|
|
13382
|
-
}
|
|
13383
|
-
const isMtimeOurs = lock2.mtime.getTime() === stat.mtime.getTime();
|
|
13384
|
-
if (!isMtimeOurs) {
|
|
13385
|
-
return setLockAsCompromised(
|
|
13386
|
-
file2,
|
|
13387
|
-
lock2,
|
|
13388
|
-
Object.assign(
|
|
13389
|
-
new Error("Unable to update lock within the stale threshold"),
|
|
13390
|
-
{ code: "ECOMPROMISED" }
|
|
13391
|
-
)
|
|
13392
|
-
);
|
|
13393
|
-
}
|
|
13394
|
-
const mtime = mtimePrecision.getMtime(lock2.mtimePrecision);
|
|
13395
|
-
options.fs.utimes(lock2.lockfilePath, mtime, mtime, (err2) => {
|
|
13396
|
-
const isOverThreshold2 = lock2.lastUpdate + options.stale < Date.now();
|
|
13397
|
-
if (lock2.released) {
|
|
13398
|
-
return;
|
|
13399
|
-
}
|
|
13400
|
-
if (err2) {
|
|
13401
|
-
if (err2.code === "ENOENT" || isOverThreshold2) {
|
|
13402
|
-
return setLockAsCompromised(file2, lock2, Object.assign(err2, { code: "ECOMPROMISED" }));
|
|
13403
|
-
}
|
|
13404
|
-
lock2.updateDelay = 1e3;
|
|
13405
|
-
return updateLock(file2, options);
|
|
13406
|
-
}
|
|
13407
|
-
lock2.mtime = mtime;
|
|
13408
|
-
lock2.lastUpdate = Date.now();
|
|
13409
|
-
lock2.updateDelay = null;
|
|
13410
|
-
updateLock(file2, options);
|
|
13411
|
-
});
|
|
13412
|
-
});
|
|
13413
|
-
}, lock2.updateDelay);
|
|
13414
|
-
if (lock2.updateTimeout.unref) {
|
|
13415
|
-
lock2.updateTimeout.unref();
|
|
13416
|
-
}
|
|
13417
|
-
}
|
|
13418
|
-
function setLockAsCompromised(file2, lock2, err) {
|
|
13419
|
-
lock2.released = true;
|
|
13420
|
-
if (lock2.updateTimeout) {
|
|
13421
|
-
clearTimeout(lock2.updateTimeout);
|
|
13422
|
-
}
|
|
13423
|
-
if (locks[file2] === lock2) {
|
|
13424
|
-
delete locks[file2];
|
|
13425
|
-
}
|
|
13426
|
-
lock2.options.onCompromised(err);
|
|
13427
|
-
}
|
|
13428
|
-
function lock(file2, options, callback) {
|
|
13429
|
-
options = {
|
|
13430
|
-
stale: 1e4,
|
|
13431
|
-
update: null,
|
|
13432
|
-
realpath: true,
|
|
13433
|
-
retries: 0,
|
|
13434
|
-
fs: fs2,
|
|
13435
|
-
onCompromised: (err) => {
|
|
13436
|
-
throw err;
|
|
13437
|
-
},
|
|
13438
|
-
...options
|
|
13439
|
-
};
|
|
13440
|
-
options.retries = options.retries || 0;
|
|
13441
|
-
options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
|
|
13442
|
-
options.stale = Math.max(options.stale || 0, 2e3);
|
|
13443
|
-
options.update = options.update == null ? options.stale / 2 : options.update || 0;
|
|
13444
|
-
options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3);
|
|
13445
|
-
resolveCanonicalPath(file2, options, (err, file3) => {
|
|
13446
|
-
if (err) {
|
|
13447
|
-
return callback(err);
|
|
13448
|
-
}
|
|
13449
|
-
const operation = retry.operation(options.retries);
|
|
13450
|
-
operation.attempt(() => {
|
|
13451
|
-
acquireLock(file3, options, (err2, mtime, mtimePrecision2) => {
|
|
13452
|
-
if (operation.retry(err2)) {
|
|
13453
|
-
return;
|
|
13454
|
-
}
|
|
13455
|
-
if (err2) {
|
|
13456
|
-
return callback(operation.mainError());
|
|
13457
|
-
}
|
|
13458
|
-
const lock2 = locks[file3] = {
|
|
13459
|
-
lockfilePath: getLockFile(file3, options),
|
|
13460
|
-
mtime,
|
|
13461
|
-
mtimePrecision: mtimePrecision2,
|
|
13462
|
-
options,
|
|
13463
|
-
lastUpdate: Date.now()
|
|
13464
|
-
};
|
|
13465
|
-
updateLock(file3, options);
|
|
13466
|
-
callback(null, (releasedCallback) => {
|
|
13467
|
-
if (lock2.released) {
|
|
13468
|
-
return releasedCallback && releasedCallback(Object.assign(new Error("Lock is already released"), { code: "ERELEASED" }));
|
|
13469
|
-
}
|
|
13470
|
-
unlock(file3, { ...options, realpath: false }, releasedCallback);
|
|
13471
|
-
});
|
|
13472
|
-
});
|
|
13473
|
-
});
|
|
13474
|
-
});
|
|
13475
|
-
}
|
|
13476
|
-
function unlock(file2, options, callback) {
|
|
13477
|
-
options = {
|
|
13478
|
-
fs: fs2,
|
|
13479
|
-
realpath: true,
|
|
13480
|
-
...options
|
|
13481
|
-
};
|
|
13482
|
-
resolveCanonicalPath(file2, options, (err, file3) => {
|
|
13483
|
-
if (err) {
|
|
13484
|
-
return callback(err);
|
|
13485
|
-
}
|
|
13486
|
-
const lock2 = locks[file3];
|
|
13487
|
-
if (!lock2) {
|
|
13488
|
-
return callback(Object.assign(new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
|
|
13489
|
-
}
|
|
13490
|
-
lock2.updateTimeout && clearTimeout(lock2.updateTimeout);
|
|
13491
|
-
lock2.released = true;
|
|
13492
|
-
delete locks[file3];
|
|
13493
|
-
removeLock(file3, options, callback);
|
|
13494
|
-
});
|
|
13495
|
-
}
|
|
13496
|
-
function check(file2, options, callback) {
|
|
13497
|
-
options = {
|
|
13498
|
-
stale: 1e4,
|
|
13499
|
-
realpath: true,
|
|
13500
|
-
fs: fs2,
|
|
13501
|
-
...options
|
|
13502
|
-
};
|
|
13503
|
-
options.stale = Math.max(options.stale || 0, 2e3);
|
|
13504
|
-
resolveCanonicalPath(file2, options, (err, file3) => {
|
|
13505
|
-
if (err) {
|
|
13506
|
-
return callback(err);
|
|
13507
|
-
}
|
|
13508
|
-
options.fs.stat(getLockFile(file3, options), (err2, stat) => {
|
|
13509
|
-
if (err2) {
|
|
13510
|
-
return err2.code === "ENOENT" ? callback(null, false) : callback(err2);
|
|
13511
|
-
}
|
|
13512
|
-
return callback(null, !isLockStale(stat, options));
|
|
13513
|
-
});
|
|
13514
|
-
});
|
|
13515
|
-
}
|
|
13516
|
-
function getLocks() {
|
|
13517
|
-
return locks;
|
|
13518
|
-
}
|
|
13519
|
-
onExit(() => {
|
|
13520
|
-
for (const file2 in locks) {
|
|
13521
|
-
const options = locks[file2].options;
|
|
13522
|
-
try {
|
|
13523
|
-
options.fs.rmdirSync(getLockFile(file2, options));
|
|
13524
|
-
} catch (e) {
|
|
13525
|
-
}
|
|
13526
|
-
}
|
|
13527
|
-
});
|
|
13528
|
-
module.exports.lock = lock;
|
|
13529
|
-
module.exports.unlock = unlock;
|
|
13530
|
-
module.exports.check = check;
|
|
13531
|
-
module.exports.getLocks = getLocks;
|
|
13532
|
-
}
|
|
13533
|
-
});
|
|
13534
|
-
|
|
13535
|
-
// node_modules/proper-lockfile/lib/adapter.js
|
|
13536
|
-
var require_adapter = __commonJS({
|
|
13537
|
-
"node_modules/proper-lockfile/lib/adapter.js"(exports, module) {
|
|
13538
|
-
"use strict";
|
|
13539
|
-
var fs2 = require_graceful_fs();
|
|
13540
|
-
function createSyncFs(fs3) {
|
|
13541
|
-
const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
|
|
13542
|
-
const newFs = { ...fs3 };
|
|
13543
|
-
methods.forEach((method) => {
|
|
13544
|
-
newFs[method] = (...args) => {
|
|
13545
|
-
const callback = args.pop();
|
|
13546
|
-
let ret;
|
|
13547
|
-
try {
|
|
13548
|
-
ret = fs3[`${method}Sync`](...args);
|
|
13549
|
-
} catch (err) {
|
|
13550
|
-
return callback(err);
|
|
13551
|
-
}
|
|
13552
|
-
callback(null, ret);
|
|
13553
|
-
};
|
|
13554
|
-
});
|
|
13555
|
-
return newFs;
|
|
13556
|
-
}
|
|
13557
|
-
function toPromise(method) {
|
|
13558
|
-
return (...args) => new Promise((resolve9, reject) => {
|
|
13559
|
-
args.push((err, result) => {
|
|
13560
|
-
if (err) {
|
|
13561
|
-
reject(err);
|
|
13562
|
-
} else {
|
|
13563
|
-
resolve9(result);
|
|
13564
|
-
}
|
|
13565
|
-
});
|
|
13566
|
-
method(...args);
|
|
13567
|
-
});
|
|
13568
|
-
}
|
|
13569
|
-
function toSync(method) {
|
|
13570
|
-
return (...args) => {
|
|
13571
|
-
let err;
|
|
13572
|
-
let result;
|
|
13573
|
-
args.push((_err, _result) => {
|
|
13574
|
-
err = _err;
|
|
13575
|
-
result = _result;
|
|
13576
|
-
});
|
|
13577
|
-
method(...args);
|
|
13578
|
-
if (err) {
|
|
13579
|
-
throw err;
|
|
13580
|
-
}
|
|
13581
|
-
return result;
|
|
13582
|
-
};
|
|
13583
|
-
}
|
|
13584
|
-
function toSyncOptions(options) {
|
|
13585
|
-
options = { ...options };
|
|
13586
|
-
options.fs = createSyncFs(options.fs || fs2);
|
|
13587
|
-
if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
|
|
13588
|
-
throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
|
|
13589
|
-
}
|
|
13590
|
-
return options;
|
|
13591
|
-
}
|
|
13592
|
-
module.exports = {
|
|
13593
|
-
toPromise,
|
|
13594
|
-
toSync,
|
|
13595
|
-
toSyncOptions
|
|
13596
|
-
};
|
|
13597
|
-
}
|
|
13598
|
-
});
|
|
13599
|
-
|
|
13600
|
-
// node_modules/proper-lockfile/index.js
|
|
13601
|
-
var require_proper_lockfile = __commonJS({
|
|
13602
|
-
"node_modules/proper-lockfile/index.js"(exports, module) {
|
|
13603
|
-
"use strict";
|
|
13604
|
-
var lockfile = require_lockfile();
|
|
13605
|
-
var { toPromise, toSync, toSyncOptions } = require_adapter();
|
|
13606
|
-
async function lock(file2, options) {
|
|
13607
|
-
const release = await toPromise(lockfile.lock)(file2, options);
|
|
13608
|
-
return toPromise(release);
|
|
13609
|
-
}
|
|
13610
|
-
function lockSync2(file2, options) {
|
|
13611
|
-
const release = toSync(lockfile.lock)(file2, toSyncOptions(options));
|
|
13612
|
-
return toSync(release);
|
|
13613
|
-
}
|
|
13614
|
-
function unlock(file2, options) {
|
|
13615
|
-
return toPromise(lockfile.unlock)(file2, options);
|
|
13616
|
-
}
|
|
13617
|
-
function unlockSync(file2, options) {
|
|
13618
|
-
return toSync(lockfile.unlock)(file2, toSyncOptions(options));
|
|
13619
|
-
}
|
|
13620
|
-
function check(file2, options) {
|
|
13621
|
-
return toPromise(lockfile.check)(file2, options);
|
|
13622
|
-
}
|
|
13623
|
-
function checkSync(file2, options) {
|
|
13624
|
-
return toSync(lockfile.check)(file2, toSyncOptions(options));
|
|
13625
|
-
}
|
|
13626
|
-
module.exports = lock;
|
|
13627
|
-
module.exports.lock = lock;
|
|
13628
|
-
module.exports.unlock = unlock;
|
|
13629
|
-
module.exports.lockSync = lockSync2;
|
|
13630
|
-
module.exports.unlockSync = unlockSync;
|
|
13631
|
-
module.exports.check = check;
|
|
13632
|
-
module.exports.checkSync = checkSync;
|
|
13633
|
-
}
|
|
13634
|
-
});
|
|
13635
|
-
|
|
13636
12062
|
// extension/config.ts
|
|
13637
12063
|
import {
|
|
13638
12064
|
closeSync as closeSync8,
|
|
@@ -13648,6 +12074,7 @@ import {
|
|
|
13648
12074
|
} from "node:fs";
|
|
13649
12075
|
import { randomUUID as randomUUID9 } from "node:crypto";
|
|
13650
12076
|
import { basename as basename7, dirname as dirname8, join as join8 } from "node:path";
|
|
12077
|
+
import { lockSync } from "proper-lockfile";
|
|
13651
12078
|
function validManagerMergeSetting(value2) {
|
|
13652
12079
|
return typeof value2 === "boolean" || value2 === "divergent";
|
|
13653
12080
|
}
|
|
@@ -13721,11 +12148,25 @@ function parseRawConfig(content) {
|
|
|
13721
12148
|
throw new Error("Invalid Pi Herdsman config field contextRetirement");
|
|
13722
12149
|
result.contextRetirement = record.contextRetirement;
|
|
13723
12150
|
}
|
|
12151
|
+
for (const key of [
|
|
12152
|
+
"peerCommunicationEnabled",
|
|
12153
|
+
"peerFederationEnabled"
|
|
12154
|
+
])
|
|
12155
|
+
if (key in record) {
|
|
12156
|
+
if (typeof record[key] !== "boolean")
|
|
12157
|
+
throw new Error(`Invalid Pi Herdsman config field ${key}`);
|
|
12158
|
+
result[key] = record[key];
|
|
12159
|
+
}
|
|
13724
12160
|
if ("autoActivateManager" in record) {
|
|
13725
12161
|
if (typeof record.autoActivateManager !== "boolean")
|
|
13726
12162
|
throw new Error("Invalid Pi Herdsman config field autoActivateManager");
|
|
13727
12163
|
result.autoActivateManager = record.autoActivateManager;
|
|
13728
12164
|
}
|
|
12165
|
+
if ("allowAgentCwdOverride" in record) {
|
|
12166
|
+
if (typeof record.allowAgentCwdOverride !== "boolean")
|
|
12167
|
+
throw new Error("Invalid Pi Herdsman config field allowAgentCwdOverride");
|
|
12168
|
+
result.allowAgentCwdOverride = record.allowAgentCwdOverride;
|
|
12169
|
+
}
|
|
13729
12170
|
if ("managerGitBootstrapWithoutConfirmation" in record) {
|
|
13730
12171
|
if (typeof record.managerGitBootstrapWithoutConfirmation !== "boolean")
|
|
13731
12172
|
throw new Error(
|
|
@@ -13762,6 +12203,13 @@ function parseRawConfig(content) {
|
|
|
13762
12203
|
}
|
|
13763
12204
|
return result;
|
|
13764
12205
|
}
|
|
12206
|
+
function readPeerPolicy() {
|
|
12207
|
+
const { peerCommunicationEnabled, peerFederationEnabled } = readConfig();
|
|
12208
|
+
return {
|
|
12209
|
+
local: peerCommunicationEnabled,
|
|
12210
|
+
remote: peerCommunicationEnabled && peerFederationEnabled
|
|
12211
|
+
};
|
|
12212
|
+
}
|
|
13765
12213
|
function isWorktreeRemovalPreapproved(repoKey) {
|
|
13766
12214
|
return !!repoKey && readConfig().worktreeRemovalPreapprovedRepos.includes(repoKey);
|
|
13767
12215
|
}
|
|
@@ -13904,7 +12352,7 @@ function assertRegularProjectSettings(path) {
|
|
|
13904
12352
|
function acquireProjectSettingsLock(path) {
|
|
13905
12353
|
for (let attempt = 0; ; attempt++) {
|
|
13906
12354
|
try {
|
|
13907
|
-
return
|
|
12355
|
+
return lockSync(path, { realpath: false });
|
|
13908
12356
|
} catch (error2) {
|
|
13909
12357
|
if (error2.code !== "ELOCKED" || attempt === 9)
|
|
13910
12358
|
throw error2;
|
|
@@ -14037,8 +12485,14 @@ function updateConfig(key, value2, expectedManagerMergeEnabled) {
|
|
|
14037
12485
|
);
|
|
14038
12486
|
if (key === "contextRetirement" && typeof value2 !== "boolean")
|
|
14039
12487
|
throw new Error("Invalid Pi Herdsman config field contextRetirement");
|
|
12488
|
+
if ((key === "peerCommunicationEnabled" || key === "peerFederationEnabled") && typeof value2 !== "boolean")
|
|
12489
|
+
throw new Error(`Invalid Pi Herdsman config field ${key}`);
|
|
14040
12490
|
if (key === "autoActivateManager" && typeof value2 !== "boolean")
|
|
14041
12491
|
throw new Error("Invalid Pi Herdsman config field autoActivateManager");
|
|
12492
|
+
if (key === "allowAgentCwdOverride" && typeof value2 !== "boolean")
|
|
12493
|
+
throw new Error(
|
|
12494
|
+
"Invalid Pi Herdsman config field allowAgentCwdOverride"
|
|
12495
|
+
);
|
|
14042
12496
|
if (key === "managerGitBootstrapWithoutConfirmation" && typeof value2 !== "boolean")
|
|
14043
12497
|
throw new Error(
|
|
14044
12498
|
"Invalid Pi Herdsman config field managerGitBootstrapWithoutConfirmation"
|
|
@@ -14053,7 +12507,7 @@ function updateConfig(key, value2, expectedManagerMergeEnabled) {
|
|
|
14053
12507
|
throw new Error(
|
|
14054
12508
|
"Invalid Pi Herdsman config field worktreeRemovalPreapprovedRepos"
|
|
14055
12509
|
);
|
|
14056
|
-
if (key !== "spawnPlacement" && key !== "statusWidgetMaxRows" && key !== "maxAgentDepth" && key !== "defaultLeadExecution" && key !== "contextRetirement" && key !== "autoActivateManager" && key !== "managerGitBootstrapWithoutConfirmation" && key !== "managerMergeEnabled" && key !== "managerMergeOverrides" && key !== "worktreeRemovalPreapprovedRepos" && !validByteLimit(value2))
|
|
12510
|
+
if (key !== "spawnPlacement" && key !== "statusWidgetMaxRows" && key !== "maxAgentDepth" && key !== "defaultLeadExecution" && key !== "contextRetirement" && key !== "autoActivateManager" && key !== "allowAgentCwdOverride" && key !== "peerCommunicationEnabled" && key !== "peerFederationEnabled" && key !== "managerGitBootstrapWithoutConfirmation" && key !== "managerMergeEnabled" && key !== "managerMergeOverrides" && key !== "worktreeRemovalPreapprovedRepos" && !validByteLimit(value2))
|
|
14057
12511
|
throw new Error(`Invalid Pi Herdsman config field ${key}`);
|
|
14058
12512
|
current[key] = value2;
|
|
14059
12513
|
} else delete current[key];
|
|
@@ -14071,11 +12525,10 @@ function updateConfig(key, value2, expectedManagerMergeEnabled) {
|
|
|
14071
12525
|
release();
|
|
14072
12526
|
}
|
|
14073
12527
|
}
|
|
14074
|
-
var
|
|
12528
|
+
var DEFAULT_BYTE_LIMIT, MIN_BYTE_LIMIT, MAX_BYTE_LIMIT, DEFAULT_STATUS_WIDGET_MAX_ROWS, DEFAULT_MAX_AGENT_DEPTH, DEFAULT_CONFIG, CONFIG_KEYS;
|
|
14075
12529
|
var init_config = __esm({
|
|
14076
12530
|
"extension/config.ts"() {
|
|
14077
12531
|
"use strict";
|
|
14078
|
-
import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
14079
12532
|
init_lock();
|
|
14080
12533
|
init_storage();
|
|
14081
12534
|
init_core();
|
|
@@ -14090,7 +12543,10 @@ var init_config = __esm({
|
|
|
14090
12543
|
spawnPlacement: "subtree",
|
|
14091
12544
|
defaultLeadExecution: "flexible",
|
|
14092
12545
|
contextRetirement: true,
|
|
12546
|
+
peerCommunicationEnabled: true,
|
|
12547
|
+
peerFederationEnabled: true,
|
|
14093
12548
|
autoActivateManager: false,
|
|
12549
|
+
allowAgentCwdOverride: false,
|
|
14094
12550
|
managerGitBootstrapWithoutConfirmation: false,
|
|
14095
12551
|
inlineAttachmentLimitBytes: DEFAULT_BYTE_LIMIT,
|
|
14096
12552
|
mailboxPayloadLimitBytes: DEFAULT_BYTE_LIMIT,
|
|
@@ -14104,7 +12560,10 @@ var init_config = __esm({
|
|
|
14104
12560
|
"spawnPlacement",
|
|
14105
12561
|
"defaultLeadExecution",
|
|
14106
12562
|
"contextRetirement",
|
|
12563
|
+
"peerCommunicationEnabled",
|
|
12564
|
+
"peerFederationEnabled",
|
|
14107
12565
|
"autoActivateManager",
|
|
12566
|
+
"allowAgentCwdOverride",
|
|
14108
12567
|
"managerGitBootstrapWithoutConfirmation",
|
|
14109
12568
|
"inlineAttachmentLimitBytes",
|
|
14110
12569
|
"mailboxPayloadLimitBytes",
|
|
@@ -14124,12 +12583,18 @@ import {
|
|
|
14124
12583
|
truncateTail as truncateTail2
|
|
14125
12584
|
} from "@earendil-works/pi-coding-agent";
|
|
14126
12585
|
import { contentText as contentText2 } from "@earendil-works/pi-ai";
|
|
14127
|
-
import {
|
|
12586
|
+
import {
|
|
12587
|
+
accessSync,
|
|
12588
|
+
constants as constants4,
|
|
12589
|
+
readdirSync as readdirSync6,
|
|
12590
|
+
realpathSync as realpathSync4,
|
|
12591
|
+
statSync as statSync6
|
|
12592
|
+
} from "node:fs";
|
|
14128
12593
|
import { unlinkSync as unlinkSync8 } from "node:fs";
|
|
14129
12594
|
import { createHash as createHash10, randomUUID as randomUUID10 } from "node:crypto";
|
|
14130
12595
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
14131
12596
|
import { homedir as homedir4 } from "node:os";
|
|
14132
|
-
import { basename as basename8, join as join9, resolve as resolve5 } from "node:path";
|
|
12597
|
+
import { basename as basename8, isAbsolute as isAbsolute5, join as join9, relative as relative3, resolve as resolve5, sep as sep3 } from "node:path";
|
|
14133
12598
|
import { setTimeout as delay } from "node:timers/promises";
|
|
14134
12599
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
14135
12600
|
import { Type } from "typebox";
|
|
@@ -16157,7 +14622,7 @@ function durableAgentDepth(states, agent) {
|
|
|
16157
14622
|
}
|
|
16158
14623
|
}
|
|
16159
14624
|
function sameRootDelegationGeneration(a, b) {
|
|
16160
|
-
return !!b && a.sessionId === b.sessionId && a.roleGeneration === b.roleGeneration && a.role === b.role && a.authority === b.authority && a.profile === b.profile;
|
|
14625
|
+
return !!b && a.sessionId === b.sessionId && a.roleGeneration === b.roleGeneration && a.role === b.role && a.sessionKind === b.sessionKind && a.authority === b.authority && a.profile === b.profile;
|
|
16161
14626
|
}
|
|
16162
14627
|
function permitsRootDelegation(policy, definition) {
|
|
16163
14628
|
return policy === "all" || policy.has(definition);
|
|
@@ -16329,14 +14794,76 @@ function validateIdentity(runtime, state, agent, options = {}) {
|
|
|
16329
14794
|
"identity"
|
|
16330
14795
|
);
|
|
16331
14796
|
}
|
|
16332
|
-
function
|
|
16333
|
-
|
|
14797
|
+
function readDelegationProjectAssignments() {
|
|
14798
|
+
try {
|
|
14799
|
+
return globalProjectAssignmentSnapshot();
|
|
14800
|
+
} catch {
|
|
14801
|
+
fail(
|
|
14802
|
+
"invalid_request",
|
|
14803
|
+
"Unable to verify local Manager checkout assignments; retry delegation",
|
|
14804
|
+
"delegate"
|
|
14805
|
+
);
|
|
14806
|
+
}
|
|
14807
|
+
}
|
|
14808
|
+
function cwdIsWithin(checkout, cwd) {
|
|
14809
|
+
const rel = relative3(checkout, cwd);
|
|
14810
|
+
return rel !== ".." && !rel.startsWith(`..${sep3}`) && !isAbsolute5(rel);
|
|
14811
|
+
}
|
|
14812
|
+
function legacyAssignmentCheckout(assignment) {
|
|
14813
|
+
if (!assignment.piSessionFile || !isAbsolute5(assignment.piSessionFile))
|
|
14814
|
+
return void 0;
|
|
14815
|
+
try {
|
|
14816
|
+
if (!statSync6(assignment.piSessionFile).isFile()) return void 0;
|
|
14817
|
+
const saved = readPiSessionHeaderIdentity(assignment.piSessionFile);
|
|
14818
|
+
if (saved?.id === assignment.id && saved.cwd && isAbsolute5(saved.cwd))
|
|
14819
|
+
return realpathSync4.native(saved.cwd);
|
|
14820
|
+
} catch {
|
|
14821
|
+
}
|
|
14822
|
+
return void 0;
|
|
14823
|
+
}
|
|
14824
|
+
function resolveDelegationCwd(value2, controllerCwd) {
|
|
14825
|
+
if (typeof value2 !== "string" || !value2.trim() || [...value2].some((character) => {
|
|
14826
|
+
const code = character.charCodeAt(0);
|
|
14827
|
+
return code < 32 || code >= 127 && code <= 159;
|
|
14828
|
+
}))
|
|
14829
|
+
fail(
|
|
14830
|
+
"invalid_request",
|
|
14831
|
+
"cwd must be a non-empty path without control characters",
|
|
14832
|
+
"delegate"
|
|
14833
|
+
);
|
|
14834
|
+
try {
|
|
14835
|
+
const cwd = realpathSync4.native(resolve5(controllerCwd, value2));
|
|
14836
|
+
const stat = statSync6(cwd, { bigint: true });
|
|
14837
|
+
if (!stat.isDirectory() || stat.ino === 0n)
|
|
14838
|
+
throw new Error("Directory identity unavailable");
|
|
14839
|
+
accessSync(cwd, constants4.R_OK | constants4.X_OK);
|
|
14840
|
+
return { cwd, dev: stat.dev, ino: stat.ino };
|
|
14841
|
+
} catch {
|
|
14842
|
+
fail(
|
|
14843
|
+
"invalid_request",
|
|
14844
|
+
"cwd must resolve to a readable directory",
|
|
14845
|
+
"delegate"
|
|
14846
|
+
);
|
|
14847
|
+
}
|
|
14848
|
+
}
|
|
14849
|
+
function validateAssignmentCwd(definition, agentCwd, controllerCwd, scope, operation, verifiedCrossDirectory) {
|
|
14850
|
+
const privateSource = operation === "delegate" && definition.privateRepositorySource;
|
|
14851
|
+
if (!definition.projectSource && !privateSource && scope.kind === "root")
|
|
14852
|
+
return;
|
|
14853
|
+
if (!(verifiedCrossDirectory ?? !sameCwd(agentCwd, controllerCwd))) return;
|
|
14854
|
+
if (definition.projectSource)
|
|
16334
14855
|
fail(
|
|
16335
14856
|
"invalid_request",
|
|
16336
14857
|
`Project agent ${definition.name} belongs to ${resolve5(controllerCwd)}`,
|
|
16337
14858
|
operation
|
|
16338
14859
|
);
|
|
16339
|
-
if (
|
|
14860
|
+
if (privateSource)
|
|
14861
|
+
fail(
|
|
14862
|
+
"invalid_request",
|
|
14863
|
+
`Agent ${definition.name} uses private-repository definition configuration`,
|
|
14864
|
+
operation
|
|
14865
|
+
);
|
|
14866
|
+
if (scope.kind === "managed-agent")
|
|
16340
14867
|
fail(
|
|
16341
14868
|
"invalid_request",
|
|
16342
14869
|
`Delegated agents must use the delegating agent cwd ${resolve5(controllerCwd)}`,
|
|
@@ -19348,6 +17875,13 @@ ${ownerMessage.text}`;
|
|
|
19348
17875
|
"retain is available only to managed Agents",
|
|
19349
17876
|
p.action
|
|
19350
17877
|
);
|
|
17878
|
+
const explicitCwd = p.action === "delegate" && Object.hasOwn(p, "cwd");
|
|
17879
|
+
if (explicitCwd && (scope?.kind !== "root" || !readConfig().allowAgentCwdOverride))
|
|
17880
|
+
fail(
|
|
17881
|
+
"invalid_request",
|
|
17882
|
+
"Working directory override is unavailable",
|
|
17883
|
+
"delegate"
|
|
17884
|
+
);
|
|
19351
17885
|
const rootAssignment = (p.action === "delegate" || p.action === "continue") && scope?.kind === "root";
|
|
19352
17886
|
if (rootAssignment && (!options.rootDelegationPolicy || !options.rootDelegationGeneration))
|
|
19353
17887
|
fail(
|
|
@@ -19421,13 +17955,23 @@ ${ownerMessage.text}`;
|
|
|
19421
17955
|
"The requested Agent continuation could not be resolved",
|
|
19422
17956
|
"continue"
|
|
19423
17957
|
);
|
|
17958
|
+
const controllerCwd = ctx.cwd;
|
|
17959
|
+
const requestedCwd = p.action === "delegate" ? p.cwd : void 0;
|
|
17960
|
+
const verifiedCwd = explicitCwd ? resolveDelegationCwd(requestedCwd, controllerCwd) : void 0;
|
|
17961
|
+
const crossDirectory = verifiedCwd !== void 0 && !sameCwd(verifiedCwd.cwd, controllerCwd);
|
|
17962
|
+
if (crossDirectory && (initiatingRootGeneration?.role !== "lead" || initiatingRootGeneration.sessionKind !== "ordinary"))
|
|
17963
|
+
fail(
|
|
17964
|
+
"invalid_request",
|
|
17965
|
+
"Cross-directory delegation requires an ordinary Lead",
|
|
17966
|
+
"delegate"
|
|
17967
|
+
);
|
|
19424
17968
|
await herdrVersion(pi, ctx, signal);
|
|
19425
17969
|
const agentDefinition = p.action === "continue" ? (resumed ?? fail(
|
|
19426
17970
|
"target_not_found",
|
|
19427
17971
|
"The requested Agent continuation could not be resolved",
|
|
19428
17972
|
"continue"
|
|
19429
17973
|
)).definition : p.definition;
|
|
19430
|
-
const agentCwd = resumed
|
|
17974
|
+
const agentCwd = resumed?.cwd ?? verifiedCwd?.cwd ?? ctx.cwd;
|
|
19431
17975
|
const requestedLabel = resumed?.label ?? (p.action === "delegate" ? p.label : void 0);
|
|
19432
17976
|
const agentContext = await contextAgentDefinitions(ctx);
|
|
19433
17977
|
const definition = agentContext.definitions.find(
|
|
@@ -19474,7 +18018,14 @@ ${ownerMessage.text}`;
|
|
|
19474
18018
|
}
|
|
19475
18019
|
};
|
|
19476
18020
|
assertRootDelegationAllowed();
|
|
19477
|
-
validateAssignmentCwd(
|
|
18021
|
+
validateAssignmentCwd(
|
|
18022
|
+
definition,
|
|
18023
|
+
agentCwd,
|
|
18024
|
+
ctx.cwd,
|
|
18025
|
+
scope,
|
|
18026
|
+
p.action,
|
|
18027
|
+
verifiedCwd ? crossDirectory : void 0
|
|
18028
|
+
);
|
|
19478
18029
|
if (resumed && resumed.id === ctx.sessionManager.getSessionId())
|
|
19479
18030
|
fail(
|
|
19480
18031
|
"invalid_request",
|
|
@@ -20344,21 +18895,112 @@ This batch was not embedded. Use read_evidence to retrieve the items relevant to
|
|
|
20344
18895
|
sharedPromptPath: promptPaths[effectiveDefinition.body ? 1 : 0],
|
|
20345
18896
|
cwd: agentCwd,
|
|
20346
18897
|
managedAgent: true,
|
|
20347
|
-
approveProject: sameCwd(agentCwd, ctx.cwd) ? agentContext.projectTrusted : void 0,
|
|
18898
|
+
approveProject: verifiedCwd ? !crossDirectory && agentContext.projectTrusted : sameCwd(agentCwd, ctx.cwd) ? agentContext.projectTrusted : void 0,
|
|
20348
18899
|
...!resumed ? { inheritedThinking: pi.getThinkingLevel() } : {},
|
|
20349
18900
|
modelDecision: childModel
|
|
20350
18901
|
});
|
|
20351
18902
|
assertRootDelegationAllowed();
|
|
20352
|
-
|
|
18903
|
+
const launchConfig = readConfig();
|
|
18904
|
+
if (launchConfig.maxAgentDepth !== maxAgentDepth)
|
|
20353
18905
|
fail(
|
|
20354
18906
|
"invalid_request",
|
|
20355
|
-
`maxAgentDepth changed from ${maxAgentDepth} to ${
|
|
18907
|
+
`maxAgentDepth changed from ${maxAgentDepth} to ${launchConfig.maxAgentDepth} while this Agent was being prepared, so it was not started; retry the delegation under the new limit`,
|
|
20356
18908
|
p.action
|
|
20357
18909
|
);
|
|
18910
|
+
const checkLaunchAuthority = (launchCwd) => {
|
|
18911
|
+
const legacy = /* @__PURE__ */ new Map();
|
|
18912
|
+
if (!verifiedCwd) return legacy;
|
|
18913
|
+
assertRootDelegationAllowed();
|
|
18914
|
+
if (!readConfig().allowAgentCwdOverride)
|
|
18915
|
+
fail(
|
|
18916
|
+
"invalid_request",
|
|
18917
|
+
"Working directory override was disabled during preflight; retry delegation",
|
|
18918
|
+
"delegate"
|
|
18919
|
+
);
|
|
18920
|
+
const assignments = crossDirectory ? readDelegationProjectAssignments() : void 0;
|
|
18921
|
+
const current = resolveDelegationCwd(requestedCwd, ctx.cwd);
|
|
18922
|
+
const stillCrossDirectory = !sameCwd(current.cwd, ctx.cwd);
|
|
18923
|
+
if (launchCwd !== verifiedCwd.cwd || current.cwd !== verifiedCwd.cwd || current.dev !== verifiedCwd.dev || current.ino !== verifiedCwd.ino || stillCrossDirectory !== crossDirectory)
|
|
18924
|
+
fail(
|
|
18925
|
+
"invalid_request",
|
|
18926
|
+
"Working directory changed during preflight; retry delegation",
|
|
18927
|
+
"delegate"
|
|
18928
|
+
);
|
|
18929
|
+
for (const matches of assignments?.values() ?? []) {
|
|
18930
|
+
for (const { assignment: assignment2 } of matches) {
|
|
18931
|
+
if (assignment2.checkoutPath) {
|
|
18932
|
+
if (cwdIsWithin(assignment2.checkoutPath, current.cwd))
|
|
18933
|
+
rejectAssignedCheckout();
|
|
18934
|
+
continue;
|
|
18935
|
+
}
|
|
18936
|
+
const checkout = legacyAssignmentCheckout(assignment2);
|
|
18937
|
+
if (!checkout || !cwdIsWithin(checkout, current.cwd)) continue;
|
|
18938
|
+
const repositories = legacy.get(checkout) ?? /* @__PURE__ */ new Set();
|
|
18939
|
+
repositories.add(assignment2.repoKey);
|
|
18940
|
+
legacy.set(checkout, repositories);
|
|
18941
|
+
}
|
|
18942
|
+
}
|
|
18943
|
+
return legacy;
|
|
18944
|
+
};
|
|
18945
|
+
const rejectAssignedCheckout = () => fail(
|
|
18946
|
+
"invalid_request",
|
|
18947
|
+
"Working directory is inside a Manager-assigned checkout",
|
|
18948
|
+
"delegate"
|
|
18949
|
+
);
|
|
18950
|
+
const assertLaunchAuthorized = (launchCwd) => {
|
|
18951
|
+
const legacy = checkLaunchAuthority(launchCwd);
|
|
18952
|
+
if (!legacy.size) return;
|
|
18953
|
+
return (async () => {
|
|
18954
|
+
const observed = /* @__PURE__ */ new Map();
|
|
18955
|
+
for (const checkout of legacy.keys()) {
|
|
18956
|
+
const topology = await runHerdr(
|
|
18957
|
+
pi,
|
|
18958
|
+
ctx,
|
|
18959
|
+
["worktree", "list", "--cwd", checkout],
|
|
18960
|
+
{ signal, timeout: 1e4 }
|
|
18961
|
+
).catch(() => void 0);
|
|
18962
|
+
if (typeof topology?.source?.repo_key !== "string" || !Array.isArray(topology.worktrees))
|
|
18963
|
+
fail(
|
|
18964
|
+
"invalid_request",
|
|
18965
|
+
"Unable to verify the legacy Manager checkout; retry delegation",
|
|
18966
|
+
"delegate"
|
|
18967
|
+
);
|
|
18968
|
+
const placement2 = resolveAssignmentCheckout(
|
|
18969
|
+
{},
|
|
18970
|
+
topology.worktrees,
|
|
18971
|
+
checkout
|
|
18972
|
+
);
|
|
18973
|
+
if (placement2.status === "conflict")
|
|
18974
|
+
fail(
|
|
18975
|
+
"invalid_request",
|
|
18976
|
+
"Legacy Manager checkout placement is ambiguous; retry delegation",
|
|
18977
|
+
"delegate"
|
|
18978
|
+
);
|
|
18979
|
+
observed.set(
|
|
18980
|
+
checkout,
|
|
18981
|
+
placement2.status === "matched" ? topology.source.repo_key : void 0
|
|
18982
|
+
);
|
|
18983
|
+
}
|
|
18984
|
+
for (const [checkout, repositories] of checkLaunchAuthority(
|
|
18985
|
+
launchCwd
|
|
18986
|
+
)) {
|
|
18987
|
+
if (!observed.has(checkout))
|
|
18988
|
+
fail(
|
|
18989
|
+
"invalid_request",
|
|
18990
|
+
"Manager checkout assignments changed during preflight; retry delegation",
|
|
18991
|
+
"delegate"
|
|
18992
|
+
);
|
|
18993
|
+
const repo = observed.get(checkout);
|
|
18994
|
+
if (repo !== void 0 && repositories.has(repo))
|
|
18995
|
+
rejectAssignedCheckout();
|
|
18996
|
+
}
|
|
18997
|
+
})();
|
|
18998
|
+
};
|
|
20358
18999
|
started = await startHerdrAgent(pi, ctx, {
|
|
20359
19000
|
label,
|
|
20360
19001
|
runId,
|
|
20361
19002
|
cwd: agentCwd,
|
|
19003
|
+
...verifiedCwd ? { assertLaunchAuthorized } : {},
|
|
20362
19004
|
extensionPath: options.extensionPath,
|
|
20363
19005
|
placement,
|
|
20364
19006
|
...placementRevalidator ? { placementRevalidator } : {},
|
|
@@ -20758,6 +19400,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
20758
19400
|
action: p.action,
|
|
20759
19401
|
agent: label,
|
|
20760
19402
|
definition: agentDefinition,
|
|
19403
|
+
...p.action === "delegate" ? { cwd: runtime.cwd } : {},
|
|
20761
19404
|
owner_session_id: runtime.ownerSessionId,
|
|
20762
19405
|
pane_id: runtime.paneId,
|
|
20763
19406
|
session_id: runtime.piSessionId,
|
|
@@ -20991,6 +19634,7 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
20991
19634
|
});
|
|
20992
19635
|
}
|
|
20993
19636
|
const agentListParameters = emptyParameters;
|
|
19637
|
+
const exposeCwd = controllerScope.kind === "root" && readConfig().allowAgentCwdOverride;
|
|
20994
19638
|
const agentDelegateParameters = Type.Object(
|
|
20995
19639
|
{
|
|
20996
19640
|
definition: controllerScope.kind === "managed-agent" ? {
|
|
@@ -21011,6 +19655,14 @@ ${result.stderr ?? ""}`.trim(),
|
|
|
21011
19655
|
})
|
|
21012
19656
|
),
|
|
21013
19657
|
files: FILES_SCHEMA,
|
|
19658
|
+
...exposeCwd ? {
|
|
19659
|
+
cwd: Type.Optional(
|
|
19660
|
+
Type.String({
|
|
19661
|
+
minLength: 1,
|
|
19662
|
+
description: "Optional execution directory for this fresh Agent. Relative paths resolve against the controller cwd. Only ordinary Leads can select a different directory."
|
|
19663
|
+
})
|
|
19664
|
+
)
|
|
19665
|
+
} : {},
|
|
21014
19666
|
...controllerScope.kind === "managed-agent" ? {
|
|
21015
19667
|
retain: Type.Optional(
|
|
21016
19668
|
Type.Boolean({
|
|
@@ -22675,7 +21327,7 @@ __export(managed_agent_runtime_exports, {
|
|
|
22675
21327
|
sessionContextRetired: () => sessionContextRetired,
|
|
22676
21328
|
validateManagedAgentIdentity: () => validateManagedAgentIdentity
|
|
22677
21329
|
});
|
|
22678
|
-
import { isAbsolute as
|
|
21330
|
+
import { isAbsolute as isAbsolute6, join as join10, resolve as resolve6 } from "node:path";
|
|
22679
21331
|
import { existsSync as existsSync2, realpathSync as realpathSync5 } from "node:fs";
|
|
22680
21332
|
import { buildSessionProjection as buildSessionProjection2 } from "@earendil-works/pi-coding-agent";
|
|
22681
21333
|
import { contentText as contentText3 } from "@earendil-works/pi-ai";
|
|
@@ -25288,7 +23940,7 @@ function allowedAgentDefinitionsFromEnv() {
|
|
|
25288
23940
|
function managedAgentEnvironmentError() {
|
|
25289
23941
|
const e = process.env;
|
|
25290
23942
|
if (!e.PI_HERDSMAN_MAILBOX) return "PI_HERDSMAN_MAILBOX missing";
|
|
25291
|
-
if (!
|
|
23943
|
+
if (!isAbsolute6(e.PI_HERDSMAN_MAILBOX))
|
|
25292
23944
|
return "PI_HERDSMAN_MAILBOX is not absolute";
|
|
25293
23945
|
if (!validId(e.PI_HERDSMAN_RUN_ID)) return "PI_HERDSMAN_RUN_ID invalid";
|
|
25294
23946
|
if (!validId(e.PI_HERDSMAN_OWNER_SESSION_ID))
|
|
@@ -25893,7 +24545,7 @@ import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
|
25893
24545
|
// package.json
|
|
25894
24546
|
var package_default = {
|
|
25895
24547
|
name: "pi-herdsman",
|
|
25896
|
-
version: "0.
|
|
24548
|
+
version: "0.52.0",
|
|
25897
24549
|
type: "module",
|
|
25898
24550
|
description: "Asynchronous Pi subagents and agent fleet orchestration for parallel coding agents with nested delegation, background work, and supervision in herdr.",
|
|
25899
24551
|
license: "Apache-2.0",
|
|
@@ -25935,7 +24587,6 @@ var package_default = {
|
|
|
25935
24587
|
"./dist/index.js"
|
|
25936
24588
|
],
|
|
25937
24589
|
skills: [
|
|
25938
|
-
"./SKILL.md",
|
|
25939
24590
|
"./skills"
|
|
25940
24591
|
],
|
|
25941
24592
|
image: "https://raw.githubusercontent.com/boadij/pi-herdsman/main/docs/assets/thumbnail.webp"
|
|
@@ -25995,7 +24646,6 @@ var package_default = {
|
|
|
25995
24646
|
files: [
|
|
25996
24647
|
"README.md",
|
|
25997
24648
|
"CHANGELOG.md",
|
|
25998
|
-
"SKILL.md",
|
|
25999
24649
|
"LICENSE",
|
|
26000
24650
|
"docs",
|
|
26001
24651
|
"dist",
|
|
@@ -26170,7 +24820,7 @@ init_agent_controller();
|
|
|
26170
24820
|
init_agent_definitions();
|
|
26171
24821
|
import { randomUUID as randomUUID12 } from "node:crypto";
|
|
26172
24822
|
import { realpathSync as realpathSync6, statSync as statSync7, unlinkSync as unlinkSync9 } from "node:fs";
|
|
26173
|
-
import { isAbsolute as
|
|
24823
|
+
import { isAbsolute as isAbsolute7, resolve as resolve7 } from "node:path";
|
|
26174
24824
|
function isFreshLeadStartupAttestation(state, sessionId, previousInstanceId, startedAt) {
|
|
26175
24825
|
return !!state && state.piSessionId === sessionId && state.instanceId !== previousInstanceId && state.updatedAt >= startedAt && state.startupAttestation?.kind === "model_restore" && state.startupAttestation.assignmentId === sessionId && state.startupAttestation.generation === state.instanceId && ["verified", "definition_override", "no_saved_model"].includes(
|
|
26176
24826
|
state.startupAttestation.result
|
|
@@ -26528,7 +25178,7 @@ function createLeadProjectRuntime(host) {
|
|
|
26528
25178
|
`Assigned checkout is not verified (${placement.reason}); worktree preserved`
|
|
26529
25179
|
);
|
|
26530
25180
|
const worktree = placement.worktree;
|
|
26531
|
-
if (typeof worktree.path !== "string" || !worktree.path || !
|
|
25181
|
+
if (typeof worktree.path !== "string" || !worktree.path || !isAbsolute7(worktree.path) || worktree.is_linked_worktree !== true)
|
|
26532
25182
|
throw new Error("Herdr worktree checkout path is unavailable");
|
|
26533
25183
|
const checkoutPath = resolve7(worktree.path);
|
|
26534
25184
|
if (sameDirectory(checkoutPath, topology.source.source_checkout_path))
|
|
@@ -26596,7 +25246,7 @@ function createLeadProjectRuntime(host) {
|
|
|
26596
25246
|
);
|
|
26597
25247
|
const metadataOutput = String(metadata.stdout ?? "");
|
|
26598
25248
|
const modulesPath = metadataOutput.endsWith("\r\n") ? metadataOutput.slice(0, -2) : metadataOutput.endsWith("\n") ? metadataOutput.slice(0, -1) : metadataOutput;
|
|
26599
|
-
if (metadata.code !== 0 || metadata.killed || metadata.stderr?.trim() || !modulesPath || /[\r\n]/u.test(modulesPath) || !
|
|
25249
|
+
if (metadata.code !== 0 || metadata.killed || metadata.stderr?.trim() || !modulesPath || /[\r\n]/u.test(modulesPath) || !isAbsolute7(modulesPath))
|
|
26600
25250
|
throw new Error(
|
|
26601
25251
|
"Git submodule metadata could not be verified; worktree preserved"
|
|
26602
25252
|
);
|
|
@@ -29051,11 +27701,11 @@ Type forget ${branch} to confirm.`,
|
|
|
29051
27701
|
timeout: 1e4
|
|
29052
27702
|
})
|
|
29053
27703
|
]);
|
|
29054
|
-
if (common.code !== 0 || common.killed || common.stderr?.trim() || branchResult.code !== 0 || branchResult.killed || branchResult.stderr?.trim() || !
|
|
27704
|
+
if (common.code !== 0 || common.killed || common.stderr?.trim() || branchResult.code !== 0 || branchResult.killed || branchResult.stderr?.trim() || !isAbsolute7(String(common.stdout ?? "").trim()) || !sameDirectory(String(common.stdout).trim(), manager.repoKey) || String(branchResult.stdout ?? "").trim() !== assignment.branch)
|
|
29055
27705
|
throw new Error(
|
|
29056
27706
|
"Herdr checkout does not match the assigned repository and branch"
|
|
29057
27707
|
);
|
|
29058
|
-
if (!
|
|
27708
|
+
if (!isAbsolute7(cwd) || workspaceId === primaryWorkspaceId || !sameDirectory(
|
|
29059
27709
|
topology.source.source_checkout_path,
|
|
29060
27710
|
localScope.checkoutPath
|
|
29061
27711
|
) || sameDirectory(cwd, topology.source.source_checkout_path) || matchingWorktrees.length === 1 && !sameDirectory(cwd, matchingWorktrees[0].path))
|
|
@@ -30481,7 +29131,7 @@ function parseGitWorktreeInventory(output) {
|
|
|
30481
29131
|
else if (/^prunable(?: .*)?$/.test(value2)) prunable = true;
|
|
30482
29132
|
else if (!/^[^\s]+(?: .*)?$/.test(value2)) return void 0;
|
|
30483
29133
|
}
|
|
30484
|
-
if (!path || !
|
|
29134
|
+
if (!path || !isAbsolute7(path) || (bare ? !!branch || detached : !head || !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(head) || !branch && !detached) || branch !== void 0 && !branch)
|
|
30485
29135
|
return void 0;
|
|
30486
29136
|
worktrees.push({
|
|
30487
29137
|
path,
|
|
@@ -30498,7 +29148,7 @@ function parseGitWorktreeInventory(output) {
|
|
|
30498
29148
|
}
|
|
30499
29149
|
async function captureSenderEnvironment(pi, ctx) {
|
|
30500
29150
|
const cwd = ctx.cwd;
|
|
30501
|
-
if (typeof cwd !== "string" || !
|
|
29151
|
+
if (typeof cwd !== "string" || !isAbsolute7(cwd) || !cwd || Buffer.byteLength(cwd) > 1024)
|
|
30502
29152
|
return void 0;
|
|
30503
29153
|
try {
|
|
30504
29154
|
const rootResult = await pi.exec("git", ["rev-parse", "--show-toplevel"], {
|
|
@@ -30507,7 +29157,7 @@ async function captureSenderEnvironment(pi, ctx) {
|
|
|
30507
29157
|
timeout: 3e3
|
|
30508
29158
|
});
|
|
30509
29159
|
const root2 = String(rootResult.stdout ?? "").trim();
|
|
30510
|
-
if (rootResult.code !== 0 || rootResult.killed || rootResult.stderr?.trim() || !
|
|
29160
|
+
if (rootResult.code !== 0 || rootResult.killed || rootResult.stderr?.trim() || !isAbsolute7(root2) || Buffer.byteLength(root2) > 1024)
|
|
30511
29161
|
return { cwd };
|
|
30512
29162
|
const inventoryResult = await pi.exec(
|
|
30513
29163
|
"git",
|
|
@@ -30543,6 +29193,18 @@ import { basename as basename9 } from "node:path";
|
|
|
30543
29193
|
import {
|
|
30544
29194
|
getSupportedThinkingLevels
|
|
30545
29195
|
} from "@earendil-works/pi-ai";
|
|
29196
|
+
var layoutLabels = {
|
|
29197
|
+
tab: "Shared tab",
|
|
29198
|
+
subtree: "Separate tabs",
|
|
29199
|
+
split: "Split panes"
|
|
29200
|
+
};
|
|
29201
|
+
var leadModeLabels = {
|
|
29202
|
+
flexible: "Flexible",
|
|
29203
|
+
orchestrate: "Orchestrate"
|
|
29204
|
+
};
|
|
29205
|
+
var sizeLabel = (bytes) => bytes % 1024 === 0 ? `${bytes / 1024} KiB` : `${bytes} B`;
|
|
29206
|
+
var countLabel = (count, unit) => `${count} ${unit}${count === 1 ? "" : "s"}`;
|
|
29207
|
+
var mergeDescription = (policy) => `${!policy.enabled ? "Off" : policy.allowDivergence ? "Conflict-free" : "Fast-forward"} \xB7 ${policy.source === "repository" ? "Repository" : "Global"}`;
|
|
30546
29208
|
function createLeadCommandRuntime(host) {
|
|
30547
29209
|
const confirmMergeGrant = (ctx, setting, scope) => ctx.ui.confirm(
|
|
30548
29210
|
`Allow Manager integration for ${scope}?`,
|
|
@@ -30561,27 +29223,30 @@ function createLeadCommandRuntime(host) {
|
|
|
30561
29223
|
const current = await host.placementSettings(ctx);
|
|
30562
29224
|
const selected = await host.selectMenu(
|
|
30563
29225
|
ctx,
|
|
30564
|
-
"
|
|
30565
|
-
|
|
30566
|
-
|
|
30567
|
-
|
|
30568
|
-
|
|
30569
|
-
|
|
30570
|
-
|
|
30571
|
-
|
|
30572
|
-
|
|
30573
|
-
|
|
30574
|
-
|
|
30575
|
-
|
|
30576
|
-
|
|
30577
|
-
|
|
30578
|
-
|
|
30579
|
-
|
|
30580
|
-
|
|
30581
|
-
|
|
30582
|
-
|
|
30583
|
-
|
|
30584
|
-
|
|
29226
|
+
"Agent terminal layout",
|
|
29227
|
+
markCurrent(
|
|
29228
|
+
[
|
|
29229
|
+
{
|
|
29230
|
+
value: "tab",
|
|
29231
|
+
label: "Shared Agents tab",
|
|
29232
|
+
help: "Directly delegated Agents from this controller share one tab."
|
|
29233
|
+
},
|
|
29234
|
+
{
|
|
29235
|
+
value: "subtree",
|
|
29236
|
+
label: layoutLabels.subtree,
|
|
29237
|
+
help: "Each directly delegated Agent gets its own tab."
|
|
29238
|
+
},
|
|
29239
|
+
{
|
|
29240
|
+
value: "split",
|
|
29241
|
+
label: layoutLabels.split,
|
|
29242
|
+
help: "Open directly delegated Agents in split panes beside the caller's pane."
|
|
29243
|
+
}
|
|
29244
|
+
].map((item) => ({
|
|
29245
|
+
...item,
|
|
29246
|
+
help: `${item.help} Nested Agents still split within their owner's tab.`
|
|
29247
|
+
})),
|
|
29248
|
+
current.effective
|
|
29249
|
+
),
|
|
30585
29250
|
current.effective
|
|
30586
29251
|
);
|
|
30587
29252
|
if (!selected || selected === current.effective) return;
|
|
@@ -30591,60 +29256,62 @@ function createLeadCommandRuntime(host) {
|
|
|
30591
29256
|
throw new Error(
|
|
30592
29257
|
`Agent placement did not become effective: ${verified.effective}`
|
|
30593
29258
|
);
|
|
30594
|
-
ctx.ui.notify(
|
|
29259
|
+
ctx.ui.notify(
|
|
29260
|
+
`Agent terminal layout: ${layoutLabels[verified.effective]}`
|
|
29261
|
+
);
|
|
30595
29262
|
},
|
|
30596
29263
|
async openMessageLimitsMenu(ctx) {
|
|
30597
29264
|
let selectedLimit = "inlineAttachmentLimitBytes";
|
|
30598
|
-
const
|
|
30599
|
-
|
|
30600
|
-
|
|
30601
|
-
}
|
|
29265
|
+
const labels = {
|
|
29266
|
+
inlineAttachmentLimitBytes: "Shared file content",
|
|
29267
|
+
mailboxPayloadLimitBytes: "Coordination messages"
|
|
29268
|
+
};
|
|
30602
29269
|
while (true) {
|
|
30603
29270
|
const limits = await host.messageLimits(ctx);
|
|
30604
29271
|
const setting = await host.selectMenu(
|
|
30605
29272
|
ctx,
|
|
30606
|
-
"Message limits",
|
|
29273
|
+
"Message and file limits",
|
|
30607
29274
|
[
|
|
30608
29275
|
{
|
|
30609
29276
|
value: "inlineAttachmentLimitBytes",
|
|
30610
|
-
label:
|
|
29277
|
+
label: labels.inlineAttachmentLimitBytes,
|
|
30611
29278
|
description: host.formatMessageLimit(limits.inline.bytes),
|
|
30612
|
-
help: "
|
|
29279
|
+
help: "Maximum size of complete text content included from a single attached file. Whether larger files can be referenced depends on the handoff."
|
|
30613
29280
|
},
|
|
30614
29281
|
{
|
|
30615
29282
|
value: "mailboxPayloadLimitBytes",
|
|
30616
|
-
label:
|
|
29283
|
+
label: labels.mailboxPayloadLimitBytes,
|
|
30617
29284
|
description: host.formatMessageLimit(limits.mailbox.bytes),
|
|
30618
|
-
help: "
|
|
29285
|
+
help: "Maximum payload size for managed Agent requests and other supported coordination messages, including Manager assignments."
|
|
30619
29286
|
}
|
|
30620
29287
|
],
|
|
30621
29288
|
selectedLimit
|
|
30622
29289
|
);
|
|
30623
|
-
if (
|
|
29290
|
+
if (setting !== "inlineAttachmentLimitBytes" && setting !== "mailboxPayloadLimitBytes")
|
|
29291
|
+
return;
|
|
30624
29292
|
selectedLimit = setting;
|
|
30625
29293
|
const currentBytes = setting === "inlineAttachmentLimitBytes" ? limits.inline.bytes : limits.mailbox.bytes;
|
|
30626
|
-
const
|
|
30627
|
-
|
|
30628
|
-
) ? String(currentBytes) : "custom";
|
|
29294
|
+
const defaultBytes = DEFAULT_CONFIG[setting];
|
|
29295
|
+
const presets = [1, 4, 16, 64, 128].map((kib) => kib * 1024).filter((bytes) => bytes !== defaultBytes);
|
|
29296
|
+
const currentChoice = currentBytes === defaultBytes ? "default" : presets.includes(currentBytes) ? String(currentBytes) : "custom";
|
|
30629
29297
|
const choice = await host.selectMenu(
|
|
30630
29298
|
ctx,
|
|
30631
|
-
|
|
29299
|
+
labels[setting],
|
|
30632
29300
|
markCurrent(
|
|
30633
29301
|
[
|
|
30634
|
-
|
|
29302
|
+
{
|
|
29303
|
+
value: "default",
|
|
29304
|
+
label: `Use default (${host.formatMessageLimit(defaultBytes)})`
|
|
29305
|
+
},
|
|
29306
|
+
...presets.map((bytes) => ({
|
|
30635
29307
|
value: String(bytes),
|
|
30636
|
-
label
|
|
29308
|
+
label: host.formatMessageLimit(bytes)
|
|
30637
29309
|
})),
|
|
30638
29310
|
{
|
|
30639
29311
|
value: "custom",
|
|
30640
29312
|
label: "Custom\u2026",
|
|
30641
29313
|
description: currentChoice === "custom" ? host.formatMessageLimit(currentBytes) : void 0,
|
|
30642
29314
|
help: "Enter a custom limit in KiB, from 1 through 1024."
|
|
30643
|
-
},
|
|
30644
|
-
{
|
|
30645
|
-
value: "reset",
|
|
30646
|
-
label: "Reset",
|
|
30647
|
-
help: "Remove the configured override and use the default."
|
|
30648
29315
|
}
|
|
30649
29316
|
],
|
|
30650
29317
|
currentChoice
|
|
@@ -30653,7 +29320,7 @@ function createLeadCommandRuntime(host) {
|
|
|
30653
29320
|
);
|
|
30654
29321
|
if (!choice) continue;
|
|
30655
29322
|
let value2;
|
|
30656
|
-
if (choice === "
|
|
29323
|
+
if (choice === "default") value2 = void 0;
|
|
30657
29324
|
else if (choice === "custom") {
|
|
30658
29325
|
const input = await host.input(ctx, "Custom limit in KiB (1\u20131024)");
|
|
30659
29326
|
if (input === void 0) continue;
|
|
@@ -30665,10 +29332,17 @@ function createLeadCommandRuntime(host) {
|
|
|
30665
29332
|
value2 = kib * 1024;
|
|
30666
29333
|
} else value2 = Number(choice);
|
|
30667
29334
|
if (value2 !== void 0 && value2 === currentBytes) continue;
|
|
30668
|
-
|
|
30669
|
-
|
|
30670
|
-
|
|
30671
|
-
|
|
29335
|
+
try {
|
|
29336
|
+
host.updateMessageLimit(setting, value2);
|
|
29337
|
+
ctx.ui.notify(
|
|
29338
|
+
`${labels[setting]}: ${value2 === void 0 ? "default restored" : host.formatMessageLimit(value2)}`
|
|
29339
|
+
);
|
|
29340
|
+
} catch (error2) {
|
|
29341
|
+
ctx.ui.notify(
|
|
29342
|
+
`Could not update ${labels[setting]}: ${String(error2)}`,
|
|
29343
|
+
"error"
|
|
29344
|
+
);
|
|
29345
|
+
}
|
|
30672
29346
|
}
|
|
30673
29347
|
},
|
|
30674
29348
|
executionSettings(ctx, definition) {
|
|
@@ -31436,7 +30110,9 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31436
30110
|
[
|
|
31437
30111
|
{ value: "sessions", label: "Sessions & agents" },
|
|
31438
30112
|
{ value: "manager", label: "Manager & repositories" },
|
|
31439
|
-
{ value: "interface", label: "Interface" }
|
|
30113
|
+
{ value: "interface", label: "Interface" },
|
|
30114
|
+
{ value: "delegation", label: "Delegation options" },
|
|
30115
|
+
{ value: "communication", label: "Communication" }
|
|
31440
30116
|
],
|
|
31441
30117
|
selectedCategory
|
|
31442
30118
|
);
|
|
@@ -31446,7 +30122,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31446
30122
|
}
|
|
31447
30123
|
},
|
|
31448
30124
|
async openSettingsCategory(ctx, category) {
|
|
31449
|
-
let selectedSetting = category === "sessions" ? "default-lead-execution" : category === "manager" ? "auto-activate-manager" : "agent-layout";
|
|
30125
|
+
let selectedSetting = category === "sessions" ? "default-lead-execution" : category === "manager" ? "auto-activate-manager" : category === "delegation" ? "max-agent-depth" : category === "communication" ? "peer-communication" : "agent-layout";
|
|
31450
30126
|
const loadProjectState = () => {
|
|
31451
30127
|
if (!ctx.isProjectTrusted())
|
|
31452
30128
|
return { trusted: false, overrides: {} };
|
|
@@ -31478,97 +30154,185 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31478
30154
|
if (category === "sessions") {
|
|
31479
30155
|
try {
|
|
31480
30156
|
const limits = await host.messageLimits(ctx);
|
|
31481
|
-
messageSummary = `
|
|
30157
|
+
messageSummary = `Files ${sizeLabel(limits.inline.bytes)} \xB7 Messages ${sizeLabel(limits.mailbox.bytes)}`;
|
|
31482
30158
|
} catch {
|
|
31483
30159
|
messageSummary = "Unavailable";
|
|
31484
30160
|
}
|
|
31485
30161
|
}
|
|
31486
|
-
const projectDescription = (key) =>
|
|
30162
|
+
const projectDescription = (key) => {
|
|
30163
|
+
if ("error" in project) return "Project unavailable";
|
|
30164
|
+
const overridden = project.trusted && Object.hasOwn(project.overrides, key);
|
|
30165
|
+
const enabled = overridden ? project.overrides[key] : config[key];
|
|
30166
|
+
return `${enabled ? "On" : "Off"} \xB7 ${overridden ? "Project" : "Global"}`;
|
|
30167
|
+
};
|
|
31487
30168
|
const selected = await host.selectMenu(
|
|
31488
30169
|
ctx,
|
|
31489
|
-
category === "sessions" ? "Sessions & agents" : category === "manager" ? "Manager & repositories" : "Interface",
|
|
30170
|
+
category === "sessions" ? "Sessions & agents" : category === "manager" ? "Manager & repositories" : category === "delegation" ? "Delegation options" : category === "communication" ? "Communication" : "Interface",
|
|
31490
30171
|
[
|
|
31491
30172
|
{
|
|
31492
30173
|
value: "agent-layout",
|
|
31493
|
-
|
|
31494
|
-
|
|
30174
|
+
category: "interface",
|
|
30175
|
+
label: "Agent terminal layout",
|
|
30176
|
+
description: category === "interface" ? layoutLabels[(await host.placementSettings(ctx)).effective] : void 0,
|
|
30177
|
+
help: "Choose how directly delegated Agents appear in the terminal. Nested Agents still split within their owner's tab."
|
|
31495
30178
|
},
|
|
31496
30179
|
{
|
|
31497
30180
|
value: "default-lead-execution",
|
|
30181
|
+
category: "sessions",
|
|
31498
30182
|
label: "Default Lead mode",
|
|
31499
|
-
description: config.defaultLeadExecution,
|
|
31500
|
-
help: "
|
|
30183
|
+
description: leadModeLabels[config.defaultLeadExecution],
|
|
30184
|
+
help: "Mode used for new ordinary Lead sessions without a saved choice. Existing sessions keep their mode."
|
|
31501
30185
|
},
|
|
31502
30186
|
{
|
|
31503
30187
|
value: "auto-activate-manager",
|
|
31504
|
-
|
|
31505
|
-
|
|
31506
|
-
|
|
30188
|
+
category: "manager",
|
|
30189
|
+
label: "Start Manager automatically",
|
|
30190
|
+
description: projectDescription("autoActivateManager"),
|
|
30191
|
+
help: "Try to start Manager when a new eligible session opens in a primary workspace. Does not change the current session or initialize Git."
|
|
31507
30192
|
},
|
|
31508
30193
|
{
|
|
31509
30194
|
value: "manager-git-bootstrap-confirmation",
|
|
31510
|
-
|
|
30195
|
+
category: "manager",
|
|
30196
|
+
label: "Confirm Git initialization",
|
|
31511
30197
|
description: config.managerGitBootstrapWithoutConfirmation ? "Skipped" : "Required",
|
|
31512
|
-
help: "
|
|
30198
|
+
help: "Ask before initializing Git when Manager is started explicitly in a directory without a Git repository."
|
|
31513
30199
|
},
|
|
31514
30200
|
{
|
|
31515
30201
|
value: "context-retirement",
|
|
31516
|
-
|
|
31517
|
-
|
|
31518
|
-
|
|
30202
|
+
category: "sessions",
|
|
30203
|
+
label: "Finish Agents near context limit",
|
|
30204
|
+
description: projectDescription("contextRetirement"),
|
|
30205
|
+
help: "Ask managed Agents to finish their assignments as context fills up, instead of compacting their sessions. Follow-up work needs a new Agent."
|
|
31519
30206
|
},
|
|
31520
30207
|
{
|
|
31521
30208
|
value: "manager-merge",
|
|
31522
|
-
|
|
31523
|
-
|
|
31524
|
-
|
|
30209
|
+
category: "manager",
|
|
30210
|
+
label: "Merge accepted branches",
|
|
30211
|
+
description: merge ? mergeDescription(merge) : "Repository unavailable",
|
|
30212
|
+
help: "Control whether Manager can merge accepted local branches, using fast-forward only or conflict-free divergent merges."
|
|
31525
30213
|
},
|
|
31526
30214
|
{
|
|
31527
30215
|
value: "status-widget-rows",
|
|
31528
|
-
|
|
31529
|
-
|
|
31530
|
-
|
|
30216
|
+
category: "interface",
|
|
30217
|
+
label: "Status widget lines",
|
|
30218
|
+
description: countLabel(config.statusWidgetMaxRows, "line"),
|
|
30219
|
+
help: "Maximum number of lines in the compact status display, including its header and overflow line."
|
|
31531
30220
|
},
|
|
31532
30221
|
{
|
|
31533
30222
|
value: "max-agent-depth",
|
|
31534
|
-
|
|
31535
|
-
|
|
31536
|
-
|
|
30223
|
+
category: "delegation",
|
|
30224
|
+
label: "Agent nesting limit",
|
|
30225
|
+
description: countLabel(config.maxAgentDepth, "level"),
|
|
30226
|
+
help: "Maximum Agent levels below a Lead, Manager or Chief. 1 = no nested Agents; 2 = one nested level."
|
|
31537
30227
|
},
|
|
31538
30228
|
{
|
|
31539
30229
|
value: "message-limits",
|
|
31540
|
-
|
|
30230
|
+
category: "sessions",
|
|
30231
|
+
label: "Message and file limits",
|
|
31541
30232
|
description: messageSummary,
|
|
31542
|
-
help: "
|
|
30233
|
+
help: "Set the maximum size of shared file contents and coordination messages."
|
|
30234
|
+
},
|
|
30235
|
+
{
|
|
30236
|
+
value: "cwd-override",
|
|
30237
|
+
category: "delegation",
|
|
30238
|
+
label: "Delegate Agents to other directories (cwd)",
|
|
30239
|
+
description: config.allowAgentCwdOverride ? "On" : "Off",
|
|
30240
|
+
help: "Allow ordinary Leads to select another directory using `cwd` in `delegate_agent`. Without it, Agents use the Lead's directory. Global setting; run `/reload` after changing it."
|
|
31543
30241
|
},
|
|
31544
30242
|
{
|
|
31545
30243
|
value: "removal-confirmation",
|
|
31546
|
-
|
|
31547
|
-
|
|
30244
|
+
category: "manager",
|
|
30245
|
+
label: "Confirm worktree removal",
|
|
30246
|
+
description: repository ? `${repository.enabled ? "Skipped" : "Required"} \xB7 Repository` : "Repository unavailable",
|
|
30247
|
+
help: "Require separate approval for explicit worktree removal. Other safety checks always apply."
|
|
30248
|
+
},
|
|
30249
|
+
{
|
|
30250
|
+
value: "peer-communication",
|
|
30251
|
+
category: "communication",
|
|
30252
|
+
label: "Peer communication",
|
|
30253
|
+
description: config.peerCommunicationEnabled ? "On" : "Off",
|
|
30254
|
+
help: "Allow horizontal peer communication. Does not affect supervision or Agent delegation."
|
|
30255
|
+
},
|
|
30256
|
+
{
|
|
30257
|
+
value: "peer-federation",
|
|
30258
|
+
category: "communication",
|
|
30259
|
+
label: "Peer federation",
|
|
30260
|
+
description: `${config.peerFederationEnabled ? "On" : "Off"}${config.peerCommunicationEnabled ? "" : " (inactive)"}`,
|
|
30261
|
+
help: "Allow communication with peers on other machines when peer communication is on."
|
|
31548
30262
|
}
|
|
31549
|
-
].filter(
|
|
31550
|
-
(item) => (category === "sessions" ? [
|
|
31551
|
-
"default-lead-execution",
|
|
31552
|
-
"context-retirement",
|
|
31553
|
-
"max-agent-depth",
|
|
31554
|
-
"message-limits"
|
|
31555
|
-
] : category === "manager" ? [
|
|
31556
|
-
"auto-activate-manager",
|
|
31557
|
-
"manager-git-bootstrap-confirmation",
|
|
31558
|
-
"manager-merge",
|
|
31559
|
-
"removal-confirmation"
|
|
31560
|
-
] : ["agent-layout", "status-widget-rows"]).includes(item.value)
|
|
31561
|
-
),
|
|
30263
|
+
].filter((item) => item.category === category).map(({ category: _category, ...item }) => item),
|
|
31562
30264
|
selectedSetting
|
|
31563
30265
|
);
|
|
31564
30266
|
if (!selected) return;
|
|
31565
30267
|
selectedSetting = selected;
|
|
31566
30268
|
if (selected === "agent-layout") {
|
|
31567
30269
|
await this.openPlacementMenu(ctx);
|
|
30270
|
+
} else if (selected === "cwd-override") {
|
|
30271
|
+
const current = config.allowAgentCwdOverride ? "on" : "off";
|
|
30272
|
+
const choice = await host.selectMenu(
|
|
30273
|
+
ctx,
|
|
30274
|
+
"Delegate Agents to other directories (cwd)",
|
|
30275
|
+
markCurrent(
|
|
30276
|
+
[
|
|
30277
|
+
{ value: "off", label: "Off" },
|
|
30278
|
+
{ value: "on", label: "On" }
|
|
30279
|
+
],
|
|
30280
|
+
current
|
|
30281
|
+
),
|
|
30282
|
+
current
|
|
30283
|
+
);
|
|
30284
|
+
if (choice !== "on" && choice !== "off" || choice === current || ctx.signal?.aborted)
|
|
30285
|
+
continue;
|
|
30286
|
+
try {
|
|
30287
|
+
host.updateConfig("allowAgentCwdOverride", choice === "on");
|
|
30288
|
+
ctx.ui.notify(
|
|
30289
|
+
`Delegate Agents to other directories (cwd): ${choice === "on" ? "On" : "Off"}. Run /reload after changing it.`
|
|
30290
|
+
);
|
|
30291
|
+
} catch (error2) {
|
|
30292
|
+
ctx.ui.notify(
|
|
30293
|
+
`Could not update \u201CDelegate Agents to other directories (cwd)\u201D: ${String(error2)}`,
|
|
30294
|
+
"error"
|
|
30295
|
+
);
|
|
30296
|
+
}
|
|
30297
|
+
} else if (selected === "peer-communication" || selected === "peer-federation") {
|
|
30298
|
+
const federation = selected === "peer-federation";
|
|
30299
|
+
const key = federation ? "peerFederationEnabled" : "peerCommunicationEnabled";
|
|
30300
|
+
const inactiveMessage = "Peer federation is inactive while peer communication is off. Its saved setting is unchanged.";
|
|
30301
|
+
try {
|
|
30302
|
+
const current = host.readConfig();
|
|
30303
|
+
if (federation && !current.peerCommunicationEnabled) {
|
|
30304
|
+
ctx.ui.notify(inactiveMessage, "info");
|
|
30305
|
+
continue;
|
|
30306
|
+
}
|
|
30307
|
+
const currentChoice = current[key] ? "on" : "off";
|
|
30308
|
+
const choice = await host.selectMenu(
|
|
30309
|
+
ctx,
|
|
30310
|
+
federation ? "Peer federation" : "Peer communication",
|
|
30311
|
+
markCurrent(
|
|
30312
|
+
[
|
|
30313
|
+
{ value: "on", label: "On" },
|
|
30314
|
+
{ value: "off", label: "Off" }
|
|
30315
|
+
],
|
|
30316
|
+
currentChoice
|
|
30317
|
+
),
|
|
30318
|
+
currentChoice
|
|
30319
|
+
);
|
|
30320
|
+
if (choice !== "on" && choice !== "off" || ctx.signal?.aborted)
|
|
30321
|
+
continue;
|
|
30322
|
+
const latest = host.readConfig();
|
|
30323
|
+
if (federation && !latest.peerCommunicationEnabled) {
|
|
30324
|
+
ctx.ui.notify(inactiveMessage, "info");
|
|
30325
|
+
continue;
|
|
30326
|
+
}
|
|
30327
|
+
const enabled = choice === "on";
|
|
30328
|
+
if (enabled !== latest[key]) host.updateConfig(key, enabled);
|
|
30329
|
+
} catch (error2) {
|
|
30330
|
+
ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
|
|
30331
|
+
}
|
|
31568
30332
|
} else if (selected === "manager-git-bootstrap-confirmation") {
|
|
31569
30333
|
const choice = await host.selectMenu(
|
|
31570
30334
|
ctx,
|
|
31571
|
-
"
|
|
30335
|
+
"Confirm Git initialization",
|
|
31572
30336
|
markCurrent(
|
|
31573
30337
|
[
|
|
31574
30338
|
{ value: "required", label: "Require confirmation" },
|
|
@@ -31593,29 +30357,31 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31593
30357
|
"managerGitBootstrapWithoutConfirmation",
|
|
31594
30358
|
choice === "skip"
|
|
31595
30359
|
);
|
|
30360
|
+
ctx.ui.notify(
|
|
30361
|
+
`Confirm Git initialization: ${choice === "skip" ? "Skipped" : "Required"}.`
|
|
30362
|
+
);
|
|
31596
30363
|
}
|
|
31597
30364
|
} else if (selected === "status-widget-rows") {
|
|
31598
30365
|
while (true) {
|
|
31599
30366
|
const currentChoice = config.statusWidgetMaxRows === DEFAULT_STATUS_WIDGET_MAX_ROWS ? "default" : [3, 5, 8, 12, 20].includes(config.statusWidgetMaxRows) ? String(config.statusWidgetMaxRows) : "custom";
|
|
31600
30367
|
const choice = await host.selectMenu(
|
|
31601
30368
|
ctx,
|
|
31602
|
-
"Status widget
|
|
30369
|
+
"Status widget lines",
|
|
31603
30370
|
markCurrent(
|
|
31604
30371
|
[
|
|
31605
30372
|
{
|
|
31606
30373
|
value: "default",
|
|
31607
|
-
label: `
|
|
30374
|
+
label: `Use default (${DEFAULT_STATUS_WIDGET_MAX_ROWS})`
|
|
31608
30375
|
},
|
|
31609
|
-
...[3, 5, 8, 12, 20].map((rows) => ({
|
|
30376
|
+
...[3, 5, 8, 12, 20].filter((rows) => rows !== DEFAULT_STATUS_WIDGET_MAX_ROWS).map((rows) => ({
|
|
31610
30377
|
value: String(rows),
|
|
31611
|
-
label:
|
|
30378
|
+
label: countLabel(rows, "line")
|
|
31612
30379
|
})),
|
|
31613
30380
|
{
|
|
31614
30381
|
value: "custom",
|
|
31615
30382
|
label: "Custom\u2026",
|
|
31616
|
-
description: currentChoice === "custom" ?
|
|
31617
|
-
}
|
|
31618
|
-
{ value: "reset", label: "Reset" }
|
|
30383
|
+
description: currentChoice === "custom" ? countLabel(config.statusWidgetMaxRows, "line") : void 0
|
|
30384
|
+
}
|
|
31619
30385
|
],
|
|
31620
30386
|
currentChoice
|
|
31621
30387
|
),
|
|
@@ -31623,11 +30389,11 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31623
30389
|
);
|
|
31624
30390
|
if (!choice) break;
|
|
31625
30391
|
let value2;
|
|
31626
|
-
if (choice === "
|
|
30392
|
+
if (choice === "default") value2 = void 0;
|
|
31627
30393
|
else if (choice === "custom") {
|
|
31628
30394
|
const input = await host.input(
|
|
31629
30395
|
ctx,
|
|
31630
|
-
"Custom status widget
|
|
30396
|
+
"Custom status widget lines (1\u2013100)"
|
|
31631
30397
|
);
|
|
31632
30398
|
if (input === void 0) continue;
|
|
31633
30399
|
value2 = Number(input.trim());
|
|
@@ -31635,19 +30401,18 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31635
30401
|
ctx.ui.notify("Enter an integer from 1 through 100", "error");
|
|
31636
30402
|
continue;
|
|
31637
30403
|
}
|
|
31638
|
-
} else
|
|
31639
|
-
value2 = choice === "default" ? DEFAULT_STATUS_WIDGET_MAX_ROWS : Number(choice);
|
|
30404
|
+
} else value2 = Number(choice);
|
|
31640
30405
|
if (value2 !== void 0 && value2 === config.statusWidgetMaxRows)
|
|
31641
30406
|
break;
|
|
31642
30407
|
try {
|
|
31643
30408
|
host.updateConfig("statusWidgetMaxRows", value2);
|
|
31644
30409
|
ctx.ui.notify(
|
|
31645
|
-
`Status widget
|
|
30410
|
+
`Status widget lines: ${value2 === void 0 ? "default restored" : countLabel(value2, "line")}`
|
|
31646
30411
|
);
|
|
31647
30412
|
break;
|
|
31648
30413
|
} catch (error2) {
|
|
31649
30414
|
ctx.ui.notify(
|
|
31650
|
-
`Could not update
|
|
30415
|
+
`Could not update Status widget lines: ${String(error2)}`,
|
|
31651
30416
|
"error"
|
|
31652
30417
|
);
|
|
31653
30418
|
}
|
|
@@ -31657,23 +30422,22 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31657
30422
|
const currentChoice = config.maxAgentDepth === DEFAULT_MAX_AGENT_DEPTH ? "default" : [1, 2, 3, 4, 5].includes(config.maxAgentDepth) ? String(config.maxAgentDepth) : "custom";
|
|
31658
30423
|
const choice = await host.selectMenu(
|
|
31659
30424
|
ctx,
|
|
31660
|
-
"
|
|
30425
|
+
"Agent nesting limit",
|
|
31661
30426
|
markCurrent(
|
|
31662
30427
|
[
|
|
31663
30428
|
{
|
|
31664
30429
|
value: "default",
|
|
31665
|
-
label: `
|
|
30430
|
+
label: `Use default (${DEFAULT_MAX_AGENT_DEPTH})`
|
|
31666
30431
|
},
|
|
31667
|
-
...[1, 2, 3, 4, 5].map((depth) => ({
|
|
30432
|
+
...[1, 2, 3, 4, 5].filter((depth) => depth !== DEFAULT_MAX_AGENT_DEPTH).map((depth) => ({
|
|
31668
30433
|
value: String(depth),
|
|
31669
|
-
label:
|
|
30434
|
+
label: countLabel(depth, "level")
|
|
31670
30435
|
})),
|
|
31671
30436
|
{
|
|
31672
30437
|
value: "custom",
|
|
31673
30438
|
label: "Custom\u2026",
|
|
31674
|
-
description: currentChoice === "custom" ?
|
|
31675
|
-
}
|
|
31676
|
-
{ value: "reset", label: "Reset" }
|
|
30439
|
+
description: currentChoice === "custom" ? countLabel(config.maxAgentDepth, "level") : void 0
|
|
30440
|
+
}
|
|
31677
30441
|
],
|
|
31678
30442
|
currentChoice
|
|
31679
30443
|
),
|
|
@@ -31681,11 +30445,11 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31681
30445
|
);
|
|
31682
30446
|
if (!choice) break;
|
|
31683
30447
|
let value2;
|
|
31684
|
-
if (choice === "
|
|
30448
|
+
if (choice === "default") value2 = void 0;
|
|
31685
30449
|
else if (choice === "custom") {
|
|
31686
30450
|
const input = await host.input(
|
|
31687
30451
|
ctx,
|
|
31688
|
-
"Custom
|
|
30452
|
+
"Custom Agent nesting limit (positive integer)"
|
|
31689
30453
|
);
|
|
31690
30454
|
if (input === void 0) continue;
|
|
31691
30455
|
value2 = Number(input.trim());
|
|
@@ -31693,18 +30457,17 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31693
30457
|
ctx.ui.notify("Enter a positive integer", "error");
|
|
31694
30458
|
continue;
|
|
31695
30459
|
}
|
|
31696
|
-
} else
|
|
31697
|
-
value2 = choice === "default" ? DEFAULT_MAX_AGENT_DEPTH : Number(choice);
|
|
30460
|
+
} else value2 = Number(choice);
|
|
31698
30461
|
if (value2 !== void 0 && value2 === config.maxAgentDepth) break;
|
|
31699
30462
|
try {
|
|
31700
30463
|
host.updateConfig("maxAgentDepth", value2);
|
|
31701
30464
|
ctx.ui.notify(
|
|
31702
|
-
`
|
|
30465
|
+
`Agent nesting limit: ${value2 === void 0 ? "default restored" : countLabel(value2, "level")}`
|
|
31703
30466
|
);
|
|
31704
30467
|
break;
|
|
31705
30468
|
} catch (error2) {
|
|
31706
30469
|
ctx.ui.notify(
|
|
31707
|
-
`Could not update
|
|
30470
|
+
`Could not update Agent nesting limit: ${String(error2)}`,
|
|
31708
30471
|
"error"
|
|
31709
30472
|
);
|
|
31710
30473
|
}
|
|
@@ -31714,19 +30477,27 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31714
30477
|
else if (selected === "default-lead-execution") {
|
|
31715
30478
|
const mode = await host.selectMenu(
|
|
31716
30479
|
ctx,
|
|
31717
|
-
"Default Lead
|
|
30480
|
+
"Default Lead mode",
|
|
31718
30481
|
markCurrent(
|
|
31719
30482
|
[
|
|
31720
|
-
{
|
|
31721
|
-
|
|
30483
|
+
{
|
|
30484
|
+
value: "flexible",
|
|
30485
|
+
label: leadModeLabels.flexible,
|
|
30486
|
+
help: "Work directly or delegate tasks when useful."
|
|
30487
|
+
},
|
|
30488
|
+
{
|
|
30489
|
+
value: "orchestrate",
|
|
30490
|
+
label: leadModeLabels.orchestrate,
|
|
30491
|
+
help: "Delegate execution work and focus on coordination and review."
|
|
30492
|
+
}
|
|
31722
30493
|
],
|
|
31723
30494
|
config.defaultLeadExecution
|
|
31724
30495
|
),
|
|
31725
30496
|
config.defaultLeadExecution
|
|
31726
30497
|
);
|
|
31727
|
-
if (mode && mode !== config.defaultLeadExecution) {
|
|
30498
|
+
if (mode && isLeadExecutionMode(mode) && mode !== config.defaultLeadExecution) {
|
|
31728
30499
|
host.updateConfig("defaultLeadExecution", mode);
|
|
31729
|
-
ctx.ui.notify(`Default Lead mode: ${mode}`);
|
|
30500
|
+
ctx.ui.notify(`Default Lead mode: ${leadModeLabels[mode]}`);
|
|
31730
30501
|
}
|
|
31731
30502
|
} else if (selected === "context-retirement" || selected === "auto-activate-manager") {
|
|
31732
30503
|
await this.openProjectSetting(
|
|
@@ -31741,10 +30512,10 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31741
30512
|
}
|
|
31742
30513
|
},
|
|
31743
30514
|
async openProjectSetting(ctx, key) {
|
|
31744
|
-
const title = key === "autoActivateManager" ? "Manager
|
|
30515
|
+
const title = key === "autoActivateManager" ? "Start Manager automatically" : "Finish Agents near context limit";
|
|
31745
30516
|
let selectedScope = "global";
|
|
31746
30517
|
while (true) {
|
|
31747
|
-
const
|
|
30518
|
+
const global = host.readConfig()[key];
|
|
31748
30519
|
let overrides;
|
|
31749
30520
|
let unavailable;
|
|
31750
30521
|
if (!ctx.isProjectTrusted()) unavailable = "Project is not trusted";
|
|
@@ -31762,12 +30533,12 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31762
30533
|
{
|
|
31763
30534
|
value: "global",
|
|
31764
30535
|
label: "Global default",
|
|
31765
|
-
description:
|
|
30536
|
+
description: global ? "On" : "Off"
|
|
31766
30537
|
},
|
|
31767
30538
|
{
|
|
31768
30539
|
value: "project",
|
|
31769
30540
|
label: "Current project",
|
|
31770
|
-
description: unavailable ?? (projectValue === void 0 ? `
|
|
30541
|
+
description: unavailable ?? (projectValue === void 0 ? `Use global setting (${global ? "On" : "Off"})` : projectValue ? "On" : "Off")
|
|
31771
30542
|
}
|
|
31772
30543
|
],
|
|
31773
30544
|
selectedScope
|
|
@@ -31778,16 +30549,16 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31778
30549
|
ctx.ui.notify(unavailable, "warning");
|
|
31779
30550
|
continue;
|
|
31780
30551
|
}
|
|
31781
|
-
const currentChoice = scope === "global" ?
|
|
30552
|
+
const currentChoice = scope === "global" ? global ? "on" : "off" : projectValue === void 0 ? "inherit" : projectValue ? "on" : "off";
|
|
31782
30553
|
const choice = await host.selectMenu(
|
|
31783
30554
|
ctx,
|
|
31784
|
-
scope === "global" ?
|
|
30555
|
+
`${scope === "global" ? "Global" : "Project"} \xB7 ${title}`,
|
|
31785
30556
|
markCurrent(
|
|
31786
30557
|
[
|
|
31787
30558
|
...scope === "project" ? [
|
|
31788
30559
|
{
|
|
31789
30560
|
value: "inherit",
|
|
31790
|
-
label: `
|
|
30561
|
+
label: `Use global setting (${global ? "On" : "Off"})`
|
|
31791
30562
|
}
|
|
31792
30563
|
] : [],
|
|
31793
30564
|
{ value: "on", label: "On" },
|
|
@@ -31801,14 +30572,14 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31801
30572
|
const value2 = choice === "inherit" ? void 0 : choice === "on";
|
|
31802
30573
|
try {
|
|
31803
30574
|
if (scope === "global") {
|
|
31804
|
-
if (value2 ===
|
|
30575
|
+
if (value2 === global || value2 === void 0) continue;
|
|
31805
30576
|
host.updateConfig(key, value2);
|
|
31806
30577
|
} else {
|
|
31807
30578
|
if (value2 === projectValue) continue;
|
|
31808
30579
|
host.updateProjectOverride(ctx, key, value2);
|
|
31809
30580
|
}
|
|
31810
30581
|
ctx.ui.notify(
|
|
31811
|
-
`${title}: ${value2 === void 0 ? "
|
|
30582
|
+
`${title}: ${value2 === void 0 ? "Uses global setting" : value2 ? "On" : "Off"} (${scope}).`
|
|
31812
30583
|
);
|
|
31813
30584
|
} catch (error2) {
|
|
31814
30585
|
ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
|
|
@@ -31819,7 +30590,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31819
30590
|
let selectedScope = "global";
|
|
31820
30591
|
while (true) {
|
|
31821
30592
|
const config = host.readConfig();
|
|
31822
|
-
const
|
|
30593
|
+
const global = config.managerMergeEnabled;
|
|
31823
30594
|
let policy;
|
|
31824
30595
|
let unavailable = "";
|
|
31825
30596
|
try {
|
|
@@ -31831,17 +30602,17 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31831
30602
|
const label = (value2) => value2 === false ? "Off" : value2 === true ? "Fast-forward" : "Conflict-free merges";
|
|
31832
30603
|
const scope = await host.selectMenu(
|
|
31833
30604
|
ctx,
|
|
31834
|
-
"
|
|
30605
|
+
"Merge accepted branches",
|
|
31835
30606
|
[
|
|
31836
30607
|
{
|
|
31837
30608
|
value: "global",
|
|
31838
30609
|
label: "Global default",
|
|
31839
|
-
description: label(
|
|
30610
|
+
description: label(global)
|
|
31840
30611
|
},
|
|
31841
30612
|
{
|
|
31842
30613
|
value: "repository",
|
|
31843
30614
|
label: "Current repository",
|
|
31844
|
-
description: repositoryPolicy ?
|
|
30615
|
+
description: repositoryPolicy ? mergeDescription(repositoryPolicy) : "Unavailable"
|
|
31845
30616
|
}
|
|
31846
30617
|
],
|
|
31847
30618
|
selectedScope
|
|
@@ -31857,12 +30628,12 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31857
30628
|
const currentChoice2 = override === void 0 ? "inherit" : override === false ? "off" : override === true ? "fast-forward" : "divergent";
|
|
31858
30629
|
const choice2 = await host.selectMenu(
|
|
31859
30630
|
ctx,
|
|
31860
|
-
`
|
|
30631
|
+
`Repository \xB7 Merge accepted branches \xB7 ${policy.repoKey}`,
|
|
31861
30632
|
markCurrent(
|
|
31862
30633
|
[
|
|
31863
30634
|
{
|
|
31864
30635
|
value: "inherit",
|
|
31865
|
-
label: `
|
|
30636
|
+
label: `Use global setting (${label(global)})`
|
|
31866
30637
|
},
|
|
31867
30638
|
{ value: "off", label: "Off" },
|
|
31868
30639
|
{ value: "fast-forward", label: "Fast-forward only" },
|
|
@@ -31880,11 +30651,11 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31880
30651
|
value2,
|
|
31881
30652
|
ctx,
|
|
31882
30653
|
policy.identity,
|
|
31883
|
-
{ global
|
|
30654
|
+
{ global, override }
|
|
31884
30655
|
);
|
|
31885
30656
|
if (stored)
|
|
31886
30657
|
ctx.ui.notify(
|
|
31887
|
-
`
|
|
30658
|
+
`Merge accepted branches: ${value2 === void 0 ? "Uses global setting" : label(value2)} (${policy.repoKey}).`
|
|
31888
30659
|
);
|
|
31889
30660
|
} catch (error2) {
|
|
31890
30661
|
ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
|
|
@@ -31895,7 +30666,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31895
30666
|
const currentChoice = current === false ? "off" : current === true ? "fast-forward" : "divergent";
|
|
31896
30667
|
const choice = await host.selectMenu(
|
|
31897
30668
|
ctx,
|
|
31898
|
-
"Global
|
|
30669
|
+
"Global \xB7 Merge accepted branches",
|
|
31899
30670
|
markCurrent(
|
|
31900
30671
|
[
|
|
31901
30672
|
{ value: "off", label: "Off" },
|
|
@@ -31927,9 +30698,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31927
30698
|
ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
|
|
31928
30699
|
continue;
|
|
31929
30700
|
}
|
|
31930
|
-
ctx.ui.notify(
|
|
31931
|
-
`Global Manager local merge: ${setting === "divergent" ? "conflict-free merges" : setting ? "fast-forward only" : "off"}`
|
|
31932
|
-
);
|
|
30701
|
+
ctx.ui.notify(`Merge accepted branches: ${label(setting)} (global).`);
|
|
31933
30702
|
}
|
|
31934
30703
|
},
|
|
31935
30704
|
async openRemovalSetting(ctx) {
|
|
@@ -31937,7 +30706,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31937
30706
|
const policy = await host.getRemovalPreauthorization(ctx);
|
|
31938
30707
|
const choice = await host.selectMenu(
|
|
31939
30708
|
ctx,
|
|
31940
|
-
`
|
|
30709
|
+
`Repository \xB7 Confirm worktree removal \xB7 ${policy.repoKey}`,
|
|
31941
30710
|
markCurrent(
|
|
31942
30711
|
[
|
|
31943
30712
|
{ value: "required", label: "Require approval for each removal" },
|
|
@@ -31958,7 +30727,7 @@ Continuity proof saved for ${persisted} stopped Agent${persisted === 1 ? "" : "s
|
|
|
31958
30727
|
);
|
|
31959
30728
|
if (stored)
|
|
31960
30729
|
ctx.ui.notify(
|
|
31961
|
-
`
|
|
30730
|
+
`Confirm worktree removal: ${choice === "skip" ? "Skipped" : "Required"} (${policy.repoKey}).`
|
|
31962
30731
|
);
|
|
31963
30732
|
} catch (error2) {
|
|
31964
30733
|
ctx.ui.notify(String(error2).replace(/^Error: /, ""), "error");
|
|
@@ -32205,13 +30974,14 @@ import { createHash as createHash14, randomUUID as randomUUID16 } from "node:cry
|
|
|
32205
30974
|
import { lstatSync as lstatSync7, realpathSync as realpathSync7, statSync as statSync8 } from "node:fs";
|
|
32206
30975
|
import {
|
|
32207
30976
|
dirname as dirname9,
|
|
32208
|
-
isAbsolute as
|
|
30977
|
+
isAbsolute as isAbsolute8,
|
|
32209
30978
|
join as join13,
|
|
32210
30979
|
resolve as resolve8,
|
|
32211
30980
|
toNamespacedPath
|
|
32212
30981
|
} from "node:path";
|
|
32213
30982
|
|
|
32214
30983
|
// extension/lead/coordination.ts
|
|
30984
|
+
init_config();
|
|
32215
30985
|
init_supervision();
|
|
32216
30986
|
init_supervision();
|
|
32217
30987
|
init_errors();
|
|
@@ -32223,6 +30993,7 @@ init_compatibility();
|
|
|
32223
30993
|
import { createHash as createHash13, randomUUID as randomUUID15 } from "node:crypto";
|
|
32224
30994
|
|
|
32225
30995
|
// extension/peer-transport.ts
|
|
30996
|
+
init_config();
|
|
32226
30997
|
init_lock();
|
|
32227
30998
|
init_storage();
|
|
32228
30999
|
import {
|
|
@@ -32238,6 +31009,16 @@ import {
|
|
|
32238
31009
|
import { createHash as createHash11, randomUUID as randomUUID13 } from "node:crypto";
|
|
32239
31010
|
import { spawn } from "node:child_process";
|
|
32240
31011
|
import { join as join11 } from "node:path";
|
|
31012
|
+
var PEER_FEDERATION_DISABLED = "Peer federation is disabled";
|
|
31013
|
+
var PeerFederationDisabledError = class extends Error {
|
|
31014
|
+
constructor() {
|
|
31015
|
+
super(PEER_FEDERATION_DISABLED);
|
|
31016
|
+
this.name = "PeerFederationDisabledError";
|
|
31017
|
+
}
|
|
31018
|
+
};
|
|
31019
|
+
function assertPeerFederationEnabled() {
|
|
31020
|
+
if (!readPeerPolicy().remote) throw new PeerFederationDisabledError();
|
|
31021
|
+
}
|
|
32241
31022
|
function peerRecoveryRequest(request, expectedDataRoot) {
|
|
32242
31023
|
return JSON.stringify({ ...request, expectedDataRoot });
|
|
32243
31024
|
}
|
|
@@ -32315,13 +31096,16 @@ function tryClaimRemotePeerOutbound(id) {
|
|
|
32315
31096
|
throw error2;
|
|
32316
31097
|
}
|
|
32317
31098
|
}
|
|
32318
|
-
function persistRemotePeerOutbound(outbound) {
|
|
31099
|
+
function persistRemotePeerOutbound(outbound, storeCorrespondence) {
|
|
31100
|
+
const serialized = JSON.stringify(outbound);
|
|
32319
31101
|
const frameBytes = Buffer.byteLength(outbound.envelope, "utf8");
|
|
32320
|
-
const recordBytes = Buffer.byteLength(
|
|
31102
|
+
const recordBytes = Buffer.byteLength(serialized, "utf8");
|
|
32321
31103
|
if (!UUID4.test(outbound.id) || frameBytes > PEER_TRANSPORT_FRAME_LIMIT_BYTES || recordBytes > OUTBOUND_RECORD_LIMIT_BYTES)
|
|
32322
31104
|
throw new Error("invalid remote peer outbound record");
|
|
32323
31105
|
const path = join11(outboundDirectory(), `${outbound.id}.json`);
|
|
32324
|
-
|
|
31106
|
+
assertPeerFederationEnabled();
|
|
31107
|
+
storeCorrespondence?.();
|
|
31108
|
+
writeFileSync6(path, `${serialized}
|
|
32325
31109
|
`, {
|
|
32326
31110
|
encoding: "utf8",
|
|
32327
31111
|
flag: "wx",
|
|
@@ -32465,10 +31249,12 @@ function run(command, args, input, signal) {
|
|
|
32465
31249
|
});
|
|
32466
31250
|
}
|
|
32467
31251
|
async function listSavedPeerMachines(signal) {
|
|
31252
|
+
assertPeerFederationEnabled();
|
|
32468
31253
|
const [listText, statusText] = await Promise.all([
|
|
32469
31254
|
run("herdr", ["machine", "list", "--json"], void 0, signal),
|
|
32470
31255
|
run("herdr", ["machine", "status", "--json"], void 0, signal)
|
|
32471
31256
|
]);
|
|
31257
|
+
assertPeerFederationEnabled();
|
|
32472
31258
|
const list = JSON.parse(listText);
|
|
32473
31259
|
const statuses = JSON.parse(statusText);
|
|
32474
31260
|
if (!Array.isArray(list) || !Array.isArray(statuses))
|
|
@@ -32511,6 +31297,7 @@ function parsePeerSshTarget(target) {
|
|
|
32511
31297
|
return { host: target };
|
|
32512
31298
|
}
|
|
32513
31299
|
async function runPeerEndpoint(machine, action, input, signal) {
|
|
31300
|
+
assertPeerFederationEnabled();
|
|
32514
31301
|
const target = parsePeerSshTarget(machine.target);
|
|
32515
31302
|
const args = [
|
|
32516
31303
|
"-T",
|
|
@@ -32524,17 +31311,25 @@ async function runPeerEndpoint(machine, action, input, signal) {
|
|
|
32524
31311
|
target.host,
|
|
32525
31312
|
`pi-herdsman-peer ${action}`
|
|
32526
31313
|
];
|
|
32527
|
-
|
|
31314
|
+
try {
|
|
31315
|
+
return await run("ssh", args, input, signal);
|
|
31316
|
+
} catch (error2) {
|
|
31317
|
+
if (error2 instanceof Error && error2.message === PEER_FEDERATION_DISABLED)
|
|
31318
|
+
throw new PeerFederationDisabledError();
|
|
31319
|
+
throw error2;
|
|
31320
|
+
}
|
|
32528
31321
|
}
|
|
32529
31322
|
async function tryPollPeerReplies(poll) {
|
|
32530
31323
|
try {
|
|
32531
31324
|
return await poll();
|
|
32532
|
-
} catch {
|
|
31325
|
+
} catch (error2) {
|
|
31326
|
+
if (error2 instanceof PeerFederationDisabledError) throw error2;
|
|
32533
31327
|
return void 0;
|
|
32534
31328
|
}
|
|
32535
31329
|
}
|
|
32536
31330
|
async function probePeerEndpoint(machine, signal) {
|
|
32537
31331
|
const output = await runPeerEndpoint(machine, "probe", void 0, signal);
|
|
31332
|
+
assertPeerFederationEnabled();
|
|
32538
31333
|
const probe = JSON.parse(output);
|
|
32539
31334
|
if (!probe || typeof probe !== "object" || typeof probe.dataRoot !== "string" || !Array.isArray(probe.peers))
|
|
32540
31335
|
throw new Error("Peer endpoint returned invalid probe data");
|
|
@@ -32655,7 +31450,7 @@ function mutate(id, action) {
|
|
|
32655
31450
|
lock.release();
|
|
32656
31451
|
}
|
|
32657
31452
|
}
|
|
32658
|
-
function
|
|
31453
|
+
function preparePeerCorrespondence(input) {
|
|
32659
31454
|
const c = {
|
|
32660
31455
|
...input,
|
|
32661
31456
|
role: input.role ?? "manager",
|
|
@@ -32664,7 +31459,6 @@ function createPeerCorrespondence(input) {
|
|
|
32664
31459
|
replies: []
|
|
32665
31460
|
};
|
|
32666
31461
|
if (!valid(c)) throw new Error("invalid peer correspondence");
|
|
32667
|
-
save(c);
|
|
32668
31462
|
return c;
|
|
32669
31463
|
}
|
|
32670
31464
|
function storePeerCorrespondence(c) {
|
|
@@ -33054,7 +31848,15 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33054
31848
|
sessionId
|
|
33055
31849
|
)?.kind;
|
|
33056
31850
|
if (!kind) return;
|
|
33057
|
-
const isCurrent = () =>
|
|
31851
|
+
const isCurrent = () => {
|
|
31852
|
+
if (expectedGeneration !== peerPresenceGeneration || ctx.signal?.aborted || processRole !== "lead" || leadRuntime.chiefMode !== "inactive" || leadRuntime.roleSuspended || !leadCoordinationHealthy || ctx.sessionManager.getSessionId() !== sessionId)
|
|
31853
|
+
return false;
|
|
31854
|
+
try {
|
|
31855
|
+
return readPeerPolicy().local;
|
|
31856
|
+
} catch {
|
|
31857
|
+
return false;
|
|
31858
|
+
}
|
|
31859
|
+
};
|
|
33058
31860
|
if (!isCurrent()) return;
|
|
33059
31861
|
const paneId = process.env.HERDR_PANE_ID;
|
|
33060
31862
|
const tabId = process.env.HERDR_TAB_ID;
|
|
@@ -33171,10 +31973,23 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33171
31973
|
appendDurableError2(pi, ctx, "pi_herdsman_state_error", error2);
|
|
33172
31974
|
}
|
|
33173
31975
|
};
|
|
31976
|
+
let peerPresencePaused = false;
|
|
33174
31977
|
const schedulePeerPresence = (ctx) => {
|
|
31978
|
+
peerPresencePaused = false;
|
|
33175
31979
|
const expectedGeneration = peerPresenceGeneration;
|
|
33176
31980
|
peerPresencePublication = peerPresencePublication.catch(() => {
|
|
33177
|
-
}).then(() =>
|
|
31981
|
+
}).then(() => {
|
|
31982
|
+
if (expectedGeneration !== peerPresenceGeneration) return;
|
|
31983
|
+
if (!readPeerPolicy().local) {
|
|
31984
|
+
peerPresencePaused = true;
|
|
31985
|
+
++peerPresenceGeneration;
|
|
31986
|
+
removePeerPresence();
|
|
31987
|
+
return;
|
|
31988
|
+
}
|
|
31989
|
+
return publishPeerPresence(ctx, expectedGeneration);
|
|
31990
|
+
}).catch(
|
|
31991
|
+
(error2) => appendDurableError2(pi, ctx, "pi_herdsman_state_error", error2)
|
|
31992
|
+
);
|
|
33178
31993
|
return peerPresencePublication;
|
|
33179
31994
|
};
|
|
33180
31995
|
const assertCurrentLeadCoordination = (ctx) => {
|
|
@@ -33264,7 +32079,8 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33264
32079
|
if (leadRuntime.controllerRole === "manager" && (!leadRuntime.managerLease || (await currentManager(ctx))?.leaseId !== leadRuntime.managerLease.descriptor.leaseId))
|
|
33265
32080
|
return false;
|
|
33266
32081
|
const target = await livePeerLead(ctx, record.toSessionId);
|
|
33267
|
-
if (!target
|
|
32082
|
+
if (!target) throw new Error("Peer presence is temporarily unavailable");
|
|
32083
|
+
if ((target.role ?? "lead") !== activeRole() || target.piSessionId !== record.toSessionId)
|
|
33268
32084
|
return false;
|
|
33269
32085
|
const source = record.peerSource;
|
|
33270
32086
|
if (source?.role === "lead" && "remoteOrdinary" in source) {
|
|
@@ -33378,15 +32194,25 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33378
32194
|
"Peer assignment changed before the message was queued"
|
|
33379
32195
|
);
|
|
33380
32196
|
verifyEvidence?.();
|
|
32197
|
+
requireLocalPeerCommunication();
|
|
33381
32198
|
writeCoordinationMessage2(record, peerRuntime2());
|
|
33382
32199
|
return record;
|
|
33383
32200
|
};
|
|
33384
32201
|
return !verifyEvidence && senderContext.role === "manager" && targetContext.role === "manager" ? publish() : withProjectAssignmentAuthority(publish);
|
|
33385
32202
|
};
|
|
33386
32203
|
const queueChiefRecord = async (kind, text, ctx, recordId, createdAt = Date.now(), runtimeOverride, expectedSupervisor, resultBindings = [], verifyEvidence, capturedEnvironment) => {
|
|
33387
|
-
|
|
33388
|
-
|
|
32204
|
+
const managerLeaseId = leadRuntime.managerLease?.descriptor.leaseId;
|
|
32205
|
+
const requiresManagerLease = leadRuntime.controllerRole === "manager" || kind === "manager_message";
|
|
32206
|
+
if (kind === "manager_message" && activeRole() !== "manager")
|
|
32207
|
+
throw new Error("Manager role is no longer active");
|
|
32208
|
+
if (kind === "manager_message" && !managerLeaseId)
|
|
33389
32209
|
throw new Error("Manager lease is no longer active");
|
|
32210
|
+
const assertManagerLease = async () => {
|
|
32211
|
+
if (requiresManagerLease && (!managerLeaseId || leadRuntime.managerLease?.descriptor.leaseId !== managerLeaseId || (await currentManager(ctx))?.leaseId !== managerLeaseId || leadRuntime.managerLease?.descriptor.leaseId !== managerLeaseId))
|
|
32212
|
+
throw new Error("Manager lease is no longer active");
|
|
32213
|
+
};
|
|
32214
|
+
assertCurrentLeadCoordination(ctx);
|
|
32215
|
+
await assertManagerLease();
|
|
33390
32216
|
const chief = await currentSupervisor(ctx);
|
|
33391
32217
|
if (!chief) throw new Error("No active supervisor is available");
|
|
33392
32218
|
if (expectedSupervisor && (chief.piSessionId !== expectedSupervisor.piSessionId || chief.leaseId !== expectedSupervisor.leaseId))
|
|
@@ -33399,7 +32225,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33399
32225
|
version: 2,
|
|
33400
32226
|
build: HERDSMAN_BUILD2,
|
|
33401
32227
|
id: recordId ?? randomUUID15(),
|
|
33402
|
-
leaseId: chief.leaseId,
|
|
32228
|
+
leaseId: kind === "manager_message" ? managerLeaseId : chief.leaseId,
|
|
33403
32229
|
kind,
|
|
33404
32230
|
fromSessionId: leadSessionId,
|
|
33405
32231
|
toSessionId: chief.piSessionId,
|
|
@@ -33411,8 +32237,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33411
32237
|
};
|
|
33412
32238
|
const freshChief = await currentSupervisor(ctx);
|
|
33413
32239
|
assertCurrentLeadCoordination(ctx);
|
|
33414
|
-
|
|
33415
|
-
throw new Error("Manager lease is no longer active");
|
|
32240
|
+
await assertManagerLease();
|
|
33416
32241
|
if (!freshChief || freshChief.leaseId !== chief.leaseId || expectedSupervisor && (freshChief.piSessionId !== expectedSupervisor.piSessionId || freshChief.leaseId !== expectedSupervisor.leaseId) || record.toSessionId !== freshChief.piSessionId)
|
|
33417
32242
|
throw new Error(
|
|
33418
32243
|
"Supervisor target changed before the message was queued"
|
|
@@ -33479,15 +32304,38 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33479
32304
|
const lastPeerCorrespondenceErrors = /* @__PURE__ */ new Map();
|
|
33480
32305
|
const matchesReturnRecipient = (correspondence, recipient) => !correspondence.finalized && correspondence.recipientSession === recipient.piSessionId && correspondence.recipientGeneration === recipient.claim.id;
|
|
33481
32306
|
let latestPeerDiscovery = 0;
|
|
32307
|
+
let remoteRouteGeneration = 0;
|
|
32308
|
+
const peerPolicy = () => {
|
|
32309
|
+
const policy = readPeerPolicy();
|
|
32310
|
+
if (!policy.remote) {
|
|
32311
|
+
++remoteRouteGeneration;
|
|
32312
|
+
remotePeerRoutes.clear();
|
|
32313
|
+
ambiguousRemoteSessions.clear();
|
|
32314
|
+
}
|
|
32315
|
+
return policy;
|
|
32316
|
+
};
|
|
32317
|
+
const requireLocalPeerCommunication = () => {
|
|
32318
|
+
if (!peerPolicy().local)
|
|
32319
|
+
throw new Error("Peer communication is disabled in Herdsman settings");
|
|
32320
|
+
};
|
|
32321
|
+
const requireFederation = () => {
|
|
32322
|
+
if (!peerPolicy().remote) throw new PeerFederationDisabledError();
|
|
32323
|
+
};
|
|
32324
|
+
const forgetMachineRoutes = (machine) => {
|
|
32325
|
+
for (const [session, route] of remotePeerRoutes)
|
|
32326
|
+
if (route.machine.id === machine.id) remotePeerRoutes.delete(session);
|
|
32327
|
+
};
|
|
33482
32328
|
const deliverRemoteOutbound = async (machine, id, envelope, signal) => {
|
|
33483
32329
|
try {
|
|
32330
|
+
requireFederation();
|
|
33484
32331
|
const receipt = JSON.parse(
|
|
33485
32332
|
await runPeerEndpoint(machine, "accept", envelope, signal)
|
|
33486
32333
|
);
|
|
33487
32334
|
if (receipt.accepted !== true || receipt.id !== id) return false;
|
|
33488
32335
|
removeRemotePeerOutbound(id);
|
|
33489
32336
|
return true;
|
|
33490
|
-
} catch {
|
|
32337
|
+
} catch (error2) {
|
|
32338
|
+
if (error2 instanceof PeerFederationDisabledError) throw error2;
|
|
33491
32339
|
return false;
|
|
33492
32340
|
}
|
|
33493
32341
|
};
|
|
@@ -33596,6 +32444,13 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33596
32444
|
"target_not_found",
|
|
33597
32445
|
"No active supervisor is available"
|
|
33598
32446
|
);
|
|
32447
|
+
const kind = activeRole() === "manager" ? "manager_message" : "lead_message";
|
|
32448
|
+
const expectedManagerLeaseId = kind === "manager_message" ? leadRuntime.managerLease?.descriptor.leaseId : void 0;
|
|
32449
|
+
if (kind === "manager_message" && !expectedManagerLeaseId)
|
|
32450
|
+
throw structuredError(
|
|
32451
|
+
"internal_failure",
|
|
32452
|
+
"Manager lease is no longer active"
|
|
32453
|
+
);
|
|
33599
32454
|
const recordId = randomUUID15();
|
|
33600
32455
|
const createdAt = Date.now();
|
|
33601
32456
|
const evidenceScope = hasManagerEvidenceSelectors(params.files ?? []) ? await host.managerEvidence?.(ctx, params.files ?? []) : void 0;
|
|
@@ -33616,8 +32471,8 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33616
32471
|
version: 2,
|
|
33617
32472
|
build: HERDSMAN_BUILD2,
|
|
33618
32473
|
id: recordId,
|
|
33619
|
-
leaseId: chief.leaseId,
|
|
33620
|
-
kind
|
|
32474
|
+
leaseId: kind === "manager_message" ? expectedManagerLeaseId : chief.leaseId,
|
|
32475
|
+
kind,
|
|
33621
32476
|
fromSessionId: ctx.sessionManager.getSessionId(),
|
|
33622
32477
|
toSessionId: chief.piSessionId,
|
|
33623
32478
|
leadSessionId: ctx.sessionManager.getSessionId(),
|
|
@@ -33628,14 +32483,21 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33628
32483
|
})
|
|
33629
32484
|
);
|
|
33630
32485
|
const queue = async () => {
|
|
32486
|
+
const currentKind = activeRole() === "manager" ? "manager_message" : "lead_message";
|
|
32487
|
+
if (currentKind !== kind)
|
|
32488
|
+
throw new Error(
|
|
32489
|
+
"Coordinator role changed before the message was queued"
|
|
32490
|
+
);
|
|
32491
|
+
if (kind === "manager_message" && leadRuntime.managerLease?.descriptor.leaseId !== expectedManagerLeaseId)
|
|
32492
|
+
throw new Error("Manager lease is no longer active");
|
|
33631
32493
|
record = await queueChiefRecord(
|
|
33632
|
-
|
|
32494
|
+
kind,
|
|
33633
32495
|
prepared.text,
|
|
33634
32496
|
ctx,
|
|
33635
32497
|
recordId,
|
|
33636
32498
|
createdAt,
|
|
33637
32499
|
void 0,
|
|
33638
|
-
|
|
32500
|
+
{ piSessionId: chief.piSessionId, leaseId: chief.leaseId },
|
|
33639
32501
|
prepared.resultBindings,
|
|
33640
32502
|
evidenceScope?.verify,
|
|
33641
32503
|
senderEnvironment ?? null
|
|
@@ -33688,7 +32550,7 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33688
32550
|
content: [
|
|
33689
32551
|
{
|
|
33690
32552
|
type: "text",
|
|
33691
|
-
text: `Message
|
|
32553
|
+
text: `Message queued for supervisor (${record.id}).`
|
|
33692
32554
|
}
|
|
33693
32555
|
],
|
|
33694
32556
|
details: { id: record.id }
|
|
@@ -33709,12 +32571,15 @@ function createLeadCoordinationRuntime(host) {
|
|
|
33709
32571
|
Semantic result reference conflict; use the immutable local artifact reference instead:
|
|
33710
32572
|
${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).join("\n")}` : "";
|
|
33711
32573
|
const executePeerMessage = async (_id, raw, signal, _update, ctx) => {
|
|
32574
|
+
const params = raw;
|
|
33712
32575
|
if (controllerScope.kind !== "root" || leadRuntime.chiefMode !== "inactive" || leadRuntime.roleSuspended)
|
|
33713
32576
|
throw new Error("Peer is unavailable in this role");
|
|
33714
32577
|
if (leadRuntime.controllerRole === "manager" && (!leadRuntime.managerLease || (await currentManager(ctx))?.leaseId !== leadRuntime.managerLease.descriptor.leaseId))
|
|
33715
32578
|
throw new Error("Manager lease is no longer active");
|
|
33716
|
-
const params = raw;
|
|
33717
32579
|
if (params.action === "list") {
|
|
32580
|
+
requireLocalPeerCommunication();
|
|
32581
|
+
if (peerPresencePaused) schedulePeerPresence(ctx);
|
|
32582
|
+
await peerPresencePublication;
|
|
33718
32583
|
const discovery = ++latestPeerDiscovery;
|
|
33719
32584
|
const self = ctx.sessionManager.getSessionId();
|
|
33720
32585
|
const assignmentSnapshot = activeRole() === "manager" ? void 0 : globalProjectAssignmentSnapshot();
|
|
@@ -33729,8 +32594,8 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33729
32594
|
throw new Error(
|
|
33730
32595
|
"Peer eligibility could not be verified; retry list_peers."
|
|
33731
32596
|
);
|
|
33732
|
-
const remoteDiscoveryEligible = activeRole() === "manager" || activeRole() === "lead" &&
|
|
33733
|
-
const correspondences = (activeRole() === "manager" || activeRole() === "lead") && own.role === activeRole() ? listPeerCorrespondences().filter(
|
|
32597
|
+
const remoteDiscoveryEligible = peerPolicy().remote && (activeRole() === "manager" || activeRole() === "lead" && assignmentSnapshot !== void 0 && isRemoteOrdinaryLead(own, assignmentSnapshot));
|
|
32598
|
+
const correspondences = peerPolicy().remote && (activeRole() === "manager" || activeRole() === "lead") && own.role === activeRole() ? listPeerCorrespondences().filter(
|
|
33734
32599
|
(correspondence) => (correspondence.role ?? "manager") === activeRole()
|
|
33735
32600
|
) : [];
|
|
33736
32601
|
for (const correspondence of correspondences) {
|
|
@@ -33791,7 +32656,9 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33791
32656
|
let machineDiscoveryIncomplete = false;
|
|
33792
32657
|
let pendingOutbounds;
|
|
33793
32658
|
let pendingCorrespondences;
|
|
33794
|
-
|
|
32659
|
+
const routeGeneration2 = remoteRouteGeneration;
|
|
32660
|
+
const remoteDiscoveryAllowed = () => !signal?.aborted && peerPolicy().remote && routeGeneration2 === remoteRouteGeneration;
|
|
32661
|
+
if (remoteDiscoveryEligible && remoteDiscoveryAllowed()) {
|
|
33795
32662
|
let machines;
|
|
33796
32663
|
let machineListingSucceeded = false;
|
|
33797
32664
|
try {
|
|
@@ -33819,7 +32686,7 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33819
32686
|
}
|
|
33820
32687
|
}
|
|
33821
32688
|
for (const machine of machines) {
|
|
33822
|
-
if (
|
|
32689
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
33823
32690
|
if (!machine.reachable) {
|
|
33824
32691
|
machineDiscoveryIncomplete = true;
|
|
33825
32692
|
addRemoteDiagnostic({
|
|
@@ -33829,9 +32696,10 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33829
32696
|
continue;
|
|
33830
32697
|
}
|
|
33831
32698
|
let identityEstablished = false;
|
|
32699
|
+
const machinePeersStart = peers.length;
|
|
33832
32700
|
try {
|
|
33833
32701
|
const snapshot = await probePeerEndpoint(machine, signal);
|
|
33834
|
-
if (
|
|
32702
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
33835
32703
|
identityEstablished = true;
|
|
33836
32704
|
const ordinaryLeadScanIncomplete = activeRole() === "lead" && snapshot.ordinaryLeadsComplete !== true;
|
|
33837
32705
|
if (ordinaryLeadScanIncomplete) {
|
|
@@ -33907,6 +32775,7 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33907
32775
|
if (!pendingOutbounds)
|
|
33908
32776
|
pendingOutbounds = listRemotePeerOutbounds();
|
|
33909
32777
|
for (const candidate of pendingOutbounds) {
|
|
32778
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
33910
32779
|
if (candidate.machine.id !== machine.id || candidate.session !== self || candidate.dataRoot !== snapshot.dataRoot)
|
|
33911
32780
|
continue;
|
|
33912
32781
|
const releaseOutbound = tryClaimRemotePeerOutbound(
|
|
@@ -33944,6 +32813,7 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33944
32813
|
continue;
|
|
33945
32814
|
}
|
|
33946
32815
|
if (retry.kind !== "retry") continue;
|
|
32816
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
33947
32817
|
if (retry.envelope !== envelope) {
|
|
33948
32818
|
envelope = retry.envelope;
|
|
33949
32819
|
retargetRemotePeerOutbound(
|
|
@@ -33959,7 +32829,8 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33959
32829
|
envelope,
|
|
33960
32830
|
signal
|
|
33961
32831
|
);
|
|
33962
|
-
} catch {
|
|
32832
|
+
} catch (error2) {
|
|
32833
|
+
if (error2 instanceof PeerFederationDisabledError) throw error2;
|
|
33963
32834
|
} finally {
|
|
33964
32835
|
releaseOutbound();
|
|
33965
32836
|
}
|
|
@@ -33967,6 +32838,7 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
33967
32838
|
if (!pendingCorrespondences)
|
|
33968
32839
|
pendingCorrespondences = listPeerCorrespondences();
|
|
33969
32840
|
for (const candidate of pendingCorrespondences) {
|
|
32841
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
33970
32842
|
if (candidate.originSession !== self || (candidate.role ?? "manager") !== activeRole())
|
|
33971
32843
|
continue;
|
|
33972
32844
|
const remote = snapshot.peers.find(
|
|
@@ -34012,6 +32884,7 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
34012
32884
|
);
|
|
34013
32885
|
correspondence.recipientGeneration = remote.claim.id;
|
|
34014
32886
|
}
|
|
32887
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
34015
32888
|
if (correspondence.originGeneration !== own.claim.id) {
|
|
34016
32889
|
const recovery = JSON.parse(
|
|
34017
32890
|
await runPeerEndpoint(
|
|
@@ -34051,6 +32924,7 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
34051
32924
|
recipientSession: correspondence.recipientSession,
|
|
34052
32925
|
recipientGeneration: correspondence.recipientGeneration
|
|
34053
32926
|
});
|
|
32927
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
34054
32928
|
const polled = await tryPollPeerReplies(
|
|
34055
32929
|
() => runPeerEndpoint(machine, "poll", request, signal)
|
|
34056
32930
|
);
|
|
@@ -34064,6 +32938,7 @@ ${conflicts.map((binding) => `${binding.ref} \u2192 ${binding.canonicalRef}`).jo
|
|
|
34064
32938
|
);
|
|
34065
32939
|
assertPeerDataRoot(response.dataRoot, snapshot.dataRoot);
|
|
34066
32940
|
for (const reply of response.replies) {
|
|
32941
|
+
if (!remoteDiscoveryAllowed()) break;
|
|
34067
32942
|
if (typeof reply.id !== "string" || typeof reply.text !== "string" || typeof reply.digest !== "string" || typeof reply.createdAt !== "number" || !Number.isFinite(reply.createdAt) || reply.attachments !== void 0 && !Array.isArray(reply.attachments) || reply.resultBindings !== void 0 && (!Array.isArray(reply.resultBindings) || !reply.resultBindings.every(isResultBinding)) || peerPayloadDigest({
|
|
34068
32943
|
text: reply.text,
|
|
34069
32944
|
...reply.attachments?.length ? { attachments: reply.attachments } : {},
|
|
@@ -34125,6 +33000,7 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34125
33000
|
...resolution.bindings.length ? { resultBindings: resolution.bindings } : {},
|
|
34126
33001
|
createdAt: reply.createdAt
|
|
34127
33002
|
};
|
|
33003
|
+
requireFederation();
|
|
34128
33004
|
writeCoordinationMessage2(record2, peerRuntime2());
|
|
34129
33005
|
importResultBindings2(
|
|
34130
33006
|
pi,
|
|
@@ -34150,6 +33026,7 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34150
33026
|
}
|
|
34151
33027
|
lastPeerCorrespondenceErrors.delete(correspondence.id);
|
|
34152
33028
|
} catch (error2) {
|
|
33029
|
+
if (error2 instanceof PeerFederationDisabledError) throw error2;
|
|
34153
33030
|
if (signal?.aborted) break;
|
|
34154
33031
|
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
34155
33032
|
if (lastPeerCorrespondenceErrors.get(correspondence.id) !== message) {
|
|
@@ -34171,7 +33048,17 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34171
33048
|
}
|
|
34172
33049
|
}
|
|
34173
33050
|
} catch (error2) {
|
|
34174
|
-
if (
|
|
33051
|
+
if (error2 instanceof PeerFederationDisabledError) {
|
|
33052
|
+
forgetMachineRoutes(machine);
|
|
33053
|
+
for (const [session, route] of discoveredRemotePeerRoutes)
|
|
33054
|
+
if (route.machine.id === machine.id)
|
|
33055
|
+
discoveredRemotePeerRoutes.delete(session);
|
|
33056
|
+
peers.splice(machinePeersStart);
|
|
33057
|
+
addRemoteDiagnostic({
|
|
33058
|
+
machine: diagnosticLabel(machine.label, "machine"),
|
|
33059
|
+
reason: "federation_disabled"
|
|
33060
|
+
});
|
|
33061
|
+
} else if (identityEstablished) {
|
|
34175
33062
|
appendDurableError2(pi, ctx, "pi_herdsman_state_error", error2);
|
|
34176
33063
|
} else {
|
|
34177
33064
|
machineDiscoveryIncomplete = true;
|
|
@@ -34208,7 +33095,16 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34208
33095
|
if (index >= 0) peers.splice(index, 1);
|
|
34209
33096
|
}
|
|
34210
33097
|
}
|
|
34211
|
-
|
|
33098
|
+
const policy = peerPolicy();
|
|
33099
|
+
if (!policy.local) requireLocalPeerCommunication();
|
|
33100
|
+
const remoteResultsValid = policy.remote && remoteRouteGeneration === routeGeneration2;
|
|
33101
|
+
if (!remoteResultsValid) {
|
|
33102
|
+
for (let i = peers.length - 1; i >= 0; i--)
|
|
33103
|
+
if ("machine" in peers[i]) peers.splice(i, 1);
|
|
33104
|
+
remoteDiagnostics.length = 0;
|
|
33105
|
+
remoteDiagnosticsOmitted = 0;
|
|
33106
|
+
}
|
|
33107
|
+
if (remoteResultsValid && (activeRole() === "manager" || activeRole() === "lead") && discovery === latestPeerDiscovery && !signal?.aborted && !machineListingFailed) {
|
|
34212
33108
|
remotePeerRoutes.clear();
|
|
34213
33109
|
for (const [session, route] of discoveredRemotePeerRoutes)
|
|
34214
33110
|
remotePeerRoutes.set(session, route);
|
|
@@ -34216,14 +33112,14 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34216
33112
|
for (const session of discoveredAmbiguousSessions)
|
|
34217
33113
|
ambiguousRemoteSessions.add(session);
|
|
34218
33114
|
}
|
|
34219
|
-
if (activeRole() === "lead" && !remoteDiscoveryEligible) {
|
|
33115
|
+
if (remoteResultsValid && discovery === latestPeerDiscovery && activeRole() === "lead" && !remoteDiscoveryEligible) {
|
|
34220
33116
|
for (const [session, route] of remotePeerRoutes)
|
|
34221
33117
|
if (route.role === "lead") remotePeerRoutes.delete(session);
|
|
34222
33118
|
ambiguousRemoteSessions.clear();
|
|
34223
33119
|
}
|
|
34224
33120
|
const discovered = new Set(peers.map((peer) => peer.session));
|
|
34225
33121
|
const replyCorrespondences = /* @__PURE__ */ new Map();
|
|
34226
|
-
if ((activeRole() === "manager" || activeRole() === "lead") && own.role === activeRole())
|
|
33122
|
+
if (remoteResultsValid && (activeRole() === "manager" || activeRole() === "lead") && own.role === activeRole())
|
|
34227
33123
|
for (const correspondence of correspondences) {
|
|
34228
33124
|
if (!matchesReturnRecipient(correspondence, own)) continue;
|
|
34229
33125
|
replyCorrespondences.set(
|
|
@@ -34291,6 +33187,11 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34291
33187
|
"Peer target role does not match the current role; run `list_peers` again."
|
|
34292
33188
|
);
|
|
34293
33189
|
const recipientSession = resolvedTarget.sessionId;
|
|
33190
|
+
const cachedRemote = remotePeerRoutes.has(recipientSession);
|
|
33191
|
+
requireLocalPeerCommunication();
|
|
33192
|
+
if (cachedRemote) requireFederation();
|
|
33193
|
+
if (peerPresencePaused) schedulePeerPresence(ctx);
|
|
33194
|
+
await peerPresencePublication;
|
|
34294
33195
|
const sender = await livePeerLead(ctx, ctx.sessionManager.getSessionId());
|
|
34295
33196
|
if (!sender)
|
|
34296
33197
|
throw new Error(
|
|
@@ -34302,6 +33203,15 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34302
33203
|
) : [];
|
|
34303
33204
|
const target = remoteRoute ? void 0 : await livePeerLead(ctx, recipientSession);
|
|
34304
33205
|
const noAuthorizedLocalTarget = (!target || (target.role ?? "lead") !== activeRole()) && returnCorrespondences.length !== 1;
|
|
33206
|
+
requireLocalPeerCommunication();
|
|
33207
|
+
const routeGeneration = remoteRouteGeneration;
|
|
33208
|
+
const assertRemoteSubmission = () => {
|
|
33209
|
+
requireFederation();
|
|
33210
|
+
if (routeGeneration !== remoteRouteGeneration)
|
|
33211
|
+
throw new Error("Remote peer route changed; run `list_peers` again.");
|
|
33212
|
+
};
|
|
33213
|
+
if (remoteRoute || returnCorrespondences.length === 1)
|
|
33214
|
+
assertRemoteSubmission();
|
|
34305
33215
|
const rejection = (sender.role ?? "lead") !== activeRole() ? "sender_role_changed" : remoteRoute ? remoteRoute.role !== activeRole() ? "route_role_mismatch" : ambiguousRemoteSessions.has(recipientSession) ? "route_ambiguous" : void 0 : noAuthorizedLocalTarget ? ambiguousRemoteSessions.has(recipientSession) ? "route_ambiguous" : "no_authorized_target" : void 0;
|
|
34306
33216
|
if (rejection)
|
|
34307
33217
|
throw new Error(
|
|
@@ -34370,6 +33280,7 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34370
33280
|
);
|
|
34371
33281
|
if (!currentSender || !samePeerLeadAuthority(currentSender, sender) || activeRole() === "lead" && (!assignments || !isRemoteOrdinaryLead(currentSender, assignments) || currentCorrespondence.length !== 1) || activeRole() !== "lead" && currentCorrespondence.length !== 1)
|
|
34372
33282
|
throw new Error("Peer correspondence authority changed");
|
|
33283
|
+
assertRemoteSubmission();
|
|
34373
33284
|
queuePeerReply(
|
|
34374
33285
|
correspondence,
|
|
34375
33286
|
replyId,
|
|
@@ -34402,7 +33313,16 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34402
33313
|
};
|
|
34403
33314
|
}
|
|
34404
33315
|
if (remoteRoute) {
|
|
34405
|
-
|
|
33316
|
+
assertRemoteSubmission();
|
|
33317
|
+
const current = await probePeerEndpoint(
|
|
33318
|
+
remoteRoute.machine,
|
|
33319
|
+
signal
|
|
33320
|
+
).catch((error2) => {
|
|
33321
|
+
if (error2 instanceof PeerFederationDisabledError)
|
|
33322
|
+
forgetMachineRoutes(remoteRoute.machine);
|
|
33323
|
+
throw error2;
|
|
33324
|
+
});
|
|
33325
|
+
assertRemoteSubmission();
|
|
34406
33326
|
const currentTarget = current.peers.find(
|
|
34407
33327
|
(peer) => peer.role === remoteRoute.role && peer.piSessionId === recipientSession && peer.claim.id === remoteRoute.claimId && (remoteRoute.role !== "lead" || current.ordinaryLeadsComplete === true && peer.sessionKind === "ordinary")
|
|
34408
33328
|
);
|
|
@@ -34458,7 +33378,7 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34458
33378
|
}
|
|
34459
33379
|
const correspondence = listPeerCorrespondences().find(
|
|
34460
33380
|
(item) => !item.finalized && (item.role ?? "manager") === remoteRoute.role && item.originSession === sender.piSessionId && item.recipientSession === recipientSession
|
|
34461
|
-
) ??
|
|
33381
|
+
) ?? preparePeerCorrespondence({
|
|
34462
33382
|
originSession: sender.piSessionId,
|
|
34463
33383
|
originGeneration: sender.claim.id,
|
|
34464
33384
|
recipientSession,
|
|
@@ -34473,7 +33393,6 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34473
33393
|
...correspondence.originDisplay,
|
|
34474
33394
|
...originDisplay
|
|
34475
33395
|
};
|
|
34476
|
-
storePeerCorrespondence(correspondence);
|
|
34477
33396
|
const envelope2 = JSON.stringify({
|
|
34478
33397
|
record: record2,
|
|
34479
33398
|
expectedDataRoot: remoteRoute.dataRoot,
|
|
@@ -34482,16 +33401,20 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34482
33401
|
correspondence
|
|
34483
33402
|
});
|
|
34484
33403
|
const transferDigest = peerPayloadDigest({ record: record2, attachments });
|
|
34485
|
-
|
|
34486
|
-
|
|
34487
|
-
|
|
34488
|
-
|
|
34489
|
-
|
|
34490
|
-
|
|
34491
|
-
|
|
34492
|
-
|
|
34493
|
-
|
|
34494
|
-
|
|
33404
|
+
assertRemoteSubmission();
|
|
33405
|
+
persistRemotePeerOutbound(
|
|
33406
|
+
{
|
|
33407
|
+
id: recordId,
|
|
33408
|
+
machine: remoteRoute.machine,
|
|
33409
|
+
dataRoot: remoteRoute.dataRoot,
|
|
33410
|
+
session: sender.piSessionId,
|
|
33411
|
+
claimId: sender.claim.id,
|
|
33412
|
+
recipientSession,
|
|
33413
|
+
digest: transferDigest,
|
|
33414
|
+
envelope: envelope2
|
|
33415
|
+
},
|
|
33416
|
+
() => storePeerCorrespondence(correspondence)
|
|
33417
|
+
);
|
|
34495
33418
|
return envelope2;
|
|
34496
33419
|
};
|
|
34497
33420
|
let envelope = "";
|
|
@@ -34513,6 +33436,9 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34513
33436
|
envelope,
|
|
34514
33437
|
signal
|
|
34515
33438
|
);
|
|
33439
|
+
} catch (error2) {
|
|
33440
|
+
if (!(error2 instanceof PeerFederationDisabledError)) throw error2;
|
|
33441
|
+
forgetMachineRoutes(remoteRoute.machine);
|
|
34516
33442
|
} finally {
|
|
34517
33443
|
releaseOutbound();
|
|
34518
33444
|
}
|
|
@@ -34854,6 +33780,26 @@ ${receivedRefs.join("\n")}` : ""}`,
|
|
|
34854
33780
|
},
|
|
34855
33781
|
supervisorMessage: executeSupervisorMessage,
|
|
34856
33782
|
peerMessage: executePeerMessage,
|
|
33783
|
+
reconcileRemotePeers: async (ctx, signal) => {
|
|
33784
|
+
const policy = peerPolicy();
|
|
33785
|
+
if (!policy.local) {
|
|
33786
|
+
if (peerPresenceRecord) await schedulePeerPresence(ctx);
|
|
33787
|
+
return;
|
|
33788
|
+
}
|
|
33789
|
+
if (peerPresencePaused) await schedulePeerPresence(ctx);
|
|
33790
|
+
if (!policy.remote) return;
|
|
33791
|
+
try {
|
|
33792
|
+
await executePeerMessage(
|
|
33793
|
+
"remote-reconciliation",
|
|
33794
|
+
{ action: "list", internal: true },
|
|
33795
|
+
signal,
|
|
33796
|
+
void 0,
|
|
33797
|
+
ctx
|
|
33798
|
+
);
|
|
33799
|
+
} catch (error2) {
|
|
33800
|
+
if (peerPolicy().local) throw error2;
|
|
33801
|
+
}
|
|
33802
|
+
},
|
|
34857
33803
|
latestCustomMessageText,
|
|
34858
33804
|
prepareLeadSupervisorStateMessage,
|
|
34859
33805
|
prepareCoordinationInput
|
|
@@ -35470,16 +34416,16 @@ This is the session-start definition snapshot. Use list_agents for live Agent st
|
|
|
35470
34416
|
}
|
|
35471
34417
|
if (!host.isActiveManager()) {
|
|
35472
34418
|
try {
|
|
35473
|
-
const
|
|
35474
|
-
if (
|
|
35475
|
-
if (
|
|
34419
|
+
const relative4 = host.currentLeadRelativePolicy?.();
|
|
34420
|
+
if (relative4) {
|
|
34421
|
+
if (relative4.excluded.some(
|
|
35476
34422
|
(pattern) => matchesToolPattern(pattern, event.toolName)
|
|
35477
34423
|
))
|
|
35478
34424
|
return {
|
|
35479
34425
|
block: true,
|
|
35480
34426
|
reason: "Tool is excluded by the active Lead profile."
|
|
35481
34427
|
};
|
|
35482
|
-
if (
|
|
34428
|
+
if (relative4.owned.has(event.toolName) && !relative4.allowedOwned.has(event.toolName))
|
|
35483
34429
|
return {
|
|
35484
34430
|
block: true,
|
|
35485
34431
|
reason: "Tool is unavailable in the active Lead profile."
|
|
@@ -35676,10 +34622,12 @@ function registerLeadRuntime(pi, options) {
|
|
|
35676
34622
|
const state = leadRuntime;
|
|
35677
34623
|
const ctx = state.leadContext;
|
|
35678
34624
|
const role2 = verifiedActiveRootRole();
|
|
34625
|
+
const sessionId = ctx?.sessionManager.getSessionId() ?? "";
|
|
35679
34626
|
return {
|
|
35680
|
-
sessionId
|
|
34627
|
+
sessionId,
|
|
35681
34628
|
roleGeneration: state.chiefModeGeneration,
|
|
35682
34629
|
role: role2,
|
|
34630
|
+
sessionKind: sessionKind?.sessionId === sessionId ? sessionKind.kind : void 0,
|
|
35683
34631
|
authority: role2 === "manager" ? state.managerLease : role2 === "chief" ? state.chiefLease : void 0,
|
|
35684
34632
|
profile: role2 === "lead" ? leadExecution : role2 === "manager" || role2 === "chief" ? currentSupervisoryProfile(ctx, role2) : void 0
|
|
35685
34633
|
};
|
|
@@ -36282,13 +35230,7 @@ function registerLeadRuntime(pi, options) {
|
|
|
36282
35230
|
),
|
|
36283
35231
|
reconcileRemotePeers: async (ctx, signal) => {
|
|
36284
35232
|
if (activeLeadRole(leadRuntime) === "manager" || activeLeadRole(leadRuntime) === "lead")
|
|
36285
|
-
await coordinationRuntime.
|
|
36286
|
-
"remote-reconciliation",
|
|
36287
|
-
{ action: "list", internal: true },
|
|
36288
|
-
signal,
|
|
36289
|
-
void 0,
|
|
36290
|
-
ctx
|
|
36291
|
-
);
|
|
35233
|
+
await coordinationRuntime.reconcileRemotePeers(ctx, signal);
|
|
36292
35234
|
}
|
|
36293
35235
|
};
|
|
36294
35236
|
inboxRuntime = createLeadInboxRuntime(inboxServices);
|
|
@@ -37009,7 +35951,7 @@ function registerLeadRuntime(pi, options) {
|
|
|
37009
35951
|
"Managed Lead session provenance does not match assignment"
|
|
37010
35952
|
);
|
|
37011
35953
|
expectedCheckout = saved.getCwd();
|
|
37012
|
-
if (!expectedCheckout || !
|
|
35954
|
+
if (!expectedCheckout || !isAbsolute8(expectedCheckout))
|
|
37013
35955
|
throw new Error("Managed Lead checkout provenance is unavailable");
|
|
37014
35956
|
const common = await pi.exec(
|
|
37015
35957
|
"git",
|
|
@@ -40103,7 +39045,7 @@ function createLeadInboxRuntime(host) {
|
|
|
40103
39045
|
"session_provenance_mismatch"
|
|
40104
39046
|
);
|
|
40105
39047
|
savedSessionCwd = saved.getCwd();
|
|
40106
|
-
if (!savedSessionCwd || !
|
|
39048
|
+
if (!savedSessionCwd || !isAbsolute8(savedSessionCwd))
|
|
40107
39049
|
return projectAssignmentAuthorized(
|
|
40108
39050
|
false,
|
|
40109
39051
|
"session_provenance_unavailable"
|
|
@@ -40355,7 +39297,7 @@ function createLeadInboxRuntime(host) {
|
|
|
40355
39297
|
} catch {
|
|
40356
39298
|
continue;
|
|
40357
39299
|
}
|
|
40358
|
-
if (record.kind === "peer_message" && record.toSessionId === sessionId && sessionId === ctx.sessionManager.getSessionId())
|
|
39300
|
+
if (record.kind === "peer_message" && readPeerPolicy().local && record.toSessionId === sessionId && sessionId === ctx.sessionManager.getSessionId())
|
|
40359
39301
|
removeChiefMessage(peerRuntime2(), sessionId, record.id, record);
|
|
40360
39302
|
}
|
|
40361
39303
|
} catch {
|
|
@@ -40619,6 +39561,10 @@ function createLeadInboxRuntime(host) {
|
|
|
40619
39561
|
const contextCurrent = recipientContext.role === "manager" ? !snapshot : !!snapshot && matches.length <= 1 && !!matches.length === recipientContext.managed && (!assignment || !!recipientContext.group && assignment.assignment.repoKey === recipientContext.group.repoKey && assignment.socketHash === createHash14("sha256").update(recipient.socket).digest("hex"));
|
|
40620
39562
|
if (!current || !samePeerLeadAuthority(current, recipient) || current.group?.repoKey !== recipient.group?.repoKey || current.group?.primaryWorkspaceId !== recipient.group?.primaryWorkspaceId || !contextCurrent || (remoteOrdinarySource ? recipientContext.role !== "lead" || !snapshot || !isRemoteOrdinaryLead(current, snapshot) : !localSource || !canMessagePeer(localSource, recipientContext)))
|
|
40621
39563
|
throw new Error("Peer eligibility changed before delivery");
|
|
39564
|
+
if (!readPeerPolicy().local)
|
|
39565
|
+
throw new Error(
|
|
39566
|
+
"Peer communication is disabled in Herdsman settings"
|
|
39567
|
+
);
|
|
40622
39568
|
importResultBindings2(pi, ctx, resultBindings, record.kind);
|
|
40623
39569
|
reservePayload();
|
|
40624
39570
|
submitted = pi.sendMessage(payload, options);
|
|
@@ -40699,6 +39645,7 @@ function createLeadInboxRuntime(host) {
|
|
|
40699
39645
|
}
|
|
40700
39646
|
}
|
|
40701
39647
|
},
|
|
39648
|
+
isPeerDeliveryEnabled: () => readPeerPolicy().local,
|
|
40702
39649
|
forceNonTriggering: !!phase,
|
|
40703
39650
|
maxDeliveries: budget ? Math.max(0, COORDINATION_INBOX_SCAN_LIMIT - budget.count) : void 0,
|
|
40704
39651
|
accepted: async (record) => {
|
|
@@ -41479,7 +40426,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
41479
40426
|
return true;
|
|
41480
40427
|
};
|
|
41481
40428
|
const gitWorktreeInventory = async (ctx, repoKey, primaryWorkspaceId, sourceCheckoutPath, knownScope) => {
|
|
41482
|
-
if (!
|
|
40429
|
+
if (!isAbsolute8(sourceCheckoutPath)) return void 0;
|
|
41483
40430
|
try {
|
|
41484
40431
|
const scope = knownScope ?? await host.worktreeGroupScope(ctx, primaryWorkspaceId, ctx.signal);
|
|
41485
40432
|
if (!scope) return void 0;
|
|
@@ -41492,7 +40439,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
41492
40439
|
if (rootResult.code !== 0 || rootResult.killed || rootResult.stderr?.trim())
|
|
41493
40440
|
return void 0;
|
|
41494
40441
|
const commonDir = String(rootResult.stdout ?? "").trim();
|
|
41495
|
-
if (!commonDir || !
|
|
40442
|
+
if (!commonDir || !isAbsolute8(commonDir)) return void 0;
|
|
41496
40443
|
const result = await host.pi.exec(
|
|
41497
40444
|
"git",
|
|
41498
40445
|
["worktree", "list", "--porcelain", "-z"],
|
|
@@ -42001,7 +40948,7 @@ function createLeadRoleTransitions(state, host) {
|
|
|
42001
40948
|
signal: ctx.signal
|
|
42002
40949
|
}))?.workspace;
|
|
42003
40950
|
const paneCwd = pane?.cwd;
|
|
42004
|
-
if (pane?.pane_id !== paneId || pane?.tab_id !== tabId || pane?.workspace_id !== workspaceId || workspace2?.workspace_id !== workspaceId || typeof paneCwd !== "string" || !
|
|
40951
|
+
if (pane?.pane_id !== paneId || pane?.tab_id !== tabId || pane?.workspace_id !== workspaceId || workspace2?.workspace_id !== workspaceId || typeof paneCwd !== "string" || !isAbsolute8(paneCwd) || !sameDirectory(paneCwd, target))
|
|
42005
40952
|
throw new Error(
|
|
42006
40953
|
"Manager activation cancelled because Herdr workspace identity does not match the approved directory"
|
|
42007
40954
|
);
|
|
@@ -43735,8 +42682,9 @@ No active Herdsman role is verified for this Pi session.`;
|
|
|
43735
42682
|
(tui, theme, keybindings, done) => {
|
|
43736
42683
|
const input = new Input();
|
|
43737
42684
|
const listContainer = new Container2();
|
|
42685
|
+
const maxHelpCharacters = 280;
|
|
43738
42686
|
const helpArea = items.some(
|
|
43739
|
-
(item) => collapseDisplayText(item.help,
|
|
42687
|
+
(item) => collapseDisplayText(item.help, maxHelpCharacters)
|
|
43740
42688
|
) ? new Container2() : void 0;
|
|
43741
42689
|
const helpText = new TuiText("", 1, 0);
|
|
43742
42690
|
const emptyHelp = new Spacer2(1);
|
|
@@ -43744,7 +42692,7 @@ No active Herdsman role is verified for this Pi session.`;
|
|
|
43744
42692
|
if (!helpArea) return;
|
|
43745
42693
|
const help = collapseDisplayText(
|
|
43746
42694
|
item?.help,
|
|
43747
|
-
|
|
42695
|
+
maxHelpCharacters
|
|
43748
42696
|
);
|
|
43749
42697
|
helpArea.clear();
|
|
43750
42698
|
if (help) {
|